prodigy192.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. /*printk ("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. printk(KERN_DEBUG "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. printk(KERN_DEBUG "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. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  254. uinfo->count = 1;
  255. uinfo->value.enumerated.items = 2;
  256. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  257. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  258. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  259. return 0;
  260. }
  261. static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
  262. struct snd_ctl_elem_value *ucontrol)
  263. {
  264. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  265. unsigned char val;
  266. val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  267. ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
  268. return 0;
  269. }
  270. static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
  271. struct snd_ctl_elem_value *ucontrol)
  272. {
  273. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  274. unsigned char new, old;
  275. int change;
  276. old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  277. new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
  278. change = (new != old);
  279. if (change)
  280. stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
  281. return change;
  282. }
  283. /*
  284. * Handler for setting correct codec rate - called when rate change is detected
  285. */
  286. static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
  287. {
  288. unsigned char old, new;
  289. int idx;
  290. unsigned char changed[7];
  291. struct prodigy192_spec *spec = ice->spec;
  292. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  293. return;
  294. else if (rate <= 48000)
  295. new = 0x08; /* 256x, base rate mode */
  296. else if (rate <= 96000)
  297. new = 0x11; /* 256x, mid rate mode */
  298. else
  299. new = 0x12; /* 128x, high rate mode */
  300. old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
  301. if (old == new)
  302. return;
  303. /* change detected, setting master clock, muting first */
  304. /* due to possible conflicts with mute controls - mutexing */
  305. mutex_lock(&spec->mute_mutex);
  306. /* we have to remember current mute status for each DAC */
  307. for (idx = 0; idx < 7 ; ++idx)
  308. changed[idx] = stac9460_dac_mute(ice,
  309. STAC946X_MASTER_VOLUME + idx, 0);
  310. /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
  311. stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
  312. udelay(10);
  313. /* unmuting - only originally unmuted dacs -
  314. * i.e. those changed when muting */
  315. for (idx = 0; idx < 7 ; ++idx) {
  316. if (changed[idx])
  317. stac9460_dac_mute(ice, STAC946X_MASTER_VOLUME + idx, 1);
  318. }
  319. mutex_unlock(&spec->mute_mutex);
  320. }
  321. static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
  322. static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
  323. /*
  324. * mixers
  325. */
  326. static struct snd_kcontrol_new stac_controls[] = {
  327. {
  328. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  329. .name = "Master Playback Switch",
  330. .info = stac9460_dac_mute_info,
  331. .get = stac9460_dac_mute_get,
  332. .put = stac9460_dac_mute_put,
  333. .private_value = 1,
  334. .tlv = { .p = db_scale_dac }
  335. },
  336. {
  337. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  338. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  339. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  340. .name = "Master Playback Volume",
  341. .info = stac9460_dac_vol_info,
  342. .get = stac9460_dac_vol_get,
  343. .put = stac9460_dac_vol_put,
  344. .private_value = 1,
  345. .tlv = { .p = db_scale_dac }
  346. },
  347. {
  348. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  349. .name = "DAC Switch",
  350. .count = 6,
  351. .info = stac9460_dac_mute_info,
  352. .get = stac9460_dac_mute_get,
  353. .put = stac9460_dac_mute_put,
  354. },
  355. {
  356. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  357. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  358. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  359. .name = "DAC Volume",
  360. .count = 6,
  361. .info = stac9460_dac_vol_info,
  362. .get = stac9460_dac_vol_get,
  363. .put = stac9460_dac_vol_put,
  364. .tlv = { .p = db_scale_dac }
  365. },
  366. {
  367. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  368. .name = "ADC Capture Switch",
  369. .count = 1,
  370. .info = stac9460_adc_mute_info,
  371. .get = stac9460_adc_mute_get,
  372. .put = stac9460_adc_mute_put,
  373. },
  374. {
  375. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  376. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  377. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  378. .name = "ADC Capture Volume",
  379. .count = 1,
  380. .info = stac9460_adc_vol_info,
  381. .get = stac9460_adc_vol_get,
  382. .put = stac9460_adc_vol_put,
  383. .tlv = { .p = db_scale_adc }
  384. },
  385. {
  386. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  387. .name = "Analog Capture Input",
  388. .info = stac9460_mic_sw_info,
  389. .get = stac9460_mic_sw_get,
  390. .put = stac9460_mic_sw_put,
  391. },
  392. };
  393. /* AK4114 - ICE1724 connections on Prodigy192 + MI/ODI/O */
  394. /* CDTO (pin 32) -- GPIO11 pin 86
  395. * CDTI (pin 33) -- GPIO10 pin 77
  396. * CCLK (pin 34) -- GPIO9 pin 76
  397. * CSN (pin 35) -- GPIO8 pin 75
  398. */
  399. #define AK4114_ADDR 0x00 /* C1-C0: Chip Address
  400. * (According to datasheet fixed to “00”)
  401. */
  402. /*
  403. * 4wire ak4114 protocol - writing data
  404. */
  405. static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
  406. unsigned int data, int idx)
  407. {
  408. for (; idx >= 0; idx--) {
  409. /* drop clock */
  410. gpio &= ~VT1724_PRODIGY192_CCLK;
  411. snd_ice1712_gpio_write(ice, gpio);
  412. udelay(1);
  413. /* set data */
  414. if (data & (1 << idx))
  415. gpio |= VT1724_PRODIGY192_CDOUT;
  416. else
  417. gpio &= ~VT1724_PRODIGY192_CDOUT;
  418. snd_ice1712_gpio_write(ice, gpio);
  419. udelay(1);
  420. /* raise clock */
  421. gpio |= VT1724_PRODIGY192_CCLK;
  422. snd_ice1712_gpio_write(ice, gpio);
  423. udelay(1);
  424. }
  425. }
  426. /*
  427. * 4wire ak4114 protocol - reading data
  428. */
  429. static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
  430. int idx)
  431. {
  432. unsigned char data = 0;
  433. for (; idx >= 0; idx--) {
  434. /* drop clock */
  435. gpio &= ~VT1724_PRODIGY192_CCLK;
  436. snd_ice1712_gpio_write(ice, gpio);
  437. udelay(1);
  438. /* read data */
  439. if (snd_ice1712_gpio_read(ice) & VT1724_PRODIGY192_CDIN)
  440. data |= (1 << idx);
  441. udelay(1);
  442. /* raise clock */
  443. gpio |= VT1724_PRODIGY192_CCLK;
  444. snd_ice1712_gpio_write(ice, gpio);
  445. udelay(1);
  446. }
  447. return data;
  448. }
  449. /*
  450. * 4wire ak4114 protocol - starting sequence
  451. */
  452. static unsigned int prodigy192_4wire_start(struct snd_ice1712 *ice)
  453. {
  454. unsigned int tmp;
  455. snd_ice1712_save_gpio_status(ice);
  456. tmp = snd_ice1712_gpio_read(ice);
  457. tmp |= VT1724_PRODIGY192_CCLK; /* high at init */
  458. tmp &= ~VT1724_PRODIGY192_CS; /* drop chip select */
  459. snd_ice1712_gpio_write(ice, tmp);
  460. udelay(1);
  461. return tmp;
  462. }
  463. /*
  464. * 4wire ak4114 protocol - final sequence
  465. */
  466. static void prodigy192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
  467. {
  468. tmp |= VT1724_PRODIGY192_CS; /* raise chip select */
  469. snd_ice1712_gpio_write(ice, tmp);
  470. udelay(1);
  471. snd_ice1712_restore_gpio_status(ice);
  472. }
  473. /*
  474. * Write data to addr register of ak4114
  475. */
  476. static void prodigy192_ak4114_write(void *private_data, unsigned char addr,
  477. unsigned char data)
  478. {
  479. struct snd_ice1712 *ice = private_data;
  480. unsigned int tmp, addrdata;
  481. tmp = prodigy192_4wire_start(ice);
  482. addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
  483. addrdata = (addrdata << 8) | data;
  484. write_data(ice, tmp, addrdata, 15);
  485. prodigy192_4wire_finish(ice, tmp);
  486. }
  487. /*
  488. * Read data from addr register of ak4114
  489. */
  490. static unsigned char prodigy192_ak4114_read(void *private_data,
  491. unsigned char addr)
  492. {
  493. struct snd_ice1712 *ice = private_data;
  494. unsigned int tmp;
  495. unsigned char data;
  496. tmp = prodigy192_4wire_start(ice);
  497. write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
  498. data = read_data(ice, tmp, 7);
  499. prodigy192_4wire_finish(ice, tmp);
  500. return data;
  501. }
  502. static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
  503. struct snd_ctl_elem_info *uinfo)
  504. {
  505. static const char * const texts[2] = { "Toslink", "Coax" };
  506. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  507. uinfo->count = 1;
  508. uinfo->value.enumerated.items = 2;
  509. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  510. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  511. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  512. return 0;
  513. }
  514. static int ak4114_input_sw_get(struct snd_kcontrol *kcontrol,
  515. struct snd_ctl_elem_value *ucontrol)
  516. {
  517. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  518. unsigned char val;
  519. val = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
  520. /* AK4114_IPS0 bit = 0 -> RX0 = Toslink
  521. * AK4114_IPS0 bit = 1 -> RX1 = Coax
  522. */
  523. ucontrol->value.enumerated.item[0] = (val & AK4114_IPS0) ? 1 : 0;
  524. return 0;
  525. }
  526. static int ak4114_input_sw_put(struct snd_kcontrol *kcontrol,
  527. struct snd_ctl_elem_value *ucontrol)
  528. {
  529. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  530. unsigned char new, old, itemvalue;
  531. int change;
  532. old = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
  533. /* AK4114_IPS0 could be any bit */
  534. itemvalue = (ucontrol->value.enumerated.item[0]) ? 0xff : 0x00;
  535. new = (itemvalue & AK4114_IPS0) | (old & ~AK4114_IPS0);
  536. change = (new != old);
  537. if (change)
  538. prodigy192_ak4114_write(ice, AK4114_REG_IO1, new);
  539. return change;
  540. }
  541. static struct snd_kcontrol_new ak4114_controls[] = {
  542. {
  543. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  544. .name = "MIODIO IEC958 Capture Input",
  545. .info = ak4114_input_sw_info,
  546. .get = ak4114_input_sw_get,
  547. .put = ak4114_input_sw_put,
  548. }
  549. };
  550. static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
  551. {
  552. static const unsigned char ak4114_init_vals[] = {
  553. AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
  554. /* ice1724 expects I2S and provides clock,
  555. * DEM0 disables the deemphasis filter
  556. */
  557. AK4114_DIF_I24I2S | AK4114_DEM0 ,
  558. AK4114_TX1E,
  559. AK4114_EFH_1024 | AK4114_DIT, /* default input RX0 */
  560. 0,
  561. 0
  562. };
  563. static const unsigned char ak4114_init_txcsb[] = {
  564. 0x41, 0x02, 0x2c, 0x00, 0x00
  565. };
  566. struct prodigy192_spec *spec = ice->spec;
  567. int err;
  568. err = snd_ak4114_create(ice->card,
  569. prodigy192_ak4114_read,
  570. prodigy192_ak4114_write,
  571. ak4114_init_vals, ak4114_init_txcsb,
  572. ice, &spec->ak4114);
  573. if (err < 0)
  574. return err;
  575. /* AK4114 in Prodigy192 cannot detect external rate correctly.
  576. * No reason to stop capture stream due to incorrect checks */
  577. spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
  578. return 0;
  579. }
  580. static void stac9460_proc_regs_read(struct snd_info_entry *entry,
  581. struct snd_info_buffer *buffer)
  582. {
  583. struct snd_ice1712 *ice = entry->private_data;
  584. int reg, val;
  585. /* registers 0x0 - 0x14 */
  586. for (reg = 0; reg <= 0x15; reg++) {
  587. val = stac9460_get(ice, reg);
  588. snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
  589. }
  590. }
  591. static void stac9460_proc_init(struct snd_ice1712 *ice)
  592. {
  593. struct snd_info_entry *entry;
  594. if (!snd_card_proc_new(ice->card, "stac9460_codec", &entry))
  595. snd_info_set_text_ops(entry, ice, stac9460_proc_regs_read);
  596. }
  597. static int prodigy192_add_controls(struct snd_ice1712 *ice)
  598. {
  599. struct prodigy192_spec *spec = ice->spec;
  600. unsigned int i;
  601. int err;
  602. for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
  603. err = snd_ctl_add(ice->card,
  604. snd_ctl_new1(&stac_controls[i], ice));
  605. if (err < 0)
  606. return err;
  607. }
  608. if (spec->ak4114) {
  609. /* ak4114 is connected */
  610. for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) {
  611. err = snd_ctl_add(ice->card,
  612. snd_ctl_new1(&ak4114_controls[i],
  613. ice));
  614. if (err < 0)
  615. return err;
  616. }
  617. err = snd_ak4114_build(spec->ak4114,
  618. NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */
  619. ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  620. if (err < 0)
  621. return err;
  622. }
  623. stac9460_proc_init(ice);
  624. return 0;
  625. }
  626. /*
  627. * check for presence of MI/ODI/O add-on card with digital inputs
  628. */
  629. static int prodigy192_miodio_exists(struct snd_ice1712 *ice)
  630. {
  631. unsigned char orig_value;
  632. const unsigned char test_data = 0xd1; /* random value */
  633. unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */
  634. int exists = 0;
  635. orig_value = prodigy192_ak4114_read(ice, addr);
  636. prodigy192_ak4114_write(ice, addr, test_data);
  637. if (prodigy192_ak4114_read(ice, addr) == test_data) {
  638. /* ak4114 seems to communicate, apparently exists */
  639. /* writing back original value */
  640. prodigy192_ak4114_write(ice, addr, orig_value);
  641. exists = 1;
  642. }
  643. return exists;
  644. }
  645. /*
  646. * initialize the chip
  647. */
  648. static int prodigy192_init(struct snd_ice1712 *ice)
  649. {
  650. static const unsigned short stac_inits_prodigy[] = {
  651. STAC946X_RESET, 0,
  652. STAC946X_MASTER_CLOCKING, 0x11,
  653. /* STAC946X_MASTER_VOLUME, 0,
  654. STAC946X_LF_VOLUME, 0,
  655. STAC946X_RF_VOLUME, 0,
  656. STAC946X_LR_VOLUME, 0,
  657. STAC946X_RR_VOLUME, 0,
  658. STAC946X_CENTER_VOLUME, 0,
  659. STAC946X_LFE_VOLUME, 0,*/
  660. (unsigned short)-1
  661. };
  662. const unsigned short *p;
  663. int err = 0;
  664. struct prodigy192_spec *spec;
  665. /* prodigy 192 */
  666. ice->num_total_dacs = 6;
  667. ice->num_total_adcs = 2;
  668. ice->vt1720 = 0; /* ice1724, e.g. 23 GPIOs */
  669. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  670. if (!spec)
  671. return -ENOMEM;
  672. ice->spec = spec;
  673. mutex_init(&spec->mute_mutex);
  674. /* initialize codec */
  675. p = stac_inits_prodigy;
  676. for (; *p != (unsigned short)-1; p += 2)
  677. stac9460_put(ice, p[0], p[1]);
  678. ice->gpio.set_pro_rate = stac9460_set_rate_val;
  679. /* MI/ODI/O add on card with AK4114 */
  680. if (prodigy192_miodio_exists(ice)) {
  681. err = prodigy192_ak4114_init(ice);
  682. /* from this moment if err = 0 then
  683. * spec->ak4114 should not be null
  684. */
  685. snd_printdd("AK4114 initialized with status %d\n", err);
  686. } else
  687. snd_printdd("AK4114 not found\n");
  688. if (err < 0)
  689. return err;
  690. return 0;
  691. }
  692. /*
  693. * Aureon boards don't provide the EEPROM data except for the vendor IDs.
  694. * hence the driver needs to sets up it properly.
  695. */
  696. static unsigned char prodigy71_eeprom[] = {
  697. [ICE_EEP2_SYSCONF] = 0x6a, /* 49MHz crystal, mpu401,
  698. * spdif-in+ 1 stereo ADC,
  699. * 3 stereo DACs
  700. */
  701. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  702. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  703. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  704. [ICE_EEP2_GPIO_DIR] = 0xff,
  705. [ICE_EEP2_GPIO_DIR1] = ~(VT1724_PRODIGY192_CDIN >> 8) ,
  706. [ICE_EEP2_GPIO_DIR2] = 0xbf,
  707. [ICE_EEP2_GPIO_MASK] = 0x00,
  708. [ICE_EEP2_GPIO_MASK1] = 0x00,
  709. [ICE_EEP2_GPIO_MASK2] = 0x00,
  710. [ICE_EEP2_GPIO_STATE] = 0x00,
  711. [ICE_EEP2_GPIO_STATE1] = 0x00,
  712. [ICE_EEP2_GPIO_STATE2] = 0x10, /* GPIO20: 0 = CD drive dig. input
  713. * passthrough,
  714. * 1 = SPDIF-OUT from ice1724
  715. */
  716. };
  717. /* entry point */
  718. struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] = {
  719. {
  720. .subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
  721. .name = "Audiotrak Prodigy 192",
  722. .model = "prodigy192",
  723. .chip_init = prodigy192_init,
  724. .build_controls = prodigy192_add_controls,
  725. .eeprom_size = sizeof(prodigy71_eeprom),
  726. .eeprom_data = prodigy71_eeprom,
  727. },
  728. { } /* terminator */
  729. };