Patchwork [07/49] i2c: addresses are load/save as uint8_t values, change types to reflect this

login
register
mail settings
Submitter Juan Quintela
Date Sept. 29, 2009, 8:48 p.m.
Message ID <d96db22cdbe350c345569a8748fe8a68c2082a35.1254255997.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/34457/
State Superseded
Headers show

Comments

Juan Quintela - Sept. 29, 2009, 8:48 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/i2c.c        |   21 +++++++++++----------
 hw/i2c.h        |    8 ++++----
 hw/mips_malta.c |    2 +-
 hw/pc.c         |    2 +-
 hw/smbus.c      |   18 +++++++++---------
 hw/smbus.h      |   18 +++++++++---------
 6 files changed, 35 insertions(+), 34 deletions(-)

Patch

diff --git a/hw/i2c.c b/hw/i2c.c
index 370c431..1033e00 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -14,14 +14,14 @@  struct i2c_bus
     BusState qbus;
     i2c_slave *current_dev;
     i2c_slave *dev;
-    int saved_address;
+    uint8_t saved_address;
 };

 static struct BusInfo i2c_bus_info = {
     .name = "I2C",
     .size = sizeof(i2c_bus),
     .props = (Property[]) {
-        DEFINE_PROP_UINT32("address", struct i2c_slave, address, 0),
+        DEFINE_PROP_UINT8("address", struct i2c_slave, address, 0),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
@@ -29,8 +29,9 @@  static struct BusInfo i2c_bus_info = {
 static void i2c_bus_save(QEMUFile *f, void *opaque)
 {
     i2c_bus *bus = (i2c_bus *)opaque;
+    bus->saved_address = bus->current_dev ? bus->current_dev->address : -1;

-    qemu_put_byte(f, bus->current_dev ? bus->current_dev->address : -1);
+    qemu_put_8s(f, &bus->saved_address);
 }

 static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id)
@@ -42,7 +43,7 @@  static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id)

     /* The bus is loaded before attached devices, so load and save the
        current device id.  Devices will check themselves as loaded.  */
-    bus->saved_address = (int8_t) qemu_get_byte(f);
+    qemu_get_8s(f, &bus->saved_address);
     bus->current_dev = NULL;

     return 0;
@@ -58,7 +59,7 @@  i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
     return bus;
 }

-void i2c_set_slave_address(i2c_slave *dev, int address)
+void i2c_set_slave_address(i2c_slave *dev, uint8_t address)
 {
     dev->address = address;
 }
@@ -71,7 +72,7 @@  int i2c_bus_busy(i2c_bus *bus)

 /* Returns non-zero if the address is not valid.  */
 /* TODO: Make this handle multiple masters.  */
-int i2c_start_transfer(i2c_bus *bus, int address, int recv)
+int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
 {
     DeviceState *qdev;
     i2c_slave *slave = NULL;
@@ -136,14 +137,14 @@  void i2c_nack(i2c_bus *bus)

 void i2c_slave_save(QEMUFile *f, i2c_slave *dev)
 {
-    qemu_put_byte(f, dev->address);
+    qemu_put_8s(f, &dev->address);
 }

 void i2c_slave_load(QEMUFile *f, i2c_slave *dev)
 {
     i2c_bus *bus;
     bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev));
-    dev->address = qemu_get_byte(f);
+    qemu_get_8s(f, &dev->address);
     if (bus->saved_address == dev->address) {
         bus->current_dev = dev;
     }
@@ -167,12 +168,12 @@  void i2c_register_slave(I2CSlaveInfo *info)
     qdev_register(&info->qdev);
 }

-DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr)
+DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
 {
     DeviceState *dev;

     dev = qdev_create(&bus->qbus, name);
-    qdev_prop_set_uint32(dev, "address", addr);
+    qdev_prop_set_uint8(dev, "address", addr);
     qdev_init(dev);
     return dev;
 }
diff --git a/hw/i2c.h b/hw/i2c.h
index 238f256..65887a2 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -40,13 +40,13 @@  struct i2c_slave
     I2CSlaveInfo *info;

     /* Remaining fields for internal use by the I2C code.  */
-    uint32_t address;
+    uint8_t address;
 };

 i2c_bus *i2c_init_bus(DeviceState *parent, const char *name);
-void i2c_set_slave_address(i2c_slave *dev, int address);
+void i2c_set_slave_address(i2c_slave *dev, uint8_t address);
 int i2c_bus_busy(i2c_bus *bus);
-int i2c_start_transfer(i2c_bus *bus, int address, int recv);
+int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv);
 void i2c_end_transfer(i2c_bus *bus);
 void i2c_nack(i2c_bus *bus);
 int i2c_send(i2c_bus *bus, uint8_t data);
@@ -59,7 +59,7 @@  void i2c_slave_load(QEMUFile *f, i2c_slave *dev);

 void i2c_register_slave(I2CSlaveInfo *type);

-DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr);
+DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);

 /* max7310.c */
 void max7310_reset(i2c_slave *i2c);
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index e09e971..900f5ec 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -931,7 +931,7 @@  void mips_malta_init (ram_addr_t ram_size,
         /* TODO: Populate SPD eeprom data.  */
         DeviceState *eeprom;
         eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-        qdev_prop_set_uint32(eeprom, "address", 0x50 + i);
+        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
         qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
         qdev_init(eeprom);
     }
diff --git a/hw/pc.c b/hw/pc.c
index bc2875e..7649547 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1402,7 +1402,7 @@  static void pc_init1(ram_addr_t ram_size,
         for (i = 0; i < 8; i++) {
             DeviceState *eeprom;
             eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-            qdev_prop_set_uint32(eeprom, "address", 0x50 + i);
+            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
             qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
             qdev_init(eeprom);
         }
diff --git a/hw/smbus.c b/hw/smbus.c
index 6c1149b..e464539 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -217,13 +217,13 @@  void smbus_register_device(SMBusDeviceInfo *info)
 }

 /* Master device commands.  */
-void smbus_quick_command(i2c_bus *bus, int addr, int read)
+void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read)
 {
     i2c_start_transfer(bus, addr, read);
     i2c_end_transfer(bus);
 }

-uint8_t smbus_receive_byte(i2c_bus *bus, int addr)
+uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr)
 {
     uint8_t data;

@@ -234,14 +234,14 @@  uint8_t smbus_receive_byte(i2c_bus *bus, int addr)
     return data;
 }

-void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data)
+void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data)
 {
     i2c_start_transfer(bus, addr, 0);
     i2c_send(bus, data);
     i2c_end_transfer(bus);
 }

-uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command)
+uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command)
 {
     uint8_t data;
     i2c_start_transfer(bus, addr, 0);
@@ -253,7 +253,7 @@  uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command)
     return data;
 }

-void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data)
+void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data)
 {
     i2c_start_transfer(bus, addr, 0);
     i2c_send(bus, command);
@@ -261,7 +261,7 @@  void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data)
     i2c_end_transfer(bus);
 }

-uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command)
+uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command)
 {
     uint16_t data;
     i2c_start_transfer(bus, addr, 0);
@@ -274,7 +274,7 @@  uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command)
     return data;
 }

-void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data)
+void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data)
 {
     i2c_start_transfer(bus, addr, 0);
     i2c_send(bus, command);
@@ -283,7 +283,7 @@  void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data)
     i2c_end_transfer(bus);
 }

-int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data)
+int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data)
 {
     int len;
     int i;
@@ -301,7 +301,7 @@  int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data)
     return len;
 }

-void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data,
+void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
                        int len)
 {
     int i;
diff --git a/hw/smbus.h b/hw/smbus.h
index d582e6d..571c52d 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -56,13 +56,13 @@  typedef struct {
 void smbus_register_device(SMBusDeviceInfo *info);

 /* Master device commands.  */
-void smbus_quick_command(i2c_bus *bus, int addr, int read);
-uint8_t smbus_receive_byte(i2c_bus *bus, int addr);
-void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data);
-uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command);
-void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data);
-uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command);
-void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data);
-int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data);
-void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data,
+void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
+uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr);
+void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data);
+uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command);
+void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data);
+uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command);
+void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data);
+int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
+void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
                        int len);