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