From patchwork Tue Oct 20 06:58:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 7442311 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1AC71BEEA4 for ; Tue, 20 Oct 2015 07:02:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0703820803 for ; Tue, 20 Oct 2015 07:02:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3613020790 for ; Tue, 20 Oct 2015 07:02:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZoQuI-0008Mi-CZ; Tue, 20 Oct 2015 07:00:26 +0000 Received: from mail-bn1on0147.outbound.protection.outlook.com ([157.56.110.147] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZoQu5-000780-U1 for linux-arm-kernel@lists.infradead.org; Tue, 20 Oct 2015 07:00:14 +0000 Received: from BLUPR03CA009.namprd03.prod.outlook.com (10.255.124.26) by DM2PR0301MB1309.namprd03.prod.outlook.com (10.160.222.154) with Microsoft SMTP Server (TLS) id 15.1.300.14; Tue, 20 Oct 2015 06:59:55 +0000 Received: from BL2FFO11FD018.protection.gbl (10.255.124.4) by BLUPR03CA009.outlook.office365.com (10.255.124.26) with Microsoft SMTP Server (TLS) id 15.1.300.14 via Frontend Transport; Tue, 20 Oct 2015 06:59:54 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD018.mail.protection.outlook.com (10.173.161.36) with Microsoft SMTP Server (TLS) id 15.1.300.4 via Frontend Transport; Tue, 20 Oct 2015 06:59:54 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t9K6xgdA031291; Mon, 19 Oct 2015 23:59:51 -0700 From: Peter Chen To: , Subject: [PATCH v5 2/2] usb: chipidea: imx: refine clock operations to adapt for all platforms Date: Tue, 20 Oct 2015 14:58:39 +0800 Message-ID: <1445324319-19063-3-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445324319-19063-1-git-send-email-peter.chen@freescale.com> References: <1445324319-19063-1-git-send-email-peter.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD018; 1:pdY9Jn3BMA+F4rsb6Dj9UyPCimEp8vsKqQn2VAWipBjzcOfoAoQ6XGpxuHmW5pOsWQB2EB45cSDb11UCMqqZQWIv/ktzI2dChtiuYWF5p5FnedExPu1CvqoHfHMEDNgf8HLS5ofLQL3RLynbcEz6EqaK9UmL6OP40nvRlO+Wzr4JnsCxmUdQa5ejOkC7hRdVXxl1Zr365WOiEyVG035Qbn840GSwGRcYDuU/1TFt6zT3oJzct1NhPtsiHRPE0TQyT672Xn8DDPft2UbaFHt5+r8POkcmveIfETr0vGAS2SlAmcbRvd4oFL3nytJF75RKLzXRvgfwPxgQe8O1bNRJL8Evm1xTL0WC/VCT3ZBt6EXyXyEOcvF9IxQZu4g+aoSuXsW2K5KavPlsC8gypSRRuQ== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(5001960100002)(87936001)(33646002)(229853001)(36756003)(189998001)(106466001)(50226001)(19580405001)(50466002)(85426001)(19580395003)(86362001)(105606002)(92566002)(2950100001)(77096005)(64706001)(76176999)(47776003)(48376002)(50986999)(5001770100001)(11100500001)(5003940100001)(97736004)(6806005)(46102003)(5008740100001)(5007970100001)(104016004)(5001920100001)(81156007); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1309; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1309; 2:1lCpCTvygE9SkZ9jowxlQSSga4FnxBAYyd6EI2taoiJO+Y03imZVBOf6RO3XLXyHmJG/3PqLcSTs7pyHh88n3PPGXrLVIEhyysdI72JdTc3G1GGa9qhkmVR5cq78Kx2uEdJTmWJBlNrABrHmnB9EfxCcYmsMgYtKbIRwho90LWE=; 3:Pu2ksakr3pu4ZIJ8ggkQfHDnV0gkTc8vDm5REaD6Rqmkvisikiw6ag3Z/WJ5BjzNNXiFeexfWlrx1/njngdI/mcKDI5NsOZoRqQuB72SXjEJQc0qd14OkwBVkdq48s5D9Ej1L7/LoAWmGj28/u8kWdMG6NtEE+gY39JYBpnQTRS+d/t0GPoNQKKfi9w9DFYKXHqLFc1ZfgFKPzcX9krUNZqnoKFBWFl4caVwFpR/3M0=; 25:815ejr9gfk+wELNRBqLARGz/WbNuR4QagTF4yDHOFc7f1YjijRthDSmifu8JCjQPulNhyhtkJ8N1qsyX6ZPiSCJd9+c5wkALmElorSVfAvrEWMfhEJaQxdw6zPuAJyyPvmO0L90dJDA41N853p5Dg9CfUAr3mRxzQU5PpkumwkXyDrCOjnqJWXUbWogen2Xo75+aeu7xs6nPThnKUY76wOumgRjj4Ky1RV3pClC8x0St3gBscMFYHUuT+1a/raKozKDhW0nc4w5gm7YhVw1fMw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1309; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1309; 20:uLMH7kiGBMg2ATD2TlIWmk9ILaGEjcXRrYcVs0oZgktXrGDlKzAB30BJqtZplXXq3Ix3rC78ygKutDl66Lzx5Y+NA7j9/H6zaSyUf4BdQKf2ifvTyy2txWNyJc2CfdIGOjaUcxUPaWUDWU5x78iaplwclaKD1z9aSaBee/FBh7gThJRhXzLuLEobjc+XTBzc9q2KFONjwb632Gl0Fwj6UP6HWNpHkf2zZoLQZPvUukuUuMjYN0VmV2vjDp+jazg7nV5fU1A5kOKiF1LFM4/TXzdGJUQA9l1Ffphg1g5YvHipkXBUTXEsPEsIi7DQuyDAthR8zlAQ+EUsZrjx3ajHaDpinnKDL6ptsPPnE4AQkNc=; 4:q6dKBLsH5L5yI72LKQv32YPhqjHnXUxEfzWoWkKWx19Qmh8TfWAO2ZjvfqAFqno7ViFSmPuBOL14MdQzD2Dc+orGI2ig928eRzB1fNlH+NCt3ba6wJev4CPZjlL7BxOCmkF1MgNAnCOIefN1n+LGVGlZfzQtfwBSIq6nFamvA9g4y1Qk6HR2rtIxaN2VBInHtKQhDI9OVzcXRmR2mDfHn57r0LOXGcpJ1XtYplvaFMPZDGMI+v0aAr/iSFkttHLGDRKud3pUPy/hkQFq2qmz91sbkXbRNSrGiHfut2iZiMuuhNZ5+mkgVagB15EI1G2H8mUpQqE9Vl/ROf8YQsOzif4NKeY1m1I+QlvsC63eXGk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001); SRVR:DM2PR0301MB1309; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1309; X-Forefront-PRVS: 073515755F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB1309; 23:DOAcvX5ZCj2ivg84/c4mc7J7eEe3JPFCsDtBVCI?= =?us-ascii?Q?NR0NQVpwRDhlmwAF4zI2vtA47mQBnjZKe5AzM12YLNJ1m0nOWMQzRac6tB7Z?= =?us-ascii?Q?7teCMnCVNfWJgbVGS0J0C0A91C2F4V5/1WiL4dkEcqqqCo86Oq7hyS+os7kK?= =?us-ascii?Q?4dlk6NgePiSgFT+b9HKz0bwb7ZQ5wOiUqN4IIc8bynW97c0Zu6ENM/t/LFiu?= =?us-ascii?Q?UGpGhUm7hh79+2UkXML5GNPb5bGXEZOwEbZyFOtO7AvnlqOGZPz2O7rqCg6e?= =?us-ascii?Q?J5Rjf3ndeJRwakK9D9Ku0zMTZOlgl85t+B0dNpbI+ejzCANeP+G20EoxeSV1?= =?us-ascii?Q?MknYV+/enkFyHVmSE9uyHxeGQP/4QX9JZb6ioc8Lz4C1BTbbonmPd4adpXsT?= =?us-ascii?Q?XIQs108sJwNVUuQcwne7ZfOPVpNL+P3BLCDXBGJwtCI1daIavfN7QGmZTvzb?= =?us-ascii?Q?Nm7lAHaoxDA6LGjSN4BMZwT/eh+7D9F6XzDFLyAqXkWqhsXJWc7IojjkNVgK?= =?us-ascii?Q?tHcY8y7M8hzYEQjnAVJ6OG4EbGqC4yTxZ38Uri/5qedUxA1SncVY84n2Cuv9?= =?us-ascii?Q?ufgrgZLAMBQUNlI9Fu9DcqhmgtUAHZwtqhZJjRn3MH+1E32eV8TxBiE7rqm/?= =?us-ascii?Q?tEQ28n0wKTmWySz2+qTRXxX0yZOv4wEiT2s4pZ6UiG7ZuD7OVoW0mTasZJWT?= =?us-ascii?Q?jVQymJoCigiwyeGRIGxoZAfnZ65YnjzKN8uupwae623lPnx32W98SJK0N9A8?= =?us-ascii?Q?R179+SSV3uAmkDy/tiYtrn8gTp0ImqNWV+IbaKPGDBeXqCShX+2ahHdg6G5i?= =?us-ascii?Q?hAEdT62X3fS0nmzI+1c3C8IO7MlR8dH1nkkWYX2xar1JrAcrl3bPpFqLHtXK?= =?us-ascii?Q?sy+r6xbd80A0BQXaGqKLgzwByAnruSwX6gbP35KIoIW9gUcltJpDjisfrfKJ?= =?us-ascii?Q?foaLXlYUcFz2xCHIuCzh24j1gHIYPfmdc9bhhs7lkVFZ8qkNh4iV5PACMj2y?= =?us-ascii?Q?arNKddwz6KDl+DG+rAmBlkUw5ZDlzyaDLyYB7Od/0KjBjMQl3NQdKawlfDCz?= =?us-ascii?Q?RWwu4pgf4x5VRx4cXEWTpRA4LQ0NkHiveqBK/rIL+2PgzETcSiQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1309; 5:c0PdKQDLI3GCz1aBWome507Ndb4jPn+TbZE/2kW3S5oCaWXXHqVI10uhdoVkUfNgGZZ9Wy0uMhBaxq4tUOjKIvROrmateIWbBVVlF7LdI7NUqdN6tpdAzI0dxyHrjq/bbY/5mmHI9q2CsdeOPfJo/g==; 24:OLqz6QhrzlKPU4g81OK6uXrbRb7FNjHPAK+l5PpuLX/AJIMXy4NXxmZNgW6fdnhnY6bq3obWqWGkeJCrwRgJOsZ28vkMa+x4JVBOSSXxmSc=; 20:MaND1inP/6lQWgDTROegFxVDYdrcuLTqfYAqmdSx16D6nTng8/aK9usS0RPyniYrCphDfVnXs/H+812LtoXUgg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2015 06:59:54.6941 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1309 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151020_000014_158325_D4E98952 X-CRM114-Status: GOOD ( 21.90 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, fabio.estevam@freescale.com, pawel.moll@arm.com, stable@vger.kernel.org, robh+dt@kernel.org, mkl@pengutronix.de, Peter Chen , kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some i.mx platforms need three clocks to let controller work, but others only need one, refine clock operation to adapt for all platforms, it fixes a regression found at i.mx27. Signed-off-by: Peter Chen Tested-by: Fabio Estevam Cc: #v4.1+ --- drivers/usb/chipidea/ci_hdrc_imx.c | 131 ++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 18 deletions(-) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 6ccbf60..7c9b630 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -84,6 +84,12 @@ struct ci_hdrc_imx_data { struct imx_usbmisc_data *usbmisc_data; bool supports_runtime_pm; bool in_lpm; + /* SoC before i.mx6 (except imx23/imx28) needs three clks */ + bool need_three_clks; + struct clk *clk_ipg; + struct clk *clk_ahb; + struct clk *clk_per; + /* --------------------------------- */ }; /* Common functions shared by usbmisc drivers */ @@ -135,6 +141,102 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) } /* End of common functions shared by usbmisc drivers*/ +static int imx_get_clks(struct device *dev) +{ + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + int ret = 0; + + data->clk_ipg = devm_clk_get(dev, "ipg"); + if (IS_ERR(data->clk_ipg)) { + /* If the platform only needs one clocks */ + data->clk = devm_clk_get(dev, NULL); + if (IS_ERR(data->clk)) { + ret = PTR_ERR(data->clk); + dev_err(dev, + "Failed to get clks, err=%ld,%ld\n", + PTR_ERR(data->clk), PTR_ERR(data->clk_ipg)); + return ret; + } + return ret; + } + + data->clk_ahb = devm_clk_get(dev, "ahb"); + if (IS_ERR(data->clk_ahb)) { + ret = PTR_ERR(data->clk_ahb); + dev_err(dev, + "Failed to get ahb clock, err=%d\n", ret); + return ret; + } + + data->clk_per = devm_clk_get(dev, "per"); + if (IS_ERR(data->clk_per)) { + ret = PTR_ERR(data->clk_per); + dev_err(dev, + "Failed to get per clock, err=%d\n", ret); + return ret; + } + + data->need_three_clks = true; + return ret; +} + +static int imx_prepare_enable_clks(struct device *dev) +{ + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + int ret = 0; + + if (data->need_three_clks) { + ret = clk_prepare_enable(data->clk_ipg); + if (ret) { + dev_err(dev, + "Failed to prepare/enable ipg clk, err=%d\n", + ret); + return ret; + } + + ret = clk_prepare_enable(data->clk_ahb); + if (ret) { + dev_err(dev, + "Failed to prepare/enable ahb clk, err=%d\n", + ret); + clk_disable_unprepare(data->clk_ipg); + return ret; + } + + ret = clk_prepare_enable(data->clk_per); + if (ret) { + dev_err(dev, + "Failed to prepare/enable per clk, err=%d\n", + ret); + clk_disable_unprepare(data->clk_ahb); + clk_disable_unprepare(data->clk_ipg); + return ret; + } + } else { + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(dev, + "Failed to prepare/enable clk, err=%d\n", + ret); + return ret; + } + } + + return ret; +} + +static void imx_disable_unprepare_clks(struct device *dev) +{ + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + + if (data->need_three_clks) { + clk_disable_unprepare(data->clk_per); + clk_disable_unprepare(data->clk_ahb); + clk_disable_unprepare(data->clk_ipg); + } else { + clk_disable_unprepare(data->clk); + } +} static int ci_hdrc_imx_probe(struct platform_device *pdev) { @@ -153,23 +255,18 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) if (!data) return -ENOMEM; + platform_set_drvdata(pdev, data); data->usbmisc_data = usbmisc_get_init_data(&pdev->dev); if (IS_ERR(data->usbmisc_data)) return PTR_ERR(data->usbmisc_data); - data->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(data->clk)) { - dev_err(&pdev->dev, - "Failed to get clock, err=%ld\n", PTR_ERR(data->clk)); - return PTR_ERR(data->clk); - } + ret = imx_get_clks(&pdev->dev); + if (ret) + return ret; - ret = clk_prepare_enable(data->clk); - if (ret) { - dev_err(&pdev->dev, - "Failed to prepare or enable clock, err=%d\n", ret); + ret = imx_prepare_enable_clks(&pdev->dev); + if (ret) return ret; - } data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); if (IS_ERR(data->phy)) { @@ -212,8 +309,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) goto disable_device; } - platform_set_drvdata(pdev, data); - if (data->supports_runtime_pm) { pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); @@ -226,7 +321,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) disable_device: ci_hdrc_remove_device(data->ci_pdev); err_clk: - clk_disable_unprepare(data->clk); + imx_disable_unprepare_clks(&pdev->dev); return ret; } @@ -240,7 +335,7 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev) pm_runtime_put_noidle(&pdev->dev); } ci_hdrc_remove_device(data->ci_pdev); - clk_disable_unprepare(data->clk); + imx_disable_unprepare_clks(&pdev->dev); return 0; } @@ -252,7 +347,7 @@ static int imx_controller_suspend(struct device *dev) dev_dbg(dev, "at %s\n", __func__); - clk_disable_unprepare(data->clk); + imx_disable_unprepare_clks(dev); data->in_lpm = true; return 0; @@ -270,7 +365,7 @@ static int imx_controller_resume(struct device *dev) return 0; } - ret = clk_prepare_enable(data->clk); + ret = imx_prepare_enable_clks(dev); if (ret) return ret; @@ -285,7 +380,7 @@ static int imx_controller_resume(struct device *dev) return 0; clk_disable: - clk_disable_unprepare(data->clk); + imx_disable_unprepare_clks(dev); return ret; }