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);
787 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
788 AC_VERB_GET_PIN_WIDGET_CONTROL,
794 /* look up the given pin config list and return the item matching with NID */
795 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
796 struct snd_array *array,
800 for (i = 0; i < array->used; i++) {
801 struct hda_pincfg *pin = snd_array_elem(array, i);
808 /* write a config value for the given NID */
809 static void set_pincfg(struct hda_codec *codec, hda_nid_t nid,
813 for (i = 0; i < 4; i++) {
814 snd_hda_codec_write(codec, nid, 0,
815 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
821 /* set the current pin config value for the given NID.
822 * the value is cached, and read via snd_hda_codec_get_pincfg()
824 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
825 hda_nid_t nid, unsigned int cfg)
827 struct hda_pincfg *pin;
830 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
833 oldcfg = snd_hda_codec_get_pincfg(codec, nid);
834 pin = look_up_pincfg(codec, list, nid);
836 pin = snd_array_new(list);
843 /* change only when needed; e.g. if the pincfg is already present
844 * in user_pins[], don't write it
846 cfg = snd_hda_codec_get_pincfg(codec, nid);
848 set_pincfg(codec, nid, cfg);
853 * snd_hda_codec_set_pincfg - Override a pin default configuration
854 * @codec: the HDA codec
855 * @nid: NID to set the pin config
856 * @cfg: the pin default config value
858 * Override a pin default configuration value in the cache.
859 * This value can be read by snd_hda_codec_get_pincfg() in a higher
860 * priority than the real hardware value.
862 int snd_hda_codec_set_pincfg(struct hda_codec *codec,
863 hda_nid_t nid, unsigned int cfg)
865 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
867 EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
870 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
871 * @codec: the HDA codec
872 * @nid: NID to get the pin config
874 * Get the current pin config value of the given pin NID.
875 * If the pincfg value is cached or overridden via sysfs or driver,
876 * returns the cached value.
878 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
880 struct hda_pincfg *pin;
882 #ifdef CONFIG_SND_HDA_HWDEP
883 pin = look_up_pincfg(codec, &codec->user_pins, nid);
887 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
890 pin = look_up_pincfg(codec, &codec->init_pins, nid);
895 EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg);
897 /* restore all current pin configs */
898 static void restore_pincfgs(struct hda_codec *codec)
901 for (i = 0; i < codec->init_pins.used; i++) {
902 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
903 set_pincfg(codec, pin->nid,
904 snd_hda_codec_get_pincfg(codec, pin->nid));
909 * snd_hda_shutup_pins - Shut up all pins
910 * @codec: the HDA codec
912 * Clear all pin controls to shup up before suspend for avoiding click noise.
913 * The controls aren't cached so that they can be resumed properly.
915 void snd_hda_shutup_pins(struct hda_codec *codec)
918 /* don't shut up pins when unloading the driver; otherwise it breaks
919 * the default pin setup at the next load of the driver
921 if (codec->bus->shutdown)
923 for (i = 0; i < codec->init_pins.used; i++) {
924 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
925 /* use read here for syncing after issuing each verb */
926 snd_hda_codec_read(codec, pin->nid, 0,
927 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
929 codec->pins_shutup = 1;
931 EXPORT_SYMBOL_HDA(snd_hda_shutup_pins);
933 /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */
934 static void restore_shutup_pins(struct hda_codec *codec)
937 if (!codec->pins_shutup)
939 if (codec->bus->shutdown)
941 for (i = 0; i < codec->init_pins.used; i++) {
942 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
943 snd_hda_codec_write(codec, pin->nid, 0,
944 AC_VERB_SET_PIN_WIDGET_CONTROL,
947 codec->pins_shutup = 0;
950 static void init_hda_cache(struct hda_cache_rec *cache,
951 unsigned int record_size);
952 static void free_hda_cache(struct hda_cache_rec *cache);
954 /* restore the initial pin cfgs and release all pincfg lists */
955 static void restore_init_pincfgs(struct hda_codec *codec)
957 /* first free driver_pins and user_pins, then call restore_pincfg
958 * so that only the values in init_pins are restored
960 snd_array_free(&codec->driver_pins);
961 #ifdef CONFIG_SND_HDA_HWDEP
962 snd_array_free(&codec->user_pins);
964 restore_pincfgs(codec);
965 snd_array_free(&codec->init_pins);
971 static void snd_hda_codec_free(struct hda_codec *codec)
975 restore_init_pincfgs(codec);
976 #ifdef CONFIG_SND_HDA_POWER_SAVE
977 cancel_delayed_work(&codec->power_work);
978 flush_workqueue(codec->bus->workq);
980 list_del(&codec->list);
981 snd_array_free(&codec->mixers);
982 snd_array_free(&codec->nids);
983 codec->bus->caddr_tbl[codec->addr] = NULL;
984 if (codec->patch_ops.free)
985 codec->patch_ops.free(codec);
986 module_put(codec->owner);
987 free_hda_cache(&codec->amp_cache);
988 free_hda_cache(&codec->cmd_cache);
989 kfree(codec->vendor_name);
990 kfree(codec->chip_name);
991 kfree(codec->modelname);
996 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
997 unsigned int power_state);
1000 * snd_hda_codec_new - create a HDA codec
1001 * @bus: the bus to assign
1002 * @codec_addr: the codec address
1003 * @codecp: the pointer to store the generated codec
1005 * Returns 0 if successful, or a negative error code.
1007 int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1008 unsigned int codec_addr,
1009 struct hda_codec **codecp)
1011 struct hda_codec *codec;
1015 if (snd_BUG_ON(!bus))
1017 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
1020 if (bus->caddr_tbl[codec_addr]) {
1021 snd_printk(KERN_ERR "hda_codec: "
1022 "address 0x%x is already occupied\n", codec_addr);
1026 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
1027 if (codec == NULL) {
1028 snd_printk(KERN_ERR "can't allocate struct hda_codec\n");
1033 codec->addr = codec_addr;
1034 mutex_init(&codec->spdif_mutex);
1035 mutex_init(&codec->control_mutex);
1036 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1037 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1038 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1039 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
1040 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
1041 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
1042 if (codec->bus->modelname) {
1043 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1044 if (!codec->modelname) {
1045 snd_hda_codec_free(codec);
1050 #ifdef CONFIG_SND_HDA_POWER_SAVE
1051 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
1052 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
1053 * the caller has to power down appropriatley after initialization
1056 hda_keep_power_on(codec);
1059 list_add_tail(&codec->list, &bus->codec_list);
1060 bus->caddr_tbl[codec_addr] = codec;
1062 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1064 if (codec->vendor_id == -1)
1065 /* read again, hopefully the access method was corrected
1066 * in the last read...
1068 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1070 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1071 AC_PAR_SUBSYSTEM_ID);
1072 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1075 setup_fg_nodes(codec);
1076 if (!codec->afg && !codec->mfg) {
1077 snd_printdd("hda_codec: no AFG or MFG node found\n");
1082 err = read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg);
1084 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
1087 err = read_pin_defaults(codec);
1091 if (!codec->subsystem_id) {
1092 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
1093 codec->subsystem_id =
1094 snd_hda_codec_read(codec, nid, 0,
1095 AC_VERB_GET_SUBSYSTEM_ID, 0);
1098 /* power-up all before initialization */
1099 hda_set_power_state(codec,
1100 codec->afg ? codec->afg : codec->mfg,
1103 snd_hda_codec_proc_new(codec);
1105 snd_hda_create_hwdep(codec);
1107 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
1108 codec->subsystem_id, codec->revision_id);
1109 snd_component_add(codec->bus->card, component);
1116 snd_hda_codec_free(codec);
1119 EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1122 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1123 * @codec: the HDA codec
1125 * Start parsing of the given codec tree and (re-)initialize the whole
1128 * Returns 0 if successful or a negative error code.
1130 int snd_hda_codec_configure(struct hda_codec *codec)
1134 codec->preset = find_codec_preset(codec);
1135 if (!codec->vendor_name || !codec->chip_name) {
1136 err = get_codec_name(codec);
1141 if (is_generic_config(codec)) {
1142 err = snd_hda_parse_generic_codec(codec);
1145 if (codec->preset && codec->preset->patch) {
1146 err = codec->preset->patch(codec);
1150 /* call the default parser */
1151 err = snd_hda_parse_generic_codec(codec);
1153 printk(KERN_ERR "hda-codec: No codec parser is available\n");
1156 if (!err && codec->patch_ops.unsol_event)
1157 err = init_unsol_queue(codec->bus);
1158 /* audio codec should override the mixer name */
1159 if (!err && (codec->afg || !*codec->bus->card->mixername))
1160 snprintf(codec->bus->card->mixername,
1161 sizeof(codec->bus->card->mixername),
1162 "%s %s", codec->vendor_name, codec->chip_name);
1165 EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
1168 * snd_hda_codec_setup_stream - set up the codec for streaming
1169 * @codec: the CODEC to set up
1170 * @nid: the NID to set up
1171 * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
1172 * @channel_id: channel id to pass, zero based.
1173 * @format: stream format.
1175 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1177 int channel_id, int format)
1182 snd_printdd("hda_codec_setup_stream: "
1183 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1184 nid, stream_tag, channel_id, format);
1185 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
1186 (stream_tag << 4) | channel_id);
1188 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
1190 EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1193 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1194 * @codec: the CODEC to clean up
1195 * @nid: the NID to clean up
1197 void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1202 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
1203 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1204 #if 0 /* keep the format */
1206 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
1209 EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1212 * amp access functions
1215 /* FIXME: more better hash key? */
1216 #define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1217 #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1218 #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1219 #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
1220 #define INFO_AMP_CAPS (1<<0)
1221 #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
1223 /* initialize the hash table */
1224 static void /*__devinit*/ init_hda_cache(struct hda_cache_rec *cache,
1225 unsigned int record_size)
1227 memset(cache, 0, sizeof(*cache));
1228 memset(cache->hash, 0xff, sizeof(cache->hash));
1229 snd_array_init(&cache->buf, record_size, 64);
1232 static void free_hda_cache(struct hda_cache_rec *cache)
1234 snd_array_free(&cache->buf);
1237 /* query the hash. allocate an entry if not found. */
1238 static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key)
1240 u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
1241 u16 cur = cache->hash[idx];
1242 struct hda_cache_head *info;
1244 while (cur != 0xffff) {
1245 info = snd_array_elem(&cache->buf, cur);
1246 if (info->key == key)
1253 /* query the hash. allocate an entry if not found. */
1254 static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
1257 struct hda_cache_head *info = get_hash(cache, key);
1260 /* add a new hash entry */
1261 info = snd_array_new(&cache->buf);
1264 cur = snd_array_index(&cache->buf, info);
1267 idx = key % (u16)ARRAY_SIZE(cache->hash);
1268 info->next = cache->hash[idx];
1269 cache->hash[idx] = cur;
1274 /* query and allocate an amp hash entry */
1275 static inline struct hda_amp_info *
1276 get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1278 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1282 * query_amp_caps - query AMP capabilities
1283 * @codec: the HD-auio codec
1284 * @nid: the NID to query
1285 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1287 * Query AMP capabilities for the given widget and direction.
1288 * Returns the obtained capability bits.
1290 * When cap bits have been already read, this doesn't read again but
1291 * returns the cached value.
1293 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1295 struct hda_amp_info *info;
1297 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
1300 if (!(info->head.val & INFO_AMP_CAPS)) {
1301 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1303 info->amp_caps = snd_hda_param_read(codec, nid,
1304 direction == HDA_OUTPUT ?
1305 AC_PAR_AMP_OUT_CAP :
1308 info->head.val |= INFO_AMP_CAPS;
1310 return info->amp_caps;
1312 EXPORT_SYMBOL_HDA(query_amp_caps);
1315 * snd_hda_override_amp_caps - Override the AMP capabilities
1316 * @codec: the CODEC to clean up
1317 * @nid: the NID to clean up
1318 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1319 * @caps: the capability bits to set
1321 * Override the cached AMP caps bits value by the given one.
1322 * This function is useful if the driver needs to adjust the AMP ranges,
1323 * e.g. limit to 0dB, etc.
1325 * Returns zero if successful or a negative error code.
1327 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1330 struct hda_amp_info *info;
1332 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0));
1335 info->amp_caps = caps;
1336 info->head.val |= INFO_AMP_CAPS;
1339 EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
1342 query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key,
1343 unsigned int (*func)(struct hda_codec *, hda_nid_t))
1345 struct hda_amp_info *info;
1347 info = get_alloc_amp_hash(codec, key);
1350 if (!info->head.val) {
1351 info->head.val |= INFO_AMP_CAPS;
1352 info->amp_caps = func(codec, nid);
1354 return info->amp_caps;
1357 static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1359 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1363 * snd_hda_query_pin_caps - Query PIN capabilities
1364 * @codec: the HD-auio codec
1365 * @nid: the NID to query
1367 * Query PIN capabilities for the given widget.
1368 * Returns the obtained capability bits.
1370 * When cap bits have been already read, this doesn't read again but
1371 * returns the cached value.
1373 u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1375 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
1378 EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1381 * snd_hda_pin_sense - execute pin sense measurement
1382 * @codec: the CODEC to sense
1383 * @nid: the pin NID to sense
1385 * Execute necessary pin sense measurement and return its Presence Detect,
1386 * Impedance, ELD Valid etc. status bits.
1388 u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1392 if (!codec->no_trigger_sense) {
1393 pincap = snd_hda_query_pin_caps(codec, nid);
1394 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1395 snd_hda_codec_read(codec, nid, 0,
1396 AC_VERB_SET_PIN_SENSE, 0);
1398 return snd_hda_codec_read(codec, nid, 0,
1399 AC_VERB_GET_PIN_SENSE, 0);
1401 EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1404 * snd_hda_jack_detect - query pin Presence Detect status
1405 * @codec: the CODEC to sense
1406 * @nid: the pin NID to sense
1408 * Query and return the pin's Presence Detect status.
1410 int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1412 u32 sense = snd_hda_pin_sense(codec, nid);
1413 return !!(sense & AC_PINSENSE_PRESENCE);
1415 EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1418 * read the current volume to info
1419 * if the cache exists, read the cache value.
1421 static unsigned int get_vol_mute(struct hda_codec *codec,
1422 struct hda_amp_info *info, hda_nid_t nid,
1423 int ch, int direction, int index)
1427 if (info->head.val & INFO_AMP_VOL(ch))
1428 return info->vol[ch];
1430 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
1431 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
1433 val = snd_hda_codec_read(codec, nid, 0,
1434 AC_VERB_GET_AMP_GAIN_MUTE, parm);
1435 info->vol[ch] = val & 0xff;
1436 info->head.val |= INFO_AMP_VOL(ch);
1437 return info->vol[ch];
1441 * write the current volume in info to the h/w and update the cache
1443 static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1444 hda_nid_t nid, int ch, int direction, int index,
1449 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
1450 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
1451 parm |= index << AC_AMP_SET_INDEX_SHIFT;
1453 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
1454 info->vol[ch] = val;
1458 * snd_hda_codec_amp_read - Read AMP value
1459 * @codec: HD-audio codec
1460 * @nid: NID to read the AMP value
1461 * @ch: channel (left=0 or right=1)
1462 * @direction: #HDA_INPUT or #HDA_OUTPUT
1463 * @index: the index value (only for input direction)
1465 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1467 int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1468 int direction, int index)
1470 struct hda_amp_info *info;
1471 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
1474 return get_vol_mute(codec, info, nid, ch, direction, index);
1476 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1479 * snd_hda_codec_amp_update - update the AMP value
1480 * @codec: HD-audio codec
1481 * @nid: NID to read the AMP value
1482 * @ch: channel (left=0 or right=1)
1483 * @direction: #HDA_INPUT or #HDA_OUTPUT
1484 * @idx: the index value (only for input direction)
1485 * @mask: bit mask to set
1486 * @val: the bits value to set
1488 * Update the AMP value with a bit mask.
1489 * Returns 0 if the value is unchanged, 1 if changed.
1491 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1492 int direction, int idx, int mask, int val)
1494 struct hda_amp_info *info;
1496 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
1499 if (snd_BUG_ON(mask & ~0xff))
1502 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
1503 if (info->vol[ch] == val)
1505 put_vol_mute(codec, info, nid, ch, direction, idx, val);
1508 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1511 * snd_hda_codec_amp_stereo - update the AMP stereo values
1512 * @codec: HD-audio codec
1513 * @nid: NID to read the AMP value
1514 * @direction: #HDA_INPUT or #HDA_OUTPUT
1515 * @idx: the index value (only for input direction)
1516 * @mask: bit mask to set
1517 * @val: the bits value to set
1519 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1520 * stereo widget with the same mask and value.
1522 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1523 int direction, int idx, int mask, int val)
1527 if (snd_BUG_ON(mask & ~0xff))
1529 for (ch = 0; ch < 2; ch++)
1530 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1534 EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1536 #ifdef SND_HDA_NEEDS_RESUME
1538 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1539 * @codec: HD-audio codec
1541 * Resume the all amp commands from the cache.
1543 void snd_hda_codec_resume_amp(struct hda_codec *codec)
1545 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
1548 for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) {
1549 u32 key = buffer->head.key;
1551 unsigned int idx, dir, ch;
1555 idx = (key >> 16) & 0xff;
1556 dir = (key >> 24) & 0xff;
1557 for (ch = 0; ch < 2; ch++) {
1558 if (!(buffer->head.val & INFO_AMP_VOL(ch)))
1560 put_vol_mute(codec, buffer, nid, ch, dir, idx,
1565 EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1566 #endif /* SND_HDA_NEEDS_RESUME */
1569 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1571 * The control element is supposed to have the private_value field
1572 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1574 int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1575 struct snd_ctl_elem_info *uinfo)
1577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1578 u16 nid = get_amp_nid(kcontrol);
1579 u8 chs = get_amp_channels(kcontrol);
1580 int dir = get_amp_direction(kcontrol);
1581 unsigned int ofs = get_amp_offset(kcontrol);
1584 caps = query_amp_caps(codec, nid, dir);
1586 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1588 printk(KERN_WARNING "hda_codec: "
1589 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid,
1595 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1596 uinfo->count = chs == 3 ? 2 : 1;
1597 uinfo->value.integer.min = 0;
1598 uinfo->value.integer.max = caps;
1601 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info);
1604 static inline unsigned int
1605 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1606 int ch, int dir, int idx, unsigned int ofs)
1609 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1610 val &= HDA_AMP_VOLMASK;
1619 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1620 int ch, int dir, int idx, unsigned int ofs,
1625 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1626 HDA_AMP_VOLMASK, val);
1630 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1632 * The control element is supposed to have the private_value field
1633 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1635 int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_value *ucontrol)
1638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1639 hda_nid_t nid = get_amp_nid(kcontrol);
1640 int chs = get_amp_channels(kcontrol);
1641 int dir = get_amp_direction(kcontrol);
1642 int idx = get_amp_index(kcontrol);
1643 unsigned int ofs = get_amp_offset(kcontrol);
1644 long *valp = ucontrol->value.integer.value;
1647 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1649 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1652 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1655 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1657 * The control element is supposed to have the private_value field
1658 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1660 int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1661 struct snd_ctl_elem_value *ucontrol)
1663 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1664 hda_nid_t nid = get_amp_nid(kcontrol);
1665 int chs = get_amp_channels(kcontrol);
1666 int dir = get_amp_direction(kcontrol);
1667 int idx = get_amp_index(kcontrol);
1668 unsigned int ofs = get_amp_offset(kcontrol);
1669 long *valp = ucontrol->value.integer.value;
1672 snd_hda_power_up(codec);
1674 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1678 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1679 snd_hda_power_down(codec);
1682 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1685 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1687 * The control element is supposed to have the private_value field
1688 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1690 int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1691 unsigned int size, unsigned int __user *_tlv)
1693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1694 hda_nid_t nid = get_amp_nid(kcontrol);
1695 int dir = get_amp_direction(kcontrol);
1696 unsigned int ofs = get_amp_offset(kcontrol);
1697 u32 caps, val1, val2;
1699 if (size < 4 * sizeof(unsigned int))
1701 caps = query_amp_caps(codec, nid, dir);
1702 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1703 val2 = (val2 + 1) * 25;
1704 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1706 val1 = ((int)val1) * ((int)val2);
1707 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
1709 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
1711 if (put_user(val1, _tlv + 2))
1713 if (put_user(val2, _tlv + 3))
1717 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1720 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1721 * @codec: HD-audio codec
1722 * @nid: NID of a reference widget
1723 * @dir: #HDA_INPUT or #HDA_OUTPUT
1724 * @tlv: TLV data to be stored, at least 4 elements
1726 * Set (static) TLV data for a virtual master volume using the AMP caps
1727 * obtained from the reference NID.
1728 * The volume range is recalculated as if the max volume is 0dB.
1730 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1736 caps = query_amp_caps(codec, nid, dir);
1737 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1738 step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1739 step = (step + 1) * 25;
1740 tlv[0] = SNDRV_CTL_TLVT_DB_SCALE;
1741 tlv[1] = 2 * sizeof(unsigned int);
1742 tlv[2] = -nums * step;
1745 EXPORT_SYMBOL_HDA(snd_hda_set_vmaster_tlv);
1747 /* find a mixer control element with the given name */
1748 static struct snd_kcontrol *
1749 _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1750 const char *name, int idx)
1752 struct snd_ctl_elem_id id;
1753 memset(&id, 0, sizeof(id));
1754 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1756 if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
1758 strcpy(id.name, name);
1759 return snd_ctl_find_id(codec->bus->card, &id);
1763 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1764 * @codec: HD-audio codec
1765 * @name: ctl id name string
1767 * Get the control element with the given id string and IFACE_MIXER.
1769 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1772 return _snd_hda_find_mixer_ctl(codec, name, 0);
1774 EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1777 * snd_hda_ctl_add - Add a control element and assign to the codec
1778 * @codec: HD-audio codec
1779 * @nid: corresponding NID (optional)
1780 * @kctl: the control element to assign
1782 * Add the given control element to an array inside the codec instance.
1783 * All control elements belonging to a codec are supposed to be added
1784 * by this function so that a proper clean-up works at the free or
1785 * reconfiguration time.
1787 * If non-zero @nid is passed, the NID is assigned to the control element.
1788 * The assignment is shown in the codec proc file.
1790 * snd_hda_ctl_add() checks the control subdev id field whether
1791 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1792 * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit
1793 * specifies if kctl->private_value is a HDA amplifier value.
1795 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1796 struct snd_kcontrol *kctl)
1799 unsigned short flags = 0;
1800 struct hda_nid_item *item;
1802 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) {
1803 flags |= HDA_NID_ITEM_AMP;
1805 nid = get_amp_nid_(kctl->private_value);
1807 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0)
1808 nid = kctl->id.subdevice & 0xffff;
1809 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
1810 kctl->id.subdevice = 0;
1811 err = snd_ctl_add(codec->bus->card, kctl);
1814 item = snd_array_new(&codec->mixers);
1819 item->flags = flags;
1822 EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1825 * snd_hda_add_nid - Assign a NID to a control element
1826 * @codec: HD-audio codec
1827 * @nid: corresponding NID (optional)
1828 * @kctl: the control element to assign
1829 * @index: index to kctl
1831 * Add the given control element to an array inside the codec instance.
1832 * This function is used when #snd_hda_ctl_add cannot be used for 1:1
1833 * NID:KCTL mapping - for example "Capture Source" selector.
1835 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1836 unsigned int index, hda_nid_t nid)
1838 struct hda_nid_item *item;
1841 item = snd_array_new(&codec->nids);
1845 item->index = index;
1849 printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n",
1850 kctl->id.name, kctl->id.index, index);
1853 EXPORT_SYMBOL_HDA(snd_hda_add_nid);
1856 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1857 * @codec: HD-audio codec
1859 void snd_hda_ctls_clear(struct hda_codec *codec)
1862 struct hda_nid_item *items = codec->mixers.list;
1863 for (i = 0; i < codec->mixers.used; i++)
1864 snd_ctl_remove(codec->bus->card, items[i].kctl);
1865 snd_array_free(&codec->mixers);
1866 snd_array_free(&codec->nids);
1869 /* pseudo device locking
1870 * toggle card->shutdown to allow/disallow the device access (as a hack)
1872 static int hda_lock_devices(struct snd_card *card)
1874 spin_lock(&card->files_lock);
1875 if (card->shutdown) {
1876 spin_unlock(&card->files_lock);
1880 spin_unlock(&card->files_lock);
1884 static void hda_unlock_devices(struct snd_card *card)
1886 spin_lock(&card->files_lock);
1888 spin_unlock(&card->files_lock);
1892 * snd_hda_codec_reset - Clear all objects assigned to the codec
1893 * @codec: HD-audio codec
1895 * This frees the all PCM and control elements assigned to the codec, and
1896 * clears the caches and restores the pin default configurations.
1898 * When a device is being used, it returns -EBSY. If successfully freed,
1901 int snd_hda_codec_reset(struct hda_codec *codec)
1903 struct snd_card *card = codec->bus->card;
1906 if (hda_lock_devices(card) < 0)
1908 /* check whether the codec isn't used by any mixer or PCM streams */
1909 if (!list_empty(&card->ctl_files)) {
1910 hda_unlock_devices(card);
1913 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
1914 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
1917 if (cpcm->pcm->streams[0].substream_opened ||
1918 cpcm->pcm->streams[1].substream_opened) {
1919 hda_unlock_devices(card);
1924 /* OK, let it free */
1926 #ifdef CONFIG_SND_HDA_POWER_SAVE
1927 cancel_delayed_work(&codec->power_work);
1928 flush_workqueue(codec->bus->workq);
1930 snd_hda_ctls_clear(codec);
1932 for (i = 0; i < codec->num_pcms; i++) {
1933 if (codec->pcm_info[i].pcm) {
1934 snd_device_free(card, codec->pcm_info[i].pcm);
1935 clear_bit(codec->pcm_info[i].device,
1936 codec->bus->pcm_dev_bits);
1939 if (codec->patch_ops.free)
1940 codec->patch_ops.free(codec);
1941 codec->proc_widget_hook = NULL;
1943 free_hda_cache(&codec->amp_cache);
1944 free_hda_cache(&codec->cmd_cache);
1945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1947 /* free only driver_pins so that init_pins + user_pins are restored */
1948 snd_array_free(&codec->driver_pins);
1949 restore_pincfgs(codec);
1950 codec->num_pcms = 0;
1951 codec->pcm_info = NULL;
1952 codec->preset = NULL;
1953 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
1954 codec->slave_dig_outs = NULL;
1955 codec->spdif_status_reset = 0;
1956 module_put(codec->owner);
1957 codec->owner = NULL;
1959 /* allow device access again */
1960 hda_unlock_devices(card);
1965 * snd_hda_add_vmaster - create a virtual master control and add slaves
1966 * @codec: HD-audio codec
1967 * @name: vmaster control name
1968 * @tlv: TLV data (optional)
1969 * @slaves: slave control names (optional)
1971 * Create a virtual master control with the given name. The TLV data
1972 * must be either NULL or a valid data.
1974 * @slaves is a NULL-terminated array of strings, each of which is a
1975 * slave control name. All controls with these names are assigned to
1976 * the new virtual master control.
1978 * This function returns zero if successful or a negative error code.
1980 int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1981 unsigned int *tlv, const char **slaves)
1983 struct snd_kcontrol *kctl;
1987 for (s = slaves; *s && !snd_hda_find_mixer_ctl(codec, *s); s++)
1990 snd_printdd("No slave found for %s\n", name);
1993 kctl = snd_ctl_make_virtual_master(name, tlv);
1996 err = snd_hda_ctl_add(codec, 0, kctl);
2000 for (s = slaves; *s; s++) {
2001 struct snd_kcontrol *sctl;
2004 sctl = _snd_hda_find_mixer_ctl(codec, *s, i);
2007 snd_printdd("Cannot find slave %s, "
2011 err = snd_ctl_add_slave(kctl, sctl);
2019 EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
2022 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
2024 * The control element is supposed to have the private_value field
2025 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2027 int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
2028 struct snd_ctl_elem_info *uinfo)
2030 int chs = get_amp_channels(kcontrol);
2032 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2033 uinfo->count = chs == 3 ? 2 : 1;
2034 uinfo->value.integer.min = 0;
2035 uinfo->value.integer.max = 1;
2038 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
2041 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2043 * The control element is supposed to have the private_value field
2044 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2046 int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
2047 struct snd_ctl_elem_value *ucontrol)
2049 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2050 hda_nid_t nid = get_amp_nid(kcontrol);
2051 int chs = get_amp_channels(kcontrol);
2052 int dir = get_amp_direction(kcontrol);
2053 int idx = get_amp_index(kcontrol);
2054 long *valp = ucontrol->value.integer.value;
2057 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2058 HDA_AMP_MUTE) ? 0 : 1;
2060 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2061 HDA_AMP_MUTE) ? 0 : 1;
2064 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
2067 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2069 * The control element is supposed to have the private_value field
2070 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2072 int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2075 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2076 hda_nid_t nid = get_amp_nid(kcontrol);
2077 int chs = get_amp_channels(kcontrol);
2078 int dir = get_amp_direction(kcontrol);
2079 int idx = get_amp_index(kcontrol);
2080 long *valp = ucontrol->value.integer.value;
2083 snd_hda_power_up(codec);
2085 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2087 *valp ? 0 : HDA_AMP_MUTE);
2091 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2093 *valp ? 0 : HDA_AMP_MUTE);
2094 #ifdef CONFIG_SND_HDA_POWER_SAVE
2095 if (codec->patch_ops.check_power_status)
2096 codec->patch_ops.check_power_status(codec, nid);
2098 snd_hda_power_down(codec);
2101 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
2103 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2105 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
2107 * This function calls snd_hda_enable_beep_device(), which behaves differently
2108 * depending on beep_mode option.
2110 int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2111 struct snd_ctl_elem_value *ucontrol)
2113 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2114 long *valp = ucontrol->value.integer.value;
2116 snd_hda_enable_beep_device(codec, *valp);
2117 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2119 EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2120 #endif /* CONFIG_SND_HDA_INPUT_BEEP */
2123 * bound volume controls
2125 * bind multiple volumes (# indices, from 0)
2128 #define AMP_VAL_IDX_SHIFT 19
2129 #define AMP_VAL_IDX_MASK (0x0f<<19)
2132 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2134 * The control element is supposed to have the private_value field
2135 * set up via HDA_BIND_MUTE*() macros.
2137 int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
2138 struct snd_ctl_elem_value *ucontrol)
2140 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2144 mutex_lock(&codec->control_mutex);
2145 pval = kcontrol->private_value;
2146 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
2147 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
2148 kcontrol->private_value = pval;
2149 mutex_unlock(&codec->control_mutex);
2152 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
2155 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2157 * The control element is supposed to have the private_value field
2158 * set up via HDA_BIND_MUTE*() macros.
2160 int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
2161 struct snd_ctl_elem_value *ucontrol)
2163 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2165 int i, indices, err = 0, change = 0;
2167 mutex_lock(&codec->control_mutex);
2168 pval = kcontrol->private_value;
2169 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
2170 for (i = 0; i < indices; i++) {
2171 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
2172 (i << AMP_VAL_IDX_SHIFT);
2173 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2178 kcontrol->private_value = pval;
2179 mutex_unlock(&codec->control_mutex);
2180 return err < 0 ? err : change;
2182 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
2185 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2187 * The control element is supposed to have the private_value field
2188 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2190 int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
2191 struct snd_ctl_elem_info *uinfo)
2193 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2194 struct hda_bind_ctls *c;
2197 mutex_lock(&codec->control_mutex);
2198 c = (struct hda_bind_ctls *)kcontrol->private_value;
2199 kcontrol->private_value = *c->values;
2200 err = c->ops->info(kcontrol, uinfo);
2201 kcontrol->private_value = (long)c;
2202 mutex_unlock(&codec->control_mutex);
2205 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
2208 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2210 * The control element is supposed to have the private_value field
2211 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2213 int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
2214 struct snd_ctl_elem_value *ucontrol)
2216 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2217 struct hda_bind_ctls *c;
2220 mutex_lock(&codec->control_mutex);
2221 c = (struct hda_bind_ctls *)kcontrol->private_value;
2222 kcontrol->private_value = *c->values;
2223 err = c->ops->get(kcontrol, ucontrol);
2224 kcontrol->private_value = (long)c;
2225 mutex_unlock(&codec->control_mutex);
2228 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
2231 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2233 * The control element is supposed to have the private_value field
2234 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2236 int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
2237 struct snd_ctl_elem_value *ucontrol)
2239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2240 struct hda_bind_ctls *c;
2241 unsigned long *vals;
2242 int err = 0, change = 0;
2244 mutex_lock(&codec->control_mutex);
2245 c = (struct hda_bind_ctls *)kcontrol->private_value;
2246 for (vals = c->values; *vals; vals++) {
2247 kcontrol->private_value = *vals;
2248 err = c->ops->put(kcontrol, ucontrol);
2253 kcontrol->private_value = (long)c;
2254 mutex_unlock(&codec->control_mutex);
2255 return err < 0 ? err : change;
2257 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
2260 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2262 * The control element is supposed to have the private_value field
2263 * set up via HDA_BIND_VOL() macro.
2265 int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2266 unsigned int size, unsigned int __user *tlv)
2268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2269 struct hda_bind_ctls *c;
2272 mutex_lock(&codec->control_mutex);
2273 c = (struct hda_bind_ctls *)kcontrol->private_value;
2274 kcontrol->private_value = *c->values;
2275 err = c->ops->tlv(kcontrol, op_flag, size, tlv);
2276 kcontrol->private_value = (long)c;
2277 mutex_unlock(&codec->control_mutex);
2280 EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_tlv);
2282 struct hda_ctl_ops snd_hda_bind_vol = {
2283 .info = snd_hda_mixer_amp_volume_info,
2284 .get = snd_hda_mixer_amp_volume_get,
2285 .put = snd_hda_mixer_amp_volume_put,
2286 .tlv = snd_hda_mixer_amp_tlv
2288 EXPORT_SYMBOL_HDA(snd_hda_bind_vol);
2290 struct hda_ctl_ops snd_hda_bind_sw = {
2291 .info = snd_hda_mixer_amp_switch_info,
2292 .get = snd_hda_mixer_amp_switch_get,
2293 .put = snd_hda_mixer_amp_switch_put,
2294 .tlv = snd_hda_mixer_amp_tlv
2296 EXPORT_SYMBOL_HDA(snd_hda_bind_sw);
2299 * SPDIF out controls
2302 static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
2303 struct snd_ctl_elem_info *uinfo)
2305 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2310 static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
2311 struct snd_ctl_elem_value *ucontrol)
2313 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2314 IEC958_AES0_NONAUDIO |
2315 IEC958_AES0_CON_EMPHASIS_5015 |
2316 IEC958_AES0_CON_NOT_COPYRIGHT;
2317 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
2318 IEC958_AES1_CON_ORIGINAL;
2322 static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
2323 struct snd_ctl_elem_value *ucontrol)
2325 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2326 IEC958_AES0_NONAUDIO |
2327 IEC958_AES0_PRO_EMPHASIS_5015;
2331 static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
2332 struct snd_ctl_elem_value *ucontrol)
2334 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2336 ucontrol->value.iec958.status[0] = codec->spdif_status & 0xff;
2337 ucontrol->value.iec958.status[1] = (codec->spdif_status >> 8) & 0xff;
2338 ucontrol->value.iec958.status[2] = (codec->spdif_status >> 16) & 0xff;
2339 ucontrol->value.iec958.status[3] = (codec->spdif_status >> 24) & 0xff;
2344 /* convert from SPDIF status bits to HDA SPDIF bits
2345 * bit 0 (DigEn) is always set zero (to be filled later)
2347 static unsigned short convert_from_spdif_status(unsigned int sbits)
2349 unsigned short val = 0;
2351 if (sbits & IEC958_AES0_PROFESSIONAL)
2352 val |= AC_DIG1_PROFESSIONAL;
2353 if (sbits & IEC958_AES0_NONAUDIO)
2354 val |= AC_DIG1_NONAUDIO;
2355 if (sbits & IEC958_AES0_PROFESSIONAL) {
2356 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
2357 IEC958_AES0_PRO_EMPHASIS_5015)
2358 val |= AC_DIG1_EMPHASIS;
2360 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
2361 IEC958_AES0_CON_EMPHASIS_5015)
2362 val |= AC_DIG1_EMPHASIS;
2363 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
2364 val |= AC_DIG1_COPYRIGHT;
2365 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
2366 val |= AC_DIG1_LEVEL;
2367 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
2372 /* convert to SPDIF status bits from HDA SPDIF bits
2374 static unsigned int convert_to_spdif_status(unsigned short val)
2376 unsigned int sbits = 0;
2378 if (val & AC_DIG1_NONAUDIO)
2379 sbits |= IEC958_AES0_NONAUDIO;
2380 if (val & AC_DIG1_PROFESSIONAL)
2381 sbits |= IEC958_AES0_PROFESSIONAL;
2382 if (sbits & IEC958_AES0_PROFESSIONAL) {
2383 if (sbits & AC_DIG1_EMPHASIS)
2384 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
2386 if (val & AC_DIG1_EMPHASIS)
2387 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
2388 if (!(val & AC_DIG1_COPYRIGHT))
2389 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
2390 if (val & AC_DIG1_LEVEL)
2391 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
2392 sbits |= val & (0x7f << 8);
2397 /* set digital convert verbs both for the given NID and its slaves */
2398 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2403 snd_hda_codec_write_cache(codec, nid, 0, verb, val);
2404 d = codec->slave_dig_outs;
2408 snd_hda_codec_write_cache(codec, *d, 0, verb, val);
2411 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2415 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1);
2417 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2);
2420 static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_value *ucontrol)
2423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2424 hda_nid_t nid = kcontrol->private_value;
2428 mutex_lock(&codec->spdif_mutex);
2429 codec->spdif_status = ucontrol->value.iec958.status[0] |
2430 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
2431 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
2432 ((unsigned int)ucontrol->value.iec958.status[3] << 24);
2433 val = convert_from_spdif_status(codec->spdif_status);
2434 val |= codec->spdif_ctls & 1;
2435 change = codec->spdif_ctls != val;
2436 codec->spdif_ctls = val;
2439 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2441 mutex_unlock(&codec->spdif_mutex);
2445 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
2447 static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
2448 struct snd_ctl_elem_value *ucontrol)
2450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2452 ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE;
2456 static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
2457 struct snd_ctl_elem_value *ucontrol)
2459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2460 hda_nid_t nid = kcontrol->private_value;
2464 mutex_lock(&codec->spdif_mutex);
2465 val = codec->spdif_ctls & ~AC_DIG1_ENABLE;
2466 if (ucontrol->value.integer.value[0])
2467 val |= AC_DIG1_ENABLE;
2468 change = codec->spdif_ctls != val;
2470 codec->spdif_ctls = val;
2471 set_dig_out_convert(codec, nid, val & 0xff, -1);
2472 /* unmute amp switch (if any) */
2473 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2474 (val & AC_DIG1_ENABLE))
2475 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2478 mutex_unlock(&codec->spdif_mutex);
2482 static struct snd_kcontrol_new dig_mixes[] = {
2484 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2486 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
2487 .info = snd_hda_spdif_mask_info,
2488 .get = snd_hda_spdif_cmask_get,
2491 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2493 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
2494 .info = snd_hda_spdif_mask_info,
2495 .get = snd_hda_spdif_pmask_get,
2498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2499 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2500 .info = snd_hda_spdif_mask_info,
2501 .get = snd_hda_spdif_default_get,
2502 .put = snd_hda_spdif_default_put,
2505 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2506 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2507 .info = snd_hda_spdif_out_switch_info,
2508 .get = snd_hda_spdif_out_switch_get,
2509 .put = snd_hda_spdif_out_switch_put,
2514 #define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
2517 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
2518 * @codec: the HDA codec
2519 * @nid: audio out widget NID
2521 * Creates controls related with the SPDIF output.
2522 * Called from each patch supporting the SPDIF out.
2524 * Returns 0 if successful, or a negative error code.
2526 int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2529 struct snd_kcontrol *kctl;
2530 struct snd_kcontrol_new *dig_mix;
2533 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
2534 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
2538 if (idx >= SPDIF_MAX_IDX) {
2539 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
2542 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
2543 kctl = snd_ctl_new1(dig_mix, codec);
2546 kctl->id.index = idx;
2547 kctl->private_value = nid;
2548 err = snd_hda_ctl_add(codec, nid, kctl);
2553 snd_hda_codec_read(codec, nid, 0,
2554 AC_VERB_GET_DIGI_CONVERT_1, 0);
2555 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
2558 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls);
2561 * SPDIF sharing with analog output
2563 static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
2564 struct snd_ctl_elem_value *ucontrol)
2566 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2567 ucontrol->value.integer.value[0] = mout->share_spdif;
2571 static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
2572 struct snd_ctl_elem_value *ucontrol)
2574 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2575 mout->share_spdif = !!ucontrol->value.integer.value[0];
2579 static struct snd_kcontrol_new spdif_share_sw = {
2580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2581 .name = "IEC958 Default PCM Playback Switch",
2582 .info = snd_ctl_boolean_mono_info,
2583 .get = spdif_share_sw_get,
2584 .put = spdif_share_sw_put,
2588 * snd_hda_create_spdif_share_sw - create Default PCM switch
2589 * @codec: the HDA codec
2590 * @mout: multi-out instance
2592 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2593 struct hda_multi_out *mout)
2595 if (!mout->dig_out_nid)
2597 /* ATTENTION: here mout is passed as private_data, instead of codec */
2598 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2599 snd_ctl_new1(&spdif_share_sw, mout));
2601 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2607 #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
2609 static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol,
2610 struct snd_ctl_elem_value *ucontrol)
2612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2614 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
2618 static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 hda_nid_t nid = kcontrol->private_value;
2623 unsigned int val = !!ucontrol->value.integer.value[0];
2626 mutex_lock(&codec->spdif_mutex);
2627 change = codec->spdif_in_enable != val;
2629 codec->spdif_in_enable = val;
2630 snd_hda_codec_write_cache(codec, nid, 0,
2631 AC_VERB_SET_DIGI_CONVERT_1, val);
2633 mutex_unlock(&codec->spdif_mutex);
2637 static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
2638 struct snd_ctl_elem_value *ucontrol)
2640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2641 hda_nid_t nid = kcontrol->private_value;
2645 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
2646 sbits = convert_to_spdif_status(val);
2647 ucontrol->value.iec958.status[0] = sbits;
2648 ucontrol->value.iec958.status[1] = sbits >> 8;
2649 ucontrol->value.iec958.status[2] = sbits >> 16;
2650 ucontrol->value.iec958.status[3] = sbits >> 24;
2654 static struct snd_kcontrol_new dig_in_ctls[] = {
2656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2657 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
2658 .info = snd_hda_spdif_in_switch_info,
2659 .get = snd_hda_spdif_in_switch_get,
2660 .put = snd_hda_spdif_in_switch_put,
2663 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2664 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2665 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
2666 .info = snd_hda_spdif_mask_info,
2667 .get = snd_hda_spdif_in_status_get,
2673 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
2674 * @codec: the HDA codec
2675 * @nid: audio in widget NID
2677 * Creates controls related with the SPDIF input.
2678 * Called from each patch supporting the SPDIF in.
2680 * Returns 0 if successful, or a negative error code.
2682 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2685 struct snd_kcontrol *kctl;
2686 struct snd_kcontrol_new *dig_mix;
2689 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
2690 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
2694 if (idx >= SPDIF_MAX_IDX) {
2695 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
2698 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
2699 kctl = snd_ctl_new1(dig_mix, codec);
2702 kctl->private_value = nid;
2703 err = snd_hda_ctl_add(codec, nid, kctl);
2707 codec->spdif_in_enable =
2708 snd_hda_codec_read(codec, nid, 0,
2709 AC_VERB_GET_DIGI_CONVERT_1, 0) &
2713 EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
2715 #ifdef SND_HDA_NEEDS_RESUME
2720 /* build a 32bit cache key with the widget id and the command parameter */
2721 #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
2722 #define get_cmd_cache_nid(key) ((key) & 0xff)
2723 #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
2726 * snd_hda_codec_write_cache - send a single command with caching
2727 * @codec: the HDA codec
2728 * @nid: NID to send the command
2729 * @direct: direct flag
2730 * @verb: the verb to send
2731 * @parm: the parameter for the verb
2733 * Send a single command without waiting for response.
2735 * Returns 0 if successful, or a negative error code.
2737 int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2738 int direct, unsigned int verb, unsigned int parm)
2740 int err = snd_hda_codec_write(codec, nid, direct, verb, parm);
2741 struct hda_cache_head *c;
2746 /* parm may contain the verb stuff for get/set amp */
2747 verb = verb | (parm >> 8);
2749 key = build_cmd_cache_key(nid, verb);
2750 mutex_lock(&codec->bus->cmd_mutex);
2751 c = get_alloc_hash(&codec->cmd_cache, key);
2754 mutex_unlock(&codec->bus->cmd_mutex);
2757 EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2760 * snd_hda_codec_update_cache - check cache and write the cmd only when needed
2761 * @codec: the HDA codec
2762 * @nid: NID to send the command
2763 * @direct: direct flag
2764 * @verb: the verb to send
2765 * @parm: the parameter for the verb
2767 * This function works like snd_hda_codec_write_cache(), but it doesn't send
2768 * command if the parameter is already identical with the cached value.
2769 * If not, it sends the command and refreshes the cache.
2771 * Returns 0 if successful, or a negative error code.
2773 int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
2774 int direct, unsigned int verb, unsigned int parm)
2776 struct hda_cache_head *c;
2779 /* parm may contain the verb stuff for get/set amp */
2780 verb = verb | (parm >> 8);
2782 key = build_cmd_cache_key(nid, verb);
2783 mutex_lock(&codec->bus->cmd_mutex);
2784 c = get_hash(&codec->cmd_cache, key);
2785 if (c && c->val == parm) {
2786 mutex_unlock(&codec->bus->cmd_mutex);
2789 mutex_unlock(&codec->bus->cmd_mutex);
2790 return snd_hda_codec_write_cache(codec, nid, direct, verb, parm);
2792 EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache);
2795 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2796 * @codec: HD-audio codec
2798 * Execute all verbs recorded in the command caches to resume.
2800 void snd_hda_codec_resume_cache(struct hda_codec *codec)
2802 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
2805 for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) {
2806 u32 key = buffer->key;
2809 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
2810 get_cmd_cache_cmd(key), buffer->val);
2813 EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache);
2816 * snd_hda_sequence_write_cache - sequence writes with caching
2817 * @codec: the HDA codec
2818 * @seq: VERB array to send
2820 * Send the commands sequentially from the given array.
2821 * Thte commands are recorded on cache for power-save and resume.
2822 * The array must be terminated with NID=0.
2824 void snd_hda_sequence_write_cache(struct hda_codec *codec,
2825 const struct hda_verb *seq)
2827 for (; seq->nid; seq++)
2828 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
2831 EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache);
2832 #endif /* SND_HDA_NEEDS_RESUME */
2835 * set power state of the codec
2837 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2838 unsigned int power_state)
2843 /* this delay seems necessary to avoid click noise at power-down */
2844 if (power_state == AC_PWRST_D3)
2846 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
2848 /* partial workaround for "azx_get_response timeout" */
2849 if (power_state == AC_PWRST_D0 &&
2850 (codec->vendor_id & 0xffff0000) == 0x14f10000)
2853 nid = codec->start_nid;
2854 for (i = 0; i < codec->num_nodes; i++, nid++) {
2855 unsigned int wcaps = get_wcaps(codec, nid);
2856 if (wcaps & AC_WCAP_POWER) {
2857 unsigned int wid_type = get_wcaps_type(wcaps);
2858 if (power_state == AC_PWRST_D3 &&
2859 wid_type == AC_WID_PIN) {
2860 unsigned int pincap;
2862 * don't power down the widget if it controls
2863 * eapd and EAPD_BTLENABLE is set.
2865 pincap = snd_hda_query_pin_caps(codec, nid);
2866 if (pincap & AC_PINCAP_EAPD) {
2867 int eapd = snd_hda_codec_read(codec,
2869 AC_VERB_GET_EAPD_BTLENABLE, 0);
2875 snd_hda_codec_write(codec, nid, 0,
2876 AC_VERB_SET_POWER_STATE,
2881 if (power_state == AC_PWRST_D0) {
2882 unsigned long end_time;
2884 /* wait until the codec reachs to D0 */
2885 end_time = jiffies + msecs_to_jiffies(500);
2887 state = snd_hda_codec_read(codec, fg, 0,
2888 AC_VERB_GET_POWER_STATE, 0);
2889 if (state == power_state)
2892 } while (time_after_eq(end_time, jiffies));
2896 #ifdef CONFIG_SND_HDA_HWDEP
2897 /* execute additional init verbs */
2898 static void hda_exec_init_verbs(struct hda_codec *codec)
2900 if (codec->init_verbs.list)
2901 snd_hda_sequence_write(codec, codec->init_verbs.list);
2904 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2907 #ifdef SND_HDA_NEEDS_RESUME
2909 * call suspend and power-down; used both from PM and power-save
2911 static void hda_call_codec_suspend(struct hda_codec *codec)
2913 if (codec->patch_ops.suspend)
2914 codec->patch_ops.suspend(codec, PMSG_SUSPEND);
2915 hda_set_power_state(codec,
2916 codec->afg ? codec->afg : codec->mfg,
2918 #ifdef CONFIG_SND_HDA_POWER_SAVE
2919 snd_hda_update_power_acct(codec);
2920 cancel_delayed_work(&codec->power_work);
2921 codec->power_on = 0;
2922 codec->power_transition = 0;
2923 codec->power_jiffies = jiffies;
2928 * kick up codec; used both from PM and power-save
2930 static void hda_call_codec_resume(struct hda_codec *codec)
2932 hda_set_power_state(codec,
2933 codec->afg ? codec->afg : codec->mfg,
2935 restore_pincfgs(codec); /* restore all current pin configs */
2936 restore_shutup_pins(codec);
2937 hda_exec_init_verbs(codec);
2938 if (codec->patch_ops.resume)
2939 codec->patch_ops.resume(codec);
2941 if (codec->patch_ops.init)
2942 codec->patch_ops.init(codec);
2943 snd_hda_codec_resume_amp(codec);
2944 snd_hda_codec_resume_cache(codec);
2947 #endif /* SND_HDA_NEEDS_RESUME */
2951 * snd_hda_build_controls - build mixer controls
2954 * Creates mixer controls for each codec included in the bus.
2956 * Returns 0 if successful, otherwise a negative error code.
2958 int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
2960 struct hda_codec *codec;
2962 list_for_each_entry(codec, &bus->codec_list, list) {
2963 int err = snd_hda_codec_build_controls(codec);
2965 printk(KERN_ERR "hda_codec: cannot build controls "
2966 "for #%d (error %d)\n", codec->addr, err);
2967 err = snd_hda_codec_reset(codec);
2970 "hda_codec: cannot revert codec\n");
2977 EXPORT_SYMBOL_HDA(snd_hda_build_controls);
2979 int snd_hda_codec_build_controls(struct hda_codec *codec)
2982 hda_exec_init_verbs(codec);
2983 /* continue to initialize... */
2984 if (codec->patch_ops.init)
2985 err = codec->patch_ops.init(codec);
2986 if (!err && codec->patch_ops.build_controls)
2987 err = codec->patch_ops.build_controls(codec);
2996 struct hda_rate_tbl {
2998 unsigned int alsa_bits;
2999 unsigned int hda_fmt;
3002 static struct hda_rate_tbl rate_bits[] = {
3003 /* rate in Hz, ALSA rate bitmask, HDA format value */
3005 /* autodetected value used in snd_hda_query_supported_pcm */
3006 { 8000, SNDRV_PCM_RATE_8000, 0x0500 }, /* 1/6 x 48 */
3007 { 11025, SNDRV_PCM_RATE_11025, 0x4300 }, /* 1/4 x 44 */
3008 { 16000, SNDRV_PCM_RATE_16000, 0x0200 }, /* 1/3 x 48 */
3009 { 22050, SNDRV_PCM_RATE_22050, 0x4100 }, /* 1/2 x 44 */
3010 { 32000, SNDRV_PCM_RATE_32000, 0x0a00 }, /* 2/3 x 48 */
3011 { 44100, SNDRV_PCM_RATE_44100, 0x4000 }, /* 44 */
3012 { 48000, SNDRV_PCM_RATE_48000, 0x0000 }, /* 48 */
3013 { 88200, SNDRV_PCM_RATE_88200, 0x4800 }, /* 2 x 44 */
3014 { 96000, SNDRV_PCM_RATE_96000, 0x0800 }, /* 2 x 48 */
3015 { 176400, SNDRV_PCM_RATE_176400, 0x5800 },/* 4 x 44 */
3016 { 192000, SNDRV_PCM_RATE_192000, 0x1800 }, /* 4 x 48 */
3017 #define AC_PAR_PCM_RATE_BITS 11
3018 /* up to bits 10, 384kHZ isn't supported properly */
3020 /* not autodetected value */
3021 { 9600, SNDRV_PCM_RATE_KNOT, 0x0400 }, /* 1/5 x 48 */
3023 { 0 } /* terminator */
3027 * snd_hda_calc_stream_format - calculate format bitset
3028 * @rate: the sample rate
3029 * @channels: the number of channels
3030 * @format: the PCM format (SNDRV_PCM_FORMAT_XXX)
3031 * @maxbps: the max. bps
3033 * Calculate the format bitset from the given rate, channels and th PCM format.
3035 * Return zero if invalid.
3037 unsigned int snd_hda_calc_stream_format(unsigned int rate,
3038 unsigned int channels,
3039 unsigned int format,
3040 unsigned int maxbps)
3043 unsigned int val = 0;
3045 for (i = 0; rate_bits[i].hz; i++)
3046 if (rate_bits[i].hz == rate) {
3047 val = rate_bits[i].hda_fmt;
3050 if (!rate_bits[i].hz) {
3051 snd_printdd("invalid rate %d\n", rate);
3055 if (channels == 0 || channels > 8) {
3056 snd_printdd("invalid channels %d\n", channels);
3059 val |= channels - 1;
3061 switch (snd_pcm_format_width(format)) {
3071 if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE)
3073 else if (maxbps >= 24)
3079 snd_printdd("invalid format width %d\n",
3080 snd_pcm_format_width(format));
3086 EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
3088 static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3090 unsigned int val = 0;
3091 if (nid != codec->afg &&
3092 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
3093 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
3094 if (!val || val == -1)
3095 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
3096 if (!val || val == -1)
3101 static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3103 return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid),
3107 static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid)
3109 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
3110 if (!streams || streams == -1)
3111 streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
3112 if (!streams || streams == -1)
3117 static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid)
3119 return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid),
3124 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
3125 * @codec: the HDA codec
3126 * @nid: NID to query
3127 * @ratesp: the pointer to store the detected rate bitflags
3128 * @formatsp: the pointer to store the detected formats
3129 * @bpsp: the pointer to store the detected format widths
3131 * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp
3132 * or @bsps argument is ignored.
3134 * Returns 0 if successful, otherwise a negative error code.
3136 static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
3137 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
3139 unsigned int i, val, wcaps;
3141 wcaps = get_wcaps(codec, nid);
3142 val = query_pcm_param(codec, nid);
3146 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) {
3148 rates |= rate_bits[i].alsa_bits;
3151 snd_printk(KERN_ERR "hda_codec: rates == 0 "
3152 "(nid=0x%x, val=0x%x, ovrd=%i)\n",
3154 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0);
3160 if (formatsp || bpsp) {
3162 unsigned int streams, bps;
3164 streams = query_stream_param(codec, nid);
3169 if (streams & AC_SUPFMT_PCM) {
3170 if (val & AC_SUPPCM_BITS_8) {
3171 formats |= SNDRV_PCM_FMTBIT_U8;
3174 if (val & AC_SUPPCM_BITS_16) {
3175 formats |= SNDRV_PCM_FMTBIT_S16_LE;
3178 if (wcaps & AC_WCAP_DIGITAL) {
3179 if (val & AC_SUPPCM_BITS_32)
3180 formats |= SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
3181 if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24))
3182 formats |= SNDRV_PCM_FMTBIT_S32_LE;
3183 if (val & AC_SUPPCM_BITS_24)
3185 else if (val & AC_SUPPCM_BITS_20)
3187 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|
3188 AC_SUPPCM_BITS_32)) {
3189 formats |= SNDRV_PCM_FMTBIT_S32_LE;
3190 if (val & AC_SUPPCM_BITS_32)
3192 else if (val & AC_SUPPCM_BITS_24)
3194 else if (val & AC_SUPPCM_BITS_20)
3198 if (streams & AC_SUPFMT_FLOAT32) {
3199 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
3203 if (streams == AC_SUPFMT_AC3) {
3204 /* should be exclusive */
3205 /* temporary hack: we have still no proper support
3206 * for the direct AC3 stream...
3208 formats |= SNDRV_PCM_FMTBIT_U8;
3212 snd_printk(KERN_ERR "hda_codec: formats == 0 "
3213 "(nid=0x%x, val=0x%x, ovrd=%i, "
3216 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0,
3221 *formatsp = formats;
3230 * snd_hda_is_supported_format - Check the validity of the format
3231 * @codec: HD-audio codec
3232 * @nid: NID to check
3233 * @format: the HD-audio format value to check
3235 * Check whether the given node supports the format value.
3237 * Returns 1 if supported, 0 if not.
3239 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
3240 unsigned int format)
3243 unsigned int val = 0, rate, stream;
3245 val = query_pcm_param(codec, nid);
3249 rate = format & 0xff00;
3250 for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++)
3251 if (rate_bits[i].hda_fmt == rate) {
3256 if (i >= AC_PAR_PCM_RATE_BITS)
3259 stream = query_stream_param(codec, nid);
3263 if (stream & AC_SUPFMT_PCM) {
3264 switch (format & 0xf0) {
3266 if (!(val & AC_SUPPCM_BITS_8))
3270 if (!(val & AC_SUPPCM_BITS_16))
3274 if (!(val & AC_SUPPCM_BITS_20))
3278 if (!(val & AC_SUPPCM_BITS_24))
3282 if (!(val & AC_SUPPCM_BITS_32))
3289 /* FIXME: check for float32 and AC3? */
3294 EXPORT_SYMBOL_HDA(snd_hda_is_supported_format);
3299 static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
3300 struct hda_codec *codec,
3301 struct snd_pcm_substream *substream)
3306 static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
3307 struct hda_codec *codec,
3308 unsigned int stream_tag,
3309 unsigned int format,
3310 struct snd_pcm_substream *substream)
3312 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3316 static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
3317 struct hda_codec *codec,
3318 struct snd_pcm_substream *substream)
3320 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3324 static int set_pcm_default_values(struct hda_codec *codec,
3325 struct hda_pcm_stream *info)
3329 /* query support PCM information from the given NID */
3330 if (info->nid && (!info->rates || !info->formats)) {
3331 err = snd_hda_query_supported_pcm(codec, info->nid,
3332 info->rates ? NULL : &info->rates,
3333 info->formats ? NULL : &info->formats,
3334 info->maxbps ? NULL : &info->maxbps);
3338 if (info->ops.open == NULL)
3339 info->ops.open = hda_pcm_default_open_close;
3340 if (info->ops.close == NULL)
3341 info->ops.close = hda_pcm_default_open_close;
3342 if (info->ops.prepare == NULL) {
3343 if (snd_BUG_ON(!info->nid))
3345 info->ops.prepare = hda_pcm_default_prepare;
3347 if (info->ops.cleanup == NULL) {
3348 if (snd_BUG_ON(!info->nid))
3350 info->ops.cleanup = hda_pcm_default_cleanup;
3356 const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3357 "Audio", "SPDIF", "HDMI", "Modem"
3361 * get the empty PCM device number to assign
3363 * note the max device number is limited by HDA_MAX_PCMS, currently 10
3365 static int get_empty_pcm_device(struct hda_bus *bus, int type)
3367 /* audio device indices; not linear to keep compatibility */
3368 static int audio_idx[HDA_PCM_NTYPES][5] = {
3369 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
3370 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
3371 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
3372 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
3376 if (type >= HDA_PCM_NTYPES) {
3377 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
3381 for (i = 0; audio_idx[type][i] >= 0 ; i++)
3382 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3383 return audio_idx[type][i];
3385 snd_printk(KERN_WARNING "Too many %s devices\n",
3386 snd_hda_pcm_type_name[type]);
3391 * attach a new PCM stream
3393 static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
3395 struct hda_bus *bus = codec->bus;
3396 struct hda_pcm_stream *info;
3399 if (snd_BUG_ON(!pcm->name))
3401 for (stream = 0; stream < 2; stream++) {
3402 info = &pcm->stream[stream];
3403 if (info->substreams) {
3404 err = set_pcm_default_values(codec, info);
3409 return bus->ops.attach_pcm(bus, codec, pcm);
3412 /* assign all PCMs of the given codec */
3413 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3418 if (!codec->num_pcms) {
3419 if (!codec->patch_ops.build_pcms)
3421 err = codec->patch_ops.build_pcms(codec);
3423 printk(KERN_ERR "hda_codec: cannot build PCMs"
3424 "for #%d (error %d)\n", codec->addr, err);
3425 err = snd_hda_codec_reset(codec);
3428 "hda_codec: cannot revert codec\n");
3433 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
3434 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
3437 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
3438 continue; /* no substreams assigned */
3441 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type);
3443 continue; /* no fatal error */
3445 err = snd_hda_attach_pcm(codec, cpcm);
3447 printk(KERN_ERR "hda_codec: cannot attach "
3448 "PCM stream %d for codec #%d\n",
3450 continue; /* no fatal error */
3458 * snd_hda_build_pcms - build PCM information
3461 * Create PCM information for each codec included in the bus.
3463 * The build_pcms codec patch is requested to set up codec->num_pcms and
3464 * codec->pcm_info properly. The array is referred by the top-level driver
3465 * to create its PCM instances.
3466 * The allocated codec->pcm_info should be released in codec->patch_ops.free
3469 * At least, substreams, channels_min and channels_max must be filled for
3470 * each stream. substreams = 0 indicates that the stream doesn't exist.
3471 * When rates and/or formats are zero, the supported values are queried
3472 * from the given nid. The nid is used also by the default ops.prepare
3473 * and ops.cleanup callbacks.
3475 * The driver needs to call ops.open in its open callback. Similarly,
3476 * ops.close is supposed to be called in the close callback.
3477 * ops.prepare should be called in the prepare or hw_params callback
3478 * with the proper parameters for set up.
3479 * ops.cleanup should be called in hw_free for clean up of streams.
3481 * This function returns 0 if successfull, or a negative error code.
3483 int __devinit snd_hda_build_pcms(struct hda_bus *bus)
3485 struct hda_codec *codec;
3487 list_for_each_entry(codec, &bus->codec_list, list) {
3488 int err = snd_hda_codec_build_pcms(codec);
3494 EXPORT_SYMBOL_HDA(snd_hda_build_pcms);
3497 * snd_hda_check_board_config - compare the current codec with the config table
3498 * @codec: the HDA codec
3499 * @num_configs: number of config enums
3500 * @models: array of model name strings
3501 * @tbl: configuration table, terminated by null entries
3503 * Compares the modelname or PCI subsystem id of the current codec with the
3504 * given configuration table. If a matching entry is found, returns its
3505 * config value (supposed to be 0 or positive).
3507 * If no entries are matching, the function returns a negative value.
3509 int snd_hda_check_board_config(struct hda_codec *codec,
3510 int num_configs, const char **models,
3511 const struct snd_pci_quirk *tbl)
3513 if (codec->modelname && models) {
3515 for (i = 0; i < num_configs; i++) {
3517 !strcmp(codec->modelname, models[i])) {
3518 snd_printd(KERN_INFO "hda_codec: model '%s' is "
3519 "selected\n", models[i]);
3525 if (!codec->bus->pci || !tbl)
3528 tbl = snd_pci_quirk_lookup(codec->bus->pci, tbl);
3531 if (tbl->value >= 0 && tbl->value < num_configs) {
3532 #ifdef CONFIG_SND_DEBUG_VERBOSE
3534 const char *model = NULL;
3536 model = models[tbl->value];
3538 sprintf(tmp, "#%d", tbl->value);
3541 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
3542 "for config %x:%x (%s)\n",
3543 model, tbl->subvendor, tbl->subdevice,
3544 (tbl->name ? tbl->name : "Unknown device"));
3550 EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
3553 * snd_hda_check_board_codec_sid_config - compare the current codec
3554 subsystem ID with the
3557 This is important for Gateway notebooks with SB450 HDA Audio
3558 where the vendor ID of the PCI device is:
3559 ATI Technologies Inc SB450 HDA Audio [1002:437b]
3560 and the vendor/subvendor are found only at the codec.
3562 * @codec: the HDA codec
3563 * @num_configs: number of config enums
3564 * @models: array of model name strings
3565 * @tbl: configuration table, terminated by null entries
3567 * Compares the modelname or PCI subsystem id of the current codec with the
3568 * given configuration table. If a matching entry is found, returns its
3569 * config value (supposed to be 0 or positive).
3571 * If no entries are matching, the function returns a negative value.
3573 int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
3574 int num_configs, const char **models,
3575 const struct snd_pci_quirk *tbl)
3577 const struct snd_pci_quirk *q;
3579 /* Search for codec ID */
3580 for (q = tbl; q->subvendor; q++) {
3581 unsigned long vendorid = (q->subdevice) | (q->subvendor << 16);
3583 if (vendorid == codec->subsystem_id)
3592 if (tbl->value >= 0 && tbl->value < num_configs) {
3593 #ifdef CONFIG_SND_DEBUG_VERBOSE
3595 const char *model = NULL;
3597 model = models[tbl->value];
3599 sprintf(tmp, "#%d", tbl->value);
3602 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected "
3603 "for config %x:%x (%s)\n",
3604 model, tbl->subvendor, tbl->subdevice,
3605 (tbl->name ? tbl->name : "Unknown device"));
3611 EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3614 * snd_hda_add_new_ctls - create controls from the array
3615 * @codec: the HDA codec
3616 * @knew: the array of struct snd_kcontrol_new
3618 * This helper function creates and add new controls in the given array.
3619 * The array must be terminated with an empty entry as terminator.
3621 * Returns 0 if successful, or a negative error code.
3623 int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3627 for (; knew->name; knew++) {
3628 struct snd_kcontrol *kctl;
3629 if (knew->iface == -1) /* skip this codec private value */
3631 kctl = snd_ctl_new1(knew, codec);
3634 err = snd_hda_ctl_add(codec, 0, kctl);
3638 kctl = snd_ctl_new1(knew, codec);
3641 kctl->id.device = codec->addr;
3642 err = snd_hda_ctl_add(codec, 0, kctl);
3649 EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);
3651 #ifdef CONFIG_SND_HDA_POWER_SAVE
3652 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
3653 unsigned int power_state);
3655 static void hda_power_work(struct work_struct *work)
3657 struct hda_codec *codec =
3658 container_of(work, struct hda_codec, power_work.work);
3659 struct hda_bus *bus = codec->bus;
3661 if (!codec->power_on || codec->power_count) {
3662 codec->power_transition = 0;
3666 hda_call_codec_suspend(codec);
3667 if (bus->ops.pm_notify)
3668 bus->ops.pm_notify(bus);
3671 static void hda_keep_power_on(struct hda_codec *codec)
3673 codec->power_count++;
3674 codec->power_on = 1;
3675 codec->power_jiffies = jiffies;
3678 /* update the power on/off account with the current jiffies */
3679 void snd_hda_update_power_acct(struct hda_codec *codec)
3681 unsigned long delta = jiffies - codec->power_jiffies;
3682 if (codec->power_on)
3683 codec->power_on_acct += delta;
3685 codec->power_off_acct += delta;
3686 codec->power_jiffies += delta;
3690 * snd_hda_power_up - Power-up the codec
3691 * @codec: HD-audio codec
3693 * Increment the power-up counter and power up the hardware really when
3694 * not turned on yet.
3696 void snd_hda_power_up(struct hda_codec *codec)
3698 struct hda_bus *bus = codec->bus;
3700 codec->power_count++;
3701 if (codec->power_on || codec->power_transition)
3704 snd_hda_update_power_acct(codec);
3705 codec->power_on = 1;
3706 codec->power_jiffies = jiffies;
3707 if (bus->ops.pm_notify)
3708 bus->ops.pm_notify(bus);
3709 hda_call_codec_resume(codec);
3710 cancel_delayed_work(&codec->power_work);
3711 codec->power_transition = 0;
3713 EXPORT_SYMBOL_HDA(snd_hda_power_up);
3715 #define power_save(codec) \
3716 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3719 * snd_hda_power_down - Power-down the codec
3720 * @codec: HD-audio codec
3722 * Decrement the power-up counter and schedules the power-off work if
3723 * the counter rearches to zero.
3725 void snd_hda_power_down(struct hda_codec *codec)
3727 --codec->power_count;
3728 if (!codec->power_on || codec->power_count || codec->power_transition)
3730 if (power_save(codec)) {
3731 codec->power_transition = 1; /* avoid reentrance */
3732 queue_delayed_work(codec->bus->workq, &codec->power_work,
3733 msecs_to_jiffies(power_save(codec) * 1000));
3736 EXPORT_SYMBOL_HDA(snd_hda_power_down);
3739 * snd_hda_check_amp_list_power - Check the amp list and update the power
3740 * @codec: HD-audio codec
3741 * @check: the object containing an AMP list and the status
3742 * @nid: NID to check / update
3744 * Check whether the given NID is in the amp list. If it's in the list,
3745 * check the current AMP status, and update the the power-status according
3746 * to the mute status.
3748 * This function is supposed to be set or called from the check_power_status
3751 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3752 struct hda_loopback_check *check,
3755 struct hda_amp_list *p;
3758 if (!check->amplist)
3760 for (p = check->amplist; p->nid; p++) {
3765 return 0; /* nothing changed */
3767 for (p = check->amplist; p->nid; p++) {
3768 for (ch = 0; ch < 2; ch++) {
3769 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3771 if (!(v & HDA_AMP_MUTE) && v > 0) {
3772 if (!check->power_on) {
3773 check->power_on = 1;
3774 snd_hda_power_up(codec);
3780 if (check->power_on) {
3781 check->power_on = 0;
3782 snd_hda_power_down(codec);
3786 EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3790 * Channel mode helper
3794 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3796 int snd_hda_ch_mode_info(struct hda_codec *codec,
3797 struct snd_ctl_elem_info *uinfo,
3798 const struct hda_channel_mode *chmode,
3801 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3803 uinfo->value.enumerated.items = num_chmodes;
3804 if (uinfo->value.enumerated.item >= num_chmodes)
3805 uinfo->value.enumerated.item = num_chmodes - 1;
3806 sprintf(uinfo->value.enumerated.name, "%dch",
3807 chmode[uinfo->value.enumerated.item].channels);
3810 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3813 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3815 int snd_hda_ch_mode_get(struct hda_codec *codec,
3816 struct snd_ctl_elem_value *ucontrol,
3817 const struct hda_channel_mode *chmode,
3823 for (i = 0; i < num_chmodes; i++) {
3824 if (max_channels == chmode[i].channels) {
3825 ucontrol->value.enumerated.item[0] = i;
3831 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3834 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3836 int snd_hda_ch_mode_put(struct hda_codec *codec,
3837 struct snd_ctl_elem_value *ucontrol,
3838 const struct hda_channel_mode *chmode,
3844 mode = ucontrol->value.enumerated.item[0];
3845 if (mode >= num_chmodes)
3847 if (*max_channelsp == chmode[mode].channels)
3849 /* change the current channel setting */
3850 *max_channelsp = chmode[mode].channels;
3851 if (chmode[mode].sequence)
3852 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
3855 EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3862 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3864 int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3865 struct snd_ctl_elem_info *uinfo)
3869 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3871 uinfo->value.enumerated.items = imux->num_items;
3872 if (!imux->num_items)
3874 index = uinfo->value.enumerated.item;
3875 if (index >= imux->num_items)
3876 index = imux->num_items - 1;
3877 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
3880 EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3883 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3885 int snd_hda_input_mux_put(struct hda_codec *codec,
3886 const struct hda_input_mux *imux,
3887 struct snd_ctl_elem_value *ucontrol,
3889 unsigned int *cur_val)
3893 if (!imux->num_items)
3895 idx = ucontrol->value.enumerated.item[0];
3896 if (idx >= imux->num_items)
3897 idx = imux->num_items - 1;
3898 if (*cur_val == idx)
3900 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3901 imux->items[idx].index);
3905 EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
3909 * Multi-channel / digital-out PCM helper functions
3912 /* setup SPDIF output stream */
3913 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3914 unsigned int stream_tag, unsigned int format)
3916 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3917 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3918 set_dig_out_convert(codec, nid,
3919 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
3921 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3922 if (codec->slave_dig_outs) {
3924 for (d = codec->slave_dig_outs; *d; d++)
3925 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3928 /* turn on again (if needed) */
3929 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3930 set_dig_out_convert(codec, nid,
3931 codec->spdif_ctls & 0xff, -1);
3934 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3936 snd_hda_codec_cleanup_stream(codec, nid);
3937 if (codec->slave_dig_outs) {
3939 for (d = codec->slave_dig_outs; *d; d++)
3940 snd_hda_codec_cleanup_stream(codec, *d);
3945 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3946 * @bus: HD-audio bus
3948 void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3950 struct hda_codec *codec;
3954 list_for_each_entry(codec, &bus->codec_list, list) {
3955 #ifdef CONFIG_SND_HDA_POWER_SAVE
3956 if (!codec->power_on)
3959 if (codec->patch_ops.reboot_notify)
3960 codec->patch_ops.reboot_notify(codec);
3963 EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3966 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3968 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3969 struct hda_multi_out *mout)
3971 mutex_lock(&codec->spdif_mutex);
3972 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
3973 /* already opened as analog dup; reset it once */
3974 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3975 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
3976 mutex_unlock(&codec->spdif_mutex);
3979 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3982 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3984 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3985 struct hda_multi_out *mout,
3986 unsigned int stream_tag,
3987 unsigned int format,
3988 struct snd_pcm_substream *substream)
3990 mutex_lock(&codec->spdif_mutex);
3991 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3992 mutex_unlock(&codec->spdif_mutex);
3995 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3998 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
4000 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
4001 struct hda_multi_out *mout)
4003 mutex_lock(&codec->spdif_mutex);
4004 cleanup_dig_out_stream(codec, mout->dig_out_nid);
4005 mutex_unlock(&codec->spdif_mutex);
4008 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
4011 * snd_hda_multi_out_dig_close - release the digital out stream
4013 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
4014 struct hda_multi_out *mout)
4016 mutex_lock(&codec->spdif_mutex);
4017 mout->dig_out_used = 0;
4018 mutex_unlock(&codec->spdif_mutex);
4021 EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
4024 * snd_hda_multi_out_analog_open - open analog outputs
4026 * Open analog outputs and set up the hw-constraints.
4027 * If the digital outputs can be opened as slave, open the digital
4030 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
4031 struct hda_multi_out *mout,
4032 struct snd_pcm_substream *substream,
4033 struct hda_pcm_stream *hinfo)
4035 struct snd_pcm_runtime *runtime = substream->runtime;
4036 runtime->hw.channels_max = mout->max_channels;
4037 if (mout->dig_out_nid) {
4038 if (!mout->analog_rates) {
4039 mout->analog_rates = hinfo->rates;
4040 mout->analog_formats = hinfo->formats;
4041 mout->analog_maxbps = hinfo->maxbps;
4043 runtime->hw.rates = mout->analog_rates;
4044 runtime->hw.formats = mout->analog_formats;
4045 hinfo->maxbps = mout->analog_maxbps;
4047 if (!mout->spdif_rates) {
4048 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
4050 &mout->spdif_formats,
4051 &mout->spdif_maxbps);
4053 mutex_lock(&codec->spdif_mutex);
4054 if (mout->share_spdif) {
4055 if ((runtime->hw.rates & mout->spdif_rates) &&
4056 (runtime->hw.formats & mout->spdif_formats)) {
4057 runtime->hw.rates &= mout->spdif_rates;
4058 runtime->hw.formats &= mout->spdif_formats;
4059 if (mout->spdif_maxbps < hinfo->maxbps)
4060 hinfo->maxbps = mout->spdif_maxbps;
4062 mout->share_spdif = 0;
4063 /* FIXME: need notify? */
4066 mutex_unlock(&codec->spdif_mutex);
4068 return snd_pcm_hw_constraint_step(substream->runtime, 0,
4069 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
4071 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
4074 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
4076 * Set up the i/o for analog out.
4077 * When the digital out is available, copy the front out to digital out, too.
4079 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
4080 struct hda_multi_out *mout,
4081 unsigned int stream_tag,
4082 unsigned int format,
4083 struct snd_pcm_substream *substream)
4085 hda_nid_t *nids = mout->dac_nids;
4086 int chs = substream->runtime->channels;
4089 mutex_lock(&codec->spdif_mutex);
4090 if (mout->dig_out_nid && mout->share_spdif &&
4091 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
4093 snd_hda_is_supported_format(codec, mout->dig_out_nid,
4095 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
4096 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
4097 setup_dig_out_stream(codec, mout->dig_out_nid,
4098 stream_tag, format);
4100 mout->dig_out_used = 0;
4101 cleanup_dig_out_stream(codec, mout->dig_out_nid);
4104 mutex_unlock(&codec->spdif_mutex);
4107 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
4109 if (!mout->no_share_stream &&
4110 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
4111 /* headphone out will just decode front left/right (stereo) */
4112 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
4114 /* extra outputs copied from front */
4115 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4116 if (!mout->no_share_stream && mout->extra_out_nid[i])
4117 snd_hda_codec_setup_stream(codec,
4118 mout->extra_out_nid[i],
4119 stream_tag, 0, format);
4122 for (i = 1; i < mout->num_dacs; i++) {
4123 if (chs >= (i + 1) * 2) /* independent out */
4124 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
4126 else if (!mout->no_share_stream) /* copy front */
4127 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
4132 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
4135 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
4137 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
4138 struct hda_multi_out *mout)
4140 hda_nid_t *nids = mout->dac_nids;
4143 for (i = 0; i < mout->num_dacs; i++)
4144 snd_hda_codec_cleanup_stream(codec, nids[i]);
4146 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
4147 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4148 if (mout->extra_out_nid[i])
4149 snd_hda_codec_cleanup_stream(codec,
4150 mout->extra_out_nid[i]);
4151 mutex_lock(&codec->spdif_mutex);
4152 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
4153 cleanup_dig_out_stream(codec, mout->dig_out_nid);
4154 mout->dig_out_used = 0;
4156 mutex_unlock(&codec->spdif_mutex);
4159 EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
4162 * Helper for automatic pin configuration
4165 static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
4167 for (; *list; list++)
4175 * Sort an associated group of pins according to their sequence numbers.
4177 static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
4184 for (i = 0; i < num_pins; i++) {
4185 for (j = i + 1; j < num_pins; j++) {
4186 if (sequences[i] > sequences[j]) {
4188 sequences[i] = sequences[j];
4200 * Parse all pin widgets and store the useful pin nids to cfg
4202 * The number of line-outs or any primary output is stored in line_outs,
4203 * and the corresponding output pins are assigned to line_out_pins[],
4204 * in the order of front, rear, CLFE, side, ...
4206 * If more extra outputs (speaker and headphone) are found, the pins are
4207 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
4208 * is detected, one of speaker of HP pins is assigned as the primary
4209 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
4210 * if any analog output exists.
4212 * The analog input pins are assigned to input_pins array.
4213 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
4216 int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4217 struct auto_pin_cfg *cfg,
4218 hda_nid_t *ignore_nids)
4220 hda_nid_t nid, end_nid;
4221 short seq, assoc_line_out, assoc_speaker;
4222 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
4223 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
4224 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
4226 memset(cfg, 0, sizeof(*cfg));
4228 memset(sequences_line_out, 0, sizeof(sequences_line_out));
4229 memset(sequences_speaker, 0, sizeof(sequences_speaker));
4230 memset(sequences_hp, 0, sizeof(sequences_hp));
4231 assoc_line_out = assoc_speaker = 0;
4233 end_nid = codec->start_nid + codec->num_nodes;
4234 for (nid = codec->start_nid; nid < end_nid; nid++) {
4235 unsigned int wid_caps = get_wcaps(codec, nid);
4236 unsigned int wid_type = get_wcaps_type(wid_caps);
4237 unsigned int def_conf;
4240 /* read all default configuration for pin complex */
4241 if (wid_type != AC_WID_PIN)
4243 /* ignore the given nids (e.g. pc-beep returns error) */
4244 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
4247 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4248 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
4250 loc = get_defcfg_location(def_conf);
4251 switch (get_defcfg_device(def_conf)) {
4252 case AC_JACK_LINE_OUT:
4253 seq = get_defcfg_sequence(def_conf);
4254 assoc = get_defcfg_association(def_conf);
4256 if (!(wid_caps & AC_WCAP_STEREO))
4257 if (!cfg->mono_out_pin)
4258 cfg->mono_out_pin = nid;
4261 if (!assoc_line_out)
4262 assoc_line_out = assoc;
4263 else if (assoc_line_out != assoc)
4265 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
4267 cfg->line_out_pins[cfg->line_outs] = nid;
4268 sequences_line_out[cfg->line_outs] = seq;
4271 case AC_JACK_SPEAKER:
4272 seq = get_defcfg_sequence(def_conf);
4273 assoc = get_defcfg_association(def_conf);
4277 assoc_speaker = assoc;
4278 else if (assoc_speaker != assoc)
4280 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
4282 cfg->speaker_pins[cfg->speaker_outs] = nid;
4283 sequences_speaker[cfg->speaker_outs] = seq;
4284 cfg->speaker_outs++;
4286 case AC_JACK_HP_OUT:
4287 seq = get_defcfg_sequence(def_conf);
4288 assoc = get_defcfg_association(def_conf);
4289 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
4291 cfg->hp_pins[cfg->hp_outs] = nid;
4292 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
4295 case AC_JACK_MIC_IN: {
4297 if (loc == AC_JACK_LOC_FRONT ||
4298 (loc & 0x30) == AC_JACK_LOC_INTERNAL) {
4299 preferred = AUTO_PIN_FRONT_MIC;
4302 preferred = AUTO_PIN_MIC;
4303 alt = AUTO_PIN_FRONT_MIC;
4305 if (!cfg->input_pins[preferred])
4306 cfg->input_pins[preferred] = nid;
4307 else if (!cfg->input_pins[alt])
4308 cfg->input_pins[alt] = nid;
4311 case AC_JACK_LINE_IN:
4312 if (loc == AC_JACK_LOC_FRONT)
4313 cfg->input_pins[AUTO_PIN_FRONT_LINE] = nid;
4315 cfg->input_pins[AUTO_PIN_LINE] = nid;
4318 cfg->input_pins[AUTO_PIN_CD] = nid;
4321 cfg->input_pins[AUTO_PIN_AUX] = nid;
4323 case AC_JACK_SPDIF_OUT:
4324 case AC_JACK_DIG_OTHER_OUT:
4325 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
4327 cfg->dig_out_pins[cfg->dig_outs] = nid;
4328 cfg->dig_out_type[cfg->dig_outs] =
4329 (loc == AC_JACK_LOC_HDMI) ?
4330 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
4333 case AC_JACK_SPDIF_IN:
4334 case AC_JACK_DIG_OTHER_IN:
4335 cfg->dig_in_pin = nid;
4336 if (loc == AC_JACK_LOC_HDMI)
4337 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
4339 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
4345 * If no line-out is defined but multiple HPs are found,
4346 * some of them might be the real line-outs.
4348 if (!cfg->line_outs && cfg->hp_outs > 1) {
4350 while (i < cfg->hp_outs) {
4351 /* The real HPs should have the sequence 0x0f */
4352 if ((sequences_hp[i] & 0x0f) == 0x0f) {
4356 /* Move it to the line-out table */
4357 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
4358 sequences_line_out[cfg->line_outs] = sequences_hp[i];
4361 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
4362 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
4363 memmove(sequences_hp + i - 1, sequences_hp + i,
4364 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
4368 /* sort by sequence */
4369 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
4371 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
4373 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
4376 /* if we have only one mic, make it AUTO_PIN_MIC */
4377 if (!cfg->input_pins[AUTO_PIN_MIC] &&
4378 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
4379 cfg->input_pins[AUTO_PIN_MIC] =
4380 cfg->input_pins[AUTO_PIN_FRONT_MIC];
4381 cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0;
4383 /* ditto for line-in */
4384 if (!cfg->input_pins[AUTO_PIN_LINE] &&
4385 cfg->input_pins[AUTO_PIN_FRONT_LINE]) {
4386 cfg->input_pins[AUTO_PIN_LINE] =
4387 cfg->input_pins[AUTO_PIN_FRONT_LINE];
4388 cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0;
4392 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
4393 * as a primary output
4395 if (!cfg->line_outs) {
4396 if (cfg->speaker_outs) {
4397 cfg->line_outs = cfg->speaker_outs;
4398 memcpy(cfg->line_out_pins, cfg->speaker_pins,
4399 sizeof(cfg->speaker_pins));
4400 cfg->speaker_outs = 0;
4401 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
4402 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
4403 } else if (cfg->hp_outs) {
4404 cfg->line_outs = cfg->hp_outs;
4405 memcpy(cfg->line_out_pins, cfg->hp_pins,
4406 sizeof(cfg->hp_pins));
4408 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4409 cfg->line_out_type = AUTO_PIN_HP_OUT;
4413 /* Reorder the surround channels
4414 * ALSA sequence is front/surr/clfe/side
4416 * 4-ch: front/surr => OK as it is
4417 * 6-ch: front/clfe/surr
4418 * 8-ch: front/clfe/rear/side|fc
4420 switch (cfg->line_outs) {
4423 nid = cfg->line_out_pins[1];
4424 cfg->line_out_pins[1] = cfg->line_out_pins[2];
4425 cfg->line_out_pins[2] = nid;
4430 * debug prints of the parsed results
4432 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4433 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
4434 cfg->line_out_pins[2], cfg->line_out_pins[3],
4435 cfg->line_out_pins[4]);
4436 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4437 cfg->speaker_outs, cfg->speaker_pins[0],
4438 cfg->speaker_pins[1], cfg->speaker_pins[2],
4439 cfg->speaker_pins[3], cfg->speaker_pins[4]);
4440 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4441 cfg->hp_outs, cfg->hp_pins[0],
4442 cfg->hp_pins[1], cfg->hp_pins[2],
4443 cfg->hp_pins[3], cfg->hp_pins[4]);
4444 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
4446 snd_printd(" dig-out=0x%x/0x%x\n",
4447 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
4448 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
4449 " cd=0x%x, aux=0x%x\n",
4450 cfg->input_pins[AUTO_PIN_MIC],
4451 cfg->input_pins[AUTO_PIN_FRONT_MIC],
4452 cfg->input_pins[AUTO_PIN_LINE],
4453 cfg->input_pins[AUTO_PIN_FRONT_LINE],
4454 cfg->input_pins[AUTO_PIN_CD],
4455 cfg->input_pins[AUTO_PIN_AUX]);
4456 if (cfg->dig_in_pin)
4457 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
4461 EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
4463 /* labels for input pins */
4464 const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
4465 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
4467 EXPORT_SYMBOL_HDA(auto_pin_cfg_labels);
4476 * snd_hda_suspend - suspend the codecs
4479 * Returns 0 if successful.
4481 int snd_hda_suspend(struct hda_bus *bus)
4483 struct hda_codec *codec;
4485 list_for_each_entry(codec, &bus->codec_list, list) {
4486 #ifdef CONFIG_SND_HDA_POWER_SAVE
4487 if (!codec->power_on)
4490 hda_call_codec_suspend(codec);
4494 EXPORT_SYMBOL_HDA(snd_hda_suspend);
4497 * snd_hda_resume - resume the codecs
4500 * Returns 0 if successful.
4502 * This fucntion is defined only when POWER_SAVE isn't set.
4503 * In the power-save mode, the codec is resumed dynamically.
4505 int snd_hda_resume(struct hda_bus *bus)
4507 struct hda_codec *codec;
4509 list_for_each_entry(codec, &bus->codec_list, list) {
4510 if (snd_hda_codec_needs_resume(codec))
4511 hda_call_codec_resume(codec);
4515 EXPORT_SYMBOL_HDA(snd_hda_resume);
4516 #endif /* CONFIG_PM */
4523 * snd_array_new - get a new element from the given array
4524 * @array: the array object
4526 * Get a new element from the given array. If it exceeds the
4527 * pre-allocated array size, re-allocate the array.
4529 * Returns NULL if allocation failed.
4531 void *snd_array_new(struct snd_array *array)
4533 if (array->used >= array->alloced) {
4534 int num = array->alloced + array->alloc_align;
4536 if (snd_BUG_ON(num >= 4096))
4538 nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
4542 memcpy(nlist, array->list,
4543 array->elem_size * array->alloced);
4546 array->list = nlist;
4547 array->alloced = num;
4549 return snd_array_elem(array, array->used++);
4551 EXPORT_SYMBOL_HDA(snd_array_new);
4554 * snd_array_free - free the given array elements
4555 * @array: the array object
4557 void snd_array_free(struct snd_array *array)
4564 EXPORT_SYMBOL_HDA(snd_array_free);
4567 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4568 * @pcm: PCM caps bits
4569 * @buf: the string buffer to write
4570 * @buflen: the max buffer length
4572 * used by hda_proc.c and hda_eld.c
4574 void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4576 static unsigned int rates[] = {
4577 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
4578 96000, 176400, 192000, 384000
4582 for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
4584 j += snprintf(buf + j, buflen - j, " %d", rates[i]);
4586 buf[j] = '\0'; /* necessary when j == 0 */
4588 EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4591 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4592 * @pcm: PCM caps bits
4593 * @buf: the string buffer to write
4594 * @buflen: the max buffer length
4596 * used by hda_proc.c and hda_eld.c
4598 void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4600 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
4603 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
4604 if (pcm & (AC_SUPPCM_BITS_8 << i))
4605 j += snprintf(buf + j, buflen - j, " %d", bits[i]);
4607 buf[j] = '\0'; /* necessary when j == 0 */
4609 EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
4611 MODULE_DESCRIPTION("HDA codec core");
4612 MODULE_LICENSE("GPL");