Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
Subsystems (2)
PATCH 1/1 Add spi-nor driver for Realtek RTL838x/RTL839x switch SoCs
This driver supports the spiflash core in all RTL838x/RTL839x SoCs, and likely some older models as well (RTL8196C).
--- 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
drivers/mtd/spi-nor/controllers/Kconfig +7 -0
@@ -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.
drivers/mtd/spi-nor/controllers/Makefile +1 -0
@@ -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
drivers/mtd/spi-nor/controllers/rtl8380-spiflash.c new file +347 -0
347 lines not on this page · raw message
drivers/mtd/spi-nor/controllers/rtl8380-spiflash.h new file +34 -0
@@ -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_ */ +
Signature · 1 line
2.25.1
Quoted 3 lines · Bert Vermeulen
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
Quoted 9 lines
Signed-off-by Bert Vermeulen <[email protected]>--- 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi!
Quoted 9 lines · On Wed, Dec 16, 2020 at 4:30 PM <[email protected]> wrote:
Quoted 3 lines · Bert Vermeulen
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.
Signature · 6 lines
Regards, Chuanhong Guo ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 5 lines · On 12/16/20 9:30 AM, [email protected] wrote:
Quoted 3 lines · Bert Vermeulen
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.
Signature · 2 lines
Bert Vermeulen [email protected]
Hi!
Quoted 10 lines · Bert Vermeulen
Quoted 5 lines · On 12/16/20 9:30 AM, [email protected] wrote:
Quoted 3 lines · Bert Vermeulen
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.
Signature · 2 lines
Regards, Chuanhong Guo
Quoted 20 lines · Chuanhong Guo
Hi!
Quoted 10 lines · Bert Vermeulen
Quoted 5 lines · On 12/16/20 9:30 AM, [email protected] wrote:
Quoted 3 lines · Bert Vermeulen
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.
Quoted 4 lines
BTW I found a SPI controller driver for RTL8196C here: [0] It seems pretty similar to the controller you are working on.
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.
Signature · 2 lines
Bert Vermeulen [email protected]