From patchwork Thu Jul 21 10:31:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12924966 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13478CCA485 for ; Thu, 21 Jul 2022 10:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1+uo8ohBWFGcKIOXb/7abhJkXOi7oRENVJS76BCsF/Y=; b=CwTHcGoAeaBp7r Kn/2kOSE9Z5QZsSgY2hEaiRjmP4qv0na15RccAimDKVSAkgSsQ1lWeuLA+Qi+Bxsw6jg1f+wt8XgM gYOoyHwlhZd3cnAK/y+/OVs0sfJCsOnv+LvfeAEYPFXiOyr3xKtJKFJwts6w3dgG3JdJi1jvQOF1S dHHJrZTrV3mF2re63NJZXTdxjhsK04GGD2yAuvAON9GMSWWWiv9noJ4HwYNsmcIaePMjzoPOjHb8k Bawo9ifULtKkWrFqpT4gXRclDJOR+3TU8ciJIt2pIVF2cAvxKtCI9VXwC/5KJSQ99wQm9K66zfQav E+ISGh4cwnyM/72jaO3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oETTD-003rjw-S5; Thu, 21 Jul 2022 10:31:51 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oETT9-003rcz-KB for linux-riscv@lists.infradead.org; Thu, 21 Jul 2022 10:31:49 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oETSz-0002W0-QW; Thu, 21 Jul 2022 12:31:38 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1oETSy-002IMq-Rm; Thu, 21 Jul 2022 12:31:36 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oETSx-006ZIP-Od; Thu, 21 Jul 2022 12:31:35 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: Wan Jiabing , kernel@pengutronix.de, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Yash Shah , Atish Patra , "Wesley W. Terpstra" Subject: [PATCH 4/7] pwm: sifive: Enable clk only after period check in .apply() Date: Thu, 21 Jul 2022 12:31:26 +0200 Message-Id: <20220721103129.304697-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220721103129.304697-1-u.kleine-koenig@pengutronix.de> References: <20220721103129.304697-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1762; h=from:subject; bh=c0fLWKgziDkgWoI6+H8lb5WHbrXxOiw4wARKI8YtL8w=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBi2Sr1Zw4qH9xQt0jcTvyTAVVW8eBROsYO15Sy4QQA WoS5sU2JATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYtkq9QAKCRDB/BR4rcrsCRvCB/ 9frF0VhcjV6YFcVmo+uGdJ5lcNa5Z7TmrJDlamHndttyGzLZ+3xD5JrHqwsCmGwYnxL+Z5qP1BWD3a cASV0TRseaXW0A+SbyGVyMOhZXGTpArSCUO1jCqoWcDsb+kavyPZJresq507ZPqpBQANP5X5sWG2Y/ 9l37G0coHGDTAN8NzI+qDZcynQVZcKIe+K+rhQ3ssLxVtFCiQPjUiuvslDNc1/wXyucXdeKgep9Azr f9ksZ+YmZYHN5pkJ+1ftn8gD7PuFLqqjy2rZUOd5U9fs2c5SAxtREuFlE7k5Xz4mXh40vYmNQlU7O1 wfq+fXcovK5KMepW7TroZ9ixWEnv2W X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220721_033147_690039_852DFBDF X-CRM114-Status: GOOD ( 13.09 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org For the period check and the initial calculations of register values there is no hardware access needed. So delay enabling the clk a bit to simplify the code flow a bit. Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-sifive.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index 6017e311a879..d833536b5e7a 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -139,12 +139,6 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->polarity != PWM_POLARITY_INVERSED) return -EINVAL; - ret = clk_enable(ddata->clk); - if (ret) { - dev_err(ddata->chip.dev, "Enable clk failed\n"); - return ret; - } - cur_state = pwm->state; enabled = cur_state.enabled; @@ -167,14 +161,19 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->period != ddata->approx_period) { if (ddata->user_count != 1) { mutex_unlock(&ddata->lock); - ret = -EBUSY; - goto exit; + return -EBUSY; } ddata->approx_period = state->period; pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk)); } mutex_unlock(&ddata->lock); + ret = clk_enable(ddata->clk); + if (ret) { + dev_err(ddata->chip.dev, "Enable clk failed\n"); + return ret; + } + writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); if (state->enabled != enabled) { @@ -186,9 +185,8 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } -exit: clk_disable(ddata->clk); - return ret; + return 0; } static const struct pwm_ops pwm_sifive_ops = {