Lines Matching refs:codec
43 #define codec_in_pm(codec) atomic_read(&(codec)->core.in_pm) argument
44 #define hda_codec_is_power_on(codec) \ argument
45 (!pm_runtime_suspended(hda_codec_dev(codec)))
47 #define codec_in_pm(codec) 0 argument
48 #define hda_codec_is_power_on(codec) 1 argument
51 #define codec_has_epss(codec) \ argument
52 ((codec)->core.power_caps & AC_PWRST_EPSS)
53 #define codec_has_clkstop(codec) \ argument
54 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
132 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in codec_exec_verb() local
133 struct hda_bus *bus = codec->bus; in codec_exec_verb()
140 snd_hda_power_up_pm(codec); in codec_exec_verb()
144 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, in codec_exec_verb()
148 snd_hda_power_down_pm(codec); in codec_exec_verb()
149 if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) { in codec_exec_verb()
151 codec_dbg(codec, in codec_exec_verb()
158 if (!err || codec_in_pm(codec)) in codec_exec_verb()
175 unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_read() argument
179 unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); in snd_hda_codec_read()
181 if (snd_hdac_exec_verb(&codec->core, cmd, flags, &res)) in snd_hda_codec_read()
199 int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, in snd_hda_codec_write() argument
202 unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); in snd_hda_codec_write()
203 return snd_hdac_exec_verb(&codec->core, cmd, flags, NULL); in snd_hda_codec_write()
215 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) in snd_hda_sequence_write() argument
218 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); in snd_hda_sequence_write()
232 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid) in lookup_conn_list() argument
235 list_for_each_entry(p, &codec->conn_list, list) { in lookup_conn_list()
242 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in add_conn_list() argument
253 list_add(&p->list, &codec->conn_list); in add_conn_list()
257 static void remove_conn_list(struct hda_codec *codec) in remove_conn_list() argument
259 while (!list_empty(&codec->conn_list)) { in remove_conn_list()
261 p = list_first_entry(&codec->conn_list, typeof(*p), list); in remove_conn_list()
268 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) in read_and_add_raw_conns() argument
274 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); in read_and_add_raw_conns()
276 len = snd_hda_get_num_raw_conns(codec, nid); in read_and_add_raw_conns()
280 len = snd_hda_get_raw_connections(codec, nid, result, len); in read_and_add_raw_conns()
283 len = snd_hda_override_conn_list(codec, nid, len, result); in read_and_add_raw_conns()
304 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_conn_list() argument
314 p = lookup_conn_list(codec, nid); in snd_hda_get_conn_list()
323 err = read_and_add_raw_conns(codec, nid); in snd_hda_get_conn_list()
343 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_connections() argument
347 int len = snd_hda_get_conn_list(codec, nid, &list); in snd_hda_get_connections()
351 codec_err(codec, "Too many connections %d for NID 0x%x\n", in snd_hda_get_connections()
374 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, in snd_hda_override_conn_list() argument
379 p = lookup_conn_list(codec, nid); in snd_hda_override_conn_list()
385 return add_conn_list(codec, nid, len, list); in snd_hda_override_conn_list()
400 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, in snd_hda_get_conn_index() argument
406 nums = snd_hda_get_conn_list(codec, mux, &conn); in snd_hda_get_conn_index()
413 codec_dbg(codec, "too deep connection for 0x%x\n", nid); in snd_hda_get_conn_index()
418 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i])); in snd_hda_get_conn_index()
421 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) in snd_hda_get_conn_index()
430 static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid) in get_num_devices() argument
432 unsigned int wcaps = get_wcaps(codec, nid); in get_num_devices()
435 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) || in get_num_devices()
439 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN); in get_num_devices()
440 if (parm == -1 && codec->bus->rirb_error) in get_num_devices()
455 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, in snd_hda_get_devices() argument
461 parm = get_num_devices(codec, nid); in snd_hda_get_devices()
470 parm = snd_hda_codec_read(codec, nid, 0, in snd_hda_get_devices()
472 if (parm == -1 && codec->bus->rirb_error) in snd_hda_get_devices()
579 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) in read_widget_caps() argument
584 codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL); in read_widget_caps()
585 if (!codec->wcaps) in read_widget_caps()
587 nid = codec->core.start_nid; in read_widget_caps()
588 for (i = 0; i < codec->core.num_nodes; i++, nid++) in read_widget_caps()
589 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, in read_widget_caps()
595 static int read_pin_defaults(struct hda_codec *codec) in read_pin_defaults() argument
599 for_each_hda_codec_node(nid, codec) { in read_pin_defaults()
601 unsigned int wcaps = get_wcaps(codec, nid); in read_pin_defaults()
605 pin = snd_array_new(&codec->init_pins); in read_pin_defaults()
609 pin->cfg = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
611 pin->ctrl = snd_hda_codec_read(codec, nid, 0, in read_pin_defaults()
619 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec, in look_up_pincfg() argument
635 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, in snd_hda_add_pincfg() argument
649 pin = look_up_pincfg(codec, list, nid); in snd_hda_add_pincfg()
670 int snd_hda_codec_set_pincfg(struct hda_codec *codec, in snd_hda_codec_set_pincfg() argument
673 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg); in snd_hda_codec_set_pincfg()
686 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pincfg() argument
693 mutex_lock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
694 pin = look_up_pincfg(codec, &codec->user_pins, nid); in snd_hda_codec_get_pincfg()
697 mutex_unlock(&codec->user_mutex); in snd_hda_codec_get_pincfg()
702 pin = look_up_pincfg(codec, &codec->driver_pins, nid); in snd_hda_codec_get_pincfg()
705 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pincfg()
722 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_set_pin_target() argument
727 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_set_pin_target()
740 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid) in snd_hda_codec_get_pin_target() argument
744 pin = look_up_pincfg(codec, &codec->init_pins, nid); in snd_hda_codec_get_pin_target()
758 void snd_hda_shutup_pins(struct hda_codec *codec) in snd_hda_shutup_pins() argument
764 if (codec->bus->shutdown) in snd_hda_shutup_pins()
766 for (i = 0; i < codec->init_pins.used; i++) { in snd_hda_shutup_pins()
767 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); in snd_hda_shutup_pins()
769 snd_hda_codec_read(codec, pin->nid, 0, in snd_hda_shutup_pins()
772 codec->pins_shutup = 1; in snd_hda_shutup_pins()
778 static void restore_shutup_pins(struct hda_codec *codec) in restore_shutup_pins() argument
781 if (!codec->pins_shutup) in restore_shutup_pins()
783 if (codec->bus->shutdown) in restore_shutup_pins()
785 for (i = 0; i < codec->init_pins.used; i++) { in restore_shutup_pins()
786 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); in restore_shutup_pins()
787 snd_hda_codec_write(codec, pin->nid, 0, in restore_shutup_pins()
791 codec->pins_shutup = 0; in restore_shutup_pins()
797 struct hda_codec *codec = in hda_jackpoll_work() local
800 snd_hda_jack_set_dirty_all(codec); in hda_jackpoll_work()
801 snd_hda_jack_poll_all(codec); in hda_jackpoll_work()
803 if (!codec->jackpoll_interval) in hda_jackpoll_work()
806 schedule_delayed_work(&codec->jackpoll_work, in hda_jackpoll_work()
807 codec->jackpoll_interval); in hda_jackpoll_work()
811 static void free_init_pincfgs(struct hda_codec *codec) in free_init_pincfgs() argument
813 snd_array_free(&codec->driver_pins); in free_init_pincfgs()
815 snd_array_free(&codec->user_pins); in free_init_pincfgs()
817 snd_array_free(&codec->init_pins); in free_init_pincfgs()
834 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) in get_hda_cvt_setup() argument
839 for (i = 0; i < codec->cvt_setups.used; i++) { in get_hda_cvt_setup()
840 p = snd_array_elem(&codec->cvt_setups, i); in get_hda_cvt_setup()
844 p = snd_array_new(&codec->cvt_setups); in get_hda_cvt_setup()
858 snd_device_free(pcm->codec->card, pcm->pcm); in release_pcm()
859 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); in release_pcm()
870 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, in snd_hda_codec_pcm_new() argument
880 pcm->codec = codec; in snd_hda_codec_pcm_new()
890 list_add_tail(&pcm->list, &codec->pcm_list_head); in snd_hda_codec_pcm_new()
898 static void codec_release_pcms(struct hda_codec *codec) in codec_release_pcms() argument
902 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { in codec_release_pcms()
905 snd_device_disconnect(codec->card, pcm->pcm); in codec_release_pcms()
910 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) in snd_hda_codec_cleanup_for_unbind() argument
912 if (codec->registered) { in snd_hda_codec_cleanup_for_unbind()
914 pm_runtime_get_noresume(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
915 pm_runtime_disable(hda_codec_dev(codec)); in snd_hda_codec_cleanup_for_unbind()
916 codec->registered = 0; in snd_hda_codec_cleanup_for_unbind()
919 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_codec_cleanup_for_unbind()
920 if (!codec->in_freeing) in snd_hda_codec_cleanup_for_unbind()
921 snd_hda_ctls_clear(codec); in snd_hda_codec_cleanup_for_unbind()
922 codec_release_pcms(codec); in snd_hda_codec_cleanup_for_unbind()
923 snd_hda_detach_beep_device(codec); in snd_hda_codec_cleanup_for_unbind()
924 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); in snd_hda_codec_cleanup_for_unbind()
925 snd_hda_jack_tbl_clear(codec); in snd_hda_codec_cleanup_for_unbind()
926 codec->proc_widget_hook = NULL; in snd_hda_codec_cleanup_for_unbind()
927 codec->spec = NULL; in snd_hda_codec_cleanup_for_unbind()
930 snd_array_free(&codec->driver_pins); in snd_hda_codec_cleanup_for_unbind()
931 snd_array_free(&codec->cvt_setups); in snd_hda_codec_cleanup_for_unbind()
932 snd_array_free(&codec->spdif_out); in snd_hda_codec_cleanup_for_unbind()
933 snd_array_free(&codec->verbs); in snd_hda_codec_cleanup_for_unbind()
934 codec->preset = NULL; in snd_hda_codec_cleanup_for_unbind()
935 codec->slave_dig_outs = NULL; in snd_hda_codec_cleanup_for_unbind()
936 codec->spdif_status_reset = 0; in snd_hda_codec_cleanup_for_unbind()
937 snd_array_free(&codec->mixers); in snd_hda_codec_cleanup_for_unbind()
938 snd_array_free(&codec->nids); in snd_hda_codec_cleanup_for_unbind()
939 remove_conn_list(codec); in snd_hda_codec_cleanup_for_unbind()
940 snd_hdac_regmap_exit(&codec->core); in snd_hda_codec_cleanup_for_unbind()
943 static unsigned int hda_set_power_state(struct hda_codec *codec,
947 void snd_hda_codec_register(struct hda_codec *codec) in snd_hda_codec_register() argument
949 if (codec->registered) in snd_hda_codec_register()
951 if (device_is_registered(hda_codec_dev(codec))) { in snd_hda_codec_register()
952 snd_hda_register_beep_device(codec); in snd_hda_codec_register()
953 pm_runtime_enable(hda_codec_dev(codec)); in snd_hda_codec_register()
955 snd_hda_power_down(codec); in snd_hda_codec_register()
956 codec->registered = 1; in snd_hda_codec_register()
968 struct hda_codec *codec = device->device_data; in snd_hda_codec_dev_disconnect() local
970 snd_hda_detach_beep_device(codec); in snd_hda_codec_dev_disconnect()
976 struct hda_codec *codec = device->device_data; in snd_hda_codec_dev_free() local
978 codec->in_freeing = 1; in snd_hda_codec_dev_free()
979 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_dev_free()
980 put_device(hda_codec_dev(codec)); in snd_hda_codec_dev_free()
986 struct hda_codec *codec = dev_to_hda_codec(dev); in snd_hda_codec_dev_release() local
988 free_init_pincfgs(codec); in snd_hda_codec_dev_release()
989 snd_hdac_device_exit(&codec->core); in snd_hda_codec_dev_release()
990 snd_hda_sysfs_clear(codec); in snd_hda_codec_dev_release()
991 kfree(codec->modelname); in snd_hda_codec_dev_release()
992 kfree(codec->wcaps); in snd_hda_codec_dev_release()
993 kfree(codec); in snd_hda_codec_dev_release()
1007 struct hda_codec *codec; in snd_hda_codec_new() local
1022 codec = kzalloc(sizeof(*codec), GFP_KERNEL); in snd_hda_codec_new()
1023 if (!codec) in snd_hda_codec_new()
1027 err = snd_hdac_device_init(&codec->core, &bus->core, component, in snd_hda_codec_new()
1030 kfree(codec); in snd_hda_codec_new()
1034 codec->core.dev.release = snd_hda_codec_dev_release; in snd_hda_codec_new()
1035 codec->core.type = HDA_DEV_LEGACY; in snd_hda_codec_new()
1036 codec->core.exec_verb = codec_exec_verb; in snd_hda_codec_new()
1038 codec->bus = bus; in snd_hda_codec_new()
1039 codec->card = card; in snd_hda_codec_new()
1040 codec->addr = codec_addr; in snd_hda_codec_new()
1041 mutex_init(&codec->spdif_mutex); in snd_hda_codec_new()
1042 mutex_init(&codec->control_mutex); in snd_hda_codec_new()
1043 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); in snd_hda_codec_new()
1044 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); in snd_hda_codec_new()
1045 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_new()
1046 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); in snd_hda_codec_new()
1047 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); in snd_hda_codec_new()
1048 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); in snd_hda_codec_new()
1049 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); in snd_hda_codec_new()
1050 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); in snd_hda_codec_new()
1051 INIT_LIST_HEAD(&codec->conn_list); in snd_hda_codec_new()
1052 INIT_LIST_HEAD(&codec->pcm_list_head); in snd_hda_codec_new()
1054 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); in snd_hda_codec_new()
1055 codec->depop_delay = -1; in snd_hda_codec_new()
1056 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; in snd_hda_codec_new()
1059 codec->power_jiffies = jiffies; in snd_hda_codec_new()
1062 snd_hda_sysfs_init(codec); in snd_hda_codec_new()
1064 if (codec->bus->modelname) { in snd_hda_codec_new()
1065 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); in snd_hda_codec_new()
1066 if (!codec->modelname) { in snd_hda_codec_new()
1072 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_new()
1073 err = read_widget_caps(codec, fg); in snd_hda_codec_new()
1076 err = read_pin_defaults(codec); in snd_hda_codec_new()
1081 hda_set_power_state(codec, AC_PWRST_D0); in snd_hda_codec_new()
1083 snd_hda_codec_proc_new(codec); in snd_hda_codec_new()
1085 snd_hda_create_hwdep(codec); in snd_hda_codec_new()
1087 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, in snd_hda_codec_new()
1088 codec->core.subsystem_id, codec->core.revision_id); in snd_hda_codec_new()
1091 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); in snd_hda_codec_new()
1096 *codecp = codec; in snd_hda_codec_new()
1100 put_device(hda_codec_dev(codec)); in snd_hda_codec_new()
1112 int snd_hda_codec_update_widgets(struct hda_codec *codec) in snd_hda_codec_update_widgets() argument
1117 err = snd_hdac_refresh_widgets(&codec->core); in snd_hda_codec_update_widgets()
1124 kfree(codec->wcaps); in snd_hda_codec_update_widgets()
1125 fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in snd_hda_codec_update_widgets()
1126 err = read_widget_caps(codec, fg); in snd_hda_codec_update_widgets()
1130 snd_array_free(&codec->init_pins); in snd_hda_codec_update_widgets()
1131 err = read_pin_defaults(codec); in snd_hda_codec_update_widgets()
1138 static void update_pcm_stream_id(struct hda_codec *codec, in update_pcm_stream_id() argument
1145 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); in update_pcm_stream_id()
1148 snd_hda_codec_write(codec, nid, 0, in update_pcm_stream_id()
1157 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p, in update_pcm_format() argument
1163 oldval = snd_hda_codec_read(codec, nid, 0, in update_pcm_format()
1167 snd_hda_codec_write(codec, nid, 0, in update_pcm_format()
1183 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_setup_stream() argument
1195 codec_dbg(codec, in snd_hda_codec_setup_stream()
1198 p = get_hda_cvt_setup(codec, nid); in snd_hda_codec_setup_stream()
1202 if (codec->patch_ops.stream_pm) in snd_hda_codec_setup_stream()
1203 codec->patch_ops.stream_pm(codec, nid, true); in snd_hda_codec_setup_stream()
1204 if (codec->pcm_format_first) in snd_hda_codec_setup_stream()
1205 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1206 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); in snd_hda_codec_setup_stream()
1207 if (!codec->pcm_format_first) in snd_hda_codec_setup_stream()
1208 update_pcm_format(codec, p, nid, format); in snd_hda_codec_setup_stream()
1214 type = get_wcaps_type(get_wcaps(codec, nid)); in snd_hda_codec_setup_stream()
1215 list_for_each_codec(c, codec->bus) { in snd_hda_codec_setup_stream()
1226 static void really_cleanup_stream(struct hda_codec *codec,
1235 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid, in __snd_hda_codec_cleanup_stream() argument
1243 if (codec->no_sticky_stream) in __snd_hda_codec_cleanup_stream()
1246 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid); in __snd_hda_codec_cleanup_stream()
1247 p = get_hda_cvt_setup(codec, nid); in __snd_hda_codec_cleanup_stream()
1254 really_cleanup_stream(codec, p); in __snd_hda_codec_cleanup_stream()
1261 static void really_cleanup_stream(struct hda_codec *codec, in really_cleanup_stream() argument
1266 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); in really_cleanup_stream()
1268 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0 in really_cleanup_stream()
1272 if (codec->patch_ops.stream_pm) in really_cleanup_stream()
1273 codec->patch_ops.stream_pm(codec, nid, false); in really_cleanup_stream()
1277 static void purify_inactive_streams(struct hda_codec *codec) in purify_inactive_streams() argument
1282 list_for_each_codec(c, codec->bus) { in purify_inactive_streams()
1294 static void hda_cleanup_all_streams(struct hda_codec *codec) in hda_cleanup_all_streams() argument
1298 for (i = 0; i < codec->cvt_setups.used; i++) { in hda_cleanup_all_streams()
1299 struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); in hda_cleanup_all_streams()
1301 really_cleanup_stream(codec, p); in hda_cleanup_all_streams()
1322 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) in query_amp_caps() argument
1324 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) in query_amp_caps()
1325 nid = codec->core.afg; in query_amp_caps()
1326 return snd_hda_param_read(codec, nid, in query_amp_caps()
1341 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, in snd_hda_check_amp_caps() argument
1346 if (get_wcaps(codec, nid) & (1 << (dir + 1))) in snd_hda_check_amp_caps()
1347 if (query_amp_caps(codec, nid, dir) & bits) in snd_hda_check_amp_caps()
1366 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_override_amp_caps() argument
1371 snd_hda_override_wcaps(codec, nid, in snd_hda_override_amp_caps()
1372 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); in snd_hda_override_amp_caps()
1374 return snd_hdac_override_parm(&codec->core, nid, parm, caps); in snd_hda_override_amp_caps()
1390 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_update() argument
1396 if ((query_amp_caps(codec, nid, dir) & in snd_hda_codec_amp_update()
1399 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); in snd_hda_codec_amp_update()
1415 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_stereo() argument
1423 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction, in snd_hda_codec_amp_stereo()
1443 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, in snd_hda_codec_amp_init() argument
1448 if (!codec->core.regmap) in snd_hda_codec_amp_init()
1450 regcache_cache_only(codec->core.regmap, true); in snd_hda_codec_amp_init()
1451 orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in snd_hda_codec_amp_init()
1452 regcache_cache_only(codec->core.regmap, false); in snd_hda_codec_amp_init()
1455 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val); in snd_hda_codec_amp_init()
1470 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, in snd_hda_codec_amp_init_stereo() argument
1478 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir, in snd_hda_codec_amp_init_stereo()
1484 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, in get_amp_max_value() argument
1487 u32 caps = query_amp_caps(codec, nid, dir); in get_amp_max_value()
1506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_info() local
1515 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); in snd_hda_mixer_amp_volume_info()
1517 codec_warn(codec, in snd_hda_mixer_amp_volume_info()
1528 read_amp_value(struct hda_codec *codec, hda_nid_t nid, in read_amp_value() argument
1532 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); in read_amp_value()
1542 update_amp_value(struct hda_codec *codec, hda_nid_t nid, in update_amp_value() argument
1551 maxval = get_amp_max_value(codec, nid, dir, 0); in update_amp_value()
1554 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, in update_amp_value()
1569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_get() local
1578 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1580 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs); in snd_hda_mixer_amp_volume_get()
1596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_volume_put() local
1606 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1610 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); in snd_hda_mixer_amp_volume_put()
1628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_tlv() local
1637 caps = query_amp_caps(codec, nid, dir); in snd_hda_mixer_amp_tlv()
1668 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, in snd_hda_set_vmaster_tlv() argument
1674 caps = query_amp_caps(codec, nid, dir); in snd_hda_set_vmaster_tlv()
1687 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) in find_mixer_ctl() argument
1697 return snd_ctl_find_id(codec->card, &id); in find_mixer_ctl()
1707 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, in snd_hda_find_mixer_ctl() argument
1710 return find_mixer_ctl(codec, name, 0, 0); in snd_hda_find_mixer_ctl()
1714 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, in find_empty_mixer_ctl_idx() argument
1720 if (!find_mixer_ctl(codec, name, 0, idx)) in find_empty_mixer_ctl_idx()
1745 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, in snd_hda_ctl_add() argument
1761 err = snd_ctl_add(codec->card, kctl); in snd_hda_ctl_add()
1764 item = snd_array_new(&codec->mixers); in snd_hda_ctl_add()
1785 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl, in snd_hda_add_nid() argument
1791 item = snd_array_new(&codec->nids); in snd_hda_add_nid()
1799 codec_err(codec, "no NID for mapping control %s:%d:%d\n", in snd_hda_add_nid()
1809 void snd_hda_ctls_clear(struct hda_codec *codec) in snd_hda_ctls_clear() argument
1812 struct hda_nid_item *items = codec->mixers.list; in snd_hda_ctls_clear()
1813 for (i = 0; i < codec->mixers.used; i++) in snd_hda_ctls_clear()
1814 snd_ctl_remove(codec->card, items[i].kctl); in snd_hda_ctls_clear()
1815 snd_array_free(&codec->mixers); in snd_hda_ctls_clear()
1816 snd_array_free(&codec->nids); in snd_hda_ctls_clear()
1828 struct hda_codec *codec; in snd_hda_lock_devices() local
1837 list_for_each_codec(codec, bus) { in snd_hda_lock_devices()
1839 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_lock_devices()
1882 int snd_hda_codec_reset(struct hda_codec *codec) in snd_hda_codec_reset() argument
1884 struct hda_bus *bus = codec->bus; in snd_hda_codec_reset()
1890 snd_hdac_device_unregister(&codec->core); in snd_hda_codec_reset()
1900 static int map_slaves(struct hda_codec *codec, const char * const *slaves, in map_slaves() argument
1907 items = codec->mixers.list; in map_slaves()
1908 for (i = 0; i < codec->mixers.used; i++) { in map_slaves()
1921 err = func(codec, data, sctl); in map_slaves()
1931 static int check_slave_present(struct hda_codec *codec, in check_slave_present() argument
1938 static int get_kctl_0dB_offset(struct hda_codec *codec, in get_kctl_0dB_offset() argument
1960 codec_err(codec, "Mismatching dB step for vmaster slave (%d!=%d)\n", in get_kctl_0dB_offset()
1985 static int init_slave_0dB(struct hda_codec *codec, in init_slave_0dB() argument
1988 int offset = get_kctl_0dB_offset(codec, slave, data); in init_slave_0dB()
1995 static int init_slave_unmute(struct hda_codec *codec, in init_slave_unmute() argument
2001 static int add_slave(struct hda_codec *codec, in add_slave() argument
2026 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, in __snd_hda_add_vmaster() argument
2037 err = map_slaves(codec, slaves, suffix, check_slave_present, NULL); in __snd_hda_add_vmaster()
2039 codec_dbg(codec, "No slave found for %s\n", name); in __snd_hda_add_vmaster()
2045 err = snd_hda_ctl_add(codec, 0, kctl); in __snd_hda_add_vmaster()
2049 err = map_slaves(codec, slaves, suffix, add_slave, kctl); in __snd_hda_add_vmaster()
2057 map_slaves(codec, slaves, suffix, in __snd_hda_add_vmaster()
2118 hook->hook(hook->codec, enabled); in vmaster_hook()
2131 int snd_hda_add_vmaster_hook(struct hda_codec *codec, in snd_hda_add_vmaster_hook() argument
2139 hook->codec = codec; in snd_hda_add_vmaster_hook()
2147 return snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_vmaster_hook()
2160 if (!hook->hook || !hook->codec) in snd_hda_sync_vmaster_hook()
2165 if (hook->codec->bus->shutdown) in snd_hda_sync_vmaster_hook()
2204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get() local
2212 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & in snd_hda_mixer_amp_switch_get()
2215 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & in snd_hda_mixer_amp_switch_get()
2232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put() local
2241 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, in snd_hda_mixer_amp_switch_put()
2247 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, in snd_hda_mixer_amp_switch_put()
2250 hda_call_check_power_status(codec, nid); in snd_hda_mixer_amp_switch_put()
2275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_switch_get() local
2279 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_switch_get()
2284 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_switch_get()
2300 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_switch_put() local
2304 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_switch_put()
2316 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_switch_put()
2332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_info() local
2336 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_info()
2341 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_info()
2357 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_get() local
2361 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_get()
2366 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_get()
2382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_ctls_put() local
2387 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_put()
2397 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_ctls_put()
2415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_bind_tlv() local
2419 mutex_lock(&codec->control_mutex); in snd_hda_mixer_bind_tlv()
2424 mutex_unlock(&codec->control_mutex); in snd_hda_mixer_bind_tlv()
2481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_get() local
2485 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2486 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_get()
2491 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_get()
2550 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, in set_dig_out() argument
2555 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, in set_dig_out()
2557 d = codec->slave_dig_outs; in set_dig_out()
2561 snd_hdac_regmap_update(&codec->core, *d, in set_dig_out()
2565 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, in set_dig_out_convert() argument
2579 set_dig_out(codec, nid, mask, val); in set_dig_out_convert()
2585 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_default_put() local
2592 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2593 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_default_put()
2604 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_default_put()
2605 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_default_put()
2614 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_get() local
2618 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2619 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_get()
2621 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_get()
2625 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid, in set_spdif_ctls() argument
2628 set_dig_out_convert(codec, nid, dig1, dig2); in set_spdif_ctls()
2630 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && in set_spdif_ctls()
2632 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, in set_spdif_ctls()
2639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_out_switch_put() local
2646 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2647 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_out_switch_put()
2655 set_spdif_ctls(codec, nid, val & 0xff, -1); in snd_hda_spdif_out_switch_put()
2656 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_out_switch_put()
2703 int snd_hda_create_dig_out_ctls(struct hda_codec *codec, in snd_hda_create_dig_out_ctls() argument
2715 struct hda_bus *bus = codec->bus; in snd_hda_create_dig_out_ctls()
2724 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0); in snd_hda_create_dig_out_ctls()
2734 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); in snd_hda_create_dig_out_ctls()
2736 codec_err(codec, "too many IEC958 outputs\n"); in snd_hda_create_dig_out_ctls()
2739 spdif = snd_array_new(&codec->spdif_out); in snd_hda_create_dig_out_ctls()
2743 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_dig_out_ctls()
2747 kctl->private_value = codec->spdif_out.used - 1; in snd_hda_create_dig_out_ctls()
2748 err = snd_hda_ctl_add(codec, associated_nid, kctl); in snd_hda_create_dig_out_ctls()
2753 snd_hdac_regmap_read(&codec->core, cvt_nid, in snd_hda_create_dig_out_ctls()
2768 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, in snd_hda_spdif_out_of_nid() argument
2772 for (i = 0; i < codec->spdif_out.used; i++) { in snd_hda_spdif_out_of_nid()
2774 snd_array_elem(&codec->spdif_out, i); in snd_hda_spdif_out_of_nid()
2789 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) in snd_hda_spdif_ctls_unassign() argument
2793 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2794 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_unassign()
2796 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_unassign()
2808 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) in snd_hda_spdif_ctls_assign() argument
2813 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2814 spdif = snd_array_elem(&codec->spdif_out, idx); in snd_hda_spdif_ctls_assign()
2818 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff); in snd_hda_spdif_ctls_assign()
2820 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_ctls_assign()
2856 int snd_hda_create_spdif_share_sw(struct hda_codec *codec, in snd_hda_create_spdif_share_sw() argument
2868 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); in snd_hda_create_spdif_share_sw()
2881 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_get() local
2883 ucontrol->value.integer.value[0] = codec->spdif_in_enable; in snd_hda_spdif_in_switch_get()
2890 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_switch_put() local
2895 mutex_lock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2896 change = codec->spdif_in_enable != val; in snd_hda_spdif_in_switch_put()
2898 codec->spdif_in_enable = val; in snd_hda_spdif_in_switch_put()
2899 snd_hdac_regmap_write(&codec->core, nid, in snd_hda_spdif_in_switch_put()
2902 mutex_unlock(&codec->spdif_mutex); in snd_hda_spdif_in_switch_put()
2909 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_spdif_in_status_get() local
2914 snd_hdac_regmap_read(&codec->core, nid, in snd_hda_spdif_in_status_get()
2952 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) in snd_hda_create_spdif_in_ctls() argument
2959 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); in snd_hda_create_spdif_in_ctls()
2961 codec_err(codec, "too many IEC958 inputs\n"); in snd_hda_create_spdif_in_ctls()
2965 kctl = snd_ctl_new1(dig_mix, codec); in snd_hda_create_spdif_in_ctls()
2969 err = snd_hda_ctl_add(codec, nid, kctl); in snd_hda_create_spdif_in_ctls()
2973 codec->spdif_in_enable = in snd_hda_create_spdif_in_ctls()
2974 snd_hda_codec_read(codec, nid, 0, in snd_hda_create_spdif_in_ctls()
2991 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
2996 for_each_hda_codec_node(nid, codec) { in snd_hda_codec_set_power_to_all()
2997 unsigned int wcaps = get_wcaps(codec, nid); in snd_hda_codec_set_power_to_all()
3001 if (codec->power_filter) { in snd_hda_codec_set_power_to_all()
3002 state = codec->power_filter(codec, nid, power_state); in snd_hda_codec_set_power_to_all()
3006 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, in snd_hda_codec_set_power_to_all()
3015 static unsigned int hda_sync_power_state(struct hda_codec *codec, in hda_sync_power_state() argument
3023 state = snd_hda_codec_read(codec, fg, 0, in hda_sync_power_state()
3047 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, in snd_hda_codec_eapd_power_filter() argument
3051 if (nid == codec->core.afg || nid == codec->core.mfg) in snd_hda_codec_eapd_power_filter()
3054 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && in snd_hda_codec_eapd_power_filter()
3055 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) { in snd_hda_codec_eapd_power_filter()
3056 int eapd = snd_hda_codec_read(codec, nid, 0, in snd_hda_codec_eapd_power_filter()
3068 static unsigned int hda_set_power_state(struct hda_codec *codec, in hda_set_power_state() argument
3071 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; in hda_set_power_state()
3078 if (codec->depop_delay < 0) in hda_set_power_state()
3079 msleep(codec_has_epss(codec) ? 10 : 100); in hda_set_power_state()
3080 else if (codec->depop_delay > 0) in hda_set_power_state()
3081 msleep(codec->depop_delay); in hda_set_power_state()
3087 if (codec->patch_ops.set_power_state) in hda_set_power_state()
3088 codec->patch_ops.set_power_state(codec, fg, in hda_set_power_state()
3092 if (codec->power_filter) in hda_set_power_state()
3093 state = codec->power_filter(codec, fg, state); in hda_set_power_state()
3095 snd_hda_codec_read(codec, fg, flags, in hda_set_power_state()
3098 snd_hda_codec_set_power_to_all(codec, fg, power_state); in hda_set_power_state()
3100 state = hda_sync_power_state(codec, fg, power_state); in hda_set_power_state()
3111 static void sync_power_up_states(struct hda_codec *codec) in sync_power_up_states() argument
3116 if (!codec->power_filter) in sync_power_up_states()
3119 for_each_hda_codec_node(nid, codec) { in sync_power_up_states()
3120 unsigned int wcaps = get_wcaps(codec, nid); in sync_power_up_states()
3124 target = codec->power_filter(codec, nid, AC_PWRST_D0); in sync_power_up_states()
3127 if (!snd_hda_check_power_state(codec, nid, target)) in sync_power_up_states()
3128 snd_hda_codec_write(codec, nid, 0, in sync_power_up_states()
3135 static void hda_exec_init_verbs(struct hda_codec *codec) in hda_exec_init_verbs() argument
3137 if (codec->init_verbs.list) in hda_exec_init_verbs()
3138 snd_hda_sequence_write(codec, codec->init_verbs.list); in hda_exec_init_verbs()
3141 static inline void hda_exec_init_verbs(struct hda_codec *codec) {} in hda_exec_init_verbs() argument
3146 static void update_power_acct(struct hda_codec *codec, bool on) in update_power_acct() argument
3148 unsigned long delta = jiffies - codec->power_jiffies; in update_power_acct()
3151 codec->power_on_acct += delta; in update_power_acct()
3153 codec->power_off_acct += delta; in update_power_acct()
3154 codec->power_jiffies += delta; in update_power_acct()
3157 void snd_hda_update_power_acct(struct hda_codec *codec) in snd_hda_update_power_acct() argument
3159 update_power_acct(codec, hda_codec_is_power_on(codec)); in snd_hda_update_power_acct()
3166 static unsigned int hda_call_codec_suspend(struct hda_codec *codec) in hda_call_codec_suspend() argument
3170 atomic_inc(&codec->core.in_pm); in hda_call_codec_suspend()
3172 if (codec->patch_ops.suspend) in hda_call_codec_suspend()
3173 codec->patch_ops.suspend(codec); in hda_call_codec_suspend()
3174 hda_cleanup_all_streams(codec); in hda_call_codec_suspend()
3175 state = hda_set_power_state(codec, AC_PWRST_D3); in hda_call_codec_suspend()
3176 update_power_acct(codec, true); in hda_call_codec_suspend()
3177 atomic_dec(&codec->core.in_pm); in hda_call_codec_suspend()
3184 static void hda_call_codec_resume(struct hda_codec *codec) in hda_call_codec_resume() argument
3186 atomic_inc(&codec->core.in_pm); in hda_call_codec_resume()
3188 if (codec->core.regmap) in hda_call_codec_resume()
3189 regcache_mark_dirty(codec->core.regmap); in hda_call_codec_resume()
3191 codec->power_jiffies = jiffies; in hda_call_codec_resume()
3193 hda_set_power_state(codec, AC_PWRST_D0); in hda_call_codec_resume()
3194 restore_shutup_pins(codec); in hda_call_codec_resume()
3195 hda_exec_init_verbs(codec); in hda_call_codec_resume()
3196 snd_hda_jack_set_dirty_all(codec); in hda_call_codec_resume()
3197 if (codec->patch_ops.resume) in hda_call_codec_resume()
3198 codec->patch_ops.resume(codec); in hda_call_codec_resume()
3200 if (codec->patch_ops.init) in hda_call_codec_resume()
3201 codec->patch_ops.init(codec); in hda_call_codec_resume()
3202 if (codec->core.regmap) in hda_call_codec_resume()
3203 regcache_sync(codec->core.regmap); in hda_call_codec_resume()
3206 if (codec->jackpoll_interval) in hda_call_codec_resume()
3207 hda_jackpoll_work(&codec->jackpoll_work.work); in hda_call_codec_resume()
3209 snd_hda_jack_report_sync(codec); in hda_call_codec_resume()
3210 atomic_dec(&codec->core.in_pm); in hda_call_codec_resume()
3215 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_suspend() local
3219 cancel_delayed_work_sync(&codec->jackpoll_work); in hda_codec_runtime_suspend()
3220 list_for_each_entry(pcm, &codec->pcm_list_head, list) in hda_codec_runtime_suspend()
3222 state = hda_call_codec_suspend(codec); in hda_codec_runtime_suspend()
3223 if (codec_has_clkstop(codec) && codec_has_epss(codec) && in hda_codec_runtime_suspend()
3225 snd_hdac_codec_link_down(&codec->core); in hda_codec_runtime_suspend()
3231 struct hda_codec *codec = dev_to_hda_codec(dev); in hda_codec_runtime_resume() local
3233 snd_hdac_codec_link_up(&codec->core); in hda_codec_runtime_resume()
3234 hda_call_codec_resume(codec); in hda_codec_runtime_resume()
3251 static int add_std_chmaps(struct hda_codec *codec) in add_std_chmaps() argument
3256 list_for_each_entry(pcm, &codec->pcm_list_head, list) { in add_std_chmaps()
3290 int snd_hda_codec_build_controls(struct hda_codec *codec) in snd_hda_codec_build_controls() argument
3293 hda_exec_init_verbs(codec); in snd_hda_codec_build_controls()
3295 if (codec->patch_ops.init) in snd_hda_codec_build_controls()
3296 err = codec->patch_ops.init(codec); in snd_hda_codec_build_controls()
3297 if (!err && codec->patch_ops.build_controls) in snd_hda_codec_build_controls()
3298 err = codec->patch_ops.build_controls(codec); in snd_hda_codec_build_controls()
3303 err = add_std_chmaps(codec); in snd_hda_codec_build_controls()
3307 if (codec->jackpoll_interval) in snd_hda_codec_build_controls()
3308 hda_jackpoll_work(&codec->jackpoll_work.work); in snd_hda_codec_build_controls()
3310 snd_hda_jack_report_sync(codec); /* call at the last init point */ in snd_hda_codec_build_controls()
3311 sync_power_up_states(codec); in snd_hda_codec_build_controls()
3366 unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, in snd_hda_calc_stream_format() argument
3382 codec_dbg(codec, "invalid rate %d\n", rate); in snd_hda_calc_stream_format()
3387 codec_dbg(codec, "invalid channels %d\n", channels); in snd_hda_calc_stream_format()
3410 codec_dbg(codec, "invalid format width %d\n", in snd_hda_calc_stream_format()
3422 static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) in query_pcm_param() argument
3425 if (nid != codec->core.afg && in query_pcm_param()
3426 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) in query_pcm_param()
3427 val = snd_hda_param_read(codec, nid, AC_PAR_PCM); in query_pcm_param()
3429 val = snd_hda_param_read(codec, codec->core.afg, AC_PAR_PCM); in query_pcm_param()
3435 static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) in query_stream_param() argument
3437 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); in query_stream_param()
3439 streams = snd_hda_param_read(codec, codec->core.afg, AC_PAR_STREAM); in query_stream_param()
3458 int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, in snd_hda_query_supported_pcm() argument
3463 wcaps = get_wcaps(codec, nid); in snd_hda_query_supported_pcm()
3464 val = query_pcm_param(codec, nid); in snd_hda_query_supported_pcm()
3473 codec_err(codec, in snd_hda_query_supported_pcm()
3486 streams = query_stream_param(codec, nid); in snd_hda_query_supported_pcm()
3536 codec_err(codec, in snd_hda_query_supported_pcm()
3563 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, in snd_hda_is_supported_format() argument
3569 val = query_pcm_param(codec, nid); in snd_hda_is_supported_format()
3583 stream = query_stream_param(codec, nid); in snd_hda_is_supported_format()
3624 struct hda_codec *codec, in hda_pcm_default_open_close() argument
3631 struct hda_codec *codec, in hda_pcm_default_prepare() argument
3636 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); in hda_pcm_default_prepare()
3641 struct hda_codec *codec, in hda_pcm_default_cleanup() argument
3644 snd_hda_codec_cleanup_stream(codec, hinfo->nid); in hda_pcm_default_cleanup()
3648 static int set_pcm_default_values(struct hda_codec *codec, in set_pcm_default_values() argument
3655 err = snd_hda_query_supported_pcm(codec, info->nid, in set_pcm_default_values()
3693 int snd_hda_codec_prepare(struct hda_codec *codec, in snd_hda_codec_prepare() argument
3700 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3702 ret = hinfo->ops.prepare(hinfo, codec, stream, format, in snd_hda_codec_prepare()
3707 purify_inactive_streams(codec); in snd_hda_codec_prepare()
3708 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_prepare()
3721 void snd_hda_codec_cleanup(struct hda_codec *codec, in snd_hda_codec_cleanup() argument
3725 mutex_lock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3727 hinfo->ops.cleanup(hinfo, codec, substream); in snd_hda_codec_cleanup()
3728 mutex_unlock(&codec->bus->prepare_mutex); in snd_hda_codec_cleanup()
3786 int snd_hda_codec_parse_pcms(struct hda_codec *codec) in snd_hda_codec_parse_pcms() argument
3791 if (!list_empty(&codec->pcm_list_head)) in snd_hda_codec_parse_pcms()
3794 if (!codec->patch_ops.build_pcms) in snd_hda_codec_parse_pcms()
3797 err = codec->patch_ops.build_pcms(codec); in snd_hda_codec_parse_pcms()
3799 codec_err(codec, "cannot build PCMs for #%d (error %d)\n", in snd_hda_codec_parse_pcms()
3800 codec->core.addr, err); in snd_hda_codec_parse_pcms()
3804 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_parse_pcms()
3812 err = set_pcm_default_values(codec, info); in snd_hda_codec_parse_pcms()
3814 codec_warn(codec, in snd_hda_codec_parse_pcms()
3826 int snd_hda_codec_build_pcms(struct hda_codec *codec) in snd_hda_codec_build_pcms() argument
3828 struct hda_bus *bus = codec->bus; in snd_hda_codec_build_pcms()
3835 err = snd_hda_codec_parse_pcms(codec); in snd_hda_codec_build_pcms()
3840 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { in snd_hda_codec_build_pcms()
3850 err = bus->ops.attach_pcm(bus, codec, cpcm); in snd_hda_codec_build_pcms()
3852 codec_err(codec, in snd_hda_codec_build_pcms()
3854 dev, codec->core.addr); in snd_hda_codec_build_pcms()
3872 int snd_hda_add_new_ctls(struct hda_codec *codec, in snd_hda_add_new_ctls() argument
3883 kctl = snd_ctl_new1(knew, codec); in snd_hda_add_new_ctls()
3890 err = snd_hda_ctl_add(codec, 0, kctl); in snd_hda_add_new_ctls()
3897 if (!addr && codec->core.addr) in snd_hda_add_new_ctls()
3898 addr = codec->core.addr; in snd_hda_add_new_ctls()
3900 idx = find_empty_mixer_ctl_idx(codec, in snd_hda_add_new_ctls()
3913 static void codec_set_power_save(struct hda_codec *codec, int delay) in codec_set_power_save() argument
3915 struct device *dev = hda_codec_dev(codec); in codec_set_power_save()
3958 int snd_hda_check_amp_list_power(struct hda_codec *codec, in snd_hda_check_amp_list_power() argument
3976 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, in snd_hda_check_amp_list_power()
3981 snd_hda_power_up_pm(codec); in snd_hda_check_amp_list_power()
3989 snd_hda_power_down_pm(codec); in snd_hda_check_amp_list_power()
4031 int snd_hda_input_mux_put(struct hda_codec *codec, in snd_hda_input_mux_put() argument
4046 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, in snd_hda_input_mux_put()
4086 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid, in setup_dig_out_stream() argument
4093 spdif = snd_hda_spdif_out_of_nid(codec, nid); in setup_dig_out_stream()
4094 curr_fmt = snd_hda_codec_read(codec, nid, 0, in setup_dig_out_stream()
4096 reset = codec->spdif_status_reset && in setup_dig_out_stream()
4103 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
4106 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); in setup_dig_out_stream()
4107 if (codec->slave_dig_outs) { in setup_dig_out_stream()
4109 for (d = codec->slave_dig_outs; *d; d++) in setup_dig_out_stream()
4110 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, in setup_dig_out_stream()
4115 set_dig_out_convert(codec, nid, in setup_dig_out_stream()
4119 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) in cleanup_dig_out_stream() argument
4121 snd_hda_codec_cleanup_stream(codec, nid); in cleanup_dig_out_stream()
4122 if (codec->slave_dig_outs) { in cleanup_dig_out_stream()
4124 for (d = codec->slave_dig_outs; *d; d++) in cleanup_dig_out_stream()
4125 snd_hda_codec_cleanup_stream(codec, *d); in cleanup_dig_out_stream()
4134 int snd_hda_multi_out_dig_open(struct hda_codec *codec, in snd_hda_multi_out_dig_open() argument
4137 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
4140 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_open()
4142 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_open()
4155 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, in snd_hda_multi_out_dig_prepare() argument
4161 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
4162 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format); in snd_hda_multi_out_dig_prepare()
4163 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_prepare()
4173 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, in snd_hda_multi_out_dig_cleanup() argument
4176 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
4177 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_dig_cleanup()
4178 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_cleanup()
4188 int snd_hda_multi_out_dig_close(struct hda_codec *codec, in snd_hda_multi_out_dig_close() argument
4191 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
4193 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_dig_close()
4209 int snd_hda_multi_out_analog_open(struct hda_codec *codec, in snd_hda_multi_out_analog_open() argument
4227 snd_hda_query_supported_pcm(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_open()
4232 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
4245 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_open()
4263 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, in snd_hda_multi_out_analog_prepare() argument
4274 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
4275 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
4279 snd_hda_is_supported_format(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
4283 setup_dig_out_stream(codec, mout->dig_out_nid, in snd_hda_multi_out_analog_prepare()
4287 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_prepare()
4290 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_prepare()
4293 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, in snd_hda_multi_out_analog_prepare()
4298 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, in snd_hda_multi_out_analog_prepare()
4303 snd_hda_codec_setup_stream(codec, in snd_hda_multi_out_analog_prepare()
4310 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
4313 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, in snd_hda_multi_out_analog_prepare()
4326 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], in snd_hda_multi_out_analog_prepare()
4339 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, in snd_hda_multi_out_analog_cleanup() argument
4346 snd_hda_codec_cleanup_stream(codec, nids[i]); in snd_hda_multi_out_analog_cleanup()
4348 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); in snd_hda_multi_out_analog_cleanup()
4351 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
4355 snd_hda_codec_cleanup_stream(codec, in snd_hda_multi_out_analog_cleanup()
4357 mutex_lock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
4359 cleanup_dig_out_stream(codec, mout->dig_out_nid); in snd_hda_multi_out_analog_cleanup()
4362 mutex_unlock(&codec->spdif_mutex); in snd_hda_multi_out_analog_cleanup()
4375 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) in snd_hda_get_default_vref() argument
4379 oldval = snd_hda_codec_read(codec, pin, 0, in snd_hda_get_default_vref()
4381 pincap = snd_hda_query_pin_caps(codec, pin); in snd_hda_get_default_vref()
4402 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, in snd_hda_correct_pin_ctl() argument
4415 cap = snd_hda_query_pin_caps(codec, pin); in snd_hda_correct_pin_ctl()
4465 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, in _snd_hda_set_pin_ctl() argument
4468 val = snd_hda_correct_pin_ctl(codec, pin, val); in _snd_hda_set_pin_ctl()
4469 snd_hda_codec_set_pin_target(codec, pin, val); in _snd_hda_set_pin_ctl()
4471 return snd_hda_codec_update_cache(codec, pin, 0, in _snd_hda_set_pin_ctl()
4474 return snd_hda_codec_write(codec, pin, 0, in _snd_hda_set_pin_ctl()
4491 int snd_hda_add_imux_item(struct hda_codec *codec, in snd_hda_add_imux_item() argument
4497 codec_err(codec, "hda_codec: Too many imux items!\n"); in snd_hda_add_imux_item()
4525 struct hda_codec *codec; in snd_hda_bus_reset() local
4527 list_for_each_codec(codec, bus) { in snd_hda_bus_reset()
4529 cancel_delayed_work_sync(&codec->jackpoll_work); in snd_hda_bus_reset()
4531 if (hda_codec_is_power_on(codec)) { in snd_hda_bus_reset()
4532 hda_call_codec_suspend(codec); in snd_hda_bus_reset()
4533 hda_call_codec_resume(codec); in snd_hda_bus_reset()