void an_pcmcia_attach(struct device *parent, struct device *self, void *aux) { struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)self; struct an_softc *sc = (struct an_softc *)self; struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; const char *intrstr; int error; psc->sc_pf = pa->pf; cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); pcmcia_function_init(pa->pf, cfe); if (pcmcia_function_enable(pa->pf)) { printf(": function enable failed\n"); return; } if (pcmcia_io_alloc(pa->pf, 0, AN_IOSIZ, AN_IOSIZ, &psc->sc_pcioh)) { printf(": can't alloc i/o space\n"); pcmcia_function_disable(pa->pf); return; } if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0, AN_IOSIZ, &psc->sc_pcioh, &psc->sc_io_window)) { printf(": can't map i/o space\n"); pcmcia_io_free(pa->pf, &psc->sc_pcioh); pcmcia_function_disable(pa->pf); return; } sc->sc_iot = psc->sc_pcioh.iot; sc->sc_ioh = psc->sc_pcioh.ioh; sc->sc_enabled = 1; sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, an_intr, sc, sc->sc_dev.dv_xname); intrstr = pcmcia_intr_string(psc->sc_pf, sc->sc_ih); if (*intrstr) printf(", %s", intrstr); printf("\n"); error = an_attach(sc); if (error) { printf("%s: failed to attach controller\n", self->dv_xname); return; } sc->sc_enabled = 0; psc->sc_state = AN_PCMCIA_ATTACHED; }
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; }
static void tr_pcmcia_attach(device_t parent, device_t self, void *aux) { struct tr_pcmcia_softc *psc = device_private(self); struct tr_softc *sc = &psc->sc_tr; struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; bus_size_t offset; psc->sc_pf = pa->pf; cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); pcmcia_function_init(pa->pf, cfe); if (pcmcia_function_enable(pa->pf) != 0) { aprint_error_dev(self, "function enable failed\n"); return; } if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start, cfe->iospace[0].length, cfe->iospace[0].length, &psc->sc_pioh) != 0) { aprint_error_dev(self, "can't allocate pio space\n"); goto fail1; } if (pcmcia_io_map(psc->sc_pf, PCMCIA_WIDTH_IO8, /* XXX _AUTO? */ &psc->sc_pioh, &psc->sc_pio_window) != 0) { aprint_error_dev(self, "can't map pio space\n"); goto fail2; } if (pcmcia_mem_alloc(psc->sc_pf, TR_SRAM_SIZE, &psc->sc_sramh) != 0) { aprint_error_dev(self, "can't allocate sram space\n"); goto fail3; } if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_COMMON, TR_PCMCIA_SRAM_ADDR, TR_SRAM_SIZE, &psc->sc_sramh, &offset, &psc->sc_sram_window) != 0) { aprint_error_dev(self, "can't map sram space\n"); goto fail4; } if (pcmcia_mem_alloc(psc->sc_pf, TR_MMIO_SIZE, &psc->sc_mmioh) != 0) { aprint_error_dev(self, "can't allocate mmio space\n"); goto fail5; return; } if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_COMMON, TR_PCMCIA_MMIO_ADDR, TR_MMIO_SIZE, &psc->sc_mmioh, &offset, &psc->sc_mmio_window) != 0) { aprint_error_dev(self, "can't map mmio space\n"); goto fail6; } sc->sc_piot = psc->sc_pioh.iot; sc->sc_pioh = psc->sc_pioh.ioh; sc->sc_memt = psc->sc_sramh.memt; sc->sc_sramh = psc->sc_sramh.memh; sc->sc_mmioh = psc->sc_mmioh.memh; sc->sc_init_status = RSP_16; sc->sc_memwinsz = TR_SRAM_SIZE; sc->sc_memsize = TR_SRAM_SIZE; sc->sc_memreserved = 0; sc->sc_aca = TR_ACA_OFFSET; sc->sc_maddr = TR_PCMCIA_SRAM_ADDR; sc->sc_mediastatus = tr_pcmcia_mediastatus; sc->sc_mediachange = tr_pcmcia_mediachange; sc->sc_enable = tr_pcmcia_enable; sc->sc_disable = tr_pcmcia_disable; tr_pcmcia_setup(sc); if (tr_reset(sc) == 0) (void)tr_attach(sc); pcmcia_function_disable(pa->pf); sc->sc_enabled = 0; return; fail6: pcmcia_mem_free(psc->sc_pf, &psc->sc_mmioh); fail5: pcmcia_mem_unmap(psc->sc_pf, psc->sc_sram_window); fail4: pcmcia_mem_free(psc->sc_pf, &psc->sc_sramh); fail3: pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window); fail2: pcmcia_io_free(psc->sc_pf, &psc->sc_pioh); fail1: pcmcia_function_disable(pa->pf); sc->sc_enabled = 0; }
void wi_pcmcia_attach(struct device *parent, struct device *self, void *aux) { struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)self; struct wi_softc *sc = &psc->sc_wi; struct pcmcia_attach_args *pa = aux; struct pcmcia_function *pf = pa->pf; struct pcmcia_config_entry *cfe = SIMPLEQ_FIRST(&pf->cfe_head); const char *intrstr; int state = 0; psc->sc_pf = pf; /* Enable the card. */ pcmcia_function_init(pf, cfe); if (pcmcia_function_enable(pf)) { printf(": function enable failed\n"); goto bad; } state++; if (pcmcia_io_alloc(pf, 0, WI_IOSIZ, WI_IOSIZ, &psc->sc_pcioh)) { printf(": can't alloc i/o space\n"); goto bad; } state++; if (pcmcia_io_map(pf, PCMCIA_WIDTH_IO16, 0, WI_IOSIZ, &psc->sc_pcioh, &psc->sc_io_window)) { printf(": can't map io space\n"); goto bad; } state++; printf(" port 0x%lx/%lu", psc->sc_pcioh.addr, (u_long)psc->sc_pcioh.size); sc->wi_ltag = sc->wi_btag = psc->sc_pcioh.iot; sc->wi_lhandle = sc->wi_bhandle = psc->sc_pcioh.ioh; sc->wi_cor_offset = WI_COR_OFFSET; sc->wi_flags |= WI_FLAGS_BUS_PCMCIA; /* Make sure interrupts are disabled. */ CSR_WRITE_2(sc, WI_INT_EN, 0); CSR_WRITE_2(sc, WI_EVENT_ACK, 0xffff); /* Establish the interrupt. */ sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, wi_intr, psc, sc->sc_dev.dv_xname); if (sc->sc_ih == NULL) { printf("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname); goto bad; } intrstr = pcmcia_intr_string(psc->sc_pf, sc->sc_ih); printf("%s%s\n", *intrstr ? ", " : "", intrstr); if (wi_attach(sc, &wi_func_io) == 0) return; /* wi_attach() failed, do some cleanup */ pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih); sc->sc_ih = NULL; bad: if (state > 2) pcmcia_io_unmap(pf, psc->sc_io_window); if (state > 1) pcmcia_io_free(pf, &psc->sc_pcioh); if (state > 0) pcmcia_function_disable(pf); }
int isic_attach_fritzpcmcia(struct pcmcia_isic_softc *psc, struct pcmcia_config_entry *cfe, struct pcmcia_attach_args *pa) { struct isic_softc *sc = &psc->sc_isic; bus_space_tag_t t; bus_space_handle_t h; int i; /* Validate config info */ if (cfe->num_memspace != 0) printf(": unexpected number of memory spaces %d should be 0\n", cfe->num_memspace); if (cfe->num_iospace != 1) printf(": unexpected number of memory spaces %d should be 1\n", cfe->num_iospace); /* Allocate pcmcia space - but don't listen to the card, it's lying about the size needed! */ for (i = 0; i < cfe->num_iospace; i++) if (pcmcia_io_alloc(pa->pf, cfe->iospace[i].start, cfe->iospace[i].length, 1, &psc->sc_pcioh) == 0) break; if (i >= cfe->num_iospace) { printf(": can't allocate i/o space\n"); return 0; } /* map the selected space */ if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ? PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), &psc->sc_pcioh, &psc->sc_io_window)) { printf(": can't map i/o space\n"); return 0; } /* Setup bus space maps */ sc->sc_num_mappings = 1; MALLOC_MAPS(sc); /* Copy our handles/tags to the MI maps */ sc->sc_maps[0].t = psc->sc_pcioh.iot; sc->sc_maps[0].h = psc->sc_pcioh.ioh; sc->sc_maps[0].offset = 0; sc->sc_maps[0].size = 0; /* not our mapping */ t = sc->sc_maps[0].t; h = sc->sc_maps[0].h; sc->clearirq = NULL; sc->readreg = avma1_pcmcia_read_reg; sc->writereg = avma1_pcmcia_write_reg; sc->readfifo = avma1_pcmcia_read_fifo; sc->writefifo = avma1_pcmcia_write_fifo; /* setup IOM bus type */ sc->sc_bustyp = BUS_TYPE_IOM2; sc->sc_ipac = 0; sc->sc_bfifolen = HSCX_FIFO_LEN; /* Reset controller again just to make sure... */ bus_space_write_1(t, h, STAT0_OFFSET, 0x00); DELAY(SEC_DELAY / 10); bus_space_write_1(t, h, STAT0_OFFSET, 0x01); DELAY(SEC_DELAY / 10); bus_space_write_1(t, h, STAT0_OFFSET, 0x00); DELAY(SEC_DELAY / 10); /* enable IRQ, disable counter IRQ */ bus_space_write_1(t, h, STAT0_OFFSET, ASL_TIMERDISABLE | ASL_TIMERRESET | ASL_ENABLE_INT); return 1; }
void gpr_attach(struct device *parent, struct device *self, void *aux) { struct gpr_softc *sc = (void *)self; struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; const char *intrstr; for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe; cfe = SIMPLEQ_NEXT(cfe, cfe_list)) { if (!pcmcia_io_alloc(pa->pf, cfe->iospace[0].start, cfe->iospace[0].length, cfe->iospace[0].length, &sc->sc_pioh)) break; } if (cfe == NULL) { printf(": can't alloc i/o space\n"); goto fail_io_alloc; } pcmcia_function_init(pa->pf, cfe); if (pcmcia_function_enable(pa->pf)) { printf(": function enable failed\n"); goto fail_enable; } if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowin)) { printf(": can't map i/o space\n"); goto fail_io_map; } /* * GPR400 has some registers in attribute memory as well. */ if (pcmcia_mem_alloc(pa->pf, GPR400_MEM_LEN, &sc->sc_pmemh)) { printf(": can't map mem space\n"); goto fail_mem_alloc; } if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR, pa->pf->ccr_base, GPR400_MEM_LEN, &sc->sc_pmemh, &sc->sc_offset, &sc->sc_memwin)) { printf(": can't map memory\n"); goto fail_mem_map; } sc->sc_pf = pa->pf; sc->sc_iot = sc->sc_pioh.iot; sc->sc_ioh = sc->sc_pioh.ioh; sc->sc_memt = sc->sc_pmemh.memt; sc->sc_memh = sc->sc_pmemh.memh; printf(" port 0x%lx/%d", sc->sc_pioh.addr, sc->sc_pioh.size); sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_TTY, gpr_intr, sc, sc->sc_dev.dv_xname); intrstr = pcmcia_intr_string(sc->sc_pf, sc->sc_ih); printf("%s%s\n", *intrstr ? ", " : "", intrstr); if (sc->sc_ih != NULL) return; pcmcia_mem_unmap(pa->pf, sc->sc_memwin); fail_mem_map: pcmcia_mem_free(pa->pf, &sc->sc_pmemh); fail_mem_alloc: pcmcia_io_unmap(pa->pf, sc->sc_iowin); fail_io_map: pcmcia_function_disable(pa->pf); fail_enable: pcmcia_io_free(pa->pf, &sc->sc_pioh); fail_io_alloc: return; }