ARM: cpu topology: Add debugfs interface for cpu_power
[cmplus.git] / arch / arm / mach-omap1 / dmtimer.c
blobdbc189cb2e143ac7e1544c94fd15d01f2d441535
1 /**
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
7 * input clock source.
9 * Copyright (C) 2010 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>
24 #include <linux/io.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 #define OMAP_TIMER_OCP_CFG_REG 0x10
45 #define OMAP_TIMER_SYS_STAT_REG 0x14
46 #define OMAP_TIMER_IF_CTRL_REG 0x40
48 static int omap1_dm_timer_set_src(struct platform_device *pdev,
49 int source)
51 int n = (pdev->id - 1) << 1;
52 u32 l;
54 l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n);
55 l |= source << n;
56 omap_writel(l, MOD_CONF_CTRL_1);
58 return 0;
62 int __init omap1_dm_timer_init(void)
64 int i;
65 int ret;
66 struct dmtimer_platform_data *pdata;
67 struct platform_device *pdev;
69 if (!cpu_is_omap16xx())
70 return 0;
72 for (i = 1; i <= OMAP1_DM_TIMER_COUNT; i++) {
73 struct resource res[2];
74 u32 base, irq;
76 switch (i) {
77 case 1:
78 base = OMAP1610_GPTIMER1_BASE;
79 irq = INT_1610_GPTIMER1;
80 break;
81 case 2:
82 base = OMAP1610_GPTIMER2_BASE;
83 irq = INT_1610_GPTIMER2;
84 break;
85 case 3:
86 base = OMAP1610_GPTIMER3_BASE;
87 irq = INT_1610_GPTIMER3;
88 break;
89 case 4:
90 base = OMAP1610_GPTIMER4_BASE;
91 irq = INT_1610_GPTIMER4;
92 break;
93 case 5:
94 base = OMAP1610_GPTIMER5_BASE;
95 irq = INT_1610_GPTIMER5;
96 break;
97 case 6:
98 base = OMAP1610_GPTIMER6_BASE;
99 irq = INT_1610_GPTIMER6;
100 break;
101 case 7:
102 base = OMAP1610_GPTIMER7_BASE;
103 irq = INT_1610_GPTIMER7;
104 break;
105 case 8:
106 base = OMAP1610_GPTIMER8_BASE;
107 irq = INT_1610_GPTIMER8;
108 break;
109 default:
111 * not supposed to reach here.
112 * this is to remove warning.
114 return -EINVAL;
117 pdev = platform_device_alloc("omap_timer", i);
118 if (!pdev) {
119 pr_err("%s: Failed to device alloc for dmtimer%d\n",
120 __func__, i);
121 return -ENOMEM;
124 memset(res, 0, 2 * sizeof(struct resource));
125 res[0].start = base;
126 res[0].end = base + 0x46;
127 res[0].flags = IORESOURCE_MEM;
128 res[1].start = irq;
129 res[1].end = irq;
130 res[1].flags = IORESOURCE_IRQ;
131 ret = platform_device_add_resources(pdev, res,
132 ARRAY_SIZE(res));
133 if (ret) {
134 dev_err(&pdev->dev, "%s: Failed to add resources.\n",
135 __func__);
136 goto err_free_pdev;
139 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
140 if (!pdata) {
141 dev_err(&pdev->dev, "%s: Failed to allocate pdata.\n",
142 __func__);
143 ret = -ENOMEM;
144 goto err_free_pdata;
147 pdata->set_timer_src = omap1_dm_timer_set_src;
148 pdata->is_early_init = 0;
149 pdata->timer_ip_type = OMAP_TIMER_IP_VERSION_1;
150 pdata->needs_manual_reset = 1;
152 ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
153 if (ret) {
154 dev_err(&pdev->dev, "%s: Failed to add platform data.\n",
155 __func__);
156 goto err_free_pdata;
159 ret = platform_device_add(pdev);
160 if (ret) {
161 dev_err(&pdev->dev, "%s: Failed to add platform device.\n",
162 __func__);
163 goto err_free_pdata;
166 dev_dbg(&pdev->dev, " Registered.\n");
169 return 0;
171 err_free_pdata:
172 kfree(pdata);
174 err_free_pdev:
175 platform_device_unregister(pdev);
177 return ret;
179 arch_initcall(omap1_dm_timer_init);