Lines Matching refs:codec
43 #define codec_in_pm(codec) atomic_read(&(codec)->core.in_pm) argument
44 #define hda_codec_is_power_on(codec) \ argument
45 (!pm_runtime_suspended(hda_codec_dev(codec)))
47 #define codec_in_pm(codec) 0 argument
48 #define hda_codec_is_power_on(codec) 1 argument
51 #define codec_has_epss(codec) \ argument
52 ((codec)->core.power_caps & AC_PWRST_EPSS)
53 #define codec_has_clkstop(codec) \ argument
54 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
62 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in codec_exec_verb() local
63 struct hda_bus *bus = codec->bus; in codec_exec_verb()
70 snd_hda_power_up_pm(codec); in codec_exec_verb()
74 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, in codec_exec_verb()
78 snd_hda_power_down_pm(codec); in codec_exec_verb()
79 if (!codec_in_pm(codec) && res && err == -EAGAIN) { in codec_exec_verb()
81 codec_dbg(codec, in codec_exec_verb()
88 if (!err || codec_in_pm(codec)) in codec_exec_verb()
101 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
104 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); in snd_hda_sequence_write()
118 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) in lookup_conn_list() argument
121 list_for_each_entry(p, &codec->conn_list, list) { in lookup_conn_list()
128 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in add_conn_list() argument
139 list_add(&p->list, &codec->conn_list); in add_conn_list()
143 static void remove_conn_list(struct hda_codec *codec) in remove_conn_list() argument
145 while (!list_empty(&codec->conn_list)) { in remove_conn_list()
147 p = list_first_entry(&codec->conn_list, typeof(*p), list); in remove_conn_list()
154 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) in read_and_add_raw_conns() argument
160 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); in read_and_add_raw_conns()
162 len = snd_hda_get_num_raw_conns(codec, nid); in read_and_add_raw_conns()
166 len = snd_hda_get_raw_connections(codec, nid, result, len); in read_and_add_raw_conns()
169 len = snd_hda_override_conn_list(codec, nid, len, result); in read_and_add_raw_conns()
190 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
200 p = lookup_conn_list(codec, nid); in snd_hda_get_conn_list()
209 err = read_and_add_raw_conns(codec, nid); in snd_hda_get_conn_list()
229 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_connections() argument
233 int len = snd_hda_get_conn_list(codec, nid, &list); in snd_hda_get_connections()
237 codec_err(codec, "Too many connections %d for NID 0x%x\n", in snd_hda_get_connections()
260 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in snd_hda_override_conn_list() argument
265 p = lookup_conn_list(codec, nid); in snd_hda_override_conn_list()
271 return add_conn_list(codec, nid, len, list); in snd_hda_override_conn_list()
286 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, in snd_hda_get_conn_index() argument
292 nums = snd_hda_get_conn_list(codec, mux, &conn); in snd_hda_get_conn_index()
299 codec_dbg(codec, "too deep connection for 0x%x\n", nid); in snd_hda_get_conn_index()
304 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i])); in snd_hda_get_conn_index()
307 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) in snd_hda_get_conn_index()
316 static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid) in get_num_devices() argument
318 unsigned int wcaps = get_wcaps(codec, nid); in get_num_devices()
321 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || in get_num_devices()
325 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN); in get_num_devices()
341 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_devices() argument
347 parm = get_num_devices(codec, nid); in snd_hda_get_devices()
356 if (snd_hdac_read(&codec->core, nid, in snd_hda_get_devices()
374 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) in read_widget_caps() argument
379 codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL); in read_widget_caps()
380 if (!codec->wcaps) in read_widget_caps()
382 nid = codec->core.start_nid; in read_widget_caps()
383 for (i = 0; i < codec->core.num_nodes; i++, nid++) in read_widget_caps()
384 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, in read_widget_caps()
390 static int read_pin_defaults(struct hda_codec *codec) in read_pin_defaults() argument
394 for_each_hda_codec_node(nid, codec) { in read_pin_defaults()
396 unsigned int wcaps = get_wcaps(codec, nid); in read_pin_defaults()
400 pin = snd_array_new(&codec->init_pins); in read_pin_defaults()
404 pin->cfg = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
406 pin->ctrl = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
414 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, in look_up_pincfg() argument
430 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
444 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
465 int snd_hda_codec_set_pincfg(struct hda_codec *codec, in snd_hda_codec_set_pincfg() argument
468 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); in snd_hda_codec_set_pincfg()
481 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pincfg() argument
488 mutex_lock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
489 pin = look_up_pincfg(codec, &codec->user_pins, nid); in snd_hda_codec_get_pincfg()
492 mutex_unlock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
497 pin = look_up_pincfg(codec, &codec->driver_pins, nid); in snd_hda_codec_get_pincfg()
500 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pincfg()
517 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_set_pin_target() argument
522 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_set_pin_target()
535 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pin_target() argument
539 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pin_target()
553 void snd_hda_shutup_pins(struct hda_codec *codec) in snd_hda_shutup_pins() argument
559 if (codec->bus->shutdown) in snd_hda_shutup_pins()
561 for (i = 0; i < codec->init_pins.used; i++) { in snd_hda_shutup_pins()
562 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); in snd_hda_shutup_pins()
564 snd_hda_codec_read(codec, pin->nid, 0, in snd_hda_shutup_pins()
567 codec->pins_shutup = 1; in snd_hda_shutup_pins()
573 static void restore_shutup_pins(struct hda_codec *codec) in restore_shutup_pins() argument
576 if (!codec->pins_shutup) in restore_shutup_pins()
578 if (codec->bus->shutdown) in restore_shutup_pins()
580 for (i = 0; i < codec->init_pins.used; i++) { in restore_shutup_pins()
581 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); in restore_shutup_pins()
582 snd_hda_codec_write(codec, pin->nid, 0, in restore_shutup_pins()
586 codec->pins_shutup = 0; in restore_shutup_pins()
592 struct hda_codec *codec = in hda_jackpoll_work() local
595 snd_hda_jack_set_dirty_all(codec); in hda_jackpoll_work()
596 snd_hda_jack_poll_all(codec); in hda_jackpoll_work()
598 if (!codec->jackpoll_interval) in hda_jackpoll_work()
601 schedule_delayed_work(&codec->jackpoll_work, in hda_jackpoll_work()
602 codec->jackpoll_interval); in hda_jackpoll_work()
606 static void free_init_pincfgs(struct hda_codec *codec) in free_init_pincfgs() argument
608 snd_array_free(&codec->driver_pins); in free_init_pincfgs()
610 snd_array_free(&codec->user_pins); in free_init_pincfgs()
612 snd_array_free(&codec->init_pins); in free_init_pincfgs()
629 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) in get_hda_cvt_setup() argument
634 for (i = 0; i < codec->cvt_setups.used; i++) { in get_hda_cvt_setup()
635 p = snd_array_elem(&codec->cvt_setups, i); in get_hda_cvt_setup()
639 p = snd_array_new(&codec->cvt_setups); in get_hda_cvt_setup()
653 snd_device_free(pcm->codec->card, pcm->pcm); in release_pcm()
654 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); in release_pcm()
665 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, in snd_hda_codec_pcm_new() argument
675 pcm->codec = codec; in snd_hda_codec_pcm_new()
685 list_add_tail(&pcm->list, &codec->pcm_list_head); in snd_hda_codec_pcm_new()
693 static void codec_release_pcms(struct hda_codec *codec) in codec_release_pcms() argument
697 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { in codec_release_pcms()
700 snd_device_disconnect(codec->card, pcm->pcm); in codec_release_pcms()
705 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) in snd_hda_codec_cleanup_for_unbind() argument
707 if (codec->registered) { in snd_hda_codec_cleanup_for_unbind()
709 pm_runtime_get_noresume(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
710 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
711 codec->registered = 0; in snd_hda_codec_cleanup_for_unbind()
714 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_cleanup_for_unbind()
715 if (!codec->in_freeing) in snd_hda_codec_cleanup_for_unbind()
716 snd_hda_ctls_clear(codec); in snd_hda_codec_cleanup_for_unbind()
717 codec_release_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
718 snd_hda_detach_beep_device(codec); in snd_hda_codec_cleanup_for_unbind()
719 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); in snd_hda_codec_cleanup_for_unbind()
720 snd_hda_jack_tbl_clear(codec); in snd_hda_codec_cleanup_for_unbind()
721 codec->proc_widget_hook = NULL; in snd_hda_codec_cleanup_for_unbind()
722 codec->spec = NULL; in snd_hda_codec_cleanup_for_unbind()
725 snd_array_free(&codec->driver_pins); in snd_hda_codec_cleanup_for_unbind()
726 snd_array_free(&codec->cvt_setups); in snd_hda_codec_cleanup_for_unbind()
727 snd_array_free(&codec->spdif_out); in snd_hda_codec_cleanup_for_unbind()
728 snd_array_free(&codec->verbs); in snd_hda_codec_cleanup_for_unbind()
729 codec->preset = NULL; in snd_hda_codec_cleanup_for_unbind()
730 codec->slave_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
731 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
732 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
733 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
734 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
735 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
738 static unsigned int hda_set_power_state(struct hda_codec *codec,
742 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
744 if (codec->registered) in snd_hda_codec_register()
746 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
747 snd_hda_register_beep_device(codec); in snd_hda_codec_register()
748 snd_hdac_link_power(&codec->core, true); in snd_hda_codec_register()
749 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
751 snd_hda_power_down(codec); in snd_hda_codec_register()
752 codec->registered = 1; in snd_hda_codec_register()
764 struct hda_codec *codec = device->device_data; in snd_hda_codec_dev_disconnect() local
766 snd_hda_detach_beep_device(codec); in snd_hda_codec_dev_disconnect()
772 struct hda_codec *codec = device->device_data; in snd_hda_codec_dev_free() local
774 codec->in_freeing = 1; in snd_hda_codec_dev_free()
775 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_dev_free()
776 snd_hdac_link_power(&codec->core, false); in snd_hda_codec_dev_free()
777 put_device(hda_codec_dev(codec)); in snd_hda_codec_dev_free()
783 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
785 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
786 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
787 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
788 kfree(codec->modelname); in snd_hda_codec_dev_release()
789 kfree(codec->wcaps); in snd_hda_codec_dev_release()
790 kfree(codec); in snd_hda_codec_dev_release()
804 struct hda_codec *codec; in snd_hda_codec_new() local
819 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_hda_codec_new()
820 if (!codec) in snd_hda_codec_new()
824 err = snd_hdac_device_init(&codec->core, &bus->core, component, in snd_hda_codec_new()
827 kfree(codec); in snd_hda_codec_new()
831 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_new()
832 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_new()
833 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_new()
835 codec->bus = bus; in snd_hda_codec_new()
836 codec->card = card; in snd_hda_codec_new()
837 codec->addr = codec_addr; in snd_hda_codec_new()
838 mutex_init(&codec->spdif_mutex); in snd_hda_codec_new()
839 mutex_init(&codec->control_mutex); in snd_hda_codec_new()
840 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_new()
841 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_new()
842 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_new()
843 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_new()
844 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_new()
845 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_new()
846 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_new()
847 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_new()
848 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_new()
849 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_new()
851 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_new()
852 codec->depop_delay = -1; in snd_hda_codec_new()
853 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_new()
856 codec->power_jiffies = jiffies; in snd_hda_codec_new()
859 snd_hda_sysfs_init(codec); in snd_hda_codec_new()
861 if (codec->bus->modelname) { in snd_hda_codec_new()
862 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_new()
863 if (!codec->modelname) { in snd_hda_codec_new()
869 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_new()
870 err = read_widget_caps(codec, fg); in snd_hda_codec_new()
873 err = read_pin_defaults(codec); in snd_hda_codec_new()
878 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_new()
880 snd_hda_codec_proc_new(codec); in snd_hda_codec_new()
882 snd_hda_create_hwdep(codec); in snd_hda_codec_new()
884 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_new()
885 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_new()
888 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_new()
893 *codecp = codec; in snd_hda_codec_new()
897 put_device(hda_codec_dev(codec)); in snd_hda_codec_new()
909 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
914 err = snd_hdac_refresh_widget_sysfs(&codec->core); in snd_hda_codec_update_widgets()
921 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
922 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
923 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
927 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
928 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
935 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
942 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
945 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
954 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
960 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
964 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
980 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
992 codec_dbg(codec, in snd_hda_codec_setup_stream()
995 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
999 if (codec->patch_ops.stream_pm) in snd_hda_codec_setup_stream()
1000 codec->patch_ops.stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1001 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1002 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1003 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1004 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1005 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1011 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1012 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1023 static void really_cleanup_stream(struct hda_codec *codec,
1032 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1040 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1043 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1044 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1051 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1058 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1063 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1065 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1069 if (codec->patch_ops.stream_pm) in really_cleanup_stream()
1070 codec->patch_ops.stream_pm(codec, nid, false); in really_cleanup_stream()
1074 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1079 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1091 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1095 for (i = 0; i < codec->cvt_setups.used; i++) { in hda_cleanup_all_streams()
1096 struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); in hda_cleanup_all_streams()
1098 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1119 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1121 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1122 nid = codec->core.afg; in query_amp_caps()
1123 return snd_hda_param_read(codec, nid, in query_amp_caps()
1138 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1143 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1144 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1163 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1168 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1169 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1171 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1187 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1193 if ((query_amp_caps(codec, nid, dir) & in snd_hda_codec_amp_update()
1196 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1212 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1220 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1240 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1245 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1247 regcache_cache_only(codec->core.regmap, true); in snd_hda_codec_amp_init()
1248 orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1249 regcache_cache_only(codec->core.regmap, false); in snd_hda_codec_amp_init()
1252 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val); in snd_hda_codec_amp_init()
1267 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1275 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1281 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1284 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1312 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1314 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1325 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1329 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1339 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1348 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1351 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1375 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1377 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1393 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1403 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1407 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_tlv() local
1434 caps = query_amp_caps(codec, nid, dir); in snd_hda_mixer_amp_tlv()
1465 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1471 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1484 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1494 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1504 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1507 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1511 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1517 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1542 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1558 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1561 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1582 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, in snd_hda_add_nid() argument
1588 item = snd_array_new(&codec->nids); in snd_hda_add_nid()
1596 codec_err(codec, "no NID for mapping control %s:%d:%d\n", in snd_hda_add_nid()
1606 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1609 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1610 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1611 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1612 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1613 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1625 struct hda_codec *codec; in snd_hda_lock_devices() local
1634 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1636 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1679 int snd_hda_codec_reset(struct hda_codec *codec) in snd_hda_codec_reset() argument
1681 struct hda_bus *bus = codec->bus; in snd_hda_codec_reset()
1687 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_reset()
1697 static int map_slaves(struct hda_codec *codec, const char * const *slaves, in map_slaves() argument
1704 items = codec->mixers.list; in map_slaves()
1705 for (i = 0; i < codec->mixers.used; i++) { in map_slaves()
1718 err = func(codec, data, sctl); in map_slaves()
1728 static int check_slave_present(struct hda_codec *codec, in check_slave_present() argument
1735 static int get_kctl_0dB_offset(struct hda_codec *codec, in get_kctl_0dB_offset() argument
1757 codec_err(codec, "Mismatching dB step for vmaster slave (%d!=%d)\n", in get_kctl_0dB_offset()
1782 static int init_slave_0dB(struct hda_codec *codec, in init_slave_0dB() argument
1785 int offset = get_kctl_0dB_offset(codec, slave, data); in init_slave_0dB()
1792 static int init_slave_unmute(struct hda_codec *codec, in init_slave_unmute() argument
1798 static int add_slave(struct hda_codec *codec, in add_slave() argument
1823 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, in __snd_hda_add_vmaster() argument
1834 err = map_slaves(codec, slaves, suffix, check_slave_present, NULL); in __snd_hda_add_vmaster()
1836 codec_dbg(codec, "No slave found for %s\n", name); in __snd_hda_add_vmaster()
1842 err = snd_hda_ctl_add(codec, 0, kctl); in __snd_hda_add_vmaster()
1846 err = map_slaves(codec, slaves, suffix, add_slave, kctl); in __snd_hda_add_vmaster()
1854 map_slaves(codec, slaves, suffix, in __snd_hda_add_vmaster()
1915 hook->hook(hook->codec, enabled); in vmaster_hook()
1928 int snd_hda_add_vmaster_hook(struct hda_codec *codec, in snd_hda_add_vmaster_hook() argument
1936 hook->codec = codec; in snd_hda_add_vmaster_hook()
1944 return snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_vmaster_hook()
1957 if (!hook->hook || !hook->codec) in snd_hda_sync_vmaster_hook()
1962 if (hook->codec->bus->shutdown) in snd_hda_sync_vmaster_hook()
2001 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get() local
2009 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & in snd_hda_mixer_amp_switch_get()
2012 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & in snd_hda_mixer_amp_switch_get()
2029 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put() local
2038 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2044 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2047 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_switch_get() local
2076 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_switch_get()
2081 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_switch_get()
2097 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_switch_put() local
2101 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_switch_put()
2113 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_switch_put()
2129 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_info() local
2133 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_info()
2138 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_info()
2154 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_get() local
2158 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_get()
2163 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_get()
2179 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_put() local
2184 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_put()
2194 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_put()
2212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_tlv() local
2216 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_tlv()
2221 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_tlv()
2278 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2282 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2283 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2288 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2347 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2352 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2354 d = codec->slave_dig_outs; in set_dig_out()
2358 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2362 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2376 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2389 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2390 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2401 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2402 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2415 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2416 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2418 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2422 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2425 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2427 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2429 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2443 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2444 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2452 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2453 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2500 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2512 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2521 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2531 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2533 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2536 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2540 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2544 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2545 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2550 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2565 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2569 for (i = 0; i < codec->spdif_out.used; i++) { in snd_hda_spdif_out_of_nid()
2571 snd_array_elem(&codec->spdif_out, i); in snd_hda_spdif_out_of_nid()
2586 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2590 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2591 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2593 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2605 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2610 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2611 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2615 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2617 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2653 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2665 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2680 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2692 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2693 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2695 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2696 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2699 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2706 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2711 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2749 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2756 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2758 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2762 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2766 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2770 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2771 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2788 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
2793 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2794 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
2798 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
2799 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
2803 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
2812 static unsigned int hda_sync_power_state(struct hda_codec *codec, in hda_sync_power_state() argument
2820 state = snd_hda_codec_read(codec, fg, 0, in hda_sync_power_state()
2844 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
2848 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
2851 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
2852 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
2853 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
2865 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
2868 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
2875 if (codec->depop_delay < 0) in hda_set_power_state()
2876 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
2877 else if (codec->depop_delay > 0) in hda_set_power_state()
2878 msleep(codec->depop_delay); in hda_set_power_state()
2884 if (codec->patch_ops.set_power_state) in hda_set_power_state()
2885 codec->patch_ops.set_power_state(codec, fg, in hda_set_power_state()
2889 if (codec->power_filter) in hda_set_power_state()
2890 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
2892 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
2895 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
2897 state = hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
2908 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
2913 if (!codec->power_filter) in sync_power_up_states()
2916 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
2917 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
2921 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
2924 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
2925 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
2932 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
2934 if (codec->init_verbs.list) in hda_exec_init_verbs()
2935 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
2938 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
2943 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
2945 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
2948 codec->power_on_acct += delta; in update_power_acct()
2950 codec->power_off_acct += delta; in update_power_acct()
2951 codec->power_jiffies += delta; in update_power_acct()
2954 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
2956 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
2963 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
2967 atomic_inc(&codec->core.in_pm); in hda_call_codec_suspend()
2969 if (codec->patch_ops.suspend) in hda_call_codec_suspend()
2970 codec->patch_ops.suspend(codec); in hda_call_codec_suspend()
2971 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
2972 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
2973 update_power_acct(codec, true); in hda_call_codec_suspend()
2974 atomic_dec(&codec->core.in_pm); in hda_call_codec_suspend()
2981 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
2983 atomic_inc(&codec->core.in_pm); in hda_call_codec_resume()
2985 if (codec->core.regmap) in hda_call_codec_resume()
2986 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
2988 codec->power_jiffies = jiffies; in hda_call_codec_resume()
2990 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
2991 restore_shutup_pins(codec); in hda_call_codec_resume()
2992 hda_exec_init_verbs(codec); in hda_call_codec_resume()
2993 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
2994 if (codec->patch_ops.resume) in hda_call_codec_resume()
2995 codec->patch_ops.resume(codec); in hda_call_codec_resume()
2997 if (codec->patch_ops.init) in hda_call_codec_resume()
2998 codec->patch_ops.init(codec); in hda_call_codec_resume()
2999 if (codec->core.regmap) in hda_call_codec_resume()
3000 regcache_sync(codec->core.regmap); in hda_call_codec_resume()
3003 if (codec->jackpoll_interval) in hda_call_codec_resume()
3004 hda_jackpoll_work(&codec->jackpoll_work.work); in hda_call_codec_resume()
3006 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
3007 atomic_dec(&codec->core.in_pm); in hda_call_codec_resume()
3012 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
3016 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_runtime_suspend()
3017 list_for_each_entry(pcm, &codec->pcm_list_head, list) in hda_codec_runtime_suspend()
3019 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
3020 if (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
3022 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
3023 snd_hdac_link_power(&codec->core, false); in hda_codec_runtime_suspend()
3029 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
3031 snd_hdac_link_power(&codec->core, true); in hda_codec_runtime_resume()
3032 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
3033 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
3050 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3055 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3088 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3091 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3093 if (codec->patch_ops.init) in snd_hda_codec_build_controls()
3094 err = codec->patch_ops.init(codec); in snd_hda_codec_build_controls()
3095 if (!err && codec->patch_ops.build_controls) in snd_hda_codec_build_controls()
3096 err = codec->patch_ops.build_controls(codec); in snd_hda_codec_build_controls()
3101 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3105 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3106 hda_jackpoll_work(&codec->jackpoll_work.work); in snd_hda_codec_build_controls()
3108 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3109 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3117 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3124 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3129 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3134 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3137 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3141 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3148 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3186 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3193 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3195 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3200 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3201 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3214 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3218 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3220 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3221 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3279 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3284 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3287 if (!codec->patch_ops.build_pcms) in snd_hda_codec_parse_pcms()
3290 err = codec->patch_ops.build_pcms(codec); in snd_hda_codec_parse_pcms()
3292 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3293 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3297 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3305 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3307 codec_warn(codec, in snd_hda_codec_parse_pcms()
3319 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3321 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3325 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3330 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3340 err = snd_hda_attach_pcm_stream(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3342 codec_err(codec, in snd_hda_codec_build_pcms()
3344 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3362 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3373 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3380 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3387 if (!addr && codec->core.addr) in snd_hda_add_new_ctls()
3388 addr = codec->core.addr; in snd_hda_add_new_ctls()
3390 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3403 static void codec_set_power_save(struct hda_codec *codec, int delay) in codec_set_power_save() argument
3405 struct device *dev = hda_codec_dev(codec); in codec_set_power_save()
3407 if (delay == 0 && codec->auto_runtime_pm) in codec_set_power_save()
3451 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3469 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3474 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3482 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
3524 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
3539 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
3579 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
3586 spdif = snd_hda_spdif_out_of_nid(codec, nid); in setup_dig_out_stream()
3587 curr_fmt = snd_hda_codec_read(codec, nid, 0, in setup_dig_out_stream()
3589 reset = codec->spdif_status_reset && in setup_dig_out_stream()
3596 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3599 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); in setup_dig_out_stream()
3600 if (codec->slave_dig_outs) { in setup_dig_out_stream()
3602 for (d = codec->slave_dig_outs; *d; d++) in setup_dig_out_stream()
3603 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, in setup_dig_out_stream()
3608 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3612 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) in cleanup_dig_out_stream() argument
3614 snd_hda_codec_cleanup_stream(codec, nid); in cleanup_dig_out_stream()
3615 if (codec->slave_dig_outs) { in cleanup_dig_out_stream()
3617 for (d = codec->slave_dig_outs; *d; d++) in cleanup_dig_out_stream()
3618 snd_hda_codec_cleanup_stream(codec, *d); in cleanup_dig_out_stream()
3627 int snd_hda_multi_out_dig_open(struct hda_codec *codec, in snd_hda_multi_out_dig_open() argument
3630 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3633 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_open()
3635 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3648 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
3654 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3655 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
3656 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3666 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
3669 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3670 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
3671 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3681 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
3684 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3686 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3702 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
3720 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
3725 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3738 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3756 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
3767 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3768 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3772 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3776 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3780 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3783 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3786 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
3791 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
3796 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
3803 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3806 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3819 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
3832 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
3839 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
3841 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
3844 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3848 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3850 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3852 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
3855 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3868 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
3872 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
3874 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
3895 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
3908 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
3958 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
3961 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
3962 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
3964 return snd_hda_codec_update_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
3967 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
3984 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
3990 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
4018 struct hda_codec *codec; in snd_hda_bus_reset_codecs() local
4020 list_for_each_codec(codec, bus) { in snd_hda_bus_reset_codecs()
4022 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset_codecs()
4024 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset_codecs()
4025 hda_call_codec_suspend(codec); in snd_hda_bus_reset_codecs()
4026 hda_call_codec_resume(codec); in snd_hda_bus_reset_codecs()