phy.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. struct phy_lookup {
  103. struct list_head node;
  104. const char *dev_id;
  105. const char *con_id;
  106. struct phy *phy;
  107. };
  108. #define to_phy(a) (container_of((a), struct phy, dev))
  109. #define of_phy_provider_register(dev, xlate) \
  110. __of_phy_provider_register((dev), THIS_MODULE, (xlate))
  111. #define devm_of_phy_provider_register(dev, xlate) \
  112. __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
  113. static inline void phy_set_drvdata(struct phy *phy, void *data)
  114. {
  115. dev_set_drvdata(&phy->dev, data);
  116. }
  117. static inline void *phy_get_drvdata(struct phy *phy)
  118. {
  119. return dev_get_drvdata(&phy->dev);
  120. }
  121. #if IS_ENABLED(CONFIG_GENERIC_PHY)
  122. int phy_pm_runtime_get(struct phy *phy);
  123. int phy_pm_runtime_get_sync(struct phy *phy);
  124. int phy_pm_runtime_put(struct phy *phy);
  125. int phy_pm_runtime_put_sync(struct phy *phy);
  126. void phy_pm_runtime_allow(struct phy *phy);
  127. void phy_pm_runtime_forbid(struct phy *phy);
  128. int phy_init(struct phy *phy);
  129. int phy_exit(struct phy *phy);
  130. int phy_power_on(struct phy *phy);
  131. int phy_power_off(struct phy *phy);
  132. static inline int phy_get_bus_width(struct phy *phy)
  133. {
  134. return phy->attrs.bus_width;
  135. }
  136. static inline void phy_set_bus_width(struct phy *phy, int bus_width)
  137. {
  138. phy->attrs.bus_width = bus_width;
  139. }
  140. struct phy *phy_get(struct device *dev, const char *string);
  141. struct phy *phy_optional_get(struct device *dev, const char *string);
  142. struct phy *devm_phy_get(struct device *dev, const char *string);
  143. struct phy *devm_phy_optional_get(struct device *dev, const char *string);
  144. struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
  145. const char *con_id);
  146. void phy_put(struct phy *phy);
  147. void devm_phy_put(struct device *dev, struct phy *phy);
  148. struct phy *of_phy_get(struct device_node *np, const char *con_id);
  149. struct phy *of_phy_simple_xlate(struct device *dev,
  150. struct of_phandle_args *args);
  151. struct phy *phy_create(struct device *dev, struct device_node *node,
  152. const struct phy_ops *ops,
  153. struct phy_init_data *init_data);
  154. struct phy *devm_phy_create(struct device *dev, struct device_node *node,
  155. const struct phy_ops *ops, struct phy_init_data *init_data);
  156. void phy_destroy(struct phy *phy);
  157. void devm_phy_destroy(struct device *dev, struct phy *phy);
  158. struct phy_provider *__of_phy_provider_register(struct device *dev,
  159. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  160. struct of_phandle_args *args));
  161. struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
  162. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  163. struct of_phandle_args *args));
  164. void of_phy_provider_unregister(struct phy_provider *phy_provider);
  165. void devm_of_phy_provider_unregister(struct device *dev,
  166. struct phy_provider *phy_provider);
  167. int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
  168. void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
  169. #else
  170. static inline int phy_pm_runtime_get(struct phy *phy)
  171. {
  172. if (!phy)
  173. return 0;
  174. return -ENOSYS;
  175. }
  176. static inline int phy_pm_runtime_get_sync(struct phy *phy)
  177. {
  178. if (!phy)
  179. return 0;
  180. return -ENOSYS;
  181. }
  182. static inline int phy_pm_runtime_put(struct phy *phy)
  183. {
  184. if (!phy)
  185. return 0;
  186. return -ENOSYS;
  187. }
  188. static inline int phy_pm_runtime_put_sync(struct phy *phy)
  189. {
  190. if (!phy)
  191. return 0;
  192. return -ENOSYS;
  193. }
  194. static inline void phy_pm_runtime_allow(struct phy *phy)
  195. {
  196. return;
  197. }
  198. static inline void phy_pm_runtime_forbid(struct phy *phy)
  199. {
  200. return;
  201. }
  202. static inline int phy_init(struct phy *phy)
  203. {
  204. if (!phy)
  205. return 0;
  206. return -ENOSYS;
  207. }
  208. static inline int phy_exit(struct phy *phy)
  209. {
  210. if (!phy)
  211. return 0;
  212. return -ENOSYS;
  213. }
  214. static inline int phy_power_on(struct phy *phy)
  215. {
  216. if (!phy)
  217. return 0;
  218. return -ENOSYS;
  219. }
  220. static inline int phy_power_off(struct phy *phy)
  221. {
  222. if (!phy)
  223. return 0;
  224. return -ENOSYS;
  225. }
  226. static inline int phy_get_bus_width(struct phy *phy)
  227. {
  228. return -ENOSYS;
  229. }
  230. static inline void phy_set_bus_width(struct phy *phy, int bus_width)
  231. {
  232. return;
  233. }
  234. static inline struct phy *phy_get(struct device *dev, const char *string)
  235. {
  236. return ERR_PTR(-ENOSYS);
  237. }
  238. static inline struct phy *phy_optional_get(struct device *dev,
  239. const char *string)
  240. {
  241. return ERR_PTR(-ENOSYS);
  242. }
  243. static inline struct phy *devm_phy_get(struct device *dev, const char *string)
  244. {
  245. return ERR_PTR(-ENOSYS);
  246. }
  247. static inline struct phy *devm_phy_optional_get(struct device *dev,
  248. const char *string)
  249. {
  250. return ERR_PTR(-ENOSYS);
  251. }
  252. static inline struct phy *devm_of_phy_get(struct device *dev,
  253. struct device_node *np,
  254. const char *con_id)
  255. {
  256. return ERR_PTR(-ENOSYS);
  257. }
  258. static inline void phy_put(struct phy *phy)
  259. {
  260. }
  261. static inline void devm_phy_put(struct device *dev, struct phy *phy)
  262. {
  263. }
  264. static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
  265. {
  266. return ERR_PTR(-ENOSYS);
  267. }
  268. static inline struct phy *of_phy_simple_xlate(struct device *dev,
  269. struct of_phandle_args *args)
  270. {
  271. return ERR_PTR(-ENOSYS);
  272. }
  273. static inline struct phy *phy_create(struct device *dev,
  274. struct device_node *node,
  275. const struct phy_ops *ops,
  276. struct phy_init_data *init_data)
  277. {
  278. return ERR_PTR(-ENOSYS);
  279. }
  280. static inline struct phy *devm_phy_create(struct device *dev,
  281. struct device_node *node,
  282. const struct phy_ops *ops,
  283. struct phy_init_data *init_data)
  284. {
  285. return ERR_PTR(-ENOSYS);
  286. }
  287. static inline void phy_destroy(struct phy *phy)
  288. {
  289. }
  290. static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
  291. {
  292. }
  293. static inline struct phy_provider *__of_phy_provider_register(
  294. struct device *dev, struct module *owner, struct phy * (*of_xlate)(
  295. struct device *dev, struct of_phandle_args *args))
  296. {
  297. return ERR_PTR(-ENOSYS);
  298. }
  299. static inline struct phy_provider *__devm_of_phy_provider_register(struct device
  300. *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  301. struct of_phandle_args *args))
  302. {
  303. return ERR_PTR(-ENOSYS);
  304. }
  305. static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
  306. {
  307. }
  308. static inline void devm_of_phy_provider_unregister(struct device *dev,
  309. struct phy_provider *phy_provider)
  310. {
  311. }
  312. static inline int
  313. phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
  314. {
  315. return 0;
  316. }
  317. static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
  318. const char *dev_id) { }
  319. #endif
  320. #endif /* __DRIVERS_PHY_H */