diff --git a/sys/arch/arm/broadcom/bcm2835_gpio_subr.c b/sys/arch/arm/broadcom/bcm2835_gpio_subr.c index 7102fe7e8421..48d3b3611d32 100644 --- a/sys/arch/arm/broadcom/bcm2835_gpio_subr.c +++ b/sys/arch/arm/broadcom/bcm2835_gpio_subr.c @@ -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 -__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 #include @@ -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); +} diff --git a/sys/arch/arm/broadcom/bcm2835_gpio_subr.h b/sys/arch/arm/broadcom/bcm2835_gpio_subr.h index f0d9c2d245ec..74112ba7fd7a 100644 --- a/sys/arch/arm/broadcom/bcm2835_gpio_subr.h +++ b/sys/arch/arm/broadcom/bcm2835_gpio_subr.h @@ -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_ */ diff --git a/sys/arch/evbarm/rpi/rpi_machdep.c b/sys/arch/evbarm/rpi/rpi_machdep.c index df94994dcaa4..9794f903e639 100644 --- a/sys/arch/evbarm/rpi/rpi_machdep.c +++ b/sys/arch/evbarm/rpi/rpi_machdep.c @@ -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 -__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 }