autri.c revision 1.3.4.4 1 1.3.4.4 jdolecek /* $NetBSD: autri.c,v 1.3.4.4 2002/06/23 17:47:33 jdolecek Exp $ */
2 1.3.4.2 thorpej
3 1.3.4.2 thorpej /*
4 1.3.4.2 thorpej * Copyright (c) 2001 SOMEYA Yoshihiko and KUROSAWA Takahiro.
5 1.3.4.2 thorpej * All rights reserved.
6 1.3.4.2 thorpej *
7 1.3.4.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 thorpej * modification, are permitted provided that the following conditions
9 1.3.4.2 thorpej * are met:
10 1.3.4.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.3.4.2 thorpej *
16 1.3.4.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.3.4.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.3.4.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.3.4.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.3.4.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.3.4.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.3.4.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.3.4.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.3.4.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.3.4.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.3.4.2 thorpej */
27 1.3.4.2 thorpej
28 1.3.4.2 thorpej /*
29 1.3.4.2 thorpej * Trident 4DWAVE-DX/NX, SiS 7018, ALi M5451 Sound Driver
30 1.3.4.2 thorpej *
31 1.3.4.2 thorpej * The register information is taken from the ALSA driver.
32 1.3.4.2 thorpej *
33 1.3.4.2 thorpej * Documentation links:
34 1.3.4.2 thorpej * - ftp://ftp.alsa-project.org/pub/manuals/trident/
35 1.3.4.2 thorpej */
36 1.3.4.2 thorpej
37 1.3.4.2 thorpej #include "midi.h"
38 1.3.4.2 thorpej
39 1.3.4.2 thorpej #include <sys/param.h>
40 1.3.4.2 thorpej #include <sys/systm.h>
41 1.3.4.2 thorpej #include <sys/kernel.h>
42 1.3.4.2 thorpej #include <sys/fcntl.h>
43 1.3.4.2 thorpej #include <sys/malloc.h>
44 1.3.4.2 thorpej #include <sys/device.h>
45 1.3.4.2 thorpej #include <sys/proc.h>
46 1.3.4.2 thorpej
47 1.3.4.2 thorpej #include <dev/pci/pcidevs.h>
48 1.3.4.2 thorpej #include <dev/pci/pcireg.h>
49 1.3.4.2 thorpej #include <dev/pci/pcivar.h>
50 1.3.4.2 thorpej
51 1.3.4.2 thorpej #include <sys/audioio.h>
52 1.3.4.2 thorpej #include <dev/audio_if.h>
53 1.3.4.2 thorpej #include <dev/midi_if.h>
54 1.3.4.2 thorpej #include <dev/mulaw.h>
55 1.3.4.2 thorpej #include <dev/auconv.h>
56 1.3.4.2 thorpej #include <dev/ic/ac97reg.h>
57 1.3.4.2 thorpej #include <dev/ic/ac97var.h>
58 1.3.4.2 thorpej #include <dev/ic/mpuvar.h>
59 1.3.4.2 thorpej
60 1.3.4.2 thorpej #include <machine/bus.h>
61 1.3.4.2 thorpej #include <machine/intr.h>
62 1.3.4.2 thorpej
63 1.3.4.2 thorpej #include <dev/pci/autrireg.h>
64 1.3.4.2 thorpej #include <dev/pci/autrivar.h>
65 1.3.4.2 thorpej
66 1.3.4.2 thorpej #ifdef AUDIO_DEBUG
67 1.3.4.2 thorpej # define DPRINTF(x) if (autridebug) printf x
68 1.3.4.2 thorpej # define DPRINTFN(n,x) if (autridebug > (n)) printf x
69 1.3.4.2 thorpej int autridebug = 0;
70 1.3.4.2 thorpej #else
71 1.3.4.2 thorpej # define DPRINTF(x)
72 1.3.4.2 thorpej # define DPRINTFN(n,x)
73 1.3.4.2 thorpej #endif
74 1.3.4.2 thorpej
75 1.3.4.2 thorpej int autri_match(struct device *, struct cfdata *, void *);
76 1.3.4.2 thorpej void autri_attach(struct device *, struct device *, void *);
77 1.3.4.2 thorpej int autri_intr(void *);
78 1.3.4.2 thorpej
79 1.3.4.2 thorpej #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
80 1.3.4.2 thorpej #define KERNADDR(p) ((void *)((p)->addr))
81 1.3.4.2 thorpej
82 1.3.4.2 thorpej int autri_allocmem(struct autri_softc *, size_t,
83 1.3.4.2 thorpej size_t, struct autri_dma *);
84 1.3.4.2 thorpej int autri_freemem(struct autri_softc *, struct autri_dma *);
85 1.3.4.2 thorpej
86 1.3.4.2 thorpej #define TWRITE1(sc, r, x) bus_space_write_1((sc)->memt, (sc)->memh, (r), (x))
87 1.3.4.2 thorpej #define TWRITE2(sc, r, x) bus_space_write_2((sc)->memt, (sc)->memh, (r), (x))
88 1.3.4.2 thorpej #define TWRITE4(sc, r, x) bus_space_write_4((sc)->memt, (sc)->memh, (r), (x))
89 1.3.4.2 thorpej #define TREAD1(sc, r) bus_space_read_1((sc)->memt, (sc)->memh, (r))
90 1.3.4.2 thorpej #define TREAD2(sc, r) bus_space_read_2((sc)->memt, (sc)->memh, (r))
91 1.3.4.2 thorpej #define TREAD4(sc, r) bus_space_read_4((sc)->memt, (sc)->memh, (r))
92 1.3.4.2 thorpej
93 1.3.4.2 thorpej static __inline void autri_reg_set_1(struct autri_softc *, int, uint8_t);
94 1.3.4.2 thorpej static __inline void autri_reg_clear_1(struct autri_softc *, int, uint8_t);
95 1.3.4.2 thorpej static __inline void autri_reg_set_4(struct autri_softc *, int, uint32_t);
96 1.3.4.2 thorpej static __inline void autri_reg_clear_4(struct autri_softc *, int, uint32_t);
97 1.3.4.2 thorpej
98 1.3.4.2 thorpej int autri_attach_codec(void *sc, struct ac97_codec_if *);
99 1.3.4.2 thorpej int autri_read_codec(void *sc, u_int8_t a, u_int16_t *d);
100 1.3.4.2 thorpej int autri_write_codec(void *sc, u_int8_t a, u_int16_t d);
101 1.3.4.2 thorpej void autri_reset_codec(void *sc);
102 1.3.4.2 thorpej
103 1.3.4.2 thorpej static void autri_powerhook(int why,void *addr);
104 1.3.4.2 thorpej static int autri_init(void *sc);
105 1.3.4.2 thorpej static struct autri_dma *autri_find_dma(struct autri_softc *, void *);
106 1.3.4.2 thorpej static void autri_setup_channel(struct autri_softc *sc,int mode,
107 1.3.4.2 thorpej struct audio_params *param);
108 1.3.4.2 thorpej static void autri_enable_interrupt(struct autri_softc *sc, int ch);
109 1.3.4.2 thorpej static void autri_disable_interrupt(struct autri_softc *sc, int ch);
110 1.3.4.2 thorpej static void autri_startch(struct autri_softc *sc, int ch, int ch_intr);
111 1.3.4.2 thorpej static void autri_stopch(struct autri_softc *sc, int ch, int ch_intr);
112 1.3.4.2 thorpej static void autri_enable_loop_interrupt(void *sc);
113 1.3.4.2 thorpej #if 0
114 1.3.4.2 thorpej static void autri_disable_loop_interrupt(void *sc);
115 1.3.4.2 thorpej #endif
116 1.3.4.2 thorpej
117 1.3.4.2 thorpej struct cfattach autri_ca = {
118 1.3.4.2 thorpej sizeof(struct autri_softc), autri_match, autri_attach
119 1.3.4.2 thorpej };
120 1.3.4.2 thorpej
121 1.3.4.2 thorpej int autri_open(void *, int);
122 1.3.4.2 thorpej void autri_close(void *);
123 1.3.4.2 thorpej int autri_query_encoding(void *, struct audio_encoding *);
124 1.3.4.2 thorpej int autri_set_params(void *, int, int,
125 1.3.4.2 thorpej struct audio_params *, struct audio_params *);
126 1.3.4.2 thorpej int autri_round_blocksize(void *, int);
127 1.3.4.2 thorpej int autri_trigger_output(void *, void *, void *, int, void (*)(void *),
128 1.3.4.2 thorpej void *, struct audio_params *);
129 1.3.4.2 thorpej int autri_trigger_input(void *, void *, void *, int, void (*)(void *),
130 1.3.4.2 thorpej void *, struct audio_params *);
131 1.3.4.2 thorpej int autri_halt_output(void *);
132 1.3.4.2 thorpej int autri_halt_input(void *);
133 1.3.4.2 thorpej int autri_getdev(void *, struct audio_device *);
134 1.3.4.2 thorpej int autri_mixer_set_port(void *, mixer_ctrl_t *);
135 1.3.4.2 thorpej int autri_mixer_get_port(void *, mixer_ctrl_t *);
136 1.3.4.2 thorpej void* autri_malloc(void *, int, size_t, int, int);
137 1.3.4.2 thorpej void autri_free(void *, void *, int);
138 1.3.4.2 thorpej size_t autri_round_buffersize(void *, int, size_t);
139 1.3.4.2 thorpej paddr_t autri_mappage(void *, void *, off_t, int);
140 1.3.4.2 thorpej int autri_get_props(void *);
141 1.3.4.2 thorpej int autri_query_devinfo(void *addr, mixer_devinfo_t *dip);
142 1.3.4.2 thorpej
143 1.3.4.2 thorpej int autri_get_portnum_by_name(struct autri_softc *, char *, char *, char *);
144 1.3.4.2 thorpej
145 1.3.4.2 thorpej static struct audio_hw_if autri_hw_if = {
146 1.3.4.2 thorpej autri_open,
147 1.3.4.2 thorpej autri_close,
148 1.3.4.2 thorpej NULL, /* drain */
149 1.3.4.2 thorpej autri_query_encoding,
150 1.3.4.2 thorpej autri_set_params,
151 1.3.4.2 thorpej autri_round_blocksize,
152 1.3.4.2 thorpej NULL, /* commit_settings */
153 1.3.4.2 thorpej NULL, /* init_output */
154 1.3.4.2 thorpej NULL, /* init_input */
155 1.3.4.2 thorpej NULL, /* start_output */
156 1.3.4.2 thorpej NULL, /* start_input */
157 1.3.4.2 thorpej autri_halt_output,
158 1.3.4.2 thorpej autri_halt_input,
159 1.3.4.2 thorpej NULL, /* speaker_ctl */
160 1.3.4.2 thorpej autri_getdev,
161 1.3.4.2 thorpej NULL, /* setfd */
162 1.3.4.2 thorpej autri_mixer_set_port,
163 1.3.4.2 thorpej autri_mixer_get_port,
164 1.3.4.2 thorpej autri_query_devinfo,
165 1.3.4.2 thorpej autri_malloc,
166 1.3.4.2 thorpej autri_free,
167 1.3.4.2 thorpej autri_round_buffersize,
168 1.3.4.2 thorpej autri_mappage,
169 1.3.4.2 thorpej autri_get_props,
170 1.3.4.2 thorpej autri_trigger_output,
171 1.3.4.2 thorpej autri_trigger_input,
172 1.3.4.2 thorpej NULL, /* dev_ioctl */
173 1.3.4.2 thorpej };
174 1.3.4.2 thorpej
175 1.3.4.2 thorpej #if NMIDI > 0
176 1.3.4.2 thorpej void autri_midi_close(void *);
177 1.3.4.2 thorpej void autri_midi_getinfo(void *, struct midi_info *);
178 1.3.4.2 thorpej int autri_midi_open(void *, int, void (*)(void *, int),
179 1.3.4.2 thorpej void (*)(void *), void *);
180 1.3.4.2 thorpej int autri_midi_output(void *, int);
181 1.3.4.2 thorpej
182 1.3.4.2 thorpej struct midi_hw_if autri_midi_hw_if = {
183 1.3.4.2 thorpej autri_midi_open,
184 1.3.4.2 thorpej autri_midi_close,
185 1.3.4.2 thorpej autri_midi_output,
186 1.3.4.2 thorpej autri_midi_getinfo,
187 1.3.4.2 thorpej NULL, /* ioctl */
188 1.3.4.2 thorpej };
189 1.3.4.2 thorpej #endif
190 1.3.4.2 thorpej
191 1.3.4.2 thorpej /*
192 1.3.4.2 thorpej * register set/clear bit
193 1.3.4.2 thorpej */
194 1.3.4.2 thorpej static __inline void
195 1.3.4.2 thorpej autri_reg_set_1(struct autri_softc *sc, int no, uint8_t mask)
196 1.3.4.2 thorpej {
197 1.3.4.2 thorpej bus_space_write_1(sc->memt, sc->memh, no,
198 1.3.4.2 thorpej (bus_space_read_1(sc->memt, sc->memh, no) | mask));
199 1.3.4.2 thorpej }
200 1.3.4.2 thorpej
201 1.3.4.2 thorpej static __inline void
202 1.3.4.2 thorpej autri_reg_clear_1(struct autri_softc *sc, int no, uint8_t mask)
203 1.3.4.2 thorpej {
204 1.3.4.2 thorpej bus_space_write_1(sc->memt, sc->memh, no,
205 1.3.4.2 thorpej (bus_space_read_1(sc->memt, sc->memh, no) & ~mask));
206 1.3.4.2 thorpej }
207 1.3.4.2 thorpej
208 1.3.4.2 thorpej static __inline void
209 1.3.4.2 thorpej autri_reg_set_4(struct autri_softc *sc, int no, uint32_t mask)
210 1.3.4.2 thorpej {
211 1.3.4.2 thorpej bus_space_write_4(sc->memt, sc->memh, no,
212 1.3.4.2 thorpej (bus_space_read_4(sc->memt, sc->memh, no) | mask));
213 1.3.4.2 thorpej }
214 1.3.4.2 thorpej
215 1.3.4.2 thorpej static __inline void
216 1.3.4.2 thorpej autri_reg_clear_4(struct autri_softc *sc, int no, uint32_t mask)
217 1.3.4.2 thorpej {
218 1.3.4.2 thorpej bus_space_write_4(sc->memt, sc->memh, no,
219 1.3.4.2 thorpej (bus_space_read_4(sc->memt, sc->memh, no) & ~mask));
220 1.3.4.2 thorpej }
221 1.3.4.2 thorpej
222 1.3.4.2 thorpej /*
223 1.3.4.2 thorpej * AC'97 codec
224 1.3.4.2 thorpej */
225 1.3.4.2 thorpej int
226 1.3.4.2 thorpej autri_attach_codec(void *sc_, struct ac97_codec_if *codec_if)
227 1.3.4.2 thorpej {
228 1.3.4.2 thorpej struct autri_codec_softc *sc = sc_;
229 1.3.4.2 thorpej
230 1.3.4.2 thorpej DPRINTF(("autri_attach_codec()\n"));
231 1.3.4.2 thorpej
232 1.3.4.2 thorpej sc->codec_if = codec_if;
233 1.3.4.2 thorpej return 0;
234 1.3.4.2 thorpej }
235 1.3.4.2 thorpej
236 1.3.4.2 thorpej int
237 1.3.4.2 thorpej autri_read_codec(void *sc_, u_int8_t index, u_int16_t *data)
238 1.3.4.2 thorpej {
239 1.3.4.2 thorpej struct autri_codec_softc *codec = sc_;
240 1.3.4.2 thorpej struct autri_softc *sc = codec->sc;
241 1.3.4.2 thorpej u_int32_t status, addr, cmd, busy;
242 1.3.4.2 thorpej u_int16_t count;
243 1.3.4.2 thorpej
244 1.3.4.2 thorpej /*DPRINTF(("sc->sc->type : 0x%X",sc->sc->type));*/
245 1.3.4.2 thorpej
246 1.3.4.2 thorpej switch (sc->sc_devid) {
247 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
248 1.3.4.2 thorpej addr = AUTRI_DX_ACR1;
249 1.3.4.2 thorpej cmd = AUTRI_DX_ACR1_CMD_READ;
250 1.3.4.2 thorpej busy = AUTRI_DX_ACR1_BUSY_READ;
251 1.3.4.2 thorpej break;
252 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
253 1.3.4.2 thorpej addr = AUTRI_NX_ACR2;
254 1.3.4.2 thorpej cmd = AUTRI_NX_ACR2_CMD_READ;
255 1.3.4.2 thorpej busy = AUTRI_NX_ACR2_BUSY_READ | AUTRI_NX_ACR2_RECV_WAIT;
256 1.3.4.2 thorpej break;
257 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
258 1.3.4.2 thorpej addr = AUTRI_SIS_ACRD;
259 1.3.4.2 thorpej cmd = AUTRI_SIS_ACRD_CMD_READ;
260 1.3.4.2 thorpej busy = AUTRI_SIS_ACRD_BUSY_READ | AUTRI_SIS_ACRD_AUDIO_BUSY;
261 1.3.4.2 thorpej break;
262 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
263 1.3.4.2 thorpej if (sc->sc_revision > 0x01)
264 1.3.4.2 thorpej addr = AUTRI_ALI_ACWR;
265 1.3.4.2 thorpej else
266 1.3.4.2 thorpej addr = AUTRI_ALI_ACRD;
267 1.3.4.2 thorpej cmd = AUTRI_ALI_ACRD_CMD_READ;
268 1.3.4.2 thorpej busy = AUTRI_ALI_ACRD_BUSY_READ;
269 1.3.4.2 thorpej break;
270 1.3.4.2 thorpej default:
271 1.3.4.2 thorpej printf("%s: autri_read_codec : unknown device\n",
272 1.3.4.2 thorpej sc->sc_dev.dv_xname);
273 1.3.4.2 thorpej return -1;
274 1.3.4.2 thorpej }
275 1.3.4.2 thorpej
276 1.3.4.2 thorpej /* wait for 'Ready to Read' */
277 1.3.4.2 thorpej for (count=0; count<0xffff; count++) {
278 1.3.4.2 thorpej if ((TREAD4(sc, addr) & busy) == 0)
279 1.3.4.2 thorpej break;
280 1.3.4.2 thorpej }
281 1.3.4.2 thorpej
282 1.3.4.2 thorpej if (count == 0xffff) {
283 1.3.4.2 thorpej printf("%s: Codec timeout. Busy reading AC'97 codec.\n",
284 1.3.4.2 thorpej sc->sc_dev.dv_xname);
285 1.3.4.2 thorpej return -1;
286 1.3.4.2 thorpej }
287 1.3.4.2 thorpej
288 1.3.4.2 thorpej /* send Read Command to AC'97 */
289 1.3.4.2 thorpej TWRITE4(sc, addr, (index & 0x7f) | cmd);
290 1.3.4.2 thorpej
291 1.3.4.2 thorpej /* wait for 'Returned data is avalable' */
292 1.3.4.2 thorpej for (count=0; count<0xffff; count++) {
293 1.3.4.2 thorpej status = TREAD4(sc, addr);
294 1.3.4.2 thorpej if ((status & busy) == 0)
295 1.3.4.2 thorpej break;
296 1.3.4.2 thorpej }
297 1.3.4.2 thorpej
298 1.3.4.2 thorpej if (count == 0xffff) {
299 1.3.4.2 thorpej printf("%s: Codec timeout. Busy reading AC'97 codec.\n",
300 1.3.4.2 thorpej sc->sc_dev.dv_xname);
301 1.3.4.2 thorpej return -1;
302 1.3.4.2 thorpej }
303 1.3.4.2 thorpej
304 1.3.4.2 thorpej *data = (status >> 16) & 0x0000ffff;
305 1.3.4.2 thorpej /*DPRINTF(("autri_read_codec(0x%X) return 0x%X\n",reg,*data));*/
306 1.3.4.2 thorpej return 0;
307 1.3.4.2 thorpej }
308 1.3.4.2 thorpej
309 1.3.4.2 thorpej int
310 1.3.4.2 thorpej autri_write_codec(void *sc_, u_int8_t index, u_int16_t data)
311 1.3.4.2 thorpej {
312 1.3.4.2 thorpej struct autri_codec_softc *codec = sc_;
313 1.3.4.2 thorpej struct autri_softc *sc = codec->sc;
314 1.3.4.2 thorpej u_int32_t addr, cmd, busy;
315 1.3.4.2 thorpej u_int16_t count;
316 1.3.4.2 thorpej
317 1.3.4.2 thorpej /*DPRINTF(("autri_write_codec(0x%X,0x%X)\n",index,data));*/
318 1.3.4.2 thorpej
319 1.3.4.2 thorpej switch (sc->sc_devid) {
320 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
321 1.3.4.2 thorpej addr = AUTRI_DX_ACR0;
322 1.3.4.2 thorpej cmd = AUTRI_DX_ACR0_CMD_WRITE;
323 1.3.4.2 thorpej busy = AUTRI_DX_ACR0_BUSY_WRITE;
324 1.3.4.2 thorpej break;
325 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
326 1.3.4.2 thorpej addr = AUTRI_NX_ACR1;
327 1.3.4.2 thorpej cmd = AUTRI_NX_ACR1_CMD_WRITE;
328 1.3.4.2 thorpej busy = AUTRI_NX_ACR1_BUSY_WRITE;
329 1.3.4.2 thorpej break;
330 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
331 1.3.4.2 thorpej addr = AUTRI_SIS_ACWR;
332 1.3.4.2 thorpej cmd = AUTRI_SIS_ACWR_CMD_WRITE;
333 1.3.4.2 thorpej busy = AUTRI_SIS_ACWR_BUSY_WRITE | AUTRI_SIS_ACWR_AUDIO_BUSY;
334 1.3.4.2 thorpej break;
335 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
336 1.3.4.2 thorpej addr = AUTRI_ALI_ACWR;
337 1.3.4.2 thorpej cmd = AUTRI_ALI_ACWR_CMD_WRITE;
338 1.3.4.2 thorpej if (sc->sc_revision > 0x01)
339 1.3.4.2 thorpej cmd |= 0x0100;
340 1.3.4.2 thorpej busy = AUTRI_ALI_ACWR_BUSY_WRITE;
341 1.3.4.2 thorpej break;
342 1.3.4.2 thorpej default:
343 1.3.4.2 thorpej printf("%s: autri_write_codec : unknown device.\n",
344 1.3.4.2 thorpej sc->sc_dev.dv_xname);
345 1.3.4.2 thorpej return -1;
346 1.3.4.2 thorpej }
347 1.3.4.2 thorpej
348 1.3.4.2 thorpej /* wait for 'Ready to Write' */
349 1.3.4.2 thorpej for (count=0; count<0xffff; count++) {
350 1.3.4.2 thorpej if ((TREAD4(sc, addr) & busy) == 0)
351 1.3.4.2 thorpej break;
352 1.3.4.2 thorpej }
353 1.3.4.2 thorpej
354 1.3.4.2 thorpej if (count == 0xffff) {
355 1.3.4.2 thorpej printf("%s: Codec timeout. Busy writing AC'97 codec\n",
356 1.3.4.2 thorpej sc->sc_dev.dv_xname);
357 1.3.4.2 thorpej return -1;
358 1.3.4.2 thorpej }
359 1.3.4.2 thorpej
360 1.3.4.2 thorpej /* send Write Command to AC'97 */
361 1.3.4.2 thorpej TWRITE4(sc, addr, (data << 16) | (index & 0x7f) | cmd);
362 1.3.4.2 thorpej
363 1.3.4.2 thorpej return 0;
364 1.3.4.2 thorpej }
365 1.3.4.2 thorpej
366 1.3.4.2 thorpej void
367 1.3.4.2 thorpej autri_reset_codec(void *sc_)
368 1.3.4.2 thorpej {
369 1.3.4.2 thorpej struct autri_codec_softc *codec = sc_;
370 1.3.4.2 thorpej struct autri_softc *sc = codec->sc;
371 1.3.4.2 thorpej u_int32_t reg, ready;
372 1.3.4.2 thorpej int addr, count = 200;
373 1.3.4.2 thorpej
374 1.3.4.2 thorpej DPRINTF(("autri_reset_codec(codec=%p,sc=%p)\n",codec,sc));
375 1.3.4.2 thorpej DPRINTF(("sc->sc_devid=%X\n",sc->sc_devid));
376 1.3.4.2 thorpej
377 1.3.4.3 jdolecek switch (sc->sc_devid) {
378 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
379 1.3.4.2 thorpej /* warm reset AC'97 codec */
380 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_DX_ACR2, 1);
381 1.3.4.2 thorpej delay(100);
382 1.3.4.2 thorpej /* release reset */
383 1.3.4.2 thorpej autri_reg_clear_4(sc, AUTRI_DX_ACR2, 1);
384 1.3.4.2 thorpej delay(100);
385 1.3.4.2 thorpej
386 1.3.4.2 thorpej addr = AUTRI_DX_ACR2;
387 1.3.4.2 thorpej ready = AUTRI_DX_ACR2_CODEC_READY;
388 1.3.4.2 thorpej break;
389 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
390 1.3.4.2 thorpej /* warm reset AC'97 codec */
391 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_NX_ACR0, 1);
392 1.3.4.2 thorpej delay(100);
393 1.3.4.2 thorpej /* release reset */
394 1.3.4.2 thorpej autri_reg_clear_4(sc, AUTRI_NX_ACR0, 1);
395 1.3.4.2 thorpej delay(100);
396 1.3.4.2 thorpej
397 1.3.4.2 thorpej addr = AUTRI_NX_ACR0;
398 1.3.4.2 thorpej ready = AUTRI_NX_ACR0_CODEC_READY;
399 1.3.4.2 thorpej break;
400 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
401 1.3.4.4 jdolecek /* cold reset AC'97 codec */
402 1.3.4.4 jdolecek autri_reg_set_4(sc, AUTRI_SIS_SCTRL, 2);
403 1.3.4.4 jdolecek delay(1000);
404 1.3.4.2 thorpej /* release reset (warm & cold) */
405 1.3.4.2 thorpej autri_reg_clear_4(sc, AUTRI_SIS_SCTRL, 3);
406 1.3.4.4 jdolecek delay(2000);
407 1.3.4.2 thorpej
408 1.3.4.2 thorpej addr = AUTRI_SIS_SCTRL;
409 1.3.4.2 thorpej ready = AUTRI_SIS_SCTRL_CODEC_READY;
410 1.3.4.2 thorpej break;
411 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
412 1.3.4.2 thorpej /* warm reset AC'97 codec */
413 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_ALI_SCTRL, 1);
414 1.3.4.2 thorpej delay(100);
415 1.3.4.2 thorpej /* release reset (warm & cold) */
416 1.3.4.2 thorpej autri_reg_clear_4(sc, AUTRI_ALI_SCTRL, 3);
417 1.3.4.2 thorpej delay(100);
418 1.3.4.2 thorpej
419 1.3.4.2 thorpej addr = AUTRI_ALI_SCTRL;
420 1.3.4.2 thorpej ready = AUTRI_ALI_SCTRL_CODEC_READY;
421 1.3.4.2 thorpej break;
422 1.3.4.2 thorpej }
423 1.3.4.2 thorpej
424 1.3.4.2 thorpej /* wait for 'Codec Ready' */
425 1.3.4.2 thorpej while (count--) {
426 1.3.4.2 thorpej reg = TREAD4(sc, addr);
427 1.3.4.2 thorpej if (reg & ready)
428 1.3.4.2 thorpej break;
429 1.3.4.2 thorpej delay(1000);
430 1.3.4.2 thorpej }
431 1.3.4.2 thorpej
432 1.3.4.2 thorpej if (count == 0)
433 1.3.4.2 thorpej printf("%s: Codec timeout. AC'97 is not ready for operation.\n",
434 1.3.4.2 thorpej sc->sc_dev.dv_xname);
435 1.3.4.2 thorpej }
436 1.3.4.2 thorpej
437 1.3.4.2 thorpej /*
438 1.3.4.2 thorpej *
439 1.3.4.2 thorpej */
440 1.3.4.2 thorpej
441 1.3.4.2 thorpej int
442 1.3.4.2 thorpej autri_match(struct device *parent, struct cfdata *match, void *aux)
443 1.3.4.2 thorpej {
444 1.3.4.2 thorpej struct pci_attach_args *pa = (struct pci_attach_args *) aux;
445 1.3.4.2 thorpej
446 1.3.4.2 thorpej switch (PCI_VENDOR(pa->pa_id)) {
447 1.3.4.2 thorpej case PCI_VENDOR_TRIDENT:
448 1.3.4.2 thorpej switch (PCI_PRODUCT(pa->pa_id)) {
449 1.3.4.2 thorpej case PCI_PRODUCT_TRIDENT_4DWAVE_DX:
450 1.3.4.2 thorpej case PCI_PRODUCT_TRIDENT_4DWAVE_NX:
451 1.3.4.2 thorpej return 1;
452 1.3.4.2 thorpej }
453 1.3.4.2 thorpej break;
454 1.3.4.2 thorpej case PCI_VENDOR_SIS:
455 1.3.4.2 thorpej switch (PCI_PRODUCT(pa->pa_id)) {
456 1.3.4.2 thorpej case PCI_PRODUCT_SIS_7018:
457 1.3.4.2 thorpej return 1;
458 1.3.4.2 thorpej }
459 1.3.4.2 thorpej break;
460 1.3.4.2 thorpej case PCI_VENDOR_ALI:
461 1.3.4.2 thorpej switch (PCI_PRODUCT(pa->pa_id)) {
462 1.3.4.2 thorpej case PCI_PRODUCT_ALI_M5451:
463 1.3.4.2 thorpej return 1;
464 1.3.4.2 thorpej }
465 1.3.4.2 thorpej break;
466 1.3.4.2 thorpej }
467 1.3.4.2 thorpej
468 1.3.4.2 thorpej return 0;
469 1.3.4.2 thorpej }
470 1.3.4.2 thorpej
471 1.3.4.2 thorpej void
472 1.3.4.2 thorpej autri_attach(struct device *parent, struct device *self, void *aux)
473 1.3.4.2 thorpej {
474 1.3.4.2 thorpej struct autri_softc *sc = (struct autri_softc *)self;
475 1.3.4.2 thorpej struct pci_attach_args *pa = (struct pci_attach_args *)aux;
476 1.3.4.2 thorpej pci_chipset_tag_t pc = pa->pa_pc;
477 1.3.4.2 thorpej struct autri_codec_softc *codec;
478 1.3.4.2 thorpej pci_intr_handle_t ih;
479 1.3.4.2 thorpej char const *intrstr;
480 1.3.4.2 thorpej char devinfo[256];
481 1.3.4.2 thorpej mixer_ctrl_t ctl;
482 1.3.4.2 thorpej int i, r;
483 1.3.4.2 thorpej u_int32_t reg;
484 1.3.4.2 thorpej
485 1.3.4.2 thorpej sc->sc_devid = pa->pa_id;
486 1.3.4.2 thorpej sc->sc_class = pa->pa_class;
487 1.3.4.2 thorpej
488 1.3.4.2 thorpej pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
489 1.3.4.2 thorpej sc->sc_revision = PCI_REVISION(pa->pa_class);
490 1.3.4.2 thorpej printf(": %s (rev. 0x%02x)\n", devinfo, sc->sc_revision);
491 1.3.4.2 thorpej
492 1.3.4.2 thorpej /* map register to memory */
493 1.3.4.2 thorpej if (pci_mapreg_map(pa, AUTRI_PCI_MEMORY_BASE,
494 1.3.4.2 thorpej PCI_MAPREG_TYPE_MEM, 0, &sc->memt, &sc->memh, NULL, NULL)) {
495 1.3.4.2 thorpej printf("%s: can't map memory space\n", sc->sc_dev.dv_xname);
496 1.3.4.2 thorpej return;
497 1.3.4.2 thorpej }
498 1.3.4.2 thorpej
499 1.3.4.2 thorpej /* map and establish the interrupt */
500 1.3.4.2 thorpej if (pci_intr_map(pa, &ih)) {
501 1.3.4.2 thorpej printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
502 1.3.4.2 thorpej return;
503 1.3.4.2 thorpej }
504 1.3.4.2 thorpej intrstr = pci_intr_string(pc, ih);
505 1.3.4.2 thorpej sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, autri_intr, sc);
506 1.3.4.2 thorpej if (sc->sc_ih == NULL) {
507 1.3.4.2 thorpej printf("%s: couldn't establish interrupt",
508 1.3.4.2 thorpej sc->sc_dev.dv_xname);
509 1.3.4.2 thorpej if (intrstr != NULL)
510 1.3.4.2 thorpej printf(" at %s", intrstr);
511 1.3.4.2 thorpej printf("\n");
512 1.3.4.2 thorpej return;
513 1.3.4.2 thorpej }
514 1.3.4.2 thorpej printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
515 1.3.4.2 thorpej
516 1.3.4.2 thorpej sc->sc_dmatag = pa->pa_dmat;
517 1.3.4.2 thorpej sc->sc_pc = pc;
518 1.3.4.2 thorpej sc->sc_pt = pa->pa_tag;
519 1.3.4.2 thorpej
520 1.3.4.2 thorpej /* enable the device */
521 1.3.4.2 thorpej reg = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
522 1.3.4.2 thorpej reg |= (PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE);
523 1.3.4.2 thorpej pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
524 1.3.4.2 thorpej
525 1.3.4.2 thorpej /* initialize the device */
526 1.3.4.2 thorpej autri_init(sc);
527 1.3.4.2 thorpej
528 1.3.4.2 thorpej /* attach AC'97 codec */
529 1.3.4.2 thorpej codec = &sc->sc_codec;
530 1.3.4.2 thorpej memcpy(&codec->sc_dev, &sc->sc_dev, sizeof(codec->sc_dev));
531 1.3.4.2 thorpej codec->sc = sc;
532 1.3.4.2 thorpej
533 1.3.4.2 thorpej codec->host_if.arg = codec;
534 1.3.4.2 thorpej codec->host_if.attach = autri_attach_codec;
535 1.3.4.2 thorpej codec->host_if.reset = autri_reset_codec;
536 1.3.4.2 thorpej codec->host_if.read = autri_read_codec;
537 1.3.4.2 thorpej codec->host_if.write = autri_write_codec;
538 1.3.4.2 thorpej
539 1.3.4.2 thorpej if ((r = ac97_attach(&codec->host_if)) != 0) {
540 1.3.4.2 thorpej printf("%s: can't attach codec (error 0x%X)\n",
541 1.3.4.2 thorpej sc->sc_dev.dv_xname, r);
542 1.3.4.2 thorpej return;
543 1.3.4.2 thorpej }
544 1.3.4.2 thorpej
545 1.3.4.2 thorpej /* disable mutes */
546 1.3.4.2 thorpej for (i = 0; i < 4; i++) {
547 1.3.4.2 thorpej static struct {
548 1.3.4.2 thorpej char *class, *device;
549 1.3.4.2 thorpej } d[] = {
550 1.3.4.2 thorpej { AudioCoutputs, AudioNmaster},
551 1.3.4.2 thorpej { AudioCinputs, AudioNdac},
552 1.3.4.2 thorpej { AudioCinputs, AudioNcd},
553 1.3.4.2 thorpej { AudioCrecord, AudioNvolume},
554 1.3.4.2 thorpej };
555 1.3.4.2 thorpej
556 1.3.4.2 thorpej ctl.type = AUDIO_MIXER_ENUM;
557 1.3.4.2 thorpej ctl.un.ord = 0;
558 1.3.4.2 thorpej
559 1.3.4.2 thorpej #if 0
560 1.3.4.2 thorpej ctl.dev = sc->sc_codec.codec_if->vtbl->get_portnum_by_name(sc->sc_codec.codec_if,
561 1.3.4.2 thorpej d[i].class, d[i].device, AudioNmute);
562 1.3.4.2 thorpej #endif
563 1.3.4.2 thorpej ctl.dev = autri_get_portnum_by_name(sc,d[i].class,
564 1.3.4.2 thorpej d[i].device, AudioNmute);
565 1.3.4.2 thorpej autri_mixer_set_port(sc, &ctl);
566 1.3.4.2 thorpej }
567 1.3.4.2 thorpej
568 1.3.4.2 thorpej /* set a reasonable default volume */
569 1.3.4.2 thorpej ctl.type = AUDIO_MIXER_VALUE;
570 1.3.4.2 thorpej ctl.un.value.num_channels = 2;
571 1.3.4.2 thorpej ctl.un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
572 1.3.4.2 thorpej ctl.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 127;
573 1.3.4.2 thorpej
574 1.3.4.2 thorpej ctl.dev = autri_get_portnum_by_name(sc,AudioCoutputs,AudioNmaster,NULL);
575 1.3.4.2 thorpej autri_mixer_set_port(sc, &ctl);
576 1.3.4.2 thorpej
577 1.3.4.2 thorpej audio_attach_mi(&autri_hw_if, sc, &sc->sc_dev);
578 1.3.4.2 thorpej
579 1.3.4.2 thorpej #if NMIDI > 0
580 1.3.4.2 thorpej midi_attach_mi(&autri_midi_hw_if, sc, &sc->sc_dev);
581 1.3.4.2 thorpej #endif
582 1.3.4.2 thorpej
583 1.3.4.2 thorpej sc->sc_old_power = PWR_RESUME;
584 1.3.4.2 thorpej powerhook_establish(autri_powerhook, sc);
585 1.3.4.2 thorpej }
586 1.3.4.2 thorpej
587 1.3.4.2 thorpej static void
588 1.3.4.2 thorpej autri_powerhook(int why, void *addr)
589 1.3.4.2 thorpej {
590 1.3.4.2 thorpej struct autri_softc *sc = addr;
591 1.3.4.2 thorpej
592 1.3.4.2 thorpej if (why == PWR_RESUME && sc->sc_old_power == PWR_SUSPEND) {
593 1.3.4.2 thorpej DPRINTF(("PWR_RESUME\n"));
594 1.3.4.2 thorpej autri_init(sc);
595 1.3.4.2 thorpej /*autri_reset_codec(&sc->sc_codec);*/
596 1.3.4.2 thorpej (sc->sc_codec.codec_if->vtbl->restore_ports)(sc->sc_codec.codec_if);
597 1.3.4.2 thorpej }
598 1.3.4.2 thorpej sc->sc_old_power = why;
599 1.3.4.2 thorpej }
600 1.3.4.2 thorpej
601 1.3.4.2 thorpej int
602 1.3.4.2 thorpej autri_init(void *sc_)
603 1.3.4.2 thorpej {
604 1.3.4.2 thorpej struct autri_softc *sc = sc_;
605 1.3.4.2 thorpej u_int32_t reg;
606 1.3.4.2 thorpej
607 1.3.4.2 thorpej pci_chipset_tag_t pc = sc->sc_pc;
608 1.3.4.2 thorpej pcitag_t pt = sc->sc_pt;
609 1.3.4.2 thorpej
610 1.3.4.2 thorpej DPRINTF(("in autri_init()\n"));
611 1.3.4.2 thorpej DPRINTFN(5,("pci_conf_read(0x40) : 0x%X\n",pci_conf_read(pc,pt,0x40)));
612 1.3.4.2 thorpej DPRINTFN(5,("pci_conf_read(0x44) : 0x%X\n",pci_conf_read(pc,pt,0x44)));
613 1.3.4.2 thorpej
614 1.3.4.2 thorpej switch (sc->sc_devid) {
615 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
616 1.3.4.2 thorpej /* disable Legacy Control */
617 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_DDMA_CFG,0);
618 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
619 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & 0xffff0000);
620 1.3.4.2 thorpej delay(100);
621 1.3.4.2 thorpej /* audio engine reset */
622 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
623 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg | 0x00040000);
624 1.3.4.2 thorpej delay(100);
625 1.3.4.2 thorpej /* release reset */
626 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
627 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & ~0x00040000);
628 1.3.4.2 thorpej delay(100);
629 1.3.4.2 thorpej /* DAC on */
630 1.3.4.2 thorpej autri_reg_set_4(sc,AUTRI_DX_ACR2,0x02);
631 1.3.4.2 thorpej break;
632 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
633 1.3.4.2 thorpej /* disable Legacy Control */
634 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_DDMA_CFG,0);
635 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
636 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & 0xffff0000);
637 1.3.4.2 thorpej delay(100);
638 1.3.4.2 thorpej /* audio engine reset */
639 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
640 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg | 0x00010000);
641 1.3.4.2 thorpej delay(100);
642 1.3.4.2 thorpej /* release reset */
643 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
644 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & ~0x00010000);
645 1.3.4.2 thorpej delay(100);
646 1.3.4.2 thorpej /* DAC on */
647 1.3.4.2 thorpej autri_reg_set_4(sc,AUTRI_NX_ACR0,0x02);
648 1.3.4.2 thorpej break;
649 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
650 1.3.4.2 thorpej /* disable Legacy Control */
651 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_DDMA_CFG,0);
652 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
653 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & 0xffff0000);
654 1.3.4.2 thorpej delay(100);
655 1.3.4.2 thorpej /* reset Digital Controller */
656 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
657 1.3.4.4 jdolecek pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg | 0x00040000);
658 1.3.4.2 thorpej delay(100);
659 1.3.4.2 thorpej /* release reset */
660 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
661 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & ~0x00040000);
662 1.3.4.2 thorpej delay(100);
663 1.3.4.2 thorpej /* disable AC97 GPIO interrupt */
664 1.3.4.2 thorpej TWRITE1(sc, AUTRI_SIS_ACGPIO, 0);
665 1.3.4.2 thorpej /* enable 64 channel mode */
666 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_LFO_GC_CIR, BANK_B_EN);
667 1.3.4.2 thorpej break;
668 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
669 1.3.4.2 thorpej /* disable Legacy Control */
670 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_DDMA_CFG,0);
671 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
672 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & 0xffff0000);
673 1.3.4.2 thorpej delay(100);
674 1.3.4.2 thorpej /* reset Digital Controller */
675 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
676 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg | 0x000c0000);
677 1.3.4.2 thorpej delay(100);
678 1.3.4.2 thorpej /* release reset */
679 1.3.4.2 thorpej reg = pci_conf_read(pc, pt, AUTRI_PCI_LEGACY_IOBASE);
680 1.3.4.2 thorpej pci_conf_write(pc, pt, AUTRI_PCI_LEGACY_IOBASE, reg & ~0x00040000);
681 1.3.4.2 thorpej delay(100);
682 1.3.4.2 thorpej /* enable PCM input */
683 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_ALI_GCONTROL, AUTRI_ALI_GCONTROL_PCM_IN);
684 1.3.4.2 thorpej break;
685 1.3.4.2 thorpej }
686 1.3.4.2 thorpej
687 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_ALI_M5451) {
688 1.3.4.2 thorpej sc->sc_play.ch = 0;
689 1.3.4.2 thorpej sc->sc_play.ch_intr = 1;
690 1.3.4.2 thorpej sc->sc_rec.ch = 31;
691 1.3.4.2 thorpej sc->sc_rec.ch_intr = 2;
692 1.3.4.2 thorpej } else {
693 1.3.4.2 thorpej sc->sc_play.ch = 0x20;
694 1.3.4.2 thorpej sc->sc_play.ch_intr = 0x21;
695 1.3.4.2 thorpej sc->sc_rec.ch = 0x22;
696 1.3.4.2 thorpej sc->sc_rec.ch_intr = 0x23;
697 1.3.4.2 thorpej }
698 1.3.4.2 thorpej
699 1.3.4.2 thorpej /* clear channel status */
700 1.3.4.2 thorpej TWRITE4(sc, AUTRI_STOP_A, 0xffffffff);
701 1.3.4.2 thorpej TWRITE4(sc, AUTRI_STOP_B, 0xffffffff);
702 1.3.4.2 thorpej
703 1.3.4.2 thorpej /* disable channel interrupt */
704 1.3.4.2 thorpej TWRITE4(sc, AUTRI_AINTEN_A, 0);
705 1.3.4.2 thorpej TWRITE4(sc, AUTRI_AINTEN_B, 0);
706 1.3.4.2 thorpej
707 1.3.4.2 thorpej #if 0
708 1.3.4.2 thorpej /* TLB */
709 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_4DWAVE_NX) {
710 1.3.4.2 thorpej TWRITE4(sc,AUTRI_NX_TLBC,0);
711 1.3.4.2 thorpej }
712 1.3.4.2 thorpej #endif
713 1.3.4.2 thorpej
714 1.3.4.2 thorpej autri_enable_loop_interrupt(sc);
715 1.3.4.2 thorpej
716 1.3.4.2 thorpej DPRINTF(("out autri_init()\n"));
717 1.3.4.2 thorpej return 0;
718 1.3.4.2 thorpej }
719 1.3.4.2 thorpej
720 1.3.4.2 thorpej static void
721 1.3.4.2 thorpej autri_enable_loop_interrupt(void *sc_)
722 1.3.4.2 thorpej {
723 1.3.4.2 thorpej struct autri_softc *sc = sc_;
724 1.3.4.2 thorpej u_int32_t reg;
725 1.3.4.2 thorpej
726 1.3.4.2 thorpej /*reg = (ENDLP_IE | MIDLP_IE);*/
727 1.3.4.2 thorpej reg = ENDLP_IE;
728 1.3.4.4 jdolecek
729 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_SIS_7018)
730 1.3.4.2 thorpej reg |= BANK_B_EN;
731 1.3.4.4 jdolecek
732 1.3.4.2 thorpej autri_reg_set_4(sc,AUTRI_LFO_GC_CIR,reg);
733 1.3.4.2 thorpej }
734 1.3.4.2 thorpej
735 1.3.4.2 thorpej #if 0
736 1.3.4.2 thorpej static void
737 1.3.4.2 thorpej autri_disable_loop_interrupt(void *sc_)
738 1.3.4.2 thorpej {
739 1.3.4.2 thorpej struct autri_softc *sc = sc_;
740 1.3.4.2 thorpej u_int32_t reg;
741 1.3.4.2 thorpej
742 1.3.4.2 thorpej reg = (ENDLP_IE | MIDLP_IE);
743 1.3.4.2 thorpej autri_reg_clear_4(sc,AUTRI_LFO_GC_CIR,reg);
744 1.3.4.2 thorpej }
745 1.3.4.2 thorpej #endif
746 1.3.4.2 thorpej
747 1.3.4.2 thorpej int
748 1.3.4.2 thorpej autri_intr(void *p)
749 1.3.4.2 thorpej {
750 1.3.4.2 thorpej struct autri_softc *sc = p;
751 1.3.4.2 thorpej u_int32_t intsrc;
752 1.3.4.2 thorpej u_int32_t mask, active[2];
753 1.3.4.2 thorpej int ch, endch;
754 1.3.4.2 thorpej /*
755 1.3.4.2 thorpej u_int32_t reg;
756 1.3.4.2 thorpej u_int32_t cso,eso;
757 1.3.4.2 thorpej */
758 1.3.4.2 thorpej
759 1.3.4.2 thorpej intsrc = TREAD4(sc,AUTRI_MISCINT);
760 1.3.4.2 thorpej if ((intsrc & (ADDRESS_IRQ|MPU401_IRQ)) == 0)
761 1.3.4.2 thorpej return 0;
762 1.3.4.2 thorpej
763 1.3.4.2 thorpej if (intsrc & ADDRESS_IRQ) {
764 1.3.4.2 thorpej
765 1.3.4.2 thorpej active[0] = TREAD4(sc,AUTRI_AIN_A);
766 1.3.4.2 thorpej active[1] = TREAD4(sc,AUTRI_AIN_B);
767 1.3.4.2 thorpej
768 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_ALI_M5451) {
769 1.3.4.2 thorpej endch = 32;
770 1.3.4.2 thorpej } else {
771 1.3.4.2 thorpej endch = 64;
772 1.3.4.2 thorpej }
773 1.3.4.2 thorpej
774 1.3.4.2 thorpej for (ch=0; ch<endch; ch++) {
775 1.3.4.2 thorpej mask = 1 << (ch & 0x1f);
776 1.3.4.2 thorpej if (active[(ch & 0x20) ? 1 : 0] & mask) {
777 1.3.4.2 thorpej
778 1.3.4.2 thorpej /* clear interupt */
779 1.3.4.2 thorpej TWRITE4(sc, (ch & 0x20) ? AUTRI_AIN_B : AUTRI_AIN_A, mask);
780 1.3.4.2 thorpej /* disable interupt */
781 1.3.4.2 thorpej autri_reg_clear_4(sc,(ch & 0x20) ? AUTRI_AINTEN_B : AUTRI_AINTEN_A, mask);
782 1.3.4.2 thorpej #if 0
783 1.3.4.2 thorpej reg = TREAD4(sc,AUTRI_LFO_GC_CIR) & ~0x0000003f;
784 1.3.4.2 thorpej TWRITE4(sc,AUTRI_LFO_GC_CIR, reg | ch);
785 1.3.4.2 thorpej
786 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_4DWAVE_NX) {
787 1.3.4.2 thorpej cso = TREAD4(sc, 0xe0) & 0x00ffffff;
788 1.3.4.2 thorpej eso = TREAD4(sc, 0xe8) & 0x00ffffff;
789 1.3.4.2 thorpej } else {
790 1.3.4.2 thorpej cso = (TREAD4(sc, 0xe0) >> 16) & 0x0000ffff;
791 1.3.4.2 thorpej eso = (TREAD4(sc, 0xe8) >> 16) & 0x0000ffff;
792 1.3.4.2 thorpej }
793 1.3.4.2 thorpej /*printf("cso=%d, eso=%d\n",cso,eso);*/
794 1.3.4.2 thorpej #endif
795 1.3.4.2 thorpej if (ch == sc->sc_play.ch_intr) {
796 1.3.4.2 thorpej if (sc->sc_play.intr)
797 1.3.4.2 thorpej sc->sc_play.intr(sc->sc_play.intr_arg);
798 1.3.4.2 thorpej }
799 1.3.4.2 thorpej
800 1.3.4.2 thorpej if (ch == sc->sc_rec.ch_intr) {
801 1.3.4.2 thorpej if (sc->sc_rec.intr)
802 1.3.4.2 thorpej sc->sc_rec.intr(sc->sc_rec.intr_arg);
803 1.3.4.2 thorpej }
804 1.3.4.2 thorpej
805 1.3.4.2 thorpej /* enable interrupt */
806 1.3.4.2 thorpej autri_reg_set_4(sc, (ch & 0x20) ? AUTRI_AINTEN_B : AUTRI_AINTEN_A, mask);
807 1.3.4.2 thorpej }
808 1.3.4.2 thorpej }
809 1.3.4.2 thorpej }
810 1.3.4.2 thorpej
811 1.3.4.2 thorpej if (intsrc & MPU401_IRQ) {
812 1.3.4.2 thorpej /* XXX */
813 1.3.4.2 thorpej }
814 1.3.4.2 thorpej
815 1.3.4.2 thorpej autri_reg_set_4(sc,AUTRI_MISCINT,
816 1.3.4.2 thorpej ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW);
817 1.3.4.2 thorpej
818 1.3.4.2 thorpej return 1;
819 1.3.4.2 thorpej }
820 1.3.4.2 thorpej
821 1.3.4.2 thorpej /*
822 1.3.4.2 thorpej *
823 1.3.4.2 thorpej */
824 1.3.4.2 thorpej
825 1.3.4.2 thorpej int
826 1.3.4.2 thorpej autri_allocmem(struct autri_softc *sc, size_t size, size_t align,
827 1.3.4.2 thorpej struct autri_dma *p)
828 1.3.4.2 thorpej {
829 1.3.4.2 thorpej int error;
830 1.3.4.2 thorpej
831 1.3.4.2 thorpej p->size = size;
832 1.3.4.2 thorpej error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
833 1.3.4.2 thorpej p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
834 1.3.4.2 thorpej &p->nsegs, BUS_DMA_NOWAIT);
835 1.3.4.2 thorpej if (error)
836 1.3.4.2 thorpej return (error);
837 1.3.4.2 thorpej
838 1.3.4.2 thorpej error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
839 1.3.4.2 thorpej &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
840 1.3.4.2 thorpej if (error)
841 1.3.4.2 thorpej goto free;
842 1.3.4.2 thorpej
843 1.3.4.2 thorpej error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
844 1.3.4.2 thorpej 0, BUS_DMA_NOWAIT, &p->map);
845 1.3.4.2 thorpej if (error)
846 1.3.4.2 thorpej goto unmap;
847 1.3.4.2 thorpej
848 1.3.4.2 thorpej error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
849 1.3.4.2 thorpej BUS_DMA_NOWAIT);
850 1.3.4.2 thorpej if (error)
851 1.3.4.2 thorpej goto destroy;
852 1.3.4.2 thorpej return (0);
853 1.3.4.2 thorpej
854 1.3.4.2 thorpej destroy:
855 1.3.4.2 thorpej bus_dmamap_destroy(sc->sc_dmatag, p->map);
856 1.3.4.2 thorpej unmap:
857 1.3.4.2 thorpej bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
858 1.3.4.2 thorpej free:
859 1.3.4.2 thorpej bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
860 1.3.4.2 thorpej return (error);
861 1.3.4.2 thorpej }
862 1.3.4.2 thorpej
863 1.3.4.2 thorpej int
864 1.3.4.2 thorpej autri_freemem(struct autri_softc *sc, struct autri_dma *p)
865 1.3.4.2 thorpej {
866 1.3.4.2 thorpej bus_dmamap_unload(sc->sc_dmatag, p->map);
867 1.3.4.2 thorpej bus_dmamap_destroy(sc->sc_dmatag, p->map);
868 1.3.4.2 thorpej bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
869 1.3.4.2 thorpej bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
870 1.3.4.2 thorpej return 0;
871 1.3.4.2 thorpej }
872 1.3.4.2 thorpej
873 1.3.4.2 thorpej int
874 1.3.4.2 thorpej autri_open(void *addr, int flags)
875 1.3.4.2 thorpej {
876 1.3.4.2 thorpej DPRINTF(("autri_open()\n"));
877 1.3.4.2 thorpej DPRINTFN(5,("MISCINT : 0x%08X\n",
878 1.3.4.2 thorpej TREAD4((struct autri_softc *)addr, AUTRI_MISCINT)));
879 1.3.4.2 thorpej DPRINTFN(5,("LFO_GC_CIR : 0x%08X\n",
880 1.3.4.2 thorpej TREAD4((struct autri_softc *)addr, AUTRI_LFO_GC_CIR)));
881 1.3.4.2 thorpej return 0;
882 1.3.4.2 thorpej }
883 1.3.4.2 thorpej
884 1.3.4.2 thorpej void
885 1.3.4.2 thorpej autri_close(void *addr)
886 1.3.4.2 thorpej {
887 1.3.4.2 thorpej DPRINTF(("autri_close()\n"));
888 1.3.4.2 thorpej }
889 1.3.4.2 thorpej
890 1.3.4.2 thorpej int
891 1.3.4.2 thorpej autri_query_encoding(void *addr, struct audio_encoding *fp)
892 1.3.4.2 thorpej {
893 1.3.4.2 thorpej switch (fp->index) {
894 1.3.4.2 thorpej case 0:
895 1.3.4.2 thorpej strcpy(fp->name, AudioEulinear);
896 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_ULINEAR;
897 1.3.4.2 thorpej fp->precision = 8;
898 1.3.4.2 thorpej fp->flags = 0;
899 1.3.4.2 thorpej break;
900 1.3.4.2 thorpej case 1:
901 1.3.4.2 thorpej strcpy(fp->name, AudioEmulaw);
902 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_ULAW;
903 1.3.4.2 thorpej fp->precision = 8;
904 1.3.4.2 thorpej fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
905 1.3.4.2 thorpej break;
906 1.3.4.2 thorpej case 2:
907 1.3.4.2 thorpej strcpy(fp->name, AudioEalaw);
908 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_ALAW;
909 1.3.4.2 thorpej fp->precision = 8;
910 1.3.4.2 thorpej fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
911 1.3.4.2 thorpej break;
912 1.3.4.2 thorpej case 3:
913 1.3.4.2 thorpej strcpy(fp->name, AudioEslinear);
914 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_SLINEAR;
915 1.3.4.2 thorpej fp->precision = 8;
916 1.3.4.2 thorpej fp->flags = 0;
917 1.3.4.2 thorpej break;
918 1.3.4.2 thorpej case 4:
919 1.3.4.2 thorpej strcpy(fp->name, AudioEslinear_le);
920 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
921 1.3.4.2 thorpej fp->precision = 16;
922 1.3.4.2 thorpej fp->flags = 0;
923 1.3.4.2 thorpej break;
924 1.3.4.2 thorpej case 5:
925 1.3.4.2 thorpej strcpy(fp->name, AudioEulinear_le);
926 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
927 1.3.4.2 thorpej fp->precision = 16;
928 1.3.4.2 thorpej fp->flags = 0;
929 1.3.4.2 thorpej break;
930 1.3.4.2 thorpej case 6:
931 1.3.4.2 thorpej strcpy(fp->name, AudioEslinear_be);
932 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
933 1.3.4.2 thorpej fp->precision = 16;
934 1.3.4.2 thorpej fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
935 1.3.4.2 thorpej break;
936 1.3.4.2 thorpej case 7:
937 1.3.4.2 thorpej strcpy(fp->name, AudioEulinear_be);
938 1.3.4.2 thorpej fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
939 1.3.4.2 thorpej fp->precision = 16;
940 1.3.4.2 thorpej fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
941 1.3.4.2 thorpej break;
942 1.3.4.2 thorpej default:
943 1.3.4.2 thorpej return (EINVAL);
944 1.3.4.2 thorpej }
945 1.3.4.2 thorpej
946 1.3.4.2 thorpej return 0;
947 1.3.4.2 thorpej }
948 1.3.4.2 thorpej
949 1.3.4.2 thorpej int
950 1.3.4.2 thorpej autri_set_params(void *addr, int setmode, int usemode,
951 1.3.4.2 thorpej struct audio_params *play, struct audio_params *rec)
952 1.3.4.2 thorpej {
953 1.3.4.2 thorpej struct audio_params *p;
954 1.3.4.2 thorpej int mode;
955 1.3.4.2 thorpej
956 1.3.4.2 thorpej for (mode = AUMODE_RECORD; mode != -1;
957 1.3.4.2 thorpej mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
958 1.3.4.2 thorpej if ((setmode & mode) == 0)
959 1.3.4.2 thorpej continue;
960 1.3.4.2 thorpej
961 1.3.4.2 thorpej p = mode == AUMODE_PLAY ? play : rec;
962 1.3.4.2 thorpej
963 1.3.4.2 thorpej if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
964 1.3.4.2 thorpej (p->precision != 8 && p->precision != 16) ||
965 1.3.4.2 thorpej (p->channels != 1 && p->channels != 2))
966 1.3.4.2 thorpej return (EINVAL);
967 1.3.4.2 thorpej
968 1.3.4.2 thorpej p->factor = 1;
969 1.3.4.2 thorpej p->sw_code = 0;
970 1.3.4.2 thorpej switch (p->encoding) {
971 1.3.4.2 thorpej case AUDIO_ENCODING_SLINEAR_BE:
972 1.3.4.2 thorpej case AUDIO_ENCODING_ULINEAR_BE:
973 1.3.4.2 thorpej if (p->precision == 16)
974 1.3.4.2 thorpej p->sw_code = swap_bytes;
975 1.3.4.2 thorpej break;
976 1.3.4.2 thorpej case AUDIO_ENCODING_SLINEAR_LE:
977 1.3.4.2 thorpej case AUDIO_ENCODING_ULINEAR_LE:
978 1.3.4.2 thorpej break;
979 1.3.4.2 thorpej case AUDIO_ENCODING_ULAW:
980 1.3.4.2 thorpej if (mode == AUMODE_PLAY)
981 1.3.4.2 thorpej p->sw_code = mulaw_to_ulinear8;
982 1.3.4.2 thorpej else
983 1.3.4.2 thorpej p->sw_code = ulinear8_to_mulaw;
984 1.3.4.2 thorpej
985 1.3.4.2 thorpej break;
986 1.3.4.2 thorpej case AUDIO_ENCODING_ALAW:
987 1.3.4.2 thorpej if (mode == AUMODE_PLAY)
988 1.3.4.2 thorpej p->sw_code = alaw_to_ulinear8;
989 1.3.4.2 thorpej else
990 1.3.4.2 thorpej p->sw_code = ulinear8_to_alaw;
991 1.3.4.2 thorpej
992 1.3.4.2 thorpej break;
993 1.3.4.2 thorpej default:
994 1.3.4.2 thorpej return (EINVAL);
995 1.3.4.2 thorpej }
996 1.3.4.2 thorpej }
997 1.3.4.2 thorpej
998 1.3.4.2 thorpej return 0;
999 1.3.4.2 thorpej }
1000 1.3.4.2 thorpej
1001 1.3.4.2 thorpej int
1002 1.3.4.2 thorpej autri_round_blocksize(void *addr, int block)
1003 1.3.4.2 thorpej {
1004 1.3.4.2 thorpej return (block & -4);
1005 1.3.4.2 thorpej }
1006 1.3.4.2 thorpej
1007 1.3.4.2 thorpej int
1008 1.3.4.2 thorpej autri_halt_output(void *addr)
1009 1.3.4.2 thorpej {
1010 1.3.4.2 thorpej struct autri_softc *sc = addr;
1011 1.3.4.2 thorpej
1012 1.3.4.2 thorpej DPRINTF(("autri_halt_output()\n"));
1013 1.3.4.2 thorpej
1014 1.3.4.2 thorpej sc->sc_play.intr = NULL;
1015 1.3.4.2 thorpej autri_stopch(sc, sc->sc_play.ch, sc->sc_play.ch_intr);
1016 1.3.4.2 thorpej autri_disable_interrupt(sc, sc->sc_play.ch_intr);
1017 1.3.4.2 thorpej
1018 1.3.4.2 thorpej return 0;
1019 1.3.4.2 thorpej }
1020 1.3.4.2 thorpej
1021 1.3.4.2 thorpej int
1022 1.3.4.2 thorpej autri_halt_input(void *addr)
1023 1.3.4.2 thorpej {
1024 1.3.4.2 thorpej struct autri_softc *sc = addr;
1025 1.3.4.2 thorpej
1026 1.3.4.2 thorpej DPRINTF(("autri_halt_input()\n"));
1027 1.3.4.2 thorpej
1028 1.3.4.2 thorpej sc->sc_rec.intr = NULL;
1029 1.3.4.2 thorpej autri_stopch(sc, sc->sc_rec.ch, sc->sc_rec.ch_intr);
1030 1.3.4.2 thorpej autri_disable_interrupt(sc, sc->sc_rec.ch_intr);
1031 1.3.4.2 thorpej
1032 1.3.4.2 thorpej return 0;
1033 1.3.4.2 thorpej }
1034 1.3.4.2 thorpej
1035 1.3.4.2 thorpej int
1036 1.3.4.2 thorpej autri_getdev(void *addr, struct audio_device *retp)
1037 1.3.4.2 thorpej {
1038 1.3.4.2 thorpej struct autri_softc *sc = addr;
1039 1.3.4.2 thorpej
1040 1.3.4.2 thorpej DPRINTF(("autri_getdev().\n"));
1041 1.3.4.2 thorpej
1042 1.3.4.2 thorpej strncpy(retp->name, "Trident 4DWAVE", sizeof(retp->name));
1043 1.3.4.2 thorpej snprintf(retp->version, sizeof(retp->version), "0x%02x",
1044 1.3.4.2 thorpej PCI_REVISION(sc->sc_class));
1045 1.3.4.2 thorpej
1046 1.3.4.2 thorpej switch (sc->sc_devid) {
1047 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
1048 1.3.4.2 thorpej strncpy(retp->config, "4DWAVE-DX", sizeof(retp->config));
1049 1.3.4.2 thorpej break;
1050 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
1051 1.3.4.2 thorpej strncpy(retp->config, "4DWAVE-NX", sizeof(retp->config));
1052 1.3.4.2 thorpej break;
1053 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
1054 1.3.4.2 thorpej strncpy(retp->config, "SiS 7018", sizeof(retp->config));
1055 1.3.4.2 thorpej break;
1056 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
1057 1.3.4.2 thorpej strncpy(retp->config, "ALi M5451", sizeof(retp->config));
1058 1.3.4.2 thorpej break;
1059 1.3.4.2 thorpej default:
1060 1.3.4.2 thorpej strncpy(retp->config, "unknown", sizeof(retp->config));
1061 1.3.4.2 thorpej }
1062 1.3.4.2 thorpej
1063 1.3.4.2 thorpej return 0;
1064 1.3.4.2 thorpej }
1065 1.3.4.2 thorpej
1066 1.3.4.2 thorpej int
1067 1.3.4.2 thorpej autri_mixer_set_port(void *addr, mixer_ctrl_t *cp)
1068 1.3.4.2 thorpej {
1069 1.3.4.2 thorpej struct autri_softc *sc = addr;
1070 1.3.4.2 thorpej
1071 1.3.4.2 thorpej return (sc->sc_codec.codec_if->vtbl->mixer_set_port(
1072 1.3.4.2 thorpej sc->sc_codec.codec_if, cp));
1073 1.3.4.2 thorpej }
1074 1.3.4.2 thorpej
1075 1.3.4.2 thorpej int
1076 1.3.4.2 thorpej autri_mixer_get_port(void *addr, mixer_ctrl_t *cp)
1077 1.3.4.2 thorpej {
1078 1.3.4.2 thorpej struct autri_softc *sc = addr;
1079 1.3.4.2 thorpej
1080 1.3.4.2 thorpej return (sc->sc_codec.codec_if->vtbl->mixer_get_port(
1081 1.3.4.2 thorpej sc->sc_codec.codec_if, cp));
1082 1.3.4.2 thorpej }
1083 1.3.4.2 thorpej
1084 1.3.4.2 thorpej int
1085 1.3.4.2 thorpej autri_query_devinfo(void *addr, mixer_devinfo_t *dip)
1086 1.3.4.2 thorpej {
1087 1.3.4.2 thorpej struct autri_softc *sc = addr;
1088 1.3.4.2 thorpej
1089 1.3.4.2 thorpej return (sc->sc_codec.codec_if->vtbl->query_devinfo(
1090 1.3.4.2 thorpej sc->sc_codec.codec_if, dip));
1091 1.3.4.2 thorpej }
1092 1.3.4.2 thorpej
1093 1.3.4.2 thorpej int
1094 1.3.4.2 thorpej autri_get_portnum_by_name(struct autri_softc *sc, char *class,
1095 1.3.4.2 thorpej char *device, char *qualifier)
1096 1.3.4.2 thorpej {
1097 1.3.4.2 thorpej return (sc->sc_codec.codec_if->vtbl->get_portnum_by_name(
1098 1.3.4.2 thorpej sc->sc_codec.codec_if, class, device, qualifier));
1099 1.3.4.2 thorpej }
1100 1.3.4.2 thorpej
1101 1.3.4.2 thorpej void *
1102 1.3.4.2 thorpej autri_malloc(void *addr, int direction, size_t size, int pool, int flags)
1103 1.3.4.2 thorpej {
1104 1.3.4.2 thorpej struct autri_softc *sc = addr;
1105 1.3.4.2 thorpej struct autri_dma *p;
1106 1.3.4.2 thorpej int error;
1107 1.3.4.2 thorpej
1108 1.3.4.2 thorpej p = malloc(sizeof(*p), pool, flags);
1109 1.3.4.2 thorpej if (!p)
1110 1.3.4.2 thorpej return NULL;
1111 1.3.4.2 thorpej
1112 1.3.4.2 thorpej #if 0
1113 1.3.4.2 thorpej error = autri_allocmem(sc, size, 16, p);
1114 1.3.4.2 thorpej #endif
1115 1.3.4.2 thorpej error = autri_allocmem(sc, size, 0x10000, p);
1116 1.3.4.2 thorpej if (error) {
1117 1.3.4.2 thorpej free(p, pool);
1118 1.3.4.2 thorpej return NULL;
1119 1.3.4.2 thorpej }
1120 1.3.4.2 thorpej
1121 1.3.4.2 thorpej p->next = sc->sc_dmas;
1122 1.3.4.2 thorpej sc->sc_dmas = p;
1123 1.3.4.2 thorpej return KERNADDR(p);
1124 1.3.4.2 thorpej }
1125 1.3.4.2 thorpej
1126 1.3.4.2 thorpej void
1127 1.3.4.2 thorpej autri_free(void *addr, void *ptr, int pool)
1128 1.3.4.2 thorpej {
1129 1.3.4.2 thorpej struct autri_softc *sc = addr;
1130 1.3.4.2 thorpej struct autri_dma **pp, *p;
1131 1.3.4.2 thorpej
1132 1.3.4.2 thorpej for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) {
1133 1.3.4.2 thorpej if (KERNADDR(p) == ptr) {
1134 1.3.4.2 thorpej autri_freemem(sc, p);
1135 1.3.4.2 thorpej *pp = p->next;
1136 1.3.4.2 thorpej free(p, pool);
1137 1.3.4.2 thorpej return;
1138 1.3.4.2 thorpej }
1139 1.3.4.2 thorpej }
1140 1.3.4.2 thorpej }
1141 1.3.4.2 thorpej
1142 1.3.4.2 thorpej static struct autri_dma *
1143 1.3.4.2 thorpej autri_find_dma(struct autri_softc *sc, void *addr)
1144 1.3.4.2 thorpej {
1145 1.3.4.2 thorpej struct autri_dma *p;
1146 1.3.4.2 thorpej
1147 1.3.4.2 thorpej for (p = sc->sc_dmas; p && KERNADDR(p) != addr; p = p->next)
1148 1.3.4.2 thorpej ;
1149 1.3.4.2 thorpej
1150 1.3.4.2 thorpej return p;
1151 1.3.4.2 thorpej }
1152 1.3.4.2 thorpej
1153 1.3.4.2 thorpej size_t
1154 1.3.4.2 thorpej autri_round_buffersize(void *addr, int direction, size_t size)
1155 1.3.4.2 thorpej {
1156 1.3.4.2 thorpej return size;
1157 1.3.4.2 thorpej }
1158 1.3.4.2 thorpej
1159 1.3.4.2 thorpej paddr_t
1160 1.3.4.2 thorpej autri_mappage(void *addr, void *mem, off_t off, int prot)
1161 1.3.4.2 thorpej {
1162 1.3.4.2 thorpej struct autri_softc *sc = addr;
1163 1.3.4.2 thorpej struct autri_dma *p;
1164 1.3.4.2 thorpej
1165 1.3.4.2 thorpej if (off < 0)
1166 1.3.4.2 thorpej return (-1);
1167 1.3.4.2 thorpej
1168 1.3.4.2 thorpej p = autri_find_dma(sc, mem);
1169 1.3.4.2 thorpej if (!p)
1170 1.3.4.2 thorpej return (-1);
1171 1.3.4.2 thorpej
1172 1.3.4.2 thorpej return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
1173 1.3.4.2 thorpej off, prot, BUS_DMA_WAITOK));
1174 1.3.4.2 thorpej }
1175 1.3.4.2 thorpej
1176 1.3.4.2 thorpej int
1177 1.3.4.2 thorpej autri_get_props(void *addr)
1178 1.3.4.2 thorpej {
1179 1.3.4.2 thorpej return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT |
1180 1.3.4.2 thorpej AUDIO_PROP_FULLDUPLEX);
1181 1.3.4.2 thorpej }
1182 1.3.4.2 thorpej
1183 1.3.4.2 thorpej static void
1184 1.3.4.2 thorpej autri_setup_channel(struct autri_softc *sc, int mode,
1185 1.3.4.2 thorpej struct audio_params *param)
1186 1.3.4.2 thorpej {
1187 1.3.4.2 thorpej int i, ch, channel;
1188 1.3.4.2 thorpej u_int32_t reg, cr[5];
1189 1.3.4.2 thorpej u_int32_t cso, eso;
1190 1.3.4.2 thorpej u_int32_t delta, dch[2], ctrl;
1191 1.3.4.2 thorpej u_int32_t alpha_fms, fm_vol, attribute;
1192 1.3.4.2 thorpej
1193 1.3.4.2 thorpej u_int32_t dmaaddr, dmalen;
1194 1.3.4.2 thorpej int factor, rvol, cvol;
1195 1.3.4.2 thorpej struct autri_chstatus *chst;
1196 1.3.4.2 thorpej
1197 1.3.4.2 thorpej ctrl = AUTRI_CTRL_LOOPMODE;
1198 1.3.4.2 thorpej switch (param->encoding) {
1199 1.3.4.2 thorpej case AUDIO_ENCODING_SLINEAR_BE:
1200 1.3.4.2 thorpej case AUDIO_ENCODING_SLINEAR_LE:
1201 1.3.4.2 thorpej ctrl |= AUTRI_CTRL_SIGNED;
1202 1.3.4.2 thorpej break;
1203 1.3.4.2 thorpej }
1204 1.3.4.2 thorpej
1205 1.3.4.2 thorpej factor = 0;
1206 1.3.4.2 thorpej if (param->precision == 16) {
1207 1.3.4.2 thorpej ctrl |= AUTRI_CTRL_16BIT;
1208 1.3.4.2 thorpej factor++;
1209 1.3.4.2 thorpej }
1210 1.3.4.2 thorpej
1211 1.3.4.2 thorpej if (param->channels == 2) {
1212 1.3.4.2 thorpej ctrl |= AUTRI_CTRL_STEREO;
1213 1.3.4.2 thorpej factor++;
1214 1.3.4.2 thorpej }
1215 1.3.4.2 thorpej
1216 1.3.4.2 thorpej delta = (u_int32_t)param->sample_rate;
1217 1.3.4.2 thorpej if (delta < 4000)
1218 1.3.4.2 thorpej delta = 4000;
1219 1.3.4.2 thorpej if (delta > 48000)
1220 1.3.4.2 thorpej delta = 48000;
1221 1.3.4.2 thorpej
1222 1.3.4.2 thorpej dch[1] = ((delta << 12) / 48000) & 0x0000ffff;
1223 1.3.4.2 thorpej if (mode == AUMODE_PLAY) {
1224 1.3.4.2 thorpej chst = &sc->sc_play;
1225 1.3.4.2 thorpej dch[0] = ((delta << 12) / 48000) & 0x0000ffff;
1226 1.3.4.4 jdolecek ctrl |= AUTRI_CTRL_WAVEVOL;
1227 1.3.4.2 thorpej } else {
1228 1.3.4.2 thorpej chst = &sc->sc_rec;
1229 1.3.4.2 thorpej dch[0] = ((48000 << 12) / delta) & 0x0000ffff;
1230 1.3.4.4 jdolecek if (sc->sc_devid == AUTRI_DEVICE_ID_SIS_7018)
1231 1.3.4.4 jdolecek ctrl |= AUTRI_CTRL_MUTEVOL_SIS;
1232 1.3.4.4 jdolecek else
1233 1.3.4.4 jdolecek ctrl |= AUTRI_CTRL_MUTEVOL;
1234 1.3.4.2 thorpej }
1235 1.3.4.2 thorpej
1236 1.3.4.2 thorpej dmaaddr = DMAADDR(chst->dma);
1237 1.3.4.2 thorpej cso = alpha_fms = 0;
1238 1.3.4.2 thorpej rvol = cvol = 0x7f;
1239 1.3.4.2 thorpej fm_vol = 0x0 | ((rvol & 0x7f) << 7) | (cvol & 0x7f);
1240 1.3.4.2 thorpej attribute = 0;
1241 1.3.4.2 thorpej
1242 1.3.4.2 thorpej for (ch=0; ch<2; ch++) {
1243 1.3.4.2 thorpej
1244 1.3.4.2 thorpej if (ch == 0)
1245 1.3.4.2 thorpej dmalen = (chst->length >> factor);
1246 1.3.4.2 thorpej else {
1247 1.3.4.2 thorpej /* channel for interrupt */
1248 1.3.4.2 thorpej dmalen = (chst->blksize >> factor);
1249 1.3.4.4 jdolecek if (sc->sc_devid == AUTRI_DEVICE_ID_SIS_7018)
1250 1.3.4.4 jdolecek ctrl |= AUTRI_CTRL_MUTEVOL_SIS;
1251 1.3.4.4 jdolecek else
1252 1.3.4.4 jdolecek ctrl |= AUTRI_CTRL_MUTEVOL;
1253 1.3.4.2 thorpej }
1254 1.3.4.2 thorpej
1255 1.3.4.2 thorpej eso = dmalen - 1;
1256 1.3.4.2 thorpej
1257 1.3.4.2 thorpej switch (sc->sc_devid) {
1258 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_DX:
1259 1.3.4.2 thorpej cr[0] = (cso << 16) | (alpha_fms & 0x0000ffff);
1260 1.3.4.2 thorpej cr[1] = dmaaddr;
1261 1.3.4.2 thorpej cr[2] = (eso << 16) | (dch[ch] & 0x0000ffff);
1262 1.3.4.2 thorpej cr[3] = fm_vol;
1263 1.3.4.2 thorpej cr[4] = ctrl;
1264 1.3.4.2 thorpej break;
1265 1.3.4.2 thorpej case AUTRI_DEVICE_ID_4DWAVE_NX:
1266 1.3.4.2 thorpej cr[0] = (dch[ch] << 24) | (cso & 0x00ffffff);
1267 1.3.4.2 thorpej cr[1] = dmaaddr;
1268 1.3.4.2 thorpej cr[2] = ((dch[ch] << 16) & 0xff000000) | (eso & 0x00ffffff);
1269 1.3.4.2 thorpej cr[3] = (alpha_fms << 16) | (fm_vol & 0x0000ffff);
1270 1.3.4.2 thorpej cr[4] = ctrl;
1271 1.3.4.2 thorpej break;
1272 1.3.4.2 thorpej case AUTRI_DEVICE_ID_SIS_7018:
1273 1.3.4.2 thorpej cr[0] = (cso << 16) | (alpha_fms & 0x0000ffff);
1274 1.3.4.2 thorpej cr[1] = dmaaddr;
1275 1.3.4.2 thorpej cr[2] = (eso << 16) | (dch[ch] & 0x0000ffff);
1276 1.3.4.2 thorpej cr[3] = (attribute << 16) | (fm_vol & 0x0000ffff);
1277 1.3.4.2 thorpej cr[4] = ctrl;
1278 1.3.4.2 thorpej break;
1279 1.3.4.2 thorpej case AUTRI_DEVICE_ID_ALI_M5451:
1280 1.3.4.2 thorpej cr[0] = (cso << 16) | (alpha_fms & 0x0000ffff);
1281 1.3.4.2 thorpej cr[1] = dmaaddr;
1282 1.3.4.2 thorpej cr[2] = (eso << 16) | (dch[ch] & 0x0000ffff);
1283 1.3.4.2 thorpej cr[3] = 0;
1284 1.3.4.2 thorpej cr[4] = ctrl;
1285 1.3.4.2 thorpej break;
1286 1.3.4.2 thorpej }
1287 1.3.4.2 thorpej
1288 1.3.4.2 thorpej /* write channel data */
1289 1.3.4.2 thorpej channel = (ch == 0) ? chst->ch : chst->ch_intr;
1290 1.3.4.2 thorpej
1291 1.3.4.2 thorpej reg = TREAD4(sc,AUTRI_LFO_GC_CIR) & ~0x0000003f;
1292 1.3.4.2 thorpej TWRITE4(sc,AUTRI_LFO_GC_CIR, reg | channel);
1293 1.3.4.2 thorpej
1294 1.3.4.2 thorpej for (i=0; i<5; i++) {
1295 1.3.4.2 thorpej TWRITE4(sc, AUTRI_ARAM_CR + i*sizeof(cr[0]), cr[i]);
1296 1.3.4.2 thorpej DPRINTFN(5,("cr[%d] : 0x%08X\n", i, cr[i]));
1297 1.3.4.2 thorpej }
1298 1.3.4.2 thorpej
1299 1.3.4.2 thorpej /* Bank A only */
1300 1.3.4.2 thorpej if (channel < 0x20) {
1301 1.3.4.2 thorpej TWRITE4(sc, AUTRI_EBUF1, AUTRI_EMOD_STILL);
1302 1.3.4.2 thorpej TWRITE4(sc, AUTRI_EBUF2, AUTRI_EMOD_STILL);
1303 1.3.4.2 thorpej }
1304 1.3.4.2 thorpej }
1305 1.3.4.2 thorpej
1306 1.3.4.2 thorpej }
1307 1.3.4.2 thorpej
1308 1.3.4.2 thorpej int
1309 1.3.4.2 thorpej autri_trigger_output(void *addr, void *start, void *end, int blksize,
1310 1.3.4.2 thorpej void (*intr)(void *), void *arg,
1311 1.3.4.2 thorpej struct audio_params *param)
1312 1.3.4.2 thorpej {
1313 1.3.4.2 thorpej struct autri_softc *sc = addr;
1314 1.3.4.2 thorpej struct autri_dma *p;
1315 1.3.4.2 thorpej
1316 1.3.4.2 thorpej DPRINTFN(5,("autri_trigger_output: sc=%p start=%p end=%p "
1317 1.3.4.2 thorpej "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
1318 1.3.4.2 thorpej
1319 1.3.4.2 thorpej sc->sc_play.intr = intr;
1320 1.3.4.2 thorpej sc->sc_play.intr_arg = arg;
1321 1.3.4.2 thorpej sc->sc_play.offset = 0;
1322 1.3.4.2 thorpej sc->sc_play.blksize = blksize;
1323 1.3.4.2 thorpej sc->sc_play.length = (char *)end - (char *)start;
1324 1.3.4.2 thorpej
1325 1.3.4.2 thorpej p = autri_find_dma(sc, start);
1326 1.3.4.2 thorpej if (!p) {
1327 1.3.4.2 thorpej printf("autri_trigger_output: bad addr %p\n", start);
1328 1.3.4.2 thorpej return (EINVAL);
1329 1.3.4.2 thorpej }
1330 1.3.4.2 thorpej
1331 1.3.4.2 thorpej sc->sc_play.dma = p;
1332 1.3.4.2 thorpej
1333 1.3.4.2 thorpej /* */
1334 1.3.4.2 thorpej autri_setup_channel(sc, AUMODE_PLAY, param);
1335 1.3.4.2 thorpej
1336 1.3.4.2 thorpej /* volume set to no attenuation */
1337 1.3.4.2 thorpej TWRITE4(sc, AUTRI_MUSICVOL_WAVEVOL, 0);
1338 1.3.4.2 thorpej
1339 1.3.4.2 thorpej /* enable interrupt */
1340 1.3.4.2 thorpej autri_enable_interrupt(sc, sc->sc_play.ch_intr);
1341 1.3.4.2 thorpej
1342 1.3.4.2 thorpej /* start channel */
1343 1.3.4.2 thorpej autri_startch(sc, sc->sc_play.ch, sc->sc_play.ch_intr);
1344 1.3.4.2 thorpej
1345 1.3.4.2 thorpej return 0;
1346 1.3.4.2 thorpej }
1347 1.3.4.2 thorpej
1348 1.3.4.2 thorpej int
1349 1.3.4.2 thorpej autri_trigger_input(void *addr, void *start, void *end, int blksize,
1350 1.3.4.2 thorpej void (*intr)(void *), void *arg,
1351 1.3.4.2 thorpej struct audio_params *param)
1352 1.3.4.2 thorpej {
1353 1.3.4.2 thorpej struct autri_softc *sc = addr;
1354 1.3.4.2 thorpej struct autri_dma *p;
1355 1.3.4.2 thorpej
1356 1.3.4.2 thorpej DPRINTFN(5,("autri_trigger_input: sc=%p start=%p end=%p "
1357 1.3.4.2 thorpej "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
1358 1.3.4.2 thorpej
1359 1.3.4.2 thorpej sc->sc_rec.intr = intr;
1360 1.3.4.2 thorpej sc->sc_rec.intr_arg = arg;
1361 1.3.4.2 thorpej sc->sc_rec.offset = 0;
1362 1.3.4.2 thorpej sc->sc_rec.blksize = blksize;
1363 1.3.4.2 thorpej sc->sc_rec.length = (char *)end - (char *)start;
1364 1.3.4.2 thorpej
1365 1.3.4.2 thorpej /* */
1366 1.3.4.2 thorpej p = autri_find_dma(sc, start);
1367 1.3.4.2 thorpej if (!p) {
1368 1.3.4.2 thorpej printf("autri_trigger_input: bad addr %p\n", start);
1369 1.3.4.2 thorpej return (EINVAL);
1370 1.3.4.2 thorpej }
1371 1.3.4.2 thorpej
1372 1.3.4.2 thorpej sc->sc_rec.dma = p;
1373 1.3.4.2 thorpej
1374 1.3.4.2 thorpej /* */
1375 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_4DWAVE_NX) {
1376 1.3.4.2 thorpej autri_reg_set_4(sc, AUTRI_NX_ACR0, AUTRI_NX_ACR0_PSB_CAPTURE);
1377 1.3.4.2 thorpej TWRITE1(sc, AUTRI_NX_RCI3, AUTRI_NX_RCI3_ENABLE | sc->sc_rec.ch);
1378 1.3.4.2 thorpej }
1379 1.3.4.2 thorpej
1380 1.3.4.2 thorpej #if 0
1381 1.3.4.2 thorpej /* 4DWAVE only allows capturing at a 48KHz rate */
1382 1.3.4.2 thorpej if (sc->sc_devid == AUTRI_DEVICE_ID_4DWAVE_DX ||
1383 1.3.4.2 thorpej sc->sc_devid == AUTRI_DEVICE_ID_4DWAVE_NX)
1384 1.3.4.2 thorpej param->sample_rate = 48000;
1385 1.3.4.2 thorpej #endif
1386 1.3.4.2 thorpej
1387 1.3.4.2 thorpej autri_setup_channel(sc, AUMODE_RECORD, param);
1388 1.3.4.2 thorpej
1389 1.3.4.2 thorpej /* enable interrupt */
1390 1.3.4.2 thorpej autri_enable_interrupt(sc, sc->sc_rec.ch_intr);
1391 1.3.4.2 thorpej
1392 1.3.4.2 thorpej /* start channel */
1393 1.3.4.2 thorpej autri_startch(sc, sc->sc_rec.ch, sc->sc_rec.ch_intr);
1394 1.3.4.2 thorpej
1395 1.3.4.2 thorpej return 0;
1396 1.3.4.2 thorpej }
1397 1.3.4.2 thorpej
1398 1.3.4.2 thorpej #if 0
1399 1.3.4.2 thorpej static int
1400 1.3.4.2 thorpej autri_halt(struct autri_softc *sc)
1401 1.3.4.2 thorpej {
1402 1.3.4.2 thorpej DPRINTF(("autri_halt().\n"));
1403 1.3.4.2 thorpej /*autri_stopch(sc);*/
1404 1.3.4.2 thorpej autri_disable_interrupt(sc, sc->sc_play.channel);
1405 1.3.4.2 thorpej autri_disable_interrupt(sc, sc->sc_rec.channel);
1406 1.3.4.2 thorpej return 0;
1407 1.3.4.2 thorpej }
1408 1.3.4.2 thorpej #endif
1409 1.3.4.2 thorpej
1410 1.3.4.2 thorpej static void
1411 1.3.4.2 thorpej autri_enable_interrupt(struct autri_softc *sc, int ch)
1412 1.3.4.2 thorpej {
1413 1.3.4.2 thorpej int reg;
1414 1.3.4.2 thorpej
1415 1.3.4.2 thorpej reg = (ch & 0x20) ? AUTRI_AINTEN_B : AUTRI_AINTEN_A;
1416 1.3.4.2 thorpej ch &= 0x1f;
1417 1.3.4.2 thorpej
1418 1.3.4.2 thorpej autri_reg_set_4(sc, reg, 1 << ch);
1419 1.3.4.2 thorpej }
1420 1.3.4.2 thorpej
1421 1.3.4.2 thorpej static void
1422 1.3.4.2 thorpej autri_disable_interrupt(struct autri_softc *sc, int ch)
1423 1.3.4.2 thorpej {
1424 1.3.4.2 thorpej int reg;
1425 1.3.4.2 thorpej
1426 1.3.4.2 thorpej reg = (ch & 0x20) ? AUTRI_AINTEN_B : AUTRI_AINTEN_A;
1427 1.3.4.2 thorpej ch &= 0x1f;
1428 1.3.4.2 thorpej
1429 1.3.4.2 thorpej autri_reg_clear_4(sc, reg, 1 << ch);
1430 1.3.4.2 thorpej }
1431 1.3.4.2 thorpej
1432 1.3.4.2 thorpej static void
1433 1.3.4.2 thorpej autri_startch(struct autri_softc *sc, int ch, int ch_intr)
1434 1.3.4.2 thorpej {
1435 1.3.4.2 thorpej int reg;
1436 1.3.4.2 thorpej u_int32_t chmask;
1437 1.3.4.2 thorpej
1438 1.3.4.2 thorpej reg = (ch & 0x20) ? AUTRI_START_B : AUTRI_START_A;
1439 1.3.4.2 thorpej ch &= 0x1f;
1440 1.3.4.2 thorpej chmask = (1 << ch) | (1 << ch_intr);
1441 1.3.4.2 thorpej
1442 1.3.4.2 thorpej autri_reg_set_4(sc, reg, chmask);
1443 1.3.4.2 thorpej }
1444 1.3.4.2 thorpej
1445 1.3.4.2 thorpej static void
1446 1.3.4.2 thorpej autri_stopch(struct autri_softc *sc, int ch, int ch_intr)
1447 1.3.4.2 thorpej {
1448 1.3.4.2 thorpej int reg;
1449 1.3.4.2 thorpej u_int32_t chmask;
1450 1.3.4.2 thorpej
1451 1.3.4.2 thorpej reg = (ch & 0x20) ? AUTRI_STOP_B : AUTRI_STOP_A;
1452 1.3.4.2 thorpej ch &= 0x1f;
1453 1.3.4.2 thorpej chmask = (1 << ch) | (1 << ch_intr);
1454 1.3.4.2 thorpej
1455 1.3.4.2 thorpej autri_reg_set_4(sc, reg, chmask);
1456 1.3.4.2 thorpej }
1457 1.3.4.2 thorpej
1458 1.3.4.2 thorpej #if NMIDI > 0
1459 1.3.4.2 thorpej int
1460 1.3.4.2 thorpej autri_midi_open(void *addr, int flags, void (*iintr)(void *, int),
1461 1.3.4.2 thorpej void (*ointr)(void *), void *arg)
1462 1.3.4.2 thorpej {
1463 1.3.4.2 thorpej struct autri_softc *sc = addr;
1464 1.3.4.2 thorpej
1465 1.3.4.2 thorpej DPRINTF(("autri_midi_open()\n"));
1466 1.3.4.2 thorpej
1467 1.3.4.2 thorpej DPRINTFN(5,("MPUR1 : 0x%02X\n",TREAD1(sc,AUTRI_MPUR1)));
1468 1.3.4.2 thorpej DPRINTFN(5,("MPUR2 : 0x%02X\n",TREAD1(sc,AUTRI_MPUR2)));
1469 1.3.4.2 thorpej
1470 1.3.4.2 thorpej sc->sc_iintr = iintr;
1471 1.3.4.2 thorpej sc->sc_ointr = ointr;
1472 1.3.4.2 thorpej sc->sc_arg = arg;
1473 1.3.4.2 thorpej
1474 1.3.4.2 thorpej if (flags & FREAD)
1475 1.3.4.2 thorpej autri_reg_clear_1(sc, AUTRI_MPUR2, AUTRI_MIDIIN_ENABLE_INTR);
1476 1.3.4.2 thorpej
1477 1.3.4.2 thorpej if (flags & FWRITE)
1478 1.3.4.2 thorpej autri_reg_set_1(sc, AUTRI_MPUR2, AUTRI_MIDIOUT_CONNECT);
1479 1.3.4.2 thorpej
1480 1.3.4.2 thorpej return (0);
1481 1.3.4.2 thorpej }
1482 1.3.4.2 thorpej
1483 1.3.4.2 thorpej void
1484 1.3.4.2 thorpej autri_midi_close(void *addr)
1485 1.3.4.2 thorpej {
1486 1.3.4.2 thorpej struct autri_softc *sc = addr;
1487 1.3.4.2 thorpej
1488 1.3.4.2 thorpej DPRINTF(("autri_midi_close()\n"));
1489 1.3.4.2 thorpej
1490 1.3.4.2 thorpej tsleep(sc, PWAIT, "autri", hz/10); /* give uart a chance to drain */
1491 1.3.4.2 thorpej
1492 1.3.4.2 thorpej sc->sc_iintr = NULL;
1493 1.3.4.2 thorpej sc->sc_ointr = NULL;
1494 1.3.4.2 thorpej }
1495 1.3.4.2 thorpej
1496 1.3.4.2 thorpej int
1497 1.3.4.2 thorpej autri_midi_output(void *addr, int d)
1498 1.3.4.2 thorpej {
1499 1.3.4.2 thorpej struct autri_softc *sc = addr;
1500 1.3.4.2 thorpej int x;
1501 1.3.4.2 thorpej
1502 1.3.4.2 thorpej for (x = 0; x != MIDI_BUSY_WAIT; x++) {
1503 1.3.4.2 thorpej if ((TREAD1(sc, AUTRI_MPUR1) & AUTRI_MIDIOUT_READY) == 0) {
1504 1.3.4.2 thorpej TWRITE1(sc, AUTRI_MPUR0, d);
1505 1.3.4.2 thorpej return (0);
1506 1.3.4.2 thorpej }
1507 1.3.4.2 thorpej delay(MIDI_BUSY_DELAY);
1508 1.3.4.2 thorpej }
1509 1.3.4.2 thorpej return (EIO);
1510 1.3.4.2 thorpej }
1511 1.3.4.2 thorpej
1512 1.3.4.2 thorpej void
1513 1.3.4.2 thorpej autri_midi_getinfo(void *addr, struct midi_info *mi)
1514 1.3.4.2 thorpej {
1515 1.3.4.2 thorpej mi->name = "4DWAVE MIDI UART";
1516 1.3.4.2 thorpej mi->props = MIDI_PROP_CAN_INPUT;
1517 1.3.4.2 thorpej }
1518 1.3.4.2 thorpej
1519 1.3.4.2 thorpej #endif
1520