* [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support
[not found] <1361033044-27629-1-git-send-email-tomasz.figa@gmail.com>
@ 2013-02-16 16:44 ` Tomasz Figa
2013-02-18 2:39 ` Rob Herring
2013-02-18 9:48 ` Mark Rutland
0 siblings, 2 replies; 3+ messages in thread
From: Tomasz Figa @ 2013-02-16 16:44 UTC (permalink / raw)
To: linux-arm-kernel
Cc: linux-samsung-soc, Kukjin Kim, kyungmin.park, linux, broonie,
kwangwoo.lee, jacmet, augulis.darius, mcuelenaere, linux,
Sylwester Nawrocki, buserror, christer, jekhor, ghcstop,
Mark Rutland, Tomasz Figa, devicetree-discuss
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 <tomasz.figa@gmail.com>
---
.../devicetree/bindings/arm/samsung-timer.txt | 33 ++++++
drivers/clocksource/samsung-time.c | 113 ++++++++++++++++++++-
2 files changed, 143 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..179b7e4
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/samsung-timer.txt
@@ -0,0 +1,33 @@
+* 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: list of timer interrupts (one interrupt per timer, starting at
+ timer 0)
+
+Optional properties:
+- samsung,source-timer: index of timer to be used as clocksource (defaults to 4)
+- samsung,event-timer: index of timer to be used as clock event (defaults to 3)
+- samsung,prescale-divisor: 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-divisor = <2>;
+ samsung,divisor = <1>;
+ };
diff --git a/drivers/clocksource/samsung-time.c b/drivers/clocksource/samsung-time.c
index 4134811..76a15ca 100644
--- a/drivers/clocksource/samsung-time.c
+++ b/drivers/clocksource/samsung-time.c
@@ -14,6 +14,9 @@
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/clockchips.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <clocksource/samsung-time.h>
@@ -480,9 +483,12 @@ 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) {
+ /* Compatibility fallback for non-DT platforms */
+ 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))
@@ -515,8 +521,102 @@ 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;
+
+ timer_base = of_iomap(np, 0);
+ if (!timer_base)
+ panic("failed to map timer registers");
+
+ for (i = 0; i < SAMSUNG_PWM_NUM; ++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;
+ }
+
+ timer_source.source_id = 4;
+ if (!of_property_read_u32(np, "samsung,source-timer", &val)) {
+ if (val >= SAMSUNG_PWM_NUM)
+ panic("samsung,source-timer property out of range");
+ timer_source.source_id = val;
+ }
+
+ timer_source.event_id = 3;
+ if (!of_property_read_u32(np, "samsung,event-timer", &val)) {
+ if (val >= SAMSUNG_PWM_NUM)
+ panic("samsung,event-timer property out of range");
+ timer_source.event_id = val;
+ }
+
+ if (!of_property_read_u32(np, "samsung,prescale-divisor", &val)) {
+ if (val < 1 || val > 256)
+ panic("samsung,prescale-divisor property out of range");
+ timer_variant.prescale = val;
+ }
+
+ if (!of_property_read_u32(np, "samsung,divisor", &val)) {
+ switch (val) {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16:
+ timer_variant.divisor = timer_variant.prescale * val;
+ break;
+ default:
+ panic("invalid value of samsung,divisor property");
+ }
+ }
+}
+#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");
@@ -527,3 +627,10 @@ void __init samsung_timer_init(void)
samsung_clockevent_init();
samsung_clocksource_init();
}
+
+#ifdef CONFIG_CLKSRC_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
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support
2013-02-16 16:44 ` [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support Tomasz Figa
@ 2013-02-18 2:39 ` Rob Herring
2013-02-18 9:48 ` Mark Rutland
1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring @ 2013-02-18 2:39 UTC (permalink / raw)
To: Tomasz Figa
Cc: linux-arm-kernel, ghcstop, Kukjin Kim, linux, kwangwoo.lee,
devicetree-discuss, broonie, mcuelenaere, christer, kyungmin.park,
linux-samsung-soc, buserror, augulis.darius, Sylwester Nawrocki,
linux, jekhor
On 02/16/2013 10:44 AM, Tomasz Figa wrote:
> This patch adds support for parsing all platform-specific data from
> Device Tree and instantiation using clocksource_of_init to samsung-time
> clocksource driver.
> +Optional properties:
> +- samsung,source-timer: index of timer to be used as clocksource (defaults to 4)
> +- samsung,event-timer: index of timer to be used as clock event (defaults to 3)
This is Linux specific, not a h/w property. Define the h/w properties of
the timers so that Linux can decide which timer to use. See the omap2
timers for an example.
> +- samsung,prescale-divisor: 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-divisor = <2>;
> + samsung,divisor = <1>;
> + };
> diff --git a/drivers/clocksource/samsung-time.c b/drivers/clocksource/samsung-time.c
> index 4134811..76a15ca 100644
> --- a/drivers/clocksource/samsung-time.c
> +++ b/drivers/clocksource/samsung-time.c
> @@ -14,6 +14,9 @@
> #include <linux/err.h>
> #include <linux/clk.h>
> #include <linux/clockchips.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/of_irq.h>
> #include <linux/platform_device.h>
>
> #include <clocksource/samsung-time.h>
> @@ -480,9 +483,12 @@ 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) {
> + /* Compatibility fallback for non-DT platforms */
> + 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))
> @@ -515,8 +521,102 @@ 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, },
Shouldn't need 2 match tables and the data here is kind of pointless
when you can just use the compatible string.
> + {},
> +};
> +
> +static void samsung_timer_parse_dt(struct device_node *np,
> + const struct of_device_id *match)
> +{
> + int i;
> + u32 val;
> +
> + timer_base = of_iomap(np, 0);
> + if (!timer_base)
> + panic("failed to map timer registers");
> +
> + for (i = 0; i < SAMSUNG_PWM_NUM; ++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;
> + }
> +
> + timer_source.source_id = 4;
> + if (!of_property_read_u32(np, "samsung,source-timer", &val)) {
> + if (val >= SAMSUNG_PWM_NUM)
> + panic("samsung,source-timer property out of range");
> + timer_source.source_id = val;
> + }
> +
> + timer_source.event_id = 3;
> + if (!of_property_read_u32(np, "samsung,event-timer", &val)) {
> + if (val >= SAMSUNG_PWM_NUM)
> + panic("samsung,event-timer property out of range");
> + timer_source.event_id = val;
> + }
> +
> + if (!of_property_read_u32(np, "samsung,prescale-divisor", &val)) {
> + if (val < 1 || val > 256)
> + panic("samsung,prescale-divisor property out of range");
> + timer_variant.prescale = val;
> + }
> +
> + if (!of_property_read_u32(np, "samsung,divisor", &val)) {
> + switch (val) {
> + case 1:
> + case 2:
> + case 4:
> + case 8:
> + case 16:
> + timer_variant.divisor = timer_variant.prescale * val;
> + break;
> + default:
> + panic("invalid value of samsung,divisor property");
> + }
> + }
> +}
> +#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()) {
Separate the OF and non-OF code to avoid this and the ifdef.
> + np = of_find_matching_node_and_match(NULL,
> + samsung_timer_ids, &match);
> + if (!np)
> + panic("timer node not found");
I have a patch to change this function to pass in the node ptr and avoid
matching twice. It should be in arm-soc shortly after rc1.
Rob
> +
> + 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");
>
> @@ -527,3 +627,10 @@ void __init samsung_timer_init(void)
> samsung_clockevent_init();
> samsung_clocksource_init();
> }
> +
> +#ifdef CONFIG_CLKSRC_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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support
2013-02-16 16:44 ` [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support Tomasz Figa
2013-02-18 2:39 ` Rob Herring
@ 2013-02-18 9:48 ` Mark Rutland
1 sibling, 0 replies; 3+ messages in thread
From: Mark Rutland @ 2013-02-18 9:48 UTC (permalink / raw)
To: Tomasz Figa
Cc: linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org, Kukjin Kim,
kyungmin.park@samsung.com, linux@simtec.co.uk,
broonie@opensource.wolfsonmicro.com, kwangwoo.lee@gmail.com,
jacmet@sunsite.dk, augulis.darius@gmail.com,
mcuelenaere@gmail.com, linux@arm.linux.org.uk, Sylwester Nawrocki,
buserror@gmail.com, christer@weinigel.se, jekhor@gmail.com,
ghcstop@gmail.com
Hi,
[...]
> +static void samsung_timer_parse_dt(struct device_node *np,
> + const struct of_device_id *match)
> +{
> + int i;
> + u32 val;
> +
> + timer_base = of_iomap(np, 0);
> + if (!timer_base)
> + panic("failed to map timer registers");
> +
> + for (i = 0; i < SAMSUNG_PWM_NUM; ++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;
Redundant conflicting assignments here.
Thanks,
Mark.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-18 9:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1361033044-27629-1-git-send-email-tomasz.figa@gmail.com>
2013-02-16 16:44 ` [PATCH v2 12/12] clocksource: samsung-time: Add Device Tree support Tomasz Figa
2013-02-18 2:39 ` Rob Herring
2013-02-18 9:48 ` Mark Rutland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).