aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2016-09-21 16:51:22 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-09-23 09:13:04 -0400
commit81d3753d9ea540c38b906399822a963e3b44a045 (patch)
tree06e58a6236f9a7d62ed317a2aa72e7995e3116d2
parent83626bbdf5ca31257066b05db5a38c846ae1e19f (diff)
gpio: axp209: Implement get_direction
Implement the get_direction callback for the GPIOs found in the AXP209 PMIC. Due to the way they are implemented, in the same register you have the muxing options, GPIO directions and GPIO values. Since you have no control over what value is there at reset, simply use output as the default. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpio-axp209.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-axp209.c b/drivers/gpio/gpio-axp209.c
index 3174799c27c6..d9c2a517c6df 100644
--- a/drivers/gpio/gpio-axp209.c
+++ b/drivers/gpio/gpio-axp209.c
@@ -77,6 +77,35 @@ static int axp20x_gpio_get(struct gpio_chip *chip, unsigned offset)
77 return !!(val & BIT(offset + 4)); 77 return !!(val & BIT(offset + 4));
78} 78}
79 79
80static int axp20x_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
81{
82 struct axp20x_gpio *gpio = gpiochip_get_data(chip);
83 unsigned int val;
84 int reg, ret;
85
86 reg = axp20x_gpio_get_reg(offset);
87 if (reg < 0)
88 return reg;
89
90 ret = regmap_read(gpio->regmap, reg, &val);
91 if (ret)
92 return ret;
93
94 /*
95 * This shouldn't really happen if the pin is in use already,
96 * or if it's not in use yet, it doesn't matter since we're
97 * going to change the value soon anyway. Default to output.
98 */
99 if ((val & AXP20X_GPIO_FUNCTIONS) > 2)
100 return 0;
101
102 /*
103 * The GPIO directions are the three lowest values.
104 * 2 is input, 0 and 1 are output
105 */
106 return val & 2;
107}
108
80static int axp20x_gpio_output(struct gpio_chip *chip, unsigned offset, 109static int axp20x_gpio_output(struct gpio_chip *chip, unsigned offset,
81 int value) 110 int value)
82{ 111{
@@ -123,6 +152,7 @@ static int axp20x_gpio_probe(struct platform_device *pdev)
123 gpio->chip.label = dev_name(&pdev->dev); 152 gpio->chip.label = dev_name(&pdev->dev);
124 gpio->chip.owner = THIS_MODULE; 153 gpio->chip.owner = THIS_MODULE;
125 gpio->chip.get = axp20x_gpio_get; 154 gpio->chip.get = axp20x_gpio_get;
155 gpio->chip.get_direction = axp20x_gpio_get_direction;
126 gpio->chip.set = axp20x_gpio_set; 156 gpio->chip.set = axp20x_gpio_set;
127 gpio->chip.direction_input = axp20x_gpio_input; 157 gpio->chip.direction_input = axp20x_gpio_input;
128 gpio->chip.direction_output = axp20x_gpio_output; 158 gpio->chip.direction_output = axp20x_gpio_output;