blob: 0ce39de834c477785a0b04ba580c80cffc4dd41e [file] [log] [blame]
Dominik Brodowski1a8d4662005-06-27 16:28:53 -07001/*
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 Brodowski1a8d4662005-06-27 16:28:53 -070017#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/interrupt.h>
20#include <linux/delay.h>
21#include <linux/pci.h>
22#include <linux/device.h>
23
24#define IN_CARD_SERVICES
Dominik Brodowski1a8d4662005-06-27 16:28:53 -070025#include <pcmcia/cs_types.h>
26#include <pcmcia/ss.h>
27#include <pcmcia/cs.h>
28#include <pcmcia/bulkmem.h>
29#include <pcmcia/cistpl.h>
30#include <pcmcia/cisreg.h>
31#include <pcmcia/ds.h>
32
33#include "cs_internal.h"
34#include "ds_internal.h"
35
36
Dominik Brodowski1a8d4662005-06-27 16:28:53 -070037/* Access speed for IO windows */
38static int io_speed = 0;
39module_param(io_speed, int, 0444);
40
41
42#ifdef CONFIG_PCMCIA_PROBE
Al Viro531e5ca2005-08-23 22:47:01 +010043#include <asm/irq.h>
Dominik Brodowski1a8d4662005-06-27 16:28:53 -070044/* mask of IRQs already reserved by other cards, we should avoid using them */
45static u8 pcmcia_used_irq[NR_IRQS];
46#endif
47
48
49#ifdef DEBUG
50extern int ds_pc_debug;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -070051
52#define ds_dbg(skt, lvl, fmt, arg...) do { \
53 if (ds_pc_debug >= lvl) \
54 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
55 cs_socket_name(skt) , ## arg); \
56} while (0)
57#else
58#define ds_dbg(lvl, fmt, arg...) do { } while (0)
59#endif
60
61
62
63/** alloc_io_space
64 *
65 * Special stuff for managing IO windows, because they are scarce
66 */
67
68static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
69 ioaddr_t num, u_int lines)
70{
71 int i;
72 kio_addr_t try, align;
73
74 align = (*base) ? (lines ? 1<<lines : 0) : 1;
75 if (align && (align < num)) {
76 if (*base) {
77 ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
78 num, align);
79 align = 0;
80 } else
81 while (align && (align < num)) align <<= 1;
82 }
83 if (*base & ~(align-1)) {
84 ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
85 *base, align);
86 align = 0;
87 }
88 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
89 *base = s->io_offset | (*base & 0x0fff);
90 return 0;
91 }
92 /* Check for an already-allocated window that must conflict with
93 * what was asked for. It is a hack because it does not catch all
94 * potential conflicts, just the most obvious ones.
95 */
96 for (i = 0; i < MAX_IO_WIN; i++)
Kaustav Majumdar4708b5f2006-10-20 14:44:09 -070097 if ((s->io[i].res) && *base &&
Dominik Brodowskic7d00692006-01-15 08:04:43 +010098 ((s->io[i].res->start & (align-1)) == *base))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -070099 return 1;
100 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100101 if (!s->io[i].res) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700102 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
103 if (s->io[i].res) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100104 *base = s->io[i].res->start;
105 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
106 s->io[i].InUse = num;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700107 break;
108 } else
109 return 1;
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100110 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700111 continue;
112 /* Try to extend top of window */
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100113 try = s->io[i].res->end + 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700114 if ((*base == 0) || (*base == try))
115 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
116 s->io[i].res->end + num, s) == 0) {
117 *base = try;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700118 s->io[i].InUse += num;
119 break;
120 }
121 /* Try to extend bottom of window */
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100122 try = s->io[i].res->start - num;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700123 if ((*base == 0) || (*base == try))
124 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
125 s->io[i].res->end, s) == 0) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100126 *base = try;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700127 s->io[i].InUse += num;
128 break;
129 }
130 }
131 return (i == MAX_IO_WIN);
132} /* alloc_io_space */
133
134
135static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
136 ioaddr_t num)
137{
138 int i;
139
140 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100141 if (!s->io[i].res)
142 continue;
143 if ((s->io[i].res->start <= base) &&
144 (s->io[i].res->end >= base+num-1)) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700145 s->io[i].InUse -= num;
146 /* Free the window if no one else is using it */
147 if (s->io[i].InUse == 0) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700148 release_resource(s->io[i].res);
149 kfree(s->io[i].res);
150 s->io[i].res = NULL;
151 }
152 }
153 }
154} /* release_io_space */
155
156
157/** pccard_access_configuration_register
158 *
159 * Access_configuration_register() reads and writes configuration
160 * registers in attribute memory. Memory window 0 is reserved for
161 * this and the tuple reading services.
162 */
163
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100164int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700165 conf_reg_t *reg)
166{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100167 struct pcmcia_socket *s;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700168 config_t *c;
169 int addr;
170 u_char val;
171
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100172 if (!p_dev || !p_dev->function_config)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700173 return CS_NO_CARD;
174
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100175 s = p_dev->socket;
176 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700177
178 if (!(c->state & CONFIG_LOCKED))
179 return CS_CONFIGURATION_LOCKED;
180
181 addr = (c->ConfigBase + reg->Offset) >> 1;
182
183 switch (reg->Action) {
184 case CS_READ:
185 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
186 reg->Value = val;
187 break;
188 case CS_WRITE:
189 val = reg->Value;
190 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
191 break;
192 default:
193 return CS_BAD_ARGS;
194 break;
195 }
196 return CS_SUCCESS;
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100197} /* pcmcia_access_configuration_register */
Dominik Brodowski34481392005-06-27 16:28:54 -0700198EXPORT_SYMBOL(pcmcia_access_configuration_register);
199
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700200
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700201int pccard_get_configuration_info(struct pcmcia_socket *s,
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100202 struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700203 config_info_t *config)
204{
205 config_t *c;
206
207 if (!(s->state & SOCKET_PRESENT))
208 return CS_NO_CARD;
209
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700210
211#ifdef CONFIG_CARDBUS
212 if (s->state & SOCKET_CARDBUS) {
213 memset(config, 0, sizeof(config_info_t));
214 config->Vcc = s->socket.Vcc;
215 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
216 config->Option = s->cb_dev->subordinate->number;
217 if (s->state & SOCKET_CARDBUS_CONFIG) {
218 config->Attributes = CONF_VALID_CLIENT;
219 config->IntType = INT_CARDBUS;
220 config->AssignedIRQ = s->irq.AssignedIRQ;
221 if (config->AssignedIRQ)
222 config->Attributes |= CONF_ENABLE_IRQ;
Daniel Ritz48b950f2006-04-14 17:42:13 +0200223 if (s->io[0].res) {
224 config->BasePort1 = s->io[0].res->start;
225 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
226 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700227 }
228 return CS_SUCCESS;
229 }
230#endif
231
Daniel Ritz48b950f2006-04-14 17:42:13 +0200232 if (p_dev) {
233 c = p_dev->function_config;
234 config->Function = p_dev->func;
235 } else {
236 c = NULL;
237 config->Function = 0;
238 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700239
240 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
241 config->Attributes = 0;
242 config->Vcc = s->socket.Vcc;
243 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
244 return CS_SUCCESS;
245 }
246
Daniel Ritz47a31972006-07-30 03:03:49 -0700247 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
248 config->Vcc = s->socket.Vcc;
249 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
250 config->IntType = c->IntType;
251 config->ConfigBase = c->ConfigBase;
252 config->Status = c->Status;
253 config->Pin = c->Pin;
254 config->Copy = c->Copy;
255 config->Option = c->Option;
256 config->ExtStatus = c->ExtStatus;
257 config->Present = config->CardValues = c->CardValues;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700258 config->IRQAttributes = c->irq.Attributes;
259 config->AssignedIRQ = s->irq.AssignedIRQ;
260 config->BasePort1 = c->io.BasePort1;
261 config->NumPorts1 = c->io.NumPorts1;
262 config->Attributes1 = c->io.Attributes1;
263 config->BasePort2 = c->io.BasePort2;
264 config->NumPorts2 = c->io.NumPorts2;
265 config->Attributes2 = c->io.Attributes2;
266 config->IOAddrLines = c->io.IOAddrLines;
267
268 return CS_SUCCESS;
269} /* pccard_get_configuration_info */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700270
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700271int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
Dominik Brodowski34481392005-06-27 16:28:54 -0700272 config_info_t *config)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700273{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100274 return pccard_get_configuration_info(p_dev->socket, p_dev,
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700275 config);
Dominik Brodowski34481392005-06-27 16:28:54 -0700276}
277EXPORT_SYMBOL(pcmcia_get_configuration_info);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700278
279
280/** pcmcia_get_window
281 */
282int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
283 int idx, win_req_t *req)
284{
285 window_t *win;
286 int w;
287
288 if (!s || !(s->state & SOCKET_PRESENT))
289 return CS_NO_CARD;
290 for (w = idx; w < MAX_WIN; w++)
291 if (s->state & SOCKET_WIN_REQ(w))
292 break;
293 if (w == MAX_WIN)
294 return CS_NO_MORE_ITEMS;
295 win = &s->win[w];
296 req->Base = win->ctl.res->start;
297 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
298 req->AccessSpeed = win->ctl.speed;
299 req->Attributes = 0;
300 if (win->ctl.flags & MAP_ATTRIB)
301 req->Attributes |= WIN_MEMORY_TYPE_AM;
302 if (win->ctl.flags & MAP_ACTIVE)
303 req->Attributes |= WIN_ENABLE;
304 if (win->ctl.flags & MAP_16BIT)
305 req->Attributes |= WIN_DATA_WIDTH_16;
306 if (win->ctl.flags & MAP_USE_WAIT)
307 req->Attributes |= WIN_USE_WAIT;
308 *handle = win;
309 return CS_SUCCESS;
310} /* pcmcia_get_window */
311EXPORT_SYMBOL(pcmcia_get_window);
312
313
314/** pccard_get_status
315 *
316 * Get the current socket state bits. We don't support the latched
317 * SocketState yet: I haven't seen any point for it.
318 */
319
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100320int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700321 cs_status_t *status)
322{
323 config_t *c;
324 int val;
325
326 s->ops->get_status(s, &val);
327 status->CardState = status->SocketState = 0;
328 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
329 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
330 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
331 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
332 if (s->state & SOCKET_SUSPEND)
333 status->CardState |= CS_EVENT_PM_SUSPEND;
334 if (!(s->state & SOCKET_PRESENT))
335 return CS_NO_CARD;
336
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100337 c = (p_dev) ? p_dev->function_config : NULL;
338
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700339 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
340 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
341 u_char reg;
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100342 if (c->CardValues & PRESENT_PIN_REPLACE) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700343 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
344 status->CardState |=
345 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
346 status->CardState |=
347 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
348 status->CardState |=
349 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
350 status->CardState |=
351 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
352 } else {
353 /* No PRR? Then assume we're always ready */
354 status->CardState |= CS_EVENT_READY_CHANGE;
355 }
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100356 if (c->CardValues & PRESENT_EXT_STATUS) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700357 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
358 status->CardState |=
359 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
360 }
361 return CS_SUCCESS;
362 }
363 status->CardState |=
364 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
365 status->CardState |=
366 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
367 status->CardState |=
368 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
369 status->CardState |=
370 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
371 return CS_SUCCESS;
372} /* pccard_get_status */
Dominik Brodowski34481392005-06-27 16:28:54 -0700373
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100374int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status)
Dominik Brodowski34481392005-06-27 16:28:54 -0700375{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100376 return pccard_get_status(p_dev->socket, p_dev, status);
Dominik Brodowski34481392005-06-27 16:28:54 -0700377}
378EXPORT_SYMBOL(pcmcia_get_status);
379
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700380
381
382/** pcmcia_get_mem_page
383 *
384 * Change the card address of an already open memory window.
385 */
386int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
387{
388 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
389 return CS_BAD_HANDLE;
390 req->Page = 0;
391 req->CardOffset = win->ctl.card_start;
392 return CS_SUCCESS;
393} /* pcmcia_get_mem_page */
394EXPORT_SYMBOL(pcmcia_get_mem_page);
395
396
397int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
398{
399 struct pcmcia_socket *s;
400 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
401 return CS_BAD_HANDLE;
402 if (req->Page != 0)
403 return CS_BAD_PAGE;
404 s = win->sock;
405 win->ctl.card_start = req->CardOffset;
406 if (s->ops->set_mem_map(s, &win->ctl) != 0)
407 return CS_BAD_OFFSET;
408 return CS_SUCCESS;
409} /* pcmcia_map_mem_page */
410EXPORT_SYMBOL(pcmcia_map_mem_page);
411
412
413/** pcmcia_modify_configuration
414 *
415 * Modify a locked socket configuration
416 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700417int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700418 modconf_t *mod)
419{
420 struct pcmcia_socket *s;
421 config_t *c;
422
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700423 s = p_dev->socket;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100424 c = p_dev->function_config;
425
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700426 if (!(s->state & SOCKET_PRESENT))
427 return CS_NO_CARD;
428 if (!(c->state & CONFIG_LOCKED))
429 return CS_CONFIGURATION_LOCKED;
430
431 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
432 if (mod->Attributes & CONF_ENABLE_IRQ) {
433 c->Attributes |= CONF_ENABLE_IRQ;
434 s->socket.io_irq = s->irq.AssignedIRQ;
435 } else {
436 c->Attributes &= ~CONF_ENABLE_IRQ;
437 s->socket.io_irq = 0;
438 }
439 s->ops->set_socket(s, &s->socket);
440 }
441
442 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
443 return CS_BAD_VCC;
444
445 /* We only allow changing Vpp1 and Vpp2 to the same value */
446 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
447 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
448 if (mod->Vpp1 != mod->Vpp2)
449 return CS_BAD_VPP;
Dominik Brodowski71ed90d2005-09-09 13:03:27 -0700450 s->socket.Vpp = mod->Vpp1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700451 if (s->ops->set_socket(s, &s->socket))
452 return CS_BAD_VPP;
453 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
454 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
455 return CS_BAD_VPP;
456
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100457 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
458 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
459 pccard_io_map io_on;
460 int i;
461
462 io_on.speed = io_speed;
463 for (i = 0; i < MAX_IO_WIN; i++) {
464 if (!s->io[i].res)
465 continue;
466 io_off.map = i;
467 io_on.map = i;
468
469 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
470 io_on.start = s->io[i].res->start;
471 io_on.stop = s->io[i].res->end;
472
473 s->ops->set_io_map(s, &io_off);
474 mdelay(40);
475 s->ops->set_io_map(s, &io_on);
476 }
477 }
478
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700479 return CS_SUCCESS;
480} /* modify_configuration */
481EXPORT_SYMBOL(pcmcia_modify_configuration);
482
483
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700484int pcmcia_release_configuration(struct pcmcia_device *p_dev)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700485{
486 pccard_io_map io = { 0, 0, 0, 0, 1 };
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700487 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100488 config_t *c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700489 int i;
490
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100491 if (p_dev->_locked) {
492 p_dev->_locked = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700493 if (--(s->lock_count) == 0) {
494 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
495 s->socket.Vpp = 0;
496 s->socket.io_irq = 0;
497 s->ops->set_socket(s, &s->socket);
498 }
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100499 }
500 if (c->state & CONFIG_LOCKED) {
501 c->state &= ~CONFIG_LOCKED;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700502 if (c->state & CONFIG_IO_REQ)
503 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100504 if (!s->io[i].res)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700505 continue;
506 s->io[i].Config--;
507 if (s->io[i].Config != 0)
508 continue;
509 io.map = i;
510 s->ops->set_io_map(s, &io);
511 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700512 }
513
514 return CS_SUCCESS;
515} /* pcmcia_release_configuration */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700516
517
518/** pcmcia_release_io
519 *
520 * Release_io() releases the I/O ranges allocated by a client. This
521 * may be invoked some time after a card ejection has already dumped
522 * the actual socket configuration, so if the client is "stale", we
523 * don't bother checking the port ranges against the current socket
524 * values.
525 */
Adrian Bunkb4c88402006-01-18 23:53:13 -0800526static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700527{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700528 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100529 config_t *c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700530
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100531 if (!p_dev->_io )
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700532 return CS_BAD_HANDLE;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100533
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100534 p_dev->_io = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700535
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100536 if ((c->io.BasePort1 != req->BasePort1) ||
537 (c->io.NumPorts1 != req->NumPorts1) ||
538 (c->io.BasePort2 != req->BasePort2) ||
539 (c->io.NumPorts2 != req->NumPorts2))
540 return CS_BAD_ARGS;
541
542 c->state &= ~CONFIG_IO_REQ;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700543
544 release_io_space(s, req->BasePort1, req->NumPorts1);
545 if (req->NumPorts2)
546 release_io_space(s, req->BasePort2, req->NumPorts2);
547
548 return CS_SUCCESS;
549} /* pcmcia_release_io */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700550
551
Adrian Bunkb4c88402006-01-18 23:53:13 -0800552static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700553{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700554 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100555 config_t *c= p_dev->function_config;
556
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100557 if (!p_dev->_irq)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700558 return CS_BAD_HANDLE;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100559 p_dev->_irq = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700560
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100561 if (c->state & CONFIG_LOCKED)
562 return CS_CONFIGURATION_LOCKED;
563 if (c->irq.Attributes != req->Attributes)
564 return CS_BAD_ATTRIBUTE;
565 if (s->irq.AssignedIRQ != req->AssignedIRQ)
566 return CS_BAD_IRQ;
567 if (--s->irq.Config == 0) {
568 c->state &= ~CONFIG_IRQ_REQ;
569 s->irq.AssignedIRQ = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700570 }
571
572 if (req->Attributes & IRQ_HANDLE_PRESENT) {
573 free_irq(req->AssignedIRQ, req->Instance);
574 }
575
576#ifdef CONFIG_PCMCIA_PROBE
577 pcmcia_used_irq[req->AssignedIRQ]--;
578#endif
579
580 return CS_SUCCESS;
581} /* pcmcia_release_irq */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700582
583
584int pcmcia_release_window(window_handle_t win)
585{
586 struct pcmcia_socket *s;
587
588 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
589 return CS_BAD_HANDLE;
590 s = win->sock;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100591 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700592 return CS_BAD_HANDLE;
593
594 /* Shut down memory window */
595 win->ctl.flags &= ~MAP_ACTIVE;
596 s->ops->set_mem_map(s, &win->ctl);
597 s->state &= ~SOCKET_WIN_REQ(win->index);
598
599 /* Release system memory */
600 if (win->ctl.res) {
601 release_resource(win->ctl.res);
602 kfree(win->ctl.res);
603 win->ctl.res = NULL;
604 }
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100605 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700606
607 win->magic = 0;
608
609 return CS_SUCCESS;
610} /* pcmcia_release_window */
611EXPORT_SYMBOL(pcmcia_release_window);
612
613
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700614int pcmcia_request_configuration(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700615 config_req_t *req)
616{
617 int i;
618 u_int base;
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700619 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700620 config_t *c;
621 pccard_io_map iomap;
622
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700623 if (!(s->state & SOCKET_PRESENT))
624 return CS_NO_CARD;
625
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700626 if (req->IntType & INT_CARDBUS)
627 return CS_UNSUPPORTED_MODE;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100628 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700629 if (c->state & CONFIG_LOCKED)
630 return CS_CONFIGURATION_LOCKED;
631
632 /* Do power control. We don't allow changes in Vcc. */
Dominik Brodowski70294b42006-01-15 12:43:16 +0100633 s->socket.Vpp = req->Vpp;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700634 if (s->ops->set_socket(s, &s->socket))
635 return CS_BAD_VPP;
636
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700637 /* Pick memory or I/O card, DMA mode, interrupt */
638 c->IntType = req->IntType;
639 c->Attributes = req->Attributes;
640 if (req->IntType & INT_MEMORY_AND_IO)
641 s->socket.flags |= SS_IOCARD;
642 if (req->IntType & INT_ZOOMED_VIDEO)
643 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
644 if (req->Attributes & CONF_ENABLE_DMA)
645 s->socket.flags |= SS_DMA_MODE;
646 if (req->Attributes & CONF_ENABLE_SPKR)
647 s->socket.flags |= SS_SPKR_ENA;
648 if (req->Attributes & CONF_ENABLE_IRQ)
649 s->socket.io_irq = s->irq.AssignedIRQ;
650 else
651 s->socket.io_irq = 0;
652 s->ops->set_socket(s, &s->socket);
653 s->lock_count++;
654
655 /* Set up CIS configuration registers */
656 base = c->ConfigBase = req->ConfigBase;
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100657 c->CardValues = req->Present;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700658 if (req->Present & PRESENT_COPY) {
659 c->Copy = req->Copy;
660 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
661 }
662 if (req->Present & PRESENT_OPTION) {
663 if (s->functions == 1) {
664 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
665 } else {
666 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
667 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
668 if (req->Present & PRESENT_IOBASE_0)
669 c->Option |= COR_ADDR_DECODE;
670 }
671 if (c->state & CONFIG_IRQ_REQ)
672 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
673 c->Option |= COR_LEVEL_REQ;
674 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
675 mdelay(40);
676 }
677 if (req->Present & PRESENT_STATUS) {
678 c->Status = req->Status;
679 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
680 }
681 if (req->Present & PRESENT_PIN_REPLACE) {
682 c->Pin = req->Pin;
683 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
684 }
685 if (req->Present & PRESENT_EXT_STATUS) {
686 c->ExtStatus = req->ExtStatus;
687 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
688 }
689 if (req->Present & PRESENT_IOBASE_0) {
690 u_char b = c->io.BasePort1 & 0xff;
691 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
692 b = (c->io.BasePort1 >> 8) & 0xff;
693 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
694 }
695 if (req->Present & PRESENT_IOSIZE) {
696 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
697 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
698 }
699
700 /* Configure I/O windows */
701 if (c->state & CONFIG_IO_REQ) {
702 iomap.speed = io_speed;
703 for (i = 0; i < MAX_IO_WIN; i++)
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100704 if (s->io[i].res) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700705 iomap.map = i;
706 iomap.flags = MAP_ACTIVE;
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100707 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700708 case IO_DATA_PATH_WIDTH_16:
709 iomap.flags |= MAP_16BIT; break;
710 case IO_DATA_PATH_WIDTH_AUTO:
711 iomap.flags |= MAP_AUTOSZ; break;
712 default:
713 break;
714 }
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100715 iomap.start = s->io[i].res->start;
716 iomap.stop = s->io[i].res->end;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700717 s->ops->set_io_map(s, &iomap);
718 s->io[i].Config++;
719 }
720 }
721
722 c->state |= CONFIG_LOCKED;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100723 p_dev->_locked = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700724 return CS_SUCCESS;
725} /* pcmcia_request_configuration */
726EXPORT_SYMBOL(pcmcia_request_configuration);
727
728
729/** pcmcia_request_io
730 *
731 * Request_io() reserves ranges of port addresses for a socket.
732 * I have not implemented range sharing or alias addressing.
733 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700734int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700735{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700736 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700737 config_t *c;
738
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700739 if (!(s->state & SOCKET_PRESENT))
740 return CS_NO_CARD;
741
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700742 if (!req)
743 return CS_UNSUPPORTED_MODE;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100744 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700745 if (c->state & CONFIG_LOCKED)
746 return CS_CONFIGURATION_LOCKED;
747 if (c->state & CONFIG_IO_REQ)
748 return CS_IN_USE;
749 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
750 return CS_BAD_ATTRIBUTE;
751 if ((req->NumPorts2 > 0) &&
752 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
753 return CS_BAD_ATTRIBUTE;
754
755 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
756 req->NumPorts1, req->IOAddrLines))
757 return CS_IN_USE;
758
759 if (req->NumPorts2) {
760 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
761 req->NumPorts2, req->IOAddrLines)) {
762 release_io_space(s, req->BasePort1, req->NumPorts1);
763 return CS_IN_USE;
764 }
765 }
766
767 c->io = *req;
768 c->state |= CONFIG_IO_REQ;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100769 p_dev->_io = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700770 return CS_SUCCESS;
771} /* pcmcia_request_io */
772EXPORT_SYMBOL(pcmcia_request_io);
773
774
775/** pcmcia_request_irq
776 *
777 * Request_irq() reserves an irq for this client.
778 *
779 * Also, since Linux only reserves irq's when they are actually
780 * hooked, we don't guarantee that an irq will still be available
781 * when the configuration is locked. Now that I think about it,
782 * there might be a way to fix this using a dummy handler.
783 */
784
785#ifdef CONFIG_PCMCIA_PROBE
David Howells7d12e782006-10-05 14:55:46 +0100786static irqreturn_t test_action(int cpl, void *dev_id)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700787{
788 return IRQ_NONE;
789}
790#endif
791
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700792int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700793{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700794 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700795 config_t *c;
796 int ret = CS_IN_USE, irq = 0;
Alan Coxc5331202006-05-16 16:16:44 +0100797 int type;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700798
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700799 if (!(s->state & SOCKET_PRESENT))
800 return CS_NO_CARD;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100801 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700802 if (c->state & CONFIG_LOCKED)
803 return CS_CONFIGURATION_LOCKED;
804 if (c->state & CONFIG_IRQ_REQ)
805 return CS_IN_USE;
806
Alan Coxc5331202006-05-16 16:16:44 +0100807 /* Decide what type of interrupt we are registering */
808 type = 0;
809 if (s->functions > 1) /* All of this ought to be handled higher up */
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700810 type = IRQF_SHARED;
Alan Coxc5331202006-05-16 16:16:44 +0100811 if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700812 type = IRQF_SHARED;
Alan Coxc5331202006-05-16 16:16:44 +0100813
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700814#ifdef CONFIG_PCMCIA_PROBE
815 if (s->irq.AssignedIRQ != 0) {
816 /* If the interrupt is already assigned, it must be the same */
817 irq = s->irq.AssignedIRQ;
818 } else {
819 int try;
820 u32 mask = s->irq_mask;
Dominik Brodowskia1b274f2005-07-28 01:07:27 -0700821 void *data = &p_dev->dev.driver; /* something unique to this device */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700822
823 for (try = 0; try < 64; try++) {
824 irq = try % 32;
825
826 /* marked as available by driver, and not blocked by userspace? */
827 if (!((mask >> irq) & 1))
828 continue;
829
830 /* avoid an IRQ which is already used by a PCMCIA card */
831 if ((try < 32) && pcmcia_used_irq[irq])
832 continue;
833
834 /* register the correct driver, if possible, of check whether
835 * registering a dummy handle works, i.e. if the IRQ isn't
836 * marked as used by the kernel resource management core */
837 ret = request_irq(irq,
838 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
Alan Coxc5331202006-05-16 16:16:44 +0100839 type,
Brice Goglinbd65a682005-09-09 13:03:29 -0700840 p_dev->devname,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700841 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
842 if (!ret) {
843 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
844 free_irq(irq, data);
845 break;
846 }
847 }
848 }
849#endif
Daniel Ritzc181e0e2005-09-09 13:03:25 -0700850 /* only assign PCI irq if no IRQ already assigned */
851 if (ret && !s->irq.AssignedIRQ) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700852 if (!s->pci_irq)
853 return ret;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700854 type = IRQF_SHARED;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700855 irq = s->pci_irq;
856 }
857
Alan Coxc5331202006-05-16 16:16:44 +0100858 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
859 if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700860 return CS_IN_USE;
861 }
862
Alan Coxc5331202006-05-16 16:16:44 +0100863 /* Make sure the fact the request type was overridden is passed back */
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700864 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
Alan Coxc5331202006-05-16 16:16:44 +0100865 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
866 printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n");
867 printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n");
868 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700869 c->irq.Attributes = req->Attributes;
870 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
871 s->irq.Config++;
872
873 c->state |= CONFIG_IRQ_REQ;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100874 p_dev->_irq = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700875
876#ifdef CONFIG_PCMCIA_PROBE
877 pcmcia_used_irq[irq]++;
878#endif
879
880 return CS_SUCCESS;
881} /* pcmcia_request_irq */
882EXPORT_SYMBOL(pcmcia_request_irq);
883
884
885/** pcmcia_request_window
886 *
887 * Request_window() establishes a mapping between card memory space
888 * and system memory space.
889 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700890int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700891{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700892 struct pcmcia_socket *s = (*p_dev)->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700893 window_t *win;
894 u_long align;
895 int w;
896
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700897 if (!(s->state & SOCKET_PRESENT))
898 return CS_NO_CARD;
899 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
900 return CS_BAD_ATTRIBUTE;
901
902 /* Window size defaults to smallest available */
903 if (req->Size == 0)
904 req->Size = s->map_size;
905 align = (((s->features & SS_CAP_MEM_ALIGN) ||
906 (req->Attributes & WIN_STRICT_ALIGN)) ?
907 req->Size : s->map_size);
908 if (req->Size & (s->map_size-1))
909 return CS_BAD_SIZE;
910 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
911 (req->Base & (align-1)))
912 return CS_BAD_BASE;
913 if (req->Base)
914 align = 0;
915
916 /* Allocate system memory window */
917 for (w = 0; w < MAX_WIN; w++)
918 if (!(s->state & SOCKET_WIN_REQ(w))) break;
919 if (w == MAX_WIN)
920 return CS_OUT_OF_RESOURCE;
921
922 win = &s->win[w];
923 win->magic = WINDOW_MAGIC;
924 win->index = w;
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700925 win->handle = *p_dev;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700926 win->sock = s;
927
928 if (!(s->features & SS_CAP_STATIC_MAP)) {
929 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
930 (req->Attributes & WIN_MAP_BELOW_1MB), s);
931 if (!win->ctl.res)
932 return CS_IN_USE;
933 }
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100934 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700935
936 /* Configure the socket controller */
937 win->ctl.map = w+1;
938 win->ctl.flags = 0;
939 win->ctl.speed = req->AccessSpeed;
940 if (req->Attributes & WIN_MEMORY_TYPE)
941 win->ctl.flags |= MAP_ATTRIB;
942 if (req->Attributes & WIN_ENABLE)
943 win->ctl.flags |= MAP_ACTIVE;
944 if (req->Attributes & WIN_DATA_WIDTH_16)
945 win->ctl.flags |= MAP_16BIT;
946 if (req->Attributes & WIN_USE_WAIT)
947 win->ctl.flags |= MAP_USE_WAIT;
948 win->ctl.card_start = 0;
949 if (s->ops->set_mem_map(s, &win->ctl) != 0)
950 return CS_BAD_ARGS;
951 s->state |= SOCKET_WIN_REQ(w);
952
953 /* Return window handle */
954 if (s->features & SS_CAP_STATIC_MAP) {
955 req->Base = win->ctl.static_start;
956 } else {
957 req->Base = win->ctl.res->start;
958 }
959 *wh = win;
960
961 return CS_SUCCESS;
962} /* pcmcia_request_window */
963EXPORT_SYMBOL(pcmcia_request_window);
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100964
965void pcmcia_disable_device(struct pcmcia_device *p_dev) {
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100966 pcmcia_release_configuration(p_dev);
Dominik Brodowskifd238232006-03-05 10:45:09 +0100967 pcmcia_release_io(p_dev, &p_dev->io);
968 pcmcia_release_irq(p_dev, &p_dev->irq);
969 if (&p_dev->win)
970 pcmcia_release_window(p_dev->win);
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100971}
972EXPORT_SYMBOL(pcmcia_disable_device);