Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'topic/hda' into for-linus

+1614 -1389
+1 -1
sound/pci/hda/Makefile
··· 1 1 snd-hda-intel-objs := hda_intel.o 2 2 3 - snd-hda-codec-y := hda_codec.o hda_jack.o 3 + snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o 4 4 snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 5 5 snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 6 6 snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
+760
sound/pci/hda/hda_auto_parser.c
··· 1 + /* 2 + * BIOS auto-parser helper functions for HD-audio 3 + * 4 + * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de> 5 + * 6 + * This driver is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #include <linux/slab.h> 13 + #include <linux/export.h> 14 + #include <sound/core.h> 15 + #include "hda_codec.h" 16 + #include "hda_local.h" 17 + #include "hda_auto_parser.h" 18 + 19 + #define SFX "hda_codec: " 20 + 21 + /* 22 + * Helper for automatic pin configuration 23 + */ 24 + 25 + static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list) 26 + { 27 + for (; *list; list++) 28 + if (*list == nid) 29 + return 1; 30 + return 0; 31 + } 32 + 33 + 34 + /* 35 + * Sort an associated group of pins according to their sequence numbers. 36 + */ 37 + static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences, 38 + int num_pins) 39 + { 40 + int i, j; 41 + short seq; 42 + hda_nid_t nid; 43 + 44 + for (i = 0; i < num_pins; i++) { 45 + for (j = i + 1; j < num_pins; j++) { 46 + if (sequences[i] > sequences[j]) { 47 + seq = sequences[i]; 48 + sequences[i] = sequences[j]; 49 + sequences[j] = seq; 50 + nid = pins[i]; 51 + pins[i] = pins[j]; 52 + pins[j] = nid; 53 + } 54 + } 55 + } 56 + } 57 + 58 + 59 + /* add the found input-pin to the cfg->inputs[] table */ 60 + static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid, 61 + int type) 62 + { 63 + if (cfg->num_inputs < AUTO_CFG_MAX_INS) { 64 + cfg->inputs[cfg->num_inputs].pin = nid; 65 + cfg->inputs[cfg->num_inputs].type = type; 66 + cfg->num_inputs++; 67 + } 68 + } 69 + 70 + /* sort inputs in the order of AUTO_PIN_* type */ 71 + static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg) 72 + { 73 + int i, j; 74 + 75 + for (i = 0; i < cfg->num_inputs; i++) { 76 + for (j = i + 1; j < cfg->num_inputs; j++) { 77 + if (cfg->inputs[i].type > cfg->inputs[j].type) { 78 + struct auto_pin_cfg_item tmp; 79 + tmp = cfg->inputs[i]; 80 + cfg->inputs[i] = cfg->inputs[j]; 81 + cfg->inputs[j] = tmp; 82 + } 83 + } 84 + } 85 + } 86 + 87 + /* Reorder the surround channels 88 + * ALSA sequence is front/surr/clfe/side 89 + * HDA sequence is: 90 + * 4-ch: front/surr => OK as it is 91 + * 6-ch: front/clfe/surr 92 + * 8-ch: front/clfe/rear/side|fc 93 + */ 94 + static void reorder_outputs(unsigned int nums, hda_nid_t *pins) 95 + { 96 + hda_nid_t nid; 97 + 98 + switch (nums) { 99 + case 3: 100 + case 4: 101 + nid = pins[1]; 102 + pins[1] = pins[2]; 103 + pins[2] = nid; 104 + break; 105 + } 106 + } 107 + 108 + /* 109 + * Parse all pin widgets and store the useful pin nids to cfg 110 + * 111 + * The number of line-outs or any primary output is stored in line_outs, 112 + * and the corresponding output pins are assigned to line_out_pins[], 113 + * in the order of front, rear, CLFE, side, ... 114 + * 115 + * If more extra outputs (speaker and headphone) are found, the pins are 116 + * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack 117 + * is detected, one of speaker of HP pins is assigned as the primary 118 + * output, i.e. to line_out_pins[0]. So, line_outs is always positive 119 + * if any analog output exists. 120 + * 121 + * The analog input pins are assigned to inputs array. 122 + * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, 123 + * respectively. 124 + */ 125 + int snd_hda_parse_pin_defcfg(struct hda_codec *codec, 126 + struct auto_pin_cfg *cfg, 127 + const hda_nid_t *ignore_nids, 128 + unsigned int cond_flags) 129 + { 130 + hda_nid_t nid, end_nid; 131 + short seq, assoc_line_out; 132 + short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; 133 + short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; 134 + short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; 135 + int i; 136 + 137 + memset(cfg, 0, sizeof(*cfg)); 138 + 139 + memset(sequences_line_out, 0, sizeof(sequences_line_out)); 140 + memset(sequences_speaker, 0, sizeof(sequences_speaker)); 141 + memset(sequences_hp, 0, sizeof(sequences_hp)); 142 + assoc_line_out = 0; 143 + 144 + codec->ignore_misc_bit = true; 145 + end_nid = codec->start_nid + codec->num_nodes; 146 + for (nid = codec->start_nid; nid < end_nid; nid++) { 147 + unsigned int wid_caps = get_wcaps(codec, nid); 148 + unsigned int wid_type = get_wcaps_type(wid_caps); 149 + unsigned int def_conf; 150 + short assoc, loc, conn, dev; 151 + 152 + /* read all default configuration for pin complex */ 153 + if (wid_type != AC_WID_PIN) 154 + continue; 155 + /* ignore the given nids (e.g. pc-beep returns error) */ 156 + if (ignore_nids && is_in_nid_list(nid, ignore_nids)) 157 + continue; 158 + 159 + def_conf = snd_hda_codec_get_pincfg(codec, nid); 160 + if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & 161 + AC_DEFCFG_MISC_NO_PRESENCE)) 162 + codec->ignore_misc_bit = false; 163 + conn = get_defcfg_connect(def_conf); 164 + if (conn == AC_JACK_PORT_NONE) 165 + continue; 166 + loc = get_defcfg_location(def_conf); 167 + dev = get_defcfg_device(def_conf); 168 + 169 + /* workaround for buggy BIOS setups */ 170 + if (dev == AC_JACK_LINE_OUT) { 171 + if (conn == AC_JACK_PORT_FIXED) 172 + dev = AC_JACK_SPEAKER; 173 + } 174 + 175 + switch (dev) { 176 + case AC_JACK_LINE_OUT: 177 + seq = get_defcfg_sequence(def_conf); 178 + assoc = get_defcfg_association(def_conf); 179 + 180 + if (!(wid_caps & AC_WCAP_STEREO)) 181 + if (!cfg->mono_out_pin) 182 + cfg->mono_out_pin = nid; 183 + if (!assoc) 184 + continue; 185 + if (!assoc_line_out) 186 + assoc_line_out = assoc; 187 + else if (assoc_line_out != assoc) 188 + continue; 189 + if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) 190 + continue; 191 + cfg->line_out_pins[cfg->line_outs] = nid; 192 + sequences_line_out[cfg->line_outs] = seq; 193 + cfg->line_outs++; 194 + break; 195 + case AC_JACK_SPEAKER: 196 + seq = get_defcfg_sequence(def_conf); 197 + assoc = get_defcfg_association(def_conf); 198 + if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) 199 + continue; 200 + cfg->speaker_pins[cfg->speaker_outs] = nid; 201 + sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq; 202 + cfg->speaker_outs++; 203 + break; 204 + case AC_JACK_HP_OUT: 205 + seq = get_defcfg_sequence(def_conf); 206 + assoc = get_defcfg_association(def_conf); 207 + if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) 208 + continue; 209 + cfg->hp_pins[cfg->hp_outs] = nid; 210 + sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; 211 + cfg->hp_outs++; 212 + break; 213 + case AC_JACK_MIC_IN: 214 + add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC); 215 + break; 216 + case AC_JACK_LINE_IN: 217 + add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN); 218 + break; 219 + case AC_JACK_CD: 220 + add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD); 221 + break; 222 + case AC_JACK_AUX: 223 + add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX); 224 + break; 225 + case AC_JACK_SPDIF_OUT: 226 + case AC_JACK_DIG_OTHER_OUT: 227 + if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) 228 + continue; 229 + cfg->dig_out_pins[cfg->dig_outs] = nid; 230 + cfg->dig_out_type[cfg->dig_outs] = 231 + (loc == AC_JACK_LOC_HDMI) ? 232 + HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; 233 + cfg->dig_outs++; 234 + break; 235 + case AC_JACK_SPDIF_IN: 236 + case AC_JACK_DIG_OTHER_IN: 237 + cfg->dig_in_pin = nid; 238 + if (loc == AC_JACK_LOC_HDMI) 239 + cfg->dig_in_type = HDA_PCM_TYPE_HDMI; 240 + else 241 + cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; 242 + break; 243 + } 244 + } 245 + 246 + /* FIX-UP: 247 + * If no line-out is defined but multiple HPs are found, 248 + * some of them might be the real line-outs. 249 + */ 250 + if (!cfg->line_outs && cfg->hp_outs > 1 && 251 + !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) { 252 + int i = 0; 253 + while (i < cfg->hp_outs) { 254 + /* The real HPs should have the sequence 0x0f */ 255 + if ((sequences_hp[i] & 0x0f) == 0x0f) { 256 + i++; 257 + continue; 258 + } 259 + /* Move it to the line-out table */ 260 + cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i]; 261 + sequences_line_out[cfg->line_outs] = sequences_hp[i]; 262 + cfg->line_outs++; 263 + cfg->hp_outs--; 264 + memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1, 265 + sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i)); 266 + memmove(sequences_hp + i, sequences_hp + i + 1, 267 + sizeof(sequences_hp[0]) * (cfg->hp_outs - i)); 268 + } 269 + memset(cfg->hp_pins + cfg->hp_outs, 0, 270 + sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); 271 + if (!cfg->hp_outs) 272 + cfg->line_out_type = AUTO_PIN_HP_OUT; 273 + 274 + } 275 + 276 + /* sort by sequence */ 277 + sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, 278 + cfg->line_outs); 279 + sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, 280 + cfg->speaker_outs); 281 + sort_pins_by_sequence(cfg->hp_pins, sequences_hp, 282 + cfg->hp_outs); 283 + 284 + /* 285 + * FIX-UP: if no line-outs are detected, try to use speaker or HP pin 286 + * as a primary output 287 + */ 288 + if (!cfg->line_outs && 289 + !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) { 290 + if (cfg->speaker_outs) { 291 + cfg->line_outs = cfg->speaker_outs; 292 + memcpy(cfg->line_out_pins, cfg->speaker_pins, 293 + sizeof(cfg->speaker_pins)); 294 + cfg->speaker_outs = 0; 295 + memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); 296 + cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; 297 + } else if (cfg->hp_outs) { 298 + cfg->line_outs = cfg->hp_outs; 299 + memcpy(cfg->line_out_pins, cfg->hp_pins, 300 + sizeof(cfg->hp_pins)); 301 + cfg->hp_outs = 0; 302 + memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); 303 + cfg->line_out_type = AUTO_PIN_HP_OUT; 304 + } 305 + } 306 + 307 + reorder_outputs(cfg->line_outs, cfg->line_out_pins); 308 + reorder_outputs(cfg->hp_outs, cfg->hp_pins); 309 + reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); 310 + 311 + sort_autocfg_input_pins(cfg); 312 + 313 + /* 314 + * debug prints of the parsed results 315 + */ 316 + snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", 317 + cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], 318 + cfg->line_out_pins[2], cfg->line_out_pins[3], 319 + cfg->line_out_pins[4], 320 + cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : 321 + (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? 322 + "speaker" : "line")); 323 + snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 324 + cfg->speaker_outs, cfg->speaker_pins[0], 325 + cfg->speaker_pins[1], cfg->speaker_pins[2], 326 + cfg->speaker_pins[3], cfg->speaker_pins[4]); 327 + snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 328 + cfg->hp_outs, cfg->hp_pins[0], 329 + cfg->hp_pins[1], cfg->hp_pins[2], 330 + cfg->hp_pins[3], cfg->hp_pins[4]); 331 + snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); 332 + if (cfg->dig_outs) 333 + snd_printd(" dig-out=0x%x/0x%x\n", 334 + cfg->dig_out_pins[0], cfg->dig_out_pins[1]); 335 + snd_printd(" inputs:"); 336 + for (i = 0; i < cfg->num_inputs; i++) { 337 + snd_printd(" %s=0x%x", 338 + hda_get_autocfg_input_label(codec, cfg, i), 339 + cfg->inputs[i].pin); 340 + } 341 + snd_printd("\n"); 342 + if (cfg->dig_in_pin) 343 + snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); 344 + 345 + return 0; 346 + } 347 + EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg); 348 + 349 + int snd_hda_get_input_pin_attr(unsigned int def_conf) 350 + { 351 + unsigned int loc = get_defcfg_location(def_conf); 352 + unsigned int conn = get_defcfg_connect(def_conf); 353 + if (conn == AC_JACK_PORT_NONE) 354 + return INPUT_PIN_ATTR_UNUSED; 355 + /* Windows may claim the internal mic to be BOTH, too */ 356 + if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) 357 + return INPUT_PIN_ATTR_INT; 358 + if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) 359 + return INPUT_PIN_ATTR_INT; 360 + if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) 361 + return INPUT_PIN_ATTR_DOCK; 362 + if (loc == AC_JACK_LOC_REAR) 363 + return INPUT_PIN_ATTR_REAR; 364 + if (loc == AC_JACK_LOC_FRONT) 365 + return INPUT_PIN_ATTR_FRONT; 366 + return INPUT_PIN_ATTR_NORMAL; 367 + } 368 + EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr); 369 + 370 + /** 371 + * hda_get_input_pin_label - Give a label for the given input pin 372 + * 373 + * When check_location is true, the function checks the pin location 374 + * for mic and line-in pins, and set an appropriate prefix like "Front", 375 + * "Rear", "Internal". 376 + */ 377 + 378 + static const char *hda_get_input_pin_label(struct hda_codec *codec, 379 + hda_nid_t pin, bool check_location) 380 + { 381 + unsigned int def_conf; 382 + static const char * const mic_names[] = { 383 + "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", 384 + }; 385 + int attr; 386 + 387 + def_conf = snd_hda_codec_get_pincfg(codec, pin); 388 + 389 + switch (get_defcfg_device(def_conf)) { 390 + case AC_JACK_MIC_IN: 391 + if (!check_location) 392 + return "Mic"; 393 + attr = snd_hda_get_input_pin_attr(def_conf); 394 + if (!attr) 395 + return "None"; 396 + return mic_names[attr - 1]; 397 + case AC_JACK_LINE_IN: 398 + if (!check_location) 399 + return "Line"; 400 + attr = snd_hda_get_input_pin_attr(def_conf); 401 + if (!attr) 402 + return "None"; 403 + if (attr == INPUT_PIN_ATTR_DOCK) 404 + return "Dock Line"; 405 + return "Line"; 406 + case AC_JACK_AUX: 407 + return "Aux"; 408 + case AC_JACK_CD: 409 + return "CD"; 410 + case AC_JACK_SPDIF_IN: 411 + return "SPDIF In"; 412 + case AC_JACK_DIG_OTHER_IN: 413 + return "Digital In"; 414 + default: 415 + return "Misc"; 416 + } 417 + } 418 + 419 + /* Check whether the location prefix needs to be added to the label. 420 + * If all mic-jacks are in the same location (e.g. rear panel), we don't 421 + * have to put "Front" prefix to each label. In such a case, returns false. 422 + */ 423 + static int check_mic_location_need(struct hda_codec *codec, 424 + const struct auto_pin_cfg *cfg, 425 + int input) 426 + { 427 + unsigned int defc; 428 + int i, attr, attr2; 429 + 430 + defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); 431 + attr = snd_hda_get_input_pin_attr(defc); 432 + /* for internal or docking mics, we need locations */ 433 + if (attr <= INPUT_PIN_ATTR_NORMAL) 434 + return 1; 435 + 436 + attr = 0; 437 + for (i = 0; i < cfg->num_inputs; i++) { 438 + defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); 439 + attr2 = snd_hda_get_input_pin_attr(defc); 440 + if (attr2 >= INPUT_PIN_ATTR_NORMAL) { 441 + if (attr && attr != attr2) 442 + return 1; /* different locations found */ 443 + attr = attr2; 444 + } 445 + } 446 + return 0; 447 + } 448 + 449 + /** 450 + * hda_get_autocfg_input_label - Get a label for the given input 451 + * 452 + * Get a label for the given input pin defined by the autocfg item. 453 + * Unlike hda_get_input_pin_label(), this function checks all inputs 454 + * defined in autocfg and avoids the redundant mic/line prefix as much as 455 + * possible. 456 + */ 457 + const char *hda_get_autocfg_input_label(struct hda_codec *codec, 458 + const struct auto_pin_cfg *cfg, 459 + int input) 460 + { 461 + int type = cfg->inputs[input].type; 462 + int has_multiple_pins = 0; 463 + 464 + if ((input > 0 && cfg->inputs[input - 1].type == type) || 465 + (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) 466 + has_multiple_pins = 1; 467 + if (has_multiple_pins && type == AUTO_PIN_MIC) 468 + has_multiple_pins &= check_mic_location_need(codec, cfg, input); 469 + return hda_get_input_pin_label(codec, cfg->inputs[input].pin, 470 + has_multiple_pins); 471 + } 472 + EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); 473 + 474 + /* return the position of NID in the list, or -1 if not found */ 475 + static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 476 + { 477 + int i; 478 + for (i = 0; i < nums; i++) 479 + if (list[i] == nid) 480 + return i; 481 + return -1; 482 + } 483 + 484 + /* get a unique suffix or an index number */ 485 + static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, 486 + int num_pins, int *indexp) 487 + { 488 + static const char * const channel_sfx[] = { 489 + " Front", " Surround", " CLFE", " Side" 490 + }; 491 + int i; 492 + 493 + i = find_idx_in_nid_list(nid, pins, num_pins); 494 + if (i < 0) 495 + return NULL; 496 + if (num_pins == 1) 497 + return ""; 498 + if (num_pins > ARRAY_SIZE(channel_sfx)) { 499 + if (indexp) 500 + *indexp = i; 501 + return ""; 502 + } 503 + return channel_sfx[i]; 504 + } 505 + 506 + static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid, 507 + const struct auto_pin_cfg *cfg, 508 + const char *name, char *label, int maxlen, 509 + int *indexp) 510 + { 511 + unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); 512 + int attr = snd_hda_get_input_pin_attr(def_conf); 513 + const char *pfx = "", *sfx = ""; 514 + 515 + /* handle as a speaker if it's a fixed line-out */ 516 + if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT) 517 + name = "Speaker"; 518 + /* check the location */ 519 + switch (attr) { 520 + case INPUT_PIN_ATTR_DOCK: 521 + pfx = "Dock "; 522 + break; 523 + case INPUT_PIN_ATTR_FRONT: 524 + pfx = "Front "; 525 + break; 526 + } 527 + if (cfg) { 528 + /* try to give a unique suffix if needed */ 529 + sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, 530 + indexp); 531 + if (!sfx) 532 + sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, 533 + indexp); 534 + if (!sfx) { 535 + /* don't add channel suffix for Headphone controls */ 536 + int idx = find_idx_in_nid_list(nid, cfg->hp_pins, 537 + cfg->hp_outs); 538 + if (idx >= 0) 539 + *indexp = idx; 540 + sfx = ""; 541 + } 542 + } 543 + snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); 544 + return 1; 545 + } 546 + 547 + /** 548 + * snd_hda_get_pin_label - Get a label for the given I/O pin 549 + * 550 + * Get a label for the given pin. This function works for both input and 551 + * output pins. When @cfg is given as non-NULL, the function tries to get 552 + * an optimized label using hda_get_autocfg_input_label(). 553 + * 554 + * This function tries to give a unique label string for the pin as much as 555 + * possible. For example, when the multiple line-outs are present, it adds 556 + * the channel suffix like "Front", "Surround", etc (only when @cfg is given). 557 + * If no unique name with a suffix is available and @indexp is non-NULL, the 558 + * index number is stored in the pointer. 559 + */ 560 + int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, 561 + const struct auto_pin_cfg *cfg, 562 + char *label, int maxlen, int *indexp) 563 + { 564 + unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); 565 + const char *name = NULL; 566 + int i; 567 + 568 + if (indexp) 569 + *indexp = 0; 570 + if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 571 + return 0; 572 + 573 + switch (get_defcfg_device(def_conf)) { 574 + case AC_JACK_LINE_OUT: 575 + return fill_audio_out_name(codec, nid, cfg, "Line Out", 576 + label, maxlen, indexp); 577 + case AC_JACK_SPEAKER: 578 + return fill_audio_out_name(codec, nid, cfg, "Speaker", 579 + label, maxlen, indexp); 580 + case AC_JACK_HP_OUT: 581 + return fill_audio_out_name(codec, nid, cfg, "Headphone", 582 + label, maxlen, indexp); 583 + case AC_JACK_SPDIF_OUT: 584 + case AC_JACK_DIG_OTHER_OUT: 585 + if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI) 586 + name = "HDMI"; 587 + else 588 + name = "SPDIF"; 589 + if (cfg && indexp) { 590 + i = find_idx_in_nid_list(nid, cfg->dig_out_pins, 591 + cfg->dig_outs); 592 + if (i >= 0) 593 + *indexp = i; 594 + } 595 + break; 596 + default: 597 + if (cfg) { 598 + for (i = 0; i < cfg->num_inputs; i++) { 599 + if (cfg->inputs[i].pin != nid) 600 + continue; 601 + name = hda_get_autocfg_input_label(codec, cfg, i); 602 + if (name) 603 + break; 604 + } 605 + } 606 + if (!name) 607 + name = hda_get_input_pin_label(codec, nid, true); 608 + break; 609 + } 610 + if (!name) 611 + return 0; 612 + strlcpy(label, name, maxlen); 613 + return 1; 614 + } 615 + EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); 616 + 617 + int snd_hda_gen_add_verbs(struct hda_gen_spec *spec, 618 + const struct hda_verb *list) 619 + { 620 + const struct hda_verb **v; 621 + snd_array_init(&spec->verbs, sizeof(struct hda_verb *), 8); 622 + v = snd_array_new(&spec->verbs); 623 + if (!v) 624 + return -ENOMEM; 625 + *v = list; 626 + return 0; 627 + } 628 + EXPORT_SYMBOL_HDA(snd_hda_gen_add_verbs); 629 + 630 + void snd_hda_gen_apply_verbs(struct hda_codec *codec) 631 + { 632 + struct hda_gen_spec *spec = codec->spec; 633 + int i; 634 + for (i = 0; i < spec->verbs.used; i++) { 635 + struct hda_verb **v = snd_array_elem(&spec->verbs, i); 636 + snd_hda_sequence_write(codec, *v); 637 + } 638 + } 639 + EXPORT_SYMBOL_HDA(snd_hda_gen_apply_verbs); 640 + 641 + void snd_hda_apply_pincfgs(struct hda_codec *codec, 642 + const struct hda_pintbl *cfg) 643 + { 644 + for (; cfg->nid; cfg++) 645 + snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 646 + } 647 + EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs); 648 + 649 + void snd_hda_apply_fixup(struct hda_codec *codec, int action) 650 + { 651 + struct hda_gen_spec *spec = codec->spec; 652 + int id = spec->fixup_id; 653 + #ifdef CONFIG_SND_DEBUG_VERBOSE 654 + const char *modelname = spec->fixup_name; 655 + #endif 656 + int depth = 0; 657 + 658 + if (!spec->fixup_list) 659 + return; 660 + 661 + while (id >= 0) { 662 + const struct hda_fixup *fix = spec->fixup_list + id; 663 + 664 + switch (fix->type) { 665 + case HDA_FIXUP_PINS: 666 + if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) 667 + break; 668 + snd_printdd(KERN_INFO SFX 669 + "%s: Apply pincfg for %s\n", 670 + codec->chip_name, modelname); 671 + snd_hda_apply_pincfgs(codec, fix->v.pins); 672 + break; 673 + case HDA_FIXUP_VERBS: 674 + if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) 675 + break; 676 + snd_printdd(KERN_INFO SFX 677 + "%s: Apply fix-verbs for %s\n", 678 + codec->chip_name, modelname); 679 + snd_hda_gen_add_verbs(codec->spec, fix->v.verbs); 680 + break; 681 + case HDA_FIXUP_FUNC: 682 + if (!fix->v.func) 683 + break; 684 + snd_printdd(KERN_INFO SFX 685 + "%s: Apply fix-func for %s\n", 686 + codec->chip_name, modelname); 687 + fix->v.func(codec, fix, action); 688 + break; 689 + default: 690 + snd_printk(KERN_ERR SFX 691 + "%s: Invalid fixup type %d\n", 692 + codec->chip_name, fix->type); 693 + break; 694 + } 695 + if (!fix->chained) 696 + break; 697 + if (++depth > 10) 698 + break; 699 + id = fix->chain_id; 700 + } 701 + } 702 + EXPORT_SYMBOL_HDA(snd_hda_apply_fixup); 703 + 704 + void snd_hda_pick_fixup(struct hda_codec *codec, 705 + const struct hda_model_fixup *models, 706 + const struct snd_pci_quirk *quirk, 707 + const struct hda_fixup *fixlist) 708 + { 709 + struct hda_gen_spec *spec = codec->spec; 710 + const struct snd_pci_quirk *q; 711 + int id = -1; 712 + const char *name = NULL; 713 + 714 + /* when model=nofixup is given, don't pick up any fixups */ 715 + if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { 716 + spec->fixup_list = NULL; 717 + spec->fixup_id = -1; 718 + return; 719 + } 720 + 721 + if (codec->modelname && models) { 722 + while (models->name) { 723 + if (!strcmp(codec->modelname, models->name)) { 724 + id = models->id; 725 + name = models->name; 726 + break; 727 + } 728 + models++; 729 + } 730 + } 731 + if (id < 0) { 732 + q = snd_pci_quirk_lookup(codec->bus->pci, quirk); 733 + if (q) { 734 + id = q->value; 735 + #ifdef CONFIG_SND_DEBUG_VERBOSE 736 + name = q->name; 737 + #endif 738 + } 739 + } 740 + if (id < 0) { 741 + for (q = quirk; q->subvendor; q++) { 742 + unsigned int vendorid = 743 + q->subdevice | (q->subvendor << 16); 744 + if (vendorid == codec->subsystem_id) { 745 + id = q->value; 746 + #ifdef CONFIG_SND_DEBUG_VERBOSE 747 + name = q->name; 748 + #endif 749 + break; 750 + } 751 + } 752 + } 753 + 754 + spec->fixup_id = id; 755 + if (id >= 0) { 756 + spec->fixup_list = fixlist; 757 + spec->fixup_name = name; 758 + } 759 + } 760 + EXPORT_SYMBOL_HDA(snd_hda_pick_fixup);
+160
sound/pci/hda/hda_auto_parser.h
··· 1 + /* 2 + * BIOS auto-parser helper functions for HD-audio 3 + * 4 + * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de> 5 + * 6 + * This driver is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #ifndef __SOUND_HDA_AUTO_PARSER_H 13 + #define __SOUND_HDA_AUTO_PARSER_H 14 + 15 + /* 16 + * Helper for automatic pin configuration 17 + */ 18 + 19 + enum { 20 + AUTO_PIN_MIC, 21 + AUTO_PIN_LINE_IN, 22 + AUTO_PIN_CD, 23 + AUTO_PIN_AUX, 24 + AUTO_PIN_LAST 25 + }; 26 + 27 + enum { 28 + AUTO_PIN_LINE_OUT, 29 + AUTO_PIN_SPEAKER_OUT, 30 + AUTO_PIN_HP_OUT 31 + }; 32 + 33 + #define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS 34 + #define AUTO_CFG_MAX_INS 8 35 + 36 + struct auto_pin_cfg_item { 37 + hda_nid_t pin; 38 + int type; 39 + }; 40 + 41 + struct auto_pin_cfg; 42 + const char *hda_get_autocfg_input_label(struct hda_codec *codec, 43 + const struct auto_pin_cfg *cfg, 44 + int input); 45 + int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, 46 + const struct auto_pin_cfg *cfg, 47 + char *label, int maxlen, int *indexp); 48 + 49 + enum { 50 + INPUT_PIN_ATTR_UNUSED, /* pin not connected */ 51 + INPUT_PIN_ATTR_INT, /* internal mic/line-in */ 52 + INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */ 53 + INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */ 54 + INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */ 55 + INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */ 56 + }; 57 + 58 + int snd_hda_get_input_pin_attr(unsigned int def_conf); 59 + 60 + struct auto_pin_cfg { 61 + int line_outs; 62 + /* sorted in the order of Front/Surr/CLFE/Side */ 63 + hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS]; 64 + int speaker_outs; 65 + hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS]; 66 + int hp_outs; 67 + int line_out_type; /* AUTO_PIN_XXX_OUT */ 68 + hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS]; 69 + int num_inputs; 70 + struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS]; 71 + int dig_outs; 72 + hda_nid_t dig_out_pins[2]; 73 + hda_nid_t dig_in_pin; 74 + hda_nid_t mono_out_pin; 75 + int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */ 76 + int dig_in_type; /* HDA_PCM_TYPE_XXX */ 77 + }; 78 + 79 + /* bit-flags for snd_hda_parse_pin_def_config() behavior */ 80 + #define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */ 81 + #define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */ 82 + 83 + int snd_hda_parse_pin_defcfg(struct hda_codec *codec, 84 + struct auto_pin_cfg *cfg, 85 + const hda_nid_t *ignore_nids, 86 + unsigned int cond_flags); 87 + 88 + /* older function */ 89 + #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ 90 + snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) 91 + 92 + /* 93 + */ 94 + 95 + struct hda_gen_spec { 96 + /* fix-up list */ 97 + int fixup_id; 98 + const struct hda_fixup *fixup_list; 99 + const char *fixup_name; 100 + 101 + /* additional init verbs */ 102 + struct snd_array verbs; 103 + }; 104 + 105 + 106 + /* 107 + * Fix-up pin default configurations and add default verbs 108 + */ 109 + 110 + struct hda_pintbl { 111 + hda_nid_t nid; 112 + u32 val; 113 + }; 114 + 115 + struct hda_model_fixup { 116 + const int id; 117 + const char *name; 118 + }; 119 + 120 + struct hda_fixup { 121 + int type; 122 + bool chained; 123 + int chain_id; 124 + union { 125 + const struct hda_pintbl *pins; 126 + const struct hda_verb *verbs; 127 + void (*func)(struct hda_codec *codec, 128 + const struct hda_fixup *fix, 129 + int action); 130 + } v; 131 + }; 132 + 133 + /* fixup types */ 134 + enum { 135 + HDA_FIXUP_INVALID, 136 + HDA_FIXUP_PINS, 137 + HDA_FIXUP_VERBS, 138 + HDA_FIXUP_FUNC, 139 + }; 140 + 141 + /* fixup action definitions */ 142 + enum { 143 + HDA_FIXUP_ACT_PRE_PROBE, 144 + HDA_FIXUP_ACT_PROBE, 145 + HDA_FIXUP_ACT_INIT, 146 + HDA_FIXUP_ACT_BUILD, 147 + }; 148 + 149 + int snd_hda_gen_add_verbs(struct hda_gen_spec *spec, 150 + const struct hda_verb *list); 151 + void snd_hda_gen_apply_verbs(struct hda_codec *codec); 152 + void snd_hda_apply_pincfgs(struct hda_codec *codec, 153 + const struct hda_pintbl *cfg); 154 + void snd_hda_apply_fixup(struct hda_codec *codec, int action); 155 + void snd_hda_pick_fixup(struct hda_codec *codec, 156 + const struct hda_model_fixup *models, 157 + const struct snd_pci_quirk *quirk, 158 + const struct hda_fixup *fixlist); 159 + 160 + #endif /* __SOUND_HDA_AUTO_PARSER_H */
+284 -747
sound/pci/hda/hda_codec.c
··· 334 334 return NULL; 335 335 } 336 336 337 - /** 338 - * snd_hda_get_conn_list - get connection list 339 - * @codec: the HDA codec 340 - * @nid: NID to parse 341 - * @listp: the pointer to store NID list 342 - * 343 - * Parses the connection list of the given widget and stores the list 344 - * of NIDs. 345 - * 346 - * Returns the number of connections, or a negative error code. 347 - */ 348 - int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, 349 - const hda_nid_t **listp) 337 + /* read the connection and add to the cache */ 338 + static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) 350 339 { 351 - struct snd_array *array = &codec->conn_lists; 352 - int len, err; 353 340 hda_nid_t list[HDA_MAX_CONNECTIONS]; 354 - hda_nid_t *p; 355 - bool added = false; 341 + int len; 356 342 357 - again: 358 - /* if the connection-list is already cached, read it */ 359 - p = lookup_conn_list(array, nid); 360 - if (p) { 361 - if (listp) 362 - *listp = p + 2; 363 - return p[1]; 364 - } 365 - if (snd_BUG_ON(added)) 366 - return -EINVAL; 367 - 368 - /* read the connection and add to the cache */ 369 - len = snd_hda_get_raw_connections(codec, nid, list, HDA_MAX_CONNECTIONS); 343 + len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); 370 344 if (len < 0) 371 345 return len; 372 - err = snd_hda_override_conn_list(codec, nid, len, list); 373 - if (err < 0) 374 - return err; 375 - added = true; 376 - goto again; 346 + return snd_hda_override_conn_list(codec, nid, len, list); 377 347 } 378 - EXPORT_SYMBOL_HDA(snd_hda_get_conn_list); 379 348 380 349 /** 381 350 * snd_hda_get_connections - copy connection list 382 351 * @codec: the HDA codec 383 352 * @nid: NID to parse 384 - * @conn_list: connection list array 353 + * @conn_list: connection list array; when NULL, checks only the size 385 354 * @max_conns: max. number of connections to store 386 355 * 387 356 * Parses the connection list of the given widget and stores the list ··· 359 390 * Returns the number of connections, or a negative error code. 360 391 */ 361 392 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, 362 - hda_nid_t *conn_list, int max_conns) 393 + hda_nid_t *conn_list, int max_conns) 363 394 { 364 - const hda_nid_t *list; 365 - int len = snd_hda_get_conn_list(codec, nid, &list); 395 + struct snd_array *array = &codec->conn_lists; 396 + int len; 397 + hda_nid_t *p; 398 + bool added = false; 366 399 367 - if (len <= 0) 368 - return len; 369 - if (len > max_conns) { 370 - snd_printk(KERN_ERR "hda_codec: " 371 - "Too many connections %d for NID 0x%x\n", 372 - len, nid); 373 - return -EINVAL; 400 + again: 401 + mutex_lock(&codec->hash_mutex); 402 + len = -1; 403 + /* if the connection-list is already cached, read it */ 404 + p = lookup_conn_list(array, nid); 405 + if (p) { 406 + len = p[1]; 407 + if (conn_list && len > max_conns) { 408 + snd_printk(KERN_ERR "hda_codec: " 409 + "Too many connections %d for NID 0x%x\n", 410 + len, nid); 411 + mutex_unlock(&codec->hash_mutex); 412 + return -EINVAL; 413 + } 414 + if (conn_list && len) 415 + memcpy(conn_list, p + 2, len * sizeof(hda_nid_t)); 374 416 } 375 - memcpy(conn_list, list, len * sizeof(hda_nid_t)); 376 - return len; 417 + mutex_unlock(&codec->hash_mutex); 418 + if (len >= 0) 419 + return len; 420 + if (snd_BUG_ON(added)) 421 + return -EINVAL; 422 + 423 + len = read_and_add_raw_conns(codec, nid); 424 + if (len < 0) 425 + return len; 426 + added = true; 427 + goto again; 377 428 } 378 429 EXPORT_SYMBOL_HDA(snd_hda_get_connections); 379 430 ··· 532 543 hda_nid_t *p; 533 544 int i, old_used; 534 545 546 + mutex_lock(&codec->hash_mutex); 535 547 p = lookup_conn_list(array, nid); 536 548 if (p) 537 549 *p = -1; /* invalidate the old entry */ ··· 543 553 for (i = 0; i < len; i++) 544 554 if (!add_conn_list(array, list[i])) 545 555 goto error_add; 556 + mutex_unlock(&codec->hash_mutex); 546 557 return 0; 547 558 548 559 error_add: 549 560 array->used = old_used; 561 + mutex_unlock(&codec->hash_mutex); 550 562 return -ENOMEM; 551 563 } 552 564 EXPORT_SYMBOL_HDA(snd_hda_override_conn_list); ··· 1247 1255 codec->addr = codec_addr; 1248 1256 mutex_init(&codec->spdif_mutex); 1249 1257 mutex_init(&codec->control_mutex); 1258 + mutex_init(&codec->hash_mutex); 1250 1259 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1251 1260 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1252 1261 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); ··· 1257 1264 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); 1258 1265 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64); 1259 1266 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); 1260 - if (codec->bus->modelname) { 1261 - codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 1262 - if (!codec->modelname) { 1263 - snd_hda_codec_free(codec); 1264 - return -ENODEV; 1265 - } 1266 - } 1267 1267 1268 1268 #ifdef CONFIG_SND_HDA_POWER_SAVE 1269 + spin_lock_init(&codec->power_lock); 1269 1270 INIT_DELAYED_WORK(&codec->power_work, hda_power_work); 1270 1271 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. 1271 1272 * the caller has to power down appropriatley after initialization ··· 1267 1280 */ 1268 1281 hda_keep_power_on(codec); 1269 1282 #endif 1283 + 1284 + if (codec->bus->modelname) { 1285 + codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 1286 + if (!codec->modelname) { 1287 + snd_hda_codec_free(codec); 1288 + return -ENODEV; 1289 + } 1290 + } 1270 1291 1271 1292 list_add_tail(&codec->list, &bus->codec_list); 1272 1293 bus->caddr_tbl[codec_addr] = codec; ··· 1598 1603 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1599 1604 } 1600 1605 1606 + /* overwrite the value with the key in the caps hash */ 1607 + static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val) 1608 + { 1609 + struct hda_amp_info *info; 1610 + 1611 + mutex_lock(&codec->hash_mutex); 1612 + info = get_alloc_amp_hash(codec, key); 1613 + if (!info) { 1614 + mutex_unlock(&codec->hash_mutex); 1615 + return -EINVAL; 1616 + } 1617 + info->amp_caps = val; 1618 + info->head.val |= INFO_AMP_CAPS; 1619 + mutex_unlock(&codec->hash_mutex); 1620 + return 0; 1621 + } 1622 + 1623 + /* query the value from the caps hash; if not found, fetch the current 1624 + * value from the given function and store in the hash 1625 + */ 1626 + static unsigned int 1627 + query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key, 1628 + unsigned int (*func)(struct hda_codec *, hda_nid_t, int)) 1629 + { 1630 + struct hda_amp_info *info; 1631 + unsigned int val; 1632 + 1633 + mutex_lock(&codec->hash_mutex); 1634 + info = get_alloc_amp_hash(codec, key); 1635 + if (!info) { 1636 + mutex_unlock(&codec->hash_mutex); 1637 + return 0; 1638 + } 1639 + if (!(info->head.val & INFO_AMP_CAPS)) { 1640 + mutex_unlock(&codec->hash_mutex); /* for reentrance */ 1641 + val = func(codec, nid, dir); 1642 + write_caps_hash(codec, key, val); 1643 + } else { 1644 + val = info->amp_caps; 1645 + mutex_unlock(&codec->hash_mutex); 1646 + } 1647 + return val; 1648 + } 1649 + 1650 + static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, 1651 + int direction) 1652 + { 1653 + if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) 1654 + nid = codec->afg; 1655 + return snd_hda_param_read(codec, nid, 1656 + direction == HDA_OUTPUT ? 1657 + AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); 1658 + } 1659 + 1601 1660 /** 1602 1661 * query_amp_caps - query AMP capabilities 1603 1662 * @codec: the HD-auio codec ··· 1666 1617 */ 1667 1618 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1668 1619 { 1669 - struct hda_amp_info *info; 1670 - 1671 - info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0)); 1672 - if (!info) 1673 - return 0; 1674 - if (!(info->head.val & INFO_AMP_CAPS)) { 1675 - if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) 1676 - nid = codec->afg; 1677 - info->amp_caps = snd_hda_param_read(codec, nid, 1678 - direction == HDA_OUTPUT ? 1679 - AC_PAR_AMP_OUT_CAP : 1680 - AC_PAR_AMP_IN_CAP); 1681 - if (info->amp_caps) 1682 - info->head.val |= INFO_AMP_CAPS; 1683 - } 1684 - return info->amp_caps; 1620 + return query_caps_hash(codec, nid, direction, 1621 + HDA_HASH_KEY(nid, direction, 0), 1622 + read_amp_cap); 1685 1623 } 1686 1624 EXPORT_SYMBOL_HDA(query_amp_caps); 1687 1625 ··· 1688 1652 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1689 1653 unsigned int caps) 1690 1654 { 1691 - struct hda_amp_info *info; 1692 - 1693 - info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0)); 1694 - if (!info) 1695 - return -EINVAL; 1696 - info->amp_caps = caps; 1697 - info->head.val |= INFO_AMP_CAPS; 1698 - return 0; 1655 + return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); 1699 1656 } 1700 1657 EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); 1701 1658 1702 - static unsigned int 1703 - query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key, 1704 - unsigned int (*func)(struct hda_codec *, hda_nid_t)) 1705 - { 1706 - struct hda_amp_info *info; 1707 - 1708 - info = get_alloc_amp_hash(codec, key); 1709 - if (!info) 1710 - return 0; 1711 - if (!info->head.val) { 1712 - info->head.val |= INFO_AMP_CAPS; 1713 - info->amp_caps = func(codec, nid); 1714 - } 1715 - return info->amp_caps; 1716 - } 1717 - 1718 - static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid) 1659 + static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid, 1660 + int dir) 1719 1661 { 1720 1662 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 1721 1663 } ··· 1711 1697 */ 1712 1698 u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1713 1699 { 1714 - return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1700 + return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid), 1715 1701 read_pin_cap); 1716 1702 } 1717 1703 EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); ··· 1729 1715 int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, 1730 1716 unsigned int caps) 1731 1717 { 1732 - struct hda_amp_info *info; 1733 - info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid)); 1734 - if (!info) 1735 - return -ENOMEM; 1736 - info->amp_caps = caps; 1737 - info->head.val |= INFO_AMP_CAPS; 1738 - return 0; 1718 + return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps); 1739 1719 } 1740 1720 EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); 1741 1721 1742 - /* 1743 - * read the current volume to info 1744 - * if the cache exists, read the cache value. 1722 + /* read or sync the hash value with the current value; 1723 + * call within hash_mutex 1745 1724 */ 1746 - static unsigned int get_vol_mute(struct hda_codec *codec, 1747 - struct hda_amp_info *info, hda_nid_t nid, 1748 - int ch, int direction, int index) 1725 + static struct hda_amp_info * 1726 + update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, 1727 + int direction, int index) 1749 1728 { 1750 - u32 val, parm; 1729 + struct hda_amp_info *info; 1730 + unsigned int parm, val = 0; 1731 + bool val_read = false; 1751 1732 1752 - if (info->head.val & INFO_AMP_VOL(ch)) 1753 - return info->vol[ch]; 1754 - 1755 - parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; 1756 - parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; 1757 - parm |= index; 1758 - val = snd_hda_codec_read(codec, nid, 0, 1733 + retry: 1734 + info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); 1735 + if (!info) 1736 + return NULL; 1737 + if (!(info->head.val & INFO_AMP_VOL(ch))) { 1738 + if (!val_read) { 1739 + mutex_unlock(&codec->hash_mutex); 1740 + parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; 1741 + parm |= direction == HDA_OUTPUT ? 1742 + AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; 1743 + parm |= index; 1744 + val = snd_hda_codec_read(codec, nid, 0, 1759 1745 AC_VERB_GET_AMP_GAIN_MUTE, parm); 1760 - info->vol[ch] = val & 0xff; 1761 - info->head.val |= INFO_AMP_VOL(ch); 1762 - return info->vol[ch]; 1746 + val &= 0xff; 1747 + val_read = true; 1748 + mutex_lock(&codec->hash_mutex); 1749 + goto retry; 1750 + } 1751 + info->vol[ch] = val; 1752 + info->head.val |= INFO_AMP_VOL(ch); 1753 + } 1754 + return info; 1763 1755 } 1764 1756 1765 1757 /* 1766 - * write the current volume in info to the h/w and update the cache 1758 + * write the current volume in info to the h/w 1767 1759 */ 1768 1760 static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, 1769 1761 hda_nid_t nid, int ch, int direction, int index, ··· 1786 1766 else 1787 1767 parm |= val; 1788 1768 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); 1789 - info->vol[ch] = val; 1790 1769 } 1791 1770 1792 1771 /** ··· 1802 1783 int direction, int index) 1803 1784 { 1804 1785 struct hda_amp_info *info; 1805 - info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); 1806 - if (!info) 1807 - return 0; 1808 - return get_vol_mute(codec, info, nid, ch, direction, index); 1786 + unsigned int val = 0; 1787 + 1788 + mutex_lock(&codec->hash_mutex); 1789 + info = update_amp_hash(codec, nid, ch, direction, index); 1790 + if (info) 1791 + val = info->vol[ch]; 1792 + mutex_unlock(&codec->hash_mutex); 1793 + return val; 1809 1794 } 1810 1795 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1811 1796 ··· 1831 1808 { 1832 1809 struct hda_amp_info *info; 1833 1810 1834 - info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx)); 1835 - if (!info) 1836 - return 0; 1837 1811 if (snd_BUG_ON(mask & ~0xff)) 1838 1812 mask &= 0xff; 1839 1813 val &= mask; 1840 - val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask; 1841 - if (info->vol[ch] == val) 1814 + 1815 + mutex_lock(&codec->hash_mutex); 1816 + info = update_amp_hash(codec, nid, ch, direction, idx); 1817 + if (!info) { 1818 + mutex_unlock(&codec->hash_mutex); 1842 1819 return 0; 1820 + } 1821 + val |= info->vol[ch] & ~mask; 1822 + if (info->vol[ch] == val) { 1823 + mutex_unlock(&codec->hash_mutex); 1824 + return 0; 1825 + } 1826 + info->vol[ch] = val; 1827 + mutex_unlock(&codec->hash_mutex); 1843 1828 put_vol_mute(codec, info, nid, ch, direction, idx, val); 1844 1829 return 1; 1845 1830 } ··· 2294 2263 /* OK, let it free */ 2295 2264 2296 2265 #ifdef CONFIG_SND_HDA_POWER_SAVE 2297 - cancel_delayed_work(&codec->power_work); 2266 + cancel_delayed_work_sync(&codec->power_work); 2267 + codec->power_on = 0; 2268 + codec->power_transition = 0; 2269 + codec->power_jiffies = jiffies; 2298 2270 flush_workqueue(codec->bus->workq); 2299 2271 #endif 2300 2272 snd_hda_ctls_clear(codec); ··· 2893 2859 { 2894 2860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2895 2861 int idx = kcontrol->private_value; 2896 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 2862 + struct hda_spdif_out *spdif; 2897 2863 2864 + mutex_lock(&codec->spdif_mutex); 2865 + spdif = snd_array_elem(&codec->spdif_out, idx); 2898 2866 ucontrol->value.iec958.status[0] = spdif->status & 0xff; 2899 2867 ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; 2900 2868 ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; 2901 2869 ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; 2870 + mutex_unlock(&codec->spdif_mutex); 2902 2871 2903 2872 return 0; 2904 2873 } ··· 2987 2950 { 2988 2951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2989 2952 int idx = kcontrol->private_value; 2990 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 2991 - hda_nid_t nid = spdif->nid; 2953 + struct hda_spdif_out *spdif; 2954 + hda_nid_t nid; 2992 2955 unsigned short val; 2993 2956 int change; 2994 2957 2995 2958 mutex_lock(&codec->spdif_mutex); 2959 + spdif = snd_array_elem(&codec->spdif_out, idx); 2960 + nid = spdif->nid; 2996 2961 spdif->status = ucontrol->value.iec958.status[0] | 2997 2962 ((unsigned int)ucontrol->value.iec958.status[1] << 8) | 2998 2963 ((unsigned int)ucontrol->value.iec958.status[2] << 16) | ··· 3016 2977 { 3017 2978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3018 2979 int idx = kcontrol->private_value; 3019 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 2980 + struct hda_spdif_out *spdif; 3020 2981 2982 + mutex_lock(&codec->spdif_mutex); 2983 + spdif = snd_array_elem(&codec->spdif_out, idx); 3021 2984 ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; 2985 + mutex_unlock(&codec->spdif_mutex); 3022 2986 return 0; 3023 2987 } 3024 2988 ··· 3041 2999 { 3042 3000 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3043 3001 int idx = kcontrol->private_value; 3044 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3045 - hda_nid_t nid = spdif->nid; 3002 + struct hda_spdif_out *spdif; 3003 + hda_nid_t nid; 3046 3004 unsigned short val; 3047 3005 int change; 3048 3006 3049 3007 mutex_lock(&codec->spdif_mutex); 3008 + spdif = snd_array_elem(&codec->spdif_out, idx); 3009 + nid = spdif->nid; 3050 3010 val = spdif->ctls & ~AC_DIG1_ENABLE; 3051 3011 if (ucontrol->value.integer.value[0]) 3052 3012 val |= AC_DIG1_ENABLE; ··· 3136 3092 } 3137 3093 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls); 3138 3094 3095 + /* get the hda_spdif_out entry from the given NID 3096 + * call within spdif_mutex lock 3097 + */ 3139 3098 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, 3140 3099 hda_nid_t nid) 3141 3100 { ··· 3155 3108 3156 3109 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) 3157 3110 { 3158 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3111 + struct hda_spdif_out *spdif; 3159 3112 3160 3113 mutex_lock(&codec->spdif_mutex); 3114 + spdif = snd_array_elem(&codec->spdif_out, idx); 3161 3115 spdif->nid = (u16)-1; 3162 3116 mutex_unlock(&codec->spdif_mutex); 3163 3117 } ··· 3166 3118 3167 3119 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) 3168 3120 { 3169 - struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3121 + struct hda_spdif_out *spdif; 3170 3122 unsigned short val; 3171 3123 3172 3124 mutex_lock(&codec->spdif_mutex); 3125 + spdif = snd_array_elem(&codec->spdif_out, idx); 3173 3126 if (spdif->nid != nid) { 3174 3127 spdif->nid = nid; 3175 3128 val = spdif->ctls; ··· 3535 3486 codec->afg ? codec->afg : codec->mfg, 3536 3487 AC_PWRST_D3); 3537 3488 #ifdef CONFIG_SND_HDA_POWER_SAVE 3538 - snd_hda_update_power_acct(codec); 3539 3489 cancel_delayed_work(&codec->power_work); 3490 + spin_lock(&codec->power_lock); 3491 + snd_hda_update_power_acct(codec); 3492 + trace_hda_power_down(codec); 3540 3493 codec->power_on = 0; 3541 3494 codec->power_transition = 0; 3542 3495 codec->power_jiffies = jiffies; 3496 + spin_unlock(&codec->power_lock); 3543 3497 #endif 3544 3498 } 3545 3499 ··· 3551 3499 */ 3552 3500 static void hda_call_codec_resume(struct hda_codec *codec) 3553 3501 { 3502 + /* set as if powered on for avoiding re-entering the resume 3503 + * in the resume / power-save sequence 3504 + */ 3505 + hda_keep_power_on(codec); 3554 3506 hda_set_power_state(codec, 3555 3507 codec->afg ? codec->afg : codec->mfg, 3556 3508 AC_PWRST_D0); ··· 3570 3514 snd_hda_codec_resume_amp(codec); 3571 3515 snd_hda_codec_resume_cache(codec); 3572 3516 } 3517 + snd_hda_power_down(codec); /* flag down before returning */ 3573 3518 } 3574 3519 #endif /* CONFIG_PM */ 3575 3520 ··· 3722 3665 } 3723 3666 EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format); 3724 3667 3725 - static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid) 3668 + static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, 3669 + int dir) 3726 3670 { 3727 3671 unsigned int val = 0; 3728 3672 if (nid != codec->afg && ··· 3738 3680 3739 3681 static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) 3740 3682 { 3741 - return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid), 3683 + return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid), 3742 3684 get_pcm_param); 3743 3685 } 3744 3686 3745 - static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid) 3687 + static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, 3688 + int dir) 3746 3689 { 3747 3690 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 3748 3691 if (!streams || streams == -1) ··· 3755 3696 3756 3697 static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) 3757 3698 { 3758 - return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid), 3699 + return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid), 3759 3700 get_stream_param); 3760 3701 } 3761 3702 ··· 3834 3775 bps = 20; 3835 3776 } 3836 3777 } 3778 + #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ 3837 3779 if (streams & AC_SUPFMT_FLOAT32) { 3838 3780 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 3839 3781 if (!bps) 3840 3782 bps = 32; 3841 3783 } 3784 + #endif 3842 3785 if (streams == AC_SUPFMT_AC3) { 3843 3786 /* should be exclusive */ 3844 3787 /* temporary hack: we have still no proper support ··· 4344 4283 container_of(work, struct hda_codec, power_work.work); 4345 4284 struct hda_bus *bus = codec->bus; 4346 4285 4347 - if (!codec->power_on || codec->power_count) { 4348 - codec->power_transition = 0; 4286 + spin_lock(&codec->power_lock); 4287 + if (codec->power_transition > 0) { /* during power-up sequence? */ 4288 + spin_unlock(&codec->power_lock); 4349 4289 return; 4350 4290 } 4291 + if (!codec->power_on || codec->power_count) { 4292 + codec->power_transition = 0; 4293 + spin_unlock(&codec->power_lock); 4294 + return; 4295 + } 4296 + spin_unlock(&codec->power_lock); 4351 4297 4352 - trace_hda_power_down(codec); 4353 4298 hda_call_codec_suspend(codec); 4354 4299 if (bus->ops.pm_notify) 4355 4300 bus->ops.pm_notify(bus); ··· 4363 4296 4364 4297 static void hda_keep_power_on(struct hda_codec *codec) 4365 4298 { 4299 + spin_lock(&codec->power_lock); 4366 4300 codec->power_count++; 4367 4301 codec->power_on = 1; 4368 4302 codec->power_jiffies = jiffies; 4303 + spin_unlock(&codec->power_lock); 4369 4304 } 4370 4305 4371 4306 /* update the power on/off account with the current jiffies */ ··· 4392 4323 { 4393 4324 struct hda_bus *bus = codec->bus; 4394 4325 4326 + spin_lock(&codec->power_lock); 4395 4327 codec->power_count++; 4396 - if (codec->power_on || codec->power_transition) 4328 + if (codec->power_on || codec->power_transition > 0) { 4329 + spin_unlock(&codec->power_lock); 4397 4330 return; 4331 + } 4332 + spin_unlock(&codec->power_lock); 4398 4333 4334 + cancel_delayed_work_sync(&codec->power_work); 4335 + 4336 + spin_lock(&codec->power_lock); 4399 4337 trace_hda_power_up(codec); 4400 4338 snd_hda_update_power_acct(codec); 4401 4339 codec->power_on = 1; 4402 4340 codec->power_jiffies = jiffies; 4341 + codec->power_transition = 1; /* avoid reentrance */ 4342 + spin_unlock(&codec->power_lock); 4343 + 4403 4344 if (bus->ops.pm_notify) 4404 4345 bus->ops.pm_notify(bus); 4405 4346 hda_call_codec_resume(codec); 4406 - cancel_delayed_work(&codec->power_work); 4347 + 4348 + spin_lock(&codec->power_lock); 4407 4349 codec->power_transition = 0; 4350 + spin_unlock(&codec->power_lock); 4408 4351 } 4409 4352 EXPORT_SYMBOL_HDA(snd_hda_power_up); 4410 4353 ··· 4432 4351 */ 4433 4352 void snd_hda_power_down(struct hda_codec *codec) 4434 4353 { 4354 + spin_lock(&codec->power_lock); 4435 4355 --codec->power_count; 4436 - if (!codec->power_on || codec->power_count || codec->power_transition) 4356 + if (!codec->power_on || codec->power_count || codec->power_transition) { 4357 + spin_unlock(&codec->power_lock); 4437 4358 return; 4359 + } 4438 4360 if (power_save(codec)) { 4439 - codec->power_transition = 1; /* avoid reentrance */ 4361 + codec->power_transition = -1; /* avoid reentrance */ 4440 4362 queue_delayed_work(codec->bus->workq, &codec->power_work, 4441 4363 msecs_to_jiffies(power_save(codec) * 1000)); 4442 4364 } 4365 + spin_unlock(&codec->power_lock); 4443 4366 } 4444 4367 EXPORT_SYMBOL_HDA(snd_hda_power_down); 4445 4368 ··· 4795 4710 { 4796 4711 const hda_nid_t *nids = mout->dac_nids; 4797 4712 int chs = substream->runtime->channels; 4798 - struct hda_spdif_out *spdif = 4799 - snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); 4713 + struct hda_spdif_out *spdif; 4800 4714 int i; 4801 4715 4802 4716 mutex_lock(&codec->spdif_mutex); 4717 + spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); 4803 4718 if (mout->dig_out_nid && mout->share_spdif && 4804 4719 mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 4805 4720 if (chs == 2 && ··· 4880 4795 } 4881 4796 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); 4882 4797 4883 - /* 4884 - * Helper for automatic pin configuration 4885 - */ 4886 - 4887 - static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list) 4888 - { 4889 - for (; *list; list++) 4890 - if (*list == nid) 4891 - return 1; 4892 - return 0; 4893 - } 4894 - 4895 - 4896 - /* 4897 - * Sort an associated group of pins according to their sequence numbers. 4898 - */ 4899 - static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences, 4900 - int num_pins) 4901 - { 4902 - int i, j; 4903 - short seq; 4904 - hda_nid_t nid; 4905 - 4906 - for (i = 0; i < num_pins; i++) { 4907 - for (j = i + 1; j < num_pins; j++) { 4908 - if (sequences[i] > sequences[j]) { 4909 - seq = sequences[i]; 4910 - sequences[i] = sequences[j]; 4911 - sequences[j] = seq; 4912 - nid = pins[i]; 4913 - pins[i] = pins[j]; 4914 - pins[j] = nid; 4915 - } 4916 - } 4917 - } 4918 - } 4919 - 4920 - 4921 - /* add the found input-pin to the cfg->inputs[] table */ 4922 - static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid, 4923 - int type) 4924 - { 4925 - if (cfg->num_inputs < AUTO_CFG_MAX_INS) { 4926 - cfg->inputs[cfg->num_inputs].pin = nid; 4927 - cfg->inputs[cfg->num_inputs].type = type; 4928 - cfg->num_inputs++; 4929 - } 4930 - } 4931 - 4932 - /* sort inputs in the order of AUTO_PIN_* type */ 4933 - static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg) 4934 - { 4935 - int i, j; 4936 - 4937 - for (i = 0; i < cfg->num_inputs; i++) { 4938 - for (j = i + 1; j < cfg->num_inputs; j++) { 4939 - if (cfg->inputs[i].type > cfg->inputs[j].type) { 4940 - struct auto_pin_cfg_item tmp; 4941 - tmp = cfg->inputs[i]; 4942 - cfg->inputs[i] = cfg->inputs[j]; 4943 - cfg->inputs[j] = tmp; 4944 - } 4945 - } 4946 - } 4947 - } 4948 - 4949 - /* Reorder the surround channels 4950 - * ALSA sequence is front/surr/clfe/side 4951 - * HDA sequence is: 4952 - * 4-ch: front/surr => OK as it is 4953 - * 6-ch: front/clfe/surr 4954 - * 8-ch: front/clfe/rear/side|fc 4955 - */ 4956 - static void reorder_outputs(unsigned int nums, hda_nid_t *pins) 4957 - { 4958 - hda_nid_t nid; 4959 - 4960 - switch (nums) { 4961 - case 3: 4962 - case 4: 4963 - nid = pins[1]; 4964 - pins[1] = pins[2]; 4965 - pins[2] = nid; 4966 - break; 4967 - } 4968 - } 4969 - 4970 - /* 4971 - * Parse all pin widgets and store the useful pin nids to cfg 4972 - * 4973 - * The number of line-outs or any primary output is stored in line_outs, 4974 - * and the corresponding output pins are assigned to line_out_pins[], 4975 - * in the order of front, rear, CLFE, side, ... 4976 - * 4977 - * If more extra outputs (speaker and headphone) are found, the pins are 4978 - * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack 4979 - * is detected, one of speaker of HP pins is assigned as the primary 4980 - * output, i.e. to line_out_pins[0]. So, line_outs is always positive 4981 - * if any analog output exists. 4982 - * 4983 - * The analog input pins are assigned to inputs array. 4984 - * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, 4985 - * respectively. 4986 - */ 4987 - int snd_hda_parse_pin_defcfg(struct hda_codec *codec, 4988 - struct auto_pin_cfg *cfg, 4989 - const hda_nid_t *ignore_nids, 4990 - unsigned int cond_flags) 4991 - { 4992 - hda_nid_t nid, end_nid; 4993 - short seq, assoc_line_out; 4994 - short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; 4995 - short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; 4996 - short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; 4997 - int i; 4998 - 4999 - memset(cfg, 0, sizeof(*cfg)); 5000 - 5001 - memset(sequences_line_out, 0, sizeof(sequences_line_out)); 5002 - memset(sequences_speaker, 0, sizeof(sequences_speaker)); 5003 - memset(sequences_hp, 0, sizeof(sequences_hp)); 5004 - assoc_line_out = 0; 5005 - 5006 - codec->ignore_misc_bit = true; 5007 - end_nid = codec->start_nid + codec->num_nodes; 5008 - for (nid = codec->start_nid; nid < end_nid; nid++) { 5009 - unsigned int wid_caps = get_wcaps(codec, nid); 5010 - unsigned int wid_type = get_wcaps_type(wid_caps); 5011 - unsigned int def_conf; 5012 - short assoc, loc, conn, dev; 5013 - 5014 - /* read all default configuration for pin complex */ 5015 - if (wid_type != AC_WID_PIN) 5016 - continue; 5017 - /* ignore the given nids (e.g. pc-beep returns error) */ 5018 - if (ignore_nids && is_in_nid_list(nid, ignore_nids)) 5019 - continue; 5020 - 5021 - def_conf = snd_hda_codec_get_pincfg(codec, nid); 5022 - if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & 5023 - AC_DEFCFG_MISC_NO_PRESENCE)) 5024 - codec->ignore_misc_bit = false; 5025 - conn = get_defcfg_connect(def_conf); 5026 - if (conn == AC_JACK_PORT_NONE) 5027 - continue; 5028 - loc = get_defcfg_location(def_conf); 5029 - dev = get_defcfg_device(def_conf); 5030 - 5031 - /* workaround for buggy BIOS setups */ 5032 - if (dev == AC_JACK_LINE_OUT) { 5033 - if (conn == AC_JACK_PORT_FIXED) 5034 - dev = AC_JACK_SPEAKER; 5035 - } 5036 - 5037 - switch (dev) { 5038 - case AC_JACK_LINE_OUT: 5039 - seq = get_defcfg_sequence(def_conf); 5040 - assoc = get_defcfg_association(def_conf); 5041 - 5042 - if (!(wid_caps & AC_WCAP_STEREO)) 5043 - if (!cfg->mono_out_pin) 5044 - cfg->mono_out_pin = nid; 5045 - if (!assoc) 5046 - continue; 5047 - if (!assoc_line_out) 5048 - assoc_line_out = assoc; 5049 - else if (assoc_line_out != assoc) 5050 - continue; 5051 - if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) 5052 - continue; 5053 - cfg->line_out_pins[cfg->line_outs] = nid; 5054 - sequences_line_out[cfg->line_outs] = seq; 5055 - cfg->line_outs++; 5056 - break; 5057 - case AC_JACK_SPEAKER: 5058 - seq = get_defcfg_sequence(def_conf); 5059 - assoc = get_defcfg_association(def_conf); 5060 - if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) 5061 - continue; 5062 - cfg->speaker_pins[cfg->speaker_outs] = nid; 5063 - sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq; 5064 - cfg->speaker_outs++; 5065 - break; 5066 - case AC_JACK_HP_OUT: 5067 - seq = get_defcfg_sequence(def_conf); 5068 - assoc = get_defcfg_association(def_conf); 5069 - if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) 5070 - continue; 5071 - cfg->hp_pins[cfg->hp_outs] = nid; 5072 - sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; 5073 - cfg->hp_outs++; 5074 - break; 5075 - case AC_JACK_MIC_IN: 5076 - add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC); 5077 - break; 5078 - case AC_JACK_LINE_IN: 5079 - add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN); 5080 - break; 5081 - case AC_JACK_CD: 5082 - add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD); 5083 - break; 5084 - case AC_JACK_AUX: 5085 - add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX); 5086 - break; 5087 - case AC_JACK_SPDIF_OUT: 5088 - case AC_JACK_DIG_OTHER_OUT: 5089 - if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) 5090 - continue; 5091 - cfg->dig_out_pins[cfg->dig_outs] = nid; 5092 - cfg->dig_out_type[cfg->dig_outs] = 5093 - (loc == AC_JACK_LOC_HDMI) ? 5094 - HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; 5095 - cfg->dig_outs++; 5096 - break; 5097 - case AC_JACK_SPDIF_IN: 5098 - case AC_JACK_DIG_OTHER_IN: 5099 - cfg->dig_in_pin = nid; 5100 - if (loc == AC_JACK_LOC_HDMI) 5101 - cfg->dig_in_type = HDA_PCM_TYPE_HDMI; 5102 - else 5103 - cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; 5104 - break; 5105 - } 5106 - } 5107 - 5108 - /* FIX-UP: 5109 - * If no line-out is defined but multiple HPs are found, 5110 - * some of them might be the real line-outs. 5111 - */ 5112 - if (!cfg->line_outs && cfg->hp_outs > 1 && 5113 - !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) { 5114 - int i = 0; 5115 - while (i < cfg->hp_outs) { 5116 - /* The real HPs should have the sequence 0x0f */ 5117 - if ((sequences_hp[i] & 0x0f) == 0x0f) { 5118 - i++; 5119 - continue; 5120 - } 5121 - /* Move it to the line-out table */ 5122 - cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i]; 5123 - sequences_line_out[cfg->line_outs] = sequences_hp[i]; 5124 - cfg->line_outs++; 5125 - cfg->hp_outs--; 5126 - memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1, 5127 - sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i)); 5128 - memmove(sequences_hp + i, sequences_hp + i + 1, 5129 - sizeof(sequences_hp[0]) * (cfg->hp_outs - i)); 5130 - } 5131 - memset(cfg->hp_pins + cfg->hp_outs, 0, 5132 - sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); 5133 - if (!cfg->hp_outs) 5134 - cfg->line_out_type = AUTO_PIN_HP_OUT; 5135 - 5136 - } 5137 - 5138 - /* sort by sequence */ 5139 - sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, 5140 - cfg->line_outs); 5141 - sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, 5142 - cfg->speaker_outs); 5143 - sort_pins_by_sequence(cfg->hp_pins, sequences_hp, 5144 - cfg->hp_outs); 5145 - 5146 - /* 5147 - * FIX-UP: if no line-outs are detected, try to use speaker or HP pin 5148 - * as a primary output 5149 - */ 5150 - if (!cfg->line_outs && 5151 - !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) { 5152 - if (cfg->speaker_outs) { 5153 - cfg->line_outs = cfg->speaker_outs; 5154 - memcpy(cfg->line_out_pins, cfg->speaker_pins, 5155 - sizeof(cfg->speaker_pins)); 5156 - cfg->speaker_outs = 0; 5157 - memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); 5158 - cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; 5159 - } else if (cfg->hp_outs) { 5160 - cfg->line_outs = cfg->hp_outs; 5161 - memcpy(cfg->line_out_pins, cfg->hp_pins, 5162 - sizeof(cfg->hp_pins)); 5163 - cfg->hp_outs = 0; 5164 - memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); 5165 - cfg->line_out_type = AUTO_PIN_HP_OUT; 5166 - } 5167 - } 5168 - 5169 - reorder_outputs(cfg->line_outs, cfg->line_out_pins); 5170 - reorder_outputs(cfg->hp_outs, cfg->hp_pins); 5171 - reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); 5172 - 5173 - sort_autocfg_input_pins(cfg); 5174 - 5175 - /* 5176 - * debug prints of the parsed results 5177 - */ 5178 - snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", 5179 - cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], 5180 - cfg->line_out_pins[2], cfg->line_out_pins[3], 5181 - cfg->line_out_pins[4], 5182 - cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : 5183 - (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? 5184 - "speaker" : "line")); 5185 - snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 5186 - cfg->speaker_outs, cfg->speaker_pins[0], 5187 - cfg->speaker_pins[1], cfg->speaker_pins[2], 5188 - cfg->speaker_pins[3], cfg->speaker_pins[4]); 5189 - snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 5190 - cfg->hp_outs, cfg->hp_pins[0], 5191 - cfg->hp_pins[1], cfg->hp_pins[2], 5192 - cfg->hp_pins[3], cfg->hp_pins[4]); 5193 - snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); 5194 - if (cfg->dig_outs) 5195 - snd_printd(" dig-out=0x%x/0x%x\n", 5196 - cfg->dig_out_pins[0], cfg->dig_out_pins[1]); 5197 - snd_printd(" inputs:"); 5198 - for (i = 0; i < cfg->num_inputs; i++) { 5199 - snd_printd(" %s=0x%x", 5200 - hda_get_autocfg_input_label(codec, cfg, i), 5201 - cfg->inputs[i].pin); 5202 - } 5203 - snd_printd("\n"); 5204 - if (cfg->dig_in_pin) 5205 - snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); 5206 - 5207 - return 0; 5208 - } 5209 - EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg); 5210 - 5211 - int snd_hda_get_input_pin_attr(unsigned int def_conf) 5212 - { 5213 - unsigned int loc = get_defcfg_location(def_conf); 5214 - unsigned int conn = get_defcfg_connect(def_conf); 5215 - if (conn == AC_JACK_PORT_NONE) 5216 - return INPUT_PIN_ATTR_UNUSED; 5217 - /* Windows may claim the internal mic to be BOTH, too */ 5218 - if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) 5219 - return INPUT_PIN_ATTR_INT; 5220 - if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) 5221 - return INPUT_PIN_ATTR_INT; 5222 - if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) 5223 - return INPUT_PIN_ATTR_DOCK; 5224 - if (loc == AC_JACK_LOC_REAR) 5225 - return INPUT_PIN_ATTR_REAR; 5226 - if (loc == AC_JACK_LOC_FRONT) 5227 - return INPUT_PIN_ATTR_FRONT; 5228 - return INPUT_PIN_ATTR_NORMAL; 5229 - } 5230 - EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr); 5231 - 5232 4798 /** 5233 - * hda_get_input_pin_label - Give a label for the given input pin 4799 + * snd_hda_get_default_vref - Get the default (mic) VREF pin bits 5234 4800 * 5235 - * When check_location is true, the function checks the pin location 5236 - * for mic and line-in pins, and set an appropriate prefix like "Front", 5237 - * "Rear", "Internal". 4801 + * Guess the suitable VREF pin bits to be set as the pin-control value. 4802 + * Note: the function doesn't set the AC_PINCTL_IN_EN bit. 5238 4803 */ 5239 - 5240 - static const char *hda_get_input_pin_label(struct hda_codec *codec, 5241 - hda_nid_t pin, bool check_location) 4804 + unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) 5242 4805 { 5243 - unsigned int def_conf; 5244 - static const char * const mic_names[] = { 5245 - "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", 5246 - }; 5247 - int attr; 5248 - 5249 - def_conf = snd_hda_codec_get_pincfg(codec, pin); 5250 - 5251 - switch (get_defcfg_device(def_conf)) { 5252 - case AC_JACK_MIC_IN: 5253 - if (!check_location) 5254 - return "Mic"; 5255 - attr = snd_hda_get_input_pin_attr(def_conf); 5256 - if (!attr) 5257 - return "None"; 5258 - return mic_names[attr - 1]; 5259 - case AC_JACK_LINE_IN: 5260 - if (!check_location) 5261 - return "Line"; 5262 - attr = snd_hda_get_input_pin_attr(def_conf); 5263 - if (!attr) 5264 - return "None"; 5265 - if (attr == INPUT_PIN_ATTR_DOCK) 5266 - return "Dock Line"; 5267 - return "Line"; 5268 - case AC_JACK_AUX: 5269 - return "Aux"; 5270 - case AC_JACK_CD: 5271 - return "CD"; 5272 - case AC_JACK_SPDIF_IN: 5273 - return "SPDIF In"; 5274 - case AC_JACK_DIG_OTHER_IN: 5275 - return "Digital In"; 5276 - default: 5277 - return "Misc"; 5278 - } 4806 + unsigned int pincap; 4807 + unsigned int oldval; 4808 + oldval = snd_hda_codec_read(codec, pin, 0, 4809 + AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 4810 + pincap = snd_hda_query_pin_caps(codec, pin); 4811 + pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; 4812 + /* Exception: if the default pin setup is vref50, we give it priority */ 4813 + if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) 4814 + return AC_PINCTL_VREF_80; 4815 + else if (pincap & AC_PINCAP_VREF_50) 4816 + return AC_PINCTL_VREF_50; 4817 + else if (pincap & AC_PINCAP_VREF_100) 4818 + return AC_PINCTL_VREF_100; 4819 + else if (pincap & AC_PINCAP_VREF_GRD) 4820 + return AC_PINCTL_VREF_GRD; 4821 + return AC_PINCTL_VREF_HIZ; 5279 4822 } 4823 + EXPORT_SYMBOL_HDA(snd_hda_get_default_vref); 5280 4824 5281 - /* Check whether the location prefix needs to be added to the label. 5282 - * If all mic-jacks are in the same location (e.g. rear panel), we don't 5283 - * have to put "Front" prefix to each label. In such a case, returns false. 5284 - */ 5285 - static int check_mic_location_need(struct hda_codec *codec, 5286 - const struct auto_pin_cfg *cfg, 5287 - int input) 4825 + int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, 4826 + unsigned int val, bool cached) 5288 4827 { 5289 - unsigned int defc; 5290 - int i, attr, attr2; 5291 - 5292 - defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); 5293 - attr = snd_hda_get_input_pin_attr(defc); 5294 - /* for internal or docking mics, we need locations */ 5295 - if (attr <= INPUT_PIN_ATTR_NORMAL) 5296 - return 1; 5297 - 5298 - attr = 0; 5299 - for (i = 0; i < cfg->num_inputs; i++) { 5300 - defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); 5301 - attr2 = snd_hda_get_input_pin_attr(defc); 5302 - if (attr2 >= INPUT_PIN_ATTR_NORMAL) { 5303 - if (attr && attr != attr2) 5304 - return 1; /* different locations found */ 5305 - attr = attr2; 4828 + if (val) { 4829 + unsigned int cap = snd_hda_query_pin_caps(codec, pin); 4830 + if (cap && (val & AC_PINCTL_OUT_EN)) { 4831 + if (!(cap & AC_PINCAP_OUT)) 4832 + val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); 4833 + else if ((val & AC_PINCTL_HP_EN) && 4834 + !(cap & AC_PINCAP_HP_DRV)) 4835 + val &= ~AC_PINCTL_HP_EN; 4836 + } 4837 + if (cap && (val & AC_PINCTL_IN_EN)) { 4838 + if (!(cap & AC_PINCAP_IN)) 4839 + val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN); 5306 4840 } 5307 4841 } 5308 - return 0; 4842 + if (cached) 4843 + return snd_hda_codec_update_cache(codec, pin, 0, 4844 + AC_VERB_SET_PIN_WIDGET_CONTROL, val); 4845 + else 4846 + return snd_hda_codec_write(codec, pin, 0, 4847 + AC_VERB_SET_PIN_WIDGET_CONTROL, val); 5309 4848 } 5310 - 5311 - /** 5312 - * hda_get_autocfg_input_label - Get a label for the given input 5313 - * 5314 - * Get a label for the given input pin defined by the autocfg item. 5315 - * Unlike hda_get_input_pin_label(), this function checks all inputs 5316 - * defined in autocfg and avoids the redundant mic/line prefix as much as 5317 - * possible. 5318 - */ 5319 - const char *hda_get_autocfg_input_label(struct hda_codec *codec, 5320 - const struct auto_pin_cfg *cfg, 5321 - int input) 5322 - { 5323 - int type = cfg->inputs[input].type; 5324 - int has_multiple_pins = 0; 5325 - 5326 - if ((input > 0 && cfg->inputs[input - 1].type == type) || 5327 - (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) 5328 - has_multiple_pins = 1; 5329 - if (has_multiple_pins && type == AUTO_PIN_MIC) 5330 - has_multiple_pins &= check_mic_location_need(codec, cfg, input); 5331 - return hda_get_input_pin_label(codec, cfg->inputs[input].pin, 5332 - has_multiple_pins); 5333 - } 5334 - EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); 5335 - 5336 - /* return the position of NID in the list, or -1 if not found */ 5337 - static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 5338 - { 5339 - int i; 5340 - for (i = 0; i < nums; i++) 5341 - if (list[i] == nid) 5342 - return i; 5343 - return -1; 5344 - } 5345 - 5346 - /* get a unique suffix or an index number */ 5347 - static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, 5348 - int num_pins, int *indexp) 5349 - { 5350 - static const char * const channel_sfx[] = { 5351 - " Front", " Surround", " CLFE", " Side" 5352 - }; 5353 - int i; 5354 - 5355 - i = find_idx_in_nid_list(nid, pins, num_pins); 5356 - if (i < 0) 5357 - return NULL; 5358 - if (num_pins == 1) 5359 - return ""; 5360 - if (num_pins > ARRAY_SIZE(channel_sfx)) { 5361 - if (indexp) 5362 - *indexp = i; 5363 - return ""; 5364 - } 5365 - return channel_sfx[i]; 5366 - } 5367 - 5368 - static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid, 5369 - const struct auto_pin_cfg *cfg, 5370 - const char *name, char *label, int maxlen, 5371 - int *indexp) 5372 - { 5373 - unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); 5374 - int attr = snd_hda_get_input_pin_attr(def_conf); 5375 - const char *pfx = "", *sfx = ""; 5376 - 5377 - /* handle as a speaker if it's a fixed line-out */ 5378 - if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT) 5379 - name = "Speaker"; 5380 - /* check the location */ 5381 - switch (attr) { 5382 - case INPUT_PIN_ATTR_DOCK: 5383 - pfx = "Dock "; 5384 - break; 5385 - case INPUT_PIN_ATTR_FRONT: 5386 - pfx = "Front "; 5387 - break; 5388 - } 5389 - if (cfg) { 5390 - /* try to give a unique suffix if needed */ 5391 - sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, 5392 - indexp); 5393 - if (!sfx) 5394 - sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, 5395 - indexp); 5396 - if (!sfx) { 5397 - /* don't add channel suffix for Headphone controls */ 5398 - int idx = find_idx_in_nid_list(nid, cfg->hp_pins, 5399 - cfg->hp_outs); 5400 - if (idx >= 0) 5401 - *indexp = idx; 5402 - sfx = ""; 5403 - } 5404 - } 5405 - snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); 5406 - return 1; 5407 - } 5408 - 5409 - /** 5410 - * snd_hda_get_pin_label - Get a label for the given I/O pin 5411 - * 5412 - * Get a label for the given pin. This function works for both input and 5413 - * output pins. When @cfg is given as non-NULL, the function tries to get 5414 - * an optimized label using hda_get_autocfg_input_label(). 5415 - * 5416 - * This function tries to give a unique label string for the pin as much as 5417 - * possible. For example, when the multiple line-outs are present, it adds 5418 - * the channel suffix like "Front", "Surround", etc (only when @cfg is given). 5419 - * If no unique name with a suffix is available and @indexp is non-NULL, the 5420 - * index number is stored in the pointer. 5421 - */ 5422 - int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, 5423 - const struct auto_pin_cfg *cfg, 5424 - char *label, int maxlen, int *indexp) 5425 - { 5426 - unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); 5427 - const char *name = NULL; 5428 - int i; 5429 - 5430 - if (indexp) 5431 - *indexp = 0; 5432 - if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 5433 - return 0; 5434 - 5435 - switch (get_defcfg_device(def_conf)) { 5436 - case AC_JACK_LINE_OUT: 5437 - return fill_audio_out_name(codec, nid, cfg, "Line Out", 5438 - label, maxlen, indexp); 5439 - case AC_JACK_SPEAKER: 5440 - return fill_audio_out_name(codec, nid, cfg, "Speaker", 5441 - label, maxlen, indexp); 5442 - case AC_JACK_HP_OUT: 5443 - return fill_audio_out_name(codec, nid, cfg, "Headphone", 5444 - label, maxlen, indexp); 5445 - case AC_JACK_SPDIF_OUT: 5446 - case AC_JACK_DIG_OTHER_OUT: 5447 - if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI) 5448 - name = "HDMI"; 5449 - else 5450 - name = "SPDIF"; 5451 - if (cfg && indexp) { 5452 - i = find_idx_in_nid_list(nid, cfg->dig_out_pins, 5453 - cfg->dig_outs); 5454 - if (i >= 0) 5455 - *indexp = i; 5456 - } 5457 - break; 5458 - default: 5459 - if (cfg) { 5460 - for (i = 0; i < cfg->num_inputs; i++) { 5461 - if (cfg->inputs[i].pin != nid) 5462 - continue; 5463 - name = hda_get_autocfg_input_label(codec, cfg, i); 5464 - if (name) 5465 - break; 5466 - } 5467 - } 5468 - if (!name) 5469 - name = hda_get_input_pin_label(codec, nid, true); 5470 - break; 5471 - } 5472 - if (!name) 5473 - return 0; 5474 - strlcpy(label, name, maxlen); 5475 - return 1; 5476 - } 5477 - EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); 4849 + EXPORT_SYMBOL_HDA(_snd_hda_set_pin_ctl); 5478 4850 5479 4851 /** 5480 4852 * snd_hda_add_imux_item - Add an item to input_mux ··· 4986 5444 list_for_each_entry(codec, &bus->codec_list, list) { 4987 5445 if (hda_codec_is_power_on(codec)) 4988 5446 hda_call_codec_suspend(codec); 4989 - if (codec->patch_ops.post_suspend) 4990 - codec->patch_ops.post_suspend(codec); 4991 5447 } 4992 5448 return 0; 4993 5449 } ··· 5005 5465 struct hda_codec *codec; 5006 5466 5007 5467 list_for_each_entry(codec, &bus->codec_list, list) { 5008 - if (codec->patch_ops.pre_resume) 5009 - codec->patch_ops.pre_resume(codec); 5010 - if (snd_hda_codec_needs_resume(codec)) 5011 - hda_call_codec_resume(codec); 5468 + hda_call_codec_resume(codec); 5012 5469 } 5013 5470 return 0; 5014 5471 }
+8 -7
sound/pci/hda/hda_codec.h
··· 704 704 unsigned int power_state); 705 705 #ifdef CONFIG_PM 706 706 int (*suspend)(struct hda_codec *codec, pm_message_t state); 707 - int (*post_suspend)(struct hda_codec *codec); 708 - int (*pre_resume)(struct hda_codec *codec); 709 707 int (*resume)(struct hda_codec *codec); 710 708 #endif 711 709 #ifdef CONFIG_SND_HDA_POWER_SAVE ··· 827 829 828 830 struct mutex spdif_mutex; 829 831 struct mutex control_mutex; 832 + struct mutex hash_mutex; 830 833 struct snd_array spdif_out; 831 834 unsigned int spdif_in_enable; /* SPDIF input enable? */ 832 835 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ ··· 860 861 unsigned int no_jack_detect:1; /* Machine has no jack-detection */ 861 862 #ifdef CONFIG_SND_HDA_POWER_SAVE 862 863 unsigned int power_on :1; /* current (global) power-state */ 863 - unsigned int power_transition :1; /* power-state in transition */ 864 + int power_transition; /* power-state in transition */ 864 865 int power_count; /* current (global) power refcount */ 865 866 struct delayed_work power_work; /* delayed task for powerdown */ 866 867 unsigned long power_on_acct; 867 868 unsigned long power_off_acct; 868 869 unsigned long power_jiffies; 870 + spinlock_t power_lock; 869 871 #endif 870 872 871 873 /* codec-specific additional proc output */ ··· 911 911 hda_nid_t *start_id); 912 912 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, 913 913 hda_nid_t *conn_list, int max_conns); 914 + static inline int 915 + snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid) 916 + { 917 + return snd_hda_get_connections(codec, nid, NULL, 0); 918 + } 914 919 int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, 915 920 hda_nid_t *conn_list, int max_conns); 916 - int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, 917 - const hda_nid_t **listp); 918 921 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, 919 922 const hda_nid_t *list); 920 923 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, ··· 1054 1051 #ifdef CONFIG_SND_HDA_POWER_SAVE 1055 1052 void snd_hda_power_up(struct hda_codec *codec); 1056 1053 void snd_hda_power_down(struct hda_codec *codec); 1057 - #define snd_hda_codec_needs_resume(codec) codec->power_count 1058 1054 void snd_hda_update_power_acct(struct hda_codec *codec); 1059 1055 #else 1060 1056 static inline void snd_hda_power_up(struct hda_codec *codec) {} 1061 1057 static inline void snd_hda_power_down(struct hda_codec *codec) {} 1062 - #define snd_hda_codec_needs_resume(codec) 1 1063 1058 #endif 1064 1059 1065 1060 #ifdef CONFIG_SND_HDA_PATCH_LOADER
+23 -17
sound/pci/hda/hda_intel.c
··· 497 497 AZX_DRIVER_NVIDIA, 498 498 AZX_DRIVER_TERA, 499 499 AZX_DRIVER_CTX, 500 + AZX_DRIVER_CTHDA, 500 501 AZX_DRIVER_GENERIC, 501 502 AZX_NUM_DRIVERS, /* keep this as last entry */ 502 503 }; ··· 519 518 #define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ 520 519 #define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */ 521 520 #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */ 521 + #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */ 522 522 523 523 /* quirks for ATI SB / AMD Hudson */ 524 524 #define AZX_DCAPS_PRESET_ATI_SB \ ··· 535 533 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ 536 534 AZX_DCAPS_ALIGN_BUFSIZE) 537 535 536 + #define AZX_DCAPS_PRESET_CTHDA \ 537 + (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) 538 + 538 539 static char *driver_short_names[] __devinitdata = { 539 540 [AZX_DRIVER_ICH] = "HDA Intel", 540 541 [AZX_DRIVER_PCH] = "HDA Intel PCH", ··· 551 546 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 552 547 [AZX_DRIVER_TERA] = "HDA Teradici", 553 548 [AZX_DRIVER_CTX] = "HDA Creative", 549 + [AZX_DRIVER_CTHDA] = "HDA Creative", 554 550 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 555 551 }; 556 552 ··· 1291 1285 /* 1292 1286 * set up a BDL entry 1293 1287 */ 1294 - static int setup_bdle(struct snd_pcm_substream *substream, 1288 + static int setup_bdle(struct azx *chip, 1289 + struct snd_pcm_substream *substream, 1295 1290 struct azx_dev *azx_dev, u32 **bdlp, 1296 1291 int ofs, int size, int with_ioc) 1297 1292 { ··· 1311 1304 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1312 1305 /* program the size field of the BDL entry */ 1313 1306 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); 1307 + /* one BDLE cannot cross 4K boundary on CTHDA chips */ 1308 + if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) { 1309 + u32 remain = 0x1000 - (ofs & 0xfff); 1310 + if (chunk > remain) 1311 + chunk = remain; 1312 + } 1314 1313 bdl[2] = cpu_to_le32(chunk); 1315 1314 /* program the IOC to enable interrupt 1316 1315 * only when the whole fragment is processed ··· 1369 1356 bdl_pos_adj[chip->dev_index]); 1370 1357 pos_adj = 0; 1371 1358 } else { 1372 - ofs = setup_bdle(substream, azx_dev, 1359 + ofs = setup_bdle(chip, substream, azx_dev, 1373 1360 &bdl, ofs, pos_adj, 1374 1361 !substream->runtime->no_period_wakeup); 1375 1362 if (ofs < 0) ··· 1379 1366 pos_adj = 0; 1380 1367 for (i = 0; i < periods; i++) { 1381 1368 if (i == periods - 1 && pos_adj) 1382 - ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1369 + ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, 1383 1370 period_bytes - pos_adj, 0); 1384 1371 else 1385 - ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1372 + ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, 1386 1373 period_bytes, 1387 1374 !substream->runtime->no_period_wakeup); 1388 1375 if (ofs < 0) ··· 2366 2353 * power management 2367 2354 */ 2368 2355 2369 - static int snd_hda_codecs_inuse(struct hda_bus *bus) 2370 - { 2371 - struct hda_codec *codec; 2372 - 2373 - list_for_each_entry(codec, &bus->codec_list, list) { 2374 - if (snd_hda_codec_needs_resume(codec)) 2375 - return 1; 2376 - } 2377 - return 0; 2378 - } 2379 - 2380 2356 static int azx_suspend(struct pci_dev *pci, pm_message_t state) 2381 2357 { 2382 2358 struct snd_card *card = pci_get_drvdata(pci); ··· 2412 2410 return -EIO; 2413 2411 azx_init_pci(chip); 2414 2412 2415 - if (snd_hda_codecs_inuse(chip->bus)) 2416 - azx_init_chip(chip, 1); 2413 + azx_init_chip(chip, 1); 2417 2414 2418 2415 snd_hda_resume(chip->bus); 2419 2416 snd_power_change_state(card, SNDRV_CTL_POWER_D0); ··· 3131 3130 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | 3132 3131 AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, 3133 3132 #endif 3133 + /* CTHDA chips */ 3134 + { PCI_DEVICE(0x1102, 0x0010), 3135 + .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, 3136 + { PCI_DEVICE(0x1102, 0x0012), 3137 + .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, 3134 3138 /* Vortex86MX */ 3135 3139 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, 3136 3140 /* VMware HDAudio */
+1
sound/pci/hda/hda_jack.c
··· 17 17 #include <sound/jack.h> 18 18 #include "hda_codec.h" 19 19 #include "hda_local.h" 20 + #include "hda_auto_parser.h" 20 21 #include "hda_jack.h" 21 22 22 23 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
+2
sound/pci/hda/hda_jack.h
··· 12 12 #ifndef __SOUND_HDA_JACK_H 13 13 #define __SOUND_HDA_JACK_H 14 14 15 + struct auto_pin_cfg; 16 + 15 17 struct hda_jack_tbl { 16 18 hda_nid_t nid; 17 19 unsigned char action; /* event action (0 = none) */
+43 -79
sound/pci/hda/hda_local.h
··· 262 262 const struct hda_input_mux *imux, 263 263 struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, 264 264 unsigned int *cur_val); 265 + int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, 266 + int index, int *type_index_ret); 265 267 266 268 /* 267 269 * Channel mode helper ··· 395 393 struct hda_bus *bus; 396 394 }; 397 395 398 - /* 399 - * Helper for automatic pin configuration 400 - */ 401 - 402 - enum { 403 - AUTO_PIN_MIC, 404 - AUTO_PIN_LINE_IN, 405 - AUTO_PIN_CD, 406 - AUTO_PIN_AUX, 407 - AUTO_PIN_LAST 408 - }; 409 - 410 - enum { 411 - AUTO_PIN_LINE_OUT, 412 - AUTO_PIN_SPEAKER_OUT, 413 - AUTO_PIN_HP_OUT 414 - }; 415 - 416 - #define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS 417 - #define AUTO_CFG_MAX_INS 8 418 - 419 - struct auto_pin_cfg_item { 420 - hda_nid_t pin; 421 - int type; 422 - }; 423 - 424 - struct auto_pin_cfg; 425 - const char *hda_get_autocfg_input_label(struct hda_codec *codec, 426 - const struct auto_pin_cfg *cfg, 427 - int input); 428 - int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, 429 - const struct auto_pin_cfg *cfg, 430 - char *label, int maxlen, int *indexp); 431 - int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, 432 - int index, int *type_index_ret); 433 - 434 - enum { 435 - INPUT_PIN_ATTR_UNUSED, /* pin not connected */ 436 - INPUT_PIN_ATTR_INT, /* internal mic/line-in */ 437 - INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */ 438 - INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */ 439 - INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */ 440 - INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */ 441 - }; 442 - 443 - int snd_hda_get_input_pin_attr(unsigned int def_conf); 444 - 445 - struct auto_pin_cfg { 446 - int line_outs; 447 - /* sorted in the order of Front/Surr/CLFE/Side */ 448 - hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS]; 449 - int speaker_outs; 450 - hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS]; 451 - int hp_outs; 452 - int line_out_type; /* AUTO_PIN_XXX_OUT */ 453 - hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS]; 454 - int num_inputs; 455 - struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS]; 456 - int dig_outs; 457 - hda_nid_t dig_out_pins[2]; 458 - hda_nid_t dig_in_pin; 459 - hda_nid_t mono_out_pin; 460 - int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */ 461 - int dig_in_type; /* HDA_PCM_TYPE_XXX */ 462 - }; 463 - 396 + /* helper macros to retrieve pin default-config values */ 464 397 #define get_defcfg_connect(cfg) \ 465 398 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) 466 399 #define get_defcfg_association(cfg) \ ··· 408 471 ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT) 409 472 #define get_defcfg_misc(cfg) \ 410 473 ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) 411 - 412 - /* bit-flags for snd_hda_parse_pin_def_config() behavior */ 413 - #define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */ 414 - #define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */ 415 - 416 - int snd_hda_parse_pin_defcfg(struct hda_codec *codec, 417 - struct auto_pin_cfg *cfg, 418 - const hda_nid_t *ignore_nids, 419 - unsigned int cond_flags); 420 - 421 - /* older function */ 422 - #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ 423 - snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) 424 474 425 475 /* amp values */ 426 476 #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) ··· 425 501 #define PIN_OUT (AC_PINCTL_OUT_EN) 426 502 #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) 427 503 #define PIN_HP_AMP (AC_PINCTL_HP_EN) 504 + 505 + unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin); 506 + int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, 507 + unsigned int val, bool cached); 508 + 509 + /** 510 + * _snd_hda_set_pin_ctl - Set a pin-control value safely 511 + * @codec: the codec instance 512 + * @pin: the pin NID to set the control 513 + * @val: the pin-control value (AC_PINCTL_* bits) 514 + * 515 + * This function sets the pin-control value to the given pin, but 516 + * filters out the invalid pin-control bits when the pin has no such 517 + * capabilities. For example, when PIN_HP is passed but the pin has no 518 + * HP-drive capability, the HP bit is omitted. 519 + * 520 + * The function doesn't check the input VREF capability bits, though. 521 + * Use snd_hda_get_default_vref() to guess the right value. 522 + * Also, this function is only for analog pins, not for HDMI pins. 523 + */ 524 + static inline int 525 + snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val) 526 + { 527 + return _snd_hda_set_pin_ctl(codec, pin, val, false); 528 + } 529 + 530 + /** 531 + * snd_hda_set_pin_ctl_cache - Set a pin-control value safely 532 + * @codec: the codec instance 533 + * @pin: the pin NID to set the control 534 + * @val: the pin-control value (AC_PINCTL_* bits) 535 + * 536 + * Just like snd_hda_set_pin_ctl() but write to cache as well. 537 + */ 538 + static inline int 539 + snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin, 540 + unsigned int val) 541 + { 542 + return _snd_hda_set_pin_ctl(codec, pin, val, true); 543 + } 428 544 429 545 /* 430 546 * get widget capabilities
+8 -6
sound/pci/hda/patch_analog.c
··· 28 28 #include <sound/core.h> 29 29 #include "hda_codec.h" 30 30 #include "hda_local.h" 31 + #include "hda_auto_parser.h" 31 32 #include "hda_beep.h" 32 33 #include "hda_jack.h" 33 34 ··· 1743 1742 if (! ad198x_eapd_put(kcontrol, ucontrol)) 1744 1743 return 0; 1745 1744 /* change speaker pin appropriately */ 1746 - snd_hda_codec_write(codec, 0x05, 0, 1747 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1748 - spec->cur_eapd ? PIN_OUT : 0); 1745 + snd_hda_set_pin_ctl(codec, 0x05, spec->cur_eapd ? PIN_OUT : 0); 1749 1746 /* toggle HP mute appropriately */ 1750 1747 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, 1751 1748 HDA_AMP_MUTE, ··· 3102 3103 int dac_idx) 3103 3104 { 3104 3105 /* set as output */ 3105 - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 3106 + snd_hda_set_pin_ctl(codec, nid, pin_type); 3106 3107 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 3107 3108 switch (nid) { 3108 3109 case 0x11: /* port-A - DAC 03 */ ··· 3156 3157 for (i = 0; i < cfg->num_inputs; i++) { 3157 3158 hda_nid_t nid = cfg->inputs[i].pin; 3158 3159 int type = cfg->inputs[i].type; 3160 + int val; 3159 3161 switch (nid) { 3160 3162 case 0x15: /* port-C */ 3161 3163 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); ··· 3165 3165 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); 3166 3166 break; 3167 3167 } 3168 - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 3169 - type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN); 3168 + val = PIN_IN; 3169 + if (type == AUTO_PIN_MIC) 3170 + val |= snd_hda_get_default_vref(codec, nid); 3171 + snd_hda_set_pin_ctl(codec, nid, val); 3170 3172 if (nid != AD1988_PIN_CD_NID) 3171 3173 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3172 3174 AMP_OUT_MUTE);
+4 -4
sound/pci/hda/patch_ca0110.c
··· 26 26 #include <sound/core.h> 27 27 #include "hda_codec.h" 28 28 #include "hda_local.h" 29 + #include "hda_auto_parser.h" 29 30 30 31 /* 31 32 */ ··· 342 341 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) 343 342 { 344 343 if (pin) { 345 - snd_hda_codec_write(codec, pin, 0, 346 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 344 + snd_hda_set_pin_ctl(codec, pin, PIN_HP); 347 345 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) 348 346 snd_hda_codec_write(codec, pin, 0, 349 347 AC_VERB_SET_AMP_GAIN_MUTE, ··· 356 356 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) 357 357 { 358 358 if (pin) { 359 - snd_hda_codec_write(codec, pin, 0, 360 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80); 359 + snd_hda_set_pin_ctl(codec, pin, PIN_IN | 360 + snd_hda_get_default_vref(codec, pin)); 361 361 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) 362 362 snd_hda_codec_write(codec, pin, 0, 363 363 AC_VERB_SET_AMP_GAIN_MUTE,
+4 -5
sound/pci/hda/patch_ca0132.c
··· 30 30 #include <sound/core.h> 31 31 #include "hda_codec.h" 32 32 #include "hda_local.h" 33 + #include "hda_auto_parser.h" 33 34 34 35 #define WIDGET_CHIP_CTRL 0x15 35 36 #define WIDGET_DSP_CTRL 0x16 ··· 240 239 static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) 241 240 { 242 241 if (pin) { 243 - snd_hda_codec_write(codec, pin, 0, 244 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 242 + snd_hda_set_pin_ctl(codec, pin, PIN_HP); 245 243 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) 246 244 snd_hda_codec_write(codec, pin, 0, 247 245 AC_VERB_SET_AMP_GAIN_MUTE, ··· 254 254 static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) 255 255 { 256 256 if (pin) { 257 - snd_hda_codec_write(codec, pin, 0, 258 - AC_VERB_SET_PIN_WIDGET_CONTROL, 259 - PIN_VREF80); 257 + snd_hda_set_pin_ctl(codec, pin, PIN_IN | 258 + snd_hda_get_default_vref(codec, pin)); 260 259 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) 261 260 snd_hda_codec_write(codec, pin, 0, 262 261 AC_VERB_SET_AMP_GAIN_MUTE,
+10 -20
sound/pci/hda/patch_cirrus.c
··· 26 26 #include <sound/core.h> 27 27 #include "hda_codec.h" 28 28 #include "hda_local.h" 29 + #include "hda_auto_parser.h" 29 30 #include "hda_jack.h" 30 31 #include <sound/tlv.h> 31 32 ··· 934 933 pin_ctl = 0; 935 934 936 935 nid = cfg->speaker_pins[i]; 937 - snd_hda_codec_write(codec, nid, 0, 938 - AC_VERB_SET_PIN_WIDGET_CONTROL, pin_ctl); 936 + snd_hda_set_pin_ctl(codec, nid, pin_ctl); 939 937 } 940 938 if (spec->gpio_eapd_hp) { 941 939 unsigned int gpio = hp_present ? ··· 948 948 /* mute HPs if spdif jack (SENSE_B) is present */ 949 949 for (i = 0; i < cfg->hp_outs; i++) { 950 950 nid = cfg->hp_pins[i]; 951 - snd_hda_codec_write(codec, nid, 0, 952 - AC_VERB_SET_PIN_WIDGET_CONTROL, 951 + snd_hda_set_pin_ctl(codec, nid, 953 952 (spdif_present && spec->sense_b) ? 0 : PIN_HP); 954 953 } 955 954 956 955 /* SPDIF TX on/off */ 957 956 if (cfg->dig_outs) { 958 957 nid = cfg->dig_out_pins[0]; 959 - snd_hda_codec_write(codec, nid, 0, 960 - AC_VERB_SET_PIN_WIDGET_CONTROL, 958 + snd_hda_set_pin_ctl(codec, nid, 961 959 spdif_present ? PIN_OUT : 0); 962 960 963 961 } ··· 1022 1024 1023 1025 /* set appropriate pin controls */ 1024 1026 for (i = 0; i < cfg->line_outs; i++) 1025 - snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 1026 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 1027 + snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT); 1027 1028 /* HP */ 1028 1029 for (i = 0; i < cfg->hp_outs; i++) { 1029 1030 hda_nid_t nid = cfg->hp_pins[i]; 1030 - snd_hda_codec_write(codec, nid, 0, 1031 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 1031 + snd_hda_set_pin_ctl(codec, nid, PIN_HP); 1032 1032 if (!cfg->speaker_outs) 1033 1033 continue; 1034 1034 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { ··· 1037 1041 1038 1042 /* Speaker */ 1039 1043 for (i = 0; i < cfg->speaker_outs; i++) 1040 - snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 1041 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 1044 + snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT); 1042 1045 1043 1046 /* SPDIF is enabled on presence detect for CS421x */ 1044 1047 if (spec->hp_detect || spec->spdif_detect) ··· 1058 1063 continue; 1059 1064 /* set appropriate pin control and mute first */ 1060 1065 ctl = PIN_IN; 1061 - if (cfg->inputs[i].type == AUTO_PIN_MIC) { 1062 - unsigned int caps = snd_hda_query_pin_caps(codec, pin); 1063 - caps >>= AC_PINCAP_VREF_SHIFT; 1064 - if (caps & AC_PINCAP_VREF_80) 1065 - ctl = PIN_VREF80; 1066 - } 1067 - snd_hda_codec_write(codec, pin, 0, 1068 - AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); 1066 + if (cfg->inputs[i].type == AUTO_PIN_MIC) 1067 + ctl |= snd_hda_get_default_vref(codec, pin); 1068 + snd_hda_set_pin_ctl(codec, pin, ctl); 1069 1069 snd_hda_codec_write(codec, spec->adc_nid[i], 0, 1070 1070 AC_VERB_SET_AMP_GAIN_MUTE, 1071 1071 AMP_IN_MUTE(spec->adc_idx[i]));
+1
sound/pci/hda/patch_cmedia.c
··· 29 29 #include <sound/core.h> 30 30 #include "hda_codec.h" 31 31 #include "hda_local.h" 32 + #include "hda_auto_parser.h" 32 33 #define NUM_PINS 11 33 34 34 35
+116 -70
sound/pci/hda/patch_conexant.c
··· 30 30 31 31 #include "hda_codec.h" 32 32 #include "hda_local.h" 33 + #include "hda_auto_parser.h" 33 34 #include "hda_beep.h" 34 35 #include "hda_jack.h" 35 36 ··· 67 66 }; 68 67 69 68 struct conexant_spec { 69 + struct hda_gen_spec gen; 70 70 71 71 const struct snd_kcontrol_new *mixers[5]; 72 72 int num_mixers; ··· 143 141 unsigned int hp_laptop:1; 144 142 unsigned int asus:1; 145 143 unsigned int pin_eapd_ctrls:1; 144 + unsigned int fixup_stereo_dmic:1; 146 145 147 146 unsigned int adc_switching:1; 148 147 ··· 1604 1601 unsigned int pinctl; 1605 1602 /* headphone pin */ 1606 1603 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 1607 - snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1608 - pinctl); 1604 + snd_hda_set_pin_ctl(codec, 0x16, pinctl); 1609 1605 /* speaker pin */ 1610 1606 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1611 - snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1612 - pinctl); 1607 + snd_hda_set_pin_ctl(codec, 0x1a, pinctl); 1613 1608 /* on ideapad there is an additional speaker (subwoofer) to mute */ 1614 1609 if (spec->ideapad) 1615 - snd_hda_codec_write(codec, 0x1b, 0, 1616 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1617 - pinctl); 1610 + snd_hda_set_pin_ctl(codec, 0x1b, pinctl); 1618 1611 } 1619 1612 1620 1613 /* turn on/off EAPD (+ mute HP) as a master switch */ ··· 1995 1996 1996 1997 /* Port A (HP) */ 1997 1998 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 1998 - snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1999 - pinctl); 1999 + snd_hda_set_pin_ctl(codec, 0x19, pinctl); 2000 2000 2001 2001 /* Port D (HP/LO) */ 2002 2002 pinctl = spec->cur_eapd ? spec->port_d_mode : 0; ··· 2008 2010 if (!hp_port_d_present(spec)) 2009 2011 pinctl = 0; 2010 2012 } 2011 - snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2012 - pinctl); 2013 + snd_hda_set_pin_ctl(codec, 0x1c, pinctl); 2013 2014 2014 2015 /* CLASS_D AMP */ 2015 2016 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 2016 - snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2017 - pinctl); 2017 + snd_hda_set_pin_ctl(codec, 0x1f, pinctl); 2018 2018 } 2019 2019 2020 2020 /* turn on/off EAPD (+ mute HP) as a master switch */ ··· 2043 2047 /* Even though port F is the DC input, the bias is controlled on port B. 2044 2048 * we also leave that port as an active input (but unselected) in DC mode 2045 2049 * just in case that is necessary to make the bias setting take effect. */ 2046 - return snd_hda_codec_write_cache(codec, 0x1a, 0, 2047 - AC_VERB_SET_PIN_WIDGET_CONTROL, 2050 + return snd_hda_set_pin_ctl_cache(codec, 0x1a, 2048 2051 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2049 2052 } 2050 2053 ··· 2076 2081 } 2077 2082 2078 2083 /* disable DC (port F) */ 2079 - snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2084 + snd_hda_set_pin_ctl(codec, 0x1e, 0); 2080 2085 2081 2086 /* external mic, port B */ 2082 - snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2087 + snd_hda_set_pin_ctl(codec, 0x1a, 2083 2088 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 2084 2089 2085 2090 /* internal mic, port C */ 2086 - snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2091 + snd_hda_set_pin_ctl(codec, 0x1b, 2087 2092 spec->ext_mic_present ? 0 : PIN_VREF80); 2088 2093 } 2089 2094 ··· 3352 3357 struct conexant_spec *spec = codec->spec; 3353 3358 int i; 3354 3359 for (i = 0; i < num_pins; i++) 3355 - snd_hda_codec_write(codec, pins[i], 0, 3356 - AC_VERB_SET_PIN_WIDGET_CONTROL, 3357 - on ? PIN_OUT : 0); 3360 + snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0); 3358 3361 if (spec->pin_eapd_ctrls) 3359 3362 cx_auto_turn_eapd(codec, num_pins, pins, on); 3360 3363 } ··· 3969 3976 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & 3970 3977 AC_PINCAP_HP_DRV) 3971 3978 val |= AC_PINCTL_HP_EN; 3972 - snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3973 - AC_VERB_SET_PIN_WIDGET_CONTROL, val); 3979 + snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val); 3974 3980 } 3975 3981 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 3976 3982 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); ··· 4022 4030 } 4023 4031 4024 4032 for (i = 0; i < cfg->num_inputs; i++) { 4025 - unsigned int type; 4033 + hda_nid_t pin = cfg->inputs[i].pin; 4034 + unsigned int type = PIN_IN; 4026 4035 if (cfg->inputs[i].type == AUTO_PIN_MIC) 4027 - type = PIN_VREF80; 4028 - else 4029 - type = PIN_IN; 4030 - snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4031 - AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4036 + type |= snd_hda_get_default_vref(codec, pin); 4037 + snd_hda_set_pin_ctl(codec, pin, type); 4032 4038 } 4033 4039 4034 4040 if (spec->auto_mic) { ··· 4053 4063 struct auto_pin_cfg *cfg = &spec->autocfg; 4054 4064 4055 4065 if (spec->multiout.dig_out_nid) 4056 - snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4057 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4066 + snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT); 4058 4067 if (spec->dig_in_nid) 4059 - snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4060 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4068 + snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN); 4061 4069 } 4062 4070 4063 4071 static int cx_auto_init(struct hda_codec *codec) ··· 4072 4084 4073 4085 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4074 4086 const char *dir, int cidx, 4075 - hda_nid_t nid, int hda_dir, int amp_idx) 4087 + hda_nid_t nid, int hda_dir, int amp_idx, int chs) 4076 4088 { 4077 - static char name[32]; 4089 + static char name[44]; 4078 4090 static struct snd_kcontrol_new knew[] = { 4079 4091 HDA_CODEC_VOLUME(name, 0, 0, 0), 4080 4092 HDA_CODEC_MUTE(name, 0, 0, 0), ··· 4084 4096 4085 4097 for (i = 0; i < 2; i++) { 4086 4098 struct snd_kcontrol *kctl; 4087 - knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4099 + knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, 4088 4100 hda_dir); 4089 4101 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4090 4102 knew[i].index = cidx; ··· 4103 4115 } 4104 4116 4105 4117 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4106 - cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4118 + cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) 4107 4119 4108 4120 #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4109 4121 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) ··· 4173 4185 return 0; 4174 4186 } 4175 4187 4188 + /* Returns zero if this is a normal stereo channel, and non-zero if it should 4189 + be split in two independent channels. 4190 + dest_label must be at least 44 characters. */ 4191 + static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, 4192 + char *dest_label, int nid) 4193 + { 4194 + struct conexant_spec *spec = codec->spec; 4195 + int i; 4196 + 4197 + if (!spec->fixup_stereo_dmic) 4198 + return 0; 4199 + 4200 + for (i = 0; i < AUTO_CFG_MAX_INS; i++) { 4201 + int def_conf; 4202 + if (spec->autocfg.inputs[i].pin != nid) 4203 + continue; 4204 + 4205 + if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) 4206 + return 0; 4207 + def_conf = snd_hda_codec_get_pincfg(codec, nid); 4208 + if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) 4209 + return 0; 4210 + 4211 + /* Finally found the inverted internal mic! */ 4212 + snprintf(dest_label, 44, "Inverted %s", label); 4213 + return 1; 4214 + } 4215 + return 0; 4216 + } 4217 + 4176 4218 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 4177 4219 const char *label, const char *pfx, 4178 4220 int cidx) ··· 4211 4193 int i; 4212 4194 4213 4195 for (i = 0; i < spec->num_adc_nids; i++) { 4196 + char rightch_label[44]; 4214 4197 hda_nid_t adc_nid = spec->adc_nids[i]; 4215 4198 int idx = get_input_connection(codec, adc_nid, nid); 4216 4199 if (idx < 0) 4217 4200 continue; 4218 4201 if (codec->single_adc_amp) 4219 4202 idx = 0; 4203 + 4204 + if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4205 + /* Make two independent kcontrols for left and right */ 4206 + int err = cx_auto_add_volume_idx(codec, label, pfx, 4207 + cidx, adc_nid, HDA_INPUT, idx, 1); 4208 + if (err < 0) 4209 + return err; 4210 + return cx_auto_add_volume_idx(codec, rightch_label, pfx, 4211 + cidx, adc_nid, HDA_INPUT, idx, 2); 4212 + } 4220 4213 return cx_auto_add_volume_idx(codec, label, pfx, 4221 - cidx, adc_nid, HDA_INPUT, idx); 4214 + cidx, adc_nid, HDA_INPUT, idx, 3); 4222 4215 } 4223 4216 return 0; 4224 4217 } ··· 4242 4213 int i, con; 4243 4214 4244 4215 nid = spec->imux_info[idx].pin; 4245 - if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4216 + if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 4217 + char rightch_label[44]; 4218 + if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4219 + int err = cx_auto_add_volume_idx(codec, label, " Boost", 4220 + cidx, nid, HDA_INPUT, 0, 1); 4221 + if (err < 0) 4222 + return err; 4223 + return cx_auto_add_volume_idx(codec, rightch_label, " Boost", 4224 + cidx, nid, HDA_INPUT, 0, 2); 4225 + } 4246 4226 return cx_auto_add_volume(codec, label, " Boost", cidx, 4247 4227 nid, HDA_INPUT); 4228 + } 4248 4229 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 4249 4230 &mux, false, 0); 4250 4231 if (con < 0) ··· 4409 4370 /* 4410 4371 * pin fix-up 4411 4372 */ 4412 - struct cxt_pincfg { 4413 - hda_nid_t nid; 4414 - u32 val; 4415 - }; 4416 - 4417 - static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4418 - { 4419 - for (; cfg->nid; cfg++) 4420 - snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4421 - 4422 - } 4423 - 4424 - static void apply_pin_fixup(struct hda_codec *codec, 4425 - const struct snd_pci_quirk *quirk, 4426 - const struct cxt_pincfg **table) 4427 - { 4428 - quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 4429 - if (quirk) { 4430 - snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4431 - quirk->name); 4432 - apply_pincfg(codec, table[quirk->value]); 4433 - } 4434 - } 4435 - 4436 4373 enum { 4437 4374 CXT_PINCFG_LENOVO_X200, 4438 4375 CXT_PINCFG_LENOVO_TP410, 4376 + CXT_FIXUP_STEREO_DMIC, 4439 4377 }; 4440 4378 4379 + static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 4380 + const struct hda_fixup *fix, int action) 4381 + { 4382 + struct conexant_spec *spec = codec->spec; 4383 + spec->fixup_stereo_dmic = 1; 4384 + } 4385 + 4441 4386 /* ThinkPad X200 & co with cxt5051 */ 4442 - static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4387 + static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 4443 4388 { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4444 4389 { 0x17, 0x21a11000 }, /* dock-mic */ 4445 4390 { 0x19, 0x2121103f }, /* dock-HP */ ··· 4432 4409 }; 4433 4410 4434 4411 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 4435 - static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { 4412 + static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { 4436 4413 { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 4437 4414 { 0x1a, 0x21a190f0 }, /* dock-mic */ 4438 4415 { 0x1c, 0x212140ff }, /* dock-HP */ 4439 4416 {} 4440 4417 }; 4441 4418 4442 - static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4443 - [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4444 - [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, 4419 + static const struct hda_fixup cxt_fixups[] = { 4420 + [CXT_PINCFG_LENOVO_X200] = { 4421 + .type = HDA_FIXUP_PINS, 4422 + .v.pins = cxt_pincfg_lenovo_x200, 4423 + }, 4424 + [CXT_PINCFG_LENOVO_TP410] = { 4425 + .type = HDA_FIXUP_PINS, 4426 + .v.pins = cxt_pincfg_lenovo_tp410, 4427 + }, 4428 + [CXT_FIXUP_STEREO_DMIC] = { 4429 + .type = HDA_FIXUP_FUNC, 4430 + .v.func = cxt_fixup_stereo_dmic, 4431 + }, 4445 4432 }; 4446 4433 4447 4434 static const struct snd_pci_quirk cxt5051_fixups[] = { ··· 4465 4432 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 4466 4433 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 4467 4434 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 4435 + SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 4468 4436 {} 4469 4437 }; 4470 4438 ··· 4505 4471 case 0x14f15051: 4506 4472 add_cx5051_fake_mutes(codec); 4507 4473 codec->pin_amp_workaround = 1; 4508 - apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); 4474 + snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups); 4509 4475 break; 4510 4476 default: 4511 4477 codec->pin_amp_workaround = 1; 4512 - apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); 4478 + snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups); 4479 + break; 4513 4480 } 4481 + 4482 + snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 4514 4483 4515 4484 /* Show mute-led control only on HP laptops 4516 4485 * This is a sort of white-list: on HP laptops, EAPD corresponds ··· 4593 4556 .patch = patch_conexant_auto }, 4594 4557 { .id = 0x14f150b9, .name = "CX20665", 4595 4558 .patch = patch_conexant_auto }, 4559 + { .id = 0x14f1510f, .name = "CX20751/2", 4560 + .patch = patch_conexant_auto }, 4561 + { .id = 0x14f15110, .name = "CX20751/2", 4562 + .patch = patch_conexant_auto }, 4563 + { .id = 0x14f15111, .name = "CX20753/4", 4564 + .patch = patch_conexant_auto }, 4596 4565 {} /* terminator */ 4597 4566 }; 4598 4567 ··· 4619 4576 MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4620 4577 MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4621 4578 MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 4579 + MODULE_ALIAS("snd-hda-codec-id:14f1510f"); 4580 + MODULE_ALIAS("snd-hda-codec-id:14f15110"); 4581 + MODULE_ALIAS("snd-hda-codec-id:14f15111"); 4622 4582 4623 4583 MODULE_LICENSE("GPL"); 4624 4584 MODULE_DESCRIPTION("Conexant HD-audio codec");
+2 -2
sound/pci/hda/patch_hdmi.c
··· 1592 1592 unsigned int dataDCC2, channel_id; 1593 1593 int i; 1594 1594 struct hdmi_spec *spec = codec->spec; 1595 - struct hda_spdif_out *spdif = 1596 - snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid); 1595 + struct hda_spdif_out *spdif; 1597 1596 1598 1597 mutex_lock(&codec->spdif_mutex); 1598 + spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid); 1599 1599 1600 1600 chs = substream->runtime->channels; 1601 1601
+130 -335
sound/pci/hda/patch_realtek.c
··· 32 32 #include <sound/jack.h> 33 33 #include "hda_codec.h" 34 34 #include "hda_local.h" 35 + #include "hda_auto_parser.h" 35 36 #include "hda_beep.h" 36 37 #include "hda_jack.h" 37 38 ··· 67 66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ 68 67 }; 69 68 70 - struct alc_fixup; 71 - 72 69 struct alc_multi_io { 73 70 hda_nid_t pin; /* multi-io widget pin NID */ 74 71 hda_nid_t dac; /* DAC to be connected */ ··· 81 82 82 83 #define MAX_VOL_NIDS 0x40 83 84 85 + /* make compatible with old code */ 86 + #define alc_apply_pincfgs snd_hda_apply_pincfgs 87 + #define alc_apply_fixup snd_hda_apply_fixup 88 + #define alc_pick_fixup snd_hda_pick_fixup 89 + #define alc_fixup hda_fixup 90 + #define alc_pincfg hda_pintbl 91 + #define alc_model_fixup hda_model_fixup 92 + 93 + #define ALC_FIXUP_PINS HDA_FIXUP_PINS 94 + #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS 95 + #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC 96 + 97 + #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE 98 + #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE 99 + #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT 100 + #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD 101 + 102 + 84 103 struct alc_spec { 104 + struct hda_gen_spec gen; 105 + 85 106 /* codec parameterization */ 86 107 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 87 108 unsigned int num_mixers; 88 109 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ 89 110 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 90 - 91 - const struct hda_verb *init_verbs[10]; /* initialization verbs 92 - * don't forget NULL 93 - * termination! 94 - */ 95 - unsigned int num_init_verbs; 96 111 97 112 char stream_name_analog[32]; /* analog PCM stream */ 98 113 const struct hda_pcm_stream *stream_analog_playback; ··· 223 210 unsigned int pll_coef_idx, pll_coef_bit; 224 211 unsigned int coef0; 225 212 226 - /* fix-up list */ 227 - int fixup_id; 228 - const struct alc_fixup *fixup_list; 229 - const char *fixup_name; 230 - 231 213 /* multi-io */ 232 214 int multi_ios; 233 215 struct alc_multi_io multi_io[4]; ··· 327 319 328 320 /* for shared I/O, change the pin-control accordingly */ 329 321 if (spec->shared_mic_hp) { 322 + unsigned int val; 323 + hda_nid_t pin = spec->autocfg.inputs[1].pin; 330 324 /* NOTE: this assumes that there are only two inputs, the 331 325 * first is the real internal mic and the second is HP jack. 332 326 */ 333 - snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, 334 - AC_VERB_SET_PIN_WIDGET_CONTROL, 335 - spec->cur_mux[adc_idx] ? 336 - PIN_VREF80 : PIN_HP); 327 + if (spec->cur_mux[adc_idx]) 328 + val = snd_hda_get_default_vref(codec, pin) | PIN_IN; 329 + else 330 + val = PIN_HP; 331 + snd_hda_set_pin_ctl(codec, pin, val); 337 332 spec->automute_speaker = !spec->cur_mux[adc_idx]; 338 333 call_update_outputs(codec); 339 334 } ··· 349 338 nid = get_capsrc(spec, adc_idx); 350 339 351 340 /* no selection? */ 352 - num_conns = snd_hda_get_conn_list(codec, nid, NULL); 341 + num_conns = snd_hda_get_num_conns(codec, nid); 353 342 if (num_conns <= 1) 354 343 return 1; 355 344 ··· 387 376 int auto_pin_type) 388 377 { 389 378 unsigned int val = PIN_IN; 390 - 391 - if (auto_pin_type == AUTO_PIN_MIC) { 392 - unsigned int pincap; 393 - unsigned int oldval; 394 - oldval = snd_hda_codec_read(codec, nid, 0, 395 - AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 396 - pincap = snd_hda_query_pin_caps(codec, nid); 397 - pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; 398 - /* if the default pin setup is vref50, we give it priority */ 399 - if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) 400 - val = PIN_VREF80; 401 - else if (pincap & AC_PINCAP_VREF_50) 402 - val = PIN_VREF50; 403 - else if (pincap & AC_PINCAP_VREF_100) 404 - val = PIN_VREF100; 405 - else if (pincap & AC_PINCAP_VREF_GRD) 406 - val = PIN_VREFGRD; 407 - } 408 - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); 379 + if (auto_pin_type == AUTO_PIN_MIC) 380 + val |= snd_hda_get_default_vref(codec, nid); 381 + snd_hda_set_pin_ctl(codec, nid, val); 409 382 } 410 383 411 384 /* ··· 402 407 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) 403 408 return; 404 409 spec->mixers[spec->num_mixers++] = mix; 405 - } 406 - 407 - static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) 408 - { 409 - if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) 410 - return; 411 - spec->init_verbs[spec->num_init_verbs++] = verb; 412 410 } 413 411 414 412 /* ··· 505 517 } else 506 518 val = 0; 507 519 val |= pin_bits; 508 - snd_hda_codec_write(codec, nid, 0, 509 - AC_VERB_SET_PIN_WIDGET_CONTROL, 510 - val); 520 + snd_hda_set_pin_ctl(codec, nid, val); 511 521 break; 512 522 case ALC_AUTOMUTE_AMP: 513 523 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, ··· 1186 1200 */ 1187 1201 #define ALC_FIXUP_SKU_IGNORE (2) 1188 1202 1203 + static void alc_fixup_sku_ignore(struct hda_codec *codec, 1204 + const struct hda_fixup *fix, int action) 1205 + { 1206 + struct alc_spec *spec = codec->spec; 1207 + if (action == HDA_FIXUP_ACT_PRE_PROBE) { 1208 + spec->cdefine.fixup = 1; 1209 + spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE; 1210 + } 1211 + } 1212 + 1189 1213 static int alc_auto_parse_customize_define(struct hda_codec *codec) 1190 1214 { 1191 1215 unsigned int ass, tmp, i; ··· 1399 1403 } 1400 1404 1401 1405 /* 1402 - * Fix-up pin default configurations and add default verbs 1403 - */ 1404 - 1405 - struct alc_pincfg { 1406 - hda_nid_t nid; 1407 - u32 val; 1408 - }; 1409 - 1410 - struct alc_model_fixup { 1411 - const int id; 1412 - const char *name; 1413 - }; 1414 - 1415 - struct alc_fixup { 1416 - int type; 1417 - bool chained; 1418 - int chain_id; 1419 - union { 1420 - unsigned int sku; 1421 - const struct alc_pincfg *pins; 1422 - const struct hda_verb *verbs; 1423 - void (*func)(struct hda_codec *codec, 1424 - const struct alc_fixup *fix, 1425 - int action); 1426 - } v; 1427 - }; 1428 - 1429 - enum { 1430 - ALC_FIXUP_INVALID, 1431 - ALC_FIXUP_SKU, 1432 - ALC_FIXUP_PINS, 1433 - ALC_FIXUP_VERBS, 1434 - ALC_FIXUP_FUNC, 1435 - }; 1436 - 1437 - enum { 1438 - ALC_FIXUP_ACT_PRE_PROBE, 1439 - ALC_FIXUP_ACT_PROBE, 1440 - ALC_FIXUP_ACT_INIT, 1441 - ALC_FIXUP_ACT_BUILD, 1442 - }; 1443 - 1444 - static void alc_apply_pincfgs(struct hda_codec *codec, 1445 - const struct alc_pincfg *cfg) 1446 - { 1447 - for (; cfg->nid; cfg++) 1448 - snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 1449 - } 1450 - 1451 - static void alc_apply_fixup(struct hda_codec *codec, int action) 1452 - { 1453 - struct alc_spec *spec = codec->spec; 1454 - int id = spec->fixup_id; 1455 - #ifdef CONFIG_SND_DEBUG_VERBOSE 1456 - const char *modelname = spec->fixup_name; 1457 - #endif 1458 - int depth = 0; 1459 - 1460 - if (!spec->fixup_list) 1461 - return; 1462 - 1463 - while (id >= 0) { 1464 - const struct alc_fixup *fix = spec->fixup_list + id; 1465 - const struct alc_pincfg *cfg; 1466 - 1467 - switch (fix->type) { 1468 - case ALC_FIXUP_SKU: 1469 - if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) 1470 - break; 1471 - snd_printdd(KERN_INFO "hda_codec: %s: " 1472 - "Apply sku override for %s\n", 1473 - codec->chip_name, modelname); 1474 - spec->cdefine.sku_cfg = fix->v.sku; 1475 - spec->cdefine.fixup = 1; 1476 - break; 1477 - case ALC_FIXUP_PINS: 1478 - cfg = fix->v.pins; 1479 - if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) 1480 - break; 1481 - snd_printdd(KERN_INFO "hda_codec: %s: " 1482 - "Apply pincfg for %s\n", 1483 - codec->chip_name, modelname); 1484 - alc_apply_pincfgs(codec, cfg); 1485 - break; 1486 - case ALC_FIXUP_VERBS: 1487 - if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) 1488 - break; 1489 - snd_printdd(KERN_INFO "hda_codec: %s: " 1490 - "Apply fix-verbs for %s\n", 1491 - codec->chip_name, modelname); 1492 - add_verb(codec->spec, fix->v.verbs); 1493 - break; 1494 - case ALC_FIXUP_FUNC: 1495 - if (!fix->v.func) 1496 - break; 1497 - snd_printdd(KERN_INFO "hda_codec: %s: " 1498 - "Apply fix-func for %s\n", 1499 - codec->chip_name, modelname); 1500 - fix->v.func(codec, fix, action); 1501 - break; 1502 - default: 1503 - snd_printk(KERN_ERR "hda_codec: %s: " 1504 - "Invalid fixup type %d\n", 1505 - codec->chip_name, fix->type); 1506 - break; 1507 - } 1508 - if (!fix->chained) 1509 - break; 1510 - if (++depth > 10) 1511 - break; 1512 - id = fix->chain_id; 1513 - } 1514 - } 1515 - 1516 - static void alc_pick_fixup(struct hda_codec *codec, 1517 - const struct alc_model_fixup *models, 1518 - const struct snd_pci_quirk *quirk, 1519 - const struct alc_fixup *fixlist) 1520 - { 1521 - struct alc_spec *spec = codec->spec; 1522 - const struct snd_pci_quirk *q; 1523 - int id = -1; 1524 - const char *name = NULL; 1525 - 1526 - /* when model=nofixup is given, don't pick up any fixups */ 1527 - if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { 1528 - spec->fixup_list = NULL; 1529 - spec->fixup_id = -1; 1530 - return; 1531 - } 1532 - 1533 - if (codec->modelname && models) { 1534 - while (models->name) { 1535 - if (!strcmp(codec->modelname, models->name)) { 1536 - id = models->id; 1537 - name = models->name; 1538 - break; 1539 - } 1540 - models++; 1541 - } 1542 - } 1543 - if (id < 0) { 1544 - q = snd_pci_quirk_lookup(codec->bus->pci, quirk); 1545 - if (q) { 1546 - id = q->value; 1547 - #ifdef CONFIG_SND_DEBUG_VERBOSE 1548 - name = q->name; 1549 - #endif 1550 - } 1551 - } 1552 - if (id < 0) { 1553 - for (q = quirk; q->subvendor; q++) { 1554 - unsigned int vendorid = 1555 - q->subdevice | (q->subvendor << 16); 1556 - if (vendorid == codec->subsystem_id) { 1557 - id = q->value; 1558 - #ifdef CONFIG_SND_DEBUG_VERBOSE 1559 - name = q->name; 1560 - #endif 1561 - break; 1562 - } 1563 - } 1564 - } 1565 - 1566 - spec->fixup_id = id; 1567 - if (id >= 0) { 1568 - spec->fixup_list = fixlist; 1569 - spec->fixup_name = name; 1570 - } 1571 - } 1572 - 1573 - /* 1574 1406 * COEF access helper functions 1575 1407 */ 1576 1408 static int alc_read_coef_idx(struct hda_codec *codec, ··· 1445 1621 pin = spec->autocfg.dig_out_pins[i]; 1446 1622 if (!pin) 1447 1623 continue; 1448 - snd_hda_codec_write(codec, pin, 0, 1449 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 1624 + snd_hda_set_pin_ctl(codec, pin, PIN_OUT); 1450 1625 if (!i) 1451 1626 dac = spec->multiout.dig_out_nid; 1452 1627 else ··· 1458 1635 } 1459 1636 pin = spec->autocfg.dig_in_pin; 1460 1637 if (pin) 1461 - snd_hda_codec_write(codec, pin, 0, 1462 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1463 - PIN_IN); 1638 + snd_hda_set_pin_ctl(codec, pin, PIN_IN); 1464 1639 } 1465 1640 1466 1641 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ ··· 1889 2068 static int alc_init(struct hda_codec *codec) 1890 2069 { 1891 2070 struct alc_spec *spec = codec->spec; 1892 - unsigned int i; 1893 2071 1894 2072 if (spec->init_hook) 1895 2073 spec->init_hook(codec); ··· 1896 2076 alc_fix_pll(codec); 1897 2077 alc_auto_init_amp(codec, spec->init_amp); 1898 2078 1899 - for (i = 0; i < spec->num_init_verbs; i++) 1900 - snd_hda_sequence_write(codec, spec->init_verbs[i]); 1901 2079 alc_init_special_input_src(codec); 1902 2080 alc_auto_init_std(codec); 1903 2081 ··· 2543 2725 nid = codec->start_nid; 2544 2726 for (i = 0; i < codec->num_nodes; i++, nid++) { 2545 2727 hda_nid_t src; 2546 - const hda_nid_t *list; 2547 2728 unsigned int caps = get_wcaps(codec, nid); 2548 2729 int type = get_wcaps_type(caps); 2549 2730 ··· 2560 2743 cap_nids[nums] = src; 2561 2744 break; 2562 2745 } 2563 - n = snd_hda_get_conn_list(codec, src, &list); 2746 + n = snd_hda_get_num_conns(codec, src); 2564 2747 if (n > 1) { 2565 2748 cap_nids[nums] = src; 2566 2749 break; 2567 2750 } else if (n != 1) 2568 2751 break; 2569 - src = *list; 2752 + if (snd_hda_get_connections(codec, src, &src, 1) != 1) 2753 + break; 2570 2754 } 2571 2755 if (++nums >= max_nums) 2572 2756 break; ··· 2674 2856 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, 2675 2857 unsigned int pin_type) 2676 2858 { 2677 - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2678 - pin_type); 2859 + snd_hda_set_pin_ctl(codec, nid, pin_type); 2679 2860 /* unmute pin */ 2680 2861 if (nid_has_mute(codec, nid, HDA_OUTPUT)) 2681 2862 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, ··· 2708 2891 2709 2892 /* mute all loopback inputs */ 2710 2893 if (spec->mixer_nid) { 2711 - int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); 2894 + int nums = snd_hda_get_num_conns(codec, spec->mixer_nid); 2712 2895 for (i = 0; i < nums; i++) 2713 2896 snd_hda_codec_write(codec, spec->mixer_nid, 0, 2714 2897 AC_VERB_SET_AMP_GAIN_MUTE, ··· 3338 3521 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { 3339 3522 type = ALC_CTL_WIDGET_MUTE; 3340 3523 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); 3341 - } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { 3524 + } else if (snd_hda_get_num_conns(codec, nid) == 1) { 3342 3525 type = ALC_CTL_WIDGET_MUTE; 3343 3526 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); 3344 3527 } else { ··· 3815 3998 snd_hda_codec_read(codec, nid, 0, 3816 3999 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3817 4000 if (output) { 3818 - snd_hda_codec_update_cache(codec, nid, 0, 3819 - AC_VERB_SET_PIN_WIDGET_CONTROL, 3820 - PIN_OUT); 4001 + snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); 3821 4002 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 3822 4003 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, 3823 4004 HDA_AMP_MUTE, 0); ··· 3824 4009 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 3825 4010 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, 3826 4011 HDA_AMP_MUTE, HDA_AMP_MUTE); 3827 - snd_hda_codec_update_cache(codec, nid, 0, 3828 - AC_VERB_SET_PIN_WIDGET_CONTROL, 3829 - spec->multi_io[idx].ctl_in); 4012 + snd_hda_set_pin_ctl_cache(codec, nid, 4013 + spec->multi_io[idx].ctl_in); 3830 4014 } 3831 4015 return 0; 3832 4016 } ··· 3898 4084 nums = 0; 3899 4085 for (n = 0; n < spec->num_adc_nids; n++) { 3900 4086 hda_nid_t cap = spec->private_capsrc_nids[n]; 3901 - int num_conns = snd_hda_get_conn_list(codec, cap, NULL); 4087 + int num_conns = snd_hda_get_num_conns(codec, cap); 3902 4088 for (i = 0; i < imux->num_items; i++) { 3903 4089 hda_nid_t pin = spec->imux_pins[i]; 3904 4090 if (pin) { ··· 4027 4213 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { 4028 4214 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, 4029 4215 HDA_AMP_MUTE, 0); 4030 - } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { 4216 + } else if (snd_hda_get_num_conns(codec, cap) > 1) { 4031 4217 snd_hda_codec_write_cache(codec, cap, 0, 4032 4218 AC_VERB_SET_CONNECT_SEL, idx); 4033 4219 } ··· 4239 4425 set_capture_mixer(codec); 4240 4426 4241 4427 return 1; 4428 + } 4429 + 4430 + /* common preparation job for alc_spec */ 4431 + static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) 4432 + { 4433 + struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4434 + int err; 4435 + 4436 + if (!spec) 4437 + return -ENOMEM; 4438 + codec->spec = spec; 4439 + spec->mixer_nid = mixer_nid; 4440 + 4441 + err = alc_codec_rename_from_preset(codec); 4442 + if (err < 0) { 4443 + kfree(spec); 4444 + return err; 4445 + } 4446 + return 0; 4242 4447 } 4243 4448 4244 4449 static int alc880_parse_auto_config(struct hda_codec *codec) ··· 4641 4808 struct alc_spec *spec; 4642 4809 int err; 4643 4810 4644 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4645 - if (spec == NULL) 4646 - return -ENOMEM; 4811 + err = alc_alloc_spec(codec, 0x0b); 4812 + if (err < 0) 4813 + return err; 4647 4814 4648 - codec->spec = spec; 4649 - 4650 - spec->mixer_nid = 0x0b; 4815 + spec = codec->spec; 4651 4816 spec->need_dac_fix = 1; 4652 4817 4653 4818 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, ··· 4721 4890 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ 4722 4891 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); 4723 4892 spec->unsol_event = alc_sku_unsol_event; 4724 - add_verb(codec->spec, alc_gpio1_init_verbs); 4893 + snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); 4725 4894 } 4726 4895 } 4727 4896 ··· 4832 5001 struct alc_spec *spec; 4833 5002 int err; 4834 5003 4835 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4836 - if (spec == NULL) 4837 - return -ENOMEM; 5004 + err = alc_alloc_spec(codec, 0x07); 5005 + if (err < 0) 5006 + return err; 4838 5007 4839 - codec->spec = spec; 4840 - 4841 - spec->mixer_nid = 0x07; 5008 + spec = codec->spec; 4842 5009 4843 5010 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); 4844 5011 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); ··· 5000 5171 val = snd_hda_codec_read(codec, nids[i], 0, 5001 5172 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 5002 5173 val |= AC_PINCTL_VREF_80; 5003 - snd_hda_codec_write(codec, nids[i], 0, 5004 - AC_VERB_SET_PIN_WIDGET_CONTROL, val); 5174 + snd_hda_set_pin_ctl(codec, nids[i], val); 5005 5175 spec->keep_vref_in_automute = 1; 5006 5176 break; 5007 5177 } ··· 5021 5193 val = snd_hda_codec_read(codec, nids[i], 0, 5022 5194 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 5023 5195 val |= AC_PINCTL_VREF_50; 5024 - snd_hda_codec_write(codec, nids[i], 0, 5025 - AC_VERB_SET_PIN_WIDGET_CONTROL, val); 5196 + snd_hda_set_pin_ctl(codec, nids[i], val); 5026 5197 } 5027 5198 spec->keep_vref_in_automute = 1; 5028 5199 } ··· 5052 5225 } 5053 5226 }, 5054 5227 [ALC882_FIXUP_ACER_ASPIRE_7736] = { 5055 - .type = ALC_FIXUP_SKU, 5056 - .v.sku = ALC_FIXUP_SKU_IGNORE, 5228 + .type = ALC_FIXUP_FUNC, 5229 + .v.func = alc_fixup_sku_ignore, 5057 5230 }, 5058 5231 [ALC882_FIXUP_ASUS_W90V] = { 5059 5232 .type = ALC_FIXUP_PINS, ··· 5303 5476 struct alc_spec *spec; 5304 5477 int err; 5305 5478 5306 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5307 - if (spec == NULL) 5308 - return -ENOMEM; 5479 + err = alc_alloc_spec(codec, 0x0b); 5480 + if (err < 0) 5481 + return err; 5309 5482 5310 - codec->spec = spec; 5311 - 5312 - spec->mixer_nid = 0x0b; 5483 + spec = codec->spec; 5313 5484 5314 5485 switch (codec->vendor_id) { 5315 5486 case 0x10ec0882: ··· 5318 5493 alc_fix_pll_init(codec, 0x20, 0x0a, 10); 5319 5494 break; 5320 5495 } 5321 - 5322 - err = alc_codec_rename_from_preset(codec); 5323 - if (err < 0) 5324 - goto error; 5325 5496 5326 5497 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, 5327 5498 alc882_fixups); ··· 5442 5621 struct alc_spec *spec; 5443 5622 int err; 5444 5623 5445 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5446 - if (spec == NULL) 5447 - return -ENOMEM; 5624 + err = alc_alloc_spec(codec, 0x0b); 5625 + if (err < 0) 5626 + return err; 5448 5627 5449 - codec->spec = spec; 5450 - 5451 - spec->mixer_nid = 0x0b; 5628 + spec = codec->spec; 5452 5629 5453 5630 #if 0 5454 5631 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is ··· 5529 5710 if (err > 0) { 5530 5711 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { 5531 5712 add_mixer(spec, alc268_beep_mixer); 5532 - add_verb(spec, alc268_beep_init_verbs); 5713 + snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); 5533 5714 } 5534 5715 } 5535 5716 return err; ··· 5542 5723 struct alc_spec *spec; 5543 5724 int i, has_beep, err; 5544 5725 5545 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5546 - if (spec == NULL) 5547 - return -ENOMEM; 5548 - 5549 - codec->spec = spec; 5550 - 5551 5726 /* ALC268 has no aa-loopback mixer */ 5727 + err = alc_alloc_spec(codec, 0); 5728 + if (err < 0) 5729 + return err; 5730 + 5731 + spec = codec->spec; 5552 5732 5553 5733 /* automatic parse from the BIOS config */ 5554 5734 err = alc268_parse_auto_config(codec); ··· 5764 5946 { 5765 5947 struct hda_codec *codec = private_data; 5766 5948 unsigned int pinval = enabled ? 0x20 : 0x24; 5767 - snd_hda_codec_update_cache(codec, 0x19, 0, 5768 - AC_VERB_SET_PIN_WIDGET_CONTROL, 5769 - pinval); 5949 + snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); 5770 5950 } 5771 5951 5772 5952 static void alc269_fixup_mic2_mute(struct hda_codec *codec, ··· 5831 6015 } 5832 6016 }, 5833 6017 [ALC269_FIXUP_SKU_IGNORE] = { 5834 - .type = ALC_FIXUP_SKU, 5835 - .v.sku = ALC_FIXUP_SKU_IGNORE, 6018 + .type = ALC_FIXUP_FUNC, 6019 + .v.func = alc_fixup_sku_ignore, 5836 6020 }, 5837 6021 [ALC269_FIXUP_ASUS_G73JW] = { 5838 6022 .type = ALC_FIXUP_PINS, ··· 6058 6242 static int patch_alc269(struct hda_codec *codec) 6059 6243 { 6060 6244 struct alc_spec *spec; 6061 - int err = 0; 6245 + int err; 6062 6246 6063 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6064 - if (spec == NULL) 6065 - return -ENOMEM; 6066 - 6067 - codec->spec = spec; 6068 - 6069 - spec->mixer_nid = 0x0b; 6070 - 6071 - err = alc_codec_rename_from_preset(codec); 6247 + err = alc_alloc_spec(codec, 0x0b); 6072 6248 if (err < 0) 6073 - goto error; 6249 + return err; 6250 + 6251 + spec = codec->spec; 6074 6252 6075 6253 if (codec->vendor_id == 0x10ec0269) { 6076 6254 spec->codec_variant = ALC269_TYPE_ALC269VA; ··· 6156 6346 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) 6157 6347 val |= AC_PINCTL_IN_EN; 6158 6348 val |= AC_PINCTL_VREF_50; 6159 - snd_hda_codec_write(codec, 0x0f, 0, 6160 - AC_VERB_SET_PIN_WIDGET_CONTROL, val); 6349 + snd_hda_set_pin_ctl(codec, 0x0f, val); 6161 6350 spec->keep_vref_in_automute = 1; 6162 6351 } 6163 6352 ··· 6210 6401 struct alc_spec *spec; 6211 6402 int err; 6212 6403 6213 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6214 - if (spec == NULL) 6215 - return -ENOMEM; 6404 + err = alc_alloc_spec(codec, 0x15); 6405 + if (err < 0) 6406 + return err; 6216 6407 6217 - codec->spec = spec; 6218 - 6219 - spec->mixer_nid = 0x15; 6408 + spec = codec->spec; 6220 6409 6221 6410 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); 6222 6411 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); ··· 6311 6504 struct alc_spec *spec; 6312 6505 int err; 6313 6506 6314 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6315 - if (spec == NULL) 6316 - return -ENOMEM; 6507 + err = alc_alloc_spec(codec, 0x0b); 6508 + if (err < 0) 6509 + return err; 6317 6510 6318 - codec->spec = spec; 6319 - 6320 - spec->mixer_nid = 0x0b; 6511 + spec = codec->spec; 6321 6512 6322 6513 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); 6323 6514 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); ··· 6327 6522 6328 6523 if (codec->vendor_id == 0x10ec0660) { 6329 6524 /* always turn on EAPD */ 6330 - add_verb(spec, alc660vd_eapd_verbs); 6525 + snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs); 6331 6526 } 6332 6527 6333 6528 if (!spec->no_analog) { ··· 6440 6635 } 6441 6636 }, 6442 6637 [ALC662_FIXUP_SKU_IGNORE] = { 6443 - .type = ALC_FIXUP_SKU, 6444 - .v.sku = ALC_FIXUP_SKU_IGNORE, 6638 + .type = ALC_FIXUP_FUNC, 6639 + .v.func = alc_fixup_sku_ignore, 6445 6640 }, 6446 6641 [ALC662_FIXUP_HP_RP5800] = { 6447 6642 .type = ALC_FIXUP_PINS, ··· 6654 6849 static int patch_alc662(struct hda_codec *codec) 6655 6850 { 6656 6851 struct alc_spec *spec; 6657 - int err = 0; 6852 + int err; 6658 6853 6659 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6660 - if (!spec) 6661 - return -ENOMEM; 6854 + err = alc_alloc_spec(codec, 0x0b); 6855 + if (err < 0) 6856 + return err; 6662 6857 6663 - codec->spec = spec; 6664 - 6665 - spec->mixer_nid = 0x0b; 6858 + spec = codec->spec; 6666 6859 6667 6860 /* handle multiple HPs as is */ 6668 6861 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; 6669 6862 6670 6863 alc_fix_pll_init(codec, 0x20, 0x04, 15); 6671 - 6672 - err = alc_codec_rename_from_preset(codec); 6673 - if (err < 0) 6674 - goto error; 6675 6864 6676 6865 if ((alc_get_coef0(codec) & (1 << 14)) && 6677 6866 codec->bus->pci->subsystem_vendor == 0x1025 && ··· 6729 6930 */ 6730 6931 static int patch_alc680(struct hda_codec *codec) 6731 6932 { 6732 - struct alc_spec *spec; 6733 6933 int err; 6734 6934 6735 - spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6736 - if (spec == NULL) 6737 - return -ENOMEM; 6738 - 6739 - codec->spec = spec; 6740 - 6741 6935 /* ALC680 has no aa-loopback mixer */ 6936 + err = alc_alloc_spec(codec, 0); 6937 + if (err < 0) 6938 + return err; 6742 6939 6743 6940 /* automatic parse from the BIOS config */ 6744 6941 err = alc680_parse_auto_config(codec);
+44 -76
sound/pci/hda/patch_sigmatel.c
··· 36 36 #include <sound/tlv.h> 37 37 #include "hda_codec.h" 38 38 #include "hda_local.h" 39 + #include "hda_auto_parser.h" 39 40 #include "hda_beep.h" 40 41 #include "hda_jack.h" 41 42 ··· 222 221 unsigned char aloopback_shift; 223 222 224 223 /* power management */ 224 + unsigned int power_map_bits; 225 225 unsigned int num_pwrs; 226 226 const hda_nid_t *pwr_nids; 227 227 const hda_nid_t *dac_list; ··· 315 313 316 314 struct hda_vmaster_mute_hook vmaster_mute; 317 315 }; 316 + 317 + #define AC_VERB_IDT_SET_POWER_MAP 0x7ec 318 + #define AC_VERB_IDT_GET_POWER_MAP 0xfec 318 319 319 320 static const hda_nid_t stac9200_adc_nids[1] = { 320 321 0x03, ··· 686 681 pinctl &= ~AC_PINCTL_VREFEN; 687 682 pinctl |= (new_vref & AC_PINCTL_VREFEN); 688 683 689 - error = snd_hda_codec_write_cache(codec, nid, 0, 690 - AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); 684 + error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl); 691 685 if (error < 0) 692 686 return error; 693 687 ··· 710 706 else 711 707 pincfg |= AC_PINCTL_IN_EN; 712 708 713 - error = snd_hda_codec_write_cache(codec, nid, 0, 714 - AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg); 709 + error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg); 715 710 if (error < 0) 716 711 return error; 717 712 else ··· 2508 2505 return 0; 2509 2506 } 2510 2507 2511 - static unsigned int stac92xx_get_default_vref(struct hda_codec *codec, 2512 - hda_nid_t nid) 2513 - { 2514 - unsigned int pincap = snd_hda_query_pin_caps(codec, nid); 2515 - pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; 2516 - if (pincap & AC_PINCAP_VREF_100) 2517 - return AC_PINCTL_VREF_100; 2518 - if (pincap & AC_PINCAP_VREF_80) 2519 - return AC_PINCTL_VREF_80; 2520 - if (pincap & AC_PINCAP_VREF_50) 2521 - return AC_PINCTL_VREF_50; 2522 - if (pincap & AC_PINCAP_VREF_GRD) 2523 - return AC_PINCTL_VREF_GRD; 2524 - return 0; 2525 - } 2526 - 2527 2508 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) 2528 2509 2529 2510 { 2530 - snd_hda_codec_write_cache(codec, nid, 0, 2531 - AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 2511 + snd_hda_set_pin_ctl_cache(codec, nid, pin_type); 2532 2512 } 2533 2513 2534 2514 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info ··· 2580 2594 hda_nid_t nid = kcontrol->private_value; 2581 2595 unsigned int vref = stac92xx_vref_get(codec, nid); 2582 2596 2583 - if (vref == stac92xx_get_default_vref(codec, nid)) 2597 + if (vref == snd_hda_get_default_vref(codec, nid)) 2584 2598 ucontrol->value.enumerated.item[0] = 0; 2585 2599 else if (vref == AC_PINCTL_VREF_GRD) 2586 2600 ucontrol->value.enumerated.item[0] = 1; ··· 2599 2613 hda_nid_t nid = kcontrol->private_value; 2600 2614 2601 2615 if (ucontrol->value.enumerated.item[0] == 0) 2602 - new_vref = stac92xx_get_default_vref(codec, nid); 2616 + new_vref = snd_hda_get_default_vref(codec, nid); 2603 2617 else if (ucontrol->value.enumerated.item[0] == 1) 2604 2618 new_vref = AC_PINCTL_VREF_GRD; 2605 2619 else if (ucontrol->value.enumerated.item[0] == 2) ··· 2665 2679 else { 2666 2680 unsigned int pinctl = AC_PINCTL_IN_EN; 2667 2681 if (io_idx) /* set VREF for mic */ 2668 - pinctl |= stac92xx_get_default_vref(codec, nid); 2682 + pinctl |= snd_hda_get_default_vref(codec, nid); 2669 2683 stac92xx_auto_set_pinctl(codec, nid, pinctl); 2670 2684 } 2671 2685 ··· 2833 2847 char name[22]; 2834 2848 2835 2849 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) { 2836 - if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD 2850 + if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD 2837 2851 && nid == spec->line_switch) 2838 2852 control = STAC_CTL_WIDGET_IO_SWITCH; 2839 2853 else if (snd_hda_query_pin_caps(codec, nid) ··· 4236 4250 val = snd_hda_get_bool_hint(codec, "eapd_switch"); 4237 4251 if (val >= 0) 4238 4252 spec->eapd_switch = val; 4239 - get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity); 4240 - if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) { 4241 - spec->gpio_mask |= spec->gpio_led; 4242 - spec->gpio_dir |= spec->gpio_led; 4243 - if (spec->gpio_led_polarity) 4244 - spec->gpio_data |= spec->gpio_led; 4245 - } 4246 4253 } 4247 4254 4248 4255 static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins, ··· 4333 4354 unsigned int pinctl, conf; 4334 4355 if (type == AUTO_PIN_MIC) { 4335 4356 /* for mic pins, force to initialize */ 4336 - pinctl = stac92xx_get_default_vref(codec, nid); 4357 + pinctl = snd_hda_get_default_vref(codec, nid); 4337 4358 pinctl |= AC_PINCTL_IN_EN; 4338 4359 stac92xx_auto_set_pinctl(codec, nid, pinctl); 4339 4360 } else { ··· 4369 4390 hda_nid_t nid = spec->pwr_nids[i]; 4370 4391 int pinctl, def_conf; 4371 4392 4393 + def_conf = snd_hda_codec_get_pincfg(codec, nid); 4394 + def_conf = get_defcfg_connect(def_conf); 4395 + if (def_conf == AC_JACK_PORT_NONE) { 4396 + /* power off unused ports */ 4397 + stac_toggle_power_map(codec, nid, 0); 4398 + continue; 4399 + } 4372 4400 /* power on when no jack detection is available */ 4373 4401 /* or when the VREF is used for controlling LED */ 4374 4402 if (!spec->hp_detect || 4375 - spec->vref_mute_led_nid == nid) { 4403 + spec->vref_mute_led_nid == nid || 4404 + !is_jack_detectable(codec, nid)) { 4376 4405 stac_toggle_power_map(codec, nid, 1); 4377 4406 continue; 4378 4407 } ··· 4398 4411 stac_toggle_power_map(codec, nid, 1); 4399 4412 continue; 4400 4413 } 4401 - def_conf = snd_hda_codec_get_pincfg(codec, nid); 4402 - def_conf = get_defcfg_connect(def_conf); 4403 - /* skip any ports that don't have jacks since presence 4404 - * detection is useless */ 4405 - if (def_conf != AC_JACK_PORT_NONE && 4406 - !is_jack_detectable(codec, nid)) { 4407 - stac_toggle_power_map(codec, nid, 1); 4408 - continue; 4409 - } 4410 4414 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) { 4411 4415 stac_issue_unsol_event(codec, nid); 4412 4416 continue; ··· 4410 4432 4411 4433 /* sync mute LED */ 4412 4434 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4435 + 4436 + /* sync the power-map */ 4437 + if (spec->num_pwrs) 4438 + snd_hda_codec_write(codec, codec->afg, 0, 4439 + AC_VERB_IDT_SET_POWER_MAP, 4440 + spec->power_map_bits); 4413 4441 if (spec->dac_list) 4414 4442 stac92xx_power_down(codec); 4415 4443 return 0; ··· 4444 4460 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 4445 4461 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid); 4446 4462 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) 4447 - snd_hda_codec_write(codec, pin->nid, 0, 4448 - AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 4463 + snd_hda_set_pin_ctl(codec, pin->nid, 0); 4449 4464 } 4450 4465 } 4451 4466 ··· 4500 4517 4501 4518 pin_ctl |= flag; 4502 4519 if (old_ctl != pin_ctl) 4503 - snd_hda_codec_write_cache(codec, nid, 0, 4504 - AC_VERB_SET_PIN_WIDGET_CONTROL, 4505 - pin_ctl); 4520 + snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl); 4506 4521 } 4507 4522 4508 4523 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, ··· 4509 4528 unsigned int pin_ctl = snd_hda_codec_read(codec, nid, 4510 4529 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); 4511 4530 if (pin_ctl & flag) 4512 - snd_hda_codec_write_cache(codec, nid, 0, 4513 - AC_VERB_SET_PIN_WIDGET_CONTROL, 4514 - pin_ctl & ~flag); 4531 + snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag); 4515 4532 } 4516 4533 4517 4534 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) ··· 4661 4682 4662 4683 idx = 1 << idx; 4663 4684 4664 - val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff; 4685 + val = spec->power_map_bits; 4665 4686 if (enable) 4666 4687 val &= ~idx; 4667 4688 else 4668 4689 val |= idx; 4669 4690 4670 4691 /* power down unused output ports */ 4671 - snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val); 4692 + if (val != spec->power_map_bits) { 4693 + spec->power_map_bits = val; 4694 + snd_hda_codec_write(codec, codec->afg, 0, 4695 + AC_VERB_IDT_SET_POWER_MAP, val); 4696 + } 4672 4697 } 4673 4698 4674 4699 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid) ··· 4849 4866 struct sigmatel_spec *spec = codec->spec; 4850 4867 const struct dmi_device *dev = NULL; 4851 4868 4869 + if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) { 4870 + get_int_hint(codec, "gpio_led_polarity", 4871 + &spec->gpio_led_polarity); 4872 + return 1; 4873 + } 4852 4874 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) { 4853 4875 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, 4854 4876 NULL, dev))) { ··· 4940 4952 { 4941 4953 if (nid == codec->afg) 4942 4954 snd_iprintf(buffer, "Power-Map: 0x%02x\n", 4943 - snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0)); 4955 + snd_hda_codec_read(codec, nid, 0, 4956 + AC_VERB_IDT_GET_POWER_MAP, 0)); 4944 4957 } 4945 4958 4946 4959 static void analog_loop_proc_hook(struct snd_info_buffer *buffer, ··· 4998 5009 return 0; 4999 5010 } 5000 5011 5001 - static int stac92xx_pre_resume(struct hda_codec *codec) 5002 - { 5003 - struct sigmatel_spec *spec = codec->spec; 5004 - 5005 - /* sync mute LED */ 5006 - if (spec->vref_mute_led_nid) 5007 - stac_vrefout_set(codec, spec->vref_mute_led_nid, 5008 - spec->vref_led); 5009 - else if (spec->gpio_led) 5010 - stac_gpio_set(codec, spec->gpio_mask, 5011 - spec->gpio_dir, spec->gpio_data); 5012 - return 0; 5013 - } 5014 - 5015 5012 static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, 5016 5013 unsigned int power_state) 5017 5014 { ··· 5021 5046 #else 5022 5047 #define stac92xx_suspend NULL 5023 5048 #define stac92xx_resume NULL 5024 - #define stac92xx_pre_resume NULL 5025 5049 #define stac92xx_set_power_state NULL 5026 5050 #endif /* CONFIG_PM */ 5027 5051 ··· 5566 5592 codec->patch_ops.set_power_state = 5567 5593 stac92xx_set_power_state; 5568 5594 } 5569 - #ifdef CONFIG_PM 5570 - codec->patch_ops.pre_resume = stac92xx_pre_resume; 5571 - #endif 5572 5595 } 5573 5596 5574 5597 err = stac92xx_parse_auto_config(codec); ··· 5872 5901 codec->patch_ops.set_power_state = 5873 5902 stac92xx_set_power_state; 5874 5903 } 5875 - #ifdef CONFIG_PM 5876 - codec->patch_ops.pre_resume = stac92xx_pre_resume; 5877 - #endif 5878 5904 } 5879 5905 5880 5906 spec->multiout.dac_nids = spec->dac_nids;
+13 -20
sound/pci/hda/patch_via.c
··· 54 54 #include <sound/asoundef.h> 55 55 #include "hda_codec.h" 56 56 #include "hda_local.h" 57 + #include "hda_auto_parser.h" 57 58 #include "hda_jack.h" 58 59 59 60 /* Pin Widget NID */ ··· 485 484 486 485 if (!path) 487 486 return; 488 - num = snd_hda_get_conn_list(codec, mix_nid, NULL); 487 + num = snd_hda_get_num_conns(codec, mix_nid); 489 488 for (i = 0; i < num; i++) { 490 489 if (i == idx) 491 490 val = AMP_IN_UNMUTE(i); ··· 533 532 { 534 533 if (!pin) 535 534 return; 536 - snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 537 - pin_type); 535 + snd_hda_set_pin_ctl(codec, pin, pin_type); 538 536 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) 539 537 snd_hda_codec_write(codec, pin, 0, 540 538 AC_VERB_SET_EAPD_BTLENABLE, 0x02); ··· 662 662 hda_nid_t nid = cfg->inputs[i].pin; 663 663 if (spec->smart51_enabled && is_smart51_pins(codec, nid)) 664 664 ctl = PIN_OUT; 665 - else if (cfg->inputs[i].type == AUTO_PIN_MIC) 666 - ctl = PIN_VREF50; 667 - else 665 + else { 668 666 ctl = PIN_IN; 669 - snd_hda_codec_write(codec, nid, 0, 670 - AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); 667 + if (cfg->inputs[i].type == AUTO_PIN_MIC) 668 + ctl |= snd_hda_get_default_vref(codec, nid); 669 + } 670 + snd_hda_set_pin_ctl(codec, nid, ctl); 671 671 } 672 672 673 673 /* init input-src */ ··· 1006 1006 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 1007 1007 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); 1008 1008 parm |= out_in; 1009 - snd_hda_codec_write(codec, nid, 0, 1010 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1011 - parm); 1009 + snd_hda_set_pin_ctl(codec, nid, parm); 1012 1010 if (out_in == AC_PINCTL_OUT_EN) { 1013 1011 mute_aa_path(codec, 1); 1014 1012 notify_aa_path_ctls(codec); ··· 1645 1647 parm &= ~AC_PINCTL_OUT_EN; 1646 1648 else 1647 1649 parm |= AC_PINCTL_OUT_EN; 1648 - snd_hda_codec_write(codec, pins[i], 0, 1649 - AC_VERB_SET_PIN_WIDGET_CONTROL, parm); 1650 + snd_hda_set_pin_ctl(codec, pins[i], parm); 1650 1651 } 1651 1652 } 1652 1653 ··· 1706 1709 1707 1710 if (gpio_data == 0x02) { 1708 1711 /* unmute line out */ 1709 - snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, 1710 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1712 + snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], 1711 1713 PIN_OUT); 1712 1714 if (vol_counter & 0x20) { 1713 1715 /* decrease volume */ ··· 1724 1728 } 1725 1729 } else if (!(gpio_data & 0x02)) { 1726 1730 /* mute line out */ 1727 - snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, 1728 - AC_VERB_SET_PIN_WIDGET_CONTROL, 1729 - 0); 1731 + snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], 0); 1730 1732 } 1731 1733 } 1732 1734 ··· 2751 2757 struct via_spec *spec = codec->spec; 2752 2758 if (!spec->dig_in_nid) 2753 2759 return; 2754 - snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, 2755 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 2760 + snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN); 2756 2761 } 2757 2762 2758 2763 /* initialize the unsolicited events */