Revision 5b7f5327
b/hw/i2c.c | ||
---|---|---|
14 | 14 |
BusState qbus; |
15 | 15 |
i2c_slave *current_dev; |
16 | 16 |
i2c_slave *dev; |
17 |
int saved_address;
|
|
17 |
uint8_t saved_address;
|
|
18 | 18 |
}; |
19 | 19 |
|
20 | 20 |
static struct BusInfo i2c_bus_info = { |
21 | 21 |
.name = "I2C", |
22 | 22 |
.size = sizeof(i2c_bus), |
23 | 23 |
.props = (Property[]) { |
24 |
DEFINE_PROP_UINT32("address", struct i2c_slave, address, 0),
|
|
24 |
DEFINE_PROP_UINT8("address", struct i2c_slave, address, 0),
|
|
25 | 25 |
DEFINE_PROP_END_OF_LIST(), |
26 | 26 |
} |
27 | 27 |
}; |
... | ... | |
29 | 29 |
static void i2c_bus_save(QEMUFile *f, void *opaque) |
30 | 30 |
{ |
31 | 31 |
i2c_bus *bus = (i2c_bus *)opaque; |
32 |
bus->saved_address = bus->current_dev ? bus->current_dev->address : -1; |
|
32 | 33 |
|
33 |
qemu_put_byte(f, bus->current_dev ? bus->current_dev->address : -1);
|
|
34 |
qemu_put_8s(f, &bus->saved_address);
|
|
34 | 35 |
} |
35 | 36 |
|
36 | 37 |
static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id) |
... | ... | |
42 | 43 |
|
43 | 44 |
/* The bus is loaded before attached devices, so load and save the |
44 | 45 |
current device id. Devices will check themselves as loaded. */ |
45 |
bus->saved_address = (int8_t) qemu_get_byte(f);
|
|
46 |
qemu_get_8s(f, &bus->saved_address);
|
|
46 | 47 |
bus->current_dev = NULL; |
47 | 48 |
|
48 | 49 |
return 0; |
... | ... | |
58 | 59 |
return bus; |
59 | 60 |
} |
60 | 61 |
|
61 |
void i2c_set_slave_address(i2c_slave *dev, int address)
|
|
62 |
void i2c_set_slave_address(i2c_slave *dev, uint8_t address)
|
|
62 | 63 |
{ |
63 | 64 |
dev->address = address; |
64 | 65 |
} |
... | ... | |
71 | 72 |
|
72 | 73 |
/* Returns non-zero if the address is not valid. */ |
73 | 74 |
/* TODO: Make this handle multiple masters. */ |
74 |
int i2c_start_transfer(i2c_bus *bus, int address, int recv)
|
|
75 |
int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
|
|
75 | 76 |
{ |
76 | 77 |
DeviceState *qdev; |
77 | 78 |
i2c_slave *slave = NULL; |
... | ... | |
136 | 137 |
|
137 | 138 |
void i2c_slave_save(QEMUFile *f, i2c_slave *dev) |
138 | 139 |
{ |
139 |
qemu_put_byte(f, dev->address);
|
|
140 |
qemu_put_8s(f, &dev->address);
|
|
140 | 141 |
} |
141 | 142 |
|
142 | 143 |
void i2c_slave_load(QEMUFile *f, i2c_slave *dev) |
143 | 144 |
{ |
144 | 145 |
i2c_bus *bus; |
145 | 146 |
bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev)); |
146 |
dev->address = qemu_get_byte(f);
|
|
147 |
qemu_get_8s(f, &dev->address);
|
|
147 | 148 |
if (bus->saved_address == dev->address) { |
148 | 149 |
bus->current_dev = dev; |
149 | 150 |
} |
... | ... | |
167 | 168 |
qdev_register(&info->qdev); |
168 | 169 |
} |
169 | 170 |
|
170 |
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr)
|
|
171 |
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
|
|
171 | 172 |
{ |
172 | 173 |
DeviceState *dev; |
173 | 174 |
|
174 | 175 |
dev = qdev_create(&bus->qbus, name); |
175 |
qdev_prop_set_uint32(dev, "address", addr);
|
|
176 |
qdev_prop_set_uint8(dev, "address", addr);
|
|
176 | 177 |
qdev_init(dev); |
177 | 178 |
return dev; |
178 | 179 |
} |
b/hw/i2c.h | ||
---|---|---|
40 | 40 |
I2CSlaveInfo *info; |
41 | 41 |
|
42 | 42 |
/* Remaining fields for internal use by the I2C code. */ |
43 |
uint32_t address;
|
|
43 |
uint8_t address;
|
|
44 | 44 |
}; |
45 | 45 |
|
46 | 46 |
i2c_bus *i2c_init_bus(DeviceState *parent, const char *name); |
47 |
void i2c_set_slave_address(i2c_slave *dev, int address);
|
|
47 |
void i2c_set_slave_address(i2c_slave *dev, uint8_t address);
|
|
48 | 48 |
int i2c_bus_busy(i2c_bus *bus); |
49 |
int i2c_start_transfer(i2c_bus *bus, int address, int recv);
|
|
49 |
int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv);
|
|
50 | 50 |
void i2c_end_transfer(i2c_bus *bus); |
51 | 51 |
void i2c_nack(i2c_bus *bus); |
52 | 52 |
int i2c_send(i2c_bus *bus, uint8_t data); |
... | ... | |
59 | 59 |
|
60 | 60 |
void i2c_register_slave(I2CSlaveInfo *type); |
61 | 61 |
|
62 |
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr);
|
|
62 |
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
|
|
63 | 63 |
|
64 | 64 |
/* max7310.c */ |
65 | 65 |
void max7310_reset(i2c_slave *i2c); |
b/hw/mips_malta.c | ||
---|---|---|
931 | 931 |
/* TODO: Populate SPD eeprom data. */ |
932 | 932 |
DeviceState *eeprom; |
933 | 933 |
eeprom = qdev_create((BusState *)smbus, "smbus-eeprom"); |
934 |
qdev_prop_set_uint32(eeprom, "address", 0x50 + i);
|
|
934 |
qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
|
|
935 | 935 |
qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256)); |
936 | 936 |
qdev_init(eeprom); |
937 | 937 |
} |
b/hw/pc.c | ||
---|---|---|
1402 | 1402 |
for (i = 0; i < 8; i++) { |
1403 | 1403 |
DeviceState *eeprom; |
1404 | 1404 |
eeprom = qdev_create((BusState *)smbus, "smbus-eeprom"); |
1405 |
qdev_prop_set_uint32(eeprom, "address", 0x50 + i);
|
|
1405 |
qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
|
|
1406 | 1406 |
qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256)); |
1407 | 1407 |
qdev_init(eeprom); |
1408 | 1408 |
} |
b/hw/smbus.c | ||
---|---|---|
217 | 217 |
} |
218 | 218 |
|
219 | 219 |
/* Master device commands. */ |
220 |
void smbus_quick_command(i2c_bus *bus, int addr, int read)
|
|
220 |
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read)
|
|
221 | 221 |
{ |
222 | 222 |
i2c_start_transfer(bus, addr, read); |
223 | 223 |
i2c_end_transfer(bus); |
224 | 224 |
} |
225 | 225 |
|
226 |
uint8_t smbus_receive_byte(i2c_bus *bus, int addr)
|
|
226 |
uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr)
|
|
227 | 227 |
{ |
228 | 228 |
uint8_t data; |
229 | 229 |
|
... | ... | |
234 | 234 |
return data; |
235 | 235 |
} |
236 | 236 |
|
237 |
void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data)
|
|
237 |
void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data)
|
|
238 | 238 |
{ |
239 | 239 |
i2c_start_transfer(bus, addr, 0); |
240 | 240 |
i2c_send(bus, data); |
241 | 241 |
i2c_end_transfer(bus); |
242 | 242 |
} |
243 | 243 |
|
244 |
uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command)
|
|
244 |
uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command)
|
|
245 | 245 |
{ |
246 | 246 |
uint8_t data; |
247 | 247 |
i2c_start_transfer(bus, addr, 0); |
... | ... | |
253 | 253 |
return data; |
254 | 254 |
} |
255 | 255 |
|
256 |
void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data)
|
|
256 |
void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data)
|
|
257 | 257 |
{ |
258 | 258 |
i2c_start_transfer(bus, addr, 0); |
259 | 259 |
i2c_send(bus, command); |
... | ... | |
261 | 261 |
i2c_end_transfer(bus); |
262 | 262 |
} |
263 | 263 |
|
264 |
uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command)
|
|
264 |
uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command)
|
|
265 | 265 |
{ |
266 | 266 |
uint16_t data; |
267 | 267 |
i2c_start_transfer(bus, addr, 0); |
... | ... | |
274 | 274 |
return data; |
275 | 275 |
} |
276 | 276 |
|
277 |
void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data)
|
|
277 |
void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data)
|
|
278 | 278 |
{ |
279 | 279 |
i2c_start_transfer(bus, addr, 0); |
280 | 280 |
i2c_send(bus, command); |
... | ... | |
283 | 283 |
i2c_end_transfer(bus); |
284 | 284 |
} |
285 | 285 |
|
286 |
int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data)
|
|
286 |
int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data)
|
|
287 | 287 |
{ |
288 | 288 |
int len; |
289 | 289 |
int i; |
... | ... | |
301 | 301 |
return len; |
302 | 302 |
} |
303 | 303 |
|
304 |
void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data,
|
|
304 |
void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
|
|
305 | 305 |
int len) |
306 | 306 |
{ |
307 | 307 |
int i; |
b/hw/smbus.h | ||
---|---|---|
56 | 56 |
void smbus_register_device(SMBusDeviceInfo *info); |
57 | 57 |
|
58 | 58 |
/* Master device commands. */ |
59 |
void smbus_quick_command(i2c_bus *bus, int addr, int read);
|
|
60 |
uint8_t smbus_receive_byte(i2c_bus *bus, int addr);
|
|
61 |
void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data);
|
|
62 |
uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command);
|
|
63 |
void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data);
|
|
64 |
uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command);
|
|
65 |
void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data);
|
|
66 |
int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data);
|
|
67 |
void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data,
|
|
59 |
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
|
|
60 |
uint8_t smbus_receive_byte(i2c_bus *bus, uint8_t addr);
|
|
61 |
void smbus_send_byte(i2c_bus *bus, uint8_t addr, uint8_t data);
|
|
62 |
uint8_t smbus_read_byte(i2c_bus *bus, uint8_t addr, uint8_t command);
|
|
63 |
void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data);
|
|
64 |
uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command);
|
|
65 |
void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data);
|
|
66 |
int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
|
|
67 |
void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
|
|
68 | 68 |
int len); |
Also available in: Unified diff