From patchwork Sat Jul 20 00:04:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 2830750 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 888FC9F3EB for ; Sat, 20 Jul 2013 00:08:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81585201E3 for ; Sat, 20 Jul 2013 00:08:49 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A34C200DE for ; Sat, 20 Jul 2013 00:08:48 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0KhJ-0004Sf-8F; Sat, 20 Jul 2013 00:06:55 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0Kgn-0005ga-3l; Sat, 20 Jul 2013 00:06:21 +0000 Received: from mail-ea0-x231.google.com ([2a00:1450:4013:c01::231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0Kfo-0005W5-Lt for linux-arm-kernel@lists.infradead.org; Sat, 20 Jul 2013 00:05:22 +0000 Received: by mail-ea0-f177.google.com with SMTP id j14so2643812eak.8 for ; Fri, 19 Jul 2013 17:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=SNO10/W12+vTMVEMifNhfKs3etckP4I31LYN4W4yFTY=; b=xdBtCL2tdLp8Zb+nF9AiwGRHs8yDfb5TqVvcb6sY5rzorfohwOzQZdTd2gBLBKJ88B M+hIFO40aqJCoS0xNxHeIzCluCU+TM7RMDaiUyqN4xcvLcMTZk4VVhsDKYkGoh38zVrH GWc0DnnCiEc5zNif8QtGxUIcaA6gxoZ2fwmjh3LFa36GjJfxtsZCFnkQeD0h81cL4vcr Vk2H1x8OsPhsHliMRa9RQwKQ+rR2FJrMCCgC2cXUORgIs+pmnX8puaE9Txitt8OpMzS1 vuy3io3SWw95PI0YJ9RdXltA8a1fY6Q87AdPzQlfIqer7jXugYFTOhrBTf25HsNXw0a6 sKkA== X-Received: by 10.14.199.134 with SMTP id x6mr18061617een.114.1374278698595; Fri, 19 Jul 2013 17:04:58 -0700 (PDT) Received: from flatron.tomeq (87-207-52-162.dynamic.chello.pl. [87.207.52.162]) by mx.google.com with ESMTPSA id bj46sm31186249eeb.13.2013.07.19.17.04.56 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Jul 2013 17:04:57 -0700 (PDT) From: Tomasz Figa To: linux-samsung-soc@vger.kernel.org Subject: [PATCH v4 05/20] clocksource: samsung_pwm_timer: Handle suspend/resume correctly Date: Sat, 20 Jul 2013 02:04:18 +0200 Message-Id: <1374278673-25615-7-git-send-email-tomasz.figa@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1374278673-25615-1-git-send-email-tomasz.figa@gmail.com> References: <1374278673-25615-1-git-send-email-tomasz.figa@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130719_200520_903820_98565A75 X-CRM114-Status: GOOD ( 15.02 ) X-Spam-Score: -2.0 (--) Cc: linux-pwm@vger.kernel.org, Kukjin Kim , =?UTF-8?q?Heiko=20St=C3=BCbner?= , Arnd Bergmann , Tomasz Figa , Mark Brown , Thierry Reding , Olof Johansson , Sylwester Nawrocki , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 Current suspend/resume handling of the driver was broken, because: - periodic timer was being enabled in CLOCK_EVT_MODE_RESUME mode, which does not seem to be correct behavior looking at other platforms, - PWM divisors need to be restored, but they were not, - clockevent interrupt mask needs to be restored, but it was not, - clocksource was being restored in clockevent resume callback. This patch fixes issues mentioned above, making suspend/resume handling in the driver correct. Signed-off-by: Tomasz Figa Acked-by: Daniel Lezcano --- drivers/clocksource/samsung_pwm_timer.c | 42 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/clocksource/samsung_pwm_timer.c b/drivers/clocksource/samsung_pwm_timer.c index 753ffec..282e0e2 100644 --- a/drivers/clocksource/samsung_pwm_timer.c +++ b/drivers/clocksource/samsung_pwm_timer.c @@ -197,17 +197,6 @@ static int samsung_set_next_event(unsigned long cycles, return 0; } -static void samsung_timer_resume(void) -{ - /* event timer restart */ - samsung_time_setup(pwm.event_id, pwm.clock_count_per_tick - 1); - samsung_time_start(pwm.event_id, true); - - /* source timer restart */ - samsung_time_setup(pwm.source_id, pwm.tcnt_max); - samsung_time_start(pwm.source_id, true); -} - static void samsung_set_mode(enum clock_event_mode mode, struct clock_event_device *evt) { @@ -224,20 +213,29 @@ static void samsung_set_mode(enum clock_event_mode mode, case CLOCK_EVT_MODE_UNUSED: case CLOCK_EVT_MODE_SHUTDOWN: - break; - case CLOCK_EVT_MODE_RESUME: - samsung_timer_resume(); break; } } +static void samsung_clockevent_resume(struct clock_event_device *cev) +{ + samsung_timer_set_prescale(pwm.event_id, pwm.tscaler_div); + samsung_timer_set_divisor(pwm.event_id, pwm.tdiv); + + if (pwm.variant.has_tint_cstat) { + u32 mask = (1 << pwm.event_id); + writel(mask | (mask << 5), pwm.base + REG_TINT_CSTAT); + } +} + static struct clock_event_device time_event_device = { .name = "samsung_event_timer", .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, .rating = 200, .set_next_event = samsung_set_next_event, .set_mode = samsung_set_mode, + .resume = samsung_clockevent_resume, }; static irqreturn_t samsung_clock_event_isr(int irq, void *dev_id) @@ -288,6 +286,20 @@ static void __init samsung_clockevent_init(void) } } +static void samsung_clocksource_suspend(struct clocksource *cs) +{ + samsung_time_stop(pwm.source_id); +} + +static void samsung_clocksource_resume(struct clocksource *cs) +{ + samsung_timer_set_prescale(pwm.source_id, pwm.tscaler_div); + samsung_timer_set_divisor(pwm.source_id, pwm.tdiv); + + samsung_time_setup(pwm.source_id, pwm.tcnt_max); + samsung_time_start(pwm.source_id, true); +} + static cycle_t samsung_clocksource_read(struct clocksource *c) { return ~readl_relaxed(pwm.source_reg); @@ -297,6 +309,8 @@ static struct clocksource samsung_clocksource = { .name = "samsung_clocksource_timer", .rating = 250, .read = samsung_clocksource_read, + .suspend = samsung_clocksource_suspend, + .resume = samsung_clocksource_resume, .flags = CLOCK_SOURCE_IS_CONTINUOUS, };