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