Skip to contentSkip to conversation

add the GPMI controller driver for IMX23/IMX28

PATCH Superseded Huang Shijie 8 participants 31 messages Mar 30, 2011 – Dec 6, 2011

Subsystems (6)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover add the GPMI controller driver for IMX23/IMX28

The general-purpose media interface(GPMI) controller is a flexible interface to up to several NAND flashs.

The Bose Ray-Choudhury Hocquenghem(BCH) module is a hardware ECC accelerator.

With the help of BCH, the GPMI controller can choose to do the hardware ECC or not.

This driver is based the Shawn Guo's DMA patches for IMX23/IMX28, please refer to :

	http://git.infradead.org/users/vkoul/slave-dma.git/commit/a580b8c5429a624d120cd603e1498bf676e2b4da

v2 --> v3:
[0] merge the imx23 and imx28 into one file(including the header file).
[1] remove the unuse registers in the headers.
[2] fix DMA bugs
[3] add bus width field to nand_attr{}
[4] others

v1 --> v2:
[0] merge the common files into the gpmi-nfc-main.c
[1] change the code to get the clock.
[2] remove the timing in the nand_device_info{}
[3] fix DMA errors
[4] add the nand_device_info.[ch] to generic code
[5] use the chip->onfi_version for the ONFI nand
[6] useless init
[7] others

Huang Shijie (6):
ARM: add GPMI support for imx23/imx28
dmaengine: change the flags of request_irq() MTD : add the database for the NANDs
MTD : add the common code for GPMI controller driver
MTD: add support for imx23 and imx28
MTD : add GPMI driver in the config and Makefile

 arch/arm/mach-mxs/Kconfig                       |    2 +
 arch/arm/mach-mxs/clock-mx23.c                  |    3 +
 arch/arm/mach-mxs/clock-mx28.c                  |    3 +
 arch/arm/mach-mxs/devices-mx23.h                |    3 +
 arch/arm/mach-mxs/devices-mx28.h                |    3 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-gpmi.c       |  140 ++
 arch/arm/mach-mxs/include/mach/devices-common.h |    4 +
 arch/arm/mach-mxs/include/mach/gpmi-nfc.h       |   62 +
 arch/arm/mach-mxs/mach-mx23evk.c                |   37 +
 arch/arm/mach-mxs/mach-mx28evk.c                |   37 +
 drivers/dma/mxs-dma.c                           |    2 +-
 drivers/mtd/nand/Kconfig                        |   10 +
 drivers/mtd/nand/Makefile                       |    1 +
 drivers/mtd/nand/gpmi-nfc/Makefile              |    6 +
 drivers/mtd/nand/gpmi-nfc/bch-mx23-mx28.h       |   88 +
 drivers/mtd/nand/gpmi-nfc/gpmi-mx23-mx28.h      |  163 ++
 drivers/mtd/nand/gpmi-nfc/gpmi-nfc-main.c       | 2451 +++++++++++++++++++++++
 drivers/mtd/nand/gpmi-nfc/gpmi-nfc.h            |  549 +++++
 drivers/mtd/nand/gpmi-nfc/hal-mx23-mx28.c       |  562 ++++++
 drivers/mtd/nand/gpmi-nfc/rom-mx23.c            |  300 +++
 drivers/mtd/nand/gpmi-nfc/rom-mx28.c            |   66 +
 drivers/mtd/nand/nand_device_info.c             |  157 ++
 drivers/mtd/nand/nand_device_info.h             |   88 +
 25 files changed, 4740 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-gpmi.c
 create mode 100644 arch/arm/mach-mxs/include/mach/gpmi-nfc.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/Makefile
 create mode 100644 drivers/mtd/nand/gpmi-nfc/bch-mx23-mx28.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-mx23-mx28.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-nfc-main.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-nfc.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/hal-mx23-mx28.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/rom-mx23.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/rom-mx28.c
 create mode 100644 drivers/mtd/nand/nand_device_info.c
 create mode 100644 drivers/mtd/nand/nand_device_info.h
#1 lore raw

PATCH v3 1/6 ARM: add GPMI support for imx23/imx28

add the clock and iomux initialization for GPMI in the imx23 and imx28.

---
 arch/arm/mach-mxs/Kconfig                       |    2 +
 arch/arm/mach-mxs/clock-mx23.c                  |    3 +
 arch/arm/mach-mxs/clock-mx28.c                  |    3 +
 arch/arm/mach-mxs/devices-mx23.h                |    3 +
 arch/arm/mach-mxs/devices-mx28.h                |    3 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-gpmi.c       |  140 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |    4 +
 arch/arm/mach-mxs/include/mach/gpmi-nfc.h       |   62 ++++++++++
 arch/arm/mach-mxs/mach-mx23evk.c                |   37 ++++++
 arch/arm/mach-mxs/mach-mx28evk.c                |   37 ++++++
 12 files changed, 298 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-gpmi.c
 create mode 100644 arch/arm/mach-mxs/include/mach/gpmi-nfc.h
arch/arm/mach-mxs/Kconfig +2 -0
index 4f6f174..e034666 100644
@@ -22,6 +22,7 @@ config MACH_MX23EVK
 	select SOC_IMX23
 	select MXS_HAVE_AMBA_DUART
 	select MXS_HAVE_PLATFORM_AUART
+	select MXS_HAVE_PLATFORM_GPMI
 	select MXS_HAVE_PLATFORM_MXSFB
 	default y
 	help
@@ -35,6 +36,7 @@ config MACH_MX28EVK
 	select MXS_HAVE_PLATFORM_AUART
 	select MXS_HAVE_PLATFORM_FEC
 	select MXS_HAVE_PLATFORM_FLEXCAN
+	select MXS_HAVE_PLATFORM_GPMI
 	select MXS_HAVE_PLATFORM_MXSFB
 	select MXS_OCOTP
 	default y
arch/arm/mach-mxs/clock-mx23.c +3 -0
index d133c7f..e99af2f 100644
@@ -29,6 +29,7 @@
 #include <mach/mx23.h>
 #include <mach/common.h>
 #include <mach/clock.h>
+#include <mach/gpmi-nfc.h>
 
 #include "regs-clkctrl-mx23.h"
 
@@ -442,6 +443,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("duart", "apb_pclk", xbus_clk)
 	/* for amba-pl011 driver */
 	_REGISTER_CLOCK("duart", NULL, uart_clk)
+	_REGISTER_CLOCK(GPMI_NFC_DRIVER_NAME, NULL, gpmi_clk)
 	_REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
 	_REGISTER_CLOCK("rtc", NULL, rtc_clk)
 	_REGISTER_CLOCK("mxs-dma-apbh", NULL, hbus_clk)
@@ -533,6 +535,7 @@ int __init mx23_clocks_init(void)
 	clk_enable(&xbus_clk);
 	clk_enable(&emi_clk);
 	clk_enable(&uart_clk);
+	clk_enable(&gpmi_clk);
 
 	clkdev_add_table(lookups, ARRAY_SIZE(lookups));
 
arch/arm/mach-mxs/clock-mx28.c +3 -0
index 5e489a2..3e8bba7 100644
@@ -29,6 +29,7 @@
 #include <mach/mx28.h>
 #include <mach/common.h>
 #include <mach/clock.h>
+#include <mach/gpmi-nfc.h>
 
 #include "regs-clkctrl-mx28.h"
 
@@ -607,6 +608,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("duart", "apb_pclk", xbus_clk)
 	/* for amba-pl011 driver */
 	_REGISTER_CLOCK("duart", NULL, uart_clk)
+	_REGISTER_CLOCK(GPMI_NFC_DRIVER_NAME, NULL, gpmi_clk)
 	_REGISTER_CLOCK("imx28-fec.0", NULL, fec_clk)
 	_REGISTER_CLOCK("imx28-fec.1", NULL, fec_clk)
 	_REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
@@ -749,6 +751,7 @@ int __init mx28_clocks_init(void)
 	clk_enable(&xbus_clk);
 	clk_enable(&emi_clk);
 	clk_enable(&uart_clk);
+	clk_enable(&gpmi_clk);
 
 	clk_set_parent(&lcdif_clk, &ref_pix_clk);
 
arch/arm/mach-mxs/devices-mx23.h +3 -0
index c7e14f4..349fb1d 100644
@@ -16,6 +16,9 @@ extern const struct amba_device mx23_duart_device __initconst;
 #define mx23_add_duart() \
 	mxs_add_duart(&mx23_duart_device)
 
+extern const struct gpmi_nfc_platform_data gpmi_platform_data_imx23 __initconst;
+#define mx23_add_gpmi() mxs_add_gpmi(&gpmi_platform_data_imx23)
+
 extern const struct mxs_auart_data mx23_auart_data[] __initconst;
 #define mx23_add_auart(id)	mxs_add_auart(&mx23_auart_data[id])
 #define mx23_add_auart0()		mx23_add_auart(0)
arch/arm/mach-mxs/devices-mx28.h +3 -0
index 9d08555..ed6427b 100644
@@ -16,6 +16,9 @@ extern const struct amba_device mx28_duart_device __initconst;
 #define mx28_add_duart() \
 	mxs_add_duart(&mx28_duart_device)
 
+extern const struct gpmi_nfc_platform_data gpmi_platform_data_imx28 __initconst;
+#define	mx28_add_gpmi()	mxs_add_gpmi(&gpmi_platform_data_imx28)
+
 extern const struct mxs_auart_data mx28_auart_data[] __initconst;
 #define mx28_add_auart(id)	mxs_add_auart(&mx28_auart_data[id])
 #define mx28_add_auart0()		mx28_add_auart(0)
arch/arm/mach-mxs/devices/Kconfig +3 -0
index 1451ad0..81e99ce 100644
@@ -5,6 +5,9 @@ config MXS_HAVE_AMBA_DUART
 config MXS_HAVE_PLATFORM_AUART
 	bool
 
+config MXS_HAVE_PLATFORM_GPMI
+	bool
+
 config MXS_HAVE_PLATFORM_FEC
 	bool
 
arch/arm/mach-mxs/devices/Makefile +1 -0
index 0d9bea3..8a7c2c8 100644
@@ -2,6 +2,7 @@ obj-$(CONFIG_MXS_HAVE_AMBA_DUART) += amba-duart.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_AUART) += platform-auart.o
 obj-y += platform-dma.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_FEC) += platform-fec.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_GPMI) += platform-gpmi.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_FLEXCAN) += platform-flexcan.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_I2C) += platform-mxs-i2c.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_PWM) += platform-mxs-pwm.o
arch/arm/mach-mxs/devices/platform-gpmi.c new file +140 -0

140 lines not on this page · raw message

arch/arm/mach-mxs/include/mach/devices-common.h +4 -0
index 71f2448..1f05503 100644
@@ -30,6 +30,10 @@ int __init mxs_add_amba_device(const struct amba_device *dev);
 /* duart */
 int __init mxs_add_duart(const struct amba_device *dev);
 
+/* GPMI */
+#include <mach/gpmi-nfc.h>
+struct platform_device *__init mxs_add_gpmi(
+				const struct gpmi_nfc_platform_data *data);
 /* auart */
 struct mxs_auart_data {
 	int id;
arch/arm/mach-mxs/include/mach/gpmi-nfc.h new file +62 -0

62 lines not on this page · raw message

arch/arm/mach-mxs/mach-mx23evk.c +37 -0
index a66994f..db715f9 100644
@@ -34,6 +34,42 @@ static const iomux_cfg_t mx23evk_pads[] __initconst = {
 	MX23_PAD_PWM0__DUART_RX | MXS_PAD_CTRL,
 	MX23_PAD_PWM1__DUART_TX | MXS_PAD_CTRL,
 
+	/* gpmi */
+	MX23_PAD_GPMI_D00__GPMI_D00 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D01__GPMI_D01 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D02__GPMI_D02 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D03__GPMI_D03 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D04__GPMI_D04 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D05__GPMI_D05 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D06__GPMI_D06 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_D07__GPMI_D07 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_CLE__GPMI_CLE |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_ALE__GPMI_ALE |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_WPN__GPMI_WPN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_WRN__GPMI_WRN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_RDN__GPMI_RDN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_RDY0__GPMI_RDY0 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_RDY1__GPMI_RDY1 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_CE0N__GPMI_CE0N |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX23_PAD_GPMI_CE1N__GPMI_CE1N |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+
 	/* auart */
 	MX23_PAD_AUART1_RX__AUART1_RX | MXS_PAD_CTRL,
 	MX23_PAD_AUART1_TX__AUART1_TX | MXS_PAD_CTRL,
@@ -108,6 +144,7 @@ static void __init mx23evk_init(void)
 	mxs_iomux_setup_multiple_pads(mx23evk_pads, ARRAY_SIZE(mx23evk_pads));
 
 	mx23_add_duart();
+	mx23_add_gpmi();
 	mx23_add_auart0();
 
 	ret = gpio_request_one(MX23EVK_LCD_ENABLE, GPIOF_DIR_OUT, "lcd-enable");
arch/arm/mach-mxs/mach-mx28evk.c +37 -0
index 08002d0..cf8ddcb 100644
@@ -39,6 +39,42 @@ static const iomux_cfg_t mx28evk_pads[] __initconst = {
 	MX28_PAD_PWM0__DUART_RX | MXS_PAD_CTRL,
 	MX28_PAD_PWM1__DUART_TX | MXS_PAD_CTRL,
 
+	/* gpmi */
+	MX28_PAD_GPMI_D00__GPMI_D0 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D01__GPMI_D1 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D02__GPMI_D2 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D03__GPMI_D3 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D04__GPMI_D4 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D05__GPMI_D5 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D06__GPMI_D6 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_D07__GPMI_D7 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_CE0N__GPMI_CE0N |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_CE1N__GPMI_CE1N |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_RDY0__GPMI_READY0 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_RDY1__GPMI_READY1 |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_RDN__GPMI_RDN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_WRN__GPMI_WRN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_ALE__GPMI_ALE |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_CLE__GPMI_CLE |
+		(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+	MX28_PAD_GPMI_RESETN__GPMI_RESETN |
+		(MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
+
 	/* auart0 */
 	MX28_PAD_AUART0_RX__AUART0_RX | MXS_PAD_CTRL,
 	MX28_PAD_AUART0_TX__AUART0_TX | MXS_PAD_CTRL,
@@ -265,6 +301,7 @@ static void __init mx28evk_init(void)
 	mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
 
 	mx28_add_duart();
+	mx28_add_gpmi();
 	mx28_add_auart0();
 	mx28_add_auart3();
 
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v3 2/6 dmaengine: change the flags of request_irq()

In reply to Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. So change the flags from '0' to IRQF_SHARED, else there will be an EBUSY error returns.

---
 drivers/dma/mxs-dma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mxs-dma.c +1 -1
index 88aad4f..0ee5b52 100644
@@ -328,7 +328,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
 	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
+				IRQF_SHARED, "mxs-dma", mxs_dma);
 	if (ret)
 		goto err_irq;
 
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH v3 2/6 dmaengine: change the flags of request_irq()

Hi,

Quoted 15 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. So change the flags from '0' to IRQF_SHARED, else there will be an EBUSY error returns.

---
 drivers/dma/mxs-dma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mxs-dma.c +0 -0
index 88aad4f..0ee5b52 100644

drivers/dma/mxs-dma.c static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) · line 334

Quoted 8 lines
drivers/dma/mxs-dma.c +1 -1
@@ -328,7 +328,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
 	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
+				IRQF_SHARED, "mxs-dma", mxs_dma);
 	if (ret)
 		goto err_irq;
 

IMO this is wrong. The interrupt is requested with all the same parameters for each DMA channel. So, actually it is not a shared IRQ, but an IRQ with the same handler registered multiple times, which is just nonsense.

Instead of declaring it as shared, it would be more sensible to only register it for the first channel. Otherwise the handler will be called multiple times in case of an interrupt with only the first invocation doing all the work and the subsequent invocations just returning without doing anything.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#4 lore raw

PATCH v3 2/6 dmaengine: change the flags of request_irq()

Quoted 20 lines · Lothar Wa?mann

Hi,

Quoted 17 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. So change the flags from '0' to IRQF_SHARED, else there will be an EBUSY error returns.

---
 drivers/dma/mxs-dma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mxs-dma.c +0 -0
index 88aad4f..0ee5b52 100644
@@ -328,7 +328,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
Quoted 8 lines

drivers/dma/mxs-dma.c static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) · line 334

Quoted 6 lines
drivers/dma/mxs-dma.c +1 -1
 	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
+				IRQF_SHARED, "mxs-dma", mxs_dma);
 	if (ret)
 		goto err_irq;
 

IMO this is wrong. The interrupt is requested with all the same parameters for each DMA channel. So, actually it is not a shared IRQ,

The parameter mxs_chan->chan_irq is different for each channel, except gpmi which has 4 channels sharing one irq.

Quoted 9 lines

but an IRQ with the same handler registered multiple times, which is just nonsense.

Instead of declaring it as shared, it would be more sensible to only register it for the first channel. Otherwise the handler will be called multiple times in case of an interrupt with only the first invocation doing all the work and the subsequent invocations just returning without doing anything.

Signature · 2 lines
Regards,
Shawn
#5 lore raw

PATCH v3 2/6 dmaengine: change the flags of request_irq()

Quoted 30 lines · Shawn Guo
Quoted 20 lines · Lothar Wa?mann

Hi,

Quoted 17 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. So change the flags from '0' to IRQF_SHARED, else there will be an EBUSY error returns.

---
 drivers/dma/mxs-dma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mxs-dma.c +0 -0
index 88aad4f..0ee5b52 100644
@@ -328,7 +328,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
Quoted 8 lines

drivers/dma/mxs-dma.c static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) · line 334

Quoted 6 lines
drivers/dma/mxs-dma.c +1 -1
 	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
+				IRQF_SHARED, "mxs-dma", mxs_dma);
 	if (ret)
 		goto err_irq;
 

IMO this is wrong. The interrupt is requested with all the same parameters for each DMA channel. So, actually it is not a shared IRQ,

Quoted 3 lines

The parameter mxs_chan->chan_irq is different for each channel, except gpmi which has 4 channels sharing one irq.

That's what I mean. The other interrupts won't need the IRQF_SHARED flag anyway.

Quoted 14 lines
Quoted 9 lines

but an IRQ with the same handler registered multiple times, which is just nonsense.

Instead of declaring it as shared, it would be more sensible to only register it for the first channel. Otherwise the handler will be called multiple times in case of an interrupt with only the first invocation doing all the work and the subsequent invocations just returning without doing anything.

Signature · 2 lines
Regards,
Shawn

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#6 lore raw

PATCH v3 2/6 dmaengine: change the flags of request_irq()

Hi:

Quoted 30 lines
Quoted 29 lines · Shawn Guo
Quoted 28 lines · Lothar Wa?mann

Hi,

Quoted 15 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. So change the flags from '0' to IRQF_SHARED, else there will be an EBUSY error returns.

---
  drivers/dma/mxs-dma.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mxs-dma.c +0 -0
index 88aad4f..0ee5b52 100644

drivers/dma/mxs-dma.c static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) · line 334

Quoted 8 lines
drivers/dma/mxs-dma.c +1 -1
@@ -328,7 +328,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
  	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
  	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
+				IRQF_SHARED, "mxs-dma", mxs_dma);
  	if (ret)
  		goto err_irq;
 

IMO this is wrong. The interrupt is requested with all the same parameters for each DMA channel. So, actually it is not a shared IRQ,

Quoted 6 lines
Quoted 3 lines

The parameter mxs_chan->chan_irq is different for each channel, except gpmi which has 4 channels sharing one irq.

That's what I mean. The other interrupts won't need the IRQF_SHARED flag anyway.

Ok. I will add a GPMI-INTERRUPT check in the mxs_dma_alloc_chan_resources().

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

but an IRQ with the same handler registered multiple times, which is just nonsense.

Instead of declaring it as shared, it would be more sensible to only register it for the first channel. Otherwise the handler will be called multiple times in case of an interrupt with only the first invocation doing all the work and the subsequent invocations just returning without doing anything.

Quoted 5 lines
Quoted 4 lines
Signature · 2 lines
Regards,
Shawn

Lothar Wa?mann

Huang Shijie

#7 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

In reply to Lothar Waßmann

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
 drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +32 -4
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
 #include <asm/irq.h>
 #include <mach/mxs.h>
 #include <mach/dma.h>
+#include <mach/mx23.h>
+#include <mach/mx28.h>
 #include <mach/common.h>
 
 /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23() && irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28
+	if (cpu_is_mx28() && irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+	return true;
+}
+
 static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
@@ -327,10 +353,12 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 
 	memset(mxs_chan->ccw, 0, PAGE_SIZE);
 
-	ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
-				0, "mxs-dma", mxs_dma);
-	if (ret)
-		goto err_irq;
+	if (irq_check(mxs_chan)) {
+		ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
+					0, "mxs-dma", mxs_dma);
+		if (ret)
+			goto err_irq;
+	}
 
 	ret = clk_enable(mxs_dma->clk);
 	if (ret)
Signature · 1 line
1.7.0.4
#8 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

Hi,

Quoted 41 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
 drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +16 -0
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
 #include <asm/irq.h>
 #include <mach/mxs.h>
 #include <mach/dma.h>
+#include <mach/mx23.h>
+#include <mach/mx28.h>
 #include <mach/common.h>
 
 /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23() && irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28

drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id) · line 334

Quoted 10 lines
drivers/dma/mxs-dma.c +9 -0
+	if (cpu_is_mx28() && irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+	return true;
+}
 

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#9 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

Hi:

Quoted 48 lines

Hi,

Quoted 45 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
  drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
  1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +20 -0
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
  #include<asm/irq.h>
  #include<mach/mxs.h>
  #include<mach/dma.h>
+#include<mach/mx23.h>
+#include<mach/mx28.h>
  #include<mach/common.h>
 
  /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
  	return IRQ_HANDLED;
  }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23()&&  irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28
+	if (cpu_is_mx28()&&  irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
Quoted 10 lines

drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)

Quoted 6 lines
drivers/dma/mxs-dma.c +5 -0
+			return false;
+	}
+#endif
+	return true;
+}
 

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

Best Regards
Huang Shijie

Quoted 1 line

Lothar Wa?mann

#10 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

Hi,

Quoted 59 lines · Huang Shijie

Hi:

Quoted 48 lines

Hi,

Quoted 45 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
  drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
  1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +20 -0
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
  #include<asm/irq.h>
  #include<mach/mxs.h>
  #include<mach/dma.h>
+#include<mach/mx23.h>
+#include<mach/mx28.h>
  #include<mach/common.h>
 
  /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
  	return IRQ_HANDLED;
  }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23()&&  irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28
+	if (cpu_is_mx28()&&  irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
Quoted 10 lines

drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)

Quoted 6 lines
drivers/dma/mxs-dma.c +5 -0
+			return false;
+	}
+#endif
+	return true;
+}
 

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

Quoted 4 lines

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

The mxs-dma driver is already using platform ids!

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#11 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

Hi,

Quoted 62 lines

Hi,

Quoted 59 lines · Huang Shijie

Hi:

Quoted 58 lines

Hi,

Quoted 41 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
   drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
   1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +16 -0
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
   #include<asm/irq.h>
   #include<mach/mxs.h>
   #include<mach/dma.h>
+#include<mach/mx23.h>
+#include<mach/mx28.h>
   #include<mach/common.h>
 
   /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
   	return IRQ_HANDLED;
   }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23()&&   irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28

drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id) · line 334

Quoted 10 lines
drivers/dma/mxs-dma.c +9 -0
+	if (cpu_is_mx28()&&   irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+	return true;
+}
 

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

Quoted 7 lines
Quoted 4 lines

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

The mxs-dma driver is already using platform ids!

Do you mean the mxd_dma_type[] ?

How can i distinction the imx23 and imx28 with it ? It seems can not be used to do the work.

thanks.

Huang Shijie

Quoted 1 line

Lothar Wa?mann

#12 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

Hi,

Quoted 67 lines · Huang Shijie

Hi,

Quoted 66 lines

Hi,

Quoted 63 lines · Huang Shijie

Hi:

Quoted 48 lines

Hi,

Quoted 45 lines · Huang Shijie

The GPMI may have many DMA channels, such as the imx23 has four DMA channels. All these DMA channels share the same interrupt. Add the interrupt check for the GPMI, only the first DMA channel will register the irq.

---
   drivers/dma/mxs-dma.c |   36 ++++++++++++++++++++++++++++++++----
   1 files changed, 32 insertions(+), 4 deletions(-)
drivers/dma/mxs-dma.c +20 -0
index 88aad4f..db36bf1 100644
@@ -26,6 +26,8 @@
   #include<asm/irq.h>
   #include<mach/mxs.h>
   #include<mach/dma.h>
+#include<mach/mx23.h>
+#include<mach/mx28.h>
   #include<mach/common.h>
 
   /*
@@ -306,6 +308,30 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
   	return IRQ_HANDLED;
   }
 
+/* The GPMI has several DMA channels, only the first can register the irq. */
+static bool irq_check(struct mxs_dma_chan *mxs_chan)
+{
+	int irq_num = mxs_chan->chan_irq;
+
+#ifdef CONFIG_SOC_IMX23
+	if (cpu_is_mx23()&&   irq_num == MX23_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX23_DMA_GPMI0)
+			return true;
+		else
+			return false;
+	}
+#endif
+#ifdef CONFIG_SOC_IMX28
+	if (cpu_is_mx28()&&   irq_num == MX28_INT_GPMI_DMA) {
+		if (mxs_chan->chan.chan_id == MX28_DMA_GPMI0)
+			return true;
+		else
Quoted 10 lines

drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)

Quoted 6 lines
drivers/dma/mxs-dma.c +5 -0
+			return false;
+	}
+#endif
+	return true;
+}
 

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

Quoted 8 lines
Quoted 3 lines

The mxs-dma driver is already using platform ids!

Do you mean the mxd_dma_type[] ?

How can i distinction the imx23 and imx28 with it ? It seems can not be used to do the work.

It should be extended to make this distinction possible.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#13 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

In reply to Huang Shijie

On Thu, Mar 31, 2011 at 05:08:54PM +0800, Huang Shijie wrote:
[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

Quoted 8 lines
Quoted 3 lines

The mxs-dma driver is already using platform ids!

Do you mean the mxd_dma_type[] ?

How can i distinction the imx23 and imx28 with it ? It seems can not be used to do the work.

You can drop the dmaengine patch from your gpmi series. I will find some time to fix this together with removing cpu_is_xx() and inclusion of mxs.h, to get it prepared for i.mx50 aphb-dma support.

Signature · 2 lines
Regards,
Shawn
#14 lore raw

PATCH v3 2/6 dmaengine: add interrupt check for GPMI controller

hi:

Quoted 13 lines · Huang Shijie

[...]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

You should make the distinction based on the platform_id, which would save you the ugly ifdef's and cpu_is_... macros.

This in the DMA driver.
Do you want me to change the DMA driver to add the platform_id? The DMA driver has already used the cpu_is_xx() macros.

The mxs-dma driver is already using platform ids!

Quoted 9 lines
Quoted 5 lines

Do you mean the mxd_dma_type[] ?

How can i distinction the imx23 and imx28 with it ? It seems can not be used to do the work.

You can drop the dmaengine patch from your gpmi series. I will find some time to fix this together with removing cpu_is_xx() and inclusion of mxs.h, to get it prepared for i.mx50 aphb-dma support.

ok, thanks.

Huang Shijie

#15 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

In reply to Huang Shijie

This is a new database for the NANDs which is searched by the id_bytes.

---
 drivers/mtd/nand/nand_device_info.c |  157 +++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_device_info.h |   88 +++++++++++++++++++
 2 files changed, 245 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/nand_device_info.c
 create mode 100644 drivers/mtd/nand/nand_device_info.h
drivers/mtd/nand/nand_device_info.c new file +157 -0
new file mode 100644
index 0000000..757ed89
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include <asm/sizes.h>
+#include <linux/mtd/nand.h>
+
+#include "nand_device_info.h"
+
+static const struct nand_device_info samsung_nand[] = {
+	{
+		.id	= { 0xec, 0xd3, 0x14, 0x25, 0x64, 0xec, 0xd3, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9G8G08U0M, K9HAG08U1M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 1LL * SZ_1G, 128,
+				2 * SZ_1K + 64, 8, 512),
+	}, {
+		.id	= { 0xec, 0xd7, 0xd5, 0x29, 0x38, 0x41, 0xec, 0xd7 },
+		.id_len	= 8,
+		.desc	= "K9LBG08U0D",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 4LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		.id	= { 0xec, 0xd5, 0x14, 0xb6, 0x74, 0xec, 0xd5, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9GAG08U0M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 2LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		/* end of the table. */
+		.id	= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+	},
+};
+
+/* macro to get the id bytes */
+#define ID_GET_MFR_CODE(id)  ((id)[0])
+
+void nand_device_print_info(struct nand_device_info *info)
+{
+	unsigned    i;
+	const char  *mfr_name;
+	const char  *cell_technology_name;
+	uint64_t    chip_size;
+	const char  *chip_size_units;
+	unsigned    page_size;
+	unsigned    oob_size;
+	struct nand_attr *attr		= &info->attr;
+
+	/* Prepare the manufacturer name. */
+	mfr_name = "Unknown";
+	for (i = 0; nand_manuf_ids[i].id; i++) {
+		if (nand_manuf_ids[i].id == ID_GET_MFR_CODE(info->id)) {
+			mfr_name = nand_manuf_ids[i].name;
+			break;
+		}
+	}
+
+	/* Prepare the name of the cell technology. */
+	switch (attr->cell_technology) {
+	case SLC:
+		cell_technology_name = "SLC";
+		break;
+	case MLC:
+		cell_technology_name = "MLC";
+		break;
+	default:
+		cell_technology_name = "Unknown";
+		break;
+	}
+
+	/* Prepare the chip size. */
+	if ((attr->chip_size_in_bytes >= SZ_1G) &&
+					!(attr->chip_size_in_bytes % SZ_1G)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1G);
+		chip_size_units = "GiB";
+	} else if ((attr->chip_size_in_bytes >= SZ_1M) &&
+					!(attr->chip_size_in_bytes % SZ_1M)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1M);
+		chip_size_units = "MiB";
+	} else {
+		chip_size       = attr->chip_size_in_bytes;
+		chip_size_units = "B";
+	}
+
+	/* Prepare the page geometry. */
+	page_size = (1 << (fls(attr->page_total_size_in_bytes) - 1));
+	oob_size  = attr->page_total_size_in_bytes - page_size;
+
+	/* Print the infomation. */
+	pr_info("--------------------------------------\n");
+	pr_info("	NAND device infomation (RAW)\n");
+	pr_info("--------------------------------------\n");
+	pr_info("Manufacturer      : %s (0x%02x)\n", mfr_name, info->id[0]);
+	pr_info("Device Code       : 0x%02x\n", info->id[1]);
+	pr_info("Cell Technology   : %s\n", cell_technology_name);
+	pr_info("Chip Size         : %llu %s\n", chip_size, chip_size_units);
+	pr_info("Pages per Block   : %u\n", attr->block_size_in_pages);
+	pr_info("Page Geometry     : %u+%u\n", page_size, oob_size);
+	pr_info("ECC Strength      : %u bits\n", attr->ecc_strength_in_bits);
+	pr_info("ECC Size          : %u B\n", attr->ecc_size_in_bytes);
+	pr_info("Description       : %s\n", info->desc);
+}
+
+static struct nand_device_info * __init
+search_table(const struct nand_device_info *table, const uint8_t id[])
+{
+	struct nand_device_info *info = (struct nand_device_info *)table;
+
+	while (ID_GET_MFR_CODE(info->id)) {
+		int i;
+
+		/* match all the valid id bytes. Is it too strict? */
+		for (i = 0; i < info->id_len; i++)
+			if (info->id[i] != id[i])
+				break;
+
+		/* found it */
+		if (i == info->id_len)
+			return info;
+		info++;
+	}
+	return NULL;
+}
+
+struct nand_device_mfr_info {
+	uint8_t                  id;
+	const struct nand_device_info  *table;
+};
+
+static const struct nand_device_mfr_info  nand_device_mfr_directory[] = {
+	{ NAND_MFR_SAMSUNG, samsung_nand },
+	{ 0, NULL },
+};
+
+struct nand_device_info *nand_device_get_info(const uint8_t id[])
+{
+	uint8_t mfr_id = ID_GET_MFR_CODE(id);
+	unsigned i;
+
+	for (i = 0; nand_device_mfr_directory[i].id; i++) {
+		if (nand_device_mfr_directory[i].id == mfr_id) {
+			const struct nand_device_info  *table;
+
+			table = nand_device_mfr_directory[i].table;
+			return search_table(table, id);
+		}
+	}
+	return NULL;
+}
drivers/mtd/nand/nand_device_info.h new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#16 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hello Huang,

Quoted 1 line · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

Quoted 267 lines
---
 drivers/mtd/nand/nand_device_info.c |  157
+++++++++++++++++++++++++++++++++++ drivers/mtd/nand/nand_device_info.h | 
 88 +++++++++++++++++++
 2 files changed, 245 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/nand_device_info.c
 create mode 100644 drivers/mtd/nand/nand_device_info.h
(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.c new file mode 100644 index 0000000..757ed89

drivers/mtd/nand/nand_device_info.c new file +157 -0
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include <asm/sizes.h>
+#include <linux/mtd/nand.h>
+
+#include "nand_device_info.h"
+
+static const struct nand_device_info samsung_nand[] = {
+	{
+		.id	= { 0xec, 0xd3, 0x14, 0x25, 0x64, 0xec, 0xd3, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9G8G08U0M, K9HAG08U1M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 1LL * SZ_1G, 128,
+				2 * SZ_1K + 64, 8, 512),
+	}, {
+		.id	= { 0xec, 0xd7, 0xd5, 0x29, 0x38, 0x41, 0xec, 0xd7 },
+		.id_len	= 8,
+		.desc	= "K9LBG08U0D",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 4LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		.id	= { 0xec, 0xd5, 0x14, 0xb6, 0x74, 0xec, 0xd5, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9GAG08U0M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 2LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		/* end of the table. */
+		.id	= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+	},
+};
+
+/* macro to get the id bytes */
+#define ID_GET_MFR_CODE(id)  ((id)[0])
+
+void nand_device_print_info(struct nand_device_info *info)
+{
+	unsigned    i;
+	const char  *mfr_name;
+	const char  *cell_technology_name;
+	uint64_t    chip_size;
+	const char  *chip_size_units;
+	unsigned    page_size;
+	unsigned    oob_size;
+	struct nand_attr *attr		= &info->attr;
+
+	/* Prepare the manufacturer name. */
+	mfr_name = "Unknown";
+	for (i = 0; nand_manuf_ids[i].id; i++) {
+		if (nand_manuf_ids[i].id == ID_GET_MFR_CODE(info->id)) {
+			mfr_name = nand_manuf_ids[i].name;
+			break;
+		}
+	}
+
+	/* Prepare the name of the cell technology. */
+	switch (attr->cell_technology) {
+	case SLC:
+		cell_technology_name = "SLC";
+		break;
+	case MLC:
+		cell_technology_name = "MLC";
+		break;
+	default:
+		cell_technology_name = "Unknown";
+		break;
+	}
+
+	/* Prepare the chip size. */
+	if ((attr->chip_size_in_bytes >= SZ_1G) &&
+					!(attr->chip_size_in_bytes % SZ_1G)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1G);
+		chip_size_units = "GiB";
+	} else if ((attr->chip_size_in_bytes >= SZ_1M) &&
+					!(attr->chip_size_in_bytes % SZ_1M)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1M);
+		chip_size_units = "MiB";
+	} else {
+		chip_size       = attr->chip_size_in_bytes;
+		chip_size_units = "B";
+	}
+
+	/* Prepare the page geometry. */
+	page_size = (1 << (fls(attr->page_total_size_in_bytes) - 1));
+	oob_size  = attr->page_total_size_in_bytes - page_size;
+
+	/* Print the infomation. */
+	pr_info("--------------------------------------\n");
+	pr_info("	NAND device infomation (RAW)\n");
+	pr_info("--------------------------------------\n");
+	pr_info("Manufacturer      : %s (0x%02x)\n", mfr_name, info->id[0]);
+	pr_info("Device Code       : 0x%02x\n", info->id[1]);
+	pr_info("Cell Technology   : %s\n", cell_technology_name);
+	pr_info("Chip Size         : %llu %s\n", chip_size, chip_size_units);
+	pr_info("Pages per Block   : %u\n", attr->block_size_in_pages);
+	pr_info("Page Geometry     : %u+%u\n", page_size, oob_size);
+	pr_info("ECC Strength      : %u bits\n", attr->ecc_strength_in_bits);
+	pr_info("ECC Size          : %u B\n", attr->ecc_size_in_bytes);
+	pr_info("Description       : %s\n", info->desc);
+}
+
+static struct nand_device_info * __init
+search_table(const struct nand_device_info *table, const uint8_t id[])
+{
+	struct nand_device_info *info = (struct nand_device_info *)table;
+
+	while (ID_GET_MFR_CODE(info->id)) {
+		int i;
+
+		/* match all the valid id bytes. Is it too strict? */
+		for (i = 0; i < info->id_len; i++)
+			if (info->id[i] != id[i])
+				break;
+
+		/* found it */
+		if (i == info->id_len)
+			return info;
+		info++;
+	}
+	return NULL;
+}
+
+struct nand_device_mfr_info {
+	uint8_t                  id;
+	const struct nand_device_info  *table;
+};
+
+static const struct nand_device_mfr_info  nand_device_mfr_directory[] = {
+	{ NAND_MFR_SAMSUNG, samsung_nand },
+	{ 0, NULL },
+};
+
+struct nand_device_info *nand_device_get_info(const uint8_t id[])
+{
+	uint8_t mfr_id = ID_GET_MFR_CODE(id);
+	unsigned i;
+
+	for (i = 0; nand_device_mfr_directory[i].id; i++) {
+		if (nand_device_mfr_directory[i].id == mfr_id) {
+			const struct nand_device_info  *table;
+
+			table = nand_device_mfr_directory[i].table;
+			return search_table(table, id);
+		}
+	}
+	return NULL;
+}
(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.h new file mode 100644 index 0000000..15f688d

drivers/mtd/nand/nand_device_info.h new file +29 -0
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __DRIVERS_NAND_DEVICE_INFO_H
+#define __DRIVERS_NAND_DEVICE_INFO_H
+
+enum nand_device_cell_technology {
+	SLC = 0,
+	MLC = 1,
+};
+
+/**
+ * @cell_technology:		The storage cell technology.
+ * @busw:			The bus width of the NAND.
+ * @chip_size_in_bytes:		The total size of the storage behind a single
+ *				chip select, in bytes. Notice that this is *not*
+ *				necessarily the total size of the storage in a
+ *				*package*, which may contain several chips.
+ * @block_size_in_pages:	The number of pages in a block.
+ * @page_total_size_in_bytes:	The total size of a page, in bytes,

including + * both the data and the OOB.
+ * @ecc_strength_in_bits: The strength of the ECC called for by the
+ * manufacturer, in number of correctable bits.
+ * @ecc_size_in_bytes: The size of the data block over which the
+ * manufacturer calls for the given ECC algorithm
+ * and strength.
+ */

drivers/mtd/nand/nand_device_info.h new file +23 -0
+struct nand_attr {
+	/* Technology */
+	enum nand_device_cell_technology  cell_technology;
+
+	/* bus width */
+#define NAND_BUSWIDTH_8	0
+	uint32_t	busw;
+
+	/* Geometry */
+	uint64_t	chip_size_in_bytes;
+	uint32_t	block_size_in_pages;
+	uint32_t	page_total_size_in_bytes;
+
+	/* ECC */
+	uint16_t	ecc_strength_in_bits;
+	uint16_t	ecc_size_in_bytes;
+};
+
+#define ID_BYTES	(8)
+/*
+ * struct nand_device_info - Information about a single NAND Flash device.
+ *
+ * This structure contains all the *essential* information about a NAND

Flash + * device, derived from the device's data sheet.
+ */

drivers/mtd/nand/nand_device_info.h new file +27 -0
+struct nand_device_info {
+	/* id */
+	uint8_t			id[ID_BYTES];
+	unsigned int		id_len;
+
+	/* Description */
+	const char		*desc;
+
+	/* attribute*/
+	struct nand_attr	attr;
+};
+
+/* macro for the NAND attribute */
+#define ATTR(_a, _b, _c, _d, _e, _f, _g)		\
+	{						\
+		.cell_technology		= (_a),	\
+		.busw				= (_b),	\
+		.chip_size_in_bytes		= (_c),	\
+		.block_size_in_pages		= (_d),	\
+		.page_total_size_in_bytes	= (_e),	\
+		.ecc_strength_in_bits		= (_f),	\
+		.ecc_size_in_bytes		= (_g),	\
+	}
+
+struct nand_device_info *nand_device_get_info(const uint8_t id_bytes[]);
+void nand_device_print_info(struct nand_device_info *info);
+#endif
#17 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hi Florian:

thanks for a so quick reply. :)

Quoted 7 lines

Hello Huang,

Quoted 1 line · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

yes.

But I will use the new database to replace the old one.

I will submit new patches to modify the generic code if my driver is accepted.

Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :( Paring the id bytes is not sufficient to get all the information you need which is faced by me.

What's more, I think the paring code is ugly, see the nand_get_flash_type().

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

I wish David and Artem give some advice about this.

Quoted 258 lines
Quoted 258 lines
---
  drivers/mtd/nand/nand_device_info.c |  157
+++++++++++++++++++++++++++++++++++ drivers/mtd/nand/nand_device_info.h |
  88 +++++++++++++++++++
  2 files changed, 245 insertions(+), 0 deletions(-)

create mode 100644 drivers/mtd/nand/nand_device_info.c create mode 100644 drivers/mtd/nand/nand_device_info.h

(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.c new file mode 100644 index 0000000..757ed89

drivers/mtd/nand/nand_device_info.c new file +157 -0
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include<asm/sizes.h>
+#include<linux/mtd/nand.h>
+
+#include "nand_device_info.h"
+
+static const struct nand_device_info samsung_nand[] = {
+	{
+		.id	= { 0xec, 0xd3, 0x14, 0x25, 0x64, 0xec, 0xd3, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9G8G08U0M, K9HAG08U1M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 1LL * SZ_1G, 128,
+				2 * SZ_1K + 64, 8, 512),
+	}, {
+		.id	= { 0xec, 0xd7, 0xd5, 0x29, 0x38, 0x41, 0xec, 0xd7 },
+		.id_len	= 8,
+		.desc	= "K9LBG08U0D",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 4LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		.id	= { 0xec, 0xd5, 0x14, 0xb6, 0x74, 0xec, 0xd5, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9GAG08U0M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 2LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		/* end of the table. */
+		.id	= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+	},
+};
+
+/* macro to get the id bytes */
+#define ID_GET_MFR_CODE(id)  ((id)[0])
+
+void nand_device_print_info(struct nand_device_info *info)
+{
+	unsigned    i;
+	const char  *mfr_name;
+	const char  *cell_technology_name;
+	uint64_t    chip_size;
+	const char  *chip_size_units;
+	unsigned    page_size;
+	unsigned    oob_size;
+	struct nand_attr *attr		=&info->attr;
+
+	/* Prepare the manufacturer name. */
+	mfr_name = "Unknown";
+	for (i = 0; nand_manuf_ids[i].id; i++) {
+		if (nand_manuf_ids[i].id == ID_GET_MFR_CODE(info->id)) {
+			mfr_name = nand_manuf_ids[i].name;
+			break;
+		}
+	}
+
+	/* Prepare the name of the cell technology. */
+	switch (attr->cell_technology) {
+	case SLC:
+		cell_technology_name = "SLC";
+		break;
+	case MLC:
+		cell_technology_name = "MLC";
+		break;
+	default:
+		cell_technology_name = "Unknown";
+		break;
+	}
+
+	/* Prepare the chip size. */
+	if ((attr->chip_size_in_bytes>= SZ_1G)&&
+					!(attr->chip_size_in_bytes % SZ_1G)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1G);
+		chip_size_units = "GiB";
+	} else if ((attr->chip_size_in_bytes>= SZ_1M)&&
+					!(attr->chip_size_in_bytes % SZ_1M)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) SZ_1M);
+		chip_size_units = "MiB";
+	} else {
+		chip_size       = attr->chip_size_in_bytes;
+		chip_size_units = "B";
+	}
+
+	/* Prepare the page geometry. */
+	page_size = (1<<  (fls(attr->page_total_size_in_bytes) - 1));
+	oob_size  = attr->page_total_size_in_bytes - page_size;
+
+	/* Print the infomation. */
+	pr_info("--------------------------------------\n");
+	pr_info("	NAND device infomation (RAW)\n");
+	pr_info("--------------------------------------\n");
+	pr_info("Manufacturer      : %s (0x%02x)\n", mfr_name, info->id[0]);
+	pr_info("Device Code       : 0x%02x\n", info->id[1]);
+	pr_info("Cell Technology   : %s\n", cell_technology_name);
+	pr_info("Chip Size         : %llu %s\n", chip_size, chip_size_units);
+	pr_info("Pages per Block   : %u\n", attr->block_size_in_pages);
+	pr_info("Page Geometry     : %u+%u\n", page_size, oob_size);
+	pr_info("ECC Strength      : %u bits\n", attr->ecc_strength_in_bits);
+	pr_info("ECC Size          : %u B\n", attr->ecc_size_in_bytes);
+	pr_info("Description       : %s\n", info->desc);
+}
+
+static struct nand_device_info * __init
+search_table(const struct nand_device_info *table, const uint8_t id[])
+{
+	struct nand_device_info *info = (struct nand_device_info *)table;
+
+	while (ID_GET_MFR_CODE(info->id)) {
+		int i;
+
+		/* match all the valid id bytes. Is it too strict? */
+		for (i = 0; i<  info->id_len; i++)
+			if (info->id[i] != id[i])
+				break;
+
+		/* found it */
+		if (i == info->id_len)
+			return info;
+		info++;
+	}
+	return NULL;
+}
+
+struct nand_device_mfr_info {
+	uint8_t                  id;
+	const struct nand_device_info  *table;
+};
+
+static const struct nand_device_mfr_info  nand_device_mfr_directory[] = {
+	{ NAND_MFR_SAMSUNG, samsung_nand },
+	{ 0, NULL },
+};
+
+struct nand_device_info *nand_device_get_info(const uint8_t id[])
+{
+	uint8_t mfr_id = ID_GET_MFR_CODE(id);
+	unsigned i;
+
+	for (i = 0; nand_device_mfr_directory[i].id; i++) {
+		if (nand_device_mfr_directory[i].id == mfr_id) {
+			const struct nand_device_info  *table;
+
+			table = nand_device_mfr_directory[i].table;
+			return search_table(table, id);
+		}
+	}
+	return NULL;
+}
(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.h new file mode 100644 index 0000000..15f688d

drivers/mtd/nand/nand_device_info.h new file +29 -0
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __DRIVERS_NAND_DEVICE_INFO_H
+#define __DRIVERS_NAND_DEVICE_INFO_H
+
+enum nand_device_cell_technology {
+	SLC = 0,
+	MLC = 1,
+};
+
+/**
+ * @cell_technology:		The storage cell technology.
+ * @busw:			The bus width of the NAND.
+ * @chip_size_in_bytes:		The total size of the storage behind a single
+ *				chip select, in bytes. Notice that this is *not*
+ *				necessarily the total size of the storage in a
+ *				*package*, which may contain several chips.
+ * @block_size_in_pages:	The number of pages in a block.
+ * @page_total_size_in_bytes:	The total size of a page, in bytes,

including + * both the data and the OOB.
+ * @ecc_strength_in_bits: The strength of the ECC called for by the
+ * manufacturer, in number of correctable bits.
+ * @ecc_size_in_bytes: The size of the data block over which the
+ * manufacturer calls for the given ECC algorithm
+ * and strength.
+ */

drivers/mtd/nand/nand_device_info.h new file +23 -0
+struct nand_attr {
+	/* Technology */
+	enum nand_device_cell_technology  cell_technology;
+
+	/* bus width */
+#define NAND_BUSWIDTH_8	0
+	uint32_t	busw;
+
+	/* Geometry */
+	uint64_t	chip_size_in_bytes;
+	uint32_t	block_size_in_pages;
+	uint32_t	page_total_size_in_bytes;
+
+	/* ECC */
+	uint16_t	ecc_strength_in_bits;
+	uint16_t	ecc_size_in_bytes;
+};
+
+#define ID_BYTES	(8)
+/*
+ * struct nand_device_info - Information about a single NAND Flash device.
+ *
+ * This structure contains all the *essential* information about a NAND

Flash + * device, derived from the device's data sheet.
+ */

drivers/mtd/nand/nand_device_info.h new file +19 -0
+struct nand_device_info {
+	/* id */
+	uint8_t			id[ID_BYTES];
+	unsigned int		id_len;
+
+	/* Description */
+	const char		*desc;
+
+	/* attribute*/
+	struct nand_attr	attr;
+};
+
+/* macro for the NAND attribute */
+#define ATTR(_a, _b, _c, _d, _e, _f, _g)		\
+	{						\
+		.cell_technology		= (_a),	\
+		.busw				= (_b),	\
+		.chip_size_in_bytes		= (_c),	\
+		.block_size_in_pages		= (_d),	\
Quoted 8 lines

drivers/mtd/nand/nand_device_info.h line 88

Quoted 8 lines
drivers/mtd/nand/nand_device_info.h new file +8 -0
+		.page_total_size_in_bytes	= (_e),	\
+		.ecc_strength_in_bits		= (_f),	\
+		.ecc_size_in_bytes		= (_g),	\
+	}
+
+struct nand_device_info *nand_device_get_info(const uint8_t id_bytes[]);
+void nand_device_print_info(struct nand_device_info *info);
+#endif

Best Regards
Huang Shijie

#18 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hello Huang,

Quoted 12 lines · On Wednesday 30 March 2011 11:05:59 Huang Shijie wrote:

Hi Florian:

thanks for a so quick reply. :)

Quoted 7 lines

Hello Huang,

Quoted 1 line · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

Quoted 6 lines

yes.

But I will use the new database to replace the old one.

I will submit new patches to modify the generic code if my driver is accepted.

I think you can start right away submitting patches to modify generic code, this can either be a premilinary patch series to the GPMI driver, or in the same patch series as the GPMI driver.

Quoted 6 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Ok, you should have written that in the patch description, otherwise it is misleading and I though you just duplicated code without knowing what the existing code could do.

Quoted 10 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :( Paring the id bytes is not sufficient to get all the information you need which is faced by me.

Quoted 6 lines

What's more, I think the paring code is ugly, see the nand_get_flash_type().

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

The idea is to hardcode as little information as possible, and let the rest be detected at runtime when possible. I think this it the right approach, because it is more future proof.

Quoted 2 lines

I wish David and Artem give some advice about this.

I would also like them to jump into this discussion.

Quoted 94 lines
Quoted 94 lines
Quoted 94 lines

---

  drivers/mtd/nand/nand_device_info.c |  157

+++++++++++++++++++++++++++++++++++ drivers/mtd/nand/nand_device_info.h |

88 +++++++++++++++++++

  2 files changed, 245 insertions(+), 0 deletions(-)

create mode 100644 drivers/mtd/nand/nand_device_info.c create mode 100644 drivers/mtd/nand/nand_device_info.h

(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.c new file mode 100644 index 0000000..757ed89

drivers/mtd/nand/nand_device_info.c new file +2 -0
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights

Reserved. + */

drivers/mtd/nand/nand_device_info.c new file +71 -0
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include<asm/sizes.h>
+#include<linux/mtd/nand.h>
+
+#include "nand_device_info.h"
+
+static const struct nand_device_info samsung_nand[] = {
+	{
+		.id	= { 0xec, 0xd3, 0x14, 0x25, 0x64, 0xec, 0xd3, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9G8G08U0M, K9HAG08U1M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 1LL * SZ_1G, 128,
+				2 * SZ_1K + 64, 8, 512),
+	}, {
+		.id	= { 0xec, 0xd7, 0xd5, 0x29, 0x38, 0x41, 0xec, 0xd7 },
+		.id_len	= 8,
+		.desc	= "K9LBG08U0D",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 4LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		.id	= { 0xec, 0xd5, 0x14, 0xb6, 0x74, 0xec, 0xd5, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9GAG08U0M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 2LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		/* end of the table. */
+		.id	= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+	},
+};
+
+/* macro to get the id bytes */
+#define ID_GET_MFR_CODE(id)  ((id)[0])
+
+void nand_device_print_info(struct nand_device_info *info)
+{
+	unsigned    i;
+	const char  *mfr_name;
+	const char  *cell_technology_name;
+	uint64_t    chip_size;
+	const char  *chip_size_units;
+	unsigned    page_size;
+	unsigned    oob_size;
+	struct nand_attr *attr		=&info->attr;
+
+	/* Prepare the manufacturer name. */
+	mfr_name = "Unknown";
+	for (i = 0; nand_manuf_ids[i].id; i++) {
+		if (nand_manuf_ids[i].id == ID_GET_MFR_CODE(info->id)) {
+			mfr_name = nand_manuf_ids[i].name;
+			break;
+		}
+	}
+
+	/* Prepare the name of the cell technology. */
+	switch (attr->cell_technology) {
+	case SLC:
+		cell_technology_name = "SLC";
+		break;
+	case MLC:
+		cell_technology_name = "MLC";
+		break;
+	default:
Quoted 8 lines
Quoted 8 lines

drivers/mtd/nand/nand_device_info.c

Quoted 8 lines
drivers/mtd/nand/nand_device_info.c new file +8 -0
+		cell_technology_name = "Unknown";
+		break;
+	}
+
+	/* Prepare the chip size. */
+	if ((attr->chip_size_in_bytes>= SZ_1G)&&
+					!(attr->chip_size_in_bytes % SZ_1G)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) 

SZ_1G);

Quoted 4 lines
Quoted 4 lines

drivers/mtd/nand/nand_device_info.c

Quoted 4 lines
drivers/mtd/nand/nand_device_info.c new file +4 -0
+		chip_size_units = "GiB";
+	} else if ((attr->chip_size_in_bytes>= SZ_1M)&&
+					!(attr->chip_size_in_bytes % SZ_1M)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t) 

SZ_1M);

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/mtd/nand/nand_device_info.c new file +10 -0
+		chip_size_units = "MiB";
+	} else {
+		chip_size       = attr->chip_size_in_bytes;
+		chip_size_units = "B";
+	}
+
+	/* Prepare the page geometry. */
+	page_size = (1<<  (fls(attr->page_total_size_in_bytes) - 1));
+	oob_size  = attr->page_total_size_in_bytes - page_size;
+
Quoted 8 lines
Quoted 8 lines

drivers/mtd/nand/nand_device_info.c

Quoted 8 lines
drivers/mtd/nand/nand_device_info.c new file +8 -0
+	/* Print the infomation. */
+	pr_info("--------------------------------------\n");
+	pr_info("	NAND device infomation (RAW)\n");
+	pr_info("--------------------------------------\n");
+	pr_info("Manufacturer      : %s (0x%02x)\n", mfr_name, info->id[0]);
+	pr_info("Device Code       : 0x%02x\n", info->id[1]);
+	pr_info("Cell Technology   : %s\n", cell_technology_name);
+	pr_info("Chip Size         : %llu %s\n", chip_size, 

chip_size_units);

Quoted 76 lines
Quoted 3 lines

drivers/mtd/nand/nand_device_info.c

Quoted 3 lines
drivers/mtd/nand/nand_device_info.c new file +3 -0
+	pr_info("Pages per Block   : %u\n", attr->block_size_in_pages);
+	pr_info("Page Geometry     : %u+%u\n", page_size, oob_size);
+	pr_info("ECC Strength      : %u bits\n", attr-

ecc_strength_in_bits);

Quoted 72 lines
Quoted 72 lines
drivers/mtd/nand/nand_device_info.c new file +31 -0
+	pr_info("ECC Size          : %u B\n", attr->ecc_size_in_bytes);
+	pr_info("Description       : %s\n", info->desc);
+}
+
+static struct nand_device_info * __init
+search_table(const struct nand_device_info *table, const uint8_t id[])
+{
+	struct nand_device_info *info = (struct nand_device_info *)table;
+
+	while (ID_GET_MFR_CODE(info->id)) {
+		int i;
+
+		/* match all the valid id bytes. Is it too strict? */
+		for (i = 0; i<  info->id_len; i++)
+			if (info->id[i] != id[i])
+				break;
+
+		/* found it */
+		if (i == info->id_len)
+			return info;
+		info++;
+	}
+	return NULL;
+}
+
+struct nand_device_mfr_info {
+	uint8_t                  id;
+	const struct nand_device_info  *table;
+};
+
+static const struct nand_device_mfr_info  nand_device_mfr_directory[] =

{ + { NAND_MFR_SAMSUNG, samsung_nand },

drivers/mtd/nand/nand_device_info.c new file +18 -0
+	{ 0, NULL },
+};
+
+struct nand_device_info *nand_device_get_info(const uint8_t id[])
+{
+	uint8_t mfr_id = ID_GET_MFR_CODE(id);
+	unsigned i;
+
+	for (i = 0; nand_device_mfr_directory[i].id; i++) {
+		if (nand_device_mfr_directory[i].id == mfr_id) {
+			const struct nand_device_info  *table;
+
+			table = nand_device_mfr_directory[i].table;
+			return search_table(table, id);
+		}
+	}
+	return NULL;
+}
(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.h new file mode 100644 index 0000000..15f688d

drivers/mtd/nand/nand_device_info.h new file +16 -0
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __DRIVERS_NAND_DEVICE_INFO_H
+#define __DRIVERS_NAND_DEVICE_INFO_H
+
+enum nand_device_cell_technology {
Quoted 8 lines
Quoted 8 lines

drivers/mtd/nand/nand_device_info.h

Quoted 8 lines
drivers/mtd/nand/nand_device_info.h new file +8 -0
+	SLC = 0,
+	MLC = 1,
+};
+
+/**
+ * @cell_technology:		The storage cell technology.
+ * @busw:			The bus width of the NAND.
+ * @chip_size_in_bytes:		The total size of the storage behind a 

single

Quoted 75 lines
Quoted 57 lines
Quoted 57 lines
drivers/mtd/nand/nand_device_info.h new file +5 -0
+ *				chip select, in bytes. Notice that this is *not*
+ *				necessarily the total size of the storage in a
+ *				*package*, which may contain several chips.
+ * @block_size_in_pages:	The number of pages in a block.
+ * @page_total_size_in_bytes:	The total size of a page, in bytes,

including + * both the data and the OOB.
+ * @ecc_strength_in_bits: The strength of the ECC called for by the
+ * manufacturer, in number of correctable bits.
+ * @ecc_size_in_bytes: The size of the data block over which the
+ * manufacturer calls for the given ECC algorithm
+ * and strength.
+ */

drivers/mtd/nand/nand_device_info.h new file +21 -0
+struct nand_attr {
+	/* Technology */
+	enum nand_device_cell_technology  cell_technology;
+
+	/* bus width */
+#define NAND_BUSWIDTH_8	0
+	uint32_t	busw;
+
+	/* Geometry */
+	uint64_t	chip_size_in_bytes;
+	uint32_t	block_size_in_pages;
+	uint32_t	page_total_size_in_bytes;
+
+	/* ECC */
+	uint16_t	ecc_strength_in_bits;
+	uint16_t	ecc_size_in_bytes;
+};
+
+#define ID_BYTES	(8)
+/*
+ * struct nand_device_info - Information about a single NAND Flash

device. + *
+ * This structure contains all the *essential* information about a NAND Flash + * device, derived from the device's data sheet.
+ */

drivers/mtd/nand/nand_device_info.h new file +20 -0
+struct nand_device_info {
+	/* id */
+	uint8_t			id[ID_BYTES];
+	unsigned int		id_len;
+
+	/* Description */
+	const char		*desc;
+
+	/* attribute*/
+	struct nand_attr	attr;
+};
+
+/* macro for the NAND attribute */
+#define ATTR(_a, _b, _c, _d, _e, _f, _g)		\
+	{						\
+		.cell_technology		= (_a),	\
+		.busw				= (_b),	\
+		.chip_size_in_bytes		= (_c),	\
+		.block_size_in_pages		= (_d),	\
+		.page_total_size_in_bytes	= (_e),	\
Quoted 8 lines
Quoted 8 lines
drivers/mtd/nand/nand_device_info.h new file +5 -0
+		.ecc_strength_in_bits		= (_f),	\
+		.ecc_size_in_bytes		= (_g),	\
+	}
+
+struct nand_device_info *nand_device_get_info(const uint8_t

id_bytes[]); +void nand_device_print_info(struct nand_device_info *info);
+#endif

Best Regards
Huang Shijie

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

#19 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hi Florian:

Quoted 15 lines

Hello Huang,

Quoted 12 lines · On Wednesday 30 March 2011 11:05:59 Huang Shijie wrote:

Hi Florian:

thanks for a so quick reply. :)

Quoted 6 lines

Hello Huang,

Quoted 1 line · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

yes.

Quoted 8 lines
Quoted 4 lines

But I will use the new database to replace the old one.

I will submit new patches to modify the generic code if my driver is accepted.

I think you can start right away submitting patches to modify generic code, this can either be a premilinary patch series to the GPMI driver, or in the same patch series as the GPMI driver.

I prefer to change the generic code after the driver is merged. thanks.

I am too busy to change it right now.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Ok, you should have written that in the patch description, otherwise it is misleading and I though you just duplicated code without knowing what the existing code could do.

my fault.

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :( Paring the id bytes is not sufficient to get all the information you need which is faced by me.

What's more, I think the paring code is ugly, see the nand_get_flash_type().

Quoted 7 lines
Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

The idea is to hardcode as little information as possible, and let the rest be detected at runtime when possible. I think this it the right approach, because it is more future proof.

thanks.

Quoted 3 lines
Quoted 1 line

I wish David and Artem give some advice about this.

I would also like them to jump into this discussion.

me too:)

Quoted 203 lines
Quoted 93 lines
Quoted 93 lines
Quoted 93 lines

---

   drivers/mtd/nand/nand_device_info.c |  157

+++++++++++++++++++++++++++++++++++ drivers/mtd/nand/nand_device_info.h |

88 +++++++++++++++++++

   2 files changed, 245 insertions(+), 0 deletions(-)

create mode 100644 drivers/mtd/nand/nand_device_info.c create mode 100644 drivers/mtd/nand/nand_device_info.h

(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.c new file mode 100644 index 0000000..757ed89

drivers/mtd/nand/nand_device_info.c new file +2 -0
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights

Reserved. + */

drivers/mtd/nand/nand_device_info.c new file +71 -0
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#include<asm/sizes.h>
+#include<linux/mtd/nand.h>
+
+#include "nand_device_info.h"
+
+static const struct nand_device_info samsung_nand[] = {
+	{
+		.id	= { 0xec, 0xd3, 0x14, 0x25, 0x64, 0xec, 0xd3, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9G8G08U0M, K9HAG08U1M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 1LL * SZ_1G, 128,
+				2 * SZ_1K + 64, 8, 512),
+	}, {
+		.id	= { 0xec, 0xd7, 0xd5, 0x29, 0x38, 0x41, 0xec, 0xd7 },
+		.id_len	= 8,
+		.desc	= "K9LBG08U0D",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 4LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		.id	= { 0xec, 0xd5, 0x14, 0xb6, 0x74, 0xec, 0xd5, 0x14 },
+		.id_len	= 8,
+		.desc	= "K9GAG08U0M",
+		.attr	= ATTR(MLC, NAND_BUSWIDTH_8, 2LL * SZ_1G, 128,
+				4 * SZ_1K + 218, 16, 512),
+	}, {
+		/* end of the table. */
+		.id	= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+	},
+};
+
+/* macro to get the id bytes */
+#define ID_GET_MFR_CODE(id)  ((id)[0])
+
+void nand_device_print_info(struct nand_device_info *info)
+{
+	unsigned    i;
+	const char  *mfr_name;
+	const char  *cell_technology_name;
+	uint64_t    chip_size;
+	const char  *chip_size_units;
+	unsigned    page_size;
+	unsigned    oob_size;
+	struct nand_attr *attr		=&info->attr;
+
+	/* Prepare the manufacturer name. */
+	mfr_name = "Unknown";
+	for (i = 0; nand_manuf_ids[i].id; i++) {
+		if (nand_manuf_ids[i].id == ID_GET_MFR_CODE(info->id)) {
+			mfr_name = nand_manuf_ids[i].name;
+			break;
+		}
+	}
+
+	/* Prepare the name of the cell technology. */
+	switch (attr->cell_technology) {
+	case SLC:
+		cell_technology_name = "SLC";
+		break;
+	case MLC:
+		cell_technology_name = "MLC";
+		break;
+	default:
Quoted 8 lines
Quoted 8 lines

drivers/mtd/nand/nand_device_info.c

Quoted 8 lines
drivers/mtd/nand/nand_device_info.c new file +8 -0
+		cell_technology_name = "Unknown";
+		break;
+	}
+
+	/* Prepare the chip size. */
+	if ((attr->chip_size_in_bytes>= SZ_1G)&&
+					!(attr->chip_size_in_bytes % SZ_1G)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t)

SZ_1G);

Quoted 4 lines
Quoted 4 lines

drivers/mtd/nand/nand_device_info.c

Quoted 4 lines
drivers/mtd/nand/nand_device_info.c new file +4 -0
+		chip_size_units = "GiB";
+	} else if ((attr->chip_size_in_bytes>= SZ_1M)&&
+					!(attr->chip_size_in_bytes % SZ_1M)) {
+		chip_size       = attr->chip_size_in_bytes / ((uint64_t)

SZ_1M);

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/mtd/nand/nand_device_info.c new file +10 -0
+		chip_size_units = "MiB";
+	} else {
+		chip_size       = attr->chip_size_in_bytes;
+		chip_size_units = "B";
+	}
+
+	/* Prepare the page geometry. */
+	page_size = (1<<   (fls(attr->page_total_size_in_bytes) - 1));
+	oob_size  = attr->page_total_size_in_bytes - page_size;
+
Quoted 8 lines
Quoted 8 lines

drivers/mtd/nand/nand_device_info.c

Quoted 8 lines
drivers/mtd/nand/nand_device_info.c new file +8 -0
+	/* Print the infomation. */
+	pr_info("--------------------------------------\n");
+	pr_info("	NAND device infomation (RAW)\n");
+	pr_info("--------------------------------------\n");
+	pr_info("Manufacturer      : %s (0x%02x)\n", mfr_name, info->id[0]);
+	pr_info("Device Code       : 0x%02x\n", info->id[1]);
+	pr_info("Cell Technology   : %s\n", cell_technology_name);
+	pr_info("Chip Size         : %llu %s\n", chip_size,

chip_size_units);

Quoted 77 lines
Quoted 3 lines

drivers/mtd/nand/nand_device_info.c

Quoted 3 lines
drivers/mtd/nand/nand_device_info.c new file +3 -0
+	pr_info("Pages per Block   : %u\n", attr->block_size_in_pages);
+	pr_info("Page Geometry     : %u+%u\n", page_size, oob_size);
+	pr_info("ECC Strength      : %u bits\n", attr-

ecc_strength_in_bits);

Quoted 73 lines
Quoted 73 lines
drivers/mtd/nand/nand_device_info.c new file +31 -0
+	pr_info("ECC Size          : %u B\n", attr->ecc_size_in_bytes);
+	pr_info("Description       : %s\n", info->desc);
+}
+
+static struct nand_device_info * __init
+search_table(const struct nand_device_info *table, const uint8_t id[])
+{
+	struct nand_device_info *info = (struct nand_device_info *)table;
+
+	while (ID_GET_MFR_CODE(info->id)) {
+		int i;
+
+		/* match all the valid id bytes. Is it too strict? */
+		for (i = 0; i<   info->id_len; i++)
+			if (info->id[i] != id[i])
+				break;
+
+		/* found it */
+		if (i == info->id_len)
+			return info;
+		info++;
+	}
+	return NULL;
+}
+
+struct nand_device_mfr_info {
+	uint8_t                  id;
+	const struct nand_device_info  *table;
+};
+
+static const struct nand_device_mfr_info  nand_device_mfr_directory[] =

{ + { NAND_MFR_SAMSUNG, samsung_nand },

drivers/mtd/nand/nand_device_info.c new file +18 -0
+	{ 0, NULL },
+};
+
+struct nand_device_info *nand_device_get_info(const uint8_t id[])
+{
+	uint8_t mfr_id = ID_GET_MFR_CODE(id);
+	unsigned i;
+
+	for (i = 0; nand_device_mfr_directory[i].id; i++) {
+		if (nand_device_mfr_directory[i].id == mfr_id) {
+			const struct nand_device_info  *table;
+
+			table = nand_device_mfr_directory[i].table;
+			return search_table(table, id);
+		}
+	}
+	return NULL;
+}
(quoted diff) +0 -0

b/drivers/mtd/nand/nand_device_info.h new file mode 100644 index 0000000..15f688d

drivers/mtd/nand/nand_device_info.h new file +17 -0
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+#ifndef __DRIVERS_NAND_DEVICE_INFO_H
+#define __DRIVERS_NAND_DEVICE_INFO_H
+
+enum nand_device_cell_technology {
+	SLC = 0,
Quoted 82 lines
Quoted 7 lines
Quoted 7 lines

drivers/mtd/nand/nand_device_info.h

Quoted 7 lines
drivers/mtd/nand/nand_device_info.h new file +7 -0
+	MLC = 1,
+};
+
+/**
+ * @cell_technology:		The storage cell technology.
+ * @busw:			The bus width of the NAND.
+ * @chip_size_in_bytes:		The total size of the storage behind a

single

Quoted 74 lines
Quoted 57 lines
Quoted 57 lines
drivers/mtd/nand/nand_device_info.h new file +5 -0
+ *				chip select, in bytes. Notice that this is *not*
+ *				necessarily the total size of the storage in a
+ *				*package*, which may contain several chips.
+ * @block_size_in_pages:	The number of pages in a block.
+ * @page_total_size_in_bytes:	The total size of a page, in bytes,

including + * both the data and the OOB.
+ * @ecc_strength_in_bits: The strength of the ECC called for by the
+ * manufacturer, in number of correctable bits.
+ * @ecc_size_in_bytes: The size of the data block over which the
+ * manufacturer calls for the given ECC algorithm
+ * and strength.
+ */

drivers/mtd/nand/nand_device_info.h new file +21 -0
+struct nand_attr {
+	/* Technology */
+	enum nand_device_cell_technology  cell_technology;
+
+	/* bus width */
+#define NAND_BUSWIDTH_8	0
+	uint32_t	busw;
+
+	/* Geometry */
+	uint64_t	chip_size_in_bytes;
+	uint32_t	block_size_in_pages;
+	uint32_t	page_total_size_in_bytes;
+
+	/* ECC */
+	uint16_t	ecc_strength_in_bits;
+	uint16_t	ecc_size_in_bytes;
+};
+
+#define ID_BYTES	(8)
+/*
+ * struct nand_device_info - Information about a single NAND Flash

device. + *
+ * This structure contains all the *essential* information about a NAND Flash + * device, derived from the device's data sheet.
+ */

drivers/mtd/nand/nand_device_info.h new file +20 -0
+struct nand_device_info {
+	/* id */
+	uint8_t			id[ID_BYTES];
+	unsigned int		id_len;
+
+	/* Description */
+	const char		*desc;
+
+	/* attribute*/
+	struct nand_attr	attr;
+};
+
+/* macro for the NAND attribute */
+#define ATTR(_a, _b, _c, _d, _e, _f, _g)		\
+	{						\
+		.cell_technology		= (_a),	\
+		.busw				= (_b),	\
+		.chip_size_in_bytes		= (_c),	\
+		.block_size_in_pages		= (_d),	\
+		.page_total_size_in_bytes	= (_e),	\
Quoted 8 lines
Quoted 8 lines
drivers/mtd/nand/nand_device_info.h new file +5 -0
+		.ecc_strength_in_bits		= (_f),	\
+		.ecc_size_in_bytes		= (_g),	\
+	}
+
+struct nand_device_info *nand_device_get_info(const uint8_t

id_bytes[]); +void nand_device_print_info(struct nand_device_info *info);
+#endif

Best Regards
Huang Shijie

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

Best Regards
Huang Shijie

#20 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

In reply to Huang Shijie

Hi,

Quoted 11 lines · Huang Shijie
Quoted 5 lines · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:
Quoted 1 line

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

yes.

But I will use the new database to replace the old one.

I will submit new patches to modify the generic code if my driver is accepted.

Sorry, but this is not how the opensource community works. The common practice everywhere in the kernel is that if the generic code/framework is too limiting, you first change the framework, then start using it. We do not do things like - I'll first create my custom solution, and then I promise I will change the framework.

Again, this is not just MTD, this is everywhere in the kernel. This is how linux goes forward - we force people to improve common code and accept their drivers, and everyone benefits form this. Yes, this is more work for you, of course, sorry :-)

Quoted 5 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Just add this information, if it is of generic nature (like SLC/MLC flag, required ECC strength, etc).

Quoted 6 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :(

Fix this please :-)

Quoted 2 lines

Paring the id bytes is not sufficient to get all the information you need which is faced by me.

Fix this too :-)

Quoted 1 line

What's more, I think the paring code is ugly, see the nand_get_flash_type().

You are welcome to fix this. There is _a lot_ of ugly code in MTD because no one loves it. Give it some love :-)

Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

You can create this database by extending/improving/cleaning up the existing code base with a nice series of patches.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (????? ????????)
#21 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

hi,

2011/3/31 Artem Bityutskiy <[email protected]>:

Quoted 12 lines

Hi,

Quoted 9 lines · Huang Shijie
Quoted 5 lines · On Wednesday 30 March 2011 10:40:10 Huang Shijie wrote:
Quoted 1 line

This is a new database for the NANDs which is searched by the id_bytes.

drivers/mtd//nand/nand_base.c will be able to detect all of your chips listed below based on the ids present in drivers/mtd/nand/nand_ids.c

yes.

But I will use the new database to replace the old one.

Quoted 9 lines
Quoted 2 lines

I will ?submit new patches to modify the generic code if my driver is accepted.

Sorry, but this is not how the opensource community works. The common practice everywhere in the kernel is that if the generic code/framework is too limiting, you first change the framework, then start using it. We do not do things like - I'll first create my custom solution, and then I promise I will change the framework.

got it.

Quoted 5 lines

Again, this is not just MTD, this is everywhere in the kernel. This is how linux goes forward - we force people to improve common code and accept their drivers, and everyone benefits form this. Yes, this is more work for you, of course, sorry :-)

thanks :)

Quoted 28 lines
Quoted 5 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure ?nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Just add this information, if it is of generic nature (like SLC/MLC flag, required ECC strength, etc).

Quoted 6 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :(

Fix this please :-)

Quoted 2 lines

Paring the id bytes is not sufficient to get all the information you need which is faced by me.

Fix this too :-)

Quoted 1 line

What's more, I think the paring code is ugly, see the nand_get_flash_type().

You are welcome to fix this. There is _a lot_ of ugly code in MTD because no one loves it. Give it some love :-)

Quoted 7 lines
Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

You can create this database by extending/improving/cleaning up the existing code base with a nice series of patches.

ok. I will try to fix the generic code before my driver is submitted.

Best Regards.

Quoted 5 lines

--
Best Regards,
Artem Bityutskiy (????? ????????)

#22 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hi,

I see nothing has happened with this thread recently. It doesn't deserve to die though.

Quoted 9 lines · Huang Shijie

2011/3/31 Artem Bityutskiy <[email protected]>:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure ?nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Just add this information, if it is of generic nature (like SLC/MLC flag, required ECC strength, etc).

Are SLC/MLC and ECC strength necessary to track? I don't see a good benefit to cost ratio of trying to detect ECC strength especially, since the levels specified in data sheets vary without much pattern and nobody provides a way for decoding this from ID; do you really want to have to make separate chip entries for every single chip that comes around?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :(

I may agree, but can you be more specific on the trap?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Paring the id bytes is not sufficient to get all the information you need which is faced by me.

What's an alternative to "paring the id bytes"?

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

What's more, I think the paring code is ugly, see the nand_get_flash_type().

You are welcome to fix this. There is _a lot_ of ugly code in MTD because no one loves it. Give it some love :-)

While I agree that a lot of this is ugly, it is mostly a matter of necessity. NAND manufacturers do not have a standard (ONFI doesn't really count, since there's basically 1 manufacturer using it), and so the most "generic" code is to have different code paths for different manufacturers (often with exceptions to each rule, since even a single manufacturer changes its standards arbitrarily). Then you find manufacturers like Toshiba that recently don't have any (published) pattern at all for detecting OOB size generically.

Thus, it seems to me like we will need some form of the approach provided by Huang. As I've found, there are some things that just can't be decoded from the ID these days, so our ID table will need to be able to track:
* full ID string (not just the 2nd byte "Device ID")
* relevant bad block scanning options

FWIW, we already implement an exception table in our own driver that includes the above 2 items, for chips that can't be handled with the table/detection structure as-is. We don't particularly need SLC/MLC but I don't object to recording it if we can determine it reliably, and while ECC level could be useful, it is difficult to discover generically, as I mentioned above.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

You can create this database by extending/improving/cleaning up the existing code base with a nice series of patches.

ok. I will try to fix the generic code before my driver is submitted.

What happened to this statement? I see that your driver was submitted, but no efforts were made for chip detection cleanup. Were you satisfied with the current detection?

While we're on the subject, I'll direct your attention to this NAND data table that I've worked on. It should provide a decent summary of most of the data sheets I have sorted through. It should also show you that certain things are going to be very hard to detect (e.g., ECC level). It should also show that while some chips are not supported by standard code (e.g., weird bad block scanning features that haven't been supported, non-standard OOB sizes with no given pattern in the datasheets), the vast majority of the chips I've come across should be detected properly:

http://linux-mtd.infradead.org/nand-data/nanddata.html

And of course, please contribute to
git://git.infradead.org/mtd-www.git if you have additions or edits for the table. It's not perfect, but it can help for sorting through different chips.

Brian

#23 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

Hi Brian:

Quoted 12 lines

Hi,

I see nothing has happened with this thread recently. It doesn't deserve to die though.

Quoted 6 lines · Huang Shijie

2011/3/31 Artem Bityutskiy<[email protected]>:

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Just add this information, if it is of generic nature (like SLC/MLC flag, required ECC strength, etc).

Are SLC/MLC and ECC strength necessary to track? I don't see a good benefit to cost ratio of trying to detect ECC strength especially, since the levels specified in data sheets vary without much pattern and nobody provides a way for decoding this from ID; do you really want to have to make separate chip entries for every single chip that comes around?

I do not need the SLC/MCL info. But i do need the ECC strength for the BCH. Currently i compute it myself based on the ECC chunk size to be 512 bytes. It's ok now.

But the ONFI nand MAYBE has its own requirements, such as some ONFI nand requires '24-bit ECC per 1080 bytes of data'(see MT29F64G08CBAAA,MT29F128G08CEAAA).
In this case, setting the ECC chunk size to 512 bytes maybe is not proper. It's better to
set the ECC chunk size to 1k, and set ECC strength to 24bit.

So, add the ECC strength to nand is worthful ( at least, it's useful for ONFI nand) .

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :(

I may agree, but can you be more specific on the trap?

I meant the parsing id code is not good.
Maybe i am wrong.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Paring the id bytes is not sufficient to get all the information you need which is faced by me.

What's an alternative to "paring the id bytes"?

I meant the the code can not get sufficient info for ONFI nand.

But the current code can parse out the info for ONFI nand now. though it does not parse out all the info.

Quoted 12 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

What's more, I think the paring code is ugly, see the nand_get_flash_type().

You are welcome to fix this. There is _a lot_ of ugly code in MTD because no one loves it. Give it some love :-)

While I agree that a lot of this is ugly, it is mostly a matter of necessity. NAND manufacturers do not have a standard (ONFI doesn't really count, since there's basically 1 manufacturer using it), and so the most "generic" code is to have different code paths for different manufacturers (often with exceptions to each rule, since even a single manufacturer changes its standards arbitrarily). Then you find manufacturers like Toshiba that recently don't have any (published) pattern at all for detecting OOB size generically.

Quoted 5 lines

Thus, it seems to me like we will need some form of the approach provided by Huang. As I've found, there are some things that just can't be decoded from the ID these days, so our ID table will need to be able to track:
* full ID string (not just the 2nd byte "Device ID")

The same idea as mine. :) I also thought it's better to store all the
ID bytes.

Quoted 9 lines

* relevant bad block scanning options

FWIW, we already implement an exception table in our own driver that includes the above 2 items, for chips that can't be handled with the table/detection structure as-is. We don't particularly need SLC/MLC but I don't object to recording it if we can determine it reliably, and while ECC level could be useful, it is difficult to discover generically, as I mentioned above.

at least the ECC strength is needed.

Quoted 10 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

You can create this database by extending/improving/cleaning up the existing code base with a nice series of patches.

ok. I will try to fix the generic code before my driver is submitted.

What happened to this statement? I see that your driver was submitted, but no efforts were made for chip detection cleanup. Were you satisfied with the current detection?

I am not satisfied with the current code.
I wish I could add the code to parsing out the ECC strength of ONFI, and something else.
But I have no time to do this. :(
feel bad.

Quoted 4 lines

While we're on the subject, I'll direct your attention to this NAND data table that I've worked on. It should provide a decent summary of most of the data sheets I have sorted through. It should also show you that certain things are going to be very hard to detect (e.g., ECC

only the ONFI nand's ECC strength is useful now. You can ignore the normal NANDs, i can compute it myself.

Quoted 8 lines

level). It should also show that while some chips are not supported by standard code (e.g., weird bad block scanning features that haven't been supported, non-standard OOB sizes with no given pattern in the datasheets), the vast majority of the chips I've come across should be detected properly:

http://linux-mtd.infradead.org/nand-data/nanddata.html

very good!

Huang Shijie

Quoted 7 lines

And of course, please contribute to
git://git.infradead.org/mtd-www.git if you have additions or edits for the table. It's not perfect, but it can help for sorting through different chips.

Brian

#24 lore raw

Re: [PATCH V3 3/6] MTD : add the database for the NANDs

In reply to Brian Norris

Hi Brian, Huang,

Sorry for the long email, but this topic also interests me.

Quoted 2 lines · Brian Norris

I see nothing has happened with this thread recently. It doesn't deserve to die though.

Having played around with the nand_ids.c and nand_get_flash_type(), I also think the approach is in need of a bit of an overhaul. The code is getting increasingly difficult to follow, given the growing number of non-standard decoding exceptions.

My first attempt was rather similar to Huang's -- using a static table of READIDs and extended device properties. However, this also gets rather complicated, and again needs to handle special cases. For example, early revisions of a NAND device often include 'don't care' bytes in the READID, or even just shorter READIDs. We could add a "matching-mask" to the table, and enforce some ordering to the binding process (e.g. bind against the first match in the table, or perhaps the most-specific match in the table?), but the semantics of the table-ordering is difficult to enforce, especially when new devices are added later. Using a static table also has other disadvantages, such as size and the need to continually update as new devices emerge (my list is now over 300 devices!).

I ended up refactoring the nand_get_flash_type() code, according to 3 basic schemes:

	'ID 2' : extract properties from nand_flash_ids[].  For 2-byte IDs, or

where device ID gives a non-zero page-size (particularly SP devices).

'Extended ID': decode properties from ID string where possible, falling
back to nand_flash_ids[]. For 3/4/5-byte IDs.

'ID 6' : decode properties from ID string where possible,
falling back to nand_flash_ids[]. For 6-byte IDs.

The refactoring was primarily aimed at simplifying the way in which decoding exceptions could be accommodated.

I have tested the code on the all the devices found in Brian's most excellent table:

Quoted 1 line

http://linux-mtd.infradead.org/nand-data/nanddata.html

with the following exceptions:
- ONFI-only devices: decode not possible using READID
- Multi-CS devices: probe must be repeated on each CS
- Toshiba devices: difficultly in acquiring the datasheets and the full
READID.

I have also added a few more devices and columns to the table (#CS, #LUNs, #RBn) which I hope to submit shortly.

I was working on a non-standard NAND driver at the time, which made little use of nand_base.c, and on an older 2.6.32 tree. However, if there is sufficient interest, I am happy at having a go at updating nand_get_flash_type() on mtd-2.6.

Let me know if you think this might be useful. Perhaps posting the standalone test code I used on nanddata.html (actually a csv version of the table!) would be a good start?

Cheers,

Angus

#25 lore raw

Re: [PATCH V3 3/6] MTD : add the database for the NANDs

Hi Huang, Angus (and anyone else interested in NAND ID decoding),

I have some responses to both Huang and Angus.

Huang:

Quoted 3 lines · Huang Shijie

I do not need the SLC/MCL info. But i do need the ECC strength for the BCH. Currently i compute it myself based on the ECC chunk size to be 512 bytes. It's ok now.

...

Quoted 2 lines

So, add the ECC strength to nand is worthful ( at least, it's useful for ONFI nand) .

For ONFI NAND, you can pull information from the ONFI parameter page (found in chip->onfi_params.ecc_bits) plus you need to read and decode the ECC information block. That's up to you to code and submit, though, which you haven't taken the time to do so far.

Quoted 8 lines
Quoted 5 lines

Thus, it seems to me like we will need some form of the approach provided by Huang. As I've found, there are some things that just can't be decoded from the ID these days, so our ID table will need to be able to track:
* full ID string (not just the 2nd byte "Device ID")

The same idea as mine. :) I also thought it's better to store all the ID
bytes.

We cannot store all the strings for all chips. I think Angus has a little better of an idea, discussed below.

Angus:

Quoted 8 lines · Angus CLARK
Quoted 2 lines · Brian Norris

I see nothing has happened with this thread recently. It doesn't deserve to die though.

Having played around with the nand_ids.c and nand_get_flash_type(), I also think the approach is in need of a bit of an overhaul.  The code is getting increasingly difficult to follow, given the growing number of non-standard decoding exceptions.

Personally, I've spent a lot of time verifying and using this code, so I don't have a particular problem with its difficulty. But if there are real improvements that are coupled with some reorganization for clarity, then I'm fine with it.

Quoted 2 lines

My first attempt was rather similar to Huang's -- using a static table of READIDs and extended device properties.

We cannot maintain a full static table of all chips.

Quoted 6 lines

We could add a
"matching-mask" to the table, and enforce some ordering to the binding process (e.g. bind against the first match in the table, or perhaps the most-specific match in the table?), but the semantics of the table-ordering is difficult to enforce, especially when new devices are added later.

I think it'd be easy enough to order chips in "specificity" order; for instance, divide the table (via comments) into 6-byte, 5-byte, 4-byte, 2-byte, etc. strings (similar to the current nand_ids.c table, where we section off the 256 Mbit, 512 Mbit, etc.)

Quoted 3 lines

Using a static table also has other disadvantages, such as size and the need to continually update as new devices emerge (my list is now over 300 devices!).

This is the key reason for the code as it stands. We try to write rules that limit the number of exceptions and prevent having to describe each and every device in a table. This is not possible for some chips/manufacturers, however, when they make no attempt to provide a pattern to their ID strings.

Quoted 11 lines

I ended up refactoring the nand_get_flash_type() code, according to 3 basic schemes:

       'ID 2' : extract properties from nand_flash_ids[].  For 2-byte IDs, or where device ID gives a non-zero page-size (particularly SP devices).

       'Extended ID': decode properties from ID string where possible, falling back to nand_flash_ids[].  For 3/4/5-byte IDs.

       'ID 6'       : decode properties from ID string where possible, falling back to nand_flash_ids[].  For 6-byte IDs.

As I see it, the only addition is the "ID 6" detection, correct? I think this is a good start, but it could use more flexibility than just a 6-byte string. Some 'exceptions' could have shorter or longer known strings. Perhaps this is where we can use the masking approach from above.

Quoted 2 lines

I have also added a few more devices and columns to the table (#CS, #LUNs, #RBn) which I hope to submit shortly.

Might be useful. Patch it against the CSV in mtd-www.git (nand-data/nanddata.csv) please.

Quoted 6 lines

I was working on a non-standard NAND driver at the time, which made little use of nand_base.c, and on an older 2.6.32 tree.  However, if there is sufficient interest, I am happy at having a go at updating nand_get_flash_type() on mtd-2.6.

Let me know if you think this might be useful.

Sure, it could be useful. It might be difficult to get everything right, but if you have working suggestions, please send patches! I think it's usually good to use l2-mtd-2.6 these days, since Artem does most of the day-to-day MTD patch tracking in his git tree.

Quoted 3 lines

 Perhaps posting the
standalone test code I used on nanddata.html (actually a csv version of the table!) would be a good start?

Perhaps. If you have an easily testable framework for validating against the CSV table from mtd-www.git, then it could be useful. Personally, I've used a combination of spreadsheet formulas and manual inspection to validate.

Brian

#26 lore raw

Re: [PATCH V3 3/6] MTD : add the database for the NANDs

Hi Brian,

Quoted 7 lines · Brian Norris
Quoted 3 lines

I have also added a few more devices and columns to the table (#CS, #LUNs, #RBn) which I hope to submit shortly.

Might be useful. Patch it against the CSV in mtd-www.git (nand-data/nanddata.csv) please.

Just about send the patches to the list...

Quoted 4 lines
Quoted 1 line

the table!) would be a good start?

Perhaps. If you have an easily testable framework for validating against the CSV table from mtd-www.git, then it could be useful.

I will update the test framework to work with the CSV table and post the result here... probably not until next week now...

Cheers,

Angus

#27 lore raw

PATCH v3 3/6 MTD : add the database for the NANDs

In reply to Brian Norris

Hi Brian:

Quoted 7 lines

Hi,

I see nothing has happened with this thread recently. It doesn't deserve to die though.

Quoted 1 line · Huang Shijie

2011/3/31 Artem Bityutskiy<[email protected]>:

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

If you have new chips to support in the future, you should add them in drivers/mtd/nand/nand_ids.c and not keep this file.

The data structure nand_flash_dev{} does not contain enough information. So I want to the nand_device_info{} to replace it in future.

Just add this information, if it is of generic nature (like SLC/MLC flag, required ECC strength, etc).

Are SLC/MLC and ECC strength necessary to track? I don't see a good

We do not necessary to track it. For normal nand, I can compute it myself ,
just as the current driver does; for ONFI nand ,we should parse it out from the Parameter Page.
It need an extra patch to do this.

Quoted 21 lines

benefit to cost ratio of trying to detect ECC strength especially, since the levels specified in data sheets vary without much pattern and nobody provides a way for decoding this from ID; do you really want to have to make separate chip entries for every single chip that comes around?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I still do not understand why this would be needed, is it because the generic code does not provide enough informations for your driver?

yes.

IMHO, the generic code is somehow trapped in a wrong way. :(

I may agree, but can you be more specific on the trap?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Paring the id bytes is not sufficient to get all the information you need which is faced by me.

What's an alternative to "paring the id bytes"?

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

What's more, I think the paring code is ugly, see the nand_get_flash_type().

You are welcome to fix this. There is _a lot_ of ugly code in MTD because no one loves it. Give it some love :-)

Quoted 8 lines

While I agree that a lot of this is ugly, it is mostly a matter of necessity. NAND manufacturers do not have a standard (ONFI doesn't really count, since there's basically 1 manufacturer using it), and so the most "generic" code is to have different code paths for different manufacturers (often with exceptions to each rule, since even a single manufacturer changes its standards arbitrarily). Then you find manufacturers like Toshiba that recently don't have any (published) pattern at all for detecting OOB size generically.

bad news. I do not have such chip yet, If i have , i will test it, and change the current MTD code.

Quoted 7 lines

Thus, it seems to me like we will need some form of the approach provided by Huang. As I've found, there are some things that just can't be decoded from the ID these days, so our ID table will need to be able to track:
* full ID string (not just the 2nd byte "Device ID")
* relevant bad block scanning options

Quoted 7 lines

FWIW, we already implement an exception table in our own driver that includes the above 2 items, for chips that can't be handled with the table/detection structure as-is. We don't particularly need SLC/MLC but I don't object to recording it if we can determine it reliably, and while ECC level could be useful, it is difficult to discover generically, as I mentioned above.

I do not use the SLC/MLC info now.

Quoted 10 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Why not create a new database which contains all the necessary information for a nand, and can be easy
find by the id bytes as the keyword?

You can create this database by extending/improving/cleaning up the existing code base with a nice series of patches.

ok. I will try to fix the generic code before my driver is submitted.

What happened to this statement? I see that your driver was submitted, but no efforts were made for chip detection cleanup. Were you satisfied with the current detection?

When i am free, I will change the current code. But i am a little busy now :(

Best Regards
Huang Shijie

Quoted 19 lines

While we're on the subject, I'll direct your attention to this NAND data table that I've worked on. It should provide a decent summary of most of the data sheets I have sorted through. It should also show you that certain things are going to be very hard to detect (e.g., ECC level). It should also show that while some chips are not supported by standard code (e.g., weird bad block scanning features that haven't been supported, non-standard OOB sizes with no given pattern in the datasheets), the vast majority of the chips I've come across should be detected properly:

http://linux-mtd.infradead.org/nand-data/nanddata.html

And of course, please contribute to
git://git.infradead.org/mtd-www.git if you have additions or edits for the table. It's not perfect, but it can help for sorting through different chips.

Brian

#28 lore raw

PATCH v3 4/6 MTD : add the common code for GPMI controller driver

In reply to Huang Shijie

These files contain the common code for the GPMI driver.

---
 drivers/mtd/nand/gpmi-nfc/gpmi-nfc-main.c | 2451 +++++++++++++++++++++++++++++
 drivers/mtd/nand/gpmi-nfc/gpmi-nfc.h      |  549 +++++++
 2 files changed, 3000 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-nfc-main.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-nfc.h
drivers/mtd/nand/gpmi-nfc/gpmi-nfc-main.c new file +2451 -0
new file mode 100644
index 0000000..ea7dfa7
@@ -0,0 +1,2451 @@
+/*
+ * Freescale GPMI NFC NAND Flash Driver
+ *
+ * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
+ * Copyright (C) 2008 Embedded Alley Solutions, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <linux/slab.h>
+#include "gpmi-nfc.h"
+
+/* add our owner bbt descriptor */
+static uint8_t scan_ff_pattern[] = { 0xff };
+static struct nand_bbt_descr gpmi_bbt_descr = {
+	.options	= 0,
+	.offs		= 0,
+	.len		= 1,
+	.pattern	= scan_ff_pattern
+};
+
+/* debug control */
+int gpmi_debug;
+
+static ssize_t show_gpmi_debug(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", gpmi_debug);
+}
+
+static ssize_t
+store_gpmi_debug(struct device *dev, struct device_attribute *attr,
+			const char *buf, size_t size)
+{
+	const char *p = buf;
+	unsigned long v;
+
+	if (strict_strtoul(p, 0, &v) < 0)
+		return size;
+
+	gpmi_debug = v;
+	return size;
+}
+
+static ssize_t show_ignorebad(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct gpmi_nfc_data  *this = dev_get_drvdata(dev);
+	struct mil            *mil  = &this->mil;
+
+	return sprintf(buf, "%d\n", mil->ignore_bad_block_marks);
+}
+
+/* Sets the value of the 'ignorebad' flag. */
+static ssize_t
+store_ignorebad(struct device *dev, struct device_attribute *attr,
+			const char *buf, size_t size)
+{
+	struct gpmi_nfc_data  *this = dev_get_drvdata(dev);
+	struct mil            *mil  = &this->mil;
+	const char            *p = buf;
+	unsigned long         v;
+
+	/* Try to make sense of what arrived from user space. */
+	if (strict_strtoul(p, 0, &v) < 0)
+		return size;
+
+	if (v > 0)
+		v = 1;
+
+	if (v != mil->ignore_bad_block_marks) {
+		if (v) {
+			/*
+			 * If control arrives here, we want to begin ignoring
+			 * bad block marks. Reach into the NAND Flash MTD data
+			 * structures and set the in-memory BBT pointer to NULL.
+			 * This will cause the NAND Flash MTD code to believe
+			 * that it never created a BBT and force it to call our
+			 * block_bad function.
+			 *
+			 * See mil_block_bad for more details.
+			 */
+			mil->saved_bbt = mil->nand.bbt;
+			mil->nand.bbt  = 0;
+		} else {
+			/*
+			 * If control arrives here, we want to stop ignoring
+			 * bad block marks. Restore the NAND Flash MTD's pointer
+			 * to its in-memory BBT.
+			 */
+			mil->nand.bbt = mil->saved_bbt;
+		}
+		mil->ignore_bad_block_marks = v;
+	}
+	return size;
+}
+
+/* Device attributes that appear in sysfs. */
+static DEVICE_ATTR(ignorebad, 0644, show_ignorebad, store_ignorebad);
+static DEVICE_ATTR(gpmi_debug, 0644, show_gpmi_debug, store_gpmi_debug);
+static struct device_attribute *device_attributes[] = {
+	&dev_attr_ignorebad,
+	&dev_attr_gpmi_debug,
+};
+
+irqreturn_t bch_irq(int irq, void *cookie)
+{
+	struct gpmi_nfc_data  *this = cookie;
+	struct nfc_hal        *nfc  = this->nfc;
+
+	/* Clear the BCH interrupt */
+	nfc->clear_bch(this);
+
+	complete(&nfc->bch_done);
+	return IRQ_HANDLED;
+}
+
+/* get the ECC strength */
+static inline int get_ecc_strength(struct gpmi_nfc_data *this)
+{
+	return this->device_info.attr.ecc_strength_in_bits;
+}
+
+static inline int get_ecc_chunk_size(struct gpmi_nfc_data *this)
+{
+	return this->device_info.attr.ecc_size_in_bytes;
+}
+
+static inline bool is_ddr_nand(struct nand_chip *chip)
+{
+	return chip->onfi_version != 0;
+}
+
+int common_nfc_set_geometry(struct gpmi_nfc_data *this)
+{
+	struct nfc_geometry       *geo = &this->nfc_geometry;
+	struct boot_rom_helper    *rom =  this->rom;
+	struct mtd_info		  *mtd = &this->mil.mtd;
+	struct nand_chip	*chip = &this->mil.nand;
+	unsigned int              metadata_size;
+	unsigned int              status_size;
+	unsigned int              chunk_data_size_in_bits;
+	unsigned int              chunk_ecc_size_in_bits;
+	unsigned int              chunk_total_size_in_bits;
+	unsigned int              block_mark_chunk_number;
+	unsigned int              block_mark_chunk_bit_offset;
+	unsigned int              block_mark_bit_offset;
+
+	/* We only support BCH now. */
+	geo->ecc_algorithm = "BCH";
+
+	/*
+	 * We always choose a metadata size of 10. Don't try to make sense of
+	 * it -- this is really only for historical compatibility.
+	 */
+	geo->metadata_size_in_bytes = 10;
+
+	/* ECC chunks */
+	geo->ecc_chunk_size_in_bytes = get_ecc_chunk_size(this);
+
+	/*
+	 * Compute the total number of ECC chunks in a page. This includes the
+	 * slightly larger chunk at the beginning of the page, which contains
+	 * both data and metadata.
+	 */
+	geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size_in_bytes;
+
+	/*
+	 * We use the same ECC strength for all chunks, including the first one.
+	 */
+	geo->ecc_strength = get_ecc_strength(this);
+	if (!geo->ecc_strength) {
+		log("Unsupported page geometry.");
+		return -EINVAL;
+	}
+
+	/* Compute the page size, include page and oob. */
+	geo->page_size_in_bytes = mtd->writesize + mtd->oobsize;
+
+	/*
+	 * ONFI/TOGGLE nand needs GF14, so re-culculate DMA page size.
+	 * The ONFI nand must do the reculation,
+	 * else it will fail in DMA in some platform(such as imx50).
+	 */
+	if (is_ddr_nand(chip))
+		geo->page_size_in_bytes = mtd->writesize +
+				geo->metadata_size_in_bytes +
+			(geo->ecc_strength * 14 * 8 / geo->ecc_chunk_count);
+
+	/*
+	 * The payload buffer contains the data area of a page. The ECC engine
+	 * only needs what's required to hold the data.
+	 */
+	geo->payload_size_in_bytes = mtd->writesize;
+
+	/*
+	 * In principle, computing the auxiliary buffer geometry is NFC
+	 * version-specific. However, at this writing, all versions share the
+	 * same model, so this code can also be shared.
+	 *
+	 * The auxiliary buffer contains the metadata and the ECC status. The
+	 * metadata is padded to the nearest 32-bit boundary. The ECC status
+	 * contains one byte for every ECC chunk, and is also padded to the
+	 * nearest 32-bit boundary.
+	 */
+	metadata_size = (geo->metadata_size_in_bytes + 0x3) & ~0x3;
+	status_size   = (geo->ecc_chunk_count        + 0x3) & ~0x3;
+
+	geo->auxiliary_size_in_bytes = metadata_size + status_size;
+	geo->auxiliary_status_offset = metadata_size;
+
+	/* Check if we're going to do block mark swapping. */
+	if (!rom->swap_block_mark)
+		return 0;
+
+	/*
+	 * If control arrives here, we're doing block mark swapping, so we need
+	 * to compute the byte and bit offsets of the physical block mark within
+	 * the ECC-based view of the page data. In principle, this isn't a
+	 * difficult computation -- but it's very important and it's easy to get
+	 * it wrong, so we do it carefully.
+	 *
+	 * Note that this calculation is simpler because we use the same ECC
+	 * strength for all chunks, including the zero'th one, which contains
+	 * the metadata. The calculation would be slightly more complicated
+	 * otherwise.
+	 *
+	 * We start by computing the physical bit offset of the block mark. We
+	 * then subtract the number of metadata and ECC bits appearing before
+	 * the mark to arrive at its bit offset within the data alone.
+	 */
+
+	/* Compute some important facts about chunk geometry. */
+	chunk_data_size_in_bits = geo->ecc_chunk_size_in_bytes * 8;
+
+	/* ONFI/TOGGLE nand needs GF14 */
+	if (is_ddr_nand(chip))
+		chunk_ecc_size_in_bits  = geo->ecc_strength * 14;
+	else
+		chunk_ecc_size_in_bits  = geo->ecc_strength * 13;
+
+	chunk_total_size_in_bits =
+			chunk_data_size_in_bits + chunk_ecc_size_in_bits;
+
+	/* Compute the bit offset of the block mark within the physical page. */
+	block_mark_bit_offset = mtd->writesize * 8;
+
+	/* Subtract the metadata bits. */
+	block_mark_bit_offset -= geo->metadata_size_in_bytes * 8;
+
+	/*
+	 * Compute the chunk number (starting at zero) in which the block mark
+	 * appears.
+	 */
+	block_mark_chunk_number =
+			block_mark_bit_offset / chunk_total_size_in_bits;
+
+	/*
+	 * Compute the bit offset of the block mark within its chunk, and
+	 * validate it.
+	 */
+	block_mark_chunk_bit_offset =
+		block_mark_bit_offset -
+			(block_mark_chunk_number * chunk_total_size_in_bits);
+
+	if (block_mark_chunk_bit_offset > chunk_data_size_in_bits) {
+		/*
+		 * If control arrives here, the block mark actually appears in
+		 * the ECC bits of this chunk. This wont' work.
+		 */
+		log("Unsupported page geometry (block mark in ECC): %u:%u",
+					mtd->writesize, mtd->oobsize);
+		return !0;
+	}
+
+	/*
+	 * Now that we know the chunk number in which the block mark appears,
+	 * we can subtract all the ECC bits that appear before it.
+	 */
+	block_mark_bit_offset -=
+			block_mark_chunk_number * chunk_ecc_size_in_bits;
+
+	/*
+	 * We now know the absolute bit offset of the block mark within the
+	 * ECC-based data. We can now compute the byte offset and the bit
+	 * offset within the byte.
+	 */
+	geo->block_mark_byte_offset = block_mark_bit_offset / 8;
+	geo->block_mark_bit_offset  = block_mark_bit_offset % 8;
+
+	return 0;
+}
+
+struct dma_chan *get_dma_chan(struct gpmi_nfc_data *this)
+{
+	int chip = this->mil.current_chip;
+
+	BUG_ON(chip < 0);
+	return this->dma_chans[chip];
+}
+
+/* Can we use the upper's buffer directly for DMA? */
+void prepare_data_dma(struct gpmi_nfc_data *this, enum dma_data_direction dr)
+{
+	struct mil *mil = &this->mil;
+	struct scatterlist *sgl = &mil->data_sgl;
+	int ret;
+
+	mil->direct_dma_map_ok = true;
+
+	/* first try to map the upper buffer directly */
+	sg_init_one(sgl, mil->upper_buf, mil->upper_len);
+	ret = dma_map_sg(this->dev, sgl, 1, dr);
+	if (ret == 0) {
+		/* We have to use our own DMA buffer. */
+		sg_init_one(sgl, mil->data_buffer_dma, PAGE_SIZE);
+
+		if (dr == DMA_TO_DEVICE)
+			memcpy(mil->data_buffer_dma, mil->upper_buf,
+				mil->upper_len);
+
+		ret = dma_map_sg(this->dev, sgl, 1, dr);
+		BUG_ON(ret == 0);
+
+		mil->direct_dma_map_ok = false;
+	}
+}
+
+/* This will be called after the DMA operation is finished. */
+static void dma_irq_callback(void *param)
+{
+	struct gpmi_nfc_data *this = param;
+	struct nfc_hal *nfc = this->nfc;
+	struct mil *mil = &this->mil;
+
+	complete(&nfc->dma_done);
+
+	switch (this->dma_type) {
+	case DMA_FOR_COMMAND:
+		dma_unmap_sg(this->dev, &mil->cmd_sgl, 1, DMA_TO_DEVICE);
+		break;
+
+	case DMA_FOR_READ_DATA:
+		dma_unmap_sg(this->dev, &mil->data_sgl, 1, DMA_FROM_DEVICE);
+		if (mil->direct_dma_map_ok == false)
+			memcpy(mil->upper_buf, (char *)mil->data_buffer_dma,
+				mil->upper_len);
+		break;
+
+	case DMA_FOR_WRITE_DATA:
+		dma_unmap_sg(this->dev, &mil->data_sgl, 1, DMA_TO_DEVICE);
+		break;
+
+	case DMA_FOR_READ_ECC_PAGE:
+	case DMA_FOR_WRITE_ECC_PAGE:
+		/* We have to wait the BCH interrupt to finish. */
+		break;
+
+	default:
+		BUG();
+	}
+}
+
+int start_dma_without_bch_irq(struct gpmi_nfc_data *this,
+				struct dma_async_tx_descriptor *desc)
+{
+	struct nfc_hal *nfc = this->nfc;
+	int err;
+
+	init_completion(&nfc->dma_done);
+
+	desc->callback		= dma_irq_callback;
+	desc->callback_param	= this;
+	dmaengine_submit(desc);
+
+	/* Wait for the interrupt from the DMA block. */
+	err = wait_for_completion_timeout(&nfc->dma_done,
+					msecs_to_jiffies(1000));
+	err = (!err) ? -ETIMEDOUT : 0;
+	if (err)
+		log("DMA timeout!!!");
+	return err;
+}
+
+/*
+ * This function is used in BCH reading or BCH writing pages.
+ * It will wait for the BCH interrupt as long as ONE second.
+ * Actually, we must wait for two interrupts :
+ *	[1] firstly the DMA interrupt and
+ *	[2] secondly the BCH interrupt.
+ *
+ * @this:	Per-device data structure.
+ * @desc:	DMA channel
+ */
+int start_dma_with_bch_irq(struct gpmi_nfc_data *this,
+			struct dma_async_tx_descriptor *desc)
+{
+	struct nfc_hal *nfc = this->nfc;
+	int err;
+
+	/* Prepare to receive an interrupt from the BCH block. */
+	init_completion(&nfc->bch_done);
+
+	/* start the DMA */
+	start_dma_without_bch_irq(this, desc);
+
+	/* Wait for the interrupt from the BCH block. */
+	err = wait_for_completion_timeout(&nfc->bch_done,
+					msecs_to_jiffies(1000));
+	err = (!err) ? -ETIMEDOUT : 0;
+	if (err)
+		log("bch timeout!!!");
+	return err;
+}
+
+/**
+ * ns_to_cycles - Converts time in nanoseconds to cycles.
+ *
+ * @ntime:   The time, in nanoseconds.
+ * @period:  The cycle period, in nanoseconds.
+ * @min:     The minimum allowable number of cycles.
+ */
+static unsigned int ns_to_cycles(unsigned int time,
+					unsigned int period, unsigned int min)
+{
+	unsigned int k;
+
+	/*
+	 * Compute the minimum number of cycles that entirely contain the
+	 * given time.
+	 */
+	k = (time + period - 1) / period;
+	return max(k, min);
+}
+
+/**
+ * gpmi_compute_hardware_timing - Apply timing to current hardware conditions.
+ *
+ * @this:             Per-device data.
+ * @hardware_timing:  A pointer to a hardware timing structure that will receive
+ *                    the results of our calculations.
+ */
+int gpmi_nfc_compute_hardware_timing(struct gpmi_nfc_data *this,
+					struct gpmi_nfc_hardware_timing *hw)
+{
+	struct gpmi_nfc_platform_data  *pdata	=  this->pdata;
+	struct nfc_hal                 *nfc	=  this->nfc;
+	struct nand_chip		*nand	= &this->mil.nand;
+	struct nand_timing		target	= nfc->timing;
+	bool           improved_timing_is_available;
+	unsigned long  clock_frequency_in_hz;
+	unsigned int   clock_period_in_ns;
+	bool           dll_use_half_periods;
+	unsigned int   dll_delay_shift;
+	unsigned int   max_sample_delay_in_ns;
+	unsigned int   address_setup_in_cycles;
+	unsigned int   data_setup_in_ns;
+	unsigned int   data_setup_in_cycles;
+	unsigned int   data_hold_in_cycles;
+	int            ideal_sample_delay_in_ns;
+	unsigned int   sample_delay_factor;
+	int            tEYE;
+	unsigned int   min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
+	unsigned int   max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
+
+	/*
+	 * If there are multiple chips, we need to relax the timings to allow
+	 * for signal distortion due to higher capacitance.
+	 */
+	if (nand->numchips > 2) {
+		target.data_setup_in_ns    += 10;
+		target.data_hold_in_ns     += 10;
+		target.address_setup_in_ns += 10;
+	} else if (nand->numchips > 1) {
+		target.data_setup_in_ns    += 5;
+		target.data_hold_in_ns     += 5;
+		target.address_setup_in_ns += 5;
+	}
+
+	/* Check if improved timing information is available. */
+	improved_timing_is_available =
+		(target.tREA_in_ns  >= 0) &&
+		(target.tRLOH_in_ns >= 0) &&
+		(target.tRHOH_in_ns >= 0) ;
+
+	/* Inspect the clock. */
+	clock_frequency_in_hz = nfc->clock_frequency_in_hz;
+	clock_period_in_ns    = 1000000000 / clock_frequency_in_hz;
+
+	/*
+	 * The NFC quantizes setup and hold parameters in terms of clock cycles.
+	 * Here, we quantize the setup and hold timing parameters to the
+	 * next-highest clock period to make sure we apply at least the
+	 * specified times.
+	 *
+	 * For data setup and data hold, the hardware interprets a value of zero
+	 * as the largest possible delay. This is not what's intended by a zero
+	 * in the input parameter, so we impose a minimum of one cycle.
+	 */
+	data_setup_in_cycles    = ns_to_cycles(target.data_setup_in_ns,
+							clock_period_in_ns, 1);
+	data_hold_in_cycles     = ns_to_cycles(target.data_hold_in_ns,
+							clock_period_in_ns, 1);
+	address_setup_in_cycles = ns_to_cycles(target.address_setup_in_ns,
+							clock_period_in_ns, 0);
+
+	/*
+	 * The clock's period affects the sample delay in a number of ways:
+	 *
+	 * (1) The NFC HAL tells us the maximum clock period the sample delay
+	 *     DLL can tolerate. If the clock period is greater than half that
+	 *     maximum, we must configure the DLL to be driven by half periods.
+	 *
+	 * (2) We need to convert from an ideal sample delay, in ns, to a
+	 *     "sample delay factor," which the NFC uses. This factor depends on
+	 *     whether we're driving the DLL with full or half periods.
+	 *     Paraphrasing the reference manual:
+	 *
+	 *         AD = SDF x 0.125 x RP
+	 *
+	 * where:
+	 *
+	 *     AD   is the applied delay, in ns.
+	 *     SDF  is the sample delay factor, which is dimensionless.
+	 *     RP   is the reference period, in ns, which is a full clock period
+	 *          if the DLL is being driven by full periods, or half that if
+	 *          the DLL is being driven by half periods.
+	 *
+	 * Let's re-arrange this in a way that's more useful to us:
+	 *
+	 *                        8
+	 *         SDF  =  AD x ----
+	 *                       RP
+	 *
+	 * The reference period is either the clock period or half that, so this
+	 * is:
+	 *
+	 *                        8       AD x DDF
+	 *         SDF  =  AD x -----  =  --------
+	 *                      f x P        P
+	 *
+	 * where:
+	 *
+	 *       f  is 1 or 1/2, depending on how we're driving the DLL.
+	 *       P  is the clock period.
+	 *     DDF  is the DLL Delay Factor, a dimensionless value that
+	 *          incorporates all the constants in the conversion.
+	 *
+	 * DDF will be either 8 or 16, both of which are powers of two. We can
+	 * reduce the cost of this conversion by using bit shifts instead of
+	 * multiplication or division. Thus:
+	 *
+	 *                 AD << DDS
+	 *         SDF  =  ---------
+	 *                     P
+	 *
+	 *     or
+	 *
+	 *         AD  =  (SDF >> DDS) x P
+	 *
+	 * where:
+	 *
+	 *     DDS  is the DLL Delay Shift, the logarithm to base 2 of the DDF.
+	 */
+	if (clock_period_in_ns > (nfc->max_dll_clock_period_in_ns >> 1)) {
+		dll_use_half_periods = true;
+		dll_delay_shift      = 3 + 1;
+	} else {
+		dll_use_half_periods = false;
+		dll_delay_shift      = 3;
+	}
+
+	/*
+	 * Compute the maximum sample delay the NFC allows, under current
+	 * conditions. If the clock is running too slowly, no sample delay is
+	 * possible.
+	 */
+	if (clock_period_in_ns > nfc->max_dll_clock_period_in_ns)
+		max_sample_delay_in_ns = 0;
+	else {
+		/*
+		 * Compute the delay implied by the largest sample delay factor
+		 * the NFC allows.
+		 */
+		max_sample_delay_in_ns =
+			(nfc->max_sample_delay_factor * clock_period_in_ns) >>
+								dll_delay_shift;
+
+		/*
+		 * Check if the implied sample delay larger than the NFC
+		 * actually allows.
+		 */
+		if (max_sample_delay_in_ns > nfc->max_dll_delay_in_ns)
+			max_sample_delay_in_ns = nfc->max_dll_delay_in_ns;
+	}
+
+	/*
+	 * Check if improved timing information is available. If not, we have to
+	 * use a less-sophisticated algorithm.
+	 */
+	if (!improved_timing_is_available) {
+		/*
+		 * Fold the read setup time required by the NFC into the ideal
+		 * sample delay.
+		 */
+		ideal_sample_delay_in_ns = target.gpmi_sample_delay_in_ns +
+						nfc->internal_data_setup_in_ns;
+
+		/*
+		 * The ideal sample delay may be greater than the maximum
+		 * allowed by the NFC. If so, we can trade off sample delay time
+		 * for more data setup time.
+		 *
+		 * In each iteration of the following loop, we add a cycle to
+		 * the data setup time and subtract a corresponding amount from
+		 * the sample delay until we've satisified the constraints or
+		 * can't do any better.
+		 */
+		while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
+			(data_setup_in_cycles < nfc->max_data_setup_cycles)) {
+
+			data_setup_in_cycles++;
+			ideal_sample_delay_in_ns -= clock_period_in_ns;
+
+			if (ideal_sample_delay_in_ns < 0)
+				ideal_sample_delay_in_ns = 0;
+
+		}
+
+		/*
+		 * Compute the sample delay factor that corresponds most closely
+		 * to the ideal sample delay. If the result is too large for the
+		 * NFC, use the maximum value.
+		 *
+		 * Notice that we use the ns_to_cycles function to compute the
+		 * sample delay factor. We do this because the form of the
+		 * computation is the same as that for calculating cycles.
+		 */
+		sample_delay_factor =
+			ns_to_cycles(
+				ideal_sample_delay_in_ns << dll_delay_shift,
+							clock_period_in_ns, 0);
+
+		if (sample_delay_factor > nfc->max_sample_delay_factor)
+			sample_delay_factor = nfc->max_sample_delay_factor;
+
+		/* Skip to the part where we return our results. */
+		goto return_results;
+	}
+
+	/*
+	 * If control arrives here, we have more detailed timing information,
+	 * so we can use a better algorithm.
+	 */
+
+	/*
+	 * Fold the read setup time required by the NFC into the maximum
+	 * propagation delay.
+	 */
+	max_prop_delay_in_ns += nfc->internal_data_setup_in_ns;
+
+	/*
+	 * Earlier, we computed the number of clock cycles required to satisfy
+	 * the data setup time. Now, we need to know the actual nanoseconds.
+	 */
+	data_setup_in_ns = clock_period_in_ns * data_setup_in_cycles;
+
+	/*
+	 * Compute tEYE, the width of the data eye when reading from the NAND
+	 * Flash. The eye width is fundamentally determined by the data setup
+	 * time, perturbed by propagation delays and some characteristics of the
+	 * NAND Flash device.
+	 *
+	 * start of the eye = max_prop_delay + tREA
+	 * end of the eye   = min_prop_delay + tRHOH + data_setup
+	 */
+	tEYE = (int)min_prop_delay_in_ns + (int)target.tRHOH_in_ns +
+							(int)data_setup_in_ns;
+
+	tEYE -= (int)max_prop_delay_in_ns + (int)target.tREA_in_ns;
+
+	/*
+	 * The eye must be open. If it's not, we can try to open it by
+	 * increasing its main forcer, the data setup time.
+	 *
+	 * In each iteration of the following loop, we increase the data setup
+	 * time by a single clock cycle. We do this until either the eye is
+	 * open or we run into NFC limits.
+	 */
+	while ((tEYE <= 0) &&
+			(data_setup_in_cycles < nfc->max_data_setup_cycles)) {
+		/* Give a cycle to data setup. */
+		data_setup_in_cycles++;
+		/* Synchronize the data setup time with the cycles. */
+		data_setup_in_ns += clock_period_in_ns;
+		/* Adjust tEYE accordingly. */
+		tEYE += clock_period_in_ns;
+	}
+
+	/*
+	 * When control arrives here, the eye is open. The ideal time to sample
+	 * the data is in the center of the eye:
+	 *
+	 *     end of the eye + start of the eye
+	 *     ---------------------------------  -  data_setup
+	 *                    2
+	 *
+	 * After some algebra, this simplifies to the code immediately below.
+	 */
+	ideal_sample_delay_in_ns =
+		((int)max_prop_delay_in_ns +
+			(int)target.tREA_in_ns +
+				(int)min_prop_delay_in_ns +
+					(int)target.tRHOH_in_ns -
+						(int)data_setup_in_ns) >> 1;
+
+	/*
+	 * The following figure illustrates some aspects of a NAND Flash read:
+	 *
+	 *
+	 *           __                   _____________________________________
+	 * RDN         \_________________/
+	 *
+	 *                                         <---- tEYE ----->
+	 *                                        /-----------------\
+	 * Read Data ----------------------------<                   >---------
+	 *                                        \-----------------/
+	 *             ^                 ^                 ^              ^
+	 *             |                 |                 |              |
+	 *             |<--Data Setup -->|<--Delay Time -->|              |
+	 *             |                 |                 |              |
+	 *             |                 |                                |
+	 *             |                 |<--   Quantized Delay Time   -->|
+	 *             |                 |                                |
+	 *
+	 *
+	 * We have some issues we must now address:
+	 *
+	 * (1) The *ideal* sample delay time must not be negative. If it is, we
+	 *     jam it to zero.
+	 *
+	 * (2) The *ideal* sample delay time must not be greater than that
+	 *     allowed by the NFC. If it is, we can increase the data setup
+	 *     time, which will reduce the delay between the end of the data
+	 *     setup and the center of the eye. It will also make the eye
+	 *     larger, which might help with the next issue...
+	 *
+	 * (3) The *quantized* sample delay time must not fall either before the
+	 *     eye opens or after it closes (the latter is the problem
+	 *     illustrated in the above figure).
+	 */
+
+	/* Jam a negative ideal sample delay to zero. */
+	if (ideal_sample_delay_in_ns < 0)
+		ideal_sample_delay_in_ns = 0;
+
+	/*
+	 * Extend the data setup as needed to reduce the ideal sample delay
+	 * below the maximum permitted by the NFC.
+	 */
+	while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
+			(data_setup_in_cycles < nfc->max_data_setup_cycles)) {
+
+		/* Give a cycle to data setup. */
+		data_setup_in_cycles++;
+		/* Synchronize the data setup time with the cycles. */
+		data_setup_in_ns += clock_period_in_ns;
+		/* Adjust tEYE accordingly. */
+		tEYE += clock_period_in_ns;
+
+		/*
+		 * Decrease the ideal sample delay by one half cycle, to keep it
+		 * in the middle of the eye.
+		 */
+		ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
+
+		/* Jam a negative ideal sample delay to zero. */
+		if (ideal_sample_delay_in_ns < 0)
+			ideal_sample_delay_in_ns = 0;
+	}
+
+	/*
+	 * Compute the sample delay factor that corresponds to the ideal sample
+	 * delay. If the result is too large, then use the maximum allowed
+	 * value.
+	 *
+	 * Notice that we use the ns_to_cycles function to compute the sample
+	 * delay factor. We do this because the form of the computation is the
+	 * same as that for calculating cycles.
+	 */
+	sample_delay_factor =
+		ns_to_cycles(ideal_sample_delay_in_ns << dll_delay_shift,
+							clock_period_in_ns, 0);
+
+	if (sample_delay_factor > nfc->max_sample_delay_factor)
+		sample_delay_factor = nfc->max_sample_delay_factor;
+
+	/*
+	 * These macros conveniently encapsulate a computation we'll use to
+	 * continuously evaluate whether or not the data sample delay is inside
+	 * the eye.
+	 */
+	#define IDEAL_DELAY  ((int) ideal_sample_delay_in_ns)
+
+	#define QUANTIZED_DELAY  \
+		((int) ((sample_delay_factor * clock_period_in_ns) >> \
+							dll_delay_shift))
+
+	#define DELAY_ERROR  (abs(QUANTIZED_DELAY - IDEAL_DELAY))
+
+	#define SAMPLE_IS_NOT_WITHIN_THE_EYE  (DELAY_ERROR > (tEYE >> 1))
+
+	/*
+	 * While the quantized sample time falls outside the eye, reduce the
+	 * sample delay or extend the data setup to move the sampling point back
+	 * toward the eye. Do not allow the number of data setup cycles to
+	 * exceed the maximum allowed by the NFC.
+	 */
+	while (SAMPLE_IS_NOT_WITHIN_THE_EYE &&
+			(data_setup_in_cycles < nfc->max_data_setup_cycles)) {
+		/*
+		 * If control arrives here, the quantized sample delay falls
+		 * outside the eye. Check if it's before the eye opens, or after
+		 * the eye closes.
+		 */
+		if (QUANTIZED_DELAY > IDEAL_DELAY) {
+			/*
+			 * If control arrives here, the quantized sample delay
+			 * falls after the eye closes. Decrease the quantized
+			 * delay time and then go back to re-evaluate.
+			 */
+			if (sample_delay_factor != 0)
+				sample_delay_factor--;
+			continue;
+		}
+
+		/*
+		 * If control arrives here, the quantized sample delay falls
+		 * before the eye opens. Shift the sample point by increasing
+		 * data setup time. This will also make the eye larger.
+		 */
+
+		/* Give a cycle to data setup. */
+		data_setup_in_cycles++;
+		/* Synchronize the data setup time with the cycles. */
+		data_setup_in_ns += clock_period_in_ns;
+		/* Adjust tEYE accordingly. */
+		tEYE += clock_period_in_ns;
+
+		/*
+		 * Decrease the ideal sample delay by one half cycle, to keep it
+		 * in the middle of the eye.
+		 */
+		ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
+
+		/* ...and one less period for the delay time. */
+		ideal_sample_delay_in_ns -= clock_period_in_ns;
+
+		/* Jam a negative ideal sample delay to zero. */
+		if (ideal_sample_delay_in_ns < 0)
+			ideal_sample_delay_in_ns = 0;
+
+		/*
+		 * We have a new ideal sample delay, so re-compute the quantized
+		 * delay.
+		 */
+		sample_delay_factor =
+			ns_to_cycles(
+				ideal_sample_delay_in_ns << dll_delay_shift,
+							clock_period_in_ns, 0);
+
+		if (sample_delay_factor > nfc->max_sample_delay_factor)
+			sample_delay_factor = nfc->max_sample_delay_factor;
+	}
+
+	/* Control arrives here when we're ready to return our results. */
+return_results:
+	hw->data_setup_in_cycles    = data_setup_in_cycles;
+	hw->data_hold_in_cycles     = data_hold_in_cycles;
+	hw->address_setup_in_cycles = address_setup_in_cycles;
+	hw->use_half_periods        = dll_use_half_periods;
+	hw->sample_delay_factor     = sample_delay_factor;
+
+	/* Return success. */
+	return 0;
+}
+
+int gpmi_nfc_rom_helper_set_geometry(struct gpmi_nfc_data *this)
+{
+	struct boot_rom_geometry  *geometry = &this->rom_geometry;
+
+	/*
+	 * Set the boot block stride size.
+	 *
+	 * In principle, we should be reading this from the OTP bits, since
+	 * that's where the ROM is going to get it. In fact, we don't have any
+	 * way to read the OTP bits, so we go with the default and hope for the
+	 * best.
+	 */
+	geometry->stride_size_in_pages = 64;
+
+	/*
+	 * Set the search area stride exponent.
+	 *
+	 * In principle, we should be reading this from the OTP bits, since
+	 * that's where the ROM is going to get it. In fact, we don't have any
+	 * way to read the OTP bits, so we go with the default and hope for the
+	 * best.
+	 */
+	geometry->search_area_stride_exponent = 2;
+
+	return 0;
+}
+
+static int acquire_register_block(struct gpmi_nfc_data *this,
+			const char *resource_name, void **reg_block_base)
+{
+	struct platform_device  *pdev = this->pdev;
+	struct resource         *r;
+	void                    *p;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, resource_name);
+	if (!r) {
+		log("Can't get resource information for '%s'", resource_name);
+		return -ENXIO;
+	}
+
+	/* remap the register block */
+	p = ioremap(r->start, resource_size(r));
+	if (!p) {
+		log("Can't remap %s", resource_name);
+		return -ENOMEM;
+	}
+
+	*reg_block_base = p;
+	return 0;
+}
+
+static void release_register_block(struct gpmi_nfc_data *this,
+				void *reg_block_base)
+{
+	iounmap(reg_block_base);
+}
+
+static int acquire_interrupt(struct gpmi_nfc_data *this,
+			const char *resource_name,
+			irq_handler_t interrupt_handler, int *lno, int *hno)
+{
+	struct platform_device  *pdev = this->pdev;
+	struct resource         *r;
+	int                     err;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, resource_name);
+	if (!r) {
+		log("Can't get resource information for '%s'", resource_name);
+		return -ENXIO;
+	}
+
+	BUG_ON(r->start != r->end);
+	err = request_irq(r->start, interrupt_handler, 0, resource_name, this);
+	if (err) {
+		log("Can't own %s", resource_name);
+		return err;
+	}
+
+	*lno = r->start;
+	*hno = r->end;
+	return 0;
+}
+
+static void release_interrupt(struct gpmi_nfc_data *this,
+			int low_interrupt_number, int high_interrupt_number)
+{
+	int i;
+	for (i = low_interrupt_number; i <= high_interrupt_number; i++)
+		free_irq(i, this);
+}
+
+static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
+{
+	struct gpmi_nfc_data *this = param;
+	struct resource *r = this->private;
+
+	if (!mxs_dma_is_apbh(chan))
+		return false;
+	/*
+	 * only catch the GPMI dma channels :
+	 *	for mx23 :	MX23_DMA_GPMI0 ~ MX23_DMA_GPMI3
+	 *		(These four channels share the same IRQ!)
+	 *
+	 *	for mx28 :	MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
+	 *		(These eight channels share the same IRQ!)
+	 */
+	if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
+		chan->private = &this->dma_data;
+		return true;
+	}
+	return false;
+}
+
+static void release_dma_channels(struct gpmi_nfc_data *this)
+{
+	unsigned int i;
+	for (i = 0; i < DMA_CHANS; i++)
+		if (this->dma_chans[i]) {
+			dma_release_channel(this->dma_chans[i]);
+			this->dma_chans[i] = NULL;
+		}
+}
+
+static int acquire_dma_channels(struct gpmi_nfc_data *this,
+				const char *resource_name,
+				unsigned *low_channel, unsigned *high_channel)
+{
+	struct platform_device  *pdev = this->pdev;
+	struct resource         *r, *r_dma;
+	unsigned int            i;
+
+	r = platform_get_resource_byname(pdev, IORESOURCE_DMA, resource_name);
+	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
+					GPMI_NFC_DMA_INTERRUPT_RES_NAME);
+	if (!r || !r_dma) {
+		log("Can't get resource for DMA");
+		return -ENXIO;
+	}
+
+	/* get the DMA interrupt */
+	BUG_ON(r_dma->start != r_dma->end);
+	this->dma_data.chan_irq = r_dma->start;
+
+	/* used in gpmi_dma_filter() */
+	this->private = r;
+
+	for (i = r->start; i <= r->end; i++) {
+		dma_cap_mask_t		mask;
+		struct dma_chan		*dma_chan;
+
+		dma_cap_zero(mask);
+		dma_cap_set(DMA_SLAVE, mask);
+
+		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
+		if (!dma_chan)
+			goto acquire_err;
+		/* fill the first empty item */
+		this->dma_chans[i - r->start] = dma_chan;
+	}
+
+	*low_channel  = r->start;
+	*high_channel = r->end;
+	return 0;
+
+acquire_err:
+	log("Can't acquire DMA channel %u", i);
+	release_dma_channels(this);
+	return -EINVAL;
+}
+
+static inline int acquire_clock(struct gpmi_nfc_data *this, struct clk **clock)
+{
+	struct clk *c;
+
+	c = clk_get(&this->pdev->dev, NULL);
+	if (IS_ERR(c)) {
+		log("Can't own clock");
+		return PTR_ERR(c);
+	}
+	*clock = c;
+	return 0;
+}
+
+static void release_clock(struct gpmi_nfc_data *this, struct clk *clock)
+{
+	clk_put(clock);
+}
+
+static int acquire_resources(struct gpmi_nfc_data *this)
+{
+	struct resources *resources = &this->resources;
+	int error;
+
+	/* Attempt to acquire the GPMI register block. */
+	error = acquire_register_block(this,
+				GPMI_NFC_GPMI_REGS_ADDR_RES_NAME,
+				&resources->gpmi_regs);
+	if (error)
+		goto exit_gpmi_regs;
+
+	/* Attempt to acquire the BCH register block. */
+	error = acquire_register_block(this,
+				GPMI_NFC_BCH_REGS_ADDR_RES_NAME,
+				&resources->bch_regs);
+	if (error)
+		goto exit_bch_regs;
+
+	/* Attempt to acquire the BCH interrupt. */
+	error = acquire_interrupt(this,
+				GPMI_NFC_BCH_INTERRUPT_RES_NAME,
+				bch_irq,
+				&resources->bch_low_interrupt,
+				&resources->bch_high_interrupt);
+	if (error)
+		goto exit_bch_interrupt;
+
+	/* Attempt to acquire the DMA channels. */
+	error = acquire_dma_channels(this,
+				GPMI_NFC_DMA_CHANNELS_RES_NAME,
+				&resources->dma_low_channel,
+				&resources->dma_high_channel);
+	if (error)
+		goto exit_dma_channels;
+
+	/* Attempt to acquire our clock. */
+	error = acquire_clock(this, &resources->clock);
+	if (error)
+		goto exit_clock;
+	return 0;
+
+exit_clock:
+	release_dma_channels(this);
+exit_dma_channels:
+	release_interrupt(this, resources->bch_low_interrupt,
+				resources->bch_high_interrupt);
+exit_bch_interrupt:
+	release_register_block(this, resources->bch_regs);
+exit_bch_regs:
+	release_register_block(this, resources->gpmi_regs);
+exit_gpmi_regs:
+	return error;
+}
+
+static void release_resources(struct gpmi_nfc_data *this)
+{
+	struct resources  *resources = &this->resources;
+
+	release_clock(this, resources->clock);
+	release_register_block(this, resources->gpmi_regs);
+	release_register_block(this, resources->bch_regs);
+	release_interrupt(this, resources->bch_low_interrupt,
+				resources->bch_low_interrupt);
+	release_dma_channels(this);
+}
+
+static void exit_nfc_hal(struct gpmi_nfc_data *this)
+{
+	if (this->nfc)
+		this->nfc->exit(this);
+}
+
+static int set_up_nfc_hal(struct gpmi_nfc_data *this)
+{
+	struct nfc_hal *nfc = NULL;
+	int error;
+
+	/*
+	 * This structure contains the "safe" GPMI timing that should succeed
+	 * with any NAND Flash device
+	 * (although, with less-than-optimal performance).
+	 */
+	static struct nand_timing  safe_timing = {
+		.data_setup_in_ns        = 80,
+		.data_hold_in_ns         = 60,
+		.address_setup_in_ns     = 25,
+		.gpmi_sample_delay_in_ns =  6,
+		.tREA_in_ns              = -1,
+		.tRLOH_in_ns             = -1,
+		.tRHOH_in_ns             = -1,
+	};
+
+	if (cpu_is_mx23() || cpu_is_mx28())
+		nfc = &gpmi_nfc_hal_imx23_imx28;
+
+	BUG_ON(nfc == NULL);
+	this->nfc = nfc;
+
+	/* Initialize the NFC HAL. */
+	error = nfc->init(this);
+	if (error)
+		return error;
+
+	/* Set up safe timing. */
+	nfc->set_timing(this, &safe_timing);
+	return 0;
+}
+
+static int set_up_boot_rom_helper(struct gpmi_nfc_data *this)
+{
+	struct boot_rom_helper *rom = NULL;
+
+	if (cpu_is_mx23())
+		rom = &gpmi_nfc_boot_rom_imx23;
+	if (cpu_is_mx28())
+		rom = &gpmi_nfc_boot_rom_imx28;
+
+	BUG_ON(rom == NULL);
+
+	pr_info("Boot ROM: Version %u, %s\n", rom->version, rom->description);
+	this->rom = rom;
+	return 0;
+}
+
+/* Creates/Removes sysfs files for this device.*/
+static void manage_sysfs_files(struct gpmi_nfc_data *this, int create)
+{
+	struct device            *dev = this->dev;
+	int                      error;
+	unsigned int             i;
+	struct device_attribute  **attr;
+
+	for (i = 0, attr = device_attributes;
+			i < ARRAY_SIZE(device_attributes); i++, attr++) {
+
+		if (create) {
+			error = device_create_file(dev, *attr);
+			if (error) {
+				while (--attr >= device_attributes)
+					device_remove_file(dev, *attr);
+				return;
+			}
+		} else {
+			device_remove_file(dev, *attr);
+		}
+	}
+}
+
+static int read_page_prepare(struct gpmi_nfc_data *this,
+			void *destination, unsigned length,
+			void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
+			void **use_virt, dma_addr_t *use_phys)
+{
+	struct device  *dev = this->dev;
+	dma_addr_t destination_phys = ~0;
+
+	if (virt_addr_valid(destination))
+		destination_phys = dma_map_single(dev, (void *)destination,
+						length, DMA_FROM_DEVICE);
+
+	if (dma_mapping_error(dev, destination_phys)) {
+		if (alt_size < length) {
+			log("Alternate buffer is too small for incoming I/O.");
+			return -ENOMEM;
+		}
+
+		*use_virt = alt_virt;
+		*use_phys = alt_phys;
+	} else {
+		*use_virt = destination;
+		*use_phys = destination_phys;
+	}
+	return 0;
+}
+
+static void read_page_end(struct gpmi_nfc_data *this,
+			void *destination, unsigned length,
+			void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
+			void *used_virt, dma_addr_t used_phys)
+{
+	struct device  *dev = this->dev;
+
+	if (used_virt == destination)
+		dma_unmap_single(dev, used_phys, length, DMA_FROM_DEVICE);
+	else
+		memcpy(destination, alt_virt, length);
+}
+
+static int send_page_prepare(struct gpmi_nfc_data *this,
+			const void *source, unsigned length,
+			void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
+			const void **use_virt, dma_addr_t *use_phys)
+{
+	dma_addr_t source_phys = ~0;
+	struct device  *dev = this->dev;
+
+	if (virt_addr_valid(source))
+		source_phys = dma_map_single(dev,
+				(void *)source, length, DMA_TO_DEVICE);
+
+	if (dma_mapping_error(dev, source_phys)) {
+		if (alt_size < length) {
+			log("Alternate buffer is too small for outgoing I/O");
+			return -ENOMEM;
+		}
+
+		/*
+		 * Copy the contents of the source buffer into the alternate
+		 * buffer and set up the return values accordingly.
+		 */
+		memcpy(alt_virt, source, length);
+
+		*use_virt = alt_virt;
+		*use_phys = alt_phys;
+	} else {
+		*use_virt = source;
+		*use_phys = source_phys;
+	}
+	return 0;
+}
+
+static void send_page_end(struct gpmi_nfc_data *this,
+			const void *source, unsigned length,
+			void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
+			const void *used_virt, dma_addr_t used_phys)
+{
+	struct device  *dev = this->dev;
+	if (used_virt == source)
+		dma_unmap_single(dev, used_phys, length, DMA_TO_DEVICE);
+}
+
+static void mil_free_dma_buffer(struct gpmi_nfc_data *this)
+{
+	struct device *dev = this->dev;
+	struct mil *mil	= &this->mil;
+
+	if (mil->page_buffer_virt && virt_addr_valid(mil->page_buffer_virt))
+		dma_free_coherent(dev, mil->page_buffer_size,
+					mil->page_buffer_virt,
+					mil->page_buffer_phys);
+	kfree(mil->cmd_buffer);
+	kfree(mil->data_buffer_dma);
+
+	mil->cmd_buffer		= NULL;
+	mil->data_buffer_dma	= NULL;
+	mil->page_buffer_virt	= NULL;
+	mil->page_buffer_size	=  0;
+	mil->page_buffer_phys	= ~0;
+}
+
+/* Allocate the DMA buffers */
+static int mil_alloc_dma_buffer(struct gpmi_nfc_data *this)
+{
+	struct device        *dev	= this->dev;
+	struct nfc_geometry  *geo	= &this->nfc_geometry;
+	struct mil           *mil	= &this->mil;
+
+	/* [1] Allocate a command buffer. PAGE_SIZE is enough. */
+	mil->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA);
+	if (mil->cmd_buffer == NULL)
+		goto error_alloc;
+
+	/* [2] Allocate a read/write data buffer. PAGE_SIZE is enough. */
+	mil->data_buffer_dma = kzalloc(PAGE_SIZE, GFP_DMA);
+	if (mil->data_buffer_dma == NULL)
+		goto error_alloc;
+
+	/*
+	 * [3] Allocate the page buffer.
+	 *
+	 * Both the payload buffer and the auxiliary buffer must appear on
+	 * 32-bit boundaries. We presume the size of the payload buffer is a
+	 * power of two and is much larger than four, which guarantees the
+	 * auxiliary buffer will appear on a 32-bit boundary.
+	 */
+	mil->page_buffer_size = geo->payload_size_in_bytes +
+				geo->auxiliary_size_in_bytes;
+
+	mil->page_buffer_virt = dma_alloc_coherent(dev, mil->page_buffer_size,
+					&mil->page_buffer_phys, GFP_DMA);
+	if (!mil->page_buffer_virt)
+		goto error_alloc;
+
+
+	/* Slice up the page buffer. */
+	mil->payload_virt = mil->page_buffer_virt;
+	mil->payload_phys = mil->page_buffer_phys;
+	mil->auxiliary_virt = ((char *) mil->payload_virt) +
+					geo->payload_size_in_bytes;
+	mil->auxiliary_phys = mil->payload_phys +
+					geo->payload_size_in_bytes;
+	return 0;
+
+error_alloc:
+	mil_free_dma_buffer(this);
+	log("allocate DMA buffer error!!");
+	return -ENOMEM;
+}
+
+static void mil_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
+{
+	struct nand_chip      *nand = mtd->priv;
+	struct gpmi_nfc_data  *this = nand->priv;
+	struct mil            *mil  = &this->mil;
+	struct nfc_hal        *nfc  =  this->nfc;
+	int                   error;
+
+	/*
+	 * Every operation begins with a command byte and a series of zero or
+	 * more address bytes. These are distinguished by either the Address
+	 * Latch Enable (ALE) or Command Latch Enable (CLE) signals being
+	 * asserted. When MTD is ready to execute the command, it will deassert
+	 * both latch enables.
+	 *
+	 * Rather than run a separate DMA operation for every single byte, we
+	 * queue them up and run a single DMA operation for the entire series
+	 * of command and data bytes. NAND_CMD_NONE means the END of the queue.
+	 */
+	if ((ctrl & (NAND_ALE | NAND_CLE))) {
+		if (data != NAND_CMD_NONE)
+			mil->cmd_buffer[mil->command_length++] = data;
+		return;
+	}
+
+	if (!mil->command_length)
+		return;
+
+	error = nfc->send_command(this);
+	if (error)
+		log("Chip: %u, Error %d", mil->current_chip, error);
+
+	mil->command_length = 0;
+}
+
+static int mil_dev_ready(struct mtd_info *mtd)
+{
+	struct nand_chip      *nand = mtd->priv;
+	struct gpmi_nfc_data  *this = nand->priv;
+	struct nfc_hal        *nfc  = this->nfc;
+	struct mil            *mil  = &this->mil;
+
+	return nfc->is_ready(this, mil->current_chip);
+}
+
+static void mil_select_chip(struct mtd_info *mtd, int chip)
+{
+	struct nand_chip      *nand  = mtd->priv;
+	struct gpmi_nfc_data  *this  = nand->priv;
+	struct mil            *mil   = &this->mil;
+	struct nfc_hal        *nfc   =  this->nfc;
+
+	if ((mil->current_chip < 0) && (chip >= 0))
+		nfc->begin(this);
+	else if ((mil->current_chip >= 0) && (chip < 0))
+		nfc->end(this);
+	else
+		;
+
+	mil->current_chip = chip;
+}
+
+static void mil_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
+{
+	struct nand_chip      *nand     = mtd->priv;
+	struct gpmi_nfc_data  *this     = nand->priv;
+	struct nfc_hal        *nfc      = this->nfc;
+	struct mil            *mil      = &this->mil;
+
+	logio(GPMI_DEBUG_READ);
+	/* save the info in mil{} for future */
+	mil->upper_buf	= buf;
+	mil->upper_len	= len;
+
+	nfc->read_data(this);
+}
+
+static void mil_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
+{
+	struct nand_chip      *nand     = mtd->priv;
+	struct gpmi_nfc_data  *this     = nand->priv;
+	struct nfc_hal        *nfc      =  this->nfc;
+	struct mil            *mil      = &this->mil;
+
+	logio(GPMI_DEBUG_WRITE);
+	/* save the info in mil{} for future */
+	mil->upper_buf	= (uint8_t *)buf;
+	mil->upper_len	= len;
+
+	nfc->send_data(this);
+}
+
+static uint8_t mil_read_byte(struct mtd_info *mtd)
+{
+	struct nand_chip      *nand     = mtd->priv;
+	struct gpmi_nfc_data  *this     = nand->priv;
+	struct mil *mil = &this->mil;
+	uint8_t *buf = mil->data_buffer_dma;
+
+	mil_read_buf(mtd, buf, 1);
+	return buf[0];
+}
+
+/**
+ * mil_handle_block_mark_swapping() - Handles block mark swapping.
+ *
+ * Note that, when this function is called, it doesn't know whether it's
+ * swapping the block mark, or swapping it *back* -- but it doesn't matter
+ * because the the operation is the same.
+ *
+ * @this:       Per-device data.
+ * @payload:    A pointer to the payload buffer.
+ * @auxiliary:  A pointer to the auxiliary buffer.
+ */
+static void mil_handle_block_mark_swapping(struct gpmi_nfc_data *this,
+						void *payload, void *auxiliary)
+{
+	struct nfc_geometry     *nfc_geo = &this->nfc_geometry;
+	struct boot_rom_helper  *rom     =  this->rom;
+	unsigned char           *p;
+	unsigned char           *a;
+	unsigned int            bit;
+	unsigned char           mask;
+	unsigned char           from_data;
+	unsigned char           from_oob;
+
+	/* Check if we're doing block mark swapping. */
+	if (!rom->swap_block_mark)
+		return;
+
+	/*
+	 * If control arrives here, we're swapping. Make some convenience
+	 * variables.
+	 */
+	bit = nfc_geo->block_mark_bit_offset;
+	p   = payload + nfc_geo->block_mark_byte_offset;
+	a   = auxiliary;
+
+	/*
+	 * Get the byte from the data area that overlays the block mark. Since
+	 * the ECC engine applies its own view to the bits in the page, the
+	 * physical block mark won't (in general) appear on a byte boundary in
+	 * the data.
+	 */
+	from_data = (p[0] >> bit) | (p[1] << (8 - bit));
+
+	/* Get the byte from the OOB. */
+	from_oob = a[0];
+
+	/* Swap them. */
+	a[0] = from_data;
+
+	mask = (0x1 << bit) - 1;
+	p[0] = (p[0] & mask) | (from_oob << bit);
+
+	mask = ~0 << bit;
+	p[1] = (p[1] & mask) | (from_oob >> (8 - bit));
+}
+
+static int mil_ecc_read_page(struct mtd_info *mtd, struct nand_chip *nand,
+				uint8_t *buf, int page)
+{
+	struct gpmi_nfc_data    *this    = nand->priv;
+	struct nfc_hal          *nfc     =  this->nfc;
+	struct nfc_geometry     *nfc_geo = &this->nfc_geometry;
+	struct mil              *mil     = &this->mil;
+	void                    *payload_virt;
+	dma_addr_t              payload_phys;
+	void                    *auxiliary_virt;
+	dma_addr_t              auxiliary_phys;
+	unsigned int            i;
+	unsigned char           *status;
+	unsigned int            failed;
+	unsigned int            corrected;
+	int                     error;
+
+	logio(GPMI_DEBUG_ECC_READ);
+	error = read_page_prepare(this, buf, mtd->writesize,
+					mil->payload_virt, mil->payload_phys,
+					nfc_geo->payload_size_in_bytes,
+					&payload_virt, &payload_phys);
+	if (error) {
+		log("Inadequate DMA buffer");
+		error = -ENOMEM;
+		return error;
+	}
+	auxiliary_virt = mil->auxiliary_virt;
+	auxiliary_phys = mil->auxiliary_phys;
+
+	/* ask the NFC */
+	error = nfc->read_page(this, payload_phys, auxiliary_phys);
+	if (error) {
+		log("Error in ECC-based read: %d", error);
+		goto exit_nfc;
+	}
+
+	/* handle the block mark swapping */
+	mil_handle_block_mark_swapping(this, payload_virt, auxiliary_virt);
+
+	/* Loop over status bytes, accumulating ECC status. */
+	failed		= 0;
+	corrected	= 0;
+	status		= auxiliary_virt + nfc_geo->auxiliary_status_offset;
+
+	for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) {
+		if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED))
+			continue;
+
+		if (*status == STATUS_UNCORRECTABLE) {
+			failed++;
+			continue;
+		}
+		corrected += *status;
+	}
+
+	/*
+	 * Propagate ECC status to the owning MTD only when failed or
+	 * corrected times nearly reaches our ECC correction threshold.
+	 */
+	if (failed || corrected >= (nfc_geo->ecc_strength - 1)) {
+		mtd->ecc_stats.failed    += failed;
+		mtd->ecc_stats.corrected += corrected;
+	}
+
+	/*
+	 * It's time to deliver the OOB bytes. See mil_ecc_read_oob() for
+	 * details about our policy for delivering the OOB.
+	 *
+	 * We fill the caller's buffer with set bits, and then copy the block
+	 * mark to th caller's buffer. Note that, if block mark swapping was
+	 * necessary, it has already been done, so we can rely on the first
+	 * byte of the auxiliary buffer to contain the block mark.
+	 */
+	memset(nand->oob_poi, ~0, mtd->oobsize);
+	nand->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
+
+exit_nfc:
+	read_page_end(this, buf, mtd->writesize,
+					mil->payload_virt, mil->payload_phys,
+					nfc_geo->payload_size_in_bytes,
+					payload_virt, payload_phys);
+	return error;
+}
+
+static void mil_ecc_write_page(struct mtd_info *mtd,
+				struct nand_chip *nand, const uint8_t *buf)
+{
+	struct gpmi_nfc_data    *this    = nand->priv;
+	struct nfc_hal          *nfc     =  this->nfc;
+	struct nfc_geometry     *nfc_geo = &this->nfc_geometry;
+	struct boot_rom_helper  *rom     =  this->rom;
+	struct mil              *mil     = &this->mil;
+	const void              *payload_virt;
+	dma_addr_t              payload_phys;
+	const void              *auxiliary_virt;
+	dma_addr_t              auxiliary_phys;
+	int                     error;
+
+	logio(GPMI_DEBUG_ECC_WRITE);
+	if (rom->swap_block_mark) {
+		/*
+		 * If control arrives here, we're doing block mark swapping.
+		 * Since we can't modify the caller's buffers, we must copy them
+		 * into our own.
+		 */
+		memcpy(mil->payload_virt, buf, mtd->writesize);
+		payload_virt = mil->payload_virt;
+		payload_phys = mil->payload_phys;
+
+		memcpy(mil->auxiliary_virt, nand->oob_poi,
+				nfc_geo->auxiliary_size_in_bytes);
+		auxiliary_virt = mil->auxiliary_virt;
+		auxiliary_phys = mil->auxiliary_phys;
+
+		/* Handle block mark swapping. */
+		mil_handle_block_mark_swapping(this,
+				(void *) payload_virt, (void *) auxiliary_virt);
+	} else {
+		/*
+		 * If control arrives here, we're not doing block mark swapping,
+		 * so we can to try and use the caller's buffers.
+		 */
+		error = send_page_prepare(this,
+				buf, mtd->writesize,
+				mil->payload_virt, mil->payload_phys,
+				nfc_geo->payload_size_in_bytes,
+				&payload_virt, &payload_phys);
+		if (error) {
+			log("Inadequate payload DMA buffer");
+			return;
+		}
+
+		error = send_page_prepare(this,
+				nand->oob_poi, mtd->oobsize,
+				mil->auxiliary_virt, mil->auxiliary_phys,
+				nfc_geo->auxiliary_size_in_bytes,
+				&auxiliary_virt, &auxiliary_phys);
+		if (error) {
+			log("Inadequate auxiliary DMA buffer");
+			goto exit_auxiliary;
+		}
+	}
+
+	/* Ask the NFC. */
+	error = nfc->send_page(this, payload_phys, auxiliary_phys);
+	if (error)
+		log("Error in ECC-based write: %d", error);
+
+	if (!rom->swap_block_mark) {
+		send_page_end(this, nand->oob_poi, mtd->oobsize,
+				mil->auxiliary_virt, mil->auxiliary_phys,
+				nfc_geo->auxiliary_size_in_bytes,
+				auxiliary_virt, auxiliary_phys);
+exit_auxiliary:
+		send_page_end(this, buf, mtd->writesize,
+				mil->payload_virt, mil->payload_phys,
+				nfc_geo->payload_size_in_bytes,
+				payload_virt, payload_phys);
+	}
+}
+
+/**
+ * mil_hook_block_markbad() - Hooked MTD Interface block_markbad().
+ *
+ * This function is a veneer that replaces the function originally installed by
+ * the NAND Flash MTD code. See the description of the marking_a_bad_block field
+ * in struct mil for more information about this.
+ *
+ * @mtd:  A pointer to the MTD.
+ * @ofs:  Byte address of the block to mark.
+ */
+static int mil_hook_block_markbad(struct mtd_info *mtd, loff_t ofs)
+{
+	register struct nand_chip  *chip = mtd->priv;
+	struct gpmi_nfc_data       *this = chip->priv;
+	struct mil                 *mil  = &this->mil;
+	int                        ret;
+
+	mil->marking_a_bad_block = true;
+	ret = mil->hooked_block_markbad(mtd, ofs);
+	mil->marking_a_bad_block = false;
+	return ret;
+}
+
+/**
+ * mil_ecc_read_oob() - MTD Interface ecc.read_oob().
+ *
+ * There are several places in this driver where we have to handle the OOB and
+ * block marks. This is the function where things are the most complicated, so
+ * this is where we try to explain it all. All the other places refer back to
+ * here.
+ *
+ * These are the rules, in order of decreasing importance:
+ *
+ * 1) Nothing the caller does can be allowed to imperil the block mark, so all
+ *    write operations take measures to protect it.
+ *
+ * 2) In read operations, the first byte of the OOB we return must reflect the
+ *    true state of the block mark, no matter where that block mark appears in
+ *    the physical page.
+ *
+ * 3) ECC-based read operations return an OOB full of set bits (since we never
+ *    allow ECC-based writes to the OOB, it doesn't matter what ECC-based reads
+ *    return).
+ *
+ * 4) "Raw" read operations return a direct view of the physical bytes in the
+ *    page, using the conventional definition of which bytes are data and which
+ *    are OOB. This gives the caller a way to see the actual, physical bytes
+ *    in the page, without the distortions applied by our ECC engine.
+ *
+ *
+ * What we do for this specific read operation depends on two questions:
+ *
+ * 1) Are we doing a "raw" read, or an ECC-based read?
+ *
+ * 2) Are we using block mark swapping or transcription?
+ *
+ * There are four cases, illustrated by the following Karnaugh map:
+ *
+ *                    |           Raw           |         ECC-based       |
+ *       -------------+-------------------------+-------------------------+
+ *                    | Read the conventional   |                         |
+ *                    | OOB at the end of the   |                         |
+ *       Swapping     | page and return it. It  |                         |
+ *                    | contains exactly what   |                         |
+ *                    | we want.                | Read the block mark and |
+ *       -------------+-------------------------+ return it in a buffer   |
+ *                    | Read the conventional   | full of set bits.       |
+ *                    | OOB at the end of the   |                         |
+ *                    | page and also the block |                         |
+ *       Transcribing | mark in the metadata.   |                         |
+ *                    | Copy the block mark     |                         |
+ *                    | into the first byte of  |                         |
+ *                    | the OOB.                |                         |
+ *       -------------+-------------------------+-------------------------+
+ *
+ * Note that we break rule #4 in the Transcribing/Raw case because we're not
+ * giving an accurate view of the actual, physical bytes in the page (we're
+ * overwriting the block mark). That's OK because it's more important to follow
+ * rule #2.
+ *
+ * It turns out that knowing whether we want an "ECC-based" or "raw" read is not
+ * easy. When reading a page, for example, the NAND Flash MTD code calls our
+ * ecc.read_page or ecc.read_page_raw function. Thus, the fact that MTD wants an
+ * ECC-based or raw view of the page is implicit in which function it calls
+ * (there is a similar pair of ECC-based/raw functions for writing).
+ *
+ * Since MTD assumes the OOB is not covered by ECC, there is no pair of
+ * ECC-based/raw functions for reading or or writing the OOB. The fact that the
+ * caller wants an ECC-based or raw view of the page is not propagated down to
+ * this driver.
+ *
+ * @mtd:     A pointer to the owning MTD.
+ * @nand:    A pointer to the owning NAND Flash MTD.
+ * @page:    The page number to read.
+ * @sndcmd:  Indicates this function should send a command to the chip before
+ *           reading the out-of-band bytes. This is only false for small page
+ *           chips that support auto-increment.
+ */
+static int mil_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *nand,
+							int page, int sndcmd)
+{
+	struct gpmi_nfc_data      *this     = nand->priv;
+	struct boot_rom_helper    *rom      =  this->rom;
+
+	/* clear the OOB buffer */
+	memset(nand->oob_poi, ~0, mtd->oobsize);
+
+	/* Read out the conventional OOB. */
+	nand->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
+	nand->read_buf(mtd, nand->oob_poi, mtd->oobsize);
+
+	/*
+	 * Now, we want to make sure the block mark is correct. In the
+	 * Swapping/Raw case, we already have it. Otherwise, we need to
+	 * explicitly read it.
+	 */
+	if (!rom->swap_block_mark) {
+		/* Read the block mark into the first byte of the OOB buffer. */
+		nand->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
+		nand->oob_poi[0] = nand->read_byte(mtd);
+	}
+
+	/*
+	 * Return true, indicating that the next call to this function must send
+	 * a command.
+	 */
+	return true;
+}
+
+static int mil_ecc_write_oob(struct mtd_info *mtd,
+				struct nand_chip *nand, int page)
+{
+	struct gpmi_nfc_data	*this	= nand->priv;
+	struct device		*dev	= this->dev;
+	struct mil		*mil	= &this->mil;
+	struct boot_rom_helper	*rom	= this->rom;
+	uint8_t			*block_mark;
+	int	block_mark_column;
+	int	status;
+	int	error = 0;
+
+	/*
+	 * There are fundamental incompatibilities between the i.MX GPMI NFC and
+	 * the NAND Flash MTD model that make it essentially impossible to write
+	 * the out-of-band bytes.
+	 *
+	 * We permit *ONE* exception. If the *intent* of writing the OOB is to
+	 * mark a block bad, we can do that.
+	 */
+	if (!mil->marking_a_bad_block) {
+		dev_emerg(dev, "This driver doesn't support writing the OOB\n");
+		WARN_ON(1);
+		error = -EIO;
+		goto exit;
+	}
+
+	/*
+	 * If control arrives here, we're marking a block bad. First, figure out
+	 * where the block mark is.
+	 *
+	 * If we're using swapping, the block mark is in the conventional
+	 * location. Otherwise, we're using transcription, and the block mark
+	 * appears in the first byte of the page.
+	 */
+	if (rom->swap_block_mark)
+		block_mark_column = mtd->writesize;
+	else
+		block_mark_column = 0;
+
+	/* Write the block mark. */
+	block_mark = mil->data_buffer_dma;
+	block_mark[0] = 0; /* bad block marker */
+
+	nand->cmdfunc(mtd, NAND_CMD_SEQIN, block_mark_column, page);
+	nand->write_buf(mtd, block_mark, 1);
+	nand->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+
+	status = nand->waitfunc(mtd, nand);
+
+	/* Check if it worked. */
+	if (status & NAND_STATUS_FAIL)
+		error = -EIO;
+exit:
+	return error;
+}
+
+/**
+ * mil_block_bad - Claims all blocks are good.
+ *
+ * In principle, this function is *only* called when the NAND Flash MTD system
+ * isn't allowed to keep an in-memory bad block table, so it is forced to ask
+ * the driver for bad block information.
+ *
+ * In fact, we permit the NAND Flash MTD system to have an in-memory BBT, so
+ * this function is *only* called when we take it away.
+ *
+ * We take away the in-memory BBT when the user sets the "ignorebad" parameter,
+ * which indicates that all blocks should be reported good.
+ *
+ * Thus, this function is only called when we want *all* blocks to look good,
+ * so it *always* return success.
+ *
+ * @mtd:      Ignored.
+ * @ofs:      Ignored.
+ * @getchip:  Ignored.
+ */
+static int mil_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
+{
+	return 0;
+}
+
+static void show_rom_geometry(struct boot_rom_geometry *geo)
+{
+	pr_info("--------------------------------------------\n");
+	pr_info("	Boot ROM Geometry\n");
+	pr_info("--------------------------------------------\n");
+	pr_info("Boot Area Count            : %u\n", geo->boot_area_count);
+	pr_info("Boot Area Size in Bytes    : %u (0x%x)\n",
+					geo->boot_area_size_in_bytes,
+					geo->boot_area_size_in_bytes);
+	pr_info("Stride Size in Pages       : %u\n", geo->stride_size_in_pages);
+	pr_info("Search Area Stride Exponent: %u\n",
+					geo->search_area_stride_exponent);
+}
+
+/* Set up the Boot ROM Helper geometry. */
+static int mil_set_boot_rom_helper_geometry(struct gpmi_nfc_data  *this)
+{
+	struct boot_rom_helper    *rom =  this->rom;
+	struct boot_rom_geometry  *geo = &this->rom_geometry;
+	int error;
+
+	error = rom->set_geometry(this);
+	if (error)
+		return error;
+
+	if (gpmi_debug & GPMI_DEBUG_INIT)
+		show_rom_geometry(geo);
+
+	return 0;
+}
+
+static void show_nfc_geometry(struct nfc_geometry *geo)
+{
+	pr_info("---------------------------------------\n");
+	pr_info("	NFC Geometry (used by BCH)\n");
+	pr_info("---------------------------------------\n");
+	pr_info("ECC Algorithm          : %s\n", geo->ecc_algorithm);
+	pr_info("ECC Strength           : %u\n", geo->ecc_strength);
+	pr_info("Page Size in Bytes     : %u\n", geo->page_size_in_bytes);
+	pr_info("Metadata Size in Bytes : %u\n", geo->metadata_size_in_bytes);
+	pr_info("ECC Chunk Size in Bytes: %u\n", geo->ecc_chunk_size_in_bytes);
+	pr_info("ECC Chunk Count        : %u\n", geo->ecc_chunk_count);
+	pr_info("Payload Size in Bytes  : %u\n", geo->payload_size_in_bytes);
+	pr_info("Auxiliary Size in Bytes: %u\n", geo->auxiliary_size_in_bytes);
+	pr_info("Auxiliary Status Offset: %u\n", geo->auxiliary_status_offset);
+	pr_info("Block Mark Byte Offset : %u\n", geo->block_mark_byte_offset);
+	pr_info("Block Mark Bit Offset  : %u\n", geo->block_mark_bit_offset);
+}
+
+static int mil_set_geometry(struct gpmi_nfc_data *this)
+{
+	struct nfc_hal *nfc = this->nfc;
+	struct nfc_geometry *geo = &this->nfc_geometry;
+	int error;
+
+	/* Free the temporary DMA memory for read ID case */
+	mil_free_dma_buffer(this);
+
+	/* Set up the NFC geometry which is used by BCH. */
+	error = nfc->set_geometry(this);
+	if (error != 0) {
+		log("NFC set geometry error : %d", error);
+		return error;
+	}
+	if (gpmi_debug & GPMI_DEBUG_INIT)
+		show_nfc_geometry(geo);
+
+	/* Alloc the new DMA buffers according to the pagesize and oobsize */
+	return mil_alloc_dma_buffer(this);
+}
+
+static int mil_pre_bbt_scan(struct gpmi_nfc_data  *this)
+{
+	struct boot_rom_helper	*rom = this->rom;
+	int error;
+
+	error = mil_set_boot_rom_helper_geometry(this);
+	if (error)
+		return error;
+
+	/* This is ROM arch-specific initilization before the BBT scanning. */
+	if (rom->rom_extra_init)
+		error = rom->rom_extra_init(this);
+	return error;
+}
+
+static int mil_scan_bbt(struct mtd_info *mtd)
+{
+	struct nand_chip         *nand = mtd->priv;
+	struct gpmi_nfc_data     *this = nand->priv;
+	int                      error;
+
+	/* Prepare for the BBT scan. */
+	error = mil_pre_bbt_scan(this);
+	if (error)
+		return error;
+
+	/* use the default BBT implementation */
+	return nand_default_bbt(mtd);
+}
+
+static int mil_boot_areas_init(struct gpmi_nfc_data *this)
+{
+	struct boot_rom_geometry       *rom      = &this->rom_geometry;
+	struct mil                     *mil      = &this->mil;
+	struct mtd_info                *mtd      = &mil->mtd;
+
+	if (rom->boot_area_count == 0) {
+		mil->general_use_mtd = &mil->mtd;
+		pr_info("There is no Boot area.\n");
+	} else if (rom->boot_area_count == 1) {
+		static char  *chip_0_boot_name = "gpmi-nfc-0-boot";
+		static char  *general_use_name = "gpmi-nfc-general-use";
+		struct mtd_partition partitions[2];
+
+		pr_info("Boot area protection is enabled.\n");
+		/*
+		 * We partition the medium like so:
+		 *
+		 * +------+----------------------------------------------------+
+		 * | Boot |                    General Use                     |
+		 * +------+----------------------------------------------------+
+		 */
+
+		/* Chip 0 Boot */
+		partitions[0].name       = chip_0_boot_name;
+		partitions[0].offset     = 0;
+		partitions[0].size       = rom->boot_area_size_in_bytes;
+		partitions[0].mask_flags = 0;
+
+		/* General Use */
+		partitions[1].name       = general_use_name;
+		partitions[1].offset     = rom->boot_area_size_in_bytes;
+		partitions[1].size       = MTDPART_SIZ_FULL;
+		partitions[1].mask_flags = 0;
+
+		/* Construct and register the partitions. */
+		add_mtd_partitions(mtd, partitions, 2);
+
+		/* Find the general use MTD. */
+		mil->general_use_mtd = get_mtd_device_nm(general_use_name);
+		if (IS_ERR(mil->general_use_mtd)) {
+			log("Can't find general use MTD");
+			BUG();
+		}
+	} else {
+		log("Boot area count greater than one is unimplemented.");
+		return -ENXIO;
+	}
+	return 0;
+}
+
+static void mil_boot_areas_exit(struct gpmi_nfc_data *this)
+{
+	struct boot_rom_geometry  *rom = &this->rom_geometry;
+	struct mil                *mil = &this->mil;
+	struct mtd_info           *mtd = &mil->mtd;
+
+	if (!rom->boot_area_count) {
+		mil->general_use_mtd = NULL;
+		return;
+	}
+	del_mtd_partitions(mtd);
+	mil->general_use_mtd = NULL;
+}
+
+static int construct_general_use_partitions(struct gpmi_nfc_data *this)
+{
+	struct mil                     *mil   = &this->mil;
+	unsigned int                   partition_count;
+	struct mtd_partition           *partitions;
+	unsigned int                   name_size;
+	char                           *names;
+	unsigned int                   size;
+	unsigned int                   i;
+	static const char              *name_prefix = "gpmi-nfc-ubi-";
+
+	/* Only handle the MTD which is larger than 2GiB. */
+	if (mil->general_use_mtd->size <= SZ_2G)
+		return 0;
+
+	/* Split it by 2G for historical reason*/
+	partition_count = mil->general_use_mtd->size >> 31;
+	if (mil->general_use_mtd->size & ((1 << 30) - 1))
+		partition_count++;
+
+	/* construct the partitions */
+	name_size = strlen(name_prefix) + 4;
+	size = (sizeof(*partitions) + name_size) * partition_count;
+	partitions = kzalloc(size, GFP_KERNEL);
+	if (!partitions) {
+		log("Could not allocate memory for UBI partitions.");
+		return -ENOMEM;
+	}
+
+	names = (char *)(partitions + partition_count);
+	for (i = 0; i < partition_count; i++) {
+		partitions[i].name   = names;
+		partitions[i].size   = SZ_2G;
+		partitions[i].offset = MTDPART_OFS_NXTBLK;
+
+		sprintf(names, "%s%u", name_prefix, i);
+		names += name_size;
+	}
+	/* Adjust the last partition to take up the remainder. */
+	partitions[i - 1].size = MTDPART_SIZ_FULL;
+
+	mil->partitions           = partitions;
+	mil->partition_count      = partition_count;
+	return 0;
+}
+
+static int mil_partitions_init(struct gpmi_nfc_data *this)
+{
+	struct mil *mil = &this->mil;
+	int  error;
+
+	error = mil_boot_areas_init(this);
+	if (error)
+		return error;
+
+	/* Construct partitions */
+	error = construct_general_use_partitions(this);
+	if (error) {
+		log("error : %d", error);
+		return error;
+	}
+	if (mil->partition_count)
+		add_mtd_partitions(mil->general_use_mtd, mil->partitions,
+					mil->partition_count);
+	return 0;
+}
+
+static void mil_partitions_exit(struct gpmi_nfc_data *this)
+{
+	struct mil *mil = &this->mil;
+
+	if (mil->partition_count) {
+		del_mtd_partitions(mil->general_use_mtd);
+		kfree(mil->partitions);
+		mil->partition_count = 0;
+	}
+	mil_boot_areas_exit(this);
+}
+
+/*
+ * This function is used to set the mtd->pagesize, mtd->oobsize,
+ * mtd->erasesize. Yes, we also do some initialization.
+ *
+ * Return with the bus width. 0 for 8-bit, -1 for error.
+ */
+static int gpmi_init_size(struct mtd_info *mtd, struct nand_chip *nand,
+				u8 *id_bytes)
+{
+	struct gpmi_nfc_data *this	= nand->priv;
+	struct nfc_hal       *nfc	= this->nfc;
+	struct mil           *mil	= &this->mil;
+	struct nand_ecclayout *layout	= &mil->oob_layout;
+	struct nand_device_info  *info;
+	struct nand_attr	 *attr;
+	int error;
+
+	/* Look up this device in our own database. */
+	info = nand_device_get_info(id_bytes);
+	if (!info) {
+		pr_err("Unrecognized NAND Flash device.\n");
+		return -EINVAL;
+	} else if (gpmi_debug & GPMI_DEBUG_INIT)
+		nand_device_print_info(info);
+	else
+		pr_info("We found nand : [ %s ]\n", info->desc);
+
+	attr = &info->attr;
+	/*
+	 *  Init the right NAND/MTD parameters which will be used
+	 *  in the following mil_set_geometry().
+	 */
+	mtd->writesize	= 1 << (fls(attr->page_total_size_in_bytes) - 1);
+	mtd->erasesize	= mtd->writesize * attr->block_size_in_pages;
+	mtd->oobsize	= attr->page_total_size_in_bytes - mtd->writesize;
+	nand->chipsize	= attr->chip_size_in_bytes;
+
+	/* Configure the struct nand_ecclayout. */
+	layout->eccbytes          = 0;
+	layout->oobavail          = mtd->oobsize;
+	layout->oobfree[0].offset = 0;
+	layout->oobfree[0].length = mtd->oobsize;
+
+	nand->ecc.layout = layout;
+
+	/* copy it. */
+	this->device_info = *info;
+	this->device_info.desc = kstrdup(info->desc, GFP_KERNEL);
+
+	/* Set up the medium geometry */
+	error = mil_set_geometry(this);
+	if (error)
+		return error;
+
+	/* extra init */
+	if (nfc->extra_init) {
+		error = nfc->extra_init(this);
+		if (error != 0)
+			return error;
+	}
+
+	/* We only use 8-bit bus now, not 16-bit. */
+	return 0;
+}
+
+/* Initializes the MTD Interface Layer */
+int gpmi_nfc_mil_init(struct gpmi_nfc_data *this)
+{
+	struct gpmi_nfc_platform_data  *pdata =  this->pdata;
+	struct mil                     *mil   = &this->mil;
+	struct mtd_info                *mtd   = &mil->mtd;
+	struct nand_chip               *nand  = &mil->nand;
+	int                            error;
+
+	/* Initialize MIL data */
+	mil->current_chip	= -1;
+	mil->command_length	=  0;
+	mil->page_buffer_virt	=  0;
+	mil->page_buffer_phys	= ~0;
+	mil->page_buffer_size	=  0;
+
+	/* Initialize the MTD data structures */
+	mtd->priv		= nand;
+	mtd->name		= "gpmi-nfc-main";
+	mtd->owner		= THIS_MODULE;
+	nand->priv		= this;
+
+	/* Controls */
+	nand->select_chip	= mil_select_chip;
+	nand->cmd_ctrl		= mil_cmd_ctrl;
+	nand->dev_ready		= mil_dev_ready;
+
+	/*
+	 * Low-level I/O :
+	 *	We don't support a 16-bit NAND Flash bus,
+	 *	so we don't implement read_word.
+	 */
+	nand->read_byte		= mil_read_byte;
+	nand->read_buf		= mil_read_buf;
+	nand->write_buf		= mil_write_buf;
+
+	/* ECC-aware I/O */
+	nand->ecc.read_page	= mil_ecc_read_page;
+	nand->ecc.write_page	= mil_ecc_write_page;
+
+	/* High-level I/O */
+	nand->ecc.read_oob	= mil_ecc_read_oob;
+	nand->ecc.write_oob	= mil_ecc_write_oob;
+
+	/* Bad Block Management */
+	nand->block_bad		= mil_block_bad;
+	nand->scan_bbt		= mil_scan_bbt;
+	nand->init_size		= gpmi_init_size;
+	nand->badblock_pattern	= &gpmi_bbt_descr;
+
+	/* Disallow partial page writes */
+	nand->options		|= NAND_NO_SUBPAGE_WRITE;
+
+	/*
+	 * Tell the NAND Flash MTD system that we'll be handling ECC with our
+	 * own hardware. It turns out that we still have to fill in the ECC size
+	 * because the MTD code will divide by it -- even though it doesn't
+	 * actually care.
+	 */
+	nand->ecc.mode		= NAND_ECC_HW;
+	nand->ecc.size		= 1;
+
+	/* Allocate a temporary DMA buffer for reading ID in the nand_scan() */
+	this->nfc_geometry.payload_size_in_bytes	= 1024;
+	this->nfc_geometry.auxiliary_size_in_bytes	= 128;
+	error = mil_alloc_dma_buffer(this);
+	if (error)
+		goto exit_dma_allocation;
+
+	pr_info("Scanning for NAND Flash chips...\n");
+	error = nand_scan(mtd, pdata->max_chip_count);
+	if (error) {
+		log("Chip scan failed");
+		goto exit_nand_scan;
+	}
+
+	/* Take over the management of the OOB */
+	mil->hooked_block_markbad = mtd->block_markbad;
+	mtd->block_markbad        = mil_hook_block_markbad;
+
+	/* Construct partitions as necessary. */
+	error = mil_partitions_init(this);
+	if (error)
+		goto exit_partitions;
+	return 0;
+
+exit_partitions:
+	nand_release(&mil->mtd);
+exit_nand_scan:
+	mil_free_dma_buffer(this);
+exit_dma_allocation:
+	return error;
+}
+
+void gpmi_nfc_mil_exit(struct gpmi_nfc_data *this)
+{
+	struct mil *mil = &this->mil;
+
+	mil_partitions_exit(this);
+	nand_release(&mil->mtd);
+	mil_free_dma_buffer(this);
+}
+static int gpmi_nfc_probe(struct platform_device *pdev)
+{
+	struct gpmi_nfc_platform_data  *pdata = pdev->dev.platform_data;
+	struct gpmi_nfc_data           *this;
+	int error;
+
+	this = kzalloc(sizeof(*this), GFP_KERNEL);
+	if (!this) {
+		log("Failed to allocate per-device memory\n");
+		return -ENOMEM;
+	}
+
+	/* Set up our data structures. */
+	platform_set_drvdata(pdev, this);
+	this->pdev  = pdev;
+	this->dev   = &pdev->dev;
+	this->pdata = pdata;
+
+	/* Acquire the resources we need. */
+	error = acquire_resources(this);
+	if (error)
+		goto exit_acquire_resources;
+
+	/* Set up the NFC. */
+	error = set_up_nfc_hal(this);
+	if (error)
+		goto exit_nfc_init;
+
+	/* Set up the Boot ROM Helper. */
+	error = set_up_boot_rom_helper(this);
+	if (error)
+		goto exit_boot_rom_helper_init;
+
+	/* Initialize the MTD Interface Layer. */
+	error = gpmi_nfc_mil_init(this);
+	if (error)
+		goto exit_mil_init;
+
+	manage_sysfs_files(this, true);
+	return 0;
+
+exit_mil_init:
+exit_boot_rom_helper_init:
+	exit_nfc_hal(this);
+exit_nfc_init:
+	release_resources(this);
+exit_acquire_resources:
+	platform_set_drvdata(pdev, NULL);
+	kfree(this);
+	return error;
+}
+
+static int __exit gpmi_nfc_remove(struct platform_device *pdev)
+{
+	struct gpmi_nfc_data *this = platform_get_drvdata(pdev);
+
+	manage_sysfs_files(this, false);
+	gpmi_nfc_mil_exit(this);
+	exit_nfc_hal(this);
+	release_resources(this);
+	platform_set_drvdata(pdev, NULL);
+	kfree(this);
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int gpmi_nfc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	return 0;
+}
+
+static int gpmi_nfc_resume(struct platform_device *pdev)
+{
+	return 0;
+}
+#else
+#define suspend  NULL
+#define resume   NULL
+#endif
+
+/* This structure represents this driver to the platform management system. */
+static struct platform_driver gpmi_nfc_driver = {
+	.driver = {
+		.name = GPMI_NFC_DRIVER_NAME,
+	},
+	.probe   = gpmi_nfc_probe,
+	.remove  = __exit_p(gpmi_nfc_remove),
+	.suspend = gpmi_nfc_suspend,
+	.resume  = gpmi_nfc_resume,
+};
+
+static int __init gpmi_nfc_init(void)
+{
+	int err;
+
+	err = platform_driver_register(&gpmi_nfc_driver);
+	if (err == 0)
+		printk(KERN_INFO "GPMI NFC driver registered. (IMX)\n");
+	else
+		pr_err("i.MX GPMI NFC driver registration failed\n");
+	return err;
+}
+
+static void __exit gpmi_nfc_exit(void)
+{
+	platform_driver_unregister(&gpmi_nfc_driver);
+}
+
+static int __init gpmi_debug_setup(char *__unused)
+{
+	gpmi_debug = GPMI_DEBUG_INIT;
+	return 1;
+}
+__setup("gpmi_debug_init", gpmi_debug_setup);
+
+module_init(gpmi_nfc_init);
+module_exit(gpmi_nfc_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor, Inc.");
+MODULE_DESCRIPTION("i.MX GPMI NAND Flash Controller Driver");
+MODULE_LICENSE("GPL");
drivers/mtd/nand/gpmi-nfc/gpmi-nfc.h new file +549 -0

549 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#29 lore raw

PATCH v3 5/6 MTD: add support for imx23 and imx28

In reply to Huang Shijie

Add the code for imx23 and imx28.
The imx23 and imx28 share most of the same code.

---
 drivers/mtd/nand/gpmi-nfc/bch-mx23-mx28.h  |   88 +++++
 drivers/mtd/nand/gpmi-nfc/gpmi-mx23-mx28.h |  163 ++++++++
 drivers/mtd/nand/gpmi-nfc/hal-mx23-mx28.c  |  562 ++++++++++++++++++++++++++++
 drivers/mtd/nand/gpmi-nfc/rom-mx23.c       |  300 +++++++++++++++
 drivers/mtd/nand/gpmi-nfc/rom-mx28.c       |   66 ++++
 5 files changed, 1179 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/gpmi-nfc/bch-mx23-mx28.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/gpmi-mx23-mx28.h
 create mode 100644 drivers/mtd/nand/gpmi-nfc/hal-mx23-mx28.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/rom-mx23.c
 create mode 100644 drivers/mtd/nand/gpmi-nfc/rom-mx28.c
drivers/mtd/nand/gpmi-nfc/bch-mx23-mx28.h new file +88 -0
new file mode 100644
index 0000000..90af8cf
@@ -0,0 +1,88 @@
+/*
+ * Freescale GPMI NFC NAND Flash Driver
+ *
+ * Copyright 2008-2011 Freescale Semiconductor, Inc.
+ * Copyright 2008 Embedded Alley Solutions, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __GPMI_NFC_BCH_REGS_H
+#define __GPMI_NFC_BCH_REGS_H
+
+/*============================================================================*/
+#define HW_BCH_CTRL				0x00000000
+#define HW_BCH_CTRL_SET				0x00000004
+#define HW_BCH_CTRL_CLR				0x00000008
+#define HW_BCH_CTRL_TOG				0x0000000c
+
+#define BM_BCH_CTRL_COMPLETE_IRQ_EN		(1 << 8)
+#define BM_BCH_CTRL_COMPLETE_IRQ		(1 << 0)
+
+/*============================================================================*/
+#define HW_BCH_STATUS0				0x00000010
+#define HW_BCH_MODE				0x00000020
+#define HW_BCH_ENCODEPTR			0x00000030
+#define HW_BCH_DATAPTR				0x00000040
+#define HW_BCH_METAPTR				0x00000050
+#define HW_BCH_LAYOUTSELECT			0x00000070
+
+/*============================================================================*/
+#define HW_BCH_FLASH0LAYOUT0			0x00000080
+
+#define BP_BCH_FLASH0LAYOUT0_NBLOCKS		24
+#define BM_BCH_FLASH0LAYOUT0_NBLOCKS	(0xff << BP_BCH_FLASH0LAYOUT0_NBLOCKS)
+#define BF_BCH_FLASH0LAYOUT0_NBLOCKS(v)		\
+	(((v) << BP_BCH_FLASH0LAYOUT0_NBLOCKS) & BM_BCH_FLASH0LAYOUT0_NBLOCKS)
+
+#define BP_BCH_FLASH0LAYOUT0_META_SIZE		16
+#define BM_BCH_FLASH0LAYOUT0_META_SIZE	(0xff << BP_BCH_FLASH0LAYOUT0_META_SIZE)
+#define BF_BCH_FLASH0LAYOUT0_META_SIZE(v)	\
+	(((v) << BP_BCH_FLASH0LAYOUT0_META_SIZE)\
+					 & BM_BCH_FLASH0LAYOUT0_META_SIZE)
+
+#define BP_BCH_FLASH0LAYOUT0_ECC0		12
+#define BM_BCH_FLASH0LAYOUT0_ECC0	(0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
+#define BF_BCH_FLASH0LAYOUT0_ECC0(v)		\
+	(((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
+
+#define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE		0
+#define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE		\
+			(0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v)	\
+	(((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
+					 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+
+/*============================================================================*/
+#define HW_BCH_FLASH0LAYOUT1			0x00000090
+
+#define BP_BCH_FLASH0LAYOUT1_PAGE_SIZE		16
+#define BM_BCH_FLASH0LAYOUT1_PAGE_SIZE		\
+			(0xffff << BP_BCH_FLASH0LAYOUT1_PAGE_SIZE)
+#define BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(v)	\
+	(((v) << BP_BCH_FLASH0LAYOUT1_PAGE_SIZE) \
+					 & BM_BCH_FLASH0LAYOUT1_PAGE_SIZE)
+
+#define BP_BCH_FLASH0LAYOUT1_ECCN		12
+#define BM_BCH_FLASH0LAYOUT1_ECCN	(0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
+#define BF_BCH_FLASH0LAYOUT1_ECCN(v)		\
+	(((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
+
+#define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE		0
+#define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE		\
+			(0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v)	\
+	(((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
+					 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#endif
drivers/mtd/nand/gpmi-nfc/gpmi-mx23-mx28.h new file +163 -0

163 lines not on this page · raw message

drivers/mtd/nand/gpmi-nfc/hal-mx23-mx28.c new file +562 -0

562 lines not on this page · raw message

drivers/mtd/nand/gpmi-nfc/rom-mx23.c new file +300 -0

300 lines not on this page · raw message

drivers/mtd/nand/gpmi-nfc/rom-mx28.c new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#30 lore raw

PATCH v3 6/6 MTD : add GPMI driver in the config and Makefile

In reply to Huang Shijie

add the GPMI driver in the relevant Kconfig and Makefile in the MTD.

---
 drivers/mtd/nand/Kconfig           |   10 ++++++++++
 drivers/mtd/nand/Makefile          |    1 +
 drivers/mtd/nand/gpmi-nfc/Makefile |    6 ++++++
 3 files changed, 17 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/gpmi-nfc/Makefile
drivers/mtd/nand/Kconfig +10 -0
index 450afc5..86effe8 100644
@@ -426,6 +426,16 @@ config MTD_NAND_NANDSIM
 	  The simulator may simulate various NAND flash chips for the
 	  MTD nand layer.
 
+config MTD_NAND_GPMI_NFC
+        bool "GPMI NAND Flash Controller driver"
+        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
+	select MTD_PARTITIONS
+        help
+	 Enables NAND Flash support for IMX23 or IMX28.
+	 The GPMI controller is very powerful, with the help of BCH
+	 module, it can do the hardware ECC. The GPMI supports several
+	 NAND flashs at the same time.
+
 config MTD_NAND_PLATFORM
 	tristate "Support for generic platform NAND driver"
 	help
drivers/mtd/nand/Makefile +1 -0
index 8ad6fae..80d1f08 100644
@@ -48,5 +48,6 @@ obj-$(CONFIG_MTD_NAND_BCM_UMI)		+= bcm_umi_nand.o nand_bcm_umi.o
 obj-$(CONFIG_MTD_NAND_MPC5121_NFC)	+= mpc5121_nfc.o
 obj-$(CONFIG_MTD_NAND_RICOH)		+= r852.o
 obj-$(CONFIG_MTD_NAND_JZ4740)		+= jz4740_nand.o
+obj-$(CONFIG_MTD_NAND_GPMI_NFC)		+= gpmi-nfc/
 
 nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/gpmi-nfc/Makefile new file +6 -0
new file mode 100644
index 0000000..8d91314
@@ -0,0 +1,6 @@
+obj-$(CONFIG_MTD_NAND_GPMI_NFC) += gpmi-nfc.o
+gpmi-nfc-objs += gpmi-nfc-main.o
+gpmi-nfc-objs += hal-mx23-mx28.o
+gpmi-nfc-objs += rom-mx23.o
+gpmi-nfc-objs += rom-mx28.o
+gpmi-nfc-objs += ../nand_device_info.o
Signature · 1 line
1.7.0.4