Skip to contentSkip to conversation

Add Spreadtrum SoC bindings and serial driver support

PATCH In review Chunyan Zhang 5 participants 16 messages Jan 28, 2015 – Jan 30, 2015 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#1 lore raw

v10 cover Add Spreadtrum SoC bindings and serial driver support

In reply to a message not in the archive

Changes from v9:
- Added SUPPORT_SYSRQ definition for sprd serial

Changes from v8:
- Removed a few unuseful code lines.

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                   |  793 ++++++++++++++++++++
 include/uapi/linux/serial_core.h                   |    3 +
 7 files changed, 834 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 · 1 line
1.7.9.5
#2 lore raw

PATCH v10 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 · 1 line
1.7.9.5
#3 lore raw

PATCH v10 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 |  793 ++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/serial_core.h |    3 +
 4 files changed, 815 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 +793 -0

793 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 · 1 line
1.7.9.5
#4 lore raw

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

Hi,

Quoted 17 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/Kconfig       |   18 +
  drivers/tty/serial/Makefile      |    1 +
  drivers/tty/serial/sprd_serial.c |  793 ++++++++++++++++++++++++++++++++++++++
  include/uapi/linux/serial_core.h |    3 +
  4 files changed, 815 insertions(+)

create mode 100644 drivers/tty/serial/sprd_serial.c

(...)

Quoted 32 lines
drivers/tty/serial/sprd_serial.c new file +32 -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))
+		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;
+
+	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;

drivers/tty/serial/sprd_serial.c line 722

Quoted 10 lines
drivers/tty/serial/sprd_serial.c new file +10 -0
+
+	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;
+	}

This check is not required. It will be done by devm_ioremap_resource()

Quoted 6 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+	up->mapbase = res->start;
+	up->membase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(up->membase))
+		return PTR_ERR(up->membase);
+
Signature · 2 lines
Thanks,
Varka Bhadram.
#5 lore raw

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

Quoted 59 lines · Varka Bhadram

Hi,

Quoted 18 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/Kconfig       |   18 +
  drivers/tty/serial/Makefile      |    1 +
  drivers/tty/serial/sprd_serial.c |  793 
++++++++++++++++++++++++++++++++++++++
  include/uapi/linux/serial_core.h |    3 +
  4 files changed, 815 insertions(+)

create mode 100644 drivers/tty/serial/sprd_serial.c

(...)

Quoted 36 lines
drivers/tty/serial/sprd_serial.c new file +36 -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))
+        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;
+
+    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);
Quoted 10 lines

drivers/tty/serial/sprd_serial.c line 722

Quoted 6 lines
drivers/tty/serial/sprd_serial.c new file +6 -0
+
+    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+    if (!res) {
+        dev_err(&pdev->dev, "not provide mem resource\n");
+        return -ENODEV;
+    }

This check is not required. It will be done by devm_ioremap_resource()

Quoted 1 line

+ up->mapbase = res->start;

Accessing of 'res' has to be done after devm_ioremap_resource()

Quoted 6 lines
Quoted 5 lines
drivers/tty/serial/sprd_serial.c new file +4 -0
+    up->membase = devm_ioremap_resource(&pdev->dev, res);
+    if (IS_ERR(up->membase))
+        return PTR_ERR(up->membase);
+
Signature · 2 lines
Thanks,
Varka Bhadram.
#6 lore raw

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

In reply to Varka Bhadram

Hi Varka,

Quoted 58 lines · Varka Bhadram

Hi,

Quoted 17 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/Kconfig       |   18 +
  drivers/tty/serial/Makefile      |    1 +
  drivers/tty/serial/sprd_serial.c |  793 ++++++++++++++++++++++++++++++++++++++
  include/uapi/linux/serial_core.h |    3 +
  4 files changed, 815 insertions(+)

create mode 100644 drivers/tty/serial/sprd_serial.c

(...)

Quoted 36 lines
drivers/tty/serial/sprd_serial.c new file +36 -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))
+        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;
+
+    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);
Quoted 8 lines

drivers/tty/serial/sprd_serial.c line 722

Quoted 6 lines
drivers/tty/serial/sprd_serial.c new file +6 -0
+
+    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+    if (!res) {
+        dev_err(&pdev->dev, "not provide mem resource\n");
+        return -ENODEV;
+    }

This check is not required. It will be done by devm_ioremap_resource()

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Regards,
Peter Hurley

Quoted 7 lines

drivers/tty/serial/sprd_serial.c line 727

Quoted 6 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+    up->mapbase = res->start;
+    up->membase = devm_ioremap_resource(&pdev->dev, res);
+    if (IS_ERR(up->membase))
+        return PTR_ERR(up->membase);
+

--
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

#7 lore raw

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

Hi Peter,

Quoted 68 lines · Peter Hurley

Hi Varka,

Quoted 57 lines · Varka Bhadram

Hi,

Quoted 17 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/Kconfig       |   18 +
   drivers/tty/serial/Makefile      |    1 +
   drivers/tty/serial/sprd_serial.c |  793 ++++++++++++++++++++++++++++++++++++++
   include/uapi/linux/serial_core.h |    3 +
   4 files changed, 815 insertions(+)

create mode 100644 drivers/tty/serial/sprd_serial.c

(...)

Quoted 35 lines
drivers/tty/serial/sprd_serial.c new file +35 -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))
+        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;
+
+    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))
Quoted 8 lines

drivers/tty/serial/sprd_serial.c line 722

Quoted 7 lines
drivers/tty/serial/sprd_serial.c new file +7 -0
+        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;
+    }

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Check on the resource happening with evm_ioremap_resource.

Not necessary to check multiple times.

I did series for all the drivers. see [1]

[1]: https://lkml.org/lkml/2014/11/3/986 <https://lkml.org/lkml/2014/11/3/986>

Quoted 9 lines

Regards,
Peter Hurley

Quoted 6 lines
Quoted 6 lines
drivers/tty/serial/sprd_serial.c new file +5 -0
+    up->mapbase = res->start;
+    up->membase = devm_ioremap_resource(&pdev->dev, res);
+    if (IS_ERR(up->membase))
+        return PTR_ERR(up->membase);
+
Signature · 2 lines
Thanks,
Varka Bhadram.
#9 lore raw

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

In reply to Peter Hurley
Quoted 5 lines · Peter Hurley

Hi Varka,

Quoted 1 line · Varka Bhadram

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

(Adding Thierry as the author of this function.)

I believe devm_ioremap_resource() was explicitly designed to remove such error handling from drivers, and to give drivers a unified error response to such things as missing resources.

See the comments for this function in lib/devres.c.

Signature · 6 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
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
#8 lore raw

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

In reply to Varka Bhadram
Quoted 79 lines · Varka Bhadram

Hi Peter,

Quoted 68 lines · Peter Hurley

Hi Varka,

Quoted 57 lines · Varka Bhadram

Hi,

Quoted 17 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/Kconfig       |   18 +
  drivers/tty/serial/Makefile      |    1 +
  drivers/tty/serial/sprd_serial.c |  793 ++++++++++++++++++++++++++++++++++++++
  include/uapi/linux/serial_core.h |    3 +
  4 files changed, 815 insertions(+)

create mode 100644 drivers/tty/serial/sprd_serial.c

(...)

Quoted 35 lines
drivers/tty/serial/sprd_serial.c new file +35 -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))
+        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;
+
+    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))
Quoted 8 lines

drivers/tty/serial/sprd_serial.c line 722

Quoted 7 lines
drivers/tty/serial/sprd_serial.c new file +7 -0
+        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;
+    }

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Quoted 7 lines

Check on the resource happening with evm_ioremap_resource.

Not necessary to check multiple times.

I did series for all the drivers. see [1]

[1]: https://lkml.org/lkml/2014/11/3/986 <https://lkml.org/lkml/2014/11/3/986>

That's a usb series. Did you do a serial driver series I missed? I don't see anything related in Greg's tty-next tree...

Regards,
Peter Hurley

--
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

#10 lore raw

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

In reply to Russell King - ARM Linux
Quoted 14 lines · Russell King - ARM Linux
Quoted 5 lines · Peter Hurley

Hi Varka,

Quoted 1 line · Varka Bhadram

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Quoted 7 lines

(Adding Thierry as the author of this function.)

I believe devm_ioremap_resource() was explicitly designed to remove such error handling from drivers, and to give drivers a unified error response to such things as missing resources.

See the comments for this function in lib/devres.c.

Maybe the purpose would be better served by wrapping the idiom in a single function.

Regards,
Peter Hurley
--
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

#11 lore raw

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

In reply to Russell King - ARM Linux
Quoted 14 lines · Russell King - ARM Linux
Quoted 5 lines · Peter Hurley

Hi Varka,

Quoted 1 line · Varka Bhadram

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Quoted 7 lines

(Adding Thierry as the author of this function.)

I believe devm_ioremap_resource() was explicitly designed to remove such error handling from drivers, and to give drivers a unified error response to such things as missing resources.

See the comments for this function in lib/devres.c.

Right. Before the introduction of this function drivers would copy the same boilerplate but would use completely inconsistent return codes. Well, to be correct devm_request_and_ioremap() was introduced first to reduce the boilerplate, but one of the problems was that it returned a NULL pointer on failure, so it was impossible to distinguish between specific error conditions. It also had the negative side-effect of not giving drivers any directions on what to do with the NULL return value other than the example in the kerneldoc. But most people just didn't seem to look at that, so instead of using -EADDRNOTAVAIL they'd again go and do completely inconsistent things everywhere.

When we introduced devm_ioremap_resource(), the idea was to remove any of these inconsistencies once and for all. You call the function and if it fails you simply propagate the error code, so you get consistent behaviour everywhere.

If I remember correctly the error codes for the various conditions were discussed quite extensively, and what we currently have is what we got by concensus.

-ENODEV is certainly not the correct return value if a resource is not available. It translates to "no such device", but the device must clearly be there, otherwise the ->probe() shouldn't have been called. Or if it really isn't there, then you'd at least need a memory region to probe, otherwise you can't determine whether it's there or not. So from the perspective of a device driver I think a missing, or NULL, resource, is indeed an "invalid argument".

I understand that people might see some ambiguity there, and -EINVAL is certainly not a very accurate description, but such is the nature of error codes. You pick what fits best. -ENXIO and -EADDRNOTAVAIL had been under discussion as well if I remember correctly, but they both equally ambiguous. -ENODATA might have been a better fit, but that too has a different meaning in other contexts.

Besides, there's an error message that goes along with the error code return, that should remove any ambiguity for people looking at dmesg.

All of that said, the original assertion that the check is not required is still valid. We can argue at length about the specific error code but if we decide that it needs to change, then we should modify devm_ioremap_resource() rather than requiring all callers to perform the extra check again.

Thierry

#12 lore raw

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

Quoted 39 lines · Thierry Reding
Quoted 14 lines · Russell King - ARM Linux
Quoted 5 lines · Peter Hurley

Hi Varka,

Quoted 1 line · Varka Bhadram

This check is not required. It will be done by devm_ioremap_resource()

Quoted 7 lines

I disagree. devm_ioremap_resource() interprets the NULL resource as a bad parameter and returns -EINVAL which is then forwarded as the return value from the probe.

-ENODEV is the correct return value from the probe if the expected resource is not available (either because it doesn't exist or was already claimed by another driver).

Quoted 7 lines

(Adding Thierry as the author of this function.)

I believe devm_ioremap_resource() was explicitly designed to remove such error handling from drivers, and to give drivers a unified error response to such things as missing resources.

See the comments for this function in lib/devres.c.

Right. Before the introduction of this function drivers would copy the same boilerplate but would use completely inconsistent return codes. Well, to be correct devm_request_and_ioremap() was introduced first to reduce the boilerplate, but one of the problems was that it returned a NULL pointer on failure, so it was impossible to distinguish between specific error conditions. It also had the negative side-effect of not giving drivers any directions on what to do with the NULL return value other than the example in the kerneldoc. But most people just didn't seem to look at that, so instead of using -EADDRNOTAVAIL they'd again go and do completely inconsistent things everywhere.

When we introduced devm_ioremap_resource(), the idea was to remove any of these inconsistencies once and for all. You call the function and if it fails you simply propagate the error code, so you get consistent behaviour everywhere.

Quoted 7 lines

If I remember correctly the error codes for the various conditions were discussed quite extensively, and what we currently have is what we got by concensus.

-ENODEV is certainly not the correct return value if a resource is not available. It translates to "no such device", but the device must clearly be there, otherwise the ->probe() shouldn't have been called.

-ENODEV is the appropriate return from the probe(); there is no device. That returning that value doesn't make sense from devm_ioremap_resource is simply a reflection of the awkward construct.

Quoted 4 lines

Or if it really isn't there, then you'd at least need a memory region to probe, otherwise you can't determine whether it's there or not. So from the perspective of a device driver I think a missing, or NULL, resource, is indeed an "invalid argument".

Trying to argue that a missing host bus window is an "invalid argument" to probe() is just trying to make the shoe fit.

Quoted 7 lines

I understand that people might see some ambiguity there, and -EINVAL is certainly not a very accurate description, but such is the nature of error codes. You pick what fits best. -ENXIO and -EADDRNOTAVAIL had been under discussion as well if I remember correctly, but they both equally ambiguous. -ENODATA might have been a better fit, but that too has a different meaning in other contexts.

Quoted 8 lines

Besides, there's an error message that goes along with the error code return, that should remove any ambiguity for people looking at dmesg.

All of that said, the original assertion that the check is not required is still valid. We can argue at length about the specific error code but if we decide that it needs to change, then we should modify devm_ioremap_resource() rather than requiring all callers to perform the extra check again.

None of the devm_ioremap_resource() changes have been submitted for serial drivers. I see no problem with accepting the Spreadtrum driver as is, and if someone wants to do a massive changeset to rework the platform_get_resource()/devm_ioremap_resource() idiom for serial drivers for 3.21, then the Spreadtrum driver would be included then.

That said, I'd prefer to see that idiom wrapped in a single function rather than what's being suggested.

Regards,
Peter Hurley

--
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

#13 lore raw

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

Quoted 6 lines · Peter Hurley
Quoted 3 lines · Thierry Reding

-ENODEV is certainly not the correct return value if a resource is not available. It translates to "no such device", but the device must clearly be there, otherwise the ->probe() shouldn't have been called.

-ENODEV is the appropriate return from the probe(); there is no device.

No it is not. "no such device" means "the device is not present". If the device is not present, we wouldn't have a struct device associated with it.

The missing resource is an error condition: what it's saying is that the device is there, but something has failed in providing the IO regions necessary to access it. That's really something very different from "there is no device present".

Quoted 7 lines
Quoted 4 lines

Or if it really isn't there, then you'd at least need a memory region to probe, otherwise you can't determine whether it's there or not. So from the perspective of a device driver I think a missing, or NULL, resource, is indeed an "invalid argument".

Trying to argue that a missing host bus window is an "invalid argument" to probe() is just trying to make the shoe fit.

As is arguing that -ENODEV is an appropriate return value for the missing resource.

Moreover, returning -ENODEV is actually *bad* in this case - the kernel's generic probe handling does not report the failure of the driver to bind given this, so a missing resource potentially becomes a silent failure of a driver - leading users to wonder why their devices aren't found.

If we /really/ have a problem with the error code, then why not invent a new error code to cater for this condition - maybe, EBADRES (bad resource).

Quoted 10 lines
Quoted 10 lines

I understand that people might see some ambiguity there, and -EINVAL is certainly not a very accurate description, but such is the nature of error codes. You pick what fits best. -ENXIO and -EADDRNOTAVAIL had been under discussion as well if I remember correctly, but they both equally ambiguous. -ENODATA might have been a better fit, but that too has a different meaning in other contexts.

Besides, there's an error message that goes along with the error code return, that should remove any ambiguity for people looking at dmesg.

Quoted 8 lines
Quoted 5 lines

All of that said, the original assertion that the check is not required is still valid. We can argue at length about the specific error code but if we decide that it needs to change, then we should modify devm_ioremap_resource() rather than requiring all callers to perform the extra check again.

None of the devm_ioremap_resource() changes have been submitted for serial drivers.

$ grep devm_ioremap_resource drivers/tty/serial/ -r | wc -l
10

It seems that statement is false.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#14 lore raw

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

Quoted 8 lines · Russell King - ARM Linux
Quoted 6 lines · Peter Hurley
Quoted 3 lines · Thierry Reding

-ENODEV is certainly not the correct return value if a resource is not available. It translates to "no such device", but the device must clearly be there, otherwise the ->probe() shouldn't have been called.

-ENODEV is the appropriate return from the probe(); there is no device.

Quoted 8 lines

No it is not. "no such device" means "the device is not present". If the device is not present, we wouldn't have a struct device associated with it.

The missing resource is an error condition: what it's saying is that the device is there, but something has failed in providing the IO regions necessary to access it. That's really something very different from "there is no device present".

This is masking behavior changes behind what is essentially a refactor. For example, here's Felipe's changelog to omap-serial:

commit d044d2356f8dd18c755e13f34318bc03ef9c6887

Author: Felipe Balbi <[email protected]>
Date:   Wed Apr 23 09:58:33 2014 -0500

tty: serial: omap: switch over to devm_ioremap_resource

just using helper function to remove some duplicated code a bit. While at that, also move allocation of struct uart_omap_port higher in the code so that we return much earlier in case of no memory.

No mention of correcting an error return value here.

Why change the error return from probe() now?

Before you say consistency, I think you should look at the stats below. IOW, if you want to change the error code return from probe() for consistency's sake, a tree-wide patch would be the appropriate way.

Quoted 35 lines
Quoted 7 lines
Quoted 4 lines

Or if it really isn't there, then you'd at least need a memory region to probe, otherwise you can't determine whether it's there or not. So from the perspective of a device driver I think a missing, or NULL, resource, is indeed an "invalid argument".

Trying to argue that a missing host bus window is an "invalid argument" to probe() is just trying to make the shoe fit.

As is arguing that -ENODEV is an appropriate return value for the missing resource.

Moreover, returning -ENODEV is actually *bad* in this case - the kernel's generic probe handling does not report the failure of the driver to bind given this, so a missing resource potentially becomes a silent failure of a driver - leading users to wonder why their devices aren't found.

If we /really/ have a problem with the error code, then why not invent a new error code to cater for this condition - maybe, EBADRES (bad resource).

Quoted 16 lines
Quoted 15 lines

I understand that people might see some ambiguity there, and -EINVAL is certainly not a very accurate description, but such is the nature of error codes. You pick what fits best. -ENXIO and -EADDRNOTAVAIL had been under discussion as well if I remember correctly, but they both equally ambiguous. -ENODATA might have been a better fit, but that too has a different meaning in other contexts.

Besides, there's an error message that goes along with the error code return, that should remove any ambiguity for people looking at dmesg.

All of that said, the original assertion that the check is not required is still valid. We can argue at length about the specific error code but if we decide that it needs to change, then we should modify devm_ioremap_resource() rather than requiring all callers to perform the extra check again.

Quoted 5 lines
Quoted 2 lines

None of the devm_ioremap_resource() changes have been submitted for serial drivers.

$ grep devm_ioremap_resource drivers/tty/serial/ -r | wc -l
10

Ok, not 'none' but hardly tree-wide.

And of those 10 drivers now using devm_ioremap_resource(),
3 drivers still return ENODEV for a missing resource [1]. (FWIW, I wrote 'none' on the basis of a grep of devm_ioremap_resource and looking at the last one, serial-tegra.c, which has exactly the construct objected to in the Spreadtrum driver).

Another 9 drivers still use plain devm_ioremap(), even those with trivial conversions like samsung.c [2]

Of the serial drivers which use platform_get_resource(),

10 return  ENODEV
5  return  EINVAL (not including those converted to devm_ioremap_resource())
4  return  ENXIO
3  return  ENOMEM
2  return  ENOENT

1 returns EBUSY
1 returns EFAULT

So to recap, I see no reason to respin this driver submission when:
1. even drivers already using devm_ioremap_resource() aren't consistent
2. drivers which could trivially use devm_ioremap_resource, don't
3. there's no basis for requiring consistent return value _yet_
(or even what that value should be)
4. the platform_get_resource()/devm_ioremap_resource is an awkward code construct

Regards,
Peter Hurley

[1]
drivers/tty/serial/bcm63xx_uart.c- res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/tty/serial/bcm63xx_uart.c- if (!res_mem)
drivers/tty/serial/bcm63xx_uart.c- return -ENODEV;
drivers/tty/serial/bcm63xx_uart.c-
drivers/tty/serial/bcm63xx_uart.c- port->mapbase = res_mem->start;
drivers/tty/serial/bcm63xx_uart.c: port->membase = devm_ioremap_resource(&pdev->dev, res_mem);

drivers/tty/serial/vt8500_serial.c- mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/tty/serial/vt8500_serial.c- irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
drivers/tty/serial/vt8500_serial.c- if (!mmres || !irqres)
drivers/tty/serial/vt8500_serial.c- return -ENODEV;
[...]
drivers/tty/serial/vt8500_serial.c: vt8500_port->uart.membase = devm_ioremap_resource(&pdev->dev, mmres);

drivers/tty/serial/serial-tegra.c- resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/tty/serial/serial-tegra.c- if (!resource) {
drivers/tty/serial/serial-tegra.c- dev_err(&pdev->dev, "No IO memory resource\n");
drivers/tty/serial/serial-tegra.c- return -ENODEV;
drivers/tty/serial/serial-tegra.c- }
drivers/tty/serial/serial-tegra.c-
drivers/tty/serial/serial-tegra.c- u->mapbase = resource->start;
drivers/tty/serial/serial-tegra.c: u->membase = devm_ioremap_resource(&pdev->dev, resource);

[2]
drivers/tty/serial/samsung.c: res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
drivers/tty/serial/samsung.c- if (res == NULL) {
drivers/tty/serial/samsung.c- dev_err(port->dev, "failed to find memory resource for uart\n");
drivers/tty/serial/samsung.c- return -EINVAL;
drivers/tty/serial/samsung.c- }
drivers/tty/serial/samsung.c-
drivers/tty/serial/samsung.c- dbg("resource %pR)\n", res);
drivers/tty/serial/samsung.c-
drivers/tty/serial/samsung.c- port->membase = devm_ioremap(port->dev, res->start, resource_size(res));
drivers/tty/serial/samsung.c- if (!port->membase) {
drivers/tty/serial/samsung.c- dev_err(port->dev, "failed to remap controller address\n");

#15 lore raw

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

Quoted 3 lines · Peter Hurley

Before you say consistency, I think you should look at the stats below. IOW, if you want to change the error code return from probe() for consistency's sake, a tree-wide patch would be the appropriate way.

Now look outside the serial driver sub-tree.

There are 1234 instances of platform_get_resource(, IORESOURCE_MEM, ) in the drivers/ sub-tree, with 700 instances of devm_ioremap_resource() being used there. Of the devm_ioremap_resource() instances:

- 555 use platform_get_resource() in the preceding two lines - which is not enough to do anything but rely on the -EINVAL return value.
- 16 mention ENODEV in the preceding three lines.

There are 132 which use platform_get_resource() and return ENODEV within the following three lines (which may intersect with the above 16 number) and 88 which use EINVAL.

So, there are in total 643 instances where a missing resource returns EINVAL, and between 132 and 148 instances which return ENODEV.

Yes, 643 + 148 isn't 1234, but I'm not going to read through all 1234
locations just for the sake of this thread. What's clear though is that
more than 50% of sites using platform_get_resource(, IORESOURCE_MEM, ) return EINVAL for the lack of a resource.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#16 lore raw

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

Quoted 19 lines · Russell King - ARM Linux
Quoted 3 lines · Peter Hurley

Before you say consistency, I think you should look at the stats below. IOW, if you want to change the error code return from probe() for consistency's sake, a tree-wide patch would be the appropriate way.

Now look outside the serial driver sub-tree.

There are 1234 instances of platform_get_resource(, IORESOURCE_MEM, ) in the drivers/ sub-tree, with 700 instances of devm_ioremap_resource() being used there. Of the devm_ioremap_resource() instances:

- 555 use platform_get_resource() in the preceding two lines - which is not enough to do anything but rely on the -EINVAL return value.
- 16 mention ENODEV in the preceding three lines.

There are 132 which use platform_get_resource() and return ENODEV within the following three lines (which may intersect with the above 16 number) and 88 which use EINVAL.

Quoted 7 lines

So, there are in total 643 instances where a missing resource returns EINVAL, and between 132 and 148 instances which return ENODEV.

Yes, 643 + 148 isn't 1234, but I'm not going to read through all 1234
locations just for the sake of this thread. What's clear though is that
more than 50% of sites using platform_get_resource(, IORESOURCE_MEM, ) return EINVAL for the lack of a resource.

Sure, now that they're using devm_ioremap_resource(). What about before they were converted?

For example, of the 10 serial drivers now using devm_ioremap_resource(), _not 1 returned EINVAL_ prior to using devm_ioremap_resource(). And of those 10 commits, only 1 mentions changing the return codes on purpose.

In fact, all of them but one returned ENODEV.

Regards,
Peter Hurley

--
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