diff --git a/Documentation/driver-api/dpll.rst b/Documentation/driver-api/dpll.rst
index 7c117ae37cc1bc..aed92693d9e604 100644
--- a/Documentation/driver-api/dpll.rst
+++ b/Documentation/driver-api/dpll.rst
@@ -350,6 +350,41 @@ bound to only one other pin at any given time.
``DPLL_A_PIN_STATE`` state of Reference SYNC connection
============================== ==========================================
+Pin links
+=========
+
+A pin represents a pad of the device whose driver registers it. When the
+board connects a pad of one device to a pad of another one, for example an
+output of a DPLL chip to a reference clock input of a network controller,
+the driver of one of them describes the connection with
+dpll_pin_link_add() on its own pin. The link names the pin at the other
+end by its firmware node, which the driver of that pin sets with
+dpll_pin_fwnode_set(). Each driver registers only its own pins and the
+drivers may probe in any order.
+
+While both pins are registered, ``DPLL_CMD_PIN_GET`` reports the link for
+each of them with the id of the pin at the other end:
+
+ ============================== ==========================================
+ ``DPLL_A_PIN_LINK`` nested attribute for each linked pin
+ ``DPLL_A_PIN_ID`` id of the pin at the other end
+ ============================== ==========================================
+
+For example, an output of a DPLL chip wired to an input of a network
+controller::
+
+ 'pin': [{
+ 'id': 7,
+ 'module-name': 'zl3073x',
+ 'parent-device': [{'parent-id': 0, 'direction': 'output', ...}],
+ 'link': [{'id': 21}]
+ }, {
+ 'id': 21,
+ 'module-name': 'ice',
+ 'parent-device': [{'parent-id': 5, 'direction': 'input', ...}],
+ 'link': [{'id': 7}]
+ }]
+
Configuration commands group
============================
@@ -467,6 +502,9 @@ according to attribute purpose.
``DPLL_A_PIN_CAPABILITIES`` attr bitmask of pin capabilities
``DPLL_A_PIN_MEASURED_FREQUENCY`` attr measured frequency of
an input pin in mHz
+ ``DPLL_A_PIN_LINK`` nested attr for each pin linked
+ with the pin
+ ``DPLL_A_PIN_ID`` attr id of the linked pin
==================================== ==================================
==================================== =================================diff --git a/Documentation/netlink/specs/dpll.yaml b/Documentation/netlink/specs/dpll.yaml
index 8fa789a502732a..c81e4dbe65d73e 100644
--- a/Documentation/netlink/specs/dpll.yaml
+++ b/Documentation/netlink/specs/dpll.yaml
@@ -542,6 +542,14 @@ attribute-sets:
Operational state of the pin with respect to its parent DPLL
device. Unlike state (which reflects the administrative intent),
operstate reflects the actual hardware status.
+ -
+ name: link
+ type: nest
+ multi-attr: true
+ nested-attributes: pin-link
+ doc: |
+ A pin connected with this pin on the board, usually a pin of
+ another device. Reported while both pins are registered.
-
name: pin-parent-device@@ -591,6 +599,12 @@ attribute-sets:
name: id
-
name: state
+ -
+ name: pin-link
+ subset-of: pin
+ attributes:
+ -
+ name: id
operations:
enum-name: dpll_cmd@@ -741,6 +755,7 @@ operations:
- esync-pulse
- reference-sync
- measured-frequency
+ - link
dump:
reply: *pin-attrsdiff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c
index 4d871542ddf762..6c61801a293b7e 100644
--- a/drivers/dpll/dpll_core.c
+++ b/drivers/dpll/dpll_core.c
@@ -806,13 +806,19 @@ EXPORT_SYMBOL_GPL(dpll_pin_put);
* @pin: pointer to a dpll pin
* @fwnode: firmware node handle
*
- * Set firmware node handle for the given dpll pin.
+ * Set firmware node handle for the given dpll pin. Links name pins by their
+ * firmware node, so the node of a registered pin must not change.
+ *
+ * Context: Acquires a lock (dpll_lock)
*/
void dpll_pin_fwnode_set(struct dpll_pin *pin, struct fwnode_handle *fwnode)
{
mutex_lock(&dpll_lock);
- fwnode_handle_put(pin->fwnode); /* Drop fwnode previously set */
- pin->fwnode = fwnode_handle_get(fwnode);
+ if (pin->fwnode != fwnode &&
+ !WARN_ON(xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED))) {
+ fwnode_handle_put(pin->fwnode); /* Drop fwnode previously set */
+ pin->fwnode = fwnode_handle_get(fwnode);
+ }
mutex_unlock(&dpll_lock);
}
EXPORT_SYMBOL_GPL(dpll_pin_fwnode_set);@@ -862,6 +868,20 @@ static bool dpll_pin_has_link(const struct dpll_pin *pin,
return false;
}
+/**
+ * dpll_pins_linked - check if two pins are linked
+ * @a: pointer to a dpll pin
+ * @b: pointer to another dpll pin
+ *
+ * Context: Caller must hold dpll_lock.
+ * Return: true if either pin has a link to the firmware node of the other
+ */
+bool dpll_pins_linked(const struct dpll_pin *a, const struct dpll_pin *b)
+{
+ return (b->fwnode && dpll_pin_has_link(a, b->fwnode)) ||
+ (a->fwnode && dpll_pin_has_link(b, a->fwnode));
+}
+
/**
* dpll_pin_link_add - add a link from a pin to another pin
* @pin: pointer to a dpll pindiff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h
index 26a16df2b6410d..f158785bf401b6 100644
--- a/drivers/dpll/dpll_core.h
+++ b/drivers/dpll/dpll_core.h
@@ -108,6 +108,7 @@ struct dpll_device *dpll_device_get_by_id(int id);
struct dpll_pin_ref *dpll_pin_own_dpll_ref_first(struct dpll_pin *pin);
const struct dpll_pin_ops *dpll_pin_ops(struct dpll_pin_ref *ref);
struct dpll_pin_ref *dpll_xa_ref_dpll_first(struct xarray *xa_refs);
+bool dpll_pins_linked(const struct dpll_pin *a, const struct dpll_pin *b);
extern struct xarray dpll_device_xa;
extern struct xarray dpll_pin_xa;
extern struct mutex dpll_lock;
diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c
index e5380d95f238b3..016f3026d2f2e5 100644
--- a/drivers/dpll/dpll_netlink.c
+++ b/drivers/dpll/dpll_netlink.c
@@ -709,6 +709,32 @@ dpll_msg_add_pin_dplls(struct sk_buff *msg, struct dpll_pin *pin,
return ret;
}
+static int dpll_msg_add_pin_links(struct sk_buff *msg, struct dpll_pin *pin)
+{
+ struct dpll_pin *pos;
+ struct nlattr *nest;
+ unsigned long i;
+
+ /* Only a pin with links or with a firmware node can be linked */
+ if (list_empty(&pin->links) && !pin->fwnode)
+ return 0;
+ xa_for_each_marked(&dpll_pin_xa, i, pos, DPLL_REGISTERED) {
+ if (pos == pin || !dpll_pins_linked(pin, pos) ||
+ !dpll_pin_available(pos))
+ continue;
+ nest = nla_nest_start(msg, DPLL_A_PIN_LINK);
+ if (!nest)
+ return -EMSGSIZE;
+ if (nla_put_u32(msg, DPLL_A_PIN_ID, pos->id)) {
+ nla_nest_cancel(msg, nest);
+ return -EMSGSIZE;
+ }
+ nla_nest_end(msg, nest);
+ }
+
+ return 0;
+}
+
static int
dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,
struct netlink_ext_ack *extack)@@ -780,8 +806,10 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,
ret = dpll_msg_add_pin_dplls(msg, pin, extack);
else
ret = dpll_msg_add_pin_parents(msg, pin, ref, extack);
+ if (ret)
+ return ret;
- return ret;
+ return dpll_msg_add_pin_links(msg, pin);
}
static int
diff --git a/include/uapi/linux/dpll.h b/include/uapi/linux/dpll.h
index 8c71fc3f986343..02e9004426f49c 100644
--- a/include/uapi/linux/dpll.h
+++ b/include/uapi/linux/dpll.h
@@ -289,6 +289,7 @@ enum dpll_a_pin {
DPLL_A_PIN_FRACTIONAL_FREQUENCY_OFFSET_PPT,
DPLL_A_PIN_MEASURED_FREQUENCY,
DPLL_A_PIN_OPERSTATE,
+ DPLL_A_PIN_LINK,
__DPLL_A_PIN_MAX,
DPLL_A_PIN_MAX = (__DPLL_A_PIN_MAX - 1)--
2.56.1