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