alc_quirks.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Common codes for Realtek codec quirks
  3. * included by patch_realtek.c
  4. */
  5. /*
  6. * configuration template - to be copied to the spec instance
  7. */
  8. struct alc_config_preset {
  9. const struct snd_kcontrol_new *mixers[5]; /* should be identical size
  10. * with spec
  11. */
  12. const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
  13. const struct hda_verb *init_verbs[5];
  14. unsigned int num_dacs;
  15. const hda_nid_t *dac_nids;
  16. hda_nid_t dig_out_nid; /* optional */
  17. hda_nid_t hp_nid; /* optional */
  18. const hda_nid_t *slave_dig_outs;
  19. unsigned int num_adc_nids;
  20. const hda_nid_t *adc_nids;
  21. const hda_nid_t *capsrc_nids;
  22. hda_nid_t dig_in_nid;
  23. unsigned int num_channel_mode;
  24. const struct hda_channel_mode *channel_mode;
  25. int need_dac_fix;
  26. int const_channel_count;
  27. unsigned int num_mux_defs;
  28. const struct hda_input_mux *input_mux;
  29. void (*unsol_event)(struct hda_codec *, unsigned int);
  30. void (*setup)(struct hda_codec *);
  31. void (*init_hook)(struct hda_codec *);
  32. #ifdef CONFIG_SND_HDA_POWER_SAVE
  33. const struct hda_amp_list *loopbacks;
  34. void (*power_hook)(struct hda_codec *codec);
  35. #endif
  36. };
  37. /*
  38. * channel mode setting
  39. */
  40. static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
  41. struct snd_ctl_elem_info *uinfo)
  42. {
  43. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  44. struct alc_spec *spec = codec->spec;
  45. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  46. spec->num_channel_mode);
  47. }
  48. static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
  49. struct snd_ctl_elem_value *ucontrol)
  50. {
  51. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  52. struct alc_spec *spec = codec->spec;
  53. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  54. spec->num_channel_mode,
  55. spec->ext_channel_count);
  56. }
  57. static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
  58. struct snd_ctl_elem_value *ucontrol)
  59. {
  60. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  61. struct alc_spec *spec = codec->spec;
  62. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  63. spec->num_channel_mode,
  64. &spec->ext_channel_count);
  65. if (err >= 0 && !spec->const_channel_count) {
  66. spec->multiout.max_channels = spec->ext_channel_count;
  67. if (spec->need_dac_fix)
  68. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  69. }
  70. return err;
  71. }
  72. static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
  73. {
  74. struct alc_spec *spec = codec->spec;
  75. struct auto_pin_cfg *cfg = &spec->autocfg;
  76. if (!cfg->line_outs) {
  77. while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
  78. cfg->line_out_pins[cfg->line_outs])
  79. cfg->line_outs++;
  80. }
  81. if (!cfg->speaker_outs) {
  82. while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
  83. cfg->speaker_pins[cfg->speaker_outs])
  84. cfg->speaker_outs++;
  85. }
  86. if (!cfg->hp_outs) {
  87. while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
  88. cfg->hp_pins[cfg->hp_outs])
  89. cfg->hp_outs++;
  90. }
  91. }
  92. /*
  93. * set up from the preset table
  94. */
  95. static void setup_preset(struct hda_codec *codec,
  96. const struct alc_config_preset *preset)
  97. {
  98. struct alc_spec *spec = codec->spec;
  99. int i;
  100. for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
  101. add_mixer(spec, preset->mixers[i]);
  102. spec->cap_mixer = preset->cap_mixer;
  103. for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
  104. i++)
  105. add_verb(spec, preset->init_verbs[i]);
  106. spec->channel_mode = preset->channel_mode;
  107. spec->num_channel_mode = preset->num_channel_mode;
  108. spec->need_dac_fix = preset->need_dac_fix;
  109. spec->const_channel_count = preset->const_channel_count;
  110. if (preset->const_channel_count)
  111. spec->multiout.max_channels = preset->const_channel_count;
  112. else
  113. spec->multiout.max_channels = spec->channel_mode[0].channels;
  114. spec->ext_channel_count = spec->channel_mode[0].channels;
  115. spec->multiout.num_dacs = preset->num_dacs;
  116. spec->multiout.dac_nids = preset->dac_nids;
  117. spec->multiout.dig_out_nid = preset->dig_out_nid;
  118. spec->multiout.slave_dig_outs = preset->slave_dig_outs;
  119. spec->multiout.hp_nid = preset->hp_nid;
  120. spec->num_mux_defs = preset->num_mux_defs;
  121. if (!spec->num_mux_defs)
  122. spec->num_mux_defs = 1;
  123. spec->input_mux = preset->input_mux;
  124. spec->num_adc_nids = preset->num_adc_nids;
  125. spec->adc_nids = preset->adc_nids;
  126. spec->capsrc_nids = preset->capsrc_nids;
  127. spec->dig_in_nid = preset->dig_in_nid;
  128. spec->unsol_event = preset->unsol_event;
  129. spec->init_hook = preset->init_hook;
  130. #ifdef CONFIG_SND_HDA_POWER_SAVE
  131. spec->power_hook = preset->power_hook;
  132. spec->loopback.amplist = preset->loopbacks;
  133. #endif
  134. if (preset->setup)
  135. preset->setup(codec);
  136. alc_fixup_autocfg_pin_nums(codec);
  137. }
  138. static void alc_simple_setup_automute(struct alc_spec *spec, int mode)
  139. {
  140. int lo_pin = spec->autocfg.line_out_pins[0];
  141. if (lo_pin == spec->autocfg.speaker_pins[0] ||
  142. lo_pin == spec->autocfg.hp_pins[0])
  143. lo_pin = 0;
  144. spec->automute_mode = mode;
  145. spec->detect_hp = !!spec->autocfg.hp_pins[0];
  146. spec->detect_lo = !!lo_pin;
  147. spec->automute_lo = spec->automute_lo_possible = !!lo_pin;
  148. spec->automute_speaker = spec->automute_speaker_possible = !!spec->autocfg.speaker_pins[0];
  149. }