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 <sound/driver.h>
25 #include <linux/time.h>
26 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 #include <linux/mutex.h>
29 #include <sound/core.h>
31 #include "pcxhr_hwdep.h"
32 #include "pcxhr_core.h"
33 #include <sound/control.h>
34 #include <sound/tlv.h>
35 #include <sound/asoundef.h>
36 #include "pcxhr_mixer.h"
39 #define PCXHR_ANALOG_CAPTURE_LEVEL_MIN 0 /* -96.0 dB */
40 #define PCXHR_ANALOG_CAPTURE_LEVEL_MAX 255 /* +31.5 dB */
41 #define PCXHR_ANALOG_CAPTURE_ZERO_LEVEL 224 /* +16.0 dB ( +31.5 dB - fix level +15.5 dB ) */
43 #define PCXHR_ANALOG_PLAYBACK_LEVEL_MIN 0 /* -128.0 dB */
44 #define PCXHR_ANALOG_PLAYBACK_LEVEL_MAX 128 /* 0.0 dB */
45 #define PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL 104 /* -24.0 dB ( 0.0 dB - fix level +24.0 dB ) */
47 static DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -9600, 50, 0);
48 static DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -12800, 100, 0);
50 static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_capture, int channel)
55 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
57 rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL;
58 rmh.cmd[2] = chip->analog_capture_volume[channel];
60 rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL;
61 if (chip->analog_playback_active[channel])
62 vol = chip->analog_playback_volume[channel];
64 vol = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN;
65 rmh.cmd[2] = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX - vol; /* playback analog levels are inversed */
67 rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */
69 err = pcxhr_send_msg(chip->mgr, &rmh);
71 snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d) "
72 "is_capture(%d) err(%x)\n", chip->chip_idx, is_capture, err);
79 * analog level control
81 static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_info *uinfo)
84 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
86 if (kcontrol->private_value == 0) { /* playback */
87 uinfo->value.integer.min = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN; /* -128 dB */
88 uinfo->value.integer.max = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX; /* 0 dB */
89 } else { /* capture */
90 uinfo->value.integer.min = PCXHR_ANALOG_CAPTURE_LEVEL_MIN; /* -96 dB */
91 uinfo->value.integer.max = PCXHR_ANALOG_CAPTURE_LEVEL_MAX; /* 31.5 dB */
96 static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
97 struct snd_ctl_elem_value *ucontrol)
99 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
100 mutex_lock(&chip->mgr->mixer_mutex);
101 if (kcontrol->private_value == 0) { /* playback */
102 ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
103 ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
104 } else { /* capture */
105 ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
106 ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
108 mutex_unlock(&chip->mgr->mixer_mutex);
112 static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
113 struct snd_ctl_elem_value *ucontrol)
115 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
119 mutex_lock(&chip->mgr->mixer_mutex);
120 is_capture = (kcontrol->private_value != 0);
121 for (i = 0; i < 2; i++) {
122 int new_volume = ucontrol->value.integer.value[i];
123 int* stored_volume = is_capture ? &chip->analog_capture_volume[i] :
124 &chip->analog_playback_volume[i];
125 if (*stored_volume != new_volume) {
126 *stored_volume = new_volume;
128 pcxhr_update_analog_audio_level(chip, is_capture, i);
131 mutex_unlock(&chip->mgr->mixer_mutex);
135 static struct snd_kcontrol_new pcxhr_control_analog_level = {
136 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
137 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
138 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
139 /* name will be filled later */
140 .info = pcxhr_analog_vol_info,
141 .get = pcxhr_analog_vol_get,
142 .put = pcxhr_analog_vol_put,
143 /* tlv will be filled later */
147 static int pcxhr_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
149 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
151 uinfo->value.integer.min = 0;
152 uinfo->value.integer.max = 1;
156 static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
157 struct snd_ctl_elem_value *ucontrol)
159 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
161 mutex_lock(&chip->mgr->mixer_mutex);
162 ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
163 ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
164 mutex_unlock(&chip->mgr->mixer_mutex);
168 static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
169 struct snd_ctl_elem_value *ucontrol)
171 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
173 mutex_lock(&chip->mgr->mixer_mutex);
174 for(i = 0; i < 2; i++) {
175 if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) {
176 chip->analog_playback_active[i] = ucontrol->value.integer.value[i];
178 pcxhr_update_analog_audio_level(chip, 0, i); /* update playback levels */
181 mutex_unlock(&chip->mgr->mixer_mutex);
185 static struct snd_kcontrol_new pcxhr_control_output_switch = {
186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
187 .name = "Master Playback Switch",
188 .info = pcxhr_sw_info, /* shared */
189 .get = pcxhr_audio_sw_get,
190 .put = pcxhr_audio_sw_put
194 #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */
195 #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */
196 #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */
198 static DECLARE_TLV_DB_SCALE(db_scale_digital, -10950, 50, 0);
200 #define MORE_THAN_ONE_STREAM_LEVEL 0x000001
201 #define VALID_STREAM_PAN_LEVEL_MASK 0x800000
202 #define VALID_STREAM_LEVEL_MASK 0x400000
203 #define VALID_STREAM_LEVEL_1_MASK 0x200000
204 #define VALID_STREAM_LEVEL_2_MASK 0x100000
206 static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
209 struct pcxhr_rmh rmh;
210 struct pcxhr_pipe *pipe = &chip->playback_pipe;
213 if (chip->digital_playback_active[idx][0])
214 left = chip->digital_playback_volume[idx][0];
216 left = PCXHR_DIGITAL_LEVEL_MIN;
217 if (chip->digital_playback_active[idx][1])
218 right = chip->digital_playback_volume[idx][1];
220 right = PCXHR_DIGITAL_LEVEL_MIN;
222 pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST);
223 /* add pipe and stream mask */
224 pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx);
225 /* volume left->left / right->right panoramic level */
226 rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL;
227 rmh.cmd[2] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK;
228 rmh.cmd[2] |= (left << 10);
229 rmh.cmd[3] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK;
233 err = pcxhr_send_msg(chip->mgr, &rmh);
235 snd_printk(KERN_DEBUG "error update_playback_stream_level "
236 "card(%d) err(%x)\n", chip->chip_idx, err);
242 #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
243 #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000
244 #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001
245 #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002
246 #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
247 #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
249 static int pcxhr_update_audio_pipe_level(struct snd_pcxhr* chip, int capture, int channel)
252 struct pcxhr_rmh rmh;
253 struct pcxhr_pipe *pipe;
256 pipe = &chip->capture_pipe[0];
258 pipe = &chip->playback_pipe;
260 pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
261 /* add channel mask */
262 pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0, 1 << (channel + pipe->first_audio));
263 /* TODO : if mask (3 << pipe->first_audio) is used, left and right channel
264 * will be programmed to the same params
267 rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
268 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled (capture pipe level) */
269 rmh.cmd[2] = chip->digital_capture_volume[channel];
271 rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL | VALID_AUDIO_IO_MUTE_MONITOR_1;
272 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL not yet
273 * handled (playback pipe level)
275 rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
276 if (chip->monitoring_active[channel] == 0)
277 rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1;
281 err = pcxhr_send_msg(chip->mgr, &rmh);
283 snd_printk(KERN_DEBUG "error update_audio_level card(%d) err(%x)\n",
284 chip->chip_idx, err);
292 static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_info *uinfo)
295 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
297 uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */
298 uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */
303 static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_value *ucontrol)
306 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
307 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
309 int is_capture = kcontrol->private_value;
311 mutex_lock(&chip->mgr->mixer_mutex);
313 stored_volume = chip->digital_capture_volume; /* digital capture */
315 stored_volume = chip->digital_playback_volume[idx]; /* digital playback */
316 ucontrol->value.integer.value[0] = stored_volume[0];
317 ucontrol->value.integer.value[1] = stored_volume[1];
318 mutex_unlock(&chip->mgr->mixer_mutex);
322 static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol)
325 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
326 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
328 int is_capture = kcontrol->private_value;
332 mutex_lock(&chip->mgr->mixer_mutex);
334 stored_volume = chip->digital_capture_volume; /* digital capture */
336 stored_volume = chip->digital_playback_volume[idx]; /* digital playback */
337 for (i = 0; i < 2; i++) {
338 if (stored_volume[i] != ucontrol->value.integer.value[i]) {
339 stored_volume[i] = ucontrol->value.integer.value[i];
341 if (is_capture) /* update capture volume */
342 pcxhr_update_audio_pipe_level(chip, 1, i);
345 if (! is_capture && changed)
346 pcxhr_update_playback_stream_level(chip, idx); /* update playback volume */
347 mutex_unlock(&chip->mgr->mixer_mutex);
351 static struct snd_kcontrol_new snd_pcxhr_pcm_vol =
353 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
354 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
355 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
356 /* name will be filled later */
357 /* count will be filled later */
358 .info = pcxhr_digital_vol_info, /* shared */
359 .get = pcxhr_pcm_vol_get,
360 .put = pcxhr_pcm_vol_put,
361 .tlv = { .p = db_scale_digital },
365 static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_value *ucontrol)
368 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
369 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
371 mutex_lock(&chip->mgr->mixer_mutex);
372 ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
373 ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
374 mutex_unlock(&chip->mgr->mixer_mutex);
378 static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
380 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
382 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
385 mutex_lock(&chip->mgr->mixer_mutex);
387 for (i = 0; i < 2; i++) {
388 if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) {
389 chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i];
394 pcxhr_update_playback_stream_level(chip, idx);
395 mutex_unlock(&chip->mgr->mixer_mutex);
399 static struct snd_kcontrol_new pcxhr_control_pcm_switch = {
400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
401 .name = "PCM Playback Switch",
402 .count = PCXHR_PLAYBACK_STREAMS,
403 .info = pcxhr_sw_info, /* shared */
404 .get = pcxhr_pcm_sw_get,
405 .put = pcxhr_pcm_sw_put
410 * monitoring level control
413 static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
414 struct snd_ctl_elem_value *ucontrol)
416 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
417 mutex_lock(&chip->mgr->mixer_mutex);
418 ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
419 ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
420 mutex_unlock(&chip->mgr->mixer_mutex);
424 static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_value *ucontrol)
427 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
431 mutex_lock(&chip->mgr->mixer_mutex);
432 for (i = 0; i < 2; i++) {
433 if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) {
434 chip->monitoring_volume[i] = ucontrol->value.integer.value[i];
435 if(chip->monitoring_active[i]) /* do only when monitoring is unmuted */
436 /* update monitoring volume and mute */
437 pcxhr_update_audio_pipe_level(chip, 0, i);
441 mutex_unlock(&chip->mgr->mixer_mutex);
445 static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
446 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
447 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
448 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
449 .name = "Monitoring Volume",
450 .info = pcxhr_digital_vol_info, /* shared */
451 .get = pcxhr_monitor_vol_get,
452 .put = pcxhr_monitor_vol_put,
453 .tlv = { .p = db_scale_digital },
457 * monitoring switch control
460 static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
464 mutex_lock(&chip->mgr->mixer_mutex);
465 ucontrol->value.integer.value[0] = chip->monitoring_active[0];
466 ucontrol->value.integer.value[1] = chip->monitoring_active[1];
467 mutex_unlock(&chip->mgr->mixer_mutex);
471 static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
472 struct snd_ctl_elem_value *ucontrol)
474 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
478 mutex_lock(&chip->mgr->mixer_mutex);
479 for (i = 0; i < 2; i++) {
480 if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) {
481 chip->monitoring_active[i] = ucontrol->value.integer.value[i];
482 changed |= (1<<i); /* mask 0x01 and 0x02 */
486 /* update left monitoring volume and mute */
487 pcxhr_update_audio_pipe_level(chip, 0, 0);
489 /* update right monitoring volume and mute */
490 pcxhr_update_audio_pipe_level(chip, 0, 1);
492 mutex_unlock(&chip->mgr->mixer_mutex);
493 return (changed != 0);
496 static struct snd_kcontrol_new pcxhr_control_monitor_sw = {
497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
498 .name = "Monitoring Switch",
499 .info = pcxhr_sw_info, /* shared */
500 .get = pcxhr_monitor_sw_get,
501 .put = pcxhr_monitor_sw_put
507 * audio source select
509 #define PCXHR_SOURCE_AUDIO01_UER 0x000100
510 #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200
511 #define PCXHR_SOURCE_AUDIO23_UER 0x000400
512 #define PCXHR_SOURCE_AUDIO45_UER 0x001000
513 #define PCXHR_SOURCE_AUDIO67_UER 0x040000
515 static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
517 struct pcxhr_rmh rmh;
518 unsigned int mask, reg;
520 int err, use_src, changed;
522 switch (chip->chip_idx) {
523 case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
524 case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break;
525 case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break;
526 case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
527 default: return -EINVAL;
529 reg = 0; /* audio source from analog plug */
530 use_src = 0; /* do not activate codec SRC */
532 if (chip->audio_capture_source != 0) {
533 reg = mask; /* audio source from digital plug */
534 if (chip->audio_capture_source == 2)
537 /* set the input source */
538 pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
539 /* resync them (otherwise channel inversion possible) */
541 pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS);
542 rmh.cmd[0] |= (1 << chip->chip_idx);
543 err = pcxhr_send_msg(chip->mgr, &rmh);
547 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* set codec SRC on off */
549 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
551 rmh.cmd[2] = (CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x54);
552 err = pcxhr_send_msg(chip->mgr, &rmh);
555 rmh.cmd[2] = (CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x49);
556 err = pcxhr_send_msg(chip->mgr, &rmh);
560 static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_info *uinfo)
563 static char *texts[3] = {"Analog", "Digital", "Digi+SRC"};
565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
567 uinfo->value.enumerated.items = 3;
568 if (uinfo->value.enumerated.item > 2)
569 uinfo->value.enumerated.item = 2;
570 strcpy(uinfo->value.enumerated.name,
571 texts[uinfo->value.enumerated.item]);
575 static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_value *ucontrol)
578 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
579 ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
583 static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_value *ucontrol)
586 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
589 mutex_lock(&chip->mgr->mixer_mutex);
590 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
591 chip->audio_capture_source = ucontrol->value.enumerated.item[0];
592 pcxhr_set_audio_source(chip);
595 mutex_unlock(&chip->mgr->mixer_mutex);
599 static struct snd_kcontrol_new pcxhr_control_audio_src = {
600 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
601 .name = "Capture Source",
602 .info = pcxhr_audio_src_info,
603 .get = pcxhr_audio_src_get,
604 .put = pcxhr_audio_src_put,
609 * clock type selection
610 * enum pcxhr_clock_type {
611 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
612 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
613 * PCXHR_CLOCK_TYPE_AES_SYNC,
614 * PCXHR_CLOCK_TYPE_AES_1,
615 * PCXHR_CLOCK_TYPE_AES_2,
616 * PCXHR_CLOCK_TYPE_AES_3,
617 * PCXHR_CLOCK_TYPE_AES_4,
621 static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_info *uinfo)
624 static char *texts[7] = {
625 "Internal", "WordClock", "AES Sync", "AES 1", "AES 2", "AES 3", "AES 4"
627 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
628 int clock_items = 3 + mgr->capture_chips;
630 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
632 uinfo->value.enumerated.items = clock_items;
633 if (uinfo->value.enumerated.item >= clock_items)
634 uinfo->value.enumerated.item = clock_items-1;
635 strcpy(uinfo->value.enumerated.name,
636 texts[uinfo->value.enumerated.item]);
640 static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
643 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
644 ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
648 static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
651 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
654 mutex_lock(&mgr->mixer_mutex);
655 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
656 mutex_lock(&mgr->setup_mutex);
657 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
658 if (mgr->use_clock_type)
659 pcxhr_get_external_clock(mgr, mgr->use_clock_type, &rate);
661 rate = mgr->sample_rate;
663 pcxhr_set_clock(mgr, rate);
664 if (mgr->sample_rate)
665 mgr->sample_rate = rate;
667 mutex_unlock(&mgr->setup_mutex);
668 ret = 1; /* return 1 even if the set was not done. ok ? */
670 mutex_unlock(&mgr->mixer_mutex);
674 static struct snd_kcontrol_new pcxhr_control_clock_type = {
675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
676 .name = "Clock Mode",
677 .info = pcxhr_clock_type_info,
678 .get = pcxhr_clock_type_get,
679 .put = pcxhr_clock_type_put,
684 * specific control that scans the sample rates on the external plugs
686 static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_info *uinfo)
689 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
690 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
691 uinfo->count = 3 + mgr->capture_chips;
692 uinfo->value.integer.min = 0; /* clock not present */
693 uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
697 static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
698 struct snd_ctl_elem_value *ucontrol)
700 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
703 mutex_lock(&mgr->mixer_mutex);
704 for(i = 0; i < 3 + mgr->capture_chips; i++) {
705 if (i == PCXHR_CLOCK_TYPE_INTERNAL)
706 rate = mgr->sample_rate_real;
708 err = pcxhr_get_external_clock(mgr, i, &rate);
712 ucontrol->value.integer.value[i] = rate;
714 mutex_unlock(&mgr->mixer_mutex);
718 static struct snd_kcontrol_new pcxhr_control_clock_rate = {
719 .access = SNDRV_CTL_ELEM_ACCESS_READ,
720 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
721 .name = "Clock Rates",
722 .info = pcxhr_clock_rate_info,
723 .get = pcxhr_clock_rate_get,
729 static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
731 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
736 static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char* aes_bits)
740 struct pcxhr_rmh rmh;
742 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
743 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
744 switch (chip->chip_idx) {
745 case 0: rmh.cmd[1] = CS8420_01_CS; break; /* use CS8416_01_CS for AES SYNC plug */
746 case 1: rmh.cmd[1] = CS8420_23_CS; break;
747 case 2: rmh.cmd[1] = CS8420_45_CS; break;
748 case 3: rmh.cmd[1] = CS8420_67_CS; break;
749 default: return -EINVAL;
752 case 0: rmh.cmd[2] = CS8420_CSB0; break; /* use CS8416_CSBx for AES SYNC plug */
753 case 1: rmh.cmd[2] = CS8420_CSB1; break;
754 case 2: rmh.cmd[2] = CS8420_CSB2; break;
755 case 3: rmh.cmd[2] = CS8420_CSB3; break;
756 case 4: rmh.cmd[2] = CS8420_CSB4; break;
757 default: return -EINVAL;
759 rmh.cmd[1] &= 0x0fffff; /* size and code the chip id for the fpga */
760 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI; /* chip signature + map for spi read */
762 err = pcxhr_send_msg(chip->mgr, &rmh);
766 for (i = 0; i < 8; i++) {
767 /* attention : reversed bit order (not with CS8416_01_CS) */
769 if (rmh.stat[1] & (1 << i))
772 snd_printdd("read iec958 AES %d byte %d = 0x%x\n", chip->chip_idx, aes_idx, temp);
777 static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
779 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
780 unsigned char aes_bits;
783 mutex_lock(&chip->mgr->mixer_mutex);
784 for(i = 0; i < 5; i++) {
785 if (kcontrol->private_value == 0) /* playback */
786 aes_bits = chip->aes_bits[i];
788 err = pcxhr_iec958_capture_byte(chip, i, &aes_bits);
792 ucontrol->value.iec958.status[i] = aes_bits;
794 mutex_unlock(&chip->mgr->mixer_mutex);
798 static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_value *ucontrol)
802 for (i = 0; i < 5; i++)
803 ucontrol->value.iec958.status[i] = 0xff;
807 static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char aes_bits)
810 unsigned char new_bits = aes_bits;
811 unsigned char old_bits = chip->aes_bits[aes_idx];
812 struct pcxhr_rmh rmh;
814 for (i = 0; i < 8; i++) {
815 if ((old_bits & 0x01) != (new_bits & 0x01)) {
816 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
817 if(chip->chip_idx > 3)
818 /* new bit used if chip_idx>3 (PCX1222HR) */
820 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
821 cmd |= (new_bits & 0x01) << 23; /* add bit value */
822 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
823 rmh.cmd[0] |= IO_NUM_REG_CUER;
826 snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n",
827 chip->chip_idx, aes_idx, i, cmd);
828 err = pcxhr_send_msg(chip->mgr, &rmh);
835 chip->aes_bits[aes_idx] = aes_bits;
839 static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
840 struct snd_ctl_elem_value *ucontrol)
842 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
846 mutex_lock(&chip->mgr->mixer_mutex);
847 for (i = 0; i < 5; i++) {
848 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
849 pcxhr_iec958_update_byte(chip, i, ucontrol->value.iec958.status[i]);
853 mutex_unlock(&chip->mgr->mixer_mutex);
857 static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
858 .access = SNDRV_CTL_ELEM_ACCESS_READ,
859 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
860 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
861 .info = pcxhr_iec958_info,
862 .get = pcxhr_iec958_mask_get
864 static struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
865 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
866 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
867 .info = pcxhr_iec958_info,
868 .get = pcxhr_iec958_get,
869 .put = pcxhr_iec958_put,
870 .private_value = 0 /* playback */
873 static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
874 .access = SNDRV_CTL_ELEM_ACCESS_READ,
875 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
876 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
877 .info = pcxhr_iec958_info,
878 .get = pcxhr_iec958_mask_get
880 static struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
881 .access = SNDRV_CTL_ELEM_ACCESS_READ,
882 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
883 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
884 .info = pcxhr_iec958_info,
885 .get = pcxhr_iec958_get,
886 .private_value = 1 /* capture */
889 static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
893 for (i = 0; i < 2; i++) {
894 if (chip->nb_streams_play) {
896 /* at boot time the digital volumes are unmuted 0dB */
897 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
898 chip->digital_playback_active[j][i] = 1;
899 chip->digital_playback_volume[j][i] = PCXHR_DIGITAL_ZERO_LEVEL;
901 /* after boot, only two bits are set on the uer interface */
902 chip->aes_bits[0] = IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_FS_48000;
903 /* only for test purpose, remove later */
904 #ifdef CONFIG_SND_DEBUG
905 /* analog volumes for playback (is LEVEL_MIN after boot) */
906 chip->analog_playback_active[i] = 1;
907 chip->analog_playback_volume[i] = PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL;
908 pcxhr_update_analog_audio_level(chip, 0, i);
912 if (chip->nb_streams_capt) {
913 /* at boot time the digital volumes are unmuted 0dB */
914 chip->digital_capture_volume[i] = PCXHR_DIGITAL_ZERO_LEVEL;
915 /* only for test purpose, remove later */
916 #ifdef CONFIG_SND_DEBUG
917 /* analog volumes for playback (is LEVEL_MIN after boot) */
918 chip->analog_capture_volume[i] = PCXHR_ANALOG_CAPTURE_ZERO_LEVEL;
919 pcxhr_update_analog_audio_level(chip, 1, i);
929 int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
931 struct snd_pcxhr *chip;
934 mutex_init(&mgr->mixer_mutex); /* can be in another place */
936 for (i = 0; i < mgr->num_cards; i++) {
937 struct snd_kcontrol_new temp;
940 if (chip->nb_streams_play) {
941 /* analog output level control */
942 temp = pcxhr_control_analog_level;
943 temp.name = "Master Playback Volume";
944 temp.private_value = 0; /* playback */
945 temp.tlv.p = db_scale_analog_playback;
946 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
948 /* output mute controls */
949 if ((err = snd_ctl_add(chip->card,
950 snd_ctl_new1(&pcxhr_control_output_switch,
954 temp = snd_pcxhr_pcm_vol;
955 temp.name = "PCM Playback Volume";
956 temp.count = PCXHR_PLAYBACK_STREAMS;
957 temp.private_value = 0; /* playback */
958 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
961 if ((err = snd_ctl_add(chip->card,
962 snd_ctl_new1(&pcxhr_control_pcm_switch,
966 /* IEC958 controls */
967 if ((err = snd_ctl_add(chip->card,
968 snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
971 if ((err = snd_ctl_add(chip->card,
972 snd_ctl_new1(&pcxhr_control_playback_iec958,
976 if (chip->nb_streams_capt) {
977 /* analog input level control only on first two chips !*/
978 temp = pcxhr_control_analog_level;
979 temp.name = "Master Capture Volume";
980 temp.private_value = 1; /* capture */
981 temp.tlv.p = db_scale_analog_capture;
982 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
985 temp = snd_pcxhr_pcm_vol;
986 temp.name = "PCM Capture Volume";
988 temp.private_value = 1; /* capture */
989 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
992 if ((err = snd_ctl_add(chip->card,
993 snd_ctl_new1(&pcxhr_control_audio_src,
996 /* IEC958 controls */
997 if ((err = snd_ctl_add(chip->card,
998 snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1001 if ((err = snd_ctl_add(chip->card,
1002 snd_ctl_new1(&pcxhr_control_capture_iec958,
1006 /* monitoring only if playback and capture device available */
1007 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1009 if ((err = snd_ctl_add(chip->card,
1010 snd_ctl_new1(&pcxhr_control_monitor_vol,
1013 if ((err = snd_ctl_add(chip->card,
1014 snd_ctl_new1(&pcxhr_control_monitor_sw,
1020 /* clock mode only one control per pcxhr */
1021 if ((err = snd_ctl_add(chip->card,
1022 snd_ctl_new1(&pcxhr_control_clock_type,
1025 /* non standard control used to scan the external clock presence/frequencies */
1026 if ((err = snd_ctl_add(chip->card,
1027 snd_ctl_new1(&pcxhr_control_clock_rate,
1032 /* init values for the mixer data */
1033 pcxhr_init_audio_levels(chip);