blob: fd45ffc48340b898cac839d6be1d5e038693d52a [file] [log] [blame]
Paul Mundtbc8fb5d2006-09-27 18:09:34 +09001/*
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +09002 * linux/arch/sh/boards/se/7343/irq.c
Paul Mundtbc8fb5d2006-09-27 18:09:34 +09003 *
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +09004 * Copyright (C) 2008 Yoshihiro Shimoda
5 *
6 * Based on linux/arch/sh/boards/se/7722/irq.c
7 * Copyright (C) 2007 Nobuhiro Iwamatsu
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090012 */
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090013#include <linux/init.h>
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090014#include <linux/irq.h>
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090015#include <linux/interrupt.h>
Paul Mundt939a24a2008-07-29 21:41:37 +090016#include <linux/io.h>
17#include <mach-se/mach/se7343.h>
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090018
Paul Mundt53e6d8e2010-01-12 13:37:04 +090019unsigned int se7343_fpga_irq[SE7343_FPGA_IRQ_NR] = { 0, };
20
Paul Mundt15ff2c62010-10-27 15:30:07 +090021static void disable_se7343_irq(struct irq_data *data)
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090022{
Paul Mundt15ff2c62010-10-27 15:30:07 +090023 unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
Paul Mundt9d56dd32010-01-26 12:58:40 +090024 __raw_writew(__raw_readw(PA_CPLD_IMSK) | 1 << bit, PA_CPLD_IMSK);
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090025}
26
Paul Mundt15ff2c62010-10-27 15:30:07 +090027static void enable_se7343_irq(struct irq_data *data)
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090028{
Paul Mundt15ff2c62010-10-27 15:30:07 +090029 unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
Paul Mundt9d56dd32010-01-26 12:58:40 +090030 __raw_writew(__raw_readw(PA_CPLD_IMSK) & ~(1 << bit), PA_CPLD_IMSK);
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090031}
32
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090033static struct irq_chip se7343_irq_chip __read_mostly = {
Paul Mundt15ff2c62010-10-27 15:30:07 +090034 .name = "SE7343-FPGA",
35 .irq_mask = disable_se7343_irq,
36 .irq_unmask = enable_se7343_irq,
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090037};
38
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090039static void se7343_irq_demux(unsigned int irq, struct irq_desc *desc)
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090040{
Paul Mundt9d56dd32010-01-26 12:58:40 +090041 unsigned short intv = __raw_readw(PA_CPLD_ST);
Paul Mundt53e6d8e2010-01-12 13:37:04 +090042 unsigned int ext_irq = 0;
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090043
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090044 intv &= (1 << SE7343_FPGA_IRQ_NR) - 1;
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090045
Paul Mundt53e6d8e2010-01-12 13:37:04 +090046 for (; intv; intv >>= 1, ext_irq++) {
47 if (!(intv & 1))
48 continue;
49
50 generic_handle_irq(se7343_fpga_irq[ext_irq]);
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090051 }
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090052}
53
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090054/*
55 * Initialize IRQ setting
56 */
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090057void __init init_7343se_IRQ(void)
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090058{
Paul Mundt53e6d8e2010-01-12 13:37:04 +090059 int i, irq;
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090060
Paul Mundt9d56dd32010-01-26 12:58:40 +090061 __raw_writew(0, PA_CPLD_IMSK); /* disable all irqs */
62 __raw_writew(0x2000, 0xb03fffec); /* mrshpc irq enable */
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090063
Paul Mundt53e6d8e2010-01-12 13:37:04 +090064 for (i = 0; i < SE7343_FPGA_IRQ_NR; i++) {
65 irq = create_irq();
66 if (irq < 0)
67 return;
68 se7343_fpga_irq[i] = irq;
69
Thomas Gleixnerfcb89182011-03-24 16:31:17 +010070 irq_set_chip_and_handler_name(se7343_fpga_irq[i],
Yoshihiro Shimodacafd63b2008-07-07 21:11:54 +090071 &se7343_irq_chip,
Thomas Gleixnerfcb89182011-03-24 16:31:17 +010072 handle_level_irq,
73 "level");
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090074
Thomas Gleixnerfcb89182011-03-24 16:31:17 +010075 irq_set_chip_data(se7343_fpga_irq[i], (void *)i);
Paul Mundt53e6d8e2010-01-12 13:37:04 +090076 }
77
Thomas Gleixnerfcb89182011-03-24 16:31:17 +010078 irq_set_chained_handler(IRQ0_IRQ, se7343_irq_demux);
79 irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
80 irq_set_chained_handler(IRQ1_IRQ, se7343_irq_demux);
81 irq_set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
82 irq_set_chained_handler(IRQ4_IRQ, se7343_irq_demux);
83 irq_set_irq_type(IRQ4_IRQ, IRQ_TYPE_LEVEL_LOW);
84 irq_set_chained_handler(IRQ5_IRQ, se7343_irq_demux);
85 irq_set_irq_type(IRQ5_IRQ, IRQ_TYPE_LEVEL_LOW);
Paul Mundtbc8fb5d2006-09-27 18:09:34 +090086}