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 | |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 22 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/slab.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Takashi Iwai | f4d6a55 | 2013-12-05 11:55:05 +0100 | [diff] [blame] | 28 | #include <linux/async.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <sound/core.h> |
| 30 | #include "hda_codec.h" |
| 31 | #include <sound/asoundef.h> |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 32 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <sound/initval.h> |
Takashi Iwai | cd372fb | 2011-03-03 14:40:14 +0100 | [diff] [blame] | 34 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "hda_local.h" |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 36 | #include "hda_beep.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 37 | #include "hda_jack.h" |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 38 | #include <sound/hda_hwdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Takashi Iwai | d66fee5 | 2011-08-02 15:39:31 +0200 | [diff] [blame] | 40 | #define CREATE_TRACE_POINTS |
| 41 | #include "hda_trace.h" |
| 42 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 43 | #ifdef CONFIG_PM |
Takashi Iwai | d846b17 | 2012-11-24 11:58:24 +0100 | [diff] [blame] | 44 | #define codec_in_pm(codec) ((codec)->in_pm) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 45 | static void hda_power_work(struct work_struct *work); |
| 46 | static void hda_keep_power_on(struct hda_codec *codec); |
Takashi Iwai | e581f3d | 2011-07-26 10:19:20 +0200 | [diff] [blame] | 47 | #define hda_codec_is_power_on(codec) ((codec)->power_on) |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 48 | |
| 49 | static void hda_call_pm_notify(struct hda_codec *codec, bool power_up) |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 50 | { |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 51 | struct hda_bus *bus = codec->bus; |
| 52 | |
| 53 | if ((power_up && codec->pm_up_notified) || |
| 54 | (!power_up && !codec->pm_up_notified)) |
| 55 | return; |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 56 | if (bus->ops.pm_notify) |
| 57 | bus->ops.pm_notify(bus, power_up); |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 58 | codec->pm_up_notified = power_up; |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 59 | } |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 60 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 61 | #else |
Takashi Iwai | d846b17 | 2012-11-24 11:58:24 +0100 | [diff] [blame] | 62 | #define codec_in_pm(codec) 0 |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 63 | static inline void hda_keep_power_on(struct hda_codec *codec) {} |
Takashi Iwai | e581f3d | 2011-07-26 10:19:20 +0200 | [diff] [blame] | 64 | #define hda_codec_is_power_on(codec) 1 |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 65 | #define hda_call_pm_notify(codec, state) {} |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 66 | #endif |
| 67 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 68 | /** |
| 69 | * snd_hda_get_jack_location - Give a location string of the jack |
| 70 | * @cfg: pin default config value |
| 71 | * |
| 72 | * Parse the pin default config value and returns the string of the |
| 73 | * jack location, e.g. "Rear", "Front", etc. |
| 74 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 75 | const char *snd_hda_get_jack_location(u32 cfg) |
| 76 | { |
| 77 | static char *bases[7] = { |
| 78 | "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom", |
| 79 | }; |
| 80 | static unsigned char specials_idx[] = { |
| 81 | 0x07, 0x08, |
| 82 | 0x17, 0x18, 0x19, |
| 83 | 0x37, 0x38 |
| 84 | }; |
| 85 | static char *specials[] = { |
| 86 | "Rear Panel", "Drive Bar", |
| 87 | "Riser", "HDMI", "ATAPI", |
| 88 | "Mobile-In", "Mobile-Out" |
| 89 | }; |
| 90 | int i; |
| 91 | cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT; |
| 92 | if ((cfg & 0x0f) < 7) |
| 93 | return bases[cfg & 0x0f]; |
| 94 | for (i = 0; i < ARRAY_SIZE(specials_idx); i++) { |
| 95 | if (cfg == specials_idx[i]) |
| 96 | return specials[i]; |
| 97 | } |
| 98 | return "UNKNOWN"; |
| 99 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 100 | EXPORT_SYMBOL_GPL(snd_hda_get_jack_location); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 101 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 102 | /** |
| 103 | * snd_hda_get_jack_connectivity - Give a connectivity string of the jack |
| 104 | * @cfg: pin default config value |
| 105 | * |
| 106 | * Parse the pin default config value and returns the string of the |
| 107 | * jack connectivity, i.e. external or internal connection. |
| 108 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 109 | const char *snd_hda_get_jack_connectivity(u32 cfg) |
| 110 | { |
| 111 | static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; |
| 112 | |
| 113 | return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3]; |
| 114 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 115 | EXPORT_SYMBOL_GPL(snd_hda_get_jack_connectivity); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 116 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 117 | /** |
| 118 | * snd_hda_get_jack_type - Give a type string of the jack |
| 119 | * @cfg: pin default config value |
| 120 | * |
| 121 | * Parse the pin default config value and returns the string of the |
| 122 | * jack type, i.e. the purpose of the jack, such as Line-Out or CD. |
| 123 | */ |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 124 | const char *snd_hda_get_jack_type(u32 cfg) |
| 125 | { |
| 126 | static char *jack_types[16] = { |
| 127 | "Line Out", "Speaker", "HP Out", "CD", |
| 128 | "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand", |
| 129 | "Line In", "Aux", "Mic", "Telephony", |
David Henningsson | aeb3a97 | 2013-04-04 11:47:13 +0200 | [diff] [blame] | 130 | "SPDIF In", "Digital In", "Reserved", "Other" |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | return jack_types[(cfg & AC_DEFCFG_DEVICE) |
| 134 | >> AC_DEFCFG_DEVICE_SHIFT]; |
| 135 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 136 | EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); |
Matthew Ranostay | 50a9f79 | 2008-10-25 01:05:45 -0400 | [diff] [blame] | 137 | |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 138 | /* |
| 139 | * Compose a 32bit command word to be sent to the HD-audio controller |
| 140 | */ |
| 141 | static inline unsigned int |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 142 | make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags, |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 143 | unsigned int verb, unsigned int parm) |
| 144 | { |
| 145 | u32 val; |
| 146 | |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 147 | if ((codec->addr & ~0xf) || (nid & ~0x7f) || |
Takashi Iwai | 82e1b80 | 2009-07-17 12:47:34 +0200 | [diff] [blame] | 148 | (verb & ~0xfff) || (parm & ~0xffff)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 149 | codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n", |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 150 | codec->addr, nid, verb, parm); |
Wu Fengguang | 6430aee | 2009-07-17 16:49:19 +0800 | [diff] [blame] | 151 | return ~0; |
| 152 | } |
| 153 | |
| 154 | val = (u32)codec->addr << 28; |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 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, |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 165 | int flags, unsigned int *res) |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 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 | |
Wu Fengguang | 6430aee | 2009-07-17 16:49:19 +0800 | [diff] [blame] | 170 | if (cmd == ~0) |
| 171 | return -1; |
| 172 | |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 173 | if (res) |
| 174 | *res = -1; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 175 | again: |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 176 | snd_hda_power_up(codec); |
| 177 | mutex_lock(&bus->cmd_mutex); |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 178 | if (flags & HDA_RW_NO_RESPONSE_FALLBACK) |
| 179 | bus->no_response_fallback = 1; |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 180 | for (;;) { |
| 181 | trace_hda_send_cmd(codec, cmd); |
| 182 | err = bus->ops.command(bus, cmd); |
| 183 | if (err != -EAGAIN) |
| 184 | break; |
| 185 | /* process pending verbs */ |
| 186 | bus->ops.get_response(bus, codec->addr); |
| 187 | } |
Takashi Iwai | d66fee5 | 2011-08-02 15:39:31 +0200 | [diff] [blame] | 188 | if (!err && res) { |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 189 | *res = bus->ops.get_response(bus, codec->addr); |
Takashi Iwai | d66fee5 | 2011-08-02 15:39:31 +0200 | [diff] [blame] | 190 | trace_hda_get_response(codec, *res); |
| 191 | } |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 192 | bus->no_response_fallback = 0; |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 193 | mutex_unlock(&bus->cmd_mutex); |
| 194 | snd_hda_power_down(codec); |
Takashi Iwai | d846b17 | 2012-11-24 11:58:24 +0100 | [diff] [blame] | 195 | if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) { |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 196 | if (bus->response_reset) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 197 | codec_dbg(codec, |
| 198 | "resetting BUS due to fatal communication error\n"); |
Takashi Iwai | d66fee5 | 2011-08-02 15:39:31 +0200 | [diff] [blame] | 199 | trace_hda_bus_reset(bus); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 200 | bus->ops.bus_reset(bus); |
| 201 | } |
| 202 | goto again; |
| 203 | } |
| 204 | /* clear reset-flag when the communication gets recovered */ |
Takashi Iwai | d846b17 | 2012-11-24 11:58:24 +0100 | [diff] [blame] | 205 | if (!err || codec_in_pm(codec)) |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 206 | bus->response_reset = 0; |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 207 | return err; |
| 208 | } |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /** |
| 211 | * snd_hda_codec_read - send a command and get the response |
| 212 | * @codec: the HDA codec |
| 213 | * @nid: NID to send the command |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 214 | * @flags: optional bit flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | * @verb: the verb to send |
| 216 | * @parm: the parameter for the verb |
| 217 | * |
| 218 | * Send a single command and read the corresponding response. |
| 219 | * |
| 220 | * Returns the obtained response value, or -1 for an error. |
| 221 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 222 | unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 223 | int flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | unsigned int verb, unsigned int parm) |
| 225 | { |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 226 | unsigned cmd = make_codec_cmd(codec, nid, flags, verb, parm); |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 227 | unsigned int res; |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 228 | if (codec_exec_verb(codec, cmd, flags, &res)) |
Greg Thelen | 9857edf | 2011-06-13 07:45:45 -0700 | [diff] [blame] | 229 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return res; |
| 231 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 232 | EXPORT_SYMBOL_GPL(snd_hda_codec_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * snd_hda_codec_write - send a single command without waiting for response |
| 236 | * @codec: the HDA codec |
| 237 | * @nid: NID to send the command |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 238 | * @flags: optional bit flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | * @verb: the verb to send |
| 240 | * @parm: the parameter for the verb |
| 241 | * |
| 242 | * Send a single command without waiting for response. |
| 243 | * |
| 244 | * Returns 0 if successful, or a negative error code. |
| 245 | */ |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 246 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, |
| 247 | unsigned int verb, unsigned int parm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 249 | unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm); |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 250 | unsigned int res; |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 251 | return codec_exec_verb(codec, cmd, flags, |
Takashi Iwai | b20f3b8 | 2009-06-02 01:20:22 +0200 | [diff] [blame] | 252 | codec->bus->sync_write ? &res : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 254 | EXPORT_SYMBOL_GPL(snd_hda_codec_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * snd_hda_sequence_write - sequence writes |
| 258 | * @codec: the HDA codec |
| 259 | * @seq: VERB array to send |
| 260 | * |
| 261 | * Send the commands sequentially from the given array. |
| 262 | * The array must be terminated with NID=0. |
| 263 | */ |
| 264 | void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) |
| 265 | { |
| 266 | for (; seq->nid; seq++) |
| 267 | snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); |
| 268 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 269 | EXPORT_SYMBOL_GPL(snd_hda_sequence_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * snd_hda_get_sub_nodes - get the range of sub nodes |
| 273 | * @codec: the HDA codec |
| 274 | * @nid: NID to parse |
| 275 | * @start_id: the pointer to store the start NID |
| 276 | * |
| 277 | * Parse the NID and store the start NID of its sub-nodes. |
| 278 | * Returns the number of sub-nodes. |
| 279 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 280 | int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, |
| 281 | hda_nid_t *start_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
| 283 | unsigned int parm; |
| 284 | |
| 285 | parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT); |
Dan Carpenter | 69eba10 | 2014-11-27 01:34:43 +0300 | [diff] [blame] | 286 | if (parm == -1) { |
| 287 | *start_id = 0; |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 288 | return 0; |
Dan Carpenter | 69eba10 | 2014-11-27 01:34:43 +0300 | [diff] [blame] | 289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | *start_id = (parm >> 16) & 0x7fff; |
| 291 | return (int)(parm & 0x7fff); |
| 292 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 293 | EXPORT_SYMBOL_GPL(snd_hda_get_sub_nodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 295 | /* connection list element */ |
| 296 | struct hda_conn_list { |
| 297 | struct list_head list; |
| 298 | int len; |
| 299 | hda_nid_t nid; |
| 300 | hda_nid_t conns[0]; |
| 301 | }; |
| 302 | |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 303 | /* look up the cached results */ |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 304 | static struct hda_conn_list * |
| 305 | lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 306 | { |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 307 | struct hda_conn_list *p; |
| 308 | list_for_each_entry(p, &codec->conn_list, list) { |
| 309 | if (p->nid == nid) |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 310 | return p; |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 311 | } |
| 312 | return NULL; |
| 313 | } |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 314 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 315 | static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, |
| 316 | const hda_nid_t *list) |
| 317 | { |
| 318 | struct hda_conn_list *p; |
| 319 | |
| 320 | p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL); |
| 321 | if (!p) |
| 322 | return -ENOMEM; |
| 323 | p->len = len; |
| 324 | p->nid = nid; |
| 325 | memcpy(p->conns, list, len * sizeof(hda_nid_t)); |
| 326 | list_add(&p->list, &codec->conn_list); |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static void remove_conn_list(struct hda_codec *codec) |
| 331 | { |
| 332 | while (!list_empty(&codec->conn_list)) { |
| 333 | struct hda_conn_list *p; |
| 334 | p = list_first_entry(&codec->conn_list, typeof(*p), list); |
| 335 | list_del(&p->list); |
| 336 | kfree(p); |
| 337 | } |
| 338 | } |
| 339 | |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 340 | /* read the connection and add to the cache */ |
| 341 | static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 342 | { |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 343 | hda_nid_t list[32]; |
| 344 | hda_nid_t *result = list; |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 345 | int len; |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 346 | |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 347 | len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 348 | if (len == -ENOSPC) { |
| 349 | len = snd_hda_get_num_raw_conns(codec, nid); |
| 350 | result = kmalloc(sizeof(hda_nid_t) * len, GFP_KERNEL); |
| 351 | if (!result) |
| 352 | return -ENOMEM; |
| 353 | len = snd_hda_get_raw_connections(codec, nid, result, len); |
| 354 | } |
| 355 | if (len >= 0) |
| 356 | len = snd_hda_override_conn_list(codec, nid, len, result); |
| 357 | if (result != list) |
| 358 | kfree(result); |
| 359 | return len; |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 360 | } |
Takashi Iwai | dce2079 | 2011-06-24 14:10:28 +0200 | [diff] [blame] | 361 | |
| 362 | /** |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 363 | * snd_hda_get_conn_list - get connection list |
| 364 | * @codec: the HDA codec |
| 365 | * @nid: NID to parse |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 366 | * @listp: the pointer to store NID list |
| 367 | * |
| 368 | * Parses the connection list of the given widget and stores the pointer |
| 369 | * to the list of NIDs. |
| 370 | * |
| 371 | * Returns the number of connections, or a negative error code. |
| 372 | * |
| 373 | * Note that the returned pointer isn't protected against the list |
| 374 | * modification. If snd_hda_override_conn_list() might be called |
| 375 | * concurrently, protect with a mutex appropriately. |
| 376 | */ |
| 377 | int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, |
| 378 | const hda_nid_t **listp) |
| 379 | { |
| 380 | bool added = false; |
| 381 | |
| 382 | for (;;) { |
| 383 | int err; |
| 384 | const struct hda_conn_list *p; |
| 385 | |
| 386 | /* if the connection-list is already cached, read it */ |
| 387 | p = lookup_conn_list(codec, nid); |
| 388 | if (p) { |
| 389 | if (listp) |
| 390 | *listp = p->conns; |
| 391 | return p->len; |
| 392 | } |
| 393 | if (snd_BUG_ON(added)) |
| 394 | return -EINVAL; |
| 395 | |
| 396 | err = read_and_add_raw_conns(codec, nid); |
| 397 | if (err < 0) |
| 398 | return err; |
| 399 | added = true; |
| 400 | } |
| 401 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 402 | EXPORT_SYMBOL_GPL(snd_hda_get_conn_list); |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 403 | |
| 404 | /** |
Takashi Iwai | dce2079 | 2011-06-24 14:10:28 +0200 | [diff] [blame] | 405 | * snd_hda_get_connections - copy connection list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | * @codec: the HDA codec |
| 407 | * @nid: NID to parse |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 408 | * @conn_list: connection list array; when NULL, checks only the size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | * @max_conns: max. number of connections to store |
| 410 | * |
| 411 | * Parses the connection list of the given widget and stores the list |
| 412 | * of NIDs. |
| 413 | * |
| 414 | * Returns the number of connections, or a negative error code. |
| 415 | */ |
| 416 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 417 | hda_nid_t *conn_list, int max_conns) |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 418 | { |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 419 | const hda_nid_t *list; |
| 420 | int len = snd_hda_get_conn_list(codec, nid, &list); |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 421 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 422 | if (len > 0 && conn_list) { |
| 423 | if (len > max_conns) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 424 | codec_err(codec, "Too many connections %d for NID 0x%x\n", |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 425 | len, nid); |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 426 | return -EINVAL; |
| 427 | } |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 428 | memcpy(conn_list, list, len * sizeof(hda_nid_t)); |
Takashi Iwai | dce2079 | 2011-06-24 14:10:28 +0200 | [diff] [blame] | 429 | } |
Takashi Iwai | 09cf03b | 2012-05-19 17:21:25 +0200 | [diff] [blame] | 430 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 431 | return len; |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 432 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 433 | EXPORT_SYMBOL_GPL(snd_hda_get_connections); |
Takashi Iwai | a12d3e1 | 2011-04-07 15:55:15 +0200 | [diff] [blame] | 434 | |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 435 | /* return CONNLIST_LEN parameter of the given widget */ |
| 436 | static unsigned int get_num_conns(struct hda_codec *codec, hda_nid_t nid) |
| 437 | { |
| 438 | unsigned int wcaps = get_wcaps(codec, nid); |
| 439 | unsigned int parm; |
| 440 | |
| 441 | if (!(wcaps & AC_WCAP_CONN_LIST) && |
| 442 | get_wcaps_type(wcaps) != AC_WID_VOL_KNB) |
| 443 | return 0; |
| 444 | |
| 445 | parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); |
| 446 | if (parm == -1) |
| 447 | parm = 0; |
| 448 | return parm; |
| 449 | } |
| 450 | |
| 451 | int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid) |
| 452 | { |
Takashi Iwai | b5f82b1 | 2013-03-12 16:47:30 +0100 | [diff] [blame] | 453 | return snd_hda_get_raw_connections(codec, nid, NULL, 0); |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Takashi Iwai | 9e7717c | 2011-07-11 15:42:52 +0200 | [diff] [blame] | 456 | /** |
| 457 | * snd_hda_get_raw_connections - copy connection list without cache |
| 458 | * @codec: the HDA codec |
| 459 | * @nid: NID to parse |
| 460 | * @conn_list: connection list array |
| 461 | * @max_conns: max. number of connections to store |
| 462 | * |
| 463 | * Like snd_hda_get_connections(), copy the connection list but without |
| 464 | * checking through the connection-list cache. |
| 465 | * Currently called only from hda_proc.c, so not exported. |
| 466 | */ |
| 467 | int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, |
| 468 | hda_nid_t *conn_list, int max_conns) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
| 470 | unsigned int parm; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 471 | int i, conn_len, conns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | unsigned int shift, num_elems, mask; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 473 | hda_nid_t prev_nid; |
Takashi Iwai | 5fdaecd | 2012-12-20 10:45:55 +0100 | [diff] [blame] | 474 | int null_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 476 | parm = get_num_conns(codec, nid); |
| 477 | if (!parm) |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 478 | return 0; |
Jaroslav Kysela | 16a433d | 2009-07-22 16:20:40 +0200 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if (parm & AC_CLIST_LONG) { |
| 481 | /* long form */ |
| 482 | shift = 16; |
| 483 | num_elems = 2; |
| 484 | } else { |
| 485 | /* short form */ |
| 486 | shift = 8; |
| 487 | num_elems = 4; |
| 488 | } |
| 489 | conn_len = parm & AC_CLIST_LENGTH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | mask = (1 << (shift-1)) - 1; |
| 491 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 492 | if (!conn_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return 0; /* no connection */ |
| 494 | |
| 495 | if (conn_len == 1) { |
| 496 | /* single connection */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 497 | parm = snd_hda_codec_read(codec, nid, 0, |
| 498 | AC_VERB_GET_CONNECT_LIST, 0); |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 499 | if (parm == -1 && codec->bus->rirb_error) |
| 500 | return -EIO; |
Takashi Iwai | b5f82b1 | 2013-03-12 16:47:30 +0100 | [diff] [blame] | 501 | if (conn_list) |
| 502 | conn_list[0] = parm & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | return 1; |
| 504 | } |
| 505 | |
| 506 | /* multi connection */ |
| 507 | conns = 0; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 508 | prev_nid = 0; |
| 509 | for (i = 0; i < conn_len; i++) { |
| 510 | int range_val; |
| 511 | hda_nid_t val, n; |
| 512 | |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 513 | if (i % num_elems == 0) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 514 | parm = snd_hda_codec_read(codec, nid, 0, |
| 515 | AC_VERB_GET_CONNECT_LIST, i); |
Takashi Iwai | 3c6aae4 | 2009-07-10 12:52:27 +0200 | [diff] [blame] | 516 | if (parm == -1 && codec->bus->rirb_error) |
| 517 | return -EIO; |
| 518 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 519 | range_val = !!(parm & (1 << (shift-1))); /* ranges */ |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 520 | val = parm & mask; |
Takashi Iwai | 5fdaecd | 2012-12-20 10:45:55 +0100 | [diff] [blame] | 521 | if (val == 0 && null_count++) { /* no second chance */ |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 522 | codec_dbg(codec, |
| 523 | "invalid CONNECT_LIST verb %x[%i]:%x\n", |
Jaroslav Kysela | 2e9bf24 | 2009-07-18 11:48:19 +0200 | [diff] [blame] | 524 | nid, i, parm); |
| 525 | return 0; |
| 526 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 527 | parm >>= shift; |
| 528 | if (range_val) { |
| 529 | /* ranges between the previous and this one */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 530 | if (!prev_nid || prev_nid >= val) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 531 | codec_warn(codec, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 532 | "invalid dep_range_val %x:%x\n", |
| 533 | prev_nid, val); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 534 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 536 | for (n = prev_nid + 1; n <= val; n++) { |
Takashi Iwai | b5f82b1 | 2013-03-12 16:47:30 +0100 | [diff] [blame] | 537 | if (conn_list) { |
| 538 | if (conns >= max_conns) |
| 539 | return -ENOSPC; |
| 540 | conn_list[conns] = n; |
| 541 | } |
| 542 | conns++; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 543 | } |
| 544 | } else { |
Takashi Iwai | b5f82b1 | 2013-03-12 16:47:30 +0100 | [diff] [blame] | 545 | if (conn_list) { |
| 546 | if (conns >= max_conns) |
| 547 | return -ENOSPC; |
| 548 | conn_list[conns] = val; |
| 549 | } |
| 550 | conns++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 552 | prev_nid = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | return conns; |
| 555 | } |
| 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | /** |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 558 | * snd_hda_override_conn_list - add/modify the connection-list to cache |
| 559 | * @codec: the HDA codec |
| 560 | * @nid: NID to parse |
| 561 | * @len: number of connection list entries |
| 562 | * @list: the list of connection entries |
| 563 | * |
| 564 | * Add or modify the given connection-list to the cache. If the corresponding |
| 565 | * cache already exists, invalidate it and append a new one. |
| 566 | * |
| 567 | * Returns zero or a negative error code. |
| 568 | */ |
| 569 | int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, |
| 570 | const hda_nid_t *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 572 | struct hda_conn_list *p; |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 573 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 574 | p = lookup_conn_list(codec, nid); |
| 575 | if (p) { |
| 576 | list_del(&p->list); |
| 577 | kfree(p); |
| 578 | } |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 579 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 580 | return add_conn_list(codec, nid, len, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 582 | EXPORT_SYMBOL_GPL(snd_hda_override_conn_list); |
Takashi Iwai | b2f934a | 2011-07-04 16:23:26 +0200 | [diff] [blame] | 583 | |
| 584 | /** |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 585 | * snd_hda_get_conn_index - get the connection index of the given NID |
| 586 | * @codec: the HDA codec |
| 587 | * @mux: NID containing the list |
| 588 | * @nid: NID to select |
| 589 | * @recursive: 1 when searching NID recursively, otherwise 0 |
| 590 | * |
| 591 | * Parses the connection list of the widget @mux and checks whether the |
| 592 | * widget @nid is present. If it is, return the connection index. |
| 593 | * Otherwise it returns -1. |
| 594 | */ |
| 595 | int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, |
| 596 | hda_nid_t nid, int recursive) |
| 597 | { |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 598 | const hda_nid_t *conn; |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 599 | int i, nums; |
| 600 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 601 | nums = snd_hda_get_conn_list(codec, mux, &conn); |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 602 | for (i = 0; i < nums; i++) |
| 603 | if (conn[i] == nid) |
| 604 | return i; |
| 605 | if (!recursive) |
| 606 | return -1; |
Takashi Iwai | d94ddd8 | 2012-12-20 14:42:42 +0100 | [diff] [blame] | 607 | if (recursive > 10) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 608 | codec_dbg(codec, "too deep connection for 0x%x\n", nid); |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 609 | return -1; |
| 610 | } |
| 611 | recursive++; |
Takashi Iwai | 99e14c9 | 2011-09-13 10:33:16 +0200 | [diff] [blame] | 612 | for (i = 0; i < nums; i++) { |
| 613 | unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i])); |
| 614 | if (type == AC_WID_PIN || type == AC_WID_AUD_OUT) |
| 615 | continue; |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 616 | if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) |
| 617 | return i; |
Takashi Iwai | 99e14c9 | 2011-09-13 10:33:16 +0200 | [diff] [blame] | 618 | } |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 619 | return -1; |
| 620 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 621 | EXPORT_SYMBOL_GPL(snd_hda_get_conn_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Mengdong Lin | f1aa068 | 2013-08-26 21:35:21 -0400 | [diff] [blame] | 623 | |
| 624 | /* return DEVLIST_LEN parameter of the given widget */ |
| 625 | static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid) |
| 626 | { |
| 627 | unsigned int wcaps = get_wcaps(codec, nid); |
| 628 | unsigned int parm; |
| 629 | |
| 630 | if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || |
| 631 | get_wcaps_type(wcaps) != AC_WID_PIN) |
| 632 | return 0; |
| 633 | |
| 634 | parm = snd_hda_param_read(codec, nid, AC_PAR_DEVLIST_LEN); |
| 635 | if (parm == -1 && codec->bus->rirb_error) |
| 636 | parm = 0; |
| 637 | return parm & AC_DEV_LIST_LEN_MASK; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * snd_hda_get_devices - copy device list without cache |
| 642 | * @codec: the HDA codec |
| 643 | * @nid: NID of the pin to parse |
| 644 | * @dev_list: device list array |
| 645 | * @max_devices: max. number of devices to store |
| 646 | * |
| 647 | * Copy the device list. This info is dynamic and so not cached. |
| 648 | * Currently called only from hda_proc.c, so not exported. |
| 649 | */ |
| 650 | int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, |
| 651 | u8 *dev_list, int max_devices) |
| 652 | { |
| 653 | unsigned int parm; |
| 654 | int i, dev_len, devices; |
| 655 | |
| 656 | parm = get_num_devices(codec, nid); |
| 657 | if (!parm) /* not multi-stream capable */ |
| 658 | return 0; |
| 659 | |
| 660 | dev_len = parm + 1; |
| 661 | dev_len = dev_len < max_devices ? dev_len : max_devices; |
| 662 | |
| 663 | devices = 0; |
| 664 | while (devices < dev_len) { |
| 665 | parm = snd_hda_codec_read(codec, nid, 0, |
| 666 | AC_VERB_GET_DEVICE_LIST, devices); |
| 667 | if (parm == -1 && codec->bus->rirb_error) |
| 668 | break; |
| 669 | |
| 670 | for (i = 0; i < 8; i++) { |
| 671 | dev_list[devices] = (u8)parm; |
| 672 | parm >>= 4; |
| 673 | devices++; |
| 674 | if (devices >= dev_len) |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | return devices; |
| 679 | } |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | /** |
| 682 | * snd_hda_queue_unsol_event - add an unsolicited event to queue |
| 683 | * @bus: the BUS |
| 684 | * @res: unsolicited event (lower 32bit of RIRB entry) |
| 685 | * @res_ex: codec addr and flags (upper 32bit or RIRB entry) |
| 686 | * |
| 687 | * Adds the given event to the queue. The events are processed in |
| 688 | * the workqueue asynchronously. Call this function in the interrupt |
| 689 | * hanlder when RIRB receives an unsolicited event. |
| 690 | * |
| 691 | * Returns 0 if successful, or a negative error code. |
| 692 | */ |
| 693 | int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) |
| 694 | { |
| 695 | struct hda_bus_unsolicited *unsol; |
| 696 | unsigned int wp; |
| 697 | |
Wang YanQing | 2195b06 | 2013-05-07 11:27:33 +0800 | [diff] [blame] | 698 | if (!bus || !bus->workq) |
| 699 | return 0; |
| 700 | |
Takashi Iwai | ecf726f | 2011-08-09 14:22:44 +0200 | [diff] [blame] | 701 | trace_hda_unsol_event(bus, res, res_ex); |
Takashi Iwai | 922c88a | 2015-02-17 14:46:40 +0100 | [diff] [blame] | 702 | unsol = &bus->unsol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; |
| 704 | unsol->wp = wp; |
| 705 | |
| 706 | wp <<= 1; |
| 707 | unsol->queue[wp] = res; |
| 708 | unsol->queue[wp + 1] = res_ex; |
| 709 | |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 710 | queue_work(bus->workq, &unsol->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | return 0; |
| 713 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 714 | EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | /* |
Wu Fengguang | 5c1d1a9 | 2008-10-07 14:17:53 +0800 | [diff] [blame] | 717 | * process queued unsolicited events |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 719 | static void process_unsol_events(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
Takashi Iwai | 922c88a | 2015-02-17 14:46:40 +0100 | [diff] [blame] | 721 | struct hda_bus *bus = container_of(work, struct hda_bus, unsol.work); |
| 722 | struct hda_bus_unsolicited *unsol = &bus->unsol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | struct hda_codec *codec; |
| 724 | unsigned int rp, caddr, res; |
| 725 | |
| 726 | while (unsol->rp != unsol->wp) { |
| 727 | rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE; |
| 728 | unsol->rp = rp; |
| 729 | rp <<= 1; |
| 730 | res = unsol->queue[rp]; |
| 731 | caddr = unsol->queue[rp + 1]; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 732 | if (!(caddr & (1 << 4))) /* no unsolicited event? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | continue; |
| 734 | codec = bus->caddr_tbl[caddr & 0x0f]; |
| 735 | if (codec && codec->patch_ops.unsol_event) |
| 736 | codec->patch_ops.unsol_event(codec, res); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | * destructor |
| 742 | */ |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 743 | static void snd_hda_bus_free(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 745 | if (!bus) |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 746 | return; |
| 747 | |
| 748 | WARN_ON(!list_empty(&bus->codec_list)); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 749 | if (bus->workq) |
| 750 | flush_workqueue(bus->workq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (bus->ops.private_free) |
| 752 | bus->ops.private_free(bus); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 753 | if (bus->workq) |
| 754 | destroy_workqueue(bus->workq); |
Mengdong Lin | 0e24dbb | 2013-11-26 23:00:51 -0500 | [diff] [blame] | 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | kfree(bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 759 | static int snd_hda_bus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 761 | snd_hda_bus_free(device->device_data); |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int snd_hda_bus_dev_disconnect(struct snd_device *device) |
| 766 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | struct hda_bus *bus = device->device_data; |
Takashi Iwai | b94d3539 | 2008-11-21 09:08:06 +0100 | [diff] [blame] | 768 | bus->shutdown = 1; |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 769 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
| 773 | * snd_hda_bus_new - create a HDA bus |
| 774 | * @card: the card entry |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | * @busp: the pointer to store the created bus instance |
| 776 | * |
| 777 | * Returns 0 if successful, or a negative error code. |
| 778 | */ |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 779 | int snd_hda_bus_new(struct snd_card *card, |
Takashi Iwai | ef74497 | 2015-02-17 13:56:29 +0100 | [diff] [blame] | 780 | struct hda_bus **busp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | { |
| 782 | struct hda_bus *bus; |
| 783 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 784 | static struct snd_device_ops dev_ops = { |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 785 | .dev_disconnect = snd_hda_bus_dev_disconnect, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | .dev_free = snd_hda_bus_dev_free, |
| 787 | }; |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | if (busp) |
| 790 | *busp = NULL; |
| 791 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 792 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | if (bus == NULL) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 794 | dev_err(card->dev, "can't allocate struct hda_bus\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | return -ENOMEM; |
| 796 | } |
| 797 | |
| 798 | bus->card = card; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 799 | mutex_init(&bus->cmd_mutex); |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 800 | mutex_init(&bus->prepare_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | INIT_LIST_HEAD(&bus->codec_list); |
Takashi Iwai | 922c88a | 2015-02-17 14:46:40 +0100 | [diff] [blame] | 802 | INIT_WORK(&bus->unsol.work, process_unsol_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Takashi Iwai | e8c0ee5 | 2009-02-05 07:34:28 +0100 | [diff] [blame] | 804 | snprintf(bus->workq_name, sizeof(bus->workq_name), |
| 805 | "hd-audio%d", card->number); |
| 806 | bus->workq = create_singlethread_workqueue(bus->workq_name); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 807 | if (!bus->workq) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 808 | dev_err(card->dev, "cannot create workqueue %s\n", |
Takashi Iwai | e8c0ee5 | 2009-02-05 07:34:28 +0100 | [diff] [blame] | 809 | bus->workq_name); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 810 | kfree(bus); |
| 811 | return -ENOMEM; |
| 812 | } |
| 813 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 814 | err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); |
| 815 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | snd_hda_bus_free(bus); |
| 817 | return err; |
| 818 | } |
| 819 | if (busp) |
| 820 | *busp = bus; |
| 821 | return 0; |
| 822 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 823 | EXPORT_SYMBOL_GPL(snd_hda_bus_new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | /* |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 826 | * look for an AFG and MFG nodes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | */ |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 828 | static void setup_fg_nodes(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
Takashi Iwai | 93e82ae | 2009-04-17 18:04:41 +0200 | [diff] [blame] | 830 | int i, total_nodes, function_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | hda_nid_t nid; |
| 832 | |
| 833 | total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); |
| 834 | for (i = 0; i < total_nodes; i++, nid++) { |
Takashi Iwai | 93e82ae | 2009-04-17 18:04:41 +0200 | [diff] [blame] | 835 | function_id = snd_hda_param_read(codec, nid, |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 836 | AC_PAR_FUNCTION_TYPE); |
Jaroslav Kysela | cd7643b | 2010-07-20 12:11:25 +0200 | [diff] [blame] | 837 | switch (function_id & 0xff) { |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 838 | case AC_GRP_AUDIO_FUNCTION: |
| 839 | codec->afg = nid; |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 840 | codec->afg_function_id = function_id & 0xff; |
| 841 | codec->afg_unsol = (function_id >> 8) & 1; |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 842 | break; |
| 843 | case AC_GRP_MODEM_FUNCTION: |
| 844 | codec->mfg = nid; |
Jaroslav Kysela | 79c944a | 2010-07-19 15:52:39 +0200 | [diff] [blame] | 845 | codec->mfg_function_id = function_id & 0xff; |
| 846 | codec->mfg_unsol = (function_id >> 8) & 1; |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 847 | break; |
| 848 | default: |
| 849 | break; |
| 850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /* |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 855 | * read widget caps for each widget and store in cache |
| 856 | */ |
| 857 | static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) |
| 858 | { |
| 859 | int i; |
| 860 | hda_nid_t nid; |
| 861 | |
| 862 | codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, |
| 863 | &codec->start_nid); |
| 864 | codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 865 | if (!codec->wcaps) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 866 | return -ENOMEM; |
| 867 | nid = codec->start_nid; |
| 868 | for (i = 0; i < codec->num_nodes; i++, nid++) |
| 869 | codec->wcaps[i] = snd_hda_param_read(codec, nid, |
| 870 | AC_PAR_AUDIO_WIDGET_CAP); |
| 871 | return 0; |
| 872 | } |
| 873 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 874 | /* read all pin default configurations and save codec->init_pins */ |
| 875 | static int read_pin_defaults(struct hda_codec *codec) |
| 876 | { |
| 877 | int i; |
| 878 | hda_nid_t nid = codec->start_nid; |
| 879 | |
| 880 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 881 | struct hda_pincfg *pin; |
| 882 | unsigned int wcaps = get_wcaps(codec, nid); |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 883 | unsigned int wid_type = get_wcaps_type(wcaps); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 884 | if (wid_type != AC_WID_PIN) |
| 885 | continue; |
| 886 | pin = snd_array_new(&codec->init_pins); |
| 887 | if (!pin) |
| 888 | return -ENOMEM; |
| 889 | pin->nid = nid; |
| 890 | pin->cfg = snd_hda_codec_read(codec, nid, 0, |
| 891 | AC_VERB_GET_CONFIG_DEFAULT, 0); |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 892 | pin->ctrl = snd_hda_codec_read(codec, nid, 0, |
| 893 | AC_VERB_GET_PIN_WIDGET_CONTROL, |
| 894 | 0); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 895 | } |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | /* look up the given pin config list and return the item matching with NID */ |
| 900 | static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, |
| 901 | struct snd_array *array, |
| 902 | hda_nid_t nid) |
| 903 | { |
| 904 | int i; |
| 905 | for (i = 0; i < array->used; i++) { |
| 906 | struct hda_pincfg *pin = snd_array_elem(array, i); |
| 907 | if (pin->nid == nid) |
| 908 | return pin; |
| 909 | } |
| 910 | return NULL; |
| 911 | } |
| 912 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 913 | /* set the current pin config value for the given NID. |
| 914 | * the value is cached, and read via snd_hda_codec_get_pincfg() |
| 915 | */ |
| 916 | int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, |
| 917 | hda_nid_t nid, unsigned int cfg) |
| 918 | { |
| 919 | struct hda_pincfg *pin; |
| 920 | |
Takashi Iwai | d5657ec | 2013-04-18 09:59:28 +0200 | [diff] [blame] | 921 | /* the check below may be invalid when pins are added by a fixup |
| 922 | * dynamically (e.g. via snd_hda_codec_update_widgets()), so disabled |
| 923 | * for now |
| 924 | */ |
| 925 | /* |
Takashi Iwai | b82855a | 2009-12-27 11:24:56 +0100 | [diff] [blame] | 926 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) |
| 927 | return -EINVAL; |
Takashi Iwai | d5657ec | 2013-04-18 09:59:28 +0200 | [diff] [blame] | 928 | */ |
Takashi Iwai | b82855a | 2009-12-27 11:24:56 +0100 | [diff] [blame] | 929 | |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 930 | pin = look_up_pincfg(codec, list, nid); |
| 931 | if (!pin) { |
| 932 | pin = snd_array_new(list); |
| 933 | if (!pin) |
| 934 | return -ENOMEM; |
| 935 | pin->nid = nid; |
| 936 | } |
| 937 | pin->cfg = cfg; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 941 | /** |
| 942 | * snd_hda_codec_set_pincfg - Override a pin default configuration |
| 943 | * @codec: the HDA codec |
| 944 | * @nid: NID to set the pin config |
| 945 | * @cfg: the pin default config value |
| 946 | * |
| 947 | * Override a pin default configuration value in the cache. |
| 948 | * This value can be read by snd_hda_codec_get_pincfg() in a higher |
| 949 | * priority than the real hardware value. |
| 950 | */ |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 951 | int snd_hda_codec_set_pincfg(struct hda_codec *codec, |
| 952 | hda_nid_t nid, unsigned int cfg) |
| 953 | { |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 954 | return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 955 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 956 | EXPORT_SYMBOL_GPL(snd_hda_codec_set_pincfg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 957 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 958 | /** |
| 959 | * snd_hda_codec_get_pincfg - Obtain a pin-default configuration |
| 960 | * @codec: the HDA codec |
| 961 | * @nid: NID to get the pin config |
| 962 | * |
| 963 | * Get the current pin config value of the given pin NID. |
| 964 | * If the pincfg value is cached or overridden via sysfs or driver, |
| 965 | * returns the cached value. |
| 966 | */ |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 967 | unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) |
| 968 | { |
| 969 | struct hda_pincfg *pin; |
| 970 | |
Takashi Iwai | 648a8d2 | 2014-02-25 10:38:13 +0100 | [diff] [blame] | 971 | #ifdef CONFIG_SND_HDA_RECONFIG |
Takashi Iwai | 09b70e8 | 2013-01-10 18:21:56 +0100 | [diff] [blame] | 972 | { |
| 973 | unsigned int cfg = 0; |
| 974 | mutex_lock(&codec->user_mutex); |
| 975 | pin = look_up_pincfg(codec, &codec->user_pins, nid); |
| 976 | if (pin) |
| 977 | cfg = pin->cfg; |
| 978 | mutex_unlock(&codec->user_mutex); |
| 979 | if (cfg) |
| 980 | return cfg; |
| 981 | } |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 982 | #endif |
Takashi Iwai | 5e7b8e0 | 2009-02-23 09:45:59 +0100 | [diff] [blame] | 983 | pin = look_up_pincfg(codec, &codec->driver_pins, nid); |
| 984 | if (pin) |
| 985 | return pin->cfg; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 986 | pin = look_up_pincfg(codec, &codec->init_pins, nid); |
| 987 | if (pin) |
| 988 | return pin->cfg; |
| 989 | return 0; |
| 990 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 991 | EXPORT_SYMBOL_GPL(snd_hda_codec_get_pincfg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 992 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 993 | /** |
| 994 | * snd_hda_codec_set_pin_target - remember the current pinctl target value |
| 995 | * @codec: the HDA codec |
| 996 | * @nid: pin NID |
| 997 | * @val: assigned pinctl value |
| 998 | * |
| 999 | * This function stores the given value to a pinctl target value in the |
| 1000 | * pincfg table. This isn't always as same as the actually written value |
| 1001 | * but can be referred at any time via snd_hda_codec_get_pin_target(). |
| 1002 | */ |
Takashi Iwai | d7fdc00 | 2013-01-10 08:38:04 +0100 | [diff] [blame] | 1003 | int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, |
| 1004 | unsigned int val) |
| 1005 | { |
| 1006 | struct hda_pincfg *pin; |
| 1007 | |
| 1008 | pin = look_up_pincfg(codec, &codec->init_pins, nid); |
| 1009 | if (!pin) |
| 1010 | return -EINVAL; |
| 1011 | pin->target = val; |
| 1012 | return 0; |
| 1013 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1014 | EXPORT_SYMBOL_GPL(snd_hda_codec_set_pin_target); |
Takashi Iwai | d7fdc00 | 2013-01-10 08:38:04 +0100 | [diff] [blame] | 1015 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 1016 | /** |
| 1017 | * snd_hda_codec_get_pin_target - return the current pinctl target value |
| 1018 | * @codec: the HDA codec |
| 1019 | * @nid: pin NID |
| 1020 | */ |
Takashi Iwai | d7fdc00 | 2013-01-10 08:38:04 +0100 | [diff] [blame] | 1021 | int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) |
| 1022 | { |
| 1023 | struct hda_pincfg *pin; |
| 1024 | |
| 1025 | pin = look_up_pincfg(codec, &codec->init_pins, nid); |
| 1026 | if (!pin) |
| 1027 | return 0; |
| 1028 | return pin->target; |
| 1029 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1030 | EXPORT_SYMBOL_GPL(snd_hda_codec_get_pin_target); |
Takashi Iwai | d7fdc00 | 2013-01-10 08:38:04 +0100 | [diff] [blame] | 1031 | |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 1032 | /** |
| 1033 | * snd_hda_shutup_pins - Shut up all pins |
| 1034 | * @codec: the HDA codec |
| 1035 | * |
| 1036 | * Clear all pin controls to shup up before suspend for avoiding click noise. |
| 1037 | * The controls aren't cached so that they can be resumed properly. |
| 1038 | */ |
| 1039 | void snd_hda_shutup_pins(struct hda_codec *codec) |
| 1040 | { |
| 1041 | int i; |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 1042 | /* don't shut up pins when unloading the driver; otherwise it breaks |
| 1043 | * the default pin setup at the next load of the driver |
| 1044 | */ |
| 1045 | if (codec->bus->shutdown) |
| 1046 | return; |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 1047 | for (i = 0; i < codec->init_pins.used; i++) { |
| 1048 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 1049 | /* use read here for syncing after issuing each verb */ |
| 1050 | snd_hda_codec_read(codec, pin->nid, 0, |
| 1051 | AC_VERB_SET_PIN_WIDGET_CONTROL, 0); |
| 1052 | } |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 1053 | codec->pins_shutup = 1; |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 1054 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1055 | EXPORT_SYMBOL_GPL(snd_hda_shutup_pins); |
Takashi Iwai | 92ee616 | 2009-12-27 11:18:59 +0100 | [diff] [blame] | 1056 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 1057 | #ifdef CONFIG_PM |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 1058 | /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */ |
| 1059 | static void restore_shutup_pins(struct hda_codec *codec) |
| 1060 | { |
| 1061 | int i; |
| 1062 | if (!codec->pins_shutup) |
| 1063 | return; |
| 1064 | if (codec->bus->shutdown) |
| 1065 | return; |
| 1066 | for (i = 0; i < codec->init_pins.used; i++) { |
| 1067 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 1068 | snd_hda_codec_write(codec, pin->nid, 0, |
| 1069 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1070 | pin->ctrl); |
| 1071 | } |
| 1072 | codec->pins_shutup = 0; |
| 1073 | } |
Mike Waychison | 1c7276c | 2011-04-20 12:04:36 -0700 | [diff] [blame] | 1074 | #endif |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 1075 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1076 | static void hda_jackpoll_work(struct work_struct *work) |
| 1077 | { |
| 1078 | struct hda_codec *codec = |
| 1079 | container_of(work, struct hda_codec, jackpoll_work.work); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1080 | |
| 1081 | snd_hda_jack_set_dirty_all(codec); |
| 1082 | snd_hda_jack_poll_all(codec); |
Wang Xingchao | 18e6062 | 2013-07-25 23:34:45 -0400 | [diff] [blame] | 1083 | |
| 1084 | if (!codec->jackpoll_interval) |
| 1085 | return; |
| 1086 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1087 | queue_delayed_work(codec->bus->workq, &codec->jackpoll_work, |
| 1088 | codec->jackpoll_interval); |
| 1089 | } |
| 1090 | |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1091 | static void init_hda_cache(struct hda_cache_rec *cache, |
| 1092 | unsigned int record_size); |
Takashi Iwai | 1fcaee6 | 2007-08-23 00:01:09 +0200 | [diff] [blame] | 1093 | static void free_hda_cache(struct hda_cache_rec *cache); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1094 | |
Takashi Iwai | 3fdf146 | 2012-11-22 08:16:31 +0100 | [diff] [blame] | 1095 | /* release all pincfg lists */ |
| 1096 | static void free_init_pincfgs(struct hda_codec *codec) |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1097 | { |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 1098 | snd_array_free(&codec->driver_pins); |
Takashi Iwai | 648a8d2 | 2014-02-25 10:38:13 +0100 | [diff] [blame] | 1099 | #ifdef CONFIG_SND_HDA_RECONFIG |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 1100 | snd_array_free(&codec->user_pins); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1101 | #endif |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1102 | snd_array_free(&codec->init_pins); |
| 1103 | } |
| 1104 | |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1105 | /* |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1106 | * audio-converter setup caches |
| 1107 | */ |
| 1108 | struct hda_cvt_setup { |
| 1109 | hda_nid_t nid; |
| 1110 | u8 stream_tag; |
| 1111 | u8 channel_id; |
| 1112 | u16 format_id; |
| 1113 | unsigned char active; /* cvt is currently used */ |
| 1114 | unsigned char dirty; /* setups should be cleared */ |
| 1115 | }; |
| 1116 | |
| 1117 | /* get or create a cache entry for the given audio converter NID */ |
| 1118 | static struct hda_cvt_setup * |
| 1119 | get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) |
| 1120 | { |
| 1121 | struct hda_cvt_setup *p; |
| 1122 | int i; |
| 1123 | |
| 1124 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 1125 | p = snd_array_elem(&codec->cvt_setups, i); |
| 1126 | if (p->nid == nid) |
| 1127 | return p; |
| 1128 | } |
| 1129 | p = snd_array_new(&codec->cvt_setups); |
| 1130 | if (p) |
| 1131 | p->nid = nid; |
| 1132 | return p; |
| 1133 | } |
| 1134 | |
| 1135 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | * codec destructor |
| 1137 | */ |
| 1138 | static void snd_hda_codec_free(struct hda_codec *codec) |
| 1139 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1140 | if (!codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | return; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1142 | cancel_delayed_work_sync(&codec->jackpoll_work); |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1143 | if (device_is_registered(hda_codec_dev(codec))) |
| 1144 | device_del(hda_codec_dev(codec)); |
Takashi Iwai | 59cad16 | 2012-06-26 15:00:20 +0200 | [diff] [blame] | 1145 | snd_hda_jack_tbl_clear(codec); |
Takashi Iwai | 3fdf146 | 2012-11-22 08:16:31 +0100 | [diff] [blame] | 1146 | free_init_pincfgs(codec); |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1147 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1148 | cancel_delayed_work(&codec->power_work); |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 1149 | flush_workqueue(codec->bus->workq); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1150 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | list_del(&codec->list); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1152 | snd_array_free(&codec->mixers); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1153 | snd_array_free(&codec->nids); |
Takashi Iwai | 59cad16 | 2012-06-26 15:00:20 +0200 | [diff] [blame] | 1154 | snd_array_free(&codec->cvt_setups); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1155 | snd_array_free(&codec->spdif_out); |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 1156 | remove_conn_list(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | codec->bus->caddr_tbl[codec->addr] = NULL; |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 1158 | hda_call_pm_notify(codec, false); /* cancel leftover refcounts */ |
Takashi Iwai | 648a8d2 | 2014-02-25 10:38:13 +0100 | [diff] [blame] | 1159 | snd_hda_sysfs_clear(codec); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1160 | free_hda_cache(&codec->amp_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1161 | free_hda_cache(&codec->cmd_cache); |
Takashi Iwai | 812a2cc | 2009-05-16 10:00:49 +0200 | [diff] [blame] | 1162 | kfree(codec->vendor_name); |
| 1163 | kfree(codec->chip_name); |
Takashi Iwai | f44ac83 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1164 | kfree(codec->modelname); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1165 | kfree(codec->wcaps); |
Mengdong Lin | 0e24dbb | 2013-11-26 23:00:51 -0500 | [diff] [blame] | 1166 | codec->bus->num_codecs--; |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1167 | put_device(hda_codec_dev(codec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1170 | static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, |
| 1171 | hda_nid_t fg, unsigned int power_state); |
| 1172 | |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1173 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
Takashi Iwai | bb6ac72 | 2009-03-13 09:02:42 +0100 | [diff] [blame] | 1174 | unsigned int power_state); |
| 1175 | |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1176 | static int snd_hda_codec_dev_register(struct snd_device *device) |
| 1177 | { |
| 1178 | struct hda_codec *codec = device->device_data; |
| 1179 | |
Takashi Iwai | d604b39 | 2014-02-28 13:42:09 +0100 | [diff] [blame] | 1180 | snd_hda_register_beep_device(codec); |
| 1181 | return 0; |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static int snd_hda_codec_dev_disconnect(struct snd_device *device) |
| 1185 | { |
| 1186 | struct hda_codec *codec = device->device_data; |
| 1187 | |
Takashi Iwai | d604b39 | 2014-02-28 13:42:09 +0100 | [diff] [blame] | 1188 | snd_hda_detach_beep_device(codec); |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1189 | return 0; |
| 1190 | } |
| 1191 | |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 1192 | static int snd_hda_codec_dev_free(struct snd_device *device) |
| 1193 | { |
| 1194 | snd_hda_codec_free(device->device_data); |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1198 | /* just free the container */ |
| 1199 | static void snd_hda_codec_dev_release(struct device *dev) |
| 1200 | { |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1201 | kfree(dev_to_hda_codec(dev)); |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1202 | } |
| 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | /** |
| 1205 | * snd_hda_codec_new - create a HDA codec |
| 1206 | * @bus: the bus to assign |
| 1207 | * @codec_addr: the codec address |
| 1208 | * @codecp: the pointer to store the generated codec |
| 1209 | * |
| 1210 | * Returns 0 if successful, or a negative error code. |
| 1211 | */ |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 1212 | int snd_hda_codec_new(struct hda_bus *bus, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1213 | unsigned int codec_addr, |
| 1214 | struct hda_codec **codecp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
| 1216 | struct hda_codec *codec; |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1217 | struct device *dev; |
Jaroslav Kysela | ba44368 | 2008-08-13 20:55:32 +0200 | [diff] [blame] | 1218 | char component[31]; |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1219 | hda_nid_t fg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | int err; |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 1221 | static struct snd_device_ops dev_ops = { |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1222 | .dev_register = snd_hda_codec_dev_register, |
| 1223 | .dev_disconnect = snd_hda_codec_dev_disconnect, |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 1224 | .dev_free = snd_hda_codec_dev_free, |
| 1225 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1227 | if (snd_BUG_ON(!bus)) |
| 1228 | return -EINVAL; |
| 1229 | if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) |
| 1230 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
| 1232 | if (bus->caddr_tbl[codec_addr]) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1233 | dev_err(bus->card->dev, |
| 1234 | "address 0x%x is already occupied\n", |
| 1235 | codec_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | return -EBUSY; |
| 1237 | } |
| 1238 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1239 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | if (codec == NULL) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1241 | dev_err(bus->card->dev, "can't allocate struct hda_codec\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | return -ENOMEM; |
| 1243 | } |
| 1244 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1245 | dev = hda_codec_dev(codec); |
| 1246 | device_initialize(dev); |
| 1247 | dev->parent = bus->card->dev; |
| 1248 | dev->bus = &snd_hda_bus_type; |
| 1249 | dev->release = snd_hda_codec_dev_release; |
| 1250 | dev->groups = snd_hda_dev_attr_groups; |
| 1251 | dev_set_name(dev, "hdaudioC%dD%d", bus->card->number, codec_addr); |
| 1252 | dev_set_drvdata(dev, codec); /* for sysfs */ |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 1253 | device_enable_async_suspend(dev); |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | codec->bus = bus; |
| 1256 | codec->addr = codec_addr; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1257 | mutex_init(&codec->spdif_mutex); |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 1258 | mutex_init(&codec->control_mutex); |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1259 | mutex_init(&codec->hash_mutex); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1260 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 1261 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1262 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); |
| 1263 | snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1264 | snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 1265 | snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1266 | snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1267 | snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 1268 | snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 1269 | snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 1270 | INIT_LIST_HEAD(&codec->conn_list); |
| 1271 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1272 | INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); |
Mengdong Lin | 7f13292 | 2013-11-29 01:48:45 -0500 | [diff] [blame] | 1273 | codec->depop_delay = -1; |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 1274 | codec->fixup_id = HDA_FIXUP_ID_NOT_SET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1276 | #ifdef CONFIG_PM |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 1277 | spin_lock_init(&codec->power_lock); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1278 | INIT_DELAYED_WORK(&codec->power_work, hda_power_work); |
| 1279 | /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. |
| 1280 | * the caller has to power down appropriatley after initialization |
| 1281 | * phase. |
| 1282 | */ |
| 1283 | hda_keep_power_on(codec); |
| 1284 | #endif |
| 1285 | |
Takashi Iwai | 648a8d2 | 2014-02-25 10:38:13 +0100 | [diff] [blame] | 1286 | snd_hda_sysfs_init(codec); |
| 1287 | |
Takashi Iwai | c382a9f | 2012-05-07 15:01:02 +0200 | [diff] [blame] | 1288 | if (codec->bus->modelname) { |
| 1289 | codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); |
| 1290 | if (!codec->modelname) { |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 1291 | err = -ENODEV; |
| 1292 | goto error; |
Takashi Iwai | c382a9f | 2012-05-07 15:01:02 +0200 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | list_add_tail(&codec->list, &bus->codec_list); |
Mengdong Lin | 0e24dbb | 2013-11-26 23:00:51 -0500 | [diff] [blame] | 1297 | bus->num_codecs++; |
Mengdong Lin | 0e24dbb | 2013-11-26 23:00:51 -0500 | [diff] [blame] | 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | bus->caddr_tbl[codec_addr] = codec; |
| 1300 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1301 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1302 | AC_PAR_VENDOR_ID); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 1303 | if (codec->vendor_id == -1) |
| 1304 | /* read again, hopefully the access method was corrected |
| 1305 | * in the last read... |
| 1306 | */ |
| 1307 | codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1308 | AC_PAR_VENDOR_ID); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1309 | codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1310 | AC_PAR_SUBSYSTEM_ID); |
| 1311 | codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, |
| 1312 | AC_PAR_REV_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 1314 | setup_fg_nodes(codec); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1315 | if (!codec->afg && !codec->mfg) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1316 | dev_err(bus->card->dev, "no AFG or MFG node found\n"); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1317 | err = -ENODEV; |
| 1318 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1321 | fg = codec->afg ? codec->afg : codec->mfg; |
| 1322 | err = read_widget_caps(codec, fg); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1323 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1324 | dev_err(bus->card->dev, "cannot malloc\n"); |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1325 | goto error; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1326 | } |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1327 | err = read_pin_defaults(codec); |
| 1328 | if (err < 0) |
| 1329 | goto error; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1330 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1331 | if (!codec->subsystem_id) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1332 | codec->subsystem_id = |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1333 | snd_hda_codec_read(codec, fg, 0, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1334 | AC_VERB_GET_SUBSYSTEM_ID, 0); |
Takashi Iwai | 86284e4 | 2005-10-11 15:05:54 +0200 | [diff] [blame] | 1335 | } |
| 1336 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1337 | #ifdef CONFIG_PM |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1338 | codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec, fg, |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1339 | AC_PWRST_CLKSTOP); |
Mengdong Lin | 5d6147f | 2012-08-24 12:06:30 +0800 | [diff] [blame] | 1340 | #endif |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1341 | codec->epss = snd_hda_codec_get_supported_ps(codec, fg, |
Takashi Iwai | 983f6b9 | 2012-08-28 09:18:01 -0700 | [diff] [blame] | 1342 | AC_PWRST_EPSS); |
Takashi Iwai | 3e9bc58 | 2013-11-26 09:58:46 +0100 | [diff] [blame] | 1343 | #ifdef CONFIG_PM |
| 1344 | if (!codec->d3_stop_clk || !codec->epss) |
| 1345 | bus->power_keep_link_on = 1; |
| 1346 | #endif |
| 1347 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1348 | |
Takashi Iwai | bb6ac72 | 2009-03-13 09:02:42 +0100 | [diff] [blame] | 1349 | /* power-up all before initialization */ |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 1350 | hda_set_power_state(codec, AC_PWRST_D0); |
Takashi Iwai | bb6ac72 | 2009-03-13 09:02:42 +0100 | [diff] [blame] | 1351 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1352 | snd_hda_codec_proc_new(codec); |
| 1353 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1354 | snd_hda_create_hwdep(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1355 | |
| 1356 | sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, |
| 1357 | codec->subsystem_id, codec->revision_id); |
| 1358 | snd_component_add(codec->bus->card, component); |
| 1359 | |
Takashi Iwai | 2565c89 | 2014-02-19 11:41:09 +0100 | [diff] [blame] | 1360 | err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); |
| 1361 | if (err < 0) |
| 1362 | goto error; |
| 1363 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1364 | if (codecp) |
| 1365 | *codecp = codec; |
| 1366 | return 0; |
Takashi Iwai | 3be1414 | 2009-02-20 14:11:16 +0100 | [diff] [blame] | 1367 | |
| 1368 | error: |
| 1369 | snd_hda_codec_free(codec); |
| 1370 | return err; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1371 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1372 | EXPORT_SYMBOL_GPL(snd_hda_codec_new); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 1373 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 1374 | /** |
| 1375 | * snd_hda_codec_update_widgets - Refresh widget caps and pin defaults |
| 1376 | * @codec: the HDA codec |
| 1377 | * |
| 1378 | * Forcibly refresh the all widget caps and the init pin configurations of |
| 1379 | * the given codec. |
| 1380 | */ |
Mengdong Lin | a15d05d | 2013-02-08 17:09:31 -0500 | [diff] [blame] | 1381 | int snd_hda_codec_update_widgets(struct hda_codec *codec) |
| 1382 | { |
| 1383 | hda_nid_t fg; |
| 1384 | int err; |
| 1385 | |
| 1386 | /* Assume the function group node does not change, |
| 1387 | * only the widget nodes may change. |
| 1388 | */ |
| 1389 | kfree(codec->wcaps); |
| 1390 | fg = codec->afg ? codec->afg : codec->mfg; |
| 1391 | err = read_widget_caps(codec, fg); |
| 1392 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1393 | codec_err(codec, "cannot malloc\n"); |
Mengdong Lin | a15d05d | 2013-02-08 17:09:31 -0500 | [diff] [blame] | 1394 | return err; |
| 1395 | } |
| 1396 | |
| 1397 | snd_array_free(&codec->init_pins); |
| 1398 | err = read_pin_defaults(codec); |
| 1399 | |
| 1400 | return err; |
| 1401 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1402 | EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); |
Mengdong Lin | a15d05d | 2013-02-08 17:09:31 -0500 | [diff] [blame] | 1403 | |
Takashi Iwai | ed36081 | 2012-08-08 17:12:52 +0200 | [diff] [blame] | 1404 | /* update the stream-id if changed */ |
| 1405 | static void update_pcm_stream_id(struct hda_codec *codec, |
| 1406 | struct hda_cvt_setup *p, hda_nid_t nid, |
| 1407 | u32 stream_tag, int channel_id) |
| 1408 | { |
| 1409 | unsigned int oldval, newval; |
| 1410 | |
| 1411 | if (p->stream_tag != stream_tag || p->channel_id != channel_id) { |
| 1412 | oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); |
| 1413 | newval = (stream_tag << 4) | channel_id; |
| 1414 | if (oldval != newval) |
| 1415 | snd_hda_codec_write(codec, nid, 0, |
| 1416 | AC_VERB_SET_CHANNEL_STREAMID, |
| 1417 | newval); |
| 1418 | p->stream_tag = stream_tag; |
| 1419 | p->channel_id = channel_id; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | /* update the format-id if changed */ |
| 1424 | static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, |
| 1425 | hda_nid_t nid, int format) |
| 1426 | { |
| 1427 | unsigned int oldval; |
| 1428 | |
| 1429 | if (p->format_id != format) { |
| 1430 | oldval = snd_hda_codec_read(codec, nid, 0, |
| 1431 | AC_VERB_GET_STREAM_FORMAT, 0); |
| 1432 | if (oldval != format) { |
| 1433 | msleep(1); |
| 1434 | snd_hda_codec_write(codec, nid, 0, |
| 1435 | AC_VERB_SET_STREAM_FORMAT, |
| 1436 | format); |
| 1437 | } |
| 1438 | p->format_id = format; |
| 1439 | } |
| 1440 | } |
| 1441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | /** |
| 1443 | * snd_hda_codec_setup_stream - set up the codec for streaming |
| 1444 | * @codec: the CODEC to set up |
| 1445 | * @nid: the NID to set up |
| 1446 | * @stream_tag: stream tag to pass, it's between 0x1 and 0xf. |
| 1447 | * @channel_id: channel id to pass, zero based. |
| 1448 | * @format: stream format. |
| 1449 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1450 | void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, |
| 1451 | u32 stream_tag, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | int channel_id, int format) |
| 1453 | { |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 1454 | struct hda_codec *c; |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1455 | struct hda_cvt_setup *p; |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1456 | int type; |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1457 | int i; |
| 1458 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1459 | if (!nid) |
Takashi Iwai | d21b37e | 2005-04-20 13:45:55 +0200 | [diff] [blame] | 1460 | return; |
| 1461 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1462 | codec_dbg(codec, |
| 1463 | "hda_codec_setup_stream: NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", |
| 1464 | nid, stream_tag, channel_id, format); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1465 | p = get_hda_cvt_setup(codec, nid); |
Takashi Iwai | 6c35ae3 | 2013-05-10 13:39:50 +0200 | [diff] [blame] | 1466 | if (!p) |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1467 | return; |
Takashi Iwai | ed36081 | 2012-08-08 17:12:52 +0200 | [diff] [blame] | 1468 | |
| 1469 | if (codec->pcm_format_first) |
| 1470 | update_pcm_format(codec, p, nid, format); |
| 1471 | update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); |
| 1472 | if (!codec->pcm_format_first) |
| 1473 | update_pcm_format(codec, p, nid, format); |
| 1474 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1475 | p->active = 1; |
| 1476 | p->dirty = 0; |
| 1477 | |
| 1478 | /* make other inactive cvts with the same stream-tag dirty */ |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1479 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 1480 | list_for_each_entry(c, &codec->bus->codec_list, list) { |
| 1481 | for (i = 0; i < c->cvt_setups.used; i++) { |
| 1482 | p = snd_array_elem(&c->cvt_setups, i); |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1483 | if (!p->active && p->stream_tag == stream_tag && |
David Henningsson | 54c2a89 | 2012-02-01 12:05:41 +0100 | [diff] [blame] | 1484 | get_wcaps_type(get_wcaps(c, p->nid)) == type) |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 1485 | p->dirty = 1; |
| 1486 | } |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1489 | EXPORT_SYMBOL_GPL(snd_hda_codec_setup_stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1491 | static void really_cleanup_stream(struct hda_codec *codec, |
| 1492 | struct hda_cvt_setup *q); |
| 1493 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1494 | /** |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1495 | * __snd_hda_codec_cleanup_stream - clean up the codec for closing |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1496 | * @codec: the CODEC to clean up |
| 1497 | * @nid: the NID to clean up |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1498 | * @do_now: really clean up the stream instead of clearing the active flag |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1499 | */ |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1500 | void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, |
| 1501 | int do_now) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1502 | { |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1503 | struct hda_cvt_setup *p; |
| 1504 | |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1505 | if (!nid) |
| 1506 | return; |
| 1507 | |
Takashi Iwai | 0e7adbe | 2010-10-25 10:37:11 +0200 | [diff] [blame] | 1508 | if (codec->no_sticky_stream) |
| 1509 | do_now = 1; |
| 1510 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1511 | codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1512 | p = get_hda_cvt_setup(codec, nid); |
Takashi Iwai | 6c35ae3 | 2013-05-10 13:39:50 +0200 | [diff] [blame] | 1513 | if (p) { |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1514 | /* here we just clear the active flag when do_now isn't set; |
| 1515 | * actual clean-ups will be done later in |
| 1516 | * purify_inactive_streams() called from snd_hda_codec_prpapre() |
| 1517 | */ |
| 1518 | if (do_now) |
| 1519 | really_cleanup_stream(codec, p); |
| 1520 | else |
| 1521 | p->active = 0; |
| 1522 | } |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1523 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1524 | EXPORT_SYMBOL_GPL(__snd_hda_codec_cleanup_stream); |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1525 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1526 | static void really_cleanup_stream(struct hda_codec *codec, |
| 1527 | struct hda_cvt_setup *q) |
| 1528 | { |
| 1529 | hda_nid_t nid = q->nid; |
Takashi Iwai | 218264a | 2011-09-27 17:33:45 +0200 | [diff] [blame] | 1530 | if (q->stream_tag || q->channel_id) |
| 1531 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 1532 | if (q->format_id) |
| 1533 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 |
| 1534 | ); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1535 | memset(q, 0, sizeof(*q)); |
| 1536 | q->nid = nid; |
| 1537 | } |
| 1538 | |
| 1539 | /* clean up the all conflicting obsolete streams */ |
| 1540 | static void purify_inactive_streams(struct hda_codec *codec) |
| 1541 | { |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 1542 | struct hda_codec *c; |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1543 | int i; |
| 1544 | |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 1545 | list_for_each_entry(c, &codec->bus->codec_list, list) { |
| 1546 | for (i = 0; i < c->cvt_setups.used; i++) { |
| 1547 | struct hda_cvt_setup *p; |
| 1548 | p = snd_array_elem(&c->cvt_setups, i); |
| 1549 | if (p->dirty) |
| 1550 | really_cleanup_stream(c, p); |
| 1551 | } |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 1555 | #ifdef CONFIG_PM |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1556 | /* clean up all streams; called from suspend */ |
| 1557 | static void hda_cleanup_all_streams(struct hda_codec *codec) |
| 1558 | { |
| 1559 | int i; |
| 1560 | |
| 1561 | for (i = 0; i < codec->cvt_setups.used; i++) { |
| 1562 | struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); |
| 1563 | if (p->stream_tag) |
| 1564 | really_cleanup_stream(codec, p); |
| 1565 | } |
| 1566 | } |
Mike Waychison | 1c7276c | 2011-04-20 12:04:36 -0700 | [diff] [blame] | 1567 | #endif |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | /* |
| 1570 | * amp access functions |
| 1571 | */ |
| 1572 | |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1573 | /* FIXME: more better hash key? */ |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 1574 | #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] | 1575 | #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1576 | #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) |
| 1577 | #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | #define INFO_AMP_CAPS (1<<0) |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1579 | #define INFO_AMP_VOL(ch) (1 << (1 + (ch))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | |
| 1581 | /* initialize the hash table */ |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 1582 | static void init_hda_cache(struct hda_cache_rec *cache, |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1583 | unsigned int record_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | { |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1585 | memset(cache, 0, sizeof(*cache)); |
| 1586 | memset(cache->hash, 0xff, sizeof(cache->hash)); |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1587 | snd_array_init(&cache->buf, record_size, 64); |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1588 | } |
| 1589 | |
Takashi Iwai | 1fcaee6 | 2007-08-23 00:01:09 +0200 | [diff] [blame] | 1590 | static void free_hda_cache(struct hda_cache_rec *cache) |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1591 | { |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1592 | snd_array_free(&cache->buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | /* query the hash. allocate an entry if not found. */ |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1596 | static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1598 | u16 idx = key % (u16)ARRAY_SIZE(cache->hash); |
| 1599 | u16 cur = cache->hash[idx]; |
| 1600 | struct hda_cache_head *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
| 1602 | while (cur != 0xffff) { |
Takashi Iwai | f43aa02 | 2008-11-10 16:24:26 +0100 | [diff] [blame] | 1603 | info = snd_array_elem(&cache->buf, cur); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | if (info->key == key) |
| 1605 | return info; |
| 1606 | cur = info->next; |
| 1607 | } |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1608 | return NULL; |
| 1609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1611 | /* query the hash. allocate an entry if not found. */ |
| 1612 | static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, |
| 1613 | u32 key) |
| 1614 | { |
| 1615 | struct hda_cache_head *info = get_hash(cache, key); |
| 1616 | if (!info) { |
| 1617 | u16 idx, cur; |
| 1618 | /* add a new hash entry */ |
| 1619 | info = snd_array_new(&cache->buf); |
| 1620 | if (!info) |
| 1621 | return NULL; |
| 1622 | cur = snd_array_index(&cache->buf, info); |
| 1623 | info->key = key; |
| 1624 | info->val = 0; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 1625 | info->dirty = 0; |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 1626 | idx = key % (u16)ARRAY_SIZE(cache->hash); |
| 1627 | info->next = cache->hash[idx]; |
| 1628 | cache->hash[idx] = cur; |
| 1629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | return info; |
| 1631 | } |
| 1632 | |
Takashi Iwai | 01751f5 | 2007-08-10 16:59:39 +0200 | [diff] [blame] | 1633 | /* query and allocate an amp hash entry */ |
| 1634 | static inline struct hda_amp_info * |
| 1635 | get_alloc_amp_hash(struct hda_codec *codec, u32 key) |
| 1636 | { |
| 1637 | return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); |
| 1638 | } |
| 1639 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1640 | /* overwrite the value with the key in the caps hash */ |
| 1641 | static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val) |
| 1642 | { |
| 1643 | struct hda_amp_info *info; |
| 1644 | |
| 1645 | mutex_lock(&codec->hash_mutex); |
| 1646 | info = get_alloc_amp_hash(codec, key); |
| 1647 | if (!info) { |
| 1648 | mutex_unlock(&codec->hash_mutex); |
| 1649 | return -EINVAL; |
| 1650 | } |
| 1651 | info->amp_caps = val; |
| 1652 | info->head.val |= INFO_AMP_CAPS; |
| 1653 | mutex_unlock(&codec->hash_mutex); |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
| 1657 | /* query the value from the caps hash; if not found, fetch the current |
| 1658 | * value from the given function and store in the hash |
| 1659 | */ |
| 1660 | static unsigned int |
| 1661 | query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key, |
| 1662 | unsigned int (*func)(struct hda_codec *, hda_nid_t, int)) |
| 1663 | { |
| 1664 | struct hda_amp_info *info; |
| 1665 | unsigned int val; |
| 1666 | |
| 1667 | mutex_lock(&codec->hash_mutex); |
| 1668 | info = get_alloc_amp_hash(codec, key); |
| 1669 | if (!info) { |
| 1670 | mutex_unlock(&codec->hash_mutex); |
| 1671 | return 0; |
| 1672 | } |
| 1673 | if (!(info->head.val & INFO_AMP_CAPS)) { |
| 1674 | mutex_unlock(&codec->hash_mutex); /* for reentrance */ |
| 1675 | val = func(codec, nid, dir); |
| 1676 | write_caps_hash(codec, key, val); |
| 1677 | } else { |
| 1678 | val = info->amp_caps; |
| 1679 | mutex_unlock(&codec->hash_mutex); |
| 1680 | } |
| 1681 | return val; |
| 1682 | } |
| 1683 | |
| 1684 | static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, |
| 1685 | int direction) |
| 1686 | { |
| 1687 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) |
| 1688 | nid = codec->afg; |
| 1689 | return snd_hda_param_read(codec, nid, |
| 1690 | direction == HDA_OUTPUT ? |
| 1691 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); |
| 1692 | } |
| 1693 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1694 | /** |
| 1695 | * query_amp_caps - query AMP capabilities |
| 1696 | * @codec: the HD-auio codec |
| 1697 | * @nid: the NID to query |
| 1698 | * @direction: either #HDA_INPUT or #HDA_OUTPUT |
| 1699 | * |
| 1700 | * Query AMP capabilities for the given widget and direction. |
| 1701 | * Returns the obtained capability bits. |
| 1702 | * |
| 1703 | * When cap bits have been already read, this doesn't read again but |
| 1704 | * returns the cached value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | */ |
Matthew Ranostay | 09a9995 | 2008-01-24 11:49:21 +0100 | [diff] [blame] | 1706 | 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] | 1707 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1708 | return query_caps_hash(codec, nid, direction, |
| 1709 | HDA_HASH_KEY(nid, direction, 0), |
| 1710 | read_amp_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1712 | EXPORT_SYMBOL_GPL(query_amp_caps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1714 | /** |
David Henningsson | 861a04e | 2014-09-23 10:38:17 +0200 | [diff] [blame] | 1715 | * snd_hda_check_amp_caps - query AMP capabilities |
| 1716 | * @codec: the HD-audio codec |
| 1717 | * @nid: the NID to query |
| 1718 | * @dir: either #HDA_INPUT or #HDA_OUTPUT |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 1719 | * @bits: bit mask to check the result |
David Henningsson | 861a04e | 2014-09-23 10:38:17 +0200 | [diff] [blame] | 1720 | * |
| 1721 | * Check whether the widget has the given amp capability for the direction. |
| 1722 | */ |
| 1723 | bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 1724 | int dir, unsigned int bits) |
| 1725 | { |
| 1726 | if (!nid) |
| 1727 | return false; |
| 1728 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 1729 | if (query_amp_caps(codec, nid, dir) & bits) |
| 1730 | return true; |
| 1731 | return false; |
| 1732 | } |
| 1733 | EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps); |
| 1734 | |
| 1735 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1736 | * snd_hda_override_amp_caps - Override the AMP capabilities |
| 1737 | * @codec: the CODEC to clean up |
| 1738 | * @nid: the NID to clean up |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 1739 | * @dir: either #HDA_INPUT or #HDA_OUTPUT |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1740 | * @caps: the capability bits to set |
| 1741 | * |
| 1742 | * Override the cached AMP caps bits value by the given one. |
| 1743 | * This function is useful if the driver needs to adjust the AMP ranges, |
| 1744 | * e.g. limit to 0dB, etc. |
| 1745 | * |
| 1746 | * Returns zero if successful or a negative error code. |
| 1747 | */ |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1748 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 1749 | unsigned int caps) |
| 1750 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1751 | return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1752 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1753 | EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); |
Takashi Iwai | 897cc18 | 2007-05-29 19:01:37 +0200 | [diff] [blame] | 1754 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1755 | static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid, |
| 1756 | int dir) |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1757 | { |
| 1758 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); |
| 1759 | } |
| 1760 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1761 | /** |
| 1762 | * snd_hda_query_pin_caps - Query PIN capabilities |
| 1763 | * @codec: the HD-auio codec |
| 1764 | * @nid: the NID to query |
| 1765 | * |
| 1766 | * Query PIN capabilities for the given widget. |
| 1767 | * Returns the obtained capability bits. |
| 1768 | * |
| 1769 | * When cap bits have been already read, this doesn't read again but |
| 1770 | * returns the cached value. |
| 1771 | */ |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1772 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) |
| 1773 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1774 | return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid), |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 1775 | read_pin_cap); |
| 1776 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1777 | EXPORT_SYMBOL_GPL(snd_hda_query_pin_caps); |
Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 1778 | |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 1779 | /** |
Takashi Iwai | f57c256 | 2011-08-15 12:49:07 +0200 | [diff] [blame] | 1780 | * snd_hda_override_pin_caps - Override the pin capabilities |
| 1781 | * @codec: the CODEC |
| 1782 | * @nid: the NID to override |
| 1783 | * @caps: the capability bits to set |
| 1784 | * |
| 1785 | * Override the cached PIN capabilitiy bits value by the given one. |
| 1786 | * |
| 1787 | * Returns zero if successful or a negative error code. |
| 1788 | */ |
| 1789 | int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, |
| 1790 | unsigned int caps) |
| 1791 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1792 | return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps); |
Takashi Iwai | f57c256 | 2011-08-15 12:49:07 +0200 | [diff] [blame] | 1793 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1794 | EXPORT_SYMBOL_GPL(snd_hda_override_pin_caps); |
Takashi Iwai | f57c256 | 2011-08-15 12:49:07 +0200 | [diff] [blame] | 1795 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1796 | /* read or sync the hash value with the current value; |
| 1797 | * call within hash_mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | */ |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1799 | static struct hda_amp_info * |
| 1800 | update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1801 | int direction, int index, bool init_only) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1803 | struct hda_amp_info *info; |
| 1804 | unsigned int parm, val = 0; |
| 1805 | bool val_read = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1807 | retry: |
| 1808 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); |
| 1809 | if (!info) |
| 1810 | return NULL; |
| 1811 | if (!(info->head.val & INFO_AMP_VOL(ch))) { |
| 1812 | if (!val_read) { |
| 1813 | mutex_unlock(&codec->hash_mutex); |
| 1814 | parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; |
| 1815 | parm |= direction == HDA_OUTPUT ? |
| 1816 | AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; |
| 1817 | parm |= index; |
| 1818 | val = snd_hda_codec_read(codec, nid, 0, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1819 | AC_VERB_GET_AMP_GAIN_MUTE, parm); |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1820 | val &= 0xff; |
| 1821 | val_read = true; |
| 1822 | mutex_lock(&codec->hash_mutex); |
| 1823 | goto retry; |
| 1824 | } |
| 1825 | info->vol[ch] = val; |
| 1826 | info->head.val |= INFO_AMP_VOL(ch); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1827 | } else if (init_only) |
| 1828 | return NULL; |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1829 | return info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | /* |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1833 | * write the current volume in info to the h/w |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | */ |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 1835 | static void put_vol_mute(struct hda_codec *codec, unsigned int amp_caps, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1836 | hda_nid_t nid, int ch, int direction, int index, |
| 1837 | int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | { |
| 1839 | u32 parm; |
| 1840 | |
| 1841 | parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT; |
| 1842 | parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT; |
| 1843 | parm |= index << AC_AMP_SET_INDEX_SHIFT; |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 1844 | if ((val & HDA_AMP_MUTE) && !(amp_caps & AC_AMPCAP_MUTE) && |
| 1845 | (amp_caps & AC_AMPCAP_MIN_MUTE)) |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 1846 | ; /* set the zero value as a fake mute */ |
| 1847 | else |
| 1848 | parm |= val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); |
| 1850 | } |
| 1851 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1852 | /** |
| 1853 | * snd_hda_codec_amp_read - Read AMP value |
| 1854 | * @codec: HD-audio codec |
| 1855 | * @nid: NID to read the AMP value |
| 1856 | * @ch: channel (left=0 or right=1) |
| 1857 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1858 | * @index: the index value (only for input direction) |
| 1859 | * |
| 1860 | * 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] | 1861 | */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 1862 | int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1863 | int direction, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 1865 | struct hda_amp_info *info; |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1866 | unsigned int val = 0; |
| 1867 | |
| 1868 | mutex_lock(&codec->hash_mutex); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1869 | info = update_amp_hash(codec, nid, ch, direction, index, false); |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 1870 | if (info) |
| 1871 | val = info->vol[ch]; |
| 1872 | mutex_unlock(&codec->hash_mutex); |
| 1873 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1875 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1877 | static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1878 | int direction, int idx, int mask, int val, |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 1879 | bool init_only, bool cache_only) |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1880 | { |
| 1881 | struct hda_amp_info *info; |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 1882 | unsigned int caps; |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1883 | |
| 1884 | if (snd_BUG_ON(mask & ~0xff)) |
| 1885 | mask &= 0xff; |
| 1886 | val &= mask; |
| 1887 | |
| 1888 | mutex_lock(&codec->hash_mutex); |
| 1889 | info = update_amp_hash(codec, nid, ch, direction, idx, init_only); |
| 1890 | if (!info) { |
| 1891 | mutex_unlock(&codec->hash_mutex); |
| 1892 | return 0; |
| 1893 | } |
| 1894 | val |= info->vol[ch] & ~mask; |
| 1895 | if (info->vol[ch] == val) { |
| 1896 | mutex_unlock(&codec->hash_mutex); |
| 1897 | return 0; |
| 1898 | } |
| 1899 | info->vol[ch] = val; |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 1900 | info->head.dirty |= cache_only; |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 1901 | caps = info->amp_caps; |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1902 | mutex_unlock(&codec->hash_mutex); |
Takashi Iwai | de1e37b | 2012-12-20 11:00:21 +0100 | [diff] [blame] | 1903 | if (!cache_only) |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 1904 | put_vol_mute(codec, caps, nid, ch, direction, idx, val); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1905 | return 1; |
| 1906 | } |
| 1907 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1908 | /** |
| 1909 | * snd_hda_codec_amp_update - update the AMP value |
| 1910 | * @codec: HD-audio codec |
| 1911 | * @nid: NID to read the AMP value |
| 1912 | * @ch: channel (left=0 or right=1) |
| 1913 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1914 | * @idx: the index value (only for input direction) |
| 1915 | * @mask: bit mask to set |
| 1916 | * @val: the bits value to set |
| 1917 | * |
| 1918 | * Update the AMP value with a bit mask. |
| 1919 | * Returns 0 if the value is unchanged, 1 if changed. |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 1920 | */ |
Takashi Iwai | 834be88 | 2006-03-01 14:16:17 +0100 | [diff] [blame] | 1921 | int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1922 | int direction, int idx, int mask, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | { |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 1924 | return codec_amp_update(codec, nid, ch, direction, idx, mask, val, |
| 1925 | false, codec->cached_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1927 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 1929 | /** |
| 1930 | * snd_hda_codec_amp_stereo - update the AMP stereo values |
| 1931 | * @codec: HD-audio codec |
| 1932 | * @nid: NID to read the AMP value |
| 1933 | * @direction: #HDA_INPUT or #HDA_OUTPUT |
| 1934 | * @idx: the index value (only for input direction) |
| 1935 | * @mask: bit mask to set |
| 1936 | * @val: the bits value to set |
| 1937 | * |
| 1938 | * Update the AMP values like snd_hda_codec_amp_update(), but for a |
| 1939 | * stereo widget with the same mask and value. |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1940 | */ |
| 1941 | int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, |
| 1942 | int direction, int idx, int mask, int val) |
| 1943 | { |
| 1944 | int ch, ret = 0; |
Takashi Iwai | 46712646 | 2010-03-29 09:19:38 +0200 | [diff] [blame] | 1945 | |
| 1946 | if (snd_BUG_ON(mask & ~0xff)) |
| 1947 | mask &= 0xff; |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1948 | for (ch = 0; ch < 2; ch++) |
| 1949 | ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, |
| 1950 | idx, mask, val); |
| 1951 | return ret; |
| 1952 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1953 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1954 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 1955 | /** |
| 1956 | * snd_hda_codec_amp_init - initialize the AMP value |
| 1957 | * @codec: the HDA codec |
| 1958 | * @nid: NID to read the AMP value |
| 1959 | * @ch: channel (left=0 or right=1) |
| 1960 | * @dir: #HDA_INPUT or #HDA_OUTPUT |
| 1961 | * @idx: the index value (only for input direction) |
| 1962 | * @mask: bit mask to set |
| 1963 | * @val: the bits value to set |
| 1964 | * |
| 1965 | * Works like snd_hda_codec_amp_update() but it writes the value only at |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1966 | * the first access. If the amp was already initialized / updated beforehand, |
| 1967 | * this does nothing. |
| 1968 | */ |
| 1969 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, |
| 1970 | int dir, int idx, int mask, int val) |
| 1971 | { |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 1972 | return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true, |
| 1973 | codec->cached_write); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1974 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 1975 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1976 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 1977 | /** |
| 1978 | * snd_hda_codec_amp_init_stereo - initialize the stereo AMP value |
| 1979 | * @codec: the HDA codec |
| 1980 | * @nid: NID to read the AMP value |
| 1981 | * @dir: #HDA_INPUT or #HDA_OUTPUT |
| 1982 | * @idx: the index value (only for input direction) |
| 1983 | * @mask: bit mask to set |
| 1984 | * @val: the bits value to set |
| 1985 | * |
| 1986 | * Call snd_hda_codec_amp_init() for both stereo channels. |
| 1987 | */ |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 1988 | int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, |
| 1989 | int dir, int idx, int mask, int val) |
| 1990 | { |
| 1991 | int ch, ret = 0; |
| 1992 | |
| 1993 | if (snd_BUG_ON(mask & ~0xff)) |
| 1994 | mask &= 0xff; |
| 1995 | for (ch = 0; ch < 2; ch++) |
| 1996 | ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, |
| 1997 | idx, mask, val); |
| 1998 | return ret; |
| 1999 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2000 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo); |
Takashi Iwai | 280e57d | 2012-12-14 10:32:21 +0100 | [diff] [blame] | 2001 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2002 | /** |
| 2003 | * snd_hda_codec_resume_amp - Resume all AMP commands from the cache |
| 2004 | * @codec: HD-audio codec |
| 2005 | * |
| 2006 | * Resume the all amp commands from the cache. |
| 2007 | */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2008 | void snd_hda_codec_resume_amp(struct hda_codec *codec) |
| 2009 | { |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2010 | int i; |
| 2011 | |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2012 | mutex_lock(&codec->hash_mutex); |
Takashi Iwai | aa88a35 | 2012-12-20 11:02:00 +0100 | [diff] [blame] | 2013 | codec->cached_write = 0; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2014 | for (i = 0; i < codec->amp_cache.buf.used; i++) { |
| 2015 | struct hda_amp_info *buffer; |
| 2016 | u32 key; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2017 | hda_nid_t nid; |
| 2018 | unsigned int idx, dir, ch; |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 2019 | struct hda_amp_info info; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2020 | |
| 2021 | buffer = snd_array_elem(&codec->amp_cache.buf, i); |
Takashi Iwai | 8565f05 | 2012-12-20 12:54:18 +0100 | [diff] [blame] | 2022 | if (!buffer->head.dirty) |
| 2023 | continue; |
| 2024 | buffer->head.dirty = 0; |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 2025 | info = *buffer; |
| 2026 | key = info.head.key; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2027 | if (!key) |
| 2028 | continue; |
| 2029 | nid = key & 0xff; |
| 2030 | idx = (key >> 16) & 0xff; |
| 2031 | dir = (key >> 24) & 0xff; |
| 2032 | for (ch = 0; ch < 2; ch++) { |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 2033 | if (!(info.head.val & INFO_AMP_VOL(ch))) |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2034 | continue; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2035 | mutex_unlock(&codec->hash_mutex); |
Takashi Iwai | 2ce4886a | 2012-12-20 12:58:12 +0100 | [diff] [blame] | 2036 | put_vol_mute(codec, info.amp_caps, nid, ch, dir, idx, |
| 2037 | info.vol[ch]); |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2038 | mutex_lock(&codec->hash_mutex); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2039 | } |
| 2040 | } |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 2041 | mutex_unlock(&codec->hash_mutex); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 2042 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2043 | EXPORT_SYMBOL_GPL(snd_hda_codec_resume_amp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 2045 | static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 2046 | unsigned int ofs) |
| 2047 | { |
| 2048 | u32 caps = query_amp_caps(codec, nid, dir); |
| 2049 | /* get num steps */ |
| 2050 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 2051 | if (ofs < caps) |
| 2052 | caps -= ofs; |
| 2053 | return caps; |
| 2054 | } |
| 2055 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2056 | /** |
| 2057 | * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2058 | * @kcontrol: referred ctl element |
| 2059 | * @uinfo: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2060 | * |
| 2061 | * The control element is supposed to have the private_value field |
| 2062 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2063 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2064 | int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, |
| 2065 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | { |
| 2067 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2068 | u16 nid = get_amp_nid(kcontrol); |
| 2069 | u8 chs = get_amp_channels(kcontrol); |
| 2070 | int dir = get_amp_direction(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2071 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 2073 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2074 | uinfo->count = chs == 3 ? 2 : 1; |
| 2075 | uinfo->value.integer.min = 0; |
| 2076 | uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); |
| 2077 | if (!uinfo->value.integer.max) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2078 | codec_warn(codec, |
| 2079 | "num_steps = 0 for NID=0x%x (ctl = %s)\n", |
| 2080 | nid, kcontrol->id.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | return -EINVAL; |
| 2082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | return 0; |
| 2084 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2085 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2087 | |
| 2088 | static inline unsigned int |
| 2089 | read_amp_value(struct hda_codec *codec, hda_nid_t nid, |
| 2090 | int ch, int dir, int idx, unsigned int ofs) |
| 2091 | { |
| 2092 | unsigned int val; |
| 2093 | val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); |
| 2094 | val &= HDA_AMP_VOLMASK; |
| 2095 | if (val >= ofs) |
| 2096 | val -= ofs; |
| 2097 | else |
| 2098 | val = 0; |
| 2099 | return val; |
| 2100 | } |
| 2101 | |
| 2102 | static inline int |
| 2103 | update_amp_value(struct hda_codec *codec, hda_nid_t nid, |
| 2104 | int ch, int dir, int idx, unsigned int ofs, |
| 2105 | unsigned int val) |
| 2106 | { |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 2107 | unsigned int maxval; |
| 2108 | |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2109 | if (val > 0) |
| 2110 | val += ofs; |
Takashi Iwai | 7ccc3ef | 2010-07-26 17:00:15 +0200 | [diff] [blame] | 2111 | /* ofs = 0: raw max value */ |
| 2112 | maxval = get_amp_max_value(codec, nid, dir, 0); |
Takashi Iwai | afbd9b8 | 2010-07-08 18:40:37 +0200 | [diff] [blame] | 2113 | if (val > maxval) |
| 2114 | val = maxval; |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 2115 | return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val, |
| 2116 | false, !hda_codec_is_power_on(codec)); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2119 | /** |
| 2120 | * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2121 | * @kcontrol: ctl element |
| 2122 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2123 | * |
| 2124 | * The control element is supposed to have the private_value field |
| 2125 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2126 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2127 | int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, |
| 2128 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | { |
| 2130 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2131 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2132 | int chs = get_amp_channels(kcontrol); |
| 2133 | int dir = get_amp_direction(kcontrol); |
| 2134 | int idx = get_amp_index(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2135 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | long *valp = ucontrol->value.integer.value; |
| 2137 | |
| 2138 | if (chs & 1) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2139 | *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | if (chs & 2) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2141 | *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | return 0; |
| 2143 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2144 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2146 | /** |
| 2147 | * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2148 | * @kcontrol: ctl element |
| 2149 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2150 | * |
| 2151 | * The control element is supposed to have the private_value field |
| 2152 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2153 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2154 | int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, |
| 2155 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | { |
| 2157 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2158 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2159 | int chs = get_amp_channels(kcontrol); |
| 2160 | int dir = get_amp_direction(kcontrol); |
| 2161 | int idx = get_amp_index(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2162 | unsigned int ofs = get_amp_offset(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | long *valp = ucontrol->value.integer.value; |
| 2164 | int change = 0; |
| 2165 | |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2166 | if (chs & 1) { |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2167 | change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2168 | valp++; |
| 2169 | } |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 2170 | if (chs & 2) |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2171 | change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | return change; |
| 2173 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2174 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2176 | /** |
| 2177 | * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2178 | * @kcontrol: ctl element |
| 2179 | * @op_flag: operation flag |
| 2180 | * @size: byte size of input TLV |
| 2181 | * @_tlv: TLV data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2182 | * |
| 2183 | * The control element is supposed to have the private_value field |
| 2184 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2185 | */ |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2186 | int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 2187 | unsigned int size, unsigned int __user *_tlv) |
| 2188 | { |
| 2189 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2190 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2191 | int dir = get_amp_direction(kcontrol); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2192 | unsigned int ofs = get_amp_offset(kcontrol); |
Clemens Ladisch | de8c85f | 2010-10-15 10:32:50 +0200 | [diff] [blame] | 2193 | bool min_mute = get_amp_min_mute(kcontrol); |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2194 | u32 caps, val1, val2; |
| 2195 | |
| 2196 | if (size < 4 * sizeof(unsigned int)) |
| 2197 | return -ENOMEM; |
| 2198 | caps = query_amp_caps(codec, nid, dir); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2199 | val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT; |
| 2200 | val2 = (val2 + 1) * 25; |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2201 | val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT); |
Takashi Iwai | 29fdbec | 2009-01-20 13:07:55 +0100 | [diff] [blame] | 2202 | val1 += ofs; |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2203 | val1 = ((int)val1) * ((int)val2); |
Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 2204 | if (min_mute || (caps & AC_AMPCAP_MIN_MUTE)) |
Takashi Iwai | c08d916 | 2010-10-17 10:40:53 +0200 | [diff] [blame] | 2205 | val2 |= TLV_DB_SCALE_MUTE; |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2206 | if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv)) |
| 2207 | return -EFAULT; |
| 2208 | if (put_user(2 * sizeof(unsigned int), _tlv + 1)) |
| 2209 | return -EFAULT; |
| 2210 | if (put_user(val1, _tlv + 2)) |
| 2211 | return -EFAULT; |
| 2212 | if (put_user(val2, _tlv + 3)) |
| 2213 | return -EFAULT; |
| 2214 | return 0; |
| 2215 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2216 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_tlv); |
Jaroslav Kysela | 302e9c5 | 2006-07-05 17:39:49 +0200 | [diff] [blame] | 2217 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2218 | /** |
| 2219 | * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control |
| 2220 | * @codec: HD-audio codec |
| 2221 | * @nid: NID of a reference widget |
| 2222 | * @dir: #HDA_INPUT or #HDA_OUTPUT |
| 2223 | * @tlv: TLV data to be stored, at least 4 elements |
| 2224 | * |
| 2225 | * Set (static) TLV data for a virtual master volume using the AMP caps |
| 2226 | * obtained from the reference NID. |
| 2227 | * The volume range is recalculated as if the max volume is 0dB. |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2228 | */ |
| 2229 | void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 2230 | unsigned int *tlv) |
| 2231 | { |
| 2232 | u32 caps; |
| 2233 | int nums, step; |
| 2234 | |
| 2235 | caps = query_amp_caps(codec, nid, dir); |
| 2236 | nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 2237 | step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT; |
| 2238 | step = (step + 1) * 25; |
| 2239 | tlv[0] = SNDRV_CTL_TLVT_DB_SCALE; |
| 2240 | tlv[1] = 2 * sizeof(unsigned int); |
| 2241 | tlv[2] = -nums * step; |
| 2242 | tlv[3] = step; |
| 2243 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2244 | EXPORT_SYMBOL_GPL(snd_hda_set_vmaster_tlv); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2245 | |
| 2246 | /* find a mixer control element with the given name */ |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2247 | static struct snd_kcontrol * |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 2248 | find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2249 | { |
| 2250 | struct snd_ctl_elem_id id; |
| 2251 | memset(&id, 0, sizeof(id)); |
| 2252 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 2253 | id.device = dev; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2254 | id.index = idx; |
Takashi Iwai | 18cb710 | 2009-04-16 10:22:24 +0200 | [diff] [blame] | 2255 | if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) |
| 2256 | return NULL; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2257 | strcpy(id.name, name); |
| 2258 | return snd_ctl_find_id(codec->bus->card, &id); |
| 2259 | } |
| 2260 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2261 | /** |
| 2262 | * snd_hda_find_mixer_ctl - Find a mixer control element with the given name |
| 2263 | * @codec: HD-audio codec |
| 2264 | * @name: ctl id name string |
| 2265 | * |
| 2266 | * Get the control element with the given id string and IFACE_MIXER. |
| 2267 | */ |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2268 | struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, |
| 2269 | const char *name) |
| 2270 | { |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 2271 | return find_mixer_ctl(codec, name, 0, 0); |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2272 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2273 | EXPORT_SYMBOL_GPL(snd_hda_find_mixer_ctl); |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 2274 | |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 2275 | static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 2276 | int start_idx) |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 2277 | { |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 2278 | int i, idx; |
| 2279 | /* 16 ctlrs should be large enough */ |
| 2280 | for (i = 0, idx = start_idx; i < 16; i++, idx++) { |
| 2281 | if (!find_mixer_ctl(codec, name, 0, idx)) |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 2282 | return idx; |
| 2283 | } |
| 2284 | return -EBUSY; |
| 2285 | } |
| 2286 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2287 | /** |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2288 | * snd_hda_ctl_add - Add a control element and assign to the codec |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2289 | * @codec: HD-audio codec |
| 2290 | * @nid: corresponding NID (optional) |
| 2291 | * @kctl: the control element to assign |
| 2292 | * |
| 2293 | * Add the given control element to an array inside the codec instance. |
| 2294 | * All control elements belonging to a codec are supposed to be added |
| 2295 | * by this function so that a proper clean-up works at the free or |
| 2296 | * reconfiguration time. |
| 2297 | * |
| 2298 | * If non-zero @nid is passed, the NID is assigned to the control element. |
| 2299 | * The assignment is shown in the codec proc file. |
| 2300 | * |
| 2301 | * snd_hda_ctl_add() checks the control subdev id field whether |
| 2302 | * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 2303 | * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit |
| 2304 | * specifies if kctl->private_value is a HDA amplifier value. |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2305 | */ |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2306 | int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, |
| 2307 | struct snd_kcontrol *kctl) |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2308 | { |
| 2309 | int err; |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 2310 | unsigned short flags = 0; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2311 | struct hda_nid_item *item; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2312 | |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2313 | if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) { |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 2314 | flags |= HDA_NID_ITEM_AMP; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2315 | if (nid == 0) |
| 2316 | nid = get_amp_nid_(kctl->private_value); |
| 2317 | } |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 2318 | if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0) |
| 2319 | nid = kctl->id.subdevice & 0xffff; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2320 | if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 2321 | kctl->id.subdevice = 0; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2322 | err = snd_ctl_add(codec->bus->card, kctl); |
| 2323 | if (err < 0) |
| 2324 | return err; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2325 | item = snd_array_new(&codec->mixers); |
| 2326 | if (!item) |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2327 | return -ENOMEM; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2328 | item->kctl = kctl; |
| 2329 | item->nid = nid; |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 2330 | item->flags = flags; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2331 | return 0; |
| 2332 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2333 | EXPORT_SYMBOL_GPL(snd_hda_ctl_add); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2334 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2335 | /** |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2336 | * snd_hda_add_nid - Assign a NID to a control element |
| 2337 | * @codec: HD-audio codec |
| 2338 | * @nid: corresponding NID (optional) |
| 2339 | * @kctl: the control element to assign |
| 2340 | * @index: index to kctl |
| 2341 | * |
| 2342 | * Add the given control element to an array inside the codec instance. |
| 2343 | * This function is used when #snd_hda_ctl_add cannot be used for 1:1 |
| 2344 | * NID:KCTL mapping - for example "Capture Source" selector. |
| 2345 | */ |
| 2346 | int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, |
| 2347 | unsigned int index, hda_nid_t nid) |
| 2348 | { |
| 2349 | struct hda_nid_item *item; |
| 2350 | |
| 2351 | if (nid > 0) { |
| 2352 | item = snd_array_new(&codec->nids); |
| 2353 | if (!item) |
| 2354 | return -ENOMEM; |
| 2355 | item->kctl = kctl; |
| 2356 | item->index = index; |
| 2357 | item->nid = nid; |
| 2358 | return 0; |
| 2359 | } |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2360 | codec_err(codec, "no NID for mapping control %s:%d:%d\n", |
| 2361 | kctl->id.name, kctl->id.index, index); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2362 | return -EINVAL; |
| 2363 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2364 | EXPORT_SYMBOL_GPL(snd_hda_add_nid); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2365 | |
| 2366 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2367 | * snd_hda_ctls_clear - Clear all controls assigned to the given codec |
| 2368 | * @codec: HD-audio codec |
| 2369 | */ |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2370 | void snd_hda_ctls_clear(struct hda_codec *codec) |
| 2371 | { |
| 2372 | int i; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2373 | struct hda_nid_item *items = codec->mixers.list; |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2374 | for (i = 0; i < codec->mixers.used; i++) |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2375 | snd_ctl_remove(codec->bus->card, items[i].kctl); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2376 | snd_array_free(&codec->mixers); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2377 | snd_array_free(&codec->nids); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2378 | } |
| 2379 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 2380 | /** |
| 2381 | * snd_hda_lock_devices - pseudo device locking |
| 2382 | * @bus: the BUS |
| 2383 | * |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2384 | * toggle card->shutdown to allow/disallow the device access (as a hack) |
| 2385 | */ |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2386 | int snd_hda_lock_devices(struct hda_bus *bus) |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2387 | { |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2388 | struct snd_card *card = bus->card; |
| 2389 | struct hda_codec *codec; |
| 2390 | |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2391 | spin_lock(&card->files_lock); |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2392 | if (card->shutdown) |
| 2393 | goto err_unlock; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2394 | card->shutdown = 1; |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2395 | if (!list_empty(&card->ctl_files)) |
| 2396 | goto err_clear; |
| 2397 | |
| 2398 | list_for_each_entry(codec, &bus->codec_list, list) { |
| 2399 | int pcm; |
| 2400 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { |
| 2401 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; |
| 2402 | if (!cpcm->pcm) |
| 2403 | continue; |
| 2404 | if (cpcm->pcm->streams[0].substream_opened || |
| 2405 | cpcm->pcm->streams[1].substream_opened) |
| 2406 | goto err_clear; |
| 2407 | } |
| 2408 | } |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2409 | spin_unlock(&card->files_lock); |
| 2410 | return 0; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2411 | |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2412 | err_clear: |
| 2413 | card->shutdown = 0; |
| 2414 | err_unlock: |
| 2415 | spin_unlock(&card->files_lock); |
| 2416 | return -EINVAL; |
| 2417 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2418 | EXPORT_SYMBOL_GPL(snd_hda_lock_devices); |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2419 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 2420 | /** |
| 2421 | * snd_hda_unlock_devices - pseudo device unlocking |
| 2422 | * @bus: the BUS |
| 2423 | */ |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2424 | void snd_hda_unlock_devices(struct hda_bus *bus) |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2425 | { |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2426 | struct snd_card *card = bus->card; |
| 2427 | |
| 2428 | card = bus->card; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2429 | spin_lock(&card->files_lock); |
| 2430 | card->shutdown = 0; |
| 2431 | spin_unlock(&card->files_lock); |
| 2432 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2433 | EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2434 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2435 | /** |
| 2436 | * snd_hda_codec_reset - Clear all objects assigned to the codec |
| 2437 | * @codec: HD-audio codec |
| 2438 | * |
| 2439 | * This frees the all PCM and control elements assigned to the codec, and |
| 2440 | * clears the caches and restores the pin default configurations. |
| 2441 | * |
| 2442 | * When a device is being used, it returns -EBSY. If successfully freed, |
| 2443 | * returns zero. |
| 2444 | */ |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2445 | int snd_hda_codec_reset(struct hda_codec *codec) |
| 2446 | { |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2447 | struct hda_bus *bus = codec->bus; |
| 2448 | struct snd_card *card = bus->card; |
| 2449 | int i; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2450 | |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2451 | if (snd_hda_lock_devices(bus) < 0) |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2452 | return -EBUSY; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2453 | |
| 2454 | /* OK, let it free */ |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 2455 | cancel_delayed_work_sync(&codec->jackpoll_work); |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 2456 | #ifdef CONFIG_PM |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 2457 | cancel_delayed_work_sync(&codec->power_work); |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2458 | flush_workqueue(bus->workq); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2459 | #endif |
| 2460 | snd_hda_ctls_clear(codec); |
Geert Uytterhoeven | 83a35e3 | 2013-06-28 11:27:31 +0200 | [diff] [blame] | 2461 | /* release PCMs */ |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2462 | for (i = 0; i < codec->num_pcms; i++) { |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 2463 | if (codec->pcm_info[i].pcm) { |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2464 | snd_device_free(card, codec->pcm_info[i].pcm); |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 2465 | clear_bit(codec->pcm_info[i].device, |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2466 | bus->pcm_dev_bits); |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 2467 | } |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2468 | } |
Takashi Iwai | d604b39 | 2014-02-28 13:42:09 +0100 | [diff] [blame] | 2469 | snd_hda_detach_beep_device(codec); |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 2470 | if (device_is_registered(hda_codec_dev(codec))) |
| 2471 | device_del(hda_codec_dev(codec)); |
| 2472 | |
Takashi Iwai | 07dc59f | 2012-09-10 09:39:31 +0200 | [diff] [blame] | 2473 | memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 2474 | snd_hda_jack_tbl_clear(codec); |
Takashi Iwai | 56d1771 | 2008-11-28 14:36:23 +0100 | [diff] [blame] | 2475 | codec->proc_widget_hook = NULL; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2476 | codec->spec = NULL; |
| 2477 | free_hda_cache(&codec->amp_cache); |
| 2478 | free_hda_cache(&codec->cmd_cache); |
Takashi Iwai | 827057f | 2008-12-19 10:12:02 +0100 | [diff] [blame] | 2479 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); |
| 2480 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); |
Takashi Iwai | 346ff70 | 2009-02-23 09:42:57 +0100 | [diff] [blame] | 2481 | /* free only driver_pins so that init_pins + user_pins are restored */ |
| 2482 | snd_array_free(&codec->driver_pins); |
Takashi Iwai | 09a6071 | 2012-06-26 15:01:33 +0200 | [diff] [blame] | 2483 | snd_array_free(&codec->cvt_setups); |
| 2484 | snd_array_free(&codec->spdif_out); |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 2485 | snd_array_free(&codec->verbs); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2486 | codec->num_pcms = 0; |
| 2487 | codec->pcm_info = NULL; |
| 2488 | codec->preset = NULL; |
Takashi Iwai | d1f1af2 | 2009-03-02 10:35:29 +0100 | [diff] [blame] | 2489 | codec->slave_dig_outs = NULL; |
| 2490 | codec->spdif_status_reset = 0; |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2491 | |
| 2492 | /* allow device access again */ |
Takashi Iwai | d3d020b | 2012-04-26 12:11:44 +0200 | [diff] [blame] | 2493 | snd_hda_unlock_devices(bus); |
Takashi Iwai | a65d629 | 2009-02-23 16:57:04 +0100 | [diff] [blame] | 2494 | return 0; |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2495 | } |
| 2496 | |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2497 | typedef int (*map_slave_func_t)(struct hda_codec *, void *, struct snd_kcontrol *); |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2498 | |
| 2499 | /* apply the function to all matching slave ctls in the mixer list */ |
| 2500 | static int map_slaves(struct hda_codec *codec, const char * const *slaves, |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2501 | const char *suffix, map_slave_func_t func, void *data) |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2502 | { |
| 2503 | struct hda_nid_item *items; |
| 2504 | const char * const *s; |
| 2505 | int i, err; |
| 2506 | |
| 2507 | items = codec->mixers.list; |
| 2508 | for (i = 0; i < codec->mixers.used; i++) { |
| 2509 | struct snd_kcontrol *sctl = items[i].kctl; |
Takashi Iwai | ca16ec0 | 2013-10-28 12:00:35 +0100 | [diff] [blame] | 2510 | if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER) |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2511 | continue; |
| 2512 | for (s = slaves; *s; s++) { |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2513 | char tmpname[sizeof(sctl->id.name)]; |
| 2514 | const char *name = *s; |
| 2515 | if (suffix) { |
| 2516 | snprintf(tmpname, sizeof(tmpname), "%s %s", |
| 2517 | name, suffix); |
| 2518 | name = tmpname; |
| 2519 | } |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2520 | if (!strcmp(sctl->id.name, name)) { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2521 | err = func(codec, data, sctl); |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2522 | if (err) |
| 2523 | return err; |
| 2524 | break; |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | return 0; |
| 2529 | } |
| 2530 | |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2531 | static int check_slave_present(struct hda_codec *codec, |
| 2532 | void *data, struct snd_kcontrol *sctl) |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2533 | { |
| 2534 | return 1; |
| 2535 | } |
| 2536 | |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2537 | /* guess the value corresponding to 0dB */ |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2538 | static int get_kctl_0dB_offset(struct hda_codec *codec, |
| 2539 | struct snd_kcontrol *kctl, int *step_to_check) |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2540 | { |
| 2541 | int _tlv[4]; |
| 2542 | const int *tlv = NULL; |
| 2543 | int val = -1; |
| 2544 | |
| 2545 | if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { |
| 2546 | /* FIXME: set_fs() hack for obtaining user-space TLV data */ |
| 2547 | mm_segment_t fs = get_fs(); |
| 2548 | set_fs(get_ds()); |
| 2549 | if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv)) |
| 2550 | tlv = _tlv; |
| 2551 | set_fs(fs); |
| 2552 | } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) |
| 2553 | tlv = kctl->tlv.p; |
Takashi Iwai | a4e7a12 | 2013-11-04 15:44:09 +0100 | [diff] [blame] | 2554 | if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) { |
| 2555 | int step = tlv[3]; |
| 2556 | step &= ~TLV_DB_SCALE_MUTE; |
| 2557 | if (!step) |
| 2558 | return -1; |
Takashi Iwai | 485e3e0 | 2013-11-04 15:51:00 +0100 | [diff] [blame] | 2559 | if (*step_to_check && *step_to_check != step) { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2560 | codec_err(codec, "Mismatching dB step for vmaster slave (%d!=%d)\n", |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2561 | - *step_to_check, step); |
Takashi Iwai | 485e3e0 | 2013-11-04 15:51:00 +0100 | [diff] [blame] | 2562 | return -1; |
| 2563 | } |
| 2564 | *step_to_check = step; |
Takashi Iwai | a4e7a12 | 2013-11-04 15:44:09 +0100 | [diff] [blame] | 2565 | val = -tlv[2] / step; |
| 2566 | } |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2567 | return val; |
| 2568 | } |
| 2569 | |
| 2570 | /* call kctl->put with the given value(s) */ |
| 2571 | static int put_kctl_with_value(struct snd_kcontrol *kctl, int val) |
| 2572 | { |
| 2573 | struct snd_ctl_elem_value *ucontrol; |
| 2574 | ucontrol = kzalloc(sizeof(*ucontrol), GFP_KERNEL); |
| 2575 | if (!ucontrol) |
| 2576 | return -ENOMEM; |
| 2577 | ucontrol->value.integer.value[0] = val; |
| 2578 | ucontrol->value.integer.value[1] = val; |
| 2579 | kctl->put(kctl, ucontrol); |
| 2580 | kfree(ucontrol); |
| 2581 | return 0; |
| 2582 | } |
| 2583 | |
| 2584 | /* initialize the slave volume with 0dB */ |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2585 | static int init_slave_0dB(struct hda_codec *codec, |
| 2586 | void *data, struct snd_kcontrol *slave) |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2587 | { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2588 | int offset = get_kctl_0dB_offset(codec, slave, data); |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2589 | if (offset > 0) |
| 2590 | put_kctl_with_value(slave, offset); |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | /* unmute the slave */ |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 2595 | static int init_slave_unmute(struct hda_codec *codec, |
| 2596 | void *data, struct snd_kcontrol *slave) |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2597 | { |
| 2598 | return put_kctl_with_value(slave, 1); |
| 2599 | } |
| 2600 | |
Takashi Iwai | e875094 | 2014-06-30 14:02:39 +0200 | [diff] [blame] | 2601 | static int add_slave(struct hda_codec *codec, |
| 2602 | void *data, struct snd_kcontrol *slave) |
| 2603 | { |
| 2604 | return snd_ctl_add_slave(data, slave); |
| 2605 | } |
| 2606 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2607 | /** |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 2608 | * __snd_hda_add_vmaster - create a virtual master control and add slaves |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2609 | * @codec: HD-audio codec |
| 2610 | * @name: vmaster control name |
| 2611 | * @tlv: TLV data (optional) |
| 2612 | * @slaves: slave control names (optional) |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2613 | * @suffix: suffix string to each slave name (optional) |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2614 | * @init_slave_vol: initialize slaves to unmute/0dB |
Takashi Iwai | 29e5853 | 2012-03-12 12:25:03 +0100 | [diff] [blame] | 2615 | * @ctl_ret: store the vmaster kcontrol in return |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2616 | * |
| 2617 | * Create a virtual master control with the given name. The TLV data |
| 2618 | * must be either NULL or a valid data. |
| 2619 | * |
| 2620 | * @slaves is a NULL-terminated array of strings, each of which is a |
| 2621 | * slave control name. All controls with these names are assigned to |
| 2622 | * the new virtual master control. |
| 2623 | * |
| 2624 | * This function returns zero if successful or a negative error code. |
| 2625 | */ |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2626 | int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2627 | unsigned int *tlv, const char * const *slaves, |
Takashi Iwai | 29e5853 | 2012-03-12 12:25:03 +0100 | [diff] [blame] | 2628 | const char *suffix, bool init_slave_vol, |
| 2629 | struct snd_kcontrol **ctl_ret) |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2630 | { |
| 2631 | struct snd_kcontrol *kctl; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2632 | int err; |
| 2633 | |
Takashi Iwai | 29e5853 | 2012-03-12 12:25:03 +0100 | [diff] [blame] | 2634 | if (ctl_ret) |
| 2635 | *ctl_ret = NULL; |
| 2636 | |
Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 2637 | err = map_slaves(codec, slaves, suffix, check_slave_present, NULL); |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2638 | if (err != 1) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2639 | codec_dbg(codec, "No slave found for %s\n", name); |
Takashi Iwai | 2f08554 | 2008-02-22 18:43:50 +0100 | [diff] [blame] | 2640 | return 0; |
| 2641 | } |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2642 | kctl = snd_ctl_make_virtual_master(name, tlv); |
| 2643 | if (!kctl) |
| 2644 | return -ENOMEM; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 2645 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2646 | if (err < 0) |
| 2647 | return err; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 2648 | |
Takashi Iwai | e875094 | 2014-06-30 14:02:39 +0200 | [diff] [blame] | 2649 | err = map_slaves(codec, slaves, suffix, add_slave, kctl); |
Takashi Iwai | aeb4b88 | 2011-11-10 12:28:38 +0100 | [diff] [blame] | 2650 | if (err < 0) |
| 2651 | return err; |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2652 | |
| 2653 | /* init with master mute & zero volume */ |
| 2654 | put_kctl_with_value(kctl, 0); |
Takashi Iwai | 485e3e0 | 2013-11-04 15:51:00 +0100 | [diff] [blame] | 2655 | if (init_slave_vol) { |
| 2656 | int step = 0; |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2657 | map_slaves(codec, slaves, suffix, |
Takashi Iwai | 485e3e0 | 2013-11-04 15:51:00 +0100 | [diff] [blame] | 2658 | tlv ? init_slave_0dB : init_slave_unmute, &step); |
| 2659 | } |
Takashi Iwai | 18478e8 | 2012-03-09 17:51:10 +0100 | [diff] [blame] | 2660 | |
Takashi Iwai | 29e5853 | 2012-03-12 12:25:03 +0100 | [diff] [blame] | 2661 | if (ctl_ret) |
| 2662 | *ctl_ret = kctl; |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2663 | return 0; |
| 2664 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2665 | EXPORT_SYMBOL_GPL(__snd_hda_add_vmaster); |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 2666 | |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2667 | /* |
| 2668 | * mute-LED control using vmaster |
| 2669 | */ |
| 2670 | static int vmaster_mute_mode_info(struct snd_kcontrol *kcontrol, |
| 2671 | struct snd_ctl_elem_info *uinfo) |
| 2672 | { |
| 2673 | static const char * const texts[] = { |
David Henningsson | c86c2d4 | 2013-01-03 14:12:29 +0100 | [diff] [blame] | 2674 | "On", "Off", "Follow Master" |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2675 | }; |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2676 | |
Takashi Iwai | 3ff7221 | 2014-10-20 18:17:28 +0200 | [diff] [blame] | 2677 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | static int vmaster_mute_mode_get(struct snd_kcontrol *kcontrol, |
| 2681 | struct snd_ctl_elem_value *ucontrol) |
| 2682 | { |
| 2683 | struct hda_vmaster_mute_hook *hook = snd_kcontrol_chip(kcontrol); |
| 2684 | ucontrol->value.enumerated.item[0] = hook->mute_mode; |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
| 2688 | static int vmaster_mute_mode_put(struct snd_kcontrol *kcontrol, |
| 2689 | struct snd_ctl_elem_value *ucontrol) |
| 2690 | { |
| 2691 | struct hda_vmaster_mute_hook *hook = snd_kcontrol_chip(kcontrol); |
| 2692 | unsigned int old_mode = hook->mute_mode; |
| 2693 | |
| 2694 | hook->mute_mode = ucontrol->value.enumerated.item[0]; |
| 2695 | if (hook->mute_mode > HDA_VMUTE_FOLLOW_MASTER) |
| 2696 | hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER; |
| 2697 | if (old_mode == hook->mute_mode) |
| 2698 | return 0; |
| 2699 | snd_hda_sync_vmaster_hook(hook); |
| 2700 | return 1; |
| 2701 | } |
| 2702 | |
| 2703 | static struct snd_kcontrol_new vmaster_mute_mode = { |
| 2704 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2705 | .name = "Mute-LED Mode", |
| 2706 | .info = vmaster_mute_mode_info, |
| 2707 | .get = vmaster_mute_mode_get, |
| 2708 | .put = vmaster_mute_mode_put, |
| 2709 | }; |
| 2710 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 2711 | /** |
| 2712 | * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED |
| 2713 | * @codec: the HDA codec |
| 2714 | * @hook: the vmaster hook object |
| 2715 | * @expose_enum_ctl: flag to create an enum ctl |
| 2716 | * |
| 2717 | * Add a mute-LED hook with the given vmaster switch kctl. |
| 2718 | * When @expose_enum_ctl is set, "Mute-LED Mode" control is automatically |
| 2719 | * created and associated with the given hook. |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2720 | */ |
| 2721 | int snd_hda_add_vmaster_hook(struct hda_codec *codec, |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 2722 | struct hda_vmaster_mute_hook *hook, |
| 2723 | bool expose_enum_ctl) |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2724 | { |
| 2725 | struct snd_kcontrol *kctl; |
| 2726 | |
| 2727 | if (!hook->hook || !hook->sw_kctl) |
| 2728 | return 0; |
| 2729 | snd_ctl_add_vmaster_hook(hook->sw_kctl, hook->hook, codec); |
| 2730 | hook->codec = codec; |
| 2731 | hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER; |
Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 2732 | if (!expose_enum_ctl) |
| 2733 | return 0; |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2734 | kctl = snd_ctl_new1(&vmaster_mute_mode, hook); |
| 2735 | if (!kctl) |
| 2736 | return -ENOMEM; |
| 2737 | return snd_hda_ctl_add(codec, 0, kctl); |
| 2738 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2739 | EXPORT_SYMBOL_GPL(snd_hda_add_vmaster_hook); |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2740 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 2741 | /** |
| 2742 | * snd_hda_sync_vmaster_hook - Sync vmaster hook |
| 2743 | * @hook: the vmaster hook |
| 2744 | * |
| 2745 | * Call the hook with the current value for synchronization. |
| 2746 | * Should be called in init callback. |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2747 | */ |
| 2748 | void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook) |
| 2749 | { |
| 2750 | if (!hook->hook || !hook->codec) |
| 2751 | return; |
Takashi Iwai | 594813f | 2013-04-17 18:16:05 +0200 | [diff] [blame] | 2752 | /* don't call vmaster hook in the destructor since it might have |
| 2753 | * been already destroyed |
| 2754 | */ |
| 2755 | if (hook->codec->bus->shutdown) |
| 2756 | return; |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2757 | switch (hook->mute_mode) { |
| 2758 | case HDA_VMUTE_FOLLOW_MASTER: |
| 2759 | snd_ctl_sync_vmaster_hook(hook->sw_kctl); |
| 2760 | break; |
| 2761 | default: |
| 2762 | hook->hook(hook->codec, hook->mute_mode); |
| 2763 | break; |
| 2764 | } |
| 2765 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2766 | EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook); |
Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 2767 | |
| 2768 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2769 | /** |
| 2770 | * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2771 | * @kcontrol: referred ctl element |
| 2772 | * @uinfo: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2773 | * |
| 2774 | * The control element is supposed to have the private_value field |
| 2775 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2776 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2777 | int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, |
| 2778 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | { |
| 2780 | int chs = get_amp_channels(kcontrol); |
| 2781 | |
| 2782 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2783 | uinfo->count = chs == 3 ? 2 : 1; |
| 2784 | uinfo->value.integer.min = 0; |
| 2785 | uinfo->value.integer.max = 1; |
| 2786 | return 0; |
| 2787 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2788 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2790 | /** |
| 2791 | * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2792 | * @kcontrol: ctl element |
| 2793 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2794 | * |
| 2795 | * The control element is supposed to have the private_value field |
| 2796 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2797 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2798 | int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, |
| 2799 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | { |
| 2801 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2802 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2803 | int chs = get_amp_channels(kcontrol); |
| 2804 | int dir = get_amp_direction(kcontrol); |
| 2805 | int idx = get_amp_index(kcontrol); |
| 2806 | long *valp = ucontrol->value.integer.value; |
| 2807 | |
| 2808 | if (chs & 1) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2809 | *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2810 | HDA_AMP_MUTE) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | if (chs & 2) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2812 | *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & |
Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 2813 | HDA_AMP_MUTE) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | return 0; |
| 2815 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2816 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2818 | /** |
| 2819 | * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2820 | * @kcontrol: ctl element |
| 2821 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2822 | * |
| 2823 | * The control element is supposed to have the private_value field |
| 2824 | * set up via HDA_COMPOSE_AMP_VAL*() or related macros. |
| 2825 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2826 | int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, |
| 2827 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | { |
| 2829 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2830 | hda_nid_t nid = get_amp_nid(kcontrol); |
| 2831 | int chs = get_amp_channels(kcontrol); |
| 2832 | int dir = get_amp_direction(kcontrol); |
| 2833 | int idx = get_amp_index(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | long *valp = ucontrol->value.integer.value; |
| 2835 | int change = 0; |
| 2836 | |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2837 | if (chs & 1) { |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 2838 | change = codec_amp_update(codec, nid, 0, dir, idx, |
| 2839 | HDA_AMP_MUTE, |
| 2840 | *valp ? 0 : HDA_AMP_MUTE, false, |
| 2841 | !hda_codec_is_power_on(codec)); |
Nicolas Graziano | b9f5a89 | 2005-07-29 12:17:20 +0200 | [diff] [blame] | 2842 | valp++; |
| 2843 | } |
Takashi Iwai | 4a19fae | 2005-06-08 14:43:58 +0200 | [diff] [blame] | 2844 | if (chs & 2) |
Takashi Iwai | 781c7b9 | 2015-02-20 10:26:25 +0100 | [diff] [blame] | 2845 | change |= codec_amp_update(codec, nid, 1, dir, idx, |
| 2846 | HDA_AMP_MUTE, |
| 2847 | *valp ? 0 : HDA_AMP_MUTE, false, |
| 2848 | !hda_codec_is_power_on(codec)); |
Takashi Iwai | 9e5341b | 2010-09-21 09:57:06 +0200 | [diff] [blame] | 2849 | hda_call_check_power_status(codec, nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | return change; |
| 2851 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2852 | EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | |
| 2854 | /* |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2855 | * bound volume controls |
| 2856 | * |
| 2857 | * bind multiple volumes (# indices, from 0) |
| 2858 | */ |
| 2859 | |
| 2860 | #define AMP_VAL_IDX_SHIFT 19 |
| 2861 | #define AMP_VAL_IDX_MASK (0x0f<<19) |
| 2862 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2863 | /** |
| 2864 | * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2865 | * @kcontrol: ctl element |
| 2866 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2867 | * |
| 2868 | * The control element is supposed to have the private_value field |
| 2869 | * set up via HDA_BIND_MUTE*() macros. |
| 2870 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2871 | int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, |
| 2872 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2873 | { |
| 2874 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2875 | unsigned long pval; |
| 2876 | int err; |
| 2877 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2878 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2879 | pval = kcontrol->private_value; |
| 2880 | kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */ |
| 2881 | err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); |
| 2882 | kcontrol->private_value = pval; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2883 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2884 | return err; |
| 2885 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2886 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_switch_get); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2887 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2888 | /** |
| 2889 | * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2890 | * @kcontrol: ctl element |
| 2891 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2892 | * |
| 2893 | * The control element is supposed to have the private_value field |
| 2894 | * set up via HDA_BIND_MUTE*() macros. |
| 2895 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2896 | int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, |
| 2897 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2898 | { |
| 2899 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2900 | unsigned long pval; |
| 2901 | int i, indices, err = 0, change = 0; |
| 2902 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2903 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2904 | pval = kcontrol->private_value; |
| 2905 | indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT; |
| 2906 | for (i = 0; i < indices; i++) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 2907 | kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | |
| 2908 | (i << AMP_VAL_IDX_SHIFT); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2909 | err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 2910 | if (err < 0) |
| 2911 | break; |
| 2912 | change |= err; |
| 2913 | } |
| 2914 | kcontrol->private_value = pval; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2915 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2916 | return err < 0 ? err : change; |
| 2917 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2918 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_switch_put); |
Takashi Iwai | 985be54 | 2005-11-02 18:26:49 +0100 | [diff] [blame] | 2919 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2920 | /** |
| 2921 | * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2922 | * @kcontrol: referred ctl element |
| 2923 | * @uinfo: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2924 | * |
| 2925 | * The control element is supposed to have the private_value field |
| 2926 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2927 | */ |
| 2928 | int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, |
| 2929 | struct snd_ctl_elem_info *uinfo) |
| 2930 | { |
| 2931 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2932 | struct hda_bind_ctls *c; |
| 2933 | int err; |
| 2934 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2935 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2936 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2937 | kcontrol->private_value = *c->values; |
| 2938 | err = c->ops->info(kcontrol, uinfo); |
| 2939 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2940 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2941 | return err; |
| 2942 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2943 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_info); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2944 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2945 | /** |
| 2946 | * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2947 | * @kcontrol: ctl element |
| 2948 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2949 | * |
| 2950 | * The control element is supposed to have the private_value field |
| 2951 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
| 2952 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2953 | int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, |
| 2954 | struct snd_ctl_elem_value *ucontrol) |
| 2955 | { |
| 2956 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2957 | struct hda_bind_ctls *c; |
| 2958 | int err; |
| 2959 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2960 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2961 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2962 | kcontrol->private_value = *c->values; |
| 2963 | err = c->ops->get(kcontrol, ucontrol); |
| 2964 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2965 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2966 | return err; |
| 2967 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2968 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_get); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2969 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2970 | /** |
| 2971 | * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 2972 | * @kcontrol: ctl element |
| 2973 | * @ucontrol: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 2974 | * |
| 2975 | * The control element is supposed to have the private_value field |
| 2976 | * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros. |
| 2977 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2978 | int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, |
| 2979 | struct snd_ctl_elem_value *ucontrol) |
| 2980 | { |
| 2981 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2982 | struct hda_bind_ctls *c; |
| 2983 | unsigned long *vals; |
| 2984 | int err = 0, change = 0; |
| 2985 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2986 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 2987 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2988 | for (vals = c->values; *vals; vals++) { |
| 2989 | kcontrol->private_value = *vals; |
| 2990 | err = c->ops->put(kcontrol, ucontrol); |
| 2991 | if (err < 0) |
| 2992 | break; |
| 2993 | change |= err; |
| 2994 | } |
| 2995 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 2996 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 2997 | return err < 0 ? err : change; |
| 2998 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 2999 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_ctls_put); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3000 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3001 | /** |
| 3002 | * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 3003 | * @kcontrol: ctl element |
| 3004 | * @op_flag: operation flag |
| 3005 | * @size: byte size of input TLV |
| 3006 | * @tlv: TLV data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3007 | * |
| 3008 | * The control element is supposed to have the private_value field |
| 3009 | * set up via HDA_BIND_VOL() macro. |
| 3010 | */ |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3011 | int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 3012 | unsigned int size, unsigned int __user *tlv) |
| 3013 | { |
| 3014 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3015 | struct hda_bind_ctls *c; |
| 3016 | int err; |
| 3017 | |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 3018 | mutex_lock(&codec->control_mutex); |
Serge A. Suchkov | 14c65f9 | 2008-02-22 18:43:16 +0100 | [diff] [blame] | 3019 | c = (struct hda_bind_ctls *)kcontrol->private_value; |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3020 | kcontrol->private_value = *c->values; |
| 3021 | err = c->ops->tlv(kcontrol, op_flag, size, tlv); |
| 3022 | kcontrol->private_value = (long)c; |
Wu Fengguang | 5a9e02e | 2009-01-09 16:45:24 +0800 | [diff] [blame] | 3023 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3024 | return err; |
| 3025 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3026 | EXPORT_SYMBOL_GPL(snd_hda_mixer_bind_tlv); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3027 | |
| 3028 | struct hda_ctl_ops snd_hda_bind_vol = { |
| 3029 | .info = snd_hda_mixer_amp_volume_info, |
| 3030 | .get = snd_hda_mixer_amp_volume_get, |
| 3031 | .put = snd_hda_mixer_amp_volume_put, |
| 3032 | .tlv = snd_hda_mixer_amp_tlv |
| 3033 | }; |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3034 | EXPORT_SYMBOL_GPL(snd_hda_bind_vol); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3035 | |
| 3036 | struct hda_ctl_ops snd_hda_bind_sw = { |
| 3037 | .info = snd_hda_mixer_amp_switch_info, |
| 3038 | .get = snd_hda_mixer_amp_switch_get, |
| 3039 | .put = snd_hda_mixer_amp_switch_put, |
| 3040 | .tlv = snd_hda_mixer_amp_tlv |
| 3041 | }; |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3042 | EXPORT_SYMBOL_GPL(snd_hda_bind_sw); |
Takashi Iwai | 532d538 | 2007-07-27 19:02:40 +0200 | [diff] [blame] | 3043 | |
| 3044 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | * SPDIF out controls |
| 3046 | */ |
| 3047 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3048 | static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol, |
| 3049 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | { |
| 3051 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 3052 | uinfo->count = 1; |
| 3053 | return 0; |
| 3054 | } |
| 3055 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3056 | static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, |
| 3057 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | { |
| 3059 | ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | |
| 3060 | IEC958_AES0_NONAUDIO | |
| 3061 | IEC958_AES0_CON_EMPHASIS_5015 | |
| 3062 | IEC958_AES0_CON_NOT_COPYRIGHT; |
| 3063 | ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY | |
| 3064 | IEC958_AES1_CON_ORIGINAL; |
| 3065 | return 0; |
| 3066 | } |
| 3067 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3068 | static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, |
| 3069 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | { |
| 3071 | ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | |
| 3072 | IEC958_AES0_NONAUDIO | |
| 3073 | IEC958_AES0_PRO_EMPHASIS_5015; |
| 3074 | return 0; |
| 3075 | } |
| 3076 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3077 | static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 3078 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | { |
| 3080 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3081 | int idx = kcontrol->private_value; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3082 | struct hda_spdif_out *spdif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3084 | mutex_lock(&codec->spdif_mutex); |
| 3085 | spdif = snd_array_elem(&codec->spdif_out, idx); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3086 | ucontrol->value.iec958.status[0] = spdif->status & 0xff; |
| 3087 | ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; |
| 3088 | ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; |
| 3089 | ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3090 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
| 3092 | return 0; |
| 3093 | } |
| 3094 | |
| 3095 | /* convert from SPDIF status bits to HDA SPDIF bits |
| 3096 | * bit 0 (DigEn) is always set zero (to be filled later) |
| 3097 | */ |
| 3098 | static unsigned short convert_from_spdif_status(unsigned int sbits) |
| 3099 | { |
| 3100 | unsigned short val = 0; |
| 3101 | |
| 3102 | if (sbits & IEC958_AES0_PROFESSIONAL) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3103 | val |= AC_DIG1_PROFESSIONAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | if (sbits & IEC958_AES0_NONAUDIO) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3105 | val |= AC_DIG1_NONAUDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | if (sbits & IEC958_AES0_PROFESSIONAL) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3107 | if ((sbits & IEC958_AES0_PRO_EMPHASIS) == |
| 3108 | IEC958_AES0_PRO_EMPHASIS_5015) |
| 3109 | val |= AC_DIG1_EMPHASIS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | } else { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3111 | if ((sbits & IEC958_AES0_CON_EMPHASIS) == |
| 3112 | IEC958_AES0_CON_EMPHASIS_5015) |
| 3113 | val |= AC_DIG1_EMPHASIS; |
| 3114 | if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT)) |
| 3115 | val |= AC_DIG1_COPYRIGHT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | if (sbits & (IEC958_AES1_CON_ORIGINAL << 8)) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3117 | val |= AC_DIG1_LEVEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | val |= sbits & (IEC958_AES1_CON_CATEGORY << 8); |
| 3119 | } |
| 3120 | return val; |
| 3121 | } |
| 3122 | |
| 3123 | /* convert to SPDIF status bits from HDA SPDIF bits |
| 3124 | */ |
| 3125 | static unsigned int convert_to_spdif_status(unsigned short val) |
| 3126 | { |
| 3127 | unsigned int sbits = 0; |
| 3128 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3129 | if (val & AC_DIG1_NONAUDIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | sbits |= IEC958_AES0_NONAUDIO; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3131 | if (val & AC_DIG1_PROFESSIONAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | sbits |= IEC958_AES0_PROFESSIONAL; |
| 3133 | if (sbits & IEC958_AES0_PROFESSIONAL) { |
Takashi Iwai | a686fd1 | 2013-03-20 15:42:00 +0100 | [diff] [blame] | 3134 | if (val & AC_DIG1_EMPHASIS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | sbits |= IEC958_AES0_PRO_EMPHASIS_5015; |
| 3136 | } else { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3137 | if (val & AC_DIG1_EMPHASIS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | sbits |= IEC958_AES0_CON_EMPHASIS_5015; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3139 | if (!(val & AC_DIG1_COPYRIGHT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | sbits |= IEC958_AES0_CON_NOT_COPYRIGHT; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3141 | if (val & AC_DIG1_LEVEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | sbits |= (IEC958_AES1_CON_ORIGINAL << 8); |
| 3143 | sbits |= val & (0x7f << 8); |
| 3144 | } |
| 3145 | return sbits; |
| 3146 | } |
| 3147 | |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 3148 | /* set digital convert verbs both for the given NID and its slaves */ |
| 3149 | static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, |
| 3150 | int verb, int val) |
| 3151 | { |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3152 | const hda_nid_t *d; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 3153 | |
Takashi Iwai | 9e97697 | 2008-11-25 08:17:20 +0100 | [diff] [blame] | 3154 | snd_hda_codec_write_cache(codec, nid, 0, verb, val); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 3155 | d = codec->slave_dig_outs; |
| 3156 | if (!d) |
| 3157 | return; |
| 3158 | for (; *d; d++) |
Takashi Iwai | 9e97697 | 2008-11-25 08:17:20 +0100 | [diff] [blame] | 3159 | snd_hda_codec_write_cache(codec, *d, 0, verb, val); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, |
| 3163 | int dig1, int dig2) |
| 3164 | { |
| 3165 | if (dig1 != -1) |
| 3166 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1); |
| 3167 | if (dig2 != -1) |
| 3168 | set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2); |
| 3169 | } |
| 3170 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3171 | static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 3172 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | { |
| 3174 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3175 | int idx = kcontrol->private_value; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3176 | struct hda_spdif_out *spdif; |
| 3177 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | unsigned short val; |
| 3179 | int change; |
| 3180 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3181 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3182 | spdif = snd_array_elem(&codec->spdif_out, idx); |
| 3183 | nid = spdif->nid; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3184 | spdif->status = ucontrol->value.iec958.status[0] | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | ((unsigned int)ucontrol->value.iec958.status[1] << 8) | |
| 3186 | ((unsigned int)ucontrol->value.iec958.status[2] << 16) | |
| 3187 | ((unsigned int)ucontrol->value.iec958.status[3] << 24); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3188 | val = convert_from_spdif_status(spdif->status); |
| 3189 | val |= spdif->ctls & 1; |
| 3190 | change = spdif->ctls != val; |
| 3191 | spdif->ctls = val; |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3192 | if (change && nid != (u16)-1) |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 3193 | set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3194 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | return change; |
| 3196 | } |
| 3197 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 3198 | #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3200 | static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, |
| 3201 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | { |
| 3203 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3204 | int idx = kcontrol->private_value; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3205 | struct hda_spdif_out *spdif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3207 | mutex_lock(&codec->spdif_mutex); |
| 3208 | spdif = snd_array_elem(&codec->spdif_out, idx); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3209 | ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3210 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | return 0; |
| 3212 | } |
| 3213 | |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3214 | static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, |
| 3215 | int dig1, int dig2) |
| 3216 | { |
| 3217 | set_dig_out_convert(codec, nid, dig1, dig2); |
| 3218 | /* unmute amp switch (if any) */ |
| 3219 | if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && |
| 3220 | (dig1 & AC_DIG1_ENABLE)) |
| 3221 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
| 3222 | HDA_AMP_MUTE, 0); |
| 3223 | } |
| 3224 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3225 | static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, |
| 3226 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { |
| 3228 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3229 | int idx = kcontrol->private_value; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3230 | struct hda_spdif_out *spdif; |
| 3231 | hda_nid_t nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | unsigned short val; |
| 3233 | int change; |
| 3234 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3235 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3236 | spdif = snd_array_elem(&codec->spdif_out, idx); |
| 3237 | nid = spdif->nid; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3238 | val = spdif->ctls & ~AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | if (ucontrol->value.integer.value[0]) |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3240 | val |= AC_DIG1_ENABLE; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3241 | change = spdif->ctls != val; |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3242 | spdif->ctls = val; |
| 3243 | if (change && nid != (u16)-1) |
| 3244 | set_spdif_ctls(codec, nid, val & 0xff, -1); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3245 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | return change; |
| 3247 | } |
| 3248 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3249 | static struct snd_kcontrol_new dig_mixes[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | { |
| 3251 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 3252 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3253 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | .info = snd_hda_spdif_mask_info, |
| 3255 | .get = snd_hda_spdif_cmask_get, |
| 3256 | }, |
| 3257 | { |
| 3258 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 3259 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3260 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | .info = snd_hda_spdif_mask_info, |
| 3262 | .get = snd_hda_spdif_pmask_get, |
| 3263 | }, |
| 3264 | { |
| 3265 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3266 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | .info = snd_hda_spdif_mask_info, |
| 3268 | .get = snd_hda_spdif_default_get, |
| 3269 | .put = snd_hda_spdif_default_put, |
| 3270 | }, |
| 3271 | { |
| 3272 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3273 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | .info = snd_hda_spdif_out_switch_info, |
| 3275 | .get = snd_hda_spdif_out_switch_get, |
| 3276 | .put = snd_hda_spdif_out_switch_put, |
| 3277 | }, |
| 3278 | { } /* end */ |
| 3279 | }; |
| 3280 | |
| 3281 | /** |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3282 | * snd_hda_create_dig_out_ctls - create Output SPDIF-related controls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | * @codec: the HDA codec |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3284 | * @associated_nid: NID that new ctls associated with |
| 3285 | * @cvt_nid: converter NID |
| 3286 | * @type: HDA_PCM_TYPE_* |
| 3287 | * Creates controls related with the digital output. |
| 3288 | * Called from each patch supporting the digital out. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | * |
| 3290 | * Returns 0 if successful, or a negative error code. |
| 3291 | */ |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3292 | int snd_hda_create_dig_out_ctls(struct hda_codec *codec, |
| 3293 | hda_nid_t associated_nid, |
| 3294 | hda_nid_t cvt_nid, |
| 3295 | int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | { |
| 3297 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3298 | struct snd_kcontrol *kctl; |
| 3299 | struct snd_kcontrol_new *dig_mix; |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3300 | int idx = 0; |
| 3301 | const int spdif_index = 16; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3302 | struct hda_spdif_out *spdif; |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3303 | struct hda_bus *bus = codec->bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3305 | if (bus->primary_dig_out_type == HDA_PCM_TYPE_HDMI && |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3306 | type == HDA_PCM_TYPE_SPDIF) { |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3307 | idx = spdif_index; |
| 3308 | } else if (bus->primary_dig_out_type == HDA_PCM_TYPE_SPDIF && |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3309 | type == HDA_PCM_TYPE_HDMI) { |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3310 | /* suppose a single SPDIF device */ |
| 3311 | for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { |
| 3312 | kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); |
| 3313 | if (!kctl) |
| 3314 | break; |
| 3315 | kctl->id.index = spdif_index; |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3316 | } |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3317 | bus->primary_dig_out_type = HDA_PCM_TYPE_HDMI; |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3318 | } |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3319 | if (!bus->primary_dig_out_type) |
| 3320 | bus->primary_dig_out_type = type; |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3321 | |
Takashi Iwai | ea9b43a | 2013-02-12 17:02:41 +0100 | [diff] [blame] | 3322 | idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 3323 | if (idx < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3324 | codec_err(codec, "too many IEC958 outputs\n"); |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 3325 | return -EBUSY; |
| 3326 | } |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3327 | spdif = snd_array_new(&codec->spdif_out); |
Mengdong Lin | 25336e8 | 2013-03-07 14:10:25 -0500 | [diff] [blame] | 3328 | if (!spdif) |
| 3329 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { |
| 3331 | kctl = snd_ctl_new1(dig_mix, codec); |
Takashi Iwai | b91f080 | 2008-11-04 08:43:08 +0100 | [diff] [blame] | 3332 | if (!kctl) |
| 3333 | return -ENOMEM; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 3334 | kctl->id.index = idx; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3335 | kctl->private_value = codec->spdif_out.used - 1; |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3336 | err = snd_hda_ctl_add(codec, associated_nid, kctl); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3337 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | return err; |
| 3339 | } |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3340 | spdif->nid = cvt_nid; |
| 3341 | spdif->ctls = snd_hda_codec_read(codec, cvt_nid, 0, |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3342 | AC_VERB_GET_DIGI_CONVERT_1, 0); |
| 3343 | spdif->status = convert_to_spdif_status(spdif->ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | return 0; |
| 3345 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3346 | EXPORT_SYMBOL_GPL(snd_hda_create_dig_out_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 3348 | /** |
| 3349 | * snd_hda_spdif_out_of_nid - get the hda_spdif_out entry from the given NID |
| 3350 | * @codec: the HDA codec |
| 3351 | * @nid: widget NID |
| 3352 | * |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3353 | * call within spdif_mutex lock |
| 3354 | */ |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3355 | struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, |
| 3356 | hda_nid_t nid) |
| 3357 | { |
| 3358 | int i; |
| 3359 | for (i = 0; i < codec->spdif_out.used; i++) { |
| 3360 | struct hda_spdif_out *spdif = |
| 3361 | snd_array_elem(&codec->spdif_out, i); |
| 3362 | if (spdif->nid == nid) |
| 3363 | return spdif; |
| 3364 | } |
| 3365 | return NULL; |
| 3366 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3367 | EXPORT_SYMBOL_GPL(snd_hda_spdif_out_of_nid); |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3368 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 3369 | /** |
| 3370 | * snd_hda_spdif_ctls_unassign - Unassign the given SPDIF ctl |
| 3371 | * @codec: the HDA codec |
| 3372 | * @idx: the SPDIF ctl index |
| 3373 | * |
| 3374 | * Unassign the widget from the given SPDIF control. |
| 3375 | */ |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3376 | void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) |
| 3377 | { |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3378 | struct hda_spdif_out *spdif; |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3379 | |
| 3380 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3381 | spdif = snd_array_elem(&codec->spdif_out, idx); |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3382 | spdif->nid = (u16)-1; |
| 3383 | mutex_unlock(&codec->spdif_mutex); |
| 3384 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3385 | EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_unassign); |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3386 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 3387 | /** |
| 3388 | * snd_hda_spdif_ctls_assign - Assign the SPDIF controls to the given NID |
| 3389 | * @codec: the HDA codec |
| 3390 | * @idx: the SPDIF ctl idx |
| 3391 | * @nid: widget NID |
| 3392 | * |
| 3393 | * Assign the widget to the SPDIF control with the given index. |
| 3394 | */ |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3395 | void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) |
| 3396 | { |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3397 | struct hda_spdif_out *spdif; |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3398 | unsigned short val; |
| 3399 | |
| 3400 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3401 | spdif = snd_array_elem(&codec->spdif_out, idx); |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3402 | if (spdif->nid != nid) { |
| 3403 | spdif->nid = nid; |
| 3404 | val = spdif->ctls; |
| 3405 | set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); |
| 3406 | } |
| 3407 | mutex_unlock(&codec->spdif_mutex); |
| 3408 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3409 | EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_assign); |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 3410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | /* |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3412 | * SPDIF sharing with analog output |
| 3413 | */ |
| 3414 | static int spdif_share_sw_get(struct snd_kcontrol *kcontrol, |
| 3415 | struct snd_ctl_elem_value *ucontrol) |
| 3416 | { |
| 3417 | struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol); |
| 3418 | ucontrol->value.integer.value[0] = mout->share_spdif; |
| 3419 | return 0; |
| 3420 | } |
| 3421 | |
| 3422 | static int spdif_share_sw_put(struct snd_kcontrol *kcontrol, |
| 3423 | struct snd_ctl_elem_value *ucontrol) |
| 3424 | { |
| 3425 | struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol); |
| 3426 | mout->share_spdif = !!ucontrol->value.integer.value[0]; |
| 3427 | return 0; |
| 3428 | } |
| 3429 | |
| 3430 | static struct snd_kcontrol_new spdif_share_sw = { |
| 3431 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3432 | .name = "IEC958 Default PCM Playback Switch", |
| 3433 | .info = snd_ctl_boolean_mono_info, |
| 3434 | .get = spdif_share_sw_get, |
| 3435 | .put = spdif_share_sw_put, |
| 3436 | }; |
| 3437 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3438 | /** |
| 3439 | * snd_hda_create_spdif_share_sw - create Default PCM switch |
| 3440 | * @codec: the HDA codec |
| 3441 | * @mout: multi-out instance |
| 3442 | */ |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3443 | int snd_hda_create_spdif_share_sw(struct hda_codec *codec, |
| 3444 | struct hda_multi_out *mout) |
| 3445 | { |
Mengdong Lin | 4c7a548 | 2013-03-07 14:11:05 -0500 | [diff] [blame] | 3446 | struct snd_kcontrol *kctl; |
| 3447 | |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3448 | if (!mout->dig_out_nid) |
| 3449 | return 0; |
Mengdong Lin | 4c7a548 | 2013-03-07 14:11:05 -0500 | [diff] [blame] | 3450 | |
| 3451 | kctl = snd_ctl_new1(&spdif_share_sw, mout); |
| 3452 | if (!kctl) |
| 3453 | return -ENOMEM; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3454 | /* ATTENTION: here mout is passed as private_data, instead of codec */ |
Mengdong Lin | 4c7a548 | 2013-03-07 14:11:05 -0500 | [diff] [blame] | 3455 | return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3456 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3457 | EXPORT_SYMBOL_GPL(snd_hda_create_spdif_share_sw); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 3458 | |
| 3459 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | * SPDIF input |
| 3461 | */ |
| 3462 | |
| 3463 | #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info |
| 3464 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3465 | static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, |
| 3466 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | { |
| 3468 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3469 | |
| 3470 | ucontrol->value.integer.value[0] = codec->spdif_in_enable; |
| 3471 | return 0; |
| 3472 | } |
| 3473 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3474 | static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, |
| 3475 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | { |
| 3477 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3478 | hda_nid_t nid = kcontrol->private_value; |
| 3479 | unsigned int val = !!ucontrol->value.integer.value[0]; |
| 3480 | int change; |
| 3481 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3482 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | change = codec->spdif_in_enable != val; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 3484 | if (change) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | codec->spdif_in_enable = val; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 3486 | snd_hda_codec_write_cache(codec, nid, 0, |
| 3487 | AC_VERB_SET_DIGI_CONVERT_1, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3489 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | return change; |
| 3491 | } |
| 3492 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3493 | static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, |
| 3494 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | { |
| 3496 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3497 | hda_nid_t nid = kcontrol->private_value; |
| 3498 | unsigned short val; |
| 3499 | unsigned int sbits; |
| 3500 | |
Andrew Paprocki | 3982d17 | 2007-12-19 12:13:44 +0100 | [diff] [blame] | 3501 | 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] | 3502 | sbits = convert_to_spdif_status(val); |
| 3503 | ucontrol->value.iec958.status[0] = sbits; |
| 3504 | ucontrol->value.iec958.status[1] = sbits >> 8; |
| 3505 | ucontrol->value.iec958.status[2] = sbits >> 16; |
| 3506 | ucontrol->value.iec958.status[3] = sbits >> 24; |
| 3507 | return 0; |
| 3508 | } |
| 3509 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3510 | static struct snd_kcontrol_new dig_in_ctls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | { |
| 3512 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3513 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | .info = snd_hda_spdif_in_switch_info, |
| 3515 | .get = snd_hda_spdif_in_switch_get, |
| 3516 | .put = snd_hda_spdif_in_switch_put, |
| 3517 | }, |
| 3518 | { |
| 3519 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 3520 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 3521 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | .info = snd_hda_spdif_mask_info, |
| 3523 | .get = snd_hda_spdif_in_status_get, |
| 3524 | }, |
| 3525 | { } /* end */ |
| 3526 | }; |
| 3527 | |
| 3528 | /** |
| 3529 | * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls |
| 3530 | * @codec: the HDA codec |
| 3531 | * @nid: audio in widget NID |
| 3532 | * |
| 3533 | * Creates controls related with the SPDIF input. |
| 3534 | * Called from each patch supporting the SPDIF in. |
| 3535 | * |
| 3536 | * Returns 0 if successful, or a negative error code. |
| 3537 | */ |
Takashi Iwai | 12f288b | 2007-08-02 15:51:59 +0200 | [diff] [blame] | 3538 | 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] | 3539 | { |
| 3540 | int err; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 3541 | struct snd_kcontrol *kctl; |
| 3542 | struct snd_kcontrol_new *dig_mix; |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 3543 | int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 3545 | idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 3546 | if (idx < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3547 | codec_err(codec, "too many IEC958 inputs\n"); |
Takashi Iwai | 09f9970 | 2008-02-04 12:31:13 +0100 | [diff] [blame] | 3548 | return -EBUSY; |
| 3549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { |
| 3551 | kctl = snd_ctl_new1(dig_mix, codec); |
Takashi Iwai | c8dcdf8 | 2009-02-06 16:21:20 +0100 | [diff] [blame] | 3552 | if (!kctl) |
| 3553 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | kctl->private_value = nid; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 3555 | err = snd_hda_ctl_add(codec, nid, kctl); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3556 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return err; |
| 3558 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3559 | codec->spdif_in_enable = |
Andrew Paprocki | 3982d17 | 2007-12-19 12:13:44 +0100 | [diff] [blame] | 3560 | snd_hda_codec_read(codec, nid, 0, |
| 3561 | AC_VERB_GET_DIGI_CONVERT_1, 0) & |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 3562 | AC_DIG1_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | return 0; |
| 3564 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3565 | EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 3567 | /* |
| 3568 | * command cache |
| 3569 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3571 | /* build a 31bit cache key with the widget id and the command parameter */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3572 | #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid) |
| 3573 | #define get_cmd_cache_nid(key) ((key) & 0xff) |
| 3574 | #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff) |
| 3575 | |
| 3576 | /** |
| 3577 | * snd_hda_codec_write_cache - send a single command with caching |
| 3578 | * @codec: the HDA codec |
| 3579 | * @nid: NID to send the command |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3580 | * @flags: optional bit flags |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3581 | * @verb: the verb to send |
| 3582 | * @parm: the parameter for the verb |
| 3583 | * |
| 3584 | * Send a single command without waiting for response. |
| 3585 | * |
| 3586 | * Returns 0 if successful, or a negative error code. |
| 3587 | */ |
| 3588 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3589 | int flags, unsigned int verb, unsigned int parm) |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3590 | { |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3591 | int err; |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 3592 | struct hda_cache_head *c; |
| 3593 | u32 key; |
Takashi Iwai | de1e37b | 2012-12-20 11:00:21 +0100 | [diff] [blame] | 3594 | unsigned int cache_only; |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 3595 | |
Takashi Iwai | de1e37b | 2012-12-20 11:00:21 +0100 | [diff] [blame] | 3596 | cache_only = codec->cached_write; |
| 3597 | if (!cache_only) { |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3598 | err = snd_hda_codec_write(codec, nid, flags, verb, parm); |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3599 | if (err < 0) |
| 3600 | return err; |
| 3601 | } |
| 3602 | |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 3603 | /* parm may contain the verb stuff for get/set amp */ |
| 3604 | verb = verb | (parm >> 8); |
| 3605 | parm &= 0xff; |
| 3606 | key = build_cmd_cache_key(nid, verb); |
| 3607 | mutex_lock(&codec->bus->cmd_mutex); |
| 3608 | c = get_alloc_hash(&codec->cmd_cache, key); |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3609 | if (c) { |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 3610 | c->val = parm; |
Takashi Iwai | de1e37b | 2012-12-20 11:00:21 +0100 | [diff] [blame] | 3611 | c->dirty = cache_only; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3612 | } |
Takashi Iwai | aa2936f | 2009-05-26 16:07:57 +0200 | [diff] [blame] | 3613 | mutex_unlock(&codec->bus->cmd_mutex); |
| 3614 | return 0; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3615 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3616 | EXPORT_SYMBOL_GPL(snd_hda_codec_write_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3617 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3618 | /** |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 3619 | * snd_hda_codec_update_cache - check cache and write the cmd only when needed |
| 3620 | * @codec: the HDA codec |
| 3621 | * @nid: NID to send the command |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3622 | * @flags: optional bit flags |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 3623 | * @verb: the verb to send |
| 3624 | * @parm: the parameter for the verb |
| 3625 | * |
| 3626 | * This function works like snd_hda_codec_write_cache(), but it doesn't send |
| 3627 | * command if the parameter is already identical with the cached value. |
| 3628 | * If not, it sends the command and refreshes the cache. |
| 3629 | * |
| 3630 | * Returns 0 if successful, or a negative error code. |
| 3631 | */ |
| 3632 | int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3633 | int flags, unsigned int verb, unsigned int parm) |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 3634 | { |
| 3635 | struct hda_cache_head *c; |
| 3636 | u32 key; |
| 3637 | |
| 3638 | /* parm may contain the verb stuff for get/set amp */ |
| 3639 | verb = verb | (parm >> 8); |
| 3640 | parm &= 0xff; |
| 3641 | key = build_cmd_cache_key(nid, verb); |
| 3642 | mutex_lock(&codec->bus->cmd_mutex); |
| 3643 | c = get_hash(&codec->cmd_cache, key); |
| 3644 | if (c && c->val == parm) { |
| 3645 | mutex_unlock(&codec->bus->cmd_mutex); |
| 3646 | return 0; |
| 3647 | } |
| 3648 | mutex_unlock(&codec->bus->cmd_mutex); |
Takashi Iwai | e7ecc27 | 2013-06-06 14:00:23 +0200 | [diff] [blame] | 3649 | return snd_hda_codec_write_cache(codec, nid, flags, verb, parm); |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 3650 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3651 | EXPORT_SYMBOL_GPL(snd_hda_codec_update_cache); |
Takashi Iwai | a68d5a5 | 2010-03-30 18:03:44 +0200 | [diff] [blame] | 3652 | |
| 3653 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 3654 | * snd_hda_codec_resume_cache - Resume the all commands from the cache |
| 3655 | * @codec: HD-audio codec |
| 3656 | * |
| 3657 | * Execute all verbs recorded in the command caches to resume. |
| 3658 | */ |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3659 | void snd_hda_codec_resume_cache(struct hda_codec *codec) |
| 3660 | { |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3661 | int i; |
| 3662 | |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3663 | mutex_lock(&codec->hash_mutex); |
Takashi Iwai | aa88a35 | 2012-12-20 11:02:00 +0100 | [diff] [blame] | 3664 | codec->cached_write = 0; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3665 | for (i = 0; i < codec->cmd_cache.buf.used; i++) { |
| 3666 | struct hda_cache_head *buffer; |
| 3667 | u32 key; |
| 3668 | |
| 3669 | buffer = snd_array_elem(&codec->cmd_cache.buf, i); |
| 3670 | key = buffer->key; |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3671 | if (!key) |
| 3672 | continue; |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3673 | if (!buffer->dirty) |
| 3674 | continue; |
| 3675 | buffer->dirty = 0; |
| 3676 | mutex_unlock(&codec->hash_mutex); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3677 | snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0, |
| 3678 | get_cmd_cache_cmd(key), buffer->val); |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3679 | mutex_lock(&codec->hash_mutex); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3680 | } |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3681 | mutex_unlock(&codec->hash_mutex); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3682 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3683 | EXPORT_SYMBOL_GPL(snd_hda_codec_resume_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3684 | |
| 3685 | /** |
| 3686 | * snd_hda_sequence_write_cache - sequence writes with caching |
| 3687 | * @codec: the HDA codec |
| 3688 | * @seq: VERB array to send |
| 3689 | * |
| 3690 | * Send the commands sequentially from the given array. |
| 3691 | * Thte commands are recorded on cache for power-save and resume. |
| 3692 | * The array must be terminated with NID=0. |
| 3693 | */ |
| 3694 | void snd_hda_sequence_write_cache(struct hda_codec *codec, |
| 3695 | const struct hda_verb *seq) |
| 3696 | { |
| 3697 | for (; seq->nid; seq++) |
| 3698 | snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, |
| 3699 | seq->param); |
| 3700 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3701 | EXPORT_SYMBOL_GPL(snd_hda_sequence_write_cache); |
Takashi Iwai | b3ac563 | 2007-08-10 17:03:40 +0200 | [diff] [blame] | 3702 | |
Takashi Iwai | dc870f3 | 2013-01-22 15:24:30 +0100 | [diff] [blame] | 3703 | /** |
| 3704 | * snd_hda_codec_flush_cache - Execute all pending (cached) amps / verbs |
| 3705 | * @codec: HD-audio codec |
| 3706 | */ |
| 3707 | void snd_hda_codec_flush_cache(struct hda_codec *codec) |
| 3708 | { |
| 3709 | snd_hda_codec_resume_amp(codec); |
| 3710 | snd_hda_codec_resume_cache(codec); |
| 3711 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3712 | EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); |
Takashi Iwai | dc870f3 | 2013-01-22 15:24:30 +0100 | [diff] [blame] | 3713 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 3714 | /** |
| 3715 | * snd_hda_codec_set_power_to_all - Set the power state to all widgets |
| 3716 | * @codec: the HDA codec |
| 3717 | * @fg: function group (not used now) |
| 3718 | * @power_state: the power state to set (AC_PWRST_*) |
| 3719 | * |
| 3720 | * Set the given power state to all widgets that have the power control. |
| 3721 | * If the codec has power_filter set, it evaluates the power state and |
| 3722 | * filter out if it's unchanged as D3. |
| 3723 | */ |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3724 | void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3725 | unsigned int power_state) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3726 | { |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3727 | hda_nid_t nid = codec->start_nid; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3728 | int i; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3729 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3730 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
Takashi Iwai | 7eba5c9 | 2007-11-14 14:53:42 +0100 | [diff] [blame] | 3731 | unsigned int wcaps = get_wcaps(codec, nid); |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3732 | unsigned int state = power_state; |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3733 | if (!(wcaps & AC_WCAP_POWER)) |
| 3734 | continue; |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3735 | if (codec->power_filter) { |
| 3736 | state = codec->power_filter(codec, nid, power_state); |
| 3737 | if (state != power_state && power_state == AC_PWRST_D3) |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3738 | continue; |
Takashi Iwai | 1194b5b | 2007-10-10 10:04:26 +0200 | [diff] [blame] | 3739 | } |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3740 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3741 | state); |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3742 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3743 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3744 | EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all); |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3745 | |
| 3746 | /* |
Wang Xingchao | 0c7f46a | 2012-06-06 22:02:48 +0800 | [diff] [blame] | 3747 | * supported power states check |
| 3748 | */ |
| 3749 | static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg, |
| 3750 | unsigned int power_state) |
| 3751 | { |
| 3752 | int sup = snd_hda_param_read(codec, fg, AC_PAR_POWER_STATE); |
| 3753 | |
Mengdong Lin | e037cb4 | 2012-08-10 14:11:58 +0200 | [diff] [blame] | 3754 | if (sup == -1) |
Wang Xingchao | 0c7f46a | 2012-06-06 22:02:48 +0800 | [diff] [blame] | 3755 | return false; |
| 3756 | if (sup & power_state) |
| 3757 | return true; |
| 3758 | else |
| 3759 | return false; |
| 3760 | } |
| 3761 | |
| 3762 | /* |
Takashi Iwai | 432c641 | 2012-08-28 09:59:20 -0700 | [diff] [blame] | 3763 | * wait until the state is reached, returns the current state |
| 3764 | */ |
| 3765 | static unsigned int hda_sync_power_state(struct hda_codec *codec, |
| 3766 | hda_nid_t fg, |
| 3767 | unsigned int power_state) |
| 3768 | { |
| 3769 | unsigned long end_time = jiffies + msecs_to_jiffies(500); |
| 3770 | unsigned int state, actual_state; |
| 3771 | |
| 3772 | for (;;) { |
| 3773 | state = snd_hda_codec_read(codec, fg, 0, |
| 3774 | AC_VERB_GET_POWER_STATE, 0); |
| 3775 | if (state & AC_PWRST_ERROR) |
| 3776 | break; |
| 3777 | actual_state = (state >> 4) & 0x0f; |
| 3778 | if (actual_state == power_state) |
| 3779 | break; |
| 3780 | if (time_after_eq(jiffies, end_time)) |
| 3781 | break; |
| 3782 | /* wait until the codec reachs to the target state */ |
| 3783 | msleep(1); |
| 3784 | } |
| 3785 | return state; |
| 3786 | } |
| 3787 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 3788 | /** |
| 3789 | * snd_hda_codec_eapd_power_filter - A power filter callback for EAPD |
| 3790 | * @codec: the HDA codec |
| 3791 | * @nid: widget NID |
| 3792 | * @power_state: power state to evalue |
| 3793 | * |
| 3794 | * Don't power down the widget if it controls eapd and EAPD_BTLENABLE is set. |
| 3795 | * This can be used a codec power_filter callback. |
| 3796 | */ |
Takashi Iwai | ba615b8 | 2013-03-13 14:47:21 +0100 | [diff] [blame] | 3797 | unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, |
| 3798 | hda_nid_t nid, |
| 3799 | unsigned int power_state) |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3800 | { |
Takashi Iwai | dfc6e46 | 2014-01-13 16:09:57 +0100 | [diff] [blame] | 3801 | if (nid == codec->afg || nid == codec->mfg) |
| 3802 | return power_state; |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3803 | if (power_state == AC_PWRST_D3 && |
| 3804 | get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && |
| 3805 | (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { |
| 3806 | int eapd = snd_hda_codec_read(codec, nid, 0, |
| 3807 | AC_VERB_GET_EAPD_BTLENABLE, 0); |
| 3808 | if (eapd & 0x02) |
| 3809 | return AC_PWRST_D0; |
| 3810 | } |
| 3811 | return power_state; |
| 3812 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 3813 | EXPORT_SYMBOL_GPL(snd_hda_codec_eapd_power_filter); |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3814 | |
Takashi Iwai | 432c641 | 2012-08-28 09:59:20 -0700 | [diff] [blame] | 3815 | /* |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3816 | * set power state of the codec, and return the power state |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3817 | */ |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 3818 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3819 | unsigned int power_state) |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3820 | { |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 3821 | hda_nid_t fg = codec->afg ? codec->afg : codec->mfg; |
Wang Xingchao | 09617ce | 2012-06-08 10:26:08 +0800 | [diff] [blame] | 3822 | int count; |
| 3823 | unsigned int state; |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 3824 | int flags = 0; |
Wang Xingchao | 09617ce | 2012-06-08 10:26:08 +0800 | [diff] [blame] | 3825 | |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3826 | /* this delay seems necessary to avoid click noise at power-down */ |
Wang Xingchao | 0f4ccbb | 2012-06-07 16:51:33 +0800 | [diff] [blame] | 3827 | if (power_state == AC_PWRST_D3) { |
Mengdong Lin | 7f13292 | 2013-11-29 01:48:45 -0500 | [diff] [blame] | 3828 | if (codec->depop_delay < 0) |
| 3829 | msleep(codec->epss ? 10 : 100); |
| 3830 | else if (codec->depop_delay > 0) |
| 3831 | msleep(codec->depop_delay); |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 3832 | flags = HDA_RW_NO_RESPONSE_FALLBACK; |
Wang Xingchao | 0f4ccbb | 2012-06-07 16:51:33 +0800 | [diff] [blame] | 3833 | } |
Wang Xingchao | 09617ce | 2012-06-08 10:26:08 +0800 | [diff] [blame] | 3834 | |
| 3835 | /* repeat power states setting at most 10 times*/ |
| 3836 | for (count = 0; count < 10; count++) { |
Takashi Iwai | 432c641 | 2012-08-28 09:59:20 -0700 | [diff] [blame] | 3837 | if (codec->patch_ops.set_power_state) |
| 3838 | codec->patch_ops.set_power_state(codec, fg, |
| 3839 | power_state); |
| 3840 | else { |
Takashi Iwai | dfc6e46 | 2014-01-13 16:09:57 +0100 | [diff] [blame] | 3841 | state = power_state; |
| 3842 | if (codec->power_filter) |
| 3843 | state = codec->power_filter(codec, fg, state); |
| 3844 | if (state == power_state || power_state != AC_PWRST_D3) |
| 3845 | snd_hda_codec_read(codec, fg, flags, |
| 3846 | AC_VERB_SET_POWER_STATE, |
| 3847 | state); |
Takashi Iwai | 9419ab6 | 2013-01-24 17:23:35 +0100 | [diff] [blame] | 3848 | snd_hda_codec_set_power_to_all(codec, fg, power_state); |
Takashi Iwai | 432c641 | 2012-08-28 09:59:20 -0700 | [diff] [blame] | 3849 | } |
| 3850 | state = hda_sync_power_state(codec, fg, power_state); |
Wang Xingchao | 09617ce | 2012-06-08 10:26:08 +0800 | [diff] [blame] | 3851 | if (!(state & AC_PWRST_ERROR)) |
| 3852 | break; |
| 3853 | } |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 3854 | |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3855 | return state; |
Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 3856 | } |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3857 | |
Takashi Iwai | b9c590b | 2013-01-24 17:27:32 +0100 | [diff] [blame] | 3858 | /* sync power states of all widgets; |
| 3859 | * this is called at the end of codec parsing |
| 3860 | */ |
| 3861 | static void sync_power_up_states(struct hda_codec *codec) |
| 3862 | { |
| 3863 | hda_nid_t nid = codec->start_nid; |
| 3864 | int i; |
| 3865 | |
Takashi Iwai | ba615b8 | 2013-03-13 14:47:21 +0100 | [diff] [blame] | 3866 | /* don't care if no filter is used */ |
| 3867 | if (!codec->power_filter) |
Takashi Iwai | b9c590b | 2013-01-24 17:27:32 +0100 | [diff] [blame] | 3868 | return; |
| 3869 | |
| 3870 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 3871 | unsigned int wcaps = get_wcaps(codec, nid); |
Takashi Iwai | 9040d10 | 2013-01-24 17:47:17 +0100 | [diff] [blame] | 3872 | unsigned int target; |
Takashi Iwai | b9c590b | 2013-01-24 17:27:32 +0100 | [diff] [blame] | 3873 | if (!(wcaps & AC_WCAP_POWER)) |
| 3874 | continue; |
| 3875 | target = codec->power_filter(codec, nid, AC_PWRST_D0); |
| 3876 | if (target == AC_PWRST_D0) |
| 3877 | continue; |
Takashi Iwai | 9040d10 | 2013-01-24 17:47:17 +0100 | [diff] [blame] | 3878 | if (!snd_hda_check_power_state(codec, nid, target)) |
Takashi Iwai | b9c590b | 2013-01-24 17:27:32 +0100 | [diff] [blame] | 3879 | snd_hda_codec_write(codec, nid, 0, |
| 3880 | AC_VERB_SET_POWER_STATE, target); |
| 3881 | } |
| 3882 | } |
| 3883 | |
Takashi Iwai | 648a8d2 | 2014-02-25 10:38:13 +0100 | [diff] [blame] | 3884 | #ifdef CONFIG_SND_HDA_RECONFIG |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 3885 | /* execute additional init verbs */ |
| 3886 | static void hda_exec_init_verbs(struct hda_codec *codec) |
| 3887 | { |
| 3888 | if (codec->init_verbs.list) |
| 3889 | snd_hda_sequence_write(codec, codec->init_verbs.list); |
| 3890 | } |
| 3891 | #else |
| 3892 | static inline void hda_exec_init_verbs(struct hda_codec *codec) {} |
| 3893 | #endif |
| 3894 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 3895 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3896 | /* |
| 3897 | * call suspend and power-down; used both from PM and power-save |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3898 | * this function returns the power state in the end |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3899 | */ |
Dylan Reid | d17344b | 2012-09-28 15:57:01 -0700 | [diff] [blame] | 3900 | static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3901 | { |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3902 | unsigned int state; |
| 3903 | |
Takashi Iwai | 989c318 | 2012-11-19 14:14:58 +0100 | [diff] [blame] | 3904 | codec->in_pm = 1; |
| 3905 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3906 | if (codec->patch_ops.suspend) |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 3907 | codec->patch_ops.suspend(codec); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 3908 | hda_cleanup_all_streams(codec); |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 3909 | state = hda_set_power_state(codec, AC_PWRST_D3); |
Dylan Reid | d17344b | 2012-09-28 15:57:01 -0700 | [diff] [blame] | 3910 | /* Cancel delayed work if we aren't currently running from it. */ |
| 3911 | if (!in_wq) |
| 3912 | cancel_delayed_work_sync(&codec->power_work); |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 3913 | spin_lock(&codec->power_lock); |
| 3914 | snd_hda_update_power_acct(codec); |
| 3915 | trace_hda_power_down(codec); |
Takashi Iwai | 95e99fd | 2007-08-13 15:29:04 +0200 | [diff] [blame] | 3916 | codec->power_on = 0; |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 3917 | codec->power_transition = 0; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 3918 | codec->power_jiffies = jiffies; |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 3919 | spin_unlock(&codec->power_lock); |
Takashi Iwai | 989c318 | 2012-11-19 14:14:58 +0100 | [diff] [blame] | 3920 | codec->in_pm = 0; |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 3921 | return state; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3922 | } |
| 3923 | |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3924 | /* mark all entries of cmd and amp caches dirty */ |
| 3925 | static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) |
| 3926 | { |
| 3927 | int i; |
| 3928 | for (i = 0; i < codec->cmd_cache.buf.used; i++) { |
| 3929 | struct hda_cache_head *cmd; |
| 3930 | cmd = snd_array_elem(&codec->cmd_cache.buf, i); |
| 3931 | cmd->dirty = 1; |
| 3932 | } |
| 3933 | for (i = 0; i < codec->amp_cache.buf.used; i++) { |
| 3934 | struct hda_amp_info *amp; |
David Henningsson | f038fca | 2013-01-15 15:27:19 +0100 | [diff] [blame] | 3935 | amp = snd_array_elem(&codec->amp_cache.buf, i); |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3936 | amp->head.dirty = 1; |
| 3937 | } |
| 3938 | } |
| 3939 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3940 | /* |
| 3941 | * kick up codec; used both from PM and power-save |
| 3942 | */ |
| 3943 | static void hda_call_codec_resume(struct hda_codec *codec) |
| 3944 | { |
Takashi Iwai | 989c318 | 2012-11-19 14:14:58 +0100 | [diff] [blame] | 3945 | codec->in_pm = 1; |
| 3946 | |
Takashi Iwai | c370dd6 | 2012-12-13 18:30:04 +0100 | [diff] [blame] | 3947 | hda_mark_cmd_cache_dirty(codec); |
| 3948 | |
Takashi Iwai | 7f30830 | 2012-05-08 16:52:23 +0200 | [diff] [blame] | 3949 | /* set as if powered on for avoiding re-entering the resume |
| 3950 | * in the resume / power-save sequence |
| 3951 | */ |
| 3952 | hda_keep_power_on(codec); |
Takashi Iwai | d819387 | 2012-08-31 07:54:38 -0700 | [diff] [blame] | 3953 | hda_set_power_state(codec, AC_PWRST_D0); |
Takashi Iwai | ac0547d | 2010-07-05 16:50:13 +0200 | [diff] [blame] | 3954 | restore_shutup_pins(codec); |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 3955 | hda_exec_init_verbs(codec); |
Takashi Iwai | 31614bb | 2013-01-23 15:58:40 +0100 | [diff] [blame] | 3956 | snd_hda_jack_set_dirty_all(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3957 | if (codec->patch_ops.resume) |
| 3958 | codec->patch_ops.resume(codec); |
| 3959 | else { |
Takashi Iwai | 9d99f31 | 2007-08-14 15:15:52 +0200 | [diff] [blame] | 3960 | if (codec->patch_ops.init) |
| 3961 | codec->patch_ops.init(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3962 | snd_hda_codec_resume_amp(codec); |
| 3963 | snd_hda_codec_resume_cache(codec); |
| 3964 | } |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 3965 | |
| 3966 | if (codec->jackpoll_interval) |
| 3967 | hda_jackpoll_work(&codec->jackpoll_work.work); |
Takashi Iwai | 31614bb | 2013-01-23 15:58:40 +0100 | [diff] [blame] | 3968 | else |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 3969 | snd_hda_jack_report_sync(codec); |
Takashi Iwai | 989c318 | 2012-11-19 14:14:58 +0100 | [diff] [blame] | 3970 | |
| 3971 | codec->in_pm = 0; |
Takashi Iwai | 7f30830 | 2012-05-08 16:52:23 +0200 | [diff] [blame] | 3972 | snd_hda_power_down(codec); /* flag down before returning */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3973 | } |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 3974 | |
| 3975 | static int hda_codec_driver_suspend(struct device *dev) |
| 3976 | { |
| 3977 | struct hda_codec *codec = dev_to_hda_codec(dev); |
| 3978 | int i; |
| 3979 | |
| 3980 | cancel_delayed_work_sync(&codec->jackpoll_work); |
| 3981 | for (i = 0; i < codec->num_pcms; i++) |
| 3982 | snd_pcm_suspend_all(codec->pcm_info[i].pcm); |
| 3983 | hda_call_codec_suspend(codec, false); |
| 3984 | return 0; |
| 3985 | } |
| 3986 | |
| 3987 | static int hda_codec_driver_resume(struct device *dev) |
| 3988 | { |
| 3989 | hda_call_codec_resume(dev_to_hda_codec(dev)); |
| 3990 | return 0; |
| 3991 | } |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 3992 | #endif /* CONFIG_PM */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3993 | |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 3994 | /* referred in hda_bind.c */ |
| 3995 | const struct dev_pm_ops hda_codec_driver_pm = { |
| 3996 | SET_SYSTEM_SLEEP_PM_OPS(hda_codec_driver_suspend, |
| 3997 | hda_codec_driver_resume) |
| 3998 | }; |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 3999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | /** |
| 4001 | * snd_hda_build_controls - build mixer controls |
| 4002 | * @bus: the BUS |
| 4003 | * |
| 4004 | * Creates mixer controls for each codec included in the bus. |
| 4005 | * |
| 4006 | * Returns 0 if successful, otherwise a negative error code. |
| 4007 | */ |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 4008 | int snd_hda_build_controls(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4010 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4012 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4013 | int err = snd_hda_codec_build_controls(codec); |
Takashi Iwai | f93d461 | 2009-03-02 10:44:15 +0100 | [diff] [blame] | 4014 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4015 | codec_err(codec, |
| 4016 | "cannot build controls for #%d (error %d)\n", |
| 4017 | codec->addr, err); |
Takashi Iwai | f93d461 | 2009-03-02 10:44:15 +0100 | [diff] [blame] | 4018 | err = snd_hda_codec_reset(codec); |
| 4019 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4020 | codec_err(codec, |
| 4021 | "cannot revert codec\n"); |
Takashi Iwai | f93d461 | 2009-03-02 10:44:15 +0100 | [diff] [blame] | 4022 | return err; |
| 4023 | } |
| 4024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | } |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4026 | return 0; |
| 4027 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4028 | EXPORT_SYMBOL_GPL(snd_hda_build_controls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | |
Takashi Iwai | 9c9a517 | 2012-07-31 11:35:35 +0200 | [diff] [blame] | 4030 | /* |
| 4031 | * add standard channel maps if not specified |
| 4032 | */ |
| 4033 | static int add_std_chmaps(struct hda_codec *codec) |
| 4034 | { |
| 4035 | int i, str, err; |
| 4036 | |
| 4037 | for (i = 0; i < codec->num_pcms; i++) { |
| 4038 | for (str = 0; str < 2; str++) { |
| 4039 | struct snd_pcm *pcm = codec->pcm_info[i].pcm; |
| 4040 | struct hda_pcm_stream *hinfo = |
| 4041 | &codec->pcm_info[i].stream[str]; |
| 4042 | struct snd_pcm_chmap *chmap; |
Takashi Iwai | ee81abb | 2012-11-08 17:12:10 +0100 | [diff] [blame] | 4043 | const struct snd_pcm_chmap_elem *elem; |
Takashi Iwai | 9c9a517 | 2012-07-31 11:35:35 +0200 | [diff] [blame] | 4044 | |
| 4045 | if (codec->pcm_info[i].own_chmap) |
| 4046 | continue; |
| 4047 | if (!pcm || !hinfo->substreams) |
| 4048 | continue; |
Takashi Iwai | ee81abb | 2012-11-08 17:12:10 +0100 | [diff] [blame] | 4049 | elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; |
| 4050 | err = snd_pcm_add_chmap_ctls(pcm, str, elem, |
Takashi Iwai | 9c9a517 | 2012-07-31 11:35:35 +0200 | [diff] [blame] | 4051 | hinfo->channels_max, |
| 4052 | 0, &chmap); |
| 4053 | if (err < 0) |
| 4054 | return err; |
| 4055 | chmap->channel_mask = SND_PCM_CHMAP_MASK_2468; |
| 4056 | } |
| 4057 | } |
| 4058 | return 0; |
| 4059 | } |
| 4060 | |
Takashi Iwai | ee81abb | 2012-11-08 17:12:10 +0100 | [diff] [blame] | 4061 | /* default channel maps for 2.1 speakers; |
| 4062 | * since HD-audio supports only stereo, odd number channels are omitted |
| 4063 | */ |
| 4064 | const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[] = { |
| 4065 | { .channels = 2, |
| 4066 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, |
| 4067 | { .channels = 4, |
| 4068 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, |
| 4069 | SNDRV_CHMAP_LFE, SNDRV_CHMAP_LFE } }, |
| 4070 | { } |
| 4071 | }; |
| 4072 | EXPORT_SYMBOL_GPL(snd_pcm_2_1_chmaps); |
| 4073 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4074 | int snd_hda_codec_build_controls(struct hda_codec *codec) |
| 4075 | { |
| 4076 | int err = 0; |
Takashi Iwai | 11aeff0 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 4077 | hda_exec_init_verbs(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4078 | /* continue to initialize... */ |
| 4079 | if (codec->patch_ops.init) |
| 4080 | err = codec->patch_ops.init(codec); |
| 4081 | if (!err && codec->patch_ops.build_controls) |
| 4082 | err = codec->patch_ops.build_controls(codec); |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4083 | if (err < 0) |
| 4084 | return err; |
Takashi Iwai | 9c9a517 | 2012-07-31 11:35:35 +0200 | [diff] [blame] | 4085 | |
| 4086 | /* we create chmaps here instead of build_pcms */ |
| 4087 | err = add_std_chmaps(codec); |
| 4088 | if (err < 0) |
| 4089 | return err; |
| 4090 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 4091 | if (codec->jackpoll_interval) |
| 4092 | hda_jackpoll_work(&codec->jackpoll_work.work); |
| 4093 | else |
| 4094 | snd_hda_jack_report_sync(codec); /* call at the last init point */ |
Takashi Iwai | b9c590b | 2013-01-24 17:27:32 +0100 | [diff] [blame] | 4095 | sync_power_up_states(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | return 0; |
| 4097 | } |
| 4098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | /* |
| 4100 | * stream formats |
| 4101 | */ |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4102 | struct hda_rate_tbl { |
| 4103 | unsigned int hz; |
| 4104 | unsigned int alsa_bits; |
| 4105 | unsigned int hda_fmt; |
| 4106 | }; |
| 4107 | |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4108 | /* rate = base * mult / div */ |
| 4109 | #define HDA_RATE(base, mult, div) \ |
| 4110 | (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \ |
| 4111 | (((div) - 1) << AC_FMT_DIV_SHIFT)) |
| 4112 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4113 | static struct hda_rate_tbl rate_bits[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | /* rate in Hz, ALSA rate bitmask, HDA format value */ |
Nicolas Graziano | 9d8f53f | 2005-08-22 13:47:16 +0200 | [diff] [blame] | 4115 | |
| 4116 | /* autodetected value used in snd_hda_query_supported_pcm */ |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4117 | { 8000, SNDRV_PCM_RATE_8000, HDA_RATE(48, 1, 6) }, |
| 4118 | { 11025, SNDRV_PCM_RATE_11025, HDA_RATE(44, 1, 4) }, |
| 4119 | { 16000, SNDRV_PCM_RATE_16000, HDA_RATE(48, 1, 3) }, |
| 4120 | { 22050, SNDRV_PCM_RATE_22050, HDA_RATE(44, 1, 2) }, |
| 4121 | { 32000, SNDRV_PCM_RATE_32000, HDA_RATE(48, 2, 3) }, |
| 4122 | { 44100, SNDRV_PCM_RATE_44100, HDA_RATE(44, 1, 1) }, |
| 4123 | { 48000, SNDRV_PCM_RATE_48000, HDA_RATE(48, 1, 1) }, |
| 4124 | { 88200, SNDRV_PCM_RATE_88200, HDA_RATE(44, 2, 1) }, |
| 4125 | { 96000, SNDRV_PCM_RATE_96000, HDA_RATE(48, 2, 1) }, |
| 4126 | { 176400, SNDRV_PCM_RATE_176400, HDA_RATE(44, 4, 1) }, |
| 4127 | { 192000, SNDRV_PCM_RATE_192000, HDA_RATE(48, 4, 1) }, |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 4128 | #define AC_PAR_PCM_RATE_BITS 11 |
| 4129 | /* up to bits 10, 384kHZ isn't supported properly */ |
| 4130 | |
| 4131 | /* not autodetected value */ |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4132 | { 9600, SNDRV_PCM_RATE_KNOT, HDA_RATE(48, 1, 5) }, |
Nicolas Graziano | 9d8f53f | 2005-08-22 13:47:16 +0200 | [diff] [blame] | 4133 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4134 | { 0 } /* terminator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | }; |
| 4136 | |
| 4137 | /** |
| 4138 | * snd_hda_calc_stream_format - calculate format bitset |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 4139 | * @codec: HD-audio codec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | * @rate: the sample rate |
| 4141 | * @channels: the number of channels |
| 4142 | * @format: the PCM format (SNDRV_PCM_FORMAT_XXX) |
| 4143 | * @maxbps: the max. bps |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4144 | * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | * |
| 4146 | * Calculate the format bitset from the given rate, channels and th PCM format. |
| 4147 | * |
| 4148 | * Return zero if invalid. |
| 4149 | */ |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 4150 | unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, |
| 4151 | unsigned int rate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | unsigned int channels, |
| 4153 | unsigned int format, |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 4154 | unsigned int maxbps, |
| 4155 | unsigned short spdif_ctls) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | { |
| 4157 | int i; |
| 4158 | unsigned int val = 0; |
| 4159 | |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4160 | for (i = 0; rate_bits[i].hz; i++) |
| 4161 | if (rate_bits[i].hz == rate) { |
| 4162 | val = rate_bits[i].hda_fmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | break; |
| 4164 | } |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4165 | if (!rate_bits[i].hz) { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 4166 | codec_dbg(codec, "invalid rate %d\n", rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | return 0; |
| 4168 | } |
| 4169 | |
| 4170 | if (channels == 0 || channels > 8) { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 4171 | codec_dbg(codec, "invalid channels %d\n", channels); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | return 0; |
| 4173 | } |
| 4174 | val |= channels - 1; |
| 4175 | |
| 4176 | switch (snd_pcm_format_width(format)) { |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4177 | case 8: |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4178 | val |= AC_FMT_BITS_8; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4179 | break; |
| 4180 | case 16: |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4181 | val |= AC_FMT_BITS_16; |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | case 20: |
| 4184 | case 24: |
| 4185 | case 32: |
Takashi Iwai | b0bb3aa | 2009-07-03 23:25:37 +0200 | [diff] [blame] | 4186 | if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4187 | val |= AC_FMT_BITS_32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | else if (maxbps >= 24) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4189 | val |= AC_FMT_BITS_24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | else |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4191 | val |= AC_FMT_BITS_20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | break; |
| 4193 | default: |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 4194 | codec_dbg(codec, "invalid format width %d\n", |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4195 | snd_pcm_format_width(format)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | return 0; |
| 4197 | } |
| 4198 | |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 4199 | if (spdif_ctls & AC_DIG1_NONAUDIO) |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 4200 | val |= AC_FMT_TYPE_NON_PCM; |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 4201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | return val; |
| 4203 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4204 | EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 4206 | static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, |
| 4207 | int dir) |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4208 | { |
| 4209 | unsigned int val = 0; |
| 4210 | if (nid != codec->afg && |
| 4211 | (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) |
| 4212 | val = snd_hda_param_read(codec, nid, AC_PAR_PCM); |
| 4213 | if (!val || val == -1) |
| 4214 | val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); |
| 4215 | if (!val || val == -1) |
| 4216 | return 0; |
| 4217 | return val; |
| 4218 | } |
| 4219 | |
| 4220 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) |
| 4221 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 4222 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid), |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4223 | get_pcm_param); |
| 4224 | } |
| 4225 | |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 4226 | static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, |
| 4227 | int dir) |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4228 | { |
| 4229 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); |
| 4230 | if (!streams || streams == -1) |
| 4231 | streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); |
| 4232 | if (!streams || streams == -1) |
| 4233 | return 0; |
| 4234 | return streams; |
| 4235 | } |
| 4236 | |
| 4237 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) |
| 4238 | { |
Takashi Iwai | c3b6bcc | 2012-05-10 16:11:15 +0200 | [diff] [blame] | 4239 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid), |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4240 | get_stream_param); |
| 4241 | } |
| 4242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | /** |
| 4244 | * snd_hda_query_supported_pcm - query the supported PCM rates and formats |
| 4245 | * @codec: the HDA codec |
| 4246 | * @nid: NID to query |
| 4247 | * @ratesp: the pointer to store the detected rate bitflags |
| 4248 | * @formatsp: the pointer to store the detected formats |
| 4249 | * @bpsp: the pointer to store the detected format widths |
| 4250 | * |
| 4251 | * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp |
| 4252 | * or @bsps argument is ignored. |
| 4253 | * |
| 4254 | * Returns 0 if successful, otherwise a negative error code. |
| 4255 | */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 4256 | 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] | 4257 | u32 *ratesp, u64 *formatsp, unsigned int *bpsp) |
| 4258 | { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4259 | unsigned int i, val, wcaps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4261 | wcaps = get_wcaps(codec, nid); |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4262 | val = query_pcm_param(codec, nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | |
| 4264 | if (ratesp) { |
| 4265 | u32 rates = 0; |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 4266 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | if (val & (1 << i)) |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4268 | rates |= rate_bits[i].alsa_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | } |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4270 | if (rates == 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4271 | codec_err(codec, |
| 4272 | "rates == 0 (nid=0x%x, val=0x%x, ovrd=%i)\n", |
| 4273 | nid, val, |
| 4274 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4275 | return -EIO; |
| 4276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | *ratesp = rates; |
| 4278 | } |
| 4279 | |
| 4280 | if (formatsp || bpsp) { |
| 4281 | u64 formats = 0; |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4282 | unsigned int streams, bps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4284 | streams = query_stream_param(codec, nid); |
| 4285 | if (!streams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | |
| 4288 | bps = 0; |
| 4289 | if (streams & AC_SUPFMT_PCM) { |
| 4290 | if (val & AC_SUPPCM_BITS_8) { |
| 4291 | formats |= SNDRV_PCM_FMTBIT_U8; |
| 4292 | bps = 8; |
| 4293 | } |
| 4294 | if (val & AC_SUPPCM_BITS_16) { |
| 4295 | formats |= SNDRV_PCM_FMTBIT_S16_LE; |
| 4296 | bps = 16; |
| 4297 | } |
| 4298 | if (wcaps & AC_WCAP_DIGITAL) { |
| 4299 | if (val & AC_SUPPCM_BITS_32) |
| 4300 | formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE; |
| 4301 | if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24)) |
| 4302 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 4303 | if (val & AC_SUPPCM_BITS_24) |
| 4304 | bps = 24; |
| 4305 | else if (val & AC_SUPPCM_BITS_20) |
| 4306 | bps = 20; |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4307 | } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24| |
| 4308 | AC_SUPPCM_BITS_32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 4310 | if (val & AC_SUPPCM_BITS_32) |
| 4311 | bps = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | else if (val & AC_SUPPCM_BITS_24) |
| 4313 | bps = 24; |
Nicolas Graziano | 33ef7651 | 2006-09-19 14:23:14 +0200 | [diff] [blame] | 4314 | else if (val & AC_SUPPCM_BITS_20) |
| 4315 | bps = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | } |
| 4317 | } |
Takashi Iwai | 8c7dd89 | 2012-05-12 09:38:05 +0200 | [diff] [blame] | 4318 | #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ |
Takashi Iwai | b5025c5 | 2009-07-01 18:05:27 +0200 | [diff] [blame] | 4319 | if (streams & AC_SUPFMT_FLOAT32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; |
Takashi Iwai | b0bb3aa | 2009-07-03 23:25:37 +0200 | [diff] [blame] | 4321 | if (!bps) |
| 4322 | bps = 32; |
Takashi Iwai | b5025c5 | 2009-07-01 18:05:27 +0200 | [diff] [blame] | 4323 | } |
Takashi Iwai | 8c7dd89 | 2012-05-12 09:38:05 +0200 | [diff] [blame] | 4324 | #endif |
Takashi Iwai | b5025c5 | 2009-07-01 18:05:27 +0200 | [diff] [blame] | 4325 | if (streams == AC_SUPFMT_AC3) { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4326 | /* should be exclusive */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | /* temporary hack: we have still no proper support |
| 4328 | * for the direct AC3 stream... |
| 4329 | */ |
| 4330 | formats |= SNDRV_PCM_FMTBIT_U8; |
| 4331 | bps = 8; |
| 4332 | } |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4333 | if (formats == 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4334 | codec_err(codec, |
| 4335 | "formats == 0 (nid=0x%x, val=0x%x, ovrd=%i, streams=0x%x)\n", |
| 4336 | nid, val, |
| 4337 | (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0, |
| 4338 | streams); |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4339 | return -EIO; |
| 4340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | if (formatsp) |
| 4342 | *formatsp = formats; |
| 4343 | if (bpsp) |
| 4344 | *bpsp = bps; |
| 4345 | } |
| 4346 | |
| 4347 | return 0; |
| 4348 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4349 | EXPORT_SYMBOL_GPL(snd_hda_query_supported_pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | |
| 4351 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4352 | * snd_hda_is_supported_format - Check the validity of the format |
| 4353 | * @codec: HD-audio codec |
| 4354 | * @nid: NID to check |
| 4355 | * @format: the HD-audio format value to check |
| 4356 | * |
| 4357 | * Check whether the given node supports the format value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | * |
| 4359 | * Returns 1 if supported, 0 if not. |
| 4360 | */ |
| 4361 | int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, |
| 4362 | unsigned int format) |
| 4363 | { |
| 4364 | int i; |
| 4365 | unsigned int val = 0, rate, stream; |
| 4366 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4367 | val = query_pcm_param(codec, nid); |
| 4368 | if (!val) |
| 4369 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | |
| 4371 | rate = format & 0xff00; |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 4372 | for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) |
Takashi Iwai | befdf31 | 2005-08-22 13:57:55 +0200 | [diff] [blame] | 4373 | if (rate_bits[i].hda_fmt == rate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | if (val & (1 << i)) |
| 4375 | break; |
| 4376 | return 0; |
| 4377 | } |
Takashi Iwai | a961f9f | 2007-04-12 13:08:09 +0200 | [diff] [blame] | 4378 | if (i >= AC_PAR_PCM_RATE_BITS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | return 0; |
| 4380 | |
Takashi Iwai | 92c7c8a | 2009-03-24 07:32:14 +0100 | [diff] [blame] | 4381 | stream = query_stream_param(codec, nid); |
| 4382 | if (!stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | return 0; |
| 4384 | |
| 4385 | if (stream & AC_SUPFMT_PCM) { |
| 4386 | switch (format & 0xf0) { |
| 4387 | case 0x00: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4388 | if (!(val & AC_SUPPCM_BITS_8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | return 0; |
| 4390 | break; |
| 4391 | case 0x10: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4392 | if (!(val & AC_SUPPCM_BITS_16)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | return 0; |
| 4394 | break; |
| 4395 | case 0x20: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4396 | if (!(val & AC_SUPPCM_BITS_20)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | return 0; |
| 4398 | break; |
| 4399 | case 0x30: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4400 | if (!(val & AC_SUPPCM_BITS_24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | return 0; |
| 4402 | break; |
| 4403 | case 0x40: |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4404 | if (!(val & AC_SUPPCM_BITS_32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | return 0; |
| 4406 | break; |
| 4407 | default: |
| 4408 | return 0; |
| 4409 | } |
| 4410 | } else { |
| 4411 | /* FIXME: check for float32 and AC3? */ |
| 4412 | } |
| 4413 | |
| 4414 | return 1; |
| 4415 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4416 | EXPORT_SYMBOL_GPL(snd_hda_is_supported_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | |
| 4418 | /* |
| 4419 | * PCM stuff |
| 4420 | */ |
| 4421 | static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo, |
| 4422 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4423 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | { |
| 4425 | return 0; |
| 4426 | } |
| 4427 | |
| 4428 | static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo, |
| 4429 | struct hda_codec *codec, |
| 4430 | unsigned int stream_tag, |
| 4431 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4432 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | { |
| 4434 | snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); |
| 4435 | return 0; |
| 4436 | } |
| 4437 | |
| 4438 | static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo, |
| 4439 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4440 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | { |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 4442 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | return 0; |
| 4444 | } |
| 4445 | |
Takashi Iwai | 6c1f45e | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4446 | static int set_pcm_default_values(struct hda_codec *codec, |
| 4447 | struct hda_pcm_stream *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4449 | int err; |
| 4450 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4451 | /* query support PCM information from the given NID */ |
| 4452 | if (info->nid && (!info->rates || !info->formats)) { |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4453 | err = snd_hda_query_supported_pcm(codec, info->nid, |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4454 | info->rates ? NULL : &info->rates, |
| 4455 | info->formats ? NULL : &info->formats, |
| 4456 | info->maxbps ? NULL : &info->maxbps); |
Jaroslav Kysela | ee50471 | 2009-03-17 14:30:31 +0100 | [diff] [blame] | 4457 | if (err < 0) |
| 4458 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | } |
| 4460 | if (info->ops.open == NULL) |
| 4461 | info->ops.open = hda_pcm_default_open_close; |
| 4462 | if (info->ops.close == NULL) |
| 4463 | info->ops.close = hda_pcm_default_open_close; |
| 4464 | if (info->ops.prepare == NULL) { |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 4465 | if (snd_BUG_ON(!info->nid)) |
| 4466 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | info->ops.prepare = hda_pcm_default_prepare; |
| 4468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | if (info->ops.cleanup == NULL) { |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 4470 | if (snd_BUG_ON(!info->nid)) |
| 4471 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | info->ops.cleanup = hda_pcm_default_cleanup; |
| 4473 | } |
| 4474 | return 0; |
| 4475 | } |
| 4476 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4477 | /* |
| 4478 | * codec prepare/cleanup entries |
| 4479 | */ |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 4480 | /** |
| 4481 | * snd_hda_codec_prepare - Prepare a stream |
| 4482 | * @codec: the HDA codec |
| 4483 | * @hinfo: PCM information |
| 4484 | * @stream: stream tag to assign |
| 4485 | * @format: format id to assign |
| 4486 | * @substream: PCM substream to assign |
| 4487 | * |
| 4488 | * Calls the prepare callback set by the codec with the given arguments. |
| 4489 | * Clean up the inactive streams when successful. |
| 4490 | */ |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4491 | int snd_hda_codec_prepare(struct hda_codec *codec, |
| 4492 | struct hda_pcm_stream *hinfo, |
| 4493 | unsigned int stream, |
| 4494 | unsigned int format, |
| 4495 | struct snd_pcm_substream *substream) |
| 4496 | { |
| 4497 | int ret; |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 4498 | mutex_lock(&codec->bus->prepare_mutex); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4499 | ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); |
| 4500 | if (ret >= 0) |
| 4501 | purify_inactive_streams(codec); |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 4502 | mutex_unlock(&codec->bus->prepare_mutex); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4503 | return ret; |
| 4504 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4505 | EXPORT_SYMBOL_GPL(snd_hda_codec_prepare); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4506 | |
Takashi Iwai | 95a962c | 2014-10-29 16:03:58 +0100 | [diff] [blame] | 4507 | /** |
| 4508 | * snd_hda_codec_cleanup - Prepare a stream |
| 4509 | * @codec: the HDA codec |
| 4510 | * @hinfo: PCM information |
| 4511 | * @substream: PCM substream |
| 4512 | * |
| 4513 | * Calls the cleanup callback set by the codec with the given arguments. |
| 4514 | */ |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4515 | void snd_hda_codec_cleanup(struct hda_codec *codec, |
| 4516 | struct hda_pcm_stream *hinfo, |
| 4517 | struct snd_pcm_substream *substream) |
| 4518 | { |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 4519 | mutex_lock(&codec->bus->prepare_mutex); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4520 | hinfo->ops.cleanup(hinfo, codec, substream); |
Takashi Iwai | 3f50ac6 | 2010-08-20 09:44:36 +0200 | [diff] [blame] | 4521 | mutex_unlock(&codec->bus->prepare_mutex); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4522 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4523 | EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 4524 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4525 | /* global */ |
Jaroslav Kysela | e330323 | 2009-11-10 14:53:02 +0100 | [diff] [blame] | 4526 | const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = { |
| 4527 | "Audio", "SPDIF", "HDMI", "Modem" |
| 4528 | }; |
| 4529 | |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4530 | /* |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4531 | * get the empty PCM device number to assign |
| 4532 | */ |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4533 | static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type) |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4534 | { |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4535 | /* audio device indices; not linear to keep compatibility */ |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4536 | /* assigned to static slots up to dev#10; if more needed, assign |
| 4537 | * the later slot dynamically (when CONFIG_SND_DYNAMIC_MINORS=y) |
| 4538 | */ |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4539 | static int audio_idx[HDA_PCM_NTYPES][5] = { |
| 4540 | [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 }, |
| 4541 | [HDA_PCM_TYPE_SPDIF] = { 1, -1 }, |
Wu Fengguang | 92608ba | 2009-10-30 11:40:03 +0100 | [diff] [blame] | 4542 | [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 }, |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4543 | [HDA_PCM_TYPE_MODEM] = { 6, -1 }, |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4544 | }; |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4545 | int i; |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4546 | |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4547 | if (type >= HDA_PCM_NTYPES) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4548 | dev_err(bus->card->dev, "Invalid PCM type %d\n", type); |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4549 | return -EINVAL; |
| 4550 | } |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4551 | |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4552 | for (i = 0; audio_idx[type][i] >= 0; i++) { |
| 4553 | #ifndef CONFIG_SND_DYNAMIC_MINORS |
| 4554 | if (audio_idx[type][i] >= 8) |
| 4555 | break; |
| 4556 | #endif |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4557 | if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits)) |
| 4558 | return audio_idx[type][i]; |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4559 | } |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4560 | |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4561 | #ifdef CONFIG_SND_DYNAMIC_MINORS |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 4562 | /* non-fixed slots starting from 10 */ |
| 4563 | for (i = 10; i < 32; i++) { |
| 4564 | if (!test_and_set_bit(i, bus->pcm_dev_bits)) |
| 4565 | return i; |
| 4566 | } |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4567 | #endif |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 4568 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4569 | dev_warn(bus->card->dev, "Too many %s devices\n", |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4570 | snd_hda_pcm_type_name[type]); |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4571 | #ifndef CONFIG_SND_DYNAMIC_MINORS |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4572 | dev_warn(bus->card->dev, |
| 4573 | "Consider building the kernel with CONFIG_SND_DYNAMIC_MINORS=y\n"); |
Takashi Iwai | 36bb00d | 2013-06-06 12:10:24 +0200 | [diff] [blame] | 4574 | #endif |
Wu Fengguang | f5d6def | 2009-10-30 11:38:26 +0100 | [diff] [blame] | 4575 | return -EAGAIN; |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /* |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4579 | * attach a new PCM stream |
| 4580 | */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4581 | 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] | 4582 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 4583 | struct hda_bus *bus = codec->bus; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4584 | struct hda_pcm_stream *info; |
| 4585 | int stream, err; |
| 4586 | |
Takashi Iwai | b91f080 | 2008-11-04 08:43:08 +0100 | [diff] [blame] | 4587 | if (snd_BUG_ON(!pcm->name)) |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4588 | return -EINVAL; |
| 4589 | for (stream = 0; stream < 2; stream++) { |
| 4590 | info = &pcm->stream[stream]; |
| 4591 | if (info->substreams) { |
| 4592 | err = set_pcm_default_values(codec, info); |
| 4593 | if (err < 0) |
| 4594 | return err; |
| 4595 | } |
| 4596 | } |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 4597 | return bus->ops.attach_pcm(bus, codec, pcm); |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4598 | } |
| 4599 | |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4600 | /* assign all PCMs of the given codec */ |
| 4601 | int snd_hda_codec_build_pcms(struct hda_codec *codec) |
| 4602 | { |
| 4603 | unsigned int pcm; |
| 4604 | int err; |
| 4605 | |
| 4606 | if (!codec->num_pcms) { |
| 4607 | if (!codec->patch_ops.build_pcms) |
| 4608 | return 0; |
| 4609 | err = codec->patch_ops.build_pcms(codec); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4610 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4611 | codec_err(codec, |
| 4612 | "cannot build PCMs for #%d (error %d)\n", |
| 4613 | codec->addr, err); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4614 | err = snd_hda_codec_reset(codec); |
| 4615 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4616 | codec_err(codec, |
| 4617 | "cannot revert codec\n"); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4618 | return err; |
| 4619 | } |
| 4620 | } |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4621 | } |
| 4622 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { |
| 4623 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; |
| 4624 | int dev; |
| 4625 | |
| 4626 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) |
Takashi Iwai | 41b5b01 | 2009-01-20 18:21:23 +0100 | [diff] [blame] | 4627 | continue; /* no substreams assigned */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4628 | |
| 4629 | if (!cpcm->pcm) { |
| 4630 | dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); |
| 4631 | if (dev < 0) |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4632 | continue; /* no fatal error */ |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4633 | cpcm->device = dev; |
| 4634 | err = snd_hda_attach_pcm(codec, cpcm); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4635 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4636 | codec_err(codec, |
| 4637 | "cannot attach PCM stream %d for codec #%d\n", |
| 4638 | dev, codec->addr); |
Takashi Iwai | 6e655bf | 2009-03-02 10:46:03 +0100 | [diff] [blame] | 4639 | continue; /* no fatal error */ |
| 4640 | } |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | return 0; |
| 4644 | } |
| 4645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | /** |
| 4647 | * snd_hda_build_pcms - build PCM information |
| 4648 | * @bus: the BUS |
| 4649 | * |
| 4650 | * Create PCM information for each codec included in the bus. |
| 4651 | * |
| 4652 | * The build_pcms codec patch is requested to set up codec->num_pcms and |
| 4653 | * codec->pcm_info properly. The array is referred by the top-level driver |
| 4654 | * to create its PCM instances. |
| 4655 | * The allocated codec->pcm_info should be released in codec->patch_ops.free |
| 4656 | * callback. |
| 4657 | * |
| 4658 | * At least, substreams, channels_min and channels_max must be filled for |
| 4659 | * each stream. substreams = 0 indicates that the stream doesn't exist. |
| 4660 | * When rates and/or formats are zero, the supported values are queried |
| 4661 | * from the given nid. The nid is used also by the default ops.prepare |
| 4662 | * and ops.cleanup callbacks. |
| 4663 | * |
| 4664 | * The driver needs to call ops.open in its open callback. Similarly, |
| 4665 | * ops.close is supposed to be called in the close callback. |
| 4666 | * ops.prepare should be called in the prepare or hw_params callback |
| 4667 | * with the proper parameters for set up. |
| 4668 | * ops.cleanup should be called in hw_free for clean up of streams. |
| 4669 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4670 | * This function returns 0 if successful, or a negative error code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | */ |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 4672 | int snd_hda_build_pcms(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4674 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4676 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 529bd6c | 2008-11-27 14:17:01 +0100 | [diff] [blame] | 4677 | int err = snd_hda_codec_build_pcms(codec); |
| 4678 | if (err < 0) |
| 4679 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | } |
| 4681 | return 0; |
| 4682 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4683 | EXPORT_SYMBOL_GPL(snd_hda_build_pcms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | * snd_hda_add_new_ctls - create controls from the array |
| 4687 | * @codec: the HDA codec |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4688 | * @knew: the array of struct snd_kcontrol_new |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | * |
| 4690 | * This helper function creates and add new controls in the given array. |
| 4691 | * The array must be terminated with an empty entry as terminator. |
| 4692 | * |
| 4693 | * Returns 0 if successful, or a negative error code. |
| 4694 | */ |
Takashi Iwai | 031024e | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4695 | int snd_hda_add_new_ctls(struct hda_codec *codec, |
| 4696 | const struct snd_kcontrol_new *knew) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | { |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 4698 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | |
| 4700 | for (; knew->name; knew++) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 4701 | struct snd_kcontrol *kctl; |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 4702 | int addr = 0, idx = 0; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4703 | if (knew->iface == -1) /* skip this codec private value */ |
| 4704 | continue; |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 4705 | for (;;) { |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 4706 | kctl = snd_ctl_new1(knew, codec); |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4707 | if (!kctl) |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 4708 | return -ENOMEM; |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 4709 | if (addr > 0) |
| 4710 | kctl->id.device = addr; |
| 4711 | if (idx > 0) |
| 4712 | kctl->id.index = idx; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 4713 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 4714 | if (!err) |
| 4715 | break; |
| 4716 | /* try first with another device index corresponding to |
| 4717 | * the codec addr; if it still fails (or it's the |
| 4718 | * primary codec), then try another control index |
| 4719 | */ |
| 4720 | if (!addr && codec->addr) |
| 4721 | addr = codec->addr; |
| 4722 | else if (!idx && !knew->index) { |
| 4723 | idx = find_empty_mixer_ctl_idx(codec, |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 4724 | knew->name, 0); |
Takashi Iwai | 1afe206 | 2010-12-23 10:17:52 +0100 | [diff] [blame] | 4725 | if (idx <= 0) |
| 4726 | return err; |
| 4727 | } else |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 4728 | return err; |
| 4729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
| 4731 | return 0; |
| 4732 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4733 | EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 4735 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4736 | static void hda_power_work(struct work_struct *work) |
| 4737 | { |
| 4738 | struct hda_codec *codec = |
| 4739 | container_of(work, struct hda_codec, power_work.work); |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 4740 | struct hda_bus *bus = codec->bus; |
Takashi Iwai | 08fa20a | 2012-08-31 07:46:56 -0700 | [diff] [blame] | 4741 | unsigned int state; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4742 | |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4743 | spin_lock(&codec->power_lock); |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 4744 | if (codec->power_transition > 0) { /* during power-up sequence? */ |
| 4745 | spin_unlock(&codec->power_lock); |
| 4746 | return; |
| 4747 | } |
Maxim Levitsky | 2e49246 | 2007-09-03 15:26:57 +0200 | [diff] [blame] | 4748 | if (!codec->power_on || codec->power_count) { |
| 4749 | codec->power_transition = 0; |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4750 | spin_unlock(&codec->power_lock); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4751 | return; |
Maxim Levitsky | 2e49246 | 2007-09-03 15:26:57 +0200 | [diff] [blame] | 4752 | } |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4753 | spin_unlock(&codec->power_lock); |
| 4754 | |
Dylan Reid | d17344b | 2012-09-28 15:57:01 -0700 | [diff] [blame] | 4755 | state = hda_call_codec_suspend(codec, true); |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 4756 | if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) |
| 4757 | hda_call_pm_notify(codec, false); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | static void hda_keep_power_on(struct hda_codec *codec) |
| 4761 | { |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4762 | spin_lock(&codec->power_lock); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4763 | codec->power_count++; |
| 4764 | codec->power_on = 1; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 4765 | codec->power_jiffies = jiffies; |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4766 | spin_unlock(&codec->power_lock); |
Takashi Iwai | a40e0a8 | 2013-11-20 12:41:20 +0100 | [diff] [blame] | 4767 | hda_call_pm_notify(codec, true); |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4770 | /* update the power on/off account with the current jiffies */ |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 4771 | void snd_hda_update_power_acct(struct hda_codec *codec) |
| 4772 | { |
| 4773 | unsigned long delta = jiffies - codec->power_jiffies; |
| 4774 | if (codec->power_on) |
| 4775 | codec->power_on_acct += delta; |
| 4776 | else |
| 4777 | codec->power_off_acct += delta; |
| 4778 | codec->power_jiffies += delta; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4779 | } |
| 4780 | |
Dylan Reid | b4a91cf | 2012-06-15 19:36:23 -0700 | [diff] [blame] | 4781 | /* Transition to powered up, if wait_power_down then wait for a pending |
| 4782 | * transition to D3 to complete. A pending D3 transition is indicated |
| 4783 | * with power_transition == -1. */ |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4784 | /* call this with codec->power_lock held! */ |
Dylan Reid | b4a91cf | 2012-06-15 19:36:23 -0700 | [diff] [blame] | 4785 | static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4786 | { |
Dylan Reid | b4a91cf | 2012-06-15 19:36:23 -0700 | [diff] [blame] | 4787 | /* Return if power_on or transitioning to power_on, unless currently |
| 4788 | * powering down. */ |
| 4789 | if ((codec->power_on || codec->power_transition > 0) && |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4790 | !(wait_power_down && codec->power_transition < 0)) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4791 | return; |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 4792 | spin_unlock(&codec->power_lock); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4793 | |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 4794 | cancel_delayed_work_sync(&codec->power_work); |
| 4795 | |
| 4796 | spin_lock(&codec->power_lock); |
Dylan Reid | b43d224 | 2012-06-21 21:51:22 -0700 | [diff] [blame] | 4797 | /* If the power down delayed work was cancelled above before starting, |
| 4798 | * then there is no need to go through power up here. |
| 4799 | */ |
| 4800 | if (codec->power_on) { |
Takashi Iwai | 535b6c5 | 2012-08-20 21:25:22 +0200 | [diff] [blame] | 4801 | if (codec->power_transition < 0) |
| 4802 | codec->power_transition = 0; |
Dylan Reid | b43d224 | 2012-06-21 21:51:22 -0700 | [diff] [blame] | 4803 | return; |
| 4804 | } |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4805 | |
Takashi Iwai | d66fee5 | 2011-08-02 15:39:31 +0200 | [diff] [blame] | 4806 | trace_hda_power_up(codec); |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 4807 | snd_hda_update_power_acct(codec); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4808 | codec->power_on = 1; |
Takashi Iwai | a2f6309 | 2009-11-11 09:34:25 +0100 | [diff] [blame] | 4809 | codec->power_jiffies = jiffies; |
Takashi Iwai | 7f30830 | 2012-05-08 16:52:23 +0200 | [diff] [blame] | 4810 | codec->power_transition = 1; /* avoid reentrance */ |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4811 | spin_unlock(&codec->power_lock); |
| 4812 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4813 | hda_call_codec_resume(codec); |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4814 | |
| 4815 | spin_lock(&codec->power_lock); |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 4816 | codec->power_transition = 0; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4817 | } |
Dylan Reid | b4a91cf | 2012-06-15 19:36:23 -0700 | [diff] [blame] | 4818 | |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4819 | #define power_save(codec) \ |
| 4820 | ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4821 | |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4822 | /* Transition to powered down */ |
| 4823 | static void __snd_hda_power_down(struct hda_codec *codec) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4824 | { |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4825 | if (!codec->power_on || codec->power_count || codec->power_transition) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4826 | return; |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4827 | |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 4828 | if (power_save(codec)) { |
Takashi Iwai | a2d96e7 | 2012-05-09 12:36:22 +0200 | [diff] [blame] | 4829 | codec->power_transition = -1; /* avoid reentrance */ |
Takashi Iwai | c107b41 | 2009-01-13 17:46:37 +0100 | [diff] [blame] | 4830 | queue_delayed_work(codec->bus->workq, &codec->power_work, |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 4831 | msecs_to_jiffies(power_save(codec) * 1000)); |
Takashi Iwai | a221e28 | 2007-08-16 16:35:33 +0200 | [diff] [blame] | 4832 | } |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /** |
| 4836 | * snd_hda_power_save - Power-up/down/sync the codec |
| 4837 | * @codec: HD-audio codec |
| 4838 | * @delta: the counter delta to change |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4839 | * @d3wait: sync for D3 transition complete |
Takashi Iwai | c376e2c | 2012-08-14 17:12:47 +0200 | [diff] [blame] | 4840 | * |
| 4841 | * Change the power-up counter via @delta, and power up or down the hardware |
| 4842 | * appropriately. For the power-down, queue to the delayed action. |
| 4843 | * Passing zero to @delta means to synchronize the power state. |
| 4844 | */ |
| 4845 | void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait) |
| 4846 | { |
| 4847 | spin_lock(&codec->power_lock); |
| 4848 | codec->power_count += delta; |
| 4849 | trace_hda_power_count(codec); |
| 4850 | if (delta > 0) |
| 4851 | __snd_hda_power_up(codec, d3wait); |
| 4852 | else |
| 4853 | __snd_hda_power_down(codec); |
Takashi Iwai | 5536c6d | 2012-05-08 17:08:10 +0200 | [diff] [blame] | 4854 | spin_unlock(&codec->power_lock); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4855 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4856 | EXPORT_SYMBOL_GPL(snd_hda_power_save); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4857 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4858 | /** |
| 4859 | * snd_hda_check_amp_list_power - Check the amp list and update the power |
| 4860 | * @codec: HD-audio codec |
| 4861 | * @check: the object containing an AMP list and the status |
| 4862 | * @nid: NID to check / update |
| 4863 | * |
| 4864 | * Check whether the given NID is in the amp list. If it's in the list, |
| 4865 | * check the current AMP status, and update the the power-status according |
| 4866 | * to the mute status. |
| 4867 | * |
| 4868 | * This function is supposed to be set or called from the check_power_status |
| 4869 | * patch ops. |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 4870 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4871 | int snd_hda_check_amp_list_power(struct hda_codec *codec, |
| 4872 | struct hda_loopback_check *check, |
| 4873 | hda_nid_t nid) |
| 4874 | { |
Takashi Iwai | 031024e | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4875 | const struct hda_amp_list *p; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4876 | int ch, v; |
| 4877 | |
| 4878 | if (!check->amplist) |
| 4879 | return 0; |
| 4880 | for (p = check->amplist; p->nid; p++) { |
| 4881 | if (p->nid == nid) |
| 4882 | break; |
| 4883 | } |
| 4884 | if (!p->nid) |
| 4885 | return 0; /* nothing changed */ |
| 4886 | |
| 4887 | for (p = check->amplist; p->nid; p++) { |
| 4888 | for (ch = 0; ch < 2; ch++) { |
| 4889 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, |
| 4890 | p->idx); |
| 4891 | if (!(v & HDA_AMP_MUTE) && v > 0) { |
| 4892 | if (!check->power_on) { |
| 4893 | check->power_on = 1; |
| 4894 | snd_hda_power_up(codec); |
| 4895 | } |
| 4896 | return 1; |
| 4897 | } |
| 4898 | } |
| 4899 | } |
| 4900 | if (check->power_on) { |
| 4901 | check->power_on = 0; |
| 4902 | snd_hda_power_down(codec); |
| 4903 | } |
| 4904 | return 0; |
| 4905 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4906 | EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 4907 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 4909 | /* |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4910 | * Channel mode helper |
| 4911 | */ |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4912 | |
| 4913 | /** |
| 4914 | * snd_hda_ch_mode_info - Info callback helper for the channel mode enum |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4915 | * @codec: the HDA codec |
| 4916 | * @uinfo: pointer to get/store the data |
| 4917 | * @chmode: channel mode array |
| 4918 | * @num_chmodes: channel mode array size |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4919 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4920 | int snd_hda_ch_mode_info(struct hda_codec *codec, |
| 4921 | struct snd_ctl_elem_info *uinfo, |
| 4922 | const struct hda_channel_mode *chmode, |
| 4923 | int num_chmodes) |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4924 | { |
| 4925 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4926 | uinfo->count = 1; |
| 4927 | uinfo->value.enumerated.items = num_chmodes; |
| 4928 | if (uinfo->value.enumerated.item >= num_chmodes) |
| 4929 | uinfo->value.enumerated.item = num_chmodes - 1; |
| 4930 | sprintf(uinfo->value.enumerated.name, "%dch", |
| 4931 | chmode[uinfo->value.enumerated.item].channels); |
| 4932 | return 0; |
| 4933 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4934 | EXPORT_SYMBOL_GPL(snd_hda_ch_mode_info); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4935 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4936 | /** |
| 4937 | * snd_hda_ch_mode_get - Get callback helper for the channel mode enum |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4938 | * @codec: the HDA codec |
| 4939 | * @ucontrol: pointer to get/store the data |
| 4940 | * @chmode: channel mode array |
| 4941 | * @num_chmodes: channel mode array size |
| 4942 | * @max_channels: max number of channels |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4943 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4944 | int snd_hda_ch_mode_get(struct hda_codec *codec, |
| 4945 | struct snd_ctl_elem_value *ucontrol, |
| 4946 | const struct hda_channel_mode *chmode, |
| 4947 | int num_chmodes, |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4948 | int max_channels) |
| 4949 | { |
| 4950 | int i; |
| 4951 | |
| 4952 | for (i = 0; i < num_chmodes; i++) { |
| 4953 | if (max_channels == chmode[i].channels) { |
| 4954 | ucontrol->value.enumerated.item[0] = i; |
| 4955 | break; |
| 4956 | } |
| 4957 | } |
| 4958 | return 0; |
| 4959 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4960 | EXPORT_SYMBOL_GPL(snd_hda_ch_mode_get); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4961 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4962 | /** |
| 4963 | * snd_hda_ch_mode_put - Put callback helper for the channel mode enum |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4964 | * @codec: the HDA codec |
| 4965 | * @ucontrol: pointer to get/store the data |
| 4966 | * @chmode: channel mode array |
| 4967 | * @num_chmodes: channel mode array size |
| 4968 | * @max_channelsp: pointer to store the max channels |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4969 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 4970 | int snd_hda_ch_mode_put(struct hda_codec *codec, |
| 4971 | struct snd_ctl_elem_value *ucontrol, |
| 4972 | const struct hda_channel_mode *chmode, |
| 4973 | int num_chmodes, |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4974 | int *max_channelsp) |
| 4975 | { |
| 4976 | unsigned int mode; |
| 4977 | |
| 4978 | mode = ucontrol->value.enumerated.item[0]; |
Takashi Iwai | 68ea7b2 | 2007-11-15 15:54:38 +0100 | [diff] [blame] | 4979 | if (mode >= num_chmodes) |
| 4980 | return -EINVAL; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4981 | if (*max_channelsp == chmode[mode].channels) |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4982 | return 0; |
| 4983 | /* change the current channel setting */ |
| 4984 | *max_channelsp = chmode[mode].channels; |
| 4985 | if (chmode[mode].sequence) |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 4986 | snd_hda_sequence_write_cache(codec, chmode[mode].sequence); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4987 | return 1; |
| 4988 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 4989 | EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put); |
Takashi Iwai | d2a6d7d | 2005-11-17 11:06:29 +0100 | [diff] [blame] | 4990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4991 | /* |
| 4992 | * input MUX helper |
| 4993 | */ |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4994 | |
| 4995 | /** |
| 4996 | * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 4997 | * @imux: imux helper object |
| 4998 | * @uinfo: pointer to get/store the data |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 4999 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5000 | int snd_hda_input_mux_info(const struct hda_input_mux *imux, |
| 5001 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | { |
| 5003 | unsigned int index; |
| 5004 | |
| 5005 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 5006 | uinfo->count = 1; |
| 5007 | uinfo->value.enumerated.items = imux->num_items; |
Takashi Iwai | 5513b0c | 2007-10-09 11:58:41 +0200 | [diff] [blame] | 5008 | if (!imux->num_items) |
| 5009 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | index = uinfo->value.enumerated.item; |
| 5011 | if (index >= imux->num_items) |
| 5012 | index = imux->num_items - 1; |
| 5013 | strcpy(uinfo->value.enumerated.name, imux->items[index].label); |
| 5014 | return 0; |
| 5015 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5016 | EXPORT_SYMBOL_GPL(snd_hda_input_mux_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5018 | /** |
| 5019 | * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5020 | * @codec: the HDA codec |
| 5021 | * @imux: imux helper object |
| 5022 | * @ucontrol: pointer to get/store the data |
| 5023 | * @nid: input mux NID |
| 5024 | * @cur_val: pointer to get/store the current imux value |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5025 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5026 | int snd_hda_input_mux_put(struct hda_codec *codec, |
| 5027 | const struct hda_input_mux *imux, |
| 5028 | struct snd_ctl_elem_value *ucontrol, |
| 5029 | hda_nid_t nid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | unsigned int *cur_val) |
| 5031 | { |
| 5032 | unsigned int idx; |
| 5033 | |
Takashi Iwai | 5513b0c | 2007-10-09 11:58:41 +0200 | [diff] [blame] | 5034 | if (!imux->num_items) |
| 5035 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | idx = ucontrol->value.enumerated.item[0]; |
| 5037 | if (idx >= imux->num_items) |
| 5038 | idx = imux->num_items - 1; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 5039 | if (*cur_val == idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | return 0; |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 5041 | snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, |
| 5042 | imux->items[idx].index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | *cur_val = idx; |
| 5044 | return 1; |
| 5045 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5046 | EXPORT_SYMBOL_GPL(snd_hda_input_mux_put); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | |
| 5048 | |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5049 | /** |
| 5050 | * snd_hda_enum_helper_info - Helper for simple enum ctls |
| 5051 | * @kcontrol: ctl element |
| 5052 | * @uinfo: pointer to get/store the data |
| 5053 | * @num_items: number of enum items |
| 5054 | * @texts: enum item string array |
| 5055 | * |
Takashi Iwai | dda415d | 2012-11-30 18:34:38 +0100 | [diff] [blame] | 5056 | * process kcontrol info callback of a simple string enum array |
| 5057 | * when @num_items is 0 or @texts is NULL, assume a boolean enum array |
| 5058 | */ |
| 5059 | int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol, |
| 5060 | struct snd_ctl_elem_info *uinfo, |
| 5061 | int num_items, const char * const *texts) |
| 5062 | { |
| 5063 | static const char * const texts_default[] = { |
| 5064 | "Disabled", "Enabled" |
| 5065 | }; |
| 5066 | |
| 5067 | if (!texts || !num_items) { |
| 5068 | num_items = 2; |
| 5069 | texts = texts_default; |
| 5070 | } |
| 5071 | |
Takashi Iwai | 3ff7221 | 2014-10-20 18:17:28 +0200 | [diff] [blame] | 5072 | return snd_ctl_enum_info(uinfo, 1, num_items, texts); |
Takashi Iwai | dda415d | 2012-11-30 18:34:38 +0100 | [diff] [blame] | 5073 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5074 | EXPORT_SYMBOL_GPL(snd_hda_enum_helper_info); |
Takashi Iwai | dda415d | 2012-11-30 18:34:38 +0100 | [diff] [blame] | 5075 | |
| 5076 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | * Multi-channel / digital-out PCM helper functions |
| 5078 | */ |
| 5079 | |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5080 | /* setup SPDIF output stream */ |
| 5081 | static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, |
| 5082 | unsigned int stream_tag, unsigned int format) |
| 5083 | { |
Laurence Darby | 3bef1c3 | 2012-11-03 17:00:06 +0000 | [diff] [blame] | 5084 | struct hda_spdif_out *spdif; |
| 5085 | unsigned int curr_fmt; |
| 5086 | bool reset; |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 5087 | |
Laurence Darby | 3bef1c3 | 2012-11-03 17:00:06 +0000 | [diff] [blame] | 5088 | spdif = snd_hda_spdif_out_of_nid(codec, nid); |
| 5089 | curr_fmt = snd_hda_codec_read(codec, nid, 0, |
| 5090 | AC_VERB_GET_STREAM_FORMAT, 0); |
| 5091 | reset = codec->spdif_status_reset && |
| 5092 | (spdif->ctls & AC_DIG1_ENABLE) && |
| 5093 | curr_fmt != format; |
| 5094 | |
| 5095 | /* turn off SPDIF if needed; otherwise the IEC958 bits won't be |
| 5096 | updated */ |
| 5097 | if (reset) |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 5098 | set_dig_out_convert(codec, nid, |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 5099 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff, |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5100 | -1); |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5101 | snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5102 | if (codec->slave_dig_outs) { |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5103 | const hda_nid_t *d; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5104 | for (d = codec->slave_dig_outs; *d; d++) |
| 5105 | snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, |
| 5106 | format); |
Matthew Ranostay | de51ca1 | 2008-09-07 14:31:40 -0400 | [diff] [blame] | 5107 | } |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5108 | /* turn on again (if needed) */ |
Laurence Darby | 3bef1c3 | 2012-11-03 17:00:06 +0000 | [diff] [blame] | 5109 | if (reset) |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5110 | set_dig_out_convert(codec, nid, |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 5111 | spdif->ctls & 0xff, -1); |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5112 | } |
Matthew Ranostay | de51ca1 | 2008-09-07 14:31:40 -0400 | [diff] [blame] | 5113 | |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5114 | static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) |
| 5115 | { |
| 5116 | snd_hda_codec_cleanup_stream(codec, nid); |
| 5117 | if (codec->slave_dig_outs) { |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5118 | const hda_nid_t *d; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5119 | for (d = codec->slave_dig_outs; *d; d++) |
| 5120 | snd_hda_codec_cleanup_stream(codec, *d); |
| 5121 | } |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5122 | } |
| 5123 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5124 | /** |
| 5125 | * snd_hda_bus_reboot_notify - call the reboot notifier of each codec |
| 5126 | * @bus: HD-audio bus |
| 5127 | */ |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 5128 | void snd_hda_bus_reboot_notify(struct hda_bus *bus) |
| 5129 | { |
| 5130 | struct hda_codec *codec; |
| 5131 | |
| 5132 | if (!bus) |
| 5133 | return; |
| 5134 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | e581f3d | 2011-07-26 10:19:20 +0200 | [diff] [blame] | 5135 | if (hda_codec_is_power_on(codec) && |
| 5136 | codec->patch_ops.reboot_notify) |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 5137 | codec->patch_ops.reboot_notify(codec); |
| 5138 | } |
| 5139 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5140 | EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify); |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 5141 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5142 | /** |
| 5143 | * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5144 | * @codec: the HDA codec |
| 5145 | * @mout: hda_multi_out object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5147 | int snd_hda_multi_out_dig_open(struct hda_codec *codec, |
| 5148 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5150 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | 5930ca4 | 2007-04-16 11:23:56 +0200 | [diff] [blame] | 5151 | if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) |
| 5152 | /* already opened as analog dup; reset it once */ |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5153 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | mout->dig_out_used = HDA_DIG_EXCLUSIVE; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5155 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | return 0; |
| 5157 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5158 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5160 | /** |
| 5161 | * snd_hda_multi_out_dig_prepare - prepare the digital out stream |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5162 | * @codec: the HDA codec |
| 5163 | * @mout: hda_multi_out object |
| 5164 | * @stream_tag: stream tag to assign |
| 5165 | * @format: format id to assign |
| 5166 | * @substream: PCM substream to assign |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5167 | */ |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5168 | int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, |
| 5169 | struct hda_multi_out *mout, |
| 5170 | unsigned int stream_tag, |
| 5171 | unsigned int format, |
| 5172 | struct snd_pcm_substream *substream) |
| 5173 | { |
| 5174 | mutex_lock(&codec->spdif_mutex); |
| 5175 | setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); |
| 5176 | mutex_unlock(&codec->spdif_mutex); |
| 5177 | return 0; |
| 5178 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5179 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_prepare); |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5180 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5181 | /** |
| 5182 | * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5183 | * @codec: the HDA codec |
| 5184 | * @mout: hda_multi_out object |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5185 | */ |
Takashi Iwai | 9411e21 | 2009-02-13 11:32:28 +0100 | [diff] [blame] | 5186 | int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, |
| 5187 | struct hda_multi_out *mout) |
| 5188 | { |
| 5189 | mutex_lock(&codec->spdif_mutex); |
| 5190 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
| 5191 | mutex_unlock(&codec->spdif_mutex); |
| 5192 | return 0; |
| 5193 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5194 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_cleanup); |
Takashi Iwai | 9411e21 | 2009-02-13 11:32:28 +0100 | [diff] [blame] | 5195 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5196 | /** |
| 5197 | * snd_hda_multi_out_dig_close - release the digital out stream |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5198 | * @codec: the HDA codec |
| 5199 | * @mout: hda_multi_out object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5201 | int snd_hda_multi_out_dig_close(struct hda_codec *codec, |
| 5202 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5204 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | mout->dig_out_used = 0; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5206 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | return 0; |
| 5208 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5209 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5211 | /** |
| 5212 | * snd_hda_multi_out_analog_open - open analog outputs |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5213 | * @codec: the HDA codec |
| 5214 | * @mout: hda_multi_out object |
| 5215 | * @substream: PCM substream to assign |
| 5216 | * @hinfo: PCM information to assign |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5217 | * |
| 5218 | * Open analog outputs and set up the hw-constraints. |
| 5219 | * If the digital outputs can be opened as slave, open the digital |
| 5220 | * outputs, too. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5222 | int snd_hda_multi_out_analog_open(struct hda_codec *codec, |
| 5223 | struct hda_multi_out *mout, |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 5224 | struct snd_pcm_substream *substream, |
| 5225 | struct hda_pcm_stream *hinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | { |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 5227 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 5228 | runtime->hw.channels_max = mout->max_channels; |
| 5229 | if (mout->dig_out_nid) { |
| 5230 | if (!mout->analog_rates) { |
| 5231 | mout->analog_rates = hinfo->rates; |
| 5232 | mout->analog_formats = hinfo->formats; |
| 5233 | mout->analog_maxbps = hinfo->maxbps; |
| 5234 | } else { |
| 5235 | runtime->hw.rates = mout->analog_rates; |
| 5236 | runtime->hw.formats = mout->analog_formats; |
| 5237 | hinfo->maxbps = mout->analog_maxbps; |
| 5238 | } |
| 5239 | if (!mout->spdif_rates) { |
| 5240 | snd_hda_query_supported_pcm(codec, mout->dig_out_nid, |
| 5241 | &mout->spdif_rates, |
| 5242 | &mout->spdif_formats, |
| 5243 | &mout->spdif_maxbps); |
| 5244 | } |
| 5245 | mutex_lock(&codec->spdif_mutex); |
| 5246 | if (mout->share_spdif) { |
Takashi Iwai | 022b466 | 2009-07-03 23:03:30 +0200 | [diff] [blame] | 5247 | if ((runtime->hw.rates & mout->spdif_rates) && |
| 5248 | (runtime->hw.formats & mout->spdif_formats)) { |
| 5249 | runtime->hw.rates &= mout->spdif_rates; |
| 5250 | runtime->hw.formats &= mout->spdif_formats; |
| 5251 | if (mout->spdif_maxbps < hinfo->maxbps) |
| 5252 | hinfo->maxbps = mout->spdif_maxbps; |
| 5253 | } else { |
| 5254 | mout->share_spdif = 0; |
| 5255 | /* FIXME: need notify? */ |
| 5256 | } |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 5257 | } |
Frederik Deweerdt | eaa9985 | 2008-04-14 13:11:44 +0200 | [diff] [blame] | 5258 | mutex_unlock(&codec->spdif_mutex); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 5259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | return snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 5261 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
| 5262 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5263 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5265 | /** |
| 5266 | * snd_hda_multi_out_analog_prepare - Preapre the analog outputs. |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5267 | * @codec: the HDA codec |
| 5268 | * @mout: hda_multi_out object |
| 5269 | * @stream_tag: stream tag to assign |
| 5270 | * @format: format id to assign |
| 5271 | * @substream: PCM substream to assign |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5272 | * |
| 5273 | * Set up the i/o for analog out. |
| 5274 | * When the digital out is available, copy the front out to digital out, too. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5276 | int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, |
| 5277 | struct hda_multi_out *mout, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | unsigned int stream_tag, |
| 5279 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 5280 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | { |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5282 | const hda_nid_t *nids = mout->dac_nids; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | int chs = substream->runtime->channels; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 5284 | struct hda_spdif_out *spdif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | int i; |
| 5286 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5287 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 5288 | spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 5289 | if (mout->dig_out_nid && mout->share_spdif && |
| 5290 | mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | if (chs == 2 && |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5292 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 5293 | format) && |
Stephen Warren | 7c935976 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 5294 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 5296 | setup_dig_out_stream(codec, mout->dig_out_nid, |
| 5297 | stream_tag, format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | } else { |
| 5299 | mout->dig_out_used = 0; |
Takashi Iwai | 2f72853 | 2008-09-25 16:32:41 +0200 | [diff] [blame] | 5300 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | } |
| 5302 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5303 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | |
| 5305 | /* front */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5306 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 5307 | 0, format); |
Takashi Iwai | d29240c | 2007-10-26 12:35:56 +0200 | [diff] [blame] | 5308 | if (!mout->no_share_stream && |
| 5309 | mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | /* headphone out will just decode front left/right (stereo) */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5311 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 5312 | 0, format); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 5313 | /* extra outputs copied from front */ |
Takashi Iwai | a06dbfc | 2011-08-23 18:16:13 +0200 | [diff] [blame] | 5314 | for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++) |
| 5315 | if (!mout->no_share_stream && mout->hp_out_nid[i]) |
| 5316 | snd_hda_codec_setup_stream(codec, |
| 5317 | mout->hp_out_nid[i], |
| 5318 | stream_tag, 0, format); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 5319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | /* surrounds */ |
| 5321 | for (i = 1; i < mout->num_dacs; i++) { |
Takashi Iwai | 4b3acaf | 2005-06-10 19:48:10 +0200 | [diff] [blame] | 5322 | if (chs >= (i + 1) * 2) /* independent out */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5323 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 5324 | i * 2, format); |
Takashi Iwai | d29240c | 2007-10-26 12:35:56 +0200 | [diff] [blame] | 5325 | else if (!mout->no_share_stream) /* copy front */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5326 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 5327 | 0, format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | } |
David Henningsson | cd4035e | 2013-10-10 09:01:25 +0200 | [diff] [blame] | 5329 | |
| 5330 | /* extra surrounds */ |
| 5331 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) { |
| 5332 | int ch = 0; |
| 5333 | if (!mout->extra_out_nid[i]) |
| 5334 | break; |
| 5335 | if (chs >= (i + 1) * 2) |
| 5336 | ch = i * 2; |
| 5337 | else if (!mout->no_share_stream) |
| 5338 | break; |
| 5339 | snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], |
| 5340 | stream_tag, ch, format); |
| 5341 | } |
| 5342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5343 | return 0; |
| 5344 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5345 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_prepare); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5347 | /** |
| 5348 | * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5349 | * @codec: the HDA codec |
| 5350 | * @mout: hda_multi_out object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | */ |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5352 | int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, |
| 5353 | struct hda_multi_out *mout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | { |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5355 | const hda_nid_t *nids = mout->dac_nids; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | int i; |
| 5357 | |
| 5358 | for (i = 0; i < mout->num_dacs; i++) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 5359 | snd_hda_codec_cleanup_stream(codec, nids[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | if (mout->hp_nid) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 5361 | snd_hda_codec_cleanup_stream(codec, mout->hp_nid); |
Takashi Iwai | a06dbfc | 2011-08-23 18:16:13 +0200 | [diff] [blame] | 5362 | for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++) |
| 5363 | if (mout->hp_out_nid[i]) |
| 5364 | snd_hda_codec_cleanup_stream(codec, |
| 5365 | mout->hp_out_nid[i]); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 5366 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 5367 | if (mout->extra_out_nid[i]) |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 5368 | snd_hda_codec_cleanup_stream(codec, |
| 5369 | mout->extra_out_nid[i]); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5370 | mutex_lock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | 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] | 5372 | cleanup_dig_out_stream(codec, mout->dig_out_nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | mout->dig_out_used = 0; |
| 5374 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 5375 | mutex_unlock(&codec->spdif_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | return 0; |
| 5377 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5378 | EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 5380 | /** |
| 5381 | * snd_hda_get_default_vref - Get the default (mic) VREF pin bits |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5382 | * @codec: the HDA codec |
| 5383 | * @pin: referred pin NID |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 5384 | * |
| 5385 | * Guess the suitable VREF pin bits to be set as the pin-control value. |
| 5386 | * Note: the function doesn't set the AC_PINCTL_IN_EN bit. |
| 5387 | */ |
| 5388 | unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) |
| 5389 | { |
| 5390 | unsigned int pincap; |
| 5391 | unsigned int oldval; |
| 5392 | oldval = snd_hda_codec_read(codec, pin, 0, |
| 5393 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 5394 | pincap = snd_hda_query_pin_caps(codec, pin); |
| 5395 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
| 5396 | /* Exception: if the default pin setup is vref50, we give it priority */ |
| 5397 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
| 5398 | return AC_PINCTL_VREF_80; |
| 5399 | else if (pincap & AC_PINCAP_VREF_50) |
| 5400 | return AC_PINCTL_VREF_50; |
| 5401 | else if (pincap & AC_PINCAP_VREF_100) |
| 5402 | return AC_PINCTL_VREF_100; |
| 5403 | else if (pincap & AC_PINCAP_VREF_GRD) |
| 5404 | return AC_PINCTL_VREF_GRD; |
| 5405 | return AC_PINCTL_VREF_HIZ; |
| 5406 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5407 | EXPORT_SYMBOL_GPL(snd_hda_get_default_vref); |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 5408 | |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5409 | /** |
| 5410 | * snd_hda_correct_pin_ctl - correct the pin ctl value for matching with the pin cap |
| 5411 | * @codec: the HDA codec |
| 5412 | * @pin: referred pin NID |
| 5413 | * @val: pin ctl value to audit |
| 5414 | */ |
Takashi Iwai | 62f3a2f | 2013-01-10 08:56:46 +0100 | [diff] [blame] | 5415 | unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, |
| 5416 | hda_nid_t pin, unsigned int val) |
| 5417 | { |
| 5418 | static unsigned int cap_lists[][2] = { |
| 5419 | { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 }, |
| 5420 | { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 }, |
| 5421 | { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 }, |
| 5422 | { AC_PINCTL_VREF_GRD, AC_PINCAP_VREF_GRD }, |
| 5423 | }; |
| 5424 | unsigned int cap; |
| 5425 | |
| 5426 | if (!val) |
| 5427 | return 0; |
| 5428 | cap = snd_hda_query_pin_caps(codec, pin); |
| 5429 | if (!cap) |
| 5430 | return val; /* don't know what to do... */ |
| 5431 | |
| 5432 | if (val & AC_PINCTL_OUT_EN) { |
| 5433 | if (!(cap & AC_PINCAP_OUT)) |
| 5434 | val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); |
| 5435 | else if ((val & AC_PINCTL_HP_EN) && !(cap & AC_PINCAP_HP_DRV)) |
| 5436 | val &= ~AC_PINCTL_HP_EN; |
| 5437 | } |
| 5438 | |
| 5439 | if (val & AC_PINCTL_IN_EN) { |
| 5440 | if (!(cap & AC_PINCAP_IN)) |
| 5441 | val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN); |
| 5442 | else { |
| 5443 | unsigned int vcap, vref; |
| 5444 | int i; |
| 5445 | vcap = (cap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
| 5446 | vref = val & AC_PINCTL_VREFEN; |
| 5447 | for (i = 0; i < ARRAY_SIZE(cap_lists); i++) { |
| 5448 | if (vref == cap_lists[i][0] && |
| 5449 | !(vcap & cap_lists[i][1])) { |
| 5450 | if (i == ARRAY_SIZE(cap_lists) - 1) |
| 5451 | vref = AC_PINCTL_VREF_HIZ; |
| 5452 | else |
| 5453 | vref = cap_lists[i + 1][0]; |
| 5454 | } |
| 5455 | } |
| 5456 | val &= ~AC_PINCTL_VREFEN; |
| 5457 | val |= vref; |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | return val; |
| 5462 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5463 | EXPORT_SYMBOL_GPL(snd_hda_correct_pin_ctl); |
Takashi Iwai | 62f3a2f | 2013-01-10 08:56:46 +0100 | [diff] [blame] | 5464 | |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5465 | /** |
| 5466 | * _snd_hda_pin_ctl - Helper to set pin ctl value |
| 5467 | * @codec: the HDA codec |
| 5468 | * @pin: referred pin NID |
| 5469 | * @val: pin control value to set |
| 5470 | * @cached: access over codec pinctl cache or direct write |
| 5471 | * |
| 5472 | * This function is a helper to set a pin ctl value more safely. |
| 5473 | * It corrects the pin ctl value via snd_hda_correct_pin_ctl(), stores the |
| 5474 | * value in pin target array via snd_hda_codec_set_pin_target(), then |
| 5475 | * actually writes the value via either snd_hda_codec_update_cache() or |
| 5476 | * snd_hda_codec_write() depending on @cached flag. |
| 5477 | */ |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 5478 | int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, |
| 5479 | unsigned int val, bool cached) |
| 5480 | { |
Takashi Iwai | 62f3a2f | 2013-01-10 08:56:46 +0100 | [diff] [blame] | 5481 | val = snd_hda_correct_pin_ctl(codec, pin, val); |
Takashi Iwai | d7fdc00 | 2013-01-10 08:38:04 +0100 | [diff] [blame] | 5482 | snd_hda_codec_set_pin_target(codec, pin, val); |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 5483 | if (cached) |
| 5484 | return snd_hda_codec_update_cache(codec, pin, 0, |
| 5485 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 5486 | else |
| 5487 | return snd_hda_codec_write(codec, pin, 0, |
| 5488 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
| 5489 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5490 | EXPORT_SYMBOL_GPL(_snd_hda_set_pin_ctl); |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 5491 | |
Takashi Iwai | 990061c | 2010-09-09 22:08:44 +0200 | [diff] [blame] | 5492 | /** |
| 5493 | * snd_hda_add_imux_item - Add an item to input_mux |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 5494 | * @codec: the HDA codec |
| 5495 | * @imux: imux helper object |
| 5496 | * @label: the name of imux item to assign |
| 5497 | * @index: index number of imux item to assign |
| 5498 | * @type_idx: pointer to store the resultant label index |
Takashi Iwai | 990061c | 2010-09-09 22:08:44 +0200 | [diff] [blame] | 5499 | * |
| 5500 | * When the same label is used already in the existing items, the number |
| 5501 | * suffix is appended to the label. This label index number is stored |
| 5502 | * to type_idx when non-NULL pointer is given. |
| 5503 | */ |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 5504 | int snd_hda_add_imux_item(struct hda_codec *codec, |
| 5505 | struct hda_input_mux *imux, const char *label, |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5506 | int index, int *type_idx) |
| 5507 | { |
| 5508 | int i, label_idx = 0; |
| 5509 | if (imux->num_items >= HDA_MAX_NUM_INPUTS) { |
Takashi Iwai | 6194b99 | 2014-06-06 18:12:16 +0200 | [diff] [blame] | 5510 | codec_err(codec, "hda_codec: Too many imux items!\n"); |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5511 | return -EINVAL; |
| 5512 | } |
| 5513 | for (i = 0; i < imux->num_items; i++) { |
| 5514 | if (!strncmp(label, imux->items[i].label, strlen(label))) |
| 5515 | label_idx++; |
| 5516 | } |
| 5517 | if (type_idx) |
| 5518 | *type_idx = label_idx; |
| 5519 | if (label_idx > 0) |
| 5520 | snprintf(imux->items[imux->num_items].label, |
| 5521 | sizeof(imux->items[imux->num_items].label), |
| 5522 | "%s %d", label, label_idx); |
| 5523 | else |
| 5524 | strlcpy(imux->items[imux->num_items].label, label, |
| 5525 | sizeof(imux->items[imux->num_items].label)); |
| 5526 | imux->items[imux->num_items].index = index; |
| 5527 | imux->num_items++; |
| 5528 | return 0; |
| 5529 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5530 | EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); |
Takashi Iwai | d7b1ae9 | 2010-08-30 13:00:16 +0200 | [diff] [blame] | 5531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | /** |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5533 | * snd_hda_bus_reset - Reset the bus |
| 5534 | * @bus: HD-audio bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | */ |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5536 | void snd_hda_bus_reset(struct hda_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | { |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5538 | struct hda_codec *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | |
Takashi Iwai | 0ba2176 | 2007-04-16 11:29:14 +0200 | [diff] [blame] | 5540 | list_for_each_entry(codec, &bus->codec_list, list) { |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5541 | /* FIXME: maybe a better way needed for forced reset */ |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 5542 | cancel_delayed_work_sync(&codec->jackpoll_work); |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5543 | #ifdef CONFIG_PM |
Mengdong Lin | 0e24dbb | 2013-11-26 23:00:51 -0500 | [diff] [blame] | 5544 | if (hda_codec_is_power_on(codec)) { |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5545 | hda_call_codec_suspend(codec, false); |
Mengdong Lin | 12edb89 | 2013-11-26 23:32:23 -0500 | [diff] [blame] | 5546 | hda_call_codec_resume(codec); |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5547 | } |
| 5548 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5550 | } |
Takashi Iwai | 59ed1ea | 2015-02-18 15:39:59 +0100 | [diff] [blame^] | 5551 | EXPORT_SYMBOL_GPL(snd_hda_bus_reset); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5552 | |
| 5553 | /* |
| 5554 | * generic arrays |
| 5555 | */ |
| 5556 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5557 | /** |
| 5558 | * snd_array_new - get a new element from the given array |
| 5559 | * @array: the array object |
Norberto Lopes | 28aedaf | 2010-02-28 20:16:53 +0100 | [diff] [blame] | 5560 | * |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5561 | * Get a new element from the given array. If it exceeds the |
| 5562 | * pre-allocated array size, re-allocate the array. |
| 5563 | * |
| 5564 | * Returns NULL if allocation failed. |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5565 | */ |
| 5566 | void *snd_array_new(struct snd_array *array) |
| 5567 | { |
Takashi Iwai | 12f1771 | 2012-10-10 08:59:14 +0200 | [diff] [blame] | 5568 | if (snd_BUG_ON(!array->elem_size)) |
| 5569 | return NULL; |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5570 | if (array->used >= array->alloced) { |
| 5571 | int num = array->alloced + array->alloc_align; |
Takashi Iwai | 3101ba0 | 2011-07-12 08:05:16 +0200 | [diff] [blame] | 5572 | int size = (num + 1) * array->elem_size; |
Takashi Iwai | b910d9a | 2008-11-07 00:26:52 +0100 | [diff] [blame] | 5573 | void *nlist; |
| 5574 | if (snd_BUG_ON(num >= 4096)) |
| 5575 | return NULL; |
Takashi Iwai | 5265fd9 | 2013-03-13 12:15:28 +0100 | [diff] [blame] | 5576 | nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5577 | if (!nlist) |
| 5578 | return NULL; |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5579 | array->list = nlist; |
| 5580 | array->alloced = num; |
| 5581 | } |
Takashi Iwai | f43aa02 | 2008-11-10 16:24:26 +0100 | [diff] [blame] | 5582 | return snd_array_elem(array, array->used++); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5583 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5584 | EXPORT_SYMBOL_GPL(snd_array_new); |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5585 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5586 | /** |
| 5587 | * snd_array_free - free the given array elements |
| 5588 | * @array: the array object |
| 5589 | */ |
Takashi Iwai | b2e1859 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 5590 | void snd_array_free(struct snd_array *array) |
| 5591 | { |
| 5592 | kfree(array->list); |
| 5593 | array->used = 0; |
| 5594 | array->alloced = 0; |
| 5595 | array->list = NULL; |
| 5596 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5597 | EXPORT_SYMBOL_GPL(snd_array_free); |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 5598 | |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5599 | /** |
Takashi Iwai | d5191e5 | 2009-11-16 14:58:17 +0100 | [diff] [blame] | 5600 | * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer |
| 5601 | * @pcm: PCM caps bits |
| 5602 | * @buf: the string buffer to write |
| 5603 | * @buflen: the max buffer length |
| 5604 | * |
| 5605 | * used by hda_proc.c and hda_eld.c |
| 5606 | */ |
Takashi Iwai | b202226 | 2008-11-21 21:24:03 +0100 | [diff] [blame] | 5607 | void snd_print_pcm_bits(int pcm, char *buf, int buflen) |
| 5608 | { |
| 5609 | static unsigned int bits[] = { 8, 16, 20, 24, 32 }; |
| 5610 | int i, j; |
| 5611 | |
| 5612 | for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++) |
| 5613 | if (pcm & (AC_SUPPCM_BITS_8 << i)) |
| 5614 | j += snprintf(buf + j, buflen - j, " %d", bits[i]); |
| 5615 | |
| 5616 | buf[j] = '\0'; /* necessary when j == 0 */ |
| 5617 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 5618 | EXPORT_SYMBOL_GPL(snd_print_pcm_bits); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 5619 | |
| 5620 | MODULE_DESCRIPTION("HDA codec core"); |
| 5621 | MODULE_LICENSE("GPL"); |