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 | |
Daniel Ritz | d250a48 | 2006-03-06 17:37:04 +0100 | [diff] [blame] | 290 | /* if powering down: do it immediately */ |
| 291 | if (state->Vcc == 0) |
| 292 | yenta_set_power(socket, state); |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | socket->io_irq = state->io_irq; |
| 295 | bridge = config_readw(socket, CB_BRIDGE_CONTROL) & ~(CB_BRIDGE_CRST | CB_BRIDGE_INTR); |
| 296 | if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) { |
| 297 | u8 intr; |
| 298 | bridge |= (state->flags & SS_RESET) ? CB_BRIDGE_CRST : 0; |
| 299 | |
| 300 | /* ISA interrupt control? */ |
| 301 | intr = exca_readb(socket, I365_INTCTL); |
| 302 | intr = (intr & ~0xf); |
| 303 | if (!socket->cb_irq) { |
| 304 | intr |= state->io_irq; |
| 305 | bridge |= CB_BRIDGE_INTR; |
| 306 | } |
| 307 | exca_writeb(socket, I365_INTCTL, intr); |
| 308 | } else { |
| 309 | u8 reg; |
| 310 | |
| 311 | reg = exca_readb(socket, I365_INTCTL) & (I365_RING_ENA | I365_INTR_ENA); |
| 312 | reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET; |
| 313 | reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0; |
| 314 | if (state->io_irq != socket->cb_irq) { |
| 315 | reg |= state->io_irq; |
| 316 | bridge |= CB_BRIDGE_INTR; |
| 317 | } |
| 318 | exca_writeb(socket, I365_INTCTL, reg); |
| 319 | |
| 320 | reg = exca_readb(socket, I365_POWER) & (I365_VCC_MASK|I365_VPP1_MASK); |
| 321 | reg |= I365_PWR_NORESET; |
| 322 | if (state->flags & SS_PWR_AUTO) reg |= I365_PWR_AUTO; |
| 323 | if (state->flags & SS_OUTPUT_ENA) reg |= I365_PWR_OUT; |
| 324 | if (exca_readb(socket, I365_POWER) != reg) |
| 325 | exca_writeb(socket, I365_POWER, reg); |
| 326 | |
| 327 | /* CSC interrupt: no ISA irq for CSC */ |
| 328 | reg = I365_CSC_DETECT; |
| 329 | if (state->flags & SS_IOCARD) { |
| 330 | if (state->csc_mask & SS_STSCHG) reg |= I365_CSC_STSCHG; |
| 331 | } else { |
| 332 | if (state->csc_mask & SS_BATDEAD) reg |= I365_CSC_BVD1; |
| 333 | if (state->csc_mask & SS_BATWARN) reg |= I365_CSC_BVD2; |
| 334 | if (state->csc_mask & SS_READY) reg |= I365_CSC_READY; |
| 335 | } |
| 336 | exca_writeb(socket, I365_CSCINT, reg); |
| 337 | exca_readb(socket, I365_CSC); |
| 338 | if(sock->zoom_video) |
| 339 | sock->zoom_video(sock, state->flags & SS_ZVCARD); |
| 340 | } |
| 341 | config_writew(socket, CB_BRIDGE_CONTROL, bridge); |
| 342 | /* Socket event mask: get card insert/remove events.. */ |
| 343 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 344 | cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK); |
Daniel Ritz | d250a48 | 2006-03-06 17:37:04 +0100 | [diff] [blame] | 345 | |
| 346 | /* if powering up: do it as the last step when the socket is configured */ |
| 347 | if (state->Vcc != 0) |
| 348 | yenta_set_power(socket, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int yenta_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io) |
| 353 | { |
| 354 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 355 | int map; |
| 356 | unsigned char ioctl, addr, enable; |
| 357 | |
| 358 | map = io->map; |
| 359 | |
| 360 | if (map > 1) |
| 361 | return -EINVAL; |
| 362 | |
| 363 | enable = I365_ENA_IO(map); |
| 364 | addr = exca_readb(socket, I365_ADDRWIN); |
| 365 | |
| 366 | /* Disable the window before changing it.. */ |
| 367 | if (addr & enable) { |
| 368 | addr &= ~enable; |
| 369 | exca_writeb(socket, I365_ADDRWIN, addr); |
| 370 | } |
| 371 | |
| 372 | exca_writew(socket, I365_IO(map)+I365_W_START, io->start); |
| 373 | exca_writew(socket, I365_IO(map)+I365_W_STOP, io->stop); |
| 374 | |
| 375 | ioctl = exca_readb(socket, I365_IOCTL) & ~I365_IOCTL_MASK(map); |
| 376 | if (io->flags & MAP_0WS) ioctl |= I365_IOCTL_0WS(map); |
| 377 | if (io->flags & MAP_16BIT) ioctl |= I365_IOCTL_16BIT(map); |
| 378 | if (io->flags & MAP_AUTOSZ) ioctl |= I365_IOCTL_IOCS16(map); |
| 379 | exca_writeb(socket, I365_IOCTL, ioctl); |
| 380 | |
| 381 | if (io->flags & MAP_ACTIVE) |
| 382 | exca_writeb(socket, I365_ADDRWIN, addr | enable); |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int yenta_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem) |
| 387 | { |
| 388 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 389 | struct pci_bus_region region; |
| 390 | int map; |
| 391 | unsigned char addr, enable; |
| 392 | unsigned int start, stop, card_start; |
| 393 | unsigned short word; |
| 394 | |
| 395 | pcibios_resource_to_bus(socket->dev, ®ion, mem->res); |
| 396 | |
| 397 | map = mem->map; |
| 398 | start = region.start; |
| 399 | stop = region.end; |
| 400 | card_start = mem->card_start; |
| 401 | |
| 402 | if (map > 4 || start > stop || ((start ^ stop) >> 24) || |
| 403 | (card_start >> 26) || mem->speed > 1000) |
| 404 | return -EINVAL; |
| 405 | |
| 406 | enable = I365_ENA_MEM(map); |
| 407 | addr = exca_readb(socket, I365_ADDRWIN); |
| 408 | if (addr & enable) { |
| 409 | addr &= ~enable; |
| 410 | exca_writeb(socket, I365_ADDRWIN, addr); |
| 411 | } |
| 412 | |
| 413 | exca_writeb(socket, CB_MEM_PAGE(map), start >> 24); |
| 414 | |
| 415 | word = (start >> 12) & 0x0fff; |
| 416 | if (mem->flags & MAP_16BIT) |
| 417 | word |= I365_MEM_16BIT; |
| 418 | if (mem->flags & MAP_0WS) |
| 419 | word |= I365_MEM_0WS; |
| 420 | exca_writew(socket, I365_MEM(map) + I365_W_START, word); |
| 421 | |
| 422 | word = (stop >> 12) & 0x0fff; |
| 423 | switch (to_cycles(mem->speed)) { |
| 424 | case 0: break; |
| 425 | case 1: word |= I365_MEM_WS0; break; |
| 426 | case 2: word |= I365_MEM_WS1; break; |
| 427 | default: word |= I365_MEM_WS1 | I365_MEM_WS0; break; |
| 428 | } |
| 429 | exca_writew(socket, I365_MEM(map) + I365_W_STOP, word); |
| 430 | |
| 431 | word = ((card_start - start) >> 12) & 0x3fff; |
| 432 | if (mem->flags & MAP_WRPROT) |
| 433 | word |= I365_MEM_WRPROT; |
| 434 | if (mem->flags & MAP_ATTRIB) |
| 435 | word |= I365_MEM_REG; |
| 436 | exca_writew(socket, I365_MEM(map) + I365_W_OFF, word); |
| 437 | |
| 438 | if (mem->flags & MAP_ACTIVE) |
| 439 | exca_writeb(socket, I365_ADDRWIN, addr | enable); |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 444 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 445 | static irqreturn_t yenta_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 447 | unsigned int events; |
| 448 | struct yenta_socket *socket = (struct yenta_socket *) dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | u8 csc; |
| 450 | u32 cb_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | /* Clear interrupt status for the event */ |
| 453 | cb_event = cb_readl(socket, CB_SOCKET_EVENT); |
| 454 | cb_writel(socket, CB_SOCKET_EVENT, cb_event); |
| 455 | |
| 456 | csc = exca_readb(socket, I365_CSC); |
| 457 | |
Daniel Ritz | e411580 | 2005-09-20 14:17:37 -0700 | [diff] [blame] | 458 | if (!(cb_event || csc)) |
| 459 | return IRQ_NONE; |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | events = (cb_event & (CB_CD1EVENT | CB_CD2EVENT)) ? SS_DETECT : 0 ; |
| 462 | events |= (csc & I365_CSC_DETECT) ? SS_DETECT : 0; |
| 463 | if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) { |
| 464 | events |= (csc & I365_CSC_STSCHG) ? SS_STSCHG : 0; |
| 465 | } else { |
| 466 | events |= (csc & I365_CSC_BVD1) ? SS_BATDEAD : 0; |
| 467 | events |= (csc & I365_CSC_BVD2) ? SS_BATWARN : 0; |
| 468 | events |= (csc & I365_CSC_READY) ? SS_READY : 0; |
| 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 471 | if (events) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | pcmcia_parse_events(&socket->socket, events); |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 473 | |
Daniel Ritz | e411580 | 2005-09-20 14:17:37 -0700 | [diff] [blame] | 474 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void yenta_interrupt_wrapper(unsigned long data) |
| 478 | { |
| 479 | struct yenta_socket *socket = (struct yenta_socket *) data; |
| 480 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 481 | yenta_interrupt(0, (void *)socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | socket->poll_timer.expires = jiffies + HZ; |
| 483 | add_timer(&socket->poll_timer); |
| 484 | } |
| 485 | |
| 486 | static void yenta_clear_maps(struct yenta_socket *socket) |
| 487 | { |
| 488 | int i; |
| 489 | struct resource res = { .start = 0, .end = 0x0fff }; |
| 490 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
| 491 | pccard_mem_map mem = { .res = &res, }; |
| 492 | |
| 493 | yenta_set_socket(&socket->socket, &dead_socket); |
| 494 | for (i = 0; i < 2; i++) { |
| 495 | io.map = i; |
| 496 | yenta_set_io_map(&socket->socket, &io); |
| 497 | } |
| 498 | for (i = 0; i < 5; i++) { |
| 499 | mem.map = i; |
| 500 | yenta_set_mem_map(&socket->socket, &mem); |
| 501 | } |
| 502 | } |
| 503 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 504 | /* redoes voltage interrogation if required */ |
| 505 | static void yenta_interrogate(struct yenta_socket *socket) |
| 506 | { |
| 507 | u32 state; |
| 508 | |
| 509 | state = cb_readl(socket, CB_SOCKET_STATE); |
| 510 | if (!(state & (CB_5VCARD | CB_3VCARD | CB_XVCARD | CB_YVCARD)) || |
| 511 | (state & (CB_CDETECT1 | CB_CDETECT2 | CB_NOTACARD | CB_BADVCCREQ)) || |
| 512 | ((state & (CB_16BITCARD | CB_CBCARD)) == (CB_16BITCARD | CB_CBCARD))) |
| 513 | cb_writel(socket, CB_SOCKET_FORCE, CB_CVSTEST); |
| 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | /* Called at resume and initialization events */ |
| 517 | static int yenta_sock_init(struct pcmcia_socket *sock) |
| 518 | { |
| 519 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | exca_writeb(socket, I365_GBLCTL, 0x00); |
| 522 | exca_writeb(socket, I365_GENCTL, 0x00); |
| 523 | |
| 524 | /* Redo card voltage interrogation */ |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 525 | yenta_interrogate(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | yenta_clear_maps(socket); |
| 528 | |
| 529 | if (socket->type && socket->type->sock_init) |
| 530 | socket->type->sock_init(socket); |
| 531 | |
| 532 | /* Re-enable CSC interrupts */ |
| 533 | cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK); |
| 534 | |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int yenta_sock_suspend(struct pcmcia_socket *sock) |
| 539 | { |
| 540 | struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); |
| 541 | |
| 542 | /* Disable CSC interrupts */ |
| 543 | cb_writel(socket, CB_SOCKET_MASK, 0x0); |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Use an adaptive allocation for the memory resource, |
| 550 | * sometimes the memory behind pci bridges is limited: |
| 551 | * 1/8 of the size of the io window of the parent. |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 552 | * max 4 MB, min 16 kB. We try very hard to not get below |
| 553 | * the "ACC" values, though. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | */ |
| 555 | #define BRIDGE_MEM_MAX 4*1024*1024 |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 556 | #define BRIDGE_MEM_ACC 128*1024 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | #define BRIDGE_MEM_MIN 16*1024 |
| 558 | |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 559 | #define BRIDGE_IO_MAX 512 |
| 560 | #define BRIDGE_IO_ACC 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | #define BRIDGE_IO_MIN 32 |
| 562 | |
| 563 | #ifndef PCIBIOS_MIN_CARDBUS_IO |
| 564 | #define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO |
| 565 | #endif |
| 566 | |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 567 | static int yenta_search_one_res(struct resource *root, struct resource *res, |
| 568 | u32 min) |
| 569 | { |
| 570 | u32 align, size, start, end; |
| 571 | |
| 572 | if (res->flags & IORESOURCE_IO) { |
| 573 | align = 1024; |
| 574 | size = BRIDGE_IO_MAX; |
| 575 | start = PCIBIOS_MIN_CARDBUS_IO; |
| 576 | end = ~0U; |
| 577 | } else { |
| 578 | unsigned long avail = root->end - root->start; |
| 579 | int i; |
| 580 | size = BRIDGE_MEM_MAX; |
| 581 | if (size > avail/8) { |
| 582 | size=(avail+1)/8; |
| 583 | /* round size down to next power of 2 */ |
| 584 | i = 0; |
| 585 | while ((size /= 2) != 0) |
| 586 | i++; |
| 587 | size = 1 << i; |
| 588 | } |
| 589 | if (size < min) |
| 590 | size = min; |
| 591 | align = size; |
| 592 | start = PCIBIOS_MIN_MEM; |
| 593 | end = ~0U; |
| 594 | } |
| 595 | |
| 596 | do { |
| 597 | if (allocate_resource(root, res, size, start, end, align, |
| 598 | NULL, NULL)==0) { |
| 599 | return 1; |
| 600 | } |
| 601 | size = size/2; |
| 602 | align = size; |
| 603 | } while (size >= min); |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, |
| 610 | u32 min) |
| 611 | { |
| 612 | int i; |
| 613 | for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) { |
| 614 | struct resource * root = socket->dev->bus->resource[i]; |
| 615 | if (!root) |
| 616 | continue; |
| 617 | |
| 618 | if ((res->flags ^ root->flags) & |
| 619 | (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH)) |
| 620 | continue; /* Wrong type */ |
| 621 | |
| 622 | if (yenta_search_one_res(root, res, min)) |
| 623 | return 1; |
| 624 | } |
| 625 | return 0; |
| 626 | } |
| 627 | |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 628 | 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] | 629 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | struct resource *root, *res; |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 631 | struct pci_bus_region region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | unsigned mask; |
| 633 | |
Ivan Kokshaysky | 7925407 | 2005-06-27 16:28:02 -0700 | [diff] [blame] | 634 | res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; |
| 635 | /* Already allocated? */ |
| 636 | if (res->parent) |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 637 | return 0; |
Ivan Kokshaysky | 7925407 | 2005-06-27 16:28:02 -0700 | [diff] [blame] | 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */ |
| 640 | mask = ~0xfff; |
| 641 | if (type & IORESOURCE_IO) |
| 642 | mask = ~3; |
| 643 | |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 644 | res->name = socket->dev->subordinate->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | res->flags = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 647 | region.start = config_readl(socket, addr_start) & mask; |
| 648 | region.end = config_readl(socket, addr_end) | ~mask; |
| 649 | if (region.start && region.end > region.start && !override_bios) { |
| 650 | pcibios_bus_to_resource(socket->dev, res, ®ion); |
Dominik Brodowski | 862104e | 2005-07-12 13:58:15 -0700 | [diff] [blame] | 651 | root = pci_find_parent_resource(socket->dev, res); |
| 652 | if (root && (request_resource(root, res) == 0)) |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 653 | return 0; |
Dominik Brodowski | 862104e | 2005-07-12 13:58:15 -0700 | [diff] [blame] | 654 | 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] | 655 | pci_name(socket->dev), nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (type & IORESOURCE_IO) { |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 659 | if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) || |
| 660 | (yenta_search_res(socket, res, BRIDGE_IO_ACC)) || |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 661 | (yenta_search_res(socket, res, BRIDGE_IO_MIN))) |
| 662 | return 1; |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 663 | } else { |
| 664 | if (type & IORESOURCE_PREFETCH) { |
| 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 | /* Approximating prefetchable by non-prefetchable */ |
| 670 | res->flags = IORESOURCE_MEM; |
| 671 | } |
| 672 | if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) || |
| 673 | (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) || |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 674 | (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) |
| 675 | return 1; |
Dominik Brodowski | eb0a90b | 2005-07-12 13:58:17 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | 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] | 679 | pci_name(socket->dev), type); |
| 680 | res->start = res->end = res->flags = 0; |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /* |
| 685 | * Allocate the bridge mappings for the device.. |
| 686 | */ |
| 687 | static void yenta_allocate_resources(struct yenta_socket *socket) |
| 688 | { |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 689 | int program = 0; |
| 690 | program += yenta_allocate_res(socket, 0, IORESOURCE_IO, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 691 | PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 692 | program += yenta_allocate_res(socket, 1, IORESOURCE_IO, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 693 | PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 694 | program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 695 | PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 696 | program += yenta_allocate_res(socket, 3, IORESOURCE_MEM, |
Dominik Brodowski | 2787983 | 2005-07-12 13:58:16 -0700 | [diff] [blame] | 697 | PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 698 | if (program) |
| 699 | pci_setup_cardbus(socket->dev->subordinate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | /* |
| 704 | * Free the bridge mappings for the device.. |
| 705 | */ |
| 706 | static void yenta_free_resources(struct yenta_socket *socket) |
| 707 | { |
| 708 | int i; |
| 709 | for (i=0;i<4;i++) { |
| 710 | struct resource *res; |
| 711 | res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i; |
| 712 | if (res->start != 0 && res->end != 0) |
| 713 | release_resource(res); |
Dominik Brodowski | b3743fa | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 714 | res->start = res->end = res->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
| 718 | |
| 719 | /* |
| 720 | * Close it down - release our resources and go home.. |
| 721 | */ |
| 722 | static void yenta_close(struct pci_dev *dev) |
| 723 | { |
| 724 | struct yenta_socket *sock = pci_get_drvdata(dev); |
| 725 | |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 726 | /* Remove the register attributes */ |
| 727 | device_remove_file(&dev->dev, &dev_attr_yenta_registers); |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | /* we don't want a dying socket registered */ |
| 730 | pcmcia_unregister_socket(&sock->socket); |
| 731 | |
| 732 | /* Disable all events so we don't die in an IRQ storm */ |
| 733 | cb_writel(sock, CB_SOCKET_MASK, 0x0); |
| 734 | exca_writeb(sock, I365_CSCINT, 0); |
| 735 | |
| 736 | if (sock->cb_irq) |
| 737 | free_irq(sock->cb_irq, sock); |
| 738 | else |
| 739 | del_timer_sync(&sock->poll_timer); |
| 740 | |
| 741 | if (sock->base) |
| 742 | iounmap(sock->base); |
| 743 | yenta_free_resources(sock); |
| 744 | |
| 745 | pci_release_regions(dev); |
| 746 | pci_disable_device(dev); |
| 747 | pci_set_drvdata(dev, NULL); |
| 748 | } |
| 749 | |
| 750 | |
| 751 | static struct pccard_operations yenta_socket_operations = { |
| 752 | .init = yenta_sock_init, |
| 753 | .suspend = yenta_sock_suspend, |
| 754 | .get_status = yenta_get_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | .set_socket = yenta_set_socket, |
| 756 | .set_io_map = yenta_set_io_map, |
| 757 | .set_mem_map = yenta_set_mem_map, |
| 758 | }; |
| 759 | |
| 760 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 761 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | #include "ti113x.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 763 | #endif |
| 764 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | #include "ricoh.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 766 | #endif |
| 767 | #ifdef CONFIG_YENTA_TOSHIBA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | #include "topic.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 769 | #endif |
| 770 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | #include "o2micro.h" |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 772 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | enum { |
| 775 | CARDBUS_TYPE_DEFAULT = -1, |
| 776 | CARDBUS_TYPE_TI, |
| 777 | CARDBUS_TYPE_TI113X, |
| 778 | CARDBUS_TYPE_TI12XX, |
| 779 | CARDBUS_TYPE_TI1250, |
| 780 | CARDBUS_TYPE_RICOH, |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 781 | CARDBUS_TYPE_TOPIC95, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | CARDBUS_TYPE_TOPIC97, |
| 783 | CARDBUS_TYPE_O2MICRO, |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 784 | CARDBUS_TYPE_ENE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | }; |
| 786 | |
| 787 | /* |
| 788 | * Different cardbus controllers have slightly different |
| 789 | * initialization sequences etc details. List them here.. |
| 790 | */ |
| 791 | static struct cardbus_type cardbus_type[] = { |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 792 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | [CARDBUS_TYPE_TI] = { |
| 794 | .override = ti_override, |
| 795 | .save_state = ti_save_state, |
| 796 | .restore_state = ti_restore_state, |
| 797 | .sock_init = ti_init, |
| 798 | }, |
| 799 | [CARDBUS_TYPE_TI113X] = { |
| 800 | .override = ti113x_override, |
| 801 | .save_state = ti_save_state, |
| 802 | .restore_state = ti_restore_state, |
| 803 | .sock_init = ti_init, |
| 804 | }, |
| 805 | [CARDBUS_TYPE_TI12XX] = { |
| 806 | .override = ti12xx_override, |
| 807 | .save_state = ti_save_state, |
| 808 | .restore_state = ti_restore_state, |
| 809 | .sock_init = ti_init, |
| 810 | }, |
| 811 | [CARDBUS_TYPE_TI1250] = { |
| 812 | .override = ti1250_override, |
| 813 | .save_state = ti_save_state, |
| 814 | .restore_state = ti_restore_state, |
| 815 | .sock_init = ti_init, |
| 816 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 817 | #endif |
| 818 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | [CARDBUS_TYPE_RICOH] = { |
| 820 | .override = ricoh_override, |
| 821 | .save_state = ricoh_save_state, |
| 822 | .restore_state = ricoh_restore_state, |
| 823 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 824 | #endif |
| 825 | #ifdef CONFIG_YENTA_TOSHIBA |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 826 | [CARDBUS_TYPE_TOPIC95] = { |
| 827 | .override = topic95_override, |
| 828 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | [CARDBUS_TYPE_TOPIC97] = { |
| 830 | .override = topic97_override, |
| 831 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 832 | #endif |
| 833 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | [CARDBUS_TYPE_O2MICRO] = { |
| 835 | .override = o2micro_override, |
| 836 | .restore_state = o2micro_restore_state, |
| 837 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 838 | #endif |
| 839 | #ifdef CONFIG_YENTA_TI |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 840 | [CARDBUS_TYPE_ENE] = { |
| 841 | .override = ene_override, |
| 842 | .save_state = ti_save_state, |
| 843 | .restore_state = ti_restore_state, |
| 844 | .sock_init = ti_init, |
| 845 | }, |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 846 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | }; |
| 848 | |
| 849 | |
| 850 | /* |
| 851 | * Only probe "regular" interrupts, don't |
| 852 | * touch dangerous spots like the mouse irq, |
| 853 | * because there are mice that apparently |
| 854 | * get really confused if they get fondled |
| 855 | * too intimately. |
| 856 | * |
| 857 | * Default to 11, 10, 9, 7, 6, 5, 4, 3. |
| 858 | */ |
| 859 | static u32 isa_interrupts = 0x0ef8; |
| 860 | |
| 861 | static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mask) |
| 862 | { |
| 863 | int i; |
| 864 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | u32 mask; |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* |
| 868 | * Probe for usable interrupts using the force |
| 869 | * register to generate bogus card status events. |
| 870 | */ |
| 871 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 872 | cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK); |
| 873 | exca_writeb(socket, I365_CSCINT, 0); |
| 874 | val = probe_irq_on() & isa_irq_mask; |
| 875 | for (i = 1; i < 16; i++) { |
| 876 | if (!((val >> i) & 1)) |
| 877 | continue; |
| 878 | exca_writeb(socket, I365_CSCINT, I365_CSC_STSCHG | (i << 4)); |
| 879 | cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS); |
| 880 | udelay(100); |
| 881 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 882 | } |
| 883 | cb_writel(socket, CB_SOCKET_MASK, 0); |
| 884 | exca_writeb(socket, I365_CSCINT, 0); |
| 885 | |
| 886 | mask = probe_irq_mask(val) & 0xffff; |
| 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | return mask; |
| 889 | } |
| 890 | |
| 891 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 892 | /** |
| 893 | * yenta PCI irq probing. |
| 894 | * currently only used in the TI/EnE initialization code |
| 895 | */ |
| 896 | #ifdef CONFIG_YENTA_TI |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* interrupt handler, only used during probing */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 899 | static irqreturn_t yenta_probe_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
| 901 | struct yenta_socket *socket = (struct yenta_socket *) dev_id; |
| 902 | u8 csc; |
| 903 | u32 cb_event; |
| 904 | |
| 905 | /* Clear interrupt status for the event */ |
| 906 | cb_event = cb_readl(socket, CB_SOCKET_EVENT); |
| 907 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 908 | csc = exca_readb(socket, I365_CSC); |
| 909 | |
| 910 | if (cb_event || csc) { |
| 911 | socket->probe_status = 1; |
| 912 | return IRQ_HANDLED; |
| 913 | } |
| 914 | |
| 915 | return IRQ_NONE; |
| 916 | } |
| 917 | |
| 918 | /* probes the PCI interrupt, use only on override functions */ |
| 919 | static int yenta_probe_cb_irq(struct yenta_socket *socket) |
| 920 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | if (!socket->cb_irq) |
| 922 | return -1; |
| 923 | |
| 924 | socket->probe_status = 0; |
| 925 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 926 | if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | printk(KERN_WARNING "Yenta: request_irq() in yenta_probe_cb_irq() failed!\n"); |
| 928 | return -1; |
| 929 | } |
| 930 | |
| 931 | /* generate interrupt, wait */ |
| 932 | exca_writeb(socket, I365_CSCINT, I365_CSC_STSCHG); |
| 933 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 934 | cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK); |
| 935 | cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS); |
Daniel Ritz | a413c09 | 2005-08-24 17:03:23 +0200 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | msleep(100); |
| 938 | |
| 939 | /* disable interrupts */ |
| 940 | cb_writel(socket, CB_SOCKET_MASK, 0); |
| 941 | exca_writeb(socket, I365_CSCINT, 0); |
| 942 | cb_writel(socket, CB_SOCKET_EVENT, -1); |
| 943 | exca_readb(socket, I365_CSC); |
| 944 | |
| 945 | free_irq(socket->cb_irq, socket); |
| 946 | |
| 947 | return (int) socket->probe_status; |
| 948 | } |
| 949 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 950 | #endif /* CONFIG_YENTA_TI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | |
| 953 | /* |
| 954 | * Set static data that doesn't need re-initializing.. |
| 955 | */ |
| 956 | static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_irq_mask) |
| 957 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | socket->socket.pci_irq = socket->cb_irq; |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 959 | if (isa_probe) |
| 960 | socket->socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask); |
| 961 | else |
| 962 | socket->socket.irq_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n", |
| 965 | socket->socket.irq_mask, socket->cb_irq); |
| 966 | } |
| 967 | |
| 968 | /* |
| 969 | * Initialize the standard cardbus registers |
| 970 | */ |
| 971 | static void yenta_config_init(struct yenta_socket *socket) |
| 972 | { |
| 973 | u16 bridge; |
| 974 | struct pci_dev *dev = socket->dev; |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 975 | struct pci_bus_region region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 977 | pcibios_resource_to_bus(socket->dev, ®ion, &dev->resource[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
| 979 | config_writel(socket, CB_LEGACY_MODE_BASE, 0); |
Dominik Brodowski | 8e5d17e | 2005-09-07 16:00:28 -0700 | [diff] [blame] | 980 | config_writel(socket, PCI_BASE_ADDRESS_0, region.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | config_writew(socket, PCI_COMMAND, |
| 982 | PCI_COMMAND_IO | |
| 983 | PCI_COMMAND_MEMORY | |
| 984 | PCI_COMMAND_MASTER | |
| 985 | PCI_COMMAND_WAIT); |
| 986 | |
| 987 | /* MAGIC NUMBERS! Fixme */ |
| 988 | config_writeb(socket, PCI_CACHE_LINE_SIZE, L1_CACHE_BYTES / 4); |
| 989 | config_writeb(socket, PCI_LATENCY_TIMER, 168); |
| 990 | config_writel(socket, PCI_PRIMARY_BUS, |
| 991 | (176 << 24) | /* sec. latency timer */ |
| 992 | (dev->subordinate->subordinate << 16) | /* subordinate bus */ |
| 993 | (dev->subordinate->secondary << 8) | /* secondary bus */ |
| 994 | dev->subordinate->primary); /* primary bus */ |
| 995 | |
| 996 | /* |
| 997 | * Set up the bridging state: |
| 998 | * - enable write posting. |
| 999 | * - memory window 0 prefetchable, window 1 non-prefetchable |
| 1000 | * - PCI interrupts enabled if a PCI interrupt exists.. |
| 1001 | */ |
| 1002 | bridge = config_readw(socket, CB_BRIDGE_CONTROL); |
Daniel Ritz | a413c09 | 2005-08-24 17:03:23 +0200 | [diff] [blame] | 1003 | bridge &= ~(CB_BRIDGE_CRST | CB_BRIDGE_PREFETCH1 | CB_BRIDGE_ISAEN | CB_BRIDGE_VGAEN); |
| 1004 | bridge |= CB_BRIDGE_PREFETCH0 | CB_BRIDGE_POSTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | config_writew(socket, CB_BRIDGE_CONTROL, bridge); |
| 1006 | } |
| 1007 | |
Bernhard Kaindl | b435261 | 2006-05-30 18:00:34 +0200 | [diff] [blame] | 1008 | /** |
Randy Dunlap | 6600521 | 2006-06-06 12:06:41 -0700 | [diff] [blame] | 1009 | * yenta_fixup_parent_bridge - Fix subordinate bus# of the parent bridge |
Bernhard Kaindl | b435261 | 2006-05-30 18:00:34 +0200 | [diff] [blame] | 1010 | * @cardbus_bridge: The PCI bus which the CardBus bridge bridges to |
| 1011 | * |
| 1012 | * Checks if devices on the bus which the CardBus bridge bridges to would be |
| 1013 | * invisible during PCI scans because of a misconfigured subordinate number |
| 1014 | * of the parent brige - some BIOSes seem to be too lazy to set it right. |
| 1015 | * Does the fixup carefully by checking how far it can go without conflicts. |
| 1016 | * See http://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information. |
| 1017 | */ |
| 1018 | static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge) |
| 1019 | { |
| 1020 | struct list_head *tmp; |
| 1021 | unsigned char upper_limit; |
| 1022 | /* |
| 1023 | * We only check and fix the parent bridge: All systems which need |
| 1024 | * this fixup that have been reviewed are laptops and the only bridge |
| 1025 | * which needed fixing was the parent bridge of the CardBus bridge: |
| 1026 | */ |
| 1027 | struct pci_bus *bridge_to_fix = cardbus_bridge->parent; |
| 1028 | |
| 1029 | /* Check bus numbers are already set up correctly: */ |
| 1030 | if (bridge_to_fix->subordinate >= cardbus_bridge->subordinate) |
| 1031 | return; /* The subordinate number is ok, nothing to do */ |
| 1032 | |
| 1033 | if (!bridge_to_fix->parent) |
| 1034 | return; /* Root bridges are ok */ |
| 1035 | |
| 1036 | /* stay within the limits of the bus range of the parent: */ |
| 1037 | upper_limit = bridge_to_fix->parent->subordinate; |
| 1038 | |
| 1039 | /* check the bus ranges of all silbling bridges to prevent overlap */ |
| 1040 | list_for_each(tmp, &bridge_to_fix->parent->children) { |
| 1041 | struct pci_bus * silbling = pci_bus_b(tmp); |
| 1042 | /* |
| 1043 | * If the silbling has a higher secondary bus number |
| 1044 | * and it's secondary is equal or smaller than our |
| 1045 | * current upper limit, set the new upper limit to |
| 1046 | * the bus number below the silbling's range: |
| 1047 | */ |
| 1048 | if (silbling->secondary > bridge_to_fix->subordinate |
| 1049 | && silbling->secondary <= upper_limit) |
| 1050 | upper_limit = silbling->secondary - 1; |
| 1051 | } |
| 1052 | |
| 1053 | /* Show that the wanted subordinate number is not possible: */ |
| 1054 | if (cardbus_bridge->subordinate > upper_limit) |
| 1055 | printk(KERN_WARNING "Yenta: Upper limit for fixing this " |
| 1056 | "bridge's parent bridge: #%02x\n", upper_limit); |
| 1057 | |
| 1058 | /* If we have room to increase the bridge's subordinate number, */ |
| 1059 | if (bridge_to_fix->subordinate < upper_limit) { |
| 1060 | |
| 1061 | /* use the highest number of the hidden bus, within limits */ |
| 1062 | unsigned char subordinate_to_assign = |
| 1063 | min(cardbus_bridge->subordinate, upper_limit); |
| 1064 | |
| 1065 | printk(KERN_INFO "Yenta: Raising subordinate bus# of parent " |
| 1066 | "bus (#%02x) from #%02x to #%02x\n", |
| 1067 | bridge_to_fix->number, |
| 1068 | bridge_to_fix->subordinate, subordinate_to_assign); |
| 1069 | |
| 1070 | /* Save the new subordinate in the bus struct of the bridge */ |
| 1071 | bridge_to_fix->subordinate = subordinate_to_assign; |
| 1072 | |
| 1073 | /* and update the PCI config space with the new subordinate */ |
| 1074 | pci_write_config_byte(bridge_to_fix->self, |
| 1075 | PCI_SUBORDINATE_BUS, bridge_to_fix->subordinate); |
| 1076 | } |
| 1077 | } |
| 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | /* |
| 1080 | * Initialize a cardbus controller. Make sure we have a usable |
| 1081 | * interrupt, and that we can map the cardbus area. Fill in the |
| 1082 | * socket information structure.. |
| 1083 | */ |
| 1084 | static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_id *id) |
| 1085 | { |
| 1086 | struct yenta_socket *socket; |
| 1087 | int ret; |
Ivan Kokshaysky | c7fb0b3 | 2005-09-14 23:05:30 +0400 | [diff] [blame] | 1088 | |
| 1089 | /* |
| 1090 | * If we failed to assign proper bus numbers for this cardbus |
| 1091 | * controller during PCI probe, its subordinate pci_bus is NULL. |
| 1092 | * Bail out if so. |
| 1093 | */ |
| 1094 | if (!dev->subordinate) { |
Linus Torvalds | 5a23f34 | 2005-09-14 13:05:17 -0700 | [diff] [blame] | 1095 | printk(KERN_ERR "Yenta: no bus associated with %s! " |
| 1096 | "(try 'pci=assign-busses')\n", pci_name(dev)); |
Ivan Kokshaysky | c7fb0b3 | 2005-09-14 23:05:30 +0400 | [diff] [blame] | 1097 | return -ENODEV; |
| 1098 | } |
| 1099 | |
Dominik Brodowski | 8084b37 | 2005-12-11 21:18:26 +0100 | [diff] [blame] | 1100 | socket = kzalloc(sizeof(struct yenta_socket), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | if (!socket) |
| 1102 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | |
| 1104 | /* prepare pcmcia_socket */ |
| 1105 | socket->socket.ops = ¥ta_socket_operations; |
| 1106 | socket->socket.resource_ops = &pccard_nonstatic_ops; |
| 1107 | socket->socket.dev.dev = &dev->dev; |
| 1108 | socket->socket.driver_data = socket; |
| 1109 | socket->socket.owner = THIS_MODULE; |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 1110 | socket->socket.features = SS_CAP_PAGE_REGS | SS_CAP_PCCARD; |
| 1111 | socket->socket.map_size = 0x1000; |
| 1112 | socket->socket.cb_dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | /* prepare struct yenta_socket */ |
| 1115 | socket->dev = dev; |
| 1116 | pci_set_drvdata(dev, socket); |
| 1117 | |
| 1118 | /* |
| 1119 | * Do some basic sanity checking.. |
| 1120 | */ |
| 1121 | if (pci_enable_device(dev)) { |
| 1122 | ret = -EBUSY; |
| 1123 | goto free; |
| 1124 | } |
| 1125 | |
| 1126 | ret = pci_request_regions(dev, "yenta_socket"); |
| 1127 | if (ret) |
| 1128 | goto disable; |
| 1129 | |
| 1130 | if (!pci_resource_start(dev, 0)) { |
| 1131 | printk(KERN_ERR "No cardbus resource!\n"); |
| 1132 | ret = -ENODEV; |
| 1133 | goto release; |
| 1134 | } |
| 1135 | |
| 1136 | /* |
| 1137 | * Ok, start setup.. Map the cardbus registers, |
| 1138 | * and request the IRQ. |
| 1139 | */ |
| 1140 | socket->base = ioremap(pci_resource_start(dev, 0), 0x1000); |
| 1141 | if (!socket->base) { |
| 1142 | ret = -ENOMEM; |
| 1143 | goto release; |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * report the subsystem vendor and device for help debugging |
| 1148 | * the irq stuff... |
| 1149 | */ |
| 1150 | printk(KERN_INFO "Yenta: CardBus bridge found at %s [%04x:%04x]\n", |
| 1151 | pci_name(dev), dev->subsystem_vendor, dev->subsystem_device); |
| 1152 | |
| 1153 | yenta_config_init(socket); |
| 1154 | |
| 1155 | /* Disable all events */ |
| 1156 | cb_writel(socket, CB_SOCKET_MASK, 0x0); |
| 1157 | |
| 1158 | /* Set up the bridge regions.. */ |
| 1159 | yenta_allocate_resources(socket); |
| 1160 | |
| 1161 | socket->cb_irq = dev->irq; |
| 1162 | |
| 1163 | /* Do we have special options for the device? */ |
| 1164 | if (id->driver_data != CARDBUS_TYPE_DEFAULT && |
| 1165 | id->driver_data < ARRAY_SIZE(cardbus_type)) { |
| 1166 | socket->type = &cardbus_type[id->driver_data]; |
| 1167 | |
| 1168 | ret = socket->type->override(socket); |
| 1169 | if (ret < 0) |
| 1170 | goto unmap; |
| 1171 | } |
| 1172 | |
| 1173 | /* We must finish initialization here */ |
| 1174 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 1175 | if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, IRQF_SHARED, "yenta", socket)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | /* No IRQ or request_irq failed. Poll */ |
| 1177 | socket->cb_irq = 0; /* But zero is a valid IRQ number. */ |
| 1178 | init_timer(&socket->poll_timer); |
| 1179 | socket->poll_timer.function = yenta_interrupt_wrapper; |
| 1180 | socket->poll_timer.data = (unsigned long)socket; |
| 1181 | socket->poll_timer.expires = jiffies + HZ; |
| 1182 | add_timer(&socket->poll_timer); |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 1183 | printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n" |
| 1184 | KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n"); |
| 1185 | } else { |
| 1186 | socket->socket.features |= SS_CAP_CARDBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /* Figure out what the dang thing can do for the PCMCIA layer... */ |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 1190 | yenta_interrogate(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | yenta_get_socket_capabilities(socket, isa_interrupts); |
| 1192 | printk(KERN_INFO "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE)); |
| 1193 | |
Bernhard Kaindl | b435261 | 2006-05-30 18:00:34 +0200 | [diff] [blame] | 1194 | yenta_fixup_parent_bridge(dev->subordinate); |
| 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | /* Register it with the pcmcia layer.. */ |
| 1197 | ret = pcmcia_register_socket(&socket->socket); |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 1198 | if (ret == 0) { |
| 1199 | /* Add the yenta register attributes */ |
| 1200 | device_create_file(&dev->dev, &dev_attr_yenta_registers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | goto out; |
Linus Torvalds | 030ee39 | 2005-10-28 13:55:08 -0700 | [diff] [blame] | 1202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | unmap: |
| 1205 | iounmap(socket->base); |
| 1206 | release: |
| 1207 | pci_release_regions(dev); |
| 1208 | disable: |
| 1209 | pci_disable_device(dev); |
| 1210 | free: |
| 1211 | kfree(socket); |
| 1212 | out: |
| 1213 | return ret; |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state) |
| 1218 | { |
| 1219 | struct yenta_socket *socket = pci_get_drvdata(dev); |
| 1220 | int ret; |
| 1221 | |
| 1222 | ret = pcmcia_socket_dev_suspend(&dev->dev, state); |
| 1223 | |
| 1224 | if (socket) { |
| 1225 | if (socket->type && socket->type->save_state) |
| 1226 | socket->type->save_state(socket); |
| 1227 | |
| 1228 | /* FIXME: pci_save_state needs to have a better interface */ |
| 1229 | pci_save_state(dev); |
| 1230 | pci_read_config_dword(dev, 16*4, &socket->saved_state[0]); |
| 1231 | pci_read_config_dword(dev, 17*4, &socket->saved_state[1]); |
David Shaohua Li | d58da59 | 2005-03-18 16:43:54 -0500 | [diff] [blame] | 1232 | pci_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
| 1234 | /* |
| 1235 | * Some laptops (IBM T22) do not like us putting the Cardbus |
| 1236 | * bridge into D3. At a guess, some other laptop will |
| 1237 | * probably require this, so leave it commented out for now. |
| 1238 | */ |
| 1239 | /* pci_set_power_state(dev, 3); */ |
| 1240 | } |
| 1241 | |
| 1242 | return ret; |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | static int yenta_dev_resume (struct pci_dev *dev) |
| 1247 | { |
| 1248 | struct yenta_socket *socket = pci_get_drvdata(dev); |
| 1249 | |
| 1250 | if (socket) { |
| 1251 | pci_set_power_state(dev, 0); |
| 1252 | /* FIXME: pci_restore_state needs to have a better interface */ |
| 1253 | pci_restore_state(dev); |
| 1254 | pci_write_config_dword(dev, 16*4, socket->saved_state[0]); |
| 1255 | pci_write_config_dword(dev, 17*4, socket->saved_state[1]); |
David Shaohua Li | d58da59 | 2005-03-18 16:43:54 -0500 | [diff] [blame] | 1256 | pci_enable_device(dev); |
| 1257 | pci_set_master(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | if (socket->type && socket->type->restore_state) |
| 1260 | socket->type->restore_state(socket); |
| 1261 | } |
| 1262 | |
| 1263 | return pcmcia_socket_dev_resume(&dev->dev); |
| 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | #define CB_ID(vend,dev,type) \ |
| 1268 | { \ |
| 1269 | .vendor = vend, \ |
| 1270 | .device = dev, \ |
| 1271 | .subvendor = PCI_ANY_ID, \ |
| 1272 | .subdevice = PCI_ANY_ID, \ |
| 1273 | .class = PCI_CLASS_BRIDGE_CARDBUS << 8, \ |
| 1274 | .class_mask = ~0, \ |
| 1275 | .driver_data = CARDBUS_TYPE_##type, \ |
| 1276 | } |
| 1277 | |
| 1278 | static struct pci_device_id yenta_table [] = { |
| 1279 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1031, TI), |
| 1280 | |
| 1281 | /* |
| 1282 | * TBD: Check if these TI variants can use more |
| 1283 | * advanced overrides instead. (I can't get the |
| 1284 | * data sheets for these devices. --rmk) |
| 1285 | */ |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1286 | #ifdef CONFIG_YENTA_TI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1210, TI), |
| 1288 | |
| 1289 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1130, TI113X), |
| 1290 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1131, TI113X), |
| 1291 | |
| 1292 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1211, TI12XX), |
| 1293 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1220, TI12XX), |
| 1294 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1221, TI12XX), |
| 1295 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1225, TI12XX), |
| 1296 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251A, TI12XX), |
| 1297 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251B, TI12XX), |
| 1298 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420, TI12XX), |
| 1299 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1450, TI12XX), |
| 1300 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1451A, TI12XX), |
| 1301 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510, TI12XX), |
| 1302 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1520, TI12XX), |
| 1303 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1620, TI12XX), |
| 1304 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4410, TI12XX), |
| 1305 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4450, TI12XX), |
| 1306 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4451, TI12XX), |
| 1307 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4510, TI12XX), |
| 1308 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4520, TI12XX), |
| 1309 | |
| 1310 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1250, TI1250), |
| 1311 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1410, TI1250), |
| 1312 | |
Daniel Ritz | 6c1a10d | 2005-09-20 14:12:17 -0700 | [diff] [blame] | 1313 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX21_XX11, TI12XX), |
| 1314 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X515, TI12XX), |
Alex Williamson | 59e35ba | 2006-05-08 23:22:07 -0600 | [diff] [blame] | 1315 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX12, TI12XX), |
Daniel Ritz | 6c1a10d | 2005-09-20 14:12:17 -0700 | [diff] [blame] | 1316 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X420, TI12XX), |
| 1317 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X620, TI12XX), |
| 1318 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7410, TI12XX), |
| 1319 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7510, TI12XX), |
| 1320 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7610, TI12XX), |
| 1321 | |
Daniel Ritz | f9cb8b7 | 2005-09-24 23:12:46 -0700 | [diff] [blame] | 1322 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_710, TI12XX), |
| 1323 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_712, TI12XX), |
| 1324 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_720, TI12XX), |
| 1325 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_722, TI12XX), |
Daniel Ritz | 8c3520d | 2005-08-21 22:29:26 -0700 | [diff] [blame] | 1326 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1211, ENE), |
| 1327 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE), |
| 1328 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE), |
| 1329 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1420, ENE), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1330 | #endif /* CONFIG_YENTA_TI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1332 | #ifdef CONFIG_YENTA_RICOH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C465, RICOH), |
| 1334 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C466, RICOH), |
| 1335 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C475, RICOH), |
| 1336 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH), |
| 1337 | CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1338 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1340 | #ifdef CONFIG_YENTA_TOSHIBA |
Daniel Ritz | ea2f159 | 2005-09-06 15:16:50 -0700 | [diff] [blame] | 1341 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC95, TOPIC95), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97), |
| 1343 | CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1344 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1346 | #ifdef CONFIG_YENTA_O2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | CB_ID(PCI_VENDOR_ID_O2, PCI_ANY_ID, O2MICRO), |
Daniel Ritz | 63e7ebd | 2005-11-03 21:12:14 +0100 | [diff] [blame] | 1348 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | /* match any cardbus bridge */ |
| 1351 | CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT), |
| 1352 | { /* all zeroes */ } |
| 1353 | }; |
| 1354 | MODULE_DEVICE_TABLE(pci, yenta_table); |
| 1355 | |
| 1356 | |
| 1357 | static struct pci_driver yenta_cardbus_driver = { |
| 1358 | .name = "yenta_cardbus", |
| 1359 | .id_table = yenta_table, |
| 1360 | .probe = yenta_probe, |
| 1361 | .remove = __devexit_p(yenta_close), |
| 1362 | .suspend = yenta_dev_suspend, |
| 1363 | .resume = yenta_dev_resume, |
| 1364 | }; |
| 1365 | |
| 1366 | |
| 1367 | static int __init yenta_socket_init(void) |
| 1368 | { |
| 1369 | return pci_register_driver (¥ta_cardbus_driver); |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | static void __exit yenta_socket_exit (void) |
| 1374 | { |
| 1375 | pci_unregister_driver (¥ta_cardbus_driver); |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | module_init(yenta_socket_init); |
| 1380 | module_exit(yenta_socket_exit); |
| 1381 | |
| 1382 | MODULE_LICENSE("GPL"); |