Blame view

drivers/irqchip/irq-ingenic.c 3.86 KB
a912e80bd   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
2
3
  /*
   *  Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
b8b0145f7   Zhou Yanjie   irqchip: Ingenic:...
4
   *  Ingenic XBurst platform IRQ support
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
5
6
7
8
9
10
11
   */
  
  #include <linux/errno.h>
  #include <linux/init.h>
  #include <linux/types.h>
  #include <linux/interrupt.h>
  #include <linux/ioport.h>
41a83e06e   Joel Porquet   irqchip: Prepare ...
12
  #include <linux/irqchip.h>
3aa94590e   Paul Burton   MIPS: JZ4740: rea...
13
  #include <linux/of_address.h>
adbdce77c   Paul Burton   MIPS: JZ4740: pro...
14
  #include <linux/of_irq.h>
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
15
16
17
  #include <linux/timex.h>
  #include <linux/slab.h>
  #include <linux/delay.h>
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
18
  #include <asm/io.h>
942e22dff   Brian Norris   MIPS: JZ4740: Fix...
19

fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
20
21
  struct ingenic_intc_data {
  	void __iomem *base;
208caadce   Paul Cercueil   irqchip: ingenic:...
22
  	struct irq_domain *domain;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
23
  	unsigned num_chips;
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
24
  };
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
25
26
27
28
29
30
  
  #define JZ_REG_INTC_STATUS	0x00
  #define JZ_REG_INTC_MASK	0x04
  #define JZ_REG_INTC_SET_MASK	0x08
  #define JZ_REG_INTC_CLEAR_MASK	0x0c
  #define JZ_REG_INTC_PENDING	0x10
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
31
  #define CHIP_SIZE		0x20
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
32

2da018849   Paul Burton   MIPS: JZ4740: Avo...
33
  static irqreturn_t intc_cascade(int irq, void *data)
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
34
  {
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
35
  	struct ingenic_intc_data *intc = irq_get_handler_data(irq);
208caadce   Paul Cercueil   irqchip: ingenic:...
36
  	struct irq_domain *domain = intc->domain;
8bc7464b5   Paul Cercueil   irqchip: ingenic:...
37
  	struct irq_chip_generic *gc;
b8b0145f7   Zhou Yanjie   irqchip: Ingenic:...
38
  	uint32_t pending;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
39
  	unsigned i;
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
40

943d69c6c   Paul Burton   MIPS: JZ4740: sup...
41
  	for (i = 0; i < intc->num_chips; i++) {
8bc7464b5   Paul Cercueil   irqchip: ingenic:...
42
  		gc = irq_get_domain_generic_chip(domain, i * 32);
b8b0145f7   Zhou Yanjie   irqchip: Ingenic:...
43
44
  		pending = irq_reg_readl(gc, JZ_REG_INTC_PENDING);
  		if (!pending)
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
45
  			continue;
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
46

b8b0145f7   Zhou Yanjie   irqchip: Ingenic:...
47
48
  		while (pending) {
  			int bit = __fls(pending);
1fd224e35   Paul Cercueil   irqchip/ingenic: ...
49
  			irq = irq_linear_revmap(domain, bit + (i * 32));
b8b0145f7   Zhou Yanjie   irqchip: Ingenic:...
50
51
52
  			generic_handle_irq(irq);
  			pending &= ~BIT(bit);
  		}
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
53
  	}
83bc76920   Lars-Peter Clausen   MIPS: JZ4740: Use...
54
55
  
  	return IRQ_HANDLED;
42b64f388   Thomas Gleixner   MIPS: JZ4740: Con...
56
  }
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
57
58
  static int __init ingenic_intc_of_init(struct device_node *node,
  				       unsigned num_chips)
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
59
  {
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
60
  	struct ingenic_intc_data *intc;
83bc76920   Lars-Peter Clausen   MIPS: JZ4740: Use...
61
62
  	struct irq_chip_generic *gc;
  	struct irq_chip_type *ct;
638c88518   Paul Burton   MIPS: JZ4740: reg...
63
  	struct irq_domain *domain;
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
64
  	int parent_irq, err = 0;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
65
  	unsigned i;
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
66
67
68
69
70
71
  
  	intc = kzalloc(sizeof(*intc), GFP_KERNEL);
  	if (!intc) {
  		err = -ENOMEM;
  		goto out_err;
  	}
69ce4b228   Paul Burton   MIPS: JZ4740: par...
72
73
  
  	parent_irq = irq_of_parse_and_map(node, 0);
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
74
75
76
77
  	if (!parent_irq) {
  		err = -EINVAL;
  		goto out_free;
  	}
83bc76920   Lars-Peter Clausen   MIPS: JZ4740: Use...
78

fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
79
80
81
  	err = irq_set_handler_data(parent_irq, intc);
  	if (err)
  		goto out_unmap_irq;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
82
  	intc->num_chips = num_chips;
3aa94590e   Paul Burton   MIPS: JZ4740: rea...
83
84
85
86
87
  	intc->base = of_iomap(node, 0);
  	if (!intc->base) {
  		err = -ENODEV;
  		goto out_unmap_irq;
  	}
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
88

1fd224e35   Paul Cercueil   irqchip/ingenic: ...
89
  	domain = irq_domain_add_linear(node, num_chips * 32,
8bc7464b5   Paul Cercueil   irqchip: ingenic:...
90
  				       &irq_generic_chip_ops, NULL);
52ecc8764   Paul Cercueil   irqchip: ingenic:...
91
92
93
94
  	if (!domain) {
  		err = -ENOMEM;
  		goto out_unmap_base;
  	}
208caadce   Paul Cercueil   irqchip: ingenic:...
95
  	intc->domain = domain;
8bc7464b5   Paul Cercueil   irqchip: ingenic:...
96
97
98
99
100
  	err = irq_alloc_domain_generic_chips(domain, 32, 1, "INTC",
  					     handle_level_irq, 0,
  					     IRQ_NOPROBE | IRQ_LEVEL, 0);
  	if (err)
  		goto out_domain_remove;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
101

8bc7464b5   Paul Cercueil   irqchip: ingenic:...
102
103
  	for (i = 0; i < num_chips; i++) {
  		gc = irq_get_domain_generic_chip(domain, i * 32);
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
104
105
  
  		gc->wake_enabled = IRQ_MSK(32);
8bc7464b5   Paul Cercueil   irqchip: ingenic:...
106
  		gc->reg_base = intc->base + (i * CHIP_SIZE);
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
107
108
109
110
111
112
113
114
  
  		ct = gc->chip_types;
  		ct->regs.enable = JZ_REG_INTC_CLEAR_MASK;
  		ct->regs.disable = JZ_REG_INTC_SET_MASK;
  		ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  		ct->chip.irq_mask = irq_gc_mask_disable_reg;
  		ct->chip.irq_mask_ack = irq_gc_mask_disable_reg;
  		ct->chip.irq_set_wake = irq_gc_set_wake;
20b44b4de   Paul Cercueil   irqchip: ingenic:...
115
  		ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND;
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
116

8bc7464b5   Paul Cercueil   irqchip: ingenic:...
117
118
  		/* Mask all irqs */
  		irq_reg_writel(gc, IRQ_MSK(32), JZ_REG_INTC_SET_MASK);
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
119
  	}
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
120

821fc9e26   Paul Cercueil   irqchip/ingenic: ...
121
  	if (request_irq(parent_irq, intc_cascade, IRQF_NO_SUSPEND,
2ef1cb763   afzal mohammed   irqchip: Replace ...
122
123
124
  			"SoC intc cascade interrupt", NULL))
  		pr_err("Failed to register SoC intc cascade interrupt
  ");
adbdce77c   Paul Burton   MIPS: JZ4740: pro...
125
  	return 0;
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
126

8bc7464b5   Paul Cercueil   irqchip: ingenic:...
127
128
  out_domain_remove:
  	irq_domain_remove(domain);
52ecc8764   Paul Cercueil   irqchip: ingenic:...
129
130
  out_unmap_base:
  	iounmap(intc->base);
fe778ece8   Paul Burton   MIPS: JZ4740: Rem...
131
132
133
134
135
136
  out_unmap_irq:
  	irq_dispose_mapping(parent_irq);
  out_free:
  	kfree(intc);
  out_err:
  	return err;
9869848d1   Lars-Peter Clausen   MIPS: JZ4740: Add...
137
  }
943d69c6c   Paul Burton   MIPS: JZ4740: sup...
138
139
140
141
142
143
144
  
  static int __init intc_1chip_of_init(struct device_node *node,
  				     struct device_node *parent)
  {
  	return ingenic_intc_of_init(node, 1);
  }
  IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init);
1047557cb   Paul Cercueil   irqchip/ingenic: ...
145
  IRQCHIP_DECLARE(jz4725b_intc, "ingenic,jz4725b-intc", intc_1chip_of_init);
24ccfa06b   Paul Burton   MIPS: JZ4740: sup...
146
147
148
149
150
151
152
153
154
  
  static int __init intc_2chip_of_init(struct device_node *node,
  	struct device_node *parent)
  {
  	return ingenic_intc_of_init(node, 2);
  }
  IRQCHIP_DECLARE(jz4770_intc, "ingenic,jz4770-intc", intc_2chip_of_init);
  IRQCHIP_DECLARE(jz4775_intc, "ingenic,jz4775-intc", intc_2chip_of_init);
  IRQCHIP_DECLARE(jz4780_intc, "ingenic,jz4780-intc", intc_2chip_of_init);