Skip to contentSkip to conversation

dt-bindings: spi: Realtek RTL838x/RTL839x SPI controller

PATCH RESEND Superseded Bert Vermeulen 3 participants 6 messages Dec 29, 2020 – Jan 1, 2021

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/2 dt-bindings: spi: Realtek RTL838x/RTL839x SPI controller

---
(resent due to mail trouble)

 .../devicetree/bindings/spi/realtek,spi.yaml  | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/realtek,spi.yaml
Documentation/devicetree/bindings/spi/realtek,spi.yaml new file +36 -0
new file mode 100644
index 000000000000..9831df6dc40d
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/spi/realtek,spi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek RTL838x/RTL839x SPI controller
+
+maintainers:
+  - Bert Vermeulen <[email protected]>
+  - Birger Koblitz <[email protected]>
+
+allOf:
+  - $ref: "spi-controller.yaml#"
+
+properties:
+  compatible:
+    const: realtek,spi
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    spi: spi@1200 {
+        compatible = "realtek,spi";
+        reg = <0x1200 0x100>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+    };
Signature · 1 line
2.25.1
#1 lore raw

PATCH RESEND v2 2/2 Add support for Realtek RTL838x/RTL839x SoC SPI controllers

This driver likely also supports earlier (RTL8196) and later (RTL93xx) SoCs.

The SPI hardware in these SoCs is specifically intended for connecting NOR bootflash chips, and only used for that in dozens of examined devices. However boiled down to basics, it's really just a half-duplex SPI controller.

The hardware appears to have a vestigial second chip-select control, but it hasn't been seen in the wild and is thus not supported.

---
(resent due to mail trouble)
Notes:
v2: rewrote from spi-nor driver to regular spi driver, implementing only
set_cs() and transfer_one() (Thanks Chuanhong Guo!)

 MAINTAINERS               |   6 ++
 drivers/spi/Kconfig       |   7 ++
 drivers/spi/Makefile      |   1 +
 drivers/spi/spi-realtek.c | 215 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+)
 create mode 100644 drivers/spi/spi-realtek.c
MAINTAINERS +6 -0
index ad0e34bf8453..311e5413b1dd 100644
@@ -15048,6 +15048,12 @@ F:	Documentation/devicetree/bindings/net/dsa/realtek-smi.txt
 F:	drivers/net/dsa/realtek-smi*
 F:	drivers/net/dsa/rtl83*
 
+REALTEK RTL83XX SPI DRIVER
+M:	Bert Vermeulen <[email protected]>
+M:	Birger Koblitz <[email protected]>
+S:	Maintained
+F:	drivers/spi/spi-realtek.c
+
 REALTEK WIRELESS DRIVER (rtlwifi family)
 M:	Ping-Ke Shih <[email protected]>
 L:	[email protected]
drivers/spi/Kconfig +7 -0
index aadaea052f51..058ed1b19bc6 100644
@@ -646,6 +646,13 @@ config SPI_RB4XX
 	help
 	  SPI controller driver for the Mikrotik RB4xx series boards.
 
+config SPI_REALTEK
+	bool "Realtek SPI controller"
+	depends on MACH_REALTEK
+	help
+	  This driver supports the SPI controller used for the bootflash
+	  in the Realtek RTL83xx series SoCs.
+
 config SPI_RPCIF
 	tristate "Renesas RPC-IF SPI driver"
 	depends on RENESAS_RPCIF
drivers/spi/Makefile +1 -0
index 6fea5821662e..6e9612b70555 100644
@@ -94,6 +94,7 @@ obj-$(CONFIG_SPI_QCOM_QSPI)		+= spi-qcom-qspi.o
 obj-$(CONFIG_SPI_QUP)			+= spi-qup.o
 obj-$(CONFIG_SPI_ROCKCHIP)		+= spi-rockchip.o
 obj-$(CONFIG_SPI_RB4XX)			+= spi-rb4xx.o
+obj-$(CONFIG_SPI_REALTEK)		+= spi-realtek.o
 obj-$(CONFIG_SPI_RPCIF)			+= spi-rpc-if.o
 obj-$(CONFIG_SPI_RSPI)			+= spi-rspi.o
 obj-$(CONFIG_SPI_S3C24XX)		+= spi-s3c24xx-hw.o
drivers/spi/spi-realtek.c new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH RESEND v2 2/2] Add support for Realtek RTL838x/RTL839x SoC SPI controllers

drivers/spi/spi-realtek.c line 64

Quoted 5 lines · Bert Vermeulen
drivers/spi/spi-realtek.c new file +5 -0
+static inline void wait_ready(struct rtspi *rtspi)
+{
+	while (!(readl(REG(RTL8380_SPI_SFCSR)) & RTL8380_SPI_SFCSR_RDY))
+		;
+}

I'd suggest calling cpu_relax() in the loop's body.

drivers/spi/spi-realtek.c line 177

Quoted 1 line
drivers/spi/spi-realtek.c new file +1 -0
+	err = devm_spi_register_controller(&pdev->dev, ctrl);

Since you're invoking devm_spi_register_controller() on probe, the controller must not be unregistered explicitly on remove. So the ->remove hook can be dropped altogether:

Quoted 8 lines
drivers/spi/spi-realtek.c new file +8 -0
+static int realtek_spi_remove(struct platform_device *pdev)
+{
+	struct spi_controller *ctrl = platform_get_drvdata(pdev);
+
+	spi_unregister_controller(ctrl);
+
+	return 0;
+}

[...]

drivers/spi/spi-realtek.c line 204

Quoted 1 line
drivers/spi/spi-realtek.c new file +1 -0
+	.remove = realtek_spi_remove,

The ->probe hook otherwise LGTM.

Thanks,

Lukas

#3 lore raw

Re: [PATCH RESEND v2 2/2] Add support for Realtek RTL838x/RTL839x SoC SPI controllers

Quoted 25 lines · Lukas Wunner

drivers/spi/spi-realtek.c line 64

Quoted 5 lines · Bert Vermeulen
drivers/spi/spi-realtek.c new file +5 -0
+static inline void wait_ready(struct rtspi *rtspi)
+{
+	while (!(readl(REG(RTL8380_SPI_SFCSR)) & RTL8380_SPI_SFCSR_RDY))
+		;
+}

I'd suggest calling cpu_relax() in the loop's body.

drivers/spi/spi-realtek.c line 177

Quoted 1 line
drivers/spi/spi-realtek.c new file +1 -0
+	err = devm_spi_register_controller(&pdev->dev, ctrl);

Since you're invoking devm_spi_register_controller() on probe, the controller must not be unregistered explicitly on remove. So the ->remove hook can be dropped altogether:

Quoted 8 lines
drivers/spi/spi-realtek.c new file +8 -0
+static int realtek_spi_remove(struct platform_device *pdev)
+{
+	struct spi_controller *ctrl = platform_get_drvdata(pdev);
+
+	spi_unregister_controller(ctrl);
+
+	return 0;
+}

[...]

Quoted 3 lines

drivers/spi/spi-realtek.c line 204

Quoted 1 line
drivers/spi/spi-realtek.c new file +1 -0
+	.remove = realtek_spi_remove,

The ->probe hook otherwise LGTM.

Thanks Lukas, will fix those issues.

Signature · 2 lines
Bert Vermeulen
[email protected]
maintainer
#4 lore raw
In reply to Bert Vermeulen

Documentation/devicetree/bindings/spi/realtek,spi.yaml line 18

Quoted 3 lines · Bert Vermeulen
Documentation/devicetree/bindings/spi/realtek,spi.yaml new file +3 -0
+properties:
+  compatible:
+    const: realtek,spi

It is possibled Realtek might make other SPI controllers, there should be some more specific name such as a compatible for each SoC that the controller appears in or an IP name if one is known.

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

#5 lore raw
Quoted 9 lines · Mark Brown

Documentation/devicetree/bindings/spi/realtek,spi.yaml line 18

Quoted 3 lines · Bert Vermeulen
Documentation/devicetree/bindings/spi/realtek,spi.yaml new file +3 -0
+properties:
+  compatible:
+    const: realtek,spi

It is possibled Realtek might make other SPI controllers, there should be some more specific name such as a compatible for each SoC that the controller appears in or an IP name if one is known.

Mark,

Good call. We're changing all the Realtek RTL838x/RTL839x stuff to some variation of "realtek-rtl", in this case "realtek,rtl-spi". The "rtl" prefix to Realtek SoCs fits the bill. Will resubmit.

Signature · 2 lines
Bert Vermeulen
[email protected]