Thomas Gleixner | a636cd6 | 2019-05-19 15:51:34 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 2 | /* |
| 3 | * interrupt controller support for CSR SiRFprimaII |
| 4 | * |
| 5 | * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company. |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/io.h> |
| 10 | #include <linux/irq.h> |
| 11 | #include <linux/of.h> |
| 12 | #include <linux/of_address.h> |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 13 | #include <linux/irqchip.h> |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 14 | #include <linux/irqdomain.h> |
| 15 | #include <linux/syscore_ops.h> |
| 16 | #include <asm/mach/irq.h> |
| 17 | #include <asm/exception.h> |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 18 | |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 19 | #define SIRFSOC_INT_RISC_MASK0 0x0018 |
| 20 | #define SIRFSOC_INT_RISC_MASK1 0x001C |
| 21 | #define SIRFSOC_INT_RISC_LEVEL0 0x0020 |
| 22 | #define SIRFSOC_INT_RISC_LEVEL1 0x0024 |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 23 | #define SIRFSOC_INIT_IRQ_ID 0x0038 |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 24 | #define SIRFSOC_INT_BASE_OFFSET 0x0004 |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 25 | |
Barry Song | 29eb51a | 2013-08-06 13:37:13 +0800 | [diff] [blame] | 26 | #define SIRFSOC_NUM_IRQS 64 |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 27 | #define SIRFSOC_NUM_BANKS (SIRFSOC_NUM_IRQS / 32) |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 28 | |
| 29 | static struct irq_domain *sirfsoc_irqdomain; |
| 30 | |
Ben Dooks | 4a3691c | 2016-06-07 13:18:30 +0100 | [diff] [blame] | 31 | static void __iomem *sirfsoc_irq_get_regbase(void) |
| 32 | { |
| 33 | return (void __iomem __force *)sirfsoc_irqdomain->host_data; |
| 34 | } |
| 35 | |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 36 | static __init void sirfsoc_alloc_gc(void __iomem *base) |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 37 | { |
Barry Song | 29eb51a | 2013-08-06 13:37:13 +0800 | [diff] [blame] | 38 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; |
Barry Song | a87010e | 2014-01-03 11:34:46 +0800 | [diff] [blame] | 39 | unsigned int set = IRQ_LEVEL; |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 40 | struct irq_chip_generic *gc; |
| 41 | struct irq_chip_type *ct; |
| 42 | int i; |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 43 | |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 44 | irq_alloc_domain_generic_chips(sirfsoc_irqdomain, 32, 1, "irq_sirfsoc", |
| 45 | handle_level_irq, clr, set, |
| 46 | IRQ_GC_INIT_MASK_CACHE); |
Barry Song | 29eb51a | 2013-08-06 13:37:13 +0800 | [diff] [blame] | 47 | |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 48 | for (i = 0; i < SIRFSOC_NUM_BANKS; i++) { |
| 49 | gc = irq_get_domain_generic_chip(sirfsoc_irqdomain, i * 32); |
| 50 | gc->reg_base = base + i * SIRFSOC_INT_BASE_OFFSET; |
| 51 | ct = gc->chip_types; |
| 52 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 53 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
| 54 | ct->regs.mask = SIRFSOC_INT_RISC_MASK0; |
| 55 | } |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 58 | static void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs) |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 59 | { |
Ben Dooks | 4a3691c | 2016-06-07 13:18:30 +0100 | [diff] [blame] | 60 | void __iomem *base = sirfsoc_irq_get_regbase(); |
Marc Zyngier | c15018e | 2014-08-26 11:03:27 +0100 | [diff] [blame] | 61 | u32 irqstat; |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 62 | |
| 63 | irqstat = readl_relaxed(base + SIRFSOC_INIT_IRQ_ID); |
Marc Zyngier | c15018e | 2014-08-26 11:03:27 +0100 | [diff] [blame] | 64 | handle_domain_irq(sirfsoc_irqdomain, irqstat & 0xff, regs); |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Bin Shi | 7caf685 | 2014-05-06 22:58:36 +0800 | [diff] [blame] | 67 | static int __init sirfsoc_irq_init(struct device_node *np, |
| 68 | struct device_node *parent) |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 69 | { |
| 70 | void __iomem *base = of_iomap(np, 0); |
| 71 | if (!base) |
| 72 | panic("unable to map intc cpu registers\n"); |
| 73 | |
Barry Song | 29eb51a | 2013-08-06 13:37:13 +0800 | [diff] [blame] | 74 | sirfsoc_irqdomain = irq_domain_add_linear(np, SIRFSOC_NUM_IRQS, |
Thomas Gleixner | d452bca | 2015-07-06 10:18:29 +0000 | [diff] [blame] | 75 | &irq_generic_chip_ops, base); |
| 76 | sirfsoc_alloc_gc(base); |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 77 | |
| 78 | writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL0); |
| 79 | writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL1); |
| 80 | |
| 81 | writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK0); |
| 82 | writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK1); |
| 83 | |
| 84 | set_handle_irq(sirfsoc_handle_irq); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | IRQCHIP_DECLARE(sirfsoc_intc, "sirf,prima2-intc", sirfsoc_irq_init); |
| 89 | |
| 90 | struct sirfsoc_irq_status { |
| 91 | u32 mask0; |
| 92 | u32 mask1; |
| 93 | u32 level0; |
| 94 | u32 level1; |
| 95 | }; |
| 96 | |
| 97 | static struct sirfsoc_irq_status sirfsoc_irq_st; |
| 98 | |
| 99 | static int sirfsoc_irq_suspend(void) |
| 100 | { |
Ben Dooks | 4a3691c | 2016-06-07 13:18:30 +0100 | [diff] [blame] | 101 | void __iomem *base = sirfsoc_irq_get_regbase(); |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 102 | |
| 103 | sirfsoc_irq_st.mask0 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK0); |
| 104 | sirfsoc_irq_st.mask1 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK1); |
| 105 | sirfsoc_irq_st.level0 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL0); |
| 106 | sirfsoc_irq_st.level1 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL1); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static void sirfsoc_irq_resume(void) |
| 112 | { |
Ben Dooks | 4a3691c | 2016-06-07 13:18:30 +0100 | [diff] [blame] | 113 | void __iomem *base = sirfsoc_irq_get_regbase(); |
Arnd Bergmann | 60dbd76 | 2013-03-19 11:21:44 +0100 | [diff] [blame] | 114 | |
| 115 | writel_relaxed(sirfsoc_irq_st.mask0, base + SIRFSOC_INT_RISC_MASK0); |
| 116 | writel_relaxed(sirfsoc_irq_st.mask1, base + SIRFSOC_INT_RISC_MASK1); |
| 117 | writel_relaxed(sirfsoc_irq_st.level0, base + SIRFSOC_INT_RISC_LEVEL0); |
| 118 | writel_relaxed(sirfsoc_irq_st.level1, base + SIRFSOC_INT_RISC_LEVEL1); |
| 119 | } |
| 120 | |
| 121 | static struct syscore_ops sirfsoc_irq_syscore_ops = { |
| 122 | .suspend = sirfsoc_irq_suspend, |
| 123 | .resume = sirfsoc_irq_resume, |
| 124 | }; |
| 125 | |
| 126 | static int __init sirfsoc_irq_pm_init(void) |
| 127 | { |
| 128 | if (!sirfsoc_irqdomain) |
| 129 | return 0; |
| 130 | |
| 131 | register_syscore_ops(&sirfsoc_irq_syscore_ops); |
| 132 | return 0; |
| 133 | } |
| 134 | device_initcall(sirfsoc_irq_pm_init); |