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