Module Name:    src
Committed By:   jmcneill
Date:           Sun Jul 30 17:32:59 UTC 2017

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_gpio_subr.c bcm2835_gpio_subr.h
        src/sys/arch/evbarm/rpi: rpi_machdep.c

Log Message:
Explicitly configure pin pull-down/up settings for SDIO.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/broadcom/bcm2835_gpio_subr.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/evbarm/rpi/rpi_machdep.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/arch/arm/broadcom/bcm2835_gpio_subr.c
diff -u src/sys/arch/arm/broadcom/bcm2835_gpio_subr.c:1.4 src/sys/arch/arm/broadcom/bcm2835_gpio_subr.c:1.5
--- src/sys/arch/arm/broadcom/bcm2835_gpio_subr.c:1.4	Tue Feb  2 13:55:50 2016
+++ src/sys/arch/arm/broadcom/bcm2835_gpio_subr.c	Sun Jul 30 17:32:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_gpio_subr.c,v 1.4 2016/02/02 13:55:50 skrll Exp $	*/
+/*	$NetBSD: bcm2835_gpio_subr.c,v 1.5 2017/07/30 17:32:59 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio_subr.c,v 1.4 2016/02/02 13:55:50 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio_subr.c,v 1.5 2017/07/30 17:32:59 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -84,3 +84,20 @@ bcm2835gpio_function_read(u_int pin)
 
 	return ((v >> shift) & mask);
 }
+
+void
+bcm2835gpio_function_setpull(u_int pin, u_int pud)
+{
+	const paddr_t iop = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_GPIO_BASE);
+	const bus_space_tag_t iot = &bcm2835_bs_tag;
+	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(iop);
+	const u_int mask = 1 << (pin % BCM2835_GPIO_GPPUD_PINS_PER_REGISTER);
+	const u_int regid = (pin / BCM2835_GPIO_GPPUD_PINS_PER_REGISTER);
+
+	bus_space_write_4(iot, ioh, BCM2835_GPIO_GPPUD, pud);
+	delay(1);
+	bus_space_write_4(iot, ioh, BCM2835_GPIO_GPPUDCLK(regid), mask);
+	delay(1);
+	bus_space_write_4(iot, ioh, BCM2835_GPIO_GPPUD, 0);
+	bus_space_write_4(iot, ioh, BCM2835_GPIO_GPPUDCLK(regid), 0);
+}

Index: src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h
diff -u src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h:1.2 src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h:1.3
--- src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h:1.2	Tue Apr 22 18:51:35 2014
+++ src/sys/arch/arm/broadcom/bcm2835_gpio_subr.h	Sun Jul 30 17:32:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_gpio_subr.h,v 1.2 2014/04/22 18:51:35 kardel Exp $	*/
+/*	$NetBSD: bcm2835_gpio_subr.h,v 1.3 2017/07/30 17:32:59 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -33,5 +33,6 @@
 
 void  bcm2835gpio_function_select(u_int, u_int);
 u_int bcm2835gpio_function_read(u_int);
+void  bcm2835gpio_function_setpull(u_int, u_int);
 
 #endif /* _BROADCOM_BCM2835_GPIOVAR_H_ */

Index: src/sys/arch/evbarm/rpi/rpi_machdep.c
diff -u src/sys/arch/evbarm/rpi/rpi_machdep.c:1.73 src/sys/arch/evbarm/rpi/rpi_machdep.c:1.74
--- src/sys/arch/evbarm/rpi/rpi_machdep.c:1.73	Sun Jul 30 16:54:36 2017
+++ src/sys/arch/evbarm/rpi/rpi_machdep.c	Sun Jul 30 17:32:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpi_machdep.c,v 1.73 2017/07/30 16:54:36 jmcneill Exp $	*/
+/*	$NetBSD: rpi_machdep.c,v 1.74 2017/07/30 17:32:59 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.73 2017/07/30 16:54:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.74 2017/07/30 17:32:59 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bcm283x.h"
@@ -492,6 +492,9 @@ rpi_pinctrl(void)
 	for (int pin = 34; pin <= 39; pin++) {
 		/* Enable SDHCI on SDIO */
 		bcm2835gpio_function_select(pin, BCM2835_GPIO_ALT3);
+		bcm2835gpio_function_setpull(pin,
+		    pin == 34 ? BCM2835_GPIO_GPPUD_PULLOFF :
+		    BCM2835_GPIO_GPPUD_PULLUP);
 	}
 #endif
 }

Reply via email to