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 */ 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; 45 }; 46 47 /** 48 * struct pse_controller_ops - PSE controller driver callbacks 49 * 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. 56 */ 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); 65 }; 66 67 struct module; 68 struct device_node; 69 struct of_phandle_args; 70 struct pse_control; 71 72 /* PSE PI pairset pinout can either be Alternative A or Alternative B */ 73 enum pse_pi_pairset_pinout { 74 ALTERNATIVE_A, 75 ALTERNATIVE_B, 76 }; 77 78 /** 79 * struct pse_pi_pairset - PSE PI pairset entity describing the pinout 80 * alternative ant its phandle 81 * 82 * @pinout: description of the pinout alternative 83 * @np: device node pointer describing the pairset phandle 84 */ 85 struct pse_pi_pairset { 86 enum pse_pi_pairset_pinout pinout; 87 struct device_node *np; 88 }; 89 90 /** 91 * struct pse_pi - PSE PI (Power Interface) entity as described in 92 * IEEE 802.3-2022 145.2.4 93 * 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 98 */ 99 struct pse_pi { 100 struct pse_pi_pairset pairset[2]; 101 struct device_node *np; 102 struct regulator_dev *rdev; 103 bool admin_state_enabled; 104 }; 105 106 /** 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 120 */ 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; 126 struct device *dev; 127 int of_pse_n_cells; 128 unsigned int nr_lines; 129 struct mutex lock; 130 enum ethtool_pse_types types; 131 struct pse_pi *pi; 132 bool no_of_pse_pi; 133 }; 134 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); 138 struct device; 139 int devm_pse_controller_register(struct device *dev, 140 struct pse_controller_dev *pcdev); 141 142 struct pse_control *of_pse_control_get(struct device_node *node); 143 void pse_control_put(struct pse_control *psec); 144 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); 151 152 bool pse_has_podl(struct pse_control *psec); 153 bool pse_has_c33(struct pse_control *psec); 154 155 #else 156 157 static inline struct pse_control *of_pse_control_get(struct device_node *node) 158 { 159 return ERR_PTR(-ENOENT); 160 } 161 162 static inline void pse_control_put(struct pse_control *psec) 163 { 164 } 165 166 static inline int pse_ethtool_get_status(struct pse_control *psec, 167 struct netlink_ext_ack *extack, 168 struct pse_control_status *status) 169 { 170 return -ENOTSUPP; 171 } 172 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) 176 { 177 return -ENOTSUPP; 178 } 179 180 static inline bool pse_has_podl(struct pse_control *psec) 181 { 182 return false; 183 } 184 185 static inline bool pse_has_c33(struct pse_control *psec) 186 { 187 return false; 188 } 189 190 #endif 191 192 #endif 193