Merge branch 'sched-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / sound / pci / hda / patch_nvhdmi.c
CommitLineData
9a10eb21
WN
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for NVIDIA HDMI codecs
5 *
6 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
7 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
8 *
9 *
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.
14 *
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.
19 *
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
23 */
24
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
32struct nvhdmi_spec {
33 struct hda_multi_out multiout;
34
35 struct hda_pcm pcm_rec;
36};
37
38static struct hda_verb nvhdmi_basic_init[] = {
39 /* enable digital output on pin widget */
40 { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
41 {} /* terminator */
42};
43
44/*
45 * Controls
46 */
47static int nvhdmi_build_controls(struct hda_codec *codec)
48{
49 struct nvhdmi_spec *spec = codec->spec;
50 int err;
51
52 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
53 if (err < 0)
54 return err;
55
56 return 0;
57}
58
59static int nvhdmi_init(struct hda_codec *codec)
60{
61 snd_hda_sequence_write(codec, nvhdmi_basic_init);
62 return 0;
63}
64
65/*
66 * Digital out
67 */
68static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
69 struct hda_codec *codec,
70 struct snd_pcm_substream *substream)
71{
72 struct nvhdmi_spec *spec = codec->spec;
73 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
74}
75
76static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
77 struct hda_codec *codec,
78 struct snd_pcm_substream *substream)
79{
80 struct nvhdmi_spec *spec = codec->spec;
81 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
82}
83
84static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
85 struct hda_codec *codec,
86 unsigned int stream_tag,
87 unsigned int format,
88 struct snd_pcm_substream *substream)
89{
90 struct nvhdmi_spec *spec = codec->spec;
91 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
92 format, substream);
93}
94
95static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
96 .substreams = 1,
97 .channels_min = 2,
98 .channels_max = 2,
99 .nid = 0x4, /* NID to query formats and rates and setup streams */
100 .rates = SNDRV_PCM_RATE_48000,
101 .maxbps = 16,
102 .formats = SNDRV_PCM_FMTBIT_S16_LE,
103 .ops = {
104 .open = nvhdmi_dig_playback_pcm_open,
105 .close = nvhdmi_dig_playback_pcm_close,
106 .prepare = nvhdmi_dig_playback_pcm_prepare
107 },
108};
109
110static int nvhdmi_build_pcms(struct hda_codec *codec)
111{
112 struct nvhdmi_spec *spec = codec->spec;
113 struct hda_pcm *info = &spec->pcm_rec;
114
115 codec->num_pcms = 1;
116 codec->pcm_info = info;
117
118 info->name = "NVIDIA HDMI";
ec4e86ba 119 info->pcm_type = HDA_PCM_TYPE_HDMI;
9a10eb21
WN
120 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
121
122 return 0;
123}
124
125static void nvhdmi_free(struct hda_codec *codec)
126{
127 kfree(codec->spec);
128}
129
130static struct hda_codec_ops nvhdmi_patch_ops = {
131 .build_controls = nvhdmi_build_controls,
132 .build_pcms = nvhdmi_build_pcms,
133 .init = nvhdmi_init,
134 .free = nvhdmi_free,
135};
136
137static int patch_nvhdmi(struct hda_codec *codec)
138{
139 struct nvhdmi_spec *spec;
140
141 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
142 if (spec == NULL)
143 return -ENOMEM;
144
145 codec->spec = spec;
146
147 spec->multiout.num_dacs = 0; /* no analog */
148 spec->multiout.max_channels = 2;
149 spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital,
150 * seems to be unused in pure-digital
151 * case. */
152
153 codec->patch_ops = nvhdmi_patch_ops;
154
155 return 0;
156}
157
158/*
159 * patch entries
160 */
1289e9e8 161static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
31117b78 162 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi },
f84e3e91 163 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi },
31117b78
TI
164 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi },
165 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi },
e3d6ce6f 166 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi },
9a10eb21
WN
167 {} /* terminator */
168};
1289e9e8
TI
169
170MODULE_ALIAS("snd-hda-codec-id:10de0002");
f84e3e91 171MODULE_ALIAS("snd-hda-codec-id:10de0006");
1289e9e8 172MODULE_ALIAS("snd-hda-codec-id:10de0007");
4151d154 173MODULE_ALIAS("snd-hda-codec-id:10de0067");
e3d6ce6f 174MODULE_ALIAS("snd-hda-codec-id:10de8001");
1289e9e8
TI
175
176MODULE_LICENSE("GPL");
177MODULE_DESCRIPTION("Nvidia HDMI HD-audio codec");
178
179static struct hda_codec_preset_list nvhdmi_list = {
180 .preset = snd_hda_preset_nvhdmi,
181 .owner = THIS_MODULE,
182};
183
184static int __init patch_nvhdmi_init(void)
185{
186 return snd_hda_add_codec_preset(&nvhdmi_list);
187}
188
189static void __exit patch_nvhdmi_exit(void)
190{
191 snd_hda_delete_codec_preset(&nvhdmi_list);
192}
193
194module_init(patch_nvhdmi_init)
195module_exit(patch_nvhdmi_exit)