patch_intelhdmi.c 6.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*
 *
 *  patch_intelhdmi.c - Patch for Intel HDMI codecs
 *
 *  Copyright(c) 2008 Intel Corporation. All rights reserved.
 *
 *  Authors:
 *  			Jiang Zhe <zhe.jiang@intel.com>
 *  			Wu Fengguang <wfg@linux.intel.com>
 *
 *  Maintained by:
 *  			Wu Fengguang <wfg@linux.intel.com>
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the Free
 *  Software Foundation; either version 2 of the License, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software Foundation,
 *  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <sound/core.h>
#include "hda_codec.h"
#include "hda_local.h"

W
Wu Fengguang 已提交
36 37 38 39 40 41 42
/*
 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
 * could support two independent pipes, each of them can be connected to one or
 * more ports (DVI, HDMI or DisplayPort).
 *
 * The HDA correspondence of pipes/ports are converter/pin nodes.
 */
43
#define MAX_HDMI_CVTS	3
44
#define MAX_HDMI_PINS	3
45

46 47 48
#include "patch_hdmi.c"

static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = {
W
Wu Fengguang 已提交
49 50
	"INTEL HDMI 0",
	"INTEL HDMI 1",
51
	"INTEL HDMI 2",
W
Wu Fengguang 已提交
52
};
53 54

/*
55
 * HDMI callbacks
56 57
 */

58
static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
59
					   struct hda_codec *codec,
60 61
					   unsigned int stream_tag,
					   unsigned int format,
62
					   struct snd_pcm_substream *substream)
63
{
W
Wu Fengguang 已提交
64
	hdmi_set_channel_count(codec, hinfo->nid,
65
			       substream->runtime->channels);
66

W
Wu Fengguang 已提交
67
	hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
68

69
	return hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
70 71
}

72
static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
73 74 75 76 77 78 79 80 81 82
					   struct hda_codec *codec,
					   struct snd_pcm_substream *substream)
{
	return 0;
}

static struct hda_pcm_stream intel_hdmi_pcm_playback = {
	.substreams = 1,
	.channels_min = 2,
	.ops = {
83
		.open = hdmi_pcm_open,
84 85
		.prepare = intel_hdmi_playback_pcm_prepare,
		.cleanup = intel_hdmi_playback_pcm_cleanup,
86 87 88 89 90
	},
};

static int intel_hdmi_build_pcms(struct hda_codec *codec)
{
91
	struct hdmi_spec *spec = codec->spec;
W
Wu Fengguang 已提交
92 93
	struct hda_pcm *info = spec->pcm_rec;
	int i;
94

W
Wu Fengguang 已提交
95
	codec->num_pcms = spec->num_cvts;
96 97
	codec->pcm_info = info;

W
Wu Fengguang 已提交
98
	for (i = 0; i < codec->num_pcms; i++, info++) {
99 100 101 102 103
		unsigned int chans;

		chans = get_wcaps(codec, spec->cvt[i]);
		chans = get_wcaps_channels(chans);

W
Wu Fengguang 已提交
104 105 106 107 108
		info->name = intel_hdmi_pcm_names[i];
		info->pcm_type = HDA_PCM_TYPE_HDMI;
		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
							intel_hdmi_pcm_playback;
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
109
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
W
Wu Fengguang 已提交
110
	}
111 112 113 114 115 116

	return 0;
}

static int intel_hdmi_build_controls(struct hda_codec *codec)
{
117
	struct hdmi_spec *spec = codec->spec;
118
	int err;
W
Wu Fengguang 已提交
119
	int i;
120

W
Wu Fengguang 已提交
121 122 123 124 125
	for (i = 0; i < codec->num_pcms; i++) {
		err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
		if (err < 0)
			return err;
	}
126 127 128 129 130 131

	return 0;
}

static int intel_hdmi_init(struct hda_codec *codec)
{
132
	struct hdmi_spec *spec = codec->spec;
W
Wu Fengguang 已提交
133
	int i;
134

W
Wu Fengguang 已提交
135 136 137 138 139 140
	for (i = 0; spec->pin[i]; i++) {
		hdmi_enable_output(codec, spec->pin[i]);
		snd_hda_codec_write(codec, spec->pin[i], 0,
				    AC_VERB_SET_UNSOLICITED_ENABLE,
				    AC_USRSP_EN | spec->pin[i]);
	}
141 142 143 144 145
	return 0;
}

static void intel_hdmi_free(struct hda_codec *codec)
{
146
	struct hdmi_spec *spec = codec->spec;
W
Wu Fengguang 已提交
147 148 149 150
	int i;

	for (i = 0; i < spec->num_pins; i++)
		snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
T
Takashi Iwai 已提交
151 152

	kfree(spec);
153 154 155 156 157 158 159
}

static struct hda_codec_ops intel_hdmi_patch_ops = {
	.init			= intel_hdmi_init,
	.free			= intel_hdmi_free,
	.build_pcms		= intel_hdmi_build_pcms,
	.build_controls 	= intel_hdmi_build_controls,
160
	.unsol_event		= hdmi_unsol_event,
161 162
};

163
static int patch_intel_hdmi(struct hda_codec *codec)
164
{
165
	struct hdmi_spec *spec;
W
Wu Fengguang 已提交
166
	int i;
167 168 169 170 171 172

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (spec == NULL)
		return -ENOMEM;

	codec->spec = spec;
173
	if (hdmi_parse_codec(codec) < 0) {
174 175 176 177
		codec->spec = NULL;
		kfree(spec);
		return -EINVAL;
	}
178 179
	codec->patch_ops = intel_hdmi_patch_ops;

W
Wu Fengguang 已提交
180 181
	for (i = 0; i < spec->num_pins; i++)
		snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
182

183 184
	init_channel_allocations();

185 186 187
	return 0;
}

188
static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
189 190 191 192 193 194
{ .id = 0x808629fb, .name = "Crestline HDMI",	.patch = patch_intel_hdmi },
{ .id = 0x80862801, .name = "Bearlake HDMI",	.patch = patch_intel_hdmi },
{ .id = 0x80862802, .name = "Cantiga HDMI",	.patch = patch_intel_hdmi },
{ .id = 0x80862803, .name = "Eaglelake HDMI",	.patch = patch_intel_hdmi },
{ .id = 0x80862804, .name = "IbexPeak HDMI",	.patch = patch_intel_hdmi },
{ .id = 0x80860054, .name = "IbexPeak HDMI",	.patch = patch_intel_hdmi },
195
{ .id = 0x80862805, .name = "CougarPoint HDMI",	.patch = patch_intel_hdmi },
196 197
{ .id = 0x10951392, .name = "SiI1392 HDMI",	.patch = patch_intel_hdmi },
{} /* terminator */
198
};
199 200 201 202 203

MODULE_ALIAS("snd-hda-codec-id:808629fb");
MODULE_ALIAS("snd-hda-codec-id:80862801");
MODULE_ALIAS("snd-hda-codec-id:80862802");
MODULE_ALIAS("snd-hda-codec-id:80862803");
204
MODULE_ALIAS("snd-hda-codec-id:80862804");
205
MODULE_ALIAS("snd-hda-codec-id:80862805");
206
MODULE_ALIAS("snd-hda-codec-id:80860054");
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
MODULE_ALIAS("snd-hda-codec-id:10951392");

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Intel HDMI HD-audio codec");

static struct hda_codec_preset_list intel_list = {
	.preset = snd_hda_preset_intelhdmi,
	.owner = THIS_MODULE,
};

static int __init patch_intelhdmi_init(void)
{
	return snd_hda_add_codec_preset(&intel_list);
}

static void __exit patch_intelhdmi_exit(void)
{
	snd_hda_delete_codec_preset(&intel_list);
}

module_init(patch_intelhdmi_init)
module_exit(patch_intelhdmi_exit)