[ALSA] hda-codec - Check PINCAP only for PIN widgets
[linux-2.6] / sound / pci / hda / patch_atihdmi.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ATI HDMI codecs
5  *
6  * Copyright (c) 2006 ATI Technologies Inc.
7  *
8  *
9  *  This driver is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This driver is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  */
23
24 #include <sound/driver.h>
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 atihdmi_spec {
33         struct hda_multi_out multiout;
34
35         struct hda_pcm pcm_rec;
36 };
37
38 static struct hda_verb atihdmi_basic_init[] = {
39         /* enable digital output on pin widget */
40         { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
41         {} /* terminator */
42 };
43
44 /*
45  * Controls
46  */
47 static int atihdmi_build_controls(struct hda_codec *codec)
48 {
49         struct atihdmi_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 atihdmi_init(struct hda_codec *codec)
60 {
61         snd_hda_sequence_write(codec, atihdmi_basic_init);
62         return 0;
63 }
64
65 /*
66  * Digital out
67  */
68 static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
69                                      struct hda_codec *codec,
70                                      struct snd_pcm_substream *substream)
71 {
72         struct atihdmi_spec *spec = codec->spec;
73         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
74 }
75
76 static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
77                                       struct hda_codec *codec,
78                                       struct snd_pcm_substream *substream)
79 {
80         struct atihdmi_spec *spec = codec->spec;
81         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
82 }
83
84 static int atihdmi_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 atihdmi_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 atihdmi_pcm_digital_playback = {
96         .substreams = 1,
97         .channels_min = 2,
98         .channels_max = 2,
99         .nid = 0x2, /* NID to query formats and rates and setup streams */
100         .ops = {
101                 .open = atihdmi_dig_playback_pcm_open,
102                 .close = atihdmi_dig_playback_pcm_close,
103                 .prepare = atihdmi_dig_playback_pcm_prepare
104         },
105 };
106
107 static int atihdmi_build_pcms(struct hda_codec *codec)
108 {
109         struct atihdmi_spec *spec = codec->spec;
110         struct hda_pcm *info = &spec->pcm_rec;
111
112         codec->num_pcms = 1;
113         codec->pcm_info = info;
114
115         info->name = "ATI HDMI";
116         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
117
118         return 0;
119 }
120
121 static void atihdmi_free(struct hda_codec *codec)
122 {
123         kfree(codec->spec);
124 }
125
126 static struct hda_codec_ops atihdmi_patch_ops = {
127         .build_controls = atihdmi_build_controls,
128         .build_pcms = atihdmi_build_pcms,
129         .init = atihdmi_init,
130         .free = atihdmi_free,
131 };
132
133 static int patch_atihdmi(struct hda_codec *codec)
134 {
135         struct atihdmi_spec *spec;
136
137         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
138         if (spec == NULL)
139                 return -ENOMEM;
140
141         codec->spec = spec;
142
143         spec->multiout.num_dacs = 0;      /* no analog */
144         spec->multiout.max_channels = 2;
145         spec->multiout.dig_out_nid = 0x2; /* NID for copying analog to digital,
146                                            * seems to be unused in pure-digital
147                                            * case. */
148
149         codec->patch_ops = atihdmi_patch_ops;
150
151         return 0;
152 }
153
154 /*
155  * patch entries
156  */
157 struct hda_codec_preset snd_hda_preset_atihdmi[] = {
158         { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
159         { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
160         { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
161         { .id = 0x1002aa01, .name = "ATI R600 HDMI", .patch = patch_atihdmi },
162         {} /* terminator */
163 };