On Fri, Oct 4, 2019 at 2:29 PM Amelie Delaunay <amelie.delaunay@xxxxxx> wrote:
When an STMFX IO is used as interrupt through the interrupt-controller
binding, the STMFX driver should configure this IO as input. Default
value of STMFX IO direction is input, but if the IO is used as output
before the interrupt use, it will not work without these callbacks.
Signed-off-by: Amelie Delaunay <amelie.delaunay@xxxxxx>
OK I see what you want to achieve.
+static int stmfx_gpio_irq_request_resources(struct irq_data *data)
+{
+ÂÂÂÂÂÂ struct gpio_chip *gpio_chip = irq_data_get_irq_chip_data(data);
+ÂÂÂÂÂÂ struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
+ÂÂÂÂÂÂ int ret;
+
+ÂÂÂÂÂÂ ret = stmfx_gpio_direction_input(&pctl->gpio_chip, data->hwirq);
+ÂÂÂÂÂÂ if (ret)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
+
+ÂÂÂÂÂÂ ret = gpiochip_lock_as_irq(&pctl->gpio_chip, data->hwirq);
+ÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(pctl->dev, "Unable to lock gpio %lu as IRQ: %d\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data->hwirq, ret);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂ }
+
+ÂÂÂÂÂÂ return 0;
+}
Just call gpiochip_reqres_irq() instead of calling the lock etc
explicitly.
+static void stmfx_gpio_irq_release_resources(struct irq_data *data)
+{
+ÂÂÂÂÂÂ struct gpio_chip *gpio_chip = irq_data_get_irq_chip_data(data);
+ÂÂÂÂÂÂ struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
+
+ÂÂÂÂÂÂ gpiochip_unlock_as_irq(&pctl->gpio_chip, data->hwirq);
+}
Just call gpiochip_relres_irq()
But all this duplicated a lot of code from the core which is not so nice.
@@ -678,6 +706,8 @@ static int stmfx_pinctrl_probe(struct platform_device *pdev)
ÂÂÂÂÂÂÂÂ pctl->irq_chip.irq_set_type = stmfx_pinctrl_irq_set_type;
ÂÂÂÂÂÂÂÂ pctl->irq_chip.irq_bus_lock = stmfx_pinctrl_irq_bus_lock;
ÂÂÂÂÂÂÂÂ pctl->irq_chip.irq_bus_sync_unlock = stmfx_pinctrl_irq_bus_sync_unlock;
+ÂÂÂÂÂÂ pctl->irq_chip.irq_request_resources = stmfx_gpio_irq_request_resources;
+ÂÂÂÂÂÂ pctl->irq_chip.irq_release_resources = stmfx_gpio_irq_release_resources;
What about just adding
pctl->irq_chip.irq_enable and do stmfx_gpio_direction_input()
in that callback instead? gpiolib will helpfully wrap it.