MTD: LPC32xx MLC NAND driver
Subsystems (4)
PATCH 1/1 MTD: LPC32xx MLC NAND driver
This patch adds a driver for the MLC NAND controller of the LPC32xx SoC.
---
Applies to v3.4-rc7 + LPC32xx SLC NAND driver (Kconfig + Makefile)
Documentation/devicetree/bindings/mtd/lpc32xx-mlc.txt | 50 drivers/mtd/nand/Kconfig | 13 drivers/mtd/nand/Makefile | 1 drivers/mtd/nand/lpc32xx_nand_mlc.c | 960 ++++++++++++++++++ 4 files changed, 1023 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mtd/lpc32xx-mlc.txt new file +50 -0
@@ -0,0 +1,50 @@ +NXP LPC32xx SoC NAND MLC controller + +Required properties: +- compatible: "nxp,lpc3220-mlc" +- reg: Address and size of the controller +- interrupts: The NAND interrupt specification +- gpios: GPIO specification for NAND write protect + +The following required properties are very controller specific. See the LPC32xx +User Manual 7.5.14 MLC NAND Timing Register (the values here are specified in +Hz, to make them independent of actual clock speed and to provide for good +accuracy:) +- nxp,tcea_delay: TCEA_DELAY +- nxp,busy_delay: BUSY_DELAY +- nxp,nand_ta: NAND_TA +- nxp,rd_high: RD_HIGH +- nxp,rd_low: RD_LOW +- nxp,wr_high: WR_HIGH +- nxp,wr_low: WR_LOW + +Optional subnodes: +- Partitions, see Documentation/devicetree/bindings/mtd/partition.txt + +Example: + + mlc: flash at 200A8000 { + compatible = "nxp,lpc3220-mlc"; + reg = <0x200A8000 0x11000>; + interrupts = <11 0>; + #address-cells = <1>; + #size-cells = <1>; + + nxp,tcea-delay = <333333333>; + nxp,busy-delay = <10000000>; + nxp,nand-ta = <18181818>; + nxp,rd-high = <31250000>; + nxp,rd-low = <45454545>; + nxp,wr-high = <40000000>; + nxp,wr-low = <83333333>; + gpios = <&gpio 5 19 1>; /* GPO_P3 19, active low */ + + mtd0 at 00000000 { + label = "boot"; + reg = <0x00000000 0x00064000>; + read-only; + }; + + ... + + };
drivers/mtd/nand/Kconfig +12 -1
@@ -415,7 +415,7 @@ config MTD_NAND_PXA3xx PXA3xx processors config MTD_NAND_SLC_LPC32XX - bool "NXP LPC32xx SLC Controller" + tristate "NXP LPC32xx SLC Controller" depends on ARCH_LPC32XX help Enables support for NXP's LPC32XX SLC (i.e. for Single Level Cell
@@ -425,6 +425,17 @@ config MTD_NAND_SLC_LPC32XX Please check the actual NAND chip connected and its support by the SLC NAND controller. +config MTD_NAND_MLC_LPC32XX + tristate "NXP LPC32xx MLC Controller" + depends on ARCH_LPC32XX + help + Uses the LPC32XX MLC (i.e. for Multi Level Cell chips) NAND + controller. This is the default for the WORK92105 controller + board. + + Please check the actual NAND chip connected and its support + by the MLC 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
@@ -41,6 +41,7 @@ obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_ 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_MLC_LPC32XX) += lpc32xx_nand_mlc.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_mlc.c new file +960 -0
960 lines not on this page · raw message
Quoted 7 lines · Roland Stigge
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +7
-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 ;
drivers/mtd/nand/lpc32xx_nand_mlc.c line 442
Quoted 10 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +10
-0+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; +if (dmaengine_slave_config (host->dma_chan, &host->dma_slave_config)) { +dev_err (mtd->dev.parent,"Failed to setup DMA slave\n" ); +return -ENXIO ; + }
Can you explain why you need to issue this call for every transfer?
The 'direction' argument should be ignored by all modern DMA engine drivers (we've decided previously to get rid of it). As far as I can see, the device address nor any of the other parameters ever change between transfers.
drivers/mtd/nand/lpc32xx_nand_mlc.c line 446
Quoted 4 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +4
-0+ +sg_init_one (&host->sgl, mem, len); + + res =dma_map_sg (host->dma_chan->device->dev, &host->sgl,1 , dir);
Also note that dma transfer directions and dma data directions are different things. You shouldn't mix the two.
Quoted 15 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +15
-0+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; + } + +init_completion (&host->comp_dma); + desc->callback = lpc32xx_dma_complete_func; + desc->callback_param = &host->comp_dma; +
drivers/mtd/nand/lpc32xx_nand_mlc.c line 471
Quoted 10 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +10
-0+ cookie =dmaengine_submit (desc); +if (dma_submit_error (cookie)) { +dev_err (mtd->dev.parent,"Failed to dmaengine_submit()\n" ); + goto out1; + } +dma_async_issue_pending (host->dma_chan); + +wait_for_completion_timeout (&host->comp_dma,msecs_to_jiffies (1000 )); + +dma_sync_sg_for_cpu (host->dma_chan->device->dev, &host->sgl,1 , dir);
Why sync? What's wrong with dma_unmap()? Have you tested this with DMA API debugging enabled?
drivers/mtd/nand/lpc32xx_nand_mlc.c line 656
Quoted 4 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +4
-0+if (dma_set_mask (host->dma_chan->device->dev,0xFFFFFFFF )) { +dev_err (mtd->dev.parent,"Failed to set dma mask\n" ); + goto out1; + }
No. You shouldn't do this to a device that you're not in charge of. If that's important for the DMA engine device, then the DMA engine device driver should have already done that.
Otherwise, you'll be potentially modifying the DMA mask for a device _you_ don't own, and which is potentially already in use.
Hi Russell!
Thanks for your notes!
Quoted 13 lines · Russell King - ARM Linux
Quoted 12 lines · Roland Stigge
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +12
-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;
Quoted 8 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c line 442
Quoted 5 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +5
-0+ host->dma_slave_config.dst_addr = dma; +if (dmaengine_slave_config (host->dma_chan, &host->dma_slave_config)) { +dev_err (mtd->dev.parent,"Failed to setup DMA slave\n" ); +return -ENXIO ; + }The 'direction' argument should be ignored by all modern DMA engine drivers
Good - this way, I can move dmaengine_slave_config() to the dma_setup() function, i.e., to probe().
However, I needed to set it there to some initial value (e.g., DMA_DEV_TO_MEM) - otherwise the amba-pl08x driver didn't accept it. Is this a bug in the pl08x driver?
Can we remove the .direction element from the struct dma_slave_config to prevent others from making the same mistakes? Or is it useful for sth. else still?
Quoted 7 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c line 446
Quoted 4 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +4
-0+ +sg_init_one (&host->sgl, mem, len); + + res =dma_map_sg (host->dma_chan->device->dev, &host->sgl,1 , dir);Also note that dma transfer directions and dma data directions are different things. You shouldn't mix the two.
Thanks for pointing this out - I wasn't aware that the distinction between the two is so important. Also consider e.g.:
arch/arm/mm/dma-mapping.c:
/**
* dma_map_sg - map a set of SG buffers for streaming mode DMA
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
* @sg: list of buffers
* @nents: number of buffers to map
* @dir: DMA transfer direction
^^^^^^^^^^^^^^^^^^^^^^
*
[...]
* Device ownership issues as mentioned for dma_map_single are the same
* here.
*/
int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir) ^^^^^^^^^^^^^^^^^^^^^^^
;-)
Roland
Quoted 7 lines · Roland Stigge
Quoted 7 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c line 446
Quoted 4 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +4
-0+ +sg_init_one (&host->sgl, mem, len); + + res =dma_map_sg (host->dma_chan->device->dev, &host->sgl,1 , dir);Also note that dma transfer directions and dma data directions are different things. You shouldn't mix the two.
Can I safely use DMA_BIDIRECTIONAL here (practically, it works - just tested), because the caller asks for read _or_ write? Or do I need to formally convert enum dma_transfer_direction to enum dma_data_direction?
Thanks in advance,
Roland
Quoted 23 lines · Roland Stigge
Quoted 13 lines · Russell King - ARM Linux
Quoted 12 lines · Roland Stigge
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +12
-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;Quoted 8 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c line 442
Quoted 5 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +5
-0+ host->dma_slave_config.dst_addr = dma; +if (dmaengine_slave_config (host->dma_chan, &host->dma_slave_config)) { +dev_err (mtd->dev.parent,"Failed to setup DMA slave\n" ); +return -ENXIO ; + }The 'direction' argument should be ignored by all modern DMA engine drivers
Quoted 6 lines
Good - this way, I can move
dmaengine_slave_config()to thedma_setup()function, i.e., toprobe().However, I needed to set it there to some initial value (e.g.,
DMA_DEV_TO_MEM) - otherwise the amba-pl08x driver didn't accept it. Is this a bug in the pl08x driver?
At some point, pl08x should lose all checking on that... It should select the parameters from the DMA slave config at prepare time instead.
Quoted 3 lines
Can we remove the .direction element from the struct
dma_slave_configto prevent others from making the same mistakes? Or is it useful for sth. else still?
That's the intention, but as yet there's been little effort in terms of patches. It requires co-operation from all the folk with DMA engine drivers to sort their stuff out as well...
Quoted 11 lines
Quoted 7 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c line 446
Quoted 4 lines
drivers/mtd/nand/lpc32xx_nand_mlc.c new file +4
-0+ +sg_init_one (&host->sgl, mem, len); + + res =dma_map_sg (host->dma_chan->device->dev, &host->sgl,1 , dir);Also note that dma transfer directions and dma data directions are different things. You shouldn't mix the two.
Thanks for pointing this out - I wasn't aware that the distinction between the two is so important. Also consider e.g.:
Quoted 8 lines
arch/arm/mm/dma-mapping.c:
/**
*dma_map_sg- map a set of SG buffers for streaming mode DMA
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
* @sg: list of buffers
* @nents: number of buffers to map
* @dir: DMA transfer direction^^^^^^^^^^^^^^^^^^^^^^
This pre-dates DMA engine renaming their 'dma_data_direction' to 'dma_transfer_direction', and it's really unfortunate that it now causes confusion.
The key thing is the enum type, not the comments.