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 dev_dbg(chip->card->dev,
76 "error update_analog_audio_level card(%d)"
77 " is_capture(%d) err(%x)\n",
78 chip->chip_idx, is_capture, err);
85 * analog level control
87 static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
88 struct snd_ctl_elem_info *uinfo)
90 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
92 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
94 if (kcontrol->private_value == 0) { /* playback */
95 if (chip->mgr->is_hr_stereo) {
96 uinfo->value.integer.min =
97 HR222_LINE_PLAYBACK_LEVEL_MIN; /* -25 dB */
98 uinfo->value.integer.max =
99 HR222_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
101 uinfo->value.integer.min =
102 PCXHR_LINE_PLAYBACK_LEVEL_MIN; /*-104 dB */
103 uinfo->value.integer.max =
104 PCXHR_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
106 } else { /* capture */
107 if (chip->mgr->is_hr_stereo) {
108 uinfo->value.integer.min =
109 HR222_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
110 uinfo->value.integer.max =
111 HR222_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
113 uinfo->value.integer.min =
114 PCXHR_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
115 uinfo->value.integer.max =
116 PCXHR_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
122 static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
123 struct snd_ctl_elem_value *ucontrol)
125 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
126 mutex_lock(&chip->mgr->mixer_mutex);
127 if (kcontrol->private_value == 0) { /* playback */
128 ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
129 ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
130 } else { /* capture */
131 ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
132 ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
134 mutex_unlock(&chip->mgr->mixer_mutex);
138 static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
139 struct snd_ctl_elem_value *ucontrol)
141 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
145 mutex_lock(&chip->mgr->mixer_mutex);
146 is_capture = (kcontrol->private_value != 0);
147 for (i = 0; i < 2; i++) {
148 int new_volume = ucontrol->value.integer.value[i];
149 int *stored_volume = is_capture ?
150 &chip->analog_capture_volume[i] :
151 &chip->analog_playback_volume[i];
153 if (chip->mgr->is_hr_stereo) {
154 if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN ||
155 new_volume > HR222_LINE_CAPTURE_LEVEL_MAX)
158 if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN ||
159 new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX)
163 if (chip->mgr->is_hr_stereo) {
164 if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN ||
165 new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX)
168 if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN ||
169 new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX)
173 if (*stored_volume != new_volume) {
174 *stored_volume = new_volume;
176 if (chip->mgr->is_hr_stereo)
177 hr222_update_analog_audio_level(chip,
180 pcxhr_update_analog_audio_level(chip,
184 mutex_unlock(&chip->mgr->mixer_mutex);
188 static struct snd_kcontrol_new pcxhr_control_analog_level = {
189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
190 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
191 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
192 /* name will be filled later */
193 .info = pcxhr_analog_vol_info,
194 .get = pcxhr_analog_vol_get,
195 .put = pcxhr_analog_vol_put,
196 /* tlv will be filled later */
201 #define pcxhr_sw_info snd_ctl_boolean_stereo_info
203 static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
204 struct snd_ctl_elem_value *ucontrol)
206 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
208 mutex_lock(&chip->mgr->mixer_mutex);
209 ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
210 ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
211 mutex_unlock(&chip->mgr->mixer_mutex);
215 static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_value *ucontrol)
218 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
220 mutex_lock(&chip->mgr->mixer_mutex);
221 for(i = 0; i < 2; i++) {
222 if (chip->analog_playback_active[i] !=
223 ucontrol->value.integer.value[i]) {
224 chip->analog_playback_active[i] =
225 !!ucontrol->value.integer.value[i];
227 /* update playback levels */
228 if (chip->mgr->is_hr_stereo)
229 hr222_update_analog_audio_level(chip, 0, i);
231 pcxhr_update_analog_audio_level(chip, 0, i);
234 mutex_unlock(&chip->mgr->mixer_mutex);
238 static struct snd_kcontrol_new pcxhr_control_output_switch = {
239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
240 .name = "Master Playback Switch",
241 .info = pcxhr_sw_info, /* shared */
242 .get = pcxhr_audio_sw_get,
243 .put = pcxhr_audio_sw_put
247 #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */
248 #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */
249 #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */
251 static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10975, 25, 1800);
253 #define MORE_THAN_ONE_STREAM_LEVEL 0x000001
254 #define VALID_STREAM_PAN_LEVEL_MASK 0x800000
255 #define VALID_STREAM_LEVEL_MASK 0x400000
256 #define VALID_STREAM_LEVEL_1_MASK 0x200000
257 #define VALID_STREAM_LEVEL_2_MASK 0x100000
259 static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
262 struct pcxhr_rmh rmh;
263 struct pcxhr_pipe *pipe = &chip->playback_pipe;
266 if (chip->digital_playback_active[idx][0])
267 left = chip->digital_playback_volume[idx][0];
269 left = PCXHR_DIGITAL_LEVEL_MIN;
270 if (chip->digital_playback_active[idx][1])
271 right = chip->digital_playback_volume[idx][1];
273 right = PCXHR_DIGITAL_LEVEL_MIN;
275 pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST);
276 /* add pipe and stream mask */
277 pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx);
278 /* volume left->left / right->right panoramic level */
279 rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL;
280 rmh.cmd[2] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK;
281 rmh.cmd[2] |= (left << 10);
282 rmh.cmd[3] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK;
286 err = pcxhr_send_msg(chip->mgr, &rmh);
288 dev_dbg(chip->card->dev, "error update_playback_stream_level "
289 "card(%d) err(%x)\n", chip->chip_idx, err);
295 #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
296 #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000
297 #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001
298 #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002
299 #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
300 #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
302 static int pcxhr_update_audio_pipe_level(struct snd_pcxhr *chip,
303 int capture, int channel)
306 struct pcxhr_rmh rmh;
307 struct pcxhr_pipe *pipe;
310 pipe = &chip->capture_pipe[0];
312 pipe = &chip->playback_pipe;
314 pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
315 /* add channel mask */
316 pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0,
317 1 << (channel + pipe->first_audio));
318 /* TODO : if mask (3 << pipe->first_audio) is used, left and right
319 * channel will be programmed to the same params */
321 rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
322 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled
323 * (capture pipe level) */
324 rmh.cmd[2] = chip->digital_capture_volume[channel];
326 rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL |
327 VALID_AUDIO_IO_MUTE_MONITOR_1;
328 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL
329 * not yet handled (playback pipe level)
331 rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
332 if (chip->monitoring_active[channel] == 0)
333 rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1;
337 err = pcxhr_send_msg(chip->mgr, &rmh);
339 dev_dbg(chip->card->dev,
340 "error update_audio_level(%d) err=%x\n",
341 chip->chip_idx, err);
349 static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol,
350 struct snd_ctl_elem_info *uinfo)
352 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
354 uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */
355 uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */
360 static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
361 struct snd_ctl_elem_value *ucontrol)
363 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
364 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
366 int is_capture = kcontrol->private_value;
368 mutex_lock(&chip->mgr->mixer_mutex);
369 if (is_capture) /* digital capture */
370 stored_volume = chip->digital_capture_volume;
371 else /* digital playback */
372 stored_volume = chip->digital_playback_volume[idx];
373 ucontrol->value.integer.value[0] = stored_volume[0];
374 ucontrol->value.integer.value[1] = stored_volume[1];
375 mutex_unlock(&chip->mgr->mixer_mutex);
379 static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
382 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
383 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
385 int is_capture = kcontrol->private_value;
389 mutex_lock(&chip->mgr->mixer_mutex);
390 if (is_capture) /* digital capture */
391 stored_volume = chip->digital_capture_volume;
392 else /* digital playback */
393 stored_volume = chip->digital_playback_volume[idx];
394 for (i = 0; i < 2; i++) {
395 int vol = ucontrol->value.integer.value[i];
396 if (vol < PCXHR_DIGITAL_LEVEL_MIN ||
397 vol > PCXHR_DIGITAL_LEVEL_MAX)
399 if (stored_volume[i] != vol) {
400 stored_volume[i] = vol;
402 if (is_capture) /* update capture volume */
403 pcxhr_update_audio_pipe_level(chip, 1, i);
406 if (!is_capture && changed) /* update playback volume */
407 pcxhr_update_playback_stream_level(chip, idx);
408 mutex_unlock(&chip->mgr->mixer_mutex);
412 static struct snd_kcontrol_new snd_pcxhr_pcm_vol =
414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
415 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
416 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
417 /* name will be filled later */
418 /* count will be filled later */
419 .info = pcxhr_digital_vol_info, /* shared */
420 .get = pcxhr_pcm_vol_get,
421 .put = pcxhr_pcm_vol_put,
422 .tlv = { .p = db_scale_digital },
426 static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol)
429 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
430 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
432 mutex_lock(&chip->mgr->mixer_mutex);
433 ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
434 ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
435 mutex_unlock(&chip->mgr->mixer_mutex);
439 static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol,
440 struct snd_ctl_elem_value *ucontrol)
442 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
444 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
447 mutex_lock(&chip->mgr->mixer_mutex);
449 for (i = 0; i < 2; i++) {
450 if (chip->digital_playback_active[j][i] !=
451 ucontrol->value.integer.value[i]) {
452 chip->digital_playback_active[j][i] =
453 !!ucontrol->value.integer.value[i];
458 pcxhr_update_playback_stream_level(chip, idx);
459 mutex_unlock(&chip->mgr->mixer_mutex);
463 static struct snd_kcontrol_new pcxhr_control_pcm_switch = {
464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
465 .name = "PCM Playback Switch",
466 .count = PCXHR_PLAYBACK_STREAMS,
467 .info = pcxhr_sw_info, /* shared */
468 .get = pcxhr_pcm_sw_get,
469 .put = pcxhr_pcm_sw_put
474 * monitoring level control
477 static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
478 struct snd_ctl_elem_value *ucontrol)
480 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
481 mutex_lock(&chip->mgr->mixer_mutex);
482 ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
483 ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
484 mutex_unlock(&chip->mgr->mixer_mutex);
488 static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
489 struct snd_ctl_elem_value *ucontrol)
491 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
495 mutex_lock(&chip->mgr->mixer_mutex);
496 for (i = 0; i < 2; i++) {
497 if (chip->monitoring_volume[i] !=
498 ucontrol->value.integer.value[i]) {
499 chip->monitoring_volume[i] =
500 ucontrol->value.integer.value[i];
501 if (chip->monitoring_active[i])
502 /* update monitoring volume and mute */
503 /* do only when monitoring is unmuted */
504 pcxhr_update_audio_pipe_level(chip, 0, i);
508 mutex_unlock(&chip->mgr->mixer_mutex);
512 static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
514 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
515 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
516 .name = "Monitoring Playback Volume",
517 .info = pcxhr_digital_vol_info, /* shared */
518 .get = pcxhr_monitor_vol_get,
519 .put = pcxhr_monitor_vol_put,
520 .tlv = { .p = db_scale_digital },
524 * monitoring switch control
527 static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
528 struct snd_ctl_elem_value *ucontrol)
530 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
531 mutex_lock(&chip->mgr->mixer_mutex);
532 ucontrol->value.integer.value[0] = chip->monitoring_active[0];
533 ucontrol->value.integer.value[1] = chip->monitoring_active[1];
534 mutex_unlock(&chip->mgr->mixer_mutex);
538 static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
539 struct snd_ctl_elem_value *ucontrol)
541 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
545 mutex_lock(&chip->mgr->mixer_mutex);
546 for (i = 0; i < 2; i++) {
547 if (chip->monitoring_active[i] !=
548 ucontrol->value.integer.value[i]) {
549 chip->monitoring_active[i] =
550 !!ucontrol->value.integer.value[i];
551 changed |= (1<<i); /* mask 0x01 and 0x02 */
555 /* update left monitoring volume and mute */
556 pcxhr_update_audio_pipe_level(chip, 0, 0);
558 /* update right monitoring volume and mute */
559 pcxhr_update_audio_pipe_level(chip, 0, 1);
561 mutex_unlock(&chip->mgr->mixer_mutex);
562 return (changed != 0);
565 static struct snd_kcontrol_new pcxhr_control_monitor_sw = {
566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
567 .name = "Monitoring Playback Switch",
568 .info = pcxhr_sw_info, /* shared */
569 .get = pcxhr_monitor_sw_get,
570 .put = pcxhr_monitor_sw_put
576 * audio source select
578 #define PCXHR_SOURCE_AUDIO01_UER 0x000100
579 #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200
580 #define PCXHR_SOURCE_AUDIO23_UER 0x000400
581 #define PCXHR_SOURCE_AUDIO45_UER 0x001000
582 #define PCXHR_SOURCE_AUDIO67_UER 0x040000
584 static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
586 struct pcxhr_rmh rmh;
587 unsigned int mask, reg;
591 switch (chip->chip_idx) {
592 case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
593 case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break;
594 case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break;
595 case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
596 default: return -EINVAL;
598 if (chip->audio_capture_source != 0) {
599 reg = mask; /* audio source from digital plug */
601 reg = 0; /* audio source from analog plug */
603 /* set the input source */
604 pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
605 /* resync them (otherwise channel inversion possible) */
607 pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS);
608 rmh.cmd[0] |= (1 << chip->chip_idx);
609 err = pcxhr_send_msg(chip->mgr, &rmh);
613 if (chip->mgr->board_aes_in_192k) {
615 unsigned int src_config = 0xC0;
616 /* update all src configs with one call */
617 for (i = 0; (i < 4) && (i < chip->mgr->capture_chips); i++) {
618 if (chip->mgr->chip[i]->audio_capture_source == 2)
619 src_config |= (1 << (3 - i));
621 /* set codec SRC on off */
622 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
624 rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC;
625 rmh.cmd[1] = src_config;
626 err = pcxhr_send_msg(chip->mgr, &rmh);
629 if (chip->audio_capture_source == 2)
631 /* set codec SRC on off */
632 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
634 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
636 rmh.cmd[2] = ((CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) |
637 (use_src ? 0x41 : 0x54));
638 err = pcxhr_send_msg(chip->mgr, &rmh);
641 rmh.cmd[2] = ((CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) |
642 (use_src ? 0x41 : 0x49));
643 err = pcxhr_send_msg(chip->mgr, &rmh);
648 static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_info *uinfo)
651 static const char *texts[5] = {
652 "Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"
655 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
657 i = 2; /* no SRC, no Mic available */
658 if (chip->mgr->board_has_aes1) {
659 i = 3; /* SRC available */
660 if (chip->mgr->board_has_mic)
661 i = 5; /* Mic and MicroMix available */
663 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
665 uinfo->value.enumerated.items = i;
666 if (uinfo->value.enumerated.item > (i-1))
667 uinfo->value.enumerated.item = i-1;
668 strcpy(uinfo->value.enumerated.name,
669 texts[uinfo->value.enumerated.item]);
673 static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_value *ucontrol)
676 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
677 ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
681 static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
684 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
686 int i = 2; /* no SRC, no Mic available */
687 if (chip->mgr->board_has_aes1) {
688 i = 3; /* SRC available */
689 if (chip->mgr->board_has_mic)
690 i = 5; /* Mic and MicroMix available */
692 if (ucontrol->value.enumerated.item[0] >= i)
694 mutex_lock(&chip->mgr->mixer_mutex);
695 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
696 chip->audio_capture_source = ucontrol->value.enumerated.item[0];
697 if (chip->mgr->is_hr_stereo)
698 hr222_set_audio_source(chip);
700 pcxhr_set_audio_source(chip);
703 mutex_unlock(&chip->mgr->mixer_mutex);
707 static struct snd_kcontrol_new pcxhr_control_audio_src = {
708 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
709 .name = "Capture Source",
710 .info = pcxhr_audio_src_info,
711 .get = pcxhr_audio_src_get,
712 .put = pcxhr_audio_src_put,
717 * clock type selection
718 * enum pcxhr_clock_type {
719 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
720 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
721 * PCXHR_CLOCK_TYPE_AES_SYNC,
722 * PCXHR_CLOCK_TYPE_AES_1,
723 * PCXHR_CLOCK_TYPE_AES_2,
724 * PCXHR_CLOCK_TYPE_AES_3,
725 * PCXHR_CLOCK_TYPE_AES_4,
726 * PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
727 * HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
728 * HR22_CLOCK_TYPE_AES_SYNC,
729 * HR22_CLOCK_TYPE_AES_1,
730 * HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
734 static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
735 struct snd_ctl_elem_info *uinfo)
737 static const char *textsPCXHR[7] = {
738 "Internal", "WordClock", "AES Sync",
739 "AES 1", "AES 2", "AES 3", "AES 4"
741 static const char *textsHR22[3] = {
742 "Internal", "AES Sync", "AES 1"
745 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
746 int clock_items = 2; /* at least Internal and AES Sync clock */
747 if (mgr->board_has_aes1) {
748 clock_items += mgr->capture_chips; /* add AES x */
749 if (!mgr->is_hr_stereo)
750 clock_items += 1; /* add word clock */
752 if (mgr->is_hr_stereo) {
754 snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1));
757 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
759 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
761 uinfo->value.enumerated.items = clock_items;
762 if (uinfo->value.enumerated.item >= clock_items)
763 uinfo->value.enumerated.item = clock_items-1;
764 strcpy(uinfo->value.enumerated.name,
765 texts[uinfo->value.enumerated.item]);
769 static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_value *ucontrol)
772 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
773 ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
777 static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value *ucontrol)
780 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
782 unsigned int clock_items = 2; /* at least Internal and AES Sync clock */
783 if (mgr->board_has_aes1) {
784 clock_items += mgr->capture_chips; /* add AES x */
785 if (!mgr->is_hr_stereo)
786 clock_items += 1; /* add word clock */
788 if (ucontrol->value.enumerated.item[0] >= clock_items)
790 mutex_lock(&mgr->mixer_mutex);
791 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
792 mutex_lock(&mgr->setup_mutex);
793 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
795 if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) {
796 pcxhr_get_external_clock(mgr, mgr->use_clock_type,
799 rate = mgr->sample_rate;
804 pcxhr_set_clock(mgr, rate);
805 if (mgr->sample_rate)
806 mgr->sample_rate = rate;
808 mutex_unlock(&mgr->setup_mutex);
809 ret = 1; /* return 1 even if the set was not done. ok ? */
811 mutex_unlock(&mgr->mixer_mutex);
815 static struct snd_kcontrol_new pcxhr_control_clock_type = {
816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
817 .name = "Clock Mode",
818 .info = pcxhr_clock_type_info,
819 .get = pcxhr_clock_type_get,
820 .put = pcxhr_clock_type_put,
825 * specific control that scans the sample rates on the external plugs
827 static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_info *uinfo)
830 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
831 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
832 uinfo->count = 3 + mgr->capture_chips;
833 uinfo->value.integer.min = 0; /* clock not present */
834 uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
838 static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
841 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
844 mutex_lock(&mgr->mixer_mutex);
845 for(i = 0; i < 3 + mgr->capture_chips; i++) {
846 if (i == PCXHR_CLOCK_TYPE_INTERNAL)
847 rate = mgr->sample_rate_real;
849 err = pcxhr_get_external_clock(mgr, i, &rate);
853 ucontrol->value.integer.value[i] = rate;
855 mutex_unlock(&mgr->mixer_mutex);
859 static struct snd_kcontrol_new pcxhr_control_clock_rate = {
860 .access = SNDRV_CTL_ELEM_ACCESS_READ,
861 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
862 .name = "Clock Rates",
863 .info = pcxhr_clock_rate_info,
864 .get = pcxhr_clock_rate_get,
870 static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
871 struct snd_ctl_elem_info *uinfo)
873 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
878 static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
879 int aes_idx, unsigned char *aes_bits)
883 struct pcxhr_rmh rmh;
885 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
886 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
887 switch (chip->chip_idx) {
888 /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
889 case 0: rmh.cmd[1] = CS8420_01_CS; break;
890 case 1: rmh.cmd[1] = CS8420_23_CS; break;
891 case 2: rmh.cmd[1] = CS8420_45_CS; break;
892 case 3: rmh.cmd[1] = CS8420_67_CS; break;
893 default: return -EINVAL;
895 if (chip->mgr->board_aes_in_192k) {
897 case 0: rmh.cmd[2] = CS8416_CSB0; break;
898 case 1: rmh.cmd[2] = CS8416_CSB1; break;
899 case 2: rmh.cmd[2] = CS8416_CSB2; break;
900 case 3: rmh.cmd[2] = CS8416_CSB3; break;
901 case 4: rmh.cmd[2] = CS8416_CSB4; break;
902 default: return -EINVAL;
906 /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
907 case 0: rmh.cmd[2] = CS8420_CSB0; break;
908 case 1: rmh.cmd[2] = CS8420_CSB1; break;
909 case 2: rmh.cmd[2] = CS8420_CSB2; break;
910 case 3: rmh.cmd[2] = CS8420_CSB3; break;
911 case 4: rmh.cmd[2] = CS8420_CSB4; break;
912 default: return -EINVAL;
915 /* size and code the chip id for the fpga */
916 rmh.cmd[1] &= 0x0fffff;
917 /* chip signature + map for spi read */
918 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
920 err = pcxhr_send_msg(chip->mgr, &rmh);
924 if (chip->mgr->board_aes_in_192k) {
925 temp = (unsigned char)rmh.stat[1];
928 /* reversed bit order (not with CS8416_01_CS) */
929 for (i = 0; i < 8; i++) {
931 if (rmh.stat[1] & (1 << i))
935 dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n",
936 chip->chip_idx, aes_idx, temp);
941 static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
942 struct snd_ctl_elem_value *ucontrol)
944 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
945 unsigned char aes_bits;
948 mutex_lock(&chip->mgr->mixer_mutex);
949 for(i = 0; i < 5; i++) {
950 if (kcontrol->private_value == 0) /* playback */
951 aes_bits = chip->aes_bits[i];
953 if (chip->mgr->is_hr_stereo)
954 err = hr222_iec958_capture_byte(chip, i,
957 err = pcxhr_iec958_capture_byte(chip, i,
962 ucontrol->value.iec958.status[i] = aes_bits;
964 mutex_unlock(&chip->mgr->mixer_mutex);
968 static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
969 struct snd_ctl_elem_value *ucontrol)
972 for (i = 0; i < 5; i++)
973 ucontrol->value.iec958.status[i] = 0xff;
977 static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
978 int aes_idx, unsigned char aes_bits)
981 unsigned char new_bits = aes_bits;
982 unsigned char old_bits = chip->aes_bits[aes_idx];
983 struct pcxhr_rmh rmh;
985 for (i = 0; i < 8; i++) {
986 if ((old_bits & 0x01) != (new_bits & 0x01)) {
987 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
988 if (chip->chip_idx > 3)
989 /* new bit used if chip_idx>3 (PCX1222HR) */
991 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
992 cmd |= (new_bits & 0x01) << 23; /* add bit value */
993 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
994 rmh.cmd[0] |= IO_NUM_REG_CUER;
997 dev_dbg(chip->card->dev,
998 "write iec958 AES %d byte %d bit %d (cmd %x)\n",
999 chip->chip_idx, aes_idx, i, cmd);
1000 err = pcxhr_send_msg(chip->mgr, &rmh);
1007 chip->aes_bits[aes_idx] = aes_bits;
1011 static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
1012 struct snd_ctl_elem_value *ucontrol)
1014 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
1018 mutex_lock(&chip->mgr->mixer_mutex);
1019 for (i = 0; i < 5; i++) {
1020 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
1021 if (chip->mgr->is_hr_stereo)
1022 hr222_iec958_update_byte(chip, i,
1023 ucontrol->value.iec958.status[i]);
1025 pcxhr_iec958_update_byte(chip, i,
1026 ucontrol->value.iec958.status[i]);
1030 mutex_unlock(&chip->mgr->mixer_mutex);
1034 static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
1035 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1036 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1037 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1038 .info = pcxhr_iec958_info,
1039 .get = pcxhr_iec958_mask_get
1041 static struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
1042 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1043 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1044 .info = pcxhr_iec958_info,
1045 .get = pcxhr_iec958_get,
1046 .put = pcxhr_iec958_put,
1047 .private_value = 0 /* playback */
1050 static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
1051 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1052 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1053 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
1054 .info = pcxhr_iec958_info,
1055 .get = pcxhr_iec958_mask_get
1057 static struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
1058 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1059 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1060 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1061 .info = pcxhr_iec958_info,
1062 .get = pcxhr_iec958_get,
1063 .private_value = 1 /* capture */
1066 static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
1070 for (i = 0; i < 2; i++) {
1071 if (chip->nb_streams_play) {
1073 /* at boot time the digital volumes are unmuted 0dB */
1074 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
1075 chip->digital_playback_active[j][i] = 1;
1076 chip->digital_playback_volume[j][i] =
1077 PCXHR_DIGITAL_ZERO_LEVEL;
1079 /* after boot, only two bits are set on the uer
1082 chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
1083 IEC958_AES0_PRO_FS_48000);
1084 #ifdef CONFIG_SND_DEBUG
1085 /* analog volumes for playback
1086 * (is LEVEL_MIN after boot)
1088 chip->analog_playback_active[i] = 1;
1089 if (chip->mgr->is_hr_stereo)
1090 chip->analog_playback_volume[i] =
1091 HR222_LINE_PLAYBACK_ZERO_LEVEL;
1093 chip->analog_playback_volume[i] =
1094 PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
1095 pcxhr_update_analog_audio_level(chip, 0, i);
1098 /* stereo cards need to be initialised after boot */
1099 if (chip->mgr->is_hr_stereo)
1100 hr222_update_analog_audio_level(chip, 0, i);
1102 if (chip->nb_streams_capt) {
1103 /* at boot time the digital volumes are unmuted 0dB */
1104 chip->digital_capture_volume[i] =
1105 PCXHR_DIGITAL_ZERO_LEVEL;
1106 chip->analog_capture_active = 1;
1107 #ifdef CONFIG_SND_DEBUG
1108 /* analog volumes for playback
1109 * (is LEVEL_MIN after boot)
1111 if (chip->mgr->is_hr_stereo)
1112 chip->analog_capture_volume[i] =
1113 HR222_LINE_CAPTURE_ZERO_LEVEL;
1115 chip->analog_capture_volume[i] =
1116 PCXHR_LINE_CAPTURE_ZERO_LEVEL;
1117 pcxhr_update_analog_audio_level(chip, 1, i);
1120 /* stereo cards need to be initialised after boot */
1121 if (chip->mgr->is_hr_stereo)
1122 hr222_update_analog_audio_level(chip, 1, i);
1130 int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
1132 struct snd_pcxhr *chip;
1135 mutex_init(&mgr->mixer_mutex); /* can be in another place */
1137 for (i = 0; i < mgr->num_cards; i++) {
1138 struct snd_kcontrol_new temp;
1139 chip = mgr->chip[i];
1141 if (chip->nb_streams_play) {
1142 /* analog output level control */
1143 temp = pcxhr_control_analog_level;
1144 temp.name = "Master Playback Volume";
1145 temp.private_value = 0; /* playback */
1146 if (mgr->is_hr_stereo)
1147 temp.tlv.p = db_scale_a_hr222_playback;
1149 temp.tlv.p = db_scale_analog_playback;
1150 err = snd_ctl_add(chip->card,
1151 snd_ctl_new1(&temp, chip));
1155 /* output mute controls */
1156 err = snd_ctl_add(chip->card,
1157 snd_ctl_new1(&pcxhr_control_output_switch,
1162 temp = snd_pcxhr_pcm_vol;
1163 temp.name = "PCM Playback Volume";
1164 temp.count = PCXHR_PLAYBACK_STREAMS;
1165 temp.private_value = 0; /* playback */
1166 err = snd_ctl_add(chip->card,
1167 snd_ctl_new1(&temp, chip));
1171 err = snd_ctl_add(chip->card,
1172 snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
1176 /* IEC958 controls */
1177 err = snd_ctl_add(chip->card,
1178 snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
1183 err = snd_ctl_add(chip->card,
1184 snd_ctl_new1(&pcxhr_control_playback_iec958,
1189 if (chip->nb_streams_capt) {
1190 /* analog input level control */
1191 temp = pcxhr_control_analog_level;
1192 temp.name = "Line Capture Volume";
1193 temp.private_value = 1; /* capture */
1194 if (mgr->is_hr_stereo)
1195 temp.tlv.p = db_scale_a_hr222_capture;
1197 temp.tlv.p = db_scale_analog_capture;
1199 err = snd_ctl_add(chip->card,
1200 snd_ctl_new1(&temp, chip));
1204 temp = snd_pcxhr_pcm_vol;
1205 temp.name = "PCM Capture Volume";
1207 temp.private_value = 1; /* capture */
1209 err = snd_ctl_add(chip->card,
1210 snd_ctl_new1(&temp, chip));
1215 err = snd_ctl_add(chip->card,
1216 snd_ctl_new1(&pcxhr_control_audio_src, chip));
1220 /* IEC958 controls */
1221 err = snd_ctl_add(chip->card,
1222 snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1227 err = snd_ctl_add(chip->card,
1228 snd_ctl_new1(&pcxhr_control_capture_iec958,
1233 if (mgr->is_hr_stereo) {
1234 err = hr222_add_mic_controls(chip);
1239 /* monitoring only if playback and capture device available */
1240 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1242 err = snd_ctl_add(chip->card,
1243 snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
1247 err = snd_ctl_add(chip->card,
1248 snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
1254 /* clock mode only one control per pcxhr */
1255 err = snd_ctl_add(chip->card,
1256 snd_ctl_new1(&pcxhr_control_clock_type, mgr));
1259 /* non standard control used to scan
1260 * the external clock presence/frequencies
1262 err = snd_ctl_add(chip->card,
1263 snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
1268 /* init values for the mixer data */
1269 pcxhr_init_audio_levels(chip);