wtm.c 12 KB

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