prodigy192.c 13 KB

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