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/cistpl.h>
30 #include <pcmcia/cisreg.h>
31 #include <pcmcia/ds.h>
33 #include "cs_internal.h"
36 /* Access speed for IO windows */
38 module_param(io_speed
, int, 0444);
41 int pcmcia_validate_mem(struct pcmcia_socket
*s
)
43 if (s
->resource_ops
->validate_mem
)
44 return s
->resource_ops
->validate_mem(s
);
45 /* if there is no callback, we can assume that everything is OK */
49 struct resource
*pcmcia_find_mem_region(u_long base
, u_long num
, u_long align
,
50 int low
, struct pcmcia_socket
*s
)
52 if (s
->resource_ops
->find_mem
)
53 return s
->resource_ops
->find_mem(base
, num
, align
, low
, s
);
58 static void release_io_space(struct pcmcia_socket
*s
, struct resource
*res
)
60 resource_size_t num
= resource_size(res
);
63 dev_dbg(&s
->dev
, "release_io_space for %pR\n", res
);
65 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
68 if ((s
->io
[i
].res
->start
<= res
->start
) &&
69 (s
->io
[i
].res
->end
>= res
->end
)) {
70 s
->io
[i
].InUse
-= num
;
72 release_resource(res
);
73 res
->start
= res
->end
= 0;
74 res
->flags
= IORESOURCE_IO
;
75 /* Free the window if no one else is using it */
76 if (s
->io
[i
].InUse
== 0) {
77 release_resource(s
->io
[i
].res
);
83 } /* release_io_space */
87 * Special stuff for managing IO windows, because they are scarce
89 static int alloc_io_space(struct pcmcia_socket
*s
, struct resource
*res
,
93 unsigned int base
= res
->start
;
94 unsigned int num
= res
->end
;
97 res
->flags
|= IORESOURCE_IO
;
99 dev_dbg(&s
->dev
, "alloc_io_space request for %pR, %d lines\n",
102 align
= base
? (lines
? 1<<lines
: 0) : 1;
103 if (align
&& (align
< num
)) {
105 dev_dbg(&s
->dev
, "odd IO request\n");
108 while (align
&& (align
< num
))
111 if (base
& ~(align
-1)) {
112 dev_dbg(&s
->dev
, "odd IO request\n");
116 ret
= s
->resource_ops
->find_io(s
, res
->flags
, &base
, num
, align
,
119 dev_dbg(&s
->dev
, "alloc_io_space request failed (%d)\n", ret
);
124 res
->end
= res
->start
+ num
- 1;
127 ret
= request_resource(res
->parent
, res
);
130 "request_resource %pR failed: %d\n", res
, ret
);
132 release_io_space(s
, res
);
135 dev_dbg(&s
->dev
, "alloc_io_space request result %d: %pR\n", ret
, res
);
137 } /* alloc_io_space */
141 * pcmcia_access_config() - read or write card configuration registers
143 * pcmcia_access_config() reads and writes configuration registers in
144 * attribute memory. Memory window 0 is reserved for this and the tuple
145 * reading services. Drivers must use pcmcia_read_config_byte() or
146 * pcmcia_write_config_byte().
148 static int pcmcia_access_config(struct pcmcia_device
*p_dev
,
149 off_t where
, u8
*val
,
150 int (*accessf
) (struct pcmcia_socket
*s
,
151 int attr
, unsigned int addr
,
152 unsigned int len
, void *ptr
))
154 struct pcmcia_socket
*s
;
161 mutex_lock(&s
->ops_mutex
);
162 c
= p_dev
->function_config
;
164 if (!(c
->state
& CONFIG_LOCKED
)) {
165 dev_dbg(&p_dev
->dev
, "Configuration isnt't locked\n");
166 mutex_unlock(&s
->ops_mutex
);
170 addr
= (p_dev
->config_base
+ where
) >> 1;
172 ret
= accessf(s
, 1, addr
, 1, val
);
174 mutex_unlock(&s
->ops_mutex
);
177 } /* pcmcia_access_config */
181 * pcmcia_read_config_byte() - read a byte from a card configuration register
183 * pcmcia_read_config_byte() reads a byte from a configuration register in
186 int pcmcia_read_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8
*val
)
188 return pcmcia_access_config(p_dev
, where
, val
, pcmcia_read_cis_mem
);
190 EXPORT_SYMBOL(pcmcia_read_config_byte
);
194 * pcmcia_write_config_byte() - write a byte to a card configuration register
196 * pcmcia_write_config_byte() writes a byte to a configuration register in
199 int pcmcia_write_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8 val
)
201 return pcmcia_access_config(p_dev
, where
, &val
, pcmcia_write_cis_mem
);
203 EXPORT_SYMBOL(pcmcia_write_config_byte
);
206 int pcmcia_map_mem_page(struct pcmcia_device
*p_dev
, struct resource
*res
,
209 struct pcmcia_socket
*s
= p_dev
->socket
;
213 w
= ((res
->flags
& IORESOURCE_BITS
& WIN_FLAGS_REQ
) >> 2) - 1;
217 mutex_lock(&s
->ops_mutex
);
218 s
->win
[w
].card_start
= offset
;
219 ret
= s
->ops
->set_mem_map(s
, &s
->win
[w
]);
221 dev_warn(&p_dev
->dev
, "failed to set_mem_map\n");
222 mutex_unlock(&s
->ops_mutex
);
224 } /* pcmcia_map_mem_page */
225 EXPORT_SYMBOL(pcmcia_map_mem_page
);
229 * pcmcia_fixup_iowidth() - reduce io width to 8bit
231 * pcmcia_fixup_iowidth() allows a PCMCIA device driver to reduce the
232 * IO width to 8bit after having called pcmcia_enable_device()
235 int pcmcia_fixup_iowidth(struct pcmcia_device
*p_dev
)
237 struct pcmcia_socket
*s
= p_dev
->socket
;
238 pccard_io_map io_off
= { 0, 0, 0, 0, 1 };
242 mutex_lock(&s
->ops_mutex
);
244 dev_dbg(&p_dev
->dev
, "fixup iowidth to 8bit\n");
246 if (!(s
->state
& SOCKET_PRESENT
) ||
247 !(p_dev
->function_config
->state
& CONFIG_LOCKED
)) {
248 dev_dbg(&p_dev
->dev
, "No card? Config not locked?\n");
253 io_on
.speed
= io_speed
;
254 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
260 io_on
.flags
= MAP_ACTIVE
| IO_DATA_PATH_WIDTH_8
;
261 io_on
.start
= s
->io
[i
].res
->start
;
262 io_on
.stop
= s
->io
[i
].res
->end
;
264 s
->ops
->set_io_map(s
, &io_off
);
266 s
->ops
->set_io_map(s
, &io_on
);
269 mutex_unlock(&s
->ops_mutex
);
273 EXPORT_SYMBOL(pcmcia_fixup_iowidth
);
277 * pcmcia_fixup_vpp() - set Vpp to a new voltage level
279 * pcmcia_fixup_vpp() allows a PCMCIA device driver to set Vpp to
280 * a new voltage level between calls to pcmcia_enable_device()
281 * and pcmcia_disable_device().
283 int pcmcia_fixup_vpp(struct pcmcia_device
*p_dev
, unsigned char new_vpp
)
285 struct pcmcia_socket
*s
= p_dev
->socket
;
288 mutex_lock(&s
->ops_mutex
);
290 dev_dbg(&p_dev
->dev
, "fixup Vpp to %d\n", new_vpp
);
292 if (!(s
->state
& SOCKET_PRESENT
) ||
293 !(p_dev
->function_config
->state
& CONFIG_LOCKED
)) {
294 dev_dbg(&p_dev
->dev
, "No card? Config not locked?\n");
299 s
->socket
.Vpp
= new_vpp
;
300 if (s
->ops
->set_socket(s
, &s
->socket
)) {
301 dev_warn(&p_dev
->dev
, "Unable to set VPP\n");
305 p_dev
->vpp
= new_vpp
;
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 * pcmcia_enable_device() - set up and activate a PCMCIA device
438 int pcmcia_enable_device(struct pcmcia_device
*p_dev
)
442 struct pcmcia_socket
*s
= p_dev
->socket
;
445 unsigned char status
= 0;
446 unsigned char ext_status
= 0;
447 unsigned char option
= 0;
448 unsigned int flags
= p_dev
->config_flags
;
450 if (!(s
->state
& SOCKET_PRESENT
))
453 mutex_lock(&s
->ops_mutex
);
454 c
= p_dev
->function_config
;
455 if (c
->state
& CONFIG_LOCKED
) {
456 mutex_unlock(&s
->ops_mutex
);
457 dev_dbg(&p_dev
->dev
, "Configuration is locked\n");
461 /* Do power control. We don't allow changes in Vcc. */
462 s
->socket
.Vpp
= p_dev
->vpp
;
463 if (s
->ops
->set_socket(s
, &s
->socket
)) {
464 mutex_unlock(&s
->ops_mutex
);
465 dev_printk(KERN_WARNING
, &p_dev
->dev
,
466 "Unable to set socket state\n");
470 /* Pick memory or I/O card, DMA mode, interrupt */
472 s
->socket
.flags
|= SS_IOCARD
;
473 if (flags
& CONF_ENABLE_SPKR
) {
474 s
->socket
.flags
|= SS_SPKR_ENA
;
475 status
= CCSR_AUDIO_ENA
;
476 if (!(p_dev
->config_regs
& PRESENT_STATUS
))
477 dev_warn(&p_dev
->dev
, "speaker requested, but "
478 "PRESENT_STATUS not set!\n");
480 if (flags
& CONF_ENABLE_IRQ
)
481 s
->socket
.io_irq
= s
->pcmcia_irq
;
483 s
->socket
.io_irq
= 0;
484 if (flags
& CONF_ENABLE_ESR
) {
485 p_dev
->config_regs
|= PRESENT_EXT_STATUS
;
486 ext_status
= ESR_REQ_ATTN_ENA
;
488 s
->ops
->set_socket(s
, &s
->socket
);
491 /* Set up CIS configuration registers */
492 base
= p_dev
->config_base
;
493 if (p_dev
->config_regs
& PRESENT_COPY
) {
495 dev_dbg(&p_dev
->dev
, "clearing CISREG_SCR\n");
496 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &tmp
);
498 if (p_dev
->config_regs
& PRESENT_PIN_REPLACE
) {
500 dev_dbg(&p_dev
->dev
, "clearing CISREG_PRR\n");
501 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &tmp
);
503 if (p_dev
->config_regs
& PRESENT_OPTION
) {
504 if (s
->functions
== 1) {
505 option
= p_dev
->config_index
& COR_CONFIG_MASK
;
507 option
= p_dev
->config_index
& COR_MFC_CONFIG_MASK
;
508 option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
509 if (p_dev
->config_regs
& PRESENT_IOBASE_0
)
510 option
|= COR_ADDR_DECODE
;
512 if ((flags
& CONF_ENABLE_IRQ
) &&
513 !(flags
& CONF_ENABLE_PULSE_IRQ
))
514 option
|= COR_LEVEL_REQ
;
515 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &option
);
518 if (p_dev
->config_regs
& PRESENT_STATUS
)
519 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &status
);
521 if (p_dev
->config_regs
& PRESENT_EXT_STATUS
)
522 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1,
525 if (p_dev
->config_regs
& PRESENT_IOBASE_0
) {
526 u8 b
= c
->io
[0].start
& 0xff;
527 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
528 b
= (c
->io
[0].start
>> 8) & 0xff;
529 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
531 if (p_dev
->config_regs
& PRESENT_IOSIZE
) {
532 u8 b
= resource_size(&c
->io
[0]) + resource_size(&c
->io
[1]) - 1;
533 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
536 /* Configure I/O windows */
537 if (c
->state
& CONFIG_IO_REQ
) {
538 iomap
.speed
= io_speed
;
539 for (i
= 0; i
< MAX_IO_WIN
; i
++)
542 iomap
.flags
= MAP_ACTIVE
;
543 switch (s
->io
[i
].res
->flags
& IO_DATA_PATH_WIDTH
) {
544 case IO_DATA_PATH_WIDTH_16
:
545 iomap
.flags
|= MAP_16BIT
; break;
546 case IO_DATA_PATH_WIDTH_AUTO
:
547 iomap
.flags
|= MAP_AUTOSZ
; break;
551 iomap
.start
= s
->io
[i
].res
->start
;
552 iomap
.stop
= s
->io
[i
].res
->end
;
553 s
->ops
->set_io_map(s
, &iomap
);
558 c
->state
|= CONFIG_LOCKED
;
560 mutex_unlock(&s
->ops_mutex
);
562 } /* pcmcia_enable_device */
563 EXPORT_SYMBOL(pcmcia_enable_device
);
567 * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
569 * pcmcia_request_io() attepts to reserve the IO port ranges specified in
570 * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The
571 * "start" value is the requested start of the IO port resource; "end"
572 * reflects the number of ports requested. The number of IO lines requested
573 * is specified in &struct pcmcia_device @p_dev->io_lines.
575 int pcmcia_request_io(struct pcmcia_device
*p_dev
)
577 struct pcmcia_socket
*s
= p_dev
->socket
;
578 config_t
*c
= p_dev
->function_config
;
581 mutex_lock(&s
->ops_mutex
);
582 dev_dbg(&p_dev
->dev
, "pcmcia_request_io: %pR , %pR",
583 &c
->io
[0], &c
->io
[1]);
585 if (!(s
->state
& SOCKET_PRESENT
)) {
586 dev_dbg(&p_dev
->dev
, "pcmcia_request_io: No card present\n");
590 if (c
->state
& CONFIG_LOCKED
) {
591 dev_dbg(&p_dev
->dev
, "Configuration is locked\n");
594 if (c
->state
& CONFIG_IO_REQ
) {
595 dev_dbg(&p_dev
->dev
, "IO already configured\n");
599 ret
= alloc_io_space(s
, &c
->io
[0], p_dev
->io_lines
);
604 ret
= alloc_io_space(s
, &c
->io
[1], p_dev
->io_lines
);
606 struct resource tmp
= c
->io
[0];
607 /* release the previously allocated resource */
608 release_io_space(s
, &c
->io
[0]);
609 /* but preserve the settings, for they worked... */
610 c
->io
[0].end
= resource_size(&tmp
);
611 c
->io
[0].start
= tmp
.start
;
612 c
->io
[0].flags
= tmp
.flags
;
618 c
->state
|= CONFIG_IO_REQ
;
621 dev_dbg(&p_dev
->dev
, "pcmcia_request_io succeeded: %pR , %pR",
622 &c
->io
[0], &c
->io
[1]);
624 mutex_unlock(&s
->ops_mutex
);
627 } /* pcmcia_request_io */
628 EXPORT_SYMBOL(pcmcia_request_io
);
632 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
634 * pcmcia_request_irq() is a wrapper around request_irq which will allow
635 * the PCMCIA core to clean up the registration in pcmcia_disable_device().
636 * Drivers are free to use request_irq() directly, but then they need to
637 * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ
638 * handlers are allowed.
640 int __must_check
pcmcia_request_irq(struct pcmcia_device
*p_dev
,
641 irq_handler_t handler
)
648 ret
= request_irq(p_dev
->irq
, handler
, IRQF_SHARED
,
649 p_dev
->devname
, p_dev
->priv
);
655 EXPORT_SYMBOL(pcmcia_request_irq
);
659 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
661 * pcmcia_request_exclusive_irq() is a wrapper around request_irq which
662 * attempts first to request an exclusive IRQ. If it fails, it also accepts
663 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
664 * IRQ sharing and either use request_irq directly (then they need to call
665 * free_irq themselves, too), or the pcmcia_request_irq() function.
668 __pcmcia_request_exclusive_irq(struct pcmcia_device
*p_dev
,
669 irq_handler_t handler
)
676 ret
= request_irq(p_dev
->irq
, handler
, 0, p_dev
->devname
, p_dev
->priv
);
678 ret
= pcmcia_request_irq(p_dev
, handler
);
679 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: "
680 "request for exclusive IRQ could not be fulfilled.\n");
681 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: the driver "
682 "needs updating to supported shared IRQ lines.\n");
685 dev_printk(KERN_INFO
, &p_dev
->dev
, "request_irq() failed\n");
690 } /* pcmcia_request_exclusive_irq */
691 EXPORT_SYMBOL(__pcmcia_request_exclusive_irq
);
694 #ifdef CONFIG_PCMCIA_PROBE
696 /* mask of IRQs already reserved by other cards, we should avoid using them */
697 static u8 pcmcia_used_irq
[32];
699 static irqreturn_t
test_action(int cpl
, void *dev_id
)
705 * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used
706 * @p_dev - the associated PCMCIA device
708 * locking note: must be called with ops_mutex locked.
710 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
712 struct pcmcia_socket
*s
= p_dev
->socket
;
713 unsigned int try, irq
;
714 u32 mask
= s
->irq_mask
;
717 for (try = 0; try < 64; try++) {
723 /* marked as available by driver, not blocked by userspace? */
724 if (!((mask
>> irq
) & 1))
727 /* avoid an IRQ which is already used by another PCMCIA card */
728 if ((try < 32) && pcmcia_used_irq
[irq
])
731 /* register the correct driver, if possible, to check whether
732 * registering a dummy handle works, i.e. if the IRQ isn't
733 * marked as used by the kernel resource management core */
734 ret
= request_irq(irq
, test_action
, type
, p_dev
->devname
,
737 free_irq(irq
, p_dev
);
738 p_dev
->irq
= s
->pcmcia_irq
= irq
;
739 pcmcia_used_irq
[irq
]++;
747 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
749 pcmcia_used_irq
[s
->pcmcia_irq
]--;
753 #else /* CONFIG_PCMCIA_PROBE */
755 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
760 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
766 #endif /* CONFIG_PCMCIA_PROBE */
770 * pcmcia_setup_irq() - determine IRQ to be used for device
771 * @p_dev - the associated PCMCIA device
773 * locking note: must be called with ops_mutex locked.
775 int pcmcia_setup_irq(struct pcmcia_device
*p_dev
)
777 struct pcmcia_socket
*s
= p_dev
->socket
;
782 /* already assigned? */
784 p_dev
->irq
= s
->pcmcia_irq
;
788 /* prefer an exclusive ISA irq */
789 if (!pcmcia_setup_isa_irq(p_dev
, 0))
792 /* but accept a shared ISA irq */
793 if (!pcmcia_setup_isa_irq(p_dev
, IRQF_SHARED
))
796 /* but use the PCI irq otherwise */
798 p_dev
->irq
= s
->pcmcia_irq
= s
->pci_irq
;
807 * pcmcia_request_window() - attempt to reserve iomem for PCMCIA devices
809 * pcmcia_request_window() attepts to reserve an iomem ranges specified in
810 * struct resource *res pointing to one of the entries in
811 * struct pcmcia_device *p_dev->resource[2..5]. The "start" value is the
812 * requested start of the IO mem resource; "end" reflects the size
815 int pcmcia_request_window(struct pcmcia_device
*p_dev
, struct resource
*res
,
818 struct pcmcia_socket
*s
= p_dev
->socket
;
823 if (!(s
->state
& SOCKET_PRESENT
)) {
824 dev_dbg(&p_dev
->dev
, "No card present\n");
828 /* Window size defaults to smallest available */
830 res
->end
= s
->map_size
;
831 align
= (s
->features
& SS_CAP_MEM_ALIGN
) ? res
->end
: s
->map_size
;
832 if (res
->end
& (s
->map_size
-1)) {
833 dev_dbg(&p_dev
->dev
, "invalid map size\n");
836 if ((res
->start
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
837 (res
->start
& (align
-1))) {
838 dev_dbg(&p_dev
->dev
, "invalid base address\n");
844 /* Allocate system memory window */
845 mutex_lock(&s
->ops_mutex
);
846 for (w
= 0; w
< MAX_WIN
; w
++)
847 if (!(s
->state
& SOCKET_WIN_REQ(w
)))
850 dev_dbg(&p_dev
->dev
, "all windows are used already\n");
851 mutex_unlock(&s
->ops_mutex
);
857 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
858 win
->res
= pcmcia_find_mem_region(res
->start
, res
->end
, align
,
861 dev_dbg(&p_dev
->dev
, "allocating mem region failed\n");
862 mutex_unlock(&s
->ops_mutex
);
866 p_dev
->_win
|= CLIENT_WIN_REQ(w
);
868 /* Configure the socket controller */
870 win
->flags
= res
->flags
& WIN_FLAGS_MAP
;
874 if (s
->ops
->set_mem_map(s
, win
) != 0) {
875 dev_dbg(&p_dev
->dev
, "failed to set memory mapping\n");
876 mutex_unlock(&s
->ops_mutex
);
879 s
->state
|= SOCKET_WIN_REQ(w
);
881 /* Return window handle */
882 if (s
->features
& SS_CAP_STATIC_MAP
)
883 res
->start
= win
->static_start
;
885 res
->start
= win
->res
->start
;
887 /* convert to new-style resources */
888 res
->end
+= res
->start
- 1;
889 res
->flags
&= ~WIN_FLAGS_REQ
;
890 res
->flags
|= (win
->map
<< 2) | IORESOURCE_MEM
;
891 res
->parent
= win
->res
;
893 request_resource(&iomem_resource
, res
);
895 dev_dbg(&p_dev
->dev
, "request_window results in %pR\n", res
);
897 mutex_unlock(&s
->ops_mutex
);
900 } /* pcmcia_request_window */
901 EXPORT_SYMBOL(pcmcia_request_window
);
903 void pcmcia_disable_device(struct pcmcia_device
*p_dev
)
906 for (i
= 0; i
< MAX_WIN
; i
++) {
907 struct resource
*res
= p_dev
->resource
[MAX_IO_WIN
+ i
];
908 if (res
->flags
& WIN_FLAGS_REQ
)
909 pcmcia_release_window(p_dev
, res
);
912 pcmcia_release_configuration(p_dev
);
913 pcmcia_release_io(p_dev
);
915 free_irq(p_dev
->irq
, p_dev
->priv
);
919 EXPORT_SYMBOL(pcmcia_disable_device
);