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