From patchwork Wed Jul 1 17:26:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 240639 List-Id: U-Boot discussion From: sebastian.reichel at collabora.com (Sebastian Reichel) Date: Wed, 1 Jul 2020 19:26:16 +0200 Subject: [PATCH 03/12] gpio: mxc_gpio: add support to read status of output gpios In-Reply-To: <20200701172625.121978-1-sebastian.reichel@collabora.com> References: <20200701172625.121978-1-sebastian.reichel@collabora.com> Message-ID: <20200701172625.121978-4-sebastian.reichel@collabora.com> This is supported by the hardware when the pinmux is configured correctly. Usually it is not, so this adds explicit code for this. This fixes all GPIO regulators being shown as disabled. Signed-off-by: Sebastian Reichel --- drivers/gpio/mxc_gpio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index c924e52f0713..a3df636e60b9 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -203,6 +203,11 @@ static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset, writel(l, ®s->gpio_dr); } +static int mxc_gpio_bank_get_out_value(struct gpio_regs *regs, int offset) +{ + return (readl(®s->gpio_dr) >> offset) & 1; +} + static int mxc_gpio_bank_get_value(struct gpio_regs *regs, int offset) { return (readl(®s->gpio_psr) >> offset) & 0x01; @@ -239,7 +244,10 @@ static int mxc_gpio_get_value(struct udevice *dev, unsigned offset) { struct mxc_bank_info *bank = dev_get_priv(dev); - return mxc_gpio_bank_get_value(bank->regs, offset); + if (mxc_gpio_is_output(bank->regs, offset)) + return mxc_gpio_bank_get_out_value(bank->regs, offset); + else + return mxc_gpio_bank_get_value(bank->regs, offset); } /* write GPIO OUT value to pin 'gpio' */