prodigy192.c 23 KB

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