Skip to contentSkip to conversation

Add UART driver for Suplus SP7021 SoC

PATCH Superseded Hammer Hsieh 4 participants 13 messages Jan 12, 2022 – Jan 28, 2022

Subsystems (3)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Hammer Hsieh

author maintainer
#0 lore raw

v6 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

Refer to (UART):
https://sunplus.atlassian.net/wiki/spaces/doc/pages/1873412290/13.+Universal+Asynchronous+Receiver+Transmitter+UART

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       |  56 ++
 MAINTAINERS                                        |   6 +
 drivers/tty/serial/Kconfig                         |  25 +
 drivers/tty/serial/Makefile                        |   1 +
 drivers/tty/serial/sunplus-uart.c                  | 756 +++++++++++++++++++++
 include/uapi/linux/serial_core.h                   |   3 +
 6 files changed, 847 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
 create mode 100644 drivers/tty/serial/sunplus-uart.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

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

Add bindings doc for Sunplus SoC UART Driver

---
Changes in v6:
- modify author mail match Signed-off-by.

 .../bindings/serial/sunplus,sp7021-uart.yaml       | 56 ++++++++++++++++++++++
 MAINTAINERS                                        |  5 ++
 2 files changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml
Documentation/devicetree/bindings/serial/sunplus,sp7021-uart.yaml new file +56 -0
new file mode 100644
index 0000000..894324c
@@ -0,0 +1,56 @@
+# 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:
+  - Hammer Hsieh <[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..3c1362e 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
#2 lore raw

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

In reply to Hammer Hsieh

Add Sunplus SoC UART Driver

---
Changes in v6:
- Addressed all comments from Jiri Slaby and Greg KH.

 MAINTAINERS                       |   1 +
 drivers/tty/serial/Kconfig        |  25 ++
 drivers/tty/serial/Makefile       |   1 +
 drivers/tty/serial/sunplus-uart.c | 756 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/serial_core.h  |   3 +
 5 files changed, 786 insertions(+)
 create mode 100644 drivers/tty/serial/sunplus-uart.c
MAINTAINERS +1 -0
index 3c1362e..2dc2fe6 100644
@@ -17949,6 +17949,7 @@ 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
 
 SUPERH
 M:	Yoshinori Sato <[email protected]>
drivers/tty/serial/Kconfig +25 -0
index 131a6a5..0865da3 100644
@@ -1561,6 +1561,31 @@ config SERIAL_LITEUART_CONSOLE
 	  and warnings and which allows logins in single user mode).
 	  Otherwise, say 'N'.
 
+config SERIAL_SUNPLUS
+	tristate "Sunplus UART support"
+	depends on OF || COMPILE_TEST
+	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 ttySUPx.
+	  This driver can also be built as a module. If so, the module will be
+	  called sunplus-uart.
+
+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=ttySUPx".
+
 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 +756 -0

756 lines not on this page · raw message

include/uapi/linux/serial_core.h +3 -0
index c4042dc..2dfe443 100644
@@ -274,4 +274,7 @@
 /* Freescale LINFlexD UART */
 #define PORT_LINFLEXUART	122
 
+/* Sunplus UART */
+#define PORT_SUNPLUS	123
+
 #endif /* _UAPILINUX_SERIAL_CORE_H */
Signature · 1 line
2.7.4
#3 lore raw

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

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.16] [cannot apply to next-20220112]
[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/Add-UART-driver-for-Suplus-SP7021-SoC/20220112-172542
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: nios2-randconfig-m031-20220112 (https://download.01.org/0day-ci/archive/20220112/202201121800.PmWf0zhj-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/359e5930a7804fbe8d313226cfec1ff484c16d11
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Hammer-Hsieh/Add-UART-driver-for-Suplus-SP7021-SoC/20220112-172542 git checkout 359e5930a7804fbe8d313226cfec1ff484c16d11
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/tty/serial/

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

All error/warnings (new ones prefixed by >>):

drivers/tty/serial/sunplus-uart.c: In function 'sunplus_poll_put_char':

>> drivers/tty/serial/sunplus-uart.c:430:9: error: implicit declaration of function 'wait_for_xmitr'; did you mean 'wait_on_bit'? [-Werror=implicit-function-declaration]
     430 |         wait_for_xmitr(port);
         |         ^~~~~~~~~~~~~~
         |         wait_on_bit
   drivers/tty/serial/sunplus-uart.c: In function 'sunplus_uart_probe':
>> drivers/tty/serial/sunplus-uart.c:624:40: warning: cast between incompatible function types from 'int (*)(struct reset_control *)' to 'void (*)(void *)' [-Wcast-function-type]
     624 |                                        (void(*)(void *))reset_control_assert,
         |                                        ^

At top level:
drivers/tty/serial/sunplus-uart.c:663:12: warning: 'sunplus_uart_resume' defined but not used [-Wunused-function]
663 | static int sunplus_uart_resume(struct device *dev)
| ^~~~~~~~~~~~~~~~~~~
drivers/tty/serial/sunplus-uart.c:653:12: warning: 'sunplus_uart_suspend' defined but not used [-Wunused-function]
653 | static int sunplus_uart_suspend(struct device *dev)
| ^~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

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

426
427 #ifdef CONFIG_CONSOLE_POLL
428 static void sunplus_poll_put_char(struct uart_port *port, unsigned char data)
429 {

 > 430		wait_for_xmitr(port);
   431		sp_uart_put_char(port, data);
   432	}
   433	
   434	static int sunplus_poll_get_char(struct uart_port *port)
   435	{
   436		unsigned int lsr = readl(port->membase + SUP_UART_LSR);
   437	
   438		if (!(lsr & SUP_UART_LSR_RX))
   439			return NO_POLL_CHAR;
   440	
   441		return readl(port->membase + SUP_UART_DATA);
   442	}
   443	#endif
   444	
   445	static const struct uart_ops sunplus_uart_ops = {
   446		.tx_empty	= sunplus_tx_empty,
   447		.set_mctrl	= sunplus_set_mctrl,
   448		.get_mctrl	= sunplus_get_mctrl,
   449		.stop_tx	= sunplus_stop_tx,
   450		.start_tx	= sunplus_start_tx,
   451		.stop_rx	= sunplus_stop_rx,
   452		.break_ctl	= sunplus_break_ctl,
   453		.startup	= sunplus_startup,
   454		.shutdown	= sunplus_shutdown,
   455		.set_termios	= sunplus_set_termios,
   456		.set_ldisc	= sunplus_set_ldisc,
   457		.type		= sunplus_type,
   458		.config_port	= sunplus_config_port,
   459		.verify_port	= sunplus_verify_port,
   460	#ifdef CONFIG_CONSOLE_POLL
   461		.poll_put_char	= sunplus_poll_put_char,
   462		.poll_get_char	= sunplus_poll_get_char,
   463	#endif
   464	};
   465	
   466	#ifdef CONFIG_SERIAL_SUNPLUS_CONSOLE
   467	struct sunplus_uart_port *sunplus_console_ports[SUP_UART_NR];
   468	
   469	static void wait_for_xmitr(struct uart_port *port)
   470	{
   471		unsigned int val;
   472		int ret;
   473	
   474		/* Wait while FIFO is full or timeout */
   475		ret = readl_poll_timeout_atomic(port->membase + SUP_UART_LSR, val,
   476						(val & SUP_UART_LSR_TX), 1, 10000);
   477	
   478		if (ret == -ETIMEDOUT) {
   479			dev_err(port->dev, "Timeout waiting while UART TX FULL\n");
   480			return;
   481		}
   482	}
   483	
   484	static void sunplus_uart_console_putchar(struct uart_port *port, int ch)
   485	{
   486		wait_for_xmitr(port);
   487		sp_uart_put_char(port, ch);
   488	}
   489	
   490	static void sunplus_console_write(struct console *co,
   491					  const char *s,
   492					  unsigned int count)
   493	{
   494		unsigned long flags;
   495		int locked = 1;
   496	
   497		local_irq_save(flags);
   498	
   499		if (sunplus_console_ports[co->index]->port.sysrq)
   500			locked = 0;
   501		else if (oops_in_progress)
   502			locked = spin_trylock(&sunplus_console_ports[co->index]->port.lock);
   503		else
   504			spin_lock(&sunplus_console_ports[co->index]->port.lock);
   505	
   506		uart_console_write(&sunplus_console_ports[co->index]->port, s, count,
   507				   sunplus_uart_console_putchar);
   508	
   509		if (locked)
   510			spin_unlock(&sunplus_console_ports[co->index]->port.lock);
   511	
   512		local_irq_restore(flags);
   513	}
   514	
   515	static int __init sunplus_console_setup(struct console *co, char *options)
   516	{
   517		struct sunplus_uart_port *sup;
   518		int baud = 115200;
   519		int bits = 8;
   520		int parity = 'n';
   521		int flow = 'n';
   522	
   523		if (co->index < 0 || co->index >= SUP_UART_NR)
   524			return -EINVAL;
   525	
   526		sup = sunplus_console_ports[co->index];
   527		if (!sup)
   528			return -ENODEV;
   529	
   530		if (options)
   531			uart_parse_options(options, &baud, &parity, &bits, &flow);
   532	
   533		return uart_set_options(&sup->port, co, baud, parity, bits, flow);
   534	}
   535	
   536	static struct uart_driver sunplus_uart_driver;
   537	static struct console sunplus_uart_console = {
   538		.name		= "ttySUP",
   539		.write		= sunplus_console_write,
   540		.device		= uart_console_device,
   541		.setup		= sunplus_console_setup,
   542		.flags		= CON_PRINTBUFFER,
   543		.index		= -1,
   544		.data		= &sunplus_uart_driver
   545	};
   546	
   547	static int __init sunplus_console_init(void)
   548	{
   549		register_console(&sunplus_uart_console);
   550		return 0;
   551	}
   552	console_initcall(sunplus_console_init);
   553	#endif
   554	
   555	static struct uart_driver sunplus_uart_driver = {
   556		.owner		= THIS_MODULE,
   557		.driver_name	= "sunplus_uart",
   558		.dev_name	= "ttySUP",
   559		.major		= TTY_MAJOR,
   560		.minor		= 64,
   561		.nr		= SUP_UART_NR,
   562		.cons		= NULL,
   563	};
   564	
   565	static int sunplus_uart_probe(struct platform_device *pdev)
   566	{
   567		struct sunplus_uart_port *sup;
   568		struct uart_port *port;
   569		struct resource *res;
   570		int ret, irq;
   571	
   572		pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
   573	
   574		if (pdev->id < 0 || pdev->id >= SUP_UART_NR)
   575			return -EINVAL;
   576	
   577		sup = devm_kzalloc(&pdev->dev, sizeof(*sup), GFP_KERNEL);
   578		if (!sup)
   579			return -ENOMEM;
   580	
   581		sup->clk = devm_clk_get_optional(&pdev->dev, NULL);
   582		if (IS_ERR(sup->clk))
   583			return dev_err_probe(&pdev->dev, PTR_ERR(sup->clk), "clk not found\n");
   584	
   585		ret = clk_prepare_enable(sup->clk);
   586		if (ret)
   587			return ret;
   588	
   589		ret = devm_add_action_or_reset(&pdev->dev,
   590					       (void(*)(void *))clk_disable_unprepare,
   591					       sup->clk);
   592		if (ret)
   593			return ret;
   594	
   595		sup->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
   596		if (IS_ERR(sup->rstc))
   597			return dev_err_probe(&pdev->dev, PTR_ERR(sup->rstc), "rstc not found\n");
   598	
   599		port = &sup->port;
   600	
   601		port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
   602		if (IS_ERR(port->membase))
   603			return dev_err_probe(&pdev->dev, PTR_ERR(port->membase), "membase not found\n");
   604	
   605		irq = platform_get_irq(pdev, 0);
   606		if (irq < 0)
   607			return irq;
   608	
   609		port->mapbase = res->start;
   610		port->uartclk = clk_get_rate(sup->clk);
   611		port->line = pdev->id;
   612		port->irq = irq;
   613		port->dev = &pdev->dev;
   614		port->iotype = UPIO_MEM;
   615		port->ops = &sunplus_uart_ops;
   616		port->flags = UPF_BOOT_AUTOCONF;
   617		port->fifosize = 128;
   618	
   619		ret = reset_control_deassert(sup->rstc);
   620		if (ret)
   621			return ret;
   622	
   623		ret = devm_add_action_or_reset(&pdev->dev,
 > 624					       (void(*)(void *))reset_control_assert,

625 sup->rstc);
626 if (ret)
627 return ret;
628

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

#4 lore raw

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

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

Hi Hammer,

I love your patch! Perhaps something to improve:

[auto build test WARNING on tty/tty-testing]
[also build test WARNING on robh/for-next linux/master linus/master v5.16] [cannot apply to next-20220112]
[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/Add-UART-driver-for-Suplus-SP7021-SoC/20220112-172542
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20220112/202201121943.u8vGs7ty-lkp(a)intel.com/config)
compiler: mips-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/359e5930a7804fbe8d313226cfec1ff484c16d11
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Hammer-Hsieh/Add-UART-driver-for-Suplus-SP7021-SoC/20220112-172542 git checkout 359e5930a7804fbe8d313226cfec1ff484c16d11
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash drivers/tty/serial/

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

All warnings (new ones prefixed by >>):

drivers/tty/serial/sunplus-uart.c: In function 'sunplus_poll_put_char':
drivers/tty/serial/sunplus-uart.c:430:9: error: implicit declaration of function 'wait_for_xmitr'; did you mean 'wait_on_bit'? [-Werror=implicit-function-declaration]

     430 |         wait_for_xmitr(port);
         |         ^~~~~~~~~~~~~~
         |         wait_on_bit
   drivers/tty/serial/sunplus-uart.c: At top level:
>> drivers/tty/serial/sunplus-uart.c:469:13: warning: conflicting types for 'wait_for_xmitr'; have 'void(struct uart_port *)'
     469 | static void wait_for_xmitr(struct uart_port *port)
         |             ^~~~~~~~~~~~~~
   drivers/tty/serial/sunplus-uart.c:469:13: error: static declaration of 'wait_for_xmitr' follows non-static declaration
   drivers/tty/serial/sunplus-uart.c:430:9: note: previous implicit declaration of 'wait_for_xmitr' with type 'void(struct uart_port *)'
     430 |         wait_for_xmitr(port);
         |         ^~~~~~~~~~~~~~
   drivers/tty/serial/sunplus-uart.c: In function 'sunplus_uart_probe':
   drivers/tty/serial/sunplus-uart.c:624:40: warning: cast between incompatible function types from 'int (*)(struct reset_control *)' to 'void (*)(void *)' [-Wcast-function-type]
     624 |                                        (void(*)(void *))reset_control_assert,
         |                                        ^

cc1: some warnings being treated as errors

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

468

 > 469	static void wait_for_xmitr(struct uart_port *port)

470 {
471 unsigned int val;
472 int ret;
473
474 /* Wait while FIFO is full or timeout */
475 ret = readl_poll_timeout_atomic(port->membase + SUP_UART_LSR, val,
476 (val & SUP_UART_LSR_TX), 1, 10000);
477
478 if (ret == -ETIMEDOUT) {
479 dev_err(port->dev, "Timeout waiting while UART TX FULL\n");
480 return;
481 }
482 }
483

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

maintainer
#5 lore raw

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

In reply to Hammer Hsieh

Hi,

Quoted 1 line · Hammer Hsieh

Add Sunplus SoC UART Driver

...

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +0 -0
@@ -0,0 +1,756 @@

...

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+/* Register offsets */
+#define SUP_UART_DATA			0x00
+#define SUP_UART_LSR			0x04
+#define SUP_UART_MSR			0x08
+#define SUP_UART_LCR			0x0C
+#define SUP_UART_MCR			0x10
+#define SUP_UART_DIV_L			0x14

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

Quoted 10 lines
drivers/tty/serial/sunplus-uart.c new file +10 -0
+#define SUP_UART_DIV_H			0x18
+#define SUP_UART_ISC			0x1C
+#define SUP_UART_TX_RESIDUE		0x20
+#define SUP_UART_RX_RESIDUE		0x24
+
+/* Line Status Register bits */
+#define SUP_UART_LSR_BC			BIT(5) /* break condition status */
+#define SUP_UART_LSR_FE			BIT(4) /* frame error status */
+#define SUP_UART_LSR_OE			BIT(3) /* overrun error status */
+#define SUP_UART_LSR_PE			BIT(2) /* parity error status */

I just wonder why do the HW creators feel so creative to redefine the world...

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

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+static void sunplus_shutdown(struct uart_port *port)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&port->lock, flags);
+	writel(0, port->membase + SUP_UART_ISC);
+	spin_unlock_irqrestore(&port->lock, flags);

I asked last time:
* What bus is this -- posting?

You replied:
* Here just clear interrupt.
* Not really understand your comment?

So I am asking again:
What bus is this? Isn't a posted write a problem here? I mean, shouldn't you read from the register so that the write hits the device? That depends on the bus this sits on, so just asking.

Other than that the driver looks much better now, i.e. LGTM.

thanks,

Signature · 2 lines
js
suse labs
author maintainer
#6 lore raw

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

Jiri Slaby <[email protected]> 於 2022年1月13日 週四 下午3:06寫道:

Quoted 22 lines

Hi,

Quoted 1 line · Hammer Hsieh

Add Sunplus SoC UART Driver

...

Quoted 3 lines
drivers/tty/serial/sunplus-uart.c new file +0 -0
@@ -0,0 +1,756 @@

...

Quoted 12 lines
drivers/tty/serial/sunplus-uart.c new file +12 -0
+/* Register offsets */
+#define SUP_UART_DATA                        0x00
+#define SUP_UART_LSR                 0x04
+#define SUP_UART_MSR                 0x08
+#define SUP_UART_LCR                 0x0C
+#define SUP_UART_MCR                 0x10
+#define SUP_UART_DIV_L                       0x14
+#define SUP_UART_DIV_H                       0x18
+#define SUP_UART_ISC                 0x1C
+#define SUP_UART_TX_RESIDUE          0x20
+#define SUP_UART_RX_RESIDUE          0x24
+
Quoted 9 lines

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

Quoted 5 lines
drivers/tty/serial/sunplus-uart.c new file +5 -0
+/* Line Status Register bits */
+#define SUP_UART_LSR_BC                      BIT(5) /* break condition status */
+#define SUP_UART_LSR_FE                      BIT(4) /* frame error status */
+#define SUP_UART_LSR_OE                      BIT(3) /* overrun error status */
+#define SUP_UART_LSR_PE                      BIT(2) /* parity error status */

I just wonder why do the HW creators feel so creative to redefine the world...

Our IC designer create it, I just try to make it work. Indeed, before Greg KH mentioned 8250-like, I didn't realize our uart so much like 8250.
Thanks for your review.

Quoted 11 lines

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

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+static void sunplus_shutdown(struct uart_port *port)
+{
+     unsigned long flags;
+
+     spin_lock_irqsave(&port->lock, flags);
+     writel(0, port->membase + SUP_UART_ISC);
+     spin_unlock_irqrestore(&port->lock, flags);

I asked last time:
* What bus is this -- posting?

Quoted 9 lines

You replied:
* Here just clear interrupt.
* Not really understand your comment?

So I am asking again:
What bus is this? Isn't a posted write a problem here? I mean, shouldn't you read from the register so that the write hits the device? That depends on the bus this sits on, so just asking.

Each UART has its own ISC register.
Ex.
dev/ttySUP0 base_adr = 0x9C00-0000 , isc_addr = 0x9C00-001C dev/ttySUP1 base_adr = 0x9C00-0080 , isc_addr = 0x9C00-009C dev/ttySUP2 base_adr = 0x9C00-0100 , isc_addr = 0x9C00-011C dev/ttySUP3 base_adr = 0x9C00-0180 , isc_addr = 0x9C00-019C dev/ttySUP4 base_adr = 0x9C00-0200 , isc_addr = 0x9C00-021C So sunplus_shutdown() just simply turn off its own device isc only. That's why I didn't read register value, just write 0 for it.

Quoted 6 lines

Other than that the driver looks much better now, i.e. LGTM.

thanks,
--
js
suse labs

maintainer
#7 lore raw

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

Quoted 21 lines · hammer hsieh
Quoted 11 lines

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

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+static void sunplus_shutdown(struct uart_port *port)
+{
+     unsigned long flags;
+
+     spin_lock_irqsave(&port->lock, flags);
+     writel(0, port->membase + SUP_UART_ISC);
+     spin_unlock_irqrestore(&port->lock, flags);

I asked last time:
* What bus is this -- posting?

Quoted 9 lines

You replied:
* Here just clear interrupt.
* Not really understand your comment?

So I am asking again:
What bus is this? Isn't a posted write a problem here? I mean, shouldn't you read from the register so that the write hits the device? That depends on the bus this sits on, so just asking.

Quoted 9 lines

Each UART has its own ISC register.
Ex.
dev/ttySUP0 base_adr = 0x9C00-0000 , isc_addr = 0x9C00-001C dev/ttySUP1 base_adr = 0x9C00-0080 , isc_addr = 0x9C00-009C dev/ttySUP2 base_adr = 0x9C00-0100 , isc_addr = 0x9C00-011C dev/ttySUP3 base_adr = 0x9C00-0180 , isc_addr = 0x9C00-019C dev/ttySUP4 base_adr = 0x9C00-0200 , isc_addr = 0x9C00-021C So sunplus_shutdown() just simply turn off its own device isc only. That's why I didn't read register value, just write 0 for it.

Could you explain me what posted write is and how does it not matter in this case?

thanks,

Signature · 2 lines
js
suse labs
author maintainer
#8 lore raw

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

Jiri Slaby <[email protected]> 於 2022年1月13日 週四 下午5:08寫道:

Quoted 33 lines · hammer hsieh
Quoted 21 lines
Quoted 11 lines

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

Quoted 7 lines
drivers/tty/serial/sunplus-uart.c new file +7 -0
+static void sunplus_shutdown(struct uart_port *port)
+{
+     unsigned long flags;
+
+     spin_lock_irqsave(&port->lock, flags);
+     writel(0, port->membase + SUP_UART_ISC);
+     spin_unlock_irqrestore(&port->lock, flags);

I asked last time:
* What bus is this -- posting?

Quoted 9 lines

You replied:
* Here just clear interrupt.
* Not really understand your comment?

So I am asking again:
What bus is this? Isn't a posted write a problem here? I mean, shouldn't you read from the register so that the write hits the device? That depends on the bus this sits on, so just asking.

Quoted 9 lines

Each UART has its own ISC register.
Ex.
dev/ttySUP0 base_adr = 0x9C00-0000 , isc_addr = 0x9C00-001C dev/ttySUP1 base_adr = 0x9C00-0080 , isc_addr = 0x9C00-009C dev/ttySUP2 base_adr = 0x9C00-0100 , isc_addr = 0x9C00-011C dev/ttySUP3 base_adr = 0x9C00-0180 , isc_addr = 0x9C00-019C dev/ttySUP4 base_adr = 0x9C00-0200 , isc_addr = 0x9C00-021C So sunplus_shutdown() just simply turn off its own device isc only. That's why I didn't read register value, just write 0 for it.

Quoted 3 lines

Could you explain me what posted write is and how does it not matter in this case?

Each UART ISC register contains

Bit7 MSM(Modem Status) INT enable / disable (Access type RW) not use now (0: default)
Bit6 LSM(Line Status) INT enable / disable (Access type RW) not use now(0: default)
Bit5 RXM INT enable / disable (Access type RW) set this Bit4 TXM INT enable / disable (Access type RW) set this

Bit3 MS(Modem Status) INT flag (Access type Read only) not use now (0: default) Bit2 LS(Line Status) INT flag (Access type Read only) not use now (0: default) Bit1 RX INT flag (Access type Read only) read this
Bit0 TX INT flag (Access type Read only) read this

sunplus_shutdown()
main purpose is to turn off TX INT(bit4) and RX INT(bit5) bit7 and bit6 not used, should be 0.
bit3 ~ bit0 read only, no effect while writing 0 to them.

Quoted 4 lines

thanks,
--
js
suse labs

maintainer
#9 lore raw

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

Quoted 5 lines · hammer hsieh
Quoted 3 lines

Could you explain me what posted write is and how does it not matter in this case?

Each UART ISC register contains

No, you still don't follow what I write. Use your favorite web search for "posted write" and/or consult with your HW team.

Signature · 2 lines
js
suse labs
author maintainer
#10 lore raw

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

Jiri Slaby <[email protected]> 於 2022年1月13日 週四 下午7:12寫道:

Quoted 11 lines · hammer hsieh
Quoted 5 lines
Quoted 3 lines

Could you explain me what posted write is and how does it not matter in this case?

Each UART ISC register contains

No, you still don't follow what I write. Use your favorite web search for "posted write" and/or consult with your HW team.

Maybe this time, we are on the same page.
Our SP7021 chipset is designed on ARM Cortex-A7 Quad core. Register Access through AMBA(AXI bus), and it is non-cached.

Did you mean
case1 have concern about "posted write", and you want to know why it not matter? case2 will be safer?

Case1 :
spin_lock_irq_save()
writel(0, target register)
spin_unlock_irqrestore()
Case2 :
spin_lock_irq_save()
tmp = readl(target register)
tmp &= ~(bit4 | bit5)
writel(tmp, target register)
spin_unlock_irqrestore()

I test uart port with linux-serial-test tool.
Ex. send char
linux-serial-test -y 0x55 -z 0x31 -p /dev/ttySUPx -b 115200 driver will call from uart startup till uart shutdown.
And it works fine, so I didn't think about "posted write" on Register bus.

Quoted 3 lines

--
js
suse labs

maintainer
#11 lore raw

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

Quoted 17 lines · hammer hsieh

Jiri Slaby <[email protected]> 於 2022年1月13日 週四 下午7:12寫道:

Quoted 11 lines · hammer hsieh
Quoted 5 lines
Quoted 3 lines

Could you explain me what posted write is and how does it not matter in this case?

Each UART ISC register contains

No, you still don't follow what I write. Use your favorite web search for "posted write" and/or consult with your HW team.

Maybe this time, we are on the same page.
Our SP7021 chipset is designed on ARM Cortex-A7 Quad core. Register Access through AMBA(AXI bus), and it is non-cached.

Quoted 8 lines

Did you mean
case1 have concern about "posted write", and you want to know why it not matter? case2 will be safer?

Case1 :
spin_lock_irq_save()
writel(0, target register)
spin_unlock_irqrestore()

A lock does not mean that your write made it to the device. Please talk to the hardware designers to properly determine how to correctly write to the hardware and "know" that the write succeeded or not. This driver does not seem to take that into consideration at all.

thanks,

greg k-h

author maintainer
#12 lore raw

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

Hi, Greg KH:

I review all driver again.
I think only startup and shutdown not good.
I will modify like below.
If you are ok, I will submit next patch.

static int sunplus_startup(struct uart_port *port)

{
        unsigned long flags;
        unsigned int isc;
        int ret;

        ret = request_irq(port->irq, sunplus_uart_irq, 0, "sunplus_uart", port);
        if (ret)
                return ret;

        spin_lock_irqsave(&port->lock, flags);

        isc = readl(port->membase + SUP_UART_ISC); //add this line
        isc |= SUP_UART_ISC_RXM;
        writel(isc, port->membase + SUP_UART_ISC);

        spin_unlock_irqrestore(&port->lock, flags);

        return 0;
}

static void sunplus_shutdown(struct uart_port *port)

{
        unsigned long flags;
        unsigned int isc;

        spin_lock_irqsave(&port->lock, flags);

        isc = readl(port->membase + SUP_UART_ISC); //add this line
        isc &= ~(SUP_UART_ISC_RXM | SUP_UART_ISC_TXM); //add this line
        writel(isc, port->membase + SUP_UART_ISC); //modify this line

        spin_unlock_irqrestore(&port->lock, flags);

        free_irq(port->irq, port);
}

Greg KH <[email protected]> 於 2022年1月26日 週三 下午9:47寫道:

Quoted 36 lines · hammer hsieh
Quoted 17 lines

Jiri Slaby <[email protected]> 於 2022年1月13日 週四 下午7:12寫道:

Quoted 11 lines · hammer hsieh
Quoted 5 lines
Quoted 3 lines

Could you explain me what posted write is and how does it not matter in this case?

Each UART ISC register contains

No, you still don't follow what I write. Use your favorite web search for "posted write" and/or consult with your HW team.

Maybe this time, we are on the same page.
Our SP7021 chipset is designed on ARM Cortex-A7 Quad core. Register Access through AMBA(AXI bus), and it is non-cached.

Quoted 8 lines

Did you mean
case1 have concern about "posted write", and you want to know why it not matter? case2 will be safer?

Case1 :
spin_lock_irq_save()
writel(0, target register)
spin_unlock_irqrestore()

A lock does not mean that your write made it to the device. Please talk to the hardware designers to properly determine how to correctly write to the hardware and "know" that the write succeeded or not. This driver does not seem to take that into consideration at all.

thanks,

greg k-h