blob: 0aa994bd9a917664fa34e8c5f481ec3e05fc986d [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) \
Thierry Reding1140f7c2016-04-05 17:17:34 +020034 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053035
36#define devm_of_phy_provider_register(dev, xlate) \
Thierry Reding1140f7c2016-04-05 17:17:34 +020037 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053038
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
Thierry Reding1140f7c2016-04-05 17:17:34 +020044Often the device tree nodes associated with a PHY provider will contain a set
45of children that each represent a single PHY. Some bindings may nest the child
46nodes within extra levels for context and extensibility, in which case the low
47level of_phy_provider_register_full() and devm_of_phy_provider_register_full()
48macros can be used to override the node containing the children.
49
50#define of_phy_provider_register_full(dev, children, xlate) \
51 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
52
53#define devm_of_phy_provider_register_full(dev, children, xlate) \
54 __devm_of_phy_provider_register_full(dev, children, THIS_MODULE, xlate)
55
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053056void devm_of_phy_provider_unregister(struct device *dev,
57 struct phy_provider *phy_provider);
58void of_phy_provider_unregister(struct phy_provider *phy_provider);
59
60devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to
61unregister the PHY.
62
633. Creating the PHY
64
65The PHY driver should create the PHY in order for other peripheral controllers
66to make use of it. The PHY framework provides 2 APIs to create the PHY.
67
Kishon Vijay Abraham If0ed8172014-07-14 15:55:02 +053068struct phy *phy_create(struct device *dev, struct device_node *node,
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +020069 const struct phy_ops *ops);
Kishon Vijay Abraham If0ed8172014-07-14 15:55:02 +053070struct phy *devm_phy_create(struct device *dev, struct device_node *node,
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +020071 const struct phy_ops *ops);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053072
73The PHY drivers can use one of the above 2 APIs to create the PHY by passing
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +020074the device pointer and phy ops.
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053075phy_ops is a set of function pointers for performing PHY operations such as
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +020076init, exit, power_on and power_off.
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053077
78Inorder to dereference the private data (in phy_ops), the phy provider driver
79can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in
80phy_ops to get back the private data.
81
824. Getting a reference to the PHY
83
84Before the controller can make use of the PHY, it has to get a reference to
85it. This framework provides the following APIs to get a reference to the PHY.
86
87struct phy *phy_get(struct device *dev, const char *string);
Andrew Lunn788a4d52014-02-04 18:33:12 +010088struct phy *phy_optional_get(struct device *dev, const char *string);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053089struct phy *devm_phy_get(struct device *dev, const char *string);
Andrew Lunn788a4d52014-02-04 18:33:12 +010090struct phy *devm_phy_optional_get(struct device *dev, const char *string);
Arun Ramamurthy6be109b2015-04-22 16:04:11 -070091struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
92 int index);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053093
Andrew Lunn788a4d52014-02-04 18:33:12 +010094phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
95be used to get the PHY. In the case of dt boot, the string arguments
96should contain the phy name as given in the dt data and in the case of
97non-dt boot, it should contain the label of the PHY. The two
98devm_phy_get associates the device with the PHY using devres on
99successful PHY get. On driver detach, release function is invoked on
100the the devres data and devres data is freed. phy_optional_get and
101devm_phy_optional_get should be used when the phy is optional. These
102two functions will never return -ENODEV, but instead returns NULL when
Arun Ramamurthy6be109b2015-04-22 16:04:11 -0700103the phy cannot be found.Some generic drivers, such as ehci, may use multiple
104phys and for such drivers referencing phy(s) by name(s) does not make sense. In
105this case, devm_of_phy_get_by_index can be used to get a phy reference based on
106the index.
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530107
Andrew Lunn04c2fac2014-02-04 18:33:11 +0100108It should be noted that NULL is a valid phy reference. All phy
109consumer calls on the NULL phy become NOPs. That is the release calls,
110the phy_init() and phy_exit() calls, and phy_power_on() and
111phy_power_off() calls are all NOP when applied to a NULL phy. The NULL
112phy is useful in devices for handling optional phy devices.
113
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +05301145. Releasing a reference to the PHY
115
116When the controller no longer needs the PHY, it has to release the reference
117to the PHY it has obtained using the APIs mentioned in the above section. The
118PHY framework provides 2 APIs to release a reference to the PHY.
119
120void phy_put(struct phy *phy);
121void devm_phy_put(struct device *dev, struct phy *phy);
122
123Both these APIs are used to release a reference to the PHY and devm_phy_put
124destroys the devres associated with this PHY.
125
1266. Destroying the PHY
127
128When the driver that created the PHY is unloaded, it should destroy the PHY it
129created using one of the following 2 APIs.
130
131void phy_destroy(struct phy *phy);
132void devm_phy_destroy(struct device *dev, struct phy *phy);
133
134Both these APIs destroy the PHY and devm_phy_destroy destroys the devres
135associated with this PHY.
136
1377. PM Runtime
138
139This subsystem is pm runtime enabled. So while creating the PHY,
140pm_runtime_enable of the phy device created by this subsystem is called and
141while destroying the PHY, pm_runtime_disable is called. Note that the phy
142device created by this subsystem will be a child of the device that calls
143phy_create (PHY provider device).
144
145So pm_runtime_get_sync of the phy_device created by this subsystem will invoke
146pm_runtime_get_sync of PHY provider device because of parent-child relationship.
147It should also be noted that phy_power_on and phy_power_off performs
148phy_pm_runtime_get_sync and phy_pm_runtime_put respectively.
149There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync,
150phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and
151phy_pm_runtime_forbid for performing PM operations.
152
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +02001538. PHY Mappings
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530154
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +0200155In order to get reference to a PHY without help from DeviceTree, the framework
156offers lookups which can be compared to clkdev that allow clk structures to be
157bound to devices. A lookup can be made be made during runtime when a handle to
158the struct phy already exists.
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530159
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +0200160The framework offers the following API for registering and unregistering the
161lookups.
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530162
Heikki Krogerusb7bc15b92014-11-19 17:28:18 +0200163int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
164void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530165
1669. DeviceTree Binding
167
168The documentation for PHY dt binding can be found @
169Documentation/devicetree/bindings/phy/phy-bindings.txt