blob: 12272508b1124abebcb68fdcc06458727cbe86da [file] [log] [blame]
Felix Kuehling778b6e12006-05-17 11:22:21 +02001/*
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
Felix Kuehling778b6e12006-05-17 11:22:21 +020024#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
Felix Kuehling778b6e12006-05-17 11:22:21 +020027#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010030#include "hda_patch.h"
Felix Kuehling778b6e12006-05-17 11:22:21 +020031
32struct atihdmi_spec {
33 struct hda_multi_out multiout;
34
35 struct hda_pcm pcm_rec;
36};
37
38static 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 */
47static 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
59static int atihdmi_init(struct hda_codec *codec)
60{
61 snd_hda_sequence_write(codec, atihdmi_basic_init);
Takashi Iwai12a733e2008-02-04 12:32:20 +010062 /* SI codec requires to unmute the pin */
63 if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
64 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
65 AMP_OUT_UNMUTE);
Felix Kuehling778b6e12006-05-17 11:22:21 +020066 return 0;
67}
68
Felix Kuehling778b6e12006-05-17 11:22:21 +020069/*
70 * Digital out
71 */
72static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
73 struct hda_codec *codec,
74 struct snd_pcm_substream *substream)
75{
76 struct atihdmi_spec *spec = codec->spec;
77 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
78}
79
80static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
81 struct hda_codec *codec,
82 struct snd_pcm_substream *substream)
83{
84 struct atihdmi_spec *spec = codec->spec;
85 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
86}
87
Takashi Iwai6b97eb42007-04-05 14:51:48 +020088static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
89 struct hda_codec *codec,
90 unsigned int stream_tag,
91 unsigned int format,
92 struct snd_pcm_substream *substream)
93{
94 struct atihdmi_spec *spec = codec->spec;
95 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
96 format, substream);
97}
98
Felix Kuehling778b6e12006-05-17 11:22:21 +020099static struct hda_pcm_stream atihdmi_pcm_digital_playback = {
100 .substreams = 1,
101 .channels_min = 2,
102 .channels_max = 2,
103 .nid = 0x2, /* NID to query formats and rates and setup streams */
104 .ops = {
105 .open = atihdmi_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200106 .close = atihdmi_dig_playback_pcm_close,
107 .prepare = atihdmi_dig_playback_pcm_prepare
Felix Kuehling778b6e12006-05-17 11:22:21 +0200108 },
109};
110
111static int atihdmi_build_pcms(struct hda_codec *codec)
112{
113 struct atihdmi_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 = "ATI HDMI";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100120 info->pcm_type = HDA_PCM_TYPE_HDMI;
Felix Kuehling778b6e12006-05-17 11:22:21 +0200121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
122
123 return 0;
124}
125
126static void atihdmi_free(struct hda_codec *codec)
127{
128 kfree(codec->spec);
129}
130
131static struct hda_codec_ops atihdmi_patch_ops = {
132 .build_controls = atihdmi_build_controls,
133 .build_pcms = atihdmi_build_pcms,
134 .init = atihdmi_init,
135 .free = atihdmi_free,
Felix Kuehling778b6e12006-05-17 11:22:21 +0200136};
137
138static int patch_atihdmi(struct hda_codec *codec)
139{
140 struct atihdmi_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 = 0x2; /* NID for copying analog to digital,
151 * seems to be unused in pure-digital
152 * case. */
153
154 codec->patch_ops = atihdmi_patch_ops;
155
156 return 0;
157}
158
159/*
160 * patch entries
161 */
162struct hda_codec_preset snd_hda_preset_atihdmi[] = {
163 { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
Tobin Davis2dcd5222007-07-10 17:04:57 +0200164 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
Wolke Liue6db1112007-04-27 12:20:57 +0200165 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
Wolke Liu27da1832007-11-16 11:06:30 +0100166 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
Takashi Iwaicc4d1382008-02-07 17:12:01 +0100167 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
168 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
Felix Kuehling778b6e12006-05-17 11:22:21 +0200169 {} /* terminator */
170};