diff mbox series

[v5,10/31] sdhci: add a Designware/Samsung host controller

Message ID 20180108154303.6522-11-f4bug@amsat.org
State New
Headers show
Series SDHCI: make it abstract, add inherited devices, add qtests | expand

Commit Message

Philippe Mathieu-Daudé Jan. 8, 2018, 3:42 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/sd/dw-mshc.c     | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/sd/Makefile.objs |  1 +
 2 files changed, 65 insertions(+)
 create mode 100644 hw/sd/dw-mshc.c

Comments

Alistair Francis Jan. 9, 2018, 11:14 p.m. UTC | #1
On Mon, Jan 8, 2018 at 7:42 AM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  hw/sd/dw-mshc.c     | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/sd/Makefile.objs |  1 +
>  2 files changed, 65 insertions(+)
>  create mode 100644 hw/sd/dw-mshc.c
>
> diff --git a/hw/sd/dw-mshc.c b/hw/sd/dw-mshc.c
> new file mode 100644
> index 0000000000..c2869cd569
> --- /dev/null
> +++ b/hw/sd/dw-mshc.c
> @@ -0,0 +1,64 @@
> +/*
> + * Synopsys Designware Mobile Storage Host Controller emulation
> + * (and Samsung Exynos specific extensions)
> + *
> + * Copyright (C) 2018 Philippe Mathieu-Daudé <f4bug@amsat.org>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +#include "qemu/osdep.h"
> +#include "hw/sd/sdhci.h"
> +#include "qapi/error.h"
> +
> +/* Compatible with:
> + * - SD Host Controller Specification Version 2.0
> + * - SDIO Specification Version 2.0
> + * - MMC Specification Version 4.3
> + *
> + * - SDMA
> + * - ADMA
> + */
> +static void exynos4210_dw_mshc_realize(DeviceState *dev, Error **errp)
> +{
> +    SDHCICommonClass *cc = SYSBUS_SDHCI_COMMON_GET_CLASS(dev);
> +    Object *obj = OBJECT(dev);
> +    Error *local_err = NULL;
> +
> +    object_property_set_uint(obj, 2, "sd-spec-version", &local_err);
> +    object_property_set_bool(obj, true, "suspend", &local_err);
> +    object_property_set_bool(obj, true, "1v8", &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +
> +    cc->parent_realize(dev, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +}
> +
> +static void exynos4210_dw_mshc_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +    SDHCICommonClass *cc = SYSBUS_SDHCI_COMMON_CLASS(klass);
> +
> +    cc->parent_realize = dc->realize;

This need an explanation, why are we doing this weird realise logic?

Alistair

> +    dc->realize = exynos4210_dw_mshc_realize;
> +}
> +
> +static const TypeInfo exynos4210_dw_mshc_info = {
> +    .name = "samsung,exynos4210-dw-mshc",
> +    .parent = TYPE_SYSBUS_SDHCI,
> +    .class_init = exynos4210_dw_mshc_class_init,
> +};
> +
> +static void dw_mshc_sdhc_register_types(void)
> +{
> +    type_register_static(&exynos4210_dw_mshc_info);
> +}
> +
> +type_init(dw_mshc_sdhc_register_types)
> diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
> index 0fe2501017..fd866d7f94 100644
> --- a/hw/sd/Makefile.objs
> +++ b/hw/sd/Makefile.objs
> @@ -3,6 +3,7 @@ common-obj-$(CONFIG_SD) += core.o
>
>  # SD/MMC host adapters
>  common-obj-$(CONFIG_PL181) += pl181.o
> +common-obj-$(CONFIG_EXYNOS4) += dw-mshc.o
>  common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
>  common-obj-$(CONFIG_SDHCI) += sdhci.o
>  obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
> --
> 2.15.1
>
>
diff mbox series

Patch

diff --git a/hw/sd/dw-mshc.c b/hw/sd/dw-mshc.c
new file mode 100644
index 0000000000..c2869cd569
--- /dev/null
+++ b/hw/sd/dw-mshc.c
@@ -0,0 +1,64 @@ 
+/*
+ * Synopsys Designware Mobile Storage Host Controller emulation
+ * (and Samsung Exynos specific extensions)
+ *
+ * Copyright (C) 2018 Philippe Mathieu-Daudé <f4bug@amsat.org>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "hw/sd/sdhci.h"
+#include "qapi/error.h"
+
+/* Compatible with:
+ * - SD Host Controller Specification Version 2.0
+ * - SDIO Specification Version 2.0
+ * - MMC Specification Version 4.3
+ *
+ * - SDMA
+ * - ADMA
+ */
+static void exynos4210_dw_mshc_realize(DeviceState *dev, Error **errp)
+{
+    SDHCICommonClass *cc = SYSBUS_SDHCI_COMMON_GET_CLASS(dev);
+    Object *obj = OBJECT(dev);
+    Error *local_err = NULL;
+
+    object_property_set_uint(obj, 2, "sd-spec-version", &local_err);
+    object_property_set_bool(obj, true, "suspend", &local_err);
+    object_property_set_bool(obj, true, "1v8", &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    cc->parent_realize(dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+}
+
+static void exynos4210_dw_mshc_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SDHCICommonClass *cc = SYSBUS_SDHCI_COMMON_CLASS(klass);
+
+    cc->parent_realize = dc->realize;
+    dc->realize = exynos4210_dw_mshc_realize;
+}
+
+static const TypeInfo exynos4210_dw_mshc_info = {
+    .name = "samsung,exynos4210-dw-mshc",
+    .parent = TYPE_SYSBUS_SDHCI,
+    .class_init = exynos4210_dw_mshc_class_init,
+};
+
+static void dw_mshc_sdhc_register_types(void)
+{
+    type_register_static(&exynos4210_dw_mshc_info);
+}
+
+type_init(dw_mshc_sdhc_register_types)
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
index 0fe2501017..fd866d7f94 100644
--- a/hw/sd/Makefile.objs
+++ b/hw/sd/Makefile.objs
@@ -3,6 +3,7 @@  common-obj-$(CONFIG_SD) += core.o
 
 # SD/MMC host adapters
 common-obj-$(CONFIG_PL181) += pl181.o
+common-obj-$(CONFIG_EXYNOS4) += dw-mshc.o
 common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 common-obj-$(CONFIG_SDHCI) += sdhci.o
 obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o