blob: 139ef301c914567232bd4d4b41080161d18ff940 [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>
26#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020031#include "hda_auto_parser.h"
Takashi Iwaib060fb02012-12-19 17:35:47 +010032#include "hda_jack.h"
33#include "hda_generic.h"
34
Takashi Iwai998caa42014-02-10 18:18:17 +010035#undef ENABLE_CMI_STATIC_QUIRKS
36
37#ifdef ENABLE_CMI_STATIC_QUIRKS
Takashi Iwaif953eff2005-04-08 15:05:13 +020038#define NUM_PINS 11
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40
41/* board config type */
42enum {
43 CMI_MINIMAL, /* back 3-jack */
44 CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */
45 CMI_FULL, /* back 6-jack + front-panel 2-jack */
46 CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */
47 CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */
Takashi Iwaif953eff2005-04-08 15:05:13 +020048 CMI_AUTO, /* let driver guess it */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049 CMI_MODELS
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
Takashi Iwai998caa42014-02-10 18:18:17 +010051#endif /* ENABLE_CMI_STATIC_QUIRKS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53struct cmi_spec {
Takashi Iwaib060fb02012-12-19 17:35:47 +010054 struct hda_gen_spec gen;
55
Takashi Iwai998caa42014-02-10 18:18:17 +010056#ifdef ENABLE_CMI_STATIC_QUIRKS
Takashi Iwaib060fb02012-12-19 17:35:47 +010057 /* below are only for static models */
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned int no_line_in: 1; /* no line-in (5-jack) */
61 unsigned int front_panel: 1; /* has front-panel 2-jack */
62
63 /* playback */
64 struct hda_multi_out multiout;
Takashi Iwai41923e42007-10-22 17:20:10 +020065 hda_nid_t dac_nids[AUTO_CFG_MAX_OUTS]; /* NID for each DAC */
Takashi Iwaie9edcee2005-06-13 14:16:38 +020066 int num_dacs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 /* capture */
Takashi Iwai779d0652011-05-02 11:34:20 +020069 const hda_nid_t *adc_nids;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 hda_nid_t dig_in_nid;
71
72 /* capture source */
73 const struct hda_input_mux *input_mux;
74 unsigned int cur_mux[2];
75
76 /* channel mode */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010077 int num_channel_modes;
78 const struct hda_channel_mode *channel_modes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 struct hda_pcm pcm_rec[2]; /* PCM information */
Takashi Iwaif953eff2005-04-08 15:05:13 +020081
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020082 /* pin default configuration */
Takashi Iwaif953eff2005-04-08 15:05:13 +020083 hda_nid_t pin_nid[NUM_PINS];
84 unsigned int def_conf[NUM_PINS];
85 unsigned int pin_def_confs;
86
87 /* multichannel pins */
Takashi Iwaif953eff2005-04-08 15:05:13 +020088 struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */
Takashi Iwai998caa42014-02-10 18:18:17 +010089#endif /* ENABLE_CMI_STATIC_QUIRKS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090};
91
Takashi Iwai998caa42014-02-10 18:18:17 +010092#ifdef ENABLE_CMI_STATIC_QUIRKS
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*
94 * input MUX
95 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010096static int cmi_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
99 struct cmi_spec *spec = codec->spec;
100 return snd_hda_input_mux_info(spec->input_mux, uinfo);
101}
102
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100103static int cmi_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
106 struct cmi_spec *spec = codec->spec;
107 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
108
109 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
110 return 0;
111}
112
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100113static int cmi_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
116 struct cmi_spec *spec = codec->spec;
117 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
118
119 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
120 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
121}
122
123/*
124 * shared line-in, mic for surrounds
125 */
126
127/* 3-stack / 2 channel */
Takashi Iwai779d0652011-05-02 11:34:20 +0200128static const struct hda_verb cmi9880_ch2_init[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* set line-in PIN for input */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200130 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* set mic PIN for input, also enable vref */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200132 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /* route front PCM (DAC1) to HP */
134 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
135 {}
136};
137
138/* 3-stack / 6 channel */
Takashi Iwai779d0652011-05-02 11:34:20 +0200139static const struct hda_verb cmi9880_ch6_init[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* set line-in PIN for output */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200141 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 /* set mic PIN for output */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200143 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* route front PCM (DAC1) to HP */
145 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
146 {}
147};
148
149/* 3-stack+front / 8 channel */
Takashi Iwai779d0652011-05-02 11:34:20 +0200150static const struct hda_verb cmi9880_ch8_init[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* set line-in PIN for output */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200152 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 /* set mic PIN for output */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200154 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* route rear-surround PCM (DAC4) to HP */
156 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 },
157 {}
158};
159
Takashi Iwai779d0652011-05-02 11:34:20 +0200160static const struct hda_channel_mode cmi9880_channel_modes[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 { 2, cmi9880_ch2_init },
162 { 6, cmi9880_ch6_init },
163 { 8, cmi9880_ch8_init },
164};
165
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100166static int cmi_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
168 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
169 struct cmi_spec *spec = codec->spec;
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100170 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes,
171 spec->num_channel_modes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100174static int cmi_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
177 struct cmi_spec *spec = codec->spec;
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100178 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes,
179 spec->num_channel_modes, spec->multiout.max_channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100182static int cmi_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
184 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
185 struct cmi_spec *spec = codec->spec;
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100186 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes,
187 spec->num_channel_modes, &spec->multiout.max_channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
190/*
191 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200192static const struct snd_kcontrol_new cmi9880_basic_mixer[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /* CMI9880 has no playback volumes! */
194 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */
195 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT),
196 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
197 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
198 HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT),
199 {
200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
201 /* The multiple "Capture Source" controls confuse alsamixer
202 * So call somewhat different..
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 */
204 /* .name = "Capture Source", */
205 .name = "Input Source",
206 .count = 2,
207 .info = cmi_mux_enum_info,
208 .get = cmi_mux_enum_get,
209 .put = cmi_mux_enum_put,
210 },
211 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT),
212 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
213 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
214 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100215 HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT),
216 HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 { } /* end */
218};
219
220/*
221 * shared I/O pins
222 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200223static const struct snd_kcontrol_new cmi9880_ch_mode_mixer[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
226 .name = "Channel Mode",
227 .info = cmi_ch_mode_info,
228 .get = cmi_ch_mode_get,
229 .put = cmi_ch_mode_put,
230 },
231 { } /* end */
232};
233
234/* AUD-in selections:
235 * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
236 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200237static const struct hda_input_mux cmi9880_basic_mux = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .num_items = 4,
239 .items = {
240 { "Front Mic", 0x5 },
241 { "Rear Mic", 0x2 },
242 { "Line", 0x1 },
243 { "CD", 0x7 },
244 }
245};
246
Takashi Iwai779d0652011-05-02 11:34:20 +0200247static const struct hda_input_mux cmi9880_no_line_mux = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 .num_items = 3,
249 .items = {
250 { "Front Mic", 0x5 },
251 { "Rear Mic", 0x2 },
252 { "CD", 0x7 },
253 }
254};
255
256/* front, rear, clfe, rear_surr */
Takashi Iwai779d0652011-05-02 11:34:20 +0200257static const hda_nid_t cmi9880_dac_nids[4] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 0x03, 0x04, 0x05, 0x06
259};
260/* ADC0, ADC1 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200261static const hda_nid_t cmi9880_adc_nids[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 0x08, 0x09
263};
264
265#define CMI_DIG_OUT_NID 0x07
266#define CMI_DIG_IN_NID 0x0a
267
268/*
269 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200270static const struct hda_verb cmi9880_basic_init[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* port-D for line out (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200272 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 /* port-E for HP out (front panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200274 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* route front PCM to HP */
276 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
277 /* port-A for surround (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200278 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /* port-G for CLFE (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200280 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
ChenLi Tiend05b2812005-03-24 20:47:35 +0100281 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* port-H for side (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200283 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
ChenLi Tiend05b2812005-03-24 20:47:35 +0100284 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 /* port-C for line-in (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200286 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* port-B for mic-in (rear panel) with vref */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200288 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* port-F for mic-in (front panel) with vref */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200290 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* CD-in */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200292 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /* route front mic to ADC1/2 */
294 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
295 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
296 {} /* terminator */
297};
298
Takashi Iwai779d0652011-05-02 11:34:20 +0200299static const struct hda_verb cmi9880_allout_init[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 /* port-D for line out (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200301 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 /* port-E for HP out (front panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200303 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* route front PCM to HP */
305 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
306 /* port-A for side (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200307 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* port-G for CLFE (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200309 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
ChenLi Tiend05b2812005-03-24 20:47:35 +0100310 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
311 /* port-H for side (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200312 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
ChenLi Tiend05b2812005-03-24 20:47:35 +0100313 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /* port-C for surround (rear panel) */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200315 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 /* port-B for mic-in (rear panel) with vref */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200317 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 /* port-F for mic-in (front panel) with vref */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200319 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* CD-in */
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200321 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /* route front mic to ADC1/2 */
323 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
324 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
325 {} /* terminator */
326};
327
328/*
329 */
330static int cmi9880_build_controls(struct hda_codec *codec)
331{
332 struct cmi_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100333 struct snd_kcontrol *kctl;
334 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
337 if (err < 0)
338 return err;
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100339 if (spec->channel_modes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
341 if (err < 0)
342 return err;
343 }
344 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -0600345 err = snd_hda_create_spdif_out_ctls(codec,
346 spec->multiout.dig_out_nid,
347 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (err < 0)
349 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100350 err = snd_hda_create_spdif_share_sw(codec,
351 &spec->multiout);
352 if (err < 0)
353 return err;
354 spec->multiout.share_spdif = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356 if (spec->dig_in_nid) {
357 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
358 if (err < 0)
359 return err;
360 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100361
362 /* assign Capture Source enums to NID */
363 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
364 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +0100365 err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100366 if (err < 0)
367 return err;
368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return 0;
370}
371
372static int cmi9880_init(struct hda_codec *codec)
373{
374 struct cmi_spec *spec = codec->spec;
375 if (spec->board_config == CMI_ALLOUT)
376 snd_hda_sequence_write(codec, cmi9880_allout_init);
377 else
378 snd_hda_sequence_write(codec, cmi9880_basic_init);
Takashi Iwaif953eff2005-04-08 15:05:13 +0200379 if (spec->board_config == CMI_AUTO)
380 snd_hda_sequence_write(codec, spec->multi_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return 0;
382}
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*
385 * Analog playback callbacks
386 */
387static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
388 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100389 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
391 struct cmi_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100392 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
393 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
396static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
397 struct hda_codec *codec,
398 unsigned int stream_tag,
399 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100400 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 struct cmi_spec *spec = codec->spec;
403 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
404 format, substream);
405}
406
407static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
408 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100409 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
411 struct cmi_spec *spec = codec->spec;
412 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
413}
414
415/*
416 * Digital out
417 */
418static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
419 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100420 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
422 struct cmi_spec *spec = codec->spec;
423 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
424}
425
426static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
427 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100428 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct cmi_spec *spec = codec->spec;
431 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
432}
433
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200434static int cmi9880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
435 struct hda_codec *codec,
436 unsigned int stream_tag,
437 unsigned int format,
438 struct snd_pcm_substream *substream)
439{
440 struct cmi_spec *spec = codec->spec;
441 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
442 format, substream);
443}
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445/*
446 * Analog capture
447 */
448static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
449 struct hda_codec *codec,
450 unsigned int stream_tag,
451 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100452 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 struct cmi_spec *spec = codec->spec;
455
456 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
457 stream_tag, 0, format);
458 return 0;
459}
460
461static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
462 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100463 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 struct cmi_spec *spec = codec->spec;
466
Takashi Iwai888afa12008-03-18 09:57:50 +0100467 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return 0;
469}
470
471
472/*
473 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200474static const struct hda_pcm_stream cmi9880_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .substreams = 1,
476 .channels_min = 2,
477 .channels_max = 8,
478 .nid = 0x03, /* NID to query formats and rates */
479 .ops = {
480 .open = cmi9880_playback_pcm_open,
481 .prepare = cmi9880_playback_pcm_prepare,
482 .cleanup = cmi9880_playback_pcm_cleanup
483 },
484};
485
Takashi Iwai779d0652011-05-02 11:34:20 +0200486static const struct hda_pcm_stream cmi9880_pcm_analog_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .substreams = 2,
488 .channels_min = 2,
489 .channels_max = 2,
490 .nid = 0x08, /* NID to query formats and rates */
491 .ops = {
492 .prepare = cmi9880_capture_pcm_prepare,
493 .cleanup = cmi9880_capture_pcm_cleanup
494 },
495};
496
Takashi Iwai779d0652011-05-02 11:34:20 +0200497static const struct hda_pcm_stream cmi9880_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .substreams = 1,
499 .channels_min = 2,
500 .channels_max = 2,
501 /* NID is set in cmi9880_build_pcms */
502 .ops = {
503 .open = cmi9880_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200504 .close = cmi9880_dig_playback_pcm_close,
505 .prepare = cmi9880_dig_playback_pcm_prepare
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
507};
508
Takashi Iwai779d0652011-05-02 11:34:20 +0200509static const struct hda_pcm_stream cmi9880_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .substreams = 1,
511 .channels_min = 2,
512 .channels_max = 2,
513 /* NID is set in cmi9880_build_pcms */
514};
515
516static int cmi9880_build_pcms(struct hda_codec *codec)
517{
518 struct cmi_spec *spec = codec->spec;
519 struct hda_pcm *info = spec->pcm_rec;
520
521 codec->num_pcms = 1;
522 codec->pcm_info = info;
523
524 info->name = "CMI9880";
525 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback;
526 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture;
527
528 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
529 codec->num_pcms++;
530 info++;
531 info->name = "CMI9880 Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100532 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (spec->multiout.dig_out_nid) {
534 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
535 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
536 }
537 if (spec->dig_in_nid) {
538 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture;
539 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
540 }
541 }
542
543 return 0;
544}
545
546static void cmi9880_free(struct hda_codec *codec)
547{
548 kfree(codec->spec);
549}
550
551/*
552 */
553
Takashi Iwaiea734962011-01-17 11:29:34 +0100554static const char * const cmi9880_models[CMI_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100555 [CMI_MINIMAL] = "minimal",
556 [CMI_MIN_FP] = "min_fp",
557 [CMI_FULL] = "full",
558 [CMI_FULL_DIG] = "full_dig",
559 [CMI_ALLOUT] = "allout",
560 [CMI_AUTO] = "auto",
561};
562
Takashi Iwai779d0652011-05-02 11:34:20 +0200563static const struct snd_pci_quirk cmi9880_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100564 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG),
Takashi Iwai79d06432008-05-30 16:54:49 +0200565 SND_PCI_QUIRK(0x1854, 0x002b, "LG LS75", CMI_MINIMAL),
Jiang zhe5b030382008-04-14 13:26:53 +0200566 SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 {} /* terminator */
568};
569
Takashi Iwai779d0652011-05-02 11:34:20 +0200570static const struct hda_codec_ops cmi9880_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .build_controls = cmi9880_build_controls,
572 .build_pcms = cmi9880_build_pcms,
573 .init = cmi9880_init,
574 .free = cmi9880_free,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575};
Takashi Iwai998caa42014-02-10 18:18:17 +0100576#endif /* ENABLE_CMI_STATIC_QUIRKS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Takashi Iwaib060fb02012-12-19 17:35:47 +0100578/*
579 * stuff for auto-parser
580 */
581static const struct hda_codec_ops cmi_auto_patch_ops = {
582 .build_controls = snd_hda_gen_build_controls,
583 .build_pcms = snd_hda_gen_build_pcms,
584 .init = snd_hda_gen_init,
585 .free = snd_hda_gen_free,
Takashi Iwai8a6c21a2013-01-18 07:51:17 +0100586 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwaib060fb02012-12-19 17:35:47 +0100587};
588
589static int cmi_parse_auto_config(struct hda_codec *codec)
590{
591 struct cmi_spec *spec = codec->spec;
592 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
593 int err;
594
595 snd_hda_gen_spec_init(&spec->gen);
596
597 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
598 if (err < 0)
Takashi Iwai998caa42014-02-10 18:18:17 +0100599 goto error;
Takashi Iwaib060fb02012-12-19 17:35:47 +0100600 err = snd_hda_gen_parse_auto_config(codec, cfg);
601 if (err < 0)
Takashi Iwai998caa42014-02-10 18:18:17 +0100602 goto error;
Takashi Iwaib060fb02012-12-19 17:35:47 +0100603
604 codec->patch_ops = cmi_auto_patch_ops;
605 return 0;
Takashi Iwai998caa42014-02-10 18:18:17 +0100606
607 error:
608 snd_hda_gen_free(codec);
609 return err;
Takashi Iwaib060fb02012-12-19 17:35:47 +0100610}
611
Takashi Iwai998caa42014-02-10 18:18:17 +0100612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613static int patch_cmi9880(struct hda_codec *codec)
614{
615 struct cmi_spec *spec;
616
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200617 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 if (spec == NULL)
619 return -ENOMEM;
620
621 codec->spec = spec;
Takashi Iwai998caa42014-02-10 18:18:17 +0100622#ifdef ENABLE_CMI_STATIC_QUIRKS
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100623 spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS,
624 cmi9880_models,
625 cmi9880_cfg_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (spec->board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +0200627 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
628 codec->chip_name);
Takashi Iwaif953eff2005-04-08 15:05:13 +0200629 spec->board_config = CMI_AUTO; /* try everything */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
Takashi Iwai998caa42014-02-10 18:18:17 +0100632 if (spec->board_config == CMI_AUTO)
633 return cmi_parse_auto_config(codec);
Takashi Iwaib060fb02012-12-19 17:35:47 +0100634
Takashi Iwaif953eff2005-04-08 15:05:13 +0200635 /* copy default DAC NIDs */
636 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200637 spec->num_dacs = 4;
Takashi Iwaif953eff2005-04-08 15:05:13 +0200638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 switch (spec->board_config) {
640 case CMI_MINIMAL:
641 case CMI_MIN_FP:
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100642 spec->channel_modes = cmi9880_channel_modes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (spec->board_config == CMI_MINIMAL)
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100644 spec->num_channel_modes = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 else {
646 spec->front_panel = 1;
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100647 spec->num_channel_modes = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
650 spec->input_mux = &cmi9880_basic_mux;
651 break;
652 case CMI_FULL:
653 case CMI_FULL_DIG:
654 spec->front_panel = 1;
655 spec->multiout.max_channels = 8;
656 spec->input_mux = &cmi9880_basic_mux;
657 if (spec->board_config == CMI_FULL_DIG) {
658 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
659 spec->dig_in_nid = CMI_DIG_IN_NID;
660 }
661 break;
662 case CMI_ALLOUT:
Takashi Iwaib060fb02012-12-19 17:35:47 +0100663 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 spec->front_panel = 1;
665 spec->multiout.max_channels = 8;
666 spec->no_line_in = 1;
667 spec->input_mux = &cmi9880_no_line_mux;
668 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
669 break;
670 }
671
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200672 spec->multiout.num_dacs = spec->num_dacs;
Takashi Iwaif953eff2005-04-08 15:05:13 +0200673 spec->multiout.dac_nids = spec->dac_nids;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 spec->adc_nids = cmi9880_adc_nids;
676
677 codec->patch_ops = cmi9880_patch_ops;
678
679 return 0;
Takashi Iwai998caa42014-02-10 18:18:17 +0100680#else
681 return cmi_parse_auto_config(codec);
682#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685/*
686 * patch entries
687 */
Takashi Iwai779d0652011-05-02 11:34:20 +0200688static const struct hda_codec_preset snd_hda_preset_cmedia[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
690 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },
691 {} /* terminator */
692};
Takashi Iwai1289e9e2008-11-27 15:47:11 +0100693
694MODULE_ALIAS("snd-hda-codec-id:13f69880");
695MODULE_ALIAS("snd-hda-codec-id:434d4980");
696
697MODULE_LICENSE("GPL");
698MODULE_DESCRIPTION("C-Media HD-audio codec");
699
700static struct hda_codec_preset_list cmedia_list = {
701 .preset = snd_hda_preset_cmedia,
702 .owner = THIS_MODULE,
703};
704
705static int __init patch_cmedia_init(void)
706{
707 return snd_hda_add_codec_preset(&cmedia_list);
708}
709
710static void __exit patch_cmedia_exit(void)
711{
712 snd_hda_delete_codec_preset(&cmedia_list);
713}
714
715module_init(patch_cmedia_init)
716module_exit(patch_cmedia_exit)