diff options
-rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index cb11eee95673..592a8f26a708 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
@@ -984,11 +984,24 @@ static void i2c_imx_unprepare_recovery(struct i2c_adapter *adap) | |||
984 | pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default); | 984 | pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default); |
985 | } | 985 | } |
986 | 986 | ||
987 | static void i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | 987 | /* |
988 | * We switch SCL and SDA to their GPIO function and do some bitbanging | ||
989 | * for bus recovery. These alternative pinmux settings can be | ||
990 | * described in the device tree by a separate pinctrl state "gpio". If | ||
991 | * this is missing this is not a big problem, the only implication is | ||
992 | * that we can't do bus recovery. | ||
993 | */ | ||
994 | static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | ||
988 | struct platform_device *pdev) | 995 | struct platform_device *pdev) |
989 | { | 996 | { |
990 | struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; | 997 | struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; |
991 | 998 | ||
999 | i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev); | ||
1000 | if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) { | ||
1001 | dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n"); | ||
1002 | return PTR_ERR(i2c_imx->pinctrl); | ||
1003 | } | ||
1004 | |||
992 | i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl, | 1005 | i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl, |
993 | PINCTRL_STATE_DEFAULT); | 1006 | PINCTRL_STATE_DEFAULT); |
994 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, | 1007 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, |
@@ -1001,7 +1014,7 @@ static void i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | |||
1001 | IS_ERR(i2c_imx->pinctrl_pins_default) || | 1014 | IS_ERR(i2c_imx->pinctrl_pins_default) || |
1002 | IS_ERR(i2c_imx->pinctrl_pins_gpio)) { | 1015 | IS_ERR(i2c_imx->pinctrl_pins_gpio)) { |
1003 | dev_dbg(&pdev->dev, "recovery information incomplete\n"); | 1016 | dev_dbg(&pdev->dev, "recovery information incomplete\n"); |
1004 | return; | 1017 | return 0; |
1005 | } | 1018 | } |
1006 | 1019 | ||
1007 | dev_dbg(&pdev->dev, "using scl-gpio %d and sda-gpio %d for recovery\n", | 1020 | dev_dbg(&pdev->dev, "using scl-gpio %d and sda-gpio %d for recovery\n", |
@@ -1011,6 +1024,8 @@ static void i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | |||
1011 | rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; | 1024 | rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; |
1012 | rinfo->recover_bus = i2c_generic_gpio_recovery; | 1025 | rinfo->recover_bus = i2c_generic_gpio_recovery; |
1013 | i2c_imx->adapter.bus_recovery_info = rinfo; | 1026 | i2c_imx->adapter.bus_recovery_info = rinfo; |
1027 | |||
1028 | return 0; | ||
1014 | } | 1029 | } |
1015 | 1030 | ||
1016 | static u32 i2c_imx_func(struct i2c_adapter *adapter) | 1031 | static u32 i2c_imx_func(struct i2c_adapter *adapter) |
@@ -1081,12 +1096,6 @@ static int i2c_imx_probe(struct platform_device *pdev) | |||
1081 | return ret; | 1096 | return ret; |
1082 | } | 1097 | } |
1083 | 1098 | ||
1084 | i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev); | ||
1085 | if (IS_ERR(i2c_imx->pinctrl)) { | ||
1086 | ret = PTR_ERR(i2c_imx->pinctrl); | ||
1087 | goto clk_disable; | ||
1088 | } | ||
1089 | |||
1090 | /* Request IRQ */ | 1099 | /* Request IRQ */ |
1091 | ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0, | 1100 | ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0, |
1092 | pdev->name, i2c_imx); | 1101 | pdev->name, i2c_imx); |
@@ -1125,7 +1134,11 @@ static int i2c_imx_probe(struct platform_device *pdev) | |||
1125 | i2c_imx, IMX_I2C_I2CR); | 1134 | i2c_imx, IMX_I2C_I2CR); |
1126 | imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); | 1135 | imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); |
1127 | 1136 | ||
1128 | i2c_imx_init_recovery_info(i2c_imx, pdev); | 1137 | /* Init optional bus recovery function */ |
1138 | ret = i2c_imx_init_recovery_info(i2c_imx, pdev); | ||
1139 | /* Give it another chance if pinctrl used is not ready yet */ | ||
1140 | if (ret == -EPROBE_DEFER) | ||
1141 | goto rpm_disable; | ||
1129 | 1142 | ||
1130 | /* Add I2C adapter */ | 1143 | /* Add I2C adapter */ |
1131 | ret = i2c_add_numbered_adapter(&i2c_imx->adapter); | 1144 | ret = i2c_add_numbered_adapter(&i2c_imx->adapter); |