FreeBSD kernel sound device code
es137x.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-4-Clause
3 *
4 * Copyright (c) 1999 Russell Cattelan <cattelan@thebarn.com>
5 * Copyright (c) 1998 Joachim Kuebart <joachim.kuebart@gmx.net>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/*-
31 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 *
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 *
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
44 * distribution.
45 *
46 * 3. All advertising materials mentioning features or use of this
47 * software must display the following acknowledgement:
48 * This product includes software developed by Joachim Kuebart.
49 *
50 * 4. The name of the author may not be used to endorse or promote
51 * products derived from this software without specific prior
52 * written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
55 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
57 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
58 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
59 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
62 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
64 * OF THE POSSIBILITY OF SUCH DAMAGE.
65 */
66
67/*
68 * Support the ENSONIQ AudioPCI board and Creative Labs SoundBlaster PCI
69 * boards based on the ES1370, ES1371 and ES1373 chips.
70 *
71 * Part of this code was heavily inspired by the linux driver from
72 * Thomas Sailer (sailer@ife.ee.ethz.ch)
73 * Just about everything has been touched and reworked in some way but
74 * the all the underlying sequences/timing/register values are from
75 * Thomas' code.
76*/
77
78#ifdef HAVE_KERNEL_OPTION_HEADERS
79#include "opt_snd.h"
80#endif
81
82#include <dev/sound/pcm/sound.h>
83#include <dev/sound/pcm/ac97.h>
85
86#include <dev/pci/pcireg.h>
87#include <dev/pci/pcivar.h>
88
89#include <sys/sysctl.h>
90
91#include "mixer_if.h"
92
93SND_DECLARE_FILE("$FreeBSD$");
94
95#define MEM_MAP_REG 0x14
96
97/* PCI IDs of supported chips */
98#define ES1370_PCI_ID 0x50001274
99#define ES1371_PCI_ID 0x13711274
100#define ES1371_PCI_ID2 0x13713274
101#define CT5880_PCI_ID 0x58801274
102#define CT4730_PCI_ID 0x89381102
103
104#define ES1371REV_ES1371_A 0x02
105#define ES1371REV_ES1371_B 0x09
106
107#define ES1371REV_ES1373_8 0x08
108#define ES1371REV_ES1373_A 0x04
109#define ES1371REV_ES1373_B 0x06
110
111#define ES1371REV_CT5880_A 0x07
112
113#define CT5880REV_CT5880_C 0x02
114#define CT5880REV_CT5880_D 0x03
115#define CT5880REV_CT5880_E 0x04
116
117#define CT4730REV_CT4730_A 0x00
118
119#define ES_DEFAULT_BUFSZ 4096
120
121/* 2 DAC for playback, 1 ADC for record */
122#define ES_DAC1 0
123#define ES_DAC2 1
124#define ES_ADC 2
125#define ES_NCHANS 3
126
127#define ES_DMA_SEGS_MIN 2
128#define ES_DMA_SEGS_MAX 256
129#define ES_BLK_MIN 64
130#define ES_BLK_ALIGN (~(ES_BLK_MIN - 1))
131
132#define ES1370_DAC1_MINSPEED 5512
133#define ES1370_DAC1_MAXSPEED 44100
134
135/* device private data */
136struct es_info;
137
138struct es_chinfo {
143 int dir, num, index;
144 uint32_t fmt, blksz, blkcnt, bufsz;
145 uint32_t ptr, prevptr;
147};
148
149/*
150 * 32bit Ensoniq Configuration (es->escfg).
151 * ----------------------------------------
152 *
153 * +-------+--------+------+------+---------+--------+---------+---------+
154 * len | 16 | 1 | 1 | 1 | 2 | 2 | 1 | 8 |
155 * +-------+--------+------+------+---------+--------+---------+---------+
156 * | fixed | single | | | | | is | general |
157 * | rate | pcm | DACx | DACy | numplay | numrec | es1370? | purpose |
158 * | | mixer | | | | | | |
159 * +-------+--------+------+------+---------+--------+---------+---------+
160 */
161#define ES_FIXED_RATE(cfgv) \
162 (((cfgv) & 0xffff0000) >> 16)
163#define ES_SET_FIXED_RATE(cfgv, nv) \
164 (((cfgv) & ~0xffff0000) | (((nv) & 0xffff) << 16))
165#define ES_SINGLE_PCM_MIX(cfgv) \
166 (((cfgv) & 0x8000) >> 15)
167#define ES_SET_SINGLE_PCM_MIX(cfgv, nv) \
168 (((cfgv) & ~0x8000) | (((nv) ? 1 : 0) << 15))
169#define ES_DAC_FIRST(cfgv) \
170 (((cfgv) & 0x4000) >> 14)
171#define ES_SET_DAC_FIRST(cfgv, nv) \
172 (((cfgv) & ~0x4000) | (((nv) & 0x1) << 14))
173#define ES_DAC_SECOND(cfgv) \
174 (((cfgv) & 0x2000) >> 13)
175#define ES_SET_DAC_SECOND(cfgv, nv) \
176 (((cfgv) & ~0x2000) | (((nv) & 0x1) << 13))
177#define ES_NUMPLAY(cfgv) \
178 (((cfgv) & 0x1800) >> 11)
179#define ES_SET_NUMPLAY(cfgv, nv) \
180 (((cfgv) & ~0x1800) | (((nv) & 0x3) << 11))
181#define ES_NUMREC(cfgv) \
182 (((cfgv) & 0x600) >> 9)
183#define ES_SET_NUMREC(cfgv, nv) \
184 (((cfgv) & ~0x600) | (((nv) & 0x3) << 9))
185#define ES_IS_ES1370(cfgv) \
186 (((cfgv) & 0x100) >> 8)
187#define ES_SET_IS_ES1370(cfgv, nv) \
188 (((cfgv) & ~0x100) | (((nv) ? 1 : 0) << 8))
189#define ES_GP(cfgv) \
190 ((cfgv) & 0xff)
191#define ES_SET_GP(cfgv, nv) \
192 (((cfgv) & ~0xff) | ((nv) & 0xff))
193
194#define ES_DAC1_ENABLED(cfgv) \
195 (ES_NUMPLAY(cfgv) > 1 || \
196 (ES_NUMPLAY(cfgv) == 1 && ES_DAC_FIRST(cfgv) == ES_DAC1))
197#define ES_DAC2_ENABLED(cfgv) \
198 (ES_NUMPLAY(cfgv) > 1 || \
199 (ES_NUMPLAY(cfgv) == 1 && ES_DAC_FIRST(cfgv) == ES_DAC2))
200
201/*
202 * DAC 1/2 configuration through kernel hint - hint.pcm.<unit>.dac="val"
203 *
204 * 0 = Enable both DACs - Default
205 * 1 = Enable single DAC (DAC1)
206 * 2 = Enable single DAC (DAC2)
207 * 3 = Enable both DACs, swap position (DAC2 comes first instead of DAC1)
208 */
209#define ES_DEFAULT_DAC_CFG 0
210
211struct es_info {
212 bus_space_tag_t st;
213 bus_space_handle_t sh;
214 bus_dma_tag_t parent_dmat;
215
216 struct resource *reg, *irq;
218 void *ih;
219
220 device_t dev;
221 int num;
222 unsigned int bufsz, blkcnt;
223
224 /* Contents of board's registers */
225 uint32_t ctrl;
226 uint32_t sctrl;
227 uint32_t escfg;
229 struct mtx *lock;
230 struct callout poll_timer;
232};
233
234#define ES_LOCK(sc) snd_mtxlock((sc)->lock)
235#define ES_UNLOCK(sc) snd_mtxunlock((sc)->lock)
236#define ES_LOCK_ASSERT(sc) snd_mtxassert((sc)->lock)
237
238/* prototypes */
239static void es_intr(void *);
240static uint32_t es1371_wait_src_ready(struct es_info *);
241static void es1371_src_write(struct es_info *,
242 unsigned short, unsigned short);
243static unsigned int es1371_adc_rate(struct es_info *, unsigned int, int);
244static unsigned int es1371_dac_rate(struct es_info *, unsigned int, int);
245static int es1371_init(struct es_info *);
246static int es1370_init(struct es_info *);
247static int es1370_wrcodec(struct es_info *, unsigned char, unsigned char);
248
249static uint32_t es_fmt[] = {
250 SND_FORMAT(AFMT_U8, 1, 0),
251 SND_FORMAT(AFMT_U8, 2, 0),
252 SND_FORMAT(AFMT_S16_LE, 1, 0),
253 SND_FORMAT(AFMT_S16_LE, 2, 0),
254 0
255};
256static struct pcmchan_caps es_caps = {4000, 48000, es_fmt, 0};
257
258static const struct {
259 unsigned volidx:4;
260 unsigned left:4;
261 unsigned right:4;
262 unsigned stereo:1;
263 unsigned recmask:13;
264 unsigned avail:1;
265} mixtable[SOUND_MIXER_NRDEVICES] = {
266 [SOUND_MIXER_VOLUME] = { 0, 0x0, 0x1, 1, 0x1f7f, 1 },
267 [SOUND_MIXER_PCM] = { 1, 0x2, 0x3, 1, 0x0400, 1 },
268 [SOUND_MIXER_SYNTH] = { 2, 0x4, 0x5, 1, 0x0060, 1 },
269 [SOUND_MIXER_CD] = { 3, 0x6, 0x7, 1, 0x0006, 1 },
270 [SOUND_MIXER_LINE] = { 4, 0x8, 0x9, 1, 0x0018, 1 },
271 [SOUND_MIXER_LINE1] = { 5, 0xa, 0xb, 1, 0x1800, 1 },
272 [SOUND_MIXER_LINE2] = { 6, 0xc, 0x0, 0, 0x0100, 1 },
273 [SOUND_MIXER_LINE3] = { 7, 0xd, 0x0, 0, 0x0200, 1 },
274 [SOUND_MIXER_MIC] = { 8, 0xe, 0x0, 0, 0x0001, 1 },
275 [SOUND_MIXER_OGAIN] = { 9, 0xf, 0x0, 0, 0x0000, 1 }
277
278static __inline uint32_t
279es_rd(struct es_info *es, int regno, int size)
280{
281 switch (size) {
282 case 1:
283 return (bus_space_read_1(es->st, es->sh, regno));
284 case 2:
285 return (bus_space_read_2(es->st, es->sh, regno));
286 case 4:
287 return (bus_space_read_4(es->st, es->sh, regno));
288 default:
289 return (0xFFFFFFFF);
290 }
291}
292
293static __inline void
294es_wr(struct es_info *es, int regno, uint32_t data, int size)
295{
296
297 switch (size) {
298 case 1:
299 bus_space_write_1(es->st, es->sh, regno, data);
300 break;
301 case 2:
302 bus_space_write_2(es->st, es->sh, regno, data);
303 break;
304 case 4:
305 bus_space_write_4(es->st, es->sh, regno, data);
306 break;
307 }
308}
309
310/* -------------------------------------------------------------------- */
311/* The es1370 mixer interface */
312
313static int
315{
316 struct es_info *es;
317 int i;
318 uint32_t v;
319
320 es = mix_getdevinfo(m);
321 v = 0;
322 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
323 if (mixtable[i].avail)
324 v |= (1 << i);
325 }
326 /*
327 * Each DAC1/2 for ES1370 can be controlled independently
328 * DAC1 = controlled by synth
329 * DAC2 = controlled by pcm
330 * This is indeed can confuse user if DAC1 become primary playback
331 * channel. Try to be smart and combine both if necessary.
332 */
333 if (ES_SINGLE_PCM_MIX(es->escfg))
334 v &= ~(1 << SOUND_MIXER_SYNTH);
335 mix_setdevs(m, v);
336 v = 0;
337 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
338 if (mixtable[i].recmask)
339 v |= (1 << i);
340 }
341 if (ES_SINGLE_PCM_MIX(es->escfg)) /* ditto */
342 v &= ~(1 << SOUND_MIXER_SYNTH);
343 mix_setrecdevs(m, v);
344 return (0);
345}
346
347static int
348es1370_mixset(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
349{
350 struct es_info *es;
351 int l, r, rl, rr, set_dac1;
352
353 if (!mixtable[dev].avail)
354 return (-1);
355 l = left;
356 r = (mixtable[dev].stereo) ? right : l;
357 if (mixtable[dev].left == 0xf)
358 rl = (l < 2) ? 0x80 : 7 - (l - 2) / 14;
359 else
360 rl = (l < 7) ? 0x80 : 31 - (l - 7) / 3;
361 es = mix_getdevinfo(m);
362 ES_LOCK(es);
363 if (dev == SOUND_MIXER_PCM && (ES_SINGLE_PCM_MIX(es->escfg)) &&
365 set_dac1 = 1;
366 else
367 set_dac1 = 0;
368 if (mixtable[dev].stereo) {
369 rr = (r < 7) ? 0x80 : 31 - (r - 7) / 3;
371 if (set_dac1 && mixtable[SOUND_MIXER_SYNTH].stereo)
373 mixtable[SOUND_MIXER_SYNTH].right, rr);
374 }
376 if (set_dac1)
377 es1370_wrcodec(es, mixtable[SOUND_MIXER_SYNTH].left, rl);
378 ES_UNLOCK(es);
379
380 return (l | (r << 8));
381}
382
383static uint32_t
385{
386 struct es_info *es;
387 int i, j = 0;
388
389 es = mix_getdevinfo(m);
390 if (src == 0) src = 1 << SOUND_MIXER_MIC;
391 src &= mix_getrecdevs(m);
392 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
393 if ((src & (1 << i)) != 0) j |= mixtable[i].recmask;
394
395 ES_LOCK(es);
396 if ((src & (1 << SOUND_MIXER_PCM)) && ES_SINGLE_PCM_MIX(es->escfg) &&
398 j |= mixtable[SOUND_MIXER_SYNTH].recmask;
399 es1370_wrcodec(es, CODEC_LIMIX1, j & 0x55);
400 es1370_wrcodec(es, CODEC_RIMIX1, j & 0xaa);
401 es1370_wrcodec(es, CODEC_LIMIX2, (j >> 8) & 0x17);
402 es1370_wrcodec(es, CODEC_RIMIX2, (j >> 8) & 0x0f);
403 es1370_wrcodec(es, CODEC_OMIX1, 0x7f);
404 es1370_wrcodec(es, CODEC_OMIX2, 0x3f);
405 ES_UNLOCK(es);
406
407 return (src);
408}
409
410static kobj_method_t es1370_mixer_methods[] = {
411 KOBJMETHOD(mixer_init, es1370_mixinit),
412 KOBJMETHOD(mixer_set, es1370_mixset),
415};
416MIXER_DECLARE(es1370_mixer);
417
418/* -------------------------------------------------------------------- */
419
420static int
421es1370_wrcodec(struct es_info *es, unsigned char i, unsigned char data)
422{
423 unsigned int t;
424
425 ES_LOCK_ASSERT(es);
426
427 for (t = 0; t < 0x1000; t++) {
428 if ((es_rd(es, ES1370_REG_STATUS, 4) &
429 STAT_CSTAT) == 0) {
431 ((unsigned short)i << CODEC_INDEX_SHIFT) | data, 2);
432 return (0);
433 }
434 DELAY(1);
435 }
436 device_printf(es->dev, "%s: timed out\n", __func__);
437 return (-1);
438}
439
440/* -------------------------------------------------------------------- */
441
442/* channel interface */
443static void *
444eschan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
445 struct pcm_channel *c, int dir)
446{
447 struct es_info *es = devinfo;
448 struct es_chinfo *ch;
449 uint32_t index;
450
451 ES_LOCK(es);
452
453 if (dir == PCMDIR_PLAY) {
454 index = ES_GP(es->escfg);
455 es->escfg = ES_SET_GP(es->escfg, index + 1);
456 if (index == 0)
457 index = ES_DAC_FIRST(es->escfg);
458 else if (index == 1)
460 else {
461 device_printf(es->dev,
462 "Invalid ES_GP index: %d\n", index);
463 ES_UNLOCK(es);
464 return (NULL);
465 }
466 if (!(index == ES_DAC1 || index == ES_DAC2)) {
467 device_printf(es->dev, "Unknown DAC: %d\n", index + 1);
468 ES_UNLOCK(es);
469 return (NULL);
470 }
471 if (es->ch[index].channel != NULL) {
472 device_printf(es->dev, "DAC%d already initialized!\n",
473 index + 1);
474 ES_UNLOCK(es);
475 return (NULL);
476 }
477 } else
478 index = ES_ADC;
479
480 ch = &es->ch[index];
481 ch->index = index;
482 ch->num = es->num++;
483 ch->caps = es_caps;
484 if (ES_IS_ES1370(es->escfg)) {
485 if (ch->index == ES_DAC1) {
488 } else {
489 uint32_t fixed_rate = ES_FIXED_RATE(es->escfg);
490 if (!(fixed_rate < es_caps.minspeed ||
491 fixed_rate > es_caps.maxspeed)) {
492 ch->caps.maxspeed = fixed_rate;
493 ch->caps.minspeed = fixed_rate;
494 }
495 }
496 }
497 ch->parent = es;
498 ch->channel = c;
499 ch->buffer = b;
500 ch->bufsz = es->bufsz;
501 ch->blkcnt = es->blkcnt;
502 ch->blksz = ch->bufsz / ch->blkcnt;
503 ch->dir = dir;
504 ES_UNLOCK(es);
505 if (sndbuf_alloc(ch->buffer, es->parent_dmat, 0, ch->bufsz) != 0)
506 return (NULL);
507 ES_LOCK(es);
508 if (dir == PCMDIR_PLAY) {
509 if (ch->index == ES_DAC1) {
513 sndbuf_getbufaddr(ch->buffer), 4);
515 (ch->bufsz >> 2) - 1, 4);
516 } else {
520 sndbuf_getbufaddr(ch->buffer), 4);
522 (ch->bufsz >> 2) - 1, 4);
523 }
524 } else {
527 sndbuf_getbufaddr(ch->buffer), 4);
529 (ch->bufsz >> 2) - 1, 4);
530 }
531 ES_UNLOCK(es);
532 return (ch);
533}
534
535static int
536eschan_setformat(kobj_t obj, void *data, uint32_t format)
537{
538 struct es_chinfo *ch = data;
539 struct es_info *es = ch->parent;
540
541 ES_LOCK(es);
542 if (ch->dir == PCMDIR_PLAY) {
543 if (ch->index == ES_DAC1) {
544 es->sctrl &= ~SCTRL_P1FMT;
545 if (format & AFMT_S16_LE)
546 es->sctrl |= SCTRL_P1SEB;
547 if (AFMT_CHANNEL(format) > 1)
548 es->sctrl |= SCTRL_P1SMB;
549 } else {
550 es->sctrl &= ~SCTRL_P2FMT;
551 if (format & AFMT_S16_LE)
552 es->sctrl |= SCTRL_P2SEB;
553 if (AFMT_CHANNEL(format) > 1)
554 es->sctrl |= SCTRL_P2SMB;
555 }
556 } else {
557 es->sctrl &= ~SCTRL_R1FMT;
558 if (format & AFMT_S16_LE)
559 es->sctrl |= SCTRL_R1SEB;
560 if (AFMT_CHANNEL(format) > 1)
561 es->sctrl |= SCTRL_R1SMB;
562 }
564 ES_UNLOCK(es);
565 ch->fmt = format;
566 return (0);
567}
568
569static uint32_t
570eschan1370_setspeed(kobj_t obj, void *data, uint32_t speed)
571{
572 struct es_chinfo *ch = data;
573 struct es_info *es = ch->parent;
574
575 ES_LOCK(es);
576 /* Fixed rate , do nothing. */
577 if (ch->caps.minspeed == ch->caps.maxspeed) {
578 ES_UNLOCK(es);
579 return (ch->caps.maxspeed);
580 }
581 if (speed < ch->caps.minspeed)
583 if (speed > ch->caps.maxspeed)
585 if (ch->index == ES_DAC1) {
586 /*
587 * DAC1 does not support continuous rate settings.
588 * Pick the nearest and use it since FEEDER_RATE will
589 * do the proper conversion for us.
590 */
591 es->ctrl &= ~CTRL_WTSRSEL;
592 if (speed < 8268) {
593 speed = 5512;
594 es->ctrl |= 0 << CTRL_SH_WTSRSEL;
595 } else if (speed < 16537) {
596 speed = 11025;
597 es->ctrl |= 1 << CTRL_SH_WTSRSEL;
598 } else if (speed < 33075) {
599 speed = 22050;
600 es->ctrl |= 2 << CTRL_SH_WTSRSEL;
601 } else {
602 speed = 44100;
603 es->ctrl |= 3 << CTRL_SH_WTSRSEL;
604 }
605 } else {
606 es->ctrl &= ~CTRL_PCLKDIV;
608 }
609 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
610 ES_UNLOCK(es);
611 return (speed);
612}
613
614static uint32_t
615eschan1371_setspeed(kobj_t obj, void *data, uint32_t speed)
616{
617 struct es_chinfo *ch = data;
618 struct es_info *es = ch->parent;
619 uint32_t i;
620 int delta;
621
622 ES_LOCK(es);
623 if (ch->dir == PCMDIR_PLAY)
624 i = es1371_dac_rate(es, speed, ch->index); /* play */
625 else
626 i = es1371_adc_rate(es, speed, ch->index); /* record */
627 ES_UNLOCK(es);
628 delta = (speed > i) ? (speed - i) : (i - speed);
629 if (delta < 2)
630 return (speed);
631 return (i);
632}
633
634static int
635eschan_setfragments(kobj_t obj, void *data, uint32_t blksz, uint32_t blkcnt)
636{
637 struct es_chinfo *ch = data;
638 struct es_info *es = ch->parent;
639
641
644 if (blksz < ES_BLK_MIN)
650
651 while ((blksz * blkcnt) > sndbuf_getmaxsize(ch->buffer)) {
652 if ((blkcnt >> 1) >= ES_DMA_SEGS_MIN)
653 blkcnt >>= 1;
654 else if ((blksz >> 1) >= ES_BLK_MIN)
655 blksz >>= 1;
656 else
657 break;
658 }
659
660 if ((sndbuf_getblksz(ch->buffer) != blksz ||
663 device_printf(es->dev, "%s: failed blksz=%u blkcnt=%u\n",
664 __func__, blksz, blkcnt);
665
669
670 return (0);
671}
672
673static uint32_t
674eschan_setblocksize(kobj_t obj, void *data, uint32_t blksz)
675{
676 struct es_chinfo *ch = data;
677 struct es_info *es = ch->parent;
678
680
681 return (ch->blksz);
682}
683
684#define es_chan_active(es) ((es)->ch[ES_DAC1].active + \
685 (es)->ch[ES_DAC2].active + \
686 (es)->ch[ES_ADC].active)
687
688static __inline int
690{
691 struct es_info *es;
692 uint32_t sz, delta;
693 uint32_t reg, ptr;
694
695 if (ch == NULL || ch->channel == NULL || ch->active == 0)
696 return (0);
697
698 es = ch->parent;
699 if (ch->dir == PCMDIR_PLAY) {
700 if (ch->index == ES_DAC1)
702 else
704 } else
706 sz = ch->blksz * ch->blkcnt;
707 es_wr(es, ES1370_REG_MEMPAGE, reg >> 8, 4);
708 ptr = es_rd(es, reg & 0x000000ff, 4) >> 16;
709 ptr <<= 2;
710 ch->ptr = ptr;
711 ptr %= sz;
712 ptr &= ~(ch->blksz - 1);
713 delta = (sz + ptr - ch->prevptr) % sz;
714
715 if (delta < ch->blksz)
716 return (0);
717
718 ch->prevptr = ptr;
719
720 return (1);
721}
722
723static void
725{
726 struct es_info *es = arg;
727 uint32_t trigger = 0;
728 int i;
729
730 if (es == NULL)
731 return;
732
733 ES_LOCK(es);
734 if (es->polling == 0 || es_chan_active(es) == 0) {
735 ES_UNLOCK(es);
736 return;
737 }
738
739 for (i = 0; i < ES_NCHANS; i++) {
740 if (es_poll_channel(&es->ch[i]) != 0)
741 trigger |= 1 << i;
742 }
743
744 /* XXX */
745 callout_reset(&es->poll_timer, 1/*es->poll_ticks*/,
746 es_poll_callback, es);
747
748 ES_UNLOCK(es);
749
750 for (i = 0; i < ES_NCHANS; i++) {
751 if (trigger & (1 << i))
752 chn_intr(es->ch[i].channel);
753 }
754}
755
756static int
757eschan_trigger(kobj_t obj, void *data, int go)
758{
759 struct es_chinfo *ch = data;
760 struct es_info *es = ch->parent;
761 uint32_t cnt, b = 0;
762
763 if (!PCMTRIG_COMMON(go))
764 return 0;
765
766 ES_LOCK(es);
767 cnt = (ch->blksz / sndbuf_getalign(ch->buffer)) - 1;
768 if (ch->fmt & AFMT_16BIT)
769 b |= 0x02;
770 if (AFMT_CHANNEL(ch->fmt) > 1)
771 b |= 0x01;
772 if (ch->dir == PCMDIR_PLAY) {
773 if (go == PCMTRIG_START) {
774 if (ch->index == ES_DAC1) {
775 es->ctrl |= CTRL_DAC1_EN;
776 es->sctrl &= ~(SCTRL_P1LOOPSEL |
778 if (es->polling == 0)
779 es->sctrl |= SCTRL_P1INTEN;
780 else
781 es->sctrl &= ~SCTRL_P1INTEN;
782 es->sctrl |= b;
783 es_wr(es, ES1370_REG_DAC1_SCOUNT, cnt, 4);
784 /* start at beginning of buffer */
788 (ch->bufsz >> 2) - 1, 4);
789 } else {
790 es->ctrl |= CTRL_DAC2_EN;
794 if (es->polling == 0)
795 es->sctrl |= SCTRL_P2INTEN;
796 else
797 es->sctrl &= ~SCTRL_P2INTEN;
798 es->sctrl |= (b << 2) |
799 ((((b >> 1) & 1) + 1) << SCTRL_SH_P2ENDINC);
800 es_wr(es, ES1370_REG_DAC2_SCOUNT, cnt, 4);
801 /* start at beginning of buffer */
805 (ch->bufsz >> 2) - 1, 4);
806 }
807 } else
808 es->ctrl &= ~((ch->index == ES_DAC1) ?
810 } else {
811 if (go == PCMTRIG_START) {
812 es->ctrl |= CTRL_ADC_EN;
813 es->sctrl &= ~SCTRL_R1LOOPSEL;
814 if (es->polling == 0)
815 es->sctrl |= SCTRL_R1INTEN;
816 else
817 es->sctrl &= ~SCTRL_R1INTEN;
818 es->sctrl |= b << 4;
819 es_wr(es, ES1370_REG_ADC_SCOUNT, cnt, 4);
820 /* start at beginning of buffer */
824 (ch->bufsz >> 2) - 1, 4);
825 } else
826 es->ctrl &= ~CTRL_ADC_EN;
827 }
829 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
830 if (go == PCMTRIG_START) {
831 if (es->polling != 0) {
832 ch->ptr = 0;
833 ch->prevptr = 0;
834 if (es_chan_active(es) == 0) {
835 es->poll_ticks = 1;
836 callout_reset(&es->poll_timer, 1,
837 es_poll_callback, es);
838 }
839 }
840 ch->active = 1;
841 } else {
842 ch->active = 0;
843 if (es->polling != 0) {
844 if (es_chan_active(es) == 0) {
845 callout_stop(&es->poll_timer);
846 es->poll_ticks = 1;
847 }
848 }
849 }
850 ES_UNLOCK(es);
851 return (0);
852}
853
854static uint32_t
855eschan_getptr(kobj_t obj, void *data)
856{
857 struct es_chinfo *ch = data;
858 struct es_info *es = ch->parent;
859 uint32_t reg, cnt;
860
861 ES_LOCK(es);
862 if (es->polling != 0)
863 cnt = ch->ptr;
864 else {
865 if (ch->dir == PCMDIR_PLAY) {
866 if (ch->index == ES_DAC1)
868 else
870 } else
872 es_wr(es, ES1370_REG_MEMPAGE, reg >> 8, 4);
873 cnt = es_rd(es, reg & 0x000000ff, 4) >> 16;
874 /* cnt is longwords */
875 cnt <<= 2;
876 }
877 ES_UNLOCK(es);
878
879 cnt &= ES_BLK_ALIGN;
880
881 return (cnt);
882}
883
884static struct pcmchan_caps *
885eschan_getcaps(kobj_t obj, void *data)
886{
887 struct es_chinfo *ch = data;
888
889 return (&ch->caps);
890}
891
892static kobj_method_t eschan1370_methods[] = {
893 KOBJMETHOD(channel_init, eschan_init),
894 KOBJMETHOD(channel_setformat, eschan_setformat),
895 KOBJMETHOD(channel_setspeed, eschan1370_setspeed),
896 KOBJMETHOD(channel_setblocksize, eschan_setblocksize),
897 KOBJMETHOD(channel_setfragments, eschan_setfragments),
898 KOBJMETHOD(channel_trigger, eschan_trigger),
899 KOBJMETHOD(channel_getptr, eschan_getptr),
900 KOBJMETHOD(channel_getcaps, eschan_getcaps),
902};
903CHANNEL_DECLARE(eschan1370);
904
905static kobj_method_t eschan1371_methods[] = {
906 KOBJMETHOD(channel_init, eschan_init),
907 KOBJMETHOD(channel_setformat, eschan_setformat),
908 KOBJMETHOD(channel_setspeed, eschan1371_setspeed),
909 KOBJMETHOD(channel_setblocksize, eschan_setblocksize),
910 KOBJMETHOD(channel_setfragments, eschan_setfragments),
911 KOBJMETHOD(channel_trigger, eschan_trigger),
912 KOBJMETHOD(channel_getptr, eschan_getptr),
913 KOBJMETHOD(channel_getcaps, eschan_getcaps),
915};
916CHANNEL_DECLARE(eschan1371);
917
918/* -------------------------------------------------------------------- */
919/* The interrupt handler */
920static void
921es_intr(void *p)
922{
923 struct es_info *es = p;
924 uint32_t intsrc, sctrl;
925
926 ES_LOCK(es);
927 if (es->polling != 0) {
928 ES_UNLOCK(es);
929 return;
930 }
931 intsrc = es_rd(es, ES1370_REG_STATUS, 4);
932 if ((intsrc & STAT_INTR) == 0) {
933 ES_UNLOCK(es);
934 return;
935 }
936
937 sctrl = es->sctrl;
938 if (intsrc & STAT_ADC)
939 sctrl &= ~SCTRL_R1INTEN;
940 if (intsrc & STAT_DAC1)
941 sctrl &= ~SCTRL_P1INTEN;
942 if (intsrc & STAT_DAC2)
943 sctrl &= ~SCTRL_P2INTEN;
944
947 ES_UNLOCK(es);
948
949 if (intsrc & STAT_ADC)
951 if (intsrc & STAT_DAC1)
953 if (intsrc & STAT_DAC2)
955}
956
957/* ES1370 specific */
958static int
960{
961 uint32_t fixed_rate;
962 int r, single_pcm;
963
964 /* ES1370 default to fixed rate operation */
965 if (resource_int_value(device_get_name(es->dev),
966 device_get_unit(es->dev), "fixed_rate", &r) == 0) {
967 fixed_rate = r;
968 if (fixed_rate) {
969 if (fixed_rate < es_caps.minspeed)
970 fixed_rate = es_caps.minspeed;
971 if (fixed_rate > es_caps.maxspeed)
972 fixed_rate = es_caps.maxspeed;
973 }
974 } else
975 fixed_rate = es_caps.maxspeed;
976
977 if (resource_int_value(device_get_name(es->dev),
978 device_get_unit(es->dev), "single_pcm_mixer", &r) == 0)
979 single_pcm = (r != 0) ? 1 : 0;
980 else
981 single_pcm = 1;
982
983 ES_LOCK(es);
984 if (ES_NUMPLAY(es->escfg) == 1)
985 single_pcm = 1;
986 /* This is ES1370 */
987 es->escfg = ES_SET_IS_ES1370(es->escfg, 1);
988 if (fixed_rate)
989 es->escfg = ES_SET_FIXED_RATE(es->escfg, fixed_rate);
990 else {
991 es->escfg = ES_SET_FIXED_RATE(es->escfg, 0);
992 fixed_rate = DSP_DEFAULT_SPEED;
993 }
994 if (single_pcm)
995 es->escfg = ES_SET_SINGLE_PCM_MIX(es->escfg, 1);
996 else
997 es->escfg = ES_SET_SINGLE_PCM_MIX(es->escfg, 0);
999 (DAC2_SRTODIV(fixed_rate) << CTRL_SH_PCLKDIV);
1000 es->ctrl |= 3 << CTRL_SH_WTSRSEL;
1001 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
1002
1003 es->sctrl = 0;
1005
1006 /* No RST, PD */
1008 /*
1009 * CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off the LRCLK2 PLL;
1010 * program DAC_SYNC=0!
1011 */
1012 es1370_wrcodec(es, CODEC_CSEL, 0);
1013 /* Recording source is mixer */
1015 /* MIC amp is 0db */
1017 ES_UNLOCK(es);
1018
1019 return (0);
1020}
1021
1022/* ES1371 specific */
1023int
1025{
1026 uint32_t cssr, devid, revid, subdev;
1027 int idx;
1028
1029 ES_LOCK(es);
1030 /* This is NOT ES1370 */
1031 es->escfg = ES_SET_IS_ES1370(es->escfg, 0);
1032 es->num = 0;
1033 es->sctrl = 0;
1034 cssr = 0;
1035 devid = pci_get_devid(es->dev);
1036 revid = pci_get_revid(es->dev);
1037 subdev = (pci_get_subdevice(es->dev) << 16) |
1038 pci_get_subvendor(es->dev);
1039 /*
1040 * Joyport blacklist. Either we're facing with broken hardware
1041 * or because this hardware need special (unknown) initialization
1042 * procedures.
1043 */
1044 switch (subdev) {
1045 case 0x20001274: /* old Ensoniq */
1046 es->ctrl = 0;
1047 break;
1048 default:
1049 es->ctrl = CTRL_JYSTK_EN;
1050 break;
1051 }
1052 if (devid == CT4730_PCI_ID) {
1053 /* XXX amplifier hack? */
1054 es->ctrl |= (1 << 16);
1055 }
1056 /* initialize the chips */
1057 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
1059 es_wr(es, ES1371_REG_LEGACY, 0, 4);
1065 cssr = 1 << 29;
1066 es_wr(es, ES1370_REG_STATUS, cssr, 4);
1067 DELAY(20000);
1068 }
1069 /* AC'97 warm reset to start the bitclk */
1070 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
1072 DELAY(2000);
1073 es_wr(es, ES1370_REG_CONTROL, es->sctrl, 4);
1075 /* Init the sample rate converter */
1077 for (idx = 0; idx < 0x80; idx++)
1078 es1371_src_write(es, idx, 0);
1083 es1371_src_write(es, ES_SMPREG_VOL_ADC, 1 << 12);
1084 es1371_src_write(es, ES_SMPREG_VOL_ADC + 1, 1 << 12);
1086 es1371_src_write(es, ES_SMPREG_VOL_DAC1 + 1, 1 << 12);
1088 es1371_src_write(es, ES_SMPREG_VOL_DAC2 + 1, 1 << 12);
1089 es1371_adc_rate(es, 22050, ES_ADC);
1090 es1371_dac_rate(es, 22050, ES_DAC1);
1091 es1371_dac_rate(es, 22050, ES_DAC2);
1092 /*
1093 * WARNING:
1094 * enabling the sample rate converter without properly programming
1095 * its parameters causes the chip to lock up (the SRC busy bit will
1096 * be stuck high, and I've found no way to rectify this other than
1097 * power cycle)
1098 */
1100 es_wr(es, ES1371_REG_SMPRATE, 0, 4);
1101 /* try to reset codec directly */
1102 es_wr(es, ES1371_REG_CODEC, 0, 4);
1103 es_wr(es, ES1370_REG_STATUS, cssr, 4);
1104 ES_UNLOCK(es);
1105
1106 return (0);
1107}
1108
1109/* -------------------------------------------------------------------- */
1110
1111static int
1112es1371_wrcd(kobj_t obj, void *s, int addr, uint32_t data)
1113{
1114 uint32_t t, x, orig;
1115 struct es_info *es = (struct es_info*)s;
1116
1117 for (t = 0; t < 0x1000; t++) {
1118 if (!es_rd(es, ES1371_REG_CODEC & CODEC_WIP, 4))
1119 break;
1120 }
1121 /* save the current state for later */
1122 x = orig = es_rd(es, ES1371_REG_SMPRATE, 4);
1123 /* enable SRC state data in SRC mux */
1125 ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000, 4);
1126 /* busy wait */
1127 for (t = 0; t < 0x1000; t++) {
1128 if ((es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) ==
1129 0x00000000)
1130 break;
1131 }
1132 /* wait for a SAFE time to write addr/data and then do it, dammit */
1133 for (t = 0; t < 0x1000; t++) {
1134 if ((es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) ==
1135 0x00010000)
1136 break;
1137 }
1138
1141 CODEC_PODAT_MASK), 4);
1142 /* restore SRC reg */
1144 es_wr(es, ES1371_REG_SMPRATE, orig, 4);
1145
1146 return (0);
1147}
1148
1149static int
1150es1371_rdcd(kobj_t obj, void *s, int addr)
1151{
1152 uint32_t t, x, orig;
1153 struct es_info *es = (struct es_info *)s;
1154
1155 for (t = 0; t < 0x1000; t++) {
1156 if (!(x = es_rd(es, ES1371_REG_CODEC, 4) & CODEC_WIP))
1157 break;
1158 }
1159
1160 /* save the current state for later */
1161 x = orig = es_rd(es, ES1371_REG_SMPRATE, 4);
1162 /* enable SRC state data in SRC mux */
1164 ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000, 4);
1165 /* busy wait */
1166 for (t = 0; t < 0x1000; t++) {
1167 if ((x = es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) ==
1168 0x00000000)
1169 break;
1170 }
1171 /* wait for a SAFE time to write addr/data and then do it, dammit */
1172 for (t = 0; t < 0x1000; t++) {
1173 if ((x = es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) ==
1174 0x00010000)
1175 break;
1176 }
1177
1180
1181 /* restore SRC reg */
1183 es_wr(es, ES1371_REG_SMPRATE, orig, 4);
1184
1185 /* now wait for the stinkin' data (RDY) */
1186 for (t = 0; t < 0x1000; t++) {
1187 if ((x = es_rd(es, ES1371_REG_CODEC, 4)) & CODEC_RDY)
1188 break;
1189 }
1190
1191 return ((x & CODEC_PIDAT_MASK) >> CODEC_PIDAT_SHIFT);
1192}
1193
1194static kobj_method_t es1371_ac97_methods[] = {
1195 KOBJMETHOD(ac97_read, es1371_rdcd),
1196 KOBJMETHOD(ac97_write, es1371_wrcd),
1198};
1199AC97_DECLARE(es1371_ac97);
1200
1201/* -------------------------------------------------------------------- */
1202
1203static unsigned int
1204es1371_src_read(struct es_info *es, unsigned short reg)
1205{
1206 uint32_t r;
1207
1211 es_wr(es, ES1371_REG_SMPRATE, r, 4);
1213}
1214
1215static void
1216es1371_src_write(struct es_info *es, unsigned short reg, unsigned short data)
1217{
1218 uint32_t r;
1219
1224}
1225
1226static unsigned int
1227es1371_adc_rate(struct es_info *es, unsigned int rate, int set)
1228{
1229 unsigned int n, truncm, freq, result;
1230
1231 ES_LOCK_ASSERT(es);
1232
1233 if (rate > 48000)
1234 rate = 48000;
1235 if (rate < 4000)
1236 rate = 4000;
1237 n = rate / 3000;
1238 if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
1239 n--;
1240 truncm = (21 * n - 1) | 1;
1241 freq = ((48000UL << 15) / rate) * n;
1242 result = (48000UL << 15) / (freq / n);
1243 if (set) {
1244 if (rate >= 24000) {
1245 if (truncm > 239)
1246 truncm = 239;
1248 (((239 - truncm) >> 1) << 9) | (n << 4));
1249 } else {
1250 if (truncm > 119)
1251 truncm = 119;
1253 0x8000 | (((119 - truncm) >> 1) << 9) | (n << 4));
1254 }
1257 0x00ff) | ((freq >> 5) & 0xfc00));
1259 freq & 0x7fff);
1261 es1371_src_write(es, ES_SMPREG_VOL_ADC + 1, n << 8);
1262 }
1263 return (result);
1264}
1265
1266static unsigned int
1267es1371_dac_rate(struct es_info *es, unsigned int rate, int set)
1268{
1269 unsigned int freq, r, result, dac, dis;
1270
1271 ES_LOCK_ASSERT(es);
1272
1273 if (rate > 48000)
1274 rate = 48000;
1275 if (rate < 4000)
1276 rate = 4000;
1277 freq = ((rate << 15) + 1500) / 3000;
1278 result = (freq * 3000) >> 15;
1279
1281 dis = (set == ES_DAC1) ? ES1371_DIS_P2 : ES1371_DIS_P1;
1284 es_wr(es, ES1371_REG_SMPRATE, r, 4);
1286 (es1371_src_read(es, dac + ES_SMPREG_INT_REGS) & 0x00ff) |
1287 ((freq >> 5) & 0xfc00));
1288 es1371_src_write(es, dac + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
1289 r = (es1371_wait_src_ready(es) &
1290 (ES1371_DIS_SRC | dis | ES1371_DIS_R1));
1291 es_wr(es, ES1371_REG_SMPRATE, r, 4);
1292 return (result);
1293}
1294
1295static uint32_t
1297{
1298 uint32_t t, r;
1299
1300 for (t = 0; t < 0x1000; t++) {
1301 if (!((r = es_rd(es, ES1371_REG_SMPRATE, 4)) &
1303 return (r);
1304 DELAY(1);
1305 }
1306 device_printf(es->dev, "%s: timed out 0x%x [0x%x]\n", __func__,
1308 return (0);
1309}
1310
1311/* -------------------------------------------------------------------- */
1312
1313/*
1314 * Probe and attach the card
1315 */
1316
1317static int
1319{
1320 switch(pci_get_devid(dev)) {
1321 case ES1370_PCI_ID:
1322 device_set_desc(dev, "AudioPCI ES1370");
1323 return (BUS_PROBE_DEFAULT);
1324 case ES1371_PCI_ID:
1325 switch(pci_get_revid(dev)) {
1326 case ES1371REV_ES1371_A:
1327 device_set_desc(dev, "AudioPCI ES1371-A");
1328 return (BUS_PROBE_DEFAULT);
1329 case ES1371REV_ES1371_B:
1330 device_set_desc(dev, "AudioPCI ES1371-B");
1331 return (BUS_PROBE_DEFAULT);
1332 case ES1371REV_ES1373_A:
1333 device_set_desc(dev, "AudioPCI ES1373-A");
1334 return (BUS_PROBE_DEFAULT);
1335 case ES1371REV_ES1373_B:
1336 device_set_desc(dev, "AudioPCI ES1373-B");
1337 return (BUS_PROBE_DEFAULT);
1338 case ES1371REV_ES1373_8:
1339 device_set_desc(dev, "AudioPCI ES1373-8");
1340 return (BUS_PROBE_DEFAULT);
1341 case ES1371REV_CT5880_A:
1342 device_set_desc(dev, "Creative CT5880-A");
1343 return (BUS_PROBE_DEFAULT);
1344 default:
1345 device_set_desc(dev, "AudioPCI ES1371-?");
1346 device_printf(dev,
1347 "unknown revision %d -- please report to "
1348 "freebsd-multimedia@freebsd.org\n",
1349 pci_get_revid(dev));
1350 return (BUS_PROBE_DEFAULT);
1351 }
1352 case ES1371_PCI_ID2:
1353 device_set_desc(dev, "Strange AudioPCI ES1371-? (vid=3274)");
1354 device_printf(dev,
1355 "unknown revision %d -- please report to "
1356 "freebsd-multimedia@freebsd.org\n", pci_get_revid(dev));
1357 return (BUS_PROBE_DEFAULT);
1358 case CT4730_PCI_ID:
1359 switch(pci_get_revid(dev)) {
1360 case CT4730REV_CT4730_A:
1361 device_set_desc(dev,
1362 "Creative SB AudioPCI CT4730/EV1938");
1363 return (BUS_PROBE_DEFAULT);
1364 default:
1365 device_set_desc(dev, "Creative SB AudioPCI CT4730-?");
1366 device_printf(dev,
1367 "unknown revision %d -- please report to "
1368 "freebsd-multimedia@freebsd.org\n",
1369 pci_get_revid(dev));
1370 return (BUS_PROBE_DEFAULT);
1371 }
1372 case CT5880_PCI_ID:
1373 switch(pci_get_revid(dev)) {
1374 case CT5880REV_CT5880_C:
1375 device_set_desc(dev, "Creative CT5880-C");
1376 return (BUS_PROBE_DEFAULT);
1377 case CT5880REV_CT5880_D:
1378 device_set_desc(dev, "Creative CT5880-D");
1379 return (BUS_PROBE_DEFAULT);
1380 case CT5880REV_CT5880_E:
1381 device_set_desc(dev, "Creative CT5880-E");
1382 return (BUS_PROBE_DEFAULT);
1383 default:
1384 device_set_desc(dev, "Creative CT5880-?");
1385 device_printf(dev,
1386 "unknown revision %d -- please report to "
1387 "freebsd-multimedia@freebsd.org\n",
1388 pci_get_revid(dev));
1389 return (BUS_PROBE_DEFAULT);
1390 }
1391 default:
1392 return (ENXIO);
1393 }
1394}
1395
1396static int
1397sysctl_es137x_spdif_enable(SYSCTL_HANDLER_ARGS)
1398{
1399 struct es_info *es;
1400 device_t dev;
1401 uint32_t r;
1402 int err, new_en;
1403
1404 dev = oidp->oid_arg1;
1405 es = pcm_getdevinfo(dev);
1406 ES_LOCK(es);
1407 r = es_rd(es, ES1370_REG_STATUS, 4);
1408 ES_UNLOCK(es);
1409 new_en = (r & ENABLE_SPDIF) ? 1 : 0;
1410 err = sysctl_handle_int(oidp, &new_en, 0, req);
1411
1412 if (err || req->newptr == NULL)
1413 return (err);
1414 if (new_en < 0 || new_en > 1)
1415 return (EINVAL);
1416
1417 ES_LOCK(es);
1418 if (new_en) {
1419 r |= ENABLE_SPDIF;
1420 es->ctrl |= SPDIFEN_B;
1421 es->ctrl |= RECEN_B;
1422 } else {
1423 r &= ~ENABLE_SPDIF;
1424 es->ctrl &= ~SPDIFEN_B;
1425 es->ctrl &= ~RECEN_B;
1426 }
1427 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
1428 es_wr(es, ES1370_REG_STATUS, r, 4);
1429 ES_UNLOCK(es);
1430
1431 return (0);
1432}
1433
1434static int
1436{
1437 struct es_info *es;
1438 device_t dev;
1439 uint32_t val;
1440 int err;
1441
1442 dev = oidp->oid_arg1;
1443 es = pcm_getdevinfo(dev);
1444 ES_LOCK(es);
1445 val = pci_read_config(dev, PCIR_LATTIMER, 1);
1446 ES_UNLOCK(es);
1447 err = sysctl_handle_int(oidp, &val, 0, req);
1448
1449 if (err || req->newptr == NULL)
1450 return (err);
1451 if (val > 255)
1452 return (EINVAL);
1453
1454 ES_LOCK(es);
1455 pci_write_config(dev, PCIR_LATTIMER, val, 1);
1456 ES_UNLOCK(es);
1457
1458 return (0);
1459}
1460
1461static int
1462sysctl_es137x_fixed_rate(SYSCTL_HANDLER_ARGS)
1463{
1464 struct es_info *es;
1465 device_t dev;
1466 uint32_t val;
1467 int err;
1468
1469 dev = oidp->oid_arg1;
1470 es = pcm_getdevinfo(dev);
1471 ES_LOCK(es);
1472 val = ES_FIXED_RATE(es->escfg);
1473 if (val < es_caps.minspeed)
1474 val = 0;
1475 ES_UNLOCK(es);
1476 err = sysctl_handle_int(oidp, &val, 0, req);
1477
1478 if (err || req->newptr == NULL)
1479 return (err);
1480 if (val != 0 && (val < es_caps.minspeed || val > es_caps.maxspeed))
1481 return (EINVAL);
1482
1483 ES_LOCK(es);
1484 if (es->ctrl & (CTRL_DAC2_EN|CTRL_ADC_EN)) {
1485 ES_UNLOCK(es);
1486 return (EBUSY);
1487 }
1488 if (val) {
1489 if (val != ES_FIXED_RATE(es->escfg)) {
1490 es->escfg = ES_SET_FIXED_RATE(es->escfg, val);
1491 es->ch[ES_DAC2].caps.maxspeed = val;
1492 es->ch[ES_DAC2].caps.minspeed = val;
1493 es->ch[ES_ADC].caps.maxspeed = val;
1494 es->ch[ES_ADC].caps.minspeed = val;
1495 es->ctrl &= ~CTRL_PCLKDIV;
1497 es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4);
1498 }
1499 } else {
1500 es->escfg = ES_SET_FIXED_RATE(es->escfg, 0);
1501 es->ch[ES_DAC2].caps = es_caps;
1502 es->ch[ES_ADC].caps = es_caps;
1503 }
1504 ES_UNLOCK(es);
1505
1506 return (0);
1507}
1508
1509static int
1511{
1512 struct es_info *es;
1513 struct snddev_info *d;
1514 struct snd_mixer *m;
1515 device_t dev;
1516 uint32_t val, set;
1517 int recsrc, level, err;
1518
1519 dev = oidp->oid_arg1;
1520 d = device_get_softc(dev);
1521 if (!PCM_REGISTERED(d) || d->mixer_dev == NULL ||
1522 d->mixer_dev->si_drv1 == NULL)
1523 return (EINVAL);
1524 es = d->devinfo;
1525 if (es == NULL)
1526 return (EINVAL);
1527 ES_LOCK(es);
1529 val = set;
1530 ES_UNLOCK(es);
1531 err = sysctl_handle_int(oidp, &val, 0, req);
1532
1533 if (err || req->newptr == NULL)
1534 return (err);
1535 if (!(val == 0 || val == 1))
1536 return (EINVAL);
1537 if (val == set)
1538 return (0);
1540 m = (d->mixer_dev != NULL) ? d->mixer_dev->si_drv1 : NULL;
1541 if (m == NULL) {
1543 return (ENODEV);
1544 }
1545 if (mixer_busy(m) != 0) {
1547 return (EBUSY);
1548 }
1549 level = mix_get(m, SOUND_MIXER_PCM);
1551 if (level < 0 || recsrc < 0) {
1553 return (ENXIO);
1554 }
1555
1556 ES_LOCK(es);
1557 if (es->ctrl & (CTRL_ADC_EN | CTRL_DAC1_EN | CTRL_DAC2_EN)) {
1558 ES_UNLOCK(es);
1560 return (EBUSY);
1561 }
1562 if (val)
1563 es->escfg = ES_SET_SINGLE_PCM_MIX(es->escfg, 1);
1564 else
1565 es->escfg = ES_SET_SINGLE_PCM_MIX(es->escfg, 0);
1566 ES_UNLOCK(es);
1567 if (!val) {
1568 mix_setdevs(m, mix_getdevs(m) | (1 << SOUND_MIXER_SYNTH));
1569 mix_setrecdevs(m, mix_getrecdevs(m) | (1 << SOUND_MIXER_SYNTH));
1570 err = mix_set(m, SOUND_MIXER_SYNTH, level & 0x7f,
1571 (level >> 8) & 0x7f);
1572 } else {
1573 err = mix_set(m, SOUND_MIXER_SYNTH, level & 0x7f,
1574 (level >> 8) & 0x7f);
1575 mix_setdevs(m, mix_getdevs(m) & ~(1 << SOUND_MIXER_SYNTH));
1577 ~(1 << SOUND_MIXER_SYNTH));
1578 }
1579 if (!err) {
1580 level = recsrc;
1581 if (recsrc & (1 << SOUND_MIXER_PCM))
1582 recsrc |= 1 << SOUND_MIXER_SYNTH;
1583 else if (recsrc & (1 << SOUND_MIXER_SYNTH))
1584 recsrc |= 1 << SOUND_MIXER_PCM;
1585 if (level != recsrc)
1586 err = mix_setrecsrc(m, recsrc);
1587 }
1588
1590
1591 return (err);
1592}
1593
1594static int
1595sysctl_es_polling(SYSCTL_HANDLER_ARGS)
1596{
1597 struct es_info *es;
1598 device_t dev;
1599 int err, val;
1600
1601 dev = oidp->oid_arg1;
1602 es = pcm_getdevinfo(dev);
1603 if (es == NULL)
1604 return (EINVAL);
1605 ES_LOCK(es);
1606 val = es->polling;
1607 ES_UNLOCK(es);
1608 err = sysctl_handle_int(oidp, &val, 0, req);
1609
1610 if (err || req->newptr == NULL)
1611 return (err);
1612 if (val < 0 || val > 1)
1613 return (EINVAL);
1614
1615 ES_LOCK(es);
1616 if (val != es->polling) {
1617 if (es_chan_active(es) != 0)
1618 err = EBUSY;
1619 else if (val == 0)
1620 es->polling = 0;
1621 else
1622 es->polling = 1;
1623 }
1624 ES_UNLOCK(es);
1625
1626 return (err);
1627}
1628
1629static void
1631{
1632 struct es_info *es;
1633 int r, devid, revid;
1634
1635 devid = pci_get_devid(dev);
1636 revid = pci_get_revid(dev);
1637 es = pcm_getdevinfo(dev);
1643 /* XXX: an user should be able to set this with a control tool,
1644 if not done before 7.0-RELEASE, this needs to be converted
1645 to a device specific sysctl "dev.pcm.X.yyy" via
1646 device_get_sysctl_*() as discussed on multimedia@ in msg-id
1647 <861wujij2q.fsf@xps.des.no> */
1648 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1649 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1650 "spdif_enabled", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
1651 dev, sizeof(dev), sysctl_es137x_spdif_enable, "I",
1652 "Enable S/PDIF output on primary playback channel");
1653 } else if (devid == ES1370_PCI_ID) {
1654 /*
1655 * Enable fixed rate sysctl if both DAC2 / ADC enabled.
1656 */
1657 if (es->ch[ES_DAC2].channel != NULL &&
1658 es->ch[ES_ADC].channel != NULL) {
1659 /* XXX: an user should be able to set this with a control tool,
1660 if not done before 7.0-RELEASE, this needs to be converted
1661 to a device specific sysctl "dev.pcm.X.yyy" via
1662 device_get_sysctl_*() as discussed on multimedia@ in msg-id
1663 <861wujij2q.fsf@xps.des.no> */
1664 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1665 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1666 OID_AUTO, "fixed_rate",
1667 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
1668 dev, sizeof(dev), sysctl_es137x_fixed_rate, "I",
1669 "Enable fixed rate playback/recording");
1670 }
1671 /*
1672 * Enable single pcm mixer sysctl if both DAC1/2 enabled.
1673 */
1674 if (es->ch[ES_DAC1].channel != NULL &&
1675 es->ch[ES_DAC2].channel != NULL) {
1676 /* XXX: an user should be able to set this with a control tool,
1677 if not done before 7.0-RELEASE, this needs to be converted
1678 to a device specific sysctl "dev.pcm.X.yyy" via
1679 device_get_sysctl_*() as discussed on multimedia@ in msg-id
1680 <861wujij2q.fsf@xps.des.no> */
1681 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1682 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1683 OID_AUTO, "single_pcm_mixer",
1684 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev,
1685 sizeof(dev), sysctl_es137x_single_pcm_mixer, "I",
1686 "Single PCM mixer controller for both DAC1/DAC2");
1687 }
1688 }
1689 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
1690 "latency_timer", &r) == 0 && !(r < 0 || r > 255))
1691 pci_write_config(dev, PCIR_LATTIMER, r, 1);
1692 /* XXX: this needs to be converted to a device specific sysctl
1693 "dev.pcm.X.yyy" via device_get_sysctl_*() as discussed on
1694 multimedia@ in msg-id <861wujij2q.fsf@xps.des.no> */
1695 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1696 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1697 "latency_timer", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
1698 dev, sizeof(dev), sysctl_es137x_latency_timer, "I",
1699 "PCI Latency Timer configuration");
1700 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1701 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1702 "polling", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev,
1703 sizeof(dev), sysctl_es_polling, "I", "Enable polling mode");
1704}
1705
1706static int
1708{
1709 struct es_info *es = NULL;
1710 int mapped, i, numplay, dac_cfg;
1711 char status[SND_STATUSLEN];
1712 struct ac97_info *codec = NULL;
1713 kobj_class_t ct = NULL;
1714 uint32_t devid;
1715
1716 es = malloc(sizeof *es, M_DEVBUF, M_WAITOK | M_ZERO);
1717 es->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_es137x softc");
1718 es->dev = dev;
1719 es->escfg = 0;
1720 mapped = 0;
1721
1722 pci_enable_busmaster(dev);
1723 if (mapped == 0) {
1724 es->regid = MEM_MAP_REG;
1725 es->regtype = SYS_RES_MEMORY;
1726 es->reg = bus_alloc_resource_any(dev, es->regtype, &es->regid,
1727 RF_ACTIVE);
1728 if (es->reg)
1729 mapped++;
1730 }
1731 if (mapped == 0) {
1732 es->regid = PCIR_BAR(0);
1733 es->regtype = SYS_RES_IOPORT;
1734 es->reg = bus_alloc_resource_any(dev, es->regtype, &es->regid,
1735 RF_ACTIVE);
1736 if (es->reg)
1737 mapped++;
1738 }
1739 if (mapped == 0) {
1740 device_printf(dev, "unable to map register space\n");
1741 goto bad;
1742 }
1743
1744 es->st = rman_get_bustag(es->reg);
1745 es->sh = rman_get_bushandle(es->reg);
1746 callout_init(&es->poll_timer, 1);
1747 es->poll_ticks = 1;
1748
1749 if (resource_int_value(device_get_name(dev),
1750 device_get_unit(dev), "polling", &i) == 0 && i != 0)
1751 es->polling = 1;
1752 else
1753 es->polling = 0;
1754
1755 es->bufsz = pcm_getbuffersize(dev, 4096, ES_DEFAULT_BUFSZ, 65536);
1756 if (resource_int_value(device_get_name(dev),
1757 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
1758 i &= ES_BLK_ALIGN;
1759 if (i < ES_BLK_MIN)
1760 i = ES_BLK_MIN;
1761 es->blkcnt = es->bufsz / i;
1762 i = 0;
1763 while (es->blkcnt >> i)
1764 i++;
1765 es->blkcnt = 1 << (i - 1);
1766 if (es->blkcnt < ES_DMA_SEGS_MIN)
1767 es->blkcnt = ES_DMA_SEGS_MIN;
1768 else if (es->blkcnt > ES_DMA_SEGS_MAX)
1769 es->blkcnt = ES_DMA_SEGS_MAX;
1770
1771 } else
1772 es->blkcnt = 2;
1773
1774 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
1775 "dac", &dac_cfg) == 0) {
1776 if (dac_cfg < 0 || dac_cfg > 3)
1777 dac_cfg = ES_DEFAULT_DAC_CFG;
1778 } else
1779 dac_cfg = ES_DEFAULT_DAC_CFG;
1780
1781 switch (dac_cfg) {
1782 case 0: /* Enable all DAC: DAC1, DAC2 */
1783 numplay = 2;
1784 es->escfg = ES_SET_DAC_FIRST(es->escfg, ES_DAC1);
1786 break;
1787 case 1: /* Only DAC1 */
1788 numplay = 1;
1789 es->escfg = ES_SET_DAC_FIRST(es->escfg, ES_DAC1);
1790 break;
1791 case 3: /* Enable all DAC / swap position: DAC2, DAC1 */
1792 numplay = 2;
1793 es->escfg = ES_SET_DAC_FIRST(es->escfg, ES_DAC2);
1795 break;
1796 case 2: /* Only DAC2 */
1797 default:
1798 numplay = 1;
1799 es->escfg = ES_SET_DAC_FIRST(es->escfg, ES_DAC2);
1800 break;
1801 }
1802 es->escfg = ES_SET_NUMPLAY(es->escfg, numplay);
1803 es->escfg = ES_SET_NUMREC(es->escfg, 1);
1804
1805 devid = pci_get_devid(dev);
1806 switch (devid) {
1807 case ES1371_PCI_ID:
1808 case ES1371_PCI_ID2:
1809 case CT5880_PCI_ID:
1810 case CT4730_PCI_ID:
1811 es1371_init(es);
1812 codec = AC97_CREATE(dev, es, es1371_ac97);
1813 if (codec == NULL)
1814 goto bad;
1815 /* our init routine does everything for us */
1816 /* set to NULL; flag mixer_init not to run the ac97_init */
1817 /* ac97_mixer.init = NULL; */
1818 if (mixer_init(dev, ac97_getmixerclass(), codec))
1819 goto bad;
1820 ct = &eschan1371_class;
1821 break;
1822 case ES1370_PCI_ID:
1823 es1370_init(es);
1824 /*
1825 * Disable fixed rate operation if DAC2 disabled.
1826 * This is a special case for es1370 only, where the
1827 * speed of both ADC and DAC2 locked together.
1828 */
1829 if (!ES_DAC2_ENABLED(es->escfg))
1830 es->escfg = ES_SET_FIXED_RATE(es->escfg, 0);
1831 if (mixer_init(dev, &es1370_mixer_class, es))
1832 goto bad;
1833 ct = &eschan1370_class;
1834 break;
1835 default:
1836 goto bad;
1837 /* NOTREACHED */
1838 }
1839
1840 es->irqid = 0;
1841 es->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &es->irqid,
1842 RF_ACTIVE | RF_SHAREABLE);
1843 if (!es->irq || snd_setup_intr(dev, es->irq, INTR_MPSAFE, es_intr,
1844 es, &es->ih)) {
1845 device_printf(dev, "unable to map interrupt\n");
1846 goto bad;
1847 }
1848
1849 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev),
1850 /*alignment*/2, /*boundary*/0,
1851 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
1852 /*highaddr*/BUS_SPACE_MAXADDR,
1853 /*filter*/NULL, /*filterarg*/NULL,
1854 /*maxsize*/es->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff,
1855 /*flags*/0, /*lockfunc*/NULL,
1856 /*lockarg*/NULL, &es->parent_dmat) != 0) {
1857 device_printf(dev, "unable to create dma tag\n");
1858 goto bad;
1859 }
1860
1861 snprintf(status, SND_STATUSLEN, "at %s 0x%jx irq %jd %s",
1862 (es->regtype == SYS_RES_IOPORT)? "io" : "memory",
1863 rman_get_start(es->reg), rman_get_start(es->irq),
1864 PCM_KLDSTRING(snd_es137x));
1865
1866 if (pcm_register(dev, es, numplay, 1))
1867 goto bad;
1868 for (i = 0; i < numplay; i++)
1869 pcm_addchan(dev, PCMDIR_PLAY, ct, es);
1870 pcm_addchan(dev, PCMDIR_REC, ct, es);
1873 es->escfg = ES_SET_GP(es->escfg, 0);
1874 if (numplay == 1)
1875 device_printf(dev, "<Playback: DAC%d / Record: ADC>\n",
1876 ES_DAC_FIRST(es->escfg) + 1);
1877 else if (numplay == 2)
1878 device_printf(dev, "<Playback: DAC%d,DAC%d / Record: ADC>\n",
1879 ES_DAC_FIRST(es->escfg) + 1, ES_DAC_SECOND(es->escfg) + 1);
1880 return (0);
1881
1882bad:
1883 if (es->parent_dmat)
1884 bus_dma_tag_destroy(es->parent_dmat);
1885 if (es->ih)
1886 bus_teardown_intr(dev, es->irq, es->ih);
1887 if (es->irq)
1888 bus_release_resource(dev, SYS_RES_IRQ, es->irqid, es->irq);
1889 if (codec)
1890 ac97_destroy(codec);
1891 if (es->reg)
1892 bus_release_resource(dev, es->regtype, es->regid, es->reg);
1893 if (es->lock)
1894 snd_mtxfree(es->lock);
1895 if (es)
1896 free(es, M_DEVBUF);
1897 return (ENXIO);
1898}
1899
1900static int
1902{
1903 int r;
1904 struct es_info *es;
1905
1906 r = pcm_unregister(dev);
1907 if (r)
1908 return (r);
1909
1910 es = pcm_getdevinfo(dev);
1911
1912 if (es != NULL && es->num != 0) {
1913 ES_LOCK(es);
1914 es->polling = 0;
1915 callout_stop(&es->poll_timer);
1916 ES_UNLOCK(es);
1917 callout_drain(&es->poll_timer);
1918 }
1919
1920 bus_teardown_intr(dev, es->irq, es->ih);
1921 bus_release_resource(dev, SYS_RES_IRQ, es->irqid, es->irq);
1922 bus_release_resource(dev, es->regtype, es->regid, es->reg);
1923 bus_dma_tag_destroy(es->parent_dmat);
1924 snd_mtxfree(es->lock);
1925 free(es, M_DEVBUF);
1926
1927 return (0);
1928}
1929
1930static device_method_t es_methods[] = {
1931 /* Device interface */
1932 DEVMETHOD(device_probe, es_pci_probe),
1933 DEVMETHOD(device_attach, es_pci_attach),
1934 DEVMETHOD(device_detach, es_pci_detach),
1935 { 0, 0 }
1936};
1937
1938static driver_t es_driver = {
1939 "pcm",
1940 es_methods,
1942};
1943
1944DRIVER_MODULE(snd_es137x, pci, es_driver, pcm_devclass, 0, 0);
1946MODULE_VERSION(snd_es137x, 1);
kobj_class_t ac97_getmixerclass(void)
Definition: ac97.c:1097
void ac97_destroy(struct ac97_info *codec)
Definition: ac97.c:860
#define AC97_CREATE(dev, devinfo, cls)
Definition: ac97.h:89
u_int32_t data
Definition: ac97_if.m:60
int regno
Definition: ac97_if.m:53
void * devinfo
Definition: ac97_if.m:47
uint16_t devid
Definition: atiixp.c:173
uint32_t format
Definition: audio_dai_if.m:39
METHOD int trigger
Definition: audio_dai_if.m:62
uint32_t speed
Definition: audio_dai_if.m:86
uint32_t rate
Definition: audio_dai_if.m:58
int go
Definition: audio_dai_if.m:64
int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
Definition: buffer.c:93
unsigned int sndbuf_getblkcnt(struct snd_dbuf *b)
Definition: buffer.c:391
bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf)
Definition: buffer.c:66
unsigned int sndbuf_getalign(struct snd_dbuf *b)
Definition: buffer.c:385
unsigned int sndbuf_getblksz(struct snd_dbuf *b)
Definition: buffer.c:403
unsigned int sndbuf_getmaxsize(struct snd_dbuf *b)
Definition: buffer.c:441
unsigned int sndbuf_getsize(struct snd_dbuf *b)
Definition: buffer.c:435
int sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
Definition: buffer.c:164
void chn_intr(struct pcm_channel *c)
Definition: channel.c:660
#define PCMDIR_PLAY
Definition: channel.h:339
#define PCMTRIG_START
Definition: channel.h:344
#define PCMDIR_REC
Definition: channel.h:341
#define PCMTRIG_COMMON(x)
Definition: channel.h:350
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
struct pcmchan_matrix * m
Definition: channel_if.m:232
struct snd_dbuf * b
Definition: channel_if.m:105
static uint32_t eschan1371_setspeed(kobj_t obj, void *data, uint32_t speed)
Definition: es137x.c:615
#define ES_DAC2
Definition: es137x.c:123
unsigned avail
Definition: es137x.c:264
#define ES_FIXED_RATE(cfgv)
Definition: es137x.c:161
#define ES1371REV_ES1373_A
Definition: es137x.c:108
static unsigned int es1371_dac_rate(struct es_info *, unsigned int, int)
Definition: es137x.c:1267
#define ES_SINGLE_PCM_MIX(cfgv)
Definition: es137x.c:165
#define es_chan_active(es)
Definition: es137x.c:684
#define ES_BLK_MIN
Definition: es137x.c:129
#define ES1371_PCI_ID
Definition: es137x.c:99
static void * eschan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
Definition: es137x.c:444
static void es_init_sysctls(device_t dev)
Definition: es137x.c:1630
static int sysctl_es137x_latency_timer(SYSCTL_HANDLER_ARGS)
Definition: es137x.c:1435
MODULE_VERSION(snd_es137x, 1)
static int sysctl_es137x_spdif_enable(SYSCTL_HANDLER_ARGS)
Definition: es137x.c:1397
#define CT5880REV_CT5880_C
Definition: es137x.c:113
static uint32_t eschan1370_setspeed(kobj_t obj, void *data, uint32_t speed)
Definition: es137x.c:570
#define MEM_MAP_REG
Definition: es137x.c:95
#define ES_LOCK(sc)
Definition: es137x.c:234
static uint32_t eschan_setblocksize(kobj_t obj, void *data, uint32_t blksz)
Definition: es137x.c:674
static void es_intr(void *)
Definition: es137x.c:921
#define ES_DMA_SEGS_MAX
Definition: es137x.c:128
#define ES1371REV_CT5880_A
Definition: es137x.c:111
#define ES_LOCK_ASSERT(sc)
Definition: es137x.c:236
#define ES_SET_NUMPLAY(cfgv, nv)
Definition: es137x.c:179
static int es_pci_attach(device_t dev)
Definition: es137x.c:1707
static unsigned int es1371_src_read(struct es_info *es, unsigned short reg)
Definition: es137x.c:1204
MODULE_DEPEND(snd_es137x, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
#define ES1370_DAC1_MINSPEED
Definition: es137x.c:132
static uint32_t eschan_getptr(kobj_t obj, void *data)
Definition: es137x.c:855
#define ES_SET_GP(cfgv, nv)
Definition: es137x.c:191
CHANNEL_DECLARE(eschan1370)
#define ES_DAC1_ENABLED(cfgv)
Definition: es137x.c:194
#define ES1371REV_ES1371_B
Definition: es137x.c:105
#define ES_DEFAULT_DAC_CFG
Definition: es137x.c:209
#define ES1371REV_ES1371_A
Definition: es137x.c:104
static kobj_method_t es1371_ac97_methods[]
Definition: es137x.c:1194
static kobj_method_t eschan1371_methods[]
Definition: es137x.c:905
unsigned stereo
Definition: es137x.c:262
AC97_DECLARE(es1371_ac97)
static driver_t es_driver
Definition: es137x.c:1938
#define ES_SET_NUMREC(cfgv, nv)
Definition: es137x.c:183
static struct pcmchan_caps * eschan_getcaps(kobj_t obj, void *data)
Definition: es137x.c:885
static int sysctl_es137x_fixed_rate(SYSCTL_HANDLER_ARGS)
Definition: es137x.c:1462
#define ES_SET_IS_ES1370(cfgv, nv)
Definition: es137x.c:187
#define ES_SET_FIXED_RATE(cfgv, nv)
Definition: es137x.c:163
#define ES1370_PCI_ID
Definition: es137x.c:98
static kobj_method_t eschan1370_methods[]
Definition: es137x.c:892
SND_DECLARE_FILE("$FreeBSD$")
#define ES_DMA_SEGS_MIN
Definition: es137x.c:127
static int es1371_rdcd(kobj_t obj, void *s, int addr)
Definition: es137x.c:1150
static int es1371_wrcd(kobj_t obj, void *s, int addr, uint32_t data)
Definition: es137x.c:1112
#define CT5880_PCI_ID
Definition: es137x.c:101
static int es1370_mixinit(struct snd_mixer *m)
Definition: es137x.c:314
#define ES_DEFAULT_BUFSZ
Definition: es137x.c:119
static int es1370_init(struct es_info *)
Definition: es137x.c:959
unsigned volidx
Definition: es137x.c:259
static int es1371_init(struct es_info *)
Definition: es137x.c:1024
#define ES_NUMPLAY(cfgv)
Definition: es137x.c:177
static int es1370_mixset(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
Definition: es137x.c:348
#define ES_ADC
Definition: es137x.c:124
#define ES_GP(cfgv)
Definition: es137x.c:189
#define ES_DAC_FIRST(cfgv)
Definition: es137x.c:169
unsigned recmask
Definition: es137x.c:263
static int es_pci_probe(device_t dev)
Definition: es137x.c:1318
MIXER_DECLARE(es1370_mixer)
static __inline uint32_t es_rd(struct es_info *es, int regno, int size)
Definition: es137x.c:279
static unsigned int es1371_adc_rate(struct es_info *, unsigned int, int)
Definition: es137x.c:1227
#define ES_DAC1
Definition: es137x.c:122
#define ES_SET_DAC_FIRST(cfgv, nv)
Definition: es137x.c:171
unsigned right
Definition: es137x.c:261
#define ES_UNLOCK(sc)
Definition: es137x.c:235
static int es_pci_detach(device_t dev)
Definition: es137x.c:1901
static uint32_t es1370_mixsetrecsrc(struct snd_mixer *m, uint32_t src)
Definition: es137x.c:384
static __inline int es_poll_channel(struct es_chinfo *ch)
Definition: es137x.c:689
#define ES1370_DAC1_MAXSPEED
Definition: es137x.c:133
#define CT5880REV_CT5880_D
Definition: es137x.c:114
#define ES_BLK_ALIGN
Definition: es137x.c:130
static void es1371_src_write(struct es_info *, unsigned short, unsigned short)
Definition: es137x.c:1216
static int eschan_trigger(kobj_t obj, void *data, int go)
Definition: es137x.c:757
static int eschan_setfragments(kobj_t obj, void *data, uint32_t blksz, uint32_t blkcnt)
Definition: es137x.c:635
static const struct @7 mixtable[SOUND_MIXER_NRDEVICES]
static int eschan_setformat(kobj_t obj, void *data, uint32_t format)
Definition: es137x.c:536
#define CT4730_PCI_ID
Definition: es137x.c:102
static device_method_t es_methods[]
Definition: es137x.c:1930
#define CT5880REV_CT5880_E
Definition: es137x.c:115
#define CT4730REV_CT4730_A
Definition: es137x.c:117
static __inline void es_wr(struct es_info *es, int regno, uint32_t data, int size)
Definition: es137x.c:294
static uint32_t es_fmt[]
Definition: es137x.c:249
#define ES_DAC_SECOND(cfgv)
Definition: es137x.c:173
unsigned left
Definition: es137x.c:260
#define ES1371REV_ES1373_B
Definition: es137x.c:109
#define ES_SET_SINGLE_PCM_MIX(cfgv, nv)
Definition: es137x.c:167
#define ES_IS_ES1370(cfgv)
Definition: es137x.c:185
static int sysctl_es137x_single_pcm_mixer(SYSCTL_HANDLER_ARGS)
Definition: es137x.c:1510
#define ES_SET_DAC_SECOND(cfgv, nv)
Definition: es137x.c:175
static struct pcmchan_caps es_caps
Definition: es137x.c:256
static void es_poll_callback(void *arg)
Definition: es137x.c:724
#define ES1371_PCI_ID2
Definition: es137x.c:100
static kobj_method_t es1370_mixer_methods[]
Definition: es137x.c:410
static int es1370_wrcodec(struct es_info *, unsigned char, unsigned char)
Definition: es137x.c:421
#define ES_NCHANS
Definition: es137x.c:125
DRIVER_MODULE(snd_es137x, pci, es_driver, pcm_devclass, 0, 0)
static uint32_t es1371_wait_src_ready(struct es_info *)
Definition: es137x.c:1296
#define ES_DAC2_ENABLED(cfgv)
Definition: es137x.c:197
static int sysctl_es_polling(SYSCTL_HANDLER_ARGS)
Definition: es137x.c:1595
#define ES1371REV_ES1373_8
Definition: es137x.c:107
#define CTRL_SERR_DIS
Definition: es137x.h:80
#define CODEC_CSEL
Definition: es137x.h:128
#define ES_SMPREG_VFREQ_FRAC
Definition: es137x.h:189
#define SCTRL_P1SEB
Definition: es137x.h:104
#define ES1370_REG_ADC_FRAMECNT
Definition: es137x.h:55
#define CODEC_PIDAT_SHIFT
Definition: es137x.h:141
#define SCTRL_P2ENDINC
Definition: es137x.h:82
#define SCTRL_R1SEB
Definition: es137x.h:96
#define SCTRL_P1INTEN
Definition: es137x.h:93
#define CTRL_DAC1_EN
Definition: es137x.h:74
#define STAT_DAC2
Definition: es137x.h:118
#define SCTRL_P2INTEN
Definition: es137x.h:92
#define ES1370_REG_DAC2_SCOUNT
Definition: es137x.h:47
#define CODEC_PIDAT_MASK
Definition: es137x.h:140
#define ES1370_REG_SERIAL_CONTROL
Definition: es137x.h:153
#define CTRL_JYSTK_EN
Definition: es137x.h:78
#define CODEC_RES_PD
Definition: es137x.h:127
#define CODEC_WIP
Definition: es137x.h:150
#define CODEC_PODAT_MASK
Definition: es137x.h:146
#define CODEC_PODAT_SHIFT
Definition: es137x.h:147
#define ES1370_REG_ADC_SCOUNT
Definition: es137x.h:48
#define SCTRL_SH_P2ENDINC
Definition: es137x.h:83
#define CTRL_ADC_EN
Definition: es137x.h:76
#define CTRL_CDC_EN
Definition: es137x.h:79
#define CODEC_POADD_MASK
Definition: es137x.h:144
#define SCTRL_P2DACSEN
Definition: es137x.h:95
#define ES1370_REG_CODEC
Definition: es137x.h:43
#define RECEN_B
Definition: es137x.h:174
#define SCTRL_R1INTEN
Definition: es137x.h:91
#define STAT_CSTAT
Definition: es137x.h:110
#define ES1370_REG_MEMPAGE
Definition: es137x.h:42
#define SCTRL_P2SMB
Definition: es137x.h:101
#define CTRL_SH_WTSRSEL
Definition: es137x.h:68
#define ES1371_DIS_SRC
Definition: es137x.h:162
#define ES1371_REG_SMPRATE
Definition: es137x.h:156
#define STAT_INTR
Definition: es137x.h:109
#define CTRL_SH_PCLKDIV
Definition: es137x.h:64
#define CODEC_OMIX2
Definition: es137x.h:122
#define ES1371_SRC_RAM_WE
Definition: es137x.h:164
#define SCTRL_P2SEB
Definition: es137x.h:100
#define CODEC_RIMIX1
Definition: es137x.h:124
#define SCTRL_P1SCTRLD
Definition: es137x.h:94
#define ES1371_DIS_P1
Definition: es137x.h:161
#define ES1371_SRC_RAM_DATAO(o)
Definition: es137x.h:166
#define CODEC_POADD_SHIFT
Definition: es137x.h:145
#define CODEC_PORD
Definition: es137x.h:143
#define ES_SMPREG_ADC
Definition: es137x.h:186
#define SCTRL_P1SMB
Definition: es137x.h:105
#define ES1370_REG_DAC2_FRAMECNT
Definition: es137x.h:53
#define ES1371_REG_LEGACY
Definition: es137x.h:155
#define ES_SMPREG_INT_REGS
Definition: es137x.h:188
#define ES1371_DIS_P2
Definition: es137x.h:160
#define ES_SMPREG_VOL_DAC2
Definition: es137x.h:192
#define ES1371_SRC_RAM_ADDRO(o)
Definition: es137x.h:165
#define SCTRL_P2LOOPSEL
Definition: es137x.h:87
#define ES1371_SYNC_RES
Definition: es137x.h:158
#define ES_SMPREG_VOL_DAC1
Definition: es137x.h:191
#define CODEC_RDY
Definition: es137x.h:149
#define CODEC_LIMIX2
Definition: es137x.h:125
#define ES1371_SRC_RAM_BUSY
Definition: es137x.h:163
#define ES1370_REG_DAC1_SCOUNT
Definition: es137x.h:46
#define ES1370_REG_DAC2_FRAMEADR
Definition: es137x.h:52
#define CODEC_OMIX1
Definition: es137x.h:121
#define ES1370_REG_STATUS
Definition: es137x.h:37
#define CODEC_INDEX_SHIFT
Definition: es137x.h:44
#define SCTRL_P1LOOPSEL
Definition: es137x.h:88
#define ENABLE_SPDIF
Definition: es137x.h:177
#define SCTRL_P2STINC
Definition: es137x.h:84
#define ES1371_REG_CODEC
Definition: es137x.h:154
#define CTRL_DAC2_EN
Definition: es137x.h:75
#define ES1371_SRC_RAM_DATAI(i)
Definition: es137x.h:167
#define ES_SMPREG_DAC2
Definition: es137x.h:185
#define SCTRL_P2PAUSE
Definition: es137x.h:89
#define DAC2_SRTODIV(x)
Definition: es137x.h:57
#define ES1370_REG_CONTROL
Definition: es137x.h:152
#define ES1370_REG_DAC1_FRAMECNT
Definition: es137x.h:51
#define CODEC_ADSEL
Definition: es137x.h:129
#define SPDIFEN_B
Definition: es137x.h:175
#define SCTRL_P1PAUSE
Definition: es137x.h:90
#define ES_SMPREG_VOL_ADC
Definition: es137x.h:190
#define ES1370_REG_ADC_FRAMEADR
Definition: es137x.h:54
#define ES1370_REG_DAC1_FRAMEADR
Definition: es137x.h:50
#define STAT_DAC1
Definition: es137x.h:117
#define CODEC_MGAIN
Definition: es137x.h:130
#define ES_SMPREG_TRUNC_N
Definition: es137x.h:187
#define CODEC_LIMIX1
Definition: es137x.h:123
#define ES_SMPREG_DAC1
Definition: es137x.h:184
#define ES1371_DIS_R1
Definition: es137x.h:159
#define CODEC_RIMIX2
Definition: es137x.h:126
#define STAT_ADC
Definition: es137x.h:119
#define SCTRL_R1SMB
Definition: es137x.h:97
uint32_t set
Definition: hdaa_patches.c:56
uint8_t reg
Definition: hdac.c:211
int blksz
Definition: hdac_if.m:64
int dir
Definition: hdac_if.m:45
int blkcnt
Definition: hdac_if.m:65
uint16_t revid
Definition: hdacc.c:74
uint8_t size
uint8_t r
uint8_t n
#define KOBJMETHOD_END
Definition: midi.c:76
static int mixer_setrecsrc(struct snd_mixer *mixer, u_int32_t src)
Definition: mixer.c:373
int mixer_busy(struct snd_mixer *m)
Definition: mixer.c:994
u_int32_t mix_getrecsrc(struct snd_mixer *m)
Definition: mixer.c:1044
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
Definition: mixer.c:725
static int mixer_set(struct snd_mixer *m, u_int dev, u_int32_t muted, u_int lev)
Definition: mixer.c:247
u_int32_t mix_getdevs(struct snd_mixer *m)
Definition: mixer.c:627
void mix_setdevs(struct snd_mixer *m, u_int32_t v)
Definition: mixer.c:489
int mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
Definition: mixer.c:1030
u_int32_t mix_getrecdevs(struct snd_mixer *m)
Definition: mixer.c:639
int mix_set(struct snd_mixer *m, u_int dev, u_int left, u_int right)
Definition: mixer.c:1002
void * mix_getdevinfo(struct snd_mixer *m)
Definition: mixer.c:645
void mix_setrecdevs(struct snd_mixer *m, u_int32_t v)
Record mask of available recording devices.
Definition: mixer.c:529
int mix_get(struct snd_mixer *m, u_int dev)
Definition: mixer.c:1016
unsigned dev
Definition: mixer_if.m:59
u_int32_t src
Definition: mixer_if.m:66
bool * status
u_int32_t val
uint64_t * addr
#define PCIR_BAR(x)
#define PCIR_LATTIMER
void * snd_mtxcreate(const char *desc, const char *type)
Definition: sound.c:88
void * pcm_getdevinfo(device_t dev)
Definition: sound.c:832
int pcm_setstatus(device_t dev, char *str)
Definition: sound.c:766
devclass_t pcm_devclass
Definition: sound.c:49
void snd_mtxfree(void *m)
Definition: sound.c:98
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
Definition: sound.c:692
int pcm_unregister(device_t dev)
Definition: sound.c:1170
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
Definition: sound.c:1080
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
Definition: sound.c:117
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
Definition: sound.c:840
#define PCM_KLDSTRING(a)
Definition: sound.h:619
#define SND_FORMAT(f, c, e)
Definition: sound.h:238
#define PCM_RELEASE_QUICK(x)
Definition: sound.h:573
#define SOUND_PREFVER
Definition: sound.h:103
#define SOUND_MAXVER
Definition: sound.h:104
#define DSP_DEFAULT_SPEED
Definition: sound.h:295
#define AFMT_CHANNEL(v)
Definition: sound.h:227
#define SOUND_MINVER
Definition: sound.h:102
#define PCM_SOFTC_SIZE
Definition: sound.h:96
#define PCM_ACQUIRE_QUICK(x)
Definition: sound.h:565
#define SND_STATUSLEN
Definition: sound.h:98
#define PCM_REGISTERED(x)
Definition: sound.h:178
#define AFMT_16BIT
Definition: sound.h:191
Definition: ac97.c:59
struct pcmchan_caps caps
Definition: es137x.c:142
int dir
Definition: es137x.c:143
uint32_t blkcnt
Definition: es137x.c:144
uint32_t prevptr
Definition: es137x.c:145
int index
Definition: es137x.c:143
struct pcm_channel * channel
Definition: es137x.c:140
uint32_t ptr
Definition: es137x.c:145
struct snd_dbuf * buffer
Definition: es137x.c:141
uint32_t blksz
Definition: es137x.c:144
struct es_info * parent
Definition: es137x.c:139
int num
Definition: es137x.c:143
uint32_t fmt
Definition: es137x.c:144
uint32_t bufsz
Definition: es137x.c:144
int active
Definition: es137x.c:146
uint32_t ctrl
Definition: es137x.c:225
int regtype
Definition: es137x.c:217
uint32_t escfg
Definition: es137x.c:227
int irqid
Definition: es137x.c:217
struct callout poll_timer
Definition: es137x.c:230
bus_space_handle_t sh
Definition: es137x.c:213
int regid
Definition: es137x.c:217
unsigned int bufsz
Definition: es137x.c:222
int polling
Definition: es137x.c:231
int num
Definition: es137x.c:221
struct mtx * lock
Definition: es137x.c:229
struct es_chinfo ch[ES_NCHANS]
Definition: es137x.c:228
device_t dev
Definition: es137x.c:220
unsigned int blkcnt
Definition: es137x.c:222
bus_dma_tag_t parent_dmat
Definition: es137x.c:214
int poll_ticks
Definition: es137x.c:231
void * ih
Definition: es137x.c:218
struct resource * irq
Definition: es137x.c:216
uint32_t sctrl
Definition: es137x.c:226
struct resource * reg
Definition: es137x.c:216
bus_space_tag_t st
Definition: es137x.c:212
u_int32_t maxspeed
Definition: channel.h:34
u_int32_t minspeed
Definition: channel.h:34
u_int16_t level[32]
Definition: mixer.c:62
u_int32_t recsrc
Definition: mixer.c:61
struct cdev * mixer_dev
Definition: sound.h:403
void * devinfo
Definition: sound.h:399
const void * req