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" |
| 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 | return 0; |
| 62 | } |
| 63 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 64 | /* |
| 65 | * Digital out |
| 66 | */ |
| 67 | static int atihdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 68 | struct hda_codec *codec, |
| 69 | struct snd_pcm_substream *substream) |
| 70 | { |
| 71 | struct atihdmi_spec *spec = codec->spec; |
| 72 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 73 | } |
| 74 | |
| 75 | static int atihdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 76 | struct hda_codec *codec, |
| 77 | struct snd_pcm_substream *substream) |
| 78 | { |
| 79 | struct atihdmi_spec *spec = codec->spec; |
| 80 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 81 | } |
| 82 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 83 | static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 84 | struct hda_codec *codec, |
| 85 | unsigned int stream_tag, |
| 86 | unsigned int format, |
| 87 | struct snd_pcm_substream *substream) |
| 88 | { |
| 89 | struct atihdmi_spec *spec = codec->spec; |
| 90 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, |
| 91 | format, substream); |
| 92 | } |
| 93 | |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 94 | static struct hda_pcm_stream atihdmi_pcm_digital_playback = { |
| 95 | .substreams = 1, |
| 96 | .channels_min = 2, |
| 97 | .channels_max = 2, |
| 98 | .nid = 0x2, /* NID to query formats and rates and setup streams */ |
| 99 | .ops = { |
| 100 | .open = atihdmi_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 101 | .close = atihdmi_dig_playback_pcm_close, |
| 102 | .prepare = atihdmi_dig_playback_pcm_prepare |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 103 | }, |
| 104 | }; |
| 105 | |
| 106 | static int atihdmi_build_pcms(struct hda_codec *codec) |
| 107 | { |
| 108 | struct atihdmi_spec *spec = codec->spec; |
| 109 | struct hda_pcm *info = &spec->pcm_rec; |
| 110 | |
| 111 | codec->num_pcms = 1; |
| 112 | codec->pcm_info = info; |
| 113 | |
| 114 | info->name = "ATI HDMI"; |
| 115 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static void atihdmi_free(struct hda_codec *codec) |
| 121 | { |
| 122 | kfree(codec->spec); |
| 123 | } |
| 124 | |
| 125 | static struct hda_codec_ops atihdmi_patch_ops = { |
| 126 | .build_controls = atihdmi_build_controls, |
| 127 | .build_pcms = atihdmi_build_pcms, |
| 128 | .init = atihdmi_init, |
| 129 | .free = atihdmi_free, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | static int patch_atihdmi(struct hda_codec *codec) |
| 133 | { |
| 134 | struct atihdmi_spec *spec; |
| 135 | |
| 136 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 137 | if (spec == NULL) |
| 138 | return -ENOMEM; |
| 139 | |
| 140 | codec->spec = spec; |
| 141 | |
| 142 | spec->multiout.num_dacs = 0; /* no analog */ |
| 143 | spec->multiout.max_channels = 2; |
| 144 | spec->multiout.dig_out_nid = 0x2; /* NID for copying analog to digital, |
| 145 | * seems to be unused in pure-digital |
| 146 | * case. */ |
| 147 | |
| 148 | codec->patch_ops = atihdmi_patch_ops; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * patch entries |
| 155 | */ |
| 156 | struct hda_codec_preset snd_hda_preset_atihdmi[] = { |
| 157 | { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, |
Tobin Davis | 2dcd522 | 2007-07-10 17:04:57 +0200 | [diff] [blame] | 158 | { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, |
Wolke Liu | e6db111 | 2007-04-27 12:20:57 +0200 | [diff] [blame] | 159 | { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, |
Wolke Liu | 27da183 | 2007-11-16 11:06:30 +0100 | [diff] [blame] | 160 | { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 161 | {} /* terminator */ |
| 162 | }; |