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