* [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
@ 2020-12-15 21:46 Bert Vermeulen
2020-12-16 8:30 ` Tudor.Ambarus
0 siblings, 1 reply; 6+ messages in thread
From: Bert Vermeulen @ 2020-12-15 21:46 UTC (permalink / raw)
To: tudor.ambarus, miquel.raynal, richard, vigneshr, broonie,
john.garry, bbrezillon, gch981213, vadivel.muruganx.ramuthevar,
linux-kernel, linux-mtd
Cc: Bert Vermeulen
This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
and likely some older models as well (RTL8196C).
Signed-off-by: Bert Vermeulen <bert@biot.com>
---
drivers/mtd/spi-nor/controllers/Kconfig | 7 +
drivers/mtd/spi-nor/controllers/Makefile | 1 +
.../spi-nor/controllers/rtl8380-spiflash.c | 347 ++++++++++++++++++
.../spi-nor/controllers/rtl8380-spiflash.h | 34 ++
4 files changed, 389 insertions(+)
create mode 100644 drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c
create mode 100644 drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h
diff --git a/drivers/mtd/spi-nor/controllers/Kconfig b/drivers/mtd/spi-nor/controllers/Kconfig
index 5c0e0ec2e6d1..1e035c511ea5 100644
--- a/drivers/mtd/spi-nor/controllers/Kconfig
+++ b/drivers/mtd/spi-nor/controllers/Kconfig
@@ -62,3 +62,10 @@ config SPI_INTEL_SPI_PLATFORM
To compile this driver as a module, choose M here: the module
will be called intel-spi-platform.
+
+config SPI_REALTEK_RTL8380
+ tristate "Realtek RTL8380 SPI flash controller"
+ depends on MACH_REALTEK
+ help
+ This enables support for the SPI flash controller in the Realtek
+ RTL8380 series SoCs.
diff --git a/drivers/mtd/spi-nor/controllers/Makefile b/drivers/mtd/spi-nor/controllers/Makefile
index e7abba491d98..f03a79e88a78 100644
--- a/drivers/mtd/spi-nor/controllers/Makefile
+++ b/drivers/mtd/spi-nor/controllers/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
obj-$(CONFIG_SPI_INTEL_SPI) += intel-spi.o
obj-$(CONFIG_SPI_INTEL_SPI_PCI) += intel-spi-pci.o
obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM) += intel-spi-platform.o
+obj-$(CONFIG_SPI_REALTEK_RTL8380) += rtl8380-spiflash.o
diff --git a/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c b/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c
new file mode 100644
index 000000000000..cd1f48f1e3d0
--- /dev/null
+++ b/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c
@@ -0,0 +1,347 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/spi-nor.h>
+
+#include "rtl8380-spiflash.h"
+
+
+extern struct realtek_soc_info soc_info;
+
+static int rtl8380_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, size_t len);
+static int rtl8380_nor_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf, size_t len);
+
+
+static inline u32 rtl8380_read(struct rtl8380_nor *rtnor, u32 reg, bool wait)
+{
+ if (wait)
+ while (!(readl(rtnor->base + RTL8380_SPI_SFCSR) & RTL8380_SPI_SFCSR_RDY))
+ ;
+ return readl(rtnor->base + reg);
+}
+
+static inline void rtl8380_write(struct rtl8380_nor *rtnor, u32 reg, u32 value, bool wait)
+{
+ if (wait)
+ while (!(readl(rtnor->base + RTL8380_SPI_SFCSR) & RTL8380_SPI_SFCSR_RDY))
+ ;
+ writel(value, rtnor->base + reg);
+}
+
+/*
+ * Deactivate both chip selects and return base SFCSR register settings: correct
+ * CS, data length 1, IO width 1.
+ */
+static uint32_t spi_prep(struct rtl8380_nor *rtnor)
+{
+ uint32_t init, ret;
+
+ /* Deactivate CS0 and CS1 first */
+ init = (RTL8380_SPI_SFCSR_CSB0 | RTL8380_SPI_SFCSR_CSB1) & RTL8380_SPI_SFCSR_LEN_MASK;
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, init, true);
+
+ /* CS bitfield is active low, so reversed logic */
+ if (rtnor->cs == 0)
+ ret = RTL8380_SPI_SFCSR_LEN1 | RTL8380_SPI_SFCSR_CSB1;
+ else
+ ret = RTL8380_SPI_SFCSR_LEN1 | RTL8380_SPI_SFCSR_CSB0 | RTL8380_SPI_SFCSR_CS;
+
+ return ret;
+}
+
+static int rtl8380_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, size_t len)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ uint32_t sfcsr;
+
+ sfcsr = spi_prep(rtnor);
+ sfcsr &= RTL8380_SPI_SFCSR_LEN_MASK | RTL8380_SPI_SFCSR_LEN1;
+
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, opcode << 24, true);
+
+ while (len > 0) {
+ *(buf) = rtl8380_read(rtnor, RTL8380_SPI_SFDR, true) >> 24;
+ buf++;
+ len--;
+ }
+
+ return 0;
+}
+
+static int rtl8380_nor_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf,
+ size_t len)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ uint32_t sfcsr, sfdr, len_bits;
+
+ sfcsr = spi_prep(rtnor);
+ sfdr = opcode << 24;
+
+ if (len == 0) {
+ len_bits = RTL8380_SPI_SFCSR_LEN1;
+ } else if (len == 1) {
+ sfdr |= buf[0] << 16;
+ len_bits = RTL8380_SPI_SFCSR_LEN2;
+ } else if (len == 2) {
+ sfdr |= buf[0] << 16;
+ sfdr |= buf[1] << 8;
+ len_bits = RTL8380_SPI_SFCSR_LEN3;
+ } else {
+ return -EINVAL;
+ }
+ sfcsr |= len_bits;
+
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, sfdr, true);
+
+ return 0;
+}
+
+static ssize_t rtl8380_nor_read(struct spi_nor *nor, loff_t from, size_t len,
+ u_char *buf)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ uint32_t sfcsr;
+ ssize_t ret = 0;
+ int sfcsr_addrlen_bits, i;
+
+ if (rtnor->nor.addr_width == 4) {
+ sfcsr_addrlen_bits = 0x03;
+ } else {
+ sfcsr_addrlen_bits = 0x02;
+ from <<= 8;
+ }
+
+ sfcsr = spi_prep(rtnor);
+ sfcsr &= RTL8380_SPI_SFCSR_LEN_MASK;
+
+ /* Send read command */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN1, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, rtnor->nor.read_opcode << 24, false);
+
+ /* Send address */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | (sfcsr_addrlen_bits << 28), true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, from, false);
+
+ /* Dummy cycles */
+ for (i = 0; i < nor->read_dummy / 8; i++) {
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, 0, false);
+ }
+
+ /* Read 4 bytes at a time */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN4, true);
+ while (len >= 4){
+ *((uint32_t*) buf) = rtl8380_read(rtnor, RTL8380_SPI_SFDR, false);
+ buf += 4;
+ len -= 4;
+ ret += 4;
+ }
+
+ /* Read remainder 1 byte at a time */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN1, true);
+ while (len > 0) {
+ *(buf) = rtl8380_read(rtnor, RTL8380_SPI_SFDR, false) >> 24;
+ buf++;
+ len--;
+ ret++;
+ }
+
+ return ret;
+}
+
+static ssize_t rtl8380_nor_write(struct spi_nor *nor, loff_t to, size_t len,
+ const u_char *buf)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ uint32_t sfcsr;
+ ssize_t ret = 0;
+ int sfcsr_addrlen_bits;
+
+ if (rtnor->nor.addr_width == 4) {
+ sfcsr_addrlen_bits = 0x03;
+ } else {
+ sfcsr_addrlen_bits = 0x02;
+ to <<= 8;
+ }
+
+ sfcsr = spi_prep(rtnor);
+ sfcsr &= RTL8380_SPI_SFCSR_LEN_MASK;
+
+ /* Send write command */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN1, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, nor->program_opcode << 24, false);
+
+ /* Send address */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | (sfcsr_addrlen_bits << 28), true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, to, false);
+
+ /* Write 4 bytes at a time */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN4, true);
+ while (len >= 4) {
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, *((uint32_t*)buf), true);
+ buf += 4;
+ len -= 4;
+ ret += 4;
+ }
+
+ /* Write remainder 1 byte at a time */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN1, true);
+ while (len > 0) {
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, *buf << 24, true);
+ buf++;
+ len--;
+ ret++;
+ }
+
+ return ret;
+}
+
+static int rtl8380_erase(struct spi_nor *nor, loff_t offset)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ uint32_t sfcsr;
+ int sfcsr_addrlen_bits;
+
+ if (rtnor->nor.addr_width == 4) {
+ sfcsr_addrlen_bits = 0x03;
+ } else {
+ sfcsr_addrlen_bits = 0x02;
+ offset <<= 8;
+ }
+
+ sfcsr = spi_prep(rtnor);
+
+ /* Send erase command */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | RTL8380_SPI_SFCSR_LEN1, true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, nor->erase_opcode << 24, false);
+
+ /* Send address */
+ rtl8380_write(rtnor, RTL8380_SPI_SFCSR, sfcsr | (sfcsr_addrlen_bits << 28), true);
+ rtl8380_write(rtnor, RTL8380_SPI_SFDR, offset, false);
+
+ return 0;
+}
+
+static const struct spi_nor_controller_ops rtl8380_controller_ops = {
+ .read_reg = rtl8380_nor_read_reg,
+ .write_reg = rtl8380_nor_write_reg,
+ .read = rtl8380_nor_read,
+ .write = rtl8380_nor_write,
+ .erase = rtl8380_erase,
+};
+
+static int rtl8380_spi_nor_scan(struct spi_nor *nor)
+{
+ struct rtl8380_nor *rtnor = nor->priv;
+ static const struct spi_nor_hwcaps hwcaps = {
+ .mask = SNOR_HWCAPS_READ | SNOR_HWCAPS_READ_FAST | SNOR_HWCAPS_PP
+ };
+ u32 sfcr;
+ int ret;
+
+ /* Turn on big-endian byte ordering */
+ sfcr = rtl8380_read(rtnor, RTL8380_SPI_SFCR, true);
+ sfcr |= RTL8380_SPI_SFCR_RBO | RTL8380_SPI_SFCR_WBO;
+ rtl8380_write(rtnor, RTL8380_SPI_SFCR, sfcr, true);
+
+ ret = spi_nor_scan(nor, NULL, &hwcaps);
+
+ return ret;
+}
+
+static int rtl8380_nor_init(struct rtl8380_nor *rtnor,
+ struct device_node *flash_node)
+{
+ struct spi_nor *nor;
+ int ret;
+
+ nor = &rtnor->nor;
+ nor->priv = rtnor;
+ spi_nor_set_flash_node(nor, flash_node);
+ nor->controller_ops = &rtl8380_controller_ops;
+ nor->mtd.name = "rtl8380-spiflash";
+
+ ret = rtl8380_spi_nor_scan(nor);
+ if (ret)
+ return ret;
+ pr_info("SPI flash address width is %d bytes\n", nor->addr_width);
+
+ ret = mtd_device_parse_register(&nor->mtd, NULL, NULL, NULL, 0);
+
+ return ret;
+}
+
+static int rtl8380_nor_drv_probe(struct platform_device *pdev)
+{
+ struct device_node *flash_np;
+ struct resource *res;
+ struct rtl8380_nor *rtnor;
+ int ret;
+
+ if (!pdev->dev.of_node) {
+ dev_err(&pdev->dev, "No DT found\n");
+ return -EINVAL;
+ }
+
+ rtnor = devm_kzalloc(&pdev->dev, sizeof(*rtnor), GFP_KERNEL);
+ if (!rtnor)
+ return -ENOMEM;
+ platform_set_drvdata(pdev, rtnor);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ rtnor->base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(rtnor->base))
+ return PTR_ERR(rtnor->base);
+
+ rtnor->nor.dev = &pdev->dev;
+
+ /* Only support one attached flash */
+ flash_np = of_get_next_available_child(pdev->dev.of_node, NULL);
+ if (!flash_np) {
+ dev_err(&pdev->dev, "no SPI flash device to configure\n");
+ return -ENODEV;
+ }
+
+ /* Optional chip select, defaults to 0 */
+ ret = of_property_read_u32(flash_np, "reg", &rtnor->cs);
+ if (ret)
+ rtnor->cs = 0;
+
+ ret = rtl8380_nor_init(rtnor, flash_np);
+
+ return ret;
+}
+
+static int rtl8380_nor_drv_remove(struct platform_device *pdev)
+{
+ struct rtl8380_nor *rtnor;
+
+ rtnor = platform_get_drvdata(pdev);
+ mtd_device_unregister(&rtnor->nor.mtd);
+
+ return 0;
+}
+
+static const struct of_device_id rtl8380_nor_of_ids[] = {
+ { .compatible = "realtek,rtl8380-spiflash"},
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, rtl8380_nor_of_ids);
+
+static struct platform_driver rtl8380_nor_driver = {
+ .probe = rtl8380_nor_drv_probe,
+ .remove = rtl8380_nor_drv_remove,
+ .driver = {
+ .name = "rtl8380-spiflash",
+ .pm = NULL,
+ .of_match_table = rtl8380_nor_of_ids,
+ },
+};
+
+module_platform_driver(rtl8380_nor_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("RTL8380 SPI NOR Flash Driver");
diff --git a/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h b/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h
new file mode 100644
index 000000000000..754e67087ed1
--- /dev/null
+++ b/drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifndef _RTL8380_SPIFLASH_H_
+#define _RTL8380_SPIFLASH_H_
+
+struct rtl8380_nor {
+ struct spi_nor nor;
+ void __iomem *base;
+ u32 cs;
+};
+
+/* SPI Flash Configuration Register */
+#define RTL8380_SPI_SFCR 0x00
+#define RTL8380_SPI_SFCR_RBO BIT(28)
+#define RTL8380_SPI_SFCR_WBO BIT(27)
+
+/* SPI Flash Control and Status Register */
+#define RTL8380_SPI_SFCSR 0x08
+#define RTL8380_SPI_SFCSR_CSB0 BIT(31)
+#define RTL8380_SPI_SFCSR_CSB1 BIT(30)
+#define RTL8380_SPI_SFCSR_RDY BIT(27)
+#define RTL8380_SPI_SFCSR_CS BIT(24)
+#define RTL8380_SPI_SFCSR_LEN_MASK ~(0x03 << 28)
+#define RTL8380_SPI_SFCSR_LEN1 (0x00 << 28)
+#define RTL8380_SPI_SFCSR_LEN2 (0x01 << 28)
+#define RTL8380_SPI_SFCSR_LEN3 (0x02 << 28)
+#define RTL8380_SPI_SFCSR_LEN4 (0x03 << 28)
+
+/* SPI Flash Data Registers */
+#define RTL8380_SPI_SFDR 0x0c
+#define RTL8380_SPI_SFDR2 0x10
+
+#endif /* _RTL8380_SPIFLASH_H_ */
+
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
2020-12-15 21:46 [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs Bert Vermeulen
@ 2020-12-16 8:30 ` Tudor.Ambarus
2020-12-16 11:15 ` Chuanhong Guo
2020-12-19 22:58 ` Bert Vermeulen
0 siblings, 2 replies; 6+ messages in thread
From: Tudor.Ambarus @ 2020-12-16 8:30 UTC (permalink / raw)
To: bert, miquel.raynal, richard, vigneshr, broonie, john.garry,
bbrezillon, gch981213, vadivel.muruganx.ramuthevar, linux-kernel,
linux-mtd
On 12/15/20 11:46 PM, Bert Vermeulen wrote:
> This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
> and likely some older models as well (RTL8196C).
>
Can we use SPIMEM and move this under drivers/spi/ instead?
Cheers,
ta
> Signed-off-by: Bert Vermeulen <bert@biot.com>
> ---
> drivers/mtd/spi-nor/controllers/Kconfig | 7 +
> drivers/mtd/spi-nor/controllers/Makefile | 1 +
> .../spi-nor/controllers/rtl8380-spiflash.c | 347 ++++++++++++++++++
> .../spi-nor/controllers/rtl8380-spiflash.h | 34 ++
> 4 files changed, 389 insertions(+)
> create mode 100644 drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c
> create mode 100644 drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
2020-12-16 8:30 ` Tudor.Ambarus
@ 2020-12-16 11:15 ` Chuanhong Guo
2020-12-19 22:58 ` Bert Vermeulen
1 sibling, 0 replies; 6+ messages in thread
From: Chuanhong Guo @ 2020-12-16 11:15 UTC (permalink / raw)
To: Tudor Ambarus
Cc: bert, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Mark Brown, john.garry, Boris Brezillon,
vadivel.muruganx.ramuthevar, open list, linux-mtd
Hi!
On Wed, Dec 16, 2020 at 4:30 PM <Tudor.Ambarus@microchip.com> wrote:
>
> On 12/15/20 11:46 PM, Bert Vermeulen wrote:
> > This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
> > and likely some older models as well (RTL8196C).
> >
> Can we use SPIMEM and move this under drivers/spi/ instead?
>
> Cheers,
> ta
Just took a brief look at the code, and here's my current understanding
of this controller:
1. CS is controlled separately with SFCSR_CSB* bits
2. To write 1-4 bytes, set SFCSR_LEN* and write to SFDR
2. To read 1-4 bytes, set SFCSR_LEN* and read SFDR
If that's true, this is a generic half-duplex spi controller, and the driver
should register a spi_controller with set_cs and transfer_one
implemented.
--
Regards,
Chuanhong Guo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
2020-12-16 8:30 ` Tudor.Ambarus
2020-12-16 11:15 ` Chuanhong Guo
@ 2020-12-19 22:58 ` Bert Vermeulen
2020-12-20 8:51 ` Chuanhong Guo
1 sibling, 1 reply; 6+ messages in thread
From: Bert Vermeulen @ 2020-12-19 22:58 UTC (permalink / raw)
To: Tudor.Ambarus, miquel.raynal, richard, vigneshr, broonie,
john.garry, bbrezillon, gch981213, vadivel.muruganx.ramuthevar,
linux-kernel, linux-mtd
On 12/16/20 9:30 AM, Tudor.Ambarus@microchip.com wrote:
> On 12/15/20 11:46 PM, Bert Vermeulen wrote:
>> This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
>> and likely some older models as well (RTL8196C).
>>
> Can we use SPIMEM and move this under drivers/spi/ instead?
I wasn't aware spimem was the thing to use for new drivers. I will rewrite
the driver to that API.
--
Bert Vermeulen
bert@biot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
2020-12-19 22:58 ` Bert Vermeulen
@ 2020-12-20 8:51 ` Chuanhong Guo
2020-12-20 15:36 ` Bert Vermeulen
0 siblings, 1 reply; 6+ messages in thread
From: Chuanhong Guo @ 2020-12-20 8:51 UTC (permalink / raw)
To: Bert Vermeulen
Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Mark Brown, john.garry, Boris Brezillon,
vadivel.muruganx.ramuthevar, open list, linux-mtd
Hi!
On Sun, Dec 20, 2020 at 7:01 AM Bert Vermeulen <bert@biot.com> wrote:
>
> On 12/16/20 9:30 AM, Tudor.Ambarus@microchip.com wrote:
> > On 12/15/20 11:46 PM, Bert Vermeulen wrote:
> >> This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
> >> and likely some older models as well (RTL8196C).
> >>
> > Can we use SPIMEM and move this under drivers/spi/ instead?
>
> I wasn't aware spimem was the thing to use for new drivers. I will rewrite
> the driver to that API.
Are there any limitations preventing this from being implemented as a
generic SPI controller?
spi-nor and spi-mem are designed for controllers which can only perform
spi-mem/spi-nor specific transfers. I can't find such limitations from
your current driver code.
BTW I found a SPI controller driver for RTL8196C here: [0]
It seems pretty similar to the controller you are working on.
[0]: https://github.com/hackpascal/lede-rtl8196c/blob/realtek/target/linux/realtek/files/drivers/spi/spi-realtek.c
--
Regards,
Chuanhong Guo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
2020-12-20 8:51 ` Chuanhong Guo
@ 2020-12-20 15:36 ` Bert Vermeulen
0 siblings, 0 replies; 6+ messages in thread
From: Bert Vermeulen @ 2020-12-20 15:36 UTC (permalink / raw)
To: Chuanhong Guo
Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Mark Brown, john.garry, Boris Brezillon,
vadivel.muruganx.ramuthevar, open list, linux-mtd
On 12/20/20 9:51 AM, Chuanhong Guo wrote:
> Hi!
>
> On Sun, Dec 20, 2020 at 7:01 AM Bert Vermeulen <bert@biot.com> wrote:
>>
>> On 12/16/20 9:30 AM, Tudor.Ambarus@microchip.com wrote:
>> > On 12/15/20 11:46 PM, Bert Vermeulen wrote:
>> >> This driver supports the spiflash core in all RTL838x/RTL839x SoCs,
>> >> and likely some older models as well (RTL8196C).
>> >>
>> > Can we use SPIMEM and move this under drivers/spi/ instead?
>>
>> I wasn't aware spimem was the thing to use for new drivers. I will rewrite
>> the driver to that API.
>
> Are there any limitations preventing this from being implemented as a
> generic SPI controller?
> spi-nor and spi-mem are designed for controllers which can only perform
> spi-mem/spi-nor specific transfers. I can't find such limitations from
> your current driver code.
>
> BTW I found a SPI controller driver for RTL8196C here: [0]
> It seems pretty similar to the controller you are working on.
>
> [0]:
https://github.com/hackpascal/lede-rtl8196c/blob/realtek/target/linux/realtek/files/drivers/spi/spi-realtek.c
The SoC's SPI core is very much intended for SPI flash use only, and indeed
we haven't come across anything else connected to that SPI bus in dozens of
devices.
I wrote my driver based on Realtek code and a datasheet for the (older)
RTL8196C found floating around the net, and found no inconsistencies.
I hadn't seen that RTL8196C driver, but if it works that proves a plain SPI
driver will do. I'll investigate.
--
Bert Vermeulen
bert@biot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-12-20 15:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 21:46 [PATCH] Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs Bert Vermeulen
2020-12-16 8:30 ` Tudor.Ambarus
2020-12-16 11:15 ` Chuanhong Guo
2020-12-19 22:58 ` Bert Vermeulen
2020-12-20 8:51 ` Chuanhong Guo
2020-12-20 15:36 ` Bert Vermeulen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).