revo.c 5.1 KB

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