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>
23 #include <linux/amba/mmci.h>
25 #include <linux/platform_data/clk-integrator.h>
26 #include <linux/slab.h>
27 #include <linux/irqchip/arm-vic.h>
28 #include <linux/gpio/machine.h>
30 #include <asm/sizes.h>
36 module_param_named(lmid, module_id, int, 0444);
37 MODULE_PARM_DESC(lmid, "logic module stack position");
41 void __iomem *vic_base;
44 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
46 struct impd1_module *impd1 = dev_get_drvdata(dev);
50 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
51 writel(cur | val, impd1->base + IMPD1_CTRL);
54 EXPORT_SYMBOL(impd1_tweak_control);
59 static struct mmci_platform_data mmc_data = {
60 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
66 #define PANEL PROSPECTOR
75 static struct clcd_panel vga = {
89 .vmode = FB_VMODE_NONINTERLACED,
93 .tim2 = TIM2_BCD | TIM2_IPC,
94 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
95 .caps = CLCD_CAP_5551,
96 .connector = IMPD1_CTRL_DISP_VGA,
102 #define PANELTYPE svga
103 static struct clcd_panel svga = {
117 .vmode = FB_VMODE_NONINTERLACED,
122 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
123 .connector = IMPD1_CTRL_DISP_VGA,
124 .caps = CLCD_CAP_5551,
129 #elif PANEL == PROSPECTOR
130 #define PANELTYPE prospector
131 static struct clcd_panel prospector = {
133 .name = "PROSPECTOR",
144 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
145 .vmode = FB_VMODE_NONINTERLACED,
150 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
151 .caps = CLCD_CAP_5551,
153 .connector = IMPD1_CTRL_DISP_LCD,
158 #elif PANEL == LTM10C209
159 #define PANELTYPE ltm10c209
163 static struct clcd_panel ltm10c209 = {
176 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
177 .vmode = FB_VMODE_NONINTERLACED,
182 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
183 .caps = CLCD_CAP_5551,
185 .connector = IMPD1_CTRL_DISP_LCD,
192 * Disable all display connectors on the interface module.
194 static void impd1fb_clcd_disable(struct clcd_fb *fb)
196 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
200 * Enable the relevant connector on the interface module.
202 static void impd1fb_clcd_enable(struct clcd_fb *fb)
204 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
205 fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
208 static int impd1fb_clcd_setup(struct clcd_fb *fb)
210 unsigned long framebase = fb->dev->res.start + 0x01000000;
211 unsigned long framesize = SZ_1M;
214 fb->panel = &PANELTYPE;
216 if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
217 printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
221 fb->fb.screen_base = ioremap(framebase, framesize);
222 if (!fb->fb.screen_base) {
223 printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
228 fb->fb.fix.smem_start = framebase;
229 fb->fb.fix.smem_len = framesize;
234 release_mem_region(framebase, framesize);
238 static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
240 unsigned long start, size;
242 start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
243 size = vma->vm_end - vma->vm_start;
245 return remap_pfn_range(vma, vma->vm_start, start, size,
249 static void impd1fb_clcd_remove(struct clcd_fb *fb)
251 iounmap(fb->fb.screen_base);
252 release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
255 static struct clcd_board impd1_clcd_data = {
257 .caps = CLCD_CAP_5551 | CLCD_CAP_888,
258 .check = clcdfb_check,
259 .decode = clcdfb_decode,
260 .disable = impd1fb_clcd_disable,
261 .enable = impd1fb_clcd_enable,
262 .setup = impd1fb_clcd_setup,
263 .mmap = impd1fb_clcd_mmap,
264 .remove = impd1fb_clcd_remove,
267 struct impd1_device {
268 unsigned long offset;
274 static struct impd1_device impd1_devs[] = {
276 .offset = 0x00100000,
280 .offset = 0x00200000,
284 .offset = 0x00300000,
288 .offset = 0x00400000,
292 .offset = 0x00500000,
296 .offset = 0x00600000,
300 .offset = 0x00700000,
303 .platform_data = &mmc_data,
305 .offset = 0x00800000,
309 .offset = 0x01000000,
312 .platform_data = &impd1_clcd_data,
317 * Valid IRQs: 0 thru 9 and 11, 10 unused.
319 #define IMPD1_VALID_IRQS 0x00000bffU
322 * As this module is bool, it is OK to have this as __ref() - no
323 * probe calls will be done after the initial system bootup, as devices
324 * are discovered as part of the machine startup.
326 static int __ref impd1_probe(struct lm_device *dev)
328 struct impd1_module *impd1;
332 if (dev->id != module_id)
335 if (!devm_request_mem_region(&dev->dev, dev->resource.start,
336 SZ_4K, "LM registers"))
339 impd1 = devm_kzalloc(&dev->dev, sizeof(struct impd1_module),
344 impd1->base = devm_ioremap(&dev->dev, dev->resource.start, SZ_4K);
348 integrator_impd1_clk_init(impd1->base, dev->id);
350 if (!devm_request_mem_region(&dev->dev,
351 dev->resource.start + 0x03000000,
355 impd1->vic_base = devm_ioremap(&dev->dev,
356 dev->resource.start + 0x03000000,
358 if (!impd1->vic_base)
361 irq_base = vic_init_cascaded(impd1->vic_base, dev->irq,
362 IMPD1_VALID_IRQS, 0);
364 lm_set_drvdata(dev, impd1);
366 dev_info(&dev->dev, "IM-PD1 found at 0x%08lx\n",
367 (unsigned long)dev->resource.start);
369 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
370 struct impd1_device *idev = impd1_devs + i;
371 struct amba_device *d;
372 unsigned long pc_base;
374 int irq1 = idev->irq[0];
375 int irq2 = idev->irq[1];
377 /* Translate IRQs to IM-PD1 local numberspace */
383 pc_base = dev->resource.start + idev->offset;
384 snprintf(devname, 32, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
386 /* Add GPIO descriptor lookup table for the PL061 block */
387 if (idev->offset == 0x00400000) {
388 struct gpiod_lookup_table *lookup;
392 lookup = devm_kzalloc(&dev->dev,
393 sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
395 chipname = devm_kstrdup(&dev->dev, devname, GFP_KERNEL);
396 mmciname = devm_kasprintf(&dev->dev, GFP_KERNEL,
397 "lm%x:00700", dev->id);
398 if (!lookup || !chipname || !mmciname)
401 lookup->dev_id = mmciname;
403 * Offsets on GPIO block 1:
404 * 3 = MMC WP (write protect)
405 * 4 = MMC CD (card detect)
407 * Offsets on GPIO block 2:
413 * 5 = Key lower right
415 /* We need the two MMCI GPIO entries */
416 lookup->table[0].chip_label = chipname;
417 lookup->table[0].chip_hwnum = 3;
418 lookup->table[0].con_id = "wp";
419 lookup->table[1].chip_label = chipname;
420 lookup->table[1].chip_hwnum = 4;
421 lookup->table[1].con_id = "cd";
422 lookup->table[1].flags = GPIO_ACTIVE_LOW;
423 gpiod_add_lookup_table(lookup);
426 d = amba_ahb_device_add_res(&dev->dev, devname, pc_base, SZ_4K,
428 idev->platform_data, idev->id,
431 dev_err(&dev->dev, "unable to register device: %ld\n", PTR_ERR(d));
439 static int impd1_remove_one(struct device *dev, void *data)
441 device_unregister(dev);
445 static void impd1_remove(struct lm_device *dev)
447 device_for_each_child(&dev->dev, NULL, impd1_remove_one);
448 integrator_impd1_clk_exit(dev->id);
450 lm_set_drvdata(dev, NULL);
453 static struct lm_driver impd1_driver = {
457 * As we're dropping the probe() function, suppress driver
458 * binding from sysfs.
460 .suppress_bind_attrs = true,
462 .probe = impd1_probe,
463 .remove = impd1_remove,
466 static int __init impd1_init(void)
468 return lm_driver_register(&impd1_driver);
471 static void __exit impd1_exit(void)
473 lm_driver_unregister(&impd1_driver);
476 module_init(impd1_init);
477 module_exit(impd1_exit);
479 MODULE_LICENSE("GPL");
480 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
481 MODULE_AUTHOR("Deep Blue Solutions Ltd");