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