pcxhr_mixer.c 36 KB

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