mtd: rawnand: Add NAND controller support on Intel LGM SoC
Subsystems (4)
v7 cover mtd: rawnand: Add NAND controller support on Intel LGM SoC
This patch adds the new IP of Nand Flash Controller(NFC) support on Intel's Lightning Mountain(LGM) SoC.
DMA is used for burst data transfer operation, also DMA HW supports aligned 32bit memory address and aligned data access by default. DMA burst of 8 supported. Data register used to support the read/write operation from/to device.
NAND controller also supports in-built HW ECC engine.
NAND controller driver implements ->exec_op() to replace legacy hooks, these specific call-back method to execute NAND operations.
---
v7:
- indentation issue is fixed
- add error check for retrieve the resource from dt
- Rob's review comments addressed
- dt-schema build issue fixed with upgraded dt-schema
v6:
- update EBU_ADDR_SELx register base value build it from DT
- Add tabs in in Kconfig
- Rob's review comments addressed in YAML file
- add addr_sel0 and addr_sel1 reg-names in YAML example
v5:
- replace by 'HSNAND_CLE_OFFS | HSNAND_CS_OFFS' to NAND_WRITE_CMD and NAND_WRITE_ADDR
- remove the unused macros
- update EBU_ADDR_MASK(x) macro
- update the EBU_ADDR_SELx register values to be written
- add the example in YAML file
v4:
- add ebu_nand_cs structure for multiple-CS support
- mask/offset encoding for 0x51 value
- update macro HSNAND_CTL_ENABLE_ECC
- drop the op argument and un-used macros.
- updated the datatype and macros
- add function disable nand module
- remove ebu_host->dma_rx = NULL;
- rename MMIO address range variables to ebu and hsnand
- implement ->setup_data_interface()
- update label err_cleanup_nand and err_cleanup_dma
- add return value check in the nand_remove function
- add/remove tabs and spaces as per coding standard
- encoded CS ids by reg property
v3:
- Add depends on MACRO in Kconfig
- file name update in Makefile
- file name update to intel-nand-controller
- modification of MACRO divided like EBU, HSNAND and NAND
- add NAND_ALE_OFFS, NAND_CLE_OFFS and NAND_CS_OFFS
- rename lgm_ to ebu_ and _va suffix is removed in the whole file
- rename structure and varaibles as per review comments.
- remove lgm_read_byte(), lgm_dev_ready() and cmd_ctrl() un-used function
- update in exec_op() as per review comments
- rename function lgm_dma_exit() by lgm_dma_cleanup()
- hardcoded magic value for base and offset replaced by MACRO defined
- mtd_device_unregister() + nand_cleanup() instead of nand_release()
v2:
- implement the ->exec_op() to replaces the legacy hook-up.
- update the commit message
- YAML compatible string update to intel, lgm-nand-controller
- add MIPS maintainers and xway_nand driver author in CC
v1:
- initial version
Ramuthevar Vadivel Murugan (2):
dt-bindings: mtd: Add Nand Flash Controller support for Intel LGM SoC
mtd: rawnand: Add NAND controller support on Intel LGM SoC
.../devicetree/bindings/mtd/intel,lgm-nand.yaml | 91 +++ drivers/mtd/nand/raw/Kconfig | 8 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/intel-nand-controller.c | 748 +++++++++++++++++++++ 4 files changed, 848 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml create mode 100644 drivers/mtd/nand/raw/intel-nand-controller.c
Signature · 1 line
2.11.0
PATCH v7 1/2 dt-bindings: mtd: Add Nand Flash Controller support for Intel LGM SoC
From: Ramuthevar Vadivel Murugan <[email protected]>
Add YAML file for dt-bindings to support NAND Flash Controller on Intel's Lightning Mountain SoC.
--- .../devicetree/bindings/mtd/intel,lgm-nand.yaml | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +91 -0
@@ -0,0 +1,91 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mtd/intel,lgm-nand.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Intel LGM SoC NAND Controller Device Tree Bindings + +allOf: + - $ref: "nand-controller.yaml" + +maintainers: + - Ramuthevar Vadivel Murugan <[email protected]> + +properties: + compatible: + const: intel,lgm-nand-controller + + reg: + items: + - description: ebunand registers + - description: hsnand registers + - description: nand_cs0 external flash access + - description: nand_cs1 external flash access + - description: addr_sel0 memory region enable and access + - description: addr_sel1 memory region enable and access + + clocks: + maxItems: 1 + + dmas: + maxItems: 2 + + dma-names: + items: + - const: tx + - const: rx + +patternProperties: + "^nand@[a-f0-9]+$": + type: object + properties: + reg: + minimum: 0 + maximum: 7 + + nand-ecc-mode: true + + nand-ecc-algo: + const: hw + + additionalProperties: false + +required: + - compatible + - reg + - clocks + - clock-names + - dmas + - dma-names + +additionalProperties: false + +examples: + - | + nand-controller@e0f00000 { + compatible = "intel,lgm-nand"; + reg = <0xe0f00000 0x100>, + <0xe1000000 0x300>, + <0xe1400000 0x8000>, + <0xe1c00000 0x1000>, + <0x17400000 0x4>, + <0x17c00000 0x4>; + reg-names = "ebunand", "hsnand", "nand_cs0", "nand_cs1", + "addr_sel0","addr_sel1"; + clocks = <&cgu0 125>; + dmas = <&dma0 8>, <&dma0 9>; + dma-names = "tx", "rx"; + #address-cells = <1>; + #size-cells = <0>; + #clock-cells = <1>; + + nand@0 { + reg = <0>; + nand-on-flash-bbt; + #address-cells = <1>; + #size-cells = <1>; + }; + }; + +...
Signature · 1 line
2.11.0
PATCH v7 2/2 mtd: rawnand: Add NAND controller support on Intel LGM SoC
In reply to Ramuthevar,Vadivel MuruganXFrom: Ramuthevar Vadivel Murugan <[email protected]>
This patch adds the new IP of Nand Flash Controller(NFC) support on Intel's Lightning Mountain(LGM) SoC.
DMA is used for burst data transfer operation, also DMA HW supports aligned 32bit memory address and aligned data access by default. DMA burst of 8 supported. Data register used to support the read/write operation from/to device.
NAND controller driver implements ->exec_op() to replace legacy hooks, these specific call-back method to execute NAND operations.
--- drivers/mtd/nand/raw/Kconfig | 8 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/intel-nand-controller.c | 748 +++++++++++++++++++++++++++ 3 files changed, 757 insertions(+) create mode 100644 drivers/mtd/nand/raw/intel-nand-controller.c
drivers/mtd/nand/raw/Kconfig +8 -0
@@ -457,6 +457,14 @@ config MTD_NAND_CADENCE Enable the driver for NAND flash on platforms using a Cadence NAND controller. +config MTD_NAND_INTEL_LGM + tristate "Support for NAND controller on Intel LGM SoC" + depends on OF || COMPILE_TEST + depends on HAS_IOMEM + help + Enables support for NAND Flash chips on Intel's LGM SoC. + NAND flash controller interfaced through the External Bus Unit. + comment "Misc" config MTD_SM_COMMON
drivers/mtd/nand/raw/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_MTD_NAND_TEGRA) += tegra_nand.o obj-$(CONFIG_MTD_NAND_STM32_FMC2) += stm32_fmc2_nand.o obj-$(CONFIG_MTD_NAND_MESON) += meson_nand.o obj-$(CONFIG_MTD_NAND_CADENCE) += cadence-nand-controller.o +obj-$(CONFIG_MTD_NAND_INTEL_LGM) += intel-nand-controller.o nand-objs := nand_base.o nand_legacy.o nand_bbt.o nand_timings.o nand_ids.o nand-objs += nand_onfi.o
drivers/mtd/nand/raw/intel-nand-controller.c new file +748 -0
748 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 12 lines · Ramuthevar,Vadivel MuruganX
From: Ramuthevar Vadivel Murugan <[email protected]>
This patch adds the new IP of Nand Flash Controller(NFC) support on Intel's Lightning Mountain(LGM) SoC.
DMA is used for burst data transfer operation, also DMA HW supports aligned 32bit memory address and aligned data access by default. DMA burst of 8 supported. Data register used to support the read/write operation from/to device.
NAND controller driver implements ->exec_op() to replace legacy hooks, these specific call-back method to execute NAND operations.
...
drivers/mtd/nand/raw/intel-nand-controller.c line 667
Quoted 12 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +11
-0+ ebu_host->dma_tx =dma_request_chan (dev,"tx" ); +if (IS_ERR (ebu_host->dma_tx)) { + ret =PTR_ERR (ebu_host->dma_tx); +dev_err (dev,"DMA tx channel request fail!.\n" ); + goto err_cleanup_dma; + } + + ebu_host->dma_rx =dma_request_chan (dev,"rx" ); +if (IS_ERR (ebu_host->dma_rx)) { + ret =PTR_ERR (ebu_host->dma_rx); +dev_err (dev,"DMA tx channel request fail!.\n" );
rx ?
Quoted 2 lines
(quoted diff) +2
-0+ goto err_cleanup_dma; + }
...
drivers/mtd/nand/raw/intel-nand-controller.c line 718
Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +5
-0+static int ebu_nand_remove (struct platform_device *pdev) +{ +struct ebu_nand_controller *ebu_host =platform_get_drvdata (pdev); + +if (ebu_host) {
I dunno why you need this check? Maybe I forgot your answer to my comment?
Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9
-0+mtd_device_unregister (nand_to_mtd (&ebu_host->chip)); +nand_cleanup (&ebu_host->chip); +ebu_nand_disable (&ebu_host->chip); +ebu_dma_cleanup (ebu_host); +clk_disable_unprepare (ebu_host->clk); + } + +return 0 ; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
kbuild test robot
build botThank you for the patch! Perhaps something to improve:
Hi "Ramuthevar,Vadivel,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on robh/for-next]
[also build test WARNING on arm-soc/for-next linus/master linux/master v5.7-rc5 next-20200514] [cannot apply to mtd/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Ramuthevar-Vadivel-MuruganX/mtd-rawnand-Add-NAND-controller-support-on-Intel-LGM-SoC/20200515-185904 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next reproduce: # apt-get install sparse # sparse version: v0.6.1-193-gb8fad4bc-dirty make ARCH=x86_64 allmodconfig make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted __be32 [assignedunsigned int val @@ >> drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: expected unsigned int val >> drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: got restricted __be32 [assigned] [usertype] reg
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted __be32 [assignedunsigned int val @@
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: expected unsigned int val
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: got restricted __be32 [assigned] [usertype] reg
vim +441 drivers/mtd/nand/raw/intel-nand-controller.c
420
421 static int ebu_nand_write_page_hwecc(struct nand_chip *chip, const u8 *buf,
422 int oob_required, int page)
423 {
424 struct mtd_info *mtd = nand_to_mtd(chip);
425 struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
426 void __iomem *int_sta = ebu_host->hsnand + HSNAND_INT_STA;
427 int ret, val, x;
428 __be32 reg;
429
430 ebu_nand_trigger(ebu_host, page, NAND_CMD_SEQIN);
431
432 ret = ebu_dma_start(ebu_host, DMA_MEM_TO_DEV, buf, mtd->writesize);
433 if (ret)
434 return ret;
435
436 if (oob_required) {
437 const u8 *pdata;
438
439 pdata = chip->oob_poi;
440 reg = cpu_to_be32(*pdata++);
> 441 writel(reg, ebu_host->hsnand + HSNAND_CMSG_0);
442
443 reg = cpu_to_be32(*pdata);
444 writel(reg, ebu_host->hsnand + HSNAND_CMSG_1);
445 }
446
447 ret = readl_poll_timeout_atomic(int_sta, val,
448 !(val & HSNAND_INT_STA_WR_C), 10, 1000);
449 if (ret)
450 return -EIO;
451
452 x = readl(ebu_host->hsnand + HSNAND_CTL);
453 x &= ~HSNAND_CTL_GO;
454 writel(x, ebu_host->hsnand + HSNAND_CTL);
455
456 return 0;
457 }
458
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 9 lines · kbuild test robot
sparse warnings: (new ones prefixed by >>)
Quoted 3 lines
Quoted 3 lines
drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: expected unsigned int valdrivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: got restricted__be32[assigned] [usertype] reg
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: expected unsigned int val
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: got restricted__be32[assigned] [usertype] reg
Quoted 5 lines
440 reg = cpu_to_be32(*pdata++);Quoted 1 line
441
writel(reg, ebu_host->hsnand + HSNAND_CMSG_0);442
443 reg = cpu_to_be32(*pdata); 444 writel(reg, ebu_host->hsnand + HSNAND_CMSG_1);
On BE:cpu_to_be32 -> no-opwritel() -> converts reg to LE
On LE:cpu_to_be32 -> converts to BEwritel() -> no-op (in terms of conversion)
Seems to me that the proper API (if above is intended) should be swab32(). But something tells me that above is broken (or my understanding is wrong).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
Quoted 5 lines · kbuild test robot
440 reg = cpu_to_be32(*pdata++);Quoted 1 line
441
writel(reg, ebu_host->hsnand + HSNAND_CMSG_0);442
443 reg = cpu_to_be32(*pdata); 444 writel(reg, ebu_host->hsnand + HSNAND_CMSG_1);On BE:
cpu_to_be32-> no-opwritel()-> converts reg to LE
Quoted 6 lines
On LE:
cpu_to_be32-> converts to BEwritel()-> no-op (in terms of conversion)Seems to me that the proper API (if above is intended) should be
swab32(). But something tells me that above is broken (or my understanding is wrong).
And perhaps it should use lo_hi_writeq() or something like that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 9 lines · kbuild test robot
sparse warnings: (new ones prefixed by >>)
Quoted 3 lines
Quoted 3 lines
drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: expected unsigned int valdrivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: got restricted__be32[assigned] [usertype] reg
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: expected unsigned int val
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: got restricted__be32[assigned] [usertype] regQuoted 5 lines
440 reg = cpu_to_be32(*pdata++);Quoted 1 line
441
writel(reg, ebu_host->hsnand + HSNAND_CMSG_0);442
443 reg = cpu_to_be32(*pdata); 444 writel(reg, ebu_host->hsnand + HSNAND_CMSG_1);On BE:
cpu_to_be32-> no-opwritel()-> converts reg to LE
Quoted 6 lines
On LE:
cpu_to_be32-> converts to BEwritel()-> no-op (in terms of conversion)Seems to me that the proper API (if above is intended) should be
swab32(). But something tells me that above is broken (or my understanding is wrong).
iowrite_be32() is the correct way to store word into a big-endian mmio register, if that is the intention here.
Arnd
Hi Arnd, Andy,
Quoted 28 lines · Arnd Bergmann
Quoted 26 lines · Andy Shevchenko
Quoted 9 lines · kbuild test robot
sparse warnings: (new ones prefixed by >>)
Quoted 3 lines
Quoted 3 lines
drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@drivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: expected unsigned int valdrivers/mtd/nand/raw/intel-nand-controller.c:441:24: sparse: got restricted__be32[assigned] [usertype] reg
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int val @@ got restricted__be32[assignedunsigned int val @@
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: expected unsigned int val
drivers/mtd/nand/raw/intel-nand-controller.c:444:24: sparse: got restricted__be32[assigned] [usertype] regQuoted 5 lines
440 reg =
cpu_to_be32(*pdata++);Quoted 1 line
441
writel(reg, ebu_host->hsnand + HSNAND_CMSG_0);442 443 reg = cpu_to_be32(*pdata); 444 writel(reg, ebu_host->hsnand + HSNAND_CMSG_1);On BE:
cpu_to_be32-> no-opwritel()-> converts reg to LEOn LE:
cpu_to_be32-> converts to BEwritel()-> no-op (in terms of conversion)
Quoted 5 lines
Quoted 2 lines
Seems to me that the proper API (if above is intended) should be
swab32(). But something tells me that above is broken (or my understanding is wrong).
iowrite_be32()is the correct way to store word into a big-endian mmio register, if that is the intention here.
Thank you for suggestions to use iowrite32be(), it suits exactly.
Regards
Vadivel
Quoted 3 lines
Arnd
Quoted 8 lines · Vadivel MuruganX
Quoted 6 lines · Arnd Bergmann
Quoted 1 line · Andy Shevchenko
On Fri, May 15, 2020 at 4:48 PM kbuild test robot <[email protected]> wrote:
iowrite_be32()is the correct way to store word into a big-endian mmio register, if that is the intention here.Thank you for suggestions to use
iowrite32be(), it suits exactly.
Can you before doing this comment what is the real intention here?
And note, if you are going to use iowrite*() / ioread*() in one place, you will probably need to replace all of the read*() / write*() to respective io* API.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Vadivel MuruganX
Quoted 6 lines · Arnd Bergmann
Quoted 1 line · Andy Shevchenko
On Fri, May 15, 2020 at 4:48 PM kbuild test robot <[email protected]> wrote:
iowrite_be32()is the correct way to store word into a big-endian mmio register, if that is the intention here.
Quoted 7 lines
Quoted 1 line
Thank you for suggestions to use
iowrite32be(), it suits exactly.Can you before doing this comment what is the real intention here?
And note, if you are going to use iowrite*() / ioread*() in one place, you will probably need to replace all of the read*() / write*() to respective io* API.
The way that ioread/iowrite are defined, they are required to be a superset of what readl/writel do and can take __iomem pointers from either ioremap() or ioport_map()/pci_iomap() style mappings, while readl/writel are only required to work with ioremap().
There is no technical requirement to stick to one set or the other for ioremap(), but the overhead of ioread/iowrite is also small enough that it generally does not hurt.
Arnd
Quoted 19 lines · Arnd Bergmann
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Vadivel MuruganX
Quoted 6 lines · Arnd Bergmann
Quoted 1 line · Andy Shevchenko
On Fri, May 15, 2020 at 4:48 PM kbuild test robot <[email protected]> wrote:
iowrite_be32()is the correct way to store word into a big-endian mmio register, if that is the intention here.Quoted 7 lines
Quoted 1 line
Thank you for suggestions to use
iowrite32be(), it suits exactly.Can you before doing this comment what is the real intention here?
And note, if you are going to use iowrite*() / ioread*() in one place, you will probably need to replace all of the read*() / write*() to respective io* API.
Quoted 8 lines
The way that ioread/iowrite are defined, they are required to be a superset of what readl/writel do and can take
__iomempointers from eitherioremap()or ioport_map()/pci_iomap() style mappings, while readl/writel are only required to work withioremap().There is no technical requirement to stick to one set or the other for
ioremap(), but the overhead of ioread/iowrite is also small enough that it generally does not hurt.
Right, my suggestion is solely for consistency. It would be a bit weird to see readl() along with ioread32() in the same driver (in case there are no differentiated callbacks specifically for different type of IP).
Signature · 2 lines
With Best Regards, Andy Shevchenko