Module Name:    src
Committed By:   jmcneill
Date:           Sun Mar  3 12:54:07 UTC 2019

Modified Files:
        src/sys/dev/fdt: files.fdt mmc_pwrseq_simple.c
Added Files:
        src/sys/dev/fdt: mmc_pwrseq_emmc.c

Log Message:
Add eMMC reset sequence provider


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/mmc_pwrseq_emmc.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/fdt/mmc_pwrseq_simple.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.42 src/sys/dev/fdt/files.fdt:1.43
--- src/sys/dev/fdt/files.fdt:1.42	Wed Jan 30 01:24:00 2019
+++ src/sys/dev/fdt/files.fdt	Sun Mar  3 12:54:07 2019
@@ -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 @@ attach	cpus at fdt
 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

Index: src/sys/dev/fdt/mmc_pwrseq_simple.c
diff -u src/sys/dev/fdt/mmc_pwrseq_simple.c:1.1 src/sys/dev/fdt/mmc_pwrseq_simple.c:1.2
--- src/sys/dev/fdt/mmc_pwrseq_simple.c:1.1	Sun Oct 22 13:56:49 2017
+++ src/sys/dev/fdt/mmc_pwrseq_simple.c	Sun Mar  3 12:54:07 2019
@@ -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 <jmcne...@invisible.ca>
@@ -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 @@ static const char * const compatible[] =
 	NULL
 };
 
-struct mmcpwrseq_softc {
+struct mmcpwrseq_simple_softc {
 	device_t sc_dev;
 	int sc_phandle;
 	struct clk *sc_clk;
@@ -56,9 +56,9 @@ struct mmcpwrseq_softc {
 };
 
 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 @@ mmcpwrseq_pre_power_on(device_t dev)
 }
 
 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 @@ mmcpwrseq_post_power_on(device_t dev)
 }
 
 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 @@ mmcpwrseq_power_off(device_t dev)
 		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 @@ mmcpwrseq_match(device_t parent, cfdata_
 }
 
 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 @@ mmcpwrseq_attach(device_t parent, device
 	    &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);

Added files:

Index: src/sys/dev/fdt/mmc_pwrseq_emmc.c
diff -u /dev/null src/sys/dev/fdt/mmc_pwrseq_emmc.c:1.1
--- /dev/null	Sun Mar  3 12:54:07 2019
+++ src/sys/dev/fdt/mmc_pwrseq_emmc.c	Sun Mar  3 12:54:07 2019
@@ -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 <jmcne...@invisible.ca>
+ * 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);

Reply via email to