/* * arch/arm/mach-ixp2000/common.c * * Common routines used by all IXP2400/2800 based platforms. * * Author: Deepak Saxena * * Copyright 2004 (C) MontaVista Software, Inc. * * Based on work Copyright (C) 2002-2003 Intel Corporation * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static DEFINE_SPINLOCK(ixp2000_slowport_lock); static unsigned long ixp2000_slowport_irq_flags; /************************************************************************* * Slowport access routines *************************************************************************/ void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg) { spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags); old_cfg->CCR = *IXP2000_SLOWPORT_CCR; old_cfg->WTC = *IXP2000_SLOWPORT_WTC2; old_cfg->RTC = *IXP2000_SLOWPORT_RTC2; old_cfg->PCR = *IXP2000_SLOWPORT_PCR; old_cfg->ADC = *IXP2000_SLOWPORT_ADC; ixp2000_reg_write(IXP2000_SLOWPORT_CCR, new_cfg->CCR); ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC); ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC); ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR); ixp2000_reg_write(IXP2000_SLOWPORT_ADC, new_cfg->ADC); } void ixp2000_release_slowport(struct slowport_cfg *old_cfg) { ixp2000_reg_write(IXP2000_SLOWPORT_CCR, old_cfg->CCR); ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC); ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC); ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR); ixp2000_reg_write(IXP2000_SLOWPORT_ADC, old_cfg->ADC); spin_unlock_irqrestore(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags); } /************************************************************************* * Chip specific mappings shared by all IXP2000 systems *************************************************************************/ static struct map_desc ixp2000_io_desc[] __initdata = { { .virtual = IXP2000_CAP_VIRT_BASE, .physical = IXP2000_CAP_PHYS_BASE, .length = IXP2000_CAP_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_INTCTL_VIRT_BASE, .physical = IXP2000_INTCTL_PHYS_BASE, .length = IXP2000_INTCTL_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_PCI_CREG_VIRT_BASE, .physical = IXP2000_PCI_CREG_PHYS_BASE, .length = IXP2000_PCI_CREG_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_PCI_CSR_VIRT_BASE, .physical = IXP2000_PCI_CSR_PHYS_BASE, .length = IXP2000_PCI_CSR_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_MSF_VIRT_BASE, .physical = IXP2000_MSF_PHYS_BASE, .length = IXP2000_MSF_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_PCI_IO_VIRT_BASE, .physical = IXP2000_PCI_IO_PHYS_BASE, .length = IXP2000_PCI_IO_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_PCI_CFG0_VIRT_BASE, .physical = IXP2000_PCI_CFG0_PHYS_BASE, .length = IXP2000_PCI_CFG0_SIZE, .type = MT_DEVICE }, { .virtual = IXP2000_PCI_CFG1_VIRT_BASE, .physical = IXP2000_PCI_CFG1_PHYS_BASE, .length = IXP2000_PCI_CFG1_SIZE, .type = MT_DEVICE } }; void __init ixp2000_map_io(void) { extern unsigned int processor_id; /* * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE for * tweaking the PMDs so XCB=101. On IXP2800s we use the normal * PMD flags. */ if ((processor_id & 0xfffffff0) == 0x69054190) { int i; printk(KERN_INFO "Enabling IXP2400 erratum #66 workaround\n"); for(i=0;i ticks_per_jiffy) { timer_tick(regs); next_jiffy_time -= ticks_per_jiffy; } write_sequnlock(&xtime_lock); return IRQ_HANDLED; } static struct irqaction ixp2000_timer_irq = { .name = "IXP2000 Timer Tick", .flags = SA_INTERRUPT | SA_TIMER, .handler = ixp2000_timer_interrupt, }; void __init ixp2000_init_time(unsigned long tick_rate) { ticks_per_jiffy = (tick_rate + HZ/2) / HZ; ticks_per_usec = tick_rate / 1000000; /* * We use timer 1 as our timer interrupt. */ ixp2000_reg_write(IXP2000_T1_CLR, 0); ixp2000_reg_write(IXP2000_T1_CLD, ticks_per_jiffy - 1); ixp2000_reg_write(IXP2000_T1_CTL, (1 << 7)); /* * We use a second timer as a monotonic counter for tracking * missed jiffies. The IXP2000 has four timers, but if we're * on an A-step IXP2800, timer 2 and 3 don't work, so on those * chips we use timer 4. Timer 4 is the only timer that can * be used for the watchdog, so we use timer 2 if we're on a * non-buggy chip. */ if ((*IXP2000_PRODUCT_ID & 0x001ffef0) == 0x00000000) { printk(KERN_INFO "Enabling IXP2800 erratum #25 workaround\n"); ixp2000_reg_write(IXP2000_T4_CLR, 0); ixp2000_reg_write(IXP2000_T4_CLD, -1); ixp2000_reg_write(IXP2000_T4_CTL, (1 << 7)); missing_jiffy_timer_csr = IXP2000_T4_CSR; } else { ixp2000_reg_write(IXP2000_T2_CLR, 0); ixp2000_reg_write(IXP2000_T2_CLD, -1); ixp2000_reg_write(IXP2000_T2_CTL, (1 << 7)); missing_jiffy_timer_csr = IXP2000_T2_CSR; } next_jiffy_time = 0xffffffff; /* register for interrupt */ setup_irq(IRQ_IXP2000_TIMER1, &ixp2000_timer_irq); } /************************************************************************* * GPIO helpers *************************************************************************/ static unsigned long GPIO_IRQ_falling_edge; static unsigned long GPIO_IRQ_rising_edge; static unsigned long GPIO_IRQ_level_low; static unsigned long GPIO_IRQ_level_high; static void update_gpio_int_csrs(void) { ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge); ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge); ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low); ixp2000_reg_write(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high); } void gpio_line_config(int line, int direction) { unsigned long flags; local_irq_save(flags); if (direction == GPIO_OUT) { irq_desc[line + IRQ_IXP2000_GPIO0].valid = 0; /* if it's an output, it ain't an interrupt anymore */ GPIO_IRQ_falling_edge &= ~(1 << line); GPIO_IRQ_rising_edge &= ~(1 << line); GPIO_IRQ_level_low &= ~(1 << line); GPIO_IRQ_level_high &= ~(1 << line); update_gpio_int_csrs(); ixp2000_reg_write(IXP2000_GPIO_PDSR, 1 << line); } else if (direction == GPIO_IN) { ixp2000_reg_write(IXP2000_GPIO_PDCR, 1 << line); } local_irq_restore(flags); } /************************************************************************* * IRQ handling IXP2000 *************************************************************************/ static void ixp2000_GPIO_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs) { int i; unsigned long status = *IXP2000_GPIO_INST; for (i = 0; i <= 7; i++) { if (status & (1<