diff options
Diffstat (limited to 'sound/pci/hda/patch_nvhdmi.c')
-rw-r--r-- | sound/pci/hda/patch_nvhdmi.c | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c new file mode 100644 index 000000000000..1a65775d28e1 --- /dev/null +++ b/sound/pci/hda/patch_nvhdmi.c | |||
@@ -0,0 +1,164 @@ | |||
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->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback; | ||
120 | |||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | static void nvhdmi_free(struct hda_codec *codec) | ||
125 | { | ||
126 | kfree(codec->spec); | ||
127 | } | ||
128 | |||
129 | static struct hda_codec_ops nvhdmi_patch_ops = { | ||
130 | .build_controls = nvhdmi_build_controls, | ||
131 | .build_pcms = nvhdmi_build_pcms, | ||
132 | .init = nvhdmi_init, | ||
133 | .free = nvhdmi_free, | ||
134 | }; | ||
135 | |||
136 | static int patch_nvhdmi(struct hda_codec *codec) | ||
137 | { | ||
138 | struct nvhdmi_spec *spec; | ||
139 | |||
140 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
141 | if (spec == NULL) | ||
142 | return -ENOMEM; | ||
143 | |||
144 | codec->spec = spec; | ||
145 | |||
146 | spec->multiout.num_dacs = 0; /* no analog */ | ||
147 | spec->multiout.max_channels = 2; | ||
148 | spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital, | ||
149 | * seems to be unused in pure-digital | ||
150 | * case. */ | ||
151 | |||
152 | codec->patch_ops = nvhdmi_patch_ops; | ||
153 | |||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | /* | ||
158 | * patch entries | ||
159 | */ | ||
160 | struct hda_codec_preset snd_hda_preset_nvhdmi[] = { | ||
161 | { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi }, | ||
162 | { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi }, | ||
163 | {} /* terminator */ | ||
164 | }; | ||