Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree
@ 2013-02-12  0:48 Doug Anderson
  2013-02-12  0:48 ` [PATCH v3 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Doug Anderson @ 2013-02-12  0:48 UTC (permalink / raw)
  To: linux-arm-kernel

This was suggested by Mark Brown in response to a patch for adding
this functionality only for the s3c2410 bus:
  https://lkml.org/lkml/2012/11/20/681

I have also modified the i2c-pxa driver to use this new functionality.
The i2c-pxa driver changes have only been compile-tested and are just
for cleanup purposes.

Changes in v3:
- Addressed Wolfram's feedback; rebased atop idr-cleanup series.

Changes in v2:
- No longer tweak pdev->id as per Sylwester Nawrocki.
- No longer add the dev ID to the adap.name.  Other drivers don't
  include the device ID here and it doesn't make sense with
  dynamically (or automatically) allocated IDs.
- Use dev_name(&dev->dev) to register for the IRQ; this matches what
  the i2c-s3c2410.c does and handles dynamically allocated IDs.
- This change was only compile-tested (corgi_defconfig), since I don't
  have access to a board that uses this driver.

Doug Anderson (2):
  i2c-core: dt: Pick i2c bus number from i2c alias if present
  i2c: pxa: Use i2c-core to get bus number now

 drivers/i2c/busses/i2c-pxa.c | 20 ++++++++--------
 drivers/i2c/i2c-core.c       | 54 ++++++++++++++++++++++++++++++++------------
 2 files changed, 49 insertions(+), 25 deletions(-)

-- 
1.8.1

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

* [PATCH v3 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present
  2013-02-12  0:48 [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
@ 2013-02-12  0:48 ` Doug Anderson
  2013-02-12  0:48 ` [PATCH v3 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Doug Anderson @ 2013-02-12  0:48 UTC (permalink / raw)
  To: linux-arm-kernel

This allows you to get the equivalent functionality of
i2c_add_numbered_adapter() with all data in the device tree and no
special case code in your driver.  This is a common device tree
technique.

For quick reference, the FDT syntax for using an alias to provide an
ID looks like:
  aliases {
    i2c0 = &i2c_0;
    i2c1 = &i2c_1;
  };

Signed-off-by: Doug Anderson <dianders@chromium.org>

---
Changes in v3:
- Addressed Wolfram's feedback; rebased atop idr-cleanup series.

Changes in v2: None

 drivers/i2c/i2c-core.c | 54 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 14 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0b599f2..5204818 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -921,13 +921,41 @@ out_list:
 }
 
 /**
+ * __i2c_add_numbered_adapter - i2c_add_numbered_adapter where nr is never -1
+ * @adap: the adapter to register (with adap->nr initialized)
+ * Context: can sleep
+ *
+ * See i2c_add_numbered_adapter() for details.
+ */
+static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
+{
+	int	id;
+
+	/* Handled by wrappers */
+	if (WARN_ON(adap->nr == -1))
+		return -EINVAL;
+
+	if (adap->nr & ~MAX_IDR_MASK)
+		return -EINVAL;
+
+	mutex_lock(&core_lock);
+	id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
+		       GFP_KERNEL);
+	mutex_unlock(&core_lock);
+	if (id < 0)
+		return id == -ENOSPC ? -EBUSY : id;
+	return i2c_register_adapter(adap);
+}
+
+/**
  * i2c_add_adapter - declare i2c adapter, use dynamic bus number
  * @adapter: the adapter to add
  * Context: can sleep
  *
  * This routine is used to declare an I2C adapter when its bus number
- * doesn't matter.  Examples: for I2C adapters dynamically added by
- * USB links or PCI plugin cards.
+ * doesn't matter or when its bus number is specified by an dt alias.
+ * Examples of bases when the bus number doesn't matter: I2C adapters
+ * dynamically added by USB links or PCI plugin cards.
  *
  * When this returns zero, a new bus number was allocated and stored
  * in adap->nr, and the specified adapter became available for clients.
@@ -935,8 +963,17 @@ out_list:
  */
 int i2c_add_adapter(struct i2c_adapter *adapter)
 {
+	struct device *dev = &adapter->dev;
 	int res;
 
+	if (dev->of_node) {
+		res = of_alias_get_id(dev->of_node, "i2c");
+		if (res >= 0) {
+			adapter->nr = res;
+			return __i2c_add_numbered_adapter(adapter);
+		}
+	}
+
 	mutex_lock(&core_lock);
 	res = idr_alloc(&i2c_adapter_idr, adapter,
 			__i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
@@ -974,20 +1011,9 @@ EXPORT_SYMBOL(i2c_add_adapter);
  */
 int i2c_add_numbered_adapter(struct i2c_adapter *adap)
 {
-	int	id;
-
 	if (adap->nr == -1) /* -1 means dynamically assign bus id */
 		return i2c_add_adapter(adap);
-	if (adap->nr & ~MAX_IDR_MASK)
-		return -EINVAL;
-
-	mutex_lock(&core_lock);
-	id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
-		       GFP_KERNEL);
-	mutex_unlock(&core_lock);
-	if (id < 0)
-		return id == -ENOSPC ? -EBUSY : id;
-	return i2c_register_adapter(adap);
+	return __i2c_add_numbered_adapter(adap);
 }
 EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
 
-- 
1.8.1

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

* [PATCH v3 2/2] i2c: pxa: Use i2c-core to get bus number now
  2013-02-12  0:48 [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
  2013-02-12  0:48 ` [PATCH v3 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
@ 2013-02-12  0:48 ` Doug Anderson
  2013-02-27  1:01 ` [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
  2013-03-01 16:57 ` [PATCH v4 " Doug Anderson
  3 siblings, 0 replies; 11+ messages in thread
From: Doug Anderson @ 2013-02-12  0:48 UTC (permalink / raw)
  To: linux-arm-kernel

The commit: "i2c-core: dt: Pick i2c bus number from i2c alias if
present" adds support for automatically picking the bus number based
on the alias ID.  Remove the now unnecessary code from i2c-pxa that
did the same thing.

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
Changes in v3: None
Changes in v2:
- No longer tweak pdev->id as per Sylwester Nawrocki.
- No longer add the dev ID to the adap.name.  Other drivers don't
  include the device ID here and it doesn't make sense with
  dynamically (or automatically) allocated IDs.
- Use dev_name(&dev->dev) to register for the IRQ; this matches what
  the i2c-s3c2410.c does and handles dynamically allocated IDs.
- This change was only compile-tested (corgi_defconfig), since I don't
  have access to a board that uses this driver.

 drivers/i2c/busses/i2c-pxa.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 1034d93..705cc9f 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1053,16 +1053,13 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id =
 			of_match_device(i2c_pxa_dt_ids, &pdev->dev);
-	int ret;
 
 	if (!of_id)
 		return 1;
-	ret = of_alias_get_id(np, "i2c");
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
-		return ret;
-	}
-	pdev->id = ret;
+
+	/* For device tree we always use the dynamic or alias-assigned ID */
+	i2c->adap.nr = -1;
+
 	if (of_get_property(np, "mrvl,i2c-polling", NULL))
 		i2c->use_pio = 1;
 	if (of_get_property(np, "mrvl,i2c-fast-mode", NULL))
@@ -1100,6 +1097,9 @@ static int i2c_pxa_probe(struct platform_device *dev)
 		goto emalloc;
 	}
 
+	/* Default adapter num to device id; i2c_pxa_probe_dt can override. */
+	i2c->adap.nr = dev->id;
+
 	ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
 	if (ret > 0)
 		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
@@ -1124,9 +1124,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	spin_lock_init(&i2c->lock);
 	init_waitqueue_head(&i2c->wait);
 
-	i2c->adap.nr = dev->id;
-	snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
-		 i2c->adap.nr);
+	strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
 
 	i2c->clk = clk_get(&dev->dev, NULL);
 	if (IS_ERR(i2c->clk)) {
@@ -1169,7 +1167,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	} else {
 		i2c->adap.algo = &i2c_pxa_algorithm;
 		ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
-				  i2c->adap.name, i2c);
+				  dev_name(&dev->dev), i2c);
 		if (ret)
 			goto ereqirq;
 	}
-- 
1.8.1

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

* [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree
  2013-02-12  0:48 [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
  2013-02-12  0:48 ` [PATCH v3 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
  2013-02-12  0:48 ` [PATCH v3 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
@ 2013-02-27  1:01 ` Doug Anderson
  2013-02-28 23:25   ` Wolfram Sang
  2013-03-01 16:57 ` [PATCH v4 " Doug Anderson
  3 siblings, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2013-02-27  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

Wolfram,

On Mon, Feb 11, 2013 at 4:48 PM, Doug Anderson <dianders@chromium.org> wrote:
> This was suggested by Mark Brown in response to a patch for adding
> this functionality only for the s3c2410 bus:
>   https://lkml.org/lkml/2012/11/20/681
>
> I have also modified the i2c-pxa driver to use this new functionality.
> The i2c-pxa driver changes have only been compile-tested and are just
> for cleanup purposes.
>
> Changes in v3:
> - Addressed Wolfram's feedback; rebased atop idr-cleanup series.
>
> Changes in v2:
> - No longer tweak pdev->id as per Sylwester Nawrocki.
> - No longer add the dev ID to the adap.name.  Other drivers don't
>   include the device ID here and it doesn't make sense with
>   dynamically (or automatically) allocated IDs.
> - Use dev_name(&dev->dev) to register for the IRQ; this matches what
>   the i2c-s3c2410.c does and handles dynamically allocated IDs.
> - This change was only compile-tested (corgi_defconfig), since I don't
>   have access to a board that uses this driver.
>
> Doug Anderson (2):
>   i2c-core: dt: Pick i2c bus number from i2c alias if present
>   i2c: pxa: Use i2c-core to get bus number now
>
>  drivers/i2c/busses/i2c-pxa.c | 20 ++++++++--------
>  drivers/i2c/i2c-core.c       | 54 ++++++++++++++++++++++++++++++++------------
>  2 files changed, 49 insertions(+), 25 deletions(-)

Is there anything else needed for this patch series?  It's been
hanging around for quite a while and it would be nice to see it land.
If you're waiting for additional acks or reviews I'll ask around and
see if I can get them...

Thanks!  :)

-Doug

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

* [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree
  2013-02-27  1:01 ` [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
@ 2013-02-28 23:25   ` Wolfram Sang
  2013-03-01  0:55     ` Doug Anderson
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2013-02-28 23:25 UTC (permalink / raw)
  To: linux-arm-kernel


> > Doug Anderson (2):
> >   i2c-core: dt: Pick i2c bus number from i2c alias if present
> >   i2c: pxa: Use i2c-core to get bus number now
> >
> >  drivers/i2c/busses/i2c-pxa.c | 20 ++++++++--------
> >  drivers/i2c/i2c-core.c       | 54 ++++++++++++++++++++++++++++++++------------
> >  2 files changed, 49 insertions(+), 25 deletions(-)
> 
> Is there anything else needed for this patch series?  It's been
> hanging around for quite a while and it would be nice to see it land.
> If you're waiting for additional acks or reviews I'll ask around and
> see if I can get them...

Regarding patch 1, I was waiting for the idr changes to hit mainline.
They are mainline now, but since the removal of MAX_IDR_MASK your patch
doesn't apply anymore :( Can you rebase and retest, please? I'd like to
get it into 3.9, still.

For patch 2, some Tested-by would be nice; but it will probably make it
into my for-next somewhen after rc1 is out.

Thanks,

   Wolfram

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

* [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree
  2013-02-28 23:25   ` Wolfram Sang
@ 2013-03-01  0:55     ` Doug Anderson
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Anderson @ 2013-03-01  0:55 UTC (permalink / raw)
  To: linux-arm-kernel

Wolfram,

On Thu, Feb 28, 2013 at 3:25 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
> Regarding patch 1, I was waiting for the idr changes to hit mainline.
> They are mainline now, but since the removal of MAX_IDR_MASK your patch
> doesn't apply anymore :( Can you rebase and retest, please? I'd like to
> get it into 3.9, still.

Yes, I'll rebase/retest tomorrow.  I'll let you make the call between
3.9 and 3.10.  Obviously I'd love to see it in 3.9 but I'm OK with
either.  I was just hoping not to find out at the end of the 3.10
cycle that it needs fixes and need to wait for 3.11.  I wanted to make
sure all my ducks were in a row.  ;-)


> For patch 2, some Tested-by would be nice; but it will probably make it
> into my for-next somewhen after rc1 is out.

I have no urgent need for patch 2 to land but it seemed nice to tidy
up the pxa driver and I felt it was my obligation to post it together
with patch set #1 (plus it's always nice to remove code).  Putting it
into your for-next seems like a very good solution.  That gives people
some time to test it and make sure it works for them.


Thanks!

-Doug

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

* [PATCH v4 0/2] Add automatic bus number support for i2c busses with device tree
  2013-02-12  0:48 [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
                   ` (2 preceding siblings ...)
  2013-02-27  1:01 ` [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
@ 2013-03-01 16:57 ` Doug Anderson
  2013-03-01 16:57   ` [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
  2013-03-01 16:57   ` [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
  3 siblings, 2 replies; 11+ messages in thread
From: Doug Anderson @ 2013-03-01 16:57 UTC (permalink / raw)
  To: linux-arm-kernel

This was suggested by Mark Brown in response to a patch for adding
this functionality only for the s3c2410 bus:
  https://lkml.org/lkml/2012/11/20/681

I have also modified the i2c-pxa driver to use this new functionality.
The i2c-pxa driver changes have only been compile-tested and are just
for cleanup purposes.

Changes in v4:
- Rebased atop the removal of MAX_IDR_MASK.

Changes in v3:
- Addressed Wolfram's feedback; rebased atop idr-cleanup series.

Changes in v2:
- No longer tweak pdev->id as per Sylwester Nawrocki.
- No longer add the dev ID to the adap.name.  Other drivers don't
  include the device ID here and it doesn't make sense with
  dynamically (or automatically) allocated IDs.
- Use dev_name(&dev->dev) to register for the IRQ; this matches what
  the i2c-s3c2410.c does and handles dynamically allocated IDs.
- This change was only compile-tested (corgi_defconfig), since I don't
  have access to a board that uses this driver.

Doug Anderson (2):
  i2c-core: dt: Pick i2c bus number from i2c alias if present
  i2c: pxa: Use i2c-core to get bus number now

 drivers/i2c/busses/i2c-pxa.c | 20 ++++++++----------
 drivers/i2c/i2c-core.c       | 49 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 46 insertions(+), 23 deletions(-)

-- 
1.8.1.3

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

* [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present
  2013-03-01 16:57 ` [PATCH v4 " Doug Anderson
@ 2013-03-01 16:57   ` Doug Anderson
  2013-03-01 19:22     ` Wolfram Sang
  2013-03-01 16:57   ` [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
  1 sibling, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2013-03-01 16:57 UTC (permalink / raw)
  To: linux-arm-kernel

This allows you to get the equivalent functionality of
i2c_add_numbered_adapter() with all data in the device tree and no
special case code in your driver.  This is a common device tree
technique.

For quick reference, the FDT syntax for using an alias to provide an
ID looks like:
  aliases {
    i2c0 = &i2c_0;
    i2c1 = &i2c_1;
  };

Signed-off-by: Doug Anderson <dianders@chromium.org>

---
Changes in v4:
- Rebased atop the removal of MAX_IDR_MASK.

Changes in v3:
- Addressed Wolfram's feedback; rebased atop idr-cleanup series.

Changes in v2: None

 drivers/i2c/i2c-core.c | 49 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 991d38d..66c5252 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -921,13 +921,38 @@ out_list:
 }
 
 /**
+ * __i2c_add_numbered_adapter - i2c_add_numbered_adapter where nr is never -1
+ * @adap: the adapter to register (with adap->nr initialized)
+ * Context: can sleep
+ *
+ * See i2c_add_numbered_adapter() for details.
+ */
+static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
+{
+	int	id;
+
+	/* Handled by wrappers */
+	if (WARN_ON(adap->nr == -1))
+		return -EINVAL;
+
+	mutex_lock(&core_lock);
+	id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
+		       GFP_KERNEL);
+	mutex_unlock(&core_lock);
+	if (id < 0)
+		return id == -ENOSPC ? -EBUSY : id;
+	return i2c_register_adapter(adap);
+}
+
+/**
  * i2c_add_adapter - declare i2c adapter, use dynamic bus number
  * @adapter: the adapter to add
  * Context: can sleep
  *
  * This routine is used to declare an I2C adapter when its bus number
- * doesn't matter.  Examples: for I2C adapters dynamically added by
- * USB links or PCI plugin cards.
+ * doesn't matter or when its bus number is specified by an dt alias.
+ * Examples of bases when the bus number doesn't matter: I2C adapters
+ * dynamically added by USB links or PCI plugin cards.
  *
  * When this returns zero, a new bus number was allocated and stored
  * in adap->nr, and the specified adapter became available for clients.
@@ -935,8 +960,17 @@ out_list:
  */
 int i2c_add_adapter(struct i2c_adapter *adapter)
 {
+	struct device *dev = &adapter->dev;
 	int id;
 
+	if (dev->of_node) {
+		id = of_alias_get_id(dev->of_node, "i2c");
+		if (id >= 0) {
+			adapter->nr = id;
+			return __i2c_add_numbered_adapter(adapter);
+		}
+	}
+
 	mutex_lock(&core_lock);
 	id = idr_alloc(&i2c_adapter_idr, adapter,
 		       __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
@@ -975,18 +1009,9 @@ EXPORT_SYMBOL(i2c_add_adapter);
  */
 int i2c_add_numbered_adapter(struct i2c_adapter *adap)
 {
-	int	id;
-
 	if (adap->nr == -1) /* -1 means dynamically assign bus id */
 		return i2c_add_adapter(adap);
-
-	mutex_lock(&core_lock);
-	id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
-		       GFP_KERNEL);
-	mutex_unlock(&core_lock);
-	if (id < 0)
-		return id == -ENOSPC ? -EBUSY : id;
-	return i2c_register_adapter(adap);
+	return __i2c_add_numbered_adapter(adap);
 }
 EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
 
-- 
1.8.1.3

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

* [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now
  2013-03-01 16:57 ` [PATCH v4 " Doug Anderson
  2013-03-01 16:57   ` [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
@ 2013-03-01 16:57   ` Doug Anderson
  2013-03-21 11:49     ` Wolfram Sang
  1 sibling, 1 reply; 11+ messages in thread
From: Doug Anderson @ 2013-03-01 16:57 UTC (permalink / raw)
  To: linux-arm-kernel

The commit: "i2c-core: dt: Pick i2c bus number from i2c alias if
present" adds support for automatically picking the bus number based
on the alias ID.  Remove the now unnecessary code from i2c-pxa that
did the same thing.

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
Changes in v4: None
Changes in v3: None
Changes in v2:
- No longer tweak pdev->id as per Sylwester Nawrocki.
- No longer add the dev ID to the adap.name.  Other drivers don't
  include the device ID here and it doesn't make sense with
  dynamically (or automatically) allocated IDs.
- Use dev_name(&dev->dev) to register for the IRQ; this matches what
  the i2c-s3c2410.c does and handles dynamically allocated IDs.
- This change was only compile-tested (corgi_defconfig), since I don't
  have access to a board that uses this driver.

 drivers/i2c/busses/i2c-pxa.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 1e88e8d..ea6d45d 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1053,16 +1053,13 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id =
 			of_match_device(i2c_pxa_dt_ids, &pdev->dev);
-	int ret;
 
 	if (!of_id)
 		return 1;
-	ret = of_alias_get_id(np, "i2c");
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
-		return ret;
-	}
-	pdev->id = ret;
+
+	/* For device tree we always use the dynamic or alias-assigned ID */
+	i2c->adap.nr = -1;
+
 	if (of_get_property(np, "mrvl,i2c-polling", NULL))
 		i2c->use_pio = 1;
 	if (of_get_property(np, "mrvl,i2c-fast-mode", NULL))
@@ -1100,6 +1097,9 @@ static int i2c_pxa_probe(struct platform_device *dev)
 		goto emalloc;
 	}
 
+	/* Default adapter num to device id; i2c_pxa_probe_dt can override. */
+	i2c->adap.nr = dev->id;
+
 	ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
 	if (ret > 0)
 		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
@@ -1124,9 +1124,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	spin_lock_init(&i2c->lock);
 	init_waitqueue_head(&i2c->wait);
 
-	i2c->adap.nr = dev->id;
-	snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
-		 i2c->adap.nr);
+	strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
 
 	i2c->clk = clk_get(&dev->dev, NULL);
 	if (IS_ERR(i2c->clk)) {
@@ -1169,7 +1167,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	} else {
 		i2c->adap.algo = &i2c_pxa_algorithm;
 		ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
-				  i2c->adap.name, i2c);
+				  dev_name(&dev->dev), i2c);
 		if (ret)
 			goto ereqirq;
 	}
-- 
1.8.1.3

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

* [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present
  2013-03-01 16:57   ` [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
@ 2013-03-01 19:22     ` Wolfram Sang
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2013-03-01 19:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 01, 2013 at 08:57:31AM -0800, Doug Anderson wrote:
> This allows you to get the equivalent functionality of
> i2c_add_numbered_adapter() with all data in the device tree and no
> special case code in your driver.  This is a common device tree
> technique.
> 
> For quick reference, the FDT syntax for using an alias to provide an
> ID looks like:
>   aliases {
>     i2c0 = &i2c_0;
>     i2c1 = &i2c_1;
>   };
> 
> Signed-off-by: Doug Anderson <dianders@chromium.org>

Thanks, applied. I'll try to get it into 3.9.

> +	/* Handled by wrappers */
> +	if (WARN_ON(adap->nr == -1))
> +		return -EINVAL;

I removed this check, though. We know our callers, all static.

Thanks,

   Wolfram

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

* [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now
  2013-03-01 16:57   ` [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
@ 2013-03-21 11:49     ` Wolfram Sang
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2013-03-21 11:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 01, 2013 at 08:57:32AM -0800, Doug Anderson wrote:
> The commit: "i2c-core: dt: Pick i2c bus number from i2c alias if
> present" adds support for automatically picking the bus number based
> on the alias ID.  Remove the now unnecessary code from i2c-pxa that
> did the same thing.
> 
> Signed-off-by: Doug Anderson <dianders@chromium.org>

Thanks, applied for-next.

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

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-12  0:48 [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
2013-02-12  0:48 ` [PATCH v3 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
2013-02-12  0:48 ` [PATCH v3 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
2013-02-27  1:01 ` [PATCH v3 0/2] Add automatic bus number support for i2c busses with device tree Doug Anderson
2013-02-28 23:25   ` Wolfram Sang
2013-03-01  0:55     ` Doug Anderson
2013-03-01 16:57 ` [PATCH v4 " Doug Anderson
2013-03-01 16:57   ` [PATCH v4 1/2] i2c-core: dt: Pick i2c bus number from i2c alias if present Doug Anderson
2013-03-01 19:22     ` Wolfram Sang
2013-03-01 16:57   ` [PATCH v4 2/2] i2c: pxa: Use i2c-core to get bus number now Doug Anderson
2013-03-21 11:49     ` Wolfram Sang

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git