]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
serdev: Add an API to find the serdev controller associated with the devicetree node
authorManivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Thu, 26 Mar 2026 08:06:30 +0000 (13:36 +0530)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tue, 31 Mar 2026 07:48:42 +0000 (09:48 +0200)
Add of_find_serdev_controller_by_node() API to find the serdev controller
device associated with the devicetree node.

Tested-by: Hans de Goede <johannes.goede@oss.qualcomm.com> # ThinkPad T14s gen6 (arm64)
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://patch.msgid.link/20260326-pci-m2-e-v7-2-43324a7866e6@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/tty/serdev/core.c
include/linux/serdev.h

index 8f25510f89b6680d2a668972670e01997663759a..bf88b95f7458d1267bffd3d9690ec0763a5b5a83 100644 (file)
@@ -514,6 +514,25 @@ err_free:
 }
 EXPORT_SYMBOL_GPL(serdev_controller_alloc);
 
+#ifdef CONFIG_OF
+/**
+ * of_find_serdev_controller_by_node() - Find the serdev controller associated
+ *                                      with the devicetree node
+ * @node:      Devicetree node
+ *
+ * Return: Pointer to the serdev controller associated with the node. NULL if
+ * the controller is not found. Caller is responsible for calling
+ * serdev_controller_put() to drop the reference.
+ */
+struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node)
+{
+       struct device *dev = bus_find_device_by_of_node(&serdev_bus_type, node);
+
+       return (dev && dev->type == &serdev_ctrl_type) ? to_serdev_controller(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(of_find_serdev_controller_by_node);
+#endif
+
 static int of_serdev_register_devices(struct serdev_controller *ctrl)
 {
        struct device_node *node;
index 0c7d3c27d1f8a5cfbb0dec2f3ab5a41abef2d170..188c0ba62d50ccfc799f638a732c183d366311fe 100644 (file)
@@ -334,4 +334,13 @@ static inline bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
 }
 #endif /* CONFIG_ACPI */
 
+#ifdef CONFIG_OF
+struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node);
+#else
+static inline struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node)
+{
+       return NULL;
+}
+#endif /* CONFIG_OF */
+
 #endif /*_LINUX_SERDEV_H */