162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * arch/sh/boards/superh/microdev/irq.c 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com) 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * SuperH SH4-202 MicroDev board support. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/init.h> 1162306a36Sopenharmony_ci#include <linux/irq.h> 1262306a36Sopenharmony_ci#include <linux/interrupt.h> 1362306a36Sopenharmony_ci#include <asm/io.h> 1462306a36Sopenharmony_ci#include <mach/microdev.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */ 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_cistatic const struct { 1962306a36Sopenharmony_ci unsigned char fpgaIrq; 2062306a36Sopenharmony_ci unsigned char mapped; 2162306a36Sopenharmony_ci const char *name; 2262306a36Sopenharmony_ci} fpgaIrqTable[NUM_EXTERNAL_IRQS] = { 2362306a36Sopenharmony_ci { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */ 2462306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */ 2562306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */ 2662306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */ 2762306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */ 2862306a36Sopenharmony_ci { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */ 2962306a36Sopenharmony_ci { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */ 3062306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */ 3162306a36Sopenharmony_ci { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */ 3262306a36Sopenharmony_ci { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */ 3362306a36Sopenharmony_ci { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */ 3462306a36Sopenharmony_ci { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */ 3562306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */ 3662306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */ 3762306a36Sopenharmony_ci { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */ 3862306a36Sopenharmony_ci { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */ 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_KEYBOARD != 1) 4262306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for Keyboard! 4362306a36Sopenharmony_ci#endif 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_ETHERNET != 3) 4662306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for Ethernet! 4762306a36Sopenharmony_ci#endif 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_USB_HC != 7) 5062306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for USB! 5162306a36Sopenharmony_ci#endif 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_MOUSE != 12) 5462306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for PS/2 Mouse! 5562306a36Sopenharmony_ci#endif 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_IDE2 != 13) 5862306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for secondary IDE! 5962306a36Sopenharmony_ci#endif 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#if (MICRODEV_LINUX_IRQ_IDE1 != 14) 6262306a36Sopenharmony_ci# error Inconsistancy in defining the IRQ# for primary IDE! 6362306a36Sopenharmony_ci#endif 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_cistatic void disable_microdev_irq(struct irq_data *data) 6662306a36Sopenharmony_ci{ 6762306a36Sopenharmony_ci unsigned int irq = data->irq; 6862306a36Sopenharmony_ci unsigned int fpgaIrq; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci if (irq >= NUM_EXTERNAL_IRQS) 7162306a36Sopenharmony_ci return; 7262306a36Sopenharmony_ci if (!fpgaIrqTable[irq].mapped) 7362306a36Sopenharmony_ci return; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci fpgaIrq = fpgaIrqTable[irq].fpgaIrq; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci /* disable interrupts on the FPGA INTC register */ 7862306a36Sopenharmony_ci __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG); 7962306a36Sopenharmony_ci} 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_cistatic void enable_microdev_irq(struct irq_data *data) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci unsigned int irq = data->irq; 8462306a36Sopenharmony_ci unsigned long priorityReg, priorities, pri; 8562306a36Sopenharmony_ci unsigned int fpgaIrq; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci if (unlikely(irq >= NUM_EXTERNAL_IRQS)) 8862306a36Sopenharmony_ci return; 8962306a36Sopenharmony_ci if (unlikely(!fpgaIrqTable[irq].mapped)) 9062306a36Sopenharmony_ci return; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci pri = 15 - irq; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci fpgaIrq = fpgaIrqTable[irq].fpgaIrq; 9562306a36Sopenharmony_ci priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci /* set priority for the interrupt */ 9862306a36Sopenharmony_ci priorities = __raw_readl(priorityReg); 9962306a36Sopenharmony_ci priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq); 10062306a36Sopenharmony_ci priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri); 10162306a36Sopenharmony_ci __raw_writel(priorities, priorityReg); 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci /* enable interrupts on the FPGA INTC register */ 10462306a36Sopenharmony_ci __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG); 10562306a36Sopenharmony_ci} 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_cistatic struct irq_chip microdev_irq_type = { 10862306a36Sopenharmony_ci .name = "MicroDev-IRQ", 10962306a36Sopenharmony_ci .irq_unmask = enable_microdev_irq, 11062306a36Sopenharmony_ci .irq_mask = disable_microdev_irq, 11162306a36Sopenharmony_ci}; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* This function sets the desired irq handler to be a MicroDev type */ 11462306a36Sopenharmony_cistatic void __init make_microdev_irq(unsigned int irq) 11562306a36Sopenharmony_ci{ 11662306a36Sopenharmony_ci disable_irq_nosync(irq); 11762306a36Sopenharmony_ci irq_set_chip_and_handler(irq, µdev_irq_type, handle_level_irq); 11862306a36Sopenharmony_ci disable_microdev_irq(irq_get_irq_data(irq)); 11962306a36Sopenharmony_ci} 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciextern void __init init_microdev_irq(void) 12262306a36Sopenharmony_ci{ 12362306a36Sopenharmony_ci int i; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci /* disable interrupts on the FPGA INTC register */ 12662306a36Sopenharmony_ci __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci for (i = 0; i < NUM_EXTERNAL_IRQS; i++) 12962306a36Sopenharmony_ci make_microdev_irq(i); 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciextern void microdev_print_fpga_intc_status(void) 13362306a36Sopenharmony_ci{ 13462306a36Sopenharmony_ci volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG; 13562306a36Sopenharmony_ci volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG; 13662306a36Sopenharmony_ci volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0); 13762306a36Sopenharmony_ci volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8); 13862306a36Sopenharmony_ci volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16); 13962306a36Sopenharmony_ci volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24); 14062306a36Sopenharmony_ci volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG; 14162306a36Sopenharmony_ci volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n"); 14462306a36Sopenharmony_ci printk("FPGA_INTENB = 0x%08x\n", *intenb); 14562306a36Sopenharmony_ci printk("FPGA_INTDSB = 0x%08x\n", *intdsb); 14662306a36Sopenharmony_ci printk("FPGA_INTSRC = 0x%08x\n", *intsrc); 14762306a36Sopenharmony_ci printk("FPGA_INTREQ = 0x%08x\n", *intreq); 14862306a36Sopenharmony_ci printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria); 14962306a36Sopenharmony_ci printk("-------------------------------------------------------------------------------\n"); 15062306a36Sopenharmony_ci} 151