Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 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 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/slab.h> |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include "hda_codec.h" |
| 29 | #include "hda_local.h" |
Harvey Harrison | 3c9a320 | 2008-02-29 11:59:26 +0100 | [diff] [blame] | 30 | #include "hda_patch.h" |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 31 | |
| 32 | struct atihdmi_spec { |
| 33 | struct hda_multi_out multiout; |
| 34 | |
| 35 | struct hda_pcm pcm_rec; |
| 36 | }; |
| 37 | |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 38 | #define CVT_NID 0x02 /* audio converter */ |
| 39 | #define PIN_NID 0x03 /* HDMI output pin */ |
| 40 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 41 | static struct hda_verb atihdmi_basic_init[] = { |
| 42 | /* enable digital output on pin widget */ |
| 43 | { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
| 44 | {} /* terminator */ |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * Controls |
| 49 | */ |
| 50 | static int atihdmi_build_controls(struct hda_codec *codec) |
| 51 | { |
| 52 | struct atihdmi_spec *spec = codec->spec; |
| 53 | int err; |
| 54 | |
| 55 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); |
| 56 | if (err < 0) |
| 57 | return err; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static int atihdmi_init(struct hda_codec *codec) |
| 63 | { |
| 64 | snd_hda_sequence_write(codec, atihdmi_basic_init); |
Takashi Iwai | 12a733e | 2008-02-04 12:32:20 +0100 | [diff] [blame] | 65 | /* SI codec requires to unmute the pin */ |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 66 | if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP) |
| 67 | snd_hda_codec_write(codec, PIN_NID, 0, |
| 68 | AC_VERB_SET_AMP_GAIN_MUTE, |
Takashi Iwai | 12a733e | 2008-02-04 12:32:20 +0100 | [diff] [blame] | 69 | AMP_OUT_UNMUTE); |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 73 | /* |
| 74 | * Digital out |
| 75 | */ |
| 76 | static int atihdmi_dig_playback_pcm_open(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_open(codec, &spec->multiout); |
| 82 | } |
| 83 | |
| 84 | static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 85 | struct hda_codec *codec, |
| 86 | struct snd_pcm_substream *substream) |
| 87 | { |
| 88 | struct atihdmi_spec *spec = codec->spec; |
| 89 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 90 | } |
| 91 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 92 | static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 93 | struct hda_codec *codec, |
| 94 | unsigned int stream_tag, |
| 95 | unsigned int format, |
| 96 | struct snd_pcm_substream *substream) |
| 97 | { |
| 98 | struct atihdmi_spec *spec = codec->spec; |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 99 | int chans = substream->runtime->channels; |
| 100 | int i, err; |
| 101 | |
| 102 | err = snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, |
| 103 | format, substream); |
| 104 | if (err < 0) |
| 105 | return err; |
| 106 | snd_hda_codec_write(codec, CVT_NID, 0, AC_VERB_SET_CVT_CHAN_COUNT, |
| 107 | chans - 1); |
| 108 | /* FIXME: XXX */ |
| 109 | for (i = 0; i < chans; i++) { |
| 110 | snd_hda_codec_write(codec, CVT_NID, 0, |
| 111 | AC_VERB_SET_HDMI_CHAN_SLOT, |
| 112 | (i << 4) | i); |
| 113 | } |
| 114 | return 0; |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 117 | static struct hda_pcm_stream atihdmi_pcm_digital_playback = { |
| 118 | .substreams = 1, |
| 119 | .channels_min = 2, |
| 120 | .channels_max = 2, |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 121 | .nid = CVT_NID, /* NID to query formats and rates and setup streams */ |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 122 | .ops = { |
| 123 | .open = atihdmi_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 124 | .close = atihdmi_dig_playback_pcm_close, |
| 125 | .prepare = atihdmi_dig_playback_pcm_prepare |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 126 | }, |
| 127 | }; |
| 128 | |
| 129 | static int atihdmi_build_pcms(struct hda_codec *codec) |
| 130 | { |
| 131 | struct atihdmi_spec *spec = codec->spec; |
| 132 | struct hda_pcm *info = &spec->pcm_rec; |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 133 | unsigned int chans; |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 134 | |
| 135 | codec->num_pcms = 1; |
| 136 | codec->pcm_info = info; |
| 137 | |
| 138 | info->name = "ATI HDMI"; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 139 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 140 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; |
| 141 | |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 142 | /* FIXME: we must check ELD and change the PCM parameters dynamically |
| 143 | */ |
| 144 | chans = get_wcaps(codec, CVT_NID); |
| 145 | chans = (chans & AC_WCAP_CHAN_CNT_EXT) >> 13; |
| 146 | chans = ((chans << 1) | 1) + 1; |
| 147 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans; |
| 148 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static void atihdmi_free(struct hda_codec *codec) |
| 153 | { |
| 154 | kfree(codec->spec); |
| 155 | } |
| 156 | |
| 157 | static struct hda_codec_ops atihdmi_patch_ops = { |
| 158 | .build_controls = atihdmi_build_controls, |
| 159 | .build_pcms = atihdmi_build_pcms, |
| 160 | .init = atihdmi_init, |
| 161 | .free = atihdmi_free, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static int patch_atihdmi(struct hda_codec *codec) |
| 165 | { |
| 166 | struct atihdmi_spec *spec; |
| 167 | |
| 168 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 169 | if (spec == NULL) |
| 170 | return -ENOMEM; |
| 171 | |
| 172 | codec->spec = spec; |
| 173 | |
| 174 | spec->multiout.num_dacs = 0; /* no analog */ |
| 175 | spec->multiout.max_channels = 2; |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 176 | /* NID for copying analog to digital, |
| 177 | * seems to be unused in pure-digital |
| 178 | * case. |
| 179 | */ |
| 180 | spec->multiout.dig_out_nid = CVT_NID; |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 181 | |
| 182 | codec->patch_ops = atihdmi_patch_ops; |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * patch entries |
| 189 | */ |
| 190 | struct hda_codec_preset snd_hda_preset_atihdmi[] = { |
| 191 | { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, |
Tobin Davis | 2dcd522 | 2007-07-10 17:04:57 +0200 | [diff] [blame] | 192 | { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, |
Wolke Liu | e6db111 | 2007-04-27 12:20:57 +0200 | [diff] [blame] | 193 | { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, |
Wolke Liu | 27da183 | 2007-11-16 11:06:30 +0100 | [diff] [blame] | 194 | { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, |
Takashi Iwai | 862f76f | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 195 | { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_atihdmi }, |
Takashi Iwai | cc4d138 | 2008-02-07 17:12:01 +0100 | [diff] [blame] | 196 | { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi }, |
| 197 | { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi }, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 198 | {} /* terminator */ |
| 199 | }; |