revo.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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(ice1712_t *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(akm4xxx_t *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) {
  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 akm4xxx_t 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 akm4xxx_t 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 int __devinit revo_init(ice1712_t *ice)
  118. {
  119. akm4xxx_t *ak;
  120. int err;
  121. /* determine I2C, DACs and ADCs */
  122. switch (ice->eeprom.subvendor) {
  123. case VT1724_SUBDEVICE_REVOLUTION71:
  124. ice->num_total_dacs = 8;
  125. ice->num_total_adcs = 2;
  126. break;
  127. default:
  128. snd_BUG();
  129. return -EINVAL;
  130. }
  131. ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
  132. /* second stage of initialization, analog parts and others */
  133. ak = ice->akm = kcalloc(2, sizeof(akm4xxx_t), GFP_KERNEL);
  134. if (! ak)
  135. return -ENOMEM;
  136. ice->akm_codecs = 2;
  137. switch (ice->eeprom.subvendor) {
  138. case VT1724_SUBDEVICE_REVOLUTION71:
  139. if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
  140. return err;
  141. if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
  142. return err;
  143. /* unmute all codecs */
  144. snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  145. break;
  146. }
  147. return 0;
  148. }
  149. static int __devinit revo_add_controls(ice1712_t *ice)
  150. {
  151. int err;
  152. switch (ice->eeprom.subvendor) {
  153. case VT1724_SUBDEVICE_REVOLUTION71:
  154. err = snd_ice1712_akm4xxx_build_controls(ice);
  155. if (err < 0)
  156. return err;
  157. }
  158. return 0;
  159. }
  160. /* entry point */
  161. struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
  162. {
  163. .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
  164. .name = "M Audio Revolution-7.1",
  165. .model = "revo71",
  166. .chip_init = revo_init,
  167. .build_controls = revo_add_controls,
  168. },
  169. { } /* terminator */
  170. };