Skip to contentSkip to conversation

mtd: physmap_of: add a hook for Gemini flash probing

PATCH New Linus Walleij 3 participants 3 messages Jan 28, 2017 – Feb 8, 2017 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 10/22 mtd: physmap_of: add a hook for Gemini flash probing

In order to support device tree probing of Gemini NOR flash chips, a certain register in the syscon needs to be poked to enable parallel flash mode.

Such things used to happen in "necessarily different" board file code, and this indeed was also done for the Gemini, so the MTD driver could treat it as any memory-mapped NOR flash, but this is not the way in the future: board files need to go, and hardware concerns distributed down to the applicable drivers.

This adds a hook in the same way that the Versatile did: if the Kconfig symbol is not selected the net total of supporting Gemini should be zero bytes of added code. To live up to this promise, also the return value error print from the Versatile extra probe call get to be removed in this patch, all printing need to happen in the add-ons.

Cc Janos Laube <[email protected]>
Cc Paulius Zaleckas <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Florian Fainelli <[email protected]>

---
ChangeLog v1->v2:
- Put a more elaborate description of the Kconfig option into the Kconfig item, take this opportunity to also modify the Versatile Kconfig entry which is equally terse.
- Modify the Makefile to build the Gemini and Versatile drivers based on their own config symbols and not based on an if on their symbol, should have been done like that from the start.
- Move a dev_info() to dev_dbg() in the driver.

MTD maintainers: please just apply this to the MTD tree when you are happy with it. It is functionally orthogonal to the rest of the series and is just in the series for context.

---
 drivers/mtd/maps/Kconfig             |  12 +++-
 drivers/mtd/maps/Makefile            |   5 +-
 drivers/mtd/maps/physmap_of.c        |   9 ++-
 drivers/mtd/maps/physmap_of_gemini.c | 120 +++++++++++++++++++++++++++++++++++
 drivers/mtd/maps/physmap_of_gemini.h |  16 +++++
 5 files changed, 155 insertions(+), 7 deletions(-)
 create mode 100644 drivers/mtd/maps/physmap_of_gemini.c
 create mode 100644 drivers/mtd/maps/physmap_of_gemini.h
drivers/mtd/maps/Kconfig +11 -1
index 5bcc896a48c3..542fdf8e81fa 100644
@@ -75,7 +75,7 @@ config MTD_PHYSMAP_OF
 	  taken from OF device tree.
 
 config MTD_PHYSMAP_OF_VERSATILE
-	bool "Support ARM Versatile physmap OF"
+	bool "ARM Versatile OF-based physical memory map handling"
 	depends on MTD_PHYSMAP_OF
 	depends on MFD_SYSCON
 	default y if (ARCH_INTEGRATOR || ARCH_VERSATILE || ARCH_REALVIEW)
@@ -84,6 +84,16 @@ config MTD_PHYSMAP_OF_VERSATILE
 	  platforms, basically to add a VPP (write protection) callback so
 	  the flash can be taken out of write protection.
 
+config MTD_PHYSMAP_OF_GEMINI
+	bool "Cortina Gemini OF-based physical memory map handling"
+	depends on MTD_PHYSMAP_OF
+	depends on MFD_SYSCON
+	default ARCH_GEMINI
+	help
+	  This provides some extra DT physmap parsing for the Gemini
+	  platforms, some detection and setting up parallel mode on the
+	  external interface.
+
 config MTD_PMC_MSP_EVM
 	tristate "CFI Flash device mapped on PMC-Sierra MSP"
 	depends on PMC_MSP && MTD_CFI
drivers/mtd/maps/Makefile +2 -3
index 644f7d36d35d..2fec1e0c2371 100644
@@ -18,9 +18,8 @@ obj-$(CONFIG_MTD_TSUNAMI)	+= tsunami_flash.o
 obj-$(CONFIG_MTD_PXA2XX)	+= pxa2xx-flash.o
 obj-$(CONFIG_MTD_PHYSMAP)	+= physmap.o
 obj-$(CONFIG_MTD_PHYSMAP_OF)	+= physmap_of.o
-ifdef CONFIG_MTD_PHYSMAP_OF_VERSATILE
-obj-$(CONFIG_MTD_PHYSMAP_OF)	+= physmap_of_versatile.o
-endif
+obj-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE)	+= physmap_of_versatile.o
+obj-$(CONFIG_MTD_PHYSMAP_OF_GEMINI)	+= physmap_of_gemini.o
 obj-$(CONFIG_MTD_PISMO)		+= pismo.o
 obj-$(CONFIG_MTD_PMC_MSP_EVM)   += pmcmsp-flash.o
 obj-$(CONFIG_MTD_PCMCIA)	+= pcmciamtd.o
drivers/mtd/maps/physmap_of.c +6 -3
index 3fad35942895..14e8909c9955 100644
@@ -24,6 +24,7 @@
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/slab.h>
+#include "physmap_of_gemini.h"
 #include "physmap_of_versatile.h"
 
 struct of_flash_list {
@@ -241,11 +242,13 @@ static int of_flash_probe(struct platform_device *dev)
 		info->list[i].map.size = res_size;
 		info->list[i].map.bankwidth = be32_to_cpup(width);
 		info->list[i].map.device_node = dp;
+
+		err = of_flash_probe_gemini(dev, dp, &info->list[i].map);
+		if (err)
+			return err;
 		err = of_flash_probe_versatile(dev, dp, &info->list[i].map);
-		if (err) {
-			dev_err(&dev->dev, "Can't probe Versatile VPP\n");
+		if (err)
 			return err;
-		}
 
 		err = -ENOMEM;
 		info->list[i].map.virt = ioremap(info->list[i].map.phys,
drivers/mtd/maps/physmap_of_gemini.c new file +120 -0

120 lines not on this page · raw message

drivers/mtd/maps/physmap_of_gemini.h new file +16 -0
new file mode 100644
index 000000000000..c675025288dd
@@ -0,0 +1,16 @@
+#include <linux/of.h>
+#include <linux/mtd/map.h>
+
+#ifdef CONFIG_MTD_PHYSMAP_OF_GEMINI
+int of_flash_probe_gemini(struct platform_device *pdev,
+			  struct device_node *np,
+			  struct map_info *map);
+#else
+static inline
+int of_flash_probe_gemini(struct platform_device *pdev,
+			  struct device_node *np,
+			  struct map_info *map)
+{
+	return 0;
+}
+#endif
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 10/22 mtd: physmap_of: add a hook for Gemini flash probing

Quoted 23 lines · Linus Walleij

In order to support device tree probing of Gemini NOR flash chips, a certain register in the syscon needs to be poked to enable parallel flash mode.

Such things used to happen in "necessarily different" board file code, and this indeed was also done for the Gemini, so the MTD driver could treat it as any memory-mapped NOR flash, but this is not the way in the future: board files need to go, and hardware concerns distributed down to the applicable drivers.

This adds a hook in the same way that the Versatile did: if the Kconfig symbol is not selected the net total of supporting Gemini should be zero bytes of added code. To live up to this promise, also the return value error print from the Versatile extra probe call get to be removed in this patch, all printing need to happen in the add-ons.

Cc Janos Laube <[email protected]>
Cc Paulius Zaleckas <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Florian Fainelli <[email protected]>
Quoted 5 lines

---
ChangeLog v1->v2:
- Put a more elaborate description of the Kconfig option into the Kconfig item, take this opportunity to also modify the Versatile Kconfig entry which is equally terse.

Thanks!

Quoted 4 lines

- Modify the Makefile to build the Gemini and Versatile drivers based on their own config symbols and not based on an if on their symbol, should have been done like that from the start.
- Move a dev_info() to dev_dbg() in the driver.

[...]

drivers/mtd/maps/physmap_of_gemini.c line 98

Quoted 4 lines
drivers/mtd/maps/physmap_of_gemini.c new file +4 -0
+	if (val & FLASH_WIDTH_16BIT) {
+		if (map->bankwidth != 2)
+			dev_warn(dev, "flash hardware say flash is 16 bit wide "
+				 "but DT says it is %d bits wide\n",

Nit, please do not break printed strings, it is not possible to 'git grep' for them if you do.

drivers/mtd/maps/physmap_of_gemini.c line 103

Quoted 5 lines
drivers/mtd/maps/physmap_of_gemini.c new file +5 -0
+				 map->bankwidth * 8);
+	} else {
+		if (map->bankwidth != 1)
+			dev_warn(dev, "flash hardware say flash is 8 bit wide "
+				 "but DT says it is %d bits wide\n",

DTTO

drivers/mtd/maps/physmap_of_gemini.c line 114

Quoted 11 lines
drivers/mtd/maps/physmap_of_gemini.c new file +11 -0
+				 map->bankwidth * 8);
+	}
+
+	/* Activate parallel (NOR flash) mode */
+	ret = regmap_update_bits(rmap, GLOBAL_MISC_CTRL,
+				 FLASH_PADS_MASK,
+				 SFLASH_PADS_DISABLE | NAND_PADS_DISABLE);
+	if (ret) {
+		dev_err(dev, "unable to set up physmap pads\n");
+		return -ENODEV;
+	}

[...]

Once you fix the nit above, add my:

Signature · 2 lines
Best regards,
Marek Vasut
Applied
#2 lore raw

PATCH v2 10/22 mtd: physmap_of: add a hook for Gemini flash probing

Quoted 47 lines · Marek Vasut
Quoted 23 lines · Linus Walleij

In order to support device tree probing of Gemini NOR flash chips, a certain register in the syscon needs to be poked to enable parallel flash mode.

Such things used to happen in "necessarily different" board file code, and this indeed was also done for the Gemini, so the MTD driver could treat it as any memory-mapped NOR flash, but this is not the way in the future: board files need to go, and hardware concerns distributed down to the applicable drivers.

This adds a hook in the same way that the Versatile did: if the Kconfig symbol is not selected the net total of supporting Gemini should be zero bytes of added code. To live up to this promise, also the return value error print from the Versatile extra probe call get to be removed in this patch, all printing need to happen in the add-ons.

Cc Janos Laube <[email protected]>
Cc Paulius Zaleckas <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Florian Fainelli <[email protected]>
Quoted 5 lines

---
ChangeLog v1->v2:
- Put a more elaborate description of the Kconfig option into the Kconfig item, take this opportunity to also modify the Versatile Kconfig entry which is equally terse.

Thanks!

Quoted 4 lines

- Modify the Makefile to build the Gemini and Versatile drivers based on their own config symbols and not based on an if on their symbol, should have been done like that from the start.
- Move a dev_info() to dev_dbg() in the driver.

[...]

drivers/mtd/maps/physmap_of_gemini.c line 98

Quoted 4 lines
drivers/mtd/maps/physmap_of_gemini.c new file +4 -0
+	if (val & FLASH_WIDTH_16BIT) {
+		if (map->bankwidth != 2)
+			dev_warn(dev, "flash hardware say flash is 16 bit wide "
+				 "but DT says it is %d bits wide\n",

Nit, please do not break printed strings, it is not possible to 'git grep' for them if you do.

Quoted 7 lines

drivers/mtd/maps/physmap_of_gemini.c line 103

Quoted 5 lines
drivers/mtd/maps/physmap_of_gemini.c new file +5 -0
+				 map->bankwidth * 8);
+	} else {
+		if (map->bankwidth != 1)
+			dev_warn(dev, "flash hardware say flash is 8 bit wide "
+				 "but DT says it is %d bits wide\n",

DTTO

I've fixed these up myself.

Quoted 14 lines
Quoted 11 lines
drivers/mtd/maps/physmap_of_gemini.c new file +11 -0
+				 map->bankwidth * 8);
+	}
+
+	/* Activate parallel (NOR flash) mode */
+	ret = regmap_update_bits(rmap, GLOBAL_MISC_CTRL,
+				 FLASH_PADS_MASK,
+				 SFLASH_PADS_DISABLE | NAND_PADS_DISABLE);
+	if (ret) {
+		dev_err(dev, "unable to set up physmap pads\n");
+		return -ENODEV;
+	}

[...]

Quoted 2 lines

Once you fix the nit above, add my:

smatch also noticed one new problem:

drivers/mtd/maps/physmap_of.c:248 of_flash_probe() warn: possible memory leak of 'mtd_list' [smatch]

This matches an existing leak seen in this function already, but my scripts look for new warnings. Would be nice to fix this sometime.

Applied to l2-mtd.git, with the above 2 fixed.

Brian