cs4231_sbus.c revision 1.31 1 1.31 kent /* $NetBSD: cs4231_sbus.c,v 1.31 2005/01/10 22:01:37 kent Exp $ */
2 1.2 pk
3 1.2 pk /*-
4 1.18 uwe * Copyright (c) 1998, 1999, 2002 The NetBSD Foundation, Inc.
5 1.2 pk * All rights reserved.
6 1.2 pk *
7 1.2 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.2 pk * by Paul Kranenburg.
9 1.2 pk *
10 1.2 pk * Redistribution and use in source and binary forms, with or without
11 1.2 pk * modification, are permitted provided that the following conditions
12 1.2 pk * are met:
13 1.2 pk * 1. Redistributions of source code must retain the above copyright
14 1.2 pk * notice, this list of conditions and the following disclaimer.
15 1.2 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 pk * notice, this list of conditions and the following disclaimer in the
17 1.2 pk * documentation and/or other materials provided with the distribution.
18 1.2 pk * 3. All advertising materials mentioning features or use of this software
19 1.2 pk * must display the following acknowledgement:
20 1.2 pk * This product includes software developed by the NetBSD
21 1.2 pk * Foundation, Inc. and its contributors.
22 1.2 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 pk * contributors may be used to endorse or promote products derived
24 1.2 pk * from this software without specific prior written permission.
25 1.2 pk *
26 1.2 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.2 pk */
38 1.16 lukem
39 1.16 lukem #include <sys/cdefs.h>
40 1.31 kent __KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.31 2005/01/10 22:01:37 kent Exp $");
41 1.1 pk
42 1.1 pk #include "audio.h"
43 1.1 pk #if NAUDIO > 0
44 1.1 pk
45 1.1 pk #include <sys/param.h>
46 1.1 pk #include <sys/systm.h>
47 1.1 pk #include <sys/errno.h>
48 1.1 pk #include <sys/device.h>
49 1.1 pk #include <sys/malloc.h>
50 1.1 pk
51 1.15 pk #include <machine/bus.h>
52 1.15 pk #include <machine/intr.h>
53 1.15 pk
54 1.15 pk #include <dev/sbus/sbusvar.h>
55 1.1 pk
56 1.1 pk #include <sys/audioio.h>
57 1.1 pk #include <dev/audio_if.h>
58 1.1 pk
59 1.1 pk #include <dev/ic/ad1848reg.h>
60 1.1 pk #include <dev/ic/cs4231reg.h>
61 1.1 pk #include <dev/ic/ad1848var.h>
62 1.11 mrg #include <dev/ic/cs4231var.h>
63 1.1 pk
64 1.18 uwe #include <dev/ic/apcdmareg.h>
65 1.1 pk
66 1.18 uwe #ifdef AUDIO_DEBUG
67 1.18 uwe int cs4231_sbus_debug = 0;
68 1.18 uwe #define DPRINTF(x) if (cs4231_sbus_debug) printf x
69 1.18 uwe #else
70 1.18 uwe #define DPRINTF(x)
71 1.18 uwe #endif
72 1.18 uwe
73 1.18 uwe /* where APC DMA registers are located */
74 1.18 uwe #define CS4231_APCDMA_OFFSET 16
75 1.18 uwe
76 1.18 uwe /* interrupt enable bits except those specific for playback/capture */
77 1.18 uwe #define APC_ENABLE (APC_EI | APC_IE | APC_EIE)
78 1.18 uwe
79 1.18 uwe struct cs4231_sbus_softc {
80 1.18 uwe struct cs4231_softc sc_cs4231;
81 1.18 uwe
82 1.18 uwe struct sbusdev sc_sd; /* sbus device */
83 1.19 eeh bus_space_tag_t sc_bt; /* DMA controller tag */
84 1.19 eeh bus_space_handle_t sc_bh; /* DMA controller registers */
85 1.18 uwe };
86 1.18 uwe
87 1.18 uwe
88 1.18 uwe static int cs4231_sbus_match(struct device *, struct cfdata *, void *);
89 1.18 uwe static void cs4231_sbus_attach(struct device *, struct device *, void *);
90 1.1 pk
91 1.23 thorpej CFATTACH_DECL(audiocs_sbus, sizeof(struct cs4231_sbus_softc),
92 1.24 thorpej cs4231_sbus_match, cs4231_sbus_attach, NULL, NULL);
93 1.18 uwe
94 1.28 wiz /* audio_hw_if methods specific to apc DMA */
95 1.18 uwe static int cs4231_sbus_trigger_output(void *, void *, void *, int,
96 1.18 uwe void (*)(void *), void *,
97 1.31 kent const audio_params_t *);
98 1.18 uwe static int cs4231_sbus_trigger_input(void *, void *, void *, int,
99 1.18 uwe void (*)(void *), void *,
100 1.31 kent const audio_params_t *);
101 1.18 uwe static int cs4231_sbus_halt_output(void *);
102 1.18 uwe static int cs4231_sbus_halt_input(void *);
103 1.18 uwe
104 1.30 yamt const struct audio_hw_if audiocs_sbus_hw_if = {
105 1.18 uwe cs4231_open,
106 1.18 uwe cs4231_close,
107 1.18 uwe NULL, /* drain */
108 1.18 uwe ad1848_query_encoding,
109 1.18 uwe ad1848_set_params,
110 1.29 uwe NULL, /* round_blocksize */
111 1.18 uwe ad1848_commit_settings,
112 1.18 uwe NULL, /* init_output */
113 1.18 uwe NULL, /* init_input */
114 1.18 uwe NULL, /* start_output */
115 1.18 uwe NULL, /* start_input */
116 1.18 uwe cs4231_sbus_halt_output,
117 1.18 uwe cs4231_sbus_halt_input,
118 1.18 uwe NULL, /* speaker_ctl */
119 1.18 uwe cs4231_getdev,
120 1.18 uwe NULL, /* setfd */
121 1.18 uwe cs4231_set_port,
122 1.18 uwe cs4231_get_port,
123 1.18 uwe cs4231_query_devinfo,
124 1.18 uwe cs4231_malloc,
125 1.18 uwe cs4231_free,
126 1.29 uwe NULL, /* round_buffersize */
127 1.18 uwe NULL, /* mappage */
128 1.18 uwe cs4231_get_props,
129 1.18 uwe cs4231_sbus_trigger_output,
130 1.18 uwe cs4231_sbus_trigger_input,
131 1.18 uwe NULL, /* dev_ioctl */
132 1.1 pk };
133 1.1 pk
134 1.1 pk
135 1.18 uwe #ifdef AUDIO_DEBUG
136 1.18 uwe static void cs4231_sbus_regdump(char *, struct cs4231_sbus_softc *);
137 1.18 uwe #endif
138 1.18 uwe
139 1.18 uwe static int cs4231_sbus_intr(void *);
140 1.18 uwe
141 1.18 uwe
142 1.18 uwe
143 1.18 uwe static int
144 1.18 uwe cs4231_sbus_match(parent, cf, aux)
145 1.1 pk struct device *parent;
146 1.1 pk struct cfdata *cf;
147 1.1 pk void *aux;
148 1.1 pk {
149 1.1 pk struct sbus_attach_args *sa = aux;
150 1.1 pk
151 1.27 pk return (strcmp(sa->sa_name, AUDIOCS_PROM_NAME) == 0);
152 1.1 pk }
153 1.1 pk
154 1.18 uwe
155 1.18 uwe static void
156 1.18 uwe cs4231_sbus_attach(parent, self, aux)
157 1.1 pk struct device *parent, *self;
158 1.1 pk void *aux;
159 1.1 pk {
160 1.18 uwe struct cs4231_sbus_softc *sbsc = (struct cs4231_sbus_softc *)self;
161 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
162 1.1 pk struct sbus_attach_args *sa = aux;
163 1.1 pk bus_space_handle_t bh;
164 1.1 pk
165 1.19 eeh sbsc->sc_bt = sc->sc_bustag = sa->sa_bustag;
166 1.1 pk sc->sc_dmatag = sa->sa_dmatag;
167 1.1 pk
168 1.1 pk /*
169 1.1 pk * Map my registers in, if they aren't already in virtual
170 1.1 pk * address space.
171 1.1 pk */
172 1.1 pk if (sa->sa_npromvaddrs) {
173 1.19 eeh sbus_promaddr_to_handle(sa->sa_bustag,
174 1.19 eeh sa->sa_promvaddrs[0], &bh);
175 1.1 pk } else {
176 1.19 eeh if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
177 1.19 eeh sa->sa_offset, sa->sa_size, 0, &bh) != 0) {
178 1.1 pk printf("%s @ sbus: cannot map registers\n",
179 1.1 pk self->dv_xname);
180 1.1 pk return;
181 1.1 pk }
182 1.1 pk }
183 1.1 pk
184 1.19 eeh bus_space_subregion(sa->sa_bustag, bh, CS4231_APCDMA_OFFSET,
185 1.29 uwe APC_DMA_SIZE, &sbsc->sc_bh);
186 1.1 pk
187 1.18 uwe cs4231_common_attach(sc, bh);
188 1.1 pk printf("\n");
189 1.1 pk
190 1.18 uwe sbus_establish(&sbsc->sc_sd, &sc->sc_ad1848.sc_dev);
191 1.1 pk
192 1.1 pk /* Establish interrupt channel */
193 1.12 pk if (sa->sa_nintr)
194 1.12 pk bus_intr_establish(sa->sa_bustag,
195 1.25 pk sa->sa_pri, IPL_AUDIO,
196 1.18 uwe cs4231_sbus_intr, sbsc);
197 1.18 uwe
198 1.18 uwe audio_attach_mi(&audiocs_sbus_hw_if, sbsc, &sc->sc_ad1848.sc_dev);
199 1.18 uwe }
200 1.18 uwe
201 1.18 uwe
202 1.18 uwe #ifdef AUDIO_DEBUG
203 1.18 uwe static void
204 1.18 uwe cs4231_sbus_regdump(label, sc)
205 1.18 uwe char *label;
206 1.18 uwe struct cs4231_sbus_softc *sc;
207 1.18 uwe {
208 1.18 uwe char bits[128];
209 1.18 uwe
210 1.18 uwe printf("cs4231regdump(%s): regs:", label);
211 1.19 eeh printf("dmapva: 0x%x; ",
212 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PVA));
213 1.19 eeh printf("dmapc: 0x%x; ",
214 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PC));
215 1.19 eeh printf("dmapnva: 0x%x; ",
216 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PNVA));
217 1.19 eeh printf("dmapnc: 0x%x\n",
218 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PNC));
219 1.19 eeh printf("dmacva: 0x%x; ",
220 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CVA));
221 1.19 eeh printf("dmacc: 0x%x; ",
222 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CC));
223 1.19 eeh printf("dmacnva: 0x%x; ",
224 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CNVA));
225 1.19 eeh printf("dmacnc: 0x%x\n",
226 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CNC));
227 1.18 uwe
228 1.18 uwe printf("apc_dmacsr=%s\n",
229 1.19 eeh bitmask_snprintf(
230 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CSR),
231 1.19 eeh APC_BITS, bits, sizeof(bits)));
232 1.18 uwe
233 1.18 uwe ad1848_dump_regs(&sc->sc_cs4231.sc_ad1848);
234 1.18 uwe }
235 1.18 uwe #endif /* AUDIO_DEBUG */
236 1.18 uwe
237 1.18 uwe
238 1.18 uwe static int
239 1.18 uwe cs4231_sbus_trigger_output(addr, start, end, blksize, intr, arg, param)
240 1.18 uwe void *addr;
241 1.18 uwe void *start, *end;
242 1.18 uwe int blksize;
243 1.18 uwe void (*intr)(void *);
244 1.18 uwe void *arg;
245 1.31 kent const audio_params_t *param;
246 1.18 uwe {
247 1.18 uwe struct cs4231_sbus_softc *sbsc = addr;
248 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
249 1.18 uwe struct cs_transfer *t = &sc->sc_playback;
250 1.18 uwe u_int32_t csr;
251 1.18 uwe bus_addr_t dmaaddr;
252 1.18 uwe bus_size_t dmasize;
253 1.18 uwe int ret;
254 1.18 uwe #ifdef AUDIO_DEBUG
255 1.18 uwe char bits[128];
256 1.18 uwe #endif
257 1.18 uwe
258 1.18 uwe ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
259 1.18 uwe start, end, blksize, intr, arg);
260 1.18 uwe if (ret != 0)
261 1.18 uwe return (ret);
262 1.18 uwe
263 1.18 uwe DPRINTF(("trigger_output: was: %x %d, %x %d\n",
264 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
265 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
266 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
267 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
268 1.18 uwe
269 1.18 uwe /* load first block */
270 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA, dmaaddr);
271 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC, dmasize);
272 1.18 uwe
273 1.18 uwe DPRINTF(("trigger_output: 1st: %x %d, %x %d\n",
274 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
275 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
276 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
277 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
278 1.18 uwe
279 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
280 1.19 eeh DPRINTF(("trigger_output: csr=%s\n",
281 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
282 1.18 uwe if ((csr & PDMA_GO) == 0 || (csr & APC_PPAUSE) != 0) {
283 1.18 uwe int cfg;
284 1.18 uwe
285 1.19 eeh csr &= ~(APC_PPAUSE | APC_PMIE | APC_INTR_MASK);
286 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
287 1.18 uwe
288 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
289 1.19 eeh csr &= ~APC_INTR_MASK;
290 1.18 uwe csr |= APC_ENABLE | APC_PIE | APC_PMIE | PDMA_GO;
291 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
292 1.18 uwe
293 1.18 uwe ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
294 1.18 uwe ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
295 1.18 uwe
296 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
297 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
298 1.18 uwe (cfg | PLAYBACK_ENABLE));
299 1.18 uwe } else {
300 1.18 uwe DPRINTF(("trigger_output: already: csr=%s\n",
301 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
302 1.18 uwe }
303 1.18 uwe
304 1.18 uwe /* load next block if we can */
305 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
306 1.19 eeh if (csr & APC_PD) {
307 1.21 mrg cs4231_transfer_advance(t, &dmaaddr, &dmasize);
308 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA, dmaaddr);
309 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC, dmasize);
310 1.19 eeh
311 1.21 mrg DPRINTF(("trigger_output: 2nd: %x %d, %x %d\n",
312 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
313 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
314 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
315 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
316 1.18 uwe }
317 1.18 uwe
318 1.18 uwe return (0);
319 1.18 uwe }
320 1.18 uwe
321 1.18 uwe
322 1.18 uwe static int
323 1.18 uwe cs4231_sbus_halt_output(addr)
324 1.18 uwe void *addr;
325 1.18 uwe {
326 1.18 uwe struct cs4231_sbus_softc *sbsc = addr;
327 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
328 1.18 uwe u_int32_t csr;
329 1.18 uwe int cfg;
330 1.18 uwe #ifdef AUDIO_DEBUG
331 1.18 uwe char bits[128];
332 1.18 uwe #endif
333 1.18 uwe
334 1.18 uwe sc->sc_playback.t_active = 0;
335 1.18 uwe
336 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
337 1.18 uwe DPRINTF(("halt_output: csr=%s\n",
338 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
339 1.18 uwe
340 1.18 uwe csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
341 1.18 uwe csr |= APC_PPAUSE; /* pause playback (let current complete) */
342 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
343 1.19 eeh
344 1.18 uwe /* let the curernt transfer complete */
345 1.18 uwe if (csr & PDMA_GO)
346 1.18 uwe do {
347 1.19 eeh csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh,
348 1.29 uwe APC_DMA_CSR);
349 1.18 uwe DPRINTF(("halt_output: csr=%s\n",
350 1.19 eeh bitmask_snprintf(csr, APC_BITS,
351 1.18 uwe bits, sizeof(bits))));
352 1.18 uwe } while ((csr & APC_PM) == 0);
353 1.1 pk
354 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
355 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,(cfg & ~PLAYBACK_ENABLE));
356 1.18 uwe
357 1.18 uwe return (0);
358 1.1 pk }
359 1.18 uwe
360 1.18 uwe
361 1.18 uwe /* NB: we don't enable APC_CMIE and won't use APC_CM */
362 1.18 uwe static int
363 1.18 uwe cs4231_sbus_trigger_input(addr, start, end, blksize, intr, arg, param)
364 1.18 uwe void *addr;
365 1.18 uwe void *start, *end;
366 1.18 uwe int blksize;
367 1.18 uwe void (*intr)(void *);
368 1.18 uwe void *arg;
369 1.31 kent const audio_params_t *param;
370 1.18 uwe {
371 1.18 uwe struct cs4231_sbus_softc *sbsc = addr;
372 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
373 1.18 uwe struct cs_transfer *t = &sc->sc_capture;
374 1.18 uwe u_int32_t csr;
375 1.18 uwe bus_addr_t dmaaddr;
376 1.18 uwe bus_size_t dmasize;
377 1.18 uwe int ret;
378 1.18 uwe #ifdef AUDIO_DEBUG
379 1.18 uwe char bits[128];
380 1.1 pk #endif
381 1.18 uwe
382 1.18 uwe ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
383 1.18 uwe start, end, blksize, intr, arg);
384 1.18 uwe if (ret != 0)
385 1.18 uwe return (ret);
386 1.18 uwe
387 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
388 1.18 uwe DPRINTF(("trigger_input: csr=%s\n",
389 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
390 1.18 uwe DPRINTF(("trigger_input: was: %x %d, %x %d\n",
391 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
392 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
393 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
394 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
395 1.18 uwe
396 1.18 uwe /* supply first block */
397 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA, dmaaddr);
398 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC, dmasize);
399 1.18 uwe
400 1.18 uwe DPRINTF(("trigger_input: 1st: %x %d, %x %d\n",
401 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
402 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
403 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
404 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
405 1.18 uwe
406 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
407 1.18 uwe if ((csr & CDMA_GO) == 0 || (csr & APC_CPAUSE) != 0) {
408 1.18 uwe int cfg;
409 1.18 uwe
410 1.19 eeh csr &= ~(APC_CPAUSE | APC_CMIE | APC_INTR_MASK);
411 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
412 1.18 uwe
413 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
414 1.19 eeh csr &= ~APC_INTR_MASK;
415 1.18 uwe csr |= APC_ENABLE | APC_CIE | CDMA_GO;
416 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
417 1.18 uwe
418 1.18 uwe ad_write(&sc->sc_ad1848, CS_LOWER_REC_CNT, 0xff);
419 1.18 uwe ad_write(&sc->sc_ad1848, CS_UPPER_REC_CNT, 0xff);
420 1.18 uwe
421 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
422 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
423 1.18 uwe (cfg | CAPTURE_ENABLE));
424 1.18 uwe } else {
425 1.18 uwe DPRINTF(("trigger_input: already: csr=%s\n",
426 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
427 1.18 uwe }
428 1.18 uwe
429 1.18 uwe /* supply next block if we can */
430 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
431 1.21 mrg if (csr & APC_CD) {
432 1.21 mrg cs4231_transfer_advance(t, &dmaaddr, &dmasize);
433 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA, dmaaddr);
434 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC, dmasize);
435 1.21 mrg DPRINTF(("trigger_input: 2nd: %x %d, %x %d\n",
436 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
437 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
438 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
439 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
440 1.18 uwe }
441 1.18 uwe
442 1.18 uwe return (0);
443 1.18 uwe }
444 1.18 uwe
445 1.18 uwe
446 1.18 uwe static int
447 1.18 uwe cs4231_sbus_halt_input(addr)
448 1.18 uwe void *addr;
449 1.18 uwe {
450 1.18 uwe struct cs4231_sbus_softc *sbsc = addr;
451 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
452 1.18 uwe u_int32_t csr;
453 1.18 uwe int cfg;
454 1.18 uwe #ifdef AUDIO_DEBUG
455 1.18 uwe char bits[128];
456 1.18 uwe #endif
457 1.18 uwe
458 1.18 uwe sc->sc_capture.t_active = 0;
459 1.18 uwe
460 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
461 1.18 uwe DPRINTF(("halt_input: csr=%s\n",
462 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
463 1.18 uwe
464 1.18 uwe csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
465 1.18 uwe csr |= APC_CPAUSE;
466 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
467 1.18 uwe
468 1.18 uwe /* let the curernt transfer complete */
469 1.18 uwe if (csr & CDMA_GO)
470 1.18 uwe do {
471 1.19 eeh csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh,
472 1.29 uwe APC_DMA_CSR);
473 1.18 uwe DPRINTF(("halt_input: csr=%s\n",
474 1.19 eeh bitmask_snprintf(csr, APC_BITS,
475 1.18 uwe bits, sizeof(bits))));
476 1.18 uwe } while ((csr & APC_CM) == 0);
477 1.18 uwe
478 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
479 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg & ~CAPTURE_ENABLE));
480 1.18 uwe
481 1.18 uwe return (0);
482 1.18 uwe }
483 1.18 uwe
484 1.18 uwe
485 1.18 uwe static int
486 1.18 uwe cs4231_sbus_intr(arg)
487 1.18 uwe void *arg;
488 1.18 uwe {
489 1.18 uwe struct cs4231_sbus_softc *sbsc = arg;
490 1.18 uwe struct cs4231_softc *sc = &sbsc->sc_cs4231;
491 1.18 uwe u_int32_t csr;
492 1.18 uwe int status;
493 1.18 uwe bus_addr_t dmaaddr;
494 1.18 uwe bus_size_t dmasize;
495 1.18 uwe int served;
496 1.18 uwe #if defined(AUDIO_DEBUG) || defined(DIAGNOSTIC)
497 1.18 uwe char bits[128];
498 1.18 uwe #endif
499 1.18 uwe
500 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
501 1.18 uwe if ((csr & APC_INTR_MASK) == 0) /* any interrupt pedning? */
502 1.18 uwe return (0);
503 1.18 uwe
504 1.19 eeh /* write back DMA status to clear interrupt */
505 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
506 1.18 uwe ++sc->sc_intrcnt.ev_count;
507 1.18 uwe served = 0;
508 1.18 uwe
509 1.18 uwe #ifdef AUDIO_DEBUG
510 1.18 uwe if (cs4231_sbus_debug > 1)
511 1.18 uwe cs4231_sbus_regdump("audiointr", sbsc);
512 1.18 uwe #endif
513 1.18 uwe
514 1.18 uwe status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
515 1.18 uwe DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
516 1.18 uwe bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
517 1.18 uwe if (status & INTERRUPT_STATUS) {
518 1.18 uwe #ifdef AUDIO_DEBUG
519 1.18 uwe int reason;
520 1.18 uwe
521 1.18 uwe reason = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
522 1.18 uwe DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
523 1.18 uwe bitmask_snprintf(reason, CS_I24_BITS, bits, sizeof(bits))));
524 1.18 uwe #endif
525 1.18 uwe /* clear ad1848 interrupt */
526 1.18 uwe ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
527 1.18 uwe }
528 1.18 uwe
529 1.18 uwe if (csr & APC_CI) {
530 1.18 uwe if (csr & APC_CD) { /* can supply new block */
531 1.18 uwe struct cs_transfer *t = &sc->sc_capture;
532 1.18 uwe
533 1.18 uwe cs4231_transfer_advance(t, &dmaaddr, &dmasize);
534 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
535 1.29 uwe APC_DMA_CNVA, dmaaddr);
536 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
537 1.29 uwe APC_DMA_CNC, dmasize);
538 1.18 uwe
539 1.18 uwe if (t->t_intr != NULL)
540 1.18 uwe (*t->t_intr)(t->t_arg);
541 1.18 uwe ++t->t_intrcnt.ev_count;
542 1.18 uwe served = 1;
543 1.18 uwe }
544 1.18 uwe }
545 1.18 uwe
546 1.18 uwe if (csr & APC_PMI) {
547 1.18 uwe if (!sc->sc_playback.t_active)
548 1.18 uwe served = 1; /* draining in halt_output() */
549 1.18 uwe }
550 1.18 uwe
551 1.18 uwe if (csr & APC_PI) {
552 1.18 uwe if (csr & APC_PD) { /* can load new block */
553 1.18 uwe struct cs_transfer *t = &sc->sc_playback;
554 1.18 uwe
555 1.18 uwe if (t->t_active) {
556 1.18 uwe cs4231_transfer_advance(t, &dmaaddr, &dmasize);
557 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
558 1.29 uwe APC_DMA_PNVA, dmaaddr);
559 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
560 1.29 uwe APC_DMA_PNC, dmasize);
561 1.18 uwe }
562 1.18 uwe
563 1.18 uwe if (t->t_intr != NULL)
564 1.18 uwe (*t->t_intr)(t->t_arg);
565 1.18 uwe ++t->t_intrcnt.ev_count;
566 1.18 uwe served = 1;
567 1.18 uwe }
568 1.18 uwe }
569 1.18 uwe
570 1.18 uwe /* got an interrupt we don't know how to handle */
571 1.18 uwe if (!served) {
572 1.18 uwe #ifdef DIAGNOSTIC
573 1.18 uwe printf("%s: unhandled csr=%s\n", sc->sc_ad1848.sc_dev.dv_xname,
574 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits)));
575 1.18 uwe #endif
576 1.18 uwe /* evcnt? */
577 1.18 uwe }
578 1.18 uwe
579 1.18 uwe return (1);
580 1.18 uwe }
581 1.18 uwe
582 1.18 uwe #endif /* NAUDIO > 0 */
583