revo.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Lowlevel functions for M-Audio Revolution 7.1
  5. *
  6. * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
  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 "revo.h"
  33. static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
  34. {
  35. /* assert PRST# to converters; MT05 bit 7 */
  36. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  37. mdelay(5);
  38. /* deassert PRST# */
  39. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  40. }
  41. /*
  42. * change the rate of envy24HT, AK4355 and AK4381
  43. */
  44. static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
  45. {
  46. unsigned char old, tmp, dfs;
  47. int reg, shift;
  48. if (rate == 0) /* no hint - S/PDIF input is master, simply return */
  49. return;
  50. /* adjust DFS on codecs */
  51. if (rate > 96000)
  52. dfs = 2;
  53. else if (rate > 48000)
  54. dfs = 1;
  55. else
  56. dfs = 0;
  57. if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
  58. reg = 2;
  59. shift = 4;
  60. } else {
  61. reg = 1;
  62. shift = 3;
  63. }
  64. tmp = snd_akm4xxx_get(ak, 0, reg);
  65. old = (tmp >> shift) & 0x03;
  66. if (old == dfs)
  67. return;
  68. /* reset DFS */
  69. snd_akm4xxx_reset(ak, 1);
  70. tmp = snd_akm4xxx_get(ak, 0, reg);
  71. tmp &= ~(0x03 << shift);
  72. tmp |= dfs << shift;
  73. // snd_akm4xxx_write(ak, 0, reg, tmp);
  74. snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
  75. snd_akm4xxx_reset(ak, 0);
  76. }
  77. /*
  78. * initialize the chips on M-Audio Revolution cards
  79. */
  80. static unsigned int revo71_num_stereo_front[] = {2};
  81. static char *revo71_channel_names_front[] = {"PCM Playback Volume"};
  82. static unsigned int revo71_num_stereo_surround[] = {1, 1, 2, 2};
  83. static char *revo71_channel_names_surround[] = {"PCM Center Playback Volume", "PCM LFE Playback Volume",
  84. "PCM Side Playback Volume", "PCM Rear Playback Volume"};
  85. static unsigned int revo51_num_stereo[] = {2, 1, 1, 2};
  86. static char *revo51_channel_names[] = {"PCM Playback Volume", "PCM Center Playback Volume",
  87. "PCM LFE Playback Volume", "PCM Rear Playback Volume"};
  88. static struct snd_akm4xxx akm_revo_front __devinitdata = {
  89. .type = SND_AK4381,
  90. .num_dacs = 2,
  91. .ops = {
  92. .set_rate_val = revo_set_rate_val
  93. },
  94. .num_stereo = revo71_num_stereo_front,
  95. .channel_names = revo71_channel_names_front
  96. };
  97. static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
  98. .caddr = 1,
  99. .cif = 0,
  100. .data_mask = VT1724_REVO_CDOUT,
  101. .clk_mask = VT1724_REVO_CCLK,
  102. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  103. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
  104. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  105. .add_flags = VT1724_REVO_CCLK, /* high at init */
  106. .mask_flags = 0,
  107. };
  108. static struct snd_akm4xxx akm_revo_surround __devinitdata = {
  109. .type = SND_AK4355,
  110. .idx_offset = 1,
  111. .num_dacs = 6,
  112. .ops = {
  113. .set_rate_val = revo_set_rate_val
  114. },
  115. .num_stereo = revo71_num_stereo_surround,
  116. .channel_names = revo71_channel_names_surround
  117. };
  118. static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
  119. .caddr = 3,
  120. .cif = 0,
  121. .data_mask = VT1724_REVO_CDOUT,
  122. .clk_mask = VT1724_REVO_CCLK,
  123. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  124. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  125. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  126. .add_flags = VT1724_REVO_CCLK, /* high at init */
  127. .mask_flags = 0,
  128. };
  129. static struct snd_akm4xxx akm_revo51 __devinitdata = {
  130. .type = SND_AK4358,
  131. .num_dacs = 6,
  132. .ops = {
  133. .set_rate_val = revo_set_rate_val
  134. },
  135. .num_stereo = revo51_num_stereo,
  136. .channel_names = revo51_channel_names
  137. };
  138. static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
  139. .caddr = 2,
  140. .cif = 0,
  141. .data_mask = VT1724_REVO_CDOUT,
  142. .clk_mask = VT1724_REVO_CCLK,
  143. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  144. .cs_addr = 0,
  145. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  146. .add_flags = VT1724_REVO_CCLK, /* high at init */
  147. .mask_flags = 0,
  148. };
  149. static int __devinit revo_init(struct snd_ice1712 *ice)
  150. {
  151. struct snd_akm4xxx *ak;
  152. int err;
  153. /* determine I2C, DACs and ADCs */
  154. switch (ice->eeprom.subvendor) {
  155. case VT1724_SUBDEVICE_REVOLUTION71:
  156. ice->num_total_dacs = 8;
  157. ice->num_total_adcs = 2;
  158. ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
  159. break;
  160. case VT1724_SUBDEVICE_REVOLUTION51:
  161. ice->num_total_dacs = 6;
  162. ice->num_total_adcs = 2;
  163. break;
  164. default:
  165. snd_BUG();
  166. return -EINVAL;
  167. }
  168. /* second stage of initialization, analog parts and others */
  169. ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
  170. if (! ak)
  171. return -ENOMEM;
  172. ice->akm_codecs = 2;
  173. switch (ice->eeprom.subvendor) {
  174. case VT1724_SUBDEVICE_REVOLUTION71:
  175. ice->akm_codecs = 2;
  176. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
  177. return err;
  178. if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
  179. return err;
  180. /* unmute all codecs */
  181. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  182. break;
  183. case VT1724_SUBDEVICE_REVOLUTION51:
  184. ice->akm_codecs = 1;
  185. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo51, &akm_revo51_priv, ice)) < 0)
  186. return err;
  187. /* unmute all codecs - needed! */
  188. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  189. break;
  190. }
  191. return 0;
  192. }
  193. static int __devinit revo_add_controls(struct snd_ice1712 *ice)
  194. {
  195. int err;
  196. switch (ice->eeprom.subvendor) {
  197. case VT1724_SUBDEVICE_REVOLUTION71:
  198. case VT1724_SUBDEVICE_REVOLUTION51:
  199. err = snd_ice1712_akm4xxx_build_controls(ice);
  200. if (err < 0)
  201. return err;
  202. }
  203. return 0;
  204. }
  205. /* entry point */
  206. struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
  207. {
  208. .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
  209. .name = "M Audio Revolution-7.1",
  210. .model = "revo71",
  211. .chip_init = revo_init,
  212. .build_controls = revo_add_controls,
  213. },
  214. {
  215. .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
  216. .name = "M Audio Revolution-5.1",
  217. .model = "revo51",
  218. .chip_init = revo_init,
  219. .build_controls = revo_add_controls,
  220. },
  221. { } /* terminator */
  222. };