Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Sep 2016 20:34:15 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r305438 - stable/11/sys/arm/allwinner
Message-ID:  <201609052034.u85KYF0F068978@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Mon Sep  5 20:34:15 2016
New Revision: 305438
URL: https://svnweb.freebsd.org/changeset/base/305438

Log:
  MFC r304289
  
  a10_gpio_get_function now returns the whole function not only
  GPIO_INPUT/GPIO_OUTPUT.
  a10_gpio_get_pud now returns the whole pud not only PULLDOWN/PULLUP.
  Add a10_gpio_get_drv to get the current drive strenght.
  During fdt pin configure, avoid setting function/drive/pud if it's already in
  the correct value.
  
  Tested on Allwinner H3 and A20

Modified:
  stable/11/sys/arm/allwinner/a10_gpio.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/allwinner/a10_gpio.c
==============================================================================
--- stable/11/sys/arm/allwinner/a10_gpio.c	Mon Sep  5 20:29:04 2016	(r305437)
+++ stable/11/sys/arm/allwinner/a10_gpio.c	Mon Sep  5 20:34:15 2016	(r305438)
@@ -196,14 +196,8 @@ a10_gpio_get_function(struct a10_gpio_so
 	offset = ((pin & 0x07) << 2);
 
 	func = A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, pin >> 3));
-	switch ((func >> offset) & 0x7) {
-	case A10_GPIO_INPUT:
-		return (GPIO_PIN_INPUT);
-	case A10_GPIO_OUTPUT:
-		return (GPIO_PIN_OUTPUT);
-	}
 
-	return (0);
+	return ((func >> offset) & 0x7);
 }
 
 static int
@@ -243,14 +237,8 @@ a10_gpio_get_pud(struct a10_gpio_softc *
 	offset = ((pin & 0x0f) << 1);
 
 	val = A10_GPIO_READ(sc, A10_GPIO_GP_PUL(bank, pin >> 4));
-	switch ((val >> offset) & 0x3) {
-	case A10_GPIO_PULLDOWN:
-		return (GPIO_PIN_PULLDOWN);
-	case A10_GPIO_PULLUP:
-		return (GPIO_PIN_PULLUP);
-	}
 
-	return (0);
+	return ((val >> offset) & AW_GPIO_PUD_MASK);
 }
 
 static void
@@ -271,6 +259,23 @@ a10_gpio_set_pud(struct a10_gpio_softc *
 	A10_GPIO_WRITE(sc, A10_GPIO_GP_PUL(bank, pin >> 4), val);
 }
 
+static uint32_t
+a10_gpio_get_drv(struct a10_gpio_softc *sc, uint32_t pin)
+{
+	uint32_t bank, offset, val;
+
+	/* Must be called with lock held. */
+	A10_GPIO_LOCK_ASSERT(sc);
+
+	bank = sc->padconf->pins[pin].port;
+	pin = sc->padconf->pins[pin].pin;
+	offset = ((pin & 0x0f) << 1);
+
+	val = A10_GPIO_READ(sc, A10_GPIO_GP_DRV(bank, pin >> 4));
+
+	return ((val >> offset) & AW_GPIO_DRV_MASK);
+}
+
 static void
 a10_gpio_set_drv(struct a10_gpio_softc *sc, uint32_t pin, uint32_t drive)
 {
@@ -359,14 +364,39 @@ static int
 a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
 {
 	struct a10_gpio_softc *sc;
+	uint32_t func;
+	uint32_t pud;
 
 	sc = device_get_softc(dev);
 	if (pin >= sc->padconf->npins)
 		return (EINVAL);
 
 	A10_GPIO_LOCK(sc);
-	*flags = a10_gpio_get_function(sc, pin);
-	*flags |= a10_gpio_get_pud(sc, pin);
+	func = a10_gpio_get_function(sc, pin);
+	switch (func) {
+	case A10_GPIO_INPUT:
+		*flags = GPIO_PIN_INPUT;
+		break;
+	case A10_GPIO_OUTPUT:
+		*flags = GPIO_PIN_OUTPUT;
+		break;
+	default:
+		*flags = 0;
+		break;
+	}
+
+	pud = a10_gpio_get_pud(sc, pin);
+	switch (pud) {
+	case A10_GPIO_PULLDOWN:
+		*flags |= GPIO_PIN_PULLDOWN;
+		break;
+	case A10_GPIO_PULLUP:
+		*flags |= GPIO_PIN_PULLUP;
+		break;
+	default:
+		break;
+	}
+
 	A10_GPIO_UNLOCK(sc);
 
 	return (0);
@@ -550,9 +580,13 @@ aw_fdt_configure_pins(device_t dev, phan
 		}
 
 		A10_GPIO_LOCK(sc);
-		a10_gpio_set_function(sc, pin_num, pin_func);
-		a10_gpio_set_drv(sc, pin_num, pin_drive);
-		a10_gpio_set_pud(sc, pin_num, pin_pull);
+
+		if (a10_gpio_get_function(sc, pin_num) != pin_func)
+			a10_gpio_set_function(sc, pin_num, pin_func);
+		if (a10_gpio_get_drv(sc, pin_num) != pin_drive)
+			a10_gpio_set_drv(sc, pin_num, pin_drive);
+		if (a10_gpio_get_pud(sc, pin_num) != pin_pull)
+			a10_gpio_set_pud(sc, pin_num, pin_pull);
 		A10_GPIO_UNLOCK(sc);
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609052034.u85KYF0F068978>