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