audioamd.c revision 1.20 1 1.20 kent /* $NetBSD: audioamd.c,v 1.20 2005/01/15 15:19:51 kent Exp $ */
2 1.1 augustss /* NetBSD: am7930_sparc.c,v 1.44 1999/03/14 22:29:00 jonathan Exp */
3 1.1 augustss
4 1.1 augustss /*
5 1.1 augustss * Copyright (c) 1995 Rolf Grossmann
6 1.1 augustss * All rights reserved.
7 1.1 augustss *
8 1.1 augustss * Redistribution and use in source and binary forms, with or without
9 1.1 augustss * modification, are permitted provided that the following conditions
10 1.1 augustss * are met:
11 1.1 augustss * 1. Redistributions of source code must retain the above copyright
12 1.1 augustss * notice, this list of conditions and the following disclaimer.
13 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 augustss * notice, this list of conditions and the following disclaimer in the
15 1.1 augustss * documentation and/or other materials provided with the distribution.
16 1.1 augustss * 3. All advertising materials mentioning features or use of this software
17 1.1 augustss * must display the following acknowledgement:
18 1.1 augustss * This product includes software developed by Rolf Grossmann.
19 1.1 augustss * 4. The name of the author may not be used to endorse or promote products
20 1.1 augustss * derived from this software without specific prior written permission
21 1.1 augustss *
22 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 augustss * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 augustss * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 augustss * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 augustss * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 augustss * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 augustss * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 augustss * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 augustss * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 augustss * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 augustss */
33 1.17 lukem
34 1.17 lukem #include <sys/cdefs.h>
35 1.20 kent __KERNEL_RCSID(0, "$NetBSD: audioamd.c,v 1.20 2005/01/15 15:19:51 kent Exp $");
36 1.1 augustss
37 1.1 augustss #include "audio.h"
38 1.1 augustss #if NAUDIO > 0
39 1.1 augustss
40 1.1 augustss #include <sys/param.h>
41 1.1 augustss #include <sys/systm.h>
42 1.1 augustss #include <sys/errno.h>
43 1.1 augustss #include <sys/device.h>
44 1.1 augustss
45 1.1 augustss #include <machine/bus.h>
46 1.6 pk #include <machine/intr.h>
47 1.1 augustss #include <machine/autoconf.h>
48 1.1 augustss
49 1.1 augustss #include <sys/audioio.h>
50 1.1 augustss #include <dev/audio_if.h>
51 1.1 augustss
52 1.1 augustss #include <dev/ic/am7930reg.h>
53 1.1 augustss #include <dev/ic/am7930var.h>
54 1.3 mycroft #include <sparc/dev/audioamdvar.h>
55 1.1 augustss
56 1.1 augustss #define AUDIO_ROM_NAME "audio"
57 1.1 augustss
58 1.1 augustss #ifdef AUDIO_DEBUG
59 1.1 augustss #define DPRINTF(x) if (am7930debug) printf x
60 1.1 augustss #define DPRINTFN(n,x) if (am7930debug>(n)) printf x
61 1.1 augustss #else
62 1.1 augustss #define DPRINTF(x)
63 1.1 augustss #define DPRINTFN(n,x)
64 1.1 augustss #endif /* AUDIO_DEBUG */
65 1.1 augustss
66 1.1 augustss
67 1.1 augustss /* interrupt interfaces */
68 1.20 kent int am7930hwintr(void *);
69 1.1 augustss struct auio *auiop;
70 1.20 kent void am7930swintr(void *);
71 1.1 augustss
72 1.15 pk /* from amd7930intr.s: */
73 1.15 pk void amd7930_trap(void);
74 1.15 pk
75 1.1 augustss /*
76 1.20 kent * interrupt-handler status
77 1.1 augustss */
78 1.1 augustss struct am7930_intrhand {
79 1.20 kent int (*ih_fun)(void *);
80 1.1 augustss void *ih_arg;
81 1.1 augustss };
82 1.1 augustss
83 1.1 augustss struct audioamd_softc {
84 1.1 augustss struct am7930_softc sc_am7930; /* glue to MI code */
85 1.1 augustss
86 1.1 augustss bus_space_tag_t sc_bt; /* bus cookie */
87 1.1 augustss bus_space_handle_t sc_bh; /* device registers */
88 1.1 augustss
89 1.1 augustss struct am7930_intrhand sc_ih; /* interrupt vector (hw or sw) */
90 1.1 augustss void (*sc_rintr)(void*); /* input completion intr handler */
91 1.1 augustss void *sc_rarg; /* arg for sc_rintr() */
92 1.1 augustss void (*sc_pintr)(void*); /* output completion intr handler */
93 1.1 augustss void *sc_parg; /* arg for sc_pintr() */
94 1.1 augustss
95 1.1 augustss /* sc_au is special in that the hardware interrupt handler uses it */
96 1.1 augustss struct auio sc_au; /* recv and xmit buffers, etc */
97 1.1 augustss #define sc_intrcnt sc_au.au_intrcnt /* statistics */
98 1.14 pk void *sc_sicookie; /* softintr(9) cookie */
99 1.1 augustss };
100 1.1 augustss
101 1.20 kent void audioamd_mainbus_attach(struct device *, struct device *, void *);
102 1.20 kent int audioamd_mainbus_match(struct device *, struct cfdata *, void *);
103 1.20 kent void audioamd_obio_attach(struct device *, struct device *, void *);
104 1.20 kent int audioamd_obio_match(struct device *, struct cfdata *, void *);
105 1.20 kent void audioamd_sbus_attach(struct device *, struct device *, void *);
106 1.20 kent int audioamd_sbus_match(struct device *, struct cfdata *, void *);
107 1.20 kent void audioamd_attach(struct audioamd_softc *, int);
108 1.1 augustss
109 1.11 thorpej CFATTACH_DECL(audioamd_mainbus, sizeof(struct audioamd_softc),
110 1.12 thorpej audioamd_mainbus_match, audioamd_mainbus_attach, NULL, NULL);
111 1.1 augustss
112 1.13 jdc CFATTACH_DECL(audioamd_obio, sizeof(struct audioamd_softc),
113 1.13 jdc audioamd_obio_match, audioamd_obio_attach, NULL, NULL);
114 1.13 jdc
115 1.11 thorpej CFATTACH_DECL(audioamd_sbus, sizeof(struct audioamd_softc),
116 1.12 thorpej audioamd_sbus_match, audioamd_sbus_attach, NULL, NULL);
117 1.1 augustss
118 1.1 augustss /*
119 1.1 augustss * Define our interface into the am7930 MI driver.
120 1.1 augustss */
121 1.1 augustss
122 1.20 kent uint8_t audioamd_codec_iread(struct am7930_softc *, int);
123 1.20 kent uint16_t audioamd_codec_iread16(struct am7930_softc *, int);
124 1.20 kent uint8_t audioamd_codec_dread(struct audioamd_softc *, int);
125 1.20 kent void audioamd_codec_iwrite(struct am7930_softc *, int, uint8_t);
126 1.20 kent void audioamd_codec_iwrite16(struct am7930_softc *, int, uint16_t);
127 1.20 kent void audioamd_codec_dwrite(struct audioamd_softc *, int, uint8_t);
128 1.20 kent void audioamd_onopen(struct am7930_softc *);
129 1.20 kent void audioamd_onclose(struct am7930_softc *);
130 1.1 augustss
131 1.1 augustss struct am7930_glue audioamd_glue = {
132 1.1 augustss audioamd_codec_iread,
133 1.1 augustss audioamd_codec_iwrite,
134 1.1 augustss audioamd_codec_iread16,
135 1.1 augustss audioamd_codec_iwrite16,
136 1.1 augustss audioamd_onopen,
137 1.1 augustss audioamd_onclose,
138 1.1 augustss 0,
139 1.1 augustss 0,
140 1.1 augustss 0,
141 1.1 augustss };
142 1.1 augustss
143 1.1 augustss /*
144 1.1 augustss * Define our interface to the higher level audio driver.
145 1.1 augustss */
146 1.20 kent int audioamd_start_output(void *, void *, int, void (*)(void *), void *);
147 1.20 kent int audioamd_start_input(void *, void *, int, void (*)(void *), void *);
148 1.20 kent int audioamd_getdev(void *, struct audio_device *);
149 1.1 augustss
150 1.19 yamt const struct audio_hw_if sa_hw_if = {
151 1.1 augustss am7930_open,
152 1.1 augustss am7930_close,
153 1.1 augustss 0,
154 1.1 augustss am7930_query_encoding,
155 1.1 augustss am7930_set_params,
156 1.1 augustss am7930_round_blocksize,
157 1.1 augustss am7930_commit_settings,
158 1.1 augustss 0,
159 1.1 augustss 0,
160 1.1 augustss audioamd_start_output, /* md */
161 1.1 augustss audioamd_start_input, /* md */
162 1.1 augustss am7930_halt_output,
163 1.1 augustss am7930_halt_input,
164 1.1 augustss 0,
165 1.1 augustss audioamd_getdev,
166 1.1 augustss 0,
167 1.1 augustss am7930_set_port,
168 1.1 augustss am7930_get_port,
169 1.1 augustss am7930_query_devinfo,
170 1.1 augustss 0,
171 1.1 augustss 0,
172 1.1 augustss 0,
173 1.20 kent 0,
174 1.1 augustss am7930_get_props,
175 1.7 augustss 0,
176 1.7 augustss 0,
177 1.20 kent 0,
178 1.1 augustss };
179 1.1 augustss
180 1.1 augustss struct audio_device audioamd_device = {
181 1.1 augustss "am7930",
182 1.1 augustss "x",
183 1.1 augustss "audioamd"
184 1.1 augustss };
185 1.1 augustss
186 1.1 augustss
187 1.1 augustss int
188 1.20 kent audioamd_mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
189 1.1 augustss {
190 1.20 kent struct mainbus_attach_args *ma;
191 1.1 augustss
192 1.20 kent ma = aux;
193 1.1 augustss if (CPU_ISSUN4)
194 1.20 kent return 0;
195 1.20 kent return strcmp(AUDIO_ROM_NAME, ma->ma_name) == 0;
196 1.1 augustss }
197 1.1 augustss
198 1.1 augustss int
199 1.20 kent audioamd_obio_match(struct device *parent, struct cfdata *cf, void *aux)
200 1.13 jdc {
201 1.20 kent union obio_attach_args *uoba;
202 1.13 jdc
203 1.20 kent uoba = aux;
204 1.13 jdc if (uoba->uoba_isobio4 != 0)
205 1.20 kent return 0;
206 1.13 jdc
207 1.20 kent return strcmp("audio", uoba->uoba_sbus.sa_name) == 0;
208 1.13 jdc }
209 1.13 jdc
210 1.13 jdc int
211 1.20 kent audioamd_sbus_match(struct device *parent, struct cfdata *cf, void *aux)
212 1.1 augustss {
213 1.20 kent struct sbus_attach_args *sa;
214 1.1 augustss
215 1.20 kent sa = aux;
216 1.20 kent return strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0;
217 1.1 augustss }
218 1.1 augustss
219 1.1 augustss void
220 1.20 kent audioamd_mainbus_attach(struct device *parent, struct device *self, void *aux)
221 1.1 augustss {
222 1.20 kent struct mainbus_attach_args *ma;
223 1.20 kent struct audioamd_softc *sc;
224 1.1 augustss bus_space_handle_t bh;
225 1.1 augustss
226 1.20 kent ma = aux;
227 1.20 kent sc = (struct audioamd_softc *)self;
228 1.1 augustss sc->sc_bt = ma->ma_bustag;
229 1.1 augustss
230 1.8 pk if (bus_space_map(
231 1.1 augustss ma->ma_bustag,
232 1.1 augustss ma->ma_paddr,
233 1.2 mycroft AM7930_DREG_SIZE,
234 1.1 augustss BUS_SPACE_MAP_LINEAR,
235 1.1 augustss &bh) != 0) {
236 1.1 augustss printf("%s: cannot map registers\n", self->dv_xname);
237 1.1 augustss return;
238 1.1 augustss }
239 1.1 augustss sc->sc_bh = bh;
240 1.1 augustss audioamd_attach(sc, ma->ma_pri);
241 1.1 augustss }
242 1.1 augustss
243 1.13 jdc void
244 1.20 kent audioamd_obio_attach(struct device *parent, struct device *self, void *aux)
245 1.20 kent {
246 1.20 kent union obio_attach_args *uoba;
247 1.20 kent struct sbus_attach_args *sa;
248 1.20 kent struct audioamd_softc *sc;
249 1.13 jdc bus_space_handle_t bh;
250 1.13 jdc
251 1.20 kent uoba = aux;
252 1.20 kent sa = &uoba->uoba_sbus;
253 1.20 kent sc = (struct audioamd_softc *)self;
254 1.13 jdc sc->sc_bt = sa->sa_bustag;
255 1.13 jdc
256 1.13 jdc if (sbus_bus_map(sa->sa_bustag,
257 1.13 jdc sa->sa_slot, sa->sa_offset,
258 1.13 jdc AM7930_DREG_SIZE,
259 1.13 jdc 0, &bh) != 0) {
260 1.13 jdc printf("%s: cannot map registers\n", self->dv_xname);
261 1.13 jdc return;
262 1.13 jdc }
263 1.13 jdc sc->sc_bh = bh;
264 1.13 jdc audioamd_attach(sc, sa->sa_pri);
265 1.13 jdc }
266 1.1 augustss
267 1.1 augustss void
268 1.20 kent audioamd_sbus_attach(struct device *parent, struct device *self, void *aux)
269 1.1 augustss {
270 1.20 kent struct sbus_attach_args *sa;
271 1.20 kent struct audioamd_softc *sc;
272 1.1 augustss bus_space_handle_t bh;
273 1.1 augustss
274 1.20 kent sa = aux;
275 1.20 kent sc = (struct audioamd_softc *)self;
276 1.1 augustss sc->sc_bt = sa->sa_bustag;
277 1.1 augustss
278 1.8 pk if (sbus_bus_map(sa->sa_bustag,
279 1.8 pk sa->sa_slot, sa->sa_offset,
280 1.8 pk AM7930_DREG_SIZE,
281 1.8 pk 0, &bh) != 0) {
282 1.1 augustss printf("%s: cannot map registers\n", self->dv_xname);
283 1.1 augustss return;
284 1.1 augustss }
285 1.1 augustss sc->sc_bh = bh;
286 1.1 augustss audioamd_attach(sc, sa->sa_pri);
287 1.1 augustss }
288 1.1 augustss
289 1.1 augustss void
290 1.20 kent audioamd_attach(struct audioamd_softc *sc, int pri)
291 1.1 augustss {
292 1.1 augustss
293 1.1 augustss /*
294 1.1 augustss * Set up glue for MI code early; we use some of it here.
295 1.1 augustss */
296 1.2 mycroft sc->sc_am7930.sc_glue = &audioamd_glue;
297 1.1 augustss
298 1.2 mycroft am7930_init(&sc->sc_am7930, AUDIOAMD_POLL_MODE);
299 1.1 augustss
300 1.14 pk auiop = &sc->sc_au;
301 1.15 pk
302 1.15 pk /* Copy bus tag & handle for use by am7930_trap */
303 1.15 pk sc->sc_au.au_bt = sc->sc_bt;
304 1.15 pk sc->sc_au.au_bh = sc->sc_bh;
305 1.16 pk (void)bus_intr_establish2(sc->sc_bt, pri, IPL_AUDIO,
306 1.15 pk am7930hwintr, sc, amd7930_trap);
307 1.14 pk
308 1.14 pk sc->sc_sicookie = softintr_establish(IPL_SOFTAUDIO, am7930swintr, sc);
309 1.14 pk if (sc->sc_sicookie == NULL) {
310 1.14 pk printf("\n%s: cannot establish software interrupt\n",
311 1.14 pk sc->sc_am7930.sc_dev.dv_xname);
312 1.14 pk return;
313 1.14 pk }
314 1.14 pk
315 1.14 pk printf(" softpri %d\n", IPL_SOFTAUDIO);
316 1.14 pk
317 1.1 augustss
318 1.4 cgd evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
319 1.4 cgd sc->sc_am7930.sc_dev.dv_xname, "intr");
320 1.1 augustss
321 1.2 mycroft audio_attach_mi(&sa_hw_if, sc, &sc->sc_am7930.sc_dev);
322 1.1 augustss }
323 1.1 augustss
324 1.1 augustss
325 1.1 augustss void
326 1.20 kent audioamd_onopen(struct am7930_softc *sc)
327 1.1 augustss {
328 1.20 kent struct audioamd_softc *mdsc;
329 1.1 augustss
330 1.20 kent mdsc = (struct audioamd_softc *)sc;
331 1.1 augustss /* reset pdma state */
332 1.1 augustss mdsc->sc_rintr = 0;
333 1.1 augustss mdsc->sc_rarg = 0;
334 1.1 augustss mdsc->sc_pintr = 0;
335 1.1 augustss mdsc->sc_parg = 0;
336 1.1 augustss
337 1.1 augustss mdsc->sc_au.au_rdata = 0;
338 1.1 augustss mdsc->sc_au.au_pdata = 0;
339 1.1 augustss }
340 1.1 augustss
341 1.1 augustss
342 1.1 augustss void
343 1.20 kent audioamd_onclose(struct am7930_softc *sc)
344 1.1 augustss {
345 1.1 augustss /* On sparc, just do the chipset-level halt. */
346 1.1 augustss am7930_halt_input(sc);
347 1.1 augustss am7930_halt_output(sc);
348 1.1 augustss }
349 1.1 augustss
350 1.1 augustss int
351 1.20 kent audioamd_start_output(void *addr, void *p, int cc,
352 1.20 kent void (*intr)(void *), void *arg)
353 1.1 augustss {
354 1.20 kent struct audioamd_softc *sc;
355 1.1 augustss
356 1.1 augustss DPRINTFN(1, ("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
357 1.20 kent sc = addr;
358 1.18 mycroft audioamd_codec_iwrite(&sc->sc_am7930,
359 1.20 kent AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
360 1.18 mycroft DPRINTF(("sa_start_output: started intrs.\n"));
361 1.1 augustss sc->sc_pintr = intr;
362 1.1 augustss sc->sc_parg = arg;
363 1.1 augustss sc->sc_au.au_pdata = p;
364 1.1 augustss sc->sc_au.au_pend = (char *)p + cc - 1;
365 1.1 augustss return(0);
366 1.1 augustss }
367 1.1 augustss
368 1.1 augustss int
369 1.20 kent audioamd_start_input(void *addr, void *p, int cc,
370 1.20 kent void (*intr)(void *), void *arg)
371 1.1 augustss {
372 1.20 kent struct audioamd_softc *sc;
373 1.1 augustss
374 1.1 augustss DPRINTFN(1, ("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg));
375 1.20 kent sc = addr;
376 1.18 mycroft audioamd_codec_iwrite(&sc->sc_am7930,
377 1.20 kent AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
378 1.18 mycroft DPRINTF(("sa_start_input: started intrs.\n"));
379 1.1 augustss sc->sc_rintr = intr;
380 1.1 augustss sc->sc_rarg = arg;
381 1.1 augustss sc->sc_au.au_rdata = p;
382 1.1 augustss sc->sc_au.au_rend = (char *)p + cc -1;
383 1.1 augustss return(0);
384 1.1 augustss }
385 1.1 augustss
386 1.1 augustss
387 1.1 augustss /*
388 1.1 augustss * Pseudo-DMA support: either C or locore assember.
389 1.1 augustss */
390 1.1 augustss
391 1.1 augustss int
392 1.20 kent am7930hwintr(void *v)
393 1.1 augustss {
394 1.20 kent struct audioamd_softc *sc;
395 1.20 kent struct auio *au;
396 1.20 kent uint8_t *d, *e;
397 1.1 augustss int k;
398 1.1 augustss
399 1.20 kent sc = v;
400 1.20 kent au = &sc->sc_au;
401 1.1 augustss /* clear interrupt */
402 1.1 augustss k = audioamd_codec_dread(sc, AM7930_DREG_IR);
403 1.14 pk if ((k & (AM7930_IR_DTTHRSH|AM7930_IR_DRTHRSH|AM7930_IR_DSRI|
404 1.14 pk AM7930_IR_DERI|AM7930_IR_BBUFF)) == 0)
405 1.20 kent return 0;
406 1.1 augustss
407 1.1 augustss /* receive incoming data */
408 1.1 augustss d = au->au_rdata;
409 1.1 augustss e = au->au_rend;
410 1.1 augustss if (d && d <= e) {
411 1.1 augustss *d = audioamd_codec_dread(sc, AM7930_DREG_BBRB);
412 1.1 augustss au->au_rdata++;
413 1.1 augustss if (d == e) {
414 1.1 augustss DPRINTFN(1, ("am7930hwintr: swintr(r) requested"));
415 1.14 pk softintr_schedule(sc->sc_sicookie);
416 1.1 augustss }
417 1.1 augustss }
418 1.1 augustss
419 1.1 augustss /* send outgoing data */
420 1.1 augustss d = au->au_pdata;
421 1.1 augustss e = au->au_pend;
422 1.1 augustss if (d && d <= e) {
423 1.1 augustss audioamd_codec_dwrite(sc, AM7930_DREG_BBTB, *d);
424 1.1 augustss au->au_pdata++;
425 1.1 augustss if (d == e) {
426 1.1 augustss DPRINTFN(1, ("am7930hwintr: swintr(p) requested"));
427 1.14 pk softintr_schedule(sc->sc_sicookie);
428 1.1 augustss }
429 1.1 augustss }
430 1.1 augustss
431 1.9 gmcgarry au->au_intrcnt.ev_count++;
432 1.20 kent return 1;
433 1.1 augustss }
434 1.1 augustss
435 1.14 pk void
436 1.20 kent am7930swintr(void *sc0)
437 1.1 augustss {
438 1.20 kent struct audioamd_softc *sc;
439 1.1 augustss struct auio *au;
440 1.14 pk int s;
441 1.1 augustss
442 1.20 kent sc = sc0;
443 1.1 augustss DPRINTFN(1, ("audiointr: sc=%p\n", sc););
444 1.1 augustss
445 1.1 augustss au = &sc->sc_au;
446 1.1 augustss s = splaudio();
447 1.1 augustss if (au->au_rdata > au->au_rend && sc->sc_rintr != NULL) {
448 1.1 augustss splx(s);
449 1.1 augustss (*sc->sc_rintr)(sc->sc_rarg);
450 1.1 augustss s = splaudio();
451 1.1 augustss }
452 1.1 augustss if (au->au_pdata > au->au_pend && sc->sc_pintr != NULL) {
453 1.1 augustss splx(s);
454 1.1 augustss (*sc->sc_pintr)(sc->sc_parg);
455 1.1 augustss } else
456 1.1 augustss splx(s);
457 1.1 augustss }
458 1.1 augustss
459 1.1 augustss
460 1.1 augustss /* indirect write */
461 1.1 augustss void
462 1.20 kent audioamd_codec_iwrite(struct am7930_softc *sc, int reg, uint8_t val)
463 1.1 augustss {
464 1.20 kent struct audioamd_softc *mdsc;
465 1.2 mycroft
466 1.20 kent mdsc = (struct audioamd_softc *)sc;
467 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
468 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val);
469 1.1 augustss }
470 1.1 augustss
471 1.1 augustss void
472 1.20 kent audioamd_codec_iwrite16(struct am7930_softc *sc, int reg, uint16_t val)
473 1.1 augustss {
474 1.20 kent struct audioamd_softc *mdsc;
475 1.2 mycroft
476 1.20 kent mdsc = (struct audioamd_softc *)sc;
477 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
478 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val);
479 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val>>8);
480 1.1 augustss }
481 1.1 augustss
482 1.1 augustss
483 1.1 augustss /* indirect read */
484 1.20 kent uint8_t
485 1.20 kent audioamd_codec_iread(struct am7930_softc *sc, int reg)
486 1.1 augustss {
487 1.20 kent struct audioamd_softc *mdsc;
488 1.2 mycroft
489 1.20 kent mdsc = (struct audioamd_softc *)sc;
490 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
491 1.2 mycroft return (audioamd_codec_dread(mdsc, AM7930_DREG_DR));
492 1.1 augustss }
493 1.1 augustss
494 1.20 kent uint16_t
495 1.20 kent audioamd_codec_iread16(struct am7930_softc *sc, int reg)
496 1.1 augustss {
497 1.20 kent struct audioamd_softc *mdsc;
498 1.20 kent uint8_t lo, hi;
499 1.2 mycroft
500 1.20 kent mdsc = (struct audioamd_softc *)sc;
501 1.2 mycroft audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
502 1.2 mycroft lo = audioamd_codec_dread(mdsc, AM7930_DREG_DR);
503 1.2 mycroft hi = audioamd_codec_dread(mdsc, AM7930_DREG_DR);
504 1.20 kent return (hi << 8) | lo;
505 1.1 augustss }
506 1.1 augustss
507 1.1 augustss /* direct read */
508 1.20 kent uint8_t
509 1.20 kent audioamd_codec_dread(struct audioamd_softc *sc, int reg)
510 1.2 mycroft {
511 1.20 kent
512 1.20 kent return bus_space_read_1(sc->sc_bt, sc->sc_bh, reg);
513 1.2 mycroft }
514 1.2 mycroft
515 1.2 mycroft /* direct write */
516 1.2 mycroft void
517 1.20 kent audioamd_codec_dwrite(struct audioamd_softc *sc, int reg, uint8_t val)
518 1.1 augustss {
519 1.20 kent
520 1.2 mycroft bus_space_write_1(sc->sc_bt, sc->sc_bh, reg, val);
521 1.2 mycroft }
522 1.2 mycroft
523 1.2 mycroft int
524 1.20 kent audioamd_getdev(void *addr, struct audio_device *retp)
525 1.2 mycroft {
526 1.2 mycroft
527 1.2 mycroft *retp = audioamd_device;
528 1.20 kent return 0;
529 1.1 augustss }
530 1.1 augustss
531 1.1 augustss #endif /* NAUDIO > 0 */
532