xref: /linux-6.15/include/linux/pse-pd/pse.h (revision ae37dc57)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 // Copyright (c) 2022 Pengutronix, Oleksij Rempel <[email protected]>
4  */
5 #ifndef _LINUX_PSE_CONTROLLER_H
6 #define _LINUX_PSE_CONTROLLER_H
7 
8 #include <linux/ethtool.h>
9 #include <linux/list.h>
10 #include <uapi/linux/ethtool.h>
11 
12 struct phy_device;
13 struct pse_controller_dev;
14 
15 /**
16  * struct pse_control_config - PSE control/channel configuration.
17  *
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
22  */
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;
26 };
27 
28 /**
29  * struct pse_control_status - PSE control/channel status.
30  *
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:
39  * @c33_pw_class: detected class of a powered PD
40  *	IEEE 802.3-2022 30.9.1.1.8 aPSEPowerClassification
41  * @c33_actual_pw: power currently delivered by the PSE in mW
42  *	IEEE 802.3-2022 30.9.1.1.23 aPSEActualPower
43  * @c33_ext_state_info: extended state information of the PSE
44  */
45 struct pse_control_status {
46 	enum ethtool_podl_pse_admin_state podl_admin_state;
47 	enum ethtool_podl_pse_pw_d_status podl_pw_status;
48 	enum ethtool_c33_pse_admin_state c33_admin_state;
49 	enum ethtool_c33_pse_pw_d_status c33_pw_status;
50 	u32 c33_pw_class;
51 	u32 c33_actual_pw;
52 	struct ethtool_c33_pse_ext_state_info c33_ext_state_info;
53 };
54 
55 /**
56  * struct pse_controller_ops - PSE controller driver callbacks
57  *
58  * @ethtool_get_status: get PSE control status for ethtool interface
59  * @setup_pi_matrix: setup PI matrix of the PSE controller
60  * @pi_is_enabled: Return 1 if the PSE PI is enabled, 0 if not.
61  *		   May also return negative errno.
62  * @pi_enable: Configure the PSE PI as enabled.
63  * @pi_disable: Configure the PSE PI as disabled.
64  */
65 struct pse_controller_ops {
66 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
67 		unsigned long id, struct netlink_ext_ack *extack,
68 		struct pse_control_status *status);
69 	int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
70 	int (*pi_is_enabled)(struct pse_controller_dev *pcdev, int id);
71 	int (*pi_enable)(struct pse_controller_dev *pcdev, int id);
72 	int (*pi_disable)(struct pse_controller_dev *pcdev, int id);
73 };
74 
75 struct module;
76 struct device_node;
77 struct of_phandle_args;
78 struct pse_control;
79 
80 /* PSE PI pairset pinout can either be Alternative A or Alternative B */
81 enum pse_pi_pairset_pinout {
82 	ALTERNATIVE_A,
83 	ALTERNATIVE_B,
84 };
85 
86 /**
87  * struct pse_pi_pairset - PSE PI pairset entity describing the pinout
88  *			   alternative ant its phandle
89  *
90  * @pinout: description of the pinout alternative
91  * @np: device node pointer describing the pairset phandle
92  */
93 struct pse_pi_pairset {
94 	enum pse_pi_pairset_pinout pinout;
95 	struct device_node *np;
96 };
97 
98 /**
99  * struct pse_pi - PSE PI (Power Interface) entity as described in
100  *		   IEEE 802.3-2022 145.2.4
101  *
102  * @pairset: table of the PSE PI pinout alternative for the two pairset
103  * @np: device node pointer of the PSE PI node
104  * @rdev: regulator represented by the PSE PI
105  * @admin_state_enabled: PI enabled state
106  */
107 struct pse_pi {
108 	struct pse_pi_pairset pairset[2];
109 	struct device_node *np;
110 	struct regulator_dev *rdev;
111 	bool admin_state_enabled;
112 };
113 
114 /**
115  * struct pse_controller_dev - PSE controller entity that might
116  *                             provide multiple PSE controls
117  * @ops: a pointer to device specific struct pse_controller_ops
118  * @owner: kernel module of the PSE controller driver
119  * @list: internal list of PSE controller devices
120  * @pse_control_head: head of internal list of requested PSE controls
121  * @dev: corresponding driver model device struct
122  * @of_pse_n_cells: number of cells in PSE line specifiers
123  * @nr_lines: number of PSE controls in this controller device
124  * @lock: Mutex for serialization access to the PSE controller
125  * @types: types of the PSE controller
126  * @pi: table of PSE PIs described in this controller device
127  * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used
128  */
129 struct pse_controller_dev {
130 	const struct pse_controller_ops *ops;
131 	struct module *owner;
132 	struct list_head list;
133 	struct list_head pse_control_head;
134 	struct device *dev;
135 	int of_pse_n_cells;
136 	unsigned int nr_lines;
137 	struct mutex lock;
138 	enum ethtool_pse_types types;
139 	struct pse_pi *pi;
140 	bool no_of_pse_pi;
141 };
142 
143 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
144 int pse_controller_register(struct pse_controller_dev *pcdev);
145 void pse_controller_unregister(struct pse_controller_dev *pcdev);
146 struct device;
147 int devm_pse_controller_register(struct device *dev,
148 				 struct pse_controller_dev *pcdev);
149 
150 struct pse_control *of_pse_control_get(struct device_node *node);
151 void pse_control_put(struct pse_control *psec);
152 
153 int pse_ethtool_get_status(struct pse_control *psec,
154 			   struct netlink_ext_ack *extack,
155 			   struct pse_control_status *status);
156 int pse_ethtool_set_config(struct pse_control *psec,
157 			   struct netlink_ext_ack *extack,
158 			   const struct pse_control_config *config);
159 
160 bool pse_has_podl(struct pse_control *psec);
161 bool pse_has_c33(struct pse_control *psec);
162 
163 #else
164 
165 static inline struct pse_control *of_pse_control_get(struct device_node *node)
166 {
167 	return ERR_PTR(-ENOENT);
168 }
169 
170 static inline void pse_control_put(struct pse_control *psec)
171 {
172 }
173 
174 static inline int pse_ethtool_get_status(struct pse_control *psec,
175 					 struct netlink_ext_ack *extack,
176 					 struct pse_control_status *status)
177 {
178 	return -EOPNOTSUPP;
179 }
180 
181 static inline int pse_ethtool_set_config(struct pse_control *psec,
182 					 struct netlink_ext_ack *extack,
183 					 const struct pse_control_config *config)
184 {
185 	return -EOPNOTSUPP;
186 }
187 
188 static inline bool pse_has_podl(struct pse_control *psec)
189 {
190 	return false;
191 }
192 
193 static inline bool pse_has_c33(struct pse_control *psec)
194 {
195 	return false;
196 }
197 
198 #endif
199 
200 #endif
201