2 * Universal Interface for Intel High Definition Audio Codec
4 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
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.
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.
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
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/mutex.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include <sound/asoundef.h>
30 #include <sound/tlv.h>
31 #include <sound/initval.h>
32 #include "hda_local.h"
33 #include <sound/hda_hwdep.h>
34 #include "hda_patch.h" /* codec presets */
36 #ifdef CONFIG_SND_HDA_POWER_SAVE
37 /* define this option here to hide as static */
38 static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
39 module_param(power_save, int, 0644);
40 MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
41 "(in second, 0 = disable).");
45 * vendor / preset table
48 struct hda_vendor_id {
53 /* codec vendor labels */
54 static struct hda_vendor_id hda_vendor_ids[] = {
56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10ec, "Realtek" },
62 { 0x11d4, "Analog Devices" },
63 { 0x13f6, "C-Media" },
64 { 0x14f1, "Conexant" },
65 { 0x17e8, "Chrontel" },
67 { 0x434d, "C-Media" },
68 { 0x8384, "SigmaTel" },
72 static const struct hda_codec_preset *hda_preset_tables[] = {
73 #ifdef CONFIG_SND_HDA_CODEC_REALTEK
74 snd_hda_preset_realtek,
76 #ifdef CONFIG_SND_HDA_CODEC_CMEDIA
77 snd_hda_preset_cmedia,
79 #ifdef CONFIG_SND_HDA_CODEC_ANALOG
80 snd_hda_preset_analog,
82 #ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
83 snd_hda_preset_sigmatel,
85 #ifdef CONFIG_SND_HDA_CODEC_SI3054
86 snd_hda_preset_si3054,
88 #ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
89 snd_hda_preset_atihdmi,
91 #ifdef CONFIG_SND_HDA_CODEC_CONEXANT
92 snd_hda_preset_conexant,
94 #ifdef CONFIG_SND_HDA_CODEC_VIA
97 #ifdef CONFIG_SND_HDA_CODEC_NVHDMI
98 snd_hda_preset_nvhdmi,
103 #ifdef CONFIG_SND_HDA_POWER_SAVE
104 static void hda_power_work(struct work_struct *work);
105 static void hda_keep_power_on(struct hda_codec *codec);
107 static inline void hda_keep_power_on(struct hda_codec *codec) {}
111 * snd_hda_codec_read - send a command and get the response
112 * @codec: the HDA codec
113 * @nid: NID to send the command
114 * @direct: direct flag
115 * @verb: the verb to send
116 * @parm: the parameter for the verb
118 * Send a single command and read the corresponding response.
120 * Returns the obtained response value, or -1 for an error.
122 unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
124 unsigned int verb, unsigned int parm)
127 snd_hda_power_up(codec);
128 mutex_lock(&codec->bus->cmd_mutex);
129 if (!codec->bus->ops.command(codec, nid, direct, verb, parm))
130 res = codec->bus->ops.get_response(codec);
132 res = (unsigned int)-1;
133 mutex_unlock(&codec->bus->cmd_mutex);
134 snd_hda_power_down(codec);
139 * snd_hda_codec_write - send a single command without waiting for response
140 * @codec: the HDA codec
141 * @nid: NID to send the command
142 * @direct: direct flag
143 * @verb: the verb to send
144 * @parm: the parameter for the verb
146 * Send a single command without waiting for response.
148 * Returns 0 if successful, or a negative error code.
150 int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
151 unsigned int verb, unsigned int parm)
154 snd_hda_power_up(codec);
155 mutex_lock(&codec->bus->cmd_mutex);
156 err = codec->bus->ops.command(codec, nid, direct, verb, parm);
157 mutex_unlock(&codec->bus->cmd_mutex);
158 snd_hda_power_down(codec);
163 * snd_hda_sequence_write - sequence writes
164 * @codec: the HDA codec
165 * @seq: VERB array to send
167 * Send the commands sequentially from the given array.
168 * The array must be terminated with NID=0.
170 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
172 for (; seq->nid; seq++)
173 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
177 * snd_hda_get_sub_nodes - get the range of sub nodes
178 * @codec: the HDA codec
180 * @start_id: the pointer to store the start NID
182 * Parse the NID and store the start NID of its sub-nodes.
183 * Returns the number of sub-nodes.
185 int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
190 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
193 *start_id = (parm >> 16) & 0x7fff;
194 return (int)(parm & 0x7fff);
198 * snd_hda_get_connections - get connection list
199 * @codec: the HDA codec
201 * @conn_list: connection list array
202 * @max_conns: max. number of connections to store
204 * Parses the connection list of the given widget and stores the list
207 * Returns the number of connections, or a negative error code.
209 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
210 hda_nid_t *conn_list, int max_conns)
213 int i, conn_len, conns;
214 unsigned int shift, num_elems, mask;
217 if (snd_BUG_ON(!conn_list || max_conns <= 0))
220 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
221 if (parm & AC_CLIST_LONG) {
230 conn_len = parm & AC_CLIST_LENGTH;
231 mask = (1 << (shift-1)) - 1;
234 return 0; /* no connection */
237 /* single connection */
238 parm = snd_hda_codec_read(codec, nid, 0,
239 AC_VERB_GET_CONNECT_LIST, 0);
240 conn_list[0] = parm & mask;
244 /* multi connection */
247 for (i = 0; i < conn_len; i++) {
251 if (i % num_elems == 0)
252 parm = snd_hda_codec_read(codec, nid, 0,
253 AC_VERB_GET_CONNECT_LIST, i);
254 range_val = !!(parm & (1 << (shift-1))); /* ranges */
258 /* ranges between the previous and this one */
259 if (!prev_nid || prev_nid >= val) {
260 snd_printk(KERN_WARNING "hda_codec: "
261 "invalid dep_range_val %x:%x\n",
265 for (n = prev_nid + 1; n <= val; n++) {
266 if (conns >= max_conns) {
268 "Too many connections\n");
271 conn_list[conns++] = n;
274 if (conns >= max_conns) {
275 snd_printk(KERN_ERR "Too many connections\n");
278 conn_list[conns++] = val;
287 * snd_hda_queue_unsol_event - add an unsolicited event to queue
289 * @res: unsolicited event (lower 32bit of RIRB entry)
290 * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
292 * Adds the given event to the queue. The events are processed in
293 * the workqueue asynchronously. Call this function in the interrupt
294 * hanlder when RIRB receives an unsolicited event.
296 * Returns 0 if successful, or a negative error code.
298 int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
300 struct hda_bus_unsolicited *unsol;
307 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
311 unsol->queue[wp] = res;
312 unsol->queue[wp + 1] = res_ex;
314 schedule_work(&unsol->work);
320 * process queued unsolicited events
322 static void process_unsol_events(struct work_struct *work)
324 struct hda_bus_unsolicited *unsol =
325 container_of(work, struct hda_bus_unsolicited, work);
326 struct hda_bus *bus = unsol->bus;
327 struct hda_codec *codec;
328 unsigned int rp, caddr, res;
330 while (unsol->rp != unsol->wp) {
331 rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE;
334 res = unsol->queue[rp];
335 caddr = unsol->queue[rp + 1];
336 if (!(caddr & (1 << 4))) /* no unsolicited event? */
338 codec = bus->caddr_tbl[caddr & 0x0f];
339 if (codec && codec->patch_ops.unsol_event)
340 codec->patch_ops.unsol_event(codec, res);
345 * initialize unsolicited queue
347 static int __devinit init_unsol_queue(struct hda_bus *bus)
349 struct hda_bus_unsolicited *unsol;
351 if (bus->unsol) /* already initialized */
354 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
356 snd_printk(KERN_ERR "hda_codec: "
357 "can't allocate unsolicited queue\n");
360 INIT_WORK(&unsol->work, process_unsol_events);
369 static void snd_hda_codec_free(struct hda_codec *codec);
371 static int snd_hda_bus_free(struct hda_bus *bus)
373 struct hda_codec *codec, *n;
378 flush_scheduled_work();
381 list_for_each_entry_safe(codec, n, &bus->codec_list, list) {
382 snd_hda_codec_free(codec);
384 if (bus->ops.private_free)
385 bus->ops.private_free(bus);
390 static int snd_hda_bus_dev_free(struct snd_device *device)
392 struct hda_bus *bus = device->device_data;
393 return snd_hda_bus_free(bus);
397 * snd_hda_bus_new - create a HDA bus
398 * @card: the card entry
399 * @temp: the template for hda_bus information
400 * @busp: the pointer to store the created bus instance
402 * Returns 0 if successful, or a negative error code.
404 int __devinit snd_hda_bus_new(struct snd_card *card,
405 const struct hda_bus_template *temp,
406 struct hda_bus **busp)
410 static struct snd_device_ops dev_ops = {
411 .dev_free = snd_hda_bus_dev_free,
414 if (snd_BUG_ON(!temp))
416 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
422 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
424 snd_printk(KERN_ERR "can't allocate struct hda_bus\n");
429 bus->private_data = temp->private_data;
430 bus->pci = temp->pci;
431 bus->modelname = temp->modelname;
432 bus->ops = temp->ops;
434 mutex_init(&bus->cmd_mutex);
435 INIT_LIST_HEAD(&bus->codec_list);
437 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
439 snd_hda_bus_free(bus);
447 #ifdef CONFIG_SND_HDA_GENERIC
448 #define is_generic_config(codec) \
449 (codec->bus->modelname && !strcmp(codec->bus->modelname, "generic"))
451 #define is_generic_config(codec) 0
455 * find a matching codec preset
457 static const struct hda_codec_preset __devinit *
458 find_codec_preset(struct hda_codec *codec)
460 const struct hda_codec_preset **tbl, *preset;
462 if (is_generic_config(codec))
463 return NULL; /* use the generic parser */
465 for (tbl = hda_preset_tables; *tbl; tbl++) {
466 for (preset = *tbl; preset->id; preset++) {
467 u32 mask = preset->mask;
468 if (preset->afg && preset->afg != codec->afg)
470 if (preset->mfg && preset->mfg != codec->mfg)
474 if (preset->id == (codec->vendor_id & mask) &&
476 preset->rev == codec->revision_id))
484 * snd_hda_get_codec_name - store the codec name
486 void snd_hda_get_codec_name(struct hda_codec *codec,
487 char *name, int namelen)
489 const struct hda_vendor_id *c;
490 const char *vendor = NULL;
491 u16 vendor_id = codec->vendor_id >> 16;
494 for (c = hda_vendor_ids; c->id; c++) {
495 if (c->id == vendor_id) {
501 sprintf(tmp, "Generic %04x", vendor_id);
504 if (codec->preset && codec->preset->name)
505 snprintf(name, namelen, "%s %s", vendor, codec->preset->name);
507 snprintf(name, namelen, "%s ID %x", vendor,
508 codec->vendor_id & 0xffff);
512 * look for an AFG and MFG nodes
514 static void __devinit setup_fg_nodes(struct hda_codec *codec)
519 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
520 for (i = 0; i < total_nodes; i++, nid++) {
522 func = snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE);
523 switch (func & 0xff) {
524 case AC_GRP_AUDIO_FUNCTION:
527 case AC_GRP_MODEM_FUNCTION:
537 * read widget caps for each widget and store in cache
539 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
544 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node,
546 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
549 nid = codec->start_nid;
550 for (i = 0; i < codec->num_nodes; i++, nid++)
551 codec->wcaps[i] = snd_hda_param_read(codec, nid,
552 AC_PAR_AUDIO_WIDGET_CAP);
557 static void init_hda_cache(struct hda_cache_rec *cache,
558 unsigned int record_size);
559 static void free_hda_cache(struct hda_cache_rec *cache);
564 static void snd_hda_codec_free(struct hda_codec *codec)
568 #ifdef CONFIG_SND_HDA_POWER_SAVE
569 cancel_delayed_work(&codec->power_work);
570 flush_scheduled_work();
572 list_del(&codec->list);
573 codec->bus->caddr_tbl[codec->addr] = NULL;
574 if (codec->patch_ops.free)
575 codec->patch_ops.free(codec);
576 free_hda_cache(&codec->amp_cache);
577 free_hda_cache(&codec->cmd_cache);
583 * snd_hda_codec_new - create a HDA codec
584 * @bus: the bus to assign
585 * @codec_addr: the codec address
586 * @codecp: the pointer to store the generated codec
588 * Returns 0 if successful, or a negative error code.
590 int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
591 struct hda_codec **codecp)
593 struct hda_codec *codec;
597 if (snd_BUG_ON(!bus))
599 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
602 if (bus->caddr_tbl[codec_addr]) {
603 snd_printk(KERN_ERR "hda_codec: "
604 "address 0x%x is already occupied\n", codec_addr);
608 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
610 snd_printk(KERN_ERR "can't allocate struct hda_codec\n");
615 codec->addr = codec_addr;
616 mutex_init(&codec->spdif_mutex);
617 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
618 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
620 #ifdef CONFIG_SND_HDA_POWER_SAVE
621 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
622 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
623 * the caller has to power down appropriatley after initialization
626 hda_keep_power_on(codec);
629 list_add_tail(&codec->list, &bus->codec_list);
630 bus->caddr_tbl[codec_addr] = codec;
632 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
634 if (codec->vendor_id == -1)
635 /* read again, hopefully the access method was corrected
636 * in the last read...
638 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
640 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
641 AC_PAR_SUBSYSTEM_ID);
642 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
645 setup_fg_nodes(codec);
646 if (!codec->afg && !codec->mfg) {
647 snd_printdd("hda_codec: no AFG or MFG node found\n");
648 snd_hda_codec_free(codec);
652 if (read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg) < 0) {
653 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
654 snd_hda_codec_free(codec);
658 if (!codec->subsystem_id) {
659 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
660 codec->subsystem_id =
661 snd_hda_codec_read(codec, nid, 0,
662 AC_VERB_GET_SUBSYSTEM_ID, 0);
665 codec->preset = find_codec_preset(codec);
666 /* audio codec should override the mixer name */
667 if (codec->afg || !*bus->card->mixername)
668 snd_hda_get_codec_name(codec, bus->card->mixername,
669 sizeof(bus->card->mixername));
671 if (is_generic_config(codec)) {
672 err = snd_hda_parse_generic_codec(codec);
675 if (codec->preset && codec->preset->patch) {
676 err = codec->preset->patch(codec);
680 /* call the default parser */
681 err = snd_hda_parse_generic_codec(codec);
683 printk(KERN_ERR "hda-codec: No codec parser is available\n");
687 snd_hda_codec_free(codec);
691 if (codec->patch_ops.unsol_event)
692 init_unsol_queue(bus);
694 snd_hda_codec_proc_new(codec);
695 #ifdef CONFIG_SND_HDA_HWDEP
696 snd_hda_create_hwdep(codec);
699 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id);
700 snd_component_add(codec->bus->card, component);
708 * snd_hda_codec_setup_stream - set up the codec for streaming
709 * @codec: the CODEC to set up
710 * @nid: the NID to set up
711 * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
712 * @channel_id: channel id to pass, zero based.
713 * @format: stream format.
715 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
717 int channel_id, int format)
722 snd_printdd("hda_codec_setup_stream: "
723 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
724 nid, stream_tag, channel_id, format);
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
726 (stream_tag << 4) | channel_id);
728 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
731 void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
736 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
737 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
738 #if 0 /* keep the format */
740 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
745 * amp access functions
748 /* FIXME: more better hash key? */
749 #define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
750 #define INFO_AMP_CAPS (1<<0)
751 #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
753 /* initialize the hash table */
754 static void __devinit init_hda_cache(struct hda_cache_rec *cache,
755 unsigned int record_size)
757 memset(cache, 0, sizeof(*cache));
758 memset(cache->hash, 0xff, sizeof(cache->hash));
759 cache->record_size = record_size;
762 static void free_hda_cache(struct hda_cache_rec *cache)
764 kfree(cache->buffer);
767 /* query the hash. allocate an entry if not found. */
768 static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
771 u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
772 u16 cur = cache->hash[idx];
773 struct hda_cache_head *info;
775 while (cur != 0xffff) {
776 info = (struct hda_cache_head *)(cache->buffer +
777 cur * cache->record_size);
778 if (info->key == key)
783 /* add a new hash entry */
784 if (cache->num_entries >= cache->size) {
785 /* reallocate the array */
786 unsigned int new_size = cache->size + 64;
788 new_buffer = kcalloc(new_size, cache->record_size, GFP_KERNEL);
790 snd_printk(KERN_ERR "hda_codec: "
791 "can't malloc amp_info\n");
795 memcpy(new_buffer, cache->buffer,
796 cache->size * cache->record_size);
797 kfree(cache->buffer);
799 cache->size = new_size;
800 cache->buffer = new_buffer;
802 cur = cache->num_entries++;
803 info = (struct hda_cache_head *)(cache->buffer +
804 cur * cache->record_size);
807 info->next = cache->hash[idx];
808 cache->hash[idx] = cur;
813 /* query and allocate an amp hash entry */
814 static inline struct hda_amp_info *
815 get_alloc_amp_hash(struct hda_codec *codec, u32 key)
817 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
821 * query AMP capabilities for the given widget and direction
823 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
825 struct hda_amp_info *info;
827 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
830 if (!(info->head.val & INFO_AMP_CAPS)) {
831 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
833 info->amp_caps = snd_hda_param_read(codec, nid,
834 direction == HDA_OUTPUT ?
838 info->head.val |= INFO_AMP_CAPS;
840 return info->amp_caps;
843 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
846 struct hda_amp_info *info;
848 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0));
851 info->amp_caps = caps;
852 info->head.val |= INFO_AMP_CAPS;
857 * read the current volume to info
858 * if the cache exists, read the cache value.
860 static unsigned int get_vol_mute(struct hda_codec *codec,
861 struct hda_amp_info *info, hda_nid_t nid,
862 int ch, int direction, int index)
866 if (info->head.val & INFO_AMP_VOL(ch))
867 return info->vol[ch];
869 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
870 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
872 val = snd_hda_codec_read(codec, nid, 0,
873 AC_VERB_GET_AMP_GAIN_MUTE, parm);
874 info->vol[ch] = val & 0xff;
875 info->head.val |= INFO_AMP_VOL(ch);
876 return info->vol[ch];
880 * write the current volume in info to the h/w and update the cache
882 static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
883 hda_nid_t nid, int ch, int direction, int index,
888 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
889 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
890 parm |= index << AC_AMP_SET_INDEX_SHIFT;
892 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
897 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
899 int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
900 int direction, int index)
902 struct hda_amp_info *info;
903 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
906 return get_vol_mute(codec, info, nid, ch, direction, index);
910 * update the AMP value, mask = bit mask to set, val = the value
912 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
913 int direction, int idx, int mask, int val)
915 struct hda_amp_info *info;
917 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
921 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
922 if (info->vol[ch] == val)
924 put_vol_mute(codec, info, nid, ch, direction, idx, val);
929 * update the AMP stereo with the same mask and value
931 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
932 int direction, int idx, int mask, int val)
935 for (ch = 0; ch < 2; ch++)
936 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
941 #ifdef SND_HDA_NEEDS_RESUME
942 /* resume the all amp commands from the cache */
943 void snd_hda_codec_resume_amp(struct hda_codec *codec)
945 struct hda_amp_info *buffer = codec->amp_cache.buffer;
948 for (i = 0; i < codec->amp_cache.size; i++, buffer++) {
949 u32 key = buffer->head.key;
951 unsigned int idx, dir, ch;
955 idx = (key >> 16) & 0xff;
956 dir = (key >> 24) & 0xff;
957 for (ch = 0; ch < 2; ch++) {
958 if (!(buffer->head.val & INFO_AMP_VOL(ch)))
960 put_vol_mute(codec, buffer, nid, ch, dir, idx,
965 #endif /* SND_HDA_NEEDS_RESUME */
968 int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
969 struct snd_ctl_elem_info *uinfo)
971 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
972 u16 nid = get_amp_nid(kcontrol);
973 u8 chs = get_amp_channels(kcontrol);
974 int dir = get_amp_direction(kcontrol);
977 caps = query_amp_caps(codec, nid, dir);
979 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
981 printk(KERN_WARNING "hda_codec: "
982 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid,
986 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
987 uinfo->count = chs == 3 ? 2 : 1;
988 uinfo->value.integer.min = 0;
989 uinfo->value.integer.max = caps;
993 int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
994 struct snd_ctl_elem_value *ucontrol)
996 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
997 hda_nid_t nid = get_amp_nid(kcontrol);
998 int chs = get_amp_channels(kcontrol);
999 int dir = get_amp_direction(kcontrol);
1000 int idx = get_amp_index(kcontrol);
1001 long *valp = ucontrol->value.integer.value;
1004 *valp++ = snd_hda_codec_amp_read(codec, nid, 0, dir, idx)
1007 *valp = snd_hda_codec_amp_read(codec, nid, 1, dir, idx)
1012 int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1013 struct snd_ctl_elem_value *ucontrol)
1015 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1016 hda_nid_t nid = get_amp_nid(kcontrol);
1017 int chs = get_amp_channels(kcontrol);
1018 int dir = get_amp_direction(kcontrol);
1019 int idx = get_amp_index(kcontrol);
1020 long *valp = ucontrol->value.integer.value;
1023 snd_hda_power_up(codec);
1025 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
1030 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
1032 snd_hda_power_down(codec);
1036 int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1037 unsigned int size, unsigned int __user *_tlv)
1039 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1040 hda_nid_t nid = get_amp_nid(kcontrol);
1041 int dir = get_amp_direction(kcontrol);
1042 u32 caps, val1, val2;
1044 if (size < 4 * sizeof(unsigned int))
1046 caps = query_amp_caps(codec, nid, dir);
1047 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1048 val2 = (val2 + 1) * 25;
1049 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1050 val1 = ((int)val1) * ((int)val2);
1051 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
1053 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
1055 if (put_user(val1, _tlv + 2))
1057 if (put_user(val2, _tlv + 3))
1063 * set (static) TLV for virtual master volume; recalculated as max 0dB
1065 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1071 caps = query_amp_caps(codec, nid, dir);
1072 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1073 step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1074 step = (step + 1) * 25;
1075 tlv[0] = SNDRV_CTL_TLVT_DB_SCALE;
1076 tlv[1] = 2 * sizeof(unsigned int);
1077 tlv[2] = -nums * step;
1081 /* find a mixer control element with the given name */
1082 static struct snd_kcontrol *
1083 _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1084 const char *name, int idx)
1086 struct snd_ctl_elem_id id;
1087 memset(&id, 0, sizeof(id));
1088 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1090 strcpy(id.name, name);
1091 return snd_ctl_find_id(codec->bus->card, &id);
1094 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1097 return _snd_hda_find_mixer_ctl(codec, name, 0);
1100 /* create a virtual master control and add slaves */
1101 int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1102 unsigned int *tlv, const char **slaves)
1104 struct snd_kcontrol *kctl;
1108 for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++)
1111 snd_printdd("No slave found for %s\n", name);
1114 kctl = snd_ctl_make_virtual_master(name, tlv);
1117 err = snd_ctl_add(codec->bus->card, kctl);
1121 for (s = slaves; *s; s++) {
1122 struct snd_kcontrol *sctl;
1124 sctl = snd_hda_find_mixer_ctl(codec, *s);
1126 snd_printdd("Cannot find slave %s, skipped\n", *s);
1129 err = snd_ctl_add_slave(kctl, sctl);
1137 int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1138 struct snd_ctl_elem_info *uinfo)
1140 int chs = get_amp_channels(kcontrol);
1142 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1143 uinfo->count = chs == 3 ? 2 : 1;
1144 uinfo->value.integer.min = 0;
1145 uinfo->value.integer.max = 1;
1149 int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1150 struct snd_ctl_elem_value *ucontrol)
1152 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1153 hda_nid_t nid = get_amp_nid(kcontrol);
1154 int chs = get_amp_channels(kcontrol);
1155 int dir = get_amp_direction(kcontrol);
1156 int idx = get_amp_index(kcontrol);
1157 long *valp = ucontrol->value.integer.value;
1160 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
1161 HDA_AMP_MUTE) ? 0 : 1;
1163 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
1164 HDA_AMP_MUTE) ? 0 : 1;
1168 int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1169 struct snd_ctl_elem_value *ucontrol)
1171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1172 hda_nid_t nid = get_amp_nid(kcontrol);
1173 int chs = get_amp_channels(kcontrol);
1174 int dir = get_amp_direction(kcontrol);
1175 int idx = get_amp_index(kcontrol);
1176 long *valp = ucontrol->value.integer.value;
1179 snd_hda_power_up(codec);
1181 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
1183 *valp ? 0 : HDA_AMP_MUTE);
1187 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
1189 *valp ? 0 : HDA_AMP_MUTE);
1190 #ifdef CONFIG_SND_HDA_POWER_SAVE
1191 if (codec->patch_ops.check_power_status)
1192 codec->patch_ops.check_power_status(codec, nid);
1194 snd_hda_power_down(codec);
1199 * bound volume controls
1201 * bind multiple volumes (# indices, from 0)
1204 #define AMP_VAL_IDX_SHIFT 19
1205 #define AMP_VAL_IDX_MASK (0x0f<<19)
1207 int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1208 struct snd_ctl_elem_value *ucontrol)
1210 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1214 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1215 pval = kcontrol->private_value;
1216 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
1217 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
1218 kcontrol->private_value = pval;
1219 mutex_unlock(&codec->spdif_mutex);
1223 int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1224 struct snd_ctl_elem_value *ucontrol)
1226 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1228 int i, indices, err = 0, change = 0;
1230 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1231 pval = kcontrol->private_value;
1232 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
1233 for (i = 0; i < indices; i++) {
1234 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
1235 (i << AMP_VAL_IDX_SHIFT);
1236 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
1241 kcontrol->private_value = pval;
1242 mutex_unlock(&codec->spdif_mutex);
1243 return err < 0 ? err : change;
1247 * generic bound volume/swtich controls
1249 int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1250 struct snd_ctl_elem_info *uinfo)
1252 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1253 struct hda_bind_ctls *c;
1256 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1257 c = (struct hda_bind_ctls *)kcontrol->private_value;
1258 kcontrol->private_value = *c->values;
1259 err = c->ops->info(kcontrol, uinfo);
1260 kcontrol->private_value = (long)c;
1261 mutex_unlock(&codec->spdif_mutex);
1265 int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1266 struct snd_ctl_elem_value *ucontrol)
1268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1269 struct hda_bind_ctls *c;
1272 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1273 c = (struct hda_bind_ctls *)kcontrol->private_value;
1274 kcontrol->private_value = *c->values;
1275 err = c->ops->get(kcontrol, ucontrol);
1276 kcontrol->private_value = (long)c;
1277 mutex_unlock(&codec->spdif_mutex);
1281 int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1282 struct snd_ctl_elem_value *ucontrol)
1284 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1285 struct hda_bind_ctls *c;
1286 unsigned long *vals;
1287 int err = 0, change = 0;
1289 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1290 c = (struct hda_bind_ctls *)kcontrol->private_value;
1291 for (vals = c->values; *vals; vals++) {
1292 kcontrol->private_value = *vals;
1293 err = c->ops->put(kcontrol, ucontrol);
1298 kcontrol->private_value = (long)c;
1299 mutex_unlock(&codec->spdif_mutex);
1300 return err < 0 ? err : change;
1303 int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1304 unsigned int size, unsigned int __user *tlv)
1306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1307 struct hda_bind_ctls *c;
1310 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1311 c = (struct hda_bind_ctls *)kcontrol->private_value;
1312 kcontrol->private_value = *c->values;
1313 err = c->ops->tlv(kcontrol, op_flag, size, tlv);
1314 kcontrol->private_value = (long)c;
1315 mutex_unlock(&codec->spdif_mutex);
1319 struct hda_ctl_ops snd_hda_bind_vol = {
1320 .info = snd_hda_mixer_amp_volume_info,
1321 .get = snd_hda_mixer_amp_volume_get,
1322 .put = snd_hda_mixer_amp_volume_put,
1323 .tlv = snd_hda_mixer_amp_tlv
1326 struct hda_ctl_ops snd_hda_bind_sw = {
1327 .info = snd_hda_mixer_amp_switch_info,
1328 .get = snd_hda_mixer_amp_switch_get,
1329 .put = snd_hda_mixer_amp_switch_put,
1330 .tlv = snd_hda_mixer_amp_tlv
1334 * SPDIF out controls
1337 static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
1338 struct snd_ctl_elem_info *uinfo)
1340 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1345 static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
1346 struct snd_ctl_elem_value *ucontrol)
1348 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
1349 IEC958_AES0_NONAUDIO |
1350 IEC958_AES0_CON_EMPHASIS_5015 |
1351 IEC958_AES0_CON_NOT_COPYRIGHT;
1352 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
1353 IEC958_AES1_CON_ORIGINAL;
1357 static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
1358 struct snd_ctl_elem_value *ucontrol)
1360 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
1361 IEC958_AES0_NONAUDIO |
1362 IEC958_AES0_PRO_EMPHASIS_5015;
1366 static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
1367 struct snd_ctl_elem_value *ucontrol)
1369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1371 ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff;
1372 ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff;
1373 ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff;
1374 ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff;
1379 /* convert from SPDIF status bits to HDA SPDIF bits
1380 * bit 0 (DigEn) is always set zero (to be filled later)
1382 static unsigned short convert_from_spdif_status(unsigned int sbits)
1384 unsigned short val = 0;
1386 if (sbits & IEC958_AES0_PROFESSIONAL)
1387 val |= AC_DIG1_PROFESSIONAL;
1388 if (sbits & IEC958_AES0_NONAUDIO)
1389 val |= AC_DIG1_NONAUDIO;
1390 if (sbits & IEC958_AES0_PROFESSIONAL) {
1391 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
1392 IEC958_AES0_PRO_EMPHASIS_5015)
1393 val |= AC_DIG1_EMPHASIS;
1395 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
1396 IEC958_AES0_CON_EMPHASIS_5015)
1397 val |= AC_DIG1_EMPHASIS;
1398 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
1399 val |= AC_DIG1_COPYRIGHT;
1400 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
1401 val |= AC_DIG1_LEVEL;
1402 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
1407 /* convert to SPDIF status bits from HDA SPDIF bits
1409 static unsigned int convert_to_spdif_status(unsigned short val)
1411 unsigned int sbits = 0;
1413 if (val & AC_DIG1_NONAUDIO)
1414 sbits |= IEC958_AES0_NONAUDIO;
1415 if (val & AC_DIG1_PROFESSIONAL)
1416 sbits |= IEC958_AES0_PROFESSIONAL;
1417 if (sbits & IEC958_AES0_PROFESSIONAL) {
1418 if (sbits & AC_DIG1_EMPHASIS)
1419 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
1421 if (val & AC_DIG1_EMPHASIS)
1422 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
1423 if (!(val & AC_DIG1_COPYRIGHT))
1424 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
1425 if (val & AC_DIG1_LEVEL)
1426 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
1427 sbits |= val & (0x7f << 8);
1432 /* set digital convert verbs both for the given NID and its slaves */
1433 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
1438 snd_hda_codec_write(codec, nid, 0, verb, val);
1439 d = codec->slave_dig_outs;
1443 snd_hda_codec_write(codec, *d, 0, verb, val);
1446 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
1450 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1);
1452 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2);
1455 static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
1456 struct snd_ctl_elem_value *ucontrol)
1458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1459 hda_nid_t nid = kcontrol->private_value;
1463 mutex_lock(&codec->spdif_mutex);
1464 codec->spdif_status = ucontrol->value.iec958.status[0] |
1465 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
1466 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
1467 ((unsigned int)ucontrol->value.iec958.status[3] << 24);
1468 val = convert_from_spdif_status(codec->spdif_status);
1469 val |= codec->spdif_ctls & 1;
1470 change = codec->spdif_ctls != val;
1471 codec->spdif_ctls = val;
1474 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
1476 mutex_unlock(&codec->spdif_mutex);
1480 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
1482 static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
1483 struct snd_ctl_elem_value *ucontrol)
1485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1487 ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE;
1491 static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
1492 struct snd_ctl_elem_value *ucontrol)
1494 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1495 hda_nid_t nid = kcontrol->private_value;
1499 mutex_lock(&codec->spdif_mutex);
1500 val = codec->spdif_ctls & ~AC_DIG1_ENABLE;
1501 if (ucontrol->value.integer.value[0])
1502 val |= AC_DIG1_ENABLE;
1503 change = codec->spdif_ctls != val;
1505 codec->spdif_ctls = val;
1506 set_dig_out_convert(codec, nid, val & 0xff, -1);
1507 /* unmute amp switch (if any) */
1508 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
1509 (val & AC_DIG1_ENABLE))
1510 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1513 mutex_unlock(&codec->spdif_mutex);
1517 static struct snd_kcontrol_new dig_mixes[] = {
1519 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1520 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1521 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
1522 .info = snd_hda_spdif_mask_info,
1523 .get = snd_hda_spdif_cmask_get,
1526 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1528 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
1529 .info = snd_hda_spdif_mask_info,
1530 .get = snd_hda_spdif_pmask_get,
1533 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1534 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1535 .info = snd_hda_spdif_mask_info,
1536 .get = snd_hda_spdif_default_get,
1537 .put = snd_hda_spdif_default_put,
1540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1541 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
1542 .info = snd_hda_spdif_out_switch_info,
1543 .get = snd_hda_spdif_out_switch_get,
1544 .put = snd_hda_spdif_out_switch_put,
1549 #define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
1552 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
1553 * @codec: the HDA codec
1554 * @nid: audio out widget NID
1556 * Creates controls related with the SPDIF output.
1557 * Called from each patch supporting the SPDIF out.
1559 * Returns 0 if successful, or a negative error code.
1561 int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1564 struct snd_kcontrol *kctl;
1565 struct snd_kcontrol_new *dig_mix;
1568 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1569 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
1573 if (idx >= SPDIF_MAX_IDX) {
1574 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
1577 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1578 kctl = snd_ctl_new1(dig_mix, codec);
1579 kctl->id.index = idx;
1580 kctl->private_value = nid;
1581 err = snd_ctl_add(codec->bus->card, kctl);
1586 snd_hda_codec_read(codec, nid, 0,
1587 AC_VERB_GET_DIGI_CONVERT_1, 0);
1588 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
1593 * SPDIF sharing with analog output
1595 static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
1596 struct snd_ctl_elem_value *ucontrol)
1598 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1599 ucontrol->value.integer.value[0] = mout->share_spdif;
1603 static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
1604 struct snd_ctl_elem_value *ucontrol)
1606 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1607 mout->share_spdif = !!ucontrol->value.integer.value[0];
1611 static struct snd_kcontrol_new spdif_share_sw = {
1612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1613 .name = "IEC958 Default PCM Playback Switch",
1614 .info = snd_ctl_boolean_mono_info,
1615 .get = spdif_share_sw_get,
1616 .put = spdif_share_sw_put,
1619 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1620 struct hda_multi_out *mout)
1622 if (!mout->dig_out_nid)
1624 /* ATTENTION: here mout is passed as private_data, instead of codec */
1625 return snd_ctl_add(codec->bus->card,
1626 snd_ctl_new1(&spdif_share_sw, mout));
1633 #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
1635 static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_value *ucontrol)
1638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1640 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
1644 static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
1645 struct snd_ctl_elem_value *ucontrol)
1647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1648 hda_nid_t nid = kcontrol->private_value;
1649 unsigned int val = !!ucontrol->value.integer.value[0];
1652 mutex_lock(&codec->spdif_mutex);
1653 change = codec->spdif_in_enable != val;
1655 codec->spdif_in_enable = val;
1656 snd_hda_codec_write_cache(codec, nid, 0,
1657 AC_VERB_SET_DIGI_CONVERT_1, val);
1659 mutex_unlock(&codec->spdif_mutex);
1663 static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
1664 struct snd_ctl_elem_value *ucontrol)
1666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1667 hda_nid_t nid = kcontrol->private_value;
1671 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
1672 sbits = convert_to_spdif_status(val);
1673 ucontrol->value.iec958.status[0] = sbits;
1674 ucontrol->value.iec958.status[1] = sbits >> 8;
1675 ucontrol->value.iec958.status[2] = sbits >> 16;
1676 ucontrol->value.iec958.status[3] = sbits >> 24;
1680 static struct snd_kcontrol_new dig_in_ctls[] = {
1682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1683 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH),
1684 .info = snd_hda_spdif_in_switch_info,
1685 .get = snd_hda_spdif_in_switch_get,
1686 .put = snd_hda_spdif_in_switch_put,
1689 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1691 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1692 .info = snd_hda_spdif_mask_info,
1693 .get = snd_hda_spdif_in_status_get,
1699 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
1700 * @codec: the HDA codec
1701 * @nid: audio in widget NID
1703 * Creates controls related with the SPDIF input.
1704 * Called from each patch supporting the SPDIF in.
1706 * Returns 0 if successful, or a negative error code.
1708 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1711 struct snd_kcontrol *kctl;
1712 struct snd_kcontrol_new *dig_mix;
1715 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1716 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
1720 if (idx >= SPDIF_MAX_IDX) {
1721 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
1724 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1725 kctl = snd_ctl_new1(dig_mix, codec);
1726 kctl->private_value = nid;
1727 err = snd_ctl_add(codec->bus->card, kctl);
1731 codec->spdif_in_enable =
1732 snd_hda_codec_read(codec, nid, 0,
1733 AC_VERB_GET_DIGI_CONVERT_1, 0) &
1738 #ifdef SND_HDA_NEEDS_RESUME
1743 /* build a 32bit cache key with the widget id and the command parameter */
1744 #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
1745 #define get_cmd_cache_nid(key) ((key) & 0xff)
1746 #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
1749 * snd_hda_codec_write_cache - send a single command with caching
1750 * @codec: the HDA codec
1751 * @nid: NID to send the command
1752 * @direct: direct flag
1753 * @verb: the verb to send
1754 * @parm: the parameter for the verb
1756 * Send a single command without waiting for response.
1758 * Returns 0 if successful, or a negative error code.
1760 int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1761 int direct, unsigned int verb, unsigned int parm)
1764 snd_hda_power_up(codec);
1765 mutex_lock(&codec->bus->cmd_mutex);
1766 err = codec->bus->ops.command(codec, nid, direct, verb, parm);
1768 struct hda_cache_head *c;
1769 u32 key = build_cmd_cache_key(nid, verb);
1770 c = get_alloc_hash(&codec->cmd_cache, key);
1774 mutex_unlock(&codec->bus->cmd_mutex);
1775 snd_hda_power_down(codec);
1779 /* resume the all commands from the cache */
1780 void snd_hda_codec_resume_cache(struct hda_codec *codec)
1782 struct hda_cache_head *buffer = codec->cmd_cache.buffer;
1785 for (i = 0; i < codec->cmd_cache.size; i++, buffer++) {
1786 u32 key = buffer->key;
1789 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
1790 get_cmd_cache_cmd(key), buffer->val);
1795 * snd_hda_sequence_write_cache - sequence writes with caching
1796 * @codec: the HDA codec
1797 * @seq: VERB array to send
1799 * Send the commands sequentially from the given array.
1800 * Thte commands are recorded on cache for power-save and resume.
1801 * The array must be terminated with NID=0.
1803 void snd_hda_sequence_write_cache(struct hda_codec *codec,
1804 const struct hda_verb *seq)
1806 for (; seq->nid; seq++)
1807 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
1810 #endif /* SND_HDA_NEEDS_RESUME */
1813 * set power state of the codec
1815 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1816 unsigned int power_state)
1821 snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_POWER_STATE,
1823 msleep(10); /* partial workaround for "azx_get_response timeout" */
1825 nid = codec->start_nid;
1826 for (i = 0; i < codec->num_nodes; i++, nid++) {
1827 unsigned int wcaps = get_wcaps(codec, nid);
1828 if (wcaps & AC_WCAP_POWER) {
1829 unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >>
1831 if (wid_type == AC_WID_PIN) {
1832 unsigned int pincap;
1834 * don't power down the widget if it controls
1835 * eapd and EAPD_BTLENABLE is set.
1837 pincap = snd_hda_param_read(codec, nid,
1839 if (pincap & AC_PINCAP_EAPD) {
1840 int eapd = snd_hda_codec_read(codec,
1842 AC_VERB_GET_EAPD_BTLENABLE, 0);
1844 if (power_state == AC_PWRST_D3 && eapd)
1848 snd_hda_codec_write(codec, nid, 0,
1849 AC_VERB_SET_POWER_STATE,
1854 if (power_state == AC_PWRST_D0) {
1855 unsigned long end_time;
1858 /* wait until the codec reachs to D0 */
1859 end_time = jiffies + msecs_to_jiffies(500);
1861 state = snd_hda_codec_read(codec, fg, 0,
1862 AC_VERB_GET_POWER_STATE, 0);
1863 if (state == power_state)
1866 } while (time_after_eq(end_time, jiffies));
1870 #ifdef SND_HDA_NEEDS_RESUME
1872 * call suspend and power-down; used both from PM and power-save
1874 static void hda_call_codec_suspend(struct hda_codec *codec)
1876 if (codec->patch_ops.suspend)
1877 codec->patch_ops.suspend(codec, PMSG_SUSPEND);
1878 hda_set_power_state(codec,
1879 codec->afg ? codec->afg : codec->mfg,
1881 #ifdef CONFIG_SND_HDA_POWER_SAVE
1882 cancel_delayed_work(&codec->power_work);
1883 codec->power_on = 0;
1884 codec->power_transition = 0;
1889 * kick up codec; used both from PM and power-save
1891 static void hda_call_codec_resume(struct hda_codec *codec)
1893 hda_set_power_state(codec,
1894 codec->afg ? codec->afg : codec->mfg,
1896 if (codec->patch_ops.resume)
1897 codec->patch_ops.resume(codec);
1899 if (codec->patch_ops.init)
1900 codec->patch_ops.init(codec);
1901 snd_hda_codec_resume_amp(codec);
1902 snd_hda_codec_resume_cache(codec);
1905 #endif /* SND_HDA_NEEDS_RESUME */
1909 * snd_hda_build_controls - build mixer controls
1912 * Creates mixer controls for each codec included in the bus.
1914 * Returns 0 if successful, otherwise a negative error code.
1916 int __devinit snd_hda_build_controls(struct hda_bus *bus)
1918 struct hda_codec *codec;
1920 list_for_each_entry(codec, &bus->codec_list, list) {
1922 /* fake as if already powered-on */
1923 hda_keep_power_on(codec);
1925 hda_set_power_state(codec,
1926 codec->afg ? codec->afg : codec->mfg,
1928 /* continue to initialize... */
1929 if (codec->patch_ops.init)
1930 err = codec->patch_ops.init(codec);
1931 if (!err && codec->patch_ops.build_controls)
1932 err = codec->patch_ops.build_controls(codec);
1933 snd_hda_power_down(codec);
1944 struct hda_rate_tbl {
1946 unsigned int alsa_bits;
1947 unsigned int hda_fmt;
1950 static struct hda_rate_tbl rate_bits[] = {
1951 /* rate in Hz, ALSA rate bitmask, HDA format value */
1953 /* autodetected value used in snd_hda_query_supported_pcm */
1954 { 8000, SNDRV_PCM_RATE_8000, 0x0500 }, /* 1/6 x 48 */
1955 { 11025, SNDRV_PCM_RATE_11025, 0x4300 }, /* 1/4 x 44 */
1956 { 16000, SNDRV_PCM_RATE_16000, 0x0200 }, /* 1/3 x 48 */
1957 { 22050, SNDRV_PCM_RATE_22050, 0x4100 }, /* 1/2 x 44 */
1958 { 32000, SNDRV_PCM_RATE_32000, 0x0a00 }, /* 2/3 x 48 */
1959 { 44100, SNDRV_PCM_RATE_44100, 0x4000 }, /* 44 */
1960 { 48000, SNDRV_PCM_RATE_48000, 0x0000 }, /* 48 */
1961 { 88200, SNDRV_PCM_RATE_88200, 0x4800 }, /* 2 x 44 */
1962 { 96000, SNDRV_PCM_RATE_96000, 0x0800 }, /* 2 x 48 */
1963 { 176400, SNDRV_PCM_RATE_176400, 0x5800 },/* 4 x 44 */
1964 { 192000, SNDRV_PCM_RATE_192000, 0x1800 }, /* 4 x 48 */
1965 #define AC_PAR_PCM_RATE_BITS 11
1966 /* up to bits 10, 384kHZ isn't supported properly */
1968 /* not autodetected value */
1969 { 9600, SNDRV_PCM_RATE_KNOT, 0x0400 }, /* 1/5 x 48 */
1971 { 0 } /* terminator */
1975 * snd_hda_calc_stream_format - calculate format bitset
1976 * @rate: the sample rate
1977 * @channels: the number of channels
1978 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
1979 * @maxbps: the max. bps
1981 * Calculate the format bitset from the given rate, channels and th PCM format.
1983 * Return zero if invalid.
1985 unsigned int snd_hda_calc_stream_format(unsigned int rate,
1986 unsigned int channels,
1987 unsigned int format,
1988 unsigned int maxbps)
1991 unsigned int val = 0;
1993 for (i = 0; rate_bits[i].hz; i++)
1994 if (rate_bits[i].hz == rate) {
1995 val = rate_bits[i].hda_fmt;
1998 if (!rate_bits[i].hz) {
1999 snd_printdd("invalid rate %d\n", rate);
2003 if (channels == 0 || channels > 8) {
2004 snd_printdd("invalid channels %d\n", channels);
2007 val |= channels - 1;
2009 switch (snd_pcm_format_width(format)) {
2010 case 8: val |= 0x00; break;
2011 case 16: val |= 0x10; break;
2017 else if (maxbps >= 24)
2023 snd_printdd("invalid format width %d\n",
2024 snd_pcm_format_width(format));
2032 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
2033 * @codec: the HDA codec
2034 * @nid: NID to query
2035 * @ratesp: the pointer to store the detected rate bitflags
2036 * @formatsp: the pointer to store the detected formats
2037 * @bpsp: the pointer to store the detected format widths
2039 * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp
2040 * or @bsps argument is ignored.
2042 * Returns 0 if successful, otherwise a negative error code.
2044 int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2045 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
2048 unsigned int val, streams;
2051 if (nid != codec->afg &&
2052 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
2053 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
2058 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
2062 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) {
2064 rates |= rate_bits[i].alsa_bits;
2069 if (formatsp || bpsp) {
2074 wcaps = get_wcaps(codec, nid);
2075 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
2079 streams = snd_hda_param_read(codec, codec->afg,
2086 if (streams & AC_SUPFMT_PCM) {
2087 if (val & AC_SUPPCM_BITS_8) {
2088 formats |= SNDRV_PCM_FMTBIT_U8;
2091 if (val & AC_SUPPCM_BITS_16) {
2092 formats |= SNDRV_PCM_FMTBIT_S16_LE;
2095 if (wcaps & AC_WCAP_DIGITAL) {
2096 if (val & AC_SUPPCM_BITS_32)
2097 formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
2098 if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24))
2099 formats |= SNDRV_PCM_FMTBIT_S32_LE;
2100 if (val & AC_SUPPCM_BITS_24)
2102 else if (val & AC_SUPPCM_BITS_20)
2104 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|
2105 AC_SUPPCM_BITS_32)) {
2106 formats |= SNDRV_PCM_FMTBIT_S32_LE;
2107 if (val & AC_SUPPCM_BITS_32)
2109 else if (val & AC_SUPPCM_BITS_24)
2111 else if (val & AC_SUPPCM_BITS_20)
2115 else if (streams == AC_SUPFMT_FLOAT32) {
2116 /* should be exclusive */
2117 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
2119 } else if (streams == AC_SUPFMT_AC3) {
2120 /* should be exclusive */
2121 /* temporary hack: we have still no proper support
2122 * for the direct AC3 stream...
2124 formats |= SNDRV_PCM_FMTBIT_U8;
2128 *formatsp = formats;
2137 * snd_hda_is_supported_format - check whether the given node supports
2140 * Returns 1 if supported, 0 if not.
2142 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
2143 unsigned int format)
2146 unsigned int val = 0, rate, stream;
2148 if (nid != codec->afg &&
2149 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
2150 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
2155 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
2160 rate = format & 0xff00;
2161 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++)
2162 if (rate_bits[i].hda_fmt == rate) {
2167 if (i >= AC_PAR_PCM_RATE_BITS)
2170 stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
2173 if (!stream && nid != codec->afg)
2174 stream = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
2175 if (!stream || stream == -1)
2178 if (stream & AC_SUPFMT_PCM) {
2179 switch (format & 0xf0) {
2181 if (!(val & AC_SUPPCM_BITS_8))
2185 if (!(val & AC_SUPPCM_BITS_16))
2189 if (!(val & AC_SUPPCM_BITS_20))
2193 if (!(val & AC_SUPPCM_BITS_24))
2197 if (!(val & AC_SUPPCM_BITS_32))
2204 /* FIXME: check for float32 and AC3? */
2213 static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
2214 struct hda_codec *codec,
2215 struct snd_pcm_substream *substream)
2220 static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
2221 struct hda_codec *codec,
2222 unsigned int stream_tag,
2223 unsigned int format,
2224 struct snd_pcm_substream *substream)
2226 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
2230 static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2231 struct hda_codec *codec,
2232 struct snd_pcm_substream *substream)
2234 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2238 static int __devinit set_pcm_default_values(struct hda_codec *codec,
2239 struct hda_pcm_stream *info)
2241 /* query support PCM information from the given NID */
2242 if (info->nid && (!info->rates || !info->formats)) {
2243 snd_hda_query_supported_pcm(codec, info->nid,
2244 info->rates ? NULL : &info->rates,
2245 info->formats ? NULL : &info->formats,
2246 info->maxbps ? NULL : &info->maxbps);
2248 if (info->ops.open == NULL)
2249 info->ops.open = hda_pcm_default_open_close;
2250 if (info->ops.close == NULL)
2251 info->ops.close = hda_pcm_default_open_close;
2252 if (info->ops.prepare == NULL) {
2253 if (snd_BUG_ON(!info->nid))
2255 info->ops.prepare = hda_pcm_default_prepare;
2257 if (info->ops.cleanup == NULL) {
2258 if (snd_BUG_ON(!info->nid))
2260 info->ops.cleanup = hda_pcm_default_cleanup;
2266 * snd_hda_build_pcms - build PCM information
2269 * Create PCM information for each codec included in the bus.
2271 * The build_pcms codec patch is requested to set up codec->num_pcms and
2272 * codec->pcm_info properly. The array is referred by the top-level driver
2273 * to create its PCM instances.
2274 * The allocated codec->pcm_info should be released in codec->patch_ops.free
2277 * At least, substreams, channels_min and channels_max must be filled for
2278 * each stream. substreams = 0 indicates that the stream doesn't exist.
2279 * When rates and/or formats are zero, the supported values are queried
2280 * from the given nid. The nid is used also by the default ops.prepare
2281 * and ops.cleanup callbacks.
2283 * The driver needs to call ops.open in its open callback. Similarly,
2284 * ops.close is supposed to be called in the close callback.
2285 * ops.prepare should be called in the prepare or hw_params callback
2286 * with the proper parameters for set up.
2287 * ops.cleanup should be called in hw_free for clean up of streams.
2289 * This function returns 0 if successfull, or a negative error code.
2291 int __devinit snd_hda_build_pcms(struct hda_bus *bus)
2293 struct hda_codec *codec;
2295 list_for_each_entry(codec, &bus->codec_list, list) {
2296 unsigned int pcm, s;
2298 if (!codec->patch_ops.build_pcms)
2300 err = codec->patch_ops.build_pcms(codec);
2303 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2304 for (s = 0; s < 2; s++) {
2305 struct hda_pcm_stream *info;
2306 info = &codec->pcm_info[pcm].stream[s];
2307 if (!info->substreams)
2309 err = set_pcm_default_values(codec, info);
2319 * snd_hda_check_board_config - compare the current codec with the config table
2320 * @codec: the HDA codec
2321 * @num_configs: number of config enums
2322 * @models: array of model name strings
2323 * @tbl: configuration table, terminated by null entries
2325 * Compares the modelname or PCI subsystem id of the current codec with the
2326 * given configuration table. If a matching entry is found, returns its
2327 * config value (supposed to be 0 or positive).
2329 * If no entries are matching, the function returns a negative value.
2331 int snd_hda_check_board_config(struct hda_codec *codec,
2332 int num_configs, const char **models,
2333 const struct snd_pci_quirk *tbl)
2335 if (codec->bus->modelname && models) {
2337 for (i = 0; i < num_configs; i++) {
2339 !strcmp(codec->bus->modelname, models[i])) {
2340 snd_printd(KERN_INFO "hda_codec: model '%s' is "
2341 "selected\n", models[i]);
2347 if (!codec->bus->pci || !tbl)
2350 tbl = snd_pci_quirk_lookup(codec->bus->pci, tbl);
2353 if (tbl->value >= 0 && tbl->value < num_configs) {
2354 #ifdef CONFIG_SND_DEBUG_VERBOSE
2356 const char *model = NULL;
2358 model = models[tbl->value];
2360 sprintf(tmp, "#%d", tbl->value);
2363 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
2364 "for config %x:%x (%s)\n",
2365 model, tbl->subvendor, tbl->subdevice,
2366 (tbl->name ? tbl->name : "Unknown device"));
2374 * snd_hda_add_new_ctls - create controls from the array
2375 * @codec: the HDA codec
2376 * @knew: the array of struct snd_kcontrol_new
2378 * This helper function creates and add new controls in the given array.
2379 * The array must be terminated with an empty entry as terminator.
2381 * Returns 0 if successful, or a negative error code.
2383 int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2387 for (; knew->name; knew++) {
2388 struct snd_kcontrol *kctl;
2389 kctl = snd_ctl_new1(knew, codec);
2392 err = snd_ctl_add(codec->bus->card, kctl);
2396 kctl = snd_ctl_new1(knew, codec);
2399 kctl->id.device = codec->addr;
2400 err = snd_ctl_add(codec->bus->card, kctl);
2408 #ifdef CONFIG_SND_HDA_POWER_SAVE
2409 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2410 unsigned int power_state);
2412 static void hda_power_work(struct work_struct *work)
2414 struct hda_codec *codec =
2415 container_of(work, struct hda_codec, power_work.work);
2417 if (!codec->power_on || codec->power_count) {
2418 codec->power_transition = 0;
2422 hda_call_codec_suspend(codec);
2423 if (codec->bus->ops.pm_notify)
2424 codec->bus->ops.pm_notify(codec);
2427 static void hda_keep_power_on(struct hda_codec *codec)
2429 codec->power_count++;
2430 codec->power_on = 1;
2433 void snd_hda_power_up(struct hda_codec *codec)
2435 codec->power_count++;
2436 if (codec->power_on || codec->power_transition)
2439 codec->power_on = 1;
2440 if (codec->bus->ops.pm_notify)
2441 codec->bus->ops.pm_notify(codec);
2442 hda_call_codec_resume(codec);
2443 cancel_delayed_work(&codec->power_work);
2444 codec->power_transition = 0;
2447 void snd_hda_power_down(struct hda_codec *codec)
2449 --codec->power_count;
2450 if (!codec->power_on || codec->power_count || codec->power_transition)
2453 codec->power_transition = 1; /* avoid reentrance */
2454 schedule_delayed_work(&codec->power_work,
2455 msecs_to_jiffies(power_save * 1000));
2459 int snd_hda_check_amp_list_power(struct hda_codec *codec,
2460 struct hda_loopback_check *check,
2463 struct hda_amp_list *p;
2466 if (!check->amplist)
2468 for (p = check->amplist; p->nid; p++) {
2473 return 0; /* nothing changed */
2475 for (p = check->amplist; p->nid; p++) {
2476 for (ch = 0; ch < 2; ch++) {
2477 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
2479 if (!(v & HDA_AMP_MUTE) && v > 0) {
2480 if (!check->power_on) {
2481 check->power_on = 1;
2482 snd_hda_power_up(codec);
2488 if (check->power_on) {
2489 check->power_on = 0;
2490 snd_hda_power_down(codec);
2497 * Channel mode helper
2499 int snd_hda_ch_mode_info(struct hda_codec *codec,
2500 struct snd_ctl_elem_info *uinfo,
2501 const struct hda_channel_mode *chmode,
2504 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2506 uinfo->value.enumerated.items = num_chmodes;
2507 if (uinfo->value.enumerated.item >= num_chmodes)
2508 uinfo->value.enumerated.item = num_chmodes - 1;
2509 sprintf(uinfo->value.enumerated.name, "%dch",
2510 chmode[uinfo->value.enumerated.item].channels);
2514 int snd_hda_ch_mode_get(struct hda_codec *codec,
2515 struct snd_ctl_elem_value *ucontrol,
2516 const struct hda_channel_mode *chmode,
2522 for (i = 0; i < num_chmodes; i++) {
2523 if (max_channels == chmode[i].channels) {
2524 ucontrol->value.enumerated.item[0] = i;
2531 int snd_hda_ch_mode_put(struct hda_codec *codec,
2532 struct snd_ctl_elem_value *ucontrol,
2533 const struct hda_channel_mode *chmode,
2539 mode = ucontrol->value.enumerated.item[0];
2540 if (mode >= num_chmodes)
2542 if (*max_channelsp == chmode[mode].channels)
2544 /* change the current channel setting */
2545 *max_channelsp = chmode[mode].channels;
2546 if (chmode[mode].sequence)
2547 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
2554 int snd_hda_input_mux_info(const struct hda_input_mux *imux,
2555 struct snd_ctl_elem_info *uinfo)
2559 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2561 uinfo->value.enumerated.items = imux->num_items;
2562 if (!imux->num_items)
2564 index = uinfo->value.enumerated.item;
2565 if (index >= imux->num_items)
2566 index = imux->num_items - 1;
2567 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
2571 int snd_hda_input_mux_put(struct hda_codec *codec,
2572 const struct hda_input_mux *imux,
2573 struct snd_ctl_elem_value *ucontrol,
2575 unsigned int *cur_val)
2579 if (!imux->num_items)
2581 idx = ucontrol->value.enumerated.item[0];
2582 if (idx >= imux->num_items)
2583 idx = imux->num_items - 1;
2584 if (*cur_val == idx)
2586 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
2587 imux->items[idx].index);
2594 * Multi-channel / digital-out PCM helper functions
2597 /* setup SPDIF output stream */
2598 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
2599 unsigned int stream_tag, unsigned int format)
2601 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2602 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
2603 set_dig_out_convert(codec, nid,
2604 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
2606 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2607 if (codec->slave_dig_outs) {
2609 for (d = codec->slave_dig_outs; *d; d++)
2610 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
2613 /* turn on again (if needed) */
2614 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
2615 set_dig_out_convert(codec, nid,
2616 codec->spdif_ctls & 0xff, -1);
2619 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
2621 snd_hda_codec_cleanup_stream(codec, nid);
2622 if (codec->slave_dig_outs) {
2624 for (d = codec->slave_dig_outs; *d; d++)
2625 snd_hda_codec_cleanup_stream(codec, *d);
2630 * open the digital out in the exclusive mode
2632 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2633 struct hda_multi_out *mout)
2635 mutex_lock(&codec->spdif_mutex);
2636 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2637 /* already opened as analog dup; reset it once */
2638 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2639 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2640 mutex_unlock(&codec->spdif_mutex);
2644 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2645 struct hda_multi_out *mout,
2646 unsigned int stream_tag,
2647 unsigned int format,
2648 struct snd_pcm_substream *substream)
2650 mutex_lock(&codec->spdif_mutex);
2651 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
2652 mutex_unlock(&codec->spdif_mutex);
2657 * release the digital out
2659 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2660 struct hda_multi_out *mout)
2662 mutex_lock(&codec->spdif_mutex);
2663 mout->dig_out_used = 0;
2664 mutex_unlock(&codec->spdif_mutex);
2669 * set up more restrictions for analog out
2671 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2672 struct hda_multi_out *mout,
2673 struct snd_pcm_substream *substream,
2674 struct hda_pcm_stream *hinfo)
2676 struct snd_pcm_runtime *runtime = substream->runtime;
2677 runtime->hw.channels_max = mout->max_channels;
2678 if (mout->dig_out_nid) {
2679 if (!mout->analog_rates) {
2680 mout->analog_rates = hinfo->rates;
2681 mout->analog_formats = hinfo->formats;
2682 mout->analog_maxbps = hinfo->maxbps;
2684 runtime->hw.rates = mout->analog_rates;
2685 runtime->hw.formats = mout->analog_formats;
2686 hinfo->maxbps = mout->analog_maxbps;
2688 if (!mout->spdif_rates) {
2689 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
2691 &mout->spdif_formats,
2692 &mout->spdif_maxbps);
2694 mutex_lock(&codec->spdif_mutex);
2695 if (mout->share_spdif) {
2696 runtime->hw.rates &= mout->spdif_rates;
2697 runtime->hw.formats &= mout->spdif_formats;
2698 if (mout->spdif_maxbps < hinfo->maxbps)
2699 hinfo->maxbps = mout->spdif_maxbps;
2701 mutex_unlock(&codec->spdif_mutex);
2703 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2704 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2708 * set up the i/o for analog out
2709 * when the digital out is available, copy the front out to digital out, too.
2711 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2712 struct hda_multi_out *mout,
2713 unsigned int stream_tag,
2714 unsigned int format,
2715 struct snd_pcm_substream *substream)
2717 hda_nid_t *nids = mout->dac_nids;
2718 int chs = substream->runtime->channels;
2721 mutex_lock(&codec->spdif_mutex);
2722 if (mout->dig_out_nid && mout->share_spdif &&
2723 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
2725 snd_hda_is_supported_format(codec, mout->dig_out_nid,
2727 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
2728 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
2729 setup_dig_out_stream(codec, mout->dig_out_nid,
2730 stream_tag, format);
2732 mout->dig_out_used = 0;
2733 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2736 mutex_unlock(&codec->spdif_mutex);
2739 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
2741 if (!mout->no_share_stream &&
2742 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
2743 /* headphone out will just decode front left/right (stereo) */
2744 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
2746 /* extra outputs copied from front */
2747 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2748 if (!mout->no_share_stream && mout->extra_out_nid[i])
2749 snd_hda_codec_setup_stream(codec,
2750 mout->extra_out_nid[i],
2751 stream_tag, 0, format);
2754 for (i = 1; i < mout->num_dacs; i++) {
2755 if (chs >= (i + 1) * 2) /* independent out */
2756 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
2758 else if (!mout->no_share_stream) /* copy front */
2759 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
2766 * clean up the setting for analog out
2768 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2769 struct hda_multi_out *mout)
2771 hda_nid_t *nids = mout->dac_nids;
2774 for (i = 0; i < mout->num_dacs; i++)
2775 snd_hda_codec_cleanup_stream(codec, nids[i]);
2777 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
2778 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2779 if (mout->extra_out_nid[i])
2780 snd_hda_codec_cleanup_stream(codec,
2781 mout->extra_out_nid[i]);
2782 mutex_lock(&codec->spdif_mutex);
2783 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2784 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2785 mout->dig_out_used = 0;
2787 mutex_unlock(&codec->spdif_mutex);
2792 * Helper for automatic pin configuration
2795 static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
2797 for (; *list; list++)
2805 * Sort an associated group of pins according to their sequence numbers.
2807 static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences,
2814 for (i = 0; i < num_pins; i++) {
2815 for (j = i + 1; j < num_pins; j++) {
2816 if (sequences[i] > sequences[j]) {
2818 sequences[i] = sequences[j];
2830 * Parse all pin widgets and store the useful pin nids to cfg
2832 * The number of line-outs or any primary output is stored in line_outs,
2833 * and the corresponding output pins are assigned to line_out_pins[],
2834 * in the order of front, rear, CLFE, side, ...
2836 * If more extra outputs (speaker and headphone) are found, the pins are
2837 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
2838 * is detected, one of speaker of HP pins is assigned as the primary
2839 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
2840 * if any analog output exists.
2842 * The analog input pins are assigned to input_pins array.
2843 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
2846 int snd_hda_parse_pin_def_config(struct hda_codec *codec,
2847 struct auto_pin_cfg *cfg,
2848 hda_nid_t *ignore_nids)
2850 hda_nid_t nid, end_nid;
2851 short seq, assoc_line_out, assoc_speaker;
2852 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
2853 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
2854 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
2856 memset(cfg, 0, sizeof(*cfg));
2858 memset(sequences_line_out, 0, sizeof(sequences_line_out));
2859 memset(sequences_speaker, 0, sizeof(sequences_speaker));
2860 memset(sequences_hp, 0, sizeof(sequences_hp));
2861 assoc_line_out = assoc_speaker = 0;
2863 end_nid = codec->start_nid + codec->num_nodes;
2864 for (nid = codec->start_nid; nid < end_nid; nid++) {
2865 unsigned int wid_caps = get_wcaps(codec, nid);
2866 unsigned int wid_type =
2867 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2868 unsigned int def_conf;
2871 /* read all default configuration for pin complex */
2872 if (wid_type != AC_WID_PIN)
2874 /* ignore the given nids (e.g. pc-beep returns error) */
2875 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
2878 def_conf = snd_hda_codec_read(codec, nid, 0,
2879 AC_VERB_GET_CONFIG_DEFAULT, 0);
2880 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2882 loc = get_defcfg_location(def_conf);
2883 switch (get_defcfg_device(def_conf)) {
2884 case AC_JACK_LINE_OUT:
2885 seq = get_defcfg_sequence(def_conf);
2886 assoc = get_defcfg_association(def_conf);
2888 if (!(wid_caps & AC_WCAP_STEREO))
2889 if (!cfg->mono_out_pin)
2890 cfg->mono_out_pin = nid;
2893 if (!assoc_line_out)
2894 assoc_line_out = assoc;
2895 else if (assoc_line_out != assoc)
2897 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
2899 cfg->line_out_pins[cfg->line_outs] = nid;
2900 sequences_line_out[cfg->line_outs] = seq;
2903 case AC_JACK_SPEAKER:
2904 seq = get_defcfg_sequence(def_conf);
2905 assoc = get_defcfg_association(def_conf);
2908 if (! assoc_speaker)
2909 assoc_speaker = assoc;
2910 else if (assoc_speaker != assoc)
2912 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
2914 cfg->speaker_pins[cfg->speaker_outs] = nid;
2915 sequences_speaker[cfg->speaker_outs] = seq;
2916 cfg->speaker_outs++;
2918 case AC_JACK_HP_OUT:
2919 seq = get_defcfg_sequence(def_conf);
2920 assoc = get_defcfg_association(def_conf);
2921 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
2923 cfg->hp_pins[cfg->hp_outs] = nid;
2924 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
2927 case AC_JACK_MIC_IN: {
2929 if (loc == AC_JACK_LOC_FRONT) {
2930 preferred = AUTO_PIN_FRONT_MIC;
2933 preferred = AUTO_PIN_MIC;
2934 alt = AUTO_PIN_FRONT_MIC;
2936 if (!cfg->input_pins[preferred])
2937 cfg->input_pins[preferred] = nid;
2938 else if (!cfg->input_pins[alt])
2939 cfg->input_pins[alt] = nid;
2942 case AC_JACK_LINE_IN:
2943 if (loc == AC_JACK_LOC_FRONT)
2944 cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid;
2946 cfg->input_pins[AUTO_PIN_LINE] = nid;
2949 cfg->input_pins[AUTO_PIN_CD] = nid;
2952 cfg->input_pins[AUTO_PIN_AUX] = nid;
2954 case AC_JACK_SPDIF_OUT:
2955 cfg->dig_out_pin = nid;
2957 case AC_JACK_SPDIF_IN:
2958 cfg->dig_in_pin = nid;
2964 * If no line-out is defined but multiple HPs are found,
2965 * some of them might be the real line-outs.
2967 if (!cfg->line_outs && cfg->hp_outs > 1) {
2969 while (i < cfg->hp_outs) {
2970 /* The real HPs should have the sequence 0x0f */
2971 if ((sequences_hp[i] & 0x0f) == 0x0f) {
2975 /* Move it to the line-out table */
2976 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
2977 sequences_line_out[cfg->line_outs] = sequences_hp[i];
2980 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
2981 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
2982 memmove(sequences_hp + i - 1, sequences_hp + i,
2983 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
2987 /* sort by sequence */
2988 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
2990 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
2992 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
2995 /* if we have only one mic, make it AUTO_PIN_MIC */
2996 if (!cfg->input_pins[AUTO_PIN_MIC] &&
2997 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
2998 cfg->input_pins[AUTO_PIN_MIC] =
2999 cfg->input_pins[AUTO_PIN_FRONT_MIC];
3000 cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0;
3002 /* ditto for line-in */
3003 if (!cfg->input_pins[AUTO_PIN_LINE] &&
3004 cfg->input_pins[AUTO_PIN_FRONT_LINE]) {
3005 cfg->input_pins[AUTO_PIN_LINE] =
3006 cfg->input_pins[AUTO_PIN_FRONT_LINE];
3007 cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0;
3011 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
3012 * as a primary output
3014 if (!cfg->line_outs) {
3015 if (cfg->speaker_outs) {
3016 cfg->line_outs = cfg->speaker_outs;
3017 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3018 sizeof(cfg->speaker_pins));
3019 cfg->speaker_outs = 0;
3020 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3021 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3022 } else if (cfg->hp_outs) {
3023 cfg->line_outs = cfg->hp_outs;
3024 memcpy(cfg->line_out_pins, cfg->hp_pins,
3025 sizeof(cfg->hp_pins));
3027 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3028 cfg->line_out_type = AUTO_PIN_HP_OUT;
3032 /* Reorder the surround channels
3033 * ALSA sequence is front/surr/clfe/side
3035 * 4-ch: front/surr => OK as it is
3036 * 6-ch: front/clfe/surr
3037 * 8-ch: front/clfe/rear/side|fc
3039 switch (cfg->line_outs) {
3042 nid = cfg->line_out_pins[1];
3043 cfg->line_out_pins[1] = cfg->line_out_pins[2];
3044 cfg->line_out_pins[2] = nid;
3049 * debug prints of the parsed results
3051 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3052 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
3053 cfg->line_out_pins[2], cfg->line_out_pins[3],
3054 cfg->line_out_pins[4]);
3055 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3056 cfg->speaker_outs, cfg->speaker_pins[0],
3057 cfg->speaker_pins[1], cfg->speaker_pins[2],
3058 cfg->speaker_pins[3], cfg->speaker_pins[4]);
3059 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3060 cfg->hp_outs, cfg->hp_pins[0],
3061 cfg->hp_pins[1], cfg->hp_pins[2],
3062 cfg->hp_pins[3], cfg->hp_pins[4]);
3063 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
3064 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
3065 " cd=0x%x, aux=0x%x\n",
3066 cfg->input_pins[AUTO_PIN_MIC],
3067 cfg->input_pins[AUTO_PIN_FRONT_MIC],
3068 cfg->input_pins[AUTO_PIN_LINE],
3069 cfg->input_pins[AUTO_PIN_FRONT_LINE],
3070 cfg->input_pins[AUTO_PIN_CD],
3071 cfg->input_pins[AUTO_PIN_AUX]);
3076 /* labels for input pins */
3077 const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
3078 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
3088 * snd_hda_suspend - suspend the codecs
3090 * @state: suspsend state
3092 * Returns 0 if successful.
3094 int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
3096 struct hda_codec *codec;
3098 list_for_each_entry(codec, &bus->codec_list, list) {
3099 #ifdef CONFIG_SND_HDA_POWER_SAVE
3100 if (!codec->power_on)
3103 hda_call_codec_suspend(codec);
3109 * snd_hda_resume - resume the codecs
3111 * @state: resume state
3113 * Returns 0 if successful.
3115 * This fucntion is defined only when POWER_SAVE isn't set.
3116 * In the power-save mode, the codec is resumed dynamically.
3118 int snd_hda_resume(struct hda_bus *bus)
3120 struct hda_codec *codec;
3122 list_for_each_entry(codec, &bus->codec_list, list) {
3123 if (snd_hda_codec_needs_resume(codec))
3124 hda_call_codec_resume(codec);
3128 #ifdef CONFIG_SND_HDA_POWER_SAVE
3129 int snd_hda_codecs_inuse(struct hda_bus *bus)
3131 struct hda_codec *codec;
3133 list_for_each_entry(codec, &bus->codec_list, list) {
3134 if (snd_hda_codec_needs_resume(codec))