prodigy192.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for AudioTrak Prodigy 192 cards
  5. * Supported IEC958 input from optional MI/ODI/O add-on card.
  6. *
  7. * Specifics (SW, HW):
  8. * -------------------
  9. * * 49.5MHz crystal
  10. * * SPDIF-OUT on the card:
  11. * - coax (through isolation transformer)/toslink supplied by
  12. * 74HC04 gates - 3 in parallel
  13. * - output switched between on-board CD drive dig-out connector
  14. * and ice1724 SPDTX pin, using 74HC02 NOR gates, controlled
  15. * by GPIO20 (0 = CD dig-out, 1 = SPDTX)
  16. * * SPDTX goes straight to MI/ODI/O card's SPDIF-OUT coax
  17. *
  18. * * MI/ODI/O card: AK4114 based, used for iec958 input only
  19. * - toslink input -> RX0
  20. * - coax input -> RX1
  21. * - 4wire protocol:
  22. * AK4114 ICE1724
  23. * ------------------------------
  24. * CDTO (pin 32) -- GPIO11 pin 86
  25. * CDTI (pin 33) -- GPIO10 pin 77
  26. * CCLK (pin 34) -- GPIO9 pin 76
  27. * CSN (pin 35) -- GPIO8 pin 75
  28. * - output data Mode 7 (24bit, I2S, slave)
  29. *
  30. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  31. * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
  32. * Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp>
  33. *
  34. * This program is free software; you can redistribute it and/or modify
  35. * it under the terms of the GNU General Public License as published by
  36. * the Free Software Foundation; either version 2 of the License, or
  37. * (at your option) any later version.
  38. *
  39. * This program is distributed in the hope that it will be useful,
  40. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  42. * GNU General Public License for more details.
  43. *
  44. * You should have received a copy of the GNU General Public License
  45. * along with this program; if not, write to the Free Software
  46. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  47. *
  48. */
  49. #include <sound/driver.h>
  50. #include <asm/io.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/init.h>
  54. #include <linux/slab.h>
  55. #include <sound/core.h>
  56. #include "ice1712.h"
  57. #include "envy24ht.h"
  58. #include "prodigy192.h"
  59. #include "stac946x.h"
  60. #include <sound/tlv.h>
  61. static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val)
  62. {
  63. snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);
  64. }
  65. static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
  66. {
  67. return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);
  68. }
  69. /*
  70. * DAC mute control
  71. */
  72. static int stac9460_dac_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  73. {
  74. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  75. uinfo->count = 1;
  76. uinfo->value.integer.min = 0;
  77. uinfo->value.integer.max = 1;
  78. return 0;
  79. }
  80. static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  81. {
  82. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  83. unsigned char val;
  84. int idx;
  85. if (kcontrol->private_value)
  86. idx = STAC946X_MASTER_VOLUME;
  87. else
  88. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  89. val = stac9460_get(ice, idx);
  90. ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
  91. return 0;
  92. }
  93. static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  94. {
  95. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  96. unsigned char new, old;
  97. int idx;
  98. int change;
  99. if (kcontrol->private_value)
  100. idx = STAC946X_MASTER_VOLUME;
  101. else
  102. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  103. old = stac9460_get(ice, idx);
  104. new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80);
  105. change = (new != old);
  106. if (change)
  107. stac9460_put(ice, idx, new);
  108. return change;
  109. }
  110. /*
  111. * DAC volume attenuation mixer control
  112. */
  113. static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  114. {
  115. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  116. uinfo->count = 1;
  117. uinfo->value.integer.min = 0; /* mute */
  118. uinfo->value.integer.max = 0x7f; /* 0dB */
  119. return 0;
  120. }
  121. static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  122. {
  123. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  124. int idx;
  125. unsigned char vol;
  126. if (kcontrol->private_value)
  127. idx = STAC946X_MASTER_VOLUME;
  128. else
  129. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  130. vol = stac9460_get(ice, idx) & 0x7f;
  131. ucontrol->value.integer.value[0] = 0x7f - vol;
  132. return 0;
  133. }
  134. static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  135. {
  136. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  137. int idx;
  138. unsigned char tmp, ovol, nvol;
  139. int change;
  140. if (kcontrol->private_value)
  141. idx = STAC946X_MASTER_VOLUME;
  142. else
  143. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  144. nvol = ucontrol->value.integer.value[0];
  145. tmp = stac9460_get(ice, idx);
  146. ovol = 0x7f - (tmp & 0x7f);
  147. change = (ovol != nvol);
  148. if (change) {
  149. stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  150. }
  151. return change;
  152. }
  153. /*
  154. * ADC mute control
  155. */
  156. static int stac9460_adc_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  157. {
  158. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  159. uinfo->count = 2;
  160. uinfo->value.integer.min = 0;
  161. uinfo->value.integer.max = 1;
  162. return 0;
  163. }
  164. static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  165. {
  166. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  167. unsigned char val;
  168. int i;
  169. for (i = 0; i < 2; ++i) {
  170. val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
  171. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  172. }
  173. return 0;
  174. }
  175. static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  176. {
  177. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  178. unsigned char new, old;
  179. int i, reg;
  180. int change;
  181. for (i = 0; i < 2; ++i) {
  182. reg = STAC946X_MIC_L_VOLUME + i;
  183. old = stac9460_get(ice, reg);
  184. new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80);
  185. change = (new != old);
  186. if (change)
  187. stac9460_put(ice, reg, new);
  188. }
  189. return change;
  190. }
  191. /*
  192. * ADC gain mixer control
  193. */
  194. static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  195. {
  196. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  197. uinfo->count = 2;
  198. uinfo->value.integer.min = 0; /* 0dB */
  199. uinfo->value.integer.max = 0x0f; /* 22.5dB */
  200. return 0;
  201. }
  202. static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  203. {
  204. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  205. int i, reg;
  206. unsigned char vol;
  207. for (i = 0; i < 2; ++i) {
  208. reg = STAC946X_MIC_L_VOLUME + i;
  209. vol = stac9460_get(ice, reg) & 0x0f;
  210. ucontrol->value.integer.value[i] = 0x0f - vol;
  211. }
  212. return 0;
  213. }
  214. static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  215. {
  216. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  217. int i, reg;
  218. unsigned char ovol, nvol;
  219. int change;
  220. for (i = 0; i < 2; ++i) {
  221. reg = STAC946X_MIC_L_VOLUME + i;
  222. nvol = ucontrol->value.integer.value[i];
  223. ovol = 0x0f - stac9460_get(ice, reg);
  224. change = ((ovol & 0x0f) != nvol);
  225. if (change)
  226. stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f));
  227. }
  228. return change;
  229. }
  230. #if 0
  231. /*
  232. * Headphone Amplifier
  233. */
  234. static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable)
  235. {
  236. unsigned int tmp, tmp2;
  237. tmp2 = tmp = snd_ice1712_gpio_read(ice);
  238. if (enable)
  239. tmp |= AUREON_HP_SEL;
  240. else
  241. tmp &= ~ AUREON_HP_SEL;
  242. if (tmp != tmp2) {
  243. snd_ice1712_gpio_write(ice, tmp);
  244. return 1;
  245. }
  246. return 0;
  247. }
  248. static int aureon_get_headphone_amp(struct snd_ice1712 *ice)
  249. {
  250. unsigned int tmp = snd_ice1712_gpio_read(ice);
  251. return ( tmp & AUREON_HP_SEL )!= 0;
  252. }
  253. static int aureon_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  254. {
  255. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  256. uinfo->count = 1;
  257. uinfo->value.integer.min = 0;
  258. uinfo->value.integer.max = 1;
  259. return 0;
  260. }
  261. static int aureon_hpamp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  262. {
  263. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  264. ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);
  265. return 0;
  266. }
  267. static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  268. {
  269. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  270. return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]);
  271. }
  272. /*
  273. * Deemphasis
  274. */
  275. static int aureon_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  276. {
  277. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  278. ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
  279. return 0;
  280. }
  281. static int aureon_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  282. {
  283. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  284. int temp, temp2;
  285. temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
  286. if (ucontrol->value.integer.value[0])
  287. temp |= 0xf;
  288. else
  289. temp &= ~0xf;
  290. if (temp != temp2) {
  291. wm_put(ice, WM_DAC_CTRL2, temp);
  292. return 1;
  293. }
  294. return 0;
  295. }
  296. /*
  297. * ADC Oversampling
  298. */
  299. static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
  300. {
  301. static char *texts[2] = { "128x", "64x" };
  302. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  303. uinfo->count = 1;
  304. uinfo->value.enumerated.items = 2;
  305. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  306. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  307. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  308. return 0;
  309. }
  310. static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  311. {
  312. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  313. ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
  314. return 0;
  315. }
  316. static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  317. {
  318. int temp, temp2;
  319. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  320. temp2 = temp = wm_get(ice, WM_MASTER);
  321. if (ucontrol->value.enumerated.item[0])
  322. temp |= 0x8;
  323. else
  324. temp &= ~0x8;
  325. if (temp != temp2) {
  326. wm_put(ice, WM_MASTER, temp);
  327. return 1;
  328. }
  329. return 0;
  330. }
  331. #endif
  332. static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
  333. struct snd_ctl_elem_info *uinfo)
  334. {
  335. static char *texts[2] = { "Line In", "Mic" };
  336. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  337. uinfo->count = 1;
  338. uinfo->value.enumerated.items = 2;
  339. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  340. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  341. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  342. return 0;
  343. }
  344. static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
  345. struct snd_ctl_elem_value *ucontrol)
  346. {
  347. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  348. unsigned char val;
  349. val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  350. ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
  351. return 0;
  352. }
  353. static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
  354. struct snd_ctl_elem_value *ucontrol)
  355. {
  356. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  357. unsigned char new, old;
  358. int change;
  359. old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  360. new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
  361. change = (new != old);
  362. if (change)
  363. stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
  364. return change;
  365. }
  366. static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
  367. static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
  368. /*
  369. * mixers
  370. */
  371. static struct snd_kcontrol_new stac_controls[] __devinitdata = {
  372. {
  373. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  374. .name = "Master Playback Switch",
  375. .info = stac9460_dac_mute_info,
  376. .get = stac9460_dac_mute_get,
  377. .put = stac9460_dac_mute_put,
  378. .private_value = 1,
  379. .tlv = { .p = db_scale_dac }
  380. },
  381. {
  382. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  383. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  384. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  385. .name = "Master Playback Volume",
  386. .info = stac9460_dac_vol_info,
  387. .get = stac9460_dac_vol_get,
  388. .put = stac9460_dac_vol_put,
  389. .private_value = 1,
  390. .tlv = { .p = db_scale_dac }
  391. },
  392. {
  393. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  394. .name = "DAC Switch",
  395. .count = 6,
  396. .info = stac9460_dac_mute_info,
  397. .get = stac9460_dac_mute_get,
  398. .put = stac9460_dac_mute_put,
  399. },
  400. {
  401. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  402. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  403. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  404. .name = "DAC Volume",
  405. .count = 6,
  406. .info = stac9460_dac_vol_info,
  407. .get = stac9460_dac_vol_get,
  408. .put = stac9460_dac_vol_put,
  409. .tlv = { .p = db_scale_dac }
  410. },
  411. {
  412. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  413. .name = "ADC Capture Switch",
  414. .count = 1,
  415. .info = stac9460_adc_mute_info,
  416. .get = stac9460_adc_mute_get,
  417. .put = stac9460_adc_mute_put,
  418. },
  419. {
  420. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  421. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  422. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  423. .name = "ADC Capture Volume",
  424. .count = 1,
  425. .info = stac9460_adc_vol_info,
  426. .get = stac9460_adc_vol_get,
  427. .put = stac9460_adc_vol_put,
  428. .tlv = { .p = db_scale_adc }
  429. },
  430. {
  431. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  432. .name = "Analog Capture Input",
  433. .info = stac9460_mic_sw_info,
  434. .get = stac9460_mic_sw_get,
  435. .put = stac9460_mic_sw_put,
  436. },
  437. #if 0
  438. {
  439. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  440. .name = "Capture Route",
  441. .info = wm_adc_mux_info,
  442. .get = wm_adc_mux_get,
  443. .put = wm_adc_mux_put,
  444. },
  445. {
  446. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  447. .name = "Headphone Amplifier Switch",
  448. .info = aureon_bool_info,
  449. .get = aureon_hpamp_get,
  450. .put = aureon_hpamp_put
  451. },
  452. {
  453. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  454. .name = "DAC Deemphasis Switch",
  455. .info = aureon_bool_info,
  456. .get = aureon_deemp_get,
  457. .put = aureon_deemp_put
  458. },
  459. {
  460. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  461. .name = "ADC Oversampling",
  462. .info = aureon_oversampling_info,
  463. .get = aureon_oversampling_get,
  464. .put = aureon_oversampling_put
  465. },
  466. #endif
  467. };
  468. /* AK4114 - ICE1724 connections on Prodigy192 + MI/ODI/O */
  469. /* CDTO (pin 32) -- GPIO11 pin 86
  470. * CDTI (pin 33) -- GPIO10 pin 77
  471. * CCLK (pin 34) -- GPIO9 pin 76
  472. * CSN (pin 35) -- GPIO8 pin 75
  473. */
  474. #define AK4114_ADDR 0x00 /* C1-C0: Chip Address
  475. * (According to datasheet fixed to “00”)
  476. */
  477. /*
  478. * 4wire ak4114 protocol - writing data
  479. */
  480. static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
  481. unsigned int data, int idx)
  482. {
  483. for (; idx >= 0; idx--) {
  484. /* drop clock */
  485. gpio &= ~VT1724_PRODIGY192_CCLK;
  486. snd_ice1712_gpio_write(ice, gpio);
  487. udelay(1);
  488. /* set data */
  489. if (data & (1 << idx))
  490. gpio |= VT1724_PRODIGY192_CDOUT;
  491. else
  492. gpio &= ~VT1724_PRODIGY192_CDOUT;
  493. snd_ice1712_gpio_write(ice, gpio);
  494. udelay(1);
  495. /* raise clock */
  496. gpio |= VT1724_PRODIGY192_CCLK;
  497. snd_ice1712_gpio_write(ice, gpio);
  498. udelay(1);
  499. }
  500. }
  501. /*
  502. * 4wire ak4114 protocol - reading data
  503. */
  504. static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
  505. int idx)
  506. {
  507. unsigned char data = 0;
  508. for (; idx >= 0; idx--) {
  509. /* drop clock */
  510. gpio &= ~VT1724_PRODIGY192_CCLK;
  511. snd_ice1712_gpio_write(ice, gpio);
  512. udelay(1);
  513. /* read data */
  514. if (snd_ice1712_gpio_read(ice) & VT1724_PRODIGY192_CDIN)
  515. data |= (1 << idx);
  516. udelay(1);
  517. /* raise clock */
  518. gpio |= VT1724_PRODIGY192_CCLK;
  519. snd_ice1712_gpio_write(ice, gpio);
  520. udelay(1);
  521. }
  522. return data;
  523. }
  524. /*
  525. * 4wire ak4114 protocol - starting sequence
  526. */
  527. static unsigned int prodigy192_4wire_start(struct snd_ice1712 *ice)
  528. {
  529. unsigned int tmp;
  530. snd_ice1712_save_gpio_status(ice);
  531. tmp = snd_ice1712_gpio_read(ice);
  532. tmp |= VT1724_PRODIGY192_CCLK; /* high at init */
  533. tmp &= ~VT1724_PRODIGY192_CS; /* drop chip select */
  534. snd_ice1712_gpio_write(ice, tmp);
  535. udelay(1);
  536. return tmp;
  537. }
  538. /*
  539. * 4wire ak4114 protocol - final sequence
  540. */
  541. static void prodigy192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
  542. {
  543. tmp |= VT1724_PRODIGY192_CS; /* raise chip select */
  544. snd_ice1712_gpio_write(ice, tmp);
  545. udelay(1);
  546. snd_ice1712_restore_gpio_status(ice);
  547. }
  548. /*
  549. * Write data to addr register of ak4114
  550. */
  551. static void prodigy192_ak4114_write(void *private_data, unsigned char addr,
  552. unsigned char data)
  553. {
  554. struct snd_ice1712 *ice = private_data;
  555. unsigned int tmp, addrdata;
  556. tmp = prodigy192_4wire_start(ice);
  557. addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
  558. addrdata = (addrdata << 8) | data;
  559. write_data(ice, tmp, addrdata, 15);
  560. prodigy192_4wire_finish(ice, tmp);
  561. }
  562. /*
  563. * Read data from addr register of ak4114
  564. */
  565. static unsigned char prodigy192_ak4114_read(void *private_data,
  566. unsigned char addr)
  567. {
  568. struct snd_ice1712 *ice = private_data;
  569. unsigned int tmp;
  570. unsigned char data;
  571. tmp = prodigy192_4wire_start(ice);
  572. write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
  573. data = read_data(ice, tmp, 7);
  574. prodigy192_4wire_finish(ice, tmp);
  575. return data;
  576. }
  577. static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
  578. struct snd_ctl_elem_info *uinfo)
  579. {
  580. static char *texts[2] = { "Toslink", "Coax" };
  581. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  582. uinfo->count = 1;
  583. uinfo->value.enumerated.items = 2;
  584. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  585. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  586. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  587. return 0;
  588. }
  589. static int ak4114_input_sw_get(struct snd_kcontrol *kcontrol,
  590. struct snd_ctl_elem_value *ucontrol)
  591. {
  592. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  593. unsigned char val;
  594. val = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
  595. /* AK4114_IPS0 bit = 0 -> RX0 = Toslink
  596. * AK4114_IPS0 bit = 1 -> RX1 = Coax
  597. */
  598. ucontrol->value.enumerated.item[0] = (val & AK4114_IPS0) ? 1 : 0;
  599. return 0;
  600. }
  601. static int ak4114_input_sw_put(struct snd_kcontrol *kcontrol,
  602. struct snd_ctl_elem_value *ucontrol)
  603. {
  604. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  605. unsigned char new, old, itemvalue;
  606. int change;
  607. old = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
  608. /* AK4114_IPS0 could be any bit */
  609. itemvalue = (ucontrol->value.enumerated.item[0]) ? 0xff : 0x00;
  610. new = (itemvalue & AK4114_IPS0) | (old & ~AK4114_IPS0);
  611. change = (new != old);
  612. if (change)
  613. prodigy192_ak4114_write(ice, AK4114_REG_IO1, new);
  614. return change;
  615. }
  616. static const struct snd_kcontrol_new ak4114_controls[] __devinitdata = {
  617. {
  618. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  619. .name = "MIODIO IEC958 Capture Input",
  620. .info = ak4114_input_sw_info,
  621. .get = ak4114_input_sw_get,
  622. .put = ak4114_input_sw_put,
  623. }
  624. };
  625. static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
  626. {
  627. static const unsigned char ak4114_init_vals[] = {
  628. AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
  629. AK4114_DIF_I24I2S, /* ice1724 expects I2S and provides clock */
  630. AK4114_TX1E,
  631. AK4114_EFH_1024 | AK4114_DIT, /* default input RX0 */
  632. 0,
  633. 0
  634. };
  635. static const unsigned char ak4114_init_txcsb[] = {
  636. 0x41, 0x02, 0x2c, 0x00, 0x00
  637. };
  638. return snd_ak4114_create(ice->card,
  639. prodigy192_ak4114_read,
  640. prodigy192_ak4114_write,
  641. ak4114_init_vals, ak4114_init_txcsb,
  642. ice, &ice->spec.prodigy192.ak4114);
  643. }
  644. static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice)
  645. {
  646. unsigned int i;
  647. int err;
  648. for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
  649. err = snd_ctl_add(ice->card,
  650. snd_ctl_new1(&stac_controls[i], ice));
  651. if (err < 0)
  652. return err;
  653. }
  654. if (ice->spec.prodigy192.ak4114) {
  655. /* ak4114 is connected */
  656. for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) {
  657. err = snd_ctl_add(ice->card,
  658. snd_ctl_new1(&ak4114_controls[i],
  659. ice));
  660. if (err < 0)
  661. return err;
  662. }
  663. err = snd_ak4114_build(ice->spec.prodigy192.ak4114,
  664. NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */
  665. ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  666. if (err < 0)
  667. return err;
  668. }
  669. return 0;
  670. }
  671. /*
  672. * check for presence of MI/ODI/O add-on card with digital inputs
  673. */
  674. static int prodigy192_miodio_exists(struct snd_ice1712 *ice)
  675. {
  676. unsigned char orig_value;
  677. const unsigned char test_data = 0xd1; /* random value */
  678. unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */
  679. int exists = 0;
  680. orig_value = prodigy192_ak4114_read(ice, addr);
  681. prodigy192_ak4114_write(ice, addr, test_data);
  682. if (prodigy192_ak4114_read(ice, addr) == test_data) {
  683. /* ak4114 seems to communicate, apparently exists */
  684. /* writing back original value */
  685. prodigy192_ak4114_write(ice, addr, orig_value);
  686. exists = 1;
  687. }
  688. return exists;
  689. }
  690. /*
  691. * initialize the chip
  692. */
  693. static int __devinit prodigy192_init(struct snd_ice1712 *ice)
  694. {
  695. static const unsigned short stac_inits_prodigy[] = {
  696. STAC946X_RESET, 0,
  697. /* STAC946X_MASTER_VOLUME, 0,
  698. STAC946X_LF_VOLUME, 0,
  699. STAC946X_RF_VOLUME, 0,
  700. STAC946X_LR_VOLUME, 0,
  701. STAC946X_RR_VOLUME, 0,
  702. STAC946X_CENTER_VOLUME, 0,
  703. STAC946X_LFE_VOLUME, 0,*/
  704. (unsigned short)-1
  705. };
  706. const unsigned short *p;
  707. int err = 0;
  708. /* prodigy 192 */
  709. ice->num_total_dacs = 6;
  710. ice->num_total_adcs = 2;
  711. ice->vt1720 = 0; /* ice1724, e.g. 23 GPIOs */
  712. /* initialize codec */
  713. p = stac_inits_prodigy;
  714. for (; *p != (unsigned short)-1; p += 2)
  715. stac9460_put(ice, p[0], p[1]);
  716. /* MI/ODI/O add on card with AK4114 */
  717. if (prodigy192_miodio_exists(ice)) {
  718. err = prodigy192_ak4114_init(ice);
  719. /* from this moment if err = 0 then
  720. * ice->spec.prodigy192.ak4114 should not be null
  721. */
  722. snd_printdd("AK4114 initialized with status %d\n", err);
  723. } else
  724. snd_printdd("AK4114 not found\n");
  725. if (err < 0)
  726. return err;
  727. return 0;
  728. }
  729. /*
  730. * Aureon boards don't provide the EEPROM data except for the vendor IDs.
  731. * hence the driver needs to sets up it properly.
  732. */
  733. static unsigned char prodigy71_eeprom[] __devinitdata = {
  734. [ICE_EEP2_SYSCONF] = 0x6a, /* 49MHz crystal, mpu401,
  735. * spdif-in+ 1 stereo ADC,
  736. * 3 stereo DACs
  737. */
  738. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  739. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  740. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  741. [ICE_EEP2_GPIO_DIR] = 0xff,
  742. [ICE_EEP2_GPIO_DIR1] = ~(VT1724_PRODIGY192_CDIN >> 8) ,
  743. [ICE_EEP2_GPIO_DIR2] = 0xbf,
  744. [ICE_EEP2_GPIO_MASK] = 0x00,
  745. [ICE_EEP2_GPIO_MASK1] = 0x00,
  746. [ICE_EEP2_GPIO_MASK2] = 0x00,
  747. [ICE_EEP2_GPIO_STATE] = 0x00,
  748. [ICE_EEP2_GPIO_STATE1] = 0x00,
  749. [ICE_EEP2_GPIO_STATE2] = 0x10, /* GPIO20: 0 = CD drive dig. input
  750. * passthrough,
  751. * 1 = SPDIF-OUT from ice1724
  752. */
  753. };
  754. /* entry point */
  755. struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
  756. {
  757. .subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
  758. .name = "Audiotrak Prodigy 192",
  759. .model = "prodigy192",
  760. .chip_init = prodigy192_init,
  761. .build_controls = prodigy192_add_controls,
  762. .eeprom_size = sizeof(prodigy71_eeprom),
  763. .eeprom_data = prodigy71_eeprom,
  764. },
  765. { } /* terminator */
  766. };