3 * Driver for Digigram pcxhr compatible soundcards
7 * Copyright (c) 2004 by Digigram <alsa@digigram.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/time.h>
25 #include <linux/interrupt.h>
26 #include <linux/init.h>
27 #include <linux/mutex.h>
28 #include <sound/core.h>
30 #include "pcxhr_hwdep.h"
31 #include "pcxhr_core.h"
32 #include <sound/control.h>
33 #include <sound/tlv.h>
34 #include <sound/asoundef.h>
35 #include "pcxhr_mixer.h"
36 #include "pcxhr_mix22.h"
38 #define PCXHR_LINE_CAPTURE_LEVEL_MIN 0 /* -112.0 dB */
39 #define PCXHR_LINE_CAPTURE_LEVEL_MAX 255 /* +15.5 dB */
40 #define PCXHR_LINE_CAPTURE_ZERO_LEVEL 224 /* 0.0 dB ( 0 dBu -> 0 dBFS ) */
42 #define PCXHR_LINE_PLAYBACK_LEVEL_MIN 0 /* -104.0 dB */
43 #define PCXHR_LINE_PLAYBACK_LEVEL_MAX 128 /* +24.0 dB */
44 #define PCXHR_LINE_PLAYBACK_ZERO_LEVEL 104 /* 0.0 dB ( 0 dBFS -> 0 dBu ) */
46 static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -11200, 50, 1550);
47 static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400);
49 static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_capture, -11150, 50, 1600);
50 static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_playback, -2550, 50, 2400);
52 static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip,
53 int is_capture, int channel)
58 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
60 rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL;
61 rmh.cmd[2] = chip->analog_capture_volume[channel];
63 rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL;
64 if (chip->analog_playback_active[channel])
65 vol = chip->analog_playback_volume[channel];
67 vol = PCXHR_LINE_PLAYBACK_LEVEL_MIN;
68 /* playback analog levels are inversed */
69 rmh.cmd[2] = PCXHR_LINE_PLAYBACK_LEVEL_MAX - vol;
71 rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */
73 err = pcxhr_send_msg(chip->mgr, &rmh);
75 snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d)"
76 " is_capture(%d) err(%x)\n",
77 chip->chip_idx, is_capture, err);
84 * analog level control
86 static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
87 struct snd_ctl_elem_info *uinfo)
89 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
91 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
93 if (kcontrol->private_value == 0) { /* playback */
94 if (chip->mgr->is_hr_stereo) {
95 uinfo->value.integer.min =
96 HR222_LINE_PLAYBACK_LEVEL_MIN; /* -25 dB */
97 uinfo->value.integer.max =
98 HR222_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
100 uinfo->value.integer.min =
101 PCXHR_LINE_PLAYBACK_LEVEL_MIN; /*-104 dB */
102 uinfo->value.integer.max =
103 PCXHR_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
105 } else { /* capture */
106 if (chip->mgr->is_hr_stereo) {
107 uinfo->value.integer.min =
108 HR222_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
109 uinfo->value.integer.max =
110 HR222_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
112 uinfo->value.integer.min =
113 PCXHR_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
114 uinfo->value.integer.max =
115 PCXHR_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
121 static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
122 struct snd_ctl_elem_value *ucontrol)
124 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
125 mutex_lock(&chip->mgr->mixer_mutex);
126 if (kcontrol->private_value == 0) { /* playback */
127 ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
128 ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
129 } else { /* capture */
130 ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
131 ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
133 mutex_unlock(&chip->mgr->mixer_mutex);
137 static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
138 struct snd_ctl_elem_value *ucontrol)
140 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
144 mutex_lock(&chip->mgr->mixer_mutex);
145 is_capture = (kcontrol->private_value != 0);
146 for (i = 0; i < 2; i++) {
147 int new_volume = ucontrol->value.integer.value[i];
148 int *stored_volume = is_capture ?
149 &chip->analog_capture_volume[i] :
150 &chip->analog_playback_volume[i];
152 if (chip->mgr->is_hr_stereo) {
153 if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN ||
154 new_volume > HR222_LINE_CAPTURE_LEVEL_MAX)
157 if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN ||
158 new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX)
162 if (chip->mgr->is_hr_stereo) {
163 if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN ||
164 new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX)
167 if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN ||
168 new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX)
172 if (*stored_volume != new_volume) {
173 *stored_volume = new_volume;
175 if (chip->mgr->is_hr_stereo)
176 hr222_update_analog_audio_level(chip,
179 pcxhr_update_analog_audio_level(chip,
183 mutex_unlock(&chip->mgr->mixer_mutex);
187 static struct snd_kcontrol_new pcxhr_control_analog_level = {
188 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
189 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
190 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
191 /* name will be filled later */
192 .info = pcxhr_analog_vol_info,
193 .get = pcxhr_analog_vol_get,
194 .put = pcxhr_analog_vol_put,
195 /* tlv will be filled later */
200 #define pcxhr_sw_info snd_ctl_boolean_stereo_info
202 static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
203 struct snd_ctl_elem_value *ucontrol)
205 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
207 mutex_lock(&chip->mgr->mixer_mutex);
208 ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
209 ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
210 mutex_unlock(&chip->mgr->mixer_mutex);
214 static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
215 struct snd_ctl_elem_value *ucontrol)
217 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
219 mutex_lock(&chip->mgr->mixer_mutex);
220 for(i = 0; i < 2; i++) {
221 if (chip->analog_playback_active[i] !=
222 ucontrol->value.integer.value[i]) {
223 chip->analog_playback_active[i] =
224 !!ucontrol->value.integer.value[i];
226 /* update playback levels */
227 if (chip->mgr->is_hr_stereo)
228 hr222_update_analog_audio_level(chip, 0, i);
230 pcxhr_update_analog_audio_level(chip, 0, i);
233 mutex_unlock(&chip->mgr->mixer_mutex);
237 static struct snd_kcontrol_new pcxhr_control_output_switch = {
238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
239 .name = "Master Playback Switch",
240 .info = pcxhr_sw_info, /* shared */
241 .get = pcxhr_audio_sw_get,
242 .put = pcxhr_audio_sw_put
246 #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */
247 #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */
248 #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */
250 static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10975, 25, 1800);
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)
261 struct pcxhr_rmh rmh;
262 struct pcxhr_pipe *pipe = &chip->playback_pipe;
265 if (chip->digital_playback_active[idx][0])
266 left = chip->digital_playback_volume[idx][0];
268 left = PCXHR_DIGITAL_LEVEL_MIN;
269 if (chip->digital_playback_active[idx][1])
270 right = chip->digital_playback_volume[idx][1];
272 right = PCXHR_DIGITAL_LEVEL_MIN;
274 pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST);
275 /* add pipe and stream mask */
276 pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx);
277 /* volume left->left / right->right panoramic level */
278 rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL;
279 rmh.cmd[2] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK;
280 rmh.cmd[2] |= (left << 10);
281 rmh.cmd[3] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK;
285 err = pcxhr_send_msg(chip->mgr, &rmh);
287 snd_printk(KERN_DEBUG "error update_playback_stream_level "
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)
305 struct pcxhr_rmh rmh;
306 struct pcxhr_pipe *pipe;
309 pipe = &chip->capture_pipe[0];
311 pipe = &chip->playback_pipe;
313 pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
314 /* add channel mask */
315 pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0,
316 1 << (channel + pipe->first_audio));
317 /* TODO : if mask (3 << pipe->first_audio) is used, left and right
318 * channel will be programmed to the same params */
320 rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
321 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled
322 * (capture pipe level) */
323 rmh.cmd[2] = chip->digital_capture_volume[channel];
325 rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL |
326 VALID_AUDIO_IO_MUTE_MONITOR_1;
327 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL
328 * not yet handled (playback pipe level)
330 rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
331 if (chip->monitoring_active[channel] == 0)
332 rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1;
336 err = pcxhr_send_msg(chip->mgr, &rmh);
338 snd_printk(KERN_DEBUG "error update_audio_level(%d) err=%x\n",
339 chip->chip_idx, err);
347 static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol,
348 struct snd_ctl_elem_info *uinfo)
350 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
352 uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */
353 uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */
358 static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
361 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
362 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
364 int is_capture = kcontrol->private_value;
366 mutex_lock(&chip->mgr->mixer_mutex);
367 if (is_capture) /* digital capture */
368 stored_volume = chip->digital_capture_volume;
369 else /* digital playback */
370 stored_volume = chip->digital_playback_volume[idx];
371 ucontrol->value.integer.value[0] = stored_volume[0];
372 ucontrol->value.integer.value[1] = stored_volume[1];
373 mutex_unlock(&chip->mgr->mixer_mutex);
377 static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_value *ucontrol)
380 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
381 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
383 int is_capture = kcontrol->private_value;
387 mutex_lock(&chip->mgr->mixer_mutex);
388 if (is_capture) /* digital capture */
389 stored_volume = chip->digital_capture_volume;
390 else /* digital playback */
391 stored_volume = chip->digital_playback_volume[idx];
392 for (i = 0; i < 2; i++) {
393 int vol = ucontrol->value.integer.value[i];
394 if (vol < PCXHR_DIGITAL_LEVEL_MIN ||
395 vol > PCXHR_DIGITAL_LEVEL_MAX)
397 if (stored_volume[i] != vol) {
398 stored_volume[i] = vol;
400 if (is_capture) /* update capture volume */
401 pcxhr_update_audio_pipe_level(chip, 1, i);
404 if (!is_capture && changed) /* update playback volume */
405 pcxhr_update_playback_stream_level(chip, idx);
406 mutex_unlock(&chip->mgr->mixer_mutex);
410 static struct snd_kcontrol_new snd_pcxhr_pcm_vol =
412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
413 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
414 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
415 /* name will be filled later */
416 /* count will be filled later */
417 .info = pcxhr_digital_vol_info, /* shared */
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,
425 struct snd_ctl_elem_value *ucontrol)
427 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
428 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
430 mutex_lock(&chip->mgr->mixer_mutex);
431 ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
432 ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
433 mutex_unlock(&chip->mgr->mixer_mutex);
437 static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol,
438 struct snd_ctl_elem_value *ucontrol)
440 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
442 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
445 mutex_lock(&chip->mgr->mixer_mutex);
447 for (i = 0; i < 2; i++) {
448 if (chip->digital_playback_active[j][i] !=
449 ucontrol->value.integer.value[i]) {
450 chip->digital_playback_active[j][i] =
451 !!ucontrol->value.integer.value[i];
456 pcxhr_update_playback_stream_level(chip, idx);
457 mutex_unlock(&chip->mgr->mixer_mutex);
461 static struct snd_kcontrol_new pcxhr_control_pcm_switch = {
462 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
463 .name = "PCM Playback Switch",
464 .count = PCXHR_PLAYBACK_STREAMS,
465 .info = pcxhr_sw_info, /* shared */
466 .get = pcxhr_pcm_sw_get,
467 .put = pcxhr_pcm_sw_put
472 * monitoring level control
475 static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
476 struct snd_ctl_elem_value *ucontrol)
478 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
479 mutex_lock(&chip->mgr->mixer_mutex);
480 ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
481 ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
482 mutex_unlock(&chip->mgr->mixer_mutex);
486 static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
487 struct snd_ctl_elem_value *ucontrol)
489 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
493 mutex_lock(&chip->mgr->mixer_mutex);
494 for (i = 0; i < 2; i++) {
495 if (chip->monitoring_volume[i] !=
496 ucontrol->value.integer.value[i]) {
497 chip->monitoring_volume[i] =
498 ucontrol->value.integer.value[i];
499 if (chip->monitoring_active[i])
500 /* update monitoring volume and mute */
501 /* do only when monitoring is unmuted */
502 pcxhr_update_audio_pipe_level(chip, 0, i);
506 mutex_unlock(&chip->mgr->mixer_mutex);
510 static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
512 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
513 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
514 .name = "Monitoring Playback Volume",
515 .info = pcxhr_digital_vol_info, /* shared */
516 .get = pcxhr_monitor_vol_get,
517 .put = pcxhr_monitor_vol_put,
518 .tlv = { .p = db_scale_digital },
522 * monitoring switch control
525 static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
526 struct snd_ctl_elem_value *ucontrol)
528 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
529 mutex_lock(&chip->mgr->mixer_mutex);
530 ucontrol->value.integer.value[0] = chip->monitoring_active[0];
531 ucontrol->value.integer.value[1] = chip->monitoring_active[1];
532 mutex_unlock(&chip->mgr->mixer_mutex);
536 static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
537 struct snd_ctl_elem_value *ucontrol)
539 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
543 mutex_lock(&chip->mgr->mixer_mutex);
544 for (i = 0; i < 2; i++) {
545 if (chip->monitoring_active[i] !=
546 ucontrol->value.integer.value[i]) {
547 chip->monitoring_active[i] =
548 !!ucontrol->value.integer.value[i];
549 changed |= (1<<i); /* mask 0x01 and 0x02 */
553 /* update left monitoring volume and mute */
554 pcxhr_update_audio_pipe_level(chip, 0, 0);
556 /* update right monitoring volume and mute */
557 pcxhr_update_audio_pipe_level(chip, 0, 1);
559 mutex_unlock(&chip->mgr->mixer_mutex);
560 return (changed != 0);
563 static struct snd_kcontrol_new pcxhr_control_monitor_sw = {
564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
565 .name = "Monitoring Playback Switch",
566 .info = pcxhr_sw_info, /* shared */
567 .get = pcxhr_monitor_sw_get,
568 .put = pcxhr_monitor_sw_put
574 * audio source select
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)
584 struct pcxhr_rmh rmh;
585 unsigned int mask, reg;
589 switch (chip->chip_idx) {
590 case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
591 case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break;
592 case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break;
593 case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
594 default: return -EINVAL;
596 if (chip->audio_capture_source != 0) {
597 reg = mask; /* audio source from digital plug */
599 reg = 0; /* audio source from analog plug */
601 /* set the input source */
602 pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
603 /* resync them (otherwise channel inversion possible) */
605 pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS);
606 rmh.cmd[0] |= (1 << chip->chip_idx);
607 err = pcxhr_send_msg(chip->mgr, &rmh);
611 if (chip->mgr->board_aes_in_192k) {
613 unsigned int src_config = 0xC0;
614 /* update all src configs with one call */
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));
619 /* set codec SRC on off */
620 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
622 rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC;
623 rmh.cmd[1] = src_config;
624 err = pcxhr_send_msg(chip->mgr, &rmh);
627 if (chip->audio_capture_source == 2)
629 /* set codec SRC on off */
630 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
632 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
634 rmh.cmd[2] = ((CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) |
635 (use_src ? 0x41 : 0x54));
636 err = pcxhr_send_msg(chip->mgr, &rmh);
639 rmh.cmd[2] = ((CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) |
640 (use_src ? 0x41 : 0x49));
641 err = pcxhr_send_msg(chip->mgr, &rmh);
646 static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
647 struct snd_ctl_elem_info *uinfo)
649 static const char *texts[5] = {
650 "Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"
653 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
655 i = 2; /* no SRC, no Mic available */
656 if (chip->mgr->board_has_aes1) {
657 i = 3; /* SRC available */
658 if (chip->mgr->board_has_mic)
659 i = 5; /* Mic and MicroMix available */
661 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
663 uinfo->value.enumerated.items = i;
664 if (uinfo->value.enumerated.item > (i-1))
665 uinfo->value.enumerated.item = i-1;
666 strcpy(uinfo->value.enumerated.name,
667 texts[uinfo->value.enumerated.item]);
671 static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
674 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
675 ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
679 static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
680 struct snd_ctl_elem_value *ucontrol)
682 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
684 int i = 2; /* no SRC, no Mic available */
685 if (chip->mgr->board_has_aes1) {
686 i = 3; /* SRC available */
687 if (chip->mgr->board_has_mic)
688 i = 5; /* Mic and MicroMix available */
690 if (ucontrol->value.enumerated.item[0] >= i)
692 mutex_lock(&chip->mgr->mixer_mutex);
693 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
694 chip->audio_capture_source = ucontrol->value.enumerated.item[0];
695 if (chip->mgr->is_hr_stereo)
696 hr222_set_audio_source(chip);
698 pcxhr_set_audio_source(chip);
701 mutex_unlock(&chip->mgr->mixer_mutex);
705 static struct snd_kcontrol_new pcxhr_control_audio_src = {
706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
707 .name = "Capture Source",
708 .info = pcxhr_audio_src_info,
709 .get = pcxhr_audio_src_get,
710 .put = pcxhr_audio_src_put,
715 * clock type selection
716 * enum pcxhr_clock_type {
717 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
718 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
719 * PCXHR_CLOCK_TYPE_AES_SYNC,
720 * PCXHR_CLOCK_TYPE_AES_1,
721 * PCXHR_CLOCK_TYPE_AES_2,
722 * PCXHR_CLOCK_TYPE_AES_3,
723 * PCXHR_CLOCK_TYPE_AES_4,
724 * PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
725 * HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
726 * HR22_CLOCK_TYPE_AES_SYNC,
727 * HR22_CLOCK_TYPE_AES_1,
728 * HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
732 static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_info *uinfo)
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"
743 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
744 int clock_items = 2; /* at least Internal and AES Sync clock */
745 if (mgr->board_has_aes1) {
746 clock_items += mgr->capture_chips; /* add AES x */
747 if (!mgr->is_hr_stereo)
748 clock_items += 1; /* add word clock */
750 if (mgr->is_hr_stereo) {
752 snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1));
755 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
757 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
759 uinfo->value.enumerated.items = clock_items;
760 if (uinfo->value.enumerated.item >= clock_items)
761 uinfo->value.enumerated.item = clock_items-1;
762 strcpy(uinfo->value.enumerated.name,
763 texts[uinfo->value.enumerated.item]);
767 static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
768 struct snd_ctl_elem_value *ucontrol)
770 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
771 ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
775 static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
776 struct snd_ctl_elem_value *ucontrol)
778 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
780 unsigned int clock_items = 2; /* at least Internal and AES Sync clock */
781 if (mgr->board_has_aes1) {
782 clock_items += mgr->capture_chips; /* add AES x */
783 if (!mgr->is_hr_stereo)
784 clock_items += 1; /* add word clock */
786 if (ucontrol->value.enumerated.item[0] >= clock_items)
788 mutex_lock(&mgr->mixer_mutex);
789 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
790 mutex_lock(&mgr->setup_mutex);
791 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
792 if (mgr->use_clock_type)
793 pcxhr_get_external_clock(mgr, mgr->use_clock_type,
796 rate = mgr->sample_rate;
798 pcxhr_set_clock(mgr, rate);
799 if (mgr->sample_rate)
800 mgr->sample_rate = rate;
802 mutex_unlock(&mgr->setup_mutex);
803 ret = 1; /* return 1 even if the set was not done. ok ? */
805 mutex_unlock(&mgr->mixer_mutex);
809 static struct snd_kcontrol_new pcxhr_control_clock_type = {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Clock Mode",
812 .info = pcxhr_clock_type_info,
813 .get = pcxhr_clock_type_get,
814 .put = pcxhr_clock_type_put,
819 * specific control that scans the sample rates on the external plugs
821 static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_info *uinfo)
824 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
825 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
826 uinfo->count = 3 + mgr->capture_chips;
827 uinfo->value.integer.min = 0; /* clock not present */
828 uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
832 static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_value *ucontrol)
835 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
838 mutex_lock(&mgr->mixer_mutex);
839 for(i = 0; i < 3 + mgr->capture_chips; i++) {
840 if (i == PCXHR_CLOCK_TYPE_INTERNAL)
841 rate = mgr->sample_rate_real;
843 err = pcxhr_get_external_clock(mgr, i, &rate);
847 ucontrol->value.integer.value[i] = rate;
849 mutex_unlock(&mgr->mixer_mutex);
853 static struct snd_kcontrol_new pcxhr_control_clock_rate = {
854 .access = SNDRV_CTL_ELEM_ACCESS_READ,
855 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
856 .name = "Clock Rates",
857 .info = pcxhr_clock_rate_info,
858 .get = pcxhr_clock_rate_get,
864 static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
865 struct snd_ctl_elem_info *uinfo)
867 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
872 static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
873 int aes_idx, unsigned char *aes_bits)
877 struct pcxhr_rmh rmh;
879 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
880 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
881 switch (chip->chip_idx) {
882 /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
883 case 0: rmh.cmd[1] = CS8420_01_CS; break;
884 case 1: rmh.cmd[1] = CS8420_23_CS; break;
885 case 2: rmh.cmd[1] = CS8420_45_CS; break;
886 case 3: rmh.cmd[1] = CS8420_67_CS; break;
887 default: return -EINVAL;
889 if (chip->mgr->board_aes_in_192k) {
891 case 0: rmh.cmd[2] = CS8416_CSB0; break;
892 case 1: rmh.cmd[2] = CS8416_CSB1; break;
893 case 2: rmh.cmd[2] = CS8416_CSB2; break;
894 case 3: rmh.cmd[2] = CS8416_CSB3; break;
895 case 4: rmh.cmd[2] = CS8416_CSB4; break;
896 default: return -EINVAL;
900 /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
901 case 0: rmh.cmd[2] = CS8420_CSB0; break;
902 case 1: rmh.cmd[2] = CS8420_CSB1; break;
903 case 2: rmh.cmd[2] = CS8420_CSB2; break;
904 case 3: rmh.cmd[2] = CS8420_CSB3; break;
905 case 4: rmh.cmd[2] = CS8420_CSB4; break;
906 default: return -EINVAL;
909 /* size and code the chip id for the fpga */
910 rmh.cmd[1] &= 0x0fffff;
911 /* chip signature + map for spi read */
912 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
914 err = pcxhr_send_msg(chip->mgr, &rmh);
918 if (chip->mgr->board_aes_in_192k) {
919 temp = (unsigned char)rmh.stat[1];
922 /* reversed bit order (not with CS8416_01_CS) */
923 for (i = 0; i < 8; i++) {
925 if (rmh.stat[1] & (1 << i))
929 snd_printdd("read iec958 AES %d byte %d = 0x%x\n",
930 chip->chip_idx, aes_idx, temp);
935 static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
936 struct snd_ctl_elem_value *ucontrol)
938 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
939 unsigned char aes_bits;
942 mutex_lock(&chip->mgr->mixer_mutex);
943 for(i = 0; i < 5; i++) {
944 if (kcontrol->private_value == 0) /* playback */
945 aes_bits = chip->aes_bits[i];
947 if (chip->mgr->is_hr_stereo)
948 err = hr222_iec958_capture_byte(chip, i,
951 err = pcxhr_iec958_capture_byte(chip, i,
956 ucontrol->value.iec958.status[i] = aes_bits;
958 mutex_unlock(&chip->mgr->mixer_mutex);
962 static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
963 struct snd_ctl_elem_value *ucontrol)
966 for (i = 0; i < 5; i++)
967 ucontrol->value.iec958.status[i] = 0xff;
971 static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
972 int aes_idx, unsigned char aes_bits)
975 unsigned char new_bits = aes_bits;
976 unsigned char old_bits = chip->aes_bits[aes_idx];
977 struct pcxhr_rmh rmh;
979 for (i = 0; i < 8; i++) {
980 if ((old_bits & 0x01) != (new_bits & 0x01)) {
981 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
982 if (chip->chip_idx > 3)
983 /* new bit used if chip_idx>3 (PCX1222HR) */
985 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
986 cmd |= (new_bits & 0x01) << 23; /* add bit value */
987 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
988 rmh.cmd[0] |= IO_NUM_REG_CUER;
991 snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n",
992 chip->chip_idx, aes_idx, i, cmd);
993 err = pcxhr_send_msg(chip->mgr, &rmh);
1000 chip->aes_bits[aes_idx] = aes_bits;
1004 static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
1005 struct snd_ctl_elem_value *ucontrol)
1007 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
1011 mutex_lock(&chip->mgr->mixer_mutex);
1012 for (i = 0; i < 5; i++) {
1013 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
1014 if (chip->mgr->is_hr_stereo)
1015 hr222_iec958_update_byte(chip, i,
1016 ucontrol->value.iec958.status[i]);
1018 pcxhr_iec958_update_byte(chip, i,
1019 ucontrol->value.iec958.status[i]);
1023 mutex_unlock(&chip->mgr->mixer_mutex);
1027 static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
1028 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1029 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1030 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1031 .info = pcxhr_iec958_info,
1032 .get = pcxhr_iec958_mask_get
1034 static struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
1035 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1036 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1037 .info = pcxhr_iec958_info,
1038 .get = pcxhr_iec958_get,
1039 .put = pcxhr_iec958_put,
1040 .private_value = 0 /* playback */
1043 static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
1044 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1045 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1046 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
1047 .info = pcxhr_iec958_info,
1048 .get = pcxhr_iec958_mask_get
1050 static struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
1051 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1052 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1053 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1054 .info = pcxhr_iec958_info,
1055 .get = pcxhr_iec958_get,
1056 .private_value = 1 /* capture */
1059 static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
1063 for (i = 0; i < 2; i++) {
1064 if (chip->nb_streams_play) {
1066 /* at boot time the digital volumes are unmuted 0dB */
1067 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
1068 chip->digital_playback_active[j][i] = 1;
1069 chip->digital_playback_volume[j][i] =
1070 PCXHR_DIGITAL_ZERO_LEVEL;
1072 /* after boot, only two bits are set on the uer
1075 chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
1076 IEC958_AES0_PRO_FS_48000);
1077 #ifdef CONFIG_SND_DEBUG
1078 /* analog volumes for playback
1079 * (is LEVEL_MIN after boot)
1081 chip->analog_playback_active[i] = 1;
1082 if (chip->mgr->is_hr_stereo)
1083 chip->analog_playback_volume[i] =
1084 HR222_LINE_PLAYBACK_ZERO_LEVEL;
1086 chip->analog_playback_volume[i] =
1087 PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
1088 pcxhr_update_analog_audio_level(chip, 0, i);
1091 /* stereo cards need to be initialised after boot */
1092 if (chip->mgr->is_hr_stereo)
1093 hr222_update_analog_audio_level(chip, 0, i);
1095 if (chip->nb_streams_capt) {
1096 /* at boot time the digital volumes are unmuted 0dB */
1097 chip->digital_capture_volume[i] =
1098 PCXHR_DIGITAL_ZERO_LEVEL;
1099 chip->analog_capture_active = 1;
1100 #ifdef CONFIG_SND_DEBUG
1101 /* analog volumes for playback
1102 * (is LEVEL_MIN after boot)
1104 if (chip->mgr->is_hr_stereo)
1105 chip->analog_capture_volume[i] =
1106 HR222_LINE_CAPTURE_ZERO_LEVEL;
1108 chip->analog_capture_volume[i] =
1109 PCXHR_LINE_CAPTURE_ZERO_LEVEL;
1110 pcxhr_update_analog_audio_level(chip, 1, i);
1113 /* stereo cards need to be initialised after boot */
1114 if (chip->mgr->is_hr_stereo)
1115 hr222_update_analog_audio_level(chip, 1, i);
1123 int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
1125 struct snd_pcxhr *chip;
1128 mutex_init(&mgr->mixer_mutex); /* can be in another place */
1130 for (i = 0; i < mgr->num_cards; i++) {
1131 struct snd_kcontrol_new temp;
1132 chip = mgr->chip[i];
1134 if (chip->nb_streams_play) {
1135 /* analog output level control */
1136 temp = pcxhr_control_analog_level;
1137 temp.name = "Master Playback Volume";
1138 temp.private_value = 0; /* playback */
1139 if (mgr->is_hr_stereo)
1140 temp.tlv.p = db_scale_a_hr222_playback;
1142 temp.tlv.p = db_scale_analog_playback;
1143 err = snd_ctl_add(chip->card,
1144 snd_ctl_new1(&temp, chip));
1148 /* output mute controls */
1149 err = snd_ctl_add(chip->card,
1150 snd_ctl_new1(&pcxhr_control_output_switch,
1155 temp = snd_pcxhr_pcm_vol;
1156 temp.name = "PCM Playback Volume";
1157 temp.count = PCXHR_PLAYBACK_STREAMS;
1158 temp.private_value = 0; /* playback */
1159 err = snd_ctl_add(chip->card,
1160 snd_ctl_new1(&temp, chip));
1164 err = snd_ctl_add(chip->card,
1165 snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
1169 /* IEC958 controls */
1170 err = snd_ctl_add(chip->card,
1171 snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
1176 err = snd_ctl_add(chip->card,
1177 snd_ctl_new1(&pcxhr_control_playback_iec958,
1182 if (chip->nb_streams_capt) {
1183 /* analog input level control */
1184 temp = pcxhr_control_analog_level;
1185 temp.name = "Line Capture Volume";
1186 temp.private_value = 1; /* capture */
1187 if (mgr->is_hr_stereo)
1188 temp.tlv.p = db_scale_a_hr222_capture;
1190 temp.tlv.p = db_scale_analog_capture;
1192 err = snd_ctl_add(chip->card,
1193 snd_ctl_new1(&temp, chip));
1197 temp = snd_pcxhr_pcm_vol;
1198 temp.name = "PCM Capture Volume";
1200 temp.private_value = 1; /* capture */
1202 err = snd_ctl_add(chip->card,
1203 snd_ctl_new1(&temp, chip));
1208 err = snd_ctl_add(chip->card,
1209 snd_ctl_new1(&pcxhr_control_audio_src, chip));
1213 /* IEC958 controls */
1214 err = snd_ctl_add(chip->card,
1215 snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1220 err = snd_ctl_add(chip->card,
1221 snd_ctl_new1(&pcxhr_control_capture_iec958,
1226 if (mgr->is_hr_stereo) {
1227 err = hr222_add_mic_controls(chip);
1232 /* monitoring only if playback and capture device available */
1233 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1235 err = snd_ctl_add(chip->card,
1236 snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
1240 err = snd_ctl_add(chip->card,
1241 snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
1247 /* clock mode only one control per pcxhr */
1248 err = snd_ctl_add(chip->card,
1249 snd_ctl_new1(&pcxhr_control_clock_type, mgr));
1252 /* non standard control used to scan
1253 * the external clock presence/frequencies
1255 err = snd_ctl_add(chip->card,
1256 snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
1261 /* init values for the mixer data */
1262 pcxhr_init_audio_levels(chip);