phy.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * phy.h -- generic phy header file
  3. *
  4. * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef __DRIVERS_PHY_H
  14. #define __DRIVERS_PHY_H
  15. #include <linux/err.h>
  16. #include <linux/of.h>
  17. #include <linux/device.h>
  18. #include <linux/pm_runtime.h>
  19. struct phy;
  20. /**
  21. * struct phy_ops - set of function pointers for performing phy operations
  22. * @init: operation to be performed for initializing phy
  23. * @exit: operation to be performed while exiting
  24. * @power_on: powering on the phy
  25. * @power_off: powering off the phy
  26. * @owner: the module owner containing the ops
  27. */
  28. struct phy_ops {
  29. int (*init)(struct phy *phy);
  30. int (*exit)(struct phy *phy);
  31. int (*power_on)(struct phy *phy);
  32. int (*power_off)(struct phy *phy);
  33. struct module *owner;
  34. };
  35. /**
  36. * struct phy - represents the phy device
  37. * @dev: phy device
  38. * @id: id of the phy device
  39. * @ops: function pointers for performing phy operations
  40. * @init_data: list of PHY consumers (non-dt only)
  41. * @mutex: mutex to protect phy_ops
  42. * @init_count: used to protect when the PHY is used by multiple consumers
  43. * @power_count: used to protect when the PHY is used by multiple consumers
  44. */
  45. struct phy {
  46. struct device dev;
  47. int id;
  48. const struct phy_ops *ops;
  49. struct phy_init_data *init_data;
  50. struct mutex mutex;
  51. int init_count;
  52. int power_count;
  53. };
  54. /**
  55. * struct phy_provider - represents the phy provider
  56. * @dev: phy provider device
  57. * @owner: the module owner having of_xlate
  58. * @of_xlate: function pointer to obtain phy instance from phy pointer
  59. * @list: to maintain a linked list of PHY providers
  60. */
  61. struct phy_provider {
  62. struct device *dev;
  63. struct module *owner;
  64. struct list_head list;
  65. struct phy * (*of_xlate)(struct device *dev,
  66. struct of_phandle_args *args);
  67. };
  68. /**
  69. * struct phy_consumer - represents the phy consumer
  70. * @dev_name: the device name of the controller that will use this PHY device
  71. * @port: name given to the consumer port
  72. */
  73. struct phy_consumer {
  74. const char *dev_name;
  75. const char *port;
  76. };
  77. /**
  78. * struct phy_init_data - contains the list of PHY consumers
  79. * @num_consumers: number of consumers for this PHY device
  80. * @consumers: list of PHY consumers
  81. */
  82. struct phy_init_data {
  83. unsigned int num_consumers;
  84. struct phy_consumer *consumers;
  85. };
  86. #define PHY_CONSUMER(_dev_name, _port) \
  87. { \
  88. .dev_name = _dev_name, \
  89. .port = _port, \
  90. }
  91. #define to_phy(dev) (container_of((dev), struct phy, dev))
  92. #define of_phy_provider_register(dev, xlate) \
  93. __of_phy_provider_register((dev), THIS_MODULE, (xlate))
  94. #define devm_of_phy_provider_register(dev, xlate) \
  95. __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
  96. static inline void phy_set_drvdata(struct phy *phy, void *data)
  97. {
  98. dev_set_drvdata(&phy->dev, data);
  99. }
  100. static inline void *phy_get_drvdata(struct phy *phy)
  101. {
  102. return dev_get_drvdata(&phy->dev);
  103. }
  104. #if IS_ENABLED(CONFIG_GENERIC_PHY)
  105. int phy_pm_runtime_get(struct phy *phy);
  106. int phy_pm_runtime_get_sync(struct phy *phy);
  107. int phy_pm_runtime_put(struct phy *phy);
  108. int phy_pm_runtime_put_sync(struct phy *phy);
  109. void phy_pm_runtime_allow(struct phy *phy);
  110. void phy_pm_runtime_forbid(struct phy *phy);
  111. int phy_init(struct phy *phy);
  112. int phy_exit(struct phy *phy);
  113. int phy_power_on(struct phy *phy);
  114. int phy_power_off(struct phy *phy);
  115. struct phy *phy_get(struct device *dev, const char *string);
  116. struct phy *devm_phy_get(struct device *dev, const char *string);
  117. void phy_put(struct phy *phy);
  118. void devm_phy_put(struct device *dev, struct phy *phy);
  119. struct phy *of_phy_simple_xlate(struct device *dev,
  120. struct of_phandle_args *args);
  121. struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
  122. struct phy_init_data *init_data);
  123. struct phy *devm_phy_create(struct device *dev,
  124. const struct phy_ops *ops, struct phy_init_data *init_data);
  125. void phy_destroy(struct phy *phy);
  126. void devm_phy_destroy(struct device *dev, struct phy *phy);
  127. struct phy_provider *__of_phy_provider_register(struct device *dev,
  128. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  129. struct of_phandle_args *args));
  130. struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
  131. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  132. struct of_phandle_args *args));
  133. void of_phy_provider_unregister(struct phy_provider *phy_provider);
  134. void devm_of_phy_provider_unregister(struct device *dev,
  135. struct phy_provider *phy_provider);
  136. #else
  137. static inline int phy_pm_runtime_get(struct phy *phy)
  138. {
  139. return -ENOSYS;
  140. }
  141. static inline int phy_pm_runtime_get_sync(struct phy *phy)
  142. {
  143. return -ENOSYS;
  144. }
  145. static inline int phy_pm_runtime_put(struct phy *phy)
  146. {
  147. return -ENOSYS;
  148. }
  149. static inline int phy_pm_runtime_put_sync(struct phy *phy)
  150. {
  151. return -ENOSYS;
  152. }
  153. static inline void phy_pm_runtime_allow(struct phy *phy)
  154. {
  155. return;
  156. }
  157. static inline void phy_pm_runtime_forbid(struct phy *phy)
  158. {
  159. return;
  160. }
  161. static inline int phy_init(struct phy *phy)
  162. {
  163. return -ENOSYS;
  164. }
  165. static inline int phy_exit(struct phy *phy)
  166. {
  167. return -ENOSYS;
  168. }
  169. static inline int phy_power_on(struct phy *phy)
  170. {
  171. return -ENOSYS;
  172. }
  173. static inline int phy_power_off(struct phy *phy)
  174. {
  175. return -ENOSYS;
  176. }
  177. static inline struct phy *phy_get(struct device *dev, const char *string)
  178. {
  179. return ERR_PTR(-ENOSYS);
  180. }
  181. static inline struct phy *devm_phy_get(struct device *dev, const char *string)
  182. {
  183. return ERR_PTR(-ENOSYS);
  184. }
  185. static inline void phy_put(struct phy *phy)
  186. {
  187. }
  188. static inline void devm_phy_put(struct device *dev, struct phy *phy)
  189. {
  190. }
  191. static inline struct phy *of_phy_simple_xlate(struct device *dev,
  192. struct of_phandle_args *args)
  193. {
  194. return ERR_PTR(-ENOSYS);
  195. }
  196. static inline struct phy *phy_create(struct device *dev,
  197. const struct phy_ops *ops, struct phy_init_data *init_data)
  198. {
  199. return ERR_PTR(-ENOSYS);
  200. }
  201. static inline struct phy *devm_phy_create(struct device *dev,
  202. const struct phy_ops *ops, struct phy_init_data *init_data)
  203. {
  204. return ERR_PTR(-ENOSYS);
  205. }
  206. static inline void phy_destroy(struct phy *phy)
  207. {
  208. }
  209. static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
  210. {
  211. }
  212. static inline struct phy_provider *__of_phy_provider_register(
  213. struct device *dev, struct module *owner, struct phy * (*of_xlate)(
  214. struct device *dev, struct of_phandle_args *args))
  215. {
  216. return ERR_PTR(-ENOSYS);
  217. }
  218. static inline struct phy_provider *__devm_of_phy_provider_register(struct device
  219. *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  220. struct of_phandle_args *args))
  221. {
  222. return ERR_PTR(-ENOSYS);
  223. }
  224. static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
  225. {
  226. }
  227. static inline void devm_of_phy_provider_unregister(struct device *dev,
  228. struct phy_provider *phy_provider)
  229. {
  230. }
  231. #endif
  232. #endif /* __DRIVERS_PHY_H */