aureon.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for Terratec Aureon cards
  5. *
  6. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. *
  23. * NOTES:
  24. *
  25. * - we reuse the struct snd_akm4xxx record for storing the wm8770 codec data.
  26. * both wm and akm codecs are pretty similar, so we can integrate
  27. * both controls in the future, once if wm codecs are reused in
  28. * many boards.
  29. *
  30. * - DAC digital volumes are not implemented in the mixer.
  31. * if they show better response than DAC analog volumes, we can use them
  32. * instead.
  33. *
  34. * Lowlevel functions for AudioTrak Prodigy 7.1 (and possibly 192) cards
  35. * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
  36. *
  37. * version 0.82: Stable / not all features work yet (no communication with AC97 secondary)
  38. * added 64x/128x oversampling switch (should be 64x only for 96khz)
  39. * fixed some recording labels (still need to check the rest)
  40. * recording is working probably thanks to correct wm8770 initialization
  41. *
  42. * version 0.5: Initial release:
  43. * working: analog output, mixer, headphone amplifier switch
  44. * not working: prety much everything else, at least i could verify that
  45. * we have no digital output, no capture, pretty bad clicks and poops
  46. * on mixer switch and other coll stuff.
  47. *
  48. */
  49. #include <sound/driver.h>
  50. #include <asm/io.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/init.h>
  54. #include <linux/slab.h>
  55. #include <linux/mutex.h>
  56. #include <sound/core.h>
  57. #include "ice1712.h"
  58. #include "envy24ht.h"
  59. #include "aureon.h"
  60. /* WM8770 registers */
  61. #define WM_DAC_ATTEN 0x00 /* DAC1-8 analog attenuation */
  62. #define WM_DAC_MASTER_ATTEN 0x08 /* DAC master analog attenuation */
  63. #define WM_DAC_DIG_ATTEN 0x09 /* DAC1-8 digital attenuation */
  64. #define WM_DAC_DIG_MASTER_ATTEN 0x11 /* DAC master digital attenuation */
  65. #define WM_PHASE_SWAP 0x12 /* DAC phase */
  66. #define WM_DAC_CTRL1 0x13 /* DAC control bits */
  67. #define WM_MUTE 0x14 /* mute controls */
  68. #define WM_DAC_CTRL2 0x15 /* de-emphasis and zefo-flag */
  69. #define WM_INT_CTRL 0x16 /* interface control */
  70. #define WM_MASTER 0x17 /* master clock and mode */
  71. #define WM_POWERDOWN 0x18 /* power-down controls */
  72. #define WM_ADC_GAIN 0x19 /* ADC gain L(19)/R(1a) */
  73. #define WM_ADC_MUX 0x1b /* input MUX */
  74. #define WM_OUT_MUX1 0x1c /* output MUX */
  75. #define WM_OUT_MUX2 0x1e /* output MUX */
  76. #define WM_RESET 0x1f /* software reset */
  77. /* CS8415A registers */
  78. #define CS8415_CTRL1 0x01
  79. #define CS8415_CTRL2 0x02
  80. #define CS8415_QSUB 0x14
  81. #define CS8415_RATIO 0x1E
  82. #define CS8415_C_BUFFER 0x20
  83. #define CS8415_ID 0x7F
  84. static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg, unsigned short val) {
  85. unsigned int tmp;
  86. /* Send address to XILINX chip */
  87. tmp = (snd_ice1712_gpio_read(ice) & ~0xFF) | (reg & 0x7F);
  88. snd_ice1712_gpio_write(ice, tmp);
  89. udelay(10);
  90. tmp |= AUREON_AC97_ADDR;
  91. snd_ice1712_gpio_write(ice, tmp);
  92. udelay(10);
  93. tmp &= ~AUREON_AC97_ADDR;
  94. snd_ice1712_gpio_write(ice, tmp);
  95. udelay(10);
  96. /* Send low-order byte to XILINX chip */
  97. tmp &= ~AUREON_AC97_DATA_MASK;
  98. tmp |= val & AUREON_AC97_DATA_MASK;
  99. snd_ice1712_gpio_write(ice, tmp);
  100. udelay(10);
  101. tmp |= AUREON_AC97_DATA_LOW;
  102. snd_ice1712_gpio_write(ice, tmp);
  103. udelay(10);
  104. tmp &= ~AUREON_AC97_DATA_LOW;
  105. snd_ice1712_gpio_write(ice, tmp);
  106. udelay(10);
  107. /* Send high-order byte to XILINX chip */
  108. tmp &= ~AUREON_AC97_DATA_MASK;
  109. tmp |= (val >> 8) & AUREON_AC97_DATA_MASK;
  110. snd_ice1712_gpio_write(ice, tmp);
  111. udelay(10);
  112. tmp |= AUREON_AC97_DATA_HIGH;
  113. snd_ice1712_gpio_write(ice, tmp);
  114. udelay(10);
  115. tmp &= ~AUREON_AC97_DATA_HIGH;
  116. snd_ice1712_gpio_write(ice, tmp);
  117. udelay(10);
  118. /* Instruct XILINX chip to parse the data to the STAC9744 chip */
  119. tmp |= AUREON_AC97_COMMIT;
  120. snd_ice1712_gpio_write(ice, tmp);
  121. udelay(10);
  122. tmp &= ~AUREON_AC97_COMMIT;
  123. snd_ice1712_gpio_write(ice, tmp);
  124. udelay(10);
  125. /* Store the data in out private buffer */
  126. ice->spec.aureon.stac9744[(reg & 0x7F) >> 1] = val;
  127. }
  128. static unsigned short aureon_ac97_read(struct snd_ice1712 *ice, unsigned short reg)
  129. {
  130. return ice->spec.aureon.stac9744[(reg & 0x7F) >> 1];
  131. }
  132. /*
  133. * Initialize STAC9744 chip
  134. */
  135. static int aureon_ac97_init (struct snd_ice1712 *ice) {
  136. int i;
  137. static unsigned short ac97_defaults[] = {
  138. 0x00, 0x9640,
  139. 0x02, 0x8000,
  140. 0x04, 0x8000,
  141. 0x06, 0x8000,
  142. 0x0C, 0x8008,
  143. 0x0E, 0x8008,
  144. 0x10, 0x8808,
  145. 0x12, 0x8808,
  146. 0x14, 0x8808,
  147. 0x16, 0x8808,
  148. 0x18, 0x8808,
  149. 0x1C, 0x8000,
  150. 0x26, 0x000F,
  151. 0x28, 0x0201,
  152. 0x2C, 0xBB80,
  153. 0x32, 0xBB80,
  154. 0x7C, 0x8384,
  155. 0x7E, 0x7644,
  156. (unsigned short)-1
  157. };
  158. unsigned int tmp;
  159. /* Cold reset */
  160. tmp = (snd_ice1712_gpio_read(ice) | AUREON_AC97_RESET) & ~AUREON_AC97_DATA_MASK;
  161. snd_ice1712_gpio_write(ice, tmp);
  162. udelay(3);
  163. tmp &= ~AUREON_AC97_RESET;
  164. snd_ice1712_gpio_write(ice, tmp);
  165. udelay(3);
  166. tmp |= AUREON_AC97_RESET;
  167. snd_ice1712_gpio_write(ice, tmp);
  168. udelay(3);
  169. memset(&ice->spec.aureon.stac9744, 0, sizeof(ice->spec.aureon.stac9744));
  170. for (i=0; ac97_defaults[i] != (unsigned short)-1; i+=2)
  171. ice->spec.aureon.stac9744[(ac97_defaults[i]) >> 1] = ac97_defaults[i+1];
  172. aureon_ac97_write(ice, AC97_MASTER, 0x0000); // Unmute AC'97 master volume permanently - muting is done by WM8770
  173. return 0;
  174. }
  175. #define AUREON_AC97_STEREO 0x80
  176. /*
  177. * AC'97 volume controls
  178. */
  179. static int aureon_ac97_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  180. {
  181. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  182. uinfo->count = kcontrol->private_value & AUREON_AC97_STEREO ? 2 : 1;
  183. uinfo->value.integer.min = 0;
  184. uinfo->value.integer.max = 31;
  185. return 0;
  186. }
  187. static int aureon_ac97_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  188. {
  189. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  190. unsigned short vol;
  191. mutex_lock(&ice->gpio_mutex);
  192. vol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
  193. ucontrol->value.integer.value[0] = 0x1F - (vol & 0x1F);
  194. if (kcontrol->private_value & AUREON_AC97_STEREO)
  195. ucontrol->value.integer.value[1] = 0x1F - ((vol >> 8) & 0x1F);
  196. mutex_unlock(&ice->gpio_mutex);
  197. return 0;
  198. }
  199. static int aureon_ac97_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  200. {
  201. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  202. unsigned short ovol, nvol;
  203. int change;
  204. snd_ice1712_save_gpio_status(ice);
  205. ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
  206. nvol = (0x1F - ucontrol->value.integer.value[0]) & 0x001F;
  207. if (kcontrol->private_value & AUREON_AC97_STEREO)
  208. nvol |= ((0x1F - ucontrol->value.integer.value[1]) << 8) & 0x1F00;
  209. nvol |= ovol & ~0x1F1F;
  210. if ((change = (ovol != nvol)))
  211. aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);
  212. snd_ice1712_restore_gpio_status(ice);
  213. return change;
  214. }
  215. /*
  216. * AC'97 mute controls
  217. */
  218. #define aureon_ac97_mute_info aureon_mono_bool_info
  219. static int aureon_ac97_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  220. {
  221. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  222. mutex_lock(&ice->gpio_mutex);
  223. ucontrol->value.integer.value[0] = aureon_ac97_read(ice, kcontrol->private_value & 0x7F) & 0x8000 ? 0 : 1;
  224. mutex_unlock(&ice->gpio_mutex);
  225. return 0;
  226. }
  227. static int aureon_ac97_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  228. {
  229. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  230. unsigned short ovol, nvol;
  231. int change;
  232. snd_ice1712_save_gpio_status(ice);
  233. ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
  234. nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x8000) | (ovol & ~ 0x8000);
  235. if ((change = (ovol != nvol)))
  236. aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);
  237. snd_ice1712_restore_gpio_status(ice);
  238. return change;
  239. }
  240. /*
  241. * AC'97 mute controls
  242. */
  243. #define aureon_ac97_micboost_info aureon_mono_bool_info
  244. static int aureon_ac97_micboost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  245. {
  246. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  247. mutex_lock(&ice->gpio_mutex);
  248. ucontrol->value.integer.value[0] = aureon_ac97_read(ice, AC97_MIC) & 0x0020 ? 0 : 1;
  249. mutex_unlock(&ice->gpio_mutex);
  250. return 0;
  251. }
  252. static int aureon_ac97_micboost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  253. {
  254. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  255. unsigned short ovol, nvol;
  256. int change;
  257. snd_ice1712_save_gpio_status(ice);
  258. ovol = aureon_ac97_read(ice, AC97_MIC);
  259. nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x0020) | (ovol & ~0x0020);
  260. if ((change = (ovol != nvol)))
  261. aureon_ac97_write(ice, AC97_MIC, nvol);
  262. snd_ice1712_restore_gpio_status(ice);
  263. return change;
  264. }
  265. /*
  266. * write data in the SPI mode
  267. */
  268. static void aureon_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits)
  269. {
  270. unsigned int tmp;
  271. int i;
  272. unsigned int mosi, clk;
  273. tmp = snd_ice1712_gpio_read(ice);
  274. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT) {
  275. snd_ice1712_gpio_set_mask(ice, ~(PRODIGY_SPI_MOSI|PRODIGY_SPI_CLK|PRODIGY_WM_CS));
  276. mosi = PRODIGY_SPI_MOSI;
  277. clk = PRODIGY_SPI_CLK;
  278. }
  279. else {
  280. snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_SPI_MOSI|AUREON_SPI_CLK|
  281. AUREON_WM_CS|AUREON_CS8415_CS));
  282. mosi = AUREON_SPI_MOSI;
  283. clk = AUREON_SPI_CLK;
  284. tmp |= AUREON_WM_RW;
  285. }
  286. tmp &= ~cs;
  287. snd_ice1712_gpio_write(ice, tmp);
  288. udelay(1);
  289. for (i = bits - 1; i >= 0; i--) {
  290. tmp &= ~clk;
  291. snd_ice1712_gpio_write(ice, tmp);
  292. udelay(1);
  293. if (data & (1 << i))
  294. tmp |= mosi;
  295. else
  296. tmp &= ~mosi;
  297. snd_ice1712_gpio_write(ice, tmp);
  298. udelay(1);
  299. tmp |= clk;
  300. snd_ice1712_gpio_write(ice, tmp);
  301. udelay(1);
  302. }
  303. tmp &= ~clk;
  304. tmp |= cs;
  305. snd_ice1712_gpio_write(ice, tmp);
  306. udelay(1);
  307. tmp |= clk;
  308. snd_ice1712_gpio_write(ice, tmp);
  309. udelay(1);
  310. }
  311. /*
  312. * Read data in SPI mode
  313. */
  314. static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits, unsigned char *buffer, int size) {
  315. int i, j;
  316. unsigned int tmp;
  317. tmp = (snd_ice1712_gpio_read(ice) & ~AUREON_SPI_CLK) | AUREON_CS8415_CS|AUREON_WM_CS;
  318. snd_ice1712_gpio_write(ice, tmp);
  319. tmp &= ~cs;
  320. snd_ice1712_gpio_write(ice, tmp);
  321. udelay(1);
  322. for (i=bits-1; i>=0; i--) {
  323. if (data & (1 << i))
  324. tmp |= AUREON_SPI_MOSI;
  325. else
  326. tmp &= ~AUREON_SPI_MOSI;
  327. snd_ice1712_gpio_write(ice, tmp);
  328. udelay(1);
  329. tmp |= AUREON_SPI_CLK;
  330. snd_ice1712_gpio_write(ice, tmp);
  331. udelay(1);
  332. tmp &= ~AUREON_SPI_CLK;
  333. snd_ice1712_gpio_write(ice, tmp);
  334. udelay(1);
  335. }
  336. for (j=0; j<size; j++) {
  337. unsigned char outdata = 0;
  338. for (i=7; i>=0; i--) {
  339. tmp = snd_ice1712_gpio_read(ice);
  340. outdata <<= 1;
  341. outdata |= (tmp & AUREON_SPI_MISO) ? 1 : 0;
  342. udelay(1);
  343. tmp |= AUREON_SPI_CLK;
  344. snd_ice1712_gpio_write(ice, tmp);
  345. udelay(1);
  346. tmp &= ~AUREON_SPI_CLK;
  347. snd_ice1712_gpio_write(ice, tmp);
  348. udelay(1);
  349. }
  350. buffer[j] = outdata;
  351. }
  352. tmp |= cs;
  353. snd_ice1712_gpio_write(ice, tmp);
  354. }
  355. static unsigned char aureon_cs8415_get(struct snd_ice1712 *ice, int reg) {
  356. unsigned char val;
  357. aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
  358. aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, &val, 1);
  359. return val;
  360. }
  361. static void aureon_cs8415_read(struct snd_ice1712 *ice, int reg, unsigned char *buffer, int size) {
  362. aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
  363. aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, buffer, size);
  364. }
  365. static void aureon_cs8415_put(struct snd_ice1712 *ice, int reg, unsigned char val) {
  366. aureon_spi_write(ice, AUREON_CS8415_CS, 0x200000 | (reg << 8) | val, 24);
  367. }
  368. /*
  369. * get the current register value of WM codec
  370. */
  371. static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
  372. {
  373. reg <<= 1;
  374. return ((unsigned short)ice->akm[0].images[reg] << 8) |
  375. ice->akm[0].images[reg + 1];
  376. }
  377. /*
  378. * set the register value of WM codec
  379. */
  380. static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
  381. {
  382. aureon_spi_write(ice,
  383. (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT ? PRODIGY_WM_CS : AUREON_WM_CS),
  384. (reg << 9) | (val & 0x1ff), 16);
  385. }
  386. /*
  387. * set the register value of WM codec and remember it
  388. */
  389. static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
  390. {
  391. wm_put_nocache(ice, reg, val);
  392. reg <<= 1;
  393. ice->akm[0].images[reg] = val >> 8;
  394. ice->akm[0].images[reg + 1] = val;
  395. }
  396. /*
  397. */
  398. static int aureon_mono_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  399. {
  400. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  401. uinfo->count = 1;
  402. uinfo->value.integer.min = 0;
  403. uinfo->value.integer.max = 1;
  404. return 0;
  405. }
  406. /*
  407. * AC'97 master playback mute controls (Mute on WM8770 chip)
  408. */
  409. #define aureon_ac97_mmute_info aureon_mono_bool_info
  410. static int aureon_ac97_mmute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  411. {
  412. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  413. mutex_lock(&ice->gpio_mutex);
  414. ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX1) >> 1) & 0x01;
  415. mutex_unlock(&ice->gpio_mutex);
  416. return 0;
  417. }
  418. static int aureon_ac97_mmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
  419. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  420. unsigned short ovol, nvol;
  421. int change;
  422. snd_ice1712_save_gpio_status(ice);
  423. ovol = wm_get(ice, WM_OUT_MUX1);
  424. nvol = (ovol & ~0x02) | (ucontrol->value.integer.value[0] ? 0x02 : 0x00);
  425. if ((change = (ovol != nvol)))
  426. wm_put(ice, WM_OUT_MUX1, nvol);
  427. snd_ice1712_restore_gpio_status(ice);
  428. return change;
  429. }
  430. /*
  431. * Logarithmic volume values for WM8770
  432. * Computed as 20 * Log10(255 / x)
  433. */
  434. static unsigned char wm_vol[256] = {
  435. 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
  436. 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
  437. 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
  438. 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
  439. 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
  440. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
  441. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  442. 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
  443. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  444. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  445. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  446. 0, 0
  447. };
  448. #define WM_VOL_MAX (sizeof(wm_vol) - 1)
  449. #define WM_VOL_MUTE 0x8000
  450. static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
  451. {
  452. unsigned char nvol;
  453. if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
  454. nvol = 0;
  455. else
  456. nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX];
  457. wm_put(ice, index, nvol);
  458. wm_put_nocache(ice, index, 0x180 | nvol);
  459. }
  460. /*
  461. * DAC mute control
  462. */
  463. #define wm_pcm_mute_info aureon_mono_bool_info
  464. static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  465. {
  466. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  467. mutex_lock(&ice->gpio_mutex);
  468. ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1;
  469. mutex_unlock(&ice->gpio_mutex);
  470. return 0;
  471. }
  472. static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  473. {
  474. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  475. unsigned short nval, oval;
  476. int change;
  477. snd_ice1712_save_gpio_status(ice);
  478. oval = wm_get(ice, WM_MUTE);
  479. nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
  480. if ((change = (nval != oval)))
  481. wm_put(ice, WM_MUTE, nval);
  482. snd_ice1712_restore_gpio_status(ice);
  483. return change;
  484. }
  485. /*
  486. * Master volume attenuation mixer control
  487. */
  488. static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  489. {
  490. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  491. uinfo->count = 2;
  492. uinfo->value.integer.min = 0;
  493. uinfo->value.integer.max = WM_VOL_MAX;
  494. return 0;
  495. }
  496. static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  497. {
  498. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  499. int i;
  500. for (i=0; i<2; i++)
  501. ucontrol->value.integer.value[i] = ice->spec.aureon.master[i] & ~WM_VOL_MUTE;
  502. return 0;
  503. }
  504. static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  505. {
  506. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  507. int ch, change = 0;
  508. snd_ice1712_save_gpio_status(ice);
  509. for (ch = 0; ch < 2; ch++) {
  510. if (ucontrol->value.integer.value[ch] != ice->spec.aureon.master[ch]) {
  511. int dac;
  512. ice->spec.aureon.master[ch] &= WM_VOL_MUTE;
  513. ice->spec.aureon.master[ch] |= ucontrol->value.integer.value[ch];
  514. for (dac = 0; dac < ice->num_total_dacs; dac += 2)
  515. wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
  516. ice->spec.aureon.vol[dac + ch],
  517. ice->spec.aureon.master[ch]);
  518. change = 1;
  519. }
  520. }
  521. snd_ice1712_restore_gpio_status(ice);
  522. return change;
  523. }
  524. /*
  525. * DAC volume attenuation mixer control
  526. */
  527. static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  528. {
  529. int voices = kcontrol->private_value >> 8;
  530. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  531. uinfo->count = voices;
  532. uinfo->value.integer.min = 0; /* mute (-101dB) */
  533. uinfo->value.integer.max = 0x7F; /* 0dB */
  534. return 0;
  535. }
  536. static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  537. {
  538. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  539. int i, ofs, voices;
  540. voices = kcontrol->private_value >> 8;
  541. ofs = kcontrol->private_value & 0xff;
  542. for (i = 0; i < voices; i++)
  543. ucontrol->value.integer.value[i] = ice->spec.aureon.vol[ofs+i] & ~WM_VOL_MUTE;
  544. return 0;
  545. }
  546. static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  547. {
  548. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  549. int i, idx, ofs, voices;
  550. int change = 0;
  551. voices = kcontrol->private_value >> 8;
  552. ofs = kcontrol->private_value & 0xff;
  553. snd_ice1712_save_gpio_status(ice);
  554. for (i = 0; i < voices; i++) {
  555. idx = WM_DAC_ATTEN + ofs + i;
  556. if (ucontrol->value.integer.value[i] != ice->spec.aureon.vol[ofs+i]) {
  557. ice->spec.aureon.vol[ofs+i] &= WM_VOL_MUTE;
  558. ice->spec.aureon.vol[ofs+i] |= ucontrol->value.integer.value[i];
  559. wm_set_vol(ice, idx, ice->spec.aureon.vol[ofs+i],
  560. ice->spec.aureon.master[i]);
  561. change = 1;
  562. }
  563. }
  564. snd_ice1712_restore_gpio_status(ice);
  565. return change;
  566. }
  567. /*
  568. * WM8770 mute control
  569. */
  570. static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  571. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  572. uinfo->count = kcontrol->private_value >> 8;
  573. uinfo->value.integer.min = 0;
  574. uinfo->value.integer.max = 1;
  575. return 0;
  576. }
  577. static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  578. {
  579. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  580. int voices, ofs, i;
  581. voices = kcontrol->private_value >> 8;
  582. ofs = kcontrol->private_value & 0xFF;
  583. for (i = 0; i < voices; i++)
  584. ucontrol->value.integer.value[i] = (ice->spec.aureon.vol[ofs+i] & WM_VOL_MUTE) ? 0 : 1;
  585. return 0;
  586. }
  587. static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  588. {
  589. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  590. int change = 0, voices, ofs, i;
  591. voices = kcontrol->private_value >> 8;
  592. ofs = kcontrol->private_value & 0xFF;
  593. snd_ice1712_save_gpio_status(ice);
  594. for (i = 0; i < voices; i++) {
  595. int val = (ice->spec.aureon.vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1;
  596. if (ucontrol->value.integer.value[i] != val) {
  597. ice->spec.aureon.vol[ofs + i] &= ~WM_VOL_MUTE;
  598. ice->spec.aureon.vol[ofs + i] |=
  599. ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
  600. wm_set_vol(ice, ofs + i, ice->spec.aureon.vol[ofs + i],
  601. ice->spec.aureon.master[i]);
  602. change = 1;
  603. }
  604. }
  605. snd_ice1712_restore_gpio_status(ice);
  606. return change;
  607. }
  608. /*
  609. * WM8770 master mute control
  610. */
  611. static int wm_master_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  612. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  613. uinfo->count = 2;
  614. uinfo->value.integer.min = 0;
  615. uinfo->value.integer.max = 1;
  616. return 0;
  617. }
  618. static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  619. {
  620. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  621. ucontrol->value.integer.value[0] = (ice->spec.aureon.master[0] & WM_VOL_MUTE) ? 0 : 1;
  622. ucontrol->value.integer.value[1] = (ice->spec.aureon.master[1] & WM_VOL_MUTE) ? 0 : 1;
  623. return 0;
  624. }
  625. static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  626. {
  627. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  628. int change = 0, i;
  629. snd_ice1712_save_gpio_status(ice);
  630. for (i = 0; i < 2; i++) {
  631. int val = (ice->spec.aureon.master[i] & WM_VOL_MUTE) ? 0 : 1;
  632. if (ucontrol->value.integer.value[i] != val) {
  633. int dac;
  634. ice->spec.aureon.master[i] &= ~WM_VOL_MUTE;
  635. ice->spec.aureon.master[i] |=
  636. ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
  637. for (dac = 0; dac < ice->num_total_dacs; dac += 2)
  638. wm_set_vol(ice, WM_DAC_ATTEN + dac + i,
  639. ice->spec.aureon.vol[dac + i],
  640. ice->spec.aureon.master[i]);
  641. change = 1;
  642. }
  643. }
  644. snd_ice1712_restore_gpio_status(ice);
  645. return change;
  646. }
  647. /* digital master volume */
  648. #define PCM_0dB 0xff
  649. #define PCM_RES 128 /* -64dB */
  650. #define PCM_MIN (PCM_0dB - PCM_RES)
  651. static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  652. {
  653. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  654. uinfo->count = 1;
  655. uinfo->value.integer.min = 0; /* mute (-64dB) */
  656. uinfo->value.integer.max = PCM_RES; /* 0dB */
  657. return 0;
  658. }
  659. static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  660. {
  661. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  662. unsigned short val;
  663. mutex_lock(&ice->gpio_mutex);
  664. val = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
  665. val = val > PCM_MIN ? (val - PCM_MIN) : 0;
  666. ucontrol->value.integer.value[0] = val;
  667. mutex_unlock(&ice->gpio_mutex);
  668. return 0;
  669. }
  670. static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  671. {
  672. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  673. unsigned short ovol, nvol;
  674. int change = 0;
  675. snd_ice1712_save_gpio_status(ice);
  676. nvol = ucontrol->value.integer.value[0];
  677. nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
  678. ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
  679. if (ovol != nvol) {
  680. wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */
  681. wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */
  682. change = 1;
  683. }
  684. snd_ice1712_restore_gpio_status(ice);
  685. return change;
  686. }
  687. /*
  688. * ADC mute control
  689. */
  690. static int wm_adc_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  691. {
  692. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  693. uinfo->count = 2;
  694. uinfo->value.integer.min = 0;
  695. uinfo->value.integer.max = 1;
  696. return 0;
  697. }
  698. static int wm_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  699. {
  700. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  701. unsigned short val;
  702. int i;
  703. mutex_lock(&ice->gpio_mutex);
  704. for (i = 0; i < 2; i++) {
  705. val = wm_get(ice, WM_ADC_GAIN + i);
  706. ucontrol->value.integer.value[i] = ~val>>5 & 0x1;
  707. }
  708. mutex_unlock(&ice->gpio_mutex);
  709. return 0;
  710. }
  711. static int wm_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  712. {
  713. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  714. unsigned short new, old;
  715. int i, change = 0;
  716. snd_ice1712_save_gpio_status(ice);
  717. for (i = 0; i < 2; i++) {
  718. old = wm_get(ice, WM_ADC_GAIN + i);
  719. new = (~ucontrol->value.integer.value[i]<<5&0x20) | (old&~0x20);
  720. if (new != old) {
  721. wm_put(ice, WM_ADC_GAIN + i, new);
  722. change = 1;
  723. }
  724. }
  725. snd_ice1712_restore_gpio_status(ice);
  726. return change;
  727. }
  728. /*
  729. * ADC gain mixer control
  730. */
  731. static int wm_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  732. {
  733. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  734. uinfo->count = 2;
  735. uinfo->value.integer.min = 0; /* -12dB */
  736. uinfo->value.integer.max = 0x1f; /* 19dB */
  737. return 0;
  738. }
  739. static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  740. {
  741. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  742. int i, idx;
  743. unsigned short vol;
  744. mutex_lock(&ice->gpio_mutex);
  745. for (i = 0; i < 2; i++) {
  746. idx = WM_ADC_GAIN + i;
  747. vol = wm_get(ice, idx) & 0x1f;
  748. ucontrol->value.integer.value[i] = vol;
  749. }
  750. mutex_unlock(&ice->gpio_mutex);
  751. return 0;
  752. }
  753. static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  754. {
  755. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  756. int i, idx;
  757. unsigned short ovol, nvol;
  758. int change = 0;
  759. snd_ice1712_save_gpio_status(ice);
  760. for (i = 0; i < 2; i++) {
  761. idx = WM_ADC_GAIN + i;
  762. nvol = ucontrol->value.integer.value[i];
  763. ovol = wm_get(ice, idx);
  764. if ((ovol & 0x1f) != nvol) {
  765. wm_put(ice, idx, nvol | (ovol & ~0x1f));
  766. change = 1;
  767. }
  768. }
  769. snd_ice1712_restore_gpio_status(ice);
  770. return change;
  771. }
  772. /*
  773. * ADC input mux mixer control
  774. */
  775. static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  776. {
  777. static char *texts[] = {
  778. "CD", //AIN1
  779. "Aux", //AIN2
  780. "Line", //AIN3
  781. "Mic", //AIN4
  782. "AC97" //AIN5
  783. };
  784. static char *universe_texts[] = {
  785. "Aux1", //AIN1
  786. "CD", //AIN2
  787. "Phono", //AIN3
  788. "Line", //AIN4
  789. "Aux2", //AIN5
  790. "Mic", //AIN6
  791. "Aux3", //AIN7
  792. "AC97" //AIN8
  793. };
  794. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  795. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  796. uinfo->count = 2;
  797. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
  798. uinfo->value.enumerated.items = 8;
  799. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  800. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  801. strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]);
  802. }
  803. else {
  804. uinfo->value.enumerated.items = 5;
  805. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  806. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  807. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  808. }
  809. return 0;
  810. }
  811. static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  812. {
  813. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  814. unsigned short val;
  815. mutex_lock(&ice->gpio_mutex);
  816. val = wm_get(ice, WM_ADC_MUX);
  817. ucontrol->value.enumerated.item[0] = val & 7;
  818. ucontrol->value.enumerated.item[1] = (val >> 4) & 7;
  819. mutex_unlock(&ice->gpio_mutex);
  820. return 0;
  821. }
  822. static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  823. {
  824. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  825. unsigned short oval, nval;
  826. int change;
  827. snd_ice1712_save_gpio_status(ice);
  828. oval = wm_get(ice, WM_ADC_MUX);
  829. nval = oval & ~0x77;
  830. nval |= ucontrol->value.enumerated.item[0] & 7;
  831. nval |= (ucontrol->value.enumerated.item[1] & 7) << 4;
  832. change = (oval != nval);
  833. if (change)
  834. wm_put(ice, WM_ADC_MUX, nval);
  835. snd_ice1712_restore_gpio_status(ice);
  836. return change;
  837. }
  838. /*
  839. * CS8415 Input mux
  840. */
  841. static int aureon_cs8415_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  842. {
  843. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  844. static char *aureon_texts[] = {
  845. "CD", //RXP0
  846. "Optical" //RXP1
  847. };
  848. static char *prodigy_texts[] = {
  849. "CD",
  850. "Coax"
  851. };
  852. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  853. uinfo->count = 1;
  854. uinfo->value.enumerated.items = 2;
  855. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  856. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  857. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
  858. strcpy(uinfo->value.enumerated.name, prodigy_texts[uinfo->value.enumerated.item]);
  859. else
  860. strcpy(uinfo->value.enumerated.name, aureon_texts[uinfo->value.enumerated.item]);
  861. return 0;
  862. }
  863. static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  864. {
  865. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  866. //snd_ice1712_save_gpio_status(ice);
  867. //val = aureon_cs8415_get(ice, CS8415_CTRL2);
  868. ucontrol->value.enumerated.item[0] = ice->spec.aureon.cs8415_mux;
  869. //snd_ice1712_restore_gpio_status(ice);
  870. return 0;
  871. }
  872. static int aureon_cs8415_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  873. {
  874. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  875. unsigned short oval, nval;
  876. int change;
  877. snd_ice1712_save_gpio_status(ice);
  878. oval = aureon_cs8415_get(ice, CS8415_CTRL2);
  879. nval = oval & ~0x07;
  880. nval |= ucontrol->value.enumerated.item[0] & 7;
  881. change = (oval != nval);
  882. if (change)
  883. aureon_cs8415_put(ice, CS8415_CTRL2, nval);
  884. snd_ice1712_restore_gpio_status(ice);
  885. ice->spec.aureon.cs8415_mux = ucontrol->value.enumerated.item[0];
  886. return change;
  887. }
  888. static int aureon_cs8415_rate_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  889. {
  890. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  891. uinfo->count = 1;
  892. uinfo->value.integer.min = 0;
  893. uinfo->value.integer.max = 192000;
  894. return 0;
  895. }
  896. static int aureon_cs8415_rate_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  897. {
  898. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  899. unsigned char ratio;
  900. ratio = aureon_cs8415_get(ice, CS8415_RATIO);
  901. ucontrol->value.integer.value[0] = (int)((unsigned int)ratio * 750);
  902. return 0;
  903. }
  904. /*
  905. * CS8415A Mute
  906. */
  907. static int aureon_cs8415_mute_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  908. {
  909. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  910. uinfo->count = 1;
  911. return 0;
  912. }
  913. static int aureon_cs8415_mute_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  914. {
  915. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  916. snd_ice1712_save_gpio_status(ice);
  917. ucontrol->value.integer.value[0] = (aureon_cs8415_get(ice, CS8415_CTRL1) & 0x20) ? 0 : 1;
  918. snd_ice1712_restore_gpio_status(ice);
  919. return 0;
  920. }
  921. static int aureon_cs8415_mute_put (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  922. {
  923. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  924. unsigned char oval, nval;
  925. int change;
  926. snd_ice1712_save_gpio_status(ice);
  927. oval = aureon_cs8415_get(ice, CS8415_CTRL1);
  928. if (ucontrol->value.integer.value[0])
  929. nval = oval & ~0x20;
  930. else
  931. nval = oval | 0x20;
  932. if ((change = (oval != nval)))
  933. aureon_cs8415_put(ice, CS8415_CTRL1, nval);
  934. snd_ice1712_restore_gpio_status(ice);
  935. return change;
  936. }
  937. /*
  938. * CS8415A Q-Sub info
  939. */
  940. static int aureon_cs8415_qsub_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  941. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  942. uinfo->count = 10;
  943. return 0;
  944. }
  945. static int aureon_cs8415_qsub_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
  946. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  947. snd_ice1712_save_gpio_status(ice);
  948. aureon_cs8415_read(ice, CS8415_QSUB, ucontrol->value.bytes.data, 10);
  949. snd_ice1712_restore_gpio_status(ice);
  950. return 0;
  951. }
  952. static int aureon_cs8415_spdif_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  953. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  954. uinfo->count = 1;
  955. return 0;
  956. }
  957. static int aureon_cs8415_mask_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
  958. memset(ucontrol->value.iec958.status, 0xFF, 24);
  959. return 0;
  960. }
  961. static int aureon_cs8415_spdif_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
  962. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  963. snd_ice1712_save_gpio_status(ice);
  964. aureon_cs8415_read(ice, CS8415_C_BUFFER, ucontrol->value.iec958.status, 24);
  965. snd_ice1712_restore_gpio_status(ice);
  966. return 0;
  967. }
  968. /*
  969. * Headphone Amplifier
  970. */
  971. static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable)
  972. {
  973. unsigned int tmp, tmp2;
  974. tmp2 = tmp = snd_ice1712_gpio_read(ice);
  975. if (enable)
  976. tmp |= AUREON_HP_SEL;
  977. else
  978. tmp &= ~ AUREON_HP_SEL;
  979. if (tmp != tmp2) {
  980. snd_ice1712_gpio_write(ice, tmp);
  981. return 1;
  982. }
  983. return 0;
  984. }
  985. static int aureon_get_headphone_amp(struct snd_ice1712 *ice)
  986. {
  987. unsigned int tmp = snd_ice1712_gpio_read(ice);
  988. return ( tmp & AUREON_HP_SEL )!= 0;
  989. }
  990. #define aureon_hpamp_info aureon_mono_bool_info
  991. static int aureon_hpamp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  992. {
  993. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  994. ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);
  995. return 0;
  996. }
  997. static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  998. {
  999. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1000. return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]);
  1001. }
  1002. /*
  1003. * Deemphasis
  1004. */
  1005. #define aureon_deemp_info aureon_mono_bool_info
  1006. static int aureon_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1007. {
  1008. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1009. ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
  1010. return 0;
  1011. }
  1012. static int aureon_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1013. {
  1014. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1015. int temp, temp2;
  1016. temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
  1017. if (ucontrol->value.integer.value[0])
  1018. temp |= 0xf;
  1019. else
  1020. temp &= ~0xf;
  1021. if (temp != temp2) {
  1022. wm_put(ice, WM_DAC_CTRL2, temp);
  1023. return 1;
  1024. }
  1025. return 0;
  1026. }
  1027. /*
  1028. * ADC Oversampling
  1029. */
  1030. static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  1031. {
  1032. static char *texts[2] = { "128x", "64x" };
  1033. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1034. uinfo->count = 1;
  1035. uinfo->value.enumerated.items = 2;
  1036. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1037. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1038. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1039. return 0;
  1040. }
  1041. static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1042. {
  1043. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1044. ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
  1045. return 0;
  1046. }
  1047. static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1048. {
  1049. int temp, temp2;
  1050. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1051. temp2 = temp = wm_get(ice, WM_MASTER);
  1052. if (ucontrol->value.enumerated.item[0])
  1053. temp |= 0x8;
  1054. else
  1055. temp &= ~0x8;
  1056. if (temp != temp2) {
  1057. wm_put(ice, WM_MASTER, temp);
  1058. return 1;
  1059. }
  1060. return 0;
  1061. }
  1062. /*
  1063. * mixers
  1064. */
  1065. static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
  1066. {
  1067. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1068. .name = "Master Playback Switch",
  1069. .info = wm_master_mute_info,
  1070. .get = wm_master_mute_get,
  1071. .put = wm_master_mute_put
  1072. },
  1073. {
  1074. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1075. .name = "Master Playback Volume",
  1076. .info = wm_master_vol_info,
  1077. .get = wm_master_vol_get,
  1078. .put = wm_master_vol_put
  1079. },
  1080. {
  1081. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1082. .name = "Front Playback Switch",
  1083. .info = wm_mute_info,
  1084. .get = wm_mute_get,
  1085. .put = wm_mute_put,
  1086. .private_value = (2 << 8) | 0
  1087. },
  1088. {
  1089. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1090. .name = "Front Playback Volume",
  1091. .info = wm_vol_info,
  1092. .get = wm_vol_get,
  1093. .put = wm_vol_put,
  1094. .private_value = (2 << 8) | 0
  1095. },
  1096. {
  1097. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1098. .name = "Rear Playback Switch",
  1099. .info = wm_mute_info,
  1100. .get = wm_mute_get,
  1101. .put = wm_mute_put,
  1102. .private_value = (2 << 8) | 2
  1103. },
  1104. {
  1105. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1106. .name = "Rear Playback Volume",
  1107. .info = wm_vol_info,
  1108. .get = wm_vol_get,
  1109. .put = wm_vol_put,
  1110. .private_value = (2 << 8) | 2
  1111. },
  1112. {
  1113. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1114. .name = "Center Playback Switch",
  1115. .info = wm_mute_info,
  1116. .get = wm_mute_get,
  1117. .put = wm_mute_put,
  1118. .private_value = (1 << 8) | 4
  1119. },
  1120. {
  1121. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1122. .name = "Center Playback Volume",
  1123. .info = wm_vol_info,
  1124. .get = wm_vol_get,
  1125. .put = wm_vol_put,
  1126. .private_value = (1 << 8) | 4
  1127. },
  1128. {
  1129. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1130. .name = "LFE Playback Switch",
  1131. .info = wm_mute_info,
  1132. .get = wm_mute_get,
  1133. .put = wm_mute_put,
  1134. .private_value = (1 << 8) | 5
  1135. },
  1136. {
  1137. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1138. .name = "LFE Playback Volume",
  1139. .info = wm_vol_info,
  1140. .get = wm_vol_get,
  1141. .put = wm_vol_put,
  1142. .private_value = (1 << 8) | 5
  1143. },
  1144. {
  1145. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1146. .name = "Side Playback Switch",
  1147. .info = wm_mute_info,
  1148. .get = wm_mute_get,
  1149. .put = wm_mute_put,
  1150. .private_value = (2 << 8) | 6
  1151. },
  1152. {
  1153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1154. .name = "Side Playback Volume",
  1155. .info = wm_vol_info,
  1156. .get = wm_vol_get,
  1157. .put = wm_vol_put,
  1158. .private_value = (2 << 8) | 6
  1159. }
  1160. };
  1161. static struct snd_kcontrol_new wm_controls[] __devinitdata = {
  1162. {
  1163. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1164. .name = "PCM Playback Switch",
  1165. .info = wm_pcm_mute_info,
  1166. .get = wm_pcm_mute_get,
  1167. .put = wm_pcm_mute_put
  1168. },
  1169. {
  1170. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1171. .name = "PCM Playback Volume",
  1172. .info = wm_pcm_vol_info,
  1173. .get = wm_pcm_vol_get,
  1174. .put = wm_pcm_vol_put
  1175. },
  1176. {
  1177. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1178. .name = "Capture Switch",
  1179. .info = wm_adc_mute_info,
  1180. .get = wm_adc_mute_get,
  1181. .put = wm_adc_mute_put,
  1182. },
  1183. {
  1184. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1185. .name = "Capture Volume",
  1186. .info = wm_adc_vol_info,
  1187. .get = wm_adc_vol_get,
  1188. .put = wm_adc_vol_put
  1189. },
  1190. {
  1191. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1192. .name = "Capture Source",
  1193. .info = wm_adc_mux_info,
  1194. .get = wm_adc_mux_get,
  1195. .put = wm_adc_mux_put,
  1196. .private_value = 5
  1197. },
  1198. {
  1199. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1200. .name = "External Amplifier",
  1201. .info = aureon_hpamp_info,
  1202. .get = aureon_hpamp_get,
  1203. .put = aureon_hpamp_put
  1204. },
  1205. {
  1206. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1207. .name = "DAC Deemphasis Switch",
  1208. .info = aureon_deemp_info,
  1209. .get = aureon_deemp_get,
  1210. .put = aureon_deemp_put
  1211. },
  1212. {
  1213. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1214. .name = "ADC Oversampling",
  1215. .info = aureon_oversampling_info,
  1216. .get = aureon_oversampling_get,
  1217. .put = aureon_oversampling_put
  1218. }
  1219. };
  1220. static struct snd_kcontrol_new ac97_controls[] __devinitdata = {
  1221. {
  1222. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1223. .name = "AC97 Playback Switch",
  1224. .info = aureon_ac97_mmute_info,
  1225. .get = aureon_ac97_mmute_get,
  1226. .put = aureon_ac97_mmute_put,
  1227. .private_value = AC97_MASTER
  1228. },
  1229. {
  1230. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1231. .name = "AC97 Playback Volume",
  1232. .info = aureon_ac97_vol_info,
  1233. .get = aureon_ac97_vol_get,
  1234. .put = aureon_ac97_vol_put,
  1235. .private_value = AC97_MASTER|AUREON_AC97_STEREO
  1236. },
  1237. {
  1238. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1239. .name = "CD Playback Switch",
  1240. .info = aureon_ac97_mute_info,
  1241. .get = aureon_ac97_mute_get,
  1242. .put = aureon_ac97_mute_put,
  1243. .private_value = AC97_CD
  1244. },
  1245. {
  1246. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1247. .name = "CD Playback Volume",
  1248. .info = aureon_ac97_vol_info,
  1249. .get = aureon_ac97_vol_get,
  1250. .put = aureon_ac97_vol_put,
  1251. .private_value = AC97_CD|AUREON_AC97_STEREO
  1252. },
  1253. {
  1254. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1255. .name = "Aux Playback Switch",
  1256. .info = aureon_ac97_mute_info,
  1257. .get = aureon_ac97_mute_get,
  1258. .put = aureon_ac97_mute_put,
  1259. .private_value = AC97_AUX,
  1260. },
  1261. {
  1262. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1263. .name = "Aux Playback Volume",
  1264. .info = aureon_ac97_vol_info,
  1265. .get = aureon_ac97_vol_get,
  1266. .put = aureon_ac97_vol_put,
  1267. .private_value = AC97_AUX|AUREON_AC97_STEREO
  1268. },
  1269. {
  1270. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1271. .name = "Line Playback Switch",
  1272. .info = aureon_ac97_mute_info,
  1273. .get = aureon_ac97_mute_get,
  1274. .put = aureon_ac97_mute_put,
  1275. .private_value = AC97_LINE
  1276. },
  1277. {
  1278. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1279. .name = "Line Playback Volume",
  1280. .info = aureon_ac97_vol_info,
  1281. .get = aureon_ac97_vol_get,
  1282. .put = aureon_ac97_vol_put,
  1283. .private_value = AC97_LINE|AUREON_AC97_STEREO
  1284. },
  1285. {
  1286. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1287. .name = "Mic Playback Switch",
  1288. .info = aureon_ac97_mute_info,
  1289. .get = aureon_ac97_mute_get,
  1290. .put = aureon_ac97_mute_put,
  1291. .private_value = AC97_MIC
  1292. },
  1293. {
  1294. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1295. .name = "Mic Playback Volume",
  1296. .info = aureon_ac97_vol_info,
  1297. .get = aureon_ac97_vol_get,
  1298. .put = aureon_ac97_vol_put,
  1299. .private_value = AC97_MIC
  1300. },
  1301. {
  1302. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1303. .name = "Mic Boost (+20dB)",
  1304. .info = aureon_ac97_micboost_info,
  1305. .get = aureon_ac97_micboost_get,
  1306. .put = aureon_ac97_micboost_put
  1307. }
  1308. };
  1309. static struct snd_kcontrol_new universe_ac97_controls[] __devinitdata = {
  1310. {
  1311. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1312. .name = "AC97 Playback Switch",
  1313. .info = aureon_ac97_mmute_info,
  1314. .get = aureon_ac97_mmute_get,
  1315. .put = aureon_ac97_mmute_put,
  1316. .private_value = AC97_MASTER
  1317. },
  1318. {
  1319. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1320. .name = "AC97 Playback Volume",
  1321. .info = aureon_ac97_vol_info,
  1322. .get = aureon_ac97_vol_get,
  1323. .put = aureon_ac97_vol_put,
  1324. .private_value = AC97_MASTER|AUREON_AC97_STEREO
  1325. },
  1326. {
  1327. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1328. .name = "CD Playback Switch",
  1329. .info = aureon_ac97_mute_info,
  1330. .get = aureon_ac97_mute_get,
  1331. .put = aureon_ac97_mute_put,
  1332. .private_value = AC97_AUX
  1333. },
  1334. {
  1335. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1336. .name = "CD Playback Volume",
  1337. .info = aureon_ac97_vol_info,
  1338. .get = aureon_ac97_vol_get,
  1339. .put = aureon_ac97_vol_put,
  1340. .private_value = AC97_AUX|AUREON_AC97_STEREO
  1341. },
  1342. {
  1343. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1344. .name = "Phono Playback Switch",
  1345. .info = aureon_ac97_mute_info,
  1346. .get = aureon_ac97_mute_get,
  1347. .put = aureon_ac97_mute_put,
  1348. .private_value = AC97_CD,
  1349. },
  1350. {
  1351. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1352. .name = "Phono Playback Volume",
  1353. .info = aureon_ac97_vol_info,
  1354. .get = aureon_ac97_vol_get,
  1355. .put = aureon_ac97_vol_put,
  1356. .private_value = AC97_CD|AUREON_AC97_STEREO
  1357. },
  1358. {
  1359. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1360. .name = "Line Playback Switch",
  1361. .info = aureon_ac97_mute_info,
  1362. .get = aureon_ac97_mute_get,
  1363. .put = aureon_ac97_mute_put,
  1364. .private_value = AC97_LINE
  1365. },
  1366. {
  1367. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1368. .name = "Line Playback Volume",
  1369. .info = aureon_ac97_vol_info,
  1370. .get = aureon_ac97_vol_get,
  1371. .put = aureon_ac97_vol_put,
  1372. .private_value = AC97_LINE|AUREON_AC97_STEREO
  1373. },
  1374. {
  1375. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1376. .name = "Mic Playback Switch",
  1377. .info = aureon_ac97_mute_info,
  1378. .get = aureon_ac97_mute_get,
  1379. .put = aureon_ac97_mute_put,
  1380. .private_value = AC97_MIC
  1381. },
  1382. {
  1383. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1384. .name = "Mic Playback Volume",
  1385. .info = aureon_ac97_vol_info,
  1386. .get = aureon_ac97_vol_get,
  1387. .put = aureon_ac97_vol_put,
  1388. .private_value = AC97_MIC
  1389. },
  1390. {
  1391. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1392. .name = "Mic Boost (+20dB)",
  1393. .info = aureon_ac97_micboost_info,
  1394. .get = aureon_ac97_micboost_get,
  1395. .put = aureon_ac97_micboost_put
  1396. },
  1397. {
  1398. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1399. .name = "Aux Playback Switch",
  1400. .info = aureon_ac97_mute_info,
  1401. .get = aureon_ac97_mute_get,
  1402. .put = aureon_ac97_mute_put,
  1403. .private_value = AC97_VIDEO,
  1404. },
  1405. {
  1406. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1407. .name = "Aux Playback Volume",
  1408. .info = aureon_ac97_vol_info,
  1409. .get = aureon_ac97_vol_get,
  1410. .put = aureon_ac97_vol_put,
  1411. .private_value = AC97_VIDEO|AUREON_AC97_STEREO
  1412. }
  1413. };
  1414. static struct snd_kcontrol_new cs8415_controls[] __devinitdata = {
  1415. {
  1416. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1417. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH),
  1418. .info = aureon_cs8415_mute_info,
  1419. .get = aureon_cs8415_mute_get,
  1420. .put = aureon_cs8415_mute_put
  1421. },
  1422. {
  1423. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1424. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Source",
  1425. .info = aureon_cs8415_mux_info,
  1426. .get = aureon_cs8415_mux_get,
  1427. .put = aureon_cs8415_mux_put,
  1428. },
  1429. {
  1430. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1431. .name = SNDRV_CTL_NAME_IEC958("Q-subcode ",CAPTURE,DEFAULT),
  1432. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1433. .info = aureon_cs8415_qsub_info,
  1434. .get = aureon_cs8415_qsub_get,
  1435. },
  1436. {
  1437. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1438. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
  1439. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1440. .info = aureon_cs8415_spdif_info,
  1441. .get = aureon_cs8415_mask_get
  1442. },
  1443. {
  1444. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1445. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
  1446. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1447. .info = aureon_cs8415_spdif_info,
  1448. .get = aureon_cs8415_spdif_get
  1449. },
  1450. {
  1451. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1452. .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Rate",
  1453. .access =SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1454. .info = aureon_cs8415_rate_info,
  1455. .get = aureon_cs8415_rate_get
  1456. }
  1457. };
  1458. static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
  1459. {
  1460. unsigned int i, counts;
  1461. int err;
  1462. counts = ARRAY_SIZE(aureon_dac_controls);
  1463. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY)
  1464. counts -= 2; /* no side */
  1465. for (i = 0; i < counts; i++) {
  1466. err = snd_ctl_add(ice->card, snd_ctl_new1(&aureon_dac_controls[i], ice));
  1467. if (err < 0)
  1468. return err;
  1469. }
  1470. for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
  1471. err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice));
  1472. if (err < 0)
  1473. return err;
  1474. }
  1475. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
  1476. for (i = 0; i < ARRAY_SIZE(universe_ac97_controls); i++) {
  1477. err = snd_ctl_add(ice->card, snd_ctl_new1(&universe_ac97_controls[i], ice));
  1478. if (err < 0)
  1479. return err;
  1480. }
  1481. }
  1482. else if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT) {
  1483. for (i = 0; i < ARRAY_SIZE(ac97_controls); i++) {
  1484. err = snd_ctl_add(ice->card, snd_ctl_new1(&ac97_controls[i], ice));
  1485. if (err < 0)
  1486. return err;
  1487. }
  1488. }
  1489. if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT) {
  1490. unsigned char id;
  1491. snd_ice1712_save_gpio_status(ice);
  1492. id = aureon_cs8415_get(ice, CS8415_ID);
  1493. if (id != 0x41)
  1494. snd_printk(KERN_INFO "No CS8415 chip. Skipping CS8415 controls.\n");
  1495. else if ((id & 0x0F) != 0x01)
  1496. snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1));
  1497. else {
  1498. for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) {
  1499. struct snd_kcontrol *kctl;
  1500. err = snd_ctl_add(ice->card, (kctl = snd_ctl_new1(&cs8415_controls[i], ice)));
  1501. if (err < 0)
  1502. return err;
  1503. if (i > 1)
  1504. kctl->id.device = ice->pcm->device;
  1505. }
  1506. }
  1507. snd_ice1712_restore_gpio_status(ice);
  1508. }
  1509. return 0;
  1510. }
  1511. /*
  1512. * initialize the chip
  1513. */
  1514. static int __devinit aureon_init(struct snd_ice1712 *ice)
  1515. {
  1516. static unsigned short wm_inits_aureon[] = {
  1517. /* These come first to reduce init pop noise */
  1518. 0x1b, 0x044, /* ADC Mux (AC'97 source) */
  1519. 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
  1520. 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
  1521. 0x18, 0x000, /* All power-up */
  1522. 0x16, 0x122, /* I2S, normal polarity, 24bit */
  1523. 0x17, 0x022, /* 256fs, slave mode */
  1524. 0x00, 0, /* DAC1 analog mute */
  1525. 0x01, 0, /* DAC2 analog mute */
  1526. 0x02, 0, /* DAC3 analog mute */
  1527. 0x03, 0, /* DAC4 analog mute */
  1528. 0x04, 0, /* DAC5 analog mute */
  1529. 0x05, 0, /* DAC6 analog mute */
  1530. 0x06, 0, /* DAC7 analog mute */
  1531. 0x07, 0, /* DAC8 analog mute */
  1532. 0x08, 0x100, /* master analog mute */
  1533. 0x09, 0xff, /* DAC1 digital full */
  1534. 0x0a, 0xff, /* DAC2 digital full */
  1535. 0x0b, 0xff, /* DAC3 digital full */
  1536. 0x0c, 0xff, /* DAC4 digital full */
  1537. 0x0d, 0xff, /* DAC5 digital full */
  1538. 0x0e, 0xff, /* DAC6 digital full */
  1539. 0x0f, 0xff, /* DAC7 digital full */
  1540. 0x10, 0xff, /* DAC8 digital full */
  1541. 0x11, 0x1ff, /* master digital full */
  1542. 0x12, 0x000, /* phase normal */
  1543. 0x13, 0x090, /* unmute DAC L/R */
  1544. 0x14, 0x000, /* all unmute */
  1545. 0x15, 0x000, /* no deemphasis, no ZFLG */
  1546. 0x19, 0x000, /* -12dB ADC/L */
  1547. 0x1a, 0x000, /* -12dB ADC/R */
  1548. (unsigned short)-1
  1549. };
  1550. static unsigned short wm_inits_prodigy[] = {
  1551. /* These come first to reduce init pop noise */
  1552. 0x1b, 0x000, /* ADC Mux */
  1553. 0x1c, 0x009, /* Out Mux1 */
  1554. 0x1d, 0x009, /* Out Mux2 */
  1555. 0x18, 0x000, /* All power-up */
  1556. 0x16, 0x022, /* I2S, normal polarity, 24bit, high-pass on */
  1557. 0x17, 0x006, /* 128fs, slave mode */
  1558. 0x00, 0, /* DAC1 analog mute */
  1559. 0x01, 0, /* DAC2 analog mute */
  1560. 0x02, 0, /* DAC3 analog mute */
  1561. 0x03, 0, /* DAC4 analog mute */
  1562. 0x04, 0, /* DAC5 analog mute */
  1563. 0x05, 0, /* DAC6 analog mute */
  1564. 0x06, 0, /* DAC7 analog mute */
  1565. 0x07, 0, /* DAC8 analog mute */
  1566. 0x08, 0x100, /* master analog mute */
  1567. 0x09, 0x7f, /* DAC1 digital full */
  1568. 0x0a, 0x7f, /* DAC2 digital full */
  1569. 0x0b, 0x7f, /* DAC3 digital full */
  1570. 0x0c, 0x7f, /* DAC4 digital full */
  1571. 0x0d, 0x7f, /* DAC5 digital full */
  1572. 0x0e, 0x7f, /* DAC6 digital full */
  1573. 0x0f, 0x7f, /* DAC7 digital full */
  1574. 0x10, 0x7f, /* DAC8 digital full */
  1575. 0x11, 0x1FF, /* master digital full */
  1576. 0x12, 0x000, /* phase normal */
  1577. 0x13, 0x090, /* unmute DAC L/R */
  1578. 0x14, 0x000, /* all unmute */
  1579. 0x15, 0x000, /* no deemphasis, no ZFLG */
  1580. 0x19, 0x000, /* -12dB ADC/L */
  1581. 0x1a, 0x000, /* -12dB ADC/R */
  1582. (unsigned short)-1
  1583. };
  1584. static unsigned short cs_inits[] = {
  1585. 0x0441, /* RUN */
  1586. 0x0180, /* no mute, OMCK output on RMCK pin */
  1587. 0x0201, /* S/PDIF source on RXP1 */
  1588. 0x0605, /* slave, 24bit, MSB on second OSCLK, SDOUT for right channel when OLRCK is high */
  1589. (unsigned short)-1
  1590. };
  1591. unsigned int tmp;
  1592. unsigned short *p;
  1593. int err, i;
  1594. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY) {
  1595. ice->num_total_dacs = 6;
  1596. ice->num_total_adcs = 2;
  1597. } else {
  1598. /* aureon 7.1 and prodigy 7.1 */
  1599. ice->num_total_dacs = 8;
  1600. ice->num_total_adcs = 2;
  1601. }
  1602. /* to remeber the register values of CS8415 */
  1603. ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  1604. if (! ice->akm)
  1605. return -ENOMEM;
  1606. ice->akm_codecs = 1;
  1607. if ((err = aureon_ac97_init(ice)) != 0)
  1608. return err;
  1609. snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */
  1610. /* reset the wm codec as the SPI mode */
  1611. snd_ice1712_save_gpio_status(ice);
  1612. snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RESET|AUREON_WM_CS|AUREON_CS8415_CS|AUREON_HP_SEL));
  1613. tmp = snd_ice1712_gpio_read(ice);
  1614. tmp &= ~AUREON_WM_RESET;
  1615. snd_ice1712_gpio_write(ice, tmp);
  1616. udelay(1);
  1617. tmp |= AUREON_WM_CS | AUREON_CS8415_CS;
  1618. snd_ice1712_gpio_write(ice, tmp);
  1619. udelay(1);
  1620. tmp |= AUREON_WM_RESET;
  1621. snd_ice1712_gpio_write(ice, tmp);
  1622. udelay(1);
  1623. /* initialize WM8770 codec */
  1624. if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71 ||
  1625. ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT)
  1626. p = wm_inits_prodigy;
  1627. else
  1628. p = wm_inits_aureon;
  1629. for (; *p != (unsigned short)-1; p += 2)
  1630. wm_put(ice, p[0], p[1]);
  1631. /* initialize CS8415A codec */
  1632. if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT) {
  1633. for (p = cs_inits; *p != (unsigned short)-1; p++)
  1634. aureon_spi_write(ice, AUREON_CS8415_CS, *p | 0x200000, 24);
  1635. ice->spec.aureon.cs8415_mux = 1;
  1636. aureon_set_headphone_amp(ice, 1);
  1637. }
  1638. snd_ice1712_restore_gpio_status(ice);
  1639. ice->spec.aureon.master[0] = WM_VOL_MUTE;
  1640. ice->spec.aureon.master[1] = WM_VOL_MUTE;
  1641. for (i = 0; i < ice->num_total_dacs; i++) {
  1642. ice->spec.aureon.vol[i] = WM_VOL_MUTE;
  1643. wm_set_vol(ice, i, ice->spec.aureon.vol[i], ice->spec.aureon.master[i % 2]);
  1644. }
  1645. return 0;
  1646. }
  1647. /*
  1648. * Aureon boards don't provide the EEPROM data except for the vendor IDs.
  1649. * hence the driver needs to sets up it properly.
  1650. */
  1651. static unsigned char aureon51_eeprom[] __devinitdata = {
  1652. 0x0a, /* SYSCONF: clock 512, spdif-in/ADC, 3DACs */
  1653. 0x80, /* ACLINK: I2S */
  1654. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1655. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  1656. 0xff, /* GPIO_DIR */
  1657. 0xff, /* GPIO_DIR1 */
  1658. 0x5f, /* GPIO_DIR2 */
  1659. 0x00, /* GPIO_MASK */
  1660. 0x00, /* GPIO_MASK1 */
  1661. 0x00, /* GPIO_MASK2 */
  1662. 0x00, /* GPIO_STATE */
  1663. 0x00, /* GPIO_STATE1 */
  1664. 0x00, /* GPIO_STATE2 */
  1665. };
  1666. static unsigned char aureon71_eeprom[] __devinitdata = {
  1667. 0x0b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
  1668. 0x80, /* ACLINK: I2S */
  1669. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1670. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  1671. 0xff, /* GPIO_DIR */
  1672. 0xff, /* GPIO_DIR1 */
  1673. 0x5f, /* GPIO_DIR2 */
  1674. 0x00, /* GPIO_MASK */
  1675. 0x00, /* GPIO_MASK1 */
  1676. 0x00, /* GPIO_MASK2 */
  1677. 0x00, /* GPIO_STATE */
  1678. 0x00, /* GPIO_STATE1 */
  1679. 0x00, /* GPIO_STATE2 */
  1680. };
  1681. static unsigned char prodigy71_eeprom[] __devinitdata = {
  1682. 0x0b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
  1683. 0x80, /* ACLINK: I2S */
  1684. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1685. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  1686. 0xff, /* GPIO_DIR */
  1687. 0xff, /* GPIO_DIR1 */
  1688. 0x5f, /* GPIO_DIR2 */
  1689. 0x00, /* GPIO_MASK */
  1690. 0x00, /* GPIO_MASK1 */
  1691. 0x00, /* GPIO_MASK2 */
  1692. 0x00, /* GPIO_STATE */
  1693. 0x00, /* GPIO_STATE1 */
  1694. 0x00, /* GPIO_STATE2 */
  1695. };
  1696. static unsigned char prodigy71lt_eeprom[] __devinitdata = {
  1697. 0x0b, /* SYSCINF: clock 512, spdif-in/ADC, 4DACs */
  1698. 0x80, /* ACLINK: I2S */
  1699. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1700. 0xc3, /* SPDUF: out-en, out-int */
  1701. 0x00, /* GPIO_DIR */
  1702. 0x07, /* GPIO_DIR1 */
  1703. 0x00, /* GPIO_DIR2 */
  1704. 0xff, /* GPIO_MASK */
  1705. 0xf8, /* GPIO_MASK1 */
  1706. 0xff, /* GPIO_MASK2 */
  1707. 0x00, /* GPIO_STATE */
  1708. 0x00, /* GPIO_STATE1 */
  1709. 0x00, /* GPIO_STATE2 */
  1710. };
  1711. /* entry point */
  1712. struct snd_ice1712_card_info snd_vt1724_aureon_cards[] __devinitdata = {
  1713. {
  1714. .subvendor = VT1724_SUBDEVICE_AUREON51_SKY,
  1715. .name = "Terratec Aureon 5.1-Sky",
  1716. .model = "aureon51",
  1717. .chip_init = aureon_init,
  1718. .build_controls = aureon_add_controls,
  1719. .eeprom_size = sizeof(aureon51_eeprom),
  1720. .eeprom_data = aureon51_eeprom,
  1721. .driver = "Aureon51",
  1722. },
  1723. {
  1724. .subvendor = VT1724_SUBDEVICE_AUREON71_SPACE,
  1725. .name = "Terratec Aureon 7.1-Space",
  1726. .model = "aureon71",
  1727. .chip_init = aureon_init,
  1728. .build_controls = aureon_add_controls,
  1729. .eeprom_size = sizeof(aureon71_eeprom),
  1730. .eeprom_data = aureon71_eeprom,
  1731. .driver = "Aureon71",
  1732. },
  1733. {
  1734. .subvendor = VT1724_SUBDEVICE_AUREON71_UNIVERSE,
  1735. .name = "Terratec Aureon 7.1-Universe",
  1736. .model = "universe",
  1737. .chip_init = aureon_init,
  1738. .build_controls = aureon_add_controls,
  1739. .eeprom_size = sizeof(aureon71_eeprom),
  1740. .eeprom_data = aureon71_eeprom,
  1741. .driver = "Aureon71Universe",
  1742. },
  1743. {
  1744. .subvendor = VT1724_SUBDEVICE_PRODIGY71,
  1745. .name = "Audiotrak Prodigy 7.1",
  1746. .model = "prodigy71",
  1747. .chip_init = aureon_init,
  1748. .build_controls = aureon_add_controls,
  1749. .eeprom_size = sizeof(prodigy71_eeprom),
  1750. .eeprom_data = prodigy71_eeprom,
  1751. .driver = "Prodigy71", /* should be identical with Aureon71 */
  1752. },
  1753. {
  1754. .subvendor = VT1724_SUBDEVICE_PRODIGY71LT,
  1755. .name = "Audiotrak Prodigy 7.1 LT",
  1756. .model = "prodigy71lt",
  1757. .chip_init = aureon_init,
  1758. .build_controls = aureon_add_controls,
  1759. .eeprom_size = sizeof(prodigy71lt_eeprom),
  1760. .eeprom_data = prodigy71lt_eeprom,
  1761. .driver = "Prodigy71LT",
  1762. },
  1763. { } /* terminator */
  1764. };