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"
34 #include <sound/hda_hwdep.h>
37 * vendor / preset table
40 struct hda_vendor_id {
45 /* codec vendor labels */
46 static struct hda_vendor_id hda_vendor_ids[] = {
48 { 0x1013, "Cirrus Logic" },
49 { 0x1057, "Motorola" },
50 { 0x1095, "Silicon Image" },
52 { 0x10ec, "Realtek" },
53 { 0x1102, "Creative" },
57 { 0x11d4, "Analog Devices" },
58 { 0x13f6, "C-Media" },
59 { 0x14f1, "Conexant" },
60 { 0x17e8, "Chrontel" },
62 { 0x1aec, "Wolfson Microelectronics" },
63 { 0x434d, "C-Media" },
65 { 0x8384, "SigmaTel" },
69 static DEFINE_MUTEX(preset_mutex);
70 static LIST_HEAD(hda_preset_tables);
72 int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
74 mutex_lock(&preset_mutex);
75 list_add_tail(&preset->list, &hda_preset_tables);
76 mutex_unlock(&preset_mutex);
79 EXPORT_SYMBOL_HDA(snd_hda_add_codec_preset);
81 int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
83 mutex_lock(&preset_mutex);
84 list_del(&preset->list);
85 mutex_unlock(&preset_mutex);
88 EXPORT_SYMBOL_HDA(snd_hda_delete_codec_preset);
90 #ifdef CONFIG_SND_HDA_POWER_SAVE
91 static void hda_power_work(struct work_struct *work);
92 static void hda_keep_power_on(struct hda_codec *codec);
94 static inline void hda_keep_power_on(struct hda_codec *codec) {}
98 * snd_hda_get_jack_location - Give a location string of the jack
99 * @cfg: pin default config value
101 * Parse the pin default config value and returns the string of the
102 * jack location, e.g. "Rear", "Front", etc.
104 const char *snd_hda_get_jack_location(u32 cfg)
106 static char *bases[7] = {
107 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
109 static unsigned char specials_idx[] = {
114 static char *specials[] = {
115 "Rear Panel", "Drive Bar",
116 "Riser", "HDMI", "ATAPI",
117 "Mobile-In", "Mobile-Out"
120 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
121 if ((cfg & 0x0f) < 7)
122 return bases[cfg & 0x0f];
123 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
124 if (cfg == specials_idx[i])
129 EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
132 * snd_hda_get_jack_connectivity - Give a connectivity string of the jack
133 * @cfg: pin default config value
135 * Parse the pin default config value and returns the string of the
136 * jack connectivity, i.e. external or internal connection.
138 const char *snd_hda_get_jack_connectivity(u32 cfg)
140 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
142 return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3];
144 EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
147 * snd_hda_get_jack_type - Give a type string of the jack
148 * @cfg: pin default config value
150 * Parse the pin default config value and returns the string of the
151 * jack type, i.e. the purpose of the jack, such as Line-Out or CD.
153 const char *snd_hda_get_jack_type(u32 cfg)
155 static char *jack_types[16] = {
156 "Line Out", "Speaker", "HP Out", "CD",
157 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
158 "Line In", "Aux", "Mic", "Telephony",
159 "SPDIF In", "Digitial In", "Reserved", "Other"
162 return jack_types[(cfg & AC_DEFCFG_DEVICE)
163 >> AC_DEFCFG_DEVICE_SHIFT];
165 EXPORT_SYMBOL_HDA(snd_hda_get_jack_type);
168 * Compose a 32bit command word to be sent to the HD-audio controller
170 static inline unsigned int
171 make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
172 unsigned int verb, unsigned int parm)
176 if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) ||
177 (verb & ~0xfff) || (parm & ~0xffff)) {
178 printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n",
179 codec->addr, direct, nid, verb, parm);
183 val = (u32)codec->addr << 28;
184 val |= (u32)direct << 27;
185 val |= (u32)nid << 20;
192 * Send and receive a verb
194 static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
197 struct hda_bus *bus = codec->bus;
206 snd_hda_power_up(codec);
207 mutex_lock(&bus->cmd_mutex);
208 err = bus->ops.command(bus, cmd);
210 *res = bus->ops.get_response(bus, codec->addr);
211 mutex_unlock(&bus->cmd_mutex);
212 snd_hda_power_down(codec);
213 if (res && *res == -1 && bus->rirb_error) {
214 if (bus->response_reset) {
215 snd_printd("hda_codec: resetting BUS due to "
216 "fatal communication error\n");
217 bus->ops.bus_reset(bus);
221 /* clear reset-flag when the communication gets recovered */
223 bus->response_reset = 0;
228 * snd_hda_codec_read - send a command and get the response
229 * @codec: the HDA codec
230 * @nid: NID to send the command
231 * @direct: direct flag
232 * @verb: the verb to send
233 * @parm: the parameter for the verb
235 * Send a single command and read the corresponding response.
237 * Returns the obtained response value, or -1 for an error.
239 unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
241 unsigned int verb, unsigned int parm)
243 unsigned cmd = make_codec_cmd(codec, nid, direct, verb, parm);
245 codec_exec_verb(codec, cmd, &res);
248 EXPORT_SYMBOL_HDA(snd_hda_codec_read);
251 * snd_hda_codec_write - send a single command without waiting for response
252 * @codec: the HDA codec
253 * @nid: NID to send the command
254 * @direct: direct flag
255 * @verb: the verb to send
256 * @parm: the parameter for the verb
258 * Send a single command without waiting for response.
260 * Returns 0 if successful, or a negative error code.
262 int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
263 unsigned int verb, unsigned int parm)
265 unsigned int cmd = make_codec_cmd(codec, nid, direct, verb, parm);
267 return codec_exec_verb(codec, cmd,
268 codec->bus->sync_write ? &res : NULL);
270 EXPORT_SYMBOL_HDA(snd_hda_codec_write);
273 * snd_hda_sequence_write - sequence writes
274 * @codec: the HDA codec
275 * @seq: VERB array to send
277 * Send the commands sequentially from the given array.
278 * The array must be terminated with NID=0.
280 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
282 for (; seq->nid; seq++)
283 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
285 EXPORT_SYMBOL_HDA(snd_hda_sequence_write);
288 * snd_hda_get_sub_nodes - get the range of sub nodes
289 * @codec: the HDA codec
291 * @start_id: the pointer to store the start NID
293 * Parse the NID and store the start NID of its sub-nodes.
294 * Returns the number of sub-nodes.
296 int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
301 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
304 *start_id = (parm >> 16) & 0x7fff;
305 return (int)(parm & 0x7fff);
307 EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes);
310 * snd_hda_get_connections - get connection list
311 * @codec: the HDA codec
313 * @conn_list: connection list array
314 * @max_conns: max. number of connections to store
316 * Parses the connection list of the given widget and stores the list
319 * Returns the number of connections, or a negative error code.
321 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
322 hda_nid_t *conn_list, int max_conns)
325 int i, conn_len, conns;
326 unsigned int shift, num_elems, mask;
330 if (snd_BUG_ON(!conn_list || max_conns <= 0))
333 wcaps = get_wcaps(codec, nid);
334 if (!(wcaps & AC_WCAP_CONN_LIST) &&
335 get_wcaps_type(wcaps) != AC_WID_VOL_KNB) {
336 snd_printk(KERN_WARNING "hda_codec: "
337 "connection list not available for 0x%x\n", nid);
341 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
342 if (parm & AC_CLIST_LONG) {
351 conn_len = parm & AC_CLIST_LENGTH;
352 mask = (1 << (shift-1)) - 1;
355 return 0; /* no connection */
358 /* single connection */
359 parm = snd_hda_codec_read(codec, nid, 0,
360 AC_VERB_GET_CONNECT_LIST, 0);
361 if (parm == -1 && codec->bus->rirb_error)
363 conn_list[0] = parm & mask;
367 /* multi connection */
370 for (i = 0; i < conn_len; i++) {
374 if (i % num_elems == 0) {
375 parm = snd_hda_codec_read(codec, nid, 0,
376 AC_VERB_GET_CONNECT_LIST, i);
377 if (parm == -1 && codec->bus->rirb_error)
380 range_val = !!(parm & (1 << (shift-1))); /* ranges */
383 snd_printk(KERN_WARNING "hda_codec: "
384 "invalid CONNECT_LIST verb %x[%i]:%x\n",
390 /* ranges between the previous and this one */
391 if (!prev_nid || prev_nid >= val) {
392 snd_printk(KERN_WARNING "hda_codec: "
393 "invalid dep_range_val %x:%x\n",
397 for (n = prev_nid + 1; n <= val; n++) {
398 if (conns >= max_conns) {
400 "Too many connections\n");
403 conn_list[conns++] = n;
406 if (conns >= max_conns) {
407 snd_printk(KERN_ERR "Too many connections\n");
410 conn_list[conns++] = val;
416 EXPORT_SYMBOL_HDA(snd_hda_get_connections);
420 * snd_hda_queue_unsol_event - add an unsolicited event to queue
422 * @res: unsolicited event (lower 32bit of RIRB entry)
423 * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
425 * Adds the given event to the queue. The events are processed in
426 * the workqueue asynchronously. Call this function in the interrupt
427 * hanlder when RIRB receives an unsolicited event.
429 * Returns 0 if successful, or a negative error code.
431 int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
433 struct hda_bus_unsolicited *unsol;
440 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
444 unsol->queue[wp] = res;
445 unsol->queue[wp + 1] = res_ex;
447 queue_work(bus->workq, &unsol->work);
451 EXPORT_SYMBOL_HDA(snd_hda_queue_unsol_event);
454 * process queued unsolicited events
456 static void process_unsol_events(struct work_struct *work)
458 struct hda_bus_unsolicited *unsol =
459 container_of(work, struct hda_bus_unsolicited, work);
460 struct hda_bus *bus = unsol->bus;
461 struct hda_codec *codec;
462 unsigned int rp, caddr, res;
464 while (unsol->rp != unsol->wp) {
465 rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE;
468 res = unsol->queue[rp];
469 caddr = unsol->queue[rp + 1];
470 if (!(caddr & (1 << 4))) /* no unsolicited event? */
472 codec = bus->caddr_tbl[caddr & 0x0f];
473 if (codec && codec->patch_ops.unsol_event)
474 codec->patch_ops.unsol_event(codec, res);
479 * initialize unsolicited queue
481 static int init_unsol_queue(struct hda_bus *bus)
483 struct hda_bus_unsolicited *unsol;
485 if (bus->unsol) /* already initialized */
488 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
490 snd_printk(KERN_ERR "hda_codec: "
491 "can't allocate unsolicited queue\n");
494 INIT_WORK(&unsol->work, process_unsol_events);
503 static void snd_hda_codec_free(struct hda_codec *codec);
505 static int snd_hda_bus_free(struct hda_bus *bus)
507 struct hda_codec *codec, *n;
512 flush_workqueue(bus->workq);
515 list_for_each_entry_safe(codec, n, &bus->codec_list, list) {
516 snd_hda_codec_free(codec);
518 if (bus->ops.private_free)
519 bus->ops.private_free(bus);
521 destroy_workqueue(bus->workq);
526 static int snd_hda_bus_dev_free(struct snd_device *device)
528 struct hda_bus *bus = device->device_data;
530 return snd_hda_bus_free(bus);
533 #ifdef CONFIG_SND_HDA_HWDEP
534 static int snd_hda_bus_dev_register(struct snd_device *device)
536 struct hda_bus *bus = device->device_data;
537 struct hda_codec *codec;
538 list_for_each_entry(codec, &bus->codec_list, list) {
539 snd_hda_hwdep_add_sysfs(codec);
540 snd_hda_hwdep_add_power_sysfs(codec);
545 #define snd_hda_bus_dev_register NULL
549 * snd_hda_bus_new - create a HDA bus
550 * @card: the card entry
551 * @temp: the template for hda_bus information
552 * @busp: the pointer to store the created bus instance
554 * Returns 0 if successful, or a negative error code.
556 int /*__devinit*/ snd_hda_bus_new(struct snd_card *card,
557 const struct hda_bus_template *temp,
558 struct hda_bus **busp)
562 static struct snd_device_ops dev_ops = {
563 .dev_register = snd_hda_bus_dev_register,
564 .dev_free = snd_hda_bus_dev_free,
567 if (snd_BUG_ON(!temp))
569 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
575 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
577 snd_printk(KERN_ERR "can't allocate struct hda_bus\n");
582 bus->private_data = temp->private_data;
583 bus->pci = temp->pci;
584 bus->modelname = temp->modelname;
585 bus->power_save = temp->power_save;
586 bus->ops = temp->ops;
588 mutex_init(&bus->cmd_mutex);
589 INIT_LIST_HEAD(&bus->codec_list);
591 snprintf(bus->workq_name, sizeof(bus->workq_name),
592 "hd-audio%d", card->number);
593 bus->workq = create_singlethread_workqueue(bus->workq_name);
595 snd_printk(KERN_ERR "cannot create workqueue %s\n",
601 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
603 snd_hda_bus_free(bus);
610 EXPORT_SYMBOL_HDA(snd_hda_bus_new);
612 #ifdef CONFIG_SND_HDA_GENERIC
613 #define is_generic_config(codec) \
614 (codec->modelname && !strcmp(codec->modelname, "generic"))
616 #define is_generic_config(codec) 0
620 #define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */
622 #define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */
626 * find a matching codec preset
628 static const struct hda_codec_preset *
629 find_codec_preset(struct hda_codec *codec)
631 struct hda_codec_preset_list *tbl;
632 const struct hda_codec_preset *preset;
633 int mod_requested = 0;
635 if (is_generic_config(codec))
636 return NULL; /* use the generic parser */
639 mutex_lock(&preset_mutex);
640 list_for_each_entry(tbl, &hda_preset_tables, list) {
641 if (!try_module_get(tbl->owner)) {
642 snd_printk(KERN_ERR "hda_codec: cannot module_get\n");
645 for (preset = tbl->preset; preset->id; preset++) {
646 u32 mask = preset->mask;
647 if (preset->afg && preset->afg != codec->afg)
649 if (preset->mfg && preset->mfg != codec->mfg)
653 if (preset->id == (codec->vendor_id & mask) &&
655 preset->rev == codec->revision_id)) {
656 mutex_unlock(&preset_mutex);
657 codec->owner = tbl->owner;
661 module_put(tbl->owner);
663 mutex_unlock(&preset_mutex);
665 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
668 snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
671 snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
672 (codec->vendor_id >> 16) & 0xffff);
673 request_module(name);
681 * get_codec_name - store the codec name
683 static int get_codec_name(struct hda_codec *codec)
685 const struct hda_vendor_id *c;
686 const char *vendor = NULL;
687 u16 vendor_id = codec->vendor_id >> 16;
690 if (codec->vendor_name)
693 for (c = hda_vendor_ids; c->id; c++) {
694 if (c->id == vendor_id) {
700 sprintf(tmp, "Generic %04x", vendor_id);
703 codec->vendor_name = kstrdup(vendor, GFP_KERNEL);
704 if (!codec->vendor_name)
708 if (codec->chip_name)
711 if (codec->preset && codec->preset->name)
712 codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL);
714 sprintf(tmp, "ID %x", codec->vendor_id & 0xffff);
715 codec->chip_name = kstrdup(tmp, GFP_KERNEL);
717 if (!codec->chip_name)
723 * look for an AFG and MFG nodes
725 static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec)
727 int i, total_nodes, function_id;
730 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
731 for (i = 0; i < total_nodes; i++, nid++) {
732 function_id = snd_hda_param_read(codec, nid,
733 AC_PAR_FUNCTION_TYPE) & 0xff;
734 switch (function_id) {
735 case AC_GRP_AUDIO_FUNCTION:
737 codec->function_id = function_id;
739 case AC_GRP_MODEM_FUNCTION:
741 codec->function_id = function_id;
750 * read widget caps for each widget and store in cache
752 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
757 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node,
759 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
762 nid = codec->start_nid;
763 for (i = 0; i < codec->num_nodes; i++, nid++)
764 codec->wcaps[i] = snd_hda_param_read(codec, nid,
765 AC_PAR_AUDIO_WIDGET_CAP);
769 /* read all pin default configurations and save codec->init_pins */
770 static int read_pin_defaults(struct hda_codec *codec)
773 hda_nid_t nid = codec->start_nid;
775 for (i = 0; i < codec->num_nodes; i++, nid++) {
776 struct hda_pincfg *pin;
777 unsigned int wcaps = get_wcaps(codec, nid);
778 unsigned int wid_type = get_wcaps_type(wcaps);
779 if (wid_type != AC_WID_PIN)
781 pin = snd_array_new(&codec->init_pins);
785 pin->cfg = snd_hda_codec_read(codec, nid, 0,
786 AC_VERB_GET_CONFIG_DEFAULT, 0);
791 /* look up the given pin config list and return the item matching with NID */
792 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
793 struct snd_array *array,
797 for (i = 0; i < array->used; i++) {
798 struct hda_pincfg *pin = snd_array_elem(array, i);
805 /* write a config value for the given NID */
806 static void set_pincfg(struct hda_codec *codec, hda_nid_t nid,
810 for (i = 0; i < 4; i++) {
811 snd_hda_codec_write(codec, nid, 0,
812 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
818 /* set the current pin config value for the given NID.
819 * the value is cached, and read via snd_hda_codec_get_pincfg()
821 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
822 hda_nid_t nid, unsigned int cfg)
824 struct hda_pincfg *pin;
827 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
830 oldcfg = snd_hda_codec_get_pincfg(codec, nid);
831 pin = look_up_pincfg(codec, list, nid);
833 pin = snd_array_new(list);
840 /* change only when needed; e.g. if the pincfg is already present
841 * in user_pins[], don't write it
843 cfg = snd_hda_codec_get_pincfg(codec, nid);
845 set_pincfg(codec, nid, cfg);
850 * snd_hda_codec_set_pincfg - Override a pin default configuration
851 * @codec: the HDA codec
852 * @nid: NID to set the pin config
853 * @cfg: the pin default config value
855 * Override a pin default configuration value in the cache.
856 * This value can be read by snd_hda_codec_get_pincfg() in a higher
857 * priority than the real hardware value.
859 int snd_hda_codec_set_pincfg(struct hda_codec *codec,
860 hda_nid_t nid, unsigned int cfg)
862 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
864 EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
867 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
868 * @codec: the HDA codec
869 * @nid: NID to get the pin config
871 * Get the current pin config value of the given pin NID.
872 * If the pincfg value is cached or overridden via sysfs or driver,
873 * returns the cached value.
875 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
877 struct hda_pincfg *pin;
879 #ifdef CONFIG_SND_HDA_HWDEP
880 pin = look_up_pincfg(codec, &codec->user_pins, nid);
884 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
887 pin = look_up_pincfg(codec, &codec->init_pins, nid);
892 EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg);
894 /* restore all current pin configs */
895 static void restore_pincfgs(struct hda_codec *codec)
898 for (i = 0; i < codec->init_pins.used; i++) {
899 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
900 set_pincfg(codec, pin->nid,
901 snd_hda_codec_get_pincfg(codec, pin->nid));
906 * snd_hda_shutup_pins - Shut up all pins
907 * @codec: the HDA codec
909 * Clear all pin controls to shup up before suspend for avoiding click noise.
910 * The controls aren't cached so that they can be resumed properly.
912 void snd_hda_shutup_pins(struct hda_codec *codec)
915 for (i = 0; i < codec->init_pins.used; i++) {
916 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
917 /* use read here for syncing after issuing each verb */
918 snd_hda_codec_read(codec, pin->nid, 0,
919 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
922 EXPORT_SYMBOL_HDA(snd_hda_shutup_pins);
924 static void init_hda_cache(struct hda_cache_rec *cache,
925 unsigned int record_size);
926 static void free_hda_cache(struct hda_cache_rec *cache);
928 /* restore the initial pin cfgs and release all pincfg lists */
929 static void restore_init_pincfgs(struct hda_codec *codec)
931 /* first free driver_pins and user_pins, then call restore_pincfg
932 * so that only the values in init_pins are restored
934 snd_array_free(&codec->driver_pins);
935 #ifdef CONFIG_SND_HDA_HWDEP
936 snd_array_free(&codec->user_pins);
938 restore_pincfgs(codec);
939 snd_array_free(&codec->init_pins);
945 static void snd_hda_codec_free(struct hda_codec *codec)
949 restore_init_pincfgs(codec);
950 #ifdef CONFIG_SND_HDA_POWER_SAVE
951 cancel_delayed_work(&codec->power_work);
952 flush_workqueue(codec->bus->workq);
954 list_del(&codec->list);
955 snd_array_free(&codec->mixers);
956 snd_array_free(&codec->nids);
957 codec->bus->caddr_tbl[codec->addr] = NULL;
958 if (codec->patch_ops.free)
959 codec->patch_ops.free(codec);
960 module_put(codec->owner);
961 free_hda_cache(&codec->amp_cache);
962 free_hda_cache(&codec->cmd_cache);
963 kfree(codec->vendor_name);
964 kfree(codec->chip_name);
965 kfree(codec->modelname);
970 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
971 unsigned int power_state);
974 * snd_hda_codec_new - create a HDA codec
975 * @bus: the bus to assign
976 * @codec_addr: the codec address
977 * @codecp: the pointer to store the generated codec
979 * Returns 0 if successful, or a negative error code.
981 int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
982 unsigned int codec_addr,
983 struct hda_codec **codecp)
985 struct hda_codec *codec;
989 if (snd_BUG_ON(!bus))
991 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
994 if (bus->caddr_tbl[codec_addr]) {
995 snd_printk(KERN_ERR "hda_codec: "
996 "address 0x%x is already occupied\n", codec_addr);
1000 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
1001 if (codec == NULL) {
1002 snd_printk(KERN_ERR "can't allocate struct hda_codec\n");
1007 codec->addr = codec_addr;
1008 mutex_init(&codec->spdif_mutex);
1009 mutex_init(&codec->control_mutex);
1010 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1011 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1012 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1013 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
1014 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
1015 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
1016 if (codec->bus->modelname) {
1017 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1018 if (!codec->modelname) {
1019 snd_hda_codec_free(codec);
1024 #ifdef CONFIG_SND_HDA_POWER_SAVE
1025 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
1026 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
1027 * the caller has to power down appropriatley after initialization
1030 hda_keep_power_on(codec);
1033 list_add_tail(&codec->list, &bus->codec_list);
1034 bus->caddr_tbl[codec_addr] = codec;
1036 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1038 if (codec->vendor_id == -1)
1039 /* read again, hopefully the access method was corrected
1040 * in the last read...
1042 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1044 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1045 AC_PAR_SUBSYSTEM_ID);
1046 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1049 setup_fg_nodes(codec);
1050 if (!codec->afg && !codec->mfg) {
1051 snd_printdd("hda_codec: no AFG or MFG node found\n");
1056 err = read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg);
1058 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
1061 err = read_pin_defaults(codec);
1065 if (!codec->subsystem_id) {
1066 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
1067 codec->subsystem_id =
1068 snd_hda_codec_read(codec, nid, 0,
1069 AC_VERB_GET_SUBSYSTEM_ID, 0);
1072 /* power-up all before initialization */
1073 hda_set_power_state(codec,
1074 codec->afg ? codec->afg : codec->mfg,
1077 snd_hda_codec_proc_new(codec);
1079 snd_hda_create_hwdep(codec);
1081 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
1082 codec->subsystem_id, codec->revision_id);
1083 snd_component_add(codec->bus->card, component);
1090 snd_hda_codec_free(codec);
1093 EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1096 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1097 * @codec: the HDA codec
1099 * Start parsing of the given codec tree and (re-)initialize the whole
1102 * Returns 0 if successful or a negative error code.
1104 int snd_hda_codec_configure(struct hda_codec *codec)
1108 codec->preset = find_codec_preset(codec);
1109 if (!codec->vendor_name || !codec->chip_name) {
1110 err = get_codec_name(codec);
1115 if (is_generic_config(codec)) {
1116 err = snd_hda_parse_generic_codec(codec);
1119 if (codec->preset && codec->preset->patch) {
1120 err = codec->preset->patch(codec);
1124 /* call the default parser */
1125 err = snd_hda_parse_generic_codec(codec);
1127 printk(KERN_ERR "hda-codec: No codec parser is available\n");
1130 if (!err && codec->patch_ops.unsol_event)
1131 err = init_unsol_queue(codec->bus);
1132 /* audio codec should override the mixer name */
1133 if (!err && (codec->afg || !*codec->bus->card->mixername))
1134 snprintf(codec->bus->card->mixername,
1135 sizeof(codec->bus->card->mixername),
1136 "%s %s", codec->vendor_name, codec->chip_name);
1139 EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
1142 * snd_hda_codec_setup_stream - set up the codec for streaming
1143 * @codec: the CODEC to set up
1144 * @nid: the NID to set up
1145 * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
1146 * @channel_id: channel id to pass, zero based.
1147 * @format: stream format.
1149 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1151 int channel_id, int format)
1156 snd_printdd("hda_codec_setup_stream: "
1157 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1158 nid, stream_tag, channel_id, format);
1159 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
1160 (stream_tag << 4) | channel_id);
1162 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
1164 EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1167 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1168 * @codec: the CODEC to clean up
1169 * @nid: the NID to clean up
1171 void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1176 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
1177 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1178 #if 0 /* keep the format */
1180 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
1183 EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1186 * amp access functions
1189 /* FIXME: more better hash key? */
1190 #define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1191 #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1192 #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1193 #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
1194 #define INFO_AMP_CAPS (1<<0)
1195 #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
1197 /* initialize the hash table */
1198 static void /*__devinit*/ init_hda_cache(struct hda_cache_rec *cache,
1199 unsigned int record_size)
1201 memset(cache, 0, sizeof(*cache));
1202 memset(cache->hash, 0xff, sizeof(cache->hash));
1203 snd_array_init(&cache->buf, record_size, 64);
1206 static void free_hda_cache(struct hda_cache_rec *cache)
1208 snd_array_free(&cache->buf);
1211 /* query the hash. allocate an entry if not found. */
1212 static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key)
1214 u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
1215 u16 cur = cache->hash[idx];
1216 struct hda_cache_head *info;
1218 while (cur != 0xffff) {
1219 info = snd_array_elem(&cache->buf, cur);
1220 if (info->key == key)
1227 /* query the hash. allocate an entry if not found. */
1228 static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
1231 struct hda_cache_head *info = get_hash(cache, key);
1234 /* add a new hash entry */
1235 info = snd_array_new(&cache->buf);
1238 cur = snd_array_index(&cache->buf, info);
1241 idx = key % (u16)ARRAY_SIZE(cache->hash);
1242 info->next = cache->hash[idx];
1243 cache->hash[idx] = cur;
1248 /* query and allocate an amp hash entry */
1249 static inline struct hda_amp_info *
1250 get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1252 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1256 * query_amp_caps - query AMP capabilities
1257 * @codec: the HD-auio codec
1258 * @nid: the NID to query
1259 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1261 * Query AMP capabilities for the given widget and direction.
1262 * Returns the obtained capability bits.
1264 * When cap bits have been already read, this doesn't read again but
1265 * returns the cached value.
1267 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1269 struct hda_amp_info *info;
1271 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
1274 if (!(info->head.val & INFO_AMP_CAPS)) {
1275 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1277 info->amp_caps = snd_hda_param_read(codec, nid,
1278 direction == HDA_OUTPUT ?
1279 AC_PAR_AMP_OUT_CAP :
1282 info->head.val |= INFO_AMP_CAPS;
1284 return info->amp_caps;
1286 EXPORT_SYMBOL_HDA(query_amp_caps);
1289 * snd_hda_override_amp_caps - Override the AMP capabilities
1290 * @codec: the CODEC to clean up
1291 * @nid: the NID to clean up
1292 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1293 * @caps: the capability bits to set
1295 * Override the cached AMP caps bits value by the given one.
1296 * This function is useful if the driver needs to adjust the AMP ranges,
1297 * e.g. limit to 0dB, etc.
1299 * Returns zero if successful or a negative error code.
1301 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1304 struct hda_amp_info *info;
1306 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0));
1309 info->amp_caps = caps;
1310 info->head.val |= INFO_AMP_CAPS;
1313 EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
1316 query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key,
1317 unsigned int (*func)(struct hda_codec *, hda_nid_t))
1319 struct hda_amp_info *info;
1321 info = get_alloc_amp_hash(codec, key);
1324 if (!info->head.val) {
1325 info->head.val |= INFO_AMP_CAPS;
1326 info->amp_caps = func(codec, nid);
1328 return info->amp_caps;
1331 static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1333 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1337 * snd_hda_query_pin_caps - Query PIN capabilities
1338 * @codec: the HD-auio codec
1339 * @nid: the NID to query
1341 * Query PIN capabilities for the given widget.
1342 * Returns the obtained capability bits.
1344 * When cap bits have been already read, this doesn't read again but
1345 * returns the cached value.
1347 u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1349 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
1352 EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1355 * snd_hda_pin_sense - execute pin sense measurement
1356 * @codec: the CODEC to sense
1357 * @nid: the pin NID to sense
1359 * Execute necessary pin sense measurement and return its Presence Detect,
1360 * Impedance, ELD Valid etc. status bits.
1362 u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1366 if (!codec->no_trigger_sense) {
1367 pincap = snd_hda_query_pin_caps(codec, nid);
1368 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1369 snd_hda_codec_read(codec, nid, 0,
1370 AC_VERB_SET_PIN_SENSE, 0);
1372 return snd_hda_codec_read(codec, nid, 0,
1373 AC_VERB_GET_PIN_SENSE, 0);
1375 EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1378 * snd_hda_jack_detect - query pin Presence Detect status
1379 * @codec: the CODEC to sense
1380 * @nid: the pin NID to sense
1382 * Query and return the pin's Presence Detect status.
1384 int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1386 u32 sense = snd_hda_pin_sense(codec, nid);
1387 return !!(sense & AC_PINSENSE_PRESENCE);
1389 EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1392 * read the current volume to info
1393 * if the cache exists, read the cache value.
1395 static unsigned int get_vol_mute(struct hda_codec *codec,
1396 struct hda_amp_info *info, hda_nid_t nid,
1397 int ch, int direction, int index)
1401 if (info->head.val & INFO_AMP_VOL(ch))
1402 return info->vol[ch];
1404 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
1405 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
1407 val = snd_hda_codec_read(codec, nid, 0,
1408 AC_VERB_GET_AMP_GAIN_MUTE, parm);
1409 info->vol[ch] = val & 0xff;
1410 info->head.val |= INFO_AMP_VOL(ch);
1411 return info->vol[ch];
1415 * write the current volume in info to the h/w and update the cache
1417 static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1418 hda_nid_t nid, int ch, int direction, int index,
1423 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
1424 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
1425 parm |= index << AC_AMP_SET_INDEX_SHIFT;
1427 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
1428 info->vol[ch] = val;
1432 * snd_hda_codec_amp_read - Read AMP value
1433 * @codec: HD-audio codec
1434 * @nid: NID to read the AMP value
1435 * @ch: channel (left=0 or right=1)
1436 * @direction: #HDA_INPUT or #HDA_OUTPUT
1437 * @index: the index value (only for input direction)
1439 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1441 int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1442 int direction, int index)
1444 struct hda_amp_info *info;
1445 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
1448 return get_vol_mute(codec, info, nid, ch, direction, index);
1450 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1453 * snd_hda_codec_amp_update - update the AMP value
1454 * @codec: HD-audio codec
1455 * @nid: NID to read the AMP value
1456 * @ch: channel (left=0 or right=1)
1457 * @direction: #HDA_INPUT or #HDA_OUTPUT
1458 * @idx: the index value (only for input direction)
1459 * @mask: bit mask to set
1460 * @val: the bits value to set
1462 * Update the AMP value with a bit mask.
1463 * Returns 0 if the value is unchanged, 1 if changed.
1465 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1466 int direction, int idx, int mask, int val)
1468 struct hda_amp_info *info;
1470 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
1473 if (snd_BUG_ON(mask & ~0xff))
1476 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
1477 if (info->vol[ch] == val)
1479 put_vol_mute(codec, info, nid, ch, direction, idx, val);
1482 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1485 * snd_hda_codec_amp_stereo - update the AMP stereo values
1486 * @codec: HD-audio codec
1487 * @nid: NID to read the AMP value
1488 * @direction: #HDA_INPUT or #HDA_OUTPUT
1489 * @idx: the index value (only for input direction)
1490 * @mask: bit mask to set
1491 * @val: the bits value to set
1493 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1494 * stereo widget with the same mask and value.
1496 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1497 int direction, int idx, int mask, int val)
1501 if (snd_BUG_ON(mask & ~0xff))
1503 for (ch = 0; ch < 2; ch++)
1504 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1508 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1510 #ifdef SND_HDA_NEEDS_RESUME
1512 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1513 * @codec: HD-audio codec
1515 * Resume the all amp commands from the cache.
1517 void snd_hda_codec_resume_amp(struct hda_codec *codec)
1519 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
1522 for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) {
1523 u32 key = buffer->head.key;
1525 unsigned int idx, dir, ch;
1529 idx = (key >> 16) & 0xff;
1530 dir = (key >> 24) & 0xff;
1531 for (ch = 0; ch < 2; ch++) {
1532 if (!(buffer->head.val & INFO_AMP_VOL(ch)))
1534 put_vol_mute(codec, buffer, nid, ch, dir, idx,
1539 EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1540 #endif /* SND_HDA_NEEDS_RESUME */
1542 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1545 u32 caps = query_amp_caps(codec, nid, dir);
1547 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1554 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1556 * The control element is supposed to have the private_value field
1557 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1559 int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_info *uinfo)
1562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1563 u16 nid = get_amp_nid(kcontrol);
1564 u8 chs = get_amp_channels(kcontrol);
1565 int dir = get_amp_direction(kcontrol);
1566 unsigned int ofs = get_amp_offset(kcontrol);
1568 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1569 uinfo->count = chs == 3 ? 2 : 1;
1570 uinfo->value.integer.min = 0;
1571 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
1572 if (!uinfo->value.integer.max) {
1573 printk(KERN_WARNING "hda_codec: "
1574 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid,
1580 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info);
1583 static inline unsigned int
1584 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1585 int ch, int dir, int idx, unsigned int ofs)
1588 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1589 val &= HDA_AMP_VOLMASK;
1598 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1599 int ch, int dir, int idx, unsigned int ofs,
1602 unsigned int maxval;
1606 maxval = get_amp_max_value(codec, nid, dir, ofs);
1609 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1610 HDA_AMP_VOLMASK, val);
1614 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1616 * The control element is supposed to have the private_value field
1617 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1619 int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1623 hda_nid_t nid = get_amp_nid(kcontrol);
1624 int chs = get_amp_channels(kcontrol);
1625 int dir = get_amp_direction(kcontrol);
1626 int idx = get_amp_index(kcontrol);
1627 unsigned int ofs = get_amp_offset(kcontrol);
1628 long *valp = ucontrol->value.integer.value;
1631 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1633 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1636 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1639 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1641 * The control element is supposed to have the private_value field
1642 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1644 int snd_hda_mixer_amp_volume_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 = get_amp_nid(kcontrol);
1649 int chs = get_amp_channels(kcontrol);
1650 int dir = get_amp_direction(kcontrol);
1651 int idx = get_amp_index(kcontrol);
1652 unsigned int ofs = get_amp_offset(kcontrol);
1653 long *valp = ucontrol->value.integer.value;
1656 snd_hda_power_up(codec);
1658 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1662 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1663 snd_hda_power_down(codec);
1666 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1669 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1671 * The control element is supposed to have the private_value field
1672 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1674 int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1675 unsigned int size, unsigned int __user *_tlv)
1677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1678 hda_nid_t nid = get_amp_nid(kcontrol);
1679 int dir = get_amp_direction(kcontrol);
1680 unsigned int ofs = get_amp_offset(kcontrol);
1681 u32 caps, val1, val2;
1683 if (size < 4 * sizeof(unsigned int))
1685 caps = query_amp_caps(codec, nid, dir);
1686 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1687 val2 = (val2 + 1) * 25;
1688 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1690 val1 = ((int)val1) * ((int)val2);
1691 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
1693 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
1695 if (put_user(val1, _tlv + 2))
1697 if (put_user(val2, _tlv + 3))
1701 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1704 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1705 * @codec: HD-audio codec
1706 * @nid: NID of a reference widget
1707 * @dir: #HDA_INPUT or #HDA_OUTPUT
1708 * @tlv: TLV data to be stored, at least 4 elements
1710 * Set (static) TLV data for a virtual master volume using the AMP caps
1711 * obtained from the reference NID.
1712 * The volume range is recalculated as if the max volume is 0dB.
1714 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1720 caps = query_amp_caps(codec, nid, dir);
1721 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1722 step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1723 step = (step + 1) * 25;
1724 tlv[0] = SNDRV_CTL_TLVT_DB_SCALE;
1725 tlv[1] = 2 * sizeof(unsigned int);
1726 tlv[2] = -nums * step;
1729 EXPORT_SYMBOL_HDA(snd_hda_set_vmaster_tlv);
1731 /* find a mixer control element with the given name */
1732 static struct snd_kcontrol *
1733 _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1734 const char *name, int idx)
1736 struct snd_ctl_elem_id id;
1737 memset(&id, 0, sizeof(id));
1738 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1740 if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
1742 strcpy(id.name, name);
1743 return snd_ctl_find_id(codec->bus->card, &id);
1747 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1748 * @codec: HD-audio codec
1749 * @name: ctl id name string
1751 * Get the control element with the given id string and IFACE_MIXER.
1753 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1756 return _snd_hda_find_mixer_ctl(codec, name, 0);
1758 EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1761 * snd_hda_ctl_add - Add a control element and assign to the codec
1762 * @codec: HD-audio codec
1763 * @nid: corresponding NID (optional)
1764 * @kctl: the control element to assign
1766 * Add the given control element to an array inside the codec instance.
1767 * All control elements belonging to a codec are supposed to be added
1768 * by this function so that a proper clean-up works at the free or
1769 * reconfiguration time.
1771 * If non-zero @nid is passed, the NID is assigned to the control element.
1772 * The assignment is shown in the codec proc file.
1774 * snd_hda_ctl_add() checks the control subdev id field whether
1775 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1776 * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit
1777 * specifies if kctl->private_value is a HDA amplifier value.
1779 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1780 struct snd_kcontrol *kctl)
1783 unsigned short flags = 0;
1784 struct hda_nid_item *item;
1786 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) {
1787 flags |= HDA_NID_ITEM_AMP;
1789 nid = get_amp_nid_(kctl->private_value);
1791 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0)
1792 nid = kctl->id.subdevice & 0xffff;
1793 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
1794 kctl->id.subdevice = 0;
1795 err = snd_ctl_add(codec->bus->card, kctl);
1798 item = snd_array_new(&codec->mixers);
1803 item->flags = flags;
1806 EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1809 * snd_hda_add_nid - Assign a NID to a control element
1810 * @codec: HD-audio codec
1811 * @nid: corresponding NID (optional)
1812 * @kctl: the control element to assign
1813 * @index: index to kctl
1815 * Add the given control element to an array inside the codec instance.
1816 * This function is used when #snd_hda_ctl_add cannot be used for 1:1
1817 * NID:KCTL mapping - for example "Capture Source" selector.
1819 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1820 unsigned int index, hda_nid_t nid)
1822 struct hda_nid_item *item;
1825 item = snd_array_new(&codec->nids);
1829 item->index = index;
1833 printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n",
1834 kctl->id.name, kctl->id.index, index);
1837 EXPORT_SYMBOL_HDA(snd_hda_add_nid);
1840 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1841 * @codec: HD-audio codec
1843 void snd_hda_ctls_clear(struct hda_codec *codec)
1846 struct hda_nid_item *items = codec->mixers.list;
1847 for (i = 0; i < codec->mixers.used; i++)
1848 snd_ctl_remove(codec->bus->card, items[i].kctl);
1849 snd_array_free(&codec->mixers);
1850 snd_array_free(&codec->nids);
1853 /* pseudo device locking
1854 * toggle card->shutdown to allow/disallow the device access (as a hack)
1856 static int hda_lock_devices(struct snd_card *card)
1858 spin_lock(&card->files_lock);
1859 if (card->shutdown) {
1860 spin_unlock(&card->files_lock);
1864 spin_unlock(&card->files_lock);
1868 static void hda_unlock_devices(struct snd_card *card)
1870 spin_lock(&card->files_lock);
1872 spin_unlock(&card->files_lock);
1876 * snd_hda_codec_reset - Clear all objects assigned to the codec
1877 * @codec: HD-audio codec
1879 * This frees the all PCM and control elements assigned to the codec, and
1880 * clears the caches and restores the pin default configurations.
1882 * When a device is being used, it returns -EBSY. If successfully freed,
1885 int snd_hda_codec_reset(struct hda_codec *codec)
1887 struct snd_card *card = codec->bus->card;
1890 if (hda_lock_devices(card) < 0)
1892 /* check whether the codec isn't used by any mixer or PCM streams */
1893 if (!list_empty(&card->ctl_files)) {
1894 hda_unlock_devices(card);
1897 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
1898 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
1901 if (cpcm->pcm->streams[0].substream_opened ||
1902 cpcm->pcm->streams[1].substream_opened) {
1903 hda_unlock_devices(card);
1908 /* OK, let it free */
1910 #ifdef CONFIG_SND_HDA_POWER_SAVE
1911 cancel_delayed_work(&codec->power_work);
1912 flush_workqueue(codec->bus->workq);
1914 snd_hda_ctls_clear(codec);
1916 for (i = 0; i < codec->num_pcms; i++) {
1917 if (codec->pcm_info[i].pcm) {
1918 snd_device_free(card, codec->pcm_info[i].pcm);
1919 clear_bit(codec->pcm_info[i].device,
1920 codec->bus->pcm_dev_bits);
1923 if (codec->patch_ops.free)
1924 codec->patch_ops.free(codec);
1925 codec->proc_widget_hook = NULL;
1927 free_hda_cache(&codec->amp_cache);
1928 free_hda_cache(&codec->cmd_cache);
1929 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1930 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1931 /* free only driver_pins so that init_pins + user_pins are restored */
1932 snd_array_free(&codec->driver_pins);
1933 restore_pincfgs(codec);
1934 codec->num_pcms = 0;
1935 codec->pcm_info = NULL;
1936 codec->preset = NULL;
1937 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
1938 codec->slave_dig_outs = NULL;
1939 codec->spdif_status_reset = 0;
1940 module_put(codec->owner);
1941 codec->owner = NULL;
1943 /* allow device access again */
1944 hda_unlock_devices(card);
1949 * snd_hda_add_vmaster - create a virtual master control and add slaves
1950 * @codec: HD-audio codec
1951 * @name: vmaster control name
1952 * @tlv: TLV data (optional)
1953 * @slaves: slave control names (optional)
1955 * Create a virtual master control with the given name. The TLV data
1956 * must be either NULL or a valid data.
1958 * @slaves is a NULL-terminated array of strings, each of which is a
1959 * slave control name. All controls with these names are assigned to
1960 * the new virtual master control.
1962 * This function returns zero if successful or a negative error code.
1964 int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1965 unsigned int *tlv, const char **slaves)
1967 struct snd_kcontrol *kctl;
1971 for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++)
1974 snd_printdd("No slave found for %s\n", name);
1977 kctl = snd_ctl_make_virtual_master(name, tlv);
1980 err = snd_hda_ctl_add(codec, 0, kctl);
1984 for (s = slaves; *s; s++) {
1985 struct snd_kcontrol *sctl;
1988 sctl = _snd_hda_find_mixer_ctl(codec, *s, i);
1991 snd_printdd("Cannot find slave %s, "
1995 err = snd_ctl_add_slave(kctl, sctl);
2003 EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
2006 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
2008 * The control element is supposed to have the private_value field
2009 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2011 int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
2012 struct snd_ctl_elem_info *uinfo)
2014 int chs = get_amp_channels(kcontrol);
2016 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2017 uinfo->count = chs == 3 ? 2 : 1;
2018 uinfo->value.integer.min = 0;
2019 uinfo->value.integer.max = 1;
2022 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
2025 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2027 * The control element is supposed to have the private_value field
2028 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2030 int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
2031 struct snd_ctl_elem_value *ucontrol)
2033 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2034 hda_nid_t nid = get_amp_nid(kcontrol);
2035 int chs = get_amp_channels(kcontrol);
2036 int dir = get_amp_direction(kcontrol);
2037 int idx = get_amp_index(kcontrol);
2038 long *valp = ucontrol->value.integer.value;
2041 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2042 HDA_AMP_MUTE) ? 0 : 1;
2044 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2045 HDA_AMP_MUTE) ? 0 : 1;
2048 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
2051 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2053 * The control element is supposed to have the private_value field
2054 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2056 int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
2057 struct snd_ctl_elem_value *ucontrol)
2059 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2060 hda_nid_t nid = get_amp_nid(kcontrol);
2061 int chs = get_amp_channels(kcontrol);
2062 int dir = get_amp_direction(kcontrol);
2063 int idx = get_amp_index(kcontrol);
2064 long *valp = ucontrol->value.integer.value;
2067 snd_hda_power_up(codec);
2069 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2071 *valp ? 0 : HDA_AMP_MUTE);
2075 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2077 *valp ? 0 : HDA_AMP_MUTE);
2078 #ifdef CONFIG_SND_HDA_POWER_SAVE
2079 if (codec->patch_ops.check_power_status)
2080 codec->patch_ops.check_power_status(codec, nid);
2082 snd_hda_power_down(codec);
2085 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
2087 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2089 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
2091 * This function calls snd_hda_enable_beep_device(), which behaves differently
2092 * depending on beep_mode option.
2094 int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2095 struct snd_ctl_elem_value *ucontrol)
2097 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2098 long *valp = ucontrol->value.integer.value;
2100 snd_hda_enable_beep_device(codec, *valp);
2101 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2103 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2104 #endif /* CONFIG_SND_HDA_INPUT_BEEP */
2107 * bound volume controls
2109 * bind multiple volumes (# indices, from 0)
2112 #define AMP_VAL_IDX_SHIFT 19
2113 #define AMP_VAL_IDX_MASK (0x0f<<19)
2116 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2118 * The control element is supposed to have the private_value field
2119 * set up via HDA_BIND_MUTE*() macros.
2121 int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
2122 struct snd_ctl_elem_value *ucontrol)
2124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2128 mutex_lock(&codec->control_mutex);
2129 pval = kcontrol->private_value;
2130 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
2131 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
2132 kcontrol->private_value = pval;
2133 mutex_unlock(&codec->control_mutex);
2136 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
2139 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2141 * The control element is supposed to have the private_value field
2142 * set up via HDA_BIND_MUTE*() macros.
2144 int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
2145 struct snd_ctl_elem_value *ucontrol)
2147 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2149 int i, indices, err = 0, change = 0;
2151 mutex_lock(&codec->control_mutex);
2152 pval = kcontrol->private_value;
2153 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
2154 for (i = 0; i < indices; i++) {
2155 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
2156 (i << AMP_VAL_IDX_SHIFT);
2157 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2162 kcontrol->private_value = pval;
2163 mutex_unlock(&codec->control_mutex);
2164 return err < 0 ? err : change;
2166 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
2169 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2171 * The control element is supposed to have the private_value field
2172 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2174 int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
2175 struct snd_ctl_elem_info *uinfo)
2177 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2178 struct hda_bind_ctls *c;
2181 mutex_lock(&codec->control_mutex);
2182 c = (struct hda_bind_ctls *)kcontrol->private_value;
2183 kcontrol->private_value = *c->values;
2184 err = c->ops->info(kcontrol, uinfo);
2185 kcontrol->private_value = (long)c;
2186 mutex_unlock(&codec->control_mutex);
2189 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
2192 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2194 * The control element is supposed to have the private_value field
2195 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2197 int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
2198 struct snd_ctl_elem_value *ucontrol)
2200 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2201 struct hda_bind_ctls *c;
2204 mutex_lock(&codec->control_mutex);
2205 c = (struct hda_bind_ctls *)kcontrol->private_value;
2206 kcontrol->private_value = *c->values;
2207 err = c->ops->get(kcontrol, ucontrol);
2208 kcontrol->private_value = (long)c;
2209 mutex_unlock(&codec->control_mutex);
2212 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
2215 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2217 * The control element is supposed to have the private_value field
2218 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2220 int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
2221 struct snd_ctl_elem_value *ucontrol)
2223 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2224 struct hda_bind_ctls *c;
2225 unsigned long *vals;
2226 int err = 0, change = 0;
2228 mutex_lock(&codec->control_mutex);
2229 c = (struct hda_bind_ctls *)kcontrol->private_value;
2230 for (vals = c->values; *vals; vals++) {
2231 kcontrol->private_value = *vals;
2232 err = c->ops->put(kcontrol, ucontrol);
2237 kcontrol->private_value = (long)c;
2238 mutex_unlock(&codec->control_mutex);
2239 return err < 0 ? err : change;
2241 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
2244 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2246 * The control element is supposed to have the private_value field
2247 * set up via HDA_BIND_VOL() macro.
2249 int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2250 unsigned int size, unsigned int __user *tlv)
2252 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2253 struct hda_bind_ctls *c;
2256 mutex_lock(&codec->control_mutex);
2257 c = (struct hda_bind_ctls *)kcontrol->private_value;
2258 kcontrol->private_value = *c->values;
2259 err = c->ops->tlv(kcontrol, op_flag, size, tlv);
2260 kcontrol->private_value = (long)c;
2261 mutex_unlock(&codec->control_mutex);
2264 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_tlv);
2266 struct hda_ctl_ops snd_hda_bind_vol = {
2267 .info = snd_hda_mixer_amp_volume_info,
2268 .get = snd_hda_mixer_amp_volume_get,
2269 .put = snd_hda_mixer_amp_volume_put,
2270 .tlv = snd_hda_mixer_amp_tlv
2272 EXPORT_SYMBOL_HDA(snd_hda_bind_vol);
2274 struct hda_ctl_ops snd_hda_bind_sw = {
2275 .info = snd_hda_mixer_amp_switch_info,
2276 .get = snd_hda_mixer_amp_switch_get,
2277 .put = snd_hda_mixer_amp_switch_put,
2278 .tlv = snd_hda_mixer_amp_tlv
2280 EXPORT_SYMBOL_HDA(snd_hda_bind_sw);
2283 * SPDIF out controls
2286 static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
2287 struct snd_ctl_elem_info *uinfo)
2289 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2294 static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
2295 struct snd_ctl_elem_value *ucontrol)
2297 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2298 IEC958_AES0_NONAUDIO |
2299 IEC958_AES0_CON_EMPHASIS_5015 |
2300 IEC958_AES0_CON_NOT_COPYRIGHT;
2301 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
2302 IEC958_AES1_CON_ORIGINAL;
2306 static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
2307 struct snd_ctl_elem_value *ucontrol)
2309 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2310 IEC958_AES0_NONAUDIO |
2311 IEC958_AES0_PRO_EMPHASIS_5015;
2315 static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
2316 struct snd_ctl_elem_value *ucontrol)
2318 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2320 ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff;
2321 ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff;
2322 ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff;
2323 ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff;
2328 /* convert from SPDIF status bits to HDA SPDIF bits
2329 * bit 0 (DigEn) is always set zero (to be filled later)
2331 static unsigned short convert_from_spdif_status(unsigned int sbits)
2333 unsigned short val = 0;
2335 if (sbits & IEC958_AES0_PROFESSIONAL)
2336 val |= AC_DIG1_PROFESSIONAL;
2337 if (sbits & IEC958_AES0_NONAUDIO)
2338 val |= AC_DIG1_NONAUDIO;
2339 if (sbits & IEC958_AES0_PROFESSIONAL) {
2340 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
2341 IEC958_AES0_PRO_EMPHASIS_5015)
2342 val |= AC_DIG1_EMPHASIS;
2344 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
2345 IEC958_AES0_CON_EMPHASIS_5015)
2346 val |= AC_DIG1_EMPHASIS;
2347 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
2348 val |= AC_DIG1_COPYRIGHT;
2349 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
2350 val |= AC_DIG1_LEVEL;
2351 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
2356 /* convert to SPDIF status bits from HDA SPDIF bits
2358 static unsigned int convert_to_spdif_status(unsigned short val)
2360 unsigned int sbits = 0;
2362 if (val & AC_DIG1_NONAUDIO)
2363 sbits |= IEC958_AES0_NONAUDIO;
2364 if (val & AC_DIG1_PROFESSIONAL)
2365 sbits |= IEC958_AES0_PROFESSIONAL;
2366 if (sbits & IEC958_AES0_PROFESSIONAL) {
2367 if (sbits & AC_DIG1_EMPHASIS)
2368 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
2370 if (val & AC_DIG1_EMPHASIS)
2371 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
2372 if (!(val & AC_DIG1_COPYRIGHT))
2373 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
2374 if (val & AC_DIG1_LEVEL)
2375 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
2376 sbits |= val & (0x7f << 8);
2381 /* set digital convert verbs both for the given NID and its slaves */
2382 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2387 snd_hda_codec_write_cache(codec, nid, 0, verb, val);
2388 d = codec->slave_dig_outs;
2392 snd_hda_codec_write_cache(codec, *d, 0, verb, val);
2395 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2399 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1);
2401 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2);
2404 static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2408 hda_nid_t nid = kcontrol->private_value;
2412 mutex_lock(&codec->spdif_mutex);
2413 codec->spdif_status = ucontrol->value.iec958.status[0] |
2414 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
2415 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
2416 ((unsigned int)ucontrol->value.iec958.status[3] << 24);
2417 val = convert_from_spdif_status(codec->spdif_status);
2418 val |= codec->spdif_ctls & 1;
2419 change = codec->spdif_ctls != val;
2420 codec->spdif_ctls = val;
2423 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2425 mutex_unlock(&codec->spdif_mutex);
2429 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
2431 static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
2432 struct snd_ctl_elem_value *ucontrol)
2434 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2436 ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE;
2440 static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
2441 struct snd_ctl_elem_value *ucontrol)
2443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2444 hda_nid_t nid = kcontrol->private_value;
2448 mutex_lock(&codec->spdif_mutex);
2449 val = codec->spdif_ctls & ~AC_DIG1_ENABLE;
2450 if (ucontrol->value.integer.value[0])
2451 val |= AC_DIG1_ENABLE;
2452 change = codec->spdif_ctls != val;
2454 codec->spdif_ctls = val;
2455 set_dig_out_convert(codec, nid, val & 0xff, -1);
2456 /* unmute amp switch (if any) */
2457 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2458 (val & AC_DIG1_ENABLE))
2459 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2462 mutex_unlock(&codec->spdif_mutex);
2466 static struct snd_kcontrol_new dig_mixes[] = {
2468 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2469 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2470 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
2471 .info = snd_hda_spdif_mask_info,
2472 .get = snd_hda_spdif_cmask_get,
2475 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2476 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2477 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
2478 .info = snd_hda_spdif_mask_info,
2479 .get = snd_hda_spdif_pmask_get,
2482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2483 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2484 .info = snd_hda_spdif_mask_info,
2485 .get = snd_hda_spdif_default_get,
2486 .put = snd_hda_spdif_default_put,
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2491 .info = snd_hda_spdif_out_switch_info,
2492 .get = snd_hda_spdif_out_switch_get,
2493 .put = snd_hda_spdif_out_switch_put,
2498 #define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
2501 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
2502 * @codec: the HDA codec
2503 * @nid: audio out widget NID
2505 * Creates controls related with the SPDIF output.
2506 * Called from each patch supporting the SPDIF out.
2508 * Returns 0 if successful, or a negative error code.
2510 int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2513 struct snd_kcontrol *kctl;
2514 struct snd_kcontrol_new *dig_mix;
2517 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
2518 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
2522 if (idx >= SPDIF_MAX_IDX) {
2523 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
2526 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
2527 kctl = snd_ctl_new1(dig_mix, codec);
2530 kctl->id.index = idx;
2531 kctl->private_value = nid;
2532 err = snd_hda_ctl_add(codec, nid, kctl);
2537 snd_hda_codec_read(codec, nid, 0,
2538 AC_VERB_GET_DIGI_CONVERT_1, 0);
2539 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
2542 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls);
2545 * SPDIF sharing with analog output
2547 static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
2548 struct snd_ctl_elem_value *ucontrol)
2550 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2551 ucontrol->value.integer.value[0] = mout->share_spdif;
2555 static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
2556 struct snd_ctl_elem_value *ucontrol)
2558 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2559 mout->share_spdif = !!ucontrol->value.integer.value[0];
2563 static struct snd_kcontrol_new spdif_share_sw = {
2564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2565 .name = "IEC958 Default PCM Playback Switch",
2566 .info = snd_ctl_boolean_mono_info,
2567 .get = spdif_share_sw_get,
2568 .put = spdif_share_sw_put,
2572 * snd_hda_create_spdif_share_sw - create Default PCM switch
2573 * @codec: the HDA codec
2574 * @mout: multi-out instance
2576 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2577 struct hda_multi_out *mout)
2579 if (!mout->dig_out_nid)
2581 /* ATTENTION: here mout is passed as private_data, instead of codec */
2582 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2583 snd_ctl_new1(&spdif_share_sw, mout));
2585 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2591 #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
2593 static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol,
2594 struct snd_ctl_elem_value *ucontrol)
2596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
2602 static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
2603 struct snd_ctl_elem_value *ucontrol)
2605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2606 hda_nid_t nid = kcontrol->private_value;
2607 unsigned int val = !!ucontrol->value.integer.value[0];
2610 mutex_lock(&codec->spdif_mutex);
2611 change = codec->spdif_in_enable != val;
2613 codec->spdif_in_enable = val;
2614 snd_hda_codec_write_cache(codec, nid, 0,
2615 AC_VERB_SET_DIGI_CONVERT_1, val);
2617 mutex_unlock(&codec->spdif_mutex);
2621 static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
2622 struct snd_ctl_elem_value *ucontrol)
2624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2625 hda_nid_t nid = kcontrol->private_value;
2629 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
2630 sbits = convert_to_spdif_status(val);
2631 ucontrol->value.iec958.status[0] = sbits;
2632 ucontrol->value.iec958.status[1] = sbits >> 8;
2633 ucontrol->value.iec958.status[2] = sbits >> 16;
2634 ucontrol->value.iec958.status[3] = sbits >> 24;
2638 static struct snd_kcontrol_new dig_in_ctls[] = {
2640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2641 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
2642 .info = snd_hda_spdif_in_switch_info,
2643 .get = snd_hda_spdif_in_switch_get,
2644 .put = snd_hda_spdif_in_switch_put,
2647 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2649 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
2650 .info = snd_hda_spdif_mask_info,
2651 .get = snd_hda_spdif_in_status_get,
2657 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
2658 * @codec: the HDA codec
2659 * @nid: audio in widget NID
2661 * Creates controls related with the SPDIF input.
2662 * Called from each patch supporting the SPDIF in.
2664 * Returns 0 if successful, or a negative error code.
2666 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2669 struct snd_kcontrol *kctl;
2670 struct snd_kcontrol_new *dig_mix;
2673 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
2674 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
2678 if (idx >= SPDIF_MAX_IDX) {
2679 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
2682 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
2683 kctl = snd_ctl_new1(dig_mix, codec);
2686 kctl->private_value = nid;
2687 err = snd_hda_ctl_add(codec, nid, kctl);
2691 codec->spdif_in_enable =
2692 snd_hda_codec_read(codec, nid, 0,
2693 AC_VERB_GET_DIGI_CONVERT_1, 0) &
2697 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
2699 #ifdef SND_HDA_NEEDS_RESUME
2704 /* build a 32bit cache key with the widget id and the command parameter */
2705 #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
2706 #define get_cmd_cache_nid(key) ((key) & 0xff)
2707 #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
2710 * snd_hda_codec_write_cache - send a single command with caching
2711 * @codec: the HDA codec
2712 * @nid: NID to send the command
2713 * @direct: direct flag
2714 * @verb: the verb to send
2715 * @parm: the parameter for the verb
2717 * Send a single command without waiting for response.
2719 * Returns 0 if successful, or a negative error code.
2721 int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2722 int direct, unsigned int verb, unsigned int parm)
2724 int err = snd_hda_codec_write(codec, nid, direct, verb, parm);
2725 struct hda_cache_head *c;
2730 /* parm may contain the verb stuff for get/set amp */
2731 verb = verb | (parm >> 8);
2733 key = build_cmd_cache_key(nid, verb);
2734 mutex_lock(&codec->bus->cmd_mutex);
2735 c = get_alloc_hash(&codec->cmd_cache, key);
2738 mutex_unlock(&codec->bus->cmd_mutex);
2741 EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2744 * snd_hda_codec_update_cache - check cache and write the cmd only when needed
2745 * @codec: the HDA codec
2746 * @nid: NID to send the command
2747 * @direct: direct flag
2748 * @verb: the verb to send
2749 * @parm: the parameter for the verb
2751 * This function works like snd_hda_codec_write_cache(), but it doesn't send
2752 * command if the parameter is already identical with the cached value.
2753 * If not, it sends the command and refreshes the cache.
2755 * Returns 0 if successful, or a negative error code.
2757 int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
2758 int direct, unsigned int verb, unsigned int parm)
2760 struct hda_cache_head *c;
2763 /* parm may contain the verb stuff for get/set amp */
2764 verb = verb | (parm >> 8);
2766 key = build_cmd_cache_key(nid, verb);
2767 mutex_lock(&codec->bus->cmd_mutex);
2768 c = get_hash(&codec->cmd_cache, key);
2769 if (c && c->val == parm) {
2770 mutex_unlock(&codec->bus->cmd_mutex);
2773 mutex_unlock(&codec->bus->cmd_mutex);
2774 return snd_hda_codec_write_cache(codec, nid, direct, verb, parm);
2776 EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache);
2779 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2780 * @codec: HD-audio codec
2782 * Execute all verbs recorded in the command caches to resume.
2784 void snd_hda_codec_resume_cache(struct hda_codec *codec)
2786 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
2789 for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) {
2790 u32 key = buffer->key;
2793 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
2794 get_cmd_cache_cmd(key), buffer->val);
2797 EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache);
2800 * snd_hda_sequence_write_cache - sequence writes with caching
2801 * @codec: the HDA codec
2802 * @seq: VERB array to send
2804 * Send the commands sequentially from the given array.
2805 * Thte commands are recorded on cache for power-save and resume.
2806 * The array must be terminated with NID=0.
2808 void snd_hda_sequence_write_cache(struct hda_codec *codec,
2809 const struct hda_verb *seq)
2811 for (; seq->nid; seq++)
2812 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
2815 EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache);
2816 #endif /* SND_HDA_NEEDS_RESUME */
2819 * set power state of the codec
2821 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2822 unsigned int power_state)
2827 /* this delay seems necessary to avoid click noise at power-down */
2828 if (power_state == AC_PWRST_D3)
2830 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
2832 /* partial workaround for "azx_get_response timeout" */
2833 if (power_state == AC_PWRST_D0 &&
2834 (codec->vendor_id & 0xffff0000) == 0x14f10000)
2837 nid = codec->start_nid;
2838 for (i = 0; i < codec->num_nodes; i++, nid++) {
2839 unsigned int wcaps = get_wcaps(codec, nid);
2840 if (wcaps & AC_WCAP_POWER) {
2841 unsigned int wid_type = get_wcaps_type(wcaps);
2842 if (power_state == AC_PWRST_D3 &&
2843 wid_type == AC_WID_PIN) {
2844 unsigned int pincap;
2846 * don't power down the widget if it controls
2847 * eapd and EAPD_BTLENABLE is set.
2849 pincap = snd_hda_query_pin_caps(codec, nid);
2850 if (pincap & AC_PINCAP_EAPD) {
2851 int eapd = snd_hda_codec_read(codec,
2853 AC_VERB_GET_EAPD_BTLENABLE, 0);
2859 snd_hda_codec_write(codec, nid, 0,
2860 AC_VERB_SET_POWER_STATE,
2865 if (power_state == AC_PWRST_D0) {
2866 unsigned long end_time;
2868 /* wait until the codec reachs to D0 */
2869 end_time = jiffies + msecs_to_jiffies(500);
2871 state = snd_hda_codec_read(codec, fg, 0,
2872 AC_VERB_GET_POWER_STATE, 0);
2873 if (state == power_state)
2876 } while (time_after_eq(end_time, jiffies));
2880 #ifdef CONFIG_SND_HDA_HWDEP
2881 /* execute additional init verbs */
2882 static void hda_exec_init_verbs(struct hda_codec *codec)
2884 if (codec->init_verbs.list)
2885 snd_hda_sequence_write(codec, codec->init_verbs.list);
2888 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2891 #ifdef SND_HDA_NEEDS_RESUME
2893 * call suspend and power-down; used both from PM and power-save
2895 static void hda_call_codec_suspend(struct hda_codec *codec)
2897 if (codec->patch_ops.suspend)
2898 codec->patch_ops.suspend(codec, PMSG_SUSPEND);
2899 hda_set_power_state(codec,
2900 codec->afg ? codec->afg : codec->mfg,
2902 #ifdef CONFIG_SND_HDA_POWER_SAVE
2903 snd_hda_update_power_acct(codec);
2904 cancel_delayed_work(&codec->power_work);
2905 codec->power_on = 0;
2906 codec->power_transition = 0;
2907 codec->power_jiffies = jiffies;
2912 * kick up codec; used both from PM and power-save
2914 static void hda_call_codec_resume(struct hda_codec *codec)
2916 hda_set_power_state(codec,
2917 codec->afg ? codec->afg : codec->mfg,
2919 restore_pincfgs(codec); /* restore all current pin configs */
2920 hda_exec_init_verbs(codec);
2921 if (codec->patch_ops.resume)
2922 codec->patch_ops.resume(codec);
2924 if (codec->patch_ops.init)
2925 codec->patch_ops.init(codec);
2926 snd_hda_codec_resume_amp(codec);
2927 snd_hda_codec_resume_cache(codec);
2930 #endif /* SND_HDA_NEEDS_RESUME */
2934 * snd_hda_build_controls - build mixer controls
2937 * Creates mixer controls for each codec included in the bus.
2939 * Returns 0 if successful, otherwise a negative error code.
2941 int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
2943 struct hda_codec *codec;
2945 list_for_each_entry(codec, &bus->codec_list, list) {
2946 int err = snd_hda_codec_build_controls(codec);
2948 printk(KERN_ERR "hda_codec: cannot build controls "
2949 "for #%d (error %d)\n", codec->addr, err);
2950 err = snd_hda_codec_reset(codec);
2953 "hda_codec: cannot revert codec\n");
2960 EXPORT_SYMBOL_HDA(snd_hda_build_controls);
2962 int snd_hda_codec_build_controls(struct hda_codec *codec)
2965 hda_exec_init_verbs(codec);
2966 /* continue to initialize... */
2967 if (codec->patch_ops.init)
2968 err = codec->patch_ops.init(codec);
2969 if (!err && codec->patch_ops.build_controls)
2970 err = codec->patch_ops.build_controls(codec);
2979 struct hda_rate_tbl {
2981 unsigned int alsa_bits;
2982 unsigned int hda_fmt;
2985 static struct hda_rate_tbl rate_bits[] = {
2986 /* rate in Hz, ALSA rate bitmask, HDA format value */
2988 /* autodetected value used in snd_hda_query_supported_pcm */
2989 { 8000, SNDRV_PCM_RATE_8000, 0x0500 }, /* 1/6 x 48 */
2990 { 11025, SNDRV_PCM_RATE_11025, 0x4300 }, /* 1/4 x 44 */
2991 { 16000, SNDRV_PCM_RATE_16000, 0x0200 }, /* 1/3 x 48 */
2992 { 22050, SNDRV_PCM_RATE_22050, 0x4100 }, /* 1/2 x 44 */
2993 { 32000, SNDRV_PCM_RATE_32000, 0x0a00 }, /* 2/3 x 48 */
2994 { 44100, SNDRV_PCM_RATE_44100, 0x4000 }, /* 44 */
2995 { 48000, SNDRV_PCM_RATE_48000, 0x0000 }, /* 48 */
2996 { 88200, SNDRV_PCM_RATE_88200, 0x4800 }, /* 2 x 44 */
2997 { 96000, SNDRV_PCM_RATE_96000, 0x0800 }, /* 2 x 48 */
2998 { 176400, SNDRV_PCM_RATE_176400, 0x5800 },/* 4 x 44 */
2999 { 192000, SNDRV_PCM_RATE_192000, 0x1800 }, /* 4 x 48 */
3000 #define AC_PAR_PCM_RATE_BITS 11
3001 /* up to bits 10, 384kHZ isn't supported properly */
3003 /* not autodetected value */
3004 { 9600, SNDRV_PCM_RATE_KNOT, 0x0400 }, /* 1/5 x 48 */
3006 { 0 } /* terminator */
3010 * snd_hda_calc_stream_format - calculate format bitset
3011 * @rate: the sample rate
3012 * @channels: the number of channels
3013 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
3014 * @maxbps: the max. bps
3016 * Calculate the format bitset from the given rate, channels and th PCM format.
3018 * Return zero if invalid.
3020 unsigned int snd_hda_calc_stream_format(unsigned int rate,
3021 unsigned int channels,
3022 unsigned int format,
3023 unsigned int maxbps)
3026 unsigned int val = 0;
3028 for (i = 0; rate_bits[i].hz; i++)
3029 if (rate_bits[i].hz == rate) {
3030 val = rate_bits[i].hda_fmt;
3033 if (!rate_bits[i].hz) {
3034 snd_printdd("invalid rate %d\n", rate);
3038 if (channels == 0 || channels > 8) {
3039 snd_printdd("invalid channels %d\n", channels);
3042 val |= channels - 1;
3044 switch (snd_pcm_format_width(format)) {
3054 if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE)
3056 else if (maxbps >= 24)
3062 snd_printdd("invalid format width %d\n",
3063 snd_pcm_format_width(format));
3069 EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
3071 static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3073 unsigned int val = 0;
3074 if (nid != codec->afg &&
3075 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
3076 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
3077 if (!val || val == -1)
3078 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
3079 if (!val || val == -1)
3084 static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3086 return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid),
3090 static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid)
3092 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
3093 if (!streams || streams == -1)
3094 streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
3095 if (!streams || streams == -1)
3100 static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid)
3102 return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid),
3107 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
3108 * @codec: the HDA codec
3109 * @nid: NID to query
3110 * @ratesp: the pointer to store the detected rate bitflags
3111 * @formatsp: the pointer to store the detected formats
3112 * @bpsp: the pointer to store the detected format widths
3114 * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp
3115 * or @bsps argument is ignored.
3117 * Returns 0 if successful, otherwise a negative error code.
3119 static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
3120 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
3122 unsigned int i, val, wcaps;
3124 wcaps = get_wcaps(codec, nid);
3125 val = query_pcm_param(codec, nid);
3129 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) {
3131 rates |= rate_bits[i].alsa_bits;
3134 snd_printk(KERN_ERR "hda_codec: rates == 0 "
3135 "(nid=0x%x, val=0x%x, ovrd=%i)\n",
3137 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0);
3143 if (formatsp || bpsp) {
3145 unsigned int streams, bps;
3147 streams = query_stream_param(codec, nid);
3152 if (streams & AC_SUPFMT_PCM) {
3153 if (val & AC_SUPPCM_BITS_8) {
3154 formats |= SNDRV_PCM_FMTBIT_U8;
3157 if (val & AC_SUPPCM_BITS_16) {
3158 formats |= SNDRV_PCM_FMTBIT_S16_LE;
3161 if (wcaps & AC_WCAP_DIGITAL) {
3162 if (val & AC_SUPPCM_BITS_32)
3163 formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
3164 if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24))
3165 formats |= SNDRV_PCM_FMTBIT_S32_LE;
3166 if (val & AC_SUPPCM_BITS_24)
3168 else if (val & AC_SUPPCM_BITS_20)
3170 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|
3171 AC_SUPPCM_BITS_32)) {
3172 formats |= SNDRV_PCM_FMTBIT_S32_LE;
3173 if (val & AC_SUPPCM_BITS_32)
3175 else if (val & AC_SUPPCM_BITS_24)
3177 else if (val & AC_SUPPCM_BITS_20)
3181 if (streams & AC_SUPFMT_FLOAT32) {
3182 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
3186 if (streams == AC_SUPFMT_AC3) {
3187 /* should be exclusive */
3188 /* temporary hack: we have still no proper support
3189 * for the direct AC3 stream...
3191 formats |= SNDRV_PCM_FMTBIT_U8;
3195 snd_printk(KERN_ERR "hda_codec: formats == 0 "
3196 "(nid=0x%x, val=0x%x, ovrd=%i, "
3199 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0,
3204 *formatsp = formats;
3213 * snd_hda_is_supported_format - Check the validity of the format
3214 * @codec: HD-audio codec
3215 * @nid: NID to check
3216 * @format: the HD-audio format value to check
3218 * Check whether the given node supports the format value.
3220 * Returns 1 if supported, 0 if not.
3222 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
3223 unsigned int format)
3226 unsigned int val = 0, rate, stream;
3228 val = query_pcm_param(codec, nid);
3232 rate = format & 0xff00;
3233 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++)
3234 if (rate_bits[i].hda_fmt == rate) {
3239 if (i >= AC_PAR_PCM_RATE_BITS)
3242 stream = query_stream_param(codec, nid);
3246 if (stream & AC_SUPFMT_PCM) {
3247 switch (format & 0xf0) {
3249 if (!(val & AC_SUPPCM_BITS_8))
3253 if (!(val & AC_SUPPCM_BITS_16))
3257 if (!(val & AC_SUPPCM_BITS_20))
3261 if (!(val & AC_SUPPCM_BITS_24))
3265 if (!(val & AC_SUPPCM_BITS_32))
3272 /* FIXME: check for float32 and AC3? */
3277 EXPORT_SYMBOL_HDA(snd_hda_is_supported_format);
3282 static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
3283 struct hda_codec *codec,
3284 struct snd_pcm_substream *substream)
3289 static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
3290 struct hda_codec *codec,
3291 unsigned int stream_tag,
3292 unsigned int format,
3293 struct snd_pcm_substream *substream)
3295 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3299 static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
3300 struct hda_codec *codec,
3301 struct snd_pcm_substream *substream)
3303 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3307 static int set_pcm_default_values(struct hda_codec *codec,
3308 struct hda_pcm_stream *info)
3312 /* query support PCM information from the given NID */
3313 if (info->nid && (!info->rates || !info->formats)) {
3314 err = snd_hda_query_supported_pcm(codec, info->nid,
3315 info->rates ? NULL : &info->rates,
3316 info->formats ? NULL : &info->formats,
3317 info->maxbps ? NULL : &info->maxbps);
3321 if (info->ops.open == NULL)
3322 info->ops.open = hda_pcm_default_open_close;
3323 if (info->ops.close == NULL)
3324 info->ops.close = hda_pcm_default_open_close;
3325 if (info->ops.prepare == NULL) {
3326 if (snd_BUG_ON(!info->nid))
3328 info->ops.prepare = hda_pcm_default_prepare;
3330 if (info->ops.cleanup == NULL) {
3331 if (snd_BUG_ON(!info->nid))
3333 info->ops.cleanup = hda_pcm_default_cleanup;
3339 const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3340 "Audio", "SPDIF", "HDMI", "Modem"
3344 * get the empty PCM device number to assign
3346 * note the max device number is limited by HDA_MAX_PCMS, currently 10
3348 static int get_empty_pcm_device(struct hda_bus *bus, int type)
3350 /* audio device indices; not linear to keep compatibility */
3351 static int audio_idx[HDA_PCM_NTYPES][5] = {
3352 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
3353 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
3354 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
3355 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
3359 if (type >= HDA_PCM_NTYPES) {
3360 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
3364 for (i = 0; audio_idx[type][i] >= 0 ; i++)
3365 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3366 return audio_idx[type][i];
3368 snd_printk(KERN_WARNING "Too many %s devices\n",
3369 snd_hda_pcm_type_name[type]);
3374 * attach a new PCM stream
3376 static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
3378 struct hda_bus *bus = codec->bus;
3379 struct hda_pcm_stream *info;
3382 if (snd_BUG_ON(!pcm->name))
3384 for (stream = 0; stream < 2; stream++) {
3385 info = &pcm->stream[stream];
3386 if (info->substreams) {
3387 err = set_pcm_default_values(codec, info);
3392 return bus->ops.attach_pcm(bus, codec, pcm);
3395 /* assign all PCMs of the given codec */
3396 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3401 if (!codec->num_pcms) {
3402 if (!codec->patch_ops.build_pcms)
3404 err = codec->patch_ops.build_pcms(codec);
3406 printk(KERN_ERR "hda_codec: cannot build PCMs"
3407 "for #%d (error %d)\n", codec->addr, err);
3408 err = snd_hda_codec_reset(codec);
3411 "hda_codec: cannot revert codec\n");
3416 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
3417 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
3420 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
3421 continue; /* no substreams assigned */
3424 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type);
3426 continue; /* no fatal error */
3428 err = snd_hda_attach_pcm(codec, cpcm);
3430 printk(KERN_ERR "hda_codec: cannot attach "
3431 "PCM stream %d for codec #%d\n",
3433 continue; /* no fatal error */
3441 * snd_hda_build_pcms - build PCM information
3444 * Create PCM information for each codec included in the bus.
3446 * The build_pcms codec patch is requested to set up codec->num_pcms and
3447 * codec->pcm_info properly. The array is referred by the top-level driver
3448 * to create its PCM instances.
3449 * The allocated codec->pcm_info should be released in codec->patch_ops.free
3452 * At least, substreams, channels_min and channels_max must be filled for
3453 * each stream. substreams = 0 indicates that the stream doesn't exist.
3454 * When rates and/or formats are zero, the supported values are queried
3455 * from the given nid. The nid is used also by the default ops.prepare
3456 * and ops.cleanup callbacks.
3458 * The driver needs to call ops.open in its open callback. Similarly,
3459 * ops.close is supposed to be called in the close callback.
3460 * ops.prepare should be called in the prepare or hw_params callback
3461 * with the proper parameters for set up.
3462 * ops.cleanup should be called in hw_free for clean up of streams.
3464 * This function returns 0 if successfull, or a negative error code.
3466 int __devinit snd_hda_build_pcms(struct hda_bus *bus)
3468 struct hda_codec *codec;
3470 list_for_each_entry(codec, &bus->codec_list, list) {
3471 int err = snd_hda_codec_build_pcms(codec);
3477 EXPORT_SYMBOL_HDA(snd_hda_build_pcms);
3480 * snd_hda_check_board_config - compare the current codec with the config table
3481 * @codec: the HDA codec
3482 * @num_configs: number of config enums
3483 * @models: array of model name strings
3484 * @tbl: configuration table, terminated by null entries
3486 * Compares the modelname or PCI subsystem id of the current codec with the
3487 * given configuration table. If a matching entry is found, returns its
3488 * config value (supposed to be 0 or positive).
3490 * If no entries are matching, the function returns a negative value.
3492 int snd_hda_check_board_config(struct hda_codec *codec,
3493 int num_configs, const char **models,
3494 const struct snd_pci_quirk *tbl)
3496 if (codec->modelname && models) {
3498 for (i = 0; i < num_configs; i++) {
3500 !strcmp(codec->modelname, models[i])) {
3501 snd_printd(KERN_INFO "hda_codec: model '%s' is "
3502 "selected\n", models[i]);
3508 if (!codec->bus->pci || !tbl)
3511 tbl = snd_pci_quirk_lookup(codec->bus->pci, tbl);
3514 if (tbl->value >= 0 && tbl->value < num_configs) {
3515 #ifdef CONFIG_SND_DEBUG_VERBOSE
3517 const char *model = NULL;
3519 model = models[tbl->value];
3521 sprintf(tmp, "#%d", tbl->value);
3524 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
3525 "for config %x:%x (%s)\n",
3526 model, tbl->subvendor, tbl->subdevice,
3527 (tbl->name ? tbl->name : "Unknown device"));
3533 EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
3536 * snd_hda_check_board_codec_sid_config - compare the current codec
3537 subsystem ID with the
3540 This is important for Gateway notebooks with SB450 HDA Audio
3541 where the vendor ID of the PCI device is:
3542 ATI Technologies Inc SB450 HDA Audio [1002:437b]
3543 and the vendor/subvendor are found only at the codec.
3545 * @codec: the HDA codec
3546 * @num_configs: number of config enums
3547 * @models: array of model name strings
3548 * @tbl: configuration table, terminated by null entries
3550 * Compares the modelname or PCI subsystem id of the current codec with the
3551 * given configuration table. If a matching entry is found, returns its
3552 * config value (supposed to be 0 or positive).
3554 * If no entries are matching, the function returns a negative value.
3556 int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
3557 int num_configs, const char **models,
3558 const struct snd_pci_quirk *tbl)
3560 const struct snd_pci_quirk *q;
3562 /* Search for codec ID */
3563 for (q = tbl; q->subvendor; q++) {
3564 unsigned long vendorid = (q->subdevice) | (q->subvendor << 16);
3566 if (vendorid == codec->subsystem_id)
3575 if (tbl->value >= 0 && tbl->value < num_configs) {
3576 #ifdef CONFIG_SND_DEBUG_VERBOSE
3578 const char *model = NULL;
3580 model = models[tbl->value];
3582 sprintf(tmp, "#%d", tbl->value);
3585 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
3586 "for config %x:%x (%s)\n",
3587 model, tbl->subvendor, tbl->subdevice,
3588 (tbl->name ? tbl->name : "Unknown device"));
3594 EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3597 * snd_hda_add_new_ctls - create controls from the array
3598 * @codec: the HDA codec
3599 * @knew: the array of struct snd_kcontrol_new
3601 * This helper function creates and add new controls in the given array.
3602 * The array must be terminated with an empty entry as terminator.
3604 * Returns 0 if successful, or a negative error code.
3606 int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3610 for (; knew->name; knew++) {
3611 struct snd_kcontrol *kctl;
3612 if (knew->iface == -1) /* skip this codec private value */
3614 kctl = snd_ctl_new1(knew, codec);
3617 err = snd_hda_ctl_add(codec, 0, kctl);
3621 kctl = snd_ctl_new1(knew, codec);
3624 kctl->id.device = codec->addr;
3625 err = snd_hda_ctl_add(codec, 0, kctl);
3632 EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);
3634 #ifdef CONFIG_SND_HDA_POWER_SAVE
3635 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
3636 unsigned int power_state);
3638 static void hda_power_work(struct work_struct *work)
3640 struct hda_codec *codec =
3641 container_of(work, struct hda_codec, power_work.work);
3642 struct hda_bus *bus = codec->bus;
3644 if (!codec->power_on || codec->power_count) {
3645 codec->power_transition = 0;
3649 hda_call_codec_suspend(codec);
3650 if (bus->ops.pm_notify)
3651 bus->ops.pm_notify(bus);
3654 static void hda_keep_power_on(struct hda_codec *codec)
3656 codec->power_count++;
3657 codec->power_on = 1;
3658 codec->power_jiffies = jiffies;
3661 /* update the power on/off account with the current jiffies */
3662 void snd_hda_update_power_acct(struct hda_codec *codec)
3664 unsigned long delta = jiffies - codec->power_jiffies;
3665 if (codec->power_on)
3666 codec->power_on_acct += delta;
3668 codec->power_off_acct += delta;
3669 codec->power_jiffies += delta;
3673 * snd_hda_power_up - Power-up the codec
3674 * @codec: HD-audio codec
3676 * Increment the power-up counter and power up the hardware really when
3677 * not turned on yet.
3679 void snd_hda_power_up(struct hda_codec *codec)
3681 struct hda_bus *bus = codec->bus;
3683 codec->power_count++;
3684 if (codec->power_on || codec->power_transition)
3687 snd_hda_update_power_acct(codec);
3688 codec->power_on = 1;
3689 codec->power_jiffies = jiffies;
3690 if (bus->ops.pm_notify)
3691 bus->ops.pm_notify(bus);
3692 hda_call_codec_resume(codec);
3693 cancel_delayed_work(&codec->power_work);
3694 codec->power_transition = 0;
3696 EXPORT_SYMBOL_HDA(snd_hda_power_up);
3698 #define power_save(codec) \
3699 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3702 * snd_hda_power_down - Power-down the codec
3703 * @codec: HD-audio codec
3705 * Decrement the power-up counter and schedules the power-off work if
3706 * the counter rearches to zero.
3708 void snd_hda_power_down(struct hda_codec *codec)
3710 --codec->power_count;
3711 if (!codec->power_on || codec->power_count || codec->power_transition)
3713 if (power_save(codec)) {
3714 codec->power_transition = 1; /* avoid reentrance */
3715 queue_delayed_work(codec->bus->workq, &codec->power_work,
3716 msecs_to_jiffies(power_save(codec) * 1000));
3719 EXPORT_SYMBOL_HDA(snd_hda_power_down);
3722 * snd_hda_check_amp_list_power - Check the amp list and update the power
3723 * @codec: HD-audio codec
3724 * @check: the object containing an AMP list and the status
3725 * @nid: NID to check / update
3727 * Check whether the given NID is in the amp list. If it's in the list,
3728 * check the current AMP status, and update the the power-status according
3729 * to the mute status.
3731 * This function is supposed to be set or called from the check_power_status
3734 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3735 struct hda_loopback_check *check,
3738 struct hda_amp_list *p;
3741 if (!check->amplist)
3743 for (p = check->amplist; p->nid; p++) {
3748 return 0; /* nothing changed */
3750 for (p = check->amplist; p->nid; p++) {
3751 for (ch = 0; ch < 2; ch++) {
3752 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3754 if (!(v & HDA_AMP_MUTE) && v > 0) {
3755 if (!check->power_on) {
3756 check->power_on = 1;
3757 snd_hda_power_up(codec);
3763 if (check->power_on) {
3764 check->power_on = 0;
3765 snd_hda_power_down(codec);
3769 EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3773 * Channel mode helper
3777 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3779 int snd_hda_ch_mode_info(struct hda_codec *codec,
3780 struct snd_ctl_elem_info *uinfo,
3781 const struct hda_channel_mode *chmode,
3784 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3786 uinfo->value.enumerated.items = num_chmodes;
3787 if (uinfo->value.enumerated.item >= num_chmodes)
3788 uinfo->value.enumerated.item = num_chmodes - 1;
3789 sprintf(uinfo->value.enumerated.name, "%dch",
3790 chmode[uinfo->value.enumerated.item].channels);
3793 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3796 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3798 int snd_hda_ch_mode_get(struct hda_codec *codec,
3799 struct snd_ctl_elem_value *ucontrol,
3800 const struct hda_channel_mode *chmode,
3806 for (i = 0; i < num_chmodes; i++) {
3807 if (max_channels == chmode[i].channels) {
3808 ucontrol->value.enumerated.item[0] = i;
3814 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3817 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3819 int snd_hda_ch_mode_put(struct hda_codec *codec,
3820 struct snd_ctl_elem_value *ucontrol,
3821 const struct hda_channel_mode *chmode,
3827 mode = ucontrol->value.enumerated.item[0];
3828 if (mode >= num_chmodes)
3830 if (*max_channelsp == chmode[mode].channels)
3832 /* change the current channel setting */
3833 *max_channelsp = chmode[mode].channels;
3834 if (chmode[mode].sequence)
3835 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
3838 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3845 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3847 int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3848 struct snd_ctl_elem_info *uinfo)
3852 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3854 uinfo->value.enumerated.items = imux->num_items;
3855 if (!imux->num_items)
3857 index = uinfo->value.enumerated.item;
3858 if (index >= imux->num_items)
3859 index = imux->num_items - 1;
3860 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
3863 EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3866 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3868 int snd_hda_input_mux_put(struct hda_codec *codec,
3869 const struct hda_input_mux *imux,
3870 struct snd_ctl_elem_value *ucontrol,
3872 unsigned int *cur_val)
3876 if (!imux->num_items)
3878 idx = ucontrol->value.enumerated.item[0];
3879 if (idx >= imux->num_items)
3880 idx = imux->num_items - 1;
3881 if (*cur_val == idx)
3883 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3884 imux->items[idx].index);
3888 EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
3892 * Multi-channel / digital-out PCM helper functions
3895 /* setup SPDIF output stream */
3896 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3897 unsigned int stream_tag, unsigned int format)
3899 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3900 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3901 set_dig_out_convert(codec, nid,
3902 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
3904 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3905 if (codec->slave_dig_outs) {
3907 for (d = codec->slave_dig_outs; *d; d++)
3908 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3911 /* turn on again (if needed) */
3912 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3913 set_dig_out_convert(codec, nid,
3914 codec->spdif_ctls & 0xff, -1);
3917 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3919 snd_hda_codec_cleanup_stream(codec, nid);
3920 if (codec->slave_dig_outs) {
3922 for (d = codec->slave_dig_outs; *d; d++)
3923 snd_hda_codec_cleanup_stream(codec, *d);
3928 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3929 * @bus: HD-audio bus
3931 void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3933 struct hda_codec *codec;
3937 list_for_each_entry(codec, &bus->codec_list, list) {
3938 #ifdef CONFIG_SND_HDA_POWER_SAVE
3939 if (!codec->power_on)
3942 if (codec->patch_ops.reboot_notify)
3943 codec->patch_ops.reboot_notify(codec);
3946 EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3949 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3951 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3952 struct hda_multi_out *mout)
3954 mutex_lock(&codec->spdif_mutex);
3955 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
3956 /* already opened as analog dup; reset it once */
3957 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3958 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
3959 mutex_unlock(&codec->spdif_mutex);
3962 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3965 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3967 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3968 struct hda_multi_out *mout,
3969 unsigned int stream_tag,
3970 unsigned int format,
3971 struct snd_pcm_substream *substream)
3973 mutex_lock(&codec->spdif_mutex);
3974 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3975 mutex_unlock(&codec->spdif_mutex);
3978 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3981 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3983 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3984 struct hda_multi_out *mout)
3986 mutex_lock(&codec->spdif_mutex);
3987 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3988 mutex_unlock(&codec->spdif_mutex);
3991 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3994 * snd_hda_multi_out_dig_close - release the digital out stream
3996 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3997 struct hda_multi_out *mout)
3999 mutex_lock(&codec->spdif_mutex);
4000 mout->dig_out_used = 0;
4001 mutex_unlock(&codec->spdif_mutex);
4004 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
4007 * snd_hda_multi_out_analog_open - open analog outputs
4009 * Open analog outputs and set up the hw-constraints.
4010 * If the digital outputs can be opened as slave, open the digital
4013 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
4014 struct hda_multi_out *mout,
4015 struct snd_pcm_substream *substream,
4016 struct hda_pcm_stream *hinfo)
4018 struct snd_pcm_runtime *runtime = substream->runtime;
4019 runtime->hw.channels_max = mout->max_channels;
4020 if (mout->dig_out_nid) {
4021 if (!mout->analog_rates) {
4022 mout->analog_rates = hinfo->rates;
4023 mout->analog_formats = hinfo->formats;
4024 mout->analog_maxbps = hinfo->maxbps;
4026 runtime->hw.rates = mout->analog_rates;
4027 runtime->hw.formats = mout->analog_formats;
4028 hinfo->maxbps = mout->analog_maxbps;
4030 if (!mout->spdif_rates) {
4031 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
4033 &mout->spdif_formats,
4034 &mout->spdif_maxbps);
4036 mutex_lock(&codec->spdif_mutex);
4037 if (mout->share_spdif) {
4038 if ((runtime->hw.rates & mout->spdif_rates) &&
4039 (runtime->hw.formats & mout->spdif_formats)) {
4040 runtime->hw.rates &= mout->spdif_rates;
4041 runtime->hw.formats &= mout->spdif_formats;
4042 if (mout->spdif_maxbps < hinfo->maxbps)
4043 hinfo->maxbps = mout->spdif_maxbps;
4045 mout->share_spdif = 0;
4046 /* FIXME: need notify? */
4049 mutex_unlock(&codec->spdif_mutex);
4051 return snd_pcm_hw_constraint_step(substream->runtime, 0,
4052 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
4054 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
4057 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
4059 * Set up the i/o for analog out.
4060 * When the digital out is available, copy the front out to digital out, too.
4062 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
4063 struct hda_multi_out *mout,
4064 unsigned int stream_tag,
4065 unsigned int format,
4066 struct snd_pcm_substream *substream)
4068 hda_nid_t *nids = mout->dac_nids;
4069 int chs = substream->runtime->channels;
4072 mutex_lock(&codec->spdif_mutex);
4073 if (mout->dig_out_nid && mout->share_spdif &&
4074 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
4076 snd_hda_is_supported_format(codec, mout->dig_out_nid,
4078 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
4079 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
4080 setup_dig_out_stream(codec, mout->dig_out_nid,
4081 stream_tag, format);
4083 mout->dig_out_used = 0;
4084 cleanup_dig_out_stream(codec, mout->dig_out_nid);
4087 mutex_unlock(&codec->spdif_mutex);
4090 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
4092 if (!mout->no_share_stream &&
4093 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
4094 /* headphone out will just decode front left/right (stereo) */
4095 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
4097 /* extra outputs copied from front */
4098 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4099 if (!mout->no_share_stream && mout->extra_out_nid[i])
4100 snd_hda_codec_setup_stream(codec,
4101 mout->extra_out_nid[i],
4102 stream_tag, 0, format);
4105 for (i = 1; i < mout->num_dacs; i++) {
4106 if (chs >= (i + 1) * 2) /* independent out */
4107 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
4109 else if (!mout->no_share_stream) /* copy front */
4110 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
4115 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
4118 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
4120 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
4121 struct hda_multi_out *mout)
4123 hda_nid_t *nids = mout->dac_nids;
4126 for (i = 0; i < mout->num_dacs; i++)
4127 snd_hda_codec_cleanup_stream(codec, nids[i]);
4129 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
4130 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4131 if (mout->extra_out_nid[i])
4132 snd_hda_codec_cleanup_stream(codec,
4133 mout->extra_out_nid[i]);
4134 mutex_lock(&codec->spdif_mutex);
4135 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
4136 cleanup_dig_out_stream(codec, mout->dig_out_nid);
4137 mout->dig_out_used = 0;
4139 mutex_unlock(&codec->spdif_mutex);
4142 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
4145 * Helper for automatic pin configuration
4148 static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
4150 for (; *list; list++)
4158 * Sort an associated group of pins according to their sequence numbers.
4160 static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
4167 for (i = 0; i < num_pins; i++) {
4168 for (j = i + 1; j < num_pins; j++) {
4169 if (sequences[i] > sequences[j]) {
4171 sequences[i] = sequences[j];
4183 * Parse all pin widgets and store the useful pin nids to cfg
4185 * The number of line-outs or any primary output is stored in line_outs,
4186 * and the corresponding output pins are assigned to line_out_pins[],
4187 * in the order of front, rear, CLFE, side, ...
4189 * If more extra outputs (speaker and headphone) are found, the pins are
4190 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
4191 * is detected, one of speaker of HP pins is assigned as the primary
4192 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
4193 * if any analog output exists.
4195 * The analog input pins are assigned to input_pins array.
4196 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
4199 int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4200 struct auto_pin_cfg *cfg,
4201 hda_nid_t *ignore_nids)
4203 hda_nid_t nid, end_nid;
4204 short seq, assoc_line_out, assoc_speaker;
4205 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
4206 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
4207 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
4209 memset(cfg, 0, sizeof(*cfg));
4211 memset(sequences_line_out, 0, sizeof(sequences_line_out));
4212 memset(sequences_speaker, 0, sizeof(sequences_speaker));
4213 memset(sequences_hp, 0, sizeof(sequences_hp));
4214 assoc_line_out = assoc_speaker = 0;
4216 end_nid = codec->start_nid + codec->num_nodes;
4217 for (nid = codec->start_nid; nid < end_nid; nid++) {
4218 unsigned int wid_caps = get_wcaps(codec, nid);
4219 unsigned int wid_type = get_wcaps_type(wid_caps);
4220 unsigned int def_conf;
4223 /* read all default configuration for pin complex */
4224 if (wid_type != AC_WID_PIN)
4226 /* ignore the given nids (e.g. pc-beep returns error) */
4227 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
4230 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4231 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
4233 loc = get_defcfg_location(def_conf);
4234 switch (get_defcfg_device(def_conf)) {
4235 case AC_JACK_LINE_OUT:
4236 seq = get_defcfg_sequence(def_conf);
4237 assoc = get_defcfg_association(def_conf);
4239 if (!(wid_caps & AC_WCAP_STEREO))
4240 if (!cfg->mono_out_pin)
4241 cfg->mono_out_pin = nid;
4244 if (!assoc_line_out)
4245 assoc_line_out = assoc;
4246 else if (assoc_line_out != assoc)
4248 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
4250 cfg->line_out_pins[cfg->line_outs] = nid;
4251 sequences_line_out[cfg->line_outs] = seq;
4254 case AC_JACK_SPEAKER:
4255 seq = get_defcfg_sequence(def_conf);
4256 assoc = get_defcfg_association(def_conf);
4260 assoc_speaker = assoc;
4261 else if (assoc_speaker != assoc)
4263 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
4265 cfg->speaker_pins[cfg->speaker_outs] = nid;
4266 sequences_speaker[cfg->speaker_outs] = seq;
4267 cfg->speaker_outs++;
4269 case AC_JACK_HP_OUT:
4270 seq = get_defcfg_sequence(def_conf);
4271 assoc = get_defcfg_association(def_conf);
4272 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
4274 cfg->hp_pins[cfg->hp_outs] = nid;
4275 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
4278 case AC_JACK_MIC_IN: {
4280 if (loc == AC_JACK_LOC_FRONT ||
4281 (loc & 0x30) == AC_JACK_LOC_INTERNAL) {
4282 preferred = AUTO_PIN_FRONT_MIC;
4285 preferred = AUTO_PIN_MIC;
4286 alt = AUTO_PIN_FRONT_MIC;
4288 if (!cfg->input_pins[preferred])
4289 cfg->input_pins[preferred] = nid;
4290 else if (!cfg->input_pins[alt])
4291 cfg->input_pins[alt] = nid;
4294 case AC_JACK_LINE_IN:
4295 if (loc == AC_JACK_LOC_FRONT)
4296 cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid;
4298 cfg->input_pins[AUTO_PIN_LINE] = nid;
4301 cfg->input_pins[AUTO_PIN_CD] = nid;
4304 cfg->input_pins[AUTO_PIN_AUX] = nid;
4306 case AC_JACK_SPDIF_OUT:
4307 case AC_JACK_DIG_OTHER_OUT:
4308 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
4310 cfg->dig_out_pins[cfg->dig_outs] = nid;
4311 cfg->dig_out_type[cfg->dig_outs] =
4312 (loc == AC_JACK_LOC_HDMI) ?
4313 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
4316 case AC_JACK_SPDIF_IN:
4317 case AC_JACK_DIG_OTHER_IN:
4318 cfg->dig_in_pin = nid;
4319 if (loc == AC_JACK_LOC_HDMI)
4320 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
4322 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
4328 * If no line-out is defined but multiple HPs are found,
4329 * some of them might be the real line-outs.
4331 if (!cfg->line_outs && cfg->hp_outs > 1) {
4333 while (i < cfg->hp_outs) {
4334 /* The real HPs should have the sequence 0x0f */
4335 if ((sequences_hp[i] & 0x0f) == 0x0f) {
4339 /* Move it to the line-out table */
4340 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
4341 sequences_line_out[cfg->line_outs] = sequences_hp[i];
4344 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
4345 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
4346 memmove(sequences_hp + i - 1, sequences_hp + i,
4347 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
4351 /* sort by sequence */
4352 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
4354 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
4356 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
4359 /* if we have only one mic, make it AUTO_PIN_MIC */
4360 if (!cfg->input_pins[AUTO_PIN_MIC] &&
4361 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
4362 cfg->input_pins[AUTO_PIN_MIC] =
4363 cfg->input_pins[AUTO_PIN_FRONT_MIC];
4364 cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0;
4366 /* ditto for line-in */
4367 if (!cfg->input_pins[AUTO_PIN_LINE] &&
4368 cfg->input_pins[AUTO_PIN_FRONT_LINE]) {
4369 cfg->input_pins[AUTO_PIN_LINE] =
4370 cfg->input_pins[AUTO_PIN_FRONT_LINE];
4371 cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0;
4375 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
4376 * as a primary output
4378 if (!cfg->line_outs) {
4379 if (cfg->speaker_outs) {
4380 cfg->line_outs = cfg->speaker_outs;
4381 memcpy(cfg->line_out_pins, cfg->speaker_pins,
4382 sizeof(cfg->speaker_pins));
4383 cfg->speaker_outs = 0;
4384 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
4385 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
4386 } else if (cfg->hp_outs) {
4387 cfg->line_outs = cfg->hp_outs;
4388 memcpy(cfg->line_out_pins, cfg->hp_pins,
4389 sizeof(cfg->hp_pins));
4391 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4392 cfg->line_out_type = AUTO_PIN_HP_OUT;
4396 /* Reorder the surround channels
4397 * ALSA sequence is front/surr/clfe/side
4399 * 4-ch: front/surr => OK as it is
4400 * 6-ch: front/clfe/surr
4401 * 8-ch: front/clfe/rear/side|fc
4403 switch (cfg->line_outs) {
4406 nid = cfg->line_out_pins[1];
4407 cfg->line_out_pins[1] = cfg->line_out_pins[2];
4408 cfg->line_out_pins[2] = nid;
4413 * debug prints of the parsed results
4415 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4416 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
4417 cfg->line_out_pins[2], cfg->line_out_pins[3],
4418 cfg->line_out_pins[4]);
4419 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4420 cfg->speaker_outs, cfg->speaker_pins[0],
4421 cfg->speaker_pins[1], cfg->speaker_pins[2],
4422 cfg->speaker_pins[3], cfg->speaker_pins[4]);
4423 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4424 cfg->hp_outs, cfg->hp_pins[0],
4425 cfg->hp_pins[1], cfg->hp_pins[2],
4426 cfg->hp_pins[3], cfg->hp_pins[4]);
4427 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
4429 snd_printd(" dig-out=0x%x/0x%x\n",
4430 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
4431 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
4432 " cd=0x%x, aux=0x%x\n",
4433 cfg->input_pins[AUTO_PIN_MIC],
4434 cfg->input_pins[AUTO_PIN_FRONT_MIC],
4435 cfg->input_pins[AUTO_PIN_LINE],
4436 cfg->input_pins[AUTO_PIN_FRONT_LINE],
4437 cfg->input_pins[AUTO_PIN_CD],
4438 cfg->input_pins[AUTO_PIN_AUX]);
4439 if (cfg->dig_in_pin)
4440 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
4444 EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
4446 /* labels for input pins */
4447 const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
4448 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
4450 EXPORT_SYMBOL_HDA(auto_pin_cfg_labels);
4459 * snd_hda_suspend - suspend the codecs
4462 * Returns 0 if successful.
4464 int snd_hda_suspend(struct hda_bus *bus)
4466 struct hda_codec *codec;
4468 list_for_each_entry(codec, &bus->codec_list, list) {
4469 #ifdef CONFIG_SND_HDA_POWER_SAVE
4470 if (!codec->power_on)
4473 hda_call_codec_suspend(codec);
4477 EXPORT_SYMBOL_HDA(snd_hda_suspend);
4480 * snd_hda_resume - resume the codecs
4483 * Returns 0 if successful.
4485 * This fucntion is defined only when POWER_SAVE isn't set.
4486 * In the power-save mode, the codec is resumed dynamically.
4488 int snd_hda_resume(struct hda_bus *bus)
4490 struct hda_codec *codec;
4492 list_for_each_entry(codec, &bus->codec_list, list) {
4493 if (snd_hda_codec_needs_resume(codec))
4494 hda_call_codec_resume(codec);
4498 EXPORT_SYMBOL_HDA(snd_hda_resume);
4499 #endif /* CONFIG_PM */
4506 * snd_array_new - get a new element from the given array
4507 * @array: the array object
4509 * Get a new element from the given array. If it exceeds the
4510 * pre-allocated array size, re-allocate the array.
4512 * Returns NULL if allocation failed.
4514 void *snd_array_new(struct snd_array *array)
4516 if (array->used >= array->alloced) {
4517 int num = array->alloced + array->alloc_align;
4519 if (snd_BUG_ON(num >= 4096))
4521 nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
4525 memcpy(nlist, array->list,
4526 array->elem_size * array->alloced);
4529 array->list = nlist;
4530 array->alloced = num;
4532 return snd_array_elem(array, array->used++);
4534 EXPORT_SYMBOL_HDA(snd_array_new);
4537 * snd_array_free - free the given array elements
4538 * @array: the array object
4540 void snd_array_free(struct snd_array *array)
4547 EXPORT_SYMBOL_HDA(snd_array_free);
4550 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4551 * @pcm: PCM caps bits
4552 * @buf: the string buffer to write
4553 * @buflen: the max buffer length
4555 * used by hda_proc.c and hda_eld.c
4557 void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4559 static unsigned int rates[] = {
4560 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
4561 96000, 176400, 192000, 384000
4565 for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
4567 j += snprintf(buf + j, buflen - j, " %d", rates[i]);
4569 buf[j] = '\0'; /* necessary when j == 0 */
4571 EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4574 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4575 * @pcm: PCM caps bits
4576 * @buf: the string buffer to write
4577 * @buflen: the max buffer length
4579 * used by hda_proc.c and hda_eld.c
4581 void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4583 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
4586 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
4587 if (pcm & (AC_SUPPCM_BITS_8 << i))
4588 j += snprintf(buf + j, buflen - j, " %d", bits[i]);
4590 buf[j] = '\0'; /* necessary when j == 0 */
4592 EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
4594 MODULE_DESCRIPTION("HDA codec core");
4595 MODULE_LICENSE("GPL");