Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALSA driver for ICEnsemble ICE1712 (Envy24) |
| 3 | * |
Vedran Miletic | cc67b7f | 2008-09-07 12:00:02 +0200 | [diff] [blame] | 4 | * Lowlevel functions for M-Audio Audiophile 192, Revolution 7.1 and 5.1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/delay.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <sound/core.h> |
| 29 | |
| 30 | #include "ice1712.h" |
| 31 | #include "envy24ht.h" |
| 32 | #include "revo.h" |
| 33 | |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 34 | /* a non-standard I2C device for revo51 */ |
| 35 | struct revo51_spec { |
| 36 | struct snd_i2c_device *dev; |
| 37 | struct snd_pt2258 *pt2258; |
Harvey Harrison | 008f359 | 2008-02-29 11:46:32 +0100 | [diff] [blame] | 38 | }; |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 39 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 40 | static void revo_i2s_mclk_changed(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | /* assert PRST# to converters; MT05 bit 7 */ |
| 43 | outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD)); |
| 44 | mdelay(5); |
| 45 | /* deassert PRST# */ |
| 46 | outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD)); |
| 47 | } |
| 48 | |
| 49 | /* |
Vedran Miletic | cc67b7f | 2008-09-07 12:00:02 +0200 | [diff] [blame] | 50 | * change the rate of Envy24HT, AK4355 and AK4381 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 52 | 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] | 53 | { |
| 54 | unsigned char old, tmp, dfs; |
| 55 | int reg, shift; |
| 56 | |
| 57 | if (rate == 0) /* no hint - S/PDIF input is master, simply return */ |
| 58 | return; |
| 59 | |
| 60 | /* adjust DFS on codecs */ |
| 61 | if (rate > 96000) |
| 62 | dfs = 2; |
| 63 | else if (rate > 48000) |
| 64 | dfs = 1; |
| 65 | else |
| 66 | dfs = 0; |
| 67 | |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 68 | if (ak->type == SND_AK4355 || ak->type == SND_AK4358) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | reg = 2; |
| 70 | shift = 4; |
| 71 | } else { |
| 72 | reg = 1; |
| 73 | shift = 3; |
| 74 | } |
| 75 | tmp = snd_akm4xxx_get(ak, 0, reg); |
| 76 | old = (tmp >> shift) & 0x03; |
| 77 | if (old == dfs) |
| 78 | return; |
| 79 | |
| 80 | /* reset DFS */ |
| 81 | snd_akm4xxx_reset(ak, 1); |
| 82 | tmp = snd_akm4xxx_get(ak, 0, reg); |
| 83 | tmp &= ~(0x03 << shift); |
| 84 | tmp |= dfs << shift; |
Vedran Miletic | cc67b7f | 2008-09-07 12:00:02 +0200 | [diff] [blame] | 85 | /* snd_akm4xxx_write(ak, 0, reg, tmp); */ |
| 86 | snd_akm4xxx_set(ak, 0, reg, tmp); /* value is written in reset(0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | snd_akm4xxx_reset(ak, 0); |
| 88 | } |
| 89 | |
| 90 | /* |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 91 | * I2C access to the PT2258 volume controller on GPIO 6/7 (Revolution 5.1) |
| 92 | */ |
| 93 | |
| 94 | static void revo_i2c_start(struct snd_i2c_bus *bus) |
| 95 | { |
| 96 | struct snd_ice1712 *ice = bus->private_data; |
| 97 | snd_ice1712_save_gpio_status(ice); |
| 98 | } |
| 99 | |
| 100 | static void revo_i2c_stop(struct snd_i2c_bus *bus) |
| 101 | { |
| 102 | struct snd_ice1712 *ice = bus->private_data; |
| 103 | snd_ice1712_restore_gpio_status(ice); |
| 104 | } |
| 105 | |
| 106 | static void revo_i2c_direction(struct snd_i2c_bus *bus, int clock, int data) |
| 107 | { |
| 108 | struct snd_ice1712 *ice = bus->private_data; |
| 109 | unsigned int mask, val; |
| 110 | |
| 111 | val = 0; |
| 112 | if (clock) |
| 113 | val |= VT1724_REVO_I2C_CLOCK; /* write SCL */ |
| 114 | if (data) |
| 115 | val |= VT1724_REVO_I2C_DATA; /* write SDA */ |
| 116 | mask = VT1724_REVO_I2C_CLOCK | VT1724_REVO_I2C_DATA; |
| 117 | ice->gpio.direction &= ~mask; |
| 118 | ice->gpio.direction |= val; |
| 119 | snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); |
| 120 | snd_ice1712_gpio_set_mask(ice, ~mask); |
| 121 | } |
| 122 | |
| 123 | static void revo_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data) |
| 124 | { |
| 125 | struct snd_ice1712 *ice = bus->private_data; |
| 126 | unsigned int val = 0; |
| 127 | |
| 128 | if (clk) |
| 129 | val |= VT1724_REVO_I2C_CLOCK; |
| 130 | if (data) |
| 131 | val |= VT1724_REVO_I2C_DATA; |
| 132 | snd_ice1712_gpio_write_bits(ice, |
| 133 | VT1724_REVO_I2C_DATA | |
| 134 | VT1724_REVO_I2C_CLOCK, val); |
| 135 | udelay(5); |
| 136 | } |
| 137 | |
| 138 | static int revo_i2c_getdata(struct snd_i2c_bus *bus, int ack) |
| 139 | { |
| 140 | struct snd_ice1712 *ice = bus->private_data; |
| 141 | int bit; |
| 142 | |
| 143 | if (ack) |
| 144 | udelay(5); |
| 145 | bit = snd_ice1712_gpio_read_bits(ice, VT1724_REVO_I2C_DATA) ? 1 : 0; |
| 146 | return bit; |
| 147 | } |
| 148 | |
| 149 | static struct snd_i2c_bit_ops revo51_bit_ops = { |
| 150 | .start = revo_i2c_start, |
| 151 | .stop = revo_i2c_stop, |
| 152 | .direction = revo_i2c_direction, |
| 153 | .setlines = revo_i2c_setlines, |
| 154 | .getdata = revo_i2c_getdata, |
| 155 | }; |
| 156 | |
| 157 | static int revo51_i2c_init(struct snd_ice1712 *ice, |
| 158 | struct snd_pt2258 *pt) |
| 159 | { |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 160 | struct revo51_spec *spec; |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 161 | int err; |
| 162 | |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 163 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 164 | if (!spec) |
| 165 | return -ENOMEM; |
| 166 | ice->spec = spec; |
| 167 | |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 168 | /* create the I2C bus */ |
| 169 | err = snd_i2c_bus_create(ice->card, "ICE1724 GPIO6", NULL, &ice->i2c); |
| 170 | if (err < 0) |
| 171 | return err; |
| 172 | |
| 173 | ice->i2c->private_data = ice; |
| 174 | ice->i2c->hw_ops.bit = &revo51_bit_ops; |
| 175 | |
| 176 | /* create the I2C device */ |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 177 | err = snd_i2c_device_create(ice->i2c, "PT2258", 0x40, &spec->dev); |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 178 | if (err < 0) |
| 179 | return err; |
| 180 | |
| 181 | pt->card = ice->card; |
| 182 | pt->i2c_bus = ice->i2c; |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 183 | pt->i2c_dev = spec->dev; |
| 184 | spec->pt2258 = pt; |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 185 | |
| 186 | snd_pt2258_reset(pt); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * initialize the chips on M-Audio Revolution cards |
| 193 | */ |
| 194 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 195 | #define AK_DAC(xname,xch) { .name = xname, .num_channels = xch } |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 196 | |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 197 | static const struct snd_akm4xxx_dac_channel revo71_front[] = { |
Pavel Hofman | ea7cfcd | 2007-05-19 17:21:04 +0200 | [diff] [blame] | 198 | { |
| 199 | .name = "PCM Playback Volume", |
| 200 | .num_channels = 2, |
| 201 | /* front channels DAC supports muting */ |
| 202 | .switch_name = "PCM Playback Switch", |
| 203 | }, |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 204 | }; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 205 | |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 206 | static const struct snd_akm4xxx_dac_channel revo71_surround[] = { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 207 | AK_DAC("PCM Center Playback Volume", 1), |
| 208 | AK_DAC("PCM LFE Playback Volume", 1), |
| 209 | AK_DAC("PCM Side Playback Volume", 2), |
| 210 | AK_DAC("PCM Rear Playback Volume", 2), |
| 211 | }; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 212 | |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 213 | static const struct snd_akm4xxx_dac_channel revo51_dac[] = { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 214 | AK_DAC("PCM Playback Volume", 2), |
| 215 | AK_DAC("PCM Center Playback Volume", 1), |
| 216 | AK_DAC("PCM LFE Playback Volume", 1), |
| 217 | AK_DAC("PCM Rear Playback Volume", 2), |
Alexander Beregalov | 46480b3 | 2008-08-21 08:28:42 +0400 | [diff] [blame] | 218 | AK_DAC("PCM Headphone Volume", 2), |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 221 | static const char *revo51_adc_input_names[] = { |
| 222 | "Mic", |
| 223 | "Line", |
| 224 | "CD", |
| 225 | NULL |
| 226 | }; |
| 227 | |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 228 | static const struct snd_akm4xxx_adc_channel revo51_adc[] = { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 229 | { |
| 230 | .name = "PCM Capture Volume", |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 231 | .switch_name = "PCM Capture Switch", |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 232 | .num_channels = 2, |
| 233 | .input_names = revo51_adc_input_names |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 234 | }, |
| 235 | }; |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 236 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 237 | static struct snd_akm4xxx akm_revo_front = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | .type = SND_AK4381, |
| 239 | .num_dacs = 2, |
| 240 | .ops = { |
| 241 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 242 | }, |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 243 | .dac_info = revo71_front, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 246 | static struct snd_ak4xxx_private akm_revo_front_priv = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | .caddr = 1, |
| 248 | .cif = 0, |
| 249 | .data_mask = VT1724_REVO_CDOUT, |
| 250 | .clk_mask = VT1724_REVO_CCLK, |
| 251 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 252 | .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS2, |
| 253 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 254 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 255 | .mask_flags = 0, |
| 256 | }; |
| 257 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 258 | static struct snd_akm4xxx akm_revo_surround = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | .type = SND_AK4355, |
| 260 | .idx_offset = 1, |
| 261 | .num_dacs = 6, |
| 262 | .ops = { |
| 263 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 264 | }, |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 265 | .dac_info = revo71_surround, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 268 | static struct snd_ak4xxx_private akm_revo_surround_priv = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | .caddr = 3, |
| 270 | .cif = 0, |
| 271 | .data_mask = VT1724_REVO_CDOUT, |
| 272 | .clk_mask = VT1724_REVO_CCLK, |
| 273 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 274 | .cs_addr = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
| 275 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1 | VT1724_REVO_CS2, |
| 276 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 277 | .mask_flags = 0, |
| 278 | }; |
| 279 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 280 | static struct snd_akm4xxx akm_revo51 = { |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 281 | .type = SND_AK4358, |
Alexander Beregalov | 46480b3 | 2008-08-21 08:28:42 +0400 | [diff] [blame] | 282 | .num_dacs = 8, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 283 | .ops = { |
| 284 | .set_rate_val = revo_set_rate_val |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 285 | }, |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 286 | .dac_info = revo51_dac, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 287 | }; |
| 288 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 289 | static struct snd_ak4xxx_private akm_revo51_priv = { |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 290 | .caddr = 2, |
| 291 | .cif = 0, |
| 292 | .data_mask = VT1724_REVO_CDOUT, |
| 293 | .clk_mask = VT1724_REVO_CCLK, |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 294 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
| 295 | .cs_addr = VT1724_REVO_CS1, |
| 296 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 297 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 298 | .mask_flags = 0, |
| 299 | }; |
| 300 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 301 | static struct snd_akm4xxx akm_revo51_adc = { |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 302 | .type = SND_AK5365, |
| 303 | .num_adcs = 2, |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 304 | .adc_info = revo51_adc, |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 305 | }; |
| 306 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 307 | static struct snd_ak4xxx_private akm_revo51_adc_priv = { |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 308 | .caddr = 2, |
| 309 | .cif = 0, |
| 310 | .data_mask = VT1724_REVO_CDOUT, |
| 311 | .clk_mask = VT1724_REVO_CCLK, |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 312 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
| 313 | .cs_addr = VT1724_REVO_CS0, |
| 314 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 315 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 316 | .mask_flags = 0, |
| 317 | }; |
| 318 | |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 319 | static struct snd_pt2258 ptc_revo51_volume; |
| 320 | |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 321 | /* AK4358 for AP192 DAC, AK5385A for ADC */ |
| 322 | static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) |
| 323 | { |
| 324 | struct snd_ice1712 *ice = ak->private_data[0]; |
Takashi Iwai | a769692 | 2008-02-04 12:36:32 +0100 | [diff] [blame] | 325 | int dfs; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 326 | |
| 327 | revo_set_rate_val(ak, rate); |
| 328 | |
Takashi Iwai | a769692 | 2008-02-04 12:36:32 +0100 | [diff] [blame] | 329 | /* reset CKS */ |
Karsten Wiese | 8a87c9c | 2008-04-22 12:53:12 +0200 | [diff] [blame] | 330 | snd_ice1712_gpio_write_bits(ice, 1 << 8, rate > 96000 ? 1 << 8 : 0); |
Takashi Iwai | a769692 | 2008-02-04 12:36:32 +0100 | [diff] [blame] | 331 | /* reset DFS pins of AK5385A for ADC, too */ |
| 332 | if (rate > 96000) |
| 333 | dfs = 2; |
| 334 | else if (rate > 48000) |
| 335 | dfs = 1; |
| 336 | else |
| 337 | dfs = 0; |
| 338 | snd_ice1712_gpio_write_bits(ice, 3 << 9, dfs << 9); |
| 339 | /* reset ADC */ |
| 340 | snd_ice1712_gpio_write_bits(ice, 1 << 11, 0); |
Karsten Wiese | 8a87c9c | 2008-04-22 12:53:12 +0200 | [diff] [blame] | 341 | snd_ice1712_gpio_write_bits(ice, 1 << 11, 1 << 11); |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 344 | static const struct snd_akm4xxx_dac_channel ap192_dac[] = { |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 345 | AK_DAC("PCM Playback Volume", 2) |
| 346 | }; |
| 347 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 348 | static struct snd_akm4xxx akm_ap192 = { |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 349 | .type = SND_AK4358, |
| 350 | .num_dacs = 2, |
| 351 | .ops = { |
| 352 | .set_rate_val = ap192_set_rate_val |
| 353 | }, |
| 354 | .dac_info = ap192_dac, |
| 355 | }; |
| 356 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 357 | static struct snd_ak4xxx_private akm_ap192_priv = { |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 358 | .caddr = 2, |
| 359 | .cif = 0, |
| 360 | .data_mask = VT1724_REVO_CDOUT, |
| 361 | .clk_mask = VT1724_REVO_CCLK, |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 362 | .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
| 363 | .cs_addr = VT1724_REVO_CS1, |
| 364 | .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1, |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 365 | .add_flags = VT1724_REVO_CCLK, /* high at init */ |
| 366 | .mask_flags = 0, |
| 367 | }; |
| 368 | |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 369 | /* AK4114 support on Audiophile 192 */ |
| 370 | /* CDTO (pin 32) -- GPIO2 pin 52 |
| 371 | * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358) |
| 372 | * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358) |
| 373 | * CSN (pin 35) -- GPIO7 pin 59 |
| 374 | */ |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 375 | #define AK4114_ADDR 0x02 |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 376 | |
| 377 | static void write_data(struct snd_ice1712 *ice, unsigned int gpio, |
| 378 | unsigned int data, int idx) |
| 379 | { |
| 380 | for (; idx >= 0; idx--) { |
| 381 | /* drop clock */ |
| 382 | gpio &= ~VT1724_REVO_CCLK; |
| 383 | snd_ice1712_gpio_write(ice, gpio); |
| 384 | udelay(1); |
| 385 | /* set data */ |
| 386 | if (data & (1 << idx)) |
| 387 | gpio |= VT1724_REVO_CDOUT; |
| 388 | else |
| 389 | gpio &= ~VT1724_REVO_CDOUT; |
| 390 | snd_ice1712_gpio_write(ice, gpio); |
| 391 | udelay(1); |
| 392 | /* raise clock */ |
| 393 | gpio |= VT1724_REVO_CCLK; |
| 394 | snd_ice1712_gpio_write(ice, gpio); |
| 395 | udelay(1); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio, |
| 400 | int idx) |
| 401 | { |
| 402 | unsigned char data = 0; |
| 403 | |
| 404 | for (; idx >= 0; idx--) { |
| 405 | /* drop clock */ |
| 406 | gpio &= ~VT1724_REVO_CCLK; |
| 407 | snd_ice1712_gpio_write(ice, gpio); |
| 408 | udelay(1); |
| 409 | /* read data */ |
| 410 | if (snd_ice1712_gpio_read(ice) & VT1724_REVO_CDIN) |
| 411 | data |= (1 << idx); |
| 412 | udelay(1); |
| 413 | /* raise clock */ |
| 414 | gpio |= VT1724_REVO_CCLK; |
| 415 | snd_ice1712_gpio_write(ice, gpio); |
| 416 | udelay(1); |
| 417 | } |
| 418 | return data; |
| 419 | } |
| 420 | |
Takashi Iwai | c052f04 | 2007-03-29 12:34:15 +0200 | [diff] [blame] | 421 | static unsigned int ap192_4wire_start(struct snd_ice1712 *ice) |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 422 | { |
| 423 | unsigned int tmp; |
| 424 | |
| 425 | snd_ice1712_save_gpio_status(ice); |
| 426 | tmp = snd_ice1712_gpio_read(ice); |
| 427 | tmp |= VT1724_REVO_CCLK; /* high at init */ |
| 428 | tmp |= VT1724_REVO_CS0; |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 429 | tmp &= ~VT1724_REVO_CS1; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 430 | snd_ice1712_gpio_write(ice, tmp); |
| 431 | udelay(1); |
| 432 | return tmp; |
| 433 | } |
| 434 | |
| 435 | static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp) |
| 436 | { |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 437 | tmp |= VT1724_REVO_CS1; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 438 | tmp |= VT1724_REVO_CS0; |
| 439 | snd_ice1712_gpio_write(ice, tmp); |
| 440 | udelay(1); |
| 441 | snd_ice1712_restore_gpio_status(ice); |
| 442 | } |
| 443 | |
| 444 | static void ap192_ak4114_write(void *private_data, unsigned char addr, |
| 445 | unsigned char data) |
| 446 | { |
| 447 | struct snd_ice1712 *ice = private_data; |
| 448 | unsigned int tmp, addrdata; |
| 449 | |
| 450 | tmp = ap192_4wire_start(ice); |
| 451 | addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f); |
| 452 | addrdata = (addrdata << 8) | data; |
| 453 | write_data(ice, tmp, addrdata, 15); |
| 454 | ap192_4wire_finish(ice, tmp); |
| 455 | } |
| 456 | |
| 457 | static unsigned char ap192_ak4114_read(void *private_data, unsigned char addr) |
| 458 | { |
| 459 | struct snd_ice1712 *ice = private_data; |
| 460 | unsigned int tmp; |
| 461 | unsigned char data; |
| 462 | |
| 463 | tmp = ap192_4wire_start(ice); |
| 464 | write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7); |
| 465 | data = read_data(ice, tmp, 7); |
| 466 | ap192_4wire_finish(ice, tmp); |
| 467 | return data; |
| 468 | } |
| 469 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 470 | static int ap192_ak4114_init(struct snd_ice1712 *ice) |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 471 | { |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 472 | static const unsigned char ak4114_init_vals[] = { |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 473 | AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1, |
| 474 | AK4114_DIF_I24I2S, |
| 475 | AK4114_TX1E, |
| 476 | AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1), |
| 477 | 0, |
| 478 | 0 |
| 479 | }; |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 480 | static const unsigned char ak4114_init_txcsb[] = { |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 481 | 0x41, 0x02, 0x2c, 0x00, 0x00 |
| 482 | }; |
| 483 | struct ak4114 *ak; |
| 484 | int err; |
| 485 | |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 486 | err = snd_ak4114_create(ice->card, |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 487 | ap192_ak4114_read, |
| 488 | ap192_ak4114_write, |
| 489 | ak4114_init_vals, ak4114_init_txcsb, |
| 490 | ice, &ak); |
Pavel Hofman | 841b23d | 2008-03-17 08:45:33 +0100 | [diff] [blame] | 491 | /* AK4114 in Revo cannot detect external rate correctly. |
| 492 | * No reason to stop capture stream due to incorrect checks */ |
| 493 | ak->check_flags = AK4114_CHECK_NO_RATE; |
| 494 | |
Takashi Iwai | f339eb0 | 2008-02-04 12:34:59 +0100 | [diff] [blame] | 495 | return 0; /* error ignored; it's no fatal error */ |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 496 | } |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 497 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 498 | static int revo_init(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 500 | struct snd_akm4xxx *ak; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | int err; |
| 502 | |
| 503 | /* determine I2C, DACs and ADCs */ |
| 504 | switch (ice->eeprom.subvendor) { |
| 505 | case VT1724_SUBDEVICE_REVOLUTION71: |
| 506 | ice->num_total_dacs = 8; |
| 507 | ice->num_total_adcs = 2; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 508 | ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed; |
| 509 | break; |
| 510 | case VT1724_SUBDEVICE_REVOLUTION51: |
Alexander Beregalov | 46480b3 | 2008-08-21 08:28:42 +0400 | [diff] [blame] | 511 | ice->num_total_dacs = 8; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 512 | ice->num_total_adcs = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | break; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 514 | case VT1724_SUBDEVICE_AUDIOPHILE192: |
| 515 | ice->num_total_dacs = 2; |
| 516 | ice->num_total_adcs = 2; |
| 517 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | default: |
| 519 | snd_BUG(); |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* second stage of initialization, analog parts and others */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 524 | ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | if (! ak) |
| 526 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | switch (ice->eeprom.subvendor) { |
| 528 | case VT1724_SUBDEVICE_REVOLUTION71: |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 529 | ice->akm_codecs = 2; |
Alexander Beregalov | faa09c9 | 2008-08-11 02:09:04 +0400 | [diff] [blame] | 530 | err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, |
| 531 | &akm_revo_front_priv, ice); |
| 532 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return err; |
Alexander Beregalov | faa09c9 | 2008-08-11 02:09:04 +0400 | [diff] [blame] | 534 | err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo_surround, |
| 535 | &akm_revo_surround_priv, ice); |
| 536 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return err; |
| 538 | /* unmute all codecs */ |
Alexander Beregalov | faa09c9 | 2008-08-11 02:09:04 +0400 | [diff] [blame] | 539 | snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, |
| 540 | VT1724_REVO_MUTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | break; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 542 | case VT1724_SUBDEVICE_REVOLUTION51: |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 543 | ice->akm_codecs = 2; |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 544 | err = snd_ice1712_akm4xxx_init(ak, &akm_revo51, |
| 545 | &akm_revo51_priv, ice); |
| 546 | if (err < 0) |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 547 | return err; |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 548 | err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo51_adc, |
Jochen Voss | 96d9e93 | 2006-08-08 21:13:42 +0200 | [diff] [blame] | 549 | &akm_revo51_adc_priv, ice); |
| 550 | if (err < 0) |
| 551 | return err; |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 552 | err = revo51_i2c_init(ice, &ptc_revo51_volume); |
| 553 | if (err < 0) |
| 554 | return err; |
| 555 | /* unmute all codecs */ |
| 556 | snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, |
| 557 | VT1724_REVO_MUTE); |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 558 | break; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 559 | case VT1724_SUBDEVICE_AUDIOPHILE192: |
| 560 | ice->akm_codecs = 1; |
| 561 | err = snd_ice1712_akm4xxx_init(ak, &akm_ap192, &akm_ap192_priv, |
| 562 | ice); |
| 563 | if (err < 0) |
| 564 | return err; |
| 565 | |
Takashi Iwai | a769692 | 2008-02-04 12:36:32 +0100 | [diff] [blame] | 566 | /* unmute all codecs */ |
| 567 | snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, |
| 568 | VT1724_REVO_MUTE); |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 569 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 576 | static int revo_add_controls(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 578 | struct revo51_spec *spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | int err; |
| 580 | |
| 581 | switch (ice->eeprom.subvendor) { |
| 582 | case VT1724_SUBDEVICE_REVOLUTION71: |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 583 | err = snd_ice1712_akm4xxx_build_controls(ice); |
| 584 | if (err < 0) |
| 585 | return err; |
| 586 | break; |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 587 | case VT1724_SUBDEVICE_REVOLUTION51: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | err = snd_ice1712_akm4xxx_build_controls(ice); |
| 589 | if (err < 0) |
| 590 | return err; |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 591 | spec = ice->spec; |
| 592 | err = snd_pt2258_build_controls(spec->pt2258); |
Jochen Voss | feaa6a7 | 2006-10-04 18:08:43 +0200 | [diff] [blame] | 593 | if (err < 0) |
| 594 | return err; |
| 595 | break; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 596 | case VT1724_SUBDEVICE_AUDIOPHILE192: |
| 597 | err = snd_ice1712_akm4xxx_build_controls(ice); |
| 598 | if (err < 0) |
| 599 | return err; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 600 | err = ap192_ak4114_init(ice); |
| 601 | if (err < 0) |
| 602 | return err; |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 603 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | /* entry point */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame^] | 609 | struct snd_ice1712_card_info snd_vt1724_revo_cards[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | .subvendor = VT1724_SUBDEVICE_REVOLUTION71, |
| 612 | .name = "M Audio Revolution-7.1", |
| 613 | .model = "revo71", |
| 614 | .chip_init = revo_init, |
| 615 | .build_controls = revo_add_controls, |
| 616 | }, |
Takashi Iwai | 59acf76 | 2005-12-05 19:22:34 +0100 | [diff] [blame] | 617 | { |
| 618 | .subvendor = VT1724_SUBDEVICE_REVOLUTION51, |
| 619 | .name = "M Audio Revolution-5.1", |
| 620 | .model = "revo51", |
| 621 | .chip_init = revo_init, |
| 622 | .build_controls = revo_add_controls, |
| 623 | }, |
Takashi Iwai | 5625506 | 2006-11-09 16:47:26 +0100 | [diff] [blame] | 624 | { |
| 625 | .subvendor = VT1724_SUBDEVICE_AUDIOPHILE192, |
| 626 | .name = "M Audio Audiophile192", |
| 627 | .model = "ap192", |
| 628 | .chip_init = revo_init, |
| 629 | .build_controls = revo_add_controls, |
| 630 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { } /* terminator */ |
| 632 | }; |