0001 PHY SUBSYSTEM
0002 Kishon Vijay Abraham I <firstname.lastname@example.org>
0004 This document explains the Generic PHY Framework along with the APIs provided,
0005 and how-to-use.
0007 1. Introduction
0009 *PHY* is the abbreviation for physical layer. It is used to connect a device
0010 to the physical medium e.g., the USB controller has a PHY to provide functions
0011 such as serialization, de-serialization, encoding, decoding and is responsible
0012 for obtaining the required data transmission rate. Note that some USB
0013 controllers have PHY functionality embedded into it and others use an external
0014 PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
0015 SATA etc.
0017 The intention of creating this framework is to bring the PHY drivers spread
0018 all over the Linux kernel to drivers/phy to increase code re-use and for
0019 better code maintainability.
0021 This framework will be of use only to devices that use external PHY (PHY
0022 functionality is not embedded within the controller).
0024 2. Registering/Unregistering the PHY provider
0026 PHY provider refers to an entity that implements one or more PHY instances.
0027 For the simple case where the PHY provider implements only a single instance of
0028 the PHY, the framework provides its own implementation of of_xlate in
0029 of_phy_simple_xlate. If the PHY provider implements multiple instances, it
0030 should provide its own implementation of of_xlate. of_xlate is used only for
0031 dt boot case.
0033 #define of_phy_provider_register(dev, xlate) \
0034 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
0036 #define devm_of_phy_provider_register(dev, xlate) \
0037 __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
0039 of_phy_provider_register and devm_of_phy_provider_register macros can be used to
0040 register the phy_provider and it takes device and of_xlate as
0041 arguments. For the dt boot case, all PHY providers should use one of the above
0042 2 macros to register the PHY provider.
0044 Often the device tree nodes associated with a PHY provider will contain a set
0045 of children that each represent a single PHY. Some bindings may nest the child
0046 nodes within extra levels for context and extensibility, in which case the low
0047 level of_phy_provider_register_full() and devm_of_phy_provider_register_full()
0048 macros can be used to override the node containing the children.
0050 #define of_phy_provider_register_full(dev, children, xlate) \
0051 __of_phy_provider_register(dev, children, THIS_MODULE, xlate)
0053 #define devm_of_phy_provider_register_full(dev, children, xlate) \
0054 __devm_of_phy_provider_register_full(dev, children, THIS_MODULE, xlate)
0056 void devm_of_phy_provider_unregister(struct device *dev,
0057 struct phy_provider *phy_provider);
0058 void of_phy_provider_unregister(struct phy_provider *phy_provider);
0060 devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to
0061 unregister the PHY.
0063 3. Creating the PHY
0065 The PHY driver should create the PHY in order for other peripheral controllers
0066 to make use of it. The PHY framework provides 2 APIs to create the PHY.
0068 struct phy *phy_create(struct device *dev, struct device_node *node,
0069 const struct phy_ops *ops);
0070 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
0071 const struct phy_ops *ops);
0073 The PHY drivers can use one of the above 2 APIs to create the PHY by passing
0074 the device pointer and phy ops.
0075 phy_ops is a set of function pointers for performing PHY operations such as
0076 init, exit, power_on and power_off.
0078 Inorder to dereference the private data (in phy_ops), the phy provider driver
0079 can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in
0080 phy_ops to get back the private data.
0082 4. Getting a reference to the PHY
0084 Before the controller can make use of the PHY, it has to get a reference to
0085 it. This framework provides the following APIs to get a reference to the PHY.
0087 struct phy *phy_get(struct device *dev, const char *string);
0088 struct phy *phy_optional_get(struct device *dev, const char *string);
0089 struct phy *devm_phy_get(struct device *dev, const char *string);
0090 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
0091 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
0092 int index);
0094 phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
0095 be used to get the PHY. In the case of dt boot, the string arguments
0096 should contain the phy name as given in the dt data and in the case of
0097 non-dt boot, it should contain the label of the PHY. The two
0098 devm_phy_get associates the device with the PHY using devres on
0099 successful PHY get. On driver detach, release function is invoked on
0100 the the devres data and devres data is freed. phy_optional_get and
0101 devm_phy_optional_get should be used when the phy is optional. These
0102 two functions will never return -ENODEV, but instead returns NULL when
0103 the phy cannot be found.Some generic drivers, such as ehci, may use multiple
0104 phys and for such drivers referencing phy(s) by name(s) does not make sense. In
0105 this case, devm_of_phy_get_by_index can be used to get a phy reference based on
0106 the index.
0108 It should be noted that NULL is a valid phy reference. All phy
0109 consumer calls on the NULL phy become NOPs. That is the release calls,
0110 the phy_init() and phy_exit() calls, and phy_power_on() and
0111 phy_power_off() calls are all NOP when applied to a NULL phy. The NULL
0112 phy is useful in devices for handling optional phy devices.
0114 5. Releasing a reference to the PHY
0116 When the controller no longer needs the PHY, it has to release the reference
0117 to the PHY it has obtained using the APIs mentioned in the above section. The
0118 PHY framework provides 2 APIs to release a reference to the PHY.
0120 void phy_put(struct phy *phy);
0121 void devm_phy_put(struct device *dev, struct phy *phy);
0123 Both these APIs are used to release a reference to the PHY and devm_phy_put
0124 destroys the devres associated with this PHY.
0126 6. Destroying the PHY
0128 When the driver that created the PHY is unloaded, it should destroy the PHY it
0129 created using one of the following 2 APIs.
0131 void phy_destroy(struct phy *phy);
0132 void devm_phy_destroy(struct device *dev, struct phy *phy);
0134 Both these APIs destroy the PHY and devm_phy_destroy destroys the devres
0135 associated with this PHY.
0137 7. PM Runtime
0139 This subsystem is pm runtime enabled. So while creating the PHY,
0140 pm_runtime_enable of the phy device created by this subsystem is called and
0141 while destroying the PHY, pm_runtime_disable is called. Note that the phy
0142 device created by this subsystem will be a child of the device that calls
0143 phy_create (PHY provider device).
0145 So pm_runtime_get_sync of the phy_device created by this subsystem will invoke
0146 pm_runtime_get_sync of PHY provider device because of parent-child relationship.
0147 It should also be noted that phy_power_on and phy_power_off performs
0148 phy_pm_runtime_get_sync and phy_pm_runtime_put respectively.
0149 There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync,
0150 phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and
0151 phy_pm_runtime_forbid for performing PM operations.
0153 8. PHY Mappings
0155 In order to get reference to a PHY without help from DeviceTree, the framework
0156 offers lookups which can be compared to clkdev that allow clk structures to be
0157 bound to devices. A lookup can be made be made during runtime when a handle to
0158 the struct phy already exists.
0160 The framework offers the following API for registering and unregistering the
0163 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
0164 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
0166 9. DeviceTree Binding
0168 The documentation for PHY dt binding can be found @