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 <linux/amba/bus.h>
22 #include <linux/amba/clcd.h>
24 #include <linux/slab.h>
26 #include <asm/clkdev.h>
27 #include <mach/clkdev.h>
28 #include <asm/hardware/icst525.h>
30 #include <mach/impd1.h>
31 #include <asm/sizes.h>
35 module_param_named(lmid
, module_id
, int, 0444);
36 MODULE_PARM_DESC(lmid
, "logic module stack position");
41 struct clk_lookup
*clks
[3];
44 static const struct icst525_params impd1_vco_params
= {
45 .ref
= 24000, /* 24 MHz */
46 .vco_max
= 200000, /* 200 MHz */
53 static void impd1_setvco(struct clk
*clk
, struct icst525_vco vco
)
55 struct impd1_module
*impd1
= clk
->data
;
56 int vconr
= clk
- impd1
->vcos
;
59 val
= vco
.v
| (vco
.r
<< 9) | (vco
.s
<< 16);
61 writel(0xa05f, impd1
->base
+ IMPD1_LOCK
);
64 writel(val
, impd1
->base
+ IMPD1_OSC1
);
67 writel(val
, impd1
->base
+ IMPD1_OSC2
);
70 writel(0, impd1
->base
+ IMPD1_LOCK
);
74 vco
.r
= (val
>> 9) & 0x7f;
75 vco
.s
= (val
>> 16) & 7;
77 pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
78 vconr
, icst525_khz(&impd1_vco_params
, vco
));
82 void impd1_tweak_control(struct device
*dev
, u32 mask
, u32 val
)
84 struct impd1_module
*impd1
= dev_get_drvdata(dev
);
88 cur
= readl(impd1
->base
+ IMPD1_CTRL
) & ~mask
;
89 writel(cur
| val
, impd1
->base
+ IMPD1_CTRL
);
92 EXPORT_SYMBOL(impd1_tweak_control
);
97 #define PANEL PROSPECTOR
105 #define PANELTYPE vga
106 static struct clcd_panel vga
= {
120 .vmode
= FB_VMODE_NONINTERLACED
,
124 .tim2
= TIM2_BCD
| TIM2_IPC
,
125 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
126 .connector
= IMPD1_CTRL_DISP_VGA
,
132 #define PANELTYPE svga
133 static struct clcd_panel svga
= {
147 .vmode
= FB_VMODE_NONINTERLACED
,
152 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
153 .connector
= IMPD1_CTRL_DISP_VGA
,
158 #elif PANEL == PROSPECTOR
159 #define PANELTYPE prospector
160 static struct clcd_panel prospector
= {
162 .name
= "PROSPECTOR",
173 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
174 .vmode
= FB_VMODE_NONINTERLACED
,
179 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
181 .connector
= IMPD1_CTRL_DISP_LCD
,
186 #elif PANEL == LTM10C209
187 #define PANELTYPE ltm10c209
191 static struct clcd_panel ltm10c209
= {
204 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
205 .vmode
= FB_VMODE_NONINTERLACED
,
210 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
212 .connector
= IMPD1_CTRL_DISP_LCD
,
219 * Disable all display connectors on the interface module.
221 static void impd1fb_clcd_disable(struct clcd_fb
*fb
)
223 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
, 0);
227 * Enable the relevant connector on the interface module.
229 static void impd1fb_clcd_enable(struct clcd_fb
*fb
)
231 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
,
232 fb
->panel
->connector
| IMPD1_CTRL_DISP_ENABLE
);
235 static int impd1fb_clcd_setup(struct clcd_fb
*fb
)
237 unsigned long framebase
= fb
->dev
->res
.start
+ 0x01000000;
238 unsigned long framesize
= SZ_1M
;
241 fb
->panel
= &PANELTYPE
;
243 if (!request_mem_region(framebase
, framesize
, "clcd framebuffer")) {
244 printk(KERN_ERR
"IM-PD1: unable to reserve framebuffer\n");
248 fb
->fb
.screen_base
= ioremap(framebase
, framesize
);
249 if (!fb
->fb
.screen_base
) {
250 printk(KERN_ERR
"IM-PD1: unable to map framebuffer\n");
255 fb
->fb
.fix
.smem_start
= framebase
;
256 fb
->fb
.fix
.smem_len
= framesize
;
261 release_mem_region(framebase
, framesize
);
265 static int impd1fb_clcd_mmap(struct clcd_fb
*fb
, struct vm_area_struct
*vma
)
267 unsigned long start
, size
;
269 start
= vma
->vm_pgoff
+ (fb
->fb
.fix
.smem_start
>> PAGE_SHIFT
);
270 size
= vma
->vm_end
- vma
->vm_start
;
272 return remap_pfn_range(vma
, vma
->vm_start
, start
, size
,
276 static void impd1fb_clcd_remove(struct clcd_fb
*fb
)
278 iounmap(fb
->fb
.screen_base
);
279 release_mem_region(fb
->fb
.fix
.smem_start
, fb
->fb
.fix
.smem_len
);
282 static struct clcd_board impd1_clcd_data
= {
284 .check
= clcdfb_check
,
285 .decode
= clcdfb_decode
,
286 .disable
= impd1fb_clcd_disable
,
287 .enable
= impd1fb_clcd_enable
,
288 .setup
= impd1fb_clcd_setup
,
289 .mmap
= impd1fb_clcd_mmap
,
290 .remove
= impd1fb_clcd_remove
,
293 struct impd1_device
{
294 unsigned long offset
;
300 static struct impd1_device impd1_devs
[] = {
302 .offset
= 0x03000000,
305 .offset
= 0x00100000,
309 .offset
= 0x00200000,
313 .offset
= 0x00300000,
317 .offset
= 0x00400000,
321 .offset
= 0x00500000,
325 .offset
= 0x00600000,
329 .offset
= 0x00700000,
333 .offset
= 0x00800000,
337 .offset
= 0x01000000,
340 .platform_data
= &impd1_clcd_data
,
344 static struct clk fixed_14745600
= {
348 static int impd1_probe(struct lm_device
*dev
)
350 struct impd1_module
*impd1
;
353 if (dev
->id
!= module_id
)
356 if (!request_mem_region(dev
->resource
.start
, SZ_4K
, "LM registers"))
359 impd1
= kzalloc(sizeof(struct impd1_module
), GFP_KERNEL
);
365 impd1
->base
= ioremap(dev
->resource
.start
, SZ_4K
);
371 lm_set_drvdata(dev
, impd1
);
373 printk("IM-PD1 found at 0x%08lx\n",
374 (unsigned long)dev
->resource
.start
);
376 for (i
= 0; i
< ARRAY_SIZE(impd1
->vcos
); i
++) {
377 impd1
->vcos
[i
].owner
= THIS_MODULE
,
378 impd1
->vcos
[i
].params
= &impd1_vco_params
,
379 impd1
->vcos
[i
].data
= impd1
,
380 impd1
->vcos
[i
].setvco
= impd1_setvco
;
383 impd1
->clks
[0] = clkdev_alloc(&impd1
->vcos
[0], NULL
, "lm%x:01000",
385 impd1
->clks
[1] = clkdev_alloc(&fixed_14745600
, NULL
, "lm%x:00100",
387 impd1
->clks
[2] = clkdev_alloc(&fixed_14745600
, NULL
, "lm%x:00200",
389 for (i
= 0; i
< ARRAY_SIZE(impd1
->clks
); i
++)
390 clkdev_add(impd1
->clks
[i
]);
392 for (i
= 0; i
< ARRAY_SIZE(impd1_devs
); i
++) {
393 struct impd1_device
*idev
= impd1_devs
+ i
;
394 struct amba_device
*d
;
395 unsigned long pc_base
;
397 pc_base
= dev
->resource
.start
+ idev
->offset
;
399 d
= kzalloc(sizeof(struct amba_device
), GFP_KERNEL
);
403 dev_set_name(&d
->dev
, "lm%x:%5.5lx", dev
->id
, idev
->offset
>> 12);
404 d
->dev
.parent
= &dev
->dev
;
405 d
->res
.start
= dev
->resource
.start
+ idev
->offset
;
406 d
->res
.end
= d
->res
.start
+ SZ_4K
- 1;
407 d
->res
.flags
= IORESOURCE_MEM
;
408 d
->irq
[0] = dev
->irq
;
409 d
->irq
[1] = dev
->irq
;
410 d
->periphid
= idev
->id
;
411 d
->dev
.platform_data
= idev
->platform_data
;
413 ret
= amba_device_register(d
, &dev
->resource
);
415 dev_err(&d
->dev
, "unable to register device: %d\n", ret
);
423 if (impd1
&& impd1
->base
)
424 iounmap(impd1
->base
);
427 release_mem_region(dev
->resource
.start
, SZ_4K
);
431 static int impd1_remove_one(struct device
*dev
, void *data
)
433 device_unregister(dev
);
437 static void impd1_remove(struct lm_device
*dev
)
439 struct impd1_module
*impd1
= lm_get_drvdata(dev
);
442 device_for_each_child(&dev
->dev
, NULL
, impd1_remove_one
);
444 for (i
= 0; i
< ARRAY_SIZE(impd1
->clks
); i
++)
445 clkdev_drop(impd1
->clks
[i
]);
447 lm_set_drvdata(dev
, NULL
);
449 iounmap(impd1
->base
);
451 release_mem_region(dev
->resource
.start
, SZ_4K
);
454 static struct lm_driver impd1_driver
= {
458 .probe
= impd1_probe
,
459 .remove
= impd1_remove
,
462 static int __init
impd1_init(void)
464 return lm_driver_register(&impd1_driver
);
467 static void __exit
impd1_exit(void)
469 lm_driver_unregister(&impd1_driver
);
472 module_init(impd1_init
);
473 module_exit(impd1_exit
);
475 MODULE_LICENSE("GPL");
476 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
477 MODULE_AUTHOR("Deep Blue Solutions Ltd");