]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dpll: add dpll_device op to get supported modes
authorIvan Vecera <ivecera@redhat.com>
Wed, 14 Jan 2026 12:27:24 +0000 (13:27 +0100)
committerJakub Kicinski <kuba@kernel.org>
Mon, 19 Jan 2026 20:04:53 +0000 (12:04 -0800)
Currently, the DPLL subsystem assumes that the only supported mode is
the one currently active on the device. When dpll_msg_add_mode_supported()
is called, it relies on ops->mode_get() and reports that single mode
to userspace. This prevents users from discovering other modes the device
might be capable of.

Add a new callback .supported_modes_get() to struct dpll_device_ops. This
allows drivers to populate a bitmap indicating all modes supported by
the hardware.

Update dpll_msg_add_mode_supported() to utilize this new callback:

* if ops->supported_modes_get is defined, use it to retrieve the full
  bitmap of supported modes.
* if not defined, fall back to the existing behavior: retrieve
  the current mode via ops->mode_get and set the corresponding bit
  in the bitmap.

Finally, iterate over the bitmap and add a DPLL_A_MODE_SUPPORTED netlink
attribute for every set bit, accurately reporting the device's capabilities
to userspace.

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
Link: https://patch.msgid.link/20260114122726.120303-2-ivecera@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/dpll/dpll_netlink.c
include/linux/dpll.h

index 64944f601ee5aa1d965f84e4ec5f964bc9e5d6da..d6a0e272d70384d438dd42ec4eefaef136a0af1d 100644 (file)
@@ -128,18 +128,29 @@ dpll_msg_add_mode_supported(struct sk_buff *msg, struct dpll_device *dpll,
                            struct netlink_ext_ack *extack)
 {
        const struct dpll_device_ops *ops = dpll_device_ops(dpll);
+       DECLARE_BITMAP(modes, DPLL_MODE_MAX + 1) = { 0 };
        enum dpll_mode mode;
        int ret;
 
-       /* No mode change is supported now, so the only supported mode is the
-        * one obtained by mode_get().
-        */
+       if (ops->supported_modes_get) {
+               ret = ops->supported_modes_get(dpll, dpll_priv(dpll), modes,
+                                              extack);
+               if (ret)
+                       return ret;
+       } else {
+               /* If the supported modes are not reported by the driver, the
+                * only supported mode is the one obtained by mode_get().
+                */
+               ret = ops->mode_get(dpll, dpll_priv(dpll), &mode, extack);
+               if (ret)
+                       return ret;
 
-       ret = ops->mode_get(dpll, dpll_priv(dpll), &mode, extack);
-       if (ret)
-               return ret;
-       if (nla_put_u32(msg, DPLL_A_MODE_SUPPORTED, mode))
-               return -EMSGSIZE;
+               __set_bit(mode, modes);
+       }
+
+       for_each_set_bit(mode, modes, DPLL_MODE_MAX + 1)
+               if (nla_put_u32(msg, DPLL_A_MODE_SUPPORTED, mode))
+                       return -EMSGSIZE;
 
        return 0;
 }
index 562f520b23c277fdb749e49fce771dd681df11f4..912a2ca3e0ee708bb03f96c337214d69e61324a9 100644 (file)
@@ -20,6 +20,9 @@ struct dpll_pin_esync;
 struct dpll_device_ops {
        int (*mode_get)(const struct dpll_device *dpll, void *dpll_priv,
                        enum dpll_mode *mode, struct netlink_ext_ack *extack);
+       int (*supported_modes_get)(const struct dpll_device *dpll,
+                                  void *dpll_priv, unsigned long *modes,
+                                  struct netlink_ext_ack *extack);
        int (*lock_status_get)(const struct dpll_device *dpll, void *dpll_priv,
                               enum dpll_lock_status *status,
                               enum dpll_lock_status_error *status_error,