http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-integrator / impd1.c
1 /*
2  *  linux/arch/arm/mach-integrator/impd1.c
3  *
4  *  Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  This file provides the core support for the IM-PD1 module.
11  *
12  * Module / boot parameters.
13  *   lmid=n   impd1.lmid=n - set the logic module position in stack to 'n'
14  */
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/device.h>
19 #include <linux/errno.h>
20
21 #include <asm/io.h>
22 #include <asm/hardware/icst525.h>
23 #include <asm/hardware/amba.h>
24 #include <asm/arch/lm.h>
25 #include <asm/arch/impd1.h>
26 #include <asm/sizes.h>
27
28 #include "clock.h"
29
30 static int module_id;
31
32 module_param_named(lmid, module_id, int, 0444);
33 MODULE_PARM_DESC(lmid, "logic module stack position");
34
35 struct impd1_module {
36         void            *base;
37         struct clk      vcos[2];
38 };
39
40 static const struct icst525_params impd1_vco_params = {
41         .ref            = 24000,        /* 24 MHz */
42         .vco_max        = 200000,       /* 200 MHz */
43         .vd_min         = 12,
44         .vd_max         = 519,
45         .rd_min         = 3,
46         .rd_max         = 120,
47 };
48
49 static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
50 {
51         struct impd1_module *impd1 = clk->data;
52         int vconr = clk - impd1->vcos;
53         u32 val;
54
55         val = vco.v | (vco.r << 9) | (vco.s << 16);
56
57         writel(0xa05f, impd1->base + IMPD1_LOCK);
58         switch (vconr) {
59         case 0:
60                 writel(val, impd1->base + IMPD1_OSC1);
61                 break;
62         case 1:
63                 writel(val, impd1->base + IMPD1_OSC2);
64                 break;
65         }
66         writel(0, impd1->base + IMPD1_LOCK);
67
68 #if DEBUG
69         vco.v = val & 0x1ff;
70         vco.r = (val >> 9) & 0x7f;
71         vco.s = (val >> 16) & 7;
72
73         pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
74                  vconr, icst525_khz(&impd1_vco_params, vco));
75 #endif
76 }
77
78 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
79 {
80         struct impd1_module *impd1 = dev_get_drvdata(dev);
81         u32 cur;
82
83         val &= mask;
84         cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
85         writel(cur | val, impd1->base + IMPD1_CTRL);
86 }
87
88 EXPORT_SYMBOL(impd1_tweak_control);
89
90 struct impd1_device {
91         unsigned long   offset;
92         unsigned int    irq[2];
93         unsigned int    id;
94 };
95
96 static struct impd1_device impd1_devs[] = {
97         {
98                 .offset = 0x03000000,
99                 .id     = 0x00041190,
100         }, {
101                 .offset = 0x00100000,
102                 .irq    = { 1 },
103                 .id     = 0x00141011,
104         }, {
105                 .offset = 0x00200000,
106                 .irq    = { 2 },
107                 .id     = 0x00141011,
108         }, {
109                 .offset = 0x00300000,
110                 .irq    = { 3 },
111                 .id     = 0x00041022,
112         }, {
113                 .offset = 0x00400000,
114                 .irq    = { 4 },
115                 .id     = 0x00041061,
116         }, {
117                 .offset = 0x00500000,
118                 .irq    = { 5 },
119                 .id     = 0x00041061,
120         }, {
121                 .offset = 0x00600000,
122                 .irq    = { 6 },
123                 .id     = 0x00041130,
124         }, {
125                 .offset = 0x00700000,
126                 .irq    = { 7, 8 },
127                 .id     = 0x00041181,
128         }, {
129                 .offset = 0x00800000,
130                 .irq    = { 9 },
131                 .id     = 0x00041041,
132         }, {
133                 .offset = 0x01000000,
134                 .irq    = { 11 },
135                 .id     = 0x00041110,
136         }
137 };
138
139 static const char *impd1_vconames[2] = {
140         "CLCDCLK",
141         "AUXVCO2",
142 };
143
144 static int impd1_probe(struct lm_device *dev)
145 {
146         struct impd1_module *impd1;
147         int i, ret;
148
149         if (dev->id != module_id)
150                 return -EINVAL;
151
152         if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
153                 return -EBUSY;
154
155         impd1 = kmalloc(sizeof(struct impd1_module), GFP_KERNEL);
156         if (!impd1) {
157                 ret = -ENOMEM;
158                 goto release_lm;
159         }
160         memset(impd1, 0, sizeof(struct impd1_module));
161
162         impd1->base = ioremap(dev->resource.start, SZ_4K);
163         if (!impd1->base) {
164                 ret = -ENOMEM;
165                 goto free_impd1;
166         }
167
168         lm_set_drvdata(dev, impd1);
169
170         printk("IM-PD1 found at 0x%08lx\n", dev->resource.start);
171
172         for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
173                 impd1->vcos[i].owner = THIS_MODULE,
174                 impd1->vcos[i].name = impd1_vconames[i],
175                 impd1->vcos[i].params = &impd1_vco_params,
176                 impd1->vcos[i].data = impd1,
177                 impd1->vcos[i].setvco = impd1_setvco;
178
179                 clk_register(&impd1->vcos[i]);
180         }
181
182         for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
183                 struct impd1_device *idev = impd1_devs + i;
184                 struct amba_device *d;
185                 unsigned long pc_base;
186
187                 pc_base = dev->resource.start + idev->offset;
188
189                 d = kmalloc(sizeof(struct amba_device), GFP_KERNEL);
190                 if (!d)
191                         continue;
192
193                 memset(d, 0, sizeof(struct amba_device));
194
195                 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
196                          "lm%x:%5.5lx", dev->id, idev->offset >> 12);
197
198                 d->dev.parent   = &dev->dev;
199                 d->res.start    = dev->resource.start + idev->offset;
200                 d->res.end      = d->res.start + SZ_4K - 1;
201                 d->res.flags    = IORESOURCE_MEM;
202                 d->irq[0]       = dev->irq;
203                 d->irq[1]       = dev->irq;
204                 d->periphid     = idev->id;
205
206                 ret = amba_device_register(d, &dev->resource);
207                 if (ret) {
208                         printk("unable to register device %s: %d\n",
209                                 d->dev.bus_id, ret);
210                         kfree(d);
211                 }
212         }
213
214         return 0;
215
216  free_impd1:
217         if (impd1 && impd1->base)
218                 iounmap(impd1->base);
219         if (impd1)
220                 kfree(impd1);
221  release_lm:
222         release_mem_region(dev->resource.start, SZ_4K);
223         return ret;
224 }
225
226 static void impd1_remove(struct lm_device *dev)
227 {
228         struct impd1_module *impd1 = lm_get_drvdata(dev);
229         struct list_head *l, *n;
230         int i;
231
232         list_for_each_safe(l, n, &dev->dev.children) {
233                 struct device *d = list_to_dev(l);
234
235                 device_unregister(d);
236         }
237
238         for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
239                 clk_unregister(&impd1->vcos[i]);
240
241         lm_set_drvdata(dev, NULL);
242
243         iounmap(impd1->base);
244         kfree(impd1);
245         release_mem_region(dev->resource.start, SZ_4K);
246 }
247
248 static struct lm_driver impd1_driver = {
249         .drv = {
250                 .name   = "impd1",
251         },
252         .probe          = impd1_probe,
253         .remove         = impd1_remove,
254 };
255
256 static int __init impd1_init(void)
257 {
258         return lm_driver_register(&impd1_driver);
259 }
260
261 static void __exit impd1_exit(void)
262 {
263         lm_driver_unregister(&impd1_driver);
264 }
265
266 module_init(impd1_init);
267 module_exit(impd1_exit);
268
269 MODULE_LICENSE("GPL");
270 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
271 MODULE_AUTHOR("Deep Blue Solutions Ltd");