Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/sociox enrich eMMC driver realities to work a bit



details:   https://anonhg.NetBSD.org/src/rev/2f85337d1de4
branches:  trunk
changeset: 849899:2f85337d1de4
user:      nisimura <nisimura%NetBSD.org@localhost>
date:      Wed Mar 18 06:44:57 2020 +0000

description:
enrich eMMC driver realities to work a bit

diffstat:

 sys/arch/arm/sociox/sni_emmc.c |  167 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 155 insertions(+), 12 deletions(-)

diffs (223 lines):

diff -r 8d6e25f01f55 -r 2f85337d1de4 sys/arch/arm/sociox/sni_emmc.c
--- a/sys/arch/arm/sociox/sni_emmc.c    Wed Mar 18 05:02:48 2020 +0000
+++ b/sys/arch/arm/sociox/sni_emmc.c    Wed Mar 18 06:44:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sni_emmc.c,v 1.1 2020/03/18 03:33:49 nisimura Exp $    */
+/*     $NetBSD: sni_emmc.c,v 1.2 2020/03/18 06:44:57 nisimura Exp $    */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.1 2020/03/18 03:33:49 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.2 2020/03/18 06:44:57 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -46,9 +46,14 @@
 
 #include <machine/endian.h>
 
+#include <dev/sdmmc/sdhcreg.h>
+#include <dev/sdmmc/sdhcvar.h>
+#include <dev/sdmmc/sdmmcvar.h>
+
 #include <dev/fdt/fdtvar.h>
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_intr.h>
 
 static int sniemmc_fdt_match(device_t, struct cfdata *, void *);
 static void sniemmc_fdt_attach(device_t, device_t, void *);
@@ -56,7 +61,17 @@
 static void sniemmc_acpi_attach(device_t, device_t, void *);
 
 struct sniemmc_softc {
-       device_t sc_dev;
+       struct sdhc_softc       sc;
+       bus_space_tag_t         sc_iot;
+       bus_space_handle_t      sc_ioh;
+       bus_addr_t              sc_iob;
+       bus_size_t              sc_ios;
+       struct sdhc_host        *sc_hosts[1];
+       void                    *sc_ih;
+       int                     sc_phandle;
+       bus_dmamap_t            sc_dmamap;
+       bus_dma_segment_t       sc_segs[1];
+       kcondvar_t              sc_cv;
 };
 
 CFATTACH_DECL_NEW(sniemmc_fdt, sizeof(struct sniemmc_softc),
@@ -65,7 +80,7 @@
 CFATTACH_DECL_NEW(sniemmc_acpi, sizeof(struct sniemmc_softc),
     sniemmc_acpi_match, sniemmc_acpi_attach, NULL, NULL);
 
-static int sniemmc_attach_i(struct sniemmc_softc *);
+static void sniemmc_attach_i(device_t);
 
 static int
 sniemmc_fdt_match(device_t parent, struct cfdata *match, void *aux)
@@ -84,10 +99,67 @@
 sniemmc_fdt_attach(device_t parent, device_t self, void *aux)
 {
        struct sniemmc_softc * const sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+       prop_dictionary_t dict = device_properties(self);
+       const int phandle = faa->faa_phandle;
+       bus_space_handle_t ioh;
+       bus_addr_t addr;
+       bus_size_t size;
+       void *ih;
+       char intrstr[128];
+       _Bool disable;
        int error;
 
-       error = sniemmc_attach_i(sc);
-       (void)error;
+       prop_dictionary_get_bool(dict, "disable", &disable);
+       if (disable) {
+               aprint_naive(": disabled\n");
+               aprint_normal(": disabled\n");
+               return;
+       }
+       error = fdtbus_get_reg(phandle, 0, &addr, &size);
+       if (error) {
+               aprint_error(": couldn't get registers\n");
+               return;
+       }
+       error = bus_space_map(faa->faa_bst, addr, size, 0, &ioh);
+       if (error) {
+               aprint_error(": unable to map device\n");
+               return;
+       }
+       error = fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr));
+       if (error) {
+               aprint_error(": failed to decode interrupt\n");
+               return;
+       }
+
+       aprint_naive(": SDHC controller\n");
+       aprint_normal(": SDHC controller\n");
+
+       sc->sc.sc_dev = self;
+       sc->sc.sc_dmat = faa->faa_dmat;
+       sc->sc.sc_host = sc->sc_hosts;
+       sc->sc_phandle = phandle;
+       sc->sc_iot = faa->faa_bst;
+       sc->sc_ioh = ioh;
+       sc->sc_iob = addr;
+       sc->sc_ios = size;
+
+       ih = fdtbus_intr_establish(phandle, 0, IPL_SDMMC, 0,
+           sdhc_intr, &sc->sc);
+       if (ih == NULL) {
+               aprint_error_dev(self, "couldn't establish interrupt on %s\n",
+                   intrstr);
+               goto fail;
+       }
+       aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+       sc->sc_ih = ih;
+
+       config_defer(self, sniemmc_attach_i);
+
+       return;
+ fail:
+       bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+       return;
 }
 
 static int
@@ -108,14 +180,85 @@
 sniemmc_acpi_attach(device_t parent, device_t self, void *aux)
 {
        struct sniemmc_softc * const sc = device_private(self);
-       int error;
+       struct acpi_attach_args *aa = aux;
+       bus_space_handle_t ioh;
+       struct acpi_resources res;
+       struct acpi_mem *mem;
+       struct acpi_irq *irq;
+       ACPI_STATUS rv;
+       void *ih;
+
+       rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+           &res, &acpi_resource_parse_ops_default);
+       if (ACPI_FAILURE(rv))
+               return;
+
+       mem = acpi_res_mem(&res, 0);
+       irq = acpi_res_irq(&res, 0);
+       if (mem == NULL || irq == NULL) {
+               aprint_error(": incomplete resources\n");
+               return;
+       }
+       if (mem->ar_length == 0) {
+               aprint_error(": zero length memory resource\n");
+               return;
+       }
+       if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
+           &ioh)) {
+               aprint_error(": couldn't map registers\n");
+               return;
+       }
 
-       error = sniemmc_attach_i(sc);
-       (void)error;
+       aprint_naive(": SDHC controller\n");
+       aprint_normal(": SDHC controller\n");
+
+       sc->sc.sc_dev = self;
+       sc->sc.sc_dmat = aa->aa_dmat;
+       sc->sc.sc_host = sc->sc_hosts;
+       sc->sc_iot = aa->aa_memt;
+       sc->sc_ioh = ioh;
+       sc->sc_ios = mem->ar_length;
+
+       ih = acpi_intr_establish(self,
+           (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
+           IPL_BIO, false, sdhc_intr, &sc->sc, device_xname(self));
+       if (ih == NULL) {
+               aprint_error_dev(self, "couldn't establish interrupt\n");
+               goto fail;
+       }
+       sc->sc_ih = ih;
+
+       config_defer(self, sniemmc_attach_i);
+
+       acpi_resource_cleanup(&res);
+       return;
+
+ fail:
+       bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+       acpi_resource_cleanup(&res);
+       return;
 }
 
-static int
-sniemmc_attach_i(struct sniemmc_softc *sc)
+static void
+sniemmc_attach_i(device_t self)
 {
-       return 0;
+       struct sniemmc_softc * const sc = device_private(self);
+       int error;
+
+       sc->sc.sc_flags = 0;
+       sc->sc.sc_flags |= SDHC_FLAG_32BIT_ACCESS;
+       sc->sc.sc_clkbase = 50000;      /* Default to 50MHz */
+
+       error = sdhc_host_found(&sc->sc, sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+       if (error) {
+               aprint_error_dev(self, "couldn't intialize host, error=%d\n",                           error);
+               goto fail;
+       }
+       return;
+ fail:
+       fdtbus_intr_disestablish(sc->sc_phandle, sc->sc_ih);
+       acpi_intr_disestablish(sc->sc_ih);
+       sc->sc_ih = NULL;
+       bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+       return;
 }



Home | Main Index | Thread Index | Old Index