From patchwork Mon Mar 25 21:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 10870185 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 8A3B61708 for ; Mon, 25 Mar 2019 22:10:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 724B628C1D for ; Mon, 25 Mar 2019 22:10:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6679D2905C; Mon, 25 Mar 2019 22:10:53 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F32A628C1D for ; Mon, 25 Mar 2019 22:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KHkor//6l/4LZCF+wIxEZ+/1+Uys7skKQijBNVOmiF8=; b=oIuDMGCp14ZY0b apl4gW2Ti8gTLHcnDDK9ll6RTgDef+FpvY3jE+9GmH+Y9UL3l3sF+MoXYopkGkVL7AlnsimjzgymE rVcE63BobewRqPMnFhRQ1ZKBCheDpeYsrQpKIu+DSGb9RSpg9geNCj9MfuDM/zl6KEB8YWhTXqkRp UXKRIybMRGxbG0lEuyxSQHi4WnhTYxQ9lNSUGhA/rChp0nvg+vQMJaPCtKHKiq7InCYLyYtgylpTa O4K5TRWitg+rivvW078Wqm6bDfEJGzc+4vYnVrSEn5+MK8X+fZaPA8VWeM7a56S+23+mFlDLnoBN0 i14UkzIuQzfgZWMbbWKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xnm-0005Id-Ux; Mon, 25 Mar 2019 22:10:42 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XnY-0004wC-W8 for linux-arm-kernel@bombadil.infradead.org; Mon, 25 Mar 2019 22:10:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CxpIShRWs3Z0XOZ8vdG8R38nVCUS7QOmS9jiLMBHg+Q=; b=ub9zCNYApPxUV7Fl0s8JTwM2M8 K9TyTFqo+jBr3BBfZHx2oFPYS/6zHpIDXupUA58nm2OdWy2wwI8Ijqr00I3mwjedkjcAHzBmn/Ewy GLwLMOxfhSJqGqwo7zjWsE1yP6wBySWZ0LDdcJps+oFpMOAT1Jwi4H8bhZ4uTeNAgkGz7M6k97u+C 0/BBfxddSTa+5hBCMessOW51u+ydFJijZso7IfbsR9/D4G5VaccQv+4uG42Dn/oEaMT/f2NFN4LJ0 Wi/zwMCtbFUbpW/gfjwowu81fpLpNka4QxuI7plOZjiZHVBu2LZikOFGaoLF/aJuBL3K3OL/ZOrme QoqfRCNQ==; Received: from muru.com ([72.249.23.125]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xcc-0001Yv-EJ for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:59:12 +0000 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id F1FA78206; Mon, 25 Mar 2019 21:59:20 +0000 (UTC) From: Tony Lindgren To: linux-omap@vger.kernel.org Subject: [PATCH 05/14] bus: ti-sysc: Add separate functions for handling clocks Date: Mon, 25 Mar 2019 14:58:40 -0700 Message-Id: <20190325215849.13182-6-tony@atomide.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325215849.13182-1-tony@atomide.com> References: <20190325215849.13182-1-tony@atomide.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_215910_734537_3D95F2F7 X-CRM114-Status: GOOD ( 17.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nishanth Menon , Tero Kristo , Dave Gerlach , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Peter Ujfalusi , Faiz Abbas , Keerthy , linux-arm-kernel@lists.infradead.org, Roger Quadros Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP At least McPDM module depends on an external optional clock to be usable. To make handling of the McPDM clock easier in the following patches, let's add separate functions for handling the main clocks and the optional clocks. Let's also add error handling to shut down already enabled clocks while at it. Signed-off-by: Tony Lindgren Signed-off-by: Tony Lindgren --- drivers/bus/ti-sysc.c | 141 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 18 deletions(-) diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c --- a/drivers/bus/ti-sysc.c +++ b/drivers/bus/ti-sysc.c @@ -231,6 +231,112 @@ static int sysc_get_clocks(struct sysc *ddata) return 0; } +static int sysc_enable_main_clocks(struct sysc *ddata) +{ + struct clk *clock; + int i, error; + + if (!ddata->clocks) + return 0; + + for (i = 0; i < SYSC_OPTFCK0; i++) { + clock = ddata->clocks[i]; + + /* Main clocks may not have ick */ + if (IS_ERR_OR_NULL(clock)) + continue; + + error = clk_enable(clock); + if (error) + goto err_disable; + } + + return 0; + +err_disable: + for (; i >= 0; i--) { + clock = ddata->clocks[i]; + + /* Main clocks may not have ick */ + if (IS_ERR_OR_NULL(clock)) + continue; + + clk_disable(clock); + } + + return error; +} + +static void sysc_disable_main_clocks(struct sysc *ddata) +{ + struct clk *clock; + int i; + + if (!ddata->clocks) + return; + + for (i = 0; i < SYSC_OPTFCK0; i++) { + clock = ddata->clocks[i]; + if (IS_ERR_OR_NULL(clock)) + continue; + + clk_disable(clock); + } +} + +static int sysc_enable_opt_clocks(struct sysc *ddata) +{ + struct clk *clock; + int i, error; + + if (!ddata->clocks) + return 0; + + for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { + clock = ddata->clocks[i]; + + /* Assume no holes for opt clocks */ + if (IS_ERR_OR_NULL(clock)) + return 0; + + error = clk_enable(clock); + if (error) + goto err_disable; + } + + return 0; + +err_disable: + for (; i >= 0; i--) { + clock = ddata->clocks[i]; + if (IS_ERR_OR_NULL(clock)) + continue; + + clk_disable(clock); + } + + return error; +} + +static void sysc_disable_opt_clocks(struct sysc *ddata) +{ + struct clk *clock; + int i; + + if (!ddata->clocks) + return; + + for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { + clock = ddata->clocks[i]; + + /* Assume no holes for opt clocks */ + if (IS_ERR_OR_NULL(clock)) + return; + + clk_disable(clock); + } +} + /** * sysc_init_resets - reset module on init * @ddata: device driver data @@ -667,7 +773,7 @@ static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev, static int __maybe_unused sysc_runtime_suspend(struct device *dev) { struct sysc *ddata; - int error = 0, i; + int error = 0; ddata = dev_get_drvdata(dev); @@ -682,15 +788,10 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev) return error; } - for (i = 0; i < ddata->nr_clocks; i++) { - if (IS_ERR_OR_NULL(ddata->clocks[i])) - continue; + sysc_disable_main_clocks(ddata); - if (i >= SYSC_OPTFCK0 && !sysc_opt_clks_needed(ddata)) - break; - - clk_disable(ddata->clocks[i]); - } + if (sysc_opt_clks_needed(ddata)) + sysc_disable_opt_clocks(ddata); ddata->enabled = false; @@ -700,7 +801,7 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev) static int __maybe_unused sysc_runtime_resume(struct device *dev) { struct sysc *ddata; - int error = 0, i; + int error = 0; ddata = dev_get_drvdata(dev); @@ -715,20 +816,24 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev) return error; } - for (i = 0; i < ddata->nr_clocks; i++) { - if (IS_ERR_OR_NULL(ddata->clocks[i])) - continue; - - if (i >= SYSC_OPTFCK0 && !sysc_opt_clks_needed(ddata)) - break; - - error = clk_enable(ddata->clocks[i]); + if (sysc_opt_clks_needed(ddata)) { + error = sysc_enable_opt_clocks(ddata); if (error) return error; } + error = sysc_enable_main_clocks(ddata); + if (error) + goto err_main_clocks; + ddata->enabled = true; + return 0; + +err_main_clocks: + if (sysc_opt_clks_needed(ddata)) + sysc_disable_opt_clocks(ddata); + return error; }