Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * tifm_7xx1.c - TI FlashMedia driver |
| 3 | * |
| 4 | * Copyright (C) 2006 Alex Dubov <oakad@yahoo.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/tifm.h> |
Andrew Morton | c403069 | 2007-04-28 14:21:10 +0200 | [diff] [blame] | 13 | #include <linux/dma-mapping.h> |
Paul Gortmaker | eb12a67 | 2011-07-03 15:14:56 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 15 | |
| 16 | #define DRIVER_NAME "tifm_7xx1" |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 17 | #define DRIVER_VERSION "0.8" |
| 18 | |
| 19 | #define TIFM_IRQ_ENABLE 0x80000000 |
| 20 | #define TIFM_IRQ_SOCKMASK(x) (x) |
| 21 | #define TIFM_IRQ_CARDMASK(x) ((x) << 8) |
| 22 | #define TIFM_IRQ_FIFOMASK(x) ((x) << 16) |
| 23 | #define TIFM_IRQ_SETALL 0xffffffff |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 24 | |
Alex Dubov | 6113ed7 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 25 | static void tifm_7xx1_dummy_eject(struct tifm_adapter *fm, |
| 26 | struct tifm_dev *sock) |
| 27 | { |
| 28 | } |
| 29 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 30 | static void tifm_7xx1_eject(struct tifm_adapter *fm, struct tifm_dev *sock) |
| 31 | { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 32 | unsigned long flags; |
| 33 | |
| 34 | spin_lock_irqsave(&fm->lock, flags); |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 35 | fm->socket_change_set |= 1 << sock->socket_id; |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 36 | tifm_queue_work(&fm->media_switcher); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 37 | spin_unlock_irqrestore(&fm->lock, flags); |
| 38 | } |
| 39 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 40 | static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 41 | { |
| 42 | struct tifm_adapter *fm = dev_id; |
Alex Dubov | 217334d | 2006-12-11 01:55:31 +1100 | [diff] [blame] | 43 | struct tifm_dev *sock; |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 44 | unsigned int irq_status, cnt; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 45 | |
| 46 | spin_lock(&fm->lock); |
| 47 | irq_status = readl(fm->addr + FM_INTERRUPT_STATUS); |
| 48 | if (irq_status == 0 || irq_status == (~0)) { |
| 49 | spin_unlock(&fm->lock); |
| 50 | return IRQ_NONE; |
| 51 | } |
| 52 | |
| 53 | if (irq_status & TIFM_IRQ_ENABLE) { |
| 54 | writel(TIFM_IRQ_ENABLE, fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
| 55 | |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 56 | for (cnt = 0; cnt < fm->num_sockets; cnt++) { |
Alex Dubov | 217334d | 2006-12-11 01:55:31 +1100 | [diff] [blame] | 57 | sock = fm->sockets[cnt]; |
Alex Dubov | 4552f0c | 2007-04-12 16:59:12 +1000 | [diff] [blame] | 58 | if (sock) { |
| 59 | if ((irq_status >> cnt) & TIFM_IRQ_FIFOMASK(1)) |
| 60 | sock->data_event(sock); |
| 61 | if ((irq_status >> cnt) & TIFM_IRQ_CARDMASK(1)) |
| 62 | sock->card_event(sock); |
| 63 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 64 | } |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 65 | |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 66 | fm->socket_change_set |= irq_status |
| 67 | & ((1 << fm->num_sockets) - 1); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 68 | } |
| 69 | writel(irq_status, fm->addr + FM_INTERRUPT_STATUS); |
| 70 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 71 | if (fm->finish_me) |
| 72 | complete_all(fm->finish_me); |
| 73 | else if (!fm->socket_change_set) |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 74 | writel(TIFM_IRQ_ENABLE, fm->addr + FM_SET_INTERRUPT_ENABLE); |
| 75 | else |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 76 | tifm_queue_work(&fm->media_switcher); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 77 | |
| 78 | spin_unlock(&fm->lock); |
| 79 | return IRQ_HANDLED; |
| 80 | } |
| 81 | |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 82 | static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 83 | { |
| 84 | unsigned int s_state; |
| 85 | int cnt; |
| 86 | |
| 87 | writel(0x0e00, sock_addr + SOCK_CONTROL); |
| 88 | |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 89 | for (cnt = 16; cnt <= 256; cnt <<= 1) { |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 90 | if (!(TIFM_SOCK_STATE_POWERED |
| 91 | & readl(sock_addr + SOCK_PRESENT_STATE))) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 92 | break; |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 93 | |
| 94 | msleep(cnt); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | s_state = readl(sock_addr + SOCK_PRESENT_STATE); |
| 98 | if (!(TIFM_SOCK_STATE_OCCUPIED & s_state)) |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 99 | return 0; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 100 | |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 101 | writel(readl(sock_addr + SOCK_CONTROL) | TIFM_CTRL_LED, |
| 102 | sock_addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 103 | |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 104 | /* xd needs some extra time before power on */ |
| 105 | if (((readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7) |
| 106 | == TIFM_TYPE_XD) |
| 107 | msleep(40); |
| 108 | |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 109 | writel((s_state & TIFM_CTRL_POWER_MASK) | 0x0c00, |
| 110 | sock_addr + SOCK_CONTROL); |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 111 | /* wait for power to stabilize */ |
| 112 | msleep(20); |
| 113 | for (cnt = 16; cnt <= 256; cnt <<= 1) { |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 114 | if ((TIFM_SOCK_STATE_POWERED |
| 115 | & readl(sock_addr + SOCK_PRESENT_STATE))) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 116 | break; |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 117 | |
| 118 | msleep(cnt); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Alex Dubov | 342c0ec | 2007-04-12 16:59:16 +1000 | [diff] [blame] | 121 | writel(readl(sock_addr + SOCK_CONTROL) & (~TIFM_CTRL_LED), |
| 122 | sock_addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 123 | |
| 124 | return (readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7; |
| 125 | } |
| 126 | |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 127 | inline static void tifm_7xx1_sock_power_off(char __iomem *sock_addr) |
| 128 | { |
| 129 | writel((~TIFM_CTRL_POWER_MASK) & readl(sock_addr + SOCK_CONTROL), |
| 130 | sock_addr + SOCK_CONTROL); |
| 131 | } |
| 132 | |
Al Viro | e069d79 | 2006-10-09 20:29:43 +0100 | [diff] [blame] | 133 | inline static char __iomem * |
| 134 | tifm_7xx1_sock_addr(char __iomem *base_addr, unsigned int sock_num) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 135 | { |
| 136 | return base_addr + ((sock_num + 1) << 10); |
| 137 | } |
| 138 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 139 | static void tifm_7xx1_switch_media(struct work_struct *work) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 140 | { |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 141 | struct tifm_adapter *fm = container_of(work, struct tifm_adapter, |
| 142 | media_switcher); |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 143 | struct tifm_dev *sock; |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 144 | char __iomem *sock_addr; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 145 | unsigned long flags; |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 146 | unsigned char media_id; |
Alex Dubov | 91f8d01 | 2007-04-12 17:05:26 +1000 | [diff] [blame] | 147 | unsigned int socket_change_set, cnt; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 148 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 149 | spin_lock_irqsave(&fm->lock, flags); |
| 150 | socket_change_set = fm->socket_change_set; |
| 151 | fm->socket_change_set = 0; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 152 | |
Tony Jones | 7dd817d | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 153 | dev_dbg(fm->dev.parent, "checking media set %x\n", |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 154 | socket_change_set); |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 155 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 156 | if (!socket_change_set) { |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 157 | spin_unlock_irqrestore(&fm->lock, flags); |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 158 | return; |
| 159 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 160 | |
Alex Dubov | 2428a8f | 2007-04-12 16:59:18 +1000 | [diff] [blame] | 161 | for (cnt = 0; cnt < fm->num_sockets; cnt++) { |
| 162 | if (!(socket_change_set & (1 << cnt))) |
| 163 | continue; |
| 164 | sock = fm->sockets[cnt]; |
| 165 | if (sock) { |
| 166 | printk(KERN_INFO |
| 167 | "%s : demand removing card from socket %u:%u\n", |
Kay Sievers | 0bad16a | 2009-01-06 10:44:35 -0800 | [diff] [blame] | 168 | dev_name(&fm->dev), fm->id, cnt); |
Alex Dubov | 2428a8f | 2007-04-12 16:59:18 +1000 | [diff] [blame] | 169 | fm->sockets[cnt] = NULL; |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 170 | sock_addr = sock->addr; |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 171 | spin_unlock_irqrestore(&fm->lock, flags); |
Alex Dubov | 2428a8f | 2007-04-12 16:59:18 +1000 | [diff] [blame] | 172 | device_unregister(&sock->dev); |
| 173 | spin_lock_irqsave(&fm->lock, flags); |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 174 | tifm_7xx1_sock_power_off(sock_addr); |
| 175 | writel(0x0e00, sock_addr + SOCK_CONTROL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 176 | } |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 177 | |
Alex Dubov | 2428a8f | 2007-04-12 16:59:18 +1000 | [diff] [blame] | 178 | spin_unlock_irqrestore(&fm->lock, flags); |
| 179 | |
| 180 | media_id = tifm_7xx1_toggle_sock_power( |
| 181 | tifm_7xx1_sock_addr(fm->addr, cnt)); |
| 182 | |
| 183 | // tifm_alloc_device will check if media_id is valid |
| 184 | sock = tifm_alloc_device(fm, cnt, media_id); |
| 185 | if (sock) { |
| 186 | sock->addr = tifm_7xx1_sock_addr(fm->addr, cnt); |
| 187 | |
| 188 | if (!device_register(&sock->dev)) { |
| 189 | spin_lock_irqsave(&fm->lock, flags); |
| 190 | if (!fm->sockets[cnt]) { |
| 191 | fm->sockets[cnt] = sock; |
| 192 | sock = NULL; |
| 193 | } |
| 194 | spin_unlock_irqrestore(&fm->lock, flags); |
| 195 | } |
| 196 | if (sock) |
| 197 | tifm_free_device(&sock->dev); |
| 198 | } |
| 199 | spin_lock_irqsave(&fm->lock, flags); |
| 200 | } |
| 201 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 202 | writel(TIFM_IRQ_FIFOMASK(socket_change_set) |
| 203 | | TIFM_IRQ_CARDMASK(socket_change_set), |
| 204 | fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
| 205 | |
| 206 | writel(TIFM_IRQ_FIFOMASK(socket_change_set) |
| 207 | | TIFM_IRQ_CARDMASK(socket_change_set), |
| 208 | fm->addr + FM_SET_INTERRUPT_ENABLE); |
| 209 | |
| 210 | writel(TIFM_IRQ_ENABLE, fm->addr + FM_SET_INTERRUPT_ENABLE); |
| 211 | spin_unlock_irqrestore(&fm->lock, flags); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 214 | #ifdef CONFIG_PM |
| 215 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 216 | static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state) |
| 217 | { |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 218 | struct tifm_adapter *fm = pci_get_drvdata(dev); |
| 219 | int cnt; |
| 220 | |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 221 | dev_dbg(&dev->dev, "suspending host\n"); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 222 | |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 223 | for (cnt = 0; cnt < fm->num_sockets; cnt++) { |
| 224 | if (fm->sockets[cnt]) |
| 225 | tifm_7xx1_sock_power_off(fm->sockets[cnt]->addr); |
| 226 | } |
| 227 | |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 228 | pci_save_state(dev); |
| 229 | pci_enable_wake(dev, pci_choose_state(dev, state), 0); |
| 230 | pci_disable_device(dev); |
| 231 | pci_set_power_state(dev, pci_choose_state(dev, state)); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int tifm_7xx1_resume(struct pci_dev *dev) |
| 236 | { |
| 237 | struct tifm_adapter *fm = pci_get_drvdata(dev); |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 238 | int rc; |
| 239 | unsigned int good_sockets = 0, bad_sockets = 0; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 240 | unsigned long flags; |
Alex Dubov | e23f2b8 | 2007-04-12 16:59:14 +1000 | [diff] [blame] | 241 | unsigned char new_ids[fm->num_sockets]; |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 242 | DECLARE_COMPLETION_ONSTACK(finish_resume); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 243 | |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 244 | pci_set_power_state(dev, PCI_D0); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 245 | pci_restore_state(dev); |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 246 | rc = pci_enable_device(dev); |
| 247 | if (rc) |
| 248 | return rc; |
| 249 | pci_set_master(dev); |
| 250 | |
| 251 | dev_dbg(&dev->dev, "resuming host\n"); |
| 252 | |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 253 | for (rc = 0; rc < fm->num_sockets; rc++) |
| 254 | new_ids[rc] = tifm_7xx1_toggle_sock_power( |
| 255 | tifm_7xx1_sock_addr(fm->addr, rc)); |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 256 | spin_lock_irqsave(&fm->lock, flags); |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 257 | for (rc = 0; rc < fm->num_sockets; rc++) { |
| 258 | if (fm->sockets[rc]) { |
| 259 | if (fm->sockets[rc]->type == new_ids[rc]) |
| 260 | good_sockets |= 1 << rc; |
| 261 | else |
| 262 | bad_sockets |= 1 << rc; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
| 266 | writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1), |
| 267 | fm->addr + FM_SET_INTERRUPT_ENABLE); |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 268 | dev_dbg(&dev->dev, "change sets on resume: good %x, bad %x\n", |
| 269 | good_sockets, bad_sockets); |
| 270 | |
| 271 | fm->socket_change_set = 0; |
| 272 | if (good_sockets) { |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 273 | fm->finish_me = &finish_resume; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 274 | spin_unlock_irqrestore(&fm->lock, flags); |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 275 | rc = wait_for_completion_timeout(&finish_resume, HZ); |
| 276 | dev_dbg(&dev->dev, "wait returned %d\n", rc); |
| 277 | writel(TIFM_IRQ_FIFOMASK(good_sockets) |
| 278 | | TIFM_IRQ_CARDMASK(good_sockets), |
| 279 | fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
| 280 | writel(TIFM_IRQ_FIFOMASK(good_sockets) |
| 281 | | TIFM_IRQ_CARDMASK(good_sockets), |
| 282 | fm->addr + FM_SET_INTERRUPT_ENABLE); |
| 283 | spin_lock_irqsave(&fm->lock, flags); |
| 284 | fm->finish_me = NULL; |
| 285 | fm->socket_change_set ^= good_sockets & fm->socket_change_set; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 286 | } |
| 287 | |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 288 | fm->socket_change_set |= bad_sockets; |
| 289 | if (fm->socket_change_set) |
| 290 | tifm_queue_work(&fm->media_switcher); |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 291 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 292 | spin_unlock_irqrestore(&fm->lock, flags); |
Alex Dubov | 88de1b2 | 2007-04-12 16:59:19 +1000 | [diff] [blame] | 293 | writel(TIFM_IRQ_ENABLE, |
| 294 | fm->addr + FM_SET_INTERRUPT_ENABLE); |
| 295 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 299 | #else |
| 300 | |
| 301 | #define tifm_7xx1_suspend NULL |
| 302 | #define tifm_7xx1_resume NULL |
| 303 | |
| 304 | #endif /* CONFIG_PM */ |
| 305 | |
Alex Dubov | baf8532 | 2008-02-09 10:20:54 -0800 | [diff] [blame] | 306 | static int tifm_7xx1_dummy_has_ms_pif(struct tifm_adapter *fm, |
| 307 | struct tifm_dev *sock) |
| 308 | { |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int tifm_7xx1_has_ms_pif(struct tifm_adapter *fm, struct tifm_dev *sock) |
| 313 | { |
| 314 | if (((fm->num_sockets == 4) && (sock->socket_id == 2)) |
| 315 | || ((fm->num_sockets == 2) && (sock->socket_id == 0))) |
| 316 | return 1; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 321 | static int tifm_7xx1_probe(struct pci_dev *dev, |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 322 | const struct pci_device_id *dev_id) |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 323 | { |
| 324 | struct tifm_adapter *fm; |
| 325 | int pci_dev_busy = 0; |
| 326 | int rc; |
| 327 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 328 | rc = pci_set_dma_mask(dev, DMA_BIT_MASK(32)); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 329 | if (rc) |
| 330 | return rc; |
| 331 | |
| 332 | rc = pci_enable_device(dev); |
| 333 | if (rc) |
| 334 | return rc; |
| 335 | |
| 336 | pci_set_master(dev); |
| 337 | |
| 338 | rc = pci_request_regions(dev, DRIVER_NAME); |
| 339 | if (rc) { |
| 340 | pci_dev_busy = 1; |
| 341 | goto err_out; |
| 342 | } |
| 343 | |
| 344 | pci_intx(dev, 1); |
| 345 | |
Alex Dubov | 6113ed7 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 346 | fm = tifm_alloc_adapter(dev->device == PCI_DEVICE_ID_TI_XX21_XX11_FM |
| 347 | ? 4 : 2, &dev->dev); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 348 | if (!fm) { |
| 349 | rc = -ENOMEM; |
| 350 | goto err_out_int; |
| 351 | } |
| 352 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 353 | INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 354 | fm->eject = tifm_7xx1_eject; |
Alex Dubov | baf8532 | 2008-02-09 10:20:54 -0800 | [diff] [blame] | 355 | fm->has_ms_pif = tifm_7xx1_has_ms_pif; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 356 | pci_set_drvdata(dev, fm); |
| 357 | |
Arjan van de Ven | bdbeed7 | 2009-01-06 14:40:39 -0800 | [diff] [blame] | 358 | fm->addr = pci_ioremap_bar(dev, 0); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 359 | if (!fm->addr) |
| 360 | goto err_out_free; |
| 361 | |
Jeff Garzik | bc913b1 | 2007-06-01 00:46:47 -0700 | [diff] [blame] | 362 | rc = request_irq(dev->irq, tifm_7xx1_isr, IRQF_SHARED, DRIVER_NAME, fm); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 363 | if (rc) |
| 364 | goto err_out_unmap; |
| 365 | |
Alex Dubov | 3540af8 | 2007-04-12 16:59:15 +1000 | [diff] [blame] | 366 | rc = tifm_add_adapter(fm); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 367 | if (rc) |
| 368 | goto err_out_irq; |
| 369 | |
Alex Dubov | 6412d92 | 2006-12-11 01:55:33 +1100 | [diff] [blame] | 370 | writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1), |
Alex Dubov | e4c70e8 | 2008-03-10 11:43:41 -0700 | [diff] [blame] | 371 | fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
| 372 | writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1), |
Alex Dubov | 8b40ada | 2006-12-11 01:55:36 +1100 | [diff] [blame] | 373 | fm->addr + FM_SET_INTERRUPT_ENABLE); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 374 | return 0; |
| 375 | |
| 376 | err_out_irq: |
| 377 | free_irq(dev->irq, fm); |
| 378 | err_out_unmap: |
| 379 | iounmap(fm->addr); |
| 380 | err_out_free: |
| 381 | pci_set_drvdata(dev, NULL); |
| 382 | tifm_free_adapter(fm); |
| 383 | err_out_int: |
| 384 | pci_intx(dev, 0); |
| 385 | pci_release_regions(dev); |
| 386 | err_out: |
| 387 | if (!pci_dev_busy) |
| 388 | pci_disable_device(dev); |
| 389 | return rc; |
| 390 | } |
| 391 | |
| 392 | static void tifm_7xx1_remove(struct pci_dev *dev) |
| 393 | { |
| 394 | struct tifm_adapter *fm = pci_get_drvdata(dev); |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 395 | int cnt; |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 396 | |
Alex Dubov | 6113ed7 | 2007-04-12 16:59:17 +1000 | [diff] [blame] | 397 | fm->eject = tifm_7xx1_dummy_eject; |
Alex Dubov | baf8532 | 2008-02-09 10:20:54 -0800 | [diff] [blame] | 398 | fm->has_ms_pif = tifm_7xx1_dummy_has_ms_pif; |
Alex Dubov | 7146f0d | 2006-12-18 14:20:06 +1100 | [diff] [blame] | 399 | writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE); |
| 400 | mmiowb(); |
| 401 | free_irq(dev->irq, fm); |
| 402 | |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 403 | tifm_remove_adapter(fm); |
| 404 | |
Alex Dubov | 055b822 | 2007-05-01 20:14:55 -0700 | [diff] [blame] | 405 | for (cnt = 0; cnt < fm->num_sockets; cnt++) |
| 406 | tifm_7xx1_sock_power_off(tifm_7xx1_sock_addr(fm->addr, cnt)); |
| 407 | |
Al Viro | e069d79 | 2006-10-09 20:29:43 +0100 | [diff] [blame] | 408 | pci_set_drvdata(dev, NULL); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 409 | |
| 410 | iounmap(fm->addr); |
| 411 | pci_intx(dev, 0); |
| 412 | pci_release_regions(dev); |
| 413 | |
| 414 | pci_disable_device(dev); |
| 415 | tifm_free_adapter(fm); |
| 416 | } |
| 417 | |
| 418 | static struct pci_device_id tifm_7xx1_pci_tbl [] = { |
Alex Dubov | b5ad676 | 2006-12-11 01:55:35 +1100 | [diff] [blame] | 419 | { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX21_XX11_FM, PCI_ANY_ID, |
| 420 | PCI_ANY_ID, 0, 0, 0 }, /* xx21 - the one I have */ |
| 421 | { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX12_FM, PCI_ANY_ID, |
| 422 | PCI_ANY_ID, 0, 0, 0 }, |
| 423 | { PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX20_FM, PCI_ANY_ID, |
| 424 | PCI_ANY_ID, 0, 0, 0 }, |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 425 | { } |
| 426 | }; |
| 427 | |
| 428 | static struct pci_driver tifm_7xx1_driver = { |
| 429 | .name = DRIVER_NAME, |
| 430 | .id_table = tifm_7xx1_pci_tbl, |
| 431 | .probe = tifm_7xx1_probe, |
| 432 | .remove = tifm_7xx1_remove, |
| 433 | .suspend = tifm_7xx1_suspend, |
| 434 | .resume = tifm_7xx1_resume, |
| 435 | }; |
| 436 | |
Devendra Naga | 7e0b2cd | 2012-08-26 14:32:43 +0530 | [diff] [blame] | 437 | module_pci_driver(tifm_7xx1_driver); |
Alex Dubov | 4020f2d | 2006-10-04 02:15:37 -0700 | [diff] [blame] | 438 | MODULE_AUTHOR("Alex Dubov"); |
| 439 | MODULE_DESCRIPTION("TI FlashMedia host driver"); |
| 440 | MODULE_LICENSE("GPL"); |
| 441 | MODULE_DEVICE_TABLE(pci, tifm_7xx1_pci_tbl); |
| 442 | MODULE_VERSION(DRIVER_VERSION); |