phase.c 23 KB

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