2 * arch/arm/mach-ixp2000/common.c
4 * Common routines used by all IXP2400/2800 based platforms.
6 * Author: Deepak Saxena <dsaxena@plexity.net>
8 * Copyright 2004 (C) MontaVista Software, Inc.
10 * Based on work Copyright (C) 2002-2003 Intel Corporation
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
21 #include <linux/sched.h>
22 #include <linux/interrupt.h>
23 #include <linux/serial.h>
24 #include <linux/tty.h>
25 #include <linux/bitops.h>
26 #include <linux/serial_core.h>
29 #include <asm/types.h>
30 #include <asm/setup.h>
31 #include <asm/memory.h>
32 #include <asm/hardware.h>
33 #include <asm/mach-types.h>
35 #include <asm/system.h>
36 #include <asm/tlbflush.h>
37 #include <asm/pgtable.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/time.h>
41 #include <asm/mach/irq.h>
43 static DEFINE_SPINLOCK(ixp2000_slowport_lock
);
44 static unsigned long ixp2000_slowport_irq_flags
;
46 /*************************************************************************
47 * Slowport access routines
48 *************************************************************************/
49 void ixp2000_acquire_slowport(struct slowport_cfg
*new_cfg
, struct slowport_cfg
*old_cfg
)
52 spin_lock_irqsave(&ixp2000_slowport_lock
, ixp2000_slowport_irq_flags
);
54 old_cfg
->CCR
= *IXP2000_SLOWPORT_CCR
;
55 old_cfg
->WTC
= *IXP2000_SLOWPORT_WTC2
;
56 old_cfg
->RTC
= *IXP2000_SLOWPORT_RTC2
;
57 old_cfg
->PCR
= *IXP2000_SLOWPORT_PCR
;
58 old_cfg
->ADC
= *IXP2000_SLOWPORT_ADC
;
60 ixp2000_reg_write(IXP2000_SLOWPORT_CCR
, new_cfg
->CCR
);
61 ixp2000_reg_write(IXP2000_SLOWPORT_WTC2
, new_cfg
->WTC
);
62 ixp2000_reg_write(IXP2000_SLOWPORT_RTC2
, new_cfg
->RTC
);
63 ixp2000_reg_write(IXP2000_SLOWPORT_PCR
, new_cfg
->PCR
);
64 ixp2000_reg_write(IXP2000_SLOWPORT_ADC
, new_cfg
->ADC
);
67 void ixp2000_release_slowport(struct slowport_cfg
*old_cfg
)
69 ixp2000_reg_write(IXP2000_SLOWPORT_CCR
, old_cfg
->CCR
);
70 ixp2000_reg_write(IXP2000_SLOWPORT_WTC2
, old_cfg
->WTC
);
71 ixp2000_reg_write(IXP2000_SLOWPORT_RTC2
, old_cfg
->RTC
);
72 ixp2000_reg_write(IXP2000_SLOWPORT_PCR
, old_cfg
->PCR
);
73 ixp2000_reg_write(IXP2000_SLOWPORT_ADC
, old_cfg
->ADC
);
75 spin_unlock_irqrestore(&ixp2000_slowport_lock
,
76 ixp2000_slowport_irq_flags
);
79 /*************************************************************************
80 * Chip specific mappings shared by all IXP2000 systems
81 *************************************************************************/
82 static struct map_desc ixp2000_io_desc
[] __initdata
= {
84 .virtual = IXP2000_CAP_VIRT_BASE
,
85 .physical
= IXP2000_CAP_PHYS_BASE
,
86 .length
= IXP2000_CAP_SIZE
,
89 .virtual = IXP2000_INTCTL_VIRT_BASE
,
90 .physical
= IXP2000_INTCTL_PHYS_BASE
,
91 .length
= IXP2000_INTCTL_SIZE
,
94 .virtual = IXP2000_PCI_CREG_VIRT_BASE
,
95 .physical
= IXP2000_PCI_CREG_PHYS_BASE
,
96 .length
= IXP2000_PCI_CREG_SIZE
,
99 .virtual = IXP2000_PCI_CSR_VIRT_BASE
,
100 .physical
= IXP2000_PCI_CSR_PHYS_BASE
,
101 .length
= IXP2000_PCI_CSR_SIZE
,
104 .virtual = IXP2000_PCI_IO_VIRT_BASE
,
105 .physical
= IXP2000_PCI_IO_PHYS_BASE
,
106 .length
= IXP2000_PCI_IO_SIZE
,
109 .virtual = IXP2000_PCI_CFG0_VIRT_BASE
,
110 .physical
= IXP2000_PCI_CFG0_PHYS_BASE
,
111 .length
= IXP2000_PCI_CFG0_SIZE
,
114 .virtual = IXP2000_PCI_CFG1_VIRT_BASE
,
115 .physical
= IXP2000_PCI_CFG1_PHYS_BASE
,
116 .length
= IXP2000_PCI_CFG1_SIZE
,
121 static struct uart_port ixp2000_serial_port
= {
122 .membase
= (char *)(IXP2000_UART_VIRT_BASE
+ 3),
123 .mapbase
= IXP2000_UART_PHYS_BASE
+ 3,
124 .irq
= IRQ_IXP2000_UART
,
125 .flags
= UPF_SKIP_TEST
,
134 void __init
ixp2000_map_io(void)
136 extern unsigned int processor_id
;
139 * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE for
140 * tweaking the PMDs so XCB=101. On IXP2800s we use the normal
143 if ((processor_id
& 0xfffffff0) == 0x69054190) {
146 printk(KERN_INFO
"Enabling IXP2400 erratum #66 workaround\n");
148 for(i
=0;i
<ARRAY_SIZE(ixp2000_io_desc
);i
++)
149 ixp2000_io_desc
[i
].type
= MT_IXP2000_DEVICE
;
152 iotable_init(ixp2000_io_desc
, ARRAY_SIZE(ixp2000_io_desc
));
153 early_serial_setup(&ixp2000_serial_port
);
155 /* Set slowport to 8-bit mode. */
156 ixp2000_reg_write(IXP2000_SLOWPORT_FRM
, 1);
159 /*************************************************************************
160 * Timer-tick functions for IXP2000
161 *************************************************************************/
162 static unsigned ticks_per_jiffy
;
163 static unsigned ticks_per_usec
;
164 static unsigned next_jiffy_time
;
165 static volatile unsigned long *missing_jiffy_timer_csr
;
167 unsigned long ixp2000_gettimeoffset (void)
169 unsigned long offset
;
171 offset
= next_jiffy_time
- *missing_jiffy_timer_csr
;
173 return offset
/ ticks_per_usec
;
176 static int ixp2000_timer_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
178 write_seqlock(&xtime_lock
);
181 ixp2000_reg_write(IXP2000_T1_CLR
, 1);
183 while ((next_jiffy_time
- *missing_jiffy_timer_csr
) > ticks_per_jiffy
) {
185 next_jiffy_time
-= ticks_per_jiffy
;
188 write_sequnlock(&xtime_lock
);
193 static struct irqaction ixp2000_timer_irq
= {
194 .name
= "IXP2000 Timer Tick",
195 .flags
= SA_INTERRUPT
,
196 .handler
= ixp2000_timer_interrupt
199 void __init
ixp2000_init_time(unsigned long tick_rate
)
201 ticks_per_jiffy
= (tick_rate
+ HZ
/2) / HZ
;
202 ticks_per_usec
= tick_rate
/ 1000000;
205 * We use timer 1 as our timer interrupt.
207 ixp2000_reg_write(IXP2000_T1_CLR
, 0);
208 ixp2000_reg_write(IXP2000_T1_CLD
, ticks_per_jiffy
- 1);
209 ixp2000_reg_write(IXP2000_T1_CTL
, (1 << 7));
212 * We use a second timer as a monotonic counter for tracking
213 * missed jiffies. The IXP2000 has four timers, but if we're
214 * on an A-step IXP2800, timer 2 and 3 don't work, so on those
215 * chips we use timer 4. Timer 4 is the only timer that can
216 * be used for the watchdog, so we use timer 2 if we're on a
219 if ((*IXP2000_PRODUCT_ID
& 0x001ffef0) == 0x00000000) {
220 printk(KERN_INFO
"Enabling IXP2800 erratum #25 workaround\n");
222 ixp2000_reg_write(IXP2000_T4_CLR
, 0);
223 ixp2000_reg_write(IXP2000_T4_CLD
, -1);
224 ixp2000_reg_write(IXP2000_T4_CTL
, (1 << 7));
225 missing_jiffy_timer_csr
= IXP2000_T4_CSR
;
227 ixp2000_reg_write(IXP2000_T2_CLR
, 0);
228 ixp2000_reg_write(IXP2000_T2_CLD
, -1);
229 ixp2000_reg_write(IXP2000_T2_CTL
, (1 << 7));
230 missing_jiffy_timer_csr
= IXP2000_T2_CSR
;
232 next_jiffy_time
= 0xffffffff;
234 /* register for interrupt */
235 setup_irq(IRQ_IXP2000_TIMER1
, &ixp2000_timer_irq
);
238 /*************************************************************************
240 *************************************************************************/
241 static unsigned long GPIO_IRQ_rising_edge
;
242 static unsigned long GPIO_IRQ_falling_edge
;
243 static unsigned long GPIO_IRQ_level_low
;
244 static unsigned long GPIO_IRQ_level_high
;
246 void gpio_line_config(int line
, int style
)
250 local_irq_save(flags
);
252 if(style
== GPIO_OUT
) {
253 /* if it's an output, it ain't an interrupt anymore */
254 ixp2000_reg_write(IXP2000_GPIO_PDSR
, (1 << line
));
255 GPIO_IRQ_falling_edge
&= ~(1 << line
);
256 GPIO_IRQ_rising_edge
&= ~(1 << line
);
257 GPIO_IRQ_level_low
&= ~(1 << line
);
258 GPIO_IRQ_level_high
&= ~(1 << line
);
259 ixp2000_reg_write(IXP2000_GPIO_FEDR
, GPIO_IRQ_falling_edge
);
260 ixp2000_reg_write(IXP2000_GPIO_REDR
, GPIO_IRQ_rising_edge
);
261 ixp2000_reg_write(IXP2000_GPIO_LSHR
, GPIO_IRQ_level_high
);
262 ixp2000_reg_write(IXP2000_GPIO_LSLR
, GPIO_IRQ_level_low
);
263 irq_desc
[line
+IRQ_IXP2000_GPIO0
].valid
= 0;
264 } else if(style
== GPIO_IN
) {
265 ixp2000_reg_write(IXP2000_GPIO_PDCR
, (1 << line
));
268 local_irq_restore(flags
);
272 /*************************************************************************
273 * IRQ handling IXP2000
274 *************************************************************************/
275 static void ixp2000_GPIO_irq_handler(unsigned int irq
, struct irqdesc
*desc
, struct pt_regs
*regs
)
278 unsigned long status
= *IXP2000_GPIO_INST
;
280 for (i
= 0; i
<= 7; i
++) {
281 if (status
& (1<<i
)) {
282 desc
= irq_desc
+ i
+ IRQ_IXP2000_GPIO0
;
283 desc
->handle(i
+ IRQ_IXP2000_GPIO0
, desc
, regs
);
288 static void ixp2000_GPIO_irq_mask_ack(unsigned int irq
)
290 ixp2000_reg_write(IXP2000_GPIO_INCR
, (1 << (irq
- IRQ_IXP2000_GPIO0
)));
291 ixp2000_reg_write(IXP2000_GPIO_INST
, (1 << (irq
- IRQ_IXP2000_GPIO0
)));
294 static void ixp2000_GPIO_irq_mask(unsigned int irq
)
296 ixp2000_reg_write(IXP2000_GPIO_INCR
, (1 << (irq
- IRQ_IXP2000_GPIO0
)));
299 static void ixp2000_GPIO_irq_unmask(unsigned int irq
)
301 ixp2000_reg_write(IXP2000_GPIO_INSR
, (1 << (irq
- IRQ_IXP2000_GPIO0
)));
304 static struct irqchip ixp2000_GPIO_irq_chip
= {
305 .ack
= ixp2000_GPIO_irq_mask_ack
,
306 .mask
= ixp2000_GPIO_irq_mask
,
307 .unmask
= ixp2000_GPIO_irq_unmask
310 static void ixp2000_pci_irq_mask(unsigned int irq
)
312 unsigned long temp
= *IXP2000_PCI_XSCALE_INT_ENABLE
;
313 if (irq
== IRQ_IXP2000_PCIA
)
314 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE
, (temp
& ~(1 << 26)));
315 else if (irq
== IRQ_IXP2000_PCIB
)
316 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE
, (temp
& ~(1 << 27)));
319 static void ixp2000_pci_irq_unmask(unsigned int irq
)
321 unsigned long temp
= *IXP2000_PCI_XSCALE_INT_ENABLE
;
322 if (irq
== IRQ_IXP2000_PCIA
)
323 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE
, (temp
| (1 << 26)));
324 else if (irq
== IRQ_IXP2000_PCIB
)
325 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE
, (temp
| (1 << 27)));
328 static struct irqchip ixp2000_pci_irq_chip
= {
329 .ack
= ixp2000_pci_irq_mask
,
330 .mask
= ixp2000_pci_irq_mask
,
331 .unmask
= ixp2000_pci_irq_unmask
334 static void ixp2000_irq_mask(unsigned int irq
)
336 ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR
, (1 << irq
));
339 static void ixp2000_irq_unmask(unsigned int irq
)
341 ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET
, (1 << irq
));
344 static struct irqchip ixp2000_irq_chip
= {
345 .ack
= ixp2000_irq_mask
,
346 .mask
= ixp2000_irq_mask
,
347 .unmask
= ixp2000_irq_unmask
350 void __init
ixp2000_init_irq(void)
357 ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR
, 0xffffffff);
358 ixp2000_reg_write(IXP2000_FIQ_ENABLE_CLR
, 0xffffffff);
360 /* clear all GPIO edge/level detects */
361 ixp2000_reg_write(IXP2000_GPIO_REDR
, 0);
362 ixp2000_reg_write(IXP2000_GPIO_FEDR
, 0);
363 ixp2000_reg_write(IXP2000_GPIO_LSHR
, 0);
364 ixp2000_reg_write(IXP2000_GPIO_LSLR
, 0);
365 ixp2000_reg_write(IXP2000_GPIO_INCR
, -1);
367 /* clear PCI interrupt sources */
368 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE
, 0);
371 * Certain bits in the IRQ status register of the
372 * IXP2000 are reserved. Instead of trying to map
373 * things non 1:1 from bit position to IRQ number,
374 * we mark the reserved IRQs as invalid. This makes
375 * our mask/unmask code much simpler.
377 for (irq
= IRQ_IXP2000_SOFT_INT
; irq
<= IRQ_IXP2000_THDB3
; irq
++) {
378 if((1 << irq
) & IXP2000_VALID_IRQ_MASK
) {
379 set_irq_chip(irq
, &ixp2000_irq_chip
);
380 set_irq_handler(irq
, do_level_IRQ
);
381 set_irq_flags(irq
, IRQF_VALID
);
382 } else set_irq_flags(irq
, 0);
386 * GPIO IRQs are invalid until someone sets the interrupt mode
387 * by calling gpio_line_set();
389 for (irq
= IRQ_IXP2000_GPIO0
; irq
<= IRQ_IXP2000_GPIO7
; irq
++) {
390 set_irq_chip(irq
, &ixp2000_GPIO_irq_chip
);
391 set_irq_handler(irq
, do_level_IRQ
);
392 set_irq_flags(irq
, 0);
394 set_irq_chained_handler(IRQ_IXP2000_GPIO
, ixp2000_GPIO_irq_handler
);
397 * Enable PCI irqs. The actual PCI[AB] decoding is done in
398 * entry-macro.S, so we don't need a chained handler for the
399 * PCI interrupt source.
401 ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET
, (1 << IRQ_IXP2000_PCI
));
402 for (irq
= IRQ_IXP2000_PCIA
; irq
<= IRQ_IXP2000_PCIB
; irq
++) {
403 set_irq_chip(irq
, &ixp2000_pci_irq_chip
);
404 set_irq_handler(irq
, do_level_IRQ
);
405 set_irq_flags(irq
, IRQF_VALID
);