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 | 56 | struct phy *phy_create(struct device *dev, struct device_node *node, |
b7bc15b9 | 57 | const struct phy_ops *ops); |
f0ed8176 | 58 | struct phy *devm_phy_create(struct device *dev, struct device_node *node, |
b7bc15b9 | 59 | const struct phy_ops *ops); |
ff764963 KVA |
60 | |
61 | The PHY drivers can use one of the above 2 APIs to create the PHY by passing | |
b7bc15b9 | 62 | the device pointer and phy ops. |
ff764963 | 63 | phy_ops is a set of function pointers for performing PHY operations such as |
b7bc15b9 | 64 | init, exit, power_on and power_off. |
ff764963 KVA |
65 | |
66 | Inorder to dereference the private data (in phy_ops), the phy provider driver | |
67 | can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in | |
68 | phy_ops to get back the private data. | |
69 | ||
70 | 4. Getting a reference to the PHY | |
71 | ||
72 | Before the controller can make use of the PHY, it has to get a reference to | |
73 | it. This framework provides the following APIs to get a reference to the PHY. | |
74 | ||
75 | struct phy *phy_get(struct device *dev, const char *string); | |
788a4d56 | 76 | struct phy *phy_optional_get(struct device *dev, const char *string); |
ff764963 | 77 | struct phy *devm_phy_get(struct device *dev, const char *string); |
788a4d56 | 78 | struct phy *devm_phy_optional_get(struct device *dev, const char *string); |
6be109b3 AR |
79 | struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, |
80 | int index); | |
788a4d56 AL |
81 | |
82 | phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can | |
83 | be used to get the PHY. In the case of dt boot, the string arguments | |
84 | should contain the phy name as given in the dt data and in the case of | |
85 | non-dt boot, it should contain the label of the PHY. The two | |
86 | devm_phy_get associates the device with the PHY using devres on | |
87 | successful PHY get. On driver detach, release function is invoked on | |
88 | the the devres data and devres data is freed. phy_optional_get and | |
89 | devm_phy_optional_get should be used when the phy is optional. These | |
90 | two functions will never return -ENODEV, but instead returns NULL when | |
6be109b3 AR |
91 | the phy cannot be found.Some generic drivers, such as ehci, may use multiple |
92 | phys and for such drivers referencing phy(s) by name(s) does not make sense. In | |
93 | this case, devm_of_phy_get_by_index can be used to get a phy reference based on | |
94 | the index. | |
ff764963 | 95 | |
04c2faca AL |
96 | It should be noted that NULL is a valid phy reference. All phy |
97 | consumer calls on the NULL phy become NOPs. That is the release calls, | |
98 | the phy_init() and phy_exit() calls, and phy_power_on() and | |
99 | phy_power_off() calls are all NOP when applied to a NULL phy. The NULL | |
100 | phy is useful in devices for handling optional phy devices. | |
101 | ||
ff764963 KVA |
102 | 5. Releasing a reference to the PHY |
103 | ||
104 | When the controller no longer needs the PHY, it has to release the reference | |
105 | to the PHY it has obtained using the APIs mentioned in the above section. The | |
106 | PHY framework provides 2 APIs to release a reference to the PHY. | |
107 | ||
108 | void phy_put(struct phy *phy); | |
109 | void devm_phy_put(struct device *dev, struct phy *phy); | |
110 | ||
111 | Both these APIs are used to release a reference to the PHY and devm_phy_put | |
112 | destroys the devres associated with this PHY. | |
113 | ||
114 | 6. Destroying the PHY | |
115 | ||
116 | When the driver that created the PHY is unloaded, it should destroy the PHY it | |
117 | created using one of the following 2 APIs. | |
118 | ||
119 | void phy_destroy(struct phy *phy); | |
120 | void devm_phy_destroy(struct device *dev, struct phy *phy); | |
121 | ||
122 | Both these APIs destroy the PHY and devm_phy_destroy destroys the devres | |
123 | associated with this PHY. | |
124 | ||
125 | 7. PM Runtime | |
126 | ||
127 | This subsystem is pm runtime enabled. So while creating the PHY, | |
128 | pm_runtime_enable of the phy device created by this subsystem is called and | |
129 | while destroying the PHY, pm_runtime_disable is called. Note that the phy | |
130 | device created by this subsystem will be a child of the device that calls | |
131 | phy_create (PHY provider device). | |
132 | ||
133 | So pm_runtime_get_sync of the phy_device created by this subsystem will invoke | |
134 | pm_runtime_get_sync of PHY provider device because of parent-child relationship. | |
135 | It should also be noted that phy_power_on and phy_power_off performs | |
136 | phy_pm_runtime_get_sync and phy_pm_runtime_put respectively. | |
137 | There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync, | |
138 | phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and | |
139 | phy_pm_runtime_forbid for performing PM operations. | |
140 | ||
b7bc15b9 HK |
141 | 8. PHY Mappings |
142 | ||
143 | In order to get reference to a PHY without help from DeviceTree, the framework | |
144 | offers lookups which can be compared to clkdev that allow clk structures to be | |
145 | bound to devices. A lookup can be made be made during runtime when a handle to | |
146 | the struct phy already exists. | |
147 | ||
148 | The framework offers the following API for registering and unregistering the | |
149 | lookups. | |
150 | ||
151 | int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id); | |
152 | void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id); | |
ff764963 KVA |
153 | |
154 | 9. DeviceTree Binding | |
155 | ||
156 | The documentation for PHY dt binding can be found @ | |
157 | Documentation/devicetree/bindings/phy/phy-bindings.txt |