From patchwork Fri Apr 12 19:17:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 2437711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 9E59EDF2A1 for ; Fri, 12 Apr 2013 19:21:46 +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 1UQjW6-0004ZF-Mr; Fri, 12 Apr 2013 19:20:11 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UQjVQ-0002P9-21; Fri, 12 Apr 2013 19:19:28 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UQjUk-0002Ls-46 for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2013 19:18:50 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0ML500JP8PN9TG60@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Sat, 13 Apr 2013 04:18:45 +0900 (KST) X-AuditID: cbfee61b-b7f076d0000034b6-e4-51685e147f49 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 1D.9C.13494.41E58615; Sat, 13 Apr 2013 04:18:44 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0ML500CT6PL8T090@mmp2.samsung.com>; Sat, 13 Apr 2013 04:18:44 +0900 (KST) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 07/14] clocksource: samsung-pwm: Use platform data to setup the clocksource Date: Fri, 12 Apr 2013 21:17:23 +0200 Message-id: <1365794250-14436-8-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1365794250-14436-1-git-send-email-t.figa@samsung.com> References: <1365794250-14436-1-git-send-email-t.figa@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWRa0hTYQCG/bazs+NqeJpWhwmJE0METSXoI000Jb9+WIkQEaM86dFJmxub SkbQvAQxl5b3FIZWZo6VbF5SaaFDR3mbGa6wVuhQkJmkIxWnK53073l5H3h/vARb0IYJifyC QkZZQEtFOA8b9zqPRAXdkGTEGMxn4W6NlQvNv7wAelvGcDjnXuBCY+caDoda5jlwVJsI/y64 OHB8xg7g8Jt2DpzwRMFHrbM4fNU7jcHJshUuNDntHNhke8+C3z7zoaevFIOvRxxc2P7lEwvO 6MowuLmxgUOde4AFu5pcGOw21bOhfnAHJAmRQWcAqKJciyPPdg1AA80OLvpuf4ej1akpLup+ cR/ZmtoAWn7iwVFVjx4g20o9ht7adWzU4LLhyG06gVxfW8CVgOu8hBxGml/MKE8lZvEk1etr HIU6/s5A5yZQA2usBvgTFHmaWpmzgAM+Rk3/6MI1gEcIyEZADa32sA+ChkWZN7c4+xZOnqTc 6gV8n4PICKpO4+TuS2xyHaOM3jpfEUhmUZWGSh9jZDg1oTXsSQTBJ89T07+jD9ZCqMWfVT7F n0yhah1LPhbsKdXGavAY8FuBnx4cZRTZCtWtPFlctIqWqYoK8qKz5TIT8B23FNwP9GpoASQB RIf5EqEkQ8Chi1UlMgugCLYoiC8252YI+Dl0yV1GKb+pLJIyKgsIJjDRcf7wg/gMAZlHFzK3 GUbBKP+3LMJfqAb3ktJCnjrDMjXL3mSQnN7hTA+trRCnNPaJn6WmneNpt1+mj/1hXc5tjx/c uhB38VDbZDdtMF116WcfBsZc2i2fCgvvt3aMWofmebW0387Ha5LsRce4zjjmFzXS8EGqVUX2 JrBSI4Z1nZmOmcRmeWjEbJec6FEHoNIzz8WESYSpJHRsJFupov8BR/Nr/LQCAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130412_151846_713471_5D1E37B3 X-CRM114-Status: GOOD ( 14.91 ) X-Spam-Score: -7.5 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.24 listed in list.dnswl.org] 1.7 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -2.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: mark.rutland@arm.com, heiko@sntech.de, Tomasz Figa , tomasz.figa@gmail.com, buserror@gmail.com, jacmet@sunsite.dk, augulis.darius@gmail.com, christer@weinigel.se, sylvester.nawrocki@gmail.com, m.szyprowski@samsung.com, kgene.kim@samsung.com, linux@arm.linux.org.uk, kwangwoo.lee@gmail.com, mcuelenaere@gmail.com, arnd@arndb.de, devicetree-discuss@lists.ozlabs.org, linux-samsung-soc@vger.kernel.org, john.stultz@linaro.org, ghcstop@gmail.com, linux@simtec.co.uk, broonie@opensource.wolfsonmicro.com, jekhor@gmail.com, kyungmin.park@samsung.com, tglx@linutronix.de 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 This patch modifies the clocksource registration code to use data taken from platform data instead of statically hardcoded defines. Signed-off-by: Tomasz Figa Signed-off-by: Kyungmin Park --- arch/arm/plat-samsung/devs.c | 7 +++ arch/arm/plat-samsung/include/plat/samsung-time.h | 29 +++++----- drivers/clocksource/samsung_pwm.c | 70 ++++++++++++++++------- include/clocksource/samsung_pwm.h | 1 + 4 files changed, 73 insertions(+), 34 deletions(-) diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c index bfae4dd..fbfabd2 100644 --- a/arch/arm/plat-samsung/devs.c +++ b/arch/arm/plat-samsung/devs.c @@ -32,6 +32,8 @@ #include #include +#include + #include #include @@ -1184,6 +1186,11 @@ struct platform_device samsung_device_pwm = { .resource = samsung_pwm_resource, }; +void samsung_timer_init(void) +{ + samsung_pwm_clocksource_init(&samsung_device_pwm); +} + /* RTC */ #ifdef CONFIG_PLAT_S3C24XX diff --git a/arch/arm/plat-samsung/include/plat/samsung-time.h b/arch/arm/plat-samsung/include/plat/samsung-time.h index ecc423c..633c151 100644 --- a/arch/arm/plat-samsung/include/plat/samsung-time.h +++ b/arch/arm/plat-samsung/include/plat/samsung-time.h @@ -13,6 +13,10 @@ #ifndef __ASM_PLAT_SAMSUNG_TIME_H #define __ASM_PLAT_SAMSUNG_TIME_H __FILE__ +#include + +#include + /* SAMSUNG HR-Timer Clock mode */ enum samsung_timer_mode { SAMSUNG_PWM0, @@ -22,20 +26,17 @@ enum samsung_timer_mode { SAMSUNG_PWM4, }; -#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S5PC100) -#define TCNT_MAX 0xffff -#define TSCALER_DIV 25 -#define TDIV 50 -#define TSIZE 16 -#else -#define TCNT_MAX 0xffffffff -#define TSCALER_DIV 2 -#define TDIV 2 -#define TSIZE 32 -#endif - -extern void __init samsung_set_timer_source(enum samsung_timer_mode event, - enum samsung_timer_mode source); +static inline void samsung_set_timer_source(enum samsung_timer_mode event, + enum samsung_timer_mode source) +{ + struct samsung_pwm_variant *variant; + + variant = samsung_device_pwm.dev.platform_data; + BUG_ON(!variant); + + variant->output_mask = (1 << 5) - 1; + variant->output_mask &= ~((1 << event) | (1 << source)); +} extern void __init samsung_timer_init(void); diff --git a/drivers/clocksource/samsung_pwm.c b/drivers/clocksource/samsung_pwm.c index 7bbd55c..841d03c 100644 --- a/drivers/clocksource/samsung_pwm.c +++ b/drivers/clocksource/samsung_pwm.c @@ -280,8 +280,13 @@ EXPORT_SYMBOL(samsung_pwm_get); struct samsung_timer_source { unsigned int event_id; unsigned int source_id; + unsigned int tcnt_max; + unsigned int tscaler_div; + unsigned int tdiv; }; +static struct samsung_pwm *pwm; + static struct clk *tin_event; static struct clk *tin_source; static struct clk *tdiv_event; @@ -473,20 +478,10 @@ static void samsung_timer_resume(void) samsung_time_start(timer_source.event_id, true); /* source timer restart */ - samsung_time_setup(timer_source.source_id, TCNT_MAX); + samsung_time_setup(timer_source.source_id, timer_source.tcnt_max); samsung_time_start(timer_source.source_id, true); } -void __init samsung_set_timer_source(enum samsung_timer_mode event, - enum samsung_timer_mode source) -{ - s3c_device_timer[event].dev.bus = &platform_bus_type; - s3c_device_timer[source].dev.bus = &platform_bus_type; - - timer_source.event_id = event; - timer_source.source_id = source; -} - static struct clock_event_device time_event_device = { .name = "samsung_event_timer", .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, @@ -522,8 +517,9 @@ static void __init samsung_clockevent_init(void) tscaler = clk_get_parent(tdiv_event); - clk_set_rate(tscaler, pclk / TSCALER_DIV); - clk_set_rate(tdiv_event, pclk / TDIV); + clk_set_rate(tscaler, pclk / timer_source.tscaler_div); + clk_set_rate(tdiv_event, + pclk / (timer_source.tdiv * timer_source.tscaler_div)); clk_set_parent(tin_event, tdiv_event); clock_rate = clk_get_rate(tin_event); @@ -532,7 +528,7 @@ static void __init samsung_clockevent_init(void) time_event_device.cpumask = cpumask_of(0); clockevents_config_and_register(&time_event_device, clock_rate, 1, -1); - irq_number = timer_source.event_id + IRQ_TIMER0; + irq_number = pwm->irq[timer_source.event_id]; setup_irq(irq_number, &samsung_clock_event_irq); } @@ -579,23 +575,29 @@ static u32 notrace samsung_read_sched_clock(void) static void __init samsung_clocksource_init(void) { + void __iomem *reg = samsung_timer_reg(); unsigned long pclk; unsigned long clock_rate; + int ret; pclk = clk_get_rate(timerclk); - clk_set_rate(tdiv_source, pclk / TDIV); + clk_set_rate(tdiv_source, + pclk / (timer_source.tdiv * timer_source.tscaler_div)); clk_set_parent(tin_source, tdiv_source); clock_rate = clk_get_rate(tin_source); - samsung_time_setup(timer_source.source_id, TCNT_MAX); + samsung_time_setup(timer_source.source_id, timer_source.tcnt_max); samsung_time_start(timer_source.source_id, true); - setup_sched_clock(samsung_read_sched_clock, TSIZE, clock_rate); + setup_sched_clock(samsung_read_sched_clock, + pwm->variant.bits, clock_rate); - if (clocksource_mmio_init(samsung_timer_reg(), "samsung_clocksource_timer", - clock_rate, 250, TSIZE, clocksource_mmio_readl_down)) + ret = clocksource_mmio_init(reg, "samsung_clocksource_timer", + clock_rate, 250, pwm->variant.bits, + clocksource_mmio_readl_down); + if (ret) panic("samsung_clocksource_timer: can't register clocksource\n"); } @@ -639,10 +641,38 @@ static void __init samsung_timer_resources(void) panic("failed to get pwm-tdiv clock for source timer"); clk_enable(tin_source); + + timer_source.tcnt_max = (1UL << pwm->variant.bits) - 1; + if (pwm->variant.bits == 16) { + timer_source.tscaler_div = 25; + timer_source.tdiv = 2; + } else { + timer_source.tscaler_div = 2; + timer_source.tdiv = 1; + } } -void __init samsung_timer_init(void) +void __init samsung_pwm_clocksource_init(struct platform_device *pdev) { + u8 mask; + int channel; + + pwm = samsung_pwm_get(pdev, NULL); + if (IS_ERR(pwm)) + panic("failed to get PWM device"); + + mask = ~pwm->variant.output_mask & ((1 << SAMSUNG_PWM_NUM) - 1); + channel = fls(mask) - 1; + if (channel < 0) + panic("failed to find PWM channel for clocksource"); + timer_source.source_id = channel; + + mask &= ~(1 << channel); + channel = fls(mask) - 1; + if (channel < 0) + panic("failed to find PWM channel for clock event"); + timer_source.event_id = channel; + samsung_timer_resources(); samsung_clockevent_init(); samsung_clocksource_init(); diff --git a/include/clocksource/samsung_pwm.h b/include/clocksource/samsung_pwm.h index d16415f..a0449d5 100644 --- a/include/clocksource/samsung_pwm.h +++ b/include/clocksource/samsung_pwm.h @@ -38,6 +38,7 @@ struct samsung_pwm { int irq[SAMSUNG_PWM_NUM]; }; +extern void samsung_pwm_clocksource_init(struct platform_device *); extern struct samsung_pwm *samsung_pwm_get(struct platform_device *, struct device_node *);