prodigy_hifi.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for Audiotrak Prodigy 7.1 Hifi
  5. * based on pontis.c
  6. *
  7. * Copyright (c) 2007 Julian Scheel <julian@jusst.de>
  8. * Copyright (c) 2007 allank
  9. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. #include <asm/io.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/init.h>
  30. #include <linux/slab.h>
  31. #include <linux/mutex.h>
  32. #include <sound/core.h>
  33. #include <sound/info.h>
  34. #include <sound/tlv.h>
  35. #include "ice1712.h"
  36. #include "envy24ht.h"
  37. #include "prodigy_hifi.h"
  38. struct prodigy_hifi_spec {
  39. unsigned short master[2];
  40. unsigned short vol[8];
  41. };
  42. /* I2C addresses */
  43. #define WM_DEV 0x34
  44. /* WM8776 registers */
  45. #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
  46. #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
  47. #define WM_HP_MASTER 0x02 /* headphone master (both channels),
  48. override LLR */
  49. #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
  50. #define WM_DAC_ATTEN_R 0x04
  51. #define WM_DAC_MASTER 0x05
  52. #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
  53. #define WM_DAC_CTRL1 0x07
  54. #define WM_DAC_MUTE 0x08
  55. #define WM_DAC_CTRL2 0x09
  56. #define WM_DAC_INT 0x0a
  57. #define WM_ADC_INT 0x0b
  58. #define WM_MASTER_CTRL 0x0c
  59. #define WM_POWERDOWN 0x0d
  60. #define WM_ADC_ATTEN_L 0x0e
  61. #define WM_ADC_ATTEN_R 0x0f
  62. #define WM_ALC_CTRL1 0x10
  63. #define WM_ALC_CTRL2 0x11
  64. #define WM_ALC_CTRL3 0x12
  65. #define WM_NOISE_GATE 0x13
  66. #define WM_LIMITER 0x14
  67. #define WM_ADC_MUX 0x15
  68. #define WM_OUT_MUX 0x16
  69. #define WM_RESET 0x17
  70. /* Analog Recording Source :- Mic, LineIn, CD/Video, */
  71. /* implement capture source select control for WM8776 */
  72. #define WM_AIN1 "AIN1"
  73. #define WM_AIN2 "AIN2"
  74. #define WM_AIN3 "AIN3"
  75. #define WM_AIN4 "AIN4"
  76. #define WM_AIN5 "AIN5"
  77. /* GPIO pins of envy24ht connected to wm8766 */
  78. #define WM8766_SPI_CLK (1<<17) /* CLK, Pin97 on ICE1724 */
  79. #define WM8766_SPI_MD (1<<16) /* DATA VT1724 -> WM8766, Pin96 */
  80. #define WM8766_SPI_ML (1<<18) /* Latch, Pin98 */
  81. /* WM8766 registers */
  82. #define WM8766_DAC_CTRL 0x02 /* DAC Control */
  83. #define WM8766_INT_CTRL 0x03 /* Interface Control */
  84. #define WM8766_DAC_CTRL2 0x09
  85. #define WM8766_DAC_CTRL3 0x0a
  86. #define WM8766_RESET 0x1f
  87. #define WM8766_LDA1 0x00
  88. #define WM8766_LDA2 0x04
  89. #define WM8766_LDA3 0x06
  90. #define WM8766_RDA1 0x01
  91. #define WM8766_RDA2 0x05
  92. #define WM8766_RDA3 0x07
  93. #define WM8766_MUTE1 0x0C
  94. #define WM8766_MUTE2 0x0F
  95. /*
  96. * Prodigy HD2
  97. */
  98. #define AK4396_ADDR 0x00
  99. #define AK4396_CSN (1 << 8) /* CSN->GPIO8, pin 75 */
  100. #define AK4396_CCLK (1 << 9) /* CCLK->GPIO9, pin 76 */
  101. #define AK4396_CDTI (1 << 10) /* CDTI->GPIO10, pin 77 */
  102. /* ak4396 registers */
  103. #define AK4396_CTRL1 0x00
  104. #define AK4396_CTRL2 0x01
  105. #define AK4396_CTRL3 0x02
  106. #define AK4396_LCH_ATT 0x03
  107. #define AK4396_RCH_ATT 0x04
  108. /*
  109. * get the current register value of WM codec
  110. */
  111. static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
  112. {
  113. reg <<= 1;
  114. return ((unsigned short)ice->akm[0].images[reg] << 8) |
  115. ice->akm[0].images[reg + 1];
  116. }
  117. /*
  118. * set the register value of WM codec and remember it
  119. */
  120. static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
  121. {
  122. unsigned short cval;
  123. cval = (reg << 9) | val;
  124. snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff);
  125. }
  126. static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
  127. {
  128. wm_put_nocache(ice, reg, val);
  129. reg <<= 1;
  130. ice->akm[0].images[reg] = val >> 8;
  131. ice->akm[0].images[reg + 1] = val;
  132. }
  133. /*
  134. * write data in the SPI mode
  135. */
  136. static void set_gpio_bit(struct snd_ice1712 *ice, unsigned int bit, int val)
  137. {
  138. unsigned int tmp = snd_ice1712_gpio_read(ice);
  139. if (val)
  140. tmp |= bit;
  141. else
  142. tmp &= ~bit;
  143. snd_ice1712_gpio_write(ice, tmp);
  144. }
  145. /*
  146. * SPI implementation for WM8766 codec - only writing supported, no readback
  147. */
  148. static void wm8766_spi_send_word(struct snd_ice1712 *ice, unsigned int data)
  149. {
  150. int i;
  151. for (i = 0; i < 16; i++) {
  152. set_gpio_bit(ice, WM8766_SPI_CLK, 0);
  153. udelay(1);
  154. set_gpio_bit(ice, WM8766_SPI_MD, data & 0x8000);
  155. udelay(1);
  156. set_gpio_bit(ice, WM8766_SPI_CLK, 1);
  157. udelay(1);
  158. data <<= 1;
  159. }
  160. }
  161. static void wm8766_spi_write(struct snd_ice1712 *ice, unsigned int reg,
  162. unsigned int data)
  163. {
  164. unsigned int block;
  165. snd_ice1712_gpio_set_dir(ice, WM8766_SPI_MD|
  166. WM8766_SPI_CLK|WM8766_SPI_ML);
  167. snd_ice1712_gpio_set_mask(ice, ~(WM8766_SPI_MD|
  168. WM8766_SPI_CLK|WM8766_SPI_ML));
  169. /* latch must be low when writing */
  170. set_gpio_bit(ice, WM8766_SPI_ML, 0);
  171. block = (reg << 9) | (data & 0x1ff);
  172. wm8766_spi_send_word(ice, block); /* REGISTER ADDRESS */
  173. /* release latch */
  174. set_gpio_bit(ice, WM8766_SPI_ML, 1);
  175. udelay(1);
  176. /* restore */
  177. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  178. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  179. }
  180. /*
  181. * serial interface for ak4396 - only writing supported, no readback
  182. */
  183. static void ak4396_send_word(struct snd_ice1712 *ice, unsigned int data)
  184. {
  185. int i;
  186. for (i = 0; i < 16; i++) {
  187. set_gpio_bit(ice, AK4396_CCLK, 0);
  188. udelay(1);
  189. set_gpio_bit(ice, AK4396_CDTI, data & 0x8000);
  190. udelay(1);
  191. set_gpio_bit(ice, AK4396_CCLK, 1);
  192. udelay(1);
  193. data <<= 1;
  194. }
  195. }
  196. static void ak4396_write(struct snd_ice1712 *ice, unsigned int reg,
  197. unsigned int data)
  198. {
  199. unsigned int block;
  200. snd_ice1712_gpio_set_dir(ice, AK4396_CSN|AK4396_CCLK|AK4396_CDTI);
  201. snd_ice1712_gpio_set_mask(ice, ~(AK4396_CSN|AK4396_CCLK|AK4396_CDTI));
  202. /* latch must be low when writing */
  203. set_gpio_bit(ice, AK4396_CSN, 0);
  204. block = ((AK4396_ADDR & 0x03) << 14) | (1 << 13) |
  205. ((reg & 0x1f) << 8) | (data & 0xff);
  206. ak4396_send_word(ice, block); /* REGISTER ADDRESS */
  207. /* release latch */
  208. set_gpio_bit(ice, AK4396_CSN, 1);
  209. udelay(1);
  210. /* restore */
  211. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  212. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  213. }
  214. /*
  215. * ak4396 mixers
  216. */
  217. /*
  218. * DAC volume attenuation mixer control (-64dB to 0dB)
  219. */
  220. static int ak4396_dac_vol_info(struct snd_kcontrol *kcontrol,
  221. struct snd_ctl_elem_info *uinfo)
  222. {
  223. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  224. uinfo->count = 2;
  225. uinfo->value.integer.min = 0; /* mute */
  226. uinfo->value.integer.max = 0xFF; /* linear */
  227. return 0;
  228. }
  229. static int ak4396_dac_vol_get(struct snd_kcontrol *kcontrol,
  230. struct snd_ctl_elem_value *ucontrol)
  231. {
  232. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  233. struct prodigy_hifi_spec *spec = ice->spec;
  234. int i;
  235. for (i = 0; i < 2; i++)
  236. ucontrol->value.integer.value[i] = spec->vol[i];
  237. return 0;
  238. }
  239. static int ak4396_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  240. {
  241. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  242. struct prodigy_hifi_spec *spec = ice->spec;
  243. int i;
  244. int change = 0;
  245. mutex_lock(&ice->gpio_mutex);
  246. for (i = 0; i < 2; i++) {
  247. if (ucontrol->value.integer.value[i] != spec->vol[i]) {
  248. spec->vol[i] = ucontrol->value.integer.value[i];
  249. ak4396_write(ice, AK4396_LCH_ATT + i,
  250. spec->vol[i] & 0xff);
  251. change = 1;
  252. }
  253. }
  254. mutex_unlock(&ice->gpio_mutex);
  255. return change;
  256. }
  257. static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1);
  258. static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
  259. static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = {
  260. {
  261. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  262. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  263. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  264. .name = "Front Playback Volume",
  265. .info = ak4396_dac_vol_info,
  266. .get = ak4396_dac_vol_get,
  267. .put = ak4396_dac_vol_put,
  268. .tlv = { .p = ak4396_db_scale },
  269. },
  270. };
  271. /* --------------- */
  272. /*
  273. * Logarithmic volume values for WM87*6
  274. * Computed as 20 * Log10(255 / x)
  275. */
  276. static const unsigned char wm_vol[256] = {
  277. 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
  278. 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
  279. 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
  280. 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
  281. 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
  282. 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,
  283. 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,
  284. 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,
  285. 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,
  286. 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,
  287. 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,
  288. 0, 0
  289. };
  290. #define WM_VOL_MAX (sizeof(wm_vol) - 1)
  291. #define WM_VOL_MUTE 0x8000
  292. #define DAC_0dB 0xff
  293. #define DAC_RES 128
  294. #define DAC_MIN (DAC_0dB - DAC_RES)
  295. static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index,
  296. unsigned short vol, unsigned short master)
  297. {
  298. unsigned char nvol;
  299. if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
  300. nvol = 0;
  301. else {
  302. nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
  303. & WM_VOL_MAX;
  304. nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
  305. }
  306. wm_put(ice, index, nvol);
  307. wm_put_nocache(ice, index, 0x100 | nvol);
  308. }
  309. static void wm8766_set_vol(struct snd_ice1712 *ice, unsigned int index,
  310. unsigned short vol, unsigned short master)
  311. {
  312. unsigned char nvol;
  313. if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
  314. nvol = 0;
  315. else {
  316. nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
  317. & WM_VOL_MAX;
  318. nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
  319. }
  320. wm8766_spi_write(ice, index, (0x0100 | nvol));
  321. }
  322. /*
  323. * DAC volume attenuation mixer control (-64dB to 0dB)
  324. */
  325. static int wm_dac_vol_info(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_info *uinfo)
  327. {
  328. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  329. uinfo->count = 2;
  330. uinfo->value.integer.min = 0; /* mute */
  331. uinfo->value.integer.max = DAC_RES; /* 0dB, 0.5dB step */
  332. return 0;
  333. }
  334. static int wm_dac_vol_get(struct snd_kcontrol *kcontrol,
  335. struct snd_ctl_elem_value *ucontrol)
  336. {
  337. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  338. struct prodigy_hifi_spec *spec = ice->spec;
  339. int i;
  340. for (i = 0; i < 2; i++)
  341. ucontrol->value.integer.value[i] =
  342. spec->vol[2 + i] & ~WM_VOL_MUTE;
  343. return 0;
  344. }
  345. static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  346. {
  347. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  348. struct prodigy_hifi_spec *spec = ice->spec;
  349. int i, idx, change = 0;
  350. mutex_lock(&ice->gpio_mutex);
  351. for (i = 0; i < 2; i++) {
  352. if (ucontrol->value.integer.value[i] != spec->vol[2 + i]) {
  353. idx = WM_DAC_ATTEN_L + i;
  354. spec->vol[2 + i] &= WM_VOL_MUTE;
  355. spec->vol[2 + i] |= ucontrol->value.integer.value[i];
  356. wm_set_vol(ice, idx, spec->vol[2 + i], spec->master[i]);
  357. change = 1;
  358. }
  359. }
  360. mutex_unlock(&ice->gpio_mutex);
  361. return change;
  362. }
  363. /*
  364. * WM8766 DAC volume attenuation mixer control
  365. */
  366. static int wm8766_vol_info(struct snd_kcontrol *kcontrol,
  367. struct snd_ctl_elem_info *uinfo)
  368. {
  369. int voices = kcontrol->private_value >> 8;
  370. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  371. uinfo->count = voices;
  372. uinfo->value.integer.min = 0; /* mute */
  373. uinfo->value.integer.max = DAC_RES; /* 0dB */
  374. return 0;
  375. }
  376. static int wm8766_vol_get(struct snd_kcontrol *kcontrol,
  377. struct snd_ctl_elem_value *ucontrol)
  378. {
  379. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  380. struct prodigy_hifi_spec *spec = ice->spec;
  381. int i, ofs, voices;
  382. voices = kcontrol->private_value >> 8;
  383. ofs = kcontrol->private_value & 0xff;
  384. for (i = 0; i < voices; i++)
  385. ucontrol->value.integer.value[i] = spec->vol[ofs + i];
  386. return 0;
  387. }
  388. static int wm8766_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  389. {
  390. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  391. struct prodigy_hifi_spec *spec = ice->spec;
  392. int i, idx, ofs, voices;
  393. int change = 0;
  394. voices = kcontrol->private_value >> 8;
  395. ofs = kcontrol->private_value & 0xff;
  396. mutex_lock(&ice->gpio_mutex);
  397. for (i = 0; i < voices; i++) {
  398. if (ucontrol->value.integer.value[i] != spec->vol[ofs + i]) {
  399. idx = WM8766_LDA1 + ofs + i;
  400. spec->vol[ofs + i] &= WM_VOL_MUTE;
  401. spec->vol[ofs + i] |= ucontrol->value.integer.value[i];
  402. wm8766_set_vol(ice, idx,
  403. spec->vol[ofs + i], spec->master[i]);
  404. change = 1;
  405. }
  406. }
  407. mutex_unlock(&ice->gpio_mutex);
  408. return change;
  409. }
  410. /*
  411. * Master volume attenuation mixer control / applied to WM8776+WM8766
  412. */
  413. static int wm_master_vol_info(struct snd_kcontrol *kcontrol,
  414. struct snd_ctl_elem_info *uinfo)
  415. {
  416. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  417. uinfo->count = 2;
  418. uinfo->value.integer.min = 0;
  419. uinfo->value.integer.max = DAC_RES;
  420. return 0;
  421. }
  422. static int wm_master_vol_get(struct snd_kcontrol *kcontrol,
  423. struct snd_ctl_elem_value *ucontrol)
  424. {
  425. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  426. struct prodigy_hifi_spec *spec = ice->spec;
  427. int i;
  428. for (i = 0; i < 2; i++)
  429. ucontrol->value.integer.value[i] = spec->master[i];
  430. return 0;
  431. }
  432. static int wm_master_vol_put(struct snd_kcontrol *kcontrol,
  433. struct snd_ctl_elem_value *ucontrol)
  434. {
  435. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  436. struct prodigy_hifi_spec *spec = ice->spec;
  437. int ch, change = 0;
  438. mutex_lock(&ice->gpio_mutex);
  439. for (ch = 0; ch < 2; ch++) {
  440. if (ucontrol->value.integer.value[ch] != spec->master[ch]) {
  441. spec->master[ch] = ucontrol->value.integer.value[ch];
  442. /* Apply to front DAC */
  443. wm_set_vol(ice, WM_DAC_ATTEN_L + ch,
  444. spec->vol[2 + ch], spec->master[ch]);
  445. wm8766_set_vol(ice, WM8766_LDA1 + ch,
  446. spec->vol[0 + ch], spec->master[ch]);
  447. wm8766_set_vol(ice, WM8766_LDA2 + ch,
  448. spec->vol[4 + ch], spec->master[ch]);
  449. wm8766_set_vol(ice, WM8766_LDA3 + ch,
  450. spec->vol[6 + ch], spec->master[ch]);
  451. change = 1;
  452. }
  453. }
  454. mutex_unlock(&ice->gpio_mutex);
  455. return change;
  456. }
  457. /* KONSTI */
  458. static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
  459. struct snd_ctl_elem_info *uinfo)
  460. {
  461. static char* texts[32] = {
  462. "NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2,
  463. WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3,
  464. WM_AIN1 "+" WM_AIN2 "+" WM_AIN3,
  465. WM_AIN4, WM_AIN1 "+" WM_AIN4, WM_AIN2 "+" WM_AIN4,
  466. WM_AIN1 "+" WM_AIN2 "+" WM_AIN4,
  467. WM_AIN3 "+" WM_AIN4, WM_AIN1 "+" WM_AIN3 "+" WM_AIN4,
  468. WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
  469. WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
  470. WM_AIN5, WM_AIN1 "+" WM_AIN5, WM_AIN2 "+" WM_AIN5,
  471. WM_AIN1 "+" WM_AIN2 "+" WM_AIN5,
  472. WM_AIN3 "+" WM_AIN5, WM_AIN1 "+" WM_AIN3 "+" WM_AIN5,
  473. WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
  474. WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
  475. WM_AIN4 "+" WM_AIN5, WM_AIN1 "+" WM_AIN4 "+" WM_AIN5,
  476. WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
  477. WM_AIN1 "+" WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
  478. WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
  479. WM_AIN1 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
  480. WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
  481. WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5
  482. };
  483. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  484. uinfo->count = 1;
  485. uinfo->value.enumerated.items = 32;
  486. if (uinfo->value.enumerated.item > 31)
  487. uinfo->value.enumerated.item = 31;
  488. strcpy(uinfo->value.enumerated.name,
  489. texts[uinfo->value.enumerated.item]);
  490. return 0;
  491. }
  492. static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol,
  493. struct snd_ctl_elem_value *ucontrol)
  494. {
  495. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  496. mutex_lock(&ice->gpio_mutex);
  497. ucontrol->value.integer.value[0] = wm_get(ice, WM_ADC_MUX) & 0x1f;
  498. mutex_unlock(&ice->gpio_mutex);
  499. return 0;
  500. }
  501. static int wm_adc_mux_enum_put(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_value *ucontrol)
  503. {
  504. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  505. unsigned short oval, nval;
  506. int change = 0;
  507. mutex_lock(&ice->gpio_mutex);
  508. oval = wm_get(ice, WM_ADC_MUX);
  509. nval = (oval & 0xe0) | ucontrol->value.integer.value[0];
  510. if (nval != oval) {
  511. wm_put(ice, WM_ADC_MUX, nval);
  512. change = 1;
  513. }
  514. mutex_unlock(&ice->gpio_mutex);
  515. return change;
  516. }
  517. /* KONSTI */
  518. /*
  519. * ADC gain mixer control (-64dB to 0dB)
  520. */
  521. #define ADC_0dB 0xcf
  522. #define ADC_RES 128
  523. #define ADC_MIN (ADC_0dB - ADC_RES)
  524. static int wm_adc_vol_info(struct snd_kcontrol *kcontrol,
  525. struct snd_ctl_elem_info *uinfo)
  526. {
  527. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  528. uinfo->count = 2;
  529. uinfo->value.integer.min = 0; /* mute (-64dB) */
  530. uinfo->value.integer.max = ADC_RES; /* 0dB, 0.5dB step */
  531. return 0;
  532. }
  533. static int wm_adc_vol_get(struct snd_kcontrol *kcontrol,
  534. struct snd_ctl_elem_value *ucontrol)
  535. {
  536. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  537. unsigned short val;
  538. int i;
  539. mutex_lock(&ice->gpio_mutex);
  540. for (i = 0; i < 2; i++) {
  541. val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff;
  542. val = val > ADC_MIN ? (val - ADC_MIN) : 0;
  543. ucontrol->value.integer.value[i] = val;
  544. }
  545. mutex_unlock(&ice->gpio_mutex);
  546. return 0;
  547. }
  548. static int wm_adc_vol_put(struct snd_kcontrol *kcontrol,
  549. struct snd_ctl_elem_value *ucontrol)
  550. {
  551. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  552. unsigned short ovol, nvol;
  553. int i, idx, change = 0;
  554. mutex_lock(&ice->gpio_mutex);
  555. for (i = 0; i < 2; i++) {
  556. nvol = ucontrol->value.integer.value[i];
  557. nvol = nvol ? (nvol + ADC_MIN) : 0;
  558. idx = WM_ADC_ATTEN_L + i;
  559. ovol = wm_get(ice, idx) & 0xff;
  560. if (ovol != nvol) {
  561. wm_put(ice, idx, nvol);
  562. change = 1;
  563. }
  564. }
  565. mutex_unlock(&ice->gpio_mutex);
  566. return change;
  567. }
  568. /*
  569. * ADC input mux mixer control
  570. */
  571. #define wm_adc_mux_info snd_ctl_boolean_mono_info
  572. static int wm_adc_mux_get(struct snd_kcontrol *kcontrol,
  573. struct snd_ctl_elem_value *ucontrol)
  574. {
  575. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  576. int bit = kcontrol->private_value;
  577. mutex_lock(&ice->gpio_mutex);
  578. ucontrol->value.integer.value[0] =
  579. (wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0;
  580. mutex_unlock(&ice->gpio_mutex);
  581. return 0;
  582. }
  583. static int wm_adc_mux_put(struct snd_kcontrol *kcontrol,
  584. struct snd_ctl_elem_value *ucontrol)
  585. {
  586. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  587. int bit = kcontrol->private_value;
  588. unsigned short oval, nval;
  589. int change;
  590. mutex_lock(&ice->gpio_mutex);
  591. nval = oval = wm_get(ice, WM_ADC_MUX);
  592. if (ucontrol->value.integer.value[0])
  593. nval |= (1 << bit);
  594. else
  595. nval &= ~(1 << bit);
  596. change = nval != oval;
  597. if (change) {
  598. wm_put(ice, WM_ADC_MUX, nval);
  599. }
  600. mutex_unlock(&ice->gpio_mutex);
  601. return 0;
  602. }
  603. /*
  604. * Analog bypass (In -> Out)
  605. */
  606. #define wm_bypass_info snd_ctl_boolean_mono_info
  607. static int wm_bypass_get(struct snd_kcontrol *kcontrol,
  608. struct snd_ctl_elem_value *ucontrol)
  609. {
  610. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  611. mutex_lock(&ice->gpio_mutex);
  612. ucontrol->value.integer.value[0] =
  613. (wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0;
  614. mutex_unlock(&ice->gpio_mutex);
  615. return 0;
  616. }
  617. static int wm_bypass_put(struct snd_kcontrol *kcontrol,
  618. struct snd_ctl_elem_value *ucontrol)
  619. {
  620. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  621. unsigned short val, oval;
  622. int change = 0;
  623. mutex_lock(&ice->gpio_mutex);
  624. val = oval = wm_get(ice, WM_OUT_MUX);
  625. if (ucontrol->value.integer.value[0])
  626. val |= 0x04;
  627. else
  628. val &= ~0x04;
  629. if (val != oval) {
  630. wm_put(ice, WM_OUT_MUX, val);
  631. change = 1;
  632. }
  633. mutex_unlock(&ice->gpio_mutex);
  634. return change;
  635. }
  636. /*
  637. * Left/Right swap
  638. */
  639. #define wm_chswap_info snd_ctl_boolean_mono_info
  640. static int wm_chswap_get(struct snd_kcontrol *kcontrol,
  641. struct snd_ctl_elem_value *ucontrol)
  642. {
  643. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  644. mutex_lock(&ice->gpio_mutex);
  645. ucontrol->value.integer.value[0] =
  646. (wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90;
  647. mutex_unlock(&ice->gpio_mutex);
  648. return 0;
  649. }
  650. static int wm_chswap_put(struct snd_kcontrol *kcontrol,
  651. struct snd_ctl_elem_value *ucontrol)
  652. {
  653. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  654. unsigned short val, oval;
  655. int change = 0;
  656. mutex_lock(&ice->gpio_mutex);
  657. oval = wm_get(ice, WM_DAC_CTRL1);
  658. val = oval & 0x0f;
  659. if (ucontrol->value.integer.value[0])
  660. val |= 0x60;
  661. else
  662. val |= 0x90;
  663. if (val != oval) {
  664. wm_put(ice, WM_DAC_CTRL1, val);
  665. wm_put_nocache(ice, WM_DAC_CTRL1, val);
  666. change = 1;
  667. }
  668. mutex_unlock(&ice->gpio_mutex);
  669. return change;
  670. }
  671. /*
  672. * mixers
  673. */
  674. static struct snd_kcontrol_new prodigy_hifi_controls[] __devinitdata = {
  675. {
  676. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  677. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  678. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  679. .name = "Master Playback Volume",
  680. .info = wm_master_vol_info,
  681. .get = wm_master_vol_get,
  682. .put = wm_master_vol_put,
  683. .tlv = { .p = db_scale_wm_dac }
  684. },
  685. {
  686. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  687. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  688. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  689. .name = "Front Playback Volume",
  690. .info = wm_dac_vol_info,
  691. .get = wm_dac_vol_get,
  692. .put = wm_dac_vol_put,
  693. .tlv = { .p = db_scale_wm_dac },
  694. },
  695. {
  696. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  697. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  698. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  699. .name = "Rear Playback Volume",
  700. .info = wm8766_vol_info,
  701. .get = wm8766_vol_get,
  702. .put = wm8766_vol_put,
  703. .private_value = (2 << 8) | 0,
  704. .tlv = { .p = db_scale_wm_dac },
  705. },
  706. {
  707. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  708. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  709. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  710. .name = "Center Playback Volume",
  711. .info = wm8766_vol_info,
  712. .get = wm8766_vol_get,
  713. .put = wm8766_vol_put,
  714. .private_value = (1 << 8) | 4,
  715. .tlv = { .p = db_scale_wm_dac }
  716. },
  717. {
  718. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  719. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  720. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  721. .name = "LFE Playback Volume",
  722. .info = wm8766_vol_info,
  723. .get = wm8766_vol_get,
  724. .put = wm8766_vol_put,
  725. .private_value = (1 << 8) | 5,
  726. .tlv = { .p = db_scale_wm_dac }
  727. },
  728. {
  729. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  730. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  731. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  732. .name = "Side Playback Volume",
  733. .info = wm8766_vol_info,
  734. .get = wm8766_vol_get,
  735. .put = wm8766_vol_put,
  736. .private_value = (2 << 8) | 6,
  737. .tlv = { .p = db_scale_wm_dac },
  738. },
  739. {
  740. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  741. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  742. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  743. .name = "Capture Volume",
  744. .info = wm_adc_vol_info,
  745. .get = wm_adc_vol_get,
  746. .put = wm_adc_vol_put,
  747. .tlv = { .p = db_scale_wm_dac },
  748. },
  749. {
  750. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  751. .name = "CD Capture Switch",
  752. .info = wm_adc_mux_info,
  753. .get = wm_adc_mux_get,
  754. .put = wm_adc_mux_put,
  755. .private_value = 0,
  756. },
  757. {
  758. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  759. .name = "Line Capture Switch",
  760. .info = wm_adc_mux_info,
  761. .get = wm_adc_mux_get,
  762. .put = wm_adc_mux_put,
  763. .private_value = 1,
  764. },
  765. {
  766. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  767. .name = "Analog Bypass Switch",
  768. .info = wm_bypass_info,
  769. .get = wm_bypass_get,
  770. .put = wm_bypass_put,
  771. },
  772. {
  773. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  774. .name = "Swap Output Channels",
  775. .info = wm_chswap_info,
  776. .get = wm_chswap_get,
  777. .put = wm_chswap_put,
  778. },
  779. {
  780. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  781. .name = "Analog Capture Source",
  782. .info = wm_adc_mux_enum_info,
  783. .get = wm_adc_mux_enum_get,
  784. .put = wm_adc_mux_enum_put,
  785. },
  786. };
  787. /*
  788. * WM codec registers
  789. */
  790. static void wm_proc_regs_write(struct snd_info_entry *entry,
  791. struct snd_info_buffer *buffer)
  792. {
  793. struct snd_ice1712 *ice = entry->private_data;
  794. char line[64];
  795. unsigned int reg, val;
  796. mutex_lock(&ice->gpio_mutex);
  797. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  798. if (sscanf(line, "%x %x", &reg, &val) != 2)
  799. continue;
  800. if (reg <= 0x17 && val <= 0xffff)
  801. wm_put(ice, reg, val);
  802. }
  803. mutex_unlock(&ice->gpio_mutex);
  804. }
  805. static void wm_proc_regs_read(struct snd_info_entry *entry,
  806. struct snd_info_buffer *buffer)
  807. {
  808. struct snd_ice1712 *ice = entry->private_data;
  809. int reg, val;
  810. mutex_lock(&ice->gpio_mutex);
  811. for (reg = 0; reg <= 0x17; reg++) {
  812. val = wm_get(ice, reg);
  813. snd_iprintf(buffer, "%02x = %04x\n", reg, val);
  814. }
  815. mutex_unlock(&ice->gpio_mutex);
  816. }
  817. static void wm_proc_init(struct snd_ice1712 *ice)
  818. {
  819. struct snd_info_entry *entry;
  820. if (!snd_card_proc_new(ice->card, "wm_codec", &entry)) {
  821. snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
  822. entry->mode |= S_IWUSR;
  823. entry->c.text.write = wm_proc_regs_write;
  824. }
  825. }
  826. static int __devinit prodigy_hifi_add_controls(struct snd_ice1712 *ice)
  827. {
  828. unsigned int i;
  829. int err;
  830. for (i = 0; i < ARRAY_SIZE(prodigy_hifi_controls); i++) {
  831. err = snd_ctl_add(ice->card,
  832. snd_ctl_new1(&prodigy_hifi_controls[i], ice));
  833. if (err < 0)
  834. return err;
  835. }
  836. wm_proc_init(ice);
  837. return 0;
  838. }
  839. static int __devinit prodigy_hd2_add_controls(struct snd_ice1712 *ice)
  840. {
  841. unsigned int i;
  842. int err;
  843. for (i = 0; i < ARRAY_SIZE(prodigy_hd2_controls); i++) {
  844. err = snd_ctl_add(ice->card,
  845. snd_ctl_new1(&prodigy_hd2_controls[i], ice));
  846. if (err < 0)
  847. return err;
  848. }
  849. wm_proc_init(ice);
  850. return 0;
  851. }
  852. /*
  853. * initialize the chip
  854. */
  855. static int __devinit prodigy_hifi_init(struct snd_ice1712 *ice)
  856. {
  857. static unsigned short wm_inits[] = {
  858. /* These come first to reduce init pop noise */
  859. WM_ADC_MUX, 0x0003, /* ADC mute */
  860. /* 0x00c0 replaced by 0x0003 */
  861. WM_DAC_MUTE, 0x0001, /* DAC softmute */
  862. WM_DAC_CTRL1, 0x0000, /* DAC mute */
  863. WM_POWERDOWN, 0x0008, /* All power-up except HP */
  864. WM_RESET, 0x0000, /* reset */
  865. };
  866. static unsigned short wm_inits2[] = {
  867. WM_MASTER_CTRL, 0x0022, /* 256fs, slave mode */
  868. WM_DAC_INT, 0x0022, /* I2S, normal polarity, 24bit */
  869. WM_ADC_INT, 0x0022, /* I2S, normal polarity, 24bit */
  870. WM_DAC_CTRL1, 0x0090, /* DAC L/R */
  871. WM_OUT_MUX, 0x0001, /* OUT DAC */
  872. WM_HP_ATTEN_L, 0x0179, /* HP 0dB */
  873. WM_HP_ATTEN_R, 0x0179, /* HP 0dB */
  874. WM_DAC_ATTEN_L, 0x0000, /* DAC 0dB */
  875. WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */
  876. WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */
  877. WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */
  878. WM_PHASE_SWAP, 0x0000, /* phase normal */
  879. #if 0
  880. WM_DAC_MASTER, 0x0100, /* DAC master muted */
  881. #endif
  882. WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */
  883. WM_ADC_ATTEN_L, 0x0000, /* ADC muted */
  884. WM_ADC_ATTEN_R, 0x0000, /* ADC muted */
  885. #if 1
  886. WM_ALC_CTRL1, 0x007b, /* */
  887. WM_ALC_CTRL2, 0x0000, /* */
  888. WM_ALC_CTRL3, 0x0000, /* */
  889. WM_NOISE_GATE, 0x0000, /* */
  890. #endif
  891. WM_DAC_MUTE, 0x0000, /* DAC unmute */
  892. WM_ADC_MUX, 0x0003, /* ADC unmute, both CD/Line On */
  893. };
  894. static unsigned short wm8766_inits[] = {
  895. WM8766_RESET, 0x0000,
  896. WM8766_DAC_CTRL, 0x0120,
  897. WM8766_INT_CTRL, 0x0022, /* I2S Normal Mode, 24 bit */
  898. WM8766_DAC_CTRL2, 0x0001,
  899. WM8766_DAC_CTRL3, 0x0080,
  900. WM8766_LDA1, 0x0100,
  901. WM8766_LDA2, 0x0100,
  902. WM8766_LDA3, 0x0100,
  903. WM8766_RDA1, 0x0100,
  904. WM8766_RDA2, 0x0100,
  905. WM8766_RDA3, 0x0100,
  906. WM8766_MUTE1, 0x0000,
  907. WM8766_MUTE2, 0x0000,
  908. };
  909. struct prodigy_hifi_spec *spec;
  910. unsigned int i;
  911. ice->vt1720 = 0;
  912. ice->vt1724 = 1;
  913. ice->num_total_dacs = 8;
  914. ice->num_total_adcs = 1;
  915. /* HACK - use this as the SPDIF source.
  916. * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
  917. */
  918. ice->gpio.saved[0] = 0;
  919. /* to remember the register values */
  920. ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  921. if (! ice->akm)
  922. return -ENOMEM;
  923. ice->akm_codecs = 1;
  924. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  925. if (!spec)
  926. return -ENOMEM;
  927. ice->spec = spec;
  928. /* initialize WM8776 codec */
  929. for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
  930. wm_put(ice, wm_inits[i], wm_inits[i+1]);
  931. schedule_timeout_uninterruptible(1);
  932. for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
  933. wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
  934. /* initialize WM8766 codec */
  935. for (i = 0; i < ARRAY_SIZE(wm8766_inits); i += 2)
  936. wm8766_spi_write(ice, wm8766_inits[i], wm8766_inits[i+1]);
  937. return 0;
  938. }
  939. /*
  940. * initialize the chip
  941. */
  942. static void ak4396_init(struct snd_ice1712 *ice)
  943. {
  944. static unsigned short ak4396_inits[] = {
  945. AK4396_CTRL1, 0x87, /* I2S Normal Mode, 24 bit */
  946. AK4396_CTRL2, 0x02,
  947. AK4396_CTRL3, 0x00,
  948. AK4396_LCH_ATT, 0x00,
  949. AK4396_RCH_ATT, 0x00,
  950. };
  951. unsigned int i;
  952. /* initialize ak4396 codec */
  953. /* reset codec */
  954. ak4396_write(ice, AK4396_CTRL1, 0x86);
  955. msleep(100);
  956. ak4396_write(ice, AK4396_CTRL1, 0x87);
  957. for (i = 0; i < ARRAY_SIZE(ak4396_inits); i += 2)
  958. ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
  959. }
  960. #ifdef CONFIG_PM
  961. static int prodigy_hd2_resume(struct snd_ice1712 *ice)
  962. {
  963. /* initialize ak4396 codec and restore previous mixer volumes */
  964. struct prodigy_hifi_spec *spec = ice->spec;
  965. int i;
  966. mutex_lock(&ice->gpio_mutex);
  967. ak4396_init(ice);
  968. for (i = 0; i < 2; i++)
  969. ak4396_write(ice, AK4396_LCH_ATT + i, spec->vol[i] & 0xff);
  970. mutex_unlock(&ice->gpio_mutex);
  971. return 0;
  972. }
  973. #endif
  974. static int __devinit prodigy_hd2_init(struct snd_ice1712 *ice)
  975. {
  976. struct prodigy_hifi_spec *spec;
  977. ice->vt1720 = 0;
  978. ice->vt1724 = 1;
  979. ice->num_total_dacs = 1;
  980. ice->num_total_adcs = 1;
  981. /* HACK - use this as the SPDIF source.
  982. * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
  983. */
  984. ice->gpio.saved[0] = 0;
  985. /* to remember the register values */
  986. ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  987. if (! ice->akm)
  988. return -ENOMEM;
  989. ice->akm_codecs = 1;
  990. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  991. if (!spec)
  992. return -ENOMEM;
  993. ice->spec = spec;
  994. #ifdef CONFIG_PM
  995. ice->pm_resume = &prodigy_hd2_resume;
  996. ice->pm_suspend_enabled = 1;
  997. #endif
  998. ak4396_init(ice);
  999. return 0;
  1000. }
  1001. static unsigned char prodigy71hifi_eeprom[] __devinitdata = {
  1002. 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
  1003. 0x80, /* ACLINK: I2S */
  1004. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1005. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  1006. 0xff, /* GPIO_DIR */
  1007. 0xff, /* GPIO_DIR1 */
  1008. 0x5f, /* GPIO_DIR2 */
  1009. 0x00, /* GPIO_MASK */
  1010. 0x00, /* GPIO_MASK1 */
  1011. 0x00, /* GPIO_MASK2 */
  1012. 0x00, /* GPIO_STATE */
  1013. 0x00, /* GPIO_STATE1 */
  1014. 0x00, /* GPIO_STATE2 */
  1015. };
  1016. static unsigned char prodigyhd2_eeprom[] __devinitdata = {
  1017. 0x4b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
  1018. 0x80, /* ACLINK: I2S */
  1019. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1020. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  1021. 0xff, /* GPIO_DIR */
  1022. 0xff, /* GPIO_DIR1 */
  1023. 0x5f, /* GPIO_DIR2 */
  1024. 0x00, /* GPIO_MASK */
  1025. 0x00, /* GPIO_MASK1 */
  1026. 0x00, /* GPIO_MASK2 */
  1027. 0x00, /* GPIO_STATE */
  1028. 0x00, /* GPIO_STATE1 */
  1029. 0x00, /* GPIO_STATE2 */
  1030. };
  1031. static unsigned char fortissimo4_eeprom[] __devinitdata = {
  1032. 0x43, /* SYSCONF: clock 512, ADC, 4DACs */
  1033. 0x80, /* ACLINK: I2S */
  1034. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  1035. 0xc1, /* SPDIF: out-en, out-int */
  1036. 0xff, /* GPIO_DIR */
  1037. 0xff, /* GPIO_DIR1 */
  1038. 0x5f, /* GPIO_DIR2 */
  1039. 0x00, /* GPIO_MASK */
  1040. 0x00, /* GPIO_MASK1 */
  1041. 0x00, /* GPIO_MASK2 */
  1042. 0x00, /* GPIO_STATE */
  1043. 0x00, /* GPIO_STATE1 */
  1044. 0x00, /* GPIO_STATE2 */
  1045. };
  1046. /* entry point */
  1047. struct snd_ice1712_card_info snd_vt1724_prodigy_hifi_cards[] __devinitdata = {
  1048. {
  1049. .subvendor = VT1724_SUBDEVICE_PRODIGY_HIFI,
  1050. .name = "Audiotrak Prodigy 7.1 HiFi",
  1051. .model = "prodigy71hifi",
  1052. .chip_init = prodigy_hifi_init,
  1053. .build_controls = prodigy_hifi_add_controls,
  1054. .eeprom_size = sizeof(prodigy71hifi_eeprom),
  1055. .eeprom_data = prodigy71hifi_eeprom,
  1056. .driver = "Prodigy71HIFI",
  1057. },
  1058. {
  1059. .subvendor = VT1724_SUBDEVICE_PRODIGY_HD2,
  1060. .name = "Audiotrak Prodigy HD2",
  1061. .model = "prodigyhd2",
  1062. .chip_init = prodigy_hd2_init,
  1063. .build_controls = prodigy_hd2_add_controls,
  1064. .eeprom_size = sizeof(prodigyhd2_eeprom),
  1065. .eeprom_data = prodigyhd2_eeprom,
  1066. .driver = "Prodigy71HD2",
  1067. },
  1068. {
  1069. .subvendor = VT1724_SUBDEVICE_FORTISSIMO4,
  1070. .name = "Hercules Fortissimo IV",
  1071. .model = "fortissimo4",
  1072. .chip_init = prodigy_hifi_init,
  1073. .build_controls = prodigy_hifi_add_controls,
  1074. .eeprom_size = sizeof(fortissimo4_eeprom),
  1075. .eeprom_data = fortissimo4_eeprom,
  1076. .driver = "Fortissimo4",
  1077. },
  1078. { } /* terminator */
  1079. };