From patchwork Mon Sep 10 09:52:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10593867 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D28C1515 for ; Mon, 10 Sep 2018 09:54:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79CC028E34 for ; Mon, 10 Sep 2018 09:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DBD028E2A; Mon, 10 Sep 2018 09:54:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036B828E23 for ; Mon, 10 Sep 2018 09:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbeIJOrb (ORCPT ); Mon, 10 Sep 2018 10:47:31 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:45268 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727353AbeIJOra (ORCPT ); Mon, 10 Sep 2018 10:47:30 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie3.idc.renesas.com with ESMTP; 10 Sep 2018 18:54:15 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 02C097DA7E; Mon, 10 Sep 2018 18:54:15 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.53,355,1531753200"; d="scan'208";a="292071062" Received: from mail-hk2apc01lp0211.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.211]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 10 Sep 2018 18:54:13 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IiDFO4zX9gRA9SNBvVtAK9SHlNNpDwoAhiAC18SlNxQ=; b=etLw8mkOOM9liKF0TP67lv79xkzYlj1CWdgoyQN/mYcdl5BPb8kGhVMUmjA5rblkCGtSqzBNNHkSstlApXnYjw/PJ5YI91DLewrXoTAXWQYENJEhLqWbMgzv/PorBg/UxYN9Qs48CzeT1VEYIp1hebEArrOCFE43uG7aGS+f+Ok= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.144) by TY2PR01MB2298.jpnprd01.prod.outlook.com (2603:1096:404:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.18; Mon, 10 Sep 2018 09:54:08 +0000 From: Yoshihiro Shimoda To: balbi@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH v4 3/3] usb: renesas_usbhs: Add multiple clocks management Date: Mon, 10 Sep 2018 18:52:20 +0900 Message-Id: <1536573140-24123-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536573140-24123-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1536573140-24123-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TYAPR01CA0147.jpnprd01.prod.outlook.com (2603:1096:404:7e::15) To TY2PR01MB2298.jpnprd01.prod.outlook.com (2603:1096:404:10::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05bed115-ed68-439e-b565-08d617035a64 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(8559020)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:TY2PR01MB2298; X-Microsoft-Exchange-Diagnostics: 1;TY2PR01MB2298;3:0jIbXQr2ukFYngUMOwQgrPDMdW6VpnFJEYt0bBYjqTCGVWrOBT0svNv0ApeEB4d9yFIwzoJFBsOBaHYplB1aXQaGhiwq2mrchcZKmXCCXaXj+8gey6xr/qIbVlO6LHm7ZMz/e0/lUAQjwwTE5hCfzPKI29XXxvkdQJQZZlf9OBdy4DK2glex3n2zmzsPOdvbrjQZpPJZZiwZkDkppuotHGiH9aaIAK2PK6bOVNGv3D5vtitPlu3GgfFgI2v8ykor;25:YVDY6N1N8MHnGu1p8HgRyC4Mrlg6hMc6US/vwYCuteq1lj4jhAcR5r0a7AhsZ5UEZSM6KKmgyE6b5EEtRGJE3iVf7oEoq8tBfNKWqLimZUEfAM7FHNjwvbW7qYfXeDQYxpdRJ6qt6Jk/Z//wWV/mkWeuIt7YqbqIc+zGop+Y9ORLe4ZMLNlcGtP4sNUa+0HtJ+8UmlQdZYrmo9YfDIN+stpYWMYYFS3b59rWLZ9wod3ILCSmIr0XNQmG6JgC+EgKbzozLaN1zE6WH70LAkiU1e2V+RHAd1NEEzbY8nfoNOkoxvHtn89MzZBLhPQMgNkAxkuQjfjopcCjUQc7AkvqCw==;31:MXwq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54muCGFmYP/KM/kFA85ig== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301075)(3002001)(93006095)(3231311)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123564045)(201708071742011)(7699050);SRVR:TY2PR01MB2298;BCL:0;PCL:0;RULEID:;SRVR:TY2PR01MB2298; X-Forefront-PRVS: 07915F544A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(136003)(366004)(396003)(39860400002)(376002)(346002)(199004)(189003)(2906002)(498600001)(6506007)(3846002)(7736002)(305945005)(53936002)(386003)(5660300001)(97736004)(81166006)(76176011)(81156014)(52116002)(6512007)(78352004)(16526019)(51416003)(6116002)(486006)(476003)(42882007)(446003)(26005)(69590400006)(956004)(11346002)(2616005)(107886003)(16586007)(8676002)(8936002)(105586002)(6486002)(4326008)(316002)(6666003)(36756003)(68736007)(66066001)(47776003)(106356001)(48376002)(50226002)(25786009)(50466002)(3720700003);DIR:OUT;SFP:1102;SCL:1;SRVR:TY2PR01MB2298;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:0;MX:0; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;TY2PR01MB2298;23:4mWQ2tQIVI8qj6SQMfxu5MYozL6hvfop7N9WheP+9NOL7ok5JqwKK5fM5QldWLD9LZXnPMfjfqIBrVCrvfffvVoubSfvTrVbDwcdtLsu3o+qIR0M8kYZvmdAVOB/VGkZKgU4DZs7AZNub5dp6J3aMb8zt0znmVasba592KA1+E+Hv5u3sMs/OwZOGmuqk/39cA+2kji6FvQhPYFtwKtXi0ZUnytEQGWV44k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36+Hi741gY/l2rawFilg6YX5LESgRTPe9OY8V0HxlGB7YW3tA0qE3gEb2iFoHRUHWDsDEeOeDxMHNiJKhDaqhFBFqz41s0Y//wR/A7vzb4HxChzyXhIt/n0hzHFpDte/CbAJvcEjRYozLBAx782tgu7OjwjjtABh04EqyZwhobAta8bG51QBLB2ek1NpKmoO7fjmTvpQ7 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;TY2PR01MB2298;20:U5Lbwt2w+JbtX6ycn7q+zHTUwH04Uh/MRYJDYO7KwJPDyT0ZW8TEzD5da7qV7NLjePI7QVD5fWTulDCVcynPAm/R/RNxKqDJ+FztNPLJsULvrcgt7QLoTOlKFgmxDh3dmxUuofT0j+OLS3ubrKPnPsR1o2dZ91LI049TuNuZX04= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2018 09:54:08.7593 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05bed115-ed68-439e-b565-08d617035a64 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY2PR01MB2298 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP R-Car Gen3 needs to enable clocks of both host and peripheral. Since [eo]hci-platform disables the reset(s) when the drivers are removed, renesas_usbhs driver doesn't work correctly. To fix this issue, this patch adds multiple clocks management on this renesas_usbhs driver. Signed-off-by: Yoshihiro Shimoda --- drivers/usb/renesas_usbhs/common.c | 88 ++++++++++++++++++++++++++++++++++++++ drivers/usb/renesas_usbhs/common.h | 2 + 2 files changed, 90 insertions(+) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 1d355d5..d6c39ba 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -5,6 +5,7 @@ * Copyright (C) 2011 Renesas Solutions Corp. * Kuninori Morimoto */ +#include #include #include #include @@ -291,6 +292,79 @@ static void usbhsc_set_buswait(struct usbhs_priv *priv) usbhs_bset(priv, BUSWAIT, 0x000F, wait); } +static bool usbhsc_is_multi_clks(struct usbhs_priv *priv) +{ + if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 || + priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) + return true; + + return false; +} + +static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv) +{ + if (!usbhsc_is_multi_clks(priv)) + return 0; + + /* The first clock should exist */ + priv->clks[0] = of_clk_get(dev->of_node, 0); + if (IS_ERR(priv->clks[0])) + return PTR_ERR(priv->clks[0]); + + /* + * To backward compatibility with old DT, this driver checks the return + * value if it's -ENOENT or not. + */ + priv->clks[1] = of_clk_get(dev->of_node, 1); + if (PTR_ERR(priv->clks[1]) == -ENOENT) + priv->clks[1] = NULL; + else if (IS_ERR(priv->clks[1])) + return PTR_ERR(priv->clks[1]); + + return 0; +} + +static void usbhsc_clk_put(struct usbhs_priv *priv) +{ + int i; + + if (!usbhsc_is_multi_clks(priv)) + return; + + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) + clk_put(priv->clks[i]); +} + +static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv) +{ + int i, ret; + + if (!usbhsc_is_multi_clks(priv)) + return 0; + + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) { + ret = clk_prepare_enable(priv->clks[i]); + if (ret) { + while (--i >= 0) + clk_disable_unprepare(priv->clks[i]); + return ret; + } + } + + return ret; +} + +static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv) +{ + int i; + + if (!usbhsc_is_multi_clks(priv)) + return; + + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) + clk_disable_unprepare(priv->clks[i]); +} + /* * platform default param */ @@ -341,6 +415,10 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable) /* enable PM */ pm_runtime_get_sync(dev); + /* enable clks */ + if (usbhsc_clk_prepare_enable(priv)) + return; + /* enable platform power */ usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); @@ -353,6 +431,9 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable) /* disable platform power */ usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); + /* disable clks */ + usbhsc_clk_disable_unprepare(priv); + /* disable PM */ pm_runtime_put_sync(dev); } @@ -667,6 +748,10 @@ static int usbhs_probe(struct platform_device *pdev) if (ret) goto probe_fail_rst; + ret = usbhsc_clk_get(&pdev->dev, priv); + if (ret) + goto probe_fail_clks; + /* * deviece reset here because * USB device might be used in boot loader. @@ -720,6 +805,8 @@ static int usbhs_probe(struct platform_device *pdev) return ret; probe_end_mod_exit: + usbhsc_clk_put(priv); +probe_fail_clks: reset_control_assert(priv->rsts); probe_fail_rst: usbhs_mod_remove(priv); @@ -750,6 +837,7 @@ static int usbhs_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); usbhs_platform_call(priv, hardware_exit, pdev); + usbhsc_clk_put(priv); reset_control_assert(priv->rsts); usbhs_mod_remove(priv); usbhs_fifo_remove(priv); diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index bce7d35..555b3e7 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -8,6 +8,7 @@ #ifndef RENESAS_USB_DRIVER_H #define RENESAS_USB_DRIVER_H +#include #include #include #include @@ -279,6 +280,7 @@ struct usbhs_priv { struct phy *phy; struct reset_control *rsts; + struct clk *clks[2]; }; /*