Path: blob/master/arch/mips/pnx833x/common/interrupts.c
10818 views
/*1* interrupts.c: Interrupt mappings for PNX833X.2*3* Copyright 2008 NXP Semiconductors4* Chris Steel <[email protected]>5* Daniel Laird <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.20*/21#include <linux/kernel.h>22#include <linux/irq.h>23#include <linux/hardirq.h>24#include <linux/interrupt.h>25#include <asm/mipsregs.h>26#include <asm/irq_cpu.h>27#include <irq.h>28#include <irq-mapping.h>29#include <gpio.h>3031static int mips_cpu_timer_irq;3233static const unsigned int irq_prio[PNX833X_PIC_NUM_IRQ] =34{350, /* unused */364, /* PNX833X_PIC_I2C0_INT 1 */374, /* PNX833X_PIC_I2C1_INT 2 */381, /* PNX833X_PIC_UART0_INT 3 */391, /* PNX833X_PIC_UART1_INT 4 */406, /* PNX833X_PIC_TS_IN0_DV_INT 5 */416, /* PNX833X_PIC_TS_IN0_DMA_INT 6 */427, /* PNX833X_PIC_GPIO_INT 7 */434, /* PNX833X_PIC_AUDIO_DEC_INT 8 */445, /* PNX833X_PIC_VIDEO_DEC_INT 9 */454, /* PNX833X_PIC_CONFIG_INT 10 */464, /* PNX833X_PIC_AOI_INT 11 */479, /* PNX833X_PIC_SYNC_INT 12 */489, /* PNX8335_PIC_SATA_INT 13 */494, /* PNX833X_PIC_OSD_INT 14 */509, /* PNX833X_PIC_DISP1_INT 15 */514, /* PNX833X_PIC_DEINTERLACER_INT 16 */529, /* PNX833X_PIC_DISPLAY2_INT 17 */534, /* PNX833X_PIC_VC_INT 18 */544, /* PNX833X_PIC_SC_INT 19 */559, /* PNX833X_PIC_IDE_INT 20 */569, /* PNX833X_PIC_IDE_DMA_INT 21 */576, /* PNX833X_PIC_TS_IN1_DV_INT 22 */586, /* PNX833X_PIC_TS_IN1_DMA_INT 23 */594, /* PNX833X_PIC_SGDX_DMA_INT 24 */604, /* PNX833X_PIC_TS_OUT_INT 25 */614, /* PNX833X_PIC_IR_INT 26 */623, /* PNX833X_PIC_VMSP1_INT 27 */633, /* PNX833X_PIC_VMSP2_INT 28 */644, /* PNX833X_PIC_PIBC_INT 29 */654, /* PNX833X_PIC_TS_IN0_TRD_INT 30 */664, /* PNX833X_PIC_SGDX_TPD_INT 31 */675, /* PNX833X_PIC_USB_INT 32 */684, /* PNX833X_PIC_TS_IN1_TRD_INT 33 */694, /* PNX833X_PIC_CLOCK_INT 34 */704, /* PNX833X_PIC_SGDX_PARSER_INT 35 */714, /* PNX833X_PIC_VMSP_DMA_INT 36 */72#if defined(CONFIG_SOC_PNX8335)734, /* PNX8335_PIC_MIU_INT 37 */744, /* PNX8335_PIC_AVCHIP_IRQ_INT 38 */759, /* PNX8335_PIC_SYNC_HD_INT 39 */769, /* PNX8335_PIC_DISP_HD_INT 40 */779, /* PNX8335_PIC_DISP_SCALER_INT 41 */784, /* PNX8335_PIC_OSD_HD1_INT 42 */794, /* PNX8335_PIC_DTL_WRITER_Y_INT 43 */804, /* PNX8335_PIC_DTL_WRITER_C_INT 44 */814, /* PNX8335_PIC_DTL_EMULATOR_Y_IR_INT 45 */824, /* PNX8335_PIC_DTL_EMULATOR_C_IR_INT 46 */834, /* PNX8335_PIC_DENC_TTX_INT 47 */844, /* PNX8335_PIC_MMI_SIF0_INT 48 */854, /* PNX8335_PIC_MMI_SIF1_INT 49 */864, /* PNX8335_PIC_MMI_CDMMU_INT 50 */874, /* PNX8335_PIC_PIBCS_INT 51 */8812, /* PNX8335_PIC_ETHERNET_INT 52 */893, /* PNX8335_PIC_VMSP1_0_INT 53 */903, /* PNX8335_PIC_VMSP1_1_INT 54 */914, /* PNX8335_PIC_VMSP1_DMA_INT 55 */924, /* PNX8335_PIC_TDGR_DE_INT 56 */934, /* PNX8335_PIC_IR1_IRQ_INT 57 */94#endif95};9697static void pnx833x_timer_dispatch(void)98{99do_IRQ(mips_cpu_timer_irq);100}101102static void pic_dispatch(void)103{104unsigned int irq = PNX833X_REGFIELD(PIC_INT_SRC, INT_SRC);105106if ((irq >= 1) && (irq < (PNX833X_PIC_NUM_IRQ))) {107unsigned long priority = PNX833X_PIC_INT_PRIORITY;108PNX833X_PIC_INT_PRIORITY = irq_prio[irq];109110if (irq == PNX833X_PIC_GPIO_INT) {111unsigned long mask = PNX833X_PIO_INT_STATUS & PNX833X_PIO_INT_ENABLE;112int pin;113while ((pin = ffs(mask & 0xffff))) {114pin -= 1;115do_IRQ(PNX833X_GPIO_IRQ_BASE + pin);116mask &= ~(1 << pin);117}118} else {119do_IRQ(irq + PNX833X_PIC_IRQ_BASE);120}121122PNX833X_PIC_INT_PRIORITY = priority;123} else {124printk(KERN_ERR "plat_irq_dispatch: unexpected irq %u\n", irq);125}126}127128asmlinkage void plat_irq_dispatch(void)129{130unsigned int pending = read_c0_status() & read_c0_cause();131132if (pending & STATUSF_IP4)133pic_dispatch();134else if (pending & STATUSF_IP7)135do_IRQ(PNX833X_TIMER_IRQ);136else137spurious_interrupt();138}139140static inline void pnx833x_hard_enable_pic_irq(unsigned int irq)141{142/* Currently we do this by setting IRQ priority to 1.143If priority support is being implemented, 1 should be repalced144by a better value. */145PNX833X_PIC_INT_REG(irq) = irq_prio[irq];146}147148static inline void pnx833x_hard_disable_pic_irq(unsigned int irq)149{150/* Disable IRQ by writing setting it's priority to 0 */151PNX833X_PIC_INT_REG(irq) = 0;152}153154static DEFINE_RAW_SPINLOCK(pnx833x_irq_lock);155156static unsigned int pnx833x_startup_pic_irq(unsigned int irq)157{158unsigned long flags;159unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;160161raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);162pnx833x_hard_enable_pic_irq(pic_irq);163raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);164return 0;165}166167static void pnx833x_enable_pic_irq(struct irq_data *d)168{169unsigned long flags;170unsigned int pic_irq = d->irq - PNX833X_PIC_IRQ_BASE;171172raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);173pnx833x_hard_enable_pic_irq(pic_irq);174raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);175}176177static void pnx833x_disable_pic_irq(struct irq_data *d)178{179unsigned long flags;180unsigned int pic_irq = d->irq - PNX833X_PIC_IRQ_BASE;181182raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);183pnx833x_hard_disable_pic_irq(pic_irq);184raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);185}186187static DEFINE_RAW_SPINLOCK(pnx833x_gpio_pnx833x_irq_lock);188189static void pnx833x_enable_gpio_irq(struct irq_data *d)190{191int pin = d->irq - PNX833X_GPIO_IRQ_BASE;192unsigned long flags;193raw_spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);194pnx833x_gpio_enable_irq(pin);195raw_spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);196}197198static void pnx833x_disable_gpio_irq(struct irq_data *d)199{200int pin = d->irq - PNX833X_GPIO_IRQ_BASE;201unsigned long flags;202raw_spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);203pnx833x_gpio_disable_irq(pin);204raw_spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);205}206207static int pnx833x_set_type_gpio_irq(struct irq_data *d, unsigned int flow_type)208{209int pin = d->irq - PNX833X_GPIO_IRQ_BASE;210int gpio_mode;211212switch (flow_type) {213case IRQ_TYPE_EDGE_RISING:214gpio_mode = GPIO_INT_EDGE_RISING;215break;216case IRQ_TYPE_EDGE_FALLING:217gpio_mode = GPIO_INT_EDGE_FALLING;218break;219case IRQ_TYPE_EDGE_BOTH:220gpio_mode = GPIO_INT_EDGE_BOTH;221break;222case IRQ_TYPE_LEVEL_HIGH:223gpio_mode = GPIO_INT_LEVEL_HIGH;224break;225case IRQ_TYPE_LEVEL_LOW:226gpio_mode = GPIO_INT_LEVEL_LOW;227break;228default:229gpio_mode = GPIO_INT_NONE;230break;231}232233pnx833x_gpio_setup_irq(gpio_mode, pin);234235return 0;236}237238static struct irq_chip pnx833x_pic_irq_type = {239.name = "PNX-PIC",240.irq_enable = pnx833x_enable_pic_irq,241.irq_disable = pnx833x_disable_pic_irq,242};243244static struct irq_chip pnx833x_gpio_irq_type = {245.name = "PNX-GPIO",246.irq_enable = pnx833x_enable_gpio_irq,247.irq_disable = pnx833x_disable_gpio_irq,248.irq_set_type = pnx833x_set_type_gpio_irq,249};250251void __init arch_init_irq(void)252{253unsigned int irq;254255/* setup standard internal cpu irqs */256mips_cpu_irq_init();257258/* Set IRQ information in irq_desc */259for (irq = PNX833X_PIC_IRQ_BASE; irq < (PNX833X_PIC_IRQ_BASE + PNX833X_PIC_NUM_IRQ); irq++) {260pnx833x_hard_disable_pic_irq(irq);261irq_set_chip_and_handler(irq, &pnx833x_pic_irq_type,262handle_simple_irq);263}264265for (irq = PNX833X_GPIO_IRQ_BASE; irq < (PNX833X_GPIO_IRQ_BASE + PNX833X_GPIO_NUM_IRQ); irq++)266irq_set_chip_and_handler(irq, &pnx833x_gpio_irq_type,267handle_simple_irq);268269/* Set PIC priority limiter register to 0 */270PNX833X_PIC_INT_PRIORITY = 0;271272/* Setup GPIO IRQ dispatching */273pnx833x_startup_pic_irq(PNX833X_PIC_GPIO_INT);274275/* Enable PIC IRQs (HWIRQ2) */276if (cpu_has_vint)277set_vi_handler(4, pic_dispatch);278279write_c0_status(read_c0_status() | IE_IRQ2);280}281282unsigned int __cpuinit get_c0_compare_int(void)283{284if (cpu_has_vint)285set_vi_handler(cp0_compare_irq, pnx833x_timer_dispatch);286287mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;288return mips_cpu_timer_irq;289}290291void __init plat_time_init(void)292{293/* calculate mips_hpt_frequency based on PNX833X_CLOCK_CPUCP_CTL reg */294295extern unsigned long mips_hpt_frequency;296unsigned long reg = PNX833X_CLOCK_CPUCP_CTL;297298if (!(PNX833X_BIT(reg, CLOCK_CPUCP_CTL, EXIT_RESET))) {299/* Functional clock is disabled so use crystal frequency */300mips_hpt_frequency = 25;301} else {302#if defined(CONFIG_SOC_PNX8335)303/* Functional clock is enabled, so get clock multiplier */304mips_hpt_frequency = 90 + (10 * PNX8335_REGFIELD(CLOCK_PLL_CPU_CTL, FREQ));305#else306static const unsigned long int freq[4] = {240, 160, 120, 80};307mips_hpt_frequency = freq[PNX833X_FIELD(reg, CLOCK_CPUCP_CTL, DIV_CLOCK)];308#endif309}310311printk(KERN_INFO "CPU clock is %ld MHz\n", mips_hpt_frequency);312313mips_hpt_frequency *= 500000;314}315316317