Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 1 | /* |
| 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 Porquet | 41a83e0 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 22 | #include <linux/irqchip.h> |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 23 | #include <linux/irqdomain.h> |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 24 | #include <linux/io.h> |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 25 | #include <linux/of.h> |
Shawn Guo | 8256aa7 | 2013-03-25 21:13:22 +0800 | [diff] [blame] | 26 | #include <linux/of_address.h> |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 27 | #include <linux/of_irq.h> |
Shawn Guo | cec6bae | 2013-03-25 21:20:05 +0800 | [diff] [blame] | 28 | #include <linux/stmp_device.h> |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 29 | #include <asm/exception.h> |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 30 | |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 31 | /* |
| 32 | * this device provide 4 offsets for each register: |
| 33 | * 0x0 - plain read write mode |
| 34 | * 0x4 - set mode, OR logic. |
| 35 | * 0x8 - clr mode, XOR logic. |
| 36 | * 0xc - togle mode. |
| 37 | */ |
| 38 | #define SET_REG 4 |
| 39 | #define CLR_REG 8 |
| 40 | |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 41 | #define HW_ICOLL_VECTOR 0x0000 |
| 42 | #define HW_ICOLL_LEVELACK 0x0010 |
| 43 | #define HW_ICOLL_CTRL 0x0020 |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 44 | #define HW_ICOLL_STAT_OFFSET 0x0070 |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 45 | #define HW_ICOLL_INTERRUPT0 0x0120 |
| 46 | #define HW_ICOLL_INTERRUPTn(n) ((n) * 0x10) |
| 47 | #define BM_ICOLL_INTR_ENABLE BIT(2) |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 48 | #define BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 0x1 |
| 49 | |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 50 | #define ICOLL_NUM_IRQS 128 |
| 51 | |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 52 | struct icoll_priv { |
| 53 | void __iomem *vector; |
| 54 | void __iomem *levelack; |
| 55 | void __iomem *ctrl; |
| 56 | void __iomem *stat; |
| 57 | void __iomem *intr; |
| 58 | }; |
| 59 | |
| 60 | static struct icoll_priv icoll_priv; |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 61 | static struct irq_domain *icoll_domain; |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 62 | |
Uwe Kleine-König | bf0c1118 | 2011-02-18 21:31:41 +0100 | [diff] [blame] | 63 | static void icoll_ack_irq(struct irq_data *d) |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 64 | { |
| 65 | /* |
| 66 | * The Interrupt Collector is able to prioritize irqs. |
| 67 | * Currently only level 0 is used. So acking can use |
| 68 | * BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 unconditionally. |
| 69 | */ |
| 70 | __raw_writel(BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0, |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 71 | icoll_priv.levelack); |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Uwe Kleine-König | bf0c1118 | 2011-02-18 21:31:41 +0100 | [diff] [blame] | 74 | static void icoll_mask_irq(struct irq_data *d) |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 75 | { |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 76 | __raw_writel(BM_ICOLL_INTR_ENABLE, |
| 77 | icoll_priv.intr + CLR_REG + HW_ICOLL_INTERRUPTn(d->hwirq)); |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 78 | } |
| 79 | |
Uwe Kleine-König | bf0c1118 | 2011-02-18 21:31:41 +0100 | [diff] [blame] | 80 | static void icoll_unmask_irq(struct irq_data *d) |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 81 | { |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 82 | __raw_writel(BM_ICOLL_INTR_ENABLE, |
| 83 | icoll_priv.intr + SET_REG + HW_ICOLL_INTERRUPTn(d->hwirq)); |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static struct irq_chip mxs_icoll_chip = { |
Uwe Kleine-König | bf0c1118 | 2011-02-18 21:31:41 +0100 | [diff] [blame] | 87 | .irq_ack = icoll_ack_irq, |
| 88 | .irq_mask = icoll_mask_irq, |
| 89 | .irq_unmask = icoll_unmask_irq, |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 92 | asmlinkage void __exception_irq_entry icoll_handle_irq(struct pt_regs *regs) |
| 93 | { |
| 94 | u32 irqnr; |
| 95 | |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 96 | irqnr = __raw_readl(icoll_priv.stat); |
| 97 | __raw_writel(irqnr, icoll_priv.vector); |
Marc Zyngier | b3410e5 | 2014-08-26 11:03:24 +0100 | [diff] [blame] | 98 | handle_domain_irq(icoll_domain, irqnr, regs); |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 99 | } |
| 100 | |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 101 | static int icoll_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 102 | irq_hw_number_t hw) |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 103 | { |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 104 | irq_set_chip_and_handler(virq, &mxs_icoll_chip, handle_level_irq); |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 105 | |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Krzysztof Kozlowski | 9600973 | 2015-04-27 21:54:24 +0900 | [diff] [blame] | 109 | static const struct irq_domain_ops icoll_irq_domain_ops = { |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 110 | .map = icoll_irq_domain_map, |
| 111 | .xlate = irq_domain_xlate_onecell, |
| 112 | }; |
| 113 | |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 114 | static void __init icoll_add_domain(struct device_node *np, |
| 115 | int num) |
| 116 | { |
| 117 | icoll_domain = irq_domain_add_linear(np, num, |
| 118 | &icoll_irq_domain_ops, NULL); |
| 119 | |
| 120 | if (!icoll_domain) |
| 121 | panic("%s: unable to create irq domain", np->full_name); |
| 122 | } |
| 123 | |
| 124 | static void __iomem * __init icoll_init_iobase(struct device_node *np) |
| 125 | { |
| 126 | void __iomem *icoll_base; |
| 127 | |
| 128 | icoll_base = of_io_request_and_map(np, 0, np->name); |
| 129 | if (!icoll_base) |
| 130 | panic("%s: unable to map resource", np->full_name); |
| 131 | return icoll_base; |
| 132 | } |
| 133 | |
Rob Herring | 10776b5 | 2014-05-12 11:37:07 -0500 | [diff] [blame] | 134 | static int __init icoll_of_init(struct device_node *np, |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 135 | struct device_node *interrupt_parent) |
| 136 | { |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 137 | void __iomem *icoll_base; |
| 138 | |
| 139 | icoll_base = icoll_init_iobase(np); |
| 140 | icoll_priv.vector = icoll_base + HW_ICOLL_VECTOR; |
| 141 | icoll_priv.levelack = icoll_base + HW_ICOLL_LEVELACK; |
| 142 | icoll_priv.ctrl = icoll_base + HW_ICOLL_CTRL; |
| 143 | icoll_priv.stat = icoll_base + HW_ICOLL_STAT_OFFSET; |
| 144 | icoll_priv.intr = icoll_base + HW_ICOLL_INTERRUPT0; |
Shawn Guo | 8256aa7 | 2013-03-25 21:13:22 +0800 | [diff] [blame] | 145 | |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 146 | /* |
| 147 | * Interrupt Collector reset, which initializes the priority |
| 148 | * for each irq to level 0. |
| 149 | */ |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 150 | stmp_reset_block(icoll_priv.ctrl); |
Shawn Guo | 289569f | 2010-12-18 21:39:28 +0800 | [diff] [blame] | 151 | |
Oleksij Rempel | 25e34b4 | 2015-10-12 21:15:33 +0200 | [diff] [blame^] | 152 | icoll_add_domain(np, ICOLL_NUM_IRQS); |
Oleksij Rempel | e59a845 | 2015-10-12 21:15:30 +0200 | [diff] [blame] | 153 | |
| 154 | return 0; |
Shawn Guo | 83a84ef | 2012-08-20 21:34:56 +0800 | [diff] [blame] | 155 | } |
Shawn Guo | 6a8e95b | 2013-03-25 21:34:51 +0800 | [diff] [blame] | 156 | IRQCHIP_DECLARE(mxs, "fsl,icoll", icoll_of_init); |