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