Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * patch_intelhdmi.c - Patch for Intel HDMI codecs |
| 4 | * |
| 5 | * Copyright(c) 2008 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * Authors: |
| 8 | * Jiang Zhe <zhe.jiang@intel.com> |
| 9 | * Wu Fengguang <wfg@linux.intel.com> |
| 10 | * |
| 11 | * Maintained by: |
| 12 | * Wu Fengguang <wfg@linux.intel.com> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify it |
| 15 | * under the terms of the GNU General Public License as published by the Free |
| 16 | * Software Foundation; either version 2 of the License, or (at your option) |
| 17 | * any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, but |
| 20 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 21 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 22 | * for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software Foundation, |
| 26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <sound/core.h> |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 33 | #include "hda_codec.h" |
| 34 | #include "hda_local.h" |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 35 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 36 | /* |
| 37 | * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device |
| 38 | * could support two independent pipes, each of them can be connected to one or |
| 39 | * more ports (DVI, HDMI or DisplayPort). |
| 40 | * |
| 41 | * The HDA correspondence of pipes/ports are converter/pin nodes. |
| 42 | */ |
Wu Fengguang | e48b008 | 2010-05-14 16:36:14 +0800 | [diff] [blame] | 43 | #define MAX_HDMI_CVTS 3 |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 44 | #define MAX_HDMI_PINS 3 |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 45 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 46 | #include "patch_hdmi.c" |
| 47 | |
| 48 | static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = { |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 49 | "INTEL HDMI 0", |
| 50 | "INTEL HDMI 1", |
Wu Fengguang | e48b008 | 2010-05-14 16:36:14 +0800 | [diff] [blame] | 51 | "INTEL HDMI 2", |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 52 | }; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 53 | |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 54 | /* |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 55 | * HDMI callbacks |
Wu Fengguang | 698544d | 2008-11-19 08:56:17 +0800 | [diff] [blame] | 56 | */ |
Wu Fengguang | 5779191 | 2009-11-18 12:38:06 +0800 | [diff] [blame] | 57 | |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 58 | static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 59 | struct hda_codec *codec, |
| 60 | unsigned int stream_tag, |
| 61 | unsigned int format, |
| 62 | struct snd_pcm_substream *substream) |
| 63 | { |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 64 | hdmi_set_channel_count(codec, hinfo->nid, |
Wu Fengguang | 7bedb01 | 2009-10-30 11:41:44 +0100 | [diff] [blame] | 65 | substream->runtime->channels); |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 66 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 67 | hdmi_setup_audio_infoframe(codec, hinfo->nid, substream); |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 68 | |
Wu Fengguang | 5779191 | 2009-11-18 12:38:06 +0800 | [diff] [blame] | 69 | hdmi_setup_stream(codec, hinfo->nid, stream_tag, format); |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Wu Fengguang | ddb8152 | 2009-10-30 11:43:03 +0100 | [diff] [blame] | 73 | static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 74 | struct hda_codec *codec, |
| 75 | struct snd_pcm_substream *substream) |
| 76 | { |
Wu Fengguang | ddb8152 | 2009-10-30 11:43:03 +0100 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 80 | static struct hda_pcm_stream intel_hdmi_pcm_playback = { |
| 81 | .substreams = 1, |
| 82 | .channels_min = 2, |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 83 | .ops = { |
Wu Fengguang | 70ca35f | 2009-10-30 11:42:18 +0100 | [diff] [blame] | 84 | .prepare = intel_hdmi_playback_pcm_prepare, |
| 85 | .cleanup = intel_hdmi_playback_pcm_cleanup, |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 86 | }, |
| 87 | }; |
| 88 | |
| 89 | static int intel_hdmi_build_pcms(struct hda_codec *codec) |
| 90 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 91 | struct hdmi_spec *spec = codec->spec; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 92 | struct hda_pcm *info = spec->pcm_rec; |
| 93 | int i; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 94 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 95 | codec->num_pcms = spec->num_cvts; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 96 | codec->pcm_info = info; |
| 97 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 98 | for (i = 0; i < codec->num_pcms; i++, info++) { |
Wu Fengguang | 69fb346 | 2009-10-30 11:45:04 +0100 | [diff] [blame] | 99 | unsigned int chans; |
| 100 | |
| 101 | chans = get_wcaps(codec, spec->cvt[i]); |
| 102 | chans = get_wcaps_channels(chans); |
| 103 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 104 | info->name = intel_hdmi_pcm_names[i]; |
| 105 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
| 106 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 107 | intel_hdmi_pcm_playback; |
| 108 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i]; |
Wu Fengguang | 69fb346 | 2009-10-30 11:45:04 +0100 | [diff] [blame] | 109 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 110 | } |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static int intel_hdmi_build_controls(struct hda_codec *codec) |
| 116 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 117 | struct hdmi_spec *spec = codec->spec; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 118 | int err; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 119 | int i; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 120 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 121 | for (i = 0; i < codec->num_pcms; i++) { |
| 122 | err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]); |
| 123 | if (err < 0) |
| 124 | return err; |
| 125 | } |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static int intel_hdmi_init(struct hda_codec *codec) |
| 131 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 132 | struct hdmi_spec *spec = codec->spec; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 133 | int i; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 134 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 135 | for (i = 0; spec->pin[i]; i++) { |
| 136 | hdmi_enable_output(codec, spec->pin[i]); |
| 137 | snd_hda_codec_write(codec, spec->pin[i], 0, |
| 138 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 139 | AC_USRSP_EN | spec->pin[i]); |
| 140 | } |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static void intel_hdmi_free(struct hda_codec *codec) |
| 145 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 146 | struct hdmi_spec *spec = codec->spec; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 147 | int i; |
Takashi Iwai | f208dba | 2008-11-21 09:11:50 +0100 | [diff] [blame] | 148 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 149 | for (i = 0; i < spec->num_pins; i++) |
| 150 | snd_hda_eld_proc_free(codec, &spec->sink_eld[i]); |
| 151 | |
Takashi Iwai | f208dba | 2008-11-21 09:11:50 +0100 | [diff] [blame] | 152 | kfree(spec); |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static struct hda_codec_ops intel_hdmi_patch_ops = { |
| 156 | .init = intel_hdmi_init, |
| 157 | .free = intel_hdmi_free, |
| 158 | .build_pcms = intel_hdmi_build_pcms, |
| 159 | .build_controls = intel_hdmi_build_controls, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 160 | .unsol_event = hdmi_unsol_event, |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 161 | }; |
| 162 | |
Wu Fengguang | fd080b2 | 2009-10-30 11:46:22 +0100 | [diff] [blame] | 163 | static int patch_intel_hdmi(struct hda_codec *codec) |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 164 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 165 | struct hdmi_spec *spec; |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 166 | int i; |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 167 | |
| 168 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 169 | if (spec == NULL) |
| 170 | return -ENOMEM; |
| 171 | |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 172 | codec->spec = spec; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 173 | if (hdmi_parse_codec(codec) < 0) { |
Wu Fengguang | f424367 | 2009-10-30 11:45:35 +0100 | [diff] [blame] | 174 | codec->spec = NULL; |
| 175 | kfree(spec); |
| 176 | return -EINVAL; |
| 177 | } |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 178 | codec->patch_ops = intel_hdmi_patch_ops; |
| 179 | |
Wu Fengguang | 54a25f8 | 2009-10-30 11:44:26 +0100 | [diff] [blame] | 180 | for (i = 0; i < spec->num_pins; i++) |
| 181 | snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i); |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 182 | |
Wu Fengguang | 698544d | 2008-11-19 08:56:17 +0800 | [diff] [blame] | 183 | init_channel_allocations(); |
| 184 | |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 188 | static struct hda_codec_preset snd_hda_preset_intelhdmi[] = { |
Wu Fengguang | 41da2e0 | 2010-05-14 16:36:13 +0800 | [diff] [blame] | 189 | { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_intel_hdmi }, |
| 190 | { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_intel_hdmi }, |
| 191 | { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_intel_hdmi }, |
| 192 | { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_intel_hdmi }, |
| 193 | { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi }, |
| 194 | { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi }, |
Wu Fengguang | e48b008 | 2010-05-14 16:36:14 +0800 | [diff] [blame] | 195 | { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_intel_hdmi }, |
Wu Fengguang | 41da2e0 | 2010-05-14 16:36:13 +0800 | [diff] [blame] | 196 | { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi }, |
| 197 | {} /* terminator */ |
Wu, Fengguang | 9150487 | 2008-11-05 11:16:56 +0800 | [diff] [blame] | 198 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 199 | |
| 200 | MODULE_ALIAS("snd-hda-codec-id:808629fb"); |
| 201 | MODULE_ALIAS("snd-hda-codec-id:80862801"); |
| 202 | MODULE_ALIAS("snd-hda-codec-id:80862802"); |
| 203 | MODULE_ALIAS("snd-hda-codec-id:80862803"); |
Wu Fengguang | a57c0eb | 2009-02-11 15:22:31 +0800 | [diff] [blame] | 204 | MODULE_ALIAS("snd-hda-codec-id:80862804"); |
Wu Fengguang | e48b008 | 2010-05-14 16:36:14 +0800 | [diff] [blame] | 205 | MODULE_ALIAS("snd-hda-codec-id:80862805"); |
Jaroslav Kysela | 87a8c37 | 2009-07-23 10:58:29 +0200 | [diff] [blame] | 206 | MODULE_ALIAS("snd-hda-codec-id:80860054"); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 207 | MODULE_ALIAS("snd-hda-codec-id:10951392"); |
| 208 | |
| 209 | MODULE_LICENSE("GPL"); |
| 210 | MODULE_DESCRIPTION("Intel HDMI HD-audio codec"); |
| 211 | |
| 212 | static struct hda_codec_preset_list intel_list = { |
| 213 | .preset = snd_hda_preset_intelhdmi, |
| 214 | .owner = THIS_MODULE, |
| 215 | }; |
| 216 | |
| 217 | static int __init patch_intelhdmi_init(void) |
| 218 | { |
| 219 | return snd_hda_add_codec_preset(&intel_list); |
| 220 | } |
| 221 | |
| 222 | static void __exit patch_intelhdmi_exit(void) |
| 223 | { |
| 224 | snd_hda_delete_codec_preset(&intel_list); |
| 225 | } |
| 226 | |
| 227 | module_init(patch_intelhdmi_init) |
| 228 | module_exit(patch_intelhdmi_exit) |