]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/arm/mach-integrator/impd1.c
Manual merge with Linus.
[linux-2.6.git] / 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 #include <linux/mm.h>
21 #include <linux/amba/bus.h>
22 #include <linux/amba/clcd.h>
23
24 #include <asm/io.h>
25 #include <asm/hardware/icst525.h>
26 #include <asm/arch/lm.h>
27 #include <asm/arch/impd1.h>
28 #include <asm/sizes.h>
29
30 #include "clock.h"
31
32 static int module_id;
33
34 module_param_named(lmid, module_id, int, 0444);
35 MODULE_PARM_DESC(lmid, "logic module stack position");
36
37 struct impd1_module {
38         void __iomem    *base;
39         struct clk      vcos[2];
40 };
41
42 static const struct icst525_params impd1_vco_params = {
43         .ref            = 24000,        /* 24 MHz */
44         .vco_max        = 200000,       /* 200 MHz */
45         .vd_min         = 12,
46         .vd_max         = 519,
47         .rd_min         = 3,
48         .rd_max         = 120,
49 };
50
51 static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
52 {
53         struct impd1_module *impd1 = clk->data;
54         int vconr = clk - impd1->vcos;
55         u32 val;
56
57         val = vco.v | (vco.r << 9) | (vco.s << 16);
58
59         writel(0xa05f, impd1->base + IMPD1_LOCK);
60         switch (vconr) {
61         case 0:
62                 writel(val, impd1->base + IMPD1_OSC1);
63                 break;
64         case 1:
65                 writel(val, impd1->base + IMPD1_OSC2);
66                 break;
67         }
68         writel(0, impd1->base + IMPD1_LOCK);
69
70 #ifdef DEBUG
71         vco.v = val & 0x1ff;
72         vco.r = (val >> 9) & 0x7f;
73         vco.s = (val >> 16) & 7;
74
75         pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
76                  vconr, icst525_khz(&impd1_vco_params, vco));
77 #endif
78 }
79
80 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
81 {
82         struct impd1_module *impd1 = dev_get_drvdata(dev);
83         u32 cur;
84
85         val &= mask;
86         cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
87         writel(cur | val, impd1->base + IMPD1_CTRL);
88 }
89
90 EXPORT_SYMBOL(impd1_tweak_control);
91
92 /*
93  * CLCD support
94  */
95 #define PANEL           PROSPECTOR
96
97 #define LTM10C209               1
98 #define PROSPECTOR              2
99 #define SVGA                    3
100 #define VGA                     4
101
102 #if PANEL == VGA
103 #define PANELTYPE       vga
104 static struct clcd_panel vga = {
105         .mode           = {
106                 .name           = "VGA",
107                 .refresh        = 60,
108                 .xres           = 640,
109                 .yres           = 480,
110                 .pixclock       = 39721,
111                 .left_margin    = 40,
112                 .right_margin   = 24,
113                 .upper_margin   = 32,
114                 .lower_margin   = 11,
115                 .hsync_len      = 96,
116                 .vsync_len      = 2,
117                 .sync           = 0,
118                 .vmode          = FB_VMODE_NONINTERLACED,
119         },
120         .width          = -1,
121         .height         = -1,
122         .tim2           = TIM2_BCD | TIM2_IPC,
123         .cntl           = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
124         .connector      = IMPD1_CTRL_DISP_VGA,
125         .bpp            = 16,
126         .grayscale      = 0,
127 };
128
129 #elif PANEL == SVGA
130 #define PANELTYPE       svga
131 static struct clcd_panel svga = {
132         .mode           = {
133                 .name           = "SVGA",
134                 .refresh        = 0,
135                 .xres           = 800,
136                 .yres           = 600,
137                 .pixclock       = 27778,
138                 .left_margin    = 20,
139                 .right_margin   = 20,
140                 .upper_margin   = 5,
141                 .lower_margin   = 5,
142                 .hsync_len      = 164,
143                 .vsync_len      = 62,
144                 .sync           = 0,
145                 .vmode          = FB_VMODE_NONINTERLACED,
146         },
147         .width          = -1,
148         .height         = -1,
149         .tim2           = TIM2_BCD,
150         .cntl           = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
151         .connector      = IMPD1_CTRL_DISP_VGA,
152         .bpp            = 16,
153         .grayscale      = 0,
154 };
155
156 #elif PANEL == PROSPECTOR
157 #define PANELTYPE       prospector
158 static struct clcd_panel prospector = {
159         .mode           = {
160                 .name           = "PROSPECTOR",
161                 .refresh        = 0,
162                 .xres           = 640,
163                 .yres           = 480,
164                 .pixclock       = 40000,
165                 .left_margin    = 33,
166                 .right_margin   = 64,
167                 .upper_margin   = 36,
168                 .lower_margin   = 7,
169                 .hsync_len      = 64,
170                 .vsync_len      = 25,
171                 .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
172                 .vmode          = FB_VMODE_NONINTERLACED,
173         },
174         .width          = -1,
175         .height         = -1,
176         .tim2           = TIM2_BCD,
177         .cntl           = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
178         .fixedtimings   = 1,
179         .connector      = IMPD1_CTRL_DISP_LCD,
180         .bpp            = 16,
181         .grayscale      = 0,
182 };
183
184 #elif PANEL == LTM10C209
185 #define PANELTYPE       ltm10c209
186 /*
187  * Untested.
188  */
189 static struct clcd_panel ltm10c209 = {
190         .mode           = {
191                 .name           = "LTM10C209",
192                 .refresh        = 0,
193                 .xres           = 640,
194                 .yres           = 480,
195                 .pixclock       = 40000,
196                 .left_margin    = 20,
197                 .right_margin   = 20,
198                 .upper_margin   = 19,
199                 .lower_margin   = 19,
200                 .hsync_len      = 20,
201                 .vsync_len      = 10,
202                 .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
203                 .vmode          = FB_VMODE_NONINTERLACED,
204         },
205         .width          = -1,
206         .height         = -1,
207         .tim2           = TIM2_BCD,
208         .cntl           = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
209         .fixedtimings   = 1,
210         .connector      = IMPD1_CTRL_DISP_LCD,
211         .bpp            = 16,
212         .grayscale      = 0,
213 };
214 #endif
215
216 /*
217  * Disable all display connectors on the interface module.
218  */
219 static void impd1fb_clcd_disable(struct clcd_fb *fb)
220 {
221         impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
222 }
223
224 /*
225  * Enable the relevant connector on the interface module.
226  */
227 static void impd1fb_clcd_enable(struct clcd_fb *fb)
228 {
229         impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
230                         fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
231 }
232
233 static int impd1fb_clcd_setup(struct clcd_fb *fb)
234 {
235         unsigned long framebase = fb->dev->res.start + 0x01000000;
236         unsigned long framesize = SZ_1M;
237         int ret = 0;
238
239         fb->panel = &PANELTYPE;
240
241         if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
242                 printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
243                 return -EBUSY;
244         }
245
246         fb->fb.screen_base = ioremap(framebase, framesize);
247         if (!fb->fb.screen_base) {
248                 printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
249                 ret = -ENOMEM;
250                 goto free_buffer;
251         }
252
253         fb->fb.fix.smem_start   = framebase;
254         fb->fb.fix.smem_len     = framesize;
255
256         return 0;
257
258  free_buffer:
259         release_mem_region(framebase, framesize);
260         return ret;
261 }
262
263 static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
264 {
265         unsigned long start, size;
266
267         start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
268         size = vma->vm_end - vma->vm_start;
269
270         return remap_pfn_range(vma, vma->vm_start, start, size,
271                                vma->vm_page_prot);
272 }
273
274 static void impd1fb_clcd_remove(struct clcd_fb *fb)
275 {
276         iounmap(fb->fb.screen_base);
277         release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
278 }
279
280 static struct clcd_board impd1_clcd_data = {
281         .name           = "IM-PD/1",
282         .check          = clcdfb_check,
283         .decode         = clcdfb_decode,
284         .disable        = impd1fb_clcd_disable,
285         .enable         = impd1fb_clcd_enable,
286         .setup          = impd1fb_clcd_setup,
287         .mmap           = impd1fb_clcd_mmap,
288         .remove         = impd1fb_clcd_remove,
289 };
290
291 struct impd1_device {
292         unsigned long   offset;
293         unsigned int    irq[2];
294         unsigned int    id;
295         void            *platform_data;
296 };
297
298 static struct impd1_device impd1_devs[] = {
299         {
300                 .offset = 0x03000000,
301                 .id     = 0x00041190,
302         }, {
303                 .offset = 0x00100000,
304                 .irq    = { 1 },
305                 .id     = 0x00141011,
306         }, {
307                 .offset = 0x00200000,
308                 .irq    = { 2 },
309                 .id     = 0x00141011,
310         }, {
311                 .offset = 0x00300000,
312                 .irq    = { 3 },
313                 .id     = 0x00041022,
314         }, {
315                 .offset = 0x00400000,
316                 .irq    = { 4 },
317                 .id     = 0x00041061,
318         }, {
319                 .offset = 0x00500000,
320                 .irq    = { 5 },
321                 .id     = 0x00041061,
322         }, {
323                 .offset = 0x00600000,
324                 .irq    = { 6 },
325                 .id     = 0x00041130,
326         }, {
327                 .offset = 0x00700000,
328                 .irq    = { 7, 8 },
329                 .id     = 0x00041181,
330         }, {
331                 .offset = 0x00800000,
332                 .irq    = { 9 },
333                 .id     = 0x00041041,
334         }, {
335                 .offset = 0x01000000,
336                 .irq    = { 11 },
337                 .id     = 0x00041110,
338                 .platform_data = &impd1_clcd_data,
339         }
340 };
341
342 static const char *impd1_vconames[2] = {
343         "CLCDCLK",
344         "AUXVCO2",
345 };
346
347 static int impd1_probe(struct lm_device *dev)
348 {
349         struct impd1_module *impd1;
350         int i, ret;
351
352         if (dev->id != module_id)
353                 return -EINVAL;
354
355         if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
356                 return -EBUSY;
357
358         impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
359         if (!impd1) {
360                 ret = -ENOMEM;
361                 goto release_lm;
362         }
363
364         impd1->base = ioremap(dev->resource.start, SZ_4K);
365         if (!impd1->base) {
366                 ret = -ENOMEM;
367                 goto free_impd1;
368         }
369
370         lm_set_drvdata(dev, impd1);
371
372         printk("IM-PD1 found at 0x%08lx\n", dev->resource.start);
373
374         for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
375                 impd1->vcos[i].owner = THIS_MODULE,
376                 impd1->vcos[i].name = impd1_vconames[i],
377                 impd1->vcos[i].params = &impd1_vco_params,
378                 impd1->vcos[i].data = impd1,
379                 impd1->vcos[i].setvco = impd1_setvco;
380
381                 clk_register(&impd1->vcos[i]);
382         }
383
384         for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
385                 struct impd1_device *idev = impd1_devs + i;
386                 struct amba_device *d;
387                 unsigned long pc_base;
388
389                 pc_base = dev->resource.start + idev->offset;
390
391                 d = kzalloc(sizeof(struct amba_device), GFP_KERNEL);
392                 if (!d)
393                         continue;
394
395                 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
396                          "lm%x:%5.5lx", dev->id, idev->offset >> 12);
397
398                 d->dev.parent   = &dev->dev;
399                 d->res.start    = dev->resource.start + idev->offset;
400                 d->res.end      = d->res.start + SZ_4K - 1;
401                 d->res.flags    = IORESOURCE_MEM;
402                 d->irq[0]       = dev->irq;
403                 d->irq[1]       = dev->irq;
404                 d->periphid     = idev->id;
405                 d->dev.platform_data = idev->platform_data;
406
407                 ret = amba_device_register(d, &dev->resource);
408                 if (ret) {
409                         printk("unable to register device %s: %d\n",
410                                 d->dev.bus_id, ret);
411                         kfree(d);
412                 }
413         }
414
415         return 0;
416
417  free_impd1:
418         if (impd1 && impd1->base)
419                 iounmap(impd1->base);
420         kfree(impd1);
421  release_lm:
422         release_mem_region(dev->resource.start, SZ_4K);
423         return ret;
424 }
425
426 static int impd1_remove_one(struct device *dev, void *data)
427 {
428         device_unregister(dev);
429         return 0;
430 }
431
432 static void impd1_remove(struct lm_device *dev)
433 {
434         struct impd1_module *impd1 = lm_get_drvdata(dev);
435         int i;
436
437         device_for_each_child(&dev->dev, NULL, impd1_remove_one);
438
439         for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
440                 clk_unregister(&impd1->vcos[i]);
441
442         lm_set_drvdata(dev, NULL);
443
444         iounmap(impd1->base);
445         kfree(impd1);
446         release_mem_region(dev->resource.start, SZ_4K);
447 }
448
449 static struct lm_driver impd1_driver = {
450         .drv = {
451                 .name   = "impd1",
452         },
453         .probe          = impd1_probe,
454         .remove         = impd1_remove,
455 };
456
457 static int __init impd1_init(void)
458 {
459         return lm_driver_register(&impd1_driver);
460 }
461
462 static void __exit impd1_exit(void)
463 {
464         lm_driver_unregister(&impd1_driver);
465 }
466
467 module_init(impd1_init);
468 module_exit(impd1_exit);
469
470 MODULE_LICENSE("GPL");
471 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
472 MODULE_AUTHOR("Deep Blue Solutions Ltd");