Skip to content

Commit

Permalink
pinctrl: rockchip: enable clock when reading pin direction register
Browse files Browse the repository at this point in the history
We generally leave the GPIO clock disabled, unless an interrupt is
requested or we're accessing IO registers. We forgot to do this for the
->get_direction() callback, which means we can sometimes [1] get
incorrect results [2] from, e.g., /sys/kernel/debug/gpio.

Enable the clock, so we get the right results!

[1] Sometimes, because many systems have 1 or mor interrupt requested on
each GPIO bank, so they always leave their clock on.

[2] Incorrect, meaning the register returns 0, and so we interpret that
as "input".

Signed-off-by: Brian Norris <[email protected]>
Reviewed-by: Heiko Stuebner <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
computersforpeace authored and linusw committed Dec 20, 2017
1 parent 51802d1 commit 5c9d8c4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/pinctrl/pinctrl-rockchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,8 +2014,16 @@ static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{
struct rockchip_pin_bank *bank = gpiochip_get_data(chip);
u32 data;
int ret;

ret = clk_enable(bank->clk);
if (ret < 0) {
dev_err(bank->drvdata->dev,
"failed to enable clock for bank %s\n", bank->name);
return ret;
}
data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
clk_disable(bank->clk);

return !(data & BIT(offset));
}
Expand Down

0 comments on commit 5c9d8c4

Please sign in to comment.