Lines Matching refs:codec

27 #define codec_in_pm(codec)		snd_hdac_is_in_pm(&codec->core)
28 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core)
29 #define codec_has_epss(codec) \
30 ((codec)->core.power_caps & AC_PWRST_EPSS)
31 #define codec_has_clkstop(codec) \
32 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
40 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
41 struct hda_bus *bus = codec->bus;
48 snd_hda_power_up_pm(codec);
52 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
56 snd_hda_power_down_pm(codec);
57 if (!codec_in_pm(codec) && res && err == -EAGAIN) {
59 codec_dbg(codec,
66 if (!err || codec_in_pm(codec))
73 * @codec: the HDA codec
79 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
82 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
96 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
99 list_for_each_entry(p, &codec->conn_list, list) {
106 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
117 list_add(&p->list, &codec->conn_list);
121 static void remove_conn_list(struct hda_codec *codec)
123 while (!list_empty(&codec->conn_list)) {
125 p = list_first_entry(&codec->conn_list, typeof(*p), list);
132 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
138 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
140 len = snd_hda_get_num_raw_conns(codec, nid);
144 len = snd_hda_get_raw_connections(codec, nid, result, len);
147 len = snd_hda_override_conn_list(codec, nid, len, result);
155 * @codec: the HDA codec
168 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
178 p = lookup_conn_list(codec, nid);
187 err = read_and_add_raw_conns(codec, nid);
197 * @codec: the HDA codec
207 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
211 int len = snd_hda_get_conn_list(codec, nid, &list);
215 codec_err(codec, "Too many connections %d for NID 0x%x\n",
228 * @codec: the HDA codec
238 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
243 p = lookup_conn_list(codec, nid);
249 return add_conn_list(codec, nid, len, list);
255 * @codec: the HDA codec
264 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
270 nums = snd_hda_get_conn_list(codec, mux, &conn);
277 codec_dbg(codec, "too deep connection for 0x%x\n", nid);
282 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i]));
285 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0)
294 * @codec: the HDA codec
300 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid)
302 unsigned int wcaps = get_wcaps(codec, nid);
305 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) ||
309 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN);
318 * @codec: the HDA codec
326 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
332 parm = snd_hda_get_num_devices(codec, nid);
341 if (snd_hdac_read(&codec->core, nid,
358 * @codec: the HDA codec
365 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid)
368 if (!codec->dp_mst)
371 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0);
377 * @codec: the HDA codec
383 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
388 if (!codec->dp_mst)
392 num_devices = snd_hda_get_num_devices(codec, nid) + 1;
406 ret = snd_hda_codec_write(codec, nid, 0,
416 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
421 codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL);
422 if (!codec->wcaps)
424 nid = codec->core.start_nid;
425 for (i = 0; i < codec->core.num_nodes; i++, nid++)
426 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core,
431 /* read all pin default configurations and save codec->init_pins */
432 static int read_pin_defaults(struct hda_codec *codec)
436 for_each_hda_codec_node(nid, codec) {
438 unsigned int wcaps = get_wcaps(codec, nid);
442 pin = snd_array_new(&codec->init_pins);
446 pin->cfg = snd_hda_codec_read(codec, nid, 0,
450 * fixme: if any codec is different, need fix here
452 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
460 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
477 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
487 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
491 pin = look_up_pincfg(codec, list, nid);
504 * @codec: the HDA codec
512 int snd_hda_codec_set_pincfg(struct hda_codec *codec,
515 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
521 * @codec: the HDA codec
528 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
535 mutex_lock(&codec->user_mutex);
536 pin = look_up_pincfg(codec, &codec->user_pins, nid);
539 mutex_unlock(&codec->user_mutex);
544 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
547 pin = look_up_pincfg(codec, &codec->init_pins, nid);
556 * @codec: the HDA codec
564 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
569 pin = look_up_pincfg(codec, &codec->init_pins, nid);
579 * @codec: the HDA codec
582 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid)
586 pin = look_up_pincfg(codec, &codec->init_pins, nid);
595 * @codec: the HDA codec
600 void snd_hda_shutup_pins(struct hda_codec *codec)
608 if (codec->bus->shutdown)
610 snd_array_for_each(&codec->init_pins, i, pin) {
612 snd_hda_codec_read(codec, pin->nid, 0,
615 codec->pins_shutup = 1;
621 static void restore_shutup_pins(struct hda_codec *codec)
626 if (!codec->pins_shutup)
628 if (codec->bus->shutdown)
630 snd_array_for_each(&codec->init_pins, i, pin) {
631 snd_hda_codec_write(codec, pin->nid, 0,
635 codec->pins_shutup = 0;
641 struct hda_codec *codec =
645 if (!codec->jackpoll_interval && snd_hdac_is_power_on(&codec->core))
649 snd_hda_power_up_pm(codec);
651 if (codec->jackpoll_interval) {
652 snd_hda_jack_set_dirty_all(codec);
653 snd_hda_jack_poll_all(codec);
655 snd_hda_power_down_pm(codec);
657 if (!codec->jackpoll_interval)
660 schedule_delayed_work(&codec->jackpoll_work,
661 codec->jackpoll_interval);
665 static void free_init_pincfgs(struct hda_codec *codec)
667 snd_array_free(&codec->driver_pins);
669 snd_array_free(&codec->user_pins);
671 snd_array_free(&codec->init_pins);
688 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
693 snd_array_for_each(&codec->cvt_setups, i, p) {
697 p = snd_array_new(&codec->cvt_setups);
708 if (refcount_dec_and_test(&pcm->codec->pcm_ref))
709 wake_up(&pcm->codec->remove_sleep);
713 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
723 pcm->codec = codec;
732 list_add_tail(&pcm->list, &codec->pcm_list_head);
733 refcount_inc(&codec->pcm_ref);
739 * codec destructor
741 void snd_hda_codec_disconnect_pcms(struct hda_codec *codec)
745 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
749 snd_device_disconnect(codec->card, pcm->pcm);
755 static void codec_release_pcms(struct hda_codec *codec)
759 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
762 snd_device_free(pcm->codec->card, pcm->pcm);
763 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
770 * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal
771 * @codec: codec device to cleanup
773 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
775 if (codec->core.registered) {
777 pm_runtime_get_noresume(hda_codec_dev(codec));
778 pm_runtime_disable(hda_codec_dev(codec));
779 codec->core.registered = 0;
782 snd_hda_codec_disconnect_pcms(codec);
783 cancel_delayed_work_sync(&codec->jackpoll_work);
784 if (!codec->in_freeing)
785 snd_hda_ctls_clear(codec);
786 codec_release_pcms(codec);
787 snd_hda_detach_beep_device(codec);
788 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
789 snd_hda_jack_tbl_clear(codec);
790 codec->proc_widget_hook = NULL;
791 codec->spec = NULL;
794 snd_array_free(&codec->driver_pins);
795 snd_array_free(&codec->cvt_setups);
796 snd_array_free(&codec->spdif_out);
797 snd_array_free(&codec->verbs);
798 codec->follower_dig_outs = NULL;
799 codec->spdif_status_reset = 0;
800 snd_array_free(&codec->mixers);
801 snd_array_free(&codec->nids);
802 remove_conn_list(codec);
803 snd_hdac_regmap_exit(&codec->core);
804 codec->configured = 0;
805 refcount_set(&codec->pcm_ref, 1); /* reset refcount */
809 static unsigned int hda_set_power_state(struct hda_codec *codec,
812 /* enable/disable display power per codec */
813 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable)
815 if (codec->display_power_control)
816 snd_hdac_display_power(&codec->bus->core, codec->addr, enable);
820 * snd_hda_codec_register - Finalize codec initialization
821 * @codec: codec device to register
825 void snd_hda_codec_register(struct hda_codec *codec)
827 if (codec->core.registered)
829 if (device_is_registered(hda_codec_dev(codec))) {
830 snd_hda_codec_display_power(codec, true);
831 pm_runtime_enable(hda_codec_dev(codec));
833 snd_hda_power_down(codec);
834 codec->core.registered = 1;
846 * snd_hda_codec_unregister - Unregister specified codec device
847 * @codec: codec device to unregister
849 void snd_hda_codec_unregister(struct hda_codec *codec)
851 codec->in_freeing = 1;
857 if (codec->core.type == HDA_DEV_LEGACY)
858 snd_hdac_device_unregister(&codec->core);
859 snd_hda_codec_display_power(codec, false);
865 if (codec->core.type == HDA_DEV_LEGACY)
866 put_device(hda_codec_dev(codec));
878 struct hda_codec *codec = dev_to_hda_codec(dev);
880 free_init_pincfgs(codec);
881 snd_hdac_device_exit(&codec->core);
882 snd_hda_sysfs_clear(codec);
883 kfree(codec->modelname);
884 kfree(codec->wcaps);
885 kfree(codec);
891 * snd_hda_codec_device_init - allocate HDA codec device
892 * @bus: codec's parent bus
893 * @codec_addr: the codec address on the parent bus
896 * Returns newly allocated codec device or ERR_PTR() on failure.
904 struct hda_codec *codec;
912 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
913 if (!codec)
920 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr);
922 kfree(codec);
926 codec->bus = bus;
927 codec->depop_delay = -1;
928 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
929 codec->core.dev.release = snd_hda_codec_dev_release;
930 codec->core.type = HDA_DEV_LEGACY;
932 mutex_init(&codec->spdif_mutex);
933 mutex_init(&codec->control_mutex);
934 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
935 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
936 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
937 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
938 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
939 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
940 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
941 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
942 INIT_LIST_HEAD(&codec->conn_list);
943 INIT_LIST_HEAD(&codec->pcm_list_head);
944 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
945 refcount_set(&codec->pcm_ref, 1);
946 init_waitqueue_head(&codec->remove_sleep);
948 return codec;
953 * snd_hda_codec_new - create a HDA codec
955 * @card: card for this codec
956 * @codec_addr: the codec address
957 * @codecp: the pointer to store the generated codec
964 struct hda_codec *codec;
967 codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d",
969 if (IS_ERR(codec))
970 return PTR_ERR(codec);
971 *codecp = codec;
982 unsigned int codec_addr, struct hda_codec *codec,
1000 codec->core.exec_verb = codec_exec_verb;
1001 codec->card = card;
1002 codec->addr = codec_addr;
1005 codec->power_jiffies = jiffies;
1008 snd_hda_sysfs_init(codec);
1010 if (codec->bus->modelname) {
1011 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1012 if (!codec->modelname)
1016 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1017 err = read_widget_caps(codec, fg);
1020 err = read_pin_defaults(codec);
1025 hda_set_power_state(codec, AC_PWRST_D0);
1026 codec->core.dev.power.power_state = PMSG_ON;
1028 snd_hda_codec_proc_new(codec);
1030 snd_hda_create_hwdep(codec);
1032 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id,
1033 codec->core.subsystem_id, codec->core.revision_id);
1038 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
1044 /* PM runtime needs to be enabled later after binding codec */
1045 if (codec->core.dev.power.runtime_auto)
1046 pm_runtime_forbid(&codec->core.dev);
1049 pm_runtime_get_noresume(&codec->core.dev);
1058 * @codec: the HDA codec
1061 * the given codec.
1063 int snd_hda_codec_update_widgets(struct hda_codec *codec)
1068 err = snd_hdac_refresh_widgets(&codec->core);
1075 kfree(codec->wcaps);
1076 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1077 err = read_widget_caps(codec, fg);
1081 snd_array_free(&codec->init_pins);
1082 err = read_pin_defaults(codec);
1089 static void update_pcm_stream_id(struct hda_codec *codec,
1096 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
1099 snd_hda_codec_write(codec, nid, 0,
1108 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p,
1114 oldval = snd_hda_codec_read(codec, nid, 0,
1118 snd_hda_codec_write(codec, nid, 0,
1127 * snd_hda_codec_setup_stream - set up the codec for streaming
1128 * @codec: the CODEC to set up
1134 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1146 codec_dbg(codec,
1149 p = get_hda_cvt_setup(codec, nid);
1153 if (codec->patch_ops.stream_pm)
1154 codec->patch_ops.stream_pm(codec, nid, true);
1155 if (codec->pcm_format_first)
1156 update_pcm_format(codec, p, nid, format);
1157 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
1158 if (!codec->pcm_format_first)
1159 update_pcm_format(codec, p, nid, format);
1165 type = get_wcaps_type(get_wcaps(codec, nid));
1166 list_for_each_codec(c, codec->bus) {
1176 static void really_cleanup_stream(struct hda_codec *codec,
1180 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1181 * @codec: the CODEC to clean up
1185 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1193 if (codec->no_sticky_stream)
1196 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid);
1197 p = get_hda_cvt_setup(codec, nid);
1204 really_cleanup_stream(codec, p);
1211 static void really_cleanup_stream(struct hda_codec *codec,
1216 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1218 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
1222 if (codec->patch_ops.stream_pm)
1223 codec->patch_ops.stream_pm(codec, nid, false);
1227 static void purify_inactive_streams(struct hda_codec *codec)
1233 list_for_each_codec(c, codec->bus) {
1243 static void hda_cleanup_all_streams(struct hda_codec *codec)
1248 snd_array_for_each(&codec->cvt_setups, i, p) {
1250 really_cleanup_stream(codec, p);
1261 * @codec: the HD-auio codec
1271 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1273 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1274 nid = codec->core.afg;
1275 return snd_hda_param_read(codec, nid,
1283 * @codec: the HD-audio codec
1290 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
1295 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
1296 if (query_amp_caps(codec, nid, dir) & bits)
1304 * @codec: the CODEC to clean up
1315 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1320 snd_hda_override_wcaps(codec, nid,
1321 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD);
1323 return snd_hdac_override_parm(&codec->core, nid, parm, caps);
1327 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid,
1333 if ((query_amp_caps(codec, nid, dir) &
1341 * @codec: HD-audio codec
1351 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
1354 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1356 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
1362 * @codec: HD-audio codec
1372 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1380 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1388 * @codec: the HDA codec
1400 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
1403 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1405 if (!codec->core.regmap)
1407 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val);
1413 * @codec: the HDA codec
1422 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
1430 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir,
1436 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1439 u32 caps = query_amp_caps(codec, nid, dir);
1458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1467 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
1469 codec_warn(codec,
1480 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1484 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1494 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1503 maxval = get_amp_max_value(codec, nid, dir, 0);
1506 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1532 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1548 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1558 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1562 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1577 caps = query_amp_caps(codec, nid, dir);
1617 * @codec: HD-audio codec
1626 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1632 caps = query_amp_caps(codec, nid, dir);
1645 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
1655 return snd_ctl_find_id(codec->card, &id);
1660 * @codec: HD-audio codec
1665 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1668 return find_mixer_ctl(codec, name, 0, 0);
1672 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name,
1678 if (!find_mixer_ctl(codec, name, 0, idx))
1685 * snd_hda_ctl_add - Add a control element and assign to the codec
1686 * @codec: HD-audio codec
1690 * Add the given control element to an array inside the codec instance.
1691 * All control elements belonging to a codec are supposed to be added
1696 * The assignment is shown in the codec proc file.
1703 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1719 err = snd_ctl_add(codec->card, kctl);
1722 item = snd_array_new(&codec->mixers);
1734 * @codec: HD-audio codec
1739 * Add the given control element to an array inside the codec instance.
1743 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1749 item = snd_array_new(&codec->nids);
1757 codec_err(codec, "no NID for mapping control %s:%d:%d\n",
1764 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1765 * @codec: HD-audio codec
1767 void snd_hda_ctls_clear(struct hda_codec *codec)
1770 struct hda_nid_item *items = codec->mixers.list;
1772 for (i = 0; i < codec->mixers.used; i++)
1773 snd_ctl_remove(codec->card, items[i].kctl);
1774 snd_array_free(&codec->mixers);
1775 snd_array_free(&codec->nids);
1787 struct hda_codec *codec;
1796 list_for_each_codec(codec, bus) {
1798 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
1832 * snd_hda_codec_reset - Clear all objects assigned to the codec
1833 * @codec: HD-audio codec
1835 * This frees the all PCM and control elements assigned to the codec, and
1841 int snd_hda_codec_reset(struct hda_codec *codec)
1843 struct hda_bus *bus = codec->bus;
1849 device_release_driver(hda_codec_dev(codec));
1859 static int map_followers(struct hda_codec *codec, const char * const *followers,
1866 items = codec->mixers.list;
1867 for (i = 0; i < codec->mixers.used; i++) {
1880 err = func(codec, data, sctl);
1890 static int check_follower_present(struct hda_codec *codec,
1911 struct hda_codec *codec;
1928 codec_err(arg->codec,
1946 codec_err(arg->codec,
1970 static int add_follower(struct hda_codec *codec,
1978 * @codec: HD-audio codec
1996 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
2007 err = map_followers(codec, followers, suffix, check_follower_present, NULL);
2009 codec_dbg(codec, "No follower found for %s\n", name);
2016 err = snd_hda_ctl_add(codec, 0, kctl);
2020 err = map_followers(codec, followers, suffix, add_follower, kctl);
2028 .codec = codec,
2047 hook->hook(hook->codec, enabled);
2052 * @codec: the HDA codec
2057 int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2062 hook->codec = codec;
2077 if (!hook->hook || !hook->codec)
2082 if (hook->codec->bus->shutdown)
2121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2129 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2132 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2158 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2164 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2167 hda_call_check_power_status(codec, nid);
2208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2212 if (WARN_ON(codec->spdif_out.used <= idx))
2214 mutex_lock(&codec->spdif_mutex);
2215 spdif = snd_array_elem(&codec->spdif_out, idx);
2220 mutex_unlock(&codec->spdif_mutex);
2279 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2284 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
2286 d = codec->follower_dig_outs;
2290 snd_hdac_regmap_update(&codec->core, *d,
2294 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2308 set_dig_out(codec, nid, mask, val);
2314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2321 if (WARN_ON(codec->spdif_out.used <= idx))
2323 mutex_lock(&codec->spdif_mutex);
2324 spdif = snd_array_elem(&codec->spdif_out, idx);
2335 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2336 mutex_unlock(&codec->spdif_mutex);
2345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2349 if (WARN_ON(codec->spdif_out.used <= idx))
2351 mutex_lock(&codec->spdif_mutex);
2352 spdif = snd_array_elem(&codec->spdif_out, idx);
2354 mutex_unlock(&codec->spdif_mutex);
2358 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid,
2361 set_dig_out_convert(codec, nid, dig1, dig2);
2363 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2365 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2372 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2379 if (WARN_ON(codec->spdif_out.used <= idx))
2381 mutex_lock(&codec->spdif_mutex);
2382 spdif = snd_array_elem(&codec->spdif_out, idx);
2390 set_spdif_ctls(codec, nid, val & 0xff, -1);
2391 mutex_unlock(&codec->spdif_mutex);
2429 * @codec: the HDA codec
2438 int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
2450 struct hda_bus *bus = codec->bus;
2461 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
2466 snd_ctl_rename_id(codec->card, &kctl->id, &id);
2473 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
2475 codec_err(codec, "too many IEC958 outputs\n");
2478 spdif = snd_array_new(&codec->spdif_out);
2482 kctl = snd_ctl_new1(dig_mix, codec);
2486 kctl->private_value = codec->spdif_out.used - 1;
2487 err = snd_hda_ctl_add(codec, associated_nid, kctl);
2492 snd_hdac_regmap_read(&codec->core, cvt_nid,
2502 * @codec: the HDA codec
2507 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
2513 snd_array_for_each(&codec->spdif_out, i, spdif) {
2523 * @codec: the HDA codec
2528 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
2532 if (WARN_ON(codec->spdif_out.used <= idx))
2534 mutex_lock(&codec->spdif_mutex);
2535 spdif = snd_array_elem(&codec->spdif_out, idx);
2537 mutex_unlock(&codec->spdif_mutex);
2543 * @codec: the HDA codec
2549 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
2554 if (WARN_ON(codec->spdif_out.used <= idx))
2556 mutex_lock(&codec->spdif_mutex);
2557 spdif = snd_array_elem(&codec->spdif_out, idx);
2561 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff);
2563 mutex_unlock(&codec->spdif_mutex);
2596 * @codec: the HDA codec
2599 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2610 /* ATTENTION: here mout is passed as private_data, instead of codec */
2611 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl);
2624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2626 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
2633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2638 mutex_lock(&codec->spdif_mutex);
2639 change = codec->spdif_in_enable != val;
2641 codec->spdif_in_enable = val;
2642 snd_hdac_regmap_write(&codec->core, nid,
2645 mutex_unlock(&codec->spdif_mutex);
2652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2657 snd_hdac_regmap_read(&codec->core, nid,
2687 * @codec: the HDA codec
2695 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2702 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
2704 codec_err(codec, "too many IEC958 inputs\n");
2708 kctl = snd_ctl_new1(dig_mix, codec);
2712 err = snd_hda_ctl_add(codec, nid, kctl);
2716 codec->spdif_in_enable =
2717 snd_hda_codec_read(codec, nid, 0,
2726 * @codec: the HDA codec
2731 * If the codec has power_filter set, it evaluates the power state and
2734 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
2739 for_each_hda_codec_node(nid, codec) {
2740 unsigned int wcaps = get_wcaps(codec, nid);
2744 if (codec->power_filter) {
2745 state = codec->power_filter(codec, nid, power_state);
2749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
2757 * @codec: the HDA codec
2762 * This can be used a codec power_filter callback.
2764 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
2768 if (nid == codec->core.afg || nid == codec->core.mfg)
2771 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
2772 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
2773 int eapd = snd_hda_codec_read(codec, nid, 0,
2783 * set power state of the codec, and return the power state
2785 static unsigned int hda_set_power_state(struct hda_codec *codec,
2788 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
2795 if (codec->depop_delay < 0)
2796 msleep(codec_has_epss(codec) ? 10 : 100);
2797 else if (codec->depop_delay > 0)
2798 msleep(codec->depop_delay);
2804 if (codec->patch_ops.set_power_state)
2805 codec->patch_ops.set_power_state(codec, fg,
2809 if (codec->power_filter)
2810 state = codec->power_filter(codec, fg, state);
2812 snd_hda_codec_read(codec, fg, flags,
2815 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2817 state = snd_hda_sync_power_state(codec, fg, power_state);
2826 * this is called at the end of codec parsing
2828 static void sync_power_up_states(struct hda_codec *codec)
2833 if (!codec->power_filter)
2836 for_each_hda_codec_node(nid, codec) {
2837 unsigned int wcaps = get_wcaps(codec, nid);
2841 target = codec->power_filter(codec, nid, AC_PWRST_D0);
2844 if (!snd_hda_check_power_state(codec, nid, target))
2845 snd_hda_codec_write(codec, nid, 0,
2852 static void hda_exec_init_verbs(struct hda_codec *codec)
2854 if (codec->init_verbs.list)
2855 snd_hda_sequence_write(codec, codec->init_verbs.list);
2858 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2863 static void update_power_acct(struct hda_codec *codec, bool on)
2865 unsigned long delta = jiffies - codec->power_jiffies;
2868 codec->power_on_acct += delta;
2870 codec->power_off_acct += delta;
2871 codec->power_jiffies += delta;
2874 void snd_hda_update_power_acct(struct hda_codec *codec)
2876 update_power_acct(codec, hda_codec_is_power_on(codec));
2883 static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
2887 snd_hdac_enter_pm(&codec->core);
2888 if (codec->patch_ops.suspend)
2889 codec->patch_ops.suspend(codec);
2890 if (!codec->no_stream_clean_at_suspend)
2891 hda_cleanup_all_streams(codec);
2892 state = hda_set_power_state(codec, AC_PWRST_D3);
2893 update_power_acct(codec, true);
2894 snd_hdac_leave_pm(&codec->core);
2899 * kick up codec; used both from PM and power-save
2901 static void hda_call_codec_resume(struct hda_codec *codec)
2903 snd_hdac_enter_pm(&codec->core);
2904 if (codec->core.regmap)
2905 regcache_mark_dirty(codec->core.regmap);
2907 codec->power_jiffies = jiffies;
2909 hda_set_power_state(codec, AC_PWRST_D0);
2910 restore_shutup_pins(codec);
2911 hda_exec_init_verbs(codec);
2912 snd_hda_jack_set_dirty_all(codec);
2913 if (codec->patch_ops.resume)
2914 codec->patch_ops.resume(codec);
2916 if (codec->patch_ops.init)
2917 codec->patch_ops.init(codec);
2918 snd_hda_regmap_sync(codec);
2921 if (codec->jackpoll_interval)
2922 hda_jackpoll_work(&codec->jackpoll_work.work);
2924 snd_hda_jack_report_sync(codec);
2925 codec->core.dev.power.power_state = PMSG_ON;
2926 snd_hdac_leave_pm(&codec->core);
2931 struct hda_codec *codec = dev_to_hda_codec(dev);
2935 if (!codec->card)
2938 cancel_delayed_work_sync(&codec->jackpoll_work);
2940 state = hda_call_codec_suspend(codec);
2941 if (codec->link_down_at_suspend ||
2942 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
2944 snd_hdac_codec_link_down(&codec->core);
2945 snd_hda_codec_display_power(codec, false);
2947 if (codec->bus->jackpoll_in_suspend &&
2949 schedule_delayed_work(&codec->jackpoll_work,
2950 codec->jackpoll_interval);
2956 struct hda_codec *codec = dev_to_hda_codec(dev);
2959 if (!codec->card)
2962 snd_hda_codec_display_power(codec, true);
2963 snd_hdac_codec_link_up(&codec->core);
2964 hda_call_codec_resume(codec);
2974 struct hda_codec *codec = dev_to_hda_codec(dev);
2976 cancel_delayed_work_sync(&codec->jackpoll_work);
2983 struct hda_codec *codec = dev_to_hda_codec(dev);
2989 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
2990 hda_codec_need_resume(codec) || codec->forced_resume))
3008 struct hda_codec *codec = dev_to_hda_codec(dev);
3010 cancel_delayed_work_sync(&codec->jackpoll_work);
3044 /* suspend the codec at shutdown; called from driver's shutdown callback */
3045 void snd_hda_codec_shutdown(struct hda_codec *codec)
3049 /* Skip the shutdown if codec is not registered */
3050 if (!codec->core.registered)
3053 cancel_delayed_work_sync(&codec->jackpoll_work);
3054 list_for_each_entry(cpcm, &codec->pcm_list_head, list)
3057 pm_runtime_force_suspend(hda_codec_dev(codec));
3058 pm_runtime_disable(hda_codec_dev(codec));
3064 static int add_std_chmaps(struct hda_codec *codec)
3069 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
3102 int snd_hda_codec_build_controls(struct hda_codec *codec)
3105 hda_exec_init_verbs(codec);
3107 if (codec->patch_ops.init)
3108 err = codec->patch_ops.init(codec);
3109 if (!err && codec->patch_ops.build_controls)
3110 err = codec->patch_ops.build_controls(codec);
3115 err = add_std_chmaps(codec);
3119 if (codec->jackpoll_interval)
3120 hda_jackpoll_work(&codec->jackpoll_work.work);
3122 snd_hda_jack_report_sync(codec); /* call at the last init point */
3123 sync_power_up_states(codec);
3132 struct hda_codec *codec,
3139 struct hda_codec *codec,
3144 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3149 struct hda_codec *codec,
3152 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3156 static int set_pcm_default_values(struct hda_codec *codec,
3163 err = snd_hda_query_supported_pcm(codec, info->nid,
3188 * codec prepare/cleanup entries
3192 * @codec: the HDA codec
3198 * Calls the prepare callback set by the codec with the given arguments.
3201 int snd_hda_codec_prepare(struct hda_codec *codec,
3208 mutex_lock(&codec->bus->prepare_mutex);
3210 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
3215 purify_inactive_streams(codec);
3216 mutex_unlock(&codec->bus->prepare_mutex);
3223 * @codec: the HDA codec
3227 * Calls the cleanup callback set by the codec with the given arguments.
3229 void snd_hda_codec_cleanup(struct hda_codec *codec,
3233 mutex_lock(&codec->bus->prepare_mutex);
3235 hinfo->ops.cleanup(hinfo, codec, substream);
3236 mutex_unlock(&codec->bus->prepare_mutex);
3293 /* call build_pcms ops of the given codec and set up the default parameters */
3294 int snd_hda_codec_parse_pcms(struct hda_codec *codec)
3299 if (!list_empty(&codec->pcm_list_head))
3302 if (!codec->patch_ops.build_pcms)
3305 err = codec->patch_ops.build_pcms(codec);
3307 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
3308 codec->core.addr, err);
3312 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3320 err = set_pcm_default_values(codec, info);
3322 codec_warn(codec,
3334 /* assign all PCMs of the given codec */
3335 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3337 struct hda_bus *bus = codec->bus;
3341 err = snd_hda_codec_parse_pcms(codec);
3346 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3358 err = snd_hda_attach_pcm_stream(bus, codec, cpcm);
3360 codec_err(codec,
3361 "cannot attach PCM stream %d for codec #%d\n",
3362 dev, codec->core.addr);
3372 * @codec: the HDA codec
3380 int snd_hda_add_new_ctls(struct hda_codec *codec,
3389 continue; /* skip this codec private value */
3391 kctl = snd_ctl_new1(knew, codec);
3399 if (addr > 0 && codec->ctl_dev_id)
3403 err = snd_hda_ctl_add(codec, 0, kctl);
3407 * the codec addr; if it still fails (or it's the
3408 * primary codec), then try another control index
3410 if (!addr && codec->core.addr) {
3411 addr = codec->core.addr;
3412 if (!codec->ctl_dev_id)
3415 idx = find_empty_mixer_ctl_idx(codec,
3429 * snd_hda_codec_set_power_save - Configure codec's runtime PM
3430 * @codec: codec device to configure
3433 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay)
3435 struct device *dev = hda_codec_dev(codec);
3437 if (delay == 0 && codec->auto_runtime_pm)
3471 * @codec: HD-audio codec
3482 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3500 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3505 snd_hda_power_up_pm(codec);
3513 snd_hda_power_down_pm(codec);
3549 * @codec: the HDA codec
3555 int snd_hda_input_mux_put(struct hda_codec *codec,
3570 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3610 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3617 spdif = snd_hda_spdif_out_of_nid(codec, nid);
3624 curr_fmt = snd_hda_codec_read(codec, nid, 0,
3626 reset = codec->spdif_status_reset &&
3633 set_dig_out_convert(codec, nid,
3636 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3637 if (codec->follower_dig_outs) {
3639 for (d = codec->follower_dig_outs; *d; d++)
3640 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3645 set_dig_out_convert(codec, nid,
3649 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3651 snd_hda_codec_cleanup_stream(codec, nid);
3652 if (codec->follower_dig_outs) {
3654 for (d = codec->follower_dig_outs; *d; d++)
3655 snd_hda_codec_cleanup_stream(codec, *d);
3661 * @codec: the HDA codec
3664 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3667 mutex_lock(&codec->spdif_mutex);
3670 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3672 mutex_unlock(&codec->spdif_mutex);
3679 * @codec: the HDA codec
3685 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3691 mutex_lock(&codec->spdif_mutex);
3692 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3693 mutex_unlock(&codec->spdif_mutex);
3700 * @codec: the HDA codec
3703 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3706 mutex_lock(&codec->spdif_mutex);
3707 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3708 mutex_unlock(&codec->spdif_mutex);
3715 * @codec: the HDA codec
3718 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3721 mutex_lock(&codec->spdif_mutex);
3723 mutex_unlock(&codec->spdif_mutex);
3730 * @codec: the HDA codec
3739 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3757 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
3762 mutex_lock(&codec->spdif_mutex);
3775 mutex_unlock(&codec->spdif_mutex);
3784 * @codec: the HDA codec
3793 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3804 mutex_lock(&codec->spdif_mutex);
3805 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
3809 snd_hda_is_supported_format(codec, mout->dig_out_nid,
3813 setup_dig_out_stream(codec, mout->dig_out_nid,
3817 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3820 mutex_unlock(&codec->spdif_mutex);
3823 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
3828 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
3833 snd_hda_codec_setup_stream(codec,
3840 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3843 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3856 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i],
3866 * @codec: the HDA codec
3869 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3876 snd_hda_codec_cleanup_stream(codec, nids[i]);
3878 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
3881 snd_hda_codec_cleanup_stream(codec,
3885 snd_hda_codec_cleanup_stream(codec,
3887 mutex_lock(&codec->spdif_mutex);
3889 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3892 mutex_unlock(&codec->spdif_mutex);
3899 * @codec: the HDA codec
3905 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
3909 oldval = snd_hda_codec_read(codec, pin, 0,
3911 pincap = snd_hda_query_pin_caps(codec, pin);
3928 * @codec: the HDA codec
3932 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
3945 cap = snd_hda_query_pin_caps(codec, pin);
3984 * @codec: the HDA codec
3987 * @cached: access over codec pinctl cache or direct write
3995 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
3998 val = snd_hda_correct_pin_ctl(codec, pin, val);
3999 snd_hda_codec_set_pin_target(codec, pin, val);
4001 return snd_hda_codec_write_cache(codec, pin, 0,
4004 return snd_hda_codec_write(codec, pin, 0,
4011 * @codec: the HDA codec
4021 int snd_hda_add_imux_item(struct hda_codec *codec,
4027 codec_err(codec, "hda_codec: Too many imux items!\n");
4055 struct hda_codec *codec;
4057 list_for_each_codec(codec, bus) {
4059 if (current_work() != &codec->jackpoll_work.work)
4060 cancel_delayed_work_sync(&codec->jackpoll_work);
4062 if (hda_codec_is_power_on(codec)) {
4063 hda_call_codec_suspend(codec);
4064 hda_call_codec_resume(codec);
4091 MODULE_DESCRIPTION("HDA codec core");