summaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorMarco Felsch <m.felsch@pengutronix.de>2019-06-17 12:00:56 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-06-26 08:41:03 +0200
commita94a9bf643a77d6b793afd56efdf6afeae4be68a (patch)
tree5e007471f36cabd76eba68fa557cd4db83ebcd1e /drivers/i2c
parent63752a90a38439f6ef39613c5b9e48e5b40531a7 (diff)
downloadbarebox-a94a9bf643a77d6b793afd56efdf6afeae4be68a.tar.gz
barebox-a94a9bf643a77d6b793afd56efdf6afeae4be68a.tar.xz
i2c: gpio: add sda/scl-gpios property support
The gpios property is marked as deprecated since kernel 4.15 so we should support the "new" mechanism too. The new mechanism has a higher priority than the deprecated one. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-gpio.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 708193344a..5ab43fe935 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -94,18 +94,25 @@ static int of_i2c_gpio_probe(struct device_node *np,
if (!IS_ENABLED(CONFIG_OFDEVICE))
return -ENODEV;
- if (of_gpio_count(np) < 2)
- return -ENODEV;
+ pdata->sda_pin = of_get_named_gpio_flags(np, "sda-gpios", 0, NULL);
+ pdata->scl_pin = of_get_named_gpio_flags(np, "scl-gpios", 0, NULL);
+
+ if ((!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin))
+ && (of_gpio_count(np) >= 2)) {
+ /* Note: The gpios property is marked as deprecated */
+ ret = of_get_gpio(np, 0);
+ if (ret < 0)
+ return ret;
+ pdata->sda_pin = ret;
- ret = of_get_gpio(np, 0);
- if (ret < 0)
- return ret;
- pdata->sda_pin = ret;
+ ret = of_get_gpio(np, 1);
+ if (ret < 0)
+ return ret;
+ pdata->scl_pin = ret;
+ }
- ret = of_get_gpio(np, 1);
- if (ret < 0)
- return ret;
- pdata->scl_pin = ret;
+ if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin))
+ return -ENODEV;
of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);