generic-phy.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. * configure - configure a PHY device
  117. *
  118. * @phy: PHY port to be configured
  119. * @params: PHY Parameters, underlying data is specific to the PHY function
  120. *
  121. * During runtime, the PHY may need to be configured for it's main function.
  122. * This function configures the PHY for it's main function following
  123. * power_on/off() after beeing initialized.
  124. *
  125. * Return: 0 if OK, or a negative error code
  126. */
  127. int (*configure)(struct phy *phy, void *params);
  128. };
  129. /**
  130. * struct phy_bulk - A handle to (allowing control of) a bulk of phys.
  131. *
  132. * Consumers provide storage for the phy bulk. The content of the structure is
  133. * managed solely by the phy API. A phy bulk struct is initialized
  134. * by "get"ing the phy bulk struct.
  135. * The phy bulk struct is passed to all other bulk phy APIs to apply
  136. * the API to all the phy in the bulk struct.
  137. *
  138. * @phys: An array of phy handles.
  139. * @count: The number of phy handles in the phys array.
  140. */
  141. struct phy_bulk {
  142. struct phy *phys;
  143. unsigned int count;
  144. };
  145. #ifdef CONFIG_PHY
  146. /**
  147. * generic_phy_init() - initialize the PHY port
  148. *
  149. * @phy: the PHY port to initialize
  150. * Return: 0 if OK, or a negative error code
  151. */
  152. int generic_phy_init(struct phy *phy);
  153. /**
  154. * generic_phy_init() - de-initialize the PHY device
  155. *
  156. * @phy: PHY port to be de-initialized
  157. * Return: 0 if OK, or a negative error code
  158. */
  159. int generic_phy_exit(struct phy *phy);
  160. /**
  161. * generic_phy_reset() - resets a PHY device without shutting down
  162. *
  163. * @phy: PHY port to be reset
  164. *Return: 0 if OK, or a negative error code
  165. */
  166. int generic_phy_reset(struct phy *phy);
  167. /**
  168. * generic_phy_power_on() - power on a PHY device
  169. *
  170. * @phy: PHY port to be powered on
  171. * Return: 0 if OK, or a negative error code
  172. */
  173. int generic_phy_power_on(struct phy *phy);
  174. /**
  175. * generic_phy_power_off() - power off a PHY device
  176. *
  177. * @phy: PHY port to be powered off
  178. * Return: 0 if OK, or a negative error code
  179. */
  180. int generic_phy_power_off(struct phy *phy);
  181. /**
  182. * generic_phy_configure() - configure a PHY device
  183. *
  184. * @phy: PHY port to be configured
  185. * @params: PHY Parameters, underlying data is specific to the PHY function
  186. * Return: 0 if OK, or a negative error code
  187. */
  188. int generic_phy_configure(struct phy *phy, void *params);
  189. /**
  190. * generic_phy_get_by_index() - Get a PHY device by integer index.
  191. *
  192. * @user: the client device
  193. * @index: The index in the list of available PHYs
  194. * @phy: A pointer to the PHY port
  195. *
  196. * This looks up a PHY device for a client device based on its position in the
  197. * list of the possible PHYs.
  198. *
  199. * example:
  200. * usb1: usb_otg_ss@xxx {
  201. * compatible = "xxx";
  202. * reg = <xxx>;
  203. * .
  204. * .
  205. * phys = <&usb2_phy>, <&usb3_phy>;
  206. * .
  207. * .
  208. * };
  209. * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
  210. * be accessed by passing index '1'
  211. *
  212. * Return: 0 if OK, or a negative error code
  213. */
  214. int generic_phy_get_by_index(struct udevice *user, int index,
  215. struct phy *phy);
  216. /**
  217. * generic_phy_get_by_index_nodev() - Get a PHY device by integer index
  218. * without a device
  219. *
  220. * @node: The client ofnode.
  221. * @index: The index in the list of available PHYs
  222. * @phy: A pointer to the PHY port
  223. *
  224. * This is a version of generic_phy_get_by_index() that does not use a device.
  225. *
  226. * This looks up a PHY device for a client device based on its ofnode and on
  227. * its position in the list of the possible PHYs.
  228. *
  229. * example:
  230. * usb1: usb_otg_ss@xxx {
  231. * compatible = "xxx";
  232. * reg = <xxx>;
  233. * .
  234. * .
  235. * phys = <&usb2_phy>, <&usb3_phy>;
  236. * .
  237. * .
  238. * };
  239. * the USB2 phy can be accessed by passing index '0' and the USB3 phy can
  240. * be accessed by passing index '1'
  241. *
  242. * Return: 0 if OK, or a negative error code
  243. */
  244. int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy);
  245. /**
  246. * generic_phy_get_by_name() - Get a PHY device by its name.
  247. *
  248. * @user: the client device
  249. * @phy_name: The name of the PHY in the list of possible PHYs
  250. * @phy: A pointer to the PHY port
  251. *
  252. * This looks up a PHY device for a client device in the
  253. * list of the possible PHYs based on its name.
  254. *
  255. * example:
  256. * usb1: usb_otg_ss@xxx {
  257. * compatible = "xxx";
  258. * reg = <xxx>;
  259. * .
  260. * .
  261. * phys = <&usb2_phy>, <&usb3_phy>;
  262. * phy-names = "usb2phy", "usb3phy";
  263. * .
  264. * .
  265. * };
  266. * the USB3 phy can be accessed using "usb3phy", and USB2 by using "usb2phy"
  267. *
  268. * Return: 0 if OK, or a negative error code
  269. */
  270. int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
  271. struct phy *phy);
  272. /**
  273. * generic_phy_get_bulk - Get all phys of a device.
  274. *
  275. * This looks up and gets all phys of the consumer device; each device is
  276. * assumed to have n phys associated with it somehow, and this function finds
  277. * and gets all of them in a separate structure.
  278. *
  279. * @dev: The consumer device.
  280. * @bulk A pointer to a phy bulk struct to initialize.
  281. * Return: 0 if OK, or a negative error code.
  282. */
  283. int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk);
  284. /**
  285. * generic_phy_init_bulk() - Initialize all phys in a phy bulk struct.
  286. *
  287. * @bulk: A phy bulk struct that was previously successfully requested
  288. * by generic_phy_get_bulk().
  289. * Return: 0 if OK, or negative error code.
  290. */
  291. int generic_phy_init_bulk(struct phy_bulk *bulk);
  292. /**
  293. * generic_phy_exit_bulk() - de-initialize all phys in a phy bulk struct.
  294. *
  295. * @bulk: A phy bulk struct that was previously successfully requested
  296. * by generic_phy_get_bulk().
  297. * Return: 0 if OK, or negative error code.
  298. */
  299. int generic_phy_exit_bulk(struct phy_bulk *bulk);
  300. /**
  301. * generic_phy_power_on_bulk() - Power on all phys in a phy bulk struct.
  302. *
  303. * @bulk: A phy bulk struct that was previously successfully requested
  304. * by generic_phy_get_bulk().
  305. * Return: 0 if OK, or negative error code.
  306. */
  307. int generic_phy_power_on_bulk(struct phy_bulk *bulk);
  308. /**
  309. * generic_phy_power_off_bulk() - Power off all phys in a phy bulk struct.
  310. *
  311. * @bulk: A phy bulk struct that was previously successfully requested
  312. * by generic_phy_get_bulk().
  313. * Return: 0 if OK, or negative error code.
  314. */
  315. int generic_phy_power_off_bulk(struct phy_bulk *bulk);
  316. #else /* CONFIG_PHY */
  317. static inline int generic_phy_init(struct phy *phy)
  318. {
  319. return 0;
  320. }
  321. static inline int generic_phy_exit(struct phy *phy)
  322. {
  323. return 0;
  324. }
  325. static inline int generic_phy_reset(struct phy *phy)
  326. {
  327. return 0;
  328. }
  329. static inline int generic_phy_power_on(struct phy *phy)
  330. {
  331. return 0;
  332. }
  333. static inline int generic_phy_power_off(struct phy *phy)
  334. {
  335. return 0;
  336. }
  337. static inline int generic_phy_get_by_index(struct udevice *user, int index,
  338. struct phy *phy)
  339. {
  340. return 0;
  341. }
  342. static inline int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
  343. struct phy *phy)
  344. {
  345. return 0;
  346. }
  347. static inline int
  348. generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
  349. {
  350. return 0;
  351. }
  352. static inline int generic_phy_init_bulk(struct phy_bulk *bulk)
  353. {
  354. return 0;
  355. }
  356. static inline int generic_phy_exit_bulk(struct phy_bulk *bulk)
  357. {
  358. return 0;
  359. }
  360. static inline int generic_phy_power_on_bulk(struct phy_bulk *bulk)
  361. {
  362. return 0;
  363. }
  364. static inline int generic_phy_power_off_bulk(struct phy_bulk *bulk)
  365. {
  366. return 0;
  367. }
  368. #endif /* CONFIG_PHY */
  369. /**
  370. * generic_phy_valid() - check if PHY port is valid
  371. *
  372. * @phy: the PHY port to check
  373. * Return: TRUE if valid, or FALSE
  374. */
  375. static inline bool generic_phy_valid(struct phy *phy)
  376. {
  377. return phy && phy->dev;
  378. }
  379. #endif /*__GENERIC_PHY_H */