mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio
@ 2016-11-16 12:18 Uwe Kleine-König
  2016-11-16 12:18 ` [PATCH 2/3] i2c: gpio: use dynamic bus number unconditionally Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-11-16 12:18 UTC (permalink / raw)
  To: barebox

Instead of using gpio_is_valid just check the return code of of_get_gpio
for being < 0. This fixes -EPROBE_DEFER handling as now this error code
is handed to the caller instead of -ENODEV. If the gpio returned by
of_get_gpio is an invalid number this isn't noticed by
of_i2c_gpio_probe, but then gpio_request later fails which is good
enough.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/i2c/busses/i2c-gpio.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 9362ed181fe3..850db7b2f652 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -89,6 +89,7 @@ static int of_i2c_gpio_probe(struct device_node *np,
 			     struct i2c_gpio_platform_data *pdata)
 {
 	u32 reg;
+	int ret;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE))
 		return -ENODEV;
@@ -96,14 +97,15 @@ static int of_i2c_gpio_probe(struct device_node *np,
 	if (of_gpio_count(np) < 2)
 		return -ENODEV;
 
-	pdata->sda_pin = of_get_gpio(np, 0);
-	pdata->scl_pin = of_get_gpio(np, 1);
+	ret = of_get_gpio(np, 0);
+	if (ret < 0)
+		return ret;
+	pdata->sda_pin = ret;
 
-	if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin)) {
-		pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
-		       np->full_name, pdata->sda_pin, pdata->scl_pin);
-		return -ENODEV;
-	}
+	ret = of_get_gpio(np, 1);
+	if (ret < 0)
+		return ret;
+	pdata->scl_pin = ret;
 
 	of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
 
-- 
2.10.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/3] i2c: gpio: use dynamic bus number unconditionally
  2016-11-16 12:18 [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Uwe Kleine-König
@ 2016-11-16 12:18 ` Uwe Kleine-König
  2016-11-16 12:18 ` [PATCH 3/3] i2c: algo-bit: remove prototype for non-existing function Uwe Kleine-König
  2016-11-17  6:59 ` [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-11-16 12:18 UTC (permalink / raw)
  To: barebox

While being a bit more random this helps dt setups where the id of a
platform device cannot easily be fixed anyhow.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/i2c/busses/i2c-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 850db7b2f652..708193344aec 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -198,7 +198,7 @@ static int i2c_gpio_probe(struct device_d *dev)
 	adap->bus_recovery_info->set_scl = i2c_set_scl_gpio_value;
 	adap->bus_recovery_info->recover_bus = i2c_generic_scl_recovery;
 
-	adap->nr = dev->id;
+	adap->nr = -1;
 	ret = i2c_bit_add_numbered_bus(adap);
 	if (ret)
 		goto err_add_bus;
-- 
2.10.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/3] i2c: algo-bit: remove prototype for non-existing function
  2016-11-16 12:18 [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Uwe Kleine-König
  2016-11-16 12:18 ` [PATCH 2/3] i2c: gpio: use dynamic bus number unconditionally Uwe Kleine-König
@ 2016-11-16 12:18 ` Uwe Kleine-König
  2016-11-17  6:59 ` [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-11-16 12:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 include/i2c/i2c-algo-bit.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/i2c/i2c-algo-bit.h b/include/i2c/i2c-algo-bit.h
index 1b722196875c..91c84361882c 100644
--- a/include/i2c/i2c-algo-bit.h
+++ b/include/i2c/i2c-algo-bit.h
@@ -48,7 +48,6 @@ struct i2c_algo_bit_data {
 	int timeout_ms;		/* in ms */
 };
 
-int i2c_bit_add_bus(struct i2c_adapter *);
 int i2c_bit_add_numbered_bus(struct i2c_adapter *);
 extern const struct i2c_algorithm i2c_bit_algo;
 
-- 
2.10.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio
  2016-11-16 12:18 [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Uwe Kleine-König
  2016-11-16 12:18 ` [PATCH 2/3] i2c: gpio: use dynamic bus number unconditionally Uwe Kleine-König
  2016-11-16 12:18 ` [PATCH 3/3] i2c: algo-bit: remove prototype for non-existing function Uwe Kleine-König
@ 2016-11-17  6:59 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-11-17  6:59 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Wed, Nov 16, 2016 at 01:18:49PM +0100, Uwe Kleine-König wrote:
> Instead of using gpio_is_valid just check the return code of of_get_gpio
> for being < 0. This fixes -EPROBE_DEFER handling as now this error code
> is handed to the caller instead of -ENODEV. If the gpio returned by
> of_get_gpio is an invalid number this isn't noticed by
> of_i2c_gpio_probe, but then gpio_request later fails which is good
> enough.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Applied, thanks

Sascha

> ---
>  drivers/i2c/busses/i2c-gpio.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
> index 9362ed181fe3..850db7b2f652 100644
> --- a/drivers/i2c/busses/i2c-gpio.c
> +++ b/drivers/i2c/busses/i2c-gpio.c
> @@ -89,6 +89,7 @@ static int of_i2c_gpio_probe(struct device_node *np,
>  			     struct i2c_gpio_platform_data *pdata)
>  {
>  	u32 reg;
> +	int ret;
>  
>  	if (!IS_ENABLED(CONFIG_OFDEVICE))
>  		return -ENODEV;
> @@ -96,14 +97,15 @@ static int of_i2c_gpio_probe(struct device_node *np,
>  	if (of_gpio_count(np) < 2)
>  		return -ENODEV;
>  
> -	pdata->sda_pin = of_get_gpio(np, 0);
> -	pdata->scl_pin = of_get_gpio(np, 1);
> +	ret = of_get_gpio(np, 0);
> +	if (ret < 0)
> +		return ret;
> +	pdata->sda_pin = ret;
>  
> -	if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin)) {
> -		pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
> -		       np->full_name, pdata->sda_pin, pdata->scl_pin);
> -		return -ENODEV;
> -	}
> +	ret = of_get_gpio(np, 1);
> +	if (ret < 0)
> +		return ret;
> +	pdata->scl_pin = ret;
>  
>  	of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
>  
> -- 
> 2.10.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2016-11-17  6:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-16 12:18 [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Uwe Kleine-König
2016-11-16 12:18 ` [PATCH 2/3] i2c: gpio: use dynamic bus number unconditionally Uwe Kleine-König
2016-11-16 12:18 ` [PATCH 3/3] i2c: algo-bit: remove prototype for non-existing function Uwe Kleine-König
2016-11-17  6:59 ` [PATCH 1/3] i2c: gpio: fix handling of return code of of_get_gpio Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox