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