blob: 862b32702d2933d062e33ccf20df8eff7bfc9d41 [file] [log] [blame]
Michael Ellermance21b3c2007-07-20 21:39:28 +02001/*
2 * Copyright 2007, Michael Ellerman, IBM Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10
11#include <linux/interrupt.h>
12#include <linux/irq.h>
13#include <linux/kernel.h>
14#include <linux/pci.h>
15#include <linux/msi.h>
Paul Gortmaker66b15db2011-05-27 10:46:24 -040016#include <linux/export.h>
Michael Ellermane4347df2008-01-25 16:59:14 +110017#include <linux/of_platform.h>
Michael Ellerman72cac212008-05-23 14:21:30 +100018#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Michael Ellermance21b3c2007-07-20 21:39:28 +020020
21#include <asm/dcr.h>
22#include <asm/machdep.h>
23#include <asm/prom.h>
24
25
26/*
27 * MSIC registers, specified as offsets from dcr_base
28 */
29#define MSIC_CTRL_REG 0x0
30
31/* Base Address registers specify FIFO location in BE memory */
32#define MSIC_BASE_ADDR_HI_REG 0x3
33#define MSIC_BASE_ADDR_LO_REG 0x4
34
35/* Hold the read/write offsets into the FIFO */
36#define MSIC_READ_OFFSET_REG 0x5
37#define MSIC_WRITE_OFFSET_REG 0x6
38
39
40/* MSIC control register flags */
41#define MSIC_CTRL_ENABLE 0x0001
42#define MSIC_CTRL_FIFO_FULL_ENABLE 0x0002
43#define MSIC_CTRL_IRQ_ENABLE 0x0008
44#define MSIC_CTRL_FULL_STOP_ENABLE 0x0010
45
46/*
47 * The MSIC can be configured to use a FIFO of 32KB, 64KB, 128KB or 256KB.
48 * Currently we're using a 64KB FIFO size.
49 */
50#define MSIC_FIFO_SIZE_SHIFT 16
51#define MSIC_FIFO_SIZE_BYTES (1 << MSIC_FIFO_SIZE_SHIFT)
52
53/*
54 * To configure the FIFO size as (1 << n) bytes, we write (n - 15) into bits
55 * 8-9 of the MSIC control reg.
56 */
57#define MSIC_CTRL_FIFO_SIZE (((MSIC_FIFO_SIZE_SHIFT - 15) << 8) & 0x300)
58
59/*
60 * We need to mask the read/write offsets to make sure they stay within
61 * the bounds of the FIFO. Also they should always be 16-byte aligned.
62 */
63#define MSIC_FIFO_SIZE_MASK ((MSIC_FIFO_SIZE_BYTES - 1) & ~0xFu)
64
65/* Each entry in the FIFO is 16 bytes, the first 4 bytes hold the irq # */
66#define MSIC_FIFO_ENTRY_SIZE 0x10
67
68
69struct axon_msic {
Grant Likelybae1d8f2012-02-14 14:06:50 -070070 struct irq_domain *irq_domain;
Michael Ellermande4c9282008-01-25 16:59:14 +110071 __le32 *fifo_virt;
72 dma_addr_t fifo_phys;
Michael Ellermance21b3c2007-07-20 21:39:28 +020073 dcr_host_t dcr_host;
Michael Ellermance21b3c2007-07-20 21:39:28 +020074 u32 read_offset;
Michael Ellerman72cac212008-05-23 14:21:30 +100075#ifdef DEBUG
76 u32 __iomem *trigger;
77#endif
Michael Ellermance21b3c2007-07-20 21:39:28 +020078};
79
Michael Ellerman72cac212008-05-23 14:21:30 +100080#ifdef DEBUG
81void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic);
82#else
83static inline void axon_msi_debug_setup(struct device_node *dn,
84 struct axon_msic *msic) { }
85#endif
86
87
Michael Ellermance21b3c2007-07-20 21:39:28 +020088static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
89{
Michael Ellerman33875f02009-06-17 18:13:53 +000090 pr_devel("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
Michael Ellermance21b3c2007-07-20 21:39:28 +020091
Michael Ellerman83f34df2007-10-15 19:34:36 +100092 dcr_write(msic->dcr_host, dcr_n, val);
Michael Ellermance21b3c2007-07-20 21:39:28 +020093}
94
Michael Ellermance21b3c2007-07-20 21:39:28 +020095static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
96{
Thomas Gleixnerec775d02011-03-25 16:45:20 +010097 struct irq_chip *chip = irq_desc_get_chip(desc);
98 struct axon_msic *msic = irq_get_handler_data(irq);
Michael Ellermance21b3c2007-07-20 21:39:28 +020099 u32 write_offset, msi;
100 int idx;
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000101 int retry = 0;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200102
Michael Ellerman2843e7f2007-10-15 19:34:38 +1000103 write_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG);
Michael Ellerman33875f02009-06-17 18:13:53 +0000104 pr_devel("axon_msi: original write_offset 0x%x\n", write_offset);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200105
106 /* write_offset doesn't wrap properly, so we have to mask it */
107 write_offset &= MSIC_FIFO_SIZE_MASK;
108
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000109 while (msic->read_offset != write_offset && retry < 100) {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200110 idx = msic->read_offset / sizeof(__le32);
Michael Ellermande4c9282008-01-25 16:59:14 +1100111 msi = le32_to_cpu(msic->fifo_virt[idx]);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200112 msi &= 0xFFFF;
113
Michael Ellerman33875f02009-06-17 18:13:53 +0000114 pr_devel("axon_msi: woff %x roff %x msi %x\n",
Michael Ellermance21b3c2007-07-20 21:39:28 +0200115 write_offset, msic->read_offset, msi);
116
Grant Likely40133692012-04-23 12:30:02 +0000117 if (msi < nr_irqs && irq_get_chip_data(msi) == msic) {
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000118 generic_handle_irq(msi);
119 msic->fifo_virt[idx] = cpu_to_le32(0xffffffff);
120 } else {
121 /*
122 * Reading the MSIC_WRITE_OFFSET_REG does not
123 * reliably flush the outstanding DMA to the
124 * FIFO buffer. Here we were reading stale
125 * data, so we need to retry.
126 */
127 udelay(1);
128 retry++;
Michael Ellerman33875f02009-06-17 18:13:53 +0000129 pr_devel("axon_msi: invalid irq 0x%x!\n", msi);
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000130 continue;
131 }
132
133 if (retry) {
Michael Ellerman33875f02009-06-17 18:13:53 +0000134 pr_devel("axon_msi: late irq 0x%x, retry %d\n",
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000135 msi, retry);
136 retry = 0;
137 }
138
Michael Ellermance21b3c2007-07-20 21:39:28 +0200139 msic->read_offset += MSIC_FIFO_ENTRY_SIZE;
140 msic->read_offset &= MSIC_FIFO_SIZE_MASK;
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000141 }
Michael Ellermance21b3c2007-07-20 21:39:28 +0200142
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000143 if (retry) {
144 printk(KERN_WARNING "axon_msi: irq timed out\n");
145
146 msic->read_offset += MSIC_FIFO_ENTRY_SIZE;
147 msic->read_offset &= MSIC_FIFO_SIZE_MASK;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200148 }
149
Lennert Buytenhekd1ae63d2011-03-07 13:59:28 +0000150 chip->irq_eoi(&desc->irq_data);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200151}
152
153static struct axon_msic *find_msi_translator(struct pci_dev *dev)
154{
Grant Likelybae1d8f2012-02-14 14:06:50 -0700155 struct irq_domain *irq_domain;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200156 struct device_node *dn, *tmp;
157 const phandle *ph;
158 struct axon_msic *msic = NULL;
159
Michael Ellermandb220b22007-09-17 16:03:45 +1000160 dn = of_node_get(pci_device_to_OF_node(dev));
Michael Ellermance21b3c2007-07-20 21:39:28 +0200161 if (!dn) {
162 dev_dbg(&dev->dev, "axon_msi: no pci_dn found\n");
163 return NULL;
164 }
165
Michael Ellerman988479e2008-04-24 12:08:54 +1000166 for (; dn; dn = of_get_next_parent(dn)) {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200167 ph = of_get_property(dn, "msi-translator", NULL);
168 if (ph)
169 break;
170 }
171
172 if (!ph) {
173 dev_dbg(&dev->dev,
174 "axon_msi: no msi-translator property found\n");
175 goto out_error;
176 }
177
178 tmp = dn;
179 dn = of_find_node_by_phandle(*ph);
Stephen Rothwellc6d01172008-02-05 13:13:15 +1100180 of_node_put(tmp);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200181 if (!dn) {
182 dev_dbg(&dev->dev,
183 "axon_msi: msi-translator doesn't point to a node\n");
184 goto out_error;
185 }
186
Grant Likelybae1d8f2012-02-14 14:06:50 -0700187 irq_domain = irq_find_host(dn);
188 if (!irq_domain) {
189 dev_dbg(&dev->dev, "axon_msi: no irq_domain found for node %s\n",
Michael Ellermance21b3c2007-07-20 21:39:28 +0200190 dn->full_name);
191 goto out_error;
192 }
193
Grant Likelybae1d8f2012-02-14 14:06:50 -0700194 msic = irq_domain->host_data;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200195
196out_error:
197 of_node_put(dn);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200198
199 return msic;
200}
201
Michael Ellermance21b3c2007-07-20 21:39:28 +0200202static int setup_msi_msg_address(struct pci_dev *dev, struct msi_msg *msg)
203{
Michael Ellerman988479e2008-04-24 12:08:54 +1000204 struct device_node *dn;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200205 struct msi_desc *entry;
206 int len;
207 const u32 *prop;
208
Michael Ellermandb220b22007-09-17 16:03:45 +1000209 dn = of_node_get(pci_device_to_OF_node(dev));
Michael Ellermance21b3c2007-07-20 21:39:28 +0200210 if (!dn) {
211 dev_dbg(&dev->dev, "axon_msi: no pci_dn found\n");
212 return -ENODEV;
213 }
214
215 entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
216
Michael Ellerman988479e2008-04-24 12:08:54 +1000217 for (; dn; dn = of_get_next_parent(dn)) {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200218 if (entry->msi_attrib.is_64) {
219 prop = of_get_property(dn, "msi-address-64", &len);
220 if (prop)
221 break;
222 }
223
224 prop = of_get_property(dn, "msi-address-32", &len);
225 if (prop)
226 break;
227 }
228
229 if (!prop) {
230 dev_dbg(&dev->dev,
231 "axon_msi: no msi-address-(32|64) properties found\n");
232 return -ENOENT;
233 }
234
235 switch (len) {
236 case 8:
237 msg->address_hi = prop[0];
238 msg->address_lo = prop[1];
239 break;
240 case 4:
241 msg->address_hi = 0;
242 msg->address_lo = prop[0];
243 break;
244 default:
245 dev_dbg(&dev->dev,
246 "axon_msi: malformed msi-address-(32|64) property\n");
247 of_node_put(dn);
248 return -EINVAL;
249 }
250
251 of_node_put(dn);
252
253 return 0;
254}
255
256static int axon_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
257{
258 unsigned int virq, rc;
259 struct msi_desc *entry;
260 struct msi_msg msg;
261 struct axon_msic *msic;
262
263 msic = find_msi_translator(dev);
264 if (!msic)
265 return -ENODEV;
266
267 rc = setup_msi_msg_address(dev, &msg);
268 if (rc)
269 return rc;
270
Michael Ellermance21b3c2007-07-20 21:39:28 +0200271 list_for_each_entry(entry, &dev->msi_list, list) {
Grant Likelybae1d8f2012-02-14 14:06:50 -0700272 virq = irq_create_direct_mapping(msic->irq_domain);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200273 if (virq == NO_IRQ) {
274 dev_warn(&dev->dev,
275 "axon_msi: virq allocation failed!\n");
276 return -1;
277 }
278 dev_dbg(&dev->dev, "axon_msi: allocated virq 0x%x\n", virq);
279
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100280 irq_set_msi_desc(virq, entry);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200281 msg.data = virq;
282 write_msi_msg(virq, &msg);
283 }
284
285 return 0;
286}
287
288static void axon_msi_teardown_msi_irqs(struct pci_dev *dev)
289{
290 struct msi_desc *entry;
291
292 dev_dbg(&dev->dev, "axon_msi: tearing down msi irqs\n");
293
294 list_for_each_entry(entry, &dev->msi_list, list) {
295 if (entry->irq == NO_IRQ)
296 continue;
297
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100298 irq_set_msi_desc(entry->irq, NULL);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200299 irq_dispose_mapping(entry->irq);
300 }
301}
302
303static struct irq_chip msic_irq_chip = {
Thomas Gleixner1c9db522010-09-28 16:46:51 +0200304 .irq_mask = mask_msi_irq,
305 .irq_unmask = unmask_msi_irq,
306 .irq_shutdown = mask_msi_irq,
Thomas Gleixnerb27df672009-11-18 23:44:21 +0000307 .name = "AXON-MSI",
Michael Ellermance21b3c2007-07-20 21:39:28 +0200308};
309
Grant Likelybae1d8f2012-02-14 14:06:50 -0700310static int msic_host_map(struct irq_domain *h, unsigned int virq,
Michael Ellermance21b3c2007-07-20 21:39:28 +0200311 irq_hw_number_t hw)
312{
Milton Miller95533612011-05-10 19:30:33 +0000313 irq_set_chip_data(virq, h->host_data);
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100314 irq_set_chip_and_handler(virq, &msic_irq_chip, handle_simple_irq);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200315
316 return 0;
317}
318
Grant Likely9f70b8e2012-01-26 12:24:34 -0700319static const struct irq_domain_ops msic_host_ops = {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200320 .map = msic_host_map,
321};
322
Grant Likely00006122011-02-22 19:59:54 -0700323static void axon_msi_shutdown(struct platform_device *device)
Michael Ellermance21b3c2007-07-20 21:39:28 +0200324{
Michael Ellerman86c27652009-06-10 19:06:34 +0000325 struct axon_msic *msic = dev_get_drvdata(&device->dev);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200326 u32 tmp;
327
Michael Ellerman33875f02009-06-17 18:13:53 +0000328 pr_devel("axon_msi: disabling %s\n",
Grant Likelybae1d8f2012-02-14 14:06:50 -0700329 msic->irq_domain->of_node->full_name);
Michael Ellermane4347df2008-01-25 16:59:14 +1100330 tmp = dcr_read(msic->dcr_host, MSIC_CTRL_REG);
331 tmp &= ~MSIC_CTRL_ENABLE & ~MSIC_CTRL_IRQ_ENABLE;
332 msic_dcr_write(msic, MSIC_CTRL_REG, tmp);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200333}
334
Grant Likely00006122011-02-22 19:59:54 -0700335static int axon_msi_probe(struct platform_device *device)
Michael Ellermance21b3c2007-07-20 21:39:28 +0200336{
Grant Likely61c7a082010-04-13 16:12:29 -0700337 struct device_node *dn = device->dev.of_node;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200338 struct axon_msic *msic;
339 unsigned int virq;
Michael Ellerman4acb88962007-09-17 16:05:02 +1000340 int dcr_base, dcr_len;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200341
Michael Ellerman33875f02009-06-17 18:13:53 +0000342 pr_devel("axon_msi: setting up dn %s\n", dn->full_name);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200343
344 msic = kzalloc(sizeof(struct axon_msic), GFP_KERNEL);
345 if (!msic) {
346 printk(KERN_ERR "axon_msi: couldn't allocate msic for %s\n",
347 dn->full_name);
348 goto out;
349 }
350
Michael Ellerman4acb88962007-09-17 16:05:02 +1000351 dcr_base = dcr_resource_start(dn, 0);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200352 dcr_len = dcr_resource_len(dn, 0);
353
Michael Ellerman4acb88962007-09-17 16:05:02 +1000354 if (dcr_base == 0 || dcr_len == 0) {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200355 printk(KERN_ERR
356 "axon_msi: couldn't parse dcr properties on %s\n",
357 dn->full_name);
Michael Ellermanaee7a282009-10-12 14:29:40 +0000358 goto out_free_msic;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200359 }
360
Michael Ellerman4acb88962007-09-17 16:05:02 +1000361 msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200362 if (!DCR_MAP_OK(msic->dcr_host)) {
363 printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
364 dn->full_name);
365 goto out_free_msic;
366 }
367
Michael Ellermande4c9282008-01-25 16:59:14 +1100368 msic->fifo_virt = dma_alloc_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES,
369 &msic->fifo_phys, GFP_KERNEL);
370 if (!msic->fifo_virt) {
Michael Ellermance21b3c2007-07-20 21:39:28 +0200371 printk(KERN_ERR "axon_msi: couldn't allocate fifo for %s\n",
372 dn->full_name);
373 goto out_free_msic;
374 }
375
Michael Ellerman997526d2008-05-26 12:12:30 +1000376 virq = irq_of_parse_and_map(dn, 0);
377 if (virq == NO_IRQ) {
378 printk(KERN_ERR "axon_msi: irq parse and map failed for %s\n",
379 dn->full_name);
380 goto out_free_fifo;
381 }
Arnd Bergmannd015fe92008-11-28 09:51:22 +0000382 memset(msic->fifo_virt, 0xff, MSIC_FIFO_SIZE_BYTES);
Michael Ellerman997526d2008-05-26 12:12:30 +1000383
Grant Likely40133692012-04-23 12:30:02 +0000384 /* We rely on being able to stash a virq in a u16, so limit irqs to < 65536 */
385 msic->irq_domain = irq_domain_add_nomap(dn, 65536, &msic_host_ops, msic);
Grant Likelybae1d8f2012-02-14 14:06:50 -0700386 if (!msic->irq_domain) {
387 printk(KERN_ERR "axon_msi: couldn't allocate irq_domain for %s\n",
Michael Ellermance21b3c2007-07-20 21:39:28 +0200388 dn->full_name);
389 goto out_free_fifo;
390 }
391
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100392 irq_set_handler_data(virq, msic);
393 irq_set_chained_handler(virq, axon_msi_cascade);
Michael Ellerman33875f02009-06-17 18:13:53 +0000394 pr_devel("axon_msi: irq 0x%x setup for axon_msi\n", virq);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200395
396 /* Enable the MSIC hardware */
Michael Ellermande4c9282008-01-25 16:59:14 +1100397 msic_dcr_write(msic, MSIC_BASE_ADDR_HI_REG, msic->fifo_phys >> 32);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200398 msic_dcr_write(msic, MSIC_BASE_ADDR_LO_REG,
Michael Ellermande4c9282008-01-25 16:59:14 +1100399 msic->fifo_phys & 0xFFFFFFFF);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200400 msic_dcr_write(msic, MSIC_CTRL_REG,
401 MSIC_CTRL_IRQ_ENABLE | MSIC_CTRL_ENABLE |
402 MSIC_CTRL_FIFO_SIZE);
403
Arnd Bergmann23e0e8a2008-12-12 09:19:50 +0000404 msic->read_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG)
405 & MSIC_FIFO_SIZE_MASK;
406
Michael Ellerman86c27652009-06-10 19:06:34 +0000407 dev_set_drvdata(&device->dev, msic);
Michael Ellermane4347df2008-01-25 16:59:14 +1100408
409 ppc_md.setup_msi_irqs = axon_msi_setup_msi_irqs;
410 ppc_md.teardown_msi_irqs = axon_msi_teardown_msi_irqs;
Michael Ellermance21b3c2007-07-20 21:39:28 +0200411
Michael Ellerman72cac212008-05-23 14:21:30 +1000412 axon_msi_debug_setup(dn, msic);
413
Michael Ellermance21b3c2007-07-20 21:39:28 +0200414 printk(KERN_DEBUG "axon_msi: setup MSIC on %s\n", dn->full_name);
415
416 return 0;
417
Michael Ellermance21b3c2007-07-20 21:39:28 +0200418out_free_fifo:
Michael Ellermande4c9282008-01-25 16:59:14 +1100419 dma_free_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES, msic->fifo_virt,
420 msic->fifo_phys);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200421out_free_msic:
422 kfree(msic);
423out:
424
425 return -1;
426}
427
Michael Ellermane4347df2008-01-25 16:59:14 +1100428static const struct of_device_id axon_msi_device_id[] = {
429 {
430 .compatible = "ibm,axon-msic"
431 },
432 {}
433};
434
Grant Likely00006122011-02-22 19:59:54 -0700435static struct platform_driver axon_msi_driver = {
Michael Ellermane4347df2008-01-25 16:59:14 +1100436 .probe = axon_msi_probe,
437 .shutdown = axon_msi_shutdown,
Grant Likely40182942010-04-13 16:13:02 -0700438 .driver = {
439 .name = "axon-msi",
440 .owner = THIS_MODULE,
441 .of_match_table = axon_msi_device_id,
Michael Ellermane4347df2008-01-25 16:59:14 +1100442 },
443};
444
445static int __init axon_msi_init(void)
Michael Ellermance21b3c2007-07-20 21:39:28 +0200446{
Grant Likely00006122011-02-22 19:59:54 -0700447 return platform_driver_register(&axon_msi_driver);
Michael Ellermance21b3c2007-07-20 21:39:28 +0200448}
Michael Ellermane4347df2008-01-25 16:59:14 +1100449subsys_initcall(axon_msi_init);
Michael Ellerman72cac212008-05-23 14:21:30 +1000450
451
452#ifdef DEBUG
453static int msic_set(void *data, u64 val)
454{
455 struct axon_msic *msic = data;
456 out_le32(msic->trigger, val);
457 return 0;
458}
459
460static int msic_get(void *data, u64 *val)
461{
462 *val = 0;
463 return 0;
464}
465
466DEFINE_SIMPLE_ATTRIBUTE(fops_msic, msic_get, msic_set, "%llu\n");
467
468void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic)
469{
470 char name[8];
471 u64 addr;
472
473 addr = of_translate_address(dn, of_get_property(dn, "reg", NULL));
474 if (addr == OF_BAD_ADDR) {
Michael Ellerman33875f02009-06-17 18:13:53 +0000475 pr_devel("axon_msi: couldn't translate reg property\n");
Michael Ellerman72cac212008-05-23 14:21:30 +1000476 return;
477 }
478
479 msic->trigger = ioremap(addr, 0x4);
480 if (!msic->trigger) {
Michael Ellerman33875f02009-06-17 18:13:53 +0000481 pr_devel("axon_msi: ioremap failed\n");
Michael Ellerman72cac212008-05-23 14:21:30 +1000482 return;
483 }
484
485 snprintf(name, sizeof(name), "msic_%d", of_node_to_nid(dn));
486
487 if (!debugfs_create_file(name, 0600, powerpc_debugfs_root,
488 msic, &fops_msic)) {
Michael Ellerman33875f02009-06-17 18:13:53 +0000489 pr_devel("axon_msi: debugfs_create_file failed!\n");
Michael Ellerman72cac212008-05-23 14:21:30 +1000490 return;
491 }
492}
493#endif /* DEBUG */