MIPS: lantiq: add NOR flash support
Subsystems (2)
PATCH v8 1/1 MIPS: lantiq: add NOR flash support
This patch adds the driver/map for NOR devices attached to the SoC via the External Bus Unit (EBU).
---
Changes in V2
* handle the endianess bug inside the map code and not in the generic cfi code
* remove the addr swizzle patch
Changes in V3
* whitespace
* change __iomem void to void __iomem
Changes in V4
* fixes a checkpatch.pl bug, the second is a false positive
* whitespace cleanups
* remove unused typecasts
* cleanup ltq_copy_from and ltq_copy_to
Changes in V6
* cleanup/add comments
* fix line breaks
* properly handle return code of add_mtd_partitions()
* use pr_err instead of printk
Changes in V7
* remove bogus KERN_INFO from pr_err() call
Changes in V8
* dynamically allocate the instance of map_info allowing the use of .addr_unlock1 for indication of the probing state, thus eliminating the need for a global variable
This patch should be merged via the MIPS tree
drivers/mtd/maps/Kconfig | 9 ++ drivers/mtd/maps/Makefile | 1 + drivers/mtd/maps/lantiq.c | 197 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/maps/lantiq.c
drivers/mtd/maps/Kconfig +9 -0
@@ -260,6 +260,15 @@ config MTD_BCM963XX Support for parsing CFE image tag and creating MTD partitions on Broadcom BCM63xx boards. +config MTD_LANTIQ + bool "Lantiq SoC NOR support" + depends on LANTIQ + select MTD_PARTITIONS + help + Lantiq SoCs have a EBU (External Bus Unit). This IP allows to attach + a number of different peripherals to the SoC. This driver adds + support for NOR chips to be added. + config MTD_DILNETPC tristate "CFI Flash device mapped on DIL/Net PC" depends on X86 && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
drivers/mtd/maps/Makefile +1 -0
@@ -60,3 +60,4 @@ obj-$(CONFIG_MTD_VMU) += vmu-flash.o obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o +obj-$(CONFIG_MTD_LANTIQ) += lantiq.o
drivers/mtd/maps/lantiq.c new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Quoted 4 lines · John Crispin
drivers/mtd/maps/lantiq.c new file +4
-0+/* +* The NOR flash is connected to the same external bus unit (EBU) as PCI. +* To make PCI work we need to enable the endianess swapping for the address +* written to the EBU. This endianess swapping works for PCI correctly but
drivers/mtd/maps/lantiq.c line 39
Quoted 10 lines
drivers/mtd/maps/lantiq.c new file +10
-0+* fails for attached NOR devices. To workaround this we need to use a complex +* map. The workaround involves swapping all addresses whilste probing the chip. +* Once probing is complete we stop swapping the addresses but swizzle the +* unlock addresses to ensure that access to the NOR device works correctly. +*/ + +enum ltq_nor_state { +LTQ_NOR_PROBING , +LTQ_NOR_NORMAL +};
You do not have to re-send because of this, just a note that in this case it makes more sense to use anonymous enum. Indeed, you do not need this 'ltq_nor_state' name at all, and C enums are not proper types anyway (no real type-checking), so it is just a tiny bit nicer to do:
enum {
LTQ_NOR_PROBING,
LTQ_NOR_NORMAL
};
But this is not important at all, just a side note :-)
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Hello.
Quoted 16 lines · John Crispin
This patch adds the driver/map for NOR devices attached to the SoC via the External Bus Unit (EBU).
Signed-off-by John Crispin <[email protected]>Signed-off-by Ralph Hempel <[email protected]>Cc David Woodhouse <[email protected]>Cc Daniel Schwierzeck <[email protected]>drivers/mtd/maps/lantiq.c new file +0
-0@@ -0,0 +1,197 @@
[...]
Quoted 3 lines
+/*
+ * The NOR flash is connected to the same external bus unit (EBU) as PCI.
+ * To make PCI work we need to enable the endianess swapping for the address
s/endianess/endianness/
Quoted 1 line
+ * written to the EBU. This endianess swapping works for PCI correctly but
Here too.
Quoted 2 lines
+ * fails for attached NOR devices. To workaround this we need to use a complex
+ * map. The workaround involves swapping all addresses whilste probing the chip.
s/whilste/whilst/
Quoted 11 lines
+ * Once probing is complete we stop swapping the addresses but swizzle the
+ * unlock addresses to ensure that access to the NOR device works correctly.
+ */drivers/mtd/maps/lantiq.c new file +8
-0+ +enum ltq_nor_state { +LTQ_NOR_PROBING , +LTQ_NOR_NORMAL +}; + +static char ltq_map_name[] ="ltq_nor" ; +
drivers/mtd/maps/lantiq.c line 52
Quoted 10 lines
drivers/mtd/maps/lantiq.c new file +10
-0+static map_word +ltq_read16 (struct map_info *map,unsigned long adr) +{ +unsigned long flags; +map_word temp; + +if (map->map_priv_1 ==LTQ_NOR_PROBING ) + adr ^=2 ; +spin_lock_irqsave (&ebu_lock, flags); + temp.x[0 ] = *((__u16 *)(map->virt + adr));
Too many parens; the most external ones are not necessary. And why not just 'u16'?
drivers/mtd/maps/lantiq.c line 65
Quoted 13 lines
drivers/mtd/maps/lantiq.c new file +13
-0+spin_unlock_irqrestore (&ebu_lock, flags); +return temp; +} + +static void +ltq_write16 (struct map_info *map,map_word d,unsigned long adr) +{ +unsigned long flags; + +if (map->map_priv_1 ==LTQ_NOR_PROBING ) + adr ^=2 ; +spin_lock_irqsave (&ebu_lock, flags); + *((__u16 *)(map->virt + adr)) = d.x[0 ];
Same here.
Quoted 6 lines
drivers/mtd/maps/lantiq.c new file +6
-0+spin_unlock_irqrestore (&ebu_lock, flags); +} + +/* +* The following 2 functions copy data between iomem and a cached memory +* section. As memcpy() makes use of pre-fetching we cannot use it here.
drivers/mtd/maps/lantiq.c line 81
Quoted 10 lines
drivers/mtd/maps/lantiq.c new file +10
-0+* The normal alternative of using memcpy_{to,from}io also makes use of +* memcpy() on MIPS so it is not applicable either. We are therefore stuck +* with having to use our own loop. +*/ +static void +ltq_copy_from (struct map_info *map,void *to, +unsigned long from,ssize_t len) +{ +unsigned char *f = (unsigned char *) (map->virt + from); +unsigned char *t = (unsigned char *) to;
I think you should either always put a space between the type and value
being cast or not -- you do both. :-)
drivers/mtd/maps/lantiq.c line 86
Quoted 5 lines
drivers/mtd/maps/lantiq.c new file +5
-0+unsigned long flags; + +spin_lock_irqsave (&ebu_lock, flags); +while (len--) + *t++ = *f++;
I'm still not sure: you've implemented only 16-bit single read/write, yet
you copy byte-by-byte? Does the byte access really work?
Quoted 3 lines
drivers/mtd/maps/lantiq.c new file +3
-0+spin_unlock_irqrestore (&ebu_lock, flags); +} +
[...]
Quoted 20 lines
drivers/mtd/maps/lantiq.c new file +20
-0+static int __init +ltq_mtd_probe (struct platform_device *pdev) +{ +struct physmap_flash_data *ltq_mtd_data =dev_get_platdata (&pdev->dev); +struct mtd_info *ltq_mtd =NULL ; +struct mtd_partition *parts =NULL ; +struct resource *res; +int nr_parts =0 ; +struct cfi_private *cfi; +struct map_info *ltq_map; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"failed to get memory resource" ); +return -ENOENT ; + } + res =devm_request_mem_region (&pdev->dev, res->start, +resource_size (res),dev_name (&pdev->dev)); +if (!res) { +dev_err (&pdev->dev,"failed to request mem resource" );
drivers/mtd/maps/lantiq.c line 135
Quoted 10 lines
drivers/mtd/maps/lantiq.c new file +10
-0+return -EBUSY ; + } + + ltq_map =kzalloc (sizeof (struct map_info ),GFP_KERNEL ); + ltq_map->phys = res->start; + ltq_map->size =resource_size (res); + ltq_map->virt =devm_ioremap_nocache (&pdev->dev, ltq_map->phys, + ltq_map->size); +if (!ltq_map->virt) { +kfree (ltq_map);
You should do error cleanup in one places, using *goto* to jump to that code,
to avoid duplicating the same code.
drivers/mtd/maps/lantiq.c line 137
Quoted 2 lines
drivers/mtd/maps/lantiq.c new file +2
-0+dev_err (&pdev->dev,"failed to ioremap!\n" ); +return -EIO ;
Rather -ENOMEM.
[...]
drivers/mtd/maps/lantiq.c line 189
Quoted 7 lines
drivers/mtd/maps/lantiq.c new file +7
-0+int __init +init_ltq_mtd (void ) +{ +int ret =platform_driver_probe (<q_mtd_driver, ltq_mtd_probe); + +if (ret) +pr_err ("ltq_nor: error registering platfom driver" );
s/platfom/platform/
drivers/mtd/maps/lantiq.c line 193
Quoted 4 lines
drivers/mtd/maps/lantiq.c new file +4
-0+return ret; +} + +module_init (init_ltq_mtd);
How about module_exit()?
WBR, Sergei
I've taken this patch to l2 tree, but I can change it with a new version easily.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Quoted 5 lines · Artem Bityutskiy
I've taken this patch to l2 tree, but I can change it with a new version easily.
let me fold the proposed changes into the patch, specially the typos :)
Quoted 9 lines · John Crispin
Quoted 5 lines · Artem Bityutskiy
I've taken this patch to l2 tree, but I can change it with a new version easily.
let me fold the proposed changes into the patch, specially the typos :)
Hi,
forgot to mention, this patch should go upstream via the MIPS tree
thanks, John
Quoted 7 lines · John Crispin
Quoted 6 lines · John Crispin
Quoted 5 lines · Artem Bityutskiy
I've taken this patch to l2 tree, but I can change it with a new version easily.
Quoted 7 lines
Quoted 3 lines
let me fold the proposed changes into the patch, specially the typos :)
Hi,
forgot to mention, this patch should go upstream via the MIPS tree
Oh, then I'm dropping it.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)