Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Jan 2021 21:38:04 GMT
From:      Marcin Wojtas <mw@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 39c24889b022 - main - arm64: QorIQ: gpio: Cleanup qoriq_gpio_* helpers
Message-ID:  <202101062138.106Lc4gE065287@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=39c24889b0222dc7e734445ee765a7d22abbd543

commit 39c24889b0222dc7e734445ee765a7d22abbd543
Author:     Marcin Wojtas <mw@FreeBSD.org>
AuthorDate: 2021-01-06 14:15:55 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2021-01-06 21:37:21 +0000

    arm64: QorIQ: gpio: Cleanup qoriq_gpio_* helpers
    
    Replace various hw reg bit set/clear helpers with a universal
    `qoriq_gpio_set` function.
    
    Submitted by: Artur Rojek <ar@semihalf.com>
    Reviewed by: mmel
    Obtained from: Semihalf
    Sponsored by: Alstom Group
    Differential Revision: https://reviews.freebsd.org/D26868
---
 sys/arm64/qoriq/ls1046_gpio.c | 91 ++++++-------------------------------------
 1 file changed, 12 insertions(+), 79 deletions(-)

diff --git a/sys/arm64/qoriq/ls1046_gpio.c b/sys/arm64/qoriq/ls1046_gpio.c
index 19695e36564e..89b98c55663b 100644
--- a/sys/arm64/qoriq/ls1046_gpio.c
+++ b/sys/arm64/qoriq/ls1046_gpio.c
@@ -83,12 +83,7 @@ struct gpio_softc {
 static bool qoriq_make_gpio_res(device_t, struct gpio_res*);
 static uint32_t qoriq_gpio_reg_read(device_t, uint32_t);
 static void qoriq_gpio_reg_write(device_t, uint32_t, uint32_t);
-static void qoriq_gpio_reg_set(device_t, uint32_t, uint32_t);
-static void qoriq_gpio_reg_clear(device_t, uint32_t, uint32_t);
-static void qoriq_gpio_out_en(device_t, uint32_t, uint8_t);
-static void qoriq_gpio_value_set(device_t, uint32_t, uint8_t);
-static uint32_t qoriq_gpio_value_get(device_t, uint32_t);
-static void qoriq_gpio_open_drain_set(device_t, uint32_t, uint8_t);
+static void qoriq_gpio_set(device_t, uint32_t, uint32_t, uint32_t);
 static int qoriq_gpio_configure(device_t, uint32_t, uint32_t);
 
 /* GPIO API */
@@ -180,75 +175,13 @@ qoriq_gpio_reg_write(device_t dev, uint32_t reg, uint32_t val)
 }
 
 static void
-qoriq_gpio_reg_set(device_t dev, uint32_t reg, uint32_t pin)
+qoriq_gpio_set(device_t dev, uint32_t reg, uint32_t pin, uint32_t set)
 {
-	uint32_t reg_val;
+	uint32_t val;
 
-	reg_val = qoriq_gpio_reg_read(dev, reg);
-	reg_val |= GPIO(pin);
-	qoriq_gpio_reg_write(dev, reg, reg_val);
-}
-
-static void
-qoriq_gpio_reg_clear(device_t dev, uint32_t reg, uint32_t pin)
-{
-	uint32_t reg_val;
-
-	reg_val = qoriq_gpio_reg_read(dev, reg);
-	reg_val &= ~(GPIO(pin));
-	qoriq_gpio_reg_write(dev, reg, reg_val);
-}
-
-static void
-qoriq_gpio_out_en(device_t dev, uint32_t pin, uint8_t enable)
-{
-
-	if (pin >= PIN_COUNT)
-		return;
-
-	if (enable != 0)
-		qoriq_gpio_reg_set(dev, DIRECTION, pin);
-	else
-		qoriq_gpio_reg_clear(dev, DIRECTION, pin);
-}
-
-static void
-qoriq_gpio_value_set(device_t dev, uint32_t pin, uint8_t val)
-{
-
-	if (pin >= PIN_COUNT)
-		return;
-
-	if (val != 0)
-		qoriq_gpio_reg_set(dev, DATA, pin);
-	else
-		qoriq_gpio_reg_clear(dev, DATA, pin);
-}
-
-static uint32_t
-qoriq_gpio_value_get(device_t dev, uint32_t pin)
-{
-	uint32_t reg_val;
-
-	if (pin >= PIN_COUNT)
-		return (0);
-
-	reg_val = qoriq_gpio_reg_read(dev, DATA);
-
-	return ((reg_val & GPIO(pin)) != 0);
-}
-
-static void
-qoriq_gpio_open_drain_set(device_t dev, uint32_t pin, uint8_t val)
-{
-
-	if (pin >= PIN_COUNT)
-		return;
-
-	if (val != 0)
-		qoriq_gpio_reg_set(dev, OPEN_DRAIN, pin);
-	else
-		qoriq_gpio_reg_clear(dev, OPEN_DRAIN, pin);
+	set = set != 0;
+	val = (qoriq_gpio_reg_read(dev, reg) & ~(1U << pin)) | (set << pin);
+	qoriq_gpio_reg_write(dev, reg, val);
 }
 
 static int
@@ -272,19 +205,19 @@ qoriq_gpio_configure(device_t dev, uint32_t pin, uint32_t flags)
 
 	if (flags & GPIO_PIN_INPUT) {
 		newflags = GPIO_PIN_INPUT;
-		qoriq_gpio_out_en(dev, pin, 0);
+		qoriq_gpio_set(dev, DIRECTION, pin, 0);
 	}
 
 	if (flags & GPIO_PIN_OUTPUT) {
 		newflags = GPIO_PIN_OUTPUT;
-		qoriq_gpio_out_en(dev, pin, 1);
+		qoriq_gpio_set(dev, DIRECTION, pin, 1);
 
 		if (flags & GPIO_PIN_OPENDRAIN) {
 			newflags |= GPIO_PIN_OPENDRAIN;
-			qoriq_gpio_open_drain_set(dev, pin, 1);
+			qoriq_gpio_set(dev, OPEN_DRAIN, pin, 1);
 		} else {
 			newflags |= GPIO_PIN_PUSHPULL;
-			qoriq_gpio_open_drain_set(dev, pin, 0);
+			qoriq_gpio_set(dev, OPEN_DRAIN, pin, 0);
 		}
 	}
 
@@ -425,7 +358,7 @@ qoriq_gpio_pin_get(device_t dev, uint32_t pin, uint32_t *value)
 		return (EINVAL);
 
 	QORIQ_GPIO_LOCK(sc);
-	*value = qoriq_gpio_value_get(dev, pin);
+	*value = (qoriq_gpio_reg_read(dev, DATA) & GPIO(pin)) != 0;
 	QORIQ_GPIO_UNLOCK(sc);
 
 	return (0);
@@ -440,7 +373,7 @@ qoriq_gpio_pin_set(device_t dev, uint32_t pin, uint32_t value)
 		return (EINVAL);
 
 	QORIQ_GPIO_LOCK(sc);
-	qoriq_gpio_value_set(dev, pin, value);
+	qoriq_gpio_set(dev, DATA, pin, value);
 	QORIQ_GPIO_UNLOCK(sc);
 
 	return (0);



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