alc260.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. //
  3. // Realtek ALC260 codec
  4. //
  5. #include <linux/init.h>
  6. #include <linux/module.h>
  7. #include "realtek.h"
  8. static int alc260_parse_auto_config(struct hda_codec *codec)
  9. {
  10. static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
  11. static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
  12. return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
  13. }
  14. /*
  15. * Pin config fixes
  16. */
  17. enum {
  18. ALC260_FIXUP_HP_DC5750,
  19. ALC260_FIXUP_HP_PIN_0F,
  20. ALC260_FIXUP_COEF,
  21. ALC260_FIXUP_GPIO1,
  22. ALC260_FIXUP_GPIO1_TOGGLE,
  23. ALC260_FIXUP_REPLACER,
  24. ALC260_FIXUP_HP_B1900,
  25. ALC260_FIXUP_KN1,
  26. ALC260_FIXUP_FSC_S7020,
  27. ALC260_FIXUP_FSC_S7020_JWSE,
  28. ALC260_FIXUP_VAIO_PINS,
  29. };
  30. static void alc260_gpio1_automute(struct hda_codec *codec)
  31. {
  32. struct alc_spec *spec = codec->spec;
  33. alc_update_gpio_data(codec, 0x01, spec->gen.hp_jack_present);
  34. }
  35. static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
  36. const struct hda_fixup *fix, int action)
  37. {
  38. struct alc_spec *spec = codec->spec;
  39. if (action == HDA_FIXUP_ACT_PROBE) {
  40. /* although the machine has only one output pin, we need to
  41. * toggle GPIO1 according to the jack state
  42. */
  43. spec->gen.automute_hook = alc260_gpio1_automute;
  44. spec->gen.detect_hp = 1;
  45. spec->gen.automute_speaker = 1;
  46. spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
  47. snd_hda_jack_detect_enable_callback(codec, 0x0f,
  48. snd_hda_gen_hp_automute);
  49. alc_setup_gpio(codec, 0x01);
  50. }
  51. }
  52. static void alc260_fixup_kn1(struct hda_codec *codec,
  53. const struct hda_fixup *fix, int action)
  54. {
  55. struct alc_spec *spec = codec->spec;
  56. static const struct hda_pintbl pincfgs[] = {
  57. { 0x0f, 0x02214000 }, /* HP/speaker */
  58. { 0x12, 0x90a60160 }, /* int mic */
  59. { 0x13, 0x02a19000 }, /* ext mic */
  60. { 0x18, 0x01446000 }, /* SPDIF out */
  61. /* disable bogus I/O pins */
  62. { 0x10, 0x411111f0 },
  63. { 0x11, 0x411111f0 },
  64. { 0x14, 0x411111f0 },
  65. { 0x15, 0x411111f0 },
  66. { 0x16, 0x411111f0 },
  67. { 0x17, 0x411111f0 },
  68. { 0x19, 0x411111f0 },
  69. { }
  70. };
  71. switch (action) {
  72. case HDA_FIXUP_ACT_PRE_PROBE:
  73. snd_hda_apply_pincfgs(codec, pincfgs);
  74. spec->init_amp = ALC_INIT_NONE;
  75. break;
  76. }
  77. }
  78. static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
  79. const struct hda_fixup *fix, int action)
  80. {
  81. struct alc_spec *spec = codec->spec;
  82. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  83. spec->init_amp = ALC_INIT_NONE;
  84. }
  85. static void alc260_fixup_fsc_s7020_jwse(struct hda_codec *codec,
  86. const struct hda_fixup *fix, int action)
  87. {
  88. struct alc_spec *spec = codec->spec;
  89. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  90. spec->gen.add_jack_modes = 1;
  91. spec->gen.hp_mic = 1;
  92. }
  93. }
  94. static const struct hda_fixup alc260_fixups[] = {
  95. [ALC260_FIXUP_HP_DC5750] = {
  96. .type = HDA_FIXUP_PINS,
  97. .v.pins = (const struct hda_pintbl[]) {
  98. { 0x11, 0x90130110 }, /* speaker */
  99. { }
  100. }
  101. },
  102. [ALC260_FIXUP_HP_PIN_0F] = {
  103. .type = HDA_FIXUP_PINS,
  104. .v.pins = (const struct hda_pintbl[]) {
  105. { 0x0f, 0x01214000 }, /* HP */
  106. { }
  107. }
  108. },
  109. [ALC260_FIXUP_COEF] = {
  110. .type = HDA_FIXUP_VERBS,
  111. .v.verbs = (const struct hda_verb[]) {
  112. { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
  113. { 0x1a, AC_VERB_SET_PROC_COEF, 0x3040 },
  114. { }
  115. },
  116. },
  117. [ALC260_FIXUP_GPIO1] = {
  118. .type = HDA_FIXUP_FUNC,
  119. .v.func = alc_fixup_gpio1,
  120. },
  121. [ALC260_FIXUP_GPIO1_TOGGLE] = {
  122. .type = HDA_FIXUP_FUNC,
  123. .v.func = alc260_fixup_gpio1_toggle,
  124. .chained = true,
  125. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  126. },
  127. [ALC260_FIXUP_REPLACER] = {
  128. .type = HDA_FIXUP_VERBS,
  129. .v.verbs = (const struct hda_verb[]) {
  130. { 0x1a, AC_VERB_SET_COEF_INDEX, 0x07 },
  131. { 0x1a, AC_VERB_SET_PROC_COEF, 0x3050 },
  132. { }
  133. },
  134. .chained = true,
  135. .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
  136. },
  137. [ALC260_FIXUP_HP_B1900] = {
  138. .type = HDA_FIXUP_FUNC,
  139. .v.func = alc260_fixup_gpio1_toggle,
  140. .chained = true,
  141. .chain_id = ALC260_FIXUP_COEF,
  142. },
  143. [ALC260_FIXUP_KN1] = {
  144. .type = HDA_FIXUP_FUNC,
  145. .v.func = alc260_fixup_kn1,
  146. },
  147. [ALC260_FIXUP_FSC_S7020] = {
  148. .type = HDA_FIXUP_FUNC,
  149. .v.func = alc260_fixup_fsc_s7020,
  150. },
  151. [ALC260_FIXUP_FSC_S7020_JWSE] = {
  152. .type = HDA_FIXUP_FUNC,
  153. .v.func = alc260_fixup_fsc_s7020_jwse,
  154. .chained = true,
  155. .chain_id = ALC260_FIXUP_FSC_S7020,
  156. },
  157. [ALC260_FIXUP_VAIO_PINS] = {
  158. .type = HDA_FIXUP_PINS,
  159. .v.pins = (const struct hda_pintbl[]) {
  160. /* Pin configs are missing completely on some VAIOs */
  161. { 0x0f, 0x01211020 },
  162. { 0x10, 0x0001003f },
  163. { 0x11, 0x411111f0 },
  164. { 0x12, 0x01a15930 },
  165. { 0x13, 0x411111f0 },
  166. { 0x14, 0x411111f0 },
  167. { 0x15, 0x411111f0 },
  168. { 0x16, 0x411111f0 },
  169. { 0x17, 0x411111f0 },
  170. { 0x18, 0x411111f0 },
  171. { 0x19, 0x411111f0 },
  172. { }
  173. }
  174. },
  175. };
  176. static const struct hda_quirk alc260_fixup_tbl[] = {
  177. SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
  178. SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
  179. SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
  180. SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
  181. SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
  182. SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_FIXUP_VAIO_PINS),
  183. SND_PCI_QUIRK(0x104d, 0x81e2, "Sony VAIO TX", ALC260_FIXUP_HP_PIN_0F),
  184. SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
  185. SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
  186. SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
  187. SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
  188. SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
  189. {}
  190. };
  191. static const struct hda_model_fixup alc260_fixup_models[] = {
  192. {.id = ALC260_FIXUP_GPIO1, .name = "gpio1"},
  193. {.id = ALC260_FIXUP_COEF, .name = "coef"},
  194. {.id = ALC260_FIXUP_FSC_S7020, .name = "fujitsu"},
  195. {.id = ALC260_FIXUP_FSC_S7020_JWSE, .name = "fujitsu-jwse"},
  196. {}
  197. };
  198. /*
  199. */
  200. static int alc260_probe(struct hda_codec *codec, const struct hda_device_id *id)
  201. {
  202. struct alc_spec *spec;
  203. int err;
  204. err = alc_alloc_spec(codec, 0x07);
  205. if (err < 0)
  206. return err;
  207. spec = codec->spec;
  208. /* as quite a few machines require HP amp for speaker outputs,
  209. * it's easier to enable it unconditionally; even if it's unneeded,
  210. * it's almost harmless.
  211. */
  212. spec->gen.prefer_hp_amp = 1;
  213. spec->gen.beep_nid = 0x01;
  214. spec->shutup = alc_eapd_shutup;
  215. alc_pre_init(codec);
  216. snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
  217. alc260_fixups);
  218. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  219. /* automatic parse from the BIOS config */
  220. err = alc260_parse_auto_config(codec);
  221. if (err < 0)
  222. goto error;
  223. if (!spec->gen.no_analog) {
  224. err = set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
  225. if (err < 0)
  226. goto error;
  227. }
  228. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  229. return 0;
  230. error:
  231. snd_hda_gen_remove(codec);
  232. return err;
  233. }
  234. static const struct hda_codec_ops alc260_codec_ops = {
  235. .probe = alc260_probe,
  236. .remove = snd_hda_gen_remove,
  237. .build_controls = alc_build_controls,
  238. .build_pcms = snd_hda_gen_build_pcms,
  239. .init = alc_init,
  240. .unsol_event = snd_hda_jack_unsol_event,
  241. .resume = alc_resume,
  242. .suspend = alc_suspend,
  243. .check_power_status = snd_hda_gen_check_power_status,
  244. .stream_pm = snd_hda_gen_stream_pm,
  245. };
  246. /*
  247. * driver entries
  248. */
  249. static const struct hda_device_id snd_hda_id_alc260[] = {
  250. HDA_CODEC_ID(0x10ec0260, "ALC260"),
  251. {} /* terminator */
  252. };
  253. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_alc260);
  254. MODULE_LICENSE("GPL");
  255. MODULE_DESCRIPTION("Realtek ALC260 HD-audio codec");
  256. MODULE_IMPORT_NS("SND_HDA_CODEC_REALTEK");
  257. static struct hda_codec_driver alc260_driver = {
  258. .id = snd_hda_id_alc260,
  259. .ops = &alc260_codec_ops,
  260. };
  261. module_hda_codec_driver(alc260_driver);