Skip to content

Commit a2b4814

Browse files
Mani-SadhasivamBartosz Golaszewski
authored andcommitted
serdev: Add an API to find the serdev controller associated with the devicetree node
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>
1 parent e7fef85 commit a2b4814

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

drivers/tty/serdev/core.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,25 @@ struct serdev_controller *serdev_controller_alloc(struct device *host,
514514
}
515515
EXPORT_SYMBOL_GPL(serdev_controller_alloc);
516516

517+
#ifdef CONFIG_OF
518+
/**
519+
* of_find_serdev_controller_by_node() - Find the serdev controller associated
520+
* with the devicetree node
521+
* @node: Devicetree node
522+
*
523+
* Return: Pointer to the serdev controller associated with the node. NULL if
524+
* the controller is not found. Caller is responsible for calling
525+
* serdev_controller_put() to drop the reference.
526+
*/
527+
struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node)
528+
{
529+
struct device *dev = bus_find_device_by_of_node(&serdev_bus_type, node);
530+
531+
return (dev && dev->type == &serdev_ctrl_type) ? to_serdev_controller(dev) : NULL;
532+
}
533+
EXPORT_SYMBOL_GPL(of_find_serdev_controller_by_node);
534+
#endif
535+
517536
static int of_serdev_register_devices(struct serdev_controller *ctrl)
518537
{
519538
struct device_node *node;

include/linux/serdev.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,13 @@ static inline bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
334334
}
335335
#endif /* CONFIG_ACPI */
336336

337+
#ifdef CONFIG_OF
338+
struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node);
339+
#else
340+
static inline struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node)
341+
{
342+
return NULL;
343+
}
344+
#endif /* CONFIG_OF */
345+
337346
#endif /*_LINUX_SERDEV_H */

0 commit comments

Comments
 (0)