Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3927345ybh; Tue, 17 Mar 2020 09:03:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtdHRGhFWk5AiW/vU1rDSN2MVGc+tLFOlldKCmLoF0rxtYpUt4LJuwvXGs8QDdtK7R43iyM X-Received: by 2002:a9d:554c:: with SMTP id h12mr4450302oti.16.1584461006009; Tue, 17 Mar 2020 09:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584461006; cv=none; d=google.com; s=arc-20160816; b=CQqGVZ7OCzYsMFAP05q9Z1XIj+XAilehNK/VD2XXcRs8slFO0AHd7O4SEGICKYxIDM +ECxXcxpn5xujxVzRRiBstBwwGAsx8wAWq7Bd8PEytm/15fNPevJbQnr52RCm5VEonZD jblDX8rcCR0zbL4sufTHK6ISJzWzAvUjGmwbzlGMS8NW85ibOD8dCUdf5nGfHE0HbRS1 e0qSMew4F+HeZ2TjoFaX/T2KHIa5y10JgkwVgd2upp73ADUwD9LYzFgS67RPCWwaaLt/ sLH2u0xWGNoxM4ZF3fUliR1FJUXCIg9Bv1kO9RKnuTV7s+iJaotX7yBt63R68J68Dr5l ucPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HWIu6Gi0APrIzMyoHqBqzed91EoxSikvrYfhLbeVFFw=; b=mINL330FPIG4LXRMD0P3pMp8YtjZkGYsTRWX62EwCLNDd8vXEfI1cSWdpKwjIhmLr1 hzZAfOZLbFA/RyGG4cLW1W6hSf6f8sqIsOWxTjr8RyHdRnR/Qd7RDGd1l4DPy8sNwOtY 6skdWmwU9+Qs4axbqqu73bVBITHWmB4tmTGcognDiJkE96wBAVfJMIVEtfqfmkPHnVWu MWXBBveLK31QF1OP4SwLwV9K9ljF0puoCgzipo/64D1Mlt1BKiDFHw3wYt553Mycox4F w5yThP0HYWu4VKMUSH0w2cGdMow5LNhppADoGYE0oeXS6Qa8Xsd1tL4F///wHlp2xT22 ZW0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@pascalroeleven.nl header.s=x header.b=cg9sFtCA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pascalroeleven.nl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18si1797416otf.196.2020.03.17.09.03.10; Tue, 17 Mar 2020 09:03:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@pascalroeleven.nl header.s=x header.b=cg9sFtCA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pascalroeleven.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726860AbgCQQAK (ORCPT + 99 others); Tue, 17 Mar 2020 12:00:10 -0400 Received: from web0081.zxcs.nl ([185.104.29.10]:55122 "EHLO web0081.zxcs.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726833AbgCQQAJ (ORCPT ); Tue, 17 Mar 2020 12:00:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pascalroeleven.nl; s=x; 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=HWIu6Gi0APrIzMyoHqBqzed91EoxSikvrYfhLbeVFFw=; b=cg9sFtCAwrmdx6rka7MxExCpLO ApcT5kz+0tEAgqOQQPojFNu79MiGohxUH3ZStdLgQV/HXK3kbz58jUmhF/hdoTvU2qXGVA17S6lmC Pt/6sYyWRqwndFO9oM3wRgnEDXydDzis8Sm98suR9AfFdjXMqDsEG8jJEz8HZUe9XRucMjoOzBPmd CvpXQQy92/KcuB0+81CGGSx2wkps4mB2fHjWe5oE/AFtzMvOBCWXI43MnDc62JKYZO4RKrs48PJV5 mm4c5bhHt3BBKDWJeuBtXFrUKPYkSapmW4ZA2aJe0HAKKlSmNg6X2aU18pRpjIJyFZsGCP+XPlF2O 9ZFwuHqw==; Received: from ip565b1bc7.direct-adsl.nl ([86.91.27.199]:60802 helo=localhost.localdomain) by web0081.zxcs.nl with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1jEEdR-001IGT-HV; Tue, 17 Mar 2020 17:00:05 +0100 From: Pascal Roeleven To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Chen-Yu Tsai , Philipp Zabel , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linux-sunxi@googlegroups.com, Pascal Roeleven Subject: [RFC PATCH 4/4] pwm: sun4i: Delay after writing the period Date: Tue, 17 Mar 2020 16:59:06 +0100 Message-Id: <20200317155906.31288-5-dev@pascalroeleven.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200317155906.31288-1-dev@pascalroeleven.nl> References: <20200317155906.31288-1-dev@pascalroeleven.nl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-Id: dev@pascalroeleven.nl Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When disabling, ensure the period write is complete before continuing. This fixes an issue on some devices when the write isn't complete before the panel is turned off but the clock gate is still on. Signed-off-by: Pascal Roeleven --- drivers/pwm/pwm-sun4i.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index a11d00f96..75250fd4c 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -299,6 +299,10 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); next_period = jiffies + usecs_to_jiffies(cstate.period / 1000 + 1); + /* When disabling, make sure the period register is written first */ + if (!state->enabled && cstate.enabled) + sun4i_pwm_wait(next_period); + if (state->polarity != PWM_POLARITY_NORMAL) ctrl &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); else @@ -320,6 +324,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return 0; /* We need a full period to elapse before disabling the channel. */ + next_period = jiffies + usecs_to_jiffies(cstate.period / 1000 + 1); sun4i_pwm_wait(next_period); spin_lock(&sun4i_pwm->ctrl_lock); -- 2.20.1