Deleted Added
sdiff udiff text old ( 55204 ) new ( 55209 )
full compact
1/*
2 * Support the ENSONIQ AudioPCI board and Creative Labs SoundBlaster PCI
3 * boards based on the ES1370, ES1371 and ES1373 chips.
4 *
5 * Copyright (c) 1999 Russell Cattelan <cattelan@thebarn.com>
6 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
7 * Copyright (c) 1998 by Joachim Kuebart. All rights reserved.
8 *

--- 24 unchanged lines hidden (view full) ---

33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * $FreeBSD: head/sys/dev/sound/pci/es137x.c 55204 1999-12-29 03:46:54Z cg $
42 */
43
44/*
45 * Part of this code was heavily inspired by the linux driver from
46 * Thomas Sailer (sailer@ife.ee.ethz.ch)
47 * Just about everything has been touched and reworked in some way but
48 * the all the underlying sequences/timing/register values are from
49 * Thomas' code.

--- 19 unchanged lines hidden (view full) ---

69
70/* PCI IDs of supported chips */
71#define ES1370_PCI_ID 0x50001274
72#define ES1371_PCI_ID 0x13711274
73
74/* device private data */
75struct es_info;
76
77typedef struct es_chinfo {
78 struct es_info *parent;
79 pcm_channel *channel;
80 snd_dbuf *buffer;
81 int dir, num;
82 u_int32_t fmt;
83} es_chinfo_t;
84
85typedef struct es_info {
86 bus_space_tag_t st;
87 bus_space_handle_t sh;
88 bus_dma_tag_t parent_dmat;
89
90 int num;
91 /* Contents of board's registers */
92 u_long ctrl;
93 u_long sctrl;
94 struct es_chinfo pch, rch;
95} es_info_t;
96
97/* -------------------------------------------------------------------- */
98
99/* prototypes */
100static void es_intr(void *);
101
102static void es1371_wrcodec(void *, int, u_int32_t);
103static u_int32_t es1371_rdcodec(void *, int);
104static u_int es1371_wait_src_ready(es_info_t *);
105static void es1371_src_write(es_info_t *, u_short, unsigned short);
106static u_int es1371_adc_rate(es_info_t *, u_int, int);
107static u_int es1371_dac_rate(es_info_t *, u_int, int);
108static int es1371_init(es_info_t *es);
109static int eschan1371_setspeed(void *data, u_int32_t speed);
110
111static int es1370_init(struct es_info *);
112static int es1370_wrcodec(struct es_info *, u_char, u_char);
113
114/* channel interface */
115static void *eschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir);
116static int eschan_setdir(void *data, int dir);
117static int eschan_setformat(void *data, u_int32_t format);
118static int eschan1370_setspeed(void *data, u_int32_t speed);
119static int eschan_setblocksize(void *data, u_int32_t blocksize);
120static int eschan_trigger(void *data, int go);
121static int eschan_getptr(void *data);
122static pcmchan_caps *eschan_getcaps(void *data);
123
124static pcmchan_caps es_playcaps = {
125 4000, 48000,
126 AFMT_STEREO | AFMT_U8 | AFMT_S16_LE,

--- 332 unchanged lines hidden (view full) ---

459 es1370_wrcodec(es, CODEC_ADSEL, 0);/* Recording source is mixer */
460 es1370_wrcodec(es, CODEC_MGAIN, 0);/* MIC amp is 0db */
461
462 return 0;
463}
464
465/* ES1371 specific */
466int
467es1371_init(struct es_info *es)
468{
469 int idx;
470
471 if (debug > 0) printf("es_init\n");
472
473 es->num = 0;
474 es->ctrl = 0;
475 es->sctrl = 0;
476 /* initialize the chips */
477 bus_space_write_4(es->st, es->sh, ES1370_REG_CONTROL, es->ctrl);
478 bus_space_write_4(es->st, es->sh, ES1370_REG_SERIAL_CONTROL, es->sctrl);
479 bus_space_write_4(es->st, es->sh, ES1371_REG_LEGACY, 0);
480 /* AC'97 warm reset to start the bitclk */
481 bus_space_write_4(es->st, es->sh, ES1371_REG_LEGACY, es->ctrl | ES1371_SYNC_RES);
482 DELAY(2000);
483 bus_space_write_4(es->st, es->sh, ES1370_REG_SERIAL_CONTROL, es->ctrl);
484 /* Init the sample rate converter */
485 bus_space_write_4(es->st, es->sh, ES1371_REG_SMPRATE, ES1371_DIS_SRC);

--- 101 unchanged lines hidden (view full) ---

587 for (t = 0; t < 0x1000; t++)
588 if ((x = bus_space_read_4(es->st, es->sh, ES1371_REG_CODEC)) & CODEC_RDY)
589 break;
590 if (debug > 0) printf("loop 3 t 0x%x 0x%x ret 0x%x\n", t, x, ((x & CODEC_PIDAT_MASK) >> CODEC_PIDAT_SHIFT));
591 return ((x & CODEC_PIDAT_MASK) >> CODEC_PIDAT_SHIFT);
592}
593
594static u_int
595es1371_src_read(es_info_t *es, u_short reg)
596{
597 unsigned int r;
598
599 r = es1371_wait_src_ready(es) &
600 (ES1371_DIS_SRC | ES1371_DIS_P1 | ES1371_DIS_P2 | ES1371_DIS_R1);
601 r |= ES1371_SRC_RAM_ADDRO(reg);
602 bus_space_write_4(es->st, es->sh, ES1371_REG_SMPRATE,r);
603 return ES1371_SRC_RAM_DATAI(es1371_wait_src_ready(es));
604}
605
606static void
607es1371_src_write(es_info_t *es, u_short reg, u_short data){
608 u_int r;
609
610 r = es1371_wait_src_ready(es) &
611 (ES1371_DIS_SRC | ES1371_DIS_P1 | ES1371_DIS_P2 | ES1371_DIS_R1);
612 r |= ES1371_SRC_RAM_ADDRO(reg) | ES1371_SRC_RAM_DATAO(data);
613 /* printf("es1371_src_write 0x%x 0x%x\n",ES1371_REG_SMPRATE,r | ES1371_SRC_RAM_WE); */
614 bus_space_write_4(es->st, es->sh, ES1371_REG_SMPRATE, r | ES1371_SRC_RAM_WE);
615}
616
617static u_int
618es1371_adc_rate(es_info_t *es, u_int rate, int set)
619{
620 u_int n, truncm, freq, result;
621
622 if (rate > 48000) rate = 48000;
623 if (rate < 4000) rate = 4000;
624 n = rate / 3000;
625 if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
626 n--;

--- 16 unchanged lines hidden (view full) ---

643 es1371_src_write(es, ES_SMPREG_ADC + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
644 es1371_src_write(es, ES_SMPREG_VOL_ADC, n << 8);
645 es1371_src_write(es, ES_SMPREG_VOL_ADC + 1, n << 8);
646 }
647 return result;
648}
649
650static u_int
651es1371_dac_rate(es_info_t *es, u_int rate, int set)
652{
653 u_int freq, r, result, dac, dis;
654
655 if (rate > 48000) rate = 48000;
656 if (rate < 4000) rate = 4000;
657 freq = (rate << 15) / 3000;
658 result = (freq * 3000) >> 15;
659 if (set) {

--- 7 unchanged lines hidden (view full) ---

667 es1371_src_write(es, dac + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff);
668 r = (es1371_wait_src_ready(es) & (ES1371_DIS_SRC | dis | ES1371_DIS_R1));
669 bus_space_write_4(es->st, es->sh, ES1371_REG_SMPRATE, r);
670 }
671 return result;
672}
673
674static u_int
675es1371_wait_src_ready(es_info_t *es)
676{
677 u_int t, r;
678
679 for (t = 0; t < 500; t++) {
680 if (!((r = bus_space_read_4(es->st, es->sh, ES1371_REG_SMPRATE)) & ES1371_SRC_RAM_BUSY))
681 return r;
682 DELAY(1000);
683 }

--- 69 unchanged lines hidden (view full) ---

753 }
754 }
755 if (mapped == 0) {
756 device_printf(dev, "unable to map register space\n");
757 goto bad;
758 }
759
760 if (pci_get_devid(dev) == ES1371_PCI_ID) {
761 if(-1 == es1371_init(es)) {
762 device_printf(dev, "unable to initialize the card\n");
763 goto bad;
764 }
765 codec = ac97_create(es, es1371_rdcodec, es1371_wrcodec);
766 if (codec == NULL) goto bad;
767 /* our init routine does everything for us */
768 /* set to NULL; flag mixer_init not to run the ac97_init */
769 /* ac97_mixer.init = NULL; */

--- 66 unchanged lines hidden ---