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