spi: realtek: Add support for RTD1625 SPI NOR Flash Controller
Subsystems (3)
Yu-Chun Lin
maintainerv5 cover spi: realtek: Add support for RTD1625 SPI NOR Flash Controller
Hi all,
This patch series introduces support for the Realtek RTD1625 SPI NOR Flash controller.
Thansk,
Yu-Chun
---
Changes in v5:
Patch 2:
- Fix the initialization and teardown sequences based on Philipp's suggestions.
- Add the check for unsupported multi-byte stateless commands in rtk_spi_supports_op().
- Move the hardware workaround for 4-byte mode switching to rtk_spi_exec_op().
v4: https://lore.kernel.org/lkml/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
Jyan Chou (2):
dt-bindings: spi: Add Realtek RTD1625 SPI NOR support
spi: spi-mem: Add Realtek SPI NOR flash controller driver
.../bindings/spi/realtek,rtd1625-nor.yaml | 65 ++ MAINTAINERS | 6 + drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-rtk-nor.c | 624 ++++++++++++++++++ 5 files changed, 706 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/realtek,rtd1625-nor.yaml create mode 100644 drivers/spi/spi-rtk-nor.c
Signature · 1 line
2.43.0
Yu-Chun Lin
maintainerPATCH v5 1/2 dt-bindings: spi: Add Realtek RTD1625 SPI NOR support
From: Jyan Chou <[email protected]>
Add DT binding schema for Realtek RTD1625 SPI NOR Flash Controller
---
Changes in v5:
- None.
--- .../bindings/spi/realtek,rtd1625-nor.yaml | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/realtek,rtd1625-nor.yaml
Documentation/devicetree/bindings/spi/realtek,rtd1625-nor.yaml new file +65 -0
@@ -0,0 +1,65 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/realtek,rtd1625-nor.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek RTD1625 SPI NOR Flash Controller + +maintainers: + - Jyan Chou <[email protected]> + - Yu-Chun Lin <[email protected]> + +properties: + compatible: + enum: + - realtek,rtd1625-nor + + reg: + maxItems: 3 + + reg-names: + items: + - const: ctrl + - const: dma + - const: dirmap + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +required: + - compatible + - reg + - reg-names + - clocks + - resets + - "#address-cells" + - "#size-cells" + +allOf: + - $ref: /schemas/spi/spi-controller.yaml# + +unevaluatedProperties: false + +examples: + - | + spi@14b000 { + compatible = "realtek,rtd1625-nor"; + reg = <0x14b000 0x50>, <0x14bf00 0x30>, <0x88100000 0x2000000>; + reg-names = "ctrl", "dma", "dirmap"; + clocks = <&cc 18>; + resets = <&cc 26>; + pinctrl-0 = <&spi_pins>; + pinctrl-names = "default"; + #address-cells = <1>; + #size-cells = <0>; + };
Signature · 1 line
2.43.0
Yu-Chun Lin
maintainerPATCH v5 2/2 spi: spi-mem: Add Realtek SPI NOR flash controller driver
In reply to Yu-Chun LinFrom: Jyan Chou <[email protected]>
Add a spi-mem driver for the SPI NOR Flash Controller (SFC) found on Realtek DHC SoC. SFC supports Dual I/O.
Implement the exec_op API for regular control commands and the dirmap API for hardware-accelerated read/write operations.
The controller is described by three register ranges. The first one (ctrl) holds the control registers. The second one (dma) holds the DMA engine registers, used to transfer the payload between the flash and main memory. The third range is the memory aperture (dirmap) that maps the flash contents.
---
Changes in v5:
- Fix the initialization and teardown sequences.
- Add the check for unsupported multi-byte stateless commands in rtk_spi_supports_op().
- Move the hardware workaround for 4-byte mode switching to rtk_spi_exec_op().
--- MAINTAINERS | 6 + drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-rtk-nor.c | 624 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 641 insertions(+) create mode 100644 drivers/spi/spi-rtk-nor.c
MAINTAINERS +6 -0
@@ -22754,6 +22754,12 @@ S: Maintained F: Documentation/devicetree/bindings/spi/realtek,rtl9301-snand.yaml F: drivers/spi/spi-realtek-rtl-snand.c +REALTEK SPI-NOR +M: Jyan Chou <[email protected]> +M: Yu-Chun Lin <[email protected]> +S: Supported +F: drivers/spi/spi-rtk-nor.c + REALTEK SYSTIMER DRIVER M: Hao-Wen Ting <[email protected]> S: Maintained
drivers/spi/Kconfig +10 -0
@@ -957,6 +957,16 @@ config SPI_RSPI help SPI driver for Renesas RSPI and QSPI blocks. +config SPI_RTK_NOR + tristate "Realtek SPI-NOR flash controller" + depends on ARCH_REALTEK || COMPILE_TEST + depends on SPI_MEM + help + This enables support for the SPI NOR Flash Controller found on + Realtek DHC SoCs. The controller supports single and dual I/O + transfers and offloads the payload to an integrated DMA engine. + Say Y or M here if you are building a kernel for a Realtek DHC SoC + config SPI_RZV2H_RSPI tristate "Renesas RZ/V2H RSPI controller" depends on ARCH_RENESAS || COMPILE_TEST
drivers/spi/Makefile +1 -0
@@ -131,6 +131,7 @@ obj-$(CONFIG_MACH_REALTEK_RTL) += spi-realtek-rtl.o obj-$(CONFIG_SPI_REALTEK_SNAND) += spi-realtek-rtl-snand.o obj-$(CONFIG_SPI_RPCIF) += spi-rpc-if.o obj-$(CONFIG_SPI_RSPI) += spi-rspi.o +obj-$(CONFIG_SPI_RTK_NOR) += spi-rtk-nor.o obj-$(CONFIG_SPI_RZV2H_RSPI) += spi-rzv2h-rspi.o obj-$(CONFIG_SPI_RZV2M_CSI) += spi-rzv2m-csi.o obj-$(CONFIG_SPI_S3C64XX) += spi-s3c64xx.o
drivers/spi/spi-rtk-nor.c new file +624 -0
624 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v5 2/2] spi: spi-mem: Add Realtek SPI NOR flash controller driver
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] spi: rtk-nor: missing error handling for pm_runtime_resume_and_get() in remove path - [High] spi…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] spi: rtk-nor: missing error handling for pm_runtime_resume_and_get() in remove path
- [High] spi: rtk-nor: rtk_spi_supports_op() returns true for unsupported commands due to bool coercion
- [High] spi: rtk-nor: rtk_spi_do_write_and_cmds() silently truncates multi-byte writes
- [High] spi: rtk-nor: stateful 4-byte mode tracking breaks dirmap memory-mapped accesses
- [High] spi: rtk-nor: missing DUAL_MODE_EN for write operations and exec_op reads causes data corruption --
commit 3bdf61831cde1ea53f0bf3d584243f565bbd2cc7
Author: Jyan Chou <[email protected]>
spi: spi-mem: Add Realtek SPI NOR flash controller driver
Add a spi-mem driver for the SPI NOR Flash Controller (SFC) found on Realtek DHC SoC. The controller supports single and dual I/O transfers and offloads the payload to an integrated DMA engine.
Quoted 3 lines
drivers/spi/spi-rtk-nor.c new file +0
-0
[ ... ]
drivers/spi/spi-rtk-nor.c line 114
Quoted 12 lines
drivers/spi/spi-rtk-nor.c new file +12
-0+static void rtk_spi_read_mode (struct rtk_spi_host *host,const struct spi_mem_op *op) +{ +u32 opcode = op->cmd.opcode; +u32 dummy_cycles, val; + +if (op->data.buswidth ==2 ) + opcode |=DUAL_MODE_EN ; + +writel (opcode, host->regbase +SFC_OPCODE ); + + val =readl (host->regbase +SFC_CTL ); + val |=RW_DATAEN |ADDR_EN ;
[Severity: High]
If a stateless 3-byte command (like Read SFDP) is issued via rtk_spi_exec_op() while the flash is in 4-byte mode, host->is_4byte is set to false and the hardware register is updated.
If a subsequent dirmap read bypasses rtk_spi_exec_op() and calls rtk_spi_read_mode() here, it appears the 4-byte enable register (SFC_ADR_FOUR_BYTE_EN) is not updated from the dirmap template.
Could this cause the controller to send a 3-byte address for a 4-byte dirmap operation, resulting in garbage data reads?
[ ... ]
drivers/spi/spi-rtk-nor.c line 131
Quoted 7 lines
drivers/spi/spi-rtk-nor.c new file +7
-0+static void rtk_spi_write_mode (struct rtk_spi_host *host, +const struct spi_mem_op *op) +{ +u32 opcode = op->cmd.opcode; +u32 val; + +writel (opcode, host->regbase +SFC_OPCODE );
[Severity: High]rtk_spi_supports_op() accepts buswidth == 2 for all data operations, and rtk_spi_read_mode() above properly sets the DUAL_MODE_EN bit for dirmap reads.
Is DUAL_MODE_EN missing here in rtk_spi_write_mode()?
If the SPI NOR core initiates a dual I/O Page Program, will the controller execute it in standard 1-1-1 mode and potentially misconfigure the hardware?
[ ... ]
drivers/spi/spi-rtk-nor.c line 197
Quoted 8 lines
drivers/spi/spi-rtk-nor.c new file +8
-0+static int rtk_spi_command_read (struct rtk_spi_host *host,const struct spi_mem_op *op) +{ +size_t len = op->data.nbytes; +loff_t offset = op->addr.val; +u8 opcode = op->cmd.opcode; +u32 dummy_cycles, val; + +writel (opcode, host->regbase +SFC_OPCODE );
[Severity: High]
Similarly, does this code also miss setting DUAL_MODE_EN for exec_op reads when dual I/O is requested?
[ ... ]
Quoted 13 lines
drivers/spi/spi-rtk-nor.c new file +13
-0+static int rtk_spi_do_write_and_cmds (struct rtk_spi_host *host,const struct spi_mem_op *op) +{ +u8 opcode = op->cmd.opcode; +u32 ctl_val =0 ; + +writel (opcode, host->regbase +SFC_OPCODE ); + +if (op->data.nbytes >0 ) + ctl_val |=RW_DATAEN ; + +if (op->addr.nbytes >0 ) + ctl_val |=ADDR_EN ; +
drivers/spi/spi-rtk-nor.c line 235
Quoted 10 lines
drivers/spi/spi-rtk-nor.c new file +10
-0+writel (ctl_val, host->regbase +SFC_CTL ); + +if (op->data.nbytes >0 ) { +const u8 *buf = op->data.buf.out; + +if (op->addr.val + op->data.nbytes > host->dirmap_size) +return -EINVAL ; + +writeb (*buf, host->iobase + op->addr.val); + }else {
[Severity: High]
When exec_op is used for multi-byte writes (where op->data.nbytes > 1), this executes a single writeb() without a loop and returns success.
Does this silently discard the rest of the payload in op->data.buf.out? If the SPI NOR core falls back to exec_op for multi-byte register writes, it appears only the first byte is written.
[ ... ]
Quoted 3 lines
drivers/spi/spi-rtk-nor.c new file +3
-0+static bool rtk_spi_supports_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{
[ ... ]
drivers/spi/spi-rtk-nor.c line 347
Quoted 8 lines
drivers/spi/spi-rtk-nor.c new file +8
-0+/* +* The data window is access-triggered: each CPU access to host->iobase +* generates one complete SPI transaction. Consecutive byte accesses +* therefore cannot be merged into a single transaction, so +* multi-byte stateless commands are not supported by this controller. +*/ +if (!op->addr.nbytes && op->data.nbytes >1 ) +return -EOPNOTSUPP ;
[Severity: High]
Since rtk_spi_supports_op() returns a bool, won't returning -EOPNOTSUPP evaluate to true?
Does this cause the driver to erroneously advertise support for multi-byte stateless commands instead of rejecting them?
[ ... ]
Quoted 8 lines
drivers/spi/spi-rtk-nor.c new file +8
-0+static void rtk_spi_remove (struct platform_device *pdev) +{ +struct spi_controller *ctrl =platform_get_drvdata (pdev); +struct rtk_spi_host *host =spi_controller_get_devdata (ctrl); +struct device *dev = &pdev->dev; + +spi_unregister_controller (ctrl); +
drivers/spi/spi-rtk-nor.c line 566
Quoted 10 lines
drivers/spi/spi-rtk-nor.c new file +10
-0+if (pm_runtime_resume_and_get (dev) <0 ) +dev_warn (dev,"Failed to resume device during remove\n" ); + +pm_runtime_put_noidle (dev); +pm_runtime_disable (dev); +pm_runtime_set_suspended (dev); +pm_runtime_dont_use_autosuspend (dev); +reset_control_assert (host->rstc); +clk_disable_unprepare (host->clk); +}
[Severity: High]
If pm_runtime_resume_and_get(dev) fails (returns < 0), it does not increment the device's PM usage counter.
Since the execution unconditionally proceeds to call pm_runtime_put_noidle(dev) and clk_disable_unprepare(host->clk), will this result in a PM usage counter underflow (double put) and a clock enable counter underflow?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerRe: [PATCH v5 2/2] spi: spi-mem: Add Realtek SPI NOR flash controller driver
In reply to Yu-Chun LinQuoted 3 lines · Dan Carpenter
Commit
aca8cbecdd2e("spi: spi-mem: Add Realtek SPI NOR flash controller driver") from Sep 30, 2026 (linux-next), leads to the following Smatch static checker warning:
You've not copied me on the rest of the series so I don't know what's going on with dependencies. When sending a patch series it is important to ensure that all the various maintainers understand what the relationship between the patches as the expecation is that there will be interdependencies. Either copy everyone on the whole series or at least copy them on the cover letter and explain what's going on. If there are no strong interdependencies then it's generally simplest to just send the patches separately to avoid any possible confusion.
Re: [PATCH v5 2/2] spi: spi-mem: Add Realtek SPI NOR flash controller driver
Quoted 5 lines · Mark Brown
Quoted 3 lines · Dan Carpenter
Commit
aca8cbecdd2e("spi: spi-mem: Add Realtek SPI NOR flash controller driver") from Sep 30, 2026 (linux-next), leads to the following Smatch static checker warning:
Quoted 8 lines
You've not copied me on the rest of the series so I don't know what's going on with dependencies. When sending a patch series it is important to ensure that all the various maintainers understand what the relationship between the patches as the expecation is that there will be interdependencies. Either copy everyone on the whole series or at least copy them on the cover letter and explain what's going on. If there are no strong interdependencies then it's generally simplest to just send the patches separately to avoid any possible confusion.
Ah, Sorry Mark. I told AI to reformat my bug reports and it screwed it up pretty badly. I'll fix that again.
Plus, when I run b4 on this, then lore doesn't have my email. Also sashiko-bot already complained about the bug that Smatch flagged.
regards,
dan carpenter
Mark Brown
maintainerQuoted 8 lines · Yu-Chun Lin
spi: realtek: Add support for RTD1625 SPI NOR Flash Controller
Hi all,
This patch series introduces support for the Realtek RTD1625 SPI NOR Flash controller.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4
Thanks!
[1/2] dt-bindings: spi: Add Realtek RTD1625 SPI NOR support
https://git.kernel.org/broonie/spi/c/cf0f217a52d0
[2/2] spi: spi-mem: Add Realtek SPI NOR flash controller driver
https://git.kernel.org/broonie/spi/c/aca8cbecdd2e
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark