mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 5/5] driver: Add platform_device_id mechanism
Date: Tue, 11 Sep 2012 15:31:53 +0200	[thread overview]
Message-ID: <1347370313-15184-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1347370313-15184-1-git-send-email-s.hauer@pengutronix.de>

It is common for drivers to handle multiple similar devices. On
Linux the driver can distinguish between the devices using the
platform_device_id mechanism. Introduce the same for barebox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/platform.c |   17 ++++++++++++++++-
 include/driver.h        |    9 +++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index e0dd9ea..82d2521 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -24,7 +24,22 @@
 
 static int platform_match(struct device_d *dev, struct driver_d *drv)
 {
-	return strcmp(dev->name, drv->name) ? -1 : 0;
+	if (!strcmp(dev->name, drv->name))
+		return 0;
+
+	if (drv->id_table) {
+		struct platform_device_id *id = drv->id_table;
+
+		while (id->name) {
+			if (!strcmp(id->name, dev->name)) {
+				dev->id_entry = id;
+				return 0;
+			}
+			id++;
+		}
+	}
+
+	return -1;
 }
 
 static int platform_probe(struct device_d *dev)
diff --git a/include/driver.h b/include/driver.h
index c74f245..40b76c1 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -60,6 +60,11 @@
 struct filep;
 struct bus_type;
 
+struct platform_device_id {
+	const char *name;
+	unsigned long driver_data;
+};
+
 /** @brief Describes a particular device present in the system */
 struct device_d {
 	/*! This member (and 'type' described below) is used to match with a
@@ -99,6 +104,8 @@ struct device_d {
 	struct list_head parameters;
 
 	struct list_head cdevs;
+
+	struct platform_device_id *id_entry;
 };
 
 /** @brief Describes a driver present in the system */
@@ -119,6 +126,8 @@ struct driver_d {
 	void    (*shortinfo) (struct device_d *);
 
 	struct bus_type *bus;
+
+	struct platform_device_id *id_table;
 };
 
 /*@}*/	/* do not delete, doxygen relevant */
-- 
1.7.10.4


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

      parent reply	other threads:[~2012-09-11 13:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11 13:31 [PATCH] device/driver work Sascha Hauer
2012-09-11 13:31 ` [PATCH 1/5] mfd mc13xxx: Separate I2C and SPI probe Sascha Hauer
2012-09-11 13:31 ` [PATCH 2/5] SPI: Put SPI devices on their own bus bus Sascha Hauer
2012-09-11 14:03   ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 14:26     ` Sascha Hauer
2012-09-11 13:31 ` [PATCH 3/5] I2C: Put I2C devices on their own bus Sascha Hauer
2012-09-11 14:04   ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 14:27     ` Sascha Hauer
2012-09-11 15:56       ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-11 16:10         ` Sascha Hauer
2012-09-11 17:24           ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-12  6:47             ` Sascha Hauer
2012-09-11 13:31 ` [PATCH 4/5] driver: rewrite dev_printf as a function Sascha Hauer
2012-09-11 13:31 ` Sascha Hauer [this message]

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=1347370313-15184-6-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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