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/asoundef.h>
35 #include "pcxhr_mixer.h"
38 #define PCXHR_ANALOG_CAPTURE_LEVEL_MIN 0 /* -96.0 dB */
39 #define PCXHR_ANALOG_CAPTURE_LEVEL_MAX 255 /* +31.5 dB */
40 #define PCXHR_ANALOG_CAPTURE_ZERO_LEVEL 224 /* +16.0 dB ( +31.5 dB - fix level +15.5 dB ) */
42 #define PCXHR_ANALOG_PLAYBACK_LEVEL_MIN 0 /* -128.0 dB */
43 #define PCXHR_ANALOG_PLAYBACK_LEVEL_MAX 128 /* 0.0 dB */
44 #define PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL 104 /* -24.0 dB ( 0.0 dB - fix level +24.0 dB ) */
46 static int pcxhr_update_analog_audio_level(struct snd_pcxhr
*chip
, int is_capture
, int channel
)
51 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_WRITE
);
53 rmh
.cmd
[0] |= IO_NUM_REG_IN_ANA_LEVEL
;
54 rmh
.cmd
[2] = chip
->analog_capture_volume
[channel
];
56 rmh
.cmd
[0] |= IO_NUM_REG_OUT_ANA_LEVEL
;
57 if (chip
->analog_playback_active
[channel
])
58 vol
= chip
->analog_playback_volume
[channel
];
60 vol
= PCXHR_ANALOG_PLAYBACK_LEVEL_MIN
;
61 rmh
.cmd
[2] = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX
- vol
; /* playback analog levels are inversed */
63 rmh
.cmd
[1] = 1 << ((2 * chip
->chip_idx
) + channel
); /* audio mask */
65 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
67 snd_printk(KERN_DEBUG
"error update_analog_audio_level card(%d) "
68 "is_capture(%d) err(%x)\n", chip
->chip_idx
, is_capture
, err
);
75 * analog level control
77 static int pcxhr_analog_vol_info(struct snd_kcontrol
*kcontrol
,
78 struct snd_ctl_elem_info
*uinfo
)
80 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
82 if (kcontrol
->private_value
== 0) { /* playback */
83 uinfo
->value
.integer
.min
= PCXHR_ANALOG_PLAYBACK_LEVEL_MIN
; /* -128 dB */
84 uinfo
->value
.integer
.max
= PCXHR_ANALOG_PLAYBACK_LEVEL_MAX
; /* 0 dB */
85 } else { /* capture */
86 uinfo
->value
.integer
.min
= PCXHR_ANALOG_CAPTURE_LEVEL_MIN
; /* -96 dB */
87 uinfo
->value
.integer
.max
= PCXHR_ANALOG_CAPTURE_LEVEL_MAX
; /* 31.5 dB */
92 static int pcxhr_analog_vol_get(struct snd_kcontrol
*kcontrol
,
93 struct snd_ctl_elem_value
*ucontrol
)
95 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
96 mutex_lock(&chip
->mgr
->mixer_mutex
);
97 if (kcontrol
->private_value
== 0) { /* playback */
98 ucontrol
->value
.integer
.value
[0] = chip
->analog_playback_volume
[0];
99 ucontrol
->value
.integer
.value
[1] = chip
->analog_playback_volume
[1];
100 } else { /* capture */
101 ucontrol
->value
.integer
.value
[0] = chip
->analog_capture_volume
[0];
102 ucontrol
->value
.integer
.value
[1] = chip
->analog_capture_volume
[1];
104 mutex_unlock(&chip
->mgr
->mixer_mutex
);
108 static int pcxhr_analog_vol_put(struct snd_kcontrol
*kcontrol
,
109 struct snd_ctl_elem_value
*ucontrol
)
111 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
115 mutex_lock(&chip
->mgr
->mixer_mutex
);
116 is_capture
= (kcontrol
->private_value
!= 0);
117 for (i
= 0; i
< 2; i
++) {
118 int new_volume
= ucontrol
->value
.integer
.value
[i
];
119 int* stored_volume
= is_capture
? &chip
->analog_capture_volume
[i
] :
120 &chip
->analog_playback_volume
[i
];
121 if (*stored_volume
!= new_volume
) {
122 *stored_volume
= new_volume
;
124 pcxhr_update_analog_audio_level(chip
, is_capture
, i
);
127 mutex_unlock(&chip
->mgr
->mixer_mutex
);
131 static struct snd_kcontrol_new pcxhr_control_analog_level
= {
132 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
133 /* name will be filled later */
134 .info
= pcxhr_analog_vol_info
,
135 .get
= pcxhr_analog_vol_get
,
136 .put
= pcxhr_analog_vol_put
,
140 static int pcxhr_sw_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
142 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
144 uinfo
->value
.integer
.min
= 0;
145 uinfo
->value
.integer
.max
= 1;
149 static int pcxhr_audio_sw_get(struct snd_kcontrol
*kcontrol
,
150 struct snd_ctl_elem_value
*ucontrol
)
152 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
154 mutex_lock(&chip
->mgr
->mixer_mutex
);
155 ucontrol
->value
.integer
.value
[0] = chip
->analog_playback_active
[0];
156 ucontrol
->value
.integer
.value
[1] = chip
->analog_playback_active
[1];
157 mutex_unlock(&chip
->mgr
->mixer_mutex
);
161 static int pcxhr_audio_sw_put(struct snd_kcontrol
*kcontrol
,
162 struct snd_ctl_elem_value
*ucontrol
)
164 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
166 mutex_lock(&chip
->mgr
->mixer_mutex
);
167 for(i
= 0; i
< 2; i
++) {
168 if (chip
->analog_playback_active
[i
] != ucontrol
->value
.integer
.value
[i
]) {
169 chip
->analog_playback_active
[i
] = ucontrol
->value
.integer
.value
[i
];
171 pcxhr_update_analog_audio_level(chip
, 0, i
); /* update playback levels */
174 mutex_unlock(&chip
->mgr
->mixer_mutex
);
178 static struct snd_kcontrol_new pcxhr_control_output_switch
= {
179 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
180 .name
= "Master Playback Switch",
181 .info
= pcxhr_sw_info
, /* shared */
182 .get
= pcxhr_audio_sw_get
,
183 .put
= pcxhr_audio_sw_put
187 #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */
188 #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */
189 #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */
192 #define MORE_THAN_ONE_STREAM_LEVEL 0x000001
193 #define VALID_STREAM_PAN_LEVEL_MASK 0x800000
194 #define VALID_STREAM_LEVEL_MASK 0x400000
195 #define VALID_STREAM_LEVEL_1_MASK 0x200000
196 #define VALID_STREAM_LEVEL_2_MASK 0x100000
198 static int pcxhr_update_playback_stream_level(struct snd_pcxhr
* chip
, int idx
)
201 struct pcxhr_rmh rmh
;
202 struct pcxhr_pipe
*pipe
= &chip
->playback_pipe
;
205 if (chip
->digital_playback_active
[idx
][0])
206 left
= chip
->digital_playback_volume
[idx
][0];
208 left
= PCXHR_DIGITAL_LEVEL_MIN
;
209 if (chip
->digital_playback_active
[idx
][1])
210 right
= chip
->digital_playback_volume
[idx
][1];
212 right
= PCXHR_DIGITAL_LEVEL_MIN
;
214 pcxhr_init_rmh(&rmh
, CMD_STREAM_OUT_LEVEL_ADJUST
);
215 /* add pipe and stream mask */
216 pcxhr_set_pipe_cmd_params(&rmh
, 0, pipe
->first_audio
, 0, 1<<idx
);
217 /* volume left->left / right->right panoramic level */
218 rmh
.cmd
[0] |= MORE_THAN_ONE_STREAM_LEVEL
;
219 rmh
.cmd
[2] = VALID_STREAM_PAN_LEVEL_MASK
| VALID_STREAM_LEVEL_1_MASK
;
220 rmh
.cmd
[2] |= (left
<< 10);
221 rmh
.cmd
[3] = VALID_STREAM_PAN_LEVEL_MASK
| VALID_STREAM_LEVEL_2_MASK
;
225 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
227 snd_printk(KERN_DEBUG
"error update_playback_stream_level "
228 "card(%d) err(%x)\n", chip
->chip_idx
, err
);
234 #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
235 #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000
236 #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001
237 #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002
238 #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
239 #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
241 static int pcxhr_update_audio_pipe_level(struct snd_pcxhr
* chip
, int capture
, int channel
)
244 struct pcxhr_rmh rmh
;
245 struct pcxhr_pipe
*pipe
;
248 pipe
= &chip
->capture_pipe
[0];
250 pipe
= &chip
->playback_pipe
;
252 pcxhr_init_rmh(&rmh
, CMD_AUDIO_LEVEL_ADJUST
);
253 /* add channel mask */
254 pcxhr_set_pipe_cmd_params(&rmh
, capture
, 0, 0, 1 << (channel
+ pipe
->first_audio
));
255 /* TODO : if mask (3 << pipe->first_audio) is used, left and right channel
256 * will be programmed to the same params
259 rmh
.cmd
[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL
;
260 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled (capture pipe level) */
261 rmh
.cmd
[2] = chip
->digital_capture_volume
[channel
];
263 rmh
.cmd
[0] |= VALID_AUDIO_IO_MONITOR_LEVEL
| VALID_AUDIO_IO_MUTE_MONITOR_1
;
264 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL not yet
265 * handled (playback pipe level)
267 rmh
.cmd
[2] = chip
->monitoring_volume
[channel
] << 10;
268 if (chip
->monitoring_active
[channel
] == 0)
269 rmh
.cmd
[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1
;
273 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
275 snd_printk(KERN_DEBUG
"error update_audio_level card(%d) err(%x)\n",
276 chip
->chip_idx
, err
);
284 static int pcxhr_digital_vol_info(struct snd_kcontrol
*kcontrol
,
285 struct snd_ctl_elem_info
*uinfo
)
287 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
289 uinfo
->value
.integer
.min
= PCXHR_DIGITAL_LEVEL_MIN
; /* -109.5 dB */
290 uinfo
->value
.integer
.max
= PCXHR_DIGITAL_LEVEL_MAX
; /* 18.0 dB */
295 static int pcxhr_pcm_vol_get(struct snd_kcontrol
*kcontrol
,
296 struct snd_ctl_elem_value
*ucontrol
)
298 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
299 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
); /* index */
301 int is_capture
= kcontrol
->private_value
;
303 mutex_lock(&chip
->mgr
->mixer_mutex
);
305 stored_volume
= chip
->digital_capture_volume
; /* digital capture */
307 stored_volume
= chip
->digital_playback_volume
[idx
]; /* digital playback */
308 ucontrol
->value
.integer
.value
[0] = stored_volume
[0];
309 ucontrol
->value
.integer
.value
[1] = stored_volume
[1];
310 mutex_unlock(&chip
->mgr
->mixer_mutex
);
314 static int pcxhr_pcm_vol_put(struct snd_kcontrol
*kcontrol
,
315 struct snd_ctl_elem_value
*ucontrol
)
317 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
318 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
); /* index */
320 int is_capture
= kcontrol
->private_value
;
324 mutex_lock(&chip
->mgr
->mixer_mutex
);
326 stored_volume
= chip
->digital_capture_volume
; /* digital capture */
328 stored_volume
= chip
->digital_playback_volume
[idx
]; /* digital playback */
329 for (i
= 0; i
< 2; i
++) {
330 if (stored_volume
[i
] != ucontrol
->value
.integer
.value
[i
]) {
331 stored_volume
[i
] = ucontrol
->value
.integer
.value
[i
];
333 if (is_capture
) /* update capture volume */
334 pcxhr_update_audio_pipe_level(chip
, 1, i
);
337 if (! is_capture
&& changed
)
338 pcxhr_update_playback_stream_level(chip
, idx
); /* update playback volume */
339 mutex_unlock(&chip
->mgr
->mixer_mutex
);
343 static struct snd_kcontrol_new snd_pcxhr_pcm_vol
=
345 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
346 /* name will be filled later */
347 /* count will be filled later */
348 .info
= pcxhr_digital_vol_info
, /* shared */
349 .get
= pcxhr_pcm_vol_get
,
350 .put
= pcxhr_pcm_vol_put
,
354 static int pcxhr_pcm_sw_get(struct snd_kcontrol
*kcontrol
,
355 struct snd_ctl_elem_value
*ucontrol
)
357 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
358 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
); /* index */
360 mutex_lock(&chip
->mgr
->mixer_mutex
);
361 ucontrol
->value
.integer
.value
[0] = chip
->digital_playback_active
[idx
][0];
362 ucontrol
->value
.integer
.value
[1] = chip
->digital_playback_active
[idx
][1];
363 mutex_unlock(&chip
->mgr
->mixer_mutex
);
367 static int pcxhr_pcm_sw_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
369 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
371 int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
); /* index */
374 mutex_lock(&chip
->mgr
->mixer_mutex
);
376 for (i
= 0; i
< 2; i
++) {
377 if (chip
->digital_playback_active
[j
][i
] != ucontrol
->value
.integer
.value
[i
]) {
378 chip
->digital_playback_active
[j
][i
] = ucontrol
->value
.integer
.value
[i
];
383 pcxhr_update_playback_stream_level(chip
, idx
);
384 mutex_unlock(&chip
->mgr
->mixer_mutex
);
388 static struct snd_kcontrol_new pcxhr_control_pcm_switch
= {
389 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
390 .name
= "PCM Playback Switch",
391 .count
= PCXHR_PLAYBACK_STREAMS
,
392 .info
= pcxhr_sw_info
, /* shared */
393 .get
= pcxhr_pcm_sw_get
,
394 .put
= pcxhr_pcm_sw_put
399 * monitoring level control
402 static int pcxhr_monitor_vol_get(struct snd_kcontrol
*kcontrol
,
403 struct snd_ctl_elem_value
*ucontrol
)
405 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
406 mutex_lock(&chip
->mgr
->mixer_mutex
);
407 ucontrol
->value
.integer
.value
[0] = chip
->monitoring_volume
[0];
408 ucontrol
->value
.integer
.value
[1] = chip
->monitoring_volume
[1];
409 mutex_unlock(&chip
->mgr
->mixer_mutex
);
413 static int pcxhr_monitor_vol_put(struct snd_kcontrol
*kcontrol
,
414 struct snd_ctl_elem_value
*ucontrol
)
416 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
420 mutex_lock(&chip
->mgr
->mixer_mutex
);
421 for (i
= 0; i
< 2; i
++) {
422 if (chip
->monitoring_volume
[i
] != ucontrol
->value
.integer
.value
[i
]) {
423 chip
->monitoring_volume
[i
] = ucontrol
->value
.integer
.value
[i
];
424 if(chip
->monitoring_active
[i
]) /* do only when monitoring is unmuted */
425 /* update monitoring volume and mute */
426 pcxhr_update_audio_pipe_level(chip
, 0, i
);
430 mutex_unlock(&chip
->mgr
->mixer_mutex
);
434 static struct snd_kcontrol_new pcxhr_control_monitor_vol
= {
435 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
436 .name
= "Monitoring Volume",
437 .info
= pcxhr_digital_vol_info
, /* shared */
438 .get
= pcxhr_monitor_vol_get
,
439 .put
= pcxhr_monitor_vol_put
,
443 * monitoring switch control
446 static int pcxhr_monitor_sw_get(struct snd_kcontrol
*kcontrol
,
447 struct snd_ctl_elem_value
*ucontrol
)
449 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
450 mutex_lock(&chip
->mgr
->mixer_mutex
);
451 ucontrol
->value
.integer
.value
[0] = chip
->monitoring_active
[0];
452 ucontrol
->value
.integer
.value
[1] = chip
->monitoring_active
[1];
453 mutex_unlock(&chip
->mgr
->mixer_mutex
);
457 static int pcxhr_monitor_sw_put(struct snd_kcontrol
*kcontrol
,
458 struct snd_ctl_elem_value
*ucontrol
)
460 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
464 mutex_lock(&chip
->mgr
->mixer_mutex
);
465 for (i
= 0; i
< 2; i
++) {
466 if (chip
->monitoring_active
[i
] != ucontrol
->value
.integer
.value
[i
]) {
467 chip
->monitoring_active
[i
] = ucontrol
->value
.integer
.value
[i
];
468 changed
|= (1<<i
); /* mask 0x01 and 0x02 */
472 /* update left monitoring volume and mute */
473 pcxhr_update_audio_pipe_level(chip
, 0, 0);
475 /* update right monitoring volume and mute */
476 pcxhr_update_audio_pipe_level(chip
, 0, 1);
478 mutex_unlock(&chip
->mgr
->mixer_mutex
);
479 return (changed
!= 0);
482 static struct snd_kcontrol_new pcxhr_control_monitor_sw
= {
483 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
484 .name
= "Monitoring Switch",
485 .info
= pcxhr_sw_info
, /* shared */
486 .get
= pcxhr_monitor_sw_get
,
487 .put
= pcxhr_monitor_sw_put
493 * audio source select
495 #define PCXHR_SOURCE_AUDIO01_UER 0x000100
496 #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200
497 #define PCXHR_SOURCE_AUDIO23_UER 0x000400
498 #define PCXHR_SOURCE_AUDIO45_UER 0x001000
499 #define PCXHR_SOURCE_AUDIO67_UER 0x040000
501 static int pcxhr_set_audio_source(struct snd_pcxhr
* chip
)
503 struct pcxhr_rmh rmh
;
504 unsigned int mask
, reg
;
506 int err
, use_src
, changed
;
508 switch (chip
->chip_idx
) {
509 case 0 : mask
= PCXHR_SOURCE_AUDIO01_UER
; codec
= CS8420_01_CS
; break;
510 case 1 : mask
= PCXHR_SOURCE_AUDIO23_UER
; codec
= CS8420_23_CS
; break;
511 case 2 : mask
= PCXHR_SOURCE_AUDIO45_UER
; codec
= CS8420_45_CS
; break;
512 case 3 : mask
= PCXHR_SOURCE_AUDIO67_UER
; codec
= CS8420_67_CS
; break;
513 default: return -EINVAL
;
515 reg
= 0; /* audio source from analog plug */
516 use_src
= 0; /* do not activate codec SRC */
518 if (chip
->audio_capture_source
!= 0) {
519 reg
= mask
; /* audio source from digital plug */
520 if (chip
->audio_capture_source
== 2)
523 /* set the input source */
524 pcxhr_write_io_num_reg_cont(chip
->mgr
, mask
, reg
, &changed
);
525 /* resync them (otherwise channel inversion possible) */
527 pcxhr_init_rmh(&rmh
, CMD_RESYNC_AUDIO_INPUTS
);
528 rmh
.cmd
[0] |= (1 << chip
->chip_idx
);
529 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
533 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_WRITE
); /* set codec SRC on off */
535 rmh
.cmd
[0] |= IO_NUM_UER_CHIP_REG
;
537 rmh
.cmd
[2] = (CS8420_DATA_FLOW_CTL
& CHIP_SIG_AND_MAP_SPI
) | (use_src
? 0x41 : 0x54);
538 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
541 rmh
.cmd
[2] = (CS8420_CLOCK_SRC_CTL
& CHIP_SIG_AND_MAP_SPI
) | (use_src
? 0x41 : 0x49);
542 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
546 static int pcxhr_audio_src_info(struct snd_kcontrol
*kcontrol
,
547 struct snd_ctl_elem_info
*uinfo
)
549 static char *texts
[3] = {"Analog", "Digital", "Digi+SRC"};
551 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
553 uinfo
->value
.enumerated
.items
= 3;
554 if (uinfo
->value
.enumerated
.item
> 2)
555 uinfo
->value
.enumerated
.item
= 2;
556 strcpy(uinfo
->value
.enumerated
.name
,
557 texts
[uinfo
->value
.enumerated
.item
]);
561 static int pcxhr_audio_src_get(struct snd_kcontrol
*kcontrol
,
562 struct snd_ctl_elem_value
*ucontrol
)
564 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
565 ucontrol
->value
.enumerated
.item
[0] = chip
->audio_capture_source
;
569 static int pcxhr_audio_src_put(struct snd_kcontrol
*kcontrol
,
570 struct snd_ctl_elem_value
*ucontrol
)
572 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
575 mutex_lock(&chip
->mgr
->mixer_mutex
);
576 if (chip
->audio_capture_source
!= ucontrol
->value
.enumerated
.item
[0]) {
577 chip
->audio_capture_source
= ucontrol
->value
.enumerated
.item
[0];
578 pcxhr_set_audio_source(chip
);
581 mutex_unlock(&chip
->mgr
->mixer_mutex
);
585 static struct snd_kcontrol_new pcxhr_control_audio_src
= {
586 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
587 .name
= "Capture Source",
588 .info
= pcxhr_audio_src_info
,
589 .get
= pcxhr_audio_src_get
,
590 .put
= pcxhr_audio_src_put
,
595 * clock type selection
596 * enum pcxhr_clock_type {
597 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
598 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
599 * PCXHR_CLOCK_TYPE_AES_SYNC,
600 * PCXHR_CLOCK_TYPE_AES_1,
601 * PCXHR_CLOCK_TYPE_AES_2,
602 * PCXHR_CLOCK_TYPE_AES_3,
603 * PCXHR_CLOCK_TYPE_AES_4,
607 static int pcxhr_clock_type_info(struct snd_kcontrol
*kcontrol
,
608 struct snd_ctl_elem_info
*uinfo
)
610 static char *texts
[7] = {
611 "Internal", "WordClock", "AES Sync", "AES 1", "AES 2", "AES 3", "AES 4"
613 struct pcxhr_mgr
*mgr
= snd_kcontrol_chip(kcontrol
);
614 int clock_items
= 3 + mgr
->capture_chips
;
616 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
618 uinfo
->value
.enumerated
.items
= clock_items
;
619 if (uinfo
->value
.enumerated
.item
>= clock_items
)
620 uinfo
->value
.enumerated
.item
= clock_items
-1;
621 strcpy(uinfo
->value
.enumerated
.name
,
622 texts
[uinfo
->value
.enumerated
.item
]);
626 static int pcxhr_clock_type_get(struct snd_kcontrol
*kcontrol
,
627 struct snd_ctl_elem_value
*ucontrol
)
629 struct pcxhr_mgr
*mgr
= snd_kcontrol_chip(kcontrol
);
630 ucontrol
->value
.enumerated
.item
[0] = mgr
->use_clock_type
;
634 static int pcxhr_clock_type_put(struct snd_kcontrol
*kcontrol
,
635 struct snd_ctl_elem_value
*ucontrol
)
637 struct pcxhr_mgr
*mgr
= snd_kcontrol_chip(kcontrol
);
640 mutex_lock(&mgr
->mixer_mutex
);
641 if (mgr
->use_clock_type
!= ucontrol
->value
.enumerated
.item
[0]) {
642 mutex_lock(&mgr
->setup_mutex
);
643 mgr
->use_clock_type
= ucontrol
->value
.enumerated
.item
[0];
644 if (mgr
->use_clock_type
)
645 pcxhr_get_external_clock(mgr
, mgr
->use_clock_type
, &rate
);
647 rate
= mgr
->sample_rate
;
649 pcxhr_set_clock(mgr
, rate
);
650 if (mgr
->sample_rate
)
651 mgr
->sample_rate
= rate
;
653 mutex_unlock(&mgr
->setup_mutex
);
654 ret
= 1; /* return 1 even if the set was not done. ok ? */
656 mutex_unlock(&mgr
->mixer_mutex
);
660 static struct snd_kcontrol_new pcxhr_control_clock_type
= {
661 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
662 .name
= "Clock Mode",
663 .info
= pcxhr_clock_type_info
,
664 .get
= pcxhr_clock_type_get
,
665 .put
= pcxhr_clock_type_put
,
670 * specific control that scans the sample rates on the external plugs
672 static int pcxhr_clock_rate_info(struct snd_kcontrol
*kcontrol
,
673 struct snd_ctl_elem_info
*uinfo
)
675 struct pcxhr_mgr
*mgr
= snd_kcontrol_chip(kcontrol
);
676 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
677 uinfo
->count
= 3 + mgr
->capture_chips
;
678 uinfo
->value
.integer
.min
= 0; /* clock not present */
679 uinfo
->value
.integer
.max
= 192000; /* max sample rate 192 kHz */
683 static int pcxhr_clock_rate_get(struct snd_kcontrol
*kcontrol
,
684 struct snd_ctl_elem_value
*ucontrol
)
686 struct pcxhr_mgr
*mgr
= snd_kcontrol_chip(kcontrol
);
689 mutex_lock(&mgr
->mixer_mutex
);
690 for(i
= 0; i
< 3 + mgr
->capture_chips
; i
++) {
691 if (i
== PCXHR_CLOCK_TYPE_INTERNAL
)
692 rate
= mgr
->sample_rate_real
;
694 err
= pcxhr_get_external_clock(mgr
, i
, &rate
);
698 ucontrol
->value
.integer
.value
[i
] = rate
;
700 mutex_unlock(&mgr
->mixer_mutex
);
704 static struct snd_kcontrol_new pcxhr_control_clock_rate
= {
705 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
706 .iface
= SNDRV_CTL_ELEM_IFACE_CARD
,
707 .name
= "Clock Rates",
708 .info
= pcxhr_clock_rate_info
,
709 .get
= pcxhr_clock_rate_get
,
715 static int pcxhr_iec958_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
717 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
722 static int pcxhr_iec958_capture_byte(struct snd_pcxhr
*chip
, int aes_idx
, unsigned char* aes_bits
)
726 struct pcxhr_rmh rmh
;
728 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_READ
);
729 rmh
.cmd
[0] |= IO_NUM_UER_CHIP_REG
;
730 switch (chip
->chip_idx
) {
731 case 0: rmh
.cmd
[1] = CS8420_01_CS
; break; /* use CS8416_01_CS for AES SYNC plug */
732 case 1: rmh
.cmd
[1] = CS8420_23_CS
; break;
733 case 2: rmh
.cmd
[1] = CS8420_45_CS
; break;
734 case 3: rmh
.cmd
[1] = CS8420_67_CS
; break;
735 default: return -EINVAL
;
738 case 0: rmh
.cmd
[2] = CS8420_CSB0
; break; /* use CS8416_CSBx for AES SYNC plug */
739 case 1: rmh
.cmd
[2] = CS8420_CSB1
; break;
740 case 2: rmh
.cmd
[2] = CS8420_CSB2
; break;
741 case 3: rmh
.cmd
[2] = CS8420_CSB3
; break;
742 case 4: rmh
.cmd
[2] = CS8420_CSB4
; break;
743 default: return -EINVAL
;
745 rmh
.cmd
[1] &= 0x0fffff; /* size and code the chip id for the fpga */
746 rmh
.cmd
[2] &= CHIP_SIG_AND_MAP_SPI
; /* chip signature + map for spi read */
748 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
752 for (i
= 0; i
< 8; i
++) {
753 /* attention : reversed bit order (not with CS8416_01_CS) */
755 if (rmh
.stat
[1] & (1 << i
))
758 snd_printdd("read iec958 AES %d byte %d = 0x%x\n", chip
->chip_idx
, aes_idx
, temp
);
763 static int pcxhr_iec958_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
765 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
766 unsigned char aes_bits
;
769 mutex_lock(&chip
->mgr
->mixer_mutex
);
770 for(i
= 0; i
< 5; i
++) {
771 if (kcontrol
->private_value
== 0) /* playback */
772 aes_bits
= chip
->aes_bits
[i
];
774 err
= pcxhr_iec958_capture_byte(chip
, i
, &aes_bits
);
778 ucontrol
->value
.iec958
.status
[i
] = aes_bits
;
780 mutex_unlock(&chip
->mgr
->mixer_mutex
);
784 static int pcxhr_iec958_mask_get(struct snd_kcontrol
*kcontrol
,
785 struct snd_ctl_elem_value
*ucontrol
)
788 for (i
= 0; i
< 5; i
++)
789 ucontrol
->value
.iec958
.status
[i
] = 0xff;
793 static int pcxhr_iec958_update_byte(struct snd_pcxhr
*chip
, int aes_idx
, unsigned char aes_bits
)
796 unsigned char new_bits
= aes_bits
;
797 unsigned char old_bits
= chip
->aes_bits
[aes_idx
];
798 struct pcxhr_rmh rmh
;
800 for (i
= 0; i
< 8; i
++) {
801 if ((old_bits
& 0x01) != (new_bits
& 0x01)) {
802 cmd
= chip
->chip_idx
& 0x03; /* chip index 0..3 */
803 if(chip
->chip_idx
> 3)
804 /* new bit used if chip_idx>3 (PCX1222HR) */
806 cmd
|= ((aes_idx
<< 3) + i
) << 2; /* add bit offset */
807 cmd
|= (new_bits
& 0x01) << 23; /* add bit value */
808 pcxhr_init_rmh(&rmh
, CMD_ACCESS_IO_WRITE
);
809 rmh
.cmd
[0] |= IO_NUM_REG_CUER
;
812 snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n",
813 chip
->chip_idx
, aes_idx
, i
, cmd
);
814 err
= pcxhr_send_msg(chip
->mgr
, &rmh
);
821 chip
->aes_bits
[aes_idx
] = aes_bits
;
825 static int pcxhr_iec958_put(struct snd_kcontrol
*kcontrol
,
826 struct snd_ctl_elem_value
*ucontrol
)
828 struct snd_pcxhr
*chip
= snd_kcontrol_chip(kcontrol
);
832 mutex_lock(&chip
->mgr
->mixer_mutex
);
833 for (i
= 0; i
< 5; i
++) {
834 if (ucontrol
->value
.iec958
.status
[i
] != chip
->aes_bits
[i
]) {
835 pcxhr_iec958_update_byte(chip
, i
, ucontrol
->value
.iec958
.status
[i
]);
839 mutex_unlock(&chip
->mgr
->mixer_mutex
);
843 static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask
= {
844 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
845 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
846 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
847 .info
= pcxhr_iec958_info
,
848 .get
= pcxhr_iec958_mask_get
850 static struct snd_kcontrol_new pcxhr_control_playback_iec958
= {
851 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
852 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
853 .info
= pcxhr_iec958_info
,
854 .get
= pcxhr_iec958_get
,
855 .put
= pcxhr_iec958_put
,
856 .private_value
= 0 /* playback */
859 static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask
= {
860 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
861 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
862 .name
= SNDRV_CTL_NAME_IEC958("",CAPTURE
,MASK
),
863 .info
= pcxhr_iec958_info
,
864 .get
= pcxhr_iec958_mask_get
866 static struct snd_kcontrol_new pcxhr_control_capture_iec958
= {
867 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
868 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
869 .name
= SNDRV_CTL_NAME_IEC958("",CAPTURE
,DEFAULT
),
870 .info
= pcxhr_iec958_info
,
871 .get
= pcxhr_iec958_get
,
872 .private_value
= 1 /* capture */
875 static void pcxhr_init_audio_levels(struct snd_pcxhr
*chip
)
879 for (i
= 0; i
< 2; i
++) {
880 if (chip
->nb_streams_play
) {
882 /* at boot time the digital volumes are unmuted 0dB */
883 for (j
= 0; j
< PCXHR_PLAYBACK_STREAMS
; j
++) {
884 chip
->digital_playback_active
[j
][i
] = 1;
885 chip
->digital_playback_volume
[j
][i
] = PCXHR_DIGITAL_ZERO_LEVEL
;
887 /* after boot, only two bits are set on the uer interface */
888 chip
->aes_bits
[0] = IEC958_AES0_PROFESSIONAL
| IEC958_AES0_PRO_FS_48000
;
889 /* only for test purpose, remove later */
890 #ifdef CONFIG_SND_DEBUG
891 /* analog volumes for playback (is LEVEL_MIN after boot) */
892 chip
->analog_playback_active
[i
] = 1;
893 chip
->analog_playback_volume
[i
] = PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL
;
894 pcxhr_update_analog_audio_level(chip
, 0, i
);
898 if (chip
->nb_streams_capt
) {
899 /* at boot time the digital volumes are unmuted 0dB */
900 chip
->digital_capture_volume
[i
] = PCXHR_DIGITAL_ZERO_LEVEL
;
901 /* only for test purpose, remove later */
902 #ifdef CONFIG_SND_DEBUG
903 /* analog volumes for playback (is LEVEL_MIN after boot) */
904 chip
->analog_capture_volume
[i
] = PCXHR_ANALOG_CAPTURE_ZERO_LEVEL
;
905 pcxhr_update_analog_audio_level(chip
, 1, i
);
915 int pcxhr_create_mixer(struct pcxhr_mgr
*mgr
)
917 struct snd_pcxhr
*chip
;
920 mutex_init(&mgr
->mixer_mutex
); /* can be in another place */
922 for (i
= 0; i
< mgr
->num_cards
; i
++) {
923 struct snd_kcontrol_new temp
;
926 if (chip
->nb_streams_play
) {
927 /* analog output level control */
928 temp
= pcxhr_control_analog_level
;
929 temp
.name
= "Master Playback Volume";
930 temp
.private_value
= 0; /* playback */
931 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&temp
, chip
))) < 0)
933 /* output mute controls */
934 if ((err
= snd_ctl_add(chip
->card
,
935 snd_ctl_new1(&pcxhr_control_output_switch
,
939 temp
= snd_pcxhr_pcm_vol
;
940 temp
.name
= "PCM Playback Volume";
941 temp
.count
= PCXHR_PLAYBACK_STREAMS
;
942 temp
.private_value
= 0; /* playback */
943 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&temp
, chip
))) < 0)
946 if ((err
= snd_ctl_add(chip
->card
,
947 snd_ctl_new1(&pcxhr_control_pcm_switch
,
951 /* IEC958 controls */
952 if ((err
= snd_ctl_add(chip
->card
,
953 snd_ctl_new1(&pcxhr_control_playback_iec958_mask
,
956 if ((err
= snd_ctl_add(chip
->card
,
957 snd_ctl_new1(&pcxhr_control_playback_iec958
,
961 if (chip
->nb_streams_capt
) {
962 /* analog input level control only on first two chips !*/
963 temp
= pcxhr_control_analog_level
;
964 temp
.name
= "Master Capture Volume";
965 temp
.private_value
= 1; /* capture */
966 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&temp
, chip
))) < 0)
969 temp
= snd_pcxhr_pcm_vol
;
970 temp
.name
= "PCM Capture Volume";
972 temp
.private_value
= 1; /* capture */
973 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&temp
, chip
))) < 0)
976 if ((err
= snd_ctl_add(chip
->card
,
977 snd_ctl_new1(&pcxhr_control_audio_src
,
980 /* IEC958 controls */
981 if ((err
= snd_ctl_add(chip
->card
,
982 snd_ctl_new1(&pcxhr_control_capture_iec958_mask
,
985 if ((err
= snd_ctl_add(chip
->card
,
986 snd_ctl_new1(&pcxhr_control_capture_iec958
,
990 /* monitoring only if playback and capture device available */
991 if (chip
->nb_streams_capt
> 0 && chip
->nb_streams_play
> 0) {
993 if ((err
= snd_ctl_add(chip
->card
,
994 snd_ctl_new1(&pcxhr_control_monitor_vol
,
997 if ((err
= snd_ctl_add(chip
->card
,
998 snd_ctl_new1(&pcxhr_control_monitor_sw
,
1004 /* clock mode only one control per pcxhr */
1005 if ((err
= snd_ctl_add(chip
->card
,
1006 snd_ctl_new1(&pcxhr_control_clock_type
,
1009 /* non standard control used to scan the external clock presence/frequencies */
1010 if ((err
= snd_ctl_add(chip
->card
,
1011 snd_ctl_new1(&pcxhr_control_clock_rate
,
1016 /* init values for the mixer data */
1017 pcxhr_init_audio_levels(chip
);