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