This source file includes following definitions.
- pcmcia_validate_mem
- pcmcia_find_mem_region
- release_io_space
- alloc_io_space
- pcmcia_access_config
- pcmcia_read_config_byte
- pcmcia_write_config_byte
- pcmcia_map_mem_page
- pcmcia_fixup_iowidth
- pcmcia_fixup_vpp
- pcmcia_release_configuration
- pcmcia_release_io
- pcmcia_release_window
- pcmcia_enable_device
- pcmcia_request_io
- pcmcia_request_irq
- test_action
- pcmcia_setup_isa_irq
- pcmcia_cleanup_irq
- pcmcia_setup_isa_irq
- pcmcia_cleanup_irq
- pcmcia_setup_irq
- pcmcia_request_window
- pcmcia_disable_device
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/interrupt.h>
16 #include <linux/delay.h>
17 #include <linux/pci.h>
18 #include <linux/device.h>
19 #include <linux/netdevice.h>
20 #include <linux/slab.h>
21
22 #include <asm/irq.h>
23
24 #include <pcmcia/ss.h>
25 #include <pcmcia/cistpl.h>
26 #include <pcmcia/cisreg.h>
27 #include <pcmcia/ds.h>
28
29 #include "cs_internal.h"
30
31
32
33 static int io_speed;
34 module_param(io_speed, int, 0444);
35
36
37 int pcmcia_validate_mem(struct pcmcia_socket *s)
38 {
39 if (s->resource_ops->validate_mem)
40 return s->resource_ops->validate_mem(s);
41
42 return 0;
43 }
44
45 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
46 int low, struct pcmcia_socket *s)
47 {
48 if (s->resource_ops->find_mem)
49 return s->resource_ops->find_mem(base, num, align, low, s);
50 return NULL;
51 }
52
53
54
55
56
57
58
59
60 static void release_io_space(struct pcmcia_socket *s, struct resource *res)
61 {
62 resource_size_t num = resource_size(res);
63 int i;
64
65 dev_dbg(&s->dev, "release_io_space for %pR\n", res);
66
67 for (i = 0; i < MAX_IO_WIN; i++) {
68 if (!s->io[i].res)
69 continue;
70 if ((s->io[i].res->start <= res->start) &&
71 (s->io[i].res->end >= res->end)) {
72 s->io[i].InUse -= num;
73 if (res->parent)
74 release_resource(res);
75 res->start = res->end = 0;
76 res->flags = IORESOURCE_IO;
77
78 if (s->io[i].InUse == 0) {
79 release_resource(s->io[i].res);
80 kfree(s->io[i].res);
81 s->io[i].res = NULL;
82 }
83 }
84 }
85 }
86
87
88
89
90
91
92
93
94
95
96 static int alloc_io_space(struct pcmcia_socket *s, struct resource *res,
97 unsigned int lines)
98 {
99 unsigned int align;
100 unsigned int base = res->start;
101 unsigned int num = res->end;
102 int ret;
103
104 res->flags |= IORESOURCE_IO;
105
106 dev_dbg(&s->dev, "alloc_io_space request for %pR, %d lines\n",
107 res, lines);
108
109 align = base ? (lines ? 1<<lines : 0) : 1;
110 if (align && (align < num)) {
111 if (base) {
112 dev_dbg(&s->dev, "odd IO request\n");
113 align = 0;
114 } else
115 while (align && (align < num))
116 align <<= 1;
117 }
118 if (base & ~(align-1)) {
119 dev_dbg(&s->dev, "odd IO request\n");
120 align = 0;
121 }
122
123 ret = s->resource_ops->find_io(s, res->flags, &base, num, align,
124 &res->parent);
125 if (ret) {
126 dev_dbg(&s->dev, "alloc_io_space request failed (%d)\n", ret);
127 return -EINVAL;
128 }
129
130 res->start = base;
131 res->end = res->start + num - 1;
132
133 if (res->parent) {
134 ret = request_resource(res->parent, res);
135 if (ret) {
136 dev_warn(&s->dev,
137 "request_resource %pR failed: %d\n", res, ret);
138 res->parent = NULL;
139 release_io_space(s, res);
140 }
141 }
142 dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res);
143 return ret;
144 }
145
146
147
148
149
150
151
152
153
154
155 static int pcmcia_access_config(struct pcmcia_device *p_dev,
156 off_t where, u8 *val,
157 int (*accessf) (struct pcmcia_socket *s,
158 int attr, unsigned int addr,
159 unsigned int len, void *ptr))
160 {
161 struct pcmcia_socket *s;
162 config_t *c;
163 int addr;
164 int ret = 0;
165
166 s = p_dev->socket;
167
168 mutex_lock(&s->ops_mutex);
169 c = p_dev->function_config;
170
171 if (!(c->state & CONFIG_LOCKED)) {
172 dev_dbg(&p_dev->dev, "Configuration isn't locked\n");
173 mutex_unlock(&s->ops_mutex);
174 return -EACCES;
175 }
176
177 addr = (p_dev->config_base + where) >> 1;
178
179 ret = accessf(s, 1, addr, 1, val);
180
181 mutex_unlock(&s->ops_mutex);
182
183 return ret;
184 }
185
186
187
188
189
190
191
192
193 int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val)
194 {
195 return pcmcia_access_config(p_dev, where, val, pcmcia_read_cis_mem);
196 }
197 EXPORT_SYMBOL(pcmcia_read_config_byte);
198
199
200
201
202
203
204
205
206 int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val)
207 {
208 return pcmcia_access_config(p_dev, where, &val, pcmcia_write_cis_mem);
209 }
210 EXPORT_SYMBOL(pcmcia_write_config_byte);
211
212
213
214
215
216
217
218
219
220
221
222
223 int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
224 unsigned int offset)
225 {
226 struct pcmcia_socket *s = p_dev->socket;
227 unsigned int w;
228 int ret;
229
230 w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1;
231 if (w >= MAX_WIN)
232 return -EINVAL;
233
234 mutex_lock(&s->ops_mutex);
235 s->win[w].card_start = offset;
236 ret = s->ops->set_mem_map(s, &s->win[w]);
237 if (ret)
238 dev_warn(&p_dev->dev, "failed to set_mem_map\n");
239 mutex_unlock(&s->ops_mutex);
240 return ret;
241 }
242 EXPORT_SYMBOL(pcmcia_map_mem_page);
243
244
245
246
247
248
249
250
251
252
253 int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev)
254 {
255 struct pcmcia_socket *s = p_dev->socket;
256 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
257 pccard_io_map io_on;
258 int i, ret = 0;
259
260 mutex_lock(&s->ops_mutex);
261
262 dev_dbg(&p_dev->dev, "fixup iowidth to 8bit\n");
263
264 if (!(s->state & SOCKET_PRESENT) ||
265 !(p_dev->function_config->state & CONFIG_LOCKED)) {
266 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
267 ret = -EACCES;
268 goto unlock;
269 }
270
271 io_on.speed = io_speed;
272 for (i = 0; i < MAX_IO_WIN; i++) {
273 if (!s->io[i].res)
274 continue;
275 io_off.map = i;
276 io_on.map = i;
277
278 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
279 io_on.start = s->io[i].res->start;
280 io_on.stop = s->io[i].res->end;
281
282 s->ops->set_io_map(s, &io_off);
283 msleep(40);
284 s->ops->set_io_map(s, &io_on);
285 }
286 unlock:
287 mutex_unlock(&s->ops_mutex);
288
289 return ret;
290 }
291 EXPORT_SYMBOL(pcmcia_fixup_iowidth);
292
293
294
295
296
297
298
299
300
301
302
303 int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp)
304 {
305 struct pcmcia_socket *s = p_dev->socket;
306 int ret = 0;
307
308 mutex_lock(&s->ops_mutex);
309
310 dev_dbg(&p_dev->dev, "fixup Vpp to %d\n", new_vpp);
311
312 if (!(s->state & SOCKET_PRESENT) ||
313 !(p_dev->function_config->state & CONFIG_LOCKED)) {
314 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
315 ret = -EACCES;
316 goto unlock;
317 }
318
319 s->socket.Vpp = new_vpp;
320 if (s->ops->set_socket(s, &s->socket)) {
321 dev_warn(&p_dev->dev, "Unable to set VPP\n");
322 ret = -EIO;
323 goto unlock;
324 }
325 p_dev->vpp = new_vpp;
326
327 unlock:
328 mutex_unlock(&s->ops_mutex);
329
330 return ret;
331 }
332 EXPORT_SYMBOL(pcmcia_fixup_vpp);
333
334
335
336
337
338
339
340
341
342
343
344
345
346 int pcmcia_release_configuration(struct pcmcia_device *p_dev)
347 {
348 pccard_io_map io = { 0, 0, 0, 0, 1 };
349 struct pcmcia_socket *s = p_dev->socket;
350 config_t *c;
351 int i;
352
353 mutex_lock(&s->ops_mutex);
354 c = p_dev->function_config;
355 if (p_dev->_locked) {
356 p_dev->_locked = 0;
357 if (--(s->lock_count) == 0) {
358 s->socket.flags = SS_OUTPUT_ENA;
359 s->socket.Vpp = 0;
360 s->socket.io_irq = 0;
361 s->ops->set_socket(s, &s->socket);
362 }
363 }
364 if (c->state & CONFIG_LOCKED) {
365 c->state &= ~CONFIG_LOCKED;
366 if (c->state & CONFIG_IO_REQ)
367 for (i = 0; i < MAX_IO_WIN; i++) {
368 if (!s->io[i].res)
369 continue;
370 s->io[i].Config--;
371 if (s->io[i].Config != 0)
372 continue;
373 io.map = i;
374 s->ops->set_io_map(s, &io);
375 }
376 }
377 mutex_unlock(&s->ops_mutex);
378
379 return 0;
380 }
381
382
383
384
385
386
387
388
389
390
391
392
393 static int pcmcia_release_io(struct pcmcia_device *p_dev)
394 {
395 struct pcmcia_socket *s = p_dev->socket;
396 int ret = -EINVAL;
397 config_t *c;
398
399 mutex_lock(&s->ops_mutex);
400 if (!p_dev->_io)
401 goto out;
402
403 c = p_dev->function_config;
404
405 release_io_space(s, &c->io[0]);
406
407 if (c->io[1].end)
408 release_io_space(s, &c->io[1]);
409
410 p_dev->_io = 0;
411 c->state &= ~CONFIG_IO_REQ;
412
413 out:
414 mutex_unlock(&s->ops_mutex);
415
416 return ret;
417 }
418
419
420
421
422
423
424
425
426
427
428 int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
429 {
430 struct pcmcia_socket *s = p_dev->socket;
431 pccard_mem_map *win;
432 unsigned int w;
433
434 dev_dbg(&p_dev->dev, "releasing window %pR\n", res);
435
436 w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1;
437 if (w >= MAX_WIN)
438 return -EINVAL;
439
440 mutex_lock(&s->ops_mutex);
441 win = &s->win[w];
442
443 if (!(p_dev->_win & CLIENT_WIN_REQ(w))) {
444 dev_dbg(&p_dev->dev, "not releasing unknown window\n");
445 mutex_unlock(&s->ops_mutex);
446 return -EINVAL;
447 }
448
449
450 win->flags &= ~MAP_ACTIVE;
451 s->ops->set_mem_map(s, win);
452 s->state &= ~SOCKET_WIN_REQ(w);
453
454
455 if (win->res) {
456 release_resource(res);
457 release_resource(win->res);
458 kfree(win->res);
459 win->res = NULL;
460 }
461 res->start = res->end = 0;
462 res->flags = IORESOURCE_MEM;
463 p_dev->_win &= ~CLIENT_WIN_REQ(w);
464 mutex_unlock(&s->ops_mutex);
465
466 return 0;
467 }
468 EXPORT_SYMBOL(pcmcia_release_window);
469
470
471
472
473
474
475
476
477
478
479
480 int pcmcia_enable_device(struct pcmcia_device *p_dev)
481 {
482 int i;
483 unsigned int base;
484 struct pcmcia_socket *s = p_dev->socket;
485 config_t *c;
486 pccard_io_map iomap;
487 unsigned char status = 0;
488 unsigned char ext_status = 0;
489 unsigned char option = 0;
490 unsigned int flags = p_dev->config_flags;
491
492 if (!(s->state & SOCKET_PRESENT))
493 return -ENODEV;
494
495 mutex_lock(&s->ops_mutex);
496 c = p_dev->function_config;
497 if (c->state & CONFIG_LOCKED) {
498 mutex_unlock(&s->ops_mutex);
499 dev_dbg(&p_dev->dev, "Configuration is locked\n");
500 return -EACCES;
501 }
502
503
504 s->socket.Vpp = p_dev->vpp;
505 if (s->ops->set_socket(s, &s->socket)) {
506 mutex_unlock(&s->ops_mutex);
507 dev_warn(&p_dev->dev, "Unable to set socket state\n");
508 return -EINVAL;
509 }
510
511
512 if (p_dev->_io || flags & CONF_ENABLE_IRQ)
513 flags |= CONF_ENABLE_IOCARD;
514 if (flags & CONF_ENABLE_IOCARD)
515 s->socket.flags |= SS_IOCARD;
516 if (flags & CONF_ENABLE_ZVCARD)
517 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
518 if (flags & CONF_ENABLE_SPKR) {
519 s->socket.flags |= SS_SPKR_ENA;
520 status = CCSR_AUDIO_ENA;
521 if (!(p_dev->config_regs & PRESENT_STATUS))
522 dev_warn(&p_dev->dev, "speaker requested, but "
523 "PRESENT_STATUS not set!\n");
524 }
525 if (flags & CONF_ENABLE_IRQ)
526 s->socket.io_irq = s->pcmcia_irq;
527 else
528 s->socket.io_irq = 0;
529 if (flags & CONF_ENABLE_ESR) {
530 p_dev->config_regs |= PRESENT_EXT_STATUS;
531 ext_status = ESR_REQ_ATTN_ENA;
532 }
533 s->ops->set_socket(s, &s->socket);
534 s->lock_count++;
535
536 dev_dbg(&p_dev->dev,
537 "enable_device: V %d, flags %x, base %x, regs %x, idx %x\n",
538 p_dev->vpp, flags, p_dev->config_base, p_dev->config_regs,
539 p_dev->config_index);
540
541
542 base = p_dev->config_base;
543 if (p_dev->config_regs & PRESENT_COPY) {
544 u16 tmp = 0;
545 dev_dbg(&p_dev->dev, "clearing CISREG_SCR\n");
546 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &tmp);
547 }
548 if (p_dev->config_regs & PRESENT_PIN_REPLACE) {
549 u16 tmp = 0;
550 dev_dbg(&p_dev->dev, "clearing CISREG_PRR\n");
551 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &tmp);
552 }
553 if (p_dev->config_regs & PRESENT_OPTION) {
554 if (s->functions == 1) {
555 option = p_dev->config_index & COR_CONFIG_MASK;
556 } else {
557 option = p_dev->config_index & COR_MFC_CONFIG_MASK;
558 option |= COR_FUNC_ENA|COR_IREQ_ENA;
559 if (p_dev->config_regs & PRESENT_IOBASE_0)
560 option |= COR_ADDR_DECODE;
561 }
562 if ((flags & CONF_ENABLE_IRQ) &&
563 !(flags & CONF_ENABLE_PULSE_IRQ))
564 option |= COR_LEVEL_REQ;
565 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &option);
566 msleep(40);
567 }
568 if (p_dev->config_regs & PRESENT_STATUS)
569 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &status);
570
571 if (p_dev->config_regs & PRESENT_EXT_STATUS)
572 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1,
573 &ext_status);
574
575 if (p_dev->config_regs & PRESENT_IOBASE_0) {
576 u8 b = c->io[0].start & 0xff;
577 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
578 b = (c->io[0].start >> 8) & 0xff;
579 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
580 }
581 if (p_dev->config_regs & PRESENT_IOSIZE) {
582 u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1;
583 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
584 }
585
586
587 if (c->state & CONFIG_IO_REQ) {
588 iomap.speed = io_speed;
589 for (i = 0; i < MAX_IO_WIN; i++)
590 if (s->io[i].res) {
591 iomap.map = i;
592 iomap.flags = MAP_ACTIVE;
593 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
594 case IO_DATA_PATH_WIDTH_16:
595 iomap.flags |= MAP_16BIT; break;
596 case IO_DATA_PATH_WIDTH_AUTO:
597 iomap.flags |= MAP_AUTOSZ; break;
598 default:
599 break;
600 }
601 iomap.start = s->io[i].res->start;
602 iomap.stop = s->io[i].res->end;
603 s->ops->set_io_map(s, &iomap);
604 s->io[i].Config++;
605 }
606 }
607
608 c->state |= CONFIG_LOCKED;
609 p_dev->_locked = 1;
610 mutex_unlock(&s->ops_mutex);
611 return 0;
612 }
613 EXPORT_SYMBOL(pcmcia_enable_device);
614
615
616
617
618
619
620
621
622
623
624
625
626 int pcmcia_request_io(struct pcmcia_device *p_dev)
627 {
628 struct pcmcia_socket *s = p_dev->socket;
629 config_t *c = p_dev->function_config;
630 int ret = -EINVAL;
631
632 mutex_lock(&s->ops_mutex);
633 dev_dbg(&p_dev->dev, "pcmcia_request_io: %pR , %pR",
634 &c->io[0], &c->io[1]);
635
636 if (!(s->state & SOCKET_PRESENT)) {
637 dev_dbg(&p_dev->dev, "pcmcia_request_io: No card present\n");
638 goto out;
639 }
640
641 if (c->state & CONFIG_LOCKED) {
642 dev_dbg(&p_dev->dev, "Configuration is locked\n");
643 goto out;
644 }
645 if (c->state & CONFIG_IO_REQ) {
646 dev_dbg(&p_dev->dev, "IO already configured\n");
647 goto out;
648 }
649
650 ret = alloc_io_space(s, &c->io[0], p_dev->io_lines);
651 if (ret)
652 goto out;
653
654 if (c->io[1].end) {
655 ret = alloc_io_space(s, &c->io[1], p_dev->io_lines);
656 if (ret) {
657 struct resource tmp = c->io[0];
658
659 release_io_space(s, &c->io[0]);
660
661 c->io[0].end = resource_size(&tmp);
662 c->io[0].start = tmp.start;
663 c->io[0].flags = tmp.flags;
664 goto out;
665 }
666 } else
667 c->io[1].start = 0;
668
669 c->state |= CONFIG_IO_REQ;
670 p_dev->_io = 1;
671
672 dev_dbg(&p_dev->dev, "pcmcia_request_io succeeded: %pR , %pR",
673 &c->io[0], &c->io[1]);
674 out:
675 mutex_unlock(&s->ops_mutex);
676
677 return ret;
678 }
679 EXPORT_SYMBOL(pcmcia_request_io);
680
681
682
683
684
685
686
687
688
689
690
691
692
693 int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
694 irq_handler_t handler)
695 {
696 int ret;
697
698 if (!p_dev->irq)
699 return -EINVAL;
700
701 ret = request_irq(p_dev->irq, handler, IRQF_SHARED,
702 p_dev->devname, p_dev->priv);
703 if (!ret)
704 p_dev->_irq = 1;
705
706 return ret;
707 }
708 EXPORT_SYMBOL(pcmcia_request_irq);
709
710
711 #ifdef CONFIG_PCMCIA_PROBE
712
713
714 static u8 pcmcia_used_irq[32];
715
716 static irqreturn_t test_action(int cpl, void *dev_id)
717 {
718 return IRQ_NONE;
719 }
720
721
722
723
724
725
726
727 static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
728 {
729 struct pcmcia_socket *s = p_dev->socket;
730 unsigned int try, irq;
731 u32 mask = s->irq_mask;
732 int ret = -ENODEV;
733
734 for (try = 0; try < 64; try++) {
735 irq = try % 32;
736
737 if (irq > NR_IRQS)
738 continue;
739
740
741 if (!((mask >> irq) & 1))
742 continue;
743
744
745 if ((try < 32) && pcmcia_used_irq[irq])
746 continue;
747
748
749
750
751 ret = request_irq(irq, test_action, type, p_dev->devname,
752 p_dev);
753 if (!ret) {
754 free_irq(irq, p_dev);
755 p_dev->irq = s->pcmcia_irq = irq;
756 pcmcia_used_irq[irq]++;
757 break;
758 }
759 }
760
761 return ret;
762 }
763
764 void pcmcia_cleanup_irq(struct pcmcia_socket *s)
765 {
766 pcmcia_used_irq[s->pcmcia_irq]--;
767 s->pcmcia_irq = 0;
768 }
769
770 #else
771
772 static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
773 {
774 return -EINVAL;
775 }
776
777 void pcmcia_cleanup_irq(struct pcmcia_socket *s)
778 {
779 s->pcmcia_irq = 0;
780 return;
781 }
782
783 #endif
784
785
786
787
788
789
790
791
792 int pcmcia_setup_irq(struct pcmcia_device *p_dev)
793 {
794 struct pcmcia_socket *s = p_dev->socket;
795
796 if (p_dev->irq)
797 return 0;
798
799
800 if (s->pcmcia_irq) {
801 p_dev->irq = s->pcmcia_irq;
802 return 0;
803 }
804
805
806 if (!pcmcia_setup_isa_irq(p_dev, 0))
807 return 0;
808
809
810 if (!pcmcia_setup_isa_irq(p_dev, IRQF_SHARED))
811 return 0;
812
813
814 if (s->pci_irq) {
815 p_dev->irq = s->pcmcia_irq = s->pci_irq;
816 return 0;
817 }
818
819 return -EINVAL;
820 }
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835 int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
836 unsigned int speed)
837 {
838 struct pcmcia_socket *s = p_dev->socket;
839 pccard_mem_map *win;
840 u_long align;
841 int w;
842
843 dev_dbg(&p_dev->dev, "request_window %pR %d\n", res, speed);
844
845 if (!(s->state & SOCKET_PRESENT)) {
846 dev_dbg(&p_dev->dev, "No card present\n");
847 return -ENODEV;
848 }
849
850
851 if (res->end == 0)
852 res->end = s->map_size;
853 align = (s->features & SS_CAP_MEM_ALIGN) ? res->end : s->map_size;
854 if (res->end & (s->map_size-1)) {
855 dev_dbg(&p_dev->dev, "invalid map size\n");
856 return -EINVAL;
857 }
858 if ((res->start && (s->features & SS_CAP_STATIC_MAP)) ||
859 (res->start & (align-1))) {
860 dev_dbg(&p_dev->dev, "invalid base address\n");
861 return -EINVAL;
862 }
863 if (res->start)
864 align = 0;
865
866
867 mutex_lock(&s->ops_mutex);
868 for (w = 0; w < MAX_WIN; w++)
869 if (!(s->state & SOCKET_WIN_REQ(w)))
870 break;
871 if (w == MAX_WIN) {
872 dev_dbg(&p_dev->dev, "all windows are used already\n");
873 mutex_unlock(&s->ops_mutex);
874 return -EINVAL;
875 }
876
877 win = &s->win[w];
878
879 if (!(s->features & SS_CAP_STATIC_MAP)) {
880 win->res = pcmcia_find_mem_region(res->start, res->end, align,
881 0, s);
882 if (!win->res) {
883 dev_dbg(&p_dev->dev, "allocating mem region failed\n");
884 mutex_unlock(&s->ops_mutex);
885 return -EINVAL;
886 }
887 }
888 p_dev->_win |= CLIENT_WIN_REQ(w);
889
890
891 win->map = w+1;
892 win->flags = res->flags & WIN_FLAGS_MAP;
893 win->speed = speed;
894 win->card_start = 0;
895
896 if (s->ops->set_mem_map(s, win) != 0) {
897 dev_dbg(&p_dev->dev, "failed to set memory mapping\n");
898 mutex_unlock(&s->ops_mutex);
899 return -EIO;
900 }
901 s->state |= SOCKET_WIN_REQ(w);
902
903
904 if (s->features & SS_CAP_STATIC_MAP)
905 res->start = win->static_start;
906 else
907 res->start = win->res->start;
908
909
910 res->end += res->start - 1;
911 res->flags &= ~WIN_FLAGS_REQ;
912 res->flags |= (win->map << 2) | IORESOURCE_MEM;
913 res->parent = win->res;
914 if (win->res)
915 request_resource(&iomem_resource, res);
916
917 dev_dbg(&p_dev->dev, "request_window results in %pR\n", res);
918
919 mutex_unlock(&s->ops_mutex);
920
921 return 0;
922 }
923 EXPORT_SYMBOL(pcmcia_request_window);
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938 void pcmcia_disable_device(struct pcmcia_device *p_dev)
939 {
940 int i;
941
942 dev_dbg(&p_dev->dev, "disabling device\n");
943
944 for (i = 0; i < MAX_WIN; i++) {
945 struct resource *res = p_dev->resource[MAX_IO_WIN + i];
946 if (res->flags & WIN_FLAGS_REQ)
947 pcmcia_release_window(p_dev, res);
948 }
949
950 pcmcia_release_configuration(p_dev);
951 pcmcia_release_io(p_dev);
952 if (p_dev->_irq) {
953 free_irq(p_dev->irq, p_dev->priv);
954 p_dev->_irq = 0;
955 }
956 }
957 EXPORT_SYMBOL(pcmcia_disable_device);