pcxhr_mixer.c 36 KB

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