23 #include <linux/slab.h>
36 for (timeout = 1000; timeout-- > 0;
udelay(10))
44 static inline unsigned char snd_ad1816a_in(
struct snd_ad1816a *chip,
unsigned char reg)
46 snd_ad1816a_busy_wait(chip);
50 static inline void snd_ad1816a_out(
struct snd_ad1816a *chip,
unsigned char reg,
53 snd_ad1816a_busy_wait(chip);
57 static inline void snd_ad1816a_out_mask(
struct snd_ad1816a *chip,
unsigned char reg,
58 unsigned char mask,
unsigned char value)
60 snd_ad1816a_out(chip, reg,
61 (value & mask) | (snd_ad1816a_in(chip, reg) & ~mask));
64 static unsigned short snd_ad1816a_read(
struct snd_ad1816a *chip,
unsigned char reg)
71 static void snd_ad1816a_write(
struct snd_ad1816a *chip,
unsigned char reg,
79 static void snd_ad1816a_write_mask(
struct snd_ad1816a *chip,
unsigned char reg,
80 unsigned short mask,
unsigned short value)
82 snd_ad1816a_write(chip, reg,
83 (value & mask) | (snd_ad1816a_read(chip, reg) & ~mask));
87 static unsigned char snd_ad1816a_get_format(
struct snd_ad1816a *chip,
108 static int snd_ad1816a_open(
struct snd_ad1816a *chip,
unsigned int mode)
114 if (chip->
mode & mode) {
115 spin_unlock_irqrestore(&chip->
lock, flags);
140 spin_unlock_irqrestore(&chip->
lock, flags);
144 static void snd_ad1816a_close(
struct snd_ad1816a *chip,
unsigned int mode)
172 spin_unlock_irqrestore(&chip->
lock, flags);
176 static int snd_ad1816a_trigger(
struct snd_ad1816a *chip,
unsigned char what,
184 spin_lock(&chip->
lock);
196 spin_unlock(&chip->
lock);
206 static int snd_ad1816a_playback_trigger(
struct snd_pcm_substream *substream,
int cmd)
213 static int snd_ad1816a_capture_trigger(
struct snd_pcm_substream *substream,
int cmd)
240 chip->
p_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
247 rate = runtime->
rate;
253 snd_ad1816a_get_format(chip, runtime->
format,
257 snd_pcm_lib_period_bytes(substream) / 4 - 1);
259 spin_unlock_irqrestore(&chip->
lock, flags);
272 chip->
c_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
279 rate = runtime->
rate;
285 snd_ad1816a_get_format(chip, runtime->
format,
289 snd_pcm_lib_period_bytes(substream) / 4 - 1);
291 spin_unlock_irqrestore(&chip->
lock, flags);
303 return bytes_to_frames(substream->
runtime, ptr);
313 return bytes_to_frames(substream->
runtime, ptr);
322 spin_lock(&chip->
lock);
324 spin_unlock(&chip->
lock);
335 spin_lock(&chip->
lock);
337 spin_unlock(&chip->
lock);
353 .buffer_bytes_max = (128*1024),
372 .buffer_bytes_max = (128*1024),
394 static unsigned long snd_ad1816a_timer_resolution(
struct snd_timer *
timer)
402 static int snd_ad1816a_timer_start(
struct snd_timer *timer)
415 AD1816A_TIMER_ENABLE, 0xffff);
417 spin_unlock_irqrestore(&chip->
lock, flags);
421 static int snd_ad1816a_timer_stop(
struct snd_timer *timer)
430 spin_unlock_irqrestore(&chip->
lock, flags);
438 .open = snd_ad1816a_timer_open,
439 .close = snd_ad1816a_timer_close,
440 .c_resolution = snd_ad1816a_timer_resolution,
441 .start = snd_ad1816a_timer_start,
442 .stop = snd_ad1816a_timer_stop,
453 runtime->
hw = snd_ad1816a_playback;
454 snd_pcm_limit_isa_dma_size(chip->
dma1, &runtime->
hw.buffer_bytes_max);
455 snd_pcm_limit_isa_dma_size(chip->
dma1, &runtime->
hw.period_bytes_max);
468 runtime->
hw = snd_ad1816a_capture;
469 snd_pcm_limit_isa_dma_size(chip->
dma2, &runtime->
hw.buffer_bytes_max);
470 snd_pcm_limit_isa_dma_size(chip->
dma2, &runtime->
hw.period_bytes_max);
494 static void snd_ad1816a_init(
struct snd_ad1816a *chip)
511 spin_unlock_irqrestore(&chip->
lock, flags);
520 snd_pcm_suspend_all(chip->
pcm);
522 for (reg = 0; reg < 48; reg++)
523 chip->image[reg] = snd_ad1816a_read(chip, reg);
524 spin_unlock_irqrestore(&chip->
lock, flags);
532 snd_ad1816a_init(chip);
534 for (reg = 0; reg < 48; reg++)
535 snd_ad1816a_write(chip, reg, chip->image[reg]);
536 spin_unlock_irqrestore(&chip->
lock, flags);
560 spin_unlock_irqrestore(&chip->
lock, flags);
564 static int snd_ad1816a_free(
struct snd_ad1816a *chip)
569 if (chip->
dma1 >= 0) {
573 if (chip->
dma2 >= 0) {
583 return snd_ad1816a_free(chip);
595 return "AD1816A - unknown";
614 snd_ad1816a_free(chip);
617 if (
request_irq(irq, snd_ad1816a_interrupt, 0,
"AD1816A", (
void *) chip)) {
619 snd_ad1816a_free(chip);
625 snd_ad1816a_free(chip);
631 snd_ad1816a_free(chip);
640 if ((error = snd_ad1816a_probe(chip))) {
641 snd_ad1816a_free(chip);
645 snd_ad1816a_init(chip);
649 snd_ad1816a_free(chip);
656 static struct snd_pcm_ops snd_ad1816a_playback_ops = {
657 .open = snd_ad1816a_playback_open,
658 .close = snd_ad1816a_playback_close,
660 .hw_params = snd_ad1816a_hw_params,
661 .hw_free = snd_ad1816a_hw_free,
662 .prepare = snd_ad1816a_playback_prepare,
663 .trigger = snd_ad1816a_playback_trigger,
664 .pointer = snd_ad1816a_playback_pointer,
667 static struct snd_pcm_ops snd_ad1816a_capture_ops = {
668 .open = snd_ad1816a_capture_open,
669 .close = snd_ad1816a_capture_close,
671 .hw_params = snd_ad1816a_hw_params,
672 .hw_free = snd_ad1816a_hw_free,
673 .prepare = snd_ad1816a_capture_prepare,
674 .trigger = snd_ad1816a_capture_trigger,
675 .pointer = snd_ad1816a_capture_pointer,
693 snd_ad1816a_init(chip);
697 64*1024, chip->
dma1 > 3 || chip->
dma2 > 3 ? 128*1024 : 64*1024);
718 strcpy(timer->
name, snd_ad1816a_chip_id(chip));
721 timer->
hw = snd_ad1816a_timer_table;
733 static char *texts[8] = {
734 "Line",
"Mix",
"CD",
"Synth",
"Video",
755 spin_unlock_irqrestore(&chip->
lock, flags);
756 ucontrol->
value.enumerated.item[0] = (val >> 12) & 7;
757 ucontrol->
value.enumerated.item[1] = (val >> 4) & 7;
768 if (ucontrol->
value.enumerated.item[0] > 6 ||
769 ucontrol->
value.enumerated.item[1] > 6)
771 val = (ucontrol->
value.enumerated.item[0] << 12) |
772 (ucontrol->
value.enumerated.item[1] << 4);
776 spin_unlock_irqrestore(&chip->
lock, flags);
780 #define AD1816A_SINGLE_TLV(xname, reg, shift, mask, invert, xtlv) \
781 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
782 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
783 .name = xname, .info = snd_ad1816a_info_single, \
784 .get = snd_ad1816a_get_single, .put = snd_ad1816a_put_single, \
785 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
786 .tlv = { .p = (xtlv) } }
787 #define AD1816A_SINGLE(xname, reg, shift, mask, invert) \
788 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_single, \
789 .get = snd_ad1816a_get_single, .put = snd_ad1816a_put_single, \
790 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
813 ucontrol->
value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask;
814 spin_unlock_irqrestore(&chip->
lock, flags);
816 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
829 unsigned short old_val,
val;
831 val = (ucontrol->
value.integer.value[0] &
mask);
836 old_val = snd_ad1816a_read(chip, reg);
837 val = (old_val & ~(mask << shift)) |
val;
838 change = val != old_val;
839 snd_ad1816a_write(chip, reg, val);
840 spin_unlock_irqrestore(&chip->
lock, flags);
844 #define AD1816A_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
845 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
846 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
847 .name = xname, .info = snd_ad1816a_info_double, \
848 .get = snd_ad1816a_get_double, .put = snd_ad1816a_put_double, \
849 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
850 .tlv = { .p = (xtlv) } }
852 #define AD1816A_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
853 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_double, \
854 .get = snd_ad1816a_get_double, .put = snd_ad1816a_put_double, \
855 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
880 val = snd_ad1816a_read(chip, reg);
881 ucontrol->
value.integer.value[0] = (val >> shift_left) & mask;
883 spin_unlock_irqrestore(&chip->
lock, flags);
885 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
886 ucontrol->
value.integer.value[1] = mask - ucontrol->
value.integer.value[1];
901 unsigned short old_val, val1, val2;
903 val1 = ucontrol->
value.integer.value[0] &
mask;
904 val2 = ucontrol->
value.integer.value[1] &
mask;
912 old_val = snd_ad1816a_read(chip, reg);
913 val1 = (old_val & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
914 change = val1 != old_val;
915 snd_ad1816a_write(chip, reg, val1);
916 spin_unlock_irqrestore(&chip->
lock, flags);
935 db_scale_5bit_12db_max),
938 db_scale_5bit_12db_max),
941 db_scale_5bit_12db_max),
947 db_scale_5bit_12db_max),
951 db_scale_5bit_12db_max),
960 .name =
"Capture Source",
961 .info = snd_ad1816a_info_mux,
962 .get = snd_ad1816a_get_mux,
963 .put = snd_ad1816a_put_mux,
985 for (idx = 0; idx <
ARRAY_SIZE(snd_ad1816a_controls); idx++) {