diff mbox

[09/11] ds1338: QOM'ify

Message ID 1391178886-17277-10-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Jan. 31, 2014, 2:34 p.m. UTC
Replace usages of FROM_I2C_SLAVE() with QOM cast macro.
Rename parent field.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/timer/ds1338.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Comments

Peter Crosthwaite Feb. 9, 2014, 1:45 a.m. UTC | #1
On Sat, Feb 1, 2014 at 12:34 AM, Andreas Färber <afaerber@suse.de> wrote:
> Replace usages of FROM_I2C_SLAVE() with QOM cast macro.
> Rename parent field.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  hw/timer/ds1338.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c
> index 8987cdc..bb2f8ee 100644
> --- a/hw/timer/ds1338.c
> +++ b/hw/timer/ds1338.c
> @@ -23,8 +23,12 @@
>  #define HOURS_PM   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;
>      uint8_t wday_offset;
>      uint8_t nvram[NVRAM_SIZE];
> @@ -38,7 +42,7 @@ static const VMStateDescription vmstate_ds1338 = {
>      .minimum_version_id = 1,
>      .minimum_version_id_old = 1,
>      .fields = (VMStateField[]) {
> -        VMSTATE_I2C_SLAVE(i2c, DS1338State),
> +        VMSTATE_I2C_SLAVE(parent_obj, DS1338State),
>          VMSTATE_INT64(offset, DS1338State),
>          VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
>          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)
>  {
> -    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
> +    DS1338State *s = DS1338(i2c);
>
>      switch (event) {
>      case I2C_START_RECV:
> @@ -111,7 +115,7 @@ static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
>
>  static int ds1338_recv(I2CSlave *i2c)
>  {
> -    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
> +    DS1338State *s = DS1338(i2c);
>      uint8_t res;
>
>      res  = s->nvram[s->ptr];
> @@ -121,7 +125,8 @@ static int ds1338_recv(I2CSlave *i2c)
>
>  static int ds1338_send(I2CSlave *i2c, uint8_t data)
>  {
> -    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
> +    DS1338State *s = DS1338(i2c);
> +
>      if (s->addr_byte) {
>          s->ptr = data & (NVRAM_SIZE - 1);
>          s->addr_byte = false;
> @@ -198,7 +203,7 @@ static int ds1338_init(I2CSlave *i2c)
>
>  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 */
>      s->offset = 0;
> @@ -222,7 +227,7 @@ static void ds1338_class_init(ObjectClass *klass, void *data)
>  }
>
>  static const TypeInfo ds1338_info = {
> -    .name          = "ds1338",
> +    .name          = TYPE_DS1338,
>      .parent        = TYPE_I2C_SLAVE,
>      .instance_size = sizeof(DS1338State),
>      .class_init    = ds1338_class_init,
> --
> 1.8.4.5
>
>
diff mbox

Patch

diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c
index 8987cdc..bb2f8ee 100644
--- a/hw/timer/ds1338.c
+++ b/hw/timer/ds1338.c
@@ -23,8 +23,12 @@ 
 #define HOURS_PM   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;
     uint8_t wday_offset;
     uint8_t nvram[NVRAM_SIZE];
@@ -38,7 +42,7 @@  static const VMStateDescription vmstate_ds1338 = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
-        VMSTATE_I2C_SLAVE(i2c, DS1338State),
+        VMSTATE_I2C_SLAVE(parent_obj, DS1338State),
         VMSTATE_INT64(offset, DS1338State),
         VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
         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)
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
 
     switch (event) {
     case I2C_START_RECV:
@@ -111,7 +115,7 @@  static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
 
 static int ds1338_recv(I2CSlave *i2c)
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
     uint8_t res;
 
     res  = s->nvram[s->ptr];
@@ -121,7 +125,8 @@  static int ds1338_recv(I2CSlave *i2c)
 
 static int ds1338_send(I2CSlave *i2c, uint8_t data)
 {
-    DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+    DS1338State *s = DS1338(i2c);
+
     if (s->addr_byte) {
         s->ptr = data & (NVRAM_SIZE - 1);
         s->addr_byte = false;
@@ -198,7 +203,7 @@  static int ds1338_init(I2CSlave *i2c)
 
 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 */
     s->offset = 0;
@@ -222,7 +227,7 @@  static void ds1338_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo ds1338_info = {
-    .name          = "ds1338",
+    .name          = TYPE_DS1338,
     .parent        = TYPE_I2C_SLAVE,
     .instance_size = sizeof(DS1338State),
     .class_init    = ds1338_class_init,