From: Niall Leonard <nl250060@ncr.com>
Use the existing shadow data register 'bgpio_data' to allow
the last written value to be returned by the read operation
when BGPIOF_NO_INPUT flag is set.
Signed-off-by: Niall Leonard <nl250060@ncr.com>
---
drivers/gpio/gpio-mmio.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index d9dff3dc92ae..7125bd8caaa4 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -164,6 +164,11 @@ static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask,
return 0;
}
+static int bgpio_get_shadow(struct gpio_chip *gc, unsigned int gpio)
+{
+ return !!(gc->bgpio_data & bgpio_line2mask(gc, gpio));
+}
+
static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
{
return !!(gc->read_reg(gc->reg_dat) & bgpio_line2mask(gc, gpio));
@@ -526,7 +531,10 @@ static int bgpio_setup_io(struct gpio_chip *gc,
* reading each line individually in that fringe case.
*/
} else {
- gc->get = bgpio_get;
+ if (flags & BGPIOF_NO_INPUT)
+ gc->get = bgpio_get_shadow;
+ else
+ gc->get = bgpio_get;
if (gc->be_bits)
gc->get_multiple = bgpio_get_multiple_be;
else
@@ -630,7 +638,11 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
if (ret)
return ret;
- gc->bgpio_data = gc->read_reg(gc->reg_dat);
+ if (flags & BGPIOF_NO_INPUT)
+ gc->bgpio_data = 0;
+ else
+ gc->bgpio_data = gc->read_reg(gc->reg_dat);
+
if (gc->set == bgpio_set_set &&
!(flags & BGPIOF_UNREADABLE_REG_SET))
gc->bgpio_data = gc->read_reg(gc->reg_set);
@@ -711,6 +723,9 @@ static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
if (of_property_read_bool(pdev->dev.of_node, "no-output"))
*flags |= BGPIOF_NO_OUTPUT;
+ if (of_property_read_bool(pdev->dev.of_node, "no-input"))
+ *flags |= BGPIOF_NO_INPUT;
+
return pdata;
}
#else
--
2.34.1
On 26/01/2023 11:17, Niall Leonard via B4 Submission Endpoint wrote: > From: Niall Leonard <nl250060@ncr.com> > > Use the existing shadow data register 'bgpio_data' to allow > the last written value to be returned by the read operation > when BGPIOF_NO_INPUT flag is set. > (...) > if (gc->set == bgpio_set_set && > !(flags & BGPIOF_UNREADABLE_REG_SET)) > gc->bgpio_data = gc->read_reg(gc->reg_set); > @@ -711,6 +723,9 @@ static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev, > if (of_property_read_bool(pdev->dev.of_node, "no-output")) > *flags |= BGPIOF_NO_OUTPUT; > > + if (of_property_read_bool(pdev->dev.of_node, "no-input")) As pointed, this brings undocumented property to two other bindings. This needs to be fixed. Best regards, Krzysztof
On 29/01/2023 16:01, Krzysztof Kozlowski wrote: > *External Message* - Use caution before opening links or attachments > > On 26/01/2023 11:17, Niall Leonard via B4 Submission Endpoint wrote: >> From: Niall Leonard <nl250060@ncr.com> >> >> Use the existing shadow data register 'bgpio_data' to allow >> the last written value to be returned by the read operation >> when BGPIOF_NO_INPUT flag is set. >> > > (...) > >> if (gc->set == bgpio_set_set && >> !(flags & BGPIOF_UNREADABLE_REG_SET)) >> gc->bgpio_data = gc->read_reg(gc->reg_set); >> @@ -711,6 +723,9 @@ static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev, >> if (of_property_read_bool(pdev->dev.of_node, "no-output")) >> *flags |= BGPIOF_NO_OUTPUT; >> >> + if (of_property_read_bool(pdev->dev.of_node, "no-input")) > > As pointed, this brings undocumented property to two other bindings. > This needs to be fixed. > > Best regards, > Krzysztof > Thanks for reviewing. I will update the other 2 bindings in the next version. Regards, Niall Leonard
On Thu, Jan 26, 2023 at 11:18 AM Niall Leonard via B4 Submission Endpoint <devnull+nl250060.ncr.com@kernel.org> wrote: > From: Niall Leonard <nl250060@ncr.com> > > Use the existing shadow data register 'bgpio_data' to allow > the last written value to be returned by the read operation > when BGPIOF_NO_INPUT flag is set. > > Signed-off-by: Niall Leonard <nl250060@ncr.com> Weird hardware, but given these restrictions it makes perfect sense to have this. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
© 2016 - 2025 Red Hat, Inc.