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>
24 #include <linux/amba/pl061.h>
26 #include <linux/platform_data/clk-integrator.h>
27 #include <linux/slab.h>
28 #include <linux/irqchip/arm-vic.h>
29 #include <linux/gpio/machine.h>
31 #include <asm/sizes.h>
37 module_param_named(lmid, module_id, int, 0444);
38 MODULE_PARM_DESC(lmid, "logic module stack position");
42 void __iomem *vic_base;
45 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
47 struct impd1_module *impd1 = dev_get_drvdata(dev);
51 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
52 writel(cur | val, impd1->base + IMPD1_CTRL);
55 EXPORT_SYMBOL(impd1_tweak_control);
60 static struct mmci_platform_data mmc_data = {
61 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
67 #define PANEL PROSPECTOR
76 static struct clcd_panel vga = {
90 .vmode = FB_VMODE_NONINTERLACED,
94 .tim2 = TIM2_BCD | TIM2_IPC,
95 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
96 .caps = CLCD_CAP_5551,
97 .connector = IMPD1_CTRL_DISP_VGA,
103 #define PANELTYPE svga
104 static struct clcd_panel svga = {
118 .vmode = FB_VMODE_NONINTERLACED,
123 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
124 .connector = IMPD1_CTRL_DISP_VGA,
125 .caps = CLCD_CAP_5551,
130 #elif PANEL == PROSPECTOR
131 #define PANELTYPE prospector
132 static struct clcd_panel prospector = {
134 .name = "PROSPECTOR",
145 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
146 .vmode = FB_VMODE_NONINTERLACED,
151 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
152 .caps = CLCD_CAP_5551,
154 .connector = IMPD1_CTRL_DISP_LCD,
159 #elif PANEL == LTM10C209
160 #define PANELTYPE ltm10c209
164 static struct clcd_panel ltm10c209 = {
177 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
178 .vmode = FB_VMODE_NONINTERLACED,
183 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
184 .caps = CLCD_CAP_5551,
186 .connector = IMPD1_CTRL_DISP_LCD,
193 * Disable all display connectors on the interface module.
195 static void impd1fb_clcd_disable(struct clcd_fb *fb)
197 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
201 * Enable the relevant connector on the interface module.
203 static void impd1fb_clcd_enable(struct clcd_fb *fb)
205 impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
206 fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
209 static int impd1fb_clcd_setup(struct clcd_fb *fb)
211 unsigned long framebase = fb->dev->res.start + 0x01000000;
212 unsigned long framesize = SZ_1M;
215 fb->panel = &PANELTYPE;
217 if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
218 printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
222 fb->fb.screen_base = ioremap(framebase, framesize);
223 if (!fb->fb.screen_base) {
224 printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
229 fb->fb.fix.smem_start = framebase;
230 fb->fb.fix.smem_len = framesize;
235 release_mem_region(framebase, framesize);
239 static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
241 unsigned long start, size;
243 start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
244 size = vma->vm_end - vma->vm_start;
246 return remap_pfn_range(vma, vma->vm_start, start, size,
250 static void impd1fb_clcd_remove(struct clcd_fb *fb)
252 iounmap(fb->fb.screen_base);
253 release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
256 static struct clcd_board impd1_clcd_data = {
258 .caps = CLCD_CAP_5551 | CLCD_CAP_888,
259 .check = clcdfb_check,
260 .decode = clcdfb_decode,
261 .disable = impd1fb_clcd_disable,
262 .enable = impd1fb_clcd_enable,
263 .setup = impd1fb_clcd_setup,
264 .mmap = impd1fb_clcd_mmap,
265 .remove = impd1fb_clcd_remove,
268 struct impd1_device {
269 unsigned long offset;
275 static struct impd1_device impd1_devs[] = {
277 .offset = 0x00100000,
281 .offset = 0x00200000,
285 .offset = 0x00300000,
289 .offset = 0x00400000,
293 .offset = 0x00500000,
297 .offset = 0x00600000,
301 .offset = 0x00700000,
304 .platform_data = &mmc_data,
306 .offset = 0x00800000,
310 .offset = 0x01000000,
313 .platform_data = &impd1_clcd_data,
318 * Valid IRQs: 0 thru 9 and 11, 10 unused.
320 #define IMPD1_VALID_IRQS 0x00000bffU
323 * As this module is bool, it is OK to have this as __init_refok() - no
324 * probe calls will be done after the initial system bootup, as devices
325 * are discovered as part of the machine startup.
327 static int __init_refok impd1_probe(struct lm_device *dev)
329 struct impd1_module *impd1;
333 if (dev->id != module_id)
336 if (!devm_request_mem_region(&dev->dev, dev->resource.start,
337 SZ_4K, "LM registers"))
340 impd1 = devm_kzalloc(&dev->dev, sizeof(struct impd1_module),
345 impd1->base = devm_ioremap(&dev->dev, dev->resource.start, SZ_4K);
349 integrator_impd1_clk_init(impd1->base, dev->id);
351 if (!devm_request_mem_region(&dev->dev,
352 dev->resource.start + 0x03000000,
356 impd1->vic_base = devm_ioremap(&dev->dev,
357 dev->resource.start + 0x03000000,
359 if (!impd1->vic_base)
362 irq_base = vic_init_cascaded(impd1->vic_base, dev->irq,
363 IMPD1_VALID_IRQS, 0);
365 lm_set_drvdata(dev, impd1);
367 dev_info(&dev->dev, "IM-PD1 found at 0x%08lx\n",
368 (unsigned long)dev->resource.start);
370 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
371 struct impd1_device *idev = impd1_devs + i;
372 struct amba_device *d;
373 unsigned long pc_base;
375 int irq1 = idev->irq[0];
376 int irq2 = idev->irq[1];
378 /* Translate IRQs to IM-PD1 local numberspace */
384 pc_base = dev->resource.start + idev->offset;
385 snprintf(devname, 32, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
387 /* Add GPIO descriptor lookup table for the PL061 block */
388 if (idev->offset == 0x00400000) {
389 struct gpiod_lookup_table *lookup;
393 lookup = devm_kzalloc(&dev->dev,
394 sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
396 chipname = devm_kstrdup(&dev->dev, devname, GFP_KERNEL);
397 mmciname = kasprintf(GFP_KERNEL, "lm%x:00700", dev->id);
398 lookup->dev_id = mmciname;
400 * Offsets on GPIO block 1:
401 * 3 = MMC WP (write protect)
402 * 4 = MMC CD (card detect)
404 * Offsets on GPIO block 2:
410 * 5 = Key lower right
412 /* We need the two MMCI GPIO entries */
413 lookup->table[0].chip_label = chipname;
414 lookup->table[0].chip_hwnum = 3;
415 lookup->table[0].con_id = "wp";
416 lookup->table[1].chip_label = chipname;
417 lookup->table[1].chip_hwnum = 4;
418 lookup->table[1].con_id = "cd";
419 lookup->table[1].flags = GPIO_ACTIVE_LOW;
420 gpiod_add_lookup_table(lookup);
423 d = amba_ahb_device_add_res(&dev->dev, devname, pc_base, SZ_4K,
425 idev->platform_data, idev->id,
428 dev_err(&dev->dev, "unable to register device: %ld\n", PTR_ERR(d));
436 static int impd1_remove_one(struct device *dev, void *data)
438 device_unregister(dev);
442 static void impd1_remove(struct lm_device *dev)
444 device_for_each_child(&dev->dev, NULL, impd1_remove_one);
445 integrator_impd1_clk_exit(dev->id);
447 lm_set_drvdata(dev, NULL);
450 static struct lm_driver impd1_driver = {
454 * As we're dropping the probe() function, suppress driver
455 * binding from sysfs.
457 .suppress_bind_attrs = true,
459 .probe = impd1_probe,
460 .remove = impd1_remove,
463 static int __init impd1_init(void)
465 return lm_driver_register(&impd1_driver);
468 static void __exit impd1_exit(void)
470 lm_driver_unregister(&impd1_driver);
473 module_init(impd1_init);
474 module_exit(impd1_exit);
476 MODULE_LICENSE("GPL");
477 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
478 MODULE_AUTHOR("Deep Blue Solutions Ltd");