generic-phy.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  4. * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
  5. */
  6. #ifndef __GENERIC_PHY_H
  7. #define __GENERIC_PHY_H
  8. /**
  9. * struct phy - A handle to (allowing control of) a single phy port.
  10. *
  11. * Clients provide storage for phy handles. The content of the structure is
  12. * managed solely by the PHY API and PHY drivers. A phy struct is
  13. * initialized by "get"ing the phy struct. The phy struct is passed to all
  14. * other phy APIs to identify which PHY port to operate upon.
  15. *
  16. * @dev: The device which implements the PHY port.
  17. * @id: The PHY ID within the provider.
  18. *
  19. */
  20. struct phy {
  21. struct udevice *dev;
  22. unsigned long id;
  23. };
  24. /*
  25. * struct udevice_ops - set of function pointers for phy operations
  26. * @init: operation to be performed for initializing phy (optional)
  27. * @exit: operation to be performed while exiting (optional)
  28. * @reset: reset the phy (optional).
  29. * @power_on: powering on the phy (optional)
  30. * @power_off: powering off the phy (optional)
  31. */
  32. struct phy_ops {
  33. /**
  34. * of_xlate - Translate a client's device-tree (OF) phy specifier.
  35. *
  36. * The PHY core calls this function as the first step in implementing
  37. * a client's generic_phy_get_by_*() call.
  38. *
  39. * If this function pointer is set to NULL, the PHY core will use a
  40. * default implementation, which assumes #phy-cells = <0> or
  41. * #phy-cells = <1>, and in the later case that the DT cell
  42. * contains a simple integer PHY port ID.
  43. *
  44. * @phy: The phy struct to hold the translation result.
  45. * @args: The phy specifier values from device tree.
  46. * @return 0 if OK, or a negative error code.
  47. */
  48. int (*of_xlate)(struct phy *phy, struct ofnode_phandle_args *args);
  49. /**
  50. * init - initialize the hardware.
  51. *
  52. * Hardware intialization should not be done in during probe() but
  53. * should be implemented in this init() function. It could be starting
  54. * PLL, taking a controller out of reset, routing, etc. This function
  55. * is typically called only once per PHY port.
  56. * If power_on() is not implemented, it must power up the phy.
  57. *
  58. * @phy: the PHY port to initialize
  59. * @return 0 if OK, or a negative error code.
  60. */
  61. int (*init)(struct phy *phy);
  62. /**
  63. * exit - de-initialize the PHY device
  64. *
  65. * Hardware de-intialization should be done here. Every step done in
  66. * init() should be undone here.
  67. * This could be used to suspend the phy to reduce power consumption or
  68. * to put the phy in a known condition before booting the OS (though it
  69. * is NOT called automatically before booting the OS)
  70. * If power_off() is not implemented, it must power down the phy.
  71. *
  72. * @phy: PHY port to be de-initialized
  73. * @return 0 if OK, or a negative error code
  74. */
  75. int (*exit)(struct phy *phy);
  76. /**
  77. * reset - resets a PHY device without shutting down
  78. *
  79. * @phy: PHY port to be reset
  80. *
  81. * During runtime, the PHY may need to be reset in order to
  82. * re-establish connection etc without being shut down or exit.
  83. *
  84. * @return 0 if OK, or a negative error code
  85. */
  86. int (*reset)(struct phy *phy);
  87. /**
  88. * power_on - power on a PHY device
  89. *
  90. * @phy: PHY port to be powered on
  91. *
  92. * During runtime, the PHY may need to be powered on or off several
  93. * times. This function is used to power on the PHY. It relies on the
  94. * setup done in init(). If init() is not implemented, it must take care
  95. * of setting up the context (PLLs, ...)
  96. *
  97. * @return 0 if OK, or a negative error code
  98. */
  99. int (*power_on)(struct phy *phy);
  100. /**
  101. * power_off - power off a PHY device
  102. *
  103. * @phy: PHY port to be powered off
  104. *
  105. * During runtime, the PHY may need to be powered on or off several
  106. * times. This function is used to power off the PHY. Except if
  107. * init()/deinit() are not implemented, it must not de-initialize
  108. * everything.
  109. *
  110. * @return 0 if OK, or a negative error code
  111. */
  112. int (*power_off)(struct phy *phy);
  113. };
  114. #ifdef CONFIG_PHY
  115. /**
  116. * generic_phy_init() - initialize the PHY port
  117. *
  118. * @phy: the PHY port to initialize
  119. * @return 0 if OK, or a negative error code
  120. */
  121. int generic_phy_init(struct phy *phy);
  122. /**
  123. * generic_phy_init() - de-initialize the PHY device
  124. *
  125. * @phy: PHY port to be de-initialized
  126. * @return 0 if OK, or a negative error code
  127. */
  128. int generic_phy_exit(struct phy *phy);
  129. /**
  130. * generic_phy_reset() - resets a PHY device without shutting down
  131. *
  132. * @phy: PHY port to be reset
  133. *@return 0 if OK, or a negative error code
  134. */
  135. int generic_phy_reset(struct phy *phy);
  136. /**
  137. * generic_phy_power_on() - power on a PHY device
  138. *
  139. * @phy: PHY port to be powered on
  140. * @return 0 if OK, or a negative error code
  141. */
  142. int generic_phy_power_on(struct phy *phy);
  143. /**
  144. * generic_phy_power_off() - power off a PHY device
  145. *
  146. * @phy: PHY port to be powered off
  147. * @return 0 if OK, or a negative error code
  148. */
  149. int generic_phy_power_off(struct phy *phy);
  150. /**
  151. * generic_phy_get_by_index() - Get a PHY device by integer index.
  152. *
  153. * @user: the client device
  154. * @index: The index in the list of available PHYs
  155. * @phy: A pointer to the PHY port
  156. *
  157. * This looks up a PHY device for a client device based on its position in the
  158. * list of the possible PHYs.
  159. *
  160. * example:
  161. * usb1: usb_otg_ss@xxx {
  162. * compatible = "xxx";
  163. * reg = <xxx>;
  164. * .
  165. * .
  166. * phys = <&usb2_phy>, <&usb3_phy>;
  167. * .
  168. * .
  169. * };
  170. * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
  171. * be accessed by passing index '1'
  172. *
  173. * @return 0 if OK, or a negative error code
  174. */
  175. int generic_phy_get_by_index(struct udevice *user, int index,
  176. struct phy *phy);
  177. /**
  178. * generic_phy_get_by_name() - Get a PHY device by its name.
  179. *
  180. * @user: the client device
  181. * @phy_name: The name of the PHY in the list of possible PHYs
  182. * @phy: A pointer to the PHY port
  183. *
  184. * This looks up a PHY device for a client device in the
  185. * list of the possible PHYs based on its name.
  186. *
  187. * example:
  188. * usb1: usb_otg_ss@xxx {
  189. * compatible = "xxx";
  190. * reg = <xxx>;
  191. * .
  192. * .
  193. * phys = <&usb2_phy>, <&usb3_phy>;
  194. * phy-names = "usb2phy", "usb3phy";
  195. * .
  196. * .
  197. * };
  198. * the USB3 phy can be accessed using "usb3phy", and USB2 by using "usb2phy"
  199. *
  200. * @return 0 if OK, or a negative error code
  201. */
  202. int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
  203. struct phy *phy);
  204. #else /* CONFIG_PHY */
  205. static inline int generic_phy_init(struct phy *phy)
  206. {
  207. return 0;
  208. }
  209. static inline int generic_phy_exit(struct phy *phy)
  210. {
  211. return 0;
  212. }
  213. static inline int generic_phy_reset(struct phy *phy)
  214. {
  215. return 0;
  216. }
  217. static inline int generic_phy_power_on(struct phy *phy)
  218. {
  219. return 0;
  220. }
  221. static inline int generic_phy_power_off(struct phy *phy)
  222. {
  223. return 0;
  224. }
  225. static inline int generic_phy_get_by_index(struct udevice *user, int index,
  226. struct phy *phy)
  227. {
  228. return 0;
  229. }
  230. static inline int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
  231. struct phy *phy)
  232. {
  233. return 0;
  234. }
  235. #endif /* CONFIG_PHY */
  236. /**
  237. * generic_phy_valid() - check if PHY port is valid
  238. *
  239. * @phy: the PHY port to check
  240. * @return TRUE if valid, or FALSE
  241. */
  242. static inline bool generic_phy_valid(struct phy *phy)
  243. {
  244. return phy->dev != NULL;
  245. }
  246. #endif /*__GENERIC_PHY_H */