Skip to contentSkip to conversation

mtd: dataflash: add device tree probe support

PATCH Superseded Shawn Guo 7 participants 19 messages Jul 10, 2011 – Jul 20, 2011

Subsystems (3)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 mtd: dataflash: add device tree probe support

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/devices/mtd_dataflash.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +11 -1
index 8f6b02c..64d7242 100644
@@ -24,6 +24,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
@@ -98,6 +100,11 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+
 /* ......................................................................... */
 
 /*
@@ -634,6 +641,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 {
 	struct dataflash		*priv;
 	struct mtd_info			*device;
+	struct mtd_part_parser_data	ppdata;
 	struct flash_platform_data	*pdata = spi->dev.platform_data;
 	char				*otp_tag = "";
 	int				err = 0;
@@ -675,7 +683,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 			pagesize, otp_tag);
 	dev_set_drvdata(&spi->dev, priv);
 
-	err = mtd_device_parse_register(device, NULL, 0,
+	ppdata.of_node = spi->dev.of_node;
+	err = mtd_device_parse_register(device, NULL, &ppdata,
 			pdata ? pdata->parts : NULL,
 			pdata ? pdata->nr_parts : 0);
 
@@ -926,6 +935,7 @@ static struct spi_driver dataflash_driver = {
 		.name		= "mtd_dataflash",
 		.bus		= &spi_bus_type,
 		.owner		= THIS_MODULE,
+		.of_match_table = dataflash_dt_ids,
 	},
 
 	.probe		= dataflash_probe,
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 24 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>
---
 drivers/mtd/devices/mtd_dataflash.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +2 -0
index 8f6b02c..64d7242 100644
@@ -24,6 +24,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 104

Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +2 -0
@@ -98,6 +100,11 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,dataflash", },

Please add also smth. like atmel,at45 to be more descriptive (probably single at45 entry will be sufficient).

Signature · 2 lines
With best wishes
Dmitry
author
#2 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

In reply to Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

 .../devicetree/bindings/mtd/atmel-dataflash.txt    |   14 ++++++++++++++
 drivers/mtd/devices/mtd_dataflash.c                |   13 ++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-dataflash.txt
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt new file +14 -0
new file mode 100644
index 0000000..3783962
@@ -0,0 +1,14 @@
+* Atmel Data Flash
+
+Required properties:
+- compatible : "atmel,<model>", "atmel,<series>", "atmel,dataflash".
+
+Example:
+
+flash at 1 {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "atmel,at45db321d", "atmel,at45xxx", "atmel,dataflash";
+	spi-max-frequency = <25000000>;
+	reg = <1>;
+};
drivers/mtd/devices/mtd_dataflash.c +12 -1
index 8f6b02c..8e091b0 100644
@@ -24,6 +24,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
@@ -98,6 +100,12 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+
 /* ......................................................................... */
 
 /*
@@ -634,6 +642,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 {
 	struct dataflash		*priv;
 	struct mtd_info			*device;
+	struct mtd_part_parser_data	ppdata;
 	struct flash_platform_data	*pdata = spi->dev.platform_data;
 	char				*otp_tag = "";
 	int				err = 0;
@@ -675,7 +684,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 			pagesize, otp_tag);
 	dev_set_drvdata(&spi->dev, priv);
 
-	err = mtd_device_parse_register(device, NULL, 0,
+	ppdata.of_node = spi->dev.of_node;
+	err = mtd_device_parse_register(device, NULL, &ppdata,
 			pdata ? pdata->parts : NULL,
 			pdata ? pdata->nr_parts : 0);
 
@@ -926,6 +936,7 @@ static struct spi_driver dataflash_driver = {
 		.name		= "mtd_dataflash",
 		.bus		= &spi_bus_type,
 		.owner		= THIS_MODULE,
+		.of_match_table = dataflash_dt_ids,
 	},
 
 	.probe		= dataflash_probe,
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

shouldnt there be #ifdef's around this ? not everyone supports devicetrees. -mike

#4 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

In reply to Shawn Guo
Quoted 10 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

I?m sorry for being unclean on this. Device family is just at45, so I?d suggest the following compatibility list:
"atmel,at45d789000", "atmel,at45"

You might want to add "atmel,dataflash" or "mtd,dataflash", but I see no point in that.

Signature · 2 lines
With best wishes
Dmitry
#5 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 12 lines · Dmitry Eremin-Solenikov
Quoted 10 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

Quoted 6 lines

I?m sorry for being unclean on this. Device family is just at45, so I?d suggest the following compatibility list:
"atmel,at45d789000", "atmel,at45"

You might want to add "atmel,dataflash" or "mtd,dataflash", but I see no point in that.

Dmitry is right. at45xxx is not a good compatible value.

Quoted 10 lines
Signature · 9 lines
-- 
With best wishes
Dmitry


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#6 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

In reply to Dmitry Eremin-Solenikov
Quoted 12 lines · Dmitry Eremin-Solenikov
Quoted 10 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

Quoted 4 lines

I?m sorry for being unclean on this. Device family is just at45, so I?d suggest the following compatibility list:
"atmel,at45d789000", "atmel,at45"

Ok.

Quoted 3 lines

You might want to add "atmel,dataflash" or "mtd,dataflash", but I see no point in that.

The binding I'm adding is for atmel dataflash (following the driver name). I want the binding to be scalable to cover possible new atmel dataflash family other than at45. We do not want to change binding every time one new family comes out, do we?

Signature · 2 lines
Regards,
Shawn
#7 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

In reply to Shawn Guo
Quoted 41 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

 .../devicetree/bindings/mtd/atmel-dataflash.txt    |   14 ++++++++++++++
 drivers/mtd/devices/mtd_dataflash.c                |   13 ++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-dataflash.txt
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt new file +14 -0
new file mode 100644
index 0000000..3783962
@@ -0,0 +1,14 @@
+* Atmel Data Flash
+
+Required properties:
+- compatible : "atmel,<model>", "atmel,<series>", "atmel,dataflash".
+
+Example:
+
+flash at 1 {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "atmel,at45db321d", "atmel,at45xxx", "atmel,dataflash";
+	spi-max-frequency = <25000000>;
+	reg = <1>;
+};
drivers/mtd/devices/mtd_dataflash.c +0 -0
index 8f6b02c..8e091b0 100644

drivers/mtd/devices/mtd_dataflash.c line 28

Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +2 -0
@@ -24,6 +24,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
+#include <linux/of.h>
+#include <linux/of_device.h>

This shouldn't be separate from the regular block of #include statements above it.

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 13 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
@@ -98,6 +100,12 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 32 lines
drivers/mtd/devices/mtd_dataflash.c +4 -1
 /* ......................................................................... */
 
 /*
@@ -634,6 +642,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 {
 	struct dataflash		*priv;
 	struct mtd_info			*device;
+	struct mtd_part_parser_data	ppdata;
 	struct flash_platform_data	*pdata = spi->dev.platform_data;
 	char				*otp_tag = "";
 	int				err = 0;
@@ -675,7 +684,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 			pagesize, otp_tag);
 	dev_set_drvdata(&spi->dev, priv);
 
-	err = mtd_device_parse_register(device, NULL, 0,
+	ppdata.of_node = spi->dev.of_node;
+	err = mtd_device_parse_register(device, NULL, &ppdata,
 			pdata ? pdata->parts : NULL,
 			pdata ? pdata->nr_parts : 0);
 
@@ -926,6 +936,7 @@ static struct spi_driver dataflash_driver = {
 		.name		= "mtd_dataflash",
 		.bus		= &spi_bus_type,
 		.owner		= THIS_MODULE,
+		.of_match_table = dataflash_dt_ids,
 	},
 
 	.probe		= dataflash_probe,
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 45 lines · Grant Likely
Quoted 44 lines · Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

 .../devicetree/bindings/mtd/atmel-dataflash.txt    |   14 ++++++++++++++
 drivers/mtd/devices/mtd_dataflash.c                |   13 ++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-dataflash.txt
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt new file +14 -0
new file mode 100644
index 0000000..3783962
@@ -0,0 +1,14 @@
+* Atmel Data Flash
+
+Required properties:
+- compatible : "atmel,<model>", "atmel,<series>", "atmel,dataflash".
+
+Example:
+
+flash at 1 {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "atmel,at45db321d", "atmel,at45xxx", "atmel,dataflash";
+	spi-max-frequency = <25000000>;
+	reg = <1>;
+};
drivers/mtd/devices/mtd_dataflash.c +0 -0
index 8f6b02c..8e091b0 100644
@@ -24,6 +24,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
Quoted 5 lines

drivers/mtd/devices/mtd_dataflash.c line 28

Quoted 2 lines
drivers/mtd/devices/mtd_dataflash.c +2 -0
+#include <linux/of.h>
+#include <linux/of_device.h>

This shouldn't be separate from the regular block of #include statements above it.

The patch does not show the context. Here is the existing code. I just followed the pattern.

#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/err.h>
#include <linux/math64.h>

#include <linux/spi/spi.h>
#include <linux/spi/flash.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>

But okay, I will add the OF headers right behind math64.h to not make it any worse.

Quoted 7 lines
Quoted 7 lines
drivers/mtd/devices/mtd_dataflash.c +0 -0
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
@@ -98,6 +100,12 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
Quoted 10 lines

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 6 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

Regards,
Shawn

Quoted 37 lines
Quoted 32 lines
drivers/mtd/devices/mtd_dataflash.c +4 -1
 /* ......................................................................... */
 
 /*
@@ -634,6 +642,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 {
 	struct dataflash		*priv;
 	struct mtd_info			*device;
+	struct mtd_part_parser_data	ppdata;
 	struct flash_platform_data	*pdata = spi->dev.platform_data;
 	char				*otp_tag = "";
 	int				err = 0;
@@ -675,7 +684,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 			pagesize, otp_tag);
 	dev_set_drvdata(&spi->dev, priv);
 
-	err = mtd_device_parse_register(device, NULL, 0,
+	ppdata.of_node = spi->dev.of_node;
+	err = mtd_device_parse_register(device, NULL, &ppdata,
 			pdata ? pdata->parts : NULL,
 			pdata ? pdata->nr_parts : 0);
 
@@ -926,6 +936,7 @@ static struct spi_driver dataflash_driver = {
 		.name		= "mtd_dataflash",
 		.bus		= &spi_bus_type,
 		.owner		= THIS_MODULE,
+		.of_match_table = dataflash_dt_ids,
 	},
 
 	.probe		= dataflash_probe,
Signature · 1 line
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

#9 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 10 lines · Shawn Guo
Quoted 10 lines

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 6 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 2 lines

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#10 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Shawn Guo
Quoted 10 lines

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 6 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 6 lines
Quoted 2 lines

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

Signature · 2 lines
Regards,
Shawn
#11 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 12 lines · Shawn Guo
Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Shawn Guo
Quoted 10 lines

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 6 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

And it will work correctly even though dataflash_dt_ids is not NULL, it will not confuse MTD layer?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#12 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 16 lines · Artem Bityutskiy
Quoted 15 lines · Shawn Guo
Quoted 14 lines · Artem Bityutskiy
Quoted 12 lines · Shawn Guo
Quoted 10 lines

drivers/mtd/devices/mtd_dataflash.c struct dataflash { · line 108

Quoted 6 lines
drivers/mtd/devices/mtd_dataflash.c +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

I guess the question is - will it compile and work if CONFIG_OF is unset?

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

And it will work correctly even though dataflash_dt_ids is not NULL, it will not confuse MTD layer?

I think for non-dt case, dataflash_dt_ids is not used anyway. So yes, it will not confuse MTD layer, at least from my testing.

Signature · 2 lines
Regards,
Shawn
#13 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 20 lines · Shawn Guo
Quoted 19 lines · Artem Bityutskiy
Quoted 18 lines · Shawn Guo
Quoted 17 lines · Artem Bityutskiy
Quoted 10 lines · Shawn Guo
Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 2 lines

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

And it will work correctly even though dataflash_dt_ids is not NULL, it will not confuse MTD layer?

I think for non-dt case, dataflash_dt_ids is not used anyway. So yes, it will not confuse MTD layer, at least from my testing.

And it is not error-prone? I mean, it is not very likely that someone changing MTD could make wrong assumptions and break dataflash driver? If so, then we probably do not need ifdefs indeed.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#14 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 27 lines · Artem Bityutskiy
Quoted 26 lines · Shawn Guo
Quoted 25 lines · Artem Bityutskiy
Quoted 12 lines · Shawn Guo
Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Shawn Guo
Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+ { .compatible = "atmel,at45xxx", },
+ { .compatible = "atmel,dataflash", },
+ { /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I personally hate #ifdef stuff. ?But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

And it will work correctly even though dataflash_dt_ids is not NULL, it will not confuse MTD layer?

Quoted 6 lines
Quoted 2 lines

I think for non-dt case, dataflash_dt_ids is not used anyway. ?So yes, it will not confuse MTD layer, at least from my testing.

And it is not error-prone? I mean, it is not very likely that someone changing MTD could make wrong assumptions and break dataflash driver? If so, then we probably do not need ifdefs indeed.

except for the part where device tree code shouldnt be wasting space on non-device tree systems
-mike

#15 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

In reply to Artem Bityutskiy
Quoted 27 lines · Artem Bityutskiy
Quoted 26 lines · Shawn Guo
Quoted 25 lines · Artem Bityutskiy
Quoted 12 lines · Shawn Guo
Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Shawn Guo
Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45xxx", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+

This should be protected with a #ifdef CONFIG_OF/#else/#endif, and there should be a MODULE_DEVICE_TABLE().

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I personally hate #ifdef stuff. But okay, I can do it since there are people being concerned by this little waste of space.

I guess the question is - will it compile and work if CONFIG_OF is unset?

Yes, it will compile, as 'struct of_device_id' is defined in include/linux/mod_devicetable.h unconditionally.

And it will work correctly even though dataflash_dt_ids is not NULL, it will not confuse MTD layer?

Quoted 7 lines
Quoted 2 lines

I think for non-dt case, dataflash_dt_ids is not used anyway. So yes, it will not confuse MTD layer, at least from my testing.

And it is not error-prone? I mean, it is not very likely that someone changing MTD could make wrong assumptions and break dataflash driver? If so, then we probably do not need ifdefs indeed.

No, it's not error-prone. The dataflash_dt_ids assigned to .of_match_table is used by OF device core to match driver and device. I do not think MTD change could impact this match.

The argument about this #ifdef thing was the driver could be used by some platforms that will never migrate to device tree. This table will be just a waste of bytes for those platforms, if we do not protect the table by '#ifdef CONFIG_OF'.

Signature · 2 lines
Regards,
Shawn
#16 lore raw

PATCH v2 1/1 mtd: dataflash: add device tree probe support

Quoted 4 lines · Shawn Guo

The argument about this #ifdef thing was the driver could be used by some platforms that will never migrate to device tree. This table will be just a waste of bytes for those platforms, if we do not protect the table by '#ifdef CONFIG_OF'.

OK, anyway, I picked your v2 already and less bytes wastage is a good enough argument.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
author
#17 lore raw

PATCH v3 1/1 mtd: dataflash: add device tree probe support

In reply to Shawn Guo

It adds device tree probe support for mtd_dataflash driver.

Cc Grant Likely <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Artem Bityutskiy <[email protected]>

---
Changes since v2:
* Change compatible string to "at45" from "at45xxx"
* Add "#ifdef CONFIG_OF" for dataflash_dt_ids

Changes since v1:
* Add "atmel,at45xxx" into the match table
* Add binding document

 .../devicetree/bindings/mtd/atmel-dataflash.txt    |   14 ++++++++++++++
 drivers/mtd/devices/mtd_dataflash.c                |   18 ++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-dataflash.txt
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt new file +14 -0
new file mode 100644
index 0000000..ef66ddd
@@ -0,0 +1,14 @@
+* Atmel Data Flash
+
+Required properties:
+- compatible : "atmel,<model>", "atmel,<series>", "atmel,dataflash".
+
+Example:
+
+flash at 1 {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "atmel,at45db321d", "atmel,at45", "atmel,dataflash";
+	spi-max-frequency = <25000000>;
+	reg = <1>;
+};
drivers/mtd/devices/mtd_dataflash.c +16 -2
index 8f6b02c..c86fa57 100644
@@ -17,6 +17,8 @@
 #include <linux/mutex.h>
 #include <linux/err.h>
 #include <linux/math64.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
@@ -24,7 +26,6 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
-
 /*
  * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
  * each chip, which may be used for double buffered I/O; but this driver
@@ -98,6 +99,16 @@ struct dataflash {
 	struct mtd_info		mtd;
 };
 
+#ifdef CONFIG_OF
+static const struct of_device_id dataflash_dt_ids[] = {
+	{ .compatible = "atmel,at45", },
+	{ .compatible = "atmel,dataflash", },
+	{ /* sentinel */ }
+};
+#else
+#define dataflash_dt_ids NULL
+#endif
+
 /* ......................................................................... */
 
 /*
@@ -634,6 +645,7 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 {
 	struct dataflash		*priv;
 	struct mtd_info			*device;
+	struct mtd_part_parser_data	ppdata;
 	struct flash_platform_data	*pdata = spi->dev.platform_data;
 	char				*otp_tag = "";
 	int				err = 0;
@@ -675,7 +687,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
 			pagesize, otp_tag);
 	dev_set_drvdata(&spi->dev, priv);
 
-	err = mtd_device_parse_register(device, NULL, 0,
+	ppdata.of_node = spi->dev.of_node;
+	err = mtd_device_parse_register(device, NULL, &ppdata,
 			pdata ? pdata->parts : NULL,
 			pdata ? pdata->nr_parts : 0);
 
@@ -926,6 +939,7 @@ static struct spi_driver dataflash_driver = {
 		.name		= "mtd_dataflash",
 		.bus		= &spi_bus_type,
 		.owner		= THIS_MODULE,
+		.of_match_table = dataflash_dt_ids,
 	},
 
 	.probe		= dataflash_probe,
Signature · 1 line
1.7.4.1