pontis.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for Pontis MS300
  5. *
  6. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/slab.h>
  27. #include <linux/mutex.h>
  28. #include <sound/core.h>
  29. #include <sound/info.h>
  30. #include <sound/tlv.h>
  31. #include "ice1712.h"
  32. #include "envy24ht.h"
  33. #include "pontis.h"
  34. /* I2C addresses */
  35. #define WM_DEV 0x34
  36. #define CS_DEV 0x20
  37. /* WM8776 registers */
  38. #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
  39. #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
  40. #define WM_HP_MASTER 0x02 /* headphone master (both channels) */
  41. /* override LLR */
  42. #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
  43. #define WM_DAC_ATTEN_R 0x04
  44. #define WM_DAC_MASTER 0x05
  45. #define WM_PHASE_SWAP 0x06 /* DAC phase swap */
  46. #define WM_DAC_CTRL1 0x07
  47. #define WM_DAC_MUTE 0x08
  48. #define WM_DAC_CTRL2 0x09
  49. #define WM_DAC_INT 0x0a
  50. #define WM_ADC_INT 0x0b
  51. #define WM_MASTER_CTRL 0x0c
  52. #define WM_POWERDOWN 0x0d
  53. #define WM_ADC_ATTEN_L 0x0e
  54. #define WM_ADC_ATTEN_R 0x0f
  55. #define WM_ALC_CTRL1 0x10
  56. #define WM_ALC_CTRL2 0x11
  57. #define WM_ALC_CTRL3 0x12
  58. #define WM_NOISE_GATE 0x13
  59. #define WM_LIMITER 0x14
  60. #define WM_ADC_MUX 0x15
  61. #define WM_OUT_MUX 0x16
  62. #define WM_RESET 0x17
  63. /*
  64. * GPIO
  65. */
  66. #define PONTIS_CS_CS (1<<4) /* CS */
  67. #define PONTIS_CS_CLK (1<<5) /* CLK */
  68. #define PONTIS_CS_RDATA (1<<6) /* CS8416 -> VT1720 */
  69. #define PONTIS_CS_WDATA (1<<7) /* VT1720 -> CS8416 */
  70. /*
  71. * get the current register value of WM codec
  72. */
  73. static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
  74. {
  75. reg <<= 1;
  76. return ((unsigned short)ice->akm[0].images[reg] << 8) |
  77. ice->akm[0].images[reg + 1];
  78. }
  79. /*
  80. * set the register value of WM codec and remember it
  81. */
  82. static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
  83. {
  84. unsigned short cval;
  85. cval = (reg << 9) | val;
  86. snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff);
  87. }
  88. static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
  89. {
  90. wm_put_nocache(ice, reg, val);
  91. reg <<= 1;
  92. ice->akm[0].images[reg] = val >> 8;
  93. ice->akm[0].images[reg + 1] = val;
  94. }
  95. /*
  96. * DAC volume attenuation mixer control (-64dB to 0dB)
  97. */
  98. #define DAC_0dB 0xff
  99. #define DAC_RES 128
  100. #define DAC_MIN (DAC_0dB - DAC_RES)
  101. static int wm_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  102. {
  103. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  104. uinfo->count = 2;
  105. uinfo->value.integer.min = 0; /* mute */
  106. uinfo->value.integer.max = DAC_RES; /* 0dB, 0.5dB step */
  107. return 0;
  108. }
  109. static int wm_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  110. {
  111. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  112. unsigned short val;
  113. int i;
  114. mutex_lock(&ice->gpio_mutex);
  115. for (i = 0; i < 2; i++) {
  116. val = wm_get(ice, WM_DAC_ATTEN_L + i) & 0xff;
  117. val = val > DAC_MIN ? (val - DAC_MIN) : 0;
  118. ucontrol->value.integer.value[i] = val;
  119. }
  120. mutex_unlock(&ice->gpio_mutex);
  121. return 0;
  122. }
  123. static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  124. {
  125. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  126. unsigned short oval, nval;
  127. int i, idx, change = 0;
  128. mutex_lock(&ice->gpio_mutex);
  129. for (i = 0; i < 2; i++) {
  130. nval = ucontrol->value.integer.value[i];
  131. nval = (nval ? (nval + DAC_MIN) : 0) & 0xff;
  132. idx = WM_DAC_ATTEN_L + i;
  133. oval = wm_get(ice, idx) & 0xff;
  134. if (oval != nval) {
  135. wm_put(ice, idx, nval);
  136. wm_put_nocache(ice, idx, nval | 0x100);
  137. change = 1;
  138. }
  139. }
  140. mutex_unlock(&ice->gpio_mutex);
  141. return change;
  142. }
  143. /*
  144. * ADC gain mixer control (-64dB to 0dB)
  145. */
  146. #define ADC_0dB 0xcf
  147. #define ADC_RES 128
  148. #define ADC_MIN (ADC_0dB - ADC_RES)
  149. static int wm_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  150. {
  151. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  152. uinfo->count = 2;
  153. uinfo->value.integer.min = 0; /* mute (-64dB) */
  154. uinfo->value.integer.max = ADC_RES; /* 0dB, 0.5dB step */
  155. return 0;
  156. }
  157. static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  158. {
  159. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  160. unsigned short val;
  161. int i;
  162. mutex_lock(&ice->gpio_mutex);
  163. for (i = 0; i < 2; i++) {
  164. val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff;
  165. val = val > ADC_MIN ? (val - ADC_MIN) : 0;
  166. ucontrol->value.integer.value[i] = val;
  167. }
  168. mutex_unlock(&ice->gpio_mutex);
  169. return 0;
  170. }
  171. static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  172. {
  173. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  174. unsigned short ovol, nvol;
  175. int i, idx, change = 0;
  176. mutex_lock(&ice->gpio_mutex);
  177. for (i = 0; i < 2; i++) {
  178. nvol = ucontrol->value.integer.value[i];
  179. nvol = nvol ? (nvol + ADC_MIN) : 0;
  180. idx = WM_ADC_ATTEN_L + i;
  181. ovol = wm_get(ice, idx) & 0xff;
  182. if (ovol != nvol) {
  183. wm_put(ice, idx, nvol);
  184. change = 1;
  185. }
  186. }
  187. mutex_unlock(&ice->gpio_mutex);
  188. return change;
  189. }
  190. /*
  191. * ADC input mux mixer control
  192. */
  193. #define wm_adc_mux_info snd_ctl_boolean_mono_info
  194. static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  195. {
  196. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  197. int bit = kcontrol->private_value;
  198. mutex_lock(&ice->gpio_mutex);
  199. ucontrol->value.integer.value[0] = (wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0;
  200. mutex_unlock(&ice->gpio_mutex);
  201. return 0;
  202. }
  203. static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  204. {
  205. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  206. int bit = kcontrol->private_value;
  207. unsigned short oval, nval;
  208. int change;
  209. mutex_lock(&ice->gpio_mutex);
  210. nval = oval = wm_get(ice, WM_ADC_MUX);
  211. if (ucontrol->value.integer.value[0])
  212. nval |= (1 << bit);
  213. else
  214. nval &= ~(1 << bit);
  215. change = nval != oval;
  216. if (change) {
  217. wm_put(ice, WM_ADC_MUX, nval);
  218. }
  219. mutex_unlock(&ice->gpio_mutex);
  220. return change;
  221. }
  222. /*
  223. * Analog bypass (In -> Out)
  224. */
  225. #define wm_bypass_info snd_ctl_boolean_mono_info
  226. static int wm_bypass_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  227. {
  228. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  229. mutex_lock(&ice->gpio_mutex);
  230. ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0;
  231. mutex_unlock(&ice->gpio_mutex);
  232. return 0;
  233. }
  234. static int wm_bypass_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  235. {
  236. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  237. unsigned short val, oval;
  238. int change = 0;
  239. mutex_lock(&ice->gpio_mutex);
  240. val = oval = wm_get(ice, WM_OUT_MUX);
  241. if (ucontrol->value.integer.value[0])
  242. val |= 0x04;
  243. else
  244. val &= ~0x04;
  245. if (val != oval) {
  246. wm_put(ice, WM_OUT_MUX, val);
  247. change = 1;
  248. }
  249. mutex_unlock(&ice->gpio_mutex);
  250. return change;
  251. }
  252. /*
  253. * Left/Right swap
  254. */
  255. #define wm_chswap_info snd_ctl_boolean_mono_info
  256. static int wm_chswap_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  257. {
  258. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  259. mutex_lock(&ice->gpio_mutex);
  260. ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90;
  261. mutex_unlock(&ice->gpio_mutex);
  262. return 0;
  263. }
  264. static int wm_chswap_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  265. {
  266. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  267. unsigned short val, oval;
  268. int change = 0;
  269. mutex_lock(&ice->gpio_mutex);
  270. oval = wm_get(ice, WM_DAC_CTRL1);
  271. val = oval & 0x0f;
  272. if (ucontrol->value.integer.value[0])
  273. val |= 0x60;
  274. else
  275. val |= 0x90;
  276. if (val != oval) {
  277. wm_put(ice, WM_DAC_CTRL1, val);
  278. wm_put_nocache(ice, WM_DAC_CTRL1, val);
  279. change = 1;
  280. }
  281. mutex_unlock(&ice->gpio_mutex);
  282. return change;
  283. }
  284. /*
  285. * write data in the SPI mode
  286. */
  287. static void set_gpio_bit(struct snd_ice1712 *ice, unsigned int bit, int val)
  288. {
  289. unsigned int tmp = snd_ice1712_gpio_read(ice);
  290. if (val)
  291. tmp |= bit;
  292. else
  293. tmp &= ~bit;
  294. snd_ice1712_gpio_write(ice, tmp);
  295. }
  296. static void spi_send_byte(struct snd_ice1712 *ice, unsigned char data)
  297. {
  298. int i;
  299. for (i = 0; i < 8; i++) {
  300. set_gpio_bit(ice, PONTIS_CS_CLK, 0);
  301. udelay(1);
  302. set_gpio_bit(ice, PONTIS_CS_WDATA, data & 0x80);
  303. udelay(1);
  304. set_gpio_bit(ice, PONTIS_CS_CLK, 1);
  305. udelay(1);
  306. data <<= 1;
  307. }
  308. }
  309. static unsigned int spi_read_byte(struct snd_ice1712 *ice)
  310. {
  311. int i;
  312. unsigned int val = 0;
  313. for (i = 0; i < 8; i++) {
  314. val <<= 1;
  315. set_gpio_bit(ice, PONTIS_CS_CLK, 0);
  316. udelay(1);
  317. if (snd_ice1712_gpio_read(ice) & PONTIS_CS_RDATA)
  318. val |= 1;
  319. udelay(1);
  320. set_gpio_bit(ice, PONTIS_CS_CLK, 1);
  321. udelay(1);
  322. }
  323. return val;
  324. }
  325. static void spi_write(struct snd_ice1712 *ice, unsigned int dev, unsigned int reg, unsigned int data)
  326. {
  327. snd_ice1712_gpio_set_dir(ice, PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK);
  328. snd_ice1712_gpio_set_mask(ice, ~(PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK));
  329. set_gpio_bit(ice, PONTIS_CS_CS, 0);
  330. spi_send_byte(ice, dev & ~1); /* WRITE */
  331. spi_send_byte(ice, reg); /* MAP */
  332. spi_send_byte(ice, data); /* DATA */
  333. /* trigger */
  334. set_gpio_bit(ice, PONTIS_CS_CS, 1);
  335. udelay(1);
  336. /* restore */
  337. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  338. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  339. }
  340. static unsigned int spi_read(struct snd_ice1712 *ice, unsigned int dev, unsigned int reg)
  341. {
  342. unsigned int val;
  343. snd_ice1712_gpio_set_dir(ice, PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK);
  344. snd_ice1712_gpio_set_mask(ice, ~(PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK));
  345. set_gpio_bit(ice, PONTIS_CS_CS, 0);
  346. spi_send_byte(ice, dev & ~1); /* WRITE */
  347. spi_send_byte(ice, reg); /* MAP */
  348. /* trigger */
  349. set_gpio_bit(ice, PONTIS_CS_CS, 1);
  350. udelay(1);
  351. set_gpio_bit(ice, PONTIS_CS_CS, 0);
  352. spi_send_byte(ice, dev | 1); /* READ */
  353. val = spi_read_byte(ice);
  354. /* trigger */
  355. set_gpio_bit(ice, PONTIS_CS_CS, 1);
  356. udelay(1);
  357. /* restore */
  358. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  359. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  360. return val;
  361. }
  362. /*
  363. * SPDIF input source
  364. */
  365. static int cs_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  366. {
  367. static const char * const texts[] = {
  368. "Coax", /* RXP0 */
  369. "Optical", /* RXP1 */
  370. "CD", /* RXP2 */
  371. };
  372. return snd_ctl_enum_info(uinfo, 1, 3, texts);
  373. }
  374. static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  375. {
  376. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  377. mutex_lock(&ice->gpio_mutex);
  378. ucontrol->value.enumerated.item[0] = ice->gpio.saved[0];
  379. mutex_unlock(&ice->gpio_mutex);
  380. return 0;
  381. }
  382. static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  383. {
  384. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  385. unsigned char val;
  386. int change = 0;
  387. mutex_lock(&ice->gpio_mutex);
  388. if (ucontrol->value.enumerated.item[0] != ice->gpio.saved[0]) {
  389. ice->gpio.saved[0] = ucontrol->value.enumerated.item[0] & 3;
  390. val = 0x80 | (ice->gpio.saved[0] << 3);
  391. spi_write(ice, CS_DEV, 0x04, val);
  392. change = 1;
  393. }
  394. mutex_unlock(&ice->gpio_mutex);
  395. return change;
  396. }
  397. /*
  398. * GPIO controls
  399. */
  400. static int pontis_gpio_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  401. {
  402. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  403. uinfo->count = 1;
  404. uinfo->value.integer.min = 0;
  405. uinfo->value.integer.max = 0xffff; /* 16bit */
  406. return 0;
  407. }
  408. static int pontis_gpio_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  409. {
  410. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  411. mutex_lock(&ice->gpio_mutex);
  412. /* 4-7 reserved */
  413. ucontrol->value.integer.value[0] = (~ice->gpio.write_mask & 0xffff) | 0x00f0;
  414. mutex_unlock(&ice->gpio_mutex);
  415. return 0;
  416. }
  417. static int pontis_gpio_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  418. {
  419. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  420. unsigned int val;
  421. int changed;
  422. mutex_lock(&ice->gpio_mutex);
  423. /* 4-7 reserved */
  424. val = (~ucontrol->value.integer.value[0] & 0xffff) | 0x00f0;
  425. changed = val != ice->gpio.write_mask;
  426. ice->gpio.write_mask = val;
  427. mutex_unlock(&ice->gpio_mutex);
  428. return changed;
  429. }
  430. static int pontis_gpio_dir_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  431. {
  432. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  433. mutex_lock(&ice->gpio_mutex);
  434. /* 4-7 reserved */
  435. ucontrol->value.integer.value[0] = ice->gpio.direction & 0xff0f;
  436. mutex_unlock(&ice->gpio_mutex);
  437. return 0;
  438. }
  439. static int pontis_gpio_dir_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  440. {
  441. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  442. unsigned int val;
  443. int changed;
  444. mutex_lock(&ice->gpio_mutex);
  445. /* 4-7 reserved */
  446. val = ucontrol->value.integer.value[0] & 0xff0f;
  447. changed = (val != ice->gpio.direction);
  448. ice->gpio.direction = val;
  449. mutex_unlock(&ice->gpio_mutex);
  450. return changed;
  451. }
  452. static int pontis_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  453. {
  454. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  455. mutex_lock(&ice->gpio_mutex);
  456. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  457. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  458. ucontrol->value.integer.value[0] = snd_ice1712_gpio_read(ice) & 0xffff;
  459. mutex_unlock(&ice->gpio_mutex);
  460. return 0;
  461. }
  462. static int pontis_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  463. {
  464. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  465. unsigned int val, nval;
  466. int changed = 0;
  467. mutex_lock(&ice->gpio_mutex);
  468. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  469. snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
  470. val = snd_ice1712_gpio_read(ice) & 0xffff;
  471. nval = ucontrol->value.integer.value[0] & 0xffff;
  472. if (val != nval) {
  473. snd_ice1712_gpio_write(ice, nval);
  474. changed = 1;
  475. }
  476. mutex_unlock(&ice->gpio_mutex);
  477. return changed;
  478. }
  479. static const DECLARE_TLV_DB_SCALE(db_scale_volume, -6400, 50, 1);
  480. /*
  481. * mixers
  482. */
  483. static struct snd_kcontrol_new pontis_controls[] = {
  484. {
  485. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  486. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  487. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  488. .name = "PCM Playback Volume",
  489. .info = wm_dac_vol_info,
  490. .get = wm_dac_vol_get,
  491. .put = wm_dac_vol_put,
  492. .tlv = { .p = db_scale_volume },
  493. },
  494. {
  495. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  496. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  497. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  498. .name = "Capture Volume",
  499. .info = wm_adc_vol_info,
  500. .get = wm_adc_vol_get,
  501. .put = wm_adc_vol_put,
  502. .tlv = { .p = db_scale_volume },
  503. },
  504. {
  505. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  506. .name = "CD Capture Switch",
  507. .info = wm_adc_mux_info,
  508. .get = wm_adc_mux_get,
  509. .put = wm_adc_mux_put,
  510. .private_value = 0,
  511. },
  512. {
  513. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  514. .name = "Line Capture Switch",
  515. .info = wm_adc_mux_info,
  516. .get = wm_adc_mux_get,
  517. .put = wm_adc_mux_put,
  518. .private_value = 1,
  519. },
  520. {
  521. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  522. .name = "Analog Bypass Switch",
  523. .info = wm_bypass_info,
  524. .get = wm_bypass_get,
  525. .put = wm_bypass_put,
  526. },
  527. {
  528. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  529. .name = "Swap Output Channels",
  530. .info = wm_chswap_info,
  531. .get = wm_chswap_get,
  532. .put = wm_chswap_put,
  533. },
  534. {
  535. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  536. .name = "IEC958 Input Source",
  537. .info = cs_source_info,
  538. .get = cs_source_get,
  539. .put = cs_source_put,
  540. },
  541. /* FIXME: which interface? */
  542. {
  543. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  544. .name = "GPIO Mask",
  545. .info = pontis_gpio_mask_info,
  546. .get = pontis_gpio_mask_get,
  547. .put = pontis_gpio_mask_put,
  548. },
  549. {
  550. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  551. .name = "GPIO Direction",
  552. .info = pontis_gpio_mask_info,
  553. .get = pontis_gpio_dir_get,
  554. .put = pontis_gpio_dir_put,
  555. },
  556. {
  557. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  558. .name = "GPIO Data",
  559. .info = pontis_gpio_mask_info,
  560. .get = pontis_gpio_data_get,
  561. .put = pontis_gpio_data_put,
  562. },
  563. };
  564. /*
  565. * WM codec registers
  566. */
  567. static void wm_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  568. {
  569. struct snd_ice1712 *ice = entry->private_data;
  570. char line[64];
  571. unsigned int reg, val;
  572. mutex_lock(&ice->gpio_mutex);
  573. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  574. if (sscanf(line, "%x %x", &reg, &val) != 2)
  575. continue;
  576. if (reg <= 0x17 && val <= 0xffff)
  577. wm_put(ice, reg, val);
  578. }
  579. mutex_unlock(&ice->gpio_mutex);
  580. }
  581. static void wm_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  582. {
  583. struct snd_ice1712 *ice = entry->private_data;
  584. int reg, val;
  585. mutex_lock(&ice->gpio_mutex);
  586. for (reg = 0; reg <= 0x17; reg++) {
  587. val = wm_get(ice, reg);
  588. snd_iprintf(buffer, "%02x = %04x\n", reg, val);
  589. }
  590. mutex_unlock(&ice->gpio_mutex);
  591. }
  592. static void wm_proc_init(struct snd_ice1712 *ice)
  593. {
  594. struct snd_info_entry *entry;
  595. if (! snd_card_proc_new(ice->card, "wm_codec", &entry)) {
  596. snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
  597. entry->mode |= S_IWUSR;
  598. entry->c.text.write = wm_proc_regs_write;
  599. }
  600. }
  601. static void cs_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  602. {
  603. struct snd_ice1712 *ice = entry->private_data;
  604. int reg, val;
  605. mutex_lock(&ice->gpio_mutex);
  606. for (reg = 0; reg <= 0x26; reg++) {
  607. val = spi_read(ice, CS_DEV, reg);
  608. snd_iprintf(buffer, "%02x = %02x\n", reg, val);
  609. }
  610. val = spi_read(ice, CS_DEV, 0x7f);
  611. snd_iprintf(buffer, "%02x = %02x\n", 0x7f, val);
  612. mutex_unlock(&ice->gpio_mutex);
  613. }
  614. static void cs_proc_init(struct snd_ice1712 *ice)
  615. {
  616. struct snd_info_entry *entry;
  617. if (! snd_card_proc_new(ice->card, "cs_codec", &entry))
  618. snd_info_set_text_ops(entry, ice, cs_proc_regs_read);
  619. }
  620. static int pontis_add_controls(struct snd_ice1712 *ice)
  621. {
  622. unsigned int i;
  623. int err;
  624. for (i = 0; i < ARRAY_SIZE(pontis_controls); i++) {
  625. err = snd_ctl_add(ice->card, snd_ctl_new1(&pontis_controls[i], ice));
  626. if (err < 0)
  627. return err;
  628. }
  629. wm_proc_init(ice);
  630. cs_proc_init(ice);
  631. return 0;
  632. }
  633. /*
  634. * initialize the chip
  635. */
  636. static int pontis_init(struct snd_ice1712 *ice)
  637. {
  638. static const unsigned short wm_inits[] = {
  639. /* These come first to reduce init pop noise */
  640. WM_ADC_MUX, 0x00c0, /* ADC mute */
  641. WM_DAC_MUTE, 0x0001, /* DAC softmute */
  642. WM_DAC_CTRL1, 0x0000, /* DAC mute */
  643. WM_POWERDOWN, 0x0008, /* All power-up except HP */
  644. WM_RESET, 0x0000, /* reset */
  645. };
  646. static const unsigned short wm_inits2[] = {
  647. WM_MASTER_CTRL, 0x0022, /* 256fs, slave mode */
  648. WM_DAC_INT, 0x0022, /* I2S, normal polarity, 24bit */
  649. WM_ADC_INT, 0x0022, /* I2S, normal polarity, 24bit */
  650. WM_DAC_CTRL1, 0x0090, /* DAC L/R */
  651. WM_OUT_MUX, 0x0001, /* OUT DAC */
  652. WM_HP_ATTEN_L, 0x0179, /* HP 0dB */
  653. WM_HP_ATTEN_R, 0x0179, /* HP 0dB */
  654. WM_DAC_ATTEN_L, 0x0000, /* DAC 0dB */
  655. WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */
  656. WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */
  657. WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */
  658. /* WM_DAC_MASTER, 0x0100, */ /* DAC master muted */
  659. WM_PHASE_SWAP, 0x0000, /* phase normal */
  660. WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */
  661. WM_ADC_ATTEN_L, 0x0000, /* ADC muted */
  662. WM_ADC_ATTEN_R, 0x0000, /* ADC muted */
  663. #if 0
  664. WM_ALC_CTRL1, 0x007b, /* */
  665. WM_ALC_CTRL2, 0x0000, /* */
  666. WM_ALC_CTRL3, 0x0000, /* */
  667. WM_NOISE_GATE, 0x0000, /* */
  668. #endif
  669. WM_DAC_MUTE, 0x0000, /* DAC unmute */
  670. WM_ADC_MUX, 0x0003, /* ADC unmute, both CD/Line On */
  671. };
  672. static const unsigned char cs_inits[] = {
  673. 0x04, 0x80, /* RUN, RXP0 */
  674. 0x05, 0x05, /* slave, 24bit */
  675. 0x01, 0x00,
  676. 0x02, 0x00,
  677. 0x03, 0x00,
  678. };
  679. unsigned int i;
  680. ice->vt1720 = 1;
  681. ice->num_total_dacs = 2;
  682. ice->num_total_adcs = 2;
  683. /* to remember the register values */
  684. ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  685. if (! ice->akm)
  686. return -ENOMEM;
  687. ice->akm_codecs = 1;
  688. /* HACK - use this as the SPDIF source.
  689. * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
  690. */
  691. ice->gpio.saved[0] = 0;
  692. /* initialize WM8776 codec */
  693. for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
  694. wm_put(ice, wm_inits[i], wm_inits[i+1]);
  695. schedule_timeout_uninterruptible(1);
  696. for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
  697. wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
  698. /* initialize CS8416 codec */
  699. /* assert PRST#; MT05 bit 7 */
  700. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  701. mdelay(5);
  702. /* deassert PRST# */
  703. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  704. for (i = 0; i < ARRAY_SIZE(cs_inits); i += 2)
  705. spi_write(ice, CS_DEV, cs_inits[i], cs_inits[i+1]);
  706. return 0;
  707. }
  708. /*
  709. * Pontis boards don't provide the EEPROM data at all.
  710. * hence the driver needs to sets up it properly.
  711. */
  712. static unsigned char pontis_eeprom[] = {
  713. [ICE_EEP2_SYSCONF] = 0x08, /* clock 256, mpu401, spdif-in/ADC, 1DAC */
  714. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  715. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  716. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  717. [ICE_EEP2_GPIO_DIR] = 0x07,
  718. [ICE_EEP2_GPIO_DIR1] = 0x00,
  719. [ICE_EEP2_GPIO_DIR2] = 0x00, /* ignored */
  720. [ICE_EEP2_GPIO_MASK] = 0x0f, /* 4-7 reserved for CS8416 */
  721. [ICE_EEP2_GPIO_MASK1] = 0xff,
  722. [ICE_EEP2_GPIO_MASK2] = 0x00, /* ignored */
  723. [ICE_EEP2_GPIO_STATE] = 0x06, /* 0-low, 1-high, 2-high */
  724. [ICE_EEP2_GPIO_STATE1] = 0x00,
  725. [ICE_EEP2_GPIO_STATE2] = 0x00, /* ignored */
  726. };
  727. /* entry point */
  728. struct snd_ice1712_card_info snd_vt1720_pontis_cards[] = {
  729. {
  730. .subvendor = VT1720_SUBDEVICE_PONTIS_MS300,
  731. .name = "Pontis MS300",
  732. .model = "ms300",
  733. .chip_init = pontis_init,
  734. .build_controls = pontis_add_controls,
  735. .eeprom_size = sizeof(pontis_eeprom),
  736. .eeprom_data = pontis_eeprom,
  737. },
  738. { } /* terminator */
  739. };