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