0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/init.h>
0011 #include <linux/slab.h>
0012 #include <linux/module.h>
0013 #include <sound/core.h>
0014 #include <sound/hda_codec.h>
0015 #include "hda_local.h"
0016 #include "hda_auto_parser.h"
0017 #include "hda_jack.h"
0018 #include "hda_generic.h"
0019
0020 struct cmi_spec {
0021 struct hda_gen_spec gen;
0022 };
0023
0024
0025
0026
0027 static const struct hda_codec_ops cmi_auto_patch_ops = {
0028 .build_controls = snd_hda_gen_build_controls,
0029 .build_pcms = snd_hda_gen_build_pcms,
0030 .init = snd_hda_gen_init,
0031 .free = snd_hda_gen_free,
0032 .unsol_event = snd_hda_jack_unsol_event,
0033 };
0034
0035 static int patch_cmi9880(struct hda_codec *codec)
0036 {
0037 struct cmi_spec *spec;
0038 struct auto_pin_cfg *cfg;
0039 int err;
0040
0041 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
0042 if (spec == NULL)
0043 return -ENOMEM;
0044
0045 codec->spec = spec;
0046 codec->patch_ops = cmi_auto_patch_ops;
0047 cfg = &spec->gen.autocfg;
0048 snd_hda_gen_spec_init(&spec->gen);
0049
0050 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
0051 if (err < 0)
0052 goto error;
0053 err = snd_hda_gen_parse_auto_config(codec, cfg);
0054 if (err < 0)
0055 goto error;
0056
0057 return 0;
0058
0059 error:
0060 snd_hda_gen_free(codec);
0061 return err;
0062 }
0063
0064 static int patch_cmi8888(struct hda_codec *codec)
0065 {
0066 struct cmi_spec *spec;
0067 struct auto_pin_cfg *cfg;
0068 int err;
0069
0070 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
0071 if (!spec)
0072 return -ENOMEM;
0073
0074 codec->spec = spec;
0075 codec->patch_ops = cmi_auto_patch_ops;
0076 cfg = &spec->gen.autocfg;
0077 snd_hda_gen_spec_init(&spec->gen);
0078
0079
0080
0081
0082 spec->gen.out_vol_mask = (1ULL << 0x10);
0083
0084 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
0085 if (err < 0)
0086 goto error;
0087 err = snd_hda_gen_parse_auto_config(codec, cfg);
0088 if (err < 0)
0089 goto error;
0090
0091 if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) ==
0092 AC_JACK_HP_OUT) {
0093 static const struct snd_kcontrol_new amp_kctl =
0094 HDA_CODEC_VOLUME("Headphone Amp Playback Volume",
0095 0x10, 0, HDA_OUTPUT);
0096 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &_kctl)) {
0097 err = -ENOMEM;
0098 goto error;
0099 }
0100 }
0101
0102 return 0;
0103
0104 error:
0105 snd_hda_gen_free(codec);
0106 return err;
0107 }
0108
0109
0110
0111
0112 static const struct hda_device_id snd_hda_id_cmedia[] = {
0113 HDA_CODEC_ENTRY(0x13f68888, "CMI8888", patch_cmi8888),
0114 HDA_CODEC_ENTRY(0x13f69880, "CMI9880", patch_cmi9880),
0115 HDA_CODEC_ENTRY(0x434d4980, "CMI9880", patch_cmi9880),
0116 {}
0117 };
0118 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cmedia);
0119
0120 MODULE_LICENSE("GPL");
0121 MODULE_DESCRIPTION("C-Media HD-audio codec");
0122
0123 static struct hda_codec_driver cmedia_driver = {
0124 .id = snd_hda_id_cmedia,
0125 };
0126
0127 module_hda_codec_driver(cmedia_driver);