1 // SPDX-License-Identifier: GPL-2.0-only 1 2 /* 3 // Copyright (c) 2022 Pengutronix, Oleksij Rem 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 /* Maximum current in uA according to IEEE 802 13 #define MAX_PI_CURRENT 1920000 14 15 struct phy_device; 16 struct pse_controller_dev; 17 18 /** 19 * struct pse_control_config - PSE control/cha 20 * 21 * @podl_admin_control: set PoDL PSE admin con 22 * IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEA 23 * @c33_admin_control: set PSE admin control a 24 * IEEE 802.3-2022 30.9.1.2.1 acPSEAdminC 25 */ 26 struct pse_control_config { 27 enum ethtool_podl_pse_admin_state podl 28 enum ethtool_c33_pse_admin_state c33_a 29 }; 30 31 /** 32 * struct pse_control_status - PSE control/cha 33 * 34 * @podl_admin_state: operational state of the 35 * functions. IEEE 802.3-2018 30.15.1.1.2 36 * @podl_pw_status: power detection status of 37 * IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPo 38 * @c33_admin_state: operational state of the 39 * functions. IEEE 802.3-2022 30.9.1.1.2 40 * @c33_pw_status: power detection status of t 41 * IEEE 802.3-2022 30.9.1.1.5 aPSEPowerDe 42 * @c33_pw_class: detected class of a powered 43 * IEEE 802.3-2022 30.9.1.1.8 aPSEPowerCl 44 * @c33_actual_pw: power currently delivered b 45 * IEEE 802.3-2022 30.9.1.1.23 aPSEActual 46 * @c33_ext_state_info: extended state informa 47 * @c33_avail_pw_limit: available power limit 48 * IEEE 802.3-2022 145.2.5.4 pse_avail_pw 49 * @c33_pw_limit_ranges: supported power limit 50 * is in charge of the memory allocation. 51 * @c33_pw_limit_nb_ranges: number of supporte 52 * ranges 53 */ 54 struct pse_control_status { 55 enum ethtool_podl_pse_admin_state podl 56 enum ethtool_podl_pse_pw_d_status podl 57 enum ethtool_c33_pse_admin_state c33_a 58 enum ethtool_c33_pse_pw_d_status c33_p 59 u32 c33_pw_class; 60 u32 c33_actual_pw; 61 struct ethtool_c33_pse_ext_state_info 62 u32 c33_avail_pw_limit; 63 struct ethtool_c33_pse_pw_limit_range 64 u32 c33_pw_limit_nb_ranges; 65 }; 66 67 /** 68 * struct pse_controller_ops - PSE controller 69 * 70 * @ethtool_get_status: get PSE control status 71 * @setup_pi_matrix: setup PI matrix of the PS 72 * @pi_is_enabled: Return 1 if the PSE PI is e 73 * May also return negative er 74 * @pi_enable: Configure the PSE PI as enabled 75 * @pi_disable: Configure the PSE PI as disabl 76 * @pi_get_voltage: Return voltage similarly t 77 * callback. 78 * @pi_get_current_limit: Get the configured c 79 * get_current_limit re 80 * @pi_set_current_limit: Configure the curren 81 * set_current_limit re 82 * Should not return an 83 * current value set. 84 */ 85 struct pse_controller_ops { 86 int (*ethtool_get_status)(struct pse_c 87 unsigned long id, struct netli 88 struct pse_control_status *sta 89 int (*setup_pi_matrix)(struct pse_cont 90 int (*pi_is_enabled)(struct pse_contro 91 int (*pi_enable)(struct pse_controller 92 int (*pi_disable)(struct pse_controlle 93 int (*pi_get_voltage)(struct pse_contr 94 int (*pi_get_current_limit)(struct pse 95 int id); 96 int (*pi_set_current_limit)(struct pse 97 int id, in 98 }; 99 100 struct module; 101 struct device_node; 102 struct of_phandle_args; 103 struct pse_control; 104 105 /* PSE PI pairset pinout can either be Alterna 106 enum pse_pi_pairset_pinout { 107 ALTERNATIVE_A, 108 ALTERNATIVE_B, 109 }; 110 111 /** 112 * struct pse_pi_pairset - PSE PI pairset enti 113 * alternative ant its 114 * 115 * @pinout: description of the pinout alternat 116 * @np: device node pointer describing the pai 117 */ 118 struct pse_pi_pairset { 119 enum pse_pi_pairset_pinout pinout; 120 struct device_node *np; 121 }; 122 123 /** 124 * struct pse_pi - PSE PI (Power Interface) en 125 * IEEE 802.3-2022 145.2.4 126 * 127 * @pairset: table of the PSE PI pinout altern 128 * @np: device node pointer of the PSE PI node 129 * @rdev: regulator represented by the PSE PI 130 * @admin_state_enabled: PI enabled state 131 */ 132 struct pse_pi { 133 struct pse_pi_pairset pairset[2]; 134 struct device_node *np; 135 struct regulator_dev *rdev; 136 bool admin_state_enabled; 137 }; 138 139 /** 140 * struct pse_controller_dev - PSE controller 141 * provide multipl 142 * @ops: a pointer to device specific struct p 143 * @owner: kernel module of the PSE controller 144 * @list: internal list of PSE controller devi 145 * @pse_control_head: head of internal list of 146 * @dev: corresponding driver model device str 147 * @of_pse_n_cells: number of cells in PSE lin 148 * @nr_lines: number of PSE controls in this c 149 * @lock: Mutex for serialization access to th 150 * @types: types of the PSE controller 151 * @pi: table of PSE PIs described in this con 152 * @no_of_pse_pi: flag set if the pse_pis devi 153 */ 154 struct pse_controller_dev { 155 const struct pse_controller_ops *ops; 156 struct module *owner; 157 struct list_head list; 158 struct list_head pse_control_head; 159 struct device *dev; 160 int of_pse_n_cells; 161 unsigned int nr_lines; 162 struct mutex lock; 163 enum ethtool_pse_types types; 164 struct pse_pi *pi; 165 bool no_of_pse_pi; 166 }; 167 168 #if IS_ENABLED(CONFIG_PSE_CONTROLLER) 169 int pse_controller_register(struct pse_control 170 void pse_controller_unregister(struct pse_cont 171 struct device; 172 int devm_pse_controller_register(struct device 173 struct pse_co 174 175 struct pse_control *of_pse_control_get(struct 176 void pse_control_put(struct pse_control *psec) 177 178 int pse_ethtool_get_status(struct pse_control 179 struct netlink_ext_ 180 struct pse_control_ 181 int pse_ethtool_set_config(struct pse_control 182 struct netlink_ext_ 183 const struct pse_co 184 int pse_ethtool_set_pw_limit(struct pse_contro 185 struct netlink_ex 186 const unsigned in 187 int pse_ethtool_get_pw_limit(struct pse_contro 188 struct netlink_ex 189 190 bool pse_has_podl(struct pse_control *psec); 191 bool pse_has_c33(struct pse_control *psec); 192 193 #else 194 195 static inline struct pse_control *of_pse_contr 196 { 197 return ERR_PTR(-ENOENT); 198 } 199 200 static inline void pse_control_put(struct pse_ 201 { 202 } 203 204 static inline int pse_ethtool_get_status(struc 205 struc 206 struc 207 { 208 return -EOPNOTSUPP; 209 } 210 211 static inline int pse_ethtool_set_config(struc 212 struc 213 const 214 { 215 return -EOPNOTSUPP; 216 } 217 218 static inline int pse_ethtool_set_pw_limit(str 219 str 220 con 221 { 222 return -EOPNOTSUPP; 223 } 224 225 static inline int pse_ethtool_get_pw_limit(str 226 str 227 { 228 return -EOPNOTSUPP; 229 } 230 231 static inline bool pse_has_podl(struct pse_con 232 { 233 return false; 234 } 235 236 static inline bool pse_has_c33(struct pse_cont 237 { 238 return false; 239 } 240 241 #endif 242 243 #endif 244
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.