prodigy192.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for AudioTrak Prodigy 192 cards
  5. *
  6. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  7. * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
  8. * Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp>
  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 "prodigy192.h"
  35. #include "stac946x.h"
  36. static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val)
  37. {
  38. snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);
  39. }
  40. static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
  41. {
  42. return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);
  43. }
  44. /*
  45. * DAC mute control
  46. */
  47. static int stac9460_dac_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  48. {
  49. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  50. uinfo->count = 1;
  51. uinfo->value.integer.min = 0;
  52. uinfo->value.integer.max = 1;
  53. return 0;
  54. }
  55. static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  56. {
  57. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  58. unsigned char val;
  59. int idx;
  60. if (kcontrol->private_value)
  61. idx = STAC946X_MASTER_VOLUME;
  62. else
  63. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  64. val = stac9460_get(ice, idx);
  65. ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
  66. return 0;
  67. }
  68. static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  69. {
  70. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  71. unsigned char new, old;
  72. int idx;
  73. int change;
  74. if (kcontrol->private_value)
  75. idx = STAC946X_MASTER_VOLUME;
  76. else
  77. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  78. old = stac9460_get(ice, idx);
  79. new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80);
  80. change = (new != old);
  81. if (change)
  82. stac9460_put(ice, idx, new);
  83. return change;
  84. }
  85. /*
  86. * DAC volume attenuation mixer control
  87. */
  88. static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  89. {
  90. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  91. uinfo->count = 1;
  92. uinfo->value.integer.min = 0; /* mute */
  93. uinfo->value.integer.max = 0x7f; /* 0dB */
  94. return 0;
  95. }
  96. static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  97. {
  98. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  99. int idx;
  100. unsigned char vol;
  101. if (kcontrol->private_value)
  102. idx = STAC946X_MASTER_VOLUME;
  103. else
  104. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  105. vol = stac9460_get(ice, idx) & 0x7f;
  106. ucontrol->value.integer.value[0] = 0x7f - vol;
  107. return 0;
  108. }
  109. static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  110. {
  111. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  112. int idx;
  113. unsigned char tmp, ovol, nvol;
  114. int change;
  115. if (kcontrol->private_value)
  116. idx = STAC946X_MASTER_VOLUME;
  117. else
  118. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  119. nvol = ucontrol->value.integer.value[0];
  120. tmp = stac9460_get(ice, idx);
  121. ovol = 0x7f - (tmp & 0x7f);
  122. change = (ovol != nvol);
  123. if (change) {
  124. stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  125. }
  126. return change;
  127. }
  128. /*
  129. * ADC mute control
  130. */
  131. static int stac9460_adc_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  132. {
  133. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  134. uinfo->count = 2;
  135. uinfo->value.integer.min = 0;
  136. uinfo->value.integer.max = 1;
  137. return 0;
  138. }
  139. static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  140. {
  141. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  142. unsigned char val;
  143. int i;
  144. for (i = 0; i < 2; ++i) {
  145. val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
  146. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  147. }
  148. return 0;
  149. }
  150. static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  151. {
  152. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  153. unsigned char new, old;
  154. int i, reg;
  155. int change;
  156. for (i = 0; i < 2; ++i) {
  157. reg = STAC946X_MIC_L_VOLUME + i;
  158. old = stac9460_get(ice, reg);
  159. new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80);
  160. change = (new != old);
  161. if (change)
  162. stac9460_put(ice, reg, new);
  163. }
  164. return change;
  165. }
  166. /*
  167. * ADC gain mixer control
  168. */
  169. static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  170. {
  171. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  172. uinfo->count = 2;
  173. uinfo->value.integer.min = 0; /* 0dB */
  174. uinfo->value.integer.max = 0x0f; /* 22.5dB */
  175. return 0;
  176. }
  177. static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  178. {
  179. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  180. int i, reg;
  181. unsigned char vol;
  182. for (i = 0; i < 2; ++i) {
  183. reg = STAC946X_MIC_L_VOLUME + i;
  184. vol = stac9460_get(ice, reg) & 0x0f;
  185. ucontrol->value.integer.value[i] = 0x0f - vol;
  186. }
  187. return 0;
  188. }
  189. static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  190. {
  191. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  192. int i, reg;
  193. unsigned char ovol, nvol;
  194. int change;
  195. for (i = 0; i < 2; ++i) {
  196. reg = STAC946X_MIC_L_VOLUME + i;
  197. nvol = ucontrol->value.integer.value[i];
  198. ovol = 0x0f - stac9460_get(ice, reg);
  199. change = ((ovol & 0x0f) != nvol);
  200. if (change)
  201. stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f));
  202. }
  203. return change;
  204. }
  205. #if 0
  206. /*
  207. * Headphone Amplifier
  208. */
  209. static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable)
  210. {
  211. unsigned int tmp, tmp2;
  212. tmp2 = tmp = snd_ice1712_gpio_read(ice);
  213. if (enable)
  214. tmp |= AUREON_HP_SEL;
  215. else
  216. tmp &= ~ AUREON_HP_SEL;
  217. if (tmp != tmp2) {
  218. snd_ice1712_gpio_write(ice, tmp);
  219. return 1;
  220. }
  221. return 0;
  222. }
  223. static int aureon_get_headphone_amp(struct snd_ice1712 *ice)
  224. {
  225. unsigned int tmp = snd_ice1712_gpio_read(ice);
  226. return ( tmp & AUREON_HP_SEL )!= 0;
  227. }
  228. static int aureon_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  229. {
  230. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  231. uinfo->count = 1;
  232. uinfo->value.integer.min = 0;
  233. uinfo->value.integer.max = 1;
  234. return 0;
  235. }
  236. static int aureon_hpamp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  237. {
  238. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  239. ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);
  240. return 0;
  241. }
  242. static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  243. {
  244. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  245. return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]);
  246. }
  247. /*
  248. * Deemphasis
  249. */
  250. static int aureon_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  251. {
  252. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  253. ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
  254. return 0;
  255. }
  256. static int aureon_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  257. {
  258. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  259. int temp, temp2;
  260. temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
  261. if (ucontrol->value.integer.value[0])
  262. temp |= 0xf;
  263. else
  264. temp &= ~0xf;
  265. if (temp != temp2) {
  266. wm_put(ice, WM_DAC_CTRL2, temp);
  267. return 1;
  268. }
  269. return 0;
  270. }
  271. /*
  272. * ADC Oversampling
  273. */
  274. static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  275. {
  276. static char *texts[2] = { "128x", "64x" };
  277. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  278. uinfo->count = 1;
  279. uinfo->value.enumerated.items = 2;
  280. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  281. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  282. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  283. return 0;
  284. }
  285. static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  286. {
  287. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  288. ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
  289. return 0;
  290. }
  291. static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  292. {
  293. int temp, temp2;
  294. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  295. temp2 = temp = wm_get(ice, WM_MASTER);
  296. if (ucontrol->value.enumerated.item[0])
  297. temp |= 0x8;
  298. else
  299. temp &= ~0x8;
  300. if (temp != temp2) {
  301. wm_put(ice, WM_MASTER, temp);
  302. return 1;
  303. }
  304. return 0;
  305. }
  306. #endif
  307. /*
  308. * mixers
  309. */
  310. static struct snd_kcontrol_new stac_controls[] __devinitdata = {
  311. {
  312. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  313. .name = "Master Playback Switch",
  314. .info = stac9460_dac_mute_info,
  315. .get = stac9460_dac_mute_get,
  316. .put = stac9460_dac_mute_put,
  317. .private_value = 1,
  318. },
  319. {
  320. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  321. .name = "Master Playback Volume",
  322. .info = stac9460_dac_vol_info,
  323. .get = stac9460_dac_vol_get,
  324. .put = stac9460_dac_vol_put,
  325. .private_value = 1,
  326. },
  327. {
  328. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  329. .name = "DAC Switch",
  330. .count = 6,
  331. .info = stac9460_dac_mute_info,
  332. .get = stac9460_dac_mute_get,
  333. .put = stac9460_dac_mute_put,
  334. },
  335. {
  336. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  337. .name = "DAC Volume",
  338. .count = 6,
  339. .info = stac9460_dac_vol_info,
  340. .get = stac9460_dac_vol_get,
  341. .put = stac9460_dac_vol_put,
  342. },
  343. {
  344. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  345. .name = "ADC Switch",
  346. .count = 1,
  347. .info = stac9460_adc_mute_info,
  348. .get = stac9460_adc_mute_get,
  349. .put = stac9460_adc_mute_put,
  350. },
  351. {
  352. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  353. .name = "ADC Volume",
  354. .count = 1,
  355. .info = stac9460_adc_vol_info,
  356. .get = stac9460_adc_vol_get,
  357. .put = stac9460_adc_vol_put,
  358. },
  359. #if 0
  360. {
  361. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  362. .name = "Capture Route",
  363. .info = wm_adc_mux_info,
  364. .get = wm_adc_mux_get,
  365. .put = wm_adc_mux_put,
  366. },
  367. {
  368. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  369. .name = "Headphone Amplifier Switch",
  370. .info = aureon_bool_info,
  371. .get = aureon_hpamp_get,
  372. .put = aureon_hpamp_put
  373. },
  374. {
  375. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  376. .name = "DAC Deemphasis Switch",
  377. .info = aureon_bool_info,
  378. .get = aureon_deemp_get,
  379. .put = aureon_deemp_put
  380. },
  381. {
  382. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  383. .name = "ADC Oversampling",
  384. .info = aureon_oversampling_info,
  385. .get = aureon_oversampling_get,
  386. .put = aureon_oversampling_put
  387. },
  388. #endif
  389. };
  390. static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice)
  391. {
  392. unsigned int i;
  393. int err;
  394. for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
  395. err = snd_ctl_add(ice->card, snd_ctl_new1(&stac_controls[i], ice));
  396. if (err < 0)
  397. return err;
  398. }
  399. return 0;
  400. }
  401. /*
  402. * initialize the chip
  403. */
  404. static int __devinit prodigy192_init(struct snd_ice1712 *ice)
  405. {
  406. static unsigned short stac_inits_prodigy[] = {
  407. STAC946X_RESET, 0,
  408. /* STAC946X_MASTER_VOLUME, 0,
  409. STAC946X_LF_VOLUME, 0,
  410. STAC946X_RF_VOLUME, 0,
  411. STAC946X_LR_VOLUME, 0,
  412. STAC946X_RR_VOLUME, 0,
  413. STAC946X_CENTER_VOLUME, 0,
  414. STAC946X_LFE_VOLUME, 0,*/
  415. (unsigned short)-1
  416. };
  417. unsigned short *p;
  418. /* prodigy 192 */
  419. ice->num_total_dacs = 6;
  420. ice->num_total_adcs = 2;
  421. /* initialize codec */
  422. p = stac_inits_prodigy;
  423. for (; *p != (unsigned short)-1; p += 2)
  424. stac9460_put(ice, p[0], p[1]);
  425. return 0;
  426. }
  427. /*
  428. * Aureon boards don't provide the EEPROM data except for the vendor IDs.
  429. * hence the driver needs to sets up it properly.
  430. */
  431. static unsigned char prodigy71_eeprom[] __devinitdata = {
  432. 0x2b, /* SYSCONF: clock 512, mpu401, spdif-in/ADC, 4DACs */
  433. 0x80, /* ACLINK: I2S */
  434. 0xf8, /* I2S: vol, 96k, 24bit, 192k */
  435. 0xc3, /* SPDIF: out-en, out-int, spdif-in */
  436. 0xff, /* GPIO_DIR */
  437. 0xff, /* GPIO_DIR1 */
  438. 0xbf, /* GPIO_DIR2 */
  439. 0x00, /* GPIO_MASK */
  440. 0x00, /* GPIO_MASK1 */
  441. 0x00, /* GPIO_MASK2 */
  442. 0x00, /* GPIO_STATE */
  443. 0x00, /* GPIO_STATE1 */
  444. 0x00, /* GPIO_STATE2 */
  445. };
  446. /* entry point */
  447. struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
  448. {
  449. .subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
  450. .name = "Audiotrak Prodigy 192",
  451. .model = "prodigy192",
  452. .chip_init = prodigy192_init,
  453. .build_controls = prodigy192_add_controls,
  454. .eeprom_size = sizeof(prodigy71_eeprom),
  455. .eeprom_data = prodigy71_eeprom,
  456. },
  457. { } /* terminator */
  458. };