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 <[email protected]>
---
 drivers/i2c/busses/i2c-gpio.c | 9 +++++++++
 1 file changed, 9 insertions(+)

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;
 
-- 
2.7.4

Reply via email to