static void cs_pcmcia_attach(device_t parent, device_t self, void *aux) { struct cs_pcmcia_softc *psc = device_private(self); struct cs_softc *sc = &psc->sc_cs; struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; struct pcmcia_function *pf; int error; sc->sc_dev = self; pf = psc->sc_pf = pa->pf; error = pcmcia_function_configure(pa->pf, cs_pcmcia_validate_config); if (error) { aprint_error_dev(self, "configure failed, error=%d\n", error); return; } cfe = pf->cfe; sc->sc_iot = cfe->iospace[0].handle.iot; sc->sc_ioh = cfe->iospace[0].handle.ioh; sc->sc_irq = -1; #define CS_PCMCIA_HACK_FOR_CARDBUS #ifdef CS_PCMCIA_HACK_FOR_CARDBUS /* * XXX is there a generic way to know if it's a cardbus or not? */ sc->sc_cfgflags |= CFGFLG_CARDBUS_HACK; #endif error = cs_pcmcia_enable(sc); if (error) goto fail; sc->sc_enable = cs_pcmcia_enable; sc->sc_disable = cs_pcmcia_disable; /* chip attach */ error = cs_attach(sc, 0, 0, 0, 0); if (error) goto fail2; cs_pcmcia_disable(sc); psc->sc_state = CS_PCMCIA_ATTACHED; return; fail2: cs_pcmcia_disable(sc); fail: pcmcia_function_unconfigure(pf); }
static int cs_pcmcia_detach(struct device *self, int flags) { struct cs_pcmcia_softc *psc = (void *)self; struct cs_softc *sc = &psc->sc_cs; struct pcmcia_function *pf = psc->sc_pf; int rv; rv = cs_detach(sc); if (rv) return rv; cs_pcmcia_disable(sc); if (psc->sc_flags & CS_PCMCIA_FLAGS_IO_ALLOCATED) { pcmcia_io_free(pf, &psc->sc_pcioh); psc->sc_flags &= ~CS_PCMCIA_FLAGS_IO_ALLOCATED; } return 0; }
static void cs_pcmcia_attach(struct device *parent, struct device *self, void *aux) { struct cs_pcmcia_softc *psc = (void *)self; struct cs_softc *sc = (void *)&psc->sc_cs; struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; struct pcmcia_function *pf; char devinfo[256]; /* Print out what we are. */ pcmcia_devinfo(&pa->pf->sc->card, 0, devinfo, sizeof(devinfo)); printf(": %s\n", devinfo); pf = psc->sc_pf = pa->pf; cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); if (cfe->num_iospace != 1) { printf("%s: unexpected number of iospace(%d)\n", DEVNAME(sc), cfe->num_iospace); goto fail; } if (cfe->iospace[0].length < CS8900_IOSIZE) { printf("%s: unexpected iosize(%lu)\n", DEVNAME(sc), cfe->iospace[0].length); goto fail; } if (cfe->num_memspace != 0) { printf("%s: unexpected number of memspace(%d)\n", DEVNAME(sc), cfe->num_memspace); goto fail; } if (pcmcia_io_alloc(pf, cfe->iospace[0].start, cfe->iospace[0].length, cfe->iospace[0].length, &psc->sc_pcioh) != 0) { printf("%s: can't allocate i/o space %lx:%lx\n", DEVNAME(sc), cfe->iospace[0].start, cfe->iospace[0].length); goto fail; } psc->sc_flags |= CS_PCMCIA_FLAGS_IO_ALLOCATED; sc->sc_iot = psc->sc_pcioh.iot; sc->sc_ioh = psc->sc_pcioh.ioh; sc->sc_irq = -1; #define CS_PCMCIA_HACK_FOR_CARDBUS #ifdef CS_PCMCIA_HACK_FOR_CARDBUS /* * XXX is there a generic way to know if it's a cardbus or not? */ sc->sc_cfgflags |= CFGFLG_CARDBUS_HACK; #endif sc->sc_enable = cs_pcmcia_enable; sc->sc_disable = cs_pcmcia_disable; pcmcia_function_init(pa->pf, cfe); if (cs_pcmcia_enable(sc)) goto fail; /* chip attach */ if (cs_attach(sc, 0, 0, 0, 0)) goto fail; cs_pcmcia_disable(sc); return; fail: cs_pcmcia_detach((struct device *)psc, 0); return; }