blob: e1336848affa474f9b101ff9f53445bda287cec5 [file] [log] [blame]
Arnd Bergmann60dbd762013-03-19 11:21:44 +01001/*
2 * interrupt controller support for CSR SiRFprimaII
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/init.h>
10#include <linux/io.h>
11#include <linux/irq.h>
12#include <linux/of.h>
13#include <linux/of_address.h>
Joel Porquet41a83e02015-07-07 17:11:46 -040014#include <linux/irqchip.h>
Arnd Bergmann60dbd762013-03-19 11:21:44 +010015#include <linux/irqdomain.h>
16#include <linux/syscore_ops.h>
17#include <asm/mach/irq.h>
18#include <asm/exception.h>
Arnd Bergmann60dbd762013-03-19 11:21:44 +010019
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000020#define SIRFSOC_INT_RISC_MASK0 0x0018
21#define SIRFSOC_INT_RISC_MASK1 0x001C
22#define SIRFSOC_INT_RISC_LEVEL0 0x0020
23#define SIRFSOC_INT_RISC_LEVEL1 0x0024
Arnd Bergmann60dbd762013-03-19 11:21:44 +010024#define SIRFSOC_INIT_IRQ_ID 0x0038
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000025#define SIRFSOC_INT_BASE_OFFSET 0x0004
Arnd Bergmann60dbd762013-03-19 11:21:44 +010026
Barry Song29eb51a2013-08-06 13:37:13 +080027#define SIRFSOC_NUM_IRQS 64
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000028#define SIRFSOC_NUM_BANKS (SIRFSOC_NUM_IRQS / 32)
Arnd Bergmann60dbd762013-03-19 11:21:44 +010029
30static struct irq_domain *sirfsoc_irqdomain;
31
Ben Dooks4a3691c2016-06-07 13:18:30 +010032static void __iomem *sirfsoc_irq_get_regbase(void)
33{
34 return (void __iomem __force *)sirfsoc_irqdomain->host_data;
35}
36
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000037static __init void sirfsoc_alloc_gc(void __iomem *base)
Arnd Bergmann60dbd762013-03-19 11:21:44 +010038{
Barry Song29eb51a2013-08-06 13:37:13 +080039 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
Barry Songa87010e2014-01-03 11:34:46 +080040 unsigned int set = IRQ_LEVEL;
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000041 struct irq_chip_generic *gc;
42 struct irq_chip_type *ct;
43 int i;
Arnd Bergmann60dbd762013-03-19 11:21:44 +010044
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000045 irq_alloc_domain_generic_chips(sirfsoc_irqdomain, 32, 1, "irq_sirfsoc",
46 handle_level_irq, clr, set,
47 IRQ_GC_INIT_MASK_CACHE);
Barry Song29eb51a2013-08-06 13:37:13 +080048
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000049 for (i = 0; i < SIRFSOC_NUM_BANKS; i++) {
50 gc = irq_get_domain_generic_chip(sirfsoc_irqdomain, i * 32);
51 gc->reg_base = base + i * SIRFSOC_INT_BASE_OFFSET;
52 ct = gc->chip_types;
53 ct->chip.irq_mask = irq_gc_mask_clr_bit;
54 ct->chip.irq_unmask = irq_gc_mask_set_bit;
55 ct->regs.mask = SIRFSOC_INT_RISC_MASK0;
56 }
Arnd Bergmann60dbd762013-03-19 11:21:44 +010057}
58
Stephen Boyd8783dd32014-03-04 16:40:30 -080059static void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs)
Arnd Bergmann60dbd762013-03-19 11:21:44 +010060{
Ben Dooks4a3691c2016-06-07 13:18:30 +010061 void __iomem *base = sirfsoc_irq_get_regbase();
Marc Zyngierc15018e2014-08-26 11:03:27 +010062 u32 irqstat;
Arnd Bergmann60dbd762013-03-19 11:21:44 +010063
64 irqstat = readl_relaxed(base + SIRFSOC_INIT_IRQ_ID);
Marc Zyngierc15018e2014-08-26 11:03:27 +010065 handle_domain_irq(sirfsoc_irqdomain, irqstat & 0xff, regs);
Arnd Bergmann60dbd762013-03-19 11:21:44 +010066}
67
Bin Shi7caf6852014-05-06 22:58:36 +080068static int __init sirfsoc_irq_init(struct device_node *np,
69 struct device_node *parent)
Arnd Bergmann60dbd762013-03-19 11:21:44 +010070{
71 void __iomem *base = of_iomap(np, 0);
72 if (!base)
73 panic("unable to map intc cpu registers\n");
74
Barry Song29eb51a2013-08-06 13:37:13 +080075 sirfsoc_irqdomain = irq_domain_add_linear(np, SIRFSOC_NUM_IRQS,
Thomas Gleixnerd452bca2015-07-06 10:18:29 +000076 &irq_generic_chip_ops, base);
77 sirfsoc_alloc_gc(base);
Arnd Bergmann60dbd762013-03-19 11:21:44 +010078
79 writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL0);
80 writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL1);
81
82 writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK0);
83 writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK1);
84
85 set_handle_irq(sirfsoc_handle_irq);
86
87 return 0;
88}
89IRQCHIP_DECLARE(sirfsoc_intc, "sirf,prima2-intc", sirfsoc_irq_init);
90
91struct sirfsoc_irq_status {
92 u32 mask0;
93 u32 mask1;
94 u32 level0;
95 u32 level1;
96};
97
98static struct sirfsoc_irq_status sirfsoc_irq_st;
99
100static int sirfsoc_irq_suspend(void)
101{
Ben Dooks4a3691c2016-06-07 13:18:30 +0100102 void __iomem *base = sirfsoc_irq_get_regbase();
Arnd Bergmann60dbd762013-03-19 11:21:44 +0100103
104 sirfsoc_irq_st.mask0 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK0);
105 sirfsoc_irq_st.mask1 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK1);
106 sirfsoc_irq_st.level0 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL0);
107 sirfsoc_irq_st.level1 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL1);
108
109 return 0;
110}
111
112static void sirfsoc_irq_resume(void)
113{
Ben Dooks4a3691c2016-06-07 13:18:30 +0100114 void __iomem *base = sirfsoc_irq_get_regbase();
Arnd Bergmann60dbd762013-03-19 11:21:44 +0100115
116 writel_relaxed(sirfsoc_irq_st.mask0, base + SIRFSOC_INT_RISC_MASK0);
117 writel_relaxed(sirfsoc_irq_st.mask1, base + SIRFSOC_INT_RISC_MASK1);
118 writel_relaxed(sirfsoc_irq_st.level0, base + SIRFSOC_INT_RISC_LEVEL0);
119 writel_relaxed(sirfsoc_irq_st.level1, base + SIRFSOC_INT_RISC_LEVEL1);
120}
121
122static struct syscore_ops sirfsoc_irq_syscore_ops = {
123 .suspend = sirfsoc_irq_suspend,
124 .resume = sirfsoc_irq_resume,
125};
126
127static int __init sirfsoc_irq_pm_init(void)
128{
129 if (!sirfsoc_irqdomain)
130 return 0;
131
132 register_syscore_ops(&sirfsoc_irq_syscore_ops);
133 return 0;
134}
135device_initcall(sirfsoc_irq_pm_init);