Home | History | Annotate | Line # | Download | only in pcmcia
aic_pcmcia.c revision 1.1.2.8
      1 #include <sys/param.h>
      2 #include <sys/systm.h>
      3 #include <sys/select.h>
      4 #include <sys/device.h>
      5 
      6 #include <machine/cpu.h>
      7 #include <machine/bus.h>
      8 #include <machine/intr.h>
      9 
     10 #include <dev/scsipi/scsipi_all.h>
     11 #include <dev/scsipi/scsipiconf.h>
     12 #include <dev/scsipi/scsi_all.h>
     13 
     14 #include <dev/ic/aic6360var.h>
     15 
     16 #include <dev/pcmcia/pcmciareg.h>
     17 #include <dev/pcmcia/pcmciavar.h>
     18 
     19 #define PCMCIA_MANUFACTURER_ADAPTEC	0x12F
     20 #define PCMCIA_PRODUCT_ADAPTEC_APA1460	0x1
     21 
     22 struct aic_pcmcia_softc {
     23 	struct aic_softc sc_aic; /* real "aic" softc */
     24 
     25 	struct pcmcia_io_handle sc_pcioh;
     26 	struct pcmcia_function *sc_pf;
     27 	int sc_io_window;	/* our i/o window */
     28 };
     29 
     30 #ifdef __BROKEN_INDIRECT_CONFIG
     31 int aic_pcmcia_match __P((struct device *, void *, void *));
     32 #else
     33 int aic_pcmcia_match __P((struct device *, struct cfdata *, void *));
     34 #endif
     35 void aic_pcmcia_attach __P((struct device *, struct device *, void *));
     36 
     37 struct cfattach aic_pcmcia_ca = {
     38     sizeof(struct aic_pcmcia_softc), aic_pcmcia_match, aic_pcmcia_attach
     39 };
     40 
     41 int
     42 aic_pcmcia_match(parent, match, aux)
     43      struct device *parent;
     44 #ifdef __BROKEN_INDIRECT_CONFIG
     45      void *match;
     46 #else
     47      struct cfdata *cf;
     48 #endif
     49      void *aux;
     50 {
     51     struct pcmcia_attach_args *pa = aux;
     52 
     53     if ((pa->manufacturer == PCMCIA_MANUFACTURER_ADAPTEC) &&
     54 	(pa->product == PCMCIA_PRODUCT_ADAPTEC_APA1460) &&
     55 	(pa->pf->number == 0))
     56 	return(1);
     57 
     58     return(0);
     59 }
     60 
     61 void
     62 aic_pcmcia_attach(parent, self, aux)
     63      struct device *parent, *self;
     64      void *aux;
     65 {
     66     struct aic_pcmcia_softc *psc = (void *) self;
     67     struct aic_softc *sc = &psc->sc_aic;
     68     struct pcmcia_attach_args *pa = aux;
     69     struct pcmcia_config_entry *cfe;
     70     struct pcmcia_function *pf = pa->pf;
     71 
     72     psc->sc_pf = pf;
     73 
     74     for (cfe = pf->cfe_head.sqh_first; cfe; cfe = cfe->cfe_list.sqe_next) {
     75 	    if (cfe->num_memspace != 0 ||
     76 		cfe->num_iospace != 1)
     77 		    continue;
     78 
     79 	    if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
     80 		cfe->iospace[0].length, 0, &psc->sc_pcioh) == 0)
     81 		    break;
     82     }
     83 
     84     if (cfe == 0) {
     85 	    printf(": can't alloc i/o space\n");
     86 	    return;
     87     }
     88 
     89     sc->sc_iot = psc->sc_pcioh.iot;
     90     sc->sc_ioh = psc->sc_pcioh.ioh;
     91 
     92     /* Enable the card. */
     93     pcmcia_function_init(pf, cfe);
     94     if (pcmcia_function_enable(pf)) {
     95 	printf(": function enable failed\n");
     96 	return;
     97     }
     98 
     99     /* map in the io space */
    100     if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
    101 	&psc->sc_pcioh, &psc->sc_io_window)) {
    102 	    printf(": can't map i/o space\n");
    103 	    return;
    104     }
    105 
    106     if (!aic_find(sc->sc_iot, sc->sc_ioh))
    107 	    printf(": coundn't find aic\n%s", sc->sc_dev.dv_xname);
    108 
    109     printf(": APA-1460 SCSI Host Adapter\n");
    110 
    111     aicattach(sc);
    112 
    113     /* establish the interrupt handler. */
    114     sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, aicintr, sc);
    115     if (sc->sc_ih == NULL)
    116 	    printf("%s: couldn't establish interrupt\n",
    117 		sc->sc_dev.dv_xname);
    118 }
    119