i2c: addresses are load/save as uint8_t values, change types to reflect this

Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Juan Quintela 2009-09-29 22:48:26 +02:00 committed by Anthony Liguori
parent c7cc172d20
commit 5b7f53270a
6 changed files with 35 additions and 34 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);