Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCMCIA 16-bit resource management functions |
| 3 | * |
| 4 | * The initial developer of the original code is David A. Hinds |
| 5 | * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds |
| 6 | * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. |
| 7 | * |
| 8 | * Copyright (C) 1999 David A. Hinds |
| 9 | * Copyright (C) 2004-2005 Dominik Brodowski |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | */ |
| 16 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/device.h> |
| 23 | |
| 24 | #define IN_CARD_SERVICES |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 25 | #include <pcmcia/cs_types.h> |
| 26 | #include <pcmcia/ss.h> |
| 27 | #include <pcmcia/cs.h> |
| 28 | #include <pcmcia/bulkmem.h> |
| 29 | #include <pcmcia/cistpl.h> |
| 30 | #include <pcmcia/cisreg.h> |
| 31 | #include <pcmcia/ds.h> |
| 32 | |
| 33 | #include "cs_internal.h" |
| 34 | #include "ds_internal.h" |
| 35 | |
| 36 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 37 | /* Access speed for IO windows */ |
| 38 | static int io_speed = 0; |
| 39 | module_param(io_speed, int, 0444); |
| 40 | |
| 41 | |
| 42 | #ifdef CONFIG_PCMCIA_PROBE |
Al Viro | 531e5ca | 2005-08-23 22:47:01 +0100 | [diff] [blame] | 43 | #include <asm/irq.h> |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 44 | /* mask of IRQs already reserved by other cards, we should avoid using them */ |
| 45 | static u8 pcmcia_used_irq[NR_IRQS]; |
| 46 | #endif |
| 47 | |
| 48 | |
| 49 | #ifdef DEBUG |
| 50 | extern int ds_pc_debug; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 51 | |
| 52 | #define ds_dbg(skt, lvl, fmt, arg...) do { \ |
| 53 | if (ds_pc_debug >= lvl) \ |
| 54 | printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \ |
| 55 | cs_socket_name(skt) , ## arg); \ |
| 56 | } while (0) |
| 57 | #else |
| 58 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) |
| 59 | #endif |
| 60 | |
| 61 | |
| 62 | |
| 63 | /** alloc_io_space |
| 64 | * |
| 65 | * Special stuff for managing IO windows, because they are scarce |
| 66 | */ |
| 67 | |
| 68 | static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base, |
| 69 | ioaddr_t num, u_int lines) |
| 70 | { |
| 71 | int i; |
| 72 | kio_addr_t try, align; |
| 73 | |
| 74 | align = (*base) ? (lines ? 1<<lines : 0) : 1; |
| 75 | if (align && (align < num)) { |
| 76 | if (*base) { |
| 77 | ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n", |
| 78 | num, align); |
| 79 | align = 0; |
| 80 | } else |
| 81 | while (align && (align < num)) align <<= 1; |
| 82 | } |
| 83 | if (*base & ~(align-1)) { |
| 84 | ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n", |
| 85 | *base, align); |
| 86 | align = 0; |
| 87 | } |
| 88 | if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) { |
| 89 | *base = s->io_offset | (*base & 0x0fff); |
| 90 | return 0; |
| 91 | } |
| 92 | /* Check for an already-allocated window that must conflict with |
| 93 | * what was asked for. It is a hack because it does not catch all |
| 94 | * potential conflicts, just the most obvious ones. |
| 95 | */ |
| 96 | for (i = 0; i < MAX_IO_WIN; i++) |
Kaustav Majumdar | 4708b5f | 2006-10-20 14:44:09 -0700 | [diff] [blame] | 97 | if ((s->io[i].res) && *base && |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 98 | ((s->io[i].res->start & (align-1)) == *base)) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 99 | return 1; |
| 100 | for (i = 0; i < MAX_IO_WIN; i++) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 101 | if (!s->io[i].res) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 102 | s->io[i].res = pcmcia_find_io_region(*base, num, align, s); |
| 103 | if (s->io[i].res) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 104 | *base = s->io[i].res->start; |
| 105 | s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS); |
| 106 | s->io[i].InUse = num; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 107 | break; |
| 108 | } else |
| 109 | return 1; |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 110 | } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS)) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 111 | continue; |
| 112 | /* Try to extend top of window */ |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 113 | try = s->io[i].res->end + 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 114 | if ((*base == 0) || (*base == try)) |
| 115 | if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start, |
| 116 | s->io[i].res->end + num, s) == 0) { |
| 117 | *base = try; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 118 | s->io[i].InUse += num; |
| 119 | break; |
| 120 | } |
| 121 | /* Try to extend bottom of window */ |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 122 | try = s->io[i].res->start - num; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 123 | if ((*base == 0) || (*base == try)) |
| 124 | if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num, |
| 125 | s->io[i].res->end, s) == 0) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 126 | *base = try; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 127 | s->io[i].InUse += num; |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | return (i == MAX_IO_WIN); |
| 132 | } /* alloc_io_space */ |
| 133 | |
| 134 | |
| 135 | static void release_io_space(struct pcmcia_socket *s, ioaddr_t base, |
| 136 | ioaddr_t num) |
| 137 | { |
| 138 | int i; |
| 139 | |
| 140 | for (i = 0; i < MAX_IO_WIN; i++) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 141 | if (!s->io[i].res) |
| 142 | continue; |
| 143 | if ((s->io[i].res->start <= base) && |
| 144 | (s->io[i].res->end >= base+num-1)) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 145 | s->io[i].InUse -= num; |
| 146 | /* Free the window if no one else is using it */ |
| 147 | if (s->io[i].InUse == 0) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 148 | release_resource(s->io[i].res); |
| 149 | kfree(s->io[i].res); |
| 150 | s->io[i].res = NULL; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } /* release_io_space */ |
| 155 | |
| 156 | |
| 157 | /** pccard_access_configuration_register |
| 158 | * |
| 159 | * Access_configuration_register() reads and writes configuration |
| 160 | * registers in attribute memory. Memory window 0 is reserved for |
| 161 | * this and the tuple reading services. |
| 162 | */ |
| 163 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 164 | int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 165 | conf_reg_t *reg) |
| 166 | { |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 167 | struct pcmcia_socket *s; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 168 | config_t *c; |
| 169 | int addr; |
| 170 | u_char val; |
| 171 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 172 | if (!p_dev || !p_dev->function_config) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 173 | return CS_NO_CARD; |
| 174 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 175 | s = p_dev->socket; |
| 176 | c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 177 | |
| 178 | if (!(c->state & CONFIG_LOCKED)) |
| 179 | return CS_CONFIGURATION_LOCKED; |
| 180 | |
| 181 | addr = (c->ConfigBase + reg->Offset) >> 1; |
| 182 | |
| 183 | switch (reg->Action) { |
| 184 | case CS_READ: |
| 185 | pcmcia_read_cis_mem(s, 1, addr, 1, &val); |
| 186 | reg->Value = val; |
| 187 | break; |
| 188 | case CS_WRITE: |
| 189 | val = reg->Value; |
| 190 | pcmcia_write_cis_mem(s, 1, addr, 1, &val); |
| 191 | break; |
| 192 | default: |
| 193 | return CS_BAD_ARGS; |
| 194 | break; |
| 195 | } |
| 196 | return CS_SUCCESS; |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 197 | } /* pcmcia_access_configuration_register */ |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 198 | EXPORT_SYMBOL(pcmcia_access_configuration_register); |
| 199 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 200 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 201 | int pccard_get_configuration_info(struct pcmcia_socket *s, |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 202 | struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 203 | config_info_t *config) |
| 204 | { |
| 205 | config_t *c; |
| 206 | |
| 207 | if (!(s->state & SOCKET_PRESENT)) |
| 208 | return CS_NO_CARD; |
| 209 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 210 | |
| 211 | #ifdef CONFIG_CARDBUS |
| 212 | if (s->state & SOCKET_CARDBUS) { |
| 213 | memset(config, 0, sizeof(config_info_t)); |
| 214 | config->Vcc = s->socket.Vcc; |
| 215 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; |
| 216 | config->Option = s->cb_dev->subordinate->number; |
| 217 | if (s->state & SOCKET_CARDBUS_CONFIG) { |
| 218 | config->Attributes = CONF_VALID_CLIENT; |
| 219 | config->IntType = INT_CARDBUS; |
| 220 | config->AssignedIRQ = s->irq.AssignedIRQ; |
| 221 | if (config->AssignedIRQ) |
| 222 | config->Attributes |= CONF_ENABLE_IRQ; |
Daniel Ritz | 48b950f | 2006-04-14 17:42:13 +0200 | [diff] [blame] | 223 | if (s->io[0].res) { |
| 224 | config->BasePort1 = s->io[0].res->start; |
| 225 | config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1; |
| 226 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 227 | } |
| 228 | return CS_SUCCESS; |
| 229 | } |
| 230 | #endif |
| 231 | |
Daniel Ritz | 48b950f | 2006-04-14 17:42:13 +0200 | [diff] [blame] | 232 | if (p_dev) { |
| 233 | c = p_dev->function_config; |
| 234 | config->Function = p_dev->func; |
| 235 | } else { |
| 236 | c = NULL; |
| 237 | config->Function = 0; |
| 238 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 239 | |
| 240 | if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { |
| 241 | config->Attributes = 0; |
| 242 | config->Vcc = s->socket.Vcc; |
| 243 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; |
| 244 | return CS_SUCCESS; |
| 245 | } |
| 246 | |
Daniel Ritz | 47a3197 | 2006-07-30 03:03:49 -0700 | [diff] [blame] | 247 | config->Attributes = c->Attributes | CONF_VALID_CLIENT; |
| 248 | config->Vcc = s->socket.Vcc; |
| 249 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; |
| 250 | config->IntType = c->IntType; |
| 251 | config->ConfigBase = c->ConfigBase; |
| 252 | config->Status = c->Status; |
| 253 | config->Pin = c->Pin; |
| 254 | config->Copy = c->Copy; |
| 255 | config->Option = c->Option; |
| 256 | config->ExtStatus = c->ExtStatus; |
| 257 | config->Present = config->CardValues = c->CardValues; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 258 | config->IRQAttributes = c->irq.Attributes; |
| 259 | config->AssignedIRQ = s->irq.AssignedIRQ; |
| 260 | config->BasePort1 = c->io.BasePort1; |
| 261 | config->NumPorts1 = c->io.NumPorts1; |
| 262 | config->Attributes1 = c->io.Attributes1; |
| 263 | config->BasePort2 = c->io.BasePort2; |
| 264 | config->NumPorts2 = c->io.NumPorts2; |
| 265 | config->Attributes2 = c->io.Attributes2; |
| 266 | config->IOAddrLines = c->io.IOAddrLines; |
| 267 | |
| 268 | return CS_SUCCESS; |
| 269 | } /* pccard_get_configuration_info */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 270 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 271 | int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 272 | config_info_t *config) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 273 | { |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 274 | return pccard_get_configuration_info(p_dev->socket, p_dev, |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 275 | config); |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 276 | } |
| 277 | EXPORT_SYMBOL(pcmcia_get_configuration_info); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 278 | |
| 279 | |
| 280 | /** pcmcia_get_window |
| 281 | */ |
| 282 | int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, |
| 283 | int idx, win_req_t *req) |
| 284 | { |
| 285 | window_t *win; |
| 286 | int w; |
| 287 | |
| 288 | if (!s || !(s->state & SOCKET_PRESENT)) |
| 289 | return CS_NO_CARD; |
| 290 | for (w = idx; w < MAX_WIN; w++) |
| 291 | if (s->state & SOCKET_WIN_REQ(w)) |
| 292 | break; |
| 293 | if (w == MAX_WIN) |
| 294 | return CS_NO_MORE_ITEMS; |
| 295 | win = &s->win[w]; |
| 296 | req->Base = win->ctl.res->start; |
| 297 | req->Size = win->ctl.res->end - win->ctl.res->start + 1; |
| 298 | req->AccessSpeed = win->ctl.speed; |
| 299 | req->Attributes = 0; |
| 300 | if (win->ctl.flags & MAP_ATTRIB) |
| 301 | req->Attributes |= WIN_MEMORY_TYPE_AM; |
| 302 | if (win->ctl.flags & MAP_ACTIVE) |
| 303 | req->Attributes |= WIN_ENABLE; |
| 304 | if (win->ctl.flags & MAP_16BIT) |
| 305 | req->Attributes |= WIN_DATA_WIDTH_16; |
| 306 | if (win->ctl.flags & MAP_USE_WAIT) |
| 307 | req->Attributes |= WIN_USE_WAIT; |
| 308 | *handle = win; |
| 309 | return CS_SUCCESS; |
| 310 | } /* pcmcia_get_window */ |
| 311 | EXPORT_SYMBOL(pcmcia_get_window); |
| 312 | |
| 313 | |
| 314 | /** pccard_get_status |
| 315 | * |
| 316 | * Get the current socket state bits. We don't support the latched |
| 317 | * SocketState yet: I haven't seen any point for it. |
| 318 | */ |
| 319 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 320 | int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 321 | cs_status_t *status) |
| 322 | { |
| 323 | config_t *c; |
| 324 | int val; |
| 325 | |
| 326 | s->ops->get_status(s, &val); |
| 327 | status->CardState = status->SocketState = 0; |
| 328 | status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0; |
| 329 | status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0; |
| 330 | status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0; |
| 331 | status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0; |
| 332 | if (s->state & SOCKET_SUSPEND) |
| 333 | status->CardState |= CS_EVENT_PM_SUSPEND; |
| 334 | if (!(s->state & SOCKET_PRESENT)) |
| 335 | return CS_NO_CARD; |
| 336 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 337 | c = (p_dev) ? p_dev->function_config : NULL; |
| 338 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 339 | if ((c != NULL) && (c->state & CONFIG_LOCKED) && |
| 340 | (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { |
| 341 | u_char reg; |
Dominik Brodowski | 1ae9c7d | 2006-01-10 20:40:40 +0100 | [diff] [blame] | 342 | if (c->CardValues & PRESENT_PIN_REPLACE) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 343 | pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, ®); |
| 344 | status->CardState |= |
| 345 | (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; |
| 346 | status->CardState |= |
| 347 | (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0; |
| 348 | status->CardState |= |
| 349 | (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0; |
| 350 | status->CardState |= |
| 351 | (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0; |
| 352 | } else { |
| 353 | /* No PRR? Then assume we're always ready */ |
| 354 | status->CardState |= CS_EVENT_READY_CHANGE; |
| 355 | } |
Dominik Brodowski | 1ae9c7d | 2006-01-10 20:40:40 +0100 | [diff] [blame] | 356 | if (c->CardValues & PRESENT_EXT_STATUS) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 357 | pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, ®); |
| 358 | status->CardState |= |
| 359 | (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; |
| 360 | } |
| 361 | return CS_SUCCESS; |
| 362 | } |
| 363 | status->CardState |= |
| 364 | (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0; |
| 365 | status->CardState |= |
| 366 | (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0; |
| 367 | status->CardState |= |
| 368 | (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0; |
| 369 | status->CardState |= |
| 370 | (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0; |
| 371 | return CS_SUCCESS; |
| 372 | } /* pccard_get_status */ |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 373 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 374 | int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status) |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 375 | { |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 376 | return pccard_get_status(p_dev->socket, p_dev, status); |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 377 | } |
| 378 | EXPORT_SYMBOL(pcmcia_get_status); |
| 379 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 380 | |
| 381 | |
| 382 | /** pcmcia_get_mem_page |
| 383 | * |
| 384 | * Change the card address of an already open memory window. |
| 385 | */ |
| 386 | int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) |
| 387 | { |
| 388 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
| 389 | return CS_BAD_HANDLE; |
| 390 | req->Page = 0; |
| 391 | req->CardOffset = win->ctl.card_start; |
| 392 | return CS_SUCCESS; |
| 393 | } /* pcmcia_get_mem_page */ |
| 394 | EXPORT_SYMBOL(pcmcia_get_mem_page); |
| 395 | |
| 396 | |
| 397 | int pcmcia_map_mem_page(window_handle_t win, memreq_t *req) |
| 398 | { |
| 399 | struct pcmcia_socket *s; |
| 400 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
| 401 | return CS_BAD_HANDLE; |
| 402 | if (req->Page != 0) |
| 403 | return CS_BAD_PAGE; |
| 404 | s = win->sock; |
| 405 | win->ctl.card_start = req->CardOffset; |
| 406 | if (s->ops->set_mem_map(s, &win->ctl) != 0) |
| 407 | return CS_BAD_OFFSET; |
| 408 | return CS_SUCCESS; |
| 409 | } /* pcmcia_map_mem_page */ |
| 410 | EXPORT_SYMBOL(pcmcia_map_mem_page); |
| 411 | |
| 412 | |
| 413 | /** pcmcia_modify_configuration |
| 414 | * |
| 415 | * Modify a locked socket configuration |
| 416 | */ |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 417 | int pcmcia_modify_configuration(struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 418 | modconf_t *mod) |
| 419 | { |
| 420 | struct pcmcia_socket *s; |
| 421 | config_t *c; |
| 422 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 423 | s = p_dev->socket; |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 424 | c = p_dev->function_config; |
| 425 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 426 | if (!(s->state & SOCKET_PRESENT)) |
| 427 | return CS_NO_CARD; |
| 428 | if (!(c->state & CONFIG_LOCKED)) |
| 429 | return CS_CONFIGURATION_LOCKED; |
| 430 | |
| 431 | if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { |
| 432 | if (mod->Attributes & CONF_ENABLE_IRQ) { |
| 433 | c->Attributes |= CONF_ENABLE_IRQ; |
| 434 | s->socket.io_irq = s->irq.AssignedIRQ; |
| 435 | } else { |
| 436 | c->Attributes &= ~CONF_ENABLE_IRQ; |
| 437 | s->socket.io_irq = 0; |
| 438 | } |
| 439 | s->ops->set_socket(s, &s->socket); |
| 440 | } |
| 441 | |
| 442 | if (mod->Attributes & CONF_VCC_CHANGE_VALID) |
| 443 | return CS_BAD_VCC; |
| 444 | |
| 445 | /* We only allow changing Vpp1 and Vpp2 to the same value */ |
| 446 | if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && |
| 447 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
| 448 | if (mod->Vpp1 != mod->Vpp2) |
| 449 | return CS_BAD_VPP; |
Dominik Brodowski | 71ed90d | 2005-09-09 13:03:27 -0700 | [diff] [blame] | 450 | s->socket.Vpp = mod->Vpp1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 451 | if (s->ops->set_socket(s, &s->socket)) |
| 452 | return CS_BAD_VPP; |
| 453 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || |
| 454 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) |
| 455 | return CS_BAD_VPP; |
| 456 | |
Dominik Brodowski | 4bbed52 | 2006-01-15 11:18:12 +0100 | [diff] [blame] | 457 | if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { |
| 458 | pccard_io_map io_off = { 0, 0, 0, 0, 1 }; |
| 459 | pccard_io_map io_on; |
| 460 | int i; |
| 461 | |
| 462 | io_on.speed = io_speed; |
| 463 | for (i = 0; i < MAX_IO_WIN; i++) { |
| 464 | if (!s->io[i].res) |
| 465 | continue; |
| 466 | io_off.map = i; |
| 467 | io_on.map = i; |
| 468 | |
| 469 | io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8; |
| 470 | io_on.start = s->io[i].res->start; |
| 471 | io_on.stop = s->io[i].res->end; |
| 472 | |
| 473 | s->ops->set_io_map(s, &io_off); |
| 474 | mdelay(40); |
| 475 | s->ops->set_io_map(s, &io_on); |
| 476 | } |
| 477 | } |
| 478 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 479 | return CS_SUCCESS; |
| 480 | } /* modify_configuration */ |
| 481 | EXPORT_SYMBOL(pcmcia_modify_configuration); |
| 482 | |
| 483 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 484 | int pcmcia_release_configuration(struct pcmcia_device *p_dev) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 485 | { |
| 486 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 487 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 488 | config_t *c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 489 | int i; |
| 490 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 491 | if (p_dev->_locked) { |
| 492 | p_dev->_locked = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 493 | if (--(s->lock_count) == 0) { |
| 494 | s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ |
| 495 | s->socket.Vpp = 0; |
| 496 | s->socket.io_irq = 0; |
| 497 | s->ops->set_socket(s, &s->socket); |
| 498 | } |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 499 | } |
| 500 | if (c->state & CONFIG_LOCKED) { |
| 501 | c->state &= ~CONFIG_LOCKED; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 502 | if (c->state & CONFIG_IO_REQ) |
| 503 | for (i = 0; i < MAX_IO_WIN; i++) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 504 | if (!s->io[i].res) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 505 | continue; |
| 506 | s->io[i].Config--; |
| 507 | if (s->io[i].Config != 0) |
| 508 | continue; |
| 509 | io.map = i; |
| 510 | s->ops->set_io_map(s, &io); |
| 511 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | return CS_SUCCESS; |
| 515 | } /* pcmcia_release_configuration */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 516 | |
| 517 | |
| 518 | /** pcmcia_release_io |
| 519 | * |
| 520 | * Release_io() releases the I/O ranges allocated by a client. This |
| 521 | * may be invoked some time after a card ejection has already dumped |
| 522 | * the actual socket configuration, so if the client is "stale", we |
| 523 | * don't bother checking the port ranges against the current socket |
| 524 | * values. |
| 525 | */ |
Adrian Bunk | b4c8840 | 2006-01-18 23:53:13 -0800 | [diff] [blame] | 526 | static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 527 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 528 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 529 | config_t *c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 530 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 531 | if (!p_dev->_io ) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 532 | return CS_BAD_HANDLE; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 533 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 534 | p_dev->_io = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 535 | |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 536 | if ((c->io.BasePort1 != req->BasePort1) || |
| 537 | (c->io.NumPorts1 != req->NumPorts1) || |
| 538 | (c->io.BasePort2 != req->BasePort2) || |
| 539 | (c->io.NumPorts2 != req->NumPorts2)) |
| 540 | return CS_BAD_ARGS; |
| 541 | |
| 542 | c->state &= ~CONFIG_IO_REQ; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 543 | |
| 544 | release_io_space(s, req->BasePort1, req->NumPorts1); |
| 545 | if (req->NumPorts2) |
| 546 | release_io_space(s, req->BasePort2, req->NumPorts2); |
| 547 | |
| 548 | return CS_SUCCESS; |
| 549 | } /* pcmcia_release_io */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 550 | |
| 551 | |
Adrian Bunk | b4c8840 | 2006-01-18 23:53:13 -0800 | [diff] [blame] | 552 | static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 553 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 554 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 555 | config_t *c= p_dev->function_config; |
| 556 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 557 | if (!p_dev->_irq) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 558 | return CS_BAD_HANDLE; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 559 | p_dev->_irq = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 560 | |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 561 | if (c->state & CONFIG_LOCKED) |
| 562 | return CS_CONFIGURATION_LOCKED; |
| 563 | if (c->irq.Attributes != req->Attributes) |
| 564 | return CS_BAD_ATTRIBUTE; |
| 565 | if (s->irq.AssignedIRQ != req->AssignedIRQ) |
| 566 | return CS_BAD_IRQ; |
| 567 | if (--s->irq.Config == 0) { |
| 568 | c->state &= ~CONFIG_IRQ_REQ; |
| 569 | s->irq.AssignedIRQ = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | if (req->Attributes & IRQ_HANDLE_PRESENT) { |
| 573 | free_irq(req->AssignedIRQ, req->Instance); |
| 574 | } |
| 575 | |
| 576 | #ifdef CONFIG_PCMCIA_PROBE |
| 577 | pcmcia_used_irq[req->AssignedIRQ]--; |
| 578 | #endif |
| 579 | |
| 580 | return CS_SUCCESS; |
| 581 | } /* pcmcia_release_irq */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 582 | |
| 583 | |
| 584 | int pcmcia_release_window(window_handle_t win) |
| 585 | { |
| 586 | struct pcmcia_socket *s; |
| 587 | |
| 588 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
| 589 | return CS_BAD_HANDLE; |
| 590 | s = win->sock; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 591 | if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 592 | return CS_BAD_HANDLE; |
| 593 | |
| 594 | /* Shut down memory window */ |
| 595 | win->ctl.flags &= ~MAP_ACTIVE; |
| 596 | s->ops->set_mem_map(s, &win->ctl); |
| 597 | s->state &= ~SOCKET_WIN_REQ(win->index); |
| 598 | |
| 599 | /* Release system memory */ |
| 600 | if (win->ctl.res) { |
| 601 | release_resource(win->ctl.res); |
| 602 | kfree(win->ctl.res); |
| 603 | win->ctl.res = NULL; |
| 604 | } |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 605 | win->handle->_win &= ~CLIENT_WIN_REQ(win->index); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 606 | |
| 607 | win->magic = 0; |
| 608 | |
| 609 | return CS_SUCCESS; |
| 610 | } /* pcmcia_release_window */ |
| 611 | EXPORT_SYMBOL(pcmcia_release_window); |
| 612 | |
| 613 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 614 | int pcmcia_request_configuration(struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 615 | config_req_t *req) |
| 616 | { |
| 617 | int i; |
| 618 | u_int base; |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 619 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 620 | config_t *c; |
| 621 | pccard_io_map iomap; |
| 622 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 623 | if (!(s->state & SOCKET_PRESENT)) |
| 624 | return CS_NO_CARD; |
| 625 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 626 | if (req->IntType & INT_CARDBUS) |
| 627 | return CS_UNSUPPORTED_MODE; |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 628 | c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 629 | if (c->state & CONFIG_LOCKED) |
| 630 | return CS_CONFIGURATION_LOCKED; |
| 631 | |
| 632 | /* Do power control. We don't allow changes in Vcc. */ |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 633 | s->socket.Vpp = req->Vpp; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 634 | if (s->ops->set_socket(s, &s->socket)) |
| 635 | return CS_BAD_VPP; |
| 636 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 637 | /* Pick memory or I/O card, DMA mode, interrupt */ |
| 638 | c->IntType = req->IntType; |
| 639 | c->Attributes = req->Attributes; |
| 640 | if (req->IntType & INT_MEMORY_AND_IO) |
| 641 | s->socket.flags |= SS_IOCARD; |
| 642 | if (req->IntType & INT_ZOOMED_VIDEO) |
| 643 | s->socket.flags |= SS_ZVCARD | SS_IOCARD; |
| 644 | if (req->Attributes & CONF_ENABLE_DMA) |
| 645 | s->socket.flags |= SS_DMA_MODE; |
| 646 | if (req->Attributes & CONF_ENABLE_SPKR) |
| 647 | s->socket.flags |= SS_SPKR_ENA; |
| 648 | if (req->Attributes & CONF_ENABLE_IRQ) |
| 649 | s->socket.io_irq = s->irq.AssignedIRQ; |
| 650 | else |
| 651 | s->socket.io_irq = 0; |
| 652 | s->ops->set_socket(s, &s->socket); |
| 653 | s->lock_count++; |
| 654 | |
| 655 | /* Set up CIS configuration registers */ |
| 656 | base = c->ConfigBase = req->ConfigBase; |
Dominik Brodowski | 1ae9c7d | 2006-01-10 20:40:40 +0100 | [diff] [blame] | 657 | c->CardValues = req->Present; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 658 | if (req->Present & PRESENT_COPY) { |
| 659 | c->Copy = req->Copy; |
| 660 | pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); |
| 661 | } |
| 662 | if (req->Present & PRESENT_OPTION) { |
| 663 | if (s->functions == 1) { |
| 664 | c->Option = req->ConfigIndex & COR_CONFIG_MASK; |
| 665 | } else { |
| 666 | c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK; |
| 667 | c->Option |= COR_FUNC_ENA|COR_IREQ_ENA; |
| 668 | if (req->Present & PRESENT_IOBASE_0) |
| 669 | c->Option |= COR_ADDR_DECODE; |
| 670 | } |
| 671 | if (c->state & CONFIG_IRQ_REQ) |
| 672 | if (!(c->irq.Attributes & IRQ_FORCED_PULSE)) |
| 673 | c->Option |= COR_LEVEL_REQ; |
| 674 | pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option); |
| 675 | mdelay(40); |
| 676 | } |
| 677 | if (req->Present & PRESENT_STATUS) { |
| 678 | c->Status = req->Status; |
| 679 | pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status); |
| 680 | } |
| 681 | if (req->Present & PRESENT_PIN_REPLACE) { |
| 682 | c->Pin = req->Pin; |
| 683 | pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin); |
| 684 | } |
| 685 | if (req->Present & PRESENT_EXT_STATUS) { |
| 686 | c->ExtStatus = req->ExtStatus; |
| 687 | pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus); |
| 688 | } |
| 689 | if (req->Present & PRESENT_IOBASE_0) { |
| 690 | u_char b = c->io.BasePort1 & 0xff; |
| 691 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); |
| 692 | b = (c->io.BasePort1 >> 8) & 0xff; |
| 693 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); |
| 694 | } |
| 695 | if (req->Present & PRESENT_IOSIZE) { |
| 696 | u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1; |
| 697 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); |
| 698 | } |
| 699 | |
| 700 | /* Configure I/O windows */ |
| 701 | if (c->state & CONFIG_IO_REQ) { |
| 702 | iomap.speed = io_speed; |
| 703 | for (i = 0; i < MAX_IO_WIN; i++) |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 704 | if (s->io[i].res) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 705 | iomap.map = i; |
| 706 | iomap.flags = MAP_ACTIVE; |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 707 | switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 708 | case IO_DATA_PATH_WIDTH_16: |
| 709 | iomap.flags |= MAP_16BIT; break; |
| 710 | case IO_DATA_PATH_WIDTH_AUTO: |
| 711 | iomap.flags |= MAP_AUTOSZ; break; |
| 712 | default: |
| 713 | break; |
| 714 | } |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 715 | iomap.start = s->io[i].res->start; |
| 716 | iomap.stop = s->io[i].res->end; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 717 | s->ops->set_io_map(s, &iomap); |
| 718 | s->io[i].Config++; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | c->state |= CONFIG_LOCKED; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 723 | p_dev->_locked = 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 724 | return CS_SUCCESS; |
| 725 | } /* pcmcia_request_configuration */ |
| 726 | EXPORT_SYMBOL(pcmcia_request_configuration); |
| 727 | |
| 728 | |
| 729 | /** pcmcia_request_io |
| 730 | * |
| 731 | * Request_io() reserves ranges of port addresses for a socket. |
| 732 | * I have not implemented range sharing or alias addressing. |
| 733 | */ |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 734 | int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 735 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 736 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 737 | config_t *c; |
| 738 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 739 | if (!(s->state & SOCKET_PRESENT)) |
| 740 | return CS_NO_CARD; |
| 741 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 742 | if (!req) |
| 743 | return CS_UNSUPPORTED_MODE; |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 744 | c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 745 | if (c->state & CONFIG_LOCKED) |
| 746 | return CS_CONFIGURATION_LOCKED; |
| 747 | if (c->state & CONFIG_IO_REQ) |
| 748 | return CS_IN_USE; |
| 749 | if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) |
| 750 | return CS_BAD_ATTRIBUTE; |
| 751 | if ((req->NumPorts2 > 0) && |
| 752 | (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) |
| 753 | return CS_BAD_ATTRIBUTE; |
| 754 | |
| 755 | if (alloc_io_space(s, req->Attributes1, &req->BasePort1, |
| 756 | req->NumPorts1, req->IOAddrLines)) |
| 757 | return CS_IN_USE; |
| 758 | |
| 759 | if (req->NumPorts2) { |
| 760 | if (alloc_io_space(s, req->Attributes2, &req->BasePort2, |
| 761 | req->NumPorts2, req->IOAddrLines)) { |
| 762 | release_io_space(s, req->BasePort1, req->NumPorts1); |
| 763 | return CS_IN_USE; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | c->io = *req; |
| 768 | c->state |= CONFIG_IO_REQ; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 769 | p_dev->_io = 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 770 | return CS_SUCCESS; |
| 771 | } /* pcmcia_request_io */ |
| 772 | EXPORT_SYMBOL(pcmcia_request_io); |
| 773 | |
| 774 | |
| 775 | /** pcmcia_request_irq |
| 776 | * |
| 777 | * Request_irq() reserves an irq for this client. |
| 778 | * |
| 779 | * Also, since Linux only reserves irq's when they are actually |
| 780 | * hooked, we don't guarantee that an irq will still be available |
| 781 | * when the configuration is locked. Now that I think about it, |
| 782 | * there might be a way to fix this using a dummy handler. |
| 783 | */ |
| 784 | |
| 785 | #ifdef CONFIG_PCMCIA_PROBE |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 786 | static irqreturn_t test_action(int cpl, void *dev_id) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 787 | { |
| 788 | return IRQ_NONE; |
| 789 | } |
| 790 | #endif |
| 791 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 792 | int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 793 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 794 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 795 | config_t *c; |
| 796 | int ret = CS_IN_USE, irq = 0; |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 797 | int type; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 798 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 799 | if (!(s->state & SOCKET_PRESENT)) |
| 800 | return CS_NO_CARD; |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 801 | c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 802 | if (c->state & CONFIG_LOCKED) |
| 803 | return CS_CONFIGURATION_LOCKED; |
| 804 | if (c->state & CONFIG_IRQ_REQ) |
| 805 | return CS_IN_USE; |
| 806 | |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 807 | /* Decide what type of interrupt we are registering */ |
| 808 | type = 0; |
| 809 | if (s->functions > 1) /* All of this ought to be handled higher up */ |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 810 | type = IRQF_SHARED; |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 811 | if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 812 | type = IRQF_SHARED; |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 813 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 814 | #ifdef CONFIG_PCMCIA_PROBE |
| 815 | if (s->irq.AssignedIRQ != 0) { |
| 816 | /* If the interrupt is already assigned, it must be the same */ |
| 817 | irq = s->irq.AssignedIRQ; |
| 818 | } else { |
| 819 | int try; |
| 820 | u32 mask = s->irq_mask; |
Dominik Brodowski | a1b274f | 2005-07-28 01:07:27 -0700 | [diff] [blame] | 821 | void *data = &p_dev->dev.driver; /* something unique to this device */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 822 | |
| 823 | for (try = 0; try < 64; try++) { |
| 824 | irq = try % 32; |
| 825 | |
| 826 | /* marked as available by driver, and not blocked by userspace? */ |
| 827 | if (!((mask >> irq) & 1)) |
| 828 | continue; |
| 829 | |
| 830 | /* avoid an IRQ which is already used by a PCMCIA card */ |
| 831 | if ((try < 32) && pcmcia_used_irq[irq]) |
| 832 | continue; |
| 833 | |
| 834 | /* register the correct driver, if possible, of check whether |
| 835 | * registering a dummy handle works, i.e. if the IRQ isn't |
| 836 | * marked as used by the kernel resource management core */ |
| 837 | ret = request_irq(irq, |
| 838 | (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action, |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 839 | type, |
Brice Goglin | bd65a68 | 2005-09-09 13:03:29 -0700 | [diff] [blame] | 840 | p_dev->devname, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 841 | (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data); |
| 842 | if (!ret) { |
| 843 | if (!(req->Attributes & IRQ_HANDLE_PRESENT)) |
| 844 | free_irq(irq, data); |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | #endif |
Daniel Ritz | c181e0e | 2005-09-09 13:03:25 -0700 | [diff] [blame] | 850 | /* only assign PCI irq if no IRQ already assigned */ |
| 851 | if (ret && !s->irq.AssignedIRQ) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 852 | if (!s->pci_irq) |
| 853 | return ret; |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 854 | type = IRQF_SHARED; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 855 | irq = s->pci_irq; |
| 856 | } |
| 857 | |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 858 | if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) { |
| 859 | if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance)) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 860 | return CS_IN_USE; |
| 861 | } |
| 862 | |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 863 | /* Make sure the fact the request type was overridden is passed back */ |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 864 | if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) { |
Alan Cox | c533120 | 2006-05-16 16:16:44 +0100 | [diff] [blame] | 865 | req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING; |
| 866 | printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n"); |
| 867 | printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n"); |
| 868 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 869 | c->irq.Attributes = req->Attributes; |
| 870 | s->irq.AssignedIRQ = req->AssignedIRQ = irq; |
| 871 | s->irq.Config++; |
| 872 | |
| 873 | c->state |= CONFIG_IRQ_REQ; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 874 | p_dev->_irq = 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 875 | |
| 876 | #ifdef CONFIG_PCMCIA_PROBE |
| 877 | pcmcia_used_irq[irq]++; |
| 878 | #endif |
| 879 | |
| 880 | return CS_SUCCESS; |
| 881 | } /* pcmcia_request_irq */ |
| 882 | EXPORT_SYMBOL(pcmcia_request_irq); |
| 883 | |
| 884 | |
| 885 | /** pcmcia_request_window |
| 886 | * |
| 887 | * Request_window() establishes a mapping between card memory space |
| 888 | * and system memory space. |
| 889 | */ |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 890 | int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 891 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 892 | struct pcmcia_socket *s = (*p_dev)->socket; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 893 | window_t *win; |
| 894 | u_long align; |
| 895 | int w; |
| 896 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 897 | if (!(s->state & SOCKET_PRESENT)) |
| 898 | return CS_NO_CARD; |
| 899 | if (req->Attributes & (WIN_PAGED | WIN_SHARED)) |
| 900 | return CS_BAD_ATTRIBUTE; |
| 901 | |
| 902 | /* Window size defaults to smallest available */ |
| 903 | if (req->Size == 0) |
| 904 | req->Size = s->map_size; |
| 905 | align = (((s->features & SS_CAP_MEM_ALIGN) || |
| 906 | (req->Attributes & WIN_STRICT_ALIGN)) ? |
| 907 | req->Size : s->map_size); |
| 908 | if (req->Size & (s->map_size-1)) |
| 909 | return CS_BAD_SIZE; |
| 910 | if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || |
| 911 | (req->Base & (align-1))) |
| 912 | return CS_BAD_BASE; |
| 913 | if (req->Base) |
| 914 | align = 0; |
| 915 | |
| 916 | /* Allocate system memory window */ |
| 917 | for (w = 0; w < MAX_WIN; w++) |
| 918 | if (!(s->state & SOCKET_WIN_REQ(w))) break; |
| 919 | if (w == MAX_WIN) |
| 920 | return CS_OUT_OF_RESOURCE; |
| 921 | |
| 922 | win = &s->win[w]; |
| 923 | win->magic = WINDOW_MAGIC; |
| 924 | win->index = w; |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 925 | win->handle = *p_dev; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 926 | win->sock = s; |
| 927 | |
| 928 | if (!(s->features & SS_CAP_STATIC_MAP)) { |
| 929 | win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, |
| 930 | (req->Attributes & WIN_MAP_BELOW_1MB), s); |
| 931 | if (!win->ctl.res) |
| 932 | return CS_IN_USE; |
| 933 | } |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 934 | (*p_dev)->_win |= CLIENT_WIN_REQ(w); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 935 | |
| 936 | /* Configure the socket controller */ |
| 937 | win->ctl.map = w+1; |
| 938 | win->ctl.flags = 0; |
| 939 | win->ctl.speed = req->AccessSpeed; |
| 940 | if (req->Attributes & WIN_MEMORY_TYPE) |
| 941 | win->ctl.flags |= MAP_ATTRIB; |
| 942 | if (req->Attributes & WIN_ENABLE) |
| 943 | win->ctl.flags |= MAP_ACTIVE; |
| 944 | if (req->Attributes & WIN_DATA_WIDTH_16) |
| 945 | win->ctl.flags |= MAP_16BIT; |
| 946 | if (req->Attributes & WIN_USE_WAIT) |
| 947 | win->ctl.flags |= MAP_USE_WAIT; |
| 948 | win->ctl.card_start = 0; |
| 949 | if (s->ops->set_mem_map(s, &win->ctl) != 0) |
| 950 | return CS_BAD_ARGS; |
| 951 | s->state |= SOCKET_WIN_REQ(w); |
| 952 | |
| 953 | /* Return window handle */ |
| 954 | if (s->features & SS_CAP_STATIC_MAP) { |
| 955 | req->Base = win->ctl.static_start; |
| 956 | } else { |
| 957 | req->Base = win->ctl.res->start; |
| 958 | } |
| 959 | *wh = win; |
| 960 | |
| 961 | return CS_SUCCESS; |
| 962 | } /* pcmcia_request_window */ |
| 963 | EXPORT_SYMBOL(pcmcia_request_window); |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 964 | |
| 965 | void pcmcia_disable_device(struct pcmcia_device *p_dev) { |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 966 | pcmcia_release_configuration(p_dev); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 967 | pcmcia_release_io(p_dev, &p_dev->io); |
| 968 | pcmcia_release_irq(p_dev, &p_dev->irq); |
| 969 | if (&p_dev->win) |
| 970 | pcmcia_release_window(p_dev->win); |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 971 | } |
| 972 | EXPORT_SYMBOL(pcmcia_disable_device); |