phy.h 8.6 KB

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