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

ALSA: hda - Update to use the new jack kctls method

Jack snd_kcontrols can now be created during snd_jack_new()
or by later calling snd_jack_add_new_kctls().

This patch creates the jacks during the initialisation stage
for both phantom and non phantom jacks.

Signed-off-by: Jie Yang <yang.jie@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Jie Yang and committed by
Takashi Iwai
2ba2dfa1 4e3f0dc6

+31 -74
+1 -1
include/sound/control.h
··· 252 252 * Helper functions for jack-detection controls 253 253 */ 254 254 struct snd_kcontrol * 255 - snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card); 255 + snd_kctl_jack_new(const char *name, struct snd_card *card); 256 256 void snd_kctl_jack_report(struct snd_card *card, 257 257 struct snd_kcontrol *kctl, bool status); 258 258
+2 -2
sound/core/ctljack.c
··· 61 61 } 62 62 63 63 struct snd_kcontrol * 64 - snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card) 64 + snd_kctl_jack_new(const char *name, struct snd_card *card) 65 65 { 66 66 struct snd_kcontrol *kctl; 67 67 68 - kctl = snd_ctl_new1(&jack_detect_kctl, private_data); 68 + kctl = snd_ctl_new1(&jack_detect_kctl, NULL); 69 69 if (!kctl) 70 70 return NULL; 71 71
+1 -1
sound/core/jack.c
··· 135 135 struct snd_jack_kctl *jack_kctl; 136 136 int err; 137 137 138 - kctl = snd_kctl_jack_new(name, card, card); 138 + kctl = snd_kctl_jack_new(name, card); 139 139 if (!kctl) 140 140 return NULL; 141 141
+25 -65
sound/pci/hda/hda_jack.c
··· 132 132 133 133 for (i = 0; i < codec->jacktbl.used; i++, jack++) { 134 134 struct hda_jack_callback *cb, *next; 135 - #ifdef CONFIG_SND_HDA_INPUT_JACK 135 + 136 136 /* free jack instances manually when clearing/reconfiguring */ 137 137 if (!codec->bus->shutdown && jack->jack) 138 138 snd_device_free(codec->card, jack->jack); 139 - #endif 139 + 140 140 for (cb = jack->callback; cb; cb = next) { 141 141 next = cb->next; 142 142 kfree(cb); ··· 337 337 jack = codec->jacktbl.list; 338 338 for (i = 0; i < codec->jacktbl.used; i++, jack++) 339 339 if (jack->nid) { 340 - if (!jack->kctl || jack->block_report) 340 + if (!jack->jack || jack->block_report) 341 341 continue; 342 342 state = get_jack_plug_state(jack->pin_sense); 343 - snd_kctl_jack_report(codec->card, jack->kctl, state); 344 - #ifdef CONFIG_SND_HDA_INPUT_JACK 345 - if (jack->jack) 346 - snd_jack_report(jack->jack, 347 - state ? jack->type : 0); 348 - #endif 343 + snd_jack_report(jack->jack, 344 + state ? jack->type : 0); 349 345 } 350 346 } 351 347 EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync); 352 348 353 - #ifdef CONFIG_SND_HDA_INPUT_JACK 354 349 /* guess the jack type from the pin-config */ 355 350 static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) 356 351 { ··· 372 377 jacks->nid = 0; 373 378 jacks->jack = NULL; 374 379 } 375 - #endif 376 380 377 381 /** 378 382 * snd_hda_jack_add_kctl - Add a kctl for the given pin 379 383 * @codec: the HDA codec 380 384 * @nid: pin NID to assign 381 385 * @name: string name for the jack 382 - * @idx: index number for the jack 383 386 * @phantom_jack: flag to deal as a phantom jack 384 387 * 385 388 * This assigns a jack-detection kctl to the given pin. The kcontrol 386 389 * will have the given name and index. 387 390 */ 388 391 static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, 389 - const char *name, int idx, bool phantom_jack) 392 + const char *name, bool phantom_jack) 390 393 { 391 394 struct hda_jack_tbl *jack; 392 - struct snd_kcontrol *kctl; 393 - int err, state; 395 + int err, state, type; 394 396 395 397 jack = snd_hda_jack_tbl_new(codec, nid); 396 398 if (!jack) 397 399 return 0; 398 - if (jack->kctl) 400 + if (jack->jack) 399 401 return 0; /* already created */ 400 - kctl = snd_kctl_jack_new(name, codec, codec->card); 401 - if (!kctl) 402 - return -ENOMEM; 403 - err = snd_hda_ctl_add(codec, nid, kctl); 402 + 403 + type = get_input_jack_type(codec, nid); 404 + err = snd_jack_new(codec->card, name, type, 405 + &jack->jack, true, phantom_jack); 404 406 if (err < 0) 405 407 return err; 406 - jack->kctl = kctl; 407 - jack->phantom_jack = !!phantom_jack; 408 408 409 + jack->phantom_jack = !!phantom_jack; 410 + jack->type = type; 411 + jack->jack->private_data = jack; 412 + jack->jack->private_free = hda_free_jack_priv; 409 413 state = snd_hda_jack_detect(codec, nid); 410 - snd_kctl_jack_report(codec->card, kctl, state); 411 - #ifdef CONFIG_SND_HDA_INPUT_JACK 412 - if (!phantom_jack) { 413 - jack->type = get_input_jack_type(codec, nid); 414 - err = snd_jack_new(codec->card, name, jack->type, 415 - &jack->jack, false, false); 416 - if (err < 0) 417 - return err; 418 - jack->jack->private_data = jack; 419 - jack->jack->private_free = hda_free_jack_priv; 420 - snd_jack_report(jack->jack, state ? jack->type : 0); 421 - } 422 - #endif 414 + snd_jack_report(jack->jack, state ? jack->type : 0); 415 + 423 416 return 0; 424 417 } 425 418 ··· 416 433 * @codec: the HDA codec 417 434 * @nid: pin NID 418 435 * @name: the name string for the jack ctl 419 - * @idx: the ctl index for the jack ctl 420 436 * 421 437 * This is a simple helper calling __snd_hda_jack_add_kctl(). 422 438 */ 423 439 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, 424 - const char *name, int idx) 440 + const char *name) 425 441 { 426 - return __snd_hda_jack_add_kctl(codec, nid, name, idx, false); 442 + return __snd_hda_jack_add_kctl(codec, nid, name, false); 427 443 } 428 444 EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl); 429 - 430 - /* get the unique index number for the given kctl name */ 431 - static int get_unique_index(struct hda_codec *codec, const char *name, int idx) 432 - { 433 - struct hda_jack_tbl *jack; 434 - int i, len = strlen(name); 435 - again: 436 - jack = codec->jacktbl.list; 437 - for (i = 0; i < codec->jacktbl.used; i++, jack++) { 438 - /* jack->kctl.id contains "XXX Jack" name string with index */ 439 - if (jack->kctl && 440 - !strncmp(name, jack->kctl->id.name, len) && 441 - !strcmp(" Jack", jack->kctl->id.name + len) && 442 - jack->kctl->id.index == idx) { 443 - idx++; 444 - goto again; 445 - } 446 - } 447 - return idx; 448 - } 449 445 450 446 static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, 451 447 const struct auto_pin_cfg *cfg, ··· 432 470 { 433 471 unsigned int def_conf, conn; 434 472 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; 435 - int idx, err; 473 + int err; 436 474 bool phantom_jack; 437 475 438 476 if (!nid) ··· 444 482 phantom_jack = (conn != AC_JACK_PORT_COMPLEX) || 445 483 !is_jack_detectable(codec, nid); 446 484 447 - if (base_name) { 485 + if (base_name) 448 486 strlcpy(name, base_name, sizeof(name)); 449 - idx = 0; 450 - } else 451 - snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx); 487 + else 488 + snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), NULL); 452 489 if (phantom_jack) 453 490 /* Example final name: "Internal Mic Phantom Jack" */ 454 491 strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); 455 - idx = get_unique_index(codec, name, idx); 456 - err = __snd_hda_jack_add_kctl(codec, nid, name, idx, phantom_jack); 492 + err = __snd_hda_jack_add_kctl(codec, nid, name, phantom_jack); 457 493 if (err < 0) 458 494 return err; 459 495
+1 -4
sound/pci/hda/hda_jack.h
··· 39 39 unsigned int block_report:1; /* in a transitional state - do not report to userspace */ 40 40 hda_nid_t gating_jack; /* valid when gating jack plugged */ 41 41 hda_nid_t gated_jack; /* gated is dependent on this jack */ 42 - struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */ 43 - #ifdef CONFIG_SND_HDA_INPUT_JACK 44 42 int type; 45 43 struct snd_jack *jack; 46 - #endif 47 44 }; 48 45 49 46 struct hda_jack_tbl * ··· 82 85 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid); 83 86 84 87 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, 85 - const char *name, int idx); 88 + const char *name); 86 89 int snd_hda_jack_add_kctls(struct hda_codec *codec, 87 90 const struct auto_pin_cfg *cfg); 88 91
+1 -1
sound/pci/hda/patch_hdmi.c
··· 2081 2081 strncat(hdmi_str, " Phantom", 2082 2082 sizeof(hdmi_str) - strlen(hdmi_str) - 1); 2083 2083 2084 - return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0); 2084 + return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str); 2085 2085 } 2086 2086 2087 2087 static int generic_hdmi_build_controls(struct hda_codec *codec)