cs4231_sbus.c revision 1.34 1 1.34 martin /* $NetBSD: cs4231_sbus.c,v 1.34 2006/10/15 19:45:06 martin 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.34 martin __KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.34 2006/10/15 19:45:06 martin 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.32 kent 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.34 martin NULL, /* powerstate */
133 1.1 pk };
134 1.1 pk
135 1.1 pk
136 1.18 uwe #ifdef AUDIO_DEBUG
137 1.18 uwe static void cs4231_sbus_regdump(char *, struct cs4231_sbus_softc *);
138 1.18 uwe #endif
139 1.18 uwe
140 1.18 uwe static int cs4231_sbus_intr(void *);
141 1.18 uwe
142 1.18 uwe
143 1.18 uwe
144 1.18 uwe static int
145 1.32 kent cs4231_sbus_match(struct device *parent, struct cfdata *cf, void *aux)
146 1.1 pk {
147 1.32 kent struct sbus_attach_args *sa;
148 1.1 pk
149 1.32 kent sa = aux;
150 1.32 kent return strcmp(sa->sa_name, AUDIOCS_PROM_NAME) == 0;
151 1.1 pk }
152 1.1 pk
153 1.18 uwe
154 1.18 uwe static void
155 1.32 kent cs4231_sbus_attach(struct device *parent, struct device *self, void *aux)
156 1.1 pk {
157 1.32 kent struct cs4231_sbus_softc *sbsc;
158 1.32 kent struct cs4231_softc *sc;
159 1.32 kent struct sbus_attach_args *sa;
160 1.1 pk bus_space_handle_t bh;
161 1.1 pk
162 1.32 kent sbsc = (struct cs4231_sbus_softc *)self;
163 1.32 kent sc = &sbsc->sc_cs4231;
164 1.32 kent sa = aux;
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.32 kent cs4231_sbus_regdump(char *label, struct cs4231_sbus_softc *sc)
205 1.18 uwe {
206 1.18 uwe char bits[128];
207 1.18 uwe
208 1.18 uwe printf("cs4231regdump(%s): regs:", label);
209 1.19 eeh printf("dmapva: 0x%x; ",
210 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PVA));
211 1.19 eeh printf("dmapc: 0x%x; ",
212 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PC));
213 1.19 eeh printf("dmapnva: 0x%x; ",
214 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PNVA));
215 1.19 eeh printf("dmapnc: 0x%x\n",
216 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_PNC));
217 1.32 kent printf("dmacva: 0x%x; ",
218 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CVA));
219 1.32 kent printf("dmacc: 0x%x; ",
220 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CC));
221 1.32 kent printf("dmacnva: 0x%x; ",
222 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CNVA));
223 1.32 kent printf("dmacnc: 0x%x\n",
224 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CNC));
225 1.18 uwe
226 1.18 uwe printf("apc_dmacsr=%s\n",
227 1.19 eeh bitmask_snprintf(
228 1.29 uwe bus_space_read_4(sc->sc_bh, sc->sc_bh, APC_DMA_CSR),
229 1.19 eeh APC_BITS, bits, sizeof(bits)));
230 1.18 uwe
231 1.18 uwe ad1848_dump_regs(&sc->sc_cs4231.sc_ad1848);
232 1.18 uwe }
233 1.18 uwe #endif /* AUDIO_DEBUG */
234 1.18 uwe
235 1.18 uwe
236 1.18 uwe static int
237 1.32 kent cs4231_sbus_trigger_output(void *addr, void *start, void *end, int blksize,
238 1.32 kent void (*intr)(void *), void *arg,
239 1.32 kent const audio_params_t *param)
240 1.18 uwe {
241 1.32 kent struct cs4231_sbus_softc *sbsc;
242 1.32 kent struct cs4231_softc *sc;
243 1.32 kent struct cs_transfer *t;
244 1.32 kent uint32_t csr;
245 1.18 uwe bus_addr_t dmaaddr;
246 1.18 uwe bus_size_t dmasize;
247 1.18 uwe int ret;
248 1.18 uwe #ifdef AUDIO_DEBUG
249 1.18 uwe char bits[128];
250 1.18 uwe #endif
251 1.18 uwe
252 1.32 kent sbsc = addr;
253 1.32 kent sc = &sbsc->sc_cs4231;
254 1.32 kent t = &sc->sc_playback;
255 1.18 uwe ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
256 1.18 uwe start, end, blksize, intr, arg);
257 1.18 uwe if (ret != 0)
258 1.32 kent return ret;
259 1.18 uwe
260 1.18 uwe DPRINTF(("trigger_output: was: %x %d, %x %d\n",
261 1.32 kent bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
262 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
263 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
264 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
265 1.18 uwe
266 1.18 uwe /* load first block */
267 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA, dmaaddr);
268 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC, dmasize);
269 1.18 uwe
270 1.18 uwe DPRINTF(("trigger_output: 1st: %x %d, %x %d\n",
271 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
272 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
273 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
274 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
275 1.18 uwe
276 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
277 1.19 eeh DPRINTF(("trigger_output: csr=%s\n",
278 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
279 1.18 uwe if ((csr & PDMA_GO) == 0 || (csr & APC_PPAUSE) != 0) {
280 1.18 uwe int cfg;
281 1.18 uwe
282 1.19 eeh csr &= ~(APC_PPAUSE | APC_PMIE | APC_INTR_MASK);
283 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
284 1.18 uwe
285 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
286 1.19 eeh csr &= ~APC_INTR_MASK;
287 1.18 uwe csr |= APC_ENABLE | APC_PIE | APC_PMIE | PDMA_GO;
288 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
289 1.18 uwe
290 1.18 uwe ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
291 1.18 uwe ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
292 1.18 uwe
293 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
294 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
295 1.18 uwe (cfg | PLAYBACK_ENABLE));
296 1.18 uwe } else {
297 1.18 uwe DPRINTF(("trigger_output: already: csr=%s\n",
298 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
299 1.18 uwe }
300 1.18 uwe
301 1.18 uwe /* load next block if we can */
302 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
303 1.19 eeh if (csr & APC_PD) {
304 1.21 mrg cs4231_transfer_advance(t, &dmaaddr, &dmasize);
305 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA, dmaaddr);
306 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC, dmasize);
307 1.19 eeh
308 1.21 mrg DPRINTF(("trigger_output: 2nd: %x %d, %x %d\n",
309 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PVA),
310 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PC),
311 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNVA),
312 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_PNC)));
313 1.18 uwe }
314 1.18 uwe
315 1.32 kent return 0;
316 1.18 uwe }
317 1.18 uwe
318 1.18 uwe
319 1.18 uwe static int
320 1.32 kent cs4231_sbus_halt_output(void *addr)
321 1.18 uwe {
322 1.32 kent struct cs4231_sbus_softc *sbsc;
323 1.32 kent struct cs4231_softc *sc;
324 1.32 kent uint32_t csr;
325 1.18 uwe int cfg;
326 1.18 uwe #ifdef AUDIO_DEBUG
327 1.18 uwe char bits[128];
328 1.18 uwe #endif
329 1.18 uwe
330 1.32 kent sbsc = addr;
331 1.32 kent sc = &sbsc->sc_cs4231;
332 1.18 uwe sc->sc_playback.t_active = 0;
333 1.18 uwe
334 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
335 1.18 uwe DPRINTF(("halt_output: csr=%s\n",
336 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
337 1.18 uwe
338 1.18 uwe csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
339 1.18 uwe csr |= APC_PPAUSE; /* pause playback (let current complete) */
340 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
341 1.32 kent
342 1.18 uwe /* let the curernt transfer complete */
343 1.18 uwe if (csr & PDMA_GO)
344 1.18 uwe do {
345 1.32 kent csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh,
346 1.29 uwe APC_DMA_CSR);
347 1.18 uwe DPRINTF(("halt_output: csr=%s\n",
348 1.19 eeh bitmask_snprintf(csr, APC_BITS,
349 1.18 uwe bits, sizeof(bits))));
350 1.18 uwe } while ((csr & APC_PM) == 0);
351 1.1 pk
352 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
353 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,(cfg & ~PLAYBACK_ENABLE));
354 1.18 uwe
355 1.32 kent return 0;
356 1.1 pk }
357 1.18 uwe
358 1.18 uwe
359 1.18 uwe /* NB: we don't enable APC_CMIE and won't use APC_CM */
360 1.18 uwe static int
361 1.32 kent cs4231_sbus_trigger_input(void *addr, void *start, void *end, int blksize,
362 1.32 kent void (*intr)(void *), void *arg,
363 1.32 kent const audio_params_t *param)
364 1.18 uwe {
365 1.32 kent struct cs4231_sbus_softc *sbsc;
366 1.32 kent struct cs4231_softc *sc;
367 1.32 kent struct cs_transfer *t;
368 1.32 kent uint32_t csr;
369 1.18 uwe bus_addr_t dmaaddr;
370 1.18 uwe bus_size_t dmasize;
371 1.18 uwe int ret;
372 1.18 uwe #ifdef AUDIO_DEBUG
373 1.18 uwe char bits[128];
374 1.1 pk #endif
375 1.18 uwe
376 1.32 kent sbsc = addr;
377 1.32 kent sc = &sbsc->sc_cs4231;
378 1.32 kent t = &sc->sc_capture;
379 1.18 uwe ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
380 1.18 uwe start, end, blksize, intr, arg);
381 1.18 uwe if (ret != 0)
382 1.32 kent return ret;
383 1.18 uwe
384 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
385 1.18 uwe DPRINTF(("trigger_input: csr=%s\n",
386 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
387 1.18 uwe DPRINTF(("trigger_input: was: %x %d, %x %d\n",
388 1.32 kent bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
389 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
390 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
391 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
392 1.18 uwe
393 1.18 uwe /* supply first block */
394 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA, dmaaddr);
395 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC, dmasize);
396 1.18 uwe
397 1.18 uwe DPRINTF(("trigger_input: 1st: %x %d, %x %d\n",
398 1.32 kent bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
399 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
400 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
401 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
402 1.18 uwe
403 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
404 1.18 uwe if ((csr & CDMA_GO) == 0 || (csr & APC_CPAUSE) != 0) {
405 1.18 uwe int cfg;
406 1.18 uwe
407 1.19 eeh csr &= ~(APC_CPAUSE | APC_CMIE | APC_INTR_MASK);
408 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
409 1.18 uwe
410 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
411 1.19 eeh csr &= ~APC_INTR_MASK;
412 1.18 uwe csr |= APC_ENABLE | APC_CIE | CDMA_GO;
413 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
414 1.18 uwe
415 1.18 uwe ad_write(&sc->sc_ad1848, CS_LOWER_REC_CNT, 0xff);
416 1.18 uwe ad_write(&sc->sc_ad1848, CS_UPPER_REC_CNT, 0xff);
417 1.18 uwe
418 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
419 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
420 1.18 uwe (cfg | CAPTURE_ENABLE));
421 1.18 uwe } else {
422 1.18 uwe DPRINTF(("trigger_input: already: csr=%s\n",
423 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
424 1.18 uwe }
425 1.18 uwe
426 1.18 uwe /* supply next block if we can */
427 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
428 1.21 mrg if (csr & APC_CD) {
429 1.21 mrg cs4231_transfer_advance(t, &dmaaddr, &dmasize);
430 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA, dmaaddr);
431 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC, dmasize);
432 1.21 mrg DPRINTF(("trigger_input: 2nd: %x %d, %x %d\n",
433 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CVA),
434 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CC),
435 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNVA),
436 1.29 uwe bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CNC)));
437 1.18 uwe }
438 1.18 uwe
439 1.32 kent return 0;
440 1.18 uwe }
441 1.18 uwe
442 1.18 uwe
443 1.18 uwe static int
444 1.32 kent cs4231_sbus_halt_input(void *addr)
445 1.18 uwe {
446 1.32 kent struct cs4231_sbus_softc *sbsc;
447 1.32 kent struct cs4231_softc *sc;
448 1.32 kent uint32_t csr;
449 1.18 uwe int cfg;
450 1.18 uwe #ifdef AUDIO_DEBUG
451 1.18 uwe char bits[128];
452 1.18 uwe #endif
453 1.18 uwe
454 1.32 kent sbsc = addr;
455 1.32 kent sc = &sbsc->sc_cs4231;
456 1.18 uwe sc->sc_capture.t_active = 0;
457 1.18 uwe
458 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
459 1.18 uwe DPRINTF(("halt_input: csr=%s\n",
460 1.19 eeh bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
461 1.18 uwe
462 1.18 uwe csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
463 1.18 uwe csr |= APC_CPAUSE;
464 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
465 1.18 uwe
466 1.18 uwe /* let the curernt transfer complete */
467 1.18 uwe if (csr & CDMA_GO)
468 1.18 uwe do {
469 1.19 eeh csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh,
470 1.29 uwe APC_DMA_CSR);
471 1.18 uwe DPRINTF(("halt_input: csr=%s\n",
472 1.19 eeh bitmask_snprintf(csr, APC_BITS,
473 1.18 uwe bits, sizeof(bits))));
474 1.18 uwe } while ((csr & APC_CM) == 0);
475 1.18 uwe
476 1.18 uwe cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
477 1.18 uwe ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg & ~CAPTURE_ENABLE));
478 1.18 uwe
479 1.32 kent return 0;
480 1.18 uwe }
481 1.18 uwe
482 1.18 uwe
483 1.18 uwe static int
484 1.32 kent cs4231_sbus_intr(void *arg)
485 1.18 uwe {
486 1.32 kent struct cs4231_sbus_softc *sbsc;
487 1.32 kent struct cs4231_softc *sc;
488 1.32 kent uint32_t csr;
489 1.18 uwe int status;
490 1.18 uwe bus_addr_t dmaaddr;
491 1.18 uwe bus_size_t dmasize;
492 1.18 uwe int served;
493 1.18 uwe #if defined(AUDIO_DEBUG) || defined(DIAGNOSTIC)
494 1.18 uwe char bits[128];
495 1.18 uwe #endif
496 1.18 uwe
497 1.32 kent sbsc = arg;
498 1.32 kent sc = &sbsc->sc_cs4231;
499 1.29 uwe csr = bus_space_read_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR);
500 1.18 uwe if ((csr & APC_INTR_MASK) == 0) /* any interrupt pedning? */
501 1.32 kent return 0;
502 1.18 uwe
503 1.19 eeh /* write back DMA status to clear interrupt */
504 1.29 uwe bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh, APC_DMA_CSR, csr);
505 1.18 uwe ++sc->sc_intrcnt.ev_count;
506 1.18 uwe served = 0;
507 1.18 uwe
508 1.18 uwe #ifdef AUDIO_DEBUG
509 1.18 uwe if (cs4231_sbus_debug > 1)
510 1.18 uwe cs4231_sbus_regdump("audiointr", sbsc);
511 1.18 uwe #endif
512 1.18 uwe
513 1.18 uwe status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
514 1.18 uwe DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
515 1.18 uwe bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
516 1.18 uwe if (status & INTERRUPT_STATUS) {
517 1.18 uwe #ifdef AUDIO_DEBUG
518 1.18 uwe int reason;
519 1.18 uwe
520 1.18 uwe reason = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
521 1.18 uwe DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
522 1.18 uwe bitmask_snprintf(reason, CS_I24_BITS, bits, sizeof(bits))));
523 1.18 uwe #endif
524 1.18 uwe /* clear ad1848 interrupt */
525 1.18 uwe ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
526 1.18 uwe }
527 1.32 kent
528 1.18 uwe if (csr & APC_CI) {
529 1.18 uwe if (csr & APC_CD) { /* can supply new block */
530 1.18 uwe struct cs_transfer *t = &sc->sc_capture;
531 1.18 uwe
532 1.18 uwe cs4231_transfer_advance(t, &dmaaddr, &dmasize);
533 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
534 1.29 uwe APC_DMA_CNVA, dmaaddr);
535 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
536 1.29 uwe APC_DMA_CNC, dmasize);
537 1.18 uwe
538 1.18 uwe if (t->t_intr != NULL)
539 1.18 uwe (*t->t_intr)(t->t_arg);
540 1.18 uwe ++t->t_intrcnt.ev_count;
541 1.18 uwe served = 1;
542 1.18 uwe }
543 1.18 uwe }
544 1.18 uwe
545 1.18 uwe if (csr & APC_PMI) {
546 1.18 uwe if (!sc->sc_playback.t_active)
547 1.18 uwe served = 1; /* draining in halt_output() */
548 1.18 uwe }
549 1.18 uwe
550 1.18 uwe if (csr & APC_PI) {
551 1.18 uwe if (csr & APC_PD) { /* can load new block */
552 1.18 uwe struct cs_transfer *t = &sc->sc_playback;
553 1.18 uwe
554 1.18 uwe if (t->t_active) {
555 1.18 uwe cs4231_transfer_advance(t, &dmaaddr, &dmasize);
556 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
557 1.29 uwe APC_DMA_PNVA, dmaaddr);
558 1.19 eeh bus_space_write_4(sbsc->sc_bt, sbsc->sc_bh,
559 1.29 uwe APC_DMA_PNC, dmasize);
560 1.18 uwe }
561 1.18 uwe
562 1.18 uwe if (t->t_intr != NULL)
563 1.18 uwe (*t->t_intr)(t->t_arg);
564 1.18 uwe ++t->t_intrcnt.ev_count;
565 1.18 uwe served = 1;
566 1.18 uwe }
567 1.18 uwe }
568 1.18 uwe
569 1.18 uwe /* got an interrupt we don't know how to handle */
570 1.18 uwe if (!served) {
571 1.18 uwe #ifdef DIAGNOSTIC
572 1.18 uwe printf("%s: unhandled csr=%s\n", sc->sc_ad1848.sc_dev.dv_xname,
573 1.18 uwe bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits)));
574 1.18 uwe #endif
575 1.18 uwe /* evcnt? */
576 1.18 uwe }
577 1.18 uwe
578 1.32 kent return 1;
579 1.18 uwe }
580 1.18 uwe
581 1.18 uwe #endif /* NAUDIO > 0 */
582