Patchwork i2c: imx: use of_alias_get_id to order i2c devices

login
register
mail settings
Submitter Philipp Zabel
Date April 9, 2013, 5:09 p.m.
Message ID <1365527379-17786-1-git-send-email-p.zabel@pengutronix.de>
Download mbox | patch
Permalink /patch/235145/
State Rejected
Headers show

Comments

Philipp Zabel - April 9, 2013, 5:09 p.m.
This allows to order i2c character devices as they are numbered
in the reference manual, instead of ordering them by register
base address.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Shawn Guo - April 12, 2013, 1:49 a.m.
On Tue, Apr 09, 2013 at 07:09:39PM +0200, Philipp Zabel wrote:
> This allows to order i2c character devices as they are numbered
> in the reference manual, instead of ordering them by register
> base address.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

I'm fine with the patch, but let's see if DT maintainers have an
opinion.

Shawn

> ---
>  drivers/i2c/busses/i2c-imx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 82f20c6..e5a3f08 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -488,6 +488,7 @@ static struct i2c_algorithm i2c_imx_algo = {
>  
>  static int __init i2c_imx_probe(struct platform_device *pdev)
>  {
> +	struct device_node *np = pdev->dev.of_node;
>  	const struct of_device_id *of_id = of_match_device(i2c_imx_dt_ids,
>  							   &pdev->dev);
>  	struct imx_i2c_struct *i2c_imx;
> @@ -531,7 +532,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  	i2c_imx->adapter.owner		= THIS_MODULE;
>  	i2c_imx->adapter.algo		= &i2c_imx_algo;
>  	i2c_imx->adapter.dev.parent	= &pdev->dev;
> -	i2c_imx->adapter.nr 		= pdev->id;
> +	i2c_imx->adapter.nr		= (pdev->id < 0) ? of_alias_get_id(np, "i2c") : pdev->id;
>  	i2c_imx->adapter.dev.of_node	= pdev->dev.of_node;
>  	i2c_imx->base			= base;
>  
> -- 
> 1.8.2.rc2
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang - April 16, 2013, 9:17 a.m.
On Tue, Apr 09, 2013 at 07:09:39PM +0200, Philipp Zabel wrote:
> This allows to order i2c character devices as they are numbered
> in the reference manual, instead of ordering them by register
> base address.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

ee5c27440cc24d62ec463cce4c000bb32c5692c7 in i2c/for-next does this on
core level.

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Philipp Zabel - April 16, 2013, 9:25 a.m.
Am Dienstag, den 16.04.2013, 11:17 +0200 schrieb Wolfram Sang:
> On Tue, Apr 09, 2013 at 07:09:39PM +0200, Philipp Zabel wrote:
> > This allows to order i2c character devices as they are numbered
> > in the reference manual, instead of ordering them by register
> > base address.
> > 
> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> 
> ee5c27440cc24d62ec463cce4c000bb32c5692c7 in i2c/for-next does this on
> core level.

Excellent, thanks!

regards
Philipp

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 82f20c6..e5a3f08 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -488,6 +488,7 @@  static struct i2c_algorithm i2c_imx_algo = {
 
 static int __init i2c_imx_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id = of_match_device(i2c_imx_dt_ids,
 							   &pdev->dev);
 	struct imx_i2c_struct *i2c_imx;
@@ -531,7 +532,7 @@  static int __init i2c_imx_probe(struct platform_device *pdev)
 	i2c_imx->adapter.owner		= THIS_MODULE;
 	i2c_imx->adapter.algo		= &i2c_imx_algo;
 	i2c_imx->adapter.dev.parent	= &pdev->dev;
-	i2c_imx->adapter.nr 		= pdev->id;
+	i2c_imx->adapter.nr		= (pdev->id < 0) ? of_alias_get_id(np, "i2c") : pdev->id;
 	i2c_imx->adapter.dev.of_node	= pdev->dev.of_node;
 	i2c_imx->base			= base;