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