ALSA: hda - fix sparse warning
[firefly-linux-kernel-4.4.55.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 #include "hda_patch.h"
32
33 struct nvhdmi_spec {
34         struct hda_multi_out multiout;
35
36         struct hda_pcm pcm_rec;
37 };
38
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 },
42         {} /* terminator */
43 };
44
45 /*
46  * Controls
47  */
48 static 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
60 static 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  */
69 static 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
77 static 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
85 static 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
96 static 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
111 static 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";
120         info->pcm_type = HDA_PCM_TYPE_HDMI;
121         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
122
123         return 0;
124 }
125
126 static void nvhdmi_free(struct hda_codec *codec)
127 {
128         kfree(codec->spec);
129 }
130
131 static 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
138 static 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  */
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 },
165         {} /* terminator */
166 };