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