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
100 #ifdef CONFIG_SND_HDA_POWER_SAVE
101 static void hda_power_work(struct work_struct *work);
102 static void hda_keep_power_on(struct hda_codec *codec);
104 static inline void hda_keep_power_on(struct hda_codec *codec) {}
108 * snd_hda_codec_read - send a command and get the response
109 * @codec: the HDA codec
110 * @nid: NID to send the command
111 * @direct: direct flag
112 * @verb: the verb to send
113 * @parm: the parameter for the verb
115 * Send a single command and read the corresponding response.
117 * Returns the obtained response value, or -1 for an error.
119 unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
121 unsigned int verb, unsigned int parm)
124 snd_hda_power_up(codec);
125 mutex_lock(&codec->bus->cmd_mutex);
126 if (!codec->bus->ops.command(codec, nid, direct, verb, parm))
127 res = codec->bus->ops.get_response(codec);
129 res = (unsigned int)-1;
130 mutex_unlock(&codec->bus->cmd_mutex);
131 snd_hda_power_down(codec);
136 * snd_hda_codec_write - send a single command without waiting for response
137 * @codec: the HDA codec
138 * @nid: NID to send the command
139 * @direct: direct flag
140 * @verb: the verb to send
141 * @parm: the parameter for the verb
143 * Send a single command without waiting for response.
145 * Returns 0 if successful, or a negative error code.
147 int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
148 unsigned int verb, unsigned int parm)
151 snd_hda_power_up(codec);
152 mutex_lock(&codec->bus->cmd_mutex);
153 err = codec->bus->ops.command(codec, nid, direct, verb, parm);
154 mutex_unlock(&codec->bus->cmd_mutex);
155 snd_hda_power_down(codec);
160 * snd_hda_sequence_write - sequence writes
161 * @codec: the HDA codec
162 * @seq: VERB array to send
164 * Send the commands sequentially from the given array.
165 * The array must be terminated with NID=0.
167 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
169 for (; seq->nid; seq++)
170 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
174 * snd_hda_get_sub_nodes - get the range of sub nodes
175 * @codec: the HDA codec
177 * @start_id: the pointer to store the start NID
179 * Parse the NID and store the start NID of its sub-nodes.
180 * Returns the number of sub-nodes.
182 int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
187 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
190 *start_id = (parm >> 16) & 0x7fff;
191 return (int)(parm & 0x7fff);
195 * snd_hda_get_connections - get connection list
196 * @codec: the HDA codec
198 * @conn_list: connection list array
199 * @max_conns: max. number of connections to store
201 * Parses the connection list of the given widget and stores the list
204 * Returns the number of connections, or a negative error code.
206 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
207 hda_nid_t *conn_list, int max_conns)
210 int i, conn_len, conns;
211 unsigned int shift, num_elems, mask;
214 if (snd_BUG_ON(!conn_list || max_conns <= 0))
217 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
218 if (parm & AC_CLIST_LONG) {
227 conn_len = parm & AC_CLIST_LENGTH;
228 mask = (1 << (shift-1)) - 1;
231 return 0; /* no connection */
234 /* single connection */
235 parm = snd_hda_codec_read(codec, nid, 0,
236 AC_VERB_GET_CONNECT_LIST, 0);
237 conn_list[0] = parm & mask;
241 /* multi connection */
244 for (i = 0; i < conn_len; i++) {
248 if (i % num_elems == 0)
249 parm = snd_hda_codec_read(codec, nid, 0,
250 AC_VERB_GET_CONNECT_LIST, i);
251 range_val = !!(parm & (1 << (shift-1))); /* ranges */
255 /* ranges between the previous and this one */
256 if (!prev_nid || prev_nid >= val) {
257 snd_printk(KERN_WARNING "hda_codec: "
258 "invalid dep_range_val %x:%x\n",
262 for (n = prev_nid + 1; n <= val; n++) {
263 if (conns >= max_conns) {
265 "Too many connections\n");
268 conn_list[conns++] = n;
271 if (conns >= max_conns) {
272 snd_printk(KERN_ERR "Too many connections\n");
275 conn_list[conns++] = val;
284 * snd_hda_queue_unsol_event - add an unsolicited event to queue
286 * @res: unsolicited event (lower 32bit of RIRB entry)
287 * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
289 * Adds the given event to the queue. The events are processed in
290 * the workqueue asynchronously. Call this function in the interrupt
291 * hanlder when RIRB receives an unsolicited event.
293 * Returns 0 if successful, or a negative error code.
295 int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
297 struct hda_bus_unsolicited *unsol;
304 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
308 unsol->queue[wp] = res;
309 unsol->queue[wp + 1] = res_ex;
311 schedule_work(&unsol->work);
317 * process queueud unsolicited events
319 static void process_unsol_events(struct work_struct *work)
321 struct hda_bus_unsolicited *unsol =
322 container_of(work, struct hda_bus_unsolicited, work);
323 struct hda_bus *bus = unsol->bus;
324 struct hda_codec *codec;
325 unsigned int rp, caddr, res;
327 while (unsol->rp != unsol->wp) {
328 rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE;
331 res = unsol->queue[rp];
332 caddr = unsol->queue[rp + 1];
333 if (!(caddr & (1 << 4))) /* no unsolicited event? */
335 codec = bus->caddr_tbl[caddr & 0x0f];
336 if (codec && codec->patch_ops.unsol_event)
337 codec->patch_ops.unsol_event(codec, res);
342 * initialize unsolicited queue
344 static int __devinit init_unsol_queue(struct hda_bus *bus)
346 struct hda_bus_unsolicited *unsol;
348 if (bus->unsol) /* already initialized */
351 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
353 snd_printk(KERN_ERR "hda_codec: "
354 "can't allocate unsolicited queue\n");
357 INIT_WORK(&unsol->work, process_unsol_events);
366 static void snd_hda_codec_free(struct hda_codec *codec);
368 static int snd_hda_bus_free(struct hda_bus *bus)
370 struct hda_codec *codec, *n;
375 flush_scheduled_work();
378 list_for_each_entry_safe(codec, n, &bus->codec_list, list) {
379 snd_hda_codec_free(codec);
381 if (bus->ops.private_free)
382 bus->ops.private_free(bus);
387 static int snd_hda_bus_dev_free(struct snd_device *device)
389 struct hda_bus *bus = device->device_data;
390 return snd_hda_bus_free(bus);
394 * snd_hda_bus_new - create a HDA bus
395 * @card: the card entry
396 * @temp: the template for hda_bus information
397 * @busp: the pointer to store the created bus instance
399 * Returns 0 if successful, or a negative error code.
401 int __devinit snd_hda_bus_new(struct snd_card *card,
402 const struct hda_bus_template *temp,
403 struct hda_bus **busp)
407 static struct snd_device_ops dev_ops = {
408 .dev_free = snd_hda_bus_dev_free,
411 if (snd_BUG_ON(!temp))
413 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
419 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
421 snd_printk(KERN_ERR "can't allocate struct hda_bus\n");
426 bus->private_data = temp->private_data;
427 bus->pci = temp->pci;
428 bus->modelname = temp->modelname;
429 bus->ops = temp->ops;
431 mutex_init(&bus->cmd_mutex);
432 INIT_LIST_HEAD(&bus->codec_list);
434 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
436 snd_hda_bus_free(bus);
444 #ifdef CONFIG_SND_HDA_GENERIC
445 #define is_generic_config(codec) \
446 (codec->bus->modelname && !strcmp(codec->bus->modelname, "generic"))
448 #define is_generic_config(codec) 0
452 * find a matching codec preset
454 static const struct hda_codec_preset __devinit *
455 find_codec_preset(struct hda_codec *codec)
457 const struct hda_codec_preset **tbl, *preset;
459 if (is_generic_config(codec))
460 return NULL; /* use the generic parser */
462 for (tbl = hda_preset_tables; *tbl; tbl++) {
463 for (preset = *tbl; preset->id; preset++) {
464 u32 mask = preset->mask;
465 if (preset->afg && preset->afg != codec->afg)
467 if (preset->mfg && preset->mfg != codec->mfg)
471 if (preset->id == (codec->vendor_id & mask) &&
473 preset->rev == codec->revision_id))
481 * snd_hda_get_codec_name - store the codec name
483 void snd_hda_get_codec_name(struct hda_codec *codec,
484 char *name, int namelen)
486 const struct hda_vendor_id *c;
487 const char *vendor = NULL;
488 u16 vendor_id = codec->vendor_id >> 16;
491 for (c = hda_vendor_ids; c->id; c++) {
492 if (c->id == vendor_id) {
498 sprintf(tmp, "Generic %04x", vendor_id);
501 if (codec->preset && codec->preset->name)
502 snprintf(name, namelen, "%s %s", vendor, codec->preset->name);
504 snprintf(name, namelen, "%s ID %x", vendor,
505 codec->vendor_id & 0xffff);
509 * look for an AFG and MFG nodes
511 static void __devinit setup_fg_nodes(struct hda_codec *codec)
516 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
517 for (i = 0; i < total_nodes; i++, nid++) {
519 func = snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE);
520 switch (func & 0xff) {
521 case AC_GRP_AUDIO_FUNCTION:
524 case AC_GRP_MODEM_FUNCTION:
534 * read widget caps for each widget and store in cache
536 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
541 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node,
543 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
546 nid = codec->start_nid;
547 for (i = 0; i < codec->num_nodes; i++, nid++)
548 codec->wcaps[i] = snd_hda_param_read(codec, nid,
549 AC_PAR_AUDIO_WIDGET_CAP);
554 static void init_hda_cache(struct hda_cache_rec *cache,
555 unsigned int record_size);
556 static void free_hda_cache(struct hda_cache_rec *cache);
561 static void snd_hda_codec_free(struct hda_codec *codec)
565 #ifdef CONFIG_SND_HDA_POWER_SAVE
566 cancel_delayed_work(&codec->power_work);
567 flush_scheduled_work();
569 list_del(&codec->list);
570 codec->bus->caddr_tbl[codec->addr] = NULL;
571 if (codec->patch_ops.free)
572 codec->patch_ops.free(codec);
573 free_hda_cache(&codec->amp_cache);
574 free_hda_cache(&codec->cmd_cache);
580 * snd_hda_codec_new - create a HDA codec
581 * @bus: the bus to assign
582 * @codec_addr: the codec address
583 * @codecp: the pointer to store the generated codec
585 * Returns 0 if successful, or a negative error code.
587 int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
588 struct hda_codec **codecp)
590 struct hda_codec *codec;
594 if (snd_BUG_ON(!bus))
596 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
599 if (bus->caddr_tbl[codec_addr]) {
600 snd_printk(KERN_ERR "hda_codec: "
601 "address 0x%x is already occupied\n", codec_addr);
605 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
607 snd_printk(KERN_ERR "can't allocate struct hda_codec\n");
612 codec->addr = codec_addr;
613 mutex_init(&codec->spdif_mutex);
614 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
615 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
617 #ifdef CONFIG_SND_HDA_POWER_SAVE
618 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
619 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
620 * the caller has to power down appropriatley after initialization
623 hda_keep_power_on(codec);
626 list_add_tail(&codec->list, &bus->codec_list);
627 bus->caddr_tbl[codec_addr] = codec;
629 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
631 if (codec->vendor_id == -1)
632 /* read again, hopefully the access method was corrected
633 * in the last read...
635 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
637 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
638 AC_PAR_SUBSYSTEM_ID);
639 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
642 setup_fg_nodes(codec);
643 if (!codec->afg && !codec->mfg) {
644 snd_printdd("hda_codec: no AFG or MFG node found\n");
645 snd_hda_codec_free(codec);
649 if (read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg) < 0) {
650 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
651 snd_hda_codec_free(codec);
655 if (!codec->subsystem_id) {
656 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
657 codec->subsystem_id =
658 snd_hda_codec_read(codec, nid, 0,
659 AC_VERB_GET_SUBSYSTEM_ID, 0);
662 codec->preset = find_codec_preset(codec);
663 /* audio codec should override the mixer name */
664 if (codec->afg || !*bus->card->mixername)
665 snd_hda_get_codec_name(codec, bus->card->mixername,
666 sizeof(bus->card->mixername));
668 if (is_generic_config(codec)) {
669 err = snd_hda_parse_generic_codec(codec);
672 if (codec->preset && codec->preset->patch) {
673 err = codec->preset->patch(codec);
677 /* call the default parser */
678 err = snd_hda_parse_generic_codec(codec);
680 printk(KERN_ERR "hda-codec: No codec parser is available\n");
684 snd_hda_codec_free(codec);
688 if (codec->patch_ops.unsol_event)
689 init_unsol_queue(bus);
691 snd_hda_codec_proc_new(codec);
692 #ifdef CONFIG_SND_HDA_HWDEP
693 snd_hda_create_hwdep(codec);
696 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id);
697 snd_component_add(codec->bus->card, component);
705 * snd_hda_codec_setup_stream - set up the codec for streaming
706 * @codec: the CODEC to set up
707 * @nid: the NID to set up
708 * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
709 * @channel_id: channel id to pass, zero based.
710 * @format: stream format.
712 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
714 int channel_id, int format)
719 snd_printdd("hda_codec_setup_stream: "
720 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
721 nid, stream_tag, channel_id, format);
722 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
723 (stream_tag << 4) | channel_id);
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
728 void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
733 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
734 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
735 #if 0 /* keep the format */
737 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
742 * amp access functions
745 /* FIXME: more better hash key? */
746 #define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
747 #define INFO_AMP_CAPS (1<<0)
748 #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
750 /* initialize the hash table */
751 static void __devinit init_hda_cache(struct hda_cache_rec *cache,
752 unsigned int record_size)
754 memset(cache, 0, sizeof(*cache));
755 memset(cache->hash, 0xff, sizeof(cache->hash));
756 cache->record_size = record_size;
759 static void free_hda_cache(struct hda_cache_rec *cache)
761 kfree(cache->buffer);
764 /* query the hash. allocate an entry if not found. */
765 static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
768 u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
769 u16 cur = cache->hash[idx];
770 struct hda_cache_head *info;
772 while (cur != 0xffff) {
773 info = (struct hda_cache_head *)(cache->buffer +
774 cur * cache->record_size);
775 if (info->key == key)
780 /* add a new hash entry */
781 if (cache->num_entries >= cache->size) {
782 /* reallocate the array */
783 unsigned int new_size = cache->size + 64;
785 new_buffer = kcalloc(new_size, cache->record_size, GFP_KERNEL);
787 snd_printk(KERN_ERR "hda_codec: "
788 "can't malloc amp_info\n");
792 memcpy(new_buffer, cache->buffer,
793 cache->size * cache->record_size);
794 kfree(cache->buffer);
796 cache->size = new_size;
797 cache->buffer = new_buffer;
799 cur = cache->num_entries++;
800 info = (struct hda_cache_head *)(cache->buffer +
801 cur * cache->record_size);
804 info->next = cache->hash[idx];
805 cache->hash[idx] = cur;
810 /* query and allocate an amp hash entry */
811 static inline struct hda_amp_info *
812 get_alloc_amp_hash(struct hda_codec *codec, u32 key)
814 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
818 * query AMP capabilities for the given widget and direction
820 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
822 struct hda_amp_info *info;
824 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
827 if (!(info->head.val & INFO_AMP_CAPS)) {
828 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
830 info->amp_caps = snd_hda_param_read(codec, nid,
831 direction == HDA_OUTPUT ?
835 info->head.val |= INFO_AMP_CAPS;
837 return info->amp_caps;
840 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
843 struct hda_amp_info *info;
845 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0));
848 info->amp_caps = caps;
849 info->head.val |= INFO_AMP_CAPS;
854 * read the current volume to info
855 * if the cache exists, read the cache value.
857 static unsigned int get_vol_mute(struct hda_codec *codec,
858 struct hda_amp_info *info, hda_nid_t nid,
859 int ch, int direction, int index)
863 if (info->head.val & INFO_AMP_VOL(ch))
864 return info->vol[ch];
866 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
867 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
869 val = snd_hda_codec_read(codec, nid, 0,
870 AC_VERB_GET_AMP_GAIN_MUTE, parm);
871 info->vol[ch] = val & 0xff;
872 info->head.val |= INFO_AMP_VOL(ch);
873 return info->vol[ch];
877 * write the current volume in info to the h/w and update the cache
879 static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
880 hda_nid_t nid, int ch, int direction, int index,
885 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
886 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
887 parm |= index << AC_AMP_SET_INDEX_SHIFT;
889 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
894 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
896 int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
897 int direction, int index)
899 struct hda_amp_info *info;
900 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
903 return get_vol_mute(codec, info, nid, ch, direction, index);
907 * update the AMP value, mask = bit mask to set, val = the value
909 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
910 int direction, int idx, int mask, int val)
912 struct hda_amp_info *info;
914 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
918 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
919 if (info->vol[ch] == val)
921 put_vol_mute(codec, info, nid, ch, direction, idx, val);
926 * update the AMP stereo with the same mask and value
928 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
929 int direction, int idx, int mask, int val)
932 for (ch = 0; ch < 2; ch++)
933 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
938 #ifdef SND_HDA_NEEDS_RESUME
939 /* resume the all amp commands from the cache */
940 void snd_hda_codec_resume_amp(struct hda_codec *codec)
942 struct hda_amp_info *buffer = codec->amp_cache.buffer;
945 for (i = 0; i < codec->amp_cache.size; i++, buffer++) {
946 u32 key = buffer->head.key;
948 unsigned int idx, dir, ch;
952 idx = (key >> 16) & 0xff;
953 dir = (key >> 24) & 0xff;
954 for (ch = 0; ch < 2; ch++) {
955 if (!(buffer->head.val & INFO_AMP_VOL(ch)))
957 put_vol_mute(codec, buffer, nid, ch, dir, idx,
962 #endif /* SND_HDA_NEEDS_RESUME */
965 int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
966 struct snd_ctl_elem_info *uinfo)
968 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
969 u16 nid = get_amp_nid(kcontrol);
970 u8 chs = get_amp_channels(kcontrol);
971 int dir = get_amp_direction(kcontrol);
974 caps = query_amp_caps(codec, nid, dir);
976 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
978 printk(KERN_WARNING "hda_codec: "
979 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid,
983 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
984 uinfo->count = chs == 3 ? 2 : 1;
985 uinfo->value.integer.min = 0;
986 uinfo->value.integer.max = caps;
990 int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
991 struct snd_ctl_elem_value *ucontrol)
993 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
994 hda_nid_t nid = get_amp_nid(kcontrol);
995 int chs = get_amp_channels(kcontrol);
996 int dir = get_amp_direction(kcontrol);
997 int idx = get_amp_index(kcontrol);
998 long *valp = ucontrol->value.integer.value;
1001 *valp++ = snd_hda_codec_amp_read(codec, nid, 0, dir, idx)
1004 *valp = snd_hda_codec_amp_read(codec, nid, 1, dir, idx)
1009 int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1010 struct snd_ctl_elem_value *ucontrol)
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 hda_nid_t nid = get_amp_nid(kcontrol);
1014 int chs = get_amp_channels(kcontrol);
1015 int dir = get_amp_direction(kcontrol);
1016 int idx = get_amp_index(kcontrol);
1017 long *valp = ucontrol->value.integer.value;
1020 snd_hda_power_up(codec);
1022 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
1027 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
1029 snd_hda_power_down(codec);
1033 int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1034 unsigned int size, unsigned int __user *_tlv)
1036 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1037 hda_nid_t nid = get_amp_nid(kcontrol);
1038 int dir = get_amp_direction(kcontrol);
1039 u32 caps, val1, val2;
1041 if (size < 4 * sizeof(unsigned int))
1043 caps = query_amp_caps(codec, nid, dir);
1044 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1045 val2 = (val2 + 1) * 25;
1046 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1047 val1 = ((int)val1) * ((int)val2);
1048 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
1050 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
1052 if (put_user(val1, _tlv + 2))
1054 if (put_user(val2, _tlv + 3))
1060 * set (static) TLV for virtual master volume; recalculated as max 0dB
1062 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1068 caps = query_amp_caps(codec, nid, dir);
1069 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1070 step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1071 step = (step + 1) * 25;
1072 tlv[0] = SNDRV_CTL_TLVT_DB_SCALE;
1073 tlv[1] = 2 * sizeof(unsigned int);
1074 tlv[2] = -nums * step;
1078 /* find a mixer control element with the given name */
1079 static struct snd_kcontrol *
1080 _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1081 const char *name, int idx)
1083 struct snd_ctl_elem_id id;
1084 memset(&id, 0, sizeof(id));
1085 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1087 strcpy(id.name, name);
1088 return snd_ctl_find_id(codec->bus->card, &id);
1091 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1094 return _snd_hda_find_mixer_ctl(codec, name, 0);
1097 /* create a virtual master control and add slaves */
1098 int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1099 unsigned int *tlv, const char **slaves)
1101 struct snd_kcontrol *kctl;
1105 for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++)
1108 snd_printdd("No slave found for %s\n", name);
1111 kctl = snd_ctl_make_virtual_master(name, tlv);
1114 err = snd_ctl_add(codec->bus->card, kctl);
1118 for (s = slaves; *s; s++) {
1119 struct snd_kcontrol *sctl;
1121 sctl = snd_hda_find_mixer_ctl(codec, *s);
1123 snd_printdd("Cannot find slave %s, skipped\n", *s);
1126 err = snd_ctl_add_slave(kctl, sctl);
1134 int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1135 struct snd_ctl_elem_info *uinfo)
1137 int chs = get_amp_channels(kcontrol);
1139 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1140 uinfo->count = chs == 3 ? 2 : 1;
1141 uinfo->value.integer.min = 0;
1142 uinfo->value.integer.max = 1;
1146 int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1147 struct snd_ctl_elem_value *ucontrol)
1149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1150 hda_nid_t nid = get_amp_nid(kcontrol);
1151 int chs = get_amp_channels(kcontrol);
1152 int dir = get_amp_direction(kcontrol);
1153 int idx = get_amp_index(kcontrol);
1154 long *valp = ucontrol->value.integer.value;
1157 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
1158 HDA_AMP_MUTE) ? 0 : 1;
1160 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
1161 HDA_AMP_MUTE) ? 0 : 1;
1165 int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1166 struct snd_ctl_elem_value *ucontrol)
1168 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1169 hda_nid_t nid = get_amp_nid(kcontrol);
1170 int chs = get_amp_channels(kcontrol);
1171 int dir = get_amp_direction(kcontrol);
1172 int idx = get_amp_index(kcontrol);
1173 long *valp = ucontrol->value.integer.value;
1176 snd_hda_power_up(codec);
1178 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
1180 *valp ? 0 : HDA_AMP_MUTE);
1184 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
1186 *valp ? 0 : HDA_AMP_MUTE);
1187 #ifdef CONFIG_SND_HDA_POWER_SAVE
1188 if (codec->patch_ops.check_power_status)
1189 codec->patch_ops.check_power_status(codec, nid);
1191 snd_hda_power_down(codec);
1196 * bound volume controls
1198 * bind multiple volumes (# indices, from 0)
1201 #define AMP_VAL_IDX_SHIFT 19
1202 #define AMP_VAL_IDX_MASK (0x0f<<19)
1204 int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1205 struct snd_ctl_elem_value *ucontrol)
1207 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1211 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1212 pval = kcontrol->private_value;
1213 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
1214 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
1215 kcontrol->private_value = pval;
1216 mutex_unlock(&codec->spdif_mutex);
1220 int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1221 struct snd_ctl_elem_value *ucontrol)
1223 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1225 int i, indices, err = 0, change = 0;
1227 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1228 pval = kcontrol->private_value;
1229 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
1230 for (i = 0; i < indices; i++) {
1231 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
1232 (i << AMP_VAL_IDX_SHIFT);
1233 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
1238 kcontrol->private_value = pval;
1239 mutex_unlock(&codec->spdif_mutex);
1240 return err < 0 ? err : change;
1244 * generic bound volume/swtich controls
1246 int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1247 struct snd_ctl_elem_info *uinfo)
1249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1250 struct hda_bind_ctls *c;
1253 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1254 c = (struct hda_bind_ctls *)kcontrol->private_value;
1255 kcontrol->private_value = *c->values;
1256 err = c->ops->info(kcontrol, uinfo);
1257 kcontrol->private_value = (long)c;
1258 mutex_unlock(&codec->spdif_mutex);
1262 int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1263 struct snd_ctl_elem_value *ucontrol)
1265 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1266 struct hda_bind_ctls *c;
1269 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1270 c = (struct hda_bind_ctls *)kcontrol->private_value;
1271 kcontrol->private_value = *c->values;
1272 err = c->ops->get(kcontrol, ucontrol);
1273 kcontrol->private_value = (long)c;
1274 mutex_unlock(&codec->spdif_mutex);
1278 int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1279 struct snd_ctl_elem_value *ucontrol)
1281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1282 struct hda_bind_ctls *c;
1283 unsigned long *vals;
1284 int err = 0, change = 0;
1286 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1287 c = (struct hda_bind_ctls *)kcontrol->private_value;
1288 for (vals = c->values; *vals; vals++) {
1289 kcontrol->private_value = *vals;
1290 err = c->ops->put(kcontrol, ucontrol);
1295 kcontrol->private_value = (long)c;
1296 mutex_unlock(&codec->spdif_mutex);
1297 return err < 0 ? err : change;
1300 int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1301 unsigned int size, unsigned int __user *tlv)
1303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1304 struct hda_bind_ctls *c;
1307 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1308 c = (struct hda_bind_ctls *)kcontrol->private_value;
1309 kcontrol->private_value = *c->values;
1310 err = c->ops->tlv(kcontrol, op_flag, size, tlv);
1311 kcontrol->private_value = (long)c;
1312 mutex_unlock(&codec->spdif_mutex);
1316 struct hda_ctl_ops snd_hda_bind_vol = {
1317 .info = snd_hda_mixer_amp_volume_info,
1318 .get = snd_hda_mixer_amp_volume_get,
1319 .put = snd_hda_mixer_amp_volume_put,
1320 .tlv = snd_hda_mixer_amp_tlv
1323 struct hda_ctl_ops snd_hda_bind_sw = {
1324 .info = snd_hda_mixer_amp_switch_info,
1325 .get = snd_hda_mixer_amp_switch_get,
1326 .put = snd_hda_mixer_amp_switch_put,
1327 .tlv = snd_hda_mixer_amp_tlv
1331 * SPDIF out controls
1334 static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
1335 struct snd_ctl_elem_info *uinfo)
1337 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1342 static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
1343 struct snd_ctl_elem_value *ucontrol)
1345 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
1346 IEC958_AES0_NONAUDIO |
1347 IEC958_AES0_CON_EMPHASIS_5015 |
1348 IEC958_AES0_CON_NOT_COPYRIGHT;
1349 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
1350 IEC958_AES1_CON_ORIGINAL;
1354 static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
1355 struct snd_ctl_elem_value *ucontrol)
1357 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
1358 IEC958_AES0_NONAUDIO |
1359 IEC958_AES0_PRO_EMPHASIS_5015;
1363 static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
1364 struct snd_ctl_elem_value *ucontrol)
1366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1368 ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff;
1369 ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff;
1370 ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff;
1371 ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff;
1376 /* convert from SPDIF status bits to HDA SPDIF bits
1377 * bit 0 (DigEn) is always set zero (to be filled later)
1379 static unsigned short convert_from_spdif_status(unsigned int sbits)
1381 unsigned short val = 0;
1383 if (sbits & IEC958_AES0_PROFESSIONAL)
1384 val |= AC_DIG1_PROFESSIONAL;
1385 if (sbits & IEC958_AES0_NONAUDIO)
1386 val |= AC_DIG1_NONAUDIO;
1387 if (sbits & IEC958_AES0_PROFESSIONAL) {
1388 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
1389 IEC958_AES0_PRO_EMPHASIS_5015)
1390 val |= AC_DIG1_EMPHASIS;
1392 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
1393 IEC958_AES0_CON_EMPHASIS_5015)
1394 val |= AC_DIG1_EMPHASIS;
1395 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
1396 val |= AC_DIG1_COPYRIGHT;
1397 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
1398 val |= AC_DIG1_LEVEL;
1399 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
1404 /* convert to SPDIF status bits from HDA SPDIF bits
1406 static unsigned int convert_to_spdif_status(unsigned short val)
1408 unsigned int sbits = 0;
1410 if (val & AC_DIG1_NONAUDIO)
1411 sbits |= IEC958_AES0_NONAUDIO;
1412 if (val & AC_DIG1_PROFESSIONAL)
1413 sbits |= IEC958_AES0_PROFESSIONAL;
1414 if (sbits & IEC958_AES0_PROFESSIONAL) {
1415 if (sbits & AC_DIG1_EMPHASIS)
1416 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
1418 if (val & AC_DIG1_EMPHASIS)
1419 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
1420 if (!(val & AC_DIG1_COPYRIGHT))
1421 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
1422 if (val & AC_DIG1_LEVEL)
1423 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
1424 sbits |= val & (0x7f << 8);
1429 static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
1430 struct snd_ctl_elem_value *ucontrol)
1432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1433 hda_nid_t nid = kcontrol->private_value;
1437 mutex_lock(&codec->spdif_mutex);
1438 codec->spdif_status = ucontrol->value.iec958.status[0] |
1439 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
1440 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
1441 ((unsigned int)ucontrol->value.iec958.status[3] << 24);
1442 val = convert_from_spdif_status(codec->spdif_status);
1443 val |= codec->spdif_ctls & 1;
1444 change = codec->spdif_ctls != val;
1445 codec->spdif_ctls = val;
1449 snd_hda_codec_write_cache(codec, nid, 0,
1450 AC_VERB_SET_DIGI_CONVERT_1,
1452 snd_hda_codec_write_cache(codec, nid, 0,
1453 AC_VERB_SET_DIGI_CONVERT_2,
1456 if (codec->slave_dig_outs)
1457 for (d = codec->slave_dig_outs; *d; d++) {
1458 snd_hda_codec_write_cache(codec, *d, 0,
1459 AC_VERB_SET_DIGI_CONVERT_1,
1461 snd_hda_codec_write_cache(codec, *d, 0,
1462 AC_VERB_SET_DIGI_CONVERT_2,
1467 mutex_unlock(&codec->spdif_mutex);
1471 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
1473 static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
1474 struct snd_ctl_elem_value *ucontrol)
1476 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1478 ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE;
1482 static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
1483 struct snd_ctl_elem_value *ucontrol)
1485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1486 hda_nid_t nid = kcontrol->private_value;
1490 mutex_lock(&codec->spdif_mutex);
1491 val = codec->spdif_ctls & ~AC_DIG1_ENABLE;
1492 if (ucontrol->value.integer.value[0])
1493 val |= AC_DIG1_ENABLE;
1494 change = codec->spdif_ctls != val;
1497 codec->spdif_ctls = val;
1498 snd_hda_codec_write_cache(codec, nid, 0,
1499 AC_VERB_SET_DIGI_CONVERT_1,
1502 if (codec->slave_dig_outs)
1503 for (d = codec->slave_dig_outs; *d; d++)
1504 snd_hda_codec_write_cache(codec, *d, 0,
1505 AC_VERB_SET_DIGI_CONVERT_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;
1656 codec->spdif_in_enable = val;
1657 snd_hda_codec_write_cache(codec, nid, 0,
1658 AC_VERB_SET_DIGI_CONVERT_1, val);
1660 if (codec->slave_dig_outs)
1661 for (d = codec->slave_dig_outs; *d; d++)
1662 snd_hda_codec_write_cache(codec, *d, 0,
1663 AC_VERB_SET_DIGI_CONVERT_1, val);
1665 mutex_unlock(&codec->spdif_mutex);
1669 static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
1672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1673 hda_nid_t nid = kcontrol->private_value;
1677 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
1678 sbits = convert_to_spdif_status(val);
1679 ucontrol->value.iec958.status[0] = sbits;
1680 ucontrol->value.iec958.status[1] = sbits >> 8;
1681 ucontrol->value.iec958.status[2] = sbits >> 16;
1682 ucontrol->value.iec958.status[3] = sbits >> 24;
1686 static struct snd_kcontrol_new dig_in_ctls[] = {
1688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH),
1690 .info = snd_hda_spdif_in_switch_info,
1691 .get = snd_hda_spdif_in_switch_get,
1692 .put = snd_hda_spdif_in_switch_put,
1695 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1697 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
1698 .info = snd_hda_spdif_mask_info,
1699 .get = snd_hda_spdif_in_status_get,
1705 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
1706 * @codec: the HDA codec
1707 * @nid: audio in widget NID
1709 * Creates controls related with the SPDIF input.
1710 * Called from each patch supporting the SPDIF in.
1712 * Returns 0 if successful, or a negative error code.
1714 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1717 struct snd_kcontrol *kctl;
1718 struct snd_kcontrol_new *dig_mix;
1721 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1722 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
1726 if (idx >= SPDIF_MAX_IDX) {
1727 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
1730 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1731 kctl = snd_ctl_new1(dig_mix, codec);
1732 kctl->private_value = nid;
1733 err = snd_ctl_add(codec->bus->card, kctl);
1737 codec->spdif_in_enable =
1738 snd_hda_codec_read(codec, nid, 0,
1739 AC_VERB_GET_DIGI_CONVERT_1, 0) &
1744 #ifdef SND_HDA_NEEDS_RESUME
1749 /* build a 32bit cache key with the widget id and the command parameter */
1750 #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
1751 #define get_cmd_cache_nid(key) ((key) & 0xff)
1752 #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
1755 * snd_hda_codec_write_cache - send a single command with caching
1756 * @codec: the HDA codec
1757 * @nid: NID to send the command
1758 * @direct: direct flag
1759 * @verb: the verb to send
1760 * @parm: the parameter for the verb
1762 * Send a single command without waiting for response.
1764 * Returns 0 if successful, or a negative error code.
1766 int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1767 int direct, unsigned int verb, unsigned int parm)
1770 snd_hda_power_up(codec);
1771 mutex_lock(&codec->bus->cmd_mutex);
1772 err = codec->bus->ops.command(codec, nid, direct, verb, parm);
1774 struct hda_cache_head *c;
1775 u32 key = build_cmd_cache_key(nid, verb);
1776 c = get_alloc_hash(&codec->cmd_cache, key);
1780 mutex_unlock(&codec->bus->cmd_mutex);
1781 snd_hda_power_down(codec);
1785 /* resume the all commands from the cache */
1786 void snd_hda_codec_resume_cache(struct hda_codec *codec)
1788 struct hda_cache_head *buffer = codec->cmd_cache.buffer;
1791 for (i = 0; i < codec->cmd_cache.size; i++, buffer++) {
1792 u32 key = buffer->key;
1795 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
1796 get_cmd_cache_cmd(key), buffer->val);
1801 * snd_hda_sequence_write_cache - sequence writes with caching
1802 * @codec: the HDA codec
1803 * @seq: VERB array to send
1805 * Send the commands sequentially from the given array.
1806 * Thte commands are recorded on cache for power-save and resume.
1807 * The array must be terminated with NID=0.
1809 void snd_hda_sequence_write_cache(struct hda_codec *codec,
1810 const struct hda_verb *seq)
1812 for (; seq->nid; seq++)
1813 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
1816 #endif /* SND_HDA_NEEDS_RESUME */
1819 * set power state of the codec
1821 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1822 unsigned int power_state)
1827 snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_POWER_STATE,
1829 msleep(10); /* partial workaround for "azx_get_response timeout" */
1831 nid = codec->start_nid;
1832 for (i = 0; i < codec->num_nodes; i++, nid++) {
1833 unsigned int wcaps = get_wcaps(codec, nid);
1834 if (wcaps & AC_WCAP_POWER) {
1835 unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >>
1837 if (wid_type == AC_WID_PIN) {
1838 unsigned int pincap;
1840 * don't power down the widget if it controls
1841 * eapd and EAPD_BTLENABLE is set.
1843 pincap = snd_hda_param_read(codec, nid,
1845 if (pincap & AC_PINCAP_EAPD) {
1846 int eapd = snd_hda_codec_read(codec,
1848 AC_VERB_GET_EAPD_BTLENABLE, 0);
1850 if (power_state == AC_PWRST_D3 && eapd)
1854 snd_hda_codec_write(codec, nid, 0,
1855 AC_VERB_SET_POWER_STATE,
1860 if (power_state == AC_PWRST_D0) {
1861 unsigned long end_time;
1864 /* wait until the codec reachs to D0 */
1865 end_time = jiffies + msecs_to_jiffies(500);
1867 state = snd_hda_codec_read(codec, fg, 0,
1868 AC_VERB_GET_POWER_STATE, 0);
1869 if (state == power_state)
1872 } while (time_after_eq(end_time, jiffies));
1876 #ifdef SND_HDA_NEEDS_RESUME
1878 * call suspend and power-down; used both from PM and power-save
1880 static void hda_call_codec_suspend(struct hda_codec *codec)
1882 if (codec->patch_ops.suspend)
1883 codec->patch_ops.suspend(codec, PMSG_SUSPEND);
1884 hda_set_power_state(codec,
1885 codec->afg ? codec->afg : codec->mfg,
1887 #ifdef CONFIG_SND_HDA_POWER_SAVE
1888 cancel_delayed_work(&codec->power_work);
1889 codec->power_on = 0;
1890 codec->power_transition = 0;
1895 * kick up codec; used both from PM and power-save
1897 static void hda_call_codec_resume(struct hda_codec *codec)
1899 hda_set_power_state(codec,
1900 codec->afg ? codec->afg : codec->mfg,
1902 if (codec->patch_ops.resume)
1903 codec->patch_ops.resume(codec);
1905 if (codec->patch_ops.init)
1906 codec->patch_ops.init(codec);
1907 snd_hda_codec_resume_amp(codec);
1908 snd_hda_codec_resume_cache(codec);
1911 #endif /* SND_HDA_NEEDS_RESUME */
1915 * snd_hda_build_controls - build mixer controls
1918 * Creates mixer controls for each codec included in the bus.
1920 * Returns 0 if successful, otherwise a negative error code.
1922 int __devinit snd_hda_build_controls(struct hda_bus *bus)
1924 struct hda_codec *codec;
1926 list_for_each_entry(codec, &bus->codec_list, list) {
1928 /* fake as if already powered-on */
1929 hda_keep_power_on(codec);
1931 hda_set_power_state(codec,
1932 codec->afg ? codec->afg : codec->mfg,
1934 /* continue to initialize... */
1935 if (codec->patch_ops.init)
1936 err = codec->patch_ops.init(codec);
1937 if (!err && codec->patch_ops.build_controls)
1938 err = codec->patch_ops.build_controls(codec);
1939 snd_hda_power_down(codec);
1950 struct hda_rate_tbl {
1952 unsigned int alsa_bits;
1953 unsigned int hda_fmt;
1956 static struct hda_rate_tbl rate_bits[] = {
1957 /* rate in Hz, ALSA rate bitmask, HDA format value */
1959 /* autodetected value used in snd_hda_query_supported_pcm */
1960 { 8000, SNDRV_PCM_RATE_8000, 0x0500 }, /* 1/6 x 48 */
1961 { 11025, SNDRV_PCM_RATE_11025, 0x4300 }, /* 1/4 x 44 */
1962 { 16000, SNDRV_PCM_RATE_16000, 0x0200 }, /* 1/3 x 48 */
1963 { 22050, SNDRV_PCM_RATE_22050, 0x4100 }, /* 1/2 x 44 */
1964 { 32000, SNDRV_PCM_RATE_32000, 0x0a00 }, /* 2/3 x 48 */
1965 { 44100, SNDRV_PCM_RATE_44100, 0x4000 }, /* 44 */
1966 { 48000, SNDRV_PCM_RATE_48000, 0x0000 }, /* 48 */
1967 { 88200, SNDRV_PCM_RATE_88200, 0x4800 }, /* 2 x 44 */
1968 { 96000, SNDRV_PCM_RATE_96000, 0x0800 }, /* 2 x 48 */
1969 { 176400, SNDRV_PCM_RATE_176400, 0x5800 },/* 4 x 44 */
1970 { 192000, SNDRV_PCM_RATE_192000, 0x1800 }, /* 4 x 48 */
1971 #define AC_PAR_PCM_RATE_BITS 11
1972 /* up to bits 10, 384kHZ isn't supported properly */
1974 /* not autodetected value */
1975 { 9600, SNDRV_PCM_RATE_KNOT, 0x0400 }, /* 1/5 x 48 */
1977 { 0 } /* terminator */
1981 * snd_hda_calc_stream_format - calculate format bitset
1982 * @rate: the sample rate
1983 * @channels: the number of channels
1984 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
1985 * @maxbps: the max. bps
1987 * Calculate the format bitset from the given rate, channels and th PCM format.
1989 * Return zero if invalid.
1991 unsigned int snd_hda_calc_stream_format(unsigned int rate,
1992 unsigned int channels,
1993 unsigned int format,
1994 unsigned int maxbps)
1997 unsigned int val = 0;
1999 for (i = 0; rate_bits[i].hz; i++)
2000 if (rate_bits[i].hz == rate) {
2001 val = rate_bits[i].hda_fmt;
2004 if (!rate_bits[i].hz) {
2005 snd_printdd("invalid rate %d\n", rate);
2009 if (channels == 0 || channels > 8) {
2010 snd_printdd("invalid channels %d\n", channels);
2013 val |= channels - 1;
2015 switch (snd_pcm_format_width(format)) {
2016 case 8: val |= 0x00; break;
2017 case 16: val |= 0x10; break;
2023 else if (maxbps >= 24)
2029 snd_printdd("invalid format width %d\n",
2030 snd_pcm_format_width(format));
2038 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
2039 * @codec: the HDA codec
2040 * @nid: NID to query
2041 * @ratesp: the pointer to store the detected rate bitflags
2042 * @formatsp: the pointer to store the detected formats
2043 * @bpsp: the pointer to store the detected format widths
2045 * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp
2046 * or @bsps argument is ignored.
2048 * Returns 0 if successful, otherwise a negative error code.
2050 int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2051 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
2054 unsigned int val, streams;
2057 if (nid != codec->afg &&
2058 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
2059 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
2064 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
2068 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) {
2070 rates |= rate_bits[i].alsa_bits;
2075 if (formatsp || bpsp) {
2080 wcaps = get_wcaps(codec, nid);
2081 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
2085 streams = snd_hda_param_read(codec, codec->afg,
2092 if (streams & AC_SUPFMT_PCM) {
2093 if (val & AC_SUPPCM_BITS_8) {
2094 formats |= SNDRV_PCM_FMTBIT_U8;
2097 if (val & AC_SUPPCM_BITS_16) {
2098 formats |= SNDRV_PCM_FMTBIT_S16_LE;
2101 if (wcaps & AC_WCAP_DIGITAL) {
2102 if (val & AC_SUPPCM_BITS_32)
2103 formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
2104 if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24))
2105 formats |= SNDRV_PCM_FMTBIT_S32_LE;
2106 if (val & AC_SUPPCM_BITS_24)
2108 else if (val & AC_SUPPCM_BITS_20)
2110 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|
2111 AC_SUPPCM_BITS_32)) {
2112 formats |= SNDRV_PCM_FMTBIT_S32_LE;
2113 if (val & AC_SUPPCM_BITS_32)
2115 else if (val & AC_SUPPCM_BITS_24)
2117 else if (val & AC_SUPPCM_BITS_20)
2121 else if (streams == AC_SUPFMT_FLOAT32) {
2122 /* should be exclusive */
2123 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
2125 } else if (streams == AC_SUPFMT_AC3) {
2126 /* should be exclusive */
2127 /* temporary hack: we have still no proper support
2128 * for the direct AC3 stream...
2130 formats |= SNDRV_PCM_FMTBIT_U8;
2134 *formatsp = formats;
2143 * snd_hda_is_supported_format - check whether the given node supports
2146 * Returns 1 if supported, 0 if not.
2148 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
2149 unsigned int format)
2152 unsigned int val = 0, rate, stream;
2154 if (nid != codec->afg &&
2155 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) {
2156 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
2161 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
2166 rate = format & 0xff00;
2167 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++)
2168 if (rate_bits[i].hda_fmt == rate) {
2173 if (i >= AC_PAR_PCM_RATE_BITS)
2176 stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
2179 if (!stream && nid != codec->afg)
2180 stream = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
2181 if (!stream || stream == -1)
2184 if (stream & AC_SUPFMT_PCM) {
2185 switch (format & 0xf0) {
2187 if (!(val & AC_SUPPCM_BITS_8))
2191 if (!(val & AC_SUPPCM_BITS_16))
2195 if (!(val & AC_SUPPCM_BITS_20))
2199 if (!(val & AC_SUPPCM_BITS_24))
2203 if (!(val & AC_SUPPCM_BITS_32))
2210 /* FIXME: check for float32 and AC3? */
2219 static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
2220 struct hda_codec *codec,
2221 struct snd_pcm_substream *substream)
2226 static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
2227 struct hda_codec *codec,
2228 unsigned int stream_tag,
2229 unsigned int format,
2230 struct snd_pcm_substream *substream)
2232 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
2236 static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2237 struct hda_codec *codec,
2238 struct snd_pcm_substream *substream)
2240 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2244 static int __devinit set_pcm_default_values(struct hda_codec *codec,
2245 struct hda_pcm_stream *info)
2247 /* query support PCM information from the given NID */
2248 if (info->nid && (!info->rates || !info->formats)) {
2249 snd_hda_query_supported_pcm(codec, info->nid,
2250 info->rates ? NULL : &info->rates,
2251 info->formats ? NULL : &info->formats,
2252 info->maxbps ? NULL : &info->maxbps);
2254 if (info->ops.open == NULL)
2255 info->ops.open = hda_pcm_default_open_close;
2256 if (info->ops.close == NULL)
2257 info->ops.close = hda_pcm_default_open_close;
2258 if (info->ops.prepare == NULL) {
2259 if (snd_BUG_ON(!info->nid))
2261 info->ops.prepare = hda_pcm_default_prepare;
2263 if (info->ops.cleanup == NULL) {
2264 if (snd_BUG_ON(!info->nid))
2266 info->ops.cleanup = hda_pcm_default_cleanup;
2272 * snd_hda_build_pcms - build PCM information
2275 * Create PCM information for each codec included in the bus.
2277 * The build_pcms codec patch is requested to set up codec->num_pcms and
2278 * codec->pcm_info properly. The array is referred by the top-level driver
2279 * to create its PCM instances.
2280 * The allocated codec->pcm_info should be released in codec->patch_ops.free
2283 * At least, substreams, channels_min and channels_max must be filled for
2284 * each stream. substreams = 0 indicates that the stream doesn't exist.
2285 * When rates and/or formats are zero, the supported values are queried
2286 * from the given nid. The nid is used also by the default ops.prepare
2287 * and ops.cleanup callbacks.
2289 * The driver needs to call ops.open in its open callback. Similarly,
2290 * ops.close is supposed to be called in the close callback.
2291 * ops.prepare should be called in the prepare or hw_params callback
2292 * with the proper parameters for set up.
2293 * ops.cleanup should be called in hw_free for clean up of streams.
2295 * This function returns 0 if successfull, or a negative error code.
2297 int __devinit snd_hda_build_pcms(struct hda_bus *bus)
2299 struct hda_codec *codec;
2301 list_for_each_entry(codec, &bus->codec_list, list) {
2302 unsigned int pcm, s;
2304 if (!codec->patch_ops.build_pcms)
2306 err = codec->patch_ops.build_pcms(codec);
2309 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2310 for (s = 0; s < 2; s++) {
2311 struct hda_pcm_stream *info;
2312 info = &codec->pcm_info[pcm].stream[s];
2313 if (!info->substreams)
2315 err = set_pcm_default_values(codec, info);
2325 * snd_hda_check_board_config - compare the current codec with the config table
2326 * @codec: the HDA codec
2327 * @num_configs: number of config enums
2328 * @models: array of model name strings
2329 * @tbl: configuration table, terminated by null entries
2331 * Compares the modelname or PCI subsystem id of the current codec with the
2332 * given configuration table. If a matching entry is found, returns its
2333 * config value (supposed to be 0 or positive).
2335 * If no entries are matching, the function returns a negative value.
2337 int snd_hda_check_board_config(struct hda_codec *codec,
2338 int num_configs, const char **models,
2339 const struct snd_pci_quirk *tbl)
2341 if (codec->bus->modelname && models) {
2343 for (i = 0; i < num_configs; i++) {
2345 !strcmp(codec->bus->modelname, models[i])) {
2346 snd_printd(KERN_INFO "hda_codec: model '%s' is "
2347 "selected\n", models[i]);
2353 if (!codec->bus->pci || !tbl)
2356 tbl = snd_pci_quirk_lookup(codec->bus->pci, tbl);
2359 if (tbl->value >= 0 && tbl->value < num_configs) {
2360 #ifdef CONFIG_SND_DEBUG_VERBOSE
2362 const char *model = NULL;
2364 model = models[tbl->value];
2366 sprintf(tmp, "#%d", tbl->value);
2369 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
2370 "for config %x:%x (%s)\n",
2371 model, tbl->subvendor, tbl->subdevice,
2372 (tbl->name ? tbl->name : "Unknown device"));
2380 * snd_hda_add_new_ctls - create controls from the array
2381 * @codec: the HDA codec
2382 * @knew: the array of struct snd_kcontrol_new
2384 * This helper function creates and add new controls in the given array.
2385 * The array must be terminated with an empty entry as terminator.
2387 * Returns 0 if successful, or a negative error code.
2389 int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2393 for (; knew->name; knew++) {
2394 struct snd_kcontrol *kctl;
2395 kctl = snd_ctl_new1(knew, codec);
2398 err = snd_ctl_add(codec->bus->card, kctl);
2402 kctl = snd_ctl_new1(knew, codec);
2405 kctl->id.device = codec->addr;
2406 err = snd_ctl_add(codec->bus->card, kctl);
2414 #ifdef CONFIG_SND_HDA_POWER_SAVE
2415 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2416 unsigned int power_state);
2418 static void hda_power_work(struct work_struct *work)
2420 struct hda_codec *codec =
2421 container_of(work, struct hda_codec, power_work.work);
2423 if (!codec->power_on || codec->power_count) {
2424 codec->power_transition = 0;
2428 hda_call_codec_suspend(codec);
2429 if (codec->bus->ops.pm_notify)
2430 codec->bus->ops.pm_notify(codec);
2433 static void hda_keep_power_on(struct hda_codec *codec)
2435 codec->power_count++;
2436 codec->power_on = 1;
2439 void snd_hda_power_up(struct hda_codec *codec)
2441 codec->power_count++;
2442 if (codec->power_on || codec->power_transition)
2445 codec->power_on = 1;
2446 if (codec->bus->ops.pm_notify)
2447 codec->bus->ops.pm_notify(codec);
2448 hda_call_codec_resume(codec);
2449 cancel_delayed_work(&codec->power_work);
2450 codec->power_transition = 0;
2453 void snd_hda_power_down(struct hda_codec *codec)
2455 --codec->power_count;
2456 if (!codec->power_on || codec->power_count || codec->power_transition)
2459 codec->power_transition = 1; /* avoid reentrance */
2460 schedule_delayed_work(&codec->power_work,
2461 msecs_to_jiffies(power_save * 1000));
2465 int snd_hda_check_amp_list_power(struct hda_codec *codec,
2466 struct hda_loopback_check *check,
2469 struct hda_amp_list *p;
2472 if (!check->amplist)
2474 for (p = check->amplist; p->nid; p++) {
2479 return 0; /* nothing changed */
2481 for (p = check->amplist; p->nid; p++) {
2482 for (ch = 0; ch < 2; ch++) {
2483 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
2485 if (!(v & HDA_AMP_MUTE) && v > 0) {
2486 if (!check->power_on) {
2487 check->power_on = 1;
2488 snd_hda_power_up(codec);
2494 if (check->power_on) {
2495 check->power_on = 0;
2496 snd_hda_power_down(codec);
2503 * Channel mode helper
2505 int snd_hda_ch_mode_info(struct hda_codec *codec,
2506 struct snd_ctl_elem_info *uinfo,
2507 const struct hda_channel_mode *chmode,
2510 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2512 uinfo->value.enumerated.items = num_chmodes;
2513 if (uinfo->value.enumerated.item >= num_chmodes)
2514 uinfo->value.enumerated.item = num_chmodes - 1;
2515 sprintf(uinfo->value.enumerated.name, "%dch",
2516 chmode[uinfo->value.enumerated.item].channels);
2520 int snd_hda_ch_mode_get(struct hda_codec *codec,
2521 struct snd_ctl_elem_value *ucontrol,
2522 const struct hda_channel_mode *chmode,
2528 for (i = 0; i < num_chmodes; i++) {
2529 if (max_channels == chmode[i].channels) {
2530 ucontrol->value.enumerated.item[0] = i;
2537 int snd_hda_ch_mode_put(struct hda_codec *codec,
2538 struct snd_ctl_elem_value *ucontrol,
2539 const struct hda_channel_mode *chmode,
2545 mode = ucontrol->value.enumerated.item[0];
2546 if (mode >= num_chmodes)
2548 if (*max_channelsp == chmode[mode].channels)
2550 /* change the current channel setting */
2551 *max_channelsp = chmode[mode].channels;
2552 if (chmode[mode].sequence)
2553 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
2560 int snd_hda_input_mux_info(const struct hda_input_mux *imux,
2561 struct snd_ctl_elem_info *uinfo)
2565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2567 uinfo->value.enumerated.items = imux->num_items;
2568 if (!imux->num_items)
2570 index = uinfo->value.enumerated.item;
2571 if (index >= imux->num_items)
2572 index = imux->num_items - 1;
2573 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
2577 int snd_hda_input_mux_put(struct hda_codec *codec,
2578 const struct hda_input_mux *imux,
2579 struct snd_ctl_elem_value *ucontrol,
2581 unsigned int *cur_val)
2585 if (!imux->num_items)
2587 idx = ucontrol->value.enumerated.item[0];
2588 if (idx >= imux->num_items)
2589 idx = imux->num_items - 1;
2590 if (*cur_val == idx)
2592 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
2593 imux->items[idx].index);
2600 * Multi-channel / digital-out PCM helper functions
2603 /* setup SPDIF output stream */
2604 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
2605 unsigned int stream_tag, unsigned int format)
2609 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2610 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) {
2611 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
2612 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
2614 if (codec->slave_dig_outs)
2615 for (d = codec->slave_dig_outs; *d; d++)
2616 snd_hda_codec_write(codec, *d, 0,
2617 AC_VERB_SET_DIGI_CONVERT_1,
2618 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
2620 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2621 /* turn on again (if needed) */
2622 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) {
2623 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
2624 codec->spdif_ctls & 0xff);
2626 if (codec->slave_dig_outs)
2627 for (d = codec->slave_dig_outs; *d; d++)
2628 snd_hda_codec_write(codec, *d, 0,
2629 AC_VERB_SET_DIGI_CONVERT_1,
2630 codec->spdif_ctls & 0xff);
2636 * open the digital out in the exclusive mode
2638 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2639 struct hda_multi_out *mout)
2641 mutex_lock(&codec->spdif_mutex);
2642 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2643 /* already opened as analog dup; reset it once */
2644 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2645 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2646 mutex_unlock(&codec->spdif_mutex);
2650 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2651 struct hda_multi_out *mout,
2652 unsigned int stream_tag,
2653 unsigned int format,
2654 struct snd_pcm_substream *substream)
2657 mutex_lock(&codec->spdif_mutex);
2658 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
2659 if (codec->slave_dig_outs)
2660 for (nid = codec->slave_dig_outs; *nid; nid++)
2661 setup_dig_out_stream(codec, *nid, stream_tag, format);
2662 mutex_unlock(&codec->spdif_mutex);
2667 * release the digital out
2669 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2670 struct hda_multi_out *mout)
2672 mutex_lock(&codec->spdif_mutex);
2673 mout->dig_out_used = 0;
2674 mutex_unlock(&codec->spdif_mutex);
2679 * set up more restrictions for analog out
2681 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2682 struct hda_multi_out *mout,
2683 struct snd_pcm_substream *substream,
2684 struct hda_pcm_stream *hinfo)
2686 struct snd_pcm_runtime *runtime = substream->runtime;
2687 runtime->hw.channels_max = mout->max_channels;
2688 if (mout->dig_out_nid) {
2689 if (!mout->analog_rates) {
2690 mout->analog_rates = hinfo->rates;
2691 mout->analog_formats = hinfo->formats;
2692 mout->analog_maxbps = hinfo->maxbps;
2694 runtime->hw.rates = mout->analog_rates;
2695 runtime->hw.formats = mout->analog_formats;
2696 hinfo->maxbps = mout->analog_maxbps;
2698 if (!mout->spdif_rates) {
2699 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
2701 &mout->spdif_formats,
2702 &mout->spdif_maxbps);
2704 mutex_lock(&codec->spdif_mutex);
2705 if (mout->share_spdif) {
2706 runtime->hw.rates &= mout->spdif_rates;
2707 runtime->hw.formats &= mout->spdif_formats;
2708 if (mout->spdif_maxbps < hinfo->maxbps)
2709 hinfo->maxbps = mout->spdif_maxbps;
2711 mutex_unlock(&codec->spdif_mutex);
2713 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2714 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2718 * set up the i/o for analog out
2719 * when the digital out is available, copy the front out to digital out, too.
2721 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2722 struct hda_multi_out *mout,
2723 unsigned int stream_tag,
2724 unsigned int format,
2725 struct snd_pcm_substream *substream)
2727 hda_nid_t *nids = mout->dac_nids;
2729 int chs = substream->runtime->channels;
2732 mutex_lock(&codec->spdif_mutex);
2733 if (mout->dig_out_nid && mout->share_spdif &&
2734 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
2736 snd_hda_is_supported_format(codec, mout->dig_out_nid,
2738 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
2739 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
2740 setup_dig_out_stream(codec, mout->dig_out_nid,
2741 stream_tag, format);
2742 if (codec->slave_dig_outs)
2743 for (d = codec->slave_dig_outs; *d; d++)
2744 setup_dig_out_stream(codec, *d,
2745 stream_tag, format);
2747 mout->dig_out_used = 0;
2748 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2749 if (codec->slave_dig_outs)
2750 for (d = codec->slave_dig_outs; *d; d++)
2751 snd_hda_codec_cleanup_stream(codec, *d);
2754 mutex_unlock(&codec->spdif_mutex);
2757 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
2759 if (!mout->no_share_stream &&
2760 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
2761 /* headphone out will just decode front left/right (stereo) */
2762 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
2764 /* extra outputs copied from front */
2765 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2766 if (!mout->no_share_stream && mout->extra_out_nid[i])
2767 snd_hda_codec_setup_stream(codec,
2768 mout->extra_out_nid[i],
2769 stream_tag, 0, format);
2772 for (i = 1; i < mout->num_dacs; i++) {
2773 if (chs >= (i + 1) * 2) /* independent out */
2774 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
2776 else if (!mout->no_share_stream) /* copy front */
2777 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
2784 * clean up the setting for analog out
2786 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2787 struct hda_multi_out *mout)
2789 hda_nid_t *nids = mout->dac_nids;
2792 for (i = 0; i < mout->num_dacs; i++)
2793 snd_hda_codec_cleanup_stream(codec, nids[i]);
2795 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
2796 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2797 if (mout->extra_out_nid[i])
2798 snd_hda_codec_cleanup_stream(codec,
2799 mout->extra_out_nid[i]);
2800 mutex_lock(&codec->spdif_mutex);
2801 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2802 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2803 mout->dig_out_used = 0;
2805 mutex_unlock(&codec->spdif_mutex);
2810 * Helper for automatic ping configuration
2813 static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
2815 for (; *list; list++)
2823 * Sort an associated group of pins according to their sequence numbers.
2825 static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences,
2832 for (i = 0; i < num_pins; i++) {
2833 for (j = i + 1; j < num_pins; j++) {
2834 if (sequences[i] > sequences[j]) {
2836 sequences[i] = sequences[j];
2848 * Parse all pin widgets and store the useful pin nids to cfg
2850 * The number of line-outs or any primary output is stored in line_outs,
2851 * and the corresponding output pins are assigned to line_out_pins[],
2852 * in the order of front, rear, CLFE, side, ...
2854 * If more extra outputs (speaker and headphone) are found, the pins are
2855 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
2856 * is detected, one of speaker of HP pins is assigned as the primary
2857 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
2858 * if any analog output exists.
2860 * The analog input pins are assigned to input_pins array.
2861 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
2864 int snd_hda_parse_pin_def_config(struct hda_codec *codec,
2865 struct auto_pin_cfg *cfg,
2866 hda_nid_t *ignore_nids)
2868 hda_nid_t nid, end_nid;
2869 short seq, assoc_line_out, assoc_speaker;
2870 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
2871 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
2872 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
2874 memset(cfg, 0, sizeof(*cfg));
2876 memset(sequences_line_out, 0, sizeof(sequences_line_out));
2877 memset(sequences_speaker, 0, sizeof(sequences_speaker));
2878 memset(sequences_hp, 0, sizeof(sequences_hp));
2879 assoc_line_out = assoc_speaker = 0;
2881 end_nid = codec->start_nid + codec->num_nodes;
2882 for (nid = codec->start_nid; nid < end_nid; nid++) {
2883 unsigned int wid_caps = get_wcaps(codec, nid);
2884 unsigned int wid_type =
2885 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2886 unsigned int def_conf;
2889 /* read all default configuration for pin complex */
2890 if (wid_type != AC_WID_PIN)
2892 /* ignore the given nids (e.g. pc-beep returns error) */
2893 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
2896 def_conf = snd_hda_codec_read(codec, nid, 0,
2897 AC_VERB_GET_CONFIG_DEFAULT, 0);
2898 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2900 loc = get_defcfg_location(def_conf);
2901 switch (get_defcfg_device(def_conf)) {
2902 case AC_JACK_LINE_OUT:
2903 seq = get_defcfg_sequence(def_conf);
2904 assoc = get_defcfg_association(def_conf);
2906 if (!(wid_caps & AC_WCAP_STEREO))
2907 if (!cfg->mono_out_pin)
2908 cfg->mono_out_pin = nid;
2911 if (!assoc_line_out)
2912 assoc_line_out = assoc;
2913 else if (assoc_line_out != assoc)
2915 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
2917 cfg->line_out_pins[cfg->line_outs] = nid;
2918 sequences_line_out[cfg->line_outs] = seq;
2921 case AC_JACK_SPEAKER:
2922 seq = get_defcfg_sequence(def_conf);
2923 assoc = get_defcfg_association(def_conf);
2926 if (! assoc_speaker)
2927 assoc_speaker = assoc;
2928 else if (assoc_speaker != assoc)
2930 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
2932 cfg->speaker_pins[cfg->speaker_outs] = nid;
2933 sequences_speaker[cfg->speaker_outs] = seq;
2934 cfg->speaker_outs++;
2936 case AC_JACK_HP_OUT:
2937 seq = get_defcfg_sequence(def_conf);
2938 assoc = get_defcfg_association(def_conf);
2939 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
2941 cfg->hp_pins[cfg->hp_outs] = nid;
2942 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
2945 case AC_JACK_MIC_IN: {
2947 if (loc == AC_JACK_LOC_FRONT) {
2948 preferred = AUTO_PIN_FRONT_MIC;
2951 preferred = AUTO_PIN_MIC;
2952 alt = AUTO_PIN_FRONT_MIC;
2954 if (!cfg->input_pins[preferred])
2955 cfg->input_pins[preferred] = nid;
2956 else if (!cfg->input_pins[alt])
2957 cfg->input_pins[alt] = nid;
2960 case AC_JACK_LINE_IN:
2961 if (loc == AC_JACK_LOC_FRONT)
2962 cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid;
2964 cfg->input_pins[AUTO_PIN_LINE] = nid;
2967 cfg->input_pins[AUTO_PIN_CD] = nid;
2970 cfg->input_pins[AUTO_PIN_AUX] = nid;
2972 case AC_JACK_SPDIF_OUT:
2973 cfg->dig_out_pin = nid;
2975 case AC_JACK_SPDIF_IN:
2976 cfg->dig_in_pin = nid;
2982 * If no line-out is defined but multiple HPs are found,
2983 * some of them might be the real line-outs.
2985 if (!cfg->line_outs && cfg->hp_outs > 1) {
2987 while (i < cfg->hp_outs) {
2988 /* The real HPs should have the sequence 0x0f */
2989 if ((sequences_hp[i] & 0x0f) == 0x0f) {
2993 /* Move it to the line-out table */
2994 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
2995 sequences_line_out[cfg->line_outs] = sequences_hp[i];
2998 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
2999 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
3000 memmove(sequences_hp + i - 1, sequences_hp + i,
3001 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
3005 /* sort by sequence */
3006 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
3008 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
3010 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
3013 /* if we have only one mic, make it AUTO_PIN_MIC */
3014 if (!cfg->input_pins[AUTO_PIN_MIC] &&
3015 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
3016 cfg->input_pins[AUTO_PIN_MIC] =
3017 cfg->input_pins[AUTO_PIN_FRONT_MIC];
3018 cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0;
3020 /* ditto for line-in */
3021 if (!cfg->input_pins[AUTO_PIN_LINE] &&
3022 cfg->input_pins[AUTO_PIN_FRONT_LINE]) {
3023 cfg->input_pins[AUTO_PIN_LINE] =
3024 cfg->input_pins[AUTO_PIN_FRONT_LINE];
3025 cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0;
3029 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
3030 * as a primary output
3032 if (!cfg->line_outs) {
3033 if (cfg->speaker_outs) {
3034 cfg->line_outs = cfg->speaker_outs;
3035 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3036 sizeof(cfg->speaker_pins));
3037 cfg->speaker_outs = 0;
3038 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3039 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3040 } else if (cfg->hp_outs) {
3041 cfg->line_outs = cfg->hp_outs;
3042 memcpy(cfg->line_out_pins, cfg->hp_pins,
3043 sizeof(cfg->hp_pins));
3045 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3046 cfg->line_out_type = AUTO_PIN_HP_OUT;
3050 /* Reorder the surround channels
3051 * ALSA sequence is front/surr/clfe/side
3053 * 4-ch: front/surr => OK as it is
3054 * 6-ch: front/clfe/surr
3055 * 8-ch: front/clfe/rear/side|fc
3057 switch (cfg->line_outs) {
3060 nid = cfg->line_out_pins[1];
3061 cfg->line_out_pins[1] = cfg->line_out_pins[2];
3062 cfg->line_out_pins[2] = nid;
3067 * debug prints of the parsed results
3069 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3070 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
3071 cfg->line_out_pins[2], cfg->line_out_pins[3],
3072 cfg->line_out_pins[4]);
3073 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3074 cfg->speaker_outs, cfg->speaker_pins[0],
3075 cfg->speaker_pins[1], cfg->speaker_pins[2],
3076 cfg->speaker_pins[3], cfg->speaker_pins[4]);
3077 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3078 cfg->hp_outs, cfg->hp_pins[0],
3079 cfg->hp_pins[1], cfg->hp_pins[2],
3080 cfg->hp_pins[3], cfg->hp_pins[4]);
3081 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
3082 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
3083 " cd=0x%x, aux=0x%x\n",
3084 cfg->input_pins[AUTO_PIN_MIC],
3085 cfg->input_pins[AUTO_PIN_FRONT_MIC],
3086 cfg->input_pins[AUTO_PIN_LINE],
3087 cfg->input_pins[AUTO_PIN_FRONT_LINE],
3088 cfg->input_pins[AUTO_PIN_CD],
3089 cfg->input_pins[AUTO_PIN_AUX]);
3094 /* labels for input pins */
3095 const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
3096 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
3106 * snd_hda_suspend - suspend the codecs
3108 * @state: suspsend state
3110 * Returns 0 if successful.
3112 int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
3114 struct hda_codec *codec;
3116 list_for_each_entry(codec, &bus->codec_list, list) {
3117 #ifdef CONFIG_SND_HDA_POWER_SAVE
3118 if (!codec->power_on)
3121 hda_call_codec_suspend(codec);
3127 * snd_hda_resume - resume the codecs
3129 * @state: resume state
3131 * Returns 0 if successful.
3133 * This fucntion is defined only when POWER_SAVE isn't set.
3134 * In the power-save mode, the codec is resumed dynamically.
3136 int snd_hda_resume(struct hda_bus *bus)
3138 struct hda_codec *codec;
3140 list_for_each_entry(codec, &bus->codec_list, list) {
3141 if (snd_hda_codec_needs_resume(codec))
3142 hda_call_codec_resume(codec);
3146 #ifdef CONFIG_SND_HDA_POWER_SAVE
3147 int snd_hda_codecs_inuse(struct hda_bus *bus)
3149 struct hda_codec *codec;
3151 list_for_each_entry(codec, &bus->codec_list, list) {
3152 if (snd_hda_codec_needs_resume(codec))