[U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
This patch adds a driver for the diskonchip G4 nand flash device. It is based on the driver from the linux kernel. This also includes a separate SPL driver. A separate SPL driver is used because the device operates in a different mode (reliable mode) when loading a boot image, and also because the storage format of the boot image is different from normal data (pages are stored redundantly). The SPL driver basically mimics how a typical IPL reads data from the device. The special operating mode and storage format are used to compensate for the fact that the IPL does not contain the BCH ecc decoding algorithm (due to size constraints). Although the u-boot SPL *could* use ecc, it operates like an IPL for the sake of simplicity and uniformity, since the IPL and SPL share the task of loading the u-boot image. As a side benefit, the SPL driver is very small. [port from linux kernel 3.4 commit 570469f3bde7f71cc1ece07a18d54a05b6a8775d] Signed-off-by: Mike Dunn --- drivers/mtd/nand/Makefile|2 + drivers/mtd/nand/docg4.c | 1035 ++ drivers/mtd/nand/docg4_spl.c | 222 + include/linux/mtd/docg4.h| 134 ++ 4 files changed, 1393 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/docg4.c create mode 100644 drivers/mtd/nand/docg4_spl.c create mode 100644 include/linux/mtd/docg4.h diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index c77c0c4..1bcf43c 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -34,6 +34,7 @@ NORMAL_DRIVERS=y endif COBJS-$(CONFIG_SPL_NAND_AM33XX_BCH) += am335x_spl_bch.o +COBJS-$(CONFIG_SPL_NAND_DOCG4) += docg4_spl.o COBJS-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o COBJS-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o COBJS-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o @@ -78,6 +79,7 @@ COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o COBJS-$(CONFIG_TEGRA_NAND) += tegra_nand.o COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o +COBJS-$(CONFIG_NAND_DOCG4) += docg4.o else # minimal SPL drivers diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c new file mode 100644 index 000..c5c4ee0 --- /dev/null +++ b/drivers/mtd/nand/docg4.c @@ -0,0 +1,1035 @@ +/* + * drivers/mtd/nand/docg4.c + * + * Copyright (C) 2013 Mike Dunn + * + * This file is released under the terms of GPL v2 and any later version. + * See the file COPYING in the root directory of the source tree for details. + * + * mtd nand driver for M-Systems DiskOnChip G4 + * + * Tested on the Palm Treo 680. The G4 is also present on Toshiba Portege, Asus + * P526, some HTC smartphones (Wizard, Prophet, ...), O2 XDA Zinc, maybe others. + * Should work on these as well. Let me know! + * + * TODO: + * + * Mechanism for management of password-protected areas + * + * Hamming ecc when reading oob only + * + * According to the M-Sys documentation, this device is also available in a + * "dual-die" configuration having a 256MB capacity, but no mechanism for + * detecting this variant is documented. Currently this driver assumes 128MB + * capacity. + * + * Support for multiple cascaded devices ("floors"). Not sure which gadgets + * contain multiple G4s in a cascaded configuration, if any. + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The device has a nop register which M-Sys claims is for the purpose of + * inserting precise delays. But beware; at least some operations fail if the + * nop writes are replaced with a generic delay! + */ +static inline void write_nop(void __iomem *docptr) +{ + writew(0, docptr + DOC_NOP); +} + + +static int poll_status(void __iomem *docptr) +{ + /* +* Busy-wait for the FLASHREADY bit to be set in the FLASHCONTROL +* register. Operations known to take a long time (e.g., block erase) +* should sleep for a while before calling this. +*/ + + uint8_t flash_status; + + /* hardware quirk requires reading twice initially */ + flash_status = readb(docptr + DOC_FLASHCONTROL); + + do { + flash_status = readb(docptr + DOC_FLASHCONTROL); + } while (!(flash_status & DOC_CTRL_FLASHREADY)); + + return 0; +} + +static void write_addr(void __iomem *docptr, uint32_t docg4_addr) +{ + /* write the four address bytes packed in docg4_addr to the device */ + + writeb(docg4_addr & 0xff, docptr + DOC_FLASHADDRESS); + docg4_addr >>= 8; + writeb(docg4_addr & 0xff, docptr + DOC_FLASHADDRESS); + docg4_addr >>= 8; + writeb(docg4_addr & 0xff, docptr + DOC_FLASHADDRESS); + docg4_addr >>= 8; + writeb(docg4_addr & 0xff, docptr + DOC_FLASHADDRESS); +} + + +#ifdef DEBUG_DOCG4 +#define dbg(format, arg...) printf("DEBUG: " format, ##arg) +#else +#define dbg(format, arg...) do {} while (0) +#endif + +/* + * This is a module parameter in the l
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
On 04/10/2013 07:45:27 PM, Mike Dunn wrote: This patch adds a driver for the diskonchip G4 nand flash device. It is based on the driver from the linux kernel. This also includes a separate SPL driver. A separate SPL driver is used because the device operates in a different mode (reliable mode) when loading a boot image, and also because the storage format of the boot image is different from normal data (pages are stored redundantly). The SPL driver basically mimics how a typical IPL reads data from the device. The special operating mode and storage format are used to compensate for the fact that the IPL does not contain the BCH ecc decoding algorithm (due to size constraints). Although the u-boot SPL *could* use ecc, it operates like an IPL for the sake of simplicity and uniformity, since the IPL and SPL share the task of loading the u-boot image. As a side benefit, the SPL driver is very small. [port from linux kernel 3.4 commit 570469f3bde7f71cc1ece07a18d54a05b6a8775d] Signed-off-by: Mike Dunn --- drivers/mtd/nand/Makefile|2 + drivers/mtd/nand/docg4.c | 1035 ++ drivers/mtd/nand/docg4_spl.c | 222 + include/linux/mtd/docg4.h| 134 ++ 4 files changed, 1393 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/docg4.c create mode 100644 drivers/mtd/nand/docg4_spl.c create mode 100644 include/linux/mtd/docg4.h [snip] +#ifdef DEBUG_DOCG4 +#define dbg(format, arg...) printf("DEBUG: " format, ##arg) +#else +#define dbg(format, arg...) do {} while (0) +#endif Maybe use MTDDEBUG? Otherwise: Acked-by: Scott Wood -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
Dear Mike Dunn, > This patch adds a driver for the diskonchip G4 nand flash device. It is > based on the driver from the linux kernel. > > This also includes a separate SPL driver. A separate SPL driver is used > because the device operates in a different mode (reliable mode) when > loading a boot image, and also because the storage format of the boot > image is different from normal data (pages are stored redundantly). The > SPL driver basically mimics how a typical IPL reads data from the device. > The special operating mode and storage format are used to compensate for > the fact that the IPL does not contain the BCH ecc decoding algorithm (due > to size constraints). Although the u-boot SPL *could* use ecc, it > operates like an IPL for the sake of simplicity and uniformity, since the > IPL and SPL share the task of loading the u-boot image. As a side benefit, > the SPL driver is very small. > > [port from linux kernel 3.4 commit > 570469f3bde7f71cc1ece07a18d54a05b6a8775d] Scott, this really is your turf. Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
On 04/11/2013 02:00 PM, Scott Wood wrote: > On 04/10/2013 07:45:27 PM, Mike Dunn wrote: >> This patch adds a driver for the diskonchip G4 nand flash device. It is >> based >> on the driver from the linux kernel. >> >> This also includes a separate SPL driver. A separate SPL driver is used >> because >> the device operates in a different mode (reliable mode) when loading a boot >> image, and also because the storage format of the boot image is different >> from >> normal data (pages are stored redundantly). The SPL driver basically mimics >> how >> a typical IPL reads data from the device. The special operating mode and >> storage format are used to compensate for the fact that the IPL does not >> contain >> the BCH ecc decoding algorithm (due to size constraints). Although the >> u-boot >> SPL *could* use ecc, it operates like an IPL for the sake of simplicity and >> uniformity, since the IPL and SPL share the task of loading the u-boot image. >> As a side benefit, the SPL driver is very small. >> >> [port from linux kernel 3.4 commit 570469f3bde7f71cc1ece07a18d54a05b6a8775d] >> >> Signed-off-by: Mike Dunn >> --- >> drivers/mtd/nand/Makefile|2 + >> drivers/mtd/nand/docg4.c | 1035 >> ++ >> drivers/mtd/nand/docg4_spl.c | 222 + >> include/linux/mtd/docg4.h| 134 ++ >> 4 files changed, 1393 insertions(+), 0 deletions(-) >> create mode 100644 drivers/mtd/nand/docg4.c >> create mode 100644 drivers/mtd/nand/docg4_spl.c >> create mode 100644 include/linux/mtd/docg4.h > [snip] >> +#ifdef DEBUG_DOCG4 >> +#define dbg(format, arg...) printf("DEBUG: " format, ##arg) >> +#else >> +#define dbg(format, arg...) do {} while (0) >> +#endif > > Maybe use MTDDEBUG? Ok. Alternatively, I wouldn't mind pulling them out entirely. It's been behaving quite nicely, and amyway, in the past I used a JTAG emultor rather than the printfs. > > Otherwise: > Acked-by: Scott Wood Many thanks Scott, Mike ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
On 04/11/2013 02:19:37 PM, Marek Vasut wrote: Dear Mike Dunn, > This patch adds a driver for the diskonchip G4 nand flash device. It is > based on the driver from the linux kernel. > > This also includes a separate SPL driver. A separate SPL driver is used > because the device operates in a different mode (reliable mode) when > loading a boot image, and also because the storage format of the boot > image is different from normal data (pages are stored redundantly). The > SPL driver basically mimics how a typical IPL reads data from the device. > The special operating mode and storage format are used to compensate for > the fact that the IPL does not contain the BCH ecc decoding algorithm (due > to size constraints). Although the u-boot SPL *could* use ecc, it > operates like an IPL for the sake of simplicity and uniformity, since the > IPL and SPL share the task of loading the u-boot image. As a side benefit, > the SPL driver is very small. > > [port from linux kernel 3.4 commit > 570469f3bde7f71cc1ece07a18d54a05b6a8775d] Scott, this really is your turf. I already acked it (it's up to Mike what he wants to do with dbg). Feel free to pick it up as part of the larger patchset -- it's a dependency for patch 7/7 that adds the board support. -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
Dear Scott Wood, [...] > > [snip] > > > +#ifdef DEBUG_DOCG4 > > +#define dbg(format, arg...) printf("DEBUG: " format, ##arg) > > +#else > > +#define dbg(format, arg...) do {} while (0) > > +#endif There already is a debugging facility in include/common.h too. And it does the same thing too. MTDDEBUG might work as well. Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 6/7] mtd: nand: add driver for diskonchip g4 nand flash
On 04/12/2013 12:27:09 PM, Marek Vasut wrote: Dear Scott Wood, [...] > > [snip] > > > +#ifdef DEBUG_DOCG4 > > +#define dbg(format, arg...) printf("DEBUG: " format, ##arg) > > +#else > > +#define dbg(format, arg...) do {} while (0) > > +#endif There already is a debugging facility in include/common.h too. And it does the same thing too. MTDDEBUG might work as well. I already pointed out MTDDEBUG, though debug() may be a better fit as it doesn't require adding debug levels, and since this driver's usage doesn't correspond to CONFIG_MTD_DEBUG in Linux (which appears to have been removed from Linux -- removal from U-Boot should likely follow). Mike said he may just remove the debug messages entirely (maybe also from the Linux driver?), making it moot. -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot