aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ipack/carriers
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-16 11:14:18 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-16 11:14:18 -0500
commit05e5027efc9c0bb6d1d04cde279afbafca0a7929 (patch)
tree733b0291db6cc6c13844b97e3c7bf593b6711d66 /drivers/ipack/carriers
parent76859725ad31ac480d55bf176e5bbe0f9ab6e6cb (diff)
Staging: ipack: move out of staging
The ipack subsystem is cleaned up enough to now move out of the staging tree, and into drivers/ipack. Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com> Cc: Jens Taprogge <jens.taprogge@taprogge.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/ipack/carriers')
-rw-r--r--drivers/ipack/carriers/Kconfig7
-rw-r--r--drivers/ipack/carriers/Makefile1
-rw-r--r--drivers/ipack/carriers/tpci200.c627
-rw-r--r--drivers/ipack/carriers/tpci200.h168
4 files changed, 803 insertions, 0 deletions
diff --git a/drivers/ipack/carriers/Kconfig b/drivers/ipack/carriers/Kconfig
new file mode 100644
index 000000000000..922ff5c35acc
--- /dev/null
+++ b/drivers/ipack/carriers/Kconfig
@@ -0,0 +1,7 @@
1config BOARD_TPCI200
2 tristate "Support for the TEWS TPCI-200 IndustryPack carrier board"
3 depends on IPACK_BUS
4 depends on PCI
5 help
6 This driver adds support for the TEWS TPCI200 IndustryPack carrier board.
7 default n
diff --git a/drivers/ipack/carriers/Makefile b/drivers/ipack/carriers/Makefile
new file mode 100644
index 000000000000..d8b76459300f
--- /dev/null
+++ b/drivers/ipack/carriers/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_BOARD_TPCI200) += tpci200.o
diff --git a/drivers/ipack/carriers/tpci200.c b/drivers/ipack/carriers/tpci200.c
new file mode 100644
index 000000000000..c1a19b274c23
--- /dev/null
+++ b/drivers/ipack/carriers/tpci200.c
@@ -0,0 +1,627 @@
1/**
2 * tpci200.c
3 *
4 * driver for the TEWS TPCI-200 device
5 *
6 * Copyright (C) 2009-2012 CERN (www.cern.ch)
7 * Author: Nicolas Serafini, EIC2 SA
8 * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; version 2 of the License.
13 */
14
15#include <linux/module.h>
16#include <linux/slab.h>
17#include "tpci200.h"
18
19static const u16 tpci200_status_timeout[] = {
20 TPCI200_A_TIMEOUT,
21 TPCI200_B_TIMEOUT,
22 TPCI200_C_TIMEOUT,
23 TPCI200_D_TIMEOUT,
24};
25
26static const u16 tpci200_status_error[] = {
27 TPCI200_A_ERROR,
28 TPCI200_B_ERROR,
29 TPCI200_C_ERROR,
30 TPCI200_D_ERROR,
31};
32
33static const size_t tpci200_space_size[IPACK_SPACE_COUNT] = {
34 [IPACK_IO_SPACE] = TPCI200_IO_SPACE_SIZE,
35 [IPACK_ID_SPACE] = TPCI200_ID_SPACE_SIZE,
36 [IPACK_INT_SPACE] = TPCI200_INT_SPACE_SIZE,
37 [IPACK_MEM8_SPACE] = TPCI200_MEM8_SPACE_SIZE,
38 [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_SIZE,
39};
40
41static const size_t tpci200_space_interval[IPACK_SPACE_COUNT] = {
42 [IPACK_IO_SPACE] = TPCI200_IO_SPACE_INTERVAL,
43 [IPACK_ID_SPACE] = TPCI200_ID_SPACE_INTERVAL,
44 [IPACK_INT_SPACE] = TPCI200_INT_SPACE_INTERVAL,
45 [IPACK_MEM8_SPACE] = TPCI200_MEM8_SPACE_INTERVAL,
46 [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_INTERVAL,
47};
48
49static struct tpci200_board *check_slot(struct ipack_device *dev)
50{
51 struct tpci200_board *tpci200;
52
53 if (dev == NULL)
54 return NULL;
55
56
57 tpci200 = dev_get_drvdata(dev->bus->parent);
58
59 if (tpci200 == NULL) {
60 dev_info(&dev->dev, "carrier board not found\n");
61 return NULL;
62 }
63
64 if (dev->slot >= TPCI200_NB_SLOT) {
65 dev_info(&dev->dev,
66 "Slot [%d:%d] doesn't exist! Last tpci200 slot is %d.\n",
67 dev->bus->bus_nr, dev->slot, TPCI200_NB_SLOT-1);
68 return NULL;
69 }
70
71 return tpci200;
72}
73
74static void tpci200_clear_mask(struct tpci200_board *tpci200,
75 __le16 __iomem *addr, u16 mask)
76{
77 unsigned long flags;
78 spin_lock_irqsave(&tpci200->regs_lock, flags);
79 iowrite16(ioread16(addr) & (~mask), addr);
80 spin_unlock_irqrestore(&tpci200->regs_lock, flags);
81}
82
83static void tpci200_set_mask(struct tpci200_board *tpci200,
84 __le16 __iomem *addr, u16 mask)
85{
86 unsigned long flags;
87 spin_lock_irqsave(&tpci200->regs_lock, flags);
88 iowrite16(ioread16(addr) | mask, addr);
89 spin_unlock_irqrestore(&tpci200->regs_lock, flags);
90}
91
92static void tpci200_unregister(struct tpci200_board *tpci200)
93{
94 free_irq(tpci200->info->pdev->irq, (void *) tpci200);
95
96 pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs);
97 pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs);
98
99 pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
100 pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
101 pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR);
102 pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR);
103 pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR);
104
105 pci_disable_device(tpci200->info->pdev);
106 pci_dev_put(tpci200->info->pdev);
107}
108
109static void tpci200_enable_irq(struct tpci200_board *tpci200,
110 int islot)
111{
112 tpci200_set_mask(tpci200,
113 &tpci200->info->interface_regs->control[islot],
114 TPCI200_INT0_EN | TPCI200_INT1_EN);
115}
116
117static void tpci200_disable_irq(struct tpci200_board *tpci200,
118 int islot)
119{
120 tpci200_clear_mask(tpci200,
121 &tpci200->info->interface_regs->control[islot],
122 TPCI200_INT0_EN | TPCI200_INT1_EN);
123}
124
125static irqreturn_t tpci200_slot_irq(struct slot_irq *slot_irq)
126{
127 irqreturn_t ret;
128
129 if (!slot_irq)
130 return -ENODEV;
131 ret = slot_irq->handler(slot_irq->arg);
132
133 return ret;
134}
135
136static irqreturn_t tpci200_interrupt(int irq, void *dev_id)
137{
138 struct tpci200_board *tpci200 = (struct tpci200_board *) dev_id;
139 struct slot_irq *slot_irq;
140 irqreturn_t ret;
141 u16 status_reg;
142 int i;
143
144 /* Read status register */
145 status_reg = ioread16(&tpci200->info->interface_regs->status);
146
147 /* Did we cause the interrupt? */
148 if (!(status_reg & TPCI200_SLOT_INT_MASK))
149 return IRQ_NONE;
150
151 /* callback to the IRQ handler for the corresponding slot */
152 rcu_read_lock();
153 for (i = 0; i < TPCI200_NB_SLOT; i++) {
154 if (!(status_reg & ((TPCI200_A_INT0 | TPCI200_A_INT1) << (2 * i))))
155 continue;
156 slot_irq = rcu_dereference(tpci200->slots[i].irq);
157 ret = tpci200_slot_irq(slot_irq);
158 if (ret == -ENODEV) {
159 dev_info(&tpci200->info->pdev->dev,
160 "No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n",
161 tpci200->number, i);
162 tpci200_disable_irq(tpci200, i);
163 }
164 }
165 rcu_read_unlock();
166
167 return IRQ_HANDLED;
168}
169
170static int tpci200_free_irq(struct ipack_device *dev)
171{
172 struct slot_irq *slot_irq;
173 struct tpci200_board *tpci200;
174
175 tpci200 = check_slot(dev);
176 if (tpci200 == NULL)
177 return -EINVAL;
178
179 if (mutex_lock_interruptible(&tpci200->mutex))
180 return -ERESTARTSYS;
181
182 if (tpci200->slots[dev->slot].irq == NULL) {
183 mutex_unlock(&tpci200->mutex);
184 return -EINVAL;
185 }
186
187 tpci200_disable_irq(tpci200, dev->slot);
188 slot_irq = tpci200->slots[dev->slot].irq;
189 /* uninstall handler */
190 RCU_INIT_POINTER(tpci200->slots[dev->slot].irq, NULL);
191 synchronize_rcu();
192 kfree(slot_irq);
193 mutex_unlock(&tpci200->mutex);
194 return 0;
195}
196
197static int tpci200_request_irq(struct ipack_device *dev,
198 irqreturn_t (*handler)(void *), void *arg)
199{
200 int res = 0;
201 struct slot_irq *slot_irq;
202 struct tpci200_board *tpci200;
203
204 tpci200 = check_slot(dev);
205 if (tpci200 == NULL)
206 return -EINVAL;
207
208 if (mutex_lock_interruptible(&tpci200->mutex))
209 return -ERESTARTSYS;
210
211 if (tpci200->slots[dev->slot].irq != NULL) {
212 dev_err(&dev->dev,
213 "Slot [%d:%d] IRQ already registered !\n",
214 dev->bus->bus_nr,
215 dev->slot);
216 res = -EINVAL;
217 goto out_unlock;
218 }
219
220 slot_irq = kzalloc(sizeof(struct slot_irq), GFP_KERNEL);
221 if (slot_irq == NULL) {
222 dev_err(&dev->dev,
223 "Slot [%d:%d] unable to allocate memory for IRQ !\n",
224 dev->bus->bus_nr, dev->slot);
225 res = -ENOMEM;
226 goto out_unlock;
227 }
228
229 /*
230 * WARNING: Setup Interrupt Vector in the IndustryPack device
231 * before an IRQ request.
232 * Read the User Manual of your IndustryPack device to know
233 * where to write the vector in memory.
234 */
235 slot_irq->handler = handler;
236 slot_irq->arg = arg;
237 slot_irq->holder = dev;
238
239 rcu_assign_pointer(tpci200->slots[dev->slot].irq, slot_irq);
240 tpci200_enable_irq(tpci200, dev->slot);
241
242out_unlock:
243 mutex_unlock(&tpci200->mutex);
244 return res;
245}
246
247static int tpci200_register(struct tpci200_board *tpci200)
248{
249 int i;
250 int res;
251 phys_addr_t ioidint_base;
252 unsigned short slot_ctrl;
253
254 if (pci_enable_device(tpci200->info->pdev) < 0)
255 return -ENODEV;
256
257 /* Request IP interface register (Bar 2) */
258 res = pci_request_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR,
259 "Carrier IP interface registers");
260 if (res) {
261 dev_err(&tpci200->info->pdev->dev,
262 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !",
263 tpci200->info->pdev->bus->number,
264 tpci200->info->pdev->devfn);
265 goto out_disable_pci;
266 }
267
268 /* Request IO ID INT space (Bar 3) */
269 res = pci_request_region(tpci200->info->pdev,
270 TPCI200_IO_ID_INT_SPACES_BAR,
271 "Carrier IO ID INT space");
272 if (res) {
273 dev_err(&tpci200->info->pdev->dev,
274 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !",
275 tpci200->info->pdev->bus->number,
276 tpci200->info->pdev->devfn);
277 goto out_release_ip_space;
278 }
279
280 /* Request MEM8 space (Bar 5) */
281 res = pci_request_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR,
282 "Carrier MEM8 space");
283 if (res) {
284 dev_err(&tpci200->info->pdev->dev,
285 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 5!",
286 tpci200->info->pdev->bus->number,
287 tpci200->info->pdev->devfn);
288 goto out_release_ioid_int_space;
289 }
290
291 /* Request MEM16 space (Bar 4) */
292 res = pci_request_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR,
293 "Carrier MEM16 space");
294 if (res) {
295 dev_err(&tpci200->info->pdev->dev,
296 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!",
297 tpci200->info->pdev->bus->number,
298 tpci200->info->pdev->devfn);
299 goto out_release_mem8_space;
300 }
301
302 /* Map internal tpci200 driver user space */
303 tpci200->info->interface_regs =
304 ioremap_nocache(pci_resource_start(tpci200->info->pdev,
305 TPCI200_IP_INTERFACE_BAR),
306 TPCI200_IFACE_SIZE);
307
308 /* Initialize lock that protects interface_regs */
309 spin_lock_init(&tpci200->regs_lock);
310
311 ioidint_base = pci_resource_start(tpci200->info->pdev,
312 TPCI200_IO_ID_INT_SPACES_BAR);
313 tpci200->mod_mem[IPACK_IO_SPACE] = ioidint_base + TPCI200_IO_SPACE_OFF;
314 tpci200->mod_mem[IPACK_ID_SPACE] = ioidint_base + TPCI200_ID_SPACE_OFF;
315 tpci200->mod_mem[IPACK_INT_SPACE] =
316 ioidint_base + TPCI200_INT_SPACE_OFF;
317 tpci200->mod_mem[IPACK_MEM8_SPACE] =
318 pci_resource_start(tpci200->info->pdev,
319 TPCI200_MEM8_SPACE_BAR);
320 tpci200->mod_mem[IPACK_MEM16_SPACE] =
321 pci_resource_start(tpci200->info->pdev,
322 TPCI200_MEM16_SPACE_BAR);
323
324 /* Set the default parameters of the slot
325 * INT0 disabled, level sensitive
326 * INT1 disabled, level sensitive
327 * error interrupt disabled
328 * timeout interrupt disabled
329 * recover time disabled
330 * clock rate 8 MHz
331 */
332 slot_ctrl = 0;
333 for (i = 0; i < TPCI200_NB_SLOT; i++)
334 writew(slot_ctrl, &tpci200->info->interface_regs->control[i]);
335
336 res = request_irq(tpci200->info->pdev->irq,
337 tpci200_interrupt, IRQF_SHARED,
338 KBUILD_MODNAME, (void *) tpci200);
339 if (res) {
340 dev_err(&tpci200->info->pdev->dev,
341 "(bn 0x%X, sn 0x%X) unable to register IRQ !",
342 tpci200->info->pdev->bus->number,
343 tpci200->info->pdev->devfn);
344 goto out_release_ioid_int_space;
345 }
346
347 return 0;
348
349out_release_mem8_space:
350 pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR);
351out_release_ioid_int_space:
352 pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
353out_release_ip_space:
354 pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
355out_disable_pci:
356 pci_disable_device(tpci200->info->pdev);
357 return res;
358}
359
360static int tpci200_get_clockrate(struct ipack_device *dev)
361{
362 struct tpci200_board *tpci200 = check_slot(dev);
363 __le16 __iomem *addr;
364
365 if (!tpci200)
366 return -ENODEV;
367
368 addr = &tpci200->info->interface_regs->control[dev->slot];
369 return (ioread16(addr) & TPCI200_CLK32) ? 32 : 8;
370}
371
372static int tpci200_set_clockrate(struct ipack_device *dev, int mherz)
373{
374 struct tpci200_board *tpci200 = check_slot(dev);
375 __le16 __iomem *addr;
376
377 if (!tpci200)
378 return -ENODEV;
379
380 addr = &tpci200->info->interface_regs->control[dev->slot];
381
382 switch (mherz) {
383 case 8:
384 tpci200_clear_mask(tpci200, addr, TPCI200_CLK32);
385 break;
386 case 32:
387 tpci200_set_mask(tpci200, addr, TPCI200_CLK32);
388 break;
389 default:
390 return -EINVAL;
391 }
392 return 0;
393}
394
395static int tpci200_get_error(struct ipack_device *dev)
396{
397 struct tpci200_board *tpci200 = check_slot(dev);
398 __le16 __iomem *addr;
399 u16 mask;
400
401 if (!tpci200)
402 return -ENODEV;
403
404 addr = &tpci200->info->interface_regs->status;
405 mask = tpci200_status_error[dev->slot];
406 return (ioread16(addr) & mask) ? 1 : 0;
407}
408
409static int tpci200_get_timeout(struct ipack_device *dev)
410{
411 struct tpci200_board *tpci200 = check_slot(dev);
412 __le16 __iomem *addr;
413 u16 mask;
414
415 if (!tpci200)
416 return -ENODEV;
417
418 addr = &tpci200->info->interface_regs->status;
419 mask = tpci200_status_timeout[dev->slot];
420
421 return (ioread16(addr) & mask) ? 1 : 0;
422}
423
424static int tpci200_reset_timeout(struct ipack_device *dev)
425{
426 struct tpci200_board *tpci200 = check_slot(dev);
427 __le16 __iomem *addr;
428 u16 mask;
429
430 if (!tpci200)
431 return -ENODEV;
432
433 addr = &tpci200->info->interface_regs->status;
434 mask = tpci200_status_timeout[dev->slot];
435
436 iowrite16(mask, addr);
437 return 0;
438}
439
440static void tpci200_uninstall(struct tpci200_board *tpci200)
441{
442 tpci200_unregister(tpci200);
443 kfree(tpci200->slots);
444}
445
446static const struct ipack_bus_ops tpci200_bus_ops = {
447 .request_irq = tpci200_request_irq,
448 .free_irq = tpci200_free_irq,
449 .get_clockrate = tpci200_get_clockrate,
450 .set_clockrate = tpci200_set_clockrate,
451 .get_error = tpci200_get_error,
452 .get_timeout = tpci200_get_timeout,
453 .reset_timeout = tpci200_reset_timeout,
454};
455
456static int tpci200_install(struct tpci200_board *tpci200)
457{
458 int res;
459
460 tpci200->slots = kzalloc(
461 TPCI200_NB_SLOT * sizeof(struct tpci200_slot), GFP_KERNEL);
462 if (tpci200->slots == NULL)
463 return -ENOMEM;
464
465 res = tpci200_register(tpci200);
466 if (res) {
467 kfree(tpci200->slots);
468 tpci200->slots = NULL;
469 return res;
470 }
471
472 mutex_init(&tpci200->mutex);
473 return 0;
474}
475
476static void tpci200_release_device(struct ipack_device *dev)
477{
478 kfree(dev);
479}
480
481static int tpci200_create_device(struct tpci200_board *tpci200, int i)
482{
483 enum ipack_space space;
484 struct ipack_device *dev =
485 kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
486 if (!dev)
487 return -ENOMEM;
488 dev->slot = i;
489 dev->bus = tpci200->info->ipack_bus;
490 dev->release = tpci200_release_device;
491
492 for (space = 0; space < IPACK_SPACE_COUNT; space++) {
493 dev->region[space].start =
494 tpci200->mod_mem[space]
495 + tpci200_space_interval[space] * i;
496 dev->region[space].size = tpci200_space_size[space];
497 }
498 return ipack_device_register(dev);
499}
500
501static int tpci200_pci_probe(struct pci_dev *pdev,
502 const struct pci_device_id *id)
503{
504 int ret, i;
505 struct tpci200_board *tpci200;
506 u32 reg32;
507
508 tpci200 = kzalloc(sizeof(struct tpci200_board), GFP_KERNEL);
509 if (!tpci200)
510 return -ENOMEM;
511
512 tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL);
513 if (!tpci200->info) {
514 ret = -ENOMEM;
515 goto out_err_info;
516 }
517
518 pci_dev_get(pdev);
519
520 /* Obtain a mapping of the carrier's PCI configuration registers */
521 ret = pci_request_region(pdev, TPCI200_CFG_MEM_BAR,
522 KBUILD_MODNAME " Configuration Memory");
523 if (ret) {
524 dev_err(&pdev->dev, "Failed to allocate PCI Configuration Memory");
525 ret = -EBUSY;
526 goto out_err_pci_request;
527 }
528 tpci200->info->cfg_regs = ioremap_nocache(
529 pci_resource_start(pdev, TPCI200_CFG_MEM_BAR),
530 pci_resource_len(pdev, TPCI200_CFG_MEM_BAR));
531 if (!tpci200->info->cfg_regs) {
532 dev_err(&pdev->dev, "Failed to map PCI Configuration Memory");
533 ret = -EFAULT;
534 goto out_err_ioremap;
535 }
536
537 /* Disable byte swapping for 16 bit IP module access. This will ensure
538 * that the Industrypack big endian byte order is preserved by the
539 * carrier. */
540 reg32 = ioread32(tpci200->info->cfg_regs + LAS1_DESC);
541 reg32 |= 1 << LAS_BIT_BIGENDIAN;
542 iowrite32(reg32, tpci200->info->cfg_regs + LAS1_DESC);
543
544 reg32 = ioread32(tpci200->info->cfg_regs + LAS2_DESC);
545 reg32 |= 1 << LAS_BIT_BIGENDIAN;
546 iowrite32(reg32, tpci200->info->cfg_regs + LAS2_DESC);
547
548 /* Save struct pci_dev pointer */
549 tpci200->info->pdev = pdev;
550 tpci200->info->id_table = (struct pci_device_id *)id;
551
552 /* register the device and initialize it */
553 ret = tpci200_install(tpci200);
554 if (ret) {
555 dev_err(&pdev->dev, "error during tpci200 install\n");
556 ret = -ENODEV;
557 goto out_err_install;
558 }
559
560 /* Register the carrier in the industry pack bus driver */
561 tpci200->info->ipack_bus = ipack_bus_register(&pdev->dev,
562 TPCI200_NB_SLOT,
563 &tpci200_bus_ops);
564 if (!tpci200->info->ipack_bus) {
565 dev_err(&pdev->dev,
566 "error registering the carrier on ipack driver\n");
567 ret = -EFAULT;
568 goto out_err_bus_register;
569 }
570
571 /* save the bus number given by ipack to logging purpose */
572 tpci200->number = tpci200->info->ipack_bus->bus_nr;
573 dev_set_drvdata(&pdev->dev, tpci200);
574
575 for (i = 0; i < TPCI200_NB_SLOT; i++)
576 tpci200_create_device(tpci200, i);
577 return 0;
578
579out_err_bus_register:
580 tpci200_uninstall(tpci200);
581out_err_install:
582 iounmap(tpci200->info->cfg_regs);
583out_err_ioremap:
584 pci_release_region(pdev, TPCI200_CFG_MEM_BAR);
585out_err_pci_request:
586 pci_dev_put(pdev);
587 kfree(tpci200->info);
588out_err_info:
589 kfree(tpci200);
590 return ret;
591}
592
593static void __tpci200_pci_remove(struct tpci200_board *tpci200)
594{
595 ipack_bus_unregister(tpci200->info->ipack_bus);
596 tpci200_uninstall(tpci200);
597
598 kfree(tpci200->info);
599 kfree(tpci200);
600}
601
602static void __devexit tpci200_pci_remove(struct pci_dev *dev)
603{
604 struct tpci200_board *tpci200 = pci_get_drvdata(dev);
605
606 __tpci200_pci_remove(tpci200);
607}
608
609static DEFINE_PCI_DEVICE_TABLE(tpci200_idtable) = {
610 { TPCI200_VENDOR_ID, TPCI200_DEVICE_ID, TPCI200_SUBVENDOR_ID,
611 TPCI200_SUBDEVICE_ID },
612 { 0, },
613};
614
615MODULE_DEVICE_TABLE(pci, tpci200_idtable);
616
617static struct pci_driver tpci200_pci_drv = {
618 .name = "tpci200",
619 .id_table = tpci200_idtable,
620 .probe = tpci200_pci_probe,
621 .remove = __devexit_p(tpci200_pci_remove),
622};
623
624module_pci_driver(tpci200_pci_drv);
625
626MODULE_DESCRIPTION("TEWS TPCI-200 device driver");
627MODULE_LICENSE("GPL");
diff --git a/drivers/ipack/carriers/tpci200.h b/drivers/ipack/carriers/tpci200.h
new file mode 100644
index 000000000000..8d9be277b34d
--- /dev/null
+++ b/drivers/ipack/carriers/tpci200.h
@@ -0,0 +1,168 @@
1/**
2 * tpci200.h
3 *
4 * driver for the carrier TEWS TPCI-200
5 *
6 * Copyright (C) 2009-2012 CERN (www.cern.ch)
7 * Author: Nicolas Serafini, EIC2 SA
8 * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; version 2 of the License.
13 */
14
15#ifndef _TPCI200_H_
16#define _TPCI200_H_
17
18#include <linux/limits.h>
19#include <linux/pci.h>
20#include <linux/spinlock.h>
21#include <linux/swab.h>
22#include <linux/io.h>
23
24#include "../ipack.h"
25
26#define TPCI200_NB_SLOT 0x4
27#define TPCI200_NB_BAR 0x6
28
29#define TPCI200_VENDOR_ID 0x1498
30#define TPCI200_DEVICE_ID 0x30C8
31#define TPCI200_SUBVENDOR_ID 0x1498
32#define TPCI200_SUBDEVICE_ID 0x300A
33
34#define TPCI200_CFG_MEM_BAR 0
35#define TPCI200_IP_INTERFACE_BAR 2
36#define TPCI200_IO_ID_INT_SPACES_BAR 3
37#define TPCI200_MEM16_SPACE_BAR 4
38#define TPCI200_MEM8_SPACE_BAR 5
39
40struct tpci200_regs {
41 __le16 revision;
42 /* writes to control should occur with the mutex held to protect
43 * read-modify-write operations */
44 __le16 control[4];
45 __le16 reset;
46 __le16 status;
47 u8 reserved[242];
48} __packed;
49
50#define TPCI200_IFACE_SIZE 0x100
51
52#define TPCI200_IO_SPACE_OFF 0x0000
53#define TPCI200_IO_SPACE_INTERVAL 0x0100
54#define TPCI200_IO_SPACE_SIZE 0x0080
55#define TPCI200_ID_SPACE_OFF 0x0080
56#define TPCI200_ID_SPACE_INTERVAL 0x0100
57#define TPCI200_ID_SPACE_SIZE 0x0040
58#define TPCI200_INT_SPACE_OFF 0x00C0
59#define TPCI200_INT_SPACE_INTERVAL 0x0100
60#define TPCI200_INT_SPACE_SIZE 0x0040
61#define TPCI200_IOIDINT_SIZE 0x0400
62
63#define TPCI200_MEM8_SPACE_INTERVAL 0x00400000
64#define TPCI200_MEM8_SPACE_SIZE 0x00400000
65#define TPCI200_MEM16_SPACE_INTERVAL 0x00800000
66#define TPCI200_MEM16_SPACE_SIZE 0x00800000
67
68/* control field in tpci200_regs */
69#define TPCI200_INT0_EN 0x0040
70#define TPCI200_INT1_EN 0x0080
71#define TPCI200_INT0_EDGE 0x0010
72#define TPCI200_INT1_EDGE 0x0020
73#define TPCI200_ERR_INT_EN 0x0008
74#define TPCI200_TIME_INT_EN 0x0004
75#define TPCI200_RECOVER_EN 0x0002
76#define TPCI200_CLK32 0x0001
77
78/* reset field in tpci200_regs */
79#define TPCI200_A_RESET 0x0001
80#define TPCI200_B_RESET 0x0002
81#define TPCI200_C_RESET 0x0004
82#define TPCI200_D_RESET 0x0008
83
84/* status field in tpci200_regs */
85#define TPCI200_A_TIMEOUT 0x1000
86#define TPCI200_B_TIMEOUT 0x2000
87#define TPCI200_C_TIMEOUT 0x4000
88#define TPCI200_D_TIMEOUT 0x8000
89
90#define TPCI200_A_ERROR 0x0100
91#define TPCI200_B_ERROR 0x0200
92#define TPCI200_C_ERROR 0x0400
93#define TPCI200_D_ERROR 0x0800
94
95#define TPCI200_A_INT0 0x0001
96#define TPCI200_A_INT1 0x0002
97#define TPCI200_B_INT0 0x0004
98#define TPCI200_B_INT1 0x0008
99#define TPCI200_C_INT0 0x0010
100#define TPCI200_C_INT1 0x0020
101#define TPCI200_D_INT0 0x0040
102#define TPCI200_D_INT1 0x0080
103
104#define TPCI200_SLOT_INT_MASK 0x00FF
105
106/* PCI Configuration registers. The PCI bridge is a PLX Technology PCI9030. */
107#define LAS1_DESC 0x2C
108#define LAS2_DESC 0x30
109
110/* Bits in the LAS?_DESC registers */
111#define LAS_BIT_BIGENDIAN 24
112
113#define VME_IOID_SPACE "IOID"
114#define VME_MEM_SPACE "MEM"
115
116/**
117 * struct slot_irq - slot IRQ definition.
118 * @vector Vector number
119 * @handler Handler called when IRQ arrives
120 * @arg Handler argument
121 *
122 */
123struct slot_irq {
124 struct ipack_device *holder;
125 int vector;
126 irqreturn_t (*handler)(void *);
127 void *arg;
128};
129
130/**
131 * struct tpci200_slot - data specific to the tpci200 slot.
132 * @slot_id Slot identification gived to external interface
133 * @irq Slot IRQ infos
134 * @io_phys IO physical base address register of the slot
135 * @id_phys ID physical base address register of the slot
136 * @int_phys INT physical base address register of the slot
137 * @mem_phys MEM physical base address register of the slot
138 *
139 */
140struct tpci200_slot {
141 struct slot_irq *irq;
142};
143
144/**
145 * struct tpci200_infos - informations specific of the TPCI200 tpci200.
146 * @pci_dev PCI device
147 * @interface_regs Pointer to IP interface space (Bar 2)
148 * @ioidint_space Pointer to IP ID, IO and INT space (Bar 3)
149 * @mem8_space Pointer to MEM space (Bar 4)
150 *
151 */
152struct tpci200_infos {
153 struct pci_dev *pdev;
154 struct pci_device_id *id_table;
155 struct tpci200_regs __iomem *interface_regs;
156 void __iomem *cfg_regs;
157 struct ipack_bus_device *ipack_bus;
158};
159struct tpci200_board {
160 unsigned int number;
161 struct mutex mutex;
162 spinlock_t regs_lock;
163 struct tpci200_slot *slots;
164 struct tpci200_infos *info;
165 phys_addr_t mod_mem[IPACK_SPACE_COUNT];
166};
167
168#endif /* _TPCI200_H_ */