repulse.c revision 1.2.4.3 1 1.2.4.3 nathanw /* $NetBSD: repulse.c,v 1.2.4.3 2002/10/18 02:35:03 nathanw Exp $ */
2 1.2.4.2 nathanw
3 1.2.4.2 nathanw /*-
4 1.2.4.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.2.4.2 nathanw * All rights reserved.
6 1.2.4.2 nathanw *
7 1.2.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 nathanw * by Ignatios Souvatzis.
9 1.2.4.2 nathanw *
10 1.2.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.4.2 nathanw * are met:
13 1.2.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 nathanw * must display the following acknowledgement:
20 1.2.4.2 nathanw * This product includes software developed by the NetBSD
21 1.2.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.4.2 nathanw * from this software without specific prior written permission.
25 1.2.4.2 nathanw *
26 1.2.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 nathanw */
38 1.2.4.2 nathanw
39 1.2.4.2 nathanw #include <sys/cdefs.h>
40 1.2.4.3 nathanw __KERNEL_RCSID(0, "$NetBSD: repulse.c,v 1.2.4.3 2002/10/18 02:35:03 nathanw Exp $");
41 1.2.4.2 nathanw
42 1.2.4.2 nathanw #include <sys/types.h>
43 1.2.4.2 nathanw #include <sys/param.h>
44 1.2.4.2 nathanw #include <sys/systm.h>
45 1.2.4.2 nathanw #include <sys/kernel.h>
46 1.2.4.2 nathanw #include <sys/device.h>
47 1.2.4.2 nathanw #include <sys/fcntl.h> /* FREAD */
48 1.2.4.2 nathanw
49 1.2.4.2 nathanw #include <machine/bus.h>
50 1.2.4.2 nathanw
51 1.2.4.2 nathanw #include <sys/audioio.h>
52 1.2.4.2 nathanw #include <dev/audio_if.h>
53 1.2.4.2 nathanw #include <dev/mulaw.h>
54 1.2.4.2 nathanw
55 1.2.4.2 nathanw #include <dev/ic/ac97reg.h>
56 1.2.4.2 nathanw #include <dev/ic/ac97var.h>
57 1.2.4.2 nathanw
58 1.2.4.2 nathanw #include <amiga/dev/zbusvar.h>
59 1.2.4.2 nathanw #include <amiga/amiga/isr.h>
60 1.2.4.2 nathanw
61 1.2.4.2 nathanw #include <amiga/dev/repulse_firmware.h>
62 1.2.4.2 nathanw
63 1.2.4.2 nathanw #ifndef vu_int8_t
64 1.2.4.2 nathanw #define vu_int8_t volatile u_int8_t
65 1.2.4.2 nathanw #endif
66 1.2.4.2 nathanw #ifndef vu_int16_t
67 1.2.4.2 nathanw #define vu_int16_t volatile u_int16_t
68 1.2.4.2 nathanw #endif
69 1.2.4.2 nathanw #ifndef vu_int32_t
70 1.2.4.2 nathanw #define vu_int32_t volatile u_int32_t
71 1.2.4.2 nathanw #endif
72 1.2.4.2 nathanw
73 1.2.4.2 nathanw /* ac97 attachment functions */
74 1.2.4.2 nathanw
75 1.2.4.2 nathanw int repac_attach(void *, struct ac97_codec_if *);
76 1.2.4.2 nathanw int repac_read(void *, u_int8_t, u_int16_t *);
77 1.2.4.2 nathanw int repac_write(void *, u_int8_t, u_int16_t);
78 1.2.4.2 nathanw void repac_reset(void *);
79 1.2.4.2 nathanw enum ac97_host_flag repac_flags(void *);
80 1.2.4.2 nathanw
81 1.2.4.2 nathanw /* audio attachment functions */
82 1.2.4.2 nathanw
83 1.2.4.2 nathanw int rep_open(void *, int);
84 1.2.4.2 nathanw void rep_close(void *);
85 1.2.4.2 nathanw int rep_getdev(void *, struct audio_device *);
86 1.2.4.2 nathanw int rep_get_props(void *);
87 1.2.4.2 nathanw int rep_halt_output(void *);
88 1.2.4.2 nathanw int rep_halt_input(void *);
89 1.2.4.2 nathanw int rep_query_encoding(void *, struct audio_encoding *);
90 1.2.4.2 nathanw int rep_set_params(void *, int, int, struct audio_params *,
91 1.2.4.2 nathanw struct audio_params *);
92 1.2.4.2 nathanw int rep_round_blocksize(void *, int);
93 1.2.4.2 nathanw int rep_set_port(void *, mixer_ctrl_t *);
94 1.2.4.2 nathanw int rep_get_port(void *, mixer_ctrl_t *);
95 1.2.4.2 nathanw int rep_query_devinfo(void *, mixer_devinfo_t *);
96 1.2.4.2 nathanw size_t rep_round_buffersize(void *, int, size_t);
97 1.2.4.2 nathanw
98 1.2.4.2 nathanw int rep_start_input(void *, void *, int, void (*)(void *), void *);
99 1.2.4.2 nathanw int rep_start_output(void *, void *, int, void (*)(void *), void *);
100 1.2.4.2 nathanw
101 1.2.4.2 nathanw int rep_intr(void *tag);
102 1.2.4.2 nathanw
103 1.2.4.2 nathanw
104 1.2.4.2 nathanw /* audio attachment */
105 1.2.4.2 nathanw
106 1.2.4.2 nathanw struct audio_hw_if rep_hw_if = {
107 1.2.4.2 nathanw rep_open,
108 1.2.4.2 nathanw rep_close,
109 1.2.4.2 nathanw /* drain */ 0,
110 1.2.4.2 nathanw rep_query_encoding,
111 1.2.4.2 nathanw rep_set_params,
112 1.2.4.2 nathanw rep_round_blocksize,
113 1.2.4.2 nathanw /* commit_setting */ 0,
114 1.2.4.2 nathanw /* init_output */ 0,
115 1.2.4.2 nathanw /* init_input */ 0,
116 1.2.4.2 nathanw rep_start_output,
117 1.2.4.2 nathanw rep_start_input,
118 1.2.4.2 nathanw rep_halt_output,
119 1.2.4.2 nathanw rep_halt_input,
120 1.2.4.2 nathanw /* speaker_ctl */ 0,
121 1.2.4.2 nathanw rep_getdev,
122 1.2.4.2 nathanw /* getfd */ 0,
123 1.2.4.2 nathanw rep_set_port,
124 1.2.4.2 nathanw rep_get_port,
125 1.2.4.2 nathanw rep_query_devinfo,
126 1.2.4.2 nathanw /* allocm */ 0,
127 1.2.4.2 nathanw /* freem */ 0,
128 1.2.4.2 nathanw rep_round_buffersize,
129 1.2.4.2 nathanw /* mappage */ 0,
130 1.2.4.2 nathanw rep_get_props,
131 1.2.4.2 nathanw /* trigger_output */ 0,
132 1.2.4.2 nathanw /* trigger_input */ 0,
133 1.2.4.2 nathanw /* dev_ioctl */ 0,
134 1.2.4.2 nathanw };
135 1.2.4.2 nathanw
136 1.2.4.2 nathanw /* hardware registers */
137 1.2.4.2 nathanw
138 1.2.4.2 nathanw struct repulse_hw {
139 1.2.4.2 nathanw vu_int16_t rhw_status;
140 1.2.4.2 nathanw vu_int16_t rhw_fifostatus; /* 0xrrrrpppp0000flag */
141 1.2.4.2 nathanw vu_int16_t rhw_reg_address;
142 1.2.4.2 nathanw vu_int16_t rhw_reg_data;
143 1.2.4.2 nathanw /* 0x08 */
144 1.2.4.2 nathanw vu_int16_t rhw_fifo_lh;
145 1.2.4.2 nathanw vu_int16_t rhw_fifo_ll;
146 1.2.4.2 nathanw vu_int16_t rhw_fifo_rh;
147 1.2.4.2 nathanw vu_int16_t rhw_fifo_rl;
148 1.2.4.2 nathanw /* 0x10 */
149 1.2.4.2 nathanw vu_int16_t rhw_fifo_pack;
150 1.2.4.2 nathanw vu_int16_t rhw_play_fifosz;
151 1.2.4.2 nathanw vu_int32_t rhw_spdifin_stat;
152 1.2.4.2 nathanw #define rhw_spdifout_stat rhw_spdifin_stat;
153 1.2.4.2 nathanw
154 1.2.4.2 nathanw /* 0x18 */
155 1.2.4.2 nathanw vu_int16_t rhw_capt_fifosz;
156 1.2.4.2 nathanw vu_int16_t rhw_version;
157 1.2.4.2 nathanw vu_int16_t rhw_dummy1;
158 1.2.4.2 nathanw vu_int8_t rhw_firmwareload;
159 1.2.4.2 nathanw /* 0x1F */
160 1.2.4.2 nathanw vu_int8_t rhw_dummy2[66 - 31];
161 1.2.4.2 nathanw /* 0x42 */
162 1.2.4.2 nathanw vu_int16_t rhw_reset;
163 1.2.4.2 nathanw } /* __attribute__((packed)) */;
164 1.2.4.2 nathanw
165 1.2.4.2 nathanw #define REPSTATUS_PLAY 0x0001
166 1.2.4.2 nathanw #define REPSTATUS_RECORD 0x0002
167 1.2.4.2 nathanw #define REPSTATUS_PLAYFIFORST 0x0004
168 1.2.4.2 nathanw #define REPSTATUS_RECFIFORST 0x0008
169 1.2.4.2 nathanw
170 1.2.4.2 nathanw #define REPSTATUS_REGSENDBUSY 0x0010
171 1.2.4.2 nathanw #define REPSTATUS_LOOPBACK 0x0020
172 1.2.4.2 nathanw #define REPSTATUS_ENSPDIFIN 0x0040
173 1.2.4.2 nathanw #define REPSTATUS_ENSPDIFOUT 0x0080
174 1.2.4.2 nathanw
175 1.2.4.2 nathanw #define REPSTATUS_CODECRESET 0x0200
176 1.2.4.2 nathanw #define REPSTATUS_SPDIFOUT24 0x0400
177 1.2.4.2 nathanw #define REPSTATUS_SPDIFIN24 0x0800
178 1.2.4.2 nathanw
179 1.2.4.2 nathanw #define REPSTATUS_RECIRQENABLE 0x1000
180 1.2.4.2 nathanw #define REPSTATUS_RECIRQACK 0x2000
181 1.2.4.2 nathanw #define REPSTATUS_PLAYIRQENABLE 0x4000
182 1.2.4.2 nathanw #define REPSTATUS_PLAYIRQACK 0x8000
183 1.2.4.2 nathanw
184 1.2.4.2 nathanw #define REPFIFO_PLAYFIFOFULL 0x0001
185 1.2.4.2 nathanw #define REPFIFO_PLAYFIFOEMPTY 0x0002
186 1.2.4.2 nathanw #define REPFIFO_RECFIFOFULL 0x0004
187 1.2.4.2 nathanw #define REPFIFO_RECFIFOEMPTY 0x0008
188 1.2.4.2 nathanw #define REPFIFO_PLAYFIFOGAUGE(x) ((x << 4) & 0xf000)
189 1.2.4.2 nathanw #define REPFIFO_RECFIFOGAUGE(x) (x & 0xf000)
190 1.2.4.2 nathanw
191 1.2.4.2 nathanw /* ac97 data stream transfer functions */
192 1.2.4.2 nathanw void rep_read_16_stereo(struct repulse_hw *, u_int8_t *, int, unsigned);
193 1.2.4.2 nathanw void rep_read_16_mono(struct repulse_hw *, u_int8_t *, int, unsigned);
194 1.2.4.2 nathanw void rep_write_16_stereo(struct repulse_hw *, u_int8_t *, int, unsigned);
195 1.2.4.2 nathanw void rep_write_16_mono(struct repulse_hw *, u_int8_t *, int, unsigned);
196 1.2.4.2 nathanw void rep_read_8_stereo(struct repulse_hw *, u_int8_t *, int, unsigned);
197 1.2.4.2 nathanw void rep_read_8_mono(struct repulse_hw *, u_int8_t *, int, unsigned);
198 1.2.4.2 nathanw void rep_write_8_stereo(struct repulse_hw *, u_int8_t *, int, unsigned);
199 1.2.4.2 nathanw void rep_write_8_mono(struct repulse_hw *, u_int8_t *, int, unsigned);
200 1.2.4.2 nathanw
201 1.2.4.2 nathanw /* AmigaDOS Delay() ticks */
202 1.2.4.2 nathanw
203 1.2.4.2 nathanw #define USECPERTICK (1000000/50)
204 1.2.4.2 nathanw
205 1.2.4.2 nathanw /* NetBSD device attachment */
206 1.2.4.2 nathanw
207 1.2.4.2 nathanw struct repulse_softc {
208 1.2.4.2 nathanw struct device sc_dev;
209 1.2.4.2 nathanw struct isr sc_isr;
210 1.2.4.2 nathanw struct ac97_host_if sc_achost;
211 1.2.4.2 nathanw struct ac97_codec_if *sc_codec_if;
212 1.2.4.2 nathanw
213 1.2.4.2 nathanw struct repulse_hw *sc_boardp;
214 1.2.4.2 nathanw
215 1.2.4.2 nathanw void (*sc_captmore)(void *);
216 1.2.4.2 nathanw void *sc_captarg;
217 1.2.4.2 nathanw
218 1.2.4.2 nathanw void (*sc_captfun)(struct repulse_hw *, u_int8_t *, int, unsigned);
219 1.2.4.2 nathanw void *sc_captbuf;
220 1.2.4.2 nathanw int sc_captscale;
221 1.2.4.2 nathanw int sc_captbufsz;
222 1.2.4.2 nathanw unsigned sc_captflags;
223 1.2.4.2 nathanw
224 1.2.4.2 nathanw
225 1.2.4.2 nathanw void (*sc_playmore)(void *);
226 1.2.4.2 nathanw void *sc_playarg;
227 1.2.4.2 nathanw void (*sc_playfun)(struct repulse_hw *, u_int8_t *, int, unsigned);
228 1.2.4.2 nathanw int sc_playscale;
229 1.2.4.2 nathanw unsigned sc_playflags;
230 1.2.4.2 nathanw
231 1.2.4.2 nathanw };
232 1.2.4.2 nathanw
233 1.2.4.2 nathanw int repulse_match (struct device *, struct cfdata *, void *);
234 1.2.4.2 nathanw void repulse_attach (struct device *, struct device *, void *);
235 1.2.4.2 nathanw
236 1.2.4.3 nathanw CFATTACH_DECL(repulse, sizeof(struct repulse_softc),
237 1.2.4.3 nathanw repulse_match, repulse_attach, NULL, NULL);
238 1.2.4.2 nathanw
239 1.2.4.2 nathanw int
240 1.2.4.2 nathanw repulse_match(struct device *parent, struct cfdata *cfp, void *aux) {
241 1.2.4.2 nathanw struct zbus_args *zap;
242 1.2.4.2 nathanw
243 1.2.4.2 nathanw zap = aux;
244 1.2.4.2 nathanw
245 1.2.4.2 nathanw if (zap->manid != 0x4144)
246 1.2.4.2 nathanw return (0);
247 1.2.4.2 nathanw
248 1.2.4.2 nathanw if (zap->prodid != 0)
249 1.2.4.2 nathanw return (0);
250 1.2.4.2 nathanw
251 1.2.4.2 nathanw return (1);
252 1.2.4.2 nathanw }
253 1.2.4.2 nathanw
254 1.2.4.2 nathanw void
255 1.2.4.2 nathanw repulse_attach(struct device *parent, struct device *self, void *aux) {
256 1.2.4.2 nathanw struct repulse_softc *sc;
257 1.2.4.2 nathanw struct zbus_args *zap;
258 1.2.4.2 nathanw struct repulse_hw *bp;
259 1.2.4.2 nathanw struct mixer_ctrl ctl;
260 1.2.4.2 nathanw u_int8_t *fwp;
261 1.2.4.2 nathanw int needs_firmware;
262 1.2.4.2 nathanw int i;
263 1.2.4.2 nathanw
264 1.2.4.2 nathanw u_int16_t a;
265 1.2.4.2 nathanw
266 1.2.4.2 nathanw sc = (struct repulse_softc *)self;
267 1.2.4.2 nathanw zap = aux;
268 1.2.4.2 nathanw bp = (struct repulse_hw *)zap->va;
269 1.2.4.2 nathanw sc->sc_boardp = bp;
270 1.2.4.2 nathanw
271 1.2.4.2 nathanw needs_firmware = 0;
272 1.2.4.2 nathanw if (bp->rhw_fifostatus & 0x00f0)
273 1.2.4.2 nathanw needs_firmware = 1;
274 1.2.4.2 nathanw else {
275 1.2.4.2 nathanw bp->rhw_status = 0x000c;
276 1.2.4.2 nathanw if (bp->rhw_status != 0 || bp->rhw_fifostatus != 0x0f0a)
277 1.2.4.2 nathanw needs_firmware = 1;
278 1.2.4.2 nathanw }
279 1.2.4.2 nathanw
280 1.2.4.2 nathanw printf(": ");
281 1.2.4.2 nathanw if (needs_firmware) {
282 1.2.4.2 nathanw printf("loading ");
283 1.2.4.2 nathanw bp->rhw_reset = 0;
284 1.2.4.2 nathanw
285 1.2.4.2 nathanw delay(1 * USECPERTICK);
286 1.2.4.2 nathanw
287 1.2.4.2 nathanw for (fwp = (u_int8_t *)repulse_firmware;
288 1.2.4.2 nathanw fwp < (repulse_firmware_size +
289 1.2.4.2 nathanw (u_int8_t *)repulse_firmware); fwp++)
290 1.2.4.2 nathanw bp->rhw_firmwareload = *fwp;
291 1.2.4.2 nathanw
292 1.2.4.2 nathanw delay(1 * USECPERTICK);
293 1.2.4.2 nathanw
294 1.2.4.2 nathanw if (bp->rhw_fifostatus & 0x00f0)
295 1.2.4.2 nathanw goto Initerr;
296 1.2.4.2 nathanw
297 1.2.4.2 nathanw a = /* bp->rhw_status;
298 1.2.4.2 nathanw a |= */ REPSTATUS_CODECRESET;
299 1.2.4.2 nathanw bp->rhw_status = a;
300 1.2.4.2 nathanw
301 1.2.4.2 nathanw a = bp->rhw_status;
302 1.2.4.2 nathanw if ((a & REPSTATUS_CODECRESET) == 0)
303 1.2.4.2 nathanw goto Initerr;
304 1.2.4.2 nathanw
305 1.2.4.2 nathanw (void)bp->rhw_status;
306 1.2.4.2 nathanw (void)bp->rhw_status;
307 1.2.4.2 nathanw (void)bp->rhw_status;
308 1.2.4.2 nathanw a = bp->rhw_status;
309 1.2.4.2 nathanw a &= ~REPSTATUS_CODECRESET;
310 1.2.4.2 nathanw bp->rhw_status = a;
311 1.2.4.2 nathanw }
312 1.2.4.2 nathanw
313 1.2.4.2 nathanw printf("firmware version 0x%x\n", bp->rhw_version);
314 1.2.4.2 nathanw
315 1.2.4.2 nathanw sc->sc_achost.arg = sc;
316 1.2.4.2 nathanw
317 1.2.4.2 nathanw sc->sc_achost.reset = repac_reset;
318 1.2.4.2 nathanw sc->sc_achost.read = repac_read;
319 1.2.4.2 nathanw sc->sc_achost.write = repac_write;
320 1.2.4.2 nathanw sc->sc_achost.attach = repac_attach;
321 1.2.4.2 nathanw sc->sc_achost.flags = 0;
322 1.2.4.2 nathanw
323 1.2.4.2 nathanw if (ac97_attach(&sc->sc_achost)) {
324 1.2.4.2 nathanw printf("%s: error attaching codec\n", self->dv_xname);
325 1.2.4.2 nathanw return;
326 1.2.4.2 nathanw }
327 1.2.4.2 nathanw
328 1.2.4.2 nathanw #ifdef DIAGNOSTIC
329 1.2.4.2 nathanw /*
330 1.2.4.2 nathanw * Print a warning if the codec doesn't support hardware variable
331 1.2.4.2 nathanw * rate audio. As the initial incarnations of the Repulse board
332 1.2.4.2 nathanw * are AC'97 2.1, it is epxected that we'll always have VRA.
333 1.2.4.2 nathanw */
334 1.2.4.2 nathanw /*
335 1.2.4.2 nathanw * XXX this should be a panic(). OTOH, audio codec speed is not
336 1.2.4.2 nathanw * important enough to do this.
337 1.2.4.2 nathanw */
338 1.2.4.3 nathanw a = sc->sc_codec_if->vtbl->get_extcaps(sc->sc_codec_if);
339 1.2.4.3 nathanw if (!(a & AC97_EXT_AUDIO_VRA)) {
340 1.2.4.2 nathanw printf("%s: warning: codec doesn't support "
341 1.2.4.2 nathanw "hardware AC'97 2.0 Variable Rate Audio\n",
342 1.2.4.2 nathanw sc->sc_dev.dv_xname);
343 1.2.4.2 nathanw }
344 1.2.4.2 nathanw #endif
345 1.2.4.2 nathanw
346 1.2.4.2 nathanw /*
347 1.2.4.2 nathanw * from auvia.c: disable mutes ...
348 1.2.4.2 nathanw * XXX maybe this should happen in MI code?
349 1.2.4.2 nathanw */
350 1.2.4.2 nathanw
351 1.2.4.2 nathanw for (i = 0; i < 5; i++) {
352 1.2.4.2 nathanw static struct {
353 1.2.4.2 nathanw char *class, *device;
354 1.2.4.2 nathanw } d[] = {
355 1.2.4.2 nathanw { AudioCoutputs, AudioNmaster},
356 1.2.4.2 nathanw { AudioCinputs, AudioNdac},
357 1.2.4.2 nathanw { AudioCinputs, AudioNcd},
358 1.2.4.2 nathanw { AudioCinputs, AudioNline},
359 1.2.4.2 nathanw { AudioCrecord, AudioNvolume},
360 1.2.4.2 nathanw };
361 1.2.4.2 nathanw
362 1.2.4.2 nathanw ctl.type = AUDIO_MIXER_ENUM;
363 1.2.4.2 nathanw ctl.un.ord = 0;
364 1.2.4.2 nathanw ctl.dev = sc->sc_codec_if->vtbl->get_portnum_by_name(
365 1.2.4.2 nathanw sc->sc_codec_if, d[i].class, d[i].device, AudioNmute);
366 1.2.4.2 nathanw rep_set_port(sc, &ctl);
367 1.2.4.2 nathanw }
368 1.2.4.2 nathanw
369 1.2.4.2 nathanw sc->sc_isr.isr_ipl = 2;
370 1.2.4.2 nathanw sc->sc_isr.isr_arg = sc;
371 1.2.4.2 nathanw sc->sc_isr.isr_intr = rep_intr;
372 1.2.4.2 nathanw add_isr(&sc->sc_isr);
373 1.2.4.2 nathanw
374 1.2.4.2 nathanw audio_attach_mi(&rep_hw_if, sc, &sc->sc_dev);
375 1.2.4.2 nathanw
376 1.2.4.2 nathanw return;
377 1.2.4.2 nathanw
378 1.2.4.2 nathanw Initerr:
379 1.2.4.2 nathanw printf("\n%s: firmware not successfully loaded\n", self->dv_xname);
380 1.2.4.2 nathanw return;
381 1.2.4.2 nathanw
382 1.2.4.2 nathanw }
383 1.2.4.2 nathanw
384 1.2.4.2 nathanw void repac_reset(void *arg) {
385 1.2.4.2 nathanw struct repulse_softc *sc = arg;
386 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
387 1.2.4.2 nathanw
388 1.2.4.2 nathanw u_int16_t a;
389 1.2.4.2 nathanw
390 1.2.4.2 nathanw a = bp->rhw_status;
391 1.2.4.2 nathanw a |= REPSTATUS_CODECRESET;
392 1.2.4.2 nathanw bp->rhw_status = a;
393 1.2.4.2 nathanw
394 1.2.4.2 nathanw a = bp->rhw_status;
395 1.2.4.2 nathanw #ifdef DIAGNOSTIC
396 1.2.4.2 nathanw if ((a & REPSTATUS_CODECRESET) == 0)
397 1.2.4.2 nathanw panic("%s: cannot set reset bit", sc->sc_dev.dv_xname);
398 1.2.4.2 nathanw #endif
399 1.2.4.2 nathanw
400 1.2.4.2 nathanw a = bp->rhw_status;
401 1.2.4.2 nathanw a = bp->rhw_status;
402 1.2.4.2 nathanw a = bp->rhw_status;
403 1.2.4.2 nathanw a = bp->rhw_status;
404 1.2.4.2 nathanw a &= ~REPSTATUS_CODECRESET;
405 1.2.4.2 nathanw bp->rhw_status = a;
406 1.2.4.2 nathanw }
407 1.2.4.2 nathanw
408 1.2.4.2 nathanw int repac_read(void *arg, u_int8_t reg, u_int16_t *valuep) {
409 1.2.4.2 nathanw struct repulse_softc *sc = arg;
410 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
411 1.2.4.2 nathanw
412 1.2.4.2 nathanw while (bp->rhw_status & REPSTATUS_REGSENDBUSY);
413 1.2.4.2 nathanw bp->rhw_reg_address = (reg & 0x7F) | 0x80;
414 1.2.4.2 nathanw
415 1.2.4.2 nathanw while (bp->rhw_status & REPSTATUS_REGSENDBUSY);
416 1.2.4.2 nathanw
417 1.2.4.2 nathanw *valuep = bp->rhw_reg_data;
418 1.2.4.2 nathanw
419 1.2.4.2 nathanw return 0;
420 1.2.4.2 nathanw }
421 1.2.4.2 nathanw
422 1.2.4.2 nathanw int repac_write(void *arg, u_int8_t reg, u_int16_t value) {
423 1.2.4.2 nathanw struct repulse_softc *sc = arg;
424 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
425 1.2.4.2 nathanw
426 1.2.4.2 nathanw bp->rhw_reg_data = value;
427 1.2.4.2 nathanw bp->rhw_reg_address = reg & 0x7F;
428 1.2.4.2 nathanw
429 1.2.4.2 nathanw while (bp->rhw_status & REPSTATUS_REGSENDBUSY);
430 1.2.4.2 nathanw
431 1.2.4.2 nathanw return 0;
432 1.2.4.2 nathanw }
433 1.2.4.2 nathanw
434 1.2.4.2 nathanw int repac_attach(void *arg, struct ac97_codec_if *acip){
435 1.2.4.2 nathanw
436 1.2.4.2 nathanw struct repulse_softc *sc;
437 1.2.4.2 nathanw
438 1.2.4.2 nathanw sc = arg;
439 1.2.4.2 nathanw sc->sc_codec_if = acip;
440 1.2.4.2 nathanw
441 1.2.4.2 nathanw return 0;
442 1.2.4.2 nathanw }
443 1.2.4.2 nathanw
444 1.2.4.2 nathanw /* audio(9) support stuff which is not ac97-constant */
445 1.2.4.2 nathanw
446 1.2.4.2 nathanw int
447 1.2.4.2 nathanw rep_open(void *arg, int flags)
448 1.2.4.2 nathanw {
449 1.2.4.2 nathanw return 0;
450 1.2.4.2 nathanw }
451 1.2.4.2 nathanw
452 1.2.4.2 nathanw void
453 1.2.4.2 nathanw rep_close(void *arg)
454 1.2.4.2 nathanw {
455 1.2.4.2 nathanw struct repulse_softc *sc = arg;
456 1.2.4.2 nathanw
457 1.2.4.2 nathanw rep_halt_output(sc);
458 1.2.4.2 nathanw rep_halt_input(sc);
459 1.2.4.2 nathanw }
460 1.2.4.2 nathanw
461 1.2.4.2 nathanw int
462 1.2.4.2 nathanw rep_getdev(void *arg, struct audio_device *retp)
463 1.2.4.2 nathanw {
464 1.2.4.2 nathanw struct repulse_softc *sc = arg;
465 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
466 1.2.4.2 nathanw
467 1.2.4.2 nathanw if (retp) {
468 1.2.4.2 nathanw strncpy(retp->name, "Repulse", sizeof(retp->name));
469 1.2.4.2 nathanw snprintf(retp->version, sizeof(retp->version), "0x%x",
470 1.2.4.2 nathanw bp->rhw_version);
471 1.2.4.2 nathanw strncpy(retp->config, "", sizeof(retp->config));
472 1.2.4.2 nathanw }
473 1.2.4.2 nathanw
474 1.2.4.2 nathanw return 0;
475 1.2.4.2 nathanw }
476 1.2.4.2 nathanw
477 1.2.4.2 nathanw int
478 1.2.4.2 nathanw rep_get_props(void *v)
479 1.2.4.2 nathanw {
480 1.2.4.2 nathanw return (AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX);
481 1.2.4.2 nathanw }
482 1.2.4.2 nathanw
483 1.2.4.2 nathanw int
484 1.2.4.2 nathanw rep_halt_output(void *arg)
485 1.2.4.2 nathanw {
486 1.2.4.2 nathanw struct repulse_softc *sc = arg;
487 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
488 1.2.4.2 nathanw
489 1.2.4.2 nathanw bp->rhw_status &= ~(REPSTATUS_PLAYIRQENABLE|REPSTATUS_PLAY);
490 1.2.4.2 nathanw
491 1.2.4.2 nathanw
492 1.2.4.2 nathanw return 0;
493 1.2.4.2 nathanw }
494 1.2.4.2 nathanw
495 1.2.4.2 nathanw int
496 1.2.4.2 nathanw rep_halt_input(void *arg)
497 1.2.4.2 nathanw {
498 1.2.4.2 nathanw struct repulse_softc *sc = arg;
499 1.2.4.2 nathanw struct repulse_hw *bp = sc->sc_boardp;
500 1.2.4.2 nathanw
501 1.2.4.2 nathanw bp->rhw_status &= ~(REPSTATUS_RECIRQENABLE|REPSTATUS_RECORD);
502 1.2.4.2 nathanw
503 1.2.4.2 nathanw return 0;
504 1.2.4.2 nathanw }
505 1.2.4.2 nathanw
506 1.2.4.2 nathanw /*
507 1.2.4.2 nathanw * Encoding support.
508 1.2.4.2 nathanw *
509 1.2.4.2 nathanw * TODO: add 24bit and 32bit modes here and in setparams.
510 1.2.4.2 nathanw */
511 1.2.4.2 nathanw
512 1.2.4.2 nathanw const struct repulse_encoding_query {
513 1.2.4.2 nathanw const char *name;
514 1.2.4.2 nathanw int encoding, precision, flags;
515 1.2.4.2 nathanw } rep_encoding_queries[] = {
516 1.2.4.2 nathanw { AudioEulinear, AUDIO_ENCODING_ULINEAR, 8, 0},
517 1.2.4.2 nathanw { AudioEmulaw, AUDIO_ENCODING_ULAW, 8, AUDIO_ENCODINGFLAG_EMULATED},
518 1.2.4.2 nathanw { AudioEalaw, AUDIO_ENCODING_ALAW, 8, AUDIO_ENCODINGFLAG_EMULATED},
519 1.2.4.2 nathanw { AudioEslinear, AUDIO_ENCODING_SLINEAR, 8, 0},
520 1.2.4.2 nathanw { AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE, 16, 0},
521 1.2.4.2 nathanw { AudioEulinear_le, AUDIO_ENCODING_ULINEAR_LE, 16, 0},
522 1.2.4.2 nathanw { AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE, 16, 0},
523 1.2.4.2 nathanw { AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE, 16, 0},
524 1.2.4.2 nathanw };
525 1.2.4.2 nathanw
526 1.2.4.2 nathanw int
527 1.2.4.2 nathanw rep_query_encoding(void *arg, struct audio_encoding *fp)
528 1.2.4.2 nathanw {
529 1.2.4.2 nathanw int i;
530 1.2.4.2 nathanw const struct repulse_encoding_query *p;
531 1.2.4.2 nathanw
532 1.2.4.2 nathanw i = fp->index;
533 1.2.4.2 nathanw
534 1.2.4.2 nathanw if (i >= sizeof(rep_encoding_queries) /
535 1.2.4.2 nathanw sizeof(struct repulse_encoding_query))
536 1.2.4.2 nathanw return (EINVAL);
537 1.2.4.2 nathanw
538 1.2.4.2 nathanw p = &rep_encoding_queries[i];
539 1.2.4.2 nathanw
540 1.2.4.2 nathanw strncpy (fp->name, p->name, sizeof(fp->name));
541 1.2.4.2 nathanw fp->encoding = p->encoding;
542 1.2.4.2 nathanw fp->precision = p->precision;
543 1.2.4.2 nathanw fp->flags = p->flags;
544 1.2.4.2 nathanw
545 1.2.4.2 nathanw return (0);
546 1.2.4.2 nathanw }
547 1.2.4.2 nathanw
548 1.2.4.2 nathanw /*
549 1.2.4.2 nathanw * XXX the following three functions need to be enhanced for the FPGA s/pdif
550 1.2.4.2 nathanw * mode. Generic ac97 versions for now.
551 1.2.4.2 nathanw */
552 1.2.4.2 nathanw
553 1.2.4.2 nathanw int
554 1.2.4.2 nathanw rep_get_port(void *arg, mixer_ctrl_t *cp)
555 1.2.4.2 nathanw {
556 1.2.4.2 nathanw struct repulse_softc *sc = arg;
557 1.2.4.2 nathanw
558 1.2.4.2 nathanw return (sc->sc_codec_if->vtbl->mixer_get_port(sc->sc_codec_if, cp));
559 1.2.4.2 nathanw }
560 1.2.4.2 nathanw
561 1.2.4.2 nathanw int
562 1.2.4.2 nathanw rep_set_port(void *arg, mixer_ctrl_t *cp)
563 1.2.4.2 nathanw {
564 1.2.4.2 nathanw struct repulse_softc *sc = arg;
565 1.2.4.2 nathanw
566 1.2.4.2 nathanw return (sc->sc_codec_if->vtbl->mixer_set_port(sc->sc_codec_if, cp));
567 1.2.4.2 nathanw }
568 1.2.4.2 nathanw
569 1.2.4.2 nathanw int
570 1.2.4.2 nathanw rep_query_devinfo (void *arg, mixer_devinfo_t *dip)
571 1.2.4.2 nathanw {
572 1.2.4.2 nathanw struct repulse_softc *sc = arg;
573 1.2.4.2 nathanw
574 1.2.4.2 nathanw return (sc->sc_codec_if->vtbl->query_devinfo(sc->sc_codec_if, dip));
575 1.2.4.2 nathanw }
576 1.2.4.2 nathanw
577 1.2.4.2 nathanw int
578 1.2.4.2 nathanw rep_round_blocksize(void *arg, int blk)
579 1.2.4.2 nathanw {
580 1.2.4.2 nathanw int b1;
581 1.2.4.2 nathanw
582 1.2.4.2 nathanw b1 = (blk & -32);
583 1.2.4.2 nathanw
584 1.2.4.2 nathanw if (b1 > 65536 / 2 / 2 /* channels */ / 4 /* bytes per channel */)
585 1.2.4.2 nathanw b1 = 65536 / 2 / 2 / 4;
586 1.2.4.2 nathanw return (b1);
587 1.2.4.2 nathanw }
588 1.2.4.2 nathanw
589 1.2.4.2 nathanw size_t
590 1.2.4.2 nathanw rep_round_buffersize(void *arg, int direction, size_t size)
591 1.2.4.2 nathanw {
592 1.2.4.2 nathanw return size;
593 1.2.4.2 nathanw }
594 1.2.4.2 nathanw
595 1.2.4.2 nathanw
596 1.2.4.2 nathanw int
597 1.2.4.2 nathanw rep_set_params(void *addr, int setmode, int usemode,
598 1.2.4.2 nathanw struct audio_params *play, struct audio_params *rec)
599 1.2.4.2 nathanw {
600 1.2.4.2 nathanw struct repulse_softc *sc = addr;
601 1.2.4.2 nathanw struct audio_params *p;
602 1.2.4.2 nathanw int mode, reg;
603 1.2.4.2 nathanw unsigned flags;
604 1.2.4.2 nathanw u_int16_t a;
605 1.2.4.2 nathanw
606 1.2.4.2 nathanw /* for mode in (RECORD, PLAY) */
607 1.2.4.2 nathanw for (mode = AUMODE_RECORD; mode != -1;
608 1.2.4.2 nathanw mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
609 1.2.4.2 nathanw
610 1.2.4.2 nathanw if ((setmode & mode) == 0)
611 1.2.4.2 nathanw continue;
612 1.2.4.2 nathanw
613 1.2.4.2 nathanw p = mode == AUMODE_PLAY ? play : rec;
614 1.2.4.2 nathanw
615 1.2.4.2 nathanw /* TODO XXX we can do upto 32bit, 96000 */
616 1.2.4.2 nathanw if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
617 1.2.4.2 nathanw (p->precision != 8 && p->precision != 16) ||
618 1.2.4.2 nathanw (p->channels != 1 && p->channels != 2))
619 1.2.4.2 nathanw return (EINVAL);
620 1.2.4.2 nathanw
621 1.2.4.2 nathanw reg = mode == AUMODE_PLAY ?
622 1.2.4.2 nathanw AC97_REG_PCM_FRONT_DAC_RATE : AC97_REG_PCM_LR_ADC_RATE;
623 1.2.4.2 nathanw
624 1.2.4.2 nathanw repac_write(sc, reg, (u_int16_t) p->sample_rate);
625 1.2.4.2 nathanw repac_read(sc, reg, &a);
626 1.2.4.2 nathanw p->sample_rate = a;
627 1.2.4.2 nathanw
628 1.2.4.2 nathanw if (mode == AUMODE_PLAY)
629 1.2.4.2 nathanw sc->sc_playscale = p->channels * p->precision / 8;
630 1.2.4.2 nathanw else
631 1.2.4.2 nathanw sc->sc_captscale = p->channels * p->precision / 8;
632 1.2.4.2 nathanw
633 1.2.4.2 nathanw p->factor = 1;
634 1.2.4.2 nathanw p->sw_code = 0;
635 1.2.4.2 nathanw
636 1.2.4.2 nathanw /* everything else is software, alas... */
637 1.2.4.2 nathanw /* XXX TBD signed/unsigned, *law, etc */
638 1.2.4.2 nathanw
639 1.2.4.2 nathanw flags = 0;
640 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_ULINEAR_LE ||
641 1.2.4.2 nathanw p->encoding == AUDIO_ENCODING_ULINEAR_BE ||
642 1.2.4.2 nathanw p->encoding == AUDIO_ENCODING_ULINEAR)
643 1.2.4.2 nathanw flags |= 1;
644 1.2.4.2 nathanw
645 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_SLINEAR_LE ||
646 1.2.4.2 nathanw p->encoding == AUDIO_ENCODING_ULINEAR_LE)
647 1.2.4.2 nathanw flags |= 2;
648 1.2.4.2 nathanw
649 1.2.4.2 nathanw if (mode == AUMODE_PLAY) {
650 1.2.4.2 nathanw sc->sc_playflags = flags;
651 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_ULAW) {
652 1.2.4.2 nathanw sc->sc_playfun = p->channels == 1 ?
653 1.2.4.2 nathanw rep_write_16_mono :
654 1.2.4.2 nathanw rep_write_16_stereo;
655 1.2.4.2 nathanw sc->sc_playflags = 0;
656 1.2.4.2 nathanw sc->sc_playscale = p->channels * 2;
657 1.2.4.2 nathanw p->sw_code = mulaw_to_slinear16_be;
658 1.2.4.2 nathanw p->factor = 2;
659 1.2.4.2 nathanw } else
660 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_ALAW) {
661 1.2.4.2 nathanw sc->sc_playfun = p->channels == 1 ?
662 1.2.4.2 nathanw rep_write_16_mono :
663 1.2.4.2 nathanw rep_write_16_stereo;
664 1.2.4.2 nathanw sc->sc_playflags = 0;
665 1.2.4.2 nathanw sc->sc_playscale = p->channels * 2;
666 1.2.4.2 nathanw p->sw_code = alaw_to_slinear16_be;
667 1.2.4.2 nathanw p->factor = 2;
668 1.2.4.2 nathanw } else
669 1.2.4.2 nathanw if (p->precision == 8 && p->channels == 1)
670 1.2.4.2 nathanw sc->sc_playfun = rep_write_8_mono;
671 1.2.4.2 nathanw else if (p->precision == 8 && p->channels == 2)
672 1.2.4.2 nathanw sc->sc_playfun = rep_write_8_stereo;
673 1.2.4.2 nathanw else if (p->precision == 16 && p->channels == 1)
674 1.2.4.2 nathanw sc->sc_playfun = rep_write_16_mono;
675 1.2.4.2 nathanw else if (p->precision == 16 && p->channels == 2)
676 1.2.4.2 nathanw sc->sc_playfun = rep_write_16_stereo;
677 1.2.4.2 nathanw } else {
678 1.2.4.2 nathanw sc->sc_captflags = flags;
679 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_ULAW) {
680 1.2.4.2 nathanw sc->sc_captfun = p->channels == 1 ?
681 1.2.4.2 nathanw rep_read_8_mono :
682 1.2.4.2 nathanw rep_read_8_stereo;
683 1.2.4.2 nathanw sc->sc_captflags = 0;
684 1.2.4.2 nathanw p->sw_code = slinear8_to_mulaw;
685 1.2.4.2 nathanw p->factor = 1;
686 1.2.4.2 nathanw } else
687 1.2.4.2 nathanw if (p->encoding == AUDIO_ENCODING_ALAW) {
688 1.2.4.2 nathanw sc->sc_captfun = p->channels == 1 ?
689 1.2.4.2 nathanw rep_read_8_mono :
690 1.2.4.2 nathanw rep_read_8_stereo;
691 1.2.4.2 nathanw sc->sc_captflags = 0;
692 1.2.4.2 nathanw p->sw_code = slinear8_to_alaw;
693 1.2.4.2 nathanw p->factor = 1;
694 1.2.4.2 nathanw } else
695 1.2.4.2 nathanw if (p->precision == 8 && p->channels == 1)
696 1.2.4.2 nathanw sc->sc_captfun = rep_read_8_mono;
697 1.2.4.2 nathanw else if (p->precision == 8 && p->channels == 2)
698 1.2.4.2 nathanw sc->sc_captfun = rep_read_8_stereo;
699 1.2.4.2 nathanw else if (p->precision == 16 && p->channels == 1)
700 1.2.4.2 nathanw sc->sc_captfun = rep_read_16_mono;
701 1.2.4.2 nathanw else if (p->precision == 16 && p->channels == 2)
702 1.2.4.2 nathanw sc->sc_captfun = rep_read_16_stereo;
703 1.2.4.2 nathanw }
704 1.2.4.2 nathanw /* TBD: ulaw, alaw */
705 1.2.4.2 nathanw }
706 1.2.4.2 nathanw return 0;
707 1.2.4.2 nathanw }
708 1.2.4.2 nathanw
709 1.2.4.2 nathanw void
710 1.2.4.2 nathanw rep_write_8_mono(struct repulse_hw *bp, u_int8_t *p, int length,
711 1.2.4.2 nathanw unsigned flags)
712 1.2.4.2 nathanw {
713 1.2.4.2 nathanw u_int16_t sample;
714 1.2.4.2 nathanw u_int16_t xor;
715 1.2.4.2 nathanw
716 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
717 1.2.4.2 nathanw
718 1.2.4.2 nathanw bp->rhw_fifo_pack = 0;
719 1.2.4.2 nathanw
720 1.2.4.2 nathanw while (length-- > 0) {
721 1.2.4.2 nathanw sample = ((*p++) << 8) ^ xor;
722 1.2.4.2 nathanw bp->rhw_fifo_lh = sample;
723 1.2.4.2 nathanw bp->rhw_fifo_rh = sample;
724 1.2.4.2 nathanw }
725 1.2.4.2 nathanw }
726 1.2.4.2 nathanw
727 1.2.4.2 nathanw void
728 1.2.4.2 nathanw rep_write_8_stereo(struct repulse_hw *bp, u_int8_t *p, int length,
729 1.2.4.2 nathanw unsigned flags)
730 1.2.4.2 nathanw {
731 1.2.4.2 nathanw u_int16_t xor;
732 1.2.4.2 nathanw
733 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
734 1.2.4.2 nathanw
735 1.2.4.2 nathanw bp->rhw_fifo_pack = 0;
736 1.2.4.2 nathanw
737 1.2.4.2 nathanw while (length-- > 0) {
738 1.2.4.2 nathanw bp->rhw_fifo_lh = ((*p++) << 8) ^ xor;
739 1.2.4.2 nathanw bp->rhw_fifo_rh = ((*p++) << 8) ^ xor;
740 1.2.4.2 nathanw }
741 1.2.4.2 nathanw }
742 1.2.4.2 nathanw
743 1.2.4.2 nathanw void
744 1.2.4.2 nathanw rep_write_16_mono(struct repulse_hw *bp, u_int8_t *p, int length,
745 1.2.4.2 nathanw unsigned flags)
746 1.2.4.2 nathanw {
747 1.2.4.2 nathanw u_int16_t *q = (u_int16_t *)p;
748 1.2.4.2 nathanw u_int16_t sample;
749 1.2.4.2 nathanw u_int16_t xor;
750 1.2.4.2 nathanw
751 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
752 1.2.4.2 nathanw
753 1.2.4.2 nathanw bp->rhw_fifo_pack = 0;
754 1.2.4.2 nathanw
755 1.2.4.2 nathanw if (flags & 2) {
756 1.2.4.2 nathanw while (length > 0) {
757 1.2.4.2 nathanw sample = bswap16(*q++) ^ xor;
758 1.2.4.2 nathanw bp->rhw_fifo_lh = sample;
759 1.2.4.2 nathanw bp->rhw_fifo_rh = sample;
760 1.2.4.2 nathanw length -= 2;
761 1.2.4.2 nathanw }
762 1.2.4.2 nathanw return;
763 1.2.4.2 nathanw }
764 1.2.4.2 nathanw
765 1.2.4.2 nathanw while (length > 0) {
766 1.2.4.2 nathanw sample = (*q++) ^ xor;
767 1.2.4.2 nathanw bp->rhw_fifo_lh = sample;
768 1.2.4.2 nathanw bp->rhw_fifo_rh = sample;
769 1.2.4.2 nathanw length -= 2;
770 1.2.4.2 nathanw }
771 1.2.4.2 nathanw }
772 1.2.4.2 nathanw
773 1.2.4.2 nathanw void
774 1.2.4.2 nathanw rep_write_16_stereo(struct repulse_hw *bp, u_int8_t *p, int length,
775 1.2.4.2 nathanw unsigned flags)
776 1.2.4.2 nathanw {
777 1.2.4.2 nathanw u_int16_t *q = (u_int16_t *)p;
778 1.2.4.2 nathanw u_int16_t xor;
779 1.2.4.2 nathanw
780 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
781 1.2.4.2 nathanw
782 1.2.4.2 nathanw bp->rhw_fifo_pack = 0;
783 1.2.4.2 nathanw
784 1.2.4.2 nathanw if (flags & 2) {
785 1.2.4.2 nathanw while (length > 0) {
786 1.2.4.2 nathanw bp->rhw_fifo_lh = bswap16(*q++) ^ xor;
787 1.2.4.2 nathanw bp->rhw_fifo_rh = bswap16(*q++) ^ xor;
788 1.2.4.2 nathanw length -= 4;
789 1.2.4.2 nathanw }
790 1.2.4.2 nathanw return;
791 1.2.4.2 nathanw }
792 1.2.4.2 nathanw while (length > 0) {
793 1.2.4.2 nathanw bp->rhw_fifo_lh = (*q++) ^ xor;
794 1.2.4.2 nathanw bp->rhw_fifo_rh = (*q++) ^ xor;
795 1.2.4.2 nathanw length -= 4;
796 1.2.4.2 nathanw }
797 1.2.4.2 nathanw }
798 1.2.4.2 nathanw
799 1.2.4.2 nathanw void
800 1.2.4.2 nathanw rep_read_8_mono(struct repulse_hw *bp, u_int8_t *p, int length,
801 1.2.4.2 nathanw unsigned flags)
802 1.2.4.2 nathanw {
803 1.2.4.2 nathanw u_int16_t v;
804 1.2.4.2 nathanw u_int16_t xor;
805 1.2.4.2 nathanw
806 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
807 1.2.4.2 nathanw
808 1.2.4.2 nathanw while (length > 0) {
809 1.2.4.2 nathanw *p++ = (bp->rhw_fifo_lh ^ xor) >> 8;
810 1.2.4.2 nathanw v = bp->rhw_fifo_rh;
811 1.2.4.2 nathanw length--;
812 1.2.4.2 nathanw }
813 1.2.4.2 nathanw }
814 1.2.4.2 nathanw
815 1.2.4.2 nathanw void
816 1.2.4.2 nathanw rep_read_16_mono(struct repulse_hw *bp, u_int8_t *p, int length,
817 1.2.4.2 nathanw unsigned flags)
818 1.2.4.2 nathanw {
819 1.2.4.2 nathanw u_int16_t *q = (u_int16_t *)p;
820 1.2.4.2 nathanw u_int16_t v;
821 1.2.4.2 nathanw u_int16_t xor;
822 1.2.4.2 nathanw
823 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
824 1.2.4.2 nathanw
825 1.2.4.2 nathanw if (flags & 2) {
826 1.2.4.2 nathanw while (length > 0) {
827 1.2.4.2 nathanw *q++ = bswap16(bp->rhw_fifo_lh ^ xor);
828 1.2.4.2 nathanw v = bp->rhw_fifo_rh;
829 1.2.4.2 nathanw length -= 2;
830 1.2.4.2 nathanw }
831 1.2.4.2 nathanw return;
832 1.2.4.2 nathanw }
833 1.2.4.2 nathanw
834 1.2.4.2 nathanw while (length > 0) {
835 1.2.4.2 nathanw *q++ = bp->rhw_fifo_lh ^ xor;
836 1.2.4.2 nathanw v = bp->rhw_fifo_rh;
837 1.2.4.2 nathanw length -= 2;
838 1.2.4.2 nathanw }
839 1.2.4.2 nathanw }
840 1.2.4.2 nathanw
841 1.2.4.2 nathanw void
842 1.2.4.2 nathanw rep_read_8_stereo(struct repulse_hw *bp, u_int8_t *p, int length,
843 1.2.4.2 nathanw unsigned flags)
844 1.2.4.2 nathanw {
845 1.2.4.2 nathanw u_int16_t xor;
846 1.2.4.2 nathanw
847 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
848 1.2.4.2 nathanw while (length > 0) {
849 1.2.4.2 nathanw *p++ = (bp->rhw_fifo_lh ^ xor) >> 8;
850 1.2.4.2 nathanw *p++ = (bp->rhw_fifo_rh ^ xor) >> 8;
851 1.2.4.2 nathanw length -= 2;
852 1.2.4.2 nathanw }
853 1.2.4.2 nathanw }
854 1.2.4.2 nathanw
855 1.2.4.2 nathanw void
856 1.2.4.2 nathanw rep_read_16_stereo(struct repulse_hw *bp, u_int8_t *p, int length,
857 1.2.4.2 nathanw unsigned flags)
858 1.2.4.2 nathanw {
859 1.2.4.2 nathanw u_int16_t *q = (u_int16_t *)p;
860 1.2.4.2 nathanw u_int16_t xor;
861 1.2.4.2 nathanw
862 1.2.4.2 nathanw xor = flags & 1 ? 0x8000 : 0;
863 1.2.4.2 nathanw
864 1.2.4.2 nathanw if (flags & 2) {
865 1.2.4.2 nathanw while (length > 0) {
866 1.2.4.2 nathanw *q++ = bswap16(bp->rhw_fifo_lh ^ xor);
867 1.2.4.2 nathanw *q++ = bswap16(bp->rhw_fifo_rh ^ xor);
868 1.2.4.2 nathanw length -= 4;
869 1.2.4.2 nathanw }
870 1.2.4.2 nathanw return;
871 1.2.4.2 nathanw }
872 1.2.4.2 nathanw while (length > 0) {
873 1.2.4.2 nathanw *q++ = bp->rhw_fifo_lh ^ xor;
874 1.2.4.2 nathanw *q++ = bp->rhw_fifo_rh ^ xor;
875 1.2.4.2 nathanw length -= 4;
876 1.2.4.2 nathanw }
877 1.2.4.2 nathanw }
878 1.2.4.2 nathanw
879 1.2.4.2 nathanw /*
880 1.2.4.2 nathanw * At this point the transfer function is set.
881 1.2.4.2 nathanw */
882 1.2.4.2 nathanw
883 1.2.4.2 nathanw int
884 1.2.4.2 nathanw rep_start_output(void *addr, void *block, int blksize,
885 1.2.4.2 nathanw void (*intr)(void*), void *intrarg) {
886 1.2.4.2 nathanw
887 1.2.4.2 nathanw struct repulse_softc *sc;
888 1.2.4.2 nathanw u_int8_t *buf;
889 1.2.4.2 nathanw struct repulse_hw *bp;
890 1.2.4.2 nathanw u_int16_t status;
891 1.2.4.2 nathanw
892 1.2.4.2 nathanw
893 1.2.4.2 nathanw sc = addr;
894 1.2.4.2 nathanw bp = sc->sc_boardp;
895 1.2.4.2 nathanw buf = block;
896 1.2.4.2 nathanw
897 1.2.4.2 nathanw /* TODO: prepare hw if necessary */
898 1.2.4.2 nathanw status = bp->rhw_status;
899 1.2.4.2 nathanw if (!(status & REPSTATUS_PLAY))
900 1.2.4.2 nathanw bp->rhw_status = status |
901 1.2.4.2 nathanw REPSTATUS_PLAY | REPSTATUS_PLAYFIFORST;
902 1.2.4.2 nathanw
903 1.2.4.2 nathanw /* copy data */
904 1.2.4.2 nathanw (*sc->sc_playfun)(bp, buf, blksize, sc->sc_playflags);
905 1.2.4.2 nathanw
906 1.2.4.2 nathanw /* TODO: set hw if necessary */
907 1.2.4.2 nathanw if (intr) {
908 1.2.4.2 nathanw bp->rhw_status |= REPSTATUS_PLAYIRQENABLE;
909 1.2.4.2 nathanw bp->rhw_play_fifosz = blksize / sc->sc_playscale / 2;
910 1.2.4.2 nathanw /* /2: give us time to return on the first call */
911 1.2.4.2 nathanw }
912 1.2.4.2 nathanw
913 1.2.4.2 nathanw /* save callback function */
914 1.2.4.2 nathanw sc->sc_playarg = intrarg;
915 1.2.4.2 nathanw sc->sc_playmore = intr;
916 1.2.4.2 nathanw
917 1.2.4.2 nathanw return 0;
918 1.2.4.2 nathanw }
919 1.2.4.2 nathanw
920 1.2.4.2 nathanw int
921 1.2.4.2 nathanw rep_start_input(void *addr, void *block, int blksize,
922 1.2.4.2 nathanw void (*intr)(void*), void *intrarg) {
923 1.2.4.2 nathanw
924 1.2.4.2 nathanw struct repulse_softc *sc;
925 1.2.4.2 nathanw struct repulse_hw *bp;
926 1.2.4.2 nathanw u_int16_t status;
927 1.2.4.2 nathanw
928 1.2.4.2 nathanw sc = addr;
929 1.2.4.2 nathanw bp = sc->sc_boardp;
930 1.2.4.2 nathanw
931 1.2.4.2 nathanw sc->sc_captbuf = block;
932 1.2.4.2 nathanw sc->sc_captbufsz = blksize;
933 1.2.4.2 nathanw sc->sc_captarg = intrarg;
934 1.2.4.2 nathanw sc->sc_captmore = intr;
935 1.2.4.2 nathanw
936 1.2.4.2 nathanw status = bp->rhw_status;
937 1.2.4.2 nathanw if (!(status & REPSTATUS_RECORD))
938 1.2.4.2 nathanw bp->rhw_status = status | REPSTATUS_RECORD
939 1.2.4.2 nathanw | REPSTATUS_RECFIFORST;
940 1.2.4.2 nathanw
941 1.2.4.2 nathanw bp->rhw_status |= REPSTATUS_RECIRQENABLE;
942 1.2.4.2 nathanw bp->rhw_capt_fifosz = blksize / sc->sc_captscale;
943 1.2.4.2 nathanw
944 1.2.4.2 nathanw return 0;
945 1.2.4.2 nathanw }
946 1.2.4.2 nathanw
947 1.2.4.2 nathanw /* irq handler */
948 1.2.4.2 nathanw
949 1.2.4.2 nathanw int
950 1.2.4.2 nathanw rep_intr(void *tag) {
951 1.2.4.2 nathanw struct repulse_softc *sc;
952 1.2.4.2 nathanw struct repulse_hw *bp;
953 1.2.4.2 nathanw int foundone;
954 1.2.4.2 nathanw u_int16_t status;
955 1.2.4.2 nathanw
956 1.2.4.2 nathanw foundone = 0;
957 1.2.4.2 nathanw
958 1.2.4.2 nathanw sc = tag;
959 1.2.4.2 nathanw bp = sc->sc_boardp;
960 1.2.4.2 nathanw status = bp->rhw_status;
961 1.2.4.2 nathanw
962 1.2.4.2 nathanw if (status & REPSTATUS_PLAYIRQACK) {
963 1.2.4.2 nathanw foundone = 1;
964 1.2.4.2 nathanw status &= ~REPSTATUS_PLAYIRQENABLE;
965 1.2.4.2 nathanw bp->rhw_status = status;
966 1.2.4.2 nathanw (*sc->sc_playmore)(sc->sc_playarg);
967 1.2.4.2 nathanw }
968 1.2.4.2 nathanw
969 1.2.4.2 nathanw if (status & REPSTATUS_RECIRQACK) {
970 1.2.4.2 nathanw foundone = 1;
971 1.2.4.2 nathanw status &= ~REPSTATUS_RECIRQENABLE;
972 1.2.4.2 nathanw bp->rhw_status = status;
973 1.2.4.2 nathanw (*sc->sc_captfun)(bp, sc->sc_captbuf, sc->sc_captbufsz,
974 1.2.4.2 nathanw sc->sc_captflags);
975 1.2.4.2 nathanw (*sc->sc_captmore)(sc->sc_captarg);
976 1.2.4.2 nathanw }
977 1.2.4.2 nathanw
978 1.2.4.2 nathanw return foundone;
979 1.2.4.2 nathanw }
980