mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Probst <markus.probst@posteo.de>
To: ChunAn Wu <an.wu@canonical.com>,
	linux-serial@vger.kernel.org,
	 platform-driver-x86@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	 jirislaby@kernel.org, hansg@kernel.org,
	ilpo.jarvinen@linux.intel.com,  mpearson-lenovo@squebb.ca,
	derekjohn.clark@gmail.com
Subject: Re: [PATCH v6 1/3] serdev: handle devices without an ACPI or device tree node
Date: Mon, 26 Oct 2026 13:59:51 +0000	[thread overview]
Message-ID: <75e6d86340073638d966acb85465c28e6a08ceda.camel@posteo.de> (raw)
In-Reply-To: <263a607c3602f31a3f6fdd245e3c2008cdf97abd.1792856688.git.an.wu@canonical.com>

[-- Attachment #1: Type: text/plain, Size: 17577 bytes --]

On Sun, 2026-10-25 at 10:03 +0800, ChunAn Wu wrote:
> Serdev clients instantiated by a driver have no ACPI companion and no
> device tree node. Their modalias read returns -ENODEV, their add uevent
> is suppressed, and they cannot be driver-matched, so creators force a
> bind with device_driver_attach().
> 
> Resolve both TODOs in the serdev core by modelling matching on the SPI
> bus: let the creator pass a modalias to serdev_device_add() and give
> struct serdev_device_driver an id_table. ACPI and OF are still tried
> first; clients without their own modalias keep returning -ENODEV. The
> device name, derived from the controller, is unchanged.
> 
> Split struct serdev_device_id and its defines into a new
> include/linux/device-id/serdev.h, following the pattern already used by
> the SPI and I2C buses, and wire the new ID struct up in file2alias and
> the of_table coccinelle check.
> 
> Update the existing serdev_device_add() callers to pass NULL. The two
> in-tree firmware-less clients (dell-uart-backlight, yoga-tab2-pro-1380
> fastcharger) also pass NULL here so the tree keeps building across the
> series; the two following patches switch them to a real modalias and
> drop their force_attach workarounds.
> 
> Signed-off-by: ChunAn Wu <an.wu@canonical.com>
> ---
>  MAINTAINERS                                   |  1 +
>  .../platform/x86/dell/dell-uart-backlight.c   |  2 +-
>  .../lenovo/yoga-tab2-pro-1380-fastcharger.c   |  2 +-
>  .../platform/x86/x86-android-tablets/core.c   |  2 +-
>  drivers/power/sequencing/pwrseq-pcie-m2.c     |  2 +-
>  drivers/tty/serdev/core.c                     | 62 ++++++++++++++++---
>  include/linux/device-id/serdev.h              | 19 ++++++
>  include/linux/mod_devicetable.h               |  1 +
>  include/linux/serdev.h                        | 11 +++-
>  scripts/coccinelle/misc/of_table.cocci        | 16 ++---
>  scripts/mod/devicetable-offsets.c             |  3 +
>  scripts/mod/file2alias.c                      |  9 +++
>  12 files changed, 108 insertions(+), 22 deletions(-)
>  create mode 100644 include/linux/device-id/serdev.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 917f3f72e31b..06e67aa5d9b0 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -24905,6 +24905,7 @@ L:	linux-serial@vger.kernel.org
>  S:	Maintained
>  F:	Documentation/devicetree/bindings/serial/serial.yaml
>  F:	drivers/tty/serdev/
> +F:	include/linux/device-id/serdev.h
>  F:	include/linux/serdev.h
>  F:	rust/helpers/serdev.c
>  F:	rust/kernel/serdev.rs
> diff --git a/drivers/platform/x86/dell/dell-uart-backlight.c b/drivers/platform/x86/dell/dell-uart-backlight.c
> index f323a667dc2d..f076cfac2bc5 100644
> --- a/drivers/platform/x86/dell/dell-uart-backlight.c
> +++ b/drivers/platform/x86/dell/dell-uart-backlight.c
> @@ -354,7 +354,7 @@ static int dell_uart_bl_pdev_probe(struct platform_device *pdev)
>  	if (!serdev)
>  		return -ENOMEM;
>  
> -	ret = serdev_device_add(serdev);
> +	ret = serdev_device_add(serdev, NULL);
>  	if (ret) {
>  		dev_err(&pdev->dev, "error %d adding serdev\n", ret);
>  		serdev_device_put(serdev);
> diff --git a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> index 8551ab4d2c7d..5e568fe1162d 100644
> --- a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> +++ b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> @@ -260,7 +260,7 @@ static int yt2_1380_fc_pdev_probe(struct platform_device *pdev)
>  	/* The fwnode is a managed node, so it will be auto-put on serdev_device_put() */
>  	fwnode_handle_get(dev_fwnode(&serdev->dev));
>  
> -	ret = serdev_device_add(serdev);
> +	ret = serdev_device_add(serdev, NULL);
>  	if (ret) {
>  		serdev_device_put(serdev);
>  		return dev_err_probe(&pdev->dev, ret, "adding serdev\n");
> diff --git a/drivers/platform/x86/x86-android-tablets/core.c b/drivers/platform/x86/x86-android-tablets/core.c
> index cfff7f5eac5d..853aa6ff5d50 100644
> --- a/drivers/platform/x86/x86-android-tablets/core.c
> +++ b/drivers/platform/x86/x86-android-tablets/core.c
> @@ -317,7 +317,7 @@ static __init int x86_instantiate_serdev(const struct x86_dev_info *dev_info, in
>  	ACPI_COMPANION_SET(&serdev->dev, serdev_adev);
>  	acpi_device_set_enumerated(serdev_adev);
>  
> -	ret = serdev_device_add(serdev);
> +	ret = serdev_device_add(serdev, NULL);
>  	if (ret) {
>  		dev_err(&serdev->dev, "error %d adding serdev\n", ret);
>  		serdev_device_put(serdev);
> diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
> index e42e85f47629..e0482f2ef39f 100644
> --- a/drivers/power/sequencing/pwrseq-pcie-m2.c
> +++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
> @@ -309,7 +309,7 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx,
>  	if (ret)
>  		goto err_free_serdev;
>  
> -	ret = serdev_device_add(pci_dev->serdev);
> +	ret = serdev_device_add(pci_dev->serdev, NULL);
>  	if (ret) {
>  		dev_err(dev, "Failed to add serdev for PCI device (%s): %d\n",
>  			pci_name(pdev), ret);
> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
> index 7500efcdfc21..e0517d5a48da 100644
> --- a/drivers/tty/serdev/core.c
> +++ b/drivers/tty/serdev/core.c
> @@ -29,13 +29,21 @@ static DEFINE_IDA(ctrl_ida);
>  static ssize_t modalias_show(struct device *dev,
>  			     struct device_attribute *attr, char *buf)
>  {
> +	const struct serdev_device *serdev = to_serdev_device(dev);
>  	int len;
>  
>  	len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1);
>  	if (len != -ENODEV)
>  		return len;
>  
> -	return of_device_modalias(dev, buf, PAGE_SIZE);
> +	len = of_device_modalias(dev, buf, PAGE_SIZE);
> +	if (len != -ENODEV)
> +		return len;
> +
> +	if (!serdev->modalias[0])
> +		return -ENODEV;
> +
> +	return sysfs_emit(buf, "%s%s\n", SERDEV_MODULE_PREFIX, serdev->modalias);
>  }
>  static DEVICE_ATTR_RO(modalias);
>  
> @@ -47,15 +55,22 @@ ATTRIBUTE_GROUPS(serdev_device);
>  
>  static int serdev_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
>  {
> +	const struct serdev_device *serdev = to_serdev_device(dev);
>  	int rc;
>  
> -	/* TODO: platform modalias */
> -
>  	rc = acpi_device_uevent_modalias(dev, env);
>  	if (rc != -ENODEV)
>  		return rc;
>  
> -	return of_device_uevent_modalias(dev, env);
> +	rc = of_device_uevent_modalias(dev, env);
> +	if (rc != -ENODEV)
> +		return rc;
> +
> +	if (!serdev->modalias[0])
> +		return -ENODEV;
> +
> +	return add_uevent_var(env, "MODALIAS=%s%s", SERDEV_MODULE_PREFIX,
> +			      serdev->modalias);
>  }
>  
>  static void serdev_device_release(struct device *dev)
> @@ -86,28 +101,57 @@ static const struct device_type serdev_ctrl_type = {
>  	.release	= serdev_ctrl_release,
>  };
>  
> +static const struct serdev_device_id *serdev_match_id(const struct serdev_device_id *id,
> +						      const char *modalias)
> +{
> +	if (!id || !modalias[0])
> +		return NULL;
> +
> +	while (id->name[0]) {
> +		if (!strcmp(modalias, id->name))
> +			return id;
> +		id++;
> +	}
> +
> +	return NULL;
> +}
> +
>  static int serdev_device_match(struct device *dev, const struct device_driver *drv)
>  {
> +	const struct serdev_device *serdev;
> +	const struct serdev_device_driver *sdrv;
> +
>  	if (!is_serdev_device(dev))
>  		return 0;
>  
> -	/* TODO: platform matching */
> +	serdev = to_serdev_device(dev);
> +	sdrv = to_serdev_device_driver(drv);
> +
>  	if (acpi_driver_match_device(dev, drv))
>  		return 1;
>  
> -	return of_driver_match_device(dev, drv);
> +	if (of_driver_match_device(dev, drv))
> +		return 1;
> +
> +	return !!serdev_match_id(sdrv->id_table, serdev->modalias);
>  }
>  
>  /**
>   * serdev_device_add() - add a device previously constructed via serdev_device_alloc()
>   * @serdev:	serdev_device to be added
> + * @modalias:	Driver name or alias, used to match devices which have neither
> + *		an ACPI companion nor a device tree node. NULL for devices
> + *		enumerated from firmware.
>   */
> -int serdev_device_add(struct serdev_device *serdev)
> +int serdev_device_add(struct serdev_device *serdev, const char *modalias)
>  {
>  	struct serdev_controller *ctrl = serdev->ctrl;
>  	struct device *parent = serdev->dev.parent;
>  	int err;
>  
> +	if (modalias)
> +		strscpy(serdev->modalias, modalias);
> +
>  	dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr);
>  
>  	/* Only a single slave device is currently supported. */
> @@ -553,7 +597,7 @@ static int of_serdev_register_devices(struct serdev_controller *ctrl)
>  
>  		device_set_node(&serdev->dev, of_fwnode_handle(node));
>  
> -		err = serdev_device_add(serdev);
> +		err = serdev_device_add(serdev, NULL);
>  		if (err) {
>  			dev_err(&serdev->dev,
>  				"failure adding device. status %pe\n",
> @@ -707,7 +751,7 @@ static acpi_status acpi_serdev_register_device(struct serdev_controller *ctrl,
>  	ACPI_COMPANION_SET(&serdev->dev, adev);
>  	acpi_device_set_enumerated(adev);
>  
> -	err = serdev_device_add(serdev);
> +	err = serdev_device_add(serdev, NULL);
>  	if (err) {
>  		dev_err(&serdev->dev,
>  			"failure adding ACPI serdev device. status %pe\n",
> diff --git a/include/linux/device-id/serdev.h b/include/linux/device-id/serdev.h
> new file mode 100644
> index 000000000000..96644953cece
> --- /dev/null
> +++ b/include/linux/device-id/serdev.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef LINUX_DEVICE_ID_SERDEV_H
> +#define LINUX_DEVICE_ID_SERDEV_H
> +
> +#ifdef __KERNEL__
> +typedef unsigned long kernel_ulong_t;
> +#endif
> +
> +/* serdev */
> +
> +#define SERDEV_NAME_SIZE	40
> +#define SERDEV_MODULE_PREFIX	"serial:"
> +
> +struct serdev_device_id {
> +	char name[SERDEV_NAME_SIZE];
> +	kernel_ulong_t driver_data;	/* Data private to the driver */
> +};
> +
> +#endif /* ifndef LINUX_DEVICE_ID_SERDEV_H */
> diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
> index 318c4b5c3451..4cb18c41254a 100644
> --- a/include/linux/mod_devicetable.h
> +++ b/include/linux/mod_devicetable.h
> @@ -52,6 +52,7 @@
>  #include "device-id/rpmsg.h"
>  #include "device-id/sdio.h"
>  #include "device-id/sdw.h"
> +#include "device-id/serdev.h"
>  #include "device-id/serio.h"
>  #include "device-id/slim.h"
>  #include "device-id/spi.h"
> diff --git a/include/linux/serdev.h b/include/linux/serdev.h
> index b6c3d957ec15..81528c69456a 100644
> --- a/include/linux/serdev.h
> +++ b/include/linux/serdev.h
> @@ -7,6 +7,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/device.h>
> +#include <linux/device-id/serdev.h>
>  #include <linux/iopoll.h>
>  #include <linux/uaccess.h>
>  #include <linux/termios.h>
> @@ -35,6 +36,10 @@ struct serdev_device_ops {
>   * struct serdev_device - Basic representation of an serdev device
>   * @dev:	Driver model representation of the device.
>   * @nr:		Device number on serdev bus.
> + * @modalias:	Name of the driver to use with this device, or the alias
> + *		for it. Empty for devices enumerated from firmware, which
> + *		are identified through their ACPI companion or their device
> + *		tree node instead. See serdev_device_add().
>   * @ctrl:	serdev controller managing this device.
>   * @ops:	Device operations.
>   * @write_comp:	Completion used by serdev_device_write() internally
> @@ -43,6 +48,7 @@ struct serdev_device_ops {
>  struct serdev_device {
>  	struct device dev;
>  	int nr;
> +	char modalias[SERDEV_NAME_SIZE];
>  	struct serdev_controller *ctrl;
>  	const struct serdev_device_ops *ops;
>  	struct completion write_comp;
> @@ -55,12 +61,15 @@ struct serdev_device {
>   * struct serdev_device_driver - serdev slave device driver
>   * @driver:	serdev device drivers should initialize name field of this
>   *		structure.
> + * @id_table:	List of serdev devices supported by this driver, used to
> + *		match devices which are not enumerated from firmware.
>   * @probe:	binds this driver to a serdev device.
>   * @remove:	unbinds this driver from the serdev device.
>   * @shutdown:	shut down this serdev device.
>   */
>  struct serdev_device_driver {
>  	struct device_driver driver;
> +	const struct serdev_device_id *id_table;
>  	int	(*probe)(struct serdev_device *);
>  	void	(*remove)(struct serdev_device *);
>  	void	(*shutdown)(struct serdev_device *);
> @@ -158,7 +167,7 @@ static inline void serdev_controller_put(struct serdev_controller *ctrl)
>  }
>  
>  struct serdev_device *serdev_device_alloc(struct serdev_controller *);
> -int serdev_device_add(struct serdev_device *);
> +int serdev_device_add(struct serdev_device *serdev, const char *modalias);
>  void serdev_device_remove(struct serdev_device *);
>  
>  struct serdev_controller *serdev_controller_alloc(struct device *host,
> diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
> index 17881cb0884b..3b6dc2c13703 100644
> --- a/scripts/coccinelle/misc/of_table.cocci
> +++ b/scripts/coccinelle/misc/of_table.cocci
> @@ -1,7 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
> -/// Make sure (of/i2c/platform/spi)_device_id tables are NULL terminated
> +/// Make sure (of/i2c/platform/serdev/spi)_device_id tables are NULL terminated
>  //
> -// Keywords: of_table i2c_table platform_table
> +// Keywords: of_table i2c_table platform_table serdev_table
>  // Confidence: Medium
>  // Options: --include-headers
>  
> @@ -15,14 +15,14 @@ identifier var, arr;
>  expression E;
>  @@
>  (
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  	{
>  	.var = E,
>  *	}
>  };
>  |
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  *	{ ..., E, ... },
>  };
> @@ -33,7 +33,7 @@ identifier var, arr;
>  expression E;
>  @@
>  (
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  	{
>  	.var = E,
> @@ -42,7 +42,7 @@ struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\)
>  +	{ }
>  };
>  |
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  	{ ..., E, ... },
>  +	{ },
> @@ -55,7 +55,7 @@ identifier var, arr;
>  expression E;
>  @@
>  (
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  	{
>  	.var = E,
> @@ -63,7 +63,7 @@ struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\)
>  	@p1
>  };
>  |
> -struct \(of_device_id \| i2c_device_id \| platform_device_id \| spi_device_id\) arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id \| serdev_device_id \| spi_device_id\) arr[] = {
>  	...,
>  	{ ..., E, ... }
>  	@p1
> diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
> index 1492e9fdc7cb..522bea285c7a 100644
> --- a/scripts/mod/devicetable-offsets.c
> +++ b/scripts/mod/devicetable-offsets.c
> @@ -158,6 +158,9 @@ int main(void)
>  	DEVID_FIELD(slim_device_id, manf_id);
>  	DEVID_FIELD(slim_device_id, prod_code);
>  
> +	DEVID(serdev_device_id);
> +	DEVID_FIELD(serdev_device_id, name);
> +
>  	DEVID(spi_device_id);
>  	DEVID_FIELD(spi_device_id, name);
>  
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index 980d7da456bb..552847deab94 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -886,6 +886,14 @@ static void do_slim_entry(struct module *mod, void *symval)
>  	module_alias_printf(mod, false, "slim:%x:%x:*", manf_id, prod_code);
>  }
>  
> +/* Looks like: serial:S */
> +static void do_serdev_entry(struct module *mod, void *symval)
> +{
> +	DEF_FIELD_ADDR(symval, serdev_device_id, name);
> +
> +	module_alias_printf(mod, false, SERDEV_MODULE_PREFIX "%s", *name);
> +}
> +
>  /* Looks like: spi:S */
>  static void do_spi_entry(struct module *mod, void *symval)
>  {
> @@ -1500,6 +1508,7 @@ static const struct devtable devtable[] = {
>  	{"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
>  	{"i2c", SIZE_i2c_device_id, do_i2c_entry},
>  	{"i3c", SIZE_i3c_device_id, do_i3c_entry},
> +	{"serdev", SIZE_serdev_device_id, do_serdev_entry},
>  	{"slim", SIZE_slim_device_id, do_slim_entry},
>  	{"spi", SIZE_spi_device_id, do_spi_entry},
>  	{"dmi", SIZE_dmi_system_id, do_dmi_entry},

Reviewed-by: Markus Probst <markus.probst@posteo.de>


You should add the maintainers for the modpost scripts to To/Cc.

$ ./scripts/get_maintainer.pl scripts/coccinelle/misc/of_table.cocci
scripts/mod/file2alias.c scripts/mod/devicetable-offsets.c
include/linux/mod_devicetable.h

Thanks
- Markus Probst


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]

  reply	other threads:[~2026-10-26 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  2:03 [PATCH v6 0/3] " ChunAn Wu
2026-10-25  2:03 ` [PATCH v6 1/3] " ChunAn Wu
2026-10-26 13:59   ` Markus Probst [this message]
2026-10-27 21:47     ` ChunAn Wu
2026-10-25  2:03 ` [PATCH v6 2/3] platform/x86: dell-uart-backlight: Bind through normal serdev matching ChunAn Wu
2026-10-25  2:03 ` [PATCH v6 3/3] platform/x86: lenovo-yoga-tab2-pro-1380-fastcharger: " ChunAn Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=75e6d86340073638d966acb85465c28e6a08ceda.camel@posteo.de \
    --to=markus.probst@posteo.de \
    --cc=an.wu@canonical.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®