Skip to contentSkip to conversation

MTD: LPC32xx SLC NAND driver

PATCH Superseded Roland Stigge 3 participants 7 messages Jun 3, 2012

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 MTD: LPC32xx SLC NAND driver

This patch adds support for the SLC NAND controller inside the LPC32xx SoC.

---
Applies to 3.5-rc1

Changes since v3:
* Adjusted to mtd API changes

Changes since v2:
* Fixed dma data direction and dma transfer direction differences
* Removed dma_sync_sg_for_cpu() - not necessary due to unmap
* Removed dma_set_mask()

Changes since v1:
* Fixed busy wait DMA timeout with cpu_relax() - unexpected condition anyway
* Fixed comment of dma_setup function
* Minor cleanup

Thanks to Artem Bityutskiy and Huang Shijie for reviewing!

 Documentation/devicetree/bindings/mtd/lpc32xx-slc.txt |   52 
 drivers/mtd/nand/Kconfig                              |   11 
 drivers/mtd/nand/Makefile                             |    1 
 drivers/mtd/nand/lpc32xx_nand_slc.c                   | 1062 ++++++++++++++++++
 4 files changed, 1126 insertions(+)
Documentation/devicetree/bindings/mtd/lpc32xx-slc.txt new file +52 -0
@@ -0,0 +1,52 @@
+NXP LPC32xx SoC NAND SLC controller
+
+Required properties:
+- compatible: "nxp,lpc3220-slc"
+- reg: Address and size of the controller
+- nand-on-flash-bbt: Use bad block table on flash
+- gpios: GPIO specification for NAND write protect
+
+The following required properties are very controller specific. See the LPC32xx
+User Manual:
+- nxp,wdr-clks: Delay before Ready signal is tested on write (W_RDY)
+- nxp,rdr-clks: Delay before Ready signal is tested on read (R_RDY)
+(The following values are specified in Hz, to make them independent of actual
+clock speed:)
+- nxp,wwidth: Write pulse width (W_WIDTH)
+- nxp,whold: Write hold time (W_HOLD)
+- nxp,wsetup: Write setup time (W_SETUP)
+- nxp,rwidth: Read pulse width (R_WIDTH)
+- nxp,rhold: Read hold time (R_HOLD)
+- nxp,rsetup: Read setup time (R_SETUP)
+
+Optional subnodes:
+- Partitions, see Documentation/devicetree/bindings/mtd/partition.txt
+
+Example:
+
+	slc: flash at 20020000 {
+		compatible = "nxp,lpc3220-slc";
+		reg = <0x20020000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		nxp,wdr-clks = <14>;
+		nxp,wwidth = <40000000>;
+		nxp,whold = <100000000>;
+		nxp,wsetup = <100000000>;
+		nxp,rdr-clks = <14>;
+		nxp,rwidth = <40000000>;
+		nxp,rhold = <66666666>;
+		nxp,rsetup = <100000000>;
+		nand-on-flash-bbt;
+		gpios = <&gpio 5 19 1>; /* GPO_P3 19, active low */
+
+		mtd0 at 00000000 {
+			label = "phy3250-boot";
+			reg = <0x00000000 0x00064000>;
+			read-only;
+		};
+
+		...
+
+	};
drivers/mtd/nand/Kconfig +11 -0
@@ -454,6 +454,17 @@ config MTD_NAND_PXA3xx
 	  This enables the driver for the NAND flash device found on
 	  PXA3xx processors
 
+config MTD_NAND_SLC_LPC32XX
+	bool "NXP LPC32xx SLC Controller"
+	depends on ARCH_LPC32XX
+	help
+	  Enables support for NXP's LPC32XX SLC (i.e. for Single Level Cell
+	  chips) NAND controller. This is the default for the PHYTEC 3250
+	  reference board which contains a NAND256R3A2CZA6 chip.
+
+	  Please check the actual NAND chip connected and its support
+	  by the SLC NAND controller.
+
 config MTD_NAND_CM_X270
 	tristate "Support for NAND Flash on CM-X270 modules"
 	depends on MACH_ARMCORE
drivers/mtd/nand/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_MTD_NAND_ORION)		+= orion_n
 obj-$(CONFIG_MTD_NAND_FSL_ELBC)		+= fsl_elbc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_IFC)		+= fsl_ifc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_UPM)		+= fsl_upm.o
+obj-$(CONFIG_MTD_NAND_SLC_LPC32XX)      += lpc32xx_nand_slc.o
 obj-$(CONFIG_MTD_NAND_SH_FLCTL)		+= sh_flctl.o
 obj-$(CONFIG_MTD_NAND_MXC)		+= mxc_nand.o
 obj-$(CONFIG_MTD_NAND_SOCRATES)		+= socrates_nand.o
drivers/mtd/nand/lpc32xx_nand_slc.c new file +1062 -0

1,062 lines not on this page · raw message

#1 lore raw
Quoted 38 lines · Roland Stigge
drivers/mtd/nand/lpc32xx_nand_slc.c new file +38 -0
+static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma,
+			    void *mem, int len, enum dma_transfer_direction dir)
+{
+	struct nand_chip *chip = mtd->priv;
+	struct lpc32xx_nand_host *host = chip->priv;
+	struct dma_async_tx_descriptor *desc;
+	int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
+	int res;
+	dma_cookie_t cookie;
+
+	host->dma_slave_config.direction = dir;
+	host->dma_slave_config.src_addr = dma;
+	host->dma_slave_config.dst_addr = dma;
+	host->dma_slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_slave_config.src_maxburst = 4;
+	host->dma_slave_config.dst_maxburst = 4;
+	/* DMA controller does flow control: */
+	host->dma_slave_config.device_fc = false;
+	if (dmaengine_slave_config(host->dma_chan, &host->dma_slave_config)) {
+		dev_err(mtd->dev.parent, "Failed to setup DMA slave\n");
+		return -ENXIO;
+	}
+
+	sg_init_one(&host->sgl, mem, len);
+
+	res = dma_map_sg(host->dma_chan->device->dev, &host->sgl, 1,
+			 DMA_BIDIRECTIONAL);
+	if (res != 1) {
+		dev_err(mtd->dev.parent, "Failed to map sg list\n");
+		return -ENXIO;
+	}
+	desc = dmaengine_prep_slave_sg(host->dma_chan, &host->sgl, 1, dir,
+				       flags);
+	if (!desc) {
+		dev_err(mtd->dev.parent, "Failed to prepare slave sg\n");
+		goto out1;
+	}

drivers/mtd/nand/lpc32xx_nand_slc.c line 487

Quoted 10 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +10 -0
+
+	init_completion(&host->comp);
+	desc->callback = lpc32xx_dma_complete_func;
+	desc->callback_param = &host->comp;
+
+	cookie = dmaengine_submit(desc);
+	if (dma_submit_error(cookie)) {
+		dev_err(mtd->dev.parent, "Failed to dmaengine_submit()\n");
+		goto out1;
+	}

dmaengine_submit() is no longer allowed to fail, so you don't need this check here anymore. It's been that way for a long time.

drivers/mtd/nand/lpc32xx_nand_slc.c line 490

Quoted 3 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +3 -0
+	dma_async_issue_pending(host->dma_chan);
+
+	wait_for_completion_timeout(&host->comp, msecs_to_jiffies(1000));

What about unmapping the buffer upon completion?

Quoted 7 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +7 -0
+
+	return 0;
+out1:
+	dma_unmap_sg(host->dma_chan->device->dev, &host->sgl, 1,
+		     DMA_BIDIRECTIONAL);
+	return -ENXIO;
+}
#2 lore raw

PLEASE, REMOVE MY EMAIL ADDRESS FROM ITS LIST.

Em 03-06-2012 16:09, Russell King - ARM Linux escreveu:

Quoted 68 lines · Roland Stigge
Quoted 38 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +38 -0
+static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma,
+			    void *mem, int len, enum dma_transfer_direction dir)
+{
+	struct nand_chip *chip = mtd->priv;
+	struct lpc32xx_nand_host *host = chip->priv;
+	struct dma_async_tx_descriptor *desc;
+	int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
+	int res;
+	dma_cookie_t cookie;
+
+	host->dma_slave_config.direction = dir;
+	host->dma_slave_config.src_addr = dma;
+	host->dma_slave_config.dst_addr = dma;
+	host->dma_slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_slave_config.src_maxburst = 4;
+	host->dma_slave_config.dst_maxburst = 4;
+	/* DMA controller does flow control: */
+	host->dma_slave_config.device_fc = false;
+	if (dmaengine_slave_config(host->dma_chan,&host->dma_slave_config)) {
+		dev_err(mtd->dev.parent, "Failed to setup DMA slave\n");
+		return -ENXIO;
+	}
+
+	sg_init_one(&host->sgl, mem, len);
+
+	res = dma_map_sg(host->dma_chan->device->dev,&host->sgl, 1,
+			 DMA_BIDIRECTIONAL);
+	if (res != 1) {
+		dev_err(mtd->dev.parent, "Failed to map sg list\n");
+		return -ENXIO;
+	}
+	desc = dmaengine_prep_slave_sg(host->dma_chan,&host->sgl, 1, dir,
+				       flags);
+	if (!desc) {
+		dev_err(mtd->dev.parent, "Failed to prepare slave sg\n");
+		goto out1;
+	}

drivers/mtd/nand/lpc32xx_nand_slc.c line 487

Quoted 10 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +10 -0
+
+	init_completion(&host->comp);
+	desc->callback = lpc32xx_dma_complete_func;
+	desc->callback_param =&host->comp;
+
+	cookie = dmaengine_submit(desc);
+	if (dma_submit_error(cookie)) {
+		dev_err(mtd->dev.parent, "Failed to dmaengine_submit()\n");
+		goto out1;
+	}

dmaengine_submit() is no longer allowed to fail, so you don't need this check here anymore. It's been that way for a long time.

drivers/mtd/nand/lpc32xx_nand_slc.c line 490

Quoted 3 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +3 -0
+	dma_async_issue_pending(host->dma_chan);
+
+	wait_for_completion_timeout(&host->comp, msecs_to_jiffies(1000));

What about unmapping the buffer upon completion?

drivers/mtd/nand/lpc32xx_nand_slc.c line 497

Quoted 7 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +7 -0
+
+	return 0;
+out1:
+	dma_unmap_sg(host->dma_chan->device->dev,&host->sgl, 1,
+		     DMA_BIDIRECTIONAL);
+	return -ENXIO;
+}

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw

Re: PLEASE, REMOVE MY EMAIL ADDRESS FROM ITS LIST.

Sigh, here we go again... why are you emailing me directly over this issue?

In short, I can't. I don't run these lists anymore. Please look at the bottom of any message you've received from the list to find the URL you need to go to to control your subscription.

Thanks.

#5 lore raw
In reply to Russell King - ARM Linux

Hi!

Thanks for the suggestions!

Quoted 5 lines · Russell King - ARM Linux

drivers/mtd/nand/lpc32xx_nand_slc.c line 490

Quoted 3 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +3 -0
+	dma_async_issue_pending(host->dma_chan);
+
+	wait_for_completion_timeout(&host->comp, msecs_to_jiffies(1000));

What about unmapping the buffer upon completion?

OK - by not specifying DMA_COMPL_SKIP_*_UNMAP in flags, I was thinking that this happens somehow magically. ;-) But maybe I was just confused.

Thanks,

Roland

#6 lore raw
Quoted 5 lines · Roland Stigge

Hi!

Thanks for the suggestions!

On 03/06/12 21:09, Russell King - ARM Linux wrote:

Quoted 8 lines
Quoted 5 lines

drivers/mtd/nand/lpc32xx_nand_slc.c line 490

Quoted 3 lines
drivers/mtd/nand/lpc32xx_nand_slc.c new file +3 -0
+	dma_async_issue_pending(host->dma_chan);
+
+	wait_for_completion_timeout(&host->comp, msecs_to_jiffies(1000));

What about unmapping the buffer upon completion?

OK - by not specifying DMA_COMPL_SKIP_*_UNMAP in flags, I was thinking that this happens somehow magically. ;-) But maybe I was just confused.

Slave transfers should never be automatically unmapped by the DMA engine driver.

#4 lore raw

Re: PLEASE, REMOVE MY EMAIL ADDRESS FROM ITS LIST.

In reply to Russell King - ARM Linux

I'm sorry, mates.

Em 03-06-2012 16:33, Russell King - ARM Linux escreveu:

Quoted 10 lines

Sigh, here we go again... why are you emailing me directly over this issue?

In short, I can't. I don't run these lists anymore. Please look at the bottom of any message you've received from the list to find the URL you need to go to to control your subscription.

Thanks.
.