@@ -96,6 +96,9 @@ OBJECT_DECLARE_TYPE(SDState, SDCardClass, SD_CARD)
#define TYPE_SD_CARD_SPI "sd-card-spi"
DECLARE_INSTANCE_CHECKER(SDState, SD_CARD_SPI, TYPE_SD_CARD_SPI)
+#define TYPE_EMMC "emmc"
+DECLARE_INSTANCE_CHECKER(SDState, EMMC, TYPE_EMMC)
+
struct SDCardClass {
/*< private >*/
DeviceClass parent_class;
@@ -2,6 +2,8 @@
* SD Memory Card emulation as defined in the "SD Memory Card Physical
* layer specification, Version 2.00."
*
+ * eMMC emulation defined in "JEDEC Standard No. 84-A43"
+ *
* Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
* Copyright (c) 2007 CodeSourcery
* Copyright (c) 2018 Philippe Mathieu-Daudé <f4bug@amsat.org>
@@ -169,12 +171,18 @@ struct SDState {
static void sd_realize(DeviceState *dev, Error **errp);
static const SDProto sd_proto_spi;
+static const SDProto sd_proto_emmc;
static bool sd_is_spi(SDState *sd)
{
return sd->proto == &sd_proto_spi;
}
+static bool sd_is_emmc(SDState *sd)
+{
+ return sd->proto == &sd_proto_emmc;
+}
+
static const char *sd_version_str(enum SDPhySpecificationVersion version)
{
static const char *sdphy_version[] = {
@@ -697,7 +705,7 @@ static void sd_reset(DeviceState *dev)
sd->state = sd_idle_state;
/* card registers */
- sd->rca = 0x0000;
+ sd->rca = sd_is_emmc(sd) ? 0x0001 : 0x0000;
sd->size = size;
sd_set_ocr(sd);
sd_set_scr(sd);
@@ -2375,6 +2383,13 @@ static const SDProto sd_proto_sd = {
},
};
+static const SDProto sd_proto_emmc = {
+ /* Only v4.3 is supported */
+ .name = "eMMC",
+ .cmd = {
+ },
+};
+
static void sd_instance_init(Object *obj)
{
SDState *sd = SDMMC_COMMON(obj);
@@ -2446,6 +2461,15 @@ static void sd_realize(DeviceState *dev, Error **errp)
}
}
+static void emmc_realize(DeviceState *dev, Error **errp)
+{
+ SDState *sd = SDMMC_COMMON(dev);
+
+ sd->spec_version = SD_PHY_SPECv3_01_VERS; /* Actually v4.3 */
+
+ sd_realize(dev, errp);
+}
+
static Property sdmmc_common_properties[] = {
DEFINE_PROP_DRIVE("drive", SDState, blk),
DEFINE_PROP_END_OF_LIST()
@@ -2457,6 +2481,10 @@ static Property sd_properties[] = {
DEFINE_PROP_END_OF_LIST()
};
+static Property emmc_properties[] = {
+ DEFINE_PROP_END_OF_LIST()
+};
+
static void sdmmc_common_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -2509,6 +2537,20 @@ static void sd_spi_class_init(ObjectClass *klass, void *data)
sc->proto = &sd_proto_spi;
}
+static void emmc_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ SDCardClass *sc = SDMMC_COMMON_CLASS(klass);
+
+ dc->desc = "eMMC";
+ dc->realize = emmc_realize;
+ device_class_set_props(dc, emmc_properties);
+ /* Reason: Soldered on board */
+ dc->user_creatable = false;
+
+ sc->proto = &sd_proto_emmc;
+}
+
static const TypeInfo sd_types[] = {
{
.name = TYPE_SDMMC_COMMON,
@@ -2530,6 +2572,12 @@ static const TypeInfo sd_types[] = {
.parent = TYPE_SD_CARD,
.class_init = sd_spi_class_init,
},
+ {
+ .name = TYPE_EMMC,
+ .parent = TYPE_SDMMC_COMMON,
+ .class_init = emmc_class_init,
+ .abstract = true, /* FIXME: Remove once model fully functional */
+ },
};
DEFINE_TYPES(sd_types)