From patchwork Wed Sep 9 13:07:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 11765429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84A40138E for ; Wed, 9 Sep 2020 13:08:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A05621D81 for ; Wed, 9 Sep 2020 13:08:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aSI8/gBg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A05621D81 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=trLAOk5EASfXqMwxD23ULyGXyq9pjGlqIjZ22I1d8gE=; b=aSI8/gBg4gBC9nCEl2wWW52EY c3DFJvJ1ASPdOTK3H5IdIyaMZaJZSo4c1iTics6KwSmL9PF7eH4U+sDakdPqczStHzUGGaXxQjAkx pOQ+phf4f20cf4YLCFFzCSaEowIXqDgEtlpcZdEPUjsr34UQ1bl/mMvrNK8ZSrgqM0WNXSygvuKaf zjTEHauuPIl47Q90QedGkHUs8EDt+rqU71qnLafZswC0w3TZLyPT8v6IkGjnoI3CZ6bdrz2iQbW2u rC3pR9e67EJ7wm6fyfCDHU6yox9hHZGhTcmUqHTIS/oUwFbRTJ0TL5/dNflCHrYUg2eIOuW0qFpr7 EKAPpVEeA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFzpO-0008JB-GV; Wed, 09 Sep 2020 13:07:58 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFzpK-0008Hu-SU for linux-arm-kernel@lists.infradead.org; Wed, 09 Sep 2020 13:07:55 +0000 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFzpB-0002t3-5r; Wed, 09 Sep 2020 15:07:45 +0200 Received: from mfe by dude02.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1kFzp9-0004Uy-Ib; Wed, 09 Sep 2020 15:07:43 +0200 From: Marco Felsch To: thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de, lee.jones@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, Anson.Huang@nxp.com, michal.vokac@ysoft.com, l.majewski@majess.pl Subject: [PATCH 1/3] pwm: imx27: track clock enable/disable to simplify code Date: Wed, 9 Sep 2020 15:07:37 +0200 Message-Id: <20200909130739.26717-2-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200909130739.26717-1-m.felsch@pengutronix.de> References: <20200909130739.26717-1-m.felsch@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200909_090754_958383_6215B92C X-CRM114-Status: GOOD ( 15.77 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, 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 Introduce a simple clock state so we can enable/disable the clock without the need to check if we are running or not. Signed-off-by: Marco Felsch --- drivers/pwm/pwm-imx27.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c index c50d453552bd..3cf9f1774244 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -91,6 +91,7 @@ struct pwm_imx27_chip { * value to return in that case. */ unsigned int duty_cycle; + bool clk_on; }; #define to_pwm_imx27_chip(chip) container_of(chip, struct pwm_imx27_chip, chip) @@ -99,6 +100,9 @@ static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx) { int ret; + if (imx->clk_on) + return 0; + ret = clk_prepare_enable(imx->clk_ipg); if (ret) return ret; @@ -109,13 +113,20 @@ static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx) return ret; } + imx->clk_on = true; + return 0; } static void pwm_imx27_clk_disable_unprepare(struct pwm_imx27_chip *imx) { + if (!imx->clk_on) + return; + clk_disable_unprepare(imx->clk_per); clk_disable_unprepare(imx->clk_ipg); + + imx->clk_on = false; } static void pwm_imx27_get_state(struct pwm_chip *chip, @@ -223,6 +234,10 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, int ret; u32 cr; + ret = pwm_imx27_clk_prepare_enable(imx); + if (ret) + return ret; + pwm_get_state(pwm, &cstate); clkrate = clk_get_rate(imx->clk_per); @@ -254,10 +269,6 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (cstate.enabled) { pwm_imx27_wait_fifo_slot(chip, pwm); } else { - ret = pwm_imx27_clk_prepare_enable(imx); - if (ret) - return ret; - pwm_imx27_sw_reset(chip); }