18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2001 MontaVista Software Inc. 38c2ecf20Sopenharmony_ci * Author: MontaVista Software, Inc. 48c2ecf20Sopenharmony_ci * ahennessy@mvista.com 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 78c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 88c2ecf20Sopenharmony_ci * for more details. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 2000-2001 Toshiba Corporation 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 138c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License as published by the 148c2ecf20Sopenharmony_ci * Free Software Foundation; either version 2 of the License, or (at your 158c2ecf20Sopenharmony_ci * option) any later version. 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 188c2ecf20Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 198c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 208c2ecf20Sopenharmony_ci * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 218c2ecf20Sopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 228c2ecf20Sopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 238c2ecf20Sopenharmony_ci * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 248c2ecf20Sopenharmony_ci * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 268c2ecf20Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License along 298c2ecf20Sopenharmony_ci * with this program; if not, write to the Free Software Foundation, Inc., 308c2ecf20Sopenharmony_ci * 675 Mass Ave, Cambridge, MA 02139, USA. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#include <linux/init.h> 338c2ecf20Sopenharmony_ci#include <linux/types.h> 348c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 358c2ecf20Sopenharmony_ci#include <linux/irq.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include <asm/io.h> 388c2ecf20Sopenharmony_ci#include <asm/mipsregs.h> 398c2ecf20Sopenharmony_ci#include <asm/txx9/generic.h> 408c2ecf20Sopenharmony_ci#include <asm/txx9/jmr3927.h> 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#if JMR3927_IRQ_END > NR_IRQS 438c2ecf20Sopenharmony_ci#error JMR3927_IRQ_END > NR_IRQS 448c2ecf20Sopenharmony_ci#endif 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* 478c2ecf20Sopenharmony_ci * CP0_STATUS is a thread's resource (saved/restored on context switch). 488c2ecf20Sopenharmony_ci * So disable_irq/enable_irq MUST handle IOC/IRC registers. 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_cistatic void mask_irq_ioc(struct irq_data *d) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci /* 0: mask */ 538c2ecf20Sopenharmony_ci unsigned int irq_nr = d->irq - JMR3927_IRQ_IOC; 548c2ecf20Sopenharmony_ci unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR); 558c2ecf20Sopenharmony_ci unsigned int bit = 1 << irq_nr; 568c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(imask & ~bit, JMR3927_IOC_INTM_ADDR); 578c2ecf20Sopenharmony_ci /* flush write buffer */ 588c2ecf20Sopenharmony_ci (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR); 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_cistatic void unmask_irq_ioc(struct irq_data *d) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci /* 0: mask */ 638c2ecf20Sopenharmony_ci unsigned int irq_nr = d->irq - JMR3927_IRQ_IOC; 648c2ecf20Sopenharmony_ci unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR); 658c2ecf20Sopenharmony_ci unsigned int bit = 1 << irq_nr; 668c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(imask | bit, JMR3927_IOC_INTM_ADDR); 678c2ecf20Sopenharmony_ci /* flush write buffer */ 688c2ecf20Sopenharmony_ci (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic int jmr3927_ioc_irqroute(void) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci unsigned char istat = jmr3927_ioc_reg_in(JMR3927_IOC_INTS2_ADDR); 748c2ecf20Sopenharmony_ci int i; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci for (i = 0; i < JMR3927_NR_IRQ_IOC; i++) { 778c2ecf20Sopenharmony_ci if (istat & (1 << i)) 788c2ecf20Sopenharmony_ci return JMR3927_IRQ_IOC + i; 798c2ecf20Sopenharmony_ci } 808c2ecf20Sopenharmony_ci return -1; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic int jmr3927_irq_dispatch(int pending) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci int irq; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci if ((pending & CAUSEF_IP7) == 0) 888c2ecf20Sopenharmony_ci return -1; 898c2ecf20Sopenharmony_ci irq = (pending >> CAUSEB_IP2) & 0x0f; 908c2ecf20Sopenharmony_ci irq += JMR3927_IRQ_IRC; 918c2ecf20Sopenharmony_ci if (irq == JMR3927_IRQ_IOCINT) 928c2ecf20Sopenharmony_ci irq = jmr3927_ioc_irqroute(); 938c2ecf20Sopenharmony_ci return irq; 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic struct irq_chip jmr3927_irq_ioc = { 978c2ecf20Sopenharmony_ci .name = "jmr3927_ioc", 988c2ecf20Sopenharmony_ci .irq_mask = mask_irq_ioc, 998c2ecf20Sopenharmony_ci .irq_unmask = unmask_irq_ioc, 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_civoid __init jmr3927_irq_setup(void) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci int i; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci txx9_irq_dispatch = jmr3927_irq_dispatch; 1078c2ecf20Sopenharmony_ci /* Now, interrupt control disabled, */ 1088c2ecf20Sopenharmony_ci /* all IRC interrupts are masked, */ 1098c2ecf20Sopenharmony_ci /* all IRC interrupt mode are Low Active. */ 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci /* mask all IOC interrupts */ 1128c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(0, JMR3927_IOC_INTM_ADDR); 1138c2ecf20Sopenharmony_ci /* setup IOC interrupt mode (SOFT:High Active, Others:Low Active) */ 1148c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(JMR3927_IOC_INTF_SOFT, JMR3927_IOC_INTP_ADDR); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci /* clear PCI Soft interrupts */ 1178c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(0, JMR3927_IOC_INTS1_ADDR); 1188c2ecf20Sopenharmony_ci /* clear PCI Reset interrupts */ 1198c2ecf20Sopenharmony_ci jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci tx3927_irq_init(); 1228c2ecf20Sopenharmony_ci for (i = JMR3927_IRQ_IOC; i < JMR3927_IRQ_IOC + JMR3927_NR_IRQ_IOC; i++) 1238c2ecf20Sopenharmony_ci irq_set_chip_and_handler(i, &jmr3927_irq_ioc, 1248c2ecf20Sopenharmony_ci handle_level_irq); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci /* setup IOC interrupt 1 (PCI, MODEM) */ 1278c2ecf20Sopenharmony_ci irq_set_chained_handler(JMR3927_IRQ_IOCINT, handle_simple_irq); 1288c2ecf20Sopenharmony_ci} 129