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