prodigy192.c 21 KB

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