juli.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <asm/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <sound/core.h>
  30. #include "ice1712.h"
  31. #include "envy24ht.h"
  32. #include "juli.h"
  33. /*
  34. * chip addresses on I2C bus
  35. */
  36. #define AK4114_ADDR 0x20 /* S/PDIF receiver */
  37. #define AK4358_ADDR 0x22 /* DAC */
  38. /*
  39. * GPIO pins
  40. */
  41. #define GPIO_FREQ_MASK (3<<0)
  42. #define GPIO_FREQ_32KHZ (0<<0)
  43. #define GPIO_FREQ_44KHZ (1<<0)
  44. #define GPIO_FREQ_48KHZ (2<<0)
  45. #define GPIO_MULTI_MASK (3<<2)
  46. #define GPIO_MULTI_4X (0<<2)
  47. #define GPIO_MULTI_2X (1<<2)
  48. #define GPIO_MULTI_1X (2<<2) /* also external */
  49. #define GPIO_MULTI_HALF (3<<2)
  50. #define GPIO_INTERNAL_CLOCK (1<<4)
  51. #define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
  52. #define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
  53. #define GPIO_AK5385A_CKS0 (1<<8)
  54. #define GPIO_AK5385A_DFS0 (1<<9) /* swapped with DFS1 according doc? */
  55. #define GPIO_AK5385A_DFS1 (1<<10)
  56. #define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
  57. #define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
  58. #define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
  59. #define GPIO_AK5385A_MCLK (1<<14) /* must be 0 */
  60. #define GPIO_MUTE_CONTROL (1<<15) /* 0 = off, 1 = on */
  61. static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val)
  62. {
  63. snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg, val);
  64. }
  65. static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
  66. {
  67. return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg);
  68. }
  69. /*
  70. * AK4358 section
  71. */
  72. static void juli_akm_lock(struct snd_akm4xxx *ak, int chip)
  73. {
  74. }
  75. static void juli_akm_unlock(struct snd_akm4xxx *ak, int chip)
  76. {
  77. }
  78. static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
  79. unsigned char addr, unsigned char data)
  80. {
  81. struct snd_ice1712 *ice = ak->private_data[0];
  82. snd_assert(chip == 0, return);
  83. snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data);
  84. }
  85. /*
  86. * change the rate of envy24HT, AK4358
  87. */
  88. static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  89. {
  90. unsigned char old, tmp, dfs;
  91. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  92. return;
  93. /* adjust DFS on codecs */
  94. if (rate > 96000)
  95. dfs = 2;
  96. else if (rate > 48000)
  97. dfs = 1;
  98. else
  99. dfs = 0;
  100. tmp = snd_akm4xxx_get(ak, 0, 2);
  101. old = (tmp >> 4) & 0x03;
  102. if (old == dfs)
  103. return;
  104. /* reset DFS */
  105. snd_akm4xxx_reset(ak, 1);
  106. tmp = snd_akm4xxx_get(ak, 0, 2);
  107. tmp &= ~(0x03 << 4);
  108. tmp |= dfs << 4;
  109. snd_akm4xxx_set(ak, 0, 2, tmp);
  110. snd_akm4xxx_reset(ak, 0);
  111. }
  112. static struct snd_akm4xxx akm_juli_dac __devinitdata = {
  113. .type = SND_AK4358,
  114. .num_dacs = 2,
  115. .ops = {
  116. .lock = juli_akm_lock,
  117. .unlock = juli_akm_unlock,
  118. .write = juli_akm_write,
  119. .set_rate_val = juli_akm_set_rate_val
  120. }
  121. };
  122. static int __devinit juli_add_controls(struct snd_ice1712 *ice)
  123. {
  124. int err;
  125. err = snd_ice1712_akm4xxx_build_controls(ice);
  126. if (err < 0)
  127. return err;
  128. /* only capture SPDIF over AK4114 */
  129. err = snd_ak4114_build(ice->spec.juli.ak4114, NULL,
  130. ice->pcm_pro->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
  131. if (err < 0)
  132. return err;
  133. return 0;
  134. }
  135. /*
  136. * initialize the chip
  137. */
  138. static int __devinit juli_init(struct snd_ice1712 *ice)
  139. {
  140. static const unsigned char ak4114_init_vals[] = {
  141. /* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
  142. /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S,
  143. /* AK4114_REG_IO0 */ AK4114_TX1E,
  144. /* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1),
  145. /* AK4114_REG_INT0_MASK */ 0,
  146. /* AK4114_REG_INT1_MASK */ 0
  147. };
  148. static const unsigned char ak4114_init_txcsb[] = {
  149. 0x41, 0x02, 0x2c, 0x00, 0x00
  150. };
  151. int err;
  152. struct snd_akm4xxx *ak;
  153. err = snd_ak4114_create(ice->card,
  154. juli_ak4114_read,
  155. juli_ak4114_write,
  156. ak4114_init_vals, ak4114_init_txcsb,
  157. ice, &ice->spec.juli.ak4114);
  158. if (err < 0)
  159. return err;
  160. #if 0
  161. /* it seems that the analog doughter board detection does not work
  162. reliably, so force the analog flag; it should be very rare
  163. to use Juli@ without the analog doughter board */
  164. ice->spec.juli.analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1;
  165. #else
  166. ice->spec.juli.analog = 1;
  167. #endif
  168. if (ice->spec.juli.analog) {
  169. printk(KERN_INFO "juli@: analog I/O detected\n");
  170. ice->num_total_dacs = 2;
  171. ice->num_total_adcs = 2;
  172. ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
  173. if (! ak)
  174. return -ENOMEM;
  175. ice->akm_codecs = 1;
  176. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice)) < 0)
  177. return err;
  178. }
  179. return 0;
  180. }
  181. /*
  182. * Juli@ boards don't provide the EEPROM data except for the vendor IDs.
  183. * hence the driver needs to sets up it properly.
  184. */
  185. static unsigned char juli_eeprom[] __devinitdata = {
  186. [ICE_EEP2_SYSCONF] = 0x20, /* clock 512, mpu401, 1xADC, 1xDACs */
  187. [ICE_EEP2_ACLINK] = 0x80, /* I2S */
  188. [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
  189. [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
  190. [ICE_EEP2_GPIO_DIR] = 0x9f,
  191. [ICE_EEP2_GPIO_DIR1] = 0xff,
  192. [ICE_EEP2_GPIO_DIR2] = 0x7f,
  193. [ICE_EEP2_GPIO_MASK] = 0x9f,
  194. [ICE_EEP2_GPIO_MASK1] = 0xff,
  195. [ICE_EEP2_GPIO_MASK2] = 0x7f,
  196. [ICE_EEP2_GPIO_STATE] = 0x16, /* internal clock, multiple 1x, 48kHz */
  197. [ICE_EEP2_GPIO_STATE1] = 0x80, /* mute */
  198. [ICE_EEP2_GPIO_STATE2] = 0x00,
  199. };
  200. /* entry point */
  201. struct snd_ice1712_card_info snd_vt1724_juli_cards[] __devinitdata = {
  202. {
  203. .subvendor = VT1724_SUBDEVICE_JULI,
  204. .name = "ESI Juli@",
  205. .model = "juli",
  206. .chip_init = juli_init,
  207. .build_controls = juli_add_controls,
  208. .eeprom_size = sizeof(juli_eeprom),
  209. .eeprom_data = juli_eeprom,
  210. },
  211. { } /* terminator */
  212. };