vmalloc: fix __GFP_HIGHMEM usage for vmalloc_32 on 32b systems
[linux/fpc-iii.git] / sound / pci / pcxhr / pcxhr_mixer.c
blobd9a1c6c50a87d2d8a8028b14c4bc32d28bb08766
1 #define __NO_VERSION__
2 /*
3 * Driver for Digigram pcxhr compatible soundcards
5 * mixer callbacks
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>
29 #include "pcxhr.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)
55 int err, vol;
56 struct pcxhr_rmh rmh;
58 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
59 if (is_capture) {
60 rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL;
61 rmh.cmd[2] = chip->analog_capture_volume[channel];
62 } else {
63 rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL;
64 if (chip->analog_playback_active[channel])
65 vol = chip->analog_playback_volume[channel];
66 else
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 */
72 rmh.cmd_len = 3;
73 err = pcxhr_send_msg(chip->mgr, &rmh);
74 if (err < 0) {
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);
79 return -EINVAL;
81 return 0;
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;
93 uinfo->count = 2;
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 */
100 } else {
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 */
112 } else {
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 */
119 return 0;
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);
135 return 0;
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);
142 int changed = 0;
143 int is_capture, i;
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];
152 if (is_capture) {
153 if (chip->mgr->is_hr_stereo) {
154 if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN ||
155 new_volume > HR222_LINE_CAPTURE_LEVEL_MAX)
156 continue;
157 } else {
158 if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN ||
159 new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX)
160 continue;
162 } else {
163 if (chip->mgr->is_hr_stereo) {
164 if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN ||
165 new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX)
166 continue;
167 } else {
168 if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN ||
169 new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX)
170 continue;
173 if (*stored_volume != new_volume) {
174 *stored_volume = new_volume;
175 changed = 1;
176 if (chip->mgr->is_hr_stereo)
177 hr222_update_analog_audio_level(chip,
178 is_capture, i);
179 else
180 pcxhr_update_analog_audio_level(chip,
181 is_capture, i);
184 mutex_unlock(&chip->mgr->mixer_mutex);
185 return changed;
188 static const 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 */
199 /* shared */
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);
212 return 0;
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);
219 int i, changed = 0;
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];
226 changed = 1;
227 /* update playback levels */
228 if (chip->mgr->is_hr_stereo)
229 hr222_update_analog_audio_level(chip, 0, i);
230 else
231 pcxhr_update_analog_audio_level(chip, 0, i);
234 mutex_unlock(&chip->mgr->mixer_mutex);
235 return changed;
238 static const 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)
261 int err;
262 struct pcxhr_rmh rmh;
263 struct pcxhr_pipe *pipe = &chip->playback_pipe;
264 int left, right;
266 if (chip->digital_playback_active[idx][0])
267 left = chip->digital_playback_volume[idx][0];
268 else
269 left = PCXHR_DIGITAL_LEVEL_MIN;
270 if (chip->digital_playback_active[idx][1])
271 right = chip->digital_playback_volume[idx][1];
272 else
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;
283 rmh.cmd[3] |= right;
284 rmh.cmd_len = 4;
286 err = pcxhr_send_msg(chip->mgr, &rmh);
287 if (err < 0) {
288 dev_dbg(chip->card->dev, "error update_playback_stream_level "
289 "card(%d) err(%x)\n", chip->chip_idx, err);
290 return -EINVAL;
292 return 0;
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)
305 int err;
306 struct pcxhr_rmh rmh;
307 struct pcxhr_pipe *pipe;
309 if (capture)
310 pipe = &chip->capture_pipe[0];
311 else
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 */
320 if (capture) {
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];
325 } else {
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;
335 rmh.cmd_len = 3;
337 err = pcxhr_send_msg(chip->mgr, &rmh);
338 if (err < 0) {
339 dev_dbg(chip->card->dev,
340 "error update_audio_level(%d) err=%x\n",
341 chip->chip_idx, err);
342 return -EINVAL;
344 return 0;
348 /* shared */
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;
353 uinfo->count = 2;
354 uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */
355 uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */
356 return 0;
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 */
365 int *stored_volume;
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);
376 return 0;
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 */
384 int changed = 0;
385 int is_capture = kcontrol->private_value;
386 int *stored_volume;
387 int i;
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)
398 continue;
399 if (stored_volume[i] != vol) {
400 stored_volume[i] = vol;
401 changed = 1;
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);
409 return changed;
412 static const 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);
436 return 0;
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);
443 int changed = 0;
444 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
445 int i, j;
447 mutex_lock(&chip->mgr->mixer_mutex);
448 j = idx;
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];
454 changed = 1;
457 if (changed)
458 pcxhr_update_playback_stream_level(chip, idx);
459 mutex_unlock(&chip->mgr->mixer_mutex);
460 return changed;
463 static const 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);
485 return 0;
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);
492 int changed = 0;
493 int i;
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);
505 changed = 1;
508 mutex_unlock(&chip->mgr->mixer_mutex);
509 return changed;
512 static const 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);
535 return 0;
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);
542 int changed = 0;
543 int i;
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 */
554 if (changed & 0x01)
555 /* update left monitoring volume and mute */
556 pcxhr_update_audio_pipe_level(chip, 0, 0);
557 if (changed & 0x02)
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 const 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;
588 unsigned int codec;
589 int err, changed;
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 */
600 } else {
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) */
606 if (changed) {
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);
610 if (err)
611 return err;
613 if (chip->mgr->board_aes_in_192k) {
614 int i;
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);
623 rmh.cmd_len = 2;
624 rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC;
625 rmh.cmd[1] = src_config;
626 err = pcxhr_send_msg(chip->mgr, &rmh);
627 } else {
628 int use_src = 0;
629 if (chip->audio_capture_source == 2)
630 use_src = 1;
631 /* set codec SRC on off */
632 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
633 rmh.cmd_len = 3;
634 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
635 rmh.cmd[1] = codec;
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);
639 if (err)
640 return err;
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);
645 return err;
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"
654 int i;
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 return snd_ctl_enum_info(uinfo, 1, i, texts);
666 static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
669 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
670 ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
671 return 0;
674 static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
677 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
678 int ret = 0;
679 int i = 2; /* no SRC, no Mic available */
680 if (chip->mgr->board_has_aes1) {
681 i = 3; /* SRC available */
682 if (chip->mgr->board_has_mic)
683 i = 5; /* Mic and MicroMix available */
685 if (ucontrol->value.enumerated.item[0] >= i)
686 return -EINVAL;
687 mutex_lock(&chip->mgr->mixer_mutex);
688 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
689 chip->audio_capture_source = ucontrol->value.enumerated.item[0];
690 if (chip->mgr->is_hr_stereo)
691 hr222_set_audio_source(chip);
692 else
693 pcxhr_set_audio_source(chip);
694 ret = 1;
696 mutex_unlock(&chip->mgr->mixer_mutex);
697 return ret;
700 static const struct snd_kcontrol_new pcxhr_control_audio_src = {
701 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
702 .name = "Capture Source",
703 .info = pcxhr_audio_src_info,
704 .get = pcxhr_audio_src_get,
705 .put = pcxhr_audio_src_put,
710 * clock type selection
711 * enum pcxhr_clock_type {
712 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
713 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
714 * PCXHR_CLOCK_TYPE_AES_SYNC,
715 * PCXHR_CLOCK_TYPE_AES_1,
716 * PCXHR_CLOCK_TYPE_AES_2,
717 * PCXHR_CLOCK_TYPE_AES_3,
718 * PCXHR_CLOCK_TYPE_AES_4,
719 * PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
720 * HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
721 * HR22_CLOCK_TYPE_AES_SYNC,
722 * HR22_CLOCK_TYPE_AES_1,
723 * HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
724 * };
727 static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
728 struct snd_ctl_elem_info *uinfo)
730 static const char *textsPCXHR[7] = {
731 "Internal", "WordClock", "AES Sync",
732 "AES 1", "AES 2", "AES 3", "AES 4"
734 static const char *textsHR22[3] = {
735 "Internal", "AES Sync", "AES 1"
737 const char **texts;
738 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
739 int clock_items = 2; /* at least Internal and AES Sync clock */
740 if (mgr->board_has_aes1) {
741 clock_items += mgr->capture_chips; /* add AES x */
742 if (!mgr->is_hr_stereo)
743 clock_items += 1; /* add word clock */
745 if (mgr->is_hr_stereo) {
746 texts = textsHR22;
747 snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1));
748 } else {
749 texts = textsPCXHR;
750 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
752 return snd_ctl_enum_info(uinfo, 1, clock_items, texts);
755 static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
756 struct snd_ctl_elem_value *ucontrol)
758 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
759 ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
760 return 0;
763 static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_value *ucontrol)
766 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
767 int rate, ret = 0;
768 unsigned int clock_items = 2; /* at least Internal and AES Sync clock */
769 if (mgr->board_has_aes1) {
770 clock_items += mgr->capture_chips; /* add AES x */
771 if (!mgr->is_hr_stereo)
772 clock_items += 1; /* add word clock */
774 if (ucontrol->value.enumerated.item[0] >= clock_items)
775 return -EINVAL;
776 mutex_lock(&mgr->mixer_mutex);
777 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
778 mutex_lock(&mgr->setup_mutex);
779 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
780 rate = 0;
781 if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) {
782 pcxhr_get_external_clock(mgr, mgr->use_clock_type,
783 &rate);
784 } else {
785 rate = mgr->sample_rate;
786 if (!rate)
787 rate = 48000;
789 if (rate) {
790 pcxhr_set_clock(mgr, rate);
791 if (mgr->sample_rate)
792 mgr->sample_rate = rate;
794 mutex_unlock(&mgr->setup_mutex);
795 ret = 1; /* return 1 even if the set was not done. ok ? */
797 mutex_unlock(&mgr->mixer_mutex);
798 return ret;
801 static const struct snd_kcontrol_new pcxhr_control_clock_type = {
802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
803 .name = "Clock Mode",
804 .info = pcxhr_clock_type_info,
805 .get = pcxhr_clock_type_get,
806 .put = pcxhr_clock_type_put,
810 * clock rate control
811 * specific control that scans the sample rates on the external plugs
813 static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
816 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
817 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
818 uinfo->count = 3 + mgr->capture_chips;
819 uinfo->value.integer.min = 0; /* clock not present */
820 uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
821 return 0;
824 static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
827 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
828 int i, err, rate;
830 mutex_lock(&mgr->mixer_mutex);
831 for(i = 0; i < 3 + mgr->capture_chips; i++) {
832 if (i == PCXHR_CLOCK_TYPE_INTERNAL)
833 rate = mgr->sample_rate_real;
834 else {
835 err = pcxhr_get_external_clock(mgr, i, &rate);
836 if (err)
837 break;
839 ucontrol->value.integer.value[i] = rate;
841 mutex_unlock(&mgr->mixer_mutex);
842 return 0;
845 static const struct snd_kcontrol_new pcxhr_control_clock_rate = {
846 .access = SNDRV_CTL_ELEM_ACCESS_READ,
847 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
848 .name = "Clock Rates",
849 .info = pcxhr_clock_rate_info,
850 .get = pcxhr_clock_rate_get,
854 * IEC958 status bits
856 static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
857 struct snd_ctl_elem_info *uinfo)
859 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
860 uinfo->count = 1;
861 return 0;
864 static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
865 int aes_idx, unsigned char *aes_bits)
867 int i, err;
868 unsigned char temp;
869 struct pcxhr_rmh rmh;
871 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
872 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
873 switch (chip->chip_idx) {
874 /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
875 case 0: rmh.cmd[1] = CS8420_01_CS; break;
876 case 1: rmh.cmd[1] = CS8420_23_CS; break;
877 case 2: rmh.cmd[1] = CS8420_45_CS; break;
878 case 3: rmh.cmd[1] = CS8420_67_CS; break;
879 default: return -EINVAL;
881 if (chip->mgr->board_aes_in_192k) {
882 switch (aes_idx) {
883 case 0: rmh.cmd[2] = CS8416_CSB0; break;
884 case 1: rmh.cmd[2] = CS8416_CSB1; break;
885 case 2: rmh.cmd[2] = CS8416_CSB2; break;
886 case 3: rmh.cmd[2] = CS8416_CSB3; break;
887 case 4: rmh.cmd[2] = CS8416_CSB4; break;
888 default: return -EINVAL;
890 } else {
891 switch (aes_idx) {
892 /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
893 case 0: rmh.cmd[2] = CS8420_CSB0; break;
894 case 1: rmh.cmd[2] = CS8420_CSB1; break;
895 case 2: rmh.cmd[2] = CS8420_CSB2; break;
896 case 3: rmh.cmd[2] = CS8420_CSB3; break;
897 case 4: rmh.cmd[2] = CS8420_CSB4; break;
898 default: return -EINVAL;
901 /* size and code the chip id for the fpga */
902 rmh.cmd[1] &= 0x0fffff;
903 /* chip signature + map for spi read */
904 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
905 rmh.cmd_len = 3;
906 err = pcxhr_send_msg(chip->mgr, &rmh);
907 if (err)
908 return err;
910 if (chip->mgr->board_aes_in_192k) {
911 temp = (unsigned char)rmh.stat[1];
912 } else {
913 temp = 0;
914 /* reversed bit order (not with CS8416_01_CS) */
915 for (i = 0; i < 8; i++) {
916 temp <<= 1;
917 if (rmh.stat[1] & (1 << i))
918 temp |= 1;
921 dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n",
922 chip->chip_idx, aes_idx, temp);
923 *aes_bits = temp;
924 return 0;
927 static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
928 struct snd_ctl_elem_value *ucontrol)
930 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
931 unsigned char aes_bits;
932 int i, err;
934 mutex_lock(&chip->mgr->mixer_mutex);
935 for(i = 0; i < 5; i++) {
936 if (kcontrol->private_value == 0) /* playback */
937 aes_bits = chip->aes_bits[i];
938 else { /* capture */
939 if (chip->mgr->is_hr_stereo)
940 err = hr222_iec958_capture_byte(chip, i,
941 &aes_bits);
942 else
943 err = pcxhr_iec958_capture_byte(chip, i,
944 &aes_bits);
945 if (err)
946 break;
948 ucontrol->value.iec958.status[i] = aes_bits;
950 mutex_unlock(&chip->mgr->mixer_mutex);
951 return 0;
954 static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
955 struct snd_ctl_elem_value *ucontrol)
957 int i;
958 for (i = 0; i < 5; i++)
959 ucontrol->value.iec958.status[i] = 0xff;
960 return 0;
963 static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
964 int aes_idx, unsigned char aes_bits)
966 int i, err, cmd;
967 unsigned char new_bits = aes_bits;
968 unsigned char old_bits = chip->aes_bits[aes_idx];
969 struct pcxhr_rmh rmh;
971 for (i = 0; i < 8; i++) {
972 if ((old_bits & 0x01) != (new_bits & 0x01)) {
973 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
974 if (chip->chip_idx > 3)
975 /* new bit used if chip_idx>3 (PCX1222HR) */
976 cmd |= 1 << 22;
977 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
978 cmd |= (new_bits & 0x01) << 23; /* add bit value */
979 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
980 rmh.cmd[0] |= IO_NUM_REG_CUER;
981 rmh.cmd[1] = cmd;
982 rmh.cmd_len = 2;
983 dev_dbg(chip->card->dev,
984 "write iec958 AES %d byte %d bit %d (cmd %x)\n",
985 chip->chip_idx, aes_idx, i, cmd);
986 err = pcxhr_send_msg(chip->mgr, &rmh);
987 if (err)
988 return err;
990 old_bits >>= 1;
991 new_bits >>= 1;
993 chip->aes_bits[aes_idx] = aes_bits;
994 return 0;
997 static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
998 struct snd_ctl_elem_value *ucontrol)
1000 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
1001 int i, changed = 0;
1003 /* playback */
1004 mutex_lock(&chip->mgr->mixer_mutex);
1005 for (i = 0; i < 5; i++) {
1006 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
1007 if (chip->mgr->is_hr_stereo)
1008 hr222_iec958_update_byte(chip, i,
1009 ucontrol->value.iec958.status[i]);
1010 else
1011 pcxhr_iec958_update_byte(chip, i,
1012 ucontrol->value.iec958.status[i]);
1013 changed = 1;
1016 mutex_unlock(&chip->mgr->mixer_mutex);
1017 return changed;
1020 static const struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
1021 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1022 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1023 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1024 .info = pcxhr_iec958_info,
1025 .get = pcxhr_iec958_mask_get
1027 static const struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
1028 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1029 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1030 .info = pcxhr_iec958_info,
1031 .get = pcxhr_iec958_get,
1032 .put = pcxhr_iec958_put,
1033 .private_value = 0 /* playback */
1036 static const struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
1037 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1038 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1039 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
1040 .info = pcxhr_iec958_info,
1041 .get = pcxhr_iec958_mask_get
1043 static const struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
1044 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1045 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1046 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1047 .info = pcxhr_iec958_info,
1048 .get = pcxhr_iec958_get,
1049 .private_value = 1 /* capture */
1052 static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
1054 int i;
1056 for (i = 0; i < 2; i++) {
1057 if (chip->nb_streams_play) {
1058 int j;
1059 /* at boot time the digital volumes are unmuted 0dB */
1060 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
1061 chip->digital_playback_active[j][i] = 1;
1062 chip->digital_playback_volume[j][i] =
1063 PCXHR_DIGITAL_ZERO_LEVEL;
1065 /* after boot, only two bits are set on the uer
1066 * interface
1068 chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
1069 IEC958_AES0_PRO_FS_48000);
1070 #ifdef CONFIG_SND_DEBUG
1071 /* analog volumes for playback
1072 * (is LEVEL_MIN after boot)
1074 chip->analog_playback_active[i] = 1;
1075 if (chip->mgr->is_hr_stereo)
1076 chip->analog_playback_volume[i] =
1077 HR222_LINE_PLAYBACK_ZERO_LEVEL;
1078 else {
1079 chip->analog_playback_volume[i] =
1080 PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
1081 pcxhr_update_analog_audio_level(chip, 0, i);
1083 #endif
1084 /* stereo cards need to be initialised after boot */
1085 if (chip->mgr->is_hr_stereo)
1086 hr222_update_analog_audio_level(chip, 0, i);
1088 if (chip->nb_streams_capt) {
1089 /* at boot time the digital volumes are unmuted 0dB */
1090 chip->digital_capture_volume[i] =
1091 PCXHR_DIGITAL_ZERO_LEVEL;
1092 chip->analog_capture_active = 1;
1093 #ifdef CONFIG_SND_DEBUG
1094 /* analog volumes for playback
1095 * (is LEVEL_MIN after boot)
1097 if (chip->mgr->is_hr_stereo)
1098 chip->analog_capture_volume[i] =
1099 HR222_LINE_CAPTURE_ZERO_LEVEL;
1100 else {
1101 chip->analog_capture_volume[i] =
1102 PCXHR_LINE_CAPTURE_ZERO_LEVEL;
1103 pcxhr_update_analog_audio_level(chip, 1, i);
1105 #endif
1106 /* stereo cards need to be initialised after boot */
1107 if (chip->mgr->is_hr_stereo)
1108 hr222_update_analog_audio_level(chip, 1, i);
1112 return;
1116 int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
1118 struct snd_pcxhr *chip;
1119 int err, i;
1121 mutex_init(&mgr->mixer_mutex); /* can be in another place */
1123 for (i = 0; i < mgr->num_cards; i++) {
1124 struct snd_kcontrol_new temp;
1125 chip = mgr->chip[i];
1127 if (chip->nb_streams_play) {
1128 /* analog output level control */
1129 temp = pcxhr_control_analog_level;
1130 temp.name = "Master Playback Volume";
1131 temp.private_value = 0; /* playback */
1132 if (mgr->is_hr_stereo)
1133 temp.tlv.p = db_scale_a_hr222_playback;
1134 else
1135 temp.tlv.p = db_scale_analog_playback;
1136 err = snd_ctl_add(chip->card,
1137 snd_ctl_new1(&temp, chip));
1138 if (err < 0)
1139 return err;
1141 /* output mute controls */
1142 err = snd_ctl_add(chip->card,
1143 snd_ctl_new1(&pcxhr_control_output_switch,
1144 chip));
1145 if (err < 0)
1146 return err;
1148 temp = snd_pcxhr_pcm_vol;
1149 temp.name = "PCM Playback Volume";
1150 temp.count = PCXHR_PLAYBACK_STREAMS;
1151 temp.private_value = 0; /* playback */
1152 err = snd_ctl_add(chip->card,
1153 snd_ctl_new1(&temp, chip));
1154 if (err < 0)
1155 return err;
1157 err = snd_ctl_add(chip->card,
1158 snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
1159 if (err < 0)
1160 return err;
1162 /* IEC958 controls */
1163 err = snd_ctl_add(chip->card,
1164 snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
1165 chip));
1166 if (err < 0)
1167 return err;
1169 err = snd_ctl_add(chip->card,
1170 snd_ctl_new1(&pcxhr_control_playback_iec958,
1171 chip));
1172 if (err < 0)
1173 return err;
1175 if (chip->nb_streams_capt) {
1176 /* analog input level control */
1177 temp = pcxhr_control_analog_level;
1178 temp.name = "Line Capture Volume";
1179 temp.private_value = 1; /* capture */
1180 if (mgr->is_hr_stereo)
1181 temp.tlv.p = db_scale_a_hr222_capture;
1182 else
1183 temp.tlv.p = db_scale_analog_capture;
1185 err = snd_ctl_add(chip->card,
1186 snd_ctl_new1(&temp, chip));
1187 if (err < 0)
1188 return err;
1190 temp = snd_pcxhr_pcm_vol;
1191 temp.name = "PCM Capture Volume";
1192 temp.count = 1;
1193 temp.private_value = 1; /* capture */
1195 err = snd_ctl_add(chip->card,
1196 snd_ctl_new1(&temp, chip));
1197 if (err < 0)
1198 return err;
1200 /* Audio source */
1201 err = snd_ctl_add(chip->card,
1202 snd_ctl_new1(&pcxhr_control_audio_src, chip));
1203 if (err < 0)
1204 return err;
1206 /* IEC958 controls */
1207 err = snd_ctl_add(chip->card,
1208 snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1209 chip));
1210 if (err < 0)
1211 return err;
1213 err = snd_ctl_add(chip->card,
1214 snd_ctl_new1(&pcxhr_control_capture_iec958,
1215 chip));
1216 if (err < 0)
1217 return err;
1219 if (mgr->is_hr_stereo) {
1220 err = hr222_add_mic_controls(chip);
1221 if (err < 0)
1222 return err;
1225 /* monitoring only if playback and capture device available */
1226 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1227 /* monitoring */
1228 err = snd_ctl_add(chip->card,
1229 snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
1230 if (err < 0)
1231 return err;
1233 err = snd_ctl_add(chip->card,
1234 snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
1235 if (err < 0)
1236 return err;
1239 if (i == 0) {
1240 /* clock mode only one control per pcxhr */
1241 err = snd_ctl_add(chip->card,
1242 snd_ctl_new1(&pcxhr_control_clock_type, mgr));
1243 if (err < 0)
1244 return err;
1245 /* non standard control used to scan
1246 * the external clock presence/frequencies
1248 err = snd_ctl_add(chip->card,
1249 snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
1250 if (err < 0)
1251 return err;
1254 /* init values for the mixer data */
1255 pcxhr_init_audio_levels(chip);
1258 return 0;