]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_nvhdmi.c
ALSA: hda - Fix PCM type of Nvidia HDMI devices
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_nvhdmi.c
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
32 struct nvhdmi_spec {
33         struct hda_multi_out multiout;
34
35         struct hda_pcm pcm_rec;
36 };
37
38 static 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  */
47 static 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
59 static 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  */
68 static 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
76 static 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
84 static 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
95 static 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
110 static 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";
119         info->pcm_type = HDA_PCM_TYPE_HDMI;
120         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
121
122         return 0;
123 }
124
125 static void nvhdmi_free(struct hda_codec *codec)
126 {
127         kfree(codec->spec);
128 }
129
130 static 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
137 static 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  */
161 struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
162         { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi },
163         { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi },
164         {} /* terminator */
165 };