summaryrefslogtreecommitdiffstats
path: root/drivers/irqchip
diff options
context:
space:
mode:
authorMa Jun <majun258@huawei.com>2015-12-17 06:56:36 -0500
committerMarc Zyngier <marc.zyngier@arm.com>2015-12-18 06:47:07 -0500
commit9650c60ebfec05fcf74d9b3eb97837501f2bb541 (patch)
tree63079f61886f8c3feeafebf2ccb49054a14cc671 /drivers/irqchip
parent717c3dbc118ecbbd5dab06c7e02dac68d3f62e1d (diff)
irqchip/mbigen: Create irq domain for each mbigen device
For peripheral devices which connect to mbigen,mbigen is a interrupt controller. So, we create irq domain for each mbigen device and add mbigen irq domain into irq hierarchy structure. Signed-off-by: Ma Jun <majun258@huawei.com> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'drivers/irqchip')
-rw-r--r--drivers/irqchip/irq-mbigen.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
index 9f036c22f9b2..2ab1c2d7232c 100644
--- a/drivers/irqchip/irq-mbigen.c
+++ b/drivers/irqchip/irq-mbigen.c
@@ -16,13 +16,39 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19#include <linux/interrupt.h>
20#include <linux/irqchip.h>
19#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/msi.h>
20#include <linux/of_address.h> 23#include <linux/of_address.h>
21#include <linux/of_irq.h> 24#include <linux/of_irq.h>
22#include <linux/of_platform.h> 25#include <linux/of_platform.h>
23#include <linux/platform_device.h> 26#include <linux/platform_device.h>
24#include <linux/slab.h> 27#include <linux/slab.h>
25 28
29/* Interrupt numbers per mbigen node supported */
30#define IRQS_PER_MBIGEN_NODE 128
31
32/* 64 irqs (Pin0-pin63) are reserved for each mbigen chip */
33#define RESERVED_IRQ_PER_MBIGEN_CHIP 64
34
35/* The maximum IRQ pin number of mbigen chip(start from 0) */
36#define MAXIMUM_IRQ_PIN_NUM 1407
37
38/**
39 * In mbigen vector register
40 * bit[21:12]: event id value
41 * bit[11:0]: device id
42 */
43#define IRQ_EVENT_ID_SHIFT 12
44#define IRQ_EVENT_ID_MASK 0x3ff
45
46/* register range of each mbigen node */
47#define MBIGEN_NODE_OFFSET 0x1000
48
49/* offset of vector register in mbigen node */
50#define REG_MBIGEN_VEC_OFFSET 0x200
51
26/** 52/**
27 * struct mbigen_device - holds the information of mbigen device. 53 * struct mbigen_device - holds the information of mbigen device.
28 * 54 *
@@ -34,10 +60,107 @@ struct mbigen_device {
34 void __iomem *base; 60 void __iomem *base;
35}; 61};
36 62
63static inline unsigned int get_mbigen_vec_reg(irq_hw_number_t hwirq)
64{
65 unsigned int nid, pin;
66
67 hwirq -= RESERVED_IRQ_PER_MBIGEN_CHIP;
68 nid = hwirq / IRQS_PER_MBIGEN_NODE + 1;
69 pin = hwirq % IRQS_PER_MBIGEN_NODE;
70
71 return pin * 4 + nid * MBIGEN_NODE_OFFSET
72 + REG_MBIGEN_VEC_OFFSET;
73}
74
75static struct irq_chip mbigen_irq_chip = {
76 .name = "mbigen-v2",
77};
78
79static void mbigen_write_msg(struct msi_desc *desc, struct msi_msg *msg)
80{
81 struct irq_data *d = irq_get_irq_data(desc->irq);
82 void __iomem *base = d->chip_data;
83 u32 val;
84
85 base += get_mbigen_vec_reg(d->hwirq);
86 val = readl_relaxed(base);
87
88 val &= ~(IRQ_EVENT_ID_MASK << IRQ_EVENT_ID_SHIFT);
89 val |= (msg->data << IRQ_EVENT_ID_SHIFT);
90
91 /* The address of doorbell is encoded in mbigen register by default
92 * So,we don't need to program the doorbell address at here
93 */
94 writel_relaxed(val, base);
95}
96
97static int mbigen_domain_translate(struct irq_domain *d,
98 struct irq_fwspec *fwspec,
99 unsigned long *hwirq,
100 unsigned int *type)
101{
102 if (is_of_node(fwspec->fwnode)) {
103 if (fwspec->param_count != 2)
104 return -EINVAL;
105
106 if ((fwspec->param[0] > MAXIMUM_IRQ_PIN_NUM) ||
107 (fwspec->param[0] < RESERVED_IRQ_PER_MBIGEN_CHIP))
108 return -EINVAL;
109 else
110 *hwirq = fwspec->param[0];
111
112 /* If there is no valid irq type, just use the default type */
113 if ((fwspec->param[1] == IRQ_TYPE_EDGE_RISING) ||
114 (fwspec->param[1] == IRQ_TYPE_LEVEL_HIGH))
115 *type = fwspec->param[1];
116 else
117 return -EINVAL;
118
119 return 0;
120 }
121 return -EINVAL;
122}
123
124static int mbigen_irq_domain_alloc(struct irq_domain *domain,
125 unsigned int virq,
126 unsigned int nr_irqs,
127 void *args)
128{
129 struct irq_fwspec *fwspec = args;
130 irq_hw_number_t hwirq;
131 unsigned int type;
132 struct mbigen_device *mgn_chip;
133 int i, err;
134
135 err = mbigen_domain_translate(domain, fwspec, &hwirq, &type);
136 if (err)
137 return err;
138
139 err = platform_msi_domain_alloc(domain, virq, nr_irqs);
140 if (err)
141 return err;
142
143 mgn_chip = platform_msi_get_host_data(domain);
144
145 for (i = 0; i < nr_irqs; i++)
146 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
147 &mbigen_irq_chip, mgn_chip->base);
148
149 return 0;
150}
151
152static struct irq_domain_ops mbigen_domain_ops = {
153 .translate = mbigen_domain_translate,
154 .alloc = mbigen_irq_domain_alloc,
155 .free = irq_domain_free_irqs_common,
156};
157
37static int mbigen_device_probe(struct platform_device *pdev) 158static int mbigen_device_probe(struct platform_device *pdev)
38{ 159{
39 struct mbigen_device *mgn_chip; 160 struct mbigen_device *mgn_chip;
40 struct resource *res; 161 struct resource *res;
162 struct irq_domain *domain;
163 u32 num_pins;
41 164
42 mgn_chip = devm_kzalloc(&pdev->dev, sizeof(*mgn_chip), GFP_KERNEL); 165 mgn_chip = devm_kzalloc(&pdev->dev, sizeof(*mgn_chip), GFP_KERNEL);
43 if (!mgn_chip) 166 if (!mgn_chip)
@@ -50,8 +173,23 @@ static int mbigen_device_probe(struct platform_device *pdev)
50 if (IS_ERR(mgn_chip->base)) 173 if (IS_ERR(mgn_chip->base))
51 return PTR_ERR(mgn_chip->base); 174 return PTR_ERR(mgn_chip->base);
52 175
176 if (of_property_read_u32(pdev->dev.of_node, "num-pins", &num_pins) < 0) {
177 dev_err(&pdev->dev, "No num-pins property\n");
178 return -EINVAL;
179 }
180
181 domain = platform_msi_create_device_domain(&pdev->dev, num_pins,
182 mbigen_write_msg,
183 &mbigen_domain_ops,
184 mgn_chip);
185
186 if (!domain)
187 return -ENOMEM;
188
53 platform_set_drvdata(pdev, mgn_chip); 189 platform_set_drvdata(pdev, mgn_chip);
54 190
191 dev_info(&pdev->dev, "Allocated %d MSIs\n", num_pins);
192
55 return 0; 193 return 0;
56} 194}
57 195