phy.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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_attrs - represents phy attributes
  37. * @bus_width: Data path width implemented by PHY
  38. */
  39. struct phy_attrs {
  40. u32 bus_width;
  41. };
  42. /**
  43. * struct phy - represents the phy device
  44. * @dev: phy device
  45. * @id: id of the phy device
  46. * @ops: function pointers for performing phy operations
  47. * @init_data: list of PHY consumers (non-dt only)
  48. * @mutex: mutex to protect phy_ops
  49. * @init_count: used to protect when the PHY is used by multiple consumers
  50. * @power_count: used to protect when the PHY is used by multiple consumers
  51. * @phy_attrs: used to specify PHY specific attributes
  52. */
  53. struct phy {
  54. struct device dev;
  55. int id;
  56. const struct phy_ops *ops;
  57. struct phy_init_data *init_data;
  58. struct mutex mutex;
  59. int init_count;
  60. int power_count;
  61. struct phy_attrs attrs;
  62. };
  63. /**
  64. * struct phy_provider - represents the phy provider
  65. * @dev: phy provider device
  66. * @owner: the module owner having of_xlate
  67. * @of_xlate: function pointer to obtain phy instance from phy pointer
  68. * @list: to maintain a linked list of PHY providers
  69. */
  70. struct phy_provider {
  71. struct device *dev;
  72. struct module *owner;
  73. struct list_head list;
  74. struct phy * (*of_xlate)(struct device *dev,
  75. struct of_phandle_args *args);
  76. };
  77. /**
  78. * struct phy_consumer - represents the phy consumer
  79. * @dev_name: the device name of the controller that will use this PHY device
  80. * @port: name given to the consumer port
  81. */
  82. struct phy_consumer {
  83. const char *dev_name;
  84. const char *port;
  85. };
  86. /**
  87. * struct phy_init_data - contains the list of PHY consumers
  88. * @num_consumers: number of consumers for this PHY device
  89. * @consumers: list of PHY consumers
  90. */
  91. struct phy_init_data {
  92. unsigned int num_consumers;
  93. struct phy_consumer *consumers;
  94. };
  95. #define PHY_CONSUMER(_dev_name, _port) \
  96. { \
  97. .dev_name = _dev_name, \
  98. .port = _port, \
  99. }
  100. #define to_phy(dev) (container_of((dev), struct phy, dev))
  101. #define of_phy_provider_register(dev, xlate) \
  102. __of_phy_provider_register((dev), THIS_MODULE, (xlate))
  103. #define devm_of_phy_provider_register(dev, xlate) \
  104. __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
  105. static inline void phy_set_drvdata(struct phy *phy, void *data)
  106. {
  107. dev_set_drvdata(&phy->dev, data);
  108. }
  109. static inline void *phy_get_drvdata(struct phy *phy)
  110. {
  111. return dev_get_drvdata(&phy->dev);
  112. }
  113. #if IS_ENABLED(CONFIG_GENERIC_PHY)
  114. int phy_pm_runtime_get(struct phy *phy);
  115. int phy_pm_runtime_get_sync(struct phy *phy);
  116. int phy_pm_runtime_put(struct phy *phy);
  117. int phy_pm_runtime_put_sync(struct phy *phy);
  118. void phy_pm_runtime_allow(struct phy *phy);
  119. void phy_pm_runtime_forbid(struct phy *phy);
  120. int phy_init(struct phy *phy);
  121. int phy_exit(struct phy *phy);
  122. int phy_power_on(struct phy *phy);
  123. int phy_power_off(struct phy *phy);
  124. static inline int phy_get_bus_width(struct phy *phy)
  125. {
  126. return phy->attrs.bus_width;
  127. }
  128. static inline void phy_set_bus_width(struct phy *phy, int bus_width)
  129. {
  130. phy->attrs.bus_width = bus_width;
  131. }
  132. struct phy *phy_get(struct device *dev, const char *string);
  133. struct phy *phy_optional_get(struct device *dev, const char *string);
  134. struct phy *devm_phy_get(struct device *dev, const char *string);
  135. struct phy *devm_phy_optional_get(struct device *dev, const char *string);
  136. struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
  137. const char *con_id);
  138. void phy_put(struct phy *phy);
  139. void devm_phy_put(struct device *dev, struct phy *phy);
  140. struct phy *of_phy_get(struct device_node *np, const char *con_id);
  141. struct phy *of_phy_simple_xlate(struct device *dev,
  142. struct of_phandle_args *args);
  143. struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
  144. struct phy_init_data *init_data);
  145. struct phy *devm_phy_create(struct device *dev,
  146. const struct phy_ops *ops, struct phy_init_data *init_data);
  147. void phy_destroy(struct phy *phy);
  148. void devm_phy_destroy(struct device *dev, struct phy *phy);
  149. struct phy_provider *__of_phy_provider_register(struct device *dev,
  150. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  151. struct of_phandle_args *args));
  152. struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
  153. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  154. struct of_phandle_args *args));
  155. void of_phy_provider_unregister(struct phy_provider *phy_provider);
  156. void devm_of_phy_provider_unregister(struct device *dev,
  157. struct phy_provider *phy_provider);
  158. #else
  159. static inline int phy_pm_runtime_get(struct phy *phy)
  160. {
  161. return -ENOSYS;
  162. }
  163. static inline int phy_pm_runtime_get_sync(struct phy *phy)
  164. {
  165. return -ENOSYS;
  166. }
  167. static inline int phy_pm_runtime_put(struct phy *phy)
  168. {
  169. return -ENOSYS;
  170. }
  171. static inline int phy_pm_runtime_put_sync(struct phy *phy)
  172. {
  173. return -ENOSYS;
  174. }
  175. static inline void phy_pm_runtime_allow(struct phy *phy)
  176. {
  177. return;
  178. }
  179. static inline void phy_pm_runtime_forbid(struct phy *phy)
  180. {
  181. return;
  182. }
  183. static inline int phy_init(struct phy *phy)
  184. {
  185. return -ENOSYS;
  186. }
  187. static inline int phy_exit(struct phy *phy)
  188. {
  189. return -ENOSYS;
  190. }
  191. static inline int phy_power_on(struct phy *phy)
  192. {
  193. return -ENOSYS;
  194. }
  195. static inline int phy_power_off(struct phy *phy)
  196. {
  197. return -ENOSYS;
  198. }
  199. static inline int phy_get_bus_width(struct phy *phy)
  200. {
  201. return -ENOSYS;
  202. }
  203. static inline void phy_set_bus_width(struct phy *phy, int bus_width)
  204. {
  205. return;
  206. }
  207. static inline struct phy *phy_get(struct device *dev, const char *string)
  208. {
  209. return ERR_PTR(-ENOSYS);
  210. }
  211. static inline struct phy *phy_optional_get(struct device *dev,
  212. const char *string)
  213. {
  214. return ERR_PTR(-ENOSYS);
  215. }
  216. static inline struct phy *devm_phy_get(struct device *dev, const char *string)
  217. {
  218. return ERR_PTR(-ENOSYS);
  219. }
  220. static inline struct phy *devm_phy_optional_get(struct device *dev,
  221. const char *string)
  222. {
  223. return ERR_PTR(-ENOSYS);
  224. }
  225. static inline struct phy *devm_of_phy_get(struct device *dev,
  226. struct device_node *np,
  227. const char *con_id)
  228. {
  229. return ERR_PTR(-ENOSYS);
  230. }
  231. static inline void phy_put(struct phy *phy)
  232. {
  233. }
  234. static inline void devm_phy_put(struct device *dev, struct phy *phy)
  235. {
  236. }
  237. static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
  238. {
  239. return ERR_PTR(-ENOSYS);
  240. }
  241. static inline struct phy *of_phy_simple_xlate(struct device *dev,
  242. struct of_phandle_args *args)
  243. {
  244. return ERR_PTR(-ENOSYS);
  245. }
  246. static inline struct phy *phy_create(struct device *dev,
  247. const struct phy_ops *ops, struct phy_init_data *init_data)
  248. {
  249. return ERR_PTR(-ENOSYS);
  250. }
  251. static inline struct phy *devm_phy_create(struct device *dev,
  252. const struct phy_ops *ops, struct phy_init_data *init_data)
  253. {
  254. return ERR_PTR(-ENOSYS);
  255. }
  256. static inline void phy_destroy(struct phy *phy)
  257. {
  258. }
  259. static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
  260. {
  261. }
  262. static inline struct phy_provider *__of_phy_provider_register(
  263. struct device *dev, struct module *owner, struct phy * (*of_xlate)(
  264. struct device *dev, struct of_phandle_args *args))
  265. {
  266. return ERR_PTR(-ENOSYS);
  267. }
  268. static inline struct phy_provider *__devm_of_phy_provider_register(struct device
  269. *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  270. struct of_phandle_args *args))
  271. {
  272. return ERR_PTR(-ENOSYS);
  273. }
  274. static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
  275. {
  276. }
  277. static inline void devm_of_phy_provider_unregister(struct device *dev,
  278. struct phy_provider *phy_provider)
  279. {
  280. }
  281. #endif
  282. #endif /* __DRIVERS_PHY_H */