Back to home page

OSCL-LXR

 
 

    


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