1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 /* 1 /* 3 * USB PHY defines 2 * USB PHY defines 4 * 3 * 5 * These APIs may be used between USB controll 4 * These APIs may be used between USB controllers. USB device drivers 6 * (for either host or peripheral roles) don't 5 * (for either host or peripheral roles) don't use these calls; they 7 * continue to use just usb_device and usb_gad 6 * continue to use just usb_device and usb_gadget. 8 */ 7 */ 9 8 10 #ifndef __LINUX_USB_PHY_H 9 #ifndef __LINUX_USB_PHY_H 11 #define __LINUX_USB_PHY_H 10 #define __LINUX_USB_PHY_H 12 11 13 #include <linux/extcon.h> 12 #include <linux/extcon.h> 14 #include <linux/notifier.h> 13 #include <linux/notifier.h> 15 #include <linux/usb.h> 14 #include <linux/usb.h> 16 #include <uapi/linux/usb/charger.h> << 17 15 18 enum usb_phy_interface { 16 enum usb_phy_interface { 19 USBPHY_INTERFACE_MODE_UNKNOWN, 17 USBPHY_INTERFACE_MODE_UNKNOWN, 20 USBPHY_INTERFACE_MODE_UTMI, 18 USBPHY_INTERFACE_MODE_UTMI, 21 USBPHY_INTERFACE_MODE_UTMIW, 19 USBPHY_INTERFACE_MODE_UTMIW, 22 USBPHY_INTERFACE_MODE_ULPI, 20 USBPHY_INTERFACE_MODE_ULPI, 23 USBPHY_INTERFACE_MODE_SERIAL, 21 USBPHY_INTERFACE_MODE_SERIAL, 24 USBPHY_INTERFACE_MODE_HSIC, 22 USBPHY_INTERFACE_MODE_HSIC, 25 }; 23 }; 26 24 27 enum usb_phy_events { 25 enum usb_phy_events { 28 USB_EVENT_NONE, /* no events o 26 USB_EVENT_NONE, /* no events or cable disconnected */ 29 USB_EVENT_VBUS, /* vbus valid 27 USB_EVENT_VBUS, /* vbus valid event */ 30 USB_EVENT_ID, /* id was grou 28 USB_EVENT_ID, /* id was grounded */ 31 USB_EVENT_CHARGER, /* usb dedicat 29 USB_EVENT_CHARGER, /* usb dedicated charger */ 32 USB_EVENT_ENUMERATED, /* gadget driv 30 USB_EVENT_ENUMERATED, /* gadget driver enumerated */ 33 }; 31 }; 34 32 35 /* associate a type with PHY */ 33 /* associate a type with PHY */ 36 enum usb_phy_type { 34 enum usb_phy_type { 37 USB_PHY_TYPE_UNDEFINED, 35 USB_PHY_TYPE_UNDEFINED, 38 USB_PHY_TYPE_USB2, 36 USB_PHY_TYPE_USB2, 39 USB_PHY_TYPE_USB3, 37 USB_PHY_TYPE_USB3, 40 }; 38 }; 41 39 42 /* OTG defines lots of enumeration states befo 40 /* OTG defines lots of enumeration states before device reset */ 43 enum usb_otg_state { 41 enum usb_otg_state { 44 OTG_STATE_UNDEFINED = 0, 42 OTG_STATE_UNDEFINED = 0, 45 43 46 /* single-role peripheral, and dual-ro 44 /* single-role peripheral, and dual-role default-b */ 47 OTG_STATE_B_IDLE, 45 OTG_STATE_B_IDLE, 48 OTG_STATE_B_SRP_INIT, 46 OTG_STATE_B_SRP_INIT, 49 OTG_STATE_B_PERIPHERAL, 47 OTG_STATE_B_PERIPHERAL, 50 48 51 /* extra dual-role default-b states */ 49 /* extra dual-role default-b states */ 52 OTG_STATE_B_WAIT_ACON, 50 OTG_STATE_B_WAIT_ACON, 53 OTG_STATE_B_HOST, 51 OTG_STATE_B_HOST, 54 52 55 /* dual-role default-a */ 53 /* dual-role default-a */ 56 OTG_STATE_A_IDLE, 54 OTG_STATE_A_IDLE, 57 OTG_STATE_A_WAIT_VRISE, 55 OTG_STATE_A_WAIT_VRISE, 58 OTG_STATE_A_WAIT_BCON, 56 OTG_STATE_A_WAIT_BCON, 59 OTG_STATE_A_HOST, 57 OTG_STATE_A_HOST, 60 OTG_STATE_A_SUSPEND, 58 OTG_STATE_A_SUSPEND, 61 OTG_STATE_A_PERIPHERAL, 59 OTG_STATE_A_PERIPHERAL, 62 OTG_STATE_A_WAIT_VFALL, 60 OTG_STATE_A_WAIT_VFALL, 63 OTG_STATE_A_VBUS_ERR, 61 OTG_STATE_A_VBUS_ERR, 64 }; 62 }; 65 63 66 struct usb_phy; 64 struct usb_phy; 67 struct usb_otg; 65 struct usb_otg; 68 66 69 /* for phys connected thru an ULPI interface, 67 /* for phys connected thru an ULPI interface, the user must 70 * provide access ops 68 * provide access ops 71 */ 69 */ 72 struct usb_phy_io_ops { 70 struct usb_phy_io_ops { 73 int (*read)(struct usb_phy *x, u32 reg 71 int (*read)(struct usb_phy *x, u32 reg); 74 int (*write)(struct usb_phy *x, u32 va 72 int (*write)(struct usb_phy *x, u32 val, u32 reg); 75 }; 73 }; 76 74 77 struct usb_charger_current { << 78 unsigned int sdp_min; << 79 unsigned int sdp_max; << 80 unsigned int dcp_min; << 81 unsigned int dcp_max; << 82 unsigned int cdp_min; << 83 unsigned int cdp_max; << 84 unsigned int aca_min; << 85 unsigned int aca_max; << 86 }; << 87 << 88 struct usb_phy { 75 struct usb_phy { 89 struct device *dev; 76 struct device *dev; 90 const char *label; 77 const char *label; 91 unsigned int flags; 78 unsigned int flags; 92 79 93 enum usb_phy_type type; 80 enum usb_phy_type type; 94 enum usb_phy_events last_event; 81 enum usb_phy_events last_event; 95 82 96 struct usb_otg *otg; 83 struct usb_otg *otg; 97 84 98 struct device *io_dev; 85 struct device *io_dev; 99 struct usb_phy_io_ops *io_ops; 86 struct usb_phy_io_ops *io_ops; 100 void __iomem *io_priv; 87 void __iomem *io_priv; 101 88 102 /* to support extcon device */ 89 /* to support extcon device */ 103 struct extcon_dev *edev; 90 struct extcon_dev *edev; 104 struct extcon_dev *id_edev; 91 struct extcon_dev *id_edev; 105 struct notifier_block vbus_nb; 92 struct notifier_block vbus_nb; 106 struct notifier_block id_nb; 93 struct notifier_block id_nb; 107 struct notifier_block type_nb; << 108 << 109 /* Support USB charger */ << 110 enum usb_charger_type chg_type; << 111 enum usb_charger_state chg_state; << 112 struct usb_charger_current chg_cu << 113 struct work_struct chg_wo << 114 94 115 /* for notification of usb_phy_events 95 /* for notification of usb_phy_events */ 116 struct atomic_notifier_head notifi 96 struct atomic_notifier_head notifier; 117 97 118 /* to pass extra port status to the ro 98 /* to pass extra port status to the root hub */ 119 u16 port_status; 99 u16 port_status; 120 u16 port_change; 100 u16 port_change; 121 101 122 /* to support controllers that have mu 102 /* to support controllers that have multiple phys */ 123 struct list_head head; 103 struct list_head head; 124 104 125 /* initialize/shutdown the phy */ 105 /* initialize/shutdown the phy */ 126 int (*init)(struct usb_phy *x); 106 int (*init)(struct usb_phy *x); 127 void (*shutdown)(struct usb_phy *x) 107 void (*shutdown)(struct usb_phy *x); 128 108 129 /* enable/disable VBUS */ 109 /* enable/disable VBUS */ 130 int (*set_vbus)(struct usb_phy *x, 110 int (*set_vbus)(struct usb_phy *x, int on); 131 111 132 /* effective for B devices, ignored fo 112 /* effective for B devices, ignored for A-peripheral */ 133 int (*set_power)(struct usb_phy *x 113 int (*set_power)(struct usb_phy *x, 134 unsigned mA); 114 unsigned mA); 135 115 136 /* Set phy into suspend mode */ 116 /* Set phy into suspend mode */ 137 int (*set_suspend)(struct usb_phy 117 int (*set_suspend)(struct usb_phy *x, 138 int suspend); 118 int suspend); 139 119 140 /* 120 /* 141 * Set wakeup enable for PHY, in that 121 * Set wakeup enable for PHY, in that case, the PHY can be 142 * woken up from suspend status due to 122 * woken up from suspend status due to external events, 143 * like vbus change, dp/dm change and 123 * like vbus change, dp/dm change and id. 144 */ 124 */ 145 int (*set_wakeup)(struct usb_phy * 125 int (*set_wakeup)(struct usb_phy *x, bool enabled); 146 126 147 /* notify phy connect status change */ 127 /* notify phy connect status change */ 148 int (*notify_connect)(struct usb_p 128 int (*notify_connect)(struct usb_phy *x, 149 enum usb_device_speed 129 enum usb_device_speed speed); 150 int (*notify_disconnect)(struct us 130 int (*notify_disconnect)(struct usb_phy *x, 151 enum usb_device_speed 131 enum usb_device_speed speed); >> 132 }; 152 133 153 /* !! 134 /** 154 * Charger detection method can be imp !! 135 * struct usb_phy_bind - represent the binding for the phy 155 * manually detect the charger type. !! 136 * @dev_name: the device name of the device that will bind to the phy 156 */ !! 137 * @phy_dev_name: the device name of the phy 157 enum usb_charger_type (*charger_detect !! 138 * @index: used if a single controller uses multiple phys >> 139 * @phy: reference to the phy >> 140 * @list: to maintain a linked list of the binding information >> 141 */ >> 142 struct usb_phy_bind { >> 143 const char *dev_name; >> 144 const char *phy_dev_name; >> 145 u8 index; >> 146 struct usb_phy *phy; >> 147 struct list_head list; 158 }; 148 }; 159 149 160 /* for board-specific init logic */ 150 /* for board-specific init logic */ 161 extern int usb_add_phy(struct usb_phy *, enum 151 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type); 162 extern int usb_add_phy_dev(struct usb_phy *); 152 extern int usb_add_phy_dev(struct usb_phy *); 163 extern void usb_remove_phy(struct usb_phy *); 153 extern void usb_remove_phy(struct usb_phy *); 164 154 165 /* helpers for direct access thru low-level io 155 /* helpers for direct access thru low-level io interface */ 166 static inline int usb_phy_io_read(struct usb_p 156 static inline int usb_phy_io_read(struct usb_phy *x, u32 reg) 167 { 157 { 168 if (x && x->io_ops && x->io_ops->read) 158 if (x && x->io_ops && x->io_ops->read) 169 return x->io_ops->read(x, reg) 159 return x->io_ops->read(x, reg); 170 160 171 return -EINVAL; 161 return -EINVAL; 172 } 162 } 173 163 174 static inline int usb_phy_io_write(struct usb_ 164 static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg) 175 { 165 { 176 if (x && x->io_ops && x->io_ops->write 166 if (x && x->io_ops && x->io_ops->write) 177 return x->io_ops->write(x, val 167 return x->io_ops->write(x, val, reg); 178 168 179 return -EINVAL; 169 return -EINVAL; 180 } 170 } 181 171 182 static inline int 172 static inline int 183 usb_phy_init(struct usb_phy *x) 173 usb_phy_init(struct usb_phy *x) 184 { 174 { 185 if (x && x->init) 175 if (x && x->init) 186 return x->init(x); 176 return x->init(x); 187 177 188 return 0; 178 return 0; 189 } 179 } 190 180 191 static inline void 181 static inline void 192 usb_phy_shutdown(struct usb_phy *x) 182 usb_phy_shutdown(struct usb_phy *x) 193 { 183 { 194 if (x && x->shutdown) 184 if (x && x->shutdown) 195 x->shutdown(x); 185 x->shutdown(x); 196 } 186 } 197 187 198 static inline int 188 static inline int 199 usb_phy_vbus_on(struct usb_phy *x) 189 usb_phy_vbus_on(struct usb_phy *x) 200 { 190 { 201 if (!x || !x->set_vbus) 191 if (!x || !x->set_vbus) 202 return 0; 192 return 0; 203 193 204 return x->set_vbus(x, true); 194 return x->set_vbus(x, true); 205 } 195 } 206 196 207 static inline int 197 static inline int 208 usb_phy_vbus_off(struct usb_phy *x) 198 usb_phy_vbus_off(struct usb_phy *x) 209 { 199 { 210 if (!x || !x->set_vbus) 200 if (!x || !x->set_vbus) 211 return 0; 201 return 0; 212 202 213 return x->set_vbus(x, false); 203 return x->set_vbus(x, false); 214 } 204 } 215 205 216 /* for usb host and peripheral controller driv 206 /* for usb host and peripheral controller drivers */ 217 #if IS_ENABLED(CONFIG_USB_PHY) 207 #if IS_ENABLED(CONFIG_USB_PHY) 218 extern struct usb_phy *usb_get_phy(enum usb_ph 208 extern struct usb_phy *usb_get_phy(enum usb_phy_type type); 219 extern struct usb_phy *devm_usb_get_phy(struct 209 extern struct usb_phy *devm_usb_get_phy(struct device *dev, 220 enum usb_phy_type type); 210 enum usb_phy_type type); >> 211 extern struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index); >> 212 extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index); 221 extern struct usb_phy *devm_usb_get_phy_by_pha 213 extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 222 const char *phandle, u8 index); 214 const char *phandle, u8 index); 223 extern struct usb_phy *devm_usb_get_phy_by_nod 215 extern struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, 224 struct device_node *node, struct notif 216 struct device_node *node, struct notifier_block *nb); 225 extern void usb_put_phy(struct usb_phy *); 217 extern void usb_put_phy(struct usb_phy *); 226 extern void devm_usb_put_phy(struct device *de 218 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); >> 219 extern int usb_bind_phy(const char *dev_name, u8 index, >> 220 const char *phy_dev_name); 227 extern void usb_phy_set_event(struct usb_phy * 221 extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); 228 extern void usb_phy_set_charger_current(struct << 229 unsign << 230 extern void usb_phy_get_charger_current(struct << 231 unsign << 232 extern void usb_phy_set_charger_state(struct u << 233 enum usb << 234 #else 222 #else 235 static inline struct usb_phy *usb_get_phy(enum 223 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 236 { 224 { 237 return ERR_PTR(-ENXIO); 225 return ERR_PTR(-ENXIO); 238 } 226 } 239 227 240 static inline struct usb_phy *devm_usb_get_phy 228 static inline struct usb_phy *devm_usb_get_phy(struct device *dev, 241 enum usb_phy_type type) 229 enum usb_phy_type type) 242 { 230 { 243 return ERR_PTR(-ENXIO); 231 return ERR_PTR(-ENXIO); 244 } 232 } 245 233 246 static inline struct usb_phy *devm_usb_get_phy !! 234 static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index) 247 const char *phandle, u8 index) << 248 { 235 { 249 return ERR_PTR(-ENXIO); 236 return ERR_PTR(-ENXIO); 250 } 237 } 251 238 252 static inline struct usb_phy *devm_usb_get_phy !! 239 static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index) 253 struct device_node *node, struct notif << 254 { 240 { 255 return ERR_PTR(-ENXIO); 241 return ERR_PTR(-ENXIO); 256 } 242 } 257 243 258 static inline void usb_put_phy(struct usb_phy !! 244 static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, >> 245 const char *phandle, u8 index) 259 { 246 { >> 247 return ERR_PTR(-ENXIO); 260 } 248 } 261 249 262 static inline void devm_usb_put_phy(struct dev !! 250 static inline struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, >> 251 struct device_node *node, struct notifier_block *nb) 263 { 252 { >> 253 return ERR_PTR(-ENXIO); 264 } 254 } 265 255 266 static inline void usb_phy_set_event(struct us !! 256 static inline void usb_put_phy(struct usb_phy *x) 267 { 257 { 268 } 258 } 269 259 270 static inline void usb_phy_set_charger_current !! 260 static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x) 271 << 272 { 261 { 273 } 262 } 274 263 275 static inline void usb_phy_get_charger_current !! 264 static inline int usb_bind_phy(const char *dev_name, u8 index, 276 !! 265 const char *phy_dev_name) 277 << 278 { 266 { >> 267 return -EOPNOTSUPP; 279 } 268 } 280 269 281 static inline void usb_phy_set_charger_state(s !! 270 static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) 282 e << 283 { 271 { 284 } 272 } 285 #endif 273 #endif 286 274 287 static inline int 275 static inline int 288 usb_phy_set_power(struct usb_phy *x, unsigned 276 usb_phy_set_power(struct usb_phy *x, unsigned mA) 289 { 277 { 290 if (!x) !! 278 if (x && x->set_power) 291 return 0; << 292 << 293 usb_phy_set_charger_current(x, mA); << 294 << 295 if (x->set_power) << 296 return x->set_power(x, mA); 279 return x->set_power(x, mA); 297 return 0; 280 return 0; 298 } 281 } 299 282 300 /* Context: can sleep */ 283 /* Context: can sleep */ 301 static inline int 284 static inline int 302 usb_phy_set_suspend(struct usb_phy *x, int sus 285 usb_phy_set_suspend(struct usb_phy *x, int suspend) 303 { 286 { 304 if (x && x->set_suspend != NULL) 287 if (x && x->set_suspend != NULL) 305 return x->set_suspend(x, suspe 288 return x->set_suspend(x, suspend); 306 else 289 else 307 return 0; 290 return 0; 308 } 291 } 309 292 310 static inline int 293 static inline int 311 usb_phy_set_wakeup(struct usb_phy *x, bool ena 294 usb_phy_set_wakeup(struct usb_phy *x, bool enabled) 312 { 295 { 313 if (x && x->set_wakeup) 296 if (x && x->set_wakeup) 314 return x->set_wakeup(x, enable 297 return x->set_wakeup(x, enabled); 315 else 298 else 316 return 0; 299 return 0; 317 } 300 } 318 301 319 static inline int 302 static inline int 320 usb_phy_notify_connect(struct usb_phy *x, enum 303 usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed) 321 { 304 { 322 if (x && x->notify_connect) 305 if (x && x->notify_connect) 323 return x->notify_connect(x, sp 306 return x->notify_connect(x, speed); 324 else 307 else 325 return 0; 308 return 0; 326 } 309 } 327 310 328 static inline int 311 static inline int 329 usb_phy_notify_disconnect(struct usb_phy *x, e 312 usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed) 330 { 313 { 331 if (x && x->notify_disconnect) 314 if (x && x->notify_disconnect) 332 return x->notify_disconnect(x, 315 return x->notify_disconnect(x, speed); 333 else 316 else 334 return 0; 317 return 0; 335 } 318 } 336 319 337 /* notifiers */ 320 /* notifiers */ 338 static inline int 321 static inline int 339 usb_register_notifier(struct usb_phy *x, struc 322 usb_register_notifier(struct usb_phy *x, struct notifier_block *nb) 340 { 323 { 341 return atomic_notifier_chain_register( 324 return atomic_notifier_chain_register(&x->notifier, nb); 342 } 325 } 343 326 344 static inline void 327 static inline void 345 usb_unregister_notifier(struct usb_phy *x, str 328 usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb) 346 { 329 { 347 atomic_notifier_chain_unregister(&x->n 330 atomic_notifier_chain_unregister(&x->notifier, nb); 348 } 331 } 349 332 350 static inline const char *usb_phy_type_string( 333 static inline const char *usb_phy_type_string(enum usb_phy_type type) 351 { 334 { 352 switch (type) { 335 switch (type) { 353 case USB_PHY_TYPE_USB2: 336 case USB_PHY_TYPE_USB2: 354 return "USB2 PHY"; 337 return "USB2 PHY"; 355 case USB_PHY_TYPE_USB3: 338 case USB_PHY_TYPE_USB3: 356 return "USB3 PHY"; 339 return "USB3 PHY"; 357 default: 340 default: 358 return "UNKNOWN PHY TYPE"; 341 return "UNKNOWN PHY TYPE"; 359 } 342 } 360 } 343 } 361 #endif /* __LINUX_USB_PHY_H */ 344 #endif /* __LINUX_USB_PHY_H */ 362 345
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.