From owner-dev-commits-src-main@freebsd.org Wed Jan 6 21:38:04 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 633CE4DFD5E; Wed, 6 Jan 2021 21:38:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DB2lw2Q5Wz3KsG; Wed, 6 Jan 2021 21:38:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4200E25A2E; Wed, 6 Jan 2021 21:38:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 106Lc4e6065288; Wed, 6 Jan 2021 21:38:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 106Lc4gE065287; Wed, 6 Jan 2021 21:38:04 GMT (envelope-from git) Date: Wed, 6 Jan 2021 21:38:04 GMT Message-Id: <202101062138.106Lc4gE065287@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Marcin Wojtas Subject: git: 39c24889b022 - main - arm64: QorIQ: gpio: Cleanup qoriq_gpio_* helpers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 39c24889b0222dc7e734445ee765a7d22abbd543 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jan 2021 21:38:04 -0000 The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=39c24889b0222dc7e734445ee765a7d22abbd543 commit 39c24889b0222dc7e734445ee765a7d22abbd543 Author: Marcin Wojtas AuthorDate: 2021-01-06 14:15:55 +0000 Commit: Marcin Wojtas 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 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);