blob: b9201c2ec38b3d15523a09ac8ee3a3af35ddddcc [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;
51#define cs_socket_name(skt) ((skt)->dev.class_id)
52
53#define ds_dbg(skt, lvl, fmt, arg...) do { \
54 if (ds_pc_debug >= lvl) \
55 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
56 cs_socket_name(skt) , ## arg); \
57} while (0)
58#else
59#define ds_dbg(lvl, fmt, arg...) do { } while (0)
60#endif
61
62
63
64/** alloc_io_space
65 *
66 * Special stuff for managing IO windows, because they are scarce
67 */
68
69static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
70 ioaddr_t num, u_int lines)
71{
72 int i;
73 kio_addr_t try, align;
74
75 align = (*base) ? (lines ? 1<<lines : 0) : 1;
76 if (align && (align < num)) {
77 if (*base) {
78 ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
79 num, align);
80 align = 0;
81 } else
82 while (align && (align < num)) align <<= 1;
83 }
84 if (*base & ~(align-1)) {
85 ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
86 *base, align);
87 align = 0;
88 }
89 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
90 *base = s->io_offset | (*base & 0x0fff);
91 return 0;
92 }
93 /* Check for an already-allocated window that must conflict with
94 * what was asked for. It is a hack because it does not catch all
95 * potential conflicts, just the most obvious ones.
96 */
97 for (i = 0; i < MAX_IO_WIN; i++)
Kaustav Majumdar4708b5f2006-10-20 14:44:09 -070098 if ((s->io[i].res) && *base &&
Dominik Brodowskic7d00692006-01-15 08:04:43 +010099 ((s->io[i].res->start & (align-1)) == *base))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700100 return 1;
101 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100102 if (!s->io[i].res) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700103 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
104 if (s->io[i].res) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100105 *base = s->io[i].res->start;
106 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
107 s->io[i].InUse = num;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700108 break;
109 } else
110 return 1;
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100111 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700112 continue;
113 /* Try to extend top of window */
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100114 try = s->io[i].res->end + 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700115 if ((*base == 0) || (*base == try))
116 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
117 s->io[i].res->end + num, s) == 0) {
118 *base = try;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700119 s->io[i].InUse += num;
120 break;
121 }
122 /* Try to extend bottom of window */
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100123 try = s->io[i].res->start - num;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700124 if ((*base == 0) || (*base == try))
125 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
126 s->io[i].res->end, s) == 0) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100127 *base = try;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700128 s->io[i].InUse += num;
129 break;
130 }
131 }
132 return (i == MAX_IO_WIN);
133} /* alloc_io_space */
134
135
136static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
137 ioaddr_t num)
138{
139 int i;
140
141 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100142 if (!s->io[i].res)
143 continue;
144 if ((s->io[i].res->start <= base) &&
145 (s->io[i].res->end >= base+num-1)) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700146 s->io[i].InUse -= num;
147 /* Free the window if no one else is using it */
148 if (s->io[i].InUse == 0) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700149 release_resource(s->io[i].res);
150 kfree(s->io[i].res);
151 s->io[i].res = NULL;
152 }
153 }
154 }
155} /* release_io_space */
156
157
158/** pccard_access_configuration_register
159 *
160 * Access_configuration_register() reads and writes configuration
161 * registers in attribute memory. Memory window 0 is reserved for
162 * this and the tuple reading services.
163 */
164
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100165int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700166 conf_reg_t *reg)
167{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100168 struct pcmcia_socket *s;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700169 config_t *c;
170 int addr;
171 u_char val;
172
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100173 if (!p_dev || !p_dev->function_config)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700174 return CS_NO_CARD;
175
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100176 s = p_dev->socket;
177 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700178
179 if (!(c->state & CONFIG_LOCKED))
180 return CS_CONFIGURATION_LOCKED;
181
182 addr = (c->ConfigBase + reg->Offset) >> 1;
183
184 switch (reg->Action) {
185 case CS_READ:
186 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
187 reg->Value = val;
188 break;
189 case CS_WRITE:
190 val = reg->Value;
191 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
192 break;
193 default:
194 return CS_BAD_ARGS;
195 break;
196 }
197 return CS_SUCCESS;
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100198} /* pcmcia_access_configuration_register */
Dominik Brodowski34481392005-06-27 16:28:54 -0700199EXPORT_SYMBOL(pcmcia_access_configuration_register);
200
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700201
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700202int pccard_get_configuration_info(struct pcmcia_socket *s,
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100203 struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700204 config_info_t *config)
205{
206 config_t *c;
207
208 if (!(s->state & SOCKET_PRESENT))
209 return CS_NO_CARD;
210
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700211
212#ifdef CONFIG_CARDBUS
213 if (s->state & SOCKET_CARDBUS) {
214 memset(config, 0, sizeof(config_info_t));
215 config->Vcc = s->socket.Vcc;
216 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
217 config->Option = s->cb_dev->subordinate->number;
218 if (s->state & SOCKET_CARDBUS_CONFIG) {
219 config->Attributes = CONF_VALID_CLIENT;
220 config->IntType = INT_CARDBUS;
221 config->AssignedIRQ = s->irq.AssignedIRQ;
222 if (config->AssignedIRQ)
223 config->Attributes |= CONF_ENABLE_IRQ;
Daniel Ritz48b950f2006-04-14 17:42:13 +0200224 if (s->io[0].res) {
225 config->BasePort1 = s->io[0].res->start;
226 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
227 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700228 }
229 return CS_SUCCESS;
230 }
231#endif
232
Daniel Ritz48b950f2006-04-14 17:42:13 +0200233 if (p_dev) {
234 c = p_dev->function_config;
235 config->Function = p_dev->func;
236 } else {
237 c = NULL;
238 config->Function = 0;
239 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700240
241 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
242 config->Attributes = 0;
243 config->Vcc = s->socket.Vcc;
244 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
245 return CS_SUCCESS;
246 }
247
Daniel Ritz47a31972006-07-30 03:03:49 -0700248 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
249 config->Vcc = s->socket.Vcc;
250 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
251 config->IntType = c->IntType;
252 config->ConfigBase = c->ConfigBase;
253 config->Status = c->Status;
254 config->Pin = c->Pin;
255 config->Copy = c->Copy;
256 config->Option = c->Option;
257 config->ExtStatus = c->ExtStatus;
258 config->Present = config->CardValues = c->CardValues;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700259 config->IRQAttributes = c->irq.Attributes;
260 config->AssignedIRQ = s->irq.AssignedIRQ;
261 config->BasePort1 = c->io.BasePort1;
262 config->NumPorts1 = c->io.NumPorts1;
263 config->Attributes1 = c->io.Attributes1;
264 config->BasePort2 = c->io.BasePort2;
265 config->NumPorts2 = c->io.NumPorts2;
266 config->Attributes2 = c->io.Attributes2;
267 config->IOAddrLines = c->io.IOAddrLines;
268
269 return CS_SUCCESS;
270} /* pccard_get_configuration_info */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700271
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700272int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
Dominik Brodowski34481392005-06-27 16:28:54 -0700273 config_info_t *config)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700274{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100275 return pccard_get_configuration_info(p_dev->socket, p_dev,
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700276 config);
Dominik Brodowski34481392005-06-27 16:28:54 -0700277}
278EXPORT_SYMBOL(pcmcia_get_configuration_info);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700279
280
281/** pcmcia_get_window
282 */
283int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
284 int idx, win_req_t *req)
285{
286 window_t *win;
287 int w;
288
289 if (!s || !(s->state & SOCKET_PRESENT))
290 return CS_NO_CARD;
291 for (w = idx; w < MAX_WIN; w++)
292 if (s->state & SOCKET_WIN_REQ(w))
293 break;
294 if (w == MAX_WIN)
295 return CS_NO_MORE_ITEMS;
296 win = &s->win[w];
297 req->Base = win->ctl.res->start;
298 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
299 req->AccessSpeed = win->ctl.speed;
300 req->Attributes = 0;
301 if (win->ctl.flags & MAP_ATTRIB)
302 req->Attributes |= WIN_MEMORY_TYPE_AM;
303 if (win->ctl.flags & MAP_ACTIVE)
304 req->Attributes |= WIN_ENABLE;
305 if (win->ctl.flags & MAP_16BIT)
306 req->Attributes |= WIN_DATA_WIDTH_16;
307 if (win->ctl.flags & MAP_USE_WAIT)
308 req->Attributes |= WIN_USE_WAIT;
309 *handle = win;
310 return CS_SUCCESS;
311} /* pcmcia_get_window */
312EXPORT_SYMBOL(pcmcia_get_window);
313
314
315/** pccard_get_status
316 *
317 * Get the current socket state bits. We don't support the latched
318 * SocketState yet: I haven't seen any point for it.
319 */
320
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100321int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700322 cs_status_t *status)
323{
324 config_t *c;
325 int val;
326
327 s->ops->get_status(s, &val);
328 status->CardState = status->SocketState = 0;
329 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
330 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
331 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
332 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
333 if (s->state & SOCKET_SUSPEND)
334 status->CardState |= CS_EVENT_PM_SUSPEND;
335 if (!(s->state & SOCKET_PRESENT))
336 return CS_NO_CARD;
337
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100338 c = (p_dev) ? p_dev->function_config : NULL;
339
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700340 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
341 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
342 u_char reg;
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100343 if (c->CardValues & PRESENT_PIN_REPLACE) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700344 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
345 status->CardState |=
346 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
347 status->CardState |=
348 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
349 status->CardState |=
350 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
351 status->CardState |=
352 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
353 } else {
354 /* No PRR? Then assume we're always ready */
355 status->CardState |= CS_EVENT_READY_CHANGE;
356 }
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100357 if (c->CardValues & PRESENT_EXT_STATUS) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700358 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
359 status->CardState |=
360 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
361 }
362 return CS_SUCCESS;
363 }
364 status->CardState |=
365 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
366 status->CardState |=
367 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
368 status->CardState |=
369 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
370 status->CardState |=
371 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
372 return CS_SUCCESS;
373} /* pccard_get_status */
Dominik Brodowski34481392005-06-27 16:28:54 -0700374
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100375int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status)
Dominik Brodowski34481392005-06-27 16:28:54 -0700376{
Dominik Brodowski855cdf12006-01-10 20:48:59 +0100377 return pccard_get_status(p_dev->socket, p_dev, status);
Dominik Brodowski34481392005-06-27 16:28:54 -0700378}
379EXPORT_SYMBOL(pcmcia_get_status);
380
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700381
382
383/** pcmcia_get_mem_page
384 *
385 * Change the card address of an already open memory window.
386 */
387int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
388{
389 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
390 return CS_BAD_HANDLE;
391 req->Page = 0;
392 req->CardOffset = win->ctl.card_start;
393 return CS_SUCCESS;
394} /* pcmcia_get_mem_page */
395EXPORT_SYMBOL(pcmcia_get_mem_page);
396
397
398int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
399{
400 struct pcmcia_socket *s;
401 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
402 return CS_BAD_HANDLE;
403 if (req->Page != 0)
404 return CS_BAD_PAGE;
405 s = win->sock;
406 win->ctl.card_start = req->CardOffset;
407 if (s->ops->set_mem_map(s, &win->ctl) != 0)
408 return CS_BAD_OFFSET;
409 return CS_SUCCESS;
410} /* pcmcia_map_mem_page */
411EXPORT_SYMBOL(pcmcia_map_mem_page);
412
413
414/** pcmcia_modify_configuration
415 *
416 * Modify a locked socket configuration
417 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700418int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700419 modconf_t *mod)
420{
421 struct pcmcia_socket *s;
422 config_t *c;
423
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700424 s = p_dev->socket;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100425 c = p_dev->function_config;
426
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700427 if (!(s->state & SOCKET_PRESENT))
428 return CS_NO_CARD;
429 if (!(c->state & CONFIG_LOCKED))
430 return CS_CONFIGURATION_LOCKED;
431
432 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
433 if (mod->Attributes & CONF_ENABLE_IRQ) {
434 c->Attributes |= CONF_ENABLE_IRQ;
435 s->socket.io_irq = s->irq.AssignedIRQ;
436 } else {
437 c->Attributes &= ~CONF_ENABLE_IRQ;
438 s->socket.io_irq = 0;
439 }
440 s->ops->set_socket(s, &s->socket);
441 }
442
443 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
444 return CS_BAD_VCC;
445
446 /* We only allow changing Vpp1 and Vpp2 to the same value */
447 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
448 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
449 if (mod->Vpp1 != mod->Vpp2)
450 return CS_BAD_VPP;
Dominik Brodowski71ed90d2005-09-09 13:03:27 -0700451 s->socket.Vpp = mod->Vpp1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700452 if (s->ops->set_socket(s, &s->socket))
453 return CS_BAD_VPP;
454 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
455 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
456 return CS_BAD_VPP;
457
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100458 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
459 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
460 pccard_io_map io_on;
461 int i;
462
463 io_on.speed = io_speed;
464 for (i = 0; i < MAX_IO_WIN; i++) {
465 if (!s->io[i].res)
466 continue;
467 io_off.map = i;
468 io_on.map = i;
469
470 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
471 io_on.start = s->io[i].res->start;
472 io_on.stop = s->io[i].res->end;
473
474 s->ops->set_io_map(s, &io_off);
475 mdelay(40);
476 s->ops->set_io_map(s, &io_on);
477 }
478 }
479
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700480 return CS_SUCCESS;
481} /* modify_configuration */
482EXPORT_SYMBOL(pcmcia_modify_configuration);
483
484
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700485int pcmcia_release_configuration(struct pcmcia_device *p_dev)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700486{
487 pccard_io_map io = { 0, 0, 0, 0, 1 };
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700488 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100489 config_t *c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700490 int i;
491
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100492 if (p_dev->_locked) {
493 p_dev->_locked = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700494 if (--(s->lock_count) == 0) {
495 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
496 s->socket.Vpp = 0;
497 s->socket.io_irq = 0;
498 s->ops->set_socket(s, &s->socket);
499 }
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100500 }
501 if (c->state & CONFIG_LOCKED) {
502 c->state &= ~CONFIG_LOCKED;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700503 if (c->state & CONFIG_IO_REQ)
504 for (i = 0; i < MAX_IO_WIN; i++) {
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100505 if (!s->io[i].res)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700506 continue;
507 s->io[i].Config--;
508 if (s->io[i].Config != 0)
509 continue;
510 io.map = i;
511 s->ops->set_io_map(s, &io);
512 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700513 }
514
515 return CS_SUCCESS;
516} /* pcmcia_release_configuration */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700517
518
519/** pcmcia_release_io
520 *
521 * Release_io() releases the I/O ranges allocated by a client. This
522 * may be invoked some time after a card ejection has already dumped
523 * the actual socket configuration, so if the client is "stale", we
524 * don't bother checking the port ranges against the current socket
525 * values.
526 */
Adrian Bunkb4c88402006-01-18 23:53:13 -0800527static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700528{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700529 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100530 config_t *c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700531
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100532 if (!p_dev->_io )
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700533 return CS_BAD_HANDLE;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100534
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100535 p_dev->_io = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700536
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100537 if ((c->io.BasePort1 != req->BasePort1) ||
538 (c->io.NumPorts1 != req->NumPorts1) ||
539 (c->io.BasePort2 != req->BasePort2) ||
540 (c->io.NumPorts2 != req->NumPorts2))
541 return CS_BAD_ARGS;
542
543 c->state &= ~CONFIG_IO_REQ;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700544
545 release_io_space(s, req->BasePort1, req->NumPorts1);
546 if (req->NumPorts2)
547 release_io_space(s, req->BasePort2, req->NumPorts2);
548
549 return CS_SUCCESS;
550} /* pcmcia_release_io */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700551
552
Adrian Bunkb4c88402006-01-18 23:53:13 -0800553static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700554{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700555 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100556 config_t *c= p_dev->function_config;
557
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100558 if (!p_dev->_irq)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700559 return CS_BAD_HANDLE;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100560 p_dev->_irq = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700561
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100562 if (c->state & CONFIG_LOCKED)
563 return CS_CONFIGURATION_LOCKED;
564 if (c->irq.Attributes != req->Attributes)
565 return CS_BAD_ATTRIBUTE;
566 if (s->irq.AssignedIRQ != req->AssignedIRQ)
567 return CS_BAD_IRQ;
568 if (--s->irq.Config == 0) {
569 c->state &= ~CONFIG_IRQ_REQ;
570 s->irq.AssignedIRQ = 0;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700571 }
572
573 if (req->Attributes & IRQ_HANDLE_PRESENT) {
574 free_irq(req->AssignedIRQ, req->Instance);
575 }
576
577#ifdef CONFIG_PCMCIA_PROBE
578 pcmcia_used_irq[req->AssignedIRQ]--;
579#endif
580
581 return CS_SUCCESS;
582} /* pcmcia_release_irq */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700583
584
585int pcmcia_release_window(window_handle_t win)
586{
587 struct pcmcia_socket *s;
588
589 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
590 return CS_BAD_HANDLE;
591 s = win->sock;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100592 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700593 return CS_BAD_HANDLE;
594
595 /* Shut down memory window */
596 win->ctl.flags &= ~MAP_ACTIVE;
597 s->ops->set_mem_map(s, &win->ctl);
598 s->state &= ~SOCKET_WIN_REQ(win->index);
599
600 /* Release system memory */
601 if (win->ctl.res) {
602 release_resource(win->ctl.res);
603 kfree(win->ctl.res);
604 win->ctl.res = NULL;
605 }
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100606 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700607
608 win->magic = 0;
609
610 return CS_SUCCESS;
611} /* pcmcia_release_window */
612EXPORT_SYMBOL(pcmcia_release_window);
613
614
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700615int pcmcia_request_configuration(struct pcmcia_device *p_dev,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700616 config_req_t *req)
617{
618 int i;
619 u_int base;
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700620 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700621 config_t *c;
622 pccard_io_map iomap;
623
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700624 if (!(s->state & SOCKET_PRESENT))
625 return CS_NO_CARD;
626
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700627 if (req->IntType & INT_CARDBUS)
628 return CS_UNSUPPORTED_MODE;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100629 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700630 if (c->state & CONFIG_LOCKED)
631 return CS_CONFIGURATION_LOCKED;
632
633 /* Do power control. We don't allow changes in Vcc. */
Dominik Brodowski70294b42006-01-15 12:43:16 +0100634 s->socket.Vpp = req->Vpp;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700635 if (s->ops->set_socket(s, &s->socket))
636 return CS_BAD_VPP;
637
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700638 /* Pick memory or I/O card, DMA mode, interrupt */
639 c->IntType = req->IntType;
640 c->Attributes = req->Attributes;
641 if (req->IntType & INT_MEMORY_AND_IO)
642 s->socket.flags |= SS_IOCARD;
643 if (req->IntType & INT_ZOOMED_VIDEO)
644 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
645 if (req->Attributes & CONF_ENABLE_DMA)
646 s->socket.flags |= SS_DMA_MODE;
647 if (req->Attributes & CONF_ENABLE_SPKR)
648 s->socket.flags |= SS_SPKR_ENA;
649 if (req->Attributes & CONF_ENABLE_IRQ)
650 s->socket.io_irq = s->irq.AssignedIRQ;
651 else
652 s->socket.io_irq = 0;
653 s->ops->set_socket(s, &s->socket);
654 s->lock_count++;
655
656 /* Set up CIS configuration registers */
657 base = c->ConfigBase = req->ConfigBase;
Dominik Brodowski1ae9c7d2006-01-10 20:40:40 +0100658 c->CardValues = req->Present;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700659 if (req->Present & PRESENT_COPY) {
660 c->Copy = req->Copy;
661 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
662 }
663 if (req->Present & PRESENT_OPTION) {
664 if (s->functions == 1) {
665 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
666 } else {
667 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
668 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
669 if (req->Present & PRESENT_IOBASE_0)
670 c->Option |= COR_ADDR_DECODE;
671 }
672 if (c->state & CONFIG_IRQ_REQ)
673 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
674 c->Option |= COR_LEVEL_REQ;
675 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
676 mdelay(40);
677 }
678 if (req->Present & PRESENT_STATUS) {
679 c->Status = req->Status;
680 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
681 }
682 if (req->Present & PRESENT_PIN_REPLACE) {
683 c->Pin = req->Pin;
684 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
685 }
686 if (req->Present & PRESENT_EXT_STATUS) {
687 c->ExtStatus = req->ExtStatus;
688 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
689 }
690 if (req->Present & PRESENT_IOBASE_0) {
691 u_char b = c->io.BasePort1 & 0xff;
692 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
693 b = (c->io.BasePort1 >> 8) & 0xff;
694 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
695 }
696 if (req->Present & PRESENT_IOSIZE) {
697 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
698 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
699 }
700
701 /* Configure I/O windows */
702 if (c->state & CONFIG_IO_REQ) {
703 iomap.speed = io_speed;
704 for (i = 0; i < MAX_IO_WIN; i++)
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100705 if (s->io[i].res) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700706 iomap.map = i;
707 iomap.flags = MAP_ACTIVE;
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100708 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700709 case IO_DATA_PATH_WIDTH_16:
710 iomap.flags |= MAP_16BIT; break;
711 case IO_DATA_PATH_WIDTH_AUTO:
712 iomap.flags |= MAP_AUTOSZ; break;
713 default:
714 break;
715 }
Dominik Brodowskic7d00692006-01-15 08:04:43 +0100716 iomap.start = s->io[i].res->start;
717 iomap.stop = s->io[i].res->end;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700718 s->ops->set_io_map(s, &iomap);
719 s->io[i].Config++;
720 }
721 }
722
723 c->state |= CONFIG_LOCKED;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100724 p_dev->_locked = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700725 return CS_SUCCESS;
726} /* pcmcia_request_configuration */
727EXPORT_SYMBOL(pcmcia_request_configuration);
728
729
730/** pcmcia_request_io
731 *
732 * Request_io() reserves ranges of port addresses for a socket.
733 * I have not implemented range sharing or alias addressing.
734 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700735int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700736{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700737 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700738 config_t *c;
739
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700740 if (!(s->state & SOCKET_PRESENT))
741 return CS_NO_CARD;
742
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700743 if (!req)
744 return CS_UNSUPPORTED_MODE;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100745 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700746 if (c->state & CONFIG_LOCKED)
747 return CS_CONFIGURATION_LOCKED;
748 if (c->state & CONFIG_IO_REQ)
749 return CS_IN_USE;
750 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
751 return CS_BAD_ATTRIBUTE;
752 if ((req->NumPorts2 > 0) &&
753 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
754 return CS_BAD_ATTRIBUTE;
755
756 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
757 req->NumPorts1, req->IOAddrLines))
758 return CS_IN_USE;
759
760 if (req->NumPorts2) {
761 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
762 req->NumPorts2, req->IOAddrLines)) {
763 release_io_space(s, req->BasePort1, req->NumPorts1);
764 return CS_IN_USE;
765 }
766 }
767
768 c->io = *req;
769 c->state |= CONFIG_IO_REQ;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100770 p_dev->_io = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700771 return CS_SUCCESS;
772} /* pcmcia_request_io */
773EXPORT_SYMBOL(pcmcia_request_io);
774
775
776/** pcmcia_request_irq
777 *
778 * Request_irq() reserves an irq for this client.
779 *
780 * Also, since Linux only reserves irq's when they are actually
781 * hooked, we don't guarantee that an irq will still be available
782 * when the configuration is locked. Now that I think about it,
783 * there might be a way to fix this using a dummy handler.
784 */
785
786#ifdef CONFIG_PCMCIA_PROBE
David Howells7d12e782006-10-05 14:55:46 +0100787static irqreturn_t test_action(int cpl, void *dev_id)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700788{
789 return IRQ_NONE;
790}
791#endif
792
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700793int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700794{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700795 struct pcmcia_socket *s = p_dev->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700796 config_t *c;
797 int ret = CS_IN_USE, irq = 0;
Alan Coxc5331202006-05-16 16:16:44 +0100798 int type;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700799
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700800 if (!(s->state & SOCKET_PRESENT))
801 return CS_NO_CARD;
Dominik Brodowskidbb22f02006-01-10 20:41:27 +0100802 c = p_dev->function_config;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700803 if (c->state & CONFIG_LOCKED)
804 return CS_CONFIGURATION_LOCKED;
805 if (c->state & CONFIG_IRQ_REQ)
806 return CS_IN_USE;
807
Alan Coxc5331202006-05-16 16:16:44 +0100808 /* Decide what type of interrupt we are registering */
809 type = 0;
810 if (s->functions > 1) /* All of this ought to be handled higher up */
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700811 type = IRQF_SHARED;
Alan Coxc5331202006-05-16 16:16:44 +0100812 if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700813 type = IRQF_SHARED;
Alan Coxc5331202006-05-16 16:16:44 +0100814
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700815#ifdef CONFIG_PCMCIA_PROBE
816 if (s->irq.AssignedIRQ != 0) {
817 /* If the interrupt is already assigned, it must be the same */
818 irq = s->irq.AssignedIRQ;
819 } else {
820 int try;
821 u32 mask = s->irq_mask;
Dominik Brodowskia1b274f2005-07-28 01:07:27 -0700822 void *data = &p_dev->dev.driver; /* something unique to this device */
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700823
824 for (try = 0; try < 64; try++) {
825 irq = try % 32;
826
827 /* marked as available by driver, and not blocked by userspace? */
828 if (!((mask >> irq) & 1))
829 continue;
830
831 /* avoid an IRQ which is already used by a PCMCIA card */
832 if ((try < 32) && pcmcia_used_irq[irq])
833 continue;
834
835 /* register the correct driver, if possible, of check whether
836 * registering a dummy handle works, i.e. if the IRQ isn't
837 * marked as used by the kernel resource management core */
838 ret = request_irq(irq,
839 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
Alan Coxc5331202006-05-16 16:16:44 +0100840 type,
Brice Goglinbd65a682005-09-09 13:03:29 -0700841 p_dev->devname,
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700842 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
843 if (!ret) {
844 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
845 free_irq(irq, data);
846 break;
847 }
848 }
849 }
850#endif
Daniel Ritzc181e0e2005-09-09 13:03:25 -0700851 /* only assign PCI irq if no IRQ already assigned */
852 if (ret && !s->irq.AssignedIRQ) {
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700853 if (!s->pci_irq)
854 return ret;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700855 type = IRQF_SHARED;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700856 irq = s->pci_irq;
857 }
858
Alan Coxc5331202006-05-16 16:16:44 +0100859 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
860 if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance))
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700861 return CS_IN_USE;
862 }
863
Alan Coxc5331202006-05-16 16:16:44 +0100864 /* Make sure the fact the request type was overridden is passed back */
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700865 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
Alan Coxc5331202006-05-16 16:16:44 +0100866 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
867 printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n");
868 printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n");
869 }
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700870 c->irq.Attributes = req->Attributes;
871 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
872 s->irq.Config++;
873
874 c->state |= CONFIG_IRQ_REQ;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100875 p_dev->_irq = 1;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700876
877#ifdef CONFIG_PCMCIA_PROBE
878 pcmcia_used_irq[irq]++;
879#endif
880
881 return CS_SUCCESS;
882} /* pcmcia_request_irq */
883EXPORT_SYMBOL(pcmcia_request_irq);
884
885
886/** pcmcia_request_window
887 *
888 * Request_window() establishes a mapping between card memory space
889 * and system memory space.
890 */
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700891int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700892{
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700893 struct pcmcia_socket *s = (*p_dev)->socket;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700894 window_t *win;
895 u_long align;
896 int w;
897
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700898 if (!(s->state & SOCKET_PRESENT))
899 return CS_NO_CARD;
900 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
901 return CS_BAD_ATTRIBUTE;
902
903 /* Window size defaults to smallest available */
904 if (req->Size == 0)
905 req->Size = s->map_size;
906 align = (((s->features & SS_CAP_MEM_ALIGN) ||
907 (req->Attributes & WIN_STRICT_ALIGN)) ?
908 req->Size : s->map_size);
909 if (req->Size & (s->map_size-1))
910 return CS_BAD_SIZE;
911 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
912 (req->Base & (align-1)))
913 return CS_BAD_BASE;
914 if (req->Base)
915 align = 0;
916
917 /* Allocate system memory window */
918 for (w = 0; w < MAX_WIN; w++)
919 if (!(s->state & SOCKET_WIN_REQ(w))) break;
920 if (w == MAX_WIN)
921 return CS_OUT_OF_RESOURCE;
922
923 win = &s->win[w];
924 win->magic = WINDOW_MAGIC;
925 win->index = w;
Dominik Brodowski2bc5a9b2005-07-07 17:59:02 -0700926 win->handle = *p_dev;
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700927 win->sock = s;
928
929 if (!(s->features & SS_CAP_STATIC_MAP)) {
930 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
931 (req->Attributes & WIN_MAP_BELOW_1MB), s);
932 if (!win->ctl.res)
933 return CS_IN_USE;
934 }
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100935 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
Dominik Brodowski1a8d4662005-06-27 16:28:53 -0700936
937 /* Configure the socket controller */
938 win->ctl.map = w+1;
939 win->ctl.flags = 0;
940 win->ctl.speed = req->AccessSpeed;
941 if (req->Attributes & WIN_MEMORY_TYPE)
942 win->ctl.flags |= MAP_ATTRIB;
943 if (req->Attributes & WIN_ENABLE)
944 win->ctl.flags |= MAP_ACTIVE;
945 if (req->Attributes & WIN_DATA_WIDTH_16)
946 win->ctl.flags |= MAP_16BIT;
947 if (req->Attributes & WIN_USE_WAIT)
948 win->ctl.flags |= MAP_USE_WAIT;
949 win->ctl.card_start = 0;
950 if (s->ops->set_mem_map(s, &win->ctl) != 0)
951 return CS_BAD_ARGS;
952 s->state |= SOCKET_WIN_REQ(w);
953
954 /* Return window handle */
955 if (s->features & SS_CAP_STATIC_MAP) {
956 req->Base = win->ctl.static_start;
957 } else {
958 req->Base = win->ctl.res->start;
959 }
960 *wh = win;
961
962 return CS_SUCCESS;
963} /* pcmcia_request_window */
964EXPORT_SYMBOL(pcmcia_request_window);
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100965
966void pcmcia_disable_device(struct pcmcia_device *p_dev) {
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100967 pcmcia_release_configuration(p_dev);
Dominik Brodowskifd238232006-03-05 10:45:09 +0100968 pcmcia_release_io(p_dev, &p_dev->io);
969 pcmcia_release_irq(p_dev, &p_dev->irq);
970 if (&p_dev->win)
971 pcmcia_release_window(p_dev->win);
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100972}
973EXPORT_SYMBOL(pcmcia_disable_device);