devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Cousson, Benoit" <b-cousson@ti.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: "Hilman, Kevin" <khilman@ti.com>, Paul Walmsley <paul@pwsan.com>,
	"G, Manjunath Kondaiah" <manjugk@ti.com>,
	"devicetree-discuss@lists.ozlabs.org"
	<devicetree-discuss@lists.ozlabs.org>,
	"Nayak, Rajendra" <rnayak@ti.com>,
	linux-omap <linux-omap@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Shouldn't DT preserve pdev name and id to allow platform_match to work?
Date: Wed, 3 Aug 2011 17:04:01 +0200	[thread overview]
Message-ID: <4E396361.3060307@ti.com> (raw)

Hi Grant,

Going further with the usage of OF_DEV_AUXDATA_ID, I realized that this is is not doing what I was expecting. My expectation might be silly, but in order to make platform_match to work without DT matching mechanism, you need to have the driver name in the pdev->name field:

	/* fall-back to driver name match */
	return (strcmp(pdev->name, drv->name) == 0);

Except that the of_device_add function is doing that:
	pdev->name = dev_name(&ofdev->dev);
	pdev->id = -1;

Thus overwriting the original pdev->name with the dev_name / bus_id in DT case.

Whereas the regular naming convention with pdev is to have dev_name = <name>.<id>".

Because of that, we cannot match the proper driver name with this entry: 

  OF_DEV_AUXDATA_ID("ti,omap-i2c", 0x48000100, "omap-i2c.1", 1, &i2c_pdata)

pdev->id will be properly overwritten after device creation, but not the pdev->name.
pdev->name will be "omap-i2c.1" instead of "omap-i2c".

By changing a little bit the format like that (removing the id from bus_id that is BTW redundant in that case):

  OF_DEV_AUXDATA_ID("ti,omap-i2c", 0x48000100, "omap-i2c", 1, &i2c_pdata)

We will be able to maintain the original driver name inside pdev->name and thus match correctly during probe with the legacy method.

Since DT is building a real platform_device, it seems to be reasonable to maintain the legacy name.

Moreover that will allow a basic driver to still probe correctly its devices.

Please find after a quick and dirty proof of concept.

Does that make sense to you?

Regards,
Benoit 


---
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 62b4b32..04727e4 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -51,11 +51,6 @@ int of_device_add(struct platform_device *ofdev)
 {
 	BUG_ON(ofdev->dev.of_node == NULL);
 
-	/* name and id have to be set so that the platform bus doesn't get
-	 * confused on matching */
-	ofdev->name = dev_name(&ofdev->dev);
-	ofdev->id = -1;
-
 	/* device_add will assume that this device is on the same node as
 	 * the parent. If there is no parent defined, set the node
 	 * explicitly */
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ebbbf42..f7b6ec1 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -130,13 +130,14 @@ void of_device_make_bus_id(struct device *dev)
  */
 struct platform_device *of_device_alloc(struct device_node *np,
 				  const char *bus_id,
-				  struct device *parent)
+				  struct device *parent,
+				  int id)
 {
 	struct platform_device *dev;
 	int rc, i, num_reg = 0, num_irq;
 	struct resource *res, temp_res;
 
-	dev = platform_device_alloc("", -1);
+	dev = platform_device_alloc(bus_id ? bus_id : "", id);
 	if (!dev)
 		return NULL;
 
@@ -169,7 +170,10 @@ struct platform_device *of_device_alloc(struct device_node *np,
 	dev->dev.parent = parent;
 
 	if (bus_id)
-		dev_set_name(&dev->dev, "%s", bus_id);
+		if (id == -1)
+			dev_set_name(&dev->dev, "%s", bus_id);
+		else
+			dev_set_name(&dev->dev, "%s.%d", bus_id, id);
 	else
 		of_device_make_bus_id(&dev->dev);
 
@@ -191,14 +195,15 @@ struct platform_device *of_platform_device_create_pdata(
 					struct device_node *np,
 					const char *bus_id,
 					void *platform_data,
-					struct device *parent)
+					struct device *parent,
+					int id)
 {
 	struct platform_device *dev;
 
 	if (!of_device_is_available(np))
 		return NULL;
 
-	dev = of_device_alloc(np, bus_id, parent);
+	dev = of_device_alloc(np, bus_id, parent, id);
 	if (!dev)
 		return NULL;
 
@@ -235,7 +240,7 @@ struct platform_device *of_platform_device_create(struct device_node *np,
 					    const char *bus_id,
 					    struct device *parent)
 {
-	return of_platform_device_create_pdata(np, bus_id, NULL, parent);
+	return of_platform_device_create_pdata(np, bus_id, NULL, parent, -1);
 }
 EXPORT_SYMBOL(of_platform_device_create);
 
@@ -595,11 +600,7 @@ static int of_platform_bus_create(struct device_node *bus,
 		return 0;
 	}
 
-	dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent);
-
-	/* override the id if auxdata gives an id */
-	if (id != -1)
-		dev->id = id;
+	dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent, id);
 
 	if (!dev || !of_match_node(matches, bus))
 		return 0;
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 252246c..9d3cbbe 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -84,7 +84,7 @@ extern const struct of_device_id of_default_bus_match_table[];
 /* Platform drivers register/unregister */
 extern struct platform_device *of_device_alloc(struct device_node *np,
 					 const char *bus_id,
-					 struct device *parent);
+					 struct device *parent, int id);
 extern struct platform_device *of_find_device_by_node(struct device_node *np);
 
 #if !defined(CONFIG_SPARC) /* SPARC has its own device registration method */

             reply	other threads:[~2011-08-03 15:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 15:04 Cousson, Benoit [this message]
2011-08-03 16:17 ` Shouldn't DT preserve pdev name and id to allow platform_match to work? G, Manjunath Kondaiah
     [not found]   ` <CAC63_iRa1qc7pO9Eub1A+cC+R=tSkwzigVPDHqcbvOngACYWqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-03 16:27     ` Cousson, Benoit
2011-08-03 16:43 ` Grant Likely
2011-08-05 10:02   ` Barry Song
2011-08-05 12:31     ` Cousson, Benoit
     [not found]       ` <4E3BE294.2020404-l0cyMroinI0@public.gmane.org>
2011-08-07  4:13         ` Grant Likely
2011-08-05 12:19   ` Cousson, Benoit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E396361.3060307@ti.com \
    --to=b-cousson@ti.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=khilman@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=manjugk@ti.com \
    --cc=paul@pwsan.com \
    --cc=rnayak@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).