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