xref: /linux/arch/mips/kernel/irq_txx9.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
18420fd00SAtsushi Nemoto /*
28420fd00SAtsushi Nemoto  * Based on linux/arch/mips/jmr3927/rbhma3100/irq.c,
38420fd00SAtsushi Nemoto  *	    linux/arch/mips/tx4927/common/tx4927_irq.c,
48420fd00SAtsushi Nemoto  *	    linux/arch/mips/tx4938/common/irq.c
58420fd00SAtsushi Nemoto  *
68420fd00SAtsushi Nemoto  * Copyright 2001, 2003-2005 MontaVista Software Inc.
78420fd00SAtsushi Nemoto  * Author: MontaVista Software, Inc.
88420fd00SAtsushi Nemoto  *	   ahennessy@mvista.com
98420fd00SAtsushi Nemoto  *	   source@mvista.com
108420fd00SAtsushi Nemoto  * Copyright (C) 2000-2001 Toshiba Corporation
118420fd00SAtsushi Nemoto  *
128420fd00SAtsushi Nemoto  * This file is subject to the terms and conditions of the GNU General Public
138420fd00SAtsushi Nemoto  * License.  See the file "COPYING" in the main directory of this archive
148420fd00SAtsushi Nemoto  * for more details.
158420fd00SAtsushi Nemoto  */
168420fd00SAtsushi Nemoto #include <linux/init.h>
178420fd00SAtsushi Nemoto #include <linux/interrupt.h>
188420fd00SAtsushi Nemoto #include <linux/types.h>
19ca4d3e67SDavid Howells #include <linux/irq.h>
208420fd00SAtsushi Nemoto #include <asm/txx9irq.h>
218420fd00SAtsushi Nemoto 
228420fd00SAtsushi Nemoto struct txx9_irc_reg {
238420fd00SAtsushi Nemoto 	u32 cer;
248420fd00SAtsushi Nemoto 	u32 cr[2];
258420fd00SAtsushi Nemoto 	u32 unused0;
268420fd00SAtsushi Nemoto 	u32 ilr[8];
278420fd00SAtsushi Nemoto 	u32 unused1[4];
288420fd00SAtsushi Nemoto 	u32 imr;
298420fd00SAtsushi Nemoto 	u32 unused2[7];
308420fd00SAtsushi Nemoto 	u32 scr;
318420fd00SAtsushi Nemoto 	u32 unused3[7];
328420fd00SAtsushi Nemoto 	u32 ssr;
338420fd00SAtsushi Nemoto 	u32 unused4[7];
348420fd00SAtsushi Nemoto 	u32 csr;
358420fd00SAtsushi Nemoto };
368420fd00SAtsushi Nemoto 
378420fd00SAtsushi Nemoto /* IRCER : Int. Control Enable */
388420fd00SAtsushi Nemoto #define TXx9_IRCER_ICE	0x00000001
398420fd00SAtsushi Nemoto 
408420fd00SAtsushi Nemoto /* IRCR : Int. Control */
418420fd00SAtsushi Nemoto #define TXx9_IRCR_LOW	0x00000000
428420fd00SAtsushi Nemoto #define TXx9_IRCR_HIGH	0x00000001
438420fd00SAtsushi Nemoto #define TXx9_IRCR_DOWN	0x00000002
448420fd00SAtsushi Nemoto #define TXx9_IRCR_UP	0x00000003
458420fd00SAtsushi Nemoto #define TXx9_IRCR_EDGE(cr)	((cr) & 0x00000002)
468420fd00SAtsushi Nemoto 
478420fd00SAtsushi Nemoto /* IRSCR : Int. Status Control */
488420fd00SAtsushi Nemoto #define TXx9_IRSCR_EIClrE	0x00000100
498420fd00SAtsushi Nemoto #define TXx9_IRSCR_EIClr_MASK	0x0000000f
508420fd00SAtsushi Nemoto 
518420fd00SAtsushi Nemoto /* IRCSR : Int. Current Status */
528420fd00SAtsushi Nemoto #define TXx9_IRCSR_IF	0x00010000
538420fd00SAtsushi Nemoto #define TXx9_IRCSR_ILV_MASK	0x00000700
548420fd00SAtsushi Nemoto #define TXx9_IRCSR_IVL_MASK	0x0000001f
558420fd00SAtsushi Nemoto 
568420fd00SAtsushi Nemoto #define irc_dlevel	0
578420fd00SAtsushi Nemoto #define irc_elevel	1
588420fd00SAtsushi Nemoto 
598420fd00SAtsushi Nemoto static struct txx9_irc_reg __iomem *txx9_ircptr __read_mostly;
608420fd00SAtsushi Nemoto 
618420fd00SAtsushi Nemoto static struct {
628420fd00SAtsushi Nemoto 	unsigned char level;
638420fd00SAtsushi Nemoto 	unsigned char mode;
648420fd00SAtsushi Nemoto } txx9irq[TXx9_MAX_IR] __read_mostly;
658420fd00SAtsushi Nemoto 
txx9_irq_unmask(struct irq_data * d)660e9c4ec6SThomas Gleixner static void txx9_irq_unmask(struct irq_data *d)
678420fd00SAtsushi Nemoto {
680e9c4ec6SThomas Gleixner 	unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
698420fd00SAtsushi Nemoto 	u32 __iomem *ilrp = &txx9_ircptr->ilr[(irq_nr % 16 ) / 2];
708420fd00SAtsushi Nemoto 	int ofs = irq_nr / 16 * 16 + (irq_nr & 1) * 8;
718420fd00SAtsushi Nemoto 
728420fd00SAtsushi Nemoto 	__raw_writel((__raw_readl(ilrp) & ~(0xff << ofs))
738420fd00SAtsushi Nemoto 		     | (txx9irq[irq_nr].level << ofs),
748420fd00SAtsushi Nemoto 		     ilrp);
758420fd00SAtsushi Nemoto }
768420fd00SAtsushi Nemoto 
txx9_irq_mask(struct irq_data * d)770e9c4ec6SThomas Gleixner static inline void txx9_irq_mask(struct irq_data *d)
788420fd00SAtsushi Nemoto {
790e9c4ec6SThomas Gleixner 	unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
808420fd00SAtsushi Nemoto 	u32 __iomem *ilrp = &txx9_ircptr->ilr[(irq_nr % 16) / 2];
818420fd00SAtsushi Nemoto 	int ofs = irq_nr / 16 * 16 + (irq_nr & 1) * 8;
828420fd00SAtsushi Nemoto 
838420fd00SAtsushi Nemoto 	__raw_writel((__raw_readl(ilrp) & ~(0xff << ofs))
848420fd00SAtsushi Nemoto 		     | (irc_dlevel << ofs),
858420fd00SAtsushi Nemoto 		     ilrp);
868420fd00SAtsushi Nemoto 	mmiowb();
878420fd00SAtsushi Nemoto }
888420fd00SAtsushi Nemoto 
txx9_irq_mask_ack(struct irq_data * d)890e9c4ec6SThomas Gleixner static void txx9_irq_mask_ack(struct irq_data *d)
908420fd00SAtsushi Nemoto {
910e9c4ec6SThomas Gleixner 	unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
928420fd00SAtsushi Nemoto 
930e9c4ec6SThomas Gleixner 	txx9_irq_mask(d);
948420fd00SAtsushi Nemoto 	/* clear edge detection */
955d3fdeacSAtsushi Nemoto 	if (unlikely(TXx9_IRCR_EDGE(txx9irq[irq_nr].mode)))
965d3fdeacSAtsushi Nemoto 		__raw_writel(TXx9_IRSCR_EIClrE | irq_nr, &txx9_ircptr->scr);
978420fd00SAtsushi Nemoto }
988420fd00SAtsushi Nemoto 
txx9_irq_set_type(struct irq_data * d,unsigned int flow_type)990e9c4ec6SThomas Gleixner static int txx9_irq_set_type(struct irq_data *d, unsigned int flow_type)
1008420fd00SAtsushi Nemoto {
1010e9c4ec6SThomas Gleixner 	unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
1028420fd00SAtsushi Nemoto 	u32 cr;
1038420fd00SAtsushi Nemoto 	u32 __iomem *crp;
1048420fd00SAtsushi Nemoto 	int ofs;
1058420fd00SAtsushi Nemoto 	int mode;
1068420fd00SAtsushi Nemoto 
1078420fd00SAtsushi Nemoto 	if (flow_type & IRQF_TRIGGER_PROBE)
1088420fd00SAtsushi Nemoto 		return 0;
1098420fd00SAtsushi Nemoto 	switch (flow_type & IRQF_TRIGGER_MASK) {
1108420fd00SAtsushi Nemoto 	case IRQF_TRIGGER_RISING:	mode = TXx9_IRCR_UP;	break;
1118420fd00SAtsushi Nemoto 	case IRQF_TRIGGER_FALLING:	mode = TXx9_IRCR_DOWN;	break;
1128420fd00SAtsushi Nemoto 	case IRQF_TRIGGER_HIGH: mode = TXx9_IRCR_HIGH;	break;
1138420fd00SAtsushi Nemoto 	case IRQF_TRIGGER_LOW:	mode = TXx9_IRCR_LOW;	break;
1148420fd00SAtsushi Nemoto 	default:
1158420fd00SAtsushi Nemoto 		return -EINVAL;
1168420fd00SAtsushi Nemoto 	}
1178420fd00SAtsushi Nemoto 	crp = &txx9_ircptr->cr[(unsigned int)irq_nr / 8];
1188420fd00SAtsushi Nemoto 	cr = __raw_readl(crp);
1198420fd00SAtsushi Nemoto 	ofs = (irq_nr & (8 - 1)) * 2;
1208420fd00SAtsushi Nemoto 	cr &= ~(0x3 << ofs);
1218420fd00SAtsushi Nemoto 	cr |= (mode & 0x3) << ofs;
1228420fd00SAtsushi Nemoto 	__raw_writel(cr, crp);
1238420fd00SAtsushi Nemoto 	txx9irq[irq_nr].mode = mode;
1248420fd00SAtsushi Nemoto 	return 0;
1258420fd00SAtsushi Nemoto }
1268420fd00SAtsushi Nemoto 
1278420fd00SAtsushi Nemoto static struct irq_chip txx9_irq_chip = {
1288420fd00SAtsushi Nemoto 	.name		= "TXX9",
1290e9c4ec6SThomas Gleixner 	.irq_ack	= txx9_irq_mask_ack,
1300e9c4ec6SThomas Gleixner 	.irq_mask	= txx9_irq_mask,
1310e9c4ec6SThomas Gleixner 	.irq_mask_ack	= txx9_irq_mask_ack,
1320e9c4ec6SThomas Gleixner 	.irq_unmask	= txx9_irq_unmask,
1330e9c4ec6SThomas Gleixner 	.irq_set_type	= txx9_irq_set_type,
1348420fd00SAtsushi Nemoto };
1358420fd00SAtsushi Nemoto 
txx9_irq_init(unsigned long baseaddr)1368420fd00SAtsushi Nemoto void __init txx9_irq_init(unsigned long baseaddr)
1378420fd00SAtsushi Nemoto {
1388420fd00SAtsushi Nemoto 	int i;
1398420fd00SAtsushi Nemoto 
1408420fd00SAtsushi Nemoto 	txx9_ircptr = ioremap(baseaddr, sizeof(struct txx9_irc_reg));
1418420fd00SAtsushi Nemoto 	for (i = 0; i < TXx9_MAX_IR; i++) {
1428420fd00SAtsushi Nemoto 		txx9irq[i].level = 4; /* middle level */
1438420fd00SAtsushi Nemoto 		txx9irq[i].mode = TXx9_IRCR_LOW;
144*e4ec7989SThomas Gleixner 		irq_set_chip_and_handler(TXX9_IRQ_BASE + i, &txx9_irq_chip,
145*e4ec7989SThomas Gleixner 					 handle_level_irq);
1468420fd00SAtsushi Nemoto 	}
1478420fd00SAtsushi Nemoto 
1488420fd00SAtsushi Nemoto 	/* mask all IRC interrupts */
1498420fd00SAtsushi Nemoto 	__raw_writel(0, &txx9_ircptr->imr);
1508420fd00SAtsushi Nemoto 	for (i = 0; i < 8; i++)
1518420fd00SAtsushi Nemoto 		__raw_writel(0, &txx9_ircptr->ilr[i]);
1528420fd00SAtsushi Nemoto 	/* setup IRC interrupt mode (Low Active) */
1538420fd00SAtsushi Nemoto 	for (i = 0; i < 2; i++)
1548420fd00SAtsushi Nemoto 		__raw_writel(0, &txx9_ircptr->cr[i]);
1558420fd00SAtsushi Nemoto 	/* enable interrupt control */
1568420fd00SAtsushi Nemoto 	__raw_writel(TXx9_IRCER_ICE, &txx9_ircptr->cer);
1578420fd00SAtsushi Nemoto 	__raw_writel(irc_elevel, &txx9_ircptr->imr);
1588420fd00SAtsushi Nemoto }
1598420fd00SAtsushi Nemoto 
txx9_irq_set_pri(int irc_irq,int new_pri)1608420fd00SAtsushi Nemoto int __init txx9_irq_set_pri(int irc_irq, int new_pri)
1618420fd00SAtsushi Nemoto {
1628420fd00SAtsushi Nemoto 	int old_pri;
1638420fd00SAtsushi Nemoto 
1648420fd00SAtsushi Nemoto 	if ((unsigned int)irc_irq >= TXx9_MAX_IR)
1658420fd00SAtsushi Nemoto 		return 0;
1668420fd00SAtsushi Nemoto 	old_pri = txx9irq[irc_irq].level;
1678420fd00SAtsushi Nemoto 	txx9irq[irc_irq].level = new_pri;
1688420fd00SAtsushi Nemoto 	return old_pri;
1698420fd00SAtsushi Nemoto }
1708420fd00SAtsushi Nemoto 
txx9_irq(void)1718420fd00SAtsushi Nemoto int txx9_irq(void)
1728420fd00SAtsushi Nemoto {
1738420fd00SAtsushi Nemoto 	u32 csr = __raw_readl(&txx9_ircptr->csr);
1748420fd00SAtsushi Nemoto 
1758420fd00SAtsushi Nemoto 	if (likely(!(csr & TXx9_IRCSR_IF)))
1768420fd00SAtsushi Nemoto 		return TXX9_IRQ_BASE + (csr & (TXx9_MAX_IR - 1));
1778420fd00SAtsushi Nemoto 	return -1;
1788420fd00SAtsushi Nemoto }
179