This source file includes following definitions.
- mpu_test
- mpu_isa_match
- mpu_isa_attach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/errno.h>
33 #include <sys/ioctl.h>
34 #include <sys/syslog.h>
35 #include <sys/device.h>
36 #include <sys/proc.h>
37
38 #include <machine/bus.h>
39
40 #include <sys/audioio.h>
41 #include <dev/audio_if.h>
42 #include <dev/midi_if.h>
43
44 #include <dev/isa/isavar.h>
45 #include <dev/isa/isadmavar.h>
46
47 #include <dev/ic/mpuvar.h>
48
49 int mpu_isa_match(struct device *, void *, void *);
50 void mpu_isa_attach(struct device *, struct device *, void *);
51 int mpu_test(bus_space_tag_t, int);
52
53 #ifdef AUDIO_DEBUG
54 #define DPRINTF(x) if (mpu_debug) printf x
55 int mpu_debug = 0;
56 #else
57 #define DPRINTF(x)
58 #endif
59
60 #define MPU_GETSTATUS(iot, ioh) (bus_space_read_1(iot, ioh, MPU_STATUS))
61
62 struct mpu_isa_softc {
63 struct device sc_dev;
64
65 struct mpu_softc sc_mpu;
66 };
67
68 struct cfattach mpu_isa_ca = {
69 sizeof(struct mpu_isa_softc), mpu_isa_match, mpu_isa_attach
70 };
71
72 int
73 mpu_test (iot, iobase)
74 bus_space_tag_t iot;
75 int iobase;
76 {
77 bus_space_handle_t ioh;
78 int i, rc;
79
80 rc = 0;
81 if (bus_space_map(iot, iobase, MPU401_NPORT, 0, &ioh)) {
82 DPRINTF(("mpu_test: can`t map: %x/2\n", iobase));
83 return (0);
84 }
85
86 DPRINTF(("mpu_test: trying: %x\n", iobase));
87
88
89
90
91
92
93 if (MPU_GETSTATUS(iot, ioh) == 0xff)
94 goto done;
95
96 for (i = 0; i < MPU_MAXWAIT; i++) {
97 if (!(MPU_GETSTATUS(iot, ioh) & MPU_OUTPUT_BUSY)) {
98 rc = 1;
99 break;
100 }
101 delay (10);
102 }
103
104 if (rc == 1) {
105 bus_space_write_1(iot, ioh, MPU_COMMAND, MPU_RESET);
106 rc = 0;
107 for (i = 0; i < 2 * MPU_MAXWAIT; i++)
108 if (!(MPU_GETSTATUS(iot, ioh) & MPU_INPUT_EMPTY) &&
109 bus_space_read_1(iot, ioh, MPU_DATA) == MPU_ACK) {
110 rc = 1;
111 break;
112 }
113 }
114 done:
115 bus_space_unmap(iot, ioh, MPU401_NPORT);
116
117 return (rc);
118 }
119
120 int
121 mpu_isa_match(parent, match, aux)
122 struct device *parent;
123 void *match, *aux;
124 {
125 struct isa_attach_args *ia = aux;
126
127 if (mpu_test(ia->ia_iot, ia->ia_iobase)) {
128 ia->ia_iosize = MPU401_NPORT;
129 return (1);
130 }
131
132 return (0);
133 }
134
135 void
136 mpu_isa_attach(parent, self, aux)
137 struct device *parent, *self;
138 void *aux;
139 {
140 struct mpu_isa_softc *sc = (struct mpu_isa_softc *)self;
141 struct isa_attach_args *ia = aux;
142
143 sc->sc_mpu.iot = ia->ia_iot;
144
145 if (bus_space_map (ia->ia_iot, ia->ia_iobase, MPU401_NPORT,
146 0, &sc->sc_mpu.ioh)) {
147 printf(": can`t map i/o space\n");
148 return;
149 }
150
151 if (!mpu_find(&sc->sc_mpu)) {
152 printf(": find failed\n");
153 return;
154 }
155
156 printf(": generic MPU-401 compatible\n");
157
158 midi_attach_mi(&mpu_midi_hw_if, &sc->sc_mpu, &sc->sc_dev);
159 }