]> err.no Git - linux-2.6/blob - sound/pci/hda/patch_atihdmi.c
[ALSA] hda-codec - Add SI HDMI codec support
[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 <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
30
31 struct atihdmi_spec {
32         struct hda_multi_out multiout;
33
34         struct hda_pcm pcm_rec;
35 };
36
37 static struct hda_verb atihdmi_basic_init[] = {
38         /* enable digital output on pin widget */
39         { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
40         {} /* terminator */
41 };
42
43 /*
44  * Controls
45  */
46 static int atihdmi_build_controls(struct hda_codec *codec)
47 {
48         struct atihdmi_spec *spec = codec->spec;
49         int err;
50
51         err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
52         if (err < 0)
53                 return err;
54
55         return 0;
56 }
57
58 static int atihdmi_init(struct hda_codec *codec)
59 {
60         snd_hda_sequence_write(codec, atihdmi_basic_init);
61         /* SI codec requires to unmute the pin */
62         if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
63                 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
64                                     AMP_OUT_UNMUTE);
65         return 0;
66 }
67
68 /*
69  * Digital out
70  */
71 static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
72                                      struct hda_codec *codec,
73                                      struct snd_pcm_substream *substream)
74 {
75         struct atihdmi_spec *spec = codec->spec;
76         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
77 }
78
79 static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
80                                       struct hda_codec *codec,
81                                       struct snd_pcm_substream *substream)
82 {
83         struct atihdmi_spec *spec = codec->spec;
84         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
85 }
86
87 static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
88                                             struct hda_codec *codec,
89                                             unsigned int stream_tag,
90                                             unsigned int format,
91                                             struct snd_pcm_substream *substream)
92 {
93         struct atihdmi_spec *spec = codec->spec;
94         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
95                                              format, substream);
96 }
97
98 static struct hda_pcm_stream atihdmi_pcm_digital_playback = {
99         .substreams = 1,
100         .channels_min = 2,
101         .channels_max = 2,
102         .nid = 0x2, /* NID to query formats and rates and setup streams */
103         .ops = {
104                 .open = atihdmi_dig_playback_pcm_open,
105                 .close = atihdmi_dig_playback_pcm_close,
106                 .prepare = atihdmi_dig_playback_pcm_prepare
107         },
108 };
109
110 static int atihdmi_build_pcms(struct hda_codec *codec)
111 {
112         struct atihdmi_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 = "ATI HDMI";
119         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
120
121         return 0;
122 }
123
124 static void atihdmi_free(struct hda_codec *codec)
125 {
126         kfree(codec->spec);
127 }
128
129 static struct hda_codec_ops atihdmi_patch_ops = {
130         .build_controls = atihdmi_build_controls,
131         .build_pcms = atihdmi_build_pcms,
132         .init = atihdmi_init,
133         .free = atihdmi_free,
134 };
135
136 static int patch_atihdmi(struct hda_codec *codec)
137 {
138         struct atihdmi_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 = 0x2; /* NID for copying analog to digital,
149                                            * seems to be unused in pure-digital
150                                            * case. */
151
152         codec->patch_ops = atihdmi_patch_ops;
153
154         return 0;
155 }
156
157 /*
158  * patch entries
159  */
160 struct hda_codec_preset snd_hda_preset_atihdmi[] = {
161         { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
162         { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
163         { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
164         { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
165         { .id = 0x10951392, .name = "SI HDMI", .patch = patch_atihdmi },
166         {} /* terminator */
167 };