patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / pci / ice1712 / revo.c
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
24 #include <sound/driver.h>
25 #include <asm/io.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31
32 #include "ice1712.h"
33 #include "envy24ht.h"
34 #include "revo.h"
35
36 /*
37  * change the rate of envy24HT, AK4355 and AK4381
38  */
39 static void revo_set_rate_val(akm4xxx_t *ak, unsigned int rate)
40 {
41         unsigned char old, tmp, dfs;
42         int reg, shift;
43
44         if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
45                 return;
46
47         /* adjust DFS on codecs */
48         if (rate > 96000)
49                 dfs = 2;
50         else if (rate > 48000)
51                 dfs = 1;
52         else
53                 dfs = 0;
54
55         if (ak->type == SND_AK4355) {
56                 reg = 2;
57                 shift = 4;
58         } else {
59                 reg = 1;
60                 shift = 3;
61         }
62         tmp = snd_akm4xxx_get(ak, 0, reg);
63         old = (tmp >> shift) & 0x03;
64         if (old == dfs)
65                 return;
66
67         /* reset DFS */
68         snd_akm4xxx_reset(ak, 1);
69         tmp = snd_akm4xxx_get(ak, 0, reg);
70         tmp &= ~(0x03 << shift);
71         tmp |= dfs << shift;
72         // snd_akm4xxx_write(ak, 0, reg, tmp);
73         snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
74         snd_akm4xxx_reset(ak, 0);
75 }
76
77 /*
78  * initialize the chips on M-Audio Revolution cards
79  */
80
81 static akm4xxx_t akm_revo_front __devinitdata = {
82         .type = SND_AK4381,
83         .num_dacs = 2,
84         .ops = {
85                 .set_rate_val = revo_set_rate_val
86         }
87 };
88
89 static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
90         .caddr = 1,
91         .cif = 0,
92         .data_mask = VT1724_REVO_CDOUT,
93         .clk_mask = VT1724_REVO_CCLK,
94         .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
95         .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
96         .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
97         .add_flags = VT1724_REVO_CCLK, /* high at init */
98         .mask_flags = 0,
99 };
100
101 static akm4xxx_t akm_revo_surround __devinitdata = {
102         .type = SND_AK4355,
103         .idx_offset = 1,
104         .num_dacs = 6,
105         .ops = {
106                 .set_rate_val = revo_set_rate_val
107         }
108 };
109
110 static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
111         .caddr = 3,
112         .cif = 0,
113         .data_mask = VT1724_REVO_CDOUT,
114         .clk_mask = VT1724_REVO_CCLK,
115         .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
116         .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
117         .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
118         .add_flags = VT1724_REVO_CCLK, /* high at init */
119         .mask_flags = 0,
120 };
121
122 static int __devinit revo_init(ice1712_t *ice)
123 {
124         akm4xxx_t *ak;
125         int err;
126
127         /* determine I2C, DACs and ADCs */
128         switch (ice->eeprom.subvendor) {
129         case VT1724_SUBDEVICE_REVOLUTION71:
130                 ice->num_total_dacs = 8;
131                 ice->num_total_adcs = 4;
132                 break;
133         default:
134                 snd_BUG();
135                 return -EINVAL;
136         }
137
138         /* second stage of initialization, analog parts and others */
139         ak = ice->akm = snd_kcalloc(sizeof(akm4xxx_t) * 2, GFP_KERNEL);
140         if (! ak)
141                 return -ENOMEM;
142         ice->akm_codecs = 2;
143         switch (ice->eeprom.subvendor) {
144         case VT1724_SUBDEVICE_REVOLUTION71:
145                 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
146                         return err;
147                 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
148                         return err;
149                 /* unmute all codecs */
150                 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
151                 break;
152         }
153
154         return 0;
155 }
156
157
158 static int __devinit revo_add_controls(ice1712_t *ice)
159 {
160         int err;
161
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
171 /* entry point */
172 struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
173         {
174                 .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
175                 .name = "M Audio Revolution-7.1",
176                 .model = "revo71",
177                 .chip_init = revo_init,
178                 .build_controls = revo_add_controls,
179         },
180         { } /* terminator */
181 };