Patchwork [v3,056/197] add I2CSlave to the type hierarchy

login
register
mail settings
Submitter Anthony Liguori
Date Dec. 12, 2011, 8:18 p.m.
Message ID <1323721273-32404-57-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/130832/
State New
Headers show

Comments

Anthony Liguori - Dec. 12, 2011, 8:18 p.m.
---
 hw/i2c.c |   15 +++++++++++++++
 hw/i2c.h |   13 +++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/i2c.c b/hw/i2c.c
index 9efe70c..cdf88f2 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -194,3 +194,18 @@  DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
     qdev_init_nofail(dev);
     return dev;
 }
+
+static TypeInfo i2c_slave_type_info = {
+    .name = TYPE_I2C_SLAVE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(I2CSlave),
+    .abstract = true,
+    .class_size = sizeof(I2CSlaveClass),
+};
+
+static void i2c_slave_register_devices(void)
+{
+    type_register_static(&i2c_slave_type_info);
+}
+
+device_init(i2c_slave_register_devices);
diff --git a/hw/i2c.h b/hw/i2c.h
index 28401f0..cc4d76b 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -26,6 +26,19 @@  typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
 
 typedef int (*i2c_slave_initfn)(I2CSlave *dev);
 
+#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;
+} I2CSlaveClass;
+
 typedef struct {
     DeviceInfo qdev;