Add helper functions to the DPLL core to retrieve a DPLL pin's firmware node handle based on the "dpll-pins" and "dpll-pin-names" properties. * `fwnode_dpll_pin_node_get()`: matches the given name against the "dpll-pin-names" property to find the correct index, then retrieves the reference from "dpll-pins". * `device_dpll_pin_node_get()`: a wrapper around the fwnode helper for convenience when using a `struct device`. These helpers simplify the process for consumer drivers (such as Ethernet controllers or PHYs) to look up their associated DPLL pins defined in the DT or ACPI, which can then be passed to the DPLL subsystem to acquire the pin object. Signed-off-by: Ivan Vecera --- drivers/dpll/dpll_core.c | 20 ++++++++++++++++++++ include/linux/dpll.h | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index fb68b5e19b480..23d04a9d022d7 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -654,6 +654,26 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode) } EXPORT_SYMBOL_GPL(fwnode_dpll_pin_find); +/** + * fwnode_dpll_pin_node_get - get dpll pin node from given fw node and pin name + * @fwnode: firmware node that uses the dpll pin + * @name: dpll pin name from dpll-pin-names property + * + * Return: ERR_PTR() on error or a valid firmware node handle on success. + */ +struct fwnode_handle *fwnode_dpll_pin_node_get(struct fwnode_handle *fwnode, + const char *name) +{ + int index = 0; + + if (name) + index = fwnode_property_match_string(fwnode, "dpll-pin-names", + name); + + return fwnode_find_reference(fwnode, "dpll-pins", index); +} +EXPORT_SYMBOL_GPL(fwnode_dpll_pin_node_get); + static int __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv, void *cookie) diff --git a/include/linux/dpll.h b/include/linux/dpll.h index f0c31a111c304..755c36d1ef45a 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -11,6 +11,7 @@ #include #include #include +#include #include struct dpll_device; @@ -176,6 +177,8 @@ int dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev); struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode); +struct fwnode_handle *fwnode_dpll_pin_node_get(struct fwnode_handle *fwnode, + const char *name); #else static inline void dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin) { } @@ -197,8 +200,20 @@ fwnode_dpll_pin_find(struct fwnode_handle *fwnode) { return NULL; } + +static inline struct fwnode_handle * +fwnode_dpll_pin_node_get(struct fwnode_handle *fwnode, const char *name) +{ + return NULL; +} #endif +static inline struct fwnode_handle * +device_dpll_pin_node_get(struct device *dev, const char *name) +{ + return fwnode_dpll_pin_node_get(dev_fwnode(dev), name); +} + struct dpll_device * dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module); -- 2.52.0