From patchwork Sun Feb 10 13:20: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: 2122291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 60F283FCA4 for ; Sun, 10 Feb 2013 13:26:21 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U4Wt6-00067p-QH; Sun, 10 Feb 2013 13:24:08 +0000 Received: from mail-ea0-f174.google.com ([209.85.215.174]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U4WqF-0003wl-Uk for linux-arm-kernel@lists.infradead.org; Sun, 10 Feb 2013 13:21:14 +0000 Received: by mail-ea0-f174.google.com with SMTP id 1so2315021eaa.19 for ; Sun, 10 Feb 2013 05:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=5sbAdidry1yMCSpsq+P+MhcnHJtkfyYncq2lbXGFDaU=; b=ciWGB7NGl3rSlkGFyBC9oEcwO/sZrNED065l0P2ozpU9cWYPcpJWpT9+exfizGIALK 2jQ9V9dr+7vNhcyT37oPuostBBAM0xXakvHRvnTIcjhPVqkpxKumsw5a/ADqZcgpttxn RBl08NhxIABI2H7Lvxkngf0wAuPqBf6OGqrO9jhs02ne2pSg3luyn+QXWOIbdUC60Yxd r+PHN9tA68jB7MGva2+n5UlweNkBNoMJ+aiF6xrDcLN3CgQ/Psh5RulloQ70aSxNbueF tEAjaRrtWCI5cl/bJbzPzpAzYgnpSu5P4/mvnZxxPIwrRWKXSkPnpBpy246zDs5M/Xbf v4pw== X-Received: by 10.14.218.71 with SMTP id j47mr38450443eep.28.1360502466841; Sun, 10 Feb 2013 05:21:06 -0800 (PST) Received: from flatron.tomeq (87-207-52-162.dynamic.chello.pl. [87.207.52.162]) by mx.google.com with ESMTPS id 44sm57225596eek.5.2013.02.10.05.21.04 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 10 Feb 2013 05:21:05 -0800 (PST) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 12/12] clocksource: samsung-time: Add Device Tree support Date: Sun, 10 Feb 2013 14:20:23 +0100 Message-Id: <1360502423-2246-13-git-send-email-tomasz.figa@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360502423-2246-1-git-send-email-tomasz.figa@gmail.com> References: <1360502423-2246-1-git-send-email-tomasz.figa@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130210_082112_245691_05694FB5 X-CRM114-Status: GOOD ( 17.79 ) X-Spam-Score: 0.3 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.174 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (tomasz.figa[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: arhuaco@freaks-unidos.net, Kukjin Kim , linux@arm.linux.org.uk, kwangwoo.lee@gmail.com, devicetree-discuss@lists.ozlabs.org, guillaume.gourat@nexvision.tv, bhmin@samsung.com, broonie@opensource.wolfsonmicro.com, mcuelenaere@gmail.com, Tomasz Figa , christer@weinigel.se, danders@amltd.com, kyungmin.park@samsung.com, linux-samsung-soc@vger.kernel.org, buserror@gmail.com, augulis.darius@gmail.com, jacmet@sunsite.dk, Sylwester Nawrocki , ghcstop@gmail.com, linux@simtec.co.uk, jekhor@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds support for parsing all platform-specific data from Device Tree and instantiation using clocksource_of_init to samsung-time clocksource driver. Cc: devicetree-discuss@lists.ozlabs.org Signed-off-by: Tomasz Figa --- .../devicetree/bindings/arm/samsung-timer.txt | 32 +++++++ drivers/clocksource/samsung-time.c | 102 ++++++++++++++++++++- 2 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/samsung-timer.txt diff --git a/Documentation/devicetree/bindings/arm/samsung-timer.txt b/Documentation/devicetree/bindings/arm/samsung-timer.txt new file mode 100644 index 0000000..8eb7030 --- /dev/null +++ b/Documentation/devicetree/bindings/arm/samsung-timer.txt @@ -0,0 +1,32 @@ +* Samsung PWM timer + +Samsung SoCs contain PWM timer blocks which can be used for system clock source +and clock event timers. + +Be aware that this configuration is supported only on uniprocessor platforms. +For SMP SoCs, SMP-aware timers should be used, like MCT. + +Required properties: +- compatible : should be one of following: + samsung,s3c24xx-pwm-timer - for 16-bit timers present on S3C24xx + samsung,s3c64xx-pwm-timer - for 32-bit timers present on S3C64xx and newer +- reg: base address and size of register area +- interrupts: interrupt list for all five PWM timers. +- samsung,source-timer: index of timer to be used as clocksource +- samsung,event-timer: index of timer to be used as clock event + +Optional properties: +- samsung,prescale: PWM prescaler divisor (from 1 to 256) +- samsung,divisor: PWM main divider divisor (1, 2, 4, 8 or 16) + +Example: + timer@7f006000 { + compatible = "samsung,s3c64xx-pwm-timer"; + reg = <0x7f006000 0x1000>; + interrupt-parent = <&vic0>; + interrupts = <23>, <24>, <25>, <27>, <28>; + samsung,source-timer = <4>; + samsung,event-timer = <3>; + samsung,prescale = <2>; + samsung,divisor = <1>; + }; diff --git a/drivers/clocksource/samsung-time.c b/drivers/clocksource/samsung-time.c index 19a1c8a..63d2992 100644 --- a/drivers/clocksource/samsung-time.c +++ b/drivers/clocksource/samsung-time.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include #include @@ -479,9 +482,11 @@ static void __init samsung_timer_resources(void) unsigned long source_id = timer_source.source_id; char devname[15]; - timer_base = ioremap_nocache(timer_variant.reg_base, SZ_4K); - if (!timer_base) - panic("failed to map timer registers"); + if (!timer_base) { + timer_base = ioremap_nocache(timer_variant.reg_base, SZ_4K); + if (!timer_base) + panic("failed to map timer registers"); + } timerclk = clk_get(NULL, "timers"); if (IS_ERR(timerclk)) @@ -514,8 +519,92 @@ static void __init samsung_timer_resources(void) clk_enable(tin_source); } +enum { + TYPE_S3C24XX, + TYPE_S3C64XX, +}; + +#ifdef CONFIG_OF +static const struct of_device_id samsung_timer_ids[] = { + { .compatible = "samsung,s3c24xx-pwm-timer", + .data = (void *)TYPE_S3C24XX, }, + { .compatible = "samsung,s3c64xx-pwm-timer", + .data = (void *)TYPE_S3C64XX, }, + {}, +}; + +static void samsung_timer_parse_dt(struct device_node *np, + const struct of_device_id *match) +{ + int i; + u32 val; + + if (of_property_read_u32(np, "samsung,source-timer", &val)) + panic("no samsung,source-timer property provided"); + if (val > ARRAY_SIZE(timer_variant.irqs)) + panic("samsung,source-timer property out of range"); + timer_source.source_id = val; + + if (of_property_read_u32(np, "samsung,event-timer", &val)) + panic("no samsung,event-timer property provided"); + if (val > ARRAY_SIZE(timer_variant.irqs)) + panic("samsung,event-timer property out of range"); + timer_source.event_id = val; + + timer_base = of_iomap(np, 0); + if (!timer_base) + panic("failed to map timer registers"); + + for (i = 0; i < ARRAY_SIZE(timer_variant.irqs); ++i) + timer_variant.irqs[i] = irq_of_parse_and_map(np, i); + + if (!timer_variant.irqs[timer_source.event_id]) + panic("no clock event irq provided"); + + switch ((unsigned int)match->data) { + case TYPE_S3C24XX: + timer_variant.bits = 16; + timer_variant.prescale = 25; + timer_variant.prescale = 50; + timer_variant.has_tint_cstat = false; + break; + case TYPE_S3C64XX: + timer_variant.bits = 32; + timer_variant.prescale = 2; + timer_variant.divisor = 2; + timer_variant.has_tint_cstat = true; + break; + } + + if (!of_property_read_u32(np, "samsung,prescale", &val)) { + if (val < 1 || val > 256) + panic("prescale must be from 1 to 256 range"); + timer_variant.prescale = val; + } + + if (!of_property_read_u32(np, "samsung,divisor", &val)) { + if (val > 16 || (1 << (fls(val) - 1)) != val) + panic("divsor must be 1, 2, 4, 8 or 16"); + timer_variant.divisor = timer_variant.prescale * val; + } +} +#endif + void __init samsung_timer_init(void) { +#ifdef CONFIG_OF + struct device_node *np; + const struct of_device_id *match; + + if (of_have_populated_dt()) { + np = of_find_matching_node_and_match(NULL, + samsung_timer_ids, &match); + if (!np) + panic("timer node not found"); + + samsung_timer_parse_dt(np, match); + } +#endif if (!timer_source.source_id && !timer_source.event_id) panic("timer sources not set (see samsung_set_timer_source)!\n"); @@ -526,3 +615,10 @@ void __init samsung_timer_init(void) samsung_clockevent_init(); samsung_clocksource_init(); } + +#ifdef CONFIG_OF +CLOCKSOURCE_OF_DECLARE(s3c24xx_timer, + "samsung,s3c24xx-pwm-timer", samsung_timer_init) +CLOCKSOURCE_OF_DECLARE(s3c64xx_timer, + "samsung,s3c64xx-pwm-timer", samsung_timer_init) +#endif