prodigy192.c 23 KB

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