Skip to contentSkip to conversation

mtd: rawnand: Add Cadence NAND controller driver

PATCH Superseded Piotr Sroka 2 participants 4 messages Sep 16, 2019

Subsystems (4)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover mtd: rawnand: Add Cadence NAND controller driver

Driver for Cadence HPNFC NAND flash controller.

HW DMA interface
Page write and page read operations are executed in Command DMA mode. Commands are defined by DMA descriptors.
In CDMA mode controller own DMA engine is used (Master DMA mode). Other operations defined by nand_op_instr are executed in "Generic" mode. In that mode data can be transferred only in by Slave DMA interface. Slave DMA interface can be connected directly to AXI or to an external DMA engine.

HW ECC support
Cadence NAND controller supports HW BCH correction.
ECC is transparent from SW point of view. It means that ECC codes
are calculated and written to flash. In read operation ECC codes are removed from user data and correction is made if necessary.

Controller data layout with ECC enabled:
-------------------------------------------------------------------------
|Sec 1 | ECC | Sec 2 | ECC ...... | Sec n | OOB (32B) | ECC | unused data |
-------------------------------------------------------------------------

Last sector is extended by a out-bound data. Tha maximum size of "extra data" is 32 bytes. The oob data are protected by ECC. If we need to read only oob data the whole last sector must be read. It is because oob data are part of last sector. Reading oob function always reads whole sector and writing oob function always writes whole last sector. Written data are interleaved with the ECC therefore part of the last sector is located on oob area and the BBM is overwritten.

SKIP BYTES feature
To protect BBM the "skip byte" HW feature is used.
Write page function copies BBM value from first byte of oob data to BBM offset defined by manufacturer. Read page functions always takes BBM from flash manufacturer offset. It causes that for not written pages the proper value of BBM marker is used.

ECC size calculation
Information about supported ECC steps and ECC strengths are read from controller registers. ECC sector size and ECC strength can be configurable. Size of ECC depends on maximum supported sector size it not depends on selected sector size. Therefore there is a separate function for calculating ECC size for each of possible sector size/step size.

Piotr Sroka (2):
Add new Cadence NAND driver to MTD subsystem
Add Cadence NAND controller driver

 .../bindings/mtd/cadence-nand-controller.txt       |   53 +
 MAINTAINERS                                        |    7 +
 drivers/mtd/nand/raw/Kconfig                       |    7 +
 drivers/mtd/nand/raw/Makefile                      |    1 +
 drivers/mtd/nand/raw/cadence-nand-controller.c     | 3036 ++++++++++++++++++++
 5 files changed, 3104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt
 create mode 100644 drivers/mtd/nand/raw/cadence-nand-controller.c
Signature · 6 lines
2.15.0


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

PATCH v6 1/2 mtd: rawnand: Add new Cadence NAND driver to MTD subsystem

Add new Cadence NAND driver to MTD subsystem

---
Changes for v6:
- add support for bank addressing modified in HPNFC R013 version
- change type of data_control_supp and is_phy_type_dll from u8 to bool
- fix writing and reading data for HPNFC slave DMA interface connected directly to AHB/AXI instead of external DMA engine.
- the default value of the board-delay parameter is set to other than 0 when it is not defined in the dts file
- put myself as maintainer of the Cadence nand driver
Changes for v5:
- fix "ecc config strength" field size
- remove unused macros
- fix address of timing2 register
- add guard for accessing data_control_size register
- simplify the driver by use the same function
for accessing main area and oob area
- add comment to the driver describing main controller modes
- change compatible name from cdns,hpnfc to cdns,hp-nfc
Changes for v4:
- fix comments issues like typos, missing capitals, missing dots etc.
- remove unnecessary PHY options phy_dll_aging and phy_per_bit_deskew
- replace all register access functions to "relaxed" version
- remove all unnecessary variables initializations
- handle error inside cadence_nand_get_ecc_strength_idx function in case correnction strength is not found
- add commit message
Changes for v3:
- remove definitions of unused registers
- remove configuring registers which are not expected to be configured in asynchronous mode
- remove not needed function reading timing registers
- remove information about oob size and write size from cdns_nand_chip type and use vales from mtd_info directly
- use nand_cleanup instead of nand_release if mtd device is not registered yet
- fix cadence_nand_chips_init function add garbage collection
if a chip init fails
- simplify PHY calculations
Changes for v2:
- create one universal wait function for all events instead of one function per event.
- split one big function executing nand operations to separate functions one per each type of operation.
- add erase atomic operation to nand operation parser
- remove unnecessary includes.
- remove unused register defines
- add support for multiple nand chips
- remove all code using legacy functions
- remove chip dependents parameters from dts bindings, they were attached to the SoC specific compatible at the driver level
- simplify interrupt handling
- simplify timing calculations
- fix calculation of maximum supported cs signals
- simplify ecc size calculation
- remove header file and put whole code to one c file

---
 MAINTAINERS                                    |    6 +
 drivers/mtd/nand/raw/Kconfig                   |    7 +
 drivers/mtd/nand/raw/Makefile                  |    1 +
 drivers/mtd/nand/raw/cadence-nand-controller.c | 3036 ++++++++++++++++++++++++
 4 files changed, 3050 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/cadence-nand-controller.c
MAINTAINERS +6 -0
index 783569e3c4b4..16e16445b88b 100644
@@ -3579,6 +3579,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/media/cdns,*.txt
 F:	drivers/media/platform/cadence/cdns-csi2*
 
+CADENCE NAND DRIVER
+M:	Piotr Sroka <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/mtd/nand/raw/cadence-nand-controller.c
+
 CADET FM/AM RADIO RECEIVER DRIVER
 M:	Hans Verkuil <[email protected]>
 L:	[email protected]
drivers/mtd/nand/raw/Kconfig +7 -0
index e59de3f60cf6..74fb91adeb46 100644
@@ -450,6 +450,13 @@ config MTD_NAND_PLATFORM
 	  devices. You will need to provide platform-specific functions
 	  via platform_data.
 
+config MTD_NAND_CADENCE
+	tristate "Support Cadence NAND (HPNFC) controller"
+	depends on OF || COMPILE_TEST
+	help
+	  Enable the driver for NAND flash on platforms using a Cadence NAND
+	  controller.
+
 comment "Misc"
 
 config MTD_SM_COMMON
drivers/mtd/nand/raw/Makefile +1 -0
index a98721988e61..2d136b158fb7 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_MTD_NAND_MXIC)		+= mxic_nand.o
 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
 
 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/cadence-nand-controller.c new file +3036 -0

2,968 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.15.0


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

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [v6 1/2] mtd: rawnand: Add new Cadence NAND driver to MTD subsystem

I love your patch! Yet something to improve:

Hi Piotr,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190915]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Piotr-Sroka/mtd-rawnand-Add-Cadence-NAND-controller-driver/20190916-205004
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=parisc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/mtd/nand/raw/cadence-nand-controller.c: In function 'cadence_nand_read_buf':

>> drivers/mtd/nand/raw/cadence-nand-controller.c:1877:3: error: implicit declaration of function 'readsl'; did you mean 'readl'? [-Werror=implicit-function-declaration]
      readsl(cdns_ctrl->io.virt, buf, len_in_words);
      ^~~~~~
      readl
   drivers/mtd/nand/raw/cadence-nand-controller.c: In function 'cadence_nand_write_buf':
>> drivers/mtd/nand/raw/cadence-nand-controller.c:1930:3: error: implicit declaration of function 'writesl'; did you mean 'writel'? [-Werror=implicit-function-declaration]
      writesl(cdns_ctrl->io.virt, buf, len_in_words);
      ^~~~~~~
      writel

cc1: some warnings being treated as errors

vim +1877 drivers/mtd/nand/raw/cadence-nand-controller.c

1860
1861 static int cadence_nand_read_buf(struct cdns_nand_ctrl *cdns_ctrl,
1862 u8 *buf, int len)
1863 {
1864 u8 thread_nr = 0;
1865 u32 sdma_size;
1866 int status;
1867
1868 /* Wait until slave DMA interface is ready to data transfer. */
1869 status = cadence_nand_wait_on_sdma(cdns_ctrl, &thread_nr, &sdma_size);
1870 if (status)
1871 return status;
1872
1873 if (!cdns_ctrl->caps1->has_dma) {
1874 int len_in_words = len >> 2;
1875
1876 /* read alingment data */

> 1877			readsl(cdns_ctrl->io.virt, buf, len_in_words);
  1878			if (sdma_size > len) {
  1879				/* read rest data from slave DMA interface if any */
  1880				readsl(cdns_ctrl->io.virt, cdns_ctrl->buf,
  1881				       sdma_size / 4 - len_in_words);
  1882				/* copy rest of data */
  1883				memcpy(buf + (len_in_words << 2), cdns_ctrl->buf,
  1884				       len - (len_in_words << 2));
  1885			}
  1886			return 0;
  1887		}
  1888	
  1889		if (cdns_ctrl->dmac && cadence_nand_dma_buf_ok(cdns_ctrl, buf, len)) {
  1890			status = cadence_nand_slave_dma_transfer(cdns_ctrl, buf,
  1891								 cdns_ctrl->io.dma,
  1892								 len, DMA_FROM_DEVICE);
  1893			if (status == 0)
  1894				return 0;
  1895	
  1896			dev_warn(cdns_ctrl->dev,
  1897				 "Slave DMA transfer failed. Try again using bounce buffer.");
  1898		}
  1899	
  1900		/* If DMA transfer is not possible or failed then use bounce buffer. */
  1901		status = cadence_nand_slave_dma_transfer(cdns_ctrl, cdns_ctrl->buf,
  1902							 cdns_ctrl->io.dma,
  1903							 sdma_size, DMA_FROM_DEVICE);
  1904	
  1905		if (status) {
  1906			dev_err(cdns_ctrl->dev, "Slave DMA transfer failed");
  1907			return status;
  1908		}
  1909	
  1910		memcpy(buf, cdns_ctrl->buf, len);
  1911	
  1912		return 0;
  1913	}
  1914	
  1915	static int cadence_nand_write_buf(struct cdns_nand_ctrl *cdns_ctrl,
  1916					  const u8 *buf, int len)
  1917	{
  1918		u8 thread_nr = 0;
  1919		u32 sdma_size;
  1920		int status;
  1921	
  1922		/* Wait until slave DMA interface is ready to data transfer. */
  1923		status = cadence_nand_wait_on_sdma(cdns_ctrl, &thread_nr, &sdma_size);
  1924		if (status)
  1925			return status;
  1926	
  1927		if (!cdns_ctrl->caps1->has_dma) {
  1928			int len_in_words = len >> 2;
  1929	
> 1930			writesl(cdns_ctrl->io.virt, buf, len_in_words);

1931 if (sdma_size > len) {
1932 /* copy rest of data */
1933 memcpy(cdns_ctrl->buf, buf + (len_in_words << 2),
1934 len - (len_in_words << 2));
1935 /* write all expected by nand controller data */
1936 writesl(cdns_ctrl->io.virt, cdns_ctrl->buf,
1937 sdma_size / 4 - len_in_words);
1938 }
1939
1940 return 0;
1941 }
1942
1943 if (cdns_ctrl->dmac && cadence_nand_dma_buf_ok(cdns_ctrl, buf, len)) {
1944 status = cadence_nand_slave_dma_transfer(cdns_ctrl, (void *)buf,
1945 cdns_ctrl->io.dma,
1946 len, DMA_TO_DEVICE);
1947 if (status == 0)
1948 return 0;
1949
1950 dev_warn(cdns_ctrl->dev,
1951 "Slave DMA transfer failed. Try again using bounce buffer.");
1952 }
1953
1954 /* If DMA transfer is not possible or failed then use bounce buffer. */
1955 memcpy(cdns_ctrl->buf, buf, len);
1956
1957 status = cadence_nand_slave_dma_transfer(cdns_ctrl, cdns_ctrl->buf,
1958 cdns_ctrl->io.dma,
1959 sdma_size, DMA_TO_DEVICE);
1960
1961 if (status)
1962 dev_err(cdns_ctrl->dev, "Slave DMA transfer failed");
1963
1964 return status;
1965 }
1966

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

PATCH v6 2/2 dt-bindings: mtd: Add Cadence NAND controller driver

In reply to Piotr Sroka

Document the bindings used by Cadence NAND controller driver

---
Changes for v6:
- add documentation for address-cells and size-cells
- remove not needed space
- put myself as maintainer of the Cadence nand driver bindings Changes for v5:
- replace "_" by "-" in all properties
- change compatible name from cdns,hpnfc to cdns,hp-nfc Changes for v4:
- add commit message
Changes for v3:
- add unit suffix for board_delay
- move child description to proper place
- remove prefix cadence_ for reg and sdma fields Changes for v2:
- remove chip dependends parameters from dts bindings
- add names for register ranges in dts bindings
- add generic bindings to describe NAND chip representation

---
 .../bindings/mtd/cadence-nand-controller.txt       | 53 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +53 -0
new file mode 100644
index 000000000000..f3893c4d3c6a
@@ -0,0 +1,53 @@
+* Cadence NAND controller
+
+Required properties:
+  - compatible : "cdns,hp-nfc"
+  - reg : Contains two entries, each of which is a tuple consisting of a
+	  physical address and length. The first entry is the address and
+	  length of the controller register set. The second entry is the
+	  address and length of the Slave DMA data port.
+  - reg-names: should contain "reg" and "sdma"
+  - #address-cells: should be 1. The cell encodes the chip select connection.
+  - #size-cells : should be 0.
+  - interrupts : The interrupt number.
+  - clocks: phandle of the controller core clock (nf_clk).
+
+Optional properties:
+  - dmas: shall reference DMA channel associated to the NAND controller
+  - cdns,board-delay-ps : Estimated Board delay. The value includes the total
+    round trip delay for the signals and is used for deciding on values
+    associated with data read capture. The example formula for SDR mode is
+    the following:
+    board delay = RE#PAD delay + PCB trace to device + PCB trace from device
+    + DQ PAD delay
+
+Child nodes represent the available NAND chips.
+
+Required properties of NAND chips:
+  - reg: shall contain the native Chip Select ids from 0 to max supported by
+    the cadence nand flash controller
+
+See Documentation/devicetree/bindings/mtd/nand.txt for more details on
+generic bindings.
+
+Example:
+
+nand_controller: nand-controller@60000000 {
+	  compatible = "cdns,hp-nfc";
+	  #address-cells = <1>;
+	  #size-cells = <0>;
+	  reg = <0x60000000 0x10000>, <0x80000000 0x10000>;
+	  reg-names = "reg", "sdma";
+	  clocks = <&nf_clk>;
+	  cdns,board-delay-ps = <4830>;
+	  interrupts = <2 0>;
+	  nand@0 {
+	      reg = <0>;
+	      label = "nand-1";
+	  };
+	  nand@1 {
+	      reg = <1>;
+	      label = "nand-2";
+	  };
+
+};
MAINTAINERS +1 -0
index 16e16445b88b..94d78f4e29ba 100644
@@ -3584,6 +3584,7 @@ M:	Piotr Sroka <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/mtd/nand/raw/cadence-nand-controller.c
+F:	Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt
 
 CADET FM/AM RADIO RECEIVER DRIVER
 M:	Hans Verkuil <[email protected]>
Signature · 1 line
2.15.0