blob: 1360d54a7d0197090e5fd9498fe2c9fb288e2d2a [file] [log] [blame]
Wei Ni9a10eb22008-09-26 13:45:46 +08001/*
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"
Hannes Eder42e81c92008-11-21 16:03:24 +010031#include "hda_patch.h"
Wei Ni9a10eb22008-09-26 13:45:46 +080032
33struct nvhdmi_spec {
34 struct hda_multi_out multiout;
35
36 struct hda_pcm pcm_rec;
37};
38
39static struct hda_verb nvhdmi_basic_init[] = {
40 /* enable digital output on pin widget */
41 { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
42 {} /* terminator */
43};
44
45/*
46 * Controls
47 */
48static int nvhdmi_build_controls(struct hda_codec *codec)
49{
50 struct nvhdmi_spec *spec = codec->spec;
51 int err;
52
53 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
54 if (err < 0)
55 return err;
56
57 return 0;
58}
59
60static int nvhdmi_init(struct hda_codec *codec)
61{
62 snd_hda_sequence_write(codec, nvhdmi_basic_init);
63 return 0;
64}
65
66/*
67 * Digital out
68 */
69static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
70 struct hda_codec *codec,
71 struct snd_pcm_substream *substream)
72{
73 struct nvhdmi_spec *spec = codec->spec;
74 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
75}
76
77static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
78 struct hda_codec *codec,
79 struct snd_pcm_substream *substream)
80{
81 struct nvhdmi_spec *spec = codec->spec;
82 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
83}
84
85static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
86 struct hda_codec *codec,
87 unsigned int stream_tag,
88 unsigned int format,
89 struct snd_pcm_substream *substream)
90{
91 struct nvhdmi_spec *spec = codec->spec;
92 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
93 format, substream);
94}
95
96static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
97 .substreams = 1,
98 .channels_min = 2,
99 .channels_max = 2,
100 .nid = 0x4, /* NID to query formats and rates and setup streams */
101 .rates = SNDRV_PCM_RATE_48000,
102 .maxbps = 16,
103 .formats = SNDRV_PCM_FMTBIT_S16_LE,
104 .ops = {
105 .open = nvhdmi_dig_playback_pcm_open,
106 .close = nvhdmi_dig_playback_pcm_close,
107 .prepare = nvhdmi_dig_playback_pcm_prepare
108 },
109};
110
111static int nvhdmi_build_pcms(struct hda_codec *codec)
112{
113 struct nvhdmi_spec *spec = codec->spec;
114 struct hda_pcm *info = &spec->pcm_rec;
115
116 codec->num_pcms = 1;
117 codec->pcm_info = info;
118
119 info->name = "NVIDIA HDMI";
Takashi Iwaiec4e86b2008-10-16 08:02:41 +0200120 info->pcm_type = HDA_PCM_TYPE_HDMI;
Wei Ni9a10eb22008-09-26 13:45:46 +0800121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
122
123 return 0;
124}
125
126static void nvhdmi_free(struct hda_codec *codec)
127{
128 kfree(codec->spec);
129}
130
131static struct hda_codec_ops nvhdmi_patch_ops = {
132 .build_controls = nvhdmi_build_controls,
133 .build_pcms = nvhdmi_build_pcms,
134 .init = nvhdmi_init,
135 .free = nvhdmi_free,
136};
137
138static int patch_nvhdmi(struct hda_codec *codec)
139{
140 struct nvhdmi_spec *spec;
141
142 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
143 if (spec == NULL)
144 return -ENOMEM;
145
146 codec->spec = spec;
147
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
152 * case. */
153
154 codec->patch_ops = nvhdmi_patch_ops;
155
156 return 0;
157}
158
159/*
160 * patch entries
161 */
162struct 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 },
165 {} /* terminator */
166};