prodigy192.c 22 KB

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