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> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <sound/core.h> |
Pierre-Louis Bossart | be57bff | 2018-08-22 15:24:57 -0500 | [diff] [blame] | 28 | #include <sound/hda_codec.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 30 | #include "hda_auto_parser.h" |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 31 | #include "hda_jack.h" |
| 32 | #include "hda_generic.h" |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct cmi_spec { |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 35 | struct hda_gen_spec gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 38 | /* |
| 39 | * stuff for auto-parser |
| 40 | */ |
| 41 | static 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 Iwai | 8a6c21a | 2013-01-18 07:51:17 +0100 | [diff] [blame] | 46 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Takashi Iwai | db8e8a9 | 2014-06-06 18:21:38 +0200 | [diff] [blame] | 49 | static int patch_cmi9880(struct hda_codec *codec) |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 50 | { |
Takashi Iwai | db8e8a9 | 2014-06-06 18:21:38 +0200 | [diff] [blame] | 51 | struct cmi_spec *spec; |
| 52 | struct auto_pin_cfg *cfg; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 53 | int err; |
| 54 | |
Takashi Iwai | db8e8a9 | 2014-06-06 18:21:38 +0200 | [diff] [blame] | 55 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 56 | if (spec == NULL) |
| 57 | return -ENOMEM; |
| 58 | |
| 59 | codec->spec = spec; |
Takashi Iwai | 225068a | 2015-05-29 10:42:14 +0200 | [diff] [blame] | 60 | codec->patch_ops = cmi_auto_patch_ops; |
Takashi Iwai | db8e8a9 | 2014-06-06 18:21:38 +0200 | [diff] [blame] | 61 | cfg = &spec->gen.autocfg; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 62 | snd_hda_gen_spec_init(&spec->gen); |
| 63 | |
| 64 | err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); |
| 65 | if (err < 0) |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame] | 66 | goto error; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 67 | err = snd_hda_gen_parse_auto_config(codec, cfg); |
| 68 | if (err < 0) |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame] | 69 | goto error; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 70 | |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 71 | return 0; |
Takashi Iwai | 998caa4 | 2014-02-10 18:18:17 +0100 | [diff] [blame] | 72 | |
| 73 | error: |
| 74 | snd_hda_gen_free(codec); |
| 75 | return err; |
Takashi Iwai | b060fb0 | 2012-12-19 17:35:47 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Takashi Iwai | 875f0dd | 2014-08-06 14:32:56 +0200 | [diff] [blame] | 78 | static 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; |
Takashi Iwai | 225068a | 2015-05-29 10:42:14 +0200 | [diff] [blame] | 89 | codec->patch_ops = cmi_auto_patch_ops; |
Takashi Iwai | 875f0dd | 2014-08-06 14:32:56 +0200 | [diff] [blame] | 90 | cfg = &spec->gen.autocfg; |
| 91 | snd_hda_gen_spec_init(&spec->gen); |
| 92 | |
| 93 | /* mask NID 0x10 from the playback volume selection; |
| 94 | * it's a headphone boost volume handled manually below |
| 95 | */ |
| 96 | spec->gen.out_vol_mask = (1ULL << 0x10); |
| 97 | |
| 98 | err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); |
| 99 | if (err < 0) |
| 100 | goto error; |
| 101 | err = snd_hda_gen_parse_auto_config(codec, cfg); |
| 102 | if (err < 0) |
| 103 | goto error; |
| 104 | |
| 105 | if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) == |
| 106 | AC_JACK_HP_OUT) { |
| 107 | static const struct snd_kcontrol_new amp_kctl = |
| 108 | HDA_CODEC_VOLUME("Headphone Amp Playback Volume", |
| 109 | 0x10, 0, HDA_OUTPUT); |
| 110 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &_kctl)) { |
| 111 | err = -ENOMEM; |
| 112 | goto error; |
| 113 | } |
| 114 | } |
| 115 | |
Takashi Iwai | 875f0dd | 2014-08-06 14:32:56 +0200 | [diff] [blame] | 116 | return 0; |
| 117 | |
| 118 | error: |
| 119 | snd_hda_gen_free(codec); |
| 120 | return err; |
| 121 | } |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * patch entries |
| 125 | */ |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 126 | static const struct hda_device_id snd_hda_id_cmedia[] = { |
| 127 | HDA_CODEC_ENTRY(0x13f68888, "CMI8888", patch_cmi8888), |
| 128 | HDA_CODEC_ENTRY(0x13f69880, "CMI9880", patch_cmi9880), |
| 129 | HDA_CODEC_ENTRY(0x434d4980, "CMI9880", patch_cmi9880), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | {} /* terminator */ |
| 131 | }; |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 132 | MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cmedia); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 133 | |
| 134 | MODULE_LICENSE("GPL"); |
| 135 | MODULE_DESCRIPTION("C-Media HD-audio codec"); |
| 136 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 137 | static struct hda_codec_driver cmedia_driver = { |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 138 | .id = snd_hda_id_cmedia, |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 141 | module_hda_codec_driver(cmedia_driver); |