提交 7d66976f 编写于 作者: C Codrin Ciubotariu 提交者: Wolfram Sang

i2c: at91: Fix pinmux after devm_gpiod_get() for bus recovery

devm_gpiod_get() usually calls gpio_request_enable() for non-strict pinmux
drivers. These puts the pins in GPIO mode, whithout notifying the pinctrl
driver. At this point, the I2C bus no longer owns the pins. To mux the
pins back to the I2C bus, we use the pinctrl driver to change the state
of the pins to GPIO, before using devm_gpiod_get(). After the pins are
received as GPIOs, we switch theer pinctrl state back to the default
one,

Fixes: d3d3fdcc ("i2c: at91: implement i2c bus recovery")
Signed-off-by: NCodrin Ciubotariu <codrin.ciubotariu@microchip.com>
Acked-by: NLudovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: NWolfram Sang <wsa@kernel.org>
上级 2f5a55c5
...@@ -845,6 +845,18 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev, ...@@ -845,6 +845,18 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev,
PINCTRL_STATE_DEFAULT); PINCTRL_STATE_DEFAULT);
dev->pinctrl_pins_gpio = pinctrl_lookup_state(dev->pinctrl, dev->pinctrl_pins_gpio = pinctrl_lookup_state(dev->pinctrl,
"gpio"); "gpio");
if (IS_ERR(dev->pinctrl_pins_default) ||
IS_ERR(dev->pinctrl_pins_gpio)) {
dev_info(&pdev->dev, "pinctrl states incomplete for recovery\n");
return -EINVAL;
}
/*
* pins will be taken as GPIO, so we might as well inform pinctrl about
* this and move the state to GPIO
*/
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_gpio);
rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER) if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
...@@ -855,9 +867,7 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev, ...@@ -855,9 +867,7 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev,
return -EPROBE_DEFER; return -EPROBE_DEFER;
if (IS_ERR(rinfo->sda_gpiod) || if (IS_ERR(rinfo->sda_gpiod) ||
IS_ERR(rinfo->scl_gpiod) || IS_ERR(rinfo->scl_gpiod)) {
IS_ERR(dev->pinctrl_pins_default) ||
IS_ERR(dev->pinctrl_pins_gpio)) {
dev_info(&pdev->dev, "recovery information incomplete\n"); dev_info(&pdev->dev, "recovery information incomplete\n");
if (!IS_ERR(rinfo->sda_gpiod)) { if (!IS_ERR(rinfo->sda_gpiod)) {
gpiod_put(rinfo->sda_gpiod); gpiod_put(rinfo->sda_gpiod);
...@@ -867,9 +877,13 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev, ...@@ -867,9 +877,13 @@ static int at91_init_twi_recovery_info(struct platform_device *pdev,
gpiod_put(rinfo->scl_gpiod); gpiod_put(rinfo->scl_gpiod);
rinfo->scl_gpiod = NULL; rinfo->scl_gpiod = NULL;
} }
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
return -EINVAL; return -EINVAL;
} }
/* change the state of the pins back to their default state */
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
dev_info(&pdev->dev, "using scl, sda for recovery\n"); dev_info(&pdev->dev, "using scl, sda for recovery\n");
rinfo->prepare_recovery = at91_prepare_twi_recovery; rinfo->prepare_recovery = at91_prepare_twi_recovery;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册