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>
25 #include <linux/clkdev.h>
27 #include <asm/hardware/icst.h>
29 #include <mach/impd1.h>
30 #include <asm/sizes.h>
34 module_param_named(lmid
, module_id
, int, 0444);
35 MODULE_PARM_DESC(lmid
, "logic module stack position");
40 struct clk_lookup
*clks
[3];
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
,
51 .s2div
= icst525_s2div
,
52 .idx2s
= icst525_idx2s
,
55 static void impd1_setvco(struct clk
*clk
, struct icst_vco vco
)
57 struct impd1_module
*impd1
= clk
->data
;
58 u32 val
= vco
.v
| (vco
.r
<< 9) | (vco
.s
<< 16);
60 writel(0xa05f, impd1
->base
+ IMPD1_LOCK
);
61 writel(val
, clk
->vcoreg
);
62 writel(0, impd1
->base
+ IMPD1_LOCK
);
66 vco
.r
= (val
>> 9) & 0x7f;
67 vco
.s
= (val
>> 16) & 7;
69 pr_debug("IM-PD1: VCO%d clock is %ld Hz\n",
70 vconr
, icst525_hz(&impd1_vco_params
, vco
));
74 static const struct clk_ops impd1_clk_ops
= {
75 .round
= icst_clk_round
,
77 .setvco
= impd1_setvco
,
80 void impd1_tweak_control(struct device
*dev
, u32 mask
, u32 val
)
82 struct impd1_module
*impd1
= dev_get_drvdata(dev
);
86 cur
= readl(impd1
->base
+ IMPD1_CTRL
) & ~mask
;
87 writel(cur
| val
, impd1
->base
+ IMPD1_CTRL
);
90 EXPORT_SYMBOL(impd1_tweak_control
);
95 #define PANEL PROSPECTOR
103 #define PANELTYPE vga
104 static struct clcd_panel vga
= {
118 .vmode
= FB_VMODE_NONINTERLACED
,
122 .tim2
= TIM2_BCD
| TIM2_IPC
,
123 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
124 .caps
= CLCD_CAP_5551
,
125 .connector
= IMPD1_CTRL_DISP_VGA
,
131 #define PANELTYPE svga
132 static struct clcd_panel svga
= {
146 .vmode
= FB_VMODE_NONINTERLACED
,
151 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
152 .connector
= IMPD1_CTRL_DISP_VGA
,
153 .caps
= CLCD_CAP_5551
,
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),
180 .caps
= CLCD_CAP_5551
,
182 .connector
= IMPD1_CTRL_DISP_LCD
,
187 #elif PANEL == LTM10C209
188 #define PANELTYPE ltm10c209
192 static struct clcd_panel ltm10c209
= {
205 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
206 .vmode
= FB_VMODE_NONINTERLACED
,
211 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
212 .caps
= CLCD_CAP_5551
,
214 .connector
= IMPD1_CTRL_DISP_LCD
,
221 * Disable all display connectors on the interface module.
223 static void impd1fb_clcd_disable(struct clcd_fb
*fb
)
225 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
, 0);
229 * Enable the relevant connector on the interface module.
231 static void impd1fb_clcd_enable(struct clcd_fb
*fb
)
233 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
,
234 fb
->panel
->connector
| IMPD1_CTRL_DISP_ENABLE
);
237 static int impd1fb_clcd_setup(struct clcd_fb
*fb
)
239 unsigned long framebase
= fb
->dev
->res
.start
+ 0x01000000;
240 unsigned long framesize
= SZ_1M
;
243 fb
->panel
= &PANELTYPE
;
245 if (!request_mem_region(framebase
, framesize
, "clcd framebuffer")) {
246 printk(KERN_ERR
"IM-PD1: unable to reserve framebuffer\n");
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");
257 fb
->fb
.fix
.smem_start
= framebase
;
258 fb
->fb
.fix
.smem_len
= framesize
;
263 release_mem_region(framebase
, framesize
);
267 static int impd1fb_clcd_mmap(struct clcd_fb
*fb
, struct vm_area_struct
*vma
)
269 unsigned long start
, size
;
271 start
= vma
->vm_pgoff
+ (fb
->fb
.fix
.smem_start
>> PAGE_SHIFT
);
272 size
= vma
->vm_end
- vma
->vm_start
;
274 return remap_pfn_range(vma
, vma
->vm_start
, start
, size
,
278 static void impd1fb_clcd_remove(struct clcd_fb
*fb
)
280 iounmap(fb
->fb
.screen_base
);
281 release_mem_region(fb
->fb
.fix
.smem_start
, fb
->fb
.fix
.smem_len
);
284 static struct clcd_board impd1_clcd_data
= {
286 .caps
= CLCD_CAP_5551
| CLCD_CAP_888
,
287 .check
= clcdfb_check
,
288 .decode
= clcdfb_decode
,
289 .disable
= impd1fb_clcd_disable
,
290 .enable
= impd1fb_clcd_enable
,
291 .setup
= impd1fb_clcd_setup
,
292 .mmap
= impd1fb_clcd_mmap
,
293 .remove
= impd1fb_clcd_remove
,
296 struct impd1_device
{
297 unsigned long offset
;
303 static struct impd1_device impd1_devs
[] = {
305 .offset
= 0x03000000,
308 .offset
= 0x00100000,
312 .offset
= 0x00200000,
316 .offset
= 0x00300000,
320 .offset
= 0x00400000,
324 .offset
= 0x00500000,
328 .offset
= 0x00600000,
332 .offset
= 0x00700000,
336 .offset
= 0x00800000,
340 .offset
= 0x01000000,
343 .platform_data
= &impd1_clcd_data
,
347 static struct clk fixed_14745600
= {
351 static int impd1_probe(struct lm_device
*dev
)
353 struct impd1_module
*impd1
;
356 if (dev
->id
!= module_id
)
359 if (!request_mem_region(dev
->resource
.start
, SZ_4K
, "LM registers"))
362 impd1
= kzalloc(sizeof(struct impd1_module
), GFP_KERNEL
);
368 impd1
->base
= ioremap(dev
->resource
.start
, SZ_4K
);
374 lm_set_drvdata(dev
, impd1
);
376 printk("IM-PD1 found at 0x%08lx\n",
377 (unsigned long)dev
->resource
.start
);
379 for (i
= 0; i
< ARRAY_SIZE(impd1
->vcos
); i
++) {
380 impd1
->vcos
[i
].ops
= &impd1_clk_ops
,
381 impd1
->vcos
[i
].owner
= THIS_MODULE
,
382 impd1
->vcos
[i
].params
= &impd1_vco_params
,
383 impd1
->vcos
[i
].data
= impd1
;
385 impd1
->vcos
[0].vcoreg
= impd1
->base
+ IMPD1_OSC1
;
386 impd1
->vcos
[1].vcoreg
= impd1
->base
+ IMPD1_OSC2
;
388 impd1
->clks
[0] = clkdev_alloc(&impd1
->vcos
[0], NULL
, "lm%x:01000",
390 impd1
->clks
[1] = clkdev_alloc(&fixed_14745600
, NULL
, "lm%x:00100",
392 impd1
->clks
[2] = clkdev_alloc(&fixed_14745600
, NULL
, "lm%x:00200",
394 for (i
= 0; i
< ARRAY_SIZE(impd1
->clks
); i
++)
395 clkdev_add(impd1
->clks
[i
]);
397 for (i
= 0; i
< ARRAY_SIZE(impd1_devs
); i
++) {
398 struct impd1_device
*idev
= impd1_devs
+ i
;
399 struct amba_device
*d
;
400 unsigned long pc_base
;
403 pc_base
= dev
->resource
.start
+ idev
->offset
;
404 snprintf(devname
, 32, "lm%x:%5.5lx", dev
->id
, idev
->offset
>> 12);
405 d
= amba_ahb_device_add(&dev
->dev
, devname
, pc_base
, SZ_4K
,
407 idev
->platform_data
, idev
->id
);
409 dev_err(&dev
->dev
, "unable to register device: %ld\n", PTR_ERR(d
));
417 if (impd1
&& impd1
->base
)
418 iounmap(impd1
->base
);
421 release_mem_region(dev
->resource
.start
, SZ_4K
);
425 static int impd1_remove_one(struct device
*dev
, void *data
)
427 device_unregister(dev
);
431 static void impd1_remove(struct lm_device
*dev
)
433 struct impd1_module
*impd1
= lm_get_drvdata(dev
);
436 device_for_each_child(&dev
->dev
, NULL
, impd1_remove_one
);
438 for (i
= 0; i
< ARRAY_SIZE(impd1
->clks
); i
++)
439 clkdev_drop(impd1
->clks
[i
]);
441 lm_set_drvdata(dev
, NULL
);
443 iounmap(impd1
->base
);
445 release_mem_region(dev
->resource
.start
, SZ_4K
);
448 static struct lm_driver impd1_driver
= {
452 .probe
= impd1_probe
,
453 .remove
= impd1_remove
,
456 static int __init
impd1_init(void)
458 return lm_driver_register(&impd1_driver
);
461 static void __exit
impd1_exit(void)
463 lm_driver_unregister(&impd1_driver
);
466 module_init(impd1_init
);
467 module_exit(impd1_exit
);
469 MODULE_LICENSE("GPL");
470 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
471 MODULE_AUTHOR("Deep Blue Solutions Ltd");