Skip to contentSkip to conversation

Add Spreadtrum SoC bindings and serial driver support

PATCH Superseded Chunyan Zhang 5 participants 8 messages Jan 27, 2015 1 message not in the archive

Subsystems (4)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): sc9836-serial-v8

#1 lore raw

v8 cover Add Spreadtrum SoC bindings and serial driver support

This patch-set split the last version, and addressed the review comments from last version on serial driver code.

Changes from v7:
* Addressed review comments from Peter:
- Initialized the stack local with zero in sprd_set_termios()
- Used dev_get_drvdata() to get sprd_uart_port

Changes from v6:
- Setted SPRD_TIMEOUT with 256 rather than 2048
- Used u32 instead of uint32_t
- Removed inline of handle_lsr_errors which is a single call site function
- Removed unused parameter of sprd_tx & sprd_rx
- Used spin_lock_irqsave in sprd_startup() instead of spin_lock
- Added a check for port->sysrq in sprd_console_write()
- Used a global counter as a condition of calling uart_{un}register_driver
- Added pdev->id assignment in probe()
- Setted port->flags with UPF_BOOT_AUTOCONF instead of ASYNC_BOOT_AUTOCONF

Changes from v5:
- Used Spreadtrum instead of SPRD in menus
- Changed TTY name to 'ttyS'
- Moved uart_register_driver() to probe()
- Added spinlock as needed
- Removed register states saving and restoring in suspend() and resume()

Chunyan Zhang (2):
Documentation: DT: Add bindings for Spreadtrum SoC Platform tty/serial: Add Spreadtrum sc9836-uart driver support

 Documentation/devicetree/bindings/arm/sprd.txt     |   11 +
 .../devicetree/bindings/serial/sprd-uart.txt       |    7 +
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 drivers/tty/serial/Kconfig                         |   18 +
 drivers/tty/serial/Makefile                        |    1 +
 drivers/tty/serial/sprd_serial.c                   |  797 ++++++++++++++++++++
 include/uapi/linux/serial_core.h                   |    3 +
 7 files changed, 838 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/sprd.txt
 create mode 100644 Documentation/devicetree/bindings/serial/sprd-uart.txt
 create mode 100644 drivers/tty/serial/sprd_serial.c
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH v8 1/2 Documentation: DT: Add bindings for Spreadtrum SoC Platform

Adds Spreadtrum's prefix "sprd" to vendor-prefixes file. Adds the devicetree binding documentations for Spreadtrum's sc9836-uart and SC9836 SoC based on the Sharkl64 Platform which is a 64-bit SoC Platform of Spreadtrum.

---
 Documentation/devicetree/bindings/arm/sprd.txt     |   11 +++++++++++
 .../devicetree/bindings/serial/sprd-uart.txt       |    7 +++++++
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 3 files changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/sprd.txt
 create mode 100644 Documentation/devicetree/bindings/serial/sprd-uart.txt
Documentation/devicetree/bindings/arm/sprd.txt new file +11 -0
new file mode 100644
index 0000000..31a629d
@@ -0,0 +1,11 @@
+Spreadtrum SoC Platforms Device Tree Bindings
+----------------------------------------------------
+
+Sharkl64 is a Spreadtrum's SoC Platform which is based
+on ARM 64-bit processor.
+
+SC9836 openphone board with SC9836 SoC based on the
+Sharkl64 Platform shall have the following properties.
+
+Required root node properties:
+        - compatible = "sprd,sc9836-openphone", "sprd,sc9836";
Documentation/devicetree/bindings/serial/sprd-uart.txt new file +7 -0
new file mode 100644
index 0000000..2aff0f2
@@ -0,0 +1,7 @@
+* Spreadtrum serial UART
+
+Required properties:
+- compatible: must be "sprd,sc9836-uart"
+- reg: offset and length of the register set for the device
+- interrupts: exactly one interrupt specifier
+- clocks: phandles to input clocks.
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index b1df0ad..0a8384f 100644
@@ -153,6 +153,7 @@ snps	Synopsys, Inc.
 solidrun	SolidRun
 sony	Sony Corporation
 spansion	Spansion Inc.
+sprd	Spreadtrum Communications Inc.
 st	STMicroelectronics
 ste	ST-Ericsson
 stericsson	ST-Ericsson
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH v8 2/2 tty/serial: Add Spreadtrum sc9836-uart driver support

In reply to Chunyan Zhang

Add a full sc9836-uart driver for SC9836 SoC which is based on the spreadtrum sharkl64 platform.
This driver also support earlycon.

---
 drivers/tty/serial/Kconfig       |   18 +
 drivers/tty/serial/Makefile      |    1 +
 drivers/tty/serial/sprd_serial.c |  797 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/serial_core.h |    3 +
 4 files changed, 819 insertions(+)
 create mode 100644 drivers/tty/serial/sprd_serial.c
drivers/tty/serial/Kconfig +18 -0
index c79b43c..13211f7 100644
@@ -1577,6 +1577,24 @@ config SERIAL_MEN_Z135
 	  This driver can also be build as a module. If so, the module will be called
 	  men_z135_uart.ko
 
+config SERIAL_SPRD
+	tristate "Support for Spreadtrum serial"
+	depends on ARCH_SPRD
+	select SERIAL_CORE
+	help
+	  This enables the driver for the Spreadtrum's serial.
+
+config SERIAL_SPRD_CONSOLE
+	bool "Spreadtrum UART console support"
+	depends on SERIAL_SPRD=y
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Support for early debug console using Spreadtrum's serial. This enables
+	  the console before standard serial driver is probed. This is enabled
+	  with "earlycon" on the kernel command line. The console is
+	  enabled when early_param is processed.
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index 9a548ac..4801aca 100644
@@ -93,6 +93,7 @@ obj-$(CONFIG_SERIAL_ARC)	+= arc_uart.o
 obj-$(CONFIG_SERIAL_RP2)	+= rp2.o
 obj-$(CONFIG_SERIAL_FSL_LPUART)	+= fsl_lpuart.o
 obj-$(CONFIG_SERIAL_MEN_Z135)	+= men_z135_uart.o
+obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o
 
 # GPIOLIB helpers for modem control lines
 obj-$(CONFIG_SERIAL_MCTRL_GPIO)	+= serial_mctrl_gpio.o
drivers/tty/serial/sprd_serial.c new file +797 -0

797 lines not on this page · raw message

include/uapi/linux/serial_core.h +3 -0
index c172180..7e6eb39 100644
@@ -248,4 +248,7 @@
 /* MESON */
 #define PORT_MESON	109
 
+/* SPRD SERIAL  */
+#define PORT_SPRD	110
+
 #endif /* _UAPILINUX_SERIAL_CORE_H */
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Re: [PATCH v8 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

Hi Chunyan,

Minor but important fixes below.

And for the v9 version, please only use "To:" for
"Greg Kroah-Hartman <[email protected]>"

All other recipients should only be Cc:

Regards,
Peter Hurley

Quoted 3 lines · Chunyan Zhang

Add a full sc9836-uart driver for SC9836 SoC which is based on the spreadtrum sharkl64 platform.
This driver also support earlycon.

[...]

drivers/tty/serial/sprd_serial.c line 642

Quoted 5 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+static int sprd_probe_dt_alias(int index, struct device *dev)
+{
+	struct device_node *np;
+	static bool seen_dev_with_alias;
+	static bool seen_dev_without_alias;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete these two lines; these were used for the message deleted in a previous patch version.

drivers/tty/serial/sprd_serial.c line 654

Quoted 12 lines
drivers/tty/serial/sprd_serial.c new file +12 -0
+	int ret = index;
+
+	if (!IS_ENABLED(CONFIG_OF))
+		return ret;
+
+	np = dev->of_node;
+	if (!np)
+		return ret;
+
+	ret = of_alias_get_id(np, "serial");
+	if (IS_ERR_VALUE(ret)) {
+		seen_dev_without_alias = true;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete this line.

drivers/tty/serial/sprd_serial.c line 657

Quoted 3 lines
drivers/tty/serial/sprd_serial.c new file +3 -0
+		ret = index;
+	} else {
+		seen_dev_with_alias = true;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete this line.

drivers/tty/serial/sprd_serial.c line 662

Quoted 5 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+		if (ret >= ARRAY_SIZE(sprd_port) || sprd_port[ret] != NULL) {
+			dev_warn(dev, "requested serial port %d  not available.\n", ret);
+			ret = index;
+		}
+	}

Simplify the entire "if (IS_ERR_VALUE(ret))" statement to:

	if (IS_ERR_VALUE(ret))
		ret = index;
	else if (ret >= ..................) {
		dev_warn(.....);
		ret = index;
	}
Quoted 34 lines
drivers/tty/serial/sprd_serial.c new file +34 -0
+
+	return ret;
+}
+
+static int sprd_remove(struct platform_device *dev)
+{
+	struct sprd_uart_port *sup = platform_get_drvdata(dev);
+
+	if (sup) {
+		uart_remove_one_port(&sprd_uart_driver, &sup->port);
+		sprd_port[sup->port.line] = NULL;
+		sprd_ports_num--;
+	}
+
+	if (!sprd_ports_num)
+		uart_unregister_driver(&sprd_uart_driver);
+
+	return 0;
+}
+
+static int sprd_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	struct uart_port *up;
+	struct clk *clk;
+	int irq;
+	int index;
+	int ret;
+
+	for (index = 0; index < ARRAY_SIZE(sprd_port); index++)
+		if (sprd_port[index] == NULL)
+			break;
+
+	if (index == ARRAY_SIZE(sprd_port))

drivers/tty/serial/sprd_serial.c line 706

Quoted 10 lines
drivers/tty/serial/sprd_serial.c new file +10 -0
+		return -EBUSY;
+
+	index = sprd_probe_dt_alias(index, &pdev->dev);
+
+	sprd_port[index] = devm_kzalloc(&pdev->dev,
+		sizeof(*sprd_port[index]), GFP_KERNEL);
+	if (!sprd_port[index])
+		return -ENOMEM;
+
+	pdev->id = index;
        ^^^^^^^^^^^^^^^^

delete this line.

The platform device id cannot be assigned by the driver. (This was left over from trying to fix sprd_suspend/sprd_resume but that's fixed correctly now.)

Quoted 51 lines
drivers/tty/serial/sprd_serial.c new file +51 -0
+
+	up = &sprd_port[index]->port;
+	up->dev = &pdev->dev;
+	up->line = index;
+	up->type = PORT_SPRD;
+	up->iotype = SERIAL_IO_PORT;
+	up->uartclk = SPRD_DEF_RATE;
+	up->fifosize = SPRD_FIFO_SIZE;
+	up->ops = &serial_sprd_ops;
+	up->flags = UPF_BOOT_AUTOCONF;
+
+	clk = devm_clk_get(&pdev->dev, NULL);
+	if (!IS_ERR(clk))
+		up->uartclk = clk_get_rate(clk);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "not provide mem resource\n");
+		return -ENODEV;
+	}
+	up->mapbase = res->start;
+	up->membase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(up->membase))
+		return PTR_ERR(up->membase);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "not provide irq resource\n");
+		return -ENODEV;
+	}
+	up->irq = irq;
+
+	if (!sprd_ports_num) {
+		ret = uart_register_driver(&sprd_uart_driver);
+		if (ret < 0) {
+			pr_err("Failed to register SPRD-UART driver\n");
+			return ret;
+		}
+	}
+	sprd_ports_num++;
+
+	ret = uart_add_one_port(&sprd_uart_driver, up);
+	if (ret) {
+		sprd_port[index] = NULL;
+		sprd_remove(pdev);
+	}
+
+	platform_set_drvdata(pdev, up);
+
+	return ret;
+}
reviewer
#5 lore raw

Re: [PATCH v8 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

Quoted 7 lines · Peter Hurley

Hi Chunyan,

Minor but important fixes below.

And for the v9 version, please only use "To:" for
"Greg Kroah-Hartman <[email protected]>"

Ok, thank you, I'll address your comments below and send the v9 to Greg.

Greg,
sorry, I'll send you a updated version tomorrow.

Quoted 163 lines

All other recipients should only be Cc:

Regards,
Peter Hurley

Quoted 3 lines · Chunyan Zhang

Add a full sc9836-uart driver for SC9836 SoC which is based on the spreadtrum sharkl64 platform.
This driver also support earlycon.

[...]

drivers/tty/serial/sprd_serial.c line 642

Quoted 5 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+static int sprd_probe_dt_alias(int index, struct device *dev)
+{
+     struct device_node *np;
+     static bool seen_dev_with_alias;
+     static bool seen_dev_without_alias;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete these two lines; these were used for the message deleted in a previous patch version.

drivers/tty/serial/sprd_serial.c line 654

Quoted 12 lines
drivers/tty/serial/sprd_serial.c new file +12 -0
+     int ret = index;
+
+     if (!IS_ENABLED(CONFIG_OF))
+             return ret;
+
+     np = dev->of_node;
+     if (!np)
+             return ret;
+
+     ret = of_alias_get_id(np, "serial");
+     if (IS_ERR_VALUE(ret)) {
+             seen_dev_without_alias = true;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete this line.

drivers/tty/serial/sprd_serial.c line 657

Quoted 3 lines
drivers/tty/serial/sprd_serial.c new file +3 -0
+             ret = index;
+     } else {
+             seen_dev_with_alias = true;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

delete this line.

drivers/tty/serial/sprd_serial.c line 662

Quoted 5 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+             if (ret >= ARRAY_SIZE(sprd_port) || sprd_port[ret] != NULL) {
+                     dev_warn(dev, "requested serial port %d  not available.\n", ret);
+                     ret = index;
+             }
+     }

Simplify the entire "if (IS_ERR_VALUE(ret))" statement to:

        if (IS_ERR_VALUE(ret))
                ret = index;
        else if (ret >= ..................) {
                dev_warn(.....);
                ret = index;
        }
Quoted 34 lines
drivers/tty/serial/sprd_serial.c new file +34 -0
+
+     return ret;
+}
+
+static int sprd_remove(struct platform_device *dev)
+{
+     struct sprd_uart_port *sup = platform_get_drvdata(dev);
+
+     if (sup) {
+             uart_remove_one_port(&sprd_uart_driver, &sup->port);
+             sprd_port[sup->port.line] = NULL;
+             sprd_ports_num--;
+     }
+
+     if (!sprd_ports_num)
+             uart_unregister_driver(&sprd_uart_driver);
+
+     return 0;
+}
+
+static int sprd_probe(struct platform_device *pdev)
+{
+     struct resource *res;
+     struct uart_port *up;
+     struct clk *clk;
+     int irq;
+     int index;
+     int ret;
+
+     for (index = 0; index < ARRAY_SIZE(sprd_port); index++)
+             if (sprd_port[index] == NULL)
+                     break;
+
+     if (index == ARRAY_SIZE(sprd_port))

drivers/tty/serial/sprd_serial.c line 706

Quoted 10 lines
drivers/tty/serial/sprd_serial.c new file +10 -0
+             return -EBUSY;
+
+     index = sprd_probe_dt_alias(index, &pdev->dev);
+
+     sprd_port[index] = devm_kzalloc(&pdev->dev,
+             sizeof(*sprd_port[index]), GFP_KERNEL);
+     if (!sprd_port[index])
+             return -ENOMEM;
+
+     pdev->id = index;
        ^^^^^^^^^^^^^^^^

delete this line.

The platform device id cannot be assigned by the driver. (This was left over from trying to fix sprd_suspend/sprd_resume but that's fixed correctly now.)

Quoted 51 lines
drivers/tty/serial/sprd_serial.c new file +51 -0
+
+     up = &sprd_port[index]->port;
+     up->dev = &pdev->dev;
+     up->line = index;
+     up->type = PORT_SPRD;
+     up->iotype = SERIAL_IO_PORT;
+     up->uartclk = SPRD_DEF_RATE;
+     up->fifosize = SPRD_FIFO_SIZE;
+     up->ops = &serial_sprd_ops;
+     up->flags = UPF_BOOT_AUTOCONF;
+
+     clk = devm_clk_get(&pdev->dev, NULL);
+     if (!IS_ERR(clk))
+             up->uartclk = clk_get_rate(clk);
+
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+     if (!res) {
+             dev_err(&pdev->dev, "not provide mem resource\n");
+             return -ENODEV;
+     }
+     up->mapbase = res->start;
+     up->membase = devm_ioremap_resource(&pdev->dev, res);
+     if (IS_ERR(up->membase))
+             return PTR_ERR(up->membase);
+
+     irq = platform_get_irq(pdev, 0);
+     if (irq < 0) {
+             dev_err(&pdev->dev, "not provide irq resource\n");
+             return -ENODEV;
+     }
+     up->irq = irq;
+
+     if (!sprd_ports_num) {
+             ret = uart_register_driver(&sprd_uart_driver);
+             if (ret < 0) {
+                     pr_err("Failed to register SPRD-UART driver\n");
+                     return ret;
+             }
+     }
+     sprd_ports_num++;
+
+     ret = uart_add_one_port(&sprd_uart_driver, up);
+     if (ret) {
+             sprd_port[index] = NULL;
+             sprd_remove(pdev);
+     }
+
+     platform_set_drvdata(pdev, up);
+
+     return ret;
+}
#6 lore raw
In reply to Chunyan Zhang
Quoted 8 lines · On Tuesday 27 January 2015 15:56:45 Chunyan Zhang wrote:

This patch-set split the last version, and addressed the review comments from last version on serial driver code.

Changes from v7:
* Addressed review comments from Peter:
- Initialized the stack local with zero in sprd_set_termios()
- Used dev_get_drvdata() to get sprd_uart_port

Looks good to me, but you still have too many people on 'To', so Greg might be missing that you expect him to merge it.

Greg, if there are no further comments, can you take both patches through the tty git?

Arnd

maintainer
#7 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · On Tuesday 27 January 2015 15:56:45 Chunyan Zhang wrote:

This patch-set split the last version, and addressed the review comments from last version on serial driver code.

Changes from v7:
* Addressed review comments from Peter:
- Initialized the stack local with zero in sprd_set_termios()
- Used dev_get_drvdata() to get sprd_uart_port

Quoted 5 lines

Looks good to me, but you still have too many people on 'To', so Greg might be missing that you expect him to merge it.

Greg, if there are no further comments, can you take both patches through the tty git?

Will do, thanks.

greg k-h

reviewer
#8 lore raw
Quoted 14 lines · Greg KH
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · On Tuesday 27 January 2015 15:56:45 Chunyan Zhang wrote:

This patch-set split the last version, and addressed the review comments from last version on serial driver code.

Changes from v7:
* Addressed review comments from Peter:
- Initialized the stack local with zero in sprd_set_termios()
- Used dev_get_drvdata() to get sprd_uart_port

Looks good to me, but you still have too many people on 'To', so Greg might be missing that you expect him to merge it.

Quoted 6 lines
Quoted 2 lines

Greg, if there are no further comments, can you take both patches through the tty git?

Will do, thanks.

greg k-h

To Arnd, Greg, Peter, and to all of others

thank you so much for your help.
You all gave us so many important comments and valuable suggestions these months.

Best regards,
Chunyan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html