Skip to content

Commit 11598d1

Browse files
charleskeepaxlinusw
authored andcommitted
gpio: arizona: Correct handling for reading input GPIOs
The GPIO register is cached since all the configuration resides within it, however, this means for input GPIOs the driver will not return the actual state but the last value written to the register cache. To correct this in the case of reading an input GPIO resume the CODEC and drop the cache for the input register to ensure an actual hardware read takes place. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent e1e37d6 commit 11598d1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

drivers/gpio/gpio-arizona.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/module.h>
1818
#include <linux/gpio.h>
1919
#include <linux/platform_device.h>
20+
#include <linux/pm_runtime.h>
2021
#include <linux/seq_file.h>
2122

2223
#include <linux/mfd/arizona/core.h>
@@ -41,13 +42,38 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
4142
{
4243
struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
4344
struct arizona *arizona = arizona_gpio->arizona;
44-
unsigned int val;
45+
unsigned int reg, val;
4546
int ret;
4647

47-
ret = regmap_read(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, &val);
48+
reg = ARIZONA_GPIO1_CTRL + offset;
49+
ret = regmap_read(arizona->regmap, reg, &val);
4850
if (ret < 0)
4951
return ret;
5052

53+
/* Resume to read actual registers for input pins */
54+
if (!(val & ARIZONA_GPN_DIR)) {
55+
ret = pm_runtime_get_sync(chip->parent);
56+
if (ret < 0) {
57+
dev_err(chip->parent, "Failed to resume: %d\n", ret);
58+
return ret;
59+
}
60+
61+
/* Register is cached, drop it to ensure a physical read */
62+
ret = regcache_drop_region(arizona->regmap, reg, reg);
63+
if (ret < 0) {
64+
dev_err(chip->parent, "Failed to drop cache: %d\n",
65+
ret);
66+
return ret;
67+
}
68+
69+
ret = regmap_read(arizona->regmap, reg, &val);
70+
if (ret < 0)
71+
return ret;
72+
73+
pm_runtime_mark_last_busy(chip->parent);
74+
pm_runtime_put_autosuspend(chip->parent);
75+
}
76+
5177
if (val & ARIZONA_GPN_LVL)
5278
return 1;
5379
else

0 commit comments

Comments
 (0)