瀏覽代碼

ds1338: QOM'ify

Replace usages of FROM_I2C_SLAVE() with QOM cast macro.
Rename parent field.

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Andreas Färber 11 年之前
父節點
當前提交
59ab56b9ad
共有 1 個文件被更改,包括 13 次插入8 次删除
  1. 13 8
      hw/timer/ds1338.c

+ 13 - 8
hw/timer/ds1338.c

@@ -23,8 +23,12 @@
 #define HOURS_PM   0x20
 #define HOURS_PM   0x20
 #define CTRL_OSF   0x20
 #define CTRL_OSF   0x20
 
 
-typedef struct {
-    I2CSlave i2c;
+#define TYPE_DS1338 "ds1338"
+#define DS1338(obj) OBJECT_CHECK(DS1338State, (obj), TYPE_DS1338)
+
+typedef struct DS1338State {
+    I2CSlave parent_obj;
+
     int64_t offset;
     int64_t offset;
     uint8_t wday_offset;
     uint8_t wday_offset;
     uint8_t nvram[NVRAM_SIZE];
     uint8_t nvram[NVRAM_SIZE];
@@ -38,7 +42,7 @@ static const VMStateDescription vmstate_ds1338 = {
     .minimum_version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
     .fields = (VMStateField[]) {
-        VMSTATE_I2C_SLAVE(i2c, DS1338State),
+        VMSTATE_I2C_SLAVE(parent_obj, DS1338State),
         VMSTATE_INT64(offset, DS1338State),
         VMSTATE_INT64(offset, DS1338State),
         VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
         VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
         VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE),
         VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE),
@@ -90,7 +94,7 @@ static void inc_regptr(DS1338State *s)
 
 
 static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
 static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
 {
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
 
 
     switch (event) {
     switch (event) {
     case I2C_START_RECV:
     case I2C_START_RECV:
@@ -111,7 +115,7 @@ static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
 
 
 static int ds1338_recv(I2CSlave *i2c)
 static int ds1338_recv(I2CSlave *i2c)
 {
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
     uint8_t res;
     uint8_t res;
 
 
     res  = s->nvram[s->ptr];
     res  = s->nvram[s->ptr];
@@ -121,7 +125,8 @@ static int ds1338_recv(I2CSlave *i2c)
 
 
 static int ds1338_send(I2CSlave *i2c, uint8_t data)
 static int ds1338_send(I2CSlave *i2c, uint8_t data)
 {
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
+
     if (s->addr_byte) {
     if (s->addr_byte) {
         s->ptr = data & (NVRAM_SIZE - 1);
         s->ptr = data & (NVRAM_SIZE - 1);
         s->addr_byte = false;
         s->addr_byte = false;
@@ -198,7 +203,7 @@ static int ds1338_init(I2CSlave *i2c)
 
 
 static void ds1338_reset(DeviceState *dev)
 static void ds1338_reset(DeviceState *dev)
 {
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, I2C_SLAVE(dev));
+    DS1338State *s = DS1338(dev);
 
 
     /* The clock is running and synchronized with the host */
     /* The clock is running and synchronized with the host */
     s->offset = 0;
     s->offset = 0;
@@ -222,7 +227,7 @@ static void ds1338_class_init(ObjectClass *klass, void *data)
 }
 }
 
 
 static const TypeInfo ds1338_info = {
 static const TypeInfo ds1338_info = {
-    .name          = "ds1338",
+    .name          = TYPE_DS1338,
     .parent        = TYPE_I2C_SLAVE,
     .parent        = TYPE_I2C_SLAVE,
     .instance_size = sizeof(DS1338State),
     .instance_size = sizeof(DS1338State),
     .class_init    = ds1338_class_init,
     .class_init    = ds1338_class_init,