blob: bf98ea34feb04b1a65992db370fadd79dc25105f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Takashi Iwaiab0c7d72005-11-17 15:00:18 +010036static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 /* assert PRST# to converters; MT05 bit 7 */
39 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
40 mdelay(5);
41 /* deassert PRST# */
42 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
43}
44
45/*
46 * change the rate of envy24HT, AK4355 and AK4381
47 */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +010048static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 unsigned char old, tmp, dfs;
51 int reg, shift;
52
53 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
54 return;
55
56 /* adjust DFS on codecs */
57 if (rate > 96000)
58 dfs = 2;
59 else if (rate > 48000)
60 dfs = 1;
61 else
62 dfs = 0;
63
Takashi Iwai59acf762005-12-05 19:22:34 +010064 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 reg = 2;
66 shift = 4;
67 } else {
68 reg = 1;
69 shift = 3;
70 }
71 tmp = snd_akm4xxx_get(ak, 0, reg);
72 old = (tmp >> shift) & 0x03;
73 if (old == dfs)
74 return;
75
76 /* reset DFS */
77 snd_akm4xxx_reset(ak, 1);
78 tmp = snd_akm4xxx_get(ak, 0, reg);
79 tmp &= ~(0x03 << shift);
80 tmp |= dfs << shift;
81 // snd_akm4xxx_write(ak, 0, reg, tmp);
82 snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */
83 snd_akm4xxx_reset(ak, 0);
84}
85
86/*
87 * initialize the chips on M-Audio Revolution cards
88 */
89
Takashi Iwai723b2b02006-08-30 16:49:54 +020090#define AK_DAC(xname,xch) { .name = xname, .num_channels = xch }
Jani Alinikulac83c0c42006-06-27 15:00:55 +020091
Takashi Iwai723b2b02006-08-30 16:49:54 +020092static struct snd_akm4xxx_dac_channel revo71_front[] = {
93 AK_DAC("PCM Playback Volume", 2)
94};
Jani Alinikulac83c0c42006-06-27 15:00:55 +020095
Takashi Iwai723b2b02006-08-30 16:49:54 +020096static struct snd_akm4xxx_dac_channel revo71_surround[] = {
97 AK_DAC("PCM Center Playback Volume", 1),
98 AK_DAC("PCM LFE Playback Volume", 1),
99 AK_DAC("PCM Side Playback Volume", 2),
100 AK_DAC("PCM Rear Playback Volume", 2),
101};
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200102
Takashi Iwai723b2b02006-08-30 16:49:54 +0200103static struct snd_akm4xxx_dac_channel revo51_dac[] = {
104 AK_DAC("PCM Playback Volume", 2),
105 AK_DAC("PCM Center Playback Volume", 1),
106 AK_DAC("PCM LFE Playback Volume", 1),
107 AK_DAC("PCM Rear Playback Volume", 2),
108};
109
110static struct snd_akm4xxx_adc_channel revo51_adc[] = {
111 {
112 .name = "PCM Capture Volume",
Takashi Iwai723b2b02006-08-30 16:49:54 +0200113 .switch_name = "PCM Capture Switch",
114 .num_channels = 2
115 },
116};
Jochen Voss96d9e932006-08-08 21:13:42 +0200117
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100118static struct snd_akm4xxx akm_revo_front __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .type = SND_AK4381,
120 .num_dacs = 2,
121 .ops = {
122 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200123 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200124 .dac_info = revo71_front,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
128 .caddr = 1,
129 .cif = 0,
130 .data_mask = VT1724_REVO_CDOUT,
131 .clk_mask = VT1724_REVO_CCLK,
132 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
133 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
134 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
135 .add_flags = VT1724_REVO_CCLK, /* high at init */
136 .mask_flags = 0,
137};
138
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100139static struct snd_akm4xxx akm_revo_surround __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .type = SND_AK4355,
141 .idx_offset = 1,
142 .num_dacs = 6,
143 .ops = {
144 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200145 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200146 .dac_info = revo71_surround,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
150 .caddr = 3,
151 .cif = 0,
152 .data_mask = VT1724_REVO_CDOUT,
153 .clk_mask = VT1724_REVO_CCLK,
154 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
155 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1,
156 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
157 .add_flags = VT1724_REVO_CCLK, /* high at init */
158 .mask_flags = 0,
159};
160
Takashi Iwai59acf762005-12-05 19:22:34 +0100161static struct snd_akm4xxx akm_revo51 __devinitdata = {
162 .type = SND_AK4358,
163 .num_dacs = 6,
164 .ops = {
165 .set_rate_val = revo_set_rate_val
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200166 },
Takashi Iwai723b2b02006-08-30 16:49:54 +0200167 .dac_info = revo51_dac,
Takashi Iwai59acf762005-12-05 19:22:34 +0100168};
169
170static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = {
171 .caddr = 2,
172 .cif = 0,
173 .data_mask = VT1724_REVO_CDOUT,
174 .clk_mask = VT1724_REVO_CCLK,
175 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
Jochen Voss96d9e932006-08-08 21:13:42 +0200176 .cs_addr = VT1724_REVO_CS1 | VT1724_REVO_CS2,
177 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
178 .add_flags = VT1724_REVO_CCLK, /* high at init */
179 .mask_flags = 0,
180};
181
182static struct snd_akm4xxx akm_revo51_adc __devinitdata = {
183 .type = SND_AK5365,
184 .num_adcs = 2,
Takashi Iwai723b2b02006-08-30 16:49:54 +0200185 .adc_info = revo51_adc,
Jochen Voss96d9e932006-08-08 21:13:42 +0200186};
187
188static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = {
189 .caddr = 2,
190 .cif = 0,
191 .data_mask = VT1724_REVO_CDOUT,
192 .clk_mask = VT1724_REVO_CCLK,
193 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
194 .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2,
Takashi Iwai59acf762005-12-05 19:22:34 +0100195 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2,
196 .add_flags = VT1724_REVO_CCLK, /* high at init */
197 .mask_flags = 0,
198};
199
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100200static int __devinit revo_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100202 struct snd_akm4xxx *ak;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 int err;
204
205 /* determine I2C, DACs and ADCs */
206 switch (ice->eeprom.subvendor) {
207 case VT1724_SUBDEVICE_REVOLUTION71:
208 ice->num_total_dacs = 8;
209 ice->num_total_adcs = 2;
Takashi Iwai59acf762005-12-05 19:22:34 +0100210 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
211 break;
212 case VT1724_SUBDEVICE_REVOLUTION51:
213 ice->num_total_dacs = 6;
214 ice->num_total_adcs = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 break;
216 default:
217 snd_BUG();
218 return -EINVAL;
219 }
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* second stage of initialization, analog parts and others */
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100222 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (! ak)
224 return -ENOMEM;
225 ice->akm_codecs = 2;
226 switch (ice->eeprom.subvendor) {
227 case VT1724_SUBDEVICE_REVOLUTION71:
Takashi Iwai59acf762005-12-05 19:22:34 +0100228 ice->akm_codecs = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0)
230 return err;
231 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0)
232 return err;
233 /* unmute all codecs */
234 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
235 break;
Takashi Iwai59acf762005-12-05 19:22:34 +0100236 case VT1724_SUBDEVICE_REVOLUTION51:
Jochen Voss96d9e932006-08-08 21:13:42 +0200237 ice->akm_codecs = 2;
Takashi Iwai59acf762005-12-05 19:22:34 +0100238 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo51, &akm_revo51_priv, ice)) < 0)
239 return err;
Jochen Voss96d9e932006-08-08 21:13:42 +0200240 err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo51_adc,
241 &akm_revo51_adc_priv, ice);
242 if (err < 0)
243 return err;
Takashi Iwai59acf762005-12-05 19:22:34 +0100244 /* unmute all codecs - needed! */
245 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
246 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return 0;
250}
251
252
Takashi Iwaiab0c7d72005-11-17 15:00:18 +0100253static int __devinit revo_add_controls(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 int err;
256
257 switch (ice->eeprom.subvendor) {
258 case VT1724_SUBDEVICE_REVOLUTION71:
Takashi Iwai59acf762005-12-05 19:22:34 +0100259 case VT1724_SUBDEVICE_REVOLUTION51:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 err = snd_ice1712_akm4xxx_build_controls(ice);
261 if (err < 0)
262 return err;
263 }
264 return 0;
265}
266
267/* entry point */
268struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = {
269 {
270 .subvendor = VT1724_SUBDEVICE_REVOLUTION71,
271 .name = "M Audio Revolution-7.1",
272 .model = "revo71",
273 .chip_init = revo_init,
274 .build_controls = revo_add_controls,
275 },
Takashi Iwai59acf762005-12-05 19:22:34 +0100276 {
277 .subvendor = VT1724_SUBDEVICE_REVOLUTION51,
278 .name = "M Audio Revolution-5.1",
279 .model = "revo51",
280 .chip_init = revo_init,
281 .build_controls = revo_add_controls,
282 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 { } /* terminator */
284};