initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / arm / mach-integrator / impd1.c
blob0859557e7133e22729ad8ea510a5e4ca17f916ce
1 /*
2 * linux/arch/arm/mach-integrator/impd1.c
4 * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
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.
10 * This file provides the core support for the IM-PD1 module.
12 * Module / boot parameters.
13 * lmid=n impd1.lmid=n - set the logic module position in stack to 'n'
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>
21 #include <asm/io.h>
22 #include <asm/hardware/icst525.h>
23 #include <asm/hardware/amba.h>
24 #include <asm/hardware/amba_clcd.h>
25 #include <asm/arch/lm.h>
26 #include <asm/arch/impd1.h>
27 #include <asm/sizes.h>
29 #include "clock.h"
31 static int module_id;
33 module_param_named(lmid, module_id, int, 0444);
34 MODULE_PARM_DESC(lmid, "logic module stack position");
36 struct impd1_module {
37 void *base;
38 struct clk vcos[2];
41 static const struct icst525_params impd1_vco_params = {
42 .ref = 24000, /* 24 MHz */
43 .vco_max = 200000, /* 200 MHz */
44 .vd_min = 12,
45 .vd_max = 519,
46 .rd_min = 3,
47 .rd_max = 120,
50 static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
52 struct impd1_module *impd1 = clk->data;
53 int vconr = clk - impd1->vcos;
54 u32 val;
56 val = vco.v | (vco.r << 9) | (vco.s << 16);
58 writel(0xa05f, impd1->base + IMPD1_LOCK);
59 switch (vconr) {
60 case 0:
61 writel(val, impd1->base + IMPD1_OSC1);
62 break;
63 case 1:
64 writel(val, impd1->base + IMPD1_OSC2);
65 break;
67 writel(0, impd1->base + IMPD1_LOCK);
69 #if DEBUG
70 vco.v = val & 0x1ff;
71 vco.r = (val >> 9) & 0x7f;
72 vco.s = (val >> 16) & 7;
74 pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
75 vconr, icst525_khz(&impd1_vco_params, vco));
76 #endif
79 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
81 struct impd1_module *impd1 = dev_get_drvdata(dev);
82 u32 cur;
84 val &= mask;
85 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
86 writel(cur | val, impd1->base + IMPD1_CTRL);
89 EXPORT_SYMBOL(impd1_tweak_control);
92 * CLCD support
94 #define PANEL PROSPECTOR
96 #define LTM10C209 1
97 #define PROSPECTOR 2
98 #define SVGA 3
99 #define VGA 4
101 #if PANEL == VGA
102 #define PANELTYPE vga
103 static struct clcd_panel vga = {
104 .mode = {
105 .name = "VGA",
106 .refresh = 60,
107 .xres = 640,
108 .yres = 480,
109 .pixclock = 39721,
110 .left_margin = 40,
111 .right_margin = 24,
112 .upper_margin = 32,
113 .lower_margin = 11,
114 .hsync_len = 96,
115 .vsync_len = 2,
116 .sync = 0,
117 .vmode = FB_VMODE_NONINTERLACED,
119 .width = -1,
120 .height = -1,
121 .tim2 = TIM2_BCD | TIM2_IPC,
122 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
123 .connector = IMPD1_CTRL_DISP_VGA,
124 .bpp = 16,
125 .grayscale = 0,
128 #elif PANEL == SVGA
129 #define PANELTYPE svga
130 static struct clcd_panel svga = {
131 .mode = {
132 .name = "SVGA",
133 .refresh = 0,
134 .xres = 800,
135 .yres = 600,
136 .pixclock = 27778,
137 .left_margin = 20,
138 .right_margin = 20,
139 .upper_margin = 5,
140 .lower_margin = 5,
141 .hsync_len = 164,
142 .vsync_len = 62,
143 .sync = 0,
144 .vmode = FB_VMODE_NONINTERLACED,
146 .width = -1,
147 .height = -1,
148 .tim2 = TIM2_BCD,
149 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
150 .connector = IMPD1_CTRL_DISP_VGA,
151 .bpp = 16,
152 .grayscale = 0,
155 #elif PANEL == PROSPECTOR
156 #define PANELTYPE prospector
157 static struct clcd_panel prospector = {
158 .mode = {
159 .name = "PROSPECTOR",
160 .refresh = 0,
161 .xres = 640,
162 .yres = 480,
163 .pixclock = 40000,
164 .left_margin = 33,
165 .right_margin = 64,
166 .upper_margin = 36,
167 .lower_margin = 7,
168 .hsync_len = 64,
169 .vsync_len = 25,
170 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
171 .vmode = FB_VMODE_NONINTERLACED,
173 .width = -1,
174 .height = -1,
175 .tim2 = TIM2_BCD,
176 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
177 .fixedtimings = 1,
178 .connector = IMPD1_CTRL_DISP_LCD,
179 .bpp = 16,
180 .grayscale = 0,
183 #elif PANEL == LTM10C209
184 #define PANELTYPE ltm10c209
186 * Untested.
188 static struct clcd_panel ltm10c209 = {
189 .mode = {
190 .name = "LTM10C209",
191 .refresh = 0,
192 .xres = 640,
193 .yres = 480,
194 .pixclock = 40000,
195 .left_margin = 20,
196 .right_margin = 20,
197 .upper_margin = 19,
198 .lower_margin = 19,
199 .hsync_len = 20,
200 .vsync_len = 10,
201 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
202 .vmode = FB_VMODE_NONINTERLACED,
204 .width = -1,
205 .height = -1,
206 .tim2 = TIM2_BCD,
207 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
208 .fixedtimings = 1,
209 .connector = IMPD1_CTRL_DISP_LCD,
210 .bpp = 16,
211 .grayscale = 0,
213 #endif
216 * Disable all display connectors on the interface module.
218 static void impd1fb_clcd_disable(struct clcd_fb *fb)
220 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
224 * Enable the relevant connector on the interface module.
226 static void impd1fb_clcd_enable(struct clcd_fb *fb)
228 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
229 fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
232 static int impd1fb_clcd_setup(struct clcd_fb *fb)
234 unsigned long framebase = fb->dev->res.start + 0x01000000;
235 unsigned long framesize = SZ_1M;
236 int ret = 0;
238 fb->panel = &PANELTYPE;
240 if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
241 printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
242 return -EBUSY;
245 fb->fb.screen_base = ioremap(framebase, framesize);
246 if (!fb->fb.screen_base) {
247 printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
248 ret = -ENOMEM;
249 goto free_buffer;
252 fb->fb.fix.smem_start = framebase;
253 fb->fb.fix.smem_len = framesize;
255 return 0;
257 free_buffer:
258 release_mem_region(framebase, framesize);
259 return ret;
262 static void impd1fb_clcd_remove(struct clcd_fb *fb)
264 iounmap(fb->fb.screen_base);
265 release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
268 static struct clcd_board impd1_clcd_data = {
269 .name = "IM-PD/1",
270 .check = clcdfb_check,
271 .decode = clcdfb_decode,
272 .disable = impd1fb_clcd_disable,
273 .enable = impd1fb_clcd_enable,
274 .setup = impd1fb_clcd_setup,
275 .remove = impd1fb_clcd_remove,
278 struct impd1_device {
279 unsigned long offset;
280 unsigned int irq[2];
281 unsigned int id;
282 void *platform_data;
285 static struct impd1_device impd1_devs[] = {
287 .offset = 0x03000000,
288 .id = 0x00041190,
289 }, {
290 .offset = 0x00100000,
291 .irq = { 1 },
292 .id = 0x00141011,
293 }, {
294 .offset = 0x00200000,
295 .irq = { 2 },
296 .id = 0x00141011,
297 }, {
298 .offset = 0x00300000,
299 .irq = { 3 },
300 .id = 0x00041022,
301 }, {
302 .offset = 0x00400000,
303 .irq = { 4 },
304 .id = 0x00041061,
305 }, {
306 .offset = 0x00500000,
307 .irq = { 5 },
308 .id = 0x00041061,
309 }, {
310 .offset = 0x00600000,
311 .irq = { 6 },
312 .id = 0x00041130,
313 }, {
314 .offset = 0x00700000,
315 .irq = { 7, 8 },
316 .id = 0x00041181,
317 }, {
318 .offset = 0x00800000,
319 .irq = { 9 },
320 .id = 0x00041041,
321 }, {
322 .offset = 0x01000000,
323 .irq = { 11 },
324 .id = 0x00041110,
325 .platform_data = &impd1_clcd_data,
329 static const char *impd1_vconames[2] = {
330 "CLCDCLK",
331 "AUXVCO2",
334 static int impd1_probe(struct lm_device *dev)
336 struct impd1_module *impd1;
337 int i, ret;
339 if (dev->id != module_id)
340 return -EINVAL;
342 if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
343 return -EBUSY;
345 impd1 = kmalloc(sizeof(struct impd1_module), GFP_KERNEL);
346 if (!impd1) {
347 ret = -ENOMEM;
348 goto release_lm;
350 memset(impd1, 0, sizeof(struct impd1_module));
352 impd1->base = ioremap(dev->resource.start, SZ_4K);
353 if (!impd1->base) {
354 ret = -ENOMEM;
355 goto free_impd1;
358 lm_set_drvdata(dev, impd1);
360 printk("IM-PD1 found at 0x%08lx\n", dev->resource.start);
362 for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
363 impd1->vcos[i].owner = THIS_MODULE,
364 impd1->vcos[i].name = impd1_vconames[i],
365 impd1->vcos[i].params = &impd1_vco_params,
366 impd1->vcos[i].data = impd1,
367 impd1->vcos[i].setvco = impd1_setvco;
369 clk_register(&impd1->vcos[i]);
372 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
373 struct impd1_device *idev = impd1_devs + i;
374 struct amba_device *d;
375 unsigned long pc_base;
377 pc_base = dev->resource.start + idev->offset;
379 d = kmalloc(sizeof(struct amba_device), GFP_KERNEL);
380 if (!d)
381 continue;
383 memset(d, 0, sizeof(struct amba_device));
385 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
386 "lm%x:%5.5lx", dev->id, idev->offset >> 12);
388 d->dev.parent = &dev->dev;
389 d->res.start = dev->resource.start + idev->offset;
390 d->res.end = d->res.start + SZ_4K - 1;
391 d->res.flags = IORESOURCE_MEM;
392 d->irq[0] = dev->irq;
393 d->irq[1] = dev->irq;
394 d->periphid = idev->id;
395 d->dev.platform_data = idev->platform_data;
397 ret = amba_device_register(d, &dev->resource);
398 if (ret) {
399 printk("unable to register device %s: %d\n",
400 d->dev.bus_id, ret);
401 kfree(d);
405 return 0;
407 free_impd1:
408 if (impd1 && impd1->base)
409 iounmap(impd1->base);
410 if (impd1)
411 kfree(impd1);
412 release_lm:
413 release_mem_region(dev->resource.start, SZ_4K);
414 return ret;
417 static void impd1_remove(struct lm_device *dev)
419 struct impd1_module *impd1 = lm_get_drvdata(dev);
420 struct list_head *l, *n;
421 int i;
423 list_for_each_safe(l, n, &dev->dev.children) {
424 struct device *d = list_to_dev(l);
426 device_unregister(d);
429 for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
430 clk_unregister(&impd1->vcos[i]);
432 lm_set_drvdata(dev, NULL);
434 iounmap(impd1->base);
435 kfree(impd1);
436 release_mem_region(dev->resource.start, SZ_4K);
439 static struct lm_driver impd1_driver = {
440 .drv = {
441 .name = "impd1",
443 .probe = impd1_probe,
444 .remove = impd1_remove,
447 static int __init impd1_init(void)
449 return lm_driver_register(&impd1_driver);
452 static void __exit impd1_exit(void)
454 lm_driver_unregister(&impd1_driver);
457 module_init(impd1_init);
458 module_exit(impd1_exit);
460 MODULE_LICENSE("GPL");
461 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
462 MODULE_AUTHOR("Deep Blue Solutions Ltd");