generic-phy.h 7.8 KB

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