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