diff options
author | Tarun Kanti DebBarma <tarun.kanti@ti.com> | 2011-09-20 07:30:17 -0400 |
---|---|---|
committer | Tony Lindgren <tony@atomide.com> | 2011-09-21 18:50:31 -0400 |
commit | 97933d6ced601de013f17ad3f589e72cf2266bba (patch) | |
tree | 429e5afed768920acbd9661e5bc81eab24a2323e /arch | |
parent | 318c3e15cd55c73a26ae22a65a8183655b3003f9 (diff) |
ARM: OMAP1: dmtimer: conversion to platform devices
Convert OMAP1 dmtimers into a platform devices and then registers with
device model framework so that it can be bound to corresponding driver.
Signed-off-by: Thara Gopinath <thara@ti.com>
Signed-off-by: Tarun Kanti DebBarma <tarun.kanti@ti.com>
Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Acked-by: Cousson, Benoit <b-cousson@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mach-omap1/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-omap1/timer.c | 173 | ||||
-rw-r--r-- | arch/arm/plat-omap/dmtimer.c | 56 | ||||
-rw-r--r-- | arch/arm/plat-omap/include/plat/dmtimer.h | 8 |
4 files changed, 194 insertions, 45 deletions
diff --git a/arch/arm/mach-omap1/Makefile b/arch/arm/mach-omap1/Makefile index 5b114d1558c8..11c85cd2731a 100644 --- a/arch/arm/mach-omap1/Makefile +++ b/arch/arm/mach-omap1/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | # Common support | 5 | # Common support |
6 | obj-y := io.o id.o sram.o time.o irq.o mux.o flash.o serial.o devices.o dma.o | 6 | obj-y := io.o id.o sram.o time.o irq.o mux.o flash.o serial.o devices.o dma.o |
7 | obj-y += clock.o clock_data.o opp_data.o reset.o pm_bus.o | 7 | obj-y += clock.o clock_data.o opp_data.o reset.o pm_bus.o timer.o |
8 | 8 | ||
9 | obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o | 9 | obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o |
10 | 10 | ||
diff --git a/arch/arm/mach-omap1/timer.c b/arch/arm/mach-omap1/timer.c new file mode 100644 index 000000000000..6e90665a7c47 --- /dev/null +++ b/arch/arm/mach-omap1/timer.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /** | ||
2 | * OMAP1 Dual-Mode Timers - platform device registration | ||
3 | * | ||
4 | * Contains first level initialization routines which internally | ||
5 | * generates timer device information and registers with linux | ||
6 | * device model. It also has low level function to chnage the timer | ||
7 | * input clock source. | ||
8 | * | ||
9 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ | ||
10 | * Tarun Kanti DebBarma <tarun.kanti@ti.com> | ||
11 | * Thara Gopinath <thara@ti.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | * | ||
17 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
18 | * kind, whether express or implied; without even the implied warranty | ||
19 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | */ | ||
22 | |||
23 | #include <linux/clk.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/err.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | |||
29 | #include <mach/irqs.h> | ||
30 | |||
31 | #include <plat/dmtimer.h> | ||
32 | |||
33 | #define OMAP1610_GPTIMER1_BASE 0xfffb1400 | ||
34 | #define OMAP1610_GPTIMER2_BASE 0xfffb1c00 | ||
35 | #define OMAP1610_GPTIMER3_BASE 0xfffb2400 | ||
36 | #define OMAP1610_GPTIMER4_BASE 0xfffb2c00 | ||
37 | #define OMAP1610_GPTIMER5_BASE 0xfffb3400 | ||
38 | #define OMAP1610_GPTIMER6_BASE 0xfffb3c00 | ||
39 | #define OMAP1610_GPTIMER7_BASE 0xfffb7400 | ||
40 | #define OMAP1610_GPTIMER8_BASE 0xfffbd400 | ||
41 | |||
42 | #define OMAP1_DM_TIMER_COUNT 8 | ||
43 | |||
44 | static int omap1_dm_timer_set_src(struct platform_device *pdev, | ||
45 | int source) | ||
46 | { | ||
47 | int n = (pdev->id - 1) << 1; | ||
48 | u32 l; | ||
49 | |||
50 | l = __raw_readl(MOD_CONF_CTRL_1) & ~(0x03 << n); | ||
51 | l |= source << n; | ||
52 | __raw_writel(l, MOD_CONF_CTRL_1); | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | |||
58 | int __init omap1_dm_timer_init(void) | ||
59 | { | ||
60 | int i; | ||
61 | int ret; | ||
62 | struct dmtimer_platform_data *pdata; | ||
63 | struct platform_device *pdev; | ||
64 | |||
65 | if (!cpu_is_omap16xx()) | ||
66 | return 0; | ||
67 | |||
68 | for (i = 1; i <= OMAP1_DM_TIMER_COUNT; i++) { | ||
69 | struct resource res[2]; | ||
70 | u32 base, irq; | ||
71 | |||
72 | switch (i) { | ||
73 | case 1: | ||
74 | base = OMAP1610_GPTIMER1_BASE; | ||
75 | irq = INT_1610_GPTIMER1; | ||
76 | break; | ||
77 | case 2: | ||
78 | base = OMAP1610_GPTIMER2_BASE; | ||
79 | irq = INT_1610_GPTIMER2; | ||
80 | break; | ||
81 | case 3: | ||
82 | base = OMAP1610_GPTIMER3_BASE; | ||
83 | irq = INT_1610_GPTIMER3; | ||
84 | break; | ||
85 | case 4: | ||
86 | base = OMAP1610_GPTIMER4_BASE; | ||
87 | irq = INT_1610_GPTIMER4; | ||
88 | break; | ||
89 | case 5: | ||
90 | base = OMAP1610_GPTIMER5_BASE; | ||
91 | irq = INT_1610_GPTIMER5; | ||
92 | break; | ||
93 | case 6: | ||
94 | base = OMAP1610_GPTIMER6_BASE; | ||
95 | irq = INT_1610_GPTIMER6; | ||
96 | break; | ||
97 | case 7: | ||
98 | base = OMAP1610_GPTIMER7_BASE; | ||
99 | irq = INT_1610_GPTIMER7; | ||
100 | break; | ||
101 | case 8: | ||
102 | base = OMAP1610_GPTIMER8_BASE; | ||
103 | irq = INT_1610_GPTIMER8; | ||
104 | break; | ||
105 | default: | ||
106 | /* | ||
107 | * not supposed to reach here. | ||
108 | * this is to remove warning. | ||
109 | */ | ||
110 | return -EINVAL; | ||
111 | } | ||
112 | |||
113 | pdev = platform_device_alloc("omap_timer", i); | ||
114 | if (!pdev) { | ||
115 | pr_err("%s: Failed to device alloc for dmtimer%d\n", | ||
116 | __func__, i); | ||
117 | return -ENOMEM; | ||
118 | } | ||
119 | |||
120 | memset(res, 0, 2 * sizeof(struct resource)); | ||
121 | res[0].start = base; | ||
122 | res[0].end = base + 0x46; | ||
123 | res[0].flags = IORESOURCE_MEM; | ||
124 | res[1].start = irq; | ||
125 | res[1].end = irq; | ||
126 | res[1].flags = IORESOURCE_IRQ; | ||
127 | ret = platform_device_add_resources(pdev, res, | ||
128 | ARRAY_SIZE(res)); | ||
129 | if (ret) { | ||
130 | dev_err(&pdev->dev, "%s: Failed to add resources.\n", | ||
131 | __func__); | ||
132 | goto err_free_pdev; | ||
133 | } | ||
134 | |||
135 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | ||
136 | if (!pdata) { | ||
137 | dev_err(&pdev->dev, "%s: Failed to allocate pdata.\n", | ||
138 | __func__); | ||
139 | ret = -ENOMEM; | ||
140 | goto err_free_pdata; | ||
141 | } | ||
142 | |||
143 | pdata->set_timer_src = omap1_dm_timer_set_src; | ||
144 | pdata->needs_manual_reset = 1; | ||
145 | |||
146 | ret = platform_device_add_data(pdev, pdata, sizeof(*pdata)); | ||
147 | if (ret) { | ||
148 | dev_err(&pdev->dev, "%s: Failed to add platform data.\n", | ||
149 | __func__); | ||
150 | goto err_free_pdata; | ||
151 | } | ||
152 | |||
153 | ret = platform_device_add(pdev); | ||
154 | if (ret) { | ||
155 | dev_err(&pdev->dev, "%s: Failed to add platform device.\n", | ||
156 | __func__); | ||
157 | goto err_free_pdata; | ||
158 | } | ||
159 | |||
160 | dev_dbg(&pdev->dev, " Registered.\n"); | ||
161 | } | ||
162 | |||
163 | return 0; | ||
164 | |||
165 | err_free_pdata: | ||
166 | kfree(pdata); | ||
167 | |||
168 | err_free_pdev: | ||
169 | platform_device_unregister(pdev); | ||
170 | |||
171 | return ret; | ||
172 | } | ||
173 | arch_initcall(omap1_dm_timer_init); | ||
diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c index e23b7cf2b219..571c14b36497 100644 --- a/arch/arm/plat-omap/dmtimer.c +++ b/arch/arm/plat-omap/dmtimer.c | |||
@@ -3,6 +3,12 @@ | |||
3 | * | 3 | * |
4 | * OMAP Dual-Mode Timers | 4 | * OMAP Dual-Mode Timers |
5 | * | 5 | * |
6 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ | ||
7 | * Tarun Kanti DebBarma <tarun.kanti@ti.com> | ||
8 | * Thara Gopinath <thara@ti.com> | ||
9 | * | ||
10 | * dmtimer adaptation to platform_driver. | ||
11 | * | ||
6 | * Copyright (C) 2005 Nokia Corporation | 12 | * Copyright (C) 2005 Nokia Corporation |
7 | * OMAP2 support by Juha Yrjola | 13 | * OMAP2 support by Juha Yrjola |
8 | * API improvements and OMAP2 clock framework support by Timo Teras | 14 | * API improvements and OMAP2 clock framework support by Timo Teras |
@@ -43,25 +49,6 @@ | |||
43 | 49 | ||
44 | static int dm_timer_count; | 50 | static int dm_timer_count; |
45 | 51 | ||
46 | #ifdef CONFIG_ARCH_OMAP1 | ||
47 | static struct omap_dm_timer omap1_dm_timers[] = { | ||
48 | { .phys_base = 0xfffb1400, .irq = INT_1610_GPTIMER1 }, | ||
49 | { .phys_base = 0xfffb1c00, .irq = INT_1610_GPTIMER2 }, | ||
50 | { .phys_base = 0xfffb2400, .irq = INT_1610_GPTIMER3 }, | ||
51 | { .phys_base = 0xfffb2c00, .irq = INT_1610_GPTIMER4 }, | ||
52 | { .phys_base = 0xfffb3400, .irq = INT_1610_GPTIMER5 }, | ||
53 | { .phys_base = 0xfffb3c00, .irq = INT_1610_GPTIMER6 }, | ||
54 | { .phys_base = 0xfffb7400, .irq = INT_1610_GPTIMER7 }, | ||
55 | { .phys_base = 0xfffbd400, .irq = INT_1610_GPTIMER8 }, | ||
56 | }; | ||
57 | |||
58 | static const int omap1_dm_timer_count = ARRAY_SIZE(omap1_dm_timers); | ||
59 | |||
60 | #else | ||
61 | #define omap1_dm_timers NULL | ||
62 | #define omap1_dm_timer_count 0 | ||
63 | #endif /* CONFIG_ARCH_OMAP1 */ | ||
64 | |||
65 | #ifdef CONFIG_ARCH_OMAP2 | 52 | #ifdef CONFIG_ARCH_OMAP2 |
66 | static struct omap_dm_timer omap2_dm_timers[] = { | 53 | static struct omap_dm_timer omap2_dm_timers[] = { |
67 | { .phys_base = 0x48028000, .irq = INT_24XX_GPTIMER1 }, | 54 | { .phys_base = 0x48028000, .irq = INT_24XX_GPTIMER1 }, |
@@ -410,35 +397,20 @@ void omap_dm_timer_stop(struct omap_dm_timer *timer) | |||
410 | } | 397 | } |
411 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); | 398 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); |
412 | 399 | ||
413 | #ifdef CONFIG_ARCH_OMAP1 | ||
414 | |||
415 | int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) | ||
416 | { | ||
417 | int n = (timer - dm_timers) << 1; | ||
418 | u32 l; | ||
419 | |||
420 | l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n); | ||
421 | l |= source << n; | ||
422 | omap_writel(l, MOD_CONF_CTRL_1); | ||
423 | |||
424 | return 0; | ||
425 | } | ||
426 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); | ||
427 | |||
428 | #else | ||
429 | |||
430 | int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) | 400 | int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) |
431 | { | 401 | { |
432 | if (source < 0 || source >= 3) | 402 | if (source < 0 || source >= 3) |
433 | return -EINVAL; | 403 | return -EINVAL; |
434 | 404 | ||
405 | #ifdef CONFIG_ARCH_OMAP2PLUS | ||
435 | return __omap_dm_timer_set_source(timer->fclk, | 406 | return __omap_dm_timer_set_source(timer->fclk, |
436 | dm_source_clocks[source]); | 407 | dm_source_clocks[source]); |
408 | #else | ||
409 | return 0; | ||
410 | #endif | ||
437 | } | 411 | } |
438 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); | 412 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
439 | 413 | ||
440 | #endif | ||
441 | |||
442 | void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, | 414 | void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, |
443 | unsigned int load) | 415 | unsigned int load) |
444 | { | 416 | { |
@@ -582,16 +554,12 @@ static int __init omap_dm_timer_init(void) | |||
582 | struct omap_dm_timer *timer; | 554 | struct omap_dm_timer *timer; |
583 | int i, map_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */ | 555 | int i, map_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */ |
584 | 556 | ||
585 | if (!(cpu_is_omap16xx() || cpu_class_is_omap2())) | 557 | if (!cpu_class_is_omap2()) |
586 | return -ENODEV; | 558 | return -ENODEV; |
587 | 559 | ||
588 | spin_lock_init(&dm_timer_lock); | 560 | spin_lock_init(&dm_timer_lock); |
589 | 561 | ||
590 | if (cpu_class_is_omap1()) { | 562 | if (cpu_is_omap24xx()) { |
591 | dm_timers = omap1_dm_timers; | ||
592 | dm_timer_count = omap1_dm_timer_count; | ||
593 | map_size = SZ_2K; | ||
594 | } else if (cpu_is_omap24xx()) { | ||
595 | dm_timers = omap2_dm_timers; | 563 | dm_timers = omap2_dm_timers; |
596 | dm_timer_count = omap2_dm_timer_count; | 564 | dm_timer_count = omap2_dm_timer_count; |
597 | dm_source_names = omap2_dm_source_names; | 565 | dm_source_names = omap2_dm_source_names; |
diff --git a/arch/arm/plat-omap/include/plat/dmtimer.h b/arch/arm/plat-omap/include/plat/dmtimer.h index ad554d36866d..1751751862da 100644 --- a/arch/arm/plat-omap/include/plat/dmtimer.h +++ b/arch/arm/plat-omap/include/plat/dmtimer.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/clk.h> | 35 | #include <linux/clk.h> |
36 | #include <linux/delay.h> | 36 | #include <linux/delay.h> |
37 | #include <linux/io.h> | 37 | #include <linux/io.h> |
38 | #include <linux/platform_device.h> | ||
38 | 39 | ||
39 | #ifndef __ASM_ARCH_DMTIMER_H | 40 | #ifndef __ASM_ARCH_DMTIMER_H |
40 | #define __ASM_ARCH_DMTIMER_H | 41 | #define __ASM_ARCH_DMTIMER_H |
@@ -62,6 +63,12 @@ | |||
62 | struct omap_dm_timer; | 63 | struct omap_dm_timer; |
63 | struct clk; | 64 | struct clk; |
64 | 65 | ||
66 | struct dmtimer_platform_data { | ||
67 | int (*set_timer_src)(struct platform_device *pdev, int source); | ||
68 | int timer_ip_version; | ||
69 | u32 needs_manual_reset:1; | ||
70 | }; | ||
71 | |||
65 | struct omap_dm_timer *omap_dm_timer_request(void); | 72 | struct omap_dm_timer *omap_dm_timer_request(void); |
66 | struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id); | 73 | struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id); |
67 | void omap_dm_timer_free(struct omap_dm_timer *timer); | 74 | void omap_dm_timer_free(struct omap_dm_timer *timer); |
@@ -228,6 +235,7 @@ struct omap_dm_timer { | |||
228 | unsigned reserved:1; | 235 | unsigned reserved:1; |
229 | unsigned enabled:1; | 236 | unsigned enabled:1; |
230 | unsigned posted:1; | 237 | unsigned posted:1; |
238 | struct platform_device *pdev; | ||
231 | }; | 239 | }; |
232 | 240 | ||
233 | extern u32 sys_timer_reserved; | 241 | extern u32 sys_timer_reserved; |