dri-devel Archive on lore.kernel.org
 help / color / Atom feed
From: "Álvaro Fernández Rojas" <noltari@gmail.com>
To: computersforpeace@gmail.com, kdasu.kdev@gmail.com,
	miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
	sumit.semwal@linaro.org, linux-mtd@lists.infradead.org,
	bcm-kernel-feedback-list@broadcom.com,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Cc: "Álvaro Fernández Rojas" <noltari@gmail.com>
Subject: [PATCH v2 5/5] mtd: rawnand: brcmnand: support v2.1-v2.2 controllers
Date: Tue, 12 May 2020 09:33:29 +0200
Message-ID: <20200512073329.742893-6-noltari@gmail.com> (raw)
In-Reply-To: <20200512073329.742893-1-noltari@gmail.com>

Tested on Netgear DGND3700v2 (BCM6362 with v2.2 controller).

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 v2: split page sizes rename into a different patch.
     name all block and page sizes versions.

 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 74 +++++++++++++++++++++---
 1 file changed, 66 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index ef60dbbeac2b..0af4e419ed99 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -338,6 +338,36 @@ enum brcmnand_reg {
 	BRCMNAND_FC_BASE,
 };
 
+/* BRCMNAND v2.1-v2.2 */
+static const u16 brcmnand_regs_v21[] = {
+	[BRCMNAND_CMD_START]		=  0x04,
+	[BRCMNAND_CMD_EXT_ADDRESS]	=  0x08,
+	[BRCMNAND_CMD_ADDRESS]		=  0x0c,
+	[BRCMNAND_INTFC_STATUS]		=  0x5c,
+	[BRCMNAND_CS_SELECT]		=  0x14,
+	[BRCMNAND_CS_XOR]		=  0x18,
+	[BRCMNAND_LL_OP]		=     0,
+	[BRCMNAND_CS0_BASE]		=  0x40,
+	[BRCMNAND_CS1_BASE]		=     0,
+	[BRCMNAND_CORR_THRESHOLD]	=     0,
+	[BRCMNAND_CORR_THRESHOLD_EXT]	=     0,
+	[BRCMNAND_UNCORR_COUNT]		=     0,
+	[BRCMNAND_CORR_COUNT]		=     0,
+	[BRCMNAND_CORR_EXT_ADDR]	=  0x60,
+	[BRCMNAND_CORR_ADDR]		=  0x64,
+	[BRCMNAND_UNCORR_EXT_ADDR]	=  0x68,
+	[BRCMNAND_UNCORR_ADDR]		=  0x6c,
+	[BRCMNAND_SEMAPHORE]		=  0x50,
+	[BRCMNAND_ID]			=  0x54,
+	[BRCMNAND_ID_EXT]		=     0,
+	[BRCMNAND_LL_RDATA]		=     0,
+	[BRCMNAND_OOB_READ_BASE]	=  0x20,
+	[BRCMNAND_OOB_READ_10_BASE]	=     0,
+	[BRCMNAND_OOB_WRITE_BASE]	=  0x30,
+	[BRCMNAND_OOB_WRITE_10_BASE]	=     0,
+	[BRCMNAND_FC_BASE]		= 0x200,
+};
+
 /* BRCMNAND v3.3-v4.0 */
 static const u16 brcmnand_regs_v33[] = {
 	[BRCMNAND_CMD_START]		=  0x04,
@@ -571,12 +601,16 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl)
 {
 	static const unsigned int block_sizes_v6[] = { 8, 16, 128, 256, 512, 1024, 2048, 0 };
 	static const unsigned int block_sizes_v4[] = { 16, 128, 8, 512, 256, 1024, 2048, 0 };
+	static const unsigned int block_sizes_v2_2[] = { 16, 128, 8, 512, 256, 0 };
+	static const unsigned int block_sizes_v2_1[] = { 16, 128, 8, 512, 0 };
 	static const unsigned int page_sizes_v3_4[] = { 512, 2048, 4096, 8192, 0 };
+	static const unsigned int page_sizes_v2_2[] = { 512, 2048, 4096, 0 };
+	static const unsigned int page_sizes_v2_1[] = { 512, 2048, 0 };
 
 	ctrl->nand_version = nand_readreg(ctrl, 0) & 0xffff;
 
-	/* Only support v4.0+? */
-	if (ctrl->nand_version < 0x0400) {
+	/* Only support v2.1+ */
+	if (ctrl->nand_version < 0x0201) {
 		dev_err(ctrl->dev, "version %#x not supported\n",
 			ctrl->nand_version);
 		return -ENODEV;
@@ -593,6 +627,8 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl)
 		ctrl->reg_offsets = brcmnand_regs_v50;
 	else if (ctrl->nand_version >= 0x0303)
 		ctrl->reg_offsets = brcmnand_regs_v33;
+	else if (ctrl->nand_version >= 0x0201)
+		ctrl->reg_offsets = brcmnand_regs_v21;
 
 	/* Chip-select stride */
 	if (ctrl->nand_version >= 0x0701)
@@ -618,14 +654,27 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl)
 		ctrl->max_page_size = 16 * 1024;
 		ctrl->max_block_size = 2 * 1024 * 1024;
 	} else {
-		ctrl->page_sizes = page_sizes_v3_4;
+		if (ctrl->nand_version >= 0x0304)
+			ctrl->page_sizes = page_sizes_v3_4;
+		else if (ctrl->nand_version >= 0x0202)
+			ctrl->page_sizes = page_sizes_v2_2;
+		else
+			ctrl->page_sizes = page_sizes_v2_1;
+
 		if (ctrl->nand_version >= 0x0600)
 			ctrl->block_sizes = block_sizes_v6;
-		else
+		else if (ctrl->nand_version >= 0x0400)
 			ctrl->block_sizes = block_sizes_v4;
+		else if (ctrl->nand_version >= 0x0202)
+			ctrl->block_sizes = block_sizes_v2_2;
+		else
+			ctrl->block_sizes = block_sizes_v2_1;
 
 		if (ctrl->nand_version < 0x0400) {
-			ctrl->max_page_size = 4096;
+			if (ctrl->nand_version < 0x0202)
+				ctrl->max_page_size = 2048;
+			else
+				ctrl->max_page_size = 4096;
 			ctrl->max_block_size = 512 * 1024;
 		}
 	}
@@ -811,6 +860,9 @@ static void brcmnand_wr_corr_thresh(struct brcmnand_host *host, u8 val)
 	enum brcmnand_reg reg = BRCMNAND_CORR_THRESHOLD;
 	int cs = host->cs;
 
+	if (!ctrl->reg_offsets[reg])
+		return;
+
 	if (ctrl->nand_version == 0x0702)
 		bits = 7;
 	else if (ctrl->nand_version >= 0x0600)
@@ -869,8 +921,10 @@ static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl)
 		return GENMASK(7, 0);
 	else if (ctrl->nand_version >= 0x0600)
 		return GENMASK(6, 0);
-	else
+	else if (ctrl->nand_version >= 0x0303)
 		return GENMASK(5, 0);
+	else
+		return GENMASK(4, 0);
 }
 
 #define NAND_ACC_CONTROL_ECC_SHIFT	16
@@ -2390,9 +2444,11 @@ static int brcmnand_set_cfg(struct brcmnand_host *host,
 
 	tmp = nand_readreg(ctrl, acc_control_offs);
 	tmp &= ~brcmnand_ecc_level_mask(ctrl);
-	tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT;
 	tmp &= ~brcmnand_spare_area_mask(ctrl);
-	tmp |= cfg->spare_area_size;
+	if (ctrl->nand_version >= 0x0302) {
+		tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT;
+		tmp |= cfg->spare_area_size;
+	}
 	nand_writereg(ctrl, acc_control_offs, tmp);
 
 	brcmnand_set_sector_size_1k(host, cfg->sector_size_1k);
@@ -2766,6 +2822,8 @@ const struct dev_pm_ops brcmnand_pm_ops = {
 EXPORT_SYMBOL_GPL(brcmnand_pm_ops);
 
 static const struct of_device_id brcmnand_of_match[] = {
+	{ .compatible = "brcm,brcmnand-v2.1" },
+	{ .compatible = "brcm,brcmnand-v2.2" },
 	{ .compatible = "brcm,brcmnand-v4.0" },
 	{ .compatible = "brcm,brcmnand-v5.0" },
 	{ .compatible = "brcm,brcmnand-v6.0" },
-- 
2.26.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply index

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10 15:14 [PATCH 1/3] nand: brcmnand: rename v4 registers Álvaro Fernández Rojas
2020-05-10 15:14 ` [PATCH 2/3] nand: brcmnand: fix CS0 layout Álvaro Fernández Rojas
2020-05-10 15:14 ` [PATCH 3/3] nand: brcmnand: support v2.1-v2.2 controllers Álvaro Fernández Rojas
2020-05-10 15:39   ` Florian Fainelli
2020-05-12  7:33 ` [PATCH v2 0/5] mtd: rawnand: " Álvaro Fernández Rojas
2020-05-12  7:33   ` [PATCH v2 1/5] mtd: rawnand: brcmnand: rename v4 registers Álvaro Fernández Rojas
2020-05-12  7:33   ` [PATCH v2 2/5] mtd: rawnand: brcmnand: fix CS0 layout Álvaro Fernández Rojas
2020-05-12  7:33   ` [PATCH v2 3/5] mtd: rawnand: brcmnand: rename page sizes Álvaro Fernández Rojas
2020-05-12  7:33   ` [PATCH v2 4/5] dt: bindings: brcmnand: add v2.1 and v2.2 support Álvaro Fernández Rojas
2020-05-12  7:33   ` Álvaro Fernández Rojas [this message]
2020-05-22  7:25   ` [PATCH v3 0/5] mtd: rawnand: brcmnand: support v2.1-v2.2 controllers Álvaro Fernández Rojas
2020-05-22  7:25     ` [PATCH v3 1/5] mtd: rawnand: brcmnand: rename v4 registers Álvaro Fernández Rojas
2020-05-22  7:25     ` [PATCH v3 2/5] mtd: rawnand: brcmnand: fix CS0 layout Álvaro Fernández Rojas
2020-05-22  7:25     ` [PATCH v3 3/5] mtd: rawnand: brcmnand: rename page sizes Álvaro Fernández Rojas
2020-05-22  7:25     ` [PATCH v3 4/5] dt: bindings: brcmnand: add v2.1 and v2.2 support Álvaro Fernández Rojas
2020-05-22  7:25     ` [PATCH v3 5/5] nand: brcmnand: support v2.1-v2.2 controllers Álvaro Fernández Rojas
2020-05-22 11:22       ` Miquel Raynal
2020-05-22 12:09         ` Álvaro Fernández Rojas
2020-05-22 12:15     ` [PATCH v4 0/5] mtd: rawnand: " Álvaro Fernández Rojas
2020-05-22 12:15       ` [PATCH v4 1/5] mtd: rawnand: brcmnand: rename v4 registers Álvaro Fernández Rojas
2020-05-22 15:33         ` Florian Fainelli
2020-05-24 19:26         ` Miquel Raynal
2020-05-22 12:15       ` [PATCH v4 2/5] mtd: rawnand: brcmnand: fix CS0 layout Álvaro Fernández Rojas
2020-05-22 15:35         ` Florian Fainelli
2020-05-24 19:26         ` Miquel Raynal
2020-05-22 12:15       ` [PATCH v4 3/5] mtd: rawnand: brcmnand: rename page sizes Álvaro Fernández Rojas
2020-05-22 15:35         ` Florian Fainelli
2020-05-24 19:26         ` Miquel Raynal
2020-05-22 12:15       ` [PATCH v4 4/5] dt: bindings: brcmnand: add v2.1 and v2.2 support Álvaro Fernández Rojas
2020-05-22 15:36         ` Florian Fainelli
2020-05-24 19:25         ` Miquel Raynal
2020-05-24 19:27           ` Miquel Raynal
2020-05-24 21:13             ` Álvaro Fernández Rojas
2020-05-24 22:06               ` Miquel Raynal
2020-05-22 12:15       ` [PATCH v4 5/5] mtd: rawnand: brcmnand: support v2.1-v2.2 controllers Álvaro Fernández Rojas
2020-05-22 15:37         ` Florian Fainelli
2020-05-24 22:06         ` Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200512073329.742893-6-noltari@gmail.com \
    --to=noltari@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=computersforpeace@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kdasu.kdev@gmail.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=sumit.semwal@linaro.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

dri-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dri-devel/0 dri-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dri-devel dri-devel/ https://lore.kernel.org/dri-devel \
		dri-devel@lists.freedesktop.org
	public-inbox-index dri-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.freedesktop.lists.dri-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git