prodigy192.c 22 KB

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