wtm.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 <linux/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <sound/core.h>
  31. #include "ice1712.h"
  32. #include "envy24ht.h"
  33. #include "wtm.h"
  34. #include "stac946x.h"
  35. /*
  36. * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
  37. */
  38. static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
  39. unsigned char val)
  40. {
  41. snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
  42. }
  43. static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
  44. {
  45. return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg);
  46. }
  47. /*
  48. * 2*ADC 2*DAC no2 ringbuffer r/w on i2c bus
  49. */
  50. static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg,
  51. unsigned char val)
  52. {
  53. snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val);
  54. }
  55. static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
  56. {
  57. return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg);
  58. }
  59. /*
  60. * DAC mute control
  61. */
  62. #define stac9460_dac_mute_info snd_ctl_boolean_mono_info
  63. static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
  64. struct snd_ctl_elem_value *ucontrol)
  65. {
  66. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  67. unsigned char val;
  68. int idx, id;
  69. if (kcontrol->private_value) {
  70. idx = STAC946X_MASTER_VOLUME;
  71. id = 0;
  72. } else {
  73. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  74. idx = id + STAC946X_LF_VOLUME;
  75. }
  76. if (id < 6)
  77. val = stac9460_get(ice, idx);
  78. else
  79. val = stac9460_2_get(ice, idx - 6);
  80. ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
  81. return 0;
  82. }
  83. static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
  84. struct snd_ctl_elem_value *ucontrol)
  85. {
  86. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  87. unsigned char new, old;
  88. int id, idx;
  89. int change;
  90. if (kcontrol->private_value) {
  91. idx = STAC946X_MASTER_VOLUME;
  92. old = stac9460_get(ice, idx);
  93. new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
  94. (old & ~0x80);
  95. change = (new != old);
  96. if (change) {
  97. stac9460_put(ice, idx, new);
  98. stac9460_2_put(ice, idx, new);
  99. }
  100. } else {
  101. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  102. idx = id + STAC946X_LF_VOLUME;
  103. if (id < 6)
  104. old = stac9460_get(ice, idx);
  105. else
  106. old = stac9460_2_get(ice, idx - 6);
  107. new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
  108. (old & ~0x80);
  109. change = (new != old);
  110. if (change) {
  111. if (id < 6)
  112. stac9460_put(ice, idx, new);
  113. else
  114. stac9460_2_put(ice, idx - 6, new);
  115. }
  116. }
  117. return change;
  118. }
  119. /*
  120. * DAC volume attenuation mixer control
  121. */
  122. static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
  123. struct snd_ctl_elem_info *uinfo)
  124. {
  125. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  126. uinfo->count = 1;
  127. uinfo->value.integer.min = 0; /* mute */
  128. uinfo->value.integer.max = 0x7f; /* 0dB */
  129. return 0;
  130. }
  131. static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
  132. struct snd_ctl_elem_value *ucontrol)
  133. {
  134. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  135. int idx, id;
  136. unsigned char vol;
  137. if (kcontrol->private_value) {
  138. idx = STAC946X_MASTER_VOLUME;
  139. id = 0;
  140. } else {
  141. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  142. idx = id + STAC946X_LF_VOLUME;
  143. }
  144. if (id < 6)
  145. vol = stac9460_get(ice, idx) & 0x7f;
  146. else
  147. vol = stac9460_2_get(ice, idx - 6) & 0x7f;
  148. ucontrol->value.integer.value[0] = 0x7f - vol;
  149. return 0;
  150. }
  151. static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
  152. struct snd_ctl_elem_value *ucontrol)
  153. {
  154. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  155. int idx, id;
  156. unsigned char tmp, ovol, nvol;
  157. int change;
  158. if (kcontrol->private_value) {
  159. idx = STAC946X_MASTER_VOLUME;
  160. nvol = ucontrol->value.integer.value[0] & 0x7f;
  161. tmp = stac9460_get(ice, idx);
  162. ovol = 0x7f - (tmp & 0x7f);
  163. change = (ovol != nvol);
  164. if (change) {
  165. stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  166. stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  167. }
  168. } else {
  169. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  170. idx = id + STAC946X_LF_VOLUME;
  171. nvol = ucontrol->value.integer.value[0] & 0x7f;
  172. if (id < 6)
  173. tmp = stac9460_get(ice, idx);
  174. else
  175. tmp = stac9460_2_get(ice, idx - 6);
  176. ovol = 0x7f - (tmp & 0x7f);
  177. change = (ovol != nvol);
  178. if (change) {
  179. if (id < 6)
  180. stac9460_put(ice, idx, (0x7f - nvol) |
  181. (tmp & 0x80));
  182. else
  183. stac9460_2_put(ice, idx-6, (0x7f - nvol) |
  184. (tmp & 0x80));
  185. }
  186. }
  187. return change;
  188. }
  189. /*
  190. * ADC mute control
  191. */
  192. #define stac9460_adc_mute_info snd_ctl_boolean_stereo_info
  193. static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
  194. struct snd_ctl_elem_value *ucontrol)
  195. {
  196. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  197. unsigned char val;
  198. int i, id;
  199. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  200. if (id == 0) {
  201. for (i = 0; i < 2; ++i) {
  202. val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
  203. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  204. }
  205. } else {
  206. for (i = 0; i < 2; ++i) {
  207. val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i);
  208. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  209. }
  210. }
  211. return 0;
  212. }
  213. static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
  214. struct snd_ctl_elem_value *ucontrol)
  215. {
  216. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  217. unsigned char new, old;
  218. int i, reg, id;
  219. int change;
  220. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  221. if (id == 0) {
  222. for (i = 0; i < 2; ++i) {
  223. reg = STAC946X_MIC_L_VOLUME + i;
  224. old = stac9460_get(ice, reg);
  225. new = (~ucontrol->value.integer.value[i]<<7&0x80) |
  226. (old&~0x80);
  227. change = (new != old);
  228. if (change)
  229. stac9460_put(ice, reg, new);
  230. }
  231. } else {
  232. for (i = 0; i < 2; ++i) {
  233. reg = STAC946X_MIC_L_VOLUME + i;
  234. old = stac9460_2_get(ice, reg);
  235. new = (~ucontrol->value.integer.value[i]<<7&0x80) |
  236. (old&~0x80);
  237. change = (new != old);
  238. if (change)
  239. stac9460_2_put(ice, reg, new);
  240. }
  241. }
  242. return change;
  243. }
  244. /*
  245. *ADC gain mixer control
  246. */
  247. static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
  248. struct snd_ctl_elem_info *uinfo)
  249. {
  250. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  251. uinfo->count = 2;
  252. uinfo->value.integer.min = 0; /* 0dB */
  253. uinfo->value.integer.max = 0x0f; /* 22.5dB */
  254. return 0;
  255. }
  256. static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
  257. struct snd_ctl_elem_value *ucontrol)
  258. {
  259. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  260. int i, reg, id;
  261. unsigned char vol;
  262. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  263. if (id == 0) {
  264. for (i = 0; i < 2; ++i) {
  265. reg = STAC946X_MIC_L_VOLUME + i;
  266. vol = stac9460_get(ice, reg) & 0x0f;
  267. ucontrol->value.integer.value[i] = 0x0f - vol;
  268. }
  269. } else {
  270. for (i = 0; i < 2; ++i) {
  271. reg = STAC946X_MIC_L_VOLUME + i;
  272. vol = stac9460_2_get(ice, reg) & 0x0f;
  273. ucontrol->value.integer.value[i] = 0x0f - vol;
  274. }
  275. }
  276. return 0;
  277. }
  278. static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
  279. struct snd_ctl_elem_value *ucontrol)
  280. {
  281. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  282. int i, reg, id;
  283. unsigned char ovol, nvol;
  284. int change;
  285. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  286. if (id == 0) {
  287. for (i = 0; i < 2; ++i) {
  288. reg = STAC946X_MIC_L_VOLUME + i;
  289. nvol = ucontrol->value.integer.value[i] & 0x0f;
  290. ovol = 0x0f - stac9460_get(ice, reg);
  291. change = ((ovol & 0x0f) != nvol);
  292. if (change)
  293. stac9460_put(ice, reg, (0x0f - nvol) |
  294. (ovol & ~0x0f));
  295. }
  296. } else {
  297. for (i = 0; i < 2; ++i) {
  298. reg = STAC946X_MIC_L_VOLUME + i;
  299. nvol = ucontrol->value.integer.value[i] & 0x0f;
  300. ovol = 0x0f - stac9460_2_get(ice, reg);
  301. change = ((ovol & 0x0f) != nvol);
  302. if (change)
  303. stac9460_2_put(ice, reg, (0x0f - nvol) |
  304. (ovol & ~0x0f));
  305. }
  306. }
  307. return change;
  308. }
  309. /*
  310. * MIC / LINE switch fonction
  311. */
  312. #define stac9460_mic_sw_info snd_ctl_boolean_mono_info
  313. static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
  314. struct snd_ctl_elem_value *ucontrol)
  315. {
  316. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  317. unsigned char val;
  318. int id;
  319. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  320. if (id == 0)
  321. val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  322. else
  323. val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
  324. ucontrol->value.integer.value[0] = ~val>>7 & 0x1;
  325. return 0;
  326. }
  327. static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
  328. struct snd_ctl_elem_value *ucontrol)
  329. {
  330. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  331. unsigned char new, old;
  332. int change, id;
  333. id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  334. if (id == 0)
  335. old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  336. else
  337. old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
  338. new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | (old & ~0x80);
  339. change = (new != old);
  340. if (change) {
  341. if (id == 0)
  342. stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
  343. else
  344. stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
  345. }
  346. return change;
  347. }
  348. /*
  349. * Control tabs
  350. */
  351. static struct snd_kcontrol_new stac9640_controls[] __devinitdata = {
  352. {
  353. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  354. .name = "Master Playback Switch",
  355. .info = stac9460_dac_mute_info,
  356. .get = stac9460_dac_mute_get,
  357. .put = stac9460_dac_mute_put,
  358. .private_value = 1
  359. },
  360. {
  361. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  362. .name = "Master Playback Volume",
  363. .info = stac9460_dac_vol_info,
  364. .get = stac9460_dac_vol_get,
  365. .put = stac9460_dac_vol_put,
  366. .private_value = 1,
  367. },
  368. {
  369. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  370. .name = "MIC/Line switch",
  371. .count = 2,
  372. .info = stac9460_mic_sw_info,
  373. .get = stac9460_mic_sw_get,
  374. .put = stac9460_mic_sw_put,
  375. },
  376. {
  377. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  378. .name = "DAC Switch",
  379. .count = 8,
  380. .info = stac9460_dac_mute_info,
  381. .get = stac9460_dac_mute_get,
  382. .put = stac9460_dac_mute_put,
  383. },
  384. {
  385. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  386. .name = "DAC Volume",
  387. .count = 8,
  388. .info = stac9460_dac_vol_info,
  389. .get = stac9460_dac_vol_get,
  390. .put = stac9460_dac_vol_put,
  391. },
  392. {
  393. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  394. .name = "ADC Switch",
  395. .count = 2,
  396. .info = stac9460_adc_mute_info,
  397. .get = stac9460_adc_mute_get,
  398. .put = stac9460_adc_mute_put,
  399. },
  400. {
  401. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  402. .name = "ADC Volume",
  403. .count = 2,
  404. .info = stac9460_adc_vol_info,
  405. .get = stac9460_adc_vol_get,
  406. .put = stac9460_adc_vol_put,
  407. }
  408. };
  409. /*INIT*/
  410. static int __devinit wtm_add_controls(struct snd_ice1712 *ice)
  411. {
  412. unsigned int i;
  413. int err;
  414. for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) {
  415. err = snd_ctl_add(ice->card,
  416. snd_ctl_new1(&stac9640_controls[i], ice));
  417. if (err < 0)
  418. return err;
  419. }
  420. return 0;
  421. }
  422. static int __devinit wtm_init(struct snd_ice1712 *ice)
  423. {
  424. static unsigned short stac_inits_prodigy[] = {
  425. STAC946X_RESET, 0,
  426. (unsigned short)-1
  427. };
  428. unsigned short *p;
  429. /*WTM 192M*/
  430. ice->num_total_dacs = 8;
  431. ice->num_total_adcs = 4;
  432. ice->force_rdma1 = 1;
  433. /*initialize codec*/
  434. p = stac_inits_prodigy;
  435. for (; *p != (unsigned short)-1; p += 2) {
  436. stac9460_put(ice, p[0], p[1]);
  437. stac9460_2_put(ice, p[0], p[1]);
  438. }
  439. return 0;
  440. }
  441. static unsigned char wtm_eeprom[] __devinitdata = {
  442. 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */
  443. 0x80, /* ACLINK : I2S */
  444. 0xf8, /* I2S: vol; 96k, 24bit, 192k */
  445. 0xc1 /*SPDIF: out-en, spidf ext out*/,
  446. 0x9f, /* GPIO_DIR */
  447. 0xff, /* GPIO_DIR1 */
  448. 0x7f, /* GPIO_DIR2 */
  449. 0x9f, /* GPIO_MASK */
  450. 0xff, /* GPIO_MASK1 */
  451. 0x7f, /* GPIO_MASK2 */
  452. 0x16, /* GPIO_STATE */
  453. 0x80, /* GPIO_STATE1 */
  454. 0x00, /* GPIO_STATE2 */
  455. };
  456. /*entry point*/
  457. struct snd_ice1712_card_info snd_vt1724_wtm_cards[] __devinitdata = {
  458. {
  459. .subvendor = VT1724_SUBDEVICE_WTM,
  460. .name = "ESI Waveterminal 192M",
  461. .model = "WT192M",
  462. .chip_init = wtm_init,
  463. .build_controls = wtm_add_controls,
  464. .eeprom_size = sizeof(wtm_eeprom),
  465. .eeprom_data = wtm_eeprom,
  466. },
  467. {} /*terminator*/
  468. };