Skip to contentSkip to conversation

mtd: rawnand: Add NAND controller support on Intel LGM SoC

PATCH Superseded Ramuthevar,Vadivel MuruganX 4 participants 17 messages Apr 23, 2020 – Apr 29, 2020

Subsystems (4)

v3 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v3 cover mtd: rawnand: Add NAND controller support on Intel LGM SoC

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 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.

Thank you very much Boris and Hauke for the reviews and suggestions.
---
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 YAML for Nand Flash Controller support
mtd: rawnand: Add NAND controller support on Intel LGM SoC

 .../devicetree/bindings/mtd/intel,lgm-nand.yaml    |  61 ++
 drivers/mtd/nand/raw/Kconfig                       |   8 +
 drivers/mtd/nand/raw/Makefile                      |   1 +
 drivers/mtd/nand/raw/intel-nand-controller.c       | 705 +++++++++++++++++++++
 4 files changed, 775 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
#1 lore raw

PATCH v3 1/2 dt-bindings: mtd: Add YAML for Nand Flash Controller support

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    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +61 -0
new file mode 100644
index 000000000000..6dd899d367b4
@@ -0,0 +1,61 @@
+# 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:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    enum:
+      - rx
+      - tx
+
+  pinctrl-names: true
+
+patternProperties:
+  "^pinctrl-[0-9]+$": true
+
+  "^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
+
+additionalProperties: false
+
+...
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: mtd: Add YAML for Nand Flash Controller support

Hi,

Quoted 38 lines · Ramuthevar,Vadivel MuruganX

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    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +21 -0
new file mode 100644
index 000000000000..6dd899d367b4
@@ -0,0 +1,61 @@
+# 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:
+    maxItems: 1
+

Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +10 -0
+  clocks:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    enum:
+      - rx
+      - tx

This looks wrong?

If you have two dmas channels, I assume you'll want to have both rx and tx, right? If so, then you need an items, not an enum.

Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +4 -0
+  pinctrl-names: true
+
+patternProperties:
+  "^pinctrl-[0-9]+$": true

both pinctrl-names and that pattern are added automatically by the tooling, you should leave them out.

Quoted 14 lines
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +14 -0
+  "^nand@[a-f0-9]+$":
+    type: object
+    properties:
+      reg:
+        minimum: 0
+        maximum: 7
+
+      nand-ecc-mode: true
+
+      nand-ecc-algo:
+        const: hw
+
+    additionalProperties: false
+

Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml line 61

Quoted 10 lines
Documentation/devicetree/bindings/mtd/intel,lgm-nand.yaml new file +10 -0
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - dmas
+
+additionalProperties: false
+
+...

Can you provide an example too?

Thanks!
Maxime

#3 lore raw

PATCH v3 2/2 mtd: rawnand: Add NAND controller support on Intel LGM SoC

In reply to 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/Kconfig                 |   8 +
 drivers/mtd/nand/raw/Makefile                |   1 +
 drivers/mtd/nand/raw/intel-nand-controller.c | 705 +++++++++++++++++++++++++++
 3 files changed, 714 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/intel-nand-controller.c
drivers/mtd/nand/raw/Kconfig +8 -0
index a80a46bb5b8b..a026bec28f39 100644
@@ -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 interfaced through the External Bus Unit.
+
 comment "Misc"
 
 config MTD_SM_COMMON
drivers/mtd/nand/raw/Makefile +1 -0
index 2d136b158fb7..bfc8fe4d2cb0 100644
@@ -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 +705 -0

705 lines not on this page · raw message

Signature · 1 line
2.11.0
#4 lore raw

drivers/mtd/nand/raw/intel-nand-controller.c line 28

Quoted 5 lines · Vadivel MuruganX
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+#define EBU_CLC			0x000
+#define EBU_CLC_RST		0x00000000u
+
+#define	EBU_ADDR_SEL(n)		(0x20 + (n) * 4)

^ Please replace those tabs by a single space.

Quoted 23 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +23 -0
+#define	EBU_ADDR_MASK		(5 << 4)
+#define	EBU_ADDR_SEL_REGEN	0x1
+
+#define EBU_BUSCON(n)		(0x60 + (n) * 4)
+#define EBU_BUSCON_CMULT_V4	0x1
+#define EBU_BUSCON_RECOVC(n)	((n) << 2)
+#define EBU_BUSCON_HOLDC(n)	((n) << 4)
+#define EBU_BUSCON_WAITRDC(n)	((n) << 6)
+#define EBU_BUSCON_WAITWRC(n)	((n) << 8)
+#define EBU_BUSCON_BCGEN_CS	0x0
+#define EBU_BUSCON_SETUP_EN	BIT(22)
+#define EBU_BUSCON_ALEC		0xC000
+
+#define EBU_CON			0x0B0
+#define EBU_CON_NANDM_EN	BIT(0)
+#define EBU_CON_NANDM_DIS	0x0
+#define EBU_CON_CSMUX_E_EN	BIT(1)
+#define EBU_CON_ALE_P_LOW	BIT(2)
+#define EBU_CON_CLE_P_LOW	BIT(3)
+#define EBU_CON_CS_P_LOW	BIT(4)
+#define EBU_CON_SE_P_LOW	BIT(5)
+#define EBU_CON_WP_P_LOW	BIT(6)
+#define EBU_CON_PRE_P_LOW	BIT(7)

drivers/mtd/nand/raw/intel-nand-controller.c line 61

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+#define EBU_CON_IN_CS_S(n)	((n) << 8)
+#define EBU_CON_OUT_CS_S(n)	((n) << 10)
+#define EBU_CON_LAT_EN_CS_P	((0x3D) << 18)
+
+#define EBU_WAIT		0x0B4
+#define EBU_WAIT_RDBY		BIT(0)
+#define EBU_WAIT_WR_C		BIT(3)
+
+#define	EBU_MEM_BASE_CS_0	0x17400
+#define	EBU_MEM_BASE_CS_1	0x17C00

If I refer to v2, that's actually 0x17400000 and 0x17C00000. And I suspect those addresses come from the physical addresses of the EBU range attached to those CS lines, which can be extracted from the resource passed to the driver. But maybe I'm wrong.

Quoted 1 line

+#define EBU_MEM_OFFSET 0x051

Sorry but that's too vague. What is this mask/offset encoding?

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+
+#define HSNAND_CTL1		0x110
+#define HSNAND_CTL1_ADDR_SHIFT	24
+
+#define HSNAND_CTL2		0x114
+#define HSNAND_CTL2_ADDR_SHIFT	8

drivers/mtd/nand/raw/intel-nand-controller.c line 78

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+#define HSNAND_CTL2_CYC_N_V5	(0x2 << 16)
+
+#define HSNAND_INT_MSK_CTL	0x124
+#define HSNAND_INT_MSK_CTL_WR_C	BIT(4)
+
+#define HSNAND_INT_STA		0x128
+#define HSNAND_INT_STA_WR_C	BIT(4)
+
+#define HSNAND_CTL		0x130
+#define HSNAND_CTL_MODE_ECC	0x1

#define HSNAND_CTL_ENABLE_ECC BIT(0)

drivers/mtd/nand/raw/intel-nand-controller.c line 87

Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9 -0
+#define HSNAND_CTL_GO		BIT(2)
+#define HSNAND_CTL_CE_SEL_CS(n)	BIT(3 + (n))
+#define HSNAND_CTL_RW_READ	0x0
+#define HSNAND_CTL_RW_WRITE	BIT(10)
+#define HSNAND_CTL_ECC_OFF_V8TH	BIT(11)
+#define HSNAND_CTL_CKFF_EN	0x0
+#define HSNAND_CTL_MSG_EN	BIT(17)
+
+#define NAND_PARA0		0x13c

Why are some of those registers prefixed NAND and others HSNAND? I guess HS stands for High-Speed.

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+#define NAND_PARA0_PAGE_V8192	0x3
+#define NAND_PARA0_PIB_V256	(0x3 << 4)
+#define NAND_PARA0_BYP_EN_NP	0x0
+#define NAND_PARA0_BYP_DEC_NP	0x0
+#define NAND_PARA0_TYPE_ONFI	BIT(18)
+#define NAND_PARA0_ADEP_EN	BIT(21)

drivers/mtd/nand/raw/intel-nand-controller.c line 103

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+
+#define NAND_CMSG_0		0x150
+#define NAND_CMSG_1		0x154
+
+#define NAND_ALE_OFFS		BIT(2)
+#define NAND_CLE_OFFS		BIT(3)
+#define NAND_CS_OFFS		BIT(4)
+
+#define NAND_WRITE_CMD		(NAND_CS_OFFS | NAND_CLE_OFFS)
+#define NAND_WRITE_ADDR		(NAND_CS_OFFS | NAND_ALE_OFFS)

Those macros are no longer used, you can drop them.

drivers/mtd/nand/raw/intel-nand-controller.c line 105

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+#define NAND_WRITE_DATA		EBU_CON_CS_P_LOW
+#define NAND_READ_DATA		EBU_CON_CS_P_LOW

And those should not be used, please use NAND_CS_OFFS instead.

drivers/mtd/nand/raw/intel-nand-controller.c line 110

Quoted 5 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+#define NAND_ECC_OFFSET		0x008
+
+struct ebu_nand_controller {
+	struct nand_controller	controller;

Can you drop the tabs and use one space between the type and field name?

drivers/mtd/nand/raw/intel-nand-controller.c line 111

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	struct nand_chip	chip;

Can you add a comment explaining that this should be reworked if someone needs to support more than one chip.

drivers/mtd/nand/raw/intel-nand-controller.c line 113

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+	void __iomem		*ebu_addr;
+	void __iomem		*nand_addr;

Can we get rid of those _addr and rename those fields so they describe more precisely what the MMIO range is about:

	void __iomem *ebu;
	void __iomem *hsnand;

drivers/mtd/nand/raw/intel-nand-controller.c line 114

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	void __iomem		*chip_addr;

This field should be part of a specialized nand_chip object (see what's done here [1]). More generally, you should move anything that's chip-specific to this driver-specific nand_chip object.

drivers/mtd/nand/raw/intel-nand-controller.c line 118

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+	struct clk		*clk;
+	unsigned long		clk_rate;
+	u32			cs;
+	u32			nd_para0;

The cs and nd_para0 fields should be attached to the ebu_nand_chip object too (see [1]). While you move that, please add a comment saying that you currently only support single-CE chips.

drivers/mtd/nand/raw/intel-nand-controller.c line 122

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+	struct device		*dev;
+	struct dma_chan		*dma_tx;
+	struct dma_chan		*dma_rx;
+	struct completion	dma_access_complete;

Maybe

	struct {
		struct dma_chan *tx;
		struct dma_chan *rx;
		struct completion complete;
	} dma;

drivers/mtd/nand/raw/intel-nand-controller.c line 123

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	const char *cs_name;

You no longer use this field.

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+};
+
+static inline struct ebu_nand_controller *nand_to_ebu(struct nand_chip *chip)
+{
+	return container_of(chip, struct ebu_nand_controller, chip);
+}

drivers/mtd/nand/raw/intel-nand-controller.c line 139

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+
+static u8 ebu_nand_readb(struct nand_chip *chip, unsigned int op)
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
+	void __iomem *nand_wait = ebu_host->ebu_addr + EBU_WAIT;
+	u32 stat;
+	int ret;
+	u8 val;
+
+	val = readb(ebu_host->chip_addr + op);

No need for op here, just pass NAND_CS_OFFS directly, and you can drop the op argument.

drivers/mtd/nand/raw/intel-nand-controller.c line 146

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+	ret = readl_poll_timeout(nand_wait, stat, stat & EBU_WAIT_WR_C,
+				 20, 1000);
+	if (ret)
+		dev_warn(ebu_host->dev,
+			 "ebu nand write timeout. nand_wait(0x%p)=0x%x\n",
+			 nand_wait, readl(nand_wait));

Maybe dev_warn_ratelimited().

drivers/mtd/nand/raw/intel-nand-controller.c line 151

Quoted 5 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+	return val;
+}
+
+static void ebu_nand_writeb(struct nand_chip *chip, int op, u8 value)
							^u32 offset,
Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
+	void __iomem *nand_wait = ebu_host->ebu_addr + EBU_WAIT;
+	u32 stat;
+	int ret;
+
+	writeb(value, ebu_host->chip_addr + op);

drivers/mtd/nand/raw/intel-nand-controller.c line 168

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+
+	ret = readl_poll_timeout(nand_wait, stat, stat & EBU_WAIT_WR_C,
+				 20, 1000);
+	if (ret)
+		dev_warn(ebu_host->dev,
+			 "ebu nand write timeout. nand_wait(0x%p)=0x%x\n",
+			 nand_wait, readl(nand_wait));
+}
+
+static void ebu_read_buf(struct nand_chip *chip, u_char *buf, int len)

^void * ^unsigned int

Please update all of those.

drivers/mtd/nand/raw/intel-nand-controller.c line 181

Quoted 13 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +13 -0
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		buf[i] = ebu_nand_readb(chip, NAND_READ_DATA);
+}
+
+static void ebu_write_buf(struct nand_chip *chip, const u_char *buf, int len)
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		ebu_nand_writeb(chip, NAND_WRITE_DATA, buf[i]);

^NAND_CS_OFFS

drivers/mtd/nand/raw/intel-nand-controller.c line 188

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+}
+
+static void ebu_unselect_chip(struct nand_chip *chip)
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
+	void __iomem *nand_con = ebu_host->ebu_addr + EBU_CON;
+	int val;
	^u32

drivers/mtd/nand/raw/intel-nand-controller.c line 191

Quoted 3 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +3 -0
+
+	val = readl(nand_con);
+	writel(val & ~EBU_CON_NANDM_EN, nand_con);

And I suspect you could just do:

	writel(0, ebu_host->ebu + EBU_CON);

here.

BTW, maybe we don't have to unselect the chip and can instead do this 'disable NAND module' in a runtime PM hook when the NAND has been unused for some time, but let's keep that for later.

Quoted 1 line

+}

...

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+static int ebu_nand_exec_op(struct nand_chip *chip,
+			    const struct nand_operation *op, bool check_only)
+{
+	struct ebu_nand_controller *ctrl = nand_to_ebu(chip);
+	const struct nand_op_instr *instr = NULL;
+	unsigned int op_id;
+	int i, time_out, ret = 0;

drivers/mtd/nand/raw/intel-nand-controller.c line 501

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+	u32 stat;
+
+	ebu_select_chip(chip);
+
+	for (op_id = 0; op_id < op->ninstrs; op_id++) {
+		instr = &op->instrs[op_id];
+
+		switch (instr->type) {
+		case NAND_OP_CMD_INSTR:
+			ebu_nand_writeb(chip, NAND_CLE_OFFS,

Hm, are you sure you shouldn't add NAND_CS_OFFS here? I'd expect the CS to be asserted when the CLE/ALE pin is. Or maybe NAND_CS_OFFS is not about CS pin assertion/de-assertion, in which case this should be documented (and the name should be changed accordingly).

Quoted 17 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +17 -0
+					instr->ctx.cmd.opcode);
+			break;
+
+		case NAND_OP_ADDR_INSTR:
+			for (i = 0; i < instr->ctx.addr.naddrs; i++)
+				ebu_nand_writeb(chip, NAND_ALE_OFFS,
+						instr->ctx.addr.addrs[i]);
+			break;
+
+		case NAND_OP_DATA_IN_INSTR:
+			ebu_read_buf(chip, instr->ctx.data.buf.in,
+				     instr->ctx.data.len);
+			break;
+
+		case NAND_OP_DATA_OUT_INSTR:
+			ebu_write_buf(chip, instr->ctx.data.buf.out,
+				      instr->ctx.data.len);

drivers/mtd/nand/raw/intel-nand-controller.c line 528

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+			break;
+
+		case NAND_OP_WAITRDY_INSTR:
+			time_out = instr->ctx.waitrdy.timeout_ms * 1000;
+			ret = readl_poll_timeout(ctrl->ebu_addr + EBU_WAIT,
+						 stat, stat & EBU_WAIT_RDBY,
+						 20, time_out);
+			break;
+		}
+	}

Yay! I really like this new version of exec_op().

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+
+	ebu_unselect_chip(chip);
+
+	return ret;
+}
+

drivers/mtd/nand/raw/intel-nand-controller.c line 544

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+static const struct nand_controller_ops ebu_nand_controller_ops = {
+	.attach_chip = ebu_nand_attach_chip,
+	.exec_op = ebu_nand_exec_op,
+};
+
+static void ebu_dma_cleanup(struct ebu_nand_controller *ebu_host)
+{
+	if (ebu_host->dma_rx) {
+		dma_release_channel(ebu_host->dma_rx);
+		ebu_host->dma_rx = NULL;

You don't need to reset the value here.

Quoted 27 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +27 -0
+	}
+
+	if (ebu_host->dma_tx) {
+		dma_release_channel(ebu_host->dma_tx);
+		ebu_host->dma_tx = NULL;
+	}
+}
+
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

drivers/mtd/nand/raw/intel-nand-controller.c line 588

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "failed to get chip select: %d\n", ret);
+		return ret;
+	}
+
+	ebu_host->cs = cs;
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cs0");
	resname = devm_kasprintf("nand-cs%d", cs);
	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
Quoted 30 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +30 -0
+	ebu_host->chip_addr = devm_ioremap_resource(&pdev->dev, res);
+	nandaddr_pa = res->start;
+	if (IS_ERR(ebu_host->chip_addr))
+		return PTR_ERR(ebu_host->chip_addr);
+
+	ebu_host->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(ebu_host->clk)) {
+		ret = PTR_ERR(ebu_host->clk);
+		dev_err(dev, "failed to get clock: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_prepare_enable(ebu_host->clk);
+	if (ret) {
+		dev_err(dev, "failed to enable clock: %d\n", ret);
+		return ret;
+	}
+	ebu_host->clk_rate = clk_get_rate(ebu_host->clk);
+
+	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 exit_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");

drivers/mtd/nand/raw/intel-nand-controller.c line 628

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+		goto exit_dma;
+	}
+
+	writel(lower_32_bits(nandaddr_pa) | EBU_ADDR_SEL_REGEN | EBU_ADDR_MASK,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(cs));
+
+	writel(EBU_BUSCON_CMULT_V4 | EBU_BUSCON_RECOVC(1) |
+	       EBU_BUSCON_HOLDC(1) | EBU_BUSCON_WAITRDC(2) |
+	       EBU_BUSCON_WAITWRC(2) | EBU_BUSCON_BCGEN_CS | EBU_BUSCON_ALEC |
+	       EBU_BUSCON_SETUP_EN, ebu_host->ebu_addr + EBU_BUSCON(cs));

Again, can you try to implement ->setup_data_interface()?

drivers/mtd/nand/raw/intel-nand-controller.c line 641

Quoted 13 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +13 -0
+
+	/*
+	 * NAND physical address selection is based on the chip select
+	 * and written to ADDR_SEL register to get Memory Region Base address.
+	 * FPI Bus addresses are compared to this base address in conjunction
+	 * with the mask control. Driver need to program this field!
+	 * Address: 0x17400 if chip select is CS_0
+	 * Address: 0x17C00 if chip select is CS_1
+	 */
+	writel(EBU_MEM_BASE_CS_0 + EBU_MEM_OFFSET,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(0));
+	writel(EBU_MEM_BASE_CS_1 + EBU_MEM_OFFSET,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(cs));

See my comments on those values. I feel like the mapping should be created based on information we gather from somewhere else.

Quoted 14 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +14 -0
+	nand_set_flash_node(&ebu_host->chip, dev->of_node);
+	mtd = nand_to_mtd(&ebu_host->chip);
+	mtd->dev.parent = dev;
+	ebu_host->dev = dev;
+
+	platform_set_drvdata(pdev, ebu_host);
+	nand_set_controller_data(&ebu_host->chip, ebu_host);
+
+	nand = &ebu_host->chip;
+	nand->controller = &ebu_host->controller;
+	nand->controller->ops = &ebu_nand_controller_ops;
+
+	/* Scan to find existence of the device */
+	ret = nand_scan(&ebu_host->chip, 1);

drivers/mtd/nand/raw/intel-nand-controller.c line 665

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+	if (ret)
+		goto exit_dma;
+
+	ret = mtd_device_register(mtd, NULL, 0);
+	if (ret)
+		goto clean_nand;
+
+	return 0;
+
+clean_nand:

err_cleanup_nand:

drivers/mtd/nand/raw/intel-nand-controller.c line 667

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+	nand_cleanup(&ebu_host->chip);
+exit_dma:

err_cleanup_dma:

drivers/mtd/nand/raw/intel-nand-controller.c line 678

Quoted 11 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +11 -0
+	ebu_dma_cleanup(ebu_host);
+	clk_disable_unprepare(ebu_host->clk);
+
+	return ret;
+}
+
+static int ebu_nand_remove(struct platform_device *pdev)
+{
+	struct ebu_nand_controller *ebu_host = platform_get_drvdata(pdev);
+
+	mtd_device_unregister(nand_to_mtd(&ebu_host->chip));

Check the return value of this function please.

[1]https://elixir.bootlin.com/linux/v5.6/source/drivers/mtd/nand/raw/atmel/nand-controller.c#L148

#5 lore raw

Hi Boris,

Thank you very much for review comments and your time...

Quoted 10 lines · Boris Brezillon

drivers/mtd/nand/raw/intel-nand-controller.c line 28

Quoted 5 lines · Vadivel MuruganX
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+#define EBU_CLC			0x000
+#define EBU_CLC_RST		0x00000000u
+
+#define	EBU_ADDR_SEL(n)		(0x20 + (n) * 4)

^ Please replace those tabs by a single space.

Noted.

Quoted 29 lines
Quoted 29 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +29 -0
+#define	EBU_ADDR_MASK		(5 << 4)
+#define	EBU_ADDR_SEL_REGEN	0x1
+
+#define EBU_BUSCON(n)		(0x60 + (n) * 4)
+#define EBU_BUSCON_CMULT_V4	0x1
+#define EBU_BUSCON_RECOVC(n)	((n) << 2)
+#define EBU_BUSCON_HOLDC(n)	((n) << 4)
+#define EBU_BUSCON_WAITRDC(n)	((n) << 6)
+#define EBU_BUSCON_WAITWRC(n)	((n) << 8)
+#define EBU_BUSCON_BCGEN_CS	0x0
+#define EBU_BUSCON_SETUP_EN	BIT(22)
+#define EBU_BUSCON_ALEC		0xC000
+
+#define EBU_CON			0x0B0
+#define EBU_CON_NANDM_EN	BIT(0)
+#define EBU_CON_NANDM_DIS	0x0
+#define EBU_CON_CSMUX_E_EN	BIT(1)
+#define EBU_CON_ALE_P_LOW	BIT(2)
+#define EBU_CON_CLE_P_LOW	BIT(3)
+#define EBU_CON_CS_P_LOW	BIT(4)
+#define EBU_CON_SE_P_LOW	BIT(5)
+#define EBU_CON_WP_P_LOW	BIT(6)
+#define EBU_CON_PRE_P_LOW	BIT(7)
+#define EBU_CON_IN_CS_S(n)	((n) << 8)
+#define EBU_CON_OUT_CS_S(n)	((n) << 10)
+#define EBU_CON_LAT_EN_CS_P	((0x3D) << 18)
+
+#define EBU_WAIT		0x0B4
+#define EBU_WAIT_RDBY		BIT(0)
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 61

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+#define EBU_WAIT_WR_C		BIT(3)
+
+#define	EBU_MEM_BASE_CS_0	0x17400
+#define	EBU_MEM_BASE_CS_1	0x17C00

If I refer to v2, that's actually 0x17400000 and 0x17C00000. And I suspect those addresses come from the physical addresses of the EBU range attached to those CS lines, which can be extracted from the resource passed to the driver. But maybe I'm wrong.

Agreed!, will update.

Quoted 2 lines
Quoted 1 line

+#define EBU_MEM_OFFSET 0x051

Sorry but that's too vague. What is this mask/offset encoding?

it's not offset, wrongly mentioned name as offset, bit field values. will correct it.

Quoted 9 lines
Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9 -0
+
+#define HSNAND_CTL1		0x110
+#define HSNAND_CTL1_ADDR_SHIFT	24
+
+#define HSNAND_CTL2		0x114
+#define HSNAND_CTL2_ADDR_SHIFT	8
+#define HSNAND_CTL2_CYC_N_V5	(0x2 << 16)
+
+#define HSNAND_INT_MSK_CTL	0x124
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 78

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+#define HSNAND_INT_MSK_CTL_WR_C	BIT(4)
+
+#define HSNAND_INT_STA		0x128
+#define HSNAND_INT_STA_WR_C	BIT(4)
+
+#define HSNAND_CTL		0x130
+#define HSNAND_CTL_MODE_ECC	0x1

#define HSNAND_CTL_ENABLE_ECC BIT(0)

Noted, will update

Quoted 11 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 87

Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9 -0
+#define HSNAND_CTL_GO		BIT(2)
+#define HSNAND_CTL_CE_SEL_CS(n)	BIT(3 + (n))
+#define HSNAND_CTL_RW_READ	0x0
+#define HSNAND_CTL_RW_WRITE	BIT(10)
+#define HSNAND_CTL_ECC_OFF_V8TH	BIT(11)
+#define HSNAND_CTL_CKFF_EN	0x0
+#define HSNAND_CTL_MSG_EN	BIT(17)
+
+#define NAND_PARA0		0x13c

Why are some of those registers prefixed NAND and others HSNAND? I guess HS stands for High-Speed.

To differentiate the common HSNAND registers between MIPS and X86 based SoC's

Quoted 9 lines
Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9 -0
+#define NAND_PARA0_PAGE_V8192	0x3
+#define NAND_PARA0_PIB_V256	(0x3 << 4)
+#define NAND_PARA0_BYP_EN_NP	0x0
+#define NAND_PARA0_BYP_DEC_NP	0x0
+#define NAND_PARA0_TYPE_ONFI	BIT(18)
+#define NAND_PARA0_ADEP_EN	BIT(21)
+
+#define NAND_CMSG_0		0x150
+#define NAND_CMSG_1		0x154
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 103

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+#define NAND_ALE_OFFS		BIT(2)
+#define NAND_CLE_OFFS		BIT(3)
+#define NAND_CS_OFFS		BIT(4)
+
+#define NAND_WRITE_CMD		(NAND_CS_OFFS | NAND_CLE_OFFS)
+#define NAND_WRITE_ADDR		(NAND_CS_OFFS | NAND_ALE_OFFS)

Those macros are no longer used, you can drop them.

Noted, will drop them

Quoted 3 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 105

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+#define NAND_WRITE_DATA		EBU_CON_CS_P_LOW
+#define NAND_READ_DATA		EBU_CON_CS_P_LOW

And those should not be used, please use NAND_CS_OFFS instead.

Sure, Noted

Quoted 6 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 110

Quoted 5 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+#define NAND_ECC_OFFSET		0x008
+
+struct ebu_nand_controller {
+	struct nand_controller	controller;

Can you drop the tabs and use one space between the type and field name?

Noted

Quoted 3 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 111

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	struct nand_chip	chip;

Can you add a comment explaining that this should be reworked if someone needs to support more than one chip.

Sure, will add comments

Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 113

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+	void __iomem		*ebu_addr;
+	void __iomem		*nand_addr;

Can we get rid of those _addr and rename those fields so they describe more precisely what the MMIO range is about:

	void __iomem *ebu;
	void __iomem *hsnand;

Noted

Quoted 4 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 114

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	void __iomem		*chip_addr;

This field should be part of a specialized nand_chip object (see what's done here [1]). More generally, you should move anything that's chip-specific to this driver-specific nand_chip object.

I supposed to add like nand_cs, will change it.

Quoted 7 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 118

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+	struct clk		*clk;
+	unsigned long		clk_rate;
+	u32			cs;
+	u32			nd_para0;

The cs and nd_para0 fields should be attached to the ebu_nand_chip object too (see [1]). While you move that, please add a comment saying that you currently only support single-CE chips.

Yes, you are correct, will do that

Quoted 11 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 122

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+	struct device		*dev;
+	struct dma_chan		*dma_tx;
+	struct dma_chan		*dma_rx;
+	struct completion	dma_access_complete;

Maybe

	struct {
		struct dma_chan *tx;
		struct dma_chan *rx;
		struct completion complete;
	} dma;

Ok, Noted

Quoted 2 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 123

Quoted 1 line
drivers/mtd/nand/raw/intel-nand-controller.c new file +1 -0
+	const char *cs_name;

You no longer use this field.

Noted, will drop it.

Quoted 10 lines
Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+};
+
+static inline struct ebu_nand_controller *nand_to_ebu(struct nand_chip *chip)
+{
+	return container_of(chip, struct ebu_nand_controller, chip);
+}
+
+static u8 ebu_nand_readb(struct nand_chip *chip, unsigned int op)
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 139

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+	void __iomem *nand_wait = ebu_host->ebu_addr + EBU_WAIT;
+	u32 stat;
+	int ret;
+	u8 val;
+
+	val = readb(ebu_host->chip_addr + op);

No need for op here, just pass NAND_CS_OFFS directly, and you can drop the op argument.

Noted, will update.

Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 146

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+	ret = readl_poll_timeout(nand_wait, stat, stat & EBU_WAIT_WR_C,
+				 20, 1000);
+	if (ret)
+		dev_warn(ebu_host->dev,
+			 "ebu nand write timeout. nand_wait(0x%p)=0x%x\n",
+			 nand_wait, readl(nand_wait));

Maybe dev_warn_ratelimited().

Not required, might be used for network drivers.

Quoted 26 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 151

Quoted 5 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +5 -0
+
+	return val;
+}
+
+static void ebu_nand_writeb(struct nand_chip *chip, int op, u8 value)
							^u32 offset,
Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
+	void __iomem *nand_wait = ebu_host->ebu_addr + EBU_WAIT;
+	u32 stat;
+	int ret;
+
+	writeb(value, ebu_host->chip_addr + op);

drivers/mtd/nand/raw/intel-nand-controller.c line 168

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+
+	ret = readl_poll_timeout(nand_wait, stat, stat & EBU_WAIT_WR_C,
+				 20, 1000);
+	if (ret)
+		dev_warn(ebu_host->dev,
+			 "ebu nand write timeout. nand_wait(0x%p)=0x%x\n",
+			 nand_wait, readl(nand_wait));
+}
+
+static void ebu_read_buf(struct nand_chip *chip, u_char *buf, int len)

^void * ^unsigned int

Quoted 1 line

Please update all of those.

Sure, will update all.

Quoted 6 lines
Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		buf[i] = ebu_nand_readb(chip, NAND_READ_DATA);
+}
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 181

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+static void ebu_write_buf(struct nand_chip *chip, const u_char *buf, int len)
+{
+	int i;
+
+	for (i = 0; i < len; i++)
+		ebu_nand_writeb(chip, NAND_WRITE_DATA, buf[i]);

^NAND_CS_OFFS

Noted.

Quoted 14 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 188

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+}
+
+static void ebu_unselect_chip(struct nand_chip *chip)
+{
+	struct ebu_nand_controller *ebu_host = nand_get_controller_data(chip);
+	void __iomem *nand_con = ebu_host->ebu_addr + EBU_CON;
+	int val;
	^u32

drivers/mtd/nand/raw/intel-nand-controller.c line 191

Quoted 3 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +3 -0
+
+	val = readl(nand_con);
+	writel(val & ~EBU_CON_NANDM_EN, nand_con);

And I suspect you could just do:

Quoted 7 lines
	writel(0, ebu_host->ebu + EBU_CON);

here.

BTW, maybe we don't have to unselect the chip and can instead do this 'disable NAND module' in a runtime PM hook when the NAND has been unused for some time, but let's keep that for later.

Sure, Noted.

Quoted 16 lines
Quoted 1 line

+}

...

Quoted 13 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +13 -0
+static int ebu_nand_exec_op(struct nand_chip *chip,
+			    const struct nand_operation *op, bool check_only)
+{
+	struct ebu_nand_controller *ctrl = nand_to_ebu(chip);
+	const struct nand_op_instr *instr = NULL;
+	unsigned int op_id;
+	int i, time_out, ret = 0;
+	u32 stat;
+
+	ebu_select_chip(chip);
+
+	for (op_id = 0; op_id < op->ninstrs; op_id++) {
+		instr = &op->instrs[op_id];
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 501

Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+
+		switch (instr->type) {
+		case NAND_OP_CMD_INSTR:
+			ebu_nand_writeb(chip, NAND_CLE_OFFS,

Hm, are you sure you shouldn't add NAND_CS_OFFS here? I'd expect the CS to be asserted when the CLE/ALE pin is. Or maybe NAND_CS_OFFS is not about CS pin assertion/de-assertion, in which case this should be documented (and the name should be changed accordingly).

before doing the read/write asserting the chip by chip_select function, let me double check as you said, will update accordingly

Quoted 20 lines
Quoted 20 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +20 -0
+					instr->ctx.cmd.opcode);
+			break;
+
+		case NAND_OP_ADDR_INSTR:
+			for (i = 0; i < instr->ctx.addr.naddrs; i++)
+				ebu_nand_writeb(chip, NAND_ALE_OFFS,
+						instr->ctx.addr.addrs[i]);
+			break;
+
+		case NAND_OP_DATA_IN_INSTR:
+			ebu_read_buf(chip, instr->ctx.data.buf.in,
+				     instr->ctx.data.len);
+			break;
+
+		case NAND_OP_DATA_OUT_INSTR:
+			ebu_write_buf(chip, instr->ctx.data.buf.out,
+				      instr->ctx.data.len);
+			break;
+
+		case NAND_OP_WAITRDY_INSTR:
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 528

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+			time_out = instr->ctx.waitrdy.timeout_ms * 1000;
+			ret = readl_poll_timeout(ctrl->ebu_addr + EBU_WAIT,
+						 stat, stat & EBU_WAIT_RDBY,
+						 20, time_out);
+			break;
+		}
+	}

Yay! I really like this new version of exec_op().

Thank you Boris!

Quoted 9 lines
Quoted 9 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +9 -0
+
+	ebu_unselect_chip(chip);
+
+	return ret;
+}
+
+static const struct nand_controller_ops ebu_nand_controller_ops = {
+	.attach_chip = ebu_nand_attach_chip,
+	.exec_op = ebu_nand_exec_op,
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 544

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+};
+
+static void ebu_dma_cleanup(struct ebu_nand_controller *ebu_host)
+{
+	if (ebu_host->dma_rx) {
+		dma_release_channel(ebu_host->dma_rx);
+		ebu_host->dma_rx = NULL;

You don't need to reset the value here.

Noted.

Quoted 30 lines
Quoted 30 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +30 -0
+	}
+
+	if (ebu_host->dma_tx) {
+		dma_release_channel(ebu_host->dma_tx);
+		ebu_host->dma_tx = NULL;
+	}
+}
+
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Ok, will check.

Quoted 9 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 588

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "failed to get chip select: %d\n", ret);
+		return ret;
+	}
+
+	ebu_host->cs = cs;
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cs0");
	resname = devm_kasprintf("nand-cs%d", cs);
	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);

I have kept same-way in my earlier patches , will update.

Quoted 33 lines
Quoted 33 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +33 -0
+	ebu_host->chip_addr = devm_ioremap_resource(&pdev->dev, res);
+	nandaddr_pa = res->start;
+	if (IS_ERR(ebu_host->chip_addr))
+		return PTR_ERR(ebu_host->chip_addr);
+
+	ebu_host->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(ebu_host->clk)) {
+		ret = PTR_ERR(ebu_host->clk);
+		dev_err(dev, "failed to get clock: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_prepare_enable(ebu_host->clk);
+	if (ret) {
+		dev_err(dev, "failed to enable clock: %d\n", ret);
+		return ret;
+	}
+	ebu_host->clk_rate = clk_get_rate(ebu_host->clk);
+
+	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 exit_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");
+		goto exit_dma;
+	}
+
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 628

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	writel(lower_32_bits(nandaddr_pa) | EBU_ADDR_SEL_REGEN | EBU_ADDR_MASK,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(cs));
+
+	writel(EBU_BUSCON_CMULT_V4 | EBU_BUSCON_RECOVC(1) |
+	       EBU_BUSCON_HOLDC(1) | EBU_BUSCON_WAITRDC(2) |
+	       EBU_BUSCON_WAITWRC(2) | EBU_BUSCON_BCGEN_CS | EBU_BUSCON_ALEC |
+	       EBU_BUSCON_SETUP_EN, ebu_host->ebu_addr + EBU_BUSCON(cs));

Again, can you try to implement ->setup_data_interface()?

Sure, will implement .

Quoted 7 lines
Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+
+	/*
+	 * NAND physical address selection is based on the chip select
+	 * and written to ADDR_SEL register to get Memory Region Base address.
+	 * FPI Bus addresses are compared to this base address in conjunction
+	 * with the mask control. Driver need to program this field!
+	 * Address: 0x17400 if chip select is CS_0
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 641

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+	 * Address: 0x17C00 if chip select is CS_1
+	 */
+	writel(EBU_MEM_BASE_CS_0 + EBU_MEM_OFFSET,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(0));
+	writel(EBU_MEM_BASE_CS_1 + EBU_MEM_OFFSET,
+	       ebu_host->ebu_addr + EBU_ADDR_SEL(cs));

See my comments on those values. I feel like the mapping should be created based on information we gather from somewhere else.

Yes, of-course will update the proper way.

Quoted 17 lines
Quoted 17 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +17 -0
+	nand_set_flash_node(&ebu_host->chip, dev->of_node);
+	mtd = nand_to_mtd(&ebu_host->chip);
+	mtd->dev.parent = dev;
+	ebu_host->dev = dev;
+
+	platform_set_drvdata(pdev, ebu_host);
+	nand_set_controller_data(&ebu_host->chip, ebu_host);
+
+	nand = &ebu_host->chip;
+	nand->controller = &ebu_host->controller;
+	nand->controller->ops = &ebu_nand_controller_ops;
+
+	/* Scan to find existence of the device */
+	ret = nand_scan(&ebu_host->chip, 1);
+	if (ret)
+		goto exit_dma;
+
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 665

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	ret = mtd_device_register(mtd, NULL, 0);
+	if (ret)
+		goto clean_nand;
+
+	return 0;
+
+clean_nand:

err_cleanup_nand:

Noted.

Quoted 3 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 667

Quoted 2 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +2 -0
+	nand_cleanup(&ebu_host->chip);
+exit_dma:

err_cleanup_dma:

Noted.

Quoted 4 lines
Quoted 4 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +4 -0
+	ebu_dma_cleanup(ebu_host);
+	clk_disable_unprepare(ebu_host->clk);
+
+	return ret;
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 678

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+}
+
+static int ebu_nand_remove(struct platform_device *pdev)
+{
+	struct ebu_nand_controller *ebu_host = platform_get_drvdata(pdev);
+
+	mtd_device_unregister(nand_to_mtd(&ebu_host->chip));

Check the return value of this function please.

sure, will check and update.
Regards
Vadivel

maintainer
#6 lore raw
In reply to Boris Brezillon

Hi Ramuthevar,

Quoted 23 lines
Quoted 23 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +23 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);  

CS ids should be encoded in the reg property (see [1]).

Is it your choice to only support a single CS or is it actually a controller limitation? If the latter, it would be much better I think to anticipate the addition of the support for another CS. And in this case there are many places in this driver that should be more generic.

Quoted 7 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 588

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "failed to get chip select: %d\n", ret);
+		return ret;
+	}
+
+	ebu_host->cs = cs;
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cs0");  

Thanks,
Miquèl

#7 lore raw

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 34 lines · Miquel Raynal

Hi Ramuthevar,

Quoted 23 lines
Quoted 23 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +23 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

Regards
Vadivel
If the latter, it would be much better I think

Quoted 15 lines

to anticipate the addition of the support for another CS. And in this case there are many places in this driver that should be more generic.

Quoted 7 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 588

Quoted 7 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +7 -0
+	if (ret) {
+		dev_err(dev, "failed to get chip select: %d\n", ret);
+		return ret;
+	}
+
+	ebu_host->cs = cs;
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cs0");

Thanks,
Miquèl

#8 lore raw
Quoted 39 lines · Vadivel MuruganX

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 34 lines · Miquel Raynal

Hi Ramuthevar,

Quoted 31 lines
Quoted 19 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +19 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);  

CS ids should be encoded in the reg property (see [1]).

Quoted 4 lines
Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

#9 lore raw

Hi Boris,

Quoted 43 lines · Boris Brezillon
Quoted 39 lines · Vadivel MuruganX

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 34 lines · Miquel Raynal

Hi Ramuthevar,

Quoted 31 lines
Quoted 19 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +19 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 10 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

At a time it supports only one chip select.
Thanks!

Regards
Vadivel

Quoted 1 line
#10 lore raw
Quoted 49 lines · Vadivel MuruganX

Hi Boris,

Quoted 46 lines · Boris Brezillon
Quoted 42 lines · Vadivel MuruganX

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 36 lines · Miquel Raynal

Hi Ramuthevar,

Quoted 23 lines
Quoted 23 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +23 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
Quoted 8 lines

drivers/mtd/nand/raw/intel-nand-controller.c line 581

Quoted 6 lines
drivers/mtd/nand/raw/intel-nand-controller.c new file +6 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);  

CS ids should be encoded in the reg property (see [1]).

Is it your choice to only support a single CS or is it actually a controller limitation?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

At a time it supports only one chip select.

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

#11 lore raw

Hi Boris,

Quoted 58 lines · Boris Brezillon
Quoted 54 lines · Vadivel MuruganX

Hi Boris,

Quoted 50 lines · Boris Brezillon
Quoted 39 lines · Vadivel MuruganX

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 34 lines · Miquel Raynal

Hi Ramuthevar,

Quoted 31 lines
Quoted 19 lines
(quoted diff) +19 -0
+static int ebu_nand_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

Review

Quoted 10 lines
(quoted diff) +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Quoted 4 lines
Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

Quoted 8 lines
Quoted 1 line

At a time it supports only one chip select.

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

Agreed, sure I will add that and update next series of patches .

Thanks! a lot Boris

Regards
Vadivel

Quoted 1 line
maintainer
#12 lore raw

Hi Vadivel MuruganX,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 14:50:35 +0800:

Quoted 61 lines

Hi Boris,

Quoted 58 lines · Boris Brezillon
Quoted 53 lines · Vadivel MuruganX

Hi Boris,

Quoted 41 lines · Boris Brezillon
Quoted 38 lines · Vadivel MuruganX
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 33 lines · Miquel Raynal

Hi Ramuthevar,
>>>>>>> +static int ebu_nand_probe(struct platform_device *pdev)

Quoted 30 lines
Quoted 18 lines
(quoted diff) +18 -0
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

Review

Quoted 10 lines
(quoted diff) +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);  

CS ids should be encoded in the reg property (see [1]).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

At a time it supports only one chip select.

Quoted 8 lines
Quoted 6 lines

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

Agreed, sure I will add that and update next series of patches .

There are also many other places where you assume blindly that there is only one CS. You can check the Atmel NAND controller driver as Boris said and we will probably propose more little changes to be more generic.

Thanks,
Miquèl

#13 lore raw

Hi Miquel,

Quoted 74 lines · Miquel Raynal

Hi Vadivel MuruganX,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 14:50:35 +0800:

Quoted 68 lines

Hi Boris,

Quoted 64 lines · Boris Brezillon
Quoted 47 lines · Vadivel MuruganX

Hi Boris,

Quoted 44 lines · Boris Brezillon
Quoted 41 lines · Vadivel MuruganX
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 35 lines · Miquel Raynal

Hi Ramuthevar,
>>>>>>> +static int ebu_nand_probe(struct platform_device *pdev)

Quoted 22 lines
Quoted 22 lines
(quoted diff) +22 -0
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Is it your choice to only support a single CS or is it actually a controller limitation?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

At a time it supports only one chip select.

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

Quoted 6 lines
Quoted 1 line

Agreed, sure I will add that and update next series of patches .

There are also many other places where you assume blindly that there is only one CS. You can check the Atmel NAND controller driver as Boris said and we will probably propose more little changes to be more generic.

since LGM EBU_NAND controller supports only one chip select at a time, so assumed like that, will change as generic way if consider like more chip select supports, Thanks!

Sure , I will do the changes as per your review comments.

Quoted 4 lines

Thanks,
Miquèl

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

maintainer
#14 lore raw

Hello,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 15:50:06 +0800:

Quoted 76 lines

Hi Miquel,

Quoted 73 lines · Miquel Raynal

Hi Vadivel MuruganX,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 14:50:35 +0800:

Quoted 67 lines

Hi Boris,

Quoted 63 lines · Boris Brezillon
Quoted 47 lines · Vadivel MuruganX
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Boris,

Quoted 44 lines · Boris Brezillon
Quoted 41 lines · Vadivel MuruganX
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Miquel,

Thank you very much for the review comments and your time...

Quoted 35 lines · Miquel Raynal

Hi Ramuthevar,
>>>>>>> +static int ebu_nand_probe(struct platform_device *pdev)

Quoted 22 lines
Quoted 22 lines
(quoted diff) +22 -0
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);  

CS ids should be encoded in the reg property (see [1]).

Is it your choice to only support a single CS or is it actually a controller limitation?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

At a time it supports only one chip select.

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Agreed, sure I will add that and update next series of patches .

There are also many other places where you assume blindly that there is only one CS. You can check the Atmel NAND controller driver as Boris said and we will probably propose more little changes to be more generic.

since LGM EBU_NAND controller supports only one chip select at a time, so assumed like that, will change as generic way if consider like more chip select supports, Thanks!

What do you mean "at a time"?

Do we have access to the spec or a register map? We could tell you very quickly if it is worth the trouble. But I am pretty sure as well that the controller supports more than 1 CS.

Quoted 5 lines

Sure , I will do the changes as per your review comments.

Quoted 4 lines

Thanks,
Miquèl

Thanks,
Miquèl

#15 lore raw

Hi Miquel,

Quoted 84 lines · Miquel Raynal

Hello,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 15:50:06 +0800:

Quoted 78 lines

Hi Miquel,

Quoted 75 lines · Miquel Raynal

Hi Vadivel MuruganX,

"Ramuthevar, Vadivel MuruganX" <[email protected]> wrote on Tue, 28 Apr 2020 14:50:35 +0800:

Quoted 68 lines

Hi Boris,

Quoted 55 lines · Boris Brezillon
Quoted 52 lines · Vadivel MuruganX
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Boris,

Quoted 48 lines · Boris Brezillon

On Tue, 28 Apr 2020 14:17:30 +0800 "Ramuthevar, Vadivel MuruganX" <[email protected]> wrote:

     >>>> Hi Miquel,
Quoted 37 lines

Thank you very much for the review comments and your time...

Quoted 33 lines · Miquel Raynal

Hi Ramuthevar,
>>>>>>> +static int ebu_nand_probe(struct platform_device *pdev)

Quoted 30 lines
Quoted 18 lines
(quoted diff) +18 -0
+{
+	struct device *dev = &pdev->dev;
+	struct ebu_nand_controller *ebu_host;
+	struct nand_chip *nand;
+	phys_addr_t nandaddr_pa;
+	struct mtd_info *mtd;
+	struct resource *res;
+	int ret;
+	u32 cs;
+
+	ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL);
+	if (!ebu_host)
+		return -ENOMEM;
+
+	ebu_host->dev = dev;
+	nand_controller_init(&ebu_host->controller);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ebunand");

Review

Quoted 10 lines
(quoted diff) +10 -0
+	ebu_host->ebu_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->ebu_addr))
+		return PTR_ERR(ebu_host->ebu_addr);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsnand");
+	ebu_host->nand_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ebu_host->nand_addr))
+		return PTR_ERR(ebu_host->nand_addr);
+
+	ret = device_property_read_u32(dev, "nand,cs", &cs);

CS ids should be encoded in the reg property (see [1]).

Quoted 4 lines
Quoted 2 lines

Is it your choice to only support a single CS or is it actually a controller limitation?

Yes , its controller limitation to support only one CS

I'm pretty sure that's not true, otherwise you wouldn't have to select the CS you want to use :P.

Quoted 8 lines
Quoted 1 line

At a time it supports only one chip select.

Yes, like 99% of the NAND controllers, but that doesn't mean you can't support multi-CS chips. All you have to do is attach an array of ebu_nand_cs to your ebu_nand_chip (as done in the atmel driver I pointed to). nand_operation.cs tells you which CS (index in your ebu_nand_cs array) a specific operation is targeting, and you can pick the right MMIO range/reg value based on that.

Agreed, sure I will add that and update next series of patches .

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

There are also many other places where you assume blindly that there is only one CS. You can check the Atmel NAND controller driver as Boris said and we will probably propose more little changes to be more generic.

since LGM EBU_NAND controller supports only one chip select at a time, so assumed like that, will change as generic way if consider like more chip select supports, Thanks!

What do you mean "at a time"?

I mean it supports multi-CS, during the run time it selects one. Thanks!

Regards
Vadivel

Quoted 14 lines

Do we have access to the spec or a register map? We could tell you very quickly if it is worth the trouble. But I am pretty sure as well that the controller supports more than 1 CS.

Quoted 5 lines

Sure , I will do the changes as per your review comments.

Quoted 4 lines

Thanks,
Miquèl

Thanks,
Miquèl

#16 lore raw
In reply to Miquel Raynal

Hi Miquel,

Quoted 3 lines · Miquel Raynal

Do we have access to the spec or a register map? We could tell you very quickly if it is worth the trouble. But I am pretty sure as well that the controller supports more than 1 CS.

Got it, will update the changes to support multiple CS as generic-way.

Thank you!

Regards
Vadivel