0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/module.h>
0014 #include <linux/kernel.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/delay.h>
0017 #include <linux/pci.h>
0018 #include <linux/device.h>
0019 #include <linux/netdevice.h>
0020 #include <linux/slab.h>
0021
0022 #include <asm/irq.h>
0023
0024 #include <pcmcia/ss.h>
0025 #include <pcmcia/cistpl.h>
0026 #include <pcmcia/cisreg.h>
0027 #include <pcmcia/ds.h>
0028
0029 #include "cs_internal.h"
0030
0031
0032
0033 static int io_speed;
0034 module_param(io_speed, int, 0444);
0035
0036
0037 int pcmcia_validate_mem(struct pcmcia_socket *s)
0038 {
0039 if (s->resource_ops->validate_mem)
0040 return s->resource_ops->validate_mem(s);
0041
0042 return 0;
0043 }
0044
0045 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
0046 int low, struct pcmcia_socket *s)
0047 {
0048 if (s->resource_ops->find_mem)
0049 return s->resource_ops->find_mem(base, num, align, low, s);
0050 return NULL;
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060 static void release_io_space(struct pcmcia_socket *s, struct resource *res)
0061 {
0062 resource_size_t num = resource_size(res);
0063 int i;
0064
0065 dev_dbg(&s->dev, "release_io_space for %pR\n", res);
0066
0067 for (i = 0; i < MAX_IO_WIN; i++) {
0068 if (!s->io[i].res)
0069 continue;
0070 if ((s->io[i].res->start <= res->start) &&
0071 (s->io[i].res->end >= res->end)) {
0072 s->io[i].InUse -= num;
0073 if (res->parent)
0074 release_resource(res);
0075 res->start = res->end = 0;
0076 res->flags = IORESOURCE_IO;
0077
0078 if (s->io[i].InUse == 0) {
0079 release_resource(s->io[i].res);
0080 kfree(s->io[i].res);
0081 s->io[i].res = NULL;
0082 }
0083 }
0084 }
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 static int alloc_io_space(struct pcmcia_socket *s, struct resource *res,
0097 unsigned int lines)
0098 {
0099 unsigned int align;
0100 unsigned int base = res->start;
0101 unsigned int num = res->end;
0102 int ret;
0103
0104 res->flags |= IORESOURCE_IO;
0105
0106 dev_dbg(&s->dev, "alloc_io_space request for %pR, %d lines\n",
0107 res, lines);
0108
0109 align = base ? (lines ? 1<<lines : 0) : 1;
0110 if (align && (align < num)) {
0111 if (base) {
0112 dev_dbg(&s->dev, "odd IO request\n");
0113 align = 0;
0114 } else
0115 while (align && (align < num))
0116 align <<= 1;
0117 }
0118 if (base & ~(align-1)) {
0119 dev_dbg(&s->dev, "odd IO request\n");
0120 align = 0;
0121 }
0122
0123 ret = s->resource_ops->find_io(s, res->flags, &base, num, align,
0124 &res->parent);
0125 if (ret) {
0126 dev_dbg(&s->dev, "alloc_io_space request failed (%d)\n", ret);
0127 return -EINVAL;
0128 }
0129
0130 res->start = base;
0131 res->end = res->start + num - 1;
0132
0133 if (res->parent) {
0134 ret = request_resource(res->parent, res);
0135 if (ret) {
0136 dev_warn(&s->dev,
0137 "request_resource %pR failed: %d\n", res, ret);
0138 res->parent = NULL;
0139 release_io_space(s, res);
0140 }
0141 }
0142 dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res);
0143 return ret;
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 static int pcmcia_access_config(struct pcmcia_device *p_dev,
0156 off_t where, u8 *val,
0157 int (*accessf) (struct pcmcia_socket *s,
0158 int attr, unsigned int addr,
0159 unsigned int len, void *ptr))
0160 {
0161 struct pcmcia_socket *s;
0162 config_t *c;
0163 int addr;
0164 int ret = 0;
0165
0166 s = p_dev->socket;
0167
0168 mutex_lock(&s->ops_mutex);
0169 c = p_dev->function_config;
0170
0171 if (!(c->state & CONFIG_LOCKED)) {
0172 dev_dbg(&p_dev->dev, "Configuration isn't locked\n");
0173 mutex_unlock(&s->ops_mutex);
0174 return -EACCES;
0175 }
0176
0177 addr = (p_dev->config_base + where) >> 1;
0178
0179 ret = accessf(s, 1, addr, 1, val);
0180
0181 mutex_unlock(&s->ops_mutex);
0182
0183 return ret;
0184 }
0185
0186
0187
0188
0189
0190
0191
0192
0193 int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val)
0194 {
0195 return pcmcia_access_config(p_dev, where, val, pcmcia_read_cis_mem);
0196 }
0197 EXPORT_SYMBOL(pcmcia_read_config_byte);
0198
0199
0200
0201
0202
0203
0204
0205
0206 int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val)
0207 {
0208 return pcmcia_access_config(p_dev, where, &val, pcmcia_write_cis_mem);
0209 }
0210 EXPORT_SYMBOL(pcmcia_write_config_byte);
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
0224 unsigned int offset)
0225 {
0226 struct pcmcia_socket *s = p_dev->socket;
0227 unsigned int w;
0228 int ret;
0229
0230 w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1;
0231 if (w >= MAX_WIN)
0232 return -EINVAL;
0233
0234 mutex_lock(&s->ops_mutex);
0235 s->win[w].card_start = offset;
0236 ret = s->ops->set_mem_map(s, &s->win[w]);
0237 if (ret)
0238 dev_warn(&p_dev->dev, "failed to set_mem_map\n");
0239 mutex_unlock(&s->ops_mutex);
0240 return ret;
0241 }
0242 EXPORT_SYMBOL(pcmcia_map_mem_page);
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253 int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev)
0254 {
0255 struct pcmcia_socket *s = p_dev->socket;
0256 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
0257 pccard_io_map io_on;
0258 int i, ret = 0;
0259
0260 mutex_lock(&s->ops_mutex);
0261
0262 dev_dbg(&p_dev->dev, "fixup iowidth to 8bit\n");
0263
0264 if (!(s->state & SOCKET_PRESENT) ||
0265 !(p_dev->function_config->state & CONFIG_LOCKED)) {
0266 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
0267 ret = -EACCES;
0268 goto unlock;
0269 }
0270
0271 io_on.speed = io_speed;
0272 for (i = 0; i < MAX_IO_WIN; i++) {
0273 if (!s->io[i].res)
0274 continue;
0275 io_off.map = i;
0276 io_on.map = i;
0277
0278 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
0279 io_on.start = s->io[i].res->start;
0280 io_on.stop = s->io[i].res->end;
0281
0282 s->ops->set_io_map(s, &io_off);
0283 msleep(40);
0284 s->ops->set_io_map(s, &io_on);
0285 }
0286 unlock:
0287 mutex_unlock(&s->ops_mutex);
0288
0289 return ret;
0290 }
0291 EXPORT_SYMBOL(pcmcia_fixup_iowidth);
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303 int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp)
0304 {
0305 struct pcmcia_socket *s = p_dev->socket;
0306 int ret = 0;
0307
0308 mutex_lock(&s->ops_mutex);
0309
0310 dev_dbg(&p_dev->dev, "fixup Vpp to %d\n", new_vpp);
0311
0312 if (!(s->state & SOCKET_PRESENT) ||
0313 !(p_dev->function_config->state & CONFIG_LOCKED)) {
0314 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
0315 ret = -EACCES;
0316 goto unlock;
0317 }
0318
0319 s->socket.Vpp = new_vpp;
0320 if (s->ops->set_socket(s, &s->socket)) {
0321 dev_warn(&p_dev->dev, "Unable to set VPP\n");
0322 ret = -EIO;
0323 goto unlock;
0324 }
0325 p_dev->vpp = new_vpp;
0326
0327 unlock:
0328 mutex_unlock(&s->ops_mutex);
0329
0330 return ret;
0331 }
0332 EXPORT_SYMBOL(pcmcia_fixup_vpp);
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 int pcmcia_release_configuration(struct pcmcia_device *p_dev)
0347 {
0348 pccard_io_map io = { 0, 0, 0, 0, 1 };
0349 struct pcmcia_socket *s = p_dev->socket;
0350 config_t *c;
0351 int i;
0352
0353 mutex_lock(&s->ops_mutex);
0354 c = p_dev->function_config;
0355 if (p_dev->_locked) {
0356 p_dev->_locked = 0;
0357 if (--(s->lock_count) == 0) {
0358 s->socket.flags = SS_OUTPUT_ENA;
0359 s->socket.Vpp = 0;
0360 s->socket.io_irq = 0;
0361 s->ops->set_socket(s, &s->socket);
0362 }
0363 }
0364 if (c->state & CONFIG_LOCKED) {
0365 c->state &= ~CONFIG_LOCKED;
0366 if (c->state & CONFIG_IO_REQ)
0367 for (i = 0; i < MAX_IO_WIN; i++) {
0368 if (!s->io[i].res)
0369 continue;
0370 s->io[i].Config--;
0371 if (s->io[i].Config != 0)
0372 continue;
0373 io.map = i;
0374 s->ops->set_io_map(s, &io);
0375 }
0376 }
0377 mutex_unlock(&s->ops_mutex);
0378
0379 return 0;
0380 }
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393 static void pcmcia_release_io(struct pcmcia_device *p_dev)
0394 {
0395 struct pcmcia_socket *s = p_dev->socket;
0396 config_t *c;
0397
0398 mutex_lock(&s->ops_mutex);
0399 if (!p_dev->_io)
0400 goto out;
0401
0402 c = p_dev->function_config;
0403
0404 release_io_space(s, &c->io[0]);
0405
0406 if (c->io[1].end)
0407 release_io_space(s, &c->io[1]);
0408
0409 p_dev->_io = 0;
0410 c->state &= ~CONFIG_IO_REQ;
0411
0412 out:
0413 mutex_unlock(&s->ops_mutex);
0414 }
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425 int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
0426 {
0427 struct pcmcia_socket *s = p_dev->socket;
0428 pccard_mem_map *win;
0429 unsigned int w;
0430
0431 dev_dbg(&p_dev->dev, "releasing window %pR\n", res);
0432
0433 w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1;
0434 if (w >= MAX_WIN)
0435 return -EINVAL;
0436
0437 mutex_lock(&s->ops_mutex);
0438 win = &s->win[w];
0439
0440 if (!(p_dev->_win & CLIENT_WIN_REQ(w))) {
0441 dev_dbg(&p_dev->dev, "not releasing unknown window\n");
0442 mutex_unlock(&s->ops_mutex);
0443 return -EINVAL;
0444 }
0445
0446
0447 win->flags &= ~MAP_ACTIVE;
0448 s->ops->set_mem_map(s, win);
0449 s->state &= ~SOCKET_WIN_REQ(w);
0450
0451
0452 if (win->res) {
0453 release_resource(res);
0454 release_resource(win->res);
0455 kfree(win->res);
0456 win->res = NULL;
0457 }
0458 res->start = res->end = 0;
0459 res->flags = IORESOURCE_MEM;
0460 p_dev->_win &= ~CLIENT_WIN_REQ(w);
0461 mutex_unlock(&s->ops_mutex);
0462
0463 return 0;
0464 }
0465 EXPORT_SYMBOL(pcmcia_release_window);
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477 int pcmcia_enable_device(struct pcmcia_device *p_dev)
0478 {
0479 int i;
0480 unsigned int base;
0481 struct pcmcia_socket *s = p_dev->socket;
0482 config_t *c;
0483 pccard_io_map iomap;
0484 unsigned char status = 0;
0485 unsigned char ext_status = 0;
0486 unsigned char option = 0;
0487 unsigned int flags = p_dev->config_flags;
0488
0489 if (!(s->state & SOCKET_PRESENT))
0490 return -ENODEV;
0491
0492 mutex_lock(&s->ops_mutex);
0493 c = p_dev->function_config;
0494 if (c->state & CONFIG_LOCKED) {
0495 mutex_unlock(&s->ops_mutex);
0496 dev_dbg(&p_dev->dev, "Configuration is locked\n");
0497 return -EACCES;
0498 }
0499
0500
0501 s->socket.Vpp = p_dev->vpp;
0502 if (s->ops->set_socket(s, &s->socket)) {
0503 mutex_unlock(&s->ops_mutex);
0504 dev_warn(&p_dev->dev, "Unable to set socket state\n");
0505 return -EINVAL;
0506 }
0507
0508
0509 if (p_dev->_io || flags & CONF_ENABLE_IRQ)
0510 flags |= CONF_ENABLE_IOCARD;
0511 if (flags & CONF_ENABLE_IOCARD)
0512 s->socket.flags |= SS_IOCARD;
0513 if (flags & CONF_ENABLE_ZVCARD)
0514 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
0515 if (flags & CONF_ENABLE_SPKR) {
0516 s->socket.flags |= SS_SPKR_ENA;
0517 status = CCSR_AUDIO_ENA;
0518 if (!(p_dev->config_regs & PRESENT_STATUS))
0519 dev_warn(&p_dev->dev, "speaker requested, but "
0520 "PRESENT_STATUS not set!\n");
0521 }
0522 if (flags & CONF_ENABLE_IRQ)
0523 s->socket.io_irq = s->pcmcia_irq;
0524 else
0525 s->socket.io_irq = 0;
0526 if (flags & CONF_ENABLE_ESR) {
0527 p_dev->config_regs |= PRESENT_EXT_STATUS;
0528 ext_status = ESR_REQ_ATTN_ENA;
0529 }
0530 s->ops->set_socket(s, &s->socket);
0531 s->lock_count++;
0532
0533 dev_dbg(&p_dev->dev,
0534 "enable_device: V %d, flags %x, base %x, regs %x, idx %x\n",
0535 p_dev->vpp, flags, p_dev->config_base, p_dev->config_regs,
0536 p_dev->config_index);
0537
0538
0539 base = p_dev->config_base;
0540 if (p_dev->config_regs & PRESENT_COPY) {
0541 u16 tmp = 0;
0542 dev_dbg(&p_dev->dev, "clearing CISREG_SCR\n");
0543 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &tmp);
0544 }
0545 if (p_dev->config_regs & PRESENT_PIN_REPLACE) {
0546 u16 tmp = 0;
0547 dev_dbg(&p_dev->dev, "clearing CISREG_PRR\n");
0548 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &tmp);
0549 }
0550 if (p_dev->config_regs & PRESENT_OPTION) {
0551 if (s->functions == 1) {
0552 option = p_dev->config_index & COR_CONFIG_MASK;
0553 } else {
0554 option = p_dev->config_index & COR_MFC_CONFIG_MASK;
0555 option |= COR_FUNC_ENA|COR_IREQ_ENA;
0556 if (p_dev->config_regs & PRESENT_IOBASE_0)
0557 option |= COR_ADDR_DECODE;
0558 }
0559 if ((flags & CONF_ENABLE_IRQ) &&
0560 !(flags & CONF_ENABLE_PULSE_IRQ))
0561 option |= COR_LEVEL_REQ;
0562 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &option);
0563 msleep(40);
0564 }
0565 if (p_dev->config_regs & PRESENT_STATUS)
0566 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &status);
0567
0568 if (p_dev->config_regs & PRESENT_EXT_STATUS)
0569 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1,
0570 &ext_status);
0571
0572 if (p_dev->config_regs & PRESENT_IOBASE_0) {
0573 u8 b = c->io[0].start & 0xff;
0574 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
0575 b = (c->io[0].start >> 8) & 0xff;
0576 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
0577 }
0578 if (p_dev->config_regs & PRESENT_IOSIZE) {
0579 u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1;
0580 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
0581 }
0582
0583
0584 if (c->state & CONFIG_IO_REQ) {
0585 iomap.speed = io_speed;
0586 for (i = 0; i < MAX_IO_WIN; i++)
0587 if (s->io[i].res) {
0588 iomap.map = i;
0589 iomap.flags = MAP_ACTIVE;
0590 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
0591 case IO_DATA_PATH_WIDTH_16:
0592 iomap.flags |= MAP_16BIT; break;
0593 case IO_DATA_PATH_WIDTH_AUTO:
0594 iomap.flags |= MAP_AUTOSZ; break;
0595 default:
0596 break;
0597 }
0598 iomap.start = s->io[i].res->start;
0599 iomap.stop = s->io[i].res->end;
0600 s->ops->set_io_map(s, &iomap);
0601 s->io[i].Config++;
0602 }
0603 }
0604
0605 c->state |= CONFIG_LOCKED;
0606 p_dev->_locked = 1;
0607 mutex_unlock(&s->ops_mutex);
0608 return 0;
0609 }
0610 EXPORT_SYMBOL(pcmcia_enable_device);
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623 int pcmcia_request_io(struct pcmcia_device *p_dev)
0624 {
0625 struct pcmcia_socket *s = p_dev->socket;
0626 config_t *c = p_dev->function_config;
0627 int ret = -EINVAL;
0628
0629 mutex_lock(&s->ops_mutex);
0630 dev_dbg(&p_dev->dev, "pcmcia_request_io: %pR , %pR",
0631 &c->io[0], &c->io[1]);
0632
0633 if (!(s->state & SOCKET_PRESENT)) {
0634 dev_dbg(&p_dev->dev, "pcmcia_request_io: No card present\n");
0635 goto out;
0636 }
0637
0638 if (c->state & CONFIG_LOCKED) {
0639 dev_dbg(&p_dev->dev, "Configuration is locked\n");
0640 goto out;
0641 }
0642 if (c->state & CONFIG_IO_REQ) {
0643 dev_dbg(&p_dev->dev, "IO already configured\n");
0644 goto out;
0645 }
0646
0647 ret = alloc_io_space(s, &c->io[0], p_dev->io_lines);
0648 if (ret)
0649 goto out;
0650
0651 if (c->io[1].end) {
0652 ret = alloc_io_space(s, &c->io[1], p_dev->io_lines);
0653 if (ret) {
0654 struct resource tmp = c->io[0];
0655
0656 release_io_space(s, &c->io[0]);
0657
0658 c->io[0].end = resource_size(&tmp);
0659 c->io[0].start = tmp.start;
0660 c->io[0].flags = tmp.flags;
0661 goto out;
0662 }
0663 } else
0664 c->io[1].start = 0;
0665
0666 c->state |= CONFIG_IO_REQ;
0667 p_dev->_io = 1;
0668
0669 dev_dbg(&p_dev->dev, "pcmcia_request_io succeeded: %pR , %pR",
0670 &c->io[0], &c->io[1]);
0671 out:
0672 mutex_unlock(&s->ops_mutex);
0673
0674 return ret;
0675 }
0676 EXPORT_SYMBOL(pcmcia_request_io);
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690 int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
0691 irq_handler_t handler)
0692 {
0693 int ret;
0694
0695 if (!p_dev->irq)
0696 return -EINVAL;
0697
0698 ret = request_irq(p_dev->irq, handler, IRQF_SHARED,
0699 p_dev->devname, p_dev->priv);
0700 if (!ret)
0701 p_dev->_irq = 1;
0702
0703 return ret;
0704 }
0705 EXPORT_SYMBOL(pcmcia_request_irq);
0706
0707
0708 #ifdef CONFIG_PCMCIA_PROBE
0709
0710
0711 static u8 pcmcia_used_irq[32];
0712
0713 static irqreturn_t test_action(int cpl, void *dev_id)
0714 {
0715 return IRQ_NONE;
0716 }
0717
0718
0719
0720
0721
0722
0723
0724
0725 static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
0726 {
0727 struct pcmcia_socket *s = p_dev->socket;
0728 unsigned int try, irq;
0729 u32 mask = s->irq_mask;
0730 int ret = -ENODEV;
0731
0732 for (try = 0; try < 64; try++) {
0733 irq = try % 32;
0734
0735 if (irq > NR_IRQS)
0736 continue;
0737
0738
0739 if (!((mask >> irq) & 1))
0740 continue;
0741
0742
0743 if ((try < 32) && pcmcia_used_irq[irq])
0744 continue;
0745
0746
0747
0748
0749 ret = request_irq(irq, test_action, type, p_dev->devname,
0750 p_dev);
0751 if (!ret) {
0752 free_irq(irq, p_dev);
0753 p_dev->irq = s->pcmcia_irq = irq;
0754 pcmcia_used_irq[irq]++;
0755 break;
0756 }
0757 }
0758
0759 return ret;
0760 }
0761
0762 void pcmcia_cleanup_irq(struct pcmcia_socket *s)
0763 {
0764 pcmcia_used_irq[s->pcmcia_irq]--;
0765 s->pcmcia_irq = 0;
0766 }
0767
0768 #else
0769
0770 static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
0771 {
0772 return -EINVAL;
0773 }
0774
0775 void pcmcia_cleanup_irq(struct pcmcia_socket *s)
0776 {
0777 s->pcmcia_irq = 0;
0778 return;
0779 }
0780
0781 #endif
0782
0783
0784
0785
0786
0787
0788
0789
0790 int pcmcia_setup_irq(struct pcmcia_device *p_dev)
0791 {
0792 struct pcmcia_socket *s = p_dev->socket;
0793
0794 if (p_dev->irq)
0795 return 0;
0796
0797
0798 if (s->pcmcia_irq) {
0799 p_dev->irq = s->pcmcia_irq;
0800 return 0;
0801 }
0802
0803
0804 if (!pcmcia_setup_isa_irq(p_dev, 0))
0805 return 0;
0806
0807
0808 if (!pcmcia_setup_isa_irq(p_dev, IRQF_SHARED))
0809 return 0;
0810
0811
0812 if (s->pci_irq) {
0813 p_dev->irq = s->pcmcia_irq = s->pci_irq;
0814 return 0;
0815 }
0816
0817 return -EINVAL;
0818 }
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833 int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
0834 unsigned int speed)
0835 {
0836 struct pcmcia_socket *s = p_dev->socket;
0837 pccard_mem_map *win;
0838 u_long align;
0839 int w;
0840
0841 dev_dbg(&p_dev->dev, "request_window %pR %d\n", res, speed);
0842
0843 if (!(s->state & SOCKET_PRESENT)) {
0844 dev_dbg(&p_dev->dev, "No card present\n");
0845 return -ENODEV;
0846 }
0847
0848
0849 if (res->end == 0)
0850 res->end = s->map_size;
0851 align = (s->features & SS_CAP_MEM_ALIGN) ? res->end : s->map_size;
0852 if (res->end & (s->map_size-1)) {
0853 dev_dbg(&p_dev->dev, "invalid map size\n");
0854 return -EINVAL;
0855 }
0856 if ((res->start && (s->features & SS_CAP_STATIC_MAP)) ||
0857 (res->start & (align-1))) {
0858 dev_dbg(&p_dev->dev, "invalid base address\n");
0859 return -EINVAL;
0860 }
0861 if (res->start)
0862 align = 0;
0863
0864
0865 mutex_lock(&s->ops_mutex);
0866 for (w = 0; w < MAX_WIN; w++)
0867 if (!(s->state & SOCKET_WIN_REQ(w)))
0868 break;
0869 if (w == MAX_WIN) {
0870 dev_dbg(&p_dev->dev, "all windows are used already\n");
0871 mutex_unlock(&s->ops_mutex);
0872 return -EINVAL;
0873 }
0874
0875 win = &s->win[w];
0876
0877 if (!(s->features & SS_CAP_STATIC_MAP)) {
0878 win->res = pcmcia_find_mem_region(res->start, res->end, align,
0879 0, s);
0880 if (!win->res) {
0881 dev_dbg(&p_dev->dev, "allocating mem region failed\n");
0882 mutex_unlock(&s->ops_mutex);
0883 return -EINVAL;
0884 }
0885 }
0886 p_dev->_win |= CLIENT_WIN_REQ(w);
0887
0888
0889 win->map = w+1;
0890 win->flags = res->flags & WIN_FLAGS_MAP;
0891 win->speed = speed;
0892 win->card_start = 0;
0893
0894 if (s->ops->set_mem_map(s, win) != 0) {
0895 dev_dbg(&p_dev->dev, "failed to set memory mapping\n");
0896 mutex_unlock(&s->ops_mutex);
0897 return -EIO;
0898 }
0899 s->state |= SOCKET_WIN_REQ(w);
0900
0901
0902 if (s->features & SS_CAP_STATIC_MAP)
0903 res->start = win->static_start;
0904 else
0905 res->start = win->res->start;
0906
0907
0908 res->end += res->start - 1;
0909 res->flags &= ~WIN_FLAGS_REQ;
0910 res->flags |= (win->map << 2) | IORESOURCE_MEM;
0911 res->parent = win->res;
0912 if (win->res)
0913 request_resource(&iomem_resource, res);
0914
0915 dev_dbg(&p_dev->dev, "request_window results in %pR\n", res);
0916
0917 mutex_unlock(&s->ops_mutex);
0918
0919 return 0;
0920 }
0921 EXPORT_SYMBOL(pcmcia_request_window);
0922
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936 void pcmcia_disable_device(struct pcmcia_device *p_dev)
0937 {
0938 int i;
0939
0940 dev_dbg(&p_dev->dev, "disabling device\n");
0941
0942 for (i = 0; i < MAX_WIN; i++) {
0943 struct resource *res = p_dev->resource[MAX_IO_WIN + i];
0944 if (res->flags & WIN_FLAGS_REQ)
0945 pcmcia_release_window(p_dev, res);
0946 }
0947
0948 pcmcia_release_configuration(p_dev);
0949 pcmcia_release_io(p_dev);
0950 if (p_dev->_irq) {
0951 free_irq(p_dev->irq, p_dev->priv);
0952 p_dev->_irq = 0;
0953 }
0954 }
0955 EXPORT_SYMBOL(pcmcia_disable_device);