Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 1 | /** |
| 2 | * tpci200.c |
| 3 | * |
| 4 | * driver for the TEWS TPCI-200 device |
Samuel Iglesias Gonsalvez | 7685972 | 2012-11-16 16:19:58 +0100 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2009-2012 CERN (www.cern.ch) |
| 7 | * Author: Nicolas Serafini, EIC2 SA |
| 8 | * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com> |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 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 |
Samuel Iglesias Gonsalvez | b995069 | 2012-05-11 10:17:14 +0200 | [diff] [blame] | 12 | * Software Foundation; version 2 of the License. |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 15 | #include <linux/module.h> |
Samuel Iglesias Gonsalvez | 9f3059c | 2012-10-22 09:36:48 +0200 | [diff] [blame] | 16 | #include <linux/slab.h> |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 17 | #include "tpci200.h" |
| 18 | |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 19 | static const u16 tpci200_status_timeout[] = { |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 20 | TPCI200_A_TIMEOUT, |
| 21 | TPCI200_B_TIMEOUT, |
| 22 | TPCI200_C_TIMEOUT, |
| 23 | TPCI200_D_TIMEOUT, |
| 24 | }; |
| 25 | |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 26 | static const u16 tpci200_status_error[] = { |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 27 | TPCI200_A_ERROR, |
| 28 | TPCI200_B_ERROR, |
| 29 | TPCI200_C_ERROR, |
| 30 | TPCI200_D_ERROR, |
| 31 | }; |
| 32 | |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 33 | static const size_t tpci200_space_size[IPACK_SPACE_COUNT] = { |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 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, |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 38 | [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_SIZE, |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | static const size_t tpci200_space_interval[IPACK_SPACE_COUNT] = { |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 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, |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 46 | [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_INTERVAL, |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 49 | static struct tpci200_board *check_slot(struct ipack_device *dev) |
| 50 | { |
| 51 | struct tpci200_board *tpci200; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 52 | |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 53 | if (dev == NULL) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 54 | return NULL; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 55 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 56 | |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 57 | tpci200 = dev_get_drvdata(dev->bus->parent); |
| 58 | |
| 59 | if (tpci200 == NULL) { |
| 60 | dev_info(&dev->dev, "carrier board not found\n"); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 61 | return NULL; |
| 62 | } |
| 63 | |
| 64 | if (dev->slot >= TPCI200_NB_SLOT) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 65 | dev_info(&dev->dev, |
| 66 | "Slot [%d:%d] doesn't exist! Last tpci200 slot is %d.\n", |
Jens Taprogge | f9e314d | 2012-09-27 12:37:25 +0200 | [diff] [blame] | 67 | dev->bus->bus_nr, dev->slot, TPCI200_NB_SLOT-1); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 68 | return NULL; |
| 69 | } |
| 70 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 71 | return tpci200; |
| 72 | } |
| 73 | |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 74 | static void tpci200_clear_mask(struct tpci200_board *tpci200, |
| 75 | __le16 __iomem *addr, u16 mask) |
| 76 | { |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 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); |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void tpci200_set_mask(struct tpci200_board *tpci200, |
| 84 | __le16 __iomem *addr, u16 mask) |
| 85 | { |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 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); |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 92 | static void tpci200_unregister(struct tpci200_board *tpci200) |
| 93 | { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 94 | free_irq(tpci200->info->pdev->irq, (void *) tpci200); |
| 95 | |
| 96 | pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs); |
Samuel Iglesias Gonsálvez | 7987812 | 2012-09-11 13:35:04 +0200 | [diff] [blame] | 97 | pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 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); |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 101 | pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 102 | pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); |
Samuel Iglesias Gonsálvez | 7987812 | 2012-09-11 13:35:04 +0200 | [diff] [blame] | 103 | pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 104 | |
| 105 | pci_disable_device(tpci200->info->pdev); |
| 106 | pci_dev_put(tpci200->info->pdev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Jens Taprogge | 877adc4 | 2012-09-12 14:55:36 +0200 | [diff] [blame] | 109 | static 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 | |
| 117 | static 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 | |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 125 | static irqreturn_t tpci200_slot_irq(struct slot_irq *slot_irq) |
| 126 | { |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 127 | irqreturn_t ret; |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 128 | |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 129 | if (!slot_irq) |
| 130 | return -ENODEV; |
| 131 | ret = slot_irq->handler(slot_irq->arg); |
| 132 | |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 133 | return ret; |
| 134 | } |
| 135 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 136 | static irqreturn_t tpci200_interrupt(int irq, void *dev_id) |
| 137 | { |
| 138 | struct tpci200_board *tpci200 = (struct tpci200_board *) dev_id; |
Jens Taprogge | 6f2c12a | 2012-09-11 13:35:13 +0200 | [diff] [blame] | 139 | struct slot_irq *slot_irq; |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 140 | irqreturn_t ret; |
| 141 | u16 status_reg; |
| 142 | int i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 143 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 144 | /* Read status register */ |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 145 | status_reg = ioread16(&tpci200->info->interface_regs->status); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 146 | |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 147 | /* Did we cause the interrupt? */ |
| 148 | if (!(status_reg & TPCI200_SLOT_INT_MASK)) |
Jens Taprogge | 88ff848 | 2012-09-12 14:55:34 +0200 | [diff] [blame] | 149 | return IRQ_NONE; |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 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); |
Jens Taprogge | 877adc4 | 2012-09-12 14:55:36 +0200 | [diff] [blame] | 162 | tpci200_disable_irq(tpci200, i); |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 163 | } |
Jens Taprogge | 88ff848 | 2012-09-12 14:55:34 +0200 | [diff] [blame] | 164 | } |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 165 | rcu_read_unlock(); |
| 166 | |
| 167 | return IRQ_HANDLED; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 170 | static 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 | |
Jens Taprogge | c6e2dfa | 2012-09-13 12:32:21 +0200 | [diff] [blame] | 197 | static int tpci200_request_irq(struct ipack_device *dev, |
Jens Taprogge | faa75c4 | 2012-09-12 14:55:38 +0200 | [diff] [blame] | 198 | irqreturn_t (*handler)(void *), void *arg) |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 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, |
Johan Meiring | 9d10b22 | 2012-11-11 22:41:13 +0200 | [diff] [blame] | 213 | "Slot [%d:%d] IRQ already registered !\n", |
| 214 | dev->bus->bus_nr, |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 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", |
Jens Taprogge | f9e314d | 2012-09-27 12:37:25 +0200 | [diff] [blame] | 224 | dev->bus->bus_nr, dev->slot); |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 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 | */ |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 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 | |
| 242 | out_unlock: |
| 243 | mutex_unlock(&tpci200->mutex); |
| 244 | return res; |
| 245 | } |
| 246 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 247 | static int tpci200_register(struct tpci200_board *tpci200) |
| 248 | { |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 249 | int i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 250 | int res; |
Jens Taprogge | bb29ab8 | 2012-09-27 12:37:28 +0200 | [diff] [blame] | 251 | phys_addr_t ioidint_base; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 252 | unsigned short slot_ctrl; |
| 253 | |
| 254 | if (pci_enable_device(tpci200->info->pdev) < 0) |
| 255 | return -ENODEV; |
| 256 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 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) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 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); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 265 | goto out_disable_pci; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 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) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 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); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 277 | goto out_release_ip_space; |
| 278 | } |
| 279 | |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 280 | /* Request MEM8 space (Bar 5) */ |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 281 | res = pci_request_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR, |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 282 | "Carrier MEM8 space"); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 283 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 284 | dev_err(&tpci200->info->pdev->dev, |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 285 | "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 5!", |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 286 | tpci200->info->pdev->bus->number, |
| 287 | tpci200->info->pdev->devfn); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 288 | goto out_release_ioid_int_space; |
| 289 | } |
| 290 | |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 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 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 302 | /* Map internal tpci200 driver user space */ |
| 303 | tpci200->info->interface_regs = |
Samuel Iglesias Gonsálvez | 5b47f3c | 2012-07-20 09:39:05 +0200 | [diff] [blame] | 304 | ioremap_nocache(pci_resource_start(tpci200->info->pdev, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 305 | TPCI200_IP_INTERFACE_BAR), |
| 306 | TPCI200_IFACE_SIZE); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 307 | |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 308 | /* Initialize lock that protects interface_regs */ |
| 309 | spin_lock_init(&tpci200->regs_lock); |
| 310 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 311 | ioidint_base = pci_resource_start(tpci200->info->pdev, |
| 312 | TPCI200_IO_ID_INT_SPACES_BAR); |
Jens Taprogge | 84a08fa | 2012-09-27 12:37:29 +0200 | [diff] [blame] | 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; |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 317 | tpci200->mod_mem[IPACK_MEM8_SPACE] = |
Jens Taprogge | 84a08fa | 2012-09-27 12:37:29 +0200 | [diff] [blame] | 318 | pci_resource_start(tpci200->info->pdev, |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 319 | TPCI200_MEM8_SPACE_BAR); |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 320 | tpci200->mod_mem[IPACK_MEM16_SPACE] = |
| 321 | pci_resource_start(tpci200->info->pdev, |
| 322 | TPCI200_MEM16_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 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; |
Jens Taprogge | a93963a | 2012-09-27 12:37:35 +0200 | [diff] [blame] | 333 | for (i = 0; i < TPCI200_NB_SLOT; i++) |
Jens Taprogge | 28086cb | 2012-09-11 13:34:54 +0200 | [diff] [blame] | 334 | writew(slot_ctrl, &tpci200->info->interface_regs->control[i]); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 335 | |
| 336 | res = request_irq(tpci200->info->pdev->irq, |
| 337 | tpci200_interrupt, IRQF_SHARED, |
Samuel Iglesias Gonsalvez | c63a7dd | 2012-05-18 11:10:07 +0200 | [diff] [blame] | 338 | KBUILD_MODNAME, (void *) tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 339 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 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); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 344 | goto out_release_ioid_int_space; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | return 0; |
| 348 | |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 349 | out_release_mem8_space: |
| 350 | pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 351 | out_release_ioid_int_space: |
| 352 | pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR); |
| 353 | out_release_ip_space: |
| 354 | pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 355 | out_disable_pci: |
| 356 | pci_disable_device(tpci200->info->pdev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 357 | return res; |
| 358 | } |
| 359 | |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 360 | static int tpci200_get_clockrate(struct ipack_device *dev) |
| 361 | { |
| 362 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 363 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 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 | |
| 372 | static int tpci200_set_clockrate(struct ipack_device *dev, int mherz) |
| 373 | { |
| 374 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 375 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 376 | |
| 377 | if (!tpci200) |
| 378 | return -ENODEV; |
| 379 | |
| 380 | addr = &tpci200->info->interface_regs->control[dev->slot]; |
| 381 | |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 382 | switch (mherz) { |
| 383 | case 8: |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 384 | tpci200_clear_mask(tpci200, addr, TPCI200_CLK32); |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 385 | break; |
| 386 | case 32: |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 387 | tpci200_set_mask(tpci200, addr, TPCI200_CLK32); |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 388 | break; |
| 389 | default: |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 390 | return -EINVAL; |
| 391 | } |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static int tpci200_get_error(struct ipack_device *dev) |
| 396 | { |
| 397 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 398 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 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 | |
| 409 | static int tpci200_get_timeout(struct ipack_device *dev) |
| 410 | { |
| 411 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 412 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 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 | |
| 424 | static int tpci200_reset_timeout(struct ipack_device *dev) |
| 425 | { |
| 426 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 427 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 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 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 440 | static void tpci200_uninstall(struct tpci200_board *tpci200) |
| 441 | { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 442 | tpci200_unregister(tpci200); |
| 443 | kfree(tpci200->slots); |
| 444 | } |
| 445 | |
Stephen Hemminger | 9869a93 | 2012-09-10 11:14:01 -0700 | [diff] [blame] | 446 | static const struct ipack_bus_ops tpci200_bus_ops = { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 447 | .request_irq = tpci200_request_irq, |
| 448 | .free_irq = tpci200_free_irq, |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 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, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | static 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); |
Miguel Gómez | ec0ceb9 | 2012-06-07 10:24:54 +0200 | [diff] [blame] | 462 | if (tpci200->slots == NULL) |
| 463 | return -ENOMEM; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 464 | |
| 465 | res = tpci200_register(tpci200); |
Miguel Gómez | ec0ceb9 | 2012-06-07 10:24:54 +0200 | [diff] [blame] | 466 | if (res) { |
| 467 | kfree(tpci200->slots); |
| 468 | tpci200->slots = NULL; |
| 469 | return res; |
| 470 | } |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 471 | |
| 472 | mutex_init(&tpci200->mutex); |
| 473 | return 0; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 476 | static void tpci200_release_device(struct ipack_device *dev) |
| 477 | { |
| 478 | kfree(dev); |
| 479 | } |
| 480 | |
| 481 | static int tpci200_create_device(struct tpci200_board *tpci200, int i) |
| 482 | { |
Samuel Iglesias Gonsalvez | e926301 | 2013-03-08 09:21:47 +0100 | [diff] [blame] | 483 | int ret; |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 484 | enum ipack_space space; |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 485 | struct ipack_device *dev = |
| 486 | kzalloc(sizeof(struct ipack_device), GFP_KERNEL); |
| 487 | if (!dev) |
| 488 | return -ENOMEM; |
| 489 | dev->slot = i; |
| 490 | dev->bus = tpci200->info->ipack_bus; |
| 491 | dev->release = tpci200_release_device; |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 492 | |
| 493 | for (space = 0; space < IPACK_SPACE_COUNT; space++) { |
| 494 | dev->region[space].start = |
| 495 | tpci200->mod_mem[space] |
| 496 | + tpci200_space_interval[space] * i; |
| 497 | dev->region[space].size = tpci200_space_size[space]; |
| 498 | } |
Samuel Iglesias Gonsalvez | e926301 | 2013-03-08 09:21:47 +0100 | [diff] [blame] | 499 | |
| 500 | ret = ipack_device_init(dev); |
| 501 | if (ret < 0) { |
| 502 | ipack_put_device(dev); |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | ret = ipack_device_add(dev); |
| 507 | if (ret < 0) |
| 508 | ipack_put_device(dev); |
| 509 | |
| 510 | return ret; |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Stephen Hemminger | 2065945 | 2012-09-07 08:50:54 -0700 | [diff] [blame] | 513 | static int tpci200_pci_probe(struct pci_dev *pdev, |
| 514 | const struct pci_device_id *id) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 515 | { |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 516 | int ret, i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 517 | struct tpci200_board *tpci200; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 518 | u32 reg32; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 519 | |
| 520 | tpci200 = kzalloc(sizeof(struct tpci200_board), GFP_KERNEL); |
| 521 | if (!tpci200) |
| 522 | return -ENOMEM; |
| 523 | |
| 524 | tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL); |
| 525 | if (!tpci200->info) { |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 526 | ret = -ENOMEM; |
| 527 | goto out_err_info; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Samuel Iglesias Gonsálvez | b442bf7 | 2012-09-11 13:35:05 +0200 | [diff] [blame] | 530 | pci_dev_get(pdev); |
| 531 | |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 532 | /* Obtain a mapping of the carrier's PCI configuration registers */ |
| 533 | ret = pci_request_region(pdev, TPCI200_CFG_MEM_BAR, |
| 534 | KBUILD_MODNAME " Configuration Memory"); |
| 535 | if (ret) { |
| 536 | dev_err(&pdev->dev, "Failed to allocate PCI Configuration Memory"); |
| 537 | ret = -EBUSY; |
| 538 | goto out_err_pci_request; |
| 539 | } |
| 540 | tpci200->info->cfg_regs = ioremap_nocache( |
| 541 | pci_resource_start(pdev, TPCI200_CFG_MEM_BAR), |
| 542 | pci_resource_len(pdev, TPCI200_CFG_MEM_BAR)); |
| 543 | if (!tpci200->info->cfg_regs) { |
| 544 | dev_err(&pdev->dev, "Failed to map PCI Configuration Memory"); |
| 545 | ret = -EFAULT; |
| 546 | goto out_err_ioremap; |
| 547 | } |
| 548 | |
| 549 | /* Disable byte swapping for 16 bit IP module access. This will ensure |
| 550 | * that the Industrypack big endian byte order is preserved by the |
| 551 | * carrier. */ |
| 552 | reg32 = ioread32(tpci200->info->cfg_regs + LAS1_DESC); |
| 553 | reg32 |= 1 << LAS_BIT_BIGENDIAN; |
| 554 | iowrite32(reg32, tpci200->info->cfg_regs + LAS1_DESC); |
| 555 | |
| 556 | reg32 = ioread32(tpci200->info->cfg_regs + LAS2_DESC); |
| 557 | reg32 |= 1 << LAS_BIT_BIGENDIAN; |
| 558 | iowrite32(reg32, tpci200->info->cfg_regs + LAS2_DESC); |
| 559 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 560 | /* Save struct pci_dev pointer */ |
| 561 | tpci200->info->pdev = pdev; |
| 562 | tpci200->info->id_table = (struct pci_device_id *)id; |
| 563 | |
| 564 | /* register the device and initialize it */ |
| 565 | ret = tpci200_install(tpci200); |
| 566 | if (ret) { |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 567 | dev_err(&pdev->dev, "error during tpci200 install\n"); |
| 568 | ret = -ENODEV; |
| 569 | goto out_err_install; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 572 | /* Register the carrier in the industry pack bus driver */ |
| 573 | tpci200->info->ipack_bus = ipack_bus_register(&pdev->dev, |
| 574 | TPCI200_NB_SLOT, |
| 575 | &tpci200_bus_ops); |
| 576 | if (!tpci200->info->ipack_bus) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 577 | dev_err(&pdev->dev, |
| 578 | "error registering the carrier on ipack driver\n"); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 579 | ret = -EFAULT; |
| 580 | goto out_err_bus_register; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 581 | } |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 582 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 583 | /* save the bus number given by ipack to logging purpose */ |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 584 | tpci200->number = tpci200->info->ipack_bus->bus_nr; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 585 | dev_set_drvdata(&pdev->dev, tpci200); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 586 | |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 587 | for (i = 0; i < TPCI200_NB_SLOT; i++) |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 588 | tpci200_create_device(tpci200, i); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 589 | return 0; |
| 590 | |
| 591 | out_err_bus_register: |
| 592 | tpci200_uninstall(tpci200); |
| 593 | out_err_install: |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 594 | iounmap(tpci200->info->cfg_regs); |
| 595 | out_err_ioremap: |
| 596 | pci_release_region(pdev, TPCI200_CFG_MEM_BAR); |
| 597 | out_err_pci_request: |
Samuel Iglesias Gonsálvez | b442bf7 | 2012-09-11 13:35:05 +0200 | [diff] [blame] | 598 | pci_dev_put(pdev); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 599 | kfree(tpci200->info); |
| 600 | out_err_info: |
| 601 | kfree(tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 602 | return ret; |
| 603 | } |
| 604 | |
| 605 | static void __tpci200_pci_remove(struct tpci200_board *tpci200) |
| 606 | { |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 607 | ipack_bus_unregister(tpci200->info->ipack_bus); |
Samuel Iglesias Gonsálvez | 9c0d169 | 2012-09-11 13:35:10 +0200 | [diff] [blame] | 608 | tpci200_uninstall(tpci200); |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 609 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 610 | kfree(tpci200->info); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 611 | kfree(tpci200); |
| 612 | } |
| 613 | |
Bill Pemberton | 29c3544 | 2012-11-19 13:26:39 -0500 | [diff] [blame] | 614 | static void tpci200_pci_remove(struct pci_dev *dev) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 615 | { |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 616 | struct tpci200_board *tpci200 = pci_get_drvdata(dev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 617 | |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 618 | __tpci200_pci_remove(tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Miguel Gómez | 3953503 | 2012-06-07 10:24:58 +0200 | [diff] [blame] | 621 | static DEFINE_PCI_DEVICE_TABLE(tpci200_idtable) = { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 622 | { TPCI200_VENDOR_ID, TPCI200_DEVICE_ID, TPCI200_SUBVENDOR_ID, |
| 623 | TPCI200_SUBDEVICE_ID }, |
| 624 | { 0, }, |
| 625 | }; |
| 626 | |
Miguel Gómez | 3953503 | 2012-06-07 10:24:58 +0200 | [diff] [blame] | 627 | MODULE_DEVICE_TABLE(pci, tpci200_idtable); |
| 628 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 629 | static struct pci_driver tpci200_pci_drv = { |
| 630 | .name = "tpci200", |
| 631 | .id_table = tpci200_idtable, |
Stephen Hemminger | 2065945 | 2012-09-07 08:50:54 -0700 | [diff] [blame] | 632 | .probe = tpci200_pci_probe, |
Bill Pemberton | c5dee46 | 2012-11-19 13:21:31 -0500 | [diff] [blame] | 633 | .remove = tpci200_pci_remove, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 634 | }; |
| 635 | |
Wei Yongjun | 1bc7c1c | 2012-10-18 23:18:46 +0800 | [diff] [blame] | 636 | module_pci_driver(tpci200_pci_drv); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 637 | |
| 638 | MODULE_DESCRIPTION("TEWS TPCI-200 device driver"); |
| 639 | MODULE_LICENSE("GPL"); |