1 // SPDX-License-Identifier: GPL-2.0-only
5 #ifndef _LINUX_PSE_CONTROLLER_H
6 #define _LINUX_PSE_CONTROLLER_H
8 #include <linux/ethtool.h>
9 #include <linux/list.h>
10 #include <uapi/linux/ethtool.h>
13 struct pse_controller_dev;
16 * struct pse_control_config - PSE control/channel configuration.
18 * @podl_admin_control: set PoDL PSE admin control as described in
19 * IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
20 * @c33_admin_control: set PSE admin control as described in
21 * IEEE 802.3-2022 30.9.1.2.1 acPSEAdminControl
23 struct pse_control_config {
24 enum ethtool_podl_pse_admin_state podl_admin_control;
25 enum ethtool_c33_pse_admin_state c33_admin_control;
29 * struct pse_control_status - PSE control/channel status.
31 * @podl_admin_state: operational state of the PoDL PSE
32 * functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState
33 * @podl_pw_status: power detection status of the PoDL PSE.
34 * IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPowerDetectionStatus:
35 * @c33_admin_state: operational state of the PSE
36 * functions. IEEE 802.3-2022 30.9.1.1.2 aPSEAdminState
37 * @c33_pw_status: power detection status of the PSE.
38 * IEEE 802.3-2022 30.9.1.1.5 aPSEPowerDetectionStatus:
40 struct pse_control_status {
41 enum ethtool_podl_pse_admin_state podl_admin_state;
42 enum ethtool_podl_pse_pw_d_status podl_pw_status;
43 enum ethtool_c33_pse_admin_state c33_admin_state;
44 enum ethtool_c33_pse_pw_d_status c33_pw_status;
48 * struct pse_controller_ops - PSE controller driver callbacks
50 * @ethtool_get_status: get PSE control status for ethtool interface
51 * @setup_pi_matrix: setup PI matrix of the PSE controller
52 * @pi_is_enabled: Return 1 if the PSE PI is enabled, 0 if not.
53 * May also return negative errno.
54 * @pi_enable: Configure the PSE PI as enabled.
55 * @pi_disable: Configure the PSE PI as disabled.
57 struct pse_controller_ops {
58 int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
59 unsigned long id, struct netlink_ext_ack *extack,
60 struct pse_control_status *status);
61 int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
62 int (*pi_is_enabled)(struct pse_controller_dev *pcdev, int id);
63 int (*pi_enable)(struct pse_controller_dev *pcdev, int id);
64 int (*pi_disable)(struct pse_controller_dev *pcdev, int id);
69 struct of_phandle_args;
72 /* PSE PI pairset pinout can either be Alternative A or Alternative B */
73 enum pse_pi_pairset_pinout {
79 * struct pse_pi_pairset - PSE PI pairset entity describing the pinout
80 * alternative ant its phandle
82 * @pinout: description of the pinout alternative
83 * @np: device node pointer describing the pairset phandle
85 struct pse_pi_pairset {
86 enum pse_pi_pairset_pinout pinout;
87 struct device_node *np;
91 * struct pse_pi - PSE PI (Power Interface) entity as described in
92 * IEEE 802.3-2022 145.2.4
94 * @pairset: table of the PSE PI pinout alternative for the two pairset
95 * @np: device node pointer of the PSE PI node
96 * @rdev: regulator represented by the PSE PI
97 * @admin_state_enabled: PI enabled state
100 struct pse_pi_pairset pairset[2];
101 struct device_node *np;
102 struct regulator_dev *rdev;
103 bool admin_state_enabled;
107 * struct pse_controller_dev - PSE controller entity that might
108 * provide multiple PSE controls
109 * @ops: a pointer to device specific struct pse_controller_ops
110 * @owner: kernel module of the PSE controller driver
111 * @list: internal list of PSE controller devices
112 * @pse_control_head: head of internal list of requested PSE controls
113 * @dev: corresponding driver model device struct
114 * @of_pse_n_cells: number of cells in PSE line specifiers
115 * @nr_lines: number of PSE controls in this controller device
116 * @lock: Mutex for serialization access to the PSE controller
117 * @types: types of the PSE controller
118 * @pi: table of PSE PIs described in this controller device
119 * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used
121 struct pse_controller_dev {
122 const struct pse_controller_ops *ops;
123 struct module *owner;
124 struct list_head list;
125 struct list_head pse_control_head;
128 unsigned int nr_lines;
130 enum ethtool_pse_types types;
135 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
136 int pse_controller_register(struct pse_controller_dev *pcdev);
137 void pse_controller_unregister(struct pse_controller_dev *pcdev);
139 int devm_pse_controller_register(struct device *dev,
140 struct pse_controller_dev *pcdev);
142 struct pse_control *of_pse_control_get(struct device_node *node);
143 void pse_control_put(struct pse_control *psec);
145 int pse_ethtool_get_status(struct pse_control *psec,
146 struct netlink_ext_ack *extack,
147 struct pse_control_status *status);
148 int pse_ethtool_set_config(struct pse_control *psec,
149 struct netlink_ext_ack *extack,
150 const struct pse_control_config *config);
152 bool pse_has_podl(struct pse_control *psec);
153 bool pse_has_c33(struct pse_control *psec);
157 static inline struct pse_control *of_pse_control_get(struct device_node *node)
159 return ERR_PTR(-ENOENT);
162 static inline void pse_control_put(struct pse_control *psec)
166 static inline int pse_ethtool_get_status(struct pse_control *psec,
167 struct netlink_ext_ack *extack,
168 struct pse_control_status *status)
173 static inline int pse_ethtool_set_config(struct pse_control *psec,
174 struct netlink_ext_ack *extack,
175 const struct pse_control_config *config)
180 static inline bool pse_has_podl(struct pse_control *psec)
185 static inline bool pse_has_c33(struct pse_control *psec)