prodigy192.c 22 KB

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