pcxhr_mixer.c 32 KB

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