blob: 2f9de622d1fa13d65dfb4e1dd3ea5aa9b3ea687d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Russell Kinga62c80e2006-01-07 13:52:45 +000021#include <linux/amba/bus.h>
22#include <linux/amba/clcd.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Russell Kingd72fbdf2008-11-08 20:08:08 +000025#include <asm/clkdev.h>
26#include <mach/clkdev.h>
Russell Kingc5a0adb2010-01-16 20:16:10 +000027#include <asm/hardware/icst.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/lm.h>
29#include <mach/impd1.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/sizes.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int module_id;
33
34module_param_named(lmid, module_id, int, 0444);
35MODULE_PARM_DESC(lmid, "logic module stack position");
36
37struct impd1_module {
38 void __iomem *base;
39 struct clk vcos[2];
Russell Kingd72fbdf2008-11-08 20:08:08 +000040 struct clk_lookup *clks[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
42
Russell King39c0cb02010-01-16 16:27:28 +000043static const struct icst_params impd1_vco_params = {
Russell King64fceb12010-01-16 17:28:44 +000044 .ref = 24000000, /* 24 MHz */
Russell King4de2edb2010-01-16 18:08:47 +000045 .vco_max = ICST525_VCO_MAX_3V,
Russell Kinge73a46a2010-01-16 19:49:39 +000046 .vco_min = ICST525_VCO_MIN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .vd_min = 12,
48 .vd_max = 519,
49 .rd_min = 3,
50 .rd_max = 120,
Russell King232eaf72010-01-16 19:46:19 +000051 .s2div = icst525_s2div,
52 .idx2s = icst525_idx2s,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
Russell King39c0cb02010-01-16 16:27:28 +000055static void impd1_setvco(struct clk *clk, struct icst_vco vco)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 struct impd1_module *impd1 = clk->data;
Russell Kingd1914c72010-01-14 20:09:34 +000058 u32 val = vco.v | (vco.r << 9) | (vco.s << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 writel(0xa05f, impd1->base + IMPD1_LOCK);
Russell Kingd1914c72010-01-14 20:09:34 +000061 writel(val, clk->vcoreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 writel(0, impd1->base + IMPD1_LOCK);
63
Russell Kingd1856632005-10-21 10:17:37 +010064#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 vco.v = val & 0x1ff;
66 vco.r = (val >> 9) & 0x7f;
67 vco.s = (val >> 16) & 7;
68
Russell King64fceb12010-01-16 17:28:44 +000069 pr_debug("IM-PD1: VCO%d clock is %ld Hz\n",
70 vconr, icst525_hz(&impd1_vco_params, vco));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#endif
72}
73
74void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
75{
76 struct impd1_module *impd1 = dev_get_drvdata(dev);
77 u32 cur;
78
79 val &= mask;
80 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
81 writel(cur | val, impd1->base + IMPD1_CTRL);
82}
83
84EXPORT_SYMBOL(impd1_tweak_control);
85
86/*
87 * CLCD support
88 */
89#define PANEL PROSPECTOR
90
91#define LTM10C209 1
92#define PROSPECTOR 2
93#define SVGA 3
94#define VGA 4
95
96#if PANEL == VGA
97#define PANELTYPE vga
98static struct clcd_panel vga = {
99 .mode = {
100 .name = "VGA",
101 .refresh = 60,
102 .xres = 640,
103 .yres = 480,
104 .pixclock = 39721,
105 .left_margin = 40,
106 .right_margin = 24,
107 .upper_margin = 32,
108 .lower_margin = 11,
109 .hsync_len = 96,
110 .vsync_len = 2,
111 .sync = 0,
112 .vmode = FB_VMODE_NONINTERLACED,
113 },
114 .width = -1,
115 .height = -1,
116 .tim2 = TIM2_BCD | TIM2_IPC,
117 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
118 .connector = IMPD1_CTRL_DISP_VGA,
119 .bpp = 16,
120 .grayscale = 0,
121};
122
123#elif PANEL == SVGA
124#define PANELTYPE svga
125static struct clcd_panel svga = {
126 .mode = {
127 .name = "SVGA",
128 .refresh = 0,
129 .xres = 800,
130 .yres = 600,
131 .pixclock = 27778,
132 .left_margin = 20,
133 .right_margin = 20,
134 .upper_margin = 5,
135 .lower_margin = 5,
136 .hsync_len = 164,
137 .vsync_len = 62,
138 .sync = 0,
139 .vmode = FB_VMODE_NONINTERLACED,
140 },
141 .width = -1,
142 .height = -1,
143 .tim2 = TIM2_BCD,
144 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
145 .connector = IMPD1_CTRL_DISP_VGA,
146 .bpp = 16,
147 .grayscale = 0,
148};
149
150#elif PANEL == PROSPECTOR
151#define PANELTYPE prospector
152static struct clcd_panel prospector = {
153 .mode = {
154 .name = "PROSPECTOR",
155 .refresh = 0,
156 .xres = 640,
157 .yres = 480,
158 .pixclock = 40000,
159 .left_margin = 33,
160 .right_margin = 64,
161 .upper_margin = 36,
162 .lower_margin = 7,
163 .hsync_len = 64,
164 .vsync_len = 25,
165 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
166 .vmode = FB_VMODE_NONINTERLACED,
167 },
168 .width = -1,
169 .height = -1,
170 .tim2 = TIM2_BCD,
171 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
172 .fixedtimings = 1,
173 .connector = IMPD1_CTRL_DISP_LCD,
174 .bpp = 16,
175 .grayscale = 0,
176};
177
178#elif PANEL == LTM10C209
179#define PANELTYPE ltm10c209
180/*
181 * Untested.
182 */
183static struct clcd_panel ltm10c209 = {
184 .mode = {
185 .name = "LTM10C209",
186 .refresh = 0,
187 .xres = 640,
188 .yres = 480,
189 .pixclock = 40000,
190 .left_margin = 20,
191 .right_margin = 20,
192 .upper_margin = 19,
193 .lower_margin = 19,
194 .hsync_len = 20,
195 .vsync_len = 10,
196 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
197 .vmode = FB_VMODE_NONINTERLACED,
198 },
199 .width = -1,
200 .height = -1,
201 .tim2 = TIM2_BCD,
202 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
203 .fixedtimings = 1,
204 .connector = IMPD1_CTRL_DISP_LCD,
205 .bpp = 16,
206 .grayscale = 0,
207};
208#endif
209
210/*
211 * Disable all display connectors on the interface module.
212 */
213static void impd1fb_clcd_disable(struct clcd_fb *fb)
214{
215 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
216}
217
218/*
219 * Enable the relevant connector on the interface module.
220 */
221static void impd1fb_clcd_enable(struct clcd_fb *fb)
222{
223 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
224 fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
225}
226
227static int impd1fb_clcd_setup(struct clcd_fb *fb)
228{
229 unsigned long framebase = fb->dev->res.start + 0x01000000;
230 unsigned long framesize = SZ_1M;
231 int ret = 0;
232
233 fb->panel = &PANELTYPE;
234
235 if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
236 printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
237 return -EBUSY;
238 }
239
240 fb->fb.screen_base = ioremap(framebase, framesize);
241 if (!fb->fb.screen_base) {
242 printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
243 ret = -ENOMEM;
244 goto free_buffer;
245 }
246
247 fb->fb.fix.smem_start = framebase;
248 fb->fb.fix.smem_len = framesize;
249
250 return 0;
251
252 free_buffer:
253 release_mem_region(framebase, framesize);
254 return ret;
255}
256
257static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
258{
259 unsigned long start, size;
260
261 start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
262 size = vma->vm_end - vma->vm_start;
263
264 return remap_pfn_range(vma, vma->vm_start, start, size,
265 vma->vm_page_prot);
266}
267
268static void impd1fb_clcd_remove(struct clcd_fb *fb)
269{
270 iounmap(fb->fb.screen_base);
271 release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
272}
273
274static struct clcd_board impd1_clcd_data = {
275 .name = "IM-PD/1",
276 .check = clcdfb_check,
277 .decode = clcdfb_decode,
278 .disable = impd1fb_clcd_disable,
279 .enable = impd1fb_clcd_enable,
280 .setup = impd1fb_clcd_setup,
281 .mmap = impd1fb_clcd_mmap,
282 .remove = impd1fb_clcd_remove,
283};
284
285struct impd1_device {
286 unsigned long offset;
287 unsigned int irq[2];
288 unsigned int id;
289 void *platform_data;
290};
291
292static struct impd1_device impd1_devs[] = {
293 {
294 .offset = 0x03000000,
295 .id = 0x00041190,
296 }, {
297 .offset = 0x00100000,
298 .irq = { 1 },
299 .id = 0x00141011,
300 }, {
301 .offset = 0x00200000,
302 .irq = { 2 },
303 .id = 0x00141011,
304 }, {
305 .offset = 0x00300000,
306 .irq = { 3 },
307 .id = 0x00041022,
308 }, {
309 .offset = 0x00400000,
310 .irq = { 4 },
311 .id = 0x00041061,
312 }, {
313 .offset = 0x00500000,
314 .irq = { 5 },
315 .id = 0x00041061,
316 }, {
317 .offset = 0x00600000,
318 .irq = { 6 },
319 .id = 0x00041130,
320 }, {
321 .offset = 0x00700000,
322 .irq = { 7, 8 },
323 .id = 0x00041181,
324 }, {
325 .offset = 0x00800000,
326 .irq = { 9 },
327 .id = 0x00041041,
328 }, {
329 .offset = 0x01000000,
330 .irq = { 11 },
331 .id = 0x00041110,
332 .platform_data = &impd1_clcd_data,
333 }
334};
335
Russell Kingd72fbdf2008-11-08 20:08:08 +0000336static struct clk fixed_14745600 = {
337 .rate = 14745600,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};
339
340static int impd1_probe(struct lm_device *dev)
341{
342 struct impd1_module *impd1;
343 int i, ret;
344
345 if (dev->id != module_id)
346 return -EINVAL;
347
348 if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
349 return -EBUSY;
350
Russell Kingd2a02b92006-03-20 19:46:41 +0000351 impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (!impd1) {
353 ret = -ENOMEM;
354 goto release_lm;
355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 impd1->base = ioremap(dev->resource.start, SZ_4K);
358 if (!impd1->base) {
359 ret = -ENOMEM;
360 goto free_impd1;
361 }
362
363 lm_set_drvdata(dev, impd1);
364
Russell King7c284722008-05-23 19:35:52 +0100365 printk("IM-PD1 found at 0x%08lx\n",
366 (unsigned long)dev->resource.start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
369 impd1->vcos[i].owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 impd1->vcos[i].params = &impd1_vco_params,
371 impd1->vcos[i].data = impd1,
372 impd1->vcos[i].setvco = impd1_setvco;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
Russell Kingd1914c72010-01-14 20:09:34 +0000374 impd1->vcos[0].vcoreg = impd1->base + IMPD1_OSC1;
375 impd1->vcos[1].vcoreg = impd1->base + IMPD1_OSC2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Russell Kingd72fbdf2008-11-08 20:08:08 +0000377 impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
378 dev->id);
379 impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
380 dev->id);
381 impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
382 dev->id);
383 for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
384 clkdev_add(impd1->clks[i]);
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
387 struct impd1_device *idev = impd1_devs + i;
388 struct amba_device *d;
389 unsigned long pc_base;
390
391 pc_base = dev->resource.start + idev->offset;
392
Russell Kingd2a02b92006-03-20 19:46:41 +0000393 d = kzalloc(sizeof(struct amba_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (!d)
395 continue;
396
Kay Sievers3f978702008-05-30 17:42:11 +0200397 dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 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) {
Russell Kingfaa64c92008-08-05 10:36:00 +0100409 dev_err(&d->dev, "unable to register device: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 kfree(d);
411 }
412 }
413
414 return 0;
415
416 free_impd1:
417 if (impd1 && impd1->base)
418 iounmap(impd1->base);
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800419 kfree(impd1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 release_lm:
421 release_mem_region(dev->resource.start, SZ_4K);
422 return ret;
423}
424
Russell Kingd1856632005-10-21 10:17:37 +0100425static int impd1_remove_one(struct device *dev, void *data)
426{
427 device_unregister(dev);
428 return 0;
429}
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431static void impd1_remove(struct lm_device *dev)
432{
433 struct impd1_module *impd1 = lm_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 int i;
435
Russell Kingd1856632005-10-21 10:17:37 +0100436 device_for_each_child(&dev->dev, NULL, impd1_remove_one);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Russell Kingd72fbdf2008-11-08 20:08:08 +0000438 for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
439 clkdev_drop(impd1->clks[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 lm_set_drvdata(dev, NULL);
442
443 iounmap(impd1->base);
444 kfree(impd1);
445 release_mem_region(dev->resource.start, SZ_4K);
446}
447
448static struct lm_driver impd1_driver = {
449 .drv = {
450 .name = "impd1",
451 },
452 .probe = impd1_probe,
453 .remove = impd1_remove,
454};
455
456static int __init impd1_init(void)
457{
458 return lm_driver_register(&impd1_driver);
459}
460
461static void __exit impd1_exit(void)
462{
463 lm_driver_unregister(&impd1_driver);
464}
465
466module_init(impd1_init);
467module_exit(impd1_exit);
468
469MODULE_LICENSE("GPL");
470MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
471MODULE_AUTHOR("Deep Blue Solutions Ltd");