diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-04 20:39:20 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-01-27 10:50:47 -0600 |
commit | b5ea932781954355a9880e2744722cd05cc496f9 (patch) | |
tree | f47482844578c1dffdae93dc3ec103a101097a71 /hw/i2c.h | |
parent | 9e07bdf816b186632cda9651ac29bba76d299c03 (diff) |
i2c: smbus: convert to QEMU Object Model
This converts two types because smbus is implemented as a subclass of i2c. It's
extremely difficult to convert these two independently.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/i2c.h')
-rw-r--r-- | hw/i2c.h | 40 |
1 files changed, 23 insertions, 17 deletions
@@ -17,29 +17,34 @@ enum i2c_event { typedef struct I2CSlave I2CSlave; -/* Master to slave. */ -typedef int (*i2c_send_cb)(I2CSlave *s, uint8_t data); -/* Slave to master. */ -typedef int (*i2c_recv_cb)(I2CSlave *s); -/* Notify the slave of a bus state change. */ -typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event); +#define TYPE_I2C_SLAVE "i2c-slave" +#define I2C_SLAVE(obj) \ + OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE) +#define I2C_SLAVE_CLASS(klass) \ + OBJECT_CLASS_CHECK(I2CSlaveClass, (klass), TYPE_I2C_SLAVE) +#define I2C_SLAVE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE) + +typedef struct I2CSlaveClass +{ + DeviceClass parent_class; + + /* Callbacks provided by the device. */ + int (*init)(I2CSlave *dev); -typedef int (*i2c_slave_initfn)(I2CSlave *dev); + /* Master to slave. */ + int (*send)(I2CSlave *s, uint8_t data); -typedef struct { - DeviceInfo qdev; + /* Slave to master. */ + int (*recv)(I2CSlave *s); - /* Callbacks provided by the device. */ - i2c_slave_initfn init; - i2c_event_cb event; - i2c_recv_cb recv; - i2c_send_cb send; -} I2CSlaveInfo; + /* Notify the slave of a bus state change. */ + void (*event)(I2CSlave *s, enum i2c_event event); +} I2CSlaveClass; struct I2CSlave { DeviceState qdev; - I2CSlaveInfo *info; /* Remaining fields for internal use by the I2C code. */ uint8_t address; @@ -57,7 +62,8 @@ int i2c_recv(i2c_bus *bus); #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev) #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev) -void i2c_register_slave(I2CSlaveInfo *type); +void i2c_register_slave(DeviceInfo *type); +void i2c_register_slave_subclass(DeviceInfo *info, const char *parent); DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr); |