Lines Matching +full:codec +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Universal Interface for Intel High Definition Audio Codec
27 #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core) argument
28 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core) argument
29 #define codec_has_epss(codec) \ argument
30 ((codec)->core.power_caps & AC_PWRST_EPSS)
31 #define codec_has_clkstop(codec) \ argument
32 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
35 * Send and receive a verb - passed to exec_verb override for hdac_device
40 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in codec_exec_verb() local
41 struct hda_bus *bus = codec->bus; in codec_exec_verb()
45 return -1; in codec_exec_verb()
48 snd_hda_power_up_pm(codec); in codec_exec_verb()
49 mutex_lock(&bus->core.cmd_mutex); in codec_exec_verb()
51 bus->no_response_fallback = 1; in codec_exec_verb()
52 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, in codec_exec_verb()
54 bus->no_response_fallback = 0; in codec_exec_verb()
55 mutex_unlock(&bus->core.cmd_mutex); in codec_exec_verb()
56 snd_hda_power_down_pm(codec); in codec_exec_verb()
57 if (!codec_in_pm(codec) && res && err == -EAGAIN) { in codec_exec_verb()
58 if (bus->response_reset) { in codec_exec_verb()
59 codec_dbg(codec, in codec_exec_verb()
65 /* clear reset-flag when the communication gets recovered */ in codec_exec_verb()
66 if (!err || codec_in_pm(codec)) in codec_exec_verb()
67 bus->response_reset = 0; in codec_exec_verb()
72 * snd_hda_sequence_write - sequence writes
73 * @codec: the HDA codec
79 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
81 for (; seq->nid; seq++) in snd_hda_sequence_write()
82 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); in snd_hda_sequence_write()
96 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) in lookup_conn_list() argument
99 list_for_each_entry(p, &codec->conn_list, list) { in lookup_conn_list()
100 if (p->nid == nid) in lookup_conn_list()
106 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in add_conn_list() argument
113 return -ENOMEM; in add_conn_list()
114 p->len = len; in add_conn_list()
115 p->nid = nid; in add_conn_list()
116 memcpy(p->conns, list, len * sizeof(hda_nid_t)); in add_conn_list()
117 list_add(&p->list, &codec->conn_list); in add_conn_list()
121 static void remove_conn_list(struct hda_codec *codec) in remove_conn_list() argument
123 while (!list_empty(&codec->conn_list)) { in remove_conn_list()
125 p = list_first_entry(&codec->conn_list, typeof(*p), list); in remove_conn_list()
126 list_del(&p->list); in remove_conn_list()
132 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) in read_and_add_raw_conns() argument
138 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); in read_and_add_raw_conns()
139 if (len == -ENOSPC) { in read_and_add_raw_conns()
140 len = snd_hda_get_num_raw_conns(codec, nid); in read_and_add_raw_conns()
143 return -ENOMEM; in read_and_add_raw_conns()
144 len = snd_hda_get_raw_connections(codec, nid, result, len); in read_and_add_raw_conns()
147 len = snd_hda_override_conn_list(codec, nid, len, result); in read_and_add_raw_conns()
154 * snd_hda_get_conn_list - get connection list
155 * @codec: the HDA codec
168 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
177 /* if the connection-list is already cached, read it */ in snd_hda_get_conn_list()
178 p = lookup_conn_list(codec, nid); in snd_hda_get_conn_list()
181 *listp = p->conns; in snd_hda_get_conn_list()
182 return p->len; in snd_hda_get_conn_list()
185 return -EINVAL; in snd_hda_get_conn_list()
187 err = read_and_add_raw_conns(codec, nid); in snd_hda_get_conn_list()
196 * snd_hda_get_connections - copy connection list
197 * @codec: the HDA codec
207 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_connections() argument
211 int len = snd_hda_get_conn_list(codec, nid, &list); in snd_hda_get_connections()
215 codec_err(codec, "Too many connections %d for NID 0x%x\n", in snd_hda_get_connections()
217 return -EINVAL; in snd_hda_get_connections()
227 * snd_hda_override_conn_list - add/modify the connection-list to cache
228 * @codec: the HDA codec
233 * Add or modify the given connection-list to the cache. If the corresponding
238 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in snd_hda_override_conn_list() argument
243 p = lookup_conn_list(codec, nid); in snd_hda_override_conn_list()
245 list_del(&p->list); in snd_hda_override_conn_list()
249 return add_conn_list(codec, nid, len, list); in snd_hda_override_conn_list()
254 * snd_hda_get_conn_index - get the connection index of the given NID
255 * @codec: the HDA codec
262 * Otherwise it returns -1.
264 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, in snd_hda_get_conn_index() argument
270 nums = snd_hda_get_conn_list(codec, mux, &conn); in snd_hda_get_conn_index()
275 return -1; in snd_hda_get_conn_index()
277 codec_dbg(codec, "too deep connection for 0x%x\n", nid); in snd_hda_get_conn_index()
278 return -1; in snd_hda_get_conn_index()
282 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i])); in snd_hda_get_conn_index()
285 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) in snd_hda_get_conn_index()
288 return -1; in snd_hda_get_conn_index()
293 * snd_hda_get_num_devices - get DEVLIST_LEN parameter of the given widget
294 * @codec: the HDA codec
300 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_num_devices() argument
302 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_get_num_devices()
305 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || in snd_hda_get_num_devices()
309 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN); in snd_hda_get_num_devices()
310 if (parm == -1) in snd_hda_get_num_devices()
317 * snd_hda_get_devices - copy device list without cache
318 * @codec: the HDA codec
326 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_devices() argument
332 parm = snd_hda_get_num_devices(codec, nid); in snd_hda_get_devices()
333 if (!parm) /* not multi-stream capable */ in snd_hda_get_devices()
341 if (snd_hdac_read(&codec->core, nid, in snd_hda_get_devices()
357 * snd_hda_get_dev_select - get device entry select on the pin
358 * @codec: the HDA codec
365 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_dev_select() argument
368 if (!codec->dp_mst) in snd_hda_get_dev_select()
371 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0); in snd_hda_get_dev_select()
376 * snd_hda_set_dev_select - set device entry select on the pin
377 * @codec: the HDA codec
383 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id) in snd_hda_set_dev_select() argument
388 if (!codec->dp_mst) in snd_hda_set_dev_select()
392 num_devices = snd_hda_get_num_devices(codec, nid) + 1; in snd_hda_set_dev_select()
404 return -EINVAL; in snd_hda_set_dev_select()
406 ret = snd_hda_codec_write(codec, nid, 0, in snd_hda_set_dev_select()
416 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) in read_widget_caps() argument
421 codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL); in read_widget_caps()
422 if (!codec->wcaps) in read_widget_caps()
423 return -ENOMEM; in read_widget_caps()
424 nid = codec->core.start_nid; in read_widget_caps()
425 for (i = 0; i < codec->core.num_nodes; i++, nid++) in read_widget_caps()
426 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, in read_widget_caps()
431 /* read all pin default configurations and save codec->init_pins */
432 static int read_pin_defaults(struct hda_codec *codec) in read_pin_defaults() argument
436 for_each_hda_codec_node(nid, codec) { in read_pin_defaults()
438 unsigned int wcaps = get_wcaps(codec, nid); in read_pin_defaults()
442 pin = snd_array_new(&codec->init_pins); in read_pin_defaults()
444 return -ENOMEM; in read_pin_defaults()
445 pin->nid = nid; in read_pin_defaults()
446 pin->cfg = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
450 * fixme: if any codec is different, need fix here in read_pin_defaults()
452 pin->ctrl = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
460 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, in look_up_pincfg() argument
468 if (pin->nid == nid) in look_up_pincfg()
477 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
487 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) in snd_hda_add_pincfg()
488 return -EINVAL; in snd_hda_add_pincfg()
491 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
495 return -ENOMEM; in snd_hda_add_pincfg()
496 pin->nid = nid; in snd_hda_add_pincfg()
498 pin->cfg = cfg; in snd_hda_add_pincfg()
503 * snd_hda_codec_set_pincfg - Override a pin default configuration
504 * @codec: the HDA codec
512 int snd_hda_codec_set_pincfg(struct hda_codec *codec, in snd_hda_codec_set_pincfg() argument
515 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); in snd_hda_codec_set_pincfg()
520 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
521 * @codec: the HDA codec
528 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pincfg() argument
535 mutex_lock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
536 pin = look_up_pincfg(codec, &codec->user_pins, nid); in snd_hda_codec_get_pincfg()
538 cfg = pin->cfg; in snd_hda_codec_get_pincfg()
539 mutex_unlock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
544 pin = look_up_pincfg(codec, &codec->driver_pins, nid); in snd_hda_codec_get_pincfg()
546 return pin->cfg; in snd_hda_codec_get_pincfg()
547 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pincfg()
549 return pin->cfg; in snd_hda_codec_get_pincfg()
555 * snd_hda_codec_set_pin_target - remember the current pinctl target value
556 * @codec: the HDA codec
564 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_set_pin_target() argument
569 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_set_pin_target()
571 return -EINVAL; in snd_hda_codec_set_pin_target()
572 pin->target = val; in snd_hda_codec_set_pin_target()
578 * snd_hda_codec_get_pin_target - return the current pinctl target value
579 * @codec: the HDA codec
582 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pin_target() argument
586 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pin_target()
589 return pin->target; in snd_hda_codec_get_pin_target()
594 * snd_hda_shutup_pins - Shut up all pins
595 * @codec: the HDA codec
600 void snd_hda_shutup_pins(struct hda_codec *codec) in snd_hda_shutup_pins() argument
608 if (codec->bus->shutdown) in snd_hda_shutup_pins()
610 snd_array_for_each(&codec->init_pins, i, pin) { in snd_hda_shutup_pins()
612 snd_hda_codec_read(codec, pin->nid, 0, in snd_hda_shutup_pins()
615 codec->pins_shutup = 1; in snd_hda_shutup_pins()
621 static void restore_shutup_pins(struct hda_codec *codec) in restore_shutup_pins() argument
626 if (!codec->pins_shutup) in restore_shutup_pins()
628 if (codec->bus->shutdown) in restore_shutup_pins()
630 snd_array_for_each(&codec->init_pins, i, pin) { in restore_shutup_pins()
631 snd_hda_codec_write(codec, pin->nid, 0, in restore_shutup_pins()
633 pin->ctrl); in restore_shutup_pins()
635 codec->pins_shutup = 0; in restore_shutup_pins()
641 struct hda_codec *codec = in hda_jackpoll_work() local
644 /* for non-polling trigger: we need nothing if already powered on */ in hda_jackpoll_work()
645 if (!codec->jackpoll_interval && snd_hdac_is_power_on(&codec->core)) in hda_jackpoll_work()
648 /* the power-up/down sequence triggers the runtime resume */ in hda_jackpoll_work()
649 snd_hda_power_up_pm(codec); in hda_jackpoll_work()
651 if (codec->jackpoll_interval) { in hda_jackpoll_work()
652 snd_hda_jack_set_dirty_all(codec); in hda_jackpoll_work()
653 snd_hda_jack_poll_all(codec); in hda_jackpoll_work()
655 snd_hda_power_down_pm(codec); in hda_jackpoll_work()
657 if (!codec->jackpoll_interval) in hda_jackpoll_work()
660 schedule_delayed_work(&codec->jackpoll_work, in hda_jackpoll_work()
661 codec->jackpoll_interval); in hda_jackpoll_work()
665 static void free_init_pincfgs(struct hda_codec *codec) in free_init_pincfgs() argument
667 snd_array_free(&codec->driver_pins); in free_init_pincfgs()
669 snd_array_free(&codec->user_pins); in free_init_pincfgs()
671 snd_array_free(&codec->init_pins); in free_init_pincfgs()
675 * audio-converter setup caches
688 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) in get_hda_cvt_setup() argument
693 snd_array_for_each(&codec->cvt_setups, i, p) { in get_hda_cvt_setup()
694 if (p->nid == nid) in get_hda_cvt_setup()
697 p = snd_array_new(&codec->cvt_setups); in get_hda_cvt_setup()
699 p->nid = nid; in get_hda_cvt_setup()
708 if (refcount_dec_and_test(&pcm->codec->pcm_ref)) in snd_hda_codec_pcm_put()
709 wake_up(&pcm->codec->remove_sleep); in snd_hda_codec_pcm_put()
713 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, in snd_hda_codec_pcm_new() argument
723 pcm->codec = codec; in snd_hda_codec_pcm_new()
725 pcm->name = kvasprintf(GFP_KERNEL, fmt, args); in snd_hda_codec_pcm_new()
727 if (!pcm->name) { in snd_hda_codec_pcm_new()
732 list_add_tail(&pcm->list, &codec->pcm_list_head); in snd_hda_codec_pcm_new()
733 refcount_inc(&codec->pcm_ref); in snd_hda_codec_pcm_new()
739 * codec destructor
741 void snd_hda_codec_disconnect_pcms(struct hda_codec *codec) in snd_hda_codec_disconnect_pcms() argument
745 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in snd_hda_codec_disconnect_pcms()
746 if (pcm->disconnected) in snd_hda_codec_disconnect_pcms()
748 if (pcm->pcm) in snd_hda_codec_disconnect_pcms()
749 snd_device_disconnect(codec->card, pcm->pcm); in snd_hda_codec_disconnect_pcms()
751 pcm->disconnected = 1; in snd_hda_codec_disconnect_pcms()
755 static void codec_release_pcms(struct hda_codec *codec) in codec_release_pcms() argument
759 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { in codec_release_pcms()
760 list_del(&pcm->list); in codec_release_pcms()
761 if (pcm->pcm) in codec_release_pcms()
762 snd_device_free(pcm->codec->card, pcm->pcm); in codec_release_pcms()
763 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); in codec_release_pcms()
764 kfree(pcm->name); in codec_release_pcms()
770 * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal
771 * @codec: codec device to cleanup
773 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) in snd_hda_codec_cleanup_for_unbind() argument
775 if (codec->core.registered) { in snd_hda_codec_cleanup_for_unbind()
777 pm_runtime_get_noresume(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
778 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
779 codec->core.registered = 0; in snd_hda_codec_cleanup_for_unbind()
782 snd_hda_codec_disconnect_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
783 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_cleanup_for_unbind()
784 if (!codec->in_freeing) in snd_hda_codec_cleanup_for_unbind()
785 snd_hda_ctls_clear(codec); in snd_hda_codec_cleanup_for_unbind()
786 codec_release_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
787 snd_hda_detach_beep_device(codec); in snd_hda_codec_cleanup_for_unbind()
788 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); in snd_hda_codec_cleanup_for_unbind()
789 snd_hda_jack_tbl_clear(codec); in snd_hda_codec_cleanup_for_unbind()
790 codec->proc_widget_hook = NULL; in snd_hda_codec_cleanup_for_unbind()
791 codec->spec = NULL; in snd_hda_codec_cleanup_for_unbind()
794 snd_array_free(&codec->driver_pins); in snd_hda_codec_cleanup_for_unbind()
795 snd_array_free(&codec->cvt_setups); in snd_hda_codec_cleanup_for_unbind()
796 snd_array_free(&codec->spdif_out); in snd_hda_codec_cleanup_for_unbind()
797 snd_array_free(&codec->verbs); in snd_hda_codec_cleanup_for_unbind()
798 codec->follower_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
799 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
800 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
801 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
802 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
803 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
804 codec->configured = 0; in snd_hda_codec_cleanup_for_unbind()
805 refcount_set(&codec->pcm_ref, 1); /* reset refcount */ in snd_hda_codec_cleanup_for_unbind()
809 static unsigned int hda_set_power_state(struct hda_codec *codec,
812 /* enable/disable display power per codec */
813 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) in snd_hda_codec_display_power() argument
815 if (codec->display_power_control) in snd_hda_codec_display_power()
816 snd_hdac_display_power(&codec->bus->core, codec->addr, enable); in snd_hda_codec_display_power()
820 * snd_hda_codec_register - Finalize codec initialization
821 * @codec: codec device to register
825 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
827 if (codec->core.registered) in snd_hda_codec_register()
829 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
830 snd_hda_codec_display_power(codec, true); in snd_hda_codec_register()
831 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
833 snd_hda_power_down(codec); in snd_hda_codec_register()
834 codec->core.registered = 1; in snd_hda_codec_register()
841 snd_hda_codec_register(device->device_data); in snd_hda_codec_dev_register()
846 * snd_hda_codec_unregister - Unregister specified codec device
847 * @codec: codec device to unregister
849 void snd_hda_codec_unregister(struct hda_codec *codec) in snd_hda_codec_unregister() argument
851 codec->in_freeing = 1; in snd_hda_codec_unregister()
857 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
858 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_unregister()
859 snd_hda_codec_display_power(codec, false); in snd_hda_codec_unregister()
862 * In the case of ASoC HD-audio bus, the device refcount is released in in snd_hda_codec_unregister()
865 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
866 put_device(hda_codec_dev(codec)); in snd_hda_codec_unregister()
872 snd_hda_codec_unregister(device->device_data); in snd_hda_codec_dev_free()
878 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
880 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
881 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
882 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
883 kfree(codec->modelname); in snd_hda_codec_dev_release()
884 kfree(codec->wcaps); in snd_hda_codec_dev_release()
885 kfree(codec); in snd_hda_codec_dev_release()
891 * snd_hda_codec_device_init - allocate HDA codec device
892 * @bus: codec's parent bus
893 * @codec_addr: the codec address on the parent bus
896 * Returns newly allocated codec device or ERR_PTR() on failure.
904 struct hda_codec *codec; in snd_hda_codec_device_init() local
908 return ERR_PTR(-EINVAL); in snd_hda_codec_device_init()
910 return ERR_PTR(-EINVAL); in snd_hda_codec_device_init()
912 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_hda_codec_device_init()
913 if (!codec) in snd_hda_codec_device_init()
914 return ERR_PTR(-ENOMEM); in snd_hda_codec_device_init()
920 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr); in snd_hda_codec_device_init()
922 kfree(codec); in snd_hda_codec_device_init()
926 codec->bus = bus; in snd_hda_codec_device_init()
927 codec->depop_delay = -1; in snd_hda_codec_device_init()
928 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_device_init()
929 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_device_init()
930 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_device_init()
932 mutex_init(&codec->spdif_mutex); in snd_hda_codec_device_init()
933 mutex_init(&codec->control_mutex); in snd_hda_codec_device_init()
934 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
935 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
936 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
937 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
938 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_device_init()
939 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_device_init()
940 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_device_init()
941 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_device_init()
942 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_device_init()
943 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_device_init()
944 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_device_init()
945 refcount_set(&codec->pcm_ref, 1); in snd_hda_codec_device_init()
946 init_waitqueue_head(&codec->remove_sleep); in snd_hda_codec_device_init()
948 return codec; in snd_hda_codec_device_init()
953 * snd_hda_codec_new - create a HDA codec
955 * @card: card for this codec
956 * @codec_addr: the codec address
957 * @codecp: the pointer to store the generated codec
964 struct hda_codec *codec; in snd_hda_codec_new() local
967 codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d", in snd_hda_codec_new()
968 card->number, codec_addr); in snd_hda_codec_new()
969 if (IS_ERR(codec)) in snd_hda_codec_new()
970 return PTR_ERR(codec); in snd_hda_codec_new()
971 *codecp = codec; in snd_hda_codec_new()
982 unsigned int codec_addr, struct hda_codec *codec, in snd_hda_codec_device_new() argument
993 dev_dbg(card->dev, "%s: entry\n", __func__); in snd_hda_codec_device_new()
996 return -EINVAL; in snd_hda_codec_device_new()
998 return -EINVAL; in snd_hda_codec_device_new()
1000 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_device_new()
1001 codec->card = card; in snd_hda_codec_device_new()
1002 codec->addr = codec_addr; in snd_hda_codec_device_new()
1005 codec->power_jiffies = jiffies; in snd_hda_codec_device_new()
1008 snd_hda_sysfs_init(codec); in snd_hda_codec_device_new()
1010 if (codec->bus->modelname) { in snd_hda_codec_device_new()
1011 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_device_new()
1012 if (!codec->modelname) in snd_hda_codec_device_new()
1013 return -ENOMEM; in snd_hda_codec_device_new()
1016 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_device_new()
1017 err = read_widget_caps(codec, fg); in snd_hda_codec_device_new()
1020 err = read_pin_defaults(codec); in snd_hda_codec_device_new()
1024 /* power-up all before initialization */ in snd_hda_codec_device_new()
1025 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_device_new()
1026 codec->core.dev.power.power_state = PMSG_ON; in snd_hda_codec_device_new()
1028 snd_hda_codec_proc_new(codec); in snd_hda_codec_device_new()
1030 snd_hda_create_hwdep(codec); in snd_hda_codec_device_new()
1032 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_device_new()
1033 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_device_new()
1038 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_device_new()
1044 /* PM runtime needs to be enabled later after binding codec */ in snd_hda_codec_device_new()
1045 if (codec->core.dev.power.runtime_auto) in snd_hda_codec_device_new()
1046 pm_runtime_forbid(&codec->core.dev); in snd_hda_codec_device_new()
1049 pm_runtime_get_noresume(&codec->core.dev); in snd_hda_codec_device_new()
1057 * snd_hda_codec_update_widgets - Refresh widget caps and pin defaults
1058 * @codec: the HDA codec
1061 * the given codec.
1063 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
1068 err = snd_hdac_refresh_widgets(&codec->core); in snd_hda_codec_update_widgets()
1075 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
1076 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
1077 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
1081 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
1082 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
1088 /* update the stream-id if changed */
1089 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
1095 if (p->stream_tag != stream_tag || p->channel_id != channel_id) { in update_pcm_stream_id()
1096 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
1099 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
1102 p->stream_tag = stream_tag; in update_pcm_stream_id()
1103 p->channel_id = channel_id; in update_pcm_stream_id()
1107 /* update the format-id if changed */
1108 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
1113 if (p->format_id != format) { in update_pcm_format()
1114 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
1118 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
1122 p->format_id = format; in update_pcm_format()
1127 * snd_hda_codec_setup_stream - set up the codec for streaming
1128 * @codec: the CODEC to set up
1134 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
1146 codec_dbg(codec, in snd_hda_codec_setup_stream()
1149 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
1153 if (codec->patch_ops.stream_pm) in snd_hda_codec_setup_stream()
1154 codec->patch_ops.stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1155 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1156 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1157 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1158 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1159 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1161 p->active = 1; in snd_hda_codec_setup_stream()
1162 p->dirty = 0; in snd_hda_codec_setup_stream()
1164 /* make other inactive cvts with the same stream-tag dirty */ in snd_hda_codec_setup_stream()
1165 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1166 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1167 snd_array_for_each(&c->cvt_setups, i, p) { in snd_hda_codec_setup_stream()
1168 if (!p->active && p->stream_tag == stream_tag && in snd_hda_codec_setup_stream()
1169 get_wcaps_type(get_wcaps(c, p->nid)) == type) in snd_hda_codec_setup_stream()
1170 p->dirty = 1; in snd_hda_codec_setup_stream()
1176 static void really_cleanup_stream(struct hda_codec *codec,
1180 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1181 * @codec: the CODEC to clean up
1185 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1193 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1196 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1197 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1200 * actual clean-ups will be done later in in __snd_hda_codec_cleanup_stream()
1204 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1206 p->active = 0; in __snd_hda_codec_cleanup_stream()
1211 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1214 hda_nid_t nid = q->nid; in really_cleanup_stream()
1215 if (q->stream_tag || q->channel_id) in really_cleanup_stream()
1216 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1217 if (q->format_id) in really_cleanup_stream()
1218 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1221 q->nid = nid; in really_cleanup_stream()
1222 if (codec->patch_ops.stream_pm) in really_cleanup_stream()
1223 codec->patch_ops.stream_pm(codec, nid, false); in really_cleanup_stream()
1227 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1233 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1234 snd_array_for_each(&c->cvt_setups, i, p) { in purify_inactive_streams()
1235 if (p->dirty) in purify_inactive_streams()
1243 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1248 snd_array_for_each(&codec->cvt_setups, i, p) { in hda_cleanup_all_streams()
1249 if (p->stream_tag) in hda_cleanup_all_streams()
1250 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1260 * query_amp_caps - query AMP capabilities
1261 * @codec: the HD-auio codec
1271 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1273 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1274 nid = codec->core.afg; in query_amp_caps()
1275 return snd_hda_param_read(codec, nid, in query_amp_caps()
1282 * snd_hda_check_amp_caps - query AMP capabilities
1283 * @codec: the HD-audio codec
1290 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1295 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1296 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1303 * snd_hda_override_amp_caps - Override the AMP capabilities
1304 * @codec: the CODEC to clean up
1315 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1320 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1321 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1323 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1327 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid, in encode_amp() argument
1333 if ((query_amp_caps(codec, nid, dir) & in encode_amp()
1340 * snd_hda_codec_amp_update - update the AMP mono value
1341 * @codec: HD-audio codec
1351 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1354 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_update()
1356 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1361 * snd_hda_codec_amp_stereo - update the AMP stereo values
1362 * @codec: HD-audio codec
1372 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1379 for (ch = 0; ch < 2; ch++) in snd_hda_codec_amp_stereo()
1380 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1387 * snd_hda_codec_amp_init - initialize the AMP value
1388 * @codec: the HDA codec
1400 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1403 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1405 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1406 return -EINVAL; in snd_hda_codec_amp_init()
1407 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val); in snd_hda_codec_amp_init()
1412 * snd_hda_codec_amp_init_stereo - initialize the stereo AMP value
1413 * @codec: the HDA codec
1422 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1429 for (ch = 0; ch < 2; ch++) in snd_hda_codec_amp_init_stereo()
1430 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1436 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1439 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1443 caps -= ofs; in get_amp_max_value()
1448 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1464 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_hda_mixer_amp_volume_info()
1465 uinfo->count = chs == 3 ? 2 : 1; in snd_hda_mixer_amp_volume_info()
1466 uinfo->value.integer.min = 0; in snd_hda_mixer_amp_volume_info()
1467 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1468 if (!uinfo->value.integer.max) { in snd_hda_mixer_amp_volume_info()
1469 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1471 nid, kcontrol->id.name); in snd_hda_mixer_amp_volume_info()
1472 return -EINVAL; in snd_hda_mixer_amp_volume_info()
1480 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1484 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1487 val -= ofs; in read_amp_value()
1494 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1503 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1506 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1511 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1527 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_volume_get()
1530 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1531 if (chs & 2) in snd_hda_mixer_amp_volume_get()
1532 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1538 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1548 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1554 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_volume_put()
1558 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1561 if (chs & 2) in snd_hda_mixer_amp_volume_put()
1562 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in get_ctl_amp_tlv() local
1577 caps = query_amp_caps(codec, nid, dir); in get_ctl_amp_tlv()
1580 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT); in get_ctl_amp_tlv()
1586 tlv[SNDRV_CTL_TLVO_LEN] = 2 * sizeof(unsigned int); in get_ctl_amp_tlv()
1592 * snd_hda_mixer_amp_tlv - TLV callback for a standard AMP mixer volume
1607 return -ENOMEM; in snd_hda_mixer_amp_tlv()
1610 return -EFAULT; in snd_hda_mixer_amp_tlv()
1616 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1617 * @codec: HD-audio codec
1626 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1632 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1637 tlv[SNDRV_CTL_TLVO_LEN] = 2 * sizeof(unsigned int); in snd_hda_set_vmaster_tlv()
1638 tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] = -nums * step; in snd_hda_set_vmaster_tlv()
1645 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1655 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1659 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1660 * @codec: HD-audio codec
1665 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1668 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1672 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1678 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1681 return -EBUSY; in find_empty_mixer_ctl_idx()
1685 * snd_hda_ctl_add - Add a control element and assign to the codec
1686 * @codec: HD-audio codec
1690 * Add the given control element to an array inside the codec instance.
1691 * All control elements belonging to a codec are supposed to be added
1692 * by this function so that a proper clean-up works at the free or
1695 * If non-zero @nid is passed, the NID is assigned to the control element.
1696 * The assignment is shown in the codec proc file.
1701 * specifies if kctl->private_value is a HDA amplifier value.
1703 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1710 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) { in snd_hda_ctl_add()
1713 nid = get_amp_nid_(kctl->private_value); in snd_hda_ctl_add()
1715 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0) in snd_hda_ctl_add()
1716 nid = kctl->id.subdevice & 0xffff; in snd_hda_ctl_add()
1717 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) in snd_hda_ctl_add()
1718 kctl->id.subdevice = 0; in snd_hda_ctl_add()
1719 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1722 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1724 return -ENOMEM; in snd_hda_ctl_add()
1725 item->kctl = kctl; in snd_hda_ctl_add()
1726 item->nid = nid; in snd_hda_ctl_add()
1727 item->flags = flags; in snd_hda_ctl_add()
1733 * snd_hda_add_nid - Assign a NID to a control element
1734 * @codec: HD-audio codec
1739 * Add the given control element to an array inside the codec instance.
1741 * NID:KCTL mapping - for example "Capture Source" selector.
1743 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, in snd_hda_add_nid() argument
1749 item = snd_array_new(&codec->nids); in snd_hda_add_nid()
1751 return -ENOMEM; in snd_hda_add_nid()
1752 item->kctl = kctl; in snd_hda_add_nid()
1753 item->index = index; in snd_hda_add_nid()
1754 item->nid = nid; in snd_hda_add_nid()
1757 codec_err(codec, "no NID for mapping control %s:%d:%d\n", in snd_hda_add_nid()
1758 kctl->id.name, kctl->id.index, index); in snd_hda_add_nid()
1759 return -EINVAL; in snd_hda_add_nid()
1764 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1765 * @codec: HD-audio codec
1767 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1770 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1772 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1773 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1774 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1775 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1779 * snd_hda_lock_devices - pseudo device locking
1782 * toggle card->shutdown to allow/disallow the device access (as a hack)
1786 struct snd_card *card = bus->card; in snd_hda_lock_devices()
1787 struct hda_codec *codec; in snd_hda_lock_devices() local
1789 spin_lock(&card->files_lock); in snd_hda_lock_devices()
1790 if (card->shutdown) in snd_hda_lock_devices()
1792 card->shutdown = 1; in snd_hda_lock_devices()
1793 if (!list_empty(&card->ctl_files)) in snd_hda_lock_devices()
1796 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1798 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1799 if (!cpcm->pcm) in snd_hda_lock_devices()
1801 if (cpcm->pcm->streams[0].substream_opened || in snd_hda_lock_devices()
1802 cpcm->pcm->streams[1].substream_opened) in snd_hda_lock_devices()
1806 spin_unlock(&card->files_lock); in snd_hda_lock_devices()
1810 card->shutdown = 0; in snd_hda_lock_devices()
1812 spin_unlock(&card->files_lock); in snd_hda_lock_devices()
1813 return -EINVAL; in snd_hda_lock_devices()
1818 * snd_hda_unlock_devices - pseudo device unlocking
1823 struct snd_card *card = bus->card; in snd_hda_unlock_devices()
1825 spin_lock(&card->files_lock); in snd_hda_unlock_devices()
1826 card->shutdown = 0; in snd_hda_unlock_devices()
1827 spin_unlock(&card->files_lock); in snd_hda_unlock_devices()
1832 * snd_hda_codec_reset - Clear all objects assigned to the codec
1833 * @codec: HD-audio codec
1835 * This frees the all PCM and control elements assigned to the codec, and
1838 * When a device is being used, it returns -EBSY. If successfully freed,
1841 int snd_hda_codec_reset(struct hda_codec *codec) in snd_hda_codec_reset() argument
1843 struct hda_bus *bus = codec->bus; in snd_hda_codec_reset()
1846 return -EBUSY; in snd_hda_codec_reset()
1849 device_release_driver(hda_codec_dev(codec)); in snd_hda_codec_reset()
1859 static int map_followers(struct hda_codec *codec, const char * const *followers, in map_followers() argument
1866 items = codec->mixers.list; in map_followers()
1867 for (i = 0; i < codec->mixers.used; i++) { in map_followers()
1869 if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER) in map_followers()
1872 char tmpname[sizeof(sctl->id.name)]; in map_followers()
1879 if (!strcmp(sctl->id.name, name)) { in map_followers()
1880 err = func(codec, data, sctl); in map_followers()
1890 static int check_follower_present(struct hda_codec *codec, in check_follower_present() argument
1896 /* call kctl->put with the given value(s) */
1902 return -ENOMEM; in put_kctl_with_value()
1903 ucontrol->value.integer.value[0] = val; in put_kctl_with_value()
1904 ucontrol->value.integer.value[1] = val; in put_kctl_with_value()
1905 kctl->put(kctl, ucontrol); in put_kctl_with_value()
1911 struct hda_codec *codec; member
1926 if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { in init_follower_0dB()
1927 if (kctl->tlv.c != snd_hda_mixer_amp_tlv) { in init_follower_0dB()
1928 codec_err(arg->codec, in init_follower_0dB()
1930 kctl->id.name, kctl->id.index); in init_follower_0dB()
1935 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) in init_follower_0dB()
1936 tlv = kctl->tlv.p; in init_follower_0dB()
1945 if (arg->step && arg->step != step) { in init_follower_0dB()
1946 codec_err(arg->codec, in init_follower_0dB()
1948 arg->step, step); in init_follower_0dB()
1952 arg->step = step; in init_follower_0dB()
1953 val = -tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] / step; in init_follower_0dB()
1970 static int add_follower(struct hda_codec *codec, in add_follower() argument
1977 * __snd_hda_add_vmaster - create a virtual master control and add followers
1978 * @codec: HD-audio codec
1990 * @followers is a NULL-terminated array of strings, each of which is a
1996 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, in __snd_hda_add_vmaster() argument
2007 err = map_followers(codec, followers, suffix, check_follower_present, NULL); in __snd_hda_add_vmaster()
2009 codec_dbg(codec, "No follower found for %s\n", name); in __snd_hda_add_vmaster()
2014 return -ENOMEM; in __snd_hda_add_vmaster()
2015 kctl->vd[0].access |= access; in __snd_hda_add_vmaster()
2016 err = snd_hda_ctl_add(codec, 0, kctl); in __snd_hda_add_vmaster()
2020 err = map_followers(codec, followers, suffix, add_follower, kctl); in __snd_hda_add_vmaster()
2028 .codec = codec, in __snd_hda_add_vmaster()
2047 hook->hook(hook->codec, enabled); in vmaster_hook()
2051 * snd_hda_add_vmaster_hook - Add a vmaster hw specific hook
2052 * @codec: the HDA codec
2057 int snd_hda_add_vmaster_hook(struct hda_codec *codec, in snd_hda_add_vmaster_hook() argument
2060 if (!hook->hook || !hook->sw_kctl) in snd_hda_add_vmaster_hook()
2062 hook->codec = codec; in snd_hda_add_vmaster_hook()
2063 snd_ctl_add_vmaster_hook(hook->sw_kctl, vmaster_hook, hook); in snd_hda_add_vmaster_hook()
2069 * snd_hda_sync_vmaster_hook - Sync vmaster hook
2077 if (!hook->hook || !hook->codec) in snd_hda_sync_vmaster_hook()
2082 if (hook->codec->bus->shutdown) in snd_hda_sync_vmaster_hook()
2084 snd_ctl_sync_vmaster_hook(hook->sw_kctl); in snd_hda_sync_vmaster_hook()
2090 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
2102 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_hda_mixer_amp_switch_info()
2103 uinfo->count = chs == 3 ? 2 : 1; in snd_hda_mixer_amp_switch_info()
2104 uinfo->value.integer.min = 0; in snd_hda_mixer_amp_switch_info()
2105 uinfo->value.integer.max = 1; in snd_hda_mixer_amp_switch_info()
2111 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get() local
2126 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_switch_get()
2129 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & in snd_hda_mixer_amp_switch_get()
2131 if (chs & 2) in snd_hda_mixer_amp_switch_get()
2132 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & in snd_hda_mixer_amp_switch_get()
2139 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put() local
2154 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_switch_put()
2158 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2163 if (chs & 2) in snd_hda_mixer_amp_switch_put()
2164 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2167 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2179 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_hda_spdif_mask_info()
2180 uinfo->count = 1; in snd_hda_spdif_mask_info()
2187 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | in snd_hda_spdif_cmask_get()
2191 ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY | in snd_hda_spdif_cmask_get()
2199 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | in snd_hda_spdif_pmask_get()
2208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2209 int idx = kcontrol->private_value; in snd_hda_spdif_default_get()
2212 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_get()
2213 return -EINVAL; in snd_hda_spdif_default_get()
2214 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2215 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2216 ucontrol->value.iec958.status[0] = spdif->status & 0xff; in snd_hda_spdif_default_get()
2217 ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; in snd_hda_spdif_default_get()
2218 ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; in snd_hda_spdif_default_get()
2219 ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; in snd_hda_spdif_default_get()
2220 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2279 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2284 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2286 d = codec->follower_dig_outs; in set_dig_out()
2290 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2294 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2300 if (dig1 != -1) { in set_dig_out_convert()
2304 if (dig2 != -1) { in set_dig_out_convert()
2308 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2315 int idx = kcontrol->private_value; in snd_hda_spdif_default_put()
2321 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_put()
2322 return -EINVAL; in snd_hda_spdif_default_put()
2323 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2324 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2325 nid = spdif->nid; in snd_hda_spdif_default_put()
2326 spdif->status = ucontrol->value.iec958.status[0] | in snd_hda_spdif_default_put()
2327 ((unsigned int)ucontrol->value.iec958.status[1] << 8) | in snd_hda_spdif_default_put()
2328 ((unsigned int)ucontrol->value.iec958.status[2] << 16) | in snd_hda_spdif_default_put()
2329 ((unsigned int)ucontrol->value.iec958.status[3] << 24); in snd_hda_spdif_default_put()
2330 val = convert_from_spdif_status(spdif->status); in snd_hda_spdif_default_put()
2331 val |= spdif->ctls & 1; in snd_hda_spdif_default_put()
2332 change = spdif->ctls != val; in snd_hda_spdif_default_put()
2333 spdif->ctls = val; in snd_hda_spdif_default_put()
2334 if (change && nid != (u16)-1) in snd_hda_spdif_default_put()
2335 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2336 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2346 int idx = kcontrol->private_value; in snd_hda_spdif_out_switch_get()
2349 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_get()
2350 return -EINVAL; in snd_hda_spdif_out_switch_get()
2351 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2352 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2353 ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; in snd_hda_spdif_out_switch_get()
2354 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2358 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2361 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2363 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2365 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2372 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2373 int idx = kcontrol->private_value; in snd_hda_spdif_out_switch_put()
2379 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_put()
2380 return -EINVAL; in snd_hda_spdif_out_switch_put()
2381 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2382 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2383 nid = spdif->nid; in snd_hda_spdif_out_switch_put()
2384 val = spdif->ctls & ~AC_DIG1_ENABLE; in snd_hda_spdif_out_switch_put()
2385 if (ucontrol->value.integer.value[0]) in snd_hda_spdif_out_switch_put()
2387 change = spdif->ctls != val; in snd_hda_spdif_out_switch_put()
2388 spdif->ctls = val; in snd_hda_spdif_out_switch_put()
2389 if (change && nid != (u16)-1) in snd_hda_spdif_out_switch_put()
2390 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2391 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2428 * snd_hda_create_dig_out_ctls - create Output SPDIF-related controls
2429 * @codec: the HDA codec
2438 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2450 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2452 if (bus->primary_dig_out_type == HDA_PCM_TYPE_HDMI && in snd_hda_create_dig_out_ctls()
2455 } else if (bus->primary_dig_out_type == HDA_PCM_TYPE_SPDIF && in snd_hda_create_dig_out_ctls()
2458 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { in snd_hda_create_dig_out_ctls()
2461 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2464 id = kctl->id; in snd_hda_create_dig_out_ctls()
2466 err = snd_ctl_rename_id(codec->card, &kctl->id, &id); in snd_hda_create_dig_out_ctls()
2470 bus->primary_dig_out_type = HDA_PCM_TYPE_HDMI; in snd_hda_create_dig_out_ctls()
2472 if (!bus->primary_dig_out_type) in snd_hda_create_dig_out_ctls()
2473 bus->primary_dig_out_type = type; in snd_hda_create_dig_out_ctls()
2475 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2477 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2478 return -EBUSY; in snd_hda_create_dig_out_ctls()
2480 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2482 return -ENOMEM; in snd_hda_create_dig_out_ctls()
2483 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { in snd_hda_create_dig_out_ctls()
2484 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2486 return -ENOMEM; in snd_hda_create_dig_out_ctls()
2487 kctl->id.index = idx; in snd_hda_create_dig_out_ctls()
2488 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2489 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2493 spdif->nid = cvt_nid; in snd_hda_create_dig_out_ctls()
2494 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2496 spdif->ctls = val; in snd_hda_create_dig_out_ctls()
2497 spdif->status = convert_to_spdif_status(spdif->ctls); in snd_hda_create_dig_out_ctls()
2503 * snd_hda_spdif_out_of_nid - get the hda_spdif_out entry from the given NID
2504 * @codec: the HDA codec
2509 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2515 snd_array_for_each(&codec->spdif_out, i, spdif) { in snd_hda_spdif_out_of_nid()
2516 if (spdif->nid == nid) in snd_hda_spdif_out_of_nid()
2524 * snd_hda_spdif_ctls_unassign - Unassign the given SPDIF ctl
2525 * @codec: the HDA codec
2530 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2534 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_unassign()
2536 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2537 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2538 spdif->nid = (u16)-1; in snd_hda_spdif_ctls_unassign()
2539 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2544 * snd_hda_spdif_ctls_assign - Assign the SPDIF controls to the given NID
2545 * @codec: the HDA codec
2551 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2556 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_assign()
2558 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2559 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2560 if (spdif->nid != nid) { in snd_hda_spdif_ctls_assign()
2561 spdif->nid = nid; in snd_hda_spdif_ctls_assign()
2562 val = spdif->ctls; in snd_hda_spdif_ctls_assign()
2563 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2565 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2576 ucontrol->value.integer.value[0] = mout->share_spdif; in spdif_share_sw_get()
2584 mout->share_spdif = !!ucontrol->value.integer.value[0]; in spdif_share_sw_put()
2597 * snd_hda_create_spdif_share_sw - create Default PCM switch
2598 * @codec: the HDA codec
2599 * @mout: multi-out instance
2601 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2606 if (!mout->dig_out_nid) in snd_hda_create_spdif_share_sw()
2611 return -ENOMEM; in snd_hda_create_spdif_share_sw()
2612 /* ATTENTION: here mout is passed as private_data, instead of codec */ in snd_hda_create_spdif_share_sw()
2613 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2628 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2636 hda_nid_t nid = kcontrol->private_value; in snd_hda_spdif_in_switch_put()
2637 unsigned int val = !!ucontrol->value.integer.value[0]; in snd_hda_spdif_in_switch_put()
2640 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2641 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2643 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2644 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2647 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2655 hda_nid_t nid = kcontrol->private_value; in snd_hda_spdif_in_status_get()
2659 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2662 ucontrol->value.iec958.status[0] = sbits; in snd_hda_spdif_in_status_get()
2663 ucontrol->value.iec958.status[1] = sbits >> 8; in snd_hda_spdif_in_status_get()
2664 ucontrol->value.iec958.status[2] = sbits >> 16; in snd_hda_spdif_in_status_get()
2665 ucontrol->value.iec958.status[3] = sbits >> 24; in snd_hda_spdif_in_status_get()
2688 * snd_hda_create_spdif_in_ctls - create Input SPDIF-related controls
2689 * @codec: the HDA codec
2697 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2704 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2706 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2707 return -EBUSY; in snd_hda_create_spdif_in_ctls()
2709 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { in snd_hda_create_spdif_in_ctls()
2710 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2712 return -ENOMEM; in snd_hda_create_spdif_in_ctls()
2713 kctl->private_value = nid; in snd_hda_create_spdif_in_ctls()
2714 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2718 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2719 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2727 * snd_hda_codec_set_power_to_all - Set the power state to all widgets
2728 * @codec: the HDA codec
2733 * If the codec has power_filter set, it evaluates the power state and
2736 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, in snd_hda_codec_set_power_to_all() argument
2741 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2742 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
2746 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
2747 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
2751 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
2758 * snd_hda_codec_eapd_power_filter - A power filter callback for EAPD
2759 * @codec: the HDA codec
2764 * This can be used a codec power_filter callback.
2766 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
2770 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
2773 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
2774 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
2775 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
2785 * set power state of the codec, and return the power state
2787 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
2790 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
2795 /* this delay seems necessary to avoid click noise at power-down */ in hda_set_power_state()
2797 if (codec->depop_delay < 0) in hda_set_power_state()
2798 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
2799 else if (codec->depop_delay > 0) in hda_set_power_state()
2800 msleep(codec->depop_delay); in hda_set_power_state()
2806 if (codec->patch_ops.set_power_state) in hda_set_power_state()
2807 codec->patch_ops.set_power_state(codec, fg, in hda_set_power_state()
2811 if (codec->power_filter) in hda_set_power_state()
2812 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
2814 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
2817 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
2819 state = snd_hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
2828 * this is called at the end of codec parsing
2830 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
2835 if (!codec->power_filter) in sync_power_up_states()
2838 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
2839 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
2843 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
2846 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
2847 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
2854 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
2856 if (codec->init_verbs.list) in hda_exec_init_verbs()
2857 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
2860 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
2865 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
2867 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
2870 codec->power_on_acct += delta; in update_power_acct()
2872 codec->power_off_acct += delta; in update_power_acct()
2873 codec->power_jiffies += delta; in update_power_acct()
2876 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
2878 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
2882 * call suspend and power-down; used both from PM and power-save
2885 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
2889 snd_hdac_enter_pm(&codec->core); in hda_call_codec_suspend()
2890 if (codec->patch_ops.suspend) in hda_call_codec_suspend()
2891 codec->patch_ops.suspend(codec); in hda_call_codec_suspend()
2892 if (!codec->no_stream_clean_at_suspend) in hda_call_codec_suspend()
2893 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
2894 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
2895 update_power_acct(codec, true); in hda_call_codec_suspend()
2896 snd_hdac_leave_pm(&codec->core); in hda_call_codec_suspend()
2901 * kick up codec; used both from PM and power-save
2903 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
2905 snd_hdac_enter_pm(&codec->core); in hda_call_codec_resume()
2906 if (codec->core.regmap) in hda_call_codec_resume()
2907 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
2909 codec->power_jiffies = jiffies; in hda_call_codec_resume()
2911 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
2912 restore_shutup_pins(codec); in hda_call_codec_resume()
2913 hda_exec_init_verbs(codec); in hda_call_codec_resume()
2914 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
2915 if (codec->patch_ops.resume) in hda_call_codec_resume()
2916 codec->patch_ops.resume(codec); in hda_call_codec_resume()
2918 if (codec->patch_ops.init) in hda_call_codec_resume()
2919 codec->patch_ops.init(codec); in hda_call_codec_resume()
2920 snd_hda_regmap_sync(codec); in hda_call_codec_resume()
2923 if (codec->jackpoll_interval) in hda_call_codec_resume()
2924 hda_jackpoll_work(&codec->jackpoll_work.work); in hda_call_codec_resume()
2926 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
2927 codec->core.dev.power.power_state = PMSG_ON; in hda_call_codec_resume()
2928 snd_hdac_leave_pm(&codec->core); in hda_call_codec_resume()
2933 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
2937 if (!codec->card) in hda_codec_runtime_suspend()
2940 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_runtime_suspend()
2942 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
2943 if (codec->link_down_at_suspend || in hda_codec_runtime_suspend()
2944 (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
2946 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
2947 snd_hda_codec_display_power(codec, false); in hda_codec_runtime_suspend()
2949 if (codec->bus->jackpoll_in_suspend && in hda_codec_runtime_suspend()
2950 (dev->power.power_state.event != PM_EVENT_SUSPEND)) in hda_codec_runtime_suspend()
2951 schedule_delayed_work(&codec->jackpoll_work, in hda_codec_runtime_suspend()
2952 codec->jackpoll_interval); in hda_codec_runtime_suspend()
2958 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
2961 if (!codec->card) in hda_codec_runtime_resume()
2964 snd_hda_codec_display_power(codec, true); in hda_codec_runtime_resume()
2965 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
2966 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
2976 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_prepare() local
2978 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_prepare()
2979 dev->power.power_state = PMSG_SUSPEND; in hda_codec_pm_prepare()
2985 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_complete() local
2987 /* If no other pm-functions are called between prepare() and complete() */ in hda_codec_pm_complete()
2988 if (dev->power.power_state.event == PM_EVENT_SUSPEND) in hda_codec_pm_complete()
2989 dev->power.power_state = PMSG_RESUME; in hda_codec_pm_complete()
2991 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval || in hda_codec_pm_complete()
2992 hda_codec_need_resume(codec) || codec->forced_resume)) in hda_codec_pm_complete()
2998 dev->power.power_state = PMSG_SUSPEND; in hda_codec_pm_suspend()
3004 dev->power.power_state = PMSG_RESUME; in hda_codec_pm_resume()
3010 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_freeze() local
3012 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_freeze()
3013 dev->power.power_state = PMSG_FREEZE; in hda_codec_pm_freeze()
3019 dev->power.power_state = PMSG_THAW; in hda_codec_pm_thaw()
3025 dev->power.power_state = PMSG_RESTORE; in hda_codec_pm_restore()
3046 /* suspend the codec at shutdown; called from driver's shutdown callback */
3047 void snd_hda_codec_shutdown(struct hda_codec *codec) in snd_hda_codec_shutdown() argument
3051 /* Skip the shutdown if codec is not registered */ in snd_hda_codec_shutdown()
3052 if (!codec->core.registered) in snd_hda_codec_shutdown()
3055 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_shutdown()
3056 list_for_each_entry(cpcm, &codec->pcm_list_head, list) in snd_hda_codec_shutdown()
3057 snd_pcm_suspend_all(cpcm->pcm); in snd_hda_codec_shutdown()
3059 pm_runtime_force_suspend(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3060 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3066 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3071 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3072 for (str = 0; str < 2; str++) { in add_std_chmaps()
3073 struct hda_pcm_stream *hinfo = &pcm->stream[str]; in add_std_chmaps()
3077 if (!pcm->pcm || pcm->own_chmap || !hinfo->substreams) in add_std_chmaps()
3079 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; in add_std_chmaps()
3080 err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem, in add_std_chmaps()
3081 hinfo->channels_max, in add_std_chmaps()
3085 chmap->channel_mask = SND_PCM_CHMAP_MASK_2468; in add_std_chmaps()
3092 * since HD-audio supports only stereo, odd number channels are omitted
3095 { .channels = 2,
3104 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3107 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3109 if (codec->patch_ops.init) in snd_hda_codec_build_controls()
3110 err = codec->patch_ops.init(codec); in snd_hda_codec_build_controls()
3111 if (!err && codec->patch_ops.build_controls) in snd_hda_codec_build_controls()
3112 err = codec->patch_ops.build_controls(codec); in snd_hda_codec_build_controls()
3117 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3121 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3122 hda_jackpoll_work(&codec->jackpoll_work.work); in snd_hda_codec_build_controls()
3124 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3125 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3134 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3141 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3146 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3151 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3154 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3158 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3164 if (info->nid && (!info->rates || !info->formats)) { in set_pcm_default_values()
3165 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3166 info->rates ? NULL : &info->rates, in set_pcm_default_values()
3167 info->formats ? NULL : &info->formats, in set_pcm_default_values()
3168 info->maxbps ? NULL : &info->maxbps); in set_pcm_default_values()
3172 if (info->ops.open == NULL) in set_pcm_default_values()
3173 info->ops.open = hda_pcm_default_open_close; in set_pcm_default_values()
3174 if (info->ops.close == NULL) in set_pcm_default_values()
3175 info->ops.close = hda_pcm_default_open_close; in set_pcm_default_values()
3176 if (info->ops.prepare == NULL) { in set_pcm_default_values()
3177 if (snd_BUG_ON(!info->nid)) in set_pcm_default_values()
3178 return -EINVAL; in set_pcm_default_values()
3179 info->ops.prepare = hda_pcm_default_prepare; in set_pcm_default_values()
3181 if (info->ops.cleanup == NULL) { in set_pcm_default_values()
3182 if (snd_BUG_ON(!info->nid)) in set_pcm_default_values()
3183 return -EINVAL; in set_pcm_default_values()
3184 info->ops.cleanup = hda_pcm_default_cleanup; in set_pcm_default_values()
3190 * codec prepare/cleanup entries
3193 * snd_hda_codec_prepare - Prepare a stream
3194 * @codec: the HDA codec
3200 * Calls the prepare callback set by the codec with the given arguments.
3203 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3210 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3211 if (hinfo->ops.prepare) in snd_hda_codec_prepare()
3212 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3215 ret = -ENODEV; in snd_hda_codec_prepare()
3217 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3218 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3224 * snd_hda_codec_cleanup - Clean up stream resources
3225 * @codec: the HDA codec
3229 * Calls the cleanup callback set by the codec with the given arguments.
3231 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3235 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3236 if (hinfo->ops.cleanup) in snd_hda_codec_cleanup()
3237 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3238 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3257 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 }, in get_empty_pcm_device()
3258 [HDA_PCM_TYPE_SPDIF] = { 1, -1 }, in get_empty_pcm_device()
3259 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 }, in get_empty_pcm_device()
3260 [HDA_PCM_TYPE_MODEM] = { 6, -1 }, in get_empty_pcm_device()
3265 dev_err(bus->card->dev, "Invalid PCM type %d\n", type); in get_empty_pcm_device()
3266 return -EINVAL; in get_empty_pcm_device()
3274 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits)) in get_empty_pcm_device()
3279 /* non-fixed slots starting from 10 */ in get_empty_pcm_device()
3281 if (!test_and_set_bit(i, bus->pcm_dev_bits)) in get_empty_pcm_device()
3286 dev_warn(bus->card->dev, "Too many %s devices\n", in get_empty_pcm_device()
3289 dev_warn(bus->card->dev, in get_empty_pcm_device()
3292 return -EAGAIN; in get_empty_pcm_device()
3295 /* call build_pcms ops of the given codec and set up the default parameters */
3296 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3301 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3304 if (!codec->patch_ops.build_pcms) in snd_hda_codec_parse_pcms()
3307 err = codec->patch_ops.build_pcms(codec); in snd_hda_codec_parse_pcms()
3309 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3310 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3314 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3317 for (stream = 0; stream < 2; stream++) { in snd_hda_codec_parse_pcms()
3318 struct hda_pcm_stream *info = &cpcm->stream[stream]; in snd_hda_codec_parse_pcms()
3320 if (!info->substreams) in snd_hda_codec_parse_pcms()
3322 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3324 codec_warn(codec, in snd_hda_codec_parse_pcms()
3326 cpcm->name); in snd_hda_codec_parse_pcms()
3336 /* assign all PCMs of the given codec */
3337 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3339 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3343 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3348 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3349 if (cpcm->pcm) in snd_hda_codec_build_pcms()
3351 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) in snd_hda_codec_build_pcms()
3354 dev = get_empty_pcm_device(bus, cpcm->pcm_type); in snd_hda_codec_build_pcms()
3356 cpcm->device = SNDRV_PCM_INVALID_DEVICE; in snd_hda_codec_build_pcms()
3359 cpcm->device = dev; in snd_hda_codec_build_pcms()
3360 err = snd_hda_attach_pcm_stream(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3362 codec_err(codec, in snd_hda_codec_build_pcms()
3363 "cannot attach PCM stream %d for codec #%d\n", in snd_hda_codec_build_pcms()
3364 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3373 * snd_hda_add_new_ctls - create controls from the array
3374 * @codec: the HDA codec
3382 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3387 for (; knew->name; knew++) { in snd_hda_add_new_ctls()
3390 if (knew->iface == (__force snd_ctl_elem_iface_t)-1) in snd_hda_add_new_ctls()
3391 continue; /* skip this codec private value */ in snd_hda_add_new_ctls()
3393 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3395 return -ENOMEM; in snd_hda_add_new_ctls()
3401 if (addr > 0 && codec->ctl_dev_id) in snd_hda_add_new_ctls()
3402 kctl->id.device = addr; in snd_hda_add_new_ctls()
3404 kctl->id.index = idx; in snd_hda_add_new_ctls()
3405 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3409 * the codec addr; if it still fails (or it's the in snd_hda_add_new_ctls()
3410 * primary codec), then try another control index in snd_hda_add_new_ctls()
3412 if (!addr && codec->core.addr) { in snd_hda_add_new_ctls()
3413 addr = codec->core.addr; in snd_hda_add_new_ctls()
3414 if (!codec->ctl_dev_id) in snd_hda_add_new_ctls()
3416 } else if (!idx && !knew->index) { in snd_hda_add_new_ctls()
3417 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3418 knew->name, 0); in snd_hda_add_new_ctls()
3431 * snd_hda_codec_set_power_save - Configure codec's runtime PM
3432 * @codec: codec device to configure
3435 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay) in snd_hda_codec_set_power_save() argument
3437 struct device *dev = hda_codec_dev(codec); in snd_hda_codec_set_power_save()
3439 if (delay == 0 && codec->auto_runtime_pm) in snd_hda_codec_set_power_save()
3456 * snd_hda_set_power_save - reprogram autosuspend for the given delay
3457 * @bus: HD-audio bus
3472 * snd_hda_check_amp_list_power - Check the amp list and update the power
3473 * @codec: HD-audio codec
3478 * check the current AMP status, and update the power-status according
3484 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3491 if (!check->amplist) in snd_hda_check_amp_list_power()
3493 for (p = check->amplist; p->nid; p++) { in snd_hda_check_amp_list_power()
3494 if (p->nid == nid) in snd_hda_check_amp_list_power()
3497 if (!p->nid) in snd_hda_check_amp_list_power()
3500 for (p = check->amplist; p->nid; p++) { in snd_hda_check_amp_list_power()
3501 for (ch = 0; ch < 2; ch++) { in snd_hda_check_amp_list_power()
3502 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3503 p->idx); in snd_hda_check_amp_list_power()
3505 if (!check->power_on) { in snd_hda_check_amp_list_power()
3506 check->power_on = 1; in snd_hda_check_amp_list_power()
3507 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3513 if (check->power_on) { in snd_hda_check_amp_list_power()
3514 check->power_on = 0; in snd_hda_check_amp_list_power()
3515 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
3527 * snd_hda_input_mux_info - Info callback helper for the input-mux enum
3536 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; in snd_hda_input_mux_info()
3537 uinfo->count = 1; in snd_hda_input_mux_info()
3538 uinfo->value.enumerated.items = imux->num_items; in snd_hda_input_mux_info()
3539 if (!imux->num_items) in snd_hda_input_mux_info()
3541 index = uinfo->value.enumerated.item; in snd_hda_input_mux_info()
3542 if (index >= imux->num_items) in snd_hda_input_mux_info()
3543 index = imux->num_items - 1; in snd_hda_input_mux_info()
3544 strcpy(uinfo->value.enumerated.name, imux->items[index].label); in snd_hda_input_mux_info()
3550 * snd_hda_input_mux_put - Put callback helper for the input-mux enum
3551 * @codec: the HDA codec
3557 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
3565 if (!imux->num_items) in snd_hda_input_mux_put()
3567 idx = ucontrol->value.enumerated.item[0]; in snd_hda_input_mux_put()
3568 if (idx >= imux->num_items) in snd_hda_input_mux_put()
3569 idx = imux->num_items - 1; in snd_hda_input_mux_put()
3572 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
3573 imux->items[idx].index); in snd_hda_input_mux_put()
3581 * snd_hda_enum_helper_info - Helper for simple enum ctls
3599 num_items = 2; in snd_hda_enum_helper_info()
3608 * Multi-channel / digital-out PCM helper functions
3612 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
3619 spdif = snd_hda_spdif_out_of_nid(codec, nid); in setup_dig_out_stream()
3626 curr_fmt = snd_hda_codec_read(codec, nid, 0, in setup_dig_out_stream()
3628 reset = codec->spdif_status_reset && in setup_dig_out_stream()
3629 (spdif->ctls & AC_DIG1_ENABLE) && in setup_dig_out_stream()
3635 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3636 spdif->ctls & ~AC_DIG1_ENABLE & 0xff, in setup_dig_out_stream()
3637 -1); in setup_dig_out_stream()
3638 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); in setup_dig_out_stream()
3639 if (codec->follower_dig_outs) { in setup_dig_out_stream()
3641 for (d = codec->follower_dig_outs; *d; d++) in setup_dig_out_stream()
3642 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, in setup_dig_out_stream()
3647 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3648 spdif->ctls & 0xff, -1); in setup_dig_out_stream()
3651 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) in cleanup_dig_out_stream() argument
3653 snd_hda_codec_cleanup_stream(codec, nid); in cleanup_dig_out_stream()
3654 if (codec->follower_dig_outs) { in cleanup_dig_out_stream()
3656 for (d = codec->follower_dig_outs; *d; d++) in cleanup_dig_out_stream()
3657 snd_hda_codec_cleanup_stream(codec, *d); in cleanup_dig_out_stream()
3662 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3663 * @codec: the HDA codec
3666 int snd_hda_multi_out_dig_open(struct hda_codec *codec, in snd_hda_multi_out_dig_open() argument
3669 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3670 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) in snd_hda_multi_out_dig_open()
3672 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_open()
3673 mout->dig_out_used = HDA_DIG_EXCLUSIVE; in snd_hda_multi_out_dig_open()
3674 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3680 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3681 * @codec: the HDA codec
3687 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
3693 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3694 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
3695 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3701 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3702 * @codec: the HDA codec
3705 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
3708 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3709 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
3710 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3716 * snd_hda_multi_out_dig_close - release the digital out stream
3717 * @codec: the HDA codec
3720 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
3723 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3724 mout->dig_out_used = 0; in snd_hda_multi_out_dig_close()
3725 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3731 * snd_hda_multi_out_analog_open - open analog outputs
3732 * @codec: the HDA codec
3737 * Open analog outputs and set up the hw-constraints.
3741 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
3746 struct snd_pcm_runtime *runtime = substream->runtime; in snd_hda_multi_out_analog_open()
3747 runtime->hw.channels_max = mout->max_channels; in snd_hda_multi_out_analog_open()
3748 if (mout->dig_out_nid) { in snd_hda_multi_out_analog_open()
3749 if (!mout->analog_rates) { in snd_hda_multi_out_analog_open()
3750 mout->analog_rates = hinfo->rates; in snd_hda_multi_out_analog_open()
3751 mout->analog_formats = hinfo->formats; in snd_hda_multi_out_analog_open()
3752 mout->analog_maxbps = hinfo->maxbps; in snd_hda_multi_out_analog_open()
3754 runtime->hw.rates = mout->analog_rates; in snd_hda_multi_out_analog_open()
3755 runtime->hw.formats = mout->analog_formats; in snd_hda_multi_out_analog_open()
3756 hinfo->maxbps = mout->analog_maxbps; in snd_hda_multi_out_analog_open()
3758 if (!mout->spdif_rates) { in snd_hda_multi_out_analog_open()
3759 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
3760 &mout->spdif_rates, in snd_hda_multi_out_analog_open()
3761 &mout->spdif_formats, in snd_hda_multi_out_analog_open()
3762 &mout->spdif_maxbps); in snd_hda_multi_out_analog_open()
3764 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3765 if (mout->share_spdif) { in snd_hda_multi_out_analog_open()
3766 if ((runtime->hw.rates & mout->spdif_rates) && in snd_hda_multi_out_analog_open()
3767 (runtime->hw.formats & mout->spdif_formats)) { in snd_hda_multi_out_analog_open()
3768 runtime->hw.rates &= mout->spdif_rates; in snd_hda_multi_out_analog_open()
3769 runtime->hw.formats &= mout->spdif_formats; in snd_hda_multi_out_analog_open()
3770 if (mout->spdif_maxbps < hinfo->maxbps) in snd_hda_multi_out_analog_open()
3771 hinfo->maxbps = mout->spdif_maxbps; in snd_hda_multi_out_analog_open()
3773 mout->share_spdif = 0; in snd_hda_multi_out_analog_open()
3777 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3779 return snd_pcm_hw_constraint_step(substream->runtime, 0, in snd_hda_multi_out_analog_open()
3780 SNDRV_PCM_HW_PARAM_CHANNELS, 2); in snd_hda_multi_out_analog_open()
3785 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
3786 * @codec: the HDA codec
3795 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
3801 const hda_nid_t *nids = mout->dac_nids; in snd_hda_multi_out_analog_prepare()
3802 int chs = substream->runtime->channels; in snd_hda_multi_out_analog_prepare()
3806 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3807 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3808 if (mout->dig_out_nid && mout->share_spdif && in snd_hda_multi_out_analog_prepare()
3809 mout->dig_out_used != HDA_DIG_EXCLUSIVE) { in snd_hda_multi_out_analog_prepare()
3810 if (chs == 2 && spdif != NULL && in snd_hda_multi_out_analog_prepare()
3811 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3813 !(spdif->status & IEC958_AES0_NONAUDIO)) { in snd_hda_multi_out_analog_prepare()
3814 mout->dig_out_used = HDA_DIG_ANALOG_DUP; in snd_hda_multi_out_analog_prepare()
3815 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3818 mout->dig_out_used = 0; in snd_hda_multi_out_analog_prepare()
3819 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3822 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3825 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
3827 if (!mout->no_share_stream && in snd_hda_multi_out_analog_prepare()
3828 mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) in snd_hda_multi_out_analog_prepare()
3830 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
3833 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++) in snd_hda_multi_out_analog_prepare()
3834 if (!mout->no_share_stream && mout->hp_out_nid[i]) in snd_hda_multi_out_analog_prepare()
3835 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
3836 mout->hp_out_nid[i], in snd_hda_multi_out_analog_prepare()
3840 for (i = 1; i < mout->num_dacs; i++) { in snd_hda_multi_out_analog_prepare()
3841 if (chs >= (i + 1) * 2) /* independent out */ in snd_hda_multi_out_analog_prepare()
3842 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3843 i * 2, format); in snd_hda_multi_out_analog_prepare()
3844 else if (!mout->no_share_stream) /* copy front */ in snd_hda_multi_out_analog_prepare()
3845 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3850 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) { in snd_hda_multi_out_analog_prepare()
3852 if (!mout->extra_out_nid[i]) in snd_hda_multi_out_analog_prepare()
3854 if (chs >= (i + 1) * 2) in snd_hda_multi_out_analog_prepare()
3855 ch = i * 2; in snd_hda_multi_out_analog_prepare()
3856 else if (!mout->no_share_stream) in snd_hda_multi_out_analog_prepare()
3858 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
3867 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3868 * @codec: the HDA codec
3871 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
3874 const hda_nid_t *nids = mout->dac_nids; in snd_hda_multi_out_analog_cleanup()
3877 for (i = 0; i < mout->num_dacs; i++) in snd_hda_multi_out_analog_cleanup()
3878 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
3879 if (mout->hp_nid) in snd_hda_multi_out_analog_cleanup()
3880 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
3881 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++) in snd_hda_multi_out_analog_cleanup()
3882 if (mout->hp_out_nid[i]) in snd_hda_multi_out_analog_cleanup()
3883 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3884 mout->hp_out_nid[i]); in snd_hda_multi_out_analog_cleanup()
3885 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) in snd_hda_multi_out_analog_cleanup()
3886 if (mout->extra_out_nid[i]) in snd_hda_multi_out_analog_cleanup()
3887 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3888 mout->extra_out_nid[i]); in snd_hda_multi_out_analog_cleanup()
3889 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3890 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { in snd_hda_multi_out_analog_cleanup()
3891 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
3892 mout->dig_out_used = 0; in snd_hda_multi_out_analog_cleanup()
3894 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3900 * snd_hda_get_default_vref - Get the default (mic) VREF pin bits
3901 * @codec: the HDA codec
3904 * Guess the suitable VREF pin bits to be set as the pin-control value.
3907 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
3911 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
3913 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
3929 * snd_hda_correct_pin_ctl - correct the pin ctl value for matching with the pin cap
3930 * @codec: the HDA codec
3934 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
3937 static const unsigned int cap_lists[][2] = { in snd_hda_correct_pin_ctl()
3947 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
3969 if (i == ARRAY_SIZE(cap_lists) - 1) in snd_hda_correct_pin_ctl()
3985 * _snd_hda_set_pin_ctl - Helper to set pin ctl value
3986 * @codec: the HDA codec
3989 * @cached: access over codec pinctl cache or direct write
3997 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
4000 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
4001 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
4003 return snd_hda_codec_write_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
4006 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
4012 * snd_hda_add_imux_item - Add an item to input_mux
4013 * @codec: the HDA codec
4021 * to type_idx when non-NULL pointer is given.
4023 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
4028 if (imux->num_items >= HDA_MAX_NUM_INPUTS) { in snd_hda_add_imux_item()
4029 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
4030 return -EINVAL; in snd_hda_add_imux_item()
4032 for (i = 0; i < imux->num_items; i++) { in snd_hda_add_imux_item()
4033 if (!strncmp(label, imux->items[i].label, strlen(label))) in snd_hda_add_imux_item()
4039 snprintf(imux->items[imux->num_items].label, in snd_hda_add_imux_item()
4040 sizeof(imux->items[imux->num_items].label), in snd_hda_add_imux_item()
4043 strscpy(imux->items[imux->num_items].label, label, in snd_hda_add_imux_item()
4044 sizeof(imux->items[imux->num_items].label)); in snd_hda_add_imux_item()
4045 imux->items[imux->num_items].index = index; in snd_hda_add_imux_item()
4046 imux->num_items++; in snd_hda_add_imux_item()
4052 * snd_hda_bus_reset_codecs - Reset the bus
4053 * @bus: HD-audio bus
4057 struct hda_codec *codec; in snd_hda_bus_reset_codecs() local
4059 list_for_each_codec(codec, bus) { in snd_hda_bus_reset_codecs()
4061 if (current_work() != &codec->jackpoll_work.work) in snd_hda_bus_reset_codecs()
4062 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset_codecs()
4064 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset_codecs()
4065 hda_call_codec_suspend(codec); in snd_hda_bus_reset_codecs()
4066 hda_call_codec_resume(codec); in snd_hda_bus_reset_codecs()
4073 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4087 j += scnprintf(buf + j, buflen - j, " %d", bits[i]); in snd_print_pcm_bits()
4093 MODULE_DESCRIPTION("HDA codec core");