1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-integrator/impd1.c
5 * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
7 * This file provides the core support for the IM-PD1 module.
9 * Module / boot parameters.
10 * lmid=n impd1.lmid=n - set the logic module position in stack to 'n'
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/errno.h>
18 #include <linux/amba/bus.h>
19 #include <linux/amba/clcd.h>
20 #include <linux/amba/mmci.h>
22 #include <linux/platform_data/clk-integrator.h>
23 #include <linux/slab.h>
24 #include <linux/irqchip/arm-vic.h>
25 #include <linux/gpio/machine.h>
27 #include <linux/sizes.h>
33 module_param_named(lmid
, module_id
, int, 0444);
34 MODULE_PARM_DESC(lmid
, "logic module stack position");
38 void __iomem
*vic_base
;
41 void impd1_tweak_control(struct device
*dev
, u32 mask
, u32 val
)
43 struct impd1_module
*impd1
= dev_get_drvdata(dev
);
47 cur
= readl(impd1
->base
+ IMPD1_CTRL
) & ~mask
;
48 writel(cur
| val
, impd1
->base
+ IMPD1_CTRL
);
51 EXPORT_SYMBOL(impd1_tweak_control
);
56 static struct mmci_platform_data mmc_data
= {
57 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
63 #define PANEL PROSPECTOR
72 static struct clcd_panel vga
= {
86 .vmode
= FB_VMODE_NONINTERLACED
,
90 .tim2
= TIM2_BCD
| TIM2_IPC
,
91 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
92 .caps
= CLCD_CAP_5551
,
93 .connector
= IMPD1_CTRL_DISP_VGA
,
99 #define PANELTYPE svga
100 static struct clcd_panel svga
= {
114 .vmode
= FB_VMODE_NONINTERLACED
,
119 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
120 .connector
= IMPD1_CTRL_DISP_VGA
,
121 .caps
= CLCD_CAP_5551
,
126 #elif PANEL == PROSPECTOR
127 #define PANELTYPE prospector
128 static struct clcd_panel prospector
= {
130 .name
= "PROSPECTOR",
141 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
142 .vmode
= FB_VMODE_NONINTERLACED
,
147 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
148 .caps
= CLCD_CAP_5551
,
150 .connector
= IMPD1_CTRL_DISP_LCD
,
155 #elif PANEL == LTM10C209
156 #define PANELTYPE ltm10c209
160 static struct clcd_panel ltm10c209
= {
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
,
189 * Disable all display connectors on the interface module.
191 static void impd1fb_clcd_disable(struct clcd_fb
*fb
)
193 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
, 0);
197 * Enable the relevant connector on the interface module.
199 static void impd1fb_clcd_enable(struct clcd_fb
*fb
)
201 impd1_tweak_control(fb
->dev
->dev
.parent
, IMPD1_CTRL_DISP_MASK
,
202 fb
->panel
->connector
| IMPD1_CTRL_DISP_ENABLE
);
205 static int impd1fb_clcd_setup(struct clcd_fb
*fb
)
207 unsigned long framebase
= fb
->dev
->res
.start
+ 0x01000000;
208 unsigned long framesize
= SZ_1M
;
211 fb
->panel
= &PANELTYPE
;
213 if (!request_mem_region(framebase
, framesize
, "clcd framebuffer")) {
214 printk(KERN_ERR
"IM-PD1: unable to reserve framebuffer\n");
218 fb
->fb
.screen_base
= ioremap(framebase
, framesize
);
219 if (!fb
->fb
.screen_base
) {
220 printk(KERN_ERR
"IM-PD1: unable to map framebuffer\n");
225 fb
->fb
.fix
.smem_start
= framebase
;
226 fb
->fb
.fix
.smem_len
= framesize
;
231 release_mem_region(framebase
, framesize
);
235 static int impd1fb_clcd_mmap(struct clcd_fb
*fb
, struct vm_area_struct
*vma
)
237 unsigned long start
, size
;
239 start
= vma
->vm_pgoff
+ (fb
->fb
.fix
.smem_start
>> PAGE_SHIFT
);
240 size
= vma
->vm_end
- vma
->vm_start
;
242 return remap_pfn_range(vma
, vma
->vm_start
, start
, size
,
246 static void impd1fb_clcd_remove(struct clcd_fb
*fb
)
248 iounmap(fb
->fb
.screen_base
);
249 release_mem_region(fb
->fb
.fix
.smem_start
, fb
->fb
.fix
.smem_len
);
252 static struct clcd_board impd1_clcd_data
= {
254 .caps
= CLCD_CAP_5551
| CLCD_CAP_888
,
255 .check
= clcdfb_check
,
256 .decode
= clcdfb_decode
,
257 .disable
= impd1fb_clcd_disable
,
258 .enable
= impd1fb_clcd_enable
,
259 .setup
= impd1fb_clcd_setup
,
260 .mmap
= impd1fb_clcd_mmap
,
261 .remove
= impd1fb_clcd_remove
,
264 struct impd1_device
{
265 unsigned long offset
;
271 static struct impd1_device impd1_devs
[] = {
273 .offset
= 0x00100000,
277 .offset
= 0x00200000,
281 .offset
= 0x00300000,
285 .offset
= 0x00400000,
289 .offset
= 0x00500000,
293 .offset
= 0x00600000,
297 .offset
= 0x00700000,
300 .platform_data
= &mmc_data
,
302 .offset
= 0x00800000,
306 .offset
= 0x01000000,
309 .platform_data
= &impd1_clcd_data
,
314 * Valid IRQs: 0 thru 9 and 11, 10 unused.
316 #define IMPD1_VALID_IRQS 0x00000bffU
319 * As this module is bool, it is OK to have this as __ref() - no
320 * probe calls will be done after the initial system bootup, as devices
321 * are discovered as part of the machine startup.
323 static int __ref
impd1_probe(struct lm_device
*dev
)
325 struct impd1_module
*impd1
;
329 if (dev
->id
!= module_id
)
332 if (!devm_request_mem_region(&dev
->dev
, dev
->resource
.start
,
333 SZ_4K
, "LM registers"))
336 impd1
= devm_kzalloc(&dev
->dev
, sizeof(struct impd1_module
),
341 impd1
->base
= devm_ioremap(&dev
->dev
, dev
->resource
.start
, SZ_4K
);
345 integrator_impd1_clk_init(impd1
->base
, dev
->id
);
347 if (!devm_request_mem_region(&dev
->dev
,
348 dev
->resource
.start
+ 0x03000000,
352 impd1
->vic_base
= devm_ioremap(&dev
->dev
,
353 dev
->resource
.start
+ 0x03000000,
355 if (!impd1
->vic_base
)
358 irq_base
= vic_init_cascaded(impd1
->vic_base
, dev
->irq
,
359 IMPD1_VALID_IRQS
, 0);
361 lm_set_drvdata(dev
, impd1
);
363 dev_info(&dev
->dev
, "IM-PD1 found at 0x%08lx\n",
364 (unsigned long)dev
->resource
.start
);
366 for (i
= 0; i
< ARRAY_SIZE(impd1_devs
); i
++) {
367 struct impd1_device
*idev
= impd1_devs
+ i
;
368 struct amba_device
*d
;
369 unsigned long pc_base
;
371 int irq1
= idev
->irq
[0];
372 int irq2
= idev
->irq
[1];
374 /* Translate IRQs to IM-PD1 local numberspace */
380 pc_base
= dev
->resource
.start
+ idev
->offset
;
381 snprintf(devname
, 32, "lm%x:%5.5lx", dev
->id
, idev
->offset
>> 12);
383 /* Add GPIO descriptor lookup table for the PL061 block */
384 if (idev
->offset
== 0x00400000) {
385 struct gpiod_lookup_table
*lookup
;
389 lookup
= devm_kzalloc(&dev
->dev
,
390 struct_size(lookup
, table
, 3),
392 chipname
= devm_kstrdup(&dev
->dev
, devname
, GFP_KERNEL
);
393 mmciname
= devm_kasprintf(&dev
->dev
, GFP_KERNEL
,
394 "lm%x:00700", dev
->id
);
395 if (!lookup
|| !chipname
|| !mmciname
)
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] = (struct gpiod_lookup
)
414 GPIO_LOOKUP(chipname
, 3, "wp", 0);
415 lookup
->table
[1] = (struct gpiod_lookup
)
416 GPIO_LOOKUP(chipname
, 4, "cd", GPIO_ACTIVE_LOW
);
417 gpiod_add_lookup_table(lookup
);
420 d
= amba_ahb_device_add_res(&dev
->dev
, devname
, pc_base
, SZ_4K
,
422 idev
->platform_data
, idev
->id
,
425 dev_err(&dev
->dev
, "unable to register device: %ld\n", PTR_ERR(d
));
433 static int impd1_remove_one(struct device
*dev
, void *data
)
435 device_unregister(dev
);
439 static void impd1_remove(struct lm_device
*dev
)
441 device_for_each_child(&dev
->dev
, NULL
, impd1_remove_one
);
442 integrator_impd1_clk_exit(dev
->id
);
444 lm_set_drvdata(dev
, NULL
);
447 static struct lm_driver impd1_driver
= {
451 * As we're dropping the probe() function, suppress driver
452 * binding from sysfs.
454 .suppress_bind_attrs
= true,
456 .probe
= impd1_probe
,
457 .remove
= impd1_remove
,
460 static int __init
impd1_init(void)
462 return lm_driver_register(&impd1_driver
);
465 static void __exit
impd1_exit(void)
467 lm_driver_unregister(&impd1_driver
);
470 module_init(impd1_init
);
471 module_exit(impd1_exit
);
473 MODULE_LICENSE("GPL");
474 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
475 MODULE_AUTHOR("Deep Blue Solutions Ltd");