1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2023 Meta Platforms, Inc. and affiliates
4 * Copyright (c) 2023 Intel and affiliates
10 #include <uapi/linux/dpll.h>
11 #include <linux/device.h>
12 #include <linux/netlink.h>
13 #include <linux/netdevice.h>
14 #include <linux/rtnetlink.h>
19 struct dpll_device_ops {
20 int (*mode_get)(const struct dpll_device *dpll, void *dpll_priv,
21 enum dpll_mode *mode, struct netlink_ext_ack *extack);
22 int (*lock_status_get)(const struct dpll_device *dpll, void *dpll_priv,
23 enum dpll_lock_status *status,
24 enum dpll_lock_status_error *status_error,
25 struct netlink_ext_ack *extack);
26 int (*temp_get)(const struct dpll_device *dpll, void *dpll_priv,
27 s32 *temp, struct netlink_ext_ack *extack);
31 int (*frequency_set)(const struct dpll_pin *pin, void *pin_priv,
32 const struct dpll_device *dpll, void *dpll_priv,
34 struct netlink_ext_ack *extack);
35 int (*frequency_get)(const struct dpll_pin *pin, void *pin_priv,
36 const struct dpll_device *dpll, void *dpll_priv,
37 u64 *frequency, struct netlink_ext_ack *extack);
38 int (*direction_set)(const struct dpll_pin *pin, void *pin_priv,
39 const struct dpll_device *dpll, void *dpll_priv,
40 const enum dpll_pin_direction direction,
41 struct netlink_ext_ack *extack);
42 int (*direction_get)(const struct dpll_pin *pin, void *pin_priv,
43 const struct dpll_device *dpll, void *dpll_priv,
44 enum dpll_pin_direction *direction,
45 struct netlink_ext_ack *extack);
46 int (*state_on_pin_get)(const struct dpll_pin *pin, void *pin_priv,
47 const struct dpll_pin *parent_pin,
48 void *parent_pin_priv,
49 enum dpll_pin_state *state,
50 struct netlink_ext_ack *extack);
51 int (*state_on_dpll_get)(const struct dpll_pin *pin, void *pin_priv,
52 const struct dpll_device *dpll,
53 void *dpll_priv, enum dpll_pin_state *state,
54 struct netlink_ext_ack *extack);
55 int (*state_on_pin_set)(const struct dpll_pin *pin, void *pin_priv,
56 const struct dpll_pin *parent_pin,
57 void *parent_pin_priv,
58 const enum dpll_pin_state state,
59 struct netlink_ext_ack *extack);
60 int (*state_on_dpll_set)(const struct dpll_pin *pin, void *pin_priv,
61 const struct dpll_device *dpll,
63 const enum dpll_pin_state state,
64 struct netlink_ext_ack *extack);
65 int (*prio_get)(const struct dpll_pin *pin, void *pin_priv,
66 const struct dpll_device *dpll, void *dpll_priv,
67 u32 *prio, struct netlink_ext_ack *extack);
68 int (*prio_set)(const struct dpll_pin *pin, void *pin_priv,
69 const struct dpll_device *dpll, void *dpll_priv,
70 const u32 prio, struct netlink_ext_ack *extack);
71 int (*phase_offset_get)(const struct dpll_pin *pin, void *pin_priv,
72 const struct dpll_device *dpll, void *dpll_priv,
74 struct netlink_ext_ack *extack);
75 int (*phase_adjust_get)(const struct dpll_pin *pin, void *pin_priv,
76 const struct dpll_device *dpll, void *dpll_priv,
78 struct netlink_ext_ack *extack);
79 int (*phase_adjust_set)(const struct dpll_pin *pin, void *pin_priv,
80 const struct dpll_device *dpll, void *dpll_priv,
81 const s32 phase_adjust,
82 struct netlink_ext_ack *extack);
83 int (*ffo_get)(const struct dpll_pin *pin, void *pin_priv,
84 const struct dpll_device *dpll, void *dpll_priv,
85 s64 *ffo, struct netlink_ext_ack *extack);
88 struct dpll_pin_frequency {
93 #define DPLL_PIN_FREQUENCY_RANGE(_min, _max) \
99 #define DPLL_PIN_FREQUENCY(_val) DPLL_PIN_FREQUENCY_RANGE(_val, _val)
100 #define DPLL_PIN_FREQUENCY_1PPS \
101 DPLL_PIN_FREQUENCY(DPLL_PIN_FREQUENCY_1_HZ)
102 #define DPLL_PIN_FREQUENCY_10MHZ \
103 DPLL_PIN_FREQUENCY(DPLL_PIN_FREQUENCY_10_MHZ)
104 #define DPLL_PIN_FREQUENCY_IRIG_B \
105 DPLL_PIN_FREQUENCY(DPLL_PIN_FREQUENCY_10_KHZ)
106 #define DPLL_PIN_FREQUENCY_DCF77 \
107 DPLL_PIN_FREQUENCY(DPLL_PIN_FREQUENCY_77_5_KHZ)
109 struct dpll_pin_phase_adjust_range {
114 struct dpll_pin_properties {
115 const char *board_label;
116 const char *panel_label;
117 const char *package_label;
118 enum dpll_pin_type type;
119 unsigned long capabilities;
120 u32 freq_supported_num;
121 struct dpll_pin_frequency *freq_supported;
122 struct dpll_pin_phase_adjust_range phase_range;
125 #if IS_ENABLED(CONFIG_DPLL)
126 void dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin);
127 void dpll_netdev_pin_clear(struct net_device *dev);
129 size_t dpll_netdev_pin_handle_size(const struct net_device *dev);
130 int dpll_netdev_add_pin_handle(struct sk_buff *msg,
131 const struct net_device *dev);
134 dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin) { }
135 static inline void dpll_netdev_pin_clear(struct net_device *dev) { }
137 static inline size_t dpll_netdev_pin_handle_size(const struct net_device *dev)
143 dpll_netdev_add_pin_handle(struct sk_buff *msg, const struct net_device *dev)
150 dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module);
152 void dpll_device_put(struct dpll_device *dpll);
154 int dpll_device_register(struct dpll_device *dpll, enum dpll_type type,
155 const struct dpll_device_ops *ops, void *priv);
157 void dpll_device_unregister(struct dpll_device *dpll,
158 const struct dpll_device_ops *ops, void *priv);
161 dpll_pin_get(u64 clock_id, u32 dev_driver_id, struct module *module,
162 const struct dpll_pin_properties *prop);
164 int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,
165 const struct dpll_pin_ops *ops, void *priv);
167 void dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin,
168 const struct dpll_pin_ops *ops, void *priv);
170 void dpll_pin_put(struct dpll_pin *pin);
172 int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,
173 const struct dpll_pin_ops *ops, void *priv);
175 void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,
176 const struct dpll_pin_ops *ops, void *priv);
178 int dpll_device_change_ntf(struct dpll_device *dpll);
180 int dpll_pin_change_ntf(struct dpll_pin *pin);