phy.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. PHY SUBSYSTEM
  2. Kishon Vijay Abraham I <kishon@ti.com>
  3. This document explains the Generic PHY Framework along with the APIs provided,
  4. and how-to-use.
  5. 1. Introduction
  6. *PHY* is the abbreviation for physical layer. It is used to connect a device
  7. to the physical medium e.g., the USB controller has a PHY to provide functions
  8. such as serialization, de-serialization, encoding, decoding and is responsible
  9. for obtaining the required data transmission rate. Note that some USB
  10. controllers have PHY functionality embedded into it and others use an external
  11. PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
  12. SATA etc.
  13. The intention of creating this framework is to bring the PHY drivers spread
  14. all over the Linux kernel to drivers/phy to increase code re-use and for
  15. better code maintainability.
  16. This framework will be of use only to devices that use external PHY (PHY
  17. functionality is not embedded within the controller).
  18. 2. Registering/Unregistering the PHY provider
  19. PHY provider refers to an entity that implements one or more PHY instances.
  20. For the simple case where the PHY provider implements only a single instance of
  21. the PHY, the framework provides its own implementation of of_xlate in
  22. of_phy_simple_xlate. If the PHY provider implements multiple instances, it
  23. should provide its own implementation of of_xlate. of_xlate is used only for
  24. dt boot case.
  25. #define of_phy_provider_register(dev, xlate) \
  26. __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
  27. #define devm_of_phy_provider_register(dev, xlate) \
  28. __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
  29. of_phy_provider_register and devm_of_phy_provider_register macros can be used to
  30. register the phy_provider and it takes device and of_xlate as
  31. arguments. For the dt boot case, all PHY providers should use one of the above
  32. 2 macros to register the PHY provider.
  33. Often the device tree nodes associated with a PHY provider will contain a set
  34. of children that each represent a single PHY. Some bindings may nest the child
  35. nodes within extra levels for context and extensibility, in which case the low
  36. level of_phy_provider_register_full() and devm_of_phy_provider_register_full()
  37. macros can be used to override the node containing the children.
  38. #define of_phy_provider_register_full(dev, children, xlate) \
  39. __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
  40. #define devm_of_phy_provider_register_full(dev, children, xlate) \
  41. __devm_of_phy_provider_register_full(dev, children, THIS_MODULE, xlate)
  42. void devm_of_phy_provider_unregister(struct device *dev,
  43. struct phy_provider *phy_provider);
  44. void of_phy_provider_unregister(struct phy_provider *phy_provider);
  45. devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to
  46. unregister the PHY.
  47. 3. Creating the PHY
  48. The PHY driver should create the PHY in order for other peripheral controllers
  49. to make use of it. The PHY framework provides 2 APIs to create the PHY.
  50. struct phy *phy_create(struct device *dev, struct device_node *node,
  51. const struct phy_ops *ops);
  52. struct phy *devm_phy_create(struct device *dev, struct device_node *node,
  53. const struct phy_ops *ops);
  54. The PHY drivers can use one of the above 2 APIs to create the PHY by passing
  55. the device pointer and phy ops.
  56. phy_ops is a set of function pointers for performing PHY operations such as
  57. init, exit, power_on and power_off.
  58. Inorder to dereference the private data (in phy_ops), the phy provider driver
  59. can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in
  60. phy_ops to get back the private data.
  61. 4. Getting a reference to the PHY
  62. Before the controller can make use of the PHY, it has to get a reference to
  63. it. This framework provides the following APIs to get a reference to the PHY.
  64. struct phy *phy_get(struct device *dev, const char *string);
  65. struct phy *phy_optional_get(struct device *dev, const char *string);
  66. struct phy *devm_phy_get(struct device *dev, const char *string);
  67. struct phy *devm_phy_optional_get(struct device *dev, const char *string);
  68. struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
  69. int index);
  70. phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
  71. be used to get the PHY. In the case of dt boot, the string arguments
  72. should contain the phy name as given in the dt data and in the case of
  73. non-dt boot, it should contain the label of the PHY. The two
  74. devm_phy_get associates the device with the PHY using devres on
  75. successful PHY get. On driver detach, release function is invoked on
  76. the the devres data and devres data is freed. phy_optional_get and
  77. devm_phy_optional_get should be used when the phy is optional. These
  78. two functions will never return -ENODEV, but instead returns NULL when
  79. the phy cannot be found.Some generic drivers, such as ehci, may use multiple
  80. phys and for such drivers referencing phy(s) by name(s) does not make sense. In
  81. this case, devm_of_phy_get_by_index can be used to get a phy reference based on
  82. the index.
  83. It should be noted that NULL is a valid phy reference. All phy
  84. consumer calls on the NULL phy become NOPs. That is the release calls,
  85. the phy_init() and phy_exit() calls, and phy_power_on() and
  86. phy_power_off() calls are all NOP when applied to a NULL phy. The NULL
  87. phy is useful in devices for handling optional phy devices.
  88. 5. Releasing a reference to the PHY
  89. When the controller no longer needs the PHY, it has to release the reference
  90. to the PHY it has obtained using the APIs mentioned in the above section. The
  91. PHY framework provides 2 APIs to release a reference to the PHY.
  92. void phy_put(struct phy *phy);
  93. void devm_phy_put(struct device *dev, struct phy *phy);
  94. Both these APIs are used to release a reference to the PHY and devm_phy_put
  95. destroys the devres associated with this PHY.
  96. 6. Destroying the PHY
  97. When the driver that created the PHY is unloaded, it should destroy the PHY it
  98. created using one of the following 2 APIs.
  99. void phy_destroy(struct phy *phy);
  100. void devm_phy_destroy(struct device *dev, struct phy *phy);
  101. Both these APIs destroy the PHY and devm_phy_destroy destroys the devres
  102. associated with this PHY.
  103. 7. PM Runtime
  104. This subsystem is pm runtime enabled. So while creating the PHY,
  105. pm_runtime_enable of the phy device created by this subsystem is called and
  106. while destroying the PHY, pm_runtime_disable is called. Note that the phy
  107. device created by this subsystem will be a child of the device that calls
  108. phy_create (PHY provider device).
  109. So pm_runtime_get_sync of the phy_device created by this subsystem will invoke
  110. pm_runtime_get_sync of PHY provider device because of parent-child relationship.
  111. It should also be noted that phy_power_on and phy_power_off performs
  112. phy_pm_runtime_get_sync and phy_pm_runtime_put respectively.
  113. There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync,
  114. phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and
  115. phy_pm_runtime_forbid for performing PM operations.
  116. 8. PHY Mappings
  117. In order to get reference to a PHY without help from DeviceTree, the framework
  118. offers lookups which can be compared to clkdev that allow clk structures to be
  119. bound to devices. A lookup can be made be made during runtime when a handle to
  120. the struct phy already exists.
  121. The framework offers the following API for registering and unregistering the
  122. lookups.
  123. int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
  124. void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
  125. 9. DeviceTree Binding
  126. The documentation for PHY dt binding can be found @
  127. Documentation/devicetree/bindings/phy/phy-bindings.txt