2 * PCMCIA 16-bit resource management functions
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.
8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski
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.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
21 #include <linux/pci.h>
22 #include <linux/device.h>
23 #include <linux/netdevice.h>
24 #include <linux/slab.h>
28 #include <pcmcia/ss.h>
29 #include <pcmcia/cs.h>
30 #include <pcmcia/cistpl.h>
31 #include <pcmcia/cisreg.h>
32 #include <pcmcia/ds.h>
34 #include "cs_internal.h"
37 /* Access speed for IO windows */
39 module_param(io_speed
, int, 0444);
42 int pcmcia_validate_mem(struct pcmcia_socket
*s
)
44 if (s
->resource_ops
->validate_mem
)
45 return s
->resource_ops
->validate_mem(s
);
46 /* if there is no callback, we can assume that everything is OK */
50 struct resource
*pcmcia_find_mem_region(u_long base
, u_long num
, u_long align
,
51 int low
, struct pcmcia_socket
*s
)
53 if (s
->resource_ops
->find_mem
)
54 return s
->resource_ops
->find_mem(base
, num
, align
, low
, s
);
59 static void release_io_space(struct pcmcia_socket
*s
, struct resource
*res
)
61 resource_size_t num
= resource_size(res
);
64 dev_dbg(&s
->dev
, "release_io_space for %pR\n", res
);
66 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
69 if ((s
->io
[i
].res
->start
<= res
->start
) &&
70 (s
->io
[i
].res
->end
>= res
->end
)) {
71 s
->io
[i
].InUse
-= num
;
73 release_resource(res
);
74 res
->start
= res
->end
= 0;
75 res
->flags
= IORESOURCE_IO
;
76 /* Free the window if no one else is using it */
77 if (s
->io
[i
].InUse
== 0) {
78 release_resource(s
->io
[i
].res
);
84 } /* release_io_space */
88 * Special stuff for managing IO windows, because they are scarce
90 static int alloc_io_space(struct pcmcia_socket
*s
, struct resource
*res
,
94 unsigned int base
= res
->start
;
95 unsigned int num
= res
->end
;
98 res
->flags
|= IORESOURCE_IO
;
100 dev_dbg(&s
->dev
, "alloc_io_space request for %pR, %d lines\n",
103 align
= base
? (lines
? 1<<lines
: 0) : 1;
104 if (align
&& (align
< num
)) {
106 dev_dbg(&s
->dev
, "odd IO request\n");
109 while (align
&& (align
< num
))
112 if (base
& ~(align
-1)) {
113 dev_dbg(&s
->dev
, "odd IO request\n");
117 ret
= s
->resource_ops
->find_io(s
, res
->flags
, &base
, num
, align
,
120 dev_dbg(&s
->dev
, "alloc_io_space request failed (%d)\n", ret
);
125 res
->end
= res
->start
+ num
- 1;
128 ret
= request_resource(res
->parent
, res
);
131 "request_resource %pR failed: %d\n", res
, ret
);
133 release_io_space(s
, res
);
136 dev_dbg(&s
->dev
, "alloc_io_space request result %d: %pR\n", ret
, res
);
138 } /* alloc_io_space */
142 * pcmcia_access_config() - read or write card configuration registers
144 * pcmcia_access_config() reads and writes configuration registers in
145 * attribute memory. Memory window 0 is reserved for this and the tuple
146 * reading services. Drivers must use pcmcia_read_config_byte() or
147 * pcmcia_write_config_byte().
149 static int pcmcia_access_config(struct pcmcia_device
*p_dev
,
150 off_t where
, u8
*val
,
151 int (*accessf
) (struct pcmcia_socket
*s
,
152 int attr
, unsigned int addr
,
153 unsigned int len
, void *ptr
))
155 struct pcmcia_socket
*s
;
162 mutex_lock(&s
->ops_mutex
);
163 c
= p_dev
->function_config
;
165 if (!(c
->state
& CONFIG_LOCKED
)) {
166 dev_dbg(&p_dev
->dev
, "Configuration isnt't locked\n");
167 mutex_unlock(&s
->ops_mutex
);
171 addr
= (c
->ConfigBase
+ where
) >> 1;
173 ret
= accessf(s
, 1, addr
, 1, val
);
175 mutex_unlock(&s
->ops_mutex
);
178 } /* pcmcia_access_config */
182 * pcmcia_read_config_byte() - read a byte from a card configuration register
184 * pcmcia_read_config_byte() reads a byte from a configuration register in
187 int pcmcia_read_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8
*val
)
189 return pcmcia_access_config(p_dev
, where
, val
, pcmcia_read_cis_mem
);
191 EXPORT_SYMBOL(pcmcia_read_config_byte
);
195 * pcmcia_write_config_byte() - write a byte to a card configuration register
197 * pcmcia_write_config_byte() writes a byte to a configuration register in
200 int pcmcia_write_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8 val
)
202 return pcmcia_access_config(p_dev
, where
, &val
, pcmcia_write_cis_mem
);
204 EXPORT_SYMBOL(pcmcia_write_config_byte
);
207 int pcmcia_map_mem_page(struct pcmcia_device
*p_dev
, struct resource
*res
,
210 struct pcmcia_socket
*s
= p_dev
->socket
;
214 w
= ((res
->flags
& IORESOURCE_BITS
& WIN_FLAGS_REQ
) >> 2) - 1;
218 mutex_lock(&s
->ops_mutex
);
219 s
->win
[w
].card_start
= offset
;
220 ret
= s
->ops
->set_mem_map(s
, &s
->win
[w
]);
222 dev_warn(&p_dev
->dev
, "failed to set_mem_map\n");
223 mutex_unlock(&s
->ops_mutex
);
225 } /* pcmcia_map_mem_page */
226 EXPORT_SYMBOL(pcmcia_map_mem_page
);
230 * pcmcia_fixup_iowidth() - reduce io width to 8bit
232 * pcmcia_fixup_iowidth() allows a PCMCIA device driver to reduce the
233 * IO width to 8bit after having called pcmcia_request_configuration()
236 int pcmcia_fixup_iowidth(struct pcmcia_device
*p_dev
)
238 struct pcmcia_socket
*s
= p_dev
->socket
;
239 pccard_io_map io_off
= { 0, 0, 0, 0, 1 };
243 mutex_lock(&s
->ops_mutex
);
245 dev_dbg(&p_dev
->dev
, "fixup iowidth to 8bit\n");
247 if (!(s
->state
& SOCKET_PRESENT
) ||
248 !(p_dev
->function_config
->state
& CONFIG_LOCKED
)) {
249 dev_dbg(&p_dev
->dev
, "No card? Config not locked?\n");
254 io_on
.speed
= io_speed
;
255 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
261 io_on
.flags
= MAP_ACTIVE
| IO_DATA_PATH_WIDTH_8
;
262 io_on
.start
= s
->io
[i
].res
->start
;
263 io_on
.stop
= s
->io
[i
].res
->end
;
265 s
->ops
->set_io_map(s
, &io_off
);
267 s
->ops
->set_io_map(s
, &io_on
);
270 mutex_unlock(&s
->ops_mutex
);
274 EXPORT_SYMBOL(pcmcia_fixup_iowidth
);
278 * pcmcia_fixup_vpp() - set Vpp to a new voltage level
280 * pcmcia_fixup_vpp() allows a PCMCIA device driver to set Vpp to
281 * a new voltage level between calls to pcmcia_request_configuration()
282 * and pcmcia_disable_device().
284 int pcmcia_fixup_vpp(struct pcmcia_device
*p_dev
, unsigned char new_vpp
)
286 struct pcmcia_socket
*s
= p_dev
->socket
;
289 mutex_lock(&s
->ops_mutex
);
291 dev_dbg(&p_dev
->dev
, "fixup Vpp to %d\n", new_vpp
);
293 if (!(s
->state
& SOCKET_PRESENT
) ||
294 !(p_dev
->function_config
->state
& CONFIG_LOCKED
)) {
295 dev_dbg(&p_dev
->dev
, "No card? Config not locked?\n");
300 s
->socket
.Vpp
= new_vpp
;
301 if (s
->ops
->set_socket(s
, &s
->socket
)) {
302 dev_warn(&p_dev
->dev
, "Unable to set VPP\n");
308 mutex_unlock(&s
->ops_mutex
);
312 EXPORT_SYMBOL(pcmcia_fixup_vpp
);
315 int pcmcia_release_configuration(struct pcmcia_device
*p_dev
)
317 pccard_io_map io
= { 0, 0, 0, 0, 1 };
318 struct pcmcia_socket
*s
= p_dev
->socket
;
322 mutex_lock(&s
->ops_mutex
);
323 c
= p_dev
->function_config
;
324 if (p_dev
->_locked
) {
326 if (--(s
->lock_count
) == 0) {
327 s
->socket
.flags
= SS_OUTPUT_ENA
; /* Is this correct? */
329 s
->socket
.io_irq
= 0;
330 s
->ops
->set_socket(s
, &s
->socket
);
333 if (c
->state
& CONFIG_LOCKED
) {
334 c
->state
&= ~CONFIG_LOCKED
;
335 if (c
->state
& CONFIG_IO_REQ
)
336 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
340 if (s
->io
[i
].Config
!= 0)
343 s
->ops
->set_io_map(s
, &io
);
346 mutex_unlock(&s
->ops_mutex
);
349 } /* pcmcia_release_configuration */
352 /** pcmcia_release_io
354 * Release_io() releases the I/O ranges allocated by a client. This
355 * may be invoked some time after a card ejection has already dumped
356 * the actual socket configuration, so if the client is "stale", we
357 * don't bother checking the port ranges against the current socket
360 static int pcmcia_release_io(struct pcmcia_device
*p_dev
)
362 struct pcmcia_socket
*s
= p_dev
->socket
;
366 mutex_lock(&s
->ops_mutex
);
370 c
= p_dev
->function_config
;
372 release_io_space(s
, &c
->io
[0]);
375 release_io_space(s
, &c
->io
[1]);
378 c
->state
&= ~CONFIG_IO_REQ
;
381 mutex_unlock(&s
->ops_mutex
);
384 } /* pcmcia_release_io */
387 * pcmcia_release_window() - release reserved iomem for PCMCIA devices
389 * pcmcia_release_window() releases struct resource *res which was
390 * previously reserved by calling pcmcia_request_window().
392 int pcmcia_release_window(struct pcmcia_device
*p_dev
, struct resource
*res
)
394 struct pcmcia_socket
*s
= p_dev
->socket
;
398 dev_dbg(&p_dev
->dev
, "releasing window %pR\n", res
);
400 w
= ((res
->flags
& IORESOURCE_BITS
& WIN_FLAGS_REQ
) >> 2) - 1;
404 mutex_lock(&s
->ops_mutex
);
407 if (!(p_dev
->_win
& CLIENT_WIN_REQ(w
))) {
408 dev_dbg(&p_dev
->dev
, "not releasing unknown window\n");
409 mutex_unlock(&s
->ops_mutex
);
413 /* Shut down memory window */
414 win
->flags
&= ~MAP_ACTIVE
;
415 s
->ops
->set_mem_map(s
, win
);
416 s
->state
&= ~SOCKET_WIN_REQ(w
);
418 /* Release system memory */
420 release_resource(res
);
421 release_resource(win
->res
);
425 res
->start
= res
->end
= 0;
426 res
->flags
= IORESOURCE_MEM
;
427 p_dev
->_win
&= ~CLIENT_WIN_REQ(w
);
428 mutex_unlock(&s
->ops_mutex
);
431 } /* pcmcia_release_window */
432 EXPORT_SYMBOL(pcmcia_release_window
);
435 int pcmcia_request_configuration(struct pcmcia_device
*p_dev
,
440 struct pcmcia_socket
*s
= p_dev
->socket
;
444 if (!(s
->state
& SOCKET_PRESENT
))
447 if (req
->IntType
& INT_CARDBUS
) {
448 dev_dbg(&p_dev
->dev
, "IntType may not be INT_CARDBUS\n");
452 mutex_lock(&s
->ops_mutex
);
453 c
= p_dev
->function_config
;
454 if (c
->state
& CONFIG_LOCKED
) {
455 mutex_unlock(&s
->ops_mutex
);
456 dev_dbg(&p_dev
->dev
, "Configuration is locked\n");
460 /* Do power control. We don't allow changes in Vcc. */
461 s
->socket
.Vpp
= req
->Vpp
;
462 if (s
->ops
->set_socket(s
, &s
->socket
)) {
463 mutex_unlock(&s
->ops_mutex
);
464 dev_printk(KERN_WARNING
, &p_dev
->dev
,
465 "Unable to set socket state\n");
469 /* Pick memory or I/O card, DMA mode, interrupt */
470 c
->IntType
= req
->IntType
;
471 c
->Attributes
= req
->Attributes
;
472 if (req
->IntType
& INT_MEMORY_AND_IO
)
473 s
->socket
.flags
|= SS_IOCARD
;
474 if (req
->IntType
& INT_ZOOMED_VIDEO
)
475 s
->socket
.flags
|= SS_ZVCARD
| SS_IOCARD
;
476 if (req
->Attributes
& CONF_ENABLE_DMA
)
477 s
->socket
.flags
|= SS_DMA_MODE
;
478 if (req
->Attributes
& CONF_ENABLE_SPKR
)
479 s
->socket
.flags
|= SS_SPKR_ENA
;
480 if (req
->Attributes
& CONF_ENABLE_IRQ
)
481 s
->socket
.io_irq
= s
->pcmcia_irq
;
483 s
->socket
.io_irq
= 0;
484 s
->ops
->set_socket(s
, &s
->socket
);
487 /* Set up CIS configuration registers */
488 base
= c
->ConfigBase
= req
->ConfigBase
;
489 c
->CardValues
= req
->Present
;
490 if (req
->Present
& PRESENT_COPY
) {
492 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
494 if (req
->Present
& PRESENT_OPTION
) {
495 if (s
->functions
== 1) {
496 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
498 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
499 c
->Option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
500 if (req
->Present
& PRESENT_IOBASE_0
)
501 c
->Option
|= COR_ADDR_DECODE
;
503 if ((req
->Attributes
& CONF_ENABLE_IRQ
) &&
504 !(req
->Attributes
& CONF_ENABLE_PULSE_IRQ
))
505 c
->Option
|= COR_LEVEL_REQ
;
506 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
509 if (req
->Present
& PRESENT_STATUS
) {
510 c
->Status
= req
->Status
;
511 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
513 if (req
->Present
& PRESENT_PIN_REPLACE
) {
515 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
517 if (req
->Present
& PRESENT_EXT_STATUS
) {
518 c
->ExtStatus
= req
->ExtStatus
;
519 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
521 if (req
->Present
& PRESENT_IOBASE_0
) {
522 u8 b
= c
->io
[0].start
& 0xff;
523 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
524 b
= (c
->io
[0].start
>> 8) & 0xff;
525 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
527 if (req
->Present
& PRESENT_IOSIZE
) {
528 u8 b
= resource_size(&c
->io
[0]) + resource_size(&c
->io
[1]) - 1;
529 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
532 /* Configure I/O windows */
533 if (c
->state
& CONFIG_IO_REQ
) {
534 iomap
.speed
= io_speed
;
535 for (i
= 0; i
< MAX_IO_WIN
; i
++)
538 iomap
.flags
= MAP_ACTIVE
;
539 switch (s
->io
[i
].res
->flags
& IO_DATA_PATH_WIDTH
) {
540 case IO_DATA_PATH_WIDTH_16
:
541 iomap
.flags
|= MAP_16BIT
; break;
542 case IO_DATA_PATH_WIDTH_AUTO
:
543 iomap
.flags
|= MAP_AUTOSZ
; break;
547 iomap
.start
= s
->io
[i
].res
->start
;
548 iomap
.stop
= s
->io
[i
].res
->end
;
549 s
->ops
->set_io_map(s
, &iomap
);
554 c
->state
|= CONFIG_LOCKED
;
556 mutex_unlock(&s
->ops_mutex
);
558 } /* pcmcia_request_configuration */
559 EXPORT_SYMBOL(pcmcia_request_configuration
);
563 * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
565 * pcmcia_request_io() attepts to reserve the IO port ranges specified in
566 * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The
567 * "start" value is the requested start of the IO port resource; "end"
568 * reflects the number of ports requested. The number of IO lines requested
569 * is specified in &struct pcmcia_device @p_dev->io_lines.
571 int pcmcia_request_io(struct pcmcia_device
*p_dev
)
573 struct pcmcia_socket
*s
= p_dev
->socket
;
574 config_t
*c
= p_dev
->function_config
;
577 mutex_lock(&s
->ops_mutex
);
578 dev_dbg(&p_dev
->dev
, "pcmcia_request_io: %pR , %pR",
579 &c
->io
[0], &c
->io
[1]);
581 if (!(s
->state
& SOCKET_PRESENT
)) {
582 dev_dbg(&p_dev
->dev
, "pcmcia_request_io: No card present\n");
586 if (c
->state
& CONFIG_LOCKED
) {
587 dev_dbg(&p_dev
->dev
, "Configuration is locked\n");
590 if (c
->state
& CONFIG_IO_REQ
) {
591 dev_dbg(&p_dev
->dev
, "IO already configured\n");
595 ret
= alloc_io_space(s
, &c
->io
[0], p_dev
->io_lines
);
600 ret
= alloc_io_space(s
, &c
->io
[1], p_dev
->io_lines
);
602 struct resource tmp
= c
->io
[0];
603 /* release the previously allocated resource */
604 release_io_space(s
, &c
->io
[0]);
605 /* but preserve the settings, for they worked... */
606 c
->io
[0].end
= resource_size(&tmp
);
607 c
->io
[0].start
= tmp
.start
;
608 c
->io
[0].flags
= tmp
.flags
;
614 c
->state
|= CONFIG_IO_REQ
;
617 dev_dbg(&p_dev
->dev
, "pcmcia_request_io succeeded: %pR , %pR",
618 &c
->io
[0], &c
->io
[1]);
620 mutex_unlock(&s
->ops_mutex
);
623 } /* pcmcia_request_io */
624 EXPORT_SYMBOL(pcmcia_request_io
);
628 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
630 * pcmcia_request_irq() is a wrapper around request_irq which will allow
631 * the PCMCIA core to clean up the registration in pcmcia_disable_device().
632 * Drivers are free to use request_irq() directly, but then they need to
633 * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ
634 * handlers are allowed.
636 int __must_check
pcmcia_request_irq(struct pcmcia_device
*p_dev
,
637 irq_handler_t handler
)
644 ret
= request_irq(p_dev
->irq
, handler
, IRQF_SHARED
,
645 p_dev
->devname
, p_dev
->priv
);
651 EXPORT_SYMBOL(pcmcia_request_irq
);
655 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
657 * pcmcia_request_exclusive_irq() is a wrapper around request_irq which
658 * attempts first to request an exclusive IRQ. If it fails, it also accepts
659 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
660 * IRQ sharing and either use request_irq directly (then they need to call
661 * free_irq themselves, too), or the pcmcia_request_irq() function.
664 __pcmcia_request_exclusive_irq(struct pcmcia_device
*p_dev
,
665 irq_handler_t handler
)
672 ret
= request_irq(p_dev
->irq
, handler
, 0, p_dev
->devname
, p_dev
->priv
);
674 ret
= pcmcia_request_irq(p_dev
, handler
);
675 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: "
676 "request for exclusive IRQ could not be fulfilled.\n");
677 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: the driver "
678 "needs updating to supported shared IRQ lines.\n");
681 dev_printk(KERN_INFO
, &p_dev
->dev
, "request_irq() failed\n");
686 } /* pcmcia_request_exclusive_irq */
687 EXPORT_SYMBOL(__pcmcia_request_exclusive_irq
);
690 #ifdef CONFIG_PCMCIA_PROBE
692 /* mask of IRQs already reserved by other cards, we should avoid using them */
693 static u8 pcmcia_used_irq
[32];
695 static irqreturn_t
test_action(int cpl
, void *dev_id
)
701 * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used
702 * @p_dev - the associated PCMCIA device
704 * locking note: must be called with ops_mutex locked.
706 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
708 struct pcmcia_socket
*s
= p_dev
->socket
;
709 unsigned int try, irq
;
710 u32 mask
= s
->irq_mask
;
713 for (try = 0; try < 64; try++) {
719 /* marked as available by driver, not blocked by userspace? */
720 if (!((mask
>> irq
) & 1))
723 /* avoid an IRQ which is already used by another PCMCIA card */
724 if ((try < 32) && pcmcia_used_irq
[irq
])
727 /* register the correct driver, if possible, to check whether
728 * registering a dummy handle works, i.e. if the IRQ isn't
729 * marked as used by the kernel resource management core */
730 ret
= request_irq(irq
, test_action
, type
, p_dev
->devname
,
733 free_irq(irq
, p_dev
);
734 p_dev
->irq
= s
->pcmcia_irq
= irq
;
735 pcmcia_used_irq
[irq
]++;
743 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
745 pcmcia_used_irq
[s
->pcmcia_irq
]--;
749 #else /* CONFIG_PCMCIA_PROBE */
751 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
756 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
762 #endif /* CONFIG_PCMCIA_PROBE */
766 * pcmcia_setup_irq() - determine IRQ to be used for device
767 * @p_dev - the associated PCMCIA device
769 * locking note: must be called with ops_mutex locked.
771 int pcmcia_setup_irq(struct pcmcia_device
*p_dev
)
773 struct pcmcia_socket
*s
= p_dev
->socket
;
778 /* already assigned? */
780 p_dev
->irq
= s
->pcmcia_irq
;
784 /* prefer an exclusive ISA irq */
785 if (!pcmcia_setup_isa_irq(p_dev
, 0))
788 /* but accept a shared ISA irq */
789 if (!pcmcia_setup_isa_irq(p_dev
, IRQF_SHARED
))
792 /* but use the PCI irq otherwise */
794 p_dev
->irq
= s
->pcmcia_irq
= s
->pci_irq
;
803 * pcmcia_request_window() - attempt to reserve iomem for PCMCIA devices
805 * pcmcia_request_window() attepts to reserve an iomem ranges specified in
806 * struct resource *res pointing to one of the entries in
807 * struct pcmcia_device *p_dev->resource[2..5]. The "start" value is the
808 * requested start of the IO mem resource; "end" reflects the size
811 int pcmcia_request_window(struct pcmcia_device
*p_dev
, struct resource
*res
,
814 struct pcmcia_socket
*s
= p_dev
->socket
;
819 if (!(s
->state
& SOCKET_PRESENT
)) {
820 dev_dbg(&p_dev
->dev
, "No card present\n");
824 /* Window size defaults to smallest available */
826 res
->end
= s
->map_size
;
827 align
= (s
->features
& SS_CAP_MEM_ALIGN
) ? res
->end
: s
->map_size
;
828 if (res
->end
& (s
->map_size
-1)) {
829 dev_dbg(&p_dev
->dev
, "invalid map size\n");
832 if ((res
->start
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
833 (res
->start
& (align
-1))) {
834 dev_dbg(&p_dev
->dev
, "invalid base address\n");
840 /* Allocate system memory window */
841 mutex_lock(&s
->ops_mutex
);
842 for (w
= 0; w
< MAX_WIN
; w
++)
843 if (!(s
->state
& SOCKET_WIN_REQ(w
)))
846 dev_dbg(&p_dev
->dev
, "all windows are used already\n");
847 mutex_unlock(&s
->ops_mutex
);
853 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
854 win
->res
= pcmcia_find_mem_region(res
->start
, res
->end
, align
,
857 dev_dbg(&p_dev
->dev
, "allocating mem region failed\n");
858 mutex_unlock(&s
->ops_mutex
);
862 p_dev
->_win
|= CLIENT_WIN_REQ(w
);
864 /* Configure the socket controller */
866 win
->flags
= res
->flags
& WIN_FLAGS_MAP
;
870 if (s
->ops
->set_mem_map(s
, win
) != 0) {
871 dev_dbg(&p_dev
->dev
, "failed to set memory mapping\n");
872 mutex_unlock(&s
->ops_mutex
);
875 s
->state
|= SOCKET_WIN_REQ(w
);
877 /* Return window handle */
878 if (s
->features
& SS_CAP_STATIC_MAP
)
879 res
->start
= win
->static_start
;
881 res
->start
= win
->res
->start
;
883 /* convert to new-style resources */
884 res
->end
+= res
->start
- 1;
885 res
->flags
&= ~WIN_FLAGS_REQ
;
886 res
->flags
|= (win
->map
<< 2) | IORESOURCE_MEM
;
887 res
->parent
= win
->res
;
889 request_resource(&iomem_resource
, res
);
891 dev_dbg(&p_dev
->dev
, "request_window results in %pR\n", res
);
893 mutex_unlock(&s
->ops_mutex
);
896 } /* pcmcia_request_window */
897 EXPORT_SYMBOL(pcmcia_request_window
);
899 void pcmcia_disable_device(struct pcmcia_device
*p_dev
)
902 for (i
= 0; i
< MAX_WIN
; i
++) {
903 struct resource
*res
= p_dev
->resource
[MAX_IO_WIN
+ i
];
904 if (res
->flags
& WIN_FLAGS_REQ
)
905 pcmcia_release_window(p_dev
, res
);
908 pcmcia_release_configuration(p_dev
);
909 pcmcia_release_io(p_dev
);
911 free_irq(p_dev
->irq
, p_dev
->priv
);
915 EXPORT_SYMBOL(pcmcia_disable_device
);