[RFC] mtd: spi-nor: Add Renesas AT25QL128A serial nor flash

Biju Das biju.das.jz at bp.renesas.com
Sun May 1 11:55:12 PDT 2022


Add support for Renesas AT25QL128A serial nor flash.
Details of flash chip can be found here [1]

[1] https://www.dialog-semiconductor.com/sites/default/files/2022-04/DS-AT25QL128A-129F-022022.pdf

Signed-off-by: Biju Das <biju.das.jz at bp.renesas.com>
---
Hi All,
 AT25QL128A serial nor flash is connected to RZ/G2UL SMARC EVK.
But with the current mtd support in mainline, I get the below error
[    3.928906] spi-nor spi1.0: unrecognized JEDEC id bytes: 1f 42 18 1f 42 18
[    3.937312] spi-nor: probe of spi1.0 failed with error -2

Then, I created a patch and the issue gone, It can detect the flash
[    3.937168] spi-nor spi1.0: at25ql128a (16384 Kbytes)
[    3.942902] 2 fixed-partitions partitions found on MTD device spi1.0
[    3.949459] Creating 2 MTD partitions on "spi1.0":
[    3.957540] 0x000000000000-0x000000200000 : "boot"
[    3.973740] 0x000000200000-0x000001000000 : "user"


Able to do read/write/format the partition with this patch.
So please provide your feedback on this patch.

&sbc {
	pinctrl-0 = <&qspi0_pins>;
	pinctrl-names = "default";
	status = "okay";

	flash at 0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <50000000>;
		spi-tx-bus-width = <1>;
		spi-rx-bus-width = <4>;

		spi-cpol;
		spi-cpha;
		m25p,fast-read;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			boot at 0 {
				reg = <0x00000000 0x200000>;
				read-only;
			};
			user at 200000 {
				reg = <0x200000 0xE00000>;
			};
		};
	};
};
---
 drivers/mtd/spi-nor/Makefile  |  1 +
 drivers/mtd/spi-nor/core.c    |  1 +
 drivers/mtd/spi-nor/core.h    |  1 +
 drivers/mtd/spi-nor/renesas.c | 57 +++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
 create mode 100644 drivers/mtd/spi-nor/renesas.c

diff --git a/drivers/mtd/spi-nor/Makefile b/drivers/mtd/spi-nor/Makefile
index 6b904e439372..2c2fce8e6132 100644
--- a/drivers/mtd/spi-nor/Makefile
+++ b/drivers/mtd/spi-nor/Makefile
@@ -12,6 +12,7 @@ spi-nor-objs			+= intel.o
 spi-nor-objs			+= issi.o
 spi-nor-objs			+= macronix.o
 spi-nor-objs			+= micron-st.o
+spi-nor-objs			+= renesas.o
 spi-nor-objs			+= spansion.o
 spi-nor-objs			+= sst.o
 spi-nor-objs			+= winbond.o
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index b4f141ad9c9c..ba9f222da00b 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1621,6 +1621,7 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
 	&spi_nor_issi,
 	&spi_nor_macronix,
 	&spi_nor_micron,
+	&spi_nor_renesas,
 	&spi_nor_st,
 	&spi_nor_spansion,
 	&spi_nor_sst,
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index b7fd760e3b47..3d2e39329079 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -511,6 +511,7 @@ extern const struct spi_nor_manufacturer spi_nor_intel;
 extern const struct spi_nor_manufacturer spi_nor_issi;
 extern const struct spi_nor_manufacturer spi_nor_macronix;
 extern const struct spi_nor_manufacturer spi_nor_micron;
+extern const struct spi_nor_manufacturer spi_nor_renesas;
 extern const struct spi_nor_manufacturer spi_nor_st;
 extern const struct spi_nor_manufacturer spi_nor_spansion;
 extern const struct spi_nor_manufacturer spi_nor_sst;
diff --git a/drivers/mtd/spi-nor/renesas.c b/drivers/mtd/spi-nor/renesas.c
new file mode 100644
index 000000000000..091542c8c088
--- /dev/null
+++ b/drivers/mtd/spi-nor/renesas.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2005, Intec Automation Inc.
+ * Copyright (C) 2014, Freescale Semiconductor, Inc.
+ */
+
+#include <linux/mtd/spi-nor.h>
+
+#include "core.h"
+
+static const struct flash_info renesas_nor_parts[] = {
+	{ "at25ql128a", INFO(0x1f4218, 0, 64 * 1024, 256)
+		NO_SFDP_FLAGS(SECT_4K | SPI_NOR_QUAD_READ) },
+};
+
+/**
+ * renesas_nor_set_4byte_addr_mode() - Set 4-byte address mode for Renesas
+ * flashes.
+ * @nor:	pointer to 'struct spi_nor'.
+ * @enable:	true to enter the 4-byte address mode, false to exit the 4-byte
+ *		address mode.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int renesas_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
+{
+	int ret;
+
+	ret = spi_nor_write_enable(nor);
+	if (ret)
+		return ret;
+
+	ret = spi_nor_set_4byte_addr_mode(nor, enable);
+	if (ret)
+		return ret;
+
+	return spi_nor_write_disable(nor);
+}
+
+static void renesas_nor_default_init(struct spi_nor *nor)
+{
+	nor->flags |= SNOR_F_HAS_LOCK;
+	nor->flags &= ~SNOR_F_HAS_16BIT_SR;
+	nor->params->quad_enable = NULL;
+	nor->params->set_4byte_addr_mode = renesas_nor_set_4byte_addr_mode;
+}
+
+static const struct spi_nor_fixups renesas_nor_fixups = {
+	.default_init = renesas_nor_default_init,
+};
+
+const struct spi_nor_manufacturer spi_nor_renesas = {
+	.name = "renesas",
+	.parts = renesas_nor_parts,
+	.nparts = ARRAY_SIZE(renesas_nor_parts),
+	.fixups = &renesas_nor_fixups,
+};
-- 
2.25.1




More information about the linux-mtd mailing list