From patchwork Fri Sep 25 15:53:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 11800153 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 DB31092C for ; Fri, 25 Sep 2020 15:55:13 +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 AE22E21D7A for ; Fri, 25 Sep 2020 15:55:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fUFWXMLx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE22E21D7A 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=Fnk2MvoRRO3uTyBhnHvOJIhG/D7mpRGow/xB5sPcsGE=; b=fUFWXMLx9E+iPFVH+SuQzgQ2C Vx19rrg6sIf/r58lg9AR0w+9C11WoHeb6y/qGHpFoFLErZSQqt8wDN9Fc6sNjuGb/lO+hbAvftjiy VjUeKfp3uyp3A364oqNA07pMa7RvEMQ6/ZegWc1A++JL6Bo0UV1rj+BgvdrPSq8GPb62vDghvi5L2 e0LLvPhJVsXwdtvTyITw2tbDIIOJPNpgiV/gZ6oYOTzwEUPl4aPx0iMdlghkQLsOHNiOF29a3ZLH1 ch1AYxzJ4AddrxSaIUibFvj94VyDeLi4A9YxFBYQ/NgOoSLEpM0vbWvPeUJbZu0WNGlAI0EBOMVw0 8XK3IT6lA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLq2e-0003Nv-DX; Fri, 25 Sep 2020 15:53:48 +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 1kLq2b-0003Ly-9w for linux-arm-kernel@lists.infradead.org; Fri, 25 Sep 2020 15:53:45 +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 1kLq2S-0000oU-Kd; Fri, 25 Sep 2020 17:53:36 +0200 Received: from mfe by dude02.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1kLq2Q-0008QO-Uv; Fri, 25 Sep 2020 17:53:34 +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 v2 5/5] pwm: imx27: wait till the duty cycle is applied Date: Fri, 25 Sep 2020 17:53:30 +0200 Message-Id: <20200925155330.32301-6-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200925155330.32301-1-m.felsch@pengutronix.de> References: <20200925155330.32301-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-20200925_115345_353978_3C8C2B0F X-CRM114-Status: GOOD ( 16.65 ) 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, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently the driver don't check if the new state was applied or not. This can cause glitches on the output pin if the new state disables the PWM. In this case the PWM clocks are disabled before the new duty cycle value gets applied. The fix is to wait till the desired duty cycle was applied. Signed-off-by: Marco Felsch --- v2: - new patch drivers/pwm/pwm-imx27.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c index 07c6a263a39c..ffa00bcd81da 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -222,6 +222,26 @@ static int pwm_imx27_get_fifo_slot(struct pwm_chip *chip, return fifoav; } +static int pwm_imx27_wait_till_applied(struct pwm_chip *chip, + struct pwm_device *pwm) +{ + unsigned int attempts = 4; + unsigned int period_ms; + int busy_slots; + + do { + busy_slots = pwm_imx27_get_fifo_slot(chip, pwm); + if (busy_slots == 0) + return 0; + + period_ms = DIV_ROUND_UP(pwm_get_period(pwm), + NSEC_PER_MSEC); + msleep(period_ms); + } while (attempts--); + + return -ETIMEDOUT; +} + static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { @@ -277,6 +297,11 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); else writel(0, imx->mmio_base + MX3_PWMSAR); + + ret = pwm_imx27_wait_till_applied(chip, pwm); + if (ret) + goto out; + writel(period_cycles, imx->mmio_base + MX3_PWMPR); /*