core.c
来自「linux2.6.16版本」· C语言 代码 · 共 533 行 · 第 1/2 页
C
533 行
/* * arch/arm/mach-ixp2000/core.c * * Common routines used by all IXP2400/2800 based platforms. * * Author: Deepak Saxena <dsaxena@plexity.net> * * 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 <linux/config.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/spinlock.h>#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/serial.h>#include <linux/tty.h>#include <linux/bitops.h>#include <linux/serial_8250.h>#include <linux/mm.h>#include <asm/types.h>#include <asm/setup.h>#include <asm/memory.h>#include <asm/hardware.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/tlbflush.h>#include <asm/pgtable.h>#include <asm/mach/map.h>#include <asm/mach/time.h>#include <asm/mach/irq.h>#include <asm/arch/gpio.h>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_wrb(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_wrb(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, .pfn = __phys_to_pfn(IXP2000_CAP_PHYS_BASE), .length = IXP2000_CAP_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_INTCTL_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_INTCTL_PHYS_BASE), .length = IXP2000_INTCTL_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_PCI_CREG_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_PCI_CREG_PHYS_BASE), .length = IXP2000_PCI_CREG_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_PCI_CSR_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_PCI_CSR_PHYS_BASE), .length = IXP2000_PCI_CSR_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_MSF_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_MSF_PHYS_BASE), .length = IXP2000_MSF_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_SCRATCH_RING_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_SCRATCH_RING_PHYS_BASE), .length = IXP2000_SCRATCH_RING_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_SRAM0_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_SRAM0_PHYS_BASE), .length = IXP2000_SRAM0_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_PCI_IO_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_PCI_IO_PHYS_BASE), .length = IXP2000_PCI_IO_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_PCI_CFG0_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_PCI_CFG0_PHYS_BASE), .length = IXP2000_PCI_CFG0_SIZE, .type = MT_IXP2000_DEVICE, }, { .virtual = IXP2000_PCI_CFG1_VIRT_BASE, .pfn = __phys_to_pfn(IXP2000_PCI_CFG1_PHYS_BASE), .length = IXP2000_PCI_CFG1_SIZE, .type = MT_IXP2000_DEVICE, }};void __init ixp2000_map_io(void){ /* * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE so that * XCB=101 (to avoid triggering erratum #66), and given that * this mode speeds up I/O accesses and we have write buffer * flushes in the right places anyway, it doesn't hurt to use * XCB=101 for all IXP2000s. */ iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc)); /* Set slowport to 8-bit mode. */ ixp2000_reg_wrb(IXP2000_SLOWPORT_FRM, 1);}/************************************************************************* * Serial port support for IXP2000 *************************************************************************/static struct plat_serial8250_port ixp2000_serial_port[] = { { .mapbase = IXP2000_UART_PHYS_BASE, .membase = (char *)(IXP2000_UART_VIRT_BASE + 3), .irq = IRQ_IXP2000_UART, .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, .iotype = UPIO_MEM, .regshift = 2, .uartclk = 50000000, }, { },};static struct resource ixp2000_uart_resource = { .start = IXP2000_UART_PHYS_BASE, .end = IXP2000_UART_PHYS_BASE + 0x1f, .flags = IORESOURCE_MEM,};static struct platform_device ixp2000_serial_device = { .name = "serial8250", .id = PLAT8250_DEV_PLATFORM, .dev = { .platform_data = ixp2000_serial_port, }, .num_resources = 1, .resource = &ixp2000_uart_resource,};void __init ixp2000_uart_init(void){ platform_device_register(&ixp2000_serial_device);}/************************************************************************* * Timer-tick functions for IXP2000 *************************************************************************/static unsigned ticks_per_jiffy;static unsigned ticks_per_usec;static unsigned next_jiffy_time;static volatile unsigned long *missing_jiffy_timer_csr;unsigned long ixp2000_gettimeoffset (void){ unsigned long offset; offset = next_jiffy_time - *missing_jiffy_timer_csr; return offset / ticks_per_usec;}static int ixp2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs){ write_seqlock(&xtime_lock); /* clear timer 1 */ ixp2000_reg_wrb(IXP2000_T1_CLR, 1); while ((next_jiffy_time - *missing_jiffy_timer_csr) > 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_wrb(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_wrb(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);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?