oxygen_mixer.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. /*
  2. * C-Media CMI8788 driver - mixer code
  3. *
  4. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  5. *
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License, version 2.
  9. *
  10. * This driver is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this driver; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/mutex.h>
  20. #include <sound/ac97_codec.h>
  21. #include <sound/asoundef.h>
  22. #include <sound/control.h>
  23. #include <sound/tlv.h>
  24. #include "oxygen.h"
  25. #include "cm9780.h"
  26. static int dac_volume_info(struct snd_kcontrol *ctl,
  27. struct snd_ctl_elem_info *info)
  28. {
  29. struct oxygen *chip = ctl->private_data;
  30. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  31. info->count = chip->model.dac_channels_mixer;
  32. info->value.integer.min = chip->model.dac_volume_min;
  33. info->value.integer.max = chip->model.dac_volume_max;
  34. return 0;
  35. }
  36. static int dac_volume_get(struct snd_kcontrol *ctl,
  37. struct snd_ctl_elem_value *value)
  38. {
  39. struct oxygen *chip = ctl->private_data;
  40. unsigned int i;
  41. mutex_lock(&chip->mutex);
  42. for (i = 0; i < chip->model.dac_channels_mixer; ++i)
  43. value->value.integer.value[i] = chip->dac_volume[i];
  44. mutex_unlock(&chip->mutex);
  45. return 0;
  46. }
  47. static int dac_volume_put(struct snd_kcontrol *ctl,
  48. struct snd_ctl_elem_value *value)
  49. {
  50. struct oxygen *chip = ctl->private_data;
  51. unsigned int i;
  52. int changed;
  53. changed = 0;
  54. mutex_lock(&chip->mutex);
  55. for (i = 0; i < chip->model.dac_channels_mixer; ++i)
  56. if (value->value.integer.value[i] != chip->dac_volume[i]) {
  57. chip->dac_volume[i] = value->value.integer.value[i];
  58. changed = 1;
  59. }
  60. if (changed)
  61. chip->model.update_dac_volume(chip);
  62. mutex_unlock(&chip->mutex);
  63. return changed;
  64. }
  65. static int dac_mute_get(struct snd_kcontrol *ctl,
  66. struct snd_ctl_elem_value *value)
  67. {
  68. struct oxygen *chip = ctl->private_data;
  69. mutex_lock(&chip->mutex);
  70. value->value.integer.value[0] = !chip->dac_mute;
  71. mutex_unlock(&chip->mutex);
  72. return 0;
  73. }
  74. static int dac_mute_put(struct snd_kcontrol *ctl,
  75. struct snd_ctl_elem_value *value)
  76. {
  77. struct oxygen *chip = ctl->private_data;
  78. int changed;
  79. mutex_lock(&chip->mutex);
  80. changed = !value->value.integer.value[0] != chip->dac_mute;
  81. if (changed) {
  82. chip->dac_mute = !value->value.integer.value[0];
  83. chip->model.update_dac_mute(chip);
  84. }
  85. mutex_unlock(&chip->mutex);
  86. return changed;
  87. }
  88. static unsigned int upmix_item_count(struct oxygen *chip)
  89. {
  90. if (chip->model.dac_channels_pcm < 8)
  91. return 2;
  92. else if (chip->model.update_center_lfe_mix)
  93. return 5;
  94. else
  95. return 3;
  96. }
  97. static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
  98. {
  99. static const char *const names[5] = {
  100. "Front",
  101. "Front+Surround",
  102. "Front+Surround+Back",
  103. "Front+Surround+Center/LFE",
  104. "Front+Surround+Center/LFE+Back",
  105. };
  106. struct oxygen *chip = ctl->private_data;
  107. unsigned int count = upmix_item_count(chip);
  108. return snd_ctl_enum_info(info, 1, count, names);
  109. }
  110. static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
  111. {
  112. struct oxygen *chip = ctl->private_data;
  113. mutex_lock(&chip->mutex);
  114. value->value.enumerated.item[0] = chip->dac_routing;
  115. mutex_unlock(&chip->mutex);
  116. return 0;
  117. }
  118. void oxygen_update_dac_routing(struct oxygen *chip)
  119. {
  120. /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */
  121. static const unsigned int reg_values[5] = {
  122. /* stereo -> front */
  123. (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  124. (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  125. (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  126. (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
  127. /* stereo -> front+surround */
  128. (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  129. (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  130. (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  131. (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
  132. /* stereo -> front+surround+back */
  133. (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  134. (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  135. (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  136. (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
  137. /* stereo -> front+surround+center/LFE */
  138. (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  139. (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  140. (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  141. (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
  142. /* stereo -> front+surround+center/LFE+back */
  143. (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  144. (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  145. (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  146. (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
  147. };
  148. u8 channels;
  149. unsigned int reg_value;
  150. channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) &
  151. OXYGEN_PLAY_CHANNELS_MASK;
  152. if (channels == OXYGEN_PLAY_CHANNELS_2)
  153. reg_value = reg_values[chip->dac_routing];
  154. else if (channels == OXYGEN_PLAY_CHANNELS_8)
  155. /* in 7.1 mode, "rear" channels go to the "back" jack */
  156. reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  157. (3 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  158. (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  159. (1 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT);
  160. else
  161. reg_value = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
  162. (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
  163. (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
  164. (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT);
  165. if (chip->model.adjust_dac_routing)
  166. reg_value = chip->model.adjust_dac_routing(chip, reg_value);
  167. oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value,
  168. OXYGEN_PLAY_DAC0_SOURCE_MASK |
  169. OXYGEN_PLAY_DAC1_SOURCE_MASK |
  170. OXYGEN_PLAY_DAC2_SOURCE_MASK |
  171. OXYGEN_PLAY_DAC3_SOURCE_MASK);
  172. if (chip->model.update_center_lfe_mix)
  173. chip->model.update_center_lfe_mix(chip, chip->dac_routing > 2);
  174. }
  175. static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
  176. {
  177. struct oxygen *chip = ctl->private_data;
  178. unsigned int count = upmix_item_count(chip);
  179. int changed;
  180. if (value->value.enumerated.item[0] >= count)
  181. return -EINVAL;
  182. mutex_lock(&chip->mutex);
  183. changed = value->value.enumerated.item[0] != chip->dac_routing;
  184. if (changed) {
  185. chip->dac_routing = value->value.enumerated.item[0];
  186. oxygen_update_dac_routing(chip);
  187. }
  188. mutex_unlock(&chip->mutex);
  189. return changed;
  190. }
  191. static int spdif_switch_get(struct snd_kcontrol *ctl,
  192. struct snd_ctl_elem_value *value)
  193. {
  194. struct oxygen *chip = ctl->private_data;
  195. mutex_lock(&chip->mutex);
  196. value->value.integer.value[0] = chip->spdif_playback_enable;
  197. mutex_unlock(&chip->mutex);
  198. return 0;
  199. }
  200. static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate)
  201. {
  202. switch (oxygen_rate) {
  203. case OXYGEN_RATE_32000:
  204. return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  205. case OXYGEN_RATE_44100:
  206. return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  207. default: /* OXYGEN_RATE_48000 */
  208. return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  209. case OXYGEN_RATE_64000:
  210. return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT;
  211. case OXYGEN_RATE_88200:
  212. return IEC958_AES3_CON_FS_88200 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  213. case OXYGEN_RATE_96000:
  214. return IEC958_AES3_CON_FS_96000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  215. case OXYGEN_RATE_176400:
  216. return IEC958_AES3_CON_FS_176400 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  217. case OXYGEN_RATE_192000:
  218. return IEC958_AES3_CON_FS_192000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
  219. }
  220. }
  221. void oxygen_update_spdif_source(struct oxygen *chip)
  222. {
  223. u32 old_control, new_control;
  224. u16 old_routing, new_routing;
  225. unsigned int oxygen_rate;
  226. old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL);
  227. old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING);
  228. if (chip->pcm_active & (1 << PCM_SPDIF)) {
  229. new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE;
  230. new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK)
  231. | OXYGEN_PLAY_SPDIF_SPDIF;
  232. oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT)
  233. & OXYGEN_I2S_RATE_MASK;
  234. /* S/PDIF rate was already set by the caller */
  235. } else if ((chip->pcm_active & (1 << PCM_MULTICH)) &&
  236. chip->spdif_playback_enable) {
  237. new_routing = (old_routing & ~OXYGEN_PLAY_SPDIF_MASK)
  238. | OXYGEN_PLAY_SPDIF_MULTICH_01;
  239. oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT)
  240. & OXYGEN_I2S_RATE_MASK;
  241. new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) |
  242. (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) |
  243. OXYGEN_SPDIF_OUT_ENABLE;
  244. } else {
  245. new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE;
  246. new_routing = old_routing;
  247. oxygen_rate = OXYGEN_RATE_44100;
  248. }
  249. if (old_routing != new_routing) {
  250. oxygen_write32(chip, OXYGEN_SPDIF_CONTROL,
  251. new_control & ~OXYGEN_SPDIF_OUT_ENABLE);
  252. oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing);
  253. }
  254. if (new_control & OXYGEN_SPDIF_OUT_ENABLE)
  255. oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS,
  256. oxygen_spdif_rate(oxygen_rate) |
  257. ((chip->pcm_active & (1 << PCM_SPDIF)) ?
  258. chip->spdif_pcm_bits : chip->spdif_bits));
  259. oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control);
  260. }
  261. static int spdif_switch_put(struct snd_kcontrol *ctl,
  262. struct snd_ctl_elem_value *value)
  263. {
  264. struct oxygen *chip = ctl->private_data;
  265. int changed;
  266. mutex_lock(&chip->mutex);
  267. changed = value->value.integer.value[0] != chip->spdif_playback_enable;
  268. if (changed) {
  269. chip->spdif_playback_enable = !!value->value.integer.value[0];
  270. spin_lock_irq(&chip->reg_lock);
  271. oxygen_update_spdif_source(chip);
  272. spin_unlock_irq(&chip->reg_lock);
  273. }
  274. mutex_unlock(&chip->mutex);
  275. return changed;
  276. }
  277. static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
  278. {
  279. info->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  280. info->count = 1;
  281. return 0;
  282. }
  283. static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value)
  284. {
  285. value->value.iec958.status[0] =
  286. bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
  287. OXYGEN_SPDIF_PREEMPHASIS);
  288. value->value.iec958.status[1] = /* category and original */
  289. bits >> OXYGEN_SPDIF_CATEGORY_SHIFT;
  290. }
  291. static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value)
  292. {
  293. u32 bits;
  294. bits = value->value.iec958.status[0] &
  295. (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C |
  296. OXYGEN_SPDIF_PREEMPHASIS);
  297. bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT;
  298. if (bits & OXYGEN_SPDIF_NONAUDIO)
  299. bits |= OXYGEN_SPDIF_V;
  300. return bits;
  301. }
  302. static inline void write_spdif_bits(struct oxygen *chip, u32 bits)
  303. {
  304. oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits,
  305. OXYGEN_SPDIF_NONAUDIO |
  306. OXYGEN_SPDIF_C |
  307. OXYGEN_SPDIF_PREEMPHASIS |
  308. OXYGEN_SPDIF_CATEGORY_MASK |
  309. OXYGEN_SPDIF_ORIGINAL |
  310. OXYGEN_SPDIF_V);
  311. }
  312. static int spdif_default_get(struct snd_kcontrol *ctl,
  313. struct snd_ctl_elem_value *value)
  314. {
  315. struct oxygen *chip = ctl->private_data;
  316. mutex_lock(&chip->mutex);
  317. oxygen_to_iec958(chip->spdif_bits, value);
  318. mutex_unlock(&chip->mutex);
  319. return 0;
  320. }
  321. static int spdif_default_put(struct snd_kcontrol *ctl,
  322. struct snd_ctl_elem_value *value)
  323. {
  324. struct oxygen *chip = ctl->private_data;
  325. u32 new_bits;
  326. int changed;
  327. new_bits = iec958_to_oxygen(value);
  328. mutex_lock(&chip->mutex);
  329. changed = new_bits != chip->spdif_bits;
  330. if (changed) {
  331. chip->spdif_bits = new_bits;
  332. if (!(chip->pcm_active & (1 << PCM_SPDIF)))
  333. write_spdif_bits(chip, new_bits);
  334. }
  335. mutex_unlock(&chip->mutex);
  336. return changed;
  337. }
  338. static int spdif_mask_get(struct snd_kcontrol *ctl,
  339. struct snd_ctl_elem_value *value)
  340. {
  341. value->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  342. IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS;
  343. value->value.iec958.status[1] =
  344. IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL;
  345. return 0;
  346. }
  347. static int spdif_pcm_get(struct snd_kcontrol *ctl,
  348. struct snd_ctl_elem_value *value)
  349. {
  350. struct oxygen *chip = ctl->private_data;
  351. mutex_lock(&chip->mutex);
  352. oxygen_to_iec958(chip->spdif_pcm_bits, value);
  353. mutex_unlock(&chip->mutex);
  354. return 0;
  355. }
  356. static int spdif_pcm_put(struct snd_kcontrol *ctl,
  357. struct snd_ctl_elem_value *value)
  358. {
  359. struct oxygen *chip = ctl->private_data;
  360. u32 new_bits;
  361. int changed;
  362. new_bits = iec958_to_oxygen(value);
  363. mutex_lock(&chip->mutex);
  364. changed = new_bits != chip->spdif_pcm_bits;
  365. if (changed) {
  366. chip->spdif_pcm_bits = new_bits;
  367. if (chip->pcm_active & (1 << PCM_SPDIF))
  368. write_spdif_bits(chip, new_bits);
  369. }
  370. mutex_unlock(&chip->mutex);
  371. return changed;
  372. }
  373. static int spdif_input_mask_get(struct snd_kcontrol *ctl,
  374. struct snd_ctl_elem_value *value)
  375. {
  376. value->value.iec958.status[0] = 0xff;
  377. value->value.iec958.status[1] = 0xff;
  378. value->value.iec958.status[2] = 0xff;
  379. value->value.iec958.status[3] = 0xff;
  380. return 0;
  381. }
  382. static int spdif_input_default_get(struct snd_kcontrol *ctl,
  383. struct snd_ctl_elem_value *value)
  384. {
  385. struct oxygen *chip = ctl->private_data;
  386. u32 bits;
  387. bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS);
  388. value->value.iec958.status[0] = bits;
  389. value->value.iec958.status[1] = bits >> 8;
  390. value->value.iec958.status[2] = bits >> 16;
  391. value->value.iec958.status[3] = bits >> 24;
  392. return 0;
  393. }
  394. static int spdif_bit_switch_get(struct snd_kcontrol *ctl,
  395. struct snd_ctl_elem_value *value)
  396. {
  397. struct oxygen *chip = ctl->private_data;
  398. u32 bit = ctl->private_value;
  399. value->value.integer.value[0] =
  400. !!(oxygen_read32(chip, OXYGEN_SPDIF_CONTROL) & bit);
  401. return 0;
  402. }
  403. static int spdif_bit_switch_put(struct snd_kcontrol *ctl,
  404. struct snd_ctl_elem_value *value)
  405. {
  406. struct oxygen *chip = ctl->private_data;
  407. u32 bit = ctl->private_value;
  408. u32 oldreg, newreg;
  409. int changed;
  410. spin_lock_irq(&chip->reg_lock);
  411. oldreg = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL);
  412. if (value->value.integer.value[0])
  413. newreg = oldreg | bit;
  414. else
  415. newreg = oldreg & ~bit;
  416. changed = newreg != oldreg;
  417. if (changed)
  418. oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, newreg);
  419. spin_unlock_irq(&chip->reg_lock);
  420. return changed;
  421. }
  422. static int monitor_volume_info(struct snd_kcontrol *ctl,
  423. struct snd_ctl_elem_info *info)
  424. {
  425. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  426. info->count = 1;
  427. info->value.integer.min = 0;
  428. info->value.integer.max = 1;
  429. return 0;
  430. }
  431. static int monitor_get(struct snd_kcontrol *ctl,
  432. struct snd_ctl_elem_value *value)
  433. {
  434. struct oxygen *chip = ctl->private_data;
  435. u8 bit = ctl->private_value;
  436. int invert = ctl->private_value & (1 << 8);
  437. value->value.integer.value[0] =
  438. !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit);
  439. return 0;
  440. }
  441. static int monitor_put(struct snd_kcontrol *ctl,
  442. struct snd_ctl_elem_value *value)
  443. {
  444. struct oxygen *chip = ctl->private_data;
  445. u8 bit = ctl->private_value;
  446. int invert = ctl->private_value & (1 << 8);
  447. u8 oldreg, newreg;
  448. int changed;
  449. spin_lock_irq(&chip->reg_lock);
  450. oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR);
  451. if ((!!value->value.integer.value[0] ^ !!invert) != 0)
  452. newreg = oldreg | bit;
  453. else
  454. newreg = oldreg & ~bit;
  455. changed = newreg != oldreg;
  456. if (changed)
  457. oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg);
  458. spin_unlock_irq(&chip->reg_lock);
  459. return changed;
  460. }
  461. static int ac97_switch_get(struct snd_kcontrol *ctl,
  462. struct snd_ctl_elem_value *value)
  463. {
  464. struct oxygen *chip = ctl->private_data;
  465. unsigned int codec = (ctl->private_value >> 24) & 1;
  466. unsigned int index = ctl->private_value & 0xff;
  467. unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
  468. int invert = ctl->private_value & (1 << 16);
  469. u16 reg;
  470. mutex_lock(&chip->mutex);
  471. reg = oxygen_read_ac97(chip, codec, index);
  472. mutex_unlock(&chip->mutex);
  473. if (!(reg & (1 << bitnr)) ^ !invert)
  474. value->value.integer.value[0] = 1;
  475. else
  476. value->value.integer.value[0] = 0;
  477. return 0;
  478. }
  479. static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
  480. {
  481. unsigned int priv_idx;
  482. u16 value;
  483. if (!chip->controls[control])
  484. return;
  485. priv_idx = chip->controls[control]->private_value & 0xff;
  486. value = oxygen_read_ac97(chip, 0, priv_idx);
  487. if (!(value & 0x8000)) {
  488. oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000);
  489. if (chip->model.ac97_switch)
  490. chip->model.ac97_switch(chip, priv_idx, 0x8000);
  491. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  492. &chip->controls[control]->id);
  493. }
  494. }
  495. static int ac97_switch_put(struct snd_kcontrol *ctl,
  496. struct snd_ctl_elem_value *value)
  497. {
  498. struct oxygen *chip = ctl->private_data;
  499. unsigned int codec = (ctl->private_value >> 24) & 1;
  500. unsigned int index = ctl->private_value & 0xff;
  501. unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
  502. int invert = ctl->private_value & (1 << 16);
  503. u16 oldreg, newreg;
  504. int change;
  505. mutex_lock(&chip->mutex);
  506. oldreg = oxygen_read_ac97(chip, codec, index);
  507. newreg = oldreg;
  508. if (!value->value.integer.value[0] ^ !invert)
  509. newreg |= 1 << bitnr;
  510. else
  511. newreg &= ~(1 << bitnr);
  512. change = newreg != oldreg;
  513. if (change) {
  514. oxygen_write_ac97(chip, codec, index, newreg);
  515. if (codec == 0 && chip->model.ac97_switch)
  516. chip->model.ac97_switch(chip, index, newreg & 0x8000);
  517. if (index == AC97_LINE) {
  518. oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
  519. newreg & 0x8000 ?
  520. CM9780_GPO0 : 0, CM9780_GPO0);
  521. if (!(newreg & 0x8000)) {
  522. mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
  523. mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
  524. mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
  525. }
  526. } else if ((index == AC97_MIC || index == AC97_CD ||
  527. index == AC97_VIDEO || index == AC97_AUX) &&
  528. bitnr == 15 && !(newreg & 0x8000)) {
  529. mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
  530. oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
  531. CM9780_GPO0, CM9780_GPO0);
  532. }
  533. }
  534. mutex_unlock(&chip->mutex);
  535. return change;
  536. }
  537. static int ac97_volume_info(struct snd_kcontrol *ctl,
  538. struct snd_ctl_elem_info *info)
  539. {
  540. int stereo = (ctl->private_value >> 16) & 1;
  541. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  542. info->count = stereo ? 2 : 1;
  543. info->value.integer.min = 0;
  544. info->value.integer.max = 0x1f;
  545. return 0;
  546. }
  547. static int ac97_volume_get(struct snd_kcontrol *ctl,
  548. struct snd_ctl_elem_value *value)
  549. {
  550. struct oxygen *chip = ctl->private_data;
  551. unsigned int codec = (ctl->private_value >> 24) & 1;
  552. int stereo = (ctl->private_value >> 16) & 1;
  553. unsigned int index = ctl->private_value & 0xff;
  554. u16 reg;
  555. mutex_lock(&chip->mutex);
  556. reg = oxygen_read_ac97(chip, codec, index);
  557. mutex_unlock(&chip->mutex);
  558. if (!stereo) {
  559. value->value.integer.value[0] = 31 - (reg & 0x1f);
  560. } else {
  561. value->value.integer.value[0] = 31 - ((reg >> 8) & 0x1f);
  562. value->value.integer.value[1] = 31 - (reg & 0x1f);
  563. }
  564. return 0;
  565. }
  566. static int ac97_volume_put(struct snd_kcontrol *ctl,
  567. struct snd_ctl_elem_value *value)
  568. {
  569. struct oxygen *chip = ctl->private_data;
  570. unsigned int codec = (ctl->private_value >> 24) & 1;
  571. int stereo = (ctl->private_value >> 16) & 1;
  572. unsigned int index = ctl->private_value & 0xff;
  573. u16 oldreg, newreg;
  574. int change;
  575. mutex_lock(&chip->mutex);
  576. oldreg = oxygen_read_ac97(chip, codec, index);
  577. if (!stereo) {
  578. newreg = oldreg & ~0x1f;
  579. newreg |= 31 - (value->value.integer.value[0] & 0x1f);
  580. } else {
  581. newreg = oldreg & ~0x1f1f;
  582. newreg |= (31 - (value->value.integer.value[0] & 0x1f)) << 8;
  583. newreg |= 31 - (value->value.integer.value[1] & 0x1f);
  584. }
  585. change = newreg != oldreg;
  586. if (change)
  587. oxygen_write_ac97(chip, codec, index, newreg);
  588. mutex_unlock(&chip->mutex);
  589. return change;
  590. }
  591. static int mic_fmic_source_info(struct snd_kcontrol *ctl,
  592. struct snd_ctl_elem_info *info)
  593. {
  594. static const char *const names[] = { "Mic Jack", "Front Panel" };
  595. return snd_ctl_enum_info(info, 1, 2, names);
  596. }
  597. static int mic_fmic_source_get(struct snd_kcontrol *ctl,
  598. struct snd_ctl_elem_value *value)
  599. {
  600. struct oxygen *chip = ctl->private_data;
  601. mutex_lock(&chip->mutex);
  602. value->value.enumerated.item[0] =
  603. !!(oxygen_read_ac97(chip, 0, CM9780_JACK) & CM9780_FMIC2MIC);
  604. mutex_unlock(&chip->mutex);
  605. return 0;
  606. }
  607. static int mic_fmic_source_put(struct snd_kcontrol *ctl,
  608. struct snd_ctl_elem_value *value)
  609. {
  610. struct oxygen *chip = ctl->private_data;
  611. u16 oldreg, newreg;
  612. int change;
  613. mutex_lock(&chip->mutex);
  614. oldreg = oxygen_read_ac97(chip, 0, CM9780_JACK);
  615. if (value->value.enumerated.item[0])
  616. newreg = oldreg | CM9780_FMIC2MIC;
  617. else
  618. newreg = oldreg & ~CM9780_FMIC2MIC;
  619. change = newreg != oldreg;
  620. if (change)
  621. oxygen_write_ac97(chip, 0, CM9780_JACK, newreg);
  622. mutex_unlock(&chip->mutex);
  623. return change;
  624. }
  625. static int ac97_fp_rec_volume_info(struct snd_kcontrol *ctl,
  626. struct snd_ctl_elem_info *info)
  627. {
  628. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  629. info->count = 2;
  630. info->value.integer.min = 0;
  631. info->value.integer.max = 7;
  632. return 0;
  633. }
  634. static int ac97_fp_rec_volume_get(struct snd_kcontrol *ctl,
  635. struct snd_ctl_elem_value *value)
  636. {
  637. struct oxygen *chip = ctl->private_data;
  638. u16 reg;
  639. mutex_lock(&chip->mutex);
  640. reg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN);
  641. mutex_unlock(&chip->mutex);
  642. value->value.integer.value[0] = reg & 7;
  643. value->value.integer.value[1] = (reg >> 8) & 7;
  644. return 0;
  645. }
  646. static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
  647. struct snd_ctl_elem_value *value)
  648. {
  649. struct oxygen *chip = ctl->private_data;
  650. u16 oldreg, newreg;
  651. int change;
  652. mutex_lock(&chip->mutex);
  653. oldreg = oxygen_read_ac97(chip, 1, AC97_REC_GAIN);
  654. newreg = oldreg & ~0x0707;
  655. newreg = newreg | (value->value.integer.value[0] & 7);
  656. newreg = newreg | ((value->value.integer.value[0] & 7) << 8);
  657. change = newreg != oldreg;
  658. if (change)
  659. oxygen_write_ac97(chip, 1, AC97_REC_GAIN, newreg);
  660. mutex_unlock(&chip->mutex);
  661. return change;
  662. }
  663. #define AC97_SWITCH(xname, codec, index, bitnr, invert) { \
  664. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  665. .name = xname, \
  666. .info = snd_ctl_boolean_mono_info, \
  667. .get = ac97_switch_get, \
  668. .put = ac97_switch_put, \
  669. .private_value = ((codec) << 24) | ((invert) << 16) | \
  670. ((bitnr) << 8) | (index), \
  671. }
  672. #define AC97_VOLUME(xname, codec, index, stereo) { \
  673. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  674. .name = xname, \
  675. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  676. SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  677. .info = ac97_volume_info, \
  678. .get = ac97_volume_get, \
  679. .put = ac97_volume_put, \
  680. .tlv = { .p = ac97_db_scale, }, \
  681. .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \
  682. }
  683. static DECLARE_TLV_DB_SCALE(monitor_db_scale, -600, 600, 0);
  684. static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
  685. static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0);
  686. static const struct snd_kcontrol_new controls[] = {
  687. {
  688. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  689. .name = "Master Playback Volume",
  690. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  691. .info = dac_volume_info,
  692. .get = dac_volume_get,
  693. .put = dac_volume_put,
  694. },
  695. {
  696. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  697. .name = "Master Playback Switch",
  698. .info = snd_ctl_boolean_mono_info,
  699. .get = dac_mute_get,
  700. .put = dac_mute_put,
  701. },
  702. {
  703. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  704. .name = "Stereo Upmixing",
  705. .info = upmix_info,
  706. .get = upmix_get,
  707. .put = upmix_put,
  708. },
  709. {
  710. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  711. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
  712. .info = snd_ctl_boolean_mono_info,
  713. .get = spdif_switch_get,
  714. .put = spdif_switch_put,
  715. },
  716. {
  717. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  718. .device = 1,
  719. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  720. .info = spdif_info,
  721. .get = spdif_default_get,
  722. .put = spdif_default_put,
  723. },
  724. {
  725. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  726. .device = 1,
  727. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  728. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  729. .info = spdif_info,
  730. .get = spdif_mask_get,
  731. },
  732. {
  733. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  734. .device = 1,
  735. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  736. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  737. SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  738. .info = spdif_info,
  739. .get = spdif_pcm_get,
  740. .put = spdif_pcm_put,
  741. },
  742. };
  743. static const struct snd_kcontrol_new spdif_input_controls[] = {
  744. {
  745. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  746. .device = 1,
  747. .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
  748. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  749. .info = spdif_info,
  750. .get = spdif_input_mask_get,
  751. },
  752. {
  753. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  754. .device = 1,
  755. .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
  756. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  757. .info = spdif_info,
  758. .get = spdif_input_default_get,
  759. },
  760. {
  761. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  762. .name = SNDRV_CTL_NAME_IEC958("Loopback ", NONE, SWITCH),
  763. .info = snd_ctl_boolean_mono_info,
  764. .get = spdif_bit_switch_get,
  765. .put = spdif_bit_switch_put,
  766. .private_value = OXYGEN_SPDIF_LOOPBACK,
  767. },
  768. {
  769. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  770. .name = SNDRV_CTL_NAME_IEC958("Validity Check ",CAPTURE,SWITCH),
  771. .info = snd_ctl_boolean_mono_info,
  772. .get = spdif_bit_switch_get,
  773. .put = spdif_bit_switch_put,
  774. .private_value = OXYGEN_SPDIF_SPDVALID,
  775. },
  776. };
  777. static const struct {
  778. unsigned int pcm_dev;
  779. struct snd_kcontrol_new controls[2];
  780. } monitor_controls[] = {
  781. {
  782. .pcm_dev = CAPTURE_0_FROM_I2S_1,
  783. .controls = {
  784. {
  785. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  786. .name = "Analog Input Monitor Playback Switch",
  787. .info = snd_ctl_boolean_mono_info,
  788. .get = monitor_get,
  789. .put = monitor_put,
  790. .private_value = OXYGEN_ADC_MONITOR_A,
  791. },
  792. {
  793. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  794. .name = "Analog Input Monitor Playback Volume",
  795. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  796. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  797. .info = monitor_volume_info,
  798. .get = monitor_get,
  799. .put = monitor_put,
  800. .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL
  801. | (1 << 8),
  802. .tlv = { .p = monitor_db_scale, },
  803. },
  804. },
  805. },
  806. {
  807. .pcm_dev = CAPTURE_0_FROM_I2S_2,
  808. .controls = {
  809. {
  810. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  811. .name = "Analog Input Monitor Playback Switch",
  812. .info = snd_ctl_boolean_mono_info,
  813. .get = monitor_get,
  814. .put = monitor_put,
  815. .private_value = OXYGEN_ADC_MONITOR_B,
  816. },
  817. {
  818. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  819. .name = "Analog Input Monitor Playback Volume",
  820. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  821. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  822. .info = monitor_volume_info,
  823. .get = monitor_get,
  824. .put = monitor_put,
  825. .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
  826. | (1 << 8),
  827. .tlv = { .p = monitor_db_scale, },
  828. },
  829. },
  830. },
  831. {
  832. .pcm_dev = CAPTURE_2_FROM_I2S_2,
  833. .controls = {
  834. {
  835. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  836. .name = "Analog Input Monitor Playback Switch",
  837. .index = 1,
  838. .info = snd_ctl_boolean_mono_info,
  839. .get = monitor_get,
  840. .put = monitor_put,
  841. .private_value = OXYGEN_ADC_MONITOR_B,
  842. },
  843. {
  844. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  845. .name = "Analog Input Monitor Playback Volume",
  846. .index = 1,
  847. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  848. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  849. .info = monitor_volume_info,
  850. .get = monitor_get,
  851. .put = monitor_put,
  852. .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
  853. | (1 << 8),
  854. .tlv = { .p = monitor_db_scale, },
  855. },
  856. },
  857. },
  858. {
  859. .pcm_dev = CAPTURE_1_FROM_SPDIF,
  860. .controls = {
  861. {
  862. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  863. .name = "Digital Input Monitor Playback Switch",
  864. .info = snd_ctl_boolean_mono_info,
  865. .get = monitor_get,
  866. .put = monitor_put,
  867. .private_value = OXYGEN_ADC_MONITOR_C,
  868. },
  869. {
  870. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  871. .name = "Digital Input Monitor Playback Volume",
  872. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  873. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  874. .info = monitor_volume_info,
  875. .get = monitor_get,
  876. .put = monitor_put,
  877. .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL
  878. | (1 << 8),
  879. .tlv = { .p = monitor_db_scale, },
  880. },
  881. },
  882. },
  883. };
  884. static const struct snd_kcontrol_new ac97_controls[] = {
  885. AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0),
  886. AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
  887. AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
  888. {
  889. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  890. .name = "Mic Source Capture Enum",
  891. .info = mic_fmic_source_info,
  892. .get = mic_fmic_source_get,
  893. .put = mic_fmic_source_put,
  894. },
  895. AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
  896. AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1),
  897. AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
  898. AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX, 1),
  899. AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1),
  900. };
  901. static const struct snd_kcontrol_new ac97_fp_controls[] = {
  902. AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE, 1),
  903. AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1),
  904. {
  905. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  906. .name = "Front Panel Capture Volume",
  907. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  908. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  909. .info = ac97_fp_rec_volume_info,
  910. .get = ac97_fp_rec_volume_get,
  911. .put = ac97_fp_rec_volume_put,
  912. .tlv = { .p = ac97_rec_db_scale, },
  913. },
  914. AC97_SWITCH("Front Panel Capture Switch", 1, AC97_REC_GAIN, 15, 1),
  915. };
  916. static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
  917. {
  918. struct oxygen *chip = ctl->private_data;
  919. unsigned int i;
  920. /* I'm too lazy to write a function for each control :-) */
  921. for (i = 0; i < ARRAY_SIZE(chip->controls); ++i)
  922. chip->controls[i] = NULL;
  923. }
  924. static int add_controls(struct oxygen *chip,
  925. const struct snd_kcontrol_new controls[],
  926. unsigned int count)
  927. {
  928. static const char *const known_ctl_names[CONTROL_COUNT] = {
  929. [CONTROL_SPDIF_PCM] =
  930. SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  931. [CONTROL_SPDIF_INPUT_BITS] =
  932. SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
  933. [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch",
  934. [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch",
  935. [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
  936. [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
  937. };
  938. unsigned int i, j;
  939. struct snd_kcontrol_new template;
  940. struct snd_kcontrol *ctl;
  941. int err;
  942. for (i = 0; i < count; ++i) {
  943. template = controls[i];
  944. if (chip->model.control_filter) {
  945. err = chip->model.control_filter(&template);
  946. if (err < 0)
  947. return err;
  948. if (err == 1)
  949. continue;
  950. }
  951. if (!strcmp(template.name, "Stereo Upmixing") &&
  952. chip->model.dac_channels_pcm == 2)
  953. continue;
  954. if (!strcmp(template.name, "Mic Source Capture Enum") &&
  955. !(chip->model.device_config & AC97_FMIC_SWITCH))
  956. continue;
  957. if (!strncmp(template.name, "CD Capture ", 11) &&
  958. !(chip->model.device_config & AC97_CD_INPUT))
  959. continue;
  960. if (!strcmp(template.name, "Master Playback Volume") &&
  961. chip->model.dac_tlv) {
  962. template.tlv.p = chip->model.dac_tlv;
  963. template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
  964. }
  965. ctl = snd_ctl_new1(&template, chip);
  966. if (!ctl)
  967. return -ENOMEM;
  968. err = snd_ctl_add(chip->card, ctl);
  969. if (err < 0)
  970. return err;
  971. for (j = 0; j < CONTROL_COUNT; ++j)
  972. if (!strcmp(ctl->id.name, known_ctl_names[j])) {
  973. chip->controls[j] = ctl;
  974. ctl->private_free = oxygen_any_ctl_free;
  975. }
  976. }
  977. return 0;
  978. }
  979. int oxygen_mixer_init(struct oxygen *chip)
  980. {
  981. unsigned int i;
  982. int err;
  983. err = add_controls(chip, controls, ARRAY_SIZE(controls));
  984. if (err < 0)
  985. return err;
  986. if (chip->model.device_config & CAPTURE_1_FROM_SPDIF) {
  987. err = add_controls(chip, spdif_input_controls,
  988. ARRAY_SIZE(spdif_input_controls));
  989. if (err < 0)
  990. return err;
  991. }
  992. for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) {
  993. if (!(chip->model.device_config & monitor_controls[i].pcm_dev))
  994. continue;
  995. err = add_controls(chip, monitor_controls[i].controls,
  996. ARRAY_SIZE(monitor_controls[i].controls));
  997. if (err < 0)
  998. return err;
  999. }
  1000. if (chip->has_ac97_0) {
  1001. err = add_controls(chip, ac97_controls,
  1002. ARRAY_SIZE(ac97_controls));
  1003. if (err < 0)
  1004. return err;
  1005. }
  1006. if (chip->has_ac97_1) {
  1007. err = add_controls(chip, ac97_fp_controls,
  1008. ARRAY_SIZE(ac97_fp_controls));
  1009. if (err < 0)
  1010. return err;
  1011. }
  1012. return chip->model.mixer_init ? chip->model.mixer_init(chip) : 0;
  1013. }