Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Regular cardbus driver ("yenta_socket") |
| 3 | * |
| 4 | * (C) Copyright 1999, 2000 Linus Torvalds |
| 5 | * |
| 6 | * Changelog: |
| 7 | * Aug 2002: Manfred Spraul <manfred@colorfullife.com> |
| 8 | * Dynamically adjust the size of the bridge resource |
| 9 | * |
| 10 | * May 2003: Dominik Brodowski <linux@brodo.de> |
| 11 | * Merge pci_socket.c and yenta.c into one file |
| 12 | */ |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/workqueue.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/module.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <pcmcia/cs_types.h> |
| 22 | #include <pcmcia/ss.h> |
| 23 | #include <pcmcia/cs.h> |
| 24 | |
| 25 | #include <asm/io.h> |
| 26 | |
| 27 | #include "yenta_socket.h" |
| 28 | #include "i82365.h" |
| 29 | |
| 30 | static int disable_clkrun; |
| 31 | module_param(disable_clkrun, bool, 0444); |
| 32 | MODULE_PARM_DESC(disable_clkrun, "If PC card doesn't function properly, please try this option"); |
| 33 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 34 | static int isa_probe = 1; |
| 35 | module_param(isa_probe, bool, 0444); |
| 36 | MODULE_PARM_DESC(isa_probe, "If set ISA interrupts are probed (default). Set to N to disable probing"); |
| 37 | |
| 38 | static int pwr_irqs_off; |
| 39 | module_param(pwr_irqs_off, bool, 0644); |
| 40 | MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #if 0 |
| 43 | #define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args) |
| 44 | #else |
| 45 | #define debug(x,args...) |
| 46 | #endif |
| 47 | |
| 48 | /* Don't ask.. */ |
| 49 | #define to_cycles(ns) ((ns)/120) |
| 50 | #define to_ns(cycles) ((cycles)*120) |
| 51 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 52 | /** |
| 53 | * yenta PCI irq probing. |
| 54 | * currently only used in the TI/EnE initialization code |
| 55 | */ |
| 56 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static int yenta_probe_cb_irq(struct yenta_socket *socket); |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 58 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | |
| 61 | static unsigned int override_bios; |
| 62 | module_param(override_bios, uint, 0000); |
| 63 | MODULE_PARM_DESC (override_bios, "yenta ignore bios resource allocation"); |
| 64 | |
| 65 | /* |
| 66 | * Generate easy-to-use ways of reading a cardbus sockets |
| 67 | * regular memory space ("cb_xxx"), configuration space |
| 68 | * ("config_xxx") and compatibility space ("exca_xxxx") |
| 69 | */ |
| 70 | static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg) |
| 71 | { |
| 72 | u32 val = readl(socket->base + reg); |
| 73 | debug("%p %04x %08x\n", socket, reg, val); |
| 74 | return val; |
| 75 | } |
| 76 | |
| 77 | static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val) |
| 78 | { |
| 79 | debug("%p %04x %08x\n", socket, reg, val); |
| 80 | writel(val, socket->base + reg); |
Daniel Ritz | c8751e4 | 2005-09-09 13:03:25 -0700 | [diff] [blame] | 81 | readl(socket->base + reg); /* avoid problems with PCI write posting */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static inline u8 config_readb(struct yenta_socket *socket, unsigned offset) |
| 85 | { |
| 86 | u8 val; |
| 87 | pci_read_config_byte(socket->dev, offset, &val); |
| 88 | debug("%p %04x %02x\n", socket, offset, val); |
| 89 | return val; |
| 90 | } |
| 91 | |
| 92 | static inline u16 config_readw(struct yenta_socket *socket, unsigned offset) |
| 93 | { |
| 94 | u16 val; |
| 95 | pci_read_config_word(socket->dev, offset, &val); |
| 96 | debug("%p %04x %04x\n", socket, offset, val); |
| 97 | return val; |
| 98 | } |
| 99 | |
| 100 | static inline u32 config_readl(struct yenta_socket *socket, unsigned offset) |
| 101 | { |
| 102 | u32 val; |
| 103 | pci_read_config_dword(socket->dev, offset, &val); |
| 104 | debug("%p %04x %08x\n", socket, offset, val); |
| 105 | return val; |
| 106 | } |
| 107 | |
| 108 | static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val) |
| 109 | { |
| 110 | debug("%p %04x %02x\n", socket, offset, val); |
| 111 | pci_write_config_byte(socket->dev, offset, val); |
| 112 | } |
| 113 | |
| 114 | static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val) |
| 115 | { |
| 116 | debug("%p %04x %04x\n", socket, offset, val); |
| 117 | pci_write_config_word(socket->dev, offset, val); |
| 118 | } |
| 119 | |
| 120 | static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val) |
| 121 | { |
| 122 | debug("%p %04x %08x\n", socket, offset, val); |
| 123 | pci_write_config_dword(socket->dev, offset, val); |
| 124 | } |
| 125 | |
| 126 | static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg) |
| 127 | { |
| 128 | u8 val = readb(socket->base + 0x800 + reg); |
| 129 | debug("%p %04x %02x\n", socket, reg, val); |
| 130 | return val; |
| 131 | } |
| 132 | |
| 133 | static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg) |
| 134 | { |
| 135 | u16 val; |
| 136 | val = readb(socket->base + 0x800 + reg); |
| 137 | val |= readb(socket->base + 0x800 + reg + 1) << 8; |
| 138 | debug("%p %04x %04x\n", socket, reg, val); |
| 139 | return val; |
| 140 | } |
| 141 | |
| 142 | static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val) |
| 143 | { |
| 144 | debug("%p %04x %02x\n", socket, reg, val); |
| 145 | writeb(val, socket->base + 0x800 + reg); |
Daniel Ritz | c8751e4 | 2005-09-09 13:03:25 -0700 | [diff] [blame] | 146 | readb(socket->base + 0x800 + reg); /* PCI write posting... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val) |
| 150 | { |
| 151 | debug("%p %04x %04x\n", socket, reg, val); |
| 152 | writeb(val, socket->base + 0x800 + reg); |
| 153 | writeb(val >> 8, socket->base + 0x800 + reg + 1); |
Daniel Ritz | c8751e4 | 2005-09-09 13:03:25 -0700 | [diff] [blame] | 154 | |
| 155 | /* PCI write posting... */ |
| 156 | readb(socket->base + 0x800 + reg); |
| 157 | readb(socket->base + 0x800 + reg + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 160 | static ssize_t show_yenta_registers(struct device *yentadev, struct device_attribute *attr, char *buf) |
| 161 | { |
| 162 | struct pci_dev *dev = to_pci_dev(yentadev); |
| 163 | struct yenta_socket *socket = pci_get_drvdata(dev); |
| 164 | int offset = 0, i; |
| 165 | |
| 166 | offset = snprintf(buf, PAGE_SIZE, "CB registers:"); |
| 167 | for (i = 0; i < 0x24; i += 4) { |
| 168 | unsigned val; |
| 169 | if (!(i & 15)) |
| 170 | offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
| 171 | val = cb_readl(socket, i); |
| 172 | offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val); |
| 173 | } |
| 174 | |
| 175 | offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:"); |
| 176 | for (i = 0; i < 0x45; i++) { |
| 177 | unsigned char val; |
| 178 | if (!(i & 7)) { |
| 179 | if (i & 8) { |
| 180 | memcpy(buf + offset, " -", 2); |
| 181 | offset += 2; |
| 182 | } else |
| 183 | offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
| 184 | } |
| 185 | val = exca_readb(socket, i); |
| 186 | offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val); |
| 187 | } |
| 188 | buf[offset++] = '\n'; |
| 189 | return offset; |
| 190 | } |
| 191 | |
| 192 | static DEVICE_ATTR(yenta_registers, S_IRUSR, show_yenta_registers, NULL); |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* |
| 195 | * Ugh, mixed-mode cardbus and 16-bit pccard state: things depend |
| 196 | * on what kind of card is inserted.. |
| 197 | */ |
| 198 | static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value) |
| 199 | { |
| 200 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 201 | unsigned int val; |
| 202 | u32 state = cb_readl(socket, CB_SOCKET_STATE); |
| 203 | |
| 204 | val = (state & CB_3VCARD) ? SS_3VCARD : 0; |
| 205 | val |= (state & CB_XVCARD) ? SS_XVCARD : 0; |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 206 | val |= (state & (CB_5VCARD | CB_3VCARD | CB_XVCARD | CB_YVCARD)) ? 0 : SS_PENDING; |
| 207 | val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? SS_PENDING : 0; |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | if (state & CB_CBCARD) { |
| 211 | val |= SS_CARDBUS; |
| 212 | val |= (state & CB_CARDSTS) ? SS_STSCHG : 0; |
| 213 | val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT; |
| 214 | val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0; |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 215 | } else if (state & CB_16BITCARD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | u8 status = exca_readb(socket, I365_STATUS); |
| 217 | val |= ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0; |
| 218 | if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) { |
| 219 | val |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG; |
| 220 | } else { |
| 221 | val |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD; |
| 222 | val |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN; |
| 223 | } |
| 224 | val |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0; |
| 225 | val |= (status & I365_CS_READY) ? SS_READY : 0; |
| 226 | val |= (status & I365_CS_POWERON) ? SS_POWERON : 0; |
| 227 | } |
| 228 | |
| 229 | *value = val; |
| 230 | return 0; |
| 231 | } |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static void yenta_set_power(struct yenta_socket *socket, socket_state_t *state) |
| 234 | { |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 235 | /* some birdges require to use the ExCA registers to power 16bit cards */ |
| 236 | if (!(cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) && |
| 237 | (socket->flags & YENTA_16BIT_POWER_EXCA)) { |
| 238 | u8 reg, old; |
| 239 | reg = old = exca_readb(socket, I365_POWER); |
| 240 | reg &= ~(I365_VCC_MASK | I365_VPP1_MASK | I365_VPP2_MASK); |
| 241 | |
| 242 | /* i82365SL-DF style */ |
| 243 | if (socket->flags & YENTA_16BIT_POWER_DF) { |
| 244 | switch (state->Vcc) { |
| 245 | case 33: reg |= I365_VCC_3V; break; |
| 246 | case 50: reg |= I365_VCC_5V; break; |
| 247 | default: reg = 0; break; |
| 248 | } |
| 249 | switch (state->Vpp) { |
| 250 | case 33: |
| 251 | case 50: reg |= I365_VPP1_5V; break; |
| 252 | case 120: reg |= I365_VPP1_12V; break; |
| 253 | } |
| 254 | } else { |
| 255 | /* i82365SL-B style */ |
| 256 | switch (state->Vcc) { |
| 257 | case 50: reg |= I365_VCC_5V; break; |
| 258 | default: reg = 0; break; |
| 259 | } |
| 260 | switch (state->Vpp) { |
| 261 | case 50: reg |= I365_VPP1_5V | I365_VPP2_5V; break; |
| 262 | case 120: reg |= I365_VPP1_12V | I365_VPP2_12V; break; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if (reg != old) |
| 267 | exca_writeb(socket, I365_POWER, reg); |
| 268 | } else { |
| 269 | u32 reg = 0; /* CB_SC_STPCLK? */ |
| 270 | switch (state->Vcc) { |
| 271 | case 33: reg = CB_SC_VCC_3V; break; |
| 272 | case 50: reg = CB_SC_VCC_5V; break; |
| 273 | default: reg = 0; break; |
| 274 | } |
| 275 | switch (state->Vpp) { |
| 276 | case 33: reg |= CB_SC_VPP_3V; break; |
| 277 | case 50: reg |= CB_SC_VPP_5V; break; |
| 278 | case 120: reg |= CB_SC_VPP_12V; break; |
| 279 | } |
| 280 | if (reg != cb_readl(socket, CB_SOCKET_CONTROL)) |
| 281 | cb_writel(socket, CB_SOCKET_CONTROL, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static int yenta_set_socket(struct pcmcia_socket *sock, socket_state_t *state) |
| 286 | { |
| 287 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 288 | u16 bridge; |
| 289 | |
| 290 | yenta_set_power(socket, state); |
| 291 | socket->io_irq = state->io_irq; |
| 292 | bridge = config_readw(socket, CB_BRIDGE_CONTROL) & ~(CB_BRIDGE_CRST | CB_BRIDGE_INTR); |
| 293 | if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) { |
| 294 | u8 intr; |
| 295 | bridge |= (state->flags & SS_RESET) ? CB_BRIDGE_CRST : 0; |
| 296 | |
| 297 | /* ISA interrupt control? */ |
| 298 | intr = exca_readb(socket, I365_INTCTL); |
| 299 | intr = (intr & ~0xf); |
| 300 | if (!socket->cb_irq) { |
| 301 | intr |= state->io_irq; |
| 302 | bridge |= CB_BRIDGE_INTR; |
| 303 | } |
| 304 | exca_writeb(socket, I365_INTCTL, intr); |
| 305 | } else { |
| 306 | u8 reg; |
| 307 | |
| 308 | reg = exca_readb(socket, I365_INTCTL) & (I365_RING_ENA | I365_INTR_ENA); |
| 309 | reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET; |
| 310 | reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0; |
| 311 | if (state->io_irq != socket->cb_irq) { |
| 312 | reg |= state->io_irq; |
| 313 | bridge |= CB_BRIDGE_INTR; |
| 314 | } |
| 315 | exca_writeb(socket, I365_INTCTL, reg); |
| 316 | |
| 317 | reg = exca_readb(socket, I365_POWER) & (I365_VCC_MASK|I365_VPP1_MASK); |
| 318 | reg |= I365_PWR_NORESET; |
| 319 | if (state->flags & SS_PWR_AUTO) reg |= I365_PWR_AUTO; |
| 320 | if (state->flags & SS_OUTPUT_ENA) reg |= I365_PWR_OUT; |
| 321 | if (exca_readb(socket, I365_POWER) != reg) |
| 322 | exca_writeb(socket, I365_POWER, reg); |
| 323 | |
| 324 | /* CSC interrupt: no ISA irq for CSC */ |
| 325 | reg = I365_CSC_DETECT; |
| 326 | if (state->flags & SS_IOCARD) { |
| 327 | if (state->csc_mask & SS_STSCHG) reg |= I365_CSC_STSCHG; |
| 328 | } else { |
| 329 | if (state->csc_mask & SS_BATDEAD) reg |= I365_CSC_BVD1; |
| 330 | if (state->csc_mask & SS_BATWARN) reg |= I365_CSC_BVD2; |
| 331 | if (state->csc_mask & SS_READY) reg |= I365_CSC_READY; |
| 332 | } |
| 333 | exca_writeb(socket, I365_CSCINT, reg); |
| 334 | exca_readb(socket, I365_CSC); |
| 335 | if(sock->zoom_video) |
| 336 | sock->zoom_video(sock, state->flags & SS_ZVCARD); |
| 337 | } |
| 338 | config_writew(socket, CB_BRIDGE_CONTROL, bridge); |
| 339 | /* Socket event mask: get card insert/remove events.. */ |
| 340 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 341 | cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK); |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | static int yenta_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io) |
| 346 | { |
| 347 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 348 | int map; |
| 349 | unsigned char ioctl, addr, enable; |
| 350 | |
| 351 | map = io->map; |
| 352 | |
| 353 | if (map > 1) |
| 354 | return -EINVAL; |
| 355 | |
| 356 | enable = I365_ENA_IO(map); |
| 357 | addr = exca_readb(socket, I365_ADDRWIN); |
| 358 | |
| 359 | /* Disable the window before changing it.. */ |
| 360 | if (addr & enable) { |
| 361 | addr &= ~enable; |
| 362 | exca_writeb(socket, I365_ADDRWIN, addr); |
| 363 | } |
| 364 | |
| 365 | exca_writew(socket, I365_IO(map)+I365_W_START, io->start); |
| 366 | exca_writew(socket, I365_IO(map)+I365_W_STOP, io->stop); |
| 367 | |
| 368 | ioctl = exca_readb(socket, I365_IOCTL) & ~I365_IOCTL_MASK(map); |
| 369 | if (io->flags & MAP_0WS) ioctl |= I365_IOCTL_0WS(map); |
| 370 | if (io->flags & MAP_16BIT) ioctl |= I365_IOCTL_16BIT(map); |
| 371 | if (io->flags & MAP_AUTOSZ) ioctl |= I365_IOCTL_IOCS16(map); |
| 372 | exca_writeb(socket, I365_IOCTL, ioctl); |
| 373 | |
| 374 | if (io->flags & MAP_ACTIVE) |
| 375 | exca_writeb(socket, I365_ADDRWIN, addr | enable); |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int yenta_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem) |
| 380 | { |
| 381 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 382 | struct pci_bus_region region; |
| 383 | int map; |
| 384 | unsigned char addr, enable; |
| 385 | unsigned int start, stop, card_start; |
| 386 | unsigned short word; |
| 387 | |
| 388 | pcibios_resource_to_bus(socket->dev, ®ion, mem->res); |
| 389 | |
| 390 | map = mem->map; |
| 391 | start = region.start; |
| 392 | stop = region.end; |
| 393 | card_start = mem->card_start; |
| 394 | |
| 395 | if (map > 4 || start > stop || ((start ^ stop) >> 24) || |
| 396 | (card_start >> 26) || mem->speed > 1000) |
| 397 | return -EINVAL; |
| 398 | |
| 399 | enable = I365_ENA_MEM(map); |
| 400 | addr = exca_readb(socket, I365_ADDRWIN); |
| 401 | if (addr & enable) { |
| 402 | addr &= ~enable; |
| 403 | exca_writeb(socket, I365_ADDRWIN, addr); |
| 404 | } |
| 405 | |
| 406 | exca_writeb(socket, CB_MEM_PAGE(map), start >> 24); |
| 407 | |
| 408 | word = (start >> 12) & 0x0fff; |
| 409 | if (mem->flags & MAP_16BIT) |
| 410 | word |= I365_MEM_16BIT; |
| 411 | if (mem->flags & MAP_0WS) |
| 412 | word |= I365_MEM_0WS; |
| 413 | exca_writew(socket, I365_MEM(map) + I365_W_START, word); |
| 414 | |
| 415 | word = (stop >> 12) & 0x0fff; |
| 416 | switch (to_cycles(mem->speed)) { |
| 417 | case 0: break; |
| 418 | case 1: word |= I365_MEM_WS0; break; |
| 419 | case 2: word |= I365_MEM_WS1; break; |
| 420 | default: word |= I365_MEM_WS1 | I365_MEM_WS0; break; |
| 421 | } |
| 422 | exca_writew(socket, I365_MEM(map) + I365_W_STOP, word); |
| 423 | |
| 424 | word = ((card_start - start) >> 12) & 0x3fff; |
| 425 | if (mem->flags & MAP_WRPROT) |
| 426 | word |= I365_MEM_WRPROT; |
| 427 | if (mem->flags & MAP_ATTRIB) |
| 428 | word |= I365_MEM_REG; |
| 429 | exca_writew(socket, I365_MEM(map) + I365_W_OFF, word); |
| 430 | |
| 431 | if (mem->flags & MAP_ACTIVE) |
| 432 | exca_writeb(socket, I365_ADDRWIN, addr | enable); |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 437 | |
| 438 | static irqreturn_t yenta_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 440 | unsigned int events; |
| 441 | struct yenta_socket *socket = (struct yenta_socket *) dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | u8 csc; |
| 443 | u32 cb_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | /* Clear interrupt status for the event */ |
| 446 | cb_event = cb_readl(socket, CB_SOCKET_EVENT); |
| 447 | cb_writel(socket, CB_SOCKET_EVENT, cb_event); |
| 448 | |
| 449 | csc = exca_readb(socket, I365_CSC); |
| 450 | |
Daniel Ritz | e411580 | 2005-09-20 14:17:37 -0700 | [diff] [blame] | 451 | if (!(cb_event || csc)) |
| 452 | return IRQ_NONE; |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | events = (cb_event & (CB_CD1EVENT | CB_CD2EVENT)) ? SS_DETECT : 0 ; |
| 455 | events |= (csc & I365_CSC_DETECT) ? SS_DETECT : 0; |
| 456 | if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) { |
| 457 | events |= (csc & I365_CSC_STSCHG) ? SS_STSCHG : 0; |
| 458 | } else { |
| 459 | events |= (csc & I365_CSC_BVD1) ? SS_BATDEAD : 0; |
| 460 | events |= (csc & I365_CSC_BVD2) ? SS_BATWARN : 0; |
| 461 | events |= (csc & I365_CSC_READY) ? SS_READY : 0; |
| 462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 464 | if (events) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | pcmcia_parse_events(&socket->socket, events); |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 466 | |
Daniel Ritz | e411580 | 2005-09-20 14:17:37 -0700 | [diff] [blame] | 467 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static void yenta_interrupt_wrapper(unsigned long data) |
| 471 | { |
| 472 | struct yenta_socket *socket = (struct yenta_socket *) data; |
| 473 | |
| 474 | yenta_interrupt(0, (void *)socket, NULL); |
| 475 | socket->poll_timer.expires = jiffies + HZ; |
| 476 | add_timer(&socket->poll_timer); |
| 477 | } |
| 478 | |
| 479 | static void yenta_clear_maps(struct yenta_socket *socket) |
| 480 | { |
| 481 | int i; |
| 482 | struct resource res = { .start = 0, .end = 0x0fff }; |
| 483 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
| 484 | pccard_mem_map mem = { .res = &res, }; |
| 485 | |
| 486 | yenta_set_socket(&socket->socket, &dead_socket); |
| 487 | for (i = 0; i < 2; i++) { |
| 488 | io.map = i; |
| 489 | yenta_set_io_map(&socket->socket, &io); |
| 490 | } |
| 491 | for (i = 0; i < 5; i++) { |
| 492 | mem.map = i; |
| 493 | yenta_set_mem_map(&socket->socket, &mem); |
| 494 | } |
| 495 | } |
| 496 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 497 | /* redoes voltage interrogation if required */ |
| 498 | static void yenta_interrogate(struct yenta_socket *socket) |
| 499 | { |
| 500 | u32 state; |
| 501 | |
| 502 | state = cb_readl(socket, CB_SOCKET_STATE); |
| 503 | if (!(state & (CB_5VCARD | CB_3VCARD | CB_XVCARD | CB_YVCARD)) || |
| 504 | (state & (CB_CDETECT1 | CB_CDETECT2 | CB_NOTACARD | CB_BADVCCREQ)) || |
| 505 | ((state & (CB_16BITCARD | CB_CBCARD)) == (CB_16BITCARD | CB_CBCARD))) |
| 506 | cb_writel(socket, CB_SOCKET_FORCE, CB_CVSTEST); |
| 507 | } |
| 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | /* Called at resume and initialization events */ |
| 510 | static int yenta_sock_init(struct pcmcia_socket *sock) |
| 511 | { |
| 512 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | exca_writeb(socket, I365_GBLCTL, 0x00); |
| 515 | exca_writeb(socket, I365_GENCTL, 0x00); |
| 516 | |
| 517 | /* Redo card voltage interrogation */ |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 518 | yenta_interrogate(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | yenta_clear_maps(socket); |
| 521 | |
| 522 | if (socket->type && socket->type->sock_init) |
| 523 | socket->type->sock_init(socket); |
| 524 | |
| 525 | /* Re-enable CSC interrupts */ |
| 526 | cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static int yenta_sock_suspend(struct pcmcia_socket *sock) |
| 532 | { |
| 533 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 534 | |
| 535 | /* Disable CSC interrupts */ |
| 536 | cb_writel(socket, CB_SOCKET_MASK, 0x0); |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Use an adaptive allocation for the memory resource, |
| 543 | * sometimes the memory behind pci bridges is limited: |
| 544 | * 1/8 of the size of the io window of the parent. |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 545 | * max 4 MB, min 16 kB. We try very hard to not get below |
| 546 | * the "ACC" values, though. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | */ |
| 548 | #define BRIDGE_MEM_MAX 4*1024*1024 |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 549 | #define BRIDGE_MEM_ACC 128*1024 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | #define BRIDGE_MEM_MIN 16*1024 |
| 551 | |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 552 | #define BRIDGE_IO_MAX 512 |
| 553 | #define BRIDGE_IO_ACC 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | #define BRIDGE_IO_MIN 32 |
| 555 | |
| 556 | #ifndef PCIBIOS_MIN_CARDBUS_IO |
| 557 | #define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO |
| 558 | #endif |
| 559 | |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 560 | static int yenta_search_one_res(struct resource *root, struct resource *res, |
| 561 | u32 min) |
| 562 | { |
| 563 | u32 align, size, start, end; |
| 564 | |
| 565 | if (res->flags & IORESOURCE_IO) { |
| 566 | align = 1024; |
| 567 | size = BRIDGE_IO_MAX; |
| 568 | start = PCIBIOS_MIN_CARDBUS_IO; |
| 569 | end = ~0U; |
| 570 | } else { |
| 571 | unsigned long avail = root->end - root->start; |
| 572 | int i; |
| 573 | size = BRIDGE_MEM_MAX; |
| 574 | if (size > avail/8) { |
| 575 | size=(avail+1)/8; |
| 576 | /* round size down to next power of 2 */ |
| 577 | i = 0; |
| 578 | while ((size /= 2) != 0) |
| 579 | i++; |
| 580 | size = 1 << i; |
| 581 | } |
| 582 | if (size < min) |
| 583 | size = min; |
| 584 | align = size; |
| 585 | start = PCIBIOS_MIN_MEM; |
| 586 | end = ~0U; |
| 587 | } |
| 588 | |
| 589 | do { |
| 590 | if (allocate_resource(root, res, size, start, end, align, |
| 591 | NULL, NULL)==0) { |
| 592 | return 1; |
| 593 | } |
| 594 | size = size/2; |
| 595 | align = size; |
| 596 | } while (size >= min); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, |
| 603 | u32 min) |
| 604 | { |
| 605 | int i; |
| 606 | for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) { |
| 607 | struct resource * root = socket->dev->bus->resource[i]; |
| 608 | if (!root) |
| 609 | continue; |
| 610 | |
| 611 | if ((res->flags ^ root->flags) & |
| 612 | (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH)) |
| 613 | continue; /* Wrong type */ |
| 614 | |
| 615 | if (yenta_search_one_res(root, res, min)) |
| 616 | return 1; |
| 617 | } |
| 618 | return 0; |
| 619 | } |
| 620 | |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 621 | static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | struct resource *root, *res; |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 624 | struct pci_bus_region region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | unsigned mask; |
| 626 | |
Ivan Kokshaysky | 7925407 | 2005-06-27 16:28:02 -0700 | [diff] [blame] | 627 | res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; |
| 628 | /* Already allocated? */ |
| 629 | if (res->parent) |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 630 | return 0; |
Ivan Kokshaysky | 7925407 | 2005-06-27 16:28:02 -0700 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */ |
| 633 | mask = ~0xfff; |
| 634 | if (type & IORESOURCE_IO) |
| 635 | mask = ~3; |
| 636 | |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 637 | res->name = socket->dev->subordinate->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | res->flags = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 640 | region.start = config_readl(socket, addr_start) & mask; |
| 641 | region.end = config_readl(socket, addr_end) | ~mask; |
| 642 | if (region.start && region.end > region.start && !override_bios) { |
| 643 | pcibios_bus_to_resource(socket->dev, res, ®ion); |
Dominik Brodowski | 862104e | 2005-07-12 13:58:15 -0700 | [diff] [blame] | 644 | root = pci_find_parent_resource(socket->dev, res); |
| 645 | if (root && (request_resource(root, res) == 0)) |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 646 | return 0; |
Dominik Brodowski | 862104e | 2005-07-12 13:58:15 -0700 | [diff] [blame] | 647 | printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | pci_name(socket->dev), nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | if (type & IORESOURCE_IO) { |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 652 | if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) || |
| 653 | (yenta_search_res(socket, res, BRIDGE_IO_ACC)) || |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 654 | (yenta_search_res(socket, res, BRIDGE_IO_MIN))) |
| 655 | return 1; |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 656 | } else { |
| 657 | if (type & IORESOURCE_PREFETCH) { |
| 658 | if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) || |
| 659 | (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) || |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 660 | (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) |
| 661 | return 1; |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 662 | /* Approximating prefetchable by non-prefetchable */ |
| 663 | res->flags = IORESOURCE_MEM; |
| 664 | } |
| 665 | if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) || |
| 666 | (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) || |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 667 | (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) |
| 668 | return 1; |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n", |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 672 | pci_name(socket->dev), type); |
| 673 | res->start = res->end = res->flags = 0; |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 674 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Allocate the bridge mappings for the device.. |
| 679 | */ |
| 680 | static void yenta_allocate_resources(struct yenta_socket *socket) |
| 681 | { |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 682 | int program = 0; |
| 683 | program += yenta_allocate_res(socket, 0, IORESOURCE_IO, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 684 | PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 685 | program += yenta_allocate_res(socket, 1, IORESOURCE_IO, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 686 | PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 687 | program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 688 | PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 689 | program += yenta_allocate_res(socket, 3, IORESOURCE_MEM, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 690 | PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 691 | if (program) |
| 692 | pci_setup_cardbus(socket->dev->subordinate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | |
| 696 | /* |
| 697 | * Free the bridge mappings for the device.. |
| 698 | */ |
| 699 | static void yenta_free_resources(struct yenta_socket *socket) |
| 700 | { |
| 701 | int i; |
| 702 | for (i=0;i<4;i++) { |
| 703 | struct resource *res; |
| 704 | res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i; |
| 705 | if (res->start != 0 && res->end != 0) |
| 706 | release_resource(res); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 707 | res->start = res->end = res->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /* |
| 713 | * Close it down - release our resources and go home.. |
| 714 | */ |
| 715 | static void yenta_close(struct pci_dev *dev) |
| 716 | { |
| 717 | struct yenta_socket *sock = pci_get_drvdata(dev); |
| 718 | |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 719 | /* Remove the register attributes */ |
| 720 | device_remove_file(&dev->dev, &dev_attr_yenta_registers); |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* we don't want a dying socket registered */ |
| 723 | pcmcia_unregister_socket(&sock->socket); |
| 724 | |
| 725 | /* Disable all events so we don't die in an IRQ storm */ |
| 726 | cb_writel(sock, CB_SOCKET_MASK, 0x0); |
| 727 | exca_writeb(sock, I365_CSCINT, 0); |
| 728 | |
| 729 | if (sock->cb_irq) |
| 730 | free_irq(sock->cb_irq, sock); |
| 731 | else |
| 732 | del_timer_sync(&sock->poll_timer); |
| 733 | |
| 734 | if (sock->base) |
| 735 | iounmap(sock->base); |
| 736 | yenta_free_resources(sock); |
| 737 | |
| 738 | pci_release_regions(dev); |
| 739 | pci_disable_device(dev); |
| 740 | pci_set_drvdata(dev, NULL); |
| 741 | } |
| 742 | |
| 743 | |
| 744 | static struct pccard_operations yenta_socket_operations = { |
| 745 | .init = yenta_sock_init, |
| 746 | .suspend = yenta_sock_suspend, |
| 747 | .get_status = yenta_get_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | .set_socket = yenta_set_socket, |
| 749 | .set_io_map = yenta_set_io_map, |
| 750 | .set_mem_map = yenta_set_mem_map, |
| 751 | }; |
| 752 | |
| 753 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 754 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | #include "ti113x.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 756 | #endif |
| 757 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | #include "ricoh.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 759 | #endif |
| 760 | #ifdef CONFIG_YENTA_TOSHIBA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | #include "topic.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 762 | #endif |
| 763 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | #include "o2micro.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 765 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
| 767 | enum { |
| 768 | CARDBUS_TYPE_DEFAULT = -1, |
| 769 | CARDBUS_TYPE_TI, |
| 770 | CARDBUS_TYPE_TI113X, |
| 771 | CARDBUS_TYPE_TI12XX, |
| 772 | CARDBUS_TYPE_TI1250, |
| 773 | CARDBUS_TYPE_RICOH, |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 774 | CARDBUS_TYPE_TOPIC95, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | CARDBUS_TYPE_TOPIC97, |
| 776 | CARDBUS_TYPE_O2MICRO, |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 777 | CARDBUS_TYPE_ENE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | }; |
| 779 | |
| 780 | /* |
| 781 | * Different cardbus controllers have slightly different |
| 782 | * initialization sequences etc details. List them here.. |
| 783 | */ |
| 784 | static struct cardbus_type cardbus_type[] = { |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 785 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | [CARDBUS_TYPE_TI] = { |
| 787 | .override = ti_override, |
| 788 | .save_state = ti_save_state, |
| 789 | .restore_state = ti_restore_state, |
| 790 | .sock_init = ti_init, |
| 791 | }, |
| 792 | [CARDBUS_TYPE_TI113X] = { |
| 793 | .override = ti113x_override, |
| 794 | .save_state = ti_save_state, |
| 795 | .restore_state = ti_restore_state, |
| 796 | .sock_init = ti_init, |
| 797 | }, |
| 798 | [CARDBUS_TYPE_TI12XX] = { |
| 799 | .override = ti12xx_override, |
| 800 | .save_state = ti_save_state, |
| 801 | .restore_state = ti_restore_state, |
| 802 | .sock_init = ti_init, |
| 803 | }, |
| 804 | [CARDBUS_TYPE_TI1250] = { |
| 805 | .override = ti1250_override, |
| 806 | .save_state = ti_save_state, |
| 807 | .restore_state = ti_restore_state, |
| 808 | .sock_init = ti_init, |
| 809 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 810 | #endif |
| 811 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | [CARDBUS_TYPE_RICOH] = { |
| 813 | .override = ricoh_override, |
| 814 | .save_state = ricoh_save_state, |
| 815 | .restore_state = ricoh_restore_state, |
| 816 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 817 | #endif |
| 818 | #ifdef CONFIG_YENTA_TOSHIBA |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 819 | [CARDBUS_TYPE_TOPIC95] = { |
| 820 | .override = topic95_override, |
| 821 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | [CARDBUS_TYPE_TOPIC97] = { |
| 823 | .override = topic97_override, |
| 824 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 825 | #endif |
| 826 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | [CARDBUS_TYPE_O2MICRO] = { |
| 828 | .override = o2micro_override, |
| 829 | .restore_state = o2micro_restore_state, |
| 830 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 831 | #endif |
| 832 | #ifdef CONFIG_YENTA_TI |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 833 | [CARDBUS_TYPE_ENE] = { |
| 834 | .override = ene_override, |
| 835 | .save_state = ti_save_state, |
| 836 | .restore_state = ti_restore_state, |
| 837 | .sock_init = ti_init, |
| 838 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 839 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | }; |
| 841 | |
| 842 | |
| 843 | /* |
| 844 | * Only probe "regular" interrupts, don't |
| 845 | * touch dangerous spots like the mouse irq, |
| 846 | * because there are mice that apparently |
| 847 | * get really confused if they get fondled |
| 848 | * too intimately. |
| 849 | * |
| 850 | * Default to 11, 10, 9, 7, 6, 5, 4, 3. |
| 851 | */ |
| 852 | static u32 isa_interrupts = 0x0ef8; |
| 853 | |
| 854 | static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mask) |
| 855 | { |
| 856 | int i; |
| 857 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | u32 mask; |
| 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | /* |
| 861 | * Probe for usable interrupts using the force |
| 862 | * register to generate bogus card status events. |
| 863 | */ |
| 864 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 865 | cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK); |
| 866 | exca_writeb(socket, I365_CSCINT, 0); |
| 867 | val = probe_irq_on() & isa_irq_mask; |
| 868 | for (i = 1; i < 16; i++) { |
| 869 | if (!((val >> i) & 1)) |
| 870 | continue; |
| 871 | exca_writeb(socket, I365_CSCINT, I365_CSC_STSCHG | (i << 4)); |
| 872 | cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS); |
| 873 | udelay(100); |
| 874 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 875 | } |
| 876 | cb_writel(socket, CB_SOCKET_MASK, 0); |
| 877 | exca_writeb(socket, I365_CSCINT, 0); |
| 878 | |
| 879 | mask = probe_irq_mask(val) & 0xffff; |
| 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | return mask; |
| 882 | } |
| 883 | |
| 884 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 885 | /** |
| 886 | * yenta PCI irq probing. |
| 887 | * currently only used in the TI/EnE initialization code |
| 888 | */ |
| 889 | #ifdef CONFIG_YENTA_TI |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | /* interrupt handler, only used during probing */ |
| 892 | static irqreturn_t yenta_probe_handler(int irq, void *dev_id, struct pt_regs *regs) |
| 893 | { |
| 894 | struct yenta_socket *socket = (struct yenta_socket *) dev_id; |
| 895 | u8 csc; |
| 896 | u32 cb_event; |
| 897 | |
| 898 | /* Clear interrupt status for the event */ |
| 899 | cb_event = cb_readl(socket, CB_SOCKET_EVENT); |
| 900 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 901 | csc = exca_readb(socket, I365_CSC); |
| 902 | |
| 903 | if (cb_event || csc) { |
| 904 | socket->probe_status = 1; |
| 905 | return IRQ_HANDLED; |
| 906 | } |
| 907 | |
| 908 | return IRQ_NONE; |
| 909 | } |
| 910 | |
| 911 | /* probes the PCI interrupt, use only on override functions */ |
| 912 | static int yenta_probe_cb_irq(struct yenta_socket *socket) |
| 913 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (!socket->cb_irq) |
| 915 | return -1; |
| 916 | |
| 917 | socket->probe_status = 0; |
| 918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | if (request_irq(socket->cb_irq, yenta_probe_handler, SA_SHIRQ, "yenta", socket)) { |
| 920 | printk(KERN_WARNING "Yenta: request_irq() in yenta_probe_cb_irq() failed!\n"); |
| 921 | return -1; |
| 922 | } |
| 923 | |
| 924 | /* generate interrupt, wait */ |
| 925 | exca_writeb(socket, I365_CSCINT, I365_CSC_STSCHG); |
| 926 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 927 | cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK); |
| 928 | cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS); |
Daniel Ritz | a413c09 | 2005-08-24 17:03:23 +0200 | [diff] [blame] | 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | msleep(100); |
| 931 | |
| 932 | /* disable interrupts */ |
| 933 | cb_writel(socket, CB_SOCKET_MASK, 0); |
| 934 | exca_writeb(socket, I365_CSCINT, 0); |
| 935 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 936 | exca_readb(socket, I365_CSC); |
| 937 | |
| 938 | free_irq(socket->cb_irq, socket); |
| 939 | |
| 940 | return (int) socket->probe_status; |
| 941 | } |
| 942 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 943 | #endif /* CONFIG_YENTA_TI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | |
| 946 | /* |
| 947 | * Set static data that doesn't need re-initializing.. |
| 948 | */ |
| 949 | static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_irq_mask) |
| 950 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | socket->socket.pci_irq = socket->cb_irq; |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 952 | if (isa_probe) |
| 953 | socket->socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask); |
| 954 | else |
| 955 | socket->socket.irq_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n", |
| 958 | socket->socket.irq_mask, socket->cb_irq); |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | * Initialize the standard cardbus registers |
| 963 | */ |
| 964 | static void yenta_config_init(struct yenta_socket *socket) |
| 965 | { |
| 966 | u16 bridge; |
| 967 | struct pci_dev *dev = socket->dev; |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 968 | struct pci_bus_region region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 970 | pcibios_resource_to_bus(socket->dev, ®ion, &dev->resource[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
| 972 | config_writel(socket, CB_LEGACY_MODE_BASE, 0); |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 973 | config_writel(socket, PCI_BASE_ADDRESS_0, region.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | config_writew(socket, PCI_COMMAND, |
| 975 | PCI_COMMAND_IO | |
| 976 | PCI_COMMAND_MEMORY | |
| 977 | PCI_COMMAND_MASTER | |
| 978 | PCI_COMMAND_WAIT); |
| 979 | |
| 980 | /* MAGIC NUMBERS! Fixme */ |
| 981 | config_writeb(socket, PCI_CACHE_LINE_SIZE, L1_CACHE_BYTES / 4); |
| 982 | config_writeb(socket, PCI_LATENCY_TIMER, 168); |
| 983 | config_writel(socket, PCI_PRIMARY_BUS, |
| 984 | (176 << 24) | /* sec. latency timer */ |
| 985 | (dev->subordinate->subordinate << 16) | /* subordinate bus */ |
| 986 | (dev->subordinate->secondary << 8) | /* secondary bus */ |
| 987 | dev->subordinate->primary); /* primary bus */ |
| 988 | |
| 989 | /* |
| 990 | * Set up the bridging state: |
| 991 | * - enable write posting. |
| 992 | * - memory window 0 prefetchable, window 1 non-prefetchable |
| 993 | * - PCI interrupts enabled if a PCI interrupt exists.. |
| 994 | */ |
| 995 | bridge = config_readw(socket, CB_BRIDGE_CONTROL); |
Daniel Ritz | a413c09 | 2005-08-24 17:03:23 +0200 | [diff] [blame] | 996 | bridge &= ~(CB_BRIDGE_CRST | CB_BRIDGE_PREFETCH1 | CB_BRIDGE_ISAEN | CB_BRIDGE_VGAEN); |
| 997 | bridge |= CB_BRIDGE_PREFETCH0 | CB_BRIDGE_POSTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | config_writew(socket, CB_BRIDGE_CONTROL, bridge); |
| 999 | } |
| 1000 | |
| 1001 | /* |
| 1002 | * Initialize a cardbus controller. Make sure we have a usable |
| 1003 | * interrupt, and that we can map the cardbus area. Fill in the |
| 1004 | * socket information structure.. |
| 1005 | */ |
| 1006 | static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_id *id) |
| 1007 | { |
| 1008 | struct yenta_socket *socket; |
| 1009 | int ret; |
Ivan Kokshaysky | c7fb0b3 | 2005-09-14 23:05:30 +0400 | [diff] [blame] | 1010 | |
| 1011 | /* |
| 1012 | * If we failed to assign proper bus numbers for this cardbus |
| 1013 | * controller during PCI probe, its subordinate pci_bus is NULL. |
| 1014 | * Bail out if so. |
| 1015 | */ |
| 1016 | if (!dev->subordinate) { |
Linus Torvalds | 5a23f34 | 2005-09-14 13:05:17 -0700 | [diff] [blame] | 1017 | printk(KERN_ERR "Yenta: no bus associated with %s! " |
| 1018 | "(try 'pci=assign-busses')\n", pci_name(dev)); |
Ivan Kokshaysky | c7fb0b3 | 2005-09-14 23:05:30 +0400 | [diff] [blame] | 1019 | return -ENODEV; |
| 1020 | } |
| 1021 | |
Dominik Brodowski | 8084b37 | 2005-12-11 21:18:26 +0100 | [diff] [blame^] | 1022 | socket = kzalloc(sizeof(struct yenta_socket), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (!socket) |
| 1024 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | /* prepare pcmcia_socket */ |
| 1027 | socket->socket.ops = ¥ta_socket_operations; |
| 1028 | socket->socket.resource_ops = &pccard_nonstatic_ops; |
| 1029 | socket->socket.dev.dev = &dev->dev; |
| 1030 | socket->socket.driver_data = socket; |
| 1031 | socket->socket.owner = THIS_MODULE; |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 1032 | socket->socket.features = SS_CAP_PAGE_REGS | SS_CAP_PCCARD; |
| 1033 | socket->socket.map_size = 0x1000; |
| 1034 | socket->socket.cb_dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | /* prepare struct yenta_socket */ |
| 1037 | socket->dev = dev; |
| 1038 | pci_set_drvdata(dev, socket); |
| 1039 | |
| 1040 | /* |
| 1041 | * Do some basic sanity checking.. |
| 1042 | */ |
| 1043 | if (pci_enable_device(dev)) { |
| 1044 | ret = -EBUSY; |
| 1045 | goto free; |
| 1046 | } |
| 1047 | |
| 1048 | ret = pci_request_regions(dev, "yenta_socket"); |
| 1049 | if (ret) |
| 1050 | goto disable; |
| 1051 | |
| 1052 | if (!pci_resource_start(dev, 0)) { |
| 1053 | printk(KERN_ERR "No cardbus resource!\n"); |
| 1054 | ret = -ENODEV; |
| 1055 | goto release; |
| 1056 | } |
| 1057 | |
| 1058 | /* |
| 1059 | * Ok, start setup.. Map the cardbus registers, |
| 1060 | * and request the IRQ. |
| 1061 | */ |
| 1062 | socket->base = ioremap(pci_resource_start(dev, 0), 0x1000); |
| 1063 | if (!socket->base) { |
| 1064 | ret = -ENOMEM; |
| 1065 | goto release; |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * report the subsystem vendor and device for help debugging |
| 1070 | * the irq stuff... |
| 1071 | */ |
| 1072 | printk(KERN_INFO "Yenta: CardBus bridge found at %s [%04x:%04x]\n", |
| 1073 | pci_name(dev), dev->subsystem_vendor, dev->subsystem_device); |
| 1074 | |
| 1075 | yenta_config_init(socket); |
| 1076 | |
| 1077 | /* Disable all events */ |
| 1078 | cb_writel(socket, CB_SOCKET_MASK, 0x0); |
| 1079 | |
| 1080 | /* Set up the bridge regions.. */ |
| 1081 | yenta_allocate_resources(socket); |
| 1082 | |
| 1083 | socket->cb_irq = dev->irq; |
| 1084 | |
| 1085 | /* Do we have special options for the device? */ |
| 1086 | if (id->driver_data != CARDBUS_TYPE_DEFAULT && |
| 1087 | id->driver_data < ARRAY_SIZE(cardbus_type)) { |
| 1088 | socket->type = &cardbus_type[id->driver_data]; |
| 1089 | |
| 1090 | ret = socket->type->override(socket); |
| 1091 | if (ret < 0) |
| 1092 | goto unmap; |
| 1093 | } |
| 1094 | |
| 1095 | /* We must finish initialization here */ |
| 1096 | |
| 1097 | if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, SA_SHIRQ, "yenta", socket)) { |
| 1098 | /* No IRQ or request_irq failed. Poll */ |
| 1099 | socket->cb_irq = 0; /* But zero is a valid IRQ number. */ |
| 1100 | init_timer(&socket->poll_timer); |
| 1101 | socket->poll_timer.function = yenta_interrupt_wrapper; |
| 1102 | socket->poll_timer.data = (unsigned long)socket; |
| 1103 | socket->poll_timer.expires = jiffies + HZ; |
| 1104 | add_timer(&socket->poll_timer); |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 1105 | printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n" |
| 1106 | KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n"); |
| 1107 | } else { |
| 1108 | socket->socket.features |= SS_CAP_CARDBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /* Figure out what the dang thing can do for the PCMCIA layer... */ |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 1112 | yenta_interrogate(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | yenta_get_socket_capabilities(socket, isa_interrupts); |
| 1114 | printk(KERN_INFO "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE)); |
| 1115 | |
| 1116 | /* Register it with the pcmcia layer.. */ |
| 1117 | ret = pcmcia_register_socket(&socket->socket); |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 1118 | if (ret == 0) { |
| 1119 | /* Add the yenta register attributes */ |
| 1120 | device_create_file(&dev->dev, &dev_attr_yenta_registers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | goto out; |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 1122 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
| 1124 | unmap: |
| 1125 | iounmap(socket->base); |
| 1126 | release: |
| 1127 | pci_release_regions(dev); |
| 1128 | disable: |
| 1129 | pci_disable_device(dev); |
| 1130 | free: |
| 1131 | kfree(socket); |
| 1132 | out: |
| 1133 | return ret; |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state) |
| 1138 | { |
| 1139 | struct yenta_socket *socket = pci_get_drvdata(dev); |
| 1140 | int ret; |
| 1141 | |
| 1142 | ret = pcmcia_socket_dev_suspend(&dev->dev, state); |
| 1143 | |
| 1144 | if (socket) { |
| 1145 | if (socket->type && socket->type->save_state) |
| 1146 | socket->type->save_state(socket); |
| 1147 | |
| 1148 | /* FIXME: pci_save_state needs to have a better interface */ |
| 1149 | pci_save_state(dev); |
| 1150 | pci_read_config_dword(dev, 16*4, &socket->saved_state[0]); |
| 1151 | pci_read_config_dword(dev, 17*4, &socket->saved_state[1]); |
David Shaohua Li | d58da59 | 2005-03-18 16:43:54 -0500 | [diff] [blame] | 1152 | pci_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
| 1154 | /* |
| 1155 | * Some laptops (IBM T22) do not like us putting the Cardbus |
| 1156 | * bridge into D3. At a guess, some other laptop will |
| 1157 | * probably require this, so leave it commented out for now. |
| 1158 | */ |
| 1159 | /* pci_set_power_state(dev, 3); */ |
| 1160 | } |
| 1161 | |
| 1162 | return ret; |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | static int yenta_dev_resume (struct pci_dev *dev) |
| 1167 | { |
| 1168 | struct yenta_socket *socket = pci_get_drvdata(dev); |
| 1169 | |
| 1170 | if (socket) { |
| 1171 | pci_set_power_state(dev, 0); |
| 1172 | /* FIXME: pci_restore_state needs to have a better interface */ |
| 1173 | pci_restore_state(dev); |
| 1174 | pci_write_config_dword(dev, 16*4, socket->saved_state[0]); |
| 1175 | pci_write_config_dword(dev, 17*4, socket->saved_state[1]); |
David Shaohua Li | d58da59 | 2005-03-18 16:43:54 -0500 | [diff] [blame] | 1176 | pci_enable_device(dev); |
| 1177 | pci_set_master(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | if (socket->type && socket->type->restore_state) |
| 1180 | socket->type->restore_state(socket); |
| 1181 | } |
| 1182 | |
| 1183 | return pcmcia_socket_dev_resume(&dev->dev); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | #define CB_ID(vend,dev,type) \ |
| 1188 | { \ |
| 1189 | .vendor = vend, \ |
| 1190 | .device = dev, \ |
| 1191 | .subvendor = PCI_ANY_ID, \ |
| 1192 | .subdevice = PCI_ANY_ID, \ |
| 1193 | .class = PCI_CLASS_BRIDGE_CARDBUS << 8, \ |
| 1194 | .class_mask = ~0, \ |
| 1195 | .driver_data = CARDBUS_TYPE_##type, \ |
| 1196 | } |
| 1197 | |
| 1198 | static struct pci_device_id yenta_table [] = { |
| 1199 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1031, TI), |
| 1200 | |
| 1201 | /* |
| 1202 | * TBD: Check if these TI variants can use more |
| 1203 | * advanced overrides instead. (I can't get the |
| 1204 | * data sheets for these devices. --rmk) |
| 1205 | */ |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1206 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1210, TI), |
| 1208 | |
| 1209 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1130, TI113X), |
| 1210 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1131, TI113X), |
| 1211 | |
| 1212 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1211, TI12XX), |
| 1213 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1220, TI12XX), |
| 1214 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1221, TI12XX), |
| 1215 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1225, TI12XX), |
| 1216 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251A, TI12XX), |
| 1217 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251B, TI12XX), |
| 1218 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420, TI12XX), |
| 1219 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1450, TI12XX), |
| 1220 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1451A, TI12XX), |
| 1221 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510, TI12XX), |
| 1222 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1520, TI12XX), |
| 1223 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1620, TI12XX), |
| 1224 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4410, TI12XX), |
| 1225 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4450, TI12XX), |
| 1226 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4451, TI12XX), |
| 1227 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4510, TI12XX), |
| 1228 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4520, TI12XX), |
| 1229 | |
| 1230 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1250, TI1250), |
| 1231 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1410, TI1250), |
| 1232 | |
Daniel Ritz | 6c1a10d | 2005-09-20 14:12:17 -0700 | [diff] [blame] | 1233 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX21_XX11, TI12XX), |
| 1234 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X515, TI12XX), |
| 1235 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X420, TI12XX), |
| 1236 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X620, TI12XX), |
| 1237 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7410, TI12XX), |
| 1238 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7510, TI12XX), |
| 1239 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7610, TI12XX), |
| 1240 | |
Daniel Ritz | f9cb8b7 | 2005-09-24 23:12:46 -0700 | [diff] [blame] | 1241 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_710, TI12XX), |
| 1242 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_712, TI12XX), |
| 1243 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_720, TI12XX), |
| 1244 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_722, TI12XX), |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 1245 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1211, ENE), |
| 1246 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE), |
| 1247 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE), |
| 1248 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1420, ENE), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1249 | #endif /* CONFIG_YENTA_TI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1251 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C465, RICOH), |
| 1253 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C466, RICOH), |
| 1254 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C475, RICOH), |
| 1255 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH), |
| 1256 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1257 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1259 | #ifdef CONFIG_YENTA_TOSHIBA |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 1260 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC95, TOPIC95), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97), |
| 1262 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1263 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1265 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | CB_ID(PCI_VENDOR_ID_O2, PCI_ANY_ID, O2MICRO), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1267 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | /* match any cardbus bridge */ |
| 1270 | CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT), |
| 1271 | { /* all zeroes */ } |
| 1272 | }; |
| 1273 | MODULE_DEVICE_TABLE(pci, yenta_table); |
| 1274 | |
| 1275 | |
| 1276 | static struct pci_driver yenta_cardbus_driver = { |
| 1277 | .name = "yenta_cardbus", |
| 1278 | .id_table = yenta_table, |
| 1279 | .probe = yenta_probe, |
| 1280 | .remove = __devexit_p(yenta_close), |
| 1281 | .suspend = yenta_dev_suspend, |
| 1282 | .resume = yenta_dev_resume, |
| 1283 | }; |
| 1284 | |
| 1285 | |
| 1286 | static int __init yenta_socket_init(void) |
| 1287 | { |
| 1288 | return pci_register_driver (¥ta_cardbus_driver); |
| 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | static void __exit yenta_socket_exit (void) |
| 1293 | { |
| 1294 | pci_unregister_driver (¥ta_cardbus_driver); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | module_init(yenta_socket_init); |
| 1299 | module_exit(yenta_socket_exit); |
| 1300 | |
| 1301 | MODULE_LICENSE("GPL"); |