phase.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * ALSA driver for ICEnsemble ICE1724 (Envy24)
  3. *
  4. * Lowlevel functions for Terratec PHASE 22
  5. *
  6. * Copyright (c) 2005 Misha Zhilin <misha@epiphan.com>
  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. /* PHASE 22 overview:
  24. * Audio controller: VIA Envy24HT-S (slightly trimmed down version of Envy24HT)
  25. * Analog chip: AK4524 (partially via Philip's 74HCT125)
  26. * Digital receiver: CS8414-CS (not supported in this release)
  27. *
  28. * Envy connects to AK4524
  29. * - CS directly from GPIO 10
  30. * - CCLK via 74HCT125's gate #4 from GPIO 4
  31. * - CDTI via 74HCT125's gate #2 from GPIO 5
  32. * CDTI may be completely blocked by 74HCT125's gate #1 controlled by GPIO 3
  33. */
  34. #include <sound/driver.h>
  35. #include <asm/io.h>
  36. #include <linux/delay.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/init.h>
  39. #include <linux/slab.h>
  40. #include <sound/core.h>
  41. #include "ice1712.h"
  42. #include "envy24ht.h"
  43. #include "phase.h"
  44. /* WM8770 registers */
  45. #define WM_DAC_ATTEN 0x00 /* DAC1-8 analog attenuation */
  46. #define WM_DAC_MASTER_ATTEN 0x08 /* DAC master analog attenuation */
  47. #define WM_DAC_DIG_ATTEN 0x09 /* DAC1-8 digital attenuation */
  48. #define WM_DAC_DIG_MASTER_ATTEN 0x11 /* DAC master digital attenuation */
  49. #define WM_PHASE_SWAP 0x12 /* DAC phase */
  50. #define WM_DAC_CTRL1 0x13 /* DAC control bits */
  51. #define WM_MUTE 0x14 /* mute controls */
  52. #define WM_DAC_CTRL2 0x15 /* de-emphasis and zefo-flag */
  53. #define WM_INT_CTRL 0x16 /* interface control */
  54. #define WM_MASTER 0x17 /* master clock and mode */
  55. #define WM_POWERDOWN 0x18 /* power-down controls */
  56. #define WM_ADC_GAIN 0x19 /* ADC gain L(19)/R(1a) */
  57. #define WM_ADC_MUX 0x1b /* input MUX */
  58. #define WM_OUT_MUX1 0x1c /* output MUX */
  59. #define WM_OUT_MUX2 0x1e /* output MUX */
  60. #define WM_RESET 0x1f /* software reset */
  61. /*
  62. * Logarithmic volume values for WM8770
  63. * Computed as 20 * Log10(255 / x)
  64. */
  65. static unsigned char wm_vol[256] = {
  66. 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
  67. 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
  68. 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
  69. 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
  70. 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
  71. 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,
  72. 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,
  73. 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,
  74. 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,
  75. 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,
  76. 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,
  77. 0, 0
  78. };
  79. #define WM_VOL_MAX (sizeof(wm_vol) - 1)
  80. #define WM_VOL_MUTE 0x8000
  81. static struct snd_akm4xxx akm_phase22 __devinitdata = {
  82. .type = SND_AK4524,
  83. .num_dacs = 2,
  84. .num_adcs = 2,
  85. };
  86. static struct snd_ak4xxx_private akm_phase22_priv __devinitdata = {
  87. .caddr = 2,
  88. .cif = 1,
  89. .data_mask = 1 << 4,
  90. .clk_mask = 1 << 5,
  91. .cs_mask = 1 << 10,
  92. .cs_addr = 1 << 10,
  93. .cs_none = 0,
  94. .add_flags = 1 << 3,
  95. .mask_flags = 0,
  96. };
  97. static int __devinit phase22_init(struct snd_ice1712 *ice)
  98. {
  99. struct snd_akm4xxx *ak;
  100. int err;
  101. // Configure DAC/ADC description for generic part of ice1724
  102. switch (ice->eeprom.subvendor) {
  103. case VT1724_SUBDEVICE_PHASE22:
  104. ice->num_total_dacs = 2;
  105. ice->num_total_adcs = 2;
  106. ice->vt1720 = 1; // Envy24HT-S have 16 bit wide GPIO
  107. break;
  108. default:
  109. snd_BUG();
  110. return -EINVAL;
  111. }
  112. // Initialize analog chips
  113. ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  114. if (! ak)
  115. return -ENOMEM;
  116. ice->akm_codecs = 1;
  117. switch (ice->eeprom.subvendor) {
  118. case VT1724_SUBDEVICE_PHASE22:
  119. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_phase22, &akm_phase22_priv, ice)) < 0)
  120. return err;
  121. break;
  122. }
  123. return 0;
  124. }
  125. static int __devinit phase22_add_controls(struct snd_ice1712 *ice)
  126. {
  127. int err = 0;
  128. switch (ice->eeprom.subvendor) {
  129. case VT1724_SUBDEVICE_PHASE22:
  130. err = snd_ice1712_akm4xxx_build_controls(ice);
  131. if (err < 0)
  132. return err;
  133. }
  134. return 0;
  135. }
  136. static unsigned char phase22_eeprom[] __devinitdata = {
  137. 0x00, /* SYSCONF: 1xADC, 1xDACs */
  138. 0x80, /* ACLINK: I2S */
  139. 0xf8, /* I2S: vol, 96k, 24bit*/
  140. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  141. 0xFF, /* GPIO_DIR */
  142. 0xFF, /* GPIO_DIR1 */
  143. 0xFF, /* GPIO_DIR2 */
  144. 0x00, /* GPIO_MASK */
  145. 0x00, /* GPIO_MASK1 */
  146. 0x00, /* GPIO_MASK2 */
  147. 0x00, /* GPIO_STATE: */
  148. 0x00, /* GPIO_STATE1: */
  149. 0x00, /* GPIO_STATE2 */
  150. };
  151. static unsigned char phase28_eeprom[] __devinitdata = {
  152. 0x0b, /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
  153. 0x80, /* ACLINK: I2S */
  154. 0xfc, /* I2S: vol, 96k, 24bit, 192k */
  155. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  156. 0xff, /* GPIO_DIR */
  157. 0xff, /* GPIO_DIR1 */
  158. 0x5f, /* GPIO_DIR2 */
  159. 0x00, /* GPIO_MASK */
  160. 0x00, /* GPIO_MASK1 */
  161. 0x00, /* GPIO_MASK2 */
  162. 0x00, /* GPIO_STATE */
  163. 0x00, /* GPIO_STATE1 */
  164. 0x00, /* GPIO_STATE2 */
  165. };
  166. /*
  167. * write data in the SPI mode
  168. */
  169. static void phase28_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits)
  170. {
  171. unsigned int tmp;
  172. int i;
  173. tmp = snd_ice1712_gpio_read(ice);
  174. snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RW|PHASE28_SPI_MOSI|PHASE28_SPI_CLK|
  175. PHASE28_WM_CS));
  176. tmp |= PHASE28_WM_RW;
  177. tmp &= ~cs;
  178. snd_ice1712_gpio_write(ice, tmp);
  179. udelay(1);
  180. for (i = bits - 1; i >= 0; i--) {
  181. tmp &= ~PHASE28_SPI_CLK;
  182. snd_ice1712_gpio_write(ice, tmp);
  183. udelay(1);
  184. if (data & (1 << i))
  185. tmp |= PHASE28_SPI_MOSI;
  186. else
  187. tmp &= ~PHASE28_SPI_MOSI;
  188. snd_ice1712_gpio_write(ice, tmp);
  189. udelay(1);
  190. tmp |= PHASE28_SPI_CLK;
  191. snd_ice1712_gpio_write(ice, tmp);
  192. udelay(1);
  193. }
  194. tmp &= ~PHASE28_SPI_CLK;
  195. tmp |= cs;
  196. snd_ice1712_gpio_write(ice, tmp);
  197. udelay(1);
  198. tmp |= PHASE28_SPI_CLK;
  199. snd_ice1712_gpio_write(ice, tmp);
  200. udelay(1);
  201. }
  202. /*
  203. * get the current register value of WM codec
  204. */
  205. static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
  206. {
  207. reg <<= 1;
  208. return ((unsigned short)ice->akm[0].images[reg] << 8) |
  209. ice->akm[0].images[reg + 1];
  210. }
  211. /*
  212. * set the register value of WM codec
  213. */
  214. static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
  215. {
  216. phase28_spi_write(ice, PHASE28_WM_CS, (reg << 9) | (val & 0x1ff), 16);
  217. }
  218. /*
  219. * set the register value of WM codec and remember it
  220. */
  221. static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
  222. {
  223. wm_put_nocache(ice, reg, val);
  224. reg <<= 1;
  225. ice->akm[0].images[reg] = val >> 8;
  226. ice->akm[0].images[reg + 1] = val;
  227. }
  228. static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
  229. {
  230. unsigned char nvol;
  231. if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
  232. nvol = 0;
  233. else
  234. nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX];
  235. wm_put(ice, index, nvol);
  236. wm_put_nocache(ice, index, 0x180 | nvol);
  237. }
  238. /*
  239. * DAC mute control
  240. */
  241. #define wm_pcm_mute_info phase28_mono_bool_info
  242. static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  243. {
  244. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  245. down(&ice->gpio_mutex);
  246. ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1;
  247. up(&ice->gpio_mutex);
  248. return 0;
  249. }
  250. static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  251. {
  252. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  253. unsigned short nval, oval;
  254. int change;
  255. snd_ice1712_save_gpio_status(ice);
  256. oval = wm_get(ice, WM_MUTE);
  257. nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
  258. if ((change = (nval != oval)))
  259. wm_put(ice, WM_MUTE, nval);
  260. snd_ice1712_restore_gpio_status(ice);
  261. return change;
  262. }
  263. /*
  264. * Master volume attenuation mixer control
  265. */
  266. static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  267. {
  268. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  269. uinfo->count = 2;
  270. uinfo->value.integer.min = 0;
  271. uinfo->value.integer.max = WM_VOL_MAX;
  272. return 0;
  273. }
  274. static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  275. {
  276. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  277. int i;
  278. for (i=0; i<2; i++)
  279. ucontrol->value.integer.value[i] = ice->spec.phase28.master[i] & ~WM_VOL_MUTE;
  280. return 0;
  281. }
  282. static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  283. {
  284. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  285. int ch, change = 0;
  286. snd_ice1712_save_gpio_status(ice);
  287. for (ch = 0; ch < 2; ch++) {
  288. if (ucontrol->value.integer.value[ch] != ice->spec.phase28.master[ch]) {
  289. int dac;
  290. ice->spec.phase28.master[ch] &= WM_VOL_MUTE;
  291. ice->spec.phase28.master[ch] |= ucontrol->value.integer.value[ch];
  292. for (dac = 0; dac < ice->num_total_dacs; dac += 2)
  293. wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
  294. ice->spec.phase28.vol[dac + ch],
  295. ice->spec.phase28.master[ch]);
  296. change = 1;
  297. }
  298. }
  299. snd_ice1712_restore_gpio_status(ice);
  300. return change;
  301. }
  302. static int __devinit phase28_init(struct snd_ice1712 *ice)
  303. {
  304. static unsigned short wm_inits_phase28[] = {
  305. /* These come first to reduce init pop noise */
  306. 0x1b, 0x044, /* ADC Mux (AC'97 source) */
  307. 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
  308. 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
  309. 0x18, 0x000, /* All power-up */
  310. 0x16, 0x122, /* I2S, normal polarity, 24bit */
  311. 0x17, 0x022, /* 256fs, slave mode */
  312. 0x00, 0, /* DAC1 analog mute */
  313. 0x01, 0, /* DAC2 analog mute */
  314. 0x02, 0, /* DAC3 analog mute */
  315. 0x03, 0, /* DAC4 analog mute */
  316. 0x04, 0, /* DAC5 analog mute */
  317. 0x05, 0, /* DAC6 analog mute */
  318. 0x06, 0, /* DAC7 analog mute */
  319. 0x07, 0, /* DAC8 analog mute */
  320. 0x08, 0x100, /* master analog mute */
  321. 0x09, 0xff, /* DAC1 digital full */
  322. 0x0a, 0xff, /* DAC2 digital full */
  323. 0x0b, 0xff, /* DAC3 digital full */
  324. 0x0c, 0xff, /* DAC4 digital full */
  325. 0x0d, 0xff, /* DAC5 digital full */
  326. 0x0e, 0xff, /* DAC6 digital full */
  327. 0x0f, 0xff, /* DAC7 digital full */
  328. 0x10, 0xff, /* DAC8 digital full */
  329. 0x11, 0x1ff, /* master digital full */
  330. 0x12, 0x000, /* phase normal */
  331. 0x13, 0x090, /* unmute DAC L/R */
  332. 0x14, 0x000, /* all unmute */
  333. 0x15, 0x000, /* no deemphasis, no ZFLG */
  334. 0x19, 0x000, /* -12dB ADC/L */
  335. 0x1a, 0x000, /* -12dB ADC/R */
  336. (unsigned short)-1
  337. };
  338. unsigned int tmp;
  339. struct snd_akm4xxx *ak;
  340. unsigned short *p;
  341. int i;
  342. ice->num_total_dacs = 8;
  343. ice->num_total_adcs = 2;
  344. // Initialize analog chips
  345. ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  346. if (!ak)
  347. return -ENOMEM;
  348. ice->akm_codecs = 1;
  349. snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */
  350. /* reset the wm codec as the SPI mode */
  351. snd_ice1712_save_gpio_status(ice);
  352. snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RESET|PHASE28_WM_CS|PHASE28_HP_SEL));
  353. tmp = snd_ice1712_gpio_read(ice);
  354. tmp &= ~PHASE28_WM_RESET;
  355. snd_ice1712_gpio_write(ice, tmp);
  356. udelay(1);
  357. tmp |= PHASE28_WM_CS;
  358. snd_ice1712_gpio_write(ice, tmp);
  359. udelay(1);
  360. tmp |= PHASE28_WM_RESET;
  361. snd_ice1712_gpio_write(ice, tmp);
  362. udelay(1);
  363. p = wm_inits_phase28;
  364. for (; *p != (unsigned short)-1; p += 2)
  365. wm_put(ice, p[0], p[1]);
  366. snd_ice1712_restore_gpio_status(ice);
  367. ice->spec.phase28.master[0] = WM_VOL_MUTE;
  368. ice->spec.phase28.master[1] = WM_VOL_MUTE;
  369. for (i = 0; i < ice->num_total_dacs; i++) {
  370. ice->spec.phase28.vol[i] = WM_VOL_MUTE;
  371. wm_set_vol(ice, i, ice->spec.phase28.vol[i], ice->spec.phase28.master[i % 2]);
  372. }
  373. return 0;
  374. }
  375. /*
  376. * DAC volume attenuation mixer control
  377. */
  378. static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  379. {
  380. int voices = kcontrol->private_value >> 8;
  381. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  382. uinfo->count = voices;
  383. uinfo->value.integer.min = 0; /* mute (-101dB) */
  384. uinfo->value.integer.max = 0x7F; /* 0dB */
  385. return 0;
  386. }
  387. static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  388. {
  389. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  390. int i, ofs, voices;
  391. voices = kcontrol->private_value >> 8;
  392. ofs = kcontrol->private_value & 0xff;
  393. for (i = 0; i < voices; i++)
  394. ucontrol->value.integer.value[i] = ice->spec.phase28.vol[ofs+i] & ~WM_VOL_MUTE;
  395. return 0;
  396. }
  397. static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  398. {
  399. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  400. int i, idx, ofs, voices;
  401. int change = 0;
  402. voices = kcontrol->private_value >> 8;
  403. ofs = kcontrol->private_value & 0xff;
  404. snd_ice1712_save_gpio_status(ice);
  405. for (i = 0; i < voices; i++) {
  406. idx = WM_DAC_ATTEN + ofs + i;
  407. if (ucontrol->value.integer.value[i] != ice->spec.phase28.vol[ofs+i]) {
  408. ice->spec.phase28.vol[ofs+i] &= WM_VOL_MUTE;
  409. ice->spec.phase28.vol[ofs+i] |= ucontrol->value.integer.value[i];
  410. wm_set_vol(ice, idx, ice->spec.phase28.vol[ofs+i],
  411. ice->spec.phase28.master[i]);
  412. change = 1;
  413. }
  414. }
  415. snd_ice1712_restore_gpio_status(ice);
  416. return change;
  417. }
  418. /*
  419. * WM8770 mute control
  420. */
  421. static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  422. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  423. uinfo->count = kcontrol->private_value >> 8;
  424. uinfo->value.integer.min = 0;
  425. uinfo->value.integer.max = 1;
  426. return 0;
  427. }
  428. static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  429. {
  430. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  431. int voices, ofs, i;
  432. voices = kcontrol->private_value >> 8;
  433. ofs = kcontrol->private_value & 0xFF;
  434. for (i = 0; i < voices; i++)
  435. ucontrol->value.integer.value[i] = (ice->spec.phase28.vol[ofs+i] & WM_VOL_MUTE) ? 0 : 1;
  436. return 0;
  437. }
  438. static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  439. {
  440. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  441. int change = 0, voices, ofs, i;
  442. voices = kcontrol->private_value >> 8;
  443. ofs = kcontrol->private_value & 0xFF;
  444. snd_ice1712_save_gpio_status(ice);
  445. for (i = 0; i < voices; i++) {
  446. int val = (ice->spec.phase28.vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1;
  447. if (ucontrol->value.integer.value[i] != val) {
  448. ice->spec.phase28.vol[ofs + i] &= ~WM_VOL_MUTE;
  449. ice->spec.phase28.vol[ofs + i] |=
  450. ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
  451. wm_set_vol(ice, ofs + i, ice->spec.phase28.vol[ofs + i],
  452. ice->spec.phase28.master[i]);
  453. change = 1;
  454. }
  455. }
  456. snd_ice1712_restore_gpio_status(ice);
  457. return change;
  458. }
  459. /*
  460. * WM8770 master mute control
  461. */
  462. static int wm_master_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) {
  463. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  464. uinfo->count = 2;
  465. uinfo->value.integer.min = 0;
  466. uinfo->value.integer.max = 1;
  467. return 0;
  468. }
  469. static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  470. {
  471. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  472. ucontrol->value.integer.value[0] = (ice->spec.phase28.master[0] & WM_VOL_MUTE) ? 0 : 1;
  473. ucontrol->value.integer.value[1] = (ice->spec.phase28.master[1] & WM_VOL_MUTE) ? 0 : 1;
  474. return 0;
  475. }
  476. static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  477. {
  478. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  479. int change = 0, i;
  480. snd_ice1712_save_gpio_status(ice);
  481. for (i = 0; i < 2; i++) {
  482. int val = (ice->spec.phase28.master[i] & WM_VOL_MUTE) ? 0 : 1;
  483. if (ucontrol->value.integer.value[i] != val) {
  484. int dac;
  485. ice->spec.phase28.master[i] &= ~WM_VOL_MUTE;
  486. ice->spec.phase28.master[i] |=
  487. ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
  488. for (dac = 0; dac < ice->num_total_dacs; dac += 2)
  489. wm_set_vol(ice, WM_DAC_ATTEN + dac + i,
  490. ice->spec.phase28.vol[dac + i],
  491. ice->spec.phase28.master[i]);
  492. change = 1;
  493. }
  494. }
  495. snd_ice1712_restore_gpio_status(ice);
  496. return change;
  497. }
  498. /* digital master volume */
  499. #define PCM_0dB 0xff
  500. #define PCM_RES 128 /* -64dB */
  501. #define PCM_MIN (PCM_0dB - PCM_RES)
  502. static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  503. {
  504. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  505. uinfo->count = 1;
  506. uinfo->value.integer.min = 0; /* mute (-64dB) */
  507. uinfo->value.integer.max = PCM_RES; /* 0dB */
  508. return 0;
  509. }
  510. static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  511. {
  512. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  513. unsigned short val;
  514. down(&ice->gpio_mutex);
  515. val = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
  516. val = val > PCM_MIN ? (val - PCM_MIN) : 0;
  517. ucontrol->value.integer.value[0] = val;
  518. up(&ice->gpio_mutex);
  519. return 0;
  520. }
  521. static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  522. {
  523. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  524. unsigned short ovol, nvol;
  525. int change = 0;
  526. snd_ice1712_save_gpio_status(ice);
  527. nvol = ucontrol->value.integer.value[0];
  528. nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
  529. ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
  530. if (ovol != nvol) {
  531. wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */
  532. wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */
  533. change = 1;
  534. }
  535. snd_ice1712_restore_gpio_status(ice);
  536. return change;
  537. }
  538. /*
  539. */
  540. static int phase28_mono_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  541. {
  542. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  543. uinfo->count = 1;
  544. uinfo->value.integer.min = 0;
  545. uinfo->value.integer.max = 1;
  546. return 0;
  547. }
  548. /*
  549. * Deemphasis
  550. */
  551. #define phase28_deemp_info phase28_mono_bool_info
  552. static int phase28_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  553. {
  554. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  555. ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
  556. return 0;
  557. }
  558. static int phase28_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  559. {
  560. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  561. int temp, temp2;
  562. temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
  563. if (ucontrol->value.integer.value[0])
  564. temp |= 0xf;
  565. else
  566. temp &= ~0xf;
  567. if (temp != temp2) {
  568. wm_put(ice, WM_DAC_CTRL2, temp);
  569. return 1;
  570. }
  571. return 0;
  572. }
  573. /*
  574. * ADC Oversampling
  575. */
  576. static int phase28_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  577. {
  578. static char *texts[2] = { "128x", "64x" };
  579. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  580. uinfo->count = 1;
  581. uinfo->value.enumerated.items = 2;
  582. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  583. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  584. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  585. return 0;
  586. }
  587. static int phase28_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  588. {
  589. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  590. ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
  591. return 0;
  592. }
  593. static int phase28_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  594. {
  595. int temp, temp2;
  596. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  597. temp2 = temp = wm_get(ice, WM_MASTER);
  598. if (ucontrol->value.enumerated.item[0])
  599. temp |= 0x8;
  600. else
  601. temp &= ~0x8;
  602. if (temp != temp2) {
  603. wm_put(ice, WM_MASTER, temp);
  604. return 1;
  605. }
  606. return 0;
  607. }
  608. static struct snd_kcontrol_new phase28_dac_controls[] __devinitdata = {
  609. {
  610. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  611. .name = "Master Playback Switch",
  612. .info = wm_master_mute_info,
  613. .get = wm_master_mute_get,
  614. .put = wm_master_mute_put
  615. },
  616. {
  617. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  618. .name = "Master Playback Volume",
  619. .info = wm_master_vol_info,
  620. .get = wm_master_vol_get,
  621. .put = wm_master_vol_put
  622. },
  623. {
  624. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  625. .name = "Front Playback Switch",
  626. .info = wm_mute_info,
  627. .get = wm_mute_get,
  628. .put = wm_mute_put,
  629. .private_value = (2 << 8) | 0
  630. },
  631. {
  632. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  633. .name = "Front Playback Volume",
  634. .info = wm_vol_info,
  635. .get = wm_vol_get,
  636. .put = wm_vol_put,
  637. .private_value = (2 << 8) | 0
  638. },
  639. {
  640. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  641. .name = "Rear Playback Switch",
  642. .info = wm_mute_info,
  643. .get = wm_mute_get,
  644. .put = wm_mute_put,
  645. .private_value = (2 << 8) | 2
  646. },
  647. {
  648. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  649. .name = "Rear Playback Volume",
  650. .info = wm_vol_info,
  651. .get = wm_vol_get,
  652. .put = wm_vol_put,
  653. .private_value = (2 << 8) | 2
  654. },
  655. {
  656. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  657. .name = "Center Playback Switch",
  658. .info = wm_mute_info,
  659. .get = wm_mute_get,
  660. .put = wm_mute_put,
  661. .private_value = (1 << 8) | 4
  662. },
  663. {
  664. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  665. .name = "Center Playback Volume",
  666. .info = wm_vol_info,
  667. .get = wm_vol_get,
  668. .put = wm_vol_put,
  669. .private_value = (1 << 8) | 4
  670. },
  671. {
  672. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  673. .name = "LFE Playback Switch",
  674. .info = wm_mute_info,
  675. .get = wm_mute_get,
  676. .put = wm_mute_put,
  677. .private_value = (1 << 8) | 5
  678. },
  679. {
  680. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  681. .name = "LFE Playback Volume",
  682. .info = wm_vol_info,
  683. .get = wm_vol_get,
  684. .put = wm_vol_put,
  685. .private_value = (1 << 8) | 5
  686. },
  687. {
  688. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  689. .name = "Side Playback Switch",
  690. .info = wm_mute_info,
  691. .get = wm_mute_get,
  692. .put = wm_mute_put,
  693. .private_value = (2 << 8) | 6
  694. },
  695. {
  696. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  697. .name = "Side Playback Volume",
  698. .info = wm_vol_info,
  699. .get = wm_vol_get,
  700. .put = wm_vol_put,
  701. .private_value = (2 << 8) | 6
  702. }
  703. };
  704. static struct snd_kcontrol_new wm_controls[] __devinitdata = {
  705. {
  706. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  707. .name = "PCM Playback Switch",
  708. .info = wm_pcm_mute_info,
  709. .get = wm_pcm_mute_get,
  710. .put = wm_pcm_mute_put
  711. },
  712. {
  713. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  714. .name = "PCM Playback Volume",
  715. .info = wm_pcm_vol_info,
  716. .get = wm_pcm_vol_get,
  717. .put = wm_pcm_vol_put
  718. },
  719. {
  720. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  721. .name = "DAC Deemphasis Switch",
  722. .info = phase28_deemp_info,
  723. .get = phase28_deemp_get,
  724. .put = phase28_deemp_put
  725. },
  726. {
  727. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  728. .name = "ADC Oversampling",
  729. .info = phase28_oversampling_info,
  730. .get = phase28_oversampling_get,
  731. .put = phase28_oversampling_put
  732. }
  733. };
  734. static int __devinit phase28_add_controls(struct snd_ice1712 *ice)
  735. {
  736. unsigned int i, counts;
  737. int err;
  738. counts = ARRAY_SIZE(phase28_dac_controls);
  739. for (i = 0; i < counts; i++) {
  740. err = snd_ctl_add(ice->card, snd_ctl_new1(&phase28_dac_controls[i], ice));
  741. if (err < 0)
  742. return err;
  743. }
  744. for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
  745. err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice));
  746. if (err < 0)
  747. return err;
  748. }
  749. return 0;
  750. }
  751. struct snd_ice1712_card_info snd_vt1724_phase_cards[] __devinitdata = {
  752. {
  753. .subvendor = VT1724_SUBDEVICE_PHASE22,
  754. .name = "Terratec PHASE 22",
  755. .model = "phase22",
  756. .chip_init = phase22_init,
  757. .build_controls = phase22_add_controls,
  758. .eeprom_size = sizeof(phase22_eeprom),
  759. .eeprom_data = phase22_eeprom,
  760. },
  761. {
  762. .subvendor = VT1724_SUBDEVICE_PHASE28,
  763. .name = "Terratec PHASE 28",
  764. .model = "phase28",
  765. .chip_init = phase28_init,
  766. .build_controls = phase28_add_controls,
  767. .eeprom_size = sizeof(phase28_eeprom),
  768. .eeprom_data = phase28_eeprom,
  769. },
  770. { } /* terminator */
  771. };