prodigy192.c 22 KB

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