Path: blob/master/arch/mips/powertv/asic/asic_int.c
10818 views
/*1* Carsten Langgaard, [email protected]2* Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.3* Copyright (C) 2001 Ralf Baechle4* Portions copyright (C) 2009 Cisco Systems, Inc.5*6* This program is free software; you can distribute it and/or modify it7* under the terms of the GNU General Public License (Version 2) as8* published by the Free Software Foundation.9*10* This program is distributed in the hope it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* for more details.14*15* You should have received a copy of the GNU General Public License along16* with this program; if not, write to the Free Software Foundation, Inc.,17* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.18*19* Routines for generic manipulation of the interrupts found on the PowerTV20* platform.21*22* The interrupt controller is located in the South Bridge a PIIX4 device23* with two internal 82C95 interrupt controllers.24*/25#include <linux/init.h>26#include <linux/irq.h>27#include <linux/sched.h>28#include <linux/interrupt.h>29#include <linux/kernel_stat.h>30#include <linux/kernel.h>31#include <linux/random.h>3233#include <asm/irq_cpu.h>34#include <linux/io.h>35#include <asm/irq_regs.h>36#include <asm/mips-boards/generic.h>3738#include <asm/mach-powertv/asic_regs.h>3940static DEFINE_RAW_SPINLOCK(asic_irq_lock);4142static inline int get_int(void)43{44unsigned long flags;45int irq;4647raw_spin_lock_irqsave(&asic_irq_lock, flags);4849irq = (asic_read(int_int_scan) >> 4) - 1;5051if (irq == 0 || irq >= NR_IRQS)52irq = -1;5354raw_spin_unlock_irqrestore(&asic_irq_lock, flags);5556return irq;57}5859static void asic_irqdispatch(void)60{61int irq;6263irq = get_int();64if (irq < 0)65return; /* interrupt has already been cleared */6667do_IRQ(irq);68}6970static inline int clz(unsigned long x)71{72__asm__(73" .set push \n"74" .set mips32 \n"75" clz %0, %1 \n"76" .set pop \n"77: "=r" (x)78: "r" (x));7980return x;81}8283/*84* Version of ffs that only looks at bits 12..15.85*/86static inline unsigned int irq_ffs(unsigned int pending)87{88return fls(pending) - 1 + CAUSEB_IP;89}9091/*92* TODO: check how it works under EIC mode.93*/94asmlinkage void plat_irq_dispatch(void)95{96unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;97int irq;9899irq = irq_ffs(pending);100101if (irq == CAUSEF_IP3)102asic_irqdispatch();103else if (irq >= 0)104do_IRQ(irq);105else106spurious_interrupt();107}108109void __init arch_init_irq(void)110{111int i;112113asic_irq_init();114115/*116* Initialize interrupt exception vectors.117*/118if (cpu_has_veic || cpu_has_vint) {119int nvec = cpu_has_veic ? 64 : 8;120for (i = 0; i < nvec; i++)121set_vi_handler(i, asic_irqdispatch);122}123}124125126