pcxhr_mixer.c 35 KB

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