Path: blob/master/arch/sh/boards/mach-dreamcast/irq.c
15126 views
/*1* arch/sh/boards/dreamcast/irq.c2*3* Holly IRQ support for the Sega Dreamcast.4*5* Copyright (c) 2001, 2002 M. R. Brown <[email protected]>6*7* This file is part of the LinuxDC project (www.linuxdc.org)8* Released under the terms of the GNU GPL v2.09*/1011#include <linux/irq.h>12#include <linux/io.h>13#include <asm/irq.h>14#include <mach/sysasic.h>1516/*17* Dreamcast System ASIC Hardware Events -18*19* The Dreamcast's System ASIC (a.k.a. Holly) is responsible for receiving20* hardware events from system peripherals and triggering an SH7750 IRQ.21* Hardware events can trigger IRQs 13, 11, or 9 depending on which bits are22* set in the Event Mask Registers (EMRs). When a hardware event is23* triggered, its corresponding bit in the Event Status Registers (ESRs)24* is set, and that bit should be rewritten to the ESR to acknowledge that25* event.26*27* There are three 32-bit ESRs located at 0xa05f6900 - 0xa05f6908. Event28* types can be found in arch/sh/include/mach-dreamcast/mach/sysasic.h.29* There are three groups of EMRs that parallel the ESRs. Each EMR group30* corresponds to an IRQ, so 0xa05f6910 - 0xa05f6918 triggers IRQ 13,31* 0xa05f6920 - 0xa05f6928 triggers IRQ 11, and 0xa05f6930 - 0xa05f693832* triggers IRQ 9.33*34* In the kernel, these events are mapped to virtual IRQs so that drivers can35* respond to them as they would a normal interrupt. In order to keep this36* mapping simple, the events are mapped as:37*38* 6900/6910 - Events 0-31, IRQ 1339* 6904/6924 - Events 32-63, IRQ 1140* 6908/6938 - Events 64-95, IRQ 941*42*/4344#define ESR_BASE 0x005f6900 /* Base event status register */45#define EMR_BASE 0x005f6910 /* Base event mask register */4647/*48* Helps us determine the EMR group that this event belongs to: 0 = 0x6910,49* 1 = 0x6920, 2 = 0x6930; also determine the event offset.50*/51#define LEVEL(event) (((event) - HW_EVENT_IRQ_BASE) / 32)5253/* Return the hardware event's bit position within the EMR/ESR */54#define EVENT_BIT(event) (((event) - HW_EVENT_IRQ_BASE) & 31)5556/*57* For each of these *_irq routines, the IRQ passed in is the virtual IRQ58* (logically mapped to the corresponding bit for the hardware event).59*/6061/* Disable the hardware event by masking its bit in its EMR */62static inline void disable_systemasic_irq(struct irq_data *data)63{64unsigned int irq = data->irq;65__u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);66__u32 mask;6768mask = inl(emr);69mask &= ~(1 << EVENT_BIT(irq));70outl(mask, emr);71}7273/* Enable the hardware event by setting its bit in its EMR */74static inline void enable_systemasic_irq(struct irq_data *data)75{76unsigned int irq = data->irq;77__u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);78__u32 mask;7980mask = inl(emr);81mask |= (1 << EVENT_BIT(irq));82outl(mask, emr);83}8485/* Acknowledge a hardware event by writing its bit back to its ESR */86static void mask_ack_systemasic_irq(struct irq_data *data)87{88unsigned int irq = data->irq;89__u32 esr = ESR_BASE + (LEVEL(irq) << 2);90disable_systemasic_irq(data);91outl((1 << EVENT_BIT(irq)), esr);92}9394struct irq_chip systemasic_int = {95.name = "System ASIC",96.irq_mask = disable_systemasic_irq,97.irq_mask_ack = mask_ack_systemasic_irq,98.irq_unmask = enable_systemasic_irq,99};100101/*102* Map the hardware event indicated by the processor IRQ to a virtual IRQ.103*/104int systemasic_irq_demux(int irq)105{106__u32 emr, esr, status, level;107__u32 j, bit;108109switch (irq) {110case 13:111level = 0;112break;113case 11:114level = 1;115break;116case 9:117level = 2;118break;119default:120return irq;121}122emr = EMR_BASE + (level << 4) + (level << 2);123esr = ESR_BASE + (level << 2);124125/* Mask the ESR to filter any spurious, unwanted interrupts */126status = inl(esr);127status &= inl(emr);128129/* Now scan and find the first set bit as the event to map */130for (bit = 1, j = 0; j < 32; bit <<= 1, j++) {131if (status & bit) {132irq = HW_EVENT_IRQ_BASE + j + (level << 5);133return irq;134}135}136137/* Not reached */138return irq;139}140141void systemasic_irq_init(void)142{143int i, nid = cpu_to_node(boot_cpu_data);144145/* Assign all virtual IRQs to the System ASIC int. handler */146for (i = HW_EVENT_IRQ_BASE; i < HW_EVENT_IRQ_MAX; i++) {147unsigned int irq;148149irq = create_irq_nr(i, nid);150if (unlikely(irq == 0)) {151pr_err("%s: failed hooking irq %d for systemasic\n",152__func__, i);153return;154}155156if (unlikely(irq != i)) {157pr_err("%s: got irq %d but wanted %d, bailing.\n",158__func__, irq, i);159destroy_irq(irq);160return;161}162163irq_set_chip_and_handler(i, &systemasic_int, handle_level_irq);164}165}166167168