mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	usb: dwc2: platform: add generic PHY framework support
Get PHY parameters from devicetree and power off usb PHY during system suspend. Acked-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Yunzhi Li <lyz@rock-chips.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
		
							parent
							
								
									46919a23ee
								
							
						
					
					
						commit
						135b3c4304
					
				
					 2 changed files with 46 additions and 23 deletions
				
			
		| 
						 | 
					@ -3410,8 +3410,6 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct device *dev = hsotg->dev;
 | 
						struct device *dev = hsotg->dev;
 | 
				
			||||||
	struct s3c_hsotg_plat *plat = dev->platform_data;
 | 
						struct s3c_hsotg_plat *plat = dev->platform_data;
 | 
				
			||||||
	struct phy *phy;
 | 
					 | 
				
			||||||
	struct usb_phy *uphy;
 | 
					 | 
				
			||||||
	struct s3c_hsotg_ep *eps;
 | 
						struct s3c_hsotg_ep *eps;
 | 
				
			||||||
	int epnum;
 | 
						int epnum;
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
| 
						 | 
					@ -3421,30 +3419,23 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
 | 
				
			||||||
	hsotg->phyif = GUSBCFG_PHYIF16;
 | 
						hsotg->phyif = GUSBCFG_PHYIF16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Attempt to find a generic PHY, then look for an old style
 | 
						 * If platform probe couldn't find a generic PHY or an old style
 | 
				
			||||||
	 * USB PHY, finally fall back to pdata
 | 
						 * USB PHY, fall back to pdata
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	phy = devm_phy_get(dev, "usb2-phy");
 | 
						if (IS_ERR_OR_NULL(hsotg->phy) && IS_ERR_OR_NULL(hsotg->uphy)) {
 | 
				
			||||||
	if (IS_ERR(phy)) {
 | 
							plat = dev_get_platdata(dev);
 | 
				
			||||||
		uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
 | 
							if (!plat) {
 | 
				
			||||||
		if (IS_ERR(uphy)) {
 | 
								dev_err(dev,
 | 
				
			||||||
			/* Fallback for pdata */
 | 
								"no platform data or transceiver defined\n");
 | 
				
			||||||
			plat = dev_get_platdata(dev);
 | 
								return -EPROBE_DEFER;
 | 
				
			||||||
			if (!plat) {
 | 
							}
 | 
				
			||||||
				dev_err(dev,
 | 
							hsotg->plat = plat;
 | 
				
			||||||
				"no platform data or transceiver defined\n");
 | 
						} else if (hsotg->phy) {
 | 
				
			||||||
				return -EPROBE_DEFER;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			hsotg->plat = plat;
 | 
					 | 
				
			||||||
		} else
 | 
					 | 
				
			||||||
			hsotg->uphy = uphy;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		hsotg->phy = phy;
 | 
					 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * If using the generic PHY framework, check if the PHY bus
 | 
							 * If using the generic PHY framework, check if the PHY bus
 | 
				
			||||||
		 * width is 8-bit and set the phyif appropriately.
 | 
							 * width is 8-bit and set the phyif appropriately.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (phy_get_bus_width(phy) == 8)
 | 
							if (phy_get_bus_width(hsotg->phy) == 8)
 | 
				
			||||||
			hsotg->phyif = GUSBCFG_PHYIF8;
 | 
								hsotg->phyif = GUSBCFG_PHYIF8;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -155,6 +155,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
 | 
				
			||||||
	struct dwc2_core_params defparams;
 | 
						struct dwc2_core_params defparams;
 | 
				
			||||||
	struct dwc2_hsotg *hsotg;
 | 
						struct dwc2_hsotg *hsotg;
 | 
				
			||||||
	struct resource *res;
 | 
						struct resource *res;
 | 
				
			||||||
 | 
						struct phy *phy;
 | 
				
			||||||
 | 
						struct usb_phy *uphy;
 | 
				
			||||||
	int retval;
 | 
						int retval;
 | 
				
			||||||
	int irq;
 | 
						int irq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -212,6 +214,24 @@ static int dwc2_driver_probe(struct platform_device *dev)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
 | 
						hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Attempt to find a generic PHY, then look for an old style
 | 
				
			||||||
 | 
						 * USB PHY
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						phy = devm_phy_get(&dev->dev, "usb2-phy");
 | 
				
			||||||
 | 
						if (IS_ERR(phy)) {
 | 
				
			||||||
 | 
							hsotg->phy = NULL;
 | 
				
			||||||
 | 
							uphy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
 | 
				
			||||||
 | 
							if (IS_ERR(uphy))
 | 
				
			||||||
 | 
								hsotg->uphy = NULL;
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								hsotg->uphy = uphy;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							hsotg->phy = phy;
 | 
				
			||||||
 | 
							phy_power_on(hsotg->phy);
 | 
				
			||||||
 | 
							phy_init(hsotg->phy);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spin_lock_init(&hsotg->lock);
 | 
						spin_lock_init(&hsotg->lock);
 | 
				
			||||||
	mutex_init(&hsotg->init_mutex);
 | 
						mutex_init(&hsotg->init_mutex);
 | 
				
			||||||
	retval = dwc2_gadget_init(hsotg, irq);
 | 
						retval = dwc2_gadget_init(hsotg, irq);
 | 
				
			||||||
| 
						 | 
					@ -231,8 +251,15 @@ static int __maybe_unused dwc2_suspend(struct device *dev)
 | 
				
			||||||
	struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
 | 
						struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
 | 
				
			||||||
	int ret = 0;
 | 
						int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (dwc2_is_device_mode(dwc2))
 | 
						if (dwc2_is_device_mode(dwc2)) {
 | 
				
			||||||
		ret = s3c_hsotg_suspend(dwc2);
 | 
							ret = s3c_hsotg_suspend(dwc2);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if (dwc2->lx_state == DWC2_L0)
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							phy_exit(dwc2->phy);
 | 
				
			||||||
 | 
							phy_power_off(dwc2->phy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -241,8 +268,13 @@ static int __maybe_unused dwc2_resume(struct device *dev)
 | 
				
			||||||
	struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
 | 
						struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
 | 
				
			||||||
	int ret = 0;
 | 
						int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (dwc2_is_device_mode(dwc2))
 | 
						if (dwc2_is_device_mode(dwc2)) {
 | 
				
			||||||
		ret = s3c_hsotg_resume(dwc2);
 | 
							ret = s3c_hsotg_resume(dwc2);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							phy_power_on(dwc2->phy);
 | 
				
			||||||
 | 
							phy_init(dwc2->phy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue