24 #include <linux/time.h>
38 #define PCXHR_LINE_CAPTURE_LEVEL_MIN 0
39 #define PCXHR_LINE_CAPTURE_LEVEL_MAX 255
40 #define PCXHR_LINE_CAPTURE_ZERO_LEVEL 224
42 #define PCXHR_LINE_PLAYBACK_LEVEL_MIN 0
43 #define PCXHR_LINE_PLAYBACK_LEVEL_MAX 128
44 #define PCXHR_LINE_PLAYBACK_ZERO_LEVEL 104
52 static int pcxhr_update_analog_audio_level(
struct snd_pcxhr *
chip,
71 rmh.cmd[1] = 1 << ((2 * chip->
chip_idx) + channel);
76 " is_capture(%d) err(%x)\n",
86 static int pcxhr_analog_vol_info(
struct snd_kcontrol *kcontrol,
94 if (chip->
mgr->is_hr_stereo) {
106 if (chip->
mgr->is_hr_stereo) {
121 static int pcxhr_analog_vol_get(
struct snd_kcontrol *kcontrol,
137 static int pcxhr_analog_vol_put(
struct snd_kcontrol *kcontrol,
146 for (i = 0; i < 2; i++) {
147 int new_volume = ucontrol->
value.integer.value[
i];
148 int *stored_volume = is_capture ?
152 if (chip->
mgr->is_hr_stereo) {
162 if (chip->
mgr->is_hr_stereo) {
172 if (*stored_volume != new_volume) {
173 *stored_volume = new_volume;
175 if (chip->
mgr->is_hr_stereo)
179 pcxhr_update_analog_audio_level(chip,
192 .
info = pcxhr_analog_vol_info,
193 .
get = pcxhr_analog_vol_get,
194 .
put = pcxhr_analog_vol_put,
200 #define pcxhr_sw_info snd_ctl_boolean_stereo_info
202 static int pcxhr_audio_sw_get(
struct snd_kcontrol *kcontrol,
214 static int pcxhr_audio_sw_put(
struct snd_kcontrol *kcontrol,
220 for(i = 0; i < 2; i++) {
222 ucontrol->
value.integer.value[i]) {
224 !!ucontrol->
value.integer.value[
i];
227 if (chip->
mgr->is_hr_stereo)
230 pcxhr_update_analog_audio_level(chip, 0, i);
239 .name =
"Master Playback Switch",
241 .get = pcxhr_audio_sw_get,
242 .put = pcxhr_audio_sw_put
246 #define PCXHR_DIGITAL_LEVEL_MIN 0x000
247 #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff
248 #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7
252 #define MORE_THAN_ONE_STREAM_LEVEL 0x000001
253 #define VALID_STREAM_PAN_LEVEL_MASK 0x800000
254 #define VALID_STREAM_LEVEL_MASK 0x400000
255 #define VALID_STREAM_LEVEL_1_MASK 0x200000
256 #define VALID_STREAM_LEVEL_2_MASK 0x100000
258 static int pcxhr_update_playback_stream_level(
struct snd_pcxhr* chip,
int idx)
280 rmh.
cmd[2] |= (left << 10);
288 "card(%d) err(%x)\n", chip->
chip_idx, err);
294 #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
295 #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000
296 #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001
297 #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002
298 #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
299 #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
301 static int pcxhr_update_audio_pipe_level(
struct snd_pcxhr *chip,
302 int capture,
int channel)
347 static int pcxhr_digital_vol_info(
struct snd_kcontrol *kcontrol,
358 static int pcxhr_pcm_vol_get(
struct snd_kcontrol *kcontrol,
362 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
371 ucontrol->
value.integer.value[0] = stored_volume[0];
372 ucontrol->
value.integer.value[1] = stored_volume[1];
377 static int pcxhr_pcm_vol_put(
struct snd_kcontrol *kcontrol,
381 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
392 for (i = 0; i < 2; i++) {
393 int vol = ucontrol->
value.integer.value[
i];
397 if (stored_volume[i] != vol) {
398 stored_volume[
i] =
vol;
401 pcxhr_update_audio_pipe_level(chip, 1, i);
404 if (!is_capture && changed)
405 pcxhr_update_playback_stream_level(chip, idx);
417 .
info = pcxhr_digital_vol_info,
418 .
get = pcxhr_pcm_vol_get,
419 .
put = pcxhr_pcm_vol_put,
420 .
tlv = { .p = db_scale_digital },
424 static int pcxhr_pcm_sw_get(
struct snd_kcontrol *kcontrol,
428 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
437 static int pcxhr_pcm_sw_put(
struct snd_kcontrol *kcontrol,
442 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
447 for (i = 0; i < 2; i++) {
449 ucontrol->
value.integer.value[i]) {
451 !!ucontrol->
value.integer.value[
i];
456 pcxhr_update_playback_stream_level(chip, idx);
463 .name =
"PCM Playback Switch",
466 .get = pcxhr_pcm_sw_get,
467 .put = pcxhr_pcm_sw_put
475 static int pcxhr_monitor_vol_get(
struct snd_kcontrol *kcontrol,
486 static int pcxhr_monitor_vol_put(
struct snd_kcontrol *kcontrol,
494 for (i = 0; i < 2; i++) {
496 ucontrol->
value.integer.value[i]) {
498 ucontrol->
value.integer.value[
i];
502 pcxhr_update_audio_pipe_level(chip, 0, i);
514 .
name =
"Monitoring Playback Volume",
515 .
info = pcxhr_digital_vol_info,
516 .
get = pcxhr_monitor_vol_get,
517 .
put = pcxhr_monitor_vol_put,
518 .
tlv = { .p = db_scale_digital },
525 static int pcxhr_monitor_sw_get(
struct snd_kcontrol *kcontrol,
536 static int pcxhr_monitor_sw_put(
struct snd_kcontrol *kcontrol,
544 for (i = 0; i < 2; i++) {
546 ucontrol->
value.integer.value[i]) {
548 !!ucontrol->
value.integer.value[
i];
554 pcxhr_update_audio_pipe_level(chip, 0, 0);
557 pcxhr_update_audio_pipe_level(chip, 0, 1);
560 return (changed != 0);
565 .name =
"Monitoring Playback Switch",
567 .get = pcxhr_monitor_sw_get,
568 .put = pcxhr_monitor_sw_put
576 #define PCXHR_SOURCE_AUDIO01_UER 0x000100
577 #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200
578 #define PCXHR_SOURCE_AUDIO23_UER 0x000400
579 #define PCXHR_SOURCE_AUDIO45_UER 0x001000
580 #define PCXHR_SOURCE_AUDIO67_UER 0x040000
582 static int pcxhr_set_audio_source(
struct snd_pcxhr* chip)
611 if (chip->
mgr->board_aes_in_192k) {
613 unsigned int src_config = 0xC0;
615 for (i = 0; (i < 4) && (i < chip->mgr->capture_chips); i++) {
616 if (chip->
mgr->chip[i]->audio_capture_source == 2)
617 src_config |= (1 << (3 -
i));
623 rmh.
cmd[1] = src_config;
635 (use_src ? 0x41 : 0x54));
640 (use_src ? 0x41 : 0x49));
646 static int pcxhr_audio_src_info(
struct snd_kcontrol *kcontrol,
649 static const char *texts[5] = {
650 "Line",
"Digital",
"Digi+SRC",
"Mic",
"Line+Mic"
656 if (chip->
mgr->board_has_aes1) {
658 if (chip->
mgr->board_has_mic)
671 static int pcxhr_audio_src_get(
struct snd_kcontrol *kcontrol,
679 static int pcxhr_audio_src_put(
struct snd_kcontrol *kcontrol,
685 if (chip->
mgr->board_has_aes1) {
687 if (chip->
mgr->board_has_mic)
690 if (ucontrol->
value.enumerated.item[0] >= i)
695 if (chip->
mgr->is_hr_stereo)
698 pcxhr_set_audio_source(chip);
707 .name =
"Capture Source",
708 .info = pcxhr_audio_src_info,
709 .get = pcxhr_audio_src_get,
710 .put = pcxhr_audio_src_put,
732 static int pcxhr_clock_type_info(
struct snd_kcontrol *kcontrol,
735 static const char *textsPCXHR[7] = {
736 "Internal",
"WordClock",
"AES Sync",
737 "AES 1",
"AES 2",
"AES 3",
"AES 4"
739 static const char *textsHR22[3] = {
740 "Internal",
"AES Sync",
"AES 1"
767 static int pcxhr_clock_type_get(
struct snd_kcontrol *kcontrol,
775 static int pcxhr_clock_type_put(
struct snd_kcontrol *kcontrol,
780 unsigned int clock_items = 2;
786 if (ucontrol->
value.enumerated.item[0] >= clock_items)
815 .name =
"Clock Mode",
816 .info = pcxhr_clock_type_info,
817 .get = pcxhr_clock_type_get,
818 .put = pcxhr_clock_type_put,
825 static int pcxhr_clock_rate_info(
struct snd_kcontrol *kcontrol,
836 static int pcxhr_clock_rate_get(
struct snd_kcontrol *kcontrol,
860 .name =
"Clock Rates",
861 .info = pcxhr_clock_rate_info,
862 .get = pcxhr_clock_rate_get,
868 static int pcxhr_iec958_info(
struct snd_kcontrol *kcontrol,
876 static int pcxhr_iec958_capture_byte(
struct snd_pcxhr *chip,
877 int aes_idx,
unsigned char *aes_bits)
893 if (chip->
mgr->board_aes_in_192k) {
914 rmh.cmd[1] &= 0x0fffff;
922 if (chip->
mgr->board_aes_in_192k) {
923 temp = (
unsigned char)rmh.stat[1];
927 for (i = 0; i < 8; i++) {
929 if (rmh.stat[1] & (1 << i))
939 static int pcxhr_iec958_get(
struct snd_kcontrol *kcontrol,
947 for(i = 0; i < 5; i++) {
951 if (chip->
mgr->is_hr_stereo)
955 err = pcxhr_iec958_capture_byte(chip, i,
966 static int pcxhr_iec958_mask_get(
struct snd_kcontrol *kcontrol,
970 for (i = 0; i < 5; i++)
971 ucontrol->
value.iec958.status[i] = 0xff;
975 static int pcxhr_iec958_update_byte(
struct snd_pcxhr *chip,
976 int aes_idx,
unsigned char aes_bits)
980 unsigned char old_bits = chip->
aes_bits[aes_idx];
983 for (i = 0; i < 8; i++) {
984 if ((old_bits & 0x01) != (new_bits & 0x01)) {
989 cmd |= ((aes_idx << 3) + i) << 2;
990 cmd |= (new_bits & 0x01) << 23;
995 snd_printdd(
"write iec958 AES %d byte %d bit %d (cmd %x)\n",
1004 chip->
aes_bits[aes_idx] = aes_bits;
1008 static int pcxhr_iec958_put(
struct snd_kcontrol *kcontrol,
1016 for (i = 0; i < 5; i++) {
1017 if (ucontrol->
value.iec958.status[i] != chip->
aes_bits[i]) {
1018 if (chip->
mgr->is_hr_stereo)
1020 ucontrol->
value.iec958.status[i]);
1022 pcxhr_iec958_update_byte(chip, i,
1023 ucontrol->
value.iec958.status[i]);
1035 .info = pcxhr_iec958_info,
1036 .get = pcxhr_iec958_mask_get
1041 .info = pcxhr_iec958_info,
1042 .get = pcxhr_iec958_get,
1043 .put = pcxhr_iec958_put,
1051 .info = pcxhr_iec958_info,
1052 .get = pcxhr_iec958_mask_get
1058 .info = pcxhr_iec958_info,
1059 .get = pcxhr_iec958_get,
1063 static void pcxhr_init_audio_levels(
struct snd_pcxhr *chip)
1067 for (i = 0; i < 2; i++) {
1081 #ifdef CONFIG_SND_DEBUG
1086 if (chip->
mgr->is_hr_stereo)
1092 pcxhr_update_analog_audio_level(chip, 0, i);
1096 if (chip->
mgr->is_hr_stereo)
1104 #ifdef CONFIG_SND_DEBUG
1108 if (chip->
mgr->is_hr_stereo)
1114 pcxhr_update_analog_audio_level(chip, 1, i);
1118 if (chip->
mgr->is_hr_stereo)
1136 chip = mgr->
chip[
i];
1138 if (chip->nb_streams_play) {
1140 temp = pcxhr_control_analog_level;
1141 temp.
name =
"Master Playback Volume";
1144 temp.
tlv.
p = db_scale_a_hr222_playback;
1146 temp.
tlv.
p = db_scale_analog_playback;
1159 temp = snd_pcxhr_pcm_vol;
1160 temp.
name =
"PCM Playback Volume";
1186 if (chip->nb_streams_capt) {
1188 temp = pcxhr_control_analog_level;
1189 temp.
name =
"Line Capture Volume";
1192 temp.
tlv.
p = db_scale_a_hr222_capture;
1194 temp.
tlv.
p = db_scale_analog_capture;
1201 temp = snd_pcxhr_pcm_vol;
1202 temp.
name =
"PCM Capture Volume";
1237 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1266 pcxhr_init_audio_levels(chip);