Lines Matching +full:chip +full:- +full:to +full:- +full:chip
8 * Rewritted from card-es1938.c source.
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 * A working Maestro setup contains the Maestro chip wired to a
39 * to release docs on. Thankfully it isn't required on the Maestro
41 * encoding. The codecs are almost always AC-97 compliant codecs,
43 * part?) wired to them. The only real difference in the Maestro
50 * mixers in the codecs. There are 64 APUs. We assign 6 to each
55 * 3 basic functions. For playback we use them to convert PCM
57 * is handed to the codec. One APU for mono, and a pair for stereo.
66 * to have a 512 byte buffer sitting around in wavecache/memory.
71 * It claims to fetch from 4 regions of PCI space, each 4 meg in length.
73 * allocations have to be in 4meg of each other. Booo. Hiss.
75 * the number of dsps to provide. All their buffer space is allocated
77 * power of 2 buffers, so we have all those next to each other, then
81 * just how to coerce the WP into doing what we want.
83 * The indirection of the various registers means we have to spinlock
90 * paths and it makes the code far easier to follow. Interrupts are
91 * blocked while holding the locks because the int handler has to
102 #include <linux/dma-mapping.h>
116 #include <sound/tea575x-tuner.h>
133 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
136 static int total_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1024 };
137 static int pcm_substreams_p[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4 };
138 static int pcm_substreams_c[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1 };
140 static int use_pm[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
141 static int enable_mpu[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
159 MODULE_PARM_DESC(clock, "Clock on " CARD_NAME " soundcard. (0 = auto-detect)");
161 MODULE_PARM_DESC(use_pm, "Toggle power-management. (0 = off, 1 = on, 2 = auto)");
310 /* APU Modes: reg 0x00, bit 4-7 */
314 #define ESM_APU_16BITLINEAR 0x01 /* 16-Bit Linear Sample Player */
315 #define ESM_APU_16BITSTEREO 0x02 /* 16-Bit Stereo Sample Player */
316 #define ESM_APU_8BITLINEAR 0x03 /* 8-Bit Linear Sample Player */
317 #define ESM_APU_8BITSTEREO 0x04 /* 8-Bit Stereo Sample Player */
318 #define ESM_APU_8BITDIFF 0x05 /* 8-Bit Differential Sample Playrer */
325 #define ESM_APU_16BITPINGPONG 0x0C /* 16-Bit Ping-Pong Sample Player */
365 /* reg 0x05 - wave start offset */
366 /* reg 0x06 - wave end offset */
367 /* reg 0x07 - wave loop length */
378 /* bit 0-7 amplitude dest? */
448 /* chip type */
518 int do_pm; /* power-management enabled */
584 static void __maestro_write(struct es1968 *chip, u16 reg, u16 data) in __maestro_write() argument
586 outw(reg, chip->io_port + ESM_INDEX); in __maestro_write()
587 outw(data, chip->io_port + ESM_DATA); in __maestro_write()
588 chip->maestro_map[reg] = data; in __maestro_write()
591 static inline void maestro_write(struct es1968 *chip, u16 reg, u16 data) in maestro_write() argument
594 spin_lock_irqsave(&chip->reg_lock, flags); in maestro_write()
595 __maestro_write(chip, reg, data); in maestro_write()
596 spin_unlock_irqrestore(&chip->reg_lock, flags); in maestro_write()
600 static u16 __maestro_read(struct es1968 *chip, u16 reg) in __maestro_read() argument
603 outw(reg, chip->io_port + ESM_INDEX); in __maestro_read()
604 chip->maestro_map[reg] = inw(chip->io_port + ESM_DATA); in __maestro_read()
606 return chip->maestro_map[reg]; in __maestro_read()
609 static inline u16 maestro_read(struct es1968 *chip, u16 reg) in maestro_read() argument
613 spin_lock_irqsave(&chip->reg_lock, flags); in maestro_read()
614 result = __maestro_read(chip, reg); in maestro_read()
615 spin_unlock_irqrestore(&chip->reg_lock, flags); in maestro_read()
619 /* Wait for the codec bus to be free */
620 static int snd_es1968_ac97_wait(struct es1968 *chip) in snd_es1968_ac97_wait() argument
624 while (timeout-- > 0) { in snd_es1968_ac97_wait()
625 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1)) in snd_es1968_ac97_wait()
633 static int snd_es1968_ac97_wait_poll(struct es1968 *chip) in snd_es1968_ac97_wait_poll() argument
637 while (timeout-- > 0) { in snd_es1968_ac97_wait_poll()
638 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1)) in snd_es1968_ac97_wait_poll()
647 struct es1968 *chip = ac97->private_data; in snd_es1968_ac97_write() local
649 snd_es1968_ac97_wait(chip); in snd_es1968_ac97_write()
652 outw(val, chip->io_port + ESM_AC97_DATA); in snd_es1968_ac97_write()
654 outb(reg, chip->io_port + ESM_AC97_INDEX); in snd_es1968_ac97_write()
661 struct es1968 *chip = ac97->private_data; in snd_es1968_ac97_read() local
663 snd_es1968_ac97_wait(chip); in snd_es1968_ac97_read()
665 outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX); in snd_es1968_ac97_read()
668 if (!snd_es1968_ac97_wait_poll(chip)) { in snd_es1968_ac97_read()
669 data = inw(chip->io_port + ESM_AC97_DATA); in snd_es1968_ac97_read()
677 static void apu_index_set(struct es1968 *chip, u16 index) in apu_index_set() argument
680 __maestro_write(chip, IDR1_CRAM_POINTER, index); in apu_index_set()
682 if (__maestro_read(chip, IDR1_CRAM_POINTER) == index) in apu_index_set()
688 static void apu_data_set(struct es1968 *chip, u16 data) in apu_data_set() argument
692 if (__maestro_read(chip, IDR0_DATA_PORT) == data) in apu_data_set()
694 __maestro_write(chip, IDR0_DATA_PORT, data); in apu_data_set()
700 static void __apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data) in __apu_set_register() argument
705 chip->apu_map[channel][reg] = data; in __apu_set_register()
708 apu_index_set(chip, reg); in __apu_set_register()
709 apu_data_set(chip, data); in __apu_set_register()
712 static void apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data) in apu_set_register() argument
715 spin_lock_irqsave(&chip->reg_lock, flags); in apu_set_register()
716 __apu_set_register(chip, channel, reg, data); in apu_set_register()
717 spin_unlock_irqrestore(&chip->reg_lock, flags); in apu_set_register()
720 static u16 __apu_get_register(struct es1968 *chip, u16 channel, u8 reg) in __apu_get_register() argument
725 apu_index_set(chip, reg); in __apu_get_register()
726 return __maestro_read(chip, IDR0_DATA_PORT); in __apu_get_register()
729 static u16 apu_get_register(struct es1968 *chip, u16 channel, u8 reg) in apu_get_register() argument
733 spin_lock_irqsave(&chip->reg_lock, flags); in apu_get_register()
734 v = __apu_get_register(chip, channel, reg); in apu_get_register()
735 spin_unlock_irqrestore(&chip->reg_lock, flags); in apu_get_register()
741 static void assp_set_register(struct es1968 *chip, u32 reg, u32 value)
745 spin_lock_irqsave(&chip->reg_lock, flags);
746 outl(reg, chip->io_port + ASSP_INDEX);
747 outl(value, chip->io_port + ASSP_DATA);
748 spin_unlock_irqrestore(&chip->reg_lock, flags);
751 static u32 assp_get_register(struct es1968 *chip, u32 reg)
756 spin_lock_irqsave(&chip->reg_lock, flags);
757 outl(reg, chip->io_port + ASSP_INDEX);
758 value = inl(chip->io_port + ASSP_DATA);
759 spin_unlock_irqrestore(&chip->reg_lock, flags);
766 static void wave_set_register(struct es1968 *chip, u16 reg, u16 value) in wave_set_register() argument
770 spin_lock_irqsave(&chip->reg_lock, flags); in wave_set_register()
771 outw(reg, chip->io_port + WC_INDEX); in wave_set_register()
772 outw(value, chip->io_port + WC_DATA); in wave_set_register()
773 spin_unlock_irqrestore(&chip->reg_lock, flags); in wave_set_register()
776 static u16 wave_get_register(struct es1968 *chip, u16 reg) in wave_get_register() argument
781 spin_lock_irqsave(&chip->reg_lock, flags); in wave_get_register()
782 outw(reg, chip->io_port + WC_INDEX); in wave_get_register()
783 value = inw(chip->io_port + WC_DATA); in wave_get_register()
784 spin_unlock_irqrestore(&chip->reg_lock, flags); in wave_get_register()
793 static void snd_es1968_bob_stop(struct es1968 *chip) in snd_es1968_bob_stop() argument
797 reg = __maestro_read(chip, 0x11); in snd_es1968_bob_stop()
799 __maestro_write(chip, 0x11, reg); in snd_es1968_bob_stop()
800 reg = __maestro_read(chip, 0x17); in snd_es1968_bob_stop()
802 __maestro_write(chip, 0x17, reg); in snd_es1968_bob_stop()
805 static void snd_es1968_bob_start(struct es1968 *chip) in snd_es1968_bob_start() argument
811 /* first, find best prescaler value to match freq */ in snd_es1968_bob_start()
813 if (chip->bob_freq > (ESS_SYSCLK >> (prescale + 9))) in snd_es1968_bob_start()
819 prescale--; in snd_es1968_bob_start()
824 /* now fine-tune the divider for best match */ in snd_es1968_bob_start()
826 if (chip->bob_freq > in snd_es1968_bob_start()
833 prescale--; in snd_es1968_bob_start()
835 divide--; in snd_es1968_bob_start()
837 __maestro_write(chip, 6, 0x9000 | (prescale << 5) | divide); /* set reg */ in snd_es1968_bob_start()
840 __maestro_write(chip, 0x11, __maestro_read(chip, 0x11) | 1); in snd_es1968_bob_start()
841 __maestro_write(chip, 0x17, __maestro_read(chip, 0x17) | 1); in snd_es1968_bob_start()
845 static void snd_es1968_bob_inc(struct es1968 *chip, int freq) in snd_es1968_bob_inc() argument
847 chip->bobclient++; in snd_es1968_bob_inc()
848 if (chip->bobclient == 1) { in snd_es1968_bob_inc()
849 chip->bob_freq = freq; in snd_es1968_bob_inc()
850 snd_es1968_bob_start(chip); in snd_es1968_bob_inc()
851 } else if (chip->bob_freq < freq) { in snd_es1968_bob_inc()
852 snd_es1968_bob_stop(chip); in snd_es1968_bob_inc()
853 chip->bob_freq = freq; in snd_es1968_bob_inc()
854 snd_es1968_bob_start(chip); in snd_es1968_bob_inc()
859 static void snd_es1968_bob_dec(struct es1968 *chip) in snd_es1968_bob_dec() argument
861 chip->bobclient--; in snd_es1968_bob_dec()
862 if (chip->bobclient <= 0) in snd_es1968_bob_dec()
863 snd_es1968_bob_stop(chip); in snd_es1968_bob_dec()
864 else if (chip->bob_freq > ESM_BOB_FREQ) { in snd_es1968_bob_dec()
868 list_for_each_entry(es, &chip->substream_list, list) { in snd_es1968_bob_dec()
869 if (max_freq < es->bob_freq) in snd_es1968_bob_dec()
870 max_freq = es->bob_freq; in snd_es1968_bob_dec()
872 if (max_freq != chip->bob_freq) { in snd_es1968_bob_dec()
873 snd_es1968_bob_stop(chip); in snd_es1968_bob_dec()
874 chip->bob_freq = max_freq; in snd_es1968_bob_dec()
875 snd_es1968_bob_start(chip); in snd_es1968_bob_dec()
881 snd_es1968_calc_bob_rate(struct es1968 *chip, struct esschan *es, in snd_es1968_calc_bob_rate() argument
885 int freq = runtime->rate * 4; in snd_es1968_calc_bob_rate()
886 if (es->fmt & ESS_FMT_STEREO) in snd_es1968_calc_bob_rate()
888 if (es->fmt & ESS_FMT_16BIT) in snd_es1968_calc_bob_rate()
890 freq /= es->frag_size; in snd_es1968_calc_bob_rate()
903 static u32 snd_es1968_compute_rate(struct es1968 *chip, u32 freq) in snd_es1968_compute_rate() argument
905 u32 rate = (freq << 16) / chip->clock; in snd_es1968_compute_rate()
915 snd_es1968_get_dma_ptr(struct es1968 *chip, struct esschan *es) in snd_es1968_get_dma_ptr() argument
919 offset = apu_get_register(chip, es->apu[0], 5); in snd_es1968_get_dma_ptr()
921 offset -= es->base[0]; in snd_es1968_get_dma_ptr()
926 static void snd_es1968_apu_set_freq(struct es1968 *chip, int apu, int freq) in snd_es1968_apu_set_freq() argument
928 apu_set_register(chip, apu, 2, in snd_es1968_apu_set_freq()
929 (apu_get_register(chip, apu, 2) & 0x00FF) | in snd_es1968_apu_set_freq()
931 apu_set_register(chip, apu, 3, freq >> 8); in snd_es1968_apu_set_freq()
943 static void snd_es1968_pcm_start(struct es1968 *chip, struct esschan *es) in snd_es1968_pcm_start() argument
945 spin_lock(&chip->reg_lock); in snd_es1968_pcm_start()
946 __apu_set_register(chip, es->apu[0], 5, es->base[0]); in snd_es1968_pcm_start()
947 snd_es1968_trigger_apu(chip, es->apu[0], es->apu_mode[0]); in snd_es1968_pcm_start()
948 if (es->mode == ESM_MODE_CAPTURE) { in snd_es1968_pcm_start()
949 __apu_set_register(chip, es->apu[2], 5, es->base[2]); in snd_es1968_pcm_start()
950 snd_es1968_trigger_apu(chip, es->apu[2], es->apu_mode[2]); in snd_es1968_pcm_start()
952 if (es->fmt & ESS_FMT_STEREO) { in snd_es1968_pcm_start()
953 __apu_set_register(chip, es->apu[1], 5, es->base[1]); in snd_es1968_pcm_start()
954 snd_es1968_trigger_apu(chip, es->apu[1], es->apu_mode[1]); in snd_es1968_pcm_start()
955 if (es->mode == ESM_MODE_CAPTURE) { in snd_es1968_pcm_start()
956 __apu_set_register(chip, es->apu[3], 5, es->base[3]); in snd_es1968_pcm_start()
957 snd_es1968_trigger_apu(chip, es->apu[3], es->apu_mode[3]); in snd_es1968_pcm_start()
960 spin_unlock(&chip->reg_lock); in snd_es1968_pcm_start()
963 static void snd_es1968_pcm_stop(struct es1968 *chip, struct esschan *es) in snd_es1968_pcm_stop() argument
965 spin_lock(&chip->reg_lock); in snd_es1968_pcm_stop()
966 snd_es1968_trigger_apu(chip, es->apu[0], 0); in snd_es1968_pcm_stop()
967 snd_es1968_trigger_apu(chip, es->apu[1], 0); in snd_es1968_pcm_stop()
968 if (es->mode == ESM_MODE_CAPTURE) { in snd_es1968_pcm_stop()
969 snd_es1968_trigger_apu(chip, es->apu[2], 0); in snd_es1968_pcm_stop()
970 snd_es1968_trigger_apu(chip, es->apu[3], 0); in snd_es1968_pcm_stop()
972 spin_unlock(&chip->reg_lock); in snd_es1968_pcm_stop()
976 static void snd_es1968_program_wavecache(struct es1968 *chip, struct esschan *es, in snd_es1968_program_wavecache() argument
979 u32 tmpval = (addr - 0x10) & 0xFFF8; in snd_es1968_program_wavecache()
982 if (!(es->fmt & ESS_FMT_16BIT)) in snd_es1968_program_wavecache()
984 if (es->fmt & ESS_FMT_STEREO) in snd_es1968_program_wavecache()
989 wave_set_register(chip, es->apu[channel] << 3, tmpval); in snd_es1968_program_wavecache()
992 es->wc_map[channel] = tmpval; in snd_es1968_program_wavecache()
997 static void snd_es1968_playback_setup(struct es1968 *chip, struct esschan *es, in snd_es1968_playback_setup() argument
1007 size = es->dma_size >> es->wav_shift; in snd_es1968_playback_setup()
1009 if (es->fmt & ESS_FMT_STEREO) in snd_es1968_playback_setup()
1013 apu = es->apu[channel]; in snd_es1968_playback_setup()
1015 snd_es1968_program_wavecache(chip, es, channel, es->memory->buf.addr, 0); in snd_es1968_playback_setup()
1017 /* Offset to PCMBAR */ in snd_es1968_playback_setup()
1018 pa = es->memory->buf.addr; in snd_es1968_playback_setup()
1019 pa -= chip->dma.addr; in snd_es1968_playback_setup()
1024 if (es->fmt & ESS_FMT_STEREO) { in snd_es1968_playback_setup()
1028 if (es->fmt & ESS_FMT_16BIT) in snd_es1968_playback_setup()
1034 es->base[channel] = pa & 0xFFFF; in snd_es1968_playback_setup()
1037 apu_set_register(chip, apu, i, 0x0000); in snd_es1968_playback_setup()
1040 apu_set_register(chip, apu, 4, ((pa >> 16) & 0xFF) << 8); in snd_es1968_playback_setup()
1041 apu_set_register(chip, apu, 5, pa & 0xFFFF); in snd_es1968_playback_setup()
1042 apu_set_register(chip, apu, 6, (pa + size) & 0xFFFF); in snd_es1968_playback_setup()
1044 apu_set_register(chip, apu, 7, size); in snd_es1968_playback_setup()
1047 apu_set_register(chip, apu, 8, 0x0000); in snd_es1968_playback_setup()
1048 /* set amp now to 0xd0 (?), low byte is 'amplitude dest'? */ in snd_es1968_playback_setup()
1049 apu_set_register(chip, apu, 9, 0xD000); in snd_es1968_playback_setup()
1052 apu_set_register(chip, apu, 11, 0x0000); in snd_es1968_playback_setup()
1053 /* dma on, no envelopes, filter to all 1s) */ in snd_es1968_playback_setup()
1054 apu_set_register(chip, apu, 0, 0x400F); in snd_es1968_playback_setup()
1056 if (es->fmt & ESS_FMT_16BIT) in snd_es1968_playback_setup()
1057 es->apu_mode[channel] = ESM_APU_16BITLINEAR; in snd_es1968_playback_setup()
1059 es->apu_mode[channel] = ESM_APU_8BITLINEAR; in snd_es1968_playback_setup()
1061 if (es->fmt & ESS_FMT_STEREO) { in snd_es1968_playback_setup()
1065 to the SPDif Link. Perhaps you have to change this in snd_es1968_playback_setup()
1066 and not the APU Regs 4-5. */ in snd_es1968_playback_setup()
1067 apu_set_register(chip, apu, 10, in snd_es1968_playback_setup()
1069 es->apu_mode[channel] += 1; /* stereo */ in snd_es1968_playback_setup()
1071 apu_set_register(chip, apu, 10, 0x8F08); in snd_es1968_playback_setup()
1074 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1968_playback_setup()
1076 outw(1, chip->io_port + 0x04); in snd_es1968_playback_setup()
1078 outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ); in snd_es1968_playback_setup()
1079 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1968_playback_setup()
1081 freq = runtime->rate; in snd_es1968_playback_setup()
1089 if (!(es->fmt & ESS_FMT_16BIT) && !(es->fmt & ESS_FMT_STEREO)) in snd_es1968_playback_setup()
1092 freq = snd_es1968_compute_rate(chip, freq); in snd_es1968_playback_setup()
1095 snd_es1968_apu_set_freq(chip, es->apu[0], freq); in snd_es1968_playback_setup()
1096 snd_es1968_apu_set_freq(chip, es->apu[1], freq); in snd_es1968_playback_setup()
1100 static void init_capture_apu(struct es1968 *chip, struct esschan *es, int channel, in init_capture_apu() argument
1104 int i, apu = es->apu[channel]; in init_capture_apu()
1106 es->apu_mode[channel] = mode; in init_capture_apu()
1109 snd_es1968_program_wavecache(chip, es, channel, pa, 1); in init_capture_apu()
1111 /* Offset to PCMBAR */ in init_capture_apu()
1112 pa -= chip->dma.addr; in init_capture_apu()
1117 es->base[channel] = pa & 0xFFFF; in init_capture_apu()
1118 pa |= 0x00400000; /* bit 22 -> System RAM */ in init_capture_apu()
1122 apu_set_register(chip, apu, i, 0x0000); in init_capture_apu()
1124 /* need to enable subgroups.. and we should probably in init_capture_apu()
1126 apu_set_register(chip, apu, 2, 0x8); in init_capture_apu()
1129 apu_set_register(chip, apu, 4, ((pa >> 16) & 0xFF) << 8); in init_capture_apu()
1130 apu_set_register(chip, apu, 5, pa & 0xFFFF); in init_capture_apu()
1131 apu_set_register(chip, apu, 6, (pa + bsize) & 0xFFFF); in init_capture_apu()
1132 apu_set_register(chip, apu, 7, bsize); in init_capture_apu()
1134 apu_set_register(chip, apu, 8, 0x00F0); in init_capture_apu()
1136 apu_set_register(chip, apu, 9, 0x0000); in init_capture_apu()
1138 apu_set_register(chip, apu, 10, 0x8F08); in init_capture_apu()
1140 apu_set_register(chip, apu, 11, route); in init_capture_apu()
1141 /* dma on, no envelopes, filter to all 1s) */ in init_capture_apu()
1142 apu_set_register(chip, apu, 0, 0x400F); in init_capture_apu()
1145 static void snd_es1968_capture_setup(struct es1968 *chip, struct esschan *es, in snd_es1968_capture_setup() argument
1152 size = es->dma_size >> es->wav_shift; in snd_es1968_capture_setup()
1160 /* data seems to flow from the codec, through an apu into in snd_es1968_capture_setup()
1162 and out to the real 'buffer'. ok. sure. */ in snd_es1968_capture_setup()
1165 /* parallel in crap, see maestro reg 0xC [8-11] */ in snd_es1968_capture_setup()
1166 init_capture_apu(chip, es, 2, in snd_es1968_capture_setup()
1167 es->mixbuf->buf.addr, ESM_MIXBUF_SIZE/4, /* in words */ in snd_es1968_capture_setup()
1170 init_capture_apu(chip, es, 0, es->memory->buf.addr, size, in snd_es1968_capture_setup()
1171 ESM_APU_SRCONVERTOR, es->apu[2]); in snd_es1968_capture_setup()
1172 if (es->fmt & ESS_FMT_STEREO) { in snd_es1968_capture_setup()
1174 init_capture_apu(chip, es, 3, in snd_es1968_capture_setup()
1175 es->mixbuf->buf.addr + ESM_MIXBUF_SIZE/2, in snd_es1968_capture_setup()
1179 init_capture_apu(chip, es, 1, in snd_es1968_capture_setup()
1180 es->memory->buf.addr + size*2, size, in snd_es1968_capture_setup()
1181 ESM_APU_SRCONVERTOR, es->apu[3]); in snd_es1968_capture_setup()
1184 freq = runtime->rate; in snd_es1968_capture_setup()
1191 freq = snd_es1968_compute_rate(chip, freq); in snd_es1968_capture_setup()
1194 snd_es1968_apu_set_freq(chip, es->apu[0], freq); in snd_es1968_capture_setup()
1195 snd_es1968_apu_set_freq(chip, es->apu[1], freq); in snd_es1968_capture_setup()
1199 snd_es1968_apu_set_freq(chip, es->apu[2], freq); in snd_es1968_capture_setup()
1200 snd_es1968_apu_set_freq(chip, es->apu[3], freq); in snd_es1968_capture_setup()
1202 spin_lock_irqsave(&chip->reg_lock, flags); in snd_es1968_capture_setup()
1204 outw(1, chip->io_port + 0x04); in snd_es1968_capture_setup()
1206 outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ); in snd_es1968_capture_setup()
1207 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_es1968_capture_setup()
1216 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_pcm_prepare() local
1217 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1968_pcm_prepare()
1218 struct esschan *es = runtime->private_data; in snd_es1968_pcm_prepare()
1220 es->dma_size = snd_pcm_lib_buffer_bytes(substream); in snd_es1968_pcm_prepare()
1221 es->frag_size = snd_pcm_lib_period_bytes(substream); in snd_es1968_pcm_prepare()
1223 es->wav_shift = 1; /* maestro handles always 16bit */ in snd_es1968_pcm_prepare()
1224 es->fmt = 0; in snd_es1968_pcm_prepare()
1225 if (snd_pcm_format_width(runtime->format) == 16) in snd_es1968_pcm_prepare()
1226 es->fmt |= ESS_FMT_16BIT; in snd_es1968_pcm_prepare()
1227 if (runtime->channels > 1) { in snd_es1968_pcm_prepare()
1228 es->fmt |= ESS_FMT_STEREO; in snd_es1968_pcm_prepare()
1229 if (es->fmt & ESS_FMT_16BIT) /* 8bit is already word shifted */ in snd_es1968_pcm_prepare()
1230 es->wav_shift++; in snd_es1968_pcm_prepare()
1232 es->bob_freq = snd_es1968_calc_bob_rate(chip, es, runtime); in snd_es1968_pcm_prepare()
1234 switch (es->mode) { in snd_es1968_pcm_prepare()
1236 snd_es1968_playback_setup(chip, es, runtime); in snd_es1968_pcm_prepare()
1239 snd_es1968_capture_setup(chip, es, runtime); in snd_es1968_pcm_prepare()
1248 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_pcm_trigger() local
1249 struct esschan *es = substream->runtime->private_data; in snd_es1968_pcm_trigger()
1251 spin_lock(&chip->substream_lock); in snd_es1968_pcm_trigger()
1255 if (es->running) in snd_es1968_pcm_trigger()
1257 snd_es1968_bob_inc(chip, es->bob_freq); in snd_es1968_pcm_trigger()
1258 es->count = 0; in snd_es1968_pcm_trigger()
1259 es->hwptr = 0; in snd_es1968_pcm_trigger()
1260 snd_es1968_pcm_start(chip, es); in snd_es1968_pcm_trigger()
1261 es->running = 1; in snd_es1968_pcm_trigger()
1265 if (! es->running) in snd_es1968_pcm_trigger()
1267 snd_es1968_pcm_stop(chip, es); in snd_es1968_pcm_trigger()
1268 es->running = 0; in snd_es1968_pcm_trigger()
1269 snd_es1968_bob_dec(chip); in snd_es1968_pcm_trigger()
1272 spin_unlock(&chip->substream_lock); in snd_es1968_pcm_trigger()
1278 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_pcm_pointer() local
1279 struct esschan *es = substream->runtime->private_data; in snd_es1968_pcm_pointer()
1282 ptr = snd_es1968_get_dma_ptr(chip, es) << es->wav_shift; in snd_es1968_pcm_pointer()
1284 return bytes_to_frames(substream->runtime, ptr % es->dma_size); in snd_es1968_pcm_pointer()
1333 /* Because the Maestro can only take addresses relative to the PCM base address
1336 static int calc_available_memory_size(struct es1968 *chip) in calc_available_memory_size() argument
1341 mutex_lock(&chip->memory_mutex); in calc_available_memory_size()
1342 list_for_each_entry(buf, &chip->buf_list, list) { in calc_available_memory_size()
1343 if (buf->empty && buf->buf.bytes > max_size) in calc_available_memory_size()
1344 max_size = buf->buf.bytes; in calc_available_memory_size()
1346 mutex_unlock(&chip->memory_mutex); in calc_available_memory_size()
1353 static struct esm_memory *snd_es1968_new_memory(struct es1968 *chip, int size) in snd_es1968_new_memory() argument
1358 mutex_lock(&chip->memory_mutex); in snd_es1968_new_memory()
1359 list_for_each_entry(buf, &chip->buf_list, list) { in snd_es1968_new_memory()
1360 if (buf->empty && buf->buf.bytes >= size) in snd_es1968_new_memory()
1363 mutex_unlock(&chip->memory_mutex); in snd_es1968_new_memory()
1367 if (buf->buf.bytes > size) { in snd_es1968_new_memory()
1370 mutex_unlock(&chip->memory_mutex); in snd_es1968_new_memory()
1373 chunk->buf = buf->buf; in snd_es1968_new_memory()
1374 chunk->buf.bytes -= size; in snd_es1968_new_memory()
1375 chunk->buf.area += size; in snd_es1968_new_memory()
1376 chunk->buf.addr += size; in snd_es1968_new_memory()
1377 chunk->empty = 1; in snd_es1968_new_memory()
1378 buf->buf.bytes = size; in snd_es1968_new_memory()
1379 list_add(&chunk->list, &buf->list); in snd_es1968_new_memory()
1381 buf->empty = 0; in snd_es1968_new_memory()
1382 mutex_unlock(&chip->memory_mutex); in snd_es1968_new_memory()
1387 static void snd_es1968_free_memory(struct es1968 *chip, struct esm_memory *buf) in snd_es1968_free_memory() argument
1391 mutex_lock(&chip->memory_mutex); in snd_es1968_free_memory()
1392 buf->empty = 1; in snd_es1968_free_memory()
1393 if (buf->list.prev != &chip->buf_list) { in snd_es1968_free_memory()
1394 chunk = list_entry(buf->list.prev, struct esm_memory, list); in snd_es1968_free_memory()
1395 if (chunk->empty) { in snd_es1968_free_memory()
1396 chunk->buf.bytes += buf->buf.bytes; in snd_es1968_free_memory()
1397 list_del(&buf->list); in snd_es1968_free_memory()
1402 if (buf->list.next != &chip->buf_list) { in snd_es1968_free_memory()
1403 chunk = list_entry(buf->list.next, struct esm_memory, list); in snd_es1968_free_memory()
1404 if (chunk->empty) { in snd_es1968_free_memory()
1405 buf->buf.bytes += chunk->buf.bytes; in snd_es1968_free_memory()
1406 list_del(&chunk->list); in snd_es1968_free_memory()
1410 mutex_unlock(&chip->memory_mutex); in snd_es1968_free_memory()
1413 static void snd_es1968_free_dmabuf(struct es1968 *chip) in snd_es1968_free_dmabuf() argument
1417 if (! chip->dma.area) in snd_es1968_free_dmabuf()
1419 snd_dma_reserve_buf(&chip->dma, snd_dma_pci_buf_id(chip->pci)); in snd_es1968_free_dmabuf()
1420 while ((p = chip->buf_list.next) != &chip->buf_list) { in snd_es1968_free_dmabuf()
1428 snd_es1968_init_dmabuf(struct es1968 *chip) in snd_es1968_init_dmabuf() argument
1433 chip->dma.dev.type = SNDRV_DMA_TYPE_DEV; in snd_es1968_init_dmabuf()
1434 chip->dma.dev.dev = snd_dma_pci_data(chip->pci); in snd_es1968_init_dmabuf()
1435 if (! snd_dma_get_reserved_buf(&chip->dma, snd_dma_pci_buf_id(chip->pci))) { in snd_es1968_init_dmabuf()
1437 snd_dma_pci_data(chip->pci), in snd_es1968_init_dmabuf()
1438 chip->total_bufsize, &chip->dma); in snd_es1968_init_dmabuf()
1439 if (err < 0 || ! chip->dma.area) { in snd_es1968_init_dmabuf()
1441 chip->total_bufsize); in snd_es1968_init_dmabuf()
1442 return -ENOMEM; in snd_es1968_init_dmabuf()
1444 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { in snd_es1968_init_dmabuf()
1445 snd_dma_free_pages(&chip->dma); in snd_es1968_init_dmabuf()
1447 return -ENOMEM; in snd_es1968_init_dmabuf()
1451 INIT_LIST_HEAD(&chip->buf_list); in snd_es1968_init_dmabuf()
1455 snd_es1968_free_dmabuf(chip); in snd_es1968_init_dmabuf()
1456 return -ENOMEM; in snd_es1968_init_dmabuf()
1458 memset(chip->dma.area, 0, ESM_MEM_ALIGN); in snd_es1968_init_dmabuf()
1459 chunk->buf = chip->dma; in snd_es1968_init_dmabuf()
1460 chunk->buf.area += ESM_MEM_ALIGN; in snd_es1968_init_dmabuf()
1461 chunk->buf.addr += ESM_MEM_ALIGN; in snd_es1968_init_dmabuf()
1462 chunk->buf.bytes -= ESM_MEM_ALIGN; in snd_es1968_init_dmabuf()
1463 chunk->empty = 1; in snd_es1968_init_dmabuf()
1464 list_add(&chunk->list, &chip->buf_list); in snd_es1968_init_dmabuf()
1470 /* buffer is extracted from the pre-allocated memory chunk */
1474 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_hw_params() local
1475 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1968_hw_params()
1476 struct esschan *chan = runtime->private_data; in snd_es1968_hw_params()
1479 if (chan->memory) { in snd_es1968_hw_params()
1480 if (chan->memory->buf.bytes >= size) { in snd_es1968_hw_params()
1481 runtime->dma_bytes = size; in snd_es1968_hw_params()
1484 snd_es1968_free_memory(chip, chan->memory); in snd_es1968_hw_params()
1486 chan->memory = snd_es1968_new_memory(chip, size); in snd_es1968_hw_params()
1487 if (chan->memory == NULL) { in snd_es1968_hw_params()
1489 return -ENOMEM; in snd_es1968_hw_params()
1491 snd_pcm_set_runtime_buffer(substream, &chan->memory->buf); in snd_es1968_hw_params()
1498 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_hw_free() local
1499 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1968_hw_free()
1502 if (runtime->private_data == NULL) in snd_es1968_hw_free()
1504 chan = runtime->private_data; in snd_es1968_hw_free()
1505 if (chan->memory) { in snd_es1968_hw_free()
1506 snd_es1968_free_memory(chip, chan->memory); in snd_es1968_hw_free()
1507 chan->memory = NULL; in snd_es1968_hw_free()
1516 static int snd_es1968_alloc_apu_pair(struct es1968 *chip, int type) in snd_es1968_alloc_apu_pair() argument
1521 if (chip->apu[apu] == ESM_APU_FREE && in snd_es1968_alloc_apu_pair()
1522 chip->apu[apu + 1] == ESM_APU_FREE) { in snd_es1968_alloc_apu_pair()
1523 chip->apu[apu] = chip->apu[apu + 1] = type; in snd_es1968_alloc_apu_pair()
1527 return -EBUSY; in snd_es1968_alloc_apu_pair()
1533 static void snd_es1968_free_apu_pair(struct es1968 *chip, int apu) in snd_es1968_free_apu_pair() argument
1535 chip->apu[apu] = chip->apu[apu + 1] = ESM_APU_FREE; in snd_es1968_free_apu_pair()
1545 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_playback_open() local
1546 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1968_playback_open()
1551 apu1 = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY); in snd_es1968_playback_open()
1557 snd_es1968_free_apu_pair(chip, apu1); in snd_es1968_playback_open()
1558 return -ENOMEM; in snd_es1968_playback_open()
1561 es->apu[0] = apu1; in snd_es1968_playback_open()
1562 es->apu[1] = apu1 + 1; in snd_es1968_playback_open()
1563 es->apu_mode[0] = 0; in snd_es1968_playback_open()
1564 es->apu_mode[1] = 0; in snd_es1968_playback_open()
1565 es->running = 0; in snd_es1968_playback_open()
1566 es->substream = substream; in snd_es1968_playback_open()
1567 es->mode = ESM_MODE_PLAY; in snd_es1968_playback_open()
1569 runtime->private_data = es; in snd_es1968_playback_open()
1570 runtime->hw = snd_es1968_playback; in snd_es1968_playback_open()
1571 runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_max = in snd_es1968_playback_open()
1572 calc_available_memory_size(chip); in snd_es1968_playback_open()
1574 spin_lock_irq(&chip->substream_lock); in snd_es1968_playback_open()
1575 list_add(&es->list, &chip->substream_list); in snd_es1968_playback_open()
1576 spin_unlock_irq(&chip->substream_lock); in snd_es1968_playback_open()
1583 struct snd_pcm_runtime *runtime = substream->runtime; in snd_es1968_capture_open()
1584 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_capture_open() local
1588 apu1 = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_CAPTURE); in snd_es1968_capture_open()
1591 apu2 = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_RATECONV); in snd_es1968_capture_open()
1593 snd_es1968_free_apu_pair(chip, apu1); in snd_es1968_capture_open()
1599 snd_es1968_free_apu_pair(chip, apu1); in snd_es1968_capture_open()
1600 snd_es1968_free_apu_pair(chip, apu2); in snd_es1968_capture_open()
1601 return -ENOMEM; in snd_es1968_capture_open()
1604 es->apu[0] = apu1; in snd_es1968_capture_open()
1605 es->apu[1] = apu1 + 1; in snd_es1968_capture_open()
1606 es->apu[2] = apu2; in snd_es1968_capture_open()
1607 es->apu[3] = apu2 + 1; in snd_es1968_capture_open()
1608 es->apu_mode[0] = 0; in snd_es1968_capture_open()
1609 es->apu_mode[1] = 0; in snd_es1968_capture_open()
1610 es->apu_mode[2] = 0; in snd_es1968_capture_open()
1611 es->apu_mode[3] = 0; in snd_es1968_capture_open()
1612 es->running = 0; in snd_es1968_capture_open()
1613 es->substream = substream; in snd_es1968_capture_open()
1614 es->mode = ESM_MODE_CAPTURE; in snd_es1968_capture_open()
1617 if ((es->mixbuf = snd_es1968_new_memory(chip, ESM_MIXBUF_SIZE)) == NULL) { in snd_es1968_capture_open()
1618 snd_es1968_free_apu_pair(chip, apu1); in snd_es1968_capture_open()
1619 snd_es1968_free_apu_pair(chip, apu2); in snd_es1968_capture_open()
1621 return -ENOMEM; in snd_es1968_capture_open()
1623 memset(es->mixbuf->buf.area, 0, ESM_MIXBUF_SIZE); in snd_es1968_capture_open()
1625 runtime->private_data = es; in snd_es1968_capture_open()
1626 runtime->hw = snd_es1968_capture; in snd_es1968_capture_open()
1627 runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_max = in snd_es1968_capture_open()
1628 calc_available_memory_size(chip) - 1024; /* keep MIXBUF size */ in snd_es1968_capture_open()
1631 spin_lock_irq(&chip->substream_lock); in snd_es1968_capture_open()
1632 list_add(&es->list, &chip->substream_list); in snd_es1968_capture_open()
1633 spin_unlock_irq(&chip->substream_lock); in snd_es1968_capture_open()
1640 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_playback_close() local
1643 if (substream->runtime->private_data == NULL) in snd_es1968_playback_close()
1645 es = substream->runtime->private_data; in snd_es1968_playback_close()
1646 spin_lock_irq(&chip->substream_lock); in snd_es1968_playback_close()
1647 list_del(&es->list); in snd_es1968_playback_close()
1648 spin_unlock_irq(&chip->substream_lock); in snd_es1968_playback_close()
1649 snd_es1968_free_apu_pair(chip, es->apu[0]); in snd_es1968_playback_close()
1657 struct es1968 *chip = snd_pcm_substream_chip(substream); in snd_es1968_capture_close() local
1660 if (substream->runtime->private_data == NULL) in snd_es1968_capture_close()
1662 es = substream->runtime->private_data; in snd_es1968_capture_close()
1663 spin_lock_irq(&chip->substream_lock); in snd_es1968_capture_close()
1664 list_del(&es->list); in snd_es1968_capture_close()
1665 spin_unlock_irq(&chip->substream_lock); in snd_es1968_capture_close()
1666 snd_es1968_free_memory(chip, es->mixbuf); in snd_es1968_capture_close()
1667 snd_es1968_free_apu_pair(chip, es->apu[0]); in snd_es1968_capture_close()
1668 snd_es1968_free_apu_pair(chip, es->apu[2]); in snd_es1968_capture_close()
1702 static void __devinit es1968_measure_clock(struct es1968 *chip) in es1968_measure_clock() argument
1709 if (chip->clock == 0) in es1968_measure_clock()
1710 chip->clock = 48000; /* default clock value */ in es1968_measure_clock()
1713 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) { in es1968_measure_clock()
1717 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) { in es1968_measure_clock()
1718 snd_printk(KERN_ERR "cannot allocate dma buffer - using default clock %d\n", chip->clock); in es1968_measure_clock()
1719 snd_es1968_free_apu_pair(chip, apu); in es1968_measure_clock()
1723 memset(memory->buf.area, 0, CLOCK_MEASURE_BUFSIZE); in es1968_measure_clock()
1725 wave_set_register(chip, apu << 3, (memory->buf.addr - 0x10) & 0xfff8); in es1968_measure_clock()
1727 pa = (unsigned int)((memory->buf.addr - chip->dma.addr) >> 1); in es1968_measure_clock()
1732 apu_set_register(chip, apu, i, 0x0000); in es1968_measure_clock()
1734 apu_set_register(chip, apu, 0, 0x400f); in es1968_measure_clock()
1735 apu_set_register(chip, apu, 4, ((pa >> 16) & 0xff) << 8); in es1968_measure_clock()
1736 apu_set_register(chip, apu, 5, pa & 0xffff); in es1968_measure_clock()
1737 apu_set_register(chip, apu, 6, (pa + CLOCK_MEASURE_BUFSIZE/2) & 0xffff); in es1968_measure_clock()
1738 apu_set_register(chip, apu, 7, CLOCK_MEASURE_BUFSIZE/2); in es1968_measure_clock()
1739 apu_set_register(chip, apu, 8, 0x0000); in es1968_measure_clock()
1740 apu_set_register(chip, apu, 9, 0xD000); in es1968_measure_clock()
1741 apu_set_register(chip, apu, 10, 0x8F08); in es1968_measure_clock()
1742 apu_set_register(chip, apu, 11, 0x0000); in es1968_measure_clock()
1743 spin_lock_irq(&chip->reg_lock); in es1968_measure_clock()
1744 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ in es1968_measure_clock()
1745 …outw(inw(chip->io_port + ESM_PORT_HOST_IRQ) | ESM_HIRQ_DSIE, chip->io_port + ESM_PORT_HOST_IRQ); /… in es1968_measure_clock()
1746 spin_unlock_irq(&chip->reg_lock); in es1968_measure_clock()
1748 snd_es1968_apu_set_freq(chip, apu, ((unsigned int)48000 << 16) / chip->clock); /* 48000 Hz */ in es1968_measure_clock()
1750 chip->in_measurement = 1; in es1968_measure_clock()
1751 chip->measure_apu = apu; in es1968_measure_clock()
1752 spin_lock_irq(&chip->reg_lock); in es1968_measure_clock()
1753 snd_es1968_bob_inc(chip, ESM_BOB_FREQ); in es1968_measure_clock()
1754 __apu_set_register(chip, apu, 5, pa & 0xffff); in es1968_measure_clock()
1755 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); in es1968_measure_clock()
1757 spin_unlock_irq(&chip->reg_lock); in es1968_measure_clock()
1759 spin_lock_irq(&chip->reg_lock); in es1968_measure_clock()
1760 offset = __apu_get_register(chip, apu, 5); in es1968_measure_clock()
1762 snd_es1968_trigger_apu(chip, apu, 0); /* stop */ in es1968_measure_clock()
1763 snd_es1968_bob_dec(chip); in es1968_measure_clock()
1764 chip->in_measurement = 0; in es1968_measure_clock()
1765 spin_unlock_irq(&chip->reg_lock); in es1968_measure_clock()
1768 offset -= (pa & 0xffff); in es1968_measure_clock()
1770 offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2); in es1968_measure_clock()
1772 t = stop_time.tv_sec - start_time.tv_sec; in es1968_measure_clock()
1775 t -= start_time.tv_usec - stop_time.tv_usec; in es1968_measure_clock()
1777 t += stop_time.tv_usec - start_time.tv_usec; in es1968_measure_clock()
1785 chip->clock = (chip->clock * offset) / 48000; in es1968_measure_clock()
1787 printk(KERN_INFO "es1968: clocking to %d\n", chip->clock); in es1968_measure_clock()
1789 snd_es1968_free_memory(chip, memory); in es1968_measure_clock()
1790 snd_es1968_free_apu_pair(chip, apu); in es1968_measure_clock()
1799 struct es1968 *esm = pcm->private_data; in snd_es1968_pcm_free()
1801 esm->pcm = NULL; in snd_es1968_pcm_free()
1805 snd_es1968_pcm(struct es1968 *chip, int device) in snd_es1968_pcm() argument
1811 if ((err = snd_es1968_init_dmabuf(chip)) < 0) in snd_es1968_pcm()
1815 wave_set_register(chip, 0x01FC, chip->dma.addr >> 12); in snd_es1968_pcm()
1816 wave_set_register(chip, 0x01FD, chip->dma.addr >> 12); in snd_es1968_pcm()
1817 wave_set_register(chip, 0x01FE, chip->dma.addr >> 12); in snd_es1968_pcm()
1818 wave_set_register(chip, 0x01FF, chip->dma.addr >> 12); in snd_es1968_pcm()
1820 if ((err = snd_pcm_new(chip->card, "ESS Maestro", device, in snd_es1968_pcm()
1821 chip->playback_streams, in snd_es1968_pcm()
1822 chip->capture_streams, &pcm)) < 0) in snd_es1968_pcm()
1825 pcm->private_data = chip; in snd_es1968_pcm()
1826 pcm->private_free = snd_es1968_pcm_free; in snd_es1968_pcm()
1831 pcm->info_flags = 0; in snd_es1968_pcm()
1833 strcpy(pcm->name, "ESS Maestro"); in snd_es1968_pcm()
1835 chip->pcm = pcm; in snd_es1968_pcm()
1842 static void snd_es1968_suppress_jitter(struct es1968 *chip, struct esschan *es) in snd_es1968_suppress_jitter() argument
1848 cp1 = __apu_get_register(chip, 0, 5); in snd_es1968_suppress_jitter()
1849 cp2 = __apu_get_register(chip, 1, 5); in snd_es1968_suppress_jitter()
1850 diff = (cp1 > cp2 ? cp1 - cp2 : cp2 - cp1); in snd_es1968_suppress_jitter()
1853 __maestro_write(chip, IDR0_DATA_PORT, cp1); in snd_es1968_suppress_jitter()
1859 static void snd_es1968_update_pcm(struct es1968 *chip, struct esschan *es) in snd_es1968_update_pcm() argument
1863 struct snd_pcm_substream *subs = es->substream; in snd_es1968_update_pcm()
1865 if (subs == NULL || !es->running) in snd_es1968_update_pcm()
1868 hwptr = snd_es1968_get_dma_ptr(chip, es) << es->wav_shift; in snd_es1968_update_pcm()
1869 hwptr %= es->dma_size; in snd_es1968_update_pcm()
1871 diff = (es->dma_size + hwptr - es->hwptr) % es->dma_size; in snd_es1968_update_pcm()
1873 es->hwptr = hwptr; in snd_es1968_update_pcm()
1874 es->count += diff; in snd_es1968_update_pcm()
1876 if (es->count > es->frag_size) { in snd_es1968_update_pcm()
1877 spin_unlock(&chip->substream_lock); in snd_es1968_update_pcm()
1879 spin_lock(&chip->substream_lock); in snd_es1968_update_pcm()
1880 es->count %= es->frag_size; in snd_es1968_update_pcm()
1885 (without wrap around) in response to volume button presses and then
1886 generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
1890 struct es1968 *chip = container_of(work, struct es1968, hwvol_work); in es1968_update_hw_volume() local
1896 x = inb(chip->io_port + 0x1c) & 0xee; in es1968_update_hw_volume()
1898 outb(0x88, chip->io_port + 0x1c); in es1968_update_hw_volume()
1899 outb(0x88, chip->io_port + 0x1d); in es1968_update_hw_volume()
1900 outb(0x88, chip->io_port + 0x1e); in es1968_update_hw_volume()
1901 outb(0x88, chip->io_port + 0x1f); in es1968_update_hw_volume()
1903 if (chip->in_suspend) in es1968_update_hw_volume()
1907 if (! chip->master_switch || ! chip->master_volume) in es1968_update_hw_volume()
1910 val = snd_ac97_read(chip->ac97, AC97_MASTER); in es1968_update_hw_volume()
1919 val--; in es1968_update_hw_volume()
1921 val -= 0x0100; in es1968_update_hw_volume()
1931 if (snd_ac97_update(chip->ac97, AC97_MASTER, val)) in es1968_update_hw_volume()
1932 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in es1968_update_hw_volume()
1933 &chip->master_volume->id); in es1968_update_hw_volume()
1935 if (!chip->input_dev) in es1968_update_hw_volume()
1942 interrupt. According to tests run by various people this in es1968_update_hw_volume()
1947 /* counters increased by 1 -> volume up */ in es1968_update_hw_volume()
1951 /* counters decreased by 1 -> volume down */ in es1968_update_hw_volume()
1957 input_report_key(chip->input_dev, val, 1); in es1968_update_hw_volume()
1958 input_sync(chip->input_dev); in es1968_update_hw_volume()
1959 input_report_key(chip->input_dev, val, 0); in es1968_update_hw_volume()
1960 input_sync(chip->input_dev); in es1968_update_hw_volume()
1970 struct es1968 *chip = dev_id; in snd_es1968_interrupt() local
1973 if (!(event = inb(chip->io_port + 0x1A))) in snd_es1968_interrupt()
1976 outw(inw(chip->io_port + 4) & 1, chip->io_port + 4); in snd_es1968_interrupt()
1979 schedule_work(&chip->hwvol_work); in snd_es1968_interrupt()
1982 outb(0xFF, chip->io_port + 0x1A); in snd_es1968_interrupt()
1984 if ((event & ESM_MPU401_IRQ) && chip->rmidi) { in snd_es1968_interrupt()
1985 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); in snd_es1968_interrupt()
1990 spin_lock(&chip->substream_lock); in snd_es1968_interrupt()
1991 list_for_each_entry(es, &chip->substream_list, list) { in snd_es1968_interrupt()
1992 if (es->running) { in snd_es1968_interrupt()
1993 snd_es1968_update_pcm(chip, es); in snd_es1968_interrupt()
1994 if (es->fmt & ESS_FMT_STEREO) in snd_es1968_interrupt()
1995 snd_es1968_suppress_jitter(chip, es); in snd_es1968_interrupt()
1998 spin_unlock(&chip->substream_lock); in snd_es1968_interrupt()
1999 if (chip->in_measurement) { in snd_es1968_interrupt()
2000 unsigned int curp = __apu_get_register(chip, chip->measure_apu, 5); in snd_es1968_interrupt()
2001 if (curp < chip->measure_lastpos) in snd_es1968_interrupt()
2002 chip->measure_count++; in snd_es1968_interrupt()
2003 chip->measure_lastpos = curp; in snd_es1968_interrupt()
2015 snd_es1968_mixer(struct es1968 *chip) in snd_es1968_mixer() argument
2028 if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0) in snd_es1968_mixer()
2030 pbus->no_vra = 1; /* ES1968 doesn't need VRA */ in snd_es1968_mixer()
2033 ac97.private_data = chip; in snd_es1968_mixer()
2034 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0) in snd_es1968_mixer()
2042 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id); in snd_es1968_mixer()
2046 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id); in snd_es1968_mixer()
2056 static void snd_es1968_ac97_reset(struct es1968 *chip) in snd_es1968_ac97_reset() argument
2058 unsigned long ioaddr = chip->io_port; in snd_es1968_ac97_reset()
2069 /* set command/status address i/o to 1st codec */ in snd_es1968_ac97_reset()
2076 pci_read_config_word(chip->pci, 0x58, &w); /* something magical with gpio and bus arb. */ in snd_es1968_ac97_reset()
2077 pci_read_config_dword(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend); in snd_es1968_ac97_reset()
2082 outw(0x0000, ioaddr + 0x60); /* write 0 to gpio 0 */ in snd_es1968_ac97_reset()
2084 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio 1 */ in snd_es1968_ac97_reset()
2098 outw(0x0001, ioaddr + 0x60); /* write 1 to gpio */ in snd_es1968_ac97_reset()
2100 outw(0x0009, ioaddr + 0x60); /* write 9 to gpio */ in snd_es1968_ac97_reset()
2106 #if 0 /* the loop here needs to be much better if we want it.. */ in snd_es1968_ac97_reset()
2149 /* Turn on the 978 docking chip. in snd_es1968_ac97_reset()
2151 then set most of the playback volume control registers to max. */ in snd_es1968_ac97_reset()
2161 static void snd_es1968_reset(struct es1968 *chip) in snd_es1968_reset() argument
2165 chip->io_port + ESM_PORT_HOST_IRQ); in snd_es1968_reset()
2167 outw(0x0000, chip->io_port + ESM_PORT_HOST_IRQ); in snd_es1968_reset()
2172 * initialize maestro chip
2174 static void snd_es1968_chip_init(struct es1968 *chip) in snd_es1968_chip_init() argument
2176 struct pci_dev *pci = chip->pci; in snd_es1968_chip_init()
2178 unsigned long iobase = chip->io_port; in snd_es1968_chip_init()
2182 /* We used to muck around with pci config space that in snd_es1968_chip_init()
2184 * about the machine to know which DMA mode is appropriate, in snd_es1968_chip_init()
2186 * them unhappy. We now trust in the BIOS to do things right, in snd_es1968_chip_init()
2201 /* XXX huh? claims to be reserved.. */ in snd_es1968_chip_init()
2203 seems to only have effect on SB in snd_es1968_chip_init()
2214 /* XXX how do we know which to use? */ in snd_es1968_chip_init()
2219 w |= DEBOUNCE; /* Debounce off: easier to push the HW buttons */ in snd_es1968_chip_init()
2225 w &= ~IRQ_TO_ISA; /* IRQ to ISA off (undoc) */ in snd_es1968_chip_init()
2247 /* Set up 978 docking control chip. */ in snd_es1968_chip_init()
2256 snd_es1968_reset(chip); in snd_es1968_chip_init()
2262 /* setup usual 0x34 stuff.. 0x36 may be chip specific */ in snd_es1968_chip_init()
2272 snd_es1968_ac97_reset(chip); in snd_es1968_chip_init()
2281 /* Set hardware volume control registers to midpoints. in snd_es1968_chip_init()
2299 /* Write 0 into the buffer area 0x1E0->1EF */ in snd_es1968_chip_init()
2303 /* The 1.10 test program seem to write 0 into the buffer area in snd_es1968_chip_init()
2304 * 0x1D0-0x1DF too.*/ in snd_es1968_chip_init()
2308 wave_set_register(chip, IDR7_WAVE_ROMRAM, in snd_es1968_chip_init()
2309 (wave_get_register(chip, IDR7_WAVE_ROMRAM) & 0xFF00)); in snd_es1968_chip_init()
2310 wave_set_register(chip, IDR7_WAVE_ROMRAM, in snd_es1968_chip_init()
2311 wave_get_register(chip, IDR7_WAVE_ROMRAM) | 0x100); in snd_es1968_chip_init()
2312 wave_set_register(chip, IDR7_WAVE_ROMRAM, in snd_es1968_chip_init()
2313 wave_get_register(chip, IDR7_WAVE_ROMRAM) & ~0x200); in snd_es1968_chip_init()
2314 wave_set_register(chip, IDR7_WAVE_ROMRAM, in snd_es1968_chip_init()
2315 wave_get_register(chip, IDR7_WAVE_ROMRAM) | ~0x400); in snd_es1968_chip_init()
2318 maestro_write(chip, IDR2_CRAM_DATA, 0x0000); in snd_es1968_chip_init()
2319 /* Now back to the DirectSound stuff */ in snd_es1968_chip_init()
2321 maestro_write(chip, 0x08, 0xB004); in snd_es1968_chip_init()
2322 maestro_write(chip, 0x09, 0x001B); in snd_es1968_chip_init()
2323 maestro_write(chip, 0x0A, 0x8000); in snd_es1968_chip_init()
2324 maestro_write(chip, 0x0B, 0x3F37); in snd_es1968_chip_init()
2325 maestro_write(chip, 0x0C, 0x0098); in snd_es1968_chip_init()
2327 /* parallel in, has something to do with recording :) */ in snd_es1968_chip_init()
2328 maestro_write(chip, 0x0C, in snd_es1968_chip_init()
2329 (maestro_read(chip, 0x0C) & ~0xF000) | 0x8000); in snd_es1968_chip_init()
2331 maestro_write(chip, 0x0C, in snd_es1968_chip_init()
2332 (maestro_read(chip, 0x0C) & ~0x0F00) | 0x0500); in snd_es1968_chip_init()
2334 maestro_write(chip, 0x0D, 0x7632); in snd_es1968_chip_init()
2336 /* Wave cache control on - test off, sg off, in snd_es1968_chip_init()
2341 w &= ~0xFA00; /* Seems to be reserved? I don't know */ in snd_es1968_chip_init()
2344 Seems to crash the Computer if enabled... */ in snd_es1968_chip_init()
2359 apu_set_register(chip, i, w, 0); in snd_es1968_chip_init()
2365 static void snd_es1968_start_irq(struct es1968 *chip) in snd_es1968_start_irq() argument
2369 if (chip->rmidi) in snd_es1968_start_irq()
2371 outb(w, chip->io_port + 0x1A); in snd_es1968_start_irq()
2372 outw(w, chip->io_port + ESM_PORT_HOST_IRQ); in snd_es1968_start_irq()
2382 struct es1968 *chip = card->private_data; in es1968_suspend() local
2384 if (! chip->do_pm) in es1968_suspend()
2387 chip->in_suspend = 1; in es1968_suspend()
2388 cancel_work_sync(&chip->hwvol_work); in es1968_suspend()
2390 snd_pcm_suspend_all(chip->pcm); in es1968_suspend()
2391 snd_ac97_suspend(chip->ac97); in es1968_suspend()
2392 snd_es1968_bob_stop(chip); in es1968_suspend()
2403 struct es1968 *chip = card->private_data; in es1968_resume() local
2406 if (! chip->do_pm) in es1968_resume()
2416 return -EIO; in es1968_resume()
2420 snd_es1968_chip_init(chip); in es1968_resume()
2422 /* need to restore the base pointers.. */ in es1968_resume()
2423 if (chip->dma.addr) { in es1968_resume()
2425 wave_set_register(chip, 0x01FC, chip->dma.addr >> 12); in es1968_resume()
2428 snd_es1968_start_irq(chip); in es1968_resume()
2431 snd_ac97_resume(chip->ac97); in es1968_resume()
2433 list_for_each_entry(es, &chip->substream_list, list) { in es1968_resume()
2434 switch (es->mode) { in es1968_resume()
2436 snd_es1968_playback_setup(chip, es, es->substream->runtime); in es1968_resume()
2439 snd_es1968_capture_setup(chip, es, es->substream->runtime); in es1968_resume()
2445 if (chip->bobclient) in es1968_resume()
2446 snd_es1968_bob_start(chip); in es1968_resume()
2449 chip->in_suspend = 0; in es1968_resume()
2456 static int __devinit snd_es1968_create_gameport(struct es1968 *chip, int dev) in snd_es1968_create_gameport() argument
2463 return -ENODEV; in snd_es1968_create_gameport()
2467 return -EBUSY; in snd_es1968_create_gameport()
2469 chip->gameport = gp = gameport_allocate_port(); in snd_es1968_create_gameport()
2473 return -ENOMEM; in snd_es1968_create_gameport()
2476 pci_read_config_word(chip->pci, ESM_LEGACY_AUDIO_CONTROL, &val); in snd_es1968_create_gameport()
2477 pci_write_config_word(chip->pci, ESM_LEGACY_AUDIO_CONTROL, val | 0x04); in snd_es1968_create_gameport()
2480 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); in snd_es1968_create_gameport()
2481 gameport_set_dev_parent(gp, &chip->pci->dev); in snd_es1968_create_gameport()
2482 gp->io = JOYSTICK_ADDR; in snd_es1968_create_gameport()
2490 static void snd_es1968_free_gameport(struct es1968 *chip) in snd_es1968_free_gameport() argument
2492 if (chip->gameport) { in snd_es1968_free_gameport()
2493 struct resource *r = gameport_get_port_data(chip->gameport); in snd_es1968_free_gameport()
2495 gameport_unregister_port(chip->gameport); in snd_es1968_free_gameport()
2496 chip->gameport = NULL; in snd_es1968_free_gameport()
2502 static inline int snd_es1968_create_gameport(struct es1968 *chip, int dev) { return -ENOSYS; } in snd_es1968_create_gameport() argument
2503 static inline void snd_es1968_free_gameport(struct es1968 *chip) { } in snd_es1968_free_gameport() argument
2507 static int __devinit snd_es1968_input_register(struct es1968 *chip) in snd_es1968_input_register() argument
2514 return -ENOMEM; in snd_es1968_input_register()
2516 snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0", in snd_es1968_input_register()
2517 pci_name(chip->pci)); in snd_es1968_input_register()
2519 input_dev->name = chip->card->driver; in snd_es1968_input_register()
2520 input_dev->phys = chip->phys; in snd_es1968_input_register()
2521 input_dev->id.bustype = BUS_PCI; in snd_es1968_input_register()
2522 input_dev->id.vendor = chip->pci->vendor; in snd_es1968_input_register()
2523 input_dev->id.product = chip->pci->device; in snd_es1968_input_register()
2524 input_dev->dev.parent = &chip->pci->dev; in snd_es1968_input_register()
2526 __set_bit(EV_KEY, input_dev->evbit); in snd_es1968_input_register()
2527 __set_bit(KEY_MUTE, input_dev->keybit); in snd_es1968_input_register()
2528 __set_bit(KEY_VOLUMEDOWN, input_dev->keybit); in snd_es1968_input_register()
2529 __set_bit(KEY_VOLUMEUP, input_dev->keybit); in snd_es1968_input_register()
2537 chip->input_dev = input_dev; in snd_es1968_input_register()
2545 bits 1=unmask write to given bit */
2556 struct es1968 *chip = tea->private_data; in snd_es1968_tea575x_set_pins() local
2557 unsigned long io = chip->io_port + GPIO_DATA; in snd_es1968_tea575x_set_pins()
2569 struct es1968 *chip = tea->private_data; in snd_es1968_tea575x_get_pins() local
2570 unsigned long io = chip->io_port + GPIO_DATA; in snd_es1968_tea575x_get_pins()
2579 struct es1968 *chip = tea->private_data; in snd_es1968_tea575x_set_direction() local
2580 unsigned long io = chip->io_port + GPIO_DATA; in snd_es1968_tea575x_set_direction()
2599 static int snd_es1968_free(struct es1968 *chip) in snd_es1968_free() argument
2601 cancel_work_sync(&chip->hwvol_work); in snd_es1968_free()
2603 if (chip->input_dev) in snd_es1968_free()
2604 input_unregister_device(chip->input_dev); in snd_es1968_free()
2607 if (chip->io_port) { in snd_es1968_free()
2608 if (chip->irq >= 0) in snd_es1968_free()
2609 synchronize_irq(chip->irq); in snd_es1968_free()
2610 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ in snd_es1968_free()
2611 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ in snd_es1968_free()
2615 snd_tea575x_exit(&chip->tea); in snd_es1968_free()
2618 if (chip->irq >= 0) in snd_es1968_free()
2619 free_irq(chip->irq, chip); in snd_es1968_free()
2620 snd_es1968_free_gameport(chip); in snd_es1968_free()
2621 pci_release_regions(chip->pci); in snd_es1968_free()
2622 pci_disable_device(chip->pci); in snd_es1968_free()
2623 kfree(chip); in snd_es1968_free()
2629 struct es1968 *chip = device->device_data; in snd_es1968_dev_free() local
2630 return snd_es1968_free(chip); in snd_es1968_dev_free()
2634 unsigned short type; /* chip type */
2663 struct es1968 *chip; in snd_es1968_create() local
2671 /* check, if we can restrict PCI DMA transfers to 28 bits */ in snd_es1968_create()
2676 return -ENXIO; in snd_es1968_create()
2679 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in snd_es1968_create()
2680 if (! chip) { in snd_es1968_create()
2682 return -ENOMEM; in snd_es1968_create()
2686 chip->type = chip_type; in snd_es1968_create()
2687 spin_lock_init(&chip->reg_lock); in snd_es1968_create()
2688 spin_lock_init(&chip->substream_lock); in snd_es1968_create()
2689 INIT_LIST_HEAD(&chip->buf_list); in snd_es1968_create()
2690 INIT_LIST_HEAD(&chip->substream_list); in snd_es1968_create()
2691 mutex_init(&chip->memory_mutex); in snd_es1968_create()
2692 INIT_WORK(&chip->hwvol_work, es1968_update_hw_volume); in snd_es1968_create()
2693 chip->card = card; in snd_es1968_create()
2694 chip->pci = pci; in snd_es1968_create()
2695 chip->irq = -1; in snd_es1968_create()
2696 chip->total_bufsize = total_bufsize; /* in bytes */ in snd_es1968_create()
2697 chip->playback_streams = play_streams; in snd_es1968_create()
2698 chip->capture_streams = capt_streams; in snd_es1968_create()
2701 kfree(chip); in snd_es1968_create()
2705 chip->io_port = pci_resource_start(pci, 0); in snd_es1968_create()
2706 if (request_irq(pci->irq, snd_es1968_interrupt, IRQF_SHARED, in snd_es1968_create()
2707 KBUILD_MODNAME, chip)) { in snd_es1968_create()
2708 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); in snd_es1968_create()
2709 snd_es1968_free(chip); in snd_es1968_create()
2710 return -EBUSY; in snd_es1968_create()
2712 chip->irq = pci->irq; in snd_es1968_create()
2716 chip->maestro_map[i] = 0; in snd_es1968_create()
2720 chip->apu[i] = ESM_APU_FREE; in snd_es1968_create()
2722 /* just to be sure */ in snd_es1968_create()
2726 /* disable power-management if not on the whitelist */ in snd_es1968_create()
2728 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend); in snd_es1968_create()
2730 if (chip->type == pm_whitelist[i].type && in snd_es1968_create()
2742 chip->do_pm = do_pm; in snd_es1968_create()
2744 snd_es1968_chip_init(chip); in snd_es1968_create()
2746 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { in snd_es1968_create()
2747 snd_es1968_free(chip); in snd_es1968_create()
2751 snd_card_set_dev(card, &pci->dev); in snd_es1968_create()
2754 chip->tea.private_data = chip; in snd_es1968_create()
2755 chip->tea.ops = &snd_es1968_tea_ops; in snd_es1968_create()
2756 strlcpy(chip->tea.card, "SF64-PCE2", sizeof(chip->tea.card)); in snd_es1968_create()
2757 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci)); in snd_es1968_create()
2758 if (!snd_tea575x_init(&chip->tea)) in snd_es1968_create()
2762 *chip_ret = chip; in snd_es1968_create()
2775 struct es1968 *chip; in snd_es1968_probe() local
2780 return -ENODEV; in snd_es1968_probe()
2783 return -ENOENT; in snd_es1968_probe()
2798 pci_id->driver_data, in snd_es1968_probe()
2800 &chip)) < 0) { in snd_es1968_probe()
2804 card->private_data = chip; in snd_es1968_probe()
2806 switch (chip->type) { in snd_es1968_probe()
2808 strcpy(card->driver, "ES1978"); in snd_es1968_probe()
2809 strcpy(card->shortname, "ESS ES1978 (Maestro 2E)"); in snd_es1968_probe()
2812 strcpy(card->driver, "ES1968"); in snd_es1968_probe()
2813 strcpy(card->shortname, "ESS ES1968 (Maestro 2)"); in snd_es1968_probe()
2816 strcpy(card->driver, "ESM1"); in snd_es1968_probe()
2817 strcpy(card->shortname, "ESS Maestro 1"); in snd_es1968_probe()
2821 if ((err = snd_es1968_pcm(chip, 0)) < 0) { in snd_es1968_probe()
2826 if ((err = snd_es1968_mixer(chip)) < 0) { in snd_es1968_probe()
2834 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend); in snd_es1968_probe()
2836 if (chip->type == mpu_blacklist[i].type && in snd_es1968_probe()
2845 chip->io_port + ESM_MPU401_PORT, in snd_es1968_probe()
2848 -1, &chip->rmidi)) < 0) { in snd_es1968_probe()
2849 printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); in snd_es1968_probe()
2853 snd_es1968_create_gameport(chip, dev); in snd_es1968_probe()
2856 err = snd_es1968_input_register(chip); in snd_es1968_probe()
2862 snd_es1968_start_irq(chip); in snd_es1968_probe()
2864 chip->clock = clock[dev]; in snd_es1968_probe()
2865 if (! chip->clock) in snd_es1968_probe()
2866 es1968_measure_clock(chip); in snd_es1968_probe()
2868 sprintf(card->longname, "%s at 0x%lx, irq %i", in snd_es1968_probe()
2869 card->shortname, chip->io_port, chip->irq); in snd_es1968_probe()