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