All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:26 ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:26 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
patch2 adds the pintrl property for i2c bus recovery.
patch3 selects gpio/default pin when prepare/unprepare recovery.

Since v2:
 - add missing property dt-binding

Since v1:
 - use IS_ERR_OR_NULL

Jisheng Zhang (3):
  dt-bindings: i2c: designware: add optional gpio recovery properties
  dt-bindings: i2c: designware: add optional pinctrl for bus recovery
  i2c: designware: select gpio/default pin when prepare/unprepare
    recovery

 .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
 drivers/i2c/busses/i2c-designware-core.h      |  3 +++
 drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
 3 files changed, 37 insertions(+)

-- 
2.19.0


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:26 ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:26 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
patch2 adds the pintrl property for i2c bus recovery.
patch3 selects gpio/default pin when prepare/unprepare recovery.

Since v2:
 - add missing property dt-binding

Since v1:
 - use IS_ERR_OR_NULL

Jisheng Zhang (3):
  dt-bindings: i2c: designware: add optional gpio recovery properties
  dt-bindings: i2c: designware: add optional pinctrl for bus recovery
  i2c: designware: select gpio/default pin when prepare/unprepare
    recovery

 .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
 drivers/i2c/busses/i2c-designware-core.h      |  3 +++
 drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
 3 files changed, 37 insertions(+)

-- 
2.19.0

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:26 ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:26 UTC (permalink / raw)
  To: linux-arm-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
patch2 adds the pintrl property for i2c bus recovery.
patch3 selects gpio/default pin when prepare/unprepare recovery.

Since v2:
 - add missing property dt-binding

Since v1:
 - use IS_ERR_OR_NULL

Jisheng Zhang (3):
  dt-bindings: i2c: designware: add optional gpio recovery properties
  dt-bindings: i2c: designware: add optional pinctrl for bus recovery
  i2c: designware: select gpio/default pin when prepare/unprepare
    recovery

 .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
 drivers/i2c/busses/i2c-designware-core.h      |  3 +++
 drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
 3 files changed, 37 insertions(+)

-- 
2.19.0

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
  2018-09-17  3:26 ` Jisheng Zhang
  (?)
@ 2018-09-17  3:27   ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:27 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

Document the scl-gpios and sda-gpios properties for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index fbb0a6d8b964..1d6a6a8061ba 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -20,6 +20,10 @@ Optional properties :
  - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
    This value which is by default 300ns is used to compute the tHIGH period.
 
+ - scl-gpios: specify the gpio of the SCL line for gpio recovery
+
+ - sda-gpios: specify the gpio of the SDA line for gpio recovery
+
 Examples :
 
 	i2c@f0000 {
@@ -42,6 +46,8 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
+		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
 
 	i2c@1120000 {
-- 
2.19.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
@ 2018-09-17  3:27   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:27 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

Document the scl-gpios and sda-gpios properties for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index fbb0a6d8b964..1d6a6a8061ba 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -20,6 +20,10 @@ Optional properties :
  - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
    This value which is by default 300ns is used to compute the tHIGH period.
 
+ - scl-gpios: specify the gpio of the SCL line for gpio recovery
+
+ - sda-gpios: specify the gpio of the SDA line for gpio recovery
+
 Examples :
 
 	i2c@f0000 {
@@ -42,6 +46,8 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
+		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
 
 	i2c@1120000 {
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
@ 2018-09-17  3:27   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:27 UTC (permalink / raw)
  To: linux-arm-kernel

Document the scl-gpios and sda-gpios properties for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index fbb0a6d8b964..1d6a6a8061ba 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -20,6 +20,10 @@ Optional properties :
  - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
    This value which is by default 300ns is used to compute the tHIGH period.
 
+ - scl-gpios: specify the gpio of the SCL line for gpio recovery
+
+ - sda-gpios: specify the gpio of the SDA line for gpio recovery
+
 Examples :
 
 	i2c at f0000 {
@@ -42,6 +46,8 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
+		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
 
 	i2c at 1120000 {
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
  2018-09-17  3:26 ` Jisheng Zhang
  (?)
@ 2018-09-17  3:28   ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:28 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

Document the pinctrl property for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index 1d6a6a8061ba..c1544d1f7b55 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -24,6 +24,9 @@ Optional properties :
 
  - sda-gpios: specify the gpio of the SDA line for gpio recovery
 
+ - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
+   bus recovery, call it "gpio" state
+
 Examples :
 
 	i2c@f0000 {
@@ -46,6 +49,9 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		pinctrl-names = "default", "gpio";
+		pinctrl-0 = <&pinctrl_i2c1>;
+		pinctrl-1 = <&pinctrl_i2c1_gpio>;
 		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
 		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
-- 
2.19.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
@ 2018-09-17  3:28   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:28 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

Document the pinctrl property for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index 1d6a6a8061ba..c1544d1f7b55 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -24,6 +24,9 @@ Optional properties :
 
  - sda-gpios: specify the gpio of the SDA line for gpio recovery
 
+ - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
+   bus recovery, call it "gpio" state
+
 Examples :
 
 	i2c@f0000 {
@@ -46,6 +49,9 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		pinctrl-names = "default", "gpio";
+		pinctrl-0 = <&pinctrl_i2c1>;
+		pinctrl-1 = <&pinctrl_i2c1_gpio>;
 		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
 		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
@ 2018-09-17  3:28   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:28 UTC (permalink / raw)
  To: linux-arm-kernel

Document the pinctrl property for bus recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index 1d6a6a8061ba..c1544d1f7b55 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -24,6 +24,9 @@ Optional properties :
 
  - sda-gpios: specify the gpio of the SDA line for gpio recovery
 
+ - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
+   bus recovery, call it "gpio" state
+
 Examples :
 
 	i2c at f0000 {
@@ -46,6 +49,9 @@ Examples :
 		i2c-sda-hold-time-ns = <300>;
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
+		pinctrl-names = "default", "gpio";
+		pinctrl-0 = <&pinctrl_i2c1>;
+		pinctrl-1 = <&pinctrl_i2c1_gpio>;
 		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
 		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
 	};
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
  2018-09-17  3:26 ` Jisheng Zhang
  (?)
@ 2018-09-17  3:29   ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:29 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/i2c/busses/i2c-designware-core.h   |  3 +++
 drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index e367b1af4ab2..01d5f01691a4 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -271,6 +271,9 @@ struct dw_i2c_dev {
 	int			(*init)(struct dw_i2c_dev *dev);
 	int			mode;
 	struct i2c_bus_recovery_info rinfo;
+	struct pinctrl		*pinctrl;
+	struct pinctrl_state	*pins_default;
+	struct pinctrl_state	*pins_gpio;
 };
 
 #define ACCESS_SWAP		0x00000001
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 94d94b4a9a0d..384d6630366a 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 
@@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
 {
 	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
 
+	if (dev->pinctrl && dev->pins_gpio)
+		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
+
 	i2c_dw_disable(dev);
 	reset_control_assert(dev->rst);
 	i2c_dw_prepare_clk(dev, false);
@@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
 	i2c_dw_prepare_clk(dev, true);
 	reset_control_deassert(dev->rst);
 	i2c_dw_init_master(dev);
+
+	if (dev->pinctrl && dev->pins_default)
+		pinctrl_select_state(dev->pinctrl, dev->pins_default);
 }
 
 static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
@@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
 	struct i2c_adapter *adap = &dev->adapter;
 	struct gpio_desc *gpio;
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *s;
 	int r;
 
 	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
@@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 		return PTR_ERR(gpio);
 	rinfo->sda_gpiod = gpio;
 
+	pinctrl = devm_pinctrl_get(dev->dev);
+	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR_OR_NULL(pinctrl)) {
+		dev->pinctrl = pinctrl;
+		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_default = s;
+		s = pinctrl_lookup_state(pinctrl, "gpio");
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_gpio = s;
+	}
+
 	rinfo->recover_bus = i2c_generic_scl_recovery;
 	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
 	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;
-- 
2.19.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:29   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:29 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/i2c/busses/i2c-designware-core.h   |  3 +++
 drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index e367b1af4ab2..01d5f01691a4 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -271,6 +271,9 @@ struct dw_i2c_dev {
 	int			(*init)(struct dw_i2c_dev *dev);
 	int			mode;
 	struct i2c_bus_recovery_info rinfo;
+	struct pinctrl		*pinctrl;
+	struct pinctrl_state	*pins_default;
+	struct pinctrl_state	*pins_gpio;
 };
 
 #define ACCESS_SWAP		0x00000001
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 94d94b4a9a0d..384d6630366a 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 
@@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
 {
 	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
 
+	if (dev->pinctrl && dev->pins_gpio)
+		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
+
 	i2c_dw_disable(dev);
 	reset_control_assert(dev->rst);
 	i2c_dw_prepare_clk(dev, false);
@@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
 	i2c_dw_prepare_clk(dev, true);
 	reset_control_deassert(dev->rst);
 	i2c_dw_init_master(dev);
+
+	if (dev->pinctrl && dev->pins_default)
+		pinctrl_select_state(dev->pinctrl, dev->pins_default);
 }
 
 static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
@@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
 	struct i2c_adapter *adap = &dev->adapter;
 	struct gpio_desc *gpio;
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *s;
 	int r;
 
 	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
@@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 		return PTR_ERR(gpio);
 	rinfo->sda_gpiod = gpio;
 
+	pinctrl = devm_pinctrl_get(dev->dev);
+	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR_OR_NULL(pinctrl)) {
+		dev->pinctrl = pinctrl;
+		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_default = s;
+		s = pinctrl_lookup_state(pinctrl, "gpio");
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_gpio = s;
+	}
+
 	rinfo->recover_bus = i2c_generic_scl_recovery;
 	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
 	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:29   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:29 UTC (permalink / raw)
  To: linux-arm-kernel

On some platforms, the sda/scl pins are muxed with gpio functions, so
they could be used for recovery. Select the gpio/default pin function
when prepare/unprepare recovery.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/i2c/busses/i2c-designware-core.h   |  3 +++
 drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index e367b1af4ab2..01d5f01691a4 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -271,6 +271,9 @@ struct dw_i2c_dev {
 	int			(*init)(struct dw_i2c_dev *dev);
 	int			mode;
 	struct i2c_bus_recovery_info rinfo;
+	struct pinctrl		*pinctrl;
+	struct pinctrl_state	*pins_default;
+	struct pinctrl_state	*pins_gpio;
 };
 
 #define ACCESS_SWAP		0x00000001
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 94d94b4a9a0d..384d6630366a 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 
@@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
 {
 	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
 
+	if (dev->pinctrl && dev->pins_gpio)
+		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
+
 	i2c_dw_disable(dev);
 	reset_control_assert(dev->rst);
 	i2c_dw_prepare_clk(dev, false);
@@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
 	i2c_dw_prepare_clk(dev, true);
 	reset_control_deassert(dev->rst);
 	i2c_dw_init_master(dev);
+
+	if (dev->pinctrl && dev->pins_default)
+		pinctrl_select_state(dev->pinctrl, dev->pins_default);
 }
 
 static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
@@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
 	struct i2c_adapter *adap = &dev->adapter;
 	struct gpio_desc *gpio;
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *s;
 	int r;
 
 	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
@@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 		return PTR_ERR(gpio);
 	rinfo->sda_gpiod = gpio;
 
+	pinctrl = devm_pinctrl_get(dev->dev);
+	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	if (!IS_ERR_OR_NULL(pinctrl)) {
+		dev->pinctrl = pinctrl;
+		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_default = s;
+		s = pinctrl_lookup_state(pinctrl, "gpio");
+		if (!IS_ERR_OR_NULL(s))
+			dev->pins_gpio = s;
+	}
+
 	rinfo->recover_bus = i2c_generic_scl_recovery;
 	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
 	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
  2018-09-17  3:26 ` Jisheng Zhang
  (?)
@ 2018-09-17  3:31   ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:31 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:26:33 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
> patch2 adds the pintrl property for i2c bus recovery.
> patch3 selects gpio/default pin when prepare/unprepare recovery.
> 
> Since v2:
>  - add missing property dt-binding
> 
> Since v1:
>  - use IS_ERR_OR_NULL
> 
> Jisheng Zhang (3):
>   dt-bindings: i2c: designware: add optional gpio recovery properties
>   dt-bindings: i2c: designware: add optional pinctrl for bus recovery
>   i2c: designware: select gpio/default pin when prepare/unprepare
>     recovery
> 
>  .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
>  drivers/i2c/busses/i2c-designware-core.h      |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
>  3 files changed, 37 insertions(+)
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:31   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:31 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:26:33 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
> patch2 adds the pintrl property for i2c bus recovery.
> patch3 selects gpio/default pin when prepare/unprepare recovery.
> 
> Since v2:
>  - add missing property dt-binding
> 
> Since v1:
>  - use IS_ERR_OR_NULL
> 
> Jisheng Zhang (3):
>   dt-bindings: i2c: designware: add optional gpio recovery properties
>   dt-bindings: i2c: designware: add optional pinctrl for bus recovery
>   i2c: designware: select gpio/default pin when prepare/unprepare
>     recovery
> 
>  .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
>  drivers/i2c/busses/i2c-designware-core.h      |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
>  3 files changed, 37 insertions(+)
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:31   ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:31 UTC (permalink / raw)
  To: linux-arm-kernel

+ DT maintainers

On Mon, 17 Sep 2018 11:26:33 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> patch1 adds the missing scl-gpios, sda-gpios properties binding doc.
> patch2 adds the pintrl property for i2c bus recovery.
> patch3 selects gpio/default pin when prepare/unprepare recovery.
> 
> Since v2:
>  - add missing property dt-binding
> 
> Since v1:
>  - use IS_ERR_OR_NULL
> 
> Jisheng Zhang (3):
>   dt-bindings: i2c: designware: add optional gpio recovery properties
>   dt-bindings: i2c: designware: add optional pinctrl for bus recovery
>   i2c: designware: select gpio/default pin when prepare/unprepare
>     recovery
> 
>  .../bindings/i2c/i2c-designware.txt           | 12 ++++++++++
>  drivers/i2c/busses/i2c-designware-core.h      |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c    | 22 +++++++++++++++++++
>  3 files changed, 37 insertions(+)
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
  2018-09-17  3:27   ` Jisheng Zhang
  (?)
@ 2018-09-17  3:32     ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:32 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:27:41 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the scl-gpios and sda-gpios properties for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index fbb0a6d8b964..1d6a6a8061ba 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -20,6 +20,10 @@ Optional properties :
>   - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
>     This value which is by default 300ns is used to compute the tHIGH period.
>  
> + - scl-gpios: specify the gpio of the SCL line for gpio recovery
> +
> + - sda-gpios: specify the gpio of the SDA line for gpio recovery
> +
>  Examples :
>  
>  	i2c@f0000 {
> @@ -42,6 +46,8 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
> +		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};
>  
>  	i2c@1120000 {


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
@ 2018-09-17  3:32     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:32 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:27:41 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the scl-gpios and sda-gpios properties for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index fbb0a6d8b964..1d6a6a8061ba 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -20,6 +20,10 @@ Optional properties :
>   - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
>     This value which is by default 300ns is used to compute the tHIGH period.
>  
> + - scl-gpios: specify the gpio of the SCL line for gpio recovery
> +
> + - sda-gpios: specify the gpio of the SDA line for gpio recovery
> +
>  Examples :
>  
>  	i2c@f0000 {
> @@ -42,6 +46,8 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
> +		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};
>  
>  	i2c@1120000 {

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties
@ 2018-09-17  3:32     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:32 UTC (permalink / raw)
  To: linux-arm-kernel

+ DT maintainers

On Mon, 17 Sep 2018 11:27:41 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the scl-gpios and sda-gpios properties for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index fbb0a6d8b964..1d6a6a8061ba 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -20,6 +20,10 @@ Optional properties :
>   - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
>     This value which is by default 300ns is used to compute the tHIGH period.
>  
> + - scl-gpios: specify the gpio of the SCL line for gpio recovery
> +
> + - sda-gpios: specify the gpio of the SDA line for gpio recovery
> +
>  Examples :
>  
>  	i2c at f0000 {
> @@ -42,6 +46,8 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
> +		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};
>  
>  	i2c at 1120000 {

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
  2018-09-17  3:28   ` Jisheng Zhang
  (?)
@ 2018-09-17  3:33     ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:33 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Mark Rutland, Rob Herring
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:28:30 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the pinctrl property for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index 1d6a6a8061ba..c1544d1f7b55 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -24,6 +24,9 @@ Optional properties :
>  
>   - sda-gpios: specify the gpio of the SDA line for gpio recovery
>  
> + - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
> +   bus recovery, call it "gpio" state
> +
>  Examples :
>  
>  	i2c@f0000 {
> @@ -46,6 +49,9 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		pinctrl-names = "default", "gpio";
> +		pinctrl-0 = <&pinctrl_i2c1>;
> +		pinctrl-1 = <&pinctrl_i2c1_gpio>;
>  		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
>  		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
@ 2018-09-17  3:33     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:33 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Mark Rutland, Rob Herring
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:28:30 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the pinctrl property for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index 1d6a6a8061ba..c1544d1f7b55 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -24,6 +24,9 @@ Optional properties :
>  
>   - sda-gpios: specify the gpio of the SDA line for gpio recovery
>  
> + - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
> +   bus recovery, call it "gpio" state
> +
>  Examples :
>  
>  	i2c@f0000 {
> @@ -46,6 +49,9 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		pinctrl-names = "default", "gpio";
> +		pinctrl-0 = <&pinctrl_i2c1>;
> +		pinctrl-1 = <&pinctrl_i2c1_gpio>;
>  		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
>  		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery
@ 2018-09-17  3:33     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:33 UTC (permalink / raw)
  To: linux-arm-kernel

+ DT maintainers

On Mon, 17 Sep 2018 11:28:30 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> Document the pinctrl property for bus recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-designware.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> index 1d6a6a8061ba..c1544d1f7b55 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
> @@ -24,6 +24,9 @@ Optional properties :
>  
>   - sda-gpios: specify the gpio of the SDA line for gpio recovery
>  
> + - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
> +   bus recovery, call it "gpio" state
> +
>  Examples :
>  
>  	i2c at f0000 {
> @@ -46,6 +49,9 @@ Examples :
>  		i2c-sda-hold-time-ns = <300>;
>  		i2c-sda-falling-time-ns = <300>;
>  		i2c-scl-falling-time-ns = <300>;
> +		pinctrl-names = "default", "gpio";
> +		pinctrl-0 = <&pinctrl_i2c1>;
> +		pinctrl-1 = <&pinctrl_i2c1_gpio>;
>  		scl-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
>  		sda-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
>  	};

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
  2018-09-17  3:29   ` Jisheng Zhang
  (?)
@ 2018-09-17  3:34     ` Jisheng Zhang
  -1 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:34 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:29:49 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/i2c/busses/i2c-designware-core.h   |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
> index e367b1af4ab2..01d5f01691a4 100644
> --- a/drivers/i2c/busses/i2c-designware-core.h
> +++ b/drivers/i2c/busses/i2c-designware-core.h
> @@ -271,6 +271,9 @@ struct dw_i2c_dev {
>  	int			(*init)(struct dw_i2c_dev *dev);
>  	int			mode;
>  	struct i2c_bus_recovery_info rinfo;
> +	struct pinctrl		*pinctrl;
> +	struct pinctrl_state	*pins_default;
> +	struct pinctrl_state	*pins_gpio;
>  };
>  
>  #define ACCESS_SWAP		0x00000001
> diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
> index 94d94b4a9a0d..384d6630366a 100644
> --- a/drivers/i2c/busses/i2c-designware-master.c
> +++ b/drivers/i2c/busses/i2c-designware-master.c
> @@ -17,6 +17,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/pinctrl/consumer.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/reset.h>
>  
> @@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
>  {
>  	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
>  
> +	if (dev->pinctrl && dev->pins_gpio)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
> +
>  	i2c_dw_disable(dev);
>  	reset_control_assert(dev->rst);
>  	i2c_dw_prepare_clk(dev, false);
> @@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
>  	i2c_dw_prepare_clk(dev, true);
>  	reset_control_deassert(dev->rst);
>  	i2c_dw_init_master(dev);
> +
> +	if (dev->pinctrl && dev->pins_default)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_default);
>  }
>  
>  static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
> @@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>  	struct i2c_adapter *adap = &dev->adapter;
>  	struct gpio_desc *gpio;
> +	struct pinctrl *pinctrl;
> +	struct pinctrl_state *s;
>  	int r;
>  
>  	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
> @@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  		return PTR_ERR(gpio);
>  	rinfo->sda_gpiod = gpio;
>  
> +	pinctrl = devm_pinctrl_get(dev->dev);
> +	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
> +		return -EPROBE_DEFER;
> +	if (!IS_ERR_OR_NULL(pinctrl)) {
> +		dev->pinctrl = pinctrl;
> +		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_default = s;
> +		s = pinctrl_lookup_state(pinctrl, "gpio");
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_gpio = s;
> +	}
> +
>  	rinfo->recover_bus = i2c_generic_scl_recovery;
>  	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
>  	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:34     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:34 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

+ DT maintainers

On Mon, 17 Sep 2018 11:29:49 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/i2c/busses/i2c-designware-core.h   |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
> index e367b1af4ab2..01d5f01691a4 100644
> --- a/drivers/i2c/busses/i2c-designware-core.h
> +++ b/drivers/i2c/busses/i2c-designware-core.h
> @@ -271,6 +271,9 @@ struct dw_i2c_dev {
>  	int			(*init)(struct dw_i2c_dev *dev);
>  	int			mode;
>  	struct i2c_bus_recovery_info rinfo;
> +	struct pinctrl		*pinctrl;
> +	struct pinctrl_state	*pins_default;
> +	struct pinctrl_state	*pins_gpio;
>  };
>  
>  #define ACCESS_SWAP		0x00000001
> diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
> index 94d94b4a9a0d..384d6630366a 100644
> --- a/drivers/i2c/busses/i2c-designware-master.c
> +++ b/drivers/i2c/busses/i2c-designware-master.c
> @@ -17,6 +17,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/pinctrl/consumer.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/reset.h>
>  
> @@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
>  {
>  	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
>  
> +	if (dev->pinctrl && dev->pins_gpio)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
> +
>  	i2c_dw_disable(dev);
>  	reset_control_assert(dev->rst);
>  	i2c_dw_prepare_clk(dev, false);
> @@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
>  	i2c_dw_prepare_clk(dev, true);
>  	reset_control_deassert(dev->rst);
>  	i2c_dw_init_master(dev);
> +
> +	if (dev->pinctrl && dev->pins_default)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_default);
>  }
>  
>  static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
> @@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>  	struct i2c_adapter *adap = &dev->adapter;
>  	struct gpio_desc *gpio;
> +	struct pinctrl *pinctrl;
> +	struct pinctrl_state *s;
>  	int r;
>  
>  	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
> @@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  		return PTR_ERR(gpio);
>  	rinfo->sda_gpiod = gpio;
>  
> +	pinctrl = devm_pinctrl_get(dev->dev);
> +	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
> +		return -EPROBE_DEFER;
> +	if (!IS_ERR_OR_NULL(pinctrl)) {
> +		dev->pinctrl = pinctrl;
> +		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_default = s;
> +		s = pinctrl_lookup_state(pinctrl, "gpio");
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_gpio = s;
> +	}
> +
>  	rinfo->recover_bus = i2c_generic_scl_recovery;
>  	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
>  	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-17  3:34     ` Jisheng Zhang
  0 siblings, 0 replies; 26+ messages in thread
From: Jisheng Zhang @ 2018-09-17  3:34 UTC (permalink / raw)
  To: linux-arm-kernel

+ DT maintainers

On Mon, 17 Sep 2018 11:29:49 +0800
Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:

> On some platforms, the sda/scl pins are muxed with gpio functions, so
> they could be used for recovery. Select the gpio/default pin function
> when prepare/unprepare recovery.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/i2c/busses/i2c-designware-core.h   |  3 +++
>  drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
> index e367b1af4ab2..01d5f01691a4 100644
> --- a/drivers/i2c/busses/i2c-designware-core.h
> +++ b/drivers/i2c/busses/i2c-designware-core.h
> @@ -271,6 +271,9 @@ struct dw_i2c_dev {
>  	int			(*init)(struct dw_i2c_dev *dev);
>  	int			mode;
>  	struct i2c_bus_recovery_info rinfo;
> +	struct pinctrl		*pinctrl;
> +	struct pinctrl_state	*pins_default;
> +	struct pinctrl_state	*pins_gpio;
>  };
>  
>  #define ACCESS_SWAP		0x00000001
> diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
> index 94d94b4a9a0d..384d6630366a 100644
> --- a/drivers/i2c/busses/i2c-designware-master.c
> +++ b/drivers/i2c/busses/i2c-designware-master.c
> @@ -17,6 +17,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/pinctrl/consumer.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/reset.h>
>  
> @@ -629,6 +630,9 @@ static void i2c_dw_prepare_recovery(struct i2c_adapter *adap)
>  {
>  	struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
>  
> +	if (dev->pinctrl && dev->pins_gpio)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_gpio);
> +
>  	i2c_dw_disable(dev);
>  	reset_control_assert(dev->rst);
>  	i2c_dw_prepare_clk(dev, false);
> @@ -641,6 +645,9 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
>  	i2c_dw_prepare_clk(dev, true);
>  	reset_control_deassert(dev->rst);
>  	i2c_dw_init_master(dev);
> +
> +	if (dev->pinctrl && dev->pins_default)
> +		pinctrl_select_state(dev->pinctrl, dev->pins_default);
>  }
>  
>  static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
> @@ -648,6 +655,8 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>  	struct i2c_adapter *adap = &dev->adapter;
>  	struct gpio_desc *gpio;
> +	struct pinctrl *pinctrl;
> +	struct pinctrl_state *s;
>  	int r;
>  
>  	gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
> @@ -664,6 +673,19 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
>  		return PTR_ERR(gpio);
>  	rinfo->sda_gpiod = gpio;
>  
> +	pinctrl = devm_pinctrl_get(dev->dev);
> +	if (PTR_ERR(pinctrl) == -EPROBE_DEFER)
> +		return -EPROBE_DEFER;
> +	if (!IS_ERR_OR_NULL(pinctrl)) {
> +		dev->pinctrl = pinctrl;
> +		s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_DEFAULT);
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_default = s;
> +		s = pinctrl_lookup_state(pinctrl, "gpio");
> +		if (!IS_ERR_OR_NULL(s))
> +			dev->pins_gpio = s;
> +	}
> +
>  	rinfo->recover_bus = i2c_generic_scl_recovery;
>  	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
>  	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
  2018-09-17  3:34     ` Jisheng Zhang
@ 2018-09-18 13:25       ` Jarkko Nikula
  -1 siblings, 0 replies; 26+ messages in thread
From: Jarkko Nikula @ 2018-09-18 13:25 UTC (permalink / raw)
  To: Jisheng Zhang, Andy Shevchenko, Mika Westerberg, Wolfram Sang,
	Rob Herring, Mark Rutland
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, devicetree

On 09/17/2018 06:34 AM, Jisheng Zhang wrote:
> + DT maintainers
> 
> On Mon, 17 Sep 2018 11:29:49 +0800
> Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:
> 
>> On some platforms, the sda/scl pins are muxed with gpio functions, so
>> they could be used for recovery. Select the gpio/default pin function
>> when prepare/unprepare recovery.
>>
>> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
>> ---
>>   drivers/i2c/busses/i2c-designware-core.h   |  3 +++
>>   drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
>>   2 files changed, 25 insertions(+)
>>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery
@ 2018-09-18 13:25       ` Jarkko Nikula
  0 siblings, 0 replies; 26+ messages in thread
From: Jarkko Nikula @ 2018-09-18 13:25 UTC (permalink / raw)
  To: linux-arm-kernel

On 09/17/2018 06:34 AM, Jisheng Zhang wrote:
> + DT maintainers
> 
> On Mon, 17 Sep 2018 11:29:49 +0800
> Jisheng Zhang <Jisheng.Zhang@synaptics.com> wrote:
> 
>> On some platforms, the sda/scl pins are muxed with gpio functions, so
>> they could be used for recovery. Select the gpio/default pin function
>> when prepare/unprepare recovery.
>>
>> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
>> ---
>>   drivers/i2c/busses/i2c-designware-core.h   |  3 +++
>>   drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++++++++++++
>>   2 files changed, 25 insertions(+)
>>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2018-09-18 13:25 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17  3:26 [PATCH v3 0/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery Jisheng Zhang
2018-09-17  3:26 ` Jisheng Zhang
2018-09-17  3:26 ` Jisheng Zhang
2018-09-17  3:27 ` [PATCH v3 1/3] dt-bindings: i2c: designware: add optional gpio recovery properties Jisheng Zhang
2018-09-17  3:27   ` Jisheng Zhang
2018-09-17  3:27   ` Jisheng Zhang
2018-09-17  3:32   ` Jisheng Zhang
2018-09-17  3:32     ` Jisheng Zhang
2018-09-17  3:32     ` Jisheng Zhang
2018-09-17  3:28 ` [PATCH v3 2/3] dt-bindings: i2c: designware: add optional pinctrl for bus recovery Jisheng Zhang
2018-09-17  3:28   ` Jisheng Zhang
2018-09-17  3:28   ` Jisheng Zhang
2018-09-17  3:33   ` Jisheng Zhang
2018-09-17  3:33     ` Jisheng Zhang
2018-09-17  3:33     ` Jisheng Zhang
2018-09-17  3:29 ` [PATCH v3 3/3] i2c: designware: select gpio/default pin when prepare/unprepare recovery Jisheng Zhang
2018-09-17  3:29   ` Jisheng Zhang
2018-09-17  3:29   ` Jisheng Zhang
2018-09-17  3:34   ` Jisheng Zhang
2018-09-17  3:34     ` Jisheng Zhang
2018-09-17  3:34     ` Jisheng Zhang
2018-09-18 13:25     ` Jarkko Nikula
2018-09-18 13:25       ` Jarkko Nikula
2018-09-17  3:31 ` [PATCH v3 0/3] " Jisheng Zhang
2018-09-17  3:31   ` Jisheng Zhang
2018-09-17  3:31   ` Jisheng Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.