mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* match of_modaliases
@ 2014-02-07  8:33 Sascha Hauer
  2014-02-07  8:33 ` [PATCH 1/2] i2c/spi: " Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-02-07  8:33 UTC (permalink / raw)
  To: barebox

Right now barebox does not match the "vendor,device" compatible entries
in the devicetree. Implement this and also let the m25p80 driver match
to the different flash types, not only "m25p80".

Sascha

----------------------------------------------------------------
Sascha Hauer (2):
      i2c/spi: match of_modaliases
      mtd: m25p80: set driver id_table

 drivers/base/bus.c           | 37 +++++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c.c            |  2 +-
 drivers/mtd/devices/m25p80.c | 16 ++++++----------
 drivers/spi/spi.c            |  2 +-
 include/driver.h             |  3 ++-
 5 files changed, 47 insertions(+), 13 deletions(-)

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

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

* [PATCH 1/2] i2c/spi: match of_modaliases
  2014-02-07  8:33 match of_modaliases Sascha Hauer
@ 2014-02-07  8:33 ` Sascha Hauer
  2014-02-07  8:33 ` [PATCH 2/2] mtd: m25p80: set driver id_table Sascha Hauer
  2014-02-07 11:52 ` match of_modaliases Lucas Stach
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-02-07  8:33 UTC (permalink / raw)
  To: barebox

i2c/spi devices in the devicetree often come with a "vendor,device"
comaptible string. These do not match in barebox, so add a
device_match_of_modalias function which does exactly that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/bus.c | 37 +++++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c.c  |  2 +-
 drivers/spi/spi.c  |  2 +-
 include/driver.h   |  3 ++-
 4 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b383d09..c41e0b0 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -71,3 +71,40 @@ int device_match(struct device_d *dev, struct driver_d *drv)
 
 	return -1;
 }
+
+int device_match_of_modalias(struct device_d *dev, struct driver_d *drv)
+{
+	struct platform_device_id *id = drv->id_table;
+	const char *of_modalias = NULL, *p;
+	int cplen;
+	const char *compat;
+
+	if (!device_match(dev, drv))
+		return 0;
+
+	if (!id || !IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
+		return -1;
+
+	compat = of_get_property(dev->device_node, "compatible", &cplen);
+	if (!compat)
+		return -1;
+
+	p = strchr(compat, ',');
+	of_modalias = p ? p + 1 : compat;
+
+	while (id->name) {
+		if (!strcmp(id->name, dev->name)) {
+			dev->id_entry = id;
+			return 0;
+		}
+
+		if (of_modalias && !strcmp(id->name, of_modalias)) {
+			dev->id_entry = id;
+			return 0;
+		}
+
+		id++;
+	}
+
+	return -1;
+}
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 3b9f601..d774105 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -467,7 +467,7 @@ static void i2c_remove(struct device_d *dev)
 
 struct bus_type i2c_bus = {
 	.name = "i2c",
-	.match = device_match,
+	.match = device_match_of_modalias,
 	.probe = i2c_probe,
 	.remove = i2c_remove,
 };
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ad65884..8bddd98 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -316,7 +316,7 @@ static void spi_remove(struct device_d *dev)
 
 struct bus_type spi_bus = {
 	.name = "spi",
-	.match = device_match,
+	.match = device_match_of_modalias,
 	.probe = spi_probe,
 	.remove = spi_remove,
 };
diff --git a/include/driver.h b/include/driver.h
index bbe789b..cbb0401 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -496,5 +496,6 @@ int devfs_del_partition(const char *name);
 
 int dev_get_drvdata(struct device_d *dev, unsigned long *data);
 
-#endif /* DRIVER_H */
+int device_match_of_modalias(struct device_d *dev, struct driver_d *drv);
 
+#endif /* DRIVER_H */
-- 
1.8.5.3


_______________________________________________
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/2] mtd: m25p80: set driver id_table
  2014-02-07  8:33 match of_modaliases Sascha Hauer
  2014-02-07  8:33 ` [PATCH 1/2] i2c/spi: " Sascha Hauer
@ 2014-02-07  8:33 ` Sascha Hauer
  2014-02-07 11:52 ` match of_modaliases Lucas Stach
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-02-07  8:33 UTC (permalink / raw)
  To: barebox

This sets the id_table in the driver correctly so that the driver
can match to the various types of flashes, not only "m25p80".

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/devices/m25p80.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 9594011..c36d240 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -73,11 +73,6 @@
 
 #define SPI_NAME_SIZE   32
 
-struct spi_device_id {
-	char name[SPI_NAME_SIZE];
-	unsigned long driver_data;
-};
-
 struct m25p {
 	struct spi_device	*spi;
 	struct mtd_info		mtd;
@@ -618,7 +613,7 @@ struct flash_info {
  * more flash chips.  This current list focusses on newer chips, which
  * have been converging on command sets which including JEDEC ID.
  */
-static const struct spi_device_id m25p_ids[] = {
+static const struct platform_device_id m25p_ids[] = {
 	/* Atmel -- some are (confusingly) marketed as "DataFlash" */
 	{ "at25fs010",  INFO(0x1f6601, 0, 32 * 1024,   4, SECT_4K) },
 	{ "at25fs040",  INFO(0x1f6604, 0, 64 * 1024,   8, SECT_4K) },
@@ -755,7 +750,7 @@ static const struct spi_device_id m25p_ids[] = {
 	{ },
 };
 
-static const struct spi_device_id *jedec_probe(struct spi_device *spi)
+static const struct platform_device_id *jedec_probe(struct spi_device *spi)
 {
 	int			tmp;
 	u8			code = OPCODE_RDID;
@@ -803,7 +798,7 @@ static const struct spi_device_id *jedec_probe(struct spi_device *spi)
 static int m25p_probe(struct device_d *dev)
 {
 	struct spi_device *spi = (struct spi_device *)dev->type_data;
-	const struct spi_device_id	*id = NULL;
+	const struct platform_device_id	*id = NULL;
 	struct flash_platform_data	*data;
 	struct m25p			*flash;
 	struct flash_info		*info = NULL;
@@ -819,7 +814,7 @@ static int m25p_probe(struct device_d *dev)
 	 */
 	data = dev->platform_data;
 	if (data && data->type) {
-		const struct spi_device_id *plat_id;
+		const struct platform_device_id *plat_id;
 
 		for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) {
 			plat_id = &m25p_ids[i];
@@ -840,7 +835,7 @@ static int m25p_probe(struct device_d *dev)
 	}
 
 	if (do_jdec_probe) {
-		const struct spi_device_id *jid;
+		const struct platform_device_id *jid;
 
 		jid = jedec_probe(spi);
 		if (IS_ERR(jid)) {
@@ -969,6 +964,7 @@ static struct driver_d m25p80_driver = {
 	.name	= "m25p80",
 	.probe	= m25p_probe,
 	.of_compatible = DRV_OF_COMPAT(m25p80_dt_ids),
+	.id_table = (struct platform_device_id *)m25p_ids,
 };
 device_spi_driver(m25p80_driver);
 
-- 
1.8.5.3


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

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

* Re: match of_modaliases
  2014-02-07  8:33 match of_modaliases Sascha Hauer
  2014-02-07  8:33 ` [PATCH 1/2] i2c/spi: " Sascha Hauer
  2014-02-07  8:33 ` [PATCH 2/2] mtd: m25p80: set driver id_table Sascha Hauer
@ 2014-02-07 11:52 ` Lucas Stach
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2014-02-07 11:52 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Am Freitag, den 07.02.2014, 09:33 +0100 schrieb Sascha Hauer:
> Right now barebox does not match the "vendor,device" compatible entries
> in the devicetree. Implement this and also let the m25p80 driver match
> to the different flash types, not only "m25p80".
> 
This needs the attached minor tweak in the m25p80 driver to actually
work for the non-jedec compatible devices.

Otherwise
Tested-by: Lucas Stach <l.stach@pengutronix.de>

This removes the need for "spi: m25p80: detect non-jedec chips by using
DT compatible"

--------------------------------->8---------------------------------
From 53121d1eae60dbef3515f36c15a415cf736480d7 Mon Sep 17 00:00:00 2001
From: Lucas Stach <l.stach@pengutronix.de>
Date: Fri, 7 Feb 2014 12:45:21 +0100
Subject: [PATCH] spi: m25p80: make DT probing work

Just use the previously matched id_entry.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/mtd/devices/m25p80.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index e6d8c05e904b..3efdd359a824 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -825,6 +825,7 @@ static int m25p_probe(struct device_d *dev)
 	unsigned			i;
 	unsigned			do_jdec_probe = 1;
 	char				*flashname = NULL;
+	const char			*typename = NULL;
 	int				device_id;
 
 	/* Platform data helps sort out which chip type we have, as
@@ -833,12 +834,17 @@ static int m25p_probe(struct device_d *dev)
 	 * newer chips, even if we don't recognize the particular chip.
 	 */
 	data = dev->platform_data;
-	if (data && data->type) {
+	if (data && data->type)
+		typename = data->type;
+	else if (dev->id_entry)
+		typename = dev->id_entry->name;
+
+	if (typename) {
 		const struct platform_device_id *plat_id;
 
 		for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) {
 			plat_id = &m25p_ids[i];
-			if (strcmp(data->type, plat_id->name))
+			if (strcmp(typename, plat_id->name))
 				continue;
 			break;
 		}
@@ -851,7 +857,7 @@ static int m25p_probe(struct device_d *dev)
 			if (!info->jedec_id)
 				do_jdec_probe = 0;
 		} else
-			dev_warn(&spi->dev, "unrecognized id %s\n", data->type);
+			dev_warn(&spi->dev, "unrecognized id %s\n", typename);
 	}
 
 	if (do_jdec_probe) {
-- 
1.8.5.3

-- 
Pengutronix e.K.                           | Lucas Stach                 |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-5076 |
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:[~2014-02-07 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-07  8:33 match of_modaliases Sascha Hauer
2014-02-07  8:33 ` [PATCH 1/2] i2c/spi: " Sascha Hauer
2014-02-07  8:33 ` [PATCH 2/2] mtd: m25p80: set driver id_table Sascha Hauer
2014-02-07 11:52 ` match of_modaliases Lucas Stach

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