From patchwork Tue Apr 23 15:46:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 2478411 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 11A68DF2E5 for ; Tue, 23 Apr 2013 15:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756863Ab3DWPtL (ORCPT ); Tue, 23 Apr 2013 11:49:11 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:45359 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756623Ab3DWPtL (ORCPT ); Tue, 23 Apr 2013 11:49:11 -0400 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MLP00KPHT9O4980@mailout4.samsung.com> for linux-samsung-soc@vger.kernel.org; Wed, 24 Apr 2013 00:49:10 +0900 (KST) X-AuditID: cbfee61b-b7f8e6d000000f44-a6-5176ad76af2d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 7C.B0.03908.67DA6715; Wed, 24 Apr 2013 00:49:10 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MLP0032TT5SFQ80@mmp1.samsung.com>; Wed, 24 Apr 2013 00:49:10 +0900 (KST) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Cc: devicetree-discuss@lists.ozlabs.org, linux-samsung-soc@vger.kernel.org, kgene.kim@samsung.com, kyungmin.park@samsung.com, tomasz.figa@gmail.com, m.szyprowski@samsung.com, arnd@arndb.de, john.stultz@linaro.org, tglx@linutronix.de, olof@lixom.net, ben-linux@fluff.org, thomas.abraham@linaro.org, Tomasz Figa Subject: [PATCH v3 09/13] clocksource: samsung_pwm_timer: Work around rounding errors in clockevents core Date: Tue, 23 Apr 2013 17:46:30 +0200 Message-id: <1366731994-7478-10-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1366731994-7478-1-git-send-email-t.figa@samsung.com> References: <1366731994-7478-1-git-send-email-t.figa@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHLMWRmVeSWpSXmKPExsVy+t9jAd2ytWWBBi13eSz+TjrGbjFp3QEm iwOzH7JanPmta9G74CqbxdmmN+wWmx5fY7WYcX4fk8XaI3fZLU5d/8xmsX7GaxaLzZumMlsc m7GE0WLVrj+MDnwev39NYvT4u+oFs8fOWXfZPe5c28Pm8e7cOXaPzUvqPc7PWMjoceVEE6tH 35ZVjB6fN8kFcEVx2aSk5mSWpRbp2yVwZUyaeZ+54CZ3xaqz/1kbGC9ydjFycEgImEhcXJHW xcgJZIpJXLi3nq2LkYtDSGARo8SBZ7fZIZwuJol1s86wg1SxCahJfG54xAZiiwhoSEzpegxW xCxwiUli/q5NrCAJYYFsiSVb/rOA2CwCqhKrj94Ds3kFnCTmnljCCrFOXuLp/T6wQZxA8Z1H H4LZQgKOEkf/tjNNYORdwMiwilE0tSC5oDgpPddIrzgxt7g0L10vOT93EyM4lJ9J72Bc1WBx iFGAg1GJh/fFrLJAIdbEsuLK3EOMEhzMSiK81rOBQrwpiZVVqUX58UWlOanFhxilOViUxHkP tloHCgmkJ5akZqemFqQWwWSZODilGhgXsd/7NWO786MLKiseiPPPDD4vkNCd9PrWnbKWtNup j3/K7M9tlFMT5hAKMnj9b0+v5senhWEvPummdqrrFvsIbE33d1p8RIa3I7qhjrPh/wT5PXWx aZLbJsk3yV29JuR/Sn1n+9EJXh3tQiEWex9mVG4qty3awzHJVXRxZJ8dz5UHTCxdl5VYijMS DbWYi4oTAZ90fWphAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Due to rounding errors in clockevents core (in conversions between ticks and nsecs), it might happen that the set_next_event callback gets called with cycles = 0, causing the code to incorrectly program the PWM timer. This patch modifies the callback to program the timer for 1 tick, if received tick count value is 0. Signed-off-by: Tomasz Figa Signed-off-by: Kyungmin Park --- drivers/clocksource/samsung_pwm_timer.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/clocksource/samsung_pwm_timer.c b/drivers/clocksource/samsung_pwm_timer.c index 92b2f13..0234c8d 100644 --- a/drivers/clocksource/samsung_pwm_timer.c +++ b/drivers/clocksource/samsung_pwm_timer.c @@ -176,6 +176,19 @@ static void samsung_time_start(unsigned int channel, bool periodic) static int samsung_set_next_event(unsigned long cycles, struct clock_event_device *evt) { + /* + * This check is needed to account for internal rounding + * errors inside clockevents core, which might result in + * passing cycles = 0, which in turn would not generate any + * timer interrupt and hang the system. + * + * Another solution would be to set up the clockevent device + * with min_delta = 2, but this would unnecessarily increase + * the minimum sleep period. + */ + if (!cycles) + cycles = 1; + samsung_time_setup(pwm.event_id, cycles); samsung_time_start(pwm.event_id, false);