File Index
Files and directories
Sign in
FILE

pcxhr_mixer.c

File preview with syntax highlighting.

linux-6.19.14/sound/pci/pcxhr/pcxhr_mixer.c C
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2#define __NO_VERSION__
   3/*
   4 * Driver for Digigram pcxhr compatible soundcards
   5 *
   6 * mixer callbacks
   7 *
   8 * Copyright (c) 2004 by Digigram <alsa@digigram.com>
   9 */
  10
  11#include <linux/time.h>
  12#include <linux/interrupt.h>
  13#include <linux/init.h>
  14#include <linux/mutex.h>
  15#include <sound/core.h>
  16#include "pcxhr.h"
  17#include "pcxhr_hwdep.h"
  18#include "pcxhr_core.h"
  19#include <sound/control.h>
  20#include <sound/tlv.h>
  21#include <sound/asoundef.h>
  22#include "pcxhr_mixer.h"
  23#include "pcxhr_mix22.h"
  24
  25#define PCXHR_LINE_CAPTURE_LEVEL_MIN   0	/* -112.0 dB */
  26#define PCXHR_LINE_CAPTURE_LEVEL_MAX   255	/* +15.5 dB */
  27#define PCXHR_LINE_CAPTURE_ZERO_LEVEL  224	/* 0.0 dB ( 0 dBu -> 0 dBFS ) */
  28
  29#define PCXHR_LINE_PLAYBACK_LEVEL_MIN  0	/* -104.0 dB */
  30#define PCXHR_LINE_PLAYBACK_LEVEL_MAX  128	/* +24.0 dB */
  31#define PCXHR_LINE_PLAYBACK_ZERO_LEVEL 104	/* 0.0 dB ( 0 dBFS -> 0 dBu ) */
  32
  33static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -11200, 50, 1550);
  34static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400);
  35
  36static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_capture, -11150, 50, 1600);
  37static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_playback, -2550, 50, 2400);
  38
  39static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip,
  40					   int is_capture, int channel)
  41{
  42	int err, vol;
  43	struct pcxhr_rmh rmh;
  44
  45	pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
  46	if (is_capture) {
  47		rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL;
  48		rmh.cmd[2] = chip->analog_capture_volume[channel];
  49	} else {
  50		rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL;
  51		if (chip->analog_playback_active[channel])
  52			vol = chip->analog_playback_volume[channel];
  53		else
  54			vol = PCXHR_LINE_PLAYBACK_LEVEL_MIN;
  55		/* playback analog levels are inversed */
  56		rmh.cmd[2] = PCXHR_LINE_PLAYBACK_LEVEL_MAX - vol;
  57	}
  58	rmh.cmd[1]  = 1 << ((2 * chip->chip_idx) + channel);	/* audio mask */
  59	rmh.cmd_len = 3;
  60	err = pcxhr_send_msg(chip->mgr, &rmh);
  61	if (err < 0) {
  62		dev_dbg(chip->card->dev,
  63			"error update_analog_audio_level card(%d)"
  64			   " is_capture(%d) err(%x)\n",
  65			   chip->chip_idx, is_capture, err);
  66		return -EINVAL;
  67	}
  68	return 0;
  69}
  70
  71/*
  72 * analog level control
  73 */
  74static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
  75				 struct snd_ctl_elem_info *uinfo)
  76{
  77	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  78
  79	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  80	uinfo->count = 2;
  81	if (kcontrol->private_value == 0) {	/* playback */
  82	    if (chip->mgr->is_hr_stereo) {
  83		uinfo->value.integer.min =
  84			HR222_LINE_PLAYBACK_LEVEL_MIN;	/* -25 dB */
  85		uinfo->value.integer.max =
  86			HR222_LINE_PLAYBACK_LEVEL_MAX;	/* +24 dB */
  87	    } else {
  88		uinfo->value.integer.min =
  89			PCXHR_LINE_PLAYBACK_LEVEL_MIN;	/*-104 dB */
  90		uinfo->value.integer.max =
  91			PCXHR_LINE_PLAYBACK_LEVEL_MAX;	/* +24 dB */
  92	    }
  93	} else {				/* capture */
  94	    if (chip->mgr->is_hr_stereo) {
  95		uinfo->value.integer.min =
  96			HR222_LINE_CAPTURE_LEVEL_MIN;	/*-112 dB */
  97		uinfo->value.integer.max =
  98			HR222_LINE_CAPTURE_LEVEL_MAX;	/* +15.5 dB */
  99	    } else {
 100		uinfo->value.integer.min =
 101			PCXHR_LINE_CAPTURE_LEVEL_MIN;	/*-112 dB */
 102		uinfo->value.integer.max =
 103			PCXHR_LINE_CAPTURE_LEVEL_MAX;	/* +15.5 dB */
 104	    }
 105	}
 106	return 0;
 107}
 108
 109static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
 110				struct snd_ctl_elem_value *ucontrol)
 111{
 112	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 113
 114	guard(mutex)(&chip->mgr->mixer_mutex);
 115	if (kcontrol->private_value == 0) {	/* playback */
 116	  ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
 117	  ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
 118	} else {				/* capture */
 119	  ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
 120	  ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
 121	}
 122	return 0;
 123}
 124
 125static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
 126				struct snd_ctl_elem_value *ucontrol)
 127{
 128	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 129	int changed = 0;
 130	int is_capture, i;
 131
 132	guard(mutex)(&chip->mgr->mixer_mutex);
 133	is_capture = (kcontrol->private_value != 0);
 134	for (i = 0; i < 2; i++) {
 135		int  new_volume = ucontrol->value.integer.value[i];
 136		int *stored_volume = is_capture ?
 137			&chip->analog_capture_volume[i] :
 138			&chip->analog_playback_volume[i];
 139		if (is_capture) {
 140			if (chip->mgr->is_hr_stereo) {
 141				if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN ||
 142				    new_volume > HR222_LINE_CAPTURE_LEVEL_MAX)
 143					continue;
 144			} else {
 145				if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN ||
 146				    new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX)
 147					continue;
 148			}
 149		} else {
 150			if (chip->mgr->is_hr_stereo) {
 151				if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN ||
 152				    new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX)
 153					continue;
 154			} else {
 155				if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN ||
 156				    new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX)
 157					continue;
 158			}
 159		}
 160		if (*stored_volume != new_volume) {
 161			*stored_volume = new_volume;
 162			changed = 1;
 163			if (chip->mgr->is_hr_stereo)
 164				hr222_update_analog_audio_level(chip,
 165								is_capture, i);
 166			else
 167				pcxhr_update_analog_audio_level(chip,
 168								is_capture, i);
 169		}
 170	}
 171	return changed;
 172}
 173
 174static const struct snd_kcontrol_new pcxhr_control_analog_level = {
 175	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 176	.access =	(SNDRV_CTL_ELEM_ACCESS_READWRITE |
 177			 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
 178	/* name will be filled later */
 179	.info =		pcxhr_analog_vol_info,
 180	.get =		pcxhr_analog_vol_get,
 181	.put =		pcxhr_analog_vol_put,
 182	/* tlv will be filled later */
 183};
 184
 185/* shared */
 186
 187#define pcxhr_sw_info		snd_ctl_boolean_stereo_info
 188
 189static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
 190			      struct snd_ctl_elem_value *ucontrol)
 191{
 192	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 193
 194	guard(mutex)(&chip->mgr->mixer_mutex);
 195	ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
 196	ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
 197	return 0;
 198}
 199
 200static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
 201			      struct snd_ctl_elem_value *ucontrol)
 202{
 203	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 204	int i, changed = 0;
 205
 206	guard(mutex)(&chip->mgr->mixer_mutex);
 207	for(i = 0; i < 2; i++) {
 208		if (chip->analog_playback_active[i] !=
 209		    ucontrol->value.integer.value[i]) {
 210			chip->analog_playback_active[i] =
 211				!!ucontrol->value.integer.value[i];
 212			changed = 1;
 213			/* update playback levels */
 214			if (chip->mgr->is_hr_stereo)
 215				hr222_update_analog_audio_level(chip, 0, i);
 216			else
 217				pcxhr_update_analog_audio_level(chip, 0, i);
 218		}
 219	}
 220	return changed;
 221}
 222
 223static const struct snd_kcontrol_new pcxhr_control_output_switch = {
 224	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 225	.name =		"Master Playback Switch",
 226	.info =		pcxhr_sw_info,		/* shared */
 227	.get =		pcxhr_audio_sw_get,
 228	.put =		pcxhr_audio_sw_put
 229};
 230
 231
 232#define PCXHR_DIGITAL_LEVEL_MIN		0x000	/* -110 dB */
 233#define PCXHR_DIGITAL_LEVEL_MAX		0x1ff	/* +18 dB */
 234#define PCXHR_DIGITAL_ZERO_LEVEL	0x1b7	/*  0 dB */
 235
 236static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10975, 25, 1800);
 237
 238#define MORE_THAN_ONE_STREAM_LEVEL	0x000001
 239#define VALID_STREAM_PAN_LEVEL_MASK	0x800000
 240#define VALID_STREAM_LEVEL_MASK		0x400000
 241#define VALID_STREAM_LEVEL_1_MASK	0x200000
 242#define VALID_STREAM_LEVEL_2_MASK	0x100000
 243
 244static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
 245{
 246	int err;
 247	struct pcxhr_rmh rmh;
 248	struct pcxhr_pipe *pipe = &chip->playback_pipe;
 249	int left, right;
 250
 251	if (chip->digital_playback_active[idx][0])
 252		left = chip->digital_playback_volume[idx][0];
 253	else
 254		left = PCXHR_DIGITAL_LEVEL_MIN;
 255	if (chip->digital_playback_active[idx][1])
 256		right = chip->digital_playback_volume[idx][1];
 257	else
 258		right = PCXHR_DIGITAL_LEVEL_MIN;
 259
 260	pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST);
 261	/* add pipe and stream mask */
 262	pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx);
 263	/* volume left->left / right->right panoramic level */
 264	rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL;
 265	rmh.cmd[2]  = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK;
 266	rmh.cmd[2] |= (left << 10);
 267	rmh.cmd[3]  = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK;
 268	rmh.cmd[3] |= right;
 269	rmh.cmd_len = 4;
 270
 271	err = pcxhr_send_msg(chip->mgr, &rmh);
 272	if (err < 0) {
 273		dev_dbg(chip->card->dev, "error update_playback_stream_level "
 274			   "card(%d) err(%x)\n", chip->chip_idx, err);
 275		return -EINVAL;
 276	}
 277	return 0;
 278}
 279
 280#define AUDIO_IO_HAS_MUTE_LEVEL		0x400000
 281#define AUDIO_IO_HAS_MUTE_MONITOR_1	0x200000
 282#define VALID_AUDIO_IO_DIGITAL_LEVEL	0x000001
 283#define VALID_AUDIO_IO_MONITOR_LEVEL	0x000002
 284#define VALID_AUDIO_IO_MUTE_LEVEL	0x000004
 285#define VALID_AUDIO_IO_MUTE_MONITOR_1	0x000008
 286
 287static int pcxhr_update_audio_pipe_level(struct snd_pcxhr *chip,
 288					 int capture, int channel)
 289{
 290	int err;
 291	struct pcxhr_rmh rmh;
 292	struct pcxhr_pipe *pipe;
 293
 294	if (capture)
 295		pipe = &chip->capture_pipe[0];
 296	else
 297		pipe = &chip->playback_pipe;
 298
 299	pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
 300	/* add channel mask */
 301	pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0,
 302				  1 << (channel + pipe->first_audio));
 303	/* TODO : if mask (3 << pipe->first_audio) is used, left and right
 304	 * channel will be programmed to the same params */
 305	if (capture) {
 306		rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
 307		/* VALID_AUDIO_IO_MUTE_LEVEL not yet handled
 308		 * (capture pipe level) */
 309		rmh.cmd[2] = chip->digital_capture_volume[channel];
 310	} else {
 311		rmh.cmd[0] |=	VALID_AUDIO_IO_MONITOR_LEVEL |
 312				VALID_AUDIO_IO_MUTE_MONITOR_1;
 313		/* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL
 314		 * not yet handled (playback pipe level)
 315		 */
 316		rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
 317		if (chip->monitoring_active[channel] == 0)
 318			rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1;
 319	}
 320	rmh.cmd_len = 3;
 321
 322	err = pcxhr_send_msg(chip->mgr, &rmh);
 323	if (err < 0) {
 324		dev_dbg(chip->card->dev,
 325			"error update_audio_level(%d) err=%x\n",
 326			   chip->chip_idx, err);
 327		return -EINVAL;
 328	}
 329	return 0;
 330}
 331
 332
 333/* shared */
 334static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol,
 335				  struct snd_ctl_elem_info *uinfo)
 336{
 337	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 338	uinfo->count = 2;
 339	uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN;   /* -109.5 dB */
 340	uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX;   /*   18.0 dB */
 341	return 0;
 342}
 343
 344
 345static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
 346			     struct snd_ctl_elem_value *ucontrol)
 347{
 348	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 349	int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	/* index */
 350	int *stored_volume;
 351	int is_capture = kcontrol->private_value;
 352
 353	guard(mutex)(&chip->mgr->mixer_mutex);
 354	if (is_capture)		/* digital capture */
 355		stored_volume = chip->digital_capture_volume;
 356	else			/* digital playback */
 357		stored_volume = chip->digital_playback_volume[idx];
 358	ucontrol->value.integer.value[0] = stored_volume[0];
 359	ucontrol->value.integer.value[1] = stored_volume[1];
 360	return 0;
 361}
 362
 363static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
 364			     struct snd_ctl_elem_value *ucontrol)
 365{
 366	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 367	int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	/* index */
 368	int changed = 0;
 369	int is_capture = kcontrol->private_value;
 370	int *stored_volume;
 371	int i;
 372
 373	guard(mutex)(&chip->mgr->mixer_mutex);
 374	if (is_capture)		/* digital capture */
 375		stored_volume = chip->digital_capture_volume;
 376	else			/* digital playback */
 377		stored_volume = chip->digital_playback_volume[idx];
 378	for (i = 0; i < 2; i++) {
 379		int vol = ucontrol->value.integer.value[i];
 380		if (vol < PCXHR_DIGITAL_LEVEL_MIN ||
 381		    vol > PCXHR_DIGITAL_LEVEL_MAX)
 382			continue;
 383		if (stored_volume[i] != vol) {
 384			stored_volume[i] = vol;
 385			changed = 1;
 386			if (is_capture)	/* update capture volume */
 387				pcxhr_update_audio_pipe_level(chip, 1, i);
 388		}
 389	}
 390	if (!is_capture && changed)	/* update playback volume */
 391		pcxhr_update_playback_stream_level(chip, idx);
 392	return changed;
 393}
 394
 395static const struct snd_kcontrol_new snd_pcxhr_pcm_vol =
 396{
 397	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 398	.access =	(SNDRV_CTL_ELEM_ACCESS_READWRITE |
 399			 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
 400	/* name will be filled later */
 401	/* count will be filled later */
 402	.info =		pcxhr_digital_vol_info,		/* shared */
 403	.get =		pcxhr_pcm_vol_get,
 404	.put =		pcxhr_pcm_vol_put,
 405	.tlv = { .p = db_scale_digital },
 406};
 407
 408
 409static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
 410			    struct snd_ctl_elem_value *ucontrol)
 411{
 412	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 413	int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
 414
 415	guard(mutex)(&chip->mgr->mixer_mutex);
 416	ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
 417	ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
 418	return 0;
 419}
 420
 421static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol,
 422			    struct snd_ctl_elem_value *ucontrol)
 423{
 424	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 425	int changed = 0;
 426	int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
 427	int i, j;
 428
 429	guard(mutex)(&chip->mgr->mixer_mutex);
 430	j = idx;
 431	for (i = 0; i < 2; i++) {
 432		if (chip->digital_playback_active[j][i] !=
 433		    ucontrol->value.integer.value[i]) {
 434			chip->digital_playback_active[j][i] =
 435				!!ucontrol->value.integer.value[i];
 436			changed = 1;
 437		}
 438	}
 439	if (changed)
 440		pcxhr_update_playback_stream_level(chip, idx);
 441	return changed;
 442}
 443
 444static const struct snd_kcontrol_new pcxhr_control_pcm_switch = {
 445	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 446	.name =		"PCM Playback Switch",
 447	.count =	PCXHR_PLAYBACK_STREAMS,
 448	.info =		pcxhr_sw_info,		/* shared */
 449	.get =		pcxhr_pcm_sw_get,
 450	.put =		pcxhr_pcm_sw_put
 451};
 452
 453
 454/*
 455 * monitoring level control
 456 */
 457
 458static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
 459				 struct snd_ctl_elem_value *ucontrol)
 460{
 461	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 462
 463	guard(mutex)(&chip->mgr->mixer_mutex);
 464	ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
 465	ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
 466	return 0;
 467}
 468
 469static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
 470				 struct snd_ctl_elem_value *ucontrol)
 471{
 472	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 473	int changed = 0;
 474	int i;
 475
 476	guard(mutex)(&chip->mgr->mixer_mutex);
 477	for (i = 0; i < 2; i++) {
 478		if (chip->monitoring_volume[i] !=
 479		    ucontrol->value.integer.value[i]) {
 480			chip->monitoring_volume[i] =
 481				ucontrol->value.integer.value[i];
 482			if (chip->monitoring_active[i])
 483				/* update monitoring volume and mute */
 484				/* do only when monitoring is unmuted */
 485				pcxhr_update_audio_pipe_level(chip, 0, i);
 486			changed = 1;
 487		}
 488	}
 489	return changed;
 490}
 491
 492static const struct snd_kcontrol_new pcxhr_control_monitor_vol = {
 493	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 494	.access =	(SNDRV_CTL_ELEM_ACCESS_READWRITE |
 495			 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
 496	.name =         "Monitoring Playback Volume",
 497	.info =		pcxhr_digital_vol_info,		/* shared */
 498	.get =		pcxhr_monitor_vol_get,
 499	.put =		pcxhr_monitor_vol_put,
 500	.tlv = { .p = db_scale_digital },
 501};
 502
 503/*
 504 * monitoring switch control
 505 */
 506
 507static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
 508				struct snd_ctl_elem_value *ucontrol)
 509{
 510	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 511
 512	guard(mutex)(&chip->mgr->mixer_mutex);
 513	ucontrol->value.integer.value[0] = chip->monitoring_active[0];
 514	ucontrol->value.integer.value[1] = chip->monitoring_active[1];
 515	return 0;
 516}
 517
 518static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
 519				struct snd_ctl_elem_value *ucontrol)
 520{
 521	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 522	int changed = 0;
 523	int i;
 524
 525	guard(mutex)(&chip->mgr->mixer_mutex);
 526	for (i = 0; i < 2; i++) {
 527		if (chip->monitoring_active[i] !=
 528		    ucontrol->value.integer.value[i]) {
 529			chip->monitoring_active[i] =
 530				!!ucontrol->value.integer.value[i];
 531			changed |= (1<<i); /* mask 0x01 and 0x02 */
 532		}
 533	}
 534	if (changed & 0x01)
 535		/* update left monitoring volume and mute */
 536		pcxhr_update_audio_pipe_level(chip, 0, 0);
 537	if (changed & 0x02)
 538		/* update right monitoring volume and mute */
 539		pcxhr_update_audio_pipe_level(chip, 0, 1);
 540
 541	return (changed != 0);
 542}
 543
 544static const struct snd_kcontrol_new pcxhr_control_monitor_sw = {
 545	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 546	.name =         "Monitoring Playback Switch",
 547	.info =         pcxhr_sw_info,		/* shared */
 548	.get =          pcxhr_monitor_sw_get,
 549	.put =          pcxhr_monitor_sw_put
 550};
 551
 552
 553
 554/*
 555 * audio source select
 556 */
 557#define PCXHR_SOURCE_AUDIO01_UER	0x000100
 558#define PCXHR_SOURCE_AUDIO01_SYNC	0x000200
 559#define PCXHR_SOURCE_AUDIO23_UER	0x000400
 560#define PCXHR_SOURCE_AUDIO45_UER	0x001000
 561#define PCXHR_SOURCE_AUDIO67_UER	0x040000
 562
 563static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
 564{
 565	struct pcxhr_rmh rmh;
 566	unsigned int mask, reg;
 567	unsigned int codec;
 568	int err, changed;
 569
 570	switch (chip->chip_idx) {
 571	case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
 572	case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break;
 573	case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break;
 574	case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
 575	default: return -EINVAL;
 576	}
 577	if (chip->audio_capture_source != 0) {
 578		reg = mask;	/* audio source from digital plug */
 579	} else {
 580		reg = 0;	/* audio source from analog plug */
 581	}
 582	/* set the input source */
 583	pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
 584	/* resync them (otherwise channel inversion possible) */
 585	if (changed) {
 586		pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS);
 587		rmh.cmd[0] |= (1 << chip->chip_idx);
 588		err = pcxhr_send_msg(chip->mgr, &rmh);
 589		if (err)
 590			return err;
 591	}
 592	if (chip->mgr->board_aes_in_192k) {
 593		int i;
 594		unsigned int src_config = 0xC0;
 595		/* update all src configs with one call */
 596		for (i = 0; (i < 4) && (i < chip->mgr->capture_chips); i++) {
 597			if (chip->mgr->chip[i]->audio_capture_source == 2)
 598				src_config |= (1 << (3 - i));
 599		}
 600		/* set codec SRC on off */
 601		pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
 602		rmh.cmd_len = 2;
 603		rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC;
 604		rmh.cmd[1] = src_config;
 605		err = pcxhr_send_msg(chip->mgr, &rmh);
 606	} else {
 607		int use_src = 0;
 608		if (chip->audio_capture_source == 2)
 609			use_src = 1;
 610		/* set codec SRC on off */
 611		pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
 612		rmh.cmd_len = 3;
 613		rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
 614		rmh.cmd[1] = codec;
 615		rmh.cmd[2] = ((CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) |
 616			      (use_src ? 0x41 : 0x54));
 617		err = pcxhr_send_msg(chip->mgr, &rmh);
 618		if (err)
 619			return err;
 620		rmh.cmd[2] = ((CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) |
 621			      (use_src ? 0x41 : 0x49));
 622		err = pcxhr_send_msg(chip->mgr, &rmh);
 623	}
 624	return err;
 625}
 626
 627static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
 628				struct snd_ctl_elem_info *uinfo)
 629{
 630	static const char *texts[5] = {
 631		"Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"
 632	};
 633	int i;
 634	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 635
 636	i = 2;			/* no SRC, no Mic available */
 637	if (chip->mgr->board_has_aes1) {
 638		i = 3;		/* SRC available */
 639		if (chip->mgr->board_has_mic)
 640			i = 5;	/* Mic and MicroMix available */
 641	}
 642	return snd_ctl_enum_info(uinfo, 1, i, texts);
 643}
 644
 645static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
 646			       struct snd_ctl_elem_value *ucontrol)
 647{
 648	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 649	ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
 650	return 0;
 651}
 652
 653static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
 654			       struct snd_ctl_elem_value *ucontrol)
 655{
 656	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 657	int ret = 0;
 658	int i = 2;		/* no SRC, no Mic available */
 659	if (chip->mgr->board_has_aes1) {
 660		i = 3;		/* SRC available */
 661		if (chip->mgr->board_has_mic)
 662			i = 5;	/* Mic and MicroMix available */
 663	}
 664	if (ucontrol->value.enumerated.item[0] >= i)
 665		return -EINVAL;
 666	guard(mutex)(&chip->mgr->mixer_mutex);
 667	if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
 668		chip->audio_capture_source = ucontrol->value.enumerated.item[0];
 669		if (chip->mgr->is_hr_stereo)
 670			hr222_set_audio_source(chip);
 671		else
 672			pcxhr_set_audio_source(chip);
 673		ret = 1;
 674	}
 675	return ret;
 676}
 677
 678static const struct snd_kcontrol_new pcxhr_control_audio_src = {
 679	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 680	.name =		"Capture Source",
 681	.info =		pcxhr_audio_src_info,
 682	.get =		pcxhr_audio_src_get,
 683	.put =		pcxhr_audio_src_put,
 684};
 685
 686
 687/*
 688 * clock type selection
 689 * enum pcxhr_clock_type {
 690 *	PCXHR_CLOCK_TYPE_INTERNAL = 0,
 691 *	PCXHR_CLOCK_TYPE_WORD_CLOCK,
 692 *	PCXHR_CLOCK_TYPE_AES_SYNC,
 693 *	PCXHR_CLOCK_TYPE_AES_1,
 694 *	PCXHR_CLOCK_TYPE_AES_2,
 695 *	PCXHR_CLOCK_TYPE_AES_3,
 696 *	PCXHR_CLOCK_TYPE_AES_4,
 697 *	PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
 698 *	HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
 699 *	HR22_CLOCK_TYPE_AES_SYNC,
 700 *	HR22_CLOCK_TYPE_AES_1,
 701 *	HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
 702 * };
 703 */
 704
 705static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
 706				 struct snd_ctl_elem_info *uinfo)
 707{
 708	static const char *textsPCXHR[7] = {
 709		"Internal", "WordClock", "AES Sync",
 710		"AES 1", "AES 2", "AES 3", "AES 4"
 711	};
 712	static const char *textsHR22[3] = {
 713		"Internal", "AES Sync", "AES 1"
 714	};
 715	const char **texts;
 716	struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
 717	int clock_items = 2;	/* at least Internal and AES Sync clock */
 718	if (mgr->board_has_aes1) {
 719		clock_items += mgr->capture_chips;	/* add AES x */
 720		if (!mgr->is_hr_stereo)
 721			clock_items += 1;		/* add word clock */
 722	}
 723	if (mgr->is_hr_stereo) {
 724		texts = textsHR22;
 725		snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1));
 726	} else {
 727		texts = textsPCXHR;
 728		snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
 729	}
 730	return snd_ctl_enum_info(uinfo, 1, clock_items, texts);
 731}
 732
 733static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
 734				struct snd_ctl_elem_value *ucontrol)
 735{
 736	struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
 737	ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
 738	return 0;
 739}
 740
 741static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
 742				struct snd_ctl_elem_value *ucontrol)
 743{
 744	struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
 745	int rate, ret = 0;
 746	unsigned int clock_items = 2; /* at least Internal and AES Sync clock */
 747	if (mgr->board_has_aes1) {
 748		clock_items += mgr->capture_chips;	/* add AES x */
 749		if (!mgr->is_hr_stereo)
 750			clock_items += 1;		/* add word clock */
 751	}
 752	if (ucontrol->value.enumerated.item[0] >= clock_items)
 753		return -EINVAL;
 754	guard(mutex)(&mgr->mixer_mutex);
 755	if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
 756		guard(mutex)(&mgr->setup_mutex);
 757		mgr->use_clock_type = ucontrol->value.enumerated.item[0];
 758		rate = 0;
 759		if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) {
 760			pcxhr_get_external_clock(mgr, mgr->use_clock_type,
 761						 &rate);
 762		} else {
 763			rate = mgr->sample_rate;
 764			if (!rate)
 765				rate = 48000;
 766		}
 767		if (rate) {
 768			pcxhr_set_clock(mgr, rate);
 769			if (mgr->sample_rate)
 770				mgr->sample_rate = rate;
 771		}
 772		ret = 1; /* return 1 even if the set was not done. ok ? */
 773	}
 774	return ret;
 775}
 776
 777static const struct snd_kcontrol_new pcxhr_control_clock_type = {
 778	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
 779	.name =		"Clock Mode",
 780	.info =		pcxhr_clock_type_info,
 781	.get =		pcxhr_clock_type_get,
 782	.put =		pcxhr_clock_type_put,
 783};
 784
 785/*
 786 * clock rate control
 787 * specific control that scans the sample rates on the external plugs
 788 */
 789static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
 790				 struct snd_ctl_elem_info *uinfo)
 791{
 792	struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
 793	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 794	uinfo->count = 3 + mgr->capture_chips;
 795	uinfo->value.integer.min = 0;		/* clock not present */
 796	uinfo->value.integer.max = 192000;	/* max sample rate 192 kHz */
 797	return 0;
 798}
 799
 800static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
 801				struct snd_ctl_elem_value *ucontrol)
 802{
 803	struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
 804	int i, err, rate;
 805
 806	guard(mutex)(&mgr->mixer_mutex);
 807	for(i = 0; i < 3 + mgr->capture_chips; i++) {
 808		if (i == PCXHR_CLOCK_TYPE_INTERNAL)
 809			rate = mgr->sample_rate_real;
 810		else {
 811			err = pcxhr_get_external_clock(mgr, i, &rate);
 812			if (err)
 813				break;
 814		}
 815		ucontrol->value.integer.value[i] = rate;
 816	}
 817	return 0;
 818}
 819
 820static const struct snd_kcontrol_new pcxhr_control_clock_rate = {
 821	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
 822	.iface =	SNDRV_CTL_ELEM_IFACE_CARD,
 823	.name =		"Clock Rates",
 824	.info =		pcxhr_clock_rate_info,
 825	.get =		pcxhr_clock_rate_get,
 826};
 827
 828/*
 829 * IEC958 status bits
 830 */
 831static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
 832			     struct snd_ctl_elem_info *uinfo)
 833{
 834	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
 835	uinfo->count = 1;
 836	return 0;
 837}
 838
 839static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
 840				     int aes_idx, unsigned char *aes_bits)
 841{
 842	int i, err;
 843	unsigned char temp;
 844	struct pcxhr_rmh rmh;
 845
 846	pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
 847	rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
 848	switch (chip->chip_idx) {
 849	  /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
 850	case 0:	rmh.cmd[1] = CS8420_01_CS; break;
 851	case 1:	rmh.cmd[1] = CS8420_23_CS; break;
 852	case 2:	rmh.cmd[1] = CS8420_45_CS; break;
 853	case 3:	rmh.cmd[1] = CS8420_67_CS; break;
 854	default: return -EINVAL;
 855	}
 856	if (chip->mgr->board_aes_in_192k) {
 857		switch (aes_idx) {
 858		case 0:	rmh.cmd[2] = CS8416_CSB0; break;
 859		case 1:	rmh.cmd[2] = CS8416_CSB1; break;
 860		case 2:	rmh.cmd[2] = CS8416_CSB2; break;
 861		case 3:	rmh.cmd[2] = CS8416_CSB3; break;
 862		case 4:	rmh.cmd[2] = CS8416_CSB4; break;
 863		default: return -EINVAL;
 864		}
 865	} else {
 866		switch (aes_idx) {
 867		  /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
 868		case 0:	rmh.cmd[2] = CS8420_CSB0; break;
 869		case 1:	rmh.cmd[2] = CS8420_CSB1; break;
 870		case 2:	rmh.cmd[2] = CS8420_CSB2; break;
 871		case 3:	rmh.cmd[2] = CS8420_CSB3; break;
 872		case 4:	rmh.cmd[2] = CS8420_CSB4; break;
 873		default: return -EINVAL;
 874		}
 875	}
 876	/* size and code the chip id for the fpga */
 877	rmh.cmd[1] &= 0x0fffff;
 878	/* chip signature + map for spi read */
 879	rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
 880	rmh.cmd_len = 3;
 881	err = pcxhr_send_msg(chip->mgr, &rmh);
 882	if (err)
 883		return err;
 884
 885	if (chip->mgr->board_aes_in_192k) {
 886		temp = (unsigned char)rmh.stat[1];
 887	} else {
 888		temp = 0;
 889		/* reversed bit order (not with CS8416_01_CS) */
 890		for (i = 0; i < 8; i++) {
 891			temp <<= 1;
 892			if (rmh.stat[1] & (1 << i))
 893				temp |= 1;
 894		}
 895	}
 896	dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n",
 897		    chip->chip_idx, aes_idx, temp);
 898	*aes_bits = temp;
 899	return 0;
 900}
 901
 902static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
 903			    struct snd_ctl_elem_value *ucontrol)
 904{
 905	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 906	unsigned char aes_bits;
 907	int i, err;
 908
 909	guard(mutex)(&chip->mgr->mixer_mutex);
 910	for(i = 0; i < 5; i++) {
 911		if (kcontrol->private_value == 0)	/* playback */
 912			aes_bits = chip->aes_bits[i];
 913		else {				/* capture */
 914			if (chip->mgr->is_hr_stereo)
 915				err = hr222_iec958_capture_byte(chip, i,
 916								&aes_bits);
 917			else
 918				err = pcxhr_iec958_capture_byte(chip, i,
 919								&aes_bits);
 920			if (err)
 921				break;
 922		}
 923		ucontrol->value.iec958.status[i] = aes_bits;
 924	}
 925        return 0;
 926}
 927
 928static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
 929				 struct snd_ctl_elem_value *ucontrol)
 930{
 931	int i;
 932	for (i = 0; i < 5; i++)
 933		ucontrol->value.iec958.status[i] = 0xff;
 934        return 0;
 935}
 936
 937static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
 938				    int aes_idx, unsigned char aes_bits)
 939{
 940	int i, err, cmd;
 941	unsigned char new_bits = aes_bits;
 942	unsigned char old_bits = chip->aes_bits[aes_idx];
 943	struct pcxhr_rmh rmh;
 944
 945	for (i = 0; i < 8; i++) {
 946		if ((old_bits & 0x01) != (new_bits & 0x01)) {
 947			cmd = chip->chip_idx & 0x03;      /* chip index 0..3 */
 948			if (chip->chip_idx > 3)
 949				/* new bit used if chip_idx>3 (PCX1222HR) */
 950				cmd |= 1 << 22;
 951			cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
 952			cmd |= (new_bits & 0x01) << 23;   /* add bit value */
 953			pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
 954			rmh.cmd[0] |= IO_NUM_REG_CUER;
 955			rmh.cmd[1] = cmd;
 956			rmh.cmd_len = 2;
 957			dev_dbg(chip->card->dev,
 958				"write iec958 AES %d byte %d bit %d (cmd %x)\n",
 959				    chip->chip_idx, aes_idx, i, cmd);
 960			err = pcxhr_send_msg(chip->mgr, &rmh);
 961			if (err)
 962				return err;
 963		}
 964		old_bits >>= 1;
 965		new_bits >>= 1;
 966	}
 967	chip->aes_bits[aes_idx] = aes_bits;
 968	return 0;
 969}
 970
 971static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
 972			    struct snd_ctl_elem_value *ucontrol)
 973{
 974	struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
 975	int i, changed = 0;
 976
 977	/* playback */
 978	guard(mutex)(&chip->mgr->mixer_mutex);
 979	for (i = 0; i < 5; i++) {
 980		if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
 981			if (chip->mgr->is_hr_stereo)
 982				hr222_iec958_update_byte(chip, i,
 983					ucontrol->value.iec958.status[i]);
 984			else
 985				pcxhr_iec958_update_byte(chip, i,
 986					ucontrol->value.iec958.status[i]);
 987			changed = 1;
 988		}
 989	}
 990	return changed;
 991}
 992
 993static const struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
 994	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
 995	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
 996	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
 997	.info =		pcxhr_iec958_info,
 998	.get =		pcxhr_iec958_mask_get
 999};
1000static const struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
1001	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1002	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1003	.info =         pcxhr_iec958_info,
1004	.get =          pcxhr_iec958_get,
1005	.put =          pcxhr_iec958_put,
1006	.private_value = 0 /* playback */
1007};
1008
1009static const struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
1010	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
1011	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1012	.name =		SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
1013	.info =		pcxhr_iec958_info,
1014	.get =		pcxhr_iec958_mask_get
1015};
1016static const struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
1017	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
1018	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1019	.name =         SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1020	.info =         pcxhr_iec958_info,
1021	.get =          pcxhr_iec958_get,
1022	.private_value = 1 /* capture */
1023};
1024
1025static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
1026{
1027	int i;
1028
1029	for (i = 0; i < 2; i++) {
1030		if (chip->nb_streams_play) {
1031			int j;
1032			/* at boot time the digital volumes are unmuted 0dB */
1033			for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
1034				chip->digital_playback_active[j][i] = 1;
1035				chip->digital_playback_volume[j][i] =
1036					PCXHR_DIGITAL_ZERO_LEVEL;
1037			}
1038			/* after boot, only two bits are set on the uer
1039			 * interface
1040			 */
1041			chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
1042					     IEC958_AES0_PRO_FS_48000);
1043#ifdef CONFIG_SND_DEBUG
1044			/* analog volumes for playback
1045			 * (is LEVEL_MIN after boot)
1046			 */
1047			chip->analog_playback_active[i] = 1;
1048			if (chip->mgr->is_hr_stereo)
1049				chip->analog_playback_volume[i] =
1050					HR222_LINE_PLAYBACK_ZERO_LEVEL;
1051			else {
1052				chip->analog_playback_volume[i] =
1053					PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
1054				pcxhr_update_analog_audio_level(chip, 0, i);
1055			}
1056#endif
1057			/* stereo cards need to be initialised after boot */
1058			if (chip->mgr->is_hr_stereo)
1059				hr222_update_analog_audio_level(chip, 0, i);
1060		}
1061		if (chip->nb_streams_capt) {
1062			/* at boot time the digital volumes are unmuted 0dB */
1063			chip->digital_capture_volume[i] =
1064				PCXHR_DIGITAL_ZERO_LEVEL;
1065			chip->analog_capture_active = 1;
1066#ifdef CONFIG_SND_DEBUG
1067			/* analog volumes for playback
1068			 * (is LEVEL_MIN after boot)
1069			 */
1070			if (chip->mgr->is_hr_stereo)
1071				chip->analog_capture_volume[i] =
1072					HR222_LINE_CAPTURE_ZERO_LEVEL;
1073			else {
1074				chip->analog_capture_volume[i] =
1075					PCXHR_LINE_CAPTURE_ZERO_LEVEL;
1076				pcxhr_update_analog_audio_level(chip, 1, i);
1077			}
1078#endif
1079			/* stereo cards need to be initialised after boot */
1080			if (chip->mgr->is_hr_stereo)
1081				hr222_update_analog_audio_level(chip, 1, i);
1082		}
1083	}
1084
1085	return;
1086}
1087
1088
1089int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
1090{
1091	struct snd_pcxhr *chip;
1092	int err, i;
1093
1094	mutex_init(&mgr->mixer_mutex); /* can be in another place */
1095
1096	for (i = 0; i < mgr->num_cards; i++) {
1097		struct snd_kcontrol_new temp;
1098		chip = mgr->chip[i];
1099
1100		if (chip->nb_streams_play) {
1101			/* analog output level control */
1102			temp = pcxhr_control_analog_level;
1103			temp.name = "Master Playback Volume";
1104			temp.private_value = 0; /* playback */
1105			if (mgr->is_hr_stereo)
1106				temp.tlv.p = db_scale_a_hr222_playback;
1107			else
1108				temp.tlv.p = db_scale_analog_playback;
1109			err = snd_ctl_add(chip->card,
1110					  snd_ctl_new1(&temp, chip));
1111			if (err < 0)
1112				return err;
1113
1114			/* output mute controls */
1115			err = snd_ctl_add(chip->card,
1116				snd_ctl_new1(&pcxhr_control_output_switch,
1117					     chip));
1118			if (err < 0)
1119				return err;
1120
1121			temp = snd_pcxhr_pcm_vol;
1122			temp.name = "PCM Playback Volume";
1123			temp.count = PCXHR_PLAYBACK_STREAMS;
1124			temp.private_value = 0; /* playback */
1125			err = snd_ctl_add(chip->card,
1126					  snd_ctl_new1(&temp, chip));
1127			if (err < 0)
1128				return err;
1129
1130			err = snd_ctl_add(chip->card,
1131				snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
1132			if (err < 0)
1133				return err;
1134
1135			/* IEC958 controls */
1136			err = snd_ctl_add(chip->card,
1137				snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
1138					     chip));
1139			if (err < 0)
1140				return err;
1141
1142			err = snd_ctl_add(chip->card,
1143				snd_ctl_new1(&pcxhr_control_playback_iec958,
1144					     chip));
1145			if (err < 0)
1146				return err;
1147		}
1148		if (chip->nb_streams_capt) {
1149			/* analog input level control */
1150			temp = pcxhr_control_analog_level;
1151			temp.name = "Line Capture Volume";
1152			temp.private_value = 1; /* capture */
1153			if (mgr->is_hr_stereo)
1154				temp.tlv.p = db_scale_a_hr222_capture;
1155			else
1156				temp.tlv.p = db_scale_analog_capture;
1157
1158			err = snd_ctl_add(chip->card,
1159					  snd_ctl_new1(&temp, chip));
1160			if (err < 0)
1161				return err;
1162
1163			temp = snd_pcxhr_pcm_vol;
1164			temp.name = "PCM Capture Volume";
1165			temp.count = 1;
1166			temp.private_value = 1; /* capture */
1167
1168			err = snd_ctl_add(chip->card,
1169					  snd_ctl_new1(&temp, chip));
1170			if (err < 0)
1171				return err;
1172
1173			/* Audio source */
1174			err = snd_ctl_add(chip->card,
1175				snd_ctl_new1(&pcxhr_control_audio_src, chip));
1176			if (err < 0)
1177				return err;
1178
1179			/* IEC958 controls */
1180			err = snd_ctl_add(chip->card,
1181				snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1182					     chip));
1183			if (err < 0)
1184				return err;
1185
1186			err = snd_ctl_add(chip->card,
1187				snd_ctl_new1(&pcxhr_control_capture_iec958,
1188					     chip));
1189			if (err < 0)
1190				return err;
1191
1192			if (mgr->is_hr_stereo) {
1193				err = hr222_add_mic_controls(chip);
1194				if (err < 0)
1195					return err;
1196			}
1197		}
1198		/* monitoring only if playback and capture device available */
1199		if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1200			/* monitoring */
1201			err = snd_ctl_add(chip->card,
1202				snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
1203			if (err < 0)
1204				return err;
1205
1206			err = snd_ctl_add(chip->card,
1207				snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
1208			if (err < 0)
1209				return err;
1210		}
1211
1212		if (i == 0) {
1213			/* clock mode only one control per pcxhr */
1214			err = snd_ctl_add(chip->card,
1215				snd_ctl_new1(&pcxhr_control_clock_type, mgr));
1216			if (err < 0)
1217				return err;
1218			/* non standard control used to scan
1219			 * the external clock presence/frequencies
1220			 */
1221			err = snd_ctl_add(chip->card,
1222				snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
1223			if (err < 0)
1224				return err;
1225		}
1226
1227		/* init values for the mixer data */
1228		pcxhr_init_audio_levels(chip);
1229	}
1230
1231	return 0;
1232}
~/ Read-only file preview.