net: dsa: mt7530: set CPU port to fallback mode
[linux/fpc-iii.git] / sound / pci / hda / hda_codec.c
blobf3a6b1d869d8a2e06cf4ff05999e859b227b490f
1 /*
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/mutex.h>
26 #include <linux/module.h>
27 #include <linux/pm.h>
28 #include <linux/pm_runtime.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include <sound/asoundef.h>
32 #include <sound/tlv.h>
33 #include <sound/initval.h>
34 #include <sound/jack.h>
35 #include "hda_local.h"
36 #include "hda_beep.h"
37 #include "hda_jack.h"
38 #include <sound/hda_hwdep.h>
40 #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core)
41 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core)
42 #define codec_has_epss(codec) \
43 ((codec)->core.power_caps & AC_PWRST_EPSS)
44 #define codec_has_clkstop(codec) \
45 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
48 * Send and receive a verb - passed to exec_verb override for hdac_device
50 static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
51 unsigned int flags, unsigned int *res)
53 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
54 struct hda_bus *bus = codec->bus;
55 int err;
57 if (cmd == ~0)
58 return -1;
60 again:
61 snd_hda_power_up_pm(codec);
62 mutex_lock(&bus->core.cmd_mutex);
63 if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
64 bus->no_response_fallback = 1;
65 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
66 cmd, res);
67 bus->no_response_fallback = 0;
68 mutex_unlock(&bus->core.cmd_mutex);
69 snd_hda_power_down_pm(codec);
70 if (!codec_in_pm(codec) && res && err == -EAGAIN) {
71 if (bus->response_reset) {
72 codec_dbg(codec,
73 "resetting BUS due to fatal communication error\n");
74 snd_hda_bus_reset(bus);
76 goto again;
78 /* clear reset-flag when the communication gets recovered */
79 if (!err || codec_in_pm(codec))
80 bus->response_reset = 0;
81 return err;
84 /**
85 * snd_hda_sequence_write - sequence writes
86 * @codec: the HDA codec
87 * @seq: VERB array to send
89 * Send the commands sequentially from the given array.
90 * The array must be terminated with NID=0.
92 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
94 for (; seq->nid; seq++)
95 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
97 EXPORT_SYMBOL_GPL(snd_hda_sequence_write);
99 /* connection list element */
100 struct hda_conn_list {
101 struct list_head list;
102 int len;
103 hda_nid_t nid;
104 hda_nid_t conns[0];
107 /* look up the cached results */
108 static struct hda_conn_list *
109 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
111 struct hda_conn_list *p;
112 list_for_each_entry(p, &codec->conn_list, list) {
113 if (p->nid == nid)
114 return p;
116 return NULL;
119 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
120 const hda_nid_t *list)
122 struct hda_conn_list *p;
124 p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL);
125 if (!p)
126 return -ENOMEM;
127 p->len = len;
128 p->nid = nid;
129 memcpy(p->conns, list, len * sizeof(hda_nid_t));
130 list_add(&p->list, &codec->conn_list);
131 return 0;
134 static void remove_conn_list(struct hda_codec *codec)
136 while (!list_empty(&codec->conn_list)) {
137 struct hda_conn_list *p;
138 p = list_first_entry(&codec->conn_list, typeof(*p), list);
139 list_del(&p->list);
140 kfree(p);
144 /* read the connection and add to the cache */
145 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
147 hda_nid_t list[32];
148 hda_nid_t *result = list;
149 int len;
151 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
152 if (len == -ENOSPC) {
153 len = snd_hda_get_num_raw_conns(codec, nid);
154 result = kmalloc_array(len, sizeof(hda_nid_t), GFP_KERNEL);
155 if (!result)
156 return -ENOMEM;
157 len = snd_hda_get_raw_connections(codec, nid, result, len);
159 if (len >= 0)
160 len = snd_hda_override_conn_list(codec, nid, len, result);
161 if (result != list)
162 kfree(result);
163 return len;
167 * snd_hda_get_conn_list - get connection list
168 * @codec: the HDA codec
169 * @nid: NID to parse
170 * @listp: the pointer to store NID list
172 * Parses the connection list of the given widget and stores the pointer
173 * to the list of NIDs.
175 * Returns the number of connections, or a negative error code.
177 * Note that the returned pointer isn't protected against the list
178 * modification. If snd_hda_override_conn_list() might be called
179 * concurrently, protect with a mutex appropriately.
181 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
182 const hda_nid_t **listp)
184 bool added = false;
186 for (;;) {
187 int err;
188 const struct hda_conn_list *p;
190 /* if the connection-list is already cached, read it */
191 p = lookup_conn_list(codec, nid);
192 if (p) {
193 if (listp)
194 *listp = p->conns;
195 return p->len;
197 if (snd_BUG_ON(added))
198 return -EINVAL;
200 err = read_and_add_raw_conns(codec, nid);
201 if (err < 0)
202 return err;
203 added = true;
206 EXPORT_SYMBOL_GPL(snd_hda_get_conn_list);
209 * snd_hda_get_connections - copy connection list
210 * @codec: the HDA codec
211 * @nid: NID to parse
212 * @conn_list: connection list array; when NULL, checks only the size
213 * @max_conns: max. number of connections to store
215 * Parses the connection list of the given widget and stores the list
216 * of NIDs.
218 * Returns the number of connections, or a negative error code.
220 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
221 hda_nid_t *conn_list, int max_conns)
223 const hda_nid_t *list;
224 int len = snd_hda_get_conn_list(codec, nid, &list);
226 if (len > 0 && conn_list) {
227 if (len > max_conns) {
228 codec_err(codec, "Too many connections %d for NID 0x%x\n",
229 len, nid);
230 return -EINVAL;
232 memcpy(conn_list, list, len * sizeof(hda_nid_t));
235 return len;
237 EXPORT_SYMBOL_GPL(snd_hda_get_connections);
240 * snd_hda_override_conn_list - add/modify the connection-list to cache
241 * @codec: the HDA codec
242 * @nid: NID to parse
243 * @len: number of connection list entries
244 * @list: the list of connection entries
246 * Add or modify the given connection-list to the cache. If the corresponding
247 * cache already exists, invalidate it and append a new one.
249 * Returns zero or a negative error code.
251 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
252 const hda_nid_t *list)
254 struct hda_conn_list *p;
256 p = lookup_conn_list(codec, nid);
257 if (p) {
258 list_del(&p->list);
259 kfree(p);
262 return add_conn_list(codec, nid, len, list);
264 EXPORT_SYMBOL_GPL(snd_hda_override_conn_list);
267 * snd_hda_get_conn_index - get the connection index of the given NID
268 * @codec: the HDA codec
269 * @mux: NID containing the list
270 * @nid: NID to select
271 * @recursive: 1 when searching NID recursively, otherwise 0
273 * Parses the connection list of the widget @mux and checks whether the
274 * widget @nid is present. If it is, return the connection index.
275 * Otherwise it returns -1.
277 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
278 hda_nid_t nid, int recursive)
280 const hda_nid_t *conn;
281 int i, nums;
283 nums = snd_hda_get_conn_list(codec, mux, &conn);
284 for (i = 0; i < nums; i++)
285 if (conn[i] == nid)
286 return i;
287 if (!recursive)
288 return -1;
289 if (recursive > 10) {
290 codec_dbg(codec, "too deep connection for 0x%x\n", nid);
291 return -1;
293 recursive++;
294 for (i = 0; i < nums; i++) {
295 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i]));
296 if (type == AC_WID_PIN || type == AC_WID_AUD_OUT)
297 continue;
298 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0)
299 return i;
301 return -1;
303 EXPORT_SYMBOL_GPL(snd_hda_get_conn_index);
306 * snd_hda_get_num_devices - get DEVLIST_LEN parameter of the given widget
307 * @codec: the HDA codec
308 * @nid: NID of the pin to parse
310 * Get the device entry number on the given widget. This is a feature of
311 * DP MST audio. Each pin can have several device entries in it.
313 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid)
315 unsigned int wcaps = get_wcaps(codec, nid);
316 unsigned int parm;
318 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) ||
319 get_wcaps_type(wcaps) != AC_WID_PIN)
320 return 0;
322 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN);
323 if (parm == -1)
324 parm = 0;
325 return parm & AC_DEV_LIST_LEN_MASK;
327 EXPORT_SYMBOL_GPL(snd_hda_get_num_devices);
330 * snd_hda_get_devices - copy device list without cache
331 * @codec: the HDA codec
332 * @nid: NID of the pin to parse
333 * @dev_list: device list array
334 * @max_devices: max. number of devices to store
336 * Copy the device list. This info is dynamic and so not cached.
337 * Currently called only from hda_proc.c, so not exported.
339 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
340 u8 *dev_list, int max_devices)
342 unsigned int parm;
343 int i, dev_len, devices;
345 parm = snd_hda_get_num_devices(codec, nid);
346 if (!parm) /* not multi-stream capable */
347 return 0;
349 dev_len = parm + 1;
350 dev_len = dev_len < max_devices ? dev_len : max_devices;
352 devices = 0;
353 while (devices < dev_len) {
354 if (snd_hdac_read(&codec->core, nid,
355 AC_VERB_GET_DEVICE_LIST, devices, &parm))
356 break; /* error */
358 for (i = 0; i < 8; i++) {
359 dev_list[devices] = (u8)parm;
360 parm >>= 4;
361 devices++;
362 if (devices >= dev_len)
363 break;
366 return devices;
370 * snd_hda_get_dev_select - get device entry select on the pin
371 * @codec: the HDA codec
372 * @nid: NID of the pin to get device entry select
374 * Get the devcie entry select on the pin. Return the device entry
375 * id selected on the pin. Return 0 means the first device entry
376 * is selected or MST is not supported.
378 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid)
380 /* not support dp_mst will always return 0, using first dev_entry */
381 if (!codec->dp_mst)
382 return 0;
384 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0);
386 EXPORT_SYMBOL_GPL(snd_hda_get_dev_select);
389 * snd_hda_set_dev_select - set device entry select on the pin
390 * @codec: the HDA codec
391 * @nid: NID of the pin to set device entry select
392 * @dev_id: device entry id to be set
394 * Set the device entry select on the pin nid.
396 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
398 int ret, num_devices;
400 /* not support dp_mst will always return 0, using first dev_entry */
401 if (!codec->dp_mst)
402 return 0;
404 /* AC_PAR_DEVLIST_LEN is 0 based. */
405 num_devices = snd_hda_get_num_devices(codec, nid) + 1;
406 /* If Device List Length is 0 (num_device = 1),
407 * the pin is not multi stream capable.
408 * Do nothing in this case.
410 if (num_devices == 1)
411 return 0;
413 /* Behavior of setting index being equal to or greater than
414 * Device List Length is not predictable
416 if (num_devices <= dev_id)
417 return -EINVAL;
419 ret = snd_hda_codec_write(codec, nid, 0,
420 AC_VERB_SET_DEVICE_SEL, dev_id);
422 return ret;
424 EXPORT_SYMBOL_GPL(snd_hda_set_dev_select);
427 * read widget caps for each widget and store in cache
429 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
431 int i;
432 hda_nid_t nid;
434 codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL);
435 if (!codec->wcaps)
436 return -ENOMEM;
437 nid = codec->core.start_nid;
438 for (i = 0; i < codec->core.num_nodes; i++, nid++)
439 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core,
440 nid, AC_PAR_AUDIO_WIDGET_CAP);
441 return 0;
444 /* read all pin default configurations and save codec->init_pins */
445 static int read_pin_defaults(struct hda_codec *codec)
447 hda_nid_t nid;
449 for_each_hda_codec_node(nid, codec) {
450 struct hda_pincfg *pin;
451 unsigned int wcaps = get_wcaps(codec, nid);
452 unsigned int wid_type = get_wcaps_type(wcaps);
453 if (wid_type != AC_WID_PIN)
454 continue;
455 pin = snd_array_new(&codec->init_pins);
456 if (!pin)
457 return -ENOMEM;
458 pin->nid = nid;
459 pin->cfg = snd_hda_codec_read(codec, nid, 0,
460 AC_VERB_GET_CONFIG_DEFAULT, 0);
462 * all device entries are the same widget control so far
463 * fixme: if any codec is different, need fix here
465 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
466 AC_VERB_GET_PIN_WIDGET_CONTROL,
469 return 0;
472 /* look up the given pin config list and return the item matching with NID */
473 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
474 struct snd_array *array,
475 hda_nid_t nid)
477 struct hda_pincfg *pin;
478 int i;
480 snd_array_for_each(array, i, pin) {
481 if (pin->nid == nid)
482 return pin;
484 return NULL;
487 /* set the current pin config value for the given NID.
488 * the value is cached, and read via snd_hda_codec_get_pincfg()
490 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
491 hda_nid_t nid, unsigned int cfg)
493 struct hda_pincfg *pin;
495 /* the check below may be invalid when pins are added by a fixup
496 * dynamically (e.g. via snd_hda_codec_update_widgets()), so disabled
497 * for now
500 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
501 return -EINVAL;
504 pin = look_up_pincfg(codec, list, nid);
505 if (!pin) {
506 pin = snd_array_new(list);
507 if (!pin)
508 return -ENOMEM;
509 pin->nid = nid;
511 pin->cfg = cfg;
512 return 0;
516 * snd_hda_codec_set_pincfg - Override a pin default configuration
517 * @codec: the HDA codec
518 * @nid: NID to set the pin config
519 * @cfg: the pin default config value
521 * Override a pin default configuration value in the cache.
522 * This value can be read by snd_hda_codec_get_pincfg() in a higher
523 * priority than the real hardware value.
525 int snd_hda_codec_set_pincfg(struct hda_codec *codec,
526 hda_nid_t nid, unsigned int cfg)
528 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
530 EXPORT_SYMBOL_GPL(snd_hda_codec_set_pincfg);
533 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
534 * @codec: the HDA codec
535 * @nid: NID to get the pin config
537 * Get the current pin config value of the given pin NID.
538 * If the pincfg value is cached or overridden via sysfs or driver,
539 * returns the cached value.
541 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
543 struct hda_pincfg *pin;
545 #ifdef CONFIG_SND_HDA_RECONFIG
547 unsigned int cfg = 0;
548 mutex_lock(&codec->user_mutex);
549 pin = look_up_pincfg(codec, &codec->user_pins, nid);
550 if (pin)
551 cfg = pin->cfg;
552 mutex_unlock(&codec->user_mutex);
553 if (cfg)
554 return cfg;
556 #endif
557 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
558 if (pin)
559 return pin->cfg;
560 pin = look_up_pincfg(codec, &codec->init_pins, nid);
561 if (pin)
562 return pin->cfg;
563 return 0;
565 EXPORT_SYMBOL_GPL(snd_hda_codec_get_pincfg);
568 * snd_hda_codec_set_pin_target - remember the current pinctl target value
569 * @codec: the HDA codec
570 * @nid: pin NID
571 * @val: assigned pinctl value
573 * This function stores the given value to a pinctl target value in the
574 * pincfg table. This isn't always as same as the actually written value
575 * but can be referred at any time via snd_hda_codec_get_pin_target().
577 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
578 unsigned int val)
580 struct hda_pincfg *pin;
582 pin = look_up_pincfg(codec, &codec->init_pins, nid);
583 if (!pin)
584 return -EINVAL;
585 pin->target = val;
586 return 0;
588 EXPORT_SYMBOL_GPL(snd_hda_codec_set_pin_target);
591 * snd_hda_codec_get_pin_target - return the current pinctl target value
592 * @codec: the HDA codec
593 * @nid: pin NID
595 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid)
597 struct hda_pincfg *pin;
599 pin = look_up_pincfg(codec, &codec->init_pins, nid);
600 if (!pin)
601 return 0;
602 return pin->target;
604 EXPORT_SYMBOL_GPL(snd_hda_codec_get_pin_target);
607 * snd_hda_shutup_pins - Shut up all pins
608 * @codec: the HDA codec
610 * Clear all pin controls to shup up before suspend for avoiding click noise.
611 * The controls aren't cached so that they can be resumed properly.
613 void snd_hda_shutup_pins(struct hda_codec *codec)
615 const struct hda_pincfg *pin;
616 int i;
618 /* don't shut up pins when unloading the driver; otherwise it breaks
619 * the default pin setup at the next load of the driver
621 if (codec->bus->shutdown)
622 return;
623 snd_array_for_each(&codec->init_pins, i, pin) {
624 /* use read here for syncing after issuing each verb */
625 snd_hda_codec_read(codec, pin->nid, 0,
626 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
628 codec->pins_shutup = 1;
630 EXPORT_SYMBOL_GPL(snd_hda_shutup_pins);
632 #ifdef CONFIG_PM
633 /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */
634 static void restore_shutup_pins(struct hda_codec *codec)
636 const struct hda_pincfg *pin;
637 int i;
639 if (!codec->pins_shutup)
640 return;
641 if (codec->bus->shutdown)
642 return;
643 snd_array_for_each(&codec->init_pins, i, pin) {
644 snd_hda_codec_write(codec, pin->nid, 0,
645 AC_VERB_SET_PIN_WIDGET_CONTROL,
646 pin->ctrl);
648 codec->pins_shutup = 0;
650 #endif
652 static void hda_jackpoll_work(struct work_struct *work)
654 struct hda_codec *codec =
655 container_of(work, struct hda_codec, jackpoll_work.work);
657 snd_hda_jack_set_dirty_all(codec);
658 snd_hda_jack_poll_all(codec);
660 if (!codec->jackpoll_interval)
661 return;
663 schedule_delayed_work(&codec->jackpoll_work,
664 codec->jackpoll_interval);
667 /* release all pincfg lists */
668 static void free_init_pincfgs(struct hda_codec *codec)
670 snd_array_free(&codec->driver_pins);
671 #ifdef CONFIG_SND_HDA_RECONFIG
672 snd_array_free(&codec->user_pins);
673 #endif
674 snd_array_free(&codec->init_pins);
678 * audio-converter setup caches
680 struct hda_cvt_setup {
681 hda_nid_t nid;
682 u8 stream_tag;
683 u8 channel_id;
684 u16 format_id;
685 unsigned char active; /* cvt is currently used */
686 unsigned char dirty; /* setups should be cleared */
689 /* get or create a cache entry for the given audio converter NID */
690 static struct hda_cvt_setup *
691 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
693 struct hda_cvt_setup *p;
694 int i;
696 snd_array_for_each(&codec->cvt_setups, i, p) {
697 if (p->nid == nid)
698 return p;
700 p = snd_array_new(&codec->cvt_setups);
701 if (p)
702 p->nid = nid;
703 return p;
707 * PCM device
709 static void release_pcm(struct kref *kref)
711 struct hda_pcm *pcm = container_of(kref, struct hda_pcm, kref);
713 if (pcm->pcm)
714 snd_device_free(pcm->codec->card, pcm->pcm);
715 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
716 kfree(pcm->name);
717 kfree(pcm);
720 void snd_hda_codec_pcm_put(struct hda_pcm *pcm)
722 kref_put(&pcm->kref, release_pcm);
724 EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put);
726 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
727 const char *fmt, ...)
729 struct hda_pcm *pcm;
730 va_list args;
732 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
733 if (!pcm)
734 return NULL;
736 pcm->codec = codec;
737 kref_init(&pcm->kref);
738 va_start(args, fmt);
739 pcm->name = kvasprintf(GFP_KERNEL, fmt, args);
740 va_end(args);
741 if (!pcm->name) {
742 kfree(pcm);
743 return NULL;
746 list_add_tail(&pcm->list, &codec->pcm_list_head);
747 return pcm;
749 EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new);
752 * codec destructor
754 static void codec_release_pcms(struct hda_codec *codec)
756 struct hda_pcm *pcm, *n;
758 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
759 list_del_init(&pcm->list);
760 if (pcm->pcm)
761 snd_device_disconnect(codec->card, pcm->pcm);
762 snd_hda_codec_pcm_put(pcm);
766 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
768 if (codec->registered) {
769 /* pm_runtime_put() is called in snd_hdac_device_exit() */
770 pm_runtime_get_noresume(hda_codec_dev(codec));
771 pm_runtime_disable(hda_codec_dev(codec));
772 codec->registered = 0;
775 cancel_delayed_work_sync(&codec->jackpoll_work);
776 if (!codec->in_freeing)
777 snd_hda_ctls_clear(codec);
778 codec_release_pcms(codec);
779 snd_hda_detach_beep_device(codec);
780 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
781 snd_hda_jack_tbl_clear(codec);
782 codec->proc_widget_hook = NULL;
783 codec->spec = NULL;
785 /* free only driver_pins so that init_pins + user_pins are restored */
786 snd_array_free(&codec->driver_pins);
787 snd_array_free(&codec->cvt_setups);
788 snd_array_free(&codec->spdif_out);
789 snd_array_free(&codec->verbs);
790 codec->preset = NULL;
791 codec->slave_dig_outs = NULL;
792 codec->spdif_status_reset = 0;
793 snd_array_free(&codec->mixers);
794 snd_array_free(&codec->nids);
795 remove_conn_list(codec);
796 snd_hdac_regmap_exit(&codec->core);
799 static unsigned int hda_set_power_state(struct hda_codec *codec,
800 unsigned int power_state);
802 /* also called from hda_bind.c */
803 void snd_hda_codec_register(struct hda_codec *codec)
805 if (codec->registered)
806 return;
807 if (device_is_registered(hda_codec_dev(codec))) {
808 snd_hda_register_beep_device(codec);
809 snd_hdac_link_power(&codec->core, true);
810 pm_runtime_enable(hda_codec_dev(codec));
811 /* it was powered up in snd_hda_codec_new(), now all done */
812 snd_hda_power_down(codec);
813 codec->registered = 1;
817 static int snd_hda_codec_dev_register(struct snd_device *device)
819 snd_hda_codec_register(device->device_data);
820 return 0;
823 static int snd_hda_codec_dev_disconnect(struct snd_device *device)
825 struct hda_codec *codec = device->device_data;
827 snd_hda_detach_beep_device(codec);
828 return 0;
831 static int snd_hda_codec_dev_free(struct snd_device *device)
833 struct hda_codec *codec = device->device_data;
835 codec->in_freeing = 1;
836 snd_hdac_device_unregister(&codec->core);
837 snd_hdac_link_power(&codec->core, false);
838 put_device(hda_codec_dev(codec));
839 return 0;
842 static void snd_hda_codec_dev_release(struct device *dev)
844 struct hda_codec *codec = dev_to_hda_codec(dev);
846 free_init_pincfgs(codec);
847 snd_hdac_device_exit(&codec->core);
848 snd_hda_sysfs_clear(codec);
849 kfree(codec->modelname);
850 kfree(codec->wcaps);
851 kfree(codec);
854 #define DEV_NAME_LEN 31
856 static int snd_hda_codec_device_init(struct hda_bus *bus, struct snd_card *card,
857 unsigned int codec_addr, struct hda_codec **codecp)
859 char name[DEV_NAME_LEN];
860 struct hda_codec *codec;
861 int err;
863 dev_dbg(card->dev, "%s: entry\n", __func__);
865 if (snd_BUG_ON(!bus))
866 return -EINVAL;
867 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
868 return -EINVAL;
870 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
871 if (!codec)
872 return -ENOMEM;
874 sprintf(name, "hdaudioC%dD%d", card->number, codec_addr);
875 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr);
876 if (err < 0) {
877 kfree(codec);
878 return err;
881 codec->core.type = HDA_DEV_LEGACY;
882 *codecp = codec;
884 return err;
888 * snd_hda_codec_new - create a HDA codec
889 * @bus: the bus to assign
890 * @codec_addr: the codec address
891 * @codecp: the pointer to store the generated codec
893 * Returns 0 if successful, or a negative error code.
895 int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
896 unsigned int codec_addr, struct hda_codec **codecp)
898 int ret;
900 ret = snd_hda_codec_device_init(bus, card, codec_addr, codecp);
901 if (ret < 0)
902 return ret;
904 return snd_hda_codec_device_new(bus, card, codec_addr, *codecp);
906 EXPORT_SYMBOL_GPL(snd_hda_codec_new);
908 int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card,
909 unsigned int codec_addr, struct hda_codec *codec)
911 char component[31];
912 hda_nid_t fg;
913 int err;
914 static struct snd_device_ops dev_ops = {
915 .dev_register = snd_hda_codec_dev_register,
916 .dev_disconnect = snd_hda_codec_dev_disconnect,
917 .dev_free = snd_hda_codec_dev_free,
920 dev_dbg(card->dev, "%s: entry\n", __func__);
922 if (snd_BUG_ON(!bus))
923 return -EINVAL;
924 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
925 return -EINVAL;
927 codec->core.dev.release = snd_hda_codec_dev_release;
928 codec->core.exec_verb = codec_exec_verb;
930 codec->bus = bus;
931 codec->card = card;
932 codec->addr = codec_addr;
933 mutex_init(&codec->spdif_mutex);
934 mutex_init(&codec->control_mutex);
935 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
936 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
937 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
938 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
939 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
940 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
941 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
942 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
943 INIT_LIST_HEAD(&codec->conn_list);
944 INIT_LIST_HEAD(&codec->pcm_list_head);
946 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
947 codec->depop_delay = -1;
948 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
950 #ifdef CONFIG_PM
951 codec->power_jiffies = jiffies;
952 #endif
954 snd_hda_sysfs_init(codec);
956 if (codec->bus->modelname) {
957 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
958 if (!codec->modelname) {
959 err = -ENOMEM;
960 goto error;
964 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
965 err = read_widget_caps(codec, fg);
966 if (err < 0)
967 goto error;
968 err = read_pin_defaults(codec);
969 if (err < 0)
970 goto error;
972 /* power-up all before initialization */
973 hda_set_power_state(codec, AC_PWRST_D0);
974 codec->core.dev.power.power_state = PMSG_ON;
976 snd_hda_codec_proc_new(codec);
978 snd_hda_create_hwdep(codec);
980 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id,
981 codec->core.subsystem_id, codec->core.revision_id);
982 snd_component_add(card, component);
984 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
985 if (err < 0)
986 goto error;
988 return 0;
990 error:
991 put_device(hda_codec_dev(codec));
992 return err;
994 EXPORT_SYMBOL_GPL(snd_hda_codec_device_new);
997 * snd_hda_codec_update_widgets - Refresh widget caps and pin defaults
998 * @codec: the HDA codec
1000 * Forcibly refresh the all widget caps and the init pin configurations of
1001 * the given codec.
1003 int snd_hda_codec_update_widgets(struct hda_codec *codec)
1005 hda_nid_t fg;
1006 int err;
1008 err = snd_hdac_refresh_widgets(&codec->core, true);
1009 if (err < 0)
1010 return err;
1012 /* Assume the function group node does not change,
1013 * only the widget nodes may change.
1015 kfree(codec->wcaps);
1016 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1017 err = read_widget_caps(codec, fg);
1018 if (err < 0)
1019 return err;
1021 snd_array_free(&codec->init_pins);
1022 err = read_pin_defaults(codec);
1024 return err;
1026 EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets);
1028 /* update the stream-id if changed */
1029 static void update_pcm_stream_id(struct hda_codec *codec,
1030 struct hda_cvt_setup *p, hda_nid_t nid,
1031 u32 stream_tag, int channel_id)
1033 unsigned int oldval, newval;
1035 if (p->stream_tag != stream_tag || p->channel_id != channel_id) {
1036 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
1037 newval = (stream_tag << 4) | channel_id;
1038 if (oldval != newval)
1039 snd_hda_codec_write(codec, nid, 0,
1040 AC_VERB_SET_CHANNEL_STREAMID,
1041 newval);
1042 p->stream_tag = stream_tag;
1043 p->channel_id = channel_id;
1047 /* update the format-id if changed */
1048 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p,
1049 hda_nid_t nid, int format)
1051 unsigned int oldval;
1053 if (p->format_id != format) {
1054 oldval = snd_hda_codec_read(codec, nid, 0,
1055 AC_VERB_GET_STREAM_FORMAT, 0);
1056 if (oldval != format) {
1057 msleep(1);
1058 snd_hda_codec_write(codec, nid, 0,
1059 AC_VERB_SET_STREAM_FORMAT,
1060 format);
1062 p->format_id = format;
1067 * snd_hda_codec_setup_stream - set up the codec for streaming
1068 * @codec: the CODEC to set up
1069 * @nid: the NID to set up
1070 * @stream_tag: stream tag to pass, it's between 0x1 and 0xf.
1071 * @channel_id: channel id to pass, zero based.
1072 * @format: stream format.
1074 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1075 u32 stream_tag,
1076 int channel_id, int format)
1078 struct hda_codec *c;
1079 struct hda_cvt_setup *p;
1080 int type;
1081 int i;
1083 if (!nid)
1084 return;
1086 codec_dbg(codec,
1087 "hda_codec_setup_stream: NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1088 nid, stream_tag, channel_id, format);
1089 p = get_hda_cvt_setup(codec, nid);
1090 if (!p)
1091 return;
1093 if (codec->patch_ops.stream_pm)
1094 codec->patch_ops.stream_pm(codec, nid, true);
1095 if (codec->pcm_format_first)
1096 update_pcm_format(codec, p, nid, format);
1097 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
1098 if (!codec->pcm_format_first)
1099 update_pcm_format(codec, p, nid, format);
1101 p->active = 1;
1102 p->dirty = 0;
1104 /* make other inactive cvts with the same stream-tag dirty */
1105 type = get_wcaps_type(get_wcaps(codec, nid));
1106 list_for_each_codec(c, codec->bus) {
1107 snd_array_for_each(&c->cvt_setups, i, p) {
1108 if (!p->active && p->stream_tag == stream_tag &&
1109 get_wcaps_type(get_wcaps(c, p->nid)) == type)
1110 p->dirty = 1;
1114 EXPORT_SYMBOL_GPL(snd_hda_codec_setup_stream);
1116 static void really_cleanup_stream(struct hda_codec *codec,
1117 struct hda_cvt_setup *q);
1120 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1121 * @codec: the CODEC to clean up
1122 * @nid: the NID to clean up
1123 * @do_now: really clean up the stream instead of clearing the active flag
1125 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1126 int do_now)
1128 struct hda_cvt_setup *p;
1130 if (!nid)
1131 return;
1133 if (codec->no_sticky_stream)
1134 do_now = 1;
1136 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid);
1137 p = get_hda_cvt_setup(codec, nid);
1138 if (p) {
1139 /* here we just clear the active flag when do_now isn't set;
1140 * actual clean-ups will be done later in
1141 * purify_inactive_streams() called from snd_hda_codec_prpapre()
1143 if (do_now)
1144 really_cleanup_stream(codec, p);
1145 else
1146 p->active = 0;
1149 EXPORT_SYMBOL_GPL(__snd_hda_codec_cleanup_stream);
1151 static void really_cleanup_stream(struct hda_codec *codec,
1152 struct hda_cvt_setup *q)
1154 hda_nid_t nid = q->nid;
1155 if (q->stream_tag || q->channel_id)
1156 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1157 if (q->format_id)
1158 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
1160 memset(q, 0, sizeof(*q));
1161 q->nid = nid;
1162 if (codec->patch_ops.stream_pm)
1163 codec->patch_ops.stream_pm(codec, nid, false);
1166 /* clean up the all conflicting obsolete streams */
1167 static void purify_inactive_streams(struct hda_codec *codec)
1169 struct hda_codec *c;
1170 struct hda_cvt_setup *p;
1171 int i;
1173 list_for_each_codec(c, codec->bus) {
1174 snd_array_for_each(&c->cvt_setups, i, p) {
1175 if (p->dirty)
1176 really_cleanup_stream(c, p);
1181 #ifdef CONFIG_PM
1182 /* clean up all streams; called from suspend */
1183 static void hda_cleanup_all_streams(struct hda_codec *codec)
1185 struct hda_cvt_setup *p;
1186 int i;
1188 snd_array_for_each(&codec->cvt_setups, i, p) {
1189 if (p->stream_tag)
1190 really_cleanup_stream(codec, p);
1193 #endif
1196 * amp access functions
1200 * query_amp_caps - query AMP capabilities
1201 * @codec: the HD-auio codec
1202 * @nid: the NID to query
1203 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1205 * Query AMP capabilities for the given widget and direction.
1206 * Returns the obtained capability bits.
1208 * When cap bits have been already read, this doesn't read again but
1209 * returns the cached value.
1211 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1213 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1214 nid = codec->core.afg;
1215 return snd_hda_param_read(codec, nid,
1216 direction == HDA_OUTPUT ?
1217 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
1219 EXPORT_SYMBOL_GPL(query_amp_caps);
1222 * snd_hda_check_amp_caps - query AMP capabilities
1223 * @codec: the HD-audio codec
1224 * @nid: the NID to query
1225 * @dir: either #HDA_INPUT or #HDA_OUTPUT
1226 * @bits: bit mask to check the result
1228 * Check whether the widget has the given amp capability for the direction.
1230 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
1231 int dir, unsigned int bits)
1233 if (!nid)
1234 return false;
1235 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
1236 if (query_amp_caps(codec, nid, dir) & bits)
1237 return true;
1238 return false;
1240 EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps);
1243 * snd_hda_override_amp_caps - Override the AMP capabilities
1244 * @codec: the CODEC to clean up
1245 * @nid: the NID to clean up
1246 * @dir: either #HDA_INPUT or #HDA_OUTPUT
1247 * @caps: the capability bits to set
1249 * Override the cached AMP caps bits value by the given one.
1250 * This function is useful if the driver needs to adjust the AMP ranges,
1251 * e.g. limit to 0dB, etc.
1253 * Returns zero if successful or a negative error code.
1255 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1256 unsigned int caps)
1258 unsigned int parm;
1260 snd_hda_override_wcaps(codec, nid,
1261 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD);
1262 parm = dir == HDA_OUTPUT ? AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP;
1263 return snd_hdac_override_parm(&codec->core, nid, parm, caps);
1265 EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps);
1268 * snd_hda_codec_amp_update - update the AMP mono value
1269 * @codec: HD-audio codec
1270 * @nid: NID to read the AMP value
1271 * @ch: channel to update (0 or 1)
1272 * @dir: #HDA_INPUT or #HDA_OUTPUT
1273 * @idx: the index value (only for input direction)
1274 * @mask: bit mask to set
1275 * @val: the bits value to set
1277 * Update the AMP values for the given channel, direction and index.
1279 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
1280 int ch, int dir, int idx, int mask, int val)
1282 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
1284 /* enable fake mute if no h/w mute but min=mute */
1285 if ((query_amp_caps(codec, nid, dir) &
1286 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) == AC_AMPCAP_MIN_MUTE)
1287 cmd |= AC_AMP_FAKE_MUTE;
1288 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
1290 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
1293 * snd_hda_codec_amp_stereo - update the AMP stereo values
1294 * @codec: HD-audio codec
1295 * @nid: NID to read the AMP value
1296 * @direction: #HDA_INPUT or #HDA_OUTPUT
1297 * @idx: the index value (only for input direction)
1298 * @mask: bit mask to set
1299 * @val: the bits value to set
1301 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1302 * stereo widget with the same mask and value.
1304 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1305 int direction, int idx, int mask, int val)
1307 int ch, ret = 0;
1309 if (snd_BUG_ON(mask & ~0xff))
1310 mask &= 0xff;
1311 for (ch = 0; ch < 2; ch++)
1312 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1313 idx, mask, val);
1314 return ret;
1316 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
1319 * snd_hda_codec_amp_init - initialize the AMP value
1320 * @codec: the HDA codec
1321 * @nid: NID to read the AMP value
1322 * @ch: channel (left=0 or right=1)
1323 * @dir: #HDA_INPUT or #HDA_OUTPUT
1324 * @idx: the index value (only for input direction)
1325 * @mask: bit mask to set
1326 * @val: the bits value to set
1328 * Works like snd_hda_codec_amp_update() but it writes the value only at
1329 * the first access. If the amp was already initialized / updated beforehand,
1330 * this does nothing.
1332 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
1333 int dir, int idx, int mask, int val)
1335 int orig;
1337 if (!codec->core.regmap)
1338 return -EINVAL;
1339 regcache_cache_only(codec->core.regmap, true);
1340 orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1341 regcache_cache_only(codec->core.regmap, false);
1342 if (orig >= 0)
1343 return 0;
1344 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val);
1346 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
1349 * snd_hda_codec_amp_init_stereo - initialize the stereo AMP value
1350 * @codec: the HDA codec
1351 * @nid: NID to read the AMP value
1352 * @dir: #HDA_INPUT or #HDA_OUTPUT
1353 * @idx: the index value (only for input direction)
1354 * @mask: bit mask to set
1355 * @val: the bits value to set
1357 * Call snd_hda_codec_amp_init() for both stereo channels.
1359 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
1360 int dir, int idx, int mask, int val)
1362 int ch, ret = 0;
1364 if (snd_BUG_ON(mask & ~0xff))
1365 mask &= 0xff;
1366 for (ch = 0; ch < 2; ch++)
1367 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir,
1368 idx, mask, val);
1369 return ret;
1371 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo);
1373 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1374 unsigned int ofs)
1376 u32 caps = query_amp_caps(codec, nid, dir);
1377 /* get num steps */
1378 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1379 if (ofs < caps)
1380 caps -= ofs;
1381 return caps;
1385 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1386 * @kcontrol: referred ctl element
1387 * @uinfo: pointer to get/store the data
1389 * The control element is supposed to have the private_value field
1390 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1392 int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1393 struct snd_ctl_elem_info *uinfo)
1395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1396 u16 nid = get_amp_nid(kcontrol);
1397 u8 chs = get_amp_channels(kcontrol);
1398 int dir = get_amp_direction(kcontrol);
1399 unsigned int ofs = get_amp_offset(kcontrol);
1401 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1402 uinfo->count = chs == 3 ? 2 : 1;
1403 uinfo->value.integer.min = 0;
1404 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
1405 if (!uinfo->value.integer.max) {
1406 codec_warn(codec,
1407 "num_steps = 0 for NID=0x%x (ctl = %s)\n",
1408 nid, kcontrol->id.name);
1409 return -EINVAL;
1411 return 0;
1413 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_info);
1416 static inline unsigned int
1417 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1418 int ch, int dir, int idx, unsigned int ofs)
1420 unsigned int val;
1421 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1422 val &= HDA_AMP_VOLMASK;
1423 if (val >= ofs)
1424 val -= ofs;
1425 else
1426 val = 0;
1427 return val;
1430 static inline int
1431 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1432 int ch, int dir, int idx, unsigned int ofs,
1433 unsigned int val)
1435 unsigned int maxval;
1437 if (val > 0)
1438 val += ofs;
1439 /* ofs = 0: raw max value */
1440 maxval = get_amp_max_value(codec, nid, dir, 0);
1441 if (val > maxval)
1442 val = maxval;
1443 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1444 HDA_AMP_VOLMASK, val);
1448 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1449 * @kcontrol: ctl element
1450 * @ucontrol: pointer to get/store the data
1452 * The control element is supposed to have the private_value field
1453 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1455 int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1456 struct snd_ctl_elem_value *ucontrol)
1458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1459 hda_nid_t nid = get_amp_nid(kcontrol);
1460 int chs = get_amp_channels(kcontrol);
1461 int dir = get_amp_direction(kcontrol);
1462 int idx = get_amp_index(kcontrol);
1463 unsigned int ofs = get_amp_offset(kcontrol);
1464 long *valp = ucontrol->value.integer.value;
1466 if (chs & 1)
1467 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1468 if (chs & 2)
1469 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1470 return 0;
1472 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_get);
1475 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1476 * @kcontrol: ctl element
1477 * @ucontrol: pointer to get/store the data
1479 * The control element is supposed to have the private_value field
1480 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1482 int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1483 struct snd_ctl_elem_value *ucontrol)
1485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1486 hda_nid_t nid = get_amp_nid(kcontrol);
1487 int chs = get_amp_channels(kcontrol);
1488 int dir = get_amp_direction(kcontrol);
1489 int idx = get_amp_index(kcontrol);
1490 unsigned int ofs = get_amp_offset(kcontrol);
1491 long *valp = ucontrol->value.integer.value;
1492 int change = 0;
1494 if (chs & 1) {
1495 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1496 valp++;
1498 if (chs & 2)
1499 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1500 return change;
1502 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
1504 /* inquiry the amp caps and convert to TLV */
1505 static void get_ctl_amp_tlv(struct snd_kcontrol *kcontrol, unsigned int *tlv)
1507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1508 hda_nid_t nid = get_amp_nid(kcontrol);
1509 int dir = get_amp_direction(kcontrol);
1510 unsigned int ofs = get_amp_offset(kcontrol);
1511 bool min_mute = get_amp_min_mute(kcontrol);
1512 u32 caps, val1, val2;
1514 caps = query_amp_caps(codec, nid, dir);
1515 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1516 val2 = (val2 + 1) * 25;
1517 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1518 val1 += ofs;
1519 val1 = ((int)val1) * ((int)val2);
1520 if (min_mute || (caps & AC_AMPCAP_MIN_MUTE))
1521 val2 |= TLV_DB_SCALE_MUTE;
1522 tlv[SNDRV_CTL_TLVO_TYPE] = SNDRV_CTL_TLVT_DB_SCALE;
1523 tlv[SNDRV_CTL_TLVO_LEN] = 2 * sizeof(unsigned int);
1524 tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] = val1;
1525 tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] = val2;
1529 * snd_hda_mixer_amp_tlv - TLV callback for a standard AMP mixer volume
1530 * @kcontrol: ctl element
1531 * @op_flag: operation flag
1532 * @size: byte size of input TLV
1533 * @_tlv: TLV data
1535 * The control element is supposed to have the private_value field
1536 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1538 int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1539 unsigned int size, unsigned int __user *_tlv)
1541 unsigned int tlv[4];
1543 if (size < 4 * sizeof(unsigned int))
1544 return -ENOMEM;
1545 get_ctl_amp_tlv(kcontrol, tlv);
1546 if (copy_to_user(_tlv, tlv, sizeof(tlv)))
1547 return -EFAULT;
1548 return 0;
1550 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_tlv);
1553 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1554 * @codec: HD-audio codec
1555 * @nid: NID of a reference widget
1556 * @dir: #HDA_INPUT or #HDA_OUTPUT
1557 * @tlv: TLV data to be stored, at least 4 elements
1559 * Set (static) TLV data for a virtual master volume using the AMP caps
1560 * obtained from the reference NID.
1561 * The volume range is recalculated as if the max volume is 0dB.
1563 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1564 unsigned int *tlv)
1566 u32 caps;
1567 int nums, step;
1569 caps = query_amp_caps(codec, nid, dir);
1570 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1571 step = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1572 step = (step + 1) * 25;
1573 tlv[SNDRV_CTL_TLVO_TYPE] = SNDRV_CTL_TLVT_DB_SCALE;
1574 tlv[SNDRV_CTL_TLVO_LEN] = 2 * sizeof(unsigned int);
1575 tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] = -nums * step;
1576 tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] = step;
1578 EXPORT_SYMBOL_GPL(snd_hda_set_vmaster_tlv);
1580 /* find a mixer control element with the given name */
1581 static struct snd_kcontrol *
1582 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
1584 struct snd_ctl_elem_id id;
1585 memset(&id, 0, sizeof(id));
1586 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1587 id.device = dev;
1588 id.index = idx;
1589 if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
1590 return NULL;
1591 strcpy(id.name, name);
1592 return snd_ctl_find_id(codec->card, &id);
1596 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1597 * @codec: HD-audio codec
1598 * @name: ctl id name string
1600 * Get the control element with the given id string and IFACE_MIXER.
1602 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1603 const char *name)
1605 return find_mixer_ctl(codec, name, 0, 0);
1607 EXPORT_SYMBOL_GPL(snd_hda_find_mixer_ctl);
1609 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name,
1610 int start_idx)
1612 int i, idx;
1613 /* 16 ctlrs should be large enough */
1614 for (i = 0, idx = start_idx; i < 16; i++, idx++) {
1615 if (!find_mixer_ctl(codec, name, 0, idx))
1616 return idx;
1618 return -EBUSY;
1622 * snd_hda_ctl_add - Add a control element and assign to the codec
1623 * @codec: HD-audio codec
1624 * @nid: corresponding NID (optional)
1625 * @kctl: the control element to assign
1627 * Add the given control element to an array inside the codec instance.
1628 * All control elements belonging to a codec are supposed to be added
1629 * by this function so that a proper clean-up works at the free or
1630 * reconfiguration time.
1632 * If non-zero @nid is passed, the NID is assigned to the control element.
1633 * The assignment is shown in the codec proc file.
1635 * snd_hda_ctl_add() checks the control subdev id field whether
1636 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1637 * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit
1638 * specifies if kctl->private_value is a HDA amplifier value.
1640 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1641 struct snd_kcontrol *kctl)
1643 int err;
1644 unsigned short flags = 0;
1645 struct hda_nid_item *item;
1647 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) {
1648 flags |= HDA_NID_ITEM_AMP;
1649 if (nid == 0)
1650 nid = get_amp_nid_(kctl->private_value);
1652 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0)
1653 nid = kctl->id.subdevice & 0xffff;
1654 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
1655 kctl->id.subdevice = 0;
1656 err = snd_ctl_add(codec->card, kctl);
1657 if (err < 0)
1658 return err;
1659 item = snd_array_new(&codec->mixers);
1660 if (!item)
1661 return -ENOMEM;
1662 item->kctl = kctl;
1663 item->nid = nid;
1664 item->flags = flags;
1665 return 0;
1667 EXPORT_SYMBOL_GPL(snd_hda_ctl_add);
1670 * snd_hda_add_nid - Assign a NID to a control element
1671 * @codec: HD-audio codec
1672 * @nid: corresponding NID (optional)
1673 * @kctl: the control element to assign
1674 * @index: index to kctl
1676 * Add the given control element to an array inside the codec instance.
1677 * This function is used when #snd_hda_ctl_add cannot be used for 1:1
1678 * NID:KCTL mapping - for example "Capture Source" selector.
1680 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1681 unsigned int index, hda_nid_t nid)
1683 struct hda_nid_item *item;
1685 if (nid > 0) {
1686 item = snd_array_new(&codec->nids);
1687 if (!item)
1688 return -ENOMEM;
1689 item->kctl = kctl;
1690 item->index = index;
1691 item->nid = nid;
1692 return 0;
1694 codec_err(codec, "no NID for mapping control %s:%d:%d\n",
1695 kctl->id.name, kctl->id.index, index);
1696 return -EINVAL;
1698 EXPORT_SYMBOL_GPL(snd_hda_add_nid);
1701 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1702 * @codec: HD-audio codec
1704 void snd_hda_ctls_clear(struct hda_codec *codec)
1706 int i;
1707 struct hda_nid_item *items = codec->mixers.list;
1708 for (i = 0; i < codec->mixers.used; i++)
1709 snd_ctl_remove(codec->card, items[i].kctl);
1710 snd_array_free(&codec->mixers);
1711 snd_array_free(&codec->nids);
1715 * snd_hda_lock_devices - pseudo device locking
1716 * @bus: the BUS
1718 * toggle card->shutdown to allow/disallow the device access (as a hack)
1720 int snd_hda_lock_devices(struct hda_bus *bus)
1722 struct snd_card *card = bus->card;
1723 struct hda_codec *codec;
1725 spin_lock(&card->files_lock);
1726 if (card->shutdown)
1727 goto err_unlock;
1728 card->shutdown = 1;
1729 if (!list_empty(&card->ctl_files))
1730 goto err_clear;
1732 list_for_each_codec(codec, bus) {
1733 struct hda_pcm *cpcm;
1734 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
1735 if (!cpcm->pcm)
1736 continue;
1737 if (cpcm->pcm->streams[0].substream_opened ||
1738 cpcm->pcm->streams[1].substream_opened)
1739 goto err_clear;
1742 spin_unlock(&card->files_lock);
1743 return 0;
1745 err_clear:
1746 card->shutdown = 0;
1747 err_unlock:
1748 spin_unlock(&card->files_lock);
1749 return -EINVAL;
1751 EXPORT_SYMBOL_GPL(snd_hda_lock_devices);
1754 * snd_hda_unlock_devices - pseudo device unlocking
1755 * @bus: the BUS
1757 void snd_hda_unlock_devices(struct hda_bus *bus)
1759 struct snd_card *card = bus->card;
1761 spin_lock(&card->files_lock);
1762 card->shutdown = 0;
1763 spin_unlock(&card->files_lock);
1765 EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
1768 * snd_hda_codec_reset - Clear all objects assigned to the codec
1769 * @codec: HD-audio codec
1771 * This frees the all PCM and control elements assigned to the codec, and
1772 * clears the caches and restores the pin default configurations.
1774 * When a device is being used, it returns -EBSY. If successfully freed,
1775 * returns zero.
1777 int snd_hda_codec_reset(struct hda_codec *codec)
1779 struct hda_bus *bus = codec->bus;
1781 if (snd_hda_lock_devices(bus) < 0)
1782 return -EBUSY;
1784 /* OK, let it free */
1785 snd_hdac_device_unregister(&codec->core);
1787 /* allow device access again */
1788 snd_hda_unlock_devices(bus);
1789 return 0;
1792 typedef int (*map_slave_func_t)(struct hda_codec *, void *, struct snd_kcontrol *);
1794 /* apply the function to all matching slave ctls in the mixer list */
1795 static int map_slaves(struct hda_codec *codec, const char * const *slaves,
1796 const char *suffix, map_slave_func_t func, void *data)
1798 struct hda_nid_item *items;
1799 const char * const *s;
1800 int i, err;
1802 items = codec->mixers.list;
1803 for (i = 0; i < codec->mixers.used; i++) {
1804 struct snd_kcontrol *sctl = items[i].kctl;
1805 if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
1806 continue;
1807 for (s = slaves; *s; s++) {
1808 char tmpname[sizeof(sctl->id.name)];
1809 const char *name = *s;
1810 if (suffix) {
1811 snprintf(tmpname, sizeof(tmpname), "%s %s",
1812 name, suffix);
1813 name = tmpname;
1815 if (!strcmp(sctl->id.name, name)) {
1816 err = func(codec, data, sctl);
1817 if (err)
1818 return err;
1819 break;
1823 return 0;
1826 static int check_slave_present(struct hda_codec *codec,
1827 void *data, struct snd_kcontrol *sctl)
1829 return 1;
1832 /* call kctl->put with the given value(s) */
1833 static int put_kctl_with_value(struct snd_kcontrol *kctl, int val)
1835 struct snd_ctl_elem_value *ucontrol;
1836 ucontrol = kzalloc(sizeof(*ucontrol), GFP_KERNEL);
1837 if (!ucontrol)
1838 return -ENOMEM;
1839 ucontrol->value.integer.value[0] = val;
1840 ucontrol->value.integer.value[1] = val;
1841 kctl->put(kctl, ucontrol);
1842 kfree(ucontrol);
1843 return 0;
1846 struct slave_init_arg {
1847 struct hda_codec *codec;
1848 int step;
1851 /* initialize the slave volume with 0dB via snd_ctl_apply_vmaster_slaves() */
1852 static int init_slave_0dB(struct snd_kcontrol *slave,
1853 struct snd_kcontrol *kctl,
1854 void *_arg)
1856 struct slave_init_arg *arg = _arg;
1857 int _tlv[4];
1858 const int *tlv = NULL;
1859 int step;
1860 int val;
1862 if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
1863 if (kctl->tlv.c != snd_hda_mixer_amp_tlv) {
1864 codec_err(arg->codec,
1865 "Unexpected TLV callback for slave %s:%d\n",
1866 kctl->id.name, kctl->id.index);
1867 return 0; /* ignore */
1869 get_ctl_amp_tlv(kctl, _tlv);
1870 tlv = _tlv;
1871 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
1872 tlv = kctl->tlv.p;
1874 if (!tlv || tlv[SNDRV_CTL_TLVO_TYPE] != SNDRV_CTL_TLVT_DB_SCALE)
1875 return 0;
1877 step = tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP];
1878 step &= ~TLV_DB_SCALE_MUTE;
1879 if (!step)
1880 return 0;
1881 if (arg->step && arg->step != step) {
1882 codec_err(arg->codec,
1883 "Mismatching dB step for vmaster slave (%d!=%d)\n",
1884 arg->step, step);
1885 return 0;
1888 arg->step = step;
1889 val = -tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] / step;
1890 if (val > 0) {
1891 put_kctl_with_value(slave, val);
1892 return val;
1895 return 0;
1898 /* unmute the slave via snd_ctl_apply_vmaster_slaves() */
1899 static int init_slave_unmute(struct snd_kcontrol *slave,
1900 struct snd_kcontrol *kctl,
1901 void *_arg)
1903 return put_kctl_with_value(slave, 1);
1906 static int add_slave(struct hda_codec *codec,
1907 void *data, struct snd_kcontrol *slave)
1909 return snd_ctl_add_slave(data, slave);
1913 * __snd_hda_add_vmaster - create a virtual master control and add slaves
1914 * @codec: HD-audio codec
1915 * @name: vmaster control name
1916 * @tlv: TLV data (optional)
1917 * @slaves: slave control names (optional)
1918 * @suffix: suffix string to each slave name (optional)
1919 * @init_slave_vol: initialize slaves to unmute/0dB
1920 * @ctl_ret: store the vmaster kcontrol in return
1922 * Create a virtual master control with the given name. The TLV data
1923 * must be either NULL or a valid data.
1925 * @slaves is a NULL-terminated array of strings, each of which is a
1926 * slave control name. All controls with these names are assigned to
1927 * the new virtual master control.
1929 * This function returns zero if successful or a negative error code.
1931 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1932 unsigned int *tlv, const char * const *slaves,
1933 const char *suffix, bool init_slave_vol,
1934 struct snd_kcontrol **ctl_ret)
1936 struct snd_kcontrol *kctl;
1937 int err;
1939 if (ctl_ret)
1940 *ctl_ret = NULL;
1942 err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
1943 if (err != 1) {
1944 codec_dbg(codec, "No slave found for %s\n", name);
1945 return 0;
1947 kctl = snd_ctl_make_virtual_master(name, tlv);
1948 if (!kctl)
1949 return -ENOMEM;
1950 err = snd_hda_ctl_add(codec, 0, kctl);
1951 if (err < 0)
1952 return err;
1954 err = map_slaves(codec, slaves, suffix, add_slave, kctl);
1955 if (err < 0)
1956 return err;
1958 /* init with master mute & zero volume */
1959 put_kctl_with_value(kctl, 0);
1960 if (init_slave_vol) {
1961 struct slave_init_arg arg = {
1962 .codec = codec,
1963 .step = 0,
1965 snd_ctl_apply_vmaster_slaves(kctl,
1966 tlv ? init_slave_0dB : init_slave_unmute,
1967 &arg);
1970 if (ctl_ret)
1971 *ctl_ret = kctl;
1972 return 0;
1974 EXPORT_SYMBOL_GPL(__snd_hda_add_vmaster);
1977 * mute-LED control using vmaster
1979 static int vmaster_mute_mode_info(struct snd_kcontrol *kcontrol,
1980 struct snd_ctl_elem_info *uinfo)
1982 static const char * const texts[] = {
1983 "On", "Off", "Follow Master"
1986 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1989 static int vmaster_mute_mode_get(struct snd_kcontrol *kcontrol,
1990 struct snd_ctl_elem_value *ucontrol)
1992 struct hda_vmaster_mute_hook *hook = snd_kcontrol_chip(kcontrol);
1993 ucontrol->value.enumerated.item[0] = hook->mute_mode;
1994 return 0;
1997 static int vmaster_mute_mode_put(struct snd_kcontrol *kcontrol,
1998 struct snd_ctl_elem_value *ucontrol)
2000 struct hda_vmaster_mute_hook *hook = snd_kcontrol_chip(kcontrol);
2001 unsigned int old_mode = hook->mute_mode;
2003 hook->mute_mode = ucontrol->value.enumerated.item[0];
2004 if (hook->mute_mode > HDA_VMUTE_FOLLOW_MASTER)
2005 hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER;
2006 if (old_mode == hook->mute_mode)
2007 return 0;
2008 snd_hda_sync_vmaster_hook(hook);
2009 return 1;
2012 static const struct snd_kcontrol_new vmaster_mute_mode = {
2013 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2014 .name = "Mute-LED Mode",
2015 .info = vmaster_mute_mode_info,
2016 .get = vmaster_mute_mode_get,
2017 .put = vmaster_mute_mode_put,
2020 /* meta hook to call each driver's vmaster hook */
2021 static void vmaster_hook(void *private_data, int enabled)
2023 struct hda_vmaster_mute_hook *hook = private_data;
2025 if (hook->mute_mode != HDA_VMUTE_FOLLOW_MASTER)
2026 enabled = hook->mute_mode;
2027 hook->hook(hook->codec, enabled);
2031 * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED
2032 * @codec: the HDA codec
2033 * @hook: the vmaster hook object
2034 * @expose_enum_ctl: flag to create an enum ctl
2036 * Add a mute-LED hook with the given vmaster switch kctl.
2037 * When @expose_enum_ctl is set, "Mute-LED Mode" control is automatically
2038 * created and associated with the given hook.
2040 int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2041 struct hda_vmaster_mute_hook *hook,
2042 bool expose_enum_ctl)
2044 struct snd_kcontrol *kctl;
2046 if (!hook->hook || !hook->sw_kctl)
2047 return 0;
2048 hook->codec = codec;
2049 hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER;
2050 snd_ctl_add_vmaster_hook(hook->sw_kctl, vmaster_hook, hook);
2051 if (!expose_enum_ctl)
2052 return 0;
2053 kctl = snd_ctl_new1(&vmaster_mute_mode, hook);
2054 if (!kctl)
2055 return -ENOMEM;
2056 return snd_hda_ctl_add(codec, 0, kctl);
2058 EXPORT_SYMBOL_GPL(snd_hda_add_vmaster_hook);
2061 * snd_hda_sync_vmaster_hook - Sync vmaster hook
2062 * @hook: the vmaster hook
2064 * Call the hook with the current value for synchronization.
2065 * Should be called in init callback.
2067 void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook)
2069 if (!hook->hook || !hook->codec)
2070 return;
2071 /* don't call vmaster hook in the destructor since it might have
2072 * been already destroyed
2074 if (hook->codec->bus->shutdown)
2075 return;
2076 snd_ctl_sync_vmaster_hook(hook->sw_kctl);
2078 EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook);
2082 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
2083 * @kcontrol: referred ctl element
2084 * @uinfo: pointer to get/store the data
2086 * The control element is supposed to have the private_value field
2087 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2089 int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
2090 struct snd_ctl_elem_info *uinfo)
2092 int chs = get_amp_channels(kcontrol);
2094 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2095 uinfo->count = chs == 3 ? 2 : 1;
2096 uinfo->value.integer.min = 0;
2097 uinfo->value.integer.max = 1;
2098 return 0;
2100 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_info);
2103 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2104 * @kcontrol: ctl element
2105 * @ucontrol: pointer to get/store the data
2107 * The control element is supposed to have the private_value field
2108 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2110 int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
2111 struct snd_ctl_elem_value *ucontrol)
2113 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2114 hda_nid_t nid = get_amp_nid(kcontrol);
2115 int chs = get_amp_channels(kcontrol);
2116 int dir = get_amp_direction(kcontrol);
2117 int idx = get_amp_index(kcontrol);
2118 long *valp = ucontrol->value.integer.value;
2120 if (chs & 1)
2121 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2122 HDA_AMP_MUTE) ? 0 : 1;
2123 if (chs & 2)
2124 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2125 HDA_AMP_MUTE) ? 0 : 1;
2126 return 0;
2128 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get);
2131 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2132 * @kcontrol: ctl element
2133 * @ucontrol: pointer to get/store the data
2135 * The control element is supposed to have the private_value field
2136 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2138 int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
2139 struct snd_ctl_elem_value *ucontrol)
2141 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2142 hda_nid_t nid = get_amp_nid(kcontrol);
2143 int chs = get_amp_channels(kcontrol);
2144 int dir = get_amp_direction(kcontrol);
2145 int idx = get_amp_index(kcontrol);
2146 long *valp = ucontrol->value.integer.value;
2147 int change = 0;
2149 if (chs & 1) {
2150 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2151 HDA_AMP_MUTE,
2152 *valp ? 0 : HDA_AMP_MUTE);
2153 valp++;
2155 if (chs & 2)
2156 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2157 HDA_AMP_MUTE,
2158 *valp ? 0 : HDA_AMP_MUTE);
2159 hda_call_check_power_status(codec, nid);
2160 return change;
2162 EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);
2165 * SPDIF out controls
2168 static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
2169 struct snd_ctl_elem_info *uinfo)
2171 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2172 uinfo->count = 1;
2173 return 0;
2176 static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
2177 struct snd_ctl_elem_value *ucontrol)
2179 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2180 IEC958_AES0_NONAUDIO |
2181 IEC958_AES0_CON_EMPHASIS_5015 |
2182 IEC958_AES0_CON_NOT_COPYRIGHT;
2183 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
2184 IEC958_AES1_CON_ORIGINAL;
2185 return 0;
2188 static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
2189 struct snd_ctl_elem_value *ucontrol)
2191 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
2192 IEC958_AES0_NONAUDIO |
2193 IEC958_AES0_PRO_EMPHASIS_5015;
2194 return 0;
2197 static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
2198 struct snd_ctl_elem_value *ucontrol)
2200 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2201 int idx = kcontrol->private_value;
2202 struct hda_spdif_out *spdif;
2204 if (WARN_ON(codec->spdif_out.used <= idx))
2205 return -EINVAL;
2206 mutex_lock(&codec->spdif_mutex);
2207 spdif = snd_array_elem(&codec->spdif_out, idx);
2208 ucontrol->value.iec958.status[0] = spdif->status & 0xff;
2209 ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff;
2210 ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff;
2211 ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff;
2212 mutex_unlock(&codec->spdif_mutex);
2214 return 0;
2217 /* convert from SPDIF status bits to HDA SPDIF bits
2218 * bit 0 (DigEn) is always set zero (to be filled later)
2220 static unsigned short convert_from_spdif_status(unsigned int sbits)
2222 unsigned short val = 0;
2224 if (sbits & IEC958_AES0_PROFESSIONAL)
2225 val |= AC_DIG1_PROFESSIONAL;
2226 if (sbits & IEC958_AES0_NONAUDIO)
2227 val |= AC_DIG1_NONAUDIO;
2228 if (sbits & IEC958_AES0_PROFESSIONAL) {
2229 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
2230 IEC958_AES0_PRO_EMPHASIS_5015)
2231 val |= AC_DIG1_EMPHASIS;
2232 } else {
2233 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
2234 IEC958_AES0_CON_EMPHASIS_5015)
2235 val |= AC_DIG1_EMPHASIS;
2236 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
2237 val |= AC_DIG1_COPYRIGHT;
2238 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
2239 val |= AC_DIG1_LEVEL;
2240 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
2242 return val;
2245 /* convert to SPDIF status bits from HDA SPDIF bits
2247 static unsigned int convert_to_spdif_status(unsigned short val)
2249 unsigned int sbits = 0;
2251 if (val & AC_DIG1_NONAUDIO)
2252 sbits |= IEC958_AES0_NONAUDIO;
2253 if (val & AC_DIG1_PROFESSIONAL)
2254 sbits |= IEC958_AES0_PROFESSIONAL;
2255 if (sbits & IEC958_AES0_PROFESSIONAL) {
2256 if (val & AC_DIG1_EMPHASIS)
2257 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
2258 } else {
2259 if (val & AC_DIG1_EMPHASIS)
2260 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
2261 if (!(val & AC_DIG1_COPYRIGHT))
2262 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
2263 if (val & AC_DIG1_LEVEL)
2264 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
2265 sbits |= val & (0x7f << 8);
2267 return sbits;
2270 /* set digital convert verbs both for the given NID and its slaves */
2271 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2272 int mask, int val)
2274 const hda_nid_t *d;
2276 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
2277 mask, val);
2278 d = codec->slave_dig_outs;
2279 if (!d)
2280 return;
2281 for (; *d; d++)
2282 snd_hdac_regmap_update(&codec->core, *d,
2283 AC_VERB_SET_DIGI_CONVERT_1, mask, val);
2286 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2287 int dig1, int dig2)
2289 unsigned int mask = 0;
2290 unsigned int val = 0;
2292 if (dig1 != -1) {
2293 mask |= 0xff;
2294 val = dig1;
2296 if (dig2 != -1) {
2297 mask |= 0xff00;
2298 val |= dig2 << 8;
2300 set_dig_out(codec, nid, mask, val);
2303 static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2304 struct snd_ctl_elem_value *ucontrol)
2306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2307 int idx = kcontrol->private_value;
2308 struct hda_spdif_out *spdif;
2309 hda_nid_t nid;
2310 unsigned short val;
2311 int change;
2313 if (WARN_ON(codec->spdif_out.used <= idx))
2314 return -EINVAL;
2315 mutex_lock(&codec->spdif_mutex);
2316 spdif = snd_array_elem(&codec->spdif_out, idx);
2317 nid = spdif->nid;
2318 spdif->status = ucontrol->value.iec958.status[0] |
2319 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
2320 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
2321 ((unsigned int)ucontrol->value.iec958.status[3] << 24);
2322 val = convert_from_spdif_status(spdif->status);
2323 val |= spdif->ctls & 1;
2324 change = spdif->ctls != val;
2325 spdif->ctls = val;
2326 if (change && nid != (u16)-1)
2327 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2328 mutex_unlock(&codec->spdif_mutex);
2329 return change;
2332 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
2334 static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
2335 struct snd_ctl_elem_value *ucontrol)
2337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2338 int idx = kcontrol->private_value;
2339 struct hda_spdif_out *spdif;
2341 if (WARN_ON(codec->spdif_out.used <= idx))
2342 return -EINVAL;
2343 mutex_lock(&codec->spdif_mutex);
2344 spdif = snd_array_elem(&codec->spdif_out, idx);
2345 ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE;
2346 mutex_unlock(&codec->spdif_mutex);
2347 return 0;
2350 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid,
2351 int dig1, int dig2)
2353 set_dig_out_convert(codec, nid, dig1, dig2);
2354 /* unmute amp switch (if any) */
2355 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2356 (dig1 & AC_DIG1_ENABLE))
2357 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2358 HDA_AMP_MUTE, 0);
2361 static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
2362 struct snd_ctl_elem_value *ucontrol)
2364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2365 int idx = kcontrol->private_value;
2366 struct hda_spdif_out *spdif;
2367 hda_nid_t nid;
2368 unsigned short val;
2369 int change;
2371 if (WARN_ON(codec->spdif_out.used <= idx))
2372 return -EINVAL;
2373 mutex_lock(&codec->spdif_mutex);
2374 spdif = snd_array_elem(&codec->spdif_out, idx);
2375 nid = spdif->nid;
2376 val = spdif->ctls & ~AC_DIG1_ENABLE;
2377 if (ucontrol->value.integer.value[0])
2378 val |= AC_DIG1_ENABLE;
2379 change = spdif->ctls != val;
2380 spdif->ctls = val;
2381 if (change && nid != (u16)-1)
2382 set_spdif_ctls(codec, nid, val & 0xff, -1);
2383 mutex_unlock(&codec->spdif_mutex);
2384 return change;
2387 static struct snd_kcontrol_new dig_mixes[] = {
2389 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2390 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2391 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
2392 .info = snd_hda_spdif_mask_info,
2393 .get = snd_hda_spdif_cmask_get,
2396 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2398 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
2399 .info = snd_hda_spdif_mask_info,
2400 .get = snd_hda_spdif_pmask_get,
2403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2404 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2405 .info = snd_hda_spdif_mask_info,
2406 .get = snd_hda_spdif_default_get,
2407 .put = snd_hda_spdif_default_put,
2410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2411 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2412 .info = snd_hda_spdif_out_switch_info,
2413 .get = snd_hda_spdif_out_switch_get,
2414 .put = snd_hda_spdif_out_switch_put,
2416 { } /* end */
2420 * snd_hda_create_dig_out_ctls - create Output SPDIF-related controls
2421 * @codec: the HDA codec
2422 * @associated_nid: NID that new ctls associated with
2423 * @cvt_nid: converter NID
2424 * @type: HDA_PCM_TYPE_*
2425 * Creates controls related with the digital output.
2426 * Called from each patch supporting the digital out.
2428 * Returns 0 if successful, or a negative error code.
2430 int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
2431 hda_nid_t associated_nid,
2432 hda_nid_t cvt_nid,
2433 int type)
2435 int err;
2436 struct snd_kcontrol *kctl;
2437 struct snd_kcontrol_new *dig_mix;
2438 int idx = 0;
2439 int val = 0;
2440 const int spdif_index = 16;
2441 struct hda_spdif_out *spdif;
2442 struct hda_bus *bus = codec->bus;
2444 if (bus->primary_dig_out_type == HDA_PCM_TYPE_HDMI &&
2445 type == HDA_PCM_TYPE_SPDIF) {
2446 idx = spdif_index;
2447 } else if (bus->primary_dig_out_type == HDA_PCM_TYPE_SPDIF &&
2448 type == HDA_PCM_TYPE_HDMI) {
2449 /* suppose a single SPDIF device */
2450 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
2451 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
2452 if (!kctl)
2453 break;
2454 kctl->id.index = spdif_index;
2456 bus->primary_dig_out_type = HDA_PCM_TYPE_HDMI;
2458 if (!bus->primary_dig_out_type)
2459 bus->primary_dig_out_type = type;
2461 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
2462 if (idx < 0) {
2463 codec_err(codec, "too many IEC958 outputs\n");
2464 return -EBUSY;
2466 spdif = snd_array_new(&codec->spdif_out);
2467 if (!spdif)
2468 return -ENOMEM;
2469 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
2470 kctl = snd_ctl_new1(dig_mix, codec);
2471 if (!kctl)
2472 return -ENOMEM;
2473 kctl->id.index = idx;
2474 kctl->private_value = codec->spdif_out.used - 1;
2475 err = snd_hda_ctl_add(codec, associated_nid, kctl);
2476 if (err < 0)
2477 return err;
2479 spdif->nid = cvt_nid;
2480 snd_hdac_regmap_read(&codec->core, cvt_nid,
2481 AC_VERB_GET_DIGI_CONVERT_1, &val);
2482 spdif->ctls = val;
2483 spdif->status = convert_to_spdif_status(spdif->ctls);
2484 return 0;
2486 EXPORT_SYMBOL_GPL(snd_hda_create_dig_out_ctls);
2489 * snd_hda_spdif_out_of_nid - get the hda_spdif_out entry from the given NID
2490 * @codec: the HDA codec
2491 * @nid: widget NID
2493 * call within spdif_mutex lock
2495 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
2496 hda_nid_t nid)
2498 struct hda_spdif_out *spdif;
2499 int i;
2501 snd_array_for_each(&codec->spdif_out, i, spdif) {
2502 if (spdif->nid == nid)
2503 return spdif;
2505 return NULL;
2507 EXPORT_SYMBOL_GPL(snd_hda_spdif_out_of_nid);
2510 * snd_hda_spdif_ctls_unassign - Unassign the given SPDIF ctl
2511 * @codec: the HDA codec
2512 * @idx: the SPDIF ctl index
2514 * Unassign the widget from the given SPDIF control.
2516 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
2518 struct hda_spdif_out *spdif;
2520 if (WARN_ON(codec->spdif_out.used <= idx))
2521 return;
2522 mutex_lock(&codec->spdif_mutex);
2523 spdif = snd_array_elem(&codec->spdif_out, idx);
2524 spdif->nid = (u16)-1;
2525 mutex_unlock(&codec->spdif_mutex);
2527 EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_unassign);
2530 * snd_hda_spdif_ctls_assign - Assign the SPDIF controls to the given NID
2531 * @codec: the HDA codec
2532 * @idx: the SPDIF ctl idx
2533 * @nid: widget NID
2535 * Assign the widget to the SPDIF control with the given index.
2537 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
2539 struct hda_spdif_out *spdif;
2540 unsigned short val;
2542 if (WARN_ON(codec->spdif_out.used <= idx))
2543 return;
2544 mutex_lock(&codec->spdif_mutex);
2545 spdif = snd_array_elem(&codec->spdif_out, idx);
2546 if (spdif->nid != nid) {
2547 spdif->nid = nid;
2548 val = spdif->ctls;
2549 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff);
2551 mutex_unlock(&codec->spdif_mutex);
2553 EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_assign);
2556 * SPDIF sharing with analog output
2558 static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
2559 struct snd_ctl_elem_value *ucontrol)
2561 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2562 ucontrol->value.integer.value[0] = mout->share_spdif;
2563 return 0;
2566 static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_value *ucontrol)
2569 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
2570 mout->share_spdif = !!ucontrol->value.integer.value[0];
2571 return 0;
2574 static const struct snd_kcontrol_new spdif_share_sw = {
2575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2576 .name = "IEC958 Default PCM Playback Switch",
2577 .info = snd_ctl_boolean_mono_info,
2578 .get = spdif_share_sw_get,
2579 .put = spdif_share_sw_put,
2583 * snd_hda_create_spdif_share_sw - create Default PCM switch
2584 * @codec: the HDA codec
2585 * @mout: multi-out instance
2587 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2588 struct hda_multi_out *mout)
2590 struct snd_kcontrol *kctl;
2592 if (!mout->dig_out_nid)
2593 return 0;
2595 kctl = snd_ctl_new1(&spdif_share_sw, mout);
2596 if (!kctl)
2597 return -ENOMEM;
2598 /* ATTENTION: here mout is passed as private_data, instead of codec */
2599 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl);
2601 EXPORT_SYMBOL_GPL(snd_hda_create_spdif_share_sw);
2604 * SPDIF input
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;
2615 return 0;
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];
2624 int change;
2626 mutex_lock(&codec->spdif_mutex);
2627 change = codec->spdif_in_enable != val;
2628 if (change) {
2629 codec->spdif_in_enable = val;
2630 snd_hdac_regmap_write(&codec->core, nid,
2631 AC_VERB_SET_DIGI_CONVERT_1, val);
2633 mutex_unlock(&codec->spdif_mutex);
2634 return change;
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;
2642 unsigned int val;
2643 unsigned int sbits;
2645 snd_hdac_regmap_read(&codec->core, nid,
2646 AC_VERB_GET_DIGI_CONVERT_1, &val);
2647 sbits = convert_to_spdif_status(val);
2648 ucontrol->value.iec958.status[0] = sbits;
2649 ucontrol->value.iec958.status[1] = sbits >> 8;
2650 ucontrol->value.iec958.status[2] = sbits >> 16;
2651 ucontrol->value.iec958.status[3] = sbits >> 24;
2652 return 0;
2655 static struct snd_kcontrol_new dig_in_ctls[] = {
2657 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2658 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
2659 .info = snd_hda_spdif_in_switch_info,
2660 .get = snd_hda_spdif_in_switch_get,
2661 .put = snd_hda_spdif_in_switch_put,
2664 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
2667 .info = snd_hda_spdif_mask_info,
2668 .get = snd_hda_spdif_in_status_get,
2670 { } /* end */
2674 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
2675 * @codec: the HDA codec
2676 * @nid: audio in widget NID
2678 * Creates controls related with the SPDIF input.
2679 * Called from each patch supporting the SPDIF in.
2681 * Returns 0 if successful, or a negative error code.
2683 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2685 int err;
2686 struct snd_kcontrol *kctl;
2687 struct snd_kcontrol_new *dig_mix;
2688 int idx;
2690 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
2691 if (idx < 0) {
2692 codec_err(codec, "too many IEC958 inputs\n");
2693 return -EBUSY;
2695 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
2696 kctl = snd_ctl_new1(dig_mix, codec);
2697 if (!kctl)
2698 return -ENOMEM;
2699 kctl->private_value = nid;
2700 err = snd_hda_ctl_add(codec, nid, kctl);
2701 if (err < 0)
2702 return err;
2704 codec->spdif_in_enable =
2705 snd_hda_codec_read(codec, nid, 0,
2706 AC_VERB_GET_DIGI_CONVERT_1, 0) &
2707 AC_DIG1_ENABLE;
2708 return 0;
2710 EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls);
2713 * snd_hda_codec_set_power_to_all - Set the power state to all widgets
2714 * @codec: the HDA codec
2715 * @fg: function group (not used now)
2716 * @power_state: the power state to set (AC_PWRST_*)
2718 * Set the given power state to all widgets that have the power control.
2719 * If the codec has power_filter set, it evaluates the power state and
2720 * filter out if it's unchanged as D3.
2722 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
2723 unsigned int power_state)
2725 hda_nid_t nid;
2727 for_each_hda_codec_node(nid, codec) {
2728 unsigned int wcaps = get_wcaps(codec, nid);
2729 unsigned int state = power_state;
2730 if (!(wcaps & AC_WCAP_POWER))
2731 continue;
2732 if (codec->power_filter) {
2733 state = codec->power_filter(codec, nid, power_state);
2734 if (state != power_state && power_state == AC_PWRST_D3)
2735 continue;
2737 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
2738 state);
2741 EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all);
2744 * snd_hda_codec_eapd_power_filter - A power filter callback for EAPD
2745 * @codec: the HDA codec
2746 * @nid: widget NID
2747 * @power_state: power state to evalue
2749 * Don't power down the widget if it controls eapd and EAPD_BTLENABLE is set.
2750 * This can be used a codec power_filter callback.
2752 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
2753 hda_nid_t nid,
2754 unsigned int power_state)
2756 if (nid == codec->core.afg || nid == codec->core.mfg)
2757 return power_state;
2758 if (power_state == AC_PWRST_D3 &&
2759 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
2760 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
2761 int eapd = snd_hda_codec_read(codec, nid, 0,
2762 AC_VERB_GET_EAPD_BTLENABLE, 0);
2763 if (eapd & 0x02)
2764 return AC_PWRST_D0;
2766 return power_state;
2768 EXPORT_SYMBOL_GPL(snd_hda_codec_eapd_power_filter);
2771 * set power state of the codec, and return the power state
2773 static unsigned int hda_set_power_state(struct hda_codec *codec,
2774 unsigned int power_state)
2776 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
2777 int count;
2778 unsigned int state;
2779 int flags = 0;
2781 /* this delay seems necessary to avoid click noise at power-down */
2782 if (power_state == AC_PWRST_D3) {
2783 if (codec->depop_delay < 0)
2784 msleep(codec_has_epss(codec) ? 10 : 100);
2785 else if (codec->depop_delay > 0)
2786 msleep(codec->depop_delay);
2787 flags = HDA_RW_NO_RESPONSE_FALLBACK;
2790 /* repeat power states setting at most 10 times*/
2791 for (count = 0; count < 10; count++) {
2792 if (codec->patch_ops.set_power_state)
2793 codec->patch_ops.set_power_state(codec, fg,
2794 power_state);
2795 else {
2796 state = power_state;
2797 if (codec->power_filter)
2798 state = codec->power_filter(codec, fg, state);
2799 if (state == power_state || power_state != AC_PWRST_D3)
2800 snd_hda_codec_read(codec, fg, flags,
2801 AC_VERB_SET_POWER_STATE,
2802 state);
2803 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2805 state = snd_hda_sync_power_state(codec, fg, power_state);
2806 if (!(state & AC_PWRST_ERROR))
2807 break;
2810 return state;
2813 /* sync power states of all widgets;
2814 * this is called at the end of codec parsing
2816 static void sync_power_up_states(struct hda_codec *codec)
2818 hda_nid_t nid;
2820 /* don't care if no filter is used */
2821 if (!codec->power_filter)
2822 return;
2824 for_each_hda_codec_node(nid, codec) {
2825 unsigned int wcaps = get_wcaps(codec, nid);
2826 unsigned int target;
2827 if (!(wcaps & AC_WCAP_POWER))
2828 continue;
2829 target = codec->power_filter(codec, nid, AC_PWRST_D0);
2830 if (target == AC_PWRST_D0)
2831 continue;
2832 if (!snd_hda_check_power_state(codec, nid, target))
2833 snd_hda_codec_write(codec, nid, 0,
2834 AC_VERB_SET_POWER_STATE, target);
2838 #ifdef CONFIG_SND_HDA_RECONFIG
2839 /* execute additional init verbs */
2840 static void hda_exec_init_verbs(struct hda_codec *codec)
2842 if (codec->init_verbs.list)
2843 snd_hda_sequence_write(codec, codec->init_verbs.list);
2845 #else
2846 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2847 #endif
2849 #ifdef CONFIG_PM
2850 /* update the power on/off account with the current jiffies */
2851 static void update_power_acct(struct hda_codec *codec, bool on)
2853 unsigned long delta = jiffies - codec->power_jiffies;
2855 if (on)
2856 codec->power_on_acct += delta;
2857 else
2858 codec->power_off_acct += delta;
2859 codec->power_jiffies += delta;
2862 void snd_hda_update_power_acct(struct hda_codec *codec)
2864 update_power_acct(codec, hda_codec_is_power_on(codec));
2868 * call suspend and power-down; used both from PM and power-save
2869 * this function returns the power state in the end
2871 static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
2873 unsigned int state;
2875 snd_hdac_enter_pm(&codec->core);
2876 if (codec->patch_ops.suspend)
2877 codec->patch_ops.suspend(codec);
2878 hda_cleanup_all_streams(codec);
2879 state = hda_set_power_state(codec, AC_PWRST_D3);
2880 update_power_acct(codec, true);
2881 snd_hdac_leave_pm(&codec->core);
2882 return state;
2886 * kick up codec; used both from PM and power-save
2888 static void hda_call_codec_resume(struct hda_codec *codec)
2890 snd_hdac_enter_pm(&codec->core);
2891 if (codec->core.regmap)
2892 regcache_mark_dirty(codec->core.regmap);
2894 codec->power_jiffies = jiffies;
2896 hda_set_power_state(codec, AC_PWRST_D0);
2897 restore_shutup_pins(codec);
2898 hda_exec_init_verbs(codec);
2899 snd_hda_jack_set_dirty_all(codec);
2900 if (codec->patch_ops.resume)
2901 codec->patch_ops.resume(codec);
2902 else {
2903 if (codec->patch_ops.init)
2904 codec->patch_ops.init(codec);
2905 if (codec->core.regmap)
2906 regcache_sync(codec->core.regmap);
2909 if (codec->jackpoll_interval)
2910 hda_jackpoll_work(&codec->jackpoll_work.work);
2911 else
2912 snd_hda_jack_report_sync(codec);
2913 codec->core.dev.power.power_state = PMSG_ON;
2914 snd_hdac_leave_pm(&codec->core);
2917 static int hda_codec_runtime_suspend(struct device *dev)
2919 struct hda_codec *codec = dev_to_hda_codec(dev);
2920 struct hda_pcm *pcm;
2921 unsigned int state;
2923 cancel_delayed_work_sync(&codec->jackpoll_work);
2924 list_for_each_entry(pcm, &codec->pcm_list_head, list)
2925 snd_pcm_suspend_all(pcm->pcm);
2926 state = hda_call_codec_suspend(codec);
2927 if (codec->link_down_at_suspend ||
2928 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
2929 (state & AC_PWRST_CLK_STOP_OK)))
2930 snd_hdac_codec_link_down(&codec->core);
2931 snd_hdac_link_power(&codec->core, false);
2932 return 0;
2935 static int hda_codec_runtime_resume(struct device *dev)
2937 struct hda_codec *codec = dev_to_hda_codec(dev);
2939 snd_hdac_link_power(&codec->core, true);
2940 snd_hdac_codec_link_up(&codec->core);
2941 hda_call_codec_resume(codec);
2942 pm_runtime_mark_last_busy(dev);
2943 return 0;
2945 #endif /* CONFIG_PM */
2947 #ifdef CONFIG_PM_SLEEP
2948 static int hda_codec_force_resume(struct device *dev)
2950 struct hda_codec *codec = dev_to_hda_codec(dev);
2951 bool forced_resume = !codec->relaxed_resume;
2952 int ret;
2954 /* The get/put pair below enforces the runtime resume even if the
2955 * device hasn't been used at suspend time. This trick is needed to
2956 * update the jack state change during the sleep.
2958 if (forced_resume)
2959 pm_runtime_get_noresume(dev);
2960 ret = pm_runtime_force_resume(dev);
2961 if (forced_resume)
2962 pm_runtime_put(dev);
2963 return ret;
2966 static int hda_codec_pm_suspend(struct device *dev)
2968 dev->power.power_state = PMSG_SUSPEND;
2969 return pm_runtime_force_suspend(dev);
2972 static int hda_codec_pm_resume(struct device *dev)
2974 dev->power.power_state = PMSG_RESUME;
2975 return hda_codec_force_resume(dev);
2978 static int hda_codec_pm_freeze(struct device *dev)
2980 dev->power.power_state = PMSG_FREEZE;
2981 return pm_runtime_force_suspend(dev);
2984 static int hda_codec_pm_thaw(struct device *dev)
2986 dev->power.power_state = PMSG_THAW;
2987 return hda_codec_force_resume(dev);
2990 static int hda_codec_pm_restore(struct device *dev)
2992 dev->power.power_state = PMSG_RESTORE;
2993 return hda_codec_force_resume(dev);
2995 #endif /* CONFIG_PM_SLEEP */
2997 /* referred in hda_bind.c */
2998 const struct dev_pm_ops hda_codec_driver_pm = {
2999 #ifdef CONFIG_PM_SLEEP
3000 .suspend = hda_codec_pm_suspend,
3001 .resume = hda_codec_pm_resume,
3002 .freeze = hda_codec_pm_freeze,
3003 .thaw = hda_codec_pm_thaw,
3004 .poweroff = hda_codec_pm_suspend,
3005 .restore = hda_codec_pm_restore,
3006 #endif /* CONFIG_PM_SLEEP */
3007 SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume,
3008 NULL)
3012 * add standard channel maps if not specified
3014 static int add_std_chmaps(struct hda_codec *codec)
3016 struct hda_pcm *pcm;
3017 int str, err;
3019 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
3020 for (str = 0; str < 2; str++) {
3021 struct hda_pcm_stream *hinfo = &pcm->stream[str];
3022 struct snd_pcm_chmap *chmap;
3023 const struct snd_pcm_chmap_elem *elem;
3025 if (!pcm->pcm || pcm->own_chmap || !hinfo->substreams)
3026 continue;
3027 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps;
3028 err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem,
3029 hinfo->channels_max,
3030 0, &chmap);
3031 if (err < 0)
3032 return err;
3033 chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
3036 return 0;
3039 /* default channel maps for 2.1 speakers;
3040 * since HD-audio supports only stereo, odd number channels are omitted
3042 const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[] = {
3043 { .channels = 2,
3044 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
3045 { .channels = 4,
3046 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
3047 SNDRV_CHMAP_LFE, SNDRV_CHMAP_LFE } },
3050 EXPORT_SYMBOL_GPL(snd_pcm_2_1_chmaps);
3052 int snd_hda_codec_build_controls(struct hda_codec *codec)
3054 int err = 0;
3055 hda_exec_init_verbs(codec);
3056 /* continue to initialize... */
3057 if (codec->patch_ops.init)
3058 err = codec->patch_ops.init(codec);
3059 if (!err && codec->patch_ops.build_controls)
3060 err = codec->patch_ops.build_controls(codec);
3061 if (err < 0)
3062 return err;
3064 /* we create chmaps here instead of build_pcms */
3065 err = add_std_chmaps(codec);
3066 if (err < 0)
3067 return err;
3069 if (codec->jackpoll_interval)
3070 hda_jackpoll_work(&codec->jackpoll_work.work);
3071 else
3072 snd_hda_jack_report_sync(codec); /* call at the last init point */
3073 sync_power_up_states(codec);
3074 return 0;
3076 EXPORT_SYMBOL_GPL(snd_hda_codec_build_controls);
3079 * PCM stuff
3081 static int hda_pcm_default_open_close(struct hda_pcm_stream *hinfo,
3082 struct hda_codec *codec,
3083 struct snd_pcm_substream *substream)
3085 return 0;
3088 static int hda_pcm_default_prepare(struct hda_pcm_stream *hinfo,
3089 struct hda_codec *codec,
3090 unsigned int stream_tag,
3091 unsigned int format,
3092 struct snd_pcm_substream *substream)
3094 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3095 return 0;
3098 static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
3099 struct hda_codec *codec,
3100 struct snd_pcm_substream *substream)
3102 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3103 return 0;
3106 static int set_pcm_default_values(struct hda_codec *codec,
3107 struct hda_pcm_stream *info)
3109 int err;
3111 /* query support PCM information from the given NID */
3112 if (info->nid && (!info->rates || !info->formats)) {
3113 err = snd_hda_query_supported_pcm(codec, info->nid,
3114 info->rates ? NULL : &info->rates,
3115 info->formats ? NULL : &info->formats,
3116 info->maxbps ? NULL : &info->maxbps);
3117 if (err < 0)
3118 return err;
3120 if (info->ops.open == NULL)
3121 info->ops.open = hda_pcm_default_open_close;
3122 if (info->ops.close == NULL)
3123 info->ops.close = hda_pcm_default_open_close;
3124 if (info->ops.prepare == NULL) {
3125 if (snd_BUG_ON(!info->nid))
3126 return -EINVAL;
3127 info->ops.prepare = hda_pcm_default_prepare;
3129 if (info->ops.cleanup == NULL) {
3130 if (snd_BUG_ON(!info->nid))
3131 return -EINVAL;
3132 info->ops.cleanup = hda_pcm_default_cleanup;
3134 return 0;
3138 * codec prepare/cleanup entries
3141 * snd_hda_codec_prepare - Prepare a stream
3142 * @codec: the HDA codec
3143 * @hinfo: PCM information
3144 * @stream: stream tag to assign
3145 * @format: format id to assign
3146 * @substream: PCM substream to assign
3148 * Calls the prepare callback set by the codec with the given arguments.
3149 * Clean up the inactive streams when successful.
3151 int snd_hda_codec_prepare(struct hda_codec *codec,
3152 struct hda_pcm_stream *hinfo,
3153 unsigned int stream,
3154 unsigned int format,
3155 struct snd_pcm_substream *substream)
3157 int ret;
3158 mutex_lock(&codec->bus->prepare_mutex);
3159 if (hinfo->ops.prepare)
3160 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
3161 substream);
3162 else
3163 ret = -ENODEV;
3164 if (ret >= 0)
3165 purify_inactive_streams(codec);
3166 mutex_unlock(&codec->bus->prepare_mutex);
3167 return ret;
3169 EXPORT_SYMBOL_GPL(snd_hda_codec_prepare);
3172 * snd_hda_codec_cleanup - Prepare a stream
3173 * @codec: the HDA codec
3174 * @hinfo: PCM information
3175 * @substream: PCM substream
3177 * Calls the cleanup callback set by the codec with the given arguments.
3179 void snd_hda_codec_cleanup(struct hda_codec *codec,
3180 struct hda_pcm_stream *hinfo,
3181 struct snd_pcm_substream *substream)
3183 mutex_lock(&codec->bus->prepare_mutex);
3184 if (hinfo->ops.cleanup)
3185 hinfo->ops.cleanup(hinfo, codec, substream);
3186 mutex_unlock(&codec->bus->prepare_mutex);
3188 EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup);
3190 /* global */
3191 const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3192 "Audio", "SPDIF", "HDMI", "Modem"
3196 * get the empty PCM device number to assign
3198 static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
3200 /* audio device indices; not linear to keep compatibility */
3201 /* assigned to static slots up to dev#10; if more needed, assign
3202 * the later slot dynamically (when CONFIG_SND_DYNAMIC_MINORS=y)
3204 static int audio_idx[HDA_PCM_NTYPES][5] = {
3205 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
3206 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
3207 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
3208 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
3210 int i;
3212 if (type >= HDA_PCM_NTYPES) {
3213 dev_err(bus->card->dev, "Invalid PCM type %d\n", type);
3214 return -EINVAL;
3217 for (i = 0; audio_idx[type][i] >= 0; i++) {
3218 #ifndef CONFIG_SND_DYNAMIC_MINORS
3219 if (audio_idx[type][i] >= 8)
3220 break;
3221 #endif
3222 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3223 return audio_idx[type][i];
3226 #ifdef CONFIG_SND_DYNAMIC_MINORS
3227 /* non-fixed slots starting from 10 */
3228 for (i = 10; i < 32; i++) {
3229 if (!test_and_set_bit(i, bus->pcm_dev_bits))
3230 return i;
3232 #endif
3234 dev_warn(bus->card->dev, "Too many %s devices\n",
3235 snd_hda_pcm_type_name[type]);
3236 #ifndef CONFIG_SND_DYNAMIC_MINORS
3237 dev_warn(bus->card->dev,
3238 "Consider building the kernel with CONFIG_SND_DYNAMIC_MINORS=y\n");
3239 #endif
3240 return -EAGAIN;
3243 /* call build_pcms ops of the given codec and set up the default parameters */
3244 int snd_hda_codec_parse_pcms(struct hda_codec *codec)
3246 struct hda_pcm *cpcm;
3247 int err;
3249 if (!list_empty(&codec->pcm_list_head))
3250 return 0; /* already parsed */
3252 if (!codec->patch_ops.build_pcms)
3253 return 0;
3255 err = codec->patch_ops.build_pcms(codec);
3256 if (err < 0) {
3257 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
3258 codec->core.addr, err);
3259 return err;
3262 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3263 int stream;
3265 for (stream = 0; stream < 2; stream++) {
3266 struct hda_pcm_stream *info = &cpcm->stream[stream];
3268 if (!info->substreams)
3269 continue;
3270 err = set_pcm_default_values(codec, info);
3271 if (err < 0) {
3272 codec_warn(codec,
3273 "fail to setup default for PCM %s\n",
3274 cpcm->name);
3275 return err;
3280 return 0;
3282 EXPORT_SYMBOL_GPL(snd_hda_codec_parse_pcms);
3284 /* assign all PCMs of the given codec */
3285 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3287 struct hda_bus *bus = codec->bus;
3288 struct hda_pcm *cpcm;
3289 int dev, err;
3291 err = snd_hda_codec_parse_pcms(codec);
3292 if (err < 0)
3293 return err;
3295 /* attach a new PCM streams */
3296 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3297 if (cpcm->pcm)
3298 continue; /* already attached */
3299 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
3300 continue; /* no substreams assigned */
3302 dev = get_empty_pcm_device(bus, cpcm->pcm_type);
3303 if (dev < 0) {
3304 cpcm->device = SNDRV_PCM_INVALID_DEVICE;
3305 continue; /* no fatal error */
3307 cpcm->device = dev;
3308 err = snd_hda_attach_pcm_stream(bus, codec, cpcm);
3309 if (err < 0) {
3310 codec_err(codec,
3311 "cannot attach PCM stream %d for codec #%d\n",
3312 dev, codec->core.addr);
3313 continue; /* no fatal error */
3317 return 0;
3321 * snd_hda_add_new_ctls - create controls from the array
3322 * @codec: the HDA codec
3323 * @knew: the array of struct snd_kcontrol_new
3325 * This helper function creates and add new controls in the given array.
3326 * The array must be terminated with an empty entry as terminator.
3328 * Returns 0 if successful, or a negative error code.
3330 int snd_hda_add_new_ctls(struct hda_codec *codec,
3331 const struct snd_kcontrol_new *knew)
3333 int err;
3335 for (; knew->name; knew++) {
3336 struct snd_kcontrol *kctl;
3337 int addr = 0, idx = 0;
3338 if (knew->iface == (__force snd_ctl_elem_iface_t)-1)
3339 continue; /* skip this codec private value */
3340 for (;;) {
3341 kctl = snd_ctl_new1(knew, codec);
3342 if (!kctl)
3343 return -ENOMEM;
3344 if (addr > 0)
3345 kctl->id.device = addr;
3346 if (idx > 0)
3347 kctl->id.index = idx;
3348 err = snd_hda_ctl_add(codec, 0, kctl);
3349 if (!err)
3350 break;
3351 /* try first with another device index corresponding to
3352 * the codec addr; if it still fails (or it's the
3353 * primary codec), then try another control index
3355 if (!addr && codec->core.addr)
3356 addr = codec->core.addr;
3357 else if (!idx && !knew->index) {
3358 idx = find_empty_mixer_ctl_idx(codec,
3359 knew->name, 0);
3360 if (idx <= 0)
3361 return err;
3362 } else
3363 return err;
3366 return 0;
3368 EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls);
3370 #ifdef CONFIG_PM
3371 static void codec_set_power_save(struct hda_codec *codec, int delay)
3373 struct device *dev = hda_codec_dev(codec);
3375 if (delay == 0 && codec->auto_runtime_pm)
3376 delay = 3000;
3378 if (delay > 0) {
3379 pm_runtime_set_autosuspend_delay(dev, delay);
3380 pm_runtime_use_autosuspend(dev);
3381 pm_runtime_allow(dev);
3382 if (!pm_runtime_suspended(dev))
3383 pm_runtime_mark_last_busy(dev);
3384 } else {
3385 pm_runtime_dont_use_autosuspend(dev);
3386 pm_runtime_forbid(dev);
3391 * snd_hda_set_power_save - reprogram autosuspend for the given delay
3392 * @bus: HD-audio bus
3393 * @delay: autosuspend delay in msec, 0 = off
3395 * Synchronize the runtime PM autosuspend state from the power_save option.
3397 void snd_hda_set_power_save(struct hda_bus *bus, int delay)
3399 struct hda_codec *c;
3401 list_for_each_codec(c, bus)
3402 codec_set_power_save(c, delay);
3404 EXPORT_SYMBOL_GPL(snd_hda_set_power_save);
3407 * snd_hda_check_amp_list_power - Check the amp list and update the power
3408 * @codec: HD-audio codec
3409 * @check: the object containing an AMP list and the status
3410 * @nid: NID to check / update
3412 * Check whether the given NID is in the amp list. If it's in the list,
3413 * check the current AMP status, and update the the power-status according
3414 * to the mute status.
3416 * This function is supposed to be set or called from the check_power_status
3417 * patch ops.
3419 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3420 struct hda_loopback_check *check,
3421 hda_nid_t nid)
3423 const struct hda_amp_list *p;
3424 int ch, v;
3426 if (!check->amplist)
3427 return 0;
3428 for (p = check->amplist; p->nid; p++) {
3429 if (p->nid == nid)
3430 break;
3432 if (!p->nid)
3433 return 0; /* nothing changed */
3435 for (p = check->amplist; p->nid; p++) {
3436 for (ch = 0; ch < 2; ch++) {
3437 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3438 p->idx);
3439 if (!(v & HDA_AMP_MUTE) && v > 0) {
3440 if (!check->power_on) {
3441 check->power_on = 1;
3442 snd_hda_power_up_pm(codec);
3444 return 1;
3448 if (check->power_on) {
3449 check->power_on = 0;
3450 snd_hda_power_down_pm(codec);
3452 return 0;
3454 EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power);
3455 #endif
3458 * input MUX helper
3462 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3463 * @imux: imux helper object
3464 * @uinfo: pointer to get/store the data
3466 int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3467 struct snd_ctl_elem_info *uinfo)
3469 unsigned int index;
3471 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3472 uinfo->count = 1;
3473 uinfo->value.enumerated.items = imux->num_items;
3474 if (!imux->num_items)
3475 return 0;
3476 index = uinfo->value.enumerated.item;
3477 if (index >= imux->num_items)
3478 index = imux->num_items - 1;
3479 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
3480 return 0;
3482 EXPORT_SYMBOL_GPL(snd_hda_input_mux_info);
3485 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3486 * @codec: the HDA codec
3487 * @imux: imux helper object
3488 * @ucontrol: pointer to get/store the data
3489 * @nid: input mux NID
3490 * @cur_val: pointer to get/store the current imux value
3492 int snd_hda_input_mux_put(struct hda_codec *codec,
3493 const struct hda_input_mux *imux,
3494 struct snd_ctl_elem_value *ucontrol,
3495 hda_nid_t nid,
3496 unsigned int *cur_val)
3498 unsigned int idx;
3500 if (!imux->num_items)
3501 return 0;
3502 idx = ucontrol->value.enumerated.item[0];
3503 if (idx >= imux->num_items)
3504 idx = imux->num_items - 1;
3505 if (*cur_val == idx)
3506 return 0;
3507 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3508 imux->items[idx].index);
3509 *cur_val = idx;
3510 return 1;
3512 EXPORT_SYMBOL_GPL(snd_hda_input_mux_put);
3516 * snd_hda_enum_helper_info - Helper for simple enum ctls
3517 * @kcontrol: ctl element
3518 * @uinfo: pointer to get/store the data
3519 * @num_items: number of enum items
3520 * @texts: enum item string array
3522 * process kcontrol info callback of a simple string enum array
3523 * when @num_items is 0 or @texts is NULL, assume a boolean enum array
3525 int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
3526 struct snd_ctl_elem_info *uinfo,
3527 int num_items, const char * const *texts)
3529 static const char * const texts_default[] = {
3530 "Disabled", "Enabled"
3533 if (!texts || !num_items) {
3534 num_items = 2;
3535 texts = texts_default;
3538 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
3540 EXPORT_SYMBOL_GPL(snd_hda_enum_helper_info);
3543 * Multi-channel / digital-out PCM helper functions
3546 /* setup SPDIF output stream */
3547 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3548 unsigned int stream_tag, unsigned int format)
3550 struct hda_spdif_out *spdif;
3551 unsigned int curr_fmt;
3552 bool reset;
3554 spdif = snd_hda_spdif_out_of_nid(codec, nid);
3555 /* Add sanity check to pass klockwork check.
3556 * This should never happen.
3558 if (WARN_ON(spdif == NULL))
3559 return;
3561 curr_fmt = snd_hda_codec_read(codec, nid, 0,
3562 AC_VERB_GET_STREAM_FORMAT, 0);
3563 reset = codec->spdif_status_reset &&
3564 (spdif->ctls & AC_DIG1_ENABLE) &&
3565 curr_fmt != format;
3567 /* turn off SPDIF if needed; otherwise the IEC958 bits won't be
3568 updated */
3569 if (reset)
3570 set_dig_out_convert(codec, nid,
3571 spdif->ctls & ~AC_DIG1_ENABLE & 0xff,
3572 -1);
3573 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3574 if (codec->slave_dig_outs) {
3575 const hda_nid_t *d;
3576 for (d = codec->slave_dig_outs; *d; d++)
3577 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3578 format);
3580 /* turn on again (if needed) */
3581 if (reset)
3582 set_dig_out_convert(codec, nid,
3583 spdif->ctls & 0xff, -1);
3586 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3588 snd_hda_codec_cleanup_stream(codec, nid);
3589 if (codec->slave_dig_outs) {
3590 const hda_nid_t *d;
3591 for (d = codec->slave_dig_outs; *d; d++)
3592 snd_hda_codec_cleanup_stream(codec, *d);
3597 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3598 * @codec: the HDA codec
3599 * @mout: hda_multi_out object
3601 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3602 struct hda_multi_out *mout)
3604 mutex_lock(&codec->spdif_mutex);
3605 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
3606 /* already opened as analog dup; reset it once */
3607 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3608 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
3609 mutex_unlock(&codec->spdif_mutex);
3610 return 0;
3612 EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_open);
3615 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3616 * @codec: the HDA codec
3617 * @mout: hda_multi_out object
3618 * @stream_tag: stream tag to assign
3619 * @format: format id to assign
3620 * @substream: PCM substream to assign
3622 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3623 struct hda_multi_out *mout,
3624 unsigned int stream_tag,
3625 unsigned int format,
3626 struct snd_pcm_substream *substream)
3628 mutex_lock(&codec->spdif_mutex);
3629 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3630 mutex_unlock(&codec->spdif_mutex);
3631 return 0;
3633 EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_prepare);
3636 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3637 * @codec: the HDA codec
3638 * @mout: hda_multi_out object
3640 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3641 struct hda_multi_out *mout)
3643 mutex_lock(&codec->spdif_mutex);
3644 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3645 mutex_unlock(&codec->spdif_mutex);
3646 return 0;
3648 EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_cleanup);
3651 * snd_hda_multi_out_dig_close - release the digital out stream
3652 * @codec: the HDA codec
3653 * @mout: hda_multi_out object
3655 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3656 struct hda_multi_out *mout)
3658 mutex_lock(&codec->spdif_mutex);
3659 mout->dig_out_used = 0;
3660 mutex_unlock(&codec->spdif_mutex);
3661 return 0;
3663 EXPORT_SYMBOL_GPL(snd_hda_multi_out_dig_close);
3666 * snd_hda_multi_out_analog_open - open analog outputs
3667 * @codec: the HDA codec
3668 * @mout: hda_multi_out object
3669 * @substream: PCM substream to assign
3670 * @hinfo: PCM information to assign
3672 * Open analog outputs and set up the hw-constraints.
3673 * If the digital outputs can be opened as slave, open the digital
3674 * outputs, too.
3676 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3677 struct hda_multi_out *mout,
3678 struct snd_pcm_substream *substream,
3679 struct hda_pcm_stream *hinfo)
3681 struct snd_pcm_runtime *runtime = substream->runtime;
3682 runtime->hw.channels_max = mout->max_channels;
3683 if (mout->dig_out_nid) {
3684 if (!mout->analog_rates) {
3685 mout->analog_rates = hinfo->rates;
3686 mout->analog_formats = hinfo->formats;
3687 mout->analog_maxbps = hinfo->maxbps;
3688 } else {
3689 runtime->hw.rates = mout->analog_rates;
3690 runtime->hw.formats = mout->analog_formats;
3691 hinfo->maxbps = mout->analog_maxbps;
3693 if (!mout->spdif_rates) {
3694 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
3695 &mout->spdif_rates,
3696 &mout->spdif_formats,
3697 &mout->spdif_maxbps);
3699 mutex_lock(&codec->spdif_mutex);
3700 if (mout->share_spdif) {
3701 if ((runtime->hw.rates & mout->spdif_rates) &&
3702 (runtime->hw.formats & mout->spdif_formats)) {
3703 runtime->hw.rates &= mout->spdif_rates;
3704 runtime->hw.formats &= mout->spdif_formats;
3705 if (mout->spdif_maxbps < hinfo->maxbps)
3706 hinfo->maxbps = mout->spdif_maxbps;
3707 } else {
3708 mout->share_spdif = 0;
3709 /* FIXME: need notify? */
3712 mutex_unlock(&codec->spdif_mutex);
3714 return snd_pcm_hw_constraint_step(substream->runtime, 0,
3715 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
3717 EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_open);
3720 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
3721 * @codec: the HDA codec
3722 * @mout: hda_multi_out object
3723 * @stream_tag: stream tag to assign
3724 * @format: format id to assign
3725 * @substream: PCM substream to assign
3727 * Set up the i/o for analog out.
3728 * When the digital out is available, copy the front out to digital out, too.
3730 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3731 struct hda_multi_out *mout,
3732 unsigned int stream_tag,
3733 unsigned int format,
3734 struct snd_pcm_substream *substream)
3736 const hda_nid_t *nids = mout->dac_nids;
3737 int chs = substream->runtime->channels;
3738 struct hda_spdif_out *spdif;
3739 int i;
3741 mutex_lock(&codec->spdif_mutex);
3742 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
3743 if (mout->dig_out_nid && mout->share_spdif &&
3744 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
3745 if (chs == 2 && spdif != NULL &&
3746 snd_hda_is_supported_format(codec, mout->dig_out_nid,
3747 format) &&
3748 !(spdif->status & IEC958_AES0_NONAUDIO)) {
3749 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
3750 setup_dig_out_stream(codec, mout->dig_out_nid,
3751 stream_tag, format);
3752 } else {
3753 mout->dig_out_used = 0;
3754 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3757 mutex_unlock(&codec->spdif_mutex);
3759 /* front */
3760 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
3761 0, format);
3762 if (!mout->no_share_stream &&
3763 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
3764 /* headphone out will just decode front left/right (stereo) */
3765 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
3766 0, format);
3767 /* extra outputs copied from front */
3768 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
3769 if (!mout->no_share_stream && mout->hp_out_nid[i])
3770 snd_hda_codec_setup_stream(codec,
3771 mout->hp_out_nid[i],
3772 stream_tag, 0, format);
3774 /* surrounds */
3775 for (i = 1; i < mout->num_dacs; i++) {
3776 if (chs >= (i + 1) * 2) /* independent out */
3777 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3778 i * 2, format);
3779 else if (!mout->no_share_stream) /* copy front */
3780 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3781 0, format);
3784 /* extra surrounds */
3785 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) {
3786 int ch = 0;
3787 if (!mout->extra_out_nid[i])
3788 break;
3789 if (chs >= (i + 1) * 2)
3790 ch = i * 2;
3791 else if (!mout->no_share_stream)
3792 break;
3793 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i],
3794 stream_tag, ch, format);
3797 return 0;
3799 EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_prepare);
3802 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3803 * @codec: the HDA codec
3804 * @mout: hda_multi_out object
3806 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3807 struct hda_multi_out *mout)
3809 const hda_nid_t *nids = mout->dac_nids;
3810 int i;
3812 for (i = 0; i < mout->num_dacs; i++)
3813 snd_hda_codec_cleanup_stream(codec, nids[i]);
3814 if (mout->hp_nid)
3815 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
3816 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
3817 if (mout->hp_out_nid[i])
3818 snd_hda_codec_cleanup_stream(codec,
3819 mout->hp_out_nid[i]);
3820 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
3821 if (mout->extra_out_nid[i])
3822 snd_hda_codec_cleanup_stream(codec,
3823 mout->extra_out_nid[i]);
3824 mutex_lock(&codec->spdif_mutex);
3825 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
3826 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3827 mout->dig_out_used = 0;
3829 mutex_unlock(&codec->spdif_mutex);
3830 return 0;
3832 EXPORT_SYMBOL_GPL(snd_hda_multi_out_analog_cleanup);
3835 * snd_hda_get_default_vref - Get the default (mic) VREF pin bits
3836 * @codec: the HDA codec
3837 * @pin: referred pin NID
3839 * Guess the suitable VREF pin bits to be set as the pin-control value.
3840 * Note: the function doesn't set the AC_PINCTL_IN_EN bit.
3842 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
3844 unsigned int pincap;
3845 unsigned int oldval;
3846 oldval = snd_hda_codec_read(codec, pin, 0,
3847 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3848 pincap = snd_hda_query_pin_caps(codec, pin);
3849 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
3850 /* Exception: if the default pin setup is vref50, we give it priority */
3851 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
3852 return AC_PINCTL_VREF_80;
3853 else if (pincap & AC_PINCAP_VREF_50)
3854 return AC_PINCTL_VREF_50;
3855 else if (pincap & AC_PINCAP_VREF_100)
3856 return AC_PINCTL_VREF_100;
3857 else if (pincap & AC_PINCAP_VREF_GRD)
3858 return AC_PINCTL_VREF_GRD;
3859 return AC_PINCTL_VREF_HIZ;
3861 EXPORT_SYMBOL_GPL(snd_hda_get_default_vref);
3864 * snd_hda_correct_pin_ctl - correct the pin ctl value for matching with the pin cap
3865 * @codec: the HDA codec
3866 * @pin: referred pin NID
3867 * @val: pin ctl value to audit
3869 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
3870 hda_nid_t pin, unsigned int val)
3872 static unsigned int cap_lists[][2] = {
3873 { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 },
3874 { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 },
3875 { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 },
3876 { AC_PINCTL_VREF_GRD, AC_PINCAP_VREF_GRD },
3878 unsigned int cap;
3880 if (!val)
3881 return 0;
3882 cap = snd_hda_query_pin_caps(codec, pin);
3883 if (!cap)
3884 return val; /* don't know what to do... */
3886 if (val & AC_PINCTL_OUT_EN) {
3887 if (!(cap & AC_PINCAP_OUT))
3888 val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3889 else if ((val & AC_PINCTL_HP_EN) && !(cap & AC_PINCAP_HP_DRV))
3890 val &= ~AC_PINCTL_HP_EN;
3893 if (val & AC_PINCTL_IN_EN) {
3894 if (!(cap & AC_PINCAP_IN))
3895 val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN);
3896 else {
3897 unsigned int vcap, vref;
3898 int i;
3899 vcap = (cap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
3900 vref = val & AC_PINCTL_VREFEN;
3901 for (i = 0; i < ARRAY_SIZE(cap_lists); i++) {
3902 if (vref == cap_lists[i][0] &&
3903 !(vcap & cap_lists[i][1])) {
3904 if (i == ARRAY_SIZE(cap_lists) - 1)
3905 vref = AC_PINCTL_VREF_HIZ;
3906 else
3907 vref = cap_lists[i + 1][0];
3910 val &= ~AC_PINCTL_VREFEN;
3911 val |= vref;
3915 return val;
3917 EXPORT_SYMBOL_GPL(snd_hda_correct_pin_ctl);
3920 * _snd_hda_pin_ctl - Helper to set pin ctl value
3921 * @codec: the HDA codec
3922 * @pin: referred pin NID
3923 * @val: pin control value to set
3924 * @cached: access over codec pinctl cache or direct write
3926 * This function is a helper to set a pin ctl value more safely.
3927 * It corrects the pin ctl value via snd_hda_correct_pin_ctl(), stores the
3928 * value in pin target array via snd_hda_codec_set_pin_target(), then
3929 * actually writes the value via either snd_hda_codec_write_cache() or
3930 * snd_hda_codec_write() depending on @cached flag.
3932 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
3933 unsigned int val, bool cached)
3935 val = snd_hda_correct_pin_ctl(codec, pin, val);
3936 snd_hda_codec_set_pin_target(codec, pin, val);
3937 if (cached)
3938 return snd_hda_codec_write_cache(codec, pin, 0,
3939 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
3940 else
3941 return snd_hda_codec_write(codec, pin, 0,
3942 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
3944 EXPORT_SYMBOL_GPL(_snd_hda_set_pin_ctl);
3947 * snd_hda_add_imux_item - Add an item to input_mux
3948 * @codec: the HDA codec
3949 * @imux: imux helper object
3950 * @label: the name of imux item to assign
3951 * @index: index number of imux item to assign
3952 * @type_idx: pointer to store the resultant label index
3954 * When the same label is used already in the existing items, the number
3955 * suffix is appended to the label. This label index number is stored
3956 * to type_idx when non-NULL pointer is given.
3958 int snd_hda_add_imux_item(struct hda_codec *codec,
3959 struct hda_input_mux *imux, const char *label,
3960 int index, int *type_idx)
3962 int i, label_idx = 0;
3963 if (imux->num_items >= HDA_MAX_NUM_INPUTS) {
3964 codec_err(codec, "hda_codec: Too many imux items!\n");
3965 return -EINVAL;
3967 for (i = 0; i < imux->num_items; i++) {
3968 if (!strncmp(label, imux->items[i].label, strlen(label)))
3969 label_idx++;
3971 if (type_idx)
3972 *type_idx = label_idx;
3973 if (label_idx > 0)
3974 snprintf(imux->items[imux->num_items].label,
3975 sizeof(imux->items[imux->num_items].label),
3976 "%s %d", label, label_idx);
3977 else
3978 strlcpy(imux->items[imux->num_items].label, label,
3979 sizeof(imux->items[imux->num_items].label));
3980 imux->items[imux->num_items].index = index;
3981 imux->num_items++;
3982 return 0;
3984 EXPORT_SYMBOL_GPL(snd_hda_add_imux_item);
3987 * snd_hda_bus_reset_codecs - Reset the bus
3988 * @bus: HD-audio bus
3990 void snd_hda_bus_reset_codecs(struct hda_bus *bus)
3992 struct hda_codec *codec;
3994 list_for_each_codec(codec, bus) {
3995 /* FIXME: maybe a better way needed for forced reset */
3996 if (current_work() != &codec->jackpoll_work.work)
3997 cancel_delayed_work_sync(&codec->jackpoll_work);
3998 #ifdef CONFIG_PM
3999 if (hda_codec_is_power_on(codec)) {
4000 hda_call_codec_suspend(codec);
4001 hda_call_codec_resume(codec);
4003 #endif
4008 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4009 * @pcm: PCM caps bits
4010 * @buf: the string buffer to write
4011 * @buflen: the max buffer length
4013 * used by hda_proc.c and hda_eld.c
4015 void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4017 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
4018 int i, j;
4020 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
4021 if (pcm & (AC_SUPPCM_BITS_8 << i))
4022 j += scnprintf(buf + j, buflen - j, " %d", bits[i]);
4024 buf[j] = '\0'; /* necessary when j == 0 */
4026 EXPORT_SYMBOL_GPL(snd_print_pcm_bits);
4028 MODULE_DESCRIPTION("HDA codec core");
4029 MODULE_LICENSE("GPL");