From patchwork Thu Jul 12 07:01:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 1187381 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 C8DC1E0038 for ; Thu, 12 Jul 2012 07:24:09 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SpDfD-00050k-6V; Thu, 12 Jul 2012 07:18:16 +0000 Received: from ch1ehsobe003.messaging.microsoft.com ([216.32.181.183] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SpDQP-0001lS-Dm for linux-arm-kernel@lists.infradead.org; Thu, 12 Jul 2012 07:03:39 +0000 Received: from mail167-ch1-R.bigfish.com (10.43.68.249) by CH1EHSOBE018.bigfish.com (10.43.70.68) with Microsoft SMTP Server id 14.1.225.23; Thu, 12 Jul 2012 07:02:47 +0000 Received: from mail167-ch1 (localhost [127.0.0.1]) by mail167-ch1-R.bigfish.com (Postfix) with ESMTP id ED112200338; Thu, 12 Jul 2012 07:02:46 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah) Received: from mail167-ch1 (localhost.localdomain [127.0.0.1]) by mail167-ch1 (MessageSwitch) id 1342076565375163_20208; Thu, 12 Jul 2012 07:02:45 +0000 (UTC) Received: from CH1EHSMHS017.bigfish.com (snatpool2.int.messaging.microsoft.com [10.43.68.238]) by mail167-ch1.bigfish.com (Postfix) with ESMTP id 5859E12004D; Thu, 12 Jul 2012 07:02:45 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS017.bigfish.com (10.43.70.17) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 12 Jul 2012 07:02:45 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.2.298.5; Thu, 12 Jul 2012 02:02:42 -0500 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q6C71r2S016222; Thu, 12 Jul 2012 00:02:38 -0700 From: Richard Zhao To: , Subject: [PATCH 10/12] USB: chipidea: add set_vbus_power support Date: Thu, 12 Jul 2012 15:01:50 +0800 Message-ID: <1342076512-19207-11-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342076512-19207-1-git-send-email-richard.zhao@freescale.com> References: <1342076512-19207-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.183 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, B20596@freescale.com, dong.aisheng@linaro.org, fabio.estevam@freescale.com, alexander.shishkin@linux.intel.com, B29397@freescale.com, balbi@ti.com, stern@rowland.harvard.edu, kernel@pengutronix.de, gregkh@linuxfoundation.org, richard.zhao@freescale.com, shawn.guo@linaro.org, mkl@pengutronix.de, linuxzsc@gmail.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 set_vbus_power is used to enable or disable vbus power for usb host. Signed-off-by: Richard Zhao --- drivers/usb/chipidea/ci13xxx_imx.c | 39 +++++++++++++++++++++++++----------- drivers/usb/chipidea/host.c | 8 ++++++++ include/linux/usb/chipidea.h | 2 ++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c index c94e30f..b3173d8 100644 --- a/drivers/usb/chipidea/ci13xxx_imx.c +++ b/drivers/usb/chipidea/ci13xxx_imx.c @@ -26,6 +26,8 @@ #define pdev_to_phy(pdev) \ ((struct usb_phy *)platform_get_drvdata(pdev)) +#define ci_to_imx_data(ci) \ + ((struct ci13xxx_imx_data *)dev_get_drvdata(ci->dev->parent)) struct ci13xxx_imx_data { struct device_node *phy_np; @@ -35,12 +37,32 @@ struct ci13xxx_imx_data { struct regulator *reg_vbus; }; +static int ci13xxx_imx_vbus(struct ci13xxx *ci, int enable) +{ + struct ci13xxx_imx_data *data = ci_to_imx_data(ci); + int ret; + + if (!data->reg_vbus) + return 0; + + if (enable) + ret = regulator_enable(data->reg_vbus); + else + ret = regulator_disable(data->reg_vbus); + if (ret) + dev_err(ci->dev, "ci13xxx_imx_vbus failed, enable:%d err:%d\n", + enable, ret); + + return ret; +} + static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = { .name = "ci13xxx_imx", .flags = CI13XXX_REQUIRE_TRANSCEIVER | CI13XXX_PULLUP_ON_VBUS | CI13XXX_DISABLE_STREAMING, .capoffset = DEF_CAPOFFSET, + .set_vbus_power = ci13xxx_imx_vbus, }; static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) @@ -101,18 +123,10 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) /* we only support host now, so enable vbus here */ reg_vbus = devm_regulator_get(&pdev->dev, "vbus"); - if (!IS_ERR(reg_vbus)) { - ret = regulator_enable(reg_vbus); - if (ret) { - dev_err(&pdev->dev, - "Failed to enable vbus regulator, err=%d\n", - ret); - goto put_np; - } + if (!IS_ERR(reg_vbus)) data->reg_vbus = reg_vbus; - } else { + else reg_vbus = NULL; - } ci13xxx_imx_platdata.phy = data->phy; @@ -127,6 +141,9 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) *pdev->dev.dma_mask = DMA_BIT_MASK(32); dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask); } + + platform_set_drvdata(pdev, data); + plat_ci = ci13xxx_add_device(&pdev->dev, pdev->resource, pdev->num_resources, &ci13xxx_imx_platdata); @@ -139,7 +156,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) } data->ci_pdev = plat_ci; - platform_set_drvdata(pdev, data); pm_runtime_no_callbacks(&pdev->dev); pm_runtime_enable(&pdev->dev); @@ -149,7 +165,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) err: if (reg_vbus) regulator_disable(reg_vbus); -put_np: if (phy_np) of_node_put(phy_np); clk_disable_unprepare(data->clk); diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index ebff9f4..e091147 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -106,6 +106,12 @@ static int host_start(struct ci13xxx *ci) if (usb_disabled()) return -ENODEV; + if (ci->platdata->set_vbus_power) { + ret = ci->platdata->set_vbus_power(ci, 1); + if (ret) + return ret; + } + hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev)); if (!hcd) return -ENOMEM; @@ -138,6 +144,8 @@ static void host_stop(struct ci13xxx *ci) usb_remove_hcd(hcd); usb_put_hcd(hcd); + if (ci->platdata->set_vbus_power) + ci->platdata->set_vbus_power(ci, 0); } int ci_hdrc_host_init(struct ci13xxx *ci) diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 544825d..080f479 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -23,6 +23,8 @@ struct ci13xxx_platform_data { #define CI13XXX_CONTROLLER_RESET_EVENT 0 #define CI13XXX_CONTROLLER_STOPPED_EVENT 1 void (*notify_event) (struct ci13xxx *ci, unsigned event); + /* set vbus power, it must be called in non-atomic context */ + int (*set_vbus_power) (struct ci13xxx *ci, int enable); }; /* Default offset of capability registers */