Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 36 | static void revo_i2s_mclk_changed(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 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 Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 48 | static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 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 Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 64 | if (ak->type == SND_AK4355 || ak->type == SND_AK4358) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | 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 | |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 90 | static unsigned int revo71_num_stereo_front[] = {2}; |
| 91 | static char *revo71_channel_names_front[] = {"PCM Playback Volume"}; |
| 92 | |
| 93 | static unsigned int revo71_num_stereo_surround[] = {1, 1, 2, 2}; |
| 94 | static char *revo71_channel_names_surround[] = {"PCM Center Playback Volume", "PCM LFE Playback Volume", |
| 95 | "PCM Side Playback Volume", "PCM Rear Playback Volume"}; |
| 96 | |
| 97 | static unsigned int revo51_num_stereo[] = {2, 1, 1, 2}; |
| 98 | static char *revo51_channel_names[] = {"PCM Playback Volume", "PCM Center Playback Volume", |
| 99 | "PCM LFE Playback Volume", "PCM Rear Playback Volume"}; |
| 100 | |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame^] | 101 | static unsigned int revo51_adc_num_stereo[] = {2}; |
| 102 | static char *revo51_adc_channel_names[] = {"PCM Capture Volume"}; |
| 103 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 104 | static struct snd_akm4xxx akm_revo_front __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .type = SND_AK4381, |
| 106 | .num_dacs = 2, |
| 107 | .ops = { |
| 108 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 109 | }, |
| 110 | .num_stereo = revo71_num_stereo_front, |
| 111 | .channel_names = revo71_channel_names_front |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = { |
| 115 | .caddr = 1, |
| 116 | .cif = 0, |
| 117 | .data_mask = VT1724_REVO_CDOUT, |
| 118 | .clk_mask = VT1724_REVO_CCLK, |
| 119 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 120 | .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2, |
| 121 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 122 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 123 | .mask_flags = 0, |
| 124 | }; |
| 125 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 126 | static struct snd_akm4xxx akm_revo_surround __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | .type = SND_AK4355, |
| 128 | .idx_offset = 1, |
| 129 | .num_dacs = 6, |
| 130 | .ops = { |
| 131 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 132 | }, |
| 133 | .num_stereo = revo71_num_stereo_surround, |
| 134 | .channel_names = revo71_channel_names_surround |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = { |
| 138 | .caddr = 3, |
| 139 | .cif = 0, |
| 140 | .data_mask = VT1724_REVO_CDOUT, |
| 141 | .clk_mask = VT1724_REVO_CCLK, |
| 142 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 143 | .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
| 144 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 145 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 146 | .mask_flags = 0, |
| 147 | }; |
| 148 | |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 149 | static struct snd_akm4xxx akm_revo51 __devinitdata = { |
| 150 | .type = SND_AK4358, |
| 151 | .num_dacs = 6, |
| 152 | .ops = { |
| 153 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 154 | }, |
| 155 | .num_stereo = revo51_num_stereo, |
| 156 | .channel_names = revo51_channel_names |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static struct snd_ak4xxx_private akm_revo51_priv __devinitdata = { |
| 160 | .caddr = 2, |
| 161 | .cif = 0, |
| 162 | .data_mask = VT1724_REVO_CDOUT, |
| 163 | .clk_mask = VT1724_REVO_CCLK, |
| 164 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame^] | 165 | .cs_addr = VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 166 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 167 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 168 | .mask_flags = 0, |
| 169 | }; |
| 170 | |
| 171 | static struct snd_akm4xxx akm_revo51_adc __devinitdata = { |
| 172 | .type = SND_AK5365, |
| 173 | .num_adcs = 2, |
| 174 | .num_stereo = revo51_adc_num_stereo, |
| 175 | .channel_names = revo51_adc_channel_names |
| 176 | }; |
| 177 | |
| 178 | static struct snd_ak4xxx_private akm_revo51_adc_priv __devinitdata = { |
| 179 | .caddr = 2, |
| 180 | .cif = 0, |
| 181 | .data_mask = VT1724_REVO_CDOUT, |
| 182 | .clk_mask = VT1724_REVO_CCLK, |
| 183 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 184 | .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 185 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 186 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 187 | .mask_flags = 0, |
| 188 | }; |
| 189 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 190 | static int __devinit revo_init(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 192 | struct snd_akm4xxx *ak; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int err; |
| 194 | |
| 195 | /* determine I2C, DACs and ADCs */ |
| 196 | switch (ice->eeprom.subvendor) { |
| 197 | case VT1724_SUBDEVICE_REVOLUTION71: |
| 198 | ice->num_total_dacs = 8; |
| 199 | ice->num_total_adcs = 2; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 200 | ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed; |
| 201 | break; |
| 202 | case VT1724_SUBDEVICE_REVOLUTION51: |
| 203 | ice->num_total_dacs = 6; |
| 204 | ice->num_total_adcs = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | break; |
| 206 | default: |
| 207 | snd_BUG(); |
| 208 | return -EINVAL; |
| 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* second stage of initialization, analog parts and others */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 212 | ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | if (! ak) |
| 214 | return -ENOMEM; |
| 215 | ice->akm_codecs = 2; |
| 216 | switch (ice->eeprom.subvendor) { |
| 217 | case VT1724_SUBDEVICE_REVOLUTION71: |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 218 | ice->akm_codecs = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0) |
| 220 | return err; |
| 221 | if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0) |
| 222 | return err; |
| 223 | /* unmute all codecs */ |
| 224 | snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE); |
| 225 | break; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 226 | case VT1724_SUBDEVICE_REVOLUTION51: |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame^] | 227 | ice->akm_codecs = 2; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 228 | if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo51, &akm_revo51_priv, ice)) < 0) |
| 229 | return err; |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame^] | 230 | err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo51_adc, |
| 231 | &akm_revo51_adc_priv, ice); |
| 232 | if (err < 0) |
| 233 | return err; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 234 | /* unmute all codecs - needed! */ |
| 235 | snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE); |
| 236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 243 | static int __devinit revo_add_controls(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | int err; |
| 246 | |
| 247 | switch (ice->eeprom.subvendor) { |
| 248 | case VT1724_SUBDEVICE_REVOLUTION71: |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 249 | case VT1724_SUBDEVICE_REVOLUTION51: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | err = snd_ice1712_akm4xxx_build_controls(ice); |
| 251 | if (err < 0) |
| 252 | return err; |
| 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /* entry point */ |
| 258 | struct snd_ice1712_card_info snd_vt1724_revo_cards[] __devinitdata = { |
| 259 | { |
| 260 | .subvendor = VT1724_SUBDEVICE_REVOLUTION71, |
| 261 | .name = "M Audio Revolution-7.1", |
| 262 | .model = "revo71", |
| 263 | .chip_init = revo_init, |
| 264 | .build_controls = revo_add_controls, |
| 265 | }, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 266 | { |
| 267 | .subvendor = VT1724_SUBDEVICE_REVOLUTION51, |
| 268 | .name = "M Audio Revolution-5.1", |
| 269 | .model = "revo51", |
| 270 | .chip_init = revo_init, |
| 271 | .build_controls = revo_add_controls, |
| 272 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { } /* terminator */ |
| 274 | }; |