juli.c 20 KB

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