/* run after a CARD_INSERTATION event is received to configure the PCMCIA * socket and make the device available to the system */ static int prism2_config(dev_link_t *link) { struct net_device *dev = (struct net_device *) link->priv; struct hostap_interface *iface = dev->priv; local_info_t *local = iface->local; int ret; tuple_t tuple; cisparse_t parse; int last_fn, last_ret; u_char buf[64]; config_info_t conf; cistpl_cftable_entry_t dflt = { 0 }; PDEBUG(DEBUG_FLOW, "prism2_config()\n"); tuple.DesiredTuple = CISTPL_CONFIG; tuple.Attributes = 0; tuple.TupleData = buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 0; CS_CHECK(GetFirstTuple, link->handle, &tuple); CS_CHECK(GetTupleData, link->handle, &tuple); CS_CHECK(ParseTuple, link->handle, &tuple, &parse); link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; CS_CHECK(GetConfigurationInfo, link->handle, &conf); PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info, ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc); link->conf.Vcc = conf.Vcc; /* Look for an appropriate configuration table entry in the CIS */ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; CS_CHECK(GetFirstTuple, link->handle, &tuple); for (;;) { cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); CFG_CHECK2(GetTupleData, link->handle, &tuple); CFG_CHECK2(ParseTuple, link->handle, &tuple, &parse); if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; if (cfg->index == 0) goto next_entry; link->conf.ConfigIndex = cfg->index; PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X " "(default 0x%02X)\n", cfg->index, dflt.index); /* Does this card need audio output? */ if (cfg->flags & CISTPL_CFTABLE_AUDIO) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } /* Use power settings for Vcc and Vpp if present */ /* Note that the CIS values need to be rescaled */ if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000 && !ignore_cis_vcc) { PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping" " this entry\n"); goto next_entry; } } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000 && !ignore_cis_vcc) { PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch " "- skipping this entry\n"); goto next_entry; } } if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) link->conf.Vpp1 = link->conf.Vpp2 = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) link->conf.Vpp1 = link->conf.Vpp2 = dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; /* Do we need to allocate an interrupt? */ if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) link->conf.Attributes |= CONF_ENABLE_IRQ; else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) { /* At least Compaq WL200 does not have IRQInfo1 set, * but it does not work without interrupts.. */ printk("Config has no IRQ info, but trying to enable " "IRQ anyway..\n"); link->conf.Attributes |= CONF_ENABLE_IRQ; } /* IO window settings */ PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d " "dflt.io.nwin=%d\n", cfg->io.nwin, dflt.io.nwin); link->io.NumPorts1 = link->io.NumPorts2 = 0; if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, " "io.base=0x%04x, len=%d\n", io->flags, io->win[0].base, io->win[0].len); if (!(io->flags & CISTPL_IO_8BIT)) link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; if (!(io->flags & CISTPL_IO_16BIT)) link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; link->io.BasePort1 = io->win[0].base; link->io.NumPorts1 = io->win[0].len; if (io->nwin > 1) { link->io.Attributes2 = link->io.Attributes1; link->io.BasePort2 = io->win[1].base; link->io.NumPorts2 = io->win[1].len; } } /* This reserves IO space but doesn't actually enable it */ CFG_CHECK2(RequestIO, link->handle, &link->io); /* This configuration table entry is OK */ break; next_entry: CS_CHECK(GetNextTuple, link->handle, &tuple); } /* * Allocate an interrupt line. Note that this does not assign a * handler to the interrupt, unless the 'Handler' member of the * irq structure is initialized. */ if (link->conf.Attributes & CONF_ENABLE_IRQ) { int i; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID; if (irq_list[0] == -1) link->irq.IRQInfo2 = irq_mask; else for (i = 0; i < 4; i++) link->irq.IRQInfo2 |= 1 << irq_list[i]; link->irq.Handler = (void *) prism2_interrupt; link->irq.Instance = dev; CS_CHECK(RequestIRQ, link->handle, &link->irq); } /* * This actually configures the PCMCIA socket -- setting up * the I/O windows and the interrupt mapping, and putting the * card and host interface into "Memory and IO" mode. */ CS_CHECK(RequestConfiguration, link->handle, &link->conf); dev->irq = link->irq.AssignedIRQ; dev->base_addr = link->io.BasePort1; /* Finally, report what we've done */ printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", dev_info, link->conf.ConfigIndex, link->conf.Vcc / 10, link->conf.Vcc % 10); if (link->conf.Vpp1) printk(", Vpp %d.%d", link->conf.Vpp1 / 10, link->conf.Vpp1 % 10); if (link->conf.Attributes & CONF_ENABLE_IRQ) printk(", irq %d", link->irq.AssignedIRQ); if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1-1); if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, link->io.BasePort2+link->io.NumPorts2-1); printk("\n"); link->state |= DEV_CONFIG; link->state &= ~DEV_CONFIG_PENDING; if (prism2_init_dev(local)) { prism2_release((u_long) link); return 1; } strcpy(local->node.dev_name, dev->name); link->dev = &local->node; local->shutdown = 0; ret = prism2_hw_config(dev, 1); return ret; cs_failed: cs_error(link->handle, last_fn, last_ret); prism2_release((u_long)link); return 1; }
static int prism2_plx_probe(struct pci_dev *pdev, const struct pci_device_id *id) { unsigned int pccard_ioaddr, plx_ioaddr; unsigned long pccard_attr_mem; unsigned int pccard_attr_len; unsigned long attr_mem = 0; unsigned int cor_offset, cor_index; u32 reg; local_info_t *local = NULL; struct net_device *dev = NULL; struct hostap_interface *iface; static int cards_found /* = 0 */; int irq_registered = 0; int tmd7160; if (pci_enable_device(pdev)) return -EIO; /* National Datacomm NCP130 based on TMD7160, not PLX9052. */ tmd7160 = (pdev->vendor == 0x15e8) && (pdev->device == 0x0131); plx_ioaddr = pci_resource_start(pdev, 1); pccard_ioaddr = pci_resource_start(pdev, tmd7160 ? 2 : 3); if (tmd7160) { /* TMD7160 */ attr_mem = 0; /* no access to PC Card attribute memory */ printk(KERN_INFO "TMD7160 PCI/PCMCIA adapter: io=0x%x, " "irq=%d, pccard_io=0x%x\n", plx_ioaddr, pdev->irq, pccard_ioaddr); cor_offset = plx_ioaddr; cor_index = 0x04; outb(cor_index | COR_LEVLREQ | COR_ENABLE_FUNC, plx_ioaddr); mdelay(1); reg = inb(plx_ioaddr); if (reg != (cor_index | COR_LEVLREQ | COR_ENABLE_FUNC)) { printk(KERN_ERR "%s: Error setting COR (expected=" "0x%02x, was=0x%02x)\n", dev_info, cor_index | COR_LEVLREQ | COR_ENABLE_FUNC, reg); goto fail; } } else { /* PLX9052 */ pccard_attr_mem = pci_resource_start(pdev, 2); pccard_attr_len = pci_resource_len(pdev, 2); if (pccard_attr_len < PLX_MIN_ATTR_LEN) goto fail; attr_mem = (unsigned long) ioremap(pccard_attr_mem, pccard_attr_len); if (!attr_mem) { printk(KERN_ERR "%s: cannot remap attr_mem\n", dev_info); goto fail; } printk(KERN_INFO "PLX9052 PCI/PCMCIA adapter: " "mem=0x%lx, plx_io=0x%x, irq=%d, pccard_io=0x%x\n", pccard_attr_mem, plx_ioaddr, pdev->irq, pccard_ioaddr); if (prism2_plx_check_cis(attr_mem, pccard_attr_len, &cor_offset, &cor_index)) { printk(KERN_INFO "Unknown PC Card CIS - not a " "Prism2/2.5 card?\n"); goto fail; } printk(KERN_DEBUG "Prism2/2.5 PC Card detected in PLX9052 " "adapter\n"); /* Write COR to enable PC Card */ writeb(cor_index | COR_LEVLREQ | COR_ENABLE_FUNC, attr_mem + cor_offset); /* Enable PCI interrupts if they are not already enabled */ reg = inl(plx_ioaddr + PLX_INTCSR); printk(KERN_DEBUG "PLX_INTCSR=0x%x\n", reg); if (!(reg & PLX_INTCSR_PCI_INTEN)) { outl(reg | PLX_INTCSR_PCI_INTEN, plx_ioaddr + PLX_INTCSR); if (!(inl(plx_ioaddr + PLX_INTCSR) & PLX_INTCSR_PCI_INTEN)) { printk(KERN_WARNING "%s: Could not enable " "Local Interrupts\n", dev_info); goto fail; } } reg = inl(plx_ioaddr + PLX_CNTRL); printk(KERN_DEBUG "PLX_CNTRL=0x%x (Serial EEPROM " "present=%d)\n", reg, (reg & PLX_CNTRL_SERIAL_EEPROM_PRESENT) != 0); /* should set PLX_PCIIPR to 0x01 (INTA#) if Serial EEPROM is * not present; but are there really such cards in use(?) */ } dev = prism2_init_local_data(&prism2_plx_funcs, cards_found); if (dev == NULL) goto fail; iface = dev->priv; local = iface->local; cards_found++; dev->irq = pdev->irq; dev->base_addr = pccard_ioaddr; local->attr_mem = attr_mem; local->cor_offset = cor_offset; if (prism2_init_dev(local)) goto fail; pci_set_drvdata(pdev, dev); if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name, dev)) { printk(KERN_WARNING "%s: request_irq failed\n", dev->name); goto fail; } else irq_registered = 1; if (prism2_hw_config(dev, 1)) { printk(KERN_DEBUG "%s: hardware initialization failed\n", dev_info); goto fail; } return 0; fail: prism2_free_local_data(dev); if (irq_registered && dev) free_irq(dev->irq, dev); if (attr_mem) iounmap((void *) attr_mem); #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4)) pci_disable_device(pdev); #endif return -ENODEV; }
static int prism2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { unsigned long phymem; unsigned long mem = 0; local_info_t *local = NULL; struct net_device *dev = NULL; static int cards_found /* = 0 */; int irq_registered = 0; struct hostap_interface *iface; if (pci_enable_device(pdev)) return -EIO; phymem = pci_resource_start(pdev, 0); if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) { printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n"); goto err_out_disable; } mem = (unsigned long) ioremap(phymem, pci_resource_len(pdev, 0)); if (!mem) { printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ; goto fail; } #ifdef PRISM2_BUS_MASTER pci_set_master(pdev); #endif /* PRISM2_BUS_MASTER */ dev = prism2_init_local_data(&prism2_pci_funcs, cards_found); if (dev == NULL) goto fail; iface = dev->priv; local = iface->local; cards_found++; dev->irq = pdev->irq; dev->mem_start = mem; dev->mem_end = mem + pci_resource_len(pdev, 0); if (prism2_init_dev(local)) goto fail; prism2_pci_cor_sreset(local); pci_set_drvdata(pdev, dev); if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name, dev)) { printk(KERN_WARNING "%s: request_irq failed\n", dev->name); goto fail; } else irq_registered = 1; if (!local->pri_only && prism2_hw_config(dev, 1)) { printk(KERN_DEBUG "%s: hardware initialization failed\n", dev_info); goto fail; } printk(KERN_INFO "%s: Intersil Prism2.5 PCI: " "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq); return 0; fail: if (irq_registered && dev) free_irq(dev->irq, dev); if (mem) iounmap((void *) mem); release_mem_region(phymem, pci_resource_len(pdev, 0)); err_out_disable: #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4)) pci_disable_device(pdev); #endif prism2_free_local_data(dev); return -ENODEV; }