patch_cmedia.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for C-Media CMI9880
  5. *
  6. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  7. *
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_auto_parser.h"
  30. #include "hda_jack.h"
  31. #include "hda_generic.h"
  32. struct cmi_spec {
  33. struct hda_gen_spec gen;
  34. };
  35. /*
  36. * stuff for auto-parser
  37. */
  38. static const struct hda_codec_ops cmi_auto_patch_ops = {
  39. .build_controls = snd_hda_gen_build_controls,
  40. .build_pcms = snd_hda_gen_build_pcms,
  41. .init = snd_hda_gen_init,
  42. .free = snd_hda_gen_free,
  43. .unsol_event = snd_hda_jack_unsol_event,
  44. };
  45. static int patch_cmi9880(struct hda_codec *codec)
  46. {
  47. struct cmi_spec *spec;
  48. struct auto_pin_cfg *cfg;
  49. int err;
  50. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  51. if (spec == NULL)
  52. return -ENOMEM;
  53. codec->spec = spec;
  54. codec->patch_ops = cmi_auto_patch_ops;
  55. cfg = &spec->gen.autocfg;
  56. snd_hda_gen_spec_init(&spec->gen);
  57. err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
  58. if (err < 0)
  59. goto error;
  60. err = snd_hda_gen_parse_auto_config(codec, cfg);
  61. if (err < 0)
  62. goto error;
  63. return 0;
  64. error:
  65. snd_hda_gen_free(codec);
  66. return err;
  67. }
  68. static int patch_cmi8888(struct hda_codec *codec)
  69. {
  70. struct cmi_spec *spec;
  71. struct auto_pin_cfg *cfg;
  72. int err;
  73. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  74. if (!spec)
  75. return -ENOMEM;
  76. codec->spec = spec;
  77. codec->patch_ops = cmi_auto_patch_ops;
  78. cfg = &spec->gen.autocfg;
  79. snd_hda_gen_spec_init(&spec->gen);
  80. /* mask NID 0x10 from the playback volume selection;
  81. * it's a headphone boost volume handled manually below
  82. */
  83. spec->gen.out_vol_mask = (1ULL << 0x10);
  84. err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
  85. if (err < 0)
  86. goto error;
  87. err = snd_hda_gen_parse_auto_config(codec, cfg);
  88. if (err < 0)
  89. goto error;
  90. if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) ==
  91. AC_JACK_HP_OUT) {
  92. static const struct snd_kcontrol_new amp_kctl =
  93. HDA_CODEC_VOLUME("Headphone Amp Playback Volume",
  94. 0x10, 0, HDA_OUTPUT);
  95. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &amp_kctl)) {
  96. err = -ENOMEM;
  97. goto error;
  98. }
  99. }
  100. return 0;
  101. error:
  102. snd_hda_gen_free(codec);
  103. return err;
  104. }
  105. /*
  106. * patch entries
  107. */
  108. static const struct hda_device_id snd_hda_id_cmedia[] = {
  109. HDA_CODEC_ENTRY(0x13f68888, "CMI8888", patch_cmi8888),
  110. HDA_CODEC_ENTRY(0x13f69880, "CMI9880", patch_cmi9880),
  111. HDA_CODEC_ENTRY(0x434d4980, "CMI9880", patch_cmi9880),
  112. {} /* terminator */
  113. };
  114. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cmedia);
  115. MODULE_LICENSE("GPL");
  116. MODULE_DESCRIPTION("C-Media HD-audio codec");
  117. static struct hda_codec_driver cmedia_driver = {
  118. .id = snd_hda_id_cmedia,
  119. };
  120. module_hda_codec_driver(cmedia_driver);