]>
Commit | Line | Data |
---|---|---|
ff764963 KVA |
1 | PHY SUBSYSTEM |
2 | Kishon Vijay Abraham I <kishon@ti.com> | |
3 | ||
4 | This document explains the Generic PHY Framework along with the APIs provided, | |
5 | and how-to-use. | |
6 | ||
7 | 1. Introduction | |
8 | ||
9 | *PHY* is the abbreviation for physical layer. It is used to connect a device | |
10 | to the physical medium e.g., the USB controller has a PHY to provide functions | |
11 | such as serialization, de-serialization, encoding, decoding and is responsible | |
12 | for obtaining the required data transmission rate. Note that some USB | |
13 | controllers have PHY functionality embedded into it and others use an external | |
14 | PHY. Other peripherals that use PHY include Wireless LAN, Ethernet, | |
15 | SATA etc. | |
16 | ||
17 | The intention of creating this framework is to bring the PHY drivers spread | |
18 | all over the Linux kernel to drivers/phy to increase code re-use and for | |
19 | better code maintainability. | |
20 | ||
21 | This framework will be of use only to devices that use external PHY (PHY | |
22 | functionality is not embedded within the controller). | |
23 | ||
24 | 2. Registering/Unregistering the PHY provider | |
25 | ||
26 | PHY provider refers to an entity that implements one or more PHY instances. | |
27 | For the simple case where the PHY provider implements only a single instance of | |
28 | the PHY, the framework provides its own implementation of of_xlate in | |
29 | of_phy_simple_xlate. If the PHY provider implements multiple instances, it | |
30 | should provide its own implementation of of_xlate. of_xlate is used only for | |
31 | dt boot case. | |
32 | ||
33 | #define of_phy_provider_register(dev, xlate) \ | |
34 | __of_phy_provider_register((dev), THIS_MODULE, (xlate)) | |
35 | ||
36 | #define devm_of_phy_provider_register(dev, xlate) \ | |
37 | __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate)) | |
38 | ||
39 | of_phy_provider_register and devm_of_phy_provider_register macros can be used to | |
40 | register the phy_provider and it takes device and of_xlate as | |
41 | arguments. For the dt boot case, all PHY providers should use one of the above | |
42 | 2 macros to register the PHY provider. | |
43 | ||
44 | void devm_of_phy_provider_unregister(struct device *dev, | |
45 | struct phy_provider *phy_provider); | |
46 | void of_phy_provider_unregister(struct phy_provider *phy_provider); | |
47 | ||
48 | devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to | |
49 | unregister the PHY. | |
50 | ||
51 | 3. Creating the PHY | |
52 | ||
53 | The PHY driver should create the PHY in order for other peripheral controllers | |
54 | to make use of it. The PHY framework provides 2 APIs to create the PHY. | |
55 | ||
f0ed8176 KVA |
56 | struct phy *phy_create(struct device *dev, struct device_node *node, |
57 | const struct phy_ops *ops, | |
58 | struct phy_init_data *init_data); | |
59 | struct phy *devm_phy_create(struct device *dev, struct device_node *node, | |
60 | const struct phy_ops *ops, | |
61 | struct phy_init_data *init_data); | |
ff764963 KVA |
62 | |
63 | The PHY drivers can use one of the above 2 APIs to create the PHY by passing | |
64 | the device pointer, phy ops and init_data. | |
65 | phy_ops is a set of function pointers for performing PHY operations such as | |
66 | init, exit, power_on and power_off. *init_data* is mandatory to get a reference | |
67 | to the PHY in the case of non-dt boot. See section *Board File Initialization* | |
68 | on how init_data should be used. | |
69 | ||
70 | Inorder to dereference the private data (in phy_ops), the phy provider driver | |
71 | can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in | |
72 | phy_ops to get back the private data. | |
73 | ||
74 | 4. Getting a reference to the PHY | |
75 | ||
76 | Before the controller can make use of the PHY, it has to get a reference to | |
77 | it. This framework provides the following APIs to get a reference to the PHY. | |
78 | ||
79 | struct phy *phy_get(struct device *dev, const char *string); | |
788a4d56 | 80 | struct phy *phy_optional_get(struct device *dev, const char *string); |
ff764963 | 81 | struct phy *devm_phy_get(struct device *dev, const char *string); |
788a4d56 AL |
82 | struct phy *devm_phy_optional_get(struct device *dev, const char *string); |
83 | ||
84 | phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can | |
85 | be used to get the PHY. In the case of dt boot, the string arguments | |
86 | should contain the phy name as given in the dt data and in the case of | |
87 | non-dt boot, it should contain the label of the PHY. The two | |
88 | devm_phy_get associates the device with the PHY using devres on | |
89 | successful PHY get. On driver detach, release function is invoked on | |
90 | the the devres data and devres data is freed. phy_optional_get and | |
91 | devm_phy_optional_get should be used when the phy is optional. These | |
92 | two functions will never return -ENODEV, but instead returns NULL when | |
93 | the phy cannot be found. | |
ff764963 | 94 | |
04c2faca AL |
95 | It should be noted that NULL is a valid phy reference. All phy |
96 | consumer calls on the NULL phy become NOPs. That is the release calls, | |
97 | the phy_init() and phy_exit() calls, and phy_power_on() and | |
98 | phy_power_off() calls are all NOP when applied to a NULL phy. The NULL | |
99 | phy is useful in devices for handling optional phy devices. | |
100 | ||
ff764963 KVA |
101 | 5. Releasing a reference to the PHY |
102 | ||
103 | When the controller no longer needs the PHY, it has to release the reference | |
104 | to the PHY it has obtained using the APIs mentioned in the above section. The | |
105 | PHY framework provides 2 APIs to release a reference to the PHY. | |
106 | ||
107 | void phy_put(struct phy *phy); | |
108 | void devm_phy_put(struct device *dev, struct phy *phy); | |
109 | ||
110 | Both these APIs are used to release a reference to the PHY and devm_phy_put | |
111 | destroys the devres associated with this PHY. | |
112 | ||
113 | 6. Destroying the PHY | |
114 | ||
115 | When the driver that created the PHY is unloaded, it should destroy the PHY it | |
116 | created using one of the following 2 APIs. | |
117 | ||
118 | void phy_destroy(struct phy *phy); | |
119 | void devm_phy_destroy(struct device *dev, struct phy *phy); | |
120 | ||
121 | Both these APIs destroy the PHY and devm_phy_destroy destroys the devres | |
122 | associated with this PHY. | |
123 | ||
124 | 7. PM Runtime | |
125 | ||
126 | This subsystem is pm runtime enabled. So while creating the PHY, | |
127 | pm_runtime_enable of the phy device created by this subsystem is called and | |
128 | while destroying the PHY, pm_runtime_disable is called. Note that the phy | |
129 | device created by this subsystem will be a child of the device that calls | |
130 | phy_create (PHY provider device). | |
131 | ||
132 | So pm_runtime_get_sync of the phy_device created by this subsystem will invoke | |
133 | pm_runtime_get_sync of PHY provider device because of parent-child relationship. | |
134 | It should also be noted that phy_power_on and phy_power_off performs | |
135 | phy_pm_runtime_get_sync and phy_pm_runtime_put respectively. | |
136 | There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync, | |
137 | phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and | |
138 | phy_pm_runtime_forbid for performing PM operations. | |
139 | ||
140 | 8. Board File Initialization | |
141 | ||
142 | Certain board file initialization is necessary in order to get a reference | |
143 | to the PHY in the case of non-dt boot. | |
144 | Say we have a single device that implements 3 PHYs that of USB, SATA and PCIe, | |
145 | then in the board file the following initialization should be done. | |
146 | ||
147 | struct phy_consumer consumers[] = { | |
148 | PHY_CONSUMER("dwc3.0", "usb"), | |
149 | PHY_CONSUMER("pcie.0", "pcie"), | |
150 | PHY_CONSUMER("sata.0", "sata"), | |
151 | }; | |
152 | PHY_CONSUMER takes 2 parameters, first is the device name of the controller | |
153 | (PHY consumer) and second is the port name. | |
154 | ||
155 | struct phy_init_data init_data = { | |
156 | .consumers = consumers, | |
157 | .num_consumers = ARRAY_SIZE(consumers), | |
158 | }; | |
159 | ||
160 | static const struct platform_device pipe3_phy_dev = { | |
161 | .name = "pipe3-phy", | |
162 | .id = -1, | |
163 | .dev = { | |
164 | .platform_data = { | |
165 | .init_data = &init_data, | |
166 | }, | |
167 | }, | |
168 | }; | |
169 | ||
170 | then, while doing phy_create, the PHY driver should pass this init_data | |
171 | phy_create(dev, ops, pdata->init_data); | |
172 | ||
173 | and the controller driver (phy consumer) should pass the port name along with | |
174 | the device to get a reference to the PHY | |
175 | phy_get(dev, "pcie"); | |
176 | ||
177 | 9. DeviceTree Binding | |
178 | ||
179 | The documentation for PHY dt binding can be found @ | |
180 | Documentation/devicetree/bindings/phy/phy-bindings.txt |