blob: c895a8f211922415b1498a2092772149d9ab13c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040026#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020030#include "hda_auto_parser.h"
Takashi Iwaib060fb02012-12-19 17:35:47 +010031#include "hda_jack.h"
32#include "hda_generic.h"
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct cmi_spec {
Takashi Iwaib060fb02012-12-19 17:35:47 +010035 struct hda_gen_spec gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
Takashi Iwaib060fb02012-12-19 17:35:47 +010038/*
39 * stuff for auto-parser
40 */
41static const struct hda_codec_ops cmi_auto_patch_ops = {
42 .build_controls = snd_hda_gen_build_controls,
43 .build_pcms = snd_hda_gen_build_pcms,
44 .init = snd_hda_gen_init,
45 .free = snd_hda_gen_free,
Takashi Iwai8a6c21a2013-01-18 07:51:17 +010046 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwaib060fb02012-12-19 17:35:47 +010047};
48
Takashi Iwaidb8e8a92014-06-06 18:21:38 +020049static int patch_cmi9880(struct hda_codec *codec)
Takashi Iwaib060fb02012-12-19 17:35:47 +010050{
Takashi Iwaidb8e8a92014-06-06 18:21:38 +020051 struct cmi_spec *spec;
52 struct auto_pin_cfg *cfg;
Takashi Iwaib060fb02012-12-19 17:35:47 +010053 int err;
54
Takashi Iwaidb8e8a92014-06-06 18:21:38 +020055 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
56 if (spec == NULL)
57 return -ENOMEM;
58
59 codec->spec = spec;
60 cfg = &spec->gen.autocfg;
Takashi Iwaib060fb02012-12-19 17:35:47 +010061 snd_hda_gen_spec_init(&spec->gen);
62
63 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
64 if (err < 0)
Takashi Iwai998caa42014-02-10 18:18:17 +010065 goto error;
Takashi Iwaib060fb02012-12-19 17:35:47 +010066 err = snd_hda_gen_parse_auto_config(codec, cfg);
67 if (err < 0)
Takashi Iwai998caa42014-02-10 18:18:17 +010068 goto error;
Takashi Iwaib060fb02012-12-19 17:35:47 +010069
70 codec->patch_ops = cmi_auto_patch_ops;
71 return 0;
Takashi Iwai998caa42014-02-10 18:18:17 +010072
73 error:
74 snd_hda_gen_free(codec);
75 return err;
Takashi Iwaib060fb02012-12-19 17:35:47 +010076}
77
Takashi Iwai875f0dd2014-08-06 14:32:56 +020078static int patch_cmi8888(struct hda_codec *codec)
79{
80 struct cmi_spec *spec;
81 struct auto_pin_cfg *cfg;
82 int err;
83
84 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
85 if (!spec)
86 return -ENOMEM;
87
88 codec->spec = spec;
89 cfg = &spec->gen.autocfg;
90 snd_hda_gen_spec_init(&spec->gen);
91
92 /* mask NID 0x10 from the playback volume selection;
93 * it's a headphone boost volume handled manually below
94 */
95 spec->gen.out_vol_mask = (1ULL << 0x10);
96
97 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
98 if (err < 0)
99 goto error;
100 err = snd_hda_gen_parse_auto_config(codec, cfg);
101 if (err < 0)
102 goto error;
103
104 if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) ==
105 AC_JACK_HP_OUT) {
106 static const struct snd_kcontrol_new amp_kctl =
107 HDA_CODEC_VOLUME("Headphone Amp Playback Volume",
108 0x10, 0, HDA_OUTPUT);
109 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &amp_kctl)) {
110 err = -ENOMEM;
111 goto error;
112 }
113 }
114
115 codec->patch_ops = cmi_auto_patch_ops;
116 return 0;
117
118 error:
119 snd_hda_gen_free(codec);
120 return err;
121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
124 * patch entries
125 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200126static const struct hda_codec_preset snd_hda_preset_cmedia[] = {
Takashi Iwai875f0dd2014-08-06 14:32:56 +0200127 { .id = 0x13f68888, .name = "CMI8888", .patch = patch_cmi8888 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
129 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },
130 {} /* terminator */
131};
Takashi Iwai1289e9e2008-11-27 15:47:11 +0100132
Takashi Iwai875f0dd2014-08-06 14:32:56 +0200133MODULE_ALIAS("snd-hda-codec-id:13f68888");
Takashi Iwai1289e9e2008-11-27 15:47:11 +0100134MODULE_ALIAS("snd-hda-codec-id:13f69880");
135MODULE_ALIAS("snd-hda-codec-id:434d4980");
136
137MODULE_LICENSE("GPL");
138MODULE_DESCRIPTION("C-Media HD-audio codec");
139
140static struct hda_codec_preset_list cmedia_list = {
141 .preset = snd_hda_preset_cmedia,
142 .owner = THIS_MODULE,
143};
144
145static int __init patch_cmedia_init(void)
146{
147 return snd_hda_add_codec_preset(&cmedia_list);
148}
149
150static void __exit patch_cmedia_exit(void)
151{
152 snd_hda_delete_codec_preset(&cmedia_list);
153}
154
155module_init(patch_cmedia_init)
156module_exit(patch_cmedia_exit)