revo.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 struct snd_akm4xxx akm_revo_front __devinitdata = {
  81. .type = SND_AK4381,
  82. .num_dacs = 2,
  83. .ops = {
  84. .set_rate_val = revo_set_rate_val
  85. }
  86. };
  87. static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
  88. .caddr = 1,
  89. .cif = 0,
  90. .data_mask = VT1724_REVO_CDOUT,
  91. .clk_mask = VT1724_REVO_CCLK,
  92. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  93. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
  94. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  95. .add_flags = VT1724_REVO_CCLK, /* high at init */
  96. .mask_flags = 0,
  97. };
  98. static struct snd_akm4xxx akm_revo_surround __devinitdata = {
  99. .type = SND_AK4355,
  100. .idx_offset = 1,
  101. .num_dacs = 6,
  102. .ops = {
  103. .set_rate_val = revo_set_rate_val
  104. }
  105. };
  106. static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
  107. .caddr = 3,
  108. .cif = 0,
  109. .data_mask = VT1724_REVO_CDOUT,
  110. .clk_mask = VT1724_REVO_CCLK,
  111. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  112. .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
  113. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  114. .add_flags = VT1724_REVO_CCLK, /* high at init */
  115. .mask_flags = 0,
  116. };
  117. static struct snd_akm4xxx akm_revo51 __devinitdata = {
  118. .type = SND_AK4358,
  119. .num_dacs = 6,
  120. .ops = {
  121. .set_rate_val = revo_set_rate_val
  122. }
  123. };
  124. static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
  125. .caddr = 2,
  126. .cif = 0,
  127. .data_mask = VT1724_REVO_CDOUT,
  128. .clk_mask = VT1724_REVO_CCLK,
  129. .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  130. .cs_addr = 0,
  131. .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
  132. .add_flags = VT1724_REVO_CCLK, /* high at init */
  133. .mask_flags = 0,
  134. };
  135. static int __devinit revo_init(struct snd_ice1712 *ice)
  136. {
  137. struct snd_akm4xxx *ak;
  138. int err;
  139. /* determine I2C, DACs and ADCs */
  140. switch (ice->eeprom.subvendor) {
  141. case VT1724_SUBDEVICE_REVOLUTION71:
  142. ice->num_total_dacs = 8;
  143. ice->num_total_adcs = 2;
  144. ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
  145. break;
  146. case VT1724_SUBDEVICE_REVOLUTION51:
  147. ice->num_total_dacs = 6;
  148. ice->num_total_adcs = 2;
  149. break;
  150. default:
  151. snd_BUG();
  152. return -EINVAL;
  153. }
  154. /* second stage of initialization, analog parts and others */
  155. ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
  156. if (! ak)
  157. return -ENOMEM;
  158. ice->akm_codecs = 2;
  159. switch (ice->eeprom.subvendor) {
  160. case VT1724_SUBDEVICE_REVOLUTION71:
  161. ice->akm_codecs = 2;
  162. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
  163. return err;
  164. if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
  165. return err;
  166. /* unmute all codecs */
  167. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  168. break;
  169. case VT1724_SUBDEVICE_REVOLUTION51:
  170. ice->akm_codecs = 1;
  171. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo51, &akm_revo51_priv, ice)) < 0)
  172. return err;
  173. /* unmute all codecs - needed! */
  174. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  175. break;
  176. }
  177. return 0;
  178. }
  179. static int __devinit revo_add_controls(struct snd_ice1712 *ice)
  180. {
  181. int err;
  182. switch (ice->eeprom.subvendor) {
  183. case VT1724_SUBDEVICE_REVOLUTION71:
  184. case VT1724_SUBDEVICE_REVOLUTION51:
  185. err = snd_ice1712_akm4xxx_build_controls(ice);
  186. if (err < 0)
  187. return err;
  188. }
  189. return 0;
  190. }
  191. /* entry point */
  192. struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
  193. {
  194. .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
  195. .name = "M Audio Revolution-7.1",
  196. .model = "revo71",
  197. .chip_init = revo_init,
  198. .build_controls = revo_add_controls,
  199. },
  200. {
  201. .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
  202. .name = "M Audio Revolution-5.1",
  203. .model = "revo51",
  204. .chip_init = revo_init,
  205. .build_controls = revo_add_controls,
  206. },
  207. { } /* terminator */
  208. };