From patchwork Wed Oct 30 04:51:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 3113001 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4093BBF924 for ; Wed, 30 Oct 2013 04:53:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 555CA2021E for ; Wed, 30 Oct 2013 04:53:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71E4C20219 for ; Wed, 30 Oct 2013 04:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750724Ab3J3ExL (ORCPT ); Wed, 30 Oct 2013 00:53:11 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:41534 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750706Ab3J3ExK (ORCPT ); Wed, 30 Oct 2013 00:53:10 -0400 Received: by mail-pa0-f47.google.com with SMTP id lf10so380805pab.20 for ; Tue, 29 Oct 2013 21:53:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rN3BMxbXYJVx2Z97RcwF6Jz0jSD0VwObLbJ/d1VtuHw=; b=mF8SXJk1GrQlO2OWUo3pGcbFaZ+Yu3WHh2SXC5S/0yNCvNl70SDFTv1XbPVizMOUEk k2RFqGeyoBErYGI3dmkRf1U+emntXm6OS6UJUduxtdxvrejLjmvdueDTAOeQTQeOCPJL txqH9DzO2k2bNByS8bKxwZrY76U7ikdRJqD0mYqrk+RvmZ8UrHV0Zxj87vreRlnyBJHj Y7u6McGy4ET+657f0vvBkjyOrILiHCXpqMSw/Ercyuv/Irphcjp0NiGePdbfdnilbr+s /suZdClC/xHUXEcIJDbAxSq4XKQn4VzCcEXXzi0/e1aR4B/RUnCJFIthaQxqwyXuouFa LFKw== X-Gm-Message-State: ALoCoQmmQo6GW0gRryw4JALBGZpfAD194/hRoxC0H3grQBLTAQUCSb0279VddY3VR2mT5Uk5IF4N X-Received: by 10.66.8.66 with SMTP id p2mr1039731paa.129.1383108789923; Tue, 29 Oct 2013 21:53:09 -0700 (PDT) Received: from linaro.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPSA id qz9sm38644676pbc.3.2013.10.29.21.53.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Oct 2013 21:53:09 -0700 (PDT) From: Sachin Kamat To: linux-pwm@vger.kernel.org Cc: thierry.reding@gmail.com, linux-samsung-soc@vger.kernel.org, tomasz.figa@gmail.com, sachin.kamat@linaro.org, Andrew Bresticker Subject: [PATCH 1/1] pwm: samsung: avoid setting manual update bit unnecessarily Date: Wed, 30 Oct 2013 10:21:44 +0530 Message-Id: <1383108704-3297-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Bresticker When possible, avoid setting the manual update bit and starting/stopping the PWM when adjusting the PWM as it causes noticable flickering when setting the backlight brightness. Signed-off-by: Andrew Bresticker Signed-off-by: Sachin Kamat --- drivers/pwm/pwm-samsung.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c index b59639e..6d23eb3 100644 --- a/drivers/pwm/pwm-samsung.c +++ b/drivers/pwm/pwm-samsung.c @@ -34,6 +34,7 @@ #define REG_TCNTB(chan) (0x0c + ((chan) * 0xc)) #define REG_TCMPB(chan) (0x10 + ((chan) * 0xc)) +#define REG_TCNTO(chan) (0x14 + ((chan) * 0xc)) #define TCFG0_PRESCALER_MASK 0xff #define TCFG0_PRESCALER1_SHIFT 8 @@ -234,15 +235,29 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip); unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm); unsigned long flags; - u32 tcon; + u32 tcon, tcnt, tcnt_o; spin_lock_irqsave(&samsung_pwm_lock, flags); tcon = readl(our_chip->base + REG_TCON); + tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm)); + tcnt_o = readl(our_chip->base + REG_TCNTO(pwm->hwpwm)); - tcon &= ~TCON_START(tcon_chan); - tcon |= TCON_MANUALUPDATE(tcon_chan); - writel(tcon, our_chip->base + REG_TCON); + /* + * If we've got a big value stuck in the PWM we need to adjust it using + * manualupdate. The start bit needs to be off for that to work + * properly so we only do this if strictly necessary since it can cause + * the PWM to blink. + * + * We will also use manualupdate if we find that the autoreload bit + * wasn't set previously since the very first time the timer is + * configured we seem to need to kickstart the PWM. + */ + if ((tcnt_o > tcnt) || !(tcon & TCON_AUTORELOAD(tcon_chan))) { + tcon &= ~TCON_START(tcon_chan); + tcon |= TCON_MANUALUPDATE(tcon_chan); + writel(tcon, our_chip->base + REG_TCON); + } tcon &= ~TCON_MANUALUPDATE(tcon_chan); tcon |= TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan);