Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Add eMMC reset sequence provider



details:   https://anonhg.NetBSD.org/src/rev/e75560a26768
branches:  trunk
changeset: 997293:e75560a26768
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Mar 03 12:54:07 2019 +0000

description:
Add eMMC reset sequence provider

diffstat:

 sys/dev/fdt/files.fdt           |    8 +-
 sys/dev/fdt/mmc_pwrseq_emmc.c   |  111 ++++++++++++++++++++++++++++++++++++++++
 sys/dev/fdt/mmc_pwrseq_simple.c |   40 +++++++-------
 3 files changed, 136 insertions(+), 23 deletions(-)

diffs (247 lines):

diff -r 42a31804a824 -r e75560a26768 sys/dev/fdt/files.fdt
--- a/sys/dev/fdt/files.fdt     Sun Mar 03 11:44:18 2019 +0000
+++ b/sys/dev/fdt/files.fdt     Sun Mar 03 12:54:07 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.42 2019/01/30 01:24:00 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.43 2019/03/03 12:54:07 jmcneill Exp $
 
 include        "external/bsd/libfdt/conf/files.libfdt"
 
@@ -72,8 +72,10 @@
 file   dev/fdt/cpus.c                          cpus
 
 device mmcpwrseq
-attach mmcpwrseq at fdt
-file   dev/fdt/mmc_pwrseq_simple.c             mmcpwrseq
+attach mmcpwrseq at fdt with mmcpwrseq_simple
+file   dev/fdt/mmc_pwrseq_simple.c             mmcpwrseq_simple
+attach mmcpwrseq at fdt with mmcpwrseq_emmc
+file   dev/fdt/mmc_pwrseq_emmc.c               mmcpwrseq_emmc
 
 device syscon { } : fdt
 attach syscon at fdt
diff -r 42a31804a824 -r e75560a26768 sys/dev/fdt/mmc_pwrseq_emmc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/mmc_pwrseq_emmc.c     Sun Mar 03 12:54:07 2019 +0000
@@ -0,0 +1,111 @@
+/* $NetBSD: mmc_pwrseq_emmc.c,v 1.1 2019/03/03 12:54:07 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mmc_pwrseq_emmc.c,v 1.1 2019/03/03 12:54:07 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/gpio.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#define        MMCPWRSEQ_MAX_PINS      32
+
+static const char * const compatible[] = {
+       "mmc-pwrseq-emmc",
+       NULL
+};
+
+struct mmcpwrseq_emmc_softc {
+       device_t sc_dev;
+       int sc_phandle;
+       struct fdtbus_gpio_pin *sc_pin;
+};
+
+static void
+mmcpwrseq_emmc_reset(device_t dev)
+{
+       struct mmcpwrseq_emmc_softc * const sc = device_private(dev);
+
+       fdtbus_gpio_write(sc->sc_pin, 1);
+       delay(1);
+       fdtbus_gpio_write(sc->sc_pin, 0);
+       delay(200);
+}
+
+static const struct fdtbus_mmc_pwrseq_func mmcpwrseq_emmc_funcs = {
+       .reset = mmcpwrseq_emmc_reset,
+};
+
+static int
+mmcpwrseq_emmc_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+
+       return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+mmcpwrseq_emmc_attach(device_t parent, device_t self, void *aux)
+{
+       struct mmcpwrseq_emmc_softc * const sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+       const int phandle = faa->faa_phandle;
+
+       sc->sc_dev = self;
+       sc->sc_phandle = phandle;
+
+       sc->sc_pin = fdtbus_gpio_acquire_index(phandle, "reset-gpios", 0, GPIO_PIN_OUTPUT);
+       if (sc->sc_pin == NULL) {
+               aprint_error(": couldn't get reset GPIO\n");
+               return;
+       }
+
+       aprint_naive("\n");
+       aprint_normal(": eMMC hardware reset provider\n");
+
+       fdtbus_register_mmc_pwrseq(self, phandle, &mmcpwrseq_emmc_funcs);
+}
+
+static int
+mmcpwrseq_emmc_detach(device_t self, int flags)
+{
+       struct mmcpwrseq_emmc_softc * const sc = device_private(self);
+
+       if (sc->sc_pin != NULL)
+               mmcpwrseq_emmc_reset(self);
+
+       return 0;
+}
+
+CFATTACH_DECL_NEW(mmcpwrseq_emmc, sizeof(struct mmcpwrseq_emmc_softc),
+       mmcpwrseq_emmc_match, mmcpwrseq_emmc_attach, mmcpwrseq_emmc_detach, NULL);
diff -r 42a31804a824 -r e75560a26768 sys/dev/fdt/mmc_pwrseq_simple.c
--- a/sys/dev/fdt/mmc_pwrseq_simple.c   Sun Mar 03 11:44:18 2019 +0000
+++ b/sys/dev/fdt/mmc_pwrseq_simple.c   Sun Mar 03 12:54:07 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mmc_pwrseq_simple.c,v 1.1 2017/10/22 13:56:49 jmcneill Exp $ */
+/* $NetBSD: mmc_pwrseq_simple.c,v 1.2 2019/03/03 12:54:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mmc_pwrseq_simple.c,v 1.1 2017/10/22 13:56:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mmc_pwrseq_simple.c,v 1.2 2019/03/03 12:54:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -45,7 +45,7 @@
        NULL
 };
 
-struct mmcpwrseq_softc {
+struct mmcpwrseq_simple_softc {
        device_t sc_dev;
        int sc_phandle;
        struct clk *sc_clk;
@@ -56,9 +56,9 @@
 };
 
 static void
-mmcpwrseq_pre_power_on(device_t dev)
+mmcpwrseq_simple_pre_power_on(device_t dev)
 {
-       struct mmcpwrseq_softc * const sc = device_private(dev);
+       struct mmcpwrseq_simple_softc * const sc = device_private(dev);
        int error;
 
        if (sc->sc_clk) {
@@ -74,9 +74,9 @@
 }
 
 static void
-mmcpwrseq_post_power_on(device_t dev)
+mmcpwrseq_simple_post_power_on(device_t dev)
 {
-       struct mmcpwrseq_softc * const sc = device_private(dev);
+       struct mmcpwrseq_simple_softc * const sc = device_private(dev);
 
        for (u_int n = 0; n < sc->sc_npins; n++)
                fdtbus_gpio_write(sc->sc_pins[n], 0);
@@ -87,9 +87,9 @@
 }
 
 static void
-mmcpwrseq_power_off(device_t dev)
+mmcpwrseq_simple_power_off(device_t dev)
 {
-       struct mmcpwrseq_softc * const sc = device_private(dev);
+       struct mmcpwrseq_simple_softc * const sc = device_private(dev);
 
        for (u_int n = 0; n < sc->sc_npins; n++)
                fdtbus_gpio_write(sc->sc_pins[n], 1);
@@ -98,14 +98,14 @@
                delay(sc->sc_power_off_delay_us);
 }
 
-static const struct fdtbus_mmc_pwrseq_func mmcpwrseq_funcs = {
-       .pre_power_on = mmcpwrseq_pre_power_on,
-       .post_power_on = mmcpwrseq_post_power_on,
-       .power_off = mmcpwrseq_power_off,
+static const struct fdtbus_mmc_pwrseq_func mmcpwrseq_simple_funcs = {
+       .pre_power_on = mmcpwrseq_simple_pre_power_on,
+       .post_power_on = mmcpwrseq_simple_post_power_on,
+       .power_off = mmcpwrseq_simple_power_off,
 };
 
 static int
-mmcpwrseq_match(device_t parent, cfdata_t cf, void *aux)
+mmcpwrseq_simple_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct fdt_attach_args * const faa = aux;
 
@@ -113,9 +113,9 @@
 }
 
 static void
-mmcpwrseq_attach(device_t parent, device_t self, void *aux)
+mmcpwrseq_simple_attach(device_t parent, device_t self, void *aux)
 {
-       struct mmcpwrseq_softc * const sc = device_private(self);
+       struct mmcpwrseq_simple_softc * const sc = device_private(self);
        struct fdt_attach_args * const faa = aux;
        const int phandle = faa->faa_phandle;
 
@@ -156,10 +156,10 @@
            &sc->sc_power_off_delay_us);
 
        aprint_naive("\n");
-       aprint_normal("\n");
+       aprint_normal(": Simple MMC power sequence provider\n");
 
-       fdtbus_register_mmc_pwrseq(self, phandle, &mmcpwrseq_funcs);
+       fdtbus_register_mmc_pwrseq(self, phandle, &mmcpwrseq_simple_funcs);
 }
 
-CFATTACH_DECL_NEW(mmcpwrseq, sizeof(struct mmcpwrseq_softc),
-       mmcpwrseq_match, mmcpwrseq_attach, NULL, NULL);
+CFATTACH_DECL_NEW(mmcpwrseq_simple, sizeof(struct mmcpwrseq_simple_softc),
+       mmcpwrseq_simple_match, mmcpwrseq_simple_attach, NULL, NULL);



Home | Main Index | Thread Index | Old Index