2 * linux/arch/arm/mach-versatile/core.c
4 * Copyright (C) 1999 - 2003 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/config.h>
22 #include <linux/init.h>
23 #include <linux/device.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/sysdev.h>
26 #include <linux/interrupt.h>
28 #include <asm/system.h>
29 #include <asm/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/hardware/amba.h>
35 #include <asm/hardware/amba_clcd.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/flash.h>
39 #include <asm/mach/irq.h>
40 #include <asm/mach/time.h>
41 #include <asm/mach/map.h>
43 #include <asm/mach/mmc.h>
47 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
50 * Setup a VA for the Versatile Vectored Interrupt Controller.
52 #define VA_VIC_BASE IO_ADDRESS(VERSATILE_VIC_BASE)
53 #define VA_SIC_BASE IO_ADDRESS(VERSATILE_SIC_BASE)
55 static void vic_mask_irq(unsigned int irq
)
58 writel(1 << irq
, VA_VIC_BASE
+ VIC_IRQ_ENABLE_CLEAR
);
61 static void vic_unmask_irq(unsigned int irq
)
64 writel(1 << irq
, VA_VIC_BASE
+ VIC_IRQ_ENABLE
);
67 static struct irqchip vic_chip
= {
70 .unmask
= vic_unmask_irq
,
73 static void sic_mask_irq(unsigned int irq
)
76 writel(1 << irq
, VA_SIC_BASE
+ SIC_IRQ_ENABLE_CLEAR
);
79 static void sic_unmask_irq(unsigned int irq
)
82 writel(1 << irq
, VA_SIC_BASE
+ SIC_IRQ_ENABLE_SET
);
85 static struct irqchip sic_chip
= {
88 .unmask
= sic_unmask_irq
,
92 sic_handle_irq(unsigned int irq
, struct irqdesc
*desc
, struct pt_regs
*regs
)
94 unsigned long status
= readl(VA_SIC_BASE
+ SIC_IRQ_STATUS
);
97 do_bad_IRQ(irq
, desc
, regs
);
102 irq
= ffs(status
) - 1;
103 status
&= ~(1 << irq
);
105 irq
+= IRQ_SIC_START
;
107 desc
= irq_desc
+ irq
;
108 desc
->handle(irq
, desc
, regs
);
113 #define IRQ_MMCI0A IRQ_VICSOURCE22
114 #define IRQ_MMCI1A IRQ_VICSOURCE23
115 #define IRQ_AACI IRQ_VICSOURCE24
116 #define IRQ_ETH IRQ_VICSOURCE25
117 #define PIC_MASK 0xFFD00000
119 #define IRQ_MMCI0A IRQ_SIC_MMCI0A
120 #define IRQ_MMCI1A IRQ_SIC_MMCI1A
121 #define IRQ_AACI IRQ_SIC_AACI
122 #define IRQ_ETH IRQ_SIC_ETH
126 static void __init
versatile_init_irq(void)
128 unsigned int i
, value
;
130 /* Disable all interrupts initially. */
132 writel(0, VA_VIC_BASE
+ VIC_INT_SELECT
);
133 writel(0, VA_VIC_BASE
+ VIC_IRQ_ENABLE
);
134 writel(~0, VA_VIC_BASE
+ VIC_IRQ_ENABLE_CLEAR
);
135 writel(0, VA_VIC_BASE
+ VIC_IRQ_STATUS
);
136 writel(0, VA_VIC_BASE
+ VIC_ITCR
);
137 writel(~0, VA_VIC_BASE
+ VIC_IRQ_SOFT_CLEAR
);
140 * Make sure we clear all existing interrupts
142 writel(0, VA_VIC_BASE
+ VIC_VECT_ADDR
);
143 for (i
= 0; i
< 19; i
++) {
144 value
= readl(VA_VIC_BASE
+ VIC_VECT_ADDR
);
145 writel(value
, VA_VIC_BASE
+ VIC_VECT_ADDR
);
148 for (i
= 0; i
< 16; i
++) {
149 value
= readl(VA_VIC_BASE
+ VIC_VECT_CNTL0
+ (i
* 4));
150 writel(value
| VICVectCntl_Enable
| i
, VA_VIC_BASE
+ VIC_VECT_CNTL0
+ (i
* 4));
153 writel(32, VA_VIC_BASE
+ VIC_DEF_VECT_ADDR
);
155 for (i
= IRQ_VIC_START
; i
<= IRQ_VIC_END
; i
++) {
156 if (i
!= IRQ_VICSOURCE31
) {
157 set_irq_chip(i
, &vic_chip
);
158 set_irq_handler(i
, do_level_IRQ
);
159 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
163 set_irq_handler(IRQ_VICSOURCE31
, sic_handle_irq
);
164 vic_unmask_irq(IRQ_VICSOURCE31
);
166 /* Do second interrupt controller */
167 writel(~0, VA_SIC_BASE
+ SIC_IRQ_ENABLE_CLEAR
);
169 for (i
= IRQ_SIC_START
; i
<= IRQ_SIC_END
; i
++) {
170 if ((PIC_MASK
& (1 << (i
- IRQ_SIC_START
))) == 0) {
171 set_irq_chip(i
, &sic_chip
);
172 set_irq_handler(i
, do_level_IRQ
);
173 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
178 * Interrupts on secondary controller from 0 to 8 are routed to
180 * Interrupts from 21 to 31 are routed directly to the VIC on
181 * the corresponding number on primary controller. This is controlled
182 * by setting PIC_ENABLEx.
184 writel(PIC_MASK
, VA_SIC_BASE
+ SIC_INT_PIC_ENABLE
);
187 static struct map_desc versatile_io_desc
[] __initdata
= {
188 { IO_ADDRESS(VERSATILE_SYS_BASE
), VERSATILE_SYS_BASE
, SZ_4K
, MT_DEVICE
},
189 { IO_ADDRESS(VERSATILE_SIC_BASE
), VERSATILE_SIC_BASE
, SZ_4K
, MT_DEVICE
},
190 { IO_ADDRESS(VERSATILE_VIC_BASE
), VERSATILE_VIC_BASE
, SZ_4K
, MT_DEVICE
},
191 { IO_ADDRESS(VERSATILE_SCTL_BASE
), VERSATILE_SCTL_BASE
, SZ_4K
* 9, MT_DEVICE
},
192 #ifdef CONFIG_DEBUG_LL
193 { IO_ADDRESS(VERSATILE_UART0_BASE
), VERSATILE_UART0_BASE
, SZ_4K
, MT_DEVICE
},
196 { PCI_MEMORY_VADDR
, PHYS_PCI_MEM_BASE
, SZ_16M
, MT_DEVICE
},
197 { PCI_CONFIG_VADDR
, PHYS_PCI_CONFIG_BASE
, SZ_16M
, MT_DEVICE
},
198 { PCI_V3_VADDR
, PHYS_PCI_V3_BASE
, SZ_512K
, MT_DEVICE
},
199 { PCI_IO_VADDR
, PHYS_PCI_IO_BASE
, SZ_64K
, MT_DEVICE
},
203 static void __init
versatile_map_io(void)
205 iotable_init(versatile_io_desc
, ARRAY_SIZE(versatile_io_desc
));
208 #define VERSATILE_REFCOUNTER (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_24MHz_OFFSET)
211 * This is the VersatilePB sched_clock implementation. This has
212 * a resolution of 41.7ns, and a maximum value of about 179s.
214 unsigned long long sched_clock(void)
216 unsigned long long v
;
218 v
= (unsigned long long)readl(VERSATILE_REFCOUNTER
) * 125;
225 #define VERSATILE_FLASHCTRL (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
227 static int versatile_flash_init(void)
231 val
= __raw_readl(VERSATILE_FLASHCTRL
);
232 val
&= ~VERSATILE_FLASHPROG_FLVPPEN
;
233 __raw_writel(val
, VERSATILE_FLASHCTRL
);
238 static void versatile_flash_exit(void)
242 val
= __raw_readl(VERSATILE_FLASHCTRL
);
243 val
&= ~VERSATILE_FLASHPROG_FLVPPEN
;
244 __raw_writel(val
, VERSATILE_FLASHCTRL
);
247 static void versatile_flash_set_vpp(int on
)
251 val
= __raw_readl(VERSATILE_FLASHCTRL
);
253 val
|= VERSATILE_FLASHPROG_FLVPPEN
;
255 val
&= ~VERSATILE_FLASHPROG_FLVPPEN
;
256 __raw_writel(val
, VERSATILE_FLASHCTRL
);
259 static struct flash_platform_data versatile_flash_data
= {
260 .map_name
= "cfi_probe",
262 .init
= versatile_flash_init
,
263 .exit
= versatile_flash_exit
,
264 .set_vpp
= versatile_flash_set_vpp
,
267 static struct resource versatile_flash_resource
= {
268 .start
= VERSATILE_FLASH_BASE
,
269 .end
= VERSATILE_FLASH_BASE
+ VERSATILE_FLASH_SIZE
,
270 .flags
= IORESOURCE_MEM
,
273 static struct platform_device versatile_flash_device
= {
277 .platform_data
= &versatile_flash_data
,
280 .resource
= &versatile_flash_resource
,
283 static struct resource smc91x_resources
[] = {
285 .start
= VERSATILE_ETH_BASE
,
286 .end
= VERSATILE_ETH_BASE
+ SZ_64K
- 1,
287 .flags
= IORESOURCE_MEM
,
292 .flags
= IORESOURCE_IRQ
,
296 static struct platform_device smc91x_device
= {
299 .num_resources
= ARRAY_SIZE(smc91x_resources
),
300 .resource
= smc91x_resources
,
303 #define VERSATILE_SYSMCI (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
306 static unsigned int mmc_status(struct device
*dev
)
308 struct amba_device
*adev
= container_of(dev
, struct amba_device
, dev
);
311 if (adev
->res
.start
== VERSATILE_MMCI0_BASE
)
316 return readl(VERSATILE_SYSMCI
) & mask
;
319 static struct mmc_platform_data mmc0_plat_data
= {
320 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
321 .status
= mmc_status
,
324 static struct mmc_platform_data mmc1_plat_data
= {
325 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
326 .status
= mmc_status
,
333 #define SYS_CLCD_MODE_MASK (3 << 0)
334 #define SYS_CLCD_MODE_5551 (0 << 0)
335 #define SYS_CLCD_MODE_565 (1 << 0)
336 #define SYS_CLCD_MODE_888 (2 << 0)
337 #define SYS_CLCD_MODE_LT (3 << 0)
338 #define SYS_CLCD_NLCDIOON (1 << 2)
339 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
340 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
341 #define SYS_CLCD_ID_MASK (0x1f << 8)
342 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
343 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
344 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
345 #define SYS_CLCD_ID_VGA (0x1f << 8)
347 static struct clcd_panel vga
= {
361 .vmode
= FB_VMODE_NONINTERLACED
,
365 .tim2
= TIM2_BCD
| TIM2_IPC
,
366 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
370 static struct clcd_panel sanyo_3_8_in
= {
372 .name
= "Sanyo QVGA",
384 .vmode
= FB_VMODE_NONINTERLACED
,
389 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
393 static struct clcd_panel epson_2_2_in
= {
395 .name
= "Epson QCIF",
407 .vmode
= FB_VMODE_NONINTERLACED
,
411 .tim2
= TIM2_BCD
| TIM2_IPC
,
412 .cntl
= CNTL_LCDTFT
| CNTL_LCDVCOMP(1),
417 * Detect which LCD panel is connected, and return the appropriate
418 * clcd_panel structure. Note: we do not have any information on
419 * the required timings for the 8.4in panel, so we presently assume
422 static struct clcd_panel
*versatile_clcd_panel(void)
424 unsigned long sys_clcd
= IO_ADDRESS(VERSATILE_SYS_BASE
) + VERSATILE_SYS_CLCD_OFFSET
;
425 struct clcd_panel
*panel
= &vga
;
428 val
= readl(sys_clcd
) & SYS_CLCD_ID_MASK
;
429 if (val
== SYS_CLCD_ID_SANYO_3_8
)
430 panel
= &sanyo_3_8_in
;
431 else if (val
== SYS_CLCD_ID_EPSON_2_2
)
432 panel
= &epson_2_2_in
;
433 else if (val
== SYS_CLCD_ID_VGA
)
436 printk(KERN_ERR
"CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
444 * Disable all display connectors on the interface module.
446 static void versatile_clcd_disable(struct clcd_fb
*fb
)
448 unsigned long sys_clcd
= IO_ADDRESS(VERSATILE_SYS_BASE
) + VERSATILE_SYS_CLCD_OFFSET
;
451 val
= readl(sys_clcd
);
452 val
&= ~SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
453 writel(val
, sys_clcd
);
457 * Enable the relevant connector on the interface module.
459 static void versatile_clcd_enable(struct clcd_fb
*fb
)
461 unsigned long sys_clcd
= IO_ADDRESS(VERSATILE_SYS_BASE
) + VERSATILE_SYS_CLCD_OFFSET
;
464 val
= readl(sys_clcd
);
465 val
&= ~SYS_CLCD_MODE_MASK
;
467 switch (fb
->fb
.var
.green
.length
) {
471 * For some undocumented reason, we need to select 565 mode
472 * even when using 555 with VGA. Maybe this is only true
473 * for the VGA output and needs to be done for LCD panels?
474 * I can't get an explaination from the people who should
477 val
|= SYS_CLCD_MODE_5551
;
481 val
|= SYS_CLCD_MODE_565
;
484 val
|= SYS_CLCD_MODE_888
;
491 writel(val
, sys_clcd
);
494 * And now enable the PSUs
496 val
|= SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
497 writel(val
, sys_clcd
);
500 static unsigned long framesize
= SZ_1M
;
502 static int versatile_clcd_setup(struct clcd_fb
*fb
)
506 fb
->panel
= versatile_clcd_panel();
508 fb
->fb
.screen_base
= dma_alloc_writecombine(&fb
->dev
->dev
, framesize
,
510 if (!fb
->fb
.screen_base
) {
511 printk(KERN_ERR
"CLCD: unable to map framebuffer\n");
515 fb
->fb
.fix
.smem_start
= dma
;
516 fb
->fb
.fix
.smem_len
= framesize
;
521 static void versatile_clcd_remove(struct clcd_fb
*fb
)
523 dma_free_writecombine(&fb
->dev
->dev
, fb
->fb
.fix
.smem_len
,
524 fb
->fb
.screen_base
, fb
->fb
.fix
.smem_start
);
527 static struct clcd_board clcd_plat_data
= {
528 .name
= "Versatile PB",
529 .check
= clcdfb_check
,
530 .decode
= clcdfb_decode
,
531 .disable
= versatile_clcd_disable
,
532 .enable
= versatile_clcd_enable
,
533 .setup
= versatile_clcd_setup
,
534 .remove
= versatile_clcd_remove
,
537 #define AMBA_DEVICE(name,busid,base,plat) \
538 static struct amba_device name##_device = { \
540 .coherent_dma_mask = ~0, \
542 .platform_data = plat, \
545 .start = VERSATILE_##base##_BASE, \
546 .end = (VERSATILE_##base##_BASE) + SZ_4K - 1,\
547 .flags = IORESOURCE_MEM, \
551 /* .dma = base##_DMA,*/ \
554 #define AACI_IRQ { IRQ_AACI, NO_IRQ }
555 #define AACI_DMA { 0x80, 0x81 }
556 #define MMCI0_IRQ { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
557 #define MMCI0_DMA { 0x84, 0 }
558 #define KMI0_IRQ { IRQ_SIC_KMI0, NO_IRQ }
559 #define KMI0_DMA { 0, 0 }
560 #define KMI1_IRQ { IRQ_SIC_KMI1, NO_IRQ }
561 #define KMI1_DMA { 0, 0 }
562 #define UART3_IRQ { IRQ_SIC_UART3, NO_IRQ }
563 #define UART3_DMA { 0x86, 0x87 }
564 #define SCI1_IRQ { IRQ_SIC_SCI3, NO_IRQ }
565 #define SCI1_DMA { 0x88, 0x89 }
566 #define MMCI1_IRQ { IRQ_MMCI1A, IRQ_SIC_MMCI1B }
567 #define MMCI1_DMA { 0x85, 0 }
570 * These devices are connected directly to the multi-layer AHB switch
572 #define SMC_IRQ { NO_IRQ, NO_IRQ }
573 #define SMC_DMA { 0, 0 }
574 #define MPMC_IRQ { NO_IRQ, NO_IRQ }
575 #define MPMC_DMA { 0, 0 }
576 #define CLCD_IRQ { IRQ_CLCDINT, NO_IRQ }
577 #define CLCD_DMA { 0, 0 }
578 #define DMAC_IRQ { IRQ_DMAINT, NO_IRQ }
579 #define DMAC_DMA { 0, 0 }
582 * These devices are connected via the core APB bridge
584 #define SCTL_IRQ { NO_IRQ, NO_IRQ }
585 #define SCTL_DMA { 0, 0 }
586 #define WATCHDOG_IRQ { IRQ_WDOGINT, NO_IRQ }
587 #define WATCHDOG_DMA { 0, 0 }
588 #define GPIO0_IRQ { IRQ_GPIOINT0, NO_IRQ }
589 #define GPIO0_DMA { 0, 0 }
590 #define GPIO1_IRQ { IRQ_GPIOINT1, NO_IRQ }
591 #define GPIO1_DMA { 0, 0 }
592 #define GPIO2_IRQ { IRQ_GPIOINT2, NO_IRQ }
593 #define GPIO2_DMA { 0, 0 }
594 #define GPIO3_IRQ { IRQ_GPIOINT3, NO_IRQ }
595 #define GPIO3_DMA { 0, 0 }
596 #define RTC_IRQ { IRQ_RTCINT, NO_IRQ }
597 #define RTC_DMA { 0, 0 }
600 * These devices are connected via the DMA APB bridge
602 #define SCI_IRQ { IRQ_SCIINT, NO_IRQ }
603 #define SCI_DMA { 7, 6 }
604 #define UART0_IRQ { IRQ_UARTINT0, NO_IRQ }
605 #define UART0_DMA { 15, 14 }
606 #define UART1_IRQ { IRQ_UARTINT1, NO_IRQ }
607 #define UART1_DMA { 13, 12 }
608 #define UART2_IRQ { IRQ_UARTINT2, NO_IRQ }
609 #define UART2_DMA { 11, 10 }
610 #define SSP_IRQ { IRQ_SSPINT, NO_IRQ }
611 #define SSP_DMA { 9, 8 }
613 /* FPGA Primecells */
614 AMBA_DEVICE(aaci
, "fpga:04", AACI
, NULL
);
616 AMBA_DEVICE(mmc0
, "fpga:05", MMCI0
, &mmc0_plat_data
);
618 AMBA_DEVICE(kmi0
, "fpga:06", KMI0
, NULL
);
619 AMBA_DEVICE(kmi1
, "fpga:07", KMI1
, NULL
);
620 AMBA_DEVICE(uart3
, "fpga:09", UART3
, NULL
);
621 AMBA_DEVICE(sci1
, "fpga:0a", SCI1
, NULL
);
623 AMBA_DEVICE(mmc1
, "fpga:0b", MMCI1
, &mmc1_plat_data
);
626 /* DevChip Primecells */
627 AMBA_DEVICE(smc
, "dev:00", SMC
, NULL
);
628 AMBA_DEVICE(mpmc
, "dev:10", MPMC
, NULL
);
629 AMBA_DEVICE(clcd
, "dev:20", CLCD
, &clcd_plat_data
);
630 AMBA_DEVICE(dmac
, "dev:30", DMAC
, NULL
);
631 AMBA_DEVICE(sctl
, "dev:e0", SCTL
, NULL
);
632 AMBA_DEVICE(wdog
, "dev:e1", WATCHDOG
, NULL
);
633 AMBA_DEVICE(gpio0
, "dev:e4", GPIO0
, NULL
);
634 AMBA_DEVICE(gpio1
, "dev:e5", GPIO1
, NULL
);
635 AMBA_DEVICE(gpio2
, "dev:e6", GPIO2
, NULL
);
636 AMBA_DEVICE(gpio3
, "dev:e7", GPIO3
, NULL
);
637 AMBA_DEVICE(rtc
, "dev:e8", RTC
, NULL
);
638 AMBA_DEVICE(sci0
, "dev:f0", SCI
, NULL
);
639 AMBA_DEVICE(uart0
, "dev:f1", UART0
, NULL
);
640 AMBA_DEVICE(uart1
, "dev:f2", UART1
, NULL
);
641 AMBA_DEVICE(uart2
, "dev:f3", UART2
, NULL
);
642 AMBA_DEVICE(ssp0
, "dev:f4", SSP
, NULL
);
644 static struct amba_device
*amba_devs
[] __initdata
= {
674 #define VA_LEDS_BASE (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
676 static void versatile_leds_event(led_event_t ledevt
)
681 local_irq_save(flags
);
682 val
= readl(VA_LEDS_BASE
);
686 val
= val
& ~VERSATILE_SYS_LED0
;
690 val
= val
| VERSATILE_SYS_LED0
;
694 val
= val
^ VERSATILE_SYS_LED1
;
705 writel(val
, VA_LEDS_BASE
);
706 local_irq_restore(flags
);
709 static void __init
versatile_init(void)
713 platform_device_register(&versatile_flash_device
);
714 platform_device_register(&smc91x_device
);
716 for (i
= 0; i
< ARRAY_SIZE(amba_devs
); i
++) {
717 struct amba_device
*d
= amba_devs
[i
];
718 amba_device_register(d
, &iomem_resource
);
721 leds_event
= versatile_leds_event
;
725 * Where is the timer (VA)?
727 #define TIMER0_VA_BASE IO_ADDRESS(VERSATILE_TIMER0_1_BASE)
728 #define TIMER1_VA_BASE (IO_ADDRESS(VERSATILE_TIMER0_1_BASE) + 0x20)
729 #define TIMER2_VA_BASE IO_ADDRESS(VERSATILE_TIMER2_3_BASE)
730 #define TIMER3_VA_BASE (IO_ADDRESS(VERSATILE_TIMER2_3_BASE) + 0x20)
731 #define VA_IC_BASE IO_ADDRESS(VERSATILE_VIC_BASE)
734 * How long is the timer interval?
736 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
737 #if TIMER_INTERVAL >= 0x100000
738 #define TIMER_RELOAD (TIMER_INTERVAL >> 8) /* Divide by 256 */
739 #define TIMER_CTRL 0x88 /* Enable, Clock / 256 */
740 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
741 #elif TIMER_INTERVAL >= 0x10000
742 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
743 #define TIMER_CTRL 0x84 /* Enable, Clock / 16 */
744 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
746 #define TIMER_RELOAD (TIMER_INTERVAL)
747 #define TIMER_CTRL 0x80 /* Enable */
748 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
751 #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable */
754 * What does it look like?
756 typedef struct TimerStruct
{
757 unsigned long TimerLoad
;
758 unsigned long TimerValue
;
759 unsigned long TimerControl
;
760 unsigned long TimerClear
;
763 extern unsigned long (*gettimeoffset
)(void);
766 * Returns number of ms since last clock interrupt. Note that interrupts
767 * will have been disabled by do_gettimeoffset()
769 static unsigned long versatile_gettimeoffset(void)
771 volatile TimerStruct_t
*timer0
= (TimerStruct_t
*)TIMER0_VA_BASE
;
772 unsigned long ticks1
, ticks2
, status
;
775 * Get the current number of ticks. Note that there is a race
776 * condition between us reading the timer and checking for
777 * an interrupt. We get around this by ensuring that the
778 * counter has not reloaded between our two reads.
780 ticks2
= timer0
->TimerValue
& 0xffff;
783 status
= __raw_readl(VA_IC_BASE
+ VIC_IRQ_RAW_STATUS
);
784 ticks2
= timer0
->TimerValue
& 0xffff;
785 } while (ticks2
> ticks1
);
788 * Number of ticks since last interrupt.
790 ticks1
= TIMER_RELOAD
- ticks2
;
793 * Interrupt pending? If so, we've reloaded once already.
795 * FIXME: Need to check this is effectively timer 0 that expires
797 if (status
& IRQMASK_TIMERINT0_1
)
798 ticks1
+= TIMER_RELOAD
;
801 * Convert the ticks to usecs
803 return TICKS2USECS(ticks1
);
807 * IRQ handler for the timer
809 static irqreturn_t
versatile_timer_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
811 volatile TimerStruct_t
*timer0
= (volatile TimerStruct_t
*)TIMER0_VA_BASE
;
813 // ...clear the interrupt
814 timer0
->TimerClear
= 1;
821 static struct irqaction versatile_timer_irq
= {
822 .name
= "Versatile Timer Tick",
823 .flags
= SA_INTERRUPT
,
824 .handler
= versatile_timer_interrupt
828 * Set up timer interrupt, and return the current time in seconds.
830 void __init
versatile_init_time(void)
832 volatile TimerStruct_t
*timer0
= (volatile TimerStruct_t
*)TIMER0_VA_BASE
;
833 volatile TimerStruct_t
*timer1
= (volatile TimerStruct_t
*)TIMER1_VA_BASE
;
834 volatile TimerStruct_t
*timer2
= (volatile TimerStruct_t
*)TIMER2_VA_BASE
;
835 volatile TimerStruct_t
*timer3
= (volatile TimerStruct_t
*)TIMER3_VA_BASE
;
838 * set clock frequency:
839 * VERSATILE_REFCLK is 32KHz
840 * VERSATILE_TIMCLK is 1MHz
842 *(volatile unsigned int *)IO_ADDRESS(VERSATILE_SCTL_BASE
) |=
843 ((VERSATILE_TIMCLK
<< VERSATILE_TIMER1_EnSel
) | (VERSATILE_TIMCLK
<< VERSATILE_TIMER2_EnSel
) |
844 (VERSATILE_TIMCLK
<< VERSATILE_TIMER3_EnSel
) | (VERSATILE_TIMCLK
<< VERSATILE_TIMER4_EnSel
));
847 * Initialise to a known state (all timers off)
849 timer0
->TimerControl
= 0;
850 timer1
->TimerControl
= 0;
851 timer2
->TimerControl
= 0;
852 timer3
->TimerControl
= 0;
854 timer0
->TimerLoad
= TIMER_RELOAD
;
855 timer0
->TimerValue
= TIMER_RELOAD
;
856 timer0
->TimerControl
= TIMER_CTRL
| 0x40 | TIMER_CTRL_IE
; /* periodic + IE */
859 * Make irqs happen for the system timer
861 setup_irq(IRQ_TIMERINT0_1
, &versatile_timer_irq
);
862 gettimeoffset
= versatile_gettimeoffset
;
865 MACHINE_START(VERSATILE_PB
, "ARM-Versatile PB")
866 MAINTAINER("ARM Ltd/Deep Blue Solutions Ltd")
867 BOOT_MEM(0x00000000, 0x101f1000, 0xf11f1000)
868 BOOT_PARAMS(0x00000100)
869 MAPIO(versatile_map_io
)
870 INITIRQ(versatile_init_irq
)
871 INITTIME(versatile_init_time
)
872 INIT_MACHINE(versatile_init
)