prodigy192.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  3. *
  4. * Lowlevel functions for AudioTrak Prodigy 192 cards
  5. * Supported IEC958 input from optional MI/ODI/O add-on card.
  6. *
  7. * Specifics (SW, HW):
  8. * -------------------
  9. * * 49.5MHz crystal
  10. * * SPDIF-OUT on the card:
  11. * - coax (through isolation transformer)/toslink supplied by
  12. * 74HC04 gates - 3 in parallel
  13. * - output switched between on-board CD drive dig-out connector
  14. * and ice1724 SPDTX pin, using 74HC02 NOR gates, controlled
  15. * by GPIO20 (0 = CD dig-out, 1 = SPDTX)
  16. * * SPDTX goes straight to MI/ODI/O card's SPDIF-OUT coax
  17. *
  18. * * MI/ODI/O card: AK4114 based, used for iec958 input only
  19. * - toslink input -> RX0
  20. * - coax input -> RX1
  21. * - 4wire protocol:
  22. * AK4114 ICE1724
  23. * ------------------------------
  24. * CDTO (pin 32) -- GPIO11 pin 86
  25. * CDTI (pin 33) -- GPIO10 pin 77
  26. * CCLK (pin 34) -- GPIO9 pin 76
  27. * CSN (pin 35) -- GPIO8 pin 75
  28. * - output data Mode 7 (24bit, I2S, slave)
  29. * - both MCKO1 and MCKO2 of ak4114 are fed to FPGA, which
  30. * outputs master clock to SPMCLKIN of ice1724.
  31. * Experimentally I found out that only a combination of
  32. * OCKS0=1, OCKS1=1 (128fs, 64fs output) and ice1724 -
  33. * VT1724_MT_I2S_MCLK_128X=0 (256fs input) yields correct
  34. * sampling rate. That means the the FPGA doubles the
  35. * MCK01 rate.
  36. *
  37. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  38. * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
  39. * Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp>
  40. *
  41. * This program is free software; you can redistribute it and/or modify
  42. * it under the terms of the GNU General Public License as published by
  43. * the Free Software Foundation; either version 2 of the License, or
  44. * (at your option) any later version.
  45. *
  46. * This program is distributed in the hope that it will be useful,
  47. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49. * GNU General Public License for more details.
  50. *
  51. * You should have received a copy of the GNU General Public License
  52. * along with this program; if not, write to the Free Software
  53. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  54. *
  55. */
  56. #include <sound/driver.h>
  57. #include <asm/io.h>
  58. #include <linux/delay.h>
  59. #include <linux/interrupt.h>
  60. #include <linux/init.h>
  61. #include <linux/slab.h>
  62. #include <sound/core.h>
  63. #include "ice1712.h"
  64. #include "envy24ht.h"
  65. #include "prodigy192.h"
  66. #include "stac946x.h"
  67. #include <sound/tlv.h>
  68. static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val)
  69. {
  70. snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);
  71. }
  72. static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
  73. {
  74. return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);
  75. }
  76. /*
  77. * DAC mute control
  78. */
  79. /*
  80. * idx = STAC9460 volume register number, mute: 0 = mute, 1 = unmute
  81. */
  82. static int stac9460_dac_mute(struct snd_ice1712 *ice, int idx,
  83. unsigned char mute)
  84. {
  85. unsigned char new, old;
  86. int change;
  87. old = stac9460_get(ice, idx);
  88. new = (~mute << 7 & 0x80) | (old & ~0x80);
  89. change = (new != old);
  90. if (change)
  91. /*printk ("Volume register 0x%02x: 0x%02x\n", idx, new);*/
  92. stac9460_put(ice, idx, new);
  93. return change;
  94. }
  95. #define stac9460_dac_mute_info snd_ctl_boolean_mono_info
  96. static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  97. {
  98. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  99. unsigned char val;
  100. int idx;
  101. if (kcontrol->private_value)
  102. idx = STAC946X_MASTER_VOLUME;
  103. else
  104. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  105. val = stac9460_get(ice, idx);
  106. ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
  107. return 0;
  108. }
  109. static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  110. {
  111. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  112. int idx, change;
  113. if (kcontrol->private_value)
  114. idx = STAC946X_MASTER_VOLUME;
  115. else
  116. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  117. /* due to possible conflicts with stac9460_set_rate_val, mutexing */
  118. mutex_lock(&ice->spec.prodigy192.mute_mutex);
  119. /*printk("Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx,
  120. ucontrol->value.integer.value[0]);*/
  121. change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]);
  122. mutex_unlock(&ice->spec.prodigy192.mute_mutex);
  123. return change;
  124. }
  125. /*
  126. * DAC volume attenuation mixer control
  127. */
  128. static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  129. {
  130. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  131. uinfo->count = 1;
  132. uinfo->value.integer.min = 0; /* mute */
  133. uinfo->value.integer.max = 0x7f; /* 0dB */
  134. return 0;
  135. }
  136. static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  137. {
  138. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  139. int idx;
  140. unsigned char vol;
  141. if (kcontrol->private_value)
  142. idx = STAC946X_MASTER_VOLUME;
  143. else
  144. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  145. vol = stac9460_get(ice, idx) & 0x7f;
  146. ucontrol->value.integer.value[0] = 0x7f - vol;
  147. return 0;
  148. }
  149. static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  150. {
  151. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  152. int idx;
  153. unsigned char tmp, ovol, nvol;
  154. int change;
  155. if (kcontrol->private_value)
  156. idx = STAC946X_MASTER_VOLUME;
  157. else
  158. idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
  159. nvol = ucontrol->value.integer.value[0];
  160. tmp = stac9460_get(ice, idx);
  161. ovol = 0x7f - (tmp & 0x7f);
  162. change = (ovol != nvol);
  163. if (change) {
  164. ovol = (0x7f - nvol) | (tmp & 0x80);
  165. /*printk("DAC Volume: reg 0x%02x: 0x%02x\n", idx, ovol);*/
  166. stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
  167. }
  168. return change;
  169. }
  170. /*
  171. * ADC mute control
  172. */
  173. #define stac9460_adc_mute_info snd_ctl_boolean_stereo_info
  174. static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  175. {
  176. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  177. unsigned char val;
  178. int i;
  179. for (i = 0; i < 2; ++i) {
  180. val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
  181. ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
  182. }
  183. return 0;
  184. }
  185. static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  186. {
  187. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  188. unsigned char new, old;
  189. int i, reg;
  190. int change;
  191. for (i = 0; i < 2; ++i) {
  192. reg = STAC946X_MIC_L_VOLUME + i;
  193. old = stac9460_get(ice, reg);
  194. new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80);
  195. change = (new != old);
  196. if (change)
  197. stac9460_put(ice, reg, new);
  198. }
  199. return change;
  200. }
  201. /*
  202. * ADC gain mixer control
  203. */
  204. static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  205. {
  206. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  207. uinfo->count = 2;
  208. uinfo->value.integer.min = 0; /* 0dB */
  209. uinfo->value.integer.max = 0x0f; /* 22.5dB */
  210. return 0;
  211. }
  212. static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  213. {
  214. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  215. int i, reg;
  216. unsigned char vol;
  217. for (i = 0; i < 2; ++i) {
  218. reg = STAC946X_MIC_L_VOLUME + i;
  219. vol = stac9460_get(ice, reg) & 0x0f;
  220. ucontrol->value.integer.value[i] = 0x0f - vol;
  221. }
  222. return 0;
  223. }
  224. static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  225. {
  226. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  227. int i, reg;
  228. unsigned char ovol, nvol;
  229. int change;
  230. for (i = 0; i < 2; ++i) {
  231. reg = STAC946X_MIC_L_VOLUME + i;
  232. nvol = ucontrol->value.integer.value[i] & 0x0f;
  233. ovol = 0x0f - stac9460_get(ice, reg);
  234. change = ((ovol & 0x0f) != nvol);
  235. if (change)
  236. stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f));
  237. }
  238. return change;
  239. }
  240. static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
  241. struct snd_ctl_elem_info *uinfo)
  242. {
  243. static char *texts[2] = { "Line In", "Mic" };
  244. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  245. uinfo->count = 1;
  246. uinfo->value.enumerated.items = 2;
  247. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  248. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  249. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  250. return 0;
  251. }
  252. static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
  253. struct snd_ctl_elem_value *ucontrol)
  254. {
  255. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  256. unsigned char val;
  257. val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  258. ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
  259. return 0;
  260. }
  261. static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
  262. struct snd_ctl_elem_value *ucontrol)
  263. {
  264. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  265. unsigned char new, old;
  266. int change;
  267. old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
  268. new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
  269. change = (new != old);
  270. if (change)
  271. stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
  272. return change;
  273. }
  274. /*
  275. * Handler for setting correct codec rate - called when rate change is detected
  276. */
  277. static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  278. {
  279. unsigned char old, new;
  280. int idx;
  281. unsigned char changed[7];
  282. struct snd_ice1712 *ice = ak->private_data[0];
  283. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  284. return;
  285. else if (rate <= 48000)
  286. new = 0x08; /* 256x, base rate mode */
  287. else if (rate <= 96000)
  288. new = 0x11; /* 256x, mid rate mode */
  289. else
  290. new = 0x12; /* 128x, high rate mode */
  291. old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
  292. if (old == new)
  293. return;
  294. /* change detected, setting master clock, muting first */
  295. /* due to possible conflicts with mute controls - mutexing */
  296. mutex_lock(&ice->spec.prodigy192.mute_mutex);
  297. /* we have to remember current mute status for each DAC */
  298. for (idx = 0; idx < 7 ; ++idx)
  299. changed[idx] = stac9460_dac_mute(ice,
  300. STAC946X_MASTER_VOLUME + idx, 0);
  301. /*printk("Rate change: %d, new MC: 0x%02x\n", rate, new);*/
  302. stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
  303. udelay(10);
  304. /* unmuting - only originally unmuted dacs -
  305. * i.e. those changed when muting */
  306. for (idx = 0; idx < 7 ; ++idx) {
  307. if (changed[idx])
  308. stac9460_dac_mute(ice, STAC946X_MASTER_VOLUME + idx, 1);
  309. }
  310. mutex_unlock(&ice->spec.prodigy192.mute_mutex);
  311. }
  312. /* using akm infrastructure for setting rate of the codec */
  313. static struct snd_akm4xxx akmlike_stac9460 __devinitdata = {
  314. .type = NON_AKM, /* special value */
  315. .num_adcs = 6, /* not used in any way, just for completeness */
  316. .num_dacs = 2,
  317. .ops = {
  318. .set_rate_val = stac9460_set_rate_val
  319. }
  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[] __devinitdata = {
  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 char *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[] __devinitdata = {
  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. return snd_ak4114_create(ice->card,
  567. prodigy192_ak4114_read,
  568. prodigy192_ak4114_write,
  569. ak4114_init_vals, ak4114_init_txcsb,
  570. ice, &ice->spec.prodigy192.ak4114);
  571. }
  572. static void stac9460_proc_regs_read(struct snd_info_entry *entry,
  573. struct snd_info_buffer *buffer)
  574. {
  575. struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
  576. int reg, val;
  577. /* registers 0x0 - 0x14 */
  578. for (reg = 0; reg <= 0x15; reg++) {
  579. val = stac9460_get(ice, reg);
  580. snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
  581. }
  582. }
  583. static void stac9460_proc_init(struct snd_ice1712 *ice)
  584. {
  585. struct snd_info_entry *entry;
  586. if (!snd_card_proc_new(ice->card, "stac9460_codec", &entry))
  587. snd_info_set_text_ops(entry, ice, stac9460_proc_regs_read);
  588. }
  589. static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice)
  590. {
  591. unsigned int i;
  592. int err;
  593. for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
  594. err = snd_ctl_add(ice->card,
  595. snd_ctl_new1(&stac_controls[i], ice));
  596. if (err < 0)
  597. return err;
  598. }
  599. if (ice->spec.prodigy192.ak4114) {
  600. /* ak4114 is connected */
  601. for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) {
  602. err = snd_ctl_add(ice->card,
  603. snd_ctl_new1(&ak4114_controls[i],
  604. ice));
  605. if (err < 0)
  606. return err;
  607. }
  608. err = snd_ak4114_build(ice->spec.prodigy192.ak4114,
  609. NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */
  610. ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  611. if (err < 0)
  612. return err;
  613. }
  614. stac9460_proc_init(ice);
  615. return 0;
  616. }
  617. /*
  618. * check for presence of MI/ODI/O add-on card with digital inputs
  619. */
  620. static int prodigy192_miodio_exists(struct snd_ice1712 *ice)
  621. {
  622. unsigned char orig_value;
  623. const unsigned char test_data = 0xd1; /* random value */
  624. unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */
  625. int exists = 0;
  626. orig_value = prodigy192_ak4114_read(ice, addr);
  627. prodigy192_ak4114_write(ice, addr, test_data);
  628. if (prodigy192_ak4114_read(ice, addr) == test_data) {
  629. /* ak4114 seems to communicate, apparently exists */
  630. /* writing back original value */
  631. prodigy192_ak4114_write(ice, addr, orig_value);
  632. exists = 1;
  633. }
  634. return exists;
  635. }
  636. /*
  637. * initialize the chip
  638. */
  639. static int __devinit prodigy192_init(struct snd_ice1712 *ice)
  640. {
  641. static const unsigned short stac_inits_prodigy[] = {
  642. STAC946X_RESET, 0,
  643. STAC946X_MASTER_CLOCKING, 0x11,
  644. /* STAC946X_MASTER_VOLUME, 0,
  645. STAC946X_LF_VOLUME, 0,
  646. STAC946X_RF_VOLUME, 0,
  647. STAC946X_LR_VOLUME, 0,
  648. STAC946X_RR_VOLUME, 0,
  649. STAC946X_CENTER_VOLUME, 0,
  650. STAC946X_LFE_VOLUME, 0,*/
  651. (unsigned short)-1
  652. };
  653. const unsigned short *p;
  654. int err = 0;
  655. struct snd_akm4xxx *ak;
  656. /* prodigy 192 */
  657. ice->num_total_dacs = 6;
  658. ice->num_total_adcs = 2;
  659. ice->vt1720 = 0; /* ice1724, e.g. 23 GPIOs */
  660. /* initialize codec */
  661. p = stac_inits_prodigy;
  662. for (; *p != (unsigned short)-1; p += 2)
  663. stac9460_put(ice, p[0], p[1]);
  664. /* reusing the akm codecs infrastructure,
  665. * for setting rate on stac9460 */
  666. ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  667. if (!ak)
  668. return -ENOMEM;
  669. ice->akm_codecs = 1;
  670. err = snd_ice1712_akm4xxx_init(ak, &akmlike_stac9460, NULL, ice);
  671. if (err < 0)
  672. return err;
  673. /* MI/ODI/O add on card with AK4114 */
  674. if (prodigy192_miodio_exists(ice)) {
  675. err = prodigy192_ak4114_init(ice);
  676. /* from this moment if err = 0 then
  677. * ice->spec.prodigy192.ak4114 should not be null
  678. */
  679. snd_printdd("AK4114 initialized with status %d\n", err);
  680. } else
  681. snd_printdd("AK4114 not found\n");
  682. if (err < 0)
  683. return err;
  684. mutex_init(&ice->spec.prodigy192.mute_mutex);
  685. return 0;
  686. }
  687. /*
  688. * Aureon boards don't provide the EEPROM data except for the vendor IDs.
  689. * hence the driver needs to sets up it properly.
  690. */
  691. static unsigned char prodigy71_eeprom[] __devinitdata = {
  692. [ICE_EEP2_SYSCONF] = 0x6a, /* 49MHz crystal, mpu401,
  693. * spdif-in+ 1 stereo ADC,
  694. * 3 stereo DACs
  695. */
  696. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  697. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  698. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  699. [ICE_EEP2_GPIO_DIR] = 0xff,
  700. [ICE_EEP2_GPIO_DIR1] = ~(VT1724_PRODIGY192_CDIN >> 8) ,
  701. [ICE_EEP2_GPIO_DIR2] = 0xbf,
  702. [ICE_EEP2_GPIO_MASK] = 0x00,
  703. [ICE_EEP2_GPIO_MASK1] = 0x00,
  704. [ICE_EEP2_GPIO_MASK2] = 0x00,
  705. [ICE_EEP2_GPIO_STATE] = 0x00,
  706. [ICE_EEP2_GPIO_STATE1] = 0x00,
  707. [ICE_EEP2_GPIO_STATE2] = 0x10, /* GPIO20: 0 = CD drive dig. input
  708. * passthrough,
  709. * 1 = SPDIF-OUT from ice1724
  710. */
  711. };
  712. /* entry point */
  713. struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
  714. {
  715. .subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
  716. .name = "Audiotrak Prodigy 192",
  717. .model = "prodigy192",
  718. .chip_init = prodigy192_init,
  719. .build_controls = prodigy192_add_controls,
  720. .eeprom_size = sizeof(prodigy71_eeprom),
  721. .eeprom_data = prodigy71_eeprom,
  722. /* the current MPU401 code loops infinitely
  723. * when opening midi device
  724. */
  725. .no_mpu401 = 1,
  726. },
  727. { } /* terminator */
  728. };