blob: 96148a7beba129ff84d557c437058dd06ec7395a [file] [log] [blame]
Shawn Guo289569f2010-12-18 21:39:28 +08001/*
2 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/irq.h>
Joel Porquet41a83e02015-07-07 17:11:46 -040022#include <linux/irqchip.h>
Shawn Guo83a84ef2012-08-20 21:34:56 +080023#include <linux/irqdomain.h>
Shawn Guo289569f2010-12-18 21:39:28 +080024#include <linux/io.h>
Shawn Guo83a84ef2012-08-20 21:34:56 +080025#include <linux/of.h>
Shawn Guo8256aa72013-03-25 21:13:22 +080026#include <linux/of_address.h>
Shawn Guo83a84ef2012-08-20 21:34:56 +080027#include <linux/of_irq.h>
Shawn Guocec6bae2013-03-25 21:20:05 +080028#include <linux/stmp_device.h>
Shawn Guo4e0a1b82012-08-20 10:14:56 +080029#include <asm/exception.h>
Shawn Guo289569f2010-12-18 21:39:28 +080030
31#define HW_ICOLL_VECTOR 0x0000
32#define HW_ICOLL_LEVELACK 0x0010
33#define HW_ICOLL_CTRL 0x0020
Shawn Guo4e0a1b82012-08-20 10:14:56 +080034#define HW_ICOLL_STAT_OFFSET 0x0070
Shawn Guo289569f2010-12-18 21:39:28 +080035#define HW_ICOLL_INTERRUPTn_SET(n) (0x0124 + (n) * 0x10)
36#define HW_ICOLL_INTERRUPTn_CLR(n) (0x0128 + (n) * 0x10)
37#define BM_ICOLL_INTERRUPTn_ENABLE 0x00000004
38#define BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 0x1
39
Shawn Guo83a84ef2012-08-20 21:34:56 +080040#define ICOLL_NUM_IRQS 128
41
Shawn Guo8256aa72013-03-25 21:13:22 +080042static void __iomem *icoll_base;
Shawn Guo83a84ef2012-08-20 21:34:56 +080043static struct irq_domain *icoll_domain;
Shawn Guo289569f2010-12-18 21:39:28 +080044
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010045static void icoll_ack_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080046{
47 /*
48 * The Interrupt Collector is able to prioritize irqs.
49 * Currently only level 0 is used. So acking can use
50 * BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 unconditionally.
51 */
52 __raw_writel(BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0,
53 icoll_base + HW_ICOLL_LEVELACK);
54}
55
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010056static void icoll_mask_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080057{
58 __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
Shawn Guo83a84ef2012-08-20 21:34:56 +080059 icoll_base + HW_ICOLL_INTERRUPTn_CLR(d->hwirq));
Shawn Guo289569f2010-12-18 21:39:28 +080060}
61
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010062static void icoll_unmask_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080063{
64 __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
Shawn Guo83a84ef2012-08-20 21:34:56 +080065 icoll_base + HW_ICOLL_INTERRUPTn_SET(d->hwirq));
Shawn Guo289569f2010-12-18 21:39:28 +080066}
67
68static struct irq_chip mxs_icoll_chip = {
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010069 .irq_ack = icoll_ack_irq,
70 .irq_mask = icoll_mask_irq,
71 .irq_unmask = icoll_unmask_irq,
Shawn Guo289569f2010-12-18 21:39:28 +080072};
73
Shawn Guo4e0a1b82012-08-20 10:14:56 +080074asmlinkage void __exception_irq_entry icoll_handle_irq(struct pt_regs *regs)
75{
76 u32 irqnr;
77
Markus Pargmannb5f83e9b2013-05-28 17:00:57 +020078 irqnr = __raw_readl(icoll_base + HW_ICOLL_STAT_OFFSET);
79 __raw_writel(irqnr, icoll_base + HW_ICOLL_VECTOR);
Marc Zyngierb3410e52014-08-26 11:03:24 +010080 handle_domain_irq(icoll_domain, irqnr, regs);
Shawn Guo4e0a1b82012-08-20 10:14:56 +080081}
82
Shawn Guo83a84ef2012-08-20 21:34:56 +080083static int icoll_irq_domain_map(struct irq_domain *d, unsigned int virq,
84 irq_hw_number_t hw)
Shawn Guo289569f2010-12-18 21:39:28 +080085{
Shawn Guo83a84ef2012-08-20 21:34:56 +080086 irq_set_chip_and_handler(virq, &mxs_icoll_chip, handle_level_irq);
Shawn Guo289569f2010-12-18 21:39:28 +080087
Shawn Guo83a84ef2012-08-20 21:34:56 +080088 return 0;
89}
90
Krzysztof Kozlowski96009732015-04-27 21:54:24 +090091static const struct irq_domain_ops icoll_irq_domain_ops = {
Shawn Guo83a84ef2012-08-20 21:34:56 +080092 .map = icoll_irq_domain_map,
93 .xlate = irq_domain_xlate_onecell,
94};
95
Rob Herring10776b52014-05-12 11:37:07 -050096static int __init icoll_of_init(struct device_node *np,
Shawn Guo83a84ef2012-08-20 21:34:56 +080097 struct device_node *interrupt_parent)
98{
Shawn Guo8256aa72013-03-25 21:13:22 +080099 icoll_base = of_iomap(np, 0);
Oleksij Rempele59a8452015-10-12 21:15:30 +0200100 if (!icoll_base)
101 panic("%s: unable to map resource", np->full_name);
Shawn Guo8256aa72013-03-25 21:13:22 +0800102
Shawn Guo289569f2010-12-18 21:39:28 +0800103 /*
104 * Interrupt Collector reset, which initializes the priority
105 * for each irq to level 0.
106 */
Shawn Guocec6bae2013-03-25 21:20:05 +0800107 stmp_reset_block(icoll_base + HW_ICOLL_CTRL);
Shawn Guo289569f2010-12-18 21:39:28 +0800108
Shawn Guo83a84ef2012-08-20 21:34:56 +0800109 icoll_domain = irq_domain_add_linear(np, ICOLL_NUM_IRQS,
110 &icoll_irq_domain_ops, NULL);
Oleksij Rempele59a8452015-10-12 21:15:30 +0200111 if (!icoll_domain)
112 panic("%s: unable to create irqdomain", np->full_name);
113
114 return 0;
Shawn Guo83a84ef2012-08-20 21:34:56 +0800115}
Shawn Guo6a8e95b2013-03-25 21:34:51 +0800116IRQCHIP_DECLARE(mxs, "fsl,icoll", icoll_of_init);