Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generic-phy.h 7.0KB

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