ARM: Initial Sunplus Plus1 SP7021 and BPI-F2S support
Subsystems (7)
cover ARM: Initial Sunplus Plus1 SP7021 and BPI-F2S support
Hello,
This patch series adds initial drivers and Device Trees for Sunplus Plus1 series (codename Pentagram) SP7021 SoC and Banana Pi BPI-F2S SBC.
First, minimal Kconfig, DT and earlycon driver are prepared to get serial output at all. Next, interrupt controller and full serial driver are added that allow to boot into an initrd with interactive serial console.
Device Tree files added are for the CPU-Chip (aka A-Chip) with quad Cortex-A7, but the file split prepares for also adding the Peripheral-Chip (B-Chip) with ARM9 later. However, for now this is not reflected in the .dts filename; this corresponds to the vf610- vs. vf610m4- naming scheme, whereas an alternative would be to use sp7021-cchip- vs. -pchip- prefix (as sp7021-cpu- looks weird). It is assumed we can reuse the same SoC and board bindings for CA7 and ARM9 and only differ for IP blocks where needed.
My inquiry to Sunplus about their GIC (anticipating complaints from Marc) remained unanswered, so I've added the two extra regions and irq myself, without being able to test KVM due to BSP U-Boot not booting in HYP mode. According to Sunplus the mode can be changed in U-Boot (but where/how?).
Similarly, the architectural timer is not properly initialized in BSP U-Boot, so that I currently have a mach- hack in my tree below. Unlike RTD1195, we do have U-Boot sources (v2019.04 based), so should be able to fix this in the bootloader rather than in the kernel, thus not included as patch here.
Based on SoC online manual [1] and downstream BPI-F2S BSP tree [2] as well as my previous Actions serial and Realtek irqchip drivers and DTs.
More details at:
https://en.opensuse.org/HCL:BananaPi_F2S
Latest experimental patches at:
https://github.com/afaerber/linux/commits/f2s-next
Have a lot of fun!
Cheers,
Andreas
[1] https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/470450252/SP7021+Technical+Manual
[2] https://github.com/BPI-SINOVOIP/BPI-F2S-bsp
Andreas Färber (11):
dt-bindings: vendor-prefixes: Add Sunplus
dt-bindings: arm: Add Sunplus SP7021 and Banana Pi BPI-F2S
ARM: Prepare Sunplus Plus1 SoC family
dt-bindings: interrupt-controller: Add Sunplus SP7021 mux
dt-bindings: serial: Add Sunplus SP7021 UART
tty: serial: Add Sunplus Plus1 UART earlycon
ARM: dts: Add Sunplus Plus1 SP7021 and Banana Pi F2S
tty: serial: sunplus: Implement full UART driver
irqchip: Add Sunplus SP7021 interrupt (mux) controller
ARM: dts: sp7021-cpu: Add interrupt controller node
ARM: dts: sp7021-cpu: Add dummy UART0 clock and interrupt
Documentation/devicetree/bindings/arm/sunplus.yaml | 22 + .../sunplus,pentagram-intc.yaml | 50 ++ .../bindings/serial/sunplus,pentagram-uart.yaml | 24 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + arch/arm/Kconfig | 2 + arch/arm/Makefile | 1 + arch/arm/boot/dts/Makefile | 2 + arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts | 29 + arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi | 93 +++ arch/arm/boot/dts/pentagram-sp7021.dtsi | 61 ++ arch/arm/mach-sunplus/Kconfig | 10 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sp7021.c | 285 ++++++++ drivers/tty/serial/Kconfig | 19 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/sunplus-uart.c | 770 +++++++++++++++++++++ include/uapi/linux/serial_core.h | 3 + 17 files changed, 1375 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/sunplus.yaml create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml create mode 100644 Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml create mode 100644 arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts create mode 100644 arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi create mode 100644 arch/arm/boot/dts/pentagram-sp7021.dtsi create mode 100644 arch/arm/mach-sunplus/Kconfig create mode 100644 drivers/irqchip/irq-sp7021.c create mode 100644 drivers/tty/serial/sunplus-uart.c
Signature · 1 line
2.16.4
RFC 1/11 dt-bindings: vendor-prefixes: Add Sunplus
Sunplus Technology Co., Ltd. is a Taiwanese IC vendor. Assign vendor prefix "sunplus".
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -955,6 +955,8 @@ patternProperties: description: Summit microelectronics "^sunchip,.*": description: Shenzhen Sunchip Technology Co., Ltd + "^sunplus,.*": + description: Sunplus Technology Co., Ltd. "^SUNW,.*": description: Sun Microsystems, Inc "^swir,.*":
Signature · 1 line
2.16.4
RFC 2/11 dt-bindings: arm: Add Sunplus SP7021 and Banana Pi BPI-F2S
In reply to Andreas Färber--- Documentation/devicetree/bindings/arm/sunplus.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/sunplus.yaml
Documentation/devicetree/bindings/arm/sunplus.yaml new file +22 -0
@@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/sunplus.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus platforms device tree bindings + +maintainers: + - Andreas Färber <[email protected]> + +properties: + $nodename: + const: '/' + compatible: + oneOf: + # SP7021 SoC based boards + - items: + - enum: + - bananapi,bpi-f2s # Banana Pi BPI-F2S + - const: sunplus,sp7021 +...
Signature · 1 line
2.16.4
RFC 3/11 ARM: Prepare Sunplus Plus1 SoC family
In reply to Andreas Färber--- arch/arm/Kconfig | 2 ++ arch/arm/Makefile | 1 + arch/arm/mach-sunplus/Kconfig | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 arch/arm/mach-sunplus/Kconfig
arch/arm/Kconfig +2 -0
@@ -722,6 +722,8 @@ source "arch/arm/mach-sti/Kconfig" source "arch/arm/mach-stm32/Kconfig" +source "arch/arm/mach-sunplus/Kconfig" + source "arch/arm/mach-sunxi/Kconfig" source "arch/arm/mach-tango/Kconfig"
arch/arm/Makefile +1 -0
@@ -158,6 +158,7 @@ textofs-$(CONFIG_ARCH_MSM8X60) := 0x00208000 textofs-$(CONFIG_ARCH_MSM8960) := 0x00208000 textofs-$(CONFIG_ARCH_MESON) := 0x00208000 textofs-$(CONFIG_ARCH_AXXIA) := 0x00308000 +textofs-$(CONFIG_ARCH_SUNPLUS) := 0x00308000 # Machine directory name. This list is sorted alphanumerically # by CONFIG_* macro name.
arch/arm/mach-sunplus/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +menuconfig ARCH_SUNPLUS + bool "Sunplus SoCs" + depends on ARCH_MULTI_V7 + select ARM_GIC + select ARM_GLOBAL_TIMER + select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK + select GENERIC_IRQ_CHIP + help + This enables support for the Sunplus Plus1 (SP7021) SoC family.
Signature · 1 line
2.16.4
RFC 4/11 dt-bindings: interrupt-controller: Add Sunplus SP7021 mux
In reply to Andreas FärberThe Sunplus SP7021 SoC has an interrupt mux.
--- .../sunplus,pentagram-intc.yaml | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/sunplus,pentagram-intc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus Pentagram SoC Interrupt Controller + +maintainers: + - Andreas Färber <[email protected]> + +allOf: + - $ref: /schemas/interrupt-controller.yaml# + +properties: + compatible: + const: sunplus,sp7021-intc + + reg: + maxItems: 2 + + interrupts: + maxItems: 2 + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + +required: + - compatible + - reg + - interrupt-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + interrupt-controller@9c000780 { + compatible = "sunplus,sp7021-intc"; + reg = <0x9c000780 0x80>, + <0x9c000a80 0x80>; + interrupts = <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + #interrupt-cells = <2>; + }; +...
Signature · 1 line
2.16.4
Rob Herring
maintainerRe: [RFC 04/11] dt-bindings: interrupt-controller: Add Sunplus SP7021 mux
Quoted 18 lines · Andreas Färber
The Sunplus SP7021 SoC has an interrupt mux.
Cc Wells Lu 呂芳騰 <[email protected]>Signed-off-by Andreas Färber <[email protected]>--- .../sunplus,pentagram-intc.yaml | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yamlDocumentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +3
-0@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause +%YAML 1.2 +---
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +10
-0+$id: http://devicetree.org/schemas/interrupt-controller/sunplus,pentagram-intc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus Pentagram SoC Interrupt Controller + +maintainers: + - Andreas Färber <[email protected]> + +allOf: + - $ref: /schemas/interrupt-controller.yaml#
No need for this. It's applied based on the node name.
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml line 20
Quoted 7 lines
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +7
-0+ +properties: + compatible: + const: sunplus,sp7021-intc + + reg: + maxItems: 2
Need to define what each one is.
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml line 23
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +3
-0+ + interrupts: + maxItems: 2
Same here.
Quoted 30 lines
Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml new file +27
-0+ + interrupt-controller: true + + "#interrupt-cells": + const: 2 + +required: + - compatible + - reg + - interrupt-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + interrupt-controller@9c000780 { + compatible = "sunplus,sp7021-intc"; + reg = <0x9c000780 0x80>, + <0x9c000a80 0x80>; + interrupts = <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + #interrupt-cells = <2>; + }; +...Signature · 1 line
2.16.4
RFC 5/11 dt-bindings: serial: Add Sunplus SP7021 UART
In reply to Andreas FärberThe Sunplus Plus1 (aka Pentagram) SP7021 SoC has five UARTs.
--- .../bindings/serial/sunplus,pentagram-uart.yaml | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml
Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml new file +24 -0
@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/serial/sunplus,pentagram-uart.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus Pentagram SoC UART Serial Interface + +maintainers: + - Andreas Färber <[email protected]> + +properties: + compatible: + const: sunplus,sp7021-uart + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 +...
Signature · 1 line
2.16.4
Rob Herring
maintainerRe: [RFC 05/11] dt-bindings: serial: Add Sunplus SP7021 UART
Quoted 16 lines · Andreas Färber
The Sunplus Plus1 (aka Pentagram) SP7021 SoC has five UARTs.
Cc Wells Lu 呂芳騰 <[email protected]>Signed-off-by Andreas Färber <[email protected]>--- .../bindings/serial/sunplus,pentagram-uart.yaml | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yamlDocumentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml new file +1
-0@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause
Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/serial/sunplus,pentagram-uart.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus Pentagram SoC UART Serial Interface + +maintainers: + - Andreas Färber <[email protected]> +
Soon this will need to reference serial.yaml which is getting added to 5.7.
Quoted 16 lines
Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml new file +13
-0+properties: + compatible: + const: sunplus,sp7021-uart + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 +...Signature · 1 line
2.16.4
RFC 6/11 tty: serial: Add Sunplus Plus1 UART earlycon
In reply to Andreas FärberPrepare an earlycon driver for Sunplus Plus1 SP7021 SoC.
Based on BPI-F2S-bsp tree.
--- drivers/tty/serial/Kconfig | 19 +++++++++ drivers/tty/serial/Makefile | 1 + drivers/tty/serial/sunplus-uart.c | 90 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 drivers/tty/serial/sunplus-uart.c
drivers/tty/serial/Kconfig +19 -0
@@ -1562,6 +1562,25 @@ config SERIAL_MILBEAUT_USIO_CONSOLE receives all kernel messages and warnings and which allows logins in single user mode). +config SERIAL_PLUS1 + bool "Sunplus Plus1 serial port support" + depends on ARCH_SUNPLUS || COMPILE_TEST + select SERIAL_CORE + help + This driver is for Sunplus Plus1 SP7021 SoC's UART. + Say 'Y' here if you wish to use the on-board serial port. + Otherwise, say 'N'. + +config SERIAL_PLUS1_CONSOLE + bool "Console on Sunplus Plus1 serial port" + depends on SERIAL_PLUS1=y + select SERIAL_CORE_CONSOLE + select SERIAL_EARLYCON + default y + help + Say 'Y' here if you wish to use Sunplus SP7021 UART + as the system console. Only earlycon is implemented currently. + endmenu config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
@@ -89,6 +89,7 @@ obj-$(CONFIG_SERIAL_OWL) += owl-uart.o obj-$(CONFIG_SERIAL_RDA) += rda-uart.o obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o obj-$(CONFIG_SERIAL_SIFIVE) += sifive.o +obj-$(CONFIG_SERIAL_PLUS1) += sunplus-uart.o # GPIOLIB helpers for modem control lines obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
drivers/tty/serial/sunplus-uart.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.16.4
RFC 7/11 ARM: dts: Add Sunplus Plus1 SP7021 and Banana Pi F2S
In reply to Andreas FärberPrepare Device Trees for Sunplus Plus1 (aka Pentagram) SP7021's CPU-Chip aka A-Chip (Cortex-A7) as well as the Banana Pi BPI-F2S SBC.
--- arch/arm/boot/dts/Makefile | 2 + arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts | 22 ++++++++ arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi | 75 ++++++++++++++++++++++++++ arch/arm/boot/dts/pentagram-sp7021.dtsi | 61 +++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts create mode 100644 arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi create mode 100644 arch/arm/boot/dts/pentagram-sp7021.dtsi
arch/arm/boot/dts/Makefile +2 -0
@@ -846,6 +846,8 @@ dtb-$(CONFIG_ARCH_ACTIONS) += \ owl-s500-cubieboard6.dtb \ owl-s500-guitar-bb-rev-b.dtb \ owl-s500-sparky.dtb +dtb-$(CONFIG_ARCH_SUNPLUS) += \ + pentagram-sp7021-bpi-f2s.dtb dtb-$(CONFIG_ARCH_PRIMA2) += \ prima2-evb.dtb dtb-$(CONFIG_ARCH_PXA) += \
arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause + +/dts-v1/; + +#include "pentagram-sp7021-cpu.dtsi" + +/ { + compatible = "bananapi,bpi-f2s", "sunplus,sp7021"; + model = "Banana Pi BPI-F2S"; + + aliases { + serial0 = &uart0; + }; + + chosen { + stdout-path = "serial0:115200n8"; + }; +}; + +&uart0 { + status = "okay"; +};
arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi new file +75 -0
75 lines not on this page · raw message
arch/arm/boot/dts/pentagram-sp7021.dtsi new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.16.4
RFC 8/11 tty: serial: sunplus: Implement full UART driver
In reply to Andreas Färber--- drivers/tty/serial/Kconfig | 4 +- drivers/tty/serial/sunplus-uart.c | 680 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/serial_core.h | 3 + 3 files changed, 685 insertions(+), 2 deletions(-)
drivers/tty/serial/Kconfig +2 -2
@@ -1563,7 +1563,7 @@ config SERIAL_MILBEAUT_USIO_CONSOLE single user mode). config SERIAL_PLUS1 - bool "Sunplus Plus1 serial port support" + tristate "Sunplus Plus1 serial port support" depends on ARCH_SUNPLUS || COMPILE_TEST select SERIAL_CORE help
@@ -1579,7 +1579,7 @@ config SERIAL_PLUS1_CONSOLE default y help Say 'Y' here if you wish to use Sunplus SP7021 UART - as the system console. Only earlycon is implemented currently. + as the system console. endmenu
drivers/tty/serial/sunplus-uart.c +680 -0
713 lines not on this page · raw message
include/uapi/linux/serial_core.h +3 -0
@@ -293,4 +293,7 @@/* Freescale LINFlexD UART */ #define PORT_LINFLEXUART 122 +/* SunPlus Plus1 UART */ +#define PORT_PLUS1 123 +#endif /* _UAPILINUX_SERIAL_CORE_H */
Signature · 1 line
2.16.4
RFC 9/11 irqchip: Add Sunplus SP7021 interrupt (mux) controller
In reply to Andreas Färber--- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sp7021.c | 285 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 drivers/irqchip/irq-sp7021.c
drivers/irqchip/Makefile +1 -0
@@ -105,3 +105,4 @@ obj-$(CONFIG_MADERA_IRQ) += irq-madera.o obj-$(CONFIG_LS1X_IRQ) += irq-ls1x.o obj-$(CONFIG_TI_SCI_INTR_IRQCHIP) += irq-ti-sci-intr.o obj-$(CONFIG_TI_SCI_INTA_IRQCHIP) += irq-ti-sci-inta.o +obj-$(CONFIG_ARCH_SUNPLUS) += irq-sp7021.o
drivers/irqchip/irq-sp7021.c new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [RFC 09/11] irqchip: Add Sunplus SP7021 interrupt (mux) controller
Quoted 2 lines · Andreas Färber
Signed-off-by Andreas Färber <[email protected]>
Since you've now given me full permission to complain, can I trouble you for a meaningful commit message. It's not like it is the first time you write a patch...
Quoted 46 lines
--- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sp7021.c | 285 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 drivers/irqchip/irq-sp7021.cdrivers/irqchip/Makefile +1
-0@@ -105,3 +105,4 @@ obj-$(CONFIG_MADERA_IRQ) += irq-madera.o obj-$(CONFIG_LS1X_IRQ) += irq-ls1x.o obj-$(CONFIG_TI_SCI_INTR_IRQCHIP) += irq-ti-sci-intr.o obj-$(CONFIG_TI_SCI_INTA_IRQCHIP) += irq-ti-sci-inta.o +obj-$(CONFIG_ARCH_SUNPLUS) += irq-sp7021.odrivers/irqchip/irq-sp7021.c new file +25
-0@@ -0,0 +1,285 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Sunplus Plus1 SP7021 SoC interrupt controller +* +* Copyright (c) 2020 Andreas Färber +*/ + +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> + +#define REG_INTC_INTR_TYPE (i) (0x0 + (i) * 4) +#define REG_INTC_INTR_POLARITY (i) (0x1c + (i) * 4) +#define REG_INTC_INTR_PRIO (i) (0x38 + (i) * 4) +#define REG_INTC_INTR_MASK (i) (0x54 + (i) * 4) + +#define REG_INTC_INTR_CLR (i) (0x0 + (i) * 4) +#define REG_INTC_MASKED_FIQS (i) (0x1c + (i) * 4) +#define REG_INTC_MASKED_IRQS (i) (0x38 + (i) * 4) +#define REG_INTC_INTR_GROUP 0x7c
drivers/irqchip/irq-sp7021.c line 35
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+ +#define INTC_INTR_GROUP_FIQ GENMASK(6, 0) +#define INTC_INTR_GROUP_IRQ GENMASK(14, 8) + +struct sp7021_intc_data { +void __iomem *base0; +void __iomem *base1; +int ext0_irq; +int ext1_irq; +struct irq_chip chip;
Why do you need this irq_chip on a per instance basis?
Quoted 49 lines
drivers/irqchip/irq-sp7021.c new file +49
-0+struct irq_domain *domain; +raw_spinlock_t lock; +}; + +static void sp7021_intc_ext0_irq_handle (struct irq_desc *desc) +{ +struct sp7021_intc_data *s =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +u32 mask, masked; +int i, j; + +chained_irq_enter (chip, desc); + + mask =readl_relaxed (s->base1 +REG_INTC_INTR_GROUP ); + mask =FIELD_GET (INTC_INTR_GROUP_IRQ , mask); +while (mask) { + i =fls (mask) -1 ; + mask &= ~BIT (i); + + masked =readl_relaxed (s->base1 +REG_INTC_MASKED_IRQS (i)); +while (masked) { + j =fls (masked) -1 ; + masked &= ~BIT (j); + +generic_handle_irq (irq_find_mapping (s->domain, + i *32 + j)); + } + } + +chained_irq_exit (chip, desc); +} + +static void sp7021_intc_ext1_irq_handle (struct irq_desc *desc) +{ +struct sp7021_intc_data *s =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +u32 mask, masked; +int i, j; + +chained_irq_enter (chip, desc); + + mask =readl_relaxed (s->base1 +REG_INTC_INTR_GROUP ); + mask =FIELD_GET (INTC_INTR_GROUP_FIQ , mask); +while (mask) { + i =fls (mask) -1 ; + mask &= ~BIT (i); + + masked =readl_relaxed (s->base1 +REG_INTC_MASKED_FIQS (i)); +while (masked) {
drivers/irqchip/irq-sp7021.c line 94
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+ j =fls (masked) -1 ; + masked &= ~BIT (j); + +generic_handle_irq (irq_find_mapping (s->domain, + i *32 + j)); + } + } + +chained_irq_exit (chip, desc); +}
Given that the only difference between these two functions is INTC_INTR_GROUP_IRQ vs INTC_INTR_GROUP_FIQ (whatever that means for something connected to SPIs...), surely you can devise a way to make this common code.
drivers/irqchip/irq-sp7021.c line 102
Quoted 8 lines
drivers/irqchip/irq-sp7021.c new file +8
-0+ +static void sp7021_intc_ack_irq (struct irq_data *data) +{ +struct sp7021_intc_data *s =irq_data_get_irq_chip_data (data); +unsigned int idx; +u32 mask; + + idx = data->hwirq /32 ;
You have this construct everywhere. How about making all your offset helpers take a hwirq number instead? It would certainly make the whole thing look a little less fragile.
Quoted 45 lines
drivers/irqchip/irq-sp7021.c new file +45
-0+ + mask =BIT (data->hwirq %32 ); +writel_relaxed (mask, s->base1 +REG_INTC_INTR_CLR (idx)); +} + +static void sp7021_intc_mask_irq (struct irq_data *data) +{ +struct sp7021_intc_data *s =irq_data_get_irq_chip_data (data); +unsigned long flags; +unsigned int idx; +u32 mask; + + idx = data->hwirq /32 ; + +raw_spin_lock_irqsave (&s->lock, flags); + + mask =readl_relaxed (s->base0 +REG_INTC_INTR_MASK (idx)); + mask &= ~BIT (data->hwirq %32 ); +writel_relaxed (mask, s->base0 +REG_INTC_INTR_MASK (idx)); + +raw_spin_unlock_irqrestore (&s->lock, flags); +} + +static void sp7021_intc_unmask_irq (struct irq_data *data) +{ +struct sp7021_intc_data *s =irq_data_get_irq_chip_data (data); +unsigned long flags; +unsigned int idx; +u32 mask; + + idx = data->hwirq /32 ; + +raw_spin_lock_irqsave (&s->lock, flags); + + mask =readl_relaxed (s->base0 +REG_INTC_INTR_MASK (idx)); + mask |=BIT (data->hwirq %32 ); +writel_relaxed (mask, s->base0 +REG_INTC_INTR_MASK (idx)); + +raw_spin_unlock_irqrestore (&s->lock, flags); +} + +static int sp7021_intc_set_irq_type (struct irq_data *data,unsigned int flow_type) +{ +struct sp7021_intc_data *s =irq_data_get_irq_chip_data (data); +unsigned long flags;
drivers/irqchip/irq-sp7021.c line 157
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+unsigned int idx; +u32 mask, type, polarity; + + idx = data->hwirq /32 ; + mask =BIT (data->hwirq %32 ); + +if (flow_type &IRQ_TYPE_LEVEL_MASK ) +irq_set_chip_handler_name_locked (data, &s->chip, handle_level_irq,NULL ); +else +irq_set_chip_handler_name_locked (data, &s->chip, handle_edge_irq,NULL );
Now you've changed the flow type even if the checks below end-up failing. Don't do that. Also, please use irq_set_chip_handler_locked() instead. You don't need to change the irqchip.
Quoted 16 lines
drivers/irqchip/irq-sp7021.c new file +16
-0+ +raw_spin_lock_irqsave (&s->lock, flags); + + type =readl_relaxed (s->base0 +REG_INTC_INTR_TYPE (idx)); + polarity =readl_relaxed (s->base0 +REG_INTC_INTR_POLARITY (idx)); + +switch (flow_type) { +case IRQ_TYPE_EDGE_RISING : + type |= mask; + polarity &= ~mask; +break ; +case IRQ_TYPE_EDGE_FALLING : + type |= mask; + polarity |= mask; +break ; +case IRQ_TYPE_LEVEL_HIGH :
drivers/irqchip/irq-sp7021.c line 183
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+ type &= ~mask; + polarity &= ~mask; +break ; +case IRQ_TYPE_LEVEL_LOW : + type &= ~mask; + polarity |= mask; +break ; +default : +raw_spin_unlock_irqrestore (&s->lock, flags); +return -EBADR ;
The canonical error to use is -EINVAL.
Quoted 6 lines
drivers/irqchip/irq-sp7021.c new file +6
-0+ } + +writel_relaxed (type, s->base0 +REG_INTC_INTR_TYPE (idx)); +writel_relaxed (polarity, s->base0 +REG_INTC_INTR_POLARITY (idx)); + +raw_spin_unlock_irqrestore (&s->lock, flags);
drivers/irqchip/irq-sp7021.c line 199
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+ +return IRQ_SET_MASK_OK ; +} + +static const struct irq_chip sp7021_intc_irq_chip = { + .name ="SP7021-A" , + .irq_ack = sp7021_intc_ack_irq, + .irq_mask = sp7021_intc_mask_irq, + .irq_unmask = sp7021_intc_unmask_irq, + .irq_set_type = sp7021_intc_set_irq_type,
I assume this SoC is SMP. You need a set_affinity method that returns -EINVAL.
Quoted 13 lines
drivers/irqchip/irq-sp7021.c new file +13
-0+}; + +static int sp7021_intc_irq_domain_map (struct irq_domain *d, +unsigned int irq,irq_hw_number_t hw) +{ +struct sp7021_intc_data *s = d->host_data; +unsigned int idx; +u32 mask, type; + + idx = hw /32 ; + mask =BIT (hw %32 ); + + type =readl_relaxed (s->base0 +REG_INTC_INTR_TYPE (idx));
drivers/irqchip/irq-sp7021.c line 222
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+ +irq_set_chip_and_handler (irq, &s->chip, (type & mask) ? handle_edge_irq : handle_level_irq); +irq_set_chip_data (irq, s); +irq_set_probe (irq); + +return 0 ; +} + +static const struct irq_domain_ops sp7021_intc_domain_ops = { + .xlate = irq_domain_xlate_onecell,
If it is a single cell, how do you express the interrupt polarity in the DT? Specially when the DT binding says that #interrupt-cells = <2>. Clearly, you have never tested this.
drivers/irqchip/irq-sp7021.c line 234
Quoted 12 lines
drivers/irqchip/irq-sp7021.c new file +12
-0+ .map = sp7021_intc_irq_domain_map, +}; + +int __init sp7021_intc_init (struct device_node *node,struct device_node *parent) +{ +struct sp7021_intc_data *s; +void __iomem *base0, *base1; +int i; + + base0 =of_iomap (node,0 ); +if (!base0) +return -EIO ;
-ENOMEM.
drivers/irqchip/irq-sp7021.c line 238
Quoted 4 lines
drivers/irqchip/irq-sp7021.c new file +4
-0+ + base1 =of_iomap (node,1 ); +if (!base1) +return -EIO ;
Leaking mapping.
drivers/irqchip/irq-sp7021.c line 242
Quoted 4 lines
drivers/irqchip/irq-sp7021.c new file +4
-0+ + s =kzalloc (sizeof (*s),GFP_KERNEL ); +if (!s) +return -ENOMEM ;
Again.
drivers/irqchip/irq-sp7021.c line 246
Quoted 4 lines
drivers/irqchip/irq-sp7021.c new file +4
-0+ + s->base0 = base0; + s->base1 = base1; + s->chip = sp7021_intc_irq_chip;
That's exactly what I was complaining about earlier: pointlessly storing a copy of a static const data structure that never gets updated. Drop this.
Quoted 17 lines
drivers/irqchip/irq-sp7021.c new file +17
-0+ + s->ext0_irq =irq_of_parse_and_map (node,0 ); +if (s->ext0_irq <=0 ) { +kfree (s); +return -EINVAL ; + } + + s->ext1_irq =irq_of_parse_and_map (node,1 ); +if (s->ext1_irq <=0 ) { +kfree (s); +return -EINVAL ; + } + +raw_spin_lock_init (&s->lock); + +for (i =0 ; i <7 ; i++) { +writel_relaxed (0 , s->base0 +REG_INTC_INTR_MASK (i));
drivers/irqchip/irq-sp7021.c line 273
Quoted 10 lines
drivers/irqchip/irq-sp7021.c new file +10
-0+writel_relaxed (~0 , s->base0 +REG_INTC_INTR_TYPE (i)); +writel_relaxed (0 , s->base0 +REG_INTC_INTR_POLARITY (i)); + +/* irq, not fiq */ +writel_relaxed (~0 , s->base0 +REG_INTC_INTR_PRIO (i)); + +writel_relaxed (~0 , s->base1 +REG_INTC_INTR_CLR (i)); + } + + s->domain = irq_domain_add_linear(node, 200, &sp7021_intc_domain_ops,
Magic numbers.
drivers/irqchip/irq-sp7021.c line 285
Quoted 12 lines
drivers/irqchip/irq-sp7021.c new file +12
-0+ s); +if (!s->domain) { +kfree (s); +return -ENOMEM ; + } + +irq_set_chained_handler_and_data (s->ext0_irq, sp7021_intc_ext0_irq_handle, s); +irq_set_chained_handler_and_data (s->ext1_irq, sp7021_intc_ext1_irq_handle, s); + +return 0 ; +} +IRQCHIP_DECLARE (sp7021_intc,"sunplus,sp7021-intc" , sp7021_intc_init);
So yes, I complained a lot. Thanks for giving me the opportunity.
M.
Signature · 6 lines
Jazz is not dead, it just smells funny. _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC 10/11 ARM: dts: sp7021-cpu: Add interrupt controller node
In reply to Andreas Färber--- arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi +13 -0
@@ -73,3 +73,16 @@ }; }; }; + +&rgst { + intc: interrupt-controller@780 { + compatible = "sunplus,sp7021-intc"; + reg = <0x780 0x80>, /* G15 */ + <0xa80 0x80>; /* G21 */ + interrupt-parent = <&gic>; + interrupts = <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + #interrupt-cells = <2>; + }; +};
Signature · 1 line
2.16.4
RFC 11/11 ARM: dts: sp7021-cpu: Add dummy UART0 clock and interrupt
In reply to Andreas Färber--- arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts | 7 +++++++ arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi | 5 +++++ 2 files changed, 12 insertions(+)
arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts +7 -0
@@ -15,8 +15,15 @@ chosen { stdout-path = "serial0:115200n8"; }; + + uart0_clk: clk { + compatible = "fixed-clock"; + clock-frequency = <27000000>; + #clock-cells = <0>; + }; }; &uart0 { status = "okay"; + clocks = <&uart0_clk>; };
arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi +5 -0
@@ -86,3 +86,8 @@ #interrupt-cells = <2>; }; }; + +&uart0 { + interrupt-parent = <&intc>; + interrupts = <53 IRQ_TYPE_LEVEL_HIGH>; +};
Signature · 1 line
2.16.4
Added Jie Zhang and Jian Qin in to cc list.
Jie Zhang is software leader of Sunplus Plus 1 (SP7021) platform.
-----Original Message-----
From: Andreas Färber <[email protected]>
Sent: Monday, March 09, 2020 12:32 AM
To: [email protected]
Cc: Wells Lu 呂芳騰 <[email protected]>; Dvorkin Dmitry <[email protected]>; [email protected]; Andreas Färber <[email protected]>; [email protected]; Rob Herring <[email protected]>; Greg Kroah-Hartman <[email protected]>; [email protected]; Thomas Gleixner <[email protected]>; Jason Cooper <[email protected]>; Marc Zyngier <[email protected]>
Subject: [RFC 00/11] ARM: Initial Sunplus Plus1 SP7021 and BPI-F2S support
Hello,
This patch series adds initial drivers and Device Trees for Sunplus Plus1 series (codename Pentagram) SP7021 SoC and Banana Pi BPI-F2S SBC.
First, minimal Kconfig, DT and earlycon driver are prepared to get serial output at all. Next, interrupt controller and full serial driver are added that allow to boot into an initrd with interactive serial console.
Device Tree files added are for the CPU-Chip (aka A-Chip) with quad Cortex-A7, but the file split prepares for also adding the Peripheral-Chip (B-Chip) with
ARM9 later. However, for now this is not reflected in the .dts filename; this corresponds to the vf610- vs. vf610m4- naming scheme, whereas an alternative would be to use sp7021-cchip- vs. -pchip- prefix (as sp7021-cpu- looks weird). It is assumed we can reuse the same SoC and board bindings for CA7 and ARM9 and only differ for IP blocks where needed.
My inquiry to Sunplus about their GIC (anticipating complaints from Marc) remained unanswered, so I've added the two extra regions and irq myself, without being able to test KVM due to BSP U-Boot not booting in HYP mode. According to Sunplus the mode can be changed in U-Boot (but where/how?).
Similarly, the architectural timer is not properly initialized in BSP U-Boot, so that I currently have a mach- hack in my tree below. Unlike RTD1195, we do have U-Boot sources (v2019.04 based), so should be able to fix this in the bootloader rather than in the kernel, thus not included as patch here.
Based on SoC online manual [1] and downstream BPI-F2S BSP tree [2] as well as my previous Actions serial and Realtek irqchip drivers and DTs.
More details at:
https://en.opensuse.org/HCL:BananaPi_F2S
Latest experimental patches at:
https://github.com/afaerber/linux/commits/f2s-next
Have a lot of fun!
Cheers,
Andreas
[1] https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/470450252/SP7021+Technical+Manual
[2] https://github.com/BPI-SINOVOIP/BPI-F2S-bsp
Andreas Färber (11):
dt-bindings: vendor-prefixes: Add Sunplus
dt-bindings: arm: Add Sunplus SP7021 and Banana Pi BPI-F2S
ARM: Prepare Sunplus Plus1 SoC family
dt-bindings: interrupt-controller: Add Sunplus SP7021 mux
dt-bindings: serial: Add Sunplus SP7021 UART
tty: serial: Add Sunplus Plus1 UART earlycon
ARM: dts: Add Sunplus Plus1 SP7021 and Banana Pi F2S
tty: serial: sunplus: Implement full UART driver
irqchip: Add Sunplus SP7021 interrupt (mux) controller
ARM: dts: sp7021-cpu: Add interrupt controller node
ARM: dts: sp7021-cpu: Add dummy UART0 clock and interrupt
Documentation/devicetree/bindings/arm/sunplus.yaml | 22 + .../sunplus,pentagram-intc.yaml | 50 ++ .../bindings/serial/sunplus,pentagram-uart.yaml | 24 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + arch/arm/Kconfig | 2 + arch/arm/Makefile | 1 + arch/arm/boot/dts/Makefile | 2 + arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts | 29 + arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi | 93 +++ arch/arm/boot/dts/pentagram-sp7021.dtsi | 61 ++ arch/arm/mach-sunplus/Kconfig | 10 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sp7021.c | 285 ++++++++ drivers/tty/serial/Kconfig | 19 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/sunplus-uart.c | 770 +++++++++++++++++++++ include/uapi/linux/serial_core.h | 3 + 17 files changed, 1375 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/sunplus.yaml create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,pentagram-intc.yaml create mode 100644 Documentation/devicetree/bindings/serial/sunplus,pentagram-uart.yaml create mode 100644 arch/arm/boot/dts/pentagram-sp7021-bpi-f2s.dts create mode 100644 arch/arm/boot/dts/pentagram-sp7021-cpu.dtsi create mode 100644 arch/arm/boot/dts/pentagram-sp7021.dtsi create mode 100644 arch/arm/mach-sunplus/Kconfig create mode 100644 drivers/irqchip/irq-sp7021.c create mode 100644 drivers/tty/serial/sunplus-uart.c
--
2.16.4
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel