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