juli.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ALSA driver for ICEnsemble VT1724 (Envy24HT)
  4. *
  5. * Lowlevel functions for ESI Juli@ cards
  6. *
  7. * Copyright (c) 2004 Jaroslav Kysela <[email protected]>
  8. * 2008 Pavel Hofman <[email protected]>
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <sound/core.h>
  16. #include <sound/tlv.h>
  17. #include "ice1712.h"
  18. #include "envy24ht.h"
  19. #include "juli.h"
  20. struct juli_spec {
  21. struct ak4114 *ak4114;
  22. unsigned int analog:1;
  23. };
  24. /*
  25. * chip addresses on I2C bus
  26. */
  27. #define AK4114_ADDR 0x20 /* S/PDIF receiver */
  28. #define AK4358_ADDR 0x22 /* DAC */
  29. /*
  30. * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is
  31. * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency
  32. * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx.
  33. *
  34. * The clock circuitry is supplied by the two ice1724 crystals. This
  35. * arrangement allows to generate independent clock signal for AK4114's input
  36. * rate detection circuit. As a result, Juli, unlike most other
  37. * ice1724+ak4114-based cards, detects spdif input rate correctly.
  38. * This fact is applied in the driver, allowing to modify PCM stream rate
  39. * parameter according to the actual input rate.
  40. *
  41. * Juli uses the remaining three stereo-channels of its DAC to optionally
  42. * monitor analog input, digital input, and digital output. The corresponding
  43. * I2S signals are routed by Xilinx, controlled by GPIOs.
  44. *
  45. * The master mute is implemented using output muting transistors (GPIO) in
  46. * combination with smuting the DAC.
  47. *
  48. * The card itself has no HW master volume control, implemented using the
  49. * vmaster control.
  50. *
  51. * TODO:
  52. * researching and fixing the input monitors
  53. */
  54. /*
  55. * GPIO pins
  56. */
  57. #define GPIO_FREQ_MASK (3<<0)
  58. #define GPIO_FREQ_32KHZ (0<<0)
  59. #define GPIO_FREQ_44KHZ (1<<0)
  60. #define GPIO_FREQ_48KHZ (2<<0)
  61. #define GPIO_MULTI_MASK (3<<2)
  62. #define GPIO_MULTI_4X (0<<2)
  63. #define GPIO_MULTI_2X (1<<2)
  64. #define GPIO_MULTI_1X (2<<2) /* also external */
  65. #define GPIO_MULTI_HALF (3<<2)
  66. #define GPIO_INTERNAL_CLOCK (1<<4) /* 0 = external, 1 = internal */
  67. #define GPIO_CLOCK_MASK (1<<4)
  68. #define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
  69. #define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
  70. #define GPIO_AK5385A_CKS0 (1<<8)
  71. #define GPIO_AK5385A_DFS1 (1<<9)
  72. #define GPIO_AK5385A_DFS0 (1<<10)
  73. #define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
  74. #define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
  75. #define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
  76. #define GPIO_AK5385A_CKS1 (1<<14) /* must be 0 */
  77. #define GPIO_MUTE_CONTROL (1<<15) /* output mute, 1 = muted */
  78. #define GPIO_RATE_MASK (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \
  79. GPIO_CLOCK_MASK)
  80. #define GPIO_AK5385A_MASK (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \
  81. GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1)
  82. #define JULI_PCM_RATE (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
  83. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  84. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  85. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
  86. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
  87. #define GPIO_RATE_16000 (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \
  88. GPIO_INTERNAL_CLOCK)
  89. #define GPIO_RATE_22050 (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \
  90. GPIO_INTERNAL_CLOCK)
  91. #define GPIO_RATE_24000 (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \
  92. GPIO_INTERNAL_CLOCK)
  93. #define GPIO_RATE_32000 (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \
  94. GPIO_INTERNAL_CLOCK)
  95. #define GPIO_RATE_44100 (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \
  96. GPIO_INTERNAL_CLOCK)
  97. #define GPIO_RATE_48000 (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \
  98. GPIO_INTERNAL_CLOCK)
  99. #define GPIO_RATE_64000 (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \
  100. GPIO_INTERNAL_CLOCK)
  101. #define GPIO_RATE_88200 (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \
  102. GPIO_INTERNAL_CLOCK)
  103. #define GPIO_RATE_96000 (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \
  104. GPIO_INTERNAL_CLOCK)
  105. #define GPIO_RATE_176400 (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \
  106. GPIO_INTERNAL_CLOCK)
  107. #define GPIO_RATE_192000 (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \
  108. GPIO_INTERNAL_CLOCK)
  109. /*
  110. * Initial setup of the conversion array GPIO <-> rate
  111. */
  112. static const unsigned int juli_rates[] = {
  113. 16000, 22050, 24000, 32000,
  114. 44100, 48000, 64000, 88200,
  115. 96000, 176400, 192000,
  116. };
  117. static const unsigned int gpio_vals[] = {
  118. GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000,
  119. GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200,
  120. GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000,
  121. };
  122. static const struct snd_pcm_hw_constraint_list juli_rates_info = {
  123. .count = ARRAY_SIZE(juli_rates),
  124. .list = juli_rates,
  125. .mask = 0,
  126. };
  127. static int get_gpio_val(int rate)
  128. {
  129. int i;
  130. for (i = 0; i < ARRAY_SIZE(juli_rates); i++)
  131. if (juli_rates[i] == rate)
  132. return gpio_vals[i];
  133. return 0;
  134. }
  135. static void juli_ak4114_write(void *private_data, unsigned char reg,
  136. unsigned char val)
  137. {
  138. snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR,
  139. reg, val);
  140. }
  141. static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
  142. {
  143. return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data,
  144. AK4114_ADDR, reg);
  145. }
  146. /*
  147. * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate
  148. * to the external rate
  149. */
  150. static void juli_spdif_in_open(struct snd_ice1712 *ice,
  151. struct snd_pcm_substream *substream)
  152. {
  153. struct juli_spec *spec = ice->spec;
  154. struct snd_pcm_runtime *runtime = substream->runtime;
  155. int rate;
  156. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  157. !ice->is_spdif_master(ice))
  158. return;
  159. rate = snd_ak4114_external_rate(spec->ak4114);
  160. if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
  161. runtime->hw.rate_min = rate;
  162. runtime->hw.rate_max = rate;
  163. }
  164. }
  165. /*
  166. * AK4358 section
  167. */
  168. static void juli_akm_lock(struct snd_akm4xxx *ak, int chip)
  169. {
  170. }
  171. static void juli_akm_unlock(struct snd_akm4xxx *ak, int chip)
  172. {
  173. }
  174. static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
  175. unsigned char addr, unsigned char data)
  176. {
  177. struct snd_ice1712 *ice = ak->private_data[0];
  178. if (snd_BUG_ON(chip))
  179. return;
  180. snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data);
  181. }
  182. /*
  183. * change the rate of envy24HT, AK4358, AK5385
  184. */
  185. static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  186. {
  187. unsigned char old, tmp, ak4358_dfs;
  188. unsigned int ak5385_pins, old_gpio, new_gpio;
  189. struct snd_ice1712 *ice = ak->private_data[0];
  190. struct juli_spec *spec = ice->spec;
  191. if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
  192. input rate undetected, simply return */
  193. return;
  194. /* adjust DFS on codecs */
  195. if (rate > 96000) {
  196. ak4358_dfs = 2;
  197. ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0;
  198. } else if (rate > 48000) {
  199. ak4358_dfs = 1;
  200. ak5385_pins = GPIO_AK5385A_DFS0;
  201. } else {
  202. ak4358_dfs = 0;
  203. ak5385_pins = 0;
  204. }
  205. /* AK5385 first, since it requires cold reset affecting both codecs */
  206. old_gpio = ice->gpio.get_data(ice);
  207. new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
  208. /* dev_dbg(ice->card->dev, "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
  209. new_gpio); */
  210. ice->gpio.set_data(ice, new_gpio);
  211. /* cold reset */
  212. old = inb(ICEMT1724(ice, AC97_CMD));
  213. outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
  214. udelay(1);
  215. outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
  216. /* AK4358 */
  217. /* set new value, reset DFS */
  218. tmp = snd_akm4xxx_get(ak, 0, 2);
  219. snd_akm4xxx_reset(ak, 1);
  220. tmp = snd_akm4xxx_get(ak, 0, 2);
  221. tmp &= ~(0x03 << 4);
  222. tmp |= ak4358_dfs << 4;
  223. snd_akm4xxx_set(ak, 0, 2, tmp);
  224. snd_akm4xxx_reset(ak, 0);
  225. /* reinit ak4114 */
  226. snd_ak4114_reinit(spec->ak4114);
  227. }
  228. #define AK_DAC(xname, xch) { .name = xname, .num_channels = xch }
  229. #define PCM_VOLUME "PCM Playback Volume"
  230. #define MONITOR_AN_IN_VOLUME "Monitor Analog In Volume"
  231. #define MONITOR_DIG_IN_VOLUME "Monitor Digital In Volume"
  232. #define MONITOR_DIG_OUT_VOLUME "Monitor Digital Out Volume"
  233. static const struct snd_akm4xxx_dac_channel juli_dac[] = {
  234. AK_DAC(PCM_VOLUME, 2),
  235. AK_DAC(MONITOR_AN_IN_VOLUME, 2),
  236. AK_DAC(MONITOR_DIG_OUT_VOLUME, 2),
  237. AK_DAC(MONITOR_DIG_IN_VOLUME, 2),
  238. };
  239. static const struct snd_akm4xxx akm_juli_dac = {
  240. .type = SND_AK4358,
  241. .num_dacs = 8, /* DAC1 - analog out
  242. DAC2 - analog in monitor
  243. DAC3 - digital out monitor
  244. DAC4 - digital in monitor
  245. */
  246. .ops = {
  247. .lock = juli_akm_lock,
  248. .unlock = juli_akm_unlock,
  249. .write = juli_akm_write,
  250. .set_rate_val = juli_akm_set_rate_val
  251. },
  252. .dac_info = juli_dac,
  253. };
  254. #define juli_mute_info snd_ctl_boolean_mono_info
  255. static int juli_mute_get(struct snd_kcontrol *kcontrol,
  256. struct snd_ctl_elem_value *ucontrol)
  257. {
  258. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  259. unsigned int val;
  260. val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value;
  261. if (kcontrol->private_value == GPIO_MUTE_CONTROL)
  262. /* val 0 = signal on */
  263. ucontrol->value.integer.value[0] = (val) ? 0 : 1;
  264. else
  265. /* val 1 = signal on */
  266. ucontrol->value.integer.value[0] = (val) ? 1 : 0;
  267. return 0;
  268. }
  269. static int juli_mute_put(struct snd_kcontrol *kcontrol,
  270. struct snd_ctl_elem_value *ucontrol)
  271. {
  272. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  273. unsigned int old_gpio, new_gpio;
  274. old_gpio = ice->gpio.get_data(ice);
  275. if (ucontrol->value.integer.value[0]) {
  276. /* unmute */
  277. if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
  278. /* 0 = signal on */
  279. new_gpio = old_gpio & ~GPIO_MUTE_CONTROL;
  280. /* un-smuting DAC */
  281. snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01);
  282. } else
  283. /* 1 = signal on */
  284. new_gpio = old_gpio |
  285. (unsigned int) kcontrol->private_value;
  286. } else {
  287. /* mute */
  288. if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
  289. /* 1 = signal off */
  290. new_gpio = old_gpio | GPIO_MUTE_CONTROL;
  291. /* smuting DAC */
  292. snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03);
  293. } else
  294. /* 0 = signal off */
  295. new_gpio = old_gpio &
  296. ~((unsigned int) kcontrol->private_value);
  297. }
  298. /* dev_dbg(ice->card->dev,
  299. "JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, "
  300. "new_gpio 0x%x\n",
  301. (unsigned int)ucontrol->value.integer.value[0], old_gpio,
  302. new_gpio); */
  303. if (old_gpio != new_gpio) {
  304. ice->gpio.set_data(ice, new_gpio);
  305. return 1;
  306. }
  307. /* no change */
  308. return 0;
  309. }
  310. static const struct snd_kcontrol_new juli_mute_controls[] = {
  311. {
  312. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  313. .name = "Master Playback Switch",
  314. .info = juli_mute_info,
  315. .get = juli_mute_get,
  316. .put = juli_mute_put,
  317. .private_value = GPIO_MUTE_CONTROL,
  318. },
  319. /* Although the following functionality respects the succint NDA'd
  320. * documentation from the card manufacturer, and the same way of
  321. * operation is coded in OSS Juli driver, only Digital Out monitor
  322. * seems to work. Surprisingly, Analog input monitor outputs Digital
  323. * output data. The two are independent, as enabling both doubles
  324. * volume of the monitor sound.
  325. *
  326. * Checking traces on the board suggests the functionality described
  327. * by the manufacturer is correct - I2S from ADC and AK4114
  328. * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor
  329. * inputs) are fed from Xilinx.
  330. *
  331. * I even checked traces on board and coded a support in driver for
  332. * an alternative possibility - the unused I2S ICE output channels
  333. * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
  334. * the DAC - to no avail. The I2S outputs seem to be unconnected.
  335. *
  336. * The windows driver supports the monitoring correctly.
  337. */
  338. {
  339. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  340. .name = "Monitor Analog In Switch",
  341. .info = juli_mute_info,
  342. .get = juli_mute_get,
  343. .put = juli_mute_put,
  344. .private_value = GPIO_ANAIN_MONITOR,
  345. },
  346. {
  347. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  348. .name = "Monitor Digital Out Switch",
  349. .info = juli_mute_info,
  350. .get = juli_mute_get,
  351. .put = juli_mute_put,
  352. .private_value = GPIO_DIGOUT_MONITOR,
  353. },
  354. {
  355. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  356. .name = "Monitor Digital In Switch",
  357. .info = juli_mute_info,
  358. .get = juli_mute_get,
  359. .put = juli_mute_put,
  360. .private_value = GPIO_DIGIN_MONITOR,
  361. },
  362. };
  363. static const char * const follower_vols[] = {
  364. PCM_VOLUME,
  365. MONITOR_AN_IN_VOLUME,
  366. MONITOR_DIG_IN_VOLUME,
  367. MONITOR_DIG_OUT_VOLUME,
  368. NULL
  369. };
  370. static
  371. DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
  372. static struct snd_kcontrol *ctl_find(struct snd_card *card,
  373. const char *name)
  374. {
  375. struct snd_ctl_elem_id sid = {0};
  376. strscpy(sid.name, name, sizeof(sid.name));
  377. sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  378. return snd_ctl_find_id(card, &sid);
  379. }
  380. static void add_followers(struct snd_card *card,
  381. struct snd_kcontrol *master,
  382. const char * const *list)
  383. {
  384. for (; *list; list++) {
  385. struct snd_kcontrol *follower = ctl_find(card, *list);
  386. /* dev_dbg(card->dev, "add_followers - %s\n", *list); */
  387. if (follower) {
  388. /* dev_dbg(card->dev, "follower %s found\n", *list); */
  389. snd_ctl_add_follower(master, follower);
  390. }
  391. }
  392. }
  393. static int juli_add_controls(struct snd_ice1712 *ice)
  394. {
  395. struct juli_spec *spec = ice->spec;
  396. int err;
  397. unsigned int i;
  398. struct snd_kcontrol *vmaster;
  399. err = snd_ice1712_akm4xxx_build_controls(ice);
  400. if (err < 0)
  401. return err;
  402. for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) {
  403. err = snd_ctl_add(ice->card,
  404. snd_ctl_new1(&juli_mute_controls[i], ice));
  405. if (err < 0)
  406. return err;
  407. }
  408. /* Create virtual master control */
  409. vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
  410. juli_master_db_scale);
  411. if (!vmaster)
  412. return -ENOMEM;
  413. add_followers(ice->card, vmaster, follower_vols);
  414. err = snd_ctl_add(ice->card, vmaster);
  415. if (err < 0)
  416. return err;
  417. /* only capture SPDIF over AK4114 */
  418. return snd_ak4114_build(spec->ak4114, NULL,
  419. ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  420. }
  421. /*
  422. * suspend/resume
  423. * */
  424. #ifdef CONFIG_PM_SLEEP
  425. static int juli_resume(struct snd_ice1712 *ice)
  426. {
  427. struct snd_akm4xxx *ak = ice->akm;
  428. struct juli_spec *spec = ice->spec;
  429. /* akm4358 un-reset, un-mute */
  430. snd_akm4xxx_reset(ak, 0);
  431. /* reinit ak4114 */
  432. snd_ak4114_resume(spec->ak4114);
  433. return 0;
  434. }
  435. static int juli_suspend(struct snd_ice1712 *ice)
  436. {
  437. struct snd_akm4xxx *ak = ice->akm;
  438. struct juli_spec *spec = ice->spec;
  439. /* akm4358 reset and soft-mute */
  440. snd_akm4xxx_reset(ak, 1);
  441. snd_ak4114_suspend(spec->ak4114);
  442. return 0;
  443. }
  444. #endif
  445. /*
  446. * initialize the chip
  447. */
  448. static inline int juli_is_spdif_master(struct snd_ice1712 *ice)
  449. {
  450. return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1;
  451. }
  452. static unsigned int juli_get_rate(struct snd_ice1712 *ice)
  453. {
  454. int i;
  455. unsigned char result;
  456. result = ice->gpio.get_data(ice) & GPIO_RATE_MASK;
  457. for (i = 0; i < ARRAY_SIZE(gpio_vals); i++)
  458. if (gpio_vals[i] == result)
  459. return juli_rates[i];
  460. return 0;
  461. }
  462. /* setting new rate */
  463. static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
  464. {
  465. unsigned int old, new;
  466. unsigned char val;
  467. old = ice->gpio.get_data(ice);
  468. new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
  469. /* dev_dbg(ice->card->dev, "JULI - set_rate: old %x, new %x\n",
  470. old & GPIO_RATE_MASK,
  471. new & GPIO_RATE_MASK); */
  472. ice->gpio.set_data(ice, new);
  473. /* switching to external clock - supplied by external circuits */
  474. val = inb(ICEMT1724(ice, RATE));
  475. outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
  476. }
  477. static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
  478. unsigned int rate)
  479. {
  480. /* no change in master clock */
  481. return 0;
  482. }
  483. /* setting clock to external - SPDIF */
  484. static int juli_set_spdif_clock(struct snd_ice1712 *ice, int type)
  485. {
  486. unsigned int old;
  487. old = ice->gpio.get_data(ice);
  488. /* external clock (= 0), multiply 1x, 48kHz */
  489. ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
  490. GPIO_FREQ_48KHZ);
  491. return 0;
  492. }
  493. /* Called when ak4114 detects change in the input SPDIF stream */
  494. static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
  495. unsigned char c1)
  496. {
  497. struct snd_ice1712 *ice = ak4114->change_callback_private;
  498. int rate;
  499. if (ice->is_spdif_master(ice) && c1) {
  500. /* only for SPDIF master mode, rate was changed */
  501. rate = snd_ak4114_external_rate(ak4114);
  502. /* dev_dbg(ice->card->dev, "ak4114 - input rate changed to %d\n",
  503. rate); */
  504. juli_akm_set_rate_val(ice->akm, rate);
  505. }
  506. }
  507. static int juli_init(struct snd_ice1712 *ice)
  508. {
  509. static const unsigned char ak4114_init_vals[] = {
  510. /* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN |
  511. AK4114_OCKS0 | AK4114_OCKS1,
  512. /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S,
  513. /* AK4114_REG_IO0 */ AK4114_TX1E,
  514. /* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT |
  515. AK4114_IPS(1),
  516. /* AK4114_REG_INT0_MASK */ 0,
  517. /* AK4114_REG_INT1_MASK */ 0
  518. };
  519. static const unsigned char ak4114_init_txcsb[] = {
  520. 0x41, 0x02, 0x2c, 0x00, 0x00
  521. };
  522. int err;
  523. struct juli_spec *spec;
  524. struct snd_akm4xxx *ak;
  525. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  526. if (!spec)
  527. return -ENOMEM;
  528. ice->spec = spec;
  529. err = snd_ak4114_create(ice->card,
  530. juli_ak4114_read,
  531. juli_ak4114_write,
  532. ak4114_init_vals, ak4114_init_txcsb,
  533. ice, &spec->ak4114);
  534. if (err < 0)
  535. return err;
  536. /* callback for codecs rate setting */
  537. spec->ak4114->change_callback = juli_ak4114_change;
  538. spec->ak4114->change_callback_private = ice;
  539. /* AK4114 in Juli can detect external rate correctly */
  540. spec->ak4114->check_flags = 0;
  541. #if 0
  542. /*
  543. * it seems that the analog doughter board detection does not work reliably, so
  544. * force the analog flag; it should be very rare (if ever) to come at Juli@
  545. * used without the analog daughter board
  546. */
  547. spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1;
  548. #else
  549. spec->analog = 1;
  550. #endif
  551. if (spec->analog) {
  552. dev_info(ice->card->dev, "juli@: analog I/O detected\n");
  553. ice->num_total_dacs = 2;
  554. ice->num_total_adcs = 2;
  555. ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  556. ak = ice->akm;
  557. if (!ak)
  558. return -ENOMEM;
  559. ice->akm_codecs = 1;
  560. err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice);
  561. if (err < 0)
  562. return err;
  563. }
  564. /* juli is clocked by Xilinx array */
  565. ice->hw_rates = &juli_rates_info;
  566. ice->is_spdif_master = juli_is_spdif_master;
  567. ice->get_rate = juli_get_rate;
  568. ice->set_rate = juli_set_rate;
  569. ice->set_mclk = juli_set_mclk;
  570. ice->set_spdif_clock = juli_set_spdif_clock;
  571. ice->spdif.ops.open = juli_spdif_in_open;
  572. #ifdef CONFIG_PM_SLEEP
  573. ice->pm_resume = juli_resume;
  574. ice->pm_suspend = juli_suspend;
  575. ice->pm_suspend_enabled = 1;
  576. #endif
  577. return 0;
  578. }
  579. /*
  580. * Juli@ boards don't provide the EEPROM data except for the vendor IDs.
  581. * hence the driver needs to sets up it properly.
  582. */
  583. static const unsigned char juli_eeprom[] = {
  584. [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, 1xADC, 1xDACs,
  585. SPDIF in */
  586. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  587. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  588. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  589. [ICE_EEP2_GPIO_DIR] = 0x9f, /* 5, 6:inputs; 7, 4-0 outputs*/
  590. [ICE_EEP2_GPIO_DIR1] = 0xff,
  591. [ICE_EEP2_GPIO_DIR2] = 0x7f,
  592. [ICE_EEP2_GPIO_MASK] = 0x60, /* 5, 6: locked; 7, 4-0 writable */
  593. [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0-7 writable */
  594. [ICE_EEP2_GPIO_MASK2] = 0x7f,
  595. [ICE_EEP2_GPIO_STATE] = GPIO_FREQ_48KHZ | GPIO_MULTI_1X |
  596. GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/
  597. [ICE_EEP2_GPIO_STATE1] = 0x00, /* unmuted */
  598. [ICE_EEP2_GPIO_STATE2] = 0x00,
  599. };
  600. /* entry point */
  601. struct snd_ice1712_card_info snd_vt1724_juli_cards[] = {
  602. {
  603. .subvendor = VT1724_SUBDEVICE_JULI,
  604. .name = "ESI Juli@",
  605. .model = "juli",
  606. .chip_init = juli_init,
  607. .build_controls = juli_add_controls,
  608. .eeprom_size = sizeof(juli_eeprom),
  609. .eeprom_data = juli_eeprom,
  610. },
  611. { } /* terminator */
  612. };