A link is reported only while the pins at both ends are registered. When a pin gets its first registration or loses its last one, send a change notification for every registered pin linked with it, so user space sees the link appear and disappear at both ends.
The notifications follow the registration of the pin. A link also disappears from the report when the last registered dpll device of the pin goes away, so a pin with a link or a firmware node has to be unregistered before its dpll devices, as zl3073x and ice do. The documentation says so. The notifications are sent from one helper, under dpll_lock like the other notifications. The message about a linked pin is built with the callbacks of its owner, also when another driver registers the pin at the other end. Signed-off-by: Ivan Vecera <[email protected]> --- Documentation/driver-api/dpll.rst | 6 ++++++ drivers/dpll/dpll_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Documentation/driver-api/dpll.rst b/Documentation/driver-api/dpll.rst index aed92693d9e604..7b083a59f0122d 100644 --- a/Documentation/driver-api/dpll.rst +++ b/Documentation/driver-api/dpll.rst @@ -370,6 +370,12 @@ each of them with the id of the pin at the other end: ``DPLL_A_PIN_ID`` id of the pin at the other end ============================== ========================================== +When a pin gets its first registration or loses its last one, the +subsystem sends ``DPLL_CMD_PIN_CHANGE_NTF`` for the registered pins +linked with it. A pin with a link or a firmware node has to be +unregistered before the dpll devices it is registered with, otherwise +its links disappear without a notification. + For example, an output of a DPLL chip wired to an input of a network controller:: diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 6c61801a293b7e..58a5a4a41a0b72 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -929,10 +929,30 @@ int dpll_pin_link_add(struct dpll_pin *pin, struct fwnode_handle *peer) } EXPORT_SYMBOL_GPL(dpll_pin_link_add); +/** + * dpll_pin_links_ntf - notify the pins linked with a pin + * @pin: pin that was registered or unregistered + * + * A link is reported only while the pins at both ends are registered, so + * send a change notification for every registered pin linked with @pin. + */ +static void dpll_pin_links_ntf(struct dpll_pin *pin) +{ + struct dpll_pin *pos; + unsigned long i; + + if (list_empty(&pin->links) && !pin->fwnode) + return; + xa_for_each_marked(&dpll_pin_xa, i, pos, DPLL_REGISTERED) + if (pos != pin && dpll_pins_linked(pin, pos)) + __dpll_pin_change_ntf(pos); +} + static int __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv, void *cookie) { + bool registered; int ret; ret = dpll_xa_ref_pin_add(&dpll->pin_refs, pin, ops, priv, cookie); @@ -941,8 +961,11 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, ret = dpll_xa_ref_dpll_add(&pin->dpll_refs, dpll, ops, priv, cookie); if (ret) goto ref_pin_del; + registered = xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED); xa_set_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED); dpll_pin_create_ntf(pin, dpll->clock_id); + if (!registered) + dpll_pin_links_ntf(pin); return ret; @@ -1035,6 +1058,7 @@ __dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin, if (xa_empty(&pin->dpll_refs)) { dpll_pin_ref_sync_pair_del(pin->id); xa_clear_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED); + dpll_pin_links_ntf(pin); } } -- 2.56.1
