pcxhr_mixer.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. #define __NO_VERSION__
  2. /*
  3. * Driver for Digigram pcxhr compatible soundcards
  4. *
  5. * mixer callbacks
  6. *
  7. * Copyright (c) 2004 by Digigram <alsa@digigram.com>
  8. *
  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.
  13. *
  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.
  18. *
  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
  22. */
  23. #include <sound/driver.h>
  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. #define PCXHR_ANALOG_CAPTURE_LEVEL_MIN 0 /* -96.0 dB */
  37. #define PCXHR_ANALOG_CAPTURE_LEVEL_MAX 255 /* +31.5 dB */
  38. #define PCXHR_ANALOG_CAPTURE_ZERO_LEVEL 224 /* +16.0 dB ( +31.5 dB - fix level +15.5 dB ) */
  39. #define PCXHR_ANALOG_PLAYBACK_LEVEL_MIN 0 /* -128.0 dB */
  40. #define PCXHR_ANALOG_PLAYBACK_LEVEL_MAX 128 /* 0.0 dB */
  41. #define PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL 104 /* -24.0 dB ( 0.0 dB - fix level +24.0 dB ) */
  42. static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -9600, 50, 3150);
  43. static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400);
  44. static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_capture, int channel)
  45. {
  46. int err, vol;
  47. struct pcxhr_rmh rmh;
  48. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
  49. if (is_capture) {
  50. rmh.cmd[0] |= IO_NUM_REG_IN_ANA_LEVEL;
  51. rmh.cmd[2] = chip->analog_capture_volume[channel];
  52. } else {
  53. rmh.cmd[0] |= IO_NUM_REG_OUT_ANA_LEVEL;
  54. if (chip->analog_playback_active[channel])
  55. vol = chip->analog_playback_volume[channel];
  56. else
  57. vol = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN;
  58. rmh.cmd[2] = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX - vol; /* playback analog levels are inversed */
  59. }
  60. rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */
  61. rmh.cmd_len = 3;
  62. err = pcxhr_send_msg(chip->mgr, &rmh);
  63. if (err < 0) {
  64. snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d) "
  65. "is_capture(%d) err(%x)\n", chip->chip_idx, is_capture, err);
  66. return -EINVAL;
  67. }
  68. return 0;
  69. }
  70. /*
  71. * analog level control
  72. */
  73. static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
  74. struct snd_ctl_elem_info *uinfo)
  75. {
  76. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  77. uinfo->count = 2;
  78. if (kcontrol->private_value == 0) { /* playback */
  79. uinfo->value.integer.min = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN; /* -128 dB */
  80. uinfo->value.integer.max = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX; /* 0 dB */
  81. } else { /* capture */
  82. uinfo->value.integer.min = PCXHR_ANALOG_CAPTURE_LEVEL_MIN; /* -96 dB */
  83. uinfo->value.integer.max = PCXHR_ANALOG_CAPTURE_LEVEL_MAX; /* 31.5 dB */
  84. }
  85. return 0;
  86. }
  87. static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
  88. struct snd_ctl_elem_value *ucontrol)
  89. {
  90. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  91. mutex_lock(&chip->mgr->mixer_mutex);
  92. if (kcontrol->private_value == 0) { /* playback */
  93. ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
  94. ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
  95. } else { /* capture */
  96. ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
  97. ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
  98. }
  99. mutex_unlock(&chip->mgr->mixer_mutex);
  100. return 0;
  101. }
  102. static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
  103. struct snd_ctl_elem_value *ucontrol)
  104. {
  105. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  106. int changed = 0;
  107. int is_capture, i;
  108. mutex_lock(&chip->mgr->mixer_mutex);
  109. is_capture = (kcontrol->private_value != 0);
  110. for (i = 0; i < 2; i++) {
  111. int new_volume = ucontrol->value.integer.value[i];
  112. int* stored_volume = is_capture ? &chip->analog_capture_volume[i] :
  113. &chip->analog_playback_volume[i];
  114. if (*stored_volume != new_volume) {
  115. *stored_volume = new_volume;
  116. changed = 1;
  117. pcxhr_update_analog_audio_level(chip, is_capture, i);
  118. }
  119. }
  120. mutex_unlock(&chip->mgr->mixer_mutex);
  121. return changed;
  122. }
  123. static struct snd_kcontrol_new pcxhr_control_analog_level = {
  124. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  125. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  126. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  127. /* name will be filled later */
  128. .info = pcxhr_analog_vol_info,
  129. .get = pcxhr_analog_vol_get,
  130. .put = pcxhr_analog_vol_put,
  131. /* tlv will be filled later */
  132. };
  133. /* shared */
  134. #define pcxhr_sw_info snd_ctl_boolean_stereo_info
  135. static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
  136. struct snd_ctl_elem_value *ucontrol)
  137. {
  138. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  139. mutex_lock(&chip->mgr->mixer_mutex);
  140. ucontrol->value.integer.value[0] = chip->analog_playback_active[0];
  141. ucontrol->value.integer.value[1] = chip->analog_playback_active[1];
  142. mutex_unlock(&chip->mgr->mixer_mutex);
  143. return 0;
  144. }
  145. static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
  146. struct snd_ctl_elem_value *ucontrol)
  147. {
  148. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  149. int i, changed = 0;
  150. mutex_lock(&chip->mgr->mixer_mutex);
  151. for(i = 0; i < 2; i++) {
  152. if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) {
  153. chip->analog_playback_active[i] = ucontrol->value.integer.value[i];
  154. changed = 1;
  155. pcxhr_update_analog_audio_level(chip, 0, i); /* update playback levels */
  156. }
  157. }
  158. mutex_unlock(&chip->mgr->mixer_mutex);
  159. return changed;
  160. }
  161. static struct snd_kcontrol_new pcxhr_control_output_switch = {
  162. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  163. .name = "Master Playback Switch",
  164. .info = pcxhr_sw_info, /* shared */
  165. .get = pcxhr_audio_sw_get,
  166. .put = pcxhr_audio_sw_put
  167. };
  168. #define PCXHR_DIGITAL_LEVEL_MIN 0x000 /* -110 dB */
  169. #define PCXHR_DIGITAL_LEVEL_MAX 0x1ff /* +18 dB */
  170. #define PCXHR_DIGITAL_ZERO_LEVEL 0x1b7 /* 0 dB */
  171. static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10975, 25, 1800);
  172. #define MORE_THAN_ONE_STREAM_LEVEL 0x000001
  173. #define VALID_STREAM_PAN_LEVEL_MASK 0x800000
  174. #define VALID_STREAM_LEVEL_MASK 0x400000
  175. #define VALID_STREAM_LEVEL_1_MASK 0x200000
  176. #define VALID_STREAM_LEVEL_2_MASK 0x100000
  177. static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
  178. {
  179. int err;
  180. struct pcxhr_rmh rmh;
  181. struct pcxhr_pipe *pipe = &chip->playback_pipe;
  182. int left, right;
  183. if (chip->digital_playback_active[idx][0])
  184. left = chip->digital_playback_volume[idx][0];
  185. else
  186. left = PCXHR_DIGITAL_LEVEL_MIN;
  187. if (chip->digital_playback_active[idx][1])
  188. right = chip->digital_playback_volume[idx][1];
  189. else
  190. right = PCXHR_DIGITAL_LEVEL_MIN;
  191. pcxhr_init_rmh(&rmh, CMD_STREAM_OUT_LEVEL_ADJUST);
  192. /* add pipe and stream mask */
  193. pcxhr_set_pipe_cmd_params(&rmh, 0, pipe->first_audio, 0, 1<<idx);
  194. /* volume left->left / right->right panoramic level */
  195. rmh.cmd[0] |= MORE_THAN_ONE_STREAM_LEVEL;
  196. rmh.cmd[2] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_1_MASK;
  197. rmh.cmd[2] |= (left << 10);
  198. rmh.cmd[3] = VALID_STREAM_PAN_LEVEL_MASK | VALID_STREAM_LEVEL_2_MASK;
  199. rmh.cmd[3] |= right;
  200. rmh.cmd_len = 4;
  201. err = pcxhr_send_msg(chip->mgr, &rmh);
  202. if (err < 0) {
  203. snd_printk(KERN_DEBUG "error update_playback_stream_level "
  204. "card(%d) err(%x)\n", chip->chip_idx, err);
  205. return -EINVAL;
  206. }
  207. return 0;
  208. }
  209. #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
  210. #define AUDIO_IO_HAS_MUTE_MONITOR_1 0x200000
  211. #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x000001
  212. #define VALID_AUDIO_IO_MONITOR_LEVEL 0x000002
  213. #define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
  214. #define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
  215. static int pcxhr_update_audio_pipe_level(struct snd_pcxhr* chip, int capture, int channel)
  216. {
  217. int err;
  218. struct pcxhr_rmh rmh;
  219. struct pcxhr_pipe *pipe;
  220. if (capture)
  221. pipe = &chip->capture_pipe[0];
  222. else
  223. pipe = &chip->playback_pipe;
  224. pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
  225. /* add channel mask */
  226. pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0, 1 << (channel + pipe->first_audio));
  227. /* TODO : if mask (3 << pipe->first_audio) is used, left and right channel
  228. * will be programmed to the same params
  229. */
  230. if (capture) {
  231. rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
  232. /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled (capture pipe level) */
  233. rmh.cmd[2] = chip->digital_capture_volume[channel];
  234. } else {
  235. rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL | VALID_AUDIO_IO_MUTE_MONITOR_1;
  236. /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL not yet
  237. * handled (playback pipe level)
  238. */
  239. rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
  240. if (chip->monitoring_active[channel] == 0)
  241. rmh.cmd[2] |= AUDIO_IO_HAS_MUTE_MONITOR_1;
  242. }
  243. rmh.cmd_len = 3;
  244. err = pcxhr_send_msg(chip->mgr, &rmh);
  245. if(err<0) {
  246. snd_printk(KERN_DEBUG "error update_audio_level card(%d) err(%x)\n",
  247. chip->chip_idx, err);
  248. return -EINVAL;
  249. }
  250. return 0;
  251. }
  252. /* shared */
  253. static int pcxhr_digital_vol_info(struct snd_kcontrol *kcontrol,
  254. struct snd_ctl_elem_info *uinfo)
  255. {
  256. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  257. uinfo->count = 2;
  258. uinfo->value.integer.min = PCXHR_DIGITAL_LEVEL_MIN; /* -109.5 dB */
  259. uinfo->value.integer.max = PCXHR_DIGITAL_LEVEL_MAX; /* 18.0 dB */
  260. return 0;
  261. }
  262. static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
  263. struct snd_ctl_elem_value *ucontrol)
  264. {
  265. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  266. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
  267. int *stored_volume;
  268. int is_capture = kcontrol->private_value;
  269. mutex_lock(&chip->mgr->mixer_mutex);
  270. if (is_capture)
  271. stored_volume = chip->digital_capture_volume; /* digital capture */
  272. else
  273. stored_volume = chip->digital_playback_volume[idx]; /* digital playback */
  274. ucontrol->value.integer.value[0] = stored_volume[0];
  275. ucontrol->value.integer.value[1] = stored_volume[1];
  276. mutex_unlock(&chip->mgr->mixer_mutex);
  277. return 0;
  278. }
  279. static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
  280. struct snd_ctl_elem_value *ucontrol)
  281. {
  282. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  283. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
  284. int changed = 0;
  285. int is_capture = kcontrol->private_value;
  286. int *stored_volume;
  287. int i;
  288. mutex_lock(&chip->mgr->mixer_mutex);
  289. if (is_capture)
  290. stored_volume = chip->digital_capture_volume; /* digital capture */
  291. else
  292. stored_volume = chip->digital_playback_volume[idx]; /* digital playback */
  293. for (i = 0; i < 2; i++) {
  294. if (stored_volume[i] != ucontrol->value.integer.value[i]) {
  295. stored_volume[i] = ucontrol->value.integer.value[i];
  296. changed = 1;
  297. if (is_capture) /* update capture volume */
  298. pcxhr_update_audio_pipe_level(chip, 1, i);
  299. }
  300. }
  301. if (! is_capture && changed)
  302. pcxhr_update_playback_stream_level(chip, idx); /* update playback volume */
  303. mutex_unlock(&chip->mgr->mixer_mutex);
  304. return changed;
  305. }
  306. static struct snd_kcontrol_new snd_pcxhr_pcm_vol =
  307. {
  308. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  309. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  310. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  311. /* name will be filled later */
  312. /* count will be filled later */
  313. .info = pcxhr_digital_vol_info, /* shared */
  314. .get = pcxhr_pcm_vol_get,
  315. .put = pcxhr_pcm_vol_put,
  316. .tlv = { .p = db_scale_digital },
  317. };
  318. static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
  319. struct snd_ctl_elem_value *ucontrol)
  320. {
  321. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  322. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
  323. mutex_lock(&chip->mgr->mixer_mutex);
  324. ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0];
  325. ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1];
  326. mutex_unlock(&chip->mgr->mixer_mutex);
  327. return 0;
  328. }
  329. static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  330. {
  331. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  332. int changed = 0;
  333. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
  334. int i, j;
  335. mutex_lock(&chip->mgr->mixer_mutex);
  336. j = idx;
  337. for (i = 0; i < 2; i++) {
  338. if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) {
  339. chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i];
  340. changed = 1;
  341. }
  342. }
  343. if (changed)
  344. pcxhr_update_playback_stream_level(chip, idx);
  345. mutex_unlock(&chip->mgr->mixer_mutex);
  346. return changed;
  347. }
  348. static struct snd_kcontrol_new pcxhr_control_pcm_switch = {
  349. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  350. .name = "PCM Playback Switch",
  351. .count = PCXHR_PLAYBACK_STREAMS,
  352. .info = pcxhr_sw_info, /* shared */
  353. .get = pcxhr_pcm_sw_get,
  354. .put = pcxhr_pcm_sw_put
  355. };
  356. /*
  357. * monitoring level control
  358. */
  359. static int pcxhr_monitor_vol_get(struct snd_kcontrol *kcontrol,
  360. struct snd_ctl_elem_value *ucontrol)
  361. {
  362. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  363. mutex_lock(&chip->mgr->mixer_mutex);
  364. ucontrol->value.integer.value[0] = chip->monitoring_volume[0];
  365. ucontrol->value.integer.value[1] = chip->monitoring_volume[1];
  366. mutex_unlock(&chip->mgr->mixer_mutex);
  367. return 0;
  368. }
  369. static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
  370. struct snd_ctl_elem_value *ucontrol)
  371. {
  372. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  373. int changed = 0;
  374. int i;
  375. mutex_lock(&chip->mgr->mixer_mutex);
  376. for (i = 0; i < 2; i++) {
  377. if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) {
  378. chip->monitoring_volume[i] = ucontrol->value.integer.value[i];
  379. if(chip->monitoring_active[i]) /* do only when monitoring is unmuted */
  380. /* update monitoring volume and mute */
  381. pcxhr_update_audio_pipe_level(chip, 0, i);
  382. changed = 1;
  383. }
  384. }
  385. mutex_unlock(&chip->mgr->mixer_mutex);
  386. return changed;
  387. }
  388. static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
  389. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  390. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  391. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  392. .name = "Monitoring Volume",
  393. .info = pcxhr_digital_vol_info, /* shared */
  394. .get = pcxhr_monitor_vol_get,
  395. .put = pcxhr_monitor_vol_put,
  396. .tlv = { .p = db_scale_digital },
  397. };
  398. /*
  399. * monitoring switch control
  400. */
  401. static int pcxhr_monitor_sw_get(struct snd_kcontrol *kcontrol,
  402. struct snd_ctl_elem_value *ucontrol)
  403. {
  404. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  405. mutex_lock(&chip->mgr->mixer_mutex);
  406. ucontrol->value.integer.value[0] = chip->monitoring_active[0];
  407. ucontrol->value.integer.value[1] = chip->monitoring_active[1];
  408. mutex_unlock(&chip->mgr->mixer_mutex);
  409. return 0;
  410. }
  411. static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *ucontrol)
  413. {
  414. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  415. int changed = 0;
  416. int i;
  417. mutex_lock(&chip->mgr->mixer_mutex);
  418. for (i = 0; i < 2; i++) {
  419. if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) {
  420. chip->monitoring_active[i] = ucontrol->value.integer.value[i];
  421. changed |= (1<<i); /* mask 0x01 and 0x02 */
  422. }
  423. }
  424. if(changed & 0x01)
  425. /* update left monitoring volume and mute */
  426. pcxhr_update_audio_pipe_level(chip, 0, 0);
  427. if(changed & 0x02)
  428. /* update right monitoring volume and mute */
  429. pcxhr_update_audio_pipe_level(chip, 0, 1);
  430. mutex_unlock(&chip->mgr->mixer_mutex);
  431. return (changed != 0);
  432. }
  433. static struct snd_kcontrol_new pcxhr_control_monitor_sw = {
  434. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  435. .name = "Monitoring Switch",
  436. .info = pcxhr_sw_info, /* shared */
  437. .get = pcxhr_monitor_sw_get,
  438. .put = pcxhr_monitor_sw_put
  439. };
  440. /*
  441. * audio source select
  442. */
  443. #define PCXHR_SOURCE_AUDIO01_UER 0x000100
  444. #define PCXHR_SOURCE_AUDIO01_SYNC 0x000200
  445. #define PCXHR_SOURCE_AUDIO23_UER 0x000400
  446. #define PCXHR_SOURCE_AUDIO45_UER 0x001000
  447. #define PCXHR_SOURCE_AUDIO67_UER 0x040000
  448. static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
  449. {
  450. struct pcxhr_rmh rmh;
  451. unsigned int mask, reg;
  452. unsigned int codec;
  453. int err, use_src, changed;
  454. switch (chip->chip_idx) {
  455. case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
  456. case 1 : mask = PCXHR_SOURCE_AUDIO23_UER; codec = CS8420_23_CS; break;
  457. case 2 : mask = PCXHR_SOURCE_AUDIO45_UER; codec = CS8420_45_CS; break;
  458. case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
  459. default: return -EINVAL;
  460. }
  461. reg = 0; /* audio source from analog plug */
  462. use_src = 0; /* do not activate codec SRC */
  463. if (chip->audio_capture_source != 0) {
  464. reg = mask; /* audio source from digital plug */
  465. if (chip->audio_capture_source == 2)
  466. use_src = 1;
  467. }
  468. /* set the input source */
  469. pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
  470. /* resync them (otherwise channel inversion possible) */
  471. if (changed) {
  472. pcxhr_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS);
  473. rmh.cmd[0] |= (1 << chip->chip_idx);
  474. err = pcxhr_send_msg(chip->mgr, &rmh);
  475. if (err)
  476. return err;
  477. }
  478. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* set codec SRC on off */
  479. rmh.cmd_len = 3;
  480. rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
  481. rmh.cmd[1] = codec;
  482. rmh.cmd[2] = (CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x54);
  483. err = pcxhr_send_msg(chip->mgr, &rmh);
  484. if(err)
  485. return err;
  486. rmh.cmd[2] = (CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x49);
  487. err = pcxhr_send_msg(chip->mgr, &rmh);
  488. return err;
  489. }
  490. static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
  491. struct snd_ctl_elem_info *uinfo)
  492. {
  493. static char *texts[3] = {"Analog", "Digital", "Digi+SRC"};
  494. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  495. uinfo->count = 1;
  496. uinfo->value.enumerated.items = 3;
  497. if (uinfo->value.enumerated.item > 2)
  498. uinfo->value.enumerated.item = 2;
  499. strcpy(uinfo->value.enumerated.name,
  500. texts[uinfo->value.enumerated.item]);
  501. return 0;
  502. }
  503. static int pcxhr_audio_src_get(struct snd_kcontrol *kcontrol,
  504. struct snd_ctl_elem_value *ucontrol)
  505. {
  506. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  507. ucontrol->value.enumerated.item[0] = chip->audio_capture_source;
  508. return 0;
  509. }
  510. static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
  511. struct snd_ctl_elem_value *ucontrol)
  512. {
  513. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  514. int ret = 0;
  515. mutex_lock(&chip->mgr->mixer_mutex);
  516. if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
  517. chip->audio_capture_source = ucontrol->value.enumerated.item[0];
  518. pcxhr_set_audio_source(chip);
  519. ret = 1;
  520. }
  521. mutex_unlock(&chip->mgr->mixer_mutex);
  522. return ret;
  523. }
  524. static struct snd_kcontrol_new pcxhr_control_audio_src = {
  525. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  526. .name = "Capture Source",
  527. .info = pcxhr_audio_src_info,
  528. .get = pcxhr_audio_src_get,
  529. .put = pcxhr_audio_src_put,
  530. };
  531. /*
  532. * clock type selection
  533. * enum pcxhr_clock_type {
  534. * PCXHR_CLOCK_TYPE_INTERNAL = 0,
  535. * PCXHR_CLOCK_TYPE_WORD_CLOCK,
  536. * PCXHR_CLOCK_TYPE_AES_SYNC,
  537. * PCXHR_CLOCK_TYPE_AES_1,
  538. * PCXHR_CLOCK_TYPE_AES_2,
  539. * PCXHR_CLOCK_TYPE_AES_3,
  540. * PCXHR_CLOCK_TYPE_AES_4,
  541. * };
  542. */
  543. static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
  544. struct snd_ctl_elem_info *uinfo)
  545. {
  546. static char *texts[7] = {
  547. "Internal", "WordClock", "AES Sync", "AES 1", "AES 2", "AES 3", "AES 4"
  548. };
  549. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  550. int clock_items = 3 + mgr->capture_chips;
  551. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  552. uinfo->count = 1;
  553. uinfo->value.enumerated.items = clock_items;
  554. if (uinfo->value.enumerated.item >= clock_items)
  555. uinfo->value.enumerated.item = clock_items-1;
  556. strcpy(uinfo->value.enumerated.name,
  557. texts[uinfo->value.enumerated.item]);
  558. return 0;
  559. }
  560. static int pcxhr_clock_type_get(struct snd_kcontrol *kcontrol,
  561. struct snd_ctl_elem_value *ucontrol)
  562. {
  563. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  564. ucontrol->value.enumerated.item[0] = mgr->use_clock_type;
  565. return 0;
  566. }
  567. static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
  568. struct snd_ctl_elem_value *ucontrol)
  569. {
  570. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  571. int rate, ret = 0;
  572. mutex_lock(&mgr->mixer_mutex);
  573. if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
  574. mutex_lock(&mgr->setup_mutex);
  575. mgr->use_clock_type = ucontrol->value.enumerated.item[0];
  576. if (mgr->use_clock_type)
  577. pcxhr_get_external_clock(mgr, mgr->use_clock_type, &rate);
  578. else
  579. rate = mgr->sample_rate;
  580. if (rate) {
  581. pcxhr_set_clock(mgr, rate);
  582. if (mgr->sample_rate)
  583. mgr->sample_rate = rate;
  584. }
  585. mutex_unlock(&mgr->setup_mutex);
  586. ret = 1; /* return 1 even if the set was not done. ok ? */
  587. }
  588. mutex_unlock(&mgr->mixer_mutex);
  589. return ret;
  590. }
  591. static struct snd_kcontrol_new pcxhr_control_clock_type = {
  592. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  593. .name = "Clock Mode",
  594. .info = pcxhr_clock_type_info,
  595. .get = pcxhr_clock_type_get,
  596. .put = pcxhr_clock_type_put,
  597. };
  598. /*
  599. * clock rate control
  600. * specific control that scans the sample rates on the external plugs
  601. */
  602. static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
  603. struct snd_ctl_elem_info *uinfo)
  604. {
  605. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  606. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  607. uinfo->count = 3 + mgr->capture_chips;
  608. uinfo->value.integer.min = 0; /* clock not present */
  609. uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
  610. return 0;
  611. }
  612. static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
  613. struct snd_ctl_elem_value *ucontrol)
  614. {
  615. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  616. int i, err, rate;
  617. mutex_lock(&mgr->mixer_mutex);
  618. for(i = 0; i < 3 + mgr->capture_chips; i++) {
  619. if (i == PCXHR_CLOCK_TYPE_INTERNAL)
  620. rate = mgr->sample_rate_real;
  621. else {
  622. err = pcxhr_get_external_clock(mgr, i, &rate);
  623. if (err)
  624. break;
  625. }
  626. ucontrol->value.integer.value[i] = rate;
  627. }
  628. mutex_unlock(&mgr->mixer_mutex);
  629. return 0;
  630. }
  631. static struct snd_kcontrol_new pcxhr_control_clock_rate = {
  632. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  633. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  634. .name = "Clock Rates",
  635. .info = pcxhr_clock_rate_info,
  636. .get = pcxhr_clock_rate_get,
  637. };
  638. /*
  639. * IEC958 status bits
  640. */
  641. static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  642. {
  643. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  644. uinfo->count = 1;
  645. return 0;
  646. }
  647. static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char* aes_bits)
  648. {
  649. int i, err;
  650. unsigned char temp;
  651. struct pcxhr_rmh rmh;
  652. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
  653. rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
  654. switch (chip->chip_idx) {
  655. case 0: rmh.cmd[1] = CS8420_01_CS; break; /* use CS8416_01_CS for AES SYNC plug */
  656. case 1: rmh.cmd[1] = CS8420_23_CS; break;
  657. case 2: rmh.cmd[1] = CS8420_45_CS; break;
  658. case 3: rmh.cmd[1] = CS8420_67_CS; break;
  659. default: return -EINVAL;
  660. }
  661. switch (aes_idx) {
  662. case 0: rmh.cmd[2] = CS8420_CSB0; break; /* use CS8416_CSBx for AES SYNC plug */
  663. case 1: rmh.cmd[2] = CS8420_CSB1; break;
  664. case 2: rmh.cmd[2] = CS8420_CSB2; break;
  665. case 3: rmh.cmd[2] = CS8420_CSB3; break;
  666. case 4: rmh.cmd[2] = CS8420_CSB4; break;
  667. default: return -EINVAL;
  668. }
  669. rmh.cmd[1] &= 0x0fffff; /* size and code the chip id for the fpga */
  670. rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI; /* chip signature + map for spi read */
  671. rmh.cmd_len = 3;
  672. err = pcxhr_send_msg(chip->mgr, &rmh);
  673. if (err)
  674. return err;
  675. temp = 0;
  676. for (i = 0; i < 8; i++) {
  677. /* attention : reversed bit order (not with CS8416_01_CS) */
  678. temp <<= 1;
  679. if (rmh.stat[1] & (1 << i))
  680. temp |= 1;
  681. }
  682. snd_printdd("read iec958 AES %d byte %d = 0x%x\n", chip->chip_idx, aes_idx, temp);
  683. *aes_bits = temp;
  684. return 0;
  685. }
  686. static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  687. {
  688. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  689. unsigned char aes_bits;
  690. int i, err;
  691. mutex_lock(&chip->mgr->mixer_mutex);
  692. for(i = 0; i < 5; i++) {
  693. if (kcontrol->private_value == 0) /* playback */
  694. aes_bits = chip->aes_bits[i];
  695. else { /* capture */
  696. err = pcxhr_iec958_capture_byte(chip, i, &aes_bits);
  697. if (err)
  698. break;
  699. }
  700. ucontrol->value.iec958.status[i] = aes_bits;
  701. }
  702. mutex_unlock(&chip->mgr->mixer_mutex);
  703. return 0;
  704. }
  705. static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
  706. struct snd_ctl_elem_value *ucontrol)
  707. {
  708. int i;
  709. for (i = 0; i < 5; i++)
  710. ucontrol->value.iec958.status[i] = 0xff;
  711. return 0;
  712. }
  713. static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char aes_bits)
  714. {
  715. int i, err, cmd;
  716. unsigned char new_bits = aes_bits;
  717. unsigned char old_bits = chip->aes_bits[aes_idx];
  718. struct pcxhr_rmh rmh;
  719. for (i = 0; i < 8; i++) {
  720. if ((old_bits & 0x01) != (new_bits & 0x01)) {
  721. cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
  722. if(chip->chip_idx > 3)
  723. /* new bit used if chip_idx>3 (PCX1222HR) */
  724. cmd |= 1 << 22;
  725. cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
  726. cmd |= (new_bits & 0x01) << 23; /* add bit value */
  727. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
  728. rmh.cmd[0] |= IO_NUM_REG_CUER;
  729. rmh.cmd[1] = cmd;
  730. rmh.cmd_len = 2;
  731. snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n",
  732. chip->chip_idx, aes_idx, i, cmd);
  733. err = pcxhr_send_msg(chip->mgr, &rmh);
  734. if (err)
  735. return err;
  736. }
  737. old_bits >>= 1;
  738. new_bits >>= 1;
  739. }
  740. chip->aes_bits[aes_idx] = aes_bits;
  741. return 0;
  742. }
  743. static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
  744. struct snd_ctl_elem_value *ucontrol)
  745. {
  746. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  747. int i, changed = 0;
  748. /* playback */
  749. mutex_lock(&chip->mgr->mixer_mutex);
  750. for (i = 0; i < 5; i++) {
  751. if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
  752. pcxhr_iec958_update_byte(chip, i, ucontrol->value.iec958.status[i]);
  753. changed = 1;
  754. }
  755. }
  756. mutex_unlock(&chip->mgr->mixer_mutex);
  757. return changed;
  758. }
  759. static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
  760. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  761. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  762. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  763. .info = pcxhr_iec958_info,
  764. .get = pcxhr_iec958_mask_get
  765. };
  766. static struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
  767. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  768. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  769. .info = pcxhr_iec958_info,
  770. .get = pcxhr_iec958_get,
  771. .put = pcxhr_iec958_put,
  772. .private_value = 0 /* playback */
  773. };
  774. static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
  775. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  776. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  777. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
  778. .info = pcxhr_iec958_info,
  779. .get = pcxhr_iec958_mask_get
  780. };
  781. static struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
  782. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  783. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  784. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
  785. .info = pcxhr_iec958_info,
  786. .get = pcxhr_iec958_get,
  787. .private_value = 1 /* capture */
  788. };
  789. static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
  790. {
  791. int i;
  792. for (i = 0; i < 2; i++) {
  793. if (chip->nb_streams_play) {
  794. int j;
  795. /* at boot time the digital volumes are unmuted 0dB */
  796. for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
  797. chip->digital_playback_active[j][i] = 1;
  798. chip->digital_playback_volume[j][i] = PCXHR_DIGITAL_ZERO_LEVEL;
  799. }
  800. /* after boot, only two bits are set on the uer interface */
  801. chip->aes_bits[0] = IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_FS_48000;
  802. /* only for test purpose, remove later */
  803. #ifdef CONFIG_SND_DEBUG
  804. /* analog volumes for playback (is LEVEL_MIN after boot) */
  805. chip->analog_playback_active[i] = 1;
  806. chip->analog_playback_volume[i] = PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL;
  807. pcxhr_update_analog_audio_level(chip, 0, i);
  808. #endif
  809. /* test end */
  810. }
  811. if (chip->nb_streams_capt) {
  812. /* at boot time the digital volumes are unmuted 0dB */
  813. chip->digital_capture_volume[i] = PCXHR_DIGITAL_ZERO_LEVEL;
  814. /* only for test purpose, remove later */
  815. #ifdef CONFIG_SND_DEBUG
  816. /* analog volumes for playback (is LEVEL_MIN after boot) */
  817. chip->analog_capture_volume[i] = PCXHR_ANALOG_CAPTURE_ZERO_LEVEL;
  818. pcxhr_update_analog_audio_level(chip, 1, i);
  819. #endif
  820. /* test end */
  821. }
  822. }
  823. return;
  824. }
  825. int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
  826. {
  827. struct snd_pcxhr *chip;
  828. int err, i;
  829. mutex_init(&mgr->mixer_mutex); /* can be in another place */
  830. for (i = 0; i < mgr->num_cards; i++) {
  831. struct snd_kcontrol_new temp;
  832. chip = mgr->chip[i];
  833. if (chip->nb_streams_play) {
  834. /* analog output level control */
  835. temp = pcxhr_control_analog_level;
  836. temp.name = "Master Playback Volume";
  837. temp.private_value = 0; /* playback */
  838. temp.tlv.p = db_scale_analog_playback;
  839. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
  840. return err;
  841. /* output mute controls */
  842. if ((err = snd_ctl_add(chip->card,
  843. snd_ctl_new1(&pcxhr_control_output_switch,
  844. chip))) < 0)
  845. return err;
  846. temp = snd_pcxhr_pcm_vol;
  847. temp.name = "PCM Playback Volume";
  848. temp.count = PCXHR_PLAYBACK_STREAMS;
  849. temp.private_value = 0; /* playback */
  850. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
  851. return err;
  852. if ((err = snd_ctl_add(chip->card,
  853. snd_ctl_new1(&pcxhr_control_pcm_switch,
  854. chip))) < 0)
  855. return err;
  856. /* IEC958 controls */
  857. if ((err = snd_ctl_add(chip->card,
  858. snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
  859. chip))) < 0)
  860. return err;
  861. if ((err = snd_ctl_add(chip->card,
  862. snd_ctl_new1(&pcxhr_control_playback_iec958,
  863. chip))) < 0)
  864. return err;
  865. }
  866. if (chip->nb_streams_capt) {
  867. /* analog input level control only on first two chips !*/
  868. temp = pcxhr_control_analog_level;
  869. temp.name = "Master Capture Volume";
  870. temp.private_value = 1; /* capture */
  871. temp.tlv.p = db_scale_analog_capture;
  872. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
  873. return err;
  874. temp = snd_pcxhr_pcm_vol;
  875. temp.name = "PCM Capture Volume";
  876. temp.count = 1;
  877. temp.private_value = 1; /* capture */
  878. if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0)
  879. return err;
  880. /* Audio source */
  881. if ((err = snd_ctl_add(chip->card,
  882. snd_ctl_new1(&pcxhr_control_audio_src,
  883. chip))) < 0)
  884. return err;
  885. /* IEC958 controls */
  886. if ((err = snd_ctl_add(chip->card,
  887. snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
  888. chip))) < 0)
  889. return err;
  890. if ((err = snd_ctl_add(chip->card,
  891. snd_ctl_new1(&pcxhr_control_capture_iec958,
  892. chip))) < 0)
  893. return err;
  894. }
  895. /* monitoring only if playback and capture device available */
  896. if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
  897. /* monitoring */
  898. if ((err = snd_ctl_add(chip->card,
  899. snd_ctl_new1(&pcxhr_control_monitor_vol,
  900. chip))) < 0)
  901. return err;
  902. if ((err = snd_ctl_add(chip->card,
  903. snd_ctl_new1(&pcxhr_control_monitor_sw,
  904. chip))) < 0)
  905. return err;
  906. }
  907. if (i == 0) {
  908. /* clock mode only one control per pcxhr */
  909. if ((err = snd_ctl_add(chip->card,
  910. snd_ctl_new1(&pcxhr_control_clock_type,
  911. mgr))) < 0)
  912. return err;
  913. /* non standard control used to scan the external clock presence/frequencies */
  914. if ((err = snd_ctl_add(chip->card,
  915. snd_ctl_new1(&pcxhr_control_clock_rate,
  916. mgr))) < 0)
  917. return err;
  918. }
  919. /* init values for the mixer data */
  920. pcxhr_init_audio_levels(chip);
  921. }
  922. return 0;
  923. }