2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for NVIDIA HDMI codecs
6 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
7 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
10 * This driver is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This driver is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <sound/core.h>
29 #include "hda_codec.h"
30 #include "hda_local.h"
31 #include "hda_patch.h"
34 struct hda_multi_out multiout;
36 struct hda_pcm pcm_rec;
39 static struct hda_verb nvhdmi_basic_init[] = {
40 /* enable digital output on pin widget */
41 { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
48 static int nvhdmi_build_controls(struct hda_codec *codec)
50 struct nvhdmi_spec *spec = codec->spec;
53 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
60 static int nvhdmi_init(struct hda_codec *codec)
62 snd_hda_sequence_write(codec, nvhdmi_basic_init);
69 static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
70 struct hda_codec *codec,
71 struct snd_pcm_substream *substream)
73 struct nvhdmi_spec *spec = codec->spec;
74 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
77 static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
78 struct hda_codec *codec,
79 struct snd_pcm_substream *substream)
81 struct nvhdmi_spec *spec = codec->spec;
82 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
85 static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
86 struct hda_codec *codec,
87 unsigned int stream_tag,
89 struct snd_pcm_substream *substream)
91 struct nvhdmi_spec *spec = codec->spec;
92 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
96 static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
100 .nid = 0x4, /* NID to query formats and rates and setup streams */
101 .rates = SNDRV_PCM_RATE_48000,
103 .formats = SNDRV_PCM_FMTBIT_S16_LE,
105 .open = nvhdmi_dig_playback_pcm_open,
106 .close = nvhdmi_dig_playback_pcm_close,
107 .prepare = nvhdmi_dig_playback_pcm_prepare
111 static int nvhdmi_build_pcms(struct hda_codec *codec)
113 struct nvhdmi_spec *spec = codec->spec;
114 struct hda_pcm *info = &spec->pcm_rec;
117 codec->pcm_info = info;
119 info->name = "NVIDIA HDMI";
120 info->pcm_type = HDA_PCM_TYPE_HDMI;
121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
126 static void nvhdmi_free(struct hda_codec *codec)
131 static struct hda_codec_ops nvhdmi_patch_ops = {
132 .build_controls = nvhdmi_build_controls,
133 .build_pcms = nvhdmi_build_pcms,
138 static int patch_nvhdmi(struct hda_codec *codec)
140 struct nvhdmi_spec *spec;
142 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
148 spec->multiout.num_dacs = 0; /* no analog */
149 spec->multiout.max_channels = 2;
150 spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital,
151 * seems to be unused in pure-digital
154 codec->patch_ops = nvhdmi_patch_ops;
162 struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
163 { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi },
164 { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi },