Changeset 72
- Timestamp:
- Jan 14, 2006, 7:08:01 PM (20 years ago)
- Location:
- GPL/trunk/alsa-kernel/pci/ac97
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/alsa-kernel/pci/ac97/ac97_codec.c
r32 r72 28 28 #include <linux/slab.h> 29 29 #include <linux/pci.h> 30 #include <linux/moduleparam.h> 30 31 #include <sound/core.h> 31 32 #include <sound/pcm.h> … … 43 44 static int enable_loopback; 44 45 45 MODULE_PARM(enable_loopback, "i");46 //module_param(enable_loopback, bool, 0444); 46 47 MODULE_PARM_DESC(enable_loopback, "Enable AC97 ADC/DAC Loopback Control"); 47 MODULE_PARM_SYNTAX(enable_loopback, SNDRV_BOOLEAN_FALSE_DESC);48 48 49 49 /* … … 51 51 */ 52 52 53 typedef struct{53 struct ac97_codec_id { 54 54 unsigned int id; 55 55 unsigned int mask; 56 56 const char *name; 57 int (*patch)( ac97_t*ac97);58 int (*mpatch)(ac97_t*ac97);59 60 } ac97_codec_id_t;61 62 static const ac97_codec_id_tsnd_ac97_codec_id_vendors[] = {57 int (*patch)(struct snd_ac97 *ac97); 58 int (*mpatch)(struct snd_ac97 *ac97); 59 unsigned int flags; 60 }; 61 62 static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = { 63 63 { 0x414b4d00, 0xffffff00, "Asahi Kasei", NULL, NULL }, 64 64 { 0x41445300, 0xffffff00, "Analog Devices", NULL, NULL }, … … 87 87 }; 88 88 89 static const ac97_codec_id_tsnd_ac97_codec_ids[] = {89 static const struct ac97_codec_id snd_ac97_codec_ids[] = { 90 90 { 0x414b4d00, 0xffffffff, "AK4540", NULL, NULL }, 91 91 { 0x414b4d01, 0xffffffff, "AK4542", NULL, NULL }, … … 100 100 { 0x41445362, 0xffffffff, "AD1887", patch_ad1881, NULL }, 101 101 { 0x41445363, 0xffffffff, "AD1886A", patch_ad1881, NULL }, 102 { 0x41445368, 0xffffffff, "AD1888", patch_ad1888,NULL },102 { 0x41445368, 0xffffffff, "AD1888", patch_ad1888, NULL }, 103 103 { 0x41445370, 0xffffffff, "AD1980", patch_ad1980, NULL }, 104 104 { 0x41445372, 0xffffffff, "AD1981A", patch_ad1981a, NULL }, 105 105 { 0x41445374, 0xffffffff, "AD1981B", patch_ad1981b, NULL }, 106 106 { 0x41445375, 0xffffffff, "AD1985", patch_ad1985, NULL }, 107 { 0x41445378, 0xffffffff, "AD1986", patch_ad1985,NULL },108 { 0x414c4300, 0xffffff00, "ALC100 /100P", NULL,NULL },109 { 0x414c4710, 0xfffffff0, "ALC200 /200P", NULL, NULL },110 { 0x414c4721, 0xffffffff, "ALC650D", NULL,NULL }, /* already patched */111 { 0x414c4722, 0xffffffff, "ALC650E", NULL,NULL }, /* already patched */112 { 0x414c4723, 0xffffffff, "ALC650F", NULL,NULL }, /* already patched */107 { 0x41445378, 0xffffffff, "AD1986", patch_ad1985, NULL }, 108 { 0x414c4300, 0xffffff00, "ALC100,100P", NULL, NULL }, 109 { 0x414c4710, 0xfffffff0, "ALC200,200P", NULL, NULL }, 110 { 0x414c4721, 0xffffffff, "ALC650D", NULL, NULL }, /* already patched */ 111 { 0x414c4722, 0xffffffff, "ALC650E", NULL, NULL }, /* already patched */ 112 { 0x414c4723, 0xffffffff, "ALC650F", NULL, NULL }, /* already patched */ 113 113 { 0x414c4720, 0xfffffff0, "ALC650", patch_alc650, NULL }, 114 114 { 0x414c4760, 0xfffffff0, "ALC655", patch_alc655, NULL }, 115 { 0x414c4781, 0xffffffff, "ALC658D", NULL,NULL }, /* already patched */115 { 0x414c4781, 0xffffffff, "ALC658D", NULL, NULL }, /* already patched */ 116 116 { 0x414c4780, 0xfffffff0, "ALC658", patch_alc655, NULL }, 117 { 0x414c4790, 0xfffffff0, "ALC850", patch_alc850,NULL },117 { 0x414c4790, 0xfffffff0, "ALC850", patch_alc850, NULL }, 118 118 { 0x414c4730, 0xffffffff, "ALC101", NULL, NULL }, 119 119 { 0x414c4740, 0xfffffff0, "ALC202", NULL, NULL }, … … 122 122 { 0x434d4941, 0xffffffff, "CMI9738", patch_cm9738, NULL }, 123 123 { 0x434d4961, 0xffffffff, "CMI9739", patch_cm9739, NULL }, 124 { 0x434d4969, 0xffffffff, "CMI9780", patch_cm9780,NULL },125 { 0x434d4978, 0xffffffff, "CMI9761", patch_cm9761,NULL },126 { 0x434d4982, 0xffffffff, "CMI9761", patch_cm9761,NULL },127 { 0x434d4983, 0xffffffff, "CMI9761", patch_cm9761,NULL },124 { 0x434d4969, 0xffffffff, "CMI9780", patch_cm9780, NULL }, 125 { 0x434d4978, 0xffffffff, "CMI9761", patch_cm9761, NULL }, 126 { 0x434d4982, 0xffffffff, "CMI9761", patch_cm9761, NULL }, 127 { 0x434d4983, 0xffffffff, "CMI9761", patch_cm9761, NULL }, 128 128 { 0x43525900, 0xfffffff8, "CS4297", NULL, NULL }, 129 129 { 0x43525910, 0xfffffff8, "CS4297A", patch_cirrus_spdif, NULL }, 130 { 0x43525920, 0xfffffff8, "CS4298", patch_cirrus_spdif,NULL },130 { 0x43525920, 0xfffffff8, "CS4298", patch_cirrus_spdif, NULL }, 131 131 { 0x43525928, 0xfffffff8, "CS4294", NULL, NULL }, 132 132 { 0x43525930, 0xfffffff8, "CS4299", patch_cirrus_cs4299, NULL }, … … 138 138 { 0x43585428, 0xfffffff8, "Cx20468", patch_conexant, NULL }, // SmartAMC fixme: the mask might be different 139 139 { 0x44543031, 0xfffffff0, "DT0398", NULL, NULL }, 140 { 0x454d4328, 0xffffffff, " 28028", NULL, NULL }, // same as TR28028?140 { 0x454d4328, 0xffffffff, "EM28028", NULL, NULL }, // same as TR28028? 141 141 { 0x45838308, 0xffffffff, "ESS1988", NULL, NULL }, 142 142 { 0x48525300, 0xffffff00, "HMP9701", NULL, NULL }, … … 144 144 { 0x49434511, 0xffffffff, "ICE1232", NULL, NULL }, // alias VIA VT1611A? 145 145 { 0x49434514, 0xffffffff, "ICE1232A", NULL, NULL }, 146 { 0x49434551, 0xffffffff, "VT1616", patch_vt1616, NULL }, 146 { 0x49434551, 0xffffffff, "VT1616", patch_vt1616, NULL }, 147 147 { 0x49434552, 0xffffffff, "VT1616i", patch_vt1616, NULL }, // VT1616 compatible (chipset integrated) 148 148 { 0x49544520, 0xffffffff, "IT2226E", NULL, NULL }, 149 149 { 0x49544561, 0xffffffff, "IT2646E", patch_it2646, NULL }, 150 { 0x4e534300, 0xffffffff, "LM4540 /43/45/46/48", NULL, NULL }, // only guess --jk150 { 0x4e534300, 0xffffffff, "LM4540,43,45,46,48", NULL, NULL }, // only guess --jk 151 151 { 0x4e534331, 0xffffffff, "LM4549", NULL, NULL }, 152 152 { 0x4e534350, 0xffffffff, "LM4550", NULL, NULL }, 153 153 { 0x50534304, 0xffffffff, "UCB1400", NULL, NULL }, 154 { 0x53494c20, 0xffffffe0, "Si3036 /8", NULL, NULL},154 { 0x53494c20, 0xffffffe0, "Si3036,8", mpatch_si3036, mpatch_si3036, AC97_MODEM_PATCH }, 155 155 { 0x54524102, 0xffffffff, "TR28022", NULL, NULL }, 156 156 { 0x54524106, 0xffffffff, "TR28026", NULL, NULL }, … … 159 159 { 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, 160 160 { 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF 161 { 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a,NULL }, // modified VT1616 with S/PDIF161 { 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF 162 162 { 0x57454301, 0xffffffff, "W83971D", NULL, NULL }, 163 163 { 0x574d4c00, 0xffffffff, "WM9701A", NULL, NULL }, 164 { 0x574d4C03, 0xffffffff, "WM9703 /WM9707/WM9708/WM9717", patch_wolfson03, NULL},165 { 0x574d4C04, 0xffffffff, "WM9704M /WM9704Q", patch_wolfson04, NULL},166 { 0x574d4C05, 0xffffffff, "WM9705 /WM9710", patch_wolfson05, NULL},164 { 0x574d4C03, 0xffffffff, "WM9703,WM9707,WM9708,WM9717", patch_wolfson03, NULL}, 165 { 0x574d4C04, 0xffffffff, "WM9704M,WM9704Q", patch_wolfson04, NULL}, 166 { 0x574d4C05, 0xffffffff, "WM9705,WM9710", patch_wolfson05, NULL}, 167 167 { 0x574d4C09, 0xffffffff, "WM9709", NULL, NULL}, 168 { 0x574d4C12, 0xffffffff, "WM9711 /WM9712", patch_wolfson11, NULL},169 { 0x574d4c13, 0xffffffff, "WM9713 /WM9714",patch_wolfson13, NULL, AC97_DEFAULT_POWER_OFF},168 { 0x574d4C12, 0xffffffff, "WM9711,WM9712", patch_wolfson11, NULL}, 169 { 0x574d4c13, 0xffffffff, "WM9713,WM9714", patch_wolfson13, NULL, AC97_DEFAULT_POWER_OFF}, 170 170 { 0x594d4800, 0xffffffff, "YMF743", NULL, NULL }, 171 171 { 0x594d4802, 0xffffffff, "YMF752", NULL, NULL }, 172 172 { 0x594d4803, 0xffffffff, "YMF753", patch_yamaha_ymf753, NULL }, 173 { 0x83847600, 0xffffffff, "STAC9700 /83/84", patch_sigmatel_stac9700, NULL },174 { 0x83847604, 0xffffffff, "STAC9701 /3/4/5", NULL, NULL },173 { 0x83847600, 0xffffffff, "STAC9700,83,84", patch_sigmatel_stac9700, NULL }, 174 { 0x83847604, 0xffffffff, "STAC9701,3,4,5", NULL, NULL }, 175 175 { 0x83847605, 0xffffffff, "STAC9704", NULL, NULL }, 176 { 0x83847608, 0xffffffff, "STAC9708 /11", patch_sigmatel_stac9708, NULL },177 { 0x83847609, 0xffffffff, "STAC9721 /23", patch_sigmatel_stac9721, NULL },176 { 0x83847608, 0xffffffff, "STAC9708,11", patch_sigmatel_stac9708, NULL }, 177 { 0x83847609, 0xffffffff, "STAC9721,23", patch_sigmatel_stac9721, NULL }, 178 178 { 0x83847644, 0xffffffff, "STAC9744", patch_sigmatel_stac9744, NULL }, 179 { 0x83847650, 0xffffffff, "STAC9750 /51", NULL, NULL }, // patch?180 { 0x83847652, 0xffffffff, "STAC9752 /53", NULL, NULL }, // patch?181 { 0x83847656, 0xffffffff, "STAC9756 /57", patch_sigmatel_stac9756, NULL },182 { 0x838476 66, 0xffffffff, "STAC9766/67", NULL, NULL }, // patch?183 { 0x838476 58, 0xffffffff, "STAC9758/59", patch_sigmatel_stac9758, NULL },179 { 0x83847650, 0xffffffff, "STAC9750,51", NULL, NULL }, // patch? 180 { 0x83847652, 0xffffffff, "STAC9752,53", NULL, NULL }, // patch? 181 { 0x83847656, 0xffffffff, "STAC9756,57", patch_sigmatel_stac9756, NULL }, 182 { 0x83847658, 0xffffffff, "STAC9758,59", patch_sigmatel_stac9758, NULL }, 183 { 0x83847666, 0xffffffff, "STAC9766,67", NULL, NULL }, // patch? 184 184 { 0, 0, NULL, NULL, NULL } 185 185 }; 186 186 187 const char *snd_ac97_stereo_enhancements[] = 188 { 189 /* 0 */ "No 3D Stereo Enhancement", 190 /* 1 */ "Analog Devices Phat Stereo", 191 /* 2 */ "Creative Stereo Enhancement", 192 /* 3 */ "National Semi 3D Stereo Enhancement", 193 /* 4 */ "YAMAHA Ymersion", 194 /* 5 */ "BBE 3D Stereo Enhancement", 195 /* 6 */ "Crystal Semi 3D Stereo Enhancement", 196 /* 7 */ "Qsound QXpander", 197 /* 8 */ "Spatializer 3D Stereo Enhancement", 198 /* 9 */ "SRS 3D Stereo Enhancement", 199 /* 10 */ "Platform Tech 3D Stereo Enhancement", 200 /* 11 */ "AKM 3D Audio", 201 /* 12 */ "Aureal Stereo Enhancement", 202 /* 13 */ "Aztech 3D Enhancement", 203 /* 14 */ "Binaura 3D Audio Enhancement", 204 /* 15 */ "ESS Technology Stereo Enhancement", 205 /* 16 */ "Harman International VMAx", 206 /* 17 */ "Nvidea/IC Ensemble/KS Waves 3D Stereo Enhancement", 207 /* 18 */ "Philips Incredible Sound", 208 /* 19 */ "Texas Instruments 3D Stereo Enhancement", 209 /* 20 */ "VLSI Technology 3D Stereo Enhancement", 210 /* 21 */ "TriTech 3D Stereo Enhancement", 211 /* 22 */ "Realtek 3D Stereo Enhancement", 212 /* 23 */ "Samsung 3D Stereo Enhancement", 213 /* 24 */ "Wolfson Microelectronics 3D Enhancement", 214 /* 25 */ "Delta Integration 3D Enhancement", 215 /* 26 */ "SigmaTel 3D Enhancement", 216 /* 27 */ "IC Ensemble/KS Waves", 217 /* 28 */ "Rockwell 3D Stereo Enhancement", 218 /* 29 */ "Reserved 29", 219 /* 30 */ "Reserved 30", 220 /* 31 */ "Reserved 31" 221 }; 222 223 224 /* * I/O routines 187 188 /* 189 * I/O routines 225 190 */ 226 191 227 static int snd_ac97_valid_reg( ac97_t*ac97, unsigned short reg)192 static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg) 228 193 { 229 194 if (ac97->limited_regs && ! test_bit(reg, ac97->reg_accessed)) … … 278 243 * reflect the change to the suspend/resume state. 279 244 */ 280 void snd_ac97_write( ac97_t*ac97, unsigned short reg, unsigned short value)245 void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value) 281 246 { 282 247 if (!snd_ac97_valid_reg(ac97, reg)) 283 284 285 286 287 ac97->bus->ops->write(ac97, AC97_RESET, 0);/* reset audio codec */288 289 248 return; 249 if ((ac97->id & 0xffffff00) == AC97_ID_ALC100) { 250 /* Fix H/W bug of ALC100/100P */ 251 if (reg == AC97_MASTER || reg == AC97_HEADPHONE) 252 ac97->bus->ops->write(ac97, AC97_RESET, 0); /* reset audio codec */ 253 } 254 ac97->bus->ops->write(ac97, reg, value); 290 255 } 291 256 292 257 /** 293 258 * snd_ac97_read - read a value from the given register 294 * 259 * 295 260 * @ac97: the ac97 instance 296 261 * @reg: the register to read … … 301 266 * Returns the read value. 302 267 */ 303 unsigned short snd_ac97_read( ac97_t*ac97, unsigned short reg)268 unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 304 269 { 305 270 if (!snd_ac97_valid_reg(ac97, reg)) 306 307 271 return 0; 272 return ac97->bus->ops->read(ac97, reg); 308 273 } 309 274 310 275 /* read a register - return the cached value if already read */ 311 static inline unsigned short snd_ac97_read_cache( ac97_t*ac97, unsigned short reg)312 { 313 314 315 316 317 276 static inline unsigned short snd_ac97_read_cache(struct snd_ac97 *ac97, unsigned short reg) 277 { 278 if (! test_bit(reg, ac97->reg_accessed)) { 279 ac97->regs[reg] = ac97->bus->ops->read(ac97, reg); 280 // set_bit(reg, ac97->reg_accessed); 281 } 282 return ac97->regs[reg]; 318 283 } 319 284 … … 328 293 * suspend/resume. 329 294 */ 330 void snd_ac97_write_cache( ac97_t*ac97, unsigned short reg, unsigned short value)295 void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value) 331 296 { 332 297 if (!snd_ac97_valid_reg(ac97, reg)) 333 334 298 return; 299 down(&ac97->reg_mutex); 335 300 ac97->regs[reg] = value; 336 337 338 301 ac97->bus->ops->write(ac97, reg, value); 302 set_bit(reg, ac97->reg_accessed); 303 up(&ac97->reg_mutex); 339 304 } 340 305 … … 351 316 * code on failure. 352 317 */ 353 int snd_ac97_update( ac97_t*ac97, unsigned short reg, unsigned short value)318 int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value) 354 319 { 355 320 int change; 356 321 357 322 if (!snd_ac97_valid_reg(ac97, reg)) 358 359 323 return -EINVAL; 324 down(&ac97->reg_mutex); 360 325 change = ac97->regs[reg] != value; 361 326 if (change) { 362 327 ac97->regs[reg] = value; 363 328 ac97->bus->ops->write(ac97, reg, value); 364 365 366 329 } 330 set_bit(reg, ac97->reg_accessed); 331 up(&ac97->reg_mutex); 367 332 return change; 368 333 } … … 381 346 * code on failure. 382 347 */ 383 int snd_ac97_update_bits( ac97_t*ac97, unsigned short reg, unsigned short mask, unsigned short value)348 int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value) 384 349 { 385 350 int change; 386 351 387 352 if (!snd_ac97_valid_reg(ac97, reg)) 388 389 390 391 392 353 return -EINVAL; 354 down(&ac97->reg_mutex); 355 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value); 356 up(&ac97->reg_mutex); 357 return change; 393 358 } 394 359 395 360 /* no lock version - see snd_ac97_updat_bits() */ 396 int snd_ac97_update_bits_nolock( ac97_t*ac97, unsigned short reg,397 398 { 399 400 401 402 403 404 361 int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg, 362 unsigned short mask, unsigned short value) 363 { 364 int change; 365 unsigned short old, new; 366 367 old = snd_ac97_read_cache(ac97, reg); 368 new = (old & ~mask) | value; 369 change = old != new; 405 370 if (change) { 406 371 ac97->regs[reg] = new; 407 372 ac97->bus->ops->write(ac97, reg, new); 408 409 373 } 374 set_bit(reg, ac97->reg_accessed); 410 375 return change; 411 376 } 412 377 413 static int snd_ac97_ad18xx_update_pcm_bits( ac97_t*ac97, int codec, unsigned short mask, unsigned short value)414 { 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 378 static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsigned short mask, unsigned short value) 379 { 380 int change; 381 unsigned short old, new, cfg; 382 383 down(&ac97->page_mutex); 384 old = ac97->spec.ad18xx.pcmreg[codec]; 385 new = (old & ~mask) | value; 386 change = old != new; 387 if (change) { 388 down(&ac97->reg_mutex); 389 cfg = snd_ac97_read_cache(ac97, AC97_AD_SERIAL_CFG); 390 ac97->spec.ad18xx.pcmreg[codec] = new; 391 /* select single codec */ 392 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG, 393 (cfg & ~0x7000) | 394 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 395 /* update PCM bits */ 396 ac97->bus->ops->write(ac97, AC97_PCM, new); 397 /* select all codecs */ 398 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG, 399 cfg | 0x7000); 400 up(&ac97->reg_mutex); 401 } 402 up(&ac97->page_mutex); 403 return change; 439 404 } 440 405 … … 443 408 */ 444 409 445 int snd_ac97_info_enum_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 446 { 447 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 448 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 449 uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 450 uinfo->value.enumerated.items = e->mask; 451 if (uinfo->value.enumerated.item > e->mask - 1) 452 uinfo->value.enumerated.item = e->mask - 1; 453 strcpy(uinfo->value.enumerated.name, e->texts[uinfo->value.enumerated.item]); 454 return 0; 455 } 456 457 int snd_ac97_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 458 { 459 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 460 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 461 unsigned short val, bitmask; 462 463 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1) 464 ; 465 val = snd_ac97_read_cache(ac97, e->reg); 466 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); 467 if (e->shift_l != e->shift_r) 468 ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & (bitmask - 1); 469 return 0; 470 } 471 472 int snd_ac97_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 473 { 474 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 475 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 476 unsigned short val; 477 unsigned short mask, bitmask; 478 479 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1) 480 ; 481 if (ucontrol->value.enumerated.item[0] > e->mask - 1) 482 return -EINVAL; 483 val = ucontrol->value.enumerated.item[0] << e->shift_l; 484 mask = (bitmask - 1) << e->shift_l; 485 if (e->shift_l != e->shift_r) { 486 if (ucontrol->value.enumerated.item[1] > e->mask - 1) 487 return -EINVAL; 488 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 489 mask |= (bitmask - 1) << e->shift_r; 490 } 491 return snd_ac97_update_bits(ac97, e->reg, mask, val); 410 int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 411 { 412 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 413 414 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 415 uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 416 uinfo->value.enumerated.items = e->mask; 417 418 if (uinfo->value.enumerated.item > e->mask - 1) 419 uinfo->value.enumerated.item = e->mask - 1; 420 strcpy(uinfo->value.enumerated.name, e->texts[uinfo->value.enumerated.item]); 421 return 0; 422 } 423 424 int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 425 { 426 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 427 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 428 unsigned short val, bitmask; 429 430 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1) 431 ; 432 val = snd_ac97_read_cache(ac97, e->reg); 433 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); 434 if (e->shift_l != e->shift_r) 435 ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & (bitmask - 1); 436 437 return 0; 438 } 439 440 int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 441 { 442 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 443 struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value; 444 unsigned short val; 445 unsigned short mask, bitmask; 446 447 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1) 448 ; 449 if (ucontrol->value.enumerated.item[0] > e->mask - 1) 450 return -EINVAL; 451 val = ucontrol->value.enumerated.item[0] << e->shift_l; 452 mask = (bitmask - 1) << e->shift_l; 453 if (e->shift_l != e->shift_r) { 454 if (ucontrol->value.enumerated.item[1] > e->mask - 1) 455 return -EINVAL; 456 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 457 mask |= (bitmask - 1) << e->shift_r; 458 } 459 return snd_ac97_update_bits(ac97, e->reg, mask, val); 492 460 } 493 461 494 462 /* save/restore ac97 v2.3 paging */ 495 static int snd_ac97_page_save( ac97_t *ac97, int reg, snd_kcontrol_t*kcontrol)496 { 497 498 499 500 501 502 503 504 505 506 507 } 508 509 static void snd_ac97_page_restore( ac97_t*ac97, int page_save)510 { 511 512 513 514 463 static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol) 464 { 465 int page_save = -1; 466 if ((kcontrol->private_value & (1<<25)) && 467 (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 && 468 (reg >= 0x60 && reg < 0x70)) { 469 unsigned short page = (kcontrol->private_value >> 26) & 0x0f; 470 down(&ac97->page_mutex); /* lock paging */ 471 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 472 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); 473 } 474 return page_save; 475 } 476 477 static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save) 478 { 479 if (page_save >= 0) { 480 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); 481 up(&ac97->page_mutex); /* unlock paging */ 482 } 515 483 } 516 484 517 485 /* volume and switch controls */ 518 int snd_ac97_info_volsw(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)486 int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 519 487 { 520 488 int mask = (kcontrol->private_value >> 16) & 0xff; 521 522 523 524 525 489 int shift = (kcontrol->private_value >> 8) & 0x0f; 490 int rshift = (kcontrol->private_value >> 12) & 0x0f; 491 492 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 493 uinfo->count = shift == rshift ? 1 : 2; 526 494 uinfo->value.integer.min = 0; 527 495 uinfo->value.integer.max = mask; … … 529 497 } 530 498 531 int snd_ac97_get_volsw(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)532 { 533 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 return 0; 552 } 553 554 int snd_ac97_put_volsw(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)555 { 556 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 } 582 583 static const s nd_kcontrol_new_tsnd_ac97_controls_master_mono[2] = {499 int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 500 { 501 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 502 int reg = kcontrol->private_value & 0xff; 503 int shift = (kcontrol->private_value >> 8) & 0x0f; 504 int rshift = (kcontrol->private_value >> 12) & 0x0f; 505 int mask = (kcontrol->private_value >> 16) & 0xff; 506 int invert = (kcontrol->private_value >> 24) & 0x01; 507 int page_save; 508 509 page_save = snd_ac97_page_save(ac97, reg, kcontrol); 510 ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask; 511 if (shift != rshift) 512 ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask; 513 if (invert) { 514 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 515 if (shift != rshift) 516 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; 517 } 518 snd_ac97_page_restore(ac97, page_save); 519 return 0; 520 } 521 522 int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 523 { 524 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 525 int reg = kcontrol->private_value & 0xff; 526 int shift = (kcontrol->private_value >> 8) & 0x0f; 527 int rshift = (kcontrol->private_value >> 12) & 0x0f; 528 int mask = (kcontrol->private_value >> 16) & 0xff; 529 int invert = (kcontrol->private_value >> 24) & 0x01; 530 int err, page_save; 531 unsigned short val, val2, val_mask; 532 533 page_save = snd_ac97_page_save(ac97, reg, kcontrol); 534 val = (ucontrol->value.integer.value[0] & mask); 535 if (invert) 536 val = mask - val; 537 val_mask = mask << shift; 538 val = val << shift; 539 if (shift != rshift) { 540 val2 = (ucontrol->value.integer.value[1] & mask); 541 if (invert) 542 val2 = mask - val2; 543 val_mask |= mask << rshift; 544 val |= val2 << rshift; 545 } 546 err = snd_ac97_update_bits(ac97, reg, val_mask, val); 547 snd_ac97_page_restore(ac97, page_save); 548 return err; 549 } 550 551 static const struct snd_kcontrol_new snd_ac97_controls_master_mono[2] = { 584 552 AC97_SINGLE("Master Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), 585 553 AC97_SINGLE("Master Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1) 586 554 }; 587 555 588 static const s nd_kcontrol_new_tsnd_ac97_controls_tone[2] = {556 static const struct snd_kcontrol_new snd_ac97_controls_tone[2] = { 589 557 AC97_SINGLE("Tone Control - Bass", AC97_MASTER_TONE, 8, 15, 1), 590 558 AC97_SINGLE("Tone Control - Treble", AC97_MASTER_TONE, 0, 15, 1) 591 559 }; 592 560 593 static const s nd_kcontrol_new_tsnd_ac97_controls_pc_beep[2] = {561 static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = { 594 562 AC97_SINGLE("PC Speaker Playback Switch", AC97_PC_BEEP, 15, 1, 1), 595 563 AC97_SINGLE("PC Speaker Playback Volume", AC97_PC_BEEP, 1, 15, 1) 596 564 }; 597 565 598 static const snd_kcontrol_new_t snd_ac97_controls_mic_boost = 599 AC97_SINGLE("Mic Boost (+20dB)", AC97_MIC, 6, 1, 0); 566 static const struct snd_kcontrol_new snd_ac97_controls_mic_boost = 567 AC97_SINGLE("Mic Boost (+20dB)", AC97_MIC, 6, 1, 0); 568 600 569 601 570 static const char* std_rec_sel[] = {"Mic", "CD", "Video", "Aux", "Line", "Mix", "Mix Mono", "Phone"}; … … 603 572 static const char* std_mix[] = {"Mix", "Mic"}; 604 573 static const char* std_mic[] = {"Mic1", "Mic2"}; 574 605 575 static const struct ac97_enum std_enum[] = { 606 607 608 609 576 AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, std_rec_sel), 577 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, std_3d_path), 578 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 9, 2, std_mix), 579 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, std_mic), 610 580 }; 611 581 612 static const s nd_kcontrol_new_t snd_ac97_control_capture_src =613 AC97_ENUM("Capture Source", std_enum[0]); 614 615 static const s nd_kcontrol_new_tsnd_ac97_control_capture_vol =582 static const struct snd_kcontrol_new snd_ac97_control_capture_src = 583 AC97_ENUM("Capture Source", std_enum[0]); 584 585 static const struct snd_kcontrol_new snd_ac97_control_capture_vol = 616 586 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0); 617 587 618 static const s nd_kcontrol_new_tsnd_ac97_controls_mic_capture[2] = {588 static const struct snd_kcontrol_new snd_ac97_controls_mic_capture[2] = { 619 589 AC97_SINGLE("Mic Capture Switch", AC97_REC_GAIN_MIC, 15, 1, 1), 620 590 AC97_SINGLE("Mic Capture Volume", AC97_REC_GAIN_MIC, 0, 15, 0) 621 591 }; 622 592 623 typedefenum {593 enum { 624 594 AC97_GENERAL_PCM_OUT = 0, 625 595 AC97_GENERAL_STEREO_ENHANCEMENT, … … 629 599 AC97_GENERAL_MIC, 630 600 AC97_GENERAL_LOOPBACK 631 } ac97_general_index_t;632 633 static const s nd_kcontrol_new_tsnd_ac97_controls_general[7] = {634 601 }; 602 603 static const struct snd_kcontrol_new snd_ac97_controls_general[7] = { 604 AC97_ENUM("PCM Out Path & Mute", std_enum[1]), 635 605 AC97_SINGLE("Simulated Stereo Enhancement", AC97_GENERAL_PURPOSE, 14, 1, 0), 636 606 AC97_SINGLE("3D Control - Switch", AC97_GENERAL_PURPOSE, 13, 1, 0), … … 641 611 }; 642 612 643 const s nd_kcontrol_new_tsnd_ac97_controls_3d[2] = {613 const struct snd_kcontrol_new snd_ac97_controls_3d[2] = { 644 614 AC97_SINGLE("3D Control - Center", AC97_3D_CONTROL, 8, 15, 0), 645 615 AC97_SINGLE("3D Control - Depth", AC97_3D_CONTROL, 0, 15, 0) 646 616 }; 647 617 648 static const s nd_kcontrol_new_tsnd_ac97_controls_center[2] = {618 static const struct snd_kcontrol_new snd_ac97_controls_center[2] = { 649 619 AC97_SINGLE("Center Playback Switch", AC97_CENTER_LFE_MASTER, 7, 1, 1), 650 620 AC97_SINGLE("Center Playback Volume", AC97_CENTER_LFE_MASTER, 0, 31, 1) 651 621 }; 652 622 653 static const s nd_kcontrol_new_tsnd_ac97_controls_lfe[2] = {623 static const struct snd_kcontrol_new snd_ac97_controls_lfe[2] = { 654 624 AC97_SINGLE("LFE Playback Switch", AC97_CENTER_LFE_MASTER, 15, 1, 1), 655 625 AC97_SINGLE("LFE Playback Volume", AC97_CENTER_LFE_MASTER, 8, 31, 1) 656 626 }; 657 627 658 static const s nd_kcontrol_new_tsnd_ac97_control_eapd =628 static const struct snd_kcontrol_new snd_ac97_control_eapd = 659 629 AC97_SINGLE("External Amplifier", AC97_POWERDOWN, 15, 1, 1); 660 630 661 static const s nd_kcontrol_new_tsnd_ac97_controls_modem_switches[2] = {631 static const struct snd_kcontrol_new snd_ac97_controls_modem_switches[2] = { 662 632 AC97_SINGLE("Off-hook Switch", AC97_GPIO_STATUS, 0, 1, 0), 663 633 AC97_SINGLE("Caller ID Switch", AC97_GPIO_STATUS, 2, 1, 0) … … 665 635 666 636 /* change the existing EAPD control as inverted */ 667 static void set_inv_eapd( ac97_t *ac97, snd_kcontrol_t*kctl)668 { 669 670 671 672 } 673 674 static int snd_ac97_spdif_mask_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)637 static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl) 638 { 639 kctl->private_value = AC97_SINGLE_VALUE(AC97_POWERDOWN, 15, 1, 0); 640 snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */ 641 ac97->scaps |= AC97_SCAP_INV_EAPD; 642 } 643 644 static int snd_ac97_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 675 645 { 676 646 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; … … 678 648 return 0; 679 649 } 680 681 static int snd_ac97_spdif_cmask_get(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)650 651 static int snd_ac97_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 682 652 { 683 653 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | … … 690 660 return 0; 691 661 } 692 693 static int snd_ac97_spdif_pmask_get(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)662 663 static int snd_ac97_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 694 664 { 695 665 /* FIXME: AC'97 spec doesn't say which bits are used for what */ … … 701 671 } 702 672 703 static int snd_ac97_spdif_default_get(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)704 { 705 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);706 707 673 static int snd_ac97_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 674 { 675 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 676 677 down(&ac97->reg_mutex); 708 678 ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff; 709 679 ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff; 710 680 ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff; 711 712 713 return 0; 714 } 715 716 static int snd_ac97_spdif_default_put(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)717 { 718 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);681 ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff; 682 up(&ac97->reg_mutex); 683 return 0; 684 } 685 686 static int snd_ac97_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 687 { 688 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 719 689 unsigned int new = 0; 720 690 unsigned short val = 0; … … 749 719 } 750 720 751 721 down(&ac97->reg_mutex); 752 722 change = ac97->spdif_status != new; 753 723 ac97->spdif_status = new; … … 759 729 case 2: x = 0; break; // 48.0 760 730 default: x = 0; break; // illegal. 761 762 731 } 732 change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12))); 763 733 } else if (ac97->flags & AC97_CX_SPDIF) { 764 734 int v; 765 735 v = new & (IEC958_AES0_CON_EMPHASIS_5015|IEC958_AES0_CON_NOT_COPYRIGHT) ? 0 : AC97_CXR_COPYRGT; 766 767 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC, 768 769 770 771 772 773 774 775 776 736 v |= new & IEC958_AES0_NONAUDIO ? AC97_CXR_SPDIF_AC3 : AC97_CXR_SPDIF_PCM; 737 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC, 738 AC97_CXR_SPDIF_MASK | AC97_CXR_COPYRGT, 739 v); 740 } else { 741 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS); 742 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */ 743 744 change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val); 745 if (extst & AC97_EA_SPDIF) { 746 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */ 777 747 } 778 748 } 779 780 up(&ac97->reg_mutex); 749 up(&ac97->reg_mutex); 750 781 751 return change; 782 752 } 783 753 784 static int snd_ac97_put_spsa(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)785 { 786 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);787 788 754 static int snd_ac97_put_spsa(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 755 { 756 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 757 int reg = kcontrol->private_value & 0xff; 758 int shift = (kcontrol->private_value >> 8) & 0xff; 789 759 int mask = (kcontrol->private_value >> 16) & 0xff; 790 760 // int invert = (kcontrol->private_value >> 24) & 0xff; 791 792 761 unsigned short value, old, new; 762 int change; 793 763 794 764 value = (ucontrol->value.integer.value[0] & mask); 795 765 796 766 down(&ac97->reg_mutex); 797 767 mask <<= shift; 798 768 value <<= shift; 799 old = snd_ac97_read_cache(ac97, reg); 800 new = (old & ~mask) | value; 801 change = old != new; 802 803 if (change) { 804 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS); 805 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */ 806 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value); 807 if (extst & AC97_EA_SPDIF) 808 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */ 809 } 810 up(&ac97->reg_mutex); 811 return change; 812 } 813 814 const snd_kcontrol_new_t snd_ac97_controls_spdif[5] = { 815 { 816 SNDRV_CTL_ELEM_IFACE_MIXER, 817 0,0, 818 SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 819 0, 820 SNDRV_CTL_ELEM_ACCESS_READ, 821 0, 822 snd_ac97_spdif_mask_info, 823 snd_ac97_spdif_cmask_get, 824 NULL, 0, 825 }, 826 { 827 SNDRV_CTL_ELEM_IFACE_MIXER, 828 0,0, 829 SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 830 0, 831 SNDRV_CTL_ELEM_ACCESS_READ, 832 0, 833 snd_ac97_spdif_mask_info, 834 snd_ac97_spdif_pmask_get, 835 NULL, 0, 836 }, 837 { 838 SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 839 SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 0,0,0, 840 snd_ac97_spdif_mask_info, 841 snd_ac97_spdif_default_get, 842 snd_ac97_spdif_default_put, 0, 843 }, 844 845 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),AC97_EXTENDED_STATUS, 2, 1, 0), 846 { 847 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, 848 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", 849 0,0,0, 850 snd_ac97_info_volsw, 851 snd_ac97_get_volsw, 852 snd_ac97_put_spsa, 853 AC97_SINGLE_VALUE(AC97_EXTENDED_STATUS, 4, 3, 0) 854 }, 769 old = snd_ac97_read_cache(ac97, reg); 770 new = (old & ~mask) | value; 771 change = old != new; 772 773 if (change) { 774 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS); 775 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */ 776 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value); 777 if (extst & AC97_EA_SPDIF) 778 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */ 779 } 780 up(&ac97->reg_mutex); 781 return change; 782 } 783 784 const struct snd_kcontrol_new snd_ac97_controls_spdif[5] = { 785 { 786 .access = SNDRV_CTL_ELEM_ACCESS_READ, 787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 788 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 789 .info = snd_ac97_spdif_mask_info, 790 .get = snd_ac97_spdif_cmask_get, 791 }, 792 { 793 .access = SNDRV_CTL_ELEM_ACCESS_READ, 794 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 795 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), 796 .info = snd_ac97_spdif_mask_info, 797 .get = snd_ac97_spdif_pmask_get, 798 }, 799 { 800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 801 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 802 .info = snd_ac97_spdif_mask_info, 803 .get = snd_ac97_spdif_default_get, 804 .put = snd_ac97_spdif_default_put, 805 }, 806 807 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),AC97_EXTENDED_STATUS, 2, 1, 0), 808 { 809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 810 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", 811 .info = snd_ac97_info_volsw, 812 .get = snd_ac97_get_volsw, 813 .put = snd_ac97_put_spsa, 814 .private_value = AC97_SINGLE_VALUE(AC97_EXTENDED_STATUS, 4, 3, 0) 815 }, 855 816 }; 856 817 857 818 #define AD18XX_PCM_BITS(xname, codec, lshift, rshift, mask) \ 858 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, 0, 0, 0,snd_ac97_ad18xx_pcm_info_bits, \859 snd_ac97_ad18xx_pcm_get_bits,snd_ac97_ad18xx_pcm_put_bits, \860 861 862 static int snd_ac97_ad18xx_pcm_info_bits(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)863 { 864 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);819 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_bits, \ 820 .get = snd_ac97_ad18xx_pcm_get_bits, .put = snd_ac97_ad18xx_pcm_put_bits, \ 821 .private_value = (codec) | ((lshift) << 8) | ((rshift) << 12) | ((mask) << 16) } 822 823 static int snd_ac97_ad18xx_pcm_info_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 824 { 825 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 865 826 int mask = (kcontrol->private_value >> 16) & 0x0f; 866 827 int lshift = (kcontrol->private_value >> 8) & 0x0f; 867 828 int rshift = (kcontrol->private_value >> 12) & 0x0f; 829 868 830 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 869 831 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) 870 832 uinfo->count = 2; 871 833 else 872 uinfo->count = 1;834 uinfo->count = 1; 873 835 uinfo->value.integer.min = 0; 874 836 uinfo->value.integer.max = mask; … … 876 838 } 877 839 878 static int snd_ac97_ad18xx_pcm_get_bits(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)879 { 880 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);840 static int snd_ac97_ad18xx_pcm_get_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 841 { 842 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 881 843 int codec = kcontrol->private_value & 3; 882 844 int lshift = (kcontrol->private_value >> 8) & 0x0f; 883 845 int rshift = (kcontrol->private_value >> 12) & 0x0f; 884 846 int mask = (kcontrol->private_value >> 16) & 0xff; 885 847 886 848 ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask); 887 849 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) … … 890 852 } 891 853 892 static int snd_ac97_ad18xx_pcm_put_bits(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)893 { 894 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);854 static int snd_ac97_ad18xx_pcm_put_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 855 { 856 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 895 857 int codec = kcontrol->private_value & 3; 896 858 int lshift = (kcontrol->private_value >> 8) & 0x0f; … … 898 860 int mask = (kcontrol->private_value >> 16) & 0xff; 899 861 unsigned short val, valmask; 900 862 901 863 val = (mask - (ucontrol->value.integer.value[0] & mask)) << lshift; 902 864 valmask = mask << lshift; … … 909 871 910 872 #define AD18XX_PCM_VOLUME(xname, codec) \ 911 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, 0, 0, 0,snd_ac97_ad18xx_pcm_info_volume, \912 snd_ac97_ad18xx_pcm_get_volume,snd_ac97_ad18xx_pcm_put_volume, \913 codec }914 915 static int snd_ac97_ad18xx_pcm_info_volume(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)873 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_volume, \ 874 .get = snd_ac97_ad18xx_pcm_get_volume, .put = snd_ac97_ad18xx_pcm_put_volume, \ 875 .private_value = codec } 876 877 static int snd_ac97_ad18xx_pcm_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 916 878 { 917 879 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; … … 922 884 } 923 885 924 static int snd_ac97_ad18xx_pcm_get_volume(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)925 { 926 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);886 static int snd_ac97_ad18xx_pcm_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 887 { 888 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 927 889 int codec = kcontrol->private_value & 3; 928 929 890 891 down(&ac97->page_mutex); 930 892 ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31); 931 932 933 return 0; 934 } 935 936 static int snd_ac97_ad18xx_pcm_put_volume(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)937 { 938 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);893 ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31); 894 up(&ac97->page_mutex); 895 return 0; 896 } 897 898 static int snd_ac97_ad18xx_pcm_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 899 { 900 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 939 901 int codec = kcontrol->private_value & 3; 940 902 unsigned short val1, val2; 941 903 942 904 val1 = 31 - (ucontrol->value.integer.value[0] & 31); 943 905 val2 = 31 - (ucontrol->value.integer.value[1] & 31); … … 945 907 } 946 908 947 static const s nd_kcontrol_new_tsnd_ac97_controls_ad18xx_pcm[2] = {909 static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_pcm[2] = { 948 910 AD18XX_PCM_BITS("PCM Playback Switch", 0, 15, 7, 1), 949 911 AD18XX_PCM_VOLUME("PCM Playback Volume", 0) 950 912 }; 951 913 952 static const s nd_kcontrol_new_tsnd_ac97_controls_ad18xx_surround[2] = {914 static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_surround[2] = { 953 915 AD18XX_PCM_BITS("Surround Playback Switch", 1, 15, 7, 1), 954 916 AD18XX_PCM_VOLUME("Surround Playback Volume", 1) 955 917 }; 956 918 957 static const s nd_kcontrol_new_tsnd_ac97_controls_ad18xx_center[2] = {919 static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_center[2] = { 958 920 AD18XX_PCM_BITS("Center Playback Switch", 2, 15, 15, 1), 959 921 AD18XX_PCM_BITS("Center Playback Volume", 2, 8, 8, 31) 960 922 }; 961 923 962 static const s nd_kcontrol_new_tsnd_ac97_controls_ad18xx_lfe[2] = {924 static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_lfe[2] = { 963 925 AD18XX_PCM_BITS("LFE Playback Switch", 2, 7, 7, 1), 964 926 AD18XX_PCM_BITS("LFE Playback Volume", 2, 0, 0, 31) … … 969 931 */ 970 932 971 static void snd_ac97_powerdown( ac97_t*ac97);972 973 static int snd_ac97_bus_free( ac97_bus_t*bus)933 static void snd_ac97_powerdown(struct snd_ac97 *ac97); 934 935 static int snd_ac97_bus_free(struct snd_ac97_bus *bus) 974 936 { 975 937 if (bus) { 976 938 snd_ac97_bus_proc_done(bus); 977 if (bus->pcms) 978 kfree(bus->pcms); 939 kfree(bus->pcms); 979 940 if (bus->private_free) 980 981 982 } 983 return 0; 984 } 985 986 static int snd_ac97_bus_dev_free(s nd_device_t*device)987 { 988 ac97_bus_t*bus = device->device_data;941 bus->private_free(bus); 942 kfree(bus); 943 } 944 return 0; 945 } 946 947 static int snd_ac97_bus_dev_free(struct snd_device *device) 948 { 949 struct snd_ac97_bus *bus = device->device_data; 989 950 return snd_ac97_bus_free(bus); 990 951 } 991 952 992 static int snd_ac97_free( ac97_t*ac97)993 { 994 995 996 997 998 999 1000 1001 1002 1003 } 1004 1005 static int snd_ac97_dev_free(s nd_device_t*device)1006 { 1007 ac97_t*ac97 = device->device_data;1008 1009 1010 } 1011 1012 static int snd_ac97_try_volume_mix( ac97_t* ac97, int reg)953 static int snd_ac97_free(struct snd_ac97 *ac97) 954 { 955 if (ac97) { 956 snd_ac97_proc_done(ac97); 957 if (ac97->bus) 958 ac97->bus->codec[ac97->num] = NULL; 959 if (ac97->private_free) 960 ac97->private_free(ac97); 961 kfree(ac97); 962 } 963 return 0; 964 } 965 966 static int snd_ac97_dev_free(struct snd_device *device) 967 { 968 struct snd_ac97 *ac97 = device->device_data; 969 snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */ 970 return snd_ac97_free(ac97); 971 } 972 973 static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg) 1013 974 { 1014 975 unsigned short val, mask = 0x8000; … … 1056 1017 snd_ac97_write_cache(ac97, reg, val | mask); 1057 1018 val = snd_ac97_read(ac97, reg); 1019 val = snd_ac97_read(ac97, reg); 1058 1020 if (!(val & mask)) 1059 1021 return 0; /* nothing here */ … … 1062 1024 } 1063 1025 1064 static void check_volume_resolution( ac97_t*ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)1065 { 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 } 1088 1089 int snd_ac97_try_bit( ac97_t* ac97, int reg, int bit)1026 static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max) 1027 { 1028 unsigned short cbit[3] = { 0x20, 0x10, 0x01 }; 1029 unsigned char max[3] = { 63, 31, 15 }; 1030 int i; 1031 1032 *lo_max = *hi_max = 0; 1033 for (i = 0 ; i < ARRAY_SIZE(cbit); i++) { 1034 unsigned short val; 1035 snd_ac97_write(ac97, reg, 0x8080 | cbit[i] | (cbit[i] << 8)); 1036 /* Do the read twice due to buffers on some ac97 codecs. 1037 * e.g. The STAC9704 returns exactly what you wrote the the register 1038 * if you read it immediately. This causes the detect routine to fail. 1039 */ 1040 val = snd_ac97_read(ac97, reg); 1041 val = snd_ac97_read(ac97, reg); 1042 if (! *lo_max && (val & 0x7f) == cbit[i]) 1043 *lo_max = max[i]; 1044 if (! *hi_max && ((val >> 8) & 0x7f) == cbit[i]) 1045 *hi_max = max[i]; 1046 if (*lo_max && *hi_max) 1047 break; 1048 } 1049 } 1050 1051 int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit) 1090 1052 { 1091 1053 unsigned short mask, val, orig, res; … … 1101 1063 1102 1064 /* check the volume resolution of center/lfe */ 1103 static void snd_ac97_change_volume_params2( ac97_t* ac97, int reg, int shift, unsigned char *max)1065 static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max) 1104 1066 { 1105 1067 unsigned short val, val1; … … 1127 1089 } 1128 1090 1129 s nd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t* ac97)1130 { 1131 s nd_kcontrol_new_ttemplate;1091 struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template, struct snd_ac97 * ac97) 1092 { 1093 struct snd_kcontrol_new template; 1132 1094 memcpy(&template, _template, sizeof(template)); 1133 snd_runtime_check(!template.index, return NULL);1134 1095 template.index = ac97->num; 1135 1096 return snd_ctl_new1(&template, ac97); 1136 1097 } 1098 1137 1099 /* 1138 1100 * create mute switch(es) for normal stereo controls 1139 1101 */ 1140 static int snd_ac97_cmute_new_stereo(snd_card_t *card, char *name, int reg, int check_stereo, ac97_t *ac97) 1141 { 1142 snd_kcontrol_t *kctl; 1143 int err; 1144 unsigned short val, val1, mute_mask; 1145 snd_kcontrol_new_t tmp = {0}; 1146 1147 if (! snd_ac97_valid_reg(ac97, reg)) 1148 return 0; 1149 1150 mute_mask = 0x8000; 1151 val = snd_ac97_read(ac97, reg); 1152 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) { 1153 /* check whether both mute bits work */ 1154 val1 = val | 0x8080; 1155 snd_ac97_write(ac97, reg, val1); 1156 if (val1 == snd_ac97_read(ac97, reg)) 1157 mute_mask = 0x8080; 1158 } 1159 1102 static int snd_ac97_cmute_new_stereo(struct snd_card *card, char *name, int reg, int check_stereo, struct snd_ac97 *ac97) 1103 { 1104 struct snd_kcontrol *kctl; 1105 int err; 1106 unsigned short val, val1, mute_mask; 1107 snd_kcontrol_new_t tmp = {0}; 1108 1109 if (! snd_ac97_valid_reg(ac97, reg)) 1110 return 0; 1111 1112 mute_mask = 0x8000; 1113 val = snd_ac97_read(ac97, reg); 1114 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) { 1115 /* check whether both mute bits work */ 1116 val1 = val | 0x8080; 1117 snd_ac97_write(ac97, reg, val1); 1118 if (val1 == snd_ac97_read(ac97, reg)) 1119 mute_mask = 0x8080; 1120 } 1121 #if 1 1122 tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1123 tmp.name = name; 1124 tmp.info = snd_ac97_info_volsw; 1125 tmp.get = snd_ac97_get_volsw; 1126 tmp.put = snd_ac97_put_volsw; 1127 tmp.index = ac97->num; 1128 if (mute_mask == 0x8080) { 1129 tmp.private_value = reg | (15 << 8) | (7 << 12) | (1 << 16) | (1 << 24); 1130 } else { 1131 tmp.private_value = reg | (15 << 8) | (1 << 16) | (1 << 24); 1132 } 1133 kctl = snd_ctl_new1(&tmp, ac97); 1134 #else 1135 if (mute_mask == 0x8080) { 1136 struct snd_kcontrol_new tmp = AC97_DOUBLE(name, reg, 15, 7, 1, 1); 1137 tmp.index = ac97->num; 1138 kctl = snd_ctl_new1(&tmp, ac97); 1139 } else { 1140 struct snd_kcontrol_new tmp = AC97_SINGLE(name, reg, 15, 1, 1); 1141 tmp.index = ac97->num; 1142 kctl = snd_ctl_new1(&tmp, ac97); 1143 } 1144 #endif 1145 err = snd_ctl_add(card, kctl); 1146 if (err < 0) 1147 return err; 1148 /* mute as default */ 1149 snd_ac97_write_cache(ac97, reg, val | mute_mask); 1150 return 0; 1151 } 1152 1153 /* 1154 * create a volume for normal stereo/mono controls 1155 */ 1156 static int snd_ac97_cvol_new(struct snd_card *card, char *name, int reg, unsigned int lo_max, 1157 unsigned int hi_max, struct snd_ac97 *ac97) 1158 { 1159 int err; 1160 struct snd_kcontrol *kctl; 1161 snd_kcontrol_new_t tmp = {0}; 1162 1163 1164 if (! snd_ac97_valid_reg(ac97, reg)) 1165 return 0; 1166 #if 1 1160 1167 tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1161 1168 tmp.name = name; … … 1164 1171 tmp.put = snd_ac97_put_volsw; 1165 1172 tmp.index = ac97->num; 1166 if (mute_mask == 0x8080) {1167 tmp.private_value = reg | (15 << 8) | (7 << 12) | (1 << 16) | (1 << 24);1168 //AC97_DOUBLE(name, reg, 15, 7, 1, 1);1169 } else {1170 // tmp = AC97_SINGLE(name, reg, 15, 1, 1);1171 tmp.private_value = reg | (15 << 8) | (1 << 16) | (1 << 24);1172 }1173 kctl = snd_ctl_new1(&tmp, ac97);1174 err = snd_ctl_add(card, kctl);1175 if (err < 0)1176 return err;1177 /* mute as default */1178 snd_ac97_write_cache(ac97, reg, val | mute_mask);1179 return 0;1180 }1181 1182 /*1183 * create a volume for normal stereo/mono controls1184 */1185 static int snd_ac97_cvol_new(snd_card_t *card, char *name, int reg, unsigned int lo_max,1186 unsigned int hi_max, ac97_t *ac97)1187 {1188 int err;1189 snd_kcontrol_t *kctl;1190 snd_kcontrol_new_t tmp = {0};1191 //= AC97_DOUBLE(name, reg, 8, 0, (unsigned int)max, 1);1192 tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1193 tmp.name = name;1194 tmp.info = snd_ac97_info_volsw;1195 tmp.get = snd_ac97_get_volsw;1196 tmp.put = snd_ac97_put_volsw;1197 1198 if (! snd_ac97_valid_reg(ac97, reg))1199 return 0;1200 1173 if (hi_max) { 1201 1174 /* invert */ 1202 1175 tmp.private_value = reg | (8 << 8) | (0 << 12) | (lo_max << 16) | (1 << 24); 1203 //snd_kcontrol_new_t tmp = AC97_DOUBLE(name, reg, 8, 0, lo_max, 1);1204 1176 } else { 1205 1177 /* invert */ 1206 1178 tmp.private_value = reg | (0 << 8) | (0 << 12) | (lo_max << 16) | (1 << 24); 1207 //snd_kcontrol_new_t tmp = AC97_SINGLE(name, reg, 0, lo_max, 1);1208 1179 } 1209 tmp.index = ac97->num;1210 1180 kctl = snd_ctl_new1(&tmp, ac97); 1211 err = snd_ctl_add(card, kctl); 1212 if (err < 0) 1213 return err; 1214 snd_ac97_write_cache(ac97, reg, 1215 (snd_ac97_read(ac97, reg) & 0x8080) | 1216 lo_max | (hi_max << 8)); 1217 return 0; 1181 1182 #else 1183 if (hi_max) { 1184 /* invert */ 1185 struct snd_kcontrol_new tmp = AC97_DOUBLE(name, reg, 8, 0, lo_max, 1); 1186 tmp.index = ac97->num; 1187 kctl = snd_ctl_new1(&tmp, ac97); 1188 } else { 1189 /* invert */ 1190 struct snd_kcontrol_new tmp = AC97_SINGLE(name, reg, 0, lo_max, 1); 1191 tmp.index = ac97->num; 1192 kctl = snd_ctl_new1(&tmp, ac97); 1193 } 1194 #endif 1195 err = snd_ctl_add(card, kctl); 1196 if (err < 0) 1197 return err; 1198 snd_ac97_write_cache(ac97, reg, 1199 (snd_ac97_read(ac97, reg) & 0x8080) | 1200 lo_max | (hi_max << 8)); 1201 return 0; 1218 1202 } 1219 1203 … … 1221 1205 * create a mute-switch and a volume for normal stereo/mono controls 1222 1206 */ 1223 static int snd_ac97_cmix_new_stereo(snd_card_t *card, const char *pfx, int reg, int check_stereo, ac97_t *ac97) 1224 { 1225 int err; 1226 char name[44]; 1227 unsigned char lo_max, hi_max; 1228 1229 if (! snd_ac97_valid_reg(ac97, reg)) 1230 return 0; 1231 if (snd_ac97_try_bit(ac97, reg, 15)) { 1232 sprintf(name, "%s Switch", pfx); 1233 if ((err = snd_ac97_cmute_new_stereo(card, name, reg, check_stereo, ac97)) < 0) 1234 return err; 1235 } 1236 check_volume_resolution(ac97, reg, &lo_max, &hi_max); 1237 if (lo_max) { 1238 sprintf(name, "%s Volume", pfx); 1239 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0) 1240 return err; 1241 } 1242 return 0; 1243 } 1244 1245 #define snd_ac97_cmix_new(card, pfx, reg, ac97) snd_ac97_cmix_new_stereo(card, pfx, reg, 0, ac97) 1246 #define snd_ac97_cmute_new(card, name, reg, ac97) snd_ac97_cmute_new_stereo(card, name, reg, 0, ac97) 1247 1248 static unsigned int snd_ac97_determine_spdif_rates(ac97_t *ac97); 1249 1250 static int snd_ac97_mixer_build(ac97_t * ac97) 1251 { 1252 snd_card_t *card = ac97->bus->card; 1253 snd_kcontrol_t *kctl; 1254 int err; 1255 unsigned int idx; 1256 unsigned char max; 1257 1258 /* build master controls */ 1259 /* AD claims to remove this control from AD1887, although spec v2.2 does not allow this */ 1260 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) { 1261 if (ac97->flags & AC97_HAS_NO_MASTER_VOL) 1262 err = snd_ac97_cmute_new(card, "Master Playback Switch", AC97_MASTER, ac97); 1263 else 1264 err = snd_ac97_cmix_new(card, "Master Playback", AC97_MASTER, ac97); 1265 if (err < 0) 1266 return err; 1267 } 1268 1269 ac97->regs[AC97_CENTER_LFE_MASTER] = 0x8080; 1270 1271 /* build center controls */ 1272 if (snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER)) { 1273 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0) 1274 return err; 1275 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0) 1276 return err; 1277 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max); 1278 kctl->private_value &= ~(0xff << 16); 1279 kctl->private_value |= (int)max << 16; 1280 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max); 1281 } 1282 1283 /* build LFE controls */ 1284 if (snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1)) { 1285 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0) 1286 return err; 1287 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0) 1288 return err; 1289 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max); 1290 kctl->private_value &= ~(0xff << 16); 1291 kctl->private_value |= (int)max << 16; 1292 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8); 1293 } 1294 1295 /* build surround controls */ 1296 if (snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER)) { 1297 /* Surround Master (0x38) is with stereo mutes */ 1298 if ((err = snd_ac97_cmix_new_stereo(card, "Surround Playback", AC97_SURROUND_MASTER, 1, ac97)) < 0) 1299 return err; 1300 } 1301 1302 /* build headphone controls */ 1303 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) { 1304 if ((err = snd_ac97_cmix_new(card, "Headphone Playback", AC97_HEADPHONE, ac97)) < 0) 1305 return err; 1306 } 1307 1308 /* build master mono controls */ 1309 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) { 1310 if ((err = snd_ac97_cmix_new(card, "Master Mono Playback", AC97_MASTER_MONO, ac97)) < 0) 1311 return err; 1312 } 1313 1314 /* build master tone controls */ 1315 if (!(ac97->flags & AC97_HAS_NO_TONE)) { 1316 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) { 1317 for (idx = 0; idx < 2; idx++) { 1318 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0) 1319 return err; 1320 if (ac97->id == AC97_ID_YMF753) { 1321 kctl->private_value &= ~(0xff << 16); 1322 kctl->private_value |= 7 << 16; 1323 } 1324 } 1325 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f); 1326 } 1327 } 1328 1329 /* build PC Speaker controls */ 1330 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 1331 ((ac97->flags & AC97_HAS_PC_BEEP) || 1332 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) { 1333 for (idx = 0; idx < 2; idx++) 1334 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0) 1335 return err; 1336 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 1337 snd_ac97_read(ac97, AC97_PC_BEEP) | 0x801e); 1338 } 1339 1340 /* build Phone controls */ 1341 if (!(ac97->flags & AC97_HAS_NO_PHONE)) { 1342 if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) { 1343 if ((err = snd_ac97_cmix_new(card, "Phone Playback", AC97_PHONE, ac97)) < 0) 1344 return err; 1345 } 1346 } 1347 1348 /* build MIC controls */ 1349 if (!(ac97->flags & AC97_HAS_NO_MIC)) { 1350 if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) { 1351 if ((err = snd_ac97_cmix_new(card, "Mic Playback", AC97_MIC, ac97)) < 0) 1352 return err; 1353 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0) 1354 return err; 1355 } 1356 } 1357 1358 /* build Line controls */ 1359 if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) { 1360 if ((err = snd_ac97_cmix_new(card, "Line Playback", AC97_LINE, ac97)) < 0) 1361 return err; 1362 } 1363 1364 /* build CD controls */ 1365 if (!(ac97->flags & AC97_HAS_NO_CD)) { 1366 if (snd_ac97_try_volume_mix(ac97, AC97_CD)) { 1367 if ((err = snd_ac97_cmix_new(card, "CD Playback", AC97_CD, ac97)) < 0) 1368 return err; 1369 } 1370 } 1371 1372 /* build Video controls */ 1373 if (!(ac97->flags & AC97_HAS_NO_VIDEO)) { 1374 if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) { 1375 if ((err = snd_ac97_cmix_new(card, "Video Playback", AC97_VIDEO, ac97)) < 0) 1376 return err; 1377 } 1378 } 1379 1380 /* build Aux controls */ 1381 if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) { 1382 if ((err = snd_ac97_cmix_new(card, "Aux Playback", AC97_AUX, ac97)) < 0) 1383 return err; 1384 } 1385 1386 /* build PCM controls */ 1387 if (ac97->flags & AC97_AD_MULTI) { 1388 unsigned short init_val; 1389 if (ac97->flags & AC97_STEREO_MUTES) 1390 init_val = 0x9f9f; 1391 else 1392 init_val = 0x9f1f; 1393 for (idx = 0; idx < 2; idx++) 1394 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0) 1395 return err; 1396 ac97->spec.ad18xx.pcmreg[0] = init_val; 1397 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) { 1398 for (idx = 0; idx < 2; idx++) 1399 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0) 1400 return err; 1401 ac97->spec.ad18xx.pcmreg[1] = init_val; 1402 } 1403 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) { 1404 for (idx = 0; idx < 2; idx++) 1405 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0) 1406 return err; 1407 for (idx = 0; idx < 2; idx++) 1408 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0) 1409 return err; 1410 ac97->spec.ad18xx.pcmreg[2] = init_val; 1411 } 1412 snd_ac97_write_cache(ac97, AC97_PCM, init_val); 1413 } else { 1414 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) { 1415 if (ac97->flags & AC97_HAS_NO_PCM_VOL) 1416 err = snd_ac97_cmute_new(card, "PCM Playback Switch", AC97_PCM, ac97); 1417 else 1418 err = snd_ac97_cmix_new(card, "PCM Playback", AC97_PCM, ac97); 1419 if (err < 0) 1420 return err; 1421 } 1422 } 1423 /* build Capture controls */ 1424 if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) { 1425 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0) 1426 return err; 1427 if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) { 1428 if ((err = snd_ac97_cmute_new(card, "Capture Switch", AC97_REC_GAIN, ac97)) < 0) 1429 return err; 1430 } 1431 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0) 1432 return err; 1433 snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000); 1434 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000); 1435 } 1436 /* build MIC Capture controls */ 1437 if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) { 1438 for (idx = 0; idx < 2; idx++) 1439 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0) 1440 return err; 1441 snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000); 1442 } 1443 1444 /* build PCM out path & mute control */ 1445 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) { 1446 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97))) < 0) 1447 return err; 1448 } 1449 1450 /* build Simulated Stereo Enhancement control */ 1451 if (ac97->caps & 0x0008) { 1452 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97))) < 0) 1453 return err; 1454 } 1455 1456 /* build 3D Stereo Enhancement control */ 1457 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) { 1458 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97))) < 0) 1459 return err; 1460 } 1461 1462 /* build Loudness control */ 1463 if (ac97->caps & 0x0020) { 1464 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97))) < 0) 1465 return err; 1466 } 1467 1468 /* build Mono output select control */ 1469 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) { 1470 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97))) < 0) 1471 return err; 1472 } 1473 1474 /* build Mic select control */ 1475 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) { 1476 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97))) < 0) 1477 return err; 1478 } 1479 1480 /* build ADC/DAC loopback control */ 1481 if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) { 1482 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97))) < 0) 1483 return err; 1484 } 1485 1486 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000); 1487 1488 /* build 3D controls */ 1489 if (ac97->build_ops->build_3d) { 1490 ac97->build_ops->build_3d(ac97); 1491 } else { 1492 if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) { 1493 unsigned short val; 1494 val = 0x0707; 1495 snd_ac97_write(ac97, AC97_3D_CONTROL, val); 1496 val = snd_ac97_read(ac97, AC97_3D_CONTROL); 1497 val = val == 0x0606; 1498 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 1499 return err; 1500 if (val) 1501 kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16); 1502 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0) 1503 return err; 1504 if (val) 1505 kctl->private_value = AC97_3D_CONTROL | (1 << 8) | (7 << 16); 1506 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 1507 } 1508 } 1509 1510 /* build S/PDIF controls */ 1511 if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) { 1512 if (ac97->build_ops->build_spdif) { 1513 if ((err = ac97->build_ops->build_spdif(ac97)) < 0) 1514 return err; 1515 } else { 1516 for (idx = 0; idx < 5; idx++) 1517 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0) 1518 return err; 1519 if (ac97->build_ops->build_post_spdif) { 1520 if ((err = ac97->build_ops->build_post_spdif(ac97)) < 0) 1521 return err; 1522 } 1523 /* set default PCM S/PDIF params */ 1524 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 1525 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20); 1526 ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97); 1527 } 1528 ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF; 1529 } 1530 1531 /* build chip specific controls */ 1532 if (ac97->build_ops->build_specific) 1533 if ((err = ac97->build_ops->build_specific(ac97)) < 0) 1534 return err; 1535 1536 if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) { 1537 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97); 1538 if (! kctl) 1539 return -ENOMEM; 1540 if (ac97->scaps & AC97_SCAP_INV_EAPD) 1541 set_inv_eapd(ac97, kctl); 1542 if ((err = snd_ctl_add(card, kctl)) < 0) 1543 return err; 1544 } 1545 1546 return 0; 1547 } 1548 1549 static int snd_ac97_modem_build(snd_card_t * card, ac97_t * ac97) 1550 { 1551 int err, idx; 1552 1553 //printk("AC97_GPIO_CFG = %x\n",snd_ac97_read(ac97,AC97_GPIO_CFG)); 1554 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1555 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1556 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff); 1557 snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0); 1558 snd_ac97_write(ac97, AC97_MISC_AFE, 0x0); 1559 1560 /* build modem switches */ 1561 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_modem_switches); idx++) 1562 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97))) < 0) 1563 return err; 1564 1565 /* build chip specific controls */ 1566 if (ac97->build_ops->build_specific) 1567 if ((err = ac97->build_ops->build_specific(ac97)) < 0) 1568 return err; 1569 1570 return 0; 1571 } 1572 1573 static int snd_ac97_test_rate(ac97_t *ac97, int reg, int shadow_reg, int rate) 1574 { 1575 unsigned short val; 1576 unsigned int tmp; 1577 1578 tmp = ((unsigned int)rate * ac97->bus->clock) / 48000; 1579 snd_ac97_write_cache(ac97, reg, tmp & 0xffff); 1580 if (shadow_reg) 1581 snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff); 1582 val = snd_ac97_read(ac97, reg); 1583 return val == (tmp & 0xffff); 1584 } 1585 1586 static void snd_ac97_determine_rates(ac97_t *ac97, int reg, int shadow_reg, unsigned int *r_result) 1587 { 1588 unsigned int result = 0; 1589 unsigned short saved; 1590 1591 if (ac97->bus->no_vra) { 1592 *r_result = SNDRV_PCM_RATE_48000; 1593 if ((ac97->flags & AC97_DOUBLE_RATE) && 1594 reg == AC97_PCM_FRONT_DAC_RATE) 1595 *r_result |= SNDRV_PCM_RATE_96000; 1596 return; 1597 } 1598 1599 saved = snd_ac97_read(ac97, reg); 1600 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) 1601 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1602 AC97_EA_DRA, 0); 1603 /* test a non-standard rate */ 1604 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000)) 1605 result |= SNDRV_PCM_RATE_CONTINUOUS; 1606 /* let's try to obtain standard rates */ 1607 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000)) 1608 result |= SNDRV_PCM_RATE_8000; 1609 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025)) 1610 result |= SNDRV_PCM_RATE_11025; 1611 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000)) 1612 result |= SNDRV_PCM_RATE_16000; 1613 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050)) 1614 result |= SNDRV_PCM_RATE_22050; 1615 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000)) 1616 result |= SNDRV_PCM_RATE_32000; 1617 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100)) 1618 result |= SNDRV_PCM_RATE_44100; 1619 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000)) 1620 result |= SNDRV_PCM_RATE_48000; 1621 if ((ac97->flags & AC97_DOUBLE_RATE) && 1622 reg == AC97_PCM_FRONT_DAC_RATE) { 1623 /* test standard double rates */ 1624 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1625 AC97_EA_DRA, AC97_EA_DRA); 1626 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2)) 1627 result |= SNDRV_PCM_RATE_64000; 1628 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2)) 1629 result |= SNDRV_PCM_RATE_88200; 1630 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2)) 1631 result |= SNDRV_PCM_RATE_96000; 1632 /* some codecs don't support variable double rates */ 1633 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2)) 1634 result &= ~SNDRV_PCM_RATE_CONTINUOUS; 1635 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1636 AC97_EA_DRA, 0); 1637 } 1638 /* restore the default value */ 1639 snd_ac97_write_cache(ac97, reg, saved); 1640 if (shadow_reg) 1641 snd_ac97_write_cache(ac97, shadow_reg, saved); 1642 *r_result = result; 1207 static int snd_ac97_cmix_new_stereo(struct snd_card *card, const char *pfx, int reg, int check_stereo, struct snd_ac97 *ac97) 1208 { 1209 int err; 1210 char name[44]; 1211 unsigned char lo_max, hi_max; 1212 1213 if (! snd_ac97_valid_reg(ac97, reg)) 1214 return 0; 1215 1216 if (snd_ac97_try_bit(ac97, reg, 15)) { 1217 sprintf(name, "%s Switch", pfx); 1218 if ((err = snd_ac97_cmute_new_stereo(card, name, reg, check_stereo, ac97)) < 0) 1219 return err; 1220 } 1221 check_volume_resolution(ac97, reg, &lo_max, &hi_max); 1222 if (lo_max) { 1223 sprintf(name, "%s Volume", pfx); 1224 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0) 1225 return err; 1226 } 1227 return 0; 1228 } 1229 1230 #define snd_ac97_cmix_new(card, pfx, reg, ac97) snd_ac97_cmix_new_stereo(card, pfx, reg, 0, ac97) 1231 #define snd_ac97_cmute_new(card, name, reg, ac97) snd_ac97_cmute_new_stereo(card, name, reg, 0, ac97) 1232 1233 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97); 1234 1235 static int snd_ac97_mixer_build(struct snd_ac97 * ac97) 1236 { 1237 struct snd_card *card = ac97->bus->card; 1238 struct snd_kcontrol *kctl; 1239 int err; 1240 unsigned int idx; 1241 unsigned char max; 1242 1243 /* build master controls */ 1244 /* AD claims to remove this control from AD1887, although spec v2.2 does not allow this */ 1245 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) { 1246 if (ac97->flags & AC97_HAS_NO_MASTER_VOL) 1247 err = snd_ac97_cmute_new(card, "Master Playback Switch", AC97_MASTER, ac97); 1248 else 1249 err = snd_ac97_cmix_new(card, "Master Playback", AC97_MASTER, ac97); 1250 if (err < 0) 1251 return err; 1252 } 1253 1254 ac97->regs[AC97_CENTER_LFE_MASTER] = 0x8080; 1255 1256 /* build center controls */ 1257 if (snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER)) { 1258 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0) 1259 return err; 1260 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0) 1261 return err; 1262 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max); 1263 kctl->private_value &= ~(0xff << 16); 1264 kctl->private_value |= (int)max << 16; 1265 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max); 1266 } 1267 1268 /* build LFE controls */ 1269 if (snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1)) { 1270 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0) 1271 return err; 1272 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0) 1273 return err; 1274 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max); 1275 kctl->private_value &= ~(0xff << 16); 1276 kctl->private_value |= (int)max << 16; 1277 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8); 1278 } 1279 1280 /* build surround controls */ 1281 if (snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER)) { 1282 /* Surround Master (0x38) is with stereo mutes */ 1283 if ((err = snd_ac97_cmix_new_stereo(card, "Surround Playback", AC97_SURROUND_MASTER, 1, ac97)) < 0) 1284 return err; 1285 } 1286 1287 /* build headphone controls */ 1288 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) { 1289 if ((err = snd_ac97_cmix_new(card, "Headphone Playback", AC97_HEADPHONE, ac97)) < 0) 1290 return err; 1291 } 1292 1293 /* build master mono controls */ 1294 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) { 1295 if ((err = snd_ac97_cmix_new(card, "Master Mono Playback", AC97_MASTER_MONO, ac97)) < 0) 1296 return err; 1297 } 1298 1299 /* build master tone controls */ 1300 if (!(ac97->flags & AC97_HAS_NO_TONE)) { 1301 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) { 1302 for (idx = 0; idx < 2; idx++) { 1303 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0) 1304 return err; 1305 if (ac97->id == AC97_ID_YMF753) { 1306 kctl->private_value &= ~(0xff << 16); 1307 kctl->private_value |= 7 << 16; 1308 } 1309 } 1310 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f); 1311 } 1312 } 1313 1314 /* build PC Speaker controls */ 1315 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 1316 ((ac97->flags & AC97_HAS_PC_BEEP) || 1317 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) { 1318 for (idx = 0; idx < 2; idx++) 1319 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0) 1320 return err; 1321 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 1322 snd_ac97_read(ac97, AC97_PC_BEEP) | 0x801e); 1323 } 1324 1325 /* build Phone controls */ 1326 if (!(ac97->flags & AC97_HAS_NO_PHONE)) { 1327 if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) { 1328 if ((err = snd_ac97_cmix_new(card, "Phone Playback", AC97_PHONE, ac97)) < 0) 1329 return err; 1330 } 1331 } 1332 1333 /* build MIC controls */ 1334 if (!(ac97->flags & AC97_HAS_NO_MIC)) { 1335 if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) { 1336 if ((err = snd_ac97_cmix_new(card, "Mic Playback", AC97_MIC, ac97)) < 0) 1337 return err; 1338 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0) 1339 return err; 1340 } 1341 } 1342 1343 /* build Line controls */ 1344 if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) { 1345 if ((err = snd_ac97_cmix_new(card, "Line Playback", AC97_LINE, ac97)) < 0) 1346 return err; 1347 } 1348 1349 /* build CD controls */ 1350 if (!(ac97->flags & AC97_HAS_NO_CD)) { 1351 if (snd_ac97_try_volume_mix(ac97, AC97_CD)) { 1352 if ((err = snd_ac97_cmix_new(card, "CD Playback", AC97_CD, ac97)) < 0) 1353 return err; 1354 } 1355 } 1356 1357 /* build Video controls */ 1358 if (!(ac97->flags & AC97_HAS_NO_VIDEO)) { 1359 if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) { 1360 if ((err = snd_ac97_cmix_new(card, "Video Playback", AC97_VIDEO, ac97)) < 0) 1361 return err; 1362 } 1363 } 1364 1365 /* build Aux controls */ 1366 if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) { 1367 if ((err = snd_ac97_cmix_new(card, "Aux Playback", AC97_AUX, ac97)) < 0) 1368 return err; 1369 } 1370 1371 /* build PCM controls */ 1372 if (ac97->flags & AC97_AD_MULTI) { 1373 unsigned short init_val; 1374 if (ac97->flags & AC97_STEREO_MUTES) 1375 init_val = 0x9f9f; 1376 else 1377 init_val = 0x9f1f; 1378 for (idx = 0; idx < 2; idx++) 1379 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0) 1380 return err; 1381 ac97->spec.ad18xx.pcmreg[0] = init_val; 1382 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) { 1383 for (idx = 0; idx < 2; idx++) 1384 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0) 1385 return err; 1386 ac97->spec.ad18xx.pcmreg[1] = init_val; 1387 } 1388 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) { 1389 for (idx = 0; idx < 2; idx++) 1390 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0) 1391 return err; 1392 for (idx = 0; idx < 2; idx++) 1393 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0) 1394 return err; 1395 ac97->spec.ad18xx.pcmreg[2] = init_val; 1396 } 1397 snd_ac97_write_cache(ac97, AC97_PCM, init_val); 1398 } else { 1399 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) { 1400 if (ac97->flags & AC97_HAS_NO_PCM_VOL) 1401 err = snd_ac97_cmute_new(card, "PCM Playback Switch", AC97_PCM, ac97); 1402 else 1403 err = snd_ac97_cmix_new(card, "PCM Playback", AC97_PCM, ac97); 1404 if (err < 0) 1405 return err; 1406 } 1407 } 1408 1409 /* build Capture controls */ 1410 if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) { 1411 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0) 1412 return err; 1413 if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) { 1414 if ((err = snd_ac97_cmute_new(card, "Capture Switch", AC97_REC_GAIN, ac97)) < 0) 1415 return err; 1416 } 1417 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0) 1418 return err; 1419 snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000); 1420 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000); 1421 } 1422 /* build MIC Capture controls */ 1423 if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) { 1424 for (idx = 0; idx < 2; idx++) 1425 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0) 1426 return err; 1427 snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000); 1428 } 1429 1430 /* build PCM out path & mute control */ 1431 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) { 1432 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97))) < 0) 1433 return err; 1434 } 1435 1436 /* build Simulated Stereo Enhancement control */ 1437 if (ac97->caps & 0x0008) { 1438 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97))) < 0) 1439 return err; 1440 } 1441 1442 /* build 3D Stereo Enhancement control */ 1443 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) { 1444 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97))) < 0) 1445 return err; 1446 } 1447 1448 /* build Loudness control */ 1449 if (ac97->caps & 0x0020) { 1450 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97))) < 0) 1451 return err; 1452 } 1453 1454 /* build Mono output select control */ 1455 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) { 1456 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97))) < 0) 1457 return err; 1458 } 1459 1460 /* build Mic select control */ 1461 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) { 1462 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97))) < 0) 1463 return err; 1464 } 1465 1466 /* build ADC/DAC loopback control */ 1467 if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) { 1468 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97))) < 0) 1469 return err; 1470 } 1471 1472 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000); 1473 1474 /* build 3D controls */ 1475 if (ac97->build_ops->build_3d) { 1476 ac97->build_ops->build_3d(ac97); 1477 } else { 1478 if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) { 1479 unsigned short val; 1480 val = 0x0707; 1481 snd_ac97_write(ac97, AC97_3D_CONTROL, val); 1482 val = snd_ac97_read(ac97, AC97_3D_CONTROL); 1483 val = val == 0x0606; 1484 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 1485 return err; 1486 if (val) 1487 kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16); 1488 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0) 1489 return err; 1490 if (val) 1491 kctl->private_value = AC97_3D_CONTROL | (1 << 8) | (7 << 16); 1492 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 1493 } 1494 } 1495 1496 /* build S/PDIF controls */ 1497 if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) { 1498 if (ac97->build_ops->build_spdif) { 1499 if ((err = ac97->build_ops->build_spdif(ac97)) < 0) 1500 return err; 1501 } else { 1502 for (idx = 0; idx < 5; idx++) 1503 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0) 1504 return err; 1505 if (ac97->build_ops->build_post_spdif) { 1506 if ((err = ac97->build_ops->build_post_spdif(ac97)) < 0) 1507 return err; 1508 } 1509 /* set default PCM S/PDIF params */ 1510 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 1511 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20); 1512 ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97); 1513 } 1514 ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF; 1515 } 1516 1517 /* build chip specific controls */ 1518 if (ac97->build_ops->build_specific) 1519 if ((err = ac97->build_ops->build_specific(ac97)) < 0) 1520 return err; 1521 1522 if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) { 1523 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97); 1524 if (! kctl) 1525 return -ENOMEM; 1526 if (ac97->scaps & AC97_SCAP_INV_EAPD) 1527 set_inv_eapd(ac97, kctl); 1528 if ((err = snd_ctl_add(card, kctl)) < 0) 1529 return err; 1530 } 1531 1532 return 0; 1533 } 1534 1535 static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97) 1536 { 1537 int err, idx; 1538 1539 //printk("AC97_GPIO_CFG = %x\n",snd_ac97_read(ac97,AC97_GPIO_CFG)); 1540 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1541 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1542 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff); 1543 snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0); 1544 snd_ac97_write(ac97, AC97_MISC_AFE, 0x0); 1545 1546 /* build modem switches */ 1547 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_modem_switches); idx++) 1548 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97))) < 0) 1549 return err; 1550 1551 /* build chip specific controls */ 1552 if (ac97->build_ops->build_specific) 1553 if ((err = ac97->build_ops->build_specific(ac97)) < 0) 1554 return err; 1555 1556 return 0; 1557 } 1558 1559 static int snd_ac97_test_rate(struct snd_ac97 *ac97, int reg, int shadow_reg, int rate) 1560 { 1561 unsigned short val; 1562 unsigned int tmp; 1563 1564 tmp = ((unsigned int)rate * ac97->bus->clock) / 48000; 1565 snd_ac97_write_cache(ac97, reg, tmp & 0xffff); 1566 if (shadow_reg) 1567 snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff); 1568 val = snd_ac97_read(ac97, reg); 1569 return val == (tmp & 0xffff); 1570 } 1571 1572 static void snd_ac97_determine_rates(struct snd_ac97 *ac97, int reg, int shadow_reg, unsigned int *r_result) 1573 { 1574 unsigned int result = 0; 1575 unsigned short saved; 1576 1577 if (ac97->bus->no_vra) { 1578 *r_result = SNDRV_PCM_RATE_48000; 1579 if ((ac97->flags & AC97_DOUBLE_RATE) && 1580 reg == AC97_PCM_FRONT_DAC_RATE) 1581 *r_result |= SNDRV_PCM_RATE_96000; 1582 return; 1583 } 1584 1585 saved = snd_ac97_read(ac97, reg); 1586 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) 1587 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1588 AC97_EA_DRA, 0); 1589 /* test a non-standard rate */ 1590 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000)) 1591 result |= SNDRV_PCM_RATE_CONTINUOUS; 1592 /* let's try to obtain standard rates */ 1593 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000)) 1594 result |= SNDRV_PCM_RATE_8000; 1595 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025)) 1596 result |= SNDRV_PCM_RATE_11025; 1597 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000)) 1598 result |= SNDRV_PCM_RATE_16000; 1599 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050)) 1600 result |= SNDRV_PCM_RATE_22050; 1601 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000)) 1602 result |= SNDRV_PCM_RATE_32000; 1603 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100)) 1604 result |= SNDRV_PCM_RATE_44100; 1605 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000)) 1606 result |= SNDRV_PCM_RATE_48000; 1607 if ((ac97->flags & AC97_DOUBLE_RATE) && 1608 reg == AC97_PCM_FRONT_DAC_RATE) { 1609 /* test standard double rates */ 1610 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1611 AC97_EA_DRA, AC97_EA_DRA); 1612 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2)) 1613 result |= SNDRV_PCM_RATE_64000; 1614 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2)) 1615 result |= SNDRV_PCM_RATE_88200; 1616 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2)) 1617 result |= SNDRV_PCM_RATE_96000; 1618 /* some codecs don't support variable double rates */ 1619 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2)) 1620 result &= ~SNDRV_PCM_RATE_CONTINUOUS; 1621 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 1622 AC97_EA_DRA, 0); 1623 } 1624 /* restore the default value */ 1625 snd_ac97_write_cache(ac97, reg, saved); 1626 if (shadow_reg) 1627 snd_ac97_write_cache(ac97, shadow_reg, saved); 1628 *r_result = result; 1643 1629 } 1644 1630 1645 1631 /* check AC97_SPDIF register to accept which sample rates */ 1646 static unsigned int snd_ac97_determine_spdif_rates( ac97_t*ac97)1647 { 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1632 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97) 1633 { 1634 unsigned int result = 0; 1635 int i; 1636 static unsigned short ctl_bits[] = { 1637 AC97_SC_SPSR_44K, AC97_SC_SPSR_32K, AC97_SC_SPSR_48K 1638 }; 1639 static unsigned int rate_bits[] = { 1640 SNDRV_PCM_RATE_44100, SNDRV_PCM_RATE_32000, SNDRV_PCM_RATE_48000 1641 }; 1642 1643 for (i = 0; i < (int)ARRAY_SIZE(ctl_bits); i++) { 1644 snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, ctl_bits[i]); 1645 if ((snd_ac97_read(ac97, AC97_SPDIF) & AC97_SC_SPSR_MASK) == ctl_bits[i]) 1646 result |= rate_bits[i]; 1647 } 1648 return result; 1663 1649 } 1664 1650 1665 1651 /* look for the codec id table matching with the given id */ 1666 static const ac97_codec_id_t *look_for_codec_id(const ac97_codec_id_t *table, 1667 unsigned int id) 1668 { 1669 const ac97_codec_id_t *pid; 1670 1671 for (pid = table; pid->id; pid++) 1672 if (pid->id == (id & pid->mask)) 1673 return pid; 1674 return NULL; 1675 } 1676 1677 void snd_ac97_get_name(ac97_t *ac97, unsigned int id, char *name, int modem) 1678 { 1679 const ac97_codec_id_t *pid; 1680 1681 sprintf(name, "0x%x %c%c%c", id, 1682 printable(id >> 24), 1683 printable(id >> 16), 1684 printable(id >> 8)); 1685 pid = look_for_codec_id(snd_ac97_codec_id_vendors, id); 1686 if (! pid) 1687 return; 1688 1689 strcpy(name, pid->name); 1690 // dprintf(("vladest: AC97 vendor [%s], patch address %x",pid->name, pid->patch)); 1691 if (ac97 && pid->patch) { 1692 if ((modem && (pid->flags & AC97_MODEM_PATCH)) || 1693 (! modem && ! (pid->flags & AC97_MODEM_PATCH))) 1694 pid->patch(ac97); 1695 } 1696 1697 pid = look_for_codec_id(snd_ac97_codec_ids, id); 1698 if (pid) { 1699 strcat(name, " "); 1700 strcat(name, pid->name); 1701 if (pid->mask != 0xffffffff) 1702 sprintf(name + strlen(name), " rev %d", id & ~pid->mask); 1703 // dprintf(("vladest: AC97 codec [%s], patch address %x, id = %x",name, pid->patch, pid->id)); 1704 if (ac97 && pid->patch) { 1705 if ((modem && (pid->flags & AC97_MODEM_PATCH)) || 1706 (! modem && ! (pid->flags & AC97_MODEM_PATCH))) 1707 pid->patch(ac97); 1708 } 1709 } else 1710 sprintf(name + strlen(name), " id %x", id & 0xff); 1711 } 1712 1652 static const struct ac97_codec_id *look_for_codec_id(const struct ac97_codec_id *table, 1653 unsigned int id) 1654 { 1655 const struct ac97_codec_id *pid; 1656 1657 for (pid = table; pid->id; pid++) 1658 if (pid->id == (id & pid->mask)) 1659 return pid; 1660 return NULL; 1661 } 1662 1663 void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int modem) 1664 { 1665 const struct ac97_codec_id *pid; 1666 1667 sprintf(name, "0x%x %c%c%c", id, 1668 printable(id >> 24), 1669 printable(id >> 16), 1670 printable(id >> 8)); 1671 pid = look_for_codec_id(snd_ac97_codec_id_vendors, id); 1672 if (! pid) 1673 return; 1674 1675 strcpy(name, pid->name); 1676 if (ac97 && pid->patch) { 1677 if ((modem && (pid->flags & AC97_MODEM_PATCH)) || 1678 (! modem && ! (pid->flags & AC97_MODEM_PATCH))) 1679 pid->patch(ac97); 1680 } 1681 1682 pid = look_for_codec_id(snd_ac97_codec_ids, id); 1683 if (pid) { 1684 strcat(name, " "); 1685 strcat(name, pid->name); 1686 if (pid->mask != 0xffffffff) 1687 sprintf(name + strlen(name), " rev %d", id & ~pid->mask); 1688 if (ac97 && pid->patch) { 1689 if ((modem && (pid->flags & AC97_MODEM_PATCH)) || 1690 (! modem && ! (pid->flags & AC97_MODEM_PATCH))) 1691 pid->patch(ac97); 1692 } 1693 } else 1694 sprintf(name + strlen(name), " id %x", id & 0xff); 1695 } 1713 1696 1714 1697 /** … … 1718 1701 * Returns the short identifying name of the codec. 1719 1702 */ 1720 const char *snd_ac97_get_short_name(ac97_t *ac97) 1721 { 1722 const ac97_codec_id_t *pid; 1723 1724 for (pid = snd_ac97_codec_ids; pid->id; pid++) 1725 if (pid->id == (ac97->id & pid->mask)) 1726 return pid->name; 1727 return "unknown codec"; 1728 } 1703 const char *snd_ac97_get_short_name(struct snd_ac97 *ac97) 1704 { 1705 const struct ac97_codec_id *pid; 1706 1707 for (pid = snd_ac97_codec_ids; pid->id; pid++) 1708 if (pid->id == (ac97->id & pid->mask)) 1709 return pid->name; 1710 return "unknown codec"; 1711 } 1712 1729 1713 1730 1714 /* wait for a while until registers are accessible after RESET 1731 1715 * return 0 if ok, negative not ready 1732 1716 */ 1733 static int ac97_reset_wait(ac97_t *ac97, int timeout, int with_modem) 1734 { 1735 unsigned long end_time, i; 1736 unsigned short x = 0; 1737 unsigned short val; 1738 1739 end_time = jiffies + timeout; 1740 1741 do { 1742 /* use preliminary reads to settle the communication */ 1743 snd_ac97_read(ac97, AC97_RESET); 1744 snd_ac97_read(ac97, AC97_VENDOR_ID1); 1745 snd_ac97_read(ac97, AC97_VENDOR_ID2); 1746 /* modem? */ 1747 if (with_modem) { 1748 val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 1749 if (val != 0xffff && (val & 1) != 0) 1750 return 0; 1751 } 1752 if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) { 1753 /* probably only Xbox issue - all registers are read as zero */ 1754 val = snd_ac97_read(ac97, AC97_VENDOR_ID1); 1755 if (val != 0 && val != 0xffff) 1756 return 0; 1757 } else { 1758 /* because the PCM or MASTER volume registers can be modified, 1759 * the REC_GAIN register is used for tests 1760 */ 1761 /* test if we can write to the record gain volume register */ 1762 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05); 1763 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05) 1764 return 0; 1765 } 1766 set_current_state(TASK_UNINTERRUPTIBLE); 1767 schedule_timeout(1); 1768 // schedule_timeout(HZ/100); 1769 } while (time_after_eq(end_time, jiffies)); 1770 return -ENODEV; 1717 static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem) 1718 { 1719 unsigned long end_time; 1720 unsigned short val; 1721 1722 end_time = jiffies + timeout; 1723 do { 1724 1725 /* use preliminary reads to settle the communication */ 1726 snd_ac97_read(ac97, AC97_RESET); 1727 snd_ac97_read(ac97, AC97_VENDOR_ID1); 1728 snd_ac97_read(ac97, AC97_VENDOR_ID2); 1729 /* modem? */ 1730 if (with_modem) { 1731 val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 1732 if (val != 0xffff && (val & 1) != 0) 1733 return 0; 1734 } 1735 if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) { 1736 /* probably only Xbox issue - all registers are read as zero */ 1737 val = snd_ac97_read(ac97, AC97_VENDOR_ID1); 1738 if (val != 0 && val != 0xffff) 1739 return 0; 1740 } else { 1741 /* because the PCM or MASTER volume registers can be modified, 1742 * the REC_GAIN register is used for tests 1743 */ 1744 /* test if we can write to the record gain volume register */ 1745 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05); 1746 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05) 1747 return 0; 1748 } 1749 schedule_timeout_uninterruptible(1); 1750 } while (time_after_eq(end_time, jiffies)); 1751 return -ENODEV; 1771 1752 } 1772 1753 … … 1779 1760 * @rbus: the pointer to store the new AC97 bus instance. 1780 1761 * 1781 * Creates an AC97 bus component. An ac97_bus_tinstance is newly1762 * Creates an AC97 bus component. An struct snd_ac97_bus instance is newly 1782 1763 * allocated and initialized. 1783 1764 * 1784 1765 * The ops table must include valid callbacks (at least read and 1785 1766 * write). The other callbacks, wait and reset, are not mandatory. 1786 * 1767 * 1787 1768 * The clock is set to 48000. If another clock is needed, set 1788 1769 * (*rbus)->clock manually. … … 1793 1774 * Returns zero if successful, or a negative error code on failure. 1794 1775 */ 1795 int snd_ac97_bus(snd_card_t *card, int num, ac97_bus_ops_t *ops, 1796 void *private_data, ac97_bus_t **rbus) 1797 { 1776 int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops, 1777 void *private_data, struct snd_ac97_bus **rbus) 1778 { 1779 1798 1780 int err; 1799 ac97_bus_t*bus;1800 static snd_device_ops_tdev_ops = {1801 /*.dev_free =*/ snd_ac97_bus_dev_free, NULL, NULL, NULL 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1781 struct snd_ac97_bus *bus; 1782 static struct snd_device_ops dev_ops = { 1783 .dev_free = snd_ac97_bus_dev_free, 1784 }; 1785 1786 snd_assert(card != NULL, return -EINVAL); 1787 snd_assert(rbus != NULL, return -EINVAL); 1788 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 1789 if (bus == NULL) 1790 return -ENOMEM; 1791 bus->card = card; 1792 bus->num = num; 1793 bus->ops = ops; 1794 bus->private_data = private_data; 1795 bus->clock = 48000; 1796 spin_lock_init(&bus->bus_lock); 1797 snd_ac97_bus_proc_init(bus); 1798 if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops)) < 0) { 1799 snd_ac97_bus_free(bus); 1800 return err; 1801 } 1802 *rbus = bus; 1803 return 0; 1822 1804 } 1823 1805 … … 1826 1808 { 1827 1809 } 1810 1828 1811 /* register ac97 codec to bus */ 1829 static int snd_ac97_dev_register(s nd_device_t*device)1812 static int snd_ac97_dev_register(struct snd_device *device) 1830 1813 { 1831 1814 #if 0 1832 ac97_t*ac97 = device->device_data;1815 struct snd_ac97 *ac97 = device->device_data; 1833 1816 int err; 1834 1817 … … 1836 1819 ac97->dev.parent = ac97->bus->card->dev; 1837 1820 ac97->dev.release = ac97_device_release; 1838 strncpy(ac97->dev.bus_id, snd_ac97_get_short_name(ac97), BUS_ID_SIZE); 1821 snprintf(ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s", 1822 ac97->bus->card->number, ac97->num, 1823 snd_ac97_get_short_name(ac97)); 1839 1824 if ((err = device_register(&ac97->dev)) < 0) { 1840 1825 snd_printk(KERN_ERR "Can't register ac97 bus\n"); … … 1847 1832 1848 1833 /* unregister ac97 codec */ 1849 static int snd_ac97_dev_unregister(s nd_device_t*device)1834 static int snd_ac97_dev_unregister(struct snd_device *device) 1850 1835 { 1851 1836 #if 0 1852 ac97_t*ac97 = device->device_data;1837 struct snd_ac97 *ac97 = device->device_data; 1853 1838 if (ac97->dev.bus) 1854 1839 device_unregister(&ac97->dev); … … 1858 1843 #endif 1859 1844 } 1845 1860 1846 /* build_ops to do nothing */ 1861 1847 static struct snd_ac97_build_ops null_build_ops; 1862 1863 1848 1864 1849 /** … … 1869 1854 * @rac97: the pointer to store the new ac97 instance. 1870 1855 * 1871 * Creates an Codec97 component. An ac97_tinstance is newly1856 * Creates an Codec97 component. An struct snd_ac97 instance is newly 1872 1857 * allocated and initialized from the template. The codec 1873 1858 * is then initialized by the standard procedure. … … 1875 1860 * The template must include the codec number (num) and address (addr), 1876 1861 * and the private data (private_data). 1877 * 1862 * 1878 1863 * The ac97 instance is registered as a low-level device, so you don't 1879 1864 * have to release it manually. … … 1881 1866 * Returns zero if successful, or a negative error code on failure. 1882 1867 */ 1883 int snd_ac97_mixer( ac97_bus_t *bus, ac97_template_t *template, ac97_t**rac97)1884 { 1885 1886 ac97_t*ac97;1887 snd_card_t*card;1888 1889 1890 1891 const ac97_codec_id_t*pid;1892 static snd_device_ops_tops = {1893 .dev_free =snd_ac97_dev_free,1894 .dev_register =snd_ac97_dev_register,1895 .dev_unregister =snd_ac97_dev_unregister,1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 if (ac97->pci) { 1921 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor); 1922 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);1923 } 1924 if (bus->ops->reset) { 1925 bus->ops->reset(ac97); 1926 goto __access_ok; 1927 } 1928 1929 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16; 1930 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2); 1931 if (ac97->id && ac97->id != (unsigned int)-1) { 1932 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);1933 if (pid && (pid->flags & AC97_DEFAULT_POWER_OFF)) 1934 goto __access_ok;1935 } 1936 1937 /* reset to defaults */ 1938 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO)) 1939 snd_ac97_write(ac97, AC97_RESET, 0); 1940 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))1941 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);1942 if (bus->ops->wait)1943 bus->ops->wait(ac97);1944 else { 1945 udelay(50);1946 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO) 1947 err = ac97_reset_wait(ac97, HZ/2, 1);1948 else { 1949 err = ac97_reset_wait(ac97, HZ/2, 0);1950 if (err < 0) 1951 err = ac97_reset_wait(ac97, HZ/2, 1);1952 } 1953 if (err < 0) { 1954 snd_printk("AC'97 %d does not respond - RESET\n", ac97->num); 1955 /* proceed anyway - it's often non-critical */ 1956 } 1957 } 1958 __access_ok: 1959 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16; 1960 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);1961 if (ac97->id == 0x00000000 || ac97->id == 0xffffffff) { 1962 snd_printk(KERN_ERR "AC'97 %d access is not valid [0x%x], removing mixer.\n", ac97->num, ac97->id);1963 snd_ac97_free(ac97); 1964 return -EIO; 1965 } 1966 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);1967 if (pid) 1968 ac97->flags |= pid->flags; 1969 /* test for AC'97 */ 1970 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) { 1971 /* test if we can write to the record gain volume register */ 1972 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06); 1973 if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06) 1974 ac97->scaps |= AC97_SCAP_AUDIO; 1975 } 1976 if (ac97->scaps & AC97_SCAP_AUDIO) { 1977 ac97->caps = snd_ac97_read(ac97, AC97_RESET); 1978 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);1979 if (ac97->ext_id == 0xffff) /* invalid combination */ 1980 ac97->ext_id = 0; 1981 } 1982 1983 /* test for MC'97*/1984 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) { 1985 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID); 1986 if (ac97->ext_mid == 0xffff) /* invalid combination */ 1987 ac97->ext_mid = 0; 1988 if (ac97->ext_mid & 1) 1989 ac97->scaps |= AC97_SCAP_MODEM;1990 } 1991 1992 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) { 1993 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM))) 1994 snd_printk(KERN_ERR "AC'97 %d access error (not audio or modem codec)\n", ac97->num, ac97->id); 1995 snd_ac97_free(ac97); 1996 return -EACCES; 1997 } 1998 1999 if (bus->ops->reset) // FIXME: always skipping? 2000 goto __ready_ok;2001 2002 /* FIXME: add powerdown control */ 2003 if (ac97_is_audio(ac97)) { 2004 /* nothing should be in powerdown mode */ 2005 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0); 2006 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) { 2007 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */ 2008 udelay(100); 2009 2010 } 2011 /* nothing should be in powerdown mode*/2012 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE,0);2013 end_time = jiffies + (HZ / 10);2014 do { 2015 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 2016 goto __ready_ok;2017 set_current_state(TASK_UNINTERRUPTIBLE);2018 schedule_timeout(1); 2019 //schedule_timeout(HZ/10); 2020 } while (time_after_eq(end_time, jiffies));2021 snd_printk(KERN_ERR "AC'97 %d analog subsections not ready\n", ac97->num);2022 } 2023 2024 /* FIXME: add powerdown control */ 2025 if (ac97_is_modem(ac97)) { 2026 unsigned char tmp; 2027 2028 /* nothing should be in powerdown mode */ 2029 /* note: it's important to set the rate at first */ 2030 tmp = AC97_MEA_GPIO; 2031 if (ac97->ext_mid & AC97_MEI_LINE1) { 2032 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);2033 tmp |= AC97_MEA_ADC1 | AC97_MEA_DAC1; 2034 } 2035 if (ac97->ext_mid & AC97_MEI_LINE2) { 2036 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000); 2037 tmp |= AC97_MEA_ADC2 | AC97_MEA_DAC2; 2038 } 2039 if (ac97->ext_mid & AC97_MEI_HANDSET) { 2040 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000); 2041 tmp |= AC97_MEA_HADC | AC97_MEA_HDAC; 2042 } 2043 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);2044 udelay(100); 2045 /* nothing should be in powerdown mode */ 2046 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS,0);2047 end_time = jiffies + (HZ / 10); 2048 do { 2049 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp) 2050 goto __ready_ok; 2051 set_current_state(TASK_UNINTERRUPTIBLE); 2052 //schedule_timeout(HZ/10);2053 schedule_timeout(1);2054 2055 snd_printk(KERN_ERR"MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));2056 2057 2058 __ready_ok:2059 2060 2061 2062 2063 if (ac97->ext_id & 0x01c9) {/* L/R, MIC, SDAC, LDAC VRA support */2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 if (ac97_is_audio(ac97)) { 2113 char comp[16]; 2114 if (card->mixername[0] == '\0') { 2115 strcpy(card->mixername, name); 2116 } else { 2117 if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)){2118 strcat(card->mixername, ","); 2119 strcat(card->mixername, name);2120 } 2121 2122 sprintf(comp, "AC97a:%08x", ac97->id); 2123 if ((err = snd_component_add(card, comp)) < 0) { 2124 snd_ac97_free(ac97); 2125 return err-2000;2126 } 2127 if (snd_ac97_mixer_build(ac97) < 0) { 2128 snd_ac97_free(ac97); 2129 return -ENOMEM;2130 } 2131 2132 if (ac97_is_modem(ac97)) { 2133 char comp[16]; 2134 if (card->mixername[0] == '\0') { 2135 strcpy(card->mixername, name); 2136 } else { 2137 if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)){2138 strcat(card->mixername, ","); 2139 strcat(card->mixername, name);2140 } 2141 2142 sprintf(comp, "AC97m:%08x", ac97->id); 2143 if ((err = snd_component_add(card, comp)) < 0) { 2144 snd_ac97_free(ac97); 2145 return err;2146 } 2147 if (snd_ac97_modem_build(card, ac97) < 0) { 2148 snd_ac97_free(ac97); 2149 return -ENOMEM;2150 } 2151 2152 /* make sure the proper powerdown bits are cleared */ 2153 if (ac97->scaps && ac97_is_audio(ac97)) { 2154 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2155 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 2156 reg &= ~AC97_EA_PRJ; 2157 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) 2158 reg &= ~(AC97_EA_PRI | AC97_EA_PRK); 2159 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);2160 } 2161 snd_ac97_proc_init(ac97); 2162 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) { 2163 snd_ac97_free(ac97); 2164 return err;2165 } 2166 *rac97 = ac97; 2167 2168 1868 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template, struct snd_ac97 **rac97) 1869 { 1870 int err; 1871 struct snd_ac97 *ac97; 1872 struct snd_card *card; 1873 char name[64]; 1874 unsigned long end_time; 1875 unsigned int reg; 1876 const struct ac97_codec_id *pid; 1877 static struct snd_device_ops ops = { 1878 .dev_free = snd_ac97_dev_free, 1879 .dev_register = snd_ac97_dev_register, 1880 .dev_unregister = snd_ac97_dev_unregister, 1881 }; 1882 1883 snd_assert(rac97 != NULL, return -EINVAL); 1884 *rac97 = NULL; 1885 snd_assert(bus != NULL && template != NULL, return -EINVAL); 1886 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL); 1887 1888 card = bus->card; 1889 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL); 1890 if (ac97 == NULL) 1891 return -ENOMEM; 1892 ac97->private_data = template->private_data; 1893 ac97->private_free = template->private_free; 1894 ac97->bus = bus; 1895 ac97->pci = template->pci; 1896 ac97->num = template->num; 1897 ac97->addr = template->addr; 1898 ac97->scaps = template->scaps; 1899 ac97->limited_regs = template->limited_regs; 1900 memcpy(ac97->reg_accessed, template->reg_accessed, sizeof(ac97->reg_accessed)); 1901 bus->codec[ac97->num] = ac97; 1902 init_MUTEX(&ac97->reg_mutex); 1903 init_MUTEX(&ac97->page_mutex); 1904 1905 #ifdef CONFIG_PCI 1906 if (ac97->pci) { 1907 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor); 1908 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device); 1909 } 1910 #endif 1911 if (bus->ops->reset) { 1912 bus->ops->reset(ac97); 1913 goto __access_ok; 1914 } 1915 1916 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16; 1917 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2); 1918 if (ac97->id && ac97->id != (unsigned int)-1) { 1919 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id); 1920 if (pid && (pid->flags & AC97_DEFAULT_POWER_OFF)) 1921 goto __access_ok; 1922 } 1923 1924 /* reset to defaults */ 1925 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO)) 1926 snd_ac97_write(ac97, AC97_RESET, 0); 1927 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM)) 1928 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0); 1929 if (bus->ops->wait) 1930 bus->ops->wait(ac97); 1931 else { 1932 udelay(50); 1933 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO) 1934 err = ac97_reset_wait(ac97, HZ/2, 1); 1935 else { 1936 err = ac97_reset_wait(ac97, HZ/2, 0); 1937 if (err < 0) 1938 err = ac97_reset_wait(ac97, HZ/2, 1); 1939 } 1940 if (err < 0) { 1941 snd_printk(KERN_WARNING "AC'97 %d does not respond - RESET\n", ac97->num); 1942 /* proceed anyway - it's often non-critical */ 1943 } 1944 } 1945 __access_ok: 1946 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16; 1947 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2); 1948 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) && 1949 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) { 1950 snd_printk(KERN_ERR "AC'97 %d access is not valid [0x%x], removing mixer.\n", ac97->num, ac97->id); 1951 snd_ac97_free(ac97); 1952 return -EIO; 1953 } 1954 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id); 1955 if (pid) 1956 ac97->flags |= pid->flags; 1957 1958 /* test for AC'97 */ 1959 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) { 1960 /* test if we can write to the record gain volume register */ 1961 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06); 1962 if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06) 1963 ac97->scaps |= AC97_SCAP_AUDIO; 1964 } 1965 if (ac97->scaps & AC97_SCAP_AUDIO) { 1966 ac97->caps = snd_ac97_read(ac97, AC97_RESET); 1967 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 1968 if (ac97->ext_id == 0xffff) /* invalid combination */ 1969 ac97->ext_id = 0; 1970 } 1971 1972 /* test for MC'97 */ 1973 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) { 1974 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID); 1975 if (ac97->ext_mid == 0xffff) /* invalid combination */ 1976 ac97->ext_mid = 0; 1977 if (ac97->ext_mid & 1) 1978 ac97->scaps |= AC97_SCAP_MODEM; 1979 } 1980 1981 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) { 1982 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM))) 1983 snd_printk(KERN_ERR "AC'97 %d access error (not audio or modem codec)\n", ac97->num); 1984 snd_ac97_free(ac97); 1985 return -EACCES; 1986 } 1987 1988 if (bus->ops->reset) // FIXME: always skipping? 1989 goto __ready_ok; 1990 1991 /* FIXME: add powerdown control */ 1992 if (ac97_is_audio(ac97)) { 1993 /* nothing should be in powerdown mode */ 1994 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0); 1995 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) { 1996 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */ 1997 udelay(100); 1998 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0); 1999 } 2000 /* nothing should be in powerdown mode */ 2001 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0); 2002 end_time = jiffies + (HZ / 10); 2003 do { 2004 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 2005 goto __ready_ok; 2006 schedule_timeout_uninterruptible(1); 2007 } while (time_after_eq(end_time, jiffies)); 2008 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num); 2009 } 2010 2011 /* FIXME: add powerdown control */ 2012 if (ac97_is_modem(ac97)) { 2013 unsigned char tmp; 2014 2015 /* nothing should be in powerdown mode */ 2016 /* note: it's important to set the rate at first */ 2017 tmp = AC97_MEA_GPIO; 2018 if (ac97->ext_mid & AC97_MEI_LINE1) { 2019 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000); 2020 tmp |= AC97_MEA_ADC1 | AC97_MEA_DAC1; 2021 } 2022 if (ac97->ext_mid & AC97_MEI_LINE2) { 2023 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000); 2024 tmp |= AC97_MEA_ADC2 | AC97_MEA_DAC2; 2025 } 2026 if (ac97->ext_mid & AC97_MEI_HANDSET) { 2027 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000); 2028 tmp |= AC97_MEA_HADC | AC97_MEA_HDAC; 2029 } 2030 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0); 2031 udelay(100); 2032 /* nothing should be in powerdown mode */ 2033 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0); 2034 end_time = jiffies + (HZ / 10); 2035 do { 2036 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp) 2037 goto __ready_ok; 2038 schedule_timeout_uninterruptible(1); 2039 } while (time_after_eq(end_time, jiffies)); 2040 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS)); 2041 } 2042 2043 __ready_ok: 2044 if (ac97_is_audio(ac97)) 2045 ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT; 2046 else 2047 ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT; 2048 if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */ 2049 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2050 reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */ 2051 if (! bus->no_vra) 2052 reg |= ac97->ext_id & 0x0009; /* VRA/VRM */ 2053 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg); 2054 } 2055 if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) { 2056 /* Intel controllers require double rate data to be put in 2057 * slots 7+8, so let's hope the codec supports it. */ 2058 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78); 2059 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78) 2060 ac97->flags |= AC97_DOUBLE_RATE; 2061 /* restore to slots 10/11 to avoid the confliction with surrounds */ 2062 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0); 2063 } 2064 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */ 2065 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]); 2066 snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]); 2067 } else { 2068 ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000; 2069 if (ac97->flags & AC97_DOUBLE_RATE) 2070 ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000; 2071 ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000; 2072 } 2073 if (ac97->ext_id & AC97_EI_SPDIF) { 2074 /* codec specific code (patch) should override these values */ 2075 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000; 2076 } 2077 if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */ 2078 snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]); 2079 } else { 2080 ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000; 2081 } 2082 if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */ 2083 snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]); 2084 ac97->scaps |= AC97_SCAP_SURROUND_DAC; 2085 } 2086 if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */ 2087 snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]); 2088 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 2089 } 2090 /* additional initializations */ 2091 if (bus->ops->init) 2092 bus->ops->init(ac97); 2093 snd_ac97_get_name(ac97, ac97->id, name, !ac97_is_audio(ac97)); 2094 snd_ac97_get_name(NULL, ac97->id, name, !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code 2095 if (! ac97->build_ops) 2096 ac97->build_ops = &null_build_ops; 2097 2098 if (ac97_is_audio(ac97)) { 2099 char comp[16]; 2100 if (card->mixername[0] == '\0') { 2101 strcpy(card->mixername, name); 2102 } else { 2103 if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)) { 2104 strcat(card->mixername, ","); 2105 strcat(card->mixername, name); 2106 } 2107 } 2108 sprintf(comp, "AC97a:%08x", ac97->id); 2109 if ((err = snd_component_add(card, comp)) < 0) { 2110 snd_ac97_free(ac97); 2111 return err; 2112 } 2113 if (snd_ac97_mixer_build(ac97) < 0) { 2114 snd_ac97_free(ac97); 2115 return -ENOMEM; 2116 } 2117 } 2118 if (ac97_is_modem(ac97)) { 2119 char comp[16]; 2120 if (card->mixername[0] == '\0') { 2121 strcpy(card->mixername, name); 2122 } else { 2123 if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)) { 2124 strcat(card->mixername, ","); 2125 strcat(card->mixername, name); 2126 } 2127 } 2128 sprintf(comp, "AC97m:%08x", ac97->id); 2129 if ((err = snd_component_add(card, comp)) < 0) { 2130 snd_ac97_free(ac97); 2131 return err; 2132 } 2133 if (snd_ac97_modem_build(card, ac97) < 0) { 2134 snd_ac97_free(ac97); 2135 return -ENOMEM; 2136 } 2137 } 2138 /* make sure the proper powerdown bits are cleared */ 2139 if (ac97->scaps && ac97_is_audio(ac97)) { 2140 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2141 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 2142 reg &= ~AC97_EA_PRJ; 2143 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) 2144 reg &= ~(AC97_EA_PRI | AC97_EA_PRK); 2145 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg); 2146 } 2147 snd_ac97_proc_init(ac97); 2148 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) { 2149 snd_ac97_free(ac97); 2150 return err; 2151 } 2152 *rac97 = ac97; 2153 return 0; 2169 2154 } 2170 2155 … … 2176 2161 * are not changed, so that the values can be restored in snd_ac97_resume(). 2177 2162 */ 2178 static void snd_ac97_powerdown(ac97_t *ac97) 2179 { 2180 unsigned short power; 2181 2182 if (ac97_is_audio(ac97)) { 2183 /* some codecs have stereo mute bits */ 2184 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f); 2185 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f); 2186 } 2187 power = ac97->regs[AC97_POWERDOWN] | 0x8000; /* EAPD */ 2188 power |= 0x4000; /* Headphone amplifier powerdown */ 2189 power |= 0x0300; /* ADC & DAC powerdown */ 2190 snd_ac97_write(ac97, AC97_POWERDOWN, power); 2191 udelay(100); 2192 power |= 0x0400; /* Analog Mixer powerdown (Vref on) */ 2193 snd_ac97_write(ac97, AC97_POWERDOWN, power); 2194 udelay(100); 2163 static void snd_ac97_powerdown(struct snd_ac97 *ac97) 2164 { 2165 unsigned short power; 2166 2167 if (ac97_is_audio(ac97)) { 2168 /* some codecs have stereo mute bits */ 2169 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f); 2170 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f); 2171 } 2172 2173 power = ac97->regs[AC97_POWERDOWN] | 0x8000; /* EAPD */ 2174 power |= 0x4000; /* Headphone amplifier powerdown */ 2175 power |= 0x0300; /* ADC & DAC powerdown */ 2176 snd_ac97_write(ac97, AC97_POWERDOWN, power); 2177 udelay(100); 2178 power |= 0x0400; /* Analog Mixer powerdown (Vref on) */ 2179 snd_ac97_write(ac97, AC97_POWERDOWN, power); 2180 udelay(100); 2195 2181 #if 0 2196 2197 2198 2182 /* FIXME: this causes click noises on some boards at resume */ 2183 power |= 0x3800; /* AC-link powerdown, internal Clk disable */ 2184 snd_ac97_write(ac97, AC97_POWERDOWN, power); 2199 2185 #endif 2200 2186 } … … 2208 2194 * Suspends the codec, power down the chip. 2209 2195 */ 2210 void snd_ac97_suspend(ac97_t *ac97) 2211 { 2212 if (ac97->build_ops->suspend) 2213 ac97->build_ops->suspend(ac97); 2214 snd_ac97_powerdown(ac97); 2196 void snd_ac97_suspend(struct snd_ac97 *ac97) 2197 { 2198 if (! ac97) 2199 return; 2200 if (ac97->build_ops->suspend) 2201 ac97->build_ops->suspend(ac97); 2202 snd_ac97_powerdown(ac97); 2215 2203 } 2216 2204 … … 2218 2206 * restore ac97 status 2219 2207 */ 2220 void snd_ac97_restore_status( ac97_t*ac97)2221 { 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2208 void snd_ac97_restore_status(struct snd_ac97 *ac97) 2209 { 2210 int i; 2211 2212 for (i = 2; i < 0x7c ; i += 2) { 2213 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 2214 continue; 2215 /* restore only accessible registers 2216 * some chip (e.g. nm256) may hang up when unsupported registers 2217 * are accessed..! 2218 */ 2219 if (test_bit(i, ac97->reg_accessed)) { 2220 snd_ac97_write(ac97, i, ac97->regs[i]); 2221 snd_ac97_read(ac97, i); 2222 } 2223 } 2236 2224 } 2237 2225 … … 2239 2227 * restore IEC958 status 2240 2228 */ 2241 void snd_ac97_restore_iec958(ac97_t *ac97) 2242 { 2243 if (ac97->ext_id & AC97_EI_SPDIF) { 2244 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) { 2245 /* reset spdif status */ 2246 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 2247 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]); 2248 if (ac97->flags & AC97_CS_SPDIF) 2249 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]); 2250 else 2251 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]); 2252 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */ 2253 } 2254 } 2255 } 2256 2229 void snd_ac97_restore_iec958(struct snd_ac97 *ac97) 2230 { 2231 if (ac97->ext_id & AC97_EI_SPDIF) { 2232 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) { 2233 /* reset spdif status */ 2234 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 2235 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]); 2236 if (ac97->flags & AC97_CS_SPDIF) 2237 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]); 2238 else 2239 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]); 2240 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */ 2241 } 2242 } 2243 } 2257 2244 2258 2245 /** … … 2263 2250 * old register values. 2264 2251 */ 2265 void snd_ac97_resume(ac97_t *ac97) 2266 { 2267 unsigned long end_time; 2268 2269 if (ac97->bus->ops->reset) { 2270 ac97->bus->ops->reset(ac97); 2271 goto __reset_ready; 2272 } 2273 2274 snd_ac97_write(ac97, AC97_POWERDOWN, 0); 2275 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) { 2276 snd_ac97_write(ac97, AC97_RESET, 0); 2277 udelay(100); 2278 snd_ac97_write(ac97, AC97_POWERDOWN, 0); 2279 } 2280 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0); 2281 2282 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]); 2283 if (ac97_is_audio(ac97)) { 2284 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101); 2285 end_time = jiffies + msecs_to_jiffies(100); 2286 do { 2287 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2288 break; 2289 set_current_state(TASK_UNINTERRUPTIBLE); 2290 schedule_timeout(1); 2291 } while (time_after_eq(end_time, jiffies)); 2292 /* FIXME: extra delay */ 2293 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2294 if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000) 2295 msleep(250); 2296 } else { 2297 end_time = jiffies + msecs_to_jiffies(100); 2298 do { 2299 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2300 if (val != 0xffff && (val & 1) != 0) 2301 break; 2302 set_current_state(TASK_UNINTERRUPTIBLE); 2303 schedule_timeout(1); 2304 } while (time_after_eq(end_time, jiffies)); 2305 } 2252 void snd_ac97_resume(struct snd_ac97 *ac97) 2253 { 2254 unsigned long end_time; 2255 2256 if (! ac97) 2257 return; 2258 2259 if (ac97->bus->ops->reset) { 2260 ac97->bus->ops->reset(ac97); 2261 goto __reset_ready; 2262 } 2263 2264 snd_ac97_write(ac97, AC97_POWERDOWN, 0); 2265 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) { 2266 snd_ac97_write(ac97, AC97_RESET, 0); 2267 udelay(100); 2268 snd_ac97_write(ac97, AC97_POWERDOWN, 0); 2269 } 2270 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0); 2271 2272 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]); 2273 if (ac97_is_audio(ac97)) { 2274 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101); 2275 end_time = jiffies + msecs_to_jiffies(100); 2276 do { 2277 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2278 break; 2279 schedule_timeout_uninterruptible(1); 2280 } while (time_after_eq(end_time, jiffies)); 2281 /* FIXME: extra delay */ 2282 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2283 if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000) 2284 msleep(250); 2285 } else { 2286 end_time = jiffies + msecs_to_jiffies(100); 2287 do { 2288 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2289 if (val != 0xffff && (val & 1) != 0) 2290 break; 2291 schedule_timeout_uninterruptible(1); 2292 } while (time_after_eq(end_time, jiffies)); 2293 } 2306 2294 __reset_ready: 2307 2295 2308 if (ac97->bus->ops->init) 2309 ac97->bus->ops->init(ac97); 2310 if (ac97->build_ops->resume) 2311 ac97->build_ops->resume(ac97); 2312 else { 2313 snd_ac97_restore_status(ac97); 2314 snd_ac97_restore_iec958(ac97); 2315 } 2296 if (ac97->bus->ops->init) 2297 ac97->bus->ops->init(ac97); 2298 2299 if (ac97->build_ops->resume) 2300 ac97->build_ops->resume(ac97); 2301 else { 2302 snd_ac97_restore_status(ac97); 2303 snd_ac97_restore_iec958(ac97); 2304 } 2316 2305 } 2317 2306 #endif … … 2319 2308 2320 2309 /* 2310 * Hardware tuning 2321 2311 */ 2322 2312 static void set_ctl_name(char *dst, const char *src, const char *suffix) 2323 2313 { 2324 if (suffix) 2325 sprintf(dst, "%s %s", src, suffix); 2326 else 2327 strcpy(dst, src); 2328 } 2329 2330 int snd_ac97_remove_ctl(ac97_t *ac97, const char *name, const char *suffix){ 2331 snd_ctl_elem_id_t id; 2332 memset(&id, 0, sizeof(id)); 2333 set_ctl_name(id.name, name, suffix); 2334 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2335 return snd_ctl_remove_id(ac97->bus->card, &id); 2336 } 2337 2338 static snd_kcontrol_t *ctl_find(ac97_t *ac97, const char *name, const char *suffix) 2339 { 2340 snd_ctl_elem_id_t sid; 2341 memset(&sid, 0, sizeof(sid)); 2342 set_ctl_name(sid.name, name, suffix); 2343 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2344 return snd_ctl_find_id(ac97->bus->card, &sid); 2345 } 2346 2347 int snd_ac97_rename_ctl(ac97_t *ac97, const char *src, const char *dst, const char *suffix) 2348 { 2349 snd_kcontrol_t *kctl = ctl_find(ac97, src, suffix); 2350 if (kctl) { 2351 set_ctl_name(kctl->id.name, dst, suffix); 2352 return 0; 2353 } 2354 return -ENOENT; 2314 if (suffix) 2315 sprintf(dst, "%s %s", src, suffix); 2316 else 2317 strcpy(dst, src); 2318 } 2319 2320 /* remove the control with the given name and optional suffix */ 2321 int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name, const char *suffix) 2322 { 2323 struct snd_ctl_elem_id id; 2324 memset(&id, 0, sizeof(id)); 2325 set_ctl_name(id.name, name, suffix); 2326 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2327 return snd_ctl_remove_id(ac97->bus->card, &id); 2328 } 2329 2330 static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix) 2331 { 2332 struct snd_ctl_elem_id sid; 2333 memset(&sid, 0, sizeof(sid)); 2334 set_ctl_name(sid.name, name, suffix); 2335 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2336 return snd_ctl_find_id(ac97->bus->card, &sid); 2337 } 2338 2339 /* rename the control with the given name and optional suffix */ 2340 int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src, const char *dst, const char *suffix) 2341 { 2342 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix); 2343 if (kctl) { 2344 set_ctl_name(kctl->id.name, dst, suffix); 2345 return 0; 2346 } 2347 return -ENOENT; 2355 2348 } 2356 2349 2357 2350 /* rename both Volume and Switch controls - don't check the return value */ 2358 void snd_ac97_rename_vol_ctl(ac97_t *ac97, const char *src, const char *dst) 2359 { 2360 snd_ac97_rename_ctl(ac97, src, dst, "Switch"); 2361 snd_ac97_rename_ctl(ac97, src, dst, "Volume"); 2362 } 2363 2364 int snd_ac97_swap_ctl(ac97_t *ac97, const char *s1, const char *s2, const char *suffix) 2365 { 2366 snd_kcontrol_t *kctl1, *kctl2; 2367 kctl1 = ctl_find(ac97, s1, suffix); 2368 kctl2 = ctl_find(ac97, s2, suffix); 2369 if (kctl1 && kctl2) { 2370 set_ctl_name(kctl1->id.name, s2, suffix); 2371 set_ctl_name(kctl2->id.name, s1, suffix); 2372 return 0; 2373 } 2374 return -ENOENT; 2351 void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src, const char *dst) 2352 { 2353 snd_ac97_rename_ctl(ac97, src, dst, "Switch"); 2354 snd_ac97_rename_ctl(ac97, src, dst, "Volume"); 2355 } 2356 2357 /* swap controls */ 2358 int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, const char *s2, const char *suffix) 2359 { 2360 struct snd_kcontrol *kctl1, *kctl2; 2361 kctl1 = ctl_find(ac97, s1, suffix); 2362 kctl2 = ctl_find(ac97, s2, suffix); 2363 if (kctl1 && kctl2) { 2364 set_ctl_name(kctl1->id.name, s2, suffix); 2365 set_ctl_name(kctl2->id.name, s1, suffix); 2366 return 0; 2367 } 2368 return -ENOENT; 2375 2369 } 2376 2370 2377 2371 #if 1 2378 2372 /* bind hp and master controls instead of using only hp control */ 2379 static int bind_hp_volsw_put(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)2373 static int bind_hp_volsw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2380 2374 { 2381 2375 int err = snd_ac97_put_volsw(kcontrol, ucontrol); … … 2390 2384 2391 2385 /* ac97 tune: bind Master and Headphone controls */ 2392 static int tune_hp_only( ac97_t*ac97)2393 { 2394 s nd_kcontrol_t*msw = ctl_find(ac97, "Master Playback Switch", NULL);2395 s nd_kcontrol_t*mvol = ctl_find(ac97, "Master Playback Volume", NULL);2386 static int tune_hp_only(struct snd_ac97 *ac97) 2387 { 2388 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL); 2389 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL); 2396 2390 if (! msw || ! mvol) 2397 2391 return -ENOENT; … … 2405 2399 #else 2406 2400 /* ac97 tune: use Headphone control as master */ 2407 static int tune_hp_only( ac97_t*ac97)2401 static int tune_hp_only(struct snd_ac97 *ac97) 2408 2402 { 2409 2403 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL) … … 2417 2411 2418 2412 /* ac97 tune: swap Headphone and Master controls */ 2419 static int tune_swap_hp( ac97_t*ac97)2413 static int tune_swap_hp(struct snd_ac97 *ac97) 2420 2414 { 2421 2415 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL) … … 2427 2421 2428 2422 /* ac97 tune: swap Surround and Master controls */ 2429 static int tune_swap_surround( ac97_t*ac97)2423 static int tune_swap_surround(struct snd_ac97 *ac97) 2430 2424 { 2431 2425 if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") || … … 2435 2429 } 2436 2430 2437 2438 static int tune_ad_sharing( ac97_t*ac97)2439 { 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 } 2450 2451 static const s nd_kcontrol_new_t snd_ac97_alc_jack_detect =2431 /* ac97 tune: set up mic sharing for AD codecs */ 2432 static int tune_ad_sharing(struct snd_ac97 *ac97) 2433 { 2434 unsigned short scfg; 2435 if ((ac97->id & 0xffffff00) != 0x41445300) { 2436 snd_printk(KERN_ERR "ac97_quirk AD_SHARING is only for AD codecs\n"); 2437 return -EINVAL; 2438 } 2439 /* Turn on OMS bit to route microphone to back panel */ 2440 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 2441 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200); 2442 return 0; 2443 } 2444 2445 static const struct snd_kcontrol_new snd_ac97_alc_jack_detect = 2452 2446 AC97_SINGLE("Jack Detect", AC97_ALC650_CLOCK, 5, 1, 0); 2453 2447 2454 static int tune_alc_jack(ac97_t *ac97) 2455 { 2456 if ((ac97->id & 0xffffff00) != 0x414c4700) { 2457 snd_printk(KERN_ERR "ac97_quirk ALC_JACK is only for Realtek codecs\n"); 2458 return -EINVAL; 2459 } 2460 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */ 2461 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */ 2462 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97)); 2463 } 2464 2465 static int tune_inv_eapd(ac97_t *ac97) 2466 { 2467 snd_kcontrol_t *kctl = ctl_find(ac97, "External Amplifier", NULL); 2468 if (! kctl) 2469 return -ENOENT; 2470 set_inv_eapd(ac97, kctl); 2471 return 0; 2472 } 2473 2474 static int master_mute_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 2475 { 2476 int err = snd_ac97_put_volsw(kcontrol, ucontrol); 2477 if (err > 0) { 2478 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2479 int shift = (kcontrol->private_value >> 8) & 0x0f; 2480 int rshift = (kcontrol->private_value >> 12) & 0x0f; 2481 unsigned short mask; 2482 if (shift != rshift) 2483 mask = 0x8080; 2484 else 2485 mask = 0x8000; 2486 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 2487 (ac97->regs[AC97_MASTER] & mask) == mask ? 2488 0x8000 : 0); 2489 } 2490 return err; 2491 } 2492 2493 static int tune_mute_led(ac97_t *ac97) 2494 { 2495 snd_kcontrol_t *msw = ctl_find(ac97, "Master Playback Switch", NULL); 2496 if (! msw) 2497 return -ENOENT; 2498 msw->put = master_mute_sw_put; 2499 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL); 2500 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */ 2501 return 0; 2448 /* ac97 tune: set up ALC jack-select */ 2449 static int tune_alc_jack(struct snd_ac97 *ac97) 2450 { 2451 if ((ac97->id & 0xffffff00) != 0x414c4700) { 2452 snd_printk(KERN_ERR "ac97_quirk ALC_JACK is only for Realtek codecs\n"); 2453 return -EINVAL; 2454 } 2455 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */ 2456 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */ 2457 if (ac97->id == AC97_ID_ALC658D) 2458 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2459 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97)); 2460 } 2461 2462 /* ac97 tune: inversed EAPD bit */ 2463 static int tune_inv_eapd(struct snd_ac97 *ac97) 2464 { 2465 struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL); 2466 if (! kctl) 2467 return -ENOENT; 2468 set_inv_eapd(ac97, kctl); 2469 return 0; 2470 } 2471 2472 static int master_mute_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2473 { 2474 int err = snd_ac97_put_volsw(kcontrol, ucontrol); 2475 if (err > 0) { 2476 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2477 int shift = (kcontrol->private_value >> 8) & 0x0f; 2478 int rshift = (kcontrol->private_value >> 12) & 0x0f; 2479 unsigned short mask; 2480 if (shift != rshift) 2481 mask = 0x8080; 2482 else 2483 mask = 0x8000; 2484 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 2485 (ac97->regs[AC97_MASTER] & mask) == mask ? 2486 0x8000 : 0); 2487 } 2488 return err; 2489 } 2490 2491 /* ac97 tune: EAPD controls mute LED bound with the master mute */ 2492 static int tune_mute_led(struct snd_ac97 *ac97) 2493 { 2494 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL); 2495 if (! msw) 2496 return -ENOENT; 2497 msw->put = master_mute_sw_put; 2498 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL); 2499 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */ 2500 return 0; 2501 } 2502 2503 static int hp_master_mute_sw_put(struct snd_kcontrol *kcontrol, 2504 struct snd_ctl_elem_value *ucontrol) 2505 { 2506 int err = bind_hp_volsw_put(kcontrol, ucontrol); 2507 if (err > 0) { 2508 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2509 int shift = (kcontrol->private_value >> 8) & 0x0f; 2510 int rshift = (kcontrol->private_value >> 12) & 0x0f; 2511 unsigned short mask; 2512 if (shift != rshift) 2513 mask = 0x8080; 2514 else 2515 mask = 0x8000; 2516 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 2517 (ac97->regs[AC97_MASTER] & mask) == mask ? 2518 0x8000 : 0); 2519 } 2520 return err; 2521 } 2522 2523 static int tune_hp_mute_led(struct snd_ac97 *ac97) 2524 { 2525 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL); 2526 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL); 2527 if (! msw || ! mvol) 2528 return -ENOENT; 2529 msw->put = hp_master_mute_sw_put; 2530 mvol->put = bind_hp_volsw_put; 2531 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL); 2532 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch"); 2533 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume"); 2534 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */ 2535 return 0; 2502 2536 } 2503 2537 2504 2538 struct quirk_table { 2505 2506 int (*func)(ac97_t*);2539 const char *name; 2540 int (*func)(struct snd_ac97 *); 2507 2541 }; 2508 2542 2509 2543 static struct quirk_table applicable_quirks[] = { 2510 { "none", NULL }, 2511 { "hp_only", tune_hp_only }, 2512 { "swap_hp", tune_swap_hp }, 2513 { "swap_surround", tune_swap_surround }, 2514 { "ad_sharing", tune_ad_sharing }, 2515 { "alc_jack", tune_alc_jack }, 2516 { "inv_eapd", tune_inv_eapd }, 2517 { "mute_led", tune_mute_led }, 2544 { "none", NULL }, 2545 { "hp_only", tune_hp_only }, 2546 { "swap_hp", tune_swap_hp }, 2547 { "swap_surround", tune_swap_surround }, 2548 { "ad_sharing", tune_ad_sharing }, 2549 { "alc_jack", tune_alc_jack }, 2550 { "inv_eapd", tune_inv_eapd }, 2551 { "mute_led", tune_mute_led }, 2552 { "hp_mute_led", tune_hp_mute_led }, 2518 2553 }; 2519 2554 2520 2555 /* apply the quirk with the given type */ 2521 static int apply_quirk( ac97_t*ac97, int type)2522 { 2523 2524 2525 2526 2527 2528 2529 2556 static int apply_quirk(struct snd_ac97 *ac97, int type) 2557 { 2558 if (type <= 0) 2559 return 0; 2560 else if (type >= ARRAY_SIZE(applicable_quirks)) 2561 return -EINVAL; 2562 if (applicable_quirks[type].func) 2563 return applicable_quirks[type].func(ac97); 2564 return 0; 2530 2565 } 2531 2566 2532 2567 /* apply the quirk with the given name */ 2533 static int apply_quirk_str( ac97_t*ac97, const char *typestr)2534 { 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2568 static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr) 2569 { 2570 int i; 2571 struct quirk_table *q; 2572 2573 for (i = 0; i < ARRAY_SIZE(applicable_quirks); i++) { 2574 q = &applicable_quirks[i]; 2575 if (q->name && ! strcmp(typestr, q->name)) 2576 return apply_quirk(ac97, i); 2577 } 2578 /* for compatibility, accept the numbers, too */ 2579 if (*typestr >= '0' && *typestr <= '9') 2580 return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10)); 2581 return -EINVAL; 2547 2582 } 2548 2583 … … 2551 2586 * @ac97: the ac97 instance 2552 2587 * @quirk: quirk list 2553 * @override: explicit quirk value (overrides the list if no t AC97_TUNE_DEFAULT)2588 * @override: explicit quirk value (overrides the list if non-NULL) 2554 2589 * 2555 2590 * Do some workaround for each pci device, such as renaming of the … … 2560 2595 */ 2561 2596 2562 int snd_ac97_tune_hardware( ac97_t*ac97, struct ac97_quirk *quirk, const char *override)2563 { 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2597 int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override) 2598 { 2599 int result; 2600 2601 /* quirk overriden? */ 2602 if (override && strcmp(override, "-1") && strcmp(override, "default")) { 2603 result = apply_quirk_str(ac97, override); 2604 if (result < 0) 2605 snd_printk(KERN_ERR "applying quirk type %s failed (%d)\n", override, result); 2606 return result; 2607 } 2608 2609 if (! quirk) 2610 return -EINVAL; 2611 2612 for (; quirk->subvendor; quirk++) { 2613 if (quirk->subvendor != ac97->subsystem_vendor) 2614 continue; 2615 if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) || 2616 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) { 2617 if (quirk->codec_id && quirk->codec_id != ac97->id) 2618 continue; 2619 snd_printdd("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, ac97->subsystem_device); 2620 result = apply_quirk(ac97, quirk->type); 2621 if (result < 0) 2622 snd_printk(KERN_ERR "applying quirk type %d for %s failed (%d)\n", quirk->type, quirk->name, result); 2623 return result; 2624 } 2625 } 2626 return 0; 2592 2627 } 2593 2628 … … 2602 2637 EXPORT_SYMBOL(snd_ac97_update); 2603 2638 EXPORT_SYMBOL(snd_ac97_update_bits); 2639 EXPORT_SYMBOL(snd_ac97_get_short_name); 2604 2640 EXPORT_SYMBOL(snd_ac97_bus); 2605 2641 EXPORT_SYMBOL(snd_ac97_mixer); … … 2621 2657 static int __init alsa_ac97_init(void) 2622 2658 { 2623 2659 return 0; 2624 2660 } 2625 2661 -
GPL/trunk/alsa-kernel/pci/ac97/ac97_id.h
r32 r72 46 46 #define AC97_ID_CS4205 0x43525958 47 47 #define AC97_ID_CS_MASK 0xfffffff8 /* bit 0-2: rev */ 48 #define AC97_ID_ALC100 48 #define AC97_ID_ALC100 0x414c4300 49 49 #define AC97_ID_ALC650 0x414c4720 50 #define AC97_ID_ALC650D 51 #define AC97_ID_ALC650E 52 #define AC97_ID_ALC650F 53 #define AC97_ID_ALC655 54 #define AC97_ID_ALC658 55 #define AC97_ID_ALC658D 56 #define AC97_ID_ALC850 50 #define AC97_ID_ALC650D 0x414c4721 51 #define AC97_ID_ALC650E 0x414c4722 52 #define AC97_ID_ALC650F 0x414c4723 53 #define AC97_ID_ALC655 0x414c4760 54 #define AC97_ID_ALC658 0x414c4780 55 #define AC97_ID_ALC658D 0x414c4781 56 #define AC97_ID_ALC850 0x414c4790 57 57 #define AC97_ID_YMF753 0x594d4803 58 58 #define AC97_ID_VT1616 0x49434551 59 59 #define AC97_ID_CM9738 0x434d4941 60 60 #define AC97_ID_CM9739 0x434d4961 61 #define AC97_ID_CM9761_78 62 #define AC97_ID_CM9761_82 63 #define AC97_ID_CM9761_83 61 #define AC97_ID_CM9761_78 0x434d4978 62 #define AC97_ID_CM9761_82 0x434d4982 63 #define AC97_ID_CM9761_83 0x434d4983 -
GPL/trunk/alsa-kernel/pci/ac97/ac97_local.h
r32 r72 24 24 25 25 #define AC97_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | ((invert) << 24)) 26 #define AC97_PAGE_SINGLE_VALUE(reg,shift,mask,invert,page) (AC97_SINGLE_VALUE(reg,shift,mask,invert) | (1<<25) | ((page) << 26)) 27 #define AC97_SINGLE(xname, reg, shift, mask, invert) \ 28 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_info_volsw, \ 29 .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 30 .private_value = AC97_SINGLE_VALUE(reg, shift, mask, invert) } 31 #define AC97_PAGE_SINGLE(xname, reg, shift, mask, invert, page) \ 32 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_info_volsw, \ 33 .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 34 .private_value = AC97_PAGE_SINGLE_VALUE(reg, shift, mask, invert, page) } 35 #define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \ 36 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_ac97_info_volsw, \ 37 .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 38 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) } 26 39 27 #define AC97_PAGE_SINGLE_VALUE(reg,shift,mask,invert,page) (AC97_SINGLE_VALUE(reg,shift,mask,invert) | (1<<25) | ((page) << 26)) 40 /* enum control */ 41 struct ac97_enum { 42 unsigned char reg; 43 unsigned char shift_l; 44 unsigned char shift_r; 45 unsigned short mask; 46 const char **texts; 47 }; 28 48 29 #define AC97_SINGLE(xname, reg, shift, mask, invert) \ 30 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, 0, 0, 0, snd_ac97_info_volsw, \ 31 snd_ac97_get_volsw, snd_ac97_put_volsw, \ 32 AC97_SINGLE_VALUE(reg, shift, mask, invert) } 49 #define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \ 50 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 51 .mask = xmask, .texts = xtexts } 52 #define AC97_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \ 53 AC97_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts) 54 #define AC97_ENUM(xname, xenum) \ 55 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_info_enum_double, \ 56 .get = snd_ac97_get_enum_double, .put = snd_ac97_put_enum_double, \ 57 .private_value = (unsigned long)&xenum } 33 58 34 #define AC97_PAGE_SINGLE(xname, reg, shift, mask, invert, page) \35 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, 0, 0, 0, \36 snd_ac97_info_volsw, \37 snd_ac97_get_volsw,\38 snd_ac97_put_volsw, \39 AC97_PAGE_SINGLE_VALUE(reg, shift, mask, invert, page) }40 #define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \41 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, (xname), 0,0,0, snd_ac97_info_volsw, \42 snd_ac97_get_volsw, snd_ac97_put_volsw, \43 (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }44 #define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \45 { xreg, xshift_l, xshift_r, \46 xmask, xtexts }47 #define AC97_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \48 AC97_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)49 #define AC97_ENUM(xname, xenum) \50 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname, 0,0,0, snd_ac97_info_enum_double, \51 snd_ac97_get_enum_double, snd_ac97_put_enum_double, \52 (unsigned long)&xenum }53 59 /* ac97_codec.c */ 54 extern const char *snd_ac97_stereo_enhancements[]; 55 extern const snd_kcontrol_new_t snd_ac97_controls_3d[]; 56 extern const snd_kcontrol_new_t snd_ac97_controls_spdif[]; 57 snd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t * ac97); 58 void snd_ac97_get_name(ac97_t *ac97, unsigned int id, char *name, int modem); 59 int snd_ac97_info_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo); 60 int snd_ac97_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol); 61 int snd_ac97_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol); 62 int snd_ac97_try_bit(ac97_t * ac97, int reg, int bit); 63 int snd_ac97_remove_ctl(ac97_t *ac97, const char *name, const char *suffix); 64 int snd_ac97_rename_ctl(ac97_t *ac97, const char *src, const char *dst, const char *suffix); 65 int snd_ac97_swap_ctl(ac97_t *ac97, const char *s1, const char *s2, const char *suffix); 66 void snd_ac97_rename_vol_ctl(ac97_t *ac97, const char *src, const char *dst); 67 void snd_ac97_restore_status(ac97_t *ac97); 68 void snd_ac97_restore_iec958(ac97_t *ac97); 69 int snd_ac97_info_enum_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo); 70 int snd_ac97_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol); 71 int snd_ac97_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol); 72 int snd_ac97_update_bits_nolock(ac97_t *ac97, unsigned short reg, 73 unsigned short mask, unsigned short value); 60 extern const struct snd_kcontrol_new snd_ac97_controls_3d[]; 61 extern const struct snd_kcontrol_new snd_ac97_controls_spdif[]; 62 struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template, struct snd_ac97 * ac97); 63 void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int modem); 64 int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); 65 int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 66 int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 67 int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit); 68 int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name, const char *suffix); 69 int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src, const char *dst, const char *suffix); 70 int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, const char *s2, const char *suffix); 71 void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src, const char *dst); 72 void snd_ac97_restore_status(struct snd_ac97 *ac97); 73 void snd_ac97_restore_iec958(struct snd_ac97 *ac97); 74 int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); 75 int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 76 int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 77 78 int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg, 79 unsigned short mask, unsigned short value); 80 74 81 /* ac97_proc.c */ 75 82 #ifdef CONFIG_PROC_FS 76 void snd_ac97_bus_proc_init( ac97_bus_t* ac97);77 void snd_ac97_bus_proc_done( ac97_bus_t* ac97);78 void snd_ac97_proc_init( ac97_t* ac97);79 void snd_ac97_proc_done( ac97_t* ac97);83 void snd_ac97_bus_proc_init(struct snd_ac97_bus * ac97); 84 void snd_ac97_bus_proc_done(struct snd_ac97_bus * ac97); 85 void snd_ac97_proc_init(struct snd_ac97 * ac97); 86 void snd_ac97_proc_done(struct snd_ac97 * ac97); 80 87 #else 81 88 #define snd_ac97_bus_proc_init(ac97_bus_t) do { } while (0) -
GPL/trunk/alsa-kernel/pci/ac97/ac97_patch.c
r32 r72 40 40 */ 41 41 42 static int patch_build_controls( ac97_t * ac97, const snd_kcontrol_new_t*controls, int count)43 { 44 45 46 47 48 49 42 static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count) 43 { 44 int idx, err; 45 46 for (idx = 0; idx < count; idx++) 47 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) 48 return err; 49 return 0; 50 50 } 51 51 52 52 /* set to the page, update bits and restore the page */ 53 static int ac97_update_bits_page( ac97_t*ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)54 { 55 56 57 58 59 60 61 62 63 64 53 static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page) 54 { 55 unsigned short page_save; 56 int ret; 57 58 down(&ac97->page_mutex); 59 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 60 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); 61 ret = snd_ac97_update_bits(ac97, reg, mask, value); 62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); 63 up(&ac97->page_mutex); /* unlock paging */ 64 return ret; 65 65 } 66 66 … … 68 68 * shared line-in/mic controls 69 69 */ 70 static int ac97_enum_text_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t*uinfo,71 72 { 73 74 75 76 77 78 79 80 } 81 82 static int ac97_surround_jack_mode_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t*uinfo)83 { 84 85 86 } 87 88 static int ac97_surround_jack_mode_get(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)89 { 90 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);91 92 93 94 } 95 96 static int ac97_surround_jack_mode_put(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)97 { 98 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);99 100 101 102 103 104 105 106 107 108 } 109 110 static int ac97_channel_mode_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t*uinfo)111 { 112 113 114 115 116 } 117 118 static int ac97_channel_mode_get(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)119 { 120 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);121 122 123 124 } 125 126 static int ac97_channel_mode_put(s nd_kcontrol_t *kcontrol, snd_ctl_elem_value_t*ucontrol)127 { 128 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);129 130 131 132 133 134 135 136 137 70 static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo, 71 const char **texts, unsigned int nums) 72 { 73 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 74 uinfo->count = 1; 75 uinfo->value.enumerated.items = nums; 76 if (uinfo->value.enumerated.item > nums - 1) 77 uinfo->value.enumerated.item = nums - 1; 78 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 79 return 0; 80 } 81 82 static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 83 { 84 static const char *texts[] = { "Shared", "Independent" }; 85 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); 86 } 87 88 static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 89 { 90 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 91 92 ucontrol->value.enumerated.item[0] = ac97->indep_surround; 93 return 0; 94 } 95 96 static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 97 { 98 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 99 unsigned char indep = !!ucontrol->value.enumerated.item[0]; 100 101 if (indep != ac97->indep_surround) { 102 ac97->indep_surround = indep; 103 if (ac97->build_ops->update_jacks) 104 ac97->build_ops->update_jacks(ac97); 105 return 1; 106 } 107 return 0; 108 } 109 110 static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 111 { 112 static const char *texts[] = { "2ch", "4ch", "6ch" }; 113 if (kcontrol->private_value) 114 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ 115 return ac97_enum_text_info(kcontrol, uinfo, texts, 3); 116 } 117 118 static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 119 { 120 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 121 122 ucontrol->value.enumerated.item[0] = ac97->channel_mode; 123 return 0; 124 } 125 126 static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 127 { 128 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 129 unsigned char mode = ucontrol->value.enumerated.item[0]; 130 131 if (mode != ac97->channel_mode) { 132 ac97->channel_mode = mode; 133 if (ac97->build_ops->update_jacks) 134 ac97->build_ops->update_jacks(ac97); 135 return 1; 136 } 137 return 0; 138 138 } 139 139 140 140 #define AC97_SURROUND_JACK_MODE_CTL \ 141 142 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,\143 "Surround Jack Mode", 0,0,0, \144 145 146 ac97_surround_jack_mode_put,0\147 141 { \ 142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 143 .name = "Surround Jack Mode", \ 144 .info = ac97_surround_jack_mode_info, \ 145 .get = ac97_surround_jack_mode_get, \ 146 .put = ac97_surround_jack_mode_put, \ 147 } 148 148 #define AC97_CHANNEL_MODE_CTL \ 149 150 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,\151 "Channel Mode",0,0,0, \152 153 154 ac97_channel_mode_put,0\155 149 { \ 150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 151 .name = "Channel Mode", \ 152 .info = ac97_channel_mode_info, \ 153 .get = ac97_channel_mode_get, \ 154 .put = ac97_channel_mode_put, \ 155 } 156 156 #define AC97_CHANNEL_MODE_4CH_CTL \ 157 158 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, \159 "Channel Mode", 0,0,0, \160 161 162 163 1\164 165 166 static inline int is_surround_on( ac97_t*ac97)167 { 168 169 } 170 171 static inline int is_clfe_on( ac97_t*ac97)172 { 173 174 } 175 176 static inline int is_shared_linein( ac97_t*ac97)177 { 178 179 } 180 181 static inline int is_shared_micin( ac97_t*ac97)182 { 183 157 { \ 158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 159 .name = "Channel Mode", \ 160 .info = ac97_channel_mode_info, \ 161 .get = ac97_channel_mode_get, \ 162 .put = ac97_channel_mode_put, \ 163 .private_value = 1, \ 164 } 165 166 static inline int is_surround_on(struct snd_ac97 *ac97) 167 { 168 return ac97->channel_mode >= 1; 169 } 170 171 static inline int is_clfe_on(struct snd_ac97 *ac97) 172 { 173 return ac97->channel_mode >= 2; 174 } 175 176 static inline int is_shared_linein(struct snd_ac97 *ac97) 177 { 178 return ! ac97->indep_surround && is_surround_on(ac97); 179 } 180 181 static inline int is_shared_micin(struct snd_ac97 *ac97) 182 { 183 return ! ac97->indep_surround && is_clfe_on(ac97); 184 184 } 185 185 … … 188 188 189 189 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */ 190 static int snd_ac97_ymf753_info_speaker(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)191 { 192 193 194 195 196 197 198 199 200 201 202 203 } 204 205 static int snd_ac97_ymf753_get_speaker(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)206 { 207 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);208 209 210 211 212 213 214 215 216 } 217 218 static int snd_ac97_ymf753_put_speaker(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)219 { 220 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);221 222 223 224 225 226 227 } 228 229 static const s nd_kcontrol_new_tsnd_ac97_ymf753_controls_speaker =230 { 231 SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0,232 "3D Control - Speaker", 0 ,0 ,0,233 234 235 snd_ac97_ymf753_put_speaker, 0,190 static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 191 { 192 static char *texts[3] = { 193 "Standard", "Small", "Smaller" 194 }; 195 196 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 197 uinfo->count = 1; 198 uinfo->value.enumerated.items = 3; 199 if (uinfo->value.enumerated.item > 2) 200 uinfo->value.enumerated.item = 2; 201 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 202 return 0; 203 } 204 205 static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 206 { 207 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 208 unsigned short val; 209 210 val = ac97->regs[AC97_YMF753_3D_MODE_SEL]; 211 val = (val >> 10) & 3; 212 if (val > 0) /* 0 = invalid */ 213 val--; 214 ucontrol->value.enumerated.item[0] = val; 215 return 0; 216 } 217 218 static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 219 { 220 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 221 unsigned short val; 222 223 if (ucontrol->value.enumerated.item[0] > 2) 224 return -EINVAL; 225 val = (ucontrol->value.enumerated.item[0] + 1) << 10; 226 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val); 227 } 228 229 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker = 230 { 231 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 232 .name = "3D Control - Speaker", 233 .info = snd_ac97_ymf753_info_speaker, 234 .get = snd_ac97_ymf753_get_speaker, 235 .put = snd_ac97_ymf753_put_speaker, 236 236 }; 237 237 238 238 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */ 239 static int snd_ac97_ymf753_spdif_source_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)240 { 241 242 243 244 245 246 247 248 249 250 } 251 252 static int snd_ac97_ymf753_spdif_source_get(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)253 { 254 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);255 256 257 258 259 260 } 261 262 static int snd_ac97_ymf753_spdif_source_put(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)263 { 264 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);265 266 267 268 269 270 239 static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 240 { 241 static char *texts[2] = { "AC-Link", "A/D Converter" }; 242 243 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 244 uinfo->count = 1; 245 uinfo->value.enumerated.items = 2; 246 if (uinfo->value.enumerated.item > 1) 247 uinfo->value.enumerated.item = 1; 248 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 249 return 0; 250 } 251 252 static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 253 { 254 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 255 unsigned short val; 256 257 val = ac97->regs[AC97_YMF753_DIT_CTRL2]; 258 ucontrol->value.enumerated.item[0] = (val >> 1) & 1; 259 return 0; 260 } 261 262 static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 263 { 264 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 265 unsigned short val; 266 267 if (ucontrol->value.enumerated.item[0] > 1) 268 return -EINVAL; 269 val = ucontrol->value.enumerated.item[0] << 1; 270 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val); 271 271 } 272 272 273 273 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 274 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.275 By default, no output pin is selected, and the S/PDIF signal is not output.276 There is also a bit to mute S/PDIF output in a vendor-specific register. */277 static int snd_ac97_ymf753_spdif_output_pin_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)278 { 279 280 281 282 283 284 285 286 287 288 } 289 290 static int snd_ac97_ymf753_spdif_output_pin_get(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)291 { 292 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);293 294 295 296 297 298 } 299 300 static int snd_ac97_ymf753_spdif_output_pin_put(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)301 { 302 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);303 304 305 306 307 308 309 310 311 312 } 313 314 static const s nd_kcontrol_new_tsnd_ac97_ymf753_controls_spdif[3] = {315 316 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,317 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 0,0,0,318 319 320 snd_ac97_ymf753_spdif_source_put, 0,321 322 323 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,324 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", 0,0,0,325 326 327 snd_ac97_ymf753_spdif_output_pin_put, 0,328 329 330 }; 331 332 static int patch_yamaha_ymf753_3d( ac97_t* ac97)333 { 334 snd_kcontrol_t*kctl;335 336 337 338 339 340 341 342 343 344 345 346 } 347 348 static int patch_yamaha_ymf753_post_spdif( ac97_t* ac97)349 { 350 351 352 353 354 274 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. 275 By default, no output pin is selected, and the S/PDIF signal is not output. 276 There is also a bit to mute S/PDIF output in a vendor-specific register. */ 277 static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 278 { 279 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" }; 280 281 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 282 uinfo->count = 1; 283 uinfo->value.enumerated.items = 3; 284 if (uinfo->value.enumerated.item > 2) 285 uinfo->value.enumerated.item = 2; 286 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 287 return 0; 288 } 289 290 static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 291 { 292 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 293 unsigned short val; 294 295 val = ac97->regs[AC97_YMF753_DIT_CTRL2]; 296 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; 297 return 0; 298 } 299 300 static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 301 { 302 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 303 unsigned short val; 304 305 if (ucontrol->value.enumerated.item[0] > 2) 306 return -EINVAL; 307 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : 308 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; 309 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val); 310 /* The following can be used to direct S/PDIF output to pin 47 (EAPD). 311 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ 312 } 313 314 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { 315 { 316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 317 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 318 .info = snd_ac97_ymf753_spdif_source_info, 319 .get = snd_ac97_ymf753_spdif_source_get, 320 .put = snd_ac97_ymf753_spdif_source_put, 321 }, 322 { 323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 324 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", 325 .info = snd_ac97_ymf753_spdif_output_pin_info, 326 .get = snd_ac97_ymf753_spdif_output_pin_get, 327 .put = snd_ac97_ymf753_spdif_output_pin_put, 328 }, 329 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1) 330 }; 331 332 static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97) 333 { 334 struct snd_kcontrol *kctl; 335 int err; 336 337 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 338 return err; 339 strcpy(kctl->id.name, "3D Control - Wide"); 340 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); 341 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 342 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0) 343 return err; 344 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00); 345 return 0; 346 } 347 348 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) 349 { 350 int err; 351 352 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) 353 return err; 354 return 0; 355 355 } 356 356 357 357 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { 358 patch_yamaha_ymf753_3d, 359 NULL, 360 NULL, 361 patch_yamaha_ymf753_post_spdif,0,0 362 }; 363 364 int patch_yamaha_ymf753(ac97_t * ac97) 365 { 366 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. 367 This chip has nonstandard and extended behaviour with regard to its S/PDIF output. 368 The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 369 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. 370 By default, no output pin is selected, and the S/PDIF signal is not output. 371 There is also a bit to mute S/PDIF output in a vendor-specific register. 372 */ 373 ac97->build_ops = &patch_yamaha_ymf753_ops; 374 ac97->caps |= AC97_BC_BASS_TREBLE; 375 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 376 return 0; 358 .build_3d = patch_yamaha_ymf753_3d, 359 .build_post_spdif = patch_yamaha_ymf753_post_spdif 360 }; 361 362 int patch_yamaha_ymf753(struct snd_ac97 * ac97) 363 { 364 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. 365 This chip has nonstandard and extended behaviour with regard to its S/PDIF output. 366 The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 367 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. 368 By default, no output pin is selected, and the S/PDIF signal is not output. 369 There is also a bit to mute S/PDIF output in a vendor-specific register. 370 */ 371 ac97->build_ops = &patch_yamaha_ymf753_ops; 372 ac97->caps |= AC97_BC_BASS_TREBLE; 373 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 374 return 0; 377 375 } 378 376 … … 383 381 */ 384 382 385 static const snd_kcontrol_new_t wm97xx_snd_ac97_controls[] = { 386 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 387 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 388 }; 389 390 static int patch_wolfson_wm9703_specific(ac97_t * ac97) 391 { 392 /* This is known to work for the ViewSonic ViewPad 1000 393 * Randolph Bentson <bentson@holmsjoen.com> 394 * WM9703/9707/9708/9717 395 */ 396 int err, i; 397 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 398 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 399 return err; 400 } 401 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); 402 return 0; 383 static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { 384 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 385 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 386 }; 387 388 static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) 389 { 390 /* This is known to work for the ViewSonic ViewPad 1000 391 * Randolph Bentson <bentson@holmsjoen.com> 392 * WM9703/9707/9708/9717 393 */ 394 int err, i; 395 396 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 397 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 398 return err; 399 } 400 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); 401 return 0; 403 402 } 404 403 405 404 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { 406 407 }; 408 409 int patch_wolfson03( ac97_t* ac97)410 { 411 412 413 } 414 415 static const s nd_kcontrol_new_twm9704_snd_ac97_controls[] = {416 417 418 419 420 421 422 }; 423 424 static int patch_wolfson_wm9704_specific( ac97_t* ac97)425 { 426 427 428 429 430 431 432 433 405 .build_specific = patch_wolfson_wm9703_specific, 406 }; 407 408 int patch_wolfson03(struct snd_ac97 * ac97) 409 { 410 ac97->build_ops = &patch_wolfson_wm9703_ops; 411 return 0; 412 } 413 414 static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { 415 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 416 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 417 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), 418 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), 419 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), 420 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), 421 }; 422 423 static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) 424 { 425 int err, i; 426 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { 427 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) 428 return err; 429 } 430 /* patch for DVD noise */ 431 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); 432 return 0; 434 433 } 435 434 436 435 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { 437 438 }; 439 440 int patch_wolfson04( ac97_t* ac97)441 { 442 443 444 445 } 446 447 static int patch_wolfson_wm9705_specific( ac97_t* ac97)448 { 449 450 451 452 453 454 455 436 .build_specific = patch_wolfson_wm9704_specific, 437 }; 438 439 int patch_wolfson04(struct snd_ac97 * ac97) 440 { 441 /* WM9704M/9704Q */ 442 ac97->build_ops = &patch_wolfson_wm9704_ops; 443 return 0; 444 } 445 446 static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97) 447 { 448 int err, i; 449 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 450 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 451 return err; 452 } 453 snd_ac97_write_cache(ac97, 0x72, 0x0808); 454 return 0; 456 455 } 457 456 458 457 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = { 459 460 }; 461 462 int patch_wolfson05( ac97_t* ac97)463 { 464 465 466 458 .build_specific = patch_wolfson_wm9705_specific, 459 }; 460 461 int patch_wolfson05(struct snd_ac97 * ac97) 462 { 463 /* WM9705, WM9710 */ 464 ac97->build_ops = &patch_wolfson_wm9705_ops; 465 return 0; 467 466 } 468 467 … … 475 474 static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 476 475 static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; 477 static const char* wm9711_rec_sel[] = 478 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};476 static const char* wm9711_rec_sel[] = 477 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; 479 478 static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; 480 479 481 480 static const struct ac97_enum wm9711_enum[] = { 482 483 484 485 486 487 488 489 490 491 492 }; 493 494 static const s nd_kcontrol_new_twm9711_snd_ac97_controls[] = {495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 }; 571 572 static int patch_wolfson_wm9711_specific( ac97_t* ac97)573 { 574 575 576 577 578 579 580 581 582 583 584 585 586 481 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), 482 AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), 483 AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), 484 AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), 485 AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), 486 AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), 487 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), 488 AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), 489 AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), 490 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), 491 }; 492 493 static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { 494 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 495 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 496 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), 497 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 498 AC97_ENUM("ALC Function", wm9711_enum[0]), 499 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), 500 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), 501 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 502 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 503 AC97_ENUM("ALC NG Type", wm9711_enum[9]), 504 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), 505 506 AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), 507 AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), 508 AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), 509 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), 510 511 AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), 512 AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1), 513 AC97_ENUM("Out3 Mux", wm9711_enum[2]), 514 AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), 515 AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), 516 517 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 518 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), 519 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), 520 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), 521 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), 522 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), 523 524 AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), 525 AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), 526 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), 527 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), 528 AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), 529 AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), 530 531 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), 532 AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), 533 534 AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), 535 AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), 536 AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), 537 538 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), 539 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), 540 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), 541 542 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), 543 AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), 544 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), 545 AC97_ENUM("Capture Select", wm9711_enum[8]), 546 547 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), 548 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), 549 550 AC97_ENUM("Bass Control", wm9711_enum[5]), 551 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), 552 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), 553 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), 554 555 AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), 556 AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), 557 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1), 558 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), 559 560 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), 561 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), 562 AC97_ENUM("Mic Select Source", wm9711_enum[7]), 563 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1), 564 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), 565 566 AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), 567 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), 568 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), 569 }; 570 571 static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) 572 { 573 int err, i; 574 575 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { 576 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) 577 return err; 578 } 579 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); 580 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); 581 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); 582 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); 583 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 584 snd_ac97_write_cache(ac97, AC97_CD, 0x0000); 585 return 0; 587 586 } 588 587 589 588 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { 590 .build_specific = patch_wolfson_wm9711_specific, 591 }; 592 593 int patch_wolfson11(ac97_t * ac97) 594 { 595 /* WM9711, WM9712 */ 596 ac97->build_ops = &patch_wolfson_wm9711_ops; 597 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | 598 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; 599 600 return 0; 601 } 602 603 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic1", "Mic2", "Mute"}; 589 .build_specific = patch_wolfson_wm9711_specific, 590 }; 591 592 int patch_wolfson11(struct snd_ac97 * ac97) 593 { 594 /* WM9711, WM9712 */ 595 ac97->build_ops = &patch_wolfson_wm9711_ops; 596 597 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | 598 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; 599 600 return 0; 601 } 602 603 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 604 604 static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 605 static const char* wm9713_rec_src[] = 606 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 607 "Mono Mix", "Zh"};605 static const char* wm9713_rec_src[] = 606 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 607 "Mono Mix", "Zh"}; 608 608 static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 609 609 static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; 610 610 static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; 611 static const char* wm9713_spk_pga[] = 612 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};611 static const char* wm9713_spk_pga[] = 612 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; 613 613 static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; 614 614 static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; 615 615 static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; 616 static const char* wm9713_dac_inv[] = 617 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 618 "Headphone Mix Mono", "NC", "Vmid"};616 static const char* wm9713_dac_inv[] = 617 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 618 "Headphone Mix Mono", "NC", "Vmid"}; 619 619 static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; 620 620 static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; 621 621 622 622 static const struct ac97_enum wm9713_enum[] = { 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 }; 638 639 static const s nd_kcontrol_new_twm13_snd_ac97_controls[] = {640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 }; 730 731 static const s nd_kcontrol_new_twm13_snd_ac97_controls_3d[] = {732 733 734 735 736 }; 737 738 static int patch_wolfson_wm9713_3d ( ac97_t* ac97)739 { 740 741 742 743 744 745 746 747 } 748 749 static int patch_wolfson_wm9713_specific( ac97_t* ac97)750 { 751 752 753 754 755 756 757 758 759 760 761 762 763 764 623 AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), 624 AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), 625 AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), 626 AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), 627 AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), 628 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), 629 AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), 630 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), 631 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), 632 AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), 633 AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), 634 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), 635 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), 636 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), 637 }; 638 639 static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { 640 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), 641 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 642 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), 643 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), 644 645 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), 646 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), 647 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), 648 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), 649 650 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 651 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 652 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), 653 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), 654 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), 655 AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), 656 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), 657 658 AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 659 AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), 660 AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), 661 AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), 662 663 AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), 664 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), 665 AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), 666 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), 667 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), 668 AC97_ENUM("Capture Select", wm9713_enum[3]), 669 670 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 671 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 672 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), 673 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 674 AC97_ENUM("ALC Function", wm9713_enum[5]), 675 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), 676 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), 677 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 678 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 679 AC97_ENUM("ALC NG Type", wm9713_enum[13]), 680 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), 681 682 AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), 683 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), 684 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), 685 AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), 686 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), 687 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), 688 689 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), 690 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), 691 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), 692 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), 693 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 694 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 695 696 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 697 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 698 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), 699 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), 700 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), 701 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), 702 703 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 704 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 705 AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), 706 AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), 707 AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), 708 AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), 709 710 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), 711 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), 712 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), 713 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), 714 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), 715 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), 716 717 AC97_ENUM("Mono Input Mux", wm9713_enum[6]), 718 AC97_ENUM("Master Input Mux", wm9713_enum[7]), 719 AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), 720 AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), 721 AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), 722 723 AC97_ENUM("Bass Control", wm9713_enum[12]), 724 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), 725 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), 726 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), 727 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), 728 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), 729 }; 730 731 static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { 732 AC97_ENUM("Inv Input Mux", wm9713_enum[11]), 733 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), 734 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), 735 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 736 }; 737 738 static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) 739 { 740 int err, i; 741 742 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { 743 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) 744 return err; 745 } 746 return 0; 747 } 748 749 static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) 750 { 751 int err, i; 752 753 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { 754 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0) 755 return err; 756 } 757 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 758 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); 759 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); 760 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); 761 snd_ac97_write_cache(ac97, AC97_CD, 0x0808); 762 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); 763 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); 764 return 0; 765 765 } 766 766 767 767 #ifdef CONFIG_PM 768 static void patch_wolfson_wm9713_suspend ( ac97_t* ac97)769 { 770 771 772 } 773 774 static void patch_wolfson_wm9713_resume ( ac97_t* ac97)775 { 776 777 778 768 static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) 769 { 770 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); 771 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); 772 } 773 774 static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) 775 { 776 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 777 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 778 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 779 779 } 780 780 #endif 781 781 782 782 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { 783 784 785 #ifdef CONFIG_PM 786 787 .resume = patch_wolfson_wm9713_resume, 783 .build_specific = patch_wolfson_wm9713_specific, 784 .build_3d = patch_wolfson_wm9713_3d, 785 #ifdef CONFIG_PM 786 .suspend = patch_wolfson_wm9713_suspend, 787 .resume = patch_wolfson_wm9713_resume 788 788 #endif 789 789 }; 790 790 791 int patch_wolfson13( ac97_t* ac97)792 { 793 794 795 796 797 798 799 ac97->scaps &= ~AC97_SCAP_MODEM;800 801 802 803 804 805 791 int patch_wolfson13(struct snd_ac97 * ac97) 792 { 793 /* WM9713, WM9714 */ 794 ac97->build_ops = &patch_wolfson_wm9713_ops; 795 796 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | 797 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | 798 AC97_HAS_NO_STD_PCM; 799 ac97->scaps &= ~AC97_SCAP_MODEM; 800 801 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 802 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 803 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 804 805 return 0; 806 806 } 807 807 … … 809 809 * Tritech codec 810 810 */ 811 int patch_tritech_tr28028( ac97_t* ac97)812 { 813 814 815 816 817 811 int patch_tritech_tr28028(struct snd_ac97 * ac97) 812 { 813 snd_ac97_write_cache(ac97, 0x26, 0x0300); 814 snd_ac97_write_cache(ac97, 0x26, 0x0000); 815 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); 816 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); 817 return 0; 818 818 } 819 819 … … 821 821 * Sigmatel STAC97xx codecs 822 822 */ 823 static int patch_sigmatel_stac9700_3d( ac97_t* ac97)824 { 825 snd_kcontrol_t*kctl;826 827 828 829 830 831 832 833 834 } 835 836 static int patch_sigmatel_stac9708_3d( ac97_t* ac97)837 { 838 snd_kcontrol_t*kctl;839 840 841 842 843 844 845 846 847 848 849 850 851 } 852 853 static const s nd_kcontrol_new_tsnd_ac97_sigmatel_4speaker =823 static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) 824 { 825 struct snd_kcontrol *kctl; 826 int err; 827 828 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 829 return err; 830 strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 831 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 832 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 833 return 0; 834 } 835 836 static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) 837 { 838 struct snd_kcontrol *kctl; 839 int err; 840 841 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 842 return err; 843 strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 844 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); 845 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 846 return err; 847 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); 848 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 849 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 850 return 0; 851 } 852 853 static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = 854 854 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); 855 855 856 static const s nd_kcontrol_new_tsnd_ac97_sigmatel_phaseinvert =856 static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = 857 857 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); 858 858 859 static const s nd_kcontrol_new_tsnd_ac97_sigmatel_controls[] = {860 861 862 }; 863 864 static int patch_sigmatel_stac97xx_specific( ac97_t* ac97)865 { 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 859 static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { 860 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), 861 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) 862 }; 863 864 static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) 865 { 866 int err; 867 868 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); 869 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) 870 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) 871 return err; 872 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) 873 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) 874 return err; 875 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) 876 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) 877 return err; 878 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) 879 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) 880 return err; 881 return 0; 882 882 } 883 883 884 884 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { 885 patch_sigmatel_stac9700_3d, 886 patch_sigmatel_stac97xx_specific, NULL, NULL,0,0 887 }; 888 889 int patch_sigmatel_stac9700(ac97_t * ac97) 890 { 891 ac97->build_ops = &patch_sigmatel_stac9700_ops; 892 return 0; 893 } 894 895 static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 896 { 897 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 898 int err; 899 900 down(&ac97->page_mutex); 901 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 902 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, 903 (ucontrol->value.integer.value[0] & 1) << 4); 904 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); 905 up(&ac97->page_mutex); 906 return err; 907 } 908 909 static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = { 910 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, 911 "Sigmatel Output Bias Switch",0,0,0, 912 snd_ac97_info_volsw, 913 snd_ac97_get_volsw, 914 snd_ac97_stac9708_put_bias, 915 AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), 916 }; 917 918 static int patch_sigmatel_stac9708_specific(ac97_t *ac97) 919 { 920 int err; 921 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); 922 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) 923 return err; 924 return patch_sigmatel_stac97xx_specific(ac97); 885 .build_3d = patch_sigmatel_stac9700_3d, 886 .build_specific = patch_sigmatel_stac97xx_specific 887 }; 888 889 int patch_sigmatel_stac9700(struct snd_ac97 * ac97) 890 { 891 ac97->build_ops = &patch_sigmatel_stac9700_ops; 892 return 0; 893 } 894 895 static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 896 { 897 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 898 int err; 899 900 down(&ac97->page_mutex); 901 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 902 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, 903 (ucontrol->value.integer.value[0] & 1) << 4); 904 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); 905 up(&ac97->page_mutex); 906 return err; 907 } 908 909 static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { 910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 911 .name = "Sigmatel Output Bias Switch", 912 .info = snd_ac97_info_volsw, 913 .get = snd_ac97_get_volsw, 914 .put = snd_ac97_stac9708_put_bias, 915 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), 916 }; 917 918 static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) 919 { 920 int err; 921 922 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); 923 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) 924 return err; 925 return patch_sigmatel_stac97xx_specific(ac97); 925 926 } 926 927 927 928 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { 928 /* .build_3d =*/ patch_sigmatel_stac9708_3d, 929 /* .build_specific =*/ patch_sigmatel_stac9708_specific, 930 NULL, NULL,0,0 931 }; 932 933 int patch_sigmatel_stac9708(ac97_t * ac97) 934 { 935 unsigned int codec72, codec6c; 936 937 ac97->build_ops = &patch_sigmatel_stac9708_ops; 938 ac97->caps |= 0x10; /* HP (sigmatel surround) support */ 939 940 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; 941 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); 942 943 if ((codec72==0) && (codec6c==0)) { 944 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 945 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); 946 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 947 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); 948 } else if ((codec72==0x8000) && (codec6c==0)) { 949 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 950 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); 951 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); 952 } else if ((codec72==0x8000) && (codec6c==0x0080)) { 953 /* nothing */ 954 } 955 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 956 return 0; 957 } 958 959 int patch_sigmatel_stac9721(ac97_t * ac97) 960 { 961 ac97->build_ops = &patch_sigmatel_stac9700_ops; 962 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { 963 // patch for SigmaTel 964 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 965 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); 966 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 968 } 969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 970 return 0; 971 } 972 973 int patch_sigmatel_stac9744(ac97_t * ac97) 974 { 975 // patch for SigmaTel 976 ac97->build_ops = &patch_sigmatel_stac9700_ops; 977 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 978 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 979 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 980 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 981 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 982 return 0; 983 } 984 985 int patch_sigmatel_stac9756(ac97_t * ac97) 986 { 987 // patch for SigmaTel 988 ac97->build_ops = &patch_sigmatel_stac9700_ops; 989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 991 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 992 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 993 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 994 return 0; 995 } 996 997 static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 998 { 999 static char *texts[5] = { "Input/Disabled", "Front Output", 1000 "Rear Output", "Center/LFE Output", "Mixer Output" }; 1001 1002 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1003 uinfo->count = 1; 1004 uinfo->value.enumerated.items = 5; 1005 if (uinfo->value.enumerated.item > 4) 1006 uinfo->value.enumerated.item = 4; 1007 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1008 return 0; 1009 } 1010 1011 static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) 1012 { 1013 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1014 int shift = kcontrol->private_value; 1015 unsigned short val; 1016 1017 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; 1018 if (!(val & 4)) 1019 ucontrol->value.enumerated.item[0] = 0; 1020 else 1021 ucontrol->value.enumerated.item[0] = 1 + (val & 3); 1022 return 0; 1023 } 1024 1025 static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1026 { 1027 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1028 int shift = kcontrol->private_value; 1029 unsigned short val; 1030 1031 if (ucontrol->value.enumerated.item[0] > 4) 1032 return -EINVAL; 1033 if (ucontrol->value.enumerated.item[0] == 0) 1034 val = 0; 1035 else 1036 val = 4 | (ucontrol->value.enumerated.item[0] - 1); 1037 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, 1038 7 << shift, val << shift, 0); 1039 } 1040 1041 static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1042 { 1043 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", 1044 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 1045 1046 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1047 uinfo->count = 1; 1048 uinfo->value.enumerated.items = 7; 1049 if (uinfo->value.enumerated.item > 6) 1050 uinfo->value.enumerated.item = 6; 1051 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1052 return 0; 1053 } 1054 1055 static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) 1056 { 1057 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1058 int shift = kcontrol->private_value; 1059 unsigned short val; 1060 1061 val = ac97->regs[AC97_SIGMATEL_INSEL]; 1062 ucontrol->value.enumerated.item[0] = (val >> shift) & 7; 1063 return 0; 1064 } 1065 1066 static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1067 { 1068 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1069 int shift = kcontrol->private_value; 1070 1071 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, 1072 ucontrol->value.enumerated.item[0] << shift, 0); 1073 } 1074 1075 static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1076 { 1077 static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; 1078 1079 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1080 uinfo->count = 1; 1081 uinfo->value.enumerated.items = 3; 1082 if (uinfo->value.enumerated.item > 2) 1083 uinfo->value.enumerated.item = 2; 1084 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1085 return 0; 1086 } 1087 1088 static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) 1089 { 1090 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1091 1092 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; 1093 return 0; 1094 } 1095 1096 static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1097 { 1098 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1099 1100 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, 1101 ucontrol->value.enumerated.item[0], 0); 929 .build_3d = patch_sigmatel_stac9708_3d, 930 .build_specific = patch_sigmatel_stac9708_specific 931 }; 932 933 int patch_sigmatel_stac9708(struct snd_ac97 * ac97) 934 { 935 unsigned int codec72, codec6c; 936 937 ac97->build_ops = &patch_sigmatel_stac9708_ops; 938 ac97->caps |= 0x10; /* HP (sigmatel surround) support */ 939 940 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; 941 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); 942 943 if ((codec72==0) && (codec6c==0)) { 944 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 945 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); 946 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 947 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); 948 } else if ((codec72==0x8000) && (codec6c==0)) { 949 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 950 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); 951 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); 952 } else if ((codec72==0x8000) && (codec6c==0x0080)) { 953 /* nothing */ 954 } 955 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 956 return 0; 957 } 958 959 int patch_sigmatel_stac9721(struct snd_ac97 * ac97) 960 { 961 ac97->build_ops = &patch_sigmatel_stac9700_ops; 962 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { 963 // patch for SigmaTel 964 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 965 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); 966 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 968 } 969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 970 return 0; 971 } 972 973 int patch_sigmatel_stac9744(struct snd_ac97 * ac97) 974 { 975 // patch for SigmaTel 976 ac97->build_ops = &patch_sigmatel_stac9700_ops; 977 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 978 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 979 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 980 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 981 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 982 return 0; 983 } 984 985 int patch_sigmatel_stac9756(struct snd_ac97 * ac97) 986 { 987 // patch for SigmaTel 988 ac97->build_ops = &patch_sigmatel_stac9700_ops; 989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 991 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 992 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 993 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 994 return 0; 995 } 996 997 static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 998 { 999 static char *texts[5] = { "Input/Disabled", "Front Output", 1000 "Rear Output", "Center/LFE Output", "Mixer Output" }; 1001 1002 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1003 uinfo->count = 1; 1004 uinfo->value.enumerated.items = 5; 1005 if (uinfo->value.enumerated.item > 4) 1006 uinfo->value.enumerated.item = 4; 1007 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1008 return 0; 1009 } 1010 1011 static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1012 { 1013 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1014 int shift = kcontrol->private_value; 1015 unsigned short val; 1016 1017 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; 1018 if (!(val & 4)) 1019 ucontrol->value.enumerated.item[0] = 0; 1020 else 1021 ucontrol->value.enumerated.item[0] = 1 + (val & 3); 1022 return 0; 1023 } 1024 1025 static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1026 { 1027 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1028 int shift = kcontrol->private_value; 1029 unsigned short val; 1030 1031 if (ucontrol->value.enumerated.item[0] > 4) 1032 return -EINVAL; 1033 if (ucontrol->value.enumerated.item[0] == 0) 1034 val = 0; 1035 else 1036 val = 4 | (ucontrol->value.enumerated.item[0] - 1); 1037 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, 1038 7 << shift, val << shift, 0); 1039 } 1040 1041 static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1042 { 1043 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", 1044 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 1045 1046 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1047 uinfo->count = 1; 1048 uinfo->value.enumerated.items = 7; 1049 if (uinfo->value.enumerated.item > 6) 1050 uinfo->value.enumerated.item = 6; 1051 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1052 return 0; 1053 } 1054 1055 static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1056 { 1057 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1058 int shift = kcontrol->private_value; 1059 unsigned short val; 1060 1061 val = ac97->regs[AC97_SIGMATEL_INSEL]; 1062 ucontrol->value.enumerated.item[0] = (val >> shift) & 7; 1063 return 0; 1064 } 1065 1066 static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1067 { 1068 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1069 int shift = kcontrol->private_value; 1070 1071 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, 1072 ucontrol->value.enumerated.item[0] << shift, 0); 1073 } 1074 1075 static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1076 { 1077 static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; 1078 1079 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1080 uinfo->count = 1; 1081 uinfo->value.enumerated.items = 3; 1082 if (uinfo->value.enumerated.item > 2) 1083 uinfo->value.enumerated.item = 2; 1084 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1085 return 0; 1086 } 1087 1088 static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1089 { 1090 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1091 1092 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; 1093 return 0; 1094 } 1095 1096 static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1097 { 1098 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1099 1100 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, 1101 ucontrol->value.enumerated.item[0], 0); 1102 1102 } 1103 1103 1104 1104 #define STAC9758_OUTPUT_JACK(xname, shift) \ 1105 { /* .iface = */SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, /*.name = */xname, 0,0,0, \1106 /*.info = */snd_ac97_stac9758_output_jack_info, \1107 /*.get = */snd_ac97_stac9758_output_jack_get, \1108 /*.put = */snd_ac97_stac9758_output_jack_put, \1109 /*.private_value = */shift }1105 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 1106 .info = snd_ac97_stac9758_output_jack_info, \ 1107 .get = snd_ac97_stac9758_output_jack_get, \ 1108 .put = snd_ac97_stac9758_output_jack_put, \ 1109 .private_value = shift } 1110 1110 #define STAC9758_INPUT_JACK(xname, shift) \ 1111 { /* .iface = */SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, /*.name = */xname, 0,0,0, \ 1112 /*.info = */snd_ac97_stac9758_input_jack_info, \ 1113 /*.get = */snd_ac97_stac9758_input_jack_get, \ 1114 /*.put = */snd_ac97_stac9758_input_jack_put, \ 1115 /*.private_value = */shift } 1116 static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = { 1117 STAC9758_OUTPUT_JACK("Mic1 Jack", 1), 1118 STAC9758_OUTPUT_JACK("LineIn Jack", 4), 1119 STAC9758_OUTPUT_JACK("Front Jack", 7), 1120 STAC9758_OUTPUT_JACK("Rear Jack", 10), 1121 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), 1122 STAC9758_INPUT_JACK("Mic Input Source", 0), 1123 STAC9758_INPUT_JACK("Line Input Source", 8), 1124 { 1125 /* .iface = */ SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 1126 /* .name = */"Headphone Amp",0,0,0, 1127 /* .info = */snd_ac97_stac9758_phonesel_info, 1128 /* .get = */snd_ac97_stac9758_phonesel_get, 1129 /* .put = */snd_ac97_stac9758_phonesel_put,0 1130 }, 1131 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), 1132 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) 1133 }; 1134 1135 static int patch_sigmatel_stac9758_specific(ac97_t *ac97) 1136 { 1137 int err; 1138 1139 err = patch_sigmatel_stac97xx_specific(ac97); 1140 if (err < 0) 1141 return err; 1142 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, 1143 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); 1144 if (err < 0) 1145 return err; 1146 /* DAC-A direct */ 1147 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); 1148 /* DAC-A to Mix = PCM */ 1149 /* DAC-B direct = Surround */ 1150 /* DAC-B to Mix */ 1151 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); 1152 /* DAC-C direct = Center/LFE */ 1153 return 0; 1111 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 1112 .info = snd_ac97_stac9758_input_jack_info, \ 1113 .get = snd_ac97_stac9758_input_jack_get, \ 1114 .put = snd_ac97_stac9758_input_jack_put, \ 1115 .private_value = shift } 1116 static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { 1117 STAC9758_OUTPUT_JACK("Mic1 Jack", 1), 1118 STAC9758_OUTPUT_JACK("LineIn Jack", 4), 1119 STAC9758_OUTPUT_JACK("Front Jack", 7), 1120 STAC9758_OUTPUT_JACK("Rear Jack", 10), 1121 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), 1122 STAC9758_INPUT_JACK("Mic Input Source", 0), 1123 STAC9758_INPUT_JACK("Line Input Source", 8), 1124 { 1125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1126 .name = "Headphone Amp", 1127 .info = snd_ac97_stac9758_phonesel_info, 1128 .get = snd_ac97_stac9758_phonesel_get, 1129 .put = snd_ac97_stac9758_phonesel_put 1130 }, 1131 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), 1132 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) 1133 }; 1134 1135 static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) 1136 { 1137 int err; 1138 1139 err = patch_sigmatel_stac97xx_specific(ac97); 1140 if (err < 0) 1141 return err; 1142 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, 1143 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); 1144 if (err < 0) 1145 return err; 1146 /* DAC-A direct */ 1147 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); 1148 /* DAC-A to Mix = PCM */ 1149 /* DAC-B direct = Surround */ 1150 /* DAC-B to Mix */ 1151 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); 1152 /* DAC-C direct = Center/LFE */ 1153 1154 return 0; 1154 1155 } 1155 1156 1156 1157 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { 1157 /*.build_specific = */patch_sigmatel_stac9758_specific, 1158 /*.build_3d = */patch_sigmatel_stac9700_3d, NULL, NULL,0,0 1159 }; 1160 1161 int patch_sigmatel_stac9758(ac97_t * ac97) 1162 { 1163 static unsigned short regs[4] = { 1164 AC97_SIGMATEL_OUTSEL, 1165 AC97_SIGMATEL_IOMISC, 1166 AC97_SIGMATEL_INSEL, 1167 AC97_SIGMATEL_VARIOUS 1168 }; 1169 static unsigned short def_regs[4] = { 1170 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ 1171 /* IOMISC */ 0x2001, 1172 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ 1173 /* VARIOUS */ 0x0040 1174 }; 1175 static unsigned short m675_regs[4] = { 1176 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ 1177 /* IOMISC */ 0x2102, /* HP amp on */ 1178 /* INSEL */ 0x0203, /* LI:LI, MI:FR */ 1179 /* VARIOUS */ 0x0041 /* stereo mic */ 1180 }; 1181 unsigned short *pregs = def_regs; 1182 int i; 1183 1184 /* Gateway M675 notebook */ 1185 if (ac97->pci && 1186 ac97->subsystem_vendor == 0x107b && 1187 ac97->subsystem_device == 0x0601) 1188 pregs = m675_regs; 1189 1190 // patch for SigmaTel 1191 ac97->build_ops = &patch_sigmatel_stac9758_ops; 1192 /* FIXME: assume only page 0 for writing cache */ 1193 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 1194 1195 for (i = 0; i < 4; i++) 1196 snd_ac97_write_cache(ac97, regs[i], pregs[i]); 1197 1198 ac97->flags |= AC97_STEREO_MUTES; 1199 return 0; 1158 .build_3d = patch_sigmatel_stac9700_3d, 1159 .build_specific = patch_sigmatel_stac9758_specific 1160 }; 1161 1162 int patch_sigmatel_stac9758(struct snd_ac97 * ac97) 1163 { 1164 static unsigned short regs[4] = { 1165 AC97_SIGMATEL_OUTSEL, 1166 AC97_SIGMATEL_IOMISC, 1167 AC97_SIGMATEL_INSEL, 1168 AC97_SIGMATEL_VARIOUS 1169 }; 1170 static unsigned short def_regs[4] = { 1171 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ 1172 /* IOMISC */ 0x2001, 1173 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ 1174 /* VARIOUS */ 0x0040 1175 }; 1176 static unsigned short m675_regs[4] = { 1177 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ 1178 /* IOMISC */ 0x2102, /* HP amp on */ 1179 /* INSEL */ 0x0203, /* LI:LI, MI:FR */ 1180 /* VARIOUS */ 0x0041 /* stereo mic */ 1181 }; 1182 unsigned short *pregs = def_regs; 1183 int i; 1184 1185 /* Gateway M675 notebook */ 1186 if (ac97->pci && 1187 ac97->subsystem_vendor == 0x107b && 1188 ac97->subsystem_device == 0x0601) 1189 pregs = m675_regs; 1190 1191 // patch for SigmaTel 1192 ac97->build_ops = &patch_sigmatel_stac9758_ops; 1193 /* FIXME: assume only page 0 for writing cache */ 1194 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 1195 for (i = 0; i < 4; i++) 1196 snd_ac97_write_cache(ac97, regs[i], pregs[i]); 1197 1198 ac97->flags |= AC97_STEREO_MUTES; 1199 return 0; 1200 1200 } 1201 1201 … … 1203 1203 * Cirrus Logic CS42xx codecs 1204 1204 */ 1205 static const s nd_kcontrol_new_tsnd_ac97_cirrus_controls_spdif[2] = {1206 1207 1208 }; 1209 1210 static int patch_cirrus_build_spdif( ac97_t* ac97)1211 { 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1205 static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { 1206 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), 1207 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) 1208 }; 1209 1210 static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) 1211 { 1212 int err; 1213 1214 /* con mask, pro mask, default */ 1215 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 1216 return err; 1217 /* switch, spsa */ 1218 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) 1219 return err; 1220 switch (ac97->id & AC97_ID_CS_MASK) { 1221 case AC97_ID_CS4205: 1222 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) 1223 return err; 1224 break; 1225 } 1226 /* set default PCM S/PDIF params */ 1227 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 1228 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); 1229 return 0; 1230 1230 } 1231 1231 1232 1232 static struct snd_ac97_build_ops patch_cirrus_ops = { 1233 NULL, NULL, 1234 patch_cirrus_build_spdif, NULL,0,0 1235 }; 1236 1237 int patch_cirrus_spdif(ac97_t * ac97) 1238 { 1239 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. 1240 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* 1241 - sp/dif EA ID is not set, but sp/dif is always present.1242 - enable/disable is spdif register bit 15. 1243 - sp/dif control register is 0x68. differs from AC97: 1244 - valid is bit 14 (vs 15) 1245 - no DRS 1246 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) 1247 - sp/dif ssource select is in 0x5e bits 0,1. 1248 */ 1249 1250 ac97->build_ops = &patch_cirrus_ops; 1251 ac97->flags |= AC97_CS_SPDIF;1252 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;1253 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 1254 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);1255 return 0; 1256 } 1257 1258 int patch_cirrus_cs4299(ac97_t * ac97) 1259 { 1260 /* force the detection of PC Beep */ 1261 ac97->flags |= AC97_HAS_PC_BEEP; 1262 1263 return patch_cirrus_spdif(ac97); 1264 } 1233 .build_spdif = patch_cirrus_build_spdif 1234 }; 1235 1236 int patch_cirrus_spdif(struct snd_ac97 * ac97) 1237 { 1238 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. 1239 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* 1240 - sp/dif EA ID is not set, but sp/dif is always present. 1241 - enable/disable is spdif register bit 15. 1242 - sp/dif control register is 0x68. differs from AC97: 1243 - valid is bit 14 (vs 15) 1244 - no DRS 1245 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) 1246 - sp/dif ssource select is in 0x5e bits 0,1. 1247 */ 1248 1249 ac97->build_ops = &patch_cirrus_ops; 1250 ac97->flags |= AC97_CS_SPDIF; 1251 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; 1252 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 1253 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); 1254 return 0; 1255 } 1256 1257 int patch_cirrus_cs4299(struct snd_ac97 * ac97) 1258 { 1259 /* force the detection of PC Beep */ 1260 ac97->flags |= AC97_HAS_PC_BEEP; 1261 1262 return patch_cirrus_spdif(ac97); 1263 } 1264 1265 1265 /* 1266 1266 * Conexant codecs 1267 1267 */ 1268 static const s nd_kcontrol_new_tsnd_ac97_conexant_controls_spdif[1] = {1269 1270 }; 1271 1272 static int patch_conexant_build_spdif( ac97_t* ac97)1273 { 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1268 static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { 1269 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), 1270 }; 1271 1272 static int patch_conexant_build_spdif(struct snd_ac97 * ac97) 1273 { 1274 int err; 1275 1276 /* con mask, pro mask, default */ 1277 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 1278 return err; 1279 /* switch */ 1280 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) 1281 return err; 1282 /* set default PCM S/PDIF params */ 1283 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 1284 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, 1285 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); 1286 return 0; 1287 1287 } 1288 1288 1289 1289 static struct snd_ac97_build_ops patch_conexant_ops = { 1290 NULL, NULL, patch_conexant_build_spdif, NULL,0,0 1291 }; 1292 1293 int patch_conexant(ac97_t * ac97) 1294 { 1295 ac97->build_ops = &patch_conexant_ops; 1296 ac97->flags |= AC97_CX_SPDIF; 1297 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 1298 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 1299 return 0; 1300 } 1290 .build_spdif = patch_conexant_build_spdif 1291 }; 1292 1293 int patch_conexant(struct snd_ac97 * ac97) 1294 { 1295 ac97->build_ops = &patch_conexant_ops; 1296 ac97->flags |= AC97_CX_SPDIF; 1297 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 1298 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 1299 return 0; 1300 } 1301 1301 1302 /* 1302 1303 * Analog Device AD18xx, AD19xx codecs 1303 1304 */ 1304 1305 static void ad18xx_resume(ac97_t *ac97) 1306 { 1307 static unsigned short setup_regs[] = { 1308 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, 1309 }; 1310 int i, codec; 1311 1312 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { 1313 unsigned short reg = setup_regs[i]; 1314 if (test_bit(reg, ac97->reg_accessed)) { 1315 snd_ac97_write(ac97, reg, ac97->regs[reg]); 1316 snd_ac97_read(ac97, reg); 1317 } 1318 } 1319 1320 if (! (ac97->flags & AC97_AD_MULTI)) 1321 /* normal restore */ 1322 snd_ac97_restore_status(ac97); 1323 else { 1324 /* restore the AD18xx codec configurations */ 1325 for (codec = 0; codec < 3; codec++) { 1326 if (! ac97->spec.ad18xx.id[codec]) 1327 continue; 1328 /* select single codec */ 1329 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1330 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 1331 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); 1332 } 1333 /* select all codecs */ 1334 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1335 1336 /* restore status */ 1337 for (i = 2; i < 0x7c ; i += 2) { 1338 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 1339 continue; 1340 if (test_bit(i, ac97->reg_accessed)) { 1341 /* handle multi codecs for AD18xx */ 1342 if (i == AC97_PCM) { 1343 for (codec = 0; codec < 3; codec++) { 1344 if (! ac97->spec.ad18xx.id[codec]) 1345 continue; 1346 /* select single codec */ 1347 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1348 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 1349 /* update PCM bits */ 1350 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); 1351 } 1352 /* select all codecs */ 1353 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1354 continue; 1355 } else if (i == AC97_AD_TEST || 1356 i == AC97_AD_CODEC_CFG || 1357 i == AC97_AD_SERIAL_CFG) 1358 continue; /* ignore */ 1359 } 1360 snd_ac97_write(ac97, i, ac97->regs[i]); 1361 snd_ac97_read(ac97, i); 1362 } 1363 } 1364 1365 snd_ac97_restore_iec958(ac97); 1366 } 1367 1368 int patch_ad1819(ac97_t * ac97) 1369 { 1370 unsigned short scfg; 1371 // patch for Analog Devices 1372 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 1373 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ 1374 return 0; 1375 } 1376 1377 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask) 1378 { 1379 unsigned short val; 1380 1381 // test for unchained codec 1382 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); 1383 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ 1384 val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 1385 if ((val & 0xff40) != 0x5340) 1386 return 0; 1387 ac97->spec.ad18xx.unchained[idx] = mask; 1388 ac97->spec.ad18xx.id[idx] = val; 1389 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; 1390 return mask; 1391 } 1392 1393 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits) 1394 { 1395 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; 1396 unsigned short val; 1397 1398 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); 1399 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE 1400 val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 1401 if ((val & 0xff40) != 0x5340) 1402 return 0; 1403 if (codec_bits) 1404 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); 1405 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; 1406 ac97->spec.ad18xx.id[idx] = val; 1407 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; 1408 return 1; 1409 } 1410 1411 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2) 1412 { 1413 // already detected? 1414 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) 1415 cidx1 = -1; 1416 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) 1417 cidx2 = -1; 1418 if (cidx1 < 0 && cidx2 < 0) 1419 return; 1420 // test for chained codecs 1421 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1422 ac97->spec.ad18xx.unchained[unchained_idx]); 1423 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C 1424 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; 1425 if (cidx1 >= 0) { 1426 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C 1427 patch_ad1881_chained1(ac97, cidx2, 0); 1428 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C 1429 patch_ad1881_chained1(ac97, cidx1, 0); 1430 } else if (cidx2 >= 0) { 1431 patch_ad1881_chained1(ac97, cidx2, 0); 1432 } 1305 #ifdef CONFIG_PM 1306 static void ad18xx_resume(struct snd_ac97 *ac97) 1307 { 1308 static unsigned short setup_regs[] = { 1309 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, 1310 }; 1311 int i, codec; 1312 1313 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { 1314 unsigned short reg = setup_regs[i]; 1315 if (test_bit(reg, ac97->reg_accessed)) { 1316 snd_ac97_write(ac97, reg, ac97->regs[reg]); 1317 snd_ac97_read(ac97, reg); 1318 } 1319 } 1320 1321 if (! (ac97->flags & AC97_AD_MULTI)) 1322 /* normal restore */ 1323 snd_ac97_restore_status(ac97); 1324 else { 1325 /* restore the AD18xx codec configurations */ 1326 for (codec = 0; codec < 3; codec++) { 1327 if (! ac97->spec.ad18xx.id[codec]) 1328 continue; 1329 /* select single codec */ 1330 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1331 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 1332 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); 1333 } 1334 /* select all codecs */ 1335 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1336 1337 /* restore status */ 1338 for (i = 2; i < 0x7c ; i += 2) { 1339 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 1340 continue; 1341 if (test_bit(i, ac97->reg_accessed)) { 1342 /* handle multi codecs for AD18xx */ 1343 if (i == AC97_PCM) { 1344 for (codec = 0; codec < 3; codec++) { 1345 if (! ac97->spec.ad18xx.id[codec]) 1346 continue; 1347 /* select single codec */ 1348 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1349 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 1350 /* update PCM bits */ 1351 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); 1352 } 1353 /* select all codecs */ 1354 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1355 continue; 1356 } else if (i == AC97_AD_TEST || 1357 i == AC97_AD_CODEC_CFG || 1358 i == AC97_AD_SERIAL_CFG) 1359 continue; /* ignore */ 1360 } 1361 snd_ac97_write(ac97, i, ac97->regs[i]); 1362 snd_ac97_read(ac97, i); 1363 } 1364 } 1365 1366 snd_ac97_restore_iec958(ac97); 1367 } 1368 #endif 1369 1370 int patch_ad1819(struct snd_ac97 * ac97) 1371 { 1372 unsigned short scfg; 1373 1374 // patch for Analog Devices 1375 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 1376 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ 1377 return 0; 1378 } 1379 1380 static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask) 1381 { 1382 unsigned short val; 1383 1384 // test for unchained codec 1385 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); 1386 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ 1387 val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 1388 if ((val & 0xff40) != 0x5340) 1389 return 0; 1390 ac97->spec.ad18xx.unchained[idx] = mask; 1391 ac97->spec.ad18xx.id[idx] = val; 1392 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; 1393 return mask; 1394 } 1395 1396 static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits) 1397 { 1398 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; 1399 unsigned short val; 1400 1401 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); 1402 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE 1403 val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 1404 if ((val & 0xff40) != 0x5340) 1405 return 0; 1406 if (codec_bits) 1407 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); 1408 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; 1409 ac97->spec.ad18xx.id[idx] = val; 1410 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; 1411 return 1; 1412 } 1413 1414 static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2) 1415 { 1416 // already detected? 1417 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) 1418 cidx1 = -1; 1419 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) 1420 cidx2 = -1; 1421 if (cidx1 < 0 && cidx2 < 0) 1422 return; 1423 // test for chained codecs 1424 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 1425 ac97->spec.ad18xx.unchained[unchained_idx]); 1426 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C 1427 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; 1428 if (cidx1 >= 0) { 1429 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C 1430 patch_ad1881_chained1(ac97, cidx2, 0); 1431 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C 1432 patch_ad1881_chained1(ac97, cidx1, 0); 1433 } else if (cidx2 >= 0) { 1434 patch_ad1881_chained1(ac97, cidx2, 0); 1435 } 1433 1436 } 1434 1437 1435 1438 static struct snd_ac97_build_ops patch_ad1881_build_ops = { 1436 0,0,0,0,0,ad18xx_resume 1437 }; 1438 1439 int patch_ad1881(ac97_t * ac97) 1440 { 1441 static const char cfg_idxs[3][2] = { 1442 {2, 1}, 1443 {0, 2}, 1444 {0, 1} 1445 }; 1446 1447 // patch for Analog Devices 1448 unsigned short codecs[3]; 1449 unsigned short val; 1450 int idx, num; 1451 1452 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 1453 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); 1454 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); 1455 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 1456 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 1457 1458 if (! (codecs[0] || codecs[1] || codecs[2])) 1459 goto __end; 1460 1461 for (idx = 0; idx < 3; idx++) 1462 if (ac97->spec.ad18xx.unchained[idx]) 1463 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); 1464 1465 if (ac97->spec.ad18xx.id[1]) { 1466 ac97->flags |= AC97_AD_MULTI; 1467 ac97->scaps |= AC97_SCAP_SURROUND_DAC; 1468 } 1469 if (ac97->spec.ad18xx.id[2]) { 1470 ac97->flags |= AC97_AD_MULTI; 1471 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 1472 } 1473 1474 __end: 1475 /* select all codecs */ 1476 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1477 /* check if only one codec is present */ 1478 for (idx = num = 0; idx < 3; idx++) 1479 if (ac97->spec.ad18xx.id[idx]) 1480 num++; 1481 if (num == 1) { 1482 /* ok, deselect all ID bits */ 1483 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); 1484 ac97->spec.ad18xx.codec_cfg[0] = 1485 ac97->spec.ad18xx.codec_cfg[1] = 1486 ac97->spec.ad18xx.codec_cfg[2] = 0x0000; 1487 } 1488 /* required for AD1886/AD1885 combination */ 1489 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 1490 if (ac97->spec.ad18xx.id[0]) { 1491 ac97->id &= 0xffff0000; 1492 ac97->id |= ac97->spec.ad18xx.id[0]; 1493 } 1494 ac97->build_ops = &patch_ad1881_build_ops; 1495 return 0; 1496 } 1497 1498 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = { 1499 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), 1500 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ 1501 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), 1502 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), 1503 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ 1504 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ 1505 }; 1506 1507 static int patch_ad1885_specific(ac97_t * ac97) 1508 { 1509 int err; 1510 1511 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) 1512 return err; 1513 return 0; 1439 #ifdef CONFIG_PM 1440 .resume = ad18xx_resume 1441 #endif 1442 }; 1443 1444 int patch_ad1881(struct snd_ac97 * ac97) 1445 { 1446 static const char cfg_idxs[3][2] = { 1447 {2, 1}, 1448 {0, 2}, 1449 {0, 1} 1450 }; 1451 1452 // patch for Analog Devices 1453 unsigned short codecs[3]; 1454 unsigned short val; 1455 int idx, num; 1456 1457 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 1458 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); 1459 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); 1460 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 1461 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 1462 1463 if (! (codecs[0] || codecs[1] || codecs[2])) 1464 goto __end; 1465 1466 for (idx = 0; idx < 3; idx++) 1467 if (ac97->spec.ad18xx.unchained[idx]) 1468 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); 1469 1470 if (ac97->spec.ad18xx.id[1]) { 1471 ac97->flags |= AC97_AD_MULTI; 1472 ac97->scaps |= AC97_SCAP_SURROUND_DAC; 1473 } 1474 if (ac97->spec.ad18xx.id[2]) { 1475 ac97->flags |= AC97_AD_MULTI; 1476 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 1477 } 1478 1479 __end: 1480 /* select all codecs */ 1481 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 1482 /* check if only one codec is present */ 1483 for (idx = num = 0; idx < 3; idx++) 1484 if (ac97->spec.ad18xx.id[idx]) 1485 num++; 1486 if (num == 1) { 1487 /* ok, deselect all ID bits */ 1488 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); 1489 ac97->spec.ad18xx.codec_cfg[0] = 1490 ac97->spec.ad18xx.codec_cfg[1] = 1491 ac97->spec.ad18xx.codec_cfg[2] = 0x0000; 1492 } 1493 /* required for AD1886/AD1885 combination */ 1494 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 1495 if (ac97->spec.ad18xx.id[0]) { 1496 ac97->id &= 0xffff0000; 1497 ac97->id |= ac97->spec.ad18xx.id[0]; 1498 } 1499 ac97->build_ops = &patch_ad1881_build_ops; 1500 return 0; 1501 } 1502 1503 static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { 1504 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), 1505 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ 1506 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), 1507 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), 1508 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ 1509 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ 1510 }; 1511 1512 static int patch_ad1885_specific(struct snd_ac97 * ac97) 1513 { 1514 int err; 1515 1516 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) 1517 return err; 1518 return 0; 1514 1519 } 1515 1520 1516 1521 static struct snd_ac97_build_ops patch_ad1885_build_ops = { 1517 NULL, 1518 patch_ad1885_specific, 1519 NULL, NULL,0, ad18xx_resume 1520 }; 1521 1522 int patch_ad1885(ac97_t * ac97) 1523 { 1524 patch_ad1881(ac97); 1525 /* This is required to deal with the Intel D815EEAL2 */ 1526 /* i.e. Line out is actually headphone out from codec */ 1527 1528 /* set default */ 1529 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); 1530 1531 ac97->build_ops = &patch_ad1885_build_ops; 1532 return 0; 1533 } 1534 1535 int patch_ad1886(ac97_t * ac97) 1536 { 1537 patch_ad1881(ac97); 1538 /* Presario700 workaround */ 1539 /* for Jack Sense/SPDIF Register misetting causing */ 1540 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); 1541 return 0; 1522 .build_specific = &patch_ad1885_specific, 1523 #ifdef CONFIG_PM 1524 .resume = ad18xx_resume 1525 #endif 1526 }; 1527 1528 int patch_ad1885(struct snd_ac97 * ac97) 1529 { 1530 patch_ad1881(ac97); 1531 /* This is required to deal with the Intel D815EEAL2 */ 1532 /* i.e. Line out is actually headphone out from codec */ 1533 1534 /* set default */ 1535 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); 1536 1537 ac97->build_ops = &patch_ad1885_build_ops; 1538 return 0; 1539 } 1540 1541 int patch_ad1886(struct snd_ac97 * ac97) 1542 { 1543 patch_ad1881(ac97); 1544 /* Presario700 workaround */ 1545 /* for Jack Sense/SPDIF Register misetting causing */ 1546 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); 1547 return 0; 1542 1548 } 1543 1549 … … 1564 1570 1565 1571 1566 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1567 { 1568 static char *texts[2] = { "AC-Link", "A/D Converter" }; 1569 1570 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1571 uinfo->count = 1; 1572 uinfo->value.enumerated.items = 2; 1573 if (uinfo->value.enumerated.item > 1) 1574 uinfo->value.enumerated.item = 1; 1575 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1576 return 0; 1577 } 1578 1579 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1580 { 1581 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1582 unsigned short val; 1583 1584 val = ac97->regs[AC97_AD_SERIAL_CFG]; 1585 ucontrol->value.enumerated.item[0] = (val >> 2) & 1; 1586 return 0; 1587 } 1588 1589 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1590 { 1591 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1592 unsigned short val; 1593 1594 if (ucontrol->value.enumerated.item[0] > 1) 1595 return -EINVAL; 1596 val = ucontrol->value.enumerated.item[0] << 2; 1597 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); 1598 } 1599 1600 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = { 1601 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, 1602 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 0,0,0, 1603 snd_ac97_ad198x_spdif_source_info, 1604 snd_ac97_ad198x_spdif_source_get, 1605 snd_ac97_ad198x_spdif_source_put, 0, 1606 }; 1607 1608 static int patch_ad198x_post_spdif(ac97_t * ac97) 1609 { 1610 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); 1611 } 1612 1613 static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = { 1614 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), 1615 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 1616 }; 1617 1618 static int patch_ad1981a_specific(ac97_t * ac97) 1619 { 1620 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 1621 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 1572 static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1573 { 1574 static char *texts[2] = { "AC-Link", "A/D Converter" }; 1575 1576 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1577 uinfo->count = 1; 1578 uinfo->value.enumerated.items = 2; 1579 if (uinfo->value.enumerated.item > 1) 1580 uinfo->value.enumerated.item = 1; 1581 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1582 return 0; 1583 } 1584 1585 static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1586 { 1587 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1588 unsigned short val; 1589 1590 val = ac97->regs[AC97_AD_SERIAL_CFG]; 1591 ucontrol->value.enumerated.item[0] = (val >> 2) & 1; 1592 return 0; 1593 } 1594 1595 static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1596 { 1597 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1598 unsigned short val; 1599 1600 if (ucontrol->value.enumerated.item[0] > 1) 1601 return -EINVAL; 1602 val = ucontrol->value.enumerated.item[0] << 2; 1603 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); 1604 } 1605 1606 static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { 1607 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1608 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 1609 .info = snd_ac97_ad198x_spdif_source_info, 1610 .get = snd_ac97_ad198x_spdif_source_get, 1611 .put = snd_ac97_ad198x_spdif_source_put, 1612 }; 1613 1614 static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) 1615 { 1616 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); 1617 } 1618 1619 static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { 1620 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), 1621 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 1622 }; 1623 1624 /* black list to avoid HP/Line jack-sense controls 1625 * (SS vendor << 16 | device) 1626 */ 1627 static unsigned int ad1981_jacks_blacklist[] = { 1628 0x10140554, /* Thinkpad T42p/R50p */ 1629 0 /* end */ 1630 }; 1631 1632 static int check_list(struct snd_ac97 *ac97, const unsigned int *list) 1633 { 1634 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; 1635 for (; *list; list++) 1636 if (*list == subid) 1637 return 1; 1638 return 0; 1639 } 1640 1641 static int patch_ad1981a_specific(struct snd_ac97 * ac97) 1642 { 1643 if (check_list(ac97, ad1981_jacks_blacklist)) 1644 return 0; 1645 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 1646 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 1622 1647 } 1623 1648 1624 1649 static struct snd_ac97_build_ops patch_ad1981a_build_ops = { 1625 NULL,patch_ad1981a_specific, 1626 NULL, 1627 /*.build_post_spdif = */patch_ad198x_post_spdif,0, 1628 ad18xx_resume 1629 }; 1630 1631 static void check_ad1981_hp_jack_sense(ac97_t *ac97) 1632 { 1633 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; 1634 switch (subid) { 1635 case 0x103c0890: /* HP nc6000 */ 1636 case 0x103c099c: /* HP nx6110 */ 1637 case 0x103c006d: /* HP nx9105 */ 1638 case 0x17340088: /* FSC Scenic-W */ 1639 /* enable headphone jack sense */ 1640 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); 1641 break; 1642 } 1643 } 1644 1645 int patch_ad1981a(ac97_t *ac97) 1646 { 1647 patch_ad1881(ac97); 1648 ac97->build_ops = &patch_ad1981a_build_ops; 1649 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 1650 ac97->flags |= AC97_STEREO_MUTES; 1651 check_ad1981_hp_jack_sense(ac97); 1652 return 0; 1653 } 1654 1655 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic = 1650 .build_post_spdif = patch_ad198x_post_spdif, 1651 .build_specific = patch_ad1981a_specific, 1652 #ifdef CONFIG_PM 1653 .resume = ad18xx_resume 1654 #endif 1655 }; 1656 1657 /* white list to enable HP jack-sense bits 1658 * (SS vendor << 16 | device) 1659 */ 1660 static unsigned int ad1981_jacks_whitelist[] = { 1661 0x0e11005a, /* HP nc4000/4010 */ 1662 0x103c0890, /* HP nc6000 */ 1663 0x103c0938, /* HP nc4220 */ 1664 0x103c099c, /* HP nx6110 */ 1665 0x103c0944, /* HP nc6220 */ 1666 0x103c0934, /* HP nc8220 */ 1667 0x103c006d, /* HP nx9105 */ 1668 0x17340088, /* FSC Scenic-W */ 1669 0 /* end */ 1670 }; 1671 1672 static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) 1673 { 1674 if (check_list(ac97, ad1981_jacks_whitelist)) 1675 /* enable headphone jack sense */ 1676 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); 1677 } 1678 1679 int patch_ad1981a(struct snd_ac97 *ac97) 1680 { 1681 patch_ad1881(ac97); 1682 ac97->build_ops = &patch_ad1981a_build_ops; 1683 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 1684 ac97->flags |= AC97_STEREO_MUTES; 1685 check_ad1981_hp_jack_sense(ac97); 1686 return 0; 1687 } 1688 1689 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = 1656 1690 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); 1657 1691 1658 static int patch_ad1981b_specific(ac97_t *ac97) 1659 { 1660 int err; 1661 1662 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 1663 return err; 1664 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 1665 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 1692 static int patch_ad1981b_specific(struct snd_ac97 *ac97) 1693 { 1694 int err; 1695 1696 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 1697 return err; 1698 if (check_list(ac97, ad1981_jacks_blacklist)) 1699 return 0; 1700 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 1701 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 1666 1702 } 1667 1703 1668 1704 static struct snd_ac97_build_ops patch_ad1981b_build_ops = { 1669 NULL, /*.build_specific = */patch_ad1981b_specific, 1670 NULL, /*.build_post_spdif = */patch_ad198x_post_spdif,0, 1671 ad18xx_resume 1672 }; 1673 1674 int patch_ad1981b(ac97_t *ac97) 1675 { 1676 patch_ad1881(ac97); 1677 ac97->build_ops = &patch_ad1981b_build_ops; 1678 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 1679 ac97->flags |= AC97_STEREO_MUTES; 1680 check_ad1981_hp_jack_sense(ac97); 1681 return 0; 1682 } 1683 1684 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1685 { 1686 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1687 uinfo->count = 1; 1688 uinfo->value.integer.min = 0; 1689 uinfo->value.integer.max = 1; 1690 return 0; 1691 } 1692 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) 1693 { 1694 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1695 unsigned short val; 1696 1697 val = ac97->regs[AC97_AD_MISC]; 1698 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); 1699 return 0; 1700 } 1701 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1702 { 1703 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1704 unsigned short val; 1705 1706 val = !ucontrol->value.integer.value[0] 1707 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; 1708 return snd_ac97_update_bits(ac97, AC97_AD_MISC, 1709 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); 1710 } 1711 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1712 { 1713 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 1714 1715 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1716 uinfo->count = 1; 1717 uinfo->value.enumerated.items = 3; 1718 if (uinfo->value.enumerated.item > 2) 1719 uinfo->value.enumerated.item = 2; 1720 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1721 return 0; 1722 } 1723 1724 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) 1725 { 1726 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1727 unsigned short val; 1728 1729 val = ac97->regs[AC97_AD_MISC]; 1730 if (!(val & AC97_AD198X_DMIX1)) 1731 ucontrol->value.enumerated.item[0] = 0; 1732 else 1733 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); 1734 return 0; 1735 } 1736 1737 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1738 { 1739 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 1740 unsigned short val; 1741 1742 if (ucontrol->value.enumerated.item[0] > 2) 1743 return -EINVAL; 1744 if (ucontrol->value.enumerated.item[0] == 0) 1745 val = 0; 1746 else 1747 val = AC97_AD198X_DMIX1 | 1748 ((ucontrol->value.enumerated.item[0] - 1) << 8); 1749 return snd_ac97_update_bits(ac97, AC97_AD_MISC, 1750 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); 1751 } 1752 1753 static void ad1888_update_jacks(ac97_t *ac97) 1754 { 1755 unsigned short val = 0; 1756 if (! is_shared_linein(ac97)) 1757 val |= (1 << 12); 1758 if (! is_shared_micin(ac97)) 1759 val |= (1 << 11); 1760 /* shared Line-In */ 1761 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); 1762 } 1763 1764 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = { 1765 { 1766 /*.iface =*/ SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 1767 /*.name = */"Exchange Front/Surround",0,0,0, 1768 /*.info = */snd_ac97_ad1888_lohpsel_info, 1769 /*.get = */snd_ac97_ad1888_lohpsel_get, 1770 /*.put = */snd_ac97_ad1888_lohpsel_put,0 1771 }, 1772 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 1773 { 1774 /*.iface = */SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 1775 /*.name = */"Downmix",0,0,0, 1776 /*.info = */snd_ac97_ad1888_downmix_info, 1777 /*.get = */snd_ac97_ad1888_downmix_get, 1778 /*.put = */snd_ac97_ad1888_downmix_put,0 1779 }, 1780 AC97_SURROUND_JACK_MODE_CTL, 1781 AC97_CHANNEL_MODE_CTL, 1782 1783 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 1784 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 1785 }; 1786 1787 static int patch_ad1888_specific(ac97_t *ac97) 1788 { 1789 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 1790 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback"); 1791 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 1792 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); 1705 .build_post_spdif = patch_ad198x_post_spdif, 1706 .build_specific = patch_ad1981b_specific, 1707 #ifdef CONFIG_PM 1708 .resume = ad18xx_resume 1709 #endif 1710 }; 1711 1712 int patch_ad1981b(struct snd_ac97 *ac97) 1713 { 1714 patch_ad1881(ac97); 1715 ac97->build_ops = &patch_ad1981b_build_ops; 1716 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 1717 ac97->flags |= AC97_STEREO_MUTES; 1718 check_ad1981_hp_jack_sense(ac97); 1719 return 0; 1720 } 1721 1722 static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1723 { 1724 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1725 uinfo->count = 1; 1726 uinfo->value.integer.min = 0; 1727 uinfo->value.integer.max = 1; 1728 return 0; 1729 } 1730 1731 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1732 { 1733 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1734 unsigned short val; 1735 1736 val = ac97->regs[AC97_AD_MISC]; 1737 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); 1738 return 0; 1739 } 1740 1741 static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1742 { 1743 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1744 unsigned short val; 1745 1746 val = !ucontrol->value.integer.value[0] 1747 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; 1748 return snd_ac97_update_bits(ac97, AC97_AD_MISC, 1749 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); 1750 } 1751 1752 static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1753 { 1754 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 1755 1756 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1757 uinfo->count = 1; 1758 uinfo->value.enumerated.items = 3; 1759 if (uinfo->value.enumerated.item > 2) 1760 uinfo->value.enumerated.item = 2; 1761 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1762 return 0; 1763 } 1764 1765 static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1766 { 1767 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1768 unsigned short val; 1769 1770 val = ac97->regs[AC97_AD_MISC]; 1771 if (!(val & AC97_AD198X_DMIX1)) 1772 ucontrol->value.enumerated.item[0] = 0; 1773 else 1774 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); 1775 return 0; 1776 } 1777 1778 static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1779 { 1780 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 1781 unsigned short val; 1782 1783 if (ucontrol->value.enumerated.item[0] > 2) 1784 return -EINVAL; 1785 if (ucontrol->value.enumerated.item[0] == 0) 1786 val = 0; 1787 else 1788 val = AC97_AD198X_DMIX1 | 1789 ((ucontrol->value.enumerated.item[0] - 1) << 8); 1790 return snd_ac97_update_bits(ac97, AC97_AD_MISC, 1791 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); 1792 } 1793 1794 static void ad1888_update_jacks(struct snd_ac97 *ac97) 1795 { 1796 unsigned short val = 0; 1797 if (! is_shared_linein(ac97)) 1798 val |= (1 << 12); 1799 if (! is_shared_micin(ac97)) 1800 val |= (1 << 11); 1801 /* shared Line-In */ 1802 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); 1803 } 1804 1805 static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { 1806 { 1807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1808 .name = "Exchange Front/Surround", 1809 .info = snd_ac97_ad1888_lohpsel_info, 1810 .get = snd_ac97_ad1888_lohpsel_get, 1811 .put = snd_ac97_ad1888_lohpsel_put 1812 }, 1813 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 1814 { 1815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1816 .name = "Downmix", 1817 .info = snd_ac97_ad1888_downmix_info, 1818 .get = snd_ac97_ad1888_downmix_get, 1819 .put = snd_ac97_ad1888_downmix_put 1820 }, 1821 AC97_SURROUND_JACK_MODE_CTL, 1822 AC97_CHANNEL_MODE_CTL, 1823 1824 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 1825 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 1826 }; 1827 1828 static int patch_ad1888_specific(struct snd_ac97 *ac97) 1829 { 1830 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 1831 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback"); 1832 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 1833 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); 1793 1834 } 1794 1835 1795 1836 static struct snd_ac97_build_ops patch_ad1888_build_ops = { 1796 NULL, patch_ad1888_specific, NULL, patch_ad198x_post_spdif,0, 1797 ad18xx_resume, 1798 ad1888_update_jacks 1799 }; 1800 1801 int patch_ad1888(ac97_t * ac97) 1802 { 1803 unsigned short misc; 1804 1805 patch_ad1881(ac97); 1806 ac97->build_ops = &patch_ad1888_build_ops; 1807 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ 1808 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */ 1809 /* AD-compatible mode */ 1810 /* Stereo mutes enabled */ 1811 misc = snd_ac97_read(ac97, AC97_AD_MISC); 1812 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 1813 AC97_AD198X_LOSEL | 1814 AC97_AD198X_HPSEL | 1815 AC97_AD198X_MSPLT | 1816 AC97_AD198X_AC97NC); 1817 ac97->flags |= AC97_STEREO_MUTES; 1818 return 0; 1819 } 1820 1821 static int patch_ad1980_specific(ac97_t *ac97) 1822 { 1823 int err; 1824 1825 if ((err = patch_ad1888_specific(ac97)) < 0) 1826 return err; 1827 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); 1837 .build_post_spdif = patch_ad198x_post_spdif, 1838 .build_specific = patch_ad1888_specific, 1839 #ifdef CONFIG_PM 1840 .resume = ad18xx_resume, 1841 #endif 1842 .update_jacks = ad1888_update_jacks, 1843 }; 1844 1845 int patch_ad1888(struct snd_ac97 * ac97) 1846 { 1847 unsigned short misc; 1848 1849 patch_ad1881(ac97); 1850 ac97->build_ops = &patch_ad1888_build_ops; 1851 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ 1852 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */ 1853 /* AD-compatible mode */ 1854 /* Stereo mutes enabled */ 1855 misc = snd_ac97_read(ac97, AC97_AD_MISC); 1856 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 1857 AC97_AD198X_LOSEL | 1858 AC97_AD198X_HPSEL | 1859 AC97_AD198X_MSPLT | 1860 AC97_AD198X_AC97NC); 1861 ac97->flags |= AC97_STEREO_MUTES; 1862 return 0; 1863 } 1864 1865 static int patch_ad1980_specific(struct snd_ac97 *ac97) 1866 { 1867 int err; 1868 1869 if ((err = patch_ad1888_specific(ac97)) < 0) 1870 return err; 1871 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); 1828 1872 } 1829 1873 1830 1874 static struct snd_ac97_build_ops patch_ad1980_build_ops = { 1831 NULL, 1832 /*.build_specific =*/ patch_ad1980_specific, 1833 NULL, 1834 /*.build_post_spdif =*/ patch_ad198x_post_spdif, 0, ad18xx_resume, 1835 ad1888_update_jacks 1836 }; 1837 1838 int patch_ad1980(ac97_t * ac97) 1839 { 1840 patch_ad1888(ac97); 1841 ac97->build_ops = &patch_ad1980_build_ops; 1842 return 0; 1843 } 1844 1845 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = { 1846 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0) 1847 }; 1848 1849 static void ad1985_update_jacks(ac97_t *ac97) 1850 { 1851 ad1888_update_jacks(ac97); 1852 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 1853 is_shared_micin(ac97) ? 0 : 1 << 9); 1854 } 1855 1856 static int patch_ad1985_specific(ac97_t *ac97) 1857 { 1858 int err; 1859 1860 if ((err = patch_ad1980_specific(ac97)) < 0) 1861 return err; 1862 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls)); 1875 .build_post_spdif = patch_ad198x_post_spdif, 1876 .build_specific = patch_ad1980_specific, 1877 #ifdef CONFIG_PM 1878 .resume = ad18xx_resume, 1879 #endif 1880 .update_jacks = ad1888_update_jacks, 1881 }; 1882 1883 int patch_ad1980(struct snd_ac97 * ac97) 1884 { 1885 patch_ad1888(ac97); 1886 ac97->build_ops = &patch_ad1980_build_ops; 1887 return 0; 1888 } 1889 1890 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { 1891 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0) 1892 }; 1893 1894 static void ad1985_update_jacks(struct snd_ac97 *ac97) 1895 { 1896 ad1888_update_jacks(ac97); 1897 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 1898 is_shared_micin(ac97) ? 0 : 1 << 9); 1899 } 1900 1901 static int patch_ad1985_specific(struct snd_ac97 *ac97) 1902 { 1903 int err; 1904 1905 if ((err = patch_ad1980_specific(ac97)) < 0) 1906 return err; 1907 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls)); 1863 1908 } 1864 1909 1865 1910 static struct snd_ac97_build_ops patch_ad1985_build_ops = { 1866 NULL,/*.build_specific = */patch_ad1985_specific, 1867 NULL, /*.build_post_spdif = */patch_ad198x_post_spdif, 0, ad18xx_resume, 1868 ad1985_update_jacks 1869 }; 1870 1871 int patch_ad1985(ac97_t * ac97) 1872 { 1873 unsigned short misc; 1874 1875 patch_ad1881(ac97); 1876 ac97->build_ops = &patch_ad1985_build_ops; 1877 misc = snd_ac97_read(ac97, AC97_AD_MISC); 1878 /* switch front/surround line-out/hp-out */ 1879 /* center/LFE, mic in 3.75V mode */ 1880 /* AD-compatible mode */ 1881 /* Stereo mutes enabled */ 1882 /* in accordance with ADI driver: misc | 0x5c28 */ 1883 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 1884 AC97_AD198X_VREFH | 1885 AC97_AD198X_LOSEL | 1886 AC97_AD198X_HPSEL | 1887 AC97_AD198X_CLDIS | 1888 AC97_AD198X_LODIS | 1889 AC97_AD198X_MSPLT | 1890 AC97_AD198X_AC97NC); 1891 ac97->flags |= AC97_STEREO_MUTES; 1892 /* on AD1985 rev. 3, AC'97 revision bits are zero */ 1893 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; 1894 return 0; 1895 } 1911 .build_post_spdif = patch_ad198x_post_spdif, 1912 .build_specific = patch_ad1985_specific, 1913 #ifdef CONFIG_PM 1914 .resume = ad18xx_resume, 1915 #endif 1916 .update_jacks = ad1985_update_jacks, 1917 }; 1918 1919 int patch_ad1985(struct snd_ac97 * ac97) 1920 { 1921 unsigned short misc; 1922 1923 patch_ad1881(ac97); 1924 ac97->build_ops = &patch_ad1985_build_ops; 1925 misc = snd_ac97_read(ac97, AC97_AD_MISC); 1926 /* switch front/surround line-out/hp-out */ 1927 /* center/LFE, mic in 3.75V mode */ 1928 /* AD-compatible mode */ 1929 /* Stereo mutes enabled */ 1930 /* in accordance with ADI driver: misc | 0x5c28 */ 1931 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 1932 AC97_AD198X_VREFH | 1933 AC97_AD198X_LOSEL | 1934 AC97_AD198X_HPSEL | 1935 AC97_AD198X_CLDIS | 1936 AC97_AD198X_LODIS | 1937 AC97_AD198X_MSPLT | 1938 AC97_AD198X_AC97NC); 1939 ac97->flags |= AC97_STEREO_MUTES; 1940 /* on AD1985 rev. 3, AC'97 revision bits are zero */ 1941 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; 1942 return 0; 1943 } 1944 1896 1945 /* 1897 1946 * realtek ALC65x/850 codecs 1898 1947 */ 1899 static void alc650_update_jacks( ac97_t*ac97)1900 { 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 } 1919 1920 static const s nd_kcontrol_new_tsnd_ac97_controls_alc650[] = {1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1948 static void alc650_update_jacks(struct snd_ac97 *ac97) 1949 { 1950 int shared; 1951 1952 /* shared Line-In */ 1953 shared = is_shared_linein(ac97); 1954 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, 1955 shared ? (1 << 9) : 0); 1956 /* update shared Mic */ 1957 shared = is_shared_micin(ac97); 1958 /* disable/enable vref */ 1959 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 1960 shared ? (1 << 12) : 0); 1961 /* turn on/off center-on-mic */ 1962 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, 1963 shared ? (1 << 10) : 0); 1964 /* GPIO0 high for mic */ 1965 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, 1966 shared ? 0 : 0x100); 1967 } 1968 1969 static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { 1970 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), 1971 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), 1972 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), 1973 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), 1974 /* 4: Analog Input To Surround */ 1975 /* 5: Analog Input To Center/LFE */ 1976 /* 6: Independent Master Volume Right */ 1977 /* 7: Independent Master Volume Left */ 1978 /* 8: reserved */ 1979 /* 9: Line-In/Surround share */ 1980 /* 10: Mic/CLFE share */ 1981 /* 11-13: in IEC958 controls */ 1982 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0), 1934 1983 #if 0 /* always set in patch_alc650 */ 1935 1936 1937 1938 1939 1940 1984 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), 1985 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), 1986 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), 1987 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), 1988 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), 1989 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), 1941 1990 #endif 1942 1943 1944 }; 1945 1946 static const s nd_kcontrol_new_tsnd_ac97_spdif_controls_alc650[] = {1947 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),1948 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),1949 1950 1951 }; 1952 1953 static int patch_alc650_specific( ac97_t* ac97)1954 { 1955 1956 1957 1958 1959 1960 1961 1962 1963 1991 AC97_SURROUND_JACK_MODE_CTL, 1992 AC97_CHANNEL_MODE_CTL, 1993 }; 1994 1995 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { 1996 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0), 1997 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), 1998 /* disable this controls since it doesn't work as expected */ 1999 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ 2000 }; 2001 2002 static int patch_alc650_specific(struct snd_ac97 * ac97) 2003 { 2004 int err; 2005 2006 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) 2007 return err; 2008 if (ac97->ext_id & AC97_EI_SPDIF) { 2009 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) 2010 return err; 2011 } 2012 return 0; 1964 2013 } 1965 2014 1966 2015 static struct snd_ac97_build_ops patch_alc650_ops = { 1967 NULL, patch_alc650_specific, NULL, NULL,0,0, 1968 alc650_update_jacks 1969 }; 1970 1971 int patch_alc650(ac97_t * ac97) 1972 { 1973 unsigned short val; 1974 1975 ac97->build_ops = &patch_alc650_ops; 1976 1977 /* determine the revision */ 1978 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; 1979 if (val < 3) 1980 ac97->id = 0x414c4720; /* Old version */ 1981 else if (val < 0x10) 1982 ac97->id = 0x414c4721; /* D version */ 1983 else if (val < 0x20) 1984 ac97->id = 0x414c4722; /* E version */ 1985 else if (val < 0x30) 1986 ac97->id = 0x414c4723; /* F version */ 1987 1988 /* revision E or F */ 1989 /* FIXME: what about revision D ? */ 1990 ac97->spec.dev_flags = (ac97->id == 0x414c4722 || 1991 ac97->id == 0x414c4723); 1992 1993 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ 1994 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 1995 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); 1996 1997 /* Enable SPDIF-IN only on Rev.E and above */ 1998 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); 1999 /* SPDIF IN with pin 47 */ 2000 if (ac97->spec.dev_flags) 2001 val |= 0x03; /* enable */ 2002 else 2003 val &= ~0x03; /* disable */ 2004 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); 2005 /* set default: slot 3,4,7,8,6,9 2006 spdif-in monitor off, analog-spdif off, spdif-in off 2007 center on mic off, surround on line-in off 2008 downmix off, duplicate front off 2009 */ 2010 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); 2011 2012 /* set GPIO0 for mic bias */ 2013 /* GPIO0 pin output, no interrupt, high */ 2014 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, 2015 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); 2016 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 2017 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); 2018 /* full DAC volume */ 2019 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2020 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2021 return 0; 2022 } 2023 2024 static void alc655_update_jacks(ac97_t *ac97) 2025 { 2026 int shared; 2027 /* shared Line-In */ 2028 shared = is_shared_linein(ac97); 2029 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, 2030 shared ? (1 << 9) : 0, 0); 2031 /* update shared mic */ 2032 shared = is_shared_micin(ac97); 2033 /* misc control; vrefout disable */ 2034 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2035 shared ? (1 << 12) : 0); 2036 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, 2037 shared ? (1 << 10) : 0, 0); 2038 } 2039 2040 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = { 2041 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2042 AC97_SURROUND_JACK_MODE_CTL, 2043 AC97_CHANNEL_MODE_CTL, 2044 }; 2045 2046 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 2047 { 2048 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; 2049 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; 2050 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2051 2052 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2053 uinfo->count = 1; 2054 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; 2055 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2056 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2057 strcpy(uinfo->value.enumerated.name, 2058 ac97->spec.dev_flags ? 2059 texts_658[uinfo->value.enumerated.item] : 2060 texts_655[uinfo->value.enumerated.item]); 2061 return 0; 2062 } 2063 2064 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 2065 { 2066 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2067 unsigned short val; 2068 2069 val = ac97->regs[AC97_ALC650_MULTICH]; 2070 val = (val >> 12) & 3; 2071 if (ac97->spec.dev_flags && val == 3) 2072 val = 0; 2073 ucontrol->value.enumerated.item[0] = val; 2074 return 0; 2075 } 2076 2077 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 2078 { 2079 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2080 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, 2081 (unsigned short)ucontrol->value.enumerated.item[0] << 12, 2082 0); 2083 } 2084 2085 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = { 2086 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), 2087 /* disable this controls since it doesn't work as expected */ 2088 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ 2089 { 2090 /*.iface =*/ SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, 2091 /*.name =*/ SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",0,0,0, 2092 /*.info =*/ alc655_iec958_route_info, 2093 /*.get =*/ alc655_iec958_route_get, 2094 /*.put =*/ alc655_iec958_route_put, 0 2095 }, 2096 }; 2097 2098 static int patch_alc655_specific(ac97_t * ac97) 2099 { 2100 int err; 2101 2102 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) 2103 return err; 2104 if (ac97->ext_id & AC97_EI_SPDIF) { 2105 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 2106 return err; 2107 } 2108 return 0; 2016 .build_specific = patch_alc650_specific, 2017 .update_jacks = alc650_update_jacks 2018 }; 2019 2020 int patch_alc650(struct snd_ac97 * ac97) 2021 { 2022 unsigned short val; 2023 2024 ac97->build_ops = &patch_alc650_ops; 2025 2026 /* determine the revision */ 2027 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; 2028 if (val < 3) 2029 ac97->id = 0x414c4720; /* Old version */ 2030 else if (val < 0x10) 2031 ac97->id = 0x414c4721; /* D version */ 2032 else if (val < 0x20) 2033 ac97->id = 0x414c4722; /* E version */ 2034 else if (val < 0x30) 2035 ac97->id = 0x414c4723; /* F version */ 2036 2037 /* revision E or F */ 2038 /* FIXME: what about revision D ? */ 2039 ac97->spec.dev_flags = (ac97->id == 0x414c4722 || 2040 ac97->id == 0x414c4723); 2041 2042 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ 2043 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 2044 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); 2045 2046 /* Enable SPDIF-IN only on Rev.E and above */ 2047 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); 2048 /* SPDIF IN with pin 47 */ 2049 if (ac97->spec.dev_flags) 2050 val |= 0x03; /* enable */ 2051 else 2052 val &= ~0x03; /* disable */ 2053 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); 2054 2055 /* set default: slot 3,4,7,8,6,9 2056 spdif-in monitor off, analog-spdif off, spdif-in off 2057 center on mic off, surround on line-in off 2058 downmix off, duplicate front off 2059 */ 2060 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); 2061 2062 /* set GPIO0 for mic bias */ 2063 /* GPIO0 pin output, no interrupt, high */ 2064 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, 2065 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); 2066 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 2067 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); 2068 2069 /* full DAC volume */ 2070 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2071 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2072 return 0; 2073 } 2074 2075 static void alc655_update_jacks(struct snd_ac97 *ac97) 2076 { 2077 int shared; 2078 2079 /* shared Line-In */ 2080 shared = is_shared_linein(ac97); 2081 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, 2082 shared ? (1 << 9) : 0, 0); 2083 /* update shared mic */ 2084 shared = is_shared_micin(ac97); 2085 /* misc control; vrefout disable */ 2086 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2087 shared ? (1 << 12) : 0); 2088 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, 2089 shared ? (1 << 10) : 0, 0); 2090 } 2091 2092 static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { 2093 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2094 AC97_SURROUND_JACK_MODE_CTL, 2095 AC97_CHANNEL_MODE_CTL, 2096 }; 2097 2098 static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2099 { 2100 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; 2101 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; 2102 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2103 2104 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2105 uinfo->count = 1; 2106 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; 2107 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2108 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2109 strcpy(uinfo->value.enumerated.name, 2110 ac97->spec.dev_flags ? 2111 texts_658[uinfo->value.enumerated.item] : 2112 texts_655[uinfo->value.enumerated.item]); 2113 return 0; 2114 } 2115 2116 static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2117 { 2118 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2119 unsigned short val; 2120 2121 val = ac97->regs[AC97_ALC650_MULTICH]; 2122 val = (val >> 12) & 3; 2123 if (ac97->spec.dev_flags && val == 3) 2124 val = 0; 2125 ucontrol->value.enumerated.item[0] = val; 2126 return 0; 2127 } 2128 2129 static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2130 { 2131 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2132 2133 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, 2134 (unsigned short)ucontrol->value.enumerated.item[0] << 12, 2135 0); 2136 } 2137 2138 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { 2139 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), 2140 /* disable this controls since it doesn't work as expected */ 2141 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ 2142 { 2143 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2144 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 2145 .info = alc655_iec958_route_info, 2146 .get = alc655_iec958_route_get, 2147 .put = alc655_iec958_route_put, 2148 }, 2149 }; 2150 2151 static int patch_alc655_specific(struct snd_ac97 * ac97) 2152 { 2153 int err; 2154 2155 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) 2156 return err; 2157 if (ac97->ext_id & AC97_EI_SPDIF) { 2158 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 2159 return err; 2160 } 2161 return 0; 2109 2162 } 2110 2163 2111 2164 static struct snd_ac97_build_ops patch_alc655_ops = { 2112 NULL,/* .build_specific =*/ patch_alc655_specific, NULL, NULL,0,0, 2113 alc655_update_jacks 2114 }; 2115 2116 int patch_alc655(ac97_t * ac97) 2117 { 2118 unsigned int val; 2119 2120 if (ac97->id == AC97_ID_ALC658) { 2121 ac97->spec.dev_flags = 1; /* ALC658 */ 2122 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { 2123 ac97->id = AC97_ID_ALC658D; 2124 ac97->spec.dev_flags = 2; 2125 } 2126 } 2127 2128 ac97->build_ops = &patch_alc655_ops; 2129 2130 /* assume only page 0 for writing cache */ 2131 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2132 2133 /* adjust default values */ 2134 val = snd_ac97_read(ac97, 0x7a); /* misc control */ 2135 if (ac97->spec.dev_flags) /* ALC658 */ 2136 val &= ~(1 << 1); /* Pin 47 is spdif input pin */ 2137 else { /* ALC655 */ 2138 if (ac97->subsystem_vendor == 0x1462 && 2139 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */ 2140 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2141 else 2142 val |= (1 << 1); /* Pin 47 is spdif input pin */ 2143 } 2144 val &= ~(1 << 12); /* vref enable */ 2145 snd_ac97_write_cache(ac97, 0x7a, val); 2146 2147 /* set default: spdif-in enabled, 2148 spdif-in monitor off, spdif-in PCM off 2149 center on mic off, surround on line-in off 2150 duplicate front off 2151 */ 2152 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2153 /* full DAC volume */ 2154 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2155 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2156 2157 /* update undocumented bit... */ 2158 if (ac97->id == AC97_ID_ALC658D) 2159 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2160 2161 return 0; 2162 } 2163 2164 #define AC97_ALC850_JACK_SELECT 0x76 2165 #define AC97_ALC850_MISC1 0x7a 2166 2167 static void alc850_update_jacks(ac97_t *ac97) 2168 { 2169 int shared; 2170 2171 /* shared Line-In */ 2172 shared = is_shared_linein(ac97); 2173 /* SURR 1kOhm (bit4), Amp (bit5) */ 2174 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), 2175 shared ? (1<<5) : (1<<4)); 2176 /* LINE-IN = 0, SURROUND = 2 */ 2177 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, 2178 shared ? (2<<12) : (0<<12)); 2179 2180 /* update shared mic */ 2181 shared = is_shared_micin(ac97); 2182 2183 /* Vref disable (bit12), 1kOhm (bit13) */ 2184 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), 2185 shared ? (1<<12) : (1<<13)); 2186 /* MIC-IN = 1, CENTER-LFE = 2 */ 2187 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2188 shared ? (2<<4) : (1<<4)); 2189 } 2190 2191 static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = { 2192 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2193 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2194 AC97_SURROUND_JACK_MODE_CTL, 2195 AC97_CHANNEL_MODE_CTL, 2196 }; 2197 2198 static int patch_alc850_specific(ac97_t *ac97) 2199 { 2200 int err; 2201 2202 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) 2203 return err; 2204 if (ac97->ext_id & AC97_EI_SPDIF) { 2205 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 2206 return err; 2207 } 2208 return 0; 2165 .build_specific = patch_alc655_specific, 2166 .update_jacks = alc655_update_jacks 2167 }; 2168 2169 int patch_alc655(struct snd_ac97 * ac97) 2170 { 2171 unsigned int val; 2172 2173 if (ac97->id == AC97_ID_ALC658) { 2174 ac97->spec.dev_flags = 1; /* ALC658 */ 2175 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { 2176 ac97->id = AC97_ID_ALC658D; 2177 ac97->spec.dev_flags = 2; 2178 } 2179 } 2180 2181 ac97->build_ops = &patch_alc655_ops; 2182 2183 /* assume only page 0 for writing cache */ 2184 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2185 2186 /* adjust default values */ 2187 val = snd_ac97_read(ac97, 0x7a); /* misc control */ 2188 if (ac97->spec.dev_flags) /* ALC658 */ 2189 val &= ~(1 << 1); /* Pin 47 is spdif input pin */ 2190 else { /* ALC655 */ 2191 if (ac97->subsystem_vendor == 0x1462 && 2192 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */ 2193 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2194 else 2195 val |= (1 << 1); /* Pin 47 is spdif input pin */ 2196 } 2197 val &= ~(1 << 12); /* vref enable */ 2198 snd_ac97_write_cache(ac97, 0x7a, val); 2199 /* set default: spdif-in enabled, 2200 spdif-in monitor off, spdif-in PCM off 2201 center on mic off, surround on line-in off 2202 duplicate front off 2203 */ 2204 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2205 2206 /* full DAC volume */ 2207 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2208 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2209 2210 /* update undocumented bit... */ 2211 if (ac97->id == AC97_ID_ALC658D) 2212 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2213 2214 return 0; 2215 } 2216 2217 2218 #define AC97_ALC850_JACK_SELECT 0x76 2219 #define AC97_ALC850_MISC1 0x7a 2220 2221 static void alc850_update_jacks(struct snd_ac97 *ac97) 2222 { 2223 int shared; 2224 2225 /* shared Line-In */ 2226 shared = is_shared_linein(ac97); 2227 /* SURR 1kOhm (bit4), Amp (bit5) */ 2228 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), 2229 shared ? (1<<5) : (1<<4)); 2230 /* LINE-IN = 0, SURROUND = 2 */ 2231 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, 2232 shared ? (2<<12) : (0<<12)); 2233 /* update shared mic */ 2234 shared = is_shared_micin(ac97); 2235 /* Vref disable (bit12), 1kOhm (bit13) */ 2236 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), 2237 shared ? (1<<12) : (1<<13)); 2238 /* MIC-IN = 1, CENTER-LFE = 5 */ 2239 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2240 shared ? (5<<4) : (1<<4)); 2241 } 2242 2243 static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 2244 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2245 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2246 AC97_SURROUND_JACK_MODE_CTL, 2247 AC97_CHANNEL_MODE_CTL, 2248 }; 2249 2250 static int patch_alc850_specific(struct snd_ac97 *ac97) 2251 { 2252 int err; 2253 2254 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) 2255 return err; 2256 if (ac97->ext_id & AC97_EI_SPDIF) { 2257 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 2258 return err; 2259 } 2260 return 0; 2209 2261 } 2210 2262 2211 2263 static struct snd_ac97_build_ops patch_alc850_ops = { 2212 NULL,/* .build_specific =*/ patch_alc850_specific, NULL, NULL,0,0, 2213 alc850_update_jacks 2214 }; 2215 2216 int patch_alc850(ac97_t *ac97) 2217 { 2218 ac97->build_ops = &patch_alc850_ops; 2219 2220 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 2221 2222 /* assume only page 0 for writing cache */ 2223 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2224 2225 /* adjust default values */ 2226 /* set default: spdif-in enabled, 2227 spdif-in monitor off, spdif-in PCM off 2228 center on mic off, surround on line-in off 2229 duplicate front off 2230 */ 2231 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2232 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 2233 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on 2234 */ 2235 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| 2236 (1<<7)|(0<<12)|(1<<13)|(0<<14)); 2237 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, 2238 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute 2239 */ 2240 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| 2241 (1<<11)|(0<<12)|(1<<15)); 2242 2243 /* full DAC volume */ 2244 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2245 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2246 return 0; 2247 } 2264 .build_specific = patch_alc850_specific, 2265 .update_jacks = alc850_update_jacks 2266 }; 2267 2268 int patch_alc850(struct snd_ac97 *ac97) 2269 { 2270 ac97->build_ops = &patch_alc850_ops; 2271 2272 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 2273 2274 /* assume only page 0 for writing cache */ 2275 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2276 2277 /* adjust default values */ 2278 /* set default: spdif-in enabled, 2279 spdif-in monitor off, spdif-in PCM off 2280 center on mic off, surround on line-in off 2281 duplicate front off 2282 */ 2283 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2284 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 2285 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on 2286 */ 2287 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| 2288 (1<<7)|(0<<12)|(1<<13)|(0<<14)); 2289 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, 2290 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute 2291 */ 2292 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| 2293 (1<<11)|(0<<12)|(1<<15)); 2294 2295 /* full DAC volume */ 2296 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 2297 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2298 return 0; 2299 } 2300 2248 2301 2249 2302 /* 2250 2303 * C-Media CM97xx codecs 2251 2304 */ 2252 static void cm9738_update_jacks( ac97_t*ac97)2253 { 2254 2255 2256 2257 } 2258 2259 static const s nd_kcontrol_new_tsnd_ac97_cm9738_controls[] = {2260 2261 2262 2263 }; 2264 2265 static int patch_cm9738_specific( ac97_t* ac97)2266 { 2267 2305 static void cm9738_update_jacks(struct snd_ac97 *ac97) 2306 { 2307 /* shared Line-In */ 2308 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, 2309 is_shared_linein(ac97) ? (1 << 10) : 0); 2310 } 2311 2312 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { 2313 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), 2314 AC97_SURROUND_JACK_MODE_CTL, 2315 AC97_CHANNEL_MODE_4CH_CTL, 2316 }; 2317 2318 static int patch_cm9738_specific(struct snd_ac97 * ac97) 2319 { 2320 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); 2268 2321 } 2269 2322 2270 2323 static struct snd_ac97_build_ops patch_cm9738_ops = { 2271 NULL, patch_cm9738_specific, NULL, NULL,0,0,2272 2273 }; 2274 2275 int patch_cm9738( ac97_t* ac97)2276 { 2277 2278 2279 2280 2281 2282 2283 2284 } 2285 2286 static int snd_ac97_cmedia_spdif_playback_source_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)2287 { 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 } 2298 2299 static int snd_ac97_cmedia_spdif_playback_source_get(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)2300 { 2301 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);2302 2303 2304 2305 2306 2307 } 2308 2309 static int snd_ac97_cmedia_spdif_playback_source_put(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)2310 { 2311 ac97_t*ac97 = snd_kcontrol_chip(kcontrol);2312 2313 2314 0x01 << 1, 2315 2316 } 2317 2318 static const s nd_kcontrol_new_tsnd_ac97_cm9739_controls_spdif[] = {2319 2320 2321 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,2322 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 0,0,0,2323 2324 2325 snd_ac97_cmedia_spdif_playback_source_put, 0,2326 2327 2328 2329 2330 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 2331 2332 2333 2334 }; 2335 2336 static void cm9739_update_jacks( ac97_t*ac97)2337 { 2338 2339 2340 2341 2342 2343 2344 } 2345 2346 static const s nd_kcontrol_new_tsnd_ac97_cm9739_controls[] = {2347 2348 2349 }; 2350 2351 static int patch_cm9739_specific( ac97_t* ac97)2352 { 2353 2354 } 2355 2356 static int patch_cm9739_post_spdif( ac97_t* ac97)2357 { 2358 2324 .build_specific = patch_cm9738_specific, 2325 .update_jacks = cm9738_update_jacks 2326 }; 2327 2328 int patch_cm9738(struct snd_ac97 * ac97) 2329 { 2330 ac97->build_ops = &patch_cm9738_ops; 2331 /* FIXME: can anyone confirm below? */ 2332 /* CM9738 has no PCM volume although the register reacts */ 2333 ac97->flags |= AC97_HAS_NO_PCM_VOL; 2334 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 2335 2336 return 0; 2337 } 2338 2339 static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2340 { 2341 static char *texts[] = { "Analog", "Digital" }; 2342 2343 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2344 uinfo->count = 1; 2345 uinfo->value.enumerated.items = 2; 2346 if (uinfo->value.enumerated.item > 1) 2347 uinfo->value.enumerated.item = 1; 2348 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2349 return 0; 2350 } 2351 2352 static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2353 { 2354 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2355 unsigned short val; 2356 2357 val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; 2358 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; 2359 return 0; 2360 } 2361 2362 static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2363 { 2364 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2365 2366 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, 2367 0x01 << 1, 2368 (ucontrol->value.enumerated.item[0] & 0x01) << 1); 2369 } 2370 2371 static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { 2372 /* BIT 0: SPDI_EN - always true */ 2373 { /* BIT 1: SPDIFS */ 2374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2375 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 2376 .info = snd_ac97_cmedia_spdif_playback_source_info, 2377 .get = snd_ac97_cmedia_spdif_playback_source_get, 2378 .put = snd_ac97_cmedia_spdif_playback_source_put, 2379 }, 2380 /* BIT 2: IG_SPIV */ 2381 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), 2382 /* BIT 3: SPI2F */ 2383 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 2384 /* BIT 4: SPI2SDI */ 2385 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), 2386 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ 2387 }; 2388 2389 static void cm9739_update_jacks(struct snd_ac97 *ac97) 2390 { 2391 /* shared Line-In */ 2392 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, 2393 is_shared_linein(ac97) ? (1 << 10) : 0); 2394 /* shared Mic */ 2395 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, 2396 is_shared_micin(ac97) ? 0x1000 : 0x2000); 2397 } 2398 2399 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { 2400 AC97_SURROUND_JACK_MODE_CTL, 2401 AC97_CHANNEL_MODE_CTL, 2402 }; 2403 2404 static int patch_cm9739_specific(struct snd_ac97 * ac97) 2405 { 2406 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); 2407 } 2408 2409 static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) 2410 { 2411 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); 2359 2412 } 2360 2413 2361 2414 static struct snd_ac97_build_ops patch_cm9739_ops = { 2362 NULL, patch_cm9739_specific, NULL, 2363 patch_cm9739_post_spdif,0,0, 2364 cm9739_update_jacks 2365 }; 2366 2367 int patch_cm9739(ac97_t * ac97) 2368 { 2369 unsigned short val; 2370 2371 ac97->build_ops = &patch_cm9739_ops; 2372 2373 /* CM9739/A has no Master and PCM volume although the register reacts */ 2374 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; 2375 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); 2376 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 2377 2378 /* check spdif */ 2379 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2380 if (val & AC97_EA_SPCV) { 2381 /* enable spdif in */ 2382 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 2383 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); 2384 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2385 } else { 2386 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ 2387 ac97->rates[AC97_RATES_SPDIF] = 0; 2388 } 2389 2390 /* set-up multi channel */ 2391 /* bit 14: 0 = SPDIF, 1 = EAPD */ 2392 /* bit 13: enable internal vref output for mic */ 2393 /* bit 12: disable center/lfe (swithable) */ 2394 /* bit 10: disable surround/line (switchable) */ 2395 /* bit 9: mix 2 surround off */ 2396 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ 2397 /* bit 3: undocumented; surround? */ 2398 /* bit 0: dB */ 2399 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); 2400 val |= (1 << 3); 2401 val |= (1 << 13); 2402 if (! (ac97->ext_id & AC97_EI_SPDIF)) 2403 val |= (1 << 14); 2404 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); 2405 /* FIXME: set up GPIO */ 2406 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ 2407 if (ac97->pci && 2408 ac97->subsystem_vendor == 0x1043 && 2409 ac97->subsystem_device == 0x1843) { 2410 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 2411 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); 2412 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, 2413 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); 2414 } 2415 snd_ac97_write_cache(ac97, 0x70, 0x0100); 2416 snd_ac97_write_cache(ac97, 0x72, 0x0020); 2417 2418 return 0; 2419 } 2420 2421 #define AC97_CM9761_MULTI_CHAN 0x64 2422 #define AC97_CM9761_FUNC 0x66 2423 #define AC97_CM9761_SPDIF_CTRL 0x6c 2424 2425 static void cm9761_update_jacks(ac97_t *ac97) 2426 { 2427 /* FIXME: check the bits for each model 2428 * model 83 is confirmed to work 2429 */ 2430 static unsigned short surr_on[3][2] = { 2431 { 0x0008, 0x0000 }, /* 9761-78 & 82 */ 2432 { 0x0000, 0x0008 }, /* 9761-82 rev.B */ 2433 { 0x0000, 0x0008 }, /* 9761-83 */ 2434 }; 2435 static unsigned short clfe_on[3][2] = { 2436 { 0x0000, 0x1000 }, /* 9761-78 & 82 */ 2437 { 0x1000, 0x0000 }, /* 9761-82 rev.B */ 2438 { 0x0000, 0x1000 }, /* 9761-83 */ 2439 }; 2440 static unsigned short surr_shared[3][2] = { 2441 { 0x0000, 0x0400 }, /* 9761-78 & 82 */ 2442 { 0x0000, 0x0400 }, /* 9761-82 rev.B */ 2443 { 0x0000, 0x0400 }, /* 9761-83 */ 2444 }; 2445 static unsigned short clfe_shared[3][2] = { 2446 { 0x2000, 0x0880 }, /* 9761-78 & 82 */ 2447 { 0x0000, 0x2880 }, /* 9761-82 rev.B */ 2448 { 0x2000, 0x0800 }, /* 9761-83 */ 2449 }; 2450 unsigned short val = 0; 2451 2452 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; 2453 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; 2454 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)]; 2455 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)]; 2456 2457 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); 2458 } 2459 2460 static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = { 2461 AC97_SURROUND_JACK_MODE_CTL, 2462 AC97_CHANNEL_MODE_CTL, 2463 }; 2464 2465 static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 2466 { 2467 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 2468 2469 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2470 uinfo->count = 1; 2471 uinfo->value.enumerated.items = 3; 2472 if (uinfo->value.enumerated.item > 2) 2473 uinfo->value.enumerated.item = 2; 2474 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2475 return 0; 2476 } 2477 2478 static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 2479 { 2480 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2481 2482 if (ac97->regs[AC97_CM9761_FUNC] & 0x1) 2483 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ 2484 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) 2485 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ 2486 else 2487 ucontrol->value.enumerated.item[0] = 0; /* AC-link */ 2488 return 0; 2489 } 2490 2491 static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 2492 { 2493 ac97_t *ac97 = snd_kcontrol_chip(kcontrol); 2494 2495 if (ucontrol->value.enumerated.item[0] == 2) 2496 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); 2497 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); 2498 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, 2499 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 2415 .build_specific = patch_cm9739_specific, 2416 .build_post_spdif = patch_cm9739_post_spdif, 2417 .update_jacks = cm9739_update_jacks 2418 }; 2419 2420 int patch_cm9739(struct snd_ac97 * ac97) 2421 { 2422 unsigned short val; 2423 2424 ac97->build_ops = &patch_cm9739_ops; 2425 2426 /* CM9739/A has no Master and PCM volume although the register reacts */ 2427 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; 2428 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); 2429 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 2430 2431 /* check spdif */ 2432 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2433 if (val & AC97_EA_SPCV) { 2434 /* enable spdif in */ 2435 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 2436 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); 2437 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2438 } else { 2439 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ 2440 ac97->rates[AC97_RATES_SPDIF] = 0; 2441 } 2442 2443 /* set-up multi channel */ 2444 /* bit 14: 0 = SPDIF, 1 = EAPD */ 2445 /* bit 13: enable internal vref output for mic */ 2446 /* bit 12: disable center/lfe (swithable) */ 2447 /* bit 10: disable surround/line (switchable) */ 2448 /* bit 9: mix 2 surround off */ 2449 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ 2450 /* bit 3: undocumented; surround? */ 2451 /* bit 0: dB */ 2452 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); 2453 val |= (1 << 3); 2454 val |= (1 << 13); 2455 if (! (ac97->ext_id & AC97_EI_SPDIF)) 2456 val |= (1 << 14); 2457 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); 2458 2459 /* FIXME: set up GPIO */ 2460 snd_ac97_write_cache(ac97, 0x70, 0x0100); 2461 snd_ac97_write_cache(ac97, 0x72, 0x0020); 2462 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ 2463 if (ac97->pci && 2464 ac97->subsystem_vendor == 0x1043 && 2465 ac97->subsystem_device == 0x1843) { 2466 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 2467 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); 2468 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, 2469 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); 2470 } 2471 2472 return 0; 2473 } 2474 2475 #define AC97_CM9761_MULTI_CHAN 0x64 2476 #define AC97_CM9761_FUNC 0x66 2477 #define AC97_CM9761_SPDIF_CTRL 0x6c 2478 2479 static void cm9761_update_jacks(struct snd_ac97 *ac97) 2480 { 2481 /* FIXME: check the bits for each model 2482 * model 83 is confirmed to work 2483 */ 2484 static unsigned short surr_on[3][2] = { 2485 { 0x0008, 0x0000 }, /* 9761-78 & 82 */ 2486 { 0x0000, 0x0008 }, /* 9761-82 rev.B */ 2487 { 0x0000, 0x0008 }, /* 9761-83 */ 2488 }; 2489 static unsigned short clfe_on[3][2] = { 2490 { 0x0000, 0x1000 }, /* 9761-78 & 82 */ 2491 { 0x1000, 0x0000 }, /* 9761-82 rev.B */ 2492 { 0x0000, 0x1000 }, /* 9761-83 */ 2493 }; 2494 static unsigned short surr_shared[3][2] = { 2495 { 0x0000, 0x0400 }, /* 9761-78 & 82 */ 2496 { 0x0000, 0x0400 }, /* 9761-82 rev.B */ 2497 { 0x0000, 0x0400 }, /* 9761-83 */ 2498 }; 2499 static unsigned short clfe_shared[3][2] = { 2500 { 0x2000, 0x0880 }, /* 9761-78 & 82 */ 2501 { 0x0000, 0x2880 }, /* 9761-82 rev.B */ 2502 { 0x2000, 0x0800 }, /* 9761-83 */ 2503 }; 2504 unsigned short val = 0; 2505 2506 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; 2507 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; 2508 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)]; 2509 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)]; 2510 2511 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); 2512 } 2513 2514 static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { 2515 AC97_SURROUND_JACK_MODE_CTL, 2516 AC97_CHANNEL_MODE_CTL, 2517 }; 2518 2519 static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2520 { 2521 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 2522 2523 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2524 uinfo->count = 1; 2525 uinfo->value.enumerated.items = 3; 2526 if (uinfo->value.enumerated.item > 2) 2527 uinfo->value.enumerated.item = 2; 2528 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2529 return 0; 2530 } 2531 2532 static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2533 { 2534 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2535 2536 if (ac97->regs[AC97_CM9761_FUNC] & 0x1) 2537 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ 2538 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) 2539 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ 2540 else 2541 ucontrol->value.enumerated.item[0] = 0; /* AC-link */ 2542 return 0; 2543 } 2544 2545 static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2546 { 2547 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2548 2549 if (ucontrol->value.enumerated.item[0] == 2) 2550 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); 2551 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); 2552 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, 2553 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 2500 2554 } 2501 2555 2502 2556 static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; 2503 2557 static const struct ac97_enum cm9761_dac_clock_enum = 2504 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);2505 2506 static const s nd_kcontrol_new_tsnd_ac97_cm9761_controls_spdif[] = {2507 2508 SNDRV_CTL_ELEM_IFACE_MIXER,0,0,2509 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",0,0,0,2510 2511 2512 cm9761_spdif_out_source_put,0 2513 2514 2515 2516 2517 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 2518 2519 2520 2521 2522 }; 2523 2524 static int patch_cm9761_post_spdif( ac97_t* ac97)2525 { 2526 2527 } 2528 2529 static int patch_cm9761_specific( ac97_t* ac97)2530 { 2531 2558 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); 2559 2560 static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { 2561 { /* BIT 1: SPDIFS */ 2562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2563 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 2564 .info = cm9761_spdif_out_source_info, 2565 .get = cm9761_spdif_out_source_get, 2566 .put = cm9761_spdif_out_source_put, 2567 }, 2568 /* BIT 2: IG_SPIV */ 2569 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), 2570 /* BIT 3: SPI2F */ 2571 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 2572 /* BIT 4: SPI2SDI */ 2573 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), 2574 /* BIT 9-10: DAC_CTL */ 2575 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), 2576 }; 2577 2578 static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) 2579 { 2580 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); 2581 } 2582 2583 static int patch_cm9761_specific(struct snd_ac97 * ac97) 2584 { 2585 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); 2532 2586 } 2533 2587 2534 2588 static struct snd_ac97_build_ops patch_cm9761_ops = { 2535 NULL, 2536 /*.build_specific = */patch_cm9761_specific, NULL, 2537 /*.build_post_spdif = */patch_cm9761_post_spdif, 2538 0,0, 2539 cm9761_update_jacks 2540 }; 2541 2542 int patch_cm9761(ac97_t *ac97) 2543 { 2544 unsigned short val; 2545 2546 /* CM9761 has no PCM volume although the register reacts */ 2547 /* Master volume seems to have _some_ influence on the analog 2548 * input sounds 2549 */ 2550 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; 2551 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 2552 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 2553 2554 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ 2555 if (ac97->id == AC97_ID_CM9761_82) { 2556 unsigned short tmp; 2557 /* check page 1, reg 0x60 */ 2558 val = snd_ac97_read(ac97, AC97_INT_PAGING); 2559 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); 2560 tmp = snd_ac97_read(ac97, 0x60); 2561 ac97->spec.dev_flags = tmp & 1; /* revision B? */ 2562 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 2563 } else if (ac97->id == AC97_ID_CM9761_83) 2564 ac97->spec.dev_flags = 2; 2565 2566 ac97->build_ops = &patch_cm9761_ops; 2567 2568 /* enable spdif */ 2569 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ 2570 ac97->ext_id |= AC97_EI_SPDIF; 2571 /* to be sure: we overwrite the ext status bits */ 2572 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); 2573 /* Don't set 0x0200 here. This results in the silent analog output */ 2574 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ 2575 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2576 2577 /* set-up multi channel */ 2589 .build_specific = patch_cm9761_specific, 2590 .build_post_spdif = patch_cm9761_post_spdif, 2591 .update_jacks = cm9761_update_jacks 2592 }; 2593 2594 int patch_cm9761(struct snd_ac97 *ac97) 2595 { 2596 unsigned short val; 2597 2598 /* CM9761 has no PCM volume although the register reacts */ 2599 /* Master volume seems to have _some_ influence on the analog 2600 * input sounds 2601 */ 2602 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; 2603 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 2604 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 2605 2606 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ 2607 if (ac97->id == AC97_ID_CM9761_82) { 2608 unsigned short tmp; 2609 /* check page 1, reg 0x60 */ 2610 val = snd_ac97_read(ac97, AC97_INT_PAGING); 2611 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); 2612 tmp = snd_ac97_read(ac97, 0x60); 2613 ac97->spec.dev_flags = tmp & 1; /* revision B? */ 2614 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 2615 } else if (ac97->id == AC97_ID_CM9761_83) 2616 ac97->spec.dev_flags = 2; 2617 2618 ac97->build_ops = &patch_cm9761_ops; 2619 2620 /* enable spdif */ 2621 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ 2622 ac97->ext_id |= AC97_EI_SPDIF; 2623 /* to be sure: we overwrite the ext status bits */ 2624 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); 2625 /* Don't set 0x0200 here. This results in the silent analog output */ 2626 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ 2627 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2628 2629 /* set-up multi channel */ 2578 2630 /* bit 15: pc master beep off 2579 2631 * bit 14: pin47 = EAPD/SPDIF … … 2594 2646 2595 2647 #if 0 2596 2597 2598 2599 2648 if (ac97->spec.dev_flags) 2649 val = 0x0214; 2650 else 2651 val = 0x321c; 2600 2652 #endif 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 } 2611 2612 #define AC97_CM9780_SIDE 2613 #define AC97_CM9780_JACK 2614 #define AC97_CM9780_MIXER 2615 #define AC97_CM9780_MULTI_CHAN 2616 #define AC97_CM9780_SPDIF 2653 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); 2654 val |= (1 << 4); /* front on */ 2655 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); 2656 2657 /* FIXME: set up GPIO */ 2658 snd_ac97_write_cache(ac97, 0x70, 0x0100); 2659 snd_ac97_write_cache(ac97, 0x72, 0x0020); 2660 2661 return 0; 2662 } 2663 2664 #define AC97_CM9780_SIDE 0x60 2665 #define AC97_CM9780_JACK 0x62 2666 #define AC97_CM9780_MIXER 0x64 2667 #define AC97_CM9780_MULTI_CHAN 0x66 2668 #define AC97_CM9780_SPDIF 0x6c 2617 2669 2618 2670 static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; 2619 2671 static const struct ac97_enum cm9780_ch_select_enum = 2620 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);2621 static const s nd_kcontrol_new_tcm9780_controls[] = {2622 2623 2624 2625 }; 2626 2627 static int patch_cm9780_specific( ac97_t*ac97)2628 { 2629 2672 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); 2673 static const struct snd_kcontrol_new cm9780_controls[] = { 2674 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), 2675 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), 2676 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), 2677 }; 2678 2679 static int patch_cm9780_specific(struct snd_ac97 *ac97) 2680 { 2681 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); 2630 2682 } 2631 2683 2632 2684 static struct snd_ac97_build_ops patch_cm9780_ops = { 2633 0,patch_cm9780_specific,2634 0, patch_cm9761_post_spdif,/* identical with CM9761 */2635 0,0 2636 }; 2637 2638 int patch_cm9780(ac97_t *ac97) 2639 { 2640 unsigned short val; 2641 2642 ac97->build_ops = &patch_cm9780_ops; 2643 2644 /* enable spdif */ 2645 if (ac97->ext_id & AC97_EI_SPDIF) { 2646 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2647 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); 2648 val |= 0x1; /* SPDI_EN */ 2649 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); 2650 } 2651 2652 return 0; 2653 } 2685 .build_specific = patch_cm9780_specific, 2686 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ 2687 }; 2688 2689 int patch_cm9780(struct snd_ac97 *ac97) 2690 { 2691 unsigned short val; 2692 2693 ac97->build_ops = &patch_cm9780_ops; 2694 2695 /* enable spdif */ 2696 if (ac97->ext_id & AC97_EI_SPDIF) { 2697 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 2698 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); 2699 val |= 0x1; /* SPDI_EN */ 2700 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); 2701 } 2702 2703 return 0; 2704 } 2705 2654 2706 /* 2655 2707 * VIA VT1616 codec 2656 2708 */ 2657 static const s nd_kcontrol_new_tsnd_ac97_controls_vt1616[] = {2658 2659 2660 2661 2662 }; 2663 2664 static int patch_vt1616_specific( ac97_t* ac97)2665 { 2666 2667 2668 2669 2670 2671 2672 2673 2709 static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 2710 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), 2711 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), 2712 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), 2713 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), 2714 }; 2715 2716 static int patch_vt1616_specific(struct snd_ac97 * ac97) 2717 { 2718 int err; 2719 2720 if (snd_ac97_try_bit(ac97, 0x5a, 9)) 2721 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) 2722 return err; 2723 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) 2724 return err; 2725 return 0; 2674 2726 } 2675 2727 2676 2728 static struct snd_ac97_build_ops patch_vt1616_ops = { 2677 NULL, patch_vt1616_specific, NULL, NULL,0,0 2678 }; 2679 2680 int patch_vt1616( ac97_t* ac97)2681 { 2682 2683 2729 .build_specific = patch_vt1616_specific 2730 }; 2731 2732 int patch_vt1616(struct snd_ac97 * ac97) 2733 { 2734 ac97->build_ops = &patch_vt1616_ops; 2735 return 0; 2684 2736 } 2685 2737 … … 2687 2739 * VT1617A codec 2688 2740 */ 2689 int patch_vt1617a( ac97_t* ac97)2690 { 2691 ac97->ext_id |= AC97_EI_SPDIF;/* force the detection of spdif */2692 2693 2741 int patch_vt1617a(struct snd_ac97 * ac97) 2742 { 2743 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 2744 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; 2745 return 0; 2694 2746 } 2695 2747 2696 2748 /* 2697 2749 */ 2698 static void it2646_update_jacks( ac97_t*ac97)2699 { 2700 2701 2702 2703 2704 2705 2706 } 2707 2708 static const s nd_kcontrol_new_tsnd_ac97_controls_it2646[] = {2709 2710 2711 }; 2712 2713 static const s nd_kcontrol_new_tsnd_ac97_spdif_controls_it2646[] = {2714 2715 2716 2717 }; 2718 2719 static int patch_it2646_specific( ac97_t* ac97)2720 { 2721 2722 2723 2724 2725 2726 2750 static void it2646_update_jacks(struct snd_ac97 *ac97) 2751 { 2752 /* shared Line-In */ 2753 snd_ac97_update_bits(ac97, 0x76, 1 << 9, 2754 is_shared_linein(ac97) ? (1<<9) : 0); 2755 /* shared Mic */ 2756 snd_ac97_update_bits(ac97, 0x76, 1 << 10, 2757 is_shared_micin(ac97) ? (1<<10) : 0); 2758 } 2759 2760 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { 2761 AC97_SURROUND_JACK_MODE_CTL, 2762 AC97_CHANNEL_MODE_CTL, 2763 }; 2764 2765 static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { 2766 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), 2767 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), 2768 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), 2769 }; 2770 2771 static int patch_it2646_specific(struct snd_ac97 * ac97) 2772 { 2773 int err; 2774 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) 2775 return err; 2776 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) 2777 return err; 2778 return 0; 2727 2779 } 2728 2780 2729 2781 static struct snd_ac97_build_ops patch_it2646_ops = { 2730 NULL, patch_it2646_specific, NULL,NULL,0,0,2731 2732 }; 2733 2734 int patch_it2646( ac97_t* ac97)2735 { 2736 2737 2738 2739 2740 2782 .build_specific = patch_it2646_specific, 2783 .update_jacks = it2646_update_jacks 2784 }; 2785 2786 int patch_it2646(struct snd_ac97 * ac97) 2787 { 2788 ac97->build_ops = &patch_it2646_ops; 2789 /* full DAC volume */ 2790 snd_ac97_write_cache(ac97, 0x5E, 0x0808); 2791 snd_ac97_write_cache(ac97, 0x7A, 0x0808); 2792 return 0; 2741 2793 } 2742 2794 … … 2744 2796 * Si3036 codec 2745 2797 */ 2798 2746 2799 #define AC97_SI3036_CHIP_ID 0x5a 2747 2800 #define AC97_SI3036_LINE_CFG 0x5c 2748 2801 2749 static const s nd_kcontrol_new_tsnd_ac97_controls_si3036[] = {2750 2751 }; 2752 2753 static int patch_si3036_specific( ac97_t* ac97)2754 { 2755 2756 2757 2758 2759 2802 static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { 2803 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) 2804 }; 2805 2806 static int patch_si3036_specific(struct snd_ac97 * ac97) 2807 { 2808 int idx, err; 2809 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) 2810 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) 2811 return err; 2812 return 0; 2760 2813 } 2761 2814 2762 2815 static struct snd_ac97_build_ops patch_si3036_ops = { 2763 .build_specific= patch_si3036_specific,2764 }; 2765 2766 int mpatch_si3036( ac97_t* ac97)2767 { 2768 2769 2770 2771 2772 } 2816 .build_specific = patch_si3036_specific, 2817 }; 2818 2819 int mpatch_si3036(struct snd_ac97 * ac97) 2820 { 2821 ac97->build_ops = &patch_si3036_ops; 2822 snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); 2823 snd_ac97_write_cache(ac97, 0x68, 0); 2824 return 0; 2825 } -
GPL/trunk/alsa-kernel/pci/ac97/ac97_patch.h
r32 r72 23 23 */ 24 24 25 int patch_yamaha_ymf753(ac97_t * ac97); 26 int patch_wolfson00(ac97_t * ac97); 27 int patch_wolfson03(ac97_t * ac97); 28 int patch_wolfson04(ac97_t * ac97); 29 int patch_wolfson05(ac97_t * ac97); 30 int patch_wolfson11(ac97_t * ac97); 31 int patch_wolfson13(ac97_t * ac97); 32 int patch_tritech_tr28028(ac97_t * ac97); 33 int patch_sigmatel_stac9700(ac97_t * ac97); 34 int patch_sigmatel_stac9708(ac97_t * ac97); 35 int patch_sigmatel_stac9721(ac97_t * ac97); 36 int patch_sigmatel_stac9744(ac97_t * ac97); 37 int patch_sigmatel_stac9756(ac97_t * ac97); 38 int patch_sigmatel_stac9758(ac97_t * ac97); 39 int patch_cirrus_cs4299(ac97_t * ac97); 40 int patch_cirrus_spdif(ac97_t * ac97); 41 int patch_conexant(ac97_t * ac97); 42 int patch_ad1819(ac97_t * ac97); 43 int patch_ad1881(ac97_t * ac97); 44 int patch_ad1885(ac97_t * ac97); 45 int patch_ad1886(ac97_t * ac97); 46 int patch_ad1888(ac97_t * ac97); 47 int patch_ad1980(ac97_t * ac97); 48 int patch_ad1981a(ac97_t * ac97); 49 int patch_ad1981b(ac97_t * ac97); 50 int patch_ad1985(ac97_t * ac97); 51 int patch_alc650(ac97_t * ac97); 52 int patch_alc655(ac97_t * ac97); 53 int patch_alc850(ac97_t * ac97); 54 int patch_cm9738(ac97_t * ac97); 55 int patch_cm9739(ac97_t * ac97); 56 int patch_cm9761(ac97_t * ac97); 57 int patch_cm9780(ac97_t * ac97); 58 int patch_vt1616(ac97_t * ac97); 59 int patch_vt1617a(ac97_t * ac97); 60 int patch_it2646(ac97_t * ac97); 25 int patch_yamaha_ymf753(struct snd_ac97 * ac97); 26 int patch_wolfson00(struct snd_ac97 * ac97); 27 int patch_wolfson03(struct snd_ac97 * ac97); 28 int patch_wolfson04(struct snd_ac97 * ac97); 29 int patch_wolfson05(struct snd_ac97 * ac97); 30 int patch_wolfson11(struct snd_ac97 * ac97); 31 int patch_wolfson13(struct snd_ac97 * ac97); 32 int patch_tritech_tr28028(struct snd_ac97 * ac97); 33 int patch_sigmatel_stac9700(struct snd_ac97 * ac97); 34 int patch_sigmatel_stac9708(struct snd_ac97 * ac97); 35 int patch_sigmatel_stac9721(struct snd_ac97 * ac97); 36 int patch_sigmatel_stac9744(struct snd_ac97 * ac97); 37 int patch_sigmatel_stac9756(struct snd_ac97 * ac97); 38 int patch_sigmatel_stac9758(struct snd_ac97 * ac97); 39 int patch_cirrus_cs4299(struct snd_ac97 * ac97); 40 int patch_cirrus_spdif(struct snd_ac97 * ac97); 41 int patch_conexant(struct snd_ac97 * ac97); 42 int patch_ad1819(struct snd_ac97 * ac97); 43 int patch_ad1881(struct snd_ac97 * ac97); 44 int patch_ad1885(struct snd_ac97 * ac97); 45 int patch_ad1886(struct snd_ac97 * ac97); 46 int patch_ad1888(struct snd_ac97 * ac97); 47 int patch_ad1980(struct snd_ac97 * ac97); 48 int patch_ad1981a(struct snd_ac97 * ac97); 49 int patch_ad1981b(struct snd_ac97 * ac97); 50 int patch_ad1985(struct snd_ac97 * ac97); 51 int patch_alc650(struct snd_ac97 * ac97); 52 int patch_alc655(struct snd_ac97 * ac97); 53 int patch_alc850(struct snd_ac97 * ac97); 54 int patch_cm9738(struct snd_ac97 * ac97); 55 int patch_cm9739(struct snd_ac97 * ac97); 56 int patch_cm9761(struct snd_ac97 * ac97); 57 int patch_cm9780(struct snd_ac97 * ac97); 58 int patch_vt1616(struct snd_ac97 * ac97); 59 int patch_vt1617a(struct snd_ac97 * ac97); 60 int patch_it2646(struct snd_ac97 * ac97); 61 int mpatch_si3036(struct snd_ac97 * ac97); -
GPL/trunk/alsa-kernel/pci/ac97/ac97_pcm.c
r32 r72 42 42 43 43 static unsigned char rate_reg_tables[2][4][9] = { 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0xff,/* slot 9 */91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 44 { 45 /* standard rates */ 46 { 47 /* 3&4 front, 7&8 rear, 6&9 center/lfe */ 48 AC97_PCM_FRONT_DAC_RATE, /* slot 3 */ 49 AC97_PCM_FRONT_DAC_RATE, /* slot 4 */ 50 0xff, /* slot 5 */ 51 AC97_PCM_LFE_DAC_RATE, /* slot 6 */ 52 AC97_PCM_SURR_DAC_RATE, /* slot 7 */ 53 AC97_PCM_SURR_DAC_RATE, /* slot 8 */ 54 AC97_PCM_LFE_DAC_RATE, /* slot 9 */ 55 0xff, /* slot 10 */ 56 0xff, /* slot 11 */ 57 }, 58 { 59 /* 7&8 front, 6&9 rear, 10&11 center/lfe */ 60 0xff, /* slot 3 */ 61 0xff, /* slot 4 */ 62 0xff, /* slot 5 */ 63 AC97_PCM_SURR_DAC_RATE, /* slot 6 */ 64 AC97_PCM_FRONT_DAC_RATE, /* slot 7 */ 65 AC97_PCM_FRONT_DAC_RATE, /* slot 8 */ 66 AC97_PCM_SURR_DAC_RATE, /* slot 9 */ 67 AC97_PCM_LFE_DAC_RATE, /* slot 10 */ 68 AC97_PCM_LFE_DAC_RATE, /* slot 11 */ 69 }, 70 { 71 /* 6&9 front, 10&11 rear, 3&4 center/lfe */ 72 AC97_PCM_LFE_DAC_RATE, /* slot 3 */ 73 AC97_PCM_LFE_DAC_RATE, /* slot 4 */ 74 0xff, /* slot 5 */ 75 AC97_PCM_FRONT_DAC_RATE, /* slot 6 */ 76 0xff, /* slot 7 */ 77 0xff, /* slot 8 */ 78 AC97_PCM_FRONT_DAC_RATE, /* slot 9 */ 79 AC97_PCM_SURR_DAC_RATE, /* slot 10 */ 80 AC97_PCM_SURR_DAC_RATE, /* slot 11 */ 81 }, 82 { 83 /* 10&11 front, 3&4 rear, 7&8 center/lfe */ 84 AC97_PCM_SURR_DAC_RATE, /* slot 3 */ 85 AC97_PCM_SURR_DAC_RATE, /* slot 4 */ 86 0xff, /* slot 5 */ 87 0xff, /* slot 6 */ 88 AC97_PCM_LFE_DAC_RATE, /* slot 7 */ 89 AC97_PCM_LFE_DAC_RATE, /* slot 8 */ 90 0xff, /* slot 9 */ 91 AC97_PCM_FRONT_DAC_RATE, /* slot 10 */ 92 AC97_PCM_FRONT_DAC_RATE, /* slot 11 */ 93 }, 94 }, 95 { 96 /* double rates */ 97 { 98 /* 3&4 front, 7&8 front (t+1) */ 99 AC97_PCM_FRONT_DAC_RATE, /* slot 3 */ 100 AC97_PCM_FRONT_DAC_RATE, /* slot 4 */ 101 0xff, /* slot 5 */ 102 0xff, /* slot 6 */ 103 AC97_PCM_FRONT_DAC_RATE, /* slot 7 */ 104 AC97_PCM_FRONT_DAC_RATE, /* slot 8 */ 105 0xff, /* slot 9 */ 106 0xff, /* slot 10 */ 107 0xff, /* slot 11 */ 108 }, 109 { 110 /* not specified in the specification */ 111 0xff, /* slot 3 */ 112 0xff, /* slot 4 */ 113 0xff, /* slot 5 */ 114 0xff, /* slot 6 */ 115 0xff, /* slot 7 */ 116 0xff, /* slot 8 */ 117 0xff, /* slot 9 */ 118 0xff, /* slot 10 */ 119 0xff, /* slot 11 */ 120 }, 121 { 122 0xff, /* slot 3 */ 123 0xff, /* slot 4 */ 124 0xff, /* slot 5 */ 125 0xff, /* slot 6 */ 126 0xff, /* slot 7 */ 127 0xff, /* slot 8 */ 128 0xff, /* slot 9 */ 129 0xff, /* slot 10 */ 130 0xff, /* slot 11 */ 131 }, 132 { 133 0xff, /* slot 3 */ 134 0xff, /* slot 4 */ 135 0xff, /* slot 5 */ 136 0xff, /* slot 6 */ 137 0xff, /* slot 7 */ 138 0xff, /* slot 8 */ 139 0xff, /* slot 9 */ 140 0xff, /* slot 10 */ 141 0xff, /* slot 11 */ 142 } 143 }}; 144 144 145 145 /* FIXME: more various mappings for ADC? */ 146 146 static unsigned char rate_cregs[9] = { 147 148 149 150 151 152 153 154 155 147 AC97_PCM_LR_ADC_RATE, /* 3 */ 148 AC97_PCM_LR_ADC_RATE, /* 4 */ 149 0xff, /* 5 */ 150 AC97_PCM_MIC_ADC_RATE, /* 6 */ 151 0xff, /* 7 */ 152 0xff, /* 8 */ 153 0xff, /* 9 */ 154 0xff, /* 10 */ 155 0xff, /* 11 */ 156 156 }; 157 157 158 158 static unsigned char get_slot_reg(struct ac97_pcm *pcm, unsigned short cidx, 159 160 { 161 162 163 164 165 166 167 168 169 170 171 } 172 173 static int set_spdif_rate( ac97_t*ac97, unsigned short rate)174 { 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 159 unsigned short slot, int dbl) 160 { 161 if (slot < 3) 162 return 0xff; 163 if (slot > 11) 164 return 0xff; 165 if (pcm->spdif) 166 return AC97_SPDIF; /* pseudo register */ 167 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK) 168 return rate_reg_tables[dbl][pcm->r[dbl].rate_table[cidx]][slot - 3]; 169 else 170 return rate_cregs[slot - 3]; 171 } 172 173 static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate) 174 { 175 unsigned short old, bits, reg, mask; 176 unsigned int sbits; 177 178 if (! (ac97->ext_id & AC97_EI_SPDIF)) 179 return -ENODEV; 180 181 /* TODO: double rate support */ 182 if (ac97->flags & AC97_CS_SPDIF) { 183 switch (rate) { 184 case 48000: bits = 0; break; 185 case 44100: bits = 1 << AC97_SC_SPSR_SHIFT; break; 186 default: /* invalid - disable output */ 187 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 188 return -EINVAL; 189 } 190 reg = AC97_CSR_SPDIF; 191 mask = 1 << AC97_SC_SPSR_SHIFT; 192 } else { 193 if (ac97->id == AC97_ID_CM9739 && rate != 48000) { 194 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 195 return -EINVAL; 196 } 197 switch (rate) { 198 case 44100: bits = AC97_SC_SPSR_44K; break; 199 case 48000: bits = AC97_SC_SPSR_48K; break; 200 case 32000: bits = AC97_SC_SPSR_32K; break; 201 default: /* invalid - disable output */ 202 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 203 return -EINVAL; 204 } 205 reg = AC97_SPDIF; 206 mask = AC97_SC_SPSR_MASK; 207 } 208 209 down(&ac97->reg_mutex); 210 old = snd_ac97_read(ac97, reg) & mask; 211 if (old != bits) { 212 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); 213 snd_ac97_update_bits_nolock(ac97, reg, mask, bits); 214 /* update the internal spdif bits */ 215 sbits = ac97->spdif_status; 216 if (sbits & IEC958_AES0_PROFESSIONAL) { 217 sbits &= ~IEC958_AES0_PRO_FS; 218 switch (rate) { 219 case 44100: sbits |= IEC958_AES0_PRO_FS_44100; break; 220 case 48000: sbits |= IEC958_AES0_PRO_FS_48000; break; 221 case 32000: sbits |= IEC958_AES0_PRO_FS_32000; break; 222 } 223 } else { 224 sbits &= ~(IEC958_AES3_CON_FS << 24); 225 switch (rate) { 226 case 44100: sbits |= IEC958_AES3_CON_FS_44100<<24; break; 227 case 48000: sbits |= IEC958_AES3_CON_FS_48000<<24; break; 228 case 32000: sbits |= IEC958_AES3_CON_FS_32000<<24; break; 229 } 230 } 231 ac97->spdif_status = sbits; 232 } 233 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); 234 up(&ac97->reg_mutex); 235 return 0; 236 236 } 237 237 … … 255 255 * Returns zero if successful, or a negative error code on failure. 256 256 */ 257 int snd_ac97_set_rate( ac97_t*ac97, int reg, unsigned int rate)258 { 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 } 317 318 static unsigned short get_pslots( ac97_t*ac97, unsigned char *rate_table, unsigned short *spdif_slots)319 { 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 } 392 393 static unsigned short get_cslots( ac97_t*ac97)394 { 395 396 397 398 399 400 401 257 int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate) 258 { 259 int dbl; 260 unsigned int tmp; 261 262 dbl = rate > 48000; 263 if (dbl) { 264 if (!(ac97->flags & AC97_DOUBLE_RATE)) 265 return -EINVAL; 266 if (reg != AC97_PCM_FRONT_DAC_RATE) 267 return -EINVAL; 268 } 269 270 switch (reg) { 271 case AC97_PCM_MIC_ADC_RATE: 272 if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRM) == 0) /* MIC VRA */ 273 if (rate != 48000) 274 return -EINVAL; 275 break; 276 case AC97_PCM_FRONT_DAC_RATE: 277 case AC97_PCM_LR_ADC_RATE: 278 if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRA) == 0) /* VRA */ 279 if (rate != 48000 && rate != 96000) 280 return -EINVAL; 281 break; 282 case AC97_PCM_SURR_DAC_RATE: 283 if (! (ac97->scaps & AC97_SCAP_SURROUND_DAC)) 284 return -EINVAL; 285 break; 286 case AC97_PCM_LFE_DAC_RATE: 287 if (! (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) 288 return -EINVAL; 289 break; 290 case AC97_SPDIF: 291 /* special case */ 292 return set_spdif_rate(ac97, rate); 293 default: 294 return -EINVAL; 295 } 296 if (dbl) 297 rate /= 2; 298 tmp = (rate * ac97->bus->clock) / 48000; 299 if (tmp > 65535) 300 return -EINVAL; 301 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) 302 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, 303 AC97_EA_DRA, dbl ? AC97_EA_DRA : 0); 304 snd_ac97_update(ac97, reg, tmp & 0xffff); 305 snd_ac97_read(ac97, reg); 306 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) { 307 /* Intel controllers require double rate data to be put in 308 * slots 7+8 309 */ 310 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, 311 AC97_GP_DRSS_MASK, 312 dbl ? AC97_GP_DRSS_78 : 0); 313 snd_ac97_read(ac97, AC97_GENERAL_PURPOSE); 314 } 315 return 0; 316 } 317 318 static unsigned short get_pslots(struct snd_ac97 *ac97, unsigned char *rate_table, unsigned short *spdif_slots) 319 { 320 if (!ac97_is_audio(ac97)) 321 return 0; 322 if (ac97_is_rev22(ac97) || ac97_can_amap(ac97)) { 323 unsigned short slots = 0; 324 if (ac97_is_rev22(ac97)) { 325 /* Note: it's simply emulation of AMAP behaviour */ 326 u16 es; 327 es = ac97->regs[AC97_EXTENDED_ID] &= ~AC97_EI_DACS_SLOT_MASK; 328 switch (ac97->addr) { 329 case 1: 330 case 2: es |= (1<<AC97_EI_DACS_SLOT_SHIFT); break; 331 case 3: es |= (2<<AC97_EI_DACS_SLOT_SHIFT); break; 332 } 333 snd_ac97_write_cache(ac97, AC97_EXTENDED_ID, es); 334 } 335 switch (ac97->addr) { 336 case 0: 337 slots |= (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT); 338 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 339 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT); 340 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) 341 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE); 342 if (ac97->ext_id & AC97_EI_SPDIF) { 343 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) 344 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT)|(1<<AC97_SLOT_SPDIF_RIGHT); 345 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) 346 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1); 347 else 348 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2); 349 } 350 *rate_table = 0; 351 break; 352 case 1: 353 case 2: 354 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT); 355 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 356 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE); 357 if (ac97->ext_id & AC97_EI_SPDIF) { 358 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) 359 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1); 360 else 361 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2); 362 } 363 *rate_table = 1; 364 break; 365 case 3: 366 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE); 367 if (ac97->ext_id & AC97_EI_SPDIF) 368 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2); 369 *rate_table = 2; 370 break; 371 } 372 return slots; 373 } else { 374 unsigned short slots; 375 slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT); 376 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 377 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT); 378 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) 379 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE); 380 if (ac97->ext_id & AC97_EI_SPDIF) { 381 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) 382 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT)|(1<<AC97_SLOT_SPDIF_RIGHT); 383 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) 384 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1); 385 else 386 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2); 387 } 388 *rate_table = 0; 389 return slots; 390 } 391 } 392 393 static unsigned short get_cslots(struct snd_ac97 *ac97) 394 { 395 unsigned short slots; 396 397 if (!ac97_is_audio(ac97)) 398 return 0; 399 slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT); 400 slots |= (1<<AC97_SLOT_MIC); 401 return slots; 402 402 } 403 403 404 404 static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned short slots, int dbl) 405 405 { 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 406 int i, idx; 407 unsigned int rates = ~0; 408 unsigned char reg; 409 410 for (i = 3; i < 12; i++) { 411 if (!(slots & (1 << i))) 412 continue; 413 reg = get_slot_reg(pcm, cidx, i, dbl); 414 switch (reg) { 415 case AC97_PCM_FRONT_DAC_RATE: idx = AC97_RATES_FRONT_DAC; break; 416 case AC97_PCM_SURR_DAC_RATE: idx = AC97_RATES_SURR_DAC; break; 417 case AC97_PCM_LFE_DAC_RATE: idx = AC97_RATES_LFE_DAC; break; 418 case AC97_PCM_LR_ADC_RATE: idx = AC97_RATES_ADC; break; 419 case AC97_PCM_MIC_ADC_RATE: idx = AC97_RATES_MIC_ADC; break; 420 default: idx = AC97_RATES_SPDIF; break; 421 } 422 rates &= pcm->r[dbl].codec[cidx]->rates[idx]; 423 } 424 if (!dbl) 425 rates &= ~(SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | 426 SNDRV_PCM_RATE_96000); 427 return rates; 428 428 } 429 429 … … 438 438 * are reduced and might be zero. 439 439 */ 440 int snd_ac97_pcm_assign( ac97_bus_t*bus,441 442 443 { 444 445 446 447 448 449 450 451 452 ac97_t*codec;453 454 455 456 457 458 459 460 461 462 if (!codec)463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 440 int snd_ac97_pcm_assign(struct snd_ac97_bus *bus, 441 unsigned short pcms_count, 442 const struct ac97_pcm *pcms) 443 { 444 int i, j, k; 445 const struct ac97_pcm *pcm; 446 struct ac97_pcm *rpcms, *rpcm; 447 unsigned short avail_slots[2][4]; 448 unsigned char rate_table[2][4]; 449 unsigned short tmp, slots; 450 unsigned short spdif_slots[4]; 451 unsigned int rates; 452 struct snd_ac97 *codec; 453 454 rpcms = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL); 455 if (rpcms == NULL) 456 return -ENOMEM; 457 memset(avail_slots, 0, sizeof(avail_slots)); 458 memset(rate_table, 0, sizeof(rate_table)); 459 memset(spdif_slots, 0, sizeof(spdif_slots)); 460 for (i = 0; i < 4; i++) { 461 codec = bus->codec[i]; 462 if (!codec) 463 continue; 464 avail_slots[0][i] = get_pslots(codec, &rate_table[0][i], &spdif_slots[i]); 465 avail_slots[1][i] = get_cslots(codec); 466 if (!(codec->scaps & AC97_SCAP_INDEP_SDIN)) { 467 for (j = 0; j < i; j++) { 468 if (bus->codec[j]) 469 avail_slots[1][i] &= ~avail_slots[1][j]; 470 } 471 } 472 } 473 /* first step - exclusive devices */ 474 for (i = 0; i < pcms_count; i++) { 475 pcm = &pcms[i]; 476 rpcm = &rpcms[i]; 477 /* low-level driver thinks that it's more clever */ 478 if (pcm->copy_flag) { 479 *rpcm = *pcm; 480 continue; 481 } 482 rpcm->stream = pcm->stream; 483 rpcm->exclusive = pcm->exclusive; 484 rpcm->spdif = pcm->spdif; 485 rpcm->private_value = pcm->private_value; 486 rpcm->bus = bus; 487 rpcm->rates = ~0; 488 slots = pcm->r[0].slots; 489 for (j = 0; j < 4 && slots; j++) { 490 if (!bus->codec[j]) 491 continue; 492 rates = ~0; 493 if (pcm->spdif && pcm->stream == 0) 494 tmp = spdif_slots[j]; 495 else 496 tmp = avail_slots[pcm->stream][j]; 497 if (pcm->exclusive) { 498 /* exclusive access */ 499 tmp &= slots; 500 for (k = 0; k < i; k++) { 501 if (rpcm->stream == rpcms[k].stream) 502 tmp &= ~rpcms[k].r[0].rslots[j]; 503 } 504 } else { 505 /* non-exclusive access */ 506 tmp &= pcm->r[0].slots; 507 } 508 if (tmp) { 509 rpcm->r[0].rslots[j] = tmp; 510 rpcm->r[0].codec[j] = bus->codec[j]; 511 rpcm->r[0].rate_table[j] = rate_table[pcm->stream][j]; 512 if (bus->no_vra) 513 rates = SNDRV_PCM_RATE_48000; 514 else 515 rates = get_rates(rpcm, j, tmp, 0); 516 if (pcm->exclusive) 517 avail_slots[pcm->stream][j] &= ~tmp; 518 } 519 slots &= ~tmp; 520 rpcm->r[0].slots |= tmp; 521 rpcm->rates &= rates; 522 } 523 /* for double rate, we check the first codec only */ 524 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK && 525 bus->codec[0] && (bus->codec[0]->flags & AC97_DOUBLE_RATE) && 526 rate_table[pcm->stream][0] == 0) { 527 tmp = (1<<AC97_SLOT_PCM_LEFT) | (1<<AC97_SLOT_PCM_RIGHT) | 528 (1<<AC97_SLOT_PCM_LEFT_0) | (1<<AC97_SLOT_PCM_RIGHT_0); 529 if ((tmp & pcm->r[1].slots) == tmp) { 530 rpcm->r[1].slots = tmp; 531 rpcm->r[1].rslots[0] = tmp; 532 rpcm->r[1].rate_table[0] = 0; 533 rpcm->r[1].codec[0] = bus->codec[0]; 534 if (pcm->exclusive) 535 avail_slots[pcm->stream][0] &= ~tmp; 536 if (bus->no_vra) 537 rates = SNDRV_PCM_RATE_96000; 538 else 539 rates = get_rates(rpcm, 0, tmp, 1); 540 rpcm->rates |= rates; 541 } 542 } 543 if (rpcm->rates == ~0) 544 rpcm->rates = 0; /* not used */ 545 } 546 bus->pcms_count = pcms_count; 547 bus->pcms = rpcms; 548 return 0; 549 549 } 550 550 … … 559 559 */ 560 560 int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, 561 enum ac97_pcm_cfg cfg, unsigned short slots) 562 { 563 ac97_bus_t *bus; 564 int i, cidx, r, ok_flag; 565 unsigned int reg_ok[4] = {0,0,0,0}; 566 unsigned char reg; 567 int err = 0; 568 569 r = rate > 48000; 570 571 bus = pcm->bus; 572 if (cfg == AC97_PCM_CFG_SPDIF) { 573 int err; 574 for (cidx = 0; cidx < 4; cidx++) 575 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { 576 err = set_spdif_rate(bus->codec[cidx], rate); 577 if (err < 0) 578 return err; 579 } 580 } 581 spin_lock_irq(&pcm->bus->bus_lock); 582 for (i = 3; i < 12; i++) { 583 if (!(slots & (1 << i))) 584 continue; 585 ok_flag = 0; 586 for (cidx = 0; cidx < 4; cidx++) { 587 if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { 588 spin_unlock_irq(&pcm->bus->bus_lock); 589 err = -EBUSY; 590 goto error; 591 } 592 if (pcm->r[r].rslots[cidx] & (1 << i)) { 593 bus->used_slots[pcm->stream][cidx] |= (1 << i); 594 ok_flag++; 595 } 596 } 597 if (!ok_flag) { 598 spin_unlock_irq(&pcm->bus->bus_lock); 599 snd_printk(KERN_ERR "cannot find configuration for AC97 slot %i\n", i); 600 err = -EAGAIN; 601 goto error; 602 } 603 } 604 spin_unlock_irq(&pcm->bus->bus_lock); 605 for (i = 3; i < 12; i++) { 606 if (!(slots & (1 << i))) 607 continue; 608 for (cidx = 0; cidx < 4; cidx++) { 609 if (pcm->r[r].rslots[cidx] & (1 << i)) { 610 reg = get_slot_reg(pcm, cidx, i, r); 611 if (reg == 0xff) { 612 snd_printk(KERN_ERR "invalid AC97 slot %i?\n", i); 613 continue; 614 } 615 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE))) 616 continue; 617 //printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate); 618 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate); 619 if (err < 0) 620 snd_printk(KERN_ERR "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx, reg, rate, err); 621 else 622 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE)); 623 } 624 } 625 } 626 pcm->aslots = slots; 627 return 0; 628 629 error: 630 pcm->aslots = slots; 631 snd_ac97_pcm_close(pcm); 632 return err; 561 enum ac97_pcm_cfg cfg, unsigned short slots) 562 { 563 struct snd_ac97_bus *bus; 564 int i, cidx, r, ok_flag; 565 unsigned int reg_ok[4] = {0,0,0,0}; 566 unsigned char reg; 567 int err = 0; 568 569 r = rate > 48000; 570 bus = pcm->bus; 571 if (cfg == AC97_PCM_CFG_SPDIF) { 572 int err; 573 for (cidx = 0; cidx < 4; cidx++) 574 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { 575 err = set_spdif_rate(bus->codec[cidx], rate); 576 if (err < 0) 577 return err; 578 } 579 } 580 spin_lock_irq(&pcm->bus->bus_lock); 581 for (i = 3; i < 12; i++) { 582 if (!(slots & (1 << i))) 583 continue; 584 ok_flag = 0; 585 for (cidx = 0; cidx < 4; cidx++) { 586 if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { 587 spin_unlock_irq(&pcm->bus->bus_lock); 588 err = -EBUSY; 589 goto error; 590 } 591 if (pcm->r[r].rslots[cidx] & (1 << i)) { 592 bus->used_slots[pcm->stream][cidx] |= (1 << i); 593 ok_flag++; 594 } 595 } 596 if (!ok_flag) { 597 spin_unlock_irq(&pcm->bus->bus_lock); 598 snd_printk(KERN_ERR "cannot find configuration for AC97 slot %i\n", i); 599 err = -EAGAIN; 600 goto error; 601 } 602 } 603 spin_unlock_irq(&pcm->bus->bus_lock); 604 for (i = 3; i < 12; i++) { 605 if (!(slots & (1 << i))) 606 continue; 607 for (cidx = 0; cidx < 4; cidx++) { 608 if (pcm->r[r].rslots[cidx] & (1 << i)) { 609 reg = get_slot_reg(pcm, cidx, i, r); 610 if (reg == 0xff) { 611 snd_printk(KERN_ERR "invalid AC97 slot %i?\n", i); 612 continue; 613 } 614 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE))) 615 continue; 616 //printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate); 617 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate); 618 if (err < 0) 619 snd_printk(KERN_ERR "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx, reg, rate, err); 620 else 621 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE)); 622 } 623 } 624 } 625 pcm->aslots = slots; 626 return 0; 627 628 error: 629 pcm->aslots = slots; 630 snd_ac97_pcm_close(pcm); 631 return err; 633 632 } 634 633 … … 641 640 int snd_ac97_pcm_close(struct ac97_pcm *pcm) 642 641 { 643 ac97_bus_t *bus; 644 unsigned short slots = pcm->aslots; 645 int i, cidx; 646 647 bus = pcm->bus; 648 spin_lock_irq(&pcm->bus->bus_lock); 649 for (i = 3; i < 12; i++) { 650 if (!(slots & (1 << i))) 651 continue; 652 for (cidx = 0; cidx < 4; cidx++) 653 bus->used_slots[pcm->stream][cidx] &= ~(1 << i); 654 } 655 pcm->aslots = 0; 656 spin_unlock_irq(&pcm->bus->bus_lock); 657 return 0; 658 } 659 660 661 static int double_rate_hw_constraint_rate(snd_pcm_hw_params_t *params, 662 snd_pcm_hw_rule_t *rule) 663 { 664 snd_interval_t *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 665 if (channels->min > 2) { 666 static const snd_interval_t single_rates = { 667 /*.min = */1, 668 /*.max = */48000,0,0,0,0 669 }; 670 snd_interval_t *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 671 return snd_interval_refine(rate, &single_rates); 672 } 673 return 0; 674 } 675 676 static int double_rate_hw_constraint_channels(snd_pcm_hw_params_t *params, 677 snd_pcm_hw_rule_t *rule) 678 { 679 snd_interval_t *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 680 if (rate->min > 48000) { 681 static const snd_interval_t double_rate_channels = { 682 /*.min = */2, 683 /*.max = */2, 0,0,0,0 684 }; 685 snd_interval_t *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 686 return snd_interval_refine(channels, &double_rate_channels); 687 } 688 return 0; 642 struct snd_ac97_bus *bus; 643 unsigned short slots = pcm->aslots; 644 int i, cidx; 645 646 bus = pcm->bus; 647 spin_lock_irq(&pcm->bus->bus_lock); 648 for (i = 3; i < 12; i++) { 649 if (!(slots & (1 << i))) 650 continue; 651 for (cidx = 0; cidx < 4; cidx++) 652 bus->used_slots[pcm->stream][cidx] &= ~(1 << i); 653 } 654 pcm->aslots = 0; 655 spin_unlock_irq(&pcm->bus->bus_lock); 656 return 0; 657 } 658 659 static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params *params, 660 struct snd_pcm_hw_rule *rule) 661 { 662 struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 663 if (channels->min > 2) { 664 static const struct snd_interval single_rates = { 665 .min = 1, 666 .max = 48000, 667 }; 668 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 669 return snd_interval_refine(rate, &single_rates); 670 } 671 return 0; 672 } 673 674 static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params *params, 675 struct snd_pcm_hw_rule *rule) 676 { 677 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 678 if (rate->min > 48000) { 679 static const struct snd_interval double_rate_channels = { 680 .min = 2, 681 .max = 2, 682 }; 683 struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 684 return snd_interval_refine(channels, &double_rate_channels); 685 } 686 return 0; 689 687 } 690 688 … … 696 694 * more than two channels at the same time. 697 695 */ 698 int snd_ac97_pcm_double_rate_rules(snd_pcm_runtime_t *runtime) 699 { 700 int err; 701 702 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 703 double_rate_hw_constraint_rate, NULL, 704 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 705 if (err < 0) 706 return err; 707 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 708 double_rate_hw_constraint_channels, NULL, 709 SNDRV_PCM_HW_PARAM_RATE, -1); 710 return err; 711 } 712 696 int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime) 697 { 698 int err; 699 700 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 701 double_rate_hw_constraint_rate, NULL, 702 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 703 if (err < 0) 704 return err; 705 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 706 double_rate_hw_constraint_channels, NULL, 707 SNDRV_PCM_HW_PARAM_RATE, -1); 708 return err; 709 } -
GPL/trunk/alsa-kernel/pci/ac97/ac97_proc.c
r32 r72 35 35 */ 36 36 37 static void snd_ac97_proc_read_functions(ac97_t *ac97, snd_info_buffer_t *buffer) 38 { 39 int header = 0, function; 40 unsigned short info, sense_info; 41 static const char *function_names[12] = { 42 "Master Out", "AUX Out", "Center/LFE Out", "SPDIF Out", 43 "Phone In", "Mic 1", "Mic 2", "Line In", "CD In", "Video In", 44 "Aux In", "Mono Out" 45 }; 46 static const char *locations[8] = { 47 "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External", 48 "reserved", "reserved", "reserved", "NC/unused" 49 }; 50 51 for (function = 0; function < 12; ++function) { 52 snd_ac97_write(ac97, AC97_FUNC_SELECT, function << 1); 53 info = snd_ac97_read(ac97, AC97_FUNC_INFO); 54 if (!(info & 0x0001)) 55 continue; 56 if (!header) { 57 snd_iprintf(buffer, "\n Gain Inverted Buffer delay Location\n"); 58 header = 1; 59 } 60 sense_info = snd_ac97_read(ac97, AC97_SENSE_INFO); 61 snd_iprintf(buffer, "%-17s: %3d.%d dBV %c %2d/fs %s\n", 62 function_names[function], 63 (info & 0x8000 ? -1 : 1) * ((info & 0x7000) >> 12) * 3 / 2, 64 ((info & 0x0800) >> 11) * 5, 65 info & 0x0400 ? 'X' : '-', 66 (info & 0x03e0) >> 5, 67 locations[sense_info >> 13]); 68 } 69 } 70 71 static void snd_ac97_proc_read_main(ac97_t *ac97, snd_info_buffer_t * buffer, int subidx) 72 { 73 char name[64]; 74 unsigned short val, tmp, ext, mext; 75 static const char *spdif_slots[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" }; 76 static const char *spdif_rates[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" }; 77 static const char *spdif_rates_cs4205[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" }; 78 static const char *double_rate_slots[4] = { "10/11", "7/8", "reserved", "reserved" }; 79 80 snd_ac97_get_name(NULL, ac97->id, name, 0); 81 snd_iprintf(buffer, "%d-%d/%d: %s\n\n", ac97->addr, ac97->num, subidx, name); 82 if ((ac97->scaps & AC97_SCAP_AUDIO) == 0) 83 goto __modem; 84 85 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) { 86 val = snd_ac97_read(ac97, AC97_INT_PAGING); 87 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 88 AC97_PAGE_MASK, AC97_PAGE_1); 89 tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV); 90 snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff); 91 snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f); 92 snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n", 93 snd_ac97_read(ac97, AC97_PCI_SVID)); 94 snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n", 95 snd_ac97_read(ac97, AC97_PCI_SID)); 96 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 97 AC97_PAGE_MASK, val & AC97_PAGE_MASK); 98 } 99 // val = snd_ac97_read(ac97, AC97_RESET); 100 val = ac97->caps; 101 snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n", 102 val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "", 103 val & AC97_BC_RESERVED1 ? " -reserved1-" : "", 104 val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "", 105 val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "", 106 val & AC97_BC_HEADPHONE ? " -headphone out-" : "", 107 val & AC97_BC_LOUDNESS ? " -loudness-" : ""); 108 tmp = ac97->caps & AC97_BC_DAC_MASK; 109 snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n", 110 tmp == AC97_BC_16BIT_DAC ? "16-bit" : "", 111 tmp == AC97_BC_18BIT_DAC ? "18-bit" : "", 112 tmp == AC97_BC_20BIT_DAC ? "20-bit" : "", 113 tmp == AC97_BC_DAC_MASK ? "???" : ""); 114 tmp = ac97->caps & AC97_BC_ADC_MASK; 115 snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n", 116 tmp == AC97_BC_16BIT_ADC ? "16-bit" : "", 117 tmp == AC97_BC_18BIT_ADC ? "18-bit" : "", 118 tmp == AC97_BC_20BIT_ADC ? "20-bit" : "", 119 tmp == AC97_BC_ADC_MASK ? "???" : ""); 120 snd_iprintf(buffer, "3D enhancement : %s\n", 121 snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]); 122 snd_iprintf(buffer, "\nCurrent setup\n"); 123 val = snd_ac97_read(ac97, AC97_MIC); 124 snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB"); 125 val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE); 126 snd_iprintf(buffer, "POP path : %s 3D\n" 127 "Sim. stereo : %s\n" 128 "3D enhancement : %s\n" 129 "Loudness : %s\n" 130 "Mono output : %s\n" 131 "Mic select : %s\n" 132 "ADC/DAC loopback : %s\n", 133 val & 0x8000 ? "post" : "pre", 134 val & 0x4000 ? "on" : "off", 135 val & 0x2000 ? "on" : "off", 136 val & 0x1000 ? "on" : "off", 137 val & 0x0200 ? "Mic" : "MIX", 138 val & 0x0100 ? "Mic2" : "Mic1", 139 val & 0x0080 ? "on" : "off"); 140 if (ac97->ext_id & AC97_EI_DRA) 141 snd_iprintf(buffer, "Double rate slots: %s\n", 142 double_rate_slots[(val >> 10) & 3]); 143 ext = snd_ac97_read(ac97, AC97_EXTENDED_ID); 144 if (ext == 0) 145 goto __modem; 146 147 snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n", 148 (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT, 149 (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT, 150 ext & AC97_EI_AMAP ? " AMAP" : "", 151 ext & AC97_EI_LDAC ? " LDAC" : "", 152 ext & AC97_EI_SDAC ? " SDAC" : "", 153 ext & AC97_EI_CDAC ? " CDAC" : "", 154 (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT, 155 ext & AC97_EI_VRM ? " VRM" : "", 156 ext & AC97_EI_SPDIF ? " SPDIF" : "", 157 ext & AC97_EI_DRA ? " DRA" : "", 158 ext & AC97_EI_VRA ? " VRA" : ""); 159 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 160 snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 161 val & AC97_EA_PRL ? " PRL" : "", 162 val & AC97_EA_PRK ? " PRK" : "", 163 val & AC97_EA_PRJ ? " PRJ" : "", 164 val & AC97_EA_PRI ? " PRI" : "", 165 val & AC97_EA_SPCV ? " SPCV" : "", 166 val & AC97_EA_MDAC ? " MADC" : "", 167 val & AC97_EA_LDAC ? " LDAC" : "", 168 val & AC97_EA_SDAC ? " SDAC" : "", 169 val & AC97_EA_CDAC ? " CDAC" : "", 170 ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "", 171 val & AC97_EA_VRM ? " VRM" : "", 172 val & AC97_EA_SPDIF ? " SPDIF" : "", 173 val & AC97_EA_DRA ? " DRA" : "", 174 val & AC97_EA_VRA ? " VRA" : ""); 175 if (ext & AC97_EI_VRA) { /* VRA */ 176 val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE); 177 snd_iprintf(buffer, "PCM front DAC : %iHz\n", val); 178 if (ext & AC97_EI_SDAC) { 179 val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE); 180 snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val); 181 } 182 if (ext & AC97_EI_LDAC) { 183 val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE); 184 snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val); 185 } 186 val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE); 187 snd_iprintf(buffer, "PCM ADC : %iHz\n", val); 188 } 189 if (ext & AC97_EI_VRM) { 190 val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE); 191 snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val); 192 } 193 if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF)) { 194 if (ac97->flags & AC97_CS_SPDIF) 195 val = snd_ac97_read(ac97, AC97_CSR_SPDIF); 196 else 197 val = snd_ac97_read(ac97, AC97_SPDIF); 198 199 snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n", 200 val & AC97_SC_PRO ? " PRO" : " Consumer", 201 val & AC97_SC_NAUDIO ? " Non-audio" : " PCM", 202 val & AC97_SC_COPY ? "" : " Copyright", 203 val & AC97_SC_PRE ? " Preemph50/15" : "", 204 (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT, 205 (val & AC97_SC_L) >> 11, 206 (ac97->flags & AC97_CS_SPDIF) ? 207 spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] : 208 spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT], 209 (ac97->flags & AC97_CS_SPDIF) ? 210 (val & AC97_SC_DRS ? " Validity" : "") : 211 (val & AC97_SC_DRS ? " DRS" : ""), 212 (ac97->flags & AC97_CS_SPDIF) ? 213 (val & AC97_SC_V ? " Enabled" : "") : 214 (val & AC97_SC_V ? " Validity" : "")); 215 /* ALC650 specific*/ 216 if ((ac97->id & 0xfffffff0) == 0x414c4720 && 217 (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) { 218 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2); 219 if (val & AC97_ALC650_CLOCK_LOCK) { 220 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1); 221 snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i", 222 val & AC97_ALC650_PRO ? " PRO" : " Consumer", 223 val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM", 224 val & AC97_ALC650_COPY ? "" : " Copyright", 225 val & AC97_ALC650_PRE ? " Preemph50/15" : "", 226 (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT, 227 (val & AC97_ALC650_L) >> 15); 228 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2); 229 snd_iprintf(buffer, "%s Accuracy=%i%s%s\n", 230 spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT], 231 (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT, 232 (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"), 233 (val & AC97_ALC650_V ? " Validity?" : "")); 234 } else { 235 snd_iprintf(buffer, "SPDIF In Status : Not Locked\n"); 236 } 237 } 238 } 239 240 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) { 241 val = snd_ac97_read(ac97, AC97_INT_PAGING); 242 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 243 AC97_PAGE_MASK, AC97_PAGE_1); 244 snd_ac97_proc_read_functions(ac97, buffer); 245 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 246 AC97_PAGE_MASK, val & AC97_PAGE_MASK); 247 } 248 __modem: 249 mext = snd_ac97_read(ac97, AC97_EXTENDED_MID); 250 if (mext == 0) 251 return; 252 253 snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n", 254 (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT, 255 mext & AC97_MEI_CID2 ? " CID2" : "", 256 mext & AC97_MEI_CID1 ? " CID1" : "", 257 mext & AC97_MEI_HANDSET ? " HSET" : "", 258 mext & AC97_MEI_LINE2 ? " LIN2" : "", 259 mext & AC97_MEI_LINE1 ? " LIN1" : ""); 260 val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS); 261 snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 262 val & AC97_MEA_GPIO ? " GPIO" : "", 263 val & AC97_MEA_MREF ? " MREF" : "", 264 val & AC97_MEA_ADC1 ? " ADC1" : "", 265 val & AC97_MEA_DAC1 ? " DAC1" : "", 266 val & AC97_MEA_ADC2 ? " ADC2" : "", 267 val & AC97_MEA_DAC2 ? " DAC2" : "", 268 val & AC97_MEA_HADC ? " HADC" : "", 269 val & AC97_MEA_HDAC ? " HDAC" : "", 270 val & AC97_MEA_PRA ? " PRA(GPIO)" : "", 271 val & AC97_MEA_PRB ? " PRB(res)" : "", 272 val & AC97_MEA_PRC ? " PRC(ADC1)" : "", 273 val & AC97_MEA_PRD ? " PRD(DAC1)" : "", 274 val & AC97_MEA_PRE ? " PRE(ADC2)" : "", 275 val & AC97_MEA_PRF ? " PRF(DAC2)" : "", 276 val & AC97_MEA_PRG ? " PRG(HADC)" : "", 277 val & AC97_MEA_PRH ? " PRH(HDAC)" : ""); 278 if (mext & AC97_MEI_LINE1) { 279 val = snd_ac97_read(ac97, AC97_LINE1_RATE); 280 snd_iprintf(buffer, "Line1 rate : %iHz\n", val); 281 } 282 if (mext & AC97_MEI_LINE2) { 283 val = snd_ac97_read(ac97, AC97_LINE2_RATE); 284 snd_iprintf(buffer, "Line2 rate : %iHz\n", val); 285 } 286 if (mext & AC97_MEI_HANDSET) { 287 val = snd_ac97_read(ac97, AC97_HANDSET_RATE); 288 snd_iprintf(buffer, "Headset rate : %iHz\n", val); 289 } 290 } 291 292 static void snd_ac97_proc_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) 293 { 294 ac97_t *ac97 = entry->private_data; 295 296 down(&ac97->page_mutex); 37 static void snd_ac97_proc_read_functions(struct snd_ac97 *ac97, struct snd_info_buffer *buffer) 38 { 39 int header = 0, function; 40 unsigned short info, sense_info; 41 static const char *function_names[12] = { 42 "Master Out", "AUX Out", "Center/LFE Out", "SPDIF Out", 43 "Phone In", "Mic 1", "Mic 2", "Line In", "CD In", "Video In", 44 "Aux In", "Mono Out" 45 }; 46 static const char *locations[8] = { 47 "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External", 48 "reserved", "reserved", "reserved", "NC/unused" 49 }; 50 51 for (function = 0; function < 12; ++function) { 52 snd_ac97_write(ac97, AC97_FUNC_SELECT, function << 1); 53 info = snd_ac97_read(ac97, AC97_FUNC_INFO); 54 if (!(info & 0x0001)) 55 continue; 56 if (!header) { 57 snd_iprintf(buffer, "\n Gain Inverted Buffer delay Location\n"); 58 header = 1; 59 } 60 sense_info = snd_ac97_read(ac97, AC97_SENSE_INFO); 61 snd_iprintf(buffer, "%-17s: %3d.%d dBV %c %2d/fs %s\n", 62 function_names[function], 63 (info & 0x8000 ? -1 : 1) * ((info & 0x7000) >> 12) * 3 / 2, 64 ((info & 0x0800) >> 11) * 5, 65 info & 0x0400 ? 'X' : '-', 66 (info & 0x03e0) >> 5, 67 locations[sense_info >> 13]); 68 } 69 } 70 71 static const char *snd_ac97_stereo_enhancements[] = 72 { 73 /* 0 */ "No 3D Stereo Enhancement", 74 /* 1 */ "Analog Devices Phat Stereo", 75 /* 2 */ "Creative Stereo Enhancement", 76 /* 3 */ "National Semi 3D Stereo Enhancement", 77 /* 4 */ "YAMAHA Ymersion", 78 /* 5 */ "BBE 3D Stereo Enhancement", 79 /* 6 */ "Crystal Semi 3D Stereo Enhancement", 80 /* 7 */ "Qsound QXpander", 81 /* 8 */ "Spatializer 3D Stereo Enhancement", 82 /* 9 */ "SRS 3D Stereo Enhancement", 83 /* 10 */ "Platform Tech 3D Stereo Enhancement", 84 /* 11 */ "AKM 3D Audio", 85 /* 12 */ "Aureal Stereo Enhancement", 86 /* 13 */ "Aztech 3D Enhancement", 87 /* 14 */ "Binaura 3D Audio Enhancement", 88 /* 15 */ "ESS Technology Stereo Enhancement", 89 /* 16 */ "Harman International VMAx", 90 /* 17 */ "Nvidea/IC Ensemble/KS Waves 3D Stereo Enhancement", 91 /* 18 */ "Philips Incredible Sound", 92 /* 19 */ "Texas Instruments 3D Stereo Enhancement", 93 /* 20 */ "VLSI Technology 3D Stereo Enhancement", 94 /* 21 */ "TriTech 3D Stereo Enhancement", 95 /* 22 */ "Realtek 3D Stereo Enhancement", 96 /* 23 */ "Samsung 3D Stereo Enhancement", 97 /* 24 */ "Wolfson Microelectronics 3D Enhancement", 98 /* 25 */ "Delta Integration 3D Enhancement", 99 /* 26 */ "SigmaTel 3D Enhancement", 100 /* 27 */ "IC Ensemble/KS Waves", 101 /* 28 */ "Rockwell 3D Stereo Enhancement", 102 /* 29 */ "Reserved 29", 103 /* 30 */ "Reserved 30", 104 /* 31 */ "Reserved 31" 105 }; 106 107 static void snd_ac97_proc_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx) 108 { 109 char name[64]; 110 unsigned short val, tmp, ext, mext; 111 static const char *spdif_slots[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" }; 112 static const char *spdif_rates[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" }; 113 static const char *spdif_rates_cs4205[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" }; 114 static const char *double_rate_slots[4] = { "10/11", "7/8", "reserved", "reserved" }; 115 116 snd_ac97_get_name(NULL, ac97->id, name, 0); 117 snd_iprintf(buffer, "%d-%d/%d: %s\n\n", ac97->addr, ac97->num, subidx, name); 118 119 if ((ac97->scaps & AC97_SCAP_AUDIO) == 0) 120 goto __modem; 121 122 snd_iprintf(buffer, "PCI Subsys Vendor: 0x%04x\n", 123 ac97->subsystem_vendor); 124 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n", 125 ac97->subsystem_device); 126 127 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) { 128 val = snd_ac97_read(ac97, AC97_INT_PAGING); 129 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 130 AC97_PAGE_MASK, AC97_PAGE_1); 131 tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV); 132 snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff); 133 snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f); 134 snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n", 135 snd_ac97_read(ac97, AC97_PCI_SVID)); 136 snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n", 137 snd_ac97_read(ac97, AC97_PCI_SID)); 138 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 139 AC97_PAGE_MASK, val & AC97_PAGE_MASK); 140 } 141 142 // val = snd_ac97_read(ac97, AC97_RESET); 143 val = ac97->caps; 144 snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n", 145 val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "", 146 val & AC97_BC_RESERVED1 ? " -reserved1-" : "", 147 val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "", 148 val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "", 149 val & AC97_BC_HEADPHONE ? " -headphone out-" : "", 150 val & AC97_BC_LOUDNESS ? " -loudness-" : ""); 151 tmp = ac97->caps & AC97_BC_DAC_MASK; 152 snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n", 153 tmp == AC97_BC_16BIT_DAC ? "16-bit" : "", 154 tmp == AC97_BC_18BIT_DAC ? "18-bit" : "", 155 tmp == AC97_BC_20BIT_DAC ? "20-bit" : "", 156 tmp == AC97_BC_DAC_MASK ? "???" : ""); 157 tmp = ac97->caps & AC97_BC_ADC_MASK; 158 snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n", 159 tmp == AC97_BC_16BIT_ADC ? "16-bit" : "", 160 tmp == AC97_BC_18BIT_ADC ? "18-bit" : "", 161 tmp == AC97_BC_20BIT_ADC ? "20-bit" : "", 162 tmp == AC97_BC_ADC_MASK ? "???" : ""); 163 snd_iprintf(buffer, "3D enhancement : %s\n", 164 snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]); 165 snd_iprintf(buffer, "\nCurrent setup\n"); 166 val = snd_ac97_read(ac97, AC97_MIC); 167 snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB"); 168 val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE); 169 snd_iprintf(buffer, "POP path : %s 3D\n" 170 "Sim. stereo : %s\n" 171 "3D enhancement : %s\n" 172 "Loudness : %s\n" 173 "Mono output : %s\n" 174 "Mic select : %s\n" 175 "ADC/DAC loopback : %s\n", 176 val & 0x8000 ? "post" : "pre", 177 val & 0x4000 ? "on" : "off", 178 val & 0x2000 ? "on" : "off", 179 val & 0x1000 ? "on" : "off", 180 val & 0x0200 ? "Mic" : "MIX", 181 val & 0x0100 ? "Mic2" : "Mic1", 182 val & 0x0080 ? "on" : "off"); 183 if (ac97->ext_id & AC97_EI_DRA) 184 snd_iprintf(buffer, "Double rate slots: %s\n", 185 double_rate_slots[(val >> 10) & 3]); 186 187 ext = snd_ac97_read(ac97, AC97_EXTENDED_ID); 188 if (ext == 0) 189 goto __modem; 190 191 snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n", 192 (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT, 193 (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT, 194 ext & AC97_EI_AMAP ? " AMAP" : "", 195 ext & AC97_EI_LDAC ? " LDAC" : "", 196 ext & AC97_EI_SDAC ? " SDAC" : "", 197 ext & AC97_EI_CDAC ? " CDAC" : "", 198 (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT, 199 ext & AC97_EI_VRM ? " VRM" : "", 200 ext & AC97_EI_SPDIF ? " SPDIF" : "", 201 ext & AC97_EI_DRA ? " DRA" : "", 202 ext & AC97_EI_VRA ? " VRA" : ""); 203 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 204 snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 205 val & AC97_EA_PRL ? " PRL" : "", 206 val & AC97_EA_PRK ? " PRK" : "", 207 val & AC97_EA_PRJ ? " PRJ" : "", 208 val & AC97_EA_PRI ? " PRI" : "", 209 val & AC97_EA_SPCV ? " SPCV" : "", 210 val & AC97_EA_MDAC ? " MADC" : "", 211 val & AC97_EA_LDAC ? " LDAC" : "", 212 val & AC97_EA_SDAC ? " SDAC" : "", 213 val & AC97_EA_CDAC ? " CDAC" : "", 214 ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "", 215 val & AC97_EA_VRM ? " VRM" : "", 216 val & AC97_EA_SPDIF ? " SPDIF" : "", 217 val & AC97_EA_DRA ? " DRA" : "", 218 val & AC97_EA_VRA ? " VRA" : ""); 219 if (ext & AC97_EI_VRA) { /* VRA */ 220 val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE); 221 snd_iprintf(buffer, "PCM front DAC : %iHz\n", val); 222 if (ext & AC97_EI_SDAC) { 223 val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE); 224 snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val); 225 } 226 if (ext & AC97_EI_LDAC) { 227 val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE); 228 snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val); 229 } 230 val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE); 231 snd_iprintf(buffer, "PCM ADC : %iHz\n", val); 232 } 233 if (ext & AC97_EI_VRM) { 234 val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE); 235 snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val); 236 } 237 if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF)) { 238 if (ac97->flags & AC97_CS_SPDIF) 239 val = snd_ac97_read(ac97, AC97_CSR_SPDIF); 240 else 241 val = snd_ac97_read(ac97, AC97_SPDIF); 242 243 snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n", 244 val & AC97_SC_PRO ? " PRO" : " Consumer", 245 val & AC97_SC_NAUDIO ? " Non-audio" : " PCM", 246 val & AC97_SC_COPY ? "" : " Copyright", 247 val & AC97_SC_PRE ? " Preemph50/15" : "", 248 (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT, 249 (val & AC97_SC_L) >> 11, 250 (ac97->flags & AC97_CS_SPDIF) ? 251 spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] : 252 spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT], 253 (ac97->flags & AC97_CS_SPDIF) ? 254 (val & AC97_SC_DRS ? " Validity" : "") : 255 (val & AC97_SC_DRS ? " DRS" : ""), 256 (ac97->flags & AC97_CS_SPDIF) ? 257 (val & AC97_SC_V ? " Enabled" : "") : 258 (val & AC97_SC_V ? " Validity" : "")); 259 /* ALC650 specific*/ 260 if ((ac97->id & 0xfffffff0) == 0x414c4720 && 261 (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) { 262 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2); 263 if (val & AC97_ALC650_CLOCK_LOCK) { 264 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1); 265 snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i", 266 val & AC97_ALC650_PRO ? " PRO" : " Consumer", 267 val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM", 268 val & AC97_ALC650_COPY ? "" : " Copyright", 269 val & AC97_ALC650_PRE ? " Preemph50/15" : "", 270 (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT, 271 (val & AC97_ALC650_L) >> 15); 272 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2); 273 snd_iprintf(buffer, "%s Accuracy=%i%s%s\n", 274 spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT], 275 (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT, 276 (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"), 277 (val & AC97_ALC650_V ? " Validity?" : "")); 278 } else { 279 snd_iprintf(buffer, "SPDIF In Status : Not Locked\n"); 280 } 281 } 282 } 283 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) { 284 val = snd_ac97_read(ac97, AC97_INT_PAGING); 285 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 286 AC97_PAGE_MASK, AC97_PAGE_1); 287 snd_ac97_proc_read_functions(ac97, buffer); 288 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 289 AC97_PAGE_MASK, val & AC97_PAGE_MASK); 290 } 291 292 293 __modem: 294 mext = snd_ac97_read(ac97, AC97_EXTENDED_MID); 295 if (mext == 0) 296 return; 297 298 snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n", 299 (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT, 300 mext & AC97_MEI_CID2 ? " CID2" : "", 301 mext & AC97_MEI_CID1 ? " CID1" : "", 302 mext & AC97_MEI_HANDSET ? " HSET" : "", 303 mext & AC97_MEI_LINE2 ? " LIN2" : "", 304 mext & AC97_MEI_LINE1 ? " LIN1" : ""); 305 val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS); 306 snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 307 val & AC97_MEA_GPIO ? " GPIO" : "", 308 val & AC97_MEA_MREF ? " MREF" : "", 309 val & AC97_MEA_ADC1 ? " ADC1" : "", 310 val & AC97_MEA_DAC1 ? " DAC1" : "", 311 val & AC97_MEA_ADC2 ? " ADC2" : "", 312 val & AC97_MEA_DAC2 ? " DAC2" : "", 313 val & AC97_MEA_HADC ? " HADC" : "", 314 val & AC97_MEA_HDAC ? " HDAC" : "", 315 val & AC97_MEA_PRA ? " PRA(GPIO)" : "", 316 val & AC97_MEA_PRB ? " PRB(res)" : "", 317 val & AC97_MEA_PRC ? " PRC(ADC1)" : "", 318 val & AC97_MEA_PRD ? " PRD(DAC1)" : "", 319 val & AC97_MEA_PRE ? " PRE(ADC2)" : "", 320 val & AC97_MEA_PRF ? " PRF(DAC2)" : "", 321 val & AC97_MEA_PRG ? " PRG(HADC)" : "", 322 val & AC97_MEA_PRH ? " PRH(HDAC)" : ""); 323 if (mext & AC97_MEI_LINE1) { 324 val = snd_ac97_read(ac97, AC97_LINE1_RATE); 325 snd_iprintf(buffer, "Line1 rate : %iHz\n", val); 326 } 327 if (mext & AC97_MEI_LINE2) { 328 val = snd_ac97_read(ac97, AC97_LINE2_RATE); 329 snd_iprintf(buffer, "Line2 rate : %iHz\n", val); 330 } 331 if (mext & AC97_MEI_HANDSET) { 332 val = snd_ac97_read(ac97, AC97_HANDSET_RATE); 333 snd_iprintf(buffer, "Headset rate : %iHz\n", val); 334 } 335 } 336 337 static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 338 { 339 struct snd_ac97 *ac97 = entry->private_data; 340 341 down(&ac97->page_mutex); 297 342 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86 298 343 int idx; 299 344 for (idx = 0; idx < 3; idx++) 300 345 if (ac97->spec.ad18xx.id[idx]) { 301 /* select single codec */ 302 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]); 303 snd_ac97_proc_read_main(ac97, buffer, idx); 304 snd_iprintf(buffer, "\n\n"); 346 /* select single codec */ 347 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 348 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]); 349 snd_ac97_proc_read_main(ac97, buffer, idx); 350 snd_iprintf(buffer, "\n\n"); 305 351 } 306 307 308 352 /* select all codecs */ 353 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 354 309 355 snd_iprintf(buffer, "\nAD18XX configuration\n"); 310 356 snd_iprintf(buffer, "Unchained : 0x%04x,0x%04x,0x%04x\n", … … 318 364 } else { 319 365 snd_ac97_proc_read_main(ac97, buffer, 0); 320 } 321 up(&ac97->page_mutex); 322 } 323 324 static void snd_ac97_proc_regs_read_main(ac97_t *ac97, snd_info_buffer_t * buffer, int subidx) 366 } 367 up(&ac97->page_mutex); 368 } 369 370 #ifdef CONFIG_SND_DEBUG 371 /* direct register write for debugging */ 372 static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 373 { 374 struct snd_ac97 *ac97 = entry->private_data; 375 char line[64]; 376 unsigned int reg, val; 377 down(&ac97->page_mutex); 378 while (!snd_info_get_line(buffer, line, sizeof(line))) { 379 if (sscanf(line, "%x %x", ®, &val) != 2) 380 continue; 381 /* register must be even */ 382 if (reg < 0x80 && (reg & 1) == 0 && val <= 0xffff) 383 snd_ac97_write_cache(ac97, reg, val); 384 } 385 up(&ac97->page_mutex); 386 } 387 #endif 388 389 static void snd_ac97_proc_regs_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx) 325 390 { 326 391 int reg, val; … … 332 397 } 333 398 334 static void snd_ac97_proc_regs_read(s nd_info_entry_t *entry,335 s nd_info_buffer_t *buffer)336 { 337 ac97_t*ac97 = entry->private_data;338 339 399 static void snd_ac97_proc_regs_read(struct snd_info_entry *entry, 400 struct snd_info_buffer *buffer) 401 { 402 struct snd_ac97 *ac97 = entry->private_data; 403 404 down(&ac97->page_mutex); 340 405 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86 341 406 … … 343 408 for (idx = 0; idx < 3; idx++) 344 409 if (ac97->spec.ad18xx.id[idx]) { 345 346 347 410 /* select single codec */ 411 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 412 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]); 348 413 snd_ac97_proc_regs_read_main(ac97, buffer, idx); 349 414 } 350 351 415 /* select all codecs */ 416 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 352 417 } else { 353 418 snd_ac97_proc_regs_read_main(ac97, buffer, 0); 354 } 355 356 } 357 358 void snd_ac97_proc_init( ac97_t* ac97)359 { 360 s nd_info_entry_t*entry;419 } 420 up(&ac97->page_mutex); 421 } 422 423 void snd_ac97_proc_init(struct snd_ac97 * ac97) 424 { 425 struct snd_info_entry *entry; 361 426 char name[32]; 362 427 const char *prefix; … … 365 430 return; 366 431 prefix = ac97_is_audio(ac97) ? "ac97" : "mc97"; 367 432 sprintf(name, "%s#%d-%d", prefix, ac97->addr, ac97->num); 368 433 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) { 369 434 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_read); … … 377 442 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) { 378 443 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_regs_read); 444 #ifdef CONFIG_SND_DEBUG 445 entry->mode |= S_IWUSR; 446 entry->c.text.write_size = 1024; 447 entry->c.text.write = snd_ac97_proc_regs_write; 448 #endif 379 449 if (snd_info_register(entry) < 0) { 380 450 snd_info_free_entry(entry); … … 385 455 } 386 456 387 void snd_ac97_proc_done( ac97_t* ac97)457 void snd_ac97_proc_done(struct snd_ac97 * ac97) 388 458 { 389 459 if (ac97->proc_regs) { … … 397 467 } 398 468 399 void snd_ac97_bus_proc_init( ac97_bus_t* bus)400 { 401 s nd_info_entry_t*entry;469 void snd_ac97_bus_proc_init(struct snd_ac97_bus * bus) 470 { 471 struct snd_info_entry *entry; 402 472 char name[32]; 403 473 … … 413 483 } 414 484 415 void snd_ac97_bus_proc_done( ac97_bus_t* bus)485 void snd_ac97_bus_proc_done(struct snd_ac97_bus * bus) 416 486 { 417 487 if (bus->proc) { -
GPL/trunk/alsa-kernel/pci/ac97/ak4531_codec.c
r32 r72 31 31 MODULE_LICENSE("GPL"); 32 32 33 static void snd_ak4531_proc_init(snd_card_t * card, ak4531_t * ak4531); 33 #ifdef CONFIG_PROC_FS 34 static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531); 35 #else 36 #define snd_ak4531_proc_init(card,ak) 37 #endif 34 38 35 39 /* … … 39 43 #if 0 40 44 41 static void snd_ak4531_dump( ak4531_t*ak4531)45 static void snd_ak4531_dump(struct snd_ak4531 *ak4531) 42 46 { 43 47 int idx; … … 52 56 * 53 57 */ 58 54 59 #define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \ 55 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname,xindex, \56 0, 0,snd_ak4531_info_single, \57 snd_ak4531_get_single,snd_ak4531_put_single, \58 reg | (shift << 16) | (mask << 24) | (invert << 22) }59 60 static int snd_ak4531_info_single(s nd_kcontrol_t * kcontrol, snd_ctl_elem_info_t *uinfo)60 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 61 .info = snd_ak4531_info_single, \ 62 .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \ 63 .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) } 64 65 static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 61 66 { 62 67 int mask = (kcontrol->private_value >> 24) & 0xff; … … 69 74 } 70 75 71 static int snd_ak4531_get_single(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)72 { 73 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);76 static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 77 { 78 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 74 79 int reg = kcontrol->private_value & 0xff; 75 80 int shift = (kcontrol->private_value >> 16) & 0x07; … … 78 83 int val; 79 84 80 81 82 85 down(&ak4531->reg_mutex); 86 val = (ak4531->regs[reg] >> shift) & mask; 87 up(&ak4531->reg_mutex); 83 88 if (invert) { 84 89 val = mask - val; … … 86 91 ucontrol->value.integer.value[0] = val; 87 92 return 0; 88 } 89 90 static int snd_ak4531_put_single(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)91 { 92 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);93 } 94 95 static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 96 { 97 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 93 98 int reg = kcontrol->private_value & 0xff; 94 99 int shift = (kcontrol->private_value >> 16) & 0x07; … … 102 107 val = mask - val; 103 108 } 104 105 109 val <<= shift; 110 down(&ak4531->reg_mutex); 106 111 val = (ak4531->regs[reg] & ~(mask << shift)) | val; 107 112 change = val != ak4531->regs[reg]; 108 109 113 ak4531->write(ak4531, reg, ak4531->regs[reg] = val); 114 up(&ak4531->reg_mutex); 110 115 return change; 111 } 116 } 112 117 113 118 #define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \ 114 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname,xindex, \115 0, 0,snd_ak4531_info_double, \116 snd_ak4531_get_double,snd_ak4531_put_double, \117 left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }118 119 static int snd_ak4531_info_double(s nd_kcontrol_t * kcontrol, snd_ctl_elem_info_t *uinfo)119 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 120 .info = snd_ak4531_info_double, \ 121 .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \ 122 .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) } 123 124 static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 120 125 { 121 126 int mask = (kcontrol->private_value >> 24) & 0xff; … … 128 133 } 129 134 130 static int snd_ak4531_get_double(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)131 { 132 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);135 static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 136 { 137 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 133 138 int left_reg = kcontrol->private_value & 0xff; 134 139 int right_reg = (kcontrol->private_value >> 8) & 0xff; … … 139 144 int left, right; 140 145 141 142 146 down(&ak4531->reg_mutex); 147 left = (ak4531->regs[left_reg] >> left_shift) & mask; 143 148 right = (ak4531->regs[right_reg] >> right_shift) & mask; 144 145 149 up(&ak4531->reg_mutex); 150 if (invert) { 146 151 left = mask - left; 147 152 right = mask - right; … … 150 155 ucontrol->value.integer.value[1] = right; 151 156 return 0; 152 } 153 154 static int snd_ak4531_put_double(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)155 { 156 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);157 } 158 159 static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 160 { 161 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 157 162 int left_reg = kcontrol->private_value & 0xff; 158 163 int right_reg = (kcontrol->private_value >> 8) & 0xff; … … 171 176 } 172 177 left <<= left_shift; 173 174 178 right <<= right_shift; 179 down(&ak4531->reg_mutex); 175 180 if (left_reg == right_reg) { 176 181 left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right; … … 184 189 ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right); 185 190 } 186 187 188 } 191 up(&ak4531->reg_mutex); 192 return change; 193 } 189 194 190 195 #define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \ 191 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname,xindex, \192 0, 0,snd_ak4531_info_input_sw, \193 snd_ak4531_get_input_sw,snd_ak4531_put_input_sw, \194 reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }195 196 static int snd_ak4531_info_input_sw(s nd_kcontrol_t * kcontrol, snd_ctl_elem_info_t *uinfo)196 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 197 .info = snd_ak4531_info_input_sw, \ 198 .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \ 199 .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) } 200 201 static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 197 202 { 198 203 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; … … 203 208 } 204 209 205 static int snd_ak4531_get_input_sw(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)206 { 207 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);210 static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 211 { 212 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 208 213 int reg1 = kcontrol->private_value & 0xff; 209 214 int reg2 = (kcontrol->private_value >> 8) & 0xff; … … 211 216 int right_shift = (kcontrol->private_value >> 24) & 0x0f; 212 217 213 218 down(&ak4531->reg_mutex); 214 219 ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1; 215 220 ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1; 216 221 ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1; 217 222 ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1; 218 219 220 } 221 222 static int snd_ak4531_put_input_sw(s nd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)223 { 224 ak4531_t*ak4531 = snd_kcontrol_chip(kcontrol);223 up(&ak4531->reg_mutex); 224 return 0; 225 } 226 227 static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 228 { 229 struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); 225 230 int reg1 = kcontrol->private_value & 0xff; 226 231 int reg2 = (kcontrol->private_value >> 8) & 0xff; … … 230 235 int val1, val2; 231 236 232 233 237 down(&ak4531->reg_mutex); 238 val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift)); 234 239 val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift)); 235 240 val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift; … … 240 245 ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1); 241 246 ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2); 242 up(&ak4531->reg_mutex); 243 return change; 244 } 245 246 #define AK4531_CONTROLS (sizeof(snd_ak4531_controls)/sizeof(snd_kcontrol_new_t)) 247 248 static snd_kcontrol_new_t snd_ak4531_controls[] = { 247 up(&ak4531->reg_mutex); 248 return change; 249 } 250 251 static struct snd_kcontrol_new snd_ak4531_controls[] = { 249 252 250 253 AK4531_DOUBLE("Master Playback Switch", 0, AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1), … … 277 280 AK4531_DOUBLE("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1), 278 281 AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0), 279 AK4531_INPUT_SW("Aux InputRoute", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),282 AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3), 280 283 281 284 AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1), … … 302 305 }; 303 306 304 static int snd_ak4531_free( ak4531_t*ak4531)307 static int snd_ak4531_free(struct snd_ak4531 *ak4531) 305 308 { 306 309 if (ak4531) { 307 310 if (ak4531->private_free) 308 309 310 } 311 return 0; 312 } 313 314 static int snd_ak4531_dev_free(s nd_device_t*device)315 { 316 ak4531_t*ak4531 = device->device_data;317 311 ak4531->private_free(ak4531); 312 kfree(ak4531); 313 } 314 return 0; 315 } 316 317 static int snd_ak4531_dev_free(struct snd_device *device) 318 { 319 struct snd_ak4531 *ak4531 = device->device_data; 320 return snd_ak4531_free(ak4531); 318 321 } 319 322 … … 347 350 }; 348 351 349 int snd_ak4531_mixer(snd_card_t * card, ak4531_t * _ak4531, ak4531_t ** rak4531) 352 int snd_ak4531_mixer(struct snd_card *card, struct snd_ak4531 *_ak4531, 353 struct snd_ak4531 **rak4531) 350 354 { 351 355 unsigned int idx; 352 356 int err; 353 ak4531_t *ak4531;354 static snd_device_ops_tops = {355 snd_ak4531_dev_free, NULL, NULL, NULL 357 struct snd_ak4531 *ak4531; 358 static struct snd_device_ops ops = { 359 .dev_free = snd_ak4531_dev_free, 356 360 }; 357 361 358 362 snd_assert(rak4531 != NULL, return -EINVAL); 359 363 *rak4531 = NULL; 360 361 ak4531 = kcalloc(1,sizeof(*ak4531), GFP_KERNEL);364 snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL); 365 ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL); 362 366 if (ak4531 == NULL) 363 367 return -ENOMEM; 364 365 368 *ak4531 = *_ak4531; 369 init_MUTEX(&ak4531->reg_mutex); 366 370 if ((err = snd_component_add(card, "AK4531")) < 0) { 367 371 snd_ak4531_free(ak4531); … … 372 376 udelay(100); 373 377 ak4531->write(ak4531, AK4531_CLOCK, 0x00); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */ 374 for (idx = 0; idx < 0x19; idx++) {378 for (idx = 0; idx <= 0x19; idx++) { 375 379 if (idx == AK4531_RESET || idx == AK4531_CLOCK) 376 380 continue; 377 381 ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]); /* recording source is mixer */ 378 382 } 379 for (idx = 0; idx < A K4531_CONTROLS; idx++) {383 for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) { 380 384 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) { 381 385 snd_ak4531_free(ak4531); … … 384 388 } 385 389 snd_ak4531_proc_init(card, ak4531); 386 if ((err = snd_device_new(card, SNDRV_DEV_ LOWLEVEL, ak4531, &ops)) < 0) {390 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) { 387 391 snd_ak4531_free(ak4531); 388 392 return err; … … 397 401 398 402 /* 399 400 */ 401 402 static void snd_ak4531_proc_read(snd_info_entry_t *entry, 403 snd_info_buffer_t * buffer) 404 { 405 ak4531_t *ak4531 = entry->private_data; 403 * power management 404 */ 405 #ifdef CONFIG_PM 406 void snd_ak4531_suspend(struct snd_ak4531 *ak4531) 407 { 408 /* mute */ 409 ak4531->write(ak4531, AK4531_LMASTER, 0x9f); 410 ak4531->write(ak4531, AK4531_RMASTER, 0x9f); 411 /* powerdown */ 412 ak4531->write(ak4531, AK4531_RESET, 0x01); 413 } 414 415 void snd_ak4531_resume(struct snd_ak4531 *ak4531) 416 { 417 int idx; 418 419 /* initialize */ 420 ak4531->write(ak4531, AK4531_RESET, 0x03); 421 udelay(100); 422 ak4531->write(ak4531, AK4531_CLOCK, 0x00); 423 /* restore mixer registers */ 424 for (idx = 0; idx <= 0x19; idx++) { 425 if (idx == AK4531_RESET || idx == AK4531_CLOCK) 426 continue; 427 ak4531->write(ak4531, idx, ak4531->regs[idx]); 428 } 429 } 430 #endif 431 432 #ifdef CONFIG_PROC_FS 433 /* 434 * /proc interface 435 */ 436 437 static void snd_ak4531_proc_read(struct snd_info_entry *entry, 438 struct snd_info_buffer *buffer) 439 { 440 struct snd_ak4531 *ak4531 = entry->private_data; 406 441 407 442 snd_iprintf(buffer, "Asahi Kasei AK4531\n\n"); … … 412 447 } 413 448 414 static void snd_ak4531_proc_init(s nd_card_t * card, ak4531_t *ak4531)415 { 416 s nd_info_entry_t*entry;449 static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531) 450 { 451 struct snd_info_entry *entry; 417 452 418 453 if (! snd_card_proc_new(card, "ak4531", &entry)) 419 454 snd_info_set_text_ops(entry, ak4531, 1024, snd_ak4531_proc_read); 420 455 } 456 #endif 421 457 422 458 EXPORT_SYMBOL(snd_ak4531_mixer); 459 #ifdef CONFIG_PM 460 EXPORT_SYMBOL(snd_ak4531_suspend); 461 EXPORT_SYMBOL(snd_ak4531_resume); 462 #endif 423 463 424 464 /*
Note:
See TracChangeset
for help on using the changeset viewer.