17 #include <linux/module.h>
18 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/device.h>
23 #include <linux/netdevice.h>
24 #include <linux/slab.h>
53 return s->
resource_ops->find_mem(base, num, align, low, s);
69 dev_dbg(&s->
dev,
"release_io_space for %pR\n", res);
105 unsigned int num = res->
end;
110 dev_dbg(&s->
dev,
"alloc_io_space request for %pR, %d lines\n",
113 align = base ? (lines ? 1<<lines : 0) : 1;
114 if (align && (align < num)) {
119 while (align && (align < num))
122 if (base & ~(align-1)) {
130 dev_dbg(&s->
dev,
"alloc_io_space request failed (%d)\n", ret);
141 "request_resource %pR failed: %d\n", res, ret);
143 release_io_space(s, res);
146 dev_dbg(&s->
dev,
"alloc_io_space request result %d: %pR\n", ret, res);
159 static int pcmcia_access_config(
struct pcmcia_device *p_dev,
163 unsigned int len,
void *
ptr))
173 c = p_dev->function_config;
176 dev_dbg(&p_dev->dev,
"Configuration isn't locked\n");
181 addr = (p_dev->config_base + where) >> 1;
183 ret = accessf(s, 1, addr, 1, val);
240 ret = s->
ops->set_mem_map(s, &s->
win[w]);
242 dev_warn(&p_dev->dev,
"failed to set_mem_map\n");
266 dev_dbg(&p_dev->dev,
"fixup iowidth to 8bit\n");
270 dev_dbg(&p_dev->dev,
"No card? Config not locked?\n");
275 io_on.
speed = io_speed;
286 s->
ops->set_io_map(s, &io_off);
288 s->
ops->set_io_map(s, &io_on);
314 dev_dbg(&p_dev->dev,
"fixup Vpp to %d\n", new_vpp);
318 dev_dbg(&p_dev->dev,
"No card? Config not locked?\n");
325 dev_warn(&p_dev->dev,
"Unable to set VPP\n");
329 p_dev->vpp = new_vpp;
358 c = p_dev->function_config;
359 if (p_dev->_locked) {
378 s->
ops->set_io_map(s, &io);
397 static int pcmcia_release_io(
struct pcmcia_device *p_dev)
407 c = p_dev->function_config;
409 release_io_space(s, &c->
io[0]);
412 release_io_space(s, &c->
io[1]);
438 dev_dbg(&p_dev->dev,
"releasing window %pR\n", res);
448 dev_dbg(&p_dev->dev,
"not releasing unknown window\n");
455 s->
ops->set_mem_map(s, win);
492 unsigned char ext_status = 0;
494 unsigned int flags = p_dev->config_flags;
500 c = p_dev->function_config;
503 dev_dbg(&p_dev->dev,
"Configuration is locked\n");
512 "Unable to set socket state\n");
517 if (p_dev->_io || flags & CONF_ENABLE_IRQ)
518 flags |= CONF_ENABLE_IOCARD;
519 if (flags & CONF_ENABLE_IOCARD)
521 if (flags & CONF_ENABLE_ZVCARD)
523 if (flags & CONF_ENABLE_SPKR) {
526 if (!(p_dev->config_regs & PRESENT_STATUS))
527 dev_warn(&p_dev->dev,
"speaker requested, but "
528 "PRESENT_STATUS not set!\n");
530 if (flags & CONF_ENABLE_IRQ)
534 if (flags & CONF_ENABLE_ESR) {
535 p_dev->config_regs |= PRESENT_EXT_STATUS;
542 "enable_device: V %d, flags %x, base %x, regs %x, idx %x\n",
543 p_dev->vpp, flags, p_dev->config_base, p_dev->config_regs,
544 p_dev->config_index);
547 base = p_dev->config_base;
548 if (p_dev->config_regs & PRESENT_COPY) {
550 dev_dbg(&p_dev->dev,
"clearing CISREG_SCR\n");
553 if (p_dev->config_regs & PRESENT_PIN_REPLACE) {
555 dev_dbg(&p_dev->dev,
"clearing CISREG_PRR\n");
558 if (p_dev->config_regs & PRESENT_OPTION) {
564 if (p_dev->config_regs & PRESENT_IOBASE_0)
567 if ((flags & CONF_ENABLE_IRQ) &&
568 !(flags & CONF_ENABLE_PULSE_IRQ))
573 if (p_dev->config_regs & PRESENT_STATUS)
576 if (p_dev->config_regs & PRESENT_EXT_STATUS)
580 if (p_dev->config_regs & PRESENT_IOBASE_0) {
581 u8 b = c->
io[0].start & 0xff;
583 b = (c->
io[0].start >> 8) & 0xff;
586 if (p_dev->config_regs & PRESENT_IOSIZE) {
587 u8 b = resource_size(&c->
io[0]) + resource_size(&c->
io[1]) - 1;
593 iomap.
speed = io_speed;
598 switch (s->
io[i].
res->flags & IO_DATA_PATH_WIDTH) {
599 case IO_DATA_PATH_WIDTH_16:
601 case IO_DATA_PATH_WIDTH_AUTO:
608 s->
ops->set_io_map(s, &iomap);
634 config_t *c = p_dev->function_config;
638 dev_dbg(&p_dev->dev,
"pcmcia_request_io: %pR , %pR",
639 &c->
io[0], &c->
io[1]);
642 dev_dbg(&p_dev->dev,
"pcmcia_request_io: No card present\n");
647 dev_dbg(&p_dev->dev,
"Configuration is locked\n");
651 dev_dbg(&p_dev->dev,
"IO already configured\n");
655 ret = alloc_io_space(s, &c->
io[0], p_dev->io_lines);
660 ret = alloc_io_space(s, &c->
io[1], p_dev->io_lines);
664 release_io_space(s, &c->
io[0]);
666 c->
io[0].end = resource_size(&tmp);
677 dev_dbg(&p_dev->dev,
"pcmcia_request_io succeeded: %pR , %pR",
678 &c->
io[0], &c->
io[1]);
707 p_dev->devname, p_dev->priv);
736 ret =
request_irq(p_dev->irq, handler, 0, p_dev->devname, p_dev->priv);
740 "request for exclusive IRQ could not be fulfilled.\n");
741 dev_printk(
KERN_WARNING, &p_dev->dev,
"pcmcia: the driver "
742 "needs updating to supported shared IRQ lines.\n");
745 dev_printk(
KERN_INFO, &p_dev->dev,
"request_irq() failed\n");
754 #ifdef CONFIG_PCMCIA_PROBE
757 static u8 pcmcia_used_irq[32];
770 static int pcmcia_setup_isa_irq(
struct pcmcia_device *p_dev,
int type)
773 unsigned int try,
irq;
777 for (
try = 0;
try < 64;
try++) {
784 if (!((mask >> irq) & 1))
788 if ((
try < 32) && pcmcia_used_irq[irq])
794 ret =
request_irq(irq, test_action, type, p_dev->devname,
798 p_dev->irq = s->pcmcia_irq = irq;
799 pcmcia_used_irq[irq]++;
809 pcmcia_used_irq[s->pcmcia_irq]--;
815 static int pcmcia_setup_isa_irq(
struct pcmcia_device *p_dev,
int type)
844 p_dev->irq = s->pcmcia_irq;
849 if (!pcmcia_setup_isa_irq(p_dev, 0))
858 p_dev->irq = s->pcmcia_irq = s->
pci_irq;
886 dev_dbg(&p_dev->dev,
"request_window %pR %d\n", res, speed);
889 dev_dbg(&p_dev->dev,
"No card present\n");
898 dev_dbg(&p_dev->dev,
"invalid map size\n");
902 (res->
start & (align-1))) {
903 dev_dbg(&p_dev->dev,
"invalid base address\n");
915 dev_dbg(&p_dev->dev,
"all windows are used already\n");
926 dev_dbg(&p_dev->dev,
"allocating mem region failed\n");
939 if (s->
ops->set_mem_map(s, win) != 0) {
940 dev_dbg(&p_dev->dev,
"failed to set memory mapping\n");
954 res->
flags &= ~WIN_FLAGS_REQ;
960 dev_dbg(&p_dev->dev,
"request_window results in %pR\n", res);
985 dev_dbg(&p_dev->dev,
"disabling device\n");
987 for (i = 0; i <
MAX_WIN; i++) {
988 struct resource *res = p_dev->resource[MAX_IO_WIN +
i];
989 if (res->
flags & WIN_FLAGS_REQ)
994 pcmcia_release_io(p_dev);