[PATCH/RFC,2/3] i2c: gpio: Add support for named gpios in DT

Message ID 1503566474-5335-3-git-send-email-geert+renesas@glider.be
State New
Headers show

Commit Message

Geert Uytterhoeven Aug. 24, 2017, 9:21 a.m.
Add support for the new DT bindings using named gpios, which are less
error-prone than unnamed gpios.  The latter are still supported as a
fallback.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/i2c/busses/i2c-gpio.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Wolfram Sang Sept. 13, 2017, 8:53 p.m. | #1
> +	/* Try deprecated unnamed gpios */

I think adding "(deprecated use)" or sth would be good.
Wolfram Sang Sept. 13, 2017, 8:57 p.m. | #2
On Wed, Sep 13, 2017 at 10:53:33PM +0200, Wolfram Sang wrote:
> 
> > +	/* Try deprecated unnamed gpios */
> 
> I think adding "(deprecated use)" or sth would be good.

Where is my brown paper bag :)

Patch

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 0ef8fcc6ac3aca1e..45b7ec99dc210bbe 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -88,6 +88,15 @@  static int i2c_gpio_getscl(void *data)
 static int of_i2c_gpio_get_pins(struct device_node *np,
 				unsigned int *sda_pin, unsigned int *scl_pin)
 {
+	*sda_pin = of_get_named_gpio(np, "sda-gpios", 0);
+	*scl_pin = of_get_named_gpio(np, "scl-gpios", 0);
+	if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	if (gpio_is_valid(*sda_pin) && gpio_is_valid(*scl_pin))
+		return 0;
+
+	/* Try deprecated unnamed gpios */
 	if (of_gpio_count(np) < 2)
 		return -ENODEV;