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