Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/slab.h> |
| 26 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <sound/core.h> |
| 29 | #include "hda_codec.h" |
| 30 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 31 | #include "hda_auto_parser.h" |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 32 | #include "hda_jack.h" |
| 33 | #include "hda_generic.h" |
| 34 | |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 35 | #undef ENABLE_CMI_STATIC_QUIRKS |
| 36 | |
| 37 | #ifdef ENABLE_CMI_STATIC_QUIRKS |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 38 | #define NUM_PINS 11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | |
| 41 | /* board config type */ |
| 42 | enum { |
| 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 Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 48 | CMI_AUTO, /* let driver guess it */ |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 49 | CMI_MODELS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 51 | #endif /* ENABLE_CMI_STATIC_QUIRKS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | struct cmi_spec { |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 54 | struct hda_gen_spec gen; |
| 55 | |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 56 | #ifdef ENABLE_CMI_STATIC_QUIRKS |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 57 | /* below are only for static models */ |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int board_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | 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 Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 65 | hda_nid_t dac_nids[AUTO_CFG_MAX_OUTS]; /* NID for each DAC */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 66 | int num_dacs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* capture */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 69 | const hda_nid_t *adc_nids; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 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 Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 77 | int num_channel_modes; |
| 78 | const struct hda_channel_mode *channel_modes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 81 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 82 | /* pin default configuration */ |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 83 | 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 Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 88 | struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */ |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 89 | #endif /* ENABLE_CMI_STATIC_QUIRKS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 92 | #ifdef ENABLE_CMI_STATIC_QUIRKS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* |
| 94 | * input MUX |
| 95 | */ |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 96 | static int cmi_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 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 Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 103 | static int cmi_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 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 Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 113 | static int cmi_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 128 | static const struct hda_verb cmi9880_ch2_init[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* set line-in PIN for input */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 130 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* set mic PIN for input, also enable vref */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 132 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* route front PCM (DAC1) to HP */ |
| 134 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, |
| 135 | {} |
| 136 | }; |
| 137 | |
| 138 | /* 3-stack / 6 channel */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 139 | static const struct hda_verb cmi9880_ch6_init[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* set line-in PIN for output */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 141 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* set mic PIN for output */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 143 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* route front PCM (DAC1) to HP */ |
| 145 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, |
| 146 | {} |
| 147 | }; |
| 148 | |
| 149 | /* 3-stack+front / 8 channel */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 150 | static const struct hda_verb cmi9880_ch8_init[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* set line-in PIN for output */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 152 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* set mic PIN for output */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 154 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* route rear-surround PCM (DAC4) to HP */ |
| 156 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 }, |
| 157 | {} |
| 158 | }; |
| 159 | |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 160 | static const struct hda_channel_mode cmi9880_channel_modes[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { 2, cmi9880_ch2_init }, |
| 162 | { 6, cmi9880_ch6_init }, |
| 163 | { 8, cmi9880_ch8_init }, |
| 164 | }; |
| 165 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 166 | static int cmi_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 169 | struct cmi_spec *spec = codec->spec; |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 170 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes, |
| 171 | spec->num_channel_modes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 174 | static int cmi_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 177 | struct cmi_spec *spec = codec->spec; |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 178 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes, |
| 179 | spec->num_channel_modes, spec->multiout.max_channels); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 182 | static int cmi_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
| 184 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 185 | struct cmi_spec *spec = codec->spec; |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 186 | return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes, |
| 187 | spec->num_channel_modes, &spec->multiout.max_channels); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* |
| 191 | */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 192 | static const struct snd_kcontrol_new cmi9880_basic_mixer[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | */ |
| 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 Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 215 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT), |
| 216 | HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { } /* end */ |
| 218 | }; |
| 219 | |
| 220 | /* |
| 221 | * shared I/O pins |
| 222 | */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 223 | static const struct snd_kcontrol_new cmi9880_ch_mode_mixer[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 237 | static const struct hda_input_mux cmi9880_basic_mux = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | .num_items = 4, |
| 239 | .items = { |
| 240 | { "Front Mic", 0x5 }, |
| 241 | { "Rear Mic", 0x2 }, |
| 242 | { "Line", 0x1 }, |
| 243 | { "CD", 0x7 }, |
| 244 | } |
| 245 | }; |
| 246 | |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 247 | static const struct hda_input_mux cmi9880_no_line_mux = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | .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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 257 | static const hda_nid_t cmi9880_dac_nids[4] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 0x03, 0x04, 0x05, 0x06 |
| 259 | }; |
| 260 | /* ADC0, ADC1 */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 261 | static const hda_nid_t cmi9880_adc_nids[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | 0x08, 0x09 |
| 263 | }; |
| 264 | |
| 265 | #define CMI_DIG_OUT_NID 0x07 |
| 266 | #define CMI_DIG_IN_NID 0x0a |
| 267 | |
| 268 | /* |
| 269 | */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 270 | static const struct hda_verb cmi9880_basic_init[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* port-D for line out (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 272 | { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /* port-E for HP out (front panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 274 | { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* route front PCM to HP */ |
| 276 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, |
| 277 | /* port-A for surround (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 278 | { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /* port-G for CLFE (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 280 | { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
ChenLi Tien | d05b281 | 2005-03-24 20:47:35 +0100 | [diff] [blame] | 281 | { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | /* port-H for side (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 283 | { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
ChenLi Tien | d05b281 | 2005-03-24 20:47:35 +0100 | [diff] [blame] | 284 | { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* port-C for line-in (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 286 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | /* port-B for mic-in (rear panel) with vref */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 288 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | /* port-F for mic-in (front panel) with vref */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 290 | { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* CD-in */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 292 | { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* 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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 299 | static const struct hda_verb cmi9880_allout_init[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | /* port-D for line out (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 301 | { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | /* port-E for HP out (front panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 303 | { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* route front PCM to HP */ |
| 305 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, |
| 306 | /* port-A for side (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 307 | { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* port-G for CLFE (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 309 | { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
ChenLi Tien | d05b281 | 2005-03-24 20:47:35 +0100 | [diff] [blame] | 310 | { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, |
| 311 | /* port-H for side (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 312 | { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
ChenLi Tien | d05b281 | 2005-03-24 20:47:35 +0100 | [diff] [blame] | 313 | { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /* port-C for surround (rear panel) */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 315 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* port-B for mic-in (rear panel) with vref */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 317 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* port-F for mic-in (front panel) with vref */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 319 | { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* CD-in */ |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 321 | { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /* 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 | */ |
| 330 | static int cmi9880_build_controls(struct hda_codec *codec) |
| 331 | { |
| 332 | struct cmi_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 333 | struct snd_kcontrol *kctl; |
| 334 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); |
| 337 | if (err < 0) |
| 338 | return err; |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 339 | if (spec->channel_modes) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | 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 Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 345 | err = snd_hda_create_spdif_out_ctls(codec, |
| 346 | spec->multiout.dig_out_nid, |
| 347 | spec->multiout.dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | if (err < 0) |
| 349 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 350 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 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 Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 361 | |
| 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 Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 365 | err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 366 | if (err < 0) |
| 367 | return err; |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static 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 Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 379 | if (spec->board_config == CMI_AUTO) |
| 380 | snd_hda_sequence_write(codec, spec->multi_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /* |
| 385 | * Analog playback callbacks |
| 386 | */ |
| 387 | static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 388 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 389 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | struct cmi_spec *spec = codec->spec; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 392 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 393 | hinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static 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 Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 400 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 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 | |
| 407 | static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 408 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 409 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
| 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 | */ |
| 418 | static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 419 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 420 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct cmi_spec *spec = codec->spec; |
| 423 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 424 | } |
| 425 | |
| 426 | static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 427 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 428 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
| 430 | struct cmi_spec *spec = codec->spec; |
| 431 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 432 | } |
| 433 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 434 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* |
| 446 | * Analog capture |
| 447 | */ |
| 448 | static 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 Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 452 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
| 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 | |
| 461 | static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 462 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 463 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
| 465 | struct cmi_spec *spec = codec->spec; |
| 466 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 467 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /* |
| 473 | */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 474 | static const struct hda_pcm_stream cmi9880_pcm_analog_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | .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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 486 | static const struct hda_pcm_stream cmi9880_pcm_analog_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | .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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 497 | static const struct hda_pcm_stream cmi9880_pcm_digital_playback = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | .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 Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 504 | .close = cmi9880_dig_playback_pcm_close, |
| 505 | .prepare = cmi9880_dig_playback_pcm_prepare |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | }, |
| 507 | }; |
| 508 | |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 509 | static const struct hda_pcm_stream cmi9880_pcm_digital_capture = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | .substreams = 1, |
| 511 | .channels_min = 2, |
| 512 | .channels_max = 2, |
| 513 | /* NID is set in cmi9880_build_pcms */ |
| 514 | }; |
| 515 | |
| 516 | static 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 Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 532 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | 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 | |
| 546 | static void cmi9880_free(struct hda_codec *codec) |
| 547 | { |
| 548 | kfree(codec->spec); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | */ |
| 553 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 554 | static const char * const cmi9880_models[CMI_MODELS] = { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 555 | [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 Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 563 | static const struct snd_pci_quirk cmi9880_cfg_tbl[] = { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 564 | SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG), |
Takashi Iwai | 79d0643 | 2008-05-30 16:54:49 +0200 | [diff] [blame] | 565 | SND_PCI_QUIRK(0x1854, 0x002b, "LG LS75", CMI_MINIMAL), |
Jiang zhe | 5b03038 | 2008-04-14 13:26:53 +0200 | [diff] [blame] | 566 | SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | {} /* terminator */ |
| 568 | }; |
| 569 | |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 570 | static const struct hda_codec_ops cmi9880_patch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | .build_controls = cmi9880_build_controls, |
| 572 | .build_pcms = cmi9880_build_pcms, |
| 573 | .init = cmi9880_init, |
| 574 | .free = cmi9880_free, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | }; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 576 | #endif /* ENABLE_CMI_STATIC_QUIRKS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 578 | /* |
| 579 | * stuff for auto-parser |
| 580 | */ |
| 581 | static 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 Iwai | 8a6c21a | 2013-01-18 07:51:17 +0100 | [diff] [blame] | 586 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | static 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 Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 599 | goto error; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 600 | err = snd_hda_gen_parse_auto_config(codec, cfg); |
| 601 | if (err < 0) |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 602 | goto error; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 603 | |
| 604 | codec->patch_ops = cmi_auto_patch_ops; |
| 605 | return 0; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 606 | |
| 607 | error: |
| 608 | snd_hda_gen_free(codec); |
| 609 | return err; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 610 | } |
| 611 | |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | static int patch_cmi9880(struct hda_codec *codec) |
| 614 | { |
| 615 | struct cmi_spec *spec; |
| 616 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 617 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | if (spec == NULL) |
| 619 | return -ENOMEM; |
| 620 | |
| 621 | codec->spec = spec; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 622 | #ifdef ENABLE_CMI_STATIC_QUIRKS |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 623 | spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS, |
| 624 | cmi9880_models, |
| 625 | cmi9880_cfg_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | if (spec->board_config < 0) { |
Takashi Iwai | 9a11f1a | 2009-07-28 16:01:20 +0200 | [diff] [blame] | 627 | snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
| 628 | codec->chip_name); |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 629 | spec->board_config = CMI_AUTO; /* try everything */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 632 | if (spec->board_config == CMI_AUTO) |
| 633 | return cmi_parse_auto_config(codec); |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 634 | |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 635 | /* copy default DAC NIDs */ |
| 636 | memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids)); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 637 | spec->num_dacs = 4; |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | switch (spec->board_config) { |
| 640 | case CMI_MINIMAL: |
| 641 | case CMI_MIN_FP: |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 642 | spec->channel_modes = cmi9880_channel_modes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | if (spec->board_config == CMI_MINIMAL) |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 644 | spec->num_channel_modes = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | else { |
| 646 | spec->front_panel = 1; |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 647 | spec->num_channel_modes = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | 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 Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 663 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | 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 Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 672 | spec->multiout.num_dacs = spec->num_dacs; |
Takashi Iwai | f953eff | 2005-04-08 15:05:13 +0200 | [diff] [blame] | 673 | spec->multiout.dac_nids = spec->dac_nids; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | spec->adc_nids = cmi9880_adc_nids; |
| 676 | |
| 677 | codec->patch_ops = cmi9880_patch_ops; |
| 678 | |
| 679 | return 0; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame^] | 680 | #else |
| 681 | return cmi_parse_auto_config(codec); |
| 682 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /* |
| 686 | * patch entries |
| 687 | */ |
Takashi Iwai | 779d065 | 2011-05-02 11:34:20 +0200 | [diff] [blame] | 688 | static const struct hda_codec_preset snd_hda_preset_cmedia[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 }, |
| 690 | { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 }, |
| 691 | {} /* terminator */ |
| 692 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 693 | |
| 694 | MODULE_ALIAS("snd-hda-codec-id:13f69880"); |
| 695 | MODULE_ALIAS("snd-hda-codec-id:434d4980"); |
| 696 | |
| 697 | MODULE_LICENSE("GPL"); |
| 698 | MODULE_DESCRIPTION("C-Media HD-audio codec"); |
| 699 | |
| 700 | static struct hda_codec_preset_list cmedia_list = { |
| 701 | .preset = snd_hda_preset_cmedia, |
| 702 | .owner = THIS_MODULE, |
| 703 | }; |
| 704 | |
| 705 | static int __init patch_cmedia_init(void) |
| 706 | { |
| 707 | return snd_hda_add_codec_preset(&cmedia_list); |
| 708 | } |
| 709 | |
| 710 | static void __exit patch_cmedia_exit(void) |
| 711 | { |
| 712 | snd_hda_delete_codec_preset(&cmedia_list); |
| 713 | } |
| 714 | |
| 715 | module_init(patch_cmedia_init) |
| 716 | module_exit(patch_cmedia_exit) |