Lines Matching refs: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)
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()
48 snd_hda_power_up_pm(codec); in codec_exec_verb()
52 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, 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()
59 codec_dbg(codec, in codec_exec_verb()
66 if (!err || codec_in_pm(codec)) in codec_exec_verb()
79 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
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()
106 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in add_conn_list() argument
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()
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()
140 len = snd_hda_get_num_raw_conns(codec, nid); 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()
168 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
178 p = lookup_conn_list(codec, nid); in snd_hda_get_conn_list()
187 err = read_and_add_raw_conns(codec, nid); in snd_hda_get_conn_list()
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()
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()
249 return add_conn_list(codec, nid, len, list); in snd_hda_override_conn_list()
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()
277 codec_dbg(codec, "too deep connection for 0x%x\n", nid); 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()
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()
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()
341 if (snd_hdac_read(&codec->core, nid, in snd_hda_get_devices()
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()
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()
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()
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()
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()
446 pin->cfg = snd_hda_codec_read(codec, nid, 0, 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
477 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
491 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
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()
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()
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()
547 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pincfg()
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()
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()
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()
635 codec->pins_shutup = 0; in restore_shutup_pins()
641 struct hda_codec *codec = in hda_jackpoll_work() local
645 if (!codec->jackpoll_interval && snd_hdac_is_power_on(&codec->core)) 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()
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()
697 p = snd_array_new(&codec->cvt_setups); 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()
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()
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()
749 snd_device_disconnect(codec->card, pcm->pcm); 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()
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()
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->preset = NULL; in snd_hda_codec_cleanup_for_unbind()
799 codec->follower_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
800 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
801 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
802 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
803 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
804 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
805 codec->configured = 0; in snd_hda_codec_cleanup_for_unbind()
806 refcount_set(&codec->pcm_ref, 1); /* reset refcount */ in snd_hda_codec_cleanup_for_unbind()
810 static unsigned int hda_set_power_state(struct hda_codec *codec,
814 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) in snd_hda_codec_display_power() argument
816 if (codec->display_power_control) in snd_hda_codec_display_power()
817 snd_hdac_display_power(&codec->bus->core, codec->addr, enable); in snd_hda_codec_display_power()
826 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
828 if (codec->core.registered) in snd_hda_codec_register()
830 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
831 snd_hda_codec_display_power(codec, true); in snd_hda_codec_register()
832 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
834 snd_hda_power_down(codec); in snd_hda_codec_register()
835 codec->core.registered = 1; in snd_hda_codec_register()
850 void snd_hda_codec_unregister(struct hda_codec *codec) in snd_hda_codec_unregister() argument
852 codec->in_freeing = 1; in snd_hda_codec_unregister()
858 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
859 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_unregister()
860 snd_hda_codec_display_power(codec, false); in snd_hda_codec_unregister()
866 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
867 put_device(hda_codec_dev(codec)); in snd_hda_codec_unregister()
879 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
881 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
882 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
883 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
884 kfree(codec->modelname); in snd_hda_codec_dev_release()
885 kfree(codec->wcaps); in snd_hda_codec_dev_release()
886 kfree(codec); in snd_hda_codec_dev_release()
905 struct hda_codec *codec; in snd_hda_codec_device_init() local
913 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_hda_codec_device_init()
914 if (!codec) in snd_hda_codec_device_init()
921 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr); in snd_hda_codec_device_init()
923 kfree(codec); in snd_hda_codec_device_init()
927 codec->bus = bus; in snd_hda_codec_device_init()
928 codec->depop_delay = -1; in snd_hda_codec_device_init()
929 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_device_init()
930 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_device_init()
931 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_device_init()
932 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_device_init()
934 mutex_init(&codec->spdif_mutex); in snd_hda_codec_device_init()
935 mutex_init(&codec->control_mutex); in snd_hda_codec_device_init()
936 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
937 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
938 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
939 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
940 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_device_init()
941 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_device_init()
942 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_device_init()
943 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_device_init()
944 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_device_init()
945 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_device_init()
946 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_device_init()
947 refcount_set(&codec->pcm_ref, 1); in snd_hda_codec_device_init()
948 init_waitqueue_head(&codec->remove_sleep); in snd_hda_codec_device_init()
950 return codec; in snd_hda_codec_device_init()
966 struct hda_codec *codec; in snd_hda_codec_new() local
969 codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d", in snd_hda_codec_new()
971 if (IS_ERR(codec)) in snd_hda_codec_new()
972 return PTR_ERR(codec); in snd_hda_codec_new()
973 *codecp = codec; in snd_hda_codec_new()
984 unsigned int codec_addr, struct hda_codec *codec, in snd_hda_codec_device_new() argument
1002 codec->card = card; in snd_hda_codec_device_new()
1003 codec->addr = codec_addr; in snd_hda_codec_device_new()
1006 codec->power_jiffies = jiffies; in snd_hda_codec_device_new()
1009 snd_hda_sysfs_init(codec); in snd_hda_codec_device_new()
1011 if (codec->bus->modelname) { in snd_hda_codec_device_new()
1012 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_device_new()
1013 if (!codec->modelname) in snd_hda_codec_device_new()
1017 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_device_new()
1018 err = read_widget_caps(codec, fg); in snd_hda_codec_device_new()
1021 err = read_pin_defaults(codec); in snd_hda_codec_device_new()
1026 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_device_new()
1027 codec->core.dev.power.power_state = PMSG_ON; in snd_hda_codec_device_new()
1029 snd_hda_codec_proc_new(codec); in snd_hda_codec_device_new()
1031 snd_hda_create_hwdep(codec); in snd_hda_codec_device_new()
1033 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_device_new()
1034 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_device_new()
1039 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_device_new()
1046 if (codec->core.dev.power.runtime_auto) in snd_hda_codec_device_new()
1047 pm_runtime_forbid(&codec->core.dev); in snd_hda_codec_device_new()
1050 pm_runtime_get_noresume(&codec->core.dev); in snd_hda_codec_device_new()
1064 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
1069 err = snd_hdac_refresh_widgets(&codec->core); in snd_hda_codec_update_widgets()
1076 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
1077 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
1078 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
1082 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
1083 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
1090 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
1097 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
1100 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
1109 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
1115 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
1119 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
1135 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
1147 codec_dbg(codec, in snd_hda_codec_setup_stream()
1150 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
1154 if (codec->patch_ops.stream_pm) in snd_hda_codec_setup_stream()
1155 codec->patch_ops.stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1156 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1157 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1158 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1159 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1160 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1166 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1167 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1177 static void really_cleanup_stream(struct hda_codec *codec,
1186 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1194 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1197 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1198 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1205 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1212 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1217 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1219 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1223 if (codec->patch_ops.stream_pm) in really_cleanup_stream()
1224 codec->patch_ops.stream_pm(codec, nid, false); in really_cleanup_stream()
1228 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1234 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1244 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1249 snd_array_for_each(&codec->cvt_setups, i, p) { in hda_cleanup_all_streams()
1251 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1272 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1274 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1275 nid = codec->core.afg; in query_amp_caps()
1276 return snd_hda_param_read(codec, nid, in query_amp_caps()
1291 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1296 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1297 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1316 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1321 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1322 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1324 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1328 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid, in encode_amp() argument
1334 if ((query_amp_caps(codec, nid, dir) & in encode_amp()
1352 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1355 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_update()
1357 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1373 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1381 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1401 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1404 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1406 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1408 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val); in snd_hda_codec_amp_init()
1423 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1431 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1437 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1440 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1468 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1470 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1481 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1485 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1495 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1504 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1507 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1531 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1533 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1559 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1563 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in get_ctl_amp_tlv() local
1578 caps = query_amp_caps(codec, nid, dir); in get_ctl_amp_tlv()
1627 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1633 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1646 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1656 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1666 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1669 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1673 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1679 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1704 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1720 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1723 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1744 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, in snd_hda_add_nid() argument
1750 item = snd_array_new(&codec->nids); in snd_hda_add_nid()
1758 codec_err(codec, "no NID for mapping control %s:%d:%d\n", in snd_hda_add_nid()
1768 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1771 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1773 down_write(&codec->card->controls_rwsem); in snd_hda_ctls_clear()
1774 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1775 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1776 up_write(&codec->card->controls_rwsem); in snd_hda_ctls_clear()
1777 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1778 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1790 struct hda_codec *codec; in snd_hda_lock_devices() local
1799 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1801 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1844 int snd_hda_codec_reset(struct hda_codec *codec) in snd_hda_codec_reset() argument
1846 struct hda_bus *bus = codec->bus; in snd_hda_codec_reset()
1852 device_release_driver(hda_codec_dev(codec)); in snd_hda_codec_reset()
1862 static int map_followers(struct hda_codec *codec, const char * const *followers, in map_followers() argument
1869 items = codec->mixers.list; in map_followers()
1870 for (i = 0; i < codec->mixers.used; i++) { in map_followers()
1883 err = func(codec, data, sctl); in map_followers()
1893 static int check_follower_present(struct hda_codec *codec, in check_follower_present() argument
1914 struct hda_codec *codec; member
1931 codec_err(arg->codec, in init_follower_0dB()
1949 codec_err(arg->codec, in init_follower_0dB()
1973 static int add_follower(struct hda_codec *codec, in add_follower() argument
1999 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, in __snd_hda_add_vmaster() argument
2010 err = map_followers(codec, followers, suffix, check_follower_present, NULL); in __snd_hda_add_vmaster()
2012 codec_dbg(codec, "No follower found for %s\n", name); in __snd_hda_add_vmaster()
2019 err = snd_hda_ctl_add(codec, 0, kctl); in __snd_hda_add_vmaster()
2023 err = map_followers(codec, followers, suffix, add_follower, kctl); in __snd_hda_add_vmaster()
2031 .codec = codec, in __snd_hda_add_vmaster()
2050 hook->hook(hook->codec, enabled); in vmaster_hook()
2060 int snd_hda_add_vmaster_hook(struct hda_codec *codec, in snd_hda_add_vmaster_hook() argument
2065 hook->codec = codec; in snd_hda_add_vmaster_hook()
2080 if (!hook->hook || !hook->codec) in snd_hda_sync_vmaster_hook()
2085 if (hook->codec->bus->shutdown) in snd_hda_sync_vmaster_hook()
2124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get() local
2132 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & in snd_hda_mixer_amp_switch_get()
2135 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & in snd_hda_mixer_amp_switch_get()
2152 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put() local
2161 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2167 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2170 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2211 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2215 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_get()
2217 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2218 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2223 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2282 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2287 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2289 d = codec->follower_dig_outs; in set_dig_out()
2293 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2297 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2311 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2317 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2324 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_put()
2326 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2327 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2338 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2339 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2352 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_get()
2354 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2355 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2357 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2361 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2364 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2366 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2368 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2382 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_put()
2384 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2385 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2393 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2394 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2441 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2453 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2462 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2472 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2474 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2477 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2481 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2485 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2486 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2491 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2506 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2512 snd_array_for_each(&codec->spdif_out, i, spdif) { in snd_hda_spdif_out_of_nid()
2527 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2531 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_unassign()
2533 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2534 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2536 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2548 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2553 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_assign()
2555 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2556 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2560 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2562 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2598 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2610 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2625 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2637 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2638 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2640 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2641 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2644 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2656 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2694 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2701 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2703 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2707 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2711 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2715 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2716 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2733 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
2738 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2739 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
2743 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
2744 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
2748 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
2763 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
2767 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
2770 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
2771 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
2772 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
2784 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
2787 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
2794 if (codec->depop_delay < 0) in hda_set_power_state()
2795 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
2796 else if (codec->depop_delay > 0) in hda_set_power_state()
2797 msleep(codec->depop_delay); in hda_set_power_state()
2803 if (codec->patch_ops.set_power_state) in hda_set_power_state()
2804 codec->patch_ops.set_power_state(codec, fg, in hda_set_power_state()
2808 if (codec->power_filter) in hda_set_power_state()
2809 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
2811 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
2814 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
2816 state = snd_hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
2827 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
2832 if (!codec->power_filter) in sync_power_up_states()
2835 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
2836 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
2840 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
2843 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
2844 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
2851 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
2853 if (codec->init_verbs.list) in hda_exec_init_verbs()
2854 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
2857 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
2862 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
2864 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
2867 codec->power_on_acct += delta; in update_power_acct()
2869 codec->power_off_acct += delta; in update_power_acct()
2870 codec->power_jiffies += delta; in update_power_acct()
2873 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
2875 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
2882 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
2886 snd_hdac_enter_pm(&codec->core); in hda_call_codec_suspend()
2887 if (codec->patch_ops.suspend) in hda_call_codec_suspend()
2888 codec->patch_ops.suspend(codec); in hda_call_codec_suspend()
2889 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
2890 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
2891 update_power_acct(codec, true); in hda_call_codec_suspend()
2892 snd_hdac_leave_pm(&codec->core); in hda_call_codec_suspend()
2899 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
2901 snd_hdac_enter_pm(&codec->core); in hda_call_codec_resume()
2902 if (codec->core.regmap) in hda_call_codec_resume()
2903 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
2905 codec->power_jiffies = jiffies; in hda_call_codec_resume()
2907 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
2908 restore_shutup_pins(codec); in hda_call_codec_resume()
2909 hda_exec_init_verbs(codec); in hda_call_codec_resume()
2910 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
2911 if (codec->patch_ops.resume) in hda_call_codec_resume()
2912 codec->patch_ops.resume(codec); in hda_call_codec_resume()
2914 if (codec->patch_ops.init) in hda_call_codec_resume()
2915 codec->patch_ops.init(codec); in hda_call_codec_resume()
2916 snd_hda_regmap_sync(codec); in hda_call_codec_resume()
2919 if (codec->jackpoll_interval) in hda_call_codec_resume()
2920 hda_jackpoll_work(&codec->jackpoll_work.work); in hda_call_codec_resume()
2922 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
2923 codec->core.dev.power.power_state = PMSG_ON; in hda_call_codec_resume()
2924 snd_hdac_leave_pm(&codec->core); in hda_call_codec_resume()
2929 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
2933 if (!codec->card) in hda_codec_runtime_suspend()
2936 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_runtime_suspend()
2938 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
2939 if (codec->link_down_at_suspend || in hda_codec_runtime_suspend()
2940 (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
2942 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
2943 snd_hda_codec_display_power(codec, false); in hda_codec_runtime_suspend()
2945 if (codec->bus->jackpoll_in_suspend && in hda_codec_runtime_suspend()
2947 schedule_delayed_work(&codec->jackpoll_work, in hda_codec_runtime_suspend()
2948 codec->jackpoll_interval); in hda_codec_runtime_suspend()
2954 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
2957 if (!codec->card) in hda_codec_runtime_resume()
2960 snd_hda_codec_display_power(codec, true); in hda_codec_runtime_resume()
2961 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
2962 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
2972 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_prepare() local
2974 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_prepare()
2981 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_complete() local
2987 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval || in hda_codec_pm_complete()
2988 hda_codec_need_resume(codec) || codec->forced_resume)) in hda_codec_pm_complete()
3006 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_freeze() local
3008 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_freeze()
3043 void snd_hda_codec_shutdown(struct hda_codec *codec) in snd_hda_codec_shutdown() argument
3048 if (!codec->core.registered) in snd_hda_codec_shutdown()
3051 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_shutdown()
3052 list_for_each_entry(cpcm, &codec->pcm_list_head, list) in snd_hda_codec_shutdown()
3055 pm_runtime_force_suspend(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3056 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3062 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3067 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3100 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3103 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3105 if (codec->patch_ops.init) in snd_hda_codec_build_controls()
3106 err = codec->patch_ops.init(codec); in snd_hda_codec_build_controls()
3107 if (!err && codec->patch_ops.build_controls) in snd_hda_codec_build_controls()
3108 err = codec->patch_ops.build_controls(codec); in snd_hda_codec_build_controls()
3113 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3117 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3118 hda_jackpoll_work(&codec->jackpoll_work.work); in snd_hda_codec_build_controls()
3120 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3121 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3130 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3137 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3142 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3147 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3150 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3154 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3161 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3199 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3206 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3208 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3213 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3214 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3227 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3231 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3233 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3234 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3292 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3297 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3300 if (!codec->patch_ops.build_pcms) in snd_hda_codec_parse_pcms()
3303 err = codec->patch_ops.build_pcms(codec); in snd_hda_codec_parse_pcms()
3305 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3306 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3310 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3318 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3320 codec_warn(codec, in snd_hda_codec_parse_pcms()
3333 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3335 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3339 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3344 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3356 err = snd_hda_attach_pcm_stream(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3358 codec_err(codec, in snd_hda_codec_build_pcms()
3360 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3378 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3389 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3396 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3403 if (!addr && codec->core.addr) in snd_hda_add_new_ctls()
3404 addr = codec->core.addr; in snd_hda_add_new_ctls()
3406 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3424 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay) in snd_hda_codec_set_power_save() argument
3426 struct device *dev = hda_codec_dev(codec); in snd_hda_codec_set_power_save()
3428 if (delay == 0 && codec->auto_runtime_pm) in snd_hda_codec_set_power_save()
3473 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3491 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3496 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3504 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
3546 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
3561 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
3601 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
3608 spdif = snd_hda_spdif_out_of_nid(codec, nid); in setup_dig_out_stream()
3615 curr_fmt = snd_hda_codec_read(codec, nid, 0, in setup_dig_out_stream()
3617 reset = codec->spdif_status_reset && in setup_dig_out_stream()
3624 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3627 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); in setup_dig_out_stream()
3628 if (codec->follower_dig_outs) { in setup_dig_out_stream()
3630 for (d = codec->follower_dig_outs; *d; d++) in setup_dig_out_stream()
3631 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, in setup_dig_out_stream()
3636 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3640 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) in cleanup_dig_out_stream() argument
3642 snd_hda_codec_cleanup_stream(codec, nid); in cleanup_dig_out_stream()
3643 if (codec->follower_dig_outs) { in cleanup_dig_out_stream()
3645 for (d = codec->follower_dig_outs; *d; d++) in cleanup_dig_out_stream()
3646 snd_hda_codec_cleanup_stream(codec, *d); in cleanup_dig_out_stream()
3655 int snd_hda_multi_out_dig_open(struct hda_codec *codec, in snd_hda_multi_out_dig_open() argument
3658 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3661 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_open()
3663 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3676 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
3682 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3683 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
3684 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3694 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
3697 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3698 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
3699 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3709 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
3712 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3714 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3730 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
3748 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
3753 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3766 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3784 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
3795 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3796 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3800 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3804 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3808 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3811 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3814 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
3819 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
3824 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
3831 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3834 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3847 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
3860 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
3867 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
3869 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
3872 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3876 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3878 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3880 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
3883 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3896 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
3900 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
3902 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
3923 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
3936 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
3986 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
3989 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
3990 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
3992 return snd_hda_codec_write_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
3995 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
4012 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
4018 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
4046 struct hda_codec *codec; in snd_hda_bus_reset_codecs() local
4048 list_for_each_codec(codec, bus) { in snd_hda_bus_reset_codecs()
4050 if (current_work() != &codec->jackpoll_work.work) in snd_hda_bus_reset_codecs()
4051 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset_codecs()
4053 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset_codecs()
4054 hda_call_codec_suspend(codec); in snd_hda_bus_reset_codecs()
4055 hda_call_codec_resume(codec); in snd_hda_bus_reset_codecs()