Skip to content

Commit c0fcc4d

Browse files
esbenAndi Shyti
authored andcommitted
i2c: imx: move to generic GPIO recovery
Starting with commit 7582031 ("i2c: core: add generic I2C GPIO recovery") GPIO bus recovery is supported by the I2C core, so we can remove the driver implementation and use that one instead. As a nice side-effect, pinctrl becomes optional, allowing bus recovery on LS1021A, which does not have such luxury, but can be wired up to use extra fixed GPIO pins. Note: The previous error messages about bus recovery not being supported is dropped with this change. Given that it is perfectly possible to have platforms where bus recovery works without pinctrl support, I happen to work on one such, both error messages does not really make sense in those cases. And I don't see how to know if this is the case or not. Signed-off-by: Esben Haabendal <[email protected]> Acked-by: Oleksij Rempel <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 4810603 commit c0fcc4d

File tree

1 file changed

+5
-57
lines changed

1 file changed

+5
-57
lines changed

drivers/i2c/busses/i2c-imx.c

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ struct imx_i2c_struct {
212212
const struct imx_i2c_hwdata *hwdata;
213213
struct i2c_bus_recovery_info rinfo;
214214

215-
struct pinctrl *pinctrl;
216-
struct pinctrl_state *pinctrl_pins_default;
217-
struct pinctrl_state *pinctrl_pins_gpio;
218-
219215
struct imx_i2c_dma *dma;
220216
struct i2c_client *slave;
221217
enum i2c_slave_event last_slave_event;
@@ -1357,24 +1353,6 @@ static int i2c_imx_xfer_atomic(struct i2c_adapter *adapter,
13571353
return result;
13581354
}
13591355

1360-
static void i2c_imx_prepare_recovery(struct i2c_adapter *adap)
1361-
{
1362-
struct imx_i2c_struct *i2c_imx;
1363-
1364-
i2c_imx = container_of(adap, struct imx_i2c_struct, adapter);
1365-
1366-
pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_gpio);
1367-
}
1368-
1369-
static void i2c_imx_unprepare_recovery(struct i2c_adapter *adap)
1370-
{
1371-
struct imx_i2c_struct *i2c_imx;
1372-
1373-
i2c_imx = container_of(adap, struct imx_i2c_struct, adapter);
1374-
1375-
pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default);
1376-
}
1377-
13781356
/*
13791357
* We switch SCL and SDA to their GPIO function and do some bitbanging
13801358
* for bus recovery. These alternative pinmux settings can be
@@ -1385,43 +1363,13 @@ static void i2c_imx_unprepare_recovery(struct i2c_adapter *adap)
13851363
static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
13861364
struct platform_device *pdev)
13871365
{
1388-
struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
1389-
1390-
i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
1391-
if (!i2c_imx->pinctrl) {
1392-
dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n");
1393-
return 0;
1394-
}
1395-
if (IS_ERR(i2c_imx->pinctrl)) {
1396-
dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
1397-
return PTR_ERR(i2c_imx->pinctrl);
1398-
}
1399-
1400-
i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl,
1401-
PINCTRL_STATE_DEFAULT);
1402-
i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl,
1403-
"gpio");
1404-
rinfo->sda_gpiod = devm_gpiod_get_optional(&pdev->dev, "sda", GPIOD_IN);
1405-
rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN);
1406-
1407-
if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER ||
1408-
PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) {
1409-
return -EPROBE_DEFER;
1410-
} else if (IS_ERR(rinfo->sda_gpiod) ||
1411-
IS_ERR(rinfo->scl_gpiod) ||
1412-
IS_ERR(i2c_imx->pinctrl_pins_default) ||
1413-
IS_ERR(i2c_imx->pinctrl_pins_gpio)) {
1414-
dev_dbg(&pdev->dev, "recovery information incomplete\n");
1415-
return 0;
1416-
}
1366+
struct i2c_bus_recovery_info *bri = &i2c_imx->rinfo;
14171367

1418-
dev_dbg(&pdev->dev, "using scl%s for recovery\n",
1419-
rinfo->sda_gpiod ? ",sda" : "");
1368+
bri->pinctrl = devm_pinctrl_get(&pdev->dev);
1369+
if (IS_ERR(bri->pinctrl))
1370+
return PTR_ERR(bri->pinctrl);
14201371

1421-
rinfo->prepare_recovery = i2c_imx_prepare_recovery;
1422-
rinfo->unprepare_recovery = i2c_imx_unprepare_recovery;
1423-
rinfo->recover_bus = i2c_generic_scl_recovery;
1424-
i2c_imx->adapter.bus_recovery_info = rinfo;
1372+
i2c_imx->adapter.bus_recovery_info = bri;
14251373

14261374
return 0;
14271375
}

0 commit comments

Comments
 (0)