Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 2 | /** |
| 3 | * tpci200.c |
| 4 | * |
| 5 | * driver for the TEWS TPCI-200 device |
Samuel Iglesias Gonsalvez | 7685972 | 2012-11-16 16:19:58 +0100 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2009-2012 CERN (www.cern.ch) |
| 8 | * Author: Nicolas Serafini, EIC2 SA |
| 9 | * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com> |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 12 | #include <linux/module.h> |
Samuel Iglesias Gonsalvez | 9f3059c | 2012-10-22 09:36:48 +0200 | [diff] [blame] | 13 | #include <linux/slab.h> |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 14 | #include "tpci200.h" |
| 15 | |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 16 | static const u16 tpci200_status_timeout[] = { |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 17 | TPCI200_A_TIMEOUT, |
| 18 | TPCI200_B_TIMEOUT, |
| 19 | TPCI200_C_TIMEOUT, |
| 20 | TPCI200_D_TIMEOUT, |
| 21 | }; |
| 22 | |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 23 | static const u16 tpci200_status_error[] = { |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 24 | TPCI200_A_ERROR, |
| 25 | TPCI200_B_ERROR, |
| 26 | TPCI200_C_ERROR, |
| 27 | TPCI200_D_ERROR, |
| 28 | }; |
| 29 | |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 30 | static const size_t tpci200_space_size[IPACK_SPACE_COUNT] = { |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 31 | [IPACK_IO_SPACE] = TPCI200_IO_SPACE_SIZE, |
| 32 | [IPACK_ID_SPACE] = TPCI200_ID_SPACE_SIZE, |
| 33 | [IPACK_INT_SPACE] = TPCI200_INT_SPACE_SIZE, |
| 34 | [IPACK_MEM8_SPACE] = TPCI200_MEM8_SPACE_SIZE, |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 35 | [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_SIZE, |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static const size_t tpci200_space_interval[IPACK_SPACE_COUNT] = { |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 39 | [IPACK_IO_SPACE] = TPCI200_IO_SPACE_INTERVAL, |
| 40 | [IPACK_ID_SPACE] = TPCI200_ID_SPACE_INTERVAL, |
| 41 | [IPACK_INT_SPACE] = TPCI200_INT_SPACE_INTERVAL, |
| 42 | [IPACK_MEM8_SPACE] = TPCI200_MEM8_SPACE_INTERVAL, |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 43 | [IPACK_MEM16_SPACE] = TPCI200_MEM16_SPACE_INTERVAL, |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 46 | static struct tpci200_board *check_slot(struct ipack_device *dev) |
| 47 | { |
| 48 | struct tpci200_board *tpci200; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 49 | |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 50 | if (dev == NULL) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 51 | return NULL; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 52 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 53 | |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 54 | tpci200 = dev_get_drvdata(dev->bus->parent); |
| 55 | |
| 56 | if (tpci200 == NULL) { |
| 57 | dev_info(&dev->dev, "carrier board not found\n"); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 58 | return NULL; |
| 59 | } |
| 60 | |
| 61 | if (dev->slot >= TPCI200_NB_SLOT) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 62 | dev_info(&dev->dev, |
| 63 | "Slot [%d:%d] doesn't exist! Last tpci200 slot is %d.\n", |
Jens Taprogge | f9e314d | 2012-09-27 12:37:25 +0200 | [diff] [blame] | 64 | dev->bus->bus_nr, dev->slot, TPCI200_NB_SLOT-1); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 65 | return NULL; |
| 66 | } |
| 67 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 68 | return tpci200; |
| 69 | } |
| 70 | |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 71 | static void tpci200_clear_mask(struct tpci200_board *tpci200, |
| 72 | __le16 __iomem *addr, u16 mask) |
| 73 | { |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 74 | unsigned long flags; |
| 75 | spin_lock_irqsave(&tpci200->regs_lock, flags); |
| 76 | iowrite16(ioread16(addr) & (~mask), addr); |
| 77 | spin_unlock_irqrestore(&tpci200->regs_lock, flags); |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void tpci200_set_mask(struct tpci200_board *tpci200, |
| 81 | __le16 __iomem *addr, u16 mask) |
| 82 | { |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 83 | unsigned long flags; |
| 84 | spin_lock_irqsave(&tpci200->regs_lock, flags); |
| 85 | iowrite16(ioread16(addr) | mask, addr); |
| 86 | spin_unlock_irqrestore(&tpci200->regs_lock, flags); |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 89 | static void tpci200_unregister(struct tpci200_board *tpci200) |
| 90 | { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 91 | free_irq(tpci200->info->pdev->irq, (void *) tpci200); |
| 92 | |
| 93 | pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs); |
Samuel Iglesias Gonsálvez | 7987812 | 2012-09-11 13:35:04 +0200 | [diff] [blame] | 94 | pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 95 | |
| 96 | pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR); |
| 97 | pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR); |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 98 | pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 99 | pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); |
Samuel Iglesias Gonsálvez | 7987812 | 2012-09-11 13:35:04 +0200 | [diff] [blame] | 100 | pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 101 | |
| 102 | pci_disable_device(tpci200->info->pdev); |
| 103 | pci_dev_put(tpci200->info->pdev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Jens Taprogge | 877adc4 | 2012-09-12 14:55:36 +0200 | [diff] [blame] | 106 | static void tpci200_enable_irq(struct tpci200_board *tpci200, |
| 107 | int islot) |
| 108 | { |
| 109 | tpci200_set_mask(tpci200, |
| 110 | &tpci200->info->interface_regs->control[islot], |
| 111 | TPCI200_INT0_EN | TPCI200_INT1_EN); |
| 112 | } |
| 113 | |
| 114 | static void tpci200_disable_irq(struct tpci200_board *tpci200, |
| 115 | int islot) |
| 116 | { |
| 117 | tpci200_clear_mask(tpci200, |
| 118 | &tpci200->info->interface_regs->control[islot], |
| 119 | TPCI200_INT0_EN | TPCI200_INT1_EN); |
| 120 | } |
| 121 | |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 122 | static irqreturn_t tpci200_slot_irq(struct slot_irq *slot_irq) |
| 123 | { |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 124 | irqreturn_t ret; |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 125 | |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 126 | if (!slot_irq) |
| 127 | return -ENODEV; |
| 128 | ret = slot_irq->handler(slot_irq->arg); |
| 129 | |
Jens Taprogge | af2140ce | 2012-09-12 14:55:25 +0200 | [diff] [blame] | 130 | return ret; |
| 131 | } |
| 132 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 133 | static irqreturn_t tpci200_interrupt(int irq, void *dev_id) |
| 134 | { |
| 135 | struct tpci200_board *tpci200 = (struct tpci200_board *) dev_id; |
Jens Taprogge | 6f2c12a | 2012-09-11 13:35:13 +0200 | [diff] [blame] | 136 | struct slot_irq *slot_irq; |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 137 | irqreturn_t ret; |
| 138 | u16 status_reg; |
| 139 | int i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 140 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 141 | /* Read status register */ |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 142 | status_reg = ioread16(&tpci200->info->interface_regs->status); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 143 | |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 144 | /* Did we cause the interrupt? */ |
| 145 | if (!(status_reg & TPCI200_SLOT_INT_MASK)) |
Jens Taprogge | 88ff848 | 2012-09-12 14:55:34 +0200 | [diff] [blame] | 146 | return IRQ_NONE; |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 147 | |
| 148 | /* callback to the IRQ handler for the corresponding slot */ |
| 149 | rcu_read_lock(); |
| 150 | for (i = 0; i < TPCI200_NB_SLOT; i++) { |
| 151 | if (!(status_reg & ((TPCI200_A_INT0 | TPCI200_A_INT1) << (2 * i)))) |
| 152 | continue; |
| 153 | slot_irq = rcu_dereference(tpci200->slots[i].irq); |
| 154 | ret = tpci200_slot_irq(slot_irq); |
| 155 | if (ret == -ENODEV) { |
| 156 | dev_info(&tpci200->info->pdev->dev, |
| 157 | "No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n", |
| 158 | tpci200->number, i); |
Jens Taprogge | 877adc4 | 2012-09-12 14:55:36 +0200 | [diff] [blame] | 159 | tpci200_disable_irq(tpci200, i); |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 160 | } |
Jens Taprogge | 88ff848 | 2012-09-12 14:55:34 +0200 | [diff] [blame] | 161 | } |
Jens Taprogge | ab0deff | 2012-09-12 14:55:35 +0200 | [diff] [blame] | 162 | rcu_read_unlock(); |
| 163 | |
| 164 | return IRQ_HANDLED; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 167 | static int tpci200_free_irq(struct ipack_device *dev) |
| 168 | { |
| 169 | struct slot_irq *slot_irq; |
| 170 | struct tpci200_board *tpci200; |
| 171 | |
| 172 | tpci200 = check_slot(dev); |
| 173 | if (tpci200 == NULL) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | if (mutex_lock_interruptible(&tpci200->mutex)) |
| 177 | return -ERESTARTSYS; |
| 178 | |
| 179 | if (tpci200->slots[dev->slot].irq == NULL) { |
| 180 | mutex_unlock(&tpci200->mutex); |
| 181 | return -EINVAL; |
| 182 | } |
| 183 | |
| 184 | tpci200_disable_irq(tpci200, dev->slot); |
| 185 | slot_irq = tpci200->slots[dev->slot].irq; |
| 186 | /* uninstall handler */ |
| 187 | RCU_INIT_POINTER(tpci200->slots[dev->slot].irq, NULL); |
| 188 | synchronize_rcu(); |
| 189 | kfree(slot_irq); |
| 190 | mutex_unlock(&tpci200->mutex); |
| 191 | return 0; |
| 192 | } |
| 193 | |
Jens Taprogge | c6e2dfa | 2012-09-13 12:32:21 +0200 | [diff] [blame] | 194 | static int tpci200_request_irq(struct ipack_device *dev, |
Jens Taprogge | faa75c4 | 2012-09-12 14:55:38 +0200 | [diff] [blame] | 195 | irqreturn_t (*handler)(void *), void *arg) |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 196 | { |
| 197 | int res = 0; |
| 198 | struct slot_irq *slot_irq; |
| 199 | struct tpci200_board *tpci200; |
| 200 | |
| 201 | tpci200 = check_slot(dev); |
| 202 | if (tpci200 == NULL) |
| 203 | return -EINVAL; |
| 204 | |
| 205 | if (mutex_lock_interruptible(&tpci200->mutex)) |
| 206 | return -ERESTARTSYS; |
| 207 | |
| 208 | if (tpci200->slots[dev->slot].irq != NULL) { |
| 209 | dev_err(&dev->dev, |
Johan Meiring | 9d10b22 | 2012-11-11 22:41:13 +0200 | [diff] [blame] | 210 | "Slot [%d:%d] IRQ already registered !\n", |
| 211 | dev->bus->bus_nr, |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 212 | dev->slot); |
| 213 | res = -EINVAL; |
| 214 | goto out_unlock; |
| 215 | } |
| 216 | |
| 217 | slot_irq = kzalloc(sizeof(struct slot_irq), GFP_KERNEL); |
| 218 | if (slot_irq == NULL) { |
| 219 | dev_err(&dev->dev, |
| 220 | "Slot [%d:%d] unable to allocate memory for IRQ !\n", |
Jens Taprogge | f9e314d | 2012-09-27 12:37:25 +0200 | [diff] [blame] | 221 | dev->bus->bus_nr, dev->slot); |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 222 | res = -ENOMEM; |
| 223 | goto out_unlock; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * WARNING: Setup Interrupt Vector in the IndustryPack device |
| 228 | * before an IRQ request. |
| 229 | * Read the User Manual of your IndustryPack device to know |
| 230 | * where to write the vector in memory. |
| 231 | */ |
Jens Taprogge | 40733ed | 2012-09-12 14:55:37 +0200 | [diff] [blame] | 232 | slot_irq->handler = handler; |
| 233 | slot_irq->arg = arg; |
| 234 | slot_irq->holder = dev; |
| 235 | |
| 236 | rcu_assign_pointer(tpci200->slots[dev->slot].irq, slot_irq); |
| 237 | tpci200_enable_irq(tpci200, dev->slot); |
| 238 | |
| 239 | out_unlock: |
| 240 | mutex_unlock(&tpci200->mutex); |
| 241 | return res; |
| 242 | } |
| 243 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 244 | static int tpci200_register(struct tpci200_board *tpci200) |
| 245 | { |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 246 | int i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 247 | int res; |
Jens Taprogge | bb29ab8 | 2012-09-27 12:37:28 +0200 | [diff] [blame] | 248 | phys_addr_t ioidint_base; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 249 | unsigned short slot_ctrl; |
| 250 | |
| 251 | if (pci_enable_device(tpci200->info->pdev) < 0) |
| 252 | return -ENODEV; |
| 253 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 254 | /* Request IP interface register (Bar 2) */ |
| 255 | res = pci_request_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR, |
| 256 | "Carrier IP interface registers"); |
| 257 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 258 | dev_err(&tpci200->info->pdev->dev, |
| 259 | "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !", |
| 260 | tpci200->info->pdev->bus->number, |
| 261 | tpci200->info->pdev->devfn); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 262 | goto out_disable_pci; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* Request IO ID INT space (Bar 3) */ |
| 266 | res = pci_request_region(tpci200->info->pdev, |
| 267 | TPCI200_IO_ID_INT_SPACES_BAR, |
| 268 | "Carrier IO ID INT space"); |
| 269 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 270 | dev_err(&tpci200->info->pdev->dev, |
| 271 | "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !", |
| 272 | tpci200->info->pdev->bus->number, |
| 273 | tpci200->info->pdev->devfn); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 274 | goto out_release_ip_space; |
| 275 | } |
| 276 | |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 277 | /* Request MEM8 space (Bar 5) */ |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 278 | res = pci_request_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR, |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 279 | "Carrier MEM8 space"); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 280 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 281 | dev_err(&tpci200->info->pdev->dev, |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 282 | "(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] | 283 | tpci200->info->pdev->bus->number, |
| 284 | tpci200->info->pdev->devfn); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 285 | goto out_release_ioid_int_space; |
| 286 | } |
| 287 | |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 288 | /* Request MEM16 space (Bar 4) */ |
| 289 | res = pci_request_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR, |
| 290 | "Carrier MEM16 space"); |
| 291 | if (res) { |
| 292 | dev_err(&tpci200->info->pdev->dev, |
| 293 | "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!", |
| 294 | tpci200->info->pdev->bus->number, |
| 295 | tpci200->info->pdev->devfn); |
| 296 | goto out_release_mem8_space; |
| 297 | } |
| 298 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 299 | /* Map internal tpci200 driver user space */ |
| 300 | tpci200->info->interface_regs = |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 301 | ioremap(pci_resource_start(tpci200->info->pdev, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 302 | TPCI200_IP_INTERFACE_BAR), |
| 303 | TPCI200_IFACE_SIZE); |
Zhouyang Jia | 4398679 | 2018-06-12 11:07:21 +0800 | [diff] [blame] | 304 | if (!tpci200->info->interface_regs) { |
| 305 | dev_err(&tpci200->info->pdev->dev, |
| 306 | "(bn 0x%X, sn 0x%X) failed to map driver user space!", |
| 307 | tpci200->info->pdev->bus->number, |
| 308 | tpci200->info->pdev->devfn); |
| 309 | goto out_release_mem8_space; |
| 310 | } |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 311 | |
Jens Taprogge | 487e0a6 | 2012-09-12 14:55:33 +0200 | [diff] [blame] | 312 | /* Initialize lock that protects interface_regs */ |
| 313 | spin_lock_init(&tpci200->regs_lock); |
| 314 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 315 | ioidint_base = pci_resource_start(tpci200->info->pdev, |
| 316 | TPCI200_IO_ID_INT_SPACES_BAR); |
Jens Taprogge | 84a08fa | 2012-09-27 12:37:29 +0200 | [diff] [blame] | 317 | tpci200->mod_mem[IPACK_IO_SPACE] = ioidint_base + TPCI200_IO_SPACE_OFF; |
| 318 | tpci200->mod_mem[IPACK_ID_SPACE] = ioidint_base + TPCI200_ID_SPACE_OFF; |
| 319 | tpci200->mod_mem[IPACK_INT_SPACE] = |
| 320 | ioidint_base + TPCI200_INT_SPACE_OFF; |
Jens Taprogge | fe4a3ed | 2012-09-27 12:37:36 +0200 | [diff] [blame] | 321 | tpci200->mod_mem[IPACK_MEM8_SPACE] = |
Jens Taprogge | 84a08fa | 2012-09-27 12:37:29 +0200 | [diff] [blame] | 322 | pci_resource_start(tpci200->info->pdev, |
Jens Taprogge | 6114aea | 2012-09-27 12:37:30 +0200 | [diff] [blame] | 323 | TPCI200_MEM8_SPACE_BAR); |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 324 | tpci200->mod_mem[IPACK_MEM16_SPACE] = |
| 325 | pci_resource_start(tpci200->info->pdev, |
| 326 | TPCI200_MEM16_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 327 | |
| 328 | /* Set the default parameters of the slot |
| 329 | * INT0 disabled, level sensitive |
| 330 | * INT1 disabled, level sensitive |
| 331 | * error interrupt disabled |
| 332 | * timeout interrupt disabled |
| 333 | * recover time disabled |
| 334 | * clock rate 8 MHz |
| 335 | */ |
| 336 | slot_ctrl = 0; |
Jens Taprogge | a93963a | 2012-09-27 12:37:35 +0200 | [diff] [blame] | 337 | for (i = 0; i < TPCI200_NB_SLOT; i++) |
Jens Taprogge | 28086cb | 2012-09-11 13:34:54 +0200 | [diff] [blame] | 338 | writew(slot_ctrl, &tpci200->info->interface_regs->control[i]); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 339 | |
| 340 | res = request_irq(tpci200->info->pdev->irq, |
| 341 | tpci200_interrupt, IRQF_SHARED, |
Samuel Iglesias Gonsalvez | c63a7dd | 2012-05-18 11:10:07 +0200 | [diff] [blame] | 342 | KBUILD_MODNAME, (void *) tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 343 | if (res) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 344 | dev_err(&tpci200->info->pdev->dev, |
| 345 | "(bn 0x%X, sn 0x%X) unable to register IRQ !", |
| 346 | tpci200->info->pdev->bus->number, |
| 347 | tpci200->info->pdev->devfn); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 348 | goto out_release_ioid_int_space; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | return 0; |
| 352 | |
Jens Taprogge | 48a9735 | 2012-09-27 12:37:37 +0200 | [diff] [blame] | 353 | out_release_mem8_space: |
| 354 | pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 355 | out_release_ioid_int_space: |
| 356 | pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR); |
| 357 | out_release_ip_space: |
| 358 | pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 359 | out_disable_pci: |
| 360 | pci_disable_device(tpci200->info->pdev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 361 | return res; |
| 362 | } |
| 363 | |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 364 | static int tpci200_get_clockrate(struct ipack_device *dev) |
| 365 | { |
| 366 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 367 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 368 | |
| 369 | if (!tpci200) |
| 370 | return -ENODEV; |
| 371 | |
| 372 | addr = &tpci200->info->interface_regs->control[dev->slot]; |
| 373 | return (ioread16(addr) & TPCI200_CLK32) ? 32 : 8; |
| 374 | } |
| 375 | |
| 376 | static int tpci200_set_clockrate(struct ipack_device *dev, int mherz) |
| 377 | { |
| 378 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 379 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 380 | |
| 381 | if (!tpci200) |
| 382 | return -ENODEV; |
| 383 | |
| 384 | addr = &tpci200->info->interface_regs->control[dev->slot]; |
| 385 | |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 386 | switch (mherz) { |
| 387 | case 8: |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 388 | tpci200_clear_mask(tpci200, addr, TPCI200_CLK32); |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 389 | break; |
| 390 | case 32: |
Jens Taprogge | 0118681 | 2012-09-12 14:55:23 +0200 | [diff] [blame] | 391 | tpci200_set_mask(tpci200, addr, TPCI200_CLK32); |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 392 | break; |
| 393 | default: |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 394 | return -EINVAL; |
| 395 | } |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int tpci200_get_error(struct ipack_device *dev) |
| 400 | { |
| 401 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 402 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 403 | u16 mask; |
| 404 | |
| 405 | if (!tpci200) |
| 406 | return -ENODEV; |
| 407 | |
| 408 | addr = &tpci200->info->interface_regs->status; |
| 409 | mask = tpci200_status_error[dev->slot]; |
| 410 | return (ioread16(addr) & mask) ? 1 : 0; |
| 411 | } |
| 412 | |
| 413 | static int tpci200_get_timeout(struct ipack_device *dev) |
| 414 | { |
| 415 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 416 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 417 | u16 mask; |
| 418 | |
| 419 | if (!tpci200) |
| 420 | return -ENODEV; |
| 421 | |
| 422 | addr = &tpci200->info->interface_regs->status; |
| 423 | mask = tpci200_status_timeout[dev->slot]; |
| 424 | |
| 425 | return (ioread16(addr) & mask) ? 1 : 0; |
| 426 | } |
| 427 | |
| 428 | static int tpci200_reset_timeout(struct ipack_device *dev) |
| 429 | { |
| 430 | struct tpci200_board *tpci200 = check_slot(dev); |
Jens Taprogge | 7dd73b8 | 2012-09-12 14:55:46 +0200 | [diff] [blame] | 431 | __le16 __iomem *addr; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 432 | u16 mask; |
| 433 | |
| 434 | if (!tpci200) |
| 435 | return -ENODEV; |
| 436 | |
| 437 | addr = &tpci200->info->interface_regs->status; |
| 438 | mask = tpci200_status_timeout[dev->slot]; |
| 439 | |
| 440 | iowrite16(mask, addr); |
| 441 | return 0; |
| 442 | } |
| 443 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 444 | static void tpci200_uninstall(struct tpci200_board *tpci200) |
| 445 | { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 446 | tpci200_unregister(tpci200); |
| 447 | kfree(tpci200->slots); |
| 448 | } |
| 449 | |
Stephen Hemminger | 9869a937 | 2012-09-10 11:14:01 -0700 | [diff] [blame] | 450 | static const struct ipack_bus_ops tpci200_bus_ops = { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 451 | .request_irq = tpci200_request_irq, |
| 452 | .free_irq = tpci200_free_irq, |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 453 | .get_clockrate = tpci200_get_clockrate, |
| 454 | .set_clockrate = tpci200_set_clockrate, |
| 455 | .get_error = tpci200_get_error, |
| 456 | .get_timeout = tpci200_get_timeout, |
| 457 | .reset_timeout = tpci200_reset_timeout, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | static int tpci200_install(struct tpci200_board *tpci200) |
| 461 | { |
| 462 | int res; |
| 463 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 464 | tpci200->slots = kcalloc(TPCI200_NB_SLOT, sizeof(struct tpci200_slot), |
| 465 | GFP_KERNEL); |
Miguel Gómez | ec0ceb9 | 2012-06-07 10:24:54 +0200 | [diff] [blame] | 466 | if (tpci200->slots == NULL) |
| 467 | return -ENOMEM; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 468 | |
| 469 | res = tpci200_register(tpci200); |
Miguel Gómez | ec0ceb9 | 2012-06-07 10:24:54 +0200 | [diff] [blame] | 470 | if (res) { |
| 471 | kfree(tpci200->slots); |
| 472 | tpci200->slots = NULL; |
| 473 | return res; |
| 474 | } |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 475 | |
| 476 | mutex_init(&tpci200->mutex); |
| 477 | return 0; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 480 | static void tpci200_release_device(struct ipack_device *dev) |
| 481 | { |
| 482 | kfree(dev); |
| 483 | } |
| 484 | |
| 485 | static int tpci200_create_device(struct tpci200_board *tpci200, int i) |
| 486 | { |
Samuel Iglesias Gonsalvez | e926301 | 2013-03-08 09:21:47 +0100 | [diff] [blame] | 487 | int ret; |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 488 | enum ipack_space space; |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 489 | struct ipack_device *dev = |
| 490 | kzalloc(sizeof(struct ipack_device), GFP_KERNEL); |
| 491 | if (!dev) |
| 492 | return -ENOMEM; |
| 493 | dev->slot = i; |
| 494 | dev->bus = tpci200->info->ipack_bus; |
| 495 | dev->release = tpci200_release_device; |
Jens Taprogge | a19ad7d | 2012-09-27 12:37:31 +0200 | [diff] [blame] | 496 | |
| 497 | for (space = 0; space < IPACK_SPACE_COUNT; space++) { |
| 498 | dev->region[space].start = |
| 499 | tpci200->mod_mem[space] |
| 500 | + tpci200_space_interval[space] * i; |
| 501 | dev->region[space].size = tpci200_space_size[space]; |
| 502 | } |
Samuel Iglesias Gonsalvez | e926301 | 2013-03-08 09:21:47 +0100 | [diff] [blame] | 503 | |
| 504 | ret = ipack_device_init(dev); |
| 505 | if (ret < 0) { |
| 506 | ipack_put_device(dev); |
| 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | ret = ipack_device_add(dev); |
| 511 | if (ret < 0) |
| 512 | ipack_put_device(dev); |
| 513 | |
| 514 | return ret; |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Stephen Hemminger | 2065945 | 2012-09-07 08:50:54 -0700 | [diff] [blame] | 517 | static int tpci200_pci_probe(struct pci_dev *pdev, |
| 518 | const struct pci_device_id *id) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 519 | { |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 520 | int ret, i; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 521 | struct tpci200_board *tpci200; |
Jens Taprogge | eb12d88 | 2012-09-11 13:34:56 +0200 | [diff] [blame] | 522 | u32 reg32; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 523 | |
| 524 | tpci200 = kzalloc(sizeof(struct tpci200_board), GFP_KERNEL); |
| 525 | if (!tpci200) |
| 526 | return -ENOMEM; |
| 527 | |
| 528 | tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL); |
| 529 | if (!tpci200->info) { |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 530 | ret = -ENOMEM; |
| 531 | goto out_err_info; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Samuel Iglesias Gonsálvez | b442bf7 | 2012-09-11 13:35:05 +0200 | [diff] [blame] | 534 | pci_dev_get(pdev); |
| 535 | |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 536 | /* Obtain a mapping of the carrier's PCI configuration registers */ |
| 537 | ret = pci_request_region(pdev, TPCI200_CFG_MEM_BAR, |
| 538 | KBUILD_MODNAME " Configuration Memory"); |
| 539 | if (ret) { |
| 540 | dev_err(&pdev->dev, "Failed to allocate PCI Configuration Memory"); |
| 541 | ret = -EBUSY; |
| 542 | goto out_err_pci_request; |
| 543 | } |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 544 | tpci200->info->cfg_regs = ioremap( |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 545 | pci_resource_start(pdev, TPCI200_CFG_MEM_BAR), |
| 546 | pci_resource_len(pdev, TPCI200_CFG_MEM_BAR)); |
| 547 | if (!tpci200->info->cfg_regs) { |
| 548 | dev_err(&pdev->dev, "Failed to map PCI Configuration Memory"); |
| 549 | ret = -EFAULT; |
| 550 | goto out_err_ioremap; |
| 551 | } |
| 552 | |
| 553 | /* Disable byte swapping for 16 bit IP module access. This will ensure |
| 554 | * that the Industrypack big endian byte order is preserved by the |
| 555 | * carrier. */ |
| 556 | reg32 = ioread32(tpci200->info->cfg_regs + LAS1_DESC); |
| 557 | reg32 |= 1 << LAS_BIT_BIGENDIAN; |
| 558 | iowrite32(reg32, tpci200->info->cfg_regs + LAS1_DESC); |
| 559 | |
| 560 | reg32 = ioread32(tpci200->info->cfg_regs + LAS2_DESC); |
| 561 | reg32 |= 1 << LAS_BIT_BIGENDIAN; |
| 562 | iowrite32(reg32, tpci200->info->cfg_regs + LAS2_DESC); |
| 563 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 564 | /* Save struct pci_dev pointer */ |
| 565 | tpci200->info->pdev = pdev; |
| 566 | tpci200->info->id_table = (struct pci_device_id *)id; |
| 567 | |
| 568 | /* register the device and initialize it */ |
| 569 | ret = tpci200_install(tpci200); |
| 570 | if (ret) { |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 571 | dev_err(&pdev->dev, "error during tpci200 install\n"); |
| 572 | ret = -ENODEV; |
| 573 | goto out_err_install; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 574 | } |
| 575 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 576 | /* Register the carrier in the industry pack bus driver */ |
| 577 | tpci200->info->ipack_bus = ipack_bus_register(&pdev->dev, |
| 578 | TPCI200_NB_SLOT, |
Federico Vaga | 36c53b3 | 2014-09-02 17:31:40 +0200 | [diff] [blame] | 579 | &tpci200_bus_ops, |
| 580 | THIS_MODULE); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 581 | if (!tpci200->info->ipack_bus) { |
Samuel Iglesias Gonsalvez | a23d320 | 2012-05-25 13:08:12 +0200 | [diff] [blame] | 582 | dev_err(&pdev->dev, |
| 583 | "error registering the carrier on ipack driver\n"); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 584 | ret = -EFAULT; |
| 585 | goto out_err_bus_register; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 586 | } |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 587 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 588 | /* save the bus number given by ipack to logging purpose */ |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 589 | tpci200->number = tpci200->info->ipack_bus->bus_nr; |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 590 | dev_set_drvdata(&pdev->dev, tpci200); |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 591 | |
Samuel Iglesias Gonsalvez | 862fe87 | 2012-05-23 15:54:40 +0200 | [diff] [blame] | 592 | for (i = 0; i < TPCI200_NB_SLOT; i++) |
Jens Taprogge | 1e91795 | 2012-09-27 12:37:26 +0200 | [diff] [blame] | 593 | tpci200_create_device(tpci200, i); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 594 | return 0; |
| 595 | |
| 596 | out_err_bus_register: |
| 597 | tpci200_uninstall(tpci200); |
| 598 | out_err_install: |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 599 | iounmap(tpci200->info->cfg_regs); |
| 600 | out_err_ioremap: |
| 601 | pci_release_region(pdev, TPCI200_CFG_MEM_BAR); |
| 602 | out_err_pci_request: |
Samuel Iglesias Gonsálvez | b442bf7 | 2012-09-11 13:35:05 +0200 | [diff] [blame] | 603 | pci_dev_put(pdev); |
Jens Taprogge | 5e15a75 | 2012-09-04 17:01:06 +0200 | [diff] [blame] | 604 | kfree(tpci200->info); |
| 605 | out_err_info: |
| 606 | kfree(tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | static void __tpci200_pci_remove(struct tpci200_board *tpci200) |
| 611 | { |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 612 | ipack_bus_unregister(tpci200->info->ipack_bus); |
Samuel Iglesias Gonsálvez | 9c0d169 | 2012-09-11 13:35:10 +0200 | [diff] [blame] | 613 | tpci200_uninstall(tpci200); |
Jens Taprogge | cea2f7c | 2012-09-04 17:01:07 +0200 | [diff] [blame] | 614 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 615 | kfree(tpci200->info); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 616 | kfree(tpci200); |
| 617 | } |
| 618 | |
Bill Pemberton | 29c3544 | 2012-11-19 13:26:39 -0500 | [diff] [blame] | 619 | static void tpci200_pci_remove(struct pci_dev *dev) |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 620 | { |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 621 | struct tpci200_board *tpci200 = pci_get_drvdata(dev); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 622 | |
Samuel Iglesias Gonsálvez | f45651f | 2012-07-20 09:39:04 +0200 | [diff] [blame] | 623 | __tpci200_pci_remove(tpci200); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Benoit Taine | 7426d29 | 2014-07-18 17:27:12 +0200 | [diff] [blame] | 626 | static const struct pci_device_id tpci200_idtable[] = { |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 627 | { TPCI200_VENDOR_ID, TPCI200_DEVICE_ID, TPCI200_SUBVENDOR_ID, |
| 628 | TPCI200_SUBDEVICE_ID }, |
| 629 | { 0, }, |
| 630 | }; |
| 631 | |
Miguel Gómez | 3953503 | 2012-06-07 10:24:58 +0200 | [diff] [blame] | 632 | MODULE_DEVICE_TABLE(pci, tpci200_idtable); |
| 633 | |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 634 | static struct pci_driver tpci200_pci_drv = { |
| 635 | .name = "tpci200", |
| 636 | .id_table = tpci200_idtable, |
Stephen Hemminger | 2065945 | 2012-09-07 08:50:54 -0700 | [diff] [blame] | 637 | .probe = tpci200_pci_probe, |
Bill Pemberton | c5dee46 | 2012-11-19 13:21:31 -0500 | [diff] [blame] | 638 | .remove = tpci200_pci_remove, |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 639 | }; |
| 640 | |
Wei Yongjun | 1bc7c1c | 2012-10-18 23:18:46 +0800 | [diff] [blame] | 641 | module_pci_driver(tpci200_pci_drv); |
Samuel Iglesias Gonsalvez | 0eeca14 | 2012-05-09 15:27:20 +0200 | [diff] [blame] | 642 | |
| 643 | MODULE_DESCRIPTION("TEWS TPCI-200 device driver"); |
| 644 | MODULE_LICENSE("GPL"); |