Lines Matching refs:codec

28 #define codec_in_pm(codec)		snd_hdac_is_in_pm(&codec->core)  argument
29 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core) argument
30 #define codec_has_epss(codec) \ argument
31 ((codec)->core.power_caps & AC_PWRST_EPSS)
32 #define codec_has_clkstop(codec) \ argument
33 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
35 static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec, in call_exec_verb() argument
41 CLASS(snd_hda_power_pm, pm)(codec); in call_exec_verb()
45 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, in call_exec_verb()
57 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in codec_exec_verb() local
58 struct hda_bus *bus = codec->bus; in codec_exec_verb()
65 err = call_exec_verb(bus, codec, cmd, flags, res); in codec_exec_verb()
66 if (!codec_in_pm(codec) && res && err == -EAGAIN) { in codec_exec_verb()
68 codec_dbg(codec, in codec_exec_verb()
75 if (!err || codec_in_pm(codec)) in codec_exec_verb()
88 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
91 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); in snd_hda_sequence_write()
105 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) in lookup_conn_list() argument
108 list_for_each_entry(p, &codec->conn_list, list) { in lookup_conn_list()
115 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in add_conn_list() argument
126 list_add(&p->list, &codec->conn_list); in add_conn_list()
130 static void remove_conn_list(struct hda_codec *codec) in remove_conn_list() argument
132 while (!list_empty(&codec->conn_list)) { in remove_conn_list()
134 p = list_first_entry(&codec->conn_list, typeof(*p), list); in remove_conn_list()
141 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) in read_and_add_raw_conns() argument
147 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); in read_and_add_raw_conns()
149 len = snd_hda_get_num_raw_conns(codec, nid); in read_and_add_raw_conns()
153 len = snd_hda_get_raw_connections(codec, nid, result, len); in read_and_add_raw_conns()
156 len = snd_hda_override_conn_list(codec, nid, len, result); in read_and_add_raw_conns()
177 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
187 p = lookup_conn_list(codec, nid); in snd_hda_get_conn_list()
196 err = read_and_add_raw_conns(codec, nid); in snd_hda_get_conn_list()
216 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_connections() argument
220 int len = snd_hda_get_conn_list(codec, nid, &list); in snd_hda_get_connections()
224 codec_err(codec, "Too many connections %d for NID 0x%x\n", in snd_hda_get_connections()
247 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in snd_hda_override_conn_list() argument
252 p = lookup_conn_list(codec, nid); in snd_hda_override_conn_list()
258 return add_conn_list(codec, nid, len, list); in snd_hda_override_conn_list()
273 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, in snd_hda_get_conn_index() argument
279 nums = snd_hda_get_conn_list(codec, mux, &conn); in snd_hda_get_conn_index()
286 codec_dbg(codec, "too deep connection for 0x%x\n", nid); in snd_hda_get_conn_index()
291 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i])); in snd_hda_get_conn_index()
294 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) in snd_hda_get_conn_index()
309 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_num_devices() argument
311 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_get_num_devices()
314 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || in snd_hda_get_num_devices()
318 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN); in snd_hda_get_num_devices()
335 unsigned int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_devices() argument
340 parm = snd_hda_get_num_devices(codec, nid); in snd_hda_get_devices()
348 if (snd_hdac_read(&codec->core, nid, in snd_hda_get_devices()
372 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_dev_select() argument
375 if (!codec->dp_mst) in snd_hda_get_dev_select()
378 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0); in snd_hda_get_dev_select()
390 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id) in snd_hda_set_dev_select() argument
395 if (!codec->dp_mst) in snd_hda_set_dev_select()
399 num_devices = snd_hda_get_num_devices(codec, nid) + 1; in snd_hda_set_dev_select()
413 ret = snd_hda_codec_write(codec, nid, 0, in snd_hda_set_dev_select()
423 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) in read_widget_caps() argument
428 codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL); in read_widget_caps()
429 if (!codec->wcaps) in read_widget_caps()
431 nid = codec->core.start_nid; in read_widget_caps()
432 for (i = 0; i < codec->core.num_nodes; i++, nid++) in read_widget_caps()
433 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, in read_widget_caps()
439 static int read_pin_defaults(struct hda_codec *codec) in read_pin_defaults() argument
443 for_each_hda_codec_node(nid, codec) { in read_pin_defaults()
445 unsigned int wcaps = get_wcaps(codec, nid); in read_pin_defaults()
449 pin = snd_array_new(&codec->init_pins); in read_pin_defaults()
453 pin->cfg = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
459 pin->ctrl = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
467 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, in look_up_pincfg() argument
484 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
489 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
510 int snd_hda_codec_set_pincfg(struct hda_codec *codec, in snd_hda_codec_set_pincfg() argument
513 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); in snd_hda_codec_set_pincfg()
526 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pincfg() argument
533 scoped_guard(mutex, &codec->user_mutex) { in snd_hda_codec_get_pincfg()
534 pin = look_up_pincfg(codec, &codec->user_pins, nid); in snd_hda_codec_get_pincfg()
542 pin = look_up_pincfg(codec, &codec->driver_pins, nid); in snd_hda_codec_get_pincfg()
545 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pincfg()
562 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_set_pin_target() argument
567 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_set_pin_target()
580 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pin_target() argument
584 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pin_target()
598 void snd_hda_shutup_pins(struct hda_codec *codec) in snd_hda_shutup_pins() argument
606 if (codec->bus->shutdown) in snd_hda_shutup_pins()
608 snd_array_for_each(&codec->init_pins, i, pin) { in snd_hda_shutup_pins()
610 snd_hda_codec_read(codec, pin->nid, 0, in snd_hda_shutup_pins()
613 codec->pins_shutup = 1; in snd_hda_shutup_pins()
618 static void restore_shutup_pins(struct hda_codec *codec) in restore_shutup_pins() argument
623 if (!codec->pins_shutup) in restore_shutup_pins()
625 if (codec->bus->shutdown) in restore_shutup_pins()
627 snd_array_for_each(&codec->init_pins, i, pin) { in restore_shutup_pins()
628 snd_hda_codec_write(codec, pin->nid, 0, in restore_shutup_pins()
632 codec->pins_shutup = 0; in restore_shutup_pins()
637 struct hda_codec *codec = in hda_jackpoll_work() local
640 if (!codec->jackpoll_interval) in hda_jackpoll_work()
644 CLASS(snd_hda_power, pm)(codec); in hda_jackpoll_work()
646 snd_hda_jack_set_dirty_all(codec); in hda_jackpoll_work()
647 snd_hda_jack_poll_all(codec); in hda_jackpoll_work()
648 schedule_delayed_work(&codec->jackpoll_work, codec->jackpoll_interval); in hda_jackpoll_work()
652 static void free_init_pincfgs(struct hda_codec *codec) in free_init_pincfgs() argument
654 snd_array_free(&codec->driver_pins); in free_init_pincfgs()
656 snd_array_free(&codec->user_pins); in free_init_pincfgs()
658 snd_array_free(&codec->init_pins); in free_init_pincfgs()
675 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) in get_hda_cvt_setup() argument
680 snd_array_for_each(&codec->cvt_setups, i, p) { in get_hda_cvt_setup()
684 p = snd_array_new(&codec->cvt_setups); in get_hda_cvt_setup()
695 if (refcount_dec_and_test(&pcm->codec->pcm_ref)) in snd_hda_codec_pcm_put()
696 wake_up(&pcm->codec->remove_sleep); in snd_hda_codec_pcm_put()
700 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, in snd_hda_codec_pcm_new() argument
710 pcm->codec = codec; in snd_hda_codec_pcm_new()
719 list_add_tail(&pcm->list, &codec->pcm_list_head); in snd_hda_codec_pcm_new()
720 refcount_inc(&codec->pcm_ref); in snd_hda_codec_pcm_new()
728 void snd_hda_codec_disconnect_pcms(struct hda_codec *codec) in snd_hda_codec_disconnect_pcms() argument
732 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in snd_hda_codec_disconnect_pcms()
736 snd_device_disconnect(codec->card, pcm->pcm); in snd_hda_codec_disconnect_pcms()
742 static void codec_release_pcms(struct hda_codec *codec) in codec_release_pcms() argument
746 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { in codec_release_pcms()
749 snd_device_free(pcm->codec->card, pcm->pcm); in codec_release_pcms()
750 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); in codec_release_pcms()
760 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) in snd_hda_codec_cleanup_for_unbind() argument
762 if (codec->core.registered) { in snd_hda_codec_cleanup_for_unbind()
764 pm_runtime_get_noresume(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
765 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
766 codec->core.registered = 0; in snd_hda_codec_cleanup_for_unbind()
769 snd_hda_codec_disconnect_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
770 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_cleanup_for_unbind()
771 if (!codec->in_freeing) in snd_hda_codec_cleanup_for_unbind()
772 snd_hda_ctls_clear(codec); in snd_hda_codec_cleanup_for_unbind()
773 codec_release_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
774 snd_hda_detach_beep_device(codec); in snd_hda_codec_cleanup_for_unbind()
775 snd_hda_jack_tbl_clear(codec); in snd_hda_codec_cleanup_for_unbind()
776 codec->proc_widget_hook = NULL; in snd_hda_codec_cleanup_for_unbind()
777 codec->spec = NULL; in snd_hda_codec_cleanup_for_unbind()
780 snd_array_free(&codec->driver_pins); in snd_hda_codec_cleanup_for_unbind()
781 snd_array_free(&codec->cvt_setups); in snd_hda_codec_cleanup_for_unbind()
782 snd_array_free(&codec->spdif_out); in snd_hda_codec_cleanup_for_unbind()
783 snd_array_free(&codec->verbs); in snd_hda_codec_cleanup_for_unbind()
784 codec->follower_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
785 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
786 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
787 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
788 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
789 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
790 codec->configured = 0; in snd_hda_codec_cleanup_for_unbind()
791 refcount_set(&codec->pcm_ref, 1); /* reset refcount */ in snd_hda_codec_cleanup_for_unbind()
795 static unsigned int hda_set_power_state(struct hda_codec *codec,
799 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) in snd_hda_codec_display_power() argument
801 if (codec->display_power_control) in snd_hda_codec_display_power()
802 snd_hdac_display_power(&codec->bus->core, codec->addr, enable); in snd_hda_codec_display_power()
811 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
813 if (codec->core.registered) in snd_hda_codec_register()
815 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
816 snd_hda_codec_display_power(codec, true); in snd_hda_codec_register()
817 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
819 snd_hda_power_down(codec); in snd_hda_codec_register()
820 codec->core.registered = 1; in snd_hda_codec_register()
835 void snd_hda_codec_unregister(struct hda_codec *codec) in snd_hda_codec_unregister() argument
837 codec->in_freeing = 1; in snd_hda_codec_unregister()
843 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
844 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_unregister()
845 snd_hda_codec_display_power(codec, false); in snd_hda_codec_unregister()
851 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_unregister()
852 put_device(hda_codec_dev(codec)); in snd_hda_codec_unregister()
864 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
866 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
867 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
868 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
869 kfree(codec->modelname); in snd_hda_codec_dev_release()
870 kfree(codec->wcaps); in snd_hda_codec_dev_release()
871 kfree(codec); in snd_hda_codec_dev_release()
890 struct hda_codec *codec; in snd_hda_codec_device_init() local
898 codec = kzalloc_obj(*codec); in snd_hda_codec_device_init()
899 if (!codec) in snd_hda_codec_device_init()
906 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr); in snd_hda_codec_device_init()
908 kfree(codec); in snd_hda_codec_device_init()
912 codec->bus = bus; in snd_hda_codec_device_init()
913 codec->depop_delay = -1; in snd_hda_codec_device_init()
914 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_device_init()
915 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_device_init()
916 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_device_init()
918 mutex_init(&codec->spdif_mutex); in snd_hda_codec_device_init()
919 mutex_init(&codec->control_mutex); in snd_hda_codec_device_init()
920 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
921 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_init()
922 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
923 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_init()
924 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_device_init()
925 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_device_init()
926 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_device_init()
927 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_device_init()
928 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_device_init()
929 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_device_init()
930 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_device_init()
931 refcount_set(&codec->pcm_ref, 1); in snd_hda_codec_device_init()
932 init_waitqueue_head(&codec->remove_sleep); in snd_hda_codec_device_init()
934 return codec; in snd_hda_codec_device_init()
950 struct hda_codec *codec; in snd_hda_codec_new() local
953 codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d", in snd_hda_codec_new()
955 if (IS_ERR(codec)) in snd_hda_codec_new()
956 return PTR_ERR(codec); in snd_hda_codec_new()
957 *codecp = codec; in snd_hda_codec_new()
968 unsigned int codec_addr, struct hda_codec *codec, in snd_hda_codec_device_new() argument
986 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_device_new()
987 codec->card = card; in snd_hda_codec_device_new()
988 codec->addr = codec_addr; in snd_hda_codec_device_new()
990 codec->power_jiffies = jiffies; in snd_hda_codec_device_new()
992 snd_hda_sysfs_init(codec); in snd_hda_codec_device_new()
994 if (codec->bus->modelname) { in snd_hda_codec_device_new()
995 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_device_new()
996 if (!codec->modelname) in snd_hda_codec_device_new()
1000 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_device_new()
1001 err = read_widget_caps(codec, fg); in snd_hda_codec_device_new()
1004 err = read_pin_defaults(codec); in snd_hda_codec_device_new()
1009 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_device_new()
1010 codec->core.dev.power.power_state = PMSG_ON; in snd_hda_codec_device_new()
1012 snd_hda_codec_proc_new(codec); in snd_hda_codec_device_new()
1014 snd_hda_create_hwdep(codec); in snd_hda_codec_device_new()
1016 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_device_new()
1017 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_device_new()
1022 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_device_new()
1029 if (codec->core.dev.power.runtime_auto) in snd_hda_codec_device_new()
1030 pm_runtime_forbid(&codec->core.dev); in snd_hda_codec_device_new()
1033 pm_runtime_get_noresume(&codec->core.dev); in snd_hda_codec_device_new()
1047 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
1052 err = snd_hdac_refresh_widgets(&codec->core); in snd_hda_codec_update_widgets()
1059 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
1060 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
1061 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
1065 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
1066 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
1073 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
1080 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
1083 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
1092 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
1098 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
1102 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
1118 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
1122 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in snd_hda_codec_setup_stream()
1131 codec_dbg(codec, in snd_hda_codec_setup_stream()
1134 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
1139 driver->ops->stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1140 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1141 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1142 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1143 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1144 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1150 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1151 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1161 static void really_cleanup_stream(struct hda_codec *codec,
1170 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1178 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1181 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1182 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1189 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1196 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1199 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in really_cleanup_stream()
1203 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1205 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1210 driver->ops->stream_pm(codec, nid, false); in really_cleanup_stream()
1214 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1220 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1229 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1234 snd_array_for_each(&codec->cvt_setups, i, p) { in hda_cleanup_all_streams()
1236 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1256 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1258 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1259 nid = codec->core.afg; in query_amp_caps()
1260 return snd_hda_param_read(codec, nid, in query_amp_caps()
1275 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1280 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1281 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1300 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1305 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1306 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1308 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1312 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid, in encode_amp() argument
1318 if ((query_amp_caps(codec, nid, dir) & in encode_amp()
1336 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1339 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_update()
1341 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1357 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1365 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1385 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1388 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1390 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1392 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val); in snd_hda_codec_amp_init()
1407 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1415 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1421 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1424 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1452 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1454 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1465 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1469 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1479 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1488 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1491 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1515 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1517 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1544 err = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1551 err = update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in get_ctl_amp_tlv() local
1570 caps = query_amp_caps(codec, nid, dir); in get_ctl_amp_tlv()
1619 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1625 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1638 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1648 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1658 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1661 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1665 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1671 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1696 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1712 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1715 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1729 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1732 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1734 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1735 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1736 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1737 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1749 struct hda_codec *codec; in snd_hda_lock_devices() local
1758 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1760 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1799 int snd_hda_codec_reset(struct hda_codec *codec) in snd_hda_codec_reset() argument
1801 struct hda_bus *bus = codec->bus; in snd_hda_codec_reset()
1807 device_release_driver(hda_codec_dev(codec)); in snd_hda_codec_reset()
1817 static int map_followers(struct hda_codec *codec, const char * const *followers, in map_followers() argument
1824 items = codec->mixers.list; in map_followers()
1825 for (i = 0; i < codec->mixers.used; i++) { in map_followers()
1838 err = func(codec, data, sctl); in map_followers()
1848 static int check_follower_present(struct hda_codec *codec, in check_follower_present() argument
1869 struct hda_codec *codec; member
1886 codec_err(arg->codec, in init_follower_0dB()
1904 codec_err(arg->codec, in init_follower_0dB()
1928 static int add_follower(struct hda_codec *codec, in add_follower() argument
1954 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, in __snd_hda_add_vmaster() argument
1965 err = map_followers(codec, followers, suffix, check_follower_present, NULL); in __snd_hda_add_vmaster()
1967 codec_dbg(codec, "No follower found for %s\n", name); in __snd_hda_add_vmaster()
1974 err = snd_hda_ctl_add(codec, 0, kctl); in __snd_hda_add_vmaster()
1978 err = map_followers(codec, followers, suffix, add_follower, kctl); in __snd_hda_add_vmaster()
1986 .codec = codec, in __snd_hda_add_vmaster()
2005 hook->hook(hook->codec, enabled); in vmaster_hook()
2015 int snd_hda_add_vmaster_hook(struct hda_codec *codec, in snd_hda_add_vmaster_hook() argument
2020 hook->codec = codec; in snd_hda_add_vmaster_hook()
2035 if (!hook->hook || !hook->codec) in snd_hda_sync_vmaster_hook()
2040 if (hook->codec->bus->shutdown) in snd_hda_sync_vmaster_hook()
2079 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get() local
2087 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & in snd_hda_mixer_amp_switch_get()
2090 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & in snd_hda_mixer_amp_switch_get()
2107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put() local
2118 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2126 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2130 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2175 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_get()
2177 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2178 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2241 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2246 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2248 d = codec->follower_dig_outs; in set_dig_out()
2252 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2256 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2270 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2283 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_put()
2285 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2286 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2297 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2310 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_get()
2312 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2313 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2318 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2321 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2323 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2325 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2339 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_put()
2341 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2342 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2350 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2397 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2409 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2420 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2425 err = snd_ctl_rename_id(codec->card, &kctl->id, &id); in snd_hda_create_dig_out_ctls()
2434 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2436 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2439 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2443 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2447 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2448 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2453 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2468 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2474 snd_array_for_each(&codec->spdif_out, i, spdif) { in snd_hda_spdif_out_of_nid()
2489 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2493 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_unassign()
2495 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2496 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2509 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2514 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_assign()
2516 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2517 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2521 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2558 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2570 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2585 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2597 guard(mutex)(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2598 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2600 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2601 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2615 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2653 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2660 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2662 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2666 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2670 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2674 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2675 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2692 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
2697 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2698 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
2702 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
2703 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
2707 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
2722 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
2726 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
2729 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
2730 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
2731 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
2743 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
2746 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in hda_set_power_state()
2747 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
2754 if (codec->depop_delay < 0) in hda_set_power_state()
2755 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
2756 else if (codec->depop_delay > 0) in hda_set_power_state()
2757 msleep(codec->depop_delay); in hda_set_power_state()
2765 driver->ops->set_power_state(codec, fg, power_state); in hda_set_power_state()
2768 if (codec->power_filter) in hda_set_power_state()
2769 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
2771 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
2774 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
2776 state = snd_hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
2787 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
2792 if (!codec->power_filter) in sync_power_up_states()
2795 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
2796 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
2800 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
2803 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
2804 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
2811 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
2813 if (codec->init_verbs.list) in hda_exec_init_verbs()
2814 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
2817 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
2821 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
2823 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
2826 codec->power_on_acct += delta; in update_power_acct()
2828 codec->power_off_acct += delta; in update_power_acct()
2829 codec->power_jiffies += delta; in update_power_acct()
2832 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
2834 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
2841 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
2843 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in hda_call_codec_suspend()
2846 snd_hdac_enter_pm(&codec->core); in hda_call_codec_suspend()
2848 driver->ops->suspend(codec); in hda_call_codec_suspend()
2849 if (!codec->no_stream_clean_at_suspend) in hda_call_codec_suspend()
2850 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
2851 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
2852 update_power_acct(codec, true); in hda_call_codec_suspend()
2853 snd_hdac_leave_pm(&codec->core); in hda_call_codec_suspend()
2860 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
2862 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in hda_call_codec_resume()
2864 snd_hdac_enter_pm(&codec->core); in hda_call_codec_resume()
2865 if (codec->core.regmap) in hda_call_codec_resume()
2866 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
2868 codec->power_jiffies = jiffies; in hda_call_codec_resume()
2870 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
2871 restore_shutup_pins(codec); in hda_call_codec_resume()
2872 hda_exec_init_verbs(codec); in hda_call_codec_resume()
2873 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
2875 driver->ops->resume(codec); in hda_call_codec_resume()
2877 snd_hda_codec_init(codec); in hda_call_codec_resume()
2878 snd_hda_regmap_sync(codec); in hda_call_codec_resume()
2881 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
2882 codec->core.dev.power.power_state = PMSG_ON; in hda_call_codec_resume()
2883 snd_hdac_leave_pm(&codec->core); in hda_call_codec_resume()
2884 if (codec->jackpoll_interval) in hda_call_codec_resume()
2885 schedule_delayed_work(&codec->jackpoll_work, in hda_call_codec_resume()
2886 codec->jackpoll_interval); in hda_call_codec_resume()
2891 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
2895 if (!codec->card) in hda_codec_runtime_suspend()
2898 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
2899 if (codec->link_down_at_suspend || in hda_codec_runtime_suspend()
2900 (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
2902 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
2903 snd_hda_codec_display_power(codec, false); in hda_codec_runtime_suspend()
2910 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
2913 if (!codec->card) in hda_codec_runtime_resume()
2916 snd_hda_codec_display_power(codec, true); in hda_codec_runtime_resume()
2917 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
2918 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
2925 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_idle() local
2927 if (codec->jackpoll_interval && !codec->bus->jackpoll_in_suspend) in hda_codec_runtime_idle()
2934 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_prepare() local
2936 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_prepare()
2943 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_complete() local
2949 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval || in hda_codec_pm_complete()
2950 hda_codec_need_resume(codec) || codec->forced_resume)) in hda_codec_pm_complete()
2968 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_freeze() local
2970 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_pm_freeze()
3002 void snd_hda_codec_shutdown(struct hda_codec *codec) in snd_hda_codec_shutdown() argument
3007 if (!codec->core.registered) in snd_hda_codec_shutdown()
3010 codec->jackpoll_interval = 0; /* don't poll any longer */ in snd_hda_codec_shutdown()
3011 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_shutdown()
3012 list_for_each_entry(cpcm, &codec->pcm_list_head, list) in snd_hda_codec_shutdown()
3015 pm_runtime_force_suspend(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3016 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3022 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3027 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3060 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3062 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in snd_hda_codec_build_controls()
3065 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3067 err = snd_hda_codec_init(codec); in snd_hda_codec_build_controls()
3072 err = driver->ops->build_controls(codec); in snd_hda_codec_build_controls()
3078 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3082 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3083 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3084 schedule_delayed_work(&codec->jackpoll_work, in snd_hda_codec_build_controls()
3085 codec->jackpoll_interval); in snd_hda_codec_build_controls()
3087 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3096 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3103 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3108 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3113 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3116 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3120 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3127 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3166 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3174 guard(mutex)(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3176 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3181 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3194 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3198 guard(mutex)(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3200 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3258 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3260 struct hda_codec_driver *driver = hda_codec_to_driver(codec); in snd_hda_codec_parse_pcms()
3264 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3270 err = driver->ops->build_pcms(codec); in snd_hda_codec_parse_pcms()
3272 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3273 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3277 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3285 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3287 codec_warn(codec, in snd_hda_codec_parse_pcms()
3300 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3302 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3306 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3311 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3323 err = snd_hda_attach_pcm_stream(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3325 codec_err(codec, in snd_hda_codec_build_pcms()
3327 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3345 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3356 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3364 if (addr > 0 && codec->ctl_dev_id) in snd_hda_add_new_ctls()
3368 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3375 if (!addr && codec->core.addr) { in snd_hda_add_new_ctls()
3376 addr = codec->core.addr; in snd_hda_add_new_ctls()
3377 if (!codec->ctl_dev_id) in snd_hda_add_new_ctls()
3380 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3397 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay) in snd_hda_codec_set_power_save() argument
3399 struct device *dev = hda_codec_dev(codec); in snd_hda_codec_set_power_save()
3401 if (delay == 0 && codec->auto_runtime_pm) in snd_hda_codec_set_power_save()
3446 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3464 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3469 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3477 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
3518 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
3533 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
3573 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
3580 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->follower_dig_outs) { in setup_dig_out_stream()
3602 for (d = codec->follower_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->follower_dig_outs) { in cleanup_dig_out_stream()
3617 for (d = codec->follower_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 guard(mutex)(&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()
3647 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
3653 guard(mutex)(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3654 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
3664 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
3667 guard(mutex)(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3668 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
3678 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
3681 guard(mutex)(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3698 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
3716 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
3722 guard(mutex)(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3752 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
3763 scoped_guard(mutex, &codec->spdif_mutex) { in snd_hda_multi_out_analog_prepare()
3764 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3768 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3772 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3776 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3782 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
3787 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
3792 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
3799 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3802 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3815 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
3828 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
3835 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
3837 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
3840 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3844 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3846 guard(mutex)(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3848 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
3863 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
3867 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
3869 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
3890 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
3903 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
3953 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
3956 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
3957 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
3959 return snd_hda_codec_write_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
3962 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
3979 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
3985 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
4013 struct hda_codec *codec; in snd_hda_bus_reset_codecs() local
4015 list_for_each_codec(codec, bus) { in snd_hda_bus_reset_codecs()
4017 if (current_work() != &codec->jackpoll_work.work) in snd_hda_bus_reset_codecs()
4018 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset_codecs()
4019 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset_codecs()
4020 hda_call_codec_suspend(codec); in snd_hda_bus_reset_codecs()
4021 hda_call_codec_resume(codec); in snd_hda_bus_reset_codecs()