yds.c revision 1.3.6.3 1 1.3.6.3 he /* $NetBSD: yds.c,v 1.3.6.3 2001/05/26 17:13:55 he Exp $ */
2 1.3.6.2 he
3 1.3.6.2 he /*
4 1.3.6.2 he * Copyright (c) 2000, 2001 Kazuki Sakamoto and Minoura Makoto.
5 1.3.6.2 he * All rights reserved.
6 1.3.6.2 he *
7 1.3.6.2 he * Redistribution and use in source and binary forms, with or without
8 1.3.6.2 he * modification, are permitted provided that the following conditions
9 1.3.6.2 he * are met:
10 1.3.6.2 he * 1. Redistributions of source code must retain the above copyright
11 1.3.6.2 he * notice, this list of conditions and the following disclaimer.
12 1.3.6.2 he * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.6.2 he * notice, this list of conditions and the following disclaimer in the
14 1.3.6.2 he * documentation and/or other materials provided with the distribution.
15 1.3.6.2 he *
16 1.3.6.2 he * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.3.6.2 he * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.3.6.2 he * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.3.6.2 he * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.3.6.2 he * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.3.6.2 he * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.3.6.2 he * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.3.6.2 he * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.3.6.2 he * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.3.6.2 he * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.3.6.2 he */
27 1.3.6.2 he
28 1.3.6.2 he /*
29 1.3.6.2 he * Yamaha YMF724[B-F]/740[B-C]/744/754
30 1.3.6.2 he *
31 1.3.6.2 he * Documentation links:
32 1.3.6.2 he * - ftp://ftp.alsa-project.org/pub/manuals/yamaha/
33 1.3.6.2 he * - ftp://ftp.alsa-project.org/pub/manuals/yamaha/pci/
34 1.3.6.2 he *
35 1.3.6.2 he * TODO:
36 1.3.6.2 he * - FM synth volume (difficult: mixed before ac97)
37 1.3.6.2 he * - Digital in/out (SPDIF) support
38 1.3.6.2 he * - Effect??
39 1.3.6.2 he */
40 1.3.6.2 he
41 1.3.6.2 he #include "mpu.h"
42 1.3.6.2 he
43 1.3.6.2 he #include <sys/param.h>
44 1.3.6.2 he #include <sys/systm.h>
45 1.3.6.2 he #include <sys/kernel.h>
46 1.3.6.2 he #include <sys/fcntl.h>
47 1.3.6.2 he #include <sys/malloc.h>
48 1.3.6.2 he #include <sys/device.h>
49 1.3.6.2 he #include <sys/proc.h>
50 1.3.6.2 he
51 1.3.6.2 he #include <dev/pci/pcidevs.h>
52 1.3.6.2 he #include <dev/pci/pcireg.h>
53 1.3.6.2 he #include <dev/pci/pcivar.h>
54 1.3.6.2 he
55 1.3.6.2 he #include <sys/audioio.h>
56 1.3.6.2 he #include <dev/audio_if.h>
57 1.3.6.2 he #include <dev/mulaw.h>
58 1.3.6.2 he #include <dev/auconv.h>
59 1.3.6.2 he #include <dev/ic/ac97reg.h>
60 1.3.6.2 he #include <dev/ic/ac97var.h>
61 1.3.6.2 he #include <dev/ic/mpuvar.h>
62 1.3.6.2 he
63 1.3.6.2 he #include <machine/bus.h>
64 1.3.6.2 he #include <machine/intr.h>
65 1.3.6.2 he
66 1.3.6.2 he #include <dev/microcode/yds/yds_hwmcode.h>
67 1.3.6.2 he #include <dev/pci/ydsreg.h>
68 1.3.6.2 he #include <dev/pci/ydsvar.h>
69 1.3.6.2 he
70 1.3.6.2 he /* Debug */
71 1.3.6.2 he #undef YDS_USE_REC_SLOT
72 1.3.6.2 he #define YDS_USE_P44
73 1.3.6.2 he
74 1.3.6.2 he #ifdef AUDIO_DEBUG
75 1.3.6.2 he # define DPRINTF(x) if (ydsdebug) printf x
76 1.3.6.2 he # define DPRINTFN(n,x) if (ydsdebug>(n)) printf x
77 1.3.6.2 he int ydsdebug = 0;
78 1.3.6.2 he #else
79 1.3.6.2 he # define DPRINTF(x)
80 1.3.6.2 he # define DPRINTFN(n,x)
81 1.3.6.2 he #endif
82 1.3.6.2 he #ifdef YDS_USE_REC_SLOT
83 1.3.6.2 he # define YDS_INPUT_SLOT 0 /* REC slot = ADC + loopbacks */
84 1.3.6.2 he #else
85 1.3.6.2 he # define YDS_INPUT_SLOT 1 /* ADC slot */
86 1.3.6.2 he #endif
87 1.3.6.2 he
88 1.3.6.2 he int yds_match __P((struct device *, struct cfdata *, void *));
89 1.3.6.2 he void yds_attach __P((struct device *, struct device *, void *));
90 1.3.6.2 he int yds_intr __P((void *));
91 1.3.6.2 he
92 1.3.6.2 he #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
93 1.3.6.2 he #define KERNADDR(p) ((void *)((p)->addr))
94 1.3.6.2 he
95 1.3.6.2 he int yds_allocmem __P((struct yds_softc *, size_t, size_t,
96 1.3.6.2 he struct yds_dma *));
97 1.3.6.2 he int yds_freemem __P((struct yds_softc *, struct yds_dma *));
98 1.3.6.2 he
99 1.3.6.2 he #ifndef AUDIO_DEBUG
100 1.3.6.2 he #define YWRITE1(sc, r, x) bus_space_write_1((sc)->memt, (sc)->memh, (r), (x))
101 1.3.6.2 he #define YWRITE2(sc, r, x) bus_space_write_2((sc)->memt, (sc)->memh, (r), (x))
102 1.3.6.2 he #define YWRITE4(sc, r, x) bus_space_write_4((sc)->memt, (sc)->memh, (r), (x))
103 1.3.6.2 he #define YREAD1(sc, r) bus_space_read_1((sc)->memt, (sc)->memh, (r))
104 1.3.6.2 he #define YREAD2(sc, r) bus_space_read_2((sc)->memt, (sc)->memh, (r))
105 1.3.6.2 he #define YREAD4(sc, r) bus_space_read_4((sc)->memt, (sc)->memh, (r))
106 1.3.6.2 he #else
107 1.3.6.2 he
108 1.3.6.2 he u_int16_t YREAD2(struct yds_softc *sc,bus_size_t r);
109 1.3.6.2 he u_int32_t YREAD4(struct yds_softc *sc,bus_size_t r);
110 1.3.6.2 he void YWRITE1(struct yds_softc *sc,bus_size_t r,u_int8_t x);
111 1.3.6.2 he void YWRITE2(struct yds_softc *sc,bus_size_t r,u_int16_t x);
112 1.3.6.2 he void YWRITE4(struct yds_softc *sc,bus_size_t r,u_int32_t x);
113 1.3.6.2 he
114 1.3.6.2 he u_int16_t YREAD2(struct yds_softc *sc,bus_size_t r)
115 1.3.6.2 he {
116 1.3.6.2 he DPRINTFN(5, (" YREAD2(0x%lX)\n",(unsigned long)r));
117 1.3.6.2 he return bus_space_read_2(sc->memt,sc->memh,r);
118 1.3.6.2 he }
119 1.3.6.2 he u_int32_t YREAD4(struct yds_softc *sc,bus_size_t r)
120 1.3.6.2 he {
121 1.3.6.2 he DPRINTFN(5, (" YREAD4(0x%lX)\n",(unsigned long)r));
122 1.3.6.2 he return bus_space_read_4(sc->memt,sc->memh,r);
123 1.3.6.2 he }
124 1.3.6.2 he void YWRITE1(struct yds_softc *sc,bus_size_t r,u_int8_t x)
125 1.3.6.2 he {
126 1.3.6.2 he DPRINTFN(5, (" YWRITE1(0x%lX,0x%lX)\n",(unsigned long)r,(unsigned long)x));
127 1.3.6.2 he bus_space_write_1(sc->memt,sc->memh,r,x);
128 1.3.6.2 he }
129 1.3.6.2 he void YWRITE2(struct yds_softc *sc,bus_size_t r,u_int16_t x)
130 1.3.6.2 he {
131 1.3.6.2 he DPRINTFN(5, (" YWRITE2(0x%lX,0x%lX)\n",(unsigned long)r,(unsigned long)x));
132 1.3.6.2 he bus_space_write_2(sc->memt,sc->memh,r,x);
133 1.3.6.2 he }
134 1.3.6.2 he void YWRITE4(struct yds_softc *sc,bus_size_t r,u_int32_t x)
135 1.3.6.2 he {
136 1.3.6.2 he DPRINTFN(5, (" YWRITE4(0x%lX,0x%lX)\n",(unsigned long)r,(unsigned long)x));
137 1.3.6.2 he bus_space_write_4(sc->memt,sc->memh,r,x);
138 1.3.6.2 he }
139 1.3.6.2 he #endif
140 1.3.6.2 he
141 1.3.6.2 he #define YWRITEREGION4(sc, r, x, c) \
142 1.3.6.2 he bus_space_write_region_4((sc)->memt, (sc)->memh, (r), (x), (c) / 4)
143 1.3.6.2 he
144 1.3.6.2 he struct cfattach yds_ca = {
145 1.3.6.2 he sizeof(struct yds_softc), yds_match, yds_attach
146 1.3.6.2 he };
147 1.3.6.2 he
148 1.3.6.2 he int yds_open __P((void *, int));
149 1.3.6.2 he void yds_close __P((void *));
150 1.3.6.2 he int yds_query_encoding __P((void *, struct audio_encoding *));
151 1.3.6.2 he int yds_set_params __P((void *, int, int,
152 1.3.6.2 he struct audio_params *, struct audio_params *));
153 1.3.6.2 he int yds_round_blocksize __P((void *, int));
154 1.3.6.2 he int yds_trigger_output __P((void *, void *, void *, int, void (*)(void *),
155 1.3.6.2 he void *, struct audio_params *));
156 1.3.6.2 he int yds_trigger_input __P((void *, void *, void *, int, void (*)(void *),
157 1.3.6.2 he void *, struct audio_params *));
158 1.3.6.2 he int yds_halt_output __P((void *));
159 1.3.6.2 he int yds_halt_input __P((void *));
160 1.3.6.2 he int yds_getdev __P((void *, struct audio_device *));
161 1.3.6.2 he int yds_mixer_set_port __P((void *, mixer_ctrl_t *));
162 1.3.6.2 he int yds_mixer_get_port __P((void *, mixer_ctrl_t *));
163 1.3.6.2 he void *yds_malloc __P((void *, int, size_t, int, int));
164 1.3.6.2 he void yds_free __P((void *, void *, int));
165 1.3.6.2 he size_t yds_round_buffersize __P((void *, int, size_t));
166 1.3.6.2 he paddr_t yds_mappage __P((void *, void *, off_t, int));
167 1.3.6.2 he int yds_get_props __P((void *));
168 1.3.6.2 he int yds_query_devinfo __P((void *addr, mixer_devinfo_t *dip));
169 1.3.6.2 he
170 1.3.6.2 he int yds_attach_codec __P((void *sc, struct ac97_codec_if *));
171 1.3.6.2 he int yds_read_codec __P((void *sc, u_int8_t a, u_int16_t *d));
172 1.3.6.2 he int yds_write_codec __P((void *sc, u_int8_t a, u_int16_t d));
173 1.3.6.2 he void yds_reset_codec __P((void *sc));
174 1.3.6.2 he int yds_get_portnum_by_name __P((struct yds_softc *, char *, char *,
175 1.3.6.2 he char *));
176 1.3.6.2 he
177 1.3.6.2 he static u_int yds_get_dstype __P((int));
178 1.3.6.2 he static int yds_download_mcode __P((struct yds_softc *));
179 1.3.6.2 he static int yds_allocate_slots __P((struct yds_softc *));
180 1.3.6.2 he static void yds_configure_legacy __P((struct device *arg));
181 1.3.6.2 he static void yds_enable_dsp __P((struct yds_softc *));
182 1.3.6.2 he static int yds_disable_dsp __P((struct yds_softc *));
183 1.3.6.2 he static int yds_ready_codec __P((struct yds_codec_softc *));
184 1.3.6.2 he static int yds_halt __P((struct yds_softc *));
185 1.3.6.2 he static u_int32_t yds_get_lpfq __P((u_int));
186 1.3.6.2 he static u_int32_t yds_get_lpfk __P((u_int));
187 1.3.6.2 he static struct yds_dma *yds_find_dma __P((struct yds_softc *, void *));
188 1.3.6.2 he
189 1.3.6.2 he #ifdef AUDIO_DEBUG
190 1.3.6.2 he static void yds_dump_play_slot __P((struct yds_softc *, int));
191 1.3.6.2 he #define YDS_DUMP_PLAY_SLOT(n,sc,bank) \
192 1.3.6.2 he if (ydsdebug > (n)) yds_dump_play_slot(sc, bank)
193 1.3.6.2 he #else
194 1.3.6.2 he #define YDS_DUMP_PLAY_SLOT(n,sc,bank)
195 1.3.6.2 he #endif /* AUDIO_DEBUG */
196 1.3.6.2 he
197 1.3.6.2 he static struct audio_hw_if yds_hw_if = {
198 1.3.6.2 he yds_open,
199 1.3.6.2 he yds_close,
200 1.3.6.2 he NULL,
201 1.3.6.2 he yds_query_encoding,
202 1.3.6.2 he yds_set_params,
203 1.3.6.2 he yds_round_blocksize,
204 1.3.6.2 he NULL,
205 1.3.6.2 he NULL,
206 1.3.6.2 he NULL,
207 1.3.6.2 he NULL,
208 1.3.6.2 he NULL,
209 1.3.6.2 he yds_halt_output,
210 1.3.6.2 he yds_halt_input,
211 1.3.6.2 he NULL,
212 1.3.6.2 he yds_getdev,
213 1.3.6.2 he NULL,
214 1.3.6.2 he yds_mixer_set_port,
215 1.3.6.2 he yds_mixer_get_port,
216 1.3.6.2 he yds_query_devinfo,
217 1.3.6.2 he yds_malloc,
218 1.3.6.2 he yds_free,
219 1.3.6.2 he yds_round_buffersize,
220 1.3.6.2 he yds_mappage,
221 1.3.6.2 he yds_get_props,
222 1.3.6.2 he yds_trigger_output,
223 1.3.6.2 he yds_trigger_input,
224 1.3.6.2 he };
225 1.3.6.2 he
226 1.3.6.2 he struct audio_device yds_device = {
227 1.3.6.2 he "Yamaha DS-1",
228 1.3.6.2 he "",
229 1.3.6.2 he "yds"
230 1.3.6.2 he };
231 1.3.6.2 he
232 1.3.6.2 he const static struct {
233 1.3.6.2 he u_int id;
234 1.3.6.2 he u_int flags;
235 1.3.6.2 he #define YDS_CAP_MCODE_1 0x0001
236 1.3.6.2 he #define YDS_CAP_MCODE_1E 0x0002
237 1.3.6.2 he #define YDS_CAP_LEGACY_SELECTABLE 0x0004
238 1.3.6.2 he #define YDS_CAP_LEGACY_FLEXIBLE 0x0008
239 1.3.6.2 he #define YDS_CAP_HAS_P44 0x0010
240 1.3.6.2 he } yds_chip_capabliity_list[] = {
241 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF724,
242 1.3.6.2 he YDS_CAP_MCODE_1|YDS_CAP_LEGACY_SELECTABLE },
243 1.3.6.2 he /* 740[C] has only 32 slots. But anyway we use only 2 */
244 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF740,
245 1.3.6.2 he YDS_CAP_MCODE_1|YDS_CAP_LEGACY_SELECTABLE }, /* XXX NOT TESTED */
246 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF740C,
247 1.3.6.2 he YDS_CAP_MCODE_1E|YDS_CAP_LEGACY_SELECTABLE },
248 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF724F,
249 1.3.6.2 he YDS_CAP_MCODE_1E|YDS_CAP_LEGACY_SELECTABLE },
250 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF744B,
251 1.3.6.2 he YDS_CAP_MCODE_1E|YDS_CAP_LEGACY_FLEXIBLE },
252 1.3.6.2 he { PCI_PRODUCT_YAMAHA_YMF754,
253 1.3.6.2 he YDS_CAP_MCODE_1E|YDS_CAP_LEGACY_FLEXIBLE|YDS_CAP_HAS_P44 },
254 1.3.6.2 he { 0, 0 }
255 1.3.6.2 he };
256 1.3.6.2 he #ifdef AUDIO_DEBUG
257 1.3.6.2 he #define YDS_CAP_BITS "\020\005P44\004LEGFLEX\003LEGSEL\002MCODE1E\001MCODE1"
258 1.3.6.2 he #endif
259 1.3.6.2 he
260 1.3.6.2 he #ifdef AUDIO_DEBUG
261 1.3.6.2 he static void
262 1.3.6.2 he yds_dump_play_slot(sc, bank)
263 1.3.6.2 he struct yds_softc *sc;
264 1.3.6.2 he int bank;
265 1.3.6.2 he {
266 1.3.6.2 he int i, j;
267 1.3.6.2 he u_int32_t *p;
268 1.3.6.2 he u_int32_t num;
269 1.3.6.2 he char *pa;
270 1.3.6.2 he
271 1.3.6.2 he for (i = 0; i < N_PLAY_SLOTS; i++) {
272 1.3.6.2 he printf("pbankp[%d] = %p,", i*2, sc->pbankp[i*2]);
273 1.3.6.2 he printf("pbankp[%d] = %p\n", i*2+1, sc->pbankp[i*2+1]);
274 1.3.6.2 he }
275 1.3.6.2 he
276 1.3.6.2 he pa = (char *)DMAADDR(&sc->sc_ctrldata) + sc->pbankoff;
277 1.3.6.2 he p = (u_int32_t *)sc->ptbl;
278 1.3.6.2 he printf("ptbl + 0: %d\n", *p++);
279 1.3.6.2 he for (i = 0; i < N_PLAY_SLOTS; i++) {
280 1.3.6.2 he printf("ptbl + %d: 0x%x, should be %p\n",
281 1.3.6.2 he i+1, *p,
282 1.3.6.2 he pa + i * sizeof(struct play_slot_ctrl_bank) *
283 1.3.6.2 he N_PLAY_SLOT_CTRL_BANK);
284 1.3.6.2 he p++;
285 1.3.6.2 he }
286 1.3.6.2 he
287 1.3.6.2 he num = *(u_int32_t*)sc->ptbl;
288 1.3.6.2 he printf("numofplay = %d\n", num);
289 1.3.6.2 he
290 1.3.6.2 he for (i = 0; i < num; i++) {
291 1.3.6.2 he p = (u_int32_t *)sc->pbankp[i*2];
292 1.3.6.2 he
293 1.3.6.2 he printf(" pbankp[%d], bank 0 : %p\n", i*2, p);
294 1.3.6.2 he for (j = 0;
295 1.3.6.2 he j < sizeof(struct play_slot_ctrl_bank) / sizeof(u_int32_t);
296 1.3.6.2 he j++) {
297 1.3.6.2 he printf(" 0x%02x: 0x%08x\n",
298 1.3.6.2 he (unsigned)(j * sizeof(u_int32_t)),
299 1.3.6.2 he (unsigned)*p++);
300 1.3.6.2 he }
301 1.3.6.2 he
302 1.3.6.2 he p = (u_int32_t *)sc->pbankp[i*2 + 1];
303 1.3.6.2 he printf(" pbankp[%d], bank 1 : %p\n", i*2 + 1, p);
304 1.3.6.2 he for (j = 0;
305 1.3.6.2 he j < sizeof(struct play_slot_ctrl_bank) / sizeof(u_int32_t);
306 1.3.6.2 he j++) {
307 1.3.6.2 he printf(" 0x%02x: 0x%08x\n",
308 1.3.6.2 he (unsigned)(j * sizeof(u_int32_t)),
309 1.3.6.2 he (unsigned)*p++);
310 1.3.6.2 he }
311 1.3.6.2 he }
312 1.3.6.2 he }
313 1.3.6.2 he #endif /* AUDIO_DEBUG */
314 1.3.6.2 he
315 1.3.6.2 he static u_int
316 1.3.6.2 he yds_get_dstype(id)
317 1.3.6.2 he int id;
318 1.3.6.2 he {
319 1.3.6.2 he int i;
320 1.3.6.2 he
321 1.3.6.2 he for (i = 0; yds_chip_capabliity_list[i].id; i++) {
322 1.3.6.2 he if (PCI_PRODUCT(id) == yds_chip_capabliity_list[i].id)
323 1.3.6.2 he return yds_chip_capabliity_list[i].flags;
324 1.3.6.2 he }
325 1.3.6.2 he
326 1.3.6.2 he return -1;
327 1.3.6.2 he }
328 1.3.6.2 he
329 1.3.6.2 he static int
330 1.3.6.2 he yds_download_mcode(sc)
331 1.3.6.2 he struct yds_softc *sc;
332 1.3.6.2 he {
333 1.3.6.2 he u_int ctrl;
334 1.3.6.2 he const u_int32_t *p;
335 1.3.6.2 he size_t size;
336 1.3.6.2 he int dstype;
337 1.3.6.2 he
338 1.3.6.2 he static struct {
339 1.3.6.2 he const u_int32_t *mcode;
340 1.3.6.2 he size_t size;
341 1.3.6.2 he } ctrls[] = {
342 1.3.6.2 he {yds_ds1_ctrl_mcode, sizeof(yds_ds1_ctrl_mcode)},
343 1.3.6.2 he {yds_ds1e_ctrl_mcode, sizeof(yds_ds1e_ctrl_mcode)},
344 1.3.6.2 he };
345 1.3.6.2 he
346 1.3.6.2 he if (sc->sc_flags & YDS_CAP_MCODE_1)
347 1.3.6.2 he dstype = YDS_DS_1;
348 1.3.6.2 he else if (sc->sc_flags & YDS_CAP_MCODE_1E)
349 1.3.6.2 he dstype = YDS_DS_1E;
350 1.3.6.2 he else
351 1.3.6.2 he return 1; /* unknown */
352 1.3.6.2 he
353 1.3.6.2 he if (yds_disable_dsp(sc))
354 1.3.6.2 he return 1;
355 1.3.6.2 he
356 1.3.6.2 he /* Software reset */
357 1.3.6.2 he YWRITE4(sc, YDS_MODE, YDS_MODE_RESET);
358 1.3.6.2 he YWRITE4(sc, YDS_MODE, 0);
359 1.3.6.2 he
360 1.3.6.2 he YWRITE4(sc, YDS_MAPOF_REC, 0);
361 1.3.6.2 he YWRITE4(sc, YDS_MAPOF_EFFECT, 0);
362 1.3.6.2 he YWRITE4(sc, YDS_PLAY_CTRLBASE, 0);
363 1.3.6.2 he YWRITE4(sc, YDS_REC_CTRLBASE, 0);
364 1.3.6.2 he YWRITE4(sc, YDS_EFFECT_CTRLBASE, 0);
365 1.3.6.2 he YWRITE4(sc, YDS_WORK_BASE, 0);
366 1.3.6.2 he
367 1.3.6.2 he ctrl = YREAD2(sc, YDS_GLOBAL_CONTROL);
368 1.3.6.2 he YWRITE2(sc, YDS_GLOBAL_CONTROL, ctrl & ~0x0007);
369 1.3.6.2 he
370 1.3.6.2 he /* Download DSP microcode. */
371 1.3.6.2 he p = yds_dsp_mcode;
372 1.3.6.2 he size = sizeof(yds_dsp_mcode);
373 1.3.6.2 he YWRITEREGION4(sc, YDS_DSP_INSTRAM, p, size);
374 1.3.6.2 he
375 1.3.6.2 he /* Download CONTROL microcode. */
376 1.3.6.2 he p = ctrls[dstype].mcode;
377 1.3.6.2 he size = ctrls[dstype].size;
378 1.3.6.2 he YWRITEREGION4(sc, YDS_CTRL_INSTRAM, p, size);
379 1.3.6.2 he
380 1.3.6.2 he yds_enable_dsp(sc);
381 1.3.6.2 he delay(10 * 1000); /* nessesary on my 724F (??) */
382 1.3.6.2 he
383 1.3.6.2 he return 0;
384 1.3.6.2 he }
385 1.3.6.2 he
386 1.3.6.2 he static int
387 1.3.6.2 he yds_allocate_slots(sc)
388 1.3.6.2 he struct yds_softc *sc;
389 1.3.6.2 he {
390 1.3.6.2 he size_t pcs, rcs, ecs, ws, memsize;
391 1.3.6.2 he void *mp;
392 1.3.6.2 he u_int32_t da; /* DMA address */
393 1.3.6.2 he char *va; /* KVA */
394 1.3.6.2 he off_t cb;
395 1.3.6.2 he int i;
396 1.3.6.2 he struct yds_dma *p;
397 1.3.6.2 he
398 1.3.6.2 he /* Alloc DSP Control Data */
399 1.3.6.2 he pcs = YREAD4(sc, YDS_PLAY_CTRLSIZE) * sizeof(u_int32_t);
400 1.3.6.2 he rcs = YREAD4(sc, YDS_REC_CTRLSIZE) * sizeof(u_int32_t);
401 1.3.6.2 he ecs = YREAD4(sc, YDS_EFFECT_CTRLSIZE) * sizeof(u_int32_t);
402 1.3.6.2 he ws = WORK_SIZE;
403 1.3.6.2 he YWRITE4(sc, YDS_WORK_SIZE, ws / sizeof(u_int32_t));
404 1.3.6.2 he
405 1.3.6.2 he DPRINTF(("play control size : %d\n", (unsigned int)pcs));
406 1.3.6.2 he DPRINTF(("rec control size : %d\n", (unsigned int)rcs));
407 1.3.6.2 he DPRINTF(("eff control size : %d\n", (unsigned int)ecs));
408 1.3.6.2 he DPRINTF(("work size : %d\n", (unsigned int)ws));
409 1.3.6.2 he #ifdef DIAGNOSTIC
410 1.3.6.2 he if (pcs != sizeof(struct play_slot_ctrl_bank)) {
411 1.3.6.2 he printf("%s: invalid play slot ctrldata %d != %d\n",
412 1.3.6.2 he sc->sc_dev.dv_xname, (unsigned int)pcs,
413 1.3.6.2 he (unsigned int)sizeof(struct play_slot_ctrl_bank));
414 1.3.6.2 he if (rcs != sizeof(struct rec_slot_ctrl_bank))
415 1.3.6.2 he printf("%s: invalid rec slot ctrldata %d != %d\n",
416 1.3.6.2 he sc->sc_dev.dv_xname, (unsigned int)rcs,
417 1.3.6.2 he (unsigned int)sizeof(struct rec_slot_ctrl_bank));
418 1.3.6.2 he }
419 1.3.6.2 he #endif
420 1.3.6.2 he
421 1.3.6.2 he memsize = N_PLAY_SLOTS*N_PLAY_SLOT_CTRL_BANK*pcs +
422 1.3.6.2 he N_REC_SLOT_CTRL*N_REC_SLOT_CTRL_BANK*rcs + ws;
423 1.3.6.2 he memsize += (N_PLAY_SLOTS+1)*sizeof(u_int32_t);
424 1.3.6.2 he
425 1.3.6.2 he p = &sc->sc_ctrldata;
426 1.3.6.2 he i = yds_allocmem(sc, memsize, 16, p);
427 1.3.6.2 he if (i) {
428 1.3.6.2 he printf("%s: couldn't alloc/map DSP DMA buffer, reason %d\n",
429 1.3.6.2 he sc->sc_dev.dv_xname, i);
430 1.3.6.2 he free(p, M_DEVBUF);
431 1.3.6.2 he return 1;
432 1.3.6.2 he }
433 1.3.6.2 he mp = KERNADDR(p);
434 1.3.6.2 he da = DMAADDR(p);
435 1.3.6.2 he
436 1.3.6.2 he DPRINTF(("mp:%p, DMA addr:%p\n",
437 1.3.6.2 he mp, (void *)sc->sc_ctrldata.map->dm_segs[0].ds_addr));
438 1.3.6.2 he
439 1.3.6.2 he bzero(mp, memsize);
440 1.3.6.2 he
441 1.3.6.2 he /* Work space */
442 1.3.6.2 he cb = 0;
443 1.3.6.2 he va = (u_int8_t *)mp;
444 1.3.6.2 he YWRITE4(sc, YDS_WORK_BASE, da + cb);
445 1.3.6.2 he cb += ws;
446 1.3.6.2 he
447 1.3.6.2 he /* Play control data table */
448 1.3.6.2 he sc->ptbl = (u_int32_t *)(va + cb);
449 1.3.6.2 he sc->ptbloff = cb;
450 1.3.6.2 he YWRITE4(sc, YDS_PLAY_CTRLBASE, da + cb);
451 1.3.6.2 he cb += (N_PLAY_SLOT_CTRL + 1) * sizeof(u_int32_t);
452 1.3.6.2 he
453 1.3.6.2 he /* Record slot control data */
454 1.3.6.2 he sc->rbank = (struct rec_slot_ctrl_bank *)(va + cb);
455 1.3.6.2 he YWRITE4(sc, YDS_REC_CTRLBASE, da + cb);
456 1.3.6.2 he sc->rbankoff = cb;
457 1.3.6.2 he cb += N_REC_SLOT_CTRL * N_REC_SLOT_CTRL_BANK * rcs;
458 1.3.6.2 he
459 1.3.6.2 he #if 0
460 1.3.6.2 he /* Effect slot control data -- unused */
461 1.3.6.2 he YWRITE4(sc, YDS_EFFECT_CTRLBASE, da + cb);
462 1.3.6.2 he cb += N_EFFECT_SLOT_CTRL * N_EFFECT_SLOT_CTRL_BANK * ecs;
463 1.3.6.2 he #endif
464 1.3.6.2 he
465 1.3.6.2 he /* Play slot control data */
466 1.3.6.2 he sc->pbankoff = cb;
467 1.3.6.2 he for (i=0; i < N_PLAY_SLOT_CTRL; i++) {
468 1.3.6.2 he sc->pbankp[i*2] = (struct play_slot_ctrl_bank *)(va + cb);
469 1.3.6.2 he *(sc->ptbl + i+1) = da + cb;
470 1.3.6.2 he cb += pcs;
471 1.3.6.2 he
472 1.3.6.2 he sc->pbankp[i*2+1] = (struct play_slot_ctrl_bank *)(va + cb);
473 1.3.6.2 he cb += pcs;
474 1.3.6.2 he }
475 1.3.6.2 he /* Sync play control data table */
476 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, p->map,
477 1.3.6.2 he sc->ptbloff, (N_PLAY_SLOT_CTRL+1) * sizeof(u_int32_t),
478 1.3.6.2 he BUS_DMASYNC_PREWRITE);
479 1.3.6.2 he
480 1.3.6.2 he return 0;
481 1.3.6.2 he }
482 1.3.6.2 he
483 1.3.6.2 he static void
484 1.3.6.2 he yds_enable_dsp(sc)
485 1.3.6.2 he struct yds_softc *sc;
486 1.3.6.2 he {
487 1.3.6.2 he YWRITE4(sc, YDS_CONFIG, YDS_DSP_SETUP);
488 1.3.6.2 he }
489 1.3.6.2 he
490 1.3.6.2 he static int
491 1.3.6.2 he yds_disable_dsp(sc)
492 1.3.6.2 he struct yds_softc *sc;
493 1.3.6.2 he {
494 1.3.6.2 he int to;
495 1.3.6.2 he u_int32_t data;
496 1.3.6.2 he
497 1.3.6.2 he data = YREAD4(sc, YDS_CONFIG);
498 1.3.6.2 he if (data)
499 1.3.6.2 he YWRITE4(sc, YDS_CONFIG, YDS_DSP_DISABLE);
500 1.3.6.2 he
501 1.3.6.2 he for (to = 0; to < YDS_WORK_TIMEOUT; to++) {
502 1.3.6.2 he if ((YREAD4(sc, YDS_STATUS) & YDS_STAT_WORK) == 0)
503 1.3.6.2 he return 0;
504 1.3.6.2 he delay(1);
505 1.3.6.2 he }
506 1.3.6.2 he
507 1.3.6.2 he return 1;
508 1.3.6.2 he }
509 1.3.6.2 he
510 1.3.6.2 he int
511 1.3.6.2 he yds_match(parent, match, aux)
512 1.3.6.2 he struct device *parent;
513 1.3.6.2 he struct cfdata *match;
514 1.3.6.2 he void *aux;
515 1.3.6.2 he {
516 1.3.6.2 he struct pci_attach_args *pa = (struct pci_attach_args *)aux;
517 1.3.6.2 he
518 1.3.6.2 he switch (PCI_VENDOR(pa->pa_id)) {
519 1.3.6.2 he case PCI_VENDOR_YAMAHA:
520 1.3.6.2 he switch (PCI_PRODUCT(pa->pa_id)) {
521 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF724:
522 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF740:
523 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF740C:
524 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF724F:
525 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF744B:
526 1.3.6.2 he case PCI_PRODUCT_YAMAHA_YMF754:
527 1.3.6.2 he return (1);
528 1.3.6.2 he }
529 1.3.6.2 he break;
530 1.3.6.2 he }
531 1.3.6.2 he
532 1.3.6.2 he return (0);
533 1.3.6.2 he }
534 1.3.6.2 he
535 1.3.6.2 he /*
536 1.3.6.2 he * This routine is called after all the ISA devices are configured,
537 1.3.6.2 he * to avoid conflict.
538 1.3.6.2 he */
539 1.3.6.2 he static void
540 1.3.6.2 he yds_configure_legacy (arg)
541 1.3.6.2 he struct device *arg;
542 1.3.6.2 he #define FLEXIBLE (sc->sc_flags & YDS_CAP_LEGACY_FLEXIBLE)
543 1.3.6.2 he #define SELECTABLE (sc->sc_flags & YDS_CAP_LEGACY_SELECTABLE)
544 1.3.6.2 he {
545 1.3.6.2 he struct yds_softc *sc = (struct yds_softc*) arg;
546 1.3.6.2 he pcireg_t reg;
547 1.3.6.2 he struct device *dev;
548 1.3.6.2 he int i;
549 1.3.6.2 he bus_addr_t opl_addrs[] = {0x388, 0x398, 0x3A0, 0x3A8};
550 1.3.6.2 he bus_addr_t mpu_addrs[] = {0x330, 0x300, 0x332, 0x334};
551 1.3.6.2 he
552 1.3.6.2 he if (!FLEXIBLE && !SELECTABLE)
553 1.3.6.2 he return;
554 1.3.6.2 he
555 1.3.6.2 he reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, YDS_PCI_LEGACY);
556 1.3.6.2 he reg &= ~0x8133c03f; /* these bits are out of interest */
557 1.3.6.2 he reg |= ((YDS_PCI_EX_LEGACY_IMOD) |
558 1.3.6.2 he (YDS_PCI_LEGACY_FMEN |
559 1.3.6.2 he YDS_PCI_LEGACY_MEN /*| YDS_PCI_LEGACY_MIEN*/));
560 1.3.6.2 he if (FLEXIBLE) {
561 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag, YDS_PCI_LEGACY, reg);
562 1.3.6.2 he delay(100*1000);
563 1.3.6.2 he }
564 1.3.6.2 he
565 1.3.6.2 he /* Look for OPL */
566 1.3.6.2 he dev = 0;
567 1.3.6.2 he for (i = 0; i < sizeof(opl_addrs) / sizeof(bus_addr_t); i++) {
568 1.3.6.2 he if (SELECTABLE) {
569 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
570 1.3.6.2 he YDS_PCI_LEGACY, reg | (i << (0+16)));
571 1.3.6.2 he delay(100*1000); /* wait 100ms */
572 1.3.6.2 he } else
573 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
574 1.3.6.2 he YDS_PCI_FM_BA, opl_addrs[i]);
575 1.3.6.2 he if (bus_space_map(sc->sc_opl_iot,
576 1.3.6.2 he opl_addrs[i], 4, 0, &sc->sc_opl_ioh) == 0) {
577 1.3.6.2 he struct audio_attach_args aa;
578 1.3.6.2 he
579 1.3.6.2 he aa.type = AUDIODEV_TYPE_OPL;
580 1.3.6.2 he aa.hwif = aa.hdl = NULL;
581 1.3.6.2 he dev = config_found(&sc->sc_dev, &aa, audioprint);
582 1.3.6.2 he if (dev == 0)
583 1.3.6.2 he bus_space_unmap(sc->sc_opl_iot,
584 1.3.6.2 he sc->sc_opl_ioh, 4);
585 1.3.6.2 he else {
586 1.3.6.2 he if (SELECTABLE)
587 1.3.6.2 he reg |= (i << (0+16));
588 1.3.6.2 he break;
589 1.3.6.2 he }
590 1.3.6.2 he }
591 1.3.6.2 he }
592 1.3.6.2 he if (dev == 0) {
593 1.3.6.2 he reg &= ~YDS_PCI_LEGACY_FMEN;
594 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
595 1.3.6.2 he YDS_PCI_LEGACY, reg);
596 1.3.6.2 he } else {
597 1.3.6.2 he /* Max. volume */
598 1.3.6.2 he YWRITE4(sc, YDS_LEGACY_OUT_VOLUME, 0x3fff3fff);
599 1.3.6.2 he YWRITE4(sc, YDS_LEGACY_REC_VOLUME, 0x3fff3fff);
600 1.3.6.2 he }
601 1.3.6.2 he
602 1.3.6.2 he /* Look for MPU */
603 1.3.6.2 he dev = 0;
604 1.3.6.2 he for (i = 0; i < sizeof(mpu_addrs) / sizeof(bus_addr_t); i++) {
605 1.3.6.2 he if (SELECTABLE)
606 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
607 1.3.6.2 he YDS_PCI_LEGACY, reg | (i << (4+16)));
608 1.3.6.2 he else
609 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
610 1.3.6.2 he YDS_PCI_MPU_BA, mpu_addrs[i]);
611 1.3.6.2 he if (bus_space_map(sc->sc_mpu_iot,
612 1.3.6.2 he mpu_addrs[i], 2, 0, &sc->sc_mpu_ioh) == 0) {
613 1.3.6.2 he struct audio_attach_args aa;
614 1.3.6.2 he
615 1.3.6.2 he aa.type = AUDIODEV_TYPE_MPU;
616 1.3.6.2 he aa.hwif = aa.hdl = NULL;
617 1.3.6.2 he dev = config_found(&sc->sc_dev, &aa, audioprint);
618 1.3.6.2 he if (dev == 0)
619 1.3.6.2 he bus_space_unmap(sc->sc_mpu_iot,
620 1.3.6.2 he sc->sc_mpu_ioh, 2);
621 1.3.6.2 he else {
622 1.3.6.2 he if (SELECTABLE)
623 1.3.6.2 he reg |= (i << (4+16));
624 1.3.6.2 he break;
625 1.3.6.2 he }
626 1.3.6.2 he }
627 1.3.6.2 he }
628 1.3.6.2 he if (dev == 0) {
629 1.3.6.2 he reg &= ~(YDS_PCI_LEGACY_MEN | YDS_PCI_LEGACY_MIEN);
630 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag, YDS_PCI_LEGACY, reg);
631 1.3.6.2 he }
632 1.3.6.2 he sc->sc_mpu = dev;
633 1.3.6.2 he }
634 1.3.6.2 he #undef FLEXIBLE
635 1.3.6.2 he #undef SELECTABLE
636 1.3.6.2 he
637 1.3.6.2 he void
638 1.3.6.2 he yds_attach(parent, self, aux)
639 1.3.6.2 he struct device *parent;
640 1.3.6.2 he struct device *self;
641 1.3.6.2 he void *aux;
642 1.3.6.2 he {
643 1.3.6.2 he struct yds_softc *sc = (struct yds_softc *)self;
644 1.3.6.2 he struct pci_attach_args *pa = (struct pci_attach_args *)aux;
645 1.3.6.2 he pci_chipset_tag_t pc = pa->pa_pc;
646 1.3.6.2 he char const *intrstr;
647 1.3.6.2 he pci_intr_handle_t ih;
648 1.3.6.2 he pcireg_t reg;
649 1.3.6.2 he struct yds_codec_softc *codec;
650 1.3.6.2 he char devinfo[256];
651 1.3.6.2 he mixer_ctrl_t ctl;
652 1.3.6.2 he int i, r, to;
653 1.3.6.2 he int revision;
654 1.3.6.2 he int ac97_id2;
655 1.3.6.2 he
656 1.3.6.2 he pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
657 1.3.6.2 he revision = PCI_REVISION(pa->pa_class);
658 1.3.6.2 he printf(": %s (rev. 0x%02x)\n", devinfo, revision);
659 1.3.6.2 he
660 1.3.6.2 he /* Map register to memory */
661 1.3.6.2 he if (pci_mapreg_map(pa, YDS_PCI_MBA, PCI_MAPREG_TYPE_MEM, 0,
662 1.3.6.2 he &sc->memt, &sc->memh, NULL, NULL)) {
663 1.3.6.2 he printf("%s: can't map memory space\n", sc->sc_dev.dv_xname);
664 1.3.6.2 he return;
665 1.3.6.2 he }
666 1.3.6.2 he
667 1.3.6.2 he /* Map and establish the interrupt. */
668 1.3.6.2 he if (pci_intr_map(pa, pa->pa_intrtag, pa->pa_intrpin,
669 1.3.6.2 he pa->pa_intrline, &ih)) {
670 1.3.6.2 he printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
671 1.3.6.2 he return;
672 1.3.6.2 he }
673 1.3.6.2 he intrstr = pci_intr_string(pc, ih);
674 1.3.6.2 he sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, yds_intr, sc);
675 1.3.6.2 he if (sc->sc_ih == NULL) {
676 1.3.6.2 he printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
677 1.3.6.2 he if (intrstr != NULL)
678 1.3.6.2 he printf(" at %s", intrstr);
679 1.3.6.2 he printf("\n");
680 1.3.6.2 he return;
681 1.3.6.2 he }
682 1.3.6.2 he printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
683 1.3.6.2 he
684 1.3.6.2 he sc->sc_dmatag = pa->pa_dmat;
685 1.3.6.2 he sc->sc_pc = pc;
686 1.3.6.2 he sc->sc_pcitag = pa->pa_tag;
687 1.3.6.2 he sc->sc_id = pa->pa_id;
688 1.3.6.2 he sc->sc_flags = yds_get_dstype(sc->sc_id);
689 1.3.6.2 he #ifdef AUDIO_DEBUG
690 1.3.6.2 he if (ydsdebug) {
691 1.3.6.2 he char bits[80];
692 1.3.6.2 he
693 1.3.6.2 he printf("%s: chip has %s\n", sc->sc_dev.dv_xname,
694 1.3.6.2 he bitmask_snprintf(sc->sc_flags, YDS_CAP_BITS, bits,
695 1.3.6.2 he sizeof(bits)));
696 1.3.6.2 he }
697 1.3.6.2 he #endif
698 1.3.6.2 he
699 1.3.6.2 he /* Disable legacy mode */
700 1.3.6.2 he reg = pci_conf_read(pc, pa->pa_tag, YDS_PCI_LEGACY);
701 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, YDS_PCI_LEGACY,
702 1.3.6.2 he reg & YDS_PCI_LEGACY_LAD);
703 1.3.6.2 he
704 1.3.6.2 he /* Enable the device. */
705 1.3.6.2 he reg = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
706 1.3.6.2 he reg |= (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
707 1.3.6.2 he PCI_COMMAND_MASTER_ENABLE);
708 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
709 1.3.6.2 he reg = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
710 1.3.6.2 he
711 1.3.6.2 he /* Mute all volumes */
712 1.3.6.2 he for (i = 0x80; i < 0xc0; i += 2)
713 1.3.6.2 he YWRITE2(sc, i, 0);
714 1.3.6.2 he
715 1.3.6.2 he /* Download microcode */
716 1.3.6.2 he if (yds_download_mcode(sc)) {
717 1.3.6.2 he printf("%s: download microcode failed\n", sc->sc_dev.dv_xname);
718 1.3.6.2 he return;
719 1.3.6.2 he }
720 1.3.6.2 he /* Allocate DMA buffers */
721 1.3.6.2 he if (yds_allocate_slots(sc)) {
722 1.3.6.2 he printf("%s: could not allocate slots\n", sc->sc_dev.dv_xname);
723 1.3.6.2 he return;
724 1.3.6.2 he }
725 1.3.6.2 he
726 1.3.6.2 he /* Warm reset */
727 1.3.6.2 he reg = pci_conf_read(pc, pa->pa_tag, YDS_PCI_DSCTRL);
728 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, YDS_PCI_DSCTRL, reg | YDS_DSCTRL_WRST);
729 1.3.6.2 he delay(50000);
730 1.3.6.2 he
731 1.3.6.2 he /*
732 1.3.6.2 he * Detect primary/secondary AC97
733 1.3.6.2 he * YMF754 Hardware Specification Rev 1.01 page 24
734 1.3.6.2 he */
735 1.3.6.2 he reg = pci_conf_read(pc, pa->pa_tag, YDS_PCI_DSCTRL);
736 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, YDS_PCI_DSCTRL, reg & ~YDS_DSCTRL_CRST);
737 1.3.6.2 he delay(400000); /* Needed for 740C. */
738 1.3.6.2 he
739 1.3.6.2 he /* Primary */
740 1.3.6.2 he for (to = 0; to < AC97_TIMEOUT; to++) {
741 1.3.6.2 he if ((YREAD2(sc, AC97_STAT_ADDR1) & AC97_BUSY) == 0)
742 1.3.6.2 he break;
743 1.3.6.2 he delay(1);
744 1.3.6.2 he }
745 1.3.6.2 he if (to == AC97_TIMEOUT) {
746 1.3.6.2 he printf("%s: no AC97 avaliable\n", sc->sc_dev.dv_xname);
747 1.3.6.2 he return;
748 1.3.6.2 he }
749 1.3.6.2 he
750 1.3.6.2 he /* Secondary */
751 1.3.6.2 he /* Secondary AC97 is used for 4ch audio. Currently unused. */
752 1.3.6.2 he ac97_id2 = -1;
753 1.3.6.2 he if ((YREAD2(sc, YDS_ACTIVITY) & YDS_ACTIVITY_DOCKA) == 0)
754 1.3.6.2 he goto detected;
755 1.3.6.2 he #if 0 /* reset secondary... */
756 1.3.6.2 he YWRITE2(sc, YDS_GPIO_OCTRL,
757 1.3.6.2 he YREAD2(sc, YDS_GPIO_OCTRL) & ~YDS_GPIO_GPO2);
758 1.3.6.2 he YWRITE2(sc, YDS_GPIO_FUNCE,
759 1.3.6.2 he (YREAD2(sc, YDS_GPIO_FUNCE)&(~YDS_GPIO_GPC2))|YDS_GPIO_GPE2);
760 1.3.6.2 he #endif
761 1.3.6.2 he for (to = 0; to < AC97_TIMEOUT; to++) {
762 1.3.6.2 he if ((YREAD2(sc, AC97_STAT_ADDR2) & AC97_BUSY) == 0)
763 1.3.6.2 he break;
764 1.3.6.2 he delay(1);
765 1.3.6.2 he }
766 1.3.6.2 he if (to < AC97_TIMEOUT) {
767 1.3.6.2 he /* detect id */
768 1.3.6.2 he for (ac97_id2 = 1; ac97_id2 < 4; ac97_id2++) {
769 1.3.6.2 he YWRITE2(sc, AC97_CMD_ADDR,
770 1.3.6.2 he AC97_CMD_READ | AC97_ID(ac97_id2) | 0x28);
771 1.3.6.2 he
772 1.3.6.2 he for (to = 0; to < AC97_TIMEOUT; to++) {
773 1.3.6.2 he if ((YREAD2(sc, AC97_STAT_ADDR2) & AC97_BUSY)
774 1.3.6.2 he == 0)
775 1.3.6.2 he goto detected;
776 1.3.6.2 he delay(1);
777 1.3.6.2 he }
778 1.3.6.2 he }
779 1.3.6.2 he if (ac97_id2 == 4)
780 1.3.6.2 he ac97_id2 = -1;
781 1.3.6.2 he detected:
782 1.3.6.2 he }
783 1.3.6.2 he
784 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, YDS_PCI_DSCTRL, reg | YDS_DSCTRL_CRST);
785 1.3.6.2 he delay (20);
786 1.3.6.2 he pci_conf_write(pc, pa->pa_tag, YDS_PCI_DSCTRL, reg & ~YDS_DSCTRL_CRST);
787 1.3.6.2 he delay (400000);
788 1.3.6.2 he for (to = 0; to < AC97_TIMEOUT; to++) {
789 1.3.6.2 he if ((YREAD2(sc, AC97_STAT_ADDR1) & AC97_BUSY) == 0)
790 1.3.6.2 he break;
791 1.3.6.2 he delay(1);
792 1.3.6.2 he }
793 1.3.6.2 he
794 1.3.6.2 he /*
795 1.3.6.2 he * Attach ac97 codec
796 1.3.6.2 he */
797 1.3.6.2 he for (i = 0; i < 2; i++) {
798 1.3.6.2 he static struct {
799 1.3.6.2 he int data;
800 1.3.6.2 he int addr;
801 1.3.6.2 he } statregs[] = {
802 1.3.6.2 he {AC97_STAT_DATA1, AC97_STAT_ADDR1},
803 1.3.6.2 he {AC97_STAT_DATA2, AC97_STAT_ADDR2},
804 1.3.6.2 he };
805 1.3.6.2 he
806 1.3.6.2 he if (i == 1 && ac97_id2 == -1)
807 1.3.6.2 he break; /* secondary ac97 not available */
808 1.3.6.2 he
809 1.3.6.2 he codec = &sc->sc_codec[i];
810 1.3.6.2 he memcpy(&codec->sc_dev, &sc->sc_dev, sizeof(codec->sc_dev));
811 1.3.6.2 he codec->sc = sc;
812 1.3.6.2 he codec->id = i == 1 ? ac97_id2 : 0;
813 1.3.6.2 he codec->status_data = statregs[i].data;
814 1.3.6.2 he codec->status_addr = statregs[i].addr;
815 1.3.6.2 he codec->host_if.arg = codec;
816 1.3.6.2 he codec->host_if.attach = yds_attach_codec;
817 1.3.6.2 he codec->host_if.read = yds_read_codec;
818 1.3.6.2 he codec->host_if.write = yds_write_codec;
819 1.3.6.2 he codec->host_if.reset = yds_reset_codec;
820 1.3.6.2 he
821 1.3.6.2 he if ((r = ac97_attach(&codec->host_if)) != 0) {
822 1.3.6.2 he printf("%s: can't attach codec (error 0x%X)\n",
823 1.3.6.2 he sc->sc_dev.dv_xname, r);
824 1.3.6.2 he return;
825 1.3.6.2 he }
826 1.3.6.2 he }
827 1.3.6.2 he
828 1.3.6.2 he /* Just enable the DAC and master volumes by default */
829 1.3.6.2 he ctl.type = AUDIO_MIXER_ENUM;
830 1.3.6.2 he ctl.un.ord = 0; /* off */
831 1.3.6.2 he ctl.dev = yds_get_portnum_by_name(sc, AudioCoutputs,
832 1.3.6.2 he AudioNmaster, AudioNmute);
833 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
834 1.3.6.2 he ctl.dev = yds_get_portnum_by_name(sc, AudioCinputs,
835 1.3.6.2 he AudioNdac, AudioNmute);
836 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
837 1.3.6.2 he ctl.dev = yds_get_portnum_by_name(sc, AudioCinputs,
838 1.3.6.2 he AudioNcd, AudioNmute);
839 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
840 1.3.6.2 he ctl.dev = yds_get_portnum_by_name(sc, AudioCrecord,
841 1.3.6.2 he AudioNvolume, AudioNmute);
842 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
843 1.3.6.2 he
844 1.3.6.2 he ctl.dev = yds_get_portnum_by_name(sc, AudioCrecord,
845 1.3.6.2 he AudioNsource, NULL);
846 1.3.6.2 he ctl.type = AUDIO_MIXER_ENUM;
847 1.3.6.2 he ctl.un.ord = 0;
848 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
849 1.3.6.2 he
850 1.3.6.2 he /* Set a reasonable default volume */
851 1.3.6.2 he ctl.type = AUDIO_MIXER_VALUE;
852 1.3.6.2 he ctl.un.value.num_channels = 2;
853 1.3.6.2 he ctl.un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
854 1.3.6.2 he ctl.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 127;
855 1.3.6.2 he
856 1.3.6.2 he ctl.dev = sc->sc_codec[0].codec_if->vtbl->get_portnum_by_name(
857 1.3.6.2 he sc->sc_codec[0].codec_if, AudioCoutputs, AudioNmaster, NULL);
858 1.3.6.2 he yds_mixer_set_port(sc, &ctl);
859 1.3.6.2 he
860 1.3.6.2 he audio_attach_mi(&yds_hw_if, sc, &sc->sc_dev);
861 1.3.6.2 he
862 1.3.6.2 he sc->sc_legacy_iot = pa->pa_iot;
863 1.3.6.2 he config_defer((struct device*) sc, yds_configure_legacy);
864 1.3.6.2 he }
865 1.3.6.2 he
866 1.3.6.2 he int
867 1.3.6.2 he yds_attach_codec(sc_, codec_if)
868 1.3.6.2 he void *sc_;
869 1.3.6.2 he struct ac97_codec_if *codec_if;
870 1.3.6.2 he {
871 1.3.6.2 he struct yds_codec_softc *sc = sc_;
872 1.3.6.2 he
873 1.3.6.2 he sc->codec_if = codec_if;
874 1.3.6.2 he return 0;
875 1.3.6.2 he }
876 1.3.6.2 he
877 1.3.6.2 he static int
878 1.3.6.2 he yds_ready_codec(sc)
879 1.3.6.2 he struct yds_codec_softc *sc;
880 1.3.6.2 he {
881 1.3.6.2 he int to;
882 1.3.6.2 he
883 1.3.6.2 he for (to = 0; to < AC97_TIMEOUT; to++) {
884 1.3.6.2 he if ((YREAD2(sc->sc, sc->status_addr) & AC97_BUSY) == 0)
885 1.3.6.2 he return 0;
886 1.3.6.2 he delay(1);
887 1.3.6.2 he }
888 1.3.6.2 he
889 1.3.6.2 he return 1;
890 1.3.6.2 he }
891 1.3.6.2 he
892 1.3.6.2 he int
893 1.3.6.2 he yds_read_codec(sc_, reg, data)
894 1.3.6.2 he void *sc_;
895 1.3.6.2 he u_int8_t reg;
896 1.3.6.2 he u_int16_t *data;
897 1.3.6.2 he {
898 1.3.6.2 he struct yds_codec_softc *sc = sc_;
899 1.3.6.2 he
900 1.3.6.2 he YWRITE2(sc->sc, AC97_CMD_ADDR, AC97_CMD_READ | AC97_ID(sc->id) | reg);
901 1.3.6.2 he
902 1.3.6.2 he if (yds_ready_codec(sc)) {
903 1.3.6.2 he printf("%s: yds_read_codec timeout\n",
904 1.3.6.2 he sc->sc->sc_dev.dv_xname);
905 1.3.6.2 he return EIO;
906 1.3.6.2 he }
907 1.3.6.2 he
908 1.3.6.2 he *data = YREAD2(sc->sc, sc->status_data);
909 1.3.6.2 he
910 1.3.6.2 he return 0;
911 1.3.6.2 he }
912 1.3.6.2 he
913 1.3.6.2 he int
914 1.3.6.2 he yds_write_codec(sc_, reg, data)
915 1.3.6.2 he void *sc_;
916 1.3.6.2 he u_int8_t reg;
917 1.3.6.2 he u_int16_t data;
918 1.3.6.2 he {
919 1.3.6.2 he struct yds_codec_softc *sc = sc_;
920 1.3.6.2 he
921 1.3.6.2 he YWRITE2(sc->sc, AC97_CMD_ADDR, AC97_CMD_WRITE | AC97_ID(sc->id) | reg);
922 1.3.6.2 he YWRITE2(sc->sc, AC97_CMD_DATA, data);
923 1.3.6.2 he
924 1.3.6.2 he if (yds_ready_codec(sc)) {
925 1.3.6.2 he printf("%s: yds_write_codec timeout\n",
926 1.3.6.2 he sc->sc->sc_dev.dv_xname);
927 1.3.6.2 he return EIO;
928 1.3.6.2 he }
929 1.3.6.2 he
930 1.3.6.2 he return 0;
931 1.3.6.2 he }
932 1.3.6.2 he
933 1.3.6.2 he /*
934 1.3.6.2 he * XXX: Must handle the secondary differntly!!
935 1.3.6.2 he */
936 1.3.6.2 he void
937 1.3.6.2 he yds_reset_codec(sc_)
938 1.3.6.2 he void *sc_;
939 1.3.6.2 he {
940 1.3.6.2 he struct yds_codec_softc *codec = sc_;
941 1.3.6.2 he struct yds_softc *sc = codec->sc;
942 1.3.6.2 he pcireg_t reg;
943 1.3.6.2 he
944 1.3.6.2 he /* reset AC97 codec */
945 1.3.6.2 he reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, YDS_PCI_DSCTRL);
946 1.3.6.2 he if (reg & 0x03) {
947 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
948 1.3.6.2 he YDS_PCI_DSCTRL, reg & ~0x03);
949 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
950 1.3.6.2 he YDS_PCI_DSCTRL, reg | 0x03);
951 1.3.6.2 he pci_conf_write(sc->sc_pc, sc->sc_pcitag,
952 1.3.6.2 he YDS_PCI_DSCTRL, reg & ~0x03);
953 1.3.6.2 he delay(50000);
954 1.3.6.2 he }
955 1.3.6.2 he
956 1.3.6.2 he yds_ready_codec(sc_);
957 1.3.6.2 he }
958 1.3.6.2 he
959 1.3.6.2 he int
960 1.3.6.2 he yds_intr(p)
961 1.3.6.2 he void *p;
962 1.3.6.2 he {
963 1.3.6.2 he struct yds_softc *sc = p;
964 1.3.6.2 he u_int status;
965 1.3.6.2 he
966 1.3.6.2 he status = YREAD4(sc, YDS_STATUS);
967 1.3.6.2 he DPRINTFN(1, ("yds_intr: status=%08x\n", status));
968 1.3.6.2 he if ((status & (YDS_STAT_INT|YDS_STAT_TINT)) == 0) {
969 1.3.6.2 he #if NMPU > 0
970 1.3.6.2 he if (sc->sc_mpu)
971 1.3.6.2 he return mpu_intr(sc->sc_mpu);
972 1.3.6.2 he #endif
973 1.3.6.2 he return 0;
974 1.3.6.2 he }
975 1.3.6.2 he
976 1.3.6.2 he if (status & YDS_STAT_TINT) {
977 1.3.6.2 he YWRITE4(sc, YDS_STATUS, YDS_STAT_TINT);
978 1.3.6.2 he printf ("yds_intr: timeout!\n");
979 1.3.6.2 he }
980 1.3.6.2 he
981 1.3.6.2 he if (status & YDS_STAT_INT) {
982 1.3.6.2 he int nbank = (YREAD4(sc, YDS_CONTROL_SELECT) == 0);
983 1.3.6.2 he
984 1.3.6.2 he /* Clear interrupt flag */
985 1.3.6.2 he YWRITE4(sc, YDS_STATUS, YDS_STAT_INT);
986 1.3.6.2 he
987 1.3.6.2 he /* Buffer for the next frame is always ready. */
988 1.3.6.2 he YWRITE4(sc, YDS_MODE, YREAD4(sc, YDS_MODE) | YDS_MODE_ACTV2);
989 1.3.6.2 he
990 1.3.6.2 he if (sc->sc_play.intr) {
991 1.3.6.2 he u_int dma, cpu, blk, len;
992 1.3.6.2 he
993 1.3.6.2 he /* Sync play slot control data */
994 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
995 1.3.6.2 he sc->pbankoff,
996 1.3.6.2 he sizeof(struct play_slot_ctrl_bank)*
997 1.3.6.2 he (*sc->ptbl)*
998 1.3.6.2 he N_PLAY_SLOT_CTRL_BANK,
999 1.3.6.2 he BUS_DMASYNC_POSTWRITE|
1000 1.3.6.2 he BUS_DMASYNC_POSTREAD);
1001 1.3.6.2 he dma = sc->pbankp[nbank]->pgstart * sc->sc_play.factor;
1002 1.3.6.2 he cpu = sc->sc_play.offset;
1003 1.3.6.2 he blk = sc->sc_play.blksize;
1004 1.3.6.2 he len = sc->sc_play.length;
1005 1.3.6.2 he
1006 1.3.6.2 he if (((dma > cpu) && (dma - cpu > blk * 2)) ||
1007 1.3.6.2 he ((cpu > dma) && (dma + len - cpu > blk * 2))) {
1008 1.3.6.2 he /* We can fill the next block */
1009 1.3.6.2 he /* Sync ring buffer for previous write */
1010 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag,
1011 1.3.6.2 he sc->sc_play.dma->map,
1012 1.3.6.2 he cpu, blk,
1013 1.3.6.2 he BUS_DMASYNC_POSTWRITE);
1014 1.3.6.2 he sc->sc_play.intr(sc->sc_play.intr_arg);
1015 1.3.6.2 he sc->sc_play.offset += blk;
1016 1.3.6.2 he if (sc->sc_play.offset >= len) {
1017 1.3.6.2 he sc->sc_play.offset -= len;
1018 1.3.6.2 he #ifdef DIAGNOSTIC
1019 1.3.6.2 he if (sc->sc_play.offset != 0)
1020 1.3.6.2 he printf ("Audio ringbuffer botch\n");
1021 1.3.6.2 he #endif
1022 1.3.6.2 he }
1023 1.3.6.2 he /* Sync ring buffer for next write */
1024 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag,
1025 1.3.6.2 he sc->sc_play.dma->map,
1026 1.3.6.2 he cpu, blk,
1027 1.3.6.2 he BUS_DMASYNC_PREWRITE);
1028 1.3.6.2 he }
1029 1.3.6.2 he }
1030 1.3.6.2 he if (sc->sc_rec.intr) {
1031 1.3.6.2 he u_int dma, cpu, blk, len;
1032 1.3.6.2 he
1033 1.3.6.2 he /* Sync rec slot control data */
1034 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
1035 1.3.6.2 he sc->rbankoff,
1036 1.3.6.2 he sizeof(struct rec_slot_ctrl_bank)*
1037 1.3.6.2 he N_REC_SLOT_CTRL*
1038 1.3.6.2 he N_REC_SLOT_CTRL_BANK,
1039 1.3.6.2 he BUS_DMASYNC_POSTWRITE|
1040 1.3.6.2 he BUS_DMASYNC_POSTREAD);
1041 1.3.6.2 he dma = sc->rbank[YDS_INPUT_SLOT*2 + nbank].pgstartadr;
1042 1.3.6.2 he cpu = sc->sc_rec.offset;
1043 1.3.6.2 he blk = sc->sc_rec.blksize;
1044 1.3.6.2 he len = sc->sc_rec.length;
1045 1.3.6.2 he
1046 1.3.6.2 he if (((dma > cpu) && (dma - cpu > blk * 2)) ||
1047 1.3.6.2 he ((cpu > dma) && (dma + len - cpu > blk * 2))) {
1048 1.3.6.2 he /* We can drain the current block */
1049 1.3.6.2 he /* Sync ring buffer first */
1050 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag,
1051 1.3.6.2 he sc->sc_rec.dma->map,
1052 1.3.6.2 he cpu, blk,
1053 1.3.6.2 he BUS_DMASYNC_POSTREAD);
1054 1.3.6.2 he sc->sc_rec.intr(sc->sc_rec.intr_arg);
1055 1.3.6.2 he sc->sc_rec.offset += blk;
1056 1.3.6.2 he if (sc->sc_rec.offset >= len) {
1057 1.3.6.2 he sc->sc_rec.offset -= len;
1058 1.3.6.2 he #ifdef DIAGNOSTIC
1059 1.3.6.2 he if (sc->sc_rec.offset != 0)
1060 1.3.6.2 he printf ("Audio ringbuffer botch\n");
1061 1.3.6.2 he #endif
1062 1.3.6.2 he }
1063 1.3.6.2 he /* Sync ring buffer for next read */
1064 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag,
1065 1.3.6.2 he sc->sc_rec.dma->map,
1066 1.3.6.2 he cpu, blk,
1067 1.3.6.2 he BUS_DMASYNC_PREREAD);
1068 1.3.6.2 he }
1069 1.3.6.2 he }
1070 1.3.6.2 he }
1071 1.3.6.2 he
1072 1.3.6.2 he return 1;
1073 1.3.6.2 he }
1074 1.3.6.2 he
1075 1.3.6.2 he int
1076 1.3.6.2 he yds_allocmem(sc, size, align, p)
1077 1.3.6.2 he struct yds_softc *sc;
1078 1.3.6.2 he size_t size;
1079 1.3.6.2 he size_t align;
1080 1.3.6.2 he struct yds_dma *p;
1081 1.3.6.2 he {
1082 1.3.6.2 he int error;
1083 1.3.6.2 he
1084 1.3.6.2 he p->size = size;
1085 1.3.6.2 he error = bus_dmamem_alloc(sc->sc_dmatag, p->size, align, 0,
1086 1.3.6.2 he p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
1087 1.3.6.2 he &p->nsegs, BUS_DMA_NOWAIT);
1088 1.3.6.2 he if (error)
1089 1.3.6.2 he return (error);
1090 1.3.6.2 he
1091 1.3.6.2 he error = bus_dmamem_map(sc->sc_dmatag, p->segs, p->nsegs, p->size,
1092 1.3.6.2 he &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
1093 1.3.6.2 he if (error)
1094 1.3.6.2 he goto free;
1095 1.3.6.2 he
1096 1.3.6.2 he error = bus_dmamap_create(sc->sc_dmatag, p->size, 1, p->size,
1097 1.3.6.2 he 0, BUS_DMA_NOWAIT, &p->map);
1098 1.3.6.2 he if (error)
1099 1.3.6.2 he goto unmap;
1100 1.3.6.2 he
1101 1.3.6.2 he error = bus_dmamap_load(sc->sc_dmatag, p->map, p->addr, p->size, NULL,
1102 1.3.6.2 he BUS_DMA_NOWAIT);
1103 1.3.6.2 he if (error)
1104 1.3.6.2 he goto destroy;
1105 1.3.6.2 he return (0);
1106 1.3.6.2 he
1107 1.3.6.2 he destroy:
1108 1.3.6.2 he bus_dmamap_destroy(sc->sc_dmatag, p->map);
1109 1.3.6.2 he unmap:
1110 1.3.6.2 he bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
1111 1.3.6.2 he free:
1112 1.3.6.2 he bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
1113 1.3.6.2 he return (error);
1114 1.3.6.2 he }
1115 1.3.6.2 he
1116 1.3.6.2 he int
1117 1.3.6.2 he yds_freemem(sc, p)
1118 1.3.6.2 he struct yds_softc *sc;
1119 1.3.6.2 he struct yds_dma *p;
1120 1.3.6.2 he {
1121 1.3.6.2 he bus_dmamap_unload(sc->sc_dmatag, p->map);
1122 1.3.6.2 he bus_dmamap_destroy(sc->sc_dmatag, p->map);
1123 1.3.6.2 he bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size);
1124 1.3.6.2 he bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs);
1125 1.3.6.2 he return 0;
1126 1.3.6.2 he }
1127 1.3.6.2 he
1128 1.3.6.2 he int
1129 1.3.6.2 he yds_open(addr, flags)
1130 1.3.6.2 he void *addr;
1131 1.3.6.2 he int flags;
1132 1.3.6.2 he {
1133 1.3.6.2 he struct yds_softc *sc = addr;
1134 1.3.6.2 he int mode;
1135 1.3.6.2 he
1136 1.3.6.2 he /* Select bank 0. */
1137 1.3.6.2 he YWRITE4(sc, YDS_CONTROL_SELECT, 0);
1138 1.3.6.2 he
1139 1.3.6.2 he /* Start the DSP operation. */
1140 1.3.6.2 he mode = YREAD4(sc, YDS_MODE);
1141 1.3.6.2 he mode |= YDS_MODE_ACTV;
1142 1.3.6.2 he mode &= ~YDS_MODE_ACTV2;
1143 1.3.6.2 he YWRITE4(sc, YDS_MODE, mode);
1144 1.3.6.2 he
1145 1.3.6.2 he return 0;
1146 1.3.6.2 he }
1147 1.3.6.2 he
1148 1.3.6.2 he /*
1149 1.3.6.2 he * Close function is called at splaudio().
1150 1.3.6.2 he */
1151 1.3.6.2 he void
1152 1.3.6.2 he yds_close(addr)
1153 1.3.6.2 he void *addr;
1154 1.3.6.2 he {
1155 1.3.6.2 he struct yds_softc *sc = addr;
1156 1.3.6.2 he
1157 1.3.6.2 he yds_halt_output(sc);
1158 1.3.6.2 he yds_halt_input(sc);
1159 1.3.6.2 he yds_halt(sc);
1160 1.3.6.2 he }
1161 1.3.6.2 he
1162 1.3.6.2 he int
1163 1.3.6.2 he yds_query_encoding(addr, fp)
1164 1.3.6.2 he void *addr;
1165 1.3.6.2 he struct audio_encoding *fp;
1166 1.3.6.2 he {
1167 1.3.6.2 he switch (fp->index) {
1168 1.3.6.2 he case 0:
1169 1.3.6.2 he strcpy(fp->name, AudioEulinear);
1170 1.3.6.2 he fp->encoding = AUDIO_ENCODING_ULINEAR;
1171 1.3.6.2 he fp->precision = 8;
1172 1.3.6.2 he fp->flags = 0;
1173 1.3.6.2 he return (0);
1174 1.3.6.2 he case 1:
1175 1.3.6.2 he strcpy(fp->name, AudioEmulaw);
1176 1.3.6.2 he fp->encoding = AUDIO_ENCODING_ULAW;
1177 1.3.6.2 he fp->precision = 8;
1178 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1179 1.3.6.2 he return (0);
1180 1.3.6.2 he case 2:
1181 1.3.6.2 he strcpy(fp->name, AudioEalaw);
1182 1.3.6.2 he fp->encoding = AUDIO_ENCODING_ALAW;
1183 1.3.6.2 he fp->precision = 8;
1184 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1185 1.3.6.2 he return (0);
1186 1.3.6.2 he case 3:
1187 1.3.6.2 he strcpy(fp->name, AudioEslinear);
1188 1.3.6.2 he fp->encoding = AUDIO_ENCODING_SLINEAR;
1189 1.3.6.2 he fp->precision = 8;
1190 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1191 1.3.6.2 he return (0);
1192 1.3.6.2 he case 4:
1193 1.3.6.2 he strcpy(fp->name, AudioEslinear_le);
1194 1.3.6.2 he fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
1195 1.3.6.2 he fp->precision = 16;
1196 1.3.6.2 he fp->flags = 0;
1197 1.3.6.2 he return (0);
1198 1.3.6.2 he case 5:
1199 1.3.6.2 he strcpy(fp->name, AudioEulinear_le);
1200 1.3.6.2 he fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
1201 1.3.6.2 he fp->precision = 16;
1202 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1203 1.3.6.2 he return (0);
1204 1.3.6.2 he case 6:
1205 1.3.6.2 he strcpy(fp->name, AudioEslinear_be);
1206 1.3.6.2 he fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
1207 1.3.6.2 he fp->precision = 16;
1208 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1209 1.3.6.2 he return (0);
1210 1.3.6.2 he case 7:
1211 1.3.6.2 he strcpy(fp->name, AudioEulinear_be);
1212 1.3.6.2 he fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
1213 1.3.6.2 he fp->precision = 16;
1214 1.3.6.2 he fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
1215 1.3.6.2 he return (0);
1216 1.3.6.2 he default:
1217 1.3.6.2 he return (EINVAL);
1218 1.3.6.2 he }
1219 1.3.6.2 he }
1220 1.3.6.2 he
1221 1.3.6.2 he int
1222 1.3.6.2 he yds_set_params(addr, setmode, usemode, play, rec)
1223 1.3.6.2 he void *addr;
1224 1.3.6.2 he int setmode, usemode;
1225 1.3.6.2 he struct audio_params *play, *rec;
1226 1.3.6.2 he {
1227 1.3.6.2 he struct audio_params *p;
1228 1.3.6.2 he int mode;
1229 1.3.6.2 he
1230 1.3.6.2 he for (mode = AUMODE_RECORD; mode != -1;
1231 1.3.6.2 he mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
1232 1.3.6.2 he if ((setmode & mode) == 0)
1233 1.3.6.2 he continue;
1234 1.3.6.2 he
1235 1.3.6.2 he p = mode == AUMODE_PLAY ? play : rec;
1236 1.3.6.2 he
1237 1.3.6.2 he if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
1238 1.3.6.2 he (p->precision != 8 && p->precision != 16) ||
1239 1.3.6.2 he (p->channels != 1 && p->channels != 2))
1240 1.3.6.2 he return (EINVAL);
1241 1.3.6.2 he
1242 1.3.6.2 he p->factor = 1;
1243 1.3.6.2 he p->sw_code = 0;
1244 1.3.6.2 he switch (p->encoding) {
1245 1.3.6.2 he case AUDIO_ENCODING_SLINEAR_BE:
1246 1.3.6.2 he if (p->precision == 16)
1247 1.3.6.2 he p->sw_code = swap_bytes;
1248 1.3.6.2 he else
1249 1.3.6.2 he p->sw_code = change_sign8;
1250 1.3.6.2 he break;
1251 1.3.6.2 he case AUDIO_ENCODING_SLINEAR_LE:
1252 1.3.6.2 he if (p->precision != 16)
1253 1.3.6.2 he p->sw_code = change_sign8;
1254 1.3.6.2 he break;
1255 1.3.6.2 he case AUDIO_ENCODING_ULINEAR_BE:
1256 1.3.6.2 he if (p->precision == 16) {
1257 1.3.6.2 he if (mode == AUMODE_PLAY)
1258 1.3.6.2 he p->sw_code = swap_bytes_change_sign16_le;
1259 1.3.6.2 he else
1260 1.3.6.2 he p->sw_code = change_sign16_swap_bytes_le;
1261 1.3.6.2 he }
1262 1.3.6.2 he break;
1263 1.3.6.2 he case AUDIO_ENCODING_ULINEAR_LE:
1264 1.3.6.2 he if (p->precision == 16)
1265 1.3.6.2 he p->sw_code = change_sign16_le;
1266 1.3.6.2 he break;
1267 1.3.6.2 he case AUDIO_ENCODING_ULAW:
1268 1.3.6.2 he if (mode == AUMODE_PLAY) {
1269 1.3.6.2 he p->factor = 2;
1270 1.3.6.2 he p->precision = 16;
1271 1.3.6.2 he p->sw_code = mulaw_to_slinear16_le;
1272 1.3.6.2 he } else
1273 1.3.6.2 he p->sw_code = ulinear8_to_mulaw;
1274 1.3.6.2 he break;
1275 1.3.6.2 he case AUDIO_ENCODING_ALAW:
1276 1.3.6.2 he if (mode == AUMODE_PLAY) {
1277 1.3.6.2 he p->factor = 2;
1278 1.3.6.2 he p->precision = 16;
1279 1.3.6.2 he p->sw_code = alaw_to_slinear16_le;
1280 1.3.6.2 he } else
1281 1.3.6.2 he p->sw_code = ulinear8_to_alaw;
1282 1.3.6.2 he break;
1283 1.3.6.2 he default:
1284 1.3.6.2 he return (EINVAL);
1285 1.3.6.2 he }
1286 1.3.6.2 he }
1287 1.3.6.2 he
1288 1.3.6.2 he return 0;
1289 1.3.6.2 he }
1290 1.3.6.2 he
1291 1.3.6.2 he int
1292 1.3.6.2 he yds_round_blocksize(addr, blk)
1293 1.3.6.2 he void *addr;
1294 1.3.6.2 he int blk;
1295 1.3.6.2 he {
1296 1.3.6.2 he /*
1297 1.3.6.2 he * Block size must be bigger than a frame.
1298 1.3.6.2 he * That is 1024bytes at most, i.e. for 48000Hz, 16bit, 2ch.
1299 1.3.6.2 he */
1300 1.3.6.2 he if (blk < 1024)
1301 1.3.6.2 he blk = 1024;
1302 1.3.6.2 he
1303 1.3.6.2 he return blk & ~4;
1304 1.3.6.2 he }
1305 1.3.6.2 he
1306 1.3.6.2 he static u_int32_t
1307 1.3.6.2 he yds_get_lpfq(sample_rate)
1308 1.3.6.2 he u_int sample_rate;
1309 1.3.6.2 he {
1310 1.3.6.2 he int i;
1311 1.3.6.2 he static struct lpfqt {
1312 1.3.6.2 he u_int rate;
1313 1.3.6.2 he u_int32_t lpfq;
1314 1.3.6.2 he } lpfqt[] = {
1315 1.3.6.2 he {8000, 0x32020000},
1316 1.3.6.2 he {11025, 0x31770000},
1317 1.3.6.2 he {16000, 0x31390000},
1318 1.3.6.2 he {22050, 0x31c90000},
1319 1.3.6.2 he {32000, 0x33d00000},
1320 1.3.6.2 he {48000, 0x40000000},
1321 1.3.6.2 he {0, 0}
1322 1.3.6.2 he };
1323 1.3.6.2 he
1324 1.3.6.2 he if (sample_rate == 44100) /* for P44 slot? */
1325 1.3.6.2 he return 0x370A0000;
1326 1.3.6.2 he
1327 1.3.6.2 he for (i = 0; lpfqt[i].rate != 0; i++)
1328 1.3.6.2 he if (sample_rate <= lpfqt[i].rate)
1329 1.3.6.2 he break;
1330 1.3.6.2 he
1331 1.3.6.2 he return lpfqt[i].lpfq;
1332 1.3.6.2 he }
1333 1.3.6.2 he
1334 1.3.6.2 he static u_int32_t
1335 1.3.6.2 he yds_get_lpfk(sample_rate)
1336 1.3.6.2 he u_int sample_rate;
1337 1.3.6.2 he {
1338 1.3.6.2 he int i;
1339 1.3.6.2 he static struct lpfkt {
1340 1.3.6.2 he u_int rate;
1341 1.3.6.2 he u_int32_t lpfk;
1342 1.3.6.2 he } lpfkt[] = {
1343 1.3.6.2 he {8000, 0x18b20000},
1344 1.3.6.2 he {11025, 0x20930000},
1345 1.3.6.2 he {16000, 0x2b9a0000},
1346 1.3.6.2 he {22050, 0x35a10000},
1347 1.3.6.2 he {32000, 0x3eaa0000},
1348 1.3.6.2 he {48000, 0x40000000},
1349 1.3.6.2 he {0, 0}
1350 1.3.6.2 he };
1351 1.3.6.2 he
1352 1.3.6.2 he if (sample_rate == 44100) /* for P44 slot? */
1353 1.3.6.2 he return 0x46460000;
1354 1.3.6.2 he
1355 1.3.6.2 he for (i = 0; lpfkt[i].rate != 0; i++)
1356 1.3.6.2 he if (sample_rate <= lpfkt[i].rate)
1357 1.3.6.2 he break;
1358 1.3.6.2 he
1359 1.3.6.2 he return lpfkt[i].lpfk;
1360 1.3.6.2 he }
1361 1.3.6.2 he
1362 1.3.6.2 he int
1363 1.3.6.2 he yds_trigger_output(addr, start, end, blksize, intr, arg, param)
1364 1.3.6.2 he void *addr;
1365 1.3.6.2 he void *start, *end;
1366 1.3.6.2 he int blksize;
1367 1.3.6.2 he void (*intr) __P((void *));
1368 1.3.6.2 he void *arg;
1369 1.3.6.2 he struct audio_params *param;
1370 1.3.6.2 he #define P44 (sc->sc_flags & YDS_CAP_HAS_P44)
1371 1.3.6.2 he {
1372 1.3.6.2 he struct yds_softc *sc = addr;
1373 1.3.6.2 he struct yds_dma *p;
1374 1.3.6.2 he struct play_slot_ctrl_bank *psb;
1375 1.3.6.2 he const u_int gain = 0x40000000;
1376 1.3.6.2 he bus_addr_t s;
1377 1.3.6.2 he size_t l;
1378 1.3.6.2 he int i;
1379 1.3.6.2 he int p44, channels;
1380 1.3.6.2 he
1381 1.3.6.2 he #ifdef DIAGNOSTIC
1382 1.3.6.2 he if (sc->sc_play.intr)
1383 1.3.6.2 he panic("yds_trigger_output: already running");
1384 1.3.6.2 he #endif
1385 1.3.6.2 he
1386 1.3.6.2 he sc->sc_play.intr = intr;
1387 1.3.6.2 he sc->sc_play.intr_arg = arg;
1388 1.3.6.2 he sc->sc_play.offset = 0;
1389 1.3.6.2 he sc->sc_play.blksize = blksize;
1390 1.3.6.2 he
1391 1.3.6.2 he DPRINTFN(1, ("yds_trigger_output: sc=%p start=%p end=%p "
1392 1.3.6.2 he "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
1393 1.3.6.2 he
1394 1.3.6.2 he p = yds_find_dma(sc, start);
1395 1.3.6.2 he if (!p) {
1396 1.3.6.2 he printf("yds_trigger_output: bad addr %p\n", start);
1397 1.3.6.2 he return (EINVAL);
1398 1.3.6.2 he }
1399 1.3.6.2 he sc->sc_play.dma = p;
1400 1.3.6.2 he
1401 1.3.6.2 he #ifdef YDS_USE_P44
1402 1.3.6.2 he /* The document says the P44 SRC supports only stereo, 16bit PCM. */
1403 1.3.6.2 he if (P44)
1404 1.3.6.2 he p44 = ((param->sample_rate == 44100) &&
1405 1.3.6.2 he (param->channels == 2) &&
1406 1.3.6.2 he (param->precision == 16));
1407 1.3.6.2 he else
1408 1.3.6.2 he #endif
1409 1.3.6.2 he p44 = 0;
1410 1.3.6.2 he channels = p44 ? 1 : param->channels;
1411 1.3.6.2 he
1412 1.3.6.2 he s = DMAADDR(p);
1413 1.3.6.2 he l = ((char *)end - (char *)start);
1414 1.3.6.2 he sc->sc_play.length = l;
1415 1.3.6.2 he
1416 1.3.6.2 he *sc->ptbl = channels; /* Num of play */
1417 1.3.6.2 he
1418 1.3.6.2 he sc->sc_play.factor = 1;
1419 1.3.6.2 he if (param->channels == 2)
1420 1.3.6.2 he sc->sc_play.factor *= 2;
1421 1.3.6.2 he if (param->precision != 8)
1422 1.3.6.2 he sc->sc_play.factor *= 2;
1423 1.3.6.2 he l /= sc->sc_play.factor;
1424 1.3.6.2 he
1425 1.3.6.2 he psb = sc->pbankp[0];
1426 1.3.6.2 he memset(psb, 0, sizeof(*psb));
1427 1.3.6.2 he psb->format = ((channels == 2 ? PSLT_FORMAT_STEREO : 0) |
1428 1.3.6.2 he (param->precision == 8 ? PSLT_FORMAT_8BIT : 0) |
1429 1.3.6.2 he (p44 ? PSLT_FORMAT_SRC441 : 0));
1430 1.3.6.2 he psb->pgbase = s;
1431 1.3.6.2 he psb->pgloopend = l;
1432 1.3.6.2 he if (!p44) {
1433 1.3.6.2 he psb->pgdeltaend = (param->sample_rate * 65536 / 48000) << 12;
1434 1.3.6.2 he psb->lpfkend = yds_get_lpfk(param->sample_rate);
1435 1.3.6.2 he psb->eggainend = gain;
1436 1.3.6.2 he psb->lpfq = yds_get_lpfq(param->sample_rate);
1437 1.3.6.2 he psb->pgdelta = psb->pgdeltaend;
1438 1.3.6.2 he psb->lpfk = yds_get_lpfk(param->sample_rate);
1439 1.3.6.2 he psb->eggain = gain;
1440 1.3.6.2 he }
1441 1.3.6.2 he
1442 1.3.6.2 he for (i = 0; i < channels; i++) {
1443 1.3.6.2 he /* i == 0: left or mono, i == 1: right */
1444 1.3.6.2 he psb = sc->pbankp[i*2];
1445 1.3.6.2 he if (i)
1446 1.3.6.2 he /* copy from left */
1447 1.3.6.2 he *psb = *(sc->pbankp[0]);
1448 1.3.6.2 he if (channels == 2) {
1449 1.3.6.2 he /* stereo */
1450 1.3.6.2 he if (i == 0) {
1451 1.3.6.2 he psb->lchgain = psb->lchgainend = gain;
1452 1.3.6.2 he } else {
1453 1.3.6.3 he psb->lchgain = psb->lchgainend = 0;
1454 1.3.6.2 he psb->rchgain = psb->rchgainend = gain;
1455 1.3.6.2 he psb->format |= PSLT_FORMAT_RCH;
1456 1.3.6.2 he }
1457 1.3.6.2 he } else if (!p44) {
1458 1.3.6.2 he /* mono */
1459 1.3.6.2 he psb->lchgain = psb->rchgain = gain;
1460 1.3.6.2 he psb->lchgainend = psb->rchgainend = gain;
1461 1.3.6.2 he }
1462 1.3.6.2 he /* copy to the other bank */
1463 1.3.6.2 he *(sc->pbankp[i*2+1]) = *psb;
1464 1.3.6.2 he }
1465 1.3.6.2 he
1466 1.3.6.2 he YDS_DUMP_PLAY_SLOT(5, sc, 0);
1467 1.3.6.2 he YDS_DUMP_PLAY_SLOT(5, sc, 1);
1468 1.3.6.2 he
1469 1.3.6.2 he if (p44)
1470 1.3.6.2 he YWRITE4(sc, YDS_P44_OUT_VOLUME, 0x3fff3fff);
1471 1.3.6.2 he else
1472 1.3.6.2 he YWRITE4(sc, YDS_DAC_OUT_VOLUME, 0x3fff3fff);
1473 1.3.6.2 he
1474 1.3.6.2 he /* Now the play slot for the next frame is set up!! */
1475 1.3.6.2 he /* Sync play slot control data for both directions */
1476 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
1477 1.3.6.2 he sc->ptbloff,
1478 1.3.6.2 he sizeof(struct play_slot_ctrl_bank) *
1479 1.3.6.2 he channels * N_PLAY_SLOT_CTRL_BANK,
1480 1.3.6.2 he BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
1481 1.3.6.2 he /* Sync ring buffer */
1482 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, p->map, 0, blksize,
1483 1.3.6.2 he BUS_DMASYNC_PREWRITE);
1484 1.3.6.2 he /* HERE WE GO!! */
1485 1.3.6.2 he YWRITE4(sc, YDS_MODE,
1486 1.3.6.2 he YREAD4(sc, YDS_MODE) | YDS_MODE_ACTV | YDS_MODE_ACTV2);
1487 1.3.6.2 he
1488 1.3.6.2 he return 0;
1489 1.3.6.2 he }
1490 1.3.6.2 he #undef P44
1491 1.3.6.2 he
1492 1.3.6.2 he int
1493 1.3.6.2 he yds_trigger_input(addr, start, end, blksize, intr, arg, param)
1494 1.3.6.2 he void *addr;
1495 1.3.6.2 he void *start, *end;
1496 1.3.6.2 he int blksize;
1497 1.3.6.2 he void (*intr) __P((void *));
1498 1.3.6.2 he void *arg;
1499 1.3.6.2 he struct audio_params *param;
1500 1.3.6.2 he {
1501 1.3.6.2 he struct yds_softc *sc = addr;
1502 1.3.6.2 he struct yds_dma *p;
1503 1.3.6.2 he u_int srate, format;
1504 1.3.6.2 he struct rec_slot_ctrl_bank *rsb;
1505 1.3.6.2 he bus_addr_t s;
1506 1.3.6.2 he size_t l;
1507 1.3.6.2 he
1508 1.3.6.2 he #ifdef DIAGNOSTIC
1509 1.3.6.2 he if (sc->sc_rec.intr)
1510 1.3.6.2 he panic("yds_trigger_input: already running");
1511 1.3.6.2 he #endif
1512 1.3.6.2 he sc->sc_rec.intr = intr;
1513 1.3.6.2 he sc->sc_rec.intr_arg = arg;
1514 1.3.6.2 he sc->sc_rec.offset = 0;
1515 1.3.6.2 he sc->sc_rec.blksize = blksize;
1516 1.3.6.2 he
1517 1.3.6.2 he DPRINTFN(1, ("yds_trigger_input: "
1518 1.3.6.2 he "sc=%p start=%p end=%p blksize=%d intr=%p(%p)\n",
1519 1.3.6.2 he addr, start, end, blksize, intr, arg));
1520 1.3.6.2 he DPRINTFN(1, (" parameters: rate=%lu, precision=%u, channels=%u\n",
1521 1.3.6.2 he param->sample_rate, param->precision, param->channels));
1522 1.3.6.2 he
1523 1.3.6.2 he p = yds_find_dma(sc, start);
1524 1.3.6.2 he if (!p) {
1525 1.3.6.2 he printf("yds_trigger_input: bad addr %p\n", start);
1526 1.3.6.2 he return (EINVAL);
1527 1.3.6.2 he }
1528 1.3.6.2 he sc->sc_rec.dma = p;
1529 1.3.6.2 he
1530 1.3.6.2 he s = DMAADDR(p);
1531 1.3.6.2 he l = ((char *)end - (char *)start);
1532 1.3.6.2 he sc->sc_rec.length = l;
1533 1.3.6.2 he
1534 1.3.6.2 he sc->sc_rec.factor = 1;
1535 1.3.6.2 he if (param->channels == 2)
1536 1.3.6.2 he sc->sc_rec.factor *= 2;
1537 1.3.6.2 he if (param->precision != 8)
1538 1.3.6.2 he sc->sc_rec.factor *= 2;
1539 1.3.6.2 he
1540 1.3.6.2 he rsb = &sc->rbank[0];
1541 1.3.6.2 he memset(rsb, 0, sizeof(*rsb));
1542 1.3.6.2 he rsb->pgbase = s;
1543 1.3.6.2 he rsb->pgloopendadr = l;
1544 1.3.6.2 he /* Seems all 4 banks must be set up... */
1545 1.3.6.2 he sc->rbank[1] = *rsb;
1546 1.3.6.2 he sc->rbank[2] = *rsb;
1547 1.3.6.2 he sc->rbank[3] = *rsb;
1548 1.3.6.2 he
1549 1.3.6.2 he YWRITE4(sc, YDS_ADC_IN_VOLUME, 0x3fff3fff);
1550 1.3.6.2 he YWRITE4(sc, YDS_REC_IN_VOLUME, 0x3fff3fff);
1551 1.3.6.2 he srate = 48000 * 4096 / param->sample_rate - 1;
1552 1.3.6.2 he format = ((param->precision == 8 ? YDS_FORMAT_8BIT : 0) |
1553 1.3.6.2 he (param->channels == 2 ? YDS_FORMAT_STEREO : 0));
1554 1.3.6.2 he DPRINTF(("srate=%d, format=%08x\n", srate, format));
1555 1.3.6.2 he #ifdef YDS_USE_REC_SLOT
1556 1.3.6.2 he YWRITE4(sc, YDS_DAC_REC_VOLUME, 0x3fff3fff);
1557 1.3.6.2 he YWRITE4(sc, YDS_P44_REC_VOLUME, 0x3fff3fff);
1558 1.3.6.2 he YWRITE4(sc, YDS_MAPOF_REC, YDS_RECSLOT_VALID);
1559 1.3.6.2 he YWRITE4(sc, YDS_REC_SAMPLE_RATE, srate);
1560 1.3.6.2 he YWRITE4(sc, YDS_REC_FORMAT, format);
1561 1.3.6.2 he #else
1562 1.3.6.2 he YWRITE4(sc, YDS_MAPOF_REC, YDS_ADCSLOT_VALID);
1563 1.3.6.2 he YWRITE4(sc, YDS_ADC_SAMPLE_RATE, srate);
1564 1.3.6.2 he YWRITE4(sc, YDS_ADC_FORMAT, format);
1565 1.3.6.2 he #endif
1566 1.3.6.2 he /* Now the rec slot for the next frame is set up!! */
1567 1.3.6.2 he /* Sync record slot control data */
1568 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
1569 1.3.6.2 he sc->rbankoff,
1570 1.3.6.2 he sizeof(struct rec_slot_ctrl_bank)*
1571 1.3.6.2 he N_REC_SLOT_CTRL*
1572 1.3.6.2 he N_REC_SLOT_CTRL_BANK,
1573 1.3.6.2 he BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
1574 1.3.6.2 he /* Sync ring buffer */
1575 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, p->map, 0, blksize,
1576 1.3.6.2 he BUS_DMASYNC_PREREAD);
1577 1.3.6.2 he /* HERE WE GO!! */
1578 1.3.6.2 he YWRITE4(sc, YDS_MODE,
1579 1.3.6.2 he YREAD4(sc, YDS_MODE) | YDS_MODE_ACTV | YDS_MODE_ACTV2);
1580 1.3.6.2 he
1581 1.3.6.2 he return 0;
1582 1.3.6.2 he }
1583 1.3.6.2 he
1584 1.3.6.2 he static int
1585 1.3.6.2 he yds_halt(sc)
1586 1.3.6.2 he struct yds_softc *sc;
1587 1.3.6.2 he {
1588 1.3.6.2 he u_int32_t mode;
1589 1.3.6.2 he
1590 1.3.6.2 he /* Stop the DSP operation. */
1591 1.3.6.2 he mode = YREAD4(sc, YDS_MODE);
1592 1.3.6.2 he YWRITE4(sc, YDS_MODE, mode & ~(YDS_MODE_ACTV|YDS_MODE_ACTV2));
1593 1.3.6.2 he
1594 1.3.6.2 he /* Paranoia... mute all */
1595 1.3.6.2 he YWRITE4(sc, YDS_P44_OUT_VOLUME, 0);
1596 1.3.6.2 he YWRITE4(sc, YDS_DAC_OUT_VOLUME, 0);
1597 1.3.6.2 he YWRITE4(sc, YDS_ADC_IN_VOLUME, 0);
1598 1.3.6.2 he YWRITE4(sc, YDS_REC_IN_VOLUME, 0);
1599 1.3.6.2 he YWRITE4(sc, YDS_DAC_REC_VOLUME, 0);
1600 1.3.6.2 he YWRITE4(sc, YDS_P44_REC_VOLUME, 0);
1601 1.3.6.2 he
1602 1.3.6.2 he return 0;
1603 1.3.6.2 he }
1604 1.3.6.2 he
1605 1.3.6.2 he int
1606 1.3.6.2 he yds_halt_output(addr)
1607 1.3.6.2 he void *addr;
1608 1.3.6.2 he {
1609 1.3.6.2 he struct yds_softc *sc = addr;
1610 1.3.6.2 he
1611 1.3.6.2 he DPRINTF(("yds: yds_halt_output\n"));
1612 1.3.6.2 he if (sc->sc_play.intr) {
1613 1.3.6.2 he sc->sc_play.intr = 0;
1614 1.3.6.2 he /* Sync play slot control data */
1615 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
1616 1.3.6.2 he sc->pbankoff,
1617 1.3.6.2 he sizeof(struct play_slot_ctrl_bank)*
1618 1.3.6.2 he (*sc->ptbl)*N_PLAY_SLOT_CTRL_BANK,
1619 1.3.6.2 he BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
1620 1.3.6.2 he /* Stop the play slot operation */
1621 1.3.6.2 he sc->pbankp[0]->status =
1622 1.3.6.2 he sc->pbankp[1]->status =
1623 1.3.6.2 he sc->pbankp[2]->status =
1624 1.3.6.2 he sc->pbankp[3]->status = 1;
1625 1.3.6.2 he /* Sync ring buffer */
1626 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_play.dma->map,
1627 1.3.6.2 he 0, sc->sc_play.length, BUS_DMASYNC_POSTWRITE);
1628 1.3.6.2 he }
1629 1.3.6.2 he
1630 1.3.6.2 he return 0;
1631 1.3.6.2 he }
1632 1.3.6.2 he
1633 1.3.6.2 he int
1634 1.3.6.2 he yds_halt_input(addr)
1635 1.3.6.2 he void *addr;
1636 1.3.6.2 he {
1637 1.3.6.2 he struct yds_softc *sc = addr;
1638 1.3.6.2 he
1639 1.3.6.2 he DPRINTF(("yds: yds_halt_input\n"));
1640 1.3.6.2 he sc->sc_rec.intr = NULL;
1641 1.3.6.2 he if (sc->sc_rec.intr) {
1642 1.3.6.2 he /* Stop the rec slot operation */
1643 1.3.6.2 he YWRITE4(sc, YDS_MAPOF_REC, 0);
1644 1.3.6.2 he sc->sc_rec.intr = 0;
1645 1.3.6.2 he /* Sync rec slot control data */
1646 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_ctrldata.map,
1647 1.3.6.2 he sc->rbankoff,
1648 1.3.6.2 he sizeof(struct rec_slot_ctrl_bank)*
1649 1.3.6.2 he N_REC_SLOT_CTRL*N_REC_SLOT_CTRL_BANK,
1650 1.3.6.2 he BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
1651 1.3.6.2 he /* Sync ring buffer */
1652 1.3.6.2 he bus_dmamap_sync(sc->sc_dmatag, sc->sc_rec.dma->map,
1653 1.3.6.2 he 0, sc->sc_rec.length, BUS_DMASYNC_POSTREAD);
1654 1.3.6.2 he }
1655 1.3.6.2 he
1656 1.3.6.2 he return 0;
1657 1.3.6.2 he }
1658 1.3.6.2 he
1659 1.3.6.2 he int
1660 1.3.6.2 he yds_getdev(addr, retp)
1661 1.3.6.2 he void *addr;
1662 1.3.6.2 he struct audio_device *retp;
1663 1.3.6.2 he {
1664 1.3.6.2 he *retp = yds_device;
1665 1.3.6.2 he
1666 1.3.6.2 he return 0;
1667 1.3.6.2 he }
1668 1.3.6.2 he
1669 1.3.6.2 he int
1670 1.3.6.2 he yds_mixer_set_port(addr, cp)
1671 1.3.6.2 he void *addr;
1672 1.3.6.2 he mixer_ctrl_t *cp;
1673 1.3.6.2 he {
1674 1.3.6.2 he struct yds_softc *sc = addr;
1675 1.3.6.2 he
1676 1.3.6.2 he return (sc->sc_codec[0].codec_if->vtbl->mixer_set_port(
1677 1.3.6.2 he sc->sc_codec[0].codec_if, cp));
1678 1.3.6.2 he }
1679 1.3.6.2 he
1680 1.3.6.2 he int
1681 1.3.6.2 he yds_mixer_get_port(addr, cp)
1682 1.3.6.2 he void *addr;
1683 1.3.6.2 he mixer_ctrl_t *cp;
1684 1.3.6.2 he {
1685 1.3.6.2 he struct yds_softc *sc = addr;
1686 1.3.6.2 he
1687 1.3.6.2 he return (sc->sc_codec[0].codec_if->vtbl->mixer_get_port(
1688 1.3.6.2 he sc->sc_codec[0].codec_if, cp));
1689 1.3.6.2 he }
1690 1.3.6.2 he
1691 1.3.6.2 he int
1692 1.3.6.2 he yds_query_devinfo(addr, dip)
1693 1.3.6.2 he void *addr;
1694 1.3.6.2 he mixer_devinfo_t *dip;
1695 1.3.6.2 he {
1696 1.3.6.2 he struct yds_softc *sc = addr;
1697 1.3.6.2 he
1698 1.3.6.2 he return (sc->sc_codec[0].codec_if->vtbl->query_devinfo(
1699 1.3.6.2 he sc->sc_codec[0].codec_if, dip));
1700 1.3.6.2 he }
1701 1.3.6.2 he
1702 1.3.6.2 he int
1703 1.3.6.2 he yds_get_portnum_by_name(sc, class, device, qualifier)
1704 1.3.6.2 he struct yds_softc *sc;
1705 1.3.6.2 he char *class, *device, *qualifier;
1706 1.3.6.2 he {
1707 1.3.6.2 he return (sc->sc_codec[0].codec_if->vtbl->get_portnum_by_name(
1708 1.3.6.2 he sc->sc_codec[0].codec_if, class, device, qualifier));
1709 1.3.6.2 he }
1710 1.3.6.2 he
1711 1.3.6.2 he void *
1712 1.3.6.2 he yds_malloc(addr, direction, size, pool, flags)
1713 1.3.6.2 he void *addr;
1714 1.3.6.2 he int direction;
1715 1.3.6.2 he size_t size;
1716 1.3.6.2 he int pool, flags;
1717 1.3.6.2 he {
1718 1.3.6.2 he struct yds_softc *sc = addr;
1719 1.3.6.2 he struct yds_dma *p;
1720 1.3.6.2 he int error;
1721 1.3.6.2 he
1722 1.3.6.2 he p = malloc(sizeof(*p), pool, flags);
1723 1.3.6.2 he if (!p)
1724 1.3.6.2 he return (0);
1725 1.3.6.2 he error = yds_allocmem(sc, size, 16, p);
1726 1.3.6.2 he if (error) {
1727 1.3.6.2 he free(p, pool);
1728 1.3.6.2 he return (0);
1729 1.3.6.2 he }
1730 1.3.6.2 he p->next = sc->sc_dmas;
1731 1.3.6.2 he sc->sc_dmas = p;
1732 1.3.6.2 he return (KERNADDR(p));
1733 1.3.6.2 he }
1734 1.3.6.2 he
1735 1.3.6.2 he void
1736 1.3.6.2 he yds_free(addr, ptr, pool)
1737 1.3.6.2 he void *addr;
1738 1.3.6.2 he void *ptr;
1739 1.3.6.2 he int pool;
1740 1.3.6.2 he {
1741 1.3.6.2 he struct yds_softc *sc = addr;
1742 1.3.6.2 he struct yds_dma **pp, *p;
1743 1.3.6.2 he
1744 1.3.6.2 he for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) {
1745 1.3.6.2 he if (KERNADDR(p) == ptr) {
1746 1.3.6.2 he yds_freemem(sc, p);
1747 1.3.6.2 he *pp = p->next;
1748 1.3.6.2 he free(p, pool);
1749 1.3.6.2 he return;
1750 1.3.6.2 he }
1751 1.3.6.2 he }
1752 1.3.6.2 he }
1753 1.3.6.2 he
1754 1.3.6.2 he static struct yds_dma *
1755 1.3.6.2 he yds_find_dma(sc, addr)
1756 1.3.6.2 he struct yds_softc *sc;
1757 1.3.6.2 he void *addr;
1758 1.3.6.2 he {
1759 1.3.6.2 he struct yds_dma *p;
1760 1.3.6.2 he
1761 1.3.6.2 he for (p = sc->sc_dmas; p && KERNADDR(p) != addr; p = p->next)
1762 1.3.6.2 he ;
1763 1.3.6.2 he
1764 1.3.6.2 he return p;
1765 1.3.6.2 he }
1766 1.3.6.2 he
1767 1.3.6.2 he size_t
1768 1.3.6.2 he yds_round_buffersize(addr, direction, size)
1769 1.3.6.2 he void *addr;
1770 1.3.6.2 he int direction;
1771 1.3.6.2 he size_t size;
1772 1.3.6.2 he {
1773 1.3.6.2 he /*
1774 1.3.6.2 he * Buffer size should be at least twice as bigger as a frame.
1775 1.3.6.2 he */
1776 1.3.6.2 he if (size < 1024 * 3)
1777 1.3.6.2 he size = 1024 * 3;
1778 1.3.6.2 he return (size);
1779 1.3.6.2 he }
1780 1.3.6.2 he
1781 1.3.6.2 he paddr_t
1782 1.3.6.2 he yds_mappage(addr, mem, off, prot)
1783 1.3.6.2 he void *addr;
1784 1.3.6.2 he void *mem;
1785 1.3.6.2 he off_t off;
1786 1.3.6.2 he int prot;
1787 1.3.6.2 he {
1788 1.3.6.2 he struct yds_softc *sc = addr;
1789 1.3.6.2 he struct yds_dma *p;
1790 1.3.6.2 he
1791 1.3.6.2 he if (off < 0)
1792 1.3.6.2 he return (-1);
1793 1.3.6.2 he p = yds_find_dma(sc, mem);
1794 1.3.6.2 he if (!p)
1795 1.3.6.2 he return (-1);
1796 1.3.6.2 he return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs,
1797 1.3.6.2 he off, prot, BUS_DMA_WAITOK));
1798 1.3.6.2 he }
1799 1.3.6.2 he
1800 1.3.6.2 he int
1801 1.3.6.2 he yds_get_props(addr)
1802 1.3.6.2 he void *addr;
1803 1.3.6.2 he {
1804 1.3.6.2 he return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT |
1805 1.3.6.2 he AUDIO_PROP_FULLDUPLEX);
1806 1.3.6.2 he }
1807