From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.125.188.123 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792733254; b=fkZ+GCTuhtnsyoxgeO2gLybOCDRaXH41RItHQqb+43Z0zRLtkUoRQ5IT7jOcd9gRG8va JlHOeAZFtVATgee2e4Uw20ICTtHqtI2bOf4loDxBnB9sJTk/3c9M1mBGJhvsvo56H5Gm6 1G42mYgvZdzAGqL4+NxY1mEH9Bc37RuwICnZ1r2tdygWOSpXnwUDWfZRlODviIfbtRc4m L9Zpk+wxQcWkJWHKKZlJx6syayfgP7cJu0rqbOKhS/WAV4p0z0rk6w6hIXYtycpbWFjXg jxWv8Nm+ZU1eQ2zwARiRY3UexKPHuPJNGZESnyrHbkv8FMO3OQK7/gX3o8blgjwRY2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792733254; h=DMARC-Filter:Received:DKIM-Signature:Received: X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ZvI+4nFpN3qtyujgG6pxLsHDOXRcs/QD5if2ojDqdPs=; b=l4xKxQkL/pOomURNdxXpwNA2qfB6C5xw4sSiFTht1Fdok7xiQbSbe8eHf9UdxohgWN4b mD/d9PAQPsTVcikMonm5nQVn6jMwwgG2JrJbLfnFX5g+nqfFNqcU8Z3Nx2vehKQfuW8Ia jHhMh6Wlizyh16gninq869oAqzTztxAdrCc4PzwJkjdN9y9bt124qjawYLRKalGbQUl71 ITnBJJHB84W7rg/qi8ImX9MAkw/2uZCYxGRxtGHEqUHGC8v3OFRoP7tNm2dtSJTpDo2ib 7h1WgUzEZlTKhpFl1zW8ds7pkeijLIWtj4x0V86fbJnWeeIf49T6+ZvMsuuqeHvzT4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b="f5MUU/Pj"; arc=none smtp.remote-ip=185.125.188.123 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E982606A328 for ; Fri, 23 Oct 2026 05:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E982606A328 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key, unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=f5MUU/Pj Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7B24B4012C for ; Fri, 23 Oct 2026 05:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1792733251; bh=ZvI+4nFpN3qtyujgG6pxLsHDOXRcs/QD5if2ojDqdPs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f5MUU/PjIytUcn28K4zlfezlXbccfh4342/njYhUV5bpOdQsTNHO8GUJYhda9mFOo XhnCK6k7Dno5n5Q6YP6FRGoCoOWM0qKARMwpOlOM8sfBrdRaRJEV+DkFU+L/TPPjbf LyAmWhQvjI+seivjM48eBjVjBTNUYDJBzpN0xorYJN+53gP5as5RMxqWVf1MGReXzT zKChNY/GIi5C7oWANcEBJpcgd/ErhQkT4k4eDwgw5hOhYNzBCUN7g6ZSH8cTo0/x6l i2lBykdffzLcF3773Q1IloXUU/lPHFMxnFQj+aq6pF5x0PL/3vzELeB9ddwA+EBPG1 wyE4CYR/ohzqcffCRWAJSCftaGqxj3LrdhNpyzDekH+ggUqrmkEpB7DDC6XGOM24v9 FjBBOsTyBGQCamqsK3EVLfzaR+z3Pl6H2AjnTAXcyVX1VP3FuAL5DLvX5XhXd7vwJB GK0+XQAUcPCyJ5q/hZRhE/rqH+K2KMExQfmUBGa9yOvYDEJOj3Ra4c0od0ZRPHxvoA q4xBhg7lkLk9budoPTQWXlH6O44eST/TOW9vUAZGigqXfcYsuSWzaeR7O4191isAqv KcU6PgRaV6ofgM9TzRioW/4u2HjaCLPq6l1VQC0oxSO8oBn8uLQwvo7MLkLUTK4jDt PQRV5a9Sf0/vD1UEgw1H5Fec= Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-33bf1d17dfeso93729eec.2 for ; Thu, 22 Oct 2026 22:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792733250; x=1793338050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZvI+4nFpN3qtyujgG6pxLsHDOXRcs/QD5if2ojDqdPs=; b=JdzxGEbhDztsVR35733KfnOzjECxW1uyLsZ5kofZX2LnVSGRlit1N3OB4T/YeW/uqT Y+rj3aYnpa/R9cUTqqFgCRS2Rktg4CxTPYk24qdfHmnvKl9PgDjwaIun6PkV0cVW7Jqj f1N7Euk2imDXuh1ABOtnUEEM3fJlgPrChdIXcgjqCyivU92utRXgW5FemL0PbsrxgedD 9mAuQCpPlgum6QKD1hsCEajnNTQsOyDT0NkRkb6oPkVTxBQalgsI60BwrTyo8ua9+0XV KIiPemjRZGNuIxNN37Soi0JO7mEhSOqNQPttO6loy0Mdtfi4KBNv441EilY7WMDahfkD tHYg== X-Gm-Message-State: AFq9FYIM8mvyCgHOF0LTqXpP0ziSXDyIMJBALTrY7ErXc56nd7MNq968 g/XPCooX5xNbuAl5pT2LON3EIOV8g63yDbeBCH/+PSfObsGIbokkF4fACgjDEbCO5i+N8Iraa3u zTCCG95kM8PBcSbnq7ODlkB9UvDljZDg+jWuEpjB1xkVXixa9p4cEbU1RzK5AxtwSPhCKlF+ab6 vVnN0F+Ez54kb1Eg== X-Gm-Gg: AYBFou2xOfB2jXQvCfsEjXGQaIBqWBsgqS+/KKKkTpK4aqupRO/31qUCISkWlNaRZC0 P1y3dxg/ryFkiRIsvnPiMiS2NK4fdgfR2Xdbj1m6CRiT4yRvJgHtv409I0hAu6FPYmKvLSZQ+ea 33aVz1uhlxxWA+35GLp7ow/riwrR/k2hyh0lrgXot0h3SIwYL87yEc7XCKxENnU5CWhAMOgrJJN znMGKBcYM3FkcYrQCMzSWPAChSgxA5zsODX55o4jsFddHauAIgjWlqAkoGNpko7pIKHZYvDs6uQ tVy17E9vN6AukznGiJhFp9a5ytOPH4M5iI1Lu2AbRNufNwBM+7/YFdsHCbzziSiOG508H1LkEb8 ohvo/iztaPGb/V8tYr6RQMvVYgGbs+md5TW1KZHsuIb4JdMnNWpCmgZv2cRePA5Zvmmo/qQhAfc yC/0MHLnBGijV76ofEC+sKxwtN9rFw6w8bVF0mwmzVmLoUY1N+kj5rQeFprtClz3O+2Xted0UL2 9CbuVLrARzKDImobvw3NKC7WMB3XLbrdxgxTPUr0Ww= X-Received: by 2002:a05:693c:87d1:10b0:367:2bed:e7a5 with SMTP id 5a478bee46e88-369d978c94dmr2892081eec.2.1792733249660; Thu, 22 Oct 2026 22:27:29 -0700 (PDT) X-Received: by 2002:a05:693c:87d1:10b0:367:2bed:e7a5 with SMTP id 5a478bee46e88-369d978c94dmr2892036eec.2.1792733249175; Thu, 22 Oct 2026 22:27:29 -0700 (PDT) Received: from an-XPS-15-9520.buildd (2001-b011-2008-445c-b47a-213f-cf99-45b4.dynamic-ip6.hinet.net. [2001:b011:2008:445c:b47a:213f:cf99:45b4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369d9e1a085sm3590098eec.29.2026.10.22.22.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 22:27:28 -0700 (PDT) From: ChunAn Wu To: linux-serial@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: linux-kernel@vger.kernel.org, markus.probst@posteo.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, hansg@kernel.org, ilpo.jarvinen@linux.intel.com, mpearson-lenovo@squebb.ca, derekjohn.clark@gmail.com Subject: [PATCH v3 1/3] serdev: handle devices without an ACPI or device tree node Date: Fri, 23 Oct 2026 13:27:15 +0800 Message-Id: <20261023052717.2577234-2-an.wu@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023052717.2577234-1-an.wu@canonical.com> References: <20261023052717.2577234-1-an.wu@canonical.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: add a creator-set modalias to struct serdev_device and an id_table to struct serdev_device_driver. ACPI and OF are still tried first; clients without their own modalias keep returning -ENODEV. The device name, derived from the controller, is unchanged. Signed-off-by: ChunAn Wu --- Changes in v3: - Rename struct serdev_device::name to ::modalias; dev_name() is unchanged - Model matching on the SPI bus: add struct serdev_device_id and id_table; drop driver->name matching - Add serdev_device_set_modalias() helper and SERDEV_MODULE_PREFIX - No MODULE_DEVICE_TABLE(serdev, ...) support: both in-tree firmware-less clients are created by the same module that provides their driver, so udev has nothing to autoload Changes in v2: - Instead of silently returning success with no modalias, use a creator-supplied name as a "serial:" modalias fallback and as the matching key, so clients can bind through normal serdev matching MAINTAINERS | 1 + drivers/tty/serdev/core.c | 54 ++++++++++++++++++++++++++++---- include/linux/device-id/serdev.h | 16 ++++++++++ include/linux/serdev.h | 34 ++++++++++++++++++++ 4 files changed, 99 insertions(+), 6 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/tty/serdev/core.c b/drivers/tty/serdev/core.c index 7500efcdfc21..e178dc57d31b 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,16 +101,43 @@ 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; + if (!is_serdev_device(dev)) return 0; - /* TODO: platform matching */ 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; + + /* + * Devices which are instantiated by a driver instead of by firmware + * have no ACPI companion and no device tree node, match them by the + * modalias their creator gave them. + */ + serdev = to_serdev_device(dev); + + return !!serdev_match_id(to_serdev_device_driver(drv)->id_table, + serdev->modalias); } /** diff --git a/include/linux/device-id/serdev.h b/include/linux/device-id/serdev.h new file mode 100644 index 000000000000..1c3b03b7d501 --- /dev/null +++ b/include/linux/device-id/serdev.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_DEVICE_ID_SERDEV_H +#define LINUX_DEVICE_ID_SERDEV_H + +/* serdev */ + +/* Large enough to hold the KBUILD_MODNAME of any serdev client driver */ +#define SERDEV_NAME_SIZE 40 +#define SERDEV_MODULE_PREFIX "serial:" + +struct serdev_device_id { + char name[SERDEV_NAME_SIZE]; + unsigned long driver_data; /* Data private to the driver */ +}; + +#endif /* ifndef LINUX_DEVICE_ID_SERDEV_H */ diff --git a/include/linux/serdev.h b/include/linux/serdev.h index b6c3d957ec15..9f91aa3e875d 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -7,7 +7,9 @@ #include #include +#include #include +#include #include #include #include @@ -35,6 +37,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_set_modalias(). * @ctrl: serdev controller managing this device. * @ops: Device operations. * @write_comp: Completion used by serdev_device_write() internally @@ -43,6 +49,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; @@ -58,12 +65,15 @@ struct serdev_device { * @probe: binds this driver to a serdev device. * @remove: unbinds this driver from the serdev device. * @shutdown: shut down this serdev device. + * @id_table: List of serdev devices supported by this driver, used to + * match devices which are not enumerated from firmware. */ struct serdev_device_driver { struct device_driver driver; int (*probe)(struct serdev_device *); void (*remove)(struct serdev_device *); void (*shutdown)(struct serdev_device *); + const struct serdev_device_id *id_table; }; #define to_serdev_device_driver(d) container_of_const(d, struct serdev_device_driver, driver) @@ -135,6 +145,30 @@ static inline void serdev_device_set_client_ops(struct serdev_device *serdev, serdev->ops = ops; } +/** + * serdev_device_set_modalias() - set the modalias of a serdev device + * @serdev: serdev device. + * @modalias: non-empty modalias to use, typically KBUILD_MODNAME of the + * client driver. + * + * A serdev device is identified by its ACPI companion, by its device tree + * node, or by a modalias set by its creator. Serdev devices which are + * instantiated by a driver rather than by firmware have neither of the + * former, so they must set a modalias before serdev_device_add() to be + * identifiable. Doing so reports a SERDEV_MODULE_PREFIX modalias to + * userspace and makes the device match an id_table entry of a serdev + * device driver. + * + * Devices enumerated from firmware have no modalias of their own and keep + * deriving their modalias and their driver match from firmware only. The + * device name is not affected either way. + */ +static inline void serdev_device_set_modalias(struct serdev_device *serdev, + const char *modalias) +{ + strscpy(serdev->modalias, modalias); +} + static inline void *serdev_controller_get_drvdata(const struct serdev_controller *ctrl) { -- 2.34.1