1 /* 2 * Copyright (c) 2008, Google Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <boot/boot.h> 30 #include <msm7k/vic.h> 31 #include <msm7k/irqs.h> 32 33 extern irq_handler irq_vector_table[NR_IRQS]; 34 35 void unknown_handler(unsigned n) 36 { 37 dprintf("unsolicited irq #%d\n", n); 38 for(;;); 39 } 40 41 void irq_init(void) 42 { 43 unsigned n; 44 45 for(n = 0; n < NR_IRQS; n++) { 46 irq_vector_table[n] = unknown_handler; 47 } 48 /* select level interrupts */ 49 writel(0, VIC_INT_TYPE0); 50 writel(0, VIC_INT_TYPE1); 51 52 /* select IRQ for all INTs */ 53 writel(0, VIC_INT_SELECT0); 54 writel(0, VIC_INT_SELECT1); 55 56 /* clear interrupts */ 57 writel(0xffffffff, VIC_INT_CLEAR0); 58 writel(0xffffffff, VIC_INT_CLEAR1); 59 60 /* disable all INTs */ 61 writel(0, VIC_INT_EN0); 62 writel(0, VIC_INT_EN1); 63 64 /* don't use 1136 vic */ 65 writel(0, VIC_CONFIG); 66 67 writel(1, VIC_INT_MASTEREN); 68 69 /* enable IRQs */ 70 enable_irq(); 71 72 (void) readl(VIC_IRQ_VEC_RD); 73 } 74 75 void irq_unmask(unsigned n) 76 { 77 unsigned reg, bit; 78 79 reg = n > 31 ? VIC_INT_EN1 : VIC_INT_EN0; 80 bit = 1 << (n & 31); 81 82 writel(readl(reg) | bit, reg); 83 } 84 85 void irq_mask(unsigned n) 86 { 87 unsigned reg, bit; 88 89 reg = n > 31 ? VIC_INT_ENCLEAR1 : VIC_INT_ENCLEAR0; 90 bit = 1 << (n & 31); 91 92 writel(bit, reg); 93 } 94 95 void irq_install(unsigned n, irq_handler func, int edge) 96 { 97 unsigned reg, bit, tmp; 98 99 reg = n > 31 ? VIC_INT_TYPE1 : VIC_INT_TYPE0; 100 bit = 1 << (n & 31); 101 102 tmp = readl(reg); 103 if(edge) { 104 writel(tmp | bit, reg); 105 } else { 106 writel(tmp & (~bit), reg); 107 } 108 109 irq_vector_table[n] = func; 110 } 111 112