aureon.c 54 KB

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