Module Name:    src
Committed By:   riz
Date:           Sun Nov  8 01:22:54 UTC 2015

Modified Files:
        src/sys/arch/arm/omap [netbsd-7]: omap3_sdhc.c
        src/sys/arch/evbarm/beagle [netbsd-7]: beagle_machdep.c
        src/sys/dev/sdmmc [netbsd-7]: sdhc.c sdhcvar.h

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1022):
        sys/dev/sdmmc/sdhc.c: revision 1.89
        sys/arch/arm/omap/omap3_sdhc.c: revision 1.19
        sys/dev/sdmmc/sdhcvar.h: revision 1.25
        sys/arch/evbarm/beagle/beagle_machdep.c: revision 1.62
allow vendor specific code to hook into bus width changes
Support 8-bit eMMC for TI AM335x. On my BeagleBone Black,
Before: 134217728 bytes transferred in 9.410 secs (14263307 bytes/sec)
After:  134217728 bytes transferred in 7.518 secs (17852850 bytes/sec)
enable 8-bit mode on AM335X SDMMC2


To generate a diff of this commit:
cvs rdiff -u -r1.14.4.1 -r1.14.4.2 src/sys/arch/arm/omap/omap3_sdhc.c
cvs rdiff -u -r1.60 -r1.60.2.1 src/sys/arch/evbarm/beagle/beagle_machdep.c
cvs rdiff -u -r1.44.2.8 -r1.44.2.9 src/sys/dev/sdmmc/sdhc.c
cvs rdiff -u -r1.13.12.3 -r1.13.12.4 src/sys/dev/sdmmc/sdhcvar.h

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

Modified files:

Index: src/sys/arch/arm/omap/omap3_sdhc.c
diff -u src/sys/arch/arm/omap/omap3_sdhc.c:1.14.4.1 src/sys/arch/arm/omap/omap3_sdhc.c:1.14.4.2
--- src/sys/arch/arm/omap/omap3_sdhc.c:1.14.4.1	Sun Apr 19 04:37:17 2015
+++ src/sys/arch/arm/omap/omap3_sdhc.c	Sun Nov  8 01:22:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: omap3_sdhc.c,v 1.14.4.1 2015/04/19 04:37:17 msaitoh Exp $	*/
+/*	$NetBSD: omap3_sdhc.c,v 1.14.4.2 2015/11/08 01:22:54 riz Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.14.4.1 2015/04/19 04:37:17 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.14.4.2 2015/11/08 01:22:54 riz Exp $");
 
 #include "opt_omap.h"
 #include "edma.h"
@@ -51,6 +51,8 @@ __KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c
 #ifdef TI_AM335X
 #  include <arm/omap/am335x_prcm.h>
 #  include <arm/omap/omap2_prcm.h>
+#  include <arm/omap/sitara_cm.h>
+#  include <arm/omap/sitara_cmreg.h>
 #endif
 
 #if NEDMA > 0
@@ -84,6 +86,7 @@ static int obiosdhc_match(device_t, cfda
 static void obiosdhc_attach(device_t, device_t, void *);
 static int obiosdhc_detach(device_t, int);
 
+static int obiosdhc_bus_width(struct sdhc_softc *, int);
 static int obiosdhc_bus_clock(struct sdhc_softc *, int);
 static int obiosdhc_rod(struct sdhc_softc *, int);
 static int obiosdhc_write_protect(struct sdhc_softc *);
@@ -129,6 +132,24 @@ static const struct am335x_sdhc am335x_s
 	{ "MMC1",   SDMMC2_BASE_TIAM335X, 28, { AM335X_PRCM_CM_PER, 0xf4 } },
 	{ "MMCHS2", SDMMC3_BASE_TIAM335X, 29, { AM335X_PRCM_CM_WKUP, 0xf8 } },
 };
+
+struct am335x_padconf {
+	const char *padname;
+	const char *padmode;
+};
+const struct am335x_padconf am335x_padconf_mmc1[] = {
+	{ "GPMC_CSn1", "mmc1_clk" },
+	{ "GPMC_CSn2", "mmc1_cmd" },
+	{ "GPMC_AD0", "mmc1_dat0" },
+	{ "GPMC_AD1", "mmc1_dat1" },
+	{ "GPMC_AD2", "mmc1_dat2" },
+	{ "GPMC_AD3", "mmc1_dat3" },
+	{ "GPMC_AD4", "mmc1_dat4" },
+	{ "GPMC_AD5", "mmc1_dat5" },
+	{ "GPMC_AD6", "mmc1_dat6" },
+	{ "GPMC_AD7", "mmc1_dat7" },
+	{ NULL, NULL }
+};
 #endif
 
 CFATTACH_DECL_NEW(obiosdhc, sizeof(struct obiosdhc_softc),
@@ -213,6 +234,7 @@ obiosdhc_attach(device_t parent, device_
 	sc->sc.sc_vendor_write_protect = obiosdhc_write_protect;
 	sc->sc.sc_vendor_card_detect = obiosdhc_card_detect;
 	sc->sc.sc_vendor_bus_clock = obiosdhc_bus_clock;
+	sc->sc.sc_vendor_bus_width = obiosdhc_bus_width;
 	sc->sc_bst = oa->obio_iot;
 
 	clksft = ffs(sc->sc.sc_clkmsk) - 1;
@@ -256,6 +278,27 @@ obiosdhc_attach(device_t parent, device_
 			break;
 		}
 	KASSERT(i < __arraycount(am335x_sdhc));
+
+	if (oa->obio_addr == SDMMC2_BASE_TIAM335X) {
+		const char *mode;
+		u_int state;
+		
+		const struct am335x_padconf *padconf = am335x_padconf_mmc1;
+		for (i = 0; padconf[i].padname; i++) {
+			const char *padname = padconf[i].padname;
+			const char *padmode = padconf[i].padmode;
+			if (sitara_cm_padconf_get(padname, &mode, &state) == 0) {
+				aprint_debug_dev(self, "%s mode %s state %d\n",
+				    padname, mode, state);
+			}
+			if (sitara_cm_padconf_set(padname, padmode,
+			    (1 << 4) | (1 << 5)) != 0) {
+				aprint_error_dev(self, "can't switch %s pad from %s to %s\n",
+				    padname, mode, padmode);
+				return;
+			}
+		}
+	}
 #endif
 
 	/* XXXXXX: Turn-on regurator via I2C. */
@@ -417,6 +460,23 @@ obiosdhc_card_detect(struct sdhc_softc *
 }
 
 static int
+obiosdhc_bus_width(struct sdhc_softc *sc, int width)
+{
+	struct obiosdhc_softc *osc = (struct obiosdhc_softc *)sc;
+	uint32_t con;
+
+	con = bus_space_read_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON);
+	if (width == 8) {
+		con |= CON_DW8;
+	} else {
+		con &= ~CON_DW8;
+	}
+	bus_space_write_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON, con);
+
+	return 0;
+}
+
+static int
 obiosdhc_bus_clock(struct sdhc_softc *sc, int clk)
 {
 	struct obiosdhc_softc *osc = (struct obiosdhc_softc *)sc;

Index: src/sys/arch/evbarm/beagle/beagle_machdep.c
diff -u src/sys/arch/evbarm/beagle/beagle_machdep.c:1.60 src/sys/arch/evbarm/beagle/beagle_machdep.c:1.60.2.1
--- src/sys/arch/evbarm/beagle/beagle_machdep.c:1.60	Mon Jul 21 22:17:44 2014
+++ src/sys/arch/evbarm/beagle/beagle_machdep.c	Sun Nov  8 01:22:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: beagle_machdep.c,v 1.60 2014/07/21 22:17:44 riz Exp $ */
+/*	$NetBSD: beagle_machdep.c,v 1.60.2.1 2015/11/08 01:22:54 riz Exp $ */
 
 /*
  * Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.60 2014/07/21 22:17:44 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.60.2.1 2015/11/08 01:22:54 riz Exp $");
 
 #include "opt_machdep.h"
 #include "opt_ddb.h"
@@ -1084,7 +1084,7 @@ beagle_device_register(device_t self, vo
 		prop_dictionary_set_uint32(dict, "clkmask", 0);
 		prop_dictionary_set_bool(dict, "8bit", true);
 #endif
-#if defined(TI_AM335X) && 0	// doesn't work
+#if defined(TI_AM335X)
 		struct obio_attach_args * const obio = aux;
 		if (obio->obio_addr == SDMMC2_BASE_TIAM335X)
 			prop_dictionary_set_bool(dict, "8bit", true);

Index: src/sys/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.44.2.8 src/sys/dev/sdmmc/sdhc.c:1.44.2.9
--- src/sys/dev/sdmmc/sdhc.c:1.44.2.8	Sun Apr 19 04:31:40 2015
+++ src/sys/dev/sdmmc/sdhc.c	Sun Nov  8 01:22:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.44.2.8 2015/04/19 04:31:40 msaitoh Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.44.2.9 2015/11/08 01:22:54 riz Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.44.2.8 2015/04/19 04:31:40 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.44.2.9 2015/11/08 01:22:54 riz Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -1000,6 +1000,12 @@ sdhc_bus_width(sdmmc_chipset_handle_t sc
 		return 1;
 	}
 
+	if (hp->sc->sc_vendor_bus_width) {
+		const int error = hp->sc->sc_vendor_bus_width(hp->sc, width);
+		if (error != 0)
+			return error;
+	}
+
 	mutex_enter(&hp->host_mtx);
 	reg = HREAD1(hp, SDHC_HOST_CTL);
 	if (ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED)) {

Index: src/sys/dev/sdmmc/sdhcvar.h
diff -u src/sys/dev/sdmmc/sdhcvar.h:1.13.12.3 src/sys/dev/sdmmc/sdhcvar.h:1.13.12.4
--- src/sys/dev/sdmmc/sdhcvar.h:1.13.12.3	Sun Apr 19 04:31:40 2015
+++ src/sys/dev/sdmmc/sdhcvar.h	Sun Nov  8 01:22:54 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhcvar.h,v 1.13.12.3 2015/04/19 04:31:40 msaitoh Exp $	*/
+/*	$NetBSD: sdhcvar.h,v 1.13.12.4 2015/11/08 01:22:54 riz Exp $	*/
 /*	$OpenBSD: sdhcvar.h,v 1.3 2007/09/06 08:01:01 jsg Exp $	*/
 
 /*
@@ -60,6 +60,7 @@ struct sdhc_softc {
 	int (*sc_vendor_rod)(struct sdhc_softc *, int);
 	int (*sc_vendor_write_protect)(struct sdhc_softc *);
 	int (*sc_vendor_card_detect)(struct sdhc_softc *);
+	int (*sc_vendor_bus_width)(struct sdhc_softc *, int);
 	int (*sc_vendor_bus_clock)(struct sdhc_softc *, int);
 	int (*sc_vendor_transfer_data_dma)(struct sdhc_softc *, struct sdmmc_command *);
 };

Reply via email to