2 * OMAP1 Dual-Mode Timers - platform device registration
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
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>
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.
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.
23 #include <linux/clk.h>
25 #include <linux/err.h>
26 #include <linux/slab.h>
27 #include <linux/platform_device.h>
29 #include <mach/irqs.h>
31 #include <plat/dmtimer.h>
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
42 #define OMAP1_DM_TIMER_COUNT 8
44 static int omap1_dm_timer_set_src(struct platform_device
*pdev
,
47 int n
= (pdev
->id
- 1) << 1;
50 l
= omap_readl(MOD_CONF_CTRL_1
) & ~(0x03 << n
);
52 omap_writel(l
, MOD_CONF_CTRL_1
);
57 static int __init
omap1_dm_timer_init(void)
61 struct dmtimer_platform_data
*pdata
;
62 struct platform_device
*pdev
;
64 if (!cpu_is_omap16xx())
67 for (i
= 1; i
<= OMAP1_DM_TIMER_COUNT
; i
++) {
68 struct resource res
[2];
73 base
= OMAP1610_GPTIMER1_BASE
;
74 irq
= INT_1610_GPTIMER1
;
77 base
= OMAP1610_GPTIMER2_BASE
;
78 irq
= INT_1610_GPTIMER2
;
81 base
= OMAP1610_GPTIMER3_BASE
;
82 irq
= INT_1610_GPTIMER3
;
85 base
= OMAP1610_GPTIMER4_BASE
;
86 irq
= INT_1610_GPTIMER4
;
89 base
= OMAP1610_GPTIMER5_BASE
;
90 irq
= INT_1610_GPTIMER5
;
93 base
= OMAP1610_GPTIMER6_BASE
;
94 irq
= INT_1610_GPTIMER6
;
97 base
= OMAP1610_GPTIMER7_BASE
;
98 irq
= INT_1610_GPTIMER7
;
101 base
= OMAP1610_GPTIMER8_BASE
;
102 irq
= INT_1610_GPTIMER8
;
106 * not supposed to reach here.
107 * this is to remove warning.
112 pdev
= platform_device_alloc("omap_timer", i
);
114 pr_err("%s: Failed to device alloc for dmtimer%d\n",
119 memset(res
, 0, 2 * sizeof(struct resource
));
121 res
[0].end
= base
+ 0x46;
122 res
[0].flags
= IORESOURCE_MEM
;
125 res
[1].flags
= IORESOURCE_IRQ
;
126 ret
= platform_device_add_resources(pdev
, res
,
129 dev_err(&pdev
->dev
, "%s: Failed to add resources.\n",
134 pdata
= kzalloc(sizeof(*pdata
), GFP_KERNEL
);
136 dev_err(&pdev
->dev
, "%s: Failed to allocate pdata.\n",
142 pdata
->set_timer_src
= omap1_dm_timer_set_src
;
143 pdata
->needs_manual_reset
= 1;
145 ret
= platform_device_add_data(pdev
, pdata
, sizeof(*pdata
));
147 dev_err(&pdev
->dev
, "%s: Failed to add platform data.\n",
152 ret
= platform_device_add(pdev
);
154 dev_err(&pdev
->dev
, "%s: Failed to add platform device.\n",
159 dev_dbg(&pdev
->dev
, " Registered.\n");
168 platform_device_unregister(pdev
);
172 arch_initcall(omap1_dm_timer_init
);