i2c: at91: Move to generic GPIO bus recovery
Make the Microchip at91 driver the first to use the generic GPIO bus recovery support from the I2C core and discard the driver implementation. Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
This commit is contained in:
parent
23a698fe65
commit
543aa2c4da
@ -816,79 +816,16 @@ error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void at91_prepare_twi_recovery(struct i2c_adapter *adap)
|
||||
{
|
||||
struct at91_twi_dev *dev = i2c_get_adapdata(adap);
|
||||
|
||||
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_gpio);
|
||||
}
|
||||
|
||||
static void at91_unprepare_twi_recovery(struct i2c_adapter *adap)
|
||||
{
|
||||
struct at91_twi_dev *dev = i2c_get_adapdata(adap);
|
||||
|
||||
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
|
||||
}
|
||||
|
||||
static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
|
||||
struct at91_twi_dev *dev)
|
||||
{
|
||||
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
|
||||
|
||||
dev->pinctrl = devm_pinctrl_get(&pdev->dev);
|
||||
if (!dev->pinctrl || IS_ERR(dev->pinctrl)) {
|
||||
rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
|
||||
if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
|
||||
dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
|
||||
return PTR_ERR(dev->pinctrl);
|
||||
return PTR_ERR(rinfo->pinctrl);
|
||||
}
|
||||
|
||||
dev->pinctrl_pins_default = pinctrl_lookup_state(dev->pinctrl,
|
||||
PINCTRL_STATE_DEFAULT);
|
||||
dev->pinctrl_pins_gpio = pinctrl_lookup_state(dev->pinctrl,
|
||||
"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);
|
||||
if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl",
|
||||
GPIOD_OUT_HIGH_OPEN_DRAIN);
|
||||
if (PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
if (IS_ERR(rinfo->sda_gpiod) ||
|
||||
IS_ERR(rinfo->scl_gpiod)) {
|
||||
dev_info(&pdev->dev, "recovery information incomplete\n");
|
||||
if (!IS_ERR(rinfo->sda_gpiod)) {
|
||||
gpiod_put(rinfo->sda_gpiod);
|
||||
rinfo->sda_gpiod = NULL;
|
||||
}
|
||||
if (!IS_ERR(rinfo->scl_gpiod)) {
|
||||
gpiod_put(rinfo->scl_gpiod);
|
||||
rinfo->scl_gpiod = NULL;
|
||||
}
|
||||
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
|
||||
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");
|
||||
|
||||
rinfo->prepare_recovery = at91_prepare_twi_recovery;
|
||||
rinfo->unprepare_recovery = at91_unprepare_twi_recovery;
|
||||
rinfo->recover_bus = i2c_generic_scl_recovery;
|
||||
dev->adapter.bus_recovery_info = rinfo;
|
||||
|
||||
return 0;
|
||||
|
@ -157,9 +157,6 @@ struct at91_twi_dev {
|
||||
struct at91_twi_dma dma;
|
||||
bool slave_detected;
|
||||
struct i2c_bus_recovery_info rinfo;
|
||||
struct pinctrl *pinctrl;
|
||||
struct pinctrl_state *pinctrl_pins_default;
|
||||
struct pinctrl_state *pinctrl_pins_gpio;
|
||||
#ifdef CONFIG_I2C_AT91_SLAVE_EXPERIMENTAL
|
||||
unsigned smr;
|
||||
struct i2c_client *slave;
|
||||
|
Loading…
Reference in New Issue
Block a user