25 #include <linux/slab.h>
27 #include <linux/module.h>
43 for (i = 10000;
i; i--)
48 #ifdef CONFIG_SND_DEBUG
54 static int snd_es1688_dsp_get_byte(
struct snd_es1688 *chip)
58 for (i = 1000;
i; i--)
65 static int snd_es1688_write(
struct snd_es1688 *chip,
66 unsigned char reg,
unsigned char data)
68 if (!snd_es1688_dsp_command(chip, reg))
70 return snd_es1688_dsp_command(chip, data);
73 static int snd_es1688_read(
struct snd_es1688 *chip,
unsigned char reg)
76 if (!snd_es1688_dsp_command(chip, 0xc0))
78 if (!snd_es1688_dsp_command(chip, reg))
80 return snd_es1688_dsp_get_byte(chip);
84 unsigned char reg,
unsigned char data)
92 static unsigned char snd_es1688_mixer_read(
struct snd_es1688 *chip,
unsigned char reg)
116 snd_es1688_dsp_command(chip, 0xc6);
121 static int snd_es1688_probe(
struct snd_es1688 *chip)
146 spin_unlock_irqrestore(&chip->
reg_lock, flags);
149 snd_es1688_dsp_command(chip, 0xe7);
151 for (i = 1000, major = minor = 0;
i; i--) {
161 spin_unlock_irqrestore(&chip->
reg_lock, flags);
163 snd_printdd(
"ESS: [0x%lx] found.. major = 0x%x, minor = 0x%x\n", chip->
port, major, minor);
165 chip->
version = (major << 8) | minor;
170 switch (chip->
version & 0xfff0) {
173 "but driver is in another place\n", chip->
port);
180 "with version 0x%x (Jazz16 soundcard?)\n",
186 snd_es1688_write(chip, 0xb1, 0x10);
187 snd_es1688_write(chip, 0xb2, 0x00);
188 spin_unlock_irqrestore(&chip->
reg_lock, flags);
193 spin_unlock_irqrestore(&chip->
mixer_lock, flags);
200 static int irqs[16] = {-1, -1, 0, -1, -1, 1, -1, 2, -1, 0, 3, -1, -1, -1, -1, -1};
207 tmp = (chip->
mpu_port & 0x0f0) >> 4;
226 cfg |= (tmp << 3) | (tmp1 << 5);
235 spin_unlock_irqrestore(&chip->
reg_lock, flags);
238 snd_es1688_read(chip, 0xb1);
239 snd_es1688_read(chip, 0xb2);
240 spin_unlock_irqrestore(&chip->
reg_lock, flags);
243 irq_bits = irqs[chip->
irq & 0x0f];
246 "for ES1688 chip!!\n",
255 snd_es1688_write(chip, 0xb1, cfg | (irq_bits << 2));
256 spin_unlock_irqrestore(&chip->
reg_lock, flags);
259 if (dma > 3 || dma == 2) {
261 "for ES1688 chip!!\n", chip->
port, dma);
273 snd_es1688_write(chip, 0xb2, cfg | (dma_bits << 2));
274 spin_unlock_irqrestore(&chip->
reg_lock, flags);
277 snd_es1688_write(chip, 0xb1, 0x10);
278 snd_es1688_write(chip, 0xb2, 0x00);
279 spin_unlock_irqrestore(&chip->
reg_lock, flags);
282 snd_es1688_read(chip, 0xb1);
283 snd_es1688_read(chip, 0xb2);
285 spin_unlock_irqrestore(&chip->
reg_lock, flags);
316 unsigned int bits, divider;
323 divider = 256 - 7160000*20/(8*82*runtime->
rate);
325 snd_es1688_write(chip, 0xa1, bits);
326 snd_es1688_write(chip, 0xa2, divider);
330 unsigned int cmd,
void *
arg)
346 val = snd_es1688_read(chip, 0xb8);
347 if ((val < 0) || (val & 0x0f) == value) {
356 snd_es1688_write(chip, 0xb8, (val & 0xf0) | value);
377 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
378 unsigned int count = snd_pcm_lib_period_bytes(substream);
383 snd_es1688_set_rate(chip, substream);
384 snd_es1688_write(chip, 0xb8, 4);
385 snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->
channels));
386 snd_es1688_write(chip, 0xb9, 2);
390 snd_es1688_write(chip, 0xb6, 0x80);
391 snd_es1688_write(chip, 0xb7, 0x51);
392 snd_es1688_write(chip, 0xb7, 0xd0);
395 snd_es1688_write(chip, 0xb6, 0x00);
396 snd_es1688_write(chip, 0xb7, 0x71);
397 snd_es1688_write(chip, 0xb7, 0xf4);
402 snd_es1688_write(chip, 0xb6, 0x80);
403 snd_es1688_write(chip, 0xb7, 0x51);
404 snd_es1688_write(chip, 0xb7, 0x98);
407 snd_es1688_write(chip, 0xb6, 0x00);
408 snd_es1688_write(chip, 0xb7, 0x71);
409 snd_es1688_write(chip, 0xb7, 0xbc);
412 snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
413 snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
415 spin_unlock_irqrestore(&chip->
reg_lock, flags);
420 snd_es1688_write(chip, 0xa4, (
unsigned char) count);
421 snd_es1688_write(chip, 0xa5, (
unsigned char) (count >> 8));
422 spin_unlock_irqrestore(&chip->
reg_lock, flags);
430 return snd_es1688_trigger(chip, cmd, 0x05);
438 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
439 unsigned int count = snd_pcm_lib_period_bytes(substream);
444 snd_es1688_set_rate(chip, substream);
446 snd_es1688_write(chip, 0xb8, 0x0e);
447 snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->
channels));
448 snd_es1688_write(chip, 0xb9, 2);
452 snd_es1688_write(chip, 0xb7, 0x51);
453 snd_es1688_write(chip, 0xb7, 0xd0);
456 snd_es1688_write(chip, 0xb7, 0x71);
457 snd_es1688_write(chip, 0xb7, 0xf4);
462 snd_es1688_write(chip, 0xb7, 0x51);
463 snd_es1688_write(chip, 0xb7, 0x98);
466 snd_es1688_write(chip, 0xb7, 0x71);
467 snd_es1688_write(chip, 0xb7, 0xbc);
470 snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
471 snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
472 spin_unlock_irqrestore(&chip->
reg_lock, flags);
477 snd_es1688_write(chip, 0xa4, (
unsigned char) count);
478 snd_es1688_write(chip, 0xa5, (
unsigned char) (count >> 8));
479 spin_unlock_irqrestore(&chip->
reg_lock, flags);
487 return snd_es1688_trigger(chip, cmd, 0x0f);
511 return bytes_to_frames(substream->
runtime, ptr);
522 return bytes_to_frames(substream->
runtime, ptr);
577 runtime->
hw = snd_es1688_playback;
579 &hw_constraints_clocks);
591 runtime->
hw = snd_es1688_capture;
593 &hw_constraints_clocks);
613 static int snd_es1688_free(
struct snd_es1688 *chip)
616 snd_es1688_init(chip, 0);
621 if (chip->
dma8 >= 0) {
631 return snd_es1688_free(chip);
634 static const char *snd_es1688_chip_id(
struct snd_es1688 *chip)
669 err =
request_irq(irq, snd_es1688_interrupt, 0,
"ES1688", (
void *) chip);
688 if (mpu_port < 0x300 || mpu_port > 0x330)
694 err = snd_es1688_probe(chip);
698 err = snd_es1688_init(chip, 1);
706 snd_es1688_free(chip);
710 static struct snd_pcm_ops snd_es1688_playback_ops = {
711 .open = snd_es1688_playback_open,
712 .close = snd_es1688_playback_close,
713 .ioctl = snd_es1688_ioctl,
714 .hw_params = snd_es1688_hw_params,
715 .hw_free = snd_es1688_hw_free,
716 .prepare = snd_es1688_playback_prepare,
717 .trigger = snd_es1688_playback_trigger,
718 .pointer = snd_es1688_playback_pointer,
721 static struct snd_pcm_ops snd_es1688_capture_ops = {
722 .open = snd_es1688_capture_open,
723 .close = snd_es1688_capture_close,
724 .ioctl = snd_es1688_ioctl,
725 .hw_params = snd_es1688_hw_params,
726 .hw_free = snd_es1688_hw_free,
727 .prepare = snd_es1688_capture_prepare,
728 .trigger = snd_es1688_capture_trigger,
729 .pointer = snd_es1688_capture_pointer,
738 err =
snd_pcm_new(card,
"ESx688", device, 1, 1, &pcm);
765 static char *texts[9] = {
766 "Mic",
"Mic Master",
"CD",
"AOUT",
767 "Mic1",
"Mix",
"Line",
"Master"
790 unsigned char oval, nval;
793 if (ucontrol->
value.enumerated.item[0] > 8)
797 nval = (ucontrol->
value.enumerated.item[0] & 7) | (oval & ~15);
798 change = nval != oval;
801 spin_unlock_irqrestore(&chip->
reg_lock, flags);
805 #define ES1688_SINGLE(xname, xindex, reg, shift, mask, invert) \
806 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
807 .info = snd_es1688_info_single, \
808 .get = snd_es1688_get_single, .put = snd_es1688_put_single, \
809 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
832 ucontrol->
value.integer.value[0] = (snd_es1688_mixer_read(chip, reg) >> shift) & mask;
833 spin_unlock_irqrestore(&chip->
reg_lock, flags);
835 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
848 unsigned char oval, nval;
850 nval = (ucontrol->
value.integer.value[0] &
mask);
855 oval = snd_es1688_mixer_read(chip, reg);
856 nval = (oval & ~(mask << shift)) | nval;
857 change = nval != oval;
860 spin_unlock_irqrestore(&chip->
reg_lock, flags);
864 #define ES1688_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
865 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
866 .info = snd_es1688_info_double, \
867 .get = snd_es1688_get_double, .put = snd_es1688_put_double, \
868 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
895 left = snd_es1688_mixer_read(chip, left_reg);
897 left = snd_es1688_read(chip, left_reg);
898 if (left_reg != right_reg) {
899 if (right_reg < 0xa0)
900 right = snd_es1688_mixer_read(chip, right_reg);
902 right = snd_es1688_read(chip, right_reg);
905 spin_unlock_irqrestore(&chip->
reg_lock, flags);
906 ucontrol->
value.integer.value[0] = (left >> shift_left) & mask;
909 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
910 ucontrol->
value.integer.value[1] = mask - ucontrol->
value.integer.value[1];
926 unsigned char val1, val2, oval1, oval2;
928 val1 = ucontrol->
value.integer.value[0] &
mask;
929 val2 = ucontrol->
value.integer.value[1] &
mask;
937 if (left_reg != right_reg) {
939 oval1 = snd_es1688_mixer_read(chip, left_reg);
941 oval1 = snd_es1688_read(chip, left_reg);
942 if (right_reg < 0xa0)
943 oval2 = snd_es1688_mixer_read(chip, right_reg);
945 oval2 = snd_es1688_read(chip, right_reg);
946 val1 = (oval1 & ~(mask << shift_left)) | val1;
948 change = val1 != oval1 || val2 != oval2;
953 snd_es1688_write(chip, left_reg, val1);
954 if (right_reg < 0xa0)
957 snd_es1688_write(chip, right_reg, val1);
961 oval1 = snd_es1688_mixer_read(chip, left_reg);
963 oval1 = snd_es1688_read(chip, left_reg);
964 val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
965 change = val1 != oval1;
970 snd_es1688_write(chip, left_reg, val1);
974 spin_unlock_irqrestore(&chip->
reg_lock, flags);
991 .name =
"Capture Source",
992 .info = snd_es1688_info_mux,
993 .get = snd_es1688_get_mux,
994 .put = snd_es1688_put_mux,
998 #define ES1688_INIT_TABLE_SIZE (sizeof(snd_es1688_init_table)/2)
1000 static unsigned char snd_es1688_init_table[][2] = {
1024 for (idx = 0; idx <
ARRAY_SIZE(snd_es1688_controls); idx++) {
1029 reg = snd_es1688_init_table[
idx][0];
1030 val = snd_es1688_init_table[
idx][1];
1034 snd_es1688_write(chip, reg, val);
1048 static int __init alsa_es1688_init(
void)
1053 static void __exit alsa_es1688_exit(
void)