Monahan/PXA3xx: integrate Linux NAND controller driver
Subsystems (2)
cover Monahan/PXA3xx: integrate Linux NAND controller driver
From: Marcel Ziswiler <[email protected]>
This patch-set integrates the PXA3xx Linux NAND controller driver and adapts the two Monahan/PXA3xx boards delta and zylonite accordingly.
Marcel Ziswiler (3):
Monahan/PXA3xx: integrate Linux NAND controller driver
delta: use new generic NAND controller driver
zylonite: use new generic NAND controller driver
board/delta/Makefile | 2 +- board/delta/delta.c | 50 +++++ board/delta/nand.c | 554 -------------------------------- board/zylonite/Makefile | 2 +- board/zylonite/nand.c | 558 -------------------------------- board/zylonite/zylonite.c | 50 ++++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/pxa3xx_nand.c | 1860 ++++++++++++++++++++++++++++++++ include/asm-arm/arch-pxa/pxa-regs.h | 95 +-- include/asm-arm/arch-pxa/pxa3xx_nand.h | 67 ++ include/configs/delta.h | 32 +-- include/configs/zylonite.h | 34 +-- 12 files changed, 2049 insertions(+), 1256 deletions(-) create mode 100644 drivers/mtd/nand/pxa3xx_nand.c create mode 100644 include/asm-arm/arch-pxa/pxa3xx_nand.h delete mode 100644 board/delta/nand.c delete mode 100644 board/zylonite/nand.c
PATCH 1/3 Monahan/PXA3xx: integrate Linux NAND controller driver
This patch integrates the PXA3xx Linux NAND controller driver.
--- drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/pxa3xx_nand.c | 1860 ++++++++++++++++++++++++++++++++ include/asm-arm/arch-pxa/pxa-regs.h | 95 +-- include/asm-arm/arch-pxa/pxa3xx_nand.h | 67 ++ 4 files changed, 1931 insertions(+), 92 deletions(-) create mode 100644 drivers/mtd/nand/pxa3xx_nand.c create mode 100644 include/asm-arm/arch-pxa/pxa3xx_nand.h
drivers/mtd/nand/Makefile +1 -0
@@ -49,6 +49,7 @@ COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o COBJS-$(CONFIG_NAND_S3C64XX) += s3c64xx.o COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o +COBJS-$(CONFIG_NAND_PXA3xx) += pxa3xx_nand.o endif COBJS := $(COBJS-y)
drivers/mtd/nand/pxa3xx_nand.c new file +1860 -0
1,860 lines not on this page · raw message
include/asm-arm/arch-pxa/pxa-regs.h +3 -92
111 lines not on this page · raw message
include/asm-arm/arch-pxa/pxa3xx_nand.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 1/3 Monahan/PXA3xx: integrate Linux NAND controller driver
drivers/mtd/nand/pxa3xx_nand.c line 15
Quoted 4 lines · Marcel Ziswiler
drivers/mtd/nand/pxa3xx_nand.c new file +4
-0+/* XXX U-BOOT XXX */ +#define __U_BOOT__ + +#ifndef __U_BOOT__
I don't think we need this.
In fact, it could make it harder to spot conflicts when merging new versions of the file from linux, since patch could find the context it's looking for in the middle of an #ifndef __U_BOOT__ section when the change really needs to be applied to the other side of the #else.
Plus, it makes it harder to read the code. Let's share what we reasonably can, and get rid of the rest.
Quoted 1 line
+#undef DEBUG
Don't undef it, just don't define it. Maybe someone wants to turn debugging on system-wide.
drivers/mtd/nand/pxa3xx_nand.c line 51
Quoted 5 lines
drivers/mtd/nand/pxa3xx_nand.c new file +5
-0+#ifdef DEBUG +#define DEBUGF(fmt, args...) printf(fmt, ##args) +#else /* DEBUG */ +#define DEBUGF(x...) +#endif /* DEBUG */
We've already got MTDDEBUG.
Quoted 1 line
+#define
CONFIG_MTD_NAND_PXA3xx_BUILTIN
This is marked deprecated in Linux; perhaps we should take the preferred approach of platform-specified data here as well?
Quoted 1 line
+#define
CONFIG_MTD_NAND_PXA3xx_POLLING
I don't see this upstream.
Quoted 36 lines
drivers/mtd/nand/pxa3xx_nand.c new file +36
-0+#ifdef CONFIG_NAND_SPL +/** +* memset - Fill a region of memory with the given value +* @s: Pointer to the start of the area. +* @c: The byte to fill the area with +* @count: The size of the area. +* +* Do not use memset() to access IO space, use memset_io() instead. +*/ +void *memset (void *s,int c,size_t count) +{ +char *xs = (char *) s; + +while (count--) + *xs++ = c; + +return s; +} + +/** +* memcpy - Copy one area of memory to another +* @dest: Where to copy to +* @src: Where to copy from +* @count: The size of the area. +* +* You should not use this function to access IO space, use memcpy_toio() +* or memcpy_fromio() instead. +*/ +void *memcpy (void *dest,const void *src,size_t count) +{ +char *tmp = (char *) dest, *s = (char *) src; + +while (count--) + *tmp++ = *s++; + +return dest;
drivers/mtd/nand/pxa3xx_nand.c line 104
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c new file +10
-0+} +#endif /* CONFIG_NAND_SPL */ + +void msleep (int count) +{ +int i; + +for (i =0 ; i < count; i++) +udelay (1000 ); +}
Can we arrange to pull in the relevant functions from the rest of u-boot rather than duplicate them?
Or try to avoid the need in the NAND loader -- for example, msleep is only used in handling NAND_CMD_RESET, which you shouldn't need.
In fact, I'm not sure how this driver can be used at all with NAND_SPL. The normal nand_spl/nand_boot.c uses cmd_ctrl. More complicated controllers that can't use cmd_ctrl generally need their own nand_spl driver (such as nand_spl/nand_boot_fsl_elbc.c). If you have a particularly large NAND boot region, you might be able to create a nand_spl driver that uses this driver, but typically space is too tight.
Quoted 22 lines
drivers/mtd/nand/pxa3xx_nand.c new file +22
-0+/* macros for registers read/write */ +#ifdef __U_BOOT__ +#define nand_writel (info, off, val) \ + ((*(volatile u32 *) ((info)->mmio_base + (off))) = (val)) + +static void nand_writesl (volatile u32 *dest,u8 *src,int size) +{ +int i; +u32 *source = (u32 *)src; + +for (i =0 ; i < size; i++) + *dest = *(source++); +} + +#define nand_readl (info, off) \ + (*(volatile u32 *)((info)->mmio_base + (off))) + +static void nand_readsl (volatile u32 *source,u8 *dst,int size) +{ +u32 *dest = (u32 *)dst; +int i; +
drivers/mtd/nand/pxa3xx_nand.c line 200
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c new file +10
-0+for (i =0 ; i < size; i++) + *(dest++) = *source; +} +#else /* __U_BOOT__ */ +#define nand_writel (info, off, val) \ + __raw_writel((val), (info)->mmio_base + (off)) + +#define nand_readl (info, off) \ + __raw_readl((info)->mmio_base + (off)) +#endif /* __U_BOOT__ */
You can (and should) use __raw_writel/__raw_readl in U-Boot as well.
There is also a prototype for__raw_writesl/__raw_readsl, but the implementation seems to be missing -- perhaps you could add it generically, rather than just in one driver.
-Scott
PATCH 1/3 Monahan/PXA3xx: integrate Linux NAND controller driver
Quoted 9 lines · Scott Wood
I don't think we need this.
In fact, it could make it harder to spot conflicts when merging new versions of the file from linux, since patch could find the context it's looking for in the middle of an #ifndef
__U_BOOT__section when the change really needs to be applied to the other side of the #else.Plus, it makes it harder to read the code. Let's share what we reasonably can, and get rid of the rest.
OK, but it es exactly how it is done with the rest of the linux MTD stuff pulled into U-Boot. I don't quite see any other practical way of achieving such shared code where we have rather diverse requirements otherwise.
Quoted 10 lines
Don't undef it, just don't define it. Maybe someone wants to turn debugging on system-wide.
drivers/mtd/nand/pxa3xx_nand.c line 51
Quoted 5 lines
drivers/mtd/nand/pxa3xx_nand.c new file +5
-0+#ifdef DEBUG +#define DEBUGF(fmt, args...) printf(fmt, ##args) +#else /* DEBUG */ +#define DEBUGF(x...) +#endif /* DEBUG */ We've already got MTDDEBUG.
OK, agreed.
Quoted 2 lines
This is marked deprecated in Linux; perhaps we should take the preferred approach of platform-specified data here as well?
Hm, I thought platform data would be an over kill for U-Boot especially if it comes down to the NAND SPL case. Will look into how I could integrate that.
Quoted 1 line
I don't see this upstream.
That's because linux generally uses interrupts, but I wanted pure polling for U-Boot.
I actually thought about first getting some of my customization upstream but the last time I submitted a mere 2 line bug fix to this driver it got completely ignored. Don't quite know how to get any MTD stuff mainline in a timely manner!
Quoted 2 lines
Can we arrange to pull in the relevant functions from the rest of u-boot rather than duplicate them?
Generally yes, but that would completely bloat the NAND SPL case. OK as later targets do no more have a 4K limit but rather 16K it might actually work out. I am just fearing further dependencies.
Quoted 9 lines
Or try to avoid the need in the NAND loader -- for example, msleep is only used in handling
NAND_CMD_RESET, which you shouldn't need.In fact, I'm not sure how this driver can be used at all with
NAND_SPL. The normalnand_spl/nand_boot.cusescmd_ctrl. More complicated controllers that can't usecmd_ctrlgenerally need their ownnand_spldriver (such asnand_spl/nand_boot_fsl_elbc.c). If you have a particularly large NAND boot region, you might be able to create anand_spldriver that uses this driver, but typically space is too tight.
It actually works just fine and boots various PXA3xx targets with my slightly modified nand_spl/nand_boot.c which I plan to submit as soon as we agree on this driver.
Quoted 5 lines
You can (and should) use __raw_writel/__raw_readl in U-Boot as well.
There is also a prototype for__raw_writesl/__raw_readsl, but the implementation seems to be missing -- perhaps you could add it generically, rather than just in one driver.
I actually had a version doing it that way but it had some nasty further dependencies so I finally decided against doing it that way. Will look into it again.
Thanks Scott!
-Marcel
PATCH 1/3 Monahan/PXA3xx: integrate Linux NAND controller driver
Quoted 8 lines · Marcel Ziswiler
Quoted 7 lines · Scott Wood
I don't think we need this.
In fact, it could make it harder to spot conflicts when merging new versions of the file from linux, since patch could find the context it's looking for in the middle of an #ifndef
__U_BOOT__section when the change really needs to be applied to the other side of the #else.
Quoted 5 lines
Quoted 2 lines
Plus, it makes it harder to read the code. Let's share what we reasonably can, and get rid of the rest.
OK, but it es exactly how it is done with the rest of the linux MTD stuff pulled into U-Boot.
There is some of this in the common NAND code, which was there when I took over the subsystem. I'd rather move in the direction of having less of it than more.
I haven't seen much of this in the drivers.
Quoted 3 lines
I don't quite see any other practical way of
achieving such shared code where we have rather diverse requirements otherwise.
But you're not actually sharing the code. You're reusing parts of it with lots of changes (which I'm guessing aren't going to make it back into Linux) and dead code.
I don't see how keeping the dead bits around helps keep things in sync.
It's usually easy enough to look at conflicts and figure out whether a
change needs to be brought over, and how. The information about what is different can be obtained at any point using diff. One thing that would help is to keep track in the comments of which Linux version/SHA1 it corresponds to.
Note that stuff like mtd/compat.h is different, in that it's allowing some very commonly used Linux facilities to be used by the shared code as-is without needing any ifdefs in the main code.
Quoted 6 lines
Quoted 2 lines
This is marked deprecated in Linux; perhaps we should take the preferred approach of platform-specified data here as well?
Hm, I thought platform data would be an over kill for U-Boot especially if it comes down to the NAND SPL case. Will look into how I could integrate that.
I suppose it depends what it ends up looking like -- but simply having platform code provide a struct with some timings and such seems pretty reasonable. The method of getting that data to the driver would likely be different than in Linux.
Quoted 4 lines
Quoted 1 line
I don't see this upstream.
That's because linux generally uses interrupts, but I wanted pure polling for U-Boot.
Right, the implication was that unless there's a plan to support polling in Linux, this amounts to another #ifdef __U_BOOT__.
Quoted 4 lines
I actually thought about first getting some of my customization upstream but the last time I submitted a mere 2 line bug fix to this driver it got completely ignored. Don't quite know how to get any MTD stuff mainline in a timely manner!
It might have just been overlooked -- try pinging the maintainer and the MTD list.
Quoted 4 lines
Quoted 2 lines
Can we arrange to pull in the relevant functions from the rest of u-boot rather than duplicate them?
Generally yes, but that would completely bloat the NAND SPL case.
I was thinking we could identify a subset that NAND SPL and similar things are generally going to need, and #ifndef the rest (similar to CONFIG_NS16550_MIN_FUNCTIONS).
Or, at least have a NAND SPL mini-library so that there's only one duplication instead of one per board/driver/etc. At least memcpy can replace some open-coding done in existing NAND SPL code.
Quoted 3 lines
It actually works just fine and boots various PXA3xx targets with my slightly modified
nand_spl/nand_boot.cwhich I plan to submit as soon as we agree on this driver.
OK, that modified nand_boot.c is what I was wondering about (other than the size).
-Scott
PATCH 2/3 delta: use new generic NAND controller driver
In reply to Marcel ZiswilerThis patch adapts the Monahan/PXA3xx board delta to use the new generic NAND controller driver.
--- board/delta/Makefile | 2 +- board/delta/delta.c | 50 +++++ board/delta/nand.c | 554 ----------------------------------------------- include/configs/delta.h | 32 +-- 4 files changed, 59 insertions(+), 579 deletions(-) delete mode 100644 board/delta/nand.c
board/delta/Makefile +1 -1
@@ -26,7 +26,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(BOARD).a -COBJS := delta.o nand.o +COBJS := delta.o SOBJS := lowlevel_init.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
board/delta/delta.c +50 -0
65 lines not on this page · raw message
board/delta/nand.c deleted +0 -554
554 lines not on this page · raw message
include/configs/delta.h +8 -24
@@ -178,7 +178,6 @@#define CONFIG_SYS_MONAHANS_RUN_MODE_OSC_RATIO 16/* valid values: 8, 16, 24, 31 */ #define CONFIG_SYS_MONAHANS_TURBO_RUN_MODE_RATIO 1/* valid values: 1, 2 */ -/* valid baudrates */ #define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
@@ -220,10 +219,13 @@/* * NAND Flash */ -#define CONFIG_SYS_NAND0_BASE 0x0/* 0x43100040 */ /* 0x10000000 */ -#undef CONFIG_SYS_NAND1_BASE +#define CONFIG_NAND_PXA3xx +#define CONFIG_NAND_PXA3xx_CLK 104000000UL +#define CONFIG_NEW_NAND_CODE +#define CONFIG_SYS_NAND_HW_ECC + +#define CONFIG_SYS_NAND_BASE 0x0 -#define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND0_BASE }#define CONFIG_SYS_MAX_NAND_DEVICE 1/* Max number of NAND devices */ /* nand timeout values */
@@ -232,32 +234,14 @@#define CONFIG_SYS_NAND_SENDCMD_RETRY 3#undef NAND_ALLOW_ERASE_ALL/* Allow erasing bad blocks - don't use */ -/* NAND Timing Parameters (in ns) */ -#define NAND_TIMING_tCH 10 -#define NAND_TIMING_tCS 0 -#define NAND_TIMING_tWH 20 -#define NAND_TIMING_tWP 40 - -#define NAND_TIMING_tRH 20 -#define NAND_TIMING_tRP 40 - -#define NAND_TIMING_tR 11123 -#define NAND_TIMING_tWHR 100 -#define NAND_TIMING_tAR 10 - -/* NAND debugging */ -#define CONFIG_SYS_DFC_DEBUG1 /* usefull */ -#undef CONFIG_SYS_DFC_DEBUG2/* noisy */ -#undef CONFIG_SYS_DFC_DEBUG3/* extremly noisy */ -#define CONFIG_MTD_DEBUG #define CONFIG_MTD_DEBUG_VERBOSE 1#define CONFIG_SYS_NO_FLASH 1 -#define CONFIG_ENV_IS_IN_NAND 1 +#define CONFIG_ENV_IS_IN_NAND 1#define CONFIG_ENV_OFFSET 0x40000#define CONFIG_ENV_OFFSET_REDUND 0x44000 -#define CONFIG_ENV_SIZE 0x4000 +#define CONFIG_ENV_SIZE 0x4000#endif /* __CONFIG_H */
Signature · 1 line
1.6.0.4
PATCH 3/3 zylonite: use new generic NAND controller driver
In reply to Marcel ZiswilerThis patch adapts the Monahan/PXA3xx board zylonite to use the new generic NAND controller driver.
--- board/zylonite/Makefile | 2 +- board/zylonite/nand.c | 558 -------------------------------------------- board/zylonite/zylonite.c | 50 ++++ include/configs/zylonite.h | 34 +-- 4 files changed, 59 insertions(+), 585 deletions(-) delete mode 100644 board/zylonite/nand.c
board/zylonite/Makefile +1 -1
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(BOARD).a -COBJS := zylonite.o nand.o +COBJS := zylonite.o SOBJS := lowlevel_init.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
board/zylonite/nand.c deleted +0 -558
558 lines not on this page · raw message
board/zylonite/zylonite.c +50 -0
65 lines not on this page · raw message
include/configs/zylonite.h +8 -26
@@ -59,7 +59,6 @@/* * Hardware drivers */ -#undef TURN_ON_ETHERNET#ifdef TURN_ON_ETHERNET # define CONFIG_SMC91111 1
@@ -189,14 +188,16 @@#undef CONFIG_SYS_SKIP_DRAM_SCRUB -/* * NAND Flash */ -#define CONFIG_SYS_NAND0_BASE 0x0 -#undef CONFIG_SYS_NAND1_BASE +#define CONFIG_NAND_PXA3xx +#define CONFIG_NAND_PXA3xx_CLK 104000000UL +#define CONFIG_NEW_NAND_CODE +#define CONFIG_SYS_NAND_HW_ECC + +#define CONFIG_SYS_NAND_BASE 0x0 -#define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND0_BASE }#define CONFIG_SYS_MAX_NAND_DEVICE 1/* Max number of NAND devices */ /* nand timeout values */
@@ -205,33 +206,14 @@#define CONFIG_SYS_NAND_SENDCMD_RETRY 3#undef NAND_ALLOW_ERASE_ALL/* Allow erasing bad blocks - don't use */ -/* NAND Timing Parameters (in ns) */ -#define NAND_TIMING_tCH 10 -#define NAND_TIMING_tCS 0 -#define NAND_TIMING_tWH 20 -#define NAND_TIMING_tWP 40 - -#define NAND_TIMING_tRH 20 -#define NAND_TIMING_tRP 40 - -#define NAND_TIMING_tR 11123 -#define NAND_TIMING_tWHR 100 -#define NAND_TIMING_tAR 10 - -/* NAND debugging */ -#define CONFIG_SYS_DFC_DEBUG1 /* usefull */ -#undef CONFIG_SYS_DFC_DEBUG2/* noisy */ -#undef CONFIG_SYS_DFC_DEBUG3/* extremly noisy */ -#define CONFIG_MTD_DEBUG #define CONFIG_MTD_DEBUG_VERBOSE 1#define CONFIG_SYS_NO_FLASH 1 -#define CONFIG_ENV_IS_IN_NAND 1 +#define CONFIG_ENV_IS_IN_NAND 1#define CONFIG_ENV_OFFSET 0x40000#define CONFIG_ENV_OFFSET_REDUND 0x44000 -#define CONFIG_ENV_SIZE 0x4000 - +#define CONFIG_ENV_SIZE 0x4000#endif /* __CONFIG_H */
Signature · 1 line
1.6.0.4