wtm.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for Ego Sys Waveterminal 192M
  5. *
  6. * Copyright (c) 2006 Guedez Clement <klem.dev@gmail.com>
  7. * Some functions are taken from the Prodigy192 driver
  8. * source
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <sound/driver.h>
  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 <sound/core.h>
  32. #include "ice1712.h"
  33. #include "envy24ht.h"
  34. #include "wtm.h"
  35. #include "stac946x.h"
  36. /*
  37. * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
  38. */
  39. static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
  40. unsigned char val)
  41. {
  42. snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
  43. }
  44. static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
  45. {
  46. return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg);
  47. }
  48. /*
  49. * 2*ADC 2*DAC no2 ringbuffer r/w on i2c bus
  50. */
  51. static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg,
  52. unsigned char val)
  53. {
  54. snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val);
  55. }
  56. static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
  57. {
  58. return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg);
  59. }
  60. /*
  61. * DAC mute control
  62. */
  63. static int stac9460_dac_mute_info(struct snd_kcontrol *kcontrol,
  64. struct snd_ctl_elem_info *uinfo)
  65. {
  66. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  67. uinfo->count = 1;
  68. uinfo->value.integer.min = 0;
  69. return 0;
  70. }
  71. static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
  72. struct snd_ctl_elem_value *ucontrol)
  73. {
  74. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  75. unsigned char val;
  76. int idx, id;
  77. if (kcontrol->private_value) {
  78. idx = STAC946X_MASTER_VOLUME;
  79. id = 0;
  80. } else {
  81. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  82. idx = id + STAC946X_LF_VOLUME;
  83. }
  84. if (id < 6)
  85. val = stac9460_get(ice, idx);
  86. else
  87. val = stac9460_2_get(ice,idx - 6);
  88. ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
  89. return 0;
  90. }
  91. static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
  92. struct snd_ctl_elem_value *ucontrol)
  93. {
  94. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  95. unsigned char new, old;
  96. int id, idx;
  97. int change;
  98. if (kcontrol->private_value) {
  99. idx = STAC946X_MASTER_VOLUME;
  100. old = stac9460_get(ice, idx);
  101. new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) |
  102. (old & ~0x80);
  103. change = (new != old);
  104. if (change) {
  105. stac9460_put(ice, idx, new);
  106. stac9460_2_put(ice, idx, new);
  107. }
  108. } else {
  109. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  110. idx = id + STAC946X_LF_VOLUME;
  111. if (id < 6)
  112. old = stac9460_get(ice, idx);
  113. else
  114. old = stac9460_2_get(ice, idx - 6);
  115. new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) |
  116. (old & ~0x80);
  117. change = (new != old);
  118. if (change) {
  119. if (id < 6)
  120. stac9460_put(ice, idx, new);
  121. else
  122. stac9460_2_put(ice, idx - 6, new);
  123. }
  124. }
  125. return change;
  126. }
  127. /*
  128. * DAC volume attenuation mixer control
  129. */
  130. static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
  131. struct snd_ctl_elem_info *uinfo)
  132. {
  133. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  134. uinfo->count = 1;
  135. uinfo->value.integer.min = 0; /* mute */
  136. uinfo->value.integer.max = 0x7f; /* 0dB */
  137. return 0;
  138. }
  139. static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
  140. struct snd_ctl_elem_value *ucontrol)
  141. {
  142. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  143. int idx, id;
  144. unsigned char vol;
  145. if (kcontrol->private_value) {
  146. idx = STAC946X_MASTER_VOLUME;
  147. id = 0;
  148. } else {
  149. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  150. idx = id + STAC946X_LF_VOLUME;
  151. }
  152. if (id < 6)
  153. vol = stac9460_get(ice, idx) & 0x7f;
  154. else
  155. vol = stac9460_2_get(ice, idx - 6) & 0x7f;
  156. ucontrol->value.integer.value[0] = 0x7f - vol;
  157. return 0;
  158. }
  159. static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
  160. struct snd_ctl_elem_value *ucontrol)
  161. {
  162. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  163. int idx, id;
  164. unsigned char tmp, ovol, nvol;
  165. int change;
  166. if (kcontrol->private_value) {
  167. idx = STAC946X_MASTER_VOLUME;
  168. nvol = ucontrol->value.integer.value[0];
  169. tmp = stac9460_get(ice, idx);
  170. ovol = 0x7f - (tmp & 0x7f);
  171. change = (ovol != nvol);
  172. if (change) {
  173. stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  174. stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  175. }
  176. } else {
  177. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  178. idx = id + STAC946X_LF_VOLUME;
  179. nvol = ucontrol->value.integer.value[0];
  180. if (id < 6)
  181. tmp = stac9460_get(ice, idx);
  182. else
  183. tmp = stac9460_2_get(ice, idx - 6);
  184. ovol = 0x7f - (tmp & 0x7f);
  185. change = (ovol != nvol);
  186. if (change) {
  187. if (id < 6)
  188. stac9460_put(ice, idx, (0x7f - nvol) |
  189. (tmp & 0x80));
  190. else
  191. stac9460_2_put(ice, idx-6, (0x7f - nvol) |
  192. (tmp & 0x80));
  193. }
  194. }
  195. return change;
  196. }
  197. /*
  198. * ADC mute control
  199. */
  200. static int stac9460_adc_mute_info(struct snd_kcontrol *kcontrol,
  201. struct snd_ctl_elem_info *uinfo)
  202. {
  203. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  204. uinfo->count = 2;
  205. uinfo->value.integer.min = 0;
  206. uinfo->value.integer.max = 1;
  207. return 0;
  208. }
  209. static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
  210. struct snd_ctl_elem_value *ucontrol)
  211. {
  212. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  213. unsigned char val;
  214. int i, id;
  215. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  216. if (id == 0) {
  217. for (i = 0; i < 2; ++i) {
  218. val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
  219. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  220. }
  221. } else {
  222. for (i = 0; i < 2; ++i) {
  223. val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i);
  224. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  225. }
  226. }
  227. return 0;
  228. }
  229. static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
  230. struct snd_ctl_elem_value *ucontrol)
  231. {
  232. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  233. unsigned char new, old;
  234. int i, reg, id;
  235. int change;
  236. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  237. if (id == 0) {
  238. for (i = 0; i < 2; ++i) {
  239. reg = STAC946X_MIC_L_VOLUME + i;
  240. old = stac9460_get(ice, reg);
  241. new = (~ucontrol->value.integer.value[i]<<7&0x80) |
  242. (old&~0x80);
  243. change = (new != old);
  244. if (change)
  245. stac9460_put(ice, reg, new);
  246. }
  247. } else {
  248. for (i = 0; i < 2; ++i) {
  249. reg = STAC946X_MIC_L_VOLUME + i;
  250. old = stac9460_2_get(ice, reg);
  251. new = (~ucontrol->value.integer.value[i]<<7&0x80) |
  252. (old&~0x80);
  253. change = (new != old);
  254. if (change)
  255. stac9460_2_put(ice, reg, new);
  256. }
  257. }
  258. return change;
  259. }
  260. /*
  261. *ADC gain mixer control
  262. */
  263. static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
  264. struct snd_ctl_elem_info *uinfo)
  265. {
  266. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  267. uinfo->count = 2;
  268. uinfo->value.integer.min = 0; /* 0dB */
  269. uinfo->value.integer.max = 0x0f; /* 22.5dB */
  270. return 0;
  271. }
  272. static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
  273. struct snd_ctl_elem_value *ucontrol)
  274. {
  275. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  276. int i, reg, id;
  277. unsigned char vol;
  278. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  279. if (id == 0) {
  280. for (i = 0; i < 2; ++i) {
  281. reg = STAC946X_MIC_L_VOLUME + i;
  282. vol = stac9460_get(ice, reg) & 0x0f;
  283. ucontrol->value.integer.value[i] = 0x0f - vol;
  284. }
  285. } else {
  286. for (i = 0; i < 2; ++i) {
  287. reg = STAC946X_MIC_L_VOLUME + i;
  288. vol = stac9460_2_get(ice, reg) & 0x0f;
  289. ucontrol->value.integer.value[i] = 0x0f - vol;
  290. }
  291. }
  292. return 0;
  293. }
  294. static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_value *ucontrol)
  296. {
  297. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  298. int i, reg, id;
  299. unsigned char ovol, nvol;
  300. int change;
  301. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  302. if (id == 0) {
  303. for (i = 0; i < 2; ++i) {
  304. reg = STAC946X_MIC_L_VOLUME + i;
  305. nvol = ucontrol->value.integer.value[i];
  306. ovol = 0x0f - stac9460_get(ice, reg);
  307. change = ((ovol & 0x0f) != nvol);
  308. if (change)
  309. stac9460_put(ice, reg, (0x0f - nvol) |
  310. (ovol & ~0x0f));
  311. }
  312. } else {
  313. for (i = 0; i < 2; ++i) {
  314. reg = STAC946X_MIC_L_VOLUME + i;
  315. nvol = ucontrol->value.integer.value[i];
  316. ovol = 0x0f - stac9460_2_get(ice, reg);
  317. change = ((ovol & 0x0f) != nvol);
  318. if (change)
  319. stac9460_2_put(ice, reg, (0x0f - nvol) |
  320. (ovol & ~0x0f));
  321. }
  322. }
  323. return change;
  324. }
  325. /*
  326. * MIC / LINE switch fonction
  327. */
  328. static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
  329. struct snd_ctl_elem_info *uinfo)
  330. {
  331. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  332. uinfo->count = 1;
  333. uinfo->value.integer.min = 0;
  334. uinfo->value.integer.max = 1;
  335. return 0;
  336. }
  337. static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
  338. struct snd_ctl_elem_value *ucontrol)
  339. {
  340. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  341. unsigned char val;
  342. int id;
  343. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  344. if (id == 0)
  345. val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  346. else
  347. val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
  348. ucontrol->value.integer.value[0] = ~val>>7 & 0x1;
  349. return 0;
  350. }
  351. static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
  352. struct snd_ctl_elem_value *ucontrol)
  353. {
  354. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  355. unsigned char new, old;
  356. int change, id;
  357. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  358. if (id == 0)
  359. old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  360. else
  361. old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
  362. new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80);
  363. change = (new != old);
  364. if (change) {
  365. if (id == 0)
  366. stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
  367. else
  368. stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
  369. }
  370. return change;
  371. }
  372. /*
  373. * Control tabs
  374. */
  375. static const struct snd_kcontrol_new stac9640_controls[] __devinitdata = {
  376. {
  377. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  378. .name = "Master Playback Switch",
  379. .info = stac9460_dac_mute_info,
  380. .get = stac9460_dac_mute_get,
  381. .put = stac9460_dac_mute_put,
  382. .private_value = 1
  383. },
  384. {
  385. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  386. .name = "Master Playback Volume",
  387. .info = stac9460_dac_vol_info,
  388. .get = stac9460_dac_vol_get,
  389. .put = stac9460_dac_vol_put,
  390. .private_value = 1,
  391. },
  392. {
  393. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  394. .name = "MIC/Line switch",
  395. .count = 2,
  396. .info = stac9460_mic_sw_info,
  397. .get = stac9460_mic_sw_get,
  398. .put = stac9460_mic_sw_put,
  399. },
  400. {
  401. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  402. .name = "DAC Switch",
  403. .count = 8,
  404. .info = stac9460_dac_mute_info,
  405. .get = stac9460_dac_mute_get,
  406. .put = stac9460_dac_mute_put,
  407. },
  408. {
  409. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  410. .name = "DAC Volume",
  411. .count = 8,
  412. .info = stac9460_dac_vol_info,
  413. .get = stac9460_dac_vol_get,
  414. .put = stac9460_dac_vol_put,
  415. },
  416. {
  417. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  418. .name = "ADC Switch",
  419. .count = 2,
  420. .info = stac9460_adc_mute_info,
  421. .get = stac9460_adc_mute_get,
  422. .put = stac9460_adc_mute_put,
  423. },
  424. {
  425. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  426. .name = "ADC Volume",
  427. .count = 2,
  428. .info = stac9460_adc_vol_info,
  429. .get = stac9460_adc_vol_get,
  430. .put = stac9460_adc_vol_put,
  431. }
  432. };
  433. /*INIT*/
  434. static int __devinit wtm_add_controls(struct snd_ice1712 *ice)
  435. {
  436. unsigned int i;
  437. int err;
  438. for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) {
  439. err = snd_ctl_add(ice->card,
  440. snd_ctl_new1(&stac9640_controls[i], ice));
  441. if (err < 0)
  442. return err;
  443. }
  444. return 0;
  445. }
  446. static int __devinit wtm_init(struct snd_ice1712 *ice)
  447. {
  448. static unsigned short stac_inits_prodigy[] = {
  449. STAC946X_RESET, 0,
  450. (unsigned short)-1
  451. };
  452. unsigned short *p;
  453. /*WTM 192M*/
  454. ice->num_total_dacs = 8;
  455. ice->num_total_adcs = 4;
  456. ice->force_rdma1 = 1;
  457. /*initialize codec*/
  458. p = stac_inits_prodigy;
  459. for (; *p != (unsigned short)-1; p += 2) {
  460. stac9460_put(ice, p[0], p[1]);
  461. stac9460_2_put(ice, p[0], p[1]);
  462. }
  463. return 0;
  464. }
  465. static unsigned char wtm_eeprom[] __devinitdata = {
  466. 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */
  467. 0x80, /* ACLINK : I2S */
  468. 0xf8, /* I2S: vol; 96k, 24bit, 192k */
  469. 0xc1 /*SPDIF: out-en, spidf ext out*/,
  470. 0x9f, /* GPIO_DIR */
  471. 0xff, /* GPIO_DIR1 */
  472. 0x7f, /* GPIO_DIR2 */
  473. 0x9f, /* GPIO_MASK */
  474. 0xff, /* GPIO_MASK1 */
  475. 0x7f, /* GPIO_MASK2 */
  476. 0x16, /* GPIO_STATE */
  477. 0x80, /* GPIO_STATE1 */
  478. 0x00, /* GPIO_STATE2 */
  479. };
  480. /*entry point*/
  481. struct snd_ice1712_card_info snd_vt1724_wtm_cards[] __devinitdata = {
  482. {
  483. .subvendor = VT1724_SUBDEVICE_WTM,
  484. .name = "ESI Waveterminal 192M",
  485. .model = "WT192M",
  486. .chip_init = wtm_init,
  487. .build_controls = wtm_add_controls,
  488. .eeprom_size = sizeof(wtm_eeprom),
  489. .eeprom_data = wtm_eeprom,
  490. },
  491. {} /*terminator*/
  492. };