Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
| 4 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 6 | * |
| 7 | * This driver is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This driver is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/pci.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include "hda_codec.h" |
| 29 | #include <sound/asoundef.h> |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 30 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/initval.h> |
| 32 | #include "hda_local.h" |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 33 | #include "hda_beep.h" |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 34 | #include <sound/hda_hwdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* |
| 37 | * vendor / preset table |
| 38 | */ |
| 39 | |
| 40 | struct hda_vendor_id { |
| 41 | unsigned int id; |
| 42 | const char *name; |
| 43 | }; |
| 44 | |
| 45 | /* codec vendor labels */ |
| 46 | static struct hda_vendor_id hda_vendor_ids[] = { |
Takashi Iwai | c8cd128 | 2008-02-13 16:59:29 +0100 | [diff] [blame] | 47 | { 0x1002, "ATI" }, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 48 | { 0x1013, "Cirrus Logic" }, |
Takashi Iwai | a922625 | 2006-09-17 22:05:54 +0200 | [diff] [blame] | 49 | { 0x1057, "Motorola" }, |
Takashi Iwai | c8cd128 | 2008-02-13 16:59:29 +0100 | [diff] [blame] | 50 | { 0x1095, "Silicon Image" }, |
Takashi Iwai | 31117b7 | 2008-12-16 14:43:21 +0100 | [diff] [blame] | 51 | { 0x10de, "Nvidia" }, |
Takashi Iwai | c8cd128 | 2008-02-13 16:59:29 +0100 | [diff] [blame] | 52 | { 0x10ec, "Realtek" }, |
Takashi Iwai | 4e01f54 | 2009-04-16 08:53:34 +0200 | [diff] [blame] | 53 | { 0x1102, "Creative" }, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 54 | { 0x1106, "VIA" }, |
Matthew Ranostay | 7f16859 | 2007-10-18 17:38:17 +0200 | [diff] [blame] | 55 | { 0x111d, "IDT" }, |
Takashi Iwai | c8cd128 | 2008-02-13 16:59:29 +0100 | [diff] [blame] | 56 | { 0x11c1, "LSI" }, |
Takashi Iwai | 54b903e | 2005-05-15 14:30:10 +0200 | [diff] [blame] | 57 | { 0x11d4, "Analog Devices" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { 0x13f6, "C-Media" }, |
Takashi Iwai | a922625 | 2006-09-17 22:05:54 +0200 | [diff] [blame] | 59 | { 0x14f1, "Conexant" }, |
Takashi Iwai | c8cd128 | 2008-02-13 16:59:29 +0100 | [diff] [blame] | 60 | { 0x17e8, "Chrontel" }, |
| 61 | { 0x1854, "LG" }, |
Mark Brown | 8199de3 | 2008-10-28 14:50:13 +0000 | [diff] [blame] | 62 | { 0x1aec, "Wolfson Microelectronics" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { 0x434d, "C-Media" }, |
Takashi Iwai | 74c6113 | 2008-12-18 09:11:33 +0100 | [diff] [blame] | 64 | { 0x8086, "Intel" }, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 65 | { 0x8384, "SigmaTel" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | {} /* terminator */ |
| 67 | }; |
| 68 | |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 69 | static DEFINE_MUTEX(preset_mutex); |
| 70 | static LIST_HEAD(hda_preset_tables); |
| 71 | |
| 72 | int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset) |
| 73 | { |
| 74 | mutex_lock(&preset_mutex); |
| 75 | list_add_tail(&preset->list, &hda_preset_tables); |
| 76 | mutex_unlock(&preset_mutex); |
| 77 | return 0; |
| 78 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 79 | EXPORT_SYMBOL_HDA(snd_hda_add_codec_preset); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 80 | |
| 81 | int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset) |
| 82 | { |
| 83 | mutex_lock(&preset_mutex); |
| 84 | list_del(&preset->list); |
| 85 | mutex_unlock(&preset_mutex); |
| 86 | return 0; |
| 87 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 88 | EXPORT_SYMBOL_HDA(snd_hda_delete_codec_preset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 91 | static void hda_power_work(struct work_struct *work); |
| 92 | static void hda_keep_power_on(struct hda_codec *codec); |
| 93 | #else |
| 94 | static inline void hda_keep_power_on(struct hda_codec *codec) {} |
| 95 | #endif |
| 96 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 97 | /** |
| 98 | * snd_hda_get_jack_location - Give a location string of the jack |
| 99 | * @cfg: pin default config value |
| 100 | * |
| 101 | * Parse the pin default config value and returns the string of the |
| 102 | * jack location, e.g. "Rear", "Front", etc. |
| 103 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 104 | const char *snd_hda_get_jack_location(u32 cfg) |
| 105 | { |
| 106 | static char *bases[7] = { |
| 107 | "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom", |
| 108 | }; |
| 109 | static unsigned char specials_idx[] = { |
| 110 | 0x07, 0x08, |
| 111 | 0x17, 0x18, 0x19, |
| 112 | 0x37, 0x38 |
| 113 | }; |
| 114 | static char *specials[] = { |
| 115 | "Rear Panel", "Drive Bar", |
| 116 | "Riser", "HDMI", "ATAPI", |
| 117 | "Mobile-In", "Mobile-Out" |
| 118 | }; |
| 119 | int i; |
| 120 | cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT; |
| 121 | if ((cfg & 0x0f) < 7) |
| 122 | return bases[cfg & 0x0f]; |
| 123 | for (i = 0; i < ARRAY_SIZE(specials_idx); i++) { |
| 124 | if (cfg == specials_idx[i]) |
| 125 | return specials[i]; |
| 126 | } |
| 127 | return "UNKNOWN"; |
| 128 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 129 | EXPORT_SYMBOL_HDA(snd_hda_get_jack_location); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 130 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 131 | /** |
| 132 | * snd_hda_get_jack_connectivity - Give a connectivity string of the jack |
| 133 | * @cfg: pin default config value |
| 134 | * |
| 135 | * Parse the pin default config value and returns the string of the |
| 136 | * jack connectivity, i.e. external or internal connection. |
| 137 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 138 | const char *snd_hda_get_jack_connectivity(u32 cfg) |
| 139 | { |
| 140 | static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; |
| 141 | |
| 142 | return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3]; |
| 143 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 144 | EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 145 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 146 | /** |
| 147 | * snd_hda_get_jack_type - Give a type string of the jack |
| 148 | * @cfg: pin default config value |
| 149 | * |
| 150 | * Parse the pin default config value and returns the string of the |
| 151 | * jack type, i.e. the purpose of the jack, such as Line-Out or CD. |
| 152 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 153 | const char *snd_hda_get_jack_type(u32 cfg) |
| 154 | { |
| 155 | static char *jack_types[16] = { |
| 156 | "Line Out", "Speaker", "HP Out", "CD", |
| 157 | "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand", |
| 158 | "Line In", "Aux", "Mic", "Telephony", |
| 159 | "SPDIF In", "Digitial In", "Reserved", "Other" |
| 160 | }; |
| 161 | |
| 162 | return jack_types[(cfg & AC_DEFCFG_DEVICE) |
| 163 | >> AC_DEFCFG_DEVICE_SHIFT]; |
| 164 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 165 | EXPORT_SYMBOL_HDA(snd_hda_get_jack_type); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 166 | |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 167 | /* |
| 168 | * Compose a 32bit command word to be sent to the HD-audio controller |
| 169 | */ |
| 170 | static inline unsigned int |
| 171 | make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, |
| 172 | unsigned int verb, unsigned int parm) |
| 173 | { |
| 174 | u32 val; |
| 175 | |
Takashi Iwai | 82e1b80 | 2009-07-17 12:47:34 +0200 | [diff] [blame] | 176 | if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) || |
| 177 | (verb & ~0xfff) || (parm & ~0xffff)) { |
Wu Fengguang | 6430aee | 2009-07-17 16:49:19 +0800 | [diff] [blame] | 178 | printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", |
| 179 | codec->addr, direct, nid, verb, parm); |
| 180 | return ~0; |
| 181 | } |
| 182 | |
| 183 | val = (u32)codec->addr << 28; |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 184 | val |= (u32)direct << 27; |
| 185 | val |= (u32)nid << 20; |
| 186 | val |= verb << 8; |
| 187 | val |= parm; |
| 188 | return val; |
| 189 | } |
| 190 | |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 191 | /* |
| 192 | * Send and receive a verb |
| 193 | */ |
| 194 | static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, |
| 195 | unsigned int *res) |
| 196 | { |
| 197 | struct hda_bus *bus = codec->bus; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 198 | int err; |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 199 | |
Wu Fengguang | 6430aee | 2009-07-17 16:49:19 +0800 | [diff] [blame] | 200 | if (cmd == ~0) |
| 201 | return -1; |
| 202 | |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 203 | if (res) |
| 204 | *res = -1; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 205 | again: |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 206 | snd_hda_power_up(codec); |
| 207 | mutex_lock(&bus->cmd_mutex); |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 208 | err = bus->ops.command(bus, cmd); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 209 | if (!err && res) |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 210 | *res = bus->ops.get_response(bus, codec->addr); |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 211 | mutex_unlock(&bus->cmd_mutex); |
| 212 | snd_hda_power_down(codec); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 213 | if (res && *res == -1 && bus->rirb_error) { |
| 214 | if (bus->response_reset) { |
| 215 | snd_printd("hda_codec: resetting BUS due to " |
| 216 | "fatal communication error\n"); |
| 217 | bus->ops.bus_reset(bus); |
| 218 | } |
| 219 | goto again; |
| 220 | } |
| 221 | /* clear reset-flag when the communication gets recovered */ |
| 222 | if (!err) |
| 223 | bus->response_reset = 0; |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 224 | return err; |
| 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /** |
| 228 | * snd_hda_codec_read - send a command and get the response |
| 229 | * @codec: the HDA codec |
| 230 | * @nid: NID to send the command |
| 231 | * @direct: direct flag |
| 232 | * @verb: the verb to send |
| 233 | * @parm: the parameter for the verb |
| 234 | * |
| 235 | * Send a single command and read the corresponding response. |
| 236 | * |
| 237 | * Returns the obtained response value, or -1 for an error. |
| 238 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 239 | unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, |
| 240 | int direct, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | unsigned int verb, unsigned int parm) |
| 242 | { |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 243 | unsigned cmd = make_codec_cmd(codec, nid, direct, verb, parm); |
| 244 | unsigned int res; |
| 245 | codec_exec_verb(codec, cmd, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return res; |
| 247 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 248 | EXPORT_SYMBOL_HDA(snd_hda_codec_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * snd_hda_codec_write - send a single command without waiting for response |
| 252 | * @codec: the HDA codec |
| 253 | * @nid: NID to send the command |
| 254 | * @direct: direct flag |
| 255 | * @verb: the verb to send |
| 256 | * @parm: the parameter for the verb |
| 257 | * |
| 258 | * Send a single command without waiting for response. |
| 259 | * |
| 260 | * Returns 0 if successful, or a negative error code. |
| 261 | */ |
| 262 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, |
| 263 | unsigned int verb, unsigned int parm) |
| 264 | { |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 265 | unsigned int cmd = make_codec_cmd(codec, nid, direct, verb, parm); |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 266 | unsigned int res; |
Takashi Iwai | b20f3b8 | 2009-06-02 01:20:22 +0200 | [diff] [blame] | 267 | return codec_exec_verb(codec, cmd, |
| 268 | codec->bus->sync_write ? &res : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 270 | EXPORT_SYMBOL_HDA(snd_hda_codec_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * snd_hda_sequence_write - sequence writes |
| 274 | * @codec: the HDA codec |
| 275 | * @seq: VERB array to send |
| 276 | * |
| 277 | * Send the commands sequentially from the given array. |
| 278 | * The array must be terminated with NID=0. |
| 279 | */ |
| 280 | void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) |
| 281 | { |
| 282 | for (; seq->nid; seq++) |
| 283 | snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); |
| 284 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 285 | EXPORT_SYMBOL_HDA(snd_hda_sequence_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * snd_hda_get_sub_nodes - get the range of sub nodes |
| 289 | * @codec: the HDA codec |
| 290 | * @nid: NID to parse |
| 291 | * @start_id: the pointer to store the start NID |
| 292 | * |
| 293 | * Parse the NID and store the start NID of its sub-nodes. |
| 294 | * Returns the number of sub-nodes. |
| 295 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 296 | int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, |
| 297 | hda_nid_t *start_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
| 299 | unsigned int parm; |
| 300 | |
| 301 | parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT); |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 302 | if (parm == -1) |
| 303 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | *start_id = (parm >> 16) & 0x7fff; |
| 305 | return (int)(parm & 0x7fff); |
| 306 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 307 | EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /** |
| 310 | * snd_hda_get_connections - get connection list |
| 311 | * @codec: the HDA codec |
| 312 | * @nid: NID to parse |
| 313 | * @conn_list: connection list array |
| 314 | * @max_conns: max. number of connections to store |
| 315 | * |
| 316 | * Parses the connection list of the given widget and stores the list |
| 317 | * of NIDs. |
| 318 | * |
| 319 | * Returns the number of connections, or a negative error code. |
| 320 | */ |
| 321 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, |
| 322 | hda_nid_t *conn_list, int max_conns) |
| 323 | { |
| 324 | unsigned int parm; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 325 | int i, conn_len, conns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | unsigned int shift, num_elems, mask; |
Takashi Iwai | 1ba7a7c | 2009-07-27 12:56:26 +0200 | [diff] [blame] | 327 | unsigned int wcaps; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 328 | hda_nid_t prev_nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 330 | if (snd_BUG_ON(!conn_list || max_conns <= 0)) |
| 331 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Takashi Iwai | 1ba7a7c | 2009-07-27 12:56:26 +0200 | [diff] [blame] | 333 | wcaps = get_wcaps(codec, nid); |
| 334 | if (!(wcaps & AC_WCAP_CONN_LIST) && |
| 335 | get_wcaps_type(wcaps) != AC_WID_VOL_KNB) { |
Jaroslav Kysela | 16a433d | 2009-07-22 16:20:40 +0200 | [diff] [blame] | 336 | snd_printk(KERN_WARNING "hda_codec: " |
| 337 | "connection list not available for 0x%x\n", nid); |
| 338 | return -EINVAL; |
| 339 | } |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); |
| 342 | if (parm & AC_CLIST_LONG) { |
| 343 | /* long form */ |
| 344 | shift = 16; |
| 345 | num_elems = 2; |
| 346 | } else { |
| 347 | /* short form */ |
| 348 | shift = 8; |
| 349 | num_elems = 4; |
| 350 | } |
| 351 | conn_len = parm & AC_CLIST_LENGTH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | mask = (1 << (shift-1)) - 1; |
| 353 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 354 | if (!conn_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return 0; /* no connection */ |
| 356 | |
| 357 | if (conn_len == 1) { |
| 358 | /* single connection */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 359 | parm = snd_hda_codec_read(codec, nid, 0, |
| 360 | AC_VERB_GET_CONNECT_LIST, 0); |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 361 | if (parm == -1 && codec->bus->rirb_error) |
| 362 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | conn_list[0] = parm & mask; |
| 364 | return 1; |
| 365 | } |
| 366 | |
| 367 | /* multi connection */ |
| 368 | conns = 0; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 369 | prev_nid = 0; |
| 370 | for (i = 0; i < conn_len; i++) { |
| 371 | int range_val; |
| 372 | hda_nid_t val, n; |
| 373 | |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 374 | if (i % num_elems == 0) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 375 | parm = snd_hda_codec_read(codec, nid, 0, |
| 376 | AC_VERB_GET_CONNECT_LIST, i); |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 377 | if (parm == -1 && codec->bus->rirb_error) |
| 378 | return -EIO; |
| 379 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 380 | range_val = !!(parm & (1 << (shift-1))); /* ranges */ |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 381 | val = parm & mask; |
Jaroslav Kysela | 2e9bf24 | 2009-07-18 11:48:19 +0200 | [diff] [blame] | 382 | if (val == 0) { |
| 383 | snd_printk(KERN_WARNING "hda_codec: " |
| 384 | "invalid CONNECT_LIST verb %x[%i]:%x\n", |
| 385 | nid, i, parm); |
| 386 | return 0; |
| 387 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 388 | parm >>= shift; |
| 389 | if (range_val) { |
| 390 | /* ranges between the previous and this one */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 391 | if (!prev_nid || prev_nid >= val) { |
| 392 | snd_printk(KERN_WARNING "hda_codec: " |
| 393 | "invalid dep_range_val %x:%x\n", |
| 394 | prev_nid, val); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 395 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 397 | for (n = prev_nid + 1; n <= val; n++) { |
| 398 | if (conns >= max_conns) { |
Takashi Iwai | 5aacc21 | 2010-07-30 10:36:29 +0200 | [diff] [blame] | 399 | snd_printk(KERN_ERR "hda_codec: " |
| 400 | "Too many connections %d for NID 0x%x\n", |
| 401 | conns, nid); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
| 404 | conn_list[conns++] = n; |
| 405 | } |
| 406 | } else { |
| 407 | if (conns >= max_conns) { |
Takashi Iwai | 5aacc21 | 2010-07-30 10:36:29 +0200 | [diff] [blame] | 408 | snd_printk(KERN_ERR "hda_codec: " |
| 409 | "Too many connections %d for NID 0x%x\n", |
| 410 | conns, nid); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 411 | return -EINVAL; |
| 412 | } |
| 413 | conn_list[conns++] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 415 | prev_nid = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | return conns; |
| 418 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 419 | EXPORT_SYMBOL_HDA(snd_hda_get_connections); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | |
| 422 | /** |
| 423 | * snd_hda_queue_unsol_event - add an unsolicited event to queue |
| 424 | * @bus: the BUS |
| 425 | * @res: unsolicited event (lower 32bit of RIRB entry) |
| 426 | * @res_ex: codec addr and flags (upper 32bit or RIRB entry) |
| 427 | * |
| 428 | * Adds the given event to the queue. The events are processed in |
| 429 | * the workqueue asynchronously. Call this function in the interrupt |
| 430 | * hanlder when RIRB receives an unsolicited event. |
| 431 | * |
| 432 | * Returns 0 if successful, or a negative error code. |
| 433 | */ |
| 434 | int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) |
| 435 | { |
| 436 | struct hda_bus_unsolicited *unsol; |
| 437 | unsigned int wp; |
| 438 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 439 | unsol = bus->unsol; |
| 440 | if (!unsol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 0; |
| 442 | |
| 443 | wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; |
| 444 | unsol->wp = wp; |
| 445 | |
| 446 | wp <<= 1; |
| 447 | unsol->queue[wp] = res; |
| 448 | unsol->queue[wp + 1] = res_ex; |
| 449 | |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 450 | queue_work(bus->workq, &unsol->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 454 | EXPORT_SYMBOL_HDA(snd_hda_queue_unsol_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | /* |
Wu Fengguang | 5c1d1a9 | 2008-10-07 14:17:53 +0800 | [diff] [blame] | 457 | * process queued unsolicited events |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 459 | static void process_unsol_events(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 461 | struct hda_bus_unsolicited *unsol = |
| 462 | container_of(work, struct hda_bus_unsolicited, work); |
| 463 | struct hda_bus *bus = unsol->bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | struct hda_codec *codec; |
| 465 | unsigned int rp, caddr, res; |
| 466 | |
| 467 | while (unsol->rp != unsol->wp) { |
| 468 | rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE; |
| 469 | unsol->rp = rp; |
| 470 | rp <<= 1; |
| 471 | res = unsol->queue[rp]; |
| 472 | caddr = unsol->queue[rp + 1]; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 473 | if (!(caddr & (1 << 4))) /* no unsolicited event? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | continue; |
| 475 | codec = bus->caddr_tbl[caddr & 0x0f]; |
| 476 | if (codec && codec->patch_ops.unsol_event) |
| 477 | codec->patch_ops.unsol_event(codec, res); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * initialize unsolicited queue |
| 483 | */ |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 484 | static int init_unsol_queue(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
| 486 | struct hda_bus_unsolicited *unsol; |
| 487 | |
Takashi Iwai | 9f146bb | 2005-11-17 11:07:49 +0100 | [diff] [blame] | 488 | if (bus->unsol) /* already initialized */ |
| 489 | return 0; |
| 490 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 491 | unsol = kzalloc(sizeof(*unsol), GFP_KERNEL); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 492 | if (!unsol) { |
| 493 | snd_printk(KERN_ERR "hda_codec: " |
| 494 | "can't allocate unsolicited queue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return -ENOMEM; |
| 496 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 497 | INIT_WORK(&unsol->work, process_unsol_events); |
| 498 | unsol->bus = bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | bus->unsol = unsol; |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * destructor |
| 505 | */ |
| 506 | static void snd_hda_codec_free(struct hda_codec *codec); |
| 507 | |
| 508 | static int snd_hda_bus_free(struct hda_bus *bus) |
| 509 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 510 | struct hda_codec *codec, *n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 512 | if (!bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | return 0; |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 514 | if (bus->workq) |
| 515 | flush_workqueue(bus->workq); |
| 516 | if (bus->unsol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | kfree(bus->unsol); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 518 | list_for_each_entry_safe(codec, n, &bus->codec_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | snd_hda_codec_free(codec); |
| 520 | } |
| 521 | if (bus->ops.private_free) |
| 522 | bus->ops.private_free(bus); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 523 | if (bus->workq) |
| 524 | destroy_workqueue(bus->workq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | kfree(bus); |
| 526 | return 0; |
| 527 | } |
| 528 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 529 | static int snd_hda_bus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
| 531 | struct hda_bus *bus = device->device_data; |
Takashi Iwai | b94d3539 | 2008-11-21 09:08:06 +0100 | [diff] [blame] | 532 | bus->shutdown = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return snd_hda_bus_free(bus); |
| 534 | } |
| 535 | |
Takashi Iwai | d7ffba1 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 536 | #ifdef CONFIG_SND_HDA_HWDEP |
| 537 | static int snd_hda_bus_dev_register(struct snd_device *device) |
| 538 | { |
| 539 | struct hda_bus *bus = device->device_data; |
| 540 | struct hda_codec *codec; |
| 541 | list_for_each_entry(codec, &bus->codec_list, list) { |
| 542 | snd_hda_hwdep_add_sysfs(codec); |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 543 | snd_hda_hwdep_add_power_sysfs(codec); |
Takashi Iwai | d7ffba1 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 544 | } |
| 545 | return 0; |
| 546 | } |
| 547 | #else |
| 548 | #define snd_hda_bus_dev_register NULL |
| 549 | #endif |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /** |
| 552 | * snd_hda_bus_new - create a HDA bus |
| 553 | * @card: the card entry |
| 554 | * @temp: the template for hda_bus information |
| 555 | * @busp: the pointer to store the created bus instance |
| 556 | * |
| 557 | * Returns 0 if successful, or a negative error code. |
| 558 | */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 559 | int /*__devinit*/ snd_hda_bus_new(struct snd_card *card, |
Takashi Iwai | 756e2b0 | 2007-04-16 11:27:07 +0200 | [diff] [blame] | 560 | const struct hda_bus_template *temp, |
| 561 | struct hda_bus **busp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
| 563 | struct hda_bus *bus; |
| 564 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 565 | static struct snd_device_ops dev_ops = { |
Takashi Iwai | d7ffba1 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 566 | .dev_register = snd_hda_bus_dev_register, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | .dev_free = snd_hda_bus_dev_free, |
| 568 | }; |
| 569 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 570 | if (snd_BUG_ON(!temp)) |
| 571 | return -EINVAL; |
| 572 | if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response)) |
| 573 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | if (busp) |
| 576 | *busp = NULL; |
| 577 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 578 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if (bus == NULL) { |
| 580 | snd_printk(KERN_ERR "can't allocate struct hda_bus\n"); |
| 581 | return -ENOMEM; |
| 582 | } |
| 583 | |
| 584 | bus->card = card; |
| 585 | bus->private_data = temp->private_data; |
| 586 | bus->pci = temp->pci; |
| 587 | bus->modelname = temp->modelname; |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 588 | bus->power_save = temp->power_save; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | bus->ops = temp->ops; |
| 590 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 591 | mutex_init(&bus->cmd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | INIT_LIST_HEAD(&bus->codec_list); |
| 593 | |
Takashi Iwai | e8c0ee5 | 2009-02-05 07:34:28 +0100 | [diff] [blame] | 594 | snprintf(bus->workq_name, sizeof(bus->workq_name), |
| 595 | "hd-audio%d", card->number); |
| 596 | bus->workq = create_singlethread_workqueue(bus->workq_name); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 597 | if (!bus->workq) { |
Takashi Iwai | e8c0ee5 | 2009-02-05 07:34:28 +0100 | [diff] [blame] | 598 | snd_printk(KERN_ERR "cannot create workqueue %s\n", |
| 599 | bus->workq_name); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 600 | kfree(bus); |
| 601 | return -ENOMEM; |
| 602 | } |
| 603 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 604 | err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); |
| 605 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | snd_hda_bus_free(bus); |
| 607 | return err; |
| 608 | } |
| 609 | if (busp) |
| 610 | *busp = bus; |
| 611 | return 0; |
| 612 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 613 | EXPORT_SYMBOL_HDA(snd_hda_bus_new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 615 | #ifdef CONFIG_SND_HDA_GENERIC |
| 616 | #define is_generic_config(codec) \ |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 617 | (codec->modelname && !strcmp(codec->modelname, "generic")) |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 618 | #else |
| 619 | #define is_generic_config(codec) 0 |
| 620 | #endif |
| 621 | |
Takashi Iwai | 645f10c | 2008-11-28 15:07:37 +0100 | [diff] [blame] | 622 | #ifdef MODULE |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 623 | #define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */ |
| 624 | #else |
Takashi Iwai | 645f10c | 2008-11-28 15:07:37 +0100 | [diff] [blame] | 625 | #define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 626 | #endif |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | /* |
| 629 | * find a matching codec preset |
| 630 | */ |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 631 | static const struct hda_codec_preset * |
Takashi Iwai | 756e2b0 | 2007-04-16 11:27:07 +0200 | [diff] [blame] | 632 | find_codec_preset(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 634 | struct hda_codec_preset_list *tbl; |
| 635 | const struct hda_codec_preset *preset; |
| 636 | int mod_requested = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 638 | if (is_generic_config(codec)) |
Takashi Iwai | d5ad630 | 2007-03-07 15:55:59 +0100 | [diff] [blame] | 639 | return NULL; /* use the generic parser */ |
| 640 | |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 641 | again: |
| 642 | mutex_lock(&preset_mutex); |
| 643 | list_for_each_entry(tbl, &hda_preset_tables, list) { |
| 644 | if (!try_module_get(tbl->owner)) { |
| 645 | snd_printk(KERN_ERR "hda_codec: cannot module_get\n"); |
| 646 | continue; |
| 647 | } |
| 648 | for (preset = tbl->preset; preset->id; preset++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | u32 mask = preset->mask; |
Marc Boucher | ca7cfae | 2008-01-22 15:32:25 +0100 | [diff] [blame] | 650 | if (preset->afg && preset->afg != codec->afg) |
| 651 | continue; |
| 652 | if (preset->mfg && preset->mfg != codec->mfg) |
| 653 | continue; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 654 | if (!mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | mask = ~0; |
Takashi Iwai | 9c7f852 | 2006-06-28 15:08:22 +0200 | [diff] [blame] | 656 | if (preset->id == (codec->vendor_id & mask) && |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 657 | (!preset->rev || |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 658 | preset->rev == codec->revision_id)) { |
| 659 | mutex_unlock(&preset_mutex); |
| 660 | codec->owner = tbl->owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return preset; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 664 | module_put(tbl->owner); |
| 665 | } |
| 666 | mutex_unlock(&preset_mutex); |
| 667 | |
| 668 | if (mod_requested < HDA_MODREQ_MAX_COUNT) { |
| 669 | char name[32]; |
| 670 | if (!mod_requested) |
| 671 | snprintf(name, sizeof(name), "snd-hda-codec-id:%08x", |
| 672 | codec->vendor_id); |
| 673 | else |
| 674 | snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*", |
| 675 | (codec->vendor_id >> 16) & 0xffff); |
| 676 | request_module(name); |
| 677 | mod_requested++; |
| 678 | goto again; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | return NULL; |
| 681 | } |
| 682 | |
| 683 | /* |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 684 | * get_codec_name - store the codec name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | */ |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 686 | static int get_codec_name(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | { |
| 688 | const struct hda_vendor_id *c; |
| 689 | const char *vendor = NULL; |
| 690 | u16 vendor_id = codec->vendor_id >> 16; |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 691 | char tmp[16]; |
| 692 | |
| 693 | if (codec->vendor_name) |
| 694 | goto get_chip_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
| 696 | for (c = hda_vendor_ids; c->id; c++) { |
| 697 | if (c->id == vendor_id) { |
| 698 | vendor = c->name; |
| 699 | break; |
| 700 | } |
| 701 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 702 | if (!vendor) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | sprintf(tmp, "Generic %04x", vendor_id); |
| 704 | vendor = tmp; |
| 705 | } |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 706 | codec->vendor_name = kstrdup(vendor, GFP_KERNEL); |
| 707 | if (!codec->vendor_name) |
| 708 | return -ENOMEM; |
| 709 | |
| 710 | get_chip_name: |
| 711 | if (codec->chip_name) |
| 712 | return 0; |
| 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | if (codec->preset && codec->preset->name) |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 715 | codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL); |
| 716 | else { |
| 717 | sprintf(tmp, "ID %x", codec->vendor_id & 0xffff); |
| 718 | codec->chip_name = kstrdup(tmp, GFP_KERNEL); |
| 719 | } |
| 720 | if (!codec->chip_name) |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 721 | return -ENOMEM; |
| 722 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /* |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 726 | * look for an AFG and MFG nodes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 728 | static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Takashi Iwai | 93e82ae | 2009-04-17 18:04:41 +0200 | [diff] [blame] | 730 | int i, total_nodes, function_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | hda_nid_t nid; |
| 732 | |
| 733 | total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); |
| 734 | for (i = 0; i < total_nodes; i++, nid++) { |
Takashi Iwai | 93e82ae | 2009-04-17 18:04:41 +0200 | [diff] [blame] | 735 | function_id = snd_hda_param_read(codec, nid, |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 736 | AC_PAR_FUNCTION_TYPE); |
Jaroslav Kysela | cd7643b | 2010-07-20 12:11:25 +0200 | [diff] [blame] | 737 | switch (function_id & 0xff) { |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 738 | case AC_GRP_AUDIO_FUNCTION: |
| 739 | codec->afg = nid; |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 740 | codec->afg_function_id = function_id & 0xff; |
| 741 | codec->afg_unsol = (function_id >> 8) & 1; |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 742 | break; |
| 743 | case AC_GRP_MODEM_FUNCTION: |
| 744 | codec->mfg = nid; |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 745 | codec->mfg_function_id = function_id & 0xff; |
| 746 | codec->mfg_unsol = (function_id >> 8) & 1; |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 747 | break; |
| 748 | default: |
| 749 | break; |
| 750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /* |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 755 | * read widget caps for each widget and store in cache |
| 756 | */ |
| 757 | static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) |
| 758 | { |
| 759 | int i; |
| 760 | hda_nid_t nid; |
| 761 | |
| 762 | codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, |
| 763 | &codec->start_nid); |
| 764 | codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 765 | if (!codec->wcaps) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 766 | return -ENOMEM; |
| 767 | nid = codec->start_nid; |
| 768 | for (i = 0; i < codec->num_nodes; i++, nid++) |
| 769 | codec->wcaps[i] = snd_hda_param_read(codec, nid, |
| 770 | AC_PAR_AUDIO_WIDGET_CAP); |
| 771 | return 0; |
| 772 | } |
| 773 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 774 | /* read all pin default configurations and save codec->init_pins */ |
| 775 | static int read_pin_defaults(struct hda_codec *codec) |
| 776 | { |
| 777 | int i; |
| 778 | hda_nid_t nid = codec->start_nid; |
| 779 | |
| 780 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 781 | struct hda_pincfg *pin; |
| 782 | unsigned int wcaps = get_wcaps(codec, nid); |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 783 | unsigned int wid_type = get_wcaps_type(wcaps); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 784 | if (wid_type != AC_WID_PIN) |
| 785 | continue; |
| 786 | pin = snd_array_new(&codec->init_pins); |
| 787 | if (!pin) |
| 788 | return -ENOMEM; |
| 789 | pin->nid = nid; |
| 790 | pin->cfg = snd_hda_codec_read(codec, nid, 0, |
| 791 | AC_VERB_GET_CONFIG_DEFAULT, 0); |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 792 | pin->ctrl = snd_hda_codec_read(codec, nid, 0, |
| 793 | AC_VERB_GET_PIN_WIDGET_CONTROL, |
| 794 | 0); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 795 | } |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /* look up the given pin config list and return the item matching with NID */ |
| 800 | static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, |
| 801 | struct snd_array *array, |
| 802 | hda_nid_t nid) |
| 803 | { |
| 804 | int i; |
| 805 | for (i = 0; i < array->used; i++) { |
| 806 | struct hda_pincfg *pin = snd_array_elem(array, i); |
| 807 | if (pin->nid == nid) |
| 808 | return pin; |
| 809 | } |
| 810 | return NULL; |
| 811 | } |
| 812 | |
| 813 | /* write a config value for the given NID */ |
| 814 | static void set_pincfg(struct hda_codec *codec, hda_nid_t nid, |
| 815 | unsigned int cfg) |
| 816 | { |
| 817 | int i; |
| 818 | for (i = 0; i < 4; i++) { |
| 819 | snd_hda_codec_write(codec, nid, 0, |
| 820 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i, |
| 821 | cfg & 0xff); |
| 822 | cfg >>= 8; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | /* set the current pin config value for the given NID. |
| 827 | * the value is cached, and read via snd_hda_codec_get_pincfg() |
| 828 | */ |
| 829 | int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, |
| 830 | hda_nid_t nid, unsigned int cfg) |
| 831 | { |
| 832 | struct hda_pincfg *pin; |
Takashi Iwai | 5e7b8e0 | 2009-02-23 09:45:59 +0100 | [diff] [blame] | 833 | unsigned int oldcfg; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 834 | |
Takashi Iwai | b82855a | 2009-12-27 11:24:56 +0100 | [diff] [blame] | 835 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 836 | return -EINVAL; |
| 837 | |
Takashi Iwai | 5e7b8e0 | 2009-02-23 09:45:59 +0100 | [diff] [blame] | 838 | oldcfg = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 839 | pin = look_up_pincfg(codec, list, nid); |
| 840 | if (!pin) { |
| 841 | pin = snd_array_new(list); |
| 842 | if (!pin) |
| 843 | return -ENOMEM; |
| 844 | pin->nid = nid; |
| 845 | } |
| 846 | pin->cfg = cfg; |
Takashi Iwai | 5e7b8e0 | 2009-02-23 09:45:59 +0100 | [diff] [blame] | 847 | |
| 848 | /* change only when needed; e.g. if the pincfg is already present |
| 849 | * in user_pins[], don't write it |
| 850 | */ |
| 851 | cfg = snd_hda_codec_get_pincfg(codec, nid); |
| 852 | if (oldcfg != cfg) |
| 853 | set_pincfg(codec, nid, cfg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 854 | return 0; |
| 855 | } |
| 856 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 857 | /** |
| 858 | * snd_hda_codec_set_pincfg - Override a pin default configuration |
| 859 | * @codec: the HDA codec |
| 860 | * @nid: NID to set the pin config |
| 861 | * @cfg: the pin default config value |
| 862 | * |
| 863 | * Override a pin default configuration value in the cache. |
| 864 | * This value can be read by snd_hda_codec_get_pincfg() in a higher |
| 865 | * priority than the real hardware value. |
| 866 | */ |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 867 | int snd_hda_codec_set_pincfg(struct hda_codec *codec, |
| 868 | hda_nid_t nid, unsigned int cfg) |
| 869 | { |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 870 | return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 871 | } |
| 872 | EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); |
| 873 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 874 | /** |
| 875 | * snd_hda_codec_get_pincfg - Obtain a pin-default configuration |
| 876 | * @codec: the HDA codec |
| 877 | * @nid: NID to get the pin config |
| 878 | * |
| 879 | * Get the current pin config value of the given pin NID. |
| 880 | * If the pincfg value is cached or overridden via sysfs or driver, |
| 881 | * returns the cached value. |
| 882 | */ |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 883 | unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) |
| 884 | { |
| 885 | struct hda_pincfg *pin; |
| 886 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 887 | #ifdef CONFIG_SND_HDA_HWDEP |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 888 | pin = look_up_pincfg(codec, &codec->user_pins, nid); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 889 | if (pin) |
| 890 | return pin->cfg; |
| 891 | #endif |
Takashi Iwai | 5e7b8e0 | 2009-02-23 09:45:59 +0100 | [diff] [blame] | 892 | pin = look_up_pincfg(codec, &codec->driver_pins, nid); |
| 893 | if (pin) |
| 894 | return pin->cfg; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 895 | pin = look_up_pincfg(codec, &codec->init_pins, nid); |
| 896 | if (pin) |
| 897 | return pin->cfg; |
| 898 | return 0; |
| 899 | } |
| 900 | EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg); |
| 901 | |
| 902 | /* restore all current pin configs */ |
| 903 | static void restore_pincfgs(struct hda_codec *codec) |
| 904 | { |
| 905 | int i; |
| 906 | for (i = 0; i < codec->init_pins.used; i++) { |
| 907 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 908 | set_pincfg(codec, pin->nid, |
| 909 | snd_hda_codec_get_pincfg(codec, pin->nid)); |
| 910 | } |
| 911 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 912 | |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 913 | /** |
| 914 | * snd_hda_shutup_pins - Shut up all pins |
| 915 | * @codec: the HDA codec |
| 916 | * |
| 917 | * Clear all pin controls to shup up before suspend for avoiding click noise. |
| 918 | * The controls aren't cached so that they can be resumed properly. |
| 919 | */ |
| 920 | void snd_hda_shutup_pins(struct hda_codec *codec) |
| 921 | { |
| 922 | int i; |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 923 | /* don't shut up pins when unloading the driver; otherwise it breaks |
| 924 | * the default pin setup at the next load of the driver |
| 925 | */ |
| 926 | if (codec->bus->shutdown) |
| 927 | return; |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 928 | for (i = 0; i < codec->init_pins.used; i++) { |
| 929 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 930 | /* use read here for syncing after issuing each verb */ |
| 931 | snd_hda_codec_read(codec, pin->nid, 0, |
| 932 | AC_VERB_SET_PIN_WIDGET_CONTROL, 0); |
| 933 | } |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 934 | codec->pins_shutup = 1; |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 935 | } |
| 936 | EXPORT_SYMBOL_HDA(snd_hda_shutup_pins); |
| 937 | |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 938 | /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */ |
| 939 | static void restore_shutup_pins(struct hda_codec *codec) |
| 940 | { |
| 941 | int i; |
| 942 | if (!codec->pins_shutup) |
| 943 | return; |
| 944 | if (codec->bus->shutdown) |
| 945 | return; |
| 946 | for (i = 0; i < codec->init_pins.used; i++) { |
| 947 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 948 | snd_hda_codec_write(codec, pin->nid, 0, |
| 949 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 950 | pin->ctrl); |
| 951 | } |
| 952 | codec->pins_shutup = 0; |
| 953 | } |
| 954 | |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 955 | static void init_hda_cache(struct hda_cache_rec *cache, |
| 956 | unsigned int record_size); |
Takashi Iwai | 1fcaee6 | 2007-08-23 00:01:09 +0200 | [diff] [blame] | 957 | static void free_hda_cache(struct hda_cache_rec *cache); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 958 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 959 | /* restore the initial pin cfgs and release all pincfg lists */ |
| 960 | static void restore_init_pincfgs(struct hda_codec *codec) |
| 961 | { |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 962 | /* first free driver_pins and user_pins, then call restore_pincfg |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 963 | * so that only the values in init_pins are restored |
| 964 | */ |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 965 | snd_array_free(&codec->driver_pins); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 966 | #ifdef CONFIG_SND_HDA_HWDEP |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 967 | snd_array_free(&codec->user_pins); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 968 | #endif |
| 969 | restore_pincfgs(codec); |
| 970 | snd_array_free(&codec->init_pins); |
| 971 | } |
| 972 | |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 973 | /* |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 974 | * audio-converter setup caches |
| 975 | */ |
| 976 | struct hda_cvt_setup { |
| 977 | hda_nid_t nid; |
| 978 | u8 stream_tag; |
| 979 | u8 channel_id; |
| 980 | u16 format_id; |
| 981 | unsigned char active; /* cvt is currently used */ |
| 982 | unsigned char dirty; /* setups should be cleared */ |
| 983 | }; |
| 984 | |
| 985 | /* get or create a cache entry for the given audio converter NID */ |
| 986 | static struct hda_cvt_setup * |
| 987 | get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) |
| 988 | { |
| 989 | struct hda_cvt_setup *p; |
| 990 | int i; |
| 991 | |
| 992 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 993 | p = snd_array_elem(&codec->cvt_setups, i); |
| 994 | if (p->nid == nid) |
| 995 | return p; |
| 996 | } |
| 997 | p = snd_array_new(&codec->cvt_setups); |
| 998 | if (p) |
| 999 | p->nid = nid; |
| 1000 | return p; |
| 1001 | } |
| 1002 | |
| 1003 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | * codec destructor |
| 1005 | */ |
| 1006 | static void snd_hda_codec_free(struct hda_codec *codec) |
| 1007 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1008 | if (!codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1010 | restore_init_pincfgs(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1011 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1012 | cancel_delayed_work(&codec->power_work); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 1013 | flush_workqueue(codec->bus->workq); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1014 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | list_del(&codec->list); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1016 | snd_array_free(&codec->mixers); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1017 | snd_array_free(&codec->nids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | codec->bus->caddr_tbl[codec->addr] = NULL; |
| 1019 | if (codec->patch_ops.free) |
| 1020 | codec->patch_ops.free(codec); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1021 | module_put(codec->owner); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1022 | free_hda_cache(&codec->amp_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1023 | free_hda_cache(&codec->cmd_cache); |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 1024 | kfree(codec->vendor_name); |
| 1025 | kfree(codec->chip_name); |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1026 | kfree(codec->modelname); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1027 | kfree(codec->wcaps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | kfree(codec); |
| 1029 | } |
| 1030 | |
Takashi Iwai | bb6ac72 | 2009-03-13 09:02:42 +0100 | [diff] [blame] | 1031 | static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
| 1032 | unsigned int power_state); |
| 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /** |
| 1035 | * snd_hda_codec_new - create a HDA codec |
| 1036 | * @bus: the bus to assign |
| 1037 | * @codec_addr: the codec address |
| 1038 | * @codecp: the pointer to store the generated codec |
| 1039 | * |
| 1040 | * Returns 0 if successful, or a negative error code. |
| 1041 | */ |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1042 | int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, |
| 1043 | unsigned int codec_addr, |
| 1044 | struct hda_codec **codecp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | { |
| 1046 | struct hda_codec *codec; |
Jaroslav Kysela | ba44368 | 2008-08-13 20:55:32 +0200 | [diff] [blame] | 1047 | char component[31]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | int err; |
| 1049 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1050 | if (snd_BUG_ON(!bus)) |
| 1051 | return -EINVAL; |
| 1052 | if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) |
| 1053 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
| 1055 | if (bus->caddr_tbl[codec_addr]) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1056 | snd_printk(KERN_ERR "hda_codec: " |
| 1057 | "address 0x%x is already occupied\n", codec_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | return -EBUSY; |
| 1059 | } |
| 1060 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1061 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | if (codec == NULL) { |
| 1063 | snd_printk(KERN_ERR "can't allocate struct hda_codec\n"); |
| 1064 | return -ENOMEM; |
| 1065 | } |
| 1066 | |
| 1067 | codec->bus = bus; |
| 1068 | codec->addr = codec_addr; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1069 | mutex_init(&codec->spdif_mutex); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1070 | mutex_init(&codec->control_mutex); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1071 | mutex_init(&codec->prepare_mutex); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1072 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1073 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1074 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); |
| 1075 | snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1076 | snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 1077 | snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1078 | snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1079 | if (codec->bus->modelname) { |
| 1080 | codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); |
| 1081 | if (!codec->modelname) { |
| 1082 | snd_hda_codec_free(codec); |
| 1083 | return -ENODEV; |
| 1084 | } |
| 1085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1087 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1088 | INIT_DELAYED_WORK(&codec->power_work, hda_power_work); |
| 1089 | /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. |
| 1090 | * the caller has to power down appropriatley after initialization |
| 1091 | * phase. |
| 1092 | */ |
| 1093 | hda_keep_power_on(codec); |
| 1094 | #endif |
| 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | list_add_tail(&codec->list, &bus->codec_list); |
| 1097 | bus->caddr_tbl[codec_addr] = codec; |
| 1098 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1099 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1100 | AC_PAR_VENDOR_ID); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 1101 | if (codec->vendor_id == -1) |
| 1102 | /* read again, hopefully the access method was corrected |
| 1103 | * in the last read... |
| 1104 | */ |
| 1105 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1106 | AC_PAR_VENDOR_ID); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1107 | codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1108 | AC_PAR_SUBSYSTEM_ID); |
| 1109 | codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1110 | AC_PAR_REV_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 1112 | setup_fg_nodes(codec); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1113 | if (!codec->afg && !codec->mfg) { |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 1114 | snd_printdd("hda_codec: no AFG or MFG node found\n"); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1115 | err = -ENODEV; |
| 1116 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1119 | err = read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg); |
| 1120 | if (err < 0) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1121 | snd_printk(KERN_ERR "hda_codec: cannot malloc\n"); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1122 | goto error; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1123 | } |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1124 | err = read_pin_defaults(codec); |
| 1125 | if (err < 0) |
| 1126 | goto error; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1127 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1128 | if (!codec->subsystem_id) { |
Takashi Iwai | 86284e4 | 2005-10-11 15:05:54 +0200 | [diff] [blame] | 1129 | hda_nid_t nid = codec->afg ? codec->afg : codec->mfg; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1130 | codec->subsystem_id = |
| 1131 | snd_hda_codec_read(codec, nid, 0, |
| 1132 | AC_VERB_GET_SUBSYSTEM_ID, 0); |
Takashi Iwai | 86284e4 | 2005-10-11 15:05:54 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
Takashi Iwai | bb6ac72 | 2009-03-13 09:02:42 +0100 | [diff] [blame] | 1135 | /* power-up all before initialization */ |
| 1136 | hda_set_power_state(codec, |
| 1137 | codec->afg ? codec->afg : codec->mfg, |
| 1138 | AC_PWRST_D0); |
| 1139 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1140 | snd_hda_codec_proc_new(codec); |
| 1141 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1142 | snd_hda_create_hwdep(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1143 | |
| 1144 | sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, |
| 1145 | codec->subsystem_id, codec->revision_id); |
| 1146 | snd_component_add(codec->bus->card, component); |
| 1147 | |
| 1148 | if (codecp) |
| 1149 | *codecp = codec; |
| 1150 | return 0; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1151 | |
| 1152 | error: |
| 1153 | snd_hda_codec_free(codec); |
| 1154 | return err; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1155 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1156 | EXPORT_SYMBOL_HDA(snd_hda_codec_new); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1157 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1158 | /** |
| 1159 | * snd_hda_codec_configure - (Re-)configure the HD-audio codec |
| 1160 | * @codec: the HDA codec |
| 1161 | * |
| 1162 | * Start parsing of the given codec tree and (re-)initialize the whole |
| 1163 | * patch instance. |
| 1164 | * |
| 1165 | * Returns 0 if successful or a negative error code. |
| 1166 | */ |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1167 | int snd_hda_codec_configure(struct hda_codec *codec) |
| 1168 | { |
| 1169 | int err; |
| 1170 | |
Takashi Iwai | d5ad630 | 2007-03-07 15:55:59 +0100 | [diff] [blame] | 1171 | codec->preset = find_codec_preset(codec); |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 1172 | if (!codec->vendor_name || !codec->chip_name) { |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1173 | err = get_codec_name(codec); |
| 1174 | if (err < 0) |
| 1175 | return err; |
| 1176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 1178 | if (is_generic_config(codec)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | err = snd_hda_parse_generic_codec(codec); |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 1180 | goto patched; |
| 1181 | } |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 1182 | if (codec->preset && codec->preset->patch) { |
| 1183 | err = codec->preset->patch(codec); |
| 1184 | goto patched; |
| 1185 | } |
| 1186 | |
| 1187 | /* call the default parser */ |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 1188 | err = snd_hda_parse_generic_codec(codec); |
Takashi Iwai | 35a1e0c | 2007-10-19 08:13:40 +0200 | [diff] [blame] | 1189 | if (err < 0) |
| 1190 | printk(KERN_ERR "hda-codec: No codec parser is available\n"); |
Takashi Iwai | 8246761 | 2007-07-27 19:15:54 +0200 | [diff] [blame] | 1191 | |
| 1192 | patched: |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1193 | if (!err && codec->patch_ops.unsol_event) |
| 1194 | err = init_unsol_queue(codec->bus); |
Takashi Iwai | f62faed | 2009-12-23 09:27:51 +0100 | [diff] [blame] | 1195 | /* audio codec should override the mixer name */ |
| 1196 | if (!err && (codec->afg || !*codec->bus->card->mixername)) |
| 1197 | snprintf(codec->bus->card->mixername, |
| 1198 | sizeof(codec->bus->card->mixername), |
| 1199 | "%s %s", codec->vendor_name, codec->chip_name); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1200 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1202 | EXPORT_SYMBOL_HDA(snd_hda_codec_configure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | /** |
| 1205 | * snd_hda_codec_setup_stream - set up the codec for streaming |
| 1206 | * @codec: the CODEC to set up |
| 1207 | * @nid: the NID to set up |
| 1208 | * @stream_tag: stream tag to pass, it's between 0x1 and 0xf. |
| 1209 | * @channel_id: channel id to pass, zero based. |
| 1210 | * @format: stream format. |
| 1211 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1212 | void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, |
| 1213 | u32 stream_tag, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | int channel_id, int format) |
| 1215 | { |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1216 | struct hda_cvt_setup *p; |
| 1217 | unsigned int oldval, newval; |
| 1218 | int i; |
| 1219 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1220 | if (!nid) |
Takashi Iwai | d21b37e | 2005-04-20 13:45:55 +0200 | [diff] [blame] | 1221 | return; |
| 1222 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1223 | snd_printdd("hda_codec_setup_stream: " |
| 1224 | "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | nid, stream_tag, channel_id, format); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1226 | p = get_hda_cvt_setup(codec, nid); |
| 1227 | if (!p) |
| 1228 | return; |
| 1229 | /* update the stream-id if changed */ |
| 1230 | if (p->stream_tag != stream_tag || p->channel_id != channel_id) { |
| 1231 | oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); |
| 1232 | newval = (stream_tag << 4) | channel_id; |
| 1233 | if (oldval != newval) |
| 1234 | snd_hda_codec_write(codec, nid, 0, |
| 1235 | AC_VERB_SET_CHANNEL_STREAMID, |
| 1236 | newval); |
| 1237 | p->stream_tag = stream_tag; |
| 1238 | p->channel_id = channel_id; |
| 1239 | } |
| 1240 | /* update the format-id if changed */ |
| 1241 | if (p->format_id != format) { |
| 1242 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 1243 | AC_VERB_GET_STREAM_FORMAT, 0); |
| 1244 | if (oldval != format) { |
| 1245 | msleep(1); |
| 1246 | snd_hda_codec_write(codec, nid, 0, |
| 1247 | AC_VERB_SET_STREAM_FORMAT, |
| 1248 | format); |
| 1249 | } |
| 1250 | p->format_id = format; |
| 1251 | } |
| 1252 | p->active = 1; |
| 1253 | p->dirty = 0; |
| 1254 | |
| 1255 | /* make other inactive cvts with the same stream-tag dirty */ |
| 1256 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 1257 | p = snd_array_elem(&codec->cvt_setups, i); |
| 1258 | if (!p->active && p->stream_tag == stream_tag) |
| 1259 | p->dirty = 1; |
| 1260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1262 | EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1264 | static void really_cleanup_stream(struct hda_codec *codec, |
| 1265 | struct hda_cvt_setup *q); |
| 1266 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1267 | /** |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1268 | * __snd_hda_codec_cleanup_stream - clean up the codec for closing |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1269 | * @codec: the CODEC to clean up |
| 1270 | * @nid: the NID to clean up |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1271 | * @do_now: really clean up the stream instead of clearing the active flag |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1272 | */ |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1273 | void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, |
| 1274 | int do_now) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1275 | { |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1276 | struct hda_cvt_setup *p; |
| 1277 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1278 | if (!nid) |
| 1279 | return; |
| 1280 | |
| 1281 | snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1282 | p = get_hda_cvt_setup(codec, nid); |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1283 | if (p) { |
| 1284 | /* here we just clear the active flag when do_now isn't set; |
| 1285 | * actual clean-ups will be done later in |
| 1286 | * purify_inactive_streams() called from snd_hda_codec_prpapre() |
| 1287 | */ |
| 1288 | if (do_now) |
| 1289 | really_cleanup_stream(codec, p); |
| 1290 | else |
| 1291 | p->active = 0; |
| 1292 | } |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1293 | } |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1294 | EXPORT_SYMBOL_HDA(__snd_hda_codec_cleanup_stream); |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1295 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1296 | static void really_cleanup_stream(struct hda_codec *codec, |
| 1297 | struct hda_cvt_setup *q) |
| 1298 | { |
| 1299 | hda_nid_t nid = q->nid; |
| 1300 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 1301 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); |
| 1302 | memset(q, 0, sizeof(*q)); |
| 1303 | q->nid = nid; |
| 1304 | } |
| 1305 | |
| 1306 | /* clean up the all conflicting obsolete streams */ |
| 1307 | static void purify_inactive_streams(struct hda_codec *codec) |
| 1308 | { |
| 1309 | int i; |
| 1310 | |
| 1311 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 1312 | struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); |
| 1313 | if (p->dirty) |
| 1314 | really_cleanup_stream(codec, p); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /* clean up all streams; called from suspend */ |
| 1319 | static void hda_cleanup_all_streams(struct hda_codec *codec) |
| 1320 | { |
| 1321 | int i; |
| 1322 | |
| 1323 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 1324 | struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); |
| 1325 | if (p->stream_tag) |
| 1326 | really_cleanup_stream(codec, p); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | /* |
| 1331 | * amp access functions |
| 1332 | */ |
| 1333 | |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1334 | /* FIXME: more better hash key? */ |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1335 | #define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1336 | #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1337 | #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) |
| 1338 | #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | #define INFO_AMP_CAPS (1<<0) |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1340 | #define INFO_AMP_VOL(ch) (1 << (1 + (ch))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
| 1342 | /* initialize the hash table */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1343 | static void /*__devinit*/ init_hda_cache(struct hda_cache_rec *cache, |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1344 | unsigned int record_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1346 | memset(cache, 0, sizeof(*cache)); |
| 1347 | memset(cache->hash, 0xff, sizeof(cache->hash)); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1348 | snd_array_init(&cache->buf, record_size, 64); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Takashi Iwai | 1fcaee6 | 2007-08-23 00:01:09 +0200 | [diff] [blame] | 1351 | static void free_hda_cache(struct hda_cache_rec *cache) |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1352 | { |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1353 | snd_array_free(&cache->buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | /* query the hash. allocate an entry if not found. */ |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1357 | static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | { |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1359 | u16 idx = key % (u16)ARRAY_SIZE(cache->hash); |
| 1360 | u16 cur = cache->hash[idx]; |
| 1361 | struct hda_cache_head *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
| 1363 | while (cur != 0xffff) { |
Takashi Iwai | f43aa02 | 2008-11-10 16:24:26 +0100 | [diff] [blame] | 1364 | info = snd_array_elem(&cache->buf, cur); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | if (info->key == key) |
| 1366 | return info; |
| 1367 | cur = info->next; |
| 1368 | } |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1369 | return NULL; |
| 1370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1372 | /* query the hash. allocate an entry if not found. */ |
| 1373 | static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, |
| 1374 | u32 key) |
| 1375 | { |
| 1376 | struct hda_cache_head *info = get_hash(cache, key); |
| 1377 | if (!info) { |
| 1378 | u16 idx, cur; |
| 1379 | /* add a new hash entry */ |
| 1380 | info = snd_array_new(&cache->buf); |
| 1381 | if (!info) |
| 1382 | return NULL; |
| 1383 | cur = snd_array_index(&cache->buf, info); |
| 1384 | info->key = key; |
| 1385 | info->val = 0; |
| 1386 | idx = key % (u16)ARRAY_SIZE(cache->hash); |
| 1387 | info->next = cache->hash[idx]; |
| 1388 | cache->hash[idx] = cur; |
| 1389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | return info; |
| 1391 | } |
| 1392 | |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1393 | /* query and allocate an amp hash entry */ |
| 1394 | static inline struct hda_amp_info * |
| 1395 | get_alloc_amp_hash(struct hda_codec *codec, u32 key) |
| 1396 | { |
| 1397 | return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); |
| 1398 | } |
| 1399 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1400 | /** |
| 1401 | * query_amp_caps - query AMP capabilities |
| 1402 | * @codec: the HD-auio codec |
| 1403 | * @nid: the NID to query |
| 1404 | * @direction: either #HDA_INPUT or #HDA_OUTPUT |
| 1405 | * |
| 1406 | * Query AMP capabilities for the given widget and direction. |
| 1407 | * Returns the obtained capability bits. |
| 1408 | * |
| 1409 | * When cap bits have been already read, this doesn't read again but |
| 1410 | * returns the cached value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | */ |
Matthew Ranostay | 09a9995 | 2008-01-24 11:49:21 +0100 | [diff] [blame] | 1412 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1414 | struct hda_amp_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1416 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0)); |
| 1417 | if (!info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | return 0; |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1419 | if (!(info->head.val & INFO_AMP_CAPS)) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1420 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | nid = codec->afg; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1422 | info->amp_caps = snd_hda_param_read(codec, nid, |
| 1423 | direction == HDA_OUTPUT ? |
| 1424 | AC_PAR_AMP_OUT_CAP : |
| 1425 | AC_PAR_AMP_IN_CAP); |
Takashi Iwai | b75e53f | 2007-05-10 16:56:09 +0200 | [diff] [blame] | 1426 | if (info->amp_caps) |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1427 | info->head.val |= INFO_AMP_CAPS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | } |
| 1429 | return info->amp_caps; |
| 1430 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1431 | EXPORT_SYMBOL_HDA(query_amp_caps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1433 | /** |
| 1434 | * snd_hda_override_amp_caps - Override the AMP capabilities |
| 1435 | * @codec: the CODEC to clean up |
| 1436 | * @nid: the NID to clean up |
| 1437 | * @direction: either #HDA_INPUT or #HDA_OUTPUT |
| 1438 | * @caps: the capability bits to set |
| 1439 | * |
| 1440 | * Override the cached AMP caps bits value by the given one. |
| 1441 | * This function is useful if the driver needs to adjust the AMP ranges, |
| 1442 | * e.g. limit to 0dB, etc. |
| 1443 | * |
| 1444 | * Returns zero if successful or a negative error code. |
| 1445 | */ |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1446 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 1447 | unsigned int caps) |
| 1448 | { |
| 1449 | struct hda_amp_info *info; |
| 1450 | |
| 1451 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0)); |
| 1452 | if (!info) |
| 1453 | return -EINVAL; |
| 1454 | info->amp_caps = caps; |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1455 | info->head.val |= INFO_AMP_CAPS; |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1456 | return 0; |
| 1457 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1458 | EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1459 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1460 | static unsigned int |
| 1461 | query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key, |
| 1462 | unsigned int (*func)(struct hda_codec *, hda_nid_t)) |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1463 | { |
| 1464 | struct hda_amp_info *info; |
| 1465 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1466 | info = get_alloc_amp_hash(codec, key); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1467 | if (!info) |
| 1468 | return 0; |
| 1469 | if (!info->head.val) { |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1470 | info->head.val |= INFO_AMP_CAPS; |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1471 | info->amp_caps = func(codec, nid); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1472 | } |
| 1473 | return info->amp_caps; |
| 1474 | } |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1475 | |
| 1476 | static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid) |
| 1477 | { |
| 1478 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); |
| 1479 | } |
| 1480 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1481 | /** |
| 1482 | * snd_hda_query_pin_caps - Query PIN capabilities |
| 1483 | * @codec: the HD-auio codec |
| 1484 | * @nid: the NID to query |
| 1485 | * |
| 1486 | * Query PIN capabilities for the given widget. |
| 1487 | * Returns the obtained capability bits. |
| 1488 | * |
| 1489 | * When cap bits have been already read, this doesn't read again but |
| 1490 | * returns the cached value. |
| 1491 | */ |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1492 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) |
| 1493 | { |
| 1494 | return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), |
| 1495 | read_pin_cap); |
| 1496 | } |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1497 | EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); |
| 1498 | |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 1499 | /** |
| 1500 | * snd_hda_pin_sense - execute pin sense measurement |
| 1501 | * @codec: the CODEC to sense |
| 1502 | * @nid: the pin NID to sense |
| 1503 | * |
| 1504 | * Execute necessary pin sense measurement and return its Presence Detect, |
| 1505 | * Impedance, ELD Valid etc. status bits. |
| 1506 | */ |
| 1507 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
| 1508 | { |
Takashi Iwai | 729d55b | 2009-12-25 22:49:01 +0100 | [diff] [blame] | 1509 | u32 pincap; |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 1510 | |
Takashi Iwai | 729d55b | 2009-12-25 22:49:01 +0100 | [diff] [blame] | 1511 | if (!codec->no_trigger_sense) { |
| 1512 | pincap = snd_hda_query_pin_caps(codec, nid); |
| 1513 | if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */ |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1514 | snd_hda_codec_read(codec, nid, 0, |
| 1515 | AC_VERB_SET_PIN_SENSE, 0); |
Takashi Iwai | 729d55b | 2009-12-25 22:49:01 +0100 | [diff] [blame] | 1516 | } |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 1517 | return snd_hda_codec_read(codec, nid, 0, |
| 1518 | AC_VERB_GET_PIN_SENSE, 0); |
| 1519 | } |
| 1520 | EXPORT_SYMBOL_HDA(snd_hda_pin_sense); |
| 1521 | |
| 1522 | /** |
| 1523 | * snd_hda_jack_detect - query pin Presence Detect status |
| 1524 | * @codec: the CODEC to sense |
| 1525 | * @nid: the pin NID to sense |
| 1526 | * |
| 1527 | * Query and return the pin's Presence Detect status. |
| 1528 | */ |
| 1529 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) |
| 1530 | { |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1531 | u32 sense = snd_hda_pin_sense(codec, nid); |
| 1532 | return !!(sense & AC_PINSENSE_PRESENCE); |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 1533 | } |
| 1534 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect); |
| 1535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | /* |
| 1537 | * read the current volume to info |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1538 | * if the cache exists, read the cache value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1540 | static unsigned int get_vol_mute(struct hda_codec *codec, |
| 1541 | struct hda_amp_info *info, hda_nid_t nid, |
| 1542 | int ch, int direction, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
| 1544 | u32 val, parm; |
| 1545 | |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1546 | if (info->head.val & INFO_AMP_VOL(ch)) |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1547 | return info->vol[ch]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
| 1549 | parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; |
| 1550 | parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; |
| 1551 | parm |= index; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1552 | val = snd_hda_codec_read(codec, nid, 0, |
| 1553 | AC_VERB_GET_AMP_GAIN_MUTE, parm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | info->vol[ch] = val & 0xff; |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1555 | info->head.val |= INFO_AMP_VOL(ch); |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1556 | return info->vol[ch]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | /* |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1560 | * write the current volume in info to the h/w and update the cache |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | */ |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1562 | static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1563 | hda_nid_t nid, int ch, int direction, int index, |
| 1564 | int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
| 1566 | u32 parm; |
| 1567 | |
| 1568 | parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT; |
| 1569 | parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT; |
| 1570 | parm |= index << AC_AMP_SET_INDEX_SHIFT; |
| 1571 | parm |= val; |
| 1572 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1573 | info->vol[ch] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1576 | /** |
| 1577 | * snd_hda_codec_amp_read - Read AMP value |
| 1578 | * @codec: HD-audio codec |
| 1579 | * @nid: NID to read the AMP value |
| 1580 | * @ch: channel (left=0 or right=1) |
| 1581 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1582 | * @index: the index value (only for input direction) |
| 1583 | * |
| 1584 | * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 1586 | int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1587 | int direction, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1589 | struct hda_amp_info *info; |
| 1590 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); |
| 1591 | if (!info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | return 0; |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1593 | return get_vol_mute(codec, info, nid, ch, direction, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1595 | EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1597 | /** |
| 1598 | * snd_hda_codec_amp_update - update the AMP value |
| 1599 | * @codec: HD-audio codec |
| 1600 | * @nid: NID to read the AMP value |
| 1601 | * @ch: channel (left=0 or right=1) |
| 1602 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1603 | * @idx: the index value (only for input direction) |
| 1604 | * @mask: bit mask to set |
| 1605 | * @val: the bits value to set |
| 1606 | * |
| 1607 | * Update the AMP value with a bit mask. |
| 1608 | * Returns 0 if the value is unchanged, 1 if changed. |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1609 | */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 1610 | int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1611 | int direction, int idx, int mask, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1613 | struct hda_amp_info *info; |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1614 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1615 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx)); |
| 1616 | if (!info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | return 0; |
Takashi Iwai | 46712646 | 2010-03-29 09:19:38 +0200 | [diff] [blame] | 1618 | if (snd_BUG_ON(mask & ~0xff)) |
| 1619 | mask &= 0xff; |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1620 | val &= mask; |
| 1621 | val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 1622 | if (info->vol[ch] == val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | return 0; |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1624 | put_vol_mute(codec, info, nid, ch, direction, idx, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | return 1; |
| 1626 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1627 | EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1629 | /** |
| 1630 | * snd_hda_codec_amp_stereo - update the AMP stereo values |
| 1631 | * @codec: HD-audio codec |
| 1632 | * @nid: NID to read the AMP value |
| 1633 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1634 | * @idx: the index value (only for input direction) |
| 1635 | * @mask: bit mask to set |
| 1636 | * @val: the bits value to set |
| 1637 | * |
| 1638 | * Update the AMP values like snd_hda_codec_amp_update(), but for a |
| 1639 | * stereo widget with the same mask and value. |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1640 | */ |
| 1641 | int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, |
| 1642 | int direction, int idx, int mask, int val) |
| 1643 | { |
| 1644 | int ch, ret = 0; |
Takashi Iwai | 46712646 | 2010-03-29 09:19:38 +0200 | [diff] [blame] | 1645 | |
| 1646 | if (snd_BUG_ON(mask & ~0xff)) |
| 1647 | mask &= 0xff; |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1648 | for (ch = 0; ch < 2; ch++) |
| 1649 | ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, |
| 1650 | idx, mask, val); |
| 1651 | return ret; |
| 1652 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1653 | EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1654 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1655 | #ifdef SND_HDA_NEEDS_RESUME |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1656 | /** |
| 1657 | * snd_hda_codec_resume_amp - Resume all AMP commands from the cache |
| 1658 | * @codec: HD-audio codec |
| 1659 | * |
| 1660 | * Resume the all amp commands from the cache. |
| 1661 | */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1662 | void snd_hda_codec_resume_amp(struct hda_codec *codec) |
| 1663 | { |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1664 | struct hda_amp_info *buffer = codec->amp_cache.buf.list; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1665 | int i; |
| 1666 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1667 | for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) { |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1668 | u32 key = buffer->head.key; |
| 1669 | hda_nid_t nid; |
| 1670 | unsigned int idx, dir, ch; |
| 1671 | if (!key) |
| 1672 | continue; |
| 1673 | nid = key & 0xff; |
| 1674 | idx = (key >> 16) & 0xff; |
| 1675 | dir = (key >> 24) & 0xff; |
| 1676 | for (ch = 0; ch < 2; ch++) { |
| 1677 | if (!(buffer->head.val & INFO_AMP_VOL(ch))) |
| 1678 | continue; |
| 1679 | put_vol_mute(codec, buffer, nid, ch, dir, idx, |
| 1680 | buffer->vol[ch]); |
| 1681 | } |
| 1682 | } |
| 1683 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1684 | EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1685 | #endif /* SND_HDA_NEEDS_RESUME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 1687 | static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 1688 | unsigned int ofs) |
| 1689 | { |
| 1690 | u32 caps = query_amp_caps(codec, nid, dir); |
| 1691 | /* get num steps */ |
| 1692 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 1693 | if (ofs < caps) |
| 1694 | caps -= ofs; |
| 1695 | return caps; |
| 1696 | } |
| 1697 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1698 | /** |
| 1699 | * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer |
| 1700 | * |
| 1701 | * The control element is supposed to have the private_value field |
| 1702 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 1703 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1704 | int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, |
| 1705 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
| 1707 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1708 | u16 nid = get_amp_nid(kcontrol); |
| 1709 | u8 chs = get_amp_channels(kcontrol); |
| 1710 | int dir = get_amp_direction(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1711 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 1713 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1714 | uinfo->count = chs == 3 ? 2 : 1; |
| 1715 | uinfo->value.integer.min = 0; |
| 1716 | uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); |
| 1717 | if (!uinfo->value.integer.max) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1718 | printk(KERN_WARNING "hda_codec: " |
Takashi Iwai | 9c8f2ab | 2008-01-11 16:12:23 +0100 | [diff] [blame] | 1719 | "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid, |
| 1720 | kcontrol->id.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | return -EINVAL; |
| 1722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | return 0; |
| 1724 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1725 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1727 | |
| 1728 | static inline unsigned int |
| 1729 | read_amp_value(struct hda_codec *codec, hda_nid_t nid, |
| 1730 | int ch, int dir, int idx, unsigned int ofs) |
| 1731 | { |
| 1732 | unsigned int val; |
| 1733 | val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); |
| 1734 | val &= HDA_AMP_VOLMASK; |
| 1735 | if (val >= ofs) |
| 1736 | val -= ofs; |
| 1737 | else |
| 1738 | val = 0; |
| 1739 | return val; |
| 1740 | } |
| 1741 | |
| 1742 | static inline int |
| 1743 | update_amp_value(struct hda_codec *codec, hda_nid_t nid, |
| 1744 | int ch, int dir, int idx, unsigned int ofs, |
| 1745 | unsigned int val) |
| 1746 | { |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 1747 | unsigned int maxval; |
| 1748 | |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1749 | if (val > 0) |
| 1750 | val += ofs; |
Takashi Iwai | 7ccc3ef | 2010-07-26 17:00:15 +0200 | [diff] [blame] | 1751 | /* ofs = 0: raw max value */ |
| 1752 | maxval = get_amp_max_value(codec, nid, dir, 0); |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 1753 | if (val > maxval) |
| 1754 | val = maxval; |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1755 | return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, |
| 1756 | HDA_AMP_VOLMASK, val); |
| 1757 | } |
| 1758 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1759 | /** |
| 1760 | * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume |
| 1761 | * |
| 1762 | * The control element is supposed to have the private_value field |
| 1763 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 1764 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1765 | int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, |
| 1766 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | { |
| 1768 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1769 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 1770 | int chs = get_amp_channels(kcontrol); |
| 1771 | int dir = get_amp_direction(kcontrol); |
| 1772 | int idx = get_amp_index(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1773 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | long *valp = ucontrol->value.integer.value; |
| 1775 | |
| 1776 | if (chs & 1) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1777 | *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | if (chs & 2) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1779 | *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | return 0; |
| 1781 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1782 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1784 | /** |
| 1785 | * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume |
| 1786 | * |
| 1787 | * The control element is supposed to have the private_value field |
| 1788 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 1789 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1790 | int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, |
| 1791 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | { |
| 1793 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1794 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 1795 | int chs = get_amp_channels(kcontrol); |
| 1796 | int dir = get_amp_direction(kcontrol); |
| 1797 | int idx = get_amp_index(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1798 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | long *valp = ucontrol->value.integer.value; |
| 1800 | int change = 0; |
| 1801 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1802 | snd_hda_power_up(codec); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 1803 | if (chs & 1) { |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1804 | change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 1805 | valp++; |
| 1806 | } |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1807 | if (chs & 2) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1808 | change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1809 | snd_hda_power_down(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | return change; |
| 1811 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1812 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1814 | /** |
| 1815 | * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume |
| 1816 | * |
| 1817 | * The control element is supposed to have the private_value field |
| 1818 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 1819 | */ |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1820 | int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1821 | unsigned int size, unsigned int __user *_tlv) |
| 1822 | { |
| 1823 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1824 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 1825 | int dir = get_amp_direction(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1826 | unsigned int ofs = get_amp_offset(kcontrol); |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1827 | u32 caps, val1, val2; |
| 1828 | |
| 1829 | if (size < 4 * sizeof(unsigned int)) |
| 1830 | return -ENOMEM; |
| 1831 | caps = query_amp_caps(codec, nid, dir); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1832 | val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT; |
| 1833 | val2 = (val2 + 1) * 25; |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1834 | val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 1835 | val1 += ofs; |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1836 | val1 = ((int)val1) * ((int)val2); |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1837 | if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv)) |
| 1838 | return -EFAULT; |
| 1839 | if (put_user(2 * sizeof(unsigned int), _tlv + 1)) |
| 1840 | return -EFAULT; |
| 1841 | if (put_user(val1, _tlv + 2)) |
| 1842 | return -EFAULT; |
| 1843 | if (put_user(val2, _tlv + 3)) |
| 1844 | return -EFAULT; |
| 1845 | return 0; |
| 1846 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1847 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 1848 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1849 | /** |
| 1850 | * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control |
| 1851 | * @codec: HD-audio codec |
| 1852 | * @nid: NID of a reference widget |
| 1853 | * @dir: #HDA_INPUT or #HDA_OUTPUT |
| 1854 | * @tlv: TLV data to be stored, at least 4 elements |
| 1855 | * |
| 1856 | * Set (static) TLV data for a virtual master volume using the AMP caps |
| 1857 | * obtained from the reference NID. |
| 1858 | * The volume range is recalculated as if the max volume is 0dB. |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1859 | */ |
| 1860 | void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 1861 | unsigned int *tlv) |
| 1862 | { |
| 1863 | u32 caps; |
| 1864 | int nums, step; |
| 1865 | |
| 1866 | caps = query_amp_caps(codec, nid, dir); |
| 1867 | nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 1868 | step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT; |
| 1869 | step = (step + 1) * 25; |
| 1870 | tlv[0] = SNDRV_CTL_TLVT_DB_SCALE; |
| 1871 | tlv[1] = 2 * sizeof(unsigned int); |
| 1872 | tlv[2] = -nums * step; |
| 1873 | tlv[3] = step; |
| 1874 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1875 | EXPORT_SYMBOL_HDA(snd_hda_set_vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1876 | |
| 1877 | /* find a mixer control element with the given name */ |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 1878 | static struct snd_kcontrol * |
| 1879 | _snd_hda_find_mixer_ctl(struct hda_codec *codec, |
| 1880 | const char *name, int idx) |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1881 | { |
| 1882 | struct snd_ctl_elem_id id; |
| 1883 | memset(&id, 0, sizeof(id)); |
| 1884 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 1885 | id.index = idx; |
Takashi Iwai | 18cb710 | 2009-04-16 10:22:24 +0200 | [diff] [blame] | 1886 | if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) |
| 1887 | return NULL; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 1888 | strcpy(id.name, name); |
| 1889 | return snd_ctl_find_id(codec->bus->card, &id); |
| 1890 | } |
| 1891 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1892 | /** |
| 1893 | * snd_hda_find_mixer_ctl - Find a mixer control element with the given name |
| 1894 | * @codec: HD-audio codec |
| 1895 | * @name: ctl id name string |
| 1896 | * |
| 1897 | * Get the control element with the given id string and IFACE_MIXER. |
| 1898 | */ |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 1899 | struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, |
| 1900 | const char *name) |
| 1901 | { |
| 1902 | return _snd_hda_find_mixer_ctl(codec, name, 0); |
| 1903 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1904 | EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 1905 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1906 | /** |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1907 | * snd_hda_ctl_add - Add a control element and assign to the codec |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1908 | * @codec: HD-audio codec |
| 1909 | * @nid: corresponding NID (optional) |
| 1910 | * @kctl: the control element to assign |
| 1911 | * |
| 1912 | * Add the given control element to an array inside the codec instance. |
| 1913 | * All control elements belonging to a codec are supposed to be added |
| 1914 | * by this function so that a proper clean-up works at the free or |
| 1915 | * reconfiguration time. |
| 1916 | * |
| 1917 | * If non-zero @nid is passed, the NID is assigned to the control element. |
| 1918 | * The assignment is shown in the codec proc file. |
| 1919 | * |
| 1920 | * snd_hda_ctl_add() checks the control subdev id field whether |
| 1921 | * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 1922 | * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit |
| 1923 | * specifies if kctl->private_value is a HDA amplifier value. |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1924 | */ |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1925 | int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, |
| 1926 | struct snd_kcontrol *kctl) |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1927 | { |
| 1928 | int err; |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 1929 | unsigned short flags = 0; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1930 | struct hda_nid_item *item; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1931 | |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1932 | if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) { |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 1933 | flags |= HDA_NID_ITEM_AMP; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1934 | if (nid == 0) |
| 1935 | nid = get_amp_nid_(kctl->private_value); |
| 1936 | } |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 1937 | if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0) |
| 1938 | nid = kctl->id.subdevice & 0xffff; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 1939 | if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 1940 | kctl->id.subdevice = 0; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1941 | err = snd_ctl_add(codec->bus->card, kctl); |
| 1942 | if (err < 0) |
| 1943 | return err; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1944 | item = snd_array_new(&codec->mixers); |
| 1945 | if (!item) |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1946 | return -ENOMEM; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1947 | item->kctl = kctl; |
| 1948 | item->nid = nid; |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 1949 | item->flags = flags; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1950 | return 0; |
| 1951 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 1952 | EXPORT_SYMBOL_HDA(snd_hda_ctl_add); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1953 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1954 | /** |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1955 | * snd_hda_add_nid - Assign a NID to a control element |
| 1956 | * @codec: HD-audio codec |
| 1957 | * @nid: corresponding NID (optional) |
| 1958 | * @kctl: the control element to assign |
| 1959 | * @index: index to kctl |
| 1960 | * |
| 1961 | * Add the given control element to an array inside the codec instance. |
| 1962 | * This function is used when #snd_hda_ctl_add cannot be used for 1:1 |
| 1963 | * NID:KCTL mapping - for example "Capture Source" selector. |
| 1964 | */ |
| 1965 | int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, |
| 1966 | unsigned int index, hda_nid_t nid) |
| 1967 | { |
| 1968 | struct hda_nid_item *item; |
| 1969 | |
| 1970 | if (nid > 0) { |
| 1971 | item = snd_array_new(&codec->nids); |
| 1972 | if (!item) |
| 1973 | return -ENOMEM; |
| 1974 | item->kctl = kctl; |
| 1975 | item->index = index; |
| 1976 | item->nid = nid; |
| 1977 | return 0; |
| 1978 | } |
Takashi Iwai | 28d1a85 | 2010-03-15 09:05:46 +0100 | [diff] [blame] | 1979 | printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n", |
| 1980 | kctl->id.name, kctl->id.index, index); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1981 | return -EINVAL; |
| 1982 | } |
| 1983 | EXPORT_SYMBOL_HDA(snd_hda_add_nid); |
| 1984 | |
| 1985 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1986 | * snd_hda_ctls_clear - Clear all controls assigned to the given codec |
| 1987 | * @codec: HD-audio codec |
| 1988 | */ |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1989 | void snd_hda_ctls_clear(struct hda_codec *codec) |
| 1990 | { |
| 1991 | int i; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1992 | struct hda_nid_item *items = codec->mixers.list; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1993 | for (i = 0; i < codec->mixers.used; i++) |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 1994 | snd_ctl_remove(codec->bus->card, items[i].kctl); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1995 | snd_array_free(&codec->mixers); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1996 | snd_array_free(&codec->nids); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1997 | } |
| 1998 | |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 1999 | /* pseudo device locking |
| 2000 | * toggle card->shutdown to allow/disallow the device access (as a hack) |
| 2001 | */ |
| 2002 | static int hda_lock_devices(struct snd_card *card) |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2003 | { |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2004 | spin_lock(&card->files_lock); |
| 2005 | if (card->shutdown) { |
| 2006 | spin_unlock(&card->files_lock); |
| 2007 | return -EINVAL; |
| 2008 | } |
| 2009 | card->shutdown = 1; |
| 2010 | spin_unlock(&card->files_lock); |
| 2011 | return 0; |
| 2012 | } |
| 2013 | |
| 2014 | static void hda_unlock_devices(struct snd_card *card) |
| 2015 | { |
| 2016 | spin_lock(&card->files_lock); |
| 2017 | card->shutdown = 0; |
| 2018 | spin_unlock(&card->files_lock); |
| 2019 | } |
| 2020 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2021 | /** |
| 2022 | * snd_hda_codec_reset - Clear all objects assigned to the codec |
| 2023 | * @codec: HD-audio codec |
| 2024 | * |
| 2025 | * This frees the all PCM and control elements assigned to the codec, and |
| 2026 | * clears the caches and restores the pin default configurations. |
| 2027 | * |
| 2028 | * When a device is being used, it returns -EBSY. If successfully freed, |
| 2029 | * returns zero. |
| 2030 | */ |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2031 | int snd_hda_codec_reset(struct hda_codec *codec) |
| 2032 | { |
| 2033 | struct snd_card *card = codec->bus->card; |
| 2034 | int i, pcm; |
| 2035 | |
| 2036 | if (hda_lock_devices(card) < 0) |
| 2037 | return -EBUSY; |
| 2038 | /* check whether the codec isn't used by any mixer or PCM streams */ |
| 2039 | if (!list_empty(&card->ctl_files)) { |
| 2040 | hda_unlock_devices(card); |
| 2041 | return -EBUSY; |
| 2042 | } |
| 2043 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { |
| 2044 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; |
| 2045 | if (!cpcm->pcm) |
| 2046 | continue; |
| 2047 | if (cpcm->pcm->streams[0].substream_opened || |
| 2048 | cpcm->pcm->streams[1].substream_opened) { |
| 2049 | hda_unlock_devices(card); |
| 2050 | return -EBUSY; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /* OK, let it free */ |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2055 | |
| 2056 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2057 | cancel_delayed_work(&codec->power_work); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 2058 | flush_workqueue(codec->bus->workq); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2059 | #endif |
| 2060 | snd_hda_ctls_clear(codec); |
| 2061 | /* relase PCMs */ |
| 2062 | for (i = 0; i < codec->num_pcms; i++) { |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 2063 | if (codec->pcm_info[i].pcm) { |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2064 | snd_device_free(card, codec->pcm_info[i].pcm); |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 2065 | clear_bit(codec->pcm_info[i].device, |
| 2066 | codec->bus->pcm_dev_bits); |
| 2067 | } |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2068 | } |
| 2069 | if (codec->patch_ops.free) |
| 2070 | codec->patch_ops.free(codec); |
Takashi Iwai | 56d1771 | 2008-11-28 14:36:23 +0100 | [diff] [blame] | 2071 | codec->proc_widget_hook = NULL; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2072 | codec->spec = NULL; |
| 2073 | free_hda_cache(&codec->amp_cache); |
| 2074 | free_hda_cache(&codec->cmd_cache); |
Takashi Iwai | 827057f | 2008-12-19 10:12:02 +0100 | [diff] [blame] | 2075 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); |
| 2076 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 2077 | /* free only driver_pins so that init_pins + user_pins are restored */ |
| 2078 | snd_array_free(&codec->driver_pins); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 2079 | restore_pincfgs(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2080 | codec->num_pcms = 0; |
| 2081 | codec->pcm_info = NULL; |
| 2082 | codec->preset = NULL; |
Takashi Iwai | d1f1af2 | 2009-03-02 10:35:29 +0100 | [diff] [blame] | 2083 | memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); |
| 2084 | codec->slave_dig_outs = NULL; |
| 2085 | codec->spdif_status_reset = 0; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 2086 | module_put(codec->owner); |
| 2087 | codec->owner = NULL; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2088 | |
| 2089 | /* allow device access again */ |
| 2090 | hda_unlock_devices(card); |
| 2091 | return 0; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2092 | } |
| 2093 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2094 | /** |
| 2095 | * snd_hda_add_vmaster - create a virtual master control and add slaves |
| 2096 | * @codec: HD-audio codec |
| 2097 | * @name: vmaster control name |
| 2098 | * @tlv: TLV data (optional) |
| 2099 | * @slaves: slave control names (optional) |
| 2100 | * |
| 2101 | * Create a virtual master control with the given name. The TLV data |
| 2102 | * must be either NULL or a valid data. |
| 2103 | * |
| 2104 | * @slaves is a NULL-terminated array of strings, each of which is a |
| 2105 | * slave control name. All controls with these names are assigned to |
| 2106 | * the new virtual master control. |
| 2107 | * |
| 2108 | * This function returns zero if successful or a negative error code. |
| 2109 | */ |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2110 | int snd_hda_add_vmaster(struct hda_codec *codec, char *name, |
| 2111 | unsigned int *tlv, const char **slaves) |
| 2112 | { |
| 2113 | struct snd_kcontrol *kctl; |
| 2114 | const char **s; |
| 2115 | int err; |
| 2116 | |
Takashi Iwai | 2f08554 | 2008-02-22 18:43:50 +0100 | [diff] [blame] | 2117 | for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++) |
| 2118 | ; |
| 2119 | if (!*s) { |
| 2120 | snd_printdd("No slave found for %s\n", name); |
| 2121 | return 0; |
| 2122 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2123 | kctl = snd_ctl_make_virtual_master(name, tlv); |
| 2124 | if (!kctl) |
| 2125 | return -ENOMEM; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2126 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2127 | if (err < 0) |
| 2128 | return err; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2129 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2130 | for (s = slaves; *s; s++) { |
| 2131 | struct snd_kcontrol *sctl; |
Takashi Iwai | 7a411ee | 2009-03-06 10:08:14 +0100 | [diff] [blame] | 2132 | int i = 0; |
| 2133 | for (;;) { |
| 2134 | sctl = _snd_hda_find_mixer_ctl(codec, *s, i); |
| 2135 | if (!sctl) { |
| 2136 | if (!i) |
| 2137 | snd_printdd("Cannot find slave %s, " |
| 2138 | "skipped\n", *s); |
| 2139 | break; |
| 2140 | } |
| 2141 | err = snd_ctl_add_slave(kctl, sctl); |
| 2142 | if (err < 0) |
| 2143 | return err; |
| 2144 | i++; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2145 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2146 | } |
| 2147 | return 0; |
| 2148 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2149 | EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2150 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2151 | /** |
| 2152 | * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch |
| 2153 | * |
| 2154 | * The control element is supposed to have the private_value field |
| 2155 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2156 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2157 | int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, |
| 2158 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | { |
| 2160 | int chs = get_amp_channels(kcontrol); |
| 2161 | |
| 2162 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2163 | uinfo->count = chs == 3 ? 2 : 1; |
| 2164 | uinfo->value.integer.min = 0; |
| 2165 | uinfo->value.integer.max = 1; |
| 2166 | return 0; |
| 2167 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2168 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2170 | /** |
| 2171 | * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch |
| 2172 | * |
| 2173 | * The control element is supposed to have the private_value field |
| 2174 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2175 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2176 | int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, |
| 2177 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | { |
| 2179 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2180 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2181 | int chs = get_amp_channels(kcontrol); |
| 2182 | int dir = get_amp_direction(kcontrol); |
| 2183 | int idx = get_amp_index(kcontrol); |
| 2184 | long *valp = ucontrol->value.integer.value; |
| 2185 | |
| 2186 | if (chs & 1) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2187 | *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2188 | HDA_AMP_MUTE) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | if (chs & 2) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2190 | *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2191 | HDA_AMP_MUTE) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | return 0; |
| 2193 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2194 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2196 | /** |
| 2197 | * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch |
| 2198 | * |
| 2199 | * The control element is supposed to have the private_value field |
| 2200 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2201 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2202 | int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, |
| 2203 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | { |
| 2205 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2206 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2207 | int chs = get_amp_channels(kcontrol); |
| 2208 | int dir = get_amp_direction(kcontrol); |
| 2209 | int idx = get_amp_index(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | long *valp = ucontrol->value.integer.value; |
| 2211 | int change = 0; |
| 2212 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2213 | snd_hda_power_up(codec); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2214 | if (chs & 1) { |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 2215 | change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2216 | HDA_AMP_MUTE, |
| 2217 | *valp ? 0 : HDA_AMP_MUTE); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2218 | valp++; |
| 2219 | } |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 2220 | if (chs & 2) |
| 2221 | change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2222 | HDA_AMP_MUTE, |
| 2223 | *valp ? 0 : HDA_AMP_MUTE); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2224 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2225 | if (codec->patch_ops.check_power_status) |
| 2226 | codec->patch_ops.check_power_status(codec, nid); |
| 2227 | #endif |
| 2228 | snd_hda_power_down(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | return change; |
| 2230 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2231 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 2233 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2234 | /** |
| 2235 | * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch |
| 2236 | * |
| 2237 | * This function calls snd_hda_enable_beep_device(), which behaves differently |
| 2238 | * depending on beep_mode option. |
| 2239 | */ |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 2240 | int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol, |
| 2241 | struct snd_ctl_elem_value *ucontrol) |
| 2242 | { |
| 2243 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2244 | long *valp = ucontrol->value.integer.value; |
| 2245 | |
| 2246 | snd_hda_enable_beep_device(codec, *valp); |
| 2247 | return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 2248 | } |
| 2249 | EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep); |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 2250 | #endif /* CONFIG_SND_HDA_INPUT_BEEP */ |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 2251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | /* |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2253 | * bound volume controls |
| 2254 | * |
| 2255 | * bind multiple volumes (# indices, from 0) |
| 2256 | */ |
| 2257 | |
| 2258 | #define AMP_VAL_IDX_SHIFT 19 |
| 2259 | #define AMP_VAL_IDX_MASK (0x0f<<19) |
| 2260 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2261 | /** |
| 2262 | * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control |
| 2263 | * |
| 2264 | * The control element is supposed to have the private_value field |
| 2265 | * set up via HDA_BIND_MUTE*() macros. |
| 2266 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2267 | int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, |
| 2268 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2269 | { |
| 2270 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2271 | unsigned long pval; |
| 2272 | int err; |
| 2273 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2274 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2275 | pval = kcontrol->private_value; |
| 2276 | kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */ |
| 2277 | err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); |
| 2278 | kcontrol->private_value = pval; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2279 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2280 | return err; |
| 2281 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2282 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2283 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2284 | /** |
| 2285 | * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control |
| 2286 | * |
| 2287 | * The control element is supposed to have the private_value field |
| 2288 | * set up via HDA_BIND_MUTE*() macros. |
| 2289 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2290 | int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, |
| 2291 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2292 | { |
| 2293 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2294 | unsigned long pval; |
| 2295 | int i, indices, err = 0, change = 0; |
| 2296 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2297 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2298 | pval = kcontrol->private_value; |
| 2299 | indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT; |
| 2300 | for (i = 0; i < indices; i++) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2301 | kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | |
| 2302 | (i << AMP_VAL_IDX_SHIFT); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2303 | err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 2304 | if (err < 0) |
| 2305 | break; |
| 2306 | change |= err; |
| 2307 | } |
| 2308 | kcontrol->private_value = pval; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2309 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2310 | return err < 0 ? err : change; |
| 2311 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2312 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2313 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2314 | /** |
| 2315 | * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control |
| 2316 | * |
| 2317 | * The control element is supposed to have the private_value field |
| 2318 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2319 | */ |
| 2320 | int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, |
| 2321 | struct snd_ctl_elem_info *uinfo) |
| 2322 | { |
| 2323 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2324 | struct hda_bind_ctls *c; |
| 2325 | int err; |
| 2326 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2327 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2328 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2329 | kcontrol->private_value = *c->values; |
| 2330 | err = c->ops->info(kcontrol, uinfo); |
| 2331 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2332 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2333 | return err; |
| 2334 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2335 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2336 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2337 | /** |
| 2338 | * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control |
| 2339 | * |
| 2340 | * The control element is supposed to have the private_value field |
| 2341 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
| 2342 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2343 | int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, |
| 2344 | struct snd_ctl_elem_value *ucontrol) |
| 2345 | { |
| 2346 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2347 | struct hda_bind_ctls *c; |
| 2348 | int err; |
| 2349 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2350 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2351 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2352 | kcontrol->private_value = *c->values; |
| 2353 | err = c->ops->get(kcontrol, ucontrol); |
| 2354 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2355 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2356 | return err; |
| 2357 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2358 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2359 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2360 | /** |
| 2361 | * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control |
| 2362 | * |
| 2363 | * The control element is supposed to have the private_value field |
| 2364 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
| 2365 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2366 | int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, |
| 2367 | struct snd_ctl_elem_value *ucontrol) |
| 2368 | { |
| 2369 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2370 | struct hda_bind_ctls *c; |
| 2371 | unsigned long *vals; |
| 2372 | int err = 0, change = 0; |
| 2373 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2374 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2375 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2376 | for (vals = c->values; *vals; vals++) { |
| 2377 | kcontrol->private_value = *vals; |
| 2378 | err = c->ops->put(kcontrol, ucontrol); |
| 2379 | if (err < 0) |
| 2380 | break; |
| 2381 | change |= err; |
| 2382 | } |
| 2383 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2384 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2385 | return err < 0 ? err : change; |
| 2386 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2387 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2388 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2389 | /** |
| 2390 | * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control |
| 2391 | * |
| 2392 | * The control element is supposed to have the private_value field |
| 2393 | * set up via HDA_BIND_VOL() macro. |
| 2394 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2395 | int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 2396 | unsigned int size, unsigned int __user *tlv) |
| 2397 | { |
| 2398 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2399 | struct hda_bind_ctls *c; |
| 2400 | int err; |
| 2401 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2402 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2403 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2404 | kcontrol->private_value = *c->values; |
| 2405 | err = c->ops->tlv(kcontrol, op_flag, size, tlv); |
| 2406 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2407 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2408 | return err; |
| 2409 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2410 | EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_tlv); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2411 | |
| 2412 | struct hda_ctl_ops snd_hda_bind_vol = { |
| 2413 | .info = snd_hda_mixer_amp_volume_info, |
| 2414 | .get = snd_hda_mixer_amp_volume_get, |
| 2415 | .put = snd_hda_mixer_amp_volume_put, |
| 2416 | .tlv = snd_hda_mixer_amp_tlv |
| 2417 | }; |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2418 | EXPORT_SYMBOL_HDA(snd_hda_bind_vol); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2419 | |
| 2420 | struct hda_ctl_ops snd_hda_bind_sw = { |
| 2421 | .info = snd_hda_mixer_amp_switch_info, |
| 2422 | .get = snd_hda_mixer_amp_switch_get, |
| 2423 | .put = snd_hda_mixer_amp_switch_put, |
| 2424 | .tlv = snd_hda_mixer_amp_tlv |
| 2425 | }; |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2426 | EXPORT_SYMBOL_HDA(snd_hda_bind_sw); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2427 | |
| 2428 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | * SPDIF out controls |
| 2430 | */ |
| 2431 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2432 | static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol, |
| 2433 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | { |
| 2435 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 2436 | uinfo->count = 1; |
| 2437 | return 0; |
| 2438 | } |
| 2439 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2440 | static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, |
| 2441 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | { |
| 2443 | ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | |
| 2444 | IEC958_AES0_NONAUDIO | |
| 2445 | IEC958_AES0_CON_EMPHASIS_5015 | |
| 2446 | IEC958_AES0_CON_NOT_COPYRIGHT; |
| 2447 | ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY | |
| 2448 | IEC958_AES1_CON_ORIGINAL; |
| 2449 | return 0; |
| 2450 | } |
| 2451 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2452 | static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, |
| 2453 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | { |
| 2455 | ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | |
| 2456 | IEC958_AES0_NONAUDIO | |
| 2457 | IEC958_AES0_PRO_EMPHASIS_5015; |
| 2458 | return 0; |
| 2459 | } |
| 2460 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2461 | static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 2462 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | { |
| 2464 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2465 | |
| 2466 | ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff; |
| 2467 | ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff; |
| 2468 | ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff; |
| 2469 | ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff; |
| 2470 | |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
| 2474 | /* convert from SPDIF status bits to HDA SPDIF bits |
| 2475 | * bit 0 (DigEn) is always set zero (to be filled later) |
| 2476 | */ |
| 2477 | static unsigned short convert_from_spdif_status(unsigned int sbits) |
| 2478 | { |
| 2479 | unsigned short val = 0; |
| 2480 | |
| 2481 | if (sbits & IEC958_AES0_PROFESSIONAL) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2482 | val |= AC_DIG1_PROFESSIONAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | if (sbits & IEC958_AES0_NONAUDIO) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2484 | val |= AC_DIG1_NONAUDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | if (sbits & IEC958_AES0_PROFESSIONAL) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2486 | if ((sbits & IEC958_AES0_PRO_EMPHASIS) == |
| 2487 | IEC958_AES0_PRO_EMPHASIS_5015) |
| 2488 | val |= AC_DIG1_EMPHASIS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | } else { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2490 | if ((sbits & IEC958_AES0_CON_EMPHASIS) == |
| 2491 | IEC958_AES0_CON_EMPHASIS_5015) |
| 2492 | val |= AC_DIG1_EMPHASIS; |
| 2493 | if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT)) |
| 2494 | val |= AC_DIG1_COPYRIGHT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | if (sbits & (IEC958_AES1_CON_ORIGINAL << 8)) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2496 | val |= AC_DIG1_LEVEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | val |= sbits & (IEC958_AES1_CON_CATEGORY << 8); |
| 2498 | } |
| 2499 | return val; |
| 2500 | } |
| 2501 | |
| 2502 | /* convert to SPDIF status bits from HDA SPDIF bits |
| 2503 | */ |
| 2504 | static unsigned int convert_to_spdif_status(unsigned short val) |
| 2505 | { |
| 2506 | unsigned int sbits = 0; |
| 2507 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2508 | if (val & AC_DIG1_NONAUDIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | sbits |= IEC958_AES0_NONAUDIO; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2510 | if (val & AC_DIG1_PROFESSIONAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | sbits |= IEC958_AES0_PROFESSIONAL; |
| 2512 | if (sbits & IEC958_AES0_PROFESSIONAL) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2513 | if (sbits & AC_DIG1_EMPHASIS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | sbits |= IEC958_AES0_PRO_EMPHASIS_5015; |
| 2515 | } else { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2516 | if (val & AC_DIG1_EMPHASIS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | sbits |= IEC958_AES0_CON_EMPHASIS_5015; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2518 | if (!(val & AC_DIG1_COPYRIGHT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | sbits |= IEC958_AES0_CON_NOT_COPYRIGHT; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2520 | if (val & AC_DIG1_LEVEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | sbits |= (IEC958_AES1_CON_ORIGINAL << 8); |
| 2522 | sbits |= val & (0x7f << 8); |
| 2523 | } |
| 2524 | return sbits; |
| 2525 | } |
| 2526 | |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 2527 | /* set digital convert verbs both for the given NID and its slaves */ |
| 2528 | static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, |
| 2529 | int verb, int val) |
| 2530 | { |
| 2531 | hda_nid_t *d; |
| 2532 | |
Takashi Iwai | 9e97697 | 2008-11-25 08:17:20 +0100 | [diff] [blame] | 2533 | snd_hda_codec_write_cache(codec, nid, 0, verb, val); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 2534 | d = codec->slave_dig_outs; |
| 2535 | if (!d) |
| 2536 | return; |
| 2537 | for (; *d; d++) |
Takashi Iwai | 9e97697 | 2008-11-25 08:17:20 +0100 | [diff] [blame] | 2538 | snd_hda_codec_write_cache(codec, *d, 0, verb, val); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, |
| 2542 | int dig1, int dig2) |
| 2543 | { |
| 2544 | if (dig1 != -1) |
| 2545 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1); |
| 2546 | if (dig2 != -1) |
| 2547 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2); |
| 2548 | } |
| 2549 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2550 | static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 2551 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | { |
| 2553 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2554 | hda_nid_t nid = kcontrol->private_value; |
| 2555 | unsigned short val; |
| 2556 | int change; |
| 2557 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2558 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | codec->spdif_status = ucontrol->value.iec958.status[0] | |
| 2560 | ((unsigned int)ucontrol->value.iec958.status[1] << 8) | |
| 2561 | ((unsigned int)ucontrol->value.iec958.status[2] << 16) | |
| 2562 | ((unsigned int)ucontrol->value.iec958.status[3] << 24); |
| 2563 | val = convert_from_spdif_status(codec->spdif_status); |
| 2564 | val |= codec->spdif_ctls & 1; |
| 2565 | change = codec->spdif_ctls != val; |
| 2566 | codec->spdif_ctls = val; |
| 2567 | |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 2568 | if (change) |
| 2569 | set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2571 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | return change; |
| 2573 | } |
| 2574 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2575 | #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2577 | static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, |
| 2578 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | { |
| 2580 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2581 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2582 | ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | return 0; |
| 2584 | } |
| 2585 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2586 | static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, |
| 2587 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | { |
| 2589 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2590 | hda_nid_t nid = kcontrol->private_value; |
| 2591 | unsigned short val; |
| 2592 | int change; |
| 2593 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2594 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2595 | val = codec->spdif_ctls & ~AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | if (ucontrol->value.integer.value[0]) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2597 | val |= AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | change = codec->spdif_ctls != val; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 2599 | if (change) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | codec->spdif_ctls = val; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 2601 | set_dig_out_convert(codec, nid, val & 0xff, -1); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2602 | /* unmute amp switch (if any) */ |
| 2603 | if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2604 | (val & AC_DIG1_ENABLE)) |
| 2605 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 2606 | HDA_AMP_MUTE, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2608 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | return change; |
| 2610 | } |
| 2611 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2612 | static struct snd_kcontrol_new dig_mixes[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | { |
| 2614 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2615 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2616 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | .info = snd_hda_spdif_mask_info, |
| 2618 | .get = snd_hda_spdif_cmask_get, |
| 2619 | }, |
| 2620 | { |
| 2621 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2622 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2623 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | .info = snd_hda_spdif_mask_info, |
| 2625 | .get = snd_hda_spdif_pmask_get, |
| 2626 | }, |
| 2627 | { |
| 2628 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2629 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | .info = snd_hda_spdif_mask_info, |
| 2631 | .get = snd_hda_spdif_default_get, |
| 2632 | .put = snd_hda_spdif_default_put, |
| 2633 | }, |
| 2634 | { |
| 2635 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2636 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | .info = snd_hda_spdif_out_switch_info, |
| 2638 | .get = snd_hda_spdif_out_switch_get, |
| 2639 | .put = snd_hda_spdif_out_switch_put, |
| 2640 | }, |
| 2641 | { } /* end */ |
| 2642 | }; |
| 2643 | |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2644 | #define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */ |
| 2645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | /** |
| 2647 | * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls |
| 2648 | * @codec: the HDA codec |
| 2649 | * @nid: audio out widget NID |
| 2650 | * |
| 2651 | * Creates controls related with the SPDIF output. |
| 2652 | * Called from each patch supporting the SPDIF out. |
| 2653 | * |
| 2654 | * Returns 0 if successful, or a negative error code. |
| 2655 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 2656 | int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | { |
| 2658 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2659 | struct snd_kcontrol *kctl; |
| 2660 | struct snd_kcontrol_new *dig_mix; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2661 | int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2663 | for (idx = 0; idx < SPDIF_MAX_IDX; idx++) { |
| 2664 | if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch", |
| 2665 | idx)) |
| 2666 | break; |
| 2667 | } |
| 2668 | if (idx >= SPDIF_MAX_IDX) { |
| 2669 | printk(KERN_ERR "hda_codec: too many IEC958 outputs\n"); |
| 2670 | return -EBUSY; |
| 2671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { |
| 2673 | kctl = snd_ctl_new1(dig_mix, codec); |
Takashi Iwai | b91f080 | 2008-11-04 08:43:08 +0100 | [diff] [blame] | 2674 | if (!kctl) |
| 2675 | return -ENOMEM; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2676 | kctl->id.index = idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | kctl->private_value = nid; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2678 | err = snd_hda_ctl_add(codec, nid, kctl); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2679 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | return err; |
| 2681 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2682 | codec->spdif_ctls = |
Andrew Paprocki | 3982d17 | 2007-12-19 12:13:44 +0100 | [diff] [blame] | 2683 | snd_hda_codec_read(codec, nid, 0, |
| 2684 | AC_VERB_GET_DIGI_CONVERT_1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls); |
| 2686 | return 0; |
| 2687 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2688 | EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | |
| 2690 | /* |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2691 | * SPDIF sharing with analog output |
| 2692 | */ |
| 2693 | static int spdif_share_sw_get(struct snd_kcontrol *kcontrol, |
| 2694 | struct snd_ctl_elem_value *ucontrol) |
| 2695 | { |
| 2696 | struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol); |
| 2697 | ucontrol->value.integer.value[0] = mout->share_spdif; |
| 2698 | return 0; |
| 2699 | } |
| 2700 | |
| 2701 | static int spdif_share_sw_put(struct snd_kcontrol *kcontrol, |
| 2702 | struct snd_ctl_elem_value *ucontrol) |
| 2703 | { |
| 2704 | struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol); |
| 2705 | mout->share_spdif = !!ucontrol->value.integer.value[0]; |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
| 2709 | static struct snd_kcontrol_new spdif_share_sw = { |
| 2710 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2711 | .name = "IEC958 Default PCM Playback Switch", |
| 2712 | .info = snd_ctl_boolean_mono_info, |
| 2713 | .get = spdif_share_sw_get, |
| 2714 | .put = spdif_share_sw_put, |
| 2715 | }; |
| 2716 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2717 | /** |
| 2718 | * snd_hda_create_spdif_share_sw - create Default PCM switch |
| 2719 | * @codec: the HDA codec |
| 2720 | * @mout: multi-out instance |
| 2721 | */ |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2722 | int snd_hda_create_spdif_share_sw(struct hda_codec *codec, |
| 2723 | struct hda_multi_out *mout) |
| 2724 | { |
| 2725 | if (!mout->dig_out_nid) |
| 2726 | return 0; |
| 2727 | /* ATTENTION: here mout is passed as private_data, instead of codec */ |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2728 | return snd_hda_ctl_add(codec, mout->dig_out_nid, |
| 2729 | snd_ctl_new1(&spdif_share_sw, mout)); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2730 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2731 | EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 2732 | |
| 2733 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | * SPDIF input |
| 2735 | */ |
| 2736 | |
| 2737 | #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info |
| 2738 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2739 | static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, |
| 2740 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | { |
| 2742 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2743 | |
| 2744 | ucontrol->value.integer.value[0] = codec->spdif_in_enable; |
| 2745 | return 0; |
| 2746 | } |
| 2747 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2748 | static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, |
| 2749 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | { |
| 2751 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2752 | hda_nid_t nid = kcontrol->private_value; |
| 2753 | unsigned int val = !!ucontrol->value.integer.value[0]; |
| 2754 | int change; |
| 2755 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2756 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | change = codec->spdif_in_enable != val; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 2758 | if (change) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | codec->spdif_in_enable = val; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 2760 | snd_hda_codec_write_cache(codec, nid, 0, |
| 2761 | AC_VERB_SET_DIGI_CONVERT_1, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2763 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | return change; |
| 2765 | } |
| 2766 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2767 | static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, |
| 2768 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | { |
| 2770 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2771 | hda_nid_t nid = kcontrol->private_value; |
| 2772 | unsigned short val; |
| 2773 | unsigned int sbits; |
| 2774 | |
Andrew Paprocki | 3982d17 | 2007-12-19 12:13:44 +0100 | [diff] [blame] | 2775 | val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | sbits = convert_to_spdif_status(val); |
| 2777 | ucontrol->value.iec958.status[0] = sbits; |
| 2778 | ucontrol->value.iec958.status[1] = sbits >> 8; |
| 2779 | ucontrol->value.iec958.status[2] = sbits >> 16; |
| 2780 | ucontrol->value.iec958.status[3] = sbits >> 24; |
| 2781 | return 0; |
| 2782 | } |
| 2783 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2784 | static struct snd_kcontrol_new dig_in_ctls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | { |
| 2786 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2787 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | .info = snd_hda_spdif_in_switch_info, |
| 2789 | .get = snd_hda_spdif_in_switch_get, |
| 2790 | .put = snd_hda_spdif_in_switch_put, |
| 2791 | }, |
| 2792 | { |
| 2793 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2794 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2795 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | .info = snd_hda_spdif_mask_info, |
| 2797 | .get = snd_hda_spdif_in_status_get, |
| 2798 | }, |
| 2799 | { } /* end */ |
| 2800 | }; |
| 2801 | |
| 2802 | /** |
| 2803 | * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls |
| 2804 | * @codec: the HDA codec |
| 2805 | * @nid: audio in widget NID |
| 2806 | * |
| 2807 | * Creates controls related with the SPDIF input. |
| 2808 | * Called from each patch supporting the SPDIF in. |
| 2809 | * |
| 2810 | * Returns 0 if successful, or a negative error code. |
| 2811 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 2812 | int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | { |
| 2814 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 2815 | struct snd_kcontrol *kctl; |
| 2816 | struct snd_kcontrol_new *dig_mix; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2817 | int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2819 | for (idx = 0; idx < SPDIF_MAX_IDX; idx++) { |
| 2820 | if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch", |
| 2821 | idx)) |
| 2822 | break; |
| 2823 | } |
| 2824 | if (idx >= SPDIF_MAX_IDX) { |
| 2825 | printk(KERN_ERR "hda_codec: too many IEC958 inputs\n"); |
| 2826 | return -EBUSY; |
| 2827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { |
| 2829 | kctl = snd_ctl_new1(dig_mix, codec); |
Takashi Iwai | c8dcdf8 | 2009-02-06 16:21:20 +0100 | [diff] [blame] | 2830 | if (!kctl) |
| 2831 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | kctl->private_value = nid; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2833 | err = snd_hda_ctl_add(codec, nid, kctl); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2834 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | return err; |
| 2836 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2837 | codec->spdif_in_enable = |
Andrew Paprocki | 3982d17 | 2007-12-19 12:13:44 +0100 | [diff] [blame] | 2838 | snd_hda_codec_read(codec, nid, 0, |
| 2839 | AC_VERB_GET_DIGI_CONVERT_1, 0) & |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2840 | AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | return 0; |
| 2842 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2843 | EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2845 | #ifdef SND_HDA_NEEDS_RESUME |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 2846 | /* |
| 2847 | * command cache |
| 2848 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2850 | /* build a 32bit cache key with the widget id and the command parameter */ |
| 2851 | #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid) |
| 2852 | #define get_cmd_cache_nid(key) ((key) & 0xff) |
| 2853 | #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff) |
| 2854 | |
| 2855 | /** |
| 2856 | * snd_hda_codec_write_cache - send a single command with caching |
| 2857 | * @codec: the HDA codec |
| 2858 | * @nid: NID to send the command |
| 2859 | * @direct: direct flag |
| 2860 | * @verb: the verb to send |
| 2861 | * @parm: the parameter for the verb |
| 2862 | * |
| 2863 | * Send a single command without waiting for response. |
| 2864 | * |
| 2865 | * Returns 0 if successful, or a negative error code. |
| 2866 | */ |
| 2867 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, |
| 2868 | int direct, unsigned int verb, unsigned int parm) |
| 2869 | { |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 2870 | int err = snd_hda_codec_write(codec, nid, direct, verb, parm); |
| 2871 | struct hda_cache_head *c; |
| 2872 | u32 key; |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 2873 | |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 2874 | if (err < 0) |
| 2875 | return err; |
| 2876 | /* parm may contain the verb stuff for get/set amp */ |
| 2877 | verb = verb | (parm >> 8); |
| 2878 | parm &= 0xff; |
| 2879 | key = build_cmd_cache_key(nid, verb); |
| 2880 | mutex_lock(&codec->bus->cmd_mutex); |
| 2881 | c = get_alloc_hash(&codec->cmd_cache, key); |
| 2882 | if (c) |
| 2883 | c->val = parm; |
| 2884 | mutex_unlock(&codec->bus->cmd_mutex); |
| 2885 | return 0; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2886 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2887 | EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2888 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2889 | /** |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 2890 | * snd_hda_codec_update_cache - check cache and write the cmd only when needed |
| 2891 | * @codec: the HDA codec |
| 2892 | * @nid: NID to send the command |
| 2893 | * @direct: direct flag |
| 2894 | * @verb: the verb to send |
| 2895 | * @parm: the parameter for the verb |
| 2896 | * |
| 2897 | * This function works like snd_hda_codec_write_cache(), but it doesn't send |
| 2898 | * command if the parameter is already identical with the cached value. |
| 2899 | * If not, it sends the command and refreshes the cache. |
| 2900 | * |
| 2901 | * Returns 0 if successful, or a negative error code. |
| 2902 | */ |
| 2903 | int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, |
| 2904 | int direct, unsigned int verb, unsigned int parm) |
| 2905 | { |
| 2906 | struct hda_cache_head *c; |
| 2907 | u32 key; |
| 2908 | |
| 2909 | /* parm may contain the verb stuff for get/set amp */ |
| 2910 | verb = verb | (parm >> 8); |
| 2911 | parm &= 0xff; |
| 2912 | key = build_cmd_cache_key(nid, verb); |
| 2913 | mutex_lock(&codec->bus->cmd_mutex); |
| 2914 | c = get_hash(&codec->cmd_cache, key); |
| 2915 | if (c && c->val == parm) { |
| 2916 | mutex_unlock(&codec->bus->cmd_mutex); |
| 2917 | return 0; |
| 2918 | } |
| 2919 | mutex_unlock(&codec->bus->cmd_mutex); |
| 2920 | return snd_hda_codec_write_cache(codec, nid, direct, verb, parm); |
| 2921 | } |
| 2922 | EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache); |
| 2923 | |
| 2924 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2925 | * snd_hda_codec_resume_cache - Resume the all commands from the cache |
| 2926 | * @codec: HD-audio codec |
| 2927 | * |
| 2928 | * Execute all verbs recorded in the command caches to resume. |
| 2929 | */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2930 | void snd_hda_codec_resume_cache(struct hda_codec *codec) |
| 2931 | { |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2932 | struct hda_cache_head *buffer = codec->cmd_cache.buf.list; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2933 | int i; |
| 2934 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2935 | for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) { |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2936 | u32 key = buffer->key; |
| 2937 | if (!key) |
| 2938 | continue; |
| 2939 | snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0, |
| 2940 | get_cmd_cache_cmd(key), buffer->val); |
| 2941 | } |
| 2942 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2943 | EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2944 | |
| 2945 | /** |
| 2946 | * snd_hda_sequence_write_cache - sequence writes with caching |
| 2947 | * @codec: the HDA codec |
| 2948 | * @seq: VERB array to send |
| 2949 | * |
| 2950 | * Send the commands sequentially from the given array. |
| 2951 | * Thte commands are recorded on cache for power-save and resume. |
| 2952 | * The array must be terminated with NID=0. |
| 2953 | */ |
| 2954 | void snd_hda_sequence_write_cache(struct hda_codec *codec, |
| 2955 | const struct hda_verb *seq) |
| 2956 | { |
| 2957 | for (; seq->nid; seq++) |
| 2958 | snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, |
| 2959 | seq->param); |
| 2960 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 2961 | EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2962 | #endif /* SND_HDA_NEEDS_RESUME */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2963 | |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 2964 | /* |
| 2965 | * set power state of the codec |
| 2966 | */ |
| 2967 | static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
| 2968 | unsigned int power_state) |
| 2969 | { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2970 | hda_nid_t nid; |
| 2971 | int i; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 2972 | |
Takashi Iwai | 05ff7e1 | 2009-07-22 12:39:24 +0200 | [diff] [blame] | 2973 | /* this delay seems necessary to avoid click noise at power-down */ |
| 2974 | if (power_state == AC_PWRST_D3) |
| 2975 | msleep(100); |
| 2976 | snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 2977 | power_state); |
Takashi Iwai | 05ff7e1 | 2009-07-22 12:39:24 +0200 | [diff] [blame] | 2978 | /* partial workaround for "azx_get_response timeout" */ |
Zhang, Rui | dd2b4a7 | 2010-02-24 09:38:49 +0800 | [diff] [blame] | 2979 | if (power_state == AC_PWRST_D0 && |
| 2980 | (codec->vendor_id & 0xffff0000) == 0x14f10000) |
Takashi Iwai | 05ff7e1 | 2009-07-22 12:39:24 +0200 | [diff] [blame] | 2981 | msleep(10); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 2982 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2983 | nid = codec->start_nid; |
| 2984 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
Takashi Iwai | 7eba5c9 | 2007-11-14 14:53:42 +0100 | [diff] [blame] | 2985 | unsigned int wcaps = get_wcaps(codec, nid); |
| 2986 | if (wcaps & AC_WCAP_POWER) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2987 | unsigned int wid_type = get_wcaps_type(wcaps); |
Takashi Iwai | a3b48c8 | 2009-04-21 13:37:29 +0200 | [diff] [blame] | 2988 | if (power_state == AC_PWRST_D3 && |
| 2989 | wid_type == AC_WID_PIN) { |
Takashi Iwai | 7eba5c9 | 2007-11-14 14:53:42 +0100 | [diff] [blame] | 2990 | unsigned int pincap; |
| 2991 | /* |
| 2992 | * don't power down the widget if it controls |
| 2993 | * eapd and EAPD_BTLENABLE is set. |
| 2994 | */ |
Takashi Iwai | 14bafe3 | 2009-03-23 16:35:39 +0100 | [diff] [blame] | 2995 | pincap = snd_hda_query_pin_caps(codec, nid); |
Takashi Iwai | 7eba5c9 | 2007-11-14 14:53:42 +0100 | [diff] [blame] | 2996 | if (pincap & AC_PINCAP_EAPD) { |
| 2997 | int eapd = snd_hda_codec_read(codec, |
| 2998 | nid, 0, |
| 2999 | AC_VERB_GET_EAPD_BTLENABLE, 0); |
| 3000 | eapd &= 0x02; |
Takashi Iwai | a3b48c8 | 2009-04-21 13:37:29 +0200 | [diff] [blame] | 3001 | if (eapd) |
Takashi Iwai | 7eba5c9 | 2007-11-14 14:53:42 +0100 | [diff] [blame] | 3002 | continue; |
| 3003 | } |
Takashi Iwai | 1194b5b | 2007-10-10 10:04:26 +0200 | [diff] [blame] | 3004 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3005 | snd_hda_codec_write(codec, nid, 0, |
| 3006 | AC_VERB_SET_POWER_STATE, |
| 3007 | power_state); |
Takashi Iwai | 1194b5b | 2007-10-10 10:04:26 +0200 | [diff] [blame] | 3008 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3011 | if (power_state == AC_PWRST_D0) { |
| 3012 | unsigned long end_time; |
| 3013 | int state; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3014 | /* wait until the codec reachs to D0 */ |
| 3015 | end_time = jiffies + msecs_to_jiffies(500); |
| 3016 | do { |
| 3017 | state = snd_hda_codec_read(codec, fg, 0, |
| 3018 | AC_VERB_GET_POWER_STATE, 0); |
| 3019 | if (state == power_state) |
| 3020 | break; |
| 3021 | msleep(1); |
| 3022 | } while (time_after_eq(end_time, jiffies)); |
| 3023 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3024 | } |
| 3025 | |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 3026 | #ifdef CONFIG_SND_HDA_HWDEP |
| 3027 | /* execute additional init verbs */ |
| 3028 | static void hda_exec_init_verbs(struct hda_codec *codec) |
| 3029 | { |
| 3030 | if (codec->init_verbs.list) |
| 3031 | snd_hda_sequence_write(codec, codec->init_verbs.list); |
| 3032 | } |
| 3033 | #else |
| 3034 | static inline void hda_exec_init_verbs(struct hda_codec *codec) {} |
| 3035 | #endif |
| 3036 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3037 | #ifdef SND_HDA_NEEDS_RESUME |
| 3038 | /* |
| 3039 | * call suspend and power-down; used both from PM and power-save |
| 3040 | */ |
| 3041 | static void hda_call_codec_suspend(struct hda_codec *codec) |
| 3042 | { |
| 3043 | if (codec->patch_ops.suspend) |
| 3044 | codec->patch_ops.suspend(codec, PMSG_SUSPEND); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 3045 | hda_cleanup_all_streams(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3046 | hda_set_power_state(codec, |
| 3047 | codec->afg ? codec->afg : codec->mfg, |
| 3048 | AC_PWRST_D3); |
| 3049 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3050 | snd_hda_update_power_acct(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3051 | cancel_delayed_work(&codec->power_work); |
Takashi Iwai | 95e99fd | 2007-08-13 15:29:04 +0200 | [diff] [blame] | 3052 | codec->power_on = 0; |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3053 | codec->power_transition = 0; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3054 | codec->power_jiffies = jiffies; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3055 | #endif |
| 3056 | } |
| 3057 | |
| 3058 | /* |
| 3059 | * kick up codec; used both from PM and power-save |
| 3060 | */ |
| 3061 | static void hda_call_codec_resume(struct hda_codec *codec) |
| 3062 | { |
| 3063 | hda_set_power_state(codec, |
| 3064 | codec->afg ? codec->afg : codec->mfg, |
| 3065 | AC_PWRST_D0); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 3066 | restore_pincfgs(codec); /* restore all current pin configs */ |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 3067 | restore_shutup_pins(codec); |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 3068 | hda_exec_init_verbs(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3069 | if (codec->patch_ops.resume) |
| 3070 | codec->patch_ops.resume(codec); |
| 3071 | else { |
Takashi Iwai | 9d99f31 | 2007-08-14 15:15:52 +0200 | [diff] [blame] | 3072 | if (codec->patch_ops.init) |
| 3073 | codec->patch_ops.init(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3074 | snd_hda_codec_resume_amp(codec); |
| 3075 | snd_hda_codec_resume_cache(codec); |
| 3076 | } |
| 3077 | } |
| 3078 | #endif /* SND_HDA_NEEDS_RESUME */ |
| 3079 | |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | /** |
| 3082 | * snd_hda_build_controls - build mixer controls |
| 3083 | * @bus: the BUS |
| 3084 | * |
| 3085 | * Creates mixer controls for each codec included in the bus. |
| 3086 | * |
| 3087 | * Returns 0 if successful, otherwise a negative error code. |
| 3088 | */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 3089 | int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3091 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3093 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3094 | int err = snd_hda_codec_build_controls(codec); |
Takashi Iwai | f93d461 | 2009-03-02 10:44:15 +0100 | [diff] [blame] | 3095 | if (err < 0) { |
Takashi Iwai | 28d1a85 | 2010-03-15 09:05:46 +0100 | [diff] [blame] | 3096 | printk(KERN_ERR "hda_codec: cannot build controls " |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3097 | "for #%d (error %d)\n", codec->addr, err); |
Takashi Iwai | f93d461 | 2009-03-02 10:44:15 +0100 | [diff] [blame] | 3098 | err = snd_hda_codec_reset(codec); |
| 3099 | if (err < 0) { |
| 3100 | printk(KERN_ERR |
| 3101 | "hda_codec: cannot revert codec\n"); |
| 3102 | return err; |
| 3103 | } |
| 3104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | } |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3106 | return 0; |
| 3107 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3108 | EXPORT_SYMBOL_HDA(snd_hda_build_controls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3110 | int snd_hda_codec_build_controls(struct hda_codec *codec) |
| 3111 | { |
| 3112 | int err = 0; |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 3113 | hda_exec_init_verbs(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3114 | /* continue to initialize... */ |
| 3115 | if (codec->patch_ops.init) |
| 3116 | err = codec->patch_ops.init(codec); |
| 3117 | if (!err && codec->patch_ops.build_controls) |
| 3118 | err = codec->patch_ops.build_controls(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3119 | if (err < 0) |
| 3120 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | return 0; |
| 3122 | } |
| 3123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | /* |
| 3125 | * stream formats |
| 3126 | */ |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3127 | struct hda_rate_tbl { |
| 3128 | unsigned int hz; |
| 3129 | unsigned int alsa_bits; |
| 3130 | unsigned int hda_fmt; |
| 3131 | }; |
| 3132 | |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3133 | /* rate = base * mult / div */ |
| 3134 | #define HDA_RATE(base, mult, div) \ |
| 3135 | (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \ |
| 3136 | (((div) - 1) << AC_FMT_DIV_SHIFT)) |
| 3137 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3138 | static struct hda_rate_tbl rate_bits[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | /* rate in Hz, ALSA rate bitmask, HDA format value */ |
Nicolas Graziano | 9d8f53f | 2005-08-22 13:47:16 +0200 | [diff] [blame] | 3140 | |
| 3141 | /* autodetected value used in snd_hda_query_supported_pcm */ |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3142 | { 8000, SNDRV_PCM_RATE_8000, HDA_RATE(48, 1, 6) }, |
| 3143 | { 11025, SNDRV_PCM_RATE_11025, HDA_RATE(44, 1, 4) }, |
| 3144 | { 16000, SNDRV_PCM_RATE_16000, HDA_RATE(48, 1, 3) }, |
| 3145 | { 22050, SNDRV_PCM_RATE_22050, HDA_RATE(44, 1, 2) }, |
| 3146 | { 32000, SNDRV_PCM_RATE_32000, HDA_RATE(48, 2, 3) }, |
| 3147 | { 44100, SNDRV_PCM_RATE_44100, HDA_RATE(44, 1, 1) }, |
| 3148 | { 48000, SNDRV_PCM_RATE_48000, HDA_RATE(48, 1, 1) }, |
| 3149 | { 88200, SNDRV_PCM_RATE_88200, HDA_RATE(44, 2, 1) }, |
| 3150 | { 96000, SNDRV_PCM_RATE_96000, HDA_RATE(48, 2, 1) }, |
| 3151 | { 176400, SNDRV_PCM_RATE_176400, HDA_RATE(44, 4, 1) }, |
| 3152 | { 192000, SNDRV_PCM_RATE_192000, HDA_RATE(48, 4, 1) }, |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 3153 | #define AC_PAR_PCM_RATE_BITS 11 |
| 3154 | /* up to bits 10, 384kHZ isn't supported properly */ |
| 3155 | |
| 3156 | /* not autodetected value */ |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3157 | { 9600, SNDRV_PCM_RATE_KNOT, HDA_RATE(48, 1, 5) }, |
Nicolas Graziano | 9d8f53f | 2005-08-22 13:47:16 +0200 | [diff] [blame] | 3158 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3159 | { 0 } /* terminator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | }; |
| 3161 | |
| 3162 | /** |
| 3163 | * snd_hda_calc_stream_format - calculate format bitset |
| 3164 | * @rate: the sample rate |
| 3165 | * @channels: the number of channels |
| 3166 | * @format: the PCM format (SNDRV_PCM_FORMAT_XXX) |
| 3167 | * @maxbps: the max. bps |
| 3168 | * |
| 3169 | * Calculate the format bitset from the given rate, channels and th PCM format. |
| 3170 | * |
| 3171 | * Return zero if invalid. |
| 3172 | */ |
| 3173 | unsigned int snd_hda_calc_stream_format(unsigned int rate, |
| 3174 | unsigned int channels, |
| 3175 | unsigned int format, |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 3176 | unsigned int maxbps, |
| 3177 | unsigned short spdif_ctls) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | { |
| 3179 | int i; |
| 3180 | unsigned int val = 0; |
| 3181 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3182 | for (i = 0; rate_bits[i].hz; i++) |
| 3183 | if (rate_bits[i].hz == rate) { |
| 3184 | val = rate_bits[i].hda_fmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | break; |
| 3186 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3187 | if (!rate_bits[i].hz) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | snd_printdd("invalid rate %d\n", rate); |
| 3189 | return 0; |
| 3190 | } |
| 3191 | |
| 3192 | if (channels == 0 || channels > 8) { |
| 3193 | snd_printdd("invalid channels %d\n", channels); |
| 3194 | return 0; |
| 3195 | } |
| 3196 | val |= channels - 1; |
| 3197 | |
| 3198 | switch (snd_pcm_format_width(format)) { |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3199 | case 8: |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3200 | val |= AC_FMT_BITS_8; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3201 | break; |
| 3202 | case 16: |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3203 | val |= AC_FMT_BITS_16; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3204 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | case 20: |
| 3206 | case 24: |
| 3207 | case 32: |
Takashi Iwai | b0bb3aa | 2009-07-03 23:25:37 +0200 | [diff] [blame] | 3208 | if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3209 | val |= AC_FMT_BITS_32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | else if (maxbps >= 24) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3211 | val |= AC_FMT_BITS_24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | else |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3213 | val |= AC_FMT_BITS_20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | break; |
| 3215 | default: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3216 | snd_printdd("invalid format width %d\n", |
| 3217 | snd_pcm_format_width(format)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | return 0; |
| 3219 | } |
| 3220 | |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 3221 | if (spdif_ctls & AC_DIG1_NONAUDIO) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 3222 | val |= AC_FMT_TYPE_NON_PCM; |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 3223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | return val; |
| 3225 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3226 | EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 3228 | static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid) |
| 3229 | { |
| 3230 | unsigned int val = 0; |
| 3231 | if (nid != codec->afg && |
| 3232 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) |
| 3233 | val = snd_hda_param_read(codec, nid, AC_PAR_PCM); |
| 3234 | if (!val || val == -1) |
| 3235 | val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); |
| 3236 | if (!val || val == -1) |
| 3237 | return 0; |
| 3238 | return val; |
| 3239 | } |
| 3240 | |
| 3241 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) |
| 3242 | { |
| 3243 | return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid), |
| 3244 | get_pcm_param); |
| 3245 | } |
| 3246 | |
| 3247 | static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid) |
| 3248 | { |
| 3249 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); |
| 3250 | if (!streams || streams == -1) |
| 3251 | streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); |
| 3252 | if (!streams || streams == -1) |
| 3253 | return 0; |
| 3254 | return streams; |
| 3255 | } |
| 3256 | |
| 3257 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) |
| 3258 | { |
| 3259 | return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid), |
| 3260 | get_stream_param); |
| 3261 | } |
| 3262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | /** |
| 3264 | * snd_hda_query_supported_pcm - query the supported PCM rates and formats |
| 3265 | * @codec: the HDA codec |
| 3266 | * @nid: NID to query |
| 3267 | * @ratesp: the pointer to store the detected rate bitflags |
| 3268 | * @formatsp: the pointer to store the detected formats |
| 3269 | * @bpsp: the pointer to store the detected format widths |
| 3270 | * |
| 3271 | * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp |
| 3272 | * or @bsps argument is ignored. |
| 3273 | * |
| 3274 | * Returns 0 if successful, otherwise a negative error code. |
| 3275 | */ |
Takashi Iwai | 986862bd | 2008-11-27 12:40:13 +0100 | [diff] [blame] | 3276 | static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp) |
| 3278 | { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3279 | unsigned int i, val, wcaps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3281 | wcaps = get_wcaps(codec, nid); |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 3282 | val = query_pcm_param(codec, nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | |
| 3284 | if (ratesp) { |
| 3285 | u32 rates = 0; |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 3286 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | if (val & (1 << i)) |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3288 | rates |= rate_bits[i].alsa_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | } |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3290 | if (rates == 0) { |
| 3291 | snd_printk(KERN_ERR "hda_codec: rates == 0 " |
| 3292 | "(nid=0x%x, val=0x%x, ovrd=%i)\n", |
| 3293 | nid, val, |
| 3294 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); |
| 3295 | return -EIO; |
| 3296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | *ratesp = rates; |
| 3298 | } |
| 3299 | |
| 3300 | if (formatsp || bpsp) { |
| 3301 | u64 formats = 0; |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3302 | unsigned int streams, bps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 3304 | streams = query_stream_param(codec, nid); |
| 3305 | if (!streams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | |
| 3308 | bps = 0; |
| 3309 | if (streams & AC_SUPFMT_PCM) { |
| 3310 | if (val & AC_SUPPCM_BITS_8) { |
| 3311 | formats |= SNDRV_PCM_FMTBIT_U8; |
| 3312 | bps = 8; |
| 3313 | } |
| 3314 | if (val & AC_SUPPCM_BITS_16) { |
| 3315 | formats |= SNDRV_PCM_FMTBIT_S16_LE; |
| 3316 | bps = 16; |
| 3317 | } |
| 3318 | if (wcaps & AC_WCAP_DIGITAL) { |
| 3319 | if (val & AC_SUPPCM_BITS_32) |
| 3320 | formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; |
| 3321 | if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24)) |
| 3322 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 3323 | if (val & AC_SUPPCM_BITS_24) |
| 3324 | bps = 24; |
| 3325 | else if (val & AC_SUPPCM_BITS_20) |
| 3326 | bps = 20; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3327 | } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24| |
| 3328 | AC_SUPPCM_BITS_32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 3330 | if (val & AC_SUPPCM_BITS_32) |
| 3331 | bps = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | else if (val & AC_SUPPCM_BITS_24) |
| 3333 | bps = 24; |
Nicolas Graziano | 33ef7651 | 2006-09-19 14:23:14 +0200 | [diff] [blame] | 3334 | else if (val & AC_SUPPCM_BITS_20) |
| 3335 | bps = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | } |
| 3337 | } |
Takashi Iwai | b5025c5 | 2009-07-01 18:05:27 +0200 | [diff] [blame] | 3338 | if (streams & AC_SUPFMT_FLOAT32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; |
Takashi Iwai | b0bb3aa | 2009-07-03 23:25:37 +0200 | [diff] [blame] | 3340 | if (!bps) |
| 3341 | bps = 32; |
Takashi Iwai | b5025c5 | 2009-07-01 18:05:27 +0200 | [diff] [blame] | 3342 | } |
| 3343 | if (streams == AC_SUPFMT_AC3) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3344 | /* should be exclusive */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | /* temporary hack: we have still no proper support |
| 3346 | * for the direct AC3 stream... |
| 3347 | */ |
| 3348 | formats |= SNDRV_PCM_FMTBIT_U8; |
| 3349 | bps = 8; |
| 3350 | } |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3351 | if (formats == 0) { |
| 3352 | snd_printk(KERN_ERR "hda_codec: formats == 0 " |
| 3353 | "(nid=0x%x, val=0x%x, ovrd=%i, " |
| 3354 | "streams=0x%x)\n", |
| 3355 | nid, val, |
| 3356 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0, |
| 3357 | streams); |
| 3358 | return -EIO; |
| 3359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | if (formatsp) |
| 3361 | *formatsp = formats; |
| 3362 | if (bpsp) |
| 3363 | *bpsp = bps; |
| 3364 | } |
| 3365 | |
| 3366 | return 0; |
| 3367 | } |
| 3368 | |
| 3369 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3370 | * snd_hda_is_supported_format - Check the validity of the format |
| 3371 | * @codec: HD-audio codec |
| 3372 | * @nid: NID to check |
| 3373 | * @format: the HD-audio format value to check |
| 3374 | * |
| 3375 | * Check whether the given node supports the format value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | * |
| 3377 | * Returns 1 if supported, 0 if not. |
| 3378 | */ |
| 3379 | int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, |
| 3380 | unsigned int format) |
| 3381 | { |
| 3382 | int i; |
| 3383 | unsigned int val = 0, rate, stream; |
| 3384 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 3385 | val = query_pcm_param(codec, nid); |
| 3386 | if (!val) |
| 3387 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
| 3389 | rate = format & 0xff00; |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 3390 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 3391 | if (rate_bits[i].hda_fmt == rate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | if (val & (1 << i)) |
| 3393 | break; |
| 3394 | return 0; |
| 3395 | } |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 3396 | if (i >= AC_PAR_PCM_RATE_BITS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | return 0; |
| 3398 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 3399 | stream = query_stream_param(codec, nid); |
| 3400 | if (!stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | return 0; |
| 3402 | |
| 3403 | if (stream & AC_SUPFMT_PCM) { |
| 3404 | switch (format & 0xf0) { |
| 3405 | case 0x00: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3406 | if (!(val & AC_SUPPCM_BITS_8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | return 0; |
| 3408 | break; |
| 3409 | case 0x10: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3410 | if (!(val & AC_SUPPCM_BITS_16)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | return 0; |
| 3412 | break; |
| 3413 | case 0x20: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3414 | if (!(val & AC_SUPPCM_BITS_20)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | return 0; |
| 3416 | break; |
| 3417 | case 0x30: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3418 | if (!(val & AC_SUPPCM_BITS_24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | return 0; |
| 3420 | break; |
| 3421 | case 0x40: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3422 | if (!(val & AC_SUPPCM_BITS_32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | return 0; |
| 3424 | break; |
| 3425 | default: |
| 3426 | return 0; |
| 3427 | } |
| 3428 | } else { |
| 3429 | /* FIXME: check for float32 and AC3? */ |
| 3430 | } |
| 3431 | |
| 3432 | return 1; |
| 3433 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3434 | EXPORT_SYMBOL_HDA(snd_hda_is_supported_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
| 3436 | /* |
| 3437 | * PCM stuff |
| 3438 | */ |
| 3439 | static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo, |
| 3440 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3441 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | { |
| 3443 | return 0; |
| 3444 | } |
| 3445 | |
| 3446 | static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo, |
| 3447 | struct hda_codec *codec, |
| 3448 | unsigned int stream_tag, |
| 3449 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3450 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | { |
| 3452 | snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); |
| 3453 | return 0; |
| 3454 | } |
| 3455 | |
| 3456 | static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo, |
| 3457 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3458 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | { |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 3460 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | return 0; |
| 3462 | } |
| 3463 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3464 | static int set_pcm_default_values(struct hda_codec *codec, |
| 3465 | struct hda_pcm_stream *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3467 | int err; |
| 3468 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3469 | /* query support PCM information from the given NID */ |
| 3470 | if (info->nid && (!info->rates || !info->formats)) { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3471 | err = snd_hda_query_supported_pcm(codec, info->nid, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3472 | info->rates ? NULL : &info->rates, |
| 3473 | info->formats ? NULL : &info->formats, |
| 3474 | info->maxbps ? NULL : &info->maxbps); |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 3475 | if (err < 0) |
| 3476 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | } |
| 3478 | if (info->ops.open == NULL) |
| 3479 | info->ops.open = hda_pcm_default_open_close; |
| 3480 | if (info->ops.close == NULL) |
| 3481 | info->ops.close = hda_pcm_default_open_close; |
| 3482 | if (info->ops.prepare == NULL) { |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3483 | if (snd_BUG_ON(!info->nid)) |
| 3484 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | info->ops.prepare = hda_pcm_default_prepare; |
| 3486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | if (info->ops.cleanup == NULL) { |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3488 | if (snd_BUG_ON(!info->nid)) |
| 3489 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | info->ops.cleanup = hda_pcm_default_cleanup; |
| 3491 | } |
| 3492 | return 0; |
| 3493 | } |
| 3494 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 3495 | /* |
| 3496 | * codec prepare/cleanup entries |
| 3497 | */ |
| 3498 | int snd_hda_codec_prepare(struct hda_codec *codec, |
| 3499 | struct hda_pcm_stream *hinfo, |
| 3500 | unsigned int stream, |
| 3501 | unsigned int format, |
| 3502 | struct snd_pcm_substream *substream) |
| 3503 | { |
| 3504 | int ret; |
| 3505 | mutex_lock(&codec->prepare_mutex); |
| 3506 | ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); |
| 3507 | if (ret >= 0) |
| 3508 | purify_inactive_streams(codec); |
| 3509 | mutex_unlock(&codec->prepare_mutex); |
| 3510 | return ret; |
| 3511 | } |
| 3512 | EXPORT_SYMBOL_HDA(snd_hda_codec_prepare); |
| 3513 | |
| 3514 | void snd_hda_codec_cleanup(struct hda_codec *codec, |
| 3515 | struct hda_pcm_stream *hinfo, |
| 3516 | struct snd_pcm_substream *substream) |
| 3517 | { |
| 3518 | mutex_lock(&codec->prepare_mutex); |
| 3519 | hinfo->ops.cleanup(hinfo, codec, substream); |
| 3520 | mutex_unlock(&codec->prepare_mutex); |
| 3521 | } |
| 3522 | EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup); |
| 3523 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3524 | /* global */ |
Jaroslav Kysela | e330323 | 2009-11-10 14:53:02 +0100 | [diff] [blame] | 3525 | const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = { |
| 3526 | "Audio", "SPDIF", "HDMI", "Modem" |
| 3527 | }; |
| 3528 | |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3529 | /* |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3530 | * get the empty PCM device number to assign |
Takashi Iwai | c893622 | 2010-01-28 17:08:53 +0100 | [diff] [blame] | 3531 | * |
| 3532 | * note the max device number is limited by HDA_MAX_PCMS, currently 10 |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3533 | */ |
| 3534 | static int get_empty_pcm_device(struct hda_bus *bus, int type) |
| 3535 | { |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3536 | /* audio device indices; not linear to keep compatibility */ |
| 3537 | static int audio_idx[HDA_PCM_NTYPES][5] = { |
| 3538 | [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 }, |
| 3539 | [HDA_PCM_TYPE_SPDIF] = { 1, -1 }, |
Wu Fengguang | 92608ba | 2009-10-30 11:40:03 +0100 | [diff] [blame] | 3540 | [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 }, |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3541 | [HDA_PCM_TYPE_MODEM] = { 6, -1 }, |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3542 | }; |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3543 | int i; |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3544 | |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3545 | if (type >= HDA_PCM_NTYPES) { |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3546 | snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); |
| 3547 | return -EINVAL; |
| 3548 | } |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3549 | |
| 3550 | for (i = 0; audio_idx[type][i] >= 0 ; i++) |
| 3551 | if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits)) |
| 3552 | return audio_idx[type][i]; |
| 3553 | |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3554 | snd_printk(KERN_WARNING "Too many %s devices\n", |
| 3555 | snd_hda_pcm_type_name[type]); |
Wu Fengguang | f5d6def5 | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 3556 | return -EAGAIN; |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | /* |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3560 | * attach a new PCM stream |
| 3561 | */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3562 | static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3563 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3564 | struct hda_bus *bus = codec->bus; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3565 | struct hda_pcm_stream *info; |
| 3566 | int stream, err; |
| 3567 | |
Takashi Iwai | b91f080 | 2008-11-04 08:43:08 +0100 | [diff] [blame] | 3568 | if (snd_BUG_ON(!pcm->name)) |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3569 | return -EINVAL; |
| 3570 | for (stream = 0; stream < 2; stream++) { |
| 3571 | info = &pcm->stream[stream]; |
| 3572 | if (info->substreams) { |
| 3573 | err = set_pcm_default_values(codec, info); |
| 3574 | if (err < 0) |
| 3575 | return err; |
| 3576 | } |
| 3577 | } |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3578 | return bus->ops.attach_pcm(bus, codec, pcm); |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3579 | } |
| 3580 | |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3581 | /* assign all PCMs of the given codec */ |
| 3582 | int snd_hda_codec_build_pcms(struct hda_codec *codec) |
| 3583 | { |
| 3584 | unsigned int pcm; |
| 3585 | int err; |
| 3586 | |
| 3587 | if (!codec->num_pcms) { |
| 3588 | if (!codec->patch_ops.build_pcms) |
| 3589 | return 0; |
| 3590 | err = codec->patch_ops.build_pcms(codec); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 3591 | if (err < 0) { |
| 3592 | printk(KERN_ERR "hda_codec: cannot build PCMs" |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3593 | "for #%d (error %d)\n", codec->addr, err); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 3594 | err = snd_hda_codec_reset(codec); |
| 3595 | if (err < 0) { |
| 3596 | printk(KERN_ERR |
| 3597 | "hda_codec: cannot revert codec\n"); |
| 3598 | return err; |
| 3599 | } |
| 3600 | } |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3601 | } |
| 3602 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { |
| 3603 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; |
| 3604 | int dev; |
| 3605 | |
| 3606 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) |
Takashi Iwai | 41b5b01 | 2009-01-20 18:21:23 +0100 | [diff] [blame] | 3607 | continue; /* no substreams assigned */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3608 | |
| 3609 | if (!cpcm->pcm) { |
| 3610 | dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); |
| 3611 | if (dev < 0) |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 3612 | continue; /* no fatal error */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3613 | cpcm->device = dev; |
| 3614 | err = snd_hda_attach_pcm(codec, cpcm); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 3615 | if (err < 0) { |
| 3616 | printk(KERN_ERR "hda_codec: cannot attach " |
| 3617 | "PCM stream %d for codec #%d\n", |
| 3618 | dev, codec->addr); |
| 3619 | continue; /* no fatal error */ |
| 3620 | } |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | return 0; |
| 3624 | } |
| 3625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | /** |
| 3627 | * snd_hda_build_pcms - build PCM information |
| 3628 | * @bus: the BUS |
| 3629 | * |
| 3630 | * Create PCM information for each codec included in the bus. |
| 3631 | * |
| 3632 | * The build_pcms codec patch is requested to set up codec->num_pcms and |
| 3633 | * codec->pcm_info properly. The array is referred by the top-level driver |
| 3634 | * to create its PCM instances. |
| 3635 | * The allocated codec->pcm_info should be released in codec->patch_ops.free |
| 3636 | * callback. |
| 3637 | * |
| 3638 | * At least, substreams, channels_min and channels_max must be filled for |
| 3639 | * each stream. substreams = 0 indicates that the stream doesn't exist. |
| 3640 | * When rates and/or formats are zero, the supported values are queried |
| 3641 | * from the given nid. The nid is used also by the default ops.prepare |
| 3642 | * and ops.cleanup callbacks. |
| 3643 | * |
| 3644 | * The driver needs to call ops.open in its open callback. Similarly, |
| 3645 | * ops.close is supposed to be called in the close callback. |
| 3646 | * ops.prepare should be called in the prepare or hw_params callback |
| 3647 | * with the proper parameters for set up. |
| 3648 | * ops.cleanup should be called in hw_free for clean up of streams. |
| 3649 | * |
| 3650 | * This function returns 0 if successfull, or a negative error code. |
| 3651 | */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3652 | int __devinit snd_hda_build_pcms(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3654 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3656 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 3657 | int err = snd_hda_codec_build_pcms(codec); |
| 3658 | if (err < 0) |
| 3659 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | return 0; |
| 3662 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3663 | EXPORT_SYMBOL_HDA(snd_hda_build_pcms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | /** |
| 3666 | * snd_hda_check_board_config - compare the current codec with the config table |
| 3667 | * @codec: the HDA codec |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3668 | * @num_configs: number of config enums |
| 3669 | * @models: array of model name strings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | * @tbl: configuration table, terminated by null entries |
| 3671 | * |
| 3672 | * Compares the modelname or PCI subsystem id of the current codec with the |
| 3673 | * given configuration table. If a matching entry is found, returns its |
| 3674 | * config value (supposed to be 0 or positive). |
| 3675 | * |
| 3676 | * If no entries are matching, the function returns a negative value. |
| 3677 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 3678 | int snd_hda_check_board_config(struct hda_codec *codec, |
| 3679 | int num_configs, const char **models, |
| 3680 | const struct snd_pci_quirk *tbl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | { |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3682 | if (codec->modelname && models) { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3683 | int i; |
| 3684 | for (i = 0; i < num_configs; i++) { |
| 3685 | if (models[i] && |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 3686 | !strcmp(codec->modelname, models[i])) { |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3687 | snd_printd(KERN_INFO "hda_codec: model '%s' is " |
| 3688 | "selected\n", models[i]); |
| 3689 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | } |
| 3693 | |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3694 | if (!codec->bus->pci || !tbl) |
| 3695 | return -1; |
| 3696 | |
| 3697 | tbl = snd_pci_quirk_lookup(codec->bus->pci, tbl); |
| 3698 | if (!tbl) |
| 3699 | return -1; |
| 3700 | if (tbl->value >= 0 && tbl->value < num_configs) { |
Takashi Iwai | 62cf872 | 2008-05-20 12:15:15 +0200 | [diff] [blame] | 3701 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3702 | char tmp[10]; |
| 3703 | const char *model = NULL; |
| 3704 | if (models) |
| 3705 | model = models[tbl->value]; |
| 3706 | if (!model) { |
| 3707 | sprintf(tmp, "#%d", tbl->value); |
| 3708 | model = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | } |
Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 3710 | snd_printdd(KERN_INFO "hda_codec: model '%s' is selected " |
| 3711 | "for config %x:%x (%s)\n", |
| 3712 | model, tbl->subvendor, tbl->subdevice, |
| 3713 | (tbl->name ? tbl->name : "Unknown device")); |
| 3714 | #endif |
| 3715 | return tbl->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | } |
| 3717 | return -1; |
| 3718 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3719 | EXPORT_SYMBOL_HDA(snd_hda_check_board_config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | |
| 3721 | /** |
Mauro Carvalho Chehab | 2eda344 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 3722 | * snd_hda_check_board_codec_sid_config - compare the current codec |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3723 | subsystem ID with the |
| 3724 | config table |
Mauro Carvalho Chehab | 2eda344 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 3725 | |
| 3726 | This is important for Gateway notebooks with SB450 HDA Audio |
| 3727 | where the vendor ID of the PCI device is: |
| 3728 | ATI Technologies Inc SB450 HDA Audio [1002:437b] |
| 3729 | and the vendor/subvendor are found only at the codec. |
| 3730 | |
| 3731 | * @codec: the HDA codec |
| 3732 | * @num_configs: number of config enums |
| 3733 | * @models: array of model name strings |
| 3734 | * @tbl: configuration table, terminated by null entries |
| 3735 | * |
| 3736 | * Compares the modelname or PCI subsystem id of the current codec with the |
| 3737 | * given configuration table. If a matching entry is found, returns its |
| 3738 | * config value (supposed to be 0 or positive). |
| 3739 | * |
| 3740 | * If no entries are matching, the function returns a negative value. |
| 3741 | */ |
| 3742 | int snd_hda_check_board_codec_sid_config(struct hda_codec *codec, |
| 3743 | int num_configs, const char **models, |
| 3744 | const struct snd_pci_quirk *tbl) |
| 3745 | { |
| 3746 | const struct snd_pci_quirk *q; |
| 3747 | |
| 3748 | /* Search for codec ID */ |
| 3749 | for (q = tbl; q->subvendor; q++) { |
| 3750 | unsigned long vendorid = (q->subdevice) | (q->subvendor << 16); |
| 3751 | |
| 3752 | if (vendorid == codec->subsystem_id) |
| 3753 | break; |
| 3754 | } |
| 3755 | |
| 3756 | if (!q->subvendor) |
| 3757 | return -1; |
| 3758 | |
| 3759 | tbl = q; |
| 3760 | |
| 3761 | if (tbl->value >= 0 && tbl->value < num_configs) { |
Takashi Iwai | d94ff6b | 2009-09-02 00:20:21 +0200 | [diff] [blame] | 3762 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Mauro Carvalho Chehab | 2eda344 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 3763 | char tmp[10]; |
| 3764 | const char *model = NULL; |
| 3765 | if (models) |
| 3766 | model = models[tbl->value]; |
| 3767 | if (!model) { |
| 3768 | sprintf(tmp, "#%d", tbl->value); |
| 3769 | model = tmp; |
| 3770 | } |
| 3771 | snd_printdd(KERN_INFO "hda_codec: model '%s' is selected " |
| 3772 | "for config %x:%x (%s)\n", |
| 3773 | model, tbl->subvendor, tbl->subdevice, |
| 3774 | (tbl->name ? tbl->name : "Unknown device")); |
| 3775 | #endif |
| 3776 | return tbl->value; |
| 3777 | } |
| 3778 | return -1; |
| 3779 | } |
| 3780 | EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config); |
| 3781 | |
| 3782 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | * snd_hda_add_new_ctls - create controls from the array |
| 3784 | * @codec: the HDA codec |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3785 | * @knew: the array of struct snd_kcontrol_new |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | * |
| 3787 | * This helper function creates and add new controls in the given array. |
| 3788 | * The array must be terminated with an empty entry as terminator. |
| 3789 | * |
| 3790 | * Returns 0 if successful, or a negative error code. |
| 3791 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 3792 | int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | { |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 3794 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | |
| 3796 | for (; knew->name; knew++) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3797 | struct snd_kcontrol *kctl; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3798 | if (knew->iface == -1) /* skip this codec private value */ |
| 3799 | continue; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3800 | kctl = snd_ctl_new1(knew, codec); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3801 | if (!kctl) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3802 | return -ENOMEM; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 3803 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3804 | if (err < 0) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3805 | if (!codec->addr) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3806 | return err; |
| 3807 | kctl = snd_ctl_new1(knew, codec); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3808 | if (!kctl) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3809 | return -ENOMEM; |
| 3810 | kctl->id.device = codec->addr; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 3811 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3812 | if (err < 0) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3813 | return err; |
| 3814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | } |
| 3816 | return 0; |
| 3817 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3818 | EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3820 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3821 | static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
| 3822 | unsigned int power_state); |
| 3823 | |
| 3824 | static void hda_power_work(struct work_struct *work) |
| 3825 | { |
| 3826 | struct hda_codec *codec = |
| 3827 | container_of(work, struct hda_codec, power_work.work); |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3828 | struct hda_bus *bus = codec->bus; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3829 | |
Maxim Levitsky | 2e49246 | 2007-09-03 15:26:57 +0200 | [diff] [blame] | 3830 | if (!codec->power_on || codec->power_count) { |
| 3831 | codec->power_transition = 0; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3832 | return; |
Maxim Levitsky | 2e49246 | 2007-09-03 15:26:57 +0200 | [diff] [blame] | 3833 | } |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3834 | |
| 3835 | hda_call_codec_suspend(codec); |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3836 | if (bus->ops.pm_notify) |
| 3837 | bus->ops.pm_notify(bus); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | static void hda_keep_power_on(struct hda_codec *codec) |
| 3841 | { |
| 3842 | codec->power_count++; |
| 3843 | codec->power_on = 1; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3844 | codec->power_jiffies = jiffies; |
| 3845 | } |
| 3846 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3847 | /* update the power on/off account with the current jiffies */ |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3848 | void snd_hda_update_power_acct(struct hda_codec *codec) |
| 3849 | { |
| 3850 | unsigned long delta = jiffies - codec->power_jiffies; |
| 3851 | if (codec->power_on) |
| 3852 | codec->power_on_acct += delta; |
| 3853 | else |
| 3854 | codec->power_off_acct += delta; |
| 3855 | codec->power_jiffies += delta; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3856 | } |
| 3857 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3858 | /** |
| 3859 | * snd_hda_power_up - Power-up the codec |
| 3860 | * @codec: HD-audio codec |
| 3861 | * |
| 3862 | * Increment the power-up counter and power up the hardware really when |
| 3863 | * not turned on yet. |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3864 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3865 | void snd_hda_power_up(struct hda_codec *codec) |
| 3866 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3867 | struct hda_bus *bus = codec->bus; |
| 3868 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3869 | codec->power_count++; |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3870 | if (codec->power_on || codec->power_transition) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3871 | return; |
| 3872 | |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3873 | snd_hda_update_power_acct(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3874 | codec->power_on = 1; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3875 | codec->power_jiffies = jiffies; |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3876 | if (bus->ops.pm_notify) |
| 3877 | bus->ops.pm_notify(bus); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3878 | hda_call_codec_resume(codec); |
| 3879 | cancel_delayed_work(&codec->power_work); |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3880 | codec->power_transition = 0; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3881 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3882 | EXPORT_SYMBOL_HDA(snd_hda_power_up); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 3883 | |
| 3884 | #define power_save(codec) \ |
| 3885 | ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3886 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3887 | /** |
| 3888 | * snd_hda_power_down - Power-down the codec |
| 3889 | * @codec: HD-audio codec |
| 3890 | * |
| 3891 | * Decrement the power-up counter and schedules the power-off work if |
| 3892 | * the counter rearches to zero. |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3893 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3894 | void snd_hda_power_down(struct hda_codec *codec) |
| 3895 | { |
| 3896 | --codec->power_count; |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3897 | if (!codec->power_on || codec->power_count || codec->power_transition) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3898 | return; |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 3899 | if (power_save(codec)) { |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3900 | codec->power_transition = 1; /* avoid reentrance */ |
Takashi Iwai | c107b41 | 2009-01-13 17:46:37 +0100 | [diff] [blame] | 3901 | queue_delayed_work(codec->bus->workq, &codec->power_work, |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 3902 | msecs_to_jiffies(power_save(codec) * 1000)); |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3903 | } |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3904 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3905 | EXPORT_SYMBOL_HDA(snd_hda_power_down); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3906 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3907 | /** |
| 3908 | * snd_hda_check_amp_list_power - Check the amp list and update the power |
| 3909 | * @codec: HD-audio codec |
| 3910 | * @check: the object containing an AMP list and the status |
| 3911 | * @nid: NID to check / update |
| 3912 | * |
| 3913 | * Check whether the given NID is in the amp list. If it's in the list, |
| 3914 | * check the current AMP status, and update the the power-status according |
| 3915 | * to the mute status. |
| 3916 | * |
| 3917 | * This function is supposed to be set or called from the check_power_status |
| 3918 | * patch ops. |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3919 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3920 | int snd_hda_check_amp_list_power(struct hda_codec *codec, |
| 3921 | struct hda_loopback_check *check, |
| 3922 | hda_nid_t nid) |
| 3923 | { |
| 3924 | struct hda_amp_list *p; |
| 3925 | int ch, v; |
| 3926 | |
| 3927 | if (!check->amplist) |
| 3928 | return 0; |
| 3929 | for (p = check->amplist; p->nid; p++) { |
| 3930 | if (p->nid == nid) |
| 3931 | break; |
| 3932 | } |
| 3933 | if (!p->nid) |
| 3934 | return 0; /* nothing changed */ |
| 3935 | |
| 3936 | for (p = check->amplist; p->nid; p++) { |
| 3937 | for (ch = 0; ch < 2; ch++) { |
| 3938 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, |
| 3939 | p->idx); |
| 3940 | if (!(v & HDA_AMP_MUTE) && v > 0) { |
| 3941 | if (!check->power_on) { |
| 3942 | check->power_on = 1; |
| 3943 | snd_hda_power_up(codec); |
| 3944 | } |
| 3945 | return 1; |
| 3946 | } |
| 3947 | } |
| 3948 | } |
| 3949 | if (check->power_on) { |
| 3950 | check->power_on = 0; |
| 3951 | snd_hda_power_down(codec); |
| 3952 | } |
| 3953 | return 0; |
| 3954 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3955 | EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3956 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3958 | /* |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 3959 | * Channel mode helper |
| 3960 | */ |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3961 | |
| 3962 | /** |
| 3963 | * snd_hda_ch_mode_info - Info callback helper for the channel mode enum |
| 3964 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3965 | int snd_hda_ch_mode_info(struct hda_codec *codec, |
| 3966 | struct snd_ctl_elem_info *uinfo, |
| 3967 | const struct hda_channel_mode *chmode, |
| 3968 | int num_chmodes) |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 3969 | { |
| 3970 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3971 | uinfo->count = 1; |
| 3972 | uinfo->value.enumerated.items = num_chmodes; |
| 3973 | if (uinfo->value.enumerated.item >= num_chmodes) |
| 3974 | uinfo->value.enumerated.item = num_chmodes - 1; |
| 3975 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 3976 | chmode[uinfo->value.enumerated.item].channels); |
| 3977 | return 0; |
| 3978 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 3979 | EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 3980 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3981 | /** |
| 3982 | * snd_hda_ch_mode_get - Get callback helper for the channel mode enum |
| 3983 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3984 | int snd_hda_ch_mode_get(struct hda_codec *codec, |
| 3985 | struct snd_ctl_elem_value *ucontrol, |
| 3986 | const struct hda_channel_mode *chmode, |
| 3987 | int num_chmodes, |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 3988 | int max_channels) |
| 3989 | { |
| 3990 | int i; |
| 3991 | |
| 3992 | for (i = 0; i < num_chmodes; i++) { |
| 3993 | if (max_channels == chmode[i].channels) { |
| 3994 | ucontrol->value.enumerated.item[0] = i; |
| 3995 | break; |
| 3996 | } |
| 3997 | } |
| 3998 | return 0; |
| 3999 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4000 | EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4001 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4002 | /** |
| 4003 | * snd_hda_ch_mode_put - Put callback helper for the channel mode enum |
| 4004 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4005 | int snd_hda_ch_mode_put(struct hda_codec *codec, |
| 4006 | struct snd_ctl_elem_value *ucontrol, |
| 4007 | const struct hda_channel_mode *chmode, |
| 4008 | int num_chmodes, |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4009 | int *max_channelsp) |
| 4010 | { |
| 4011 | unsigned int mode; |
| 4012 | |
| 4013 | mode = ucontrol->value.enumerated.item[0]; |
Takashi Iwai | 68ea7b2 | 2007-11-15 15:54:38 +0100 | [diff] [blame] | 4014 | if (mode >= num_chmodes) |
| 4015 | return -EINVAL; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4016 | if (*max_channelsp == chmode[mode].channels) |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4017 | return 0; |
| 4018 | /* change the current channel setting */ |
| 4019 | *max_channelsp = chmode[mode].channels; |
| 4020 | if (chmode[mode].sequence) |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4021 | snd_hda_sequence_write_cache(codec, chmode[mode].sequence); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4022 | return 1; |
| 4023 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4024 | EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | /* |
| 4027 | * input MUX helper |
| 4028 | */ |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4029 | |
| 4030 | /** |
| 4031 | * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum |
| 4032 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4033 | int snd_hda_input_mux_info(const struct hda_input_mux *imux, |
| 4034 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | { |
| 4036 | unsigned int index; |
| 4037 | |
| 4038 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4039 | uinfo->count = 1; |
| 4040 | uinfo->value.enumerated.items = imux->num_items; |
Takashi Iwai | 5513b0c | 2007-10-09 11:58:41 +0200 | [diff] [blame] | 4041 | if (!imux->num_items) |
| 4042 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | index = uinfo->value.enumerated.item; |
| 4044 | if (index >= imux->num_items) |
| 4045 | index = imux->num_items - 1; |
| 4046 | strcpy(uinfo->value.enumerated.name, imux->items[index].label); |
| 4047 | return 0; |
| 4048 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4049 | EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4051 | /** |
| 4052 | * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum |
| 4053 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4054 | int snd_hda_input_mux_put(struct hda_codec *codec, |
| 4055 | const struct hda_input_mux *imux, |
| 4056 | struct snd_ctl_elem_value *ucontrol, |
| 4057 | hda_nid_t nid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | unsigned int *cur_val) |
| 4059 | { |
| 4060 | unsigned int idx; |
| 4061 | |
Takashi Iwai | 5513b0c | 2007-10-09 11:58:41 +0200 | [diff] [blame] | 4062 | if (!imux->num_items) |
| 4063 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | idx = ucontrol->value.enumerated.item[0]; |
| 4065 | if (idx >= imux->num_items) |
| 4066 | idx = imux->num_items - 1; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4067 | if (*cur_val == idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | return 0; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4069 | snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, |
| 4070 | imux->items[idx].index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | *cur_val = idx; |
| 4072 | return 1; |
| 4073 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4074 | EXPORT_SYMBOL_HDA(snd_hda_input_mux_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | |
| 4076 | |
| 4077 | /* |
| 4078 | * Multi-channel / digital-out PCM helper functions |
| 4079 | */ |
| 4080 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4081 | /* setup SPDIF output stream */ |
| 4082 | static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, |
| 4083 | unsigned int stream_tag, unsigned int format) |
| 4084 | { |
| 4085 | /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4086 | if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4087 | set_dig_out_convert(codec, nid, |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4088 | codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff, |
| 4089 | -1); |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4090 | snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4091 | if (codec->slave_dig_outs) { |
| 4092 | hda_nid_t *d; |
| 4093 | for (d = codec->slave_dig_outs; *d; d++) |
| 4094 | snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, |
| 4095 | format); |
Matthew Ranostay | de51ca1 | 2008-09-07 14:31:40 -0400 | [diff] [blame] | 4096 | } |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4097 | /* turn on again (if needed) */ |
| 4098 | if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) |
| 4099 | set_dig_out_convert(codec, nid, |
| 4100 | codec->spdif_ctls & 0xff, -1); |
| 4101 | } |
Matthew Ranostay | de51ca1 | 2008-09-07 14:31:40 -0400 | [diff] [blame] | 4102 | |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4103 | static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) |
| 4104 | { |
| 4105 | snd_hda_codec_cleanup_stream(codec, nid); |
| 4106 | if (codec->slave_dig_outs) { |
| 4107 | hda_nid_t *d; |
| 4108 | for (d = codec->slave_dig_outs; *d; d++) |
| 4109 | snd_hda_codec_cleanup_stream(codec, *d); |
| 4110 | } |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4111 | } |
| 4112 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4113 | /** |
| 4114 | * snd_hda_bus_reboot_notify - call the reboot notifier of each codec |
| 4115 | * @bus: HD-audio bus |
| 4116 | */ |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 4117 | void snd_hda_bus_reboot_notify(struct hda_bus *bus) |
| 4118 | { |
| 4119 | struct hda_codec *codec; |
| 4120 | |
| 4121 | if (!bus) |
| 4122 | return; |
| 4123 | list_for_each_entry(codec, &bus->codec_list, list) { |
| 4124 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4125 | if (!codec->power_on) |
| 4126 | continue; |
| 4127 | #endif |
| 4128 | if (codec->patch_ops.reboot_notify) |
| 4129 | codec->patch_ops.reboot_notify(codec); |
| 4130 | } |
| 4131 | } |
Takashi Iwai | 8f217a2 | 2009-11-10 18:26:12 +0100 | [diff] [blame] | 4132 | EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify); |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 4133 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4134 | /** |
| 4135 | * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4137 | int snd_hda_multi_out_dig_open(struct hda_codec *codec, |
| 4138 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4140 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | 5930ca4 | 2007-04-16 11:23:56 +0200 | [diff] [blame] | 4141 | if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) |
| 4142 | /* already opened as analog dup; reset it once */ |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4143 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | mout->dig_out_used = HDA_DIG_EXCLUSIVE; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4145 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | return 0; |
| 4147 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4148 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4150 | /** |
| 4151 | * snd_hda_multi_out_dig_prepare - prepare the digital out stream |
| 4152 | */ |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4153 | int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, |
| 4154 | struct hda_multi_out *mout, |
| 4155 | unsigned int stream_tag, |
| 4156 | unsigned int format, |
| 4157 | struct snd_pcm_substream *substream) |
| 4158 | { |
| 4159 | mutex_lock(&codec->spdif_mutex); |
| 4160 | setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); |
| 4161 | mutex_unlock(&codec->spdif_mutex); |
| 4162 | return 0; |
| 4163 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4164 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4165 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4166 | /** |
| 4167 | * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream |
| 4168 | */ |
Takashi Iwai | 9411e21 | 2009-02-13 11:32:28 +0100 | [diff] [blame] | 4169 | int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, |
| 4170 | struct hda_multi_out *mout) |
| 4171 | { |
| 4172 | mutex_lock(&codec->spdif_mutex); |
| 4173 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
| 4174 | mutex_unlock(&codec->spdif_mutex); |
| 4175 | return 0; |
| 4176 | } |
| 4177 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); |
| 4178 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4179 | /** |
| 4180 | * snd_hda_multi_out_dig_close - release the digital out stream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4182 | int snd_hda_multi_out_dig_close(struct hda_codec *codec, |
| 4183 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4185 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | mout->dig_out_used = 0; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4187 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | return 0; |
| 4189 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4190 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4192 | /** |
| 4193 | * snd_hda_multi_out_analog_open - open analog outputs |
| 4194 | * |
| 4195 | * Open analog outputs and set up the hw-constraints. |
| 4196 | * If the digital outputs can be opened as slave, open the digital |
| 4197 | * outputs, too. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4199 | int snd_hda_multi_out_analog_open(struct hda_codec *codec, |
| 4200 | struct hda_multi_out *mout, |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 4201 | struct snd_pcm_substream *substream, |
| 4202 | struct hda_pcm_stream *hinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | { |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 4204 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 4205 | runtime->hw.channels_max = mout->max_channels; |
| 4206 | if (mout->dig_out_nid) { |
| 4207 | if (!mout->analog_rates) { |
| 4208 | mout->analog_rates = hinfo->rates; |
| 4209 | mout->analog_formats = hinfo->formats; |
| 4210 | mout->analog_maxbps = hinfo->maxbps; |
| 4211 | } else { |
| 4212 | runtime->hw.rates = mout->analog_rates; |
| 4213 | runtime->hw.formats = mout->analog_formats; |
| 4214 | hinfo->maxbps = mout->analog_maxbps; |
| 4215 | } |
| 4216 | if (!mout->spdif_rates) { |
| 4217 | snd_hda_query_supported_pcm(codec, mout->dig_out_nid, |
| 4218 | &mout->spdif_rates, |
| 4219 | &mout->spdif_formats, |
| 4220 | &mout->spdif_maxbps); |
| 4221 | } |
| 4222 | mutex_lock(&codec->spdif_mutex); |
| 4223 | if (mout->share_spdif) { |
Takashi Iwai | 022b466 | 2009-07-03 23:03:30 +0200 | [diff] [blame] | 4224 | if ((runtime->hw.rates & mout->spdif_rates) && |
| 4225 | (runtime->hw.formats & mout->spdif_formats)) { |
| 4226 | runtime->hw.rates &= mout->spdif_rates; |
| 4227 | runtime->hw.formats &= mout->spdif_formats; |
| 4228 | if (mout->spdif_maxbps < hinfo->maxbps) |
| 4229 | hinfo->maxbps = mout->spdif_maxbps; |
| 4230 | } else { |
| 4231 | mout->share_spdif = 0; |
| 4232 | /* FIXME: need notify? */ |
| 4233 | } |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 4234 | } |
Frederik Deweerdt | eaa9985 | 2008-04-14 13:11:44 +0200 | [diff] [blame] | 4235 | mutex_unlock(&codec->spdif_mutex); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 4236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | return snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 4238 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
| 4239 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4240 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4242 | /** |
| 4243 | * snd_hda_multi_out_analog_prepare - Preapre the analog outputs. |
| 4244 | * |
| 4245 | * Set up the i/o for analog out. |
| 4246 | * When the digital out is available, copy the front out to digital out, too. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4248 | int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, |
| 4249 | struct hda_multi_out *mout, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | unsigned int stream_tag, |
| 4251 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4252 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | { |
| 4254 | hda_nid_t *nids = mout->dac_nids; |
| 4255 | int chs = substream->runtime->channels; |
| 4256 | int i; |
| 4257 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4258 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 4259 | if (mout->dig_out_nid && mout->share_spdif && |
| 4260 | mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | if (chs == 2 && |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4262 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 4263 | format) && |
| 4264 | !(codec->spdif_status & IEC958_AES0_NONAUDIO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 4266 | setup_dig_out_stream(codec, mout->dig_out_nid, |
| 4267 | stream_tag, format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | } else { |
| 4269 | mout->dig_out_used = 0; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4270 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | } |
| 4272 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4273 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | |
| 4275 | /* front */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4276 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 4277 | 0, format); |
Takashi Iwai | d29240c | 2007-10-26 12:35:56 +0200 | [diff] [blame] | 4278 | if (!mout->no_share_stream && |
| 4279 | mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | /* headphone out will just decode front left/right (stereo) */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4281 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 4282 | 0, format); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4283 | /* extra outputs copied from front */ |
| 4284 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
Takashi Iwai | d29240c | 2007-10-26 12:35:56 +0200 | [diff] [blame] | 4285 | if (!mout->no_share_stream && mout->extra_out_nid[i]) |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4286 | snd_hda_codec_setup_stream(codec, |
| 4287 | mout->extra_out_nid[i], |
| 4288 | stream_tag, 0, format); |
| 4289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | /* surrounds */ |
| 4291 | for (i = 1; i < mout->num_dacs; i++) { |
Takashi Iwai | 4b3acaf | 2005-06-10 19:48:10 +0200 | [diff] [blame] | 4292 | if (chs >= (i + 1) * 2) /* independent out */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4293 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 4294 | i * 2, format); |
Takashi Iwai | d29240c | 2007-10-26 12:35:56 +0200 | [diff] [blame] | 4295 | else if (!mout->no_share_stream) /* copy front */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4296 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 4297 | 0, format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | } |
| 4299 | return 0; |
| 4300 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4301 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4303 | /** |
| 4304 | * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4306 | int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, |
| 4307 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | { |
| 4309 | hda_nid_t *nids = mout->dac_nids; |
| 4310 | int i; |
| 4311 | |
| 4312 | for (i = 0; i < mout->num_dacs; i++) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 4313 | snd_hda_codec_cleanup_stream(codec, nids[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | if (mout->hp_nid) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 4315 | snd_hda_codec_cleanup_stream(codec, mout->hp_nid); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4316 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 4317 | if (mout->extra_out_nid[i]) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 4318 | snd_hda_codec_cleanup_stream(codec, |
| 4319 | mout->extra_out_nid[i]); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4320 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 4322 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | mout->dig_out_used = 0; |
| 4324 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 4325 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | return 0; |
| 4327 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4328 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4330 | /* |
Wu Fengguang | 6b34500 | 2008-10-07 14:21:41 +0800 | [diff] [blame] | 4331 | * Helper for automatic pin configuration |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4332 | */ |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 4333 | |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 4334 | static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list) |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 4335 | { |
| 4336 | for (; *list; list++) |
| 4337 | if (*list == nid) |
| 4338 | return 1; |
| 4339 | return 0; |
| 4340 | } |
| 4341 | |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4342 | |
| 4343 | /* |
| 4344 | * Sort an associated group of pins according to their sequence numbers. |
| 4345 | */ |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4346 | static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences, |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4347 | int num_pins) |
| 4348 | { |
| 4349 | int i, j; |
| 4350 | short seq; |
| 4351 | hda_nid_t nid; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4352 | |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4353 | for (i = 0; i < num_pins; i++) { |
| 4354 | for (j = i + 1; j < num_pins; j++) { |
| 4355 | if (sequences[i] > sequences[j]) { |
| 4356 | seq = sequences[i]; |
| 4357 | sequences[i] = sequences[j]; |
| 4358 | sequences[j] = seq; |
| 4359 | nid = pins[i]; |
| 4360 | pins[i] = pins[j]; |
| 4361 | pins[j] = nid; |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4368 | /* |
| 4369 | * Parse all pin widgets and store the useful pin nids to cfg |
| 4370 | * |
| 4371 | * The number of line-outs or any primary output is stored in line_outs, |
| 4372 | * and the corresponding output pins are assigned to line_out_pins[], |
| 4373 | * in the order of front, rear, CLFE, side, ... |
| 4374 | * |
| 4375 | * If more extra outputs (speaker and headphone) are found, the pins are |
Takashi Iwai | eb06ed8 | 2006-09-20 17:10:27 +0200 | [diff] [blame] | 4376 | * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4377 | * is detected, one of speaker of HP pins is assigned as the primary |
| 4378 | * output, i.e. to line_out_pins[0]. So, line_outs is always positive |
| 4379 | * if any analog output exists. |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4380 | * |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4381 | * The analog input pins are assigned to input_pins array. |
| 4382 | * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, |
| 4383 | * respectively. |
| 4384 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 4385 | int snd_hda_parse_pin_def_config(struct hda_codec *codec, |
| 4386 | struct auto_pin_cfg *cfg, |
| 4387 | hda_nid_t *ignore_nids) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4388 | { |
Takashi Iwai | 0ef6ce7 | 2008-01-22 15:35:37 +0100 | [diff] [blame] | 4389 | hda_nid_t nid, end_nid; |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4390 | short seq, assoc_line_out, assoc_speaker; |
| 4391 | short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; |
| 4392 | short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4393 | short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4394 | |
| 4395 | memset(cfg, 0, sizeof(*cfg)); |
| 4396 | |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4397 | memset(sequences_line_out, 0, sizeof(sequences_line_out)); |
| 4398 | memset(sequences_speaker, 0, sizeof(sequences_speaker)); |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4399 | memset(sequences_hp, 0, sizeof(sequences_hp)); |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4400 | assoc_line_out = assoc_speaker = 0; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4401 | |
Takashi Iwai | 0ef6ce7 | 2008-01-22 15:35:37 +0100 | [diff] [blame] | 4402 | end_nid = codec->start_nid + codec->num_nodes; |
| 4403 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 4404 | unsigned int wid_caps = get_wcaps(codec, nid); |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 4405 | unsigned int wid_type = get_wcaps_type(wid_caps); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4406 | unsigned int def_conf; |
| 4407 | short assoc, loc; |
| 4408 | |
| 4409 | /* read all default configuration for pin complex */ |
| 4410 | if (wid_type != AC_WID_PIN) |
| 4411 | continue; |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 4412 | /* ignore the given nids (e.g. pc-beep returns error) */ |
| 4413 | if (ignore_nids && is_in_nid_list(nid, ignore_nids)) |
| 4414 | continue; |
| 4415 | |
Takashi Iwai | c17a1ab | 2009-02-23 09:28:12 +0100 | [diff] [blame] | 4416 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4417 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) |
| 4418 | continue; |
| 4419 | loc = get_defcfg_location(def_conf); |
| 4420 | switch (get_defcfg_device(def_conf)) { |
| 4421 | case AC_JACK_LINE_OUT: |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4422 | seq = get_defcfg_sequence(def_conf); |
| 4423 | assoc = get_defcfg_association(def_conf); |
Matthew Ranostay | 90da78b | 2008-01-24 11:48:01 +0100 | [diff] [blame] | 4424 | |
| 4425 | if (!(wid_caps & AC_WCAP_STEREO)) |
| 4426 | if (!cfg->mono_out_pin) |
| 4427 | cfg->mono_out_pin = nid; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4428 | if (!assoc) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4429 | continue; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4430 | if (!assoc_line_out) |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4431 | assoc_line_out = assoc; |
| 4432 | else if (assoc_line_out != assoc) |
| 4433 | continue; |
| 4434 | if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) |
| 4435 | continue; |
| 4436 | cfg->line_out_pins[cfg->line_outs] = nid; |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4437 | sequences_line_out[cfg->line_outs] = seq; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4438 | cfg->line_outs++; |
| 4439 | break; |
Takashi Iwai | 8d88bc3 | 2005-11-17 11:09:23 +0100 | [diff] [blame] | 4440 | case AC_JACK_SPEAKER: |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4441 | seq = get_defcfg_sequence(def_conf); |
| 4442 | assoc = get_defcfg_association(def_conf); |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4443 | if (!assoc) |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4444 | continue; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4445 | if (!assoc_speaker) |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4446 | assoc_speaker = assoc; |
| 4447 | else if (assoc_speaker != assoc) |
| 4448 | continue; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4449 | if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) |
| 4450 | continue; |
| 4451 | cfg->speaker_pins[cfg->speaker_outs] = nid; |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4452 | sequences_speaker[cfg->speaker_outs] = seq; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4453 | cfg->speaker_outs++; |
Takashi Iwai | 8d88bc3 | 2005-11-17 11:09:23 +0100 | [diff] [blame] | 4454 | break; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4455 | case AC_JACK_HP_OUT: |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4456 | seq = get_defcfg_sequence(def_conf); |
| 4457 | assoc = get_defcfg_association(def_conf); |
Takashi Iwai | eb06ed8 | 2006-09-20 17:10:27 +0200 | [diff] [blame] | 4458 | if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) |
| 4459 | continue; |
| 4460 | cfg->hp_pins[cfg->hp_outs] = nid; |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4461 | sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; |
Takashi Iwai | eb06ed8 | 2006-09-20 17:10:27 +0200 | [diff] [blame] | 4462 | cfg->hp_outs++; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4463 | break; |
Takashi Iwai | 314634b | 2006-09-21 11:56:18 +0200 | [diff] [blame] | 4464 | case AC_JACK_MIC_IN: { |
| 4465 | int preferred, alt; |
Kailang Yang | 6ff86a3 | 2010-03-19 11:14:36 +0100 | [diff] [blame] | 4466 | if (loc == AC_JACK_LOC_FRONT || |
| 4467 | (loc & 0x30) == AC_JACK_LOC_INTERNAL) { |
Takashi Iwai | 314634b | 2006-09-21 11:56:18 +0200 | [diff] [blame] | 4468 | preferred = AUTO_PIN_FRONT_MIC; |
| 4469 | alt = AUTO_PIN_MIC; |
| 4470 | } else { |
| 4471 | preferred = AUTO_PIN_MIC; |
| 4472 | alt = AUTO_PIN_FRONT_MIC; |
| 4473 | } |
| 4474 | if (!cfg->input_pins[preferred]) |
| 4475 | cfg->input_pins[preferred] = nid; |
| 4476 | else if (!cfg->input_pins[alt]) |
| 4477 | cfg->input_pins[alt] = nid; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4478 | break; |
Takashi Iwai | 314634b | 2006-09-21 11:56:18 +0200 | [diff] [blame] | 4479 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4480 | case AC_JACK_LINE_IN: |
| 4481 | if (loc == AC_JACK_LOC_FRONT) |
| 4482 | cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid; |
| 4483 | else |
| 4484 | cfg->input_pins[AUTO_PIN_LINE] = nid; |
| 4485 | break; |
| 4486 | case AC_JACK_CD: |
| 4487 | cfg->input_pins[AUTO_PIN_CD] = nid; |
| 4488 | break; |
| 4489 | case AC_JACK_AUX: |
| 4490 | cfg->input_pins[AUTO_PIN_AUX] = nid; |
| 4491 | break; |
| 4492 | case AC_JACK_SPDIF_OUT: |
Takashi Iwai | 1b52ae7 | 2009-01-20 17:17:29 +0100 | [diff] [blame] | 4493 | case AC_JACK_DIG_OTHER_OUT: |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 4494 | if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) |
| 4495 | continue; |
| 4496 | cfg->dig_out_pins[cfg->dig_outs] = nid; |
| 4497 | cfg->dig_out_type[cfg->dig_outs] = |
| 4498 | (loc == AC_JACK_LOC_HDMI) ? |
| 4499 | HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; |
| 4500 | cfg->dig_outs++; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4501 | break; |
| 4502 | case AC_JACK_SPDIF_IN: |
Takashi Iwai | 1b52ae7 | 2009-01-20 17:17:29 +0100 | [diff] [blame] | 4503 | case AC_JACK_DIG_OTHER_IN: |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4504 | cfg->dig_in_pin = nid; |
Takashi Iwai | 2297bd6 | 2009-01-20 18:24:13 +0100 | [diff] [blame] | 4505 | if (loc == AC_JACK_LOC_HDMI) |
| 4506 | cfg->dig_in_type = HDA_PCM_TYPE_HDMI; |
| 4507 | else |
| 4508 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4509 | break; |
| 4510 | } |
| 4511 | } |
| 4512 | |
Takashi Iwai | 5832fcf8 | 2008-02-12 18:30:12 +0100 | [diff] [blame] | 4513 | /* FIX-UP: |
| 4514 | * If no line-out is defined but multiple HPs are found, |
| 4515 | * some of them might be the real line-outs. |
| 4516 | */ |
| 4517 | if (!cfg->line_outs && cfg->hp_outs > 1) { |
| 4518 | int i = 0; |
| 4519 | while (i < cfg->hp_outs) { |
| 4520 | /* The real HPs should have the sequence 0x0f */ |
| 4521 | if ((sequences_hp[i] & 0x0f) == 0x0f) { |
| 4522 | i++; |
| 4523 | continue; |
| 4524 | } |
| 4525 | /* Move it to the line-out table */ |
| 4526 | cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i]; |
| 4527 | sequences_line_out[cfg->line_outs] = sequences_hp[i]; |
| 4528 | cfg->line_outs++; |
| 4529 | cfg->hp_outs--; |
| 4530 | memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1, |
| 4531 | sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i)); |
| 4532 | memmove(sequences_hp + i - 1, sequences_hp + i, |
| 4533 | sizeof(sequences_hp[0]) * (cfg->hp_outs - i)); |
| 4534 | } |
| 4535 | } |
| 4536 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4537 | /* sort by sequence */ |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4538 | sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, |
| 4539 | cfg->line_outs); |
| 4540 | sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, |
| 4541 | cfg->speaker_outs); |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4542 | sort_pins_by_sequence(cfg->hp_pins, sequences_hp, |
| 4543 | cfg->hp_outs); |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4544 | |
Takashi Iwai | f889fa9 | 2007-10-31 15:49:32 +0100 | [diff] [blame] | 4545 | /* if we have only one mic, make it AUTO_PIN_MIC */ |
| 4546 | if (!cfg->input_pins[AUTO_PIN_MIC] && |
| 4547 | cfg->input_pins[AUTO_PIN_FRONT_MIC]) { |
| 4548 | cfg->input_pins[AUTO_PIN_MIC] = |
| 4549 | cfg->input_pins[AUTO_PIN_FRONT_MIC]; |
| 4550 | cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0; |
| 4551 | } |
| 4552 | /* ditto for line-in */ |
| 4553 | if (!cfg->input_pins[AUTO_PIN_LINE] && |
| 4554 | cfg->input_pins[AUTO_PIN_FRONT_LINE]) { |
| 4555 | cfg->input_pins[AUTO_PIN_LINE] = |
| 4556 | cfg->input_pins[AUTO_PIN_FRONT_LINE]; |
| 4557 | cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0; |
| 4558 | } |
| 4559 | |
Steve Longerbeam | 81937d3 | 2007-05-08 15:33:03 +0200 | [diff] [blame] | 4560 | /* |
| 4561 | * FIX-UP: if no line-outs are detected, try to use speaker or HP pin |
| 4562 | * as a primary output |
| 4563 | */ |
| 4564 | if (!cfg->line_outs) { |
| 4565 | if (cfg->speaker_outs) { |
| 4566 | cfg->line_outs = cfg->speaker_outs; |
| 4567 | memcpy(cfg->line_out_pins, cfg->speaker_pins, |
| 4568 | sizeof(cfg->speaker_pins)); |
| 4569 | cfg->speaker_outs = 0; |
| 4570 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); |
| 4571 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; |
| 4572 | } else if (cfg->hp_outs) { |
| 4573 | cfg->line_outs = cfg->hp_outs; |
| 4574 | memcpy(cfg->line_out_pins, cfg->hp_pins, |
| 4575 | sizeof(cfg->hp_pins)); |
| 4576 | cfg->hp_outs = 0; |
| 4577 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 4578 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 4579 | } |
| 4580 | } |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4581 | |
Takashi Iwai | cb8e2f8 | 2005-07-29 11:54:32 +0200 | [diff] [blame] | 4582 | /* Reorder the surround channels |
| 4583 | * ALSA sequence is front/surr/clfe/side |
| 4584 | * HDA sequence is: |
| 4585 | * 4-ch: front/surr => OK as it is |
| 4586 | * 6-ch: front/clfe/surr |
Takashi Iwai | 9422db4 | 2007-04-20 16:11:43 +0200 | [diff] [blame] | 4587 | * 8-ch: front/clfe/rear/side|fc |
Takashi Iwai | cb8e2f8 | 2005-07-29 11:54:32 +0200 | [diff] [blame] | 4588 | */ |
| 4589 | switch (cfg->line_outs) { |
| 4590 | case 3: |
Takashi Iwai | cb8e2f8 | 2005-07-29 11:54:32 +0200 | [diff] [blame] | 4591 | case 4: |
| 4592 | nid = cfg->line_out_pins[1]; |
Takashi Iwai | 9422db4 | 2007-04-20 16:11:43 +0200 | [diff] [blame] | 4593 | cfg->line_out_pins[1] = cfg->line_out_pins[2]; |
Takashi Iwai | cb8e2f8 | 2005-07-29 11:54:32 +0200 | [diff] [blame] | 4594 | cfg->line_out_pins[2] = nid; |
| 4595 | break; |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4596 | } |
| 4597 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4598 | /* |
| 4599 | * debug prints of the parsed results |
| 4600 | */ |
| 4601 | snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
| 4602 | cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], |
| 4603 | cfg->line_out_pins[2], cfg->line_out_pins[3], |
| 4604 | cfg->line_out_pins[4]); |
| 4605 | snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
| 4606 | cfg->speaker_outs, cfg->speaker_pins[0], |
| 4607 | cfg->speaker_pins[1], cfg->speaker_pins[2], |
| 4608 | cfg->speaker_pins[3], cfg->speaker_pins[4]); |
Takashi Iwai | eb06ed8 | 2006-09-20 17:10:27 +0200 | [diff] [blame] | 4609 | snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
| 4610 | cfg->hp_outs, cfg->hp_pins[0], |
| 4611 | cfg->hp_pins[1], cfg->hp_pins[2], |
| 4612 | cfg->hp_pins[3], cfg->hp_pins[4]); |
Matthew Ranostay | 90da78b | 2008-01-24 11:48:01 +0100 | [diff] [blame] | 4613 | snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 4614 | if (cfg->dig_outs) |
| 4615 | snd_printd(" dig-out=0x%x/0x%x\n", |
| 4616 | cfg->dig_out_pins[0], cfg->dig_out_pins[1]); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4617 | snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x," |
| 4618 | " cd=0x%x, aux=0x%x\n", |
| 4619 | cfg->input_pins[AUTO_PIN_MIC], |
| 4620 | cfg->input_pins[AUTO_PIN_FRONT_MIC], |
| 4621 | cfg->input_pins[AUTO_PIN_LINE], |
| 4622 | cfg->input_pins[AUTO_PIN_FRONT_LINE], |
| 4623 | cfg->input_pins[AUTO_PIN_CD], |
| 4624 | cfg->input_pins[AUTO_PIN_AUX]); |
Takashi Iwai | 32d2c7f | 2009-02-11 11:33:13 +0100 | [diff] [blame] | 4625 | if (cfg->dig_in_pin) |
Takashi Iwai | 89ce9e8 | 2009-01-20 17:15:57 +0100 | [diff] [blame] | 4626 | snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 4627 | |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4628 | return 0; |
| 4629 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4630 | EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config); |
Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 4631 | |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 4632 | /* labels for input pins */ |
| 4633 | const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = { |
| 4634 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux" |
| 4635 | }; |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4636 | EXPORT_SYMBOL_HDA(auto_pin_cfg_labels); |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 4637 | |
| 4638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | #ifdef CONFIG_PM |
| 4640 | /* |
| 4641 | * power management |
| 4642 | */ |
| 4643 | |
| 4644 | /** |
| 4645 | * snd_hda_suspend - suspend the codecs |
| 4646 | * @bus: the HDA bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | * |
| 4648 | * Returns 0 if successful. |
| 4649 | */ |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 4650 | int snd_hda_suspend(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4652 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4654 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 0b7a2e9 | 2007-08-14 15:18:26 +0200 | [diff] [blame] | 4655 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4656 | if (!codec->power_on) |
| 4657 | continue; |
| 4658 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4659 | hda_call_codec_suspend(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | } |
| 4661 | return 0; |
| 4662 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4663 | EXPORT_SYMBOL_HDA(snd_hda_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | |
| 4665 | /** |
| 4666 | * snd_hda_resume - resume the codecs |
| 4667 | * @bus: the HDA bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | * |
| 4669 | * Returns 0 if successful. |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4670 | * |
| 4671 | * This fucntion is defined only when POWER_SAVE isn't set. |
| 4672 | * In the power-save mode, the codec is resumed dynamically. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | */ |
| 4674 | int snd_hda_resume(struct hda_bus *bus) |
| 4675 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4676 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4678 | list_for_each_entry(codec, &bus->codec_list, list) { |
Maxim Levitsky | d804ad9 | 2007-09-03 15:28:04 +0200 | [diff] [blame] | 4679 | if (snd_hda_codec_needs_resume(codec)) |
| 4680 | hda_call_codec_resume(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | return 0; |
| 4683 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4684 | EXPORT_SYMBOL_HDA(snd_hda_resume); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4685 | #endif /* CONFIG_PM */ |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4686 | |
| 4687 | /* |
| 4688 | * generic arrays |
| 4689 | */ |
| 4690 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4691 | /** |
| 4692 | * snd_array_new - get a new element from the given array |
| 4693 | * @array: the array object |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4694 | * |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4695 | * Get a new element from the given array. If it exceeds the |
| 4696 | * pre-allocated array size, re-allocate the array. |
| 4697 | * |
| 4698 | * Returns NULL if allocation failed. |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4699 | */ |
| 4700 | void *snd_array_new(struct snd_array *array) |
| 4701 | { |
| 4702 | if (array->used >= array->alloced) { |
| 4703 | int num = array->alloced + array->alloc_align; |
Takashi Iwai | b910d9a | 2008-11-07 00:26:52 +0100 | [diff] [blame] | 4704 | void *nlist; |
| 4705 | if (snd_BUG_ON(num >= 4096)) |
| 4706 | return NULL; |
| 4707 | nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4708 | if (!nlist) |
| 4709 | return NULL; |
| 4710 | if (array->list) { |
| 4711 | memcpy(nlist, array->list, |
| 4712 | array->elem_size * array->alloced); |
| 4713 | kfree(array->list); |
| 4714 | } |
| 4715 | array->list = nlist; |
| 4716 | array->alloced = num; |
| 4717 | } |
Takashi Iwai | f43aa02 | 2008-11-10 16:24:26 +0100 | [diff] [blame] | 4718 | return snd_array_elem(array, array->used++); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4719 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4720 | EXPORT_SYMBOL_HDA(snd_array_new); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4721 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4722 | /** |
| 4723 | * snd_array_free - free the given array elements |
| 4724 | * @array: the array object |
| 4725 | */ |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4726 | void snd_array_free(struct snd_array *array) |
| 4727 | { |
| 4728 | kfree(array->list); |
| 4729 | array->used = 0; |
| 4730 | array->alloced = 0; |
| 4731 | array->list = NULL; |
| 4732 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4733 | EXPORT_SYMBOL_HDA(snd_array_free); |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 4734 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4735 | /** |
| 4736 | * snd_print_pcm_rates - Print the supported PCM rates to the string buffer |
| 4737 | * @pcm: PCM caps bits |
| 4738 | * @buf: the string buffer to write |
| 4739 | * @buflen: the max buffer length |
| 4740 | * |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 4741 | * used by hda_proc.c and hda_eld.c |
| 4742 | */ |
| 4743 | void snd_print_pcm_rates(int pcm, char *buf, int buflen) |
| 4744 | { |
| 4745 | static unsigned int rates[] = { |
| 4746 | 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, |
| 4747 | 96000, 176400, 192000, 384000 |
| 4748 | }; |
| 4749 | int i, j; |
| 4750 | |
| 4751 | for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++) |
| 4752 | if (pcm & (1 << i)) |
| 4753 | j += snprintf(buf + j, buflen - j, " %d", rates[i]); |
| 4754 | |
| 4755 | buf[j] = '\0'; /* necessary when j == 0 */ |
| 4756 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4757 | EXPORT_SYMBOL_HDA(snd_print_pcm_rates); |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 4758 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4759 | /** |
| 4760 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer |
| 4761 | * @pcm: PCM caps bits |
| 4762 | * @buf: the string buffer to write |
| 4763 | * @buflen: the max buffer length |
| 4764 | * |
| 4765 | * used by hda_proc.c and hda_eld.c |
| 4766 | */ |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 4767 | void snd_print_pcm_bits(int pcm, char *buf, int buflen) |
| 4768 | { |
| 4769 | static unsigned int bits[] = { 8, 16, 20, 24, 32 }; |
| 4770 | int i, j; |
| 4771 | |
| 4772 | for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++) |
| 4773 | if (pcm & (AC_SUPPCM_BITS_8 << i)) |
| 4774 | j += snprintf(buf + j, buflen - j, " %d", bits[i]); |
| 4775 | |
| 4776 | buf[j] = '\0'; /* necessary when j == 0 */ |
| 4777 | } |
Takashi Iwai | ff7a326 | 2008-11-28 15:17:06 +0100 | [diff] [blame] | 4778 | EXPORT_SYMBOL_HDA(snd_print_pcm_bits); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4779 | |
| 4780 | MODULE_DESCRIPTION("HDA codec core"); |
| 4781 | MODULE_LICENSE("GPL"); |