Lines Matching full:codec
3 * Universal Interface for Intel High Definition Audio Codec
27 #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core) argument
28 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core) argument
29 #define codec_has_epss(codec) \ argument
30 ((codec)->core.power_caps & AC_PWRST_EPSS)
31 #define codec_has_clkstop(codec) \ argument
32 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
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()
73 * @codec: the HDA codec
79 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
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()
155 * @codec: the HDA codec
168 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
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()
197 * @codec: the HDA codec
207 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_connections() argument
211 int len = snd_hda_get_conn_list(codec, nid, &list); in snd_hda_get_connections()
215 codec_err(codec, "Too many connections %d for NID 0x%x\n", in snd_hda_get_connections()
228 * @codec: the HDA codec
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()
255 * @codec: the HDA codec
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()
294 * @codec: the HDA codec
300 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_num_devices() argument
302 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_get_num_devices()
305 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || in snd_hda_get_num_devices()
309 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN); in snd_hda_get_num_devices()
318 * @codec: the HDA codec
326 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_devices() argument
332 parm = snd_hda_get_num_devices(codec, nid); in snd_hda_get_devices()
341 if (snd_hdac_read(&codec->core, nid, in snd_hda_get_devices()
358 * @codec: the HDA codec
365 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid) in snd_hda_get_dev_select() argument
368 if (!codec->dp_mst) in snd_hda_get_dev_select()
371 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0); in snd_hda_get_dev_select()
377 * @codec: the HDA codec
383 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id) in snd_hda_set_dev_select() argument
388 if (!codec->dp_mst) in snd_hda_set_dev_select()
392 num_devices = snd_hda_get_num_devices(codec, nid) + 1; in snd_hda_set_dev_select()
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()
431 /* read all pin default configurations and save codec->init_pins */
432 static int read_pin_defaults(struct hda_codec *codec) in read_pin_defaults() argument
436 for_each_hda_codec_node(nid, codec) { in read_pin_defaults()
438 unsigned int wcaps = get_wcaps(codec, nid); in read_pin_defaults()
442 pin = snd_array_new(&codec->init_pins); in read_pin_defaults()
446 pin->cfg = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
450 * fixme: if any codec is different, need fix here in read_pin_defaults()
452 pin->ctrl = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
460 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, in look_up_pincfg() argument
477 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
487 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) in snd_hda_add_pincfg()
491 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
504 * @codec: the HDA codec
512 int snd_hda_codec_set_pincfg(struct hda_codec *codec, in snd_hda_codec_set_pincfg() argument
515 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); in snd_hda_codec_set_pincfg()
521 * @codec: the HDA codec
528 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pincfg() argument
535 mutex_lock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
536 pin = look_up_pincfg(codec, &codec->user_pins, nid); in snd_hda_codec_get_pincfg()
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()
556 * @codec: the HDA codec
564 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_set_pin_target() argument
569 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_set_pin_target()
579 * @codec: the HDA codec
582 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pin_target() argument
586 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pin_target()
595 * @codec: the HDA codec
600 void snd_hda_shutup_pins(struct hda_codec *codec) in snd_hda_shutup_pins() argument
608 if (codec->bus->shutdown) in snd_hda_shutup_pins()
610 snd_array_for_each(&codec->init_pins, i, pin) { in snd_hda_shutup_pins()
612 snd_hda_codec_read(codec, pin->nid, 0, in snd_hda_shutup_pins()
615 codec->pins_shutup = 1; in snd_hda_shutup_pins()
621 static void restore_shutup_pins(struct hda_codec *codec) in restore_shutup_pins() argument
626 if (!codec->pins_shutup) in restore_shutup_pins()
628 if (codec->bus->shutdown) in restore_shutup_pins()
630 snd_array_for_each(&codec->init_pins, i, pin) { in restore_shutup_pins()
631 snd_hda_codec_write(codec, pin->nid, 0, in restore_shutup_pins()
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()
711 snd_device_free(pcm->codec->card, pcm->pcm); in release_pcm()
712 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); in release_pcm()
723 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, in snd_hda_codec_pcm_new() argument
733 pcm->codec = codec; in snd_hda_codec_pcm_new()
743 list_add_tail(&pcm->list, &codec->pcm_list_head); in snd_hda_codec_pcm_new()
749 * codec destructor
751 static void codec_release_pcms(struct hda_codec *codec) in codec_release_pcms() argument
755 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { in codec_release_pcms()
758 snd_device_disconnect(codec->card, pcm->pcm); in codec_release_pcms()
763 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) in snd_hda_codec_cleanup_for_unbind() argument
765 if (codec->registered) { in snd_hda_codec_cleanup_for_unbind()
767 pm_runtime_get_noresume(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
768 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
769 codec->registered = 0; in snd_hda_codec_cleanup_for_unbind()
772 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_cleanup_for_unbind()
773 if (!codec->in_freeing) in snd_hda_codec_cleanup_for_unbind()
774 snd_hda_ctls_clear(codec); in snd_hda_codec_cleanup_for_unbind()
775 codec_release_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
776 snd_hda_detach_beep_device(codec); in snd_hda_codec_cleanup_for_unbind()
777 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); in snd_hda_codec_cleanup_for_unbind()
778 snd_hda_jack_tbl_clear(codec); in snd_hda_codec_cleanup_for_unbind()
779 codec->proc_widget_hook = NULL; in snd_hda_codec_cleanup_for_unbind()
780 codec->spec = NULL; in snd_hda_codec_cleanup_for_unbind()
783 snd_array_free(&codec->driver_pins); in snd_hda_codec_cleanup_for_unbind()
784 snd_array_free(&codec->cvt_setups); in snd_hda_codec_cleanup_for_unbind()
785 snd_array_free(&codec->spdif_out); in snd_hda_codec_cleanup_for_unbind()
786 snd_array_free(&codec->verbs); in snd_hda_codec_cleanup_for_unbind()
787 codec->preset = NULL; in snd_hda_codec_cleanup_for_unbind()
788 codec->follower_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
789 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
790 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
791 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
792 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
793 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
794 codec->configured = 0; in snd_hda_codec_cleanup_for_unbind()
798 static unsigned int hda_set_power_state(struct hda_codec *codec,
801 /* enable/disable display power per codec */
802 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) in snd_hda_codec_display_power() argument
804 if (codec->display_power_control) in snd_hda_codec_display_power()
805 snd_hdac_display_power(&codec->bus->core, codec->addr, enable); in snd_hda_codec_display_power()
809 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
811 if (codec->registered) in snd_hda_codec_register()
813 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
814 snd_hda_codec_display_power(codec, true); in snd_hda_codec_register()
815 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
817 snd_hda_power_down(codec); in snd_hda_codec_register()
818 codec->registered = 1; in snd_hda_codec_register()
830 struct hda_codec *codec = device->device_data; in snd_hda_codec_dev_free() local
832 codec->in_freeing = 1; in snd_hda_codec_dev_free()
838 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_dev_free()
839 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_dev_free()
840 snd_hda_codec_display_power(codec, false); in snd_hda_codec_dev_free()
846 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_dev_free()
847 put_device(hda_codec_dev(codec)); in snd_hda_codec_dev_free()
854 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
856 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
857 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
858 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
859 kfree(codec->modelname); in snd_hda_codec_dev_release()
860 kfree(codec->wcaps); in snd_hda_codec_dev_release()
866 if (codec->core.type == HDA_DEV_LEGACY) in snd_hda_codec_dev_release()
867 kfree(codec); in snd_hda_codec_dev_release()
876 struct hda_codec *codec; in snd_hda_codec_device_init() local
886 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_hda_codec_device_init()
887 if (!codec) in snd_hda_codec_device_init()
891 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr); in snd_hda_codec_device_init()
893 kfree(codec); in snd_hda_codec_device_init()
897 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_device_init()
898 *codecp = codec; in snd_hda_codec_device_init()
904 * snd_hda_codec_new - create a HDA codec
906 * @card: card for this codec
907 * @codec_addr: the codec address
908 * @codecp: the pointer to store the generated codec
926 unsigned int codec_addr, struct hda_codec *codec) in snd_hda_codec_device_new() argument
943 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_device_new()
944 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_device_new()
946 codec->bus = bus; in snd_hda_codec_device_new()
947 codec->card = card; in snd_hda_codec_device_new()
948 codec->addr = codec_addr; in snd_hda_codec_device_new()
949 mutex_init(&codec->spdif_mutex); in snd_hda_codec_device_new()
950 mutex_init(&codec->control_mutex); in snd_hda_codec_device_new()
951 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_new()
952 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_device_new()
953 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_new()
954 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_device_new()
955 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_device_new()
956 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_device_new()
957 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_device_new()
958 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_device_new()
959 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_device_new()
960 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_device_new()
962 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_device_new()
963 codec->depop_delay = -1; in snd_hda_codec_device_new()
964 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_device_new()
967 codec->power_jiffies = jiffies; in snd_hda_codec_device_new()
970 snd_hda_sysfs_init(codec); in snd_hda_codec_device_new()
972 if (codec->bus->modelname) { in snd_hda_codec_device_new()
973 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_device_new()
974 if (!codec->modelname) { in snd_hda_codec_device_new()
980 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_device_new()
981 err = read_widget_caps(codec, fg); in snd_hda_codec_device_new()
984 err = read_pin_defaults(codec); in snd_hda_codec_device_new()
989 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_device_new()
990 codec->core.dev.power.power_state = PMSG_ON; in snd_hda_codec_device_new()
992 snd_hda_codec_proc_new(codec); in snd_hda_codec_device_new()
994 snd_hda_create_hwdep(codec); in snd_hda_codec_device_new()
996 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_device_new()
997 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_device_new()
1000 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_device_new()
1004 /* PM runtime needs to be enabled later after binding codec */ in snd_hda_codec_device_new()
1005 pm_runtime_forbid(&codec->core.dev); in snd_hda_codec_device_new()
1010 put_device(hda_codec_dev(codec)); in snd_hda_codec_device_new()
1017 * @codec: the HDA codec
1020 * the given codec.
1022 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
1027 err = snd_hdac_refresh_widgets(&codec->core); in snd_hda_codec_update_widgets()
1034 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
1035 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
1036 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
1040 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
1041 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
1048 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
1055 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
1058 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
1067 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
1073 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
1077 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
1086 * snd_hda_codec_setup_stream - set up the codec for streaming
1087 * @codec: the CODEC to set up
1093 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
1105 codec_dbg(codec, in snd_hda_codec_setup_stream()
1108 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
1112 if (codec->patch_ops.stream_pm) in snd_hda_codec_setup_stream()
1113 codec->patch_ops.stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1114 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1115 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1116 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1117 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1118 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1124 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1125 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1135 static void really_cleanup_stream(struct hda_codec *codec,
1139 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1140 * @codec: the CODEC to clean up
1144 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1152 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1155 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1156 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1163 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1170 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1175 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1177 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1181 if (codec->patch_ops.stream_pm) in really_cleanup_stream()
1182 codec->patch_ops.stream_pm(codec, nid, false); in really_cleanup_stream()
1186 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1192 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1202 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1207 snd_array_for_each(&codec->cvt_setups, i, p) { in hda_cleanup_all_streams()
1209 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1220 * @codec: the HD-auio codec
1230 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1232 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1233 nid = codec->core.afg; in query_amp_caps()
1234 return snd_hda_param_read(codec, nid, in query_amp_caps()
1242 * @codec: the HD-audio codec
1249 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1254 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1255 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1263 * @codec: the CODEC to clean up
1274 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1279 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1280 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1282 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1286 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid, in encode_amp() argument
1292 if ((query_amp_caps(codec, nid, dir) & in encode_amp()
1300 * @codec: HD-audio codec
1310 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1313 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_update()
1315 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1321 * @codec: HD-audio codec
1331 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1339 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1347 * @codec: the HDA codec
1359 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1362 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1364 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1366 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val); in snd_hda_codec_amp_init()
1372 * @codec: the HDA codec
1381 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1389 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1395 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1398 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1426 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1428 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1439 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1443 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1453 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1462 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1465 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1480 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1489 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1491 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1517 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1521 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in get_ctl_amp_tlv() local
1536 caps = query_amp_caps(codec, nid, dir); in get_ctl_amp_tlv()
1576 * @codec: HD-audio codec
1585 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1591 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1604 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1614 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1619 * @codec: HD-audio codec
1624 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1627 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1631 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1637 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1644 * snd_hda_ctl_add - Add a control element and assign to the codec
1645 * @codec: HD-audio codec
1649 * Add the given control element to an array inside the codec instance.
1650 * All control elements belonging to a codec are supposed to be added
1655 * The assignment is shown in the codec proc file.
1662 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1678 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1681 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1693 * @codec: HD-audio codec
1698 * Add the given control element to an array inside the codec instance.
1702 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, in snd_hda_add_nid() argument
1708 item = snd_array_new(&codec->nids); in snd_hda_add_nid()
1716 codec_err(codec, "no NID for mapping control %s:%d:%d\n", in snd_hda_add_nid()
1723 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1724 * @codec: HD-audio codec
1726 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1729 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1730 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1731 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1732 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1733 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1745 struct hda_codec *codec; in snd_hda_lock_devices() local
1754 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1756 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1790 * snd_hda_codec_reset - Clear all objects assigned to the codec
1791 * @codec: HD-audio codec
1793 * This frees the all PCM and control elements assigned to the codec, and
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
1936 * @codec: HD-audio codec
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()
2010 * @codec: the HDA codec
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
2116 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2122 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2125 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2170 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_get()
2172 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2173 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2178 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2237 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2242 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2244 d = codec->follower_dig_outs; in set_dig_out()
2248 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2252 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2266 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2279 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_default_put()
2281 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2282 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2293 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2294 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2307 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_get()
2309 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2310 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2312 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2316 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2319 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2321 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2323 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2337 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_out_switch_put()
2339 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2340 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2348 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2349 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2387 * @codec: the HDA codec
2396 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2408 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2417 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2427 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2429 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2432 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2436 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2440 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2441 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2446 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2456 * @codec: the HDA codec
2461 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2467 snd_array_for_each(&codec->spdif_out, i, spdif) { in snd_hda_spdif_out_of_nid()
2477 * @codec: the HDA codec
2482 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2486 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_unassign()
2488 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2489 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2491 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2497 * @codec: the HDA codec
2503 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2508 if (WARN_ON(codec->spdif_out.used <= idx)) in snd_hda_spdif_ctls_assign()
2510 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2511 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2515 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2517 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2550 * @codec: the HDA codec
2553 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2564 /* ATTENTION: here mout is passed as private_data, instead of codec */ in snd_hda_create_spdif_share_sw()
2565 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2580 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2592 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2593 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2595 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2596 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2599 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2611 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2641 * @codec: the HDA codec
2649 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2656 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2658 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2662 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2666 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2670 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2671 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2680 * @codec: the HDA codec
2685 * If the codec has power_filter set, it evaluates the power state and
2688 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
2693 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2694 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
2698 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
2699 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
2703 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
2711 * @codec: the HDA codec
2716 * This can be used a codec power_filter callback.
2718 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
2722 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
2725 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
2726 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
2727 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
2737 * set power state of the codec, and return the power state
2739 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
2742 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
2749 if (codec->depop_delay < 0) in hda_set_power_state()
2750 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
2751 else if (codec->depop_delay > 0) in hda_set_power_state()
2752 msleep(codec->depop_delay); in hda_set_power_state()
2758 if (codec->patch_ops.set_power_state) in hda_set_power_state()
2759 codec->patch_ops.set_power_state(codec, fg, in hda_set_power_state()
2763 if (codec->power_filter) in hda_set_power_state()
2764 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
2766 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
2769 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
2771 state = snd_hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
2780 * this is called at the end of codec parsing
2782 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
2787 if (!codec->power_filter) in sync_power_up_states()
2790 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
2791 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
2795 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
2798 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
2799 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
2806 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
2808 if (codec->init_verbs.list) in hda_exec_init_verbs()
2809 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
2812 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
2817 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
2819 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
2822 codec->power_on_acct += delta; in update_power_acct()
2824 codec->power_off_acct += delta; in update_power_acct()
2825 codec->power_jiffies += delta; in update_power_acct()
2828 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
2830 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
2837 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
2841 snd_hdac_enter_pm(&codec->core); in hda_call_codec_suspend()
2842 if (codec->patch_ops.suspend) in hda_call_codec_suspend()
2843 codec->patch_ops.suspend(codec); in hda_call_codec_suspend()
2844 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
2845 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
2846 update_power_acct(codec, true); in hda_call_codec_suspend()
2847 snd_hdac_leave_pm(&codec->core); in hda_call_codec_suspend()
2852 * kick up codec; used both from PM and power-save
2854 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
2856 snd_hdac_enter_pm(&codec->core); in hda_call_codec_resume()
2857 if (codec->core.regmap) in hda_call_codec_resume()
2858 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
2860 codec->power_jiffies = jiffies; in hda_call_codec_resume()
2862 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
2863 restore_shutup_pins(codec); in hda_call_codec_resume()
2864 hda_exec_init_verbs(codec); in hda_call_codec_resume()
2865 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
2866 if (codec->patch_ops.resume) in hda_call_codec_resume()
2867 codec->patch_ops.resume(codec); in hda_call_codec_resume()
2869 if (codec->patch_ops.init) in hda_call_codec_resume()
2870 codec->patch_ops.init(codec); in hda_call_codec_resume()
2871 snd_hda_regmap_sync(codec); in hda_call_codec_resume()
2874 if (codec->jackpoll_interval) in hda_call_codec_resume()
2875 hda_jackpoll_work(&codec->jackpoll_work.work); in hda_call_codec_resume()
2877 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
2878 codec->core.dev.power.power_state = PMSG_ON; in hda_call_codec_resume()
2879 snd_hdac_leave_pm(&codec->core); in hda_call_codec_resume()
2884 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
2888 if (!codec->card) in hda_codec_runtime_suspend()
2891 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_runtime_suspend()
2892 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
2893 if (codec->link_down_at_suspend || in hda_codec_runtime_suspend()
2894 (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
2896 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
2897 snd_hda_codec_display_power(codec, false); in hda_codec_runtime_suspend()
2903 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
2906 if (!codec->card) in hda_codec_runtime_resume()
2909 snd_hda_codec_display_power(codec, true); in hda_codec_runtime_resume()
2910 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
2911 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
2927 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_pm_complete() local
2933 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval || in hda_codec_pm_complete()
2934 hda_codec_need_resume(codec) || codec->forced_resume)) in hda_codec_pm_complete()
2985 /* suspend the codec at shutdown; called from driver's shutdown callback */
2986 void snd_hda_codec_shutdown(struct hda_codec *codec) in snd_hda_codec_shutdown() argument
2990 list_for_each_entry(cpcm, &codec->pcm_list_head, list) in snd_hda_codec_shutdown()
2993 pm_runtime_force_suspend(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
2994 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_shutdown()
3000 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3005 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3038 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3041 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3043 if (codec->patch_ops.init) in snd_hda_codec_build_controls()
3044 err = codec->patch_ops.init(codec); in snd_hda_codec_build_controls()
3045 if (!err && codec->patch_ops.build_controls) in snd_hda_codec_build_controls()
3046 err = codec->patch_ops.build_controls(codec); in snd_hda_codec_build_controls()
3051 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3055 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3056 hda_jackpoll_work(&codec->jackpoll_work.work); in snd_hda_codec_build_controls()
3058 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3059 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3068 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3075 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3080 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3085 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3088 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3092 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3099 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3124 * codec prepare/cleanup entries
3128 * @codec: the HDA codec
3134 * Calls the prepare callback set by the codec with the given arguments.
3137 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3144 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3146 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3151 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3152 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3159 * @codec: the HDA codec
3163 * Calls the cleanup callback set by the codec with the given arguments.
3165 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3169 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3171 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3172 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3229 /* call build_pcms ops of the given codec and set up the default parameters */
3230 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3235 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3238 if (!codec->patch_ops.build_pcms) in snd_hda_codec_parse_pcms()
3241 err = codec->patch_ops.build_pcms(codec); in snd_hda_codec_parse_pcms()
3243 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3244 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3248 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3256 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3258 codec_warn(codec, in snd_hda_codec_parse_pcms()
3270 /* assign all PCMs of the given codec */
3271 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3273 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3277 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3282 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3294 err = snd_hda_attach_pcm_stream(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3296 codec_err(codec, in snd_hda_codec_build_pcms()
3297 "cannot attach PCM stream %d for codec #%d\n", in snd_hda_codec_build_pcms()
3298 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3308 * @codec: the HDA codec
3316 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3325 continue; /* skip this codec private value */ in snd_hda_add_new_ctls()
3327 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3334 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3338 * the codec addr; if it still fails (or it's the in snd_hda_add_new_ctls()
3339 * primary codec), then try another control index in snd_hda_add_new_ctls()
3341 if (!addr && codec->core.addr) in snd_hda_add_new_ctls()
3342 addr = codec->core.addr; in snd_hda_add_new_ctls()
3344 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3357 static void codec_set_power_save(struct hda_codec *codec, int delay) in codec_set_power_save() argument
3359 struct device *dev = hda_codec_dev(codec); in codec_set_power_save()
3361 if (delay == 0 && codec->auto_runtime_pm) in codec_set_power_save()
3394 * @codec: HD-audio codec
3405 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3423 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3428 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3436 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
3472 * @codec: the HDA codec
3478 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
3493 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
3533 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
3540 spdif = snd_hda_spdif_out_of_nid(codec, nid); in setup_dig_out_stream()
3547 curr_fmt = snd_hda_codec_read(codec, nid, 0, in setup_dig_out_stream()
3549 reset = codec->spdif_status_reset && in setup_dig_out_stream()
3556 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3559 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); in setup_dig_out_stream()
3560 if (codec->follower_dig_outs) { in setup_dig_out_stream()
3562 for (d = codec->follower_dig_outs; *d; d++) in setup_dig_out_stream()
3563 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, in setup_dig_out_stream()
3568 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
3572 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) in cleanup_dig_out_stream() argument
3574 snd_hda_codec_cleanup_stream(codec, nid); in cleanup_dig_out_stream()
3575 if (codec->follower_dig_outs) { in cleanup_dig_out_stream()
3577 for (d = codec->follower_dig_outs; *d; d++) in cleanup_dig_out_stream()
3578 snd_hda_codec_cleanup_stream(codec, *d); in cleanup_dig_out_stream()
3584 * @codec: the HDA codec
3587 int snd_hda_multi_out_dig_open(struct hda_codec *codec, in snd_hda_multi_out_dig_open() argument
3590 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3593 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_open()
3595 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
3602 * @codec: the HDA codec
3608 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
3614 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3615 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
3616 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
3623 * @codec: the HDA codec
3626 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
3629 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3630 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
3631 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
3638 * @codec: the HDA codec
3641 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
3644 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3646 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
3653 * @codec: the HDA codec
3662 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
3680 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
3685 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3698 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
3707 * @codec: the HDA codec
3716 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
3727 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3728 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3732 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3736 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
3740 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
3743 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
3746 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
3751 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
3756 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
3763 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3766 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
3779 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
3789 * @codec: the HDA codec
3792 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
3799 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
3801 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
3804 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3808 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
3810 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3812 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
3815 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
3822 * @codec: the HDA codec
3828 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
3832 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
3834 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
3851 * @codec: the HDA codec
3855 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
3868 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
3907 * @codec: the HDA codec
3910 * @cached: access over codec pinctl cache or direct write
3918 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
3921 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
3922 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
3924 return snd_hda_codec_write_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
3927 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
3934 * @codec: the HDA codec
3944 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
3950 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
3978 struct hda_codec *codec; in snd_hda_bus_reset_codecs() local
3980 list_for_each_codec(codec, bus) { in snd_hda_bus_reset_codecs()
3982 if (current_work() != &codec->jackpoll_work.work) in snd_hda_bus_reset_codecs()
3983 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset_codecs()
3985 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset_codecs()
3986 hda_call_codec_suspend(codec); in snd_hda_bus_reset_codecs()
3987 hda_call_codec_resume(codec); in snd_hda_bus_reset_codecs()
4014 MODULE_DESCRIPTION("HDA codec core");