pcxhr_mixer.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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. rate = 0;
  720. if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) {
  721. pcxhr_get_external_clock(mgr, mgr->use_clock_type,
  722. &rate);
  723. } else {
  724. rate = mgr->sample_rate;
  725. if (!rate)
  726. rate = 48000;
  727. }
  728. if (rate) {
  729. pcxhr_set_clock(mgr, rate);
  730. if (mgr->sample_rate)
  731. mgr->sample_rate = rate;
  732. }
  733. mutex_unlock(&mgr->setup_mutex);
  734. ret = 1; /* return 1 even if the set was not done. ok ? */
  735. }
  736. mutex_unlock(&mgr->mixer_mutex);
  737. return ret;
  738. }
  739. static struct snd_kcontrol_new pcxhr_control_clock_type = {
  740. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  741. .name = "Clock Mode",
  742. .info = pcxhr_clock_type_info,
  743. .get = pcxhr_clock_type_get,
  744. .put = pcxhr_clock_type_put,
  745. };
  746. /*
  747. * clock rate control
  748. * specific control that scans the sample rates on the external plugs
  749. */
  750. static int pcxhr_clock_rate_info(struct snd_kcontrol *kcontrol,
  751. struct snd_ctl_elem_info *uinfo)
  752. {
  753. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  754. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  755. uinfo->count = 3 + mgr->capture_chips;
  756. uinfo->value.integer.min = 0; /* clock not present */
  757. uinfo->value.integer.max = 192000; /* max sample rate 192 kHz */
  758. return 0;
  759. }
  760. static int pcxhr_clock_rate_get(struct snd_kcontrol *kcontrol,
  761. struct snd_ctl_elem_value *ucontrol)
  762. {
  763. struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
  764. int i, err, rate;
  765. mutex_lock(&mgr->mixer_mutex);
  766. for(i = 0; i < 3 + mgr->capture_chips; i++) {
  767. if (i == PCXHR_CLOCK_TYPE_INTERNAL)
  768. rate = mgr->sample_rate_real;
  769. else {
  770. err = pcxhr_get_external_clock(mgr, i, &rate);
  771. if (err)
  772. break;
  773. }
  774. ucontrol->value.integer.value[i] = rate;
  775. }
  776. mutex_unlock(&mgr->mixer_mutex);
  777. return 0;
  778. }
  779. static struct snd_kcontrol_new pcxhr_control_clock_rate = {
  780. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  781. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  782. .name = "Clock Rates",
  783. .info = pcxhr_clock_rate_info,
  784. .get = pcxhr_clock_rate_get,
  785. };
  786. /*
  787. * IEC958 status bits
  788. */
  789. static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
  790. struct snd_ctl_elem_info *uinfo)
  791. {
  792. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  793. uinfo->count = 1;
  794. return 0;
  795. }
  796. static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
  797. int aes_idx, unsigned char *aes_bits)
  798. {
  799. int i, err;
  800. unsigned char temp;
  801. struct pcxhr_rmh rmh;
  802. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
  803. rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
  804. switch (chip->chip_idx) {
  805. /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
  806. case 0: rmh.cmd[1] = CS8420_01_CS; break;
  807. case 1: rmh.cmd[1] = CS8420_23_CS; break;
  808. case 2: rmh.cmd[1] = CS8420_45_CS; break;
  809. case 3: rmh.cmd[1] = CS8420_67_CS; break;
  810. default: return -EINVAL;
  811. }
  812. if (chip->mgr->board_aes_in_192k) {
  813. switch (aes_idx) {
  814. case 0: rmh.cmd[2] = CS8416_CSB0; break;
  815. case 1: rmh.cmd[2] = CS8416_CSB1; break;
  816. case 2: rmh.cmd[2] = CS8416_CSB2; break;
  817. case 3: rmh.cmd[2] = CS8416_CSB3; break;
  818. case 4: rmh.cmd[2] = CS8416_CSB4; break;
  819. default: return -EINVAL;
  820. }
  821. } else {
  822. switch (aes_idx) {
  823. /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
  824. case 0: rmh.cmd[2] = CS8420_CSB0; break;
  825. case 1: rmh.cmd[2] = CS8420_CSB1; break;
  826. case 2: rmh.cmd[2] = CS8420_CSB2; break;
  827. case 3: rmh.cmd[2] = CS8420_CSB3; break;
  828. case 4: rmh.cmd[2] = CS8420_CSB4; break;
  829. default: return -EINVAL;
  830. }
  831. }
  832. /* size and code the chip id for the fpga */
  833. rmh.cmd[1] &= 0x0fffff;
  834. /* chip signature + map for spi read */
  835. rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
  836. rmh.cmd_len = 3;
  837. err = pcxhr_send_msg(chip->mgr, &rmh);
  838. if (err)
  839. return err;
  840. if (chip->mgr->board_aes_in_192k) {
  841. temp = (unsigned char)rmh.stat[1];
  842. } else {
  843. temp = 0;
  844. /* reversed bit order (not with CS8416_01_CS) */
  845. for (i = 0; i < 8; i++) {
  846. temp <<= 1;
  847. if (rmh.stat[1] & (1 << i))
  848. temp |= 1;
  849. }
  850. }
  851. snd_printdd("read iec958 AES %d byte %d = 0x%x\n",
  852. chip->chip_idx, aes_idx, temp);
  853. *aes_bits = temp;
  854. return 0;
  855. }
  856. static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
  857. struct snd_ctl_elem_value *ucontrol)
  858. {
  859. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  860. unsigned char aes_bits;
  861. int i, err;
  862. mutex_lock(&chip->mgr->mixer_mutex);
  863. for(i = 0; i < 5; i++) {
  864. if (kcontrol->private_value == 0) /* playback */
  865. aes_bits = chip->aes_bits[i];
  866. else { /* capture */
  867. if (chip->mgr->is_hr_stereo)
  868. err = hr222_iec958_capture_byte(chip, i,
  869. &aes_bits);
  870. else
  871. err = pcxhr_iec958_capture_byte(chip, i,
  872. &aes_bits);
  873. if (err)
  874. break;
  875. }
  876. ucontrol->value.iec958.status[i] = aes_bits;
  877. }
  878. mutex_unlock(&chip->mgr->mixer_mutex);
  879. return 0;
  880. }
  881. static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
  882. struct snd_ctl_elem_value *ucontrol)
  883. {
  884. int i;
  885. for (i = 0; i < 5; i++)
  886. ucontrol->value.iec958.status[i] = 0xff;
  887. return 0;
  888. }
  889. static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
  890. int aes_idx, unsigned char aes_bits)
  891. {
  892. int i, err, cmd;
  893. unsigned char new_bits = aes_bits;
  894. unsigned char old_bits = chip->aes_bits[aes_idx];
  895. struct pcxhr_rmh rmh;
  896. for (i = 0; i < 8; i++) {
  897. if ((old_bits & 0x01) != (new_bits & 0x01)) {
  898. cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
  899. if (chip->chip_idx > 3)
  900. /* new bit used if chip_idx>3 (PCX1222HR) */
  901. cmd |= 1 << 22;
  902. cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
  903. cmd |= (new_bits & 0x01) << 23; /* add bit value */
  904. pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
  905. rmh.cmd[0] |= IO_NUM_REG_CUER;
  906. rmh.cmd[1] = cmd;
  907. rmh.cmd_len = 2;
  908. snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n",
  909. chip->chip_idx, aes_idx, i, cmd);
  910. err = pcxhr_send_msg(chip->mgr, &rmh);
  911. if (err)
  912. return err;
  913. }
  914. old_bits >>= 1;
  915. new_bits >>= 1;
  916. }
  917. chip->aes_bits[aes_idx] = aes_bits;
  918. return 0;
  919. }
  920. static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
  921. struct snd_ctl_elem_value *ucontrol)
  922. {
  923. struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
  924. int i, changed = 0;
  925. /* playback */
  926. mutex_lock(&chip->mgr->mixer_mutex);
  927. for (i = 0; i < 5; i++) {
  928. if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
  929. if (chip->mgr->is_hr_stereo)
  930. hr222_iec958_update_byte(chip, i,
  931. ucontrol->value.iec958.status[i]);
  932. else
  933. pcxhr_iec958_update_byte(chip, i,
  934. ucontrol->value.iec958.status[i]);
  935. changed = 1;
  936. }
  937. }
  938. mutex_unlock(&chip->mgr->mixer_mutex);
  939. return changed;
  940. }
  941. static struct snd_kcontrol_new pcxhr_control_playback_iec958_mask = {
  942. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  943. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  944. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  945. .info = pcxhr_iec958_info,
  946. .get = pcxhr_iec958_mask_get
  947. };
  948. static struct snd_kcontrol_new pcxhr_control_playback_iec958 = {
  949. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  950. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  951. .info = pcxhr_iec958_info,
  952. .get = pcxhr_iec958_get,
  953. .put = pcxhr_iec958_put,
  954. .private_value = 0 /* playback */
  955. };
  956. static struct snd_kcontrol_new pcxhr_control_capture_iec958_mask = {
  957. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  958. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  959. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
  960. .info = pcxhr_iec958_info,
  961. .get = pcxhr_iec958_mask_get
  962. };
  963. static struct snd_kcontrol_new pcxhr_control_capture_iec958 = {
  964. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  965. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  966. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
  967. .info = pcxhr_iec958_info,
  968. .get = pcxhr_iec958_get,
  969. .private_value = 1 /* capture */
  970. };
  971. static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
  972. {
  973. int i;
  974. for (i = 0; i < 2; i++) {
  975. if (chip->nb_streams_play) {
  976. int j;
  977. /* at boot time the digital volumes are unmuted 0dB */
  978. for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
  979. chip->digital_playback_active[j][i] = 1;
  980. chip->digital_playback_volume[j][i] =
  981. PCXHR_DIGITAL_ZERO_LEVEL;
  982. }
  983. /* after boot, only two bits are set on the uer
  984. * interface
  985. */
  986. chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
  987. IEC958_AES0_PRO_FS_48000);
  988. #ifdef CONFIG_SND_DEBUG
  989. /* analog volumes for playback
  990. * (is LEVEL_MIN after boot)
  991. */
  992. chip->analog_playback_active[i] = 1;
  993. if (chip->mgr->is_hr_stereo)
  994. chip->analog_playback_volume[i] =
  995. HR222_LINE_PLAYBACK_ZERO_LEVEL;
  996. else {
  997. chip->analog_playback_volume[i] =
  998. PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
  999. pcxhr_update_analog_audio_level(chip, 0, i);
  1000. }
  1001. #endif
  1002. /* stereo cards need to be initialised after boot */
  1003. if (chip->mgr->is_hr_stereo)
  1004. hr222_update_analog_audio_level(chip, 0, i);
  1005. }
  1006. if (chip->nb_streams_capt) {
  1007. /* at boot time the digital volumes are unmuted 0dB */
  1008. chip->digital_capture_volume[i] =
  1009. PCXHR_DIGITAL_ZERO_LEVEL;
  1010. chip->analog_capture_active = 1;
  1011. #ifdef CONFIG_SND_DEBUG
  1012. /* analog volumes for playback
  1013. * (is LEVEL_MIN after boot)
  1014. */
  1015. if (chip->mgr->is_hr_stereo)
  1016. chip->analog_capture_volume[i] =
  1017. HR222_LINE_CAPTURE_ZERO_LEVEL;
  1018. else {
  1019. chip->analog_capture_volume[i] =
  1020. PCXHR_LINE_CAPTURE_ZERO_LEVEL;
  1021. pcxhr_update_analog_audio_level(chip, 1, i);
  1022. }
  1023. #endif
  1024. /* stereo cards need to be initialised after boot */
  1025. if (chip->mgr->is_hr_stereo)
  1026. hr222_update_analog_audio_level(chip, 1, i);
  1027. }
  1028. }
  1029. return;
  1030. }
  1031. int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
  1032. {
  1033. struct snd_pcxhr *chip;
  1034. int err, i;
  1035. mutex_init(&mgr->mixer_mutex); /* can be in another place */
  1036. for (i = 0; i < mgr->num_cards; i++) {
  1037. struct snd_kcontrol_new temp;
  1038. chip = mgr->chip[i];
  1039. if (chip->nb_streams_play) {
  1040. /* analog output level control */
  1041. temp = pcxhr_control_analog_level;
  1042. temp.name = "Master Playback Volume";
  1043. temp.private_value = 0; /* playback */
  1044. if (mgr->is_hr_stereo)
  1045. temp.tlv.p = db_scale_a_hr222_playback;
  1046. else
  1047. temp.tlv.p = db_scale_analog_playback;
  1048. err = snd_ctl_add(chip->card,
  1049. snd_ctl_new1(&temp, chip));
  1050. if (err < 0)
  1051. return err;
  1052. /* output mute controls */
  1053. err = snd_ctl_add(chip->card,
  1054. snd_ctl_new1(&pcxhr_control_output_switch,
  1055. chip));
  1056. if (err < 0)
  1057. return err;
  1058. temp = snd_pcxhr_pcm_vol;
  1059. temp.name = "PCM Playback Volume";
  1060. temp.count = PCXHR_PLAYBACK_STREAMS;
  1061. temp.private_value = 0; /* playback */
  1062. err = snd_ctl_add(chip->card,
  1063. snd_ctl_new1(&temp, chip));
  1064. if (err < 0)
  1065. return err;
  1066. err = snd_ctl_add(chip->card,
  1067. snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
  1068. if (err < 0)
  1069. return err;
  1070. /* IEC958 controls */
  1071. err = snd_ctl_add(chip->card,
  1072. snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
  1073. chip));
  1074. if (err < 0)
  1075. return err;
  1076. err = snd_ctl_add(chip->card,
  1077. snd_ctl_new1(&pcxhr_control_playback_iec958,
  1078. chip));
  1079. if (err < 0)
  1080. return err;
  1081. }
  1082. if (chip->nb_streams_capt) {
  1083. /* analog input level control */
  1084. temp = pcxhr_control_analog_level;
  1085. temp.name = "Line Capture Volume";
  1086. temp.private_value = 1; /* capture */
  1087. if (mgr->is_hr_stereo)
  1088. temp.tlv.p = db_scale_a_hr222_capture;
  1089. else
  1090. temp.tlv.p = db_scale_analog_capture;
  1091. err = snd_ctl_add(chip->card,
  1092. snd_ctl_new1(&temp, chip));
  1093. if (err < 0)
  1094. return err;
  1095. temp = snd_pcxhr_pcm_vol;
  1096. temp.name = "PCM Capture Volume";
  1097. temp.count = 1;
  1098. temp.private_value = 1; /* capture */
  1099. err = snd_ctl_add(chip->card,
  1100. snd_ctl_new1(&temp, chip));
  1101. if (err < 0)
  1102. return err;
  1103. /* Audio source */
  1104. err = snd_ctl_add(chip->card,
  1105. snd_ctl_new1(&pcxhr_control_audio_src, chip));
  1106. if (err < 0)
  1107. return err;
  1108. /* IEC958 controls */
  1109. err = snd_ctl_add(chip->card,
  1110. snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
  1111. chip));
  1112. if (err < 0)
  1113. return err;
  1114. err = snd_ctl_add(chip->card,
  1115. snd_ctl_new1(&pcxhr_control_capture_iec958,
  1116. chip));
  1117. if (err < 0)
  1118. return err;
  1119. if (mgr->is_hr_stereo) {
  1120. err = hr222_add_mic_controls(chip);
  1121. if (err < 0)
  1122. return err;
  1123. }
  1124. }
  1125. /* monitoring only if playback and capture device available */
  1126. if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
  1127. /* monitoring */
  1128. err = snd_ctl_add(chip->card,
  1129. snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
  1130. if (err < 0)
  1131. return err;
  1132. err = snd_ctl_add(chip->card,
  1133. snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
  1134. if (err < 0)
  1135. return err;
  1136. }
  1137. if (i == 0) {
  1138. /* clock mode only one control per pcxhr */
  1139. err = snd_ctl_add(chip->card,
  1140. snd_ctl_new1(&pcxhr_control_clock_type, mgr));
  1141. if (err < 0)
  1142. return err;
  1143. /* non standard control used to scan
  1144. * the external clock presence/frequencies
  1145. */
  1146. err = snd_ctl_add(chip->card,
  1147. snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
  1148. if (err < 0)
  1149. return err;
  1150. }
  1151. /* init values for the mixer data */
  1152. pcxhr_init_audio_levels(chip);
  1153. }
  1154. return 0;
  1155. }