From patchwork Thu Jan 10 16:51:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 1961351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 6543FDF264 for ; Thu, 10 Jan 2013 17:00:34 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TtLQ7-0007OO-N5; Thu, 10 Jan 2013 16:56:00 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TtLML-0005aO-HS for linux-arm-kernel@lists.infradead.org; Thu, 10 Jan 2013 16:52:08 +0000 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id r0AGpqHt018360; Thu, 10 Jan 2013 10:51:52 -0600 Received: from DLEE74.ent.ti.com (dlee74.ent.ti.com [157.170.170.8]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r0AGpqMk029865; Thu, 10 Jan 2013 10:51:52 -0600 Received: from dlelxv22.itg.ti.com (172.17.1.197) by DLEE74.ent.ti.com (157.170.170.8) with Microsoft SMTP Server id 14.1.323.3; Thu, 10 Jan 2013 10:51:52 -0600 Received: from rockdesk.itg.ti.com (h113-58.vpn.ti.com [172.24.113.58]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r0AGpYI5023935; Thu, 10 Jan 2013 10:51:50 -0600 From: Roger Quadros To: Subject: [PATCH 07/14] usb: ehci-omap: Instantiate PHY devices if required Date: Thu, 10 Jan 2013 18:51:27 +0200 Message-ID: <1357836694-30788-8-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1357836694-30788-1-git-send-email-rogerq@ti.com> References: <1357836694-30788-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130110_115205_906327_6F605CEE X-CRM114-Status: GOOD ( 17.43 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.94.94.41 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: sameo@linux.intel.com, tony@atomide.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kishon@ti.com, linux-arm-kernel@lists.infradead.org, rogerq@ti.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If the OMAP's Host controller is in PHY mode then we instantiate a platform device for the PHY (one for each port in PHY mode) and hold a reference to it so that we can use the usb_phy API, e.g. while suspend/resume. The platform data for the PHY must be supplied in the newly added .phy_config parameter in struct usbhs_omap_platform_data. The end goal is to move the PHY's reset and power handling code out of the ehci-omap driver and into the phy driver. Signed-off-by: Roger Quadros --- drivers/usb/host/ehci-omap.c | 83 ++++++++++++++++++++++++++++++- include/linux/platform_data/usb-omap.h | 8 +++ 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index b96a4bf..e6a2d76 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c @@ -61,6 +61,11 @@ static const struct hc_driver ehci_omap_hc_driver; +struct omap_ehci_hcd { + struct usb_hcd *hcd; + struct usb_phy **phy; /* one PHY for each port */ + int nports; +}; static inline void ehci_write(void __iomem *base, u32 reg, u32 val) { @@ -179,6 +184,8 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) struct usbhs_omap_platform_data *pdata = dev->platform_data; struct resource *res; struct usb_hcd *hcd; + struct omap_ehci_hcd *omap_hcd; + struct usb_phy *phy; void __iomem *regs; int ret = -ENODEV; int irq; @@ -193,6 +200,25 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) return -ENODEV; } + if (!pdata) { + dev_err(dev, "Missing platform data\n"); + return -ENODEV; + } + + omap_hcd = devm_kzalloc(&pdev->dev, sizeof(*omap_hcd), GFP_KERNEL); + if (!omap_hcd) { + dev_err(dev, "Memory allocation failed\n"); + return -ENOMEM; + } + + omap_hcd->nports = pdata->nports; + i = sizeof(struct usb_phy *) * omap_hcd->nports; + omap_hcd->phy = devm_kzalloc(&pdev->dev, i, GFP_KERNEL); + if (!omap_hcd->phy) { + dev_err(dev, "Memory allocation failed\n"); + return -ENOMEM; + } + irq = platform_get_irq_byname(pdev, "ehci-irq"); if (irq < 0) { dev_err(dev, "EHCI irq failed\n"); @@ -223,9 +249,15 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); hcd->regs = regs; + omap_hcd->hcd = hcd; + + platform_set_drvdata(pdev, omap_hcd); /* get ehci regulator and enable */ - for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { + for (i = 0 ; i < omap_hcd->nports ; i++) { + struct platform_device *phy_pdev; + struct usbhs_phy_config *phy_config; + if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY) { pdata->regulator[i] = NULL; continue; @@ -239,6 +271,33 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) } else { regulator_enable(pdata->regulator[i]); } + + /* instantiate PHY */ + if (!pdata->phy_config[i]) { + dev_dbg(dev, "missing phy_config for port %d\n", i); + continue; + } + + phy_config = pdata->phy_config[i]; + phy_pdev = platform_device_register_data(&pdev->dev, + phy_config->name, i, phy_config->pdata, + phy_config->pdata_size); + if (IS_ERR(phy_pdev)) { + dev_dbg(dev, "error creating PHY device for port %d\n", + i); + } + + phy = usb_get_phy_from_dev(&phy_pdev->dev); + if (IS_ERR(phy)) { + dev_dbg(dev, "could not get USB PHY for port %d\n", i); + platform_device_unregister(phy_pdev); + continue; + } + + usb_phy_init(phy); + omap_hcd->phy[i] = phy; + /* bring PHY out of suspend */ + usb_phy_set_suspend(omap_hcd->phy[i], 0); } pm_runtime_enable(dev); @@ -269,6 +328,12 @@ err_pm_runtime: disable_put_regulator(pdata); pm_runtime_put_sync(dev); usb_put_hcd(hcd); + for (i = 0 ; i < omap_hcd->nports ; i++) { + phy = omap_hcd->phy[i]; + if (!phy) + continue; + platform_device_unregister(to_platform_device(phy->dev)); + } err_io: iounmap(regs); @@ -286,14 +351,26 @@ err_io: */ static int ehci_hcd_omap_remove(struct platform_device *pdev) { - struct device *dev = &pdev->dev; - struct usb_hcd *hcd = dev_get_drvdata(dev); + struct device *dev = &pdev->dev; + struct omap_ehci_hcd *omap_hcd = dev_get_drvdata(dev); + struct usb_hcd *hcd = omap_hcd->hcd; + int i; usb_remove_hcd(hcd); disable_put_regulator(dev->platform_data); iounmap(hcd->regs); usb_put_hcd(hcd); + for (i = 0; i < omap_hcd->nports; i++) { + struct usb_phy *phy = omap_hcd->phy[i]; + + if (!phy) + continue; + + usb_phy_shutdown(phy); + platform_device_unregister(to_platform_device(phy->dev)); + } + pm_runtime_put_sync(dev); pm_runtime_disable(dev); diff --git a/include/linux/platform_data/usb-omap.h b/include/linux/platform_data/usb-omap.h index d63eb7d..927b8a1 100644 --- a/include/linux/platform_data/usb-omap.h +++ b/include/linux/platform_data/usb-omap.h @@ -38,6 +38,12 @@ enum usbhs_omap_port_mode { OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM }; +struct usbhs_phy_config { + char *name; /* binds to device driver */ + void *pdata; /* platform data for the phy */ + size_t pdata_size; +}; + struct usbhs_omap_platform_data { int nports; enum usbhs_omap_port_mode port_mode[OMAP3_HS_USB_PORTS]; @@ -49,6 +55,8 @@ struct usbhs_omap_platform_data { unsigned single_ulpi_bypass:1; unsigned es2_compatibility:1; unsigned phy_reset:1; + + struct usbhs_phy_config *phy_config[OMAP3_HS_USB_PORTS]; }; /*-------------------------------------------------------------------------*/