2 * linux/arch/arm/mach-integrator/integrator_cp.c
4 * Copyright (C) 2003 Deep Blue Solutions Ltd
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/list.h>
14 #include <linux/platform_device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/slab.h>
17 #include <linux/string.h>
18 #include <linux/sysdev.h>
19 #include <linux/amba/bus.h>
20 #include <linux/amba/kmi.h>
21 #include <linux/amba/clcd.h>
24 #include <asm/clkdev.h>
25 #include <mach/clkdev.h>
26 #include <mach/hardware.h>
28 #include <asm/setup.h>
29 #include <asm/mach-types.h>
30 #include <asm/hardware/icst525.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/flash.h>
37 #include <asm/mach/irq.h>
38 #include <asm/mach/mmc.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/time.h>
44 #define INTCP_PA_MMC_BASE 0x1c000000
45 #define INTCP_PA_AACI_BASE 0x1d000000
47 #define INTCP_PA_FLASH_BASE 0x24000000
48 #define INTCP_FLASH_SIZE SZ_32M
50 #define INTCP_PA_CLCD_BASE 0xc0000000
52 #define INTCP_VA_CIC_BASE 0xf1000040
53 #define INTCP_VA_PIC_BASE 0xf1400000
54 #define INTCP_VA_SIC_BASE 0xfca00000
56 #define INTCP_PA_ETH_BASE 0xc8000000
57 #define INTCP_ETH_SIZE 0x10
59 #define INTCP_VA_CTRL_BASE 0xfcb00000
60 #define INTCP_FLASHPROG 0x04
61 #define CINTEGRATOR_FLASHPROG_FLVPPEN (1 << 0)
62 #define CINTEGRATOR_FLASHPROG_FLWREN (1 << 1)
66 * f1000000 10000000 Core module registers
67 * f1100000 11000000 System controller registers
68 * f1200000 12000000 EBI registers
69 * f1300000 13000000 Counter/Timer
70 * f1400000 14000000 Interrupt controller
71 * f1600000 16000000 UART 0
72 * f1700000 17000000 UART 1
73 * f1a00000 1a000000 Debug LEDs
74 * f1b00000 1b000000 GPIO
77 static struct map_desc intcp_io_desc[] __initdata = {
79 .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE),
80 .pfn = __phys_to_pfn(INTEGRATOR_HDR_BASE),
84 .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE),
85 .pfn = __phys_to_pfn(INTEGRATOR_SC_BASE),
89 .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE),
90 .pfn = __phys_to_pfn(INTEGRATOR_EBI_BASE),
94 .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE),
95 .pfn = __phys_to_pfn(INTEGRATOR_CT_BASE),
99 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
100 .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
104 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
105 .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
109 .virtual = IO_ADDRESS(INTEGRATOR_UART1_BASE),
110 .pfn = __phys_to_pfn(INTEGRATOR_UART1_BASE),
114 .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
115 .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
119 .virtual = IO_ADDRESS(INTEGRATOR_GPIO_BASE),
120 .pfn = __phys_to_pfn(INTEGRATOR_GPIO_BASE),
124 .virtual = 0xfca00000,
125 .pfn = __phys_to_pfn(0xca000000),
129 .virtual = 0xfcb00000,
130 .pfn = __phys_to_pfn(0xcb000000),
136 static void __init intcp_map_io(void)
138 iotable_init(intcp_io_desc, ARRAY_SIZE(intcp_io_desc));
141 #define cic_writel __raw_writel
142 #define cic_readl __raw_readl
143 #define pic_writel __raw_writel
144 #define pic_readl __raw_readl
145 #define sic_writel __raw_writel
146 #define sic_readl __raw_readl
148 static void cic_mask_irq(unsigned int irq)
150 irq -= IRQ_CIC_START;
151 cic_writel(1 << irq, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
154 static void cic_unmask_irq(unsigned int irq)
156 irq -= IRQ_CIC_START;
157 cic_writel(1 << irq, INTCP_VA_CIC_BASE + IRQ_ENABLE_SET);
160 static struct irq_chip cic_chip = {
163 .mask = cic_mask_irq,
164 .unmask = cic_unmask_irq,
167 static void pic_mask_irq(unsigned int irq)
169 irq -= IRQ_PIC_START;
170 pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
173 static void pic_unmask_irq(unsigned int irq)
175 irq -= IRQ_PIC_START;
176 pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_SET);
179 static struct irq_chip pic_chip = {
182 .mask = pic_mask_irq,
183 .unmask = pic_unmask_irq,
186 static void sic_mask_irq(unsigned int irq)
188 irq -= IRQ_SIC_START;
189 sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
192 static void sic_unmask_irq(unsigned int irq)
194 irq -= IRQ_SIC_START;
195 sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_SET);
198 static struct irq_chip sic_chip = {
201 .mask = sic_mask_irq,
202 .unmask = sic_unmask_irq,
206 sic_handle_irq(unsigned int irq, struct irq_desc *desc)
208 unsigned long status = sic_readl(INTCP_VA_SIC_BASE + IRQ_STATUS);
211 do_bad_IRQ(irq, desc);
216 irq = ffs(status) - 1;
217 status &= ~(1 << irq);
219 irq += IRQ_SIC_START;
221 generic_handle_irq(irq);
225 static void __init intcp_init_irq(void)
230 * Disable all interrupt sources
232 pic_writel(0xffffffff, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
233 pic_writel(0xffffffff, INTCP_VA_PIC_BASE + FIQ_ENABLE_CLEAR);
235 for (i = IRQ_PIC_START; i <= IRQ_PIC_END; i++) {
240 set_irq_chip(i, &pic_chip);
241 set_irq_handler(i, handle_level_irq);
242 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
245 cic_writel(0xffffffff, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
246 cic_writel(0xffffffff, INTCP_VA_CIC_BASE + FIQ_ENABLE_CLEAR);
248 for (i = IRQ_CIC_START; i <= IRQ_CIC_END; i++) {
249 set_irq_chip(i, &cic_chip);
250 set_irq_handler(i, handle_level_irq);
251 set_irq_flags(i, IRQF_VALID);
254 sic_writel(0x00000fff, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
255 sic_writel(0x00000fff, INTCP_VA_SIC_BASE + FIQ_ENABLE_CLEAR);
257 for (i = IRQ_SIC_START; i <= IRQ_SIC_END; i++) {
258 set_irq_chip(i, &sic_chip);
259 set_irq_handler(i, handle_level_irq);
260 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
263 set_irq_chained_handler(IRQ_CP_CPPLDINT, sic_handle_irq);
269 #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
270 #define CM_AUXOSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+0x1c)
272 static const struct icst525_params cp_auxvco_params = {
281 static void cp_auxvco_set(struct clk *clk, struct icst525_vco vco)
285 val = readl(CM_AUXOSC) & ~0x7ffff;
286 val |= vco.v | (vco.r << 9) | (vco.s << 16);
288 writel(0xa05f, CM_LOCK);
289 writel(val, CM_AUXOSC);
293 static struct clk cp_auxclk = {
294 .params = &cp_auxvco_params,
295 .setvco = cp_auxvco_set,
298 static struct clk_lookup cp_lookups[] = {
308 static int intcp_flash_init(void)
312 val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
313 val |= CINTEGRATOR_FLASHPROG_FLWREN;
314 writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
319 static void intcp_flash_exit(void)
323 val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
324 val &= ~(CINTEGRATOR_FLASHPROG_FLVPPEN|CINTEGRATOR_FLASHPROG_FLWREN);
325 writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
328 static void intcp_flash_set_vpp(int on)
332 val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
334 val |= CINTEGRATOR_FLASHPROG_FLVPPEN;
336 val &= ~CINTEGRATOR_FLASHPROG_FLVPPEN;
337 writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
340 static struct flash_platform_data intcp_flash_data = {
341 .map_name = "cfi_probe",
343 .init = intcp_flash_init,
344 .exit = intcp_flash_exit,
345 .set_vpp = intcp_flash_set_vpp,
348 static struct resource intcp_flash_resource = {
349 .start = INTCP_PA_FLASH_BASE,
350 .end = INTCP_PA_FLASH_BASE + INTCP_FLASH_SIZE - 1,
351 .flags = IORESOURCE_MEM,
354 static struct platform_device intcp_flash_device = {
358 .platform_data = &intcp_flash_data,
361 .resource = &intcp_flash_resource,
364 static struct resource smc91x_resources[] = {
366 .start = INTCP_PA_ETH_BASE,
367 .end = INTCP_PA_ETH_BASE + INTCP_ETH_SIZE - 1,
368 .flags = IORESOURCE_MEM,
371 .start = IRQ_CP_ETHINT,
372 .end = IRQ_CP_ETHINT,
373 .flags = IORESOURCE_IRQ,
377 static struct platform_device smc91x_device = {
380 .num_resources = ARRAY_SIZE(smc91x_resources),
381 .resource = smc91x_resources,
384 static struct platform_device *intcp_devs[] __initdata = {
390 * It seems that the card insertion interrupt remains active after
391 * we've acknowledged it. We therefore ignore the interrupt, and
392 * rely on reading it from the SIC. This also means that we must
393 * clear the latched interrupt.
395 static unsigned int mmc_status(struct device *dev)
397 unsigned int status = readl(0xfca00004);
398 writel(8, 0xfcb00008);
403 static struct mmc_platform_data mmc_data = {
404 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
405 .status = mmc_status,
408 static struct amba_device mmc_device = {
411 .platform_data = &mmc_data,
414 .start = INTCP_PA_MMC_BASE,
415 .end = INTCP_PA_MMC_BASE + SZ_4K - 1,
416 .flags = IORESOURCE_MEM,
418 .irq = { IRQ_CP_MMCIINT0, IRQ_CP_MMCIINT1 },
422 static struct amba_device aaci_device = {
427 .start = INTCP_PA_AACI_BASE,
428 .end = INTCP_PA_AACI_BASE + SZ_4K - 1,
429 .flags = IORESOURCE_MEM,
431 .irq = { IRQ_CP_AACIINT, NO_IRQ },
439 static struct clcd_panel vga = {
453 .vmode = FB_VMODE_NONINTERLACED,
457 .tim2 = TIM2_BCD | TIM2_IPC,
458 .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
464 * Ensure VGA is selected.
466 static void cp_clcd_enable(struct clcd_fb *fb)
470 if (fb->fb.var.bits_per_pixel <= 8)
471 val = CM_CTRL_LCDMUXSEL_VGA_8421BPP;
472 else if (fb->fb.var.bits_per_pixel <= 16)
473 val = CM_CTRL_LCDMUXSEL_VGA_16BPP
474 | CM_CTRL_LCDEN0 | CM_CTRL_LCDEN1
475 | CM_CTRL_STATIC1 | CM_CTRL_STATIC2;
477 val = 0; /* no idea for this, don't trust the docs */
479 cm_control(CM_CTRL_LCDMUXSEL_MASK|
485 CM_CTRL_n24BITEN, val);
488 static unsigned long framesize = SZ_1M;
490 static int cp_clcd_setup(struct clcd_fb *fb)
496 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
498 if (!fb->fb.screen_base) {
499 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
503 fb->fb.fix.smem_start = dma;
504 fb->fb.fix.smem_len = framesize;
509 static int cp_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
511 return dma_mmap_writecombine(&fb->dev->dev, vma,
513 fb->fb.fix.smem_start,
514 fb->fb.fix.smem_len);
517 static void cp_clcd_remove(struct clcd_fb *fb)
519 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
520 fb->fb.screen_base, fb->fb.fix.smem_start);
523 static struct clcd_board clcd_data = {
524 .name = "Integrator/CP",
525 .check = clcdfb_check,
526 .decode = clcdfb_decode,
527 .enable = cp_clcd_enable,
528 .setup = cp_clcd_setup,
529 .mmap = cp_clcd_mmap,
530 .remove = cp_clcd_remove,
533 static struct amba_device clcd_device = {
536 .coherent_dma_mask = ~0,
537 .platform_data = &clcd_data,
540 .start = INTCP_PA_CLCD_BASE,
541 .end = INTCP_PA_CLCD_BASE + SZ_4K - 1,
542 .flags = IORESOURCE_MEM,
545 .irq = { IRQ_CP_CLCDCINT, NO_IRQ },
549 static struct amba_device *amba_devs[] __initdata = {
555 static void __init intcp_init(void)
559 for (i = 0; i < ARRAY_SIZE(cp_lookups); i++)
560 clkdev_add(&cp_lookups[i]);
562 platform_add_devices(intcp_devs, ARRAY_SIZE(intcp_devs));
564 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
565 struct amba_device *d = amba_devs[i];
566 amba_device_register(d, &iomem_resource);
570 #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable */
572 static void __init intcp_timer_init(void)
574 integrator_time_init(1000000 / HZ, TIMER_CTRL_IE);
577 static struct sys_timer cp_timer = {
578 .init = intcp_timer_init,
579 .offset = integrator_gettimeoffset,
582 MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
583 /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
584 .phys_io = 0x16000000,
585 .io_pg_offst = ((0xf1600000) >> 18) & 0xfffc,
586 .boot_params = 0x00000100,
587 .map_io = intcp_map_io,
588 .init_irq = intcp_init_irq,
590 .init_machine = intcp_init,