riscv: sophgo: dts: Add spi controller for SG2042
Subsystems (3)
PATCH v2 1/1 riscv: sophgo: dts: Add spi controller for SG2042
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
---
For this spi controller patch, only bindings are included.
This is tested on milkv-pioneer board. Using driver/spi/spidev.c
for creating /dev/spidevX.Y and tools/spi/spidev_test for testing functionality.
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated properties clock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)
arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8 -0
@@ -72,6 +72,14 @@ &uart0 { status = "okay"; }; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; + / { thermal-zones { soc-thermal {
arch/riscv/boot/dts/sophgo/sg2042.dtsi +28 -0
@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40004000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>; + interrupt-parent = <&intc>; + interrupts = <110 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + resets = <&rstgen RST_SPI0>; + status = "disabled"; + }; + + spi1: spi@7040005000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40005000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>; + interrupt-parent = <&intc>; + interrupts = <111 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + resets = <&rstgen RST_SPI1>; + status = "disabled"; + }; }; };
---
base-commit: aa5ee7180ec41bb77c3e327e95d119f2294babea
change-id: 20250228-sfg-spi-e3f2aeca09ab
Best regards,
Signature · 1 line
Zixian Zeng <[email protected]>
Quoted 7 lines · Zixian Zeng
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
Signed-off-by Zixian Zeng <[email protected]>---
For this spi controller patch, only bindings are included.
^^^ you've not actually included any bindings in this patch, copy-paste mistake?
Quoted 39 lines
This is tested on milkv-pioneer board. Using
driver/spi/spidev.c
for creating/dev/spidevX.Yandtools/spi/spidev_testfor testing functionality.
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated propertiesclock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8
-0@@ -72,6 +72,14 @@ &uart0 { status = "okay"; }; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; + / { thermal-zones { soc-thermal {arch/riscv/boot/dts/sophgo/sg2042.dtsi +0
-0
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 550
Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi";
I thought were were dropping the use of "snps,dw-abp-ssi" in isolation, and starting to require soc-specific compatibles now.
Rob, Krzysztof?
On 2025/3/1 2:22, Conor Dooley wrote:
[......]
Quoted 7 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 550
Quoted 3 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0+ + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi";I thought were were dropping the use of "snps,dw-abp-ssi" in isolation, and starting to require soc-specific compatibles now.
Rob, Krzysztof?
I'm also very interested to know why we can't just use "snps,dw-abp-ssi", maybe I missed some discussion ...
I googled examples of soc-specific defined in the code, and it doesn't seem to be much, only arch/mips/boot/dts/mscc/ocelot.dtsi and arch/riscv/boot/dts/thead/th1520.dtsi.
Specially, I looked at the commits for th1520 and saw this https://lore.kernel.org/linux-riscv/20240703-garbage-explicit-bd95f8deb716@wendy/. It tells if the fallback works identically, then the specific compatible is not needed.
This makes me more confused :)
Regards,
Chen
Quoted 9 lines · Chen Wang
On 2025/3/1 2:22, Conor Dooley wrote:
[......]Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 550
Quoted 3 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0+ + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi";I thought were were dropping the use of "snps,dw-abp-ssi" in isolation, and starting to require soc-specific compatibles now.
Quoted 3 lines
Quoted 1 line
Rob, Krzysztof?
I'm also very interested to know why we can't just use "snps,dw-abp-ssi", maybe I missed some discussion ...
Ordinarily you're not allowed to use generic compatibles at all, the dw stuff has kinda been an ?unofficial? exception for a while and not just for spi. I think that "exception" has been withdrawn though, and dw stuff is being brought in line with everything else, but cannot remember where that started.
Quoted 7 lines
I googled examples of soc-specific defined in the code, and it doesn't seem to be much, only
arch/mips/boot/dts/mscc/ocelot.dtsiandarch/riscv/boot/dts/thead/th1520.dtsi.Specially, I looked at the commits for th1520 and saw this https://lore.kernel.org/linux-riscv/20240703-garbage-explicit-bd95f8deb716@wendy/.
It tells if the fallback works identically, then the specific compatible is
not needed.
This link is talking about the driver, not the dts/binding. Adding the device-specific compatible to the driver is only needed if the specific one has some extra features above and beyond the compatible used as the fallback.
Cheers,
Conor.
Quoted 12 lines · Conor Dooley
Quoted 7 lines · Zixian Zeng
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
Signed-off-by Zixian Zeng <[email protected]>---
For this spi controller patch, only bindings are included.^^^ you've not actually included any bindings in this patch, copy-paste mistake?
My bad, I was confused about what’s the “binding” meaning. I will remove this description in next revision.
Quoted 40 lines
Quoted 40 lines
This is tested on milkv-pioneer board. Using
driver/spi/spidev.c
for creating/dev/spidevX.Yandtools/spi/spidev_testfor testing functionality.
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated propertiesclock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8
-0@@ -72,6 +72,14 @@ &uart0 { status = "okay"; }; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; + / { thermal-zones { soc-thermal {arch/riscv/boot/dts/sophgo/sg2042.dtsi +0
-0@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer";
Quoted 9 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 550
Quoted 5 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi";I thought were were dropping the use of "snps,dw-abp-ssi" in isolation, and starting to require soc-specific compatibles now.
That’s better, I will do it in next revision.
BTW, <https://lore.kernel.org/linux-riscv/20240703-garbage-explicit-bd95f8deb716@wendy>
has similar situation,
those patches only create binding but not implement the compatible property of "thead,th1520-spi” in driver.
When kernel matching, it will find out there’s no compatible of "thead,th1520-spi” so fallback to "snps,dw-apb-ssi”
May I take you a few minutes for reason behind it? My understanding is that using soc-specific compatible is better
for future maintaining, If the device actually comes with some unknown quirks not present in the generic IP.
And all we need to do for fixing is implementing the soc-specific compatible property.
Quoted 2 lines
Rob, Krzysztof?
Best regards,
Zixian Zeng
Quoted 26 lines · damon
Quoted 17 lines · Conor Dooley
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 550
Quoted 11 lines · Zixian Zeng
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi";I thought were were dropping the use of "snps,dw-abp-ssi" in isolation, and starting to require soc-specific compatibles now.
That’s better, I will do it in next revision.
BTW, <https://lore.kernel.org/linux-riscv/20240703-garbage-explicit-bd95f8deb716@wendy>
has similar situation,
those patches only create binding but not implement the compatible property of "thead,th1520-spi” in driver.
When kernel matching, it will find out there’s no compatible of "thead,th1520-spi” so fallback to "snps,dw-apb-ssi”
Quoted 4 lines
May I take you a few minutes for reason behind it? My understanding is that using soc-specific compatible is better
for future maintaining, If the device actually comes with some unknown quirks not present in the generic IP.
Yup, that's pretty much it. Those quirks could be some sort of bug etc, or they could be an extra feature. Sometimes the specific compatible is only used to enforce constraints on what properties are allowed, but that's more of a thing for the more configurable IPs like the dwmac.
Quoted 2 lines
And all we need to do for fixing is implementing the soc-specific compatible property.
Correct. You just need to add a specific compatible to the binding and to the dts, the driver will work just fine with the "fallback" dw one.
Inochi Amaoto
maintainerQuoted 10 lines · Zixian Zeng
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
Signed-off-by Zixian Zeng <[email protected]>---
For this spi controller patch, only bindings are included. This is tested on milkv-pioneer board. Usingdriver/spi/spidev.cfor creating/dev/spidevX.Yandtools/spi/spidev_testfor testing functionality.
I wonder whether this patch is tested (or at least can be tested), as I am not sure there are pins for spi or any onboard device on existing SG2042 board.
Quoted 36 lines
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated propertiesclock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8
-0@@ -72,6 +72,14 @@ &uart0 { status = "okay"; }; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; + / { thermal-zones { soc-thermal {arch/riscv/boot/dts/sophgo/sg2042.dtsi +0
-0
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 554
Quoted 10 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +6
-0@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40004000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>;
Is the sysdma axi clock for the this device. IIRC is APB interface.
Also, Are these clock aligned? If not, use space to align the two clocks. You also need to add the clock-names here.
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 558
Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +5
-0+ interrupt-parent = <&intc>; + interrupts = <110 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>;
Just use decimal number, no hex there.
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 567
Quoted 10 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +9
-0+ resets = <&rstgen RST_SPI0>; + status = "disabled"; + }; + + spi1: spi@7040005000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40005000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>;
The same as above.
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 572
Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +5
-0+ interrupt-parent = <&intc>; + interrupts = <111 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>;
The same as above.
Quoted 14 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-1+ resets = <&rstgen RST_SPI1>; + status = "disabled"; + }; }; }; ---base-commit:
aa5ee7180ec41bb77c3e327e95d119f2294babea
change-id: 20250228-sfg-spi-e3f2aeca09abBest regards,
Signature · 1 line
Zixian Zeng <[email protected]>
Quoted 12 lines · Inochi Amaoto
Quoted 10 lines · Zixian Zeng
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
Signed-off-by Zixian Zeng <[email protected]>---
For this spi controller patch, only bindings are included. This is tested on milkv-pioneer board. Usingdriver/spi/spidev.cfor creating/dev/spidevX.Yandtools/spi/spidev_testfor testing functionality.
Quoted 4 lines
I wonder whether this patch is tested (or at least can be tested), as I am not sure there are pins for spi or any onboard device on existing SG2042 board.
Yes, this is tested on milkv-pioneer board.
Since this patch is just for supporting SPI controller in BUS level which not relates to the real hardware such as screen, I used driver/spi/spidev.c for creating virtual device /dev/spidevX.Y by adding nodes in DTS file as following:
spidev@0 {
compatible = "snps,dw-apb-ssi";
reg = <0>;
status = "okay";
};spidev@1 {
compatible = "snps,dw-apb-ssi";
reg = <1>;
status = "okay";
};And using tools/spi/spidev_{test,fdx} provided by kernel tree for testing bus functionality.
Quoted 44 lines
Quoted 43 lines
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated propertiesclock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8
-0@@ -72,6 +72,14 @@ &uart0 { status = "okay"; }; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; + / { thermal-zones { soc-thermal {arch/riscv/boot/dts/sophgo/sg2042.dtsi +4
-0@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40004000 0x00 0x1000>;
Quoted 5 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 553
Quoted 2 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +2
-0+ clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>;Is the sysdma axi clock for the this device. IIRC is APB interface.
Thanks, I will remove the GATE_CLK_SYSDMA_AXI in next revision.
Quoted 2 lines
Also, Are these clock aligned? If not, use space to align the two clocks. You also need to add the clock-names here.
In the case of the only clock, I think it’s probably no need to add the clock-names property here.
Quoted 10 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 558
Quoted 7 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +5
-0+ interrupt-parent = <&intc>; + interrupts = <110 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>;Just use decimal number, no hex there.
Thanks, I will fix it in next revision.
Quoted 8 lines
Quoted 7 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +7
-0+ resets = <&rstgen RST_SPI0>; + status = "disabled"; + }; + + spi1: spi@7040005000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40005000 0x00 0x1000>;
Quoted 5 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 568
Quoted 2 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +2
-0+ clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>;The same as above.
Thanks.
Quoted 9 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi sd: mmc@704002b000 { · line 572
Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +5
-0+ interrupt-parent = <&intc>; + interrupts = <111 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>;The same as above.
Thanks.
Quoted 6 lines
Quoted 6 lines
arch/riscv/boot/dts/sophgo/sg2042.dtsi +3
-0+ resets = <&rstgen RST_SPI1>; + status = "disabled"; + };};};
Quoted 8 lines
Quoted 8 lines
---
base-commit:aa5ee7180ec41bb77c3e327e95d119f2294babea
change-id: 20250228-sfg-spi-e3f2aeca09abBest regards,
--
Zixian Zeng <[email protected]>
Best regards,
Zixian Zeng <[email protected]>
Quoted 28 lines · Zixian Zeng
Add spi controllers for SG2042.
SG2042 uses the upstreamed Synopsys DW SPI IP.
Signed-off-by Zixian Zeng <[email protected]>---
For this spi controller patch, only bindings are included.
This is tested on milkv-pioneer board. Usingdriver/spi/spidev.c
for creating/dev/spidevX.Yandtools/spi/spidev_testfor testing functionality.
---
Changes in v2:
- rebase v1 to sophgo/master(github.com/sophgo/linux.git).
- order properties in device node.
- remove unevaluated propertiesclock-frequency.
- set default status to disable.
- Link to v1: https://lore.kernel.org/r/[email protected]--- .../riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts | 8 +++++++ arch/riscv/boot/dts/sophgo/sg2042.dtsi | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+)arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +0
-0@@ -72,6 +72,14 @@ &uart0 { status = "okay";
arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts &uart0 { · line 82
Quoted 10 lines
arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +8
-0}; +&spi0 { + status = "okay"; +}; + +&spi1 { + status = "okay"; +}; +
Pioneerbox doesn't use these SPI controllers, so just drop this change and keep the change for sg2042.dtsi should be fine.
Thanks,
Chen
Quoted 47 lines
arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +0
-0/ { thermal-zones { soc-thermal {arch/riscv/boot/dts/sophgo/sg2042.dtsi +28
-1@@ -545,5 +545,33 @@ sd: mmc@704002b000 { "timer"; status = "disabled"; }; + + spi0: spi@7040004000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40004000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>; + interrupt-parent = <&intc>; + interrupts = <110 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + resets = <&rstgen RST_SPI0>; + status = "disabled"; + }; + + spi1: spi@7040005000 { + compatible = "snps,dw-apb-ssi"; + reg = <0x70 0x40005000 0x00 0x1000>; + clocks = <&clkgen GATE_CLK_APB_SPI>, + <&clkgen GATE_CLK_SYSDMA_AXI>; + interrupt-parent = <&intc>; + interrupts = <111 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <0x01>; + #size-cells = <0x00>; + num-cs = <0x02>; + resets = <&rstgen RST_SPI1>; + status = "disabled"; + }; }; }; ---base-commit:
aa5ee7180ec41bb77c3e327e95d119f2294babea
change-id: 20250228-sfg-spi-e3f2aeca09abBest regards,