Patchwork [V2,08/10] SD card: introduce "spi_mode" property for SD card objects

login
register
mail settings
Submitter Mitsyanko Igor
Date April 5, 2012, 3:48 p.m.
Message ID <1333640913-16028-9-git-send-email-i.mitsyanko@samsung.com>
Download mbox | patch
Permalink /patch/151223/
State New
Headers show

Comments

Mitsyanko Igor - April 5, 2012, 3:48 p.m.
And drop passing is_spi argument to SDCardClass::init function. After this,
SDCardClass::init is trivialized enough to replace it with Object::realize
callback in the future.

"spi_mode" property should be set before realizing SD card object. It defaults to
"false".

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
---
 hw/milkymist-memcard.c |    3 ++-
 hw/omap_mmc.c          |    6 ++++--
 hw/pl181.c             |    3 ++-
 hw/pxa2xx_mmci.c       |    3 ++-
 hw/sd.c                |   28 ++++++++++++++++++++++++++--
 hw/sd.h                |    4 ++--
 hw/ssi-sd.c            |    3 ++-
 7 files changed, 40 insertions(+), 10 deletions(-)

Patch

diff --git a/hw/milkymist-memcard.c b/hw/milkymist-memcard.c
index 2fff47f..80cac20 100644
--- a/hw/milkymist-memcard.c
+++ b/hw/milkymist-memcard.c
@@ -258,8 +258,9 @@  static int milkymist_memcard_init(SysBusDevice *dev)
     if (dinfo) {
         object_property_set_int(OBJECT(s->card), dinfo->unit, "if-idx", &errp);
     }
+    object_property_set_bool(OBJECT(s->card), false, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->card, false);
+    SD_INIT(s->card);
     s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
 
     memory_region_init_io(&s->regs_region, &memcard_mmio_ops, s,
diff --git a/hw/omap_mmc.c b/hw/omap_mmc.c
index 3bf29c2..2c59869 100644
--- a/hw/omap_mmc.c
+++ b/hw/omap_mmc.c
@@ -598,8 +598,9 @@  struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base,
     /* Instantiate the storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
     object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    object_property_set_bool(OBJECT(s->card), false, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->card, false);
+    SD_INIT(s->card);
 
     return s;
 }
@@ -627,8 +628,9 @@  struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
     /* Instantiate the storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
     object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    object_property_set_bool(OBJECT(s->card), false, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->card, false);
+    SD_INIT(s->card);
 
     s->cdet = qemu_allocate_irqs(omap_mmc_cover_cb, s, 1)[0];
     SD_SET_CB(s->card, NULL, s->cdet);
diff --git a/hw/pl181.c b/hw/pl181.c
index a0a8fe3..48720ae 100644
--- a/hw/pl181.c
+++ b/hw/pl181.c
@@ -489,8 +489,9 @@  static int pl181_init(SysBusDevice *dev)
     if (dinfo) {
         object_property_set_int(OBJECT(s->card), dinfo->unit, "if-idx", &errp);
     }
+    object_property_set_bool(OBJECT(s->card), false, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->card, false);
+    SD_INIT(s->card);
     return 0;
 }
 
diff --git a/hw/pxa2xx_mmci.c b/hw/pxa2xx_mmci.c
index c06a108..1e0cb7b 100644
--- a/hw/pxa2xx_mmci.c
+++ b/hw/pxa2xx_mmci.c
@@ -547,8 +547,9 @@  PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
     /* Instantiate the actual storage */
     s->card = SD_CARD(object_new(TYPE_SD_CARD));
     object_property_set_int(OBJECT(s->card), di->unit, "if-idx", &errp);
+    object_property_set_bool(OBJECT(s->card), false, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->card, false);
+    SD_INIT(s->card);
 
     register_savevm(NULL, "pxa2xx_mmci", 0, 0,
                     pxa2xx_mmci_save, pxa2xx_mmci_load, s);
diff --git a/hw/sd.c b/hw/sd.c
index 1ea1756..8ffaa17 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -487,7 +487,7 @@  static const VMStateDescription sd_vmstate = {
    whether card should be in SSI or MMC/SD mode.  It is also up to the
    board to ensure that ssi transfers only occur when the chip select
    is asserted.  */
-static void sd_init(SDState *sd, bool is_spi)
+static void sd_init(SDState *sd)
 {
     DriveInfo *di = drive_get_by_index(IF_SD, sd->if_idx);
     BlockDriverState *bs = NULL;
@@ -496,7 +496,6 @@  static void sd_init(SDState *sd, bool is_spi)
         bs = di->bdrv;
     }
     sd->buf = qemu_blockalign(bs, 512);
-    sd->spi = is_spi;
     sd->enable = true;
     sd_reset(sd, bs);
     if (sd->bdrv) {
@@ -1795,13 +1794,38 @@  static void sd_set_if_index(Object *obj, Visitor *v, void *opaque,
     }
 }
 
+static void sd_is_spi(Object *obj, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+{
+    SDState *sd = SD_CARD(obj);
+
+    visit_type_bool(v, &sd->spi, name, errp);
+}
+
+static void sd_set_spimode(Object *obj, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+{
+    SDState *sd = SD_CARD(obj);
+    bool is_spi;
+
+    visit_type_bool(v, &is_spi, name, errp);
+    if (sd->bdrv) {
+        error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(sd->bdrv));
+    } else {
+        sd->spi = is_spi;
+    }
+}
+
 static void sd_initfn(Object *obj)
 {
     SDState *sd = SD_CARD(obj);
 
     sd->if_idx = -1;
+    sd->spi = false;
     object_property_add(obj, "if-idx", "int", sd_get_if_index, sd_set_if_index,
             NULL, NULL, NULL);
+    object_property_add(obj, "spi-mode", "boolean", sd_is_spi, sd_set_spimode,
+            NULL, NULL, NULL);
 }
 
 static TypeInfo sd_type_info = {
diff --git a/hw/sd.h b/hw/sd.h
index e2b458a..e45ce2f 100644
--- a/hw/sd.h
+++ b/hw/sd.h
@@ -73,7 +73,7 @@  typedef struct SDState SDState;
 typedef struct SDClass {
     ObjectClass parent_class;
 
-    void (*init)(SDState *sd, bool is_spi);
+    void (*init)(SDState *sd);
     int (*do_command)(SDState *sd, SDRequest *req, uint8_t *response);
     void (*write_data)(SDState *sd, uint8_t value);
     uint8_t (*read_data)(SDState *sd);
@@ -90,7 +90,7 @@  typedef struct SDClass {
 #define SD_GET_CLASS(obj)       \
      OBJECT_GET_CLASS(SDClass, (obj), TYPE_SD_CARD)
 
-#define SD_INIT(sd, bdrv, is_spi)   (SD_GET_CLASS(sd)->init(sd, is_spi))
+#define SD_INIT(sd, bdrv, is_spi)   (SD_GET_CLASS(sd)->init(sd))
 #define SD_DO_COMMAND(sd, req, rsp) (SD_GET_CLASS(sd)->do_command(sd, req, rsp))
 #define SD_WRITE(sd, value)         (SD_GET_CLASS(sd)->write_data(sd, value))
 #define SD_READ(sd)                 (SD_GET_CLASS(sd)->read_data(sd))
diff --git a/hw/ssi-sd.c b/hw/ssi-sd.c
index 38057ba..9f4510d 100644
--- a/hw/ssi-sd.c
+++ b/hw/ssi-sd.c
@@ -244,8 +244,9 @@  static int ssi_sd_init(SSISlave *dev)
     if (dinfo) {
         object_property_set_int(OBJECT(s->sd), dinfo->unit, "if-idx", &errp);
     }
+    object_property_set_bool(OBJECT(s->sd), true, "spi-mode", &errp);
     assert_no_error(errp);
-    SD_INIT(s->sd, true);
+    SD_INIT(s->sd);
     register_savevm(&dev->qdev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
     return 0;
 }