From patchwork Tue Jan 15 06:08:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 1974901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id C7CCE3FE1B for ; Tue, 15 Jan 2013 06:12:26 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TuziG-0008Ux-NG; Tue, 15 Jan 2013 06:09:32 +0000 Received: from co9ehsobe003.messaging.microsoft.com ([207.46.163.26] helo=co9outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tuzi2-0008SR-ES for linux-arm-kernel@lists.infradead.org; Tue, 15 Jan 2013 06:09:19 +0000 Received: from mail81-co9-R.bigfish.com (10.236.132.245) by CO9EHSOBE014.bigfish.com (10.236.130.77) with Microsoft SMTP Server id 14.1.225.23; Tue, 15 Jan 2013 06:09:16 +0000 Received: from mail81-co9 (localhost [127.0.0.1]) by mail81-co9-R.bigfish.com (Postfix) with ESMTP id F2B351E027E; Tue, 15 Jan 2013 06:09:15 +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(zzzz1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h1155h) Received: from mail81-co9 (localhost.localdomain [127.0.0.1]) by mail81-co9 (MessageSwitch) id 1358230153599815_7838; Tue, 15 Jan 2013 06:09:13 +0000 (UTC) Received: from CO9EHSMHS032.bigfish.com (unknown [10.236.132.249]) by mail81-co9.bigfish.com (Postfix) with ESMTP id 84A4C8005A; Tue, 15 Jan 2013 06:09:13 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS032.bigfish.com (10.236.130.42) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 15 Jan 2013 06:09:13 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.2.318.3; Tue, 15 Jan 2013 06:09:12 +0000 Received: from localhost.localdomain (nchen-desktop.ap.freescale.net [10.192.242.40]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r0F68cEL000665; Mon, 14 Jan 2013 23:09:06 -0700 From: Peter Chen To: , , , , , , Subject: [PATCH v2 4/4] usb: chipidea: imx: Add system suspend/resume API Date: Tue, 15 Jan 2013 14:08:37 +0800 Message-ID: <1358230117-19443-4-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1358230117-19443-1-git-send-email-peter.chen@freescale.com> References: <1358230117-19443-1-git-send-email-peter.chen@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130115_010918_765330_0414F6A4 X-CRM114-Status: GOOD ( 18.94 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.46.163.26 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, m.grzeschik@pengutronix.de, linux-doc@vger.kernel.org, matt@genesi-usa.com, devicetree-discuss@lists.ozlabs.org, linux-usb@vger.kernel.org, mkl@pengutronix.de, maxime.ripard@free-electrons.com, festevam@gmail.com, linux-arm-kernel@lists.infradead.org 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 During the system suspend/resume procedure, the USB also needs to go suspend/resume procedure, this patch adds related APIs. It is tested at i.mx6q sabrelite. Meanwhile, it fixes the bug that the USB will out of work after system suspend/resume. Signed-off-by: Peter Chen --- drivers/usb/chipidea/bits.h | 1 + drivers/usb/chipidea/ci13xxx_imx.c | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index ba9c6ef..d1467bb 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h @@ -47,6 +47,7 @@ #define PORTSC_FPR BIT(6) #define PORTSC_SUSP BIT(7) #define PORTSC_HSP BIT(9) +#define PORTSC_PHCD BIT(23) /* phy suspend mode */ #define PORTSC_PTC (0x0FUL << 16) /* DEVLC */ diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c index 342eab0..dd257b1 100644 --- a/drivers/usb/chipidea/ci13xxx_imx.c +++ b/drivers/usb/chipidea/ci13xxx_imx.c @@ -25,6 +25,7 @@ #include #include "ci.h" +#include "bits.h" #include "ci13xxx_imx.h" #define pdev_to_phy(pdev) \ @@ -321,6 +322,63 @@ static int ci13xxx_imx_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int ci13xxx_imx_suspend(struct device *dev) +{ + struct ci13xxx_imx_data *data = + platform_get_drvdata(to_platform_device(dev)); + struct platform_device *plat_ci; + struct ci13xxx *ci; + + plat_ci = data->ci_pdev; + ci = platform_get_drvdata(plat_ci); + + hw_write(ci, OP_PORTSC, PORTSC_PHCD, 1); + + if (data->phy) + usb_phy_set_suspend(data->phy, 1); + + clk_disable_unprepare(data->clk); + + return 0; +} + +static int ci13xxx_imx_resume(struct device *dev) +{ + int ret; + struct ci13xxx_imx_data *data = + platform_get_drvdata(to_platform_device(dev)); + struct platform_device *plat_ci; + struct ci13xxx *ci; + + plat_ci = data->ci_pdev; + ci = platform_get_drvdata(plat_ci); + + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(dev, + "Failed to prepare or enable clock, err=%d\n", ret); + return ret; + } + + if (hw_read(ci, OP_PORTSC, PORTSC_PHCD)) { + hw_write(ci, OP_PORTSC, PORTSC_PHCD, 0); + /* Some clks sync between Controller and USB PHY */ + mdelay(1); + } + + if (data->phy) + usb_phy_set_suspend(data->phy, 0); + + return ret; +} + +static const struct dev_pm_ops ci13xxx_imx_pm_ops = { + .suspend = ci13xxx_imx_suspend, + .resume = ci13xxx_imx_resume, +}; +#endif + static const struct of_device_id ci13xxx_imx_dt_ids[] = { { .compatible = "fsl,imx27-usb", }, { /* sentinel */ } @@ -334,6 +392,9 @@ static struct platform_driver ci13xxx_imx_driver = { .name = "imx_usb", .owner = THIS_MODULE, .of_match_table = ci13xxx_imx_dt_ids, +#ifdef CONFIG_PM + .pm = &ci13xxx_imx_pm_ops, +#endif }, };