Skip to contentSkip to conversation

serial: 8250_pnp: Support configurable reg shift property

PATCH Superseded Guanbing Huang 3 participants 9 messages Apr 9, 2024 – Apr 10, 2024

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover serial: 8250_pnp: Support configurable reg shift property

From: Guanbing Huang <[email protected]>

The 16550a serial port based on the ACPI table requires obtaining the reg-shift attribute. In the ACPI scenario, If the reg-shift property is not configured like in DTS, the 16550a serial driver cannot read or write controller registers properly during initialization.

To address the issue of configuring the reg-shift property, the __uart_read_properties() universal interface is called to implement it. Adaptation of PNP devices is done in the __uart_read_properties() function.

Guanbing Huang (3):
PNP: Add dev_is_pnp() macro
serial: port: Add support of PNP IRQ to __uart_read_properties()
serial: 8250_pnp: Support configurable reg shift property

 drivers/tty/serial/8250/8250_pnp.c | 40 +++++++++++++++++++-----------
 drivers/tty/serial/serial_port.c   |  7 +++++-
 include/linux/pnp.h                |  2 ++
 3 files changed, 33 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v6 1/3 PNP: Add dev_is_pnp() macro

From: Guanbing Huang <[email protected]>

Add dev_is_pnp() macro to determine whether the device is a PNP device.

---
v5 -> v6: fix the issue that the cover letter is not chained with the patch series v4 -> v5: change "pnp" in the commit message to uppercase

 include/linux/pnp.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/pnp.h +2 -0
index ddbe7c3ca4ce..792921c06594 100644
@@ -502,6 +502,8 @@ static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
 
 #endif /* CONFIG_PNP */
 
+#define dev_is_pnp(d) ((d)->bus == &pnp_bus_type)
+
 /**
  * module_pnp_driver() - Helper macro for registering a PnP driver
  * @__pnp_driver: pnp_driver struct
Signature · 1 line
2.17.1
#2 lore raw

PATCH v6 2/3 serial: port: Add support of PNP IRQ to __uart_read_properties()

In reply to Guanbing Huang

From: Guanbing Huang <[email protected]>

The function __uart_read_properties doesn't cover PNP devices, so add IRQ processing for PNP devices in the branch.

---
v5 -> v6: fix the issue that the cover letter is not chained with the patch series v4 -> v5: change "pnp" and "irq" in the commit message to uppercase, modify the subject
to start with "serial: port:", modify the location of the header file pnp.h

 drivers/tty/serial/serial_port.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/tty/serial/serial_port.c +6 -1
index 22b9eeb23e68..8504bae1d2c9 100644
@@ -11,6 +11,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/pnp.h>
 #include <linux/property.h>
 #include <linux/serial_core.h>
 #include <linux/spinlock.h>
@@ -221,7 +222,11 @@ static int __uart_read_properties(struct uart_port *port, bool use_defaults)
 
 	if (dev_is_platform(dev))
 		ret = platform_get_irq(to_platform_device(dev), 0);
-	else
+	else if (dev_is_pnp(dev)) {
+		ret = pnp_irq(to_pnp_dev(dev), 0);
+		if (ret < 0)
+			ret = -ENXIO;
+	} else
 		ret = fwnode_irq_get(dev_fwnode(dev), 0);
 	if (ret == -EPROBE_DEFER)
 		return ret;
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v6 2/3] serial: port: Add support of PNP IRQ to __uart_read_properties()

kernel test robot noticed the following build errors:

Hi Guanbing,

kernel test robot noticed the following build errors:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.9-rc3 next-20240409] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Guanbing-Huang/PNP-Add-dev_is_pnp-macro/20240409-154558
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link:    https://lore.kernel.org/r/e6dc33e399f119e6430bca48223cb2127930939b.1712646750.git.albanhuang%40tencent.com
patch subject: [PATCH v6 2/3] serial: port: Add support of PNP IRQ to __uart_read_properties()
config: sparc-allnoconfig (https://download.01.org/0day-ci/archive/20240410/[email protected]/config)
compiler: sparc-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240410/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

sparc-linux-ld: drivers/tty/serial/serial_port.o: in function `__uart_read_properties':
serial_port.c:(.text+0x1c4): undefined reference to `pnp_bus_type'

>> sparc-linux-ld: serial_port.c:(.text+0x1c8): undefined reference to `pnp_bus_type'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v6 2/3] serial: port: Add support of PNP IRQ to __uart_read_properties()

In reply to Guanbing Huang
kernel test robot noticed the following build errors:

Hi Guanbing,

kernel test robot noticed the following build errors:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.9-rc3 next-20240409] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Guanbing-Huang/PNP-Add-dev_is_pnp-macro/20240409-154558
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link:    https://lore.kernel.org/r/e6dc33e399f119e6430bca48223cb2127930939b.1712646750.git.albanhuang%40tencent.com
patch subject: [PATCH v6 2/3] serial: port: Add support of PNP IRQ to __uart_read_properties()
config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20240410/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240410/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

or1k-linux-ld: drivers/tty/serial/serial_port.o: in function `__uart_read_properties':

>> serial_port.c:(.text+0x230): undefined reference to `pnp_bus_type'
>> or1k-linux-ld: serial_port.c:(.text+0x234): undefined reference to `pnp_bus_type'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH v6 3/3 serial: 8250_pnp: Support configurable reg shift property

In reply to Guanbing Huang

From: Guanbing Huang <[email protected]>

The 16550a serial port based on the ACPI table requires obtaining the reg-shift attribute. In the ACPI scenario, If the reg-shift property is not configured like in DTS, the 16550a serial driver cannot read or write controller registers properly during initialization.

---
v5 -> v6: fix the issue that the cover letter is not chained with the patch series
v4 -> v5: modify to obtain the value of mapsize through the pnp_mem_len function,
add annotations for the iotype variable, delete excess uart.port.flags operation
v3 -> v4: dependent on two pre patches: "pnp: Add dev_is_pnp() macro" and
"serial: 8250_port: Add support of pnp irq to __uart_read_properties()",
the iotype is reserved, the mapsize is initialized, fix the UPF_SHARE_IRQ
flag, check for IRQ being absent
v2 -> v3: switch to use uart_read_port_properties(), change "Signed-off-by" to "Reviewed-by" and "Tested-by" v1 -> v2: change the names after "Signed off by" to the real names

 drivers/tty/serial/8250/8250_pnp.c | 40 +++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 15 deletions(-)
drivers/tty/serial/8250/8250_pnp.c +25 -15
index 1974bbadc975..8f72a7de1d1d 100644
@@ -435,6 +435,7 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 {
 	struct uart_8250_port uart, *port;
 	int ret, line, flags = dev_id->driver_data;
+	unsigned char iotype;
 
 	if (flags & UNKNOWN_DEV) {
 		ret = serial_pnp_guess_board(dev);
@@ -443,37 +444,46 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
 	}
 
 	memset(&uart, 0, sizeof(uart));
-	if (pnp_irq_valid(dev, 0))
-		uart.port.irq = pnp_irq(dev, 0);
 	if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) {
 		uart.port.iobase = pnp_port_start(dev, 2);
-		uart.port.iotype = UPIO_PORT;
+		iotype = UPIO_PORT;
 	} else if (pnp_port_valid(dev, 0)) {
 		uart.port.iobase = pnp_port_start(dev, 0);
-		uart.port.iotype = UPIO_PORT;
+		iotype = UPIO_PORT;
 	} else if (pnp_mem_valid(dev, 0)) {
 		uart.port.mapbase = pnp_mem_start(dev, 0);
-		uart.port.iotype = UPIO_MEM;
+		uart.port.mapsize = pnp_mem_len(dev, 0);
+		iotype = UPIO_MEM;
 		uart.port.flags = UPF_IOREMAP;
 	} else
 		return -ENODEV;
 
-	dev_dbg(&dev->dev,
-		 "Setup PNP port: port %#lx, mem %#llx, irq %u, type %u\n",
-		 uart.port.iobase, (unsigned long long)uart.port.mapbase,
-		 uart.port.irq, uart.port.iotype);
+	uart.port.uartclk = 1843200;
+	uart.port.dev = &dev->dev;
+	uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
+
+	ret = uart_read_port_properties(&uart.port);
+	/* no interrupt -> fall back to polling */
+	if (ret == -ENXIO)
+		ret = 0;
+	if (ret)
+		return ret;
+
+	/*
+	 * The previous call may not set iotype correctly when reg-io-width
+	 * property is absent and it doesn't support IO port resource.
+	 */
+	uart.port.iotype = iotype;
 
 	if (flags & CIR_PORT) {
 		uart.port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE;
 		uart.port.type = PORT_8250_CIR;
 	}
 
-	uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
-	if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
-		uart.port.flags |= UPF_SHARE_IRQ;
-	uart.port.uartclk = 1843200;
-	device_property_read_u32(&dev->dev, "clock-frequency", &uart.port.uartclk);
-	uart.port.dev = &dev->dev;
+	dev_dbg(&dev->dev,
+		 "Setup PNP port: port %#lx, mem %#llx, size %#llx, irq %u, type %u\n",
+		 uart.port.iobase, (unsigned long long)uart.port.mapbase,
+		 (unsigned long long)uart.port.mapsize, uart.port.irq, uart.port.iotype);
 
 	line = serial8250_register_8250_port(&uart);
 	if (line < 0 || (flags & CIR_PORT))
Signature · 1 line
2.17.1
#6 lore raw
In reply to Guanbing Huang
Quoted 10 lines · Guanbing Huang

From: Guanbing Huang <[email protected]>

The 16550a serial port based on the ACPI table requires obtaining the reg-shift attribute. In the ACPI scenario, If the reg-shift property is not configured like in DTS, the 16550a serial driver cannot read or write controller registers properly during initialization.

To address the issue of configuring the reg-shift property, the __uart_read_properties() universal interface is called to implement it. Adaptation of PNP devices is done in the __uart_read_properties() function.

You either forgot or deliberately not added my tag. Can you elaborate?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#7 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Guanbing Huang

From: Guanbing Huang <[email protected]>

The 16550a serial port based on the ACPI table requires obtaining the reg-shift attribute. In the ACPI scenario, If the reg-shift property is not configured like in DTS, the 16550a serial driver cannot read or write controller registers properly during initialization.

Quoted 4 lines
Quoted 3 lines

To address the issue of configuring the reg-shift property, the __uart_read_properties() universal interface is called to implement it. Adaptation of PNP devices is done in the __uart_read_properties() function.

You either forgot or deliberately not added my tag. Can you elaborate?

I'm very sorry, this is my first time submitting a kernel patch. My understanding

of the submission specification is not comprehensive and profound enough,

and I didn't intentionally not add tags. I hope you can forgive my operational mistake.

Should I just add a "Reviewed-by tag", or do I need any other tags? Thanks.

With Best Regards.

Quoted 1 line
#8 lore raw
Quoted 17 lines · albanhuang
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Guanbing Huang

From: Guanbing Huang <[email protected]>

The 16550a serial port based on the ACPI table requires obtaining the reg-shift attribute. In the ACPI scenario, If the reg-shift property is not configured like in DTS, the 16550a serial driver cannot read or write controller registers properly during initialization.

Quoted 4 lines
Quoted 3 lines

To address the issue of configuring the reg-shift property, the __uart_read_properties() universal interface is called to implement it. Adaptation of PNP devices is done in the __uart_read_properties() function.

You either forgot or deliberately not added my tag. Can you elaborate?

I'm very sorry, this is my first time submitting a kernel patch. My understanding

Quoted 6 lines

of the submission specification is not comprehensive and profound enough,

and I didn't intentionally not add tags. I hope you can forgive my operational mistake.

Should I just add a "Reviewed-by tag", or do I need any other tags? Thanks.

Understood. So if you are is one who is sending a new version, you should take care about any given tags (such as Reviewed-by) and carry them, in case the code is not drastically changed. I.o.w. if you don't, you have to explain why.

Anyways, it seems the patch still has a flaw as per LKP, so fix that by providing probably two macros in the pnp.h header for both cases (CONFIG_PNP=y/n), and I will review it again.

	#ifdef CONFIG_PNP
	...
	#define dev_is_pnp(...) ...
	...
	#else
	...
	#define dev_is_pnp(...)		false
	...
	#endif
Signature · 2 lines
With Best Regards,
Andy Shevchenko