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