From patchwork Tue Sep 11 08:47:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10595309 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 30498921 for ; Tue, 11 Sep 2018 08:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20E652924C for ; Tue, 11 Sep 2018 08:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1570C292CB; Tue, 11 Sep 2018 08:49:01 +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=ham 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 671852924C for ; Tue, 11 Sep 2018 08:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726734AbeIKNrQ (ORCPT ); Tue, 11 Sep 2018 09:47:16 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:46763 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726546AbeIKNrQ (ORCPT ); Tue, 11 Sep 2018 09:47:16 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 11 Sep 2018 17:48:51 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 992686CBAF; Tue, 11 Sep 2018 17:48:51 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.53,359,1531753200"; d="scan'208";a="292175658" Received: from mail-os2jpn01lp0152.outbound.protection.outlook.com (HELO JPN01-OS2-obe.outbound.protection.outlook.com) ([23.103.139.152]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 11 Sep 2018 17:48:51 +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=dFqlX4HpHVnHugq2IYGuSl4vhQ8wIMXpYusYNu5mu0TNZM4vpCBNtMck65uuN+87vWrYEqUfSE7mRrju9l7eIwhCL33b+WpCG4YJjhERU+9YmmmecRWHQR5HN1I7FYxgDvop6CA2bRNYdKXysR86Dcfb+XM9OCepoTFeva04iWI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.144) by TYAPR01MB2302.jpnprd01.prod.outlook.com (2603:1096:404:3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.16; Tue, 11 Sep 2018 08:48:47 +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 v5 3/3] usb: renesas_usbhs: Add multiple clocks management Date: Tue, 11 Sep 2018 17:47:05 +0900 Message-Id: <1536655625-10550-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536655625-10550-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1536655625-10550-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS2PR01CA0132.jpnprd01.prod.outlook.com (2603:1096:602::26) To TYAPR01MB2302.jpnprd01.prod.outlook.com (2603:1096:404:3::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3941694-5411-45e7-9e0e-08d617c363c8 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:TYAPR01MB2302; X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2302;3:6NqFbRyUCh1sl86iH4UKHYHoZv6P1EvNKSljibwUswz/LGnrYDfVqzxpC5NOnkHKE9Ars6w0GlMopa7RwXplnx6UeC4Sfslcg2hNqiwC5AqtLd7SwUi2MXWkJwRhf+zwUr/4k+IVmDMD03aOlDFqRf4HfVvuN712ZsFjrqH8PayTl/WEW76qvYFgDovE98sn0VDjOMUy4XNoeI56Kn6AFYQHdEgQdIwCo9Qrp5Bx3qgI8PsEpugNKN/PAeT47HUg;25:iPx04j7WBFA6jYH19NKeJcIKv9YQzkgbtylYfec+Pal5pKWTFwzV1cBgCZbuP8k/zop0Ycow7T9EC85pxcWJmBTWPbZABrOH3ppwCdxzbJkcPaHlyz5GUvh7l6PrN5hoB/9lISBYK5VxpfrNwaxQq/dKtJ3ex6x+sZAcvlt9T5jxx6Gn8BmYv9IKSMdvCgZA77FqEhXDi0L7JGeOdx0sxLmQycCf3HsgijchtZCwqiUrmWeSxN8FsT0PrHlKL1z9fMFyoq0Az5k8/WUVm6B3RAfA/SYWtjnSaa99EbavbAtjNZDCmelzwrM/2Gfyn7eaYEpJ4bXRH+ux1iphfe+h5g==;31:ubAhha4yxxX6v2gRT5BGuWHfLX1WRHPRPp+79rUxx1+1MfBR2n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-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(10201501046)(3002001)(3231311)(944501410)(52105095)(93006095)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123564045)(20161123560045)(201708071742011)(7699050);SRVR:TYAPR01MB2302;BCL:0;PCL:0;RULEID:;SRVR:TYAPR01MB2302; X-Forefront-PRVS: 0792DBEAD0 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(396003)(366004)(376002)(39860400002)(346002)(136003)(199004)(189003)(107886003)(97736004)(2906002)(5660300001)(53936002)(4326008)(25786009)(6486002)(78352004)(8676002)(305945005)(7736002)(16586007)(316002)(105586002)(106356001)(76176011)(6666003)(6512007)(6506007)(52116002)(51416003)(26005)(386003)(476003)(2616005)(956004)(486006)(3846002)(446003)(11346002)(47776003)(68736007)(42882007)(498600001)(48376002)(6116002)(50466002)(36756003)(16526019)(66066001)(81156014)(81166006)(50226002)(69590400006)(8936002)(3720700003);DIR:OUT;SFP:1102;SCL:1;SRVR:TYAPR01MB2302;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;TYAPR01MB2302;23:ZcyRxp8GBQOxpB2kXsWBsuvIBowWWT97LWdypipdGnNSdvyCO66w0BsRCqDAlKZJev9qhAR6ByPNMOyXeW2HDaP8aE3xK2Ie0xPhMouQnWPGsItvKEvxmGDZuEAKptfD3nzZlh2rRhEnkpJNJl7BTa5XBFu+CaVMdKwzE0qTWsnZtDaMg5PjK8oEuC9pbRLYU0hPNlzGr9iTzSTjwvUQCGPtcRAbzrRf89j3X11AkE3Y1UKP7HtiBoxnnCbuMeKQCv9BS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9pich6dm8QXSi2lf6ND3ZKFUCXd1mX32kwRijm/sOXp14x1DKL2601PBu8HEG4rHiL2aqEFgpNw3ULsPAep6KAHYHOKu8ZOLCCt0IhLEOJy4jxp31tZPoaX5phT3qrk6ncyb6WN5qrYIDN28NoC71KMaMky4mUxfMWT/l9/KqZ4i4INY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2302;20:6LMSHBF5H9yQoi9XZ+8RS+Y+AHiDNifChPgsyF9ynHt6AIsmiiAtdzubqBz1Z87fw6pa7cmVZushtTNTN/ZlS/yERq85+fYxffarhUW5jjgFlwaqJRODt1d9xBnnbLapzpf5OTzH9EcSDpxJVnvI2u3kCVwD7q4MwywQXyIdS5Y= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2018 08:48:47.7125 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3941694-5411-45e7-9e0e-08d617c363c8 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYAPR01MB2302 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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]; }; /*