From 6d8e04f9d38345770572a39125a47da37bb8ce9e Mon Sep 17 00:00:00 2001 From: Martin DEVERA Date: Wed, 5 Aug 2020 11:28:11 +0200 Subject: [PATCH] pinctrl: sx150x: Fix pinctrl enablement order bug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I encountered bug in SX1502 expander driver in 5.7.7. Here is relevant DTS part: compatible = "semtech,sx1502q"; gpio4_cfg_pins: gpio2-cfg {                         pins = "gpio5";                         output-high;     }; And part of OOPS: [    0.673996] [] (gpiochip_get_data) from [] (sx150x_gpio_direction_output+0xd) [    0.683259] [] (sx150x_gpio_direction_output) from [] (sx150x_pinconf_set+0x) [    0.692796] [] (sx150x_pinconf_set) from [] (pinconf_apply_setting+0x39/0x7e) [    0.701635] [] (pinconf_apply_setting) from [] (pinctrl_commit_state+0xa5/0x) [    0.710648] [] (pinctrl_commit_state) from [] (pinctrl_enable+0xff/0x1d4) [    0.719139] [] (pinctrl_enable) from [] (sx150x_probe+0x1a3/0x358) [    0.727027] [] (sx150x_probe) from [] (i2c_device_probe+0x1bb/0x1dc) The problem is that sx150x_pinconf_set uses sx150x_gpio_direction_output but gpio is not setup yet. Patch below fixes it but I'm not sure whether is it correct. Link: https://lore.kernel.org/r/f32130bf-cfd4-b1bf-538c-dbc9ee2d947a@eaxlabs.cz Signed-off-by: Martin DEVERA Signed-off-by: Linus Walleij --- drivers/pinctrl/pinctrl-sx150x.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c index b325a13..c110f78 100644 --- a/drivers/pinctrl/pinctrl-sx150x.c +++ b/drivers/pinctrl/pinctrl-sx150x.c @@ -1154,12 +1154,6 @@ static int sx150x_probe(struct i2c_client *client, return ret; } - ret = pinctrl_enable(pctl->pctldev); - if (ret) { - dev_err(dev, "Failed to enable pinctrl device\n"); - return ret; - } - /* Register GPIO controller */ pctl->gpio.base = -1; pctl->gpio.ngpio = pctl->data->npins; @@ -1238,6 +1232,17 @@ static int sx150x_probe(struct i2c_client *client, if (ret) return ret; + /* + * Pin control functions need to be enabled AFTER registering the + * GPIO chip because sx150x_pinconf_set() calls + * sx150x_gpio_direction_output(). + */ + ret = pinctrl_enable(pctl->pctldev); + if (ret) { + dev_err(dev, "Failed to enable pinctrl device\n"); + return ret; + } + ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev), 0, 0, pctl->data->npins); if (ret) -- 2.7.4