ALSA: hda - Check the external mic pin more strictly for Conexant chips
[firewire-audio.git] / sound / pci / hda / patch_intelhdmi.c
blob36a9b83a6174d93f703bf76795e7ba140901c739
1 /*
3 * patch_intelhdmi.c - Patch for Intel HDMI codecs
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
7 * Authors:
8 * Jiang Zhe <zhe.jiang@intel.com>
9 * Wu Fengguang <wfg@linux.intel.com>
11 * Maintained by:
12 * Wu Fengguang <wfg@linux.intel.com>
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.
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.
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.
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <sound/core.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
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).
41 * The HDA correspondence of pipes/ports are converter/pin nodes.
43 #define MAX_HDMI_CVTS 3
44 #define MAX_HDMI_PINS 3
46 #include "patch_hdmi.c"
48 static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = {
49 "INTEL HDMI 0",
50 "INTEL HDMI 1",
51 "INTEL HDMI 2",
55 * HDMI callbacks
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)
64 hdmi_set_channel_count(codec, hinfo->nid,
65 substream->runtime->channels);
67 hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
69 return hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
72 static struct hda_pcm_stream intel_hdmi_pcm_playback = {
73 .substreams = 1,
74 .channels_min = 2,
75 .ops = {
76 .open = hdmi_pcm_open,
77 .prepare = intel_hdmi_playback_pcm_prepare,
81 static int intel_hdmi_build_pcms(struct hda_codec *codec)
83 struct hdmi_spec *spec = codec->spec;
84 struct hda_pcm *info = spec->pcm_rec;
85 int i;
87 codec->num_pcms = spec->num_cvts;
88 codec->pcm_info = info;
90 for (i = 0; i < codec->num_pcms; i++, info++) {
91 unsigned int chans;
93 chans = get_wcaps(codec, spec->cvt[i]);
94 chans = get_wcaps_channels(chans);
96 info->name = intel_hdmi_pcm_names[i];
97 info->pcm_type = HDA_PCM_TYPE_HDMI;
98 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
99 intel_hdmi_pcm_playback;
100 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
101 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
104 return 0;
107 static int intel_hdmi_build_controls(struct hda_codec *codec)
109 struct hdmi_spec *spec = codec->spec;
110 int err;
111 int i;
113 for (i = 0; i < codec->num_pcms; i++) {
114 err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
115 if (err < 0)
116 return err;
119 return 0;
122 static int intel_hdmi_init(struct hda_codec *codec)
124 struct hdmi_spec *spec = codec->spec;
125 int i;
127 for (i = 0; spec->pin[i]; i++) {
128 hdmi_enable_output(codec, spec->pin[i]);
129 snd_hda_codec_write(codec, spec->pin[i], 0,
130 AC_VERB_SET_UNSOLICITED_ENABLE,
131 AC_USRSP_EN | spec->pin[i]);
133 return 0;
136 static void intel_hdmi_free(struct hda_codec *codec)
138 struct hdmi_spec *spec = codec->spec;
139 int i;
141 for (i = 0; i < spec->num_pins; i++)
142 snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
144 kfree(spec);
147 static struct hda_codec_ops intel_hdmi_patch_ops = {
148 .init = intel_hdmi_init,
149 .free = intel_hdmi_free,
150 .build_pcms = intel_hdmi_build_pcms,
151 .build_controls = intel_hdmi_build_controls,
152 .unsol_event = hdmi_unsol_event,
155 static int patch_intel_hdmi(struct hda_codec *codec)
157 struct hdmi_spec *spec;
158 int i;
160 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
161 if (spec == NULL)
162 return -ENOMEM;
164 codec->spec = spec;
165 if (hdmi_parse_codec(codec) < 0) {
166 codec->spec = NULL;
167 kfree(spec);
168 return -EINVAL;
170 codec->patch_ops = intel_hdmi_patch_ops;
172 for (i = 0; i < spec->num_pins; i++)
173 snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
175 init_channel_allocations();
177 return 0;
180 static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
181 { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_intel_hdmi },
182 { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_intel_hdmi },
183 { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_intel_hdmi },
184 { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_intel_hdmi },
185 { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
186 { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_intel_hdmi },
187 { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_intel_hdmi },
188 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
189 {} /* terminator */
192 MODULE_ALIAS("snd-hda-codec-id:808629fb");
193 MODULE_ALIAS("snd-hda-codec-id:80862801");
194 MODULE_ALIAS("snd-hda-codec-id:80862802");
195 MODULE_ALIAS("snd-hda-codec-id:80862803");
196 MODULE_ALIAS("snd-hda-codec-id:80862804");
197 MODULE_ALIAS("snd-hda-codec-id:80862805");
198 MODULE_ALIAS("snd-hda-codec-id:80860054");
199 MODULE_ALIAS("snd-hda-codec-id:10951392");
201 MODULE_LICENSE("GPL");
202 MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
204 static struct hda_codec_preset_list intel_list = {
205 .preset = snd_hda_preset_intelhdmi,
206 .owner = THIS_MODULE,
209 static int __init patch_intelhdmi_init(void)
211 return snd_hda_add_codec_preset(&intel_list);
214 static void __exit patch_intelhdmi_exit(void)
216 snd_hda_delete_codec_preset(&intel_list);
219 module_init(patch_intelhdmi_init)
220 module_exit(patch_intelhdmi_exit)