Skip to contentSkip to conversation

Add UART driver for Suplus SP7021 SoC

PATCH Superseded hammer.hsieh 7 participants 19 messages Nov 1, 2021 – Nov 29, 2021

Subsystems (3)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

hammer.hsieh

author maintainer
#0 lore raw

cover Add UART driver for Suplus SP7021 SoC

This is a patch series for UART driver for Suplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART. I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

hammer.hsieh (2):
dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver serial:sunplus-uart:Add Sunplus SoC UART Driver

 .../devicetree/bindings/serial/sunplus,uart.yaml   |  116 ++
 MAINTAINERS                                        |    7 +
 drivers/tty/serial/Kconfig                         |   23 +
 drivers/tty/serial/Makefile                        |    1 +
 drivers/tty/serial/sunplus-uart.c                  | 1848 ++++++++++++++++++++
 include/soc/sunplus/sp_uart.h                      |  158 ++
 6 files changed, 2153 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,uart.yaml
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 1/2 dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

Add bindings doc for Sunplus SoC UART Driver

---
 .../devicetree/bindings/serial/sunplus,uart.yaml   | 116 +++++++++++++++++++++
 MAINTAINERS                                        |   5 +
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,uart.yaml
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +116 -0
new file mode 100644
index 0000000..f2ca9ee
@@ -0,0 +1,116 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/serial/sunplus,uart.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Sunplus SoC UART Controller Device Tree Bindings
+
+maintainers:
+  - Tony Huang <[email protected]>
+  - Hammer Hsieh <[email protected]>
+  - Wells Lu <[email protected]>
+
+allOf:
+  - $ref: serial.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-uart
+
+  reg:
+    minItems: 1
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 1
+    maxItems: 2
+
+  clock-names:
+    oneOf:
+      - items:
+        - const: UADMA
+        - const: PERI0
+      - items:
+        - const: UADMA
+        - const: PERI1
+      - items:
+        - const: HWUA
+        - const: PERI0
+      - items:
+        - const: HWUA
+        - const: PERI1
+
+  resets:
+    maxItems: 1
+
+  which-uart:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [ 1, 2, 3, 4]
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    aliases {
+            serial0 = &uart0;
+            serial1 = &uart1;
+            serial10 = &uartdmarx0;
+            serial20 = &uartdmatx0;
+    };
+
+    uart0: serial@9c000900 {
+      compatible = "sunplus,sp7021-uart";
+      reg = <0x9c000900 0x80>;
+      interrupt-parent = <&intc>;
+      interrupts = <53 IRQ_TYPE_LEVEL_HIGH>;
+      clocks = <&clkc UA0>;
+      resets = <&rstc RST_UA0>;
+    };
+
+    // UART1 PIO mode
+    uart1: serial@9c000980 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000980 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <54 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc UA1>;
+        resets = <&rstc RST_UA1>;
+    };
+
+    // UART1 DMA mode for RX
+    uartdmarx0: serial@9c008980 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c008980 0x40>;
+        interrupt-parent = <&intc>;
+        interrupts = <138 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc UADMA>, <&clkc PERI0>;
+        clock-names = "UADMA", "PERI0";
+        resets = <&rstc RST_UADMA>;
+        which-uart = <1>;
+    };
+
+    // UART1 DMA mode for TX
+    uartdmatx0: serial@9c008a00 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c008a00 0x40>, <0x9c008880 0x80>;
+        clocks = <&clkc HWUA>, <&clkc PERI0>;
+        clock-names = "HWUA", "PERI0";
+        resets = <&rstc RST_HWUA>;
+        which-uart = <1>;
+    };
+
+...
MAINTAINERS +5 -0
index 3b79fd4..f863e97 100644
@@ -17945,6 +17945,11 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS UART DRIVER
+M:	Hammer Hsieh <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/serial/sunplus,uart.yaml
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

Quoted 9 lines · hammer.hsieh

Add bindings doc for Sunplus SoC UART Driver

---
 .../devicetree/bindings/serial/sunplus,uart.yaml   | 116 +++++++++++++++++++++
 MAINTAINERS                                        |   5 +
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,uart.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/serial/sunplus,uart.yaml:36:9: [warning] wrong indentation: expected 10 but found 8 (indentation) ./Documentation/devicetree/bindings/serial/sunplus,uart.yaml:39:9: [warning] wrong indentation: expected 10 but found 8 (indentation) ./Documentation/devicetree/bindings/serial/sunplus,uart.yaml:42:9: [warning] wrong indentation: expected 10 but found 8 (indentation) ./Documentation/devicetree/bindings/serial/sunplus,uart.yaml:45:9: [warning] wrong indentation: expected 10 but found 8 (indentation)

dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/serial/sunplus,uart.example.dts:20:18: fatal error: dt-bindings/clock/sp-sp7021.h: No such file or directory
20 | #include <dt-bindings/clock/sp-sp7021.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:385: Documentation/devicetree/bindings/serial/sunplus,uart.example.dt.yaml] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1441: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1548996

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

maintainer
#3 lore raw

Re: [PATCH 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

In reply to hammer.hsieh
Quoted 45 lines · hammer.hsieh

Add bindings doc for Sunplus SoC UART Driver

---
 .../devicetree/bindings/serial/sunplus,uart.yaml   | 116 +++++++++++++++++++++
 MAINTAINERS                                        |   5 +
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,uart.yaml
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +30 -0
new file mode 100644
index 0000000..f2ca9ee
@@ -0,0 +1,116 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/serial/sunplus,uart.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Sunplus SoC UART Controller Device Tree Bindings
+
+maintainers:
+  - Tony Huang <[email protected]>
+  - Hammer Hsieh <[email protected]>
+  - Wells Lu <[email protected]>
+
+allOf:
+  - $ref: serial.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-uart
+
+  reg:
+    minItems: 1
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 1

Documentation/devicetree/bindings/serial/sunplus,uart.yaml line 40

Quoted 10 lines
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +10 -0
+    maxItems: 2
+
+  clock-names:
+    oneOf:
+      - items:
+        - const: UADMA
+        - const: PERI0
+      - items:
+        - const: UADMA
+        - const: PERI1

These 2 can be:

items:
- const UADMA
- pattern: '^PERI[0-1]$'

But why the difference for only one model of UART? The names should reflect the function of the clock.

Documentation/devicetree/bindings/serial/sunplus,uart.yaml line 53

Quoted 13 lines
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +13 -0
+      - items:
+        - const: HWUA
+        - const: PERI0
+      - items:
+        - const: HWUA
+        - const: PERI1
+
+  resets:
+    maxItems: 1
+
+  which-uart:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [ 1, 2, 3, 4]

What's this for? Looks like an index and we don't do indices in DT. There is 'aliases' though.

Quoted 17 lines
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +17 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    aliases {
+            serial0 = &uart0;
+            serial1 = &uart1;

Documentation/devicetree/bindings/serial/sunplus,uart.yaml line 80

Quoted 10 lines
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +10 -0
+            serial10 = &uartdmarx0;
+            serial20 = &uartdmatx0;
+    };
+
+    uart0: serial@9c000900 {
+      compatible = "sunplus,sp7021-uart";
+      reg = <0x9c000900 0x80>;
+      interrupt-parent = <&intc>;
+      interrupts = <53 IRQ_TYPE_LEVEL_HIGH>;
+      clocks = <&clkc UA0>;

The schema says you must have 2 clocks.

Quoted 56 lines
Documentation/devicetree/bindings/serial/sunplus,uart.yaml new file +36 -0
+      resets = <&rstc RST_UA0>;
+    };
+
+    // UART1 PIO mode
+    uart1: serial@9c000980 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000980 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <54 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc UA1>;
+        resets = <&rstc RST_UA1>;
+    };
+
+    // UART1 DMA mode for RX
+    uartdmarx0: serial@9c008980 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c008980 0x40>;
+        interrupt-parent = <&intc>;
+        interrupts = <138 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc UADMA>, <&clkc PERI0>;
+        clock-names = "UADMA", "PERI0";
+        resets = <&rstc RST_UADMA>;
+        which-uart = <1>;
+    };
+
+    // UART1 DMA mode for TX
+    uartdmatx0: serial@9c008a00 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c008a00 0x40>, <0x9c008880 0x80>;
+        clocks = <&clkc HWUA>, <&clkc PERI0>;
+        clock-names = "HWUA", "PERI0";
+        resets = <&rstc RST_HWUA>;
+        which-uart = <1>;
+    };
+
+...
MAINTAINERS +5 -0
index 3b79fd4..f863e97 100644
@@ -17945,6 +17945,11 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS UART DRIVER
+M:	Hammer Hsieh <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/serial/sunplus,uart.yaml
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
Signature · 1 line
2.7.4
author maintainer
#4 lore raw

PATCH 2/2 serial:sunplus-uart:Add Sunplus SoC UART Driver

In reply to hammer.hsieh

Add Sunplus SoC UART Driver

---
 MAINTAINERS                       |    2 +
 drivers/tty/serial/Kconfig        |   23 +
 drivers/tty/serial/Makefile       |    1 +
 drivers/tty/serial/sunplus-uart.c | 1848 +++++++++++++++++++++++++++++++++++++
 include/soc/sunplus/sp_uart.h     |  158 ++++
 5 files changed, 2032 insertions(+)
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
MAINTAINERS +2 -0
index f863e97..0176026 100644
@@ -17949,6 +17949,8 @@ SUNPLUS UART DRIVER
 M:	Hammer Hsieh <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/serial/sunplus,uart.yaml
+F:	drivers/tty/serial/sunplus-uart.c
+F:	include/soc/sunplus/sp-uart.h
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/tty/serial/Kconfig +23 -0
index 131a6a5..319f5db 100644
@@ -1561,6 +1561,29 @@ config SERIAL_LITEUART_CONSOLE
 	  and warnings and which allows logins in single user mode).
 	  Otherwise, say 'N'.
 
+config SERIAL_SUNPLUS
+	bool "Sunplus UART support"
+	depends on OF
+	select SERIAL_CORE
+	help
+	  Select this option if you would like to use Sunplus serial port on
+	  Sunplus SoC SP7021.
+	  If you enable this option, Sunplus serial ports in the system will
+	  be registered as ttySx.
+
+config SERIAL_SUNPLUS_CONSOLE
+	bool "Console on Sunplus UART"
+	depends on SERIAL_SUNPLUS
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Select this option if you would like to use a Sunplus UART as the
+	  system console.
+	  Even if you say Y here, the currently visible virtual console
+	  (/dev/tty0) will still be used as the system console by default, but
+	  you can alter that using a kernel command line option such as
+	  "console=ttySx".
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index 7da0856..61cc8de 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_SERIAL_RDA)	+= rda-uart.o
 obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o
 obj-$(CONFIG_SERIAL_SIFIVE)	+= sifive.o
 obj-$(CONFIG_SERIAL_LITEUART) += liteuart.o
+obj-$(CONFIG_SERIAL_SUNPLUS)	+= 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 +1848 -0

1,848 lines not on this page · raw message

include/soc/sunplus/sp_uart.h new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#5 lore raw

Re: [PATCH 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Quoted 3 lines · hammer.hsieh

Add Sunplus SoC UART Driver

I doubt you sign your name with a "." in it, right?

Also this address does not match your From: address. Please fix this up when resending this.

Quoted 75 lines
---
 MAINTAINERS                       |    2 +
 drivers/tty/serial/Kconfig        |   23 +
 drivers/tty/serial/Makefile       |    1 +
 drivers/tty/serial/sunplus-uart.c | 1848 +++++++++++++++++++++++++++++++++++++
 include/soc/sunplus/sp_uart.h     |  158 ++++
 5 files changed, 2032 insertions(+)
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
MAINTAINERS +2 -0
index f863e97..0176026 100644
@@ -17949,6 +17949,8 @@ SUNPLUS UART DRIVER
 M:	Hammer Hsieh <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/serial/sunplus,uart.yaml
+F:	drivers/tty/serial/sunplus-uart.c
+F:	include/soc/sunplus/sp-uart.h
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/tty/serial/Kconfig +23 -0
index 131a6a5..319f5db 100644
@@ -1561,6 +1561,29 @@ config SERIAL_LITEUART_CONSOLE
 	  and warnings and which allows logins in single user mode).
 	  Otherwise, say 'N'.
 
+config SERIAL_SUNPLUS
+	bool "Sunplus UART support"
+	depends on OF
+	select SERIAL_CORE
+	help
+	  Select this option if you would like to use Sunplus serial port on
+	  Sunplus SoC SP7021.
+	  If you enable this option, Sunplus serial ports in the system will
+	  be registered as ttySx.
+
+config SERIAL_SUNPLUS_CONSOLE
+	bool "Console on Sunplus UART"
+	depends on SERIAL_SUNPLUS
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Select this option if you would like to use a Sunplus UART as the
+	  system console.
+	  Even if you say Y here, the currently visible virtual console
+	  (/dev/tty0) will still be used as the system console by default, but
+	  you can alter that using a kernel command line option such as
+	  "console=ttySx".
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index 7da0856..61cc8de 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_SERIAL_RDA)	+= rda-uart.o
 obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o
 obj-$(CONFIG_SERIAL_SIFIVE)	+= sifive.o
 obj-$(CONFIG_SERIAL_LITEUART) += liteuart.o
+obj-$(CONFIG_SERIAL_SUNPLUS)	+= 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 +0 -0
new file mode 100644
index 0000000..d1524dc

drivers/tty/serial/sunplus-uart.c line 1

Quoted 1 line
drivers/tty/serial/sunplus-uart.c new file +1 -0
@@ -0,0 +1,1848 @@
+// SPDX-License-Identifier: GPL-2.0-or-later

I have to ask,. but are you sure about this license that it needs to be "-or-later"?

Quoted 22 lines
drivers/tty/serial/sunplus-uart.c new file +22 -0
+/*
+ * Sunplus SoC UART driver
+ *
+ * Author: Hammer Hsieh <[email protected]>
+ * Tony Huang <[email protected]>
+ * Wells Lu <[email protected]>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/of_platform.h>
+#include <asm/irq.h>
+#if defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#include <linux/sysrq.h>
+#endif

drivers/tty/serial/sunplus-uart.c line 33

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+#include <linux/serial_core.h>
+#include <linux/clk.h>
+#include <linux/reset.h>
+#include <linux/io.h>
+#include <linux/dma-mapping.h>
+#include <soc/sunplus/sp_uart.h>
+
+#ifdef CONFIG_PM_RUNTIME_UART
+#include <linux/pm_runtime.h>
+#endif

Why the #ifdef in the .c file?

drivers/tty/serial/sunplus-uart.c line 35

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+
+#include <linux/gpio.h>

GPIO in a serial driver?

drivers/tty/serial/sunplus-uart.c line 41

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <dt-bindings/clock/sp-sp7021.h>
+#include <dt-bindings/pinctrl/sppctl-sp7021.h>
+#include <linux/delay.h>
+#include <linux/hrtimer.h>

Please put the linux/ includes above the dt-bindings ones.

drivers/tty/serial/sunplus-uart.c line 44

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+
+#define DEVICE_NAME				"ttyS"
+#define SP_UART_MAJOR			TTY_MAJOR

Why is this driver allowed to be named the same as the other serial drivers? What happens when you plug in a 8250 card to this device?

drivers/tty/serial/sunplus-uart.c line 45

Quoted 1 line
drivers/tty/serial/sunplus-uart.c new file +1 -0
+#define SP_UART_MINOR_START		64

Why here?

drivers/tty/serial/sunplus-uart.c line 49

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+
+#define NUM_UART		6	/* serial0,  ... */
+#define NUM_UARTDMARX	2	/* serial10, ... */
+#define NUM_UARTDMATX	2	/* serial20, ... */

Why are these hard codeded?

drivers/tty/serial/sunplus-uart.c line 61

Quoted 12 lines
drivers/tty/serial/sunplus-uart.c new file +12 -0
+
+#define ID_BASE_DMARX	10
+#define ID_BASE_DMATX	20
+
+#define IS_UARTDMARX_ID(X) \
+	(((X) >= (ID_BASE_DMARX)) && ((X) < (ID_BASE_DMARX + NUM_UARTDMARX)))
+#define IS_UARTDMATX_ID(X) \
+	(((X) >= (ID_BASE_DMATX)) && ((X) < (ID_BASE_DMATX + NUM_UARTDMATX)))
+
+//#define TTYS_KDBG_INFO
+#define TTYS_KDBG_ERR
+//#define TTYS_GPIO

Why is this commented out?

Why is this defined at all?

drivers/tty/serial/sunplus-uart.c line 72

Quoted 11 lines
drivers/tty/serial/sunplus-uart.c new file +11 -0
+
+#ifdef TTYS_KDBG_INFO
+#define DBG_INFO(fmt, args ...)	pr_info("K_TTYS: " fmt, ## args)
+#else
+#define DBG_INFO(fmt, args ...)
+#endif
+#ifdef TTYS_KDBG_ERR
+#define DBG_ERR(fmt, args ...)	pr_err("K_TTYS: " fmt, ## args)
+#else
+#define DBG_ERR(fmt, args ...)
+#endif

No, please use dev_info(), dev_err() and dev_dbg() only. Do not create your own logging macros for a single driver, use the ones the kernel gives you.

drivers/tty/serial/sunplus-uart.c line 83

Quoted 11 lines
drivers/tty/serial/sunplus-uart.c new file +11 -0
+
+#define SP_UART_CREAD_DISABLED		(1 << 16)
+
+#define UARXDMA_BUF_SZ			PAGE_SIZE
+#define MAX_SZ_RXDMA_ISR		(1 << 9)
+#define UATXDMA_BUF_SZ			PAGE_SIZE
+
+#define CLK_HIGH_UART			202500000
+#define UART_RATIO				232
+
+#if defined(CONFIG_SP_MON)

What sets this?

I've stopped reviewing here.

thanks,

greg k-h

author maintainer
#6 lore raw

v2 cover Add UART driver for Suplus SP7021 SoC

In reply to hammer.hsieh

This is a patch series for UART driver for Suplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART. I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Hammer Hsieh (2):
dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver serial:sunplus-uart:Add Sunplus SoC UART Driver

 .../bindings/serial/sunplus,sp7021-uart.yaml       |  157 ++
 MAINTAINERS                                        |    7 +
 drivers/tty/serial/Kconfig                         |   23 +
 drivers/tty/serial/Makefile                        |    1 +
 drivers/tty/serial/sunplus-uart.c                  | 1591 ++++++++++++++++++++
 include/soc/sunplus/sp_uart.h                      |  147 ++
 6 files changed, 1926 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
Signature · 1 line
2.7.4
author maintainer
#7 lore raw

PATCH v2 1/2 dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

Add bindings doc for Sunplus SoC UART Driver

---
Changes in v2:
- Addressed all comments from Mr. Rob Herring.

 .../bindings/serial/sunplus,sp7021-uart.yaml       | 157 +++++++++++++++++++++
 MAINTAINERS                                        |   5 +
 2 files changed, 162 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml new file +157 -0
new file mode 100644
index 0000000..3f46f3e
@@ -0,0 +1,157 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/serial/sunplus,sp7021-uart.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Sunplus SoC SP7021 UART Controller Device Tree Bindings
+
+maintainers:
+  - Tony Huang <[email protected]>
+  - Hammer Hsieh <[email protected]>
+  - Wells Lu <[email protected]>
+
+allOf:
+  - $ref: serial.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-uart
+
+  reg:
+    minItems: 1
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 1
+    maxItems: 2
+
+  clock-names:
+    oneOf:
+      - items:
+          - const: UADMA
+          - pattern: '^PERI[0-1]$'
+      - items:
+          - const: HWUA
+          - pattern: '^PERI[0-1]$'
+
+  resets:
+    maxItems: 1
+
+  which-uart:
+    description:
+      UA1-4 support DMA mode, UA0 support PIO mode only.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [ 1, 2, 3, 4]
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+if:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sunplus,sp7021-uart-rxdma
+          - sunplus,sp7021-uart-txdma
+then:
+  required:
+    - clock-names
+    - which-uart
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    aliases {
+            serial0 = &uart0;
+            serial1 = &uart1;
+            serial2 = &uart2;
+            serial10 = &uartdmarx0;
+            serial20 = &uartdmatx0;
+            serial11 = &uartdmarx1;
+            serial21 = &uartdmatx1;
+    };
+
+    // UART0 PIO mode only
+    uart0: serial@9c000900 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000900 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <53 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x28>;
+        resets = <&rstc 0x18>;
+    };
+
+    // UART1 PIO mode
+    uart1: serial@9c000980 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000980 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <54 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x29>;
+        resets = <&rstc 0x19>;
+    };
+
+    // UART1 DMA mode for RX
+    uartdmarx0: serial@9c008980 {
+        compatible = "sunplus,sp7021-uart-rxdma";
+        reg = <0x9c008980 0x40>;
+        interrupt-parent = <&intc>;
+        interrupts = <138 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x2f>, <&clkc 0x1b>;
+        clock-names = "UADMA", "PERI0";
+        resets = <&rstc 0x1f>;
+        which-uart = <1>;
+    };
+
+    // UART1 DMA mode for TX
+    uartdmatx0: serial@9c008a00 {
+        compatible = "sunplus,sp7021-uart-txdma";
+        reg = <0x9c008a00 0x40>, <0x9c008880 0x80>;
+        clocks = <&clkc 0x2d>, <&clkc 0x1b>;
+        clock-names = "HWUA", "PERI0";
+        resets = <&rstc 0x1d>;
+        which-uart = <1>;
+    };
+
+    // UART2 PIO mode
+    uart2: serial@9c000800 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000800 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <55 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x2a>;
+        resets = <&rstc 0x1a>;
+    };
+
+    // UART2 DMA mode for RX
+    uartdmarx1: serial@9c0089c0 {
+        compatible = "sunplus,sp7021-uart-rxdma";
+        reg = <0x9c0089c0 0x40>;
+        interrupt-parent = <&intc>;
+        interrupts = <139 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x2f>,	<&clkc 0x1f>;
+        clock-names = "UADMA", "PERI1";
+        resets = <&rstc 0x1f>;
+        which-uart = <2>;
+    };
+
+    // UART2 DMA mode for TX
+    uartdmatx1: serial@9c008a40 {
+        compatible = "sunplus,sp7021-uart-txdma";
+        reg = <0x9c008a40 0x40>, <0x9c008900 0x80>;
+        clocks = <&clkc 0x2d>, <&clkc 0x1f>;
+        clock-names = "HWUA", "PERI1";
+        resets = <&rstc 0x1d>;
+        which-uart = <2>;
+    };
+...
MAINTAINERS +5 -0
index 3b79fd4..f2ee40c 100644
@@ -17945,6 +17945,11 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS UART DRIVER
+M:	Hammer Hsieh <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
Signature · 1 line
2.7.4
author maintainer
#8 lore raw

PATCH v2 2/2 serial:sunplus-uart:Add Sunplus SoC UART Driver

In reply to Hammer Hsieh

Add Sunplus SoC UART Driver

---
Changes in v2:
- Addressed all comments from Mr. Greg Kroah-Hartman.

 MAINTAINERS                       |    2 +
 drivers/tty/serial/Kconfig        |   23 +
 drivers/tty/serial/Makefile       |    1 +
 drivers/tty/serial/sunplus-uart.c | 1591 +++++++++++++++++++++++++++++++++++++
 include/soc/sunplus/sp_uart.h     |  147 ++++
 5 files changed, 1764 insertions(+)
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
MAINTAINERS +2 -0
index f2ee40c..14790a4 100644
@@ -17949,6 +17949,8 @@ SUNPLUS UART DRIVER
 M:	Hammer Hsieh <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
+F:	drivers/tty/serial/sunplus-uart.c
+F:	include/soc/sunplus/sp-uart.h
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/tty/serial/Kconfig +23 -0
index 131a6a5..319f5db 100644
@@ -1561,6 +1561,29 @@ config SERIAL_LITEUART_CONSOLE
 	  and warnings and which allows logins in single user mode).
 	  Otherwise, say 'N'.
 
+config SERIAL_SUNPLUS
+	bool "Sunplus UART support"
+	depends on OF
+	select SERIAL_CORE
+	help
+	  Select this option if you would like to use Sunplus serial port on
+	  Sunplus SoC SP7021.
+	  If you enable this option, Sunplus serial ports in the system will
+	  be registered as ttySx.
+
+config SERIAL_SUNPLUS_CONSOLE
+	bool "Console on Sunplus UART"
+	depends on SERIAL_SUNPLUS
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Select this option if you would like to use a Sunplus UART as the
+	  system console.
+	  Even if you say Y here, the currently visible virtual console
+	  (/dev/tty0) will still be used as the system console by default, but
+	  you can alter that using a kernel command line option such as
+	  "console=ttySx".
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index 7da0856..61cc8de 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_SERIAL_RDA)	+= rda-uart.o
 obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o
 obj-$(CONFIG_SERIAL_SIFIVE)	+= sifive.o
 obj-$(CONFIG_SERIAL_LITEUART) += liteuart.o
+obj-$(CONFIG_SERIAL_SUNPLUS)	+= 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 +1591 -0

1,591 lines not on this page · raw message

include/soc/sunplus/sp_uart.h new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Hi,

On Wed, 2021-11-10 at 15:51 +0800, Hammer Hsieh wrote:
[...]

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+struct sunplus_uart_port {
+	char name[16];
+	struct uart_port uport;
+	struct sunplus_dma_info *uartdma_rx;

drivers/tty/serial/sunplus-uart.c line 70

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+	struct sunplus_dma_info *uartdma_tx;
+	struct clk *clk;
+	struct reset_control *rstc;
+	unsigned int pllsys_rate;
+	struct gpio_desc *rts_gpio;
+	struct hrtimer rts_check_tx_empty;
+	struct hrtimer rts_delay_before_send;
+	struct hrtimer rts_delay_after_send;
+};
+struct sunplus_uart_port sunplus_uart_ports[UART_NR];

Does this have to be a global array? I would expect these to be allocated in the probe function, one at a time.

[...]

Quoted 17 lines
drivers/tty/serial/sunplus-uart.c new file +17 -0
+static int sunplus_uart_probe(struct platform_device *pdev)
+{
+	struct resource *res_mem;
+	struct uart_port *port;
+	struct clk *clk, *pllsys;
+	unsigned int pllsys_rate;
+	int ret, irq;
+	int idx_offset, idx;
+	int idx_which_uart;
+	char peri_name[16];
+
+	if (pdev->dev.of_node) {
+		pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
+		if (pdev->id < 0)
+			pdev->id = of_alias_get_id(pdev->dev.of_node, "uart");
+	}
+

drivers/tty/serial/sunplus-uart.c line 1252

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+	idx_offset = -1;
+
+	if (IS_UARTDMARX_ID(pdev->id))
+		idx_offset = 0;
+	else if (IS_UARTDMATX_ID(pdev->id))
+		idx_offset = UART_DMARX_NR;
+
+	/* init txdma or rxdma */
+	if (idx_offset >= 0) {
+		clk = devm_clk_get(&pdev->dev, NULL);

Should this be requested by name? Looking at the binding, this could be UADMA or HWUA?

drivers/tty/serial/sunplus-uart.c line 1258

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;

I suggest to move this down after all required resources are available. Otherwise you'll have to either disable the clock in the error paths, or you are left with a running clock if anything below fails.

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+		if (idx_offset == 0)
+			idx = idx_offset + pdev->id - ID_BASE_DMARX;
+		else
+			idx = idx_offset + pdev->id - ID_BASE_DMATX;
+
+		res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);

drivers/tty/serial/sunplus-uart.c line 1275

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+		if (!res_mem)
+			return -ENODEV;
+
+		sprintf(peri_name, "PERI%d", (idx & 0x01));
+
+		clk = devm_clk_get(&pdev->dev, peri_name);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		ret = clk_prepare_enable(clk);

Same as above.

Quoted 68 lines
drivers/tty/serial/sunplus-uart.c new file +68 -0
+		if (ret)
+			return ret;
+
+		sunplus_uartdma[idx].addr_phy =
+			(unsigned long)(res_mem->start);
+		sunplus_uartdma[idx].membase =
+			devm_ioremap_resource(&pdev->dev, res_mem);
+
+		if (IS_ERR(sunplus_uartdma[idx].membase))
+			return PTR_ERR(sunplus_uartdma[idx].membase);
+
+		if (IS_UARTDMARX_ID(pdev->id)) {
+			irq = platform_get_irq(pdev, 0);
+			if (irq < 0)
+				return -ENODEV;
+
+			sunplus_uartdma[idx].irq = irq;
+		} else {
+			res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+			if (!res_mem)
+				return -ENODEV;
+
+			sunplus_uartdma[idx].gdma_membase =
+				devm_ioremap_resource(&pdev->dev, res_mem);
+
+			if (IS_ERR(sunplus_uartdma[idx].gdma_membase))
+				return -EINVAL;
+		}
+
+		if (of_property_read_u32(pdev->dev.of_node, "which-uart", &idx_which_uart) != 0) {
+			dev_err(&pdev->dev, "\"which-uart\" is not assigned.");
+			return -EINVAL;
+		}
+
+		if (idx_which_uart >= UART_NR) {
+			dev_err(&pdev->dev, "\"which-uart\" is not valid.");
+			return -EINVAL;
+		}
+
+		sunplus_uartdma[idx].which_uart = idx_which_uart;
+
+		return 0;
+	} else if (pdev->id < 0 || pdev->id >= UART_NR)
+		return -EINVAL;
+
+	/* init uart */
+	port = &sunplus_uart_ports[pdev->id].uport;
+	if (port->membase)
+		return -EBUSY;
+
+	memset(port, 0, sizeof(*port));
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_mem)
+		return -ENODEV;
+
+	port->dev = &pdev->dev;
+	port->mapbase = res_mem->start;
+
+	port->membase = devm_ioremap_resource(&pdev->dev, res_mem);
+	if (IS_ERR(port->membase))
+		return PTR_ERR(port->membase);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return -ENODEV;
+
+	uart_get_rs485_mode(port);

drivers/tty/serial/sunplus-uart.c line 1353

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+	sunplus_uart_ports[pdev->id].rts_gpio =
+		devm_gpiod_get(&pdev->dev, "rts", GPIOD_OUT_LOW);
+	port->rs485_config = sunplus_uart_config_rs485;
+	sunplus_uart_ports[pdev->id].rts_check_tx_empty.function = NULL;
+	sunplus_uart_ports[pdev->id].rts_delay_before_send.function = NULL;
+	sunplus_uart_ports[pdev->id].rts_delay_after_send.function = NULL;
+	if (port->rs485.flags & SER_RS485_ENABLED)
+		sunplus_uart_rs485_on(port);
+
+	sunplus_uart_ports[pdev->id].clk = devm_clk_get(&pdev->dev, NULL);

Here the same nameless clock as in the loop above is requested again. Should this be UADMA or HWUA?

drivers/tty/serial/sunplus-uart.c line 1359

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+	if (IS_ERR(sunplus_uart_ports[pdev->id].clk))
+		return PTR_ERR(sunplus_uart_ports[pdev->id].clk);
+
+	ret = clk_prepare_enable(sunplus_uart_ports[pdev->id].clk);
+	if (ret)
+		return ret;

Same comment as above. Better to request the reset control before enabling the clock, for example.

drivers/tty/serial/sunplus-uart.c line 1362

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+
+	sunplus_uart_ports[pdev->id].rstc =
+		devm_reset_control_get(&pdev->dev, NULL);

Please use devm_reset_control_get_exclusive() instead.

drivers/tty/serial/sunplus-uart.c line 1372

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+
+	if (IS_ERR(sunplus_uart_ports[pdev->id].rstc))
+		return PTR_ERR(sunplus_uart_ports[pdev->id].rstc);
+
+	ret = reset_control_deassert(sunplus_uart_ports[pdev->id].rstc);
+	if (ret)
+		return ret;
+
+	clk = sunplus_uart_ports[pdev->id].clk;
+	if (IS_ERR(clk))

This can't ever be true, the code above already returned in this case.

[...]

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+static int sunplus_uart_remove(struct platform_device *pdev)
+{
+#ifdef CONFIG_PM_RUNTIME_UART
+	if (pdev->id != 0) {
+		pm_runtime_disable(&pdev->dev);

drivers/tty/serial/sunplus-uart.c line 1451

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+		pm_runtime_set_suspended(&pdev->dev);
+	}
+#endif
+	uart_remove_one_port(&sunplus_uart_driver,
+		&sunplus_uart_ports[pdev->id].uport);
+
+	if (pdev->id < UART_NR) {
+		clk_disable_unprepare(sunplus_uart_ports[pdev->id].clk);
+		reset_control_assert(sunplus_uart_ports[pdev->id].rstc);
+	}

What about the PERI clocks? This seems to leave them enabled.

regards
Philipp

#10 lore raw

RE: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Quoted 17 lines

-----Original Message-----
From: Philipp Zabel <[email protected]>
Sent: Wednesday, November 10, 2021 5:50 PM
To: Hammer Hsieh <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Tony Huang 黃懷厚 <[email protected]>; Wells Lu 呂芳騰 <[email protected]>; Hammer Hsieh 謝宏孟 <[email protected]>
Subject: Re: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Hi,

On Wed, 2021-11-10 at 15:51 +0800, Hammer Hsieh wrote:
[...]

Quoted 17 lines

drivers/tty/serial/sunplus-uart.c

Quoted 13 lines
drivers/tty/serial/sunplus-uart.c new file +13 -0
+struct sunplus_uart_port {
+	char name[16];
+	struct uart_port uport;
+	struct sunplus_dma_info *uartdma_rx;
+	struct sunplus_dma_info *uartdma_tx;
+	struct clk *clk;
+	struct reset_control *rstc;
+	unsigned int pllsys_rate;
+	struct gpio_desc *rts_gpio;
+	struct hrtimer rts_check_tx_empty;
+	struct hrtimer rts_delay_before_send;
+	struct hrtimer rts_delay_after_send; }; struct sunplus_uart_port
+sunplus_uart_ports[UART_NR];

Does this have to be a global array? I would expect these to be allocated in the probe function, one at a time.

With console, it uses global array.
Such as:
/drivers/tty/serial/ar933x_uart.c
#ifdef CONFIG_SERIAL_AR933X_CONSOLE
ar933x_uart_port * ar933x_console_port[ ];
With normal use, it should probe once at a time.
I will think about how to modify it.

Quoted 22 lines

[...]

Quoted 21 lines
drivers/tty/serial/sunplus-uart.c new file +21 -0
+static int sunplus_uart_probe(struct platform_device *pdev) {
+	struct resource *res_mem;
+	struct uart_port *port;
+	struct clk *clk, *pllsys;
+	unsigned int pllsys_rate;
+	int ret, irq;
+	int idx_offset, idx;
+	int idx_which_uart;
+	char peri_name[16];
+
+	if (pdev->dev.of_node) {
+		pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
+		if (pdev->id < 0)
+			pdev->id = of_alias_get_id(pdev->dev.of_node, "uart");
+	}
+
+	idx_offset = -1;
+
+	if (IS_UARTDMARX_ID(pdev->id))
+		idx_offset = 0;
+	else if (IS_UARTDMATX_ID(pdev->id))
Quoted 9 lines

drivers/tty/serial/sunplus-uart.c line 1252

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+		idx_offset = UART_DMARX_NR;
+
+	/* init txdma or rxdma */
+	if (idx_offset >= 0) {
+		clk = devm_clk_get(&pdev->dev, NULL);

Should this be requested by name? Looking at the binding, this could be UADMA or HWUA?

Yes, it is better requested by name.
But , if request by name , I can't probe both dma_tx and dma_rx with one line. I will think about how to modify it.

Quoted 11 lines

drivers/tty/serial/sunplus-uart.c line 1258

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;

I suggest to move this down after all required resources are available. Otherwise you'll have to either disable the clock in the error paths, or you are left with a running clock if anything below fails.

OK, I will modify it.

Quoted 10 lines
Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+		if (idx_offset == 0)
+			idx = idx_offset + pdev->id - ID_BASE_DMARX;
+		else
+			idx = idx_offset + pdev->id - ID_BASE_DMATX;
+
+		res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		if (!res_mem)
+			return -ENODEV;
+
+		sprintf(peri_name, "PERI%d", (idx & 0x01));
Quoted 8 lines

drivers/tty/serial/sunplus-uart.c line 1275

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+
+		clk = devm_clk_get(&pdev->dev, peri_name);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		ret = clk_prepare_enable(clk);

Same as above.

OK, I will modify it.

Quoted 76 lines
Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +9 -0
+		if (ret)
+			return ret;
+
+		sunplus_uartdma[idx].addr_phy =
+			(unsigned long)(res_mem->start);
+		sunplus_uartdma[idx].membase =
+			devm_ioremap_resource(&pdev->dev, res_mem);
+
+		if (IS_ERR(sunplus_uartdma[idx].membase))

drivers/tty/serial/sunplus-uart.c

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+			return PTR_ERR(sunplus_uartdma[idx].membase);
+
+		if (IS_UARTDMARX_ID(pdev->id)) {
+			irq = platform_get_irq(pdev, 0);
+			if (irq < 0)
+				return -ENODEV;
+
+			sunplus_uartdma[idx].irq = irq;
+		} else {
+			res_mem = platform_get_resource(pdev, IORESOURCE_MEM,

1);

drivers/tty/serial/sunplus-uart.c

Quoted 11 lines
drivers/tty/serial/sunplus-uart.c new file +11 -0
+			if (!res_mem)
+				return -ENODEV;
+
+			sunplus_uartdma[idx].gdma_membase =
+				devm_ioremap_resource(&pdev->dev, res_mem);
+
+			if (IS_ERR(sunplus_uartdma[idx].gdma_membase))
+				return -EINVAL;
+		}
+
+		if (of_property_read_u32(pdev->dev.of_node, "which-uart",

&idx_which_uart) != 0) {

Quoted 43 lines
drivers/tty/serial/sunplus-uart.c new file +43 -0
+			dev_err(&pdev->dev, "\"which-uart\" is not assigned.");
+			return -EINVAL;
+		}
+
+		if (idx_which_uart >= UART_NR) {
+			dev_err(&pdev->dev, "\"which-uart\" is not valid.");
+			return -EINVAL;
+		}
+
+		sunplus_uartdma[idx].which_uart = idx_which_uart;
+
+		return 0;
+	} else if (pdev->id < 0 || pdev->id >= UART_NR)
+		return -EINVAL;
+
+	/* init uart */
+	port = &sunplus_uart_ports[pdev->id].uport;
+	if (port->membase)
+		return -EBUSY;
+
+	memset(port, 0, sizeof(*port));
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_mem)
+		return -ENODEV;
+
+	port->dev = &pdev->dev;
+	port->mapbase = res_mem->start;
+
+	port->membase = devm_ioremap_resource(&pdev->dev, res_mem);
+	if (IS_ERR(port->membase))
+		return PTR_ERR(port->membase);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return -ENODEV;
+
+	uart_get_rs485_mode(port);
+	sunplus_uart_ports[pdev->id].rts_gpio =
+		devm_gpiod_get(&pdev->dev, "rts", GPIOD_OUT_LOW);
+	port->rs485_config = sunplus_uart_config_rs485;
+	sunplus_uart_ports[pdev->id].rts_check_tx_empty.function = NULL;
+	sunplus_uart_ports[pdev->id].rts_delay_before_send.function = NULL;
Quoted 9 lines

drivers/tty/serial/sunplus-uart.c line 1353

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+	sunplus_uart_ports[pdev->id].rts_delay_after_send.function = NULL;
+	if (port->rs485.flags & SER_RS485_ENABLED)
+		sunplus_uart_rs485_on(port);
+
+	sunplus_uart_ports[pdev->id].clk = devm_clk_get(&pdev->dev, NULL);

Here the same nameless clock as in the loop above is requested again. Should this be UADMA or HWUA?

No, here should be UART clk, each uart didn't use "clock-names" , that's why we use NULL. In dts UART only use clocks=<&clkc UA0> or <&clkc UA1> or <&clkc UA2>.
We did not use "clock-names".
uart_probe( ) , first init dma , then init uart.

Quoted 10 lines

drivers/tty/serial/sunplus-uart.c line 1359

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+	if (IS_ERR(sunplus_uart_ports[pdev->id].clk))
+		return PTR_ERR(sunplus_uart_ports[pdev->id].clk);
+
+	ret = clk_prepare_enable(sunplus_uart_ports[pdev->id].clk);
+	if (ret)
+		return ret;

Same comment as above. Better to request the reset control before enabling the clock, for example.

OK, I will modify it.

Quoted 6 lines

drivers/tty/serial/sunplus-uart.c line 1362

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+
+	sunplus_uart_ports[pdev->id].rstc =
+		devm_reset_control_get(&pdev->dev, NULL);

Please use devm_reset_control_get_exclusive() instead.

OK, I will modify it.

Quoted 4 lines
Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+
+	if (IS_ERR(sunplus_uart_ports[pdev->id].rstc))
+		return PTR_ERR(sunplus_uart_ports[pdev->id].rstc);
+
Quoted 9 lines

drivers/tty/serial/sunplus-uart.c line 1372

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+	ret = reset_control_deassert(sunplus_uart_ports[pdev->id].rstc);
+	if (ret)
+		return ret;
+
+	clk = sunplus_uart_ports[pdev->id].clk;
+	if (IS_ERR(clk))

This can't ever be true, the code above already returned in this case.

Indeed, I will modify it.

Quoted 18 lines

[...]

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+static int sunplus_uart_remove(struct platform_device *pdev) { #ifdef
+CONFIG_PM_RUNTIME_UART
+	if (pdev->id != 0) {
+		pm_runtime_disable(&pdev->dev);

drivers/tty/serial/sunplus-uart.c line 1451

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+		pm_runtime_set_suspended(&pdev->dev);
+	}
+#endif
+	uart_remove_one_port(&sunplus_uart_driver,
+		&sunplus_uart_ports[pdev->id].uport);
+
+	if (pdev->id < UART_NR) {
+		clk_disable_unprepare(sunplus_uart_ports[pdev->id].clk);
+		reset_control_assert(sunplus_uart_ports[pdev->id].rstc);
+	}

What about the PERI clocks? This seems to leave them enabled.

In case of dma enable, we should consider it.
I will modify it.

Quoted 2 lines

regards
Philipp

#11 lore raw

Re: [PATCH v2 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

In reply to Hammer Hsieh
I love your patch! Yet something to improve:

Hi Hammer,

I love your patch! Yet something to improve:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on robh/for-next linux/master linus/master v5.15 next-20211112] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hammer-Hsieh/dt-bindings-serial-Add-bindings-doc-for-Sunplus-SoC-UART-Driver/20211110-165153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/bf691d823221e8ab7a6710bcf06c227fcb00ac6d
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hammer-Hsieh/dt-bindings-serial-Add-bindings-doc-for-Sunplus-SoC-UART-Driver/20211110-165153
        git checkout bf691d823221e8ab7a6710bcf06c227fcb00ac6d
        # save the attached .config to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/tty/serial/sunplus-uart.c:32:10: fatal error: dt-bindings/clock/sp-sp7021.h: No such file or directory
      32 | #include <dt-bindings/clock/sp-sp7021.h>
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.

vim +32 drivers/tty/serial/sunplus-uart.c

  > 32	#include <dt-bindings/clock/sp-sp7021.h>
    33	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw
In reply to Hammer Hsieh
Quoted 10 lines · Hammer Hsieh

This is a patch series for UART driver for Suplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART. I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

...

Quoted 2 lines
 drivers/tty/serial/sunplus-uart.c                  | 1591 ++++++++++++++++++++
 include/soc/sunplus/sp_uart.h                      |  147 ++

Sorry, but I do not believe this driver requires so many LOCs. Please, try to get it under 1000, I am pretty sure it's possible and achievable.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#13 lore raw

v3 cover Add UART driver for Suplus SP7021 SoC

In reply to hammer.hsieh

This is a patch series for UART driver for Suplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART. I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Hammer Hsieh (2):
dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver serial:sunplus-uart:Add Sunplus SoC UART Driver

 .../bindings/serial/sunplus,sp7021-uart.yaml       |  58 ++
 MAINTAINERS                                        |   7 +
 drivers/tty/serial/Kconfig                         |  23 +
 drivers/tty/serial/Makefile                        |   1 +
 drivers/tty/serial/sunplus-uart.c                  | 903 +++++++++++++++++++++
 include/soc/sunplus/sp_uart.h                      |  93 +++
 6 files changed, 1085 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
Signature · 1 line
2.7.4
author maintainer
#14 lore raw

PATCH v3 1/2 dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

Add bindings doc for Sunplus SoC UART Driver

---
Changes in v3:
- Modify yaml file based on uart driver (remove dma function).

 .../bindings/serial/sunplus,sp7021-uart.yaml       | 58 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml new file +58 -0
new file mode 100644
index 0000000..df11074
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/serial/sunplus,sp7021-uart.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Sunplus SoC SP7021 UART Controller Device Tree Bindings
+
+maintainers:
+  - Tony Huang <[email protected]>
+  - Hammer Hsieh <[email protected]>
+  - Wells Lu <[email protected]>
+
+allOf:
+  - $ref: serial.yaml#
+
+properties:
+  compatible:
+    const: sunplus,sp7021-uart
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    aliases {
+            serial0 = &uart0;
+    };
+
+    uart0: serial@9c000900 {
+        compatible = "sunplus,sp7021-uart";
+        reg = <0x9c000900 0x80>;
+        interrupt-parent = <&intc>;
+        interrupts = <53 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc 0x28>;
+        resets = <&rstc 0x18>;
+    };
+...
MAINTAINERS +5 -0
index 3b79fd4..f2ee40c 100644
@@ -17945,6 +17945,11 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS UART DRIVER
+M:	Hammer Hsieh <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
Signature · 1 line
2.7.4
maintainer Reviewed-by on v3 1/2
#15 lore raw

Re: [PATCH v3 1/2] dt-bindings:serial:Add bindings doc for Sunplus SoC UART Driver

Quoted 12 lines · Hammer Hsieh

Add bindings doc for Sunplus SoC UART Driver

---
Changes in v3:
- Modify yaml file based on uart driver (remove dma function).

 .../bindings/serial/sunplus,sp7021-uart.yaml       | 58 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
author maintainer
#16 lore raw

PATCH v3 2/2 serial:sunplus-uart:Add Sunplus SoC UART Driver

In reply to Hammer Hsieh

Add Sunplus SoC UART Driver

---
Changes in v3:
- Addressed all comments from Andy Shevchenko and Philipp Zabel.

 MAINTAINERS                       |   2 +
 drivers/tty/serial/Kconfig        |  23 +
 drivers/tty/serial/Makefile       |   1 +
 drivers/tty/serial/sunplus-uart.c | 903 ++++++++++++++++++++++++++++++++++++++
 include/soc/sunplus/sp_uart.h     |  93 ++++
 5 files changed, 1022 insertions(+)
 create mode 100644 drivers/tty/serial/sunplus-uart.c
 create mode 100644 include/soc/sunplus/sp_uart.h
MAINTAINERS +2 -0
index f2ee40c..14790a4 100644
@@ -17949,6 +17949,8 @@ SUNPLUS UART DRIVER
 M:	Hammer Hsieh <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
+F:	drivers/tty/serial/sunplus-uart.c
+F:	include/soc/sunplus/sp-uart.h
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/tty/serial/Kconfig +23 -0
index 131a6a5..319f5db 100644
@@ -1561,6 +1561,29 @@ config SERIAL_LITEUART_CONSOLE
 	  and warnings and which allows logins in single user mode).
 	  Otherwise, say 'N'.
 
+config SERIAL_SUNPLUS
+	bool "Sunplus UART support"
+	depends on OF
+	select SERIAL_CORE
+	help
+	  Select this option if you would like to use Sunplus serial port on
+	  Sunplus SoC SP7021.
+	  If you enable this option, Sunplus serial ports in the system will
+	  be registered as ttySx.
+
+config SERIAL_SUNPLUS_CONSOLE
+	bool "Console on Sunplus UART"
+	depends on SERIAL_SUNPLUS
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Select this option if you would like to use a Sunplus UART as the
+	  system console.
+	  Even if you say Y here, the currently visible virtual console
+	  (/dev/tty0) will still be used as the system console by default, but
+	  you can alter that using a kernel command line option such as
+	  "console=ttySx".
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index 7da0856..61cc8de 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_SERIAL_RDA)	+= rda-uart.o
 obj-$(CONFIG_SERIAL_MILBEAUT_USIO) += milbeaut_usio.o
 obj-$(CONFIG_SERIAL_SIFIVE)	+= sifive.o
 obj-$(CONFIG_SERIAL_LITEUART) += liteuart.o
+obj-$(CONFIG_SERIAL_SUNPLUS)	+= 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 +903 -0

903 lines not on this page · raw message

include/soc/sunplus/sp_uart.h new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
#17 lore raw

Re: [PATCH v3 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Quoted 2 lines · Hammer Hsieh

Add Sunplus SoC UART Driver

Thanks for update, my comments below.

...

Quoted 1 line
 drivers/tty/serial/sunplus-uart.c | 903 ++++++++++++++++++++++++++++++++++++++

I believe 50 LOCs easily can be removed (see below for a few examples I caught just by looking into this for less than 1 minute).

...

Quoted 1 line
 include/soc/sunplus/sp_uart.h     |  93 ++++

Why do you need this header?

...

drivers/tty/serial/Kconfig config SERIAL_LITEUART_CONSOLE · line 1565

Quoted 2 lines
drivers/tty/serial/Kconfig +2 -0
+config SERIAL_SUNPLUS
+       bool "Sunplus UART support"

No module? Why?

Quoted 1 line

+ depends on OF

No COMPILE_TEST, why?

drivers/tty/serial/Kconfig config SERIAL_LITEUART_CONSOLE · line 1572

Quoted 6 lines
drivers/tty/serial/Kconfig +6 -0
+       select SERIAL_CORE
+       help
+         Select this option if you would like to use Sunplus serial port on
+         Sunplus SoC SP7021.
+         If you enable this option, Sunplus serial ports in the system will
+         be registered as ttySx.

If it's ttySx, it most probably 8250 compatible, no?

...

Quoted 8 lines

+/*
+ * Sunplus SoC UART driver
+ *
+ * Author: Hammer Hsieh <[email protected]>
+ * Tony Huang <[email protected]>
+ * Wells Lu <[email protected]>

+ *

Redundant.

Quoted 1 line

+ */

...

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>

drivers/tty/serial/sunplus-uart.c line 27

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+#include <linux/of_platform.h>
+#include <asm/irq.h>
+#include <linux/sysrq.h>
+#include <linux/serial_core.h>
+#include <linux/clk.h>
+#include <linux/reset.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/of.h>
+#include <linux/delay.h>

Sort above alphabetically and get rid of unneeded headers.

Quoted 1 line

+#include <soc/sunplus/sp_uart.h>

...

Quoted 1 line

+#define UART_NR 5

We have this as a config option, why do you need a separate one?

...

Quoted 1 line

+static struct uart_driver sunplus_uart_driver;

Why global variables?

...

drivers/tty/serial/sunplus-uart.c line 35

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+struct sunplus_uart_port {
+       char name[16];

uart_port has a name, what is this one for?

Quoted 1 line

+ struct uart_port port;

It's better to make it first in the structure to optimize container_of() away.

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+       struct clk *clk;
+       struct reset_control *rstc;
+};

...

drivers/tty/serial/sunplus-uart.c line 54

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+static inline u32 sp_uart_line_status_tx_buf_not_full(struct uart_port *port)
+{
+       return ((readl(port->membase + SP_UART_LSR) & SP_UART_LSR_TX)
+               ? SP_UART_LSR_TX_NOT_FULL : 0);

Use temporary variables for better reading. Here and everywhere else where it's applicable.

Quoted 1 line

+}

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+       writel(mcr, port->membase + SP_UART_MCR);
+

Redundant blank line. Check everywhere you have no such waste space.

...

drivers/tty/serial/sunplus-uart.c line 153

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+static void sunplus_enable_ms(struct uart_port *port)
+{
+       /* Do nothing */
+}

Is this stub needed at all?

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+

One blank line is enough.

...

Quoted 1 line

+ if (port->cons == NULL)

Don't we have a special API to check if the port is a console or not?

Quoted 1 line

+ dev_err(port->dev, "UART%d, SP_UART_LSR_FE\n", port->line);

...

drivers/tty/serial/sunplus-uart.c line 308

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+#ifdef CONFIG_PM_RUNTIME_UART
+       if (port->line > 0) {
+               ret = pm_runtime_get_sync(port->dev);
+               if (ret < 0)
+                       goto out;
+       }
+#endif

Can we postpone implementation of it right now, please? Can you test this [1] series instead?

[1]: https://lore.kernel.org/linux-serial/[email protected]/T/#u

...

drivers/tty/serial/sunplus-uart.c line 357

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       /* Disable flow control of Tx, so that queued data can be sent out
+        * There is no way for s/w to let h/w abort in the middle of
+        * transaction.
+        * Don't reset module except it's in idle state. Otherwise, it might

the module unless
in an idle

Quoted 2 lines
(quoted diff) +2 -0
+        * cause bus to hang.
+        */

...

drivers/tty/serial/sunplus-uart.c line 382

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+       /*
+        * Send all data in Tx FIFO before changing clock source,
+        * it should be UART0 only
+        */
+       while (!(readl(port->membase + SP_UART_LSR) & SP_UART_LSR_TXE))
+               ;

We do not allow busyloops in the kernel. Consider readl_poll_timeout() or its atomic variant.

...

drivers/tty/serial/sunplus-uart.c line 389

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+       clk += baud >> 1;
+       div = clk / baud;
+       ext = div & 0x0F;
+       div = (div >> 4) - 1;
+       div_l = (div & 0xFF) | (ext << 12);
+       div_h = div >> 8;

Divisor voodoo should be explained in the comment.

...

drivers/tty/serial/sunplus-uart.c line 507

Quoted 13 lines
drivers/tty/serial/sunplus-uart.c new file +12 -0
+static void sunplus_release_port(struct uart_port *port)
+{
+}
+
+static int sunplus_request_port(struct uart_port *port)
+{
+       return 0;
+}
 
+static int sunplus_verify_port(struct uart_port *port, struct serial_struct *serial)
+{
+       return -EINVAL;
+}

Why the stubs?

...

drivers/tty/serial/sunplus-uart.c line 566

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+static inline void wait_for_xmitr(struct uart_port *port)
+{
+       while (1) {
+               if (sp_uart_line_status_tx_buf_not_full(port))
+                       break;
+       }

read_poll_timeout() or its atomic variant.

Quoted 1 line

+}

...

Quoted 1 line

+ if (pdev->dev.of_node) {

Redundant check

drivers/tty/serial/sunplus-uart.c line 651

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+               pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
+               if (pdev->id < 0)
+                       pdev->id = of_alias_get_id(pdev->dev.of_node, "uart");
+       }
 
+

Redundant blank line.

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       if (pdev->id < 0 || pdev->id >= UART_NR)
+               return -EINVAL;

...

drivers/tty/serial/sunplus-uart.c line 656

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       sup = devm_kzalloc(&pdev->dev, sizeof(struct sunplus_uart_port),
+                         GFP_KERNEL);

sizeof(*sup) and make it one line.

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       if (!sup)
+               return -ENOMEM;

...

drivers/tty/serial/sunplus-uart.c line 663

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       sup->clk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(sup->clk)) {
+               dev_err(&pdev->dev, "unable to get UART clock\n");
+               return PTR_ERR(sup->clk);

Respect deferred probe by

return dev_err_probe(...);

Quoted 1 line

+ }

...

drivers/tty/serial/sunplus-uart.c line 675

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
+       if (!res_mem)
+               return -ENODEV;
+

Redundant check, besides that...

drivers/tty/serial/sunplus-uart.c line 678

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+       port->membase = devm_ioremap_resource(&pdev->dev, res_mem);
+       if (IS_ERR(port->membase))
+               return PTR_ERR(port->membase);

...there is an API that does these two in one.

...

drivers/tty/serial/sunplus-uart.c line 687

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       port->uartclk = clk_get_rate(sup->clk);
+       if (!port->uartclk) {
+               ret = -EINVAL;
 
+               goto err_disable_clk;

Instead use devm_add_action_or_reset() as many other drivers do in the kernel.

Quoted 1 line

+ }

...

drivers/tty/serial/sunplus-uart.c line 692

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return -ENODEV;

What's wrong with the error code in the irq variable?

...

drivers/tty/serial/sunplus-uart.c line 714

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       port->private_data = container_of(&sup->port,
+               struct sunplus_uart_port, port);

What does this mean?

...

drivers/tty/serial/sunplus-uart.c line 826

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+static const struct of_device_id sp_uart_of_match[] = {
+       { .compatible = "sunplus,sp7021-uart" },
 
+       {},

No comma for terminator entries.

Quoted 1 line

+};

...

drivers/tty/serial/sunplus-uart.c line 837

Quoted 9 lines
drivers/tty/serial/sunplus-uart.c new file +8 -0
+static struct platform_driver sunplus_uart_platform_driver = {
+       .probe          = sunplus_uart_probe,
+       .remove         = sunplus_uart_remove,
+       .suspend        = sunplus_uart_suspend,
+       .resume         = sunplus_uart_resume,
+       .driver = {
+               .name   = "sunplus-uart",
 
+               .owner  = THIS_MODULE,

This is done by registration call, no?

Quoted 1 line

+ .of_match_table = of_match_ptr(sp_uart_of_match),

Effectively a warning (but you don't see it since COMPILE_TEST is missed).
Hint: drop of_match_ptr() completely.

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+#ifdef CONFIG_PM_RUNTIME_UART
+               .pm     = sunplus_uart_pm_ops,
+#endif
+       }
+};

...

drivers/tty/serial/sunplus-uart.c line 858

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       ret = platform_driver_register(&sunplus_uart_platform_driver);
 
+       if (ret != 0) {

Keep the same style over the driver.

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+               uart_unregister_driver(&sunplus_uart_driver);
+               return ret;
+       }

...

drivers/tty/serial/sunplus-uart.c line 877

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+       for (;;) {
+               status = readl(port->membase + SP_UART_LSR);
+               if ((status & SP_UART_LSR_TXE) == SP_UART_LSR_TXE)
+                       break;
+               cpu_relax();
+       }

real_poll_timeout*()

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#18 lore raw

RE: [PATCH v3 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Hi, Andy Shevchenko :

I may not fully understand all your comments. But most of them I will modify when next submit. I try to answer all your comments below.
And also have some question about some of your comments.

Thanks
Regards,
Hammer

Quoted 26 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Friday, November 19, 2021 5:35 PM
To: Hammer Hsieh <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>; Rob Herring <[email protected]>; open list:SERIAL DRIVERS <[email protected]>; devicetree <[email protected]>; Linux Kernel Mailing List <[email protected]>; Jiri Slaby <[email protected]>; Philipp Zabel <[email protected]>; Tony Huang 黃懷厚 <[email protected]>; Wells Lu 呂芳騰 <[email protected]>; Hammer Hsieh 謝宏孟 <[email protected]>
Subject: Re: [PATCH v3 2/2] serial:sunplus-uart:Add Sunplus SoC UART Driver

Quoted 2 lines · Hammer Hsieh

Add Sunplus SoC UART Driver

Thanks for update, my comments below.

...

Quoted 2 lines
 drivers/tty/serial/sunplus-uart.c | 903

++++++++++++++++++++++++++++++++++++++

Quoted 9 lines

I believe 50 LOCs easily can be removed (see below for a few examples I caught just by looking into this for less than 1 minute).

...

Quoted 1 line
 include/soc/sunplus/sp_uart.h     |  93 ++++

Why do you need this header?

Ok, will remove header file, reg define will move to sunplus-uart.c

Quoted 6 lines

...

drivers/tty/serial/Kconfig config SERIAL_LITEUART_CONSOLE · line 1565

Quoted 2 lines
drivers/tty/serial/Kconfig +2 -0
+config SERIAL_SUNPLUS
+       bool "Sunplus UART support"

No module? Why?

Will add tristate for it. I will confirm load/unload *.ko for it.

Quoted 4 lines
Quoted 2 lines

+ depends on OF

No COMPILE_TEST, why?

Will add COMPILE_TEST for it.

Quoted 10 lines

drivers/tty/serial/Kconfig config SERIAL_LITEUART_CONSOLE · line 1572

Quoted 7 lines
drivers/tty/serial/Kconfig +6 -0
+       select SERIAL_CORE
+       help
+         Select this option if you would like to use Sunplus serial port on
+         Sunplus SoC SP7021.
+         If you enable this option, Sunplus serial ports in the system will
+         be registered as ttySx.

If it's ttySx, it most probably 8250 compatible, no?

No , it is a single chip, not 8250 compatible.
I plan to use 'ttySUP' for Sunplus SoC UART.
We define PORT_SUNPLUS 123 at /include/uapi/linux/serial_core.h Is that ok?

Quoted 9 lines

...

Quoted 6 lines

+/*
+ * Sunplus SoC UART driver
+ *
+ * Author: Hammer Hsieh <[email protected]>
+ * Tony Huang <[email protected]>
+ * Wells Lu <[email protected]>

Quoted 4 lines
Quoted 1 line

+ *

Redundant.

Ok , will remove it.

Quoted 15 lines
Quoted 1 line

+ */

...

Quoted 11 lines
drivers/tty/serial/sunplus-uart.c new file +11 -0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/of_platform.h>
+#include <asm/irq.h>
+#include <linux/sysrq.h>
+#include <linux/serial_core.h>
Quoted 11 lines

drivers/tty/serial/sunplus-uart.c line 27

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+#include <linux/clk.h>
+#include <linux/reset.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/of.h>
+#include <linux/delay.h>

Sort above alphabetically and get rid of unneeded headers.

Quoted 1 line

+#include <soc/sunplus/sp_uart.h>

Ok , will do it.

Quoted 6 lines

...

Quoted 1 line

+#define UART_NR 5

We have this as a config option, why do you need a separate one?

Can I keep UART_NR in sunplus-uart.c ?
If all uart driver define CONFIG_xxx_UART_NR in Kconfig. Kconfig will get big very fast.
In sunplus-uart.c just only one line code.
In Kconfig takes 8 ~ 10 line code.

Quoted 6 lines

...

Quoted 1 line

+static struct uart_driver sunplus_uart_driver;

Why global variables?

It is define for struct console { }
I will move it to close to struct console { }

Quoted 6 lines

...

drivers/tty/serial/sunplus-uart.c line 35

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+struct sunplus_uart_port {
+       char name[16];

uart_port has a name, what is this one for?

Ok , will remove it.

Quoted 8 lines
Quoted 1 line

+ struct uart_port port;

It's better to make it first in the structure to optimize container_of() away.

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+       struct clk *clk;
+       struct reset_control *rstc;
+};

Ok, thanks for the information.

Quoted 13 lines

...

Review

Quoted 3 lines
(quoted diff) +3 -0
+static inline u32 sp_uart_line_status_tx_buf_not_full(struct
+uart_port *port) {
+       return ((readl(port->membase + SP_UART_LSR) &

SP_UART_LSR_TX)

Quoted 1 line

+ ? SP_UART_LSR_TX_NOT_FULL : 0);

Use temporary variables for better reading. Here and everywhere else where it's applicable.

Quoted 1 line

+}

Ok, will modify it.

Quoted 7 lines

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+       writel(mcr, port->membase + SP_UART_MCR);
+

Redundant blank line. Check everywhere you have no such waste space.

Ok, will remove it.

Quoted 8 lines

...

drivers/tty/serial/sunplus-uart.c line 153

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+static void sunplus_enable_ms(struct uart_port *port) {
+       /* Do nothing */
+}

Is this stub needed at all?

No, will remove it.

Quoted 7 lines

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+

One blank line is enough.

Ok, will remove it.

Quoted 6 lines

...

Quoted 1 line

+ if (port->cons == NULL)

Don't we have a special API to check if the port is a console or not?

Can you show me the API ?

Quoted 17 lines
Quoted 1 line

+ dev_err(port->dev,

"UART%d,

Quoted 1 line

+ SP_UART_LSR_FE\n", port->line);

...

drivers/tty/serial/sunplus-uart.c line 308

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+#ifdef CONFIG_PM_RUNTIME_UART
+       if (port->line > 0) {
+               ret = pm_runtime_get_sync(port->dev);
+               if (ret < 0)
+                       goto out;
+       }
+#endif

Can we postpone implementation of it right now, please? Can you test this [1] series instead?

Quoted 4 lines

[1]:
https://lore.kernel.org/linux-serial/[email protected]
om/T/#u

I don't understand what's going on this issue?

Quoted 21 lines

...

drivers/tty/serial/sunplus-uart.c

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+       /* Disable flow control of Tx, so that queued data can be sent out
+        * There is no way for s/w to let h/w abort in the middle of
+        * transaction.
+        * Don't reset module except it's in idle state. Otherwise, it
+ might

the module unless
in an idle

Quoted 2 lines
(quoted diff) +2 -0
+        * cause bus to hang.
+        */

...

drivers/tty/serial/sunplus-uart.c

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+       /*
+        * Send all data in Tx FIFO before changing clock source,
+        * it should be UART0 only
+        */
+       while (!(readl(port->membase + SP_UART_LSR) &
Quoted 6 lines

SP_UART_LSR_TXE))

Quoted 1 line

+ ;

We do not allow busyloops in the kernel. Consider readl_poll_timeout() or its atomic variant.

Ok, will modify for it.

Quoted 11 lines

...

drivers/tty/serial/sunplus-uart.c line 389

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+       clk += baud >> 1;
+       div = clk / baud;
+       ext = div & 0x0F;
+       div = (div >> 4) - 1;
+       div_l = (div & 0xFF) | (ext << 12);
+       div_h = div >> 8;

Divisor voodoo should be explained in the comment.

Ok, will add explanation for it.

Quoted 8 lines

...

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+static void sunplus_release_port(struct uart_port *port) { }
+
+static int sunplus_request_port(struct uart_port *port) {
+       return 0;
+}
Quoted 7 lines

drivers/tty/serial/sunplus-uart.c line 507

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+static int sunplus_verify_port(struct uart_port *port, struct
+serial_struct *serial) {
+       return -EINVAL;
+}

Why the stubs?

Will modify it.
Like below:
if((type!= PORT_UNKNOWN) && (type != PORT_SUNPLUS))

    return -EINVAL;

return 0;

Quoted 10 lines

...

drivers/tty/serial/sunplus-uart.c line 566

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+static inline void wait_for_xmitr(struct uart_port *port) {
+       while (1) {
+               if (sp_uart_line_status_tx_buf_not_full(port))
+                       break;
+       }

read_poll_timeout() or its atomic variant.

Ok, will modify it.

Quoted 7 lines
Quoted 1 line

+}

...

Quoted 1 line

+ if (pdev->dev.of_node) {

Redundant check

Sure, will remove it.

Quoted 10 lines

drivers/tty/serial/sunplus-uart.c

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+               pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
+               if (pdev->id < 0)
+                       pdev->id = of_alias_get_id(pdev->dev.of_node,

"uart");

drivers/tty/serial/sunplus-uart.c line 45

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       }
 
+

Redundant blank line.

Ok, will remove it.

Quoted 11 lines
Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       if (pdev->id < 0 || pdev->id >= UART_NR)
+               return -EINVAL;

...

drivers/tty/serial/sunplus-uart.c line 656

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       sup = devm_kzalloc(&pdev->dev, sizeof(struct sunplus_uart_port),
+                         GFP_KERNEL);

sizeof(*sup) and make it one line.

Ok, will modify it.

Quoted 5 lines
Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       if (!sup)
+               return -ENOMEM;

...

Quoted 9 lines

drivers/tty/serial/sunplus-uart.c line 663

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       sup->clk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(sup->clk)) {
+               dev_err(&pdev->dev, "unable to get UART clock\n");
+               return PTR_ERR(sup->clk);

Respect deferred probe by

return dev_err_probe(...);

Ok, will modify it.

Quoted 11 lines
Quoted 1 line

+ }

...

drivers/tty/serial/sunplus-uart.c line 675

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
+       if (!res_mem)
+               return -ENODEV;
+

Redundant check, besides that...

Ok, will remove it.

Quoted 8 lines
Quoted 2 lines

+ port->membase = devm_ioremap_resource(&pdev->dev,

res_mem);

drivers/tty/serial/sunplus-uart.c line 678

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       if (IS_ERR(port->membase))
+               return PTR_ERR(port->membase);

...there is an API that does these two in one.

API of_ioremap(res, offset, sizeof(xx), "xxx") can do it.
But we didn't use reg-names for it in dts.
I think it is better keep orginal platform_get_resource() + devm_ioremap_resource().

Quoted 13 lines

...

drivers/tty/serial/sunplus-uart.c line 687

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +4 -0
+       port->uartclk = clk_get_rate(sup->clk);
+       if (!port->uartclk) {
+               ret = -EINVAL;
 
+               goto err_disable_clk;

Instead use devm_add_action_or_reset() as many other drivers do in the kernel.

Quoted 1 line

+ }

Ok, will modify it.

Quoted 8 lines

...

drivers/tty/serial/sunplus-uart.c line 692

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return -ENODEV;

What's wrong with the error code in the irq variable?

Will change 'return -ENODEV' to 'return irq'.

Quoted 7 lines

...

drivers/tty/serial/sunplus-uart.c line 714

Quoted 2 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       port->private_data = container_of(&sup->port,
+               struct sunplus_uart_port, port);

What does this mean?

Previous code use it to store 'struct sunplus_uart_port' pointer, will remove it.

Quoted 9 lines

...

drivers/tty/serial/sunplus-uart.c line 826

Quoted 4 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+static const struct of_device_id sp_uart_of_match[] = {
+       { .compatible = "sunplus,sp7021-uart" },
 
+       {},

No comma for terminator entries.

Ok, will remove it.

Quoted 12 lines
Quoted 1 line

+};

...

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+static struct platform_driver sunplus_uart_platform_driver = {
+       .probe          = sunplus_uart_probe,
+       .remove         = sunplus_uart_remove,
+       .suspend        = sunplus_uart_suspend,
+       .resume         = sunplus_uart_resume,
+       .driver = {
+               .name   = "sunplus-uart",
Quoted 4 lines
Quoted 1 line

+ .owner = THIS_MODULE,

This is done by registration call, no?

Ok, will remove it.

Quoted 5 lines
Quoted 1 line

+ .of_match_table = of_match_ptr(sp_uart_of_match),

Effectively a warning (but you don't see it since COMPILE_TEST is missed).
Hint: drop of_match_ptr() completely.

Ok, thanks for the information. I will add COMPILE_TEST in Kconfig.

Quoted 8 lines
Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+#ifdef CONFIG_PM_RUNTIME_UART
+               .pm     = sunplus_uart_pm_ops,
+#endif
+       }
+};

...

Quoted 6 lines

drivers/tty/serial/sunplus-uart.c line 858

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +2 -0
+       ret = platform_driver_register(&sunplus_uart_platform_driver);
 
+       if (ret != 0) {

Keep the same style over the driver.

Ok, will modify it.

Quoted 6 lines
Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +3 -0
+               uart_unregister_driver(&sunplus_uart_driver);
+               return ret;
+       }

...

Quoted 9 lines

drivers/tty/serial/sunplus-uart.c line 877

Quoted 6 lines
drivers/tty/serial/sunplus-uart.c new file +6 -0
+       for (;;) {
+               status = readl(port->membase + SP_UART_LSR);
+               if ((status & SP_UART_LSR_TXE) == SP_UART_LSR_TXE)
+                       break;
+               cpu_relax();
+       }

real_poll_timeout*()

Ok, will modify it.

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko