PHY subsystem¶
| Author: | Kishon Vijay Abraham I <kishon@ti.com> |
|---|
This document explains the Generic PHY Framework along with the APIs provided,and how-to-use.
Introduction¶
PHY is the abbreviation for physical layer. It is used to connect a deviceto the physical medium e.g., the USB controller has a PHY to provide functionssuch as serialization, de-serialization, encoding, decoding and is responsiblefor obtaining the required data transmission rate. Note that some USBcontrollers have PHY functionality embedded into it and others use an externalPHY. Other peripherals that use PHY include Wireless LAN, Ethernet,SATA etc.
The intention of creating this framework is to bring the PHY drivers spreadall over the Linux kernel to drivers/phy to increase code re-use and forbetter code maintainability.
This framework will be of use only to devices that use external PHY (PHYfunctionality is not embedded within the controller).
Registering/Unregistering the PHY provider¶
PHY provider refers to an entity that implements one or more PHY instances.For the simple case where the PHY provider implements only a single instance ofthe PHY, the framework provides its own implementation of of_xlate inof_phy_simple_xlate. If the PHY provider implements multiple instances, itshould provide its own implementation of of_xlate. of_xlate is used only fordt boot case.
#define of_phy_provider_register(dev, xlate) \ __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))#define devm_of_phy_provider_register(dev, xlate) \ __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
of_phy_provider_register and devm_of_phy_provider_register macros can be used toregister the phy_provider and it takes device and of_xlate asarguments. For the dt boot case, all PHY providers should use one of the above2 macros to register the PHY provider.
Often the device tree nodes associated with a PHY provider will contain a setof children that each represent a single PHY. Some bindings may nest the childnodes within extra levels for context and extensibility, in which case the lowlevel of_phy_provider_register_full() and devm_of_phy_provider_register_full()macros can be used to override the node containing the children.
#define of_phy_provider_register_full(dev, children, xlate) \ __of_phy_provider_register(dev, children, THIS_MODULE, xlate)#define devm_of_phy_provider_register_full(dev, children, xlate) \ __devm_of_phy_provider_register_full(dev, children, THIS_MODULE, xlate)void devm_of_phy_provider_unregister(struct device *dev, struct phy_provider *phy_provider);void of_phy_provider_unregister(struct phy_provider *phy_provider);
devm_of_phy_provider_unregister and of_phy_provider_unregister can be used tounregister the PHY.
Creating the PHY¶
The PHY driver should create the PHY in order for other peripheral controllersto make use of it. The PHY framework provides 2 APIs to create the PHY.
struct phy *phy_create(struct device *dev, struct device_node *node, const struct phy_ops *ops);struct phy *devm_phy_create(struct device *dev, struct device_node *node, const struct phy_ops *ops);
The PHY drivers can use one of the above 2 APIs to create the PHY by passingthe device pointer and phy ops.phy_ops is a set of function pointers for performing PHY operations such asinit, exit, power_on and power_off.
Inorder to dereference the private data (in phy_ops), the phy provider drivercan use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() inphy_ops to get back the private data.
- Getting a reference to the PHY
Before the controller can make use of the PHY, it has to get a reference toit. This framework provides the following APIs to get a reference to the PHY.
struct phy *phy_get(struct device *dev, const char *string);struct phy *phy_optional_get(struct device *dev, const char *string);struct phy *devm_phy_get(struct device *dev, const char *string);struct phy *devm_phy_optional_get(struct device *dev, const char *string);struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index);
phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get canbe used to get the PHY. In the case of dt boot, the string argumentsshould contain the phy name as given in the dt data and in the case ofnon-dt boot, it should contain the label of the PHY. The twodevm_phy_get associates the device with the PHY using devres onsuccessful PHY get. On driver detach, release function is invoked onthe devres data and devres data is freed. phy_optional_get anddevm_phy_optional_get should be used when the phy is optional. Thesetwo functions will never return -ENODEV, but instead returns NULL whenthe phy cannot be found.Some generic drivers, such as ehci, may use multiplephys and for such drivers referencing phy(s) by name(s) does not make sense. Inthis case, devm_of_phy_get_by_index can be used to get a phy reference based onthe index.
It should be noted that NULL is a valid phy reference. All phyconsumer calls on the NULL phy become NOPs. That is the release calls,the phy_init() and phy_exit() calls, and phy_power_on() andphy_power_off() calls are all NOP when applied to a NULL phy. The NULLphy is useful in devices for handling optional phy devices.
Releasing a reference to the PHY¶
When the controller no longer needs the PHY, it has to release the referenceto the PHY it has obtained using the APIs mentioned in the above section. ThePHY framework provides 2 APIs to release a reference to the PHY.
void phy_put(struct phy *phy);void devm_phy_put(struct device *dev, struct phy *phy);
Both these APIs are used to release a reference to the PHY and devm_phy_putdestroys the devres associated with this PHY.
Destroying the PHY¶
When the driver that created the PHY is unloaded, it should destroy the PHY itcreated using one of the following 2 APIs:
void phy_destroy(struct phy *phy);void devm_phy_destroy(struct device *dev, struct phy *phy);
Both these APIs destroy the PHY and devm_phy_destroy destroys the devresassociated with this PHY.
PM Runtime¶
This subsystem is pm runtime enabled. So while creating the PHY,pm_runtime_enable of the phy device created by this subsystem is called andwhile destroying the PHY, pm_runtime_disable is called. Note that the phydevice created by this subsystem will be a child of the device that callsphy_create (PHY provider device).
So pm_runtime_get_sync of the phy_device created by this subsystem will invokepm_runtime_get_sync of PHY provider device because of parent-child relationship.It should also be noted that phy_power_on and phy_power_off performsphy_pm_runtime_get_sync and phy_pm_runtime_put respectively.There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync,phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow andphy_pm_runtime_forbid for performing PM operations.
PHY Mappings¶
In order to get reference to a PHY without help from DeviceTree, the frameworkoffers lookups which can be compared to clkdev that allow clk structures to bebound to devices. A lookup can be made during runtime when a handle to thestruct phy already exists.
The framework offers the following API for registering and unregistering thelookups:
int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
DeviceTree Binding¶
The documentation for PHY dt binding can be found @Documentation/devicetree/bindings/phy/phy-bindings.txt