]> Git Repo - qemu.git/blobdiff - hw/ads7846.c
vmstate: port m48t59
[qemu.git] / hw / ads7846.c
index 9fa18c7cff637a5f1e7da8ce2671ea217be8d3c0..9c58a5f59f969d6a5ee8d8eb59d4f625b1cb1c4d 100644 (file)
@@ -7,11 +7,11 @@
  * This code is licensed under the GNU GPL v2.
  */
 
-#include "hw.h"
-#include "devices.h"
+#include "ssi.h"
 #include "console.h"
 
-struct ADS7846State {
+typedef struct {
+    SSISlave ssidev;
     qemu_irq interrupt;
 
     int input[8];
@@ -20,7 +20,7 @@ struct ADS7846State {
 
     int cycle;
     int output;
-};
+} ADS7846State;
 
 /* Control-byte bitfields */
 #define CB_PD0         (1 << 0)
@@ -52,16 +52,9 @@ static void ads7846_int_update(ADS7846State *s)
         qemu_set_irq(s->interrupt, s->pressure == 0);
 }
 
-uint32_t ads7846_read(void *opaque)
-{
-    ADS7846State *s = (ADS7846State *) opaque;
-
-    return s->output;
-}
-
-void ads7846_write(void *opaque, uint32_t value)
+static uint32_t ads7846_transfer(SSISlave *dev, uint32_t value)
 {
-    ADS7846State *s = (ADS7846State *) opaque;
+    ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
 
     switch (s->cycle ++) {
     case 0:
@@ -89,6 +82,7 @@ void ads7846_write(void *opaque, uint32_t value)
         s->cycle = 0;
         break;
     }
+    return s->output;
 }
 
 static void ads7846_ts_event(void *opaque,
@@ -111,43 +105,35 @@ static void ads7846_ts_event(void *opaque,
     }
 }
 
-static void ads7846_save(QEMUFile *f, void *opaque)
+static int ads7856_post_load(void *opaque, int version_id)
 {
-    ADS7846State *s = (ADS7846State *) opaque;
-    int i;
-
-    for (i = 0; i < 8; i ++)
-        qemu_put_be32(f, s->input[i]);
-    qemu_put_be32(f, s->noise);
-    qemu_put_be32(f, s->cycle);
-    qemu_put_be32(f, s->output);
-}
-
-static int ads7846_load(QEMUFile *f, void *opaque, int version_id)
-{
-    ADS7846State *s = (ADS7846State *) opaque;
-    int i;
-
-    for (i = 0; i < 8; i ++)
-        s->input[i] = qemu_get_be32(f);
-    s->noise = qemu_get_be32(f);
-    s->cycle = qemu_get_be32(f);
-    s->output = qemu_get_be32(f);
+    ADS7846State *s = opaque;
 
     s->pressure = 0;
     ads7846_int_update(s);
-
     return 0;
 }
 
-ADS7846State *ads7846_init(qemu_irq penirq)
+static const VMStateDescription vmstate_ads7846 = {
+    .name = "ads7846",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .post_load = ads7856_post_load,
+    .fields      = (VMStateField[]) {
+        VMSTATE_INT32_ARRAY(input, ADS7846State, 8),
+        VMSTATE_INT32(noise, ADS7846State),
+        VMSTATE_INT32(cycle, ADS7846State),
+        VMSTATE_INT32(output, ADS7846State),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static int ads7846_init(SSISlave *dev)
 {
-    ADS7846State *s;
-    s = (ADS7846State *)
-            qemu_mallocz(sizeof(ADS7846State));
-    memset(s, 0, sizeof(ADS7846State));
+    ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
 
-    s->interrupt = penirq;
+    qdev_init_gpio_out(&dev->qdev, &s->interrupt, 1);
 
     s->input[0] = ADS_TEMP0;   /* TEMP0 */
     s->input[2] = ADS_VBAT;    /* VBAT */
@@ -160,7 +146,20 @@ ADS7846State *ads7846_init(qemu_irq penirq)
 
     ads7846_int_update(s);
 
-    register_savevm("ads7846", -1, 0, ads7846_save, ads7846_load, s);
+    vmstate_register(NULL, -1, &vmstate_ads7846, s);
+    return 0;
+}
+
+static SSISlaveInfo ads7846_info = {
+    .qdev.name ="ads7846",
+    .qdev.size = sizeof(ADS7846State),
+    .init = ads7846_init,
+    .transfer = ads7846_transfer
+};
 
-    return s;
+static void ads7846_register_devices(void)
+{
+    ssi_register_slave(&ads7846_info);
 }
+
+device_init(ads7846_register_devices)
This page took 0.028052 seconds and 4 git commands to generate.