mtd: nand: Add Cadence NAND controller driver
v3 cover mtd: nand: 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
dt-bindings: nand: Add Cadence NAND controller driver
.../bindings/mtd/cadence-nand-controller.txt | 51 + drivers/mtd/nand/raw/Kconfig | 7 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/cadence-nand-controller.c | 3119 ++++++++++++++++++++ 4 files changed, 3178 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/
PATCH v3 1/2 mtd: nand: Add Cadence NAND controller driver
---
Changes for v3:
- remove definitions of unused registres/
- remove configuring registers which are not excpected 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
--- drivers/mtd/nand/raw/Kconfig | 7 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/cadence-nand-controller.c | 3119 ++++++++++++++++++++++++ 3 files changed, 3127 insertions(+) create mode 100644 drivers/mtd/nand/raw/cadence-nand-controller.c
drivers/mtd/nand/raw/Kconfig +7 -0
@@ -557,5 +557,12 @@ config MTD_NAND_MESON help Enables support for NAND controller on Amlogic's Meson SoCs. This controller is found on Meson SoCs. +config MTD_NAND_CADENCE + tristate "Support Cadence NAND (HPNFC) controller" + depends on OF + help + Enable the driver for NAND flash on platforms using a Cadence NAND + controller. + endif # MTD_NAND
drivers/mtd/nand/raw/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_MTD_NAND_MTK) += mtk_ecc.o mtk_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 +3119 -0
2,981 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.
PATCH v3 2/2 dt-bindings: nand: Add Cadence NAND controller driver
---
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 | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +51 -0
@@ -0,0 +1,51 @@ +* Cadence NAND controller + +Required properties: + - compatible : "cdns,hpnfc" + - 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" + - 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 + +Children 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,hpnfc"; + 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"; + }; + +};
Signature · 1 line
2.15.0
Rob Herring
maintainerRe: [v3 2/2] dt-bindings: nand: Add Cadence NAND controller driver
Quoted 21 lines · Piotr Sroka
Signed-off-by Piotr Sroka <[email protected]>---
Changes for v3:
- add unit suffix forboard_delay
- move child description to proper place
- remove prefixcadence_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 | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/cadence-nand-controller.txtDocumentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +0
-0
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +4
-0@@ -0,0 +1,51 @@ +* Cadence NAND controller + +Required properties: + - compatible : "cdns,hpnfc"
Only 1 version of h/w features and bugs?
'hp-nfc' would be a bit more readable IMO.
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 15
Quoted 11 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +11
-0+ - 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" + - 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
s/_/-/
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 22
Quoted 7 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +7
-0+ 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 + +Children nodes represent the available NAND chips.
Child nodes...
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 34
Quoted 12 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +12
-0+ +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 {
remove space ^
Quoted 20 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +17
-0+ + compatible = "cdns,hpnfc"; + 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"; + }; + +};Signature · 1 line
2.15.0
Re: [v3 2/2] dt-bindings: nand: Add Cadence NAND controller driver
Quoted 19 lines · Rob Herring
EXTERNAL MAIL
Quoted 15 lines · Piotr Sroka
Signed-off-by Piotr Sroka <[email protected]>---
Changes for v3:
- add unit suffix forboard_delay
- move child description to proper place
- remove prefixcadence_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 | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt
Quoted 13 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 4
Quoted 10 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +4
-0@@ -0,0 +1,51 @@ +* Cadence NAND controller + +Required properties: + - compatible : "cdns,hpnfc"Only 1 version of h/w features and bugs?
At the moment, yes.
Quoted 2 lines
'hp-nfc' would be a bit more readable IMO.
I will replace it.
Quoted 51 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 15
Quoted 11 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +11
-0+ - 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" + - 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 totals/_/-/
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 22
Quoted 7 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +7
-0+ 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 + +Children nodes represent the available NAND chips.Child nodes...
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt line 34
Quoted 12 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +12
-0+ +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 {remove space ^
Quoted 12 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +12
-0+ + compatible = "cdns,hpnfc"; + 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 {
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt new file +5
-1+ reg = <1>; + label = "nand-2"; + }; + +}; --2.15.0
Thanks
Piotr
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
14.06.2019 18:09, Piotr Sroka пишет:
Commit description is mandatory.
Quoted 2 lines
Signed-off-by Piotr Sroka <[email protected]>---
[snip]
Quoted 4 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +4
-0+ +/* Cadnence NAND flash controller capabilities get from driver data. */ +struct cadence_nand_dt_devdata { +/* Skew value of the output signals of the NAND Flash interface. */
drivers/mtd/nand/raw/cadence-nand-controller.c line 439
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+u32 if_skew; +/* It informs if aging feature in the DLL PHY supported. */ +u8 phy_dll_aging; +/* +* It informs if per bit deskew for read and write path in +* the PHY is supported. +*/ +u8 phy_per_bit_deskew; +/* It informs if slave DMA interface is connected to DMA engine. */ +u8 has_dma;
There is no needed to dedicate 8 bits to a variable if you only care about a single bit. You may write this as:
bool has_dma : 1;
[snip]
drivers/mtd/nand/raw/cadence-nand-controller.c line 546
Quoted 11 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +11
-0+static struct +cdns_nand_chip *to_cdns_nand_chip (struct nand_chip *chip) +{ + return container_of(chip, struct cdns_nand_chip, chip); +} + +static struct +cdns_nand_ctrl *to_cdns_nand_ctrl (struct nand_controller *controller) +{ + return container_of(controller, struct cdns_nand_ctrl, controller); +}
It's better to inline explicitly such cases because they won't get inlined with some kernel configurations, like enabled ftracing for example.
Quoted 11 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +11
-0+static bool +cadence_nand_dma_buf_ok (struct cdns_nand_ctrl *cdns_ctrl,const void *buf, +u32 buf_len) +{ +u8 data_dma_width = cdns_ctrl->caps2.data_dma_width; + +return buf &&virt_addr_valid (buf) && +likely (IS_ALIGNED ((uintptr_t )buf, data_dma_width)) && +likely (IS_ALIGNED (buf_len, data_dma_width)); +} +
drivers/mtd/nand/raw/cadence-nand-controller.c line 568
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+static int cadence_nand_wait_for_value (struct cdns_nand_ctrl *cdns_ctrl, +u32 reg_offset,u32 timeout_us, +u32 mask,bool is_clear) +{ +u32 val; +int ret =0 ; + + ret =readl_poll_timeout (cdns_ctrl->reg + reg_offset, + val, !(val & mask) == is_clear, +10 , timeout_us);
Apparently you don't care about having memory barrier here, hence readl_relaxed_poll_timeout().
Quoted 17 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +17
-0+if (ret <0 ) { +dev_err (cdns_ctrl->dev, +"Timeout while waiting for reg %x with mask %x is clear %d\n" , + reg_offset, mask, is_clear); + } + +return ret; +} + +static int cadence_nand_set_ecc_enable (struct cdns_nand_ctrl *cdns_ctrl, +bool enable) +{ +u32 reg; + +if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true))
drivers/mtd/nand/raw/cadence-nand-controller.c line 596
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+return -ETIMEDOUT ; + + reg =readl (cdns_ctrl->reg +ECC_CONFIG_0 ); + +if (enable) + reg |=ECC_CONFIG_0_ECC_EN ; +else + reg &= ~ECC_CONFIG_0_ECC_EN ; + +writel (reg, cdns_ctrl->reg +ECC_CONFIG_0 );
And here.. looks like there is no need for the memory barries, hence use the relaxed versions of readl/writel. Same for the rest of the patch.
Quoted 20 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +20
-0+return 0 ; +} + +static void cadence_nand_set_ecc_strength (struct cdns_nand_ctrl *cdns_ctrl, +u8 corr_str_idx) +{ +u32 reg; + +if (cdns_ctrl->curr_corr_str_idx == corr_str_idx) +return ; + + reg =readl (cdns_ctrl->reg +ECC_CONFIG_0 ); + reg &= ~ECC_CONFIG_0_CORR_STR ; + reg |=FIELD_PREP (ECC_CONFIG_0_CORR_STR , corr_str_idx); +writel (reg, cdns_ctrl->reg +ECC_CONFIG_0 ); + + cdns_ctrl->curr_corr_str_idx = corr_str_idx; +} + +static u8 cadence_nand_get_ecc_strength_idx(struct cdns_nand_ctrl *cdns_ctrl,
drivers/mtd/nand/raw/cadence-nand-controller.c line 627
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+ u8 strength) +{ +u8 i, corr_str_idx =0 ; + +for (i =0 ; i <BCH_MAX_NUM_CORR_CAPS ; i++) { +if (cdns_ctrl->ecc_strengths[i] == strength) { + corr_str_idx = i; +break ; + } + }
Is it a error case when i == BCH_MAX_NUM_CORR_CAPS?
Quoted 20 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +20
-0+return corr_str_idx; +} + +static int cadence_nand_set_skip_marker_val (struct cdns_nand_ctrl *cdns_ctrl, +u16 marker_value) +{ +u32 reg =0 ; + +if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true)) +return -ETIMEDOUT ; + + reg =readl (cdns_ctrl->reg +SKIP_BYTES_CONF ); + reg &= ~SKIP_BYTES_MARKER_VALUE ; + reg |=FIELD_PREP (SKIP_BYTES_MARKER_VALUE , + marker_value); + +writel (reg, cdns_ctrl->reg +SKIP_BYTES_CONF ); +
drivers/mtd/nand/raw/cadence-nand-controller.c line 658
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+return 0 ; +} + +static int cadence_nand_set_skip_bytes_conf (struct cdns_nand_ctrl *cdns_ctrl, +u8 num_of_bytes, +u32 offset_value, +int enable) +{ +u32 reg =0 ; +u32 skip_bytes_offset =0 ;
Please don't initialize variables if not necessary. You could also write this in a single line.
u32 skip_bytes_offset, reg;
Same for the rest of the patch.
Quoted 14 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +14
-0+if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true)) +return -ETIMEDOUT ; + +if (!enable) { + num_of_bytes =0 ; + offset_value =0 ; + } + + reg =readl (cdns_ctrl->reg +SKIP_BYTES_CONF ); + reg &= ~SKIP_BYTES_NUM_OF_BYTES ; + reg |=FIELD_PREP (SKIP_BYTES_NUM_OF_BYTES , + num_of_bytes);
drivers/mtd/nand/raw/cadence-nand-controller.c line 683
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+ skip_bytes_offset =FIELD_PREP (SKIP_BYTES_OFFSET_VALUE , + offset_value); + +writel (reg, cdns_ctrl->reg +SKIP_BYTES_CONF ); +writel (skip_bytes_offset, cdns_ctrl->reg +SKIP_BYTES_OFFSET ); + +return 0 ; +} + +/* Fucntions enables/disables hardware detection of erased data */
s/Fucntions/Function/, please use spellchecker. I'd also recommend to start all single-line comments with a lower case (and without a dot in the end) because it is a more common style in the kernel and is a bit easier for the eyes.
[snip]
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi Dmitry
Quoted 30 lines · Dmitry Osipenko
EXTERNAL MAIL
14.06.2019 18:09, Piotr Sroka пишет:
Commit description is mandatory.
Quoted 2 lines
Signed-off-by Piotr Sroka <[email protected]>---
[snip]
Quoted 4 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +4
-0+ +/* Cadnence NAND flash controller capabilities get from driver data. */ +struct cadence_nand_dt_devdata { +/* Skew value of the output signals of the NAND Flash interface. */ drivers/mtd/nand/raw/cadence-nand-controller.c line 439
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+u32 if_skew; +/* It informs if aging feature in the DLL PHY supported. */ +u8 phy_dll_aging; +/* +* It informs if per bit deskew for read and write path in +* the PHY is supported. +*/ +u8 phy_per_bit_deskew; +/* It informs if slave DMA interface is connected to DMA engine. */ +u8 has_dma;There is no needed to dedicate 8 bits to a variable if you only care about a single bit. You may write this as:
Quoted 1 line
bool
has_dma: 1;
I modified it locally but it looks that checkpatch does not like such notation
"WARNING: Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>"
So maybe I will leave it as is.
Quoted 33 lines
[snip]
drivers/mtd/nand/raw/cadence-nand-controller.c line 546
Quoted 11 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +11
-0+static struct +cdns_nand_chip *to_cdns_nand_chip (struct nand_chip *chip) +{ + return container_of(chip, struct cdns_nand_chip, chip); +} + +static struct +cdns_nand_ctrl *to_cdns_nand_ctrl (struct nand_controller *controller) +{ + return container_of(controller, struct cdns_nand_ctrl, controller); +}It's better to inline explicitly such cases because they won't get inlined with some kernel configurations, like enabled ftracing for example.
Quoted 16 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +16
-0+static bool +cadence_nand_dma_buf_ok (struct cdns_nand_ctrl *cdns_ctrl,const void *buf, +u32 buf_len) +{ +u8 data_dma_width = cdns_ctrl->caps2.data_dma_width; + +return buf &&virt_addr_valid (buf) && +likely (IS_ALIGNED ((uintptr_t )buf, data_dma_width)) && +likely (IS_ALIGNED (buf_len, data_dma_width)); +} + +static int cadence_nand_wait_for_value (struct cdns_nand_ctrl *cdns_ctrl, +u32 reg_offset,u32 timeout_us, +u32 mask,bool is_clear) +{ +u32 val;
Quoted 8 lines
drivers/mtd/nand/raw/cadence-nand-controller.c line 568
Quoted 5 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +5
-0+int ret =0 ; + + ret =readl_poll_timeout (cdns_ctrl->reg + reg_offset, + val, !(val & mask) == is_clear, +10 , timeout_us);Apparently you don't care about having memory barrier here, hence
readl_relaxed_poll_timeout().
ok I will update it.
Quoted 23 lines
Quoted 23 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +22
-0+if (ret <0 ) { +dev_err (cdns_ctrl->dev, +"Timeout while waiting for reg %x with mask %x is clear %d\n" , + reg_offset, mask, is_clear); + } + +return ret; +} + +static int cadence_nand_set_ecc_enable (struct cdns_nand_ctrl *cdns_ctrl, +bool enable) +{ +u32 reg; + +if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true)) +return -ETIMEDOUT ; + + reg =readl (cdns_ctrl->reg +ECC_CONFIG_0 ); + +if (enable)
Quoted 9 lines
drivers/mtd/nand/raw/cadence-nand-controller.c line 596
Quoted 5 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +5
-0+ reg |=ECC_CONFIG_0_ECC_EN ; + else + reg &= ~ECC_CONFIG_0_ECC_EN; + +writel (reg, cdns_ctrl->reg +ECC_CONFIG_0 );And here.. looks like there is no need for the memory barries, hence use the relaxed versions of readl/writel. Same for the rest of the patch.
ok
Quoted 24 lines
Quoted 24 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +24
-0+return 0 ; +} + +static void cadence_nand_set_ecc_strength (struct cdns_nand_ctrl *cdns_ctrl, +u8 corr_str_idx) +{ +u32 reg; + +if (cdns_ctrl->curr_corr_str_idx == corr_str_idx) +return ; + + reg =readl (cdns_ctrl->reg +ECC_CONFIG_0 ); + reg &= ~ECC_CONFIG_0_CORR_STR ; + reg |=FIELD_PREP (ECC_CONFIG_0_CORR_STR , corr_str_idx); +writel (reg, cdns_ctrl->reg +ECC_CONFIG_0 ); + + cdns_ctrl->curr_corr_str_idx = corr_str_idx; +} + +static u8 cadence_nand_get_ecc_strength_idx (struct cdns_nand_ctrl *cdns_ctrl, +u8 strength) +{ +u8 i, corr_str_idx =0 ; +
Quoted 8 lines
drivers/mtd/nand/raw/cadence-nand-controller.c line 627
Quoted 6 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +6
-0+for (i =0 ; i <BCH_MAX_NUM_CORR_CAPS ; i++) { +if (cdns_ctrl->ecc_strengths[i] == strength) { + corr_str_idx = i; +break ; + } + }Is it a error case when i ==
BCH_MAX_NUM_CORR_CAPS?
Yes it is an error but it could appear only if ECC capability registers have wrong values. I will handle that error anyway.
Quoted 34 lines
Quoted 20 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +20
-0+return corr_str_idx; +} + +static int cadence_nand_set_skip_marker_val (struct cdns_nand_ctrl *cdns_ctrl, +u16 marker_value) +{ +u32 reg =0 ; + +if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true)) +return -ETIMEDOUT ; + + reg =readl (cdns_ctrl->reg +SKIP_BYTES_CONF ); + reg &= ~SKIP_BYTES_MARKER_VALUE ; + reg |=FIELD_PREP (SKIP_BYTES_MARKER_VALUE , + marker_value); + +writel (reg, cdns_ctrl->reg +SKIP_BYTES_CONF ); +drivers/mtd/nand/raw/cadence-nand-controller.c line 658
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+return 0 ; +} + +static int cadence_nand_set_skip_bytes_conf (struct cdns_nand_ctrl *cdns_ctrl, +u8 num_of_bytes, +u32 offset_value, +int enable) +{ +u32 reg =0 ; +u32 skip_bytes_offset =0 ;Please don't initialize variables if not necessary. You could also write this in a single line.
Quoted 4 lines
u32 skip_bytes_offset, reg;Same for the rest of the patch.
Ok to I will change it.
Quoted 20 lines
Quoted 20 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +20
-0+if (cadence_nand_wait_for_value (cdns_ctrl,CTRL_STATUS , +1000000 , +CTRL_STATUS_CTRL_BUSY , true)) +return -ETIMEDOUT ; + +if (!enable) { + num_of_bytes =0 ; + offset_value =0 ; + } + + reg =readl (cdns_ctrl->reg +SKIP_BYTES_CONF ); + reg &= ~SKIP_BYTES_NUM_OF_BYTES ; + reg |=FIELD_PREP (SKIP_BYTES_NUM_OF_BYTES , + num_of_bytes); + skip_bytes_offset =FIELD_PREP (SKIP_BYTES_OFFSET_VALUE , + offset_value); + +writel (reg, cdns_ctrl->reg +SKIP_BYTES_CONF ); +writel (skip_bytes_offset, cdns_ctrl->reg +SKIP_BYTES_OFFSET ); +
Quoted 8 lines
drivers/mtd/nand/raw/cadence-nand-controller.c line 683
Quoted 4 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +4
-0+return 0 ; +} + +/* Fucntions enables/disables hardware detection of erased data */ s/Fucntions/Function/, please use spellchecker. I'd also recommend to start all single-line comments with a lower case (and without a dot in the end) because it is a more common style in the kernel and is a bit easier for the eyes.
Ok I will do it.
Quoted 2 lines
[snip]
Thanks
Piotr Sroka
25.06.2019 16:02, Piotr Sroka пишет:
Quoted 33 lines
Hi Dmitry
Quoted 30 lines · Dmitry Osipenko
EXTERNAL MAIL
14.06.2019 18:09, Piotr Sroka пишет:
Commit description is mandatory.
Quoted 2 lines
Signed-off-by Piotr Sroka <[email protected]>---
[snip]
Quoted 4 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +4
-0+ +/* Cadnence NAND flash controller capabilities get from driver data. */ +struct cadence_nand_dt_devdata { + /* Skew value of the output signals of the NAND Flash interface. */drivers/mtd/nand/raw/cadence-nand-controller.c line 439
Quoted 10 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +10
-0+ u32 if_skew; + /* It informs if aging feature in the DLL PHY supported. */ + u8 phy_dll_aging; + /* + * It informs if per bit deskew for read and write path in + * the PHY is supported. + */ + u8 phy_per_bit_deskew; + /* It informs if slave DMA interface is connected to DMA engine. */ + u8 has_dma;There is no needed to dedicate 8 bits to a variable if you only care about a single bit. You may write this as:
Quoted 6 lines
Quoted 1 line
bool
has_dma: 1;I modified it locally but it looks that checkpatch does not like such notation
"WARNING: Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>"
So maybe I will leave it as is.
You may also use the "u8 : 1" form then, to satisfy the checkpatch. Probably "unsigned int : 1" will be the best in this case, it's up to you.
Quoted 21 lines · Dmitry Osipenko
25.06.2019 16:02, Piotr Sroka пишет:
Quoted 20 lines
Quoted 19 lines · Dmitry Osipenko
14.06.2019 18:09, Piotr Sroka пишет:
drivers/mtd/nand/raw/cadence-nand-controller.c line 439
Quoted 13 lines
drivers/mtd/nand/raw/cadence-nand-controller.c new file +13
-0+/* Cadnence NAND flash controller capabilities get from driver data. */ +struct cadence_nand_dt_devdata { +/* Skew value of the output signals of the NAND Flash interface. */ +u32 if_skew; +/* It informs if aging feature in the DLL PHY supported. */ +u8 phy_dll_aging; +/* +* It informs if per bit deskew for read and write path in +* the PHY is supported. +*/ +u8 phy_per_bit_deskew; +/* It informs if slave DMA interface is connected to DMA engine. */ +u8 has_dma;There is no needed to dedicate 8 bits to a variable if you only care about a single bit. You may write this as:
bool
has_dma: 1;
Quoted 8 lines
Quoted 5 lines
I modified it locally but it looks that checkpatch does not like such notation
"WARNING: Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>"
So maybe I will leave it as is.You may also use the "u8 : 1" form then, to satisfy the checkpatch. Probably "unsigned int : 1" will be the best in this case, it's up to you.
Exactly. The compiler will allocate the sufficient amount of space to store the bitfield.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds