pcxhr_mixer.c 36 KB

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