Lines Matching full:codec
3 * Universal Interface for Intel High Definition Audio Codec
28 #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core)
29 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core)
30 #define codec_has_epss(codec) \
31 ((codec)->core.power_caps & AC_PWRST_EPSS)
32 #define codec_has_clkstop(codec) \
33 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
35 static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,
41 CLASS(snd_hda_power_pm, pm)(codec);
45 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
57 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
58 struct hda_bus *bus = codec->bus;
65 err = call_exec_verb(bus, codec, cmd, flags, res);
66 if (!codec_in_pm(codec) && res && err == -EAGAIN) {
68 codec_dbg(codec,
75 if (!err || codec_in_pm(codec))
82 * @codec: the HDA codec
88 void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
91 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
105 lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
108 list_for_each_entry(p, &codec->conn_list, list) {
115 static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
126 list_add(&p->list, &codec->conn_list);
130 static void remove_conn_list(struct hda_codec *codec)
132 while (!list_empty(&codec->conn_list)) {
134 p = list_first_entry(&codec->conn_list, typeof(*p), list);
141 static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
147 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
149 len = snd_hda_get_num_raw_conns(codec, nid);
153 len = snd_hda_get_raw_connections(codec, nid, result, len);
156 len = snd_hda_override_conn_list(codec, nid, len, result);
164 * @codec: the HDA codec
177 int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
187 p = lookup_conn_list(codec, nid);
196 err = read_and_add_raw_conns(codec, nid);
206 * @codec: the HDA codec
216 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
220 int len = snd_hda_get_conn_list(codec, nid, &list);
224 codec_err(codec, "Too many connections %d for NID 0x%x\n",
237 * @codec: the HDA codec
247 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
252 p = lookup_conn_list(codec, nid);
258 return add_conn_list(codec, nid, len, list);
264 * @codec: the HDA codec
273 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
279 nums = snd_hda_get_conn_list(codec, mux, &conn);
286 codec_dbg(codec, "too deep connection for 0x%x\n", nid);
291 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i]));
294 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0)
303 * @codec: the HDA codec
309 unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid)
311 unsigned int wcaps = get_wcaps(codec, nid);
314 if (!codec->dp_mst || !(wcaps & AC_WCAP_DIGITAL) ||
318 parm = snd_hdac_read_parm_uncached(&codec->core, nid, AC_PAR_DEVLIST_LEN);
327 * @codec: the HDA codec
335 unsigned int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
340 parm = snd_hda_get_num_devices(codec, nid);
348 if (snd_hdac_read(&codec->core, nid,
365 * @codec: the HDA codec
372 int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid)
375 if (!codec->dp_mst)
378 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0);
384 * @codec: the HDA codec
390 int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
395 if (!codec->dp_mst)
399 num_devices = snd_hda_get_num_devices(codec, nid) + 1;
413 ret = snd_hda_codec_write(codec, nid, 0,
423 static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
428 codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL);
429 if (!codec->wcaps)
431 nid = codec->core.start_nid;
432 for (i = 0; i < codec->core.num_nodes; i++, nid++)
433 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core,
438 /* read all pin default configurations and save codec->init_pins */
439 static int read_pin_defaults(struct hda_codec *codec)
443 for_each_hda_codec_node(nid, codec) {
445 unsigned int wcaps = get_wcaps(codec, nid);
449 pin = snd_array_new(&codec->init_pins);
453 pin->cfg = snd_hda_codec_read(codec, nid, 0,
457 * fixme: if any codec is different, need fix here
459 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
467 static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
484 int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
489 pin = look_up_pincfg(codec, list, nid);
502 * @codec: the HDA codec
510 int snd_hda_codec_set_pincfg(struct hda_codec *codec,
513 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
519 * @codec: the HDA codec
526 unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
533 scoped_guard(mutex, &codec->user_mutex) {
534 pin = look_up_pincfg(codec, &codec->user_pins, nid);
542 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
545 pin = look_up_pincfg(codec, &codec->init_pins, nid);
554 * @codec: the HDA codec
562 int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
567 pin = look_up_pincfg(codec, &codec->init_pins, nid);
577 * @codec: the HDA codec
580 int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid)
584 pin = look_up_pincfg(codec, &codec->init_pins, nid);
593 * @codec: the HDA codec
598 void snd_hda_shutup_pins(struct hda_codec *codec)
606 if (codec->bus->shutdown)
608 snd_array_for_each(&codec->init_pins, i, pin) {
610 snd_hda_codec_read(codec, pin->nid, 0,
613 codec->pins_shutup = 1;
618 static void restore_shutup_pins(struct hda_codec *codec)
623 if (!codec->pins_shutup)
625 if (codec->bus->shutdown)
627 snd_array_for_each(&codec->init_pins, i, pin) {
628 snd_hda_codec_write(codec, pin->nid, 0,
632 codec->pins_shutup = 0;
637 struct hda_codec *codec =
640 if (!codec->jackpoll_interval)
644 CLASS(snd_hda_power, pm)(codec);
646 snd_hda_jack_set_dirty_all(codec);
647 snd_hda_jack_poll_all(codec);
648 schedule_delayed_work(&codec->jackpoll_work, codec->jackpoll_interval);
652 static void free_init_pincfgs(struct hda_codec *codec)
654 snd_array_free(&codec->driver_pins);
656 snd_array_free(&codec->user_pins);
658 snd_array_free(&codec->init_pins);
675 get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
680 snd_array_for_each(&codec->cvt_setups, i, p) {
684 p = snd_array_new(&codec->cvt_setups);
695 if (refcount_dec_and_test(&pcm->codec->pcm_ref))
696 wake_up(&pcm->codec->remove_sleep);
700 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
710 pcm->codec = codec;
719 list_add_tail(&pcm->list, &codec->pcm_list_head);
720 refcount_inc(&codec->pcm_ref);
726 * codec destructor
728 void snd_hda_codec_disconnect_pcms(struct hda_codec *codec)
732 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
736 snd_device_disconnect(codec->card, pcm->pcm);
742 static void codec_release_pcms(struct hda_codec *codec)
746 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
749 snd_device_free(pcm->codec->card, pcm->pcm);
750 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
757 * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal
758 * @codec: codec device to cleanup
760 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
762 if (codec->core.registered) {
764 pm_runtime_get_noresume(hda_codec_dev(codec));
765 pm_runtime_disable(hda_codec_dev(codec));
766 codec->core.registered = 0;
769 snd_hda_codec_disconnect_pcms(codec);
770 cancel_delayed_work_sync(&codec->jackpoll_work);
771 if (!codec->in_freeing)
772 snd_hda_ctls_clear(codec);
773 codec_release_pcms(codec);
774 snd_hda_detach_beep_device(codec);
775 snd_hda_jack_tbl_clear(codec);
776 codec->proc_widget_hook = NULL;
777 codec->spec = NULL;
780 snd_array_free(&codec->driver_pins);
781 snd_array_free(&codec->cvt_setups);
782 snd_array_free(&codec->spdif_out);
783 snd_array_free(&codec->verbs);
784 codec->follower_dig_outs = NULL;
785 codec->spdif_status_reset = 0;
786 snd_array_free(&codec->mixers);
787 snd_array_free(&codec->nids);
788 remove_conn_list(codec);
789 snd_hdac_regmap_exit(&codec->core);
790 codec->configured = 0;
791 refcount_set(&codec->pcm_ref, 1); /* reset refcount */
795 static unsigned int hda_set_power_state(struct hda_codec *codec,
798 /* enable/disable display power per codec */
799 void snd_hda_codec_display_power(struct hda_codec *codec, bool enable)
801 if (codec->display_power_control)
802 snd_hdac_display_power(&codec->bus->core, codec->addr, enable);
806 * snd_hda_codec_register - Finalize codec initialization
807 * @codec: codec device to register
811 void snd_hda_codec_register(struct hda_codec *codec)
813 if (codec->core.registered)
815 if (device_is_registered(hda_codec_dev(codec))) {
816 snd_hda_codec_display_power(codec, true);
817 pm_runtime_enable(hda_codec_dev(codec));
819 snd_hda_power_down(codec);
820 codec->core.registered = 1;
832 * snd_hda_codec_unregister - Unregister specified codec device
833 * @codec: codec device to unregister
835 void snd_hda_codec_unregister(struct hda_codec *codec)
837 codec->in_freeing = 1;
843 if (codec->core.type == HDA_DEV_LEGACY)
844 snd_hdac_device_unregister(&codec->core);
845 snd_hda_codec_display_power(codec, false);
851 if (codec->core.type == HDA_DEV_LEGACY)
852 put_device(hda_codec_dev(codec));
864 struct hda_codec *codec = dev_to_hda_codec(dev);
866 free_init_pincfgs(codec);
867 snd_hdac_device_exit(&codec->core);
868 snd_hda_sysfs_clear(codec);
869 kfree(codec->modelname);
870 kfree(codec->wcaps);
871 kfree(codec);
877 * snd_hda_codec_device_init - allocate HDA codec device
878 * @bus: codec's parent bus
879 * @codec_addr: the codec address on the parent bus
882 * Returns newly allocated codec device or ERR_PTR() on failure.
890 struct hda_codec *codec;
898 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
899 if (!codec)
906 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr);
908 kfree(codec);
912 codec->bus = bus;
913 codec->depop_delay = -1;
914 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
915 codec->core.dev.release = snd_hda_codec_dev_release;
916 codec->core.type = HDA_DEV_LEGACY;
918 mutex_init(&codec->spdif_mutex);
919 mutex_init(&codec->control_mutex);
920 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
921 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
922 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
923 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
924 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
925 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
926 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
927 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
928 INIT_LIST_HEAD(&codec->conn_list);
929 INIT_LIST_HEAD(&codec->pcm_list_head);
930 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
931 refcount_set(&codec->pcm_ref, 1);
932 init_waitqueue_head(&codec->remove_sleep);
934 return codec;
939 * snd_hda_codec_new - create a HDA codec
941 * @card: card for this codec
942 * @codec_addr: the codec address
943 * @codecp: the pointer to store the generated codec
950 struct hda_codec *codec;
953 codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d",
955 if (IS_ERR(codec))
956 return PTR_ERR(codec);
957 *codecp = codec;
968 unsigned int codec_addr, struct hda_codec *codec,
986 codec->core.exec_verb = codec_exec_verb;
987 codec->card = card;
988 codec->addr = codec_addr;
990 codec->power_jiffies = jiffies;
992 snd_hda_sysfs_init(codec);
994 if (codec->bus->modelname) {
995 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
996 if (!codec->modelname)
1000 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1001 err = read_widget_caps(codec, fg);
1004 err = read_pin_defaults(codec);
1009 hda_set_power_state(codec, AC_PWRST_D0);
1010 codec->core.dev.power.power_state = PMSG_ON;
1012 snd_hda_codec_proc_new(codec);
1014 snd_hda_create_hwdep(codec);
1016 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id,
1017 codec->core.subsystem_id, codec->core.revision_id);
1022 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
1028 /* PM runtime needs to be enabled later after binding codec */
1029 if (codec->core.dev.power.runtime_auto)
1030 pm_runtime_forbid(&codec->core.dev);
1033 pm_runtime_get_noresume(&codec->core.dev);
1042 * @codec: the HDA codec
1045 * the given codec.
1047 int snd_hda_codec_update_widgets(struct hda_codec *codec)
1052 err = snd_hdac_refresh_widgets(&codec->core);
1059 kfree(codec->wcaps);
1060 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1061 err = read_widget_caps(codec, fg);
1065 snd_array_free(&codec->init_pins);
1066 err = read_pin_defaults(codec);
1073 static void update_pcm_stream_id(struct hda_codec *codec,
1080 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
1083 snd_hda_codec_write(codec, nid, 0,
1092 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p,
1098 oldval = snd_hda_codec_read(codec, nid, 0,
1102 snd_hda_codec_write(codec, nid, 0,
1111 * snd_hda_codec_setup_stream - set up the codec for streaming
1112 * @codec: the CODEC to set up
1118 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1122 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
1131 codec_dbg(codec,
1134 p = get_hda_cvt_setup(codec, nid);
1139 driver->ops->stream_pm(codec, nid, true);
1140 if (codec->pcm_format_first)
1141 update_pcm_format(codec, p, nid, format);
1142 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
1143 if (!codec->pcm_format_first)
1144 update_pcm_format(codec, p, nid, format);
1150 type = get_wcaps_type(get_wcaps(codec, nid));
1151 list_for_each_codec(c, codec->bus) {
1161 static void really_cleanup_stream(struct hda_codec *codec,
1165 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1166 * @codec: the CODEC to clean up
1170 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1178 if (codec->no_sticky_stream)
1181 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid);
1182 p = get_hda_cvt_setup(codec, nid);
1189 really_cleanup_stream(codec, p);
1196 static void really_cleanup_stream(struct hda_codec *codec,
1199 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
1203 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1205 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
1210 driver->ops->stream_pm(codec, nid, false);
1214 static void purify_inactive_streams(struct hda_codec *codec)
1220 list_for_each_codec(c, codec->bus) {
1229 static void hda_cleanup_all_streams(struct hda_codec *codec)
1234 snd_array_for_each(&codec->cvt_setups, i, p) {
1236 really_cleanup_stream(codec, p);
1246 * @codec: the HD-auio codec
1256 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1258 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1259 nid = codec->core.afg;
1260 return snd_hda_param_read(codec, nid,
1268 * @codec: the HD-audio codec
1275 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
1280 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
1281 if (query_amp_caps(codec, nid, dir) & bits)
1289 * @codec: the CODEC to clean up
1300 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1305 snd_hda_override_wcaps(codec, nid,
1306 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD);
1308 return snd_hdac_override_parm(&codec->core, nid, parm, caps);
1312 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid,
1318 if ((query_amp_caps(codec, nid, dir) &
1326 * @codec: HD-audio codec
1336 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
1339 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1341 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
1347 * @codec: HD-audio codec
1357 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1365 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1373 * @codec: the HDA codec
1385 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
1388 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1390 if (!codec->core.regmap)
1392 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val);
1398 * @codec: the HDA codec
1407 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
1415 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir,
1421 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1424 u32 caps = query_amp_caps(codec, nid, dir);
1443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1452 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
1454 codec_warn(codec,
1465 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1469 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1479 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1488 maxval = get_amp_max_value(codec, nid, dir, 0);
1491 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1515 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1517 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1544 err = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1551 err = update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1570 caps = query_amp_caps(codec, nid, dir);
1610 * @codec: HD-audio codec
1619 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1625 caps = query_amp_caps(codec, nid, dir);
1638 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
1648 return snd_ctl_find_id(codec->card, &id);
1653 * @codec: HD-audio codec
1658 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1661 return find_mixer_ctl(codec, name, 0, 0);
1665 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name,
1671 if (!find_mixer_ctl(codec, name, 0, idx))
1678 * snd_hda_ctl_add - Add a control element and assign to the codec
1679 * @codec: HD-audio codec
1683 * Add the given control element to an array inside the codec instance.
1684 * All control elements belonging to a codec are supposed to be added
1689 * The assignment is shown in the codec proc file.
1696 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1712 err = snd_ctl_add(codec->card, kctl);
1715 item = snd_array_new(&codec->mixers);
1726 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1727 * @codec: HD-audio codec
1729 void snd_hda_ctls_clear(struct hda_codec *codec)
1732 struct hda_nid_item *items = codec->mixers.list;
1734 for (i = 0; i < codec->mixers.used; i++)
1735 snd_ctl_remove(codec->card, items[i].kctl);
1736 snd_array_free(&codec->mixers);
1737 snd_array_free(&codec->nids);
1749 struct hda_codec *codec;
1758 list_for_each_codec(codec, bus) {
1760 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
1790 * snd_hda_codec_reset - Clear all objects assigned to the codec
1791 * @codec: HD-audio codec
1793 * This frees the all PCM and control elements assigned to the codec, and
1799 int snd_hda_codec_reset(struct hda_codec *codec)
1801 struct hda_bus *bus = codec->bus;
1807 device_release_driver(hda_codec_dev(codec));
1817 static int map_followers(struct hda_codec *codec, const char * const *followers,
1824 items = codec->mixers.list;
1825 for (i = 0; i < codec->mixers.used; i++) {
1838 err = func(codec, data, sctl);
1848 static int check_follower_present(struct hda_codec *codec,
1869 struct hda_codec *codec;
1886 codec_err(arg->codec,
1904 codec_err(arg->codec,
1928 static int add_follower(struct hda_codec *codec,
1936 * @codec: HD-audio codec
1954 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1965 err = map_followers(codec, followers, suffix, check_follower_present, NULL);
1967 codec_dbg(codec, "No follower found for %s\n", name);
1974 err = snd_hda_ctl_add(codec, 0, kctl);
1978 err = map_followers(codec, followers, suffix, add_follower, kctl);
1986 .codec = codec,
2005 hook->hook(hook->codec, enabled);
2010 * @codec: the HDA codec
2015 int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2020 hook->codec = codec;
2035 if (!hook->hook || !hook->codec)
2040 if (hook->codec->bus->shutdown)
2079 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2087 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2090 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2118 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2126 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2130 hda_call_check_power_status(codec, nid);
2171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2175 if (WARN_ON(codec->spdif_out.used <= idx))
2177 guard(mutex)(&codec->spdif_mutex);
2178 spdif = snd_array_elem(&codec->spdif_out, idx);
2241 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2246 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
2248 d = codec->follower_dig_outs;
2252 snd_hdac_regmap_update(&codec->core, *d,
2256 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2270 set_dig_out(codec, nid, mask, val);
2276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2283 if (WARN_ON(codec->spdif_out.used <= idx))
2285 guard(mutex)(&codec->spdif_mutex);
2286 spdif = snd_array_elem(&codec->spdif_out, idx);
2297 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2310 if (WARN_ON(codec->spdif_out.used <= idx))
2312 guard(mutex)(&codec->spdif_mutex);
2313 spdif = snd_array_elem(&codec->spdif_out, idx);
2318 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid,
2321 set_dig_out_convert(codec, nid, dig1, dig2);
2323 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2325 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2339 if (WARN_ON(codec->spdif_out.used <= idx))
2341 guard(mutex)(&codec->spdif_mutex);
2342 spdif = snd_array_elem(&codec->spdif_out, idx);
2350 set_spdif_ctls(codec, nid, val & 0xff, -1);
2388 * @codec: the HDA codec
2393 * Called from each codec driver supporting the digital out.
2397 int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
2409 struct hda_bus *bus = codec->bus;
2420 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
2425 err = snd_ctl_rename_id(codec->card, &kctl->id, &id);
2434 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
2436 codec_err(codec, "too many IEC958 outputs\n");
2439 spdif = snd_array_new(&codec->spdif_out);
2443 kctl = snd_ctl_new1(dig_mix, codec);
2447 kctl->private_value = codec->spdif_out.used - 1;
2448 err = snd_hda_ctl_add(codec, associated_nid, kctl);
2453 snd_hdac_regmap_read(&codec->core, cvt_nid,
2463 * @codec: the HDA codec
2468 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
2474 snd_array_for_each(&codec->spdif_out, i, spdif) {
2484 * @codec: the HDA codec
2489 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
2493 if (WARN_ON(codec->spdif_out.used <= idx))
2495 guard(mutex)(&codec->spdif_mutex);
2496 spdif = snd_array_elem(&codec->spdif_out, idx);
2503 * @codec: the HDA codec
2509 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
2514 if (WARN_ON(codec->spdif_out.used <= idx))
2516 guard(mutex)(&codec->spdif_mutex);
2517 spdif = snd_array_elem(&codec->spdif_out, idx);
2521 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff);
2555 * @codec: the HDA codec
2558 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2569 /* ATTENTION: here mout is passed as private_data, instead of codec */
2570 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl);
2583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2585 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2597 guard(mutex)(&codec->spdif_mutex);
2598 change = codec->spdif_in_enable != val;
2600 codec->spdif_in_enable = val;
2601 snd_hdac_regmap_write(&codec->core, nid,
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2615 snd_hdac_regmap_read(&codec->core, nid,
2645 * @codec: the HDA codec
2649 * Called from each codec driver supporting the SPDIF in.
2653 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2660 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
2662 codec_err(codec, "too many IEC958 inputs\n");
2666 kctl = snd_ctl_new1(dig_mix, codec);
2670 err = snd_hda_ctl_add(codec, nid, kctl);
2674 codec->spdif_in_enable =
2675 snd_hda_codec_read(codec, nid, 0,
2684 * @codec: the HDA codec
2689 * If the codec has power_filter set, it evaluates the power state and
2692 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
2697 for_each_hda_codec_node(nid, codec) {
2698 unsigned int wcaps = get_wcaps(codec, nid);
2702 if (codec->power_filter) {
2703 state = codec->power_filter(codec, nid, power_state);
2707 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
2715 * @codec: the HDA codec
2720 * This can be used a codec power_filter callback.
2722 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
2726 if (nid == codec->core.afg || nid == codec->core.mfg)
2729 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
2730 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
2731 int eapd = snd_hda_codec_read(codec, nid, 0,
2741 * set power state of the codec, and return the power state
2743 static unsigned int hda_set_power_state(struct hda_codec *codec,
2746 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
2747 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
2754 if (codec->depop_delay < 0)
2755 msleep(codec_has_epss(codec) ? 10 : 100);
2756 else if (codec->depop_delay > 0)
2757 msleep(codec->depop_delay);
2765 driver->ops->set_power_state(codec, fg, power_state);
2768 if (codec->power_filter)
2769 state = codec->power_filter(codec, fg, state);
2771 snd_hda_codec_read(codec, fg, flags,
2774 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2776 state = snd_hda_sync_power_state(codec, fg, power_state);
2785 * this is called at the end of codec parsing
2787 static void sync_power_up_states(struct hda_codec *codec)
2792 if (!codec->power_filter)
2795 for_each_hda_codec_node(nid, codec) {
2796 unsigned int wcaps = get_wcaps(codec, nid);
2800 target = codec->power_filter(codec, nid, AC_PWRST_D0);
2803 if (!snd_hda_check_power_state(codec, nid, target))
2804 snd_hda_codec_write(codec, nid, 0,
2811 static void hda_exec_init_verbs(struct hda_codec *codec)
2813 if (codec->init_verbs.list)
2814 snd_hda_sequence_write(codec, codec->init_verbs.list);
2817 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2821 static void update_power_acct(struct hda_codec *codec, bool on)
2823 unsigned long delta = jiffies - codec->power_jiffies;
2826 codec->power_on_acct += delta;
2828 codec->power_off_acct += delta;
2829 codec->power_jiffies += delta;
2832 void snd_hda_update_power_acct(struct hda_codec *codec)
2834 update_power_acct(codec, hda_codec_is_power_on(codec));
2841 static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
2843 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
2846 snd_hdac_enter_pm(&codec->core);
2848 driver->ops->suspend(codec);
2849 if (!codec->no_stream_clean_at_suspend)
2850 hda_cleanup_all_streams(codec);
2851 state = hda_set_power_state(codec, AC_PWRST_D3);
2852 update_power_acct(codec, true);
2853 snd_hdac_leave_pm(&codec->core);
2858 * kick up codec; used both from PM and power-save
2860 static void hda_call_codec_resume(struct hda_codec *codec)
2862 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
2864 snd_hdac_enter_pm(&codec->core);
2865 if (codec->core.regmap)
2866 regcache_mark_dirty(codec->core.regmap);
2868 codec->power_jiffies = jiffies;
2870 hda_set_power_state(codec, AC_PWRST_D0);
2871 restore_shutup_pins(codec);
2872 hda_exec_init_verbs(codec);
2873 snd_hda_jack_set_dirty_all(codec);
2875 driver->ops->resume(codec);
2877 snd_hda_codec_init(codec);
2878 snd_hda_regmap_sync(codec);
2881 snd_hda_jack_report_sync(codec);
2882 codec->core.dev.power.power_state = PMSG_ON;
2883 snd_hdac_leave_pm(&codec->core);
2884 if (codec->jackpoll_interval)
2885 schedule_delayed_work(&codec->jackpoll_work,
2886 codec->jackpoll_interval);
2891 struct hda_codec *codec = dev_to_hda_codec(dev);
2895 if (!codec->card)
2898 state = hda_call_codec_suspend(codec);
2899 if (codec->link_down_at_suspend ||
2900 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
2902 snd_hdac_codec_link_down(&codec->core);
2903 snd_hda_codec_display_power(codec, false);
2910 struct hda_codec *codec = dev_to_hda_codec(dev);
2913 if (!codec->card)
2916 snd_hda_codec_display_power(codec, true);
2917 snd_hdac_codec_link_up(&codec->core);
2918 hda_call_codec_resume(codec);
2925 struct hda_codec *codec = dev_to_hda_codec(dev);
2927 if (codec->jackpoll_interval && !codec->bus->jackpoll_in_suspend)
2934 struct hda_codec *codec = dev_to_hda_codec(dev);
2936 cancel_delayed_work_sync(&codec->jackpoll_work);
2943 struct hda_codec *codec = dev_to_hda_codec(dev);
2949 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
2950 hda_codec_need_resume(codec) || codec->forced_resume))
2968 struct hda_codec *codec = dev_to_hda_codec(dev);
2970 cancel_delayed_work_sync(&codec->jackpoll_work);
3001 /* suspend the codec at shutdown; called from driver's shutdown callback */
3002 void snd_hda_codec_shutdown(struct hda_codec *codec)
3006 /* Skip the shutdown if codec is not registered */
3007 if (!codec->core.registered)
3010 codec->jackpoll_interval = 0; /* don't poll any longer */
3011 cancel_delayed_work_sync(&codec->jackpoll_work);
3012 list_for_each_entry(cpcm, &codec->pcm_list_head, list)
3015 pm_runtime_force_suspend(hda_codec_dev(codec));
3016 pm_runtime_disable(hda_codec_dev(codec));
3022 static int add_std_chmaps(struct hda_codec *codec)
3027 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
3060 int snd_hda_codec_build_controls(struct hda_codec *codec)
3062 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
3065 hda_exec_init_verbs(codec);
3067 err = snd_hda_codec_init(codec);
3072 err = driver->ops->build_controls(codec);
3078 err = add_std_chmaps(codec);
3082 snd_hda_jack_report_sync(codec); /* call at the last init point */
3083 if (codec->jackpoll_interval)
3084 schedule_delayed_work(&codec->jackpoll_work,
3085 codec->jackpoll_interval);
3087 sync_power_up_states(codec);
3096 struct hda_codec *codec,
3103 struct hda_codec *codec,
3108 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3113 struct hda_codec *codec,
3116 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3120 static int set_pcm_default_values(struct hda_codec *codec,
3127 err = snd_hda_query_supported_pcm(codec, info->nid,
3153 * codec prepare/cleanup entries
3157 * @codec: the HDA codec
3163 * Calls the prepare callback set by the codec with the given arguments.
3166 int snd_hda_codec_prepare(struct hda_codec *codec,
3174 guard(mutex)(&codec->bus->prepare_mutex);
3176 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
3181 purify_inactive_streams(codec);
3188 * @codec: the HDA codec
3192 * Calls the cleanup callback set by the codec with the given arguments.
3194 void snd_hda_codec_cleanup(struct hda_codec *codec,
3198 guard(mutex)(&codec->bus->prepare_mutex);
3200 hinfo->ops.cleanup(hinfo, codec, substream);
3257 /* call build_pcms ops of the given codec and set up the default parameters */
3258 int snd_hda_codec_parse_pcms(struct hda_codec *codec)
3260 struct hda_codec_driver *driver = hda_codec_to_driver(codec);
3264 if (!list_empty(&codec->pcm_list_head))
3270 err = driver->ops->build_pcms(codec);
3272 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
3273 codec->core.addr, err);
3277 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3285 err = set_pcm_default_values(codec, info);
3287 codec_warn(codec,
3299 /* assign all PCMs of the given codec */
3300 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3302 struct hda_bus *bus = codec->bus;
3306 err = snd_hda_codec_parse_pcms(codec);
3311 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3323 err = snd_hda_attach_pcm_stream(bus, codec, cpcm);
3325 codec_err(codec,
3326 "cannot attach PCM stream %d for codec #%d\n",
3327 dev, codec->core.addr);
3337 * @codec: the HDA codec
3345 int snd_hda_add_new_ctls(struct hda_codec *codec,
3354 continue; /* skip this codec private value */
3356 kctl = snd_ctl_new1(knew, codec);
3364 if (addr > 0 && codec->ctl_dev_id)
3368 err = snd_hda_ctl_add(codec, 0, kctl);
3372 * the codec addr; if it still fails (or it's the
3373 * primary codec), then try another control index
3375 if (!addr && codec->core.addr) {
3376 addr = codec->core.addr;
3377 if (!codec->ctl_dev_id)
3380 idx = find_empty_mixer_ctl_idx(codec,
3393 * snd_hda_codec_set_power_save - Configure codec's runtime PM
3394 * @codec: codec device to configure
3397 void snd_hda_codec_set_power_save(struct hda_codec *codec, int delay)
3399 struct device *dev = hda_codec_dev(codec);
3401 if (delay == 0 && codec->auto_runtime_pm)
3435 * @codec: HD-audio codec
3446 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3464 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3469 snd_hda_power_up_pm(codec);
3477 snd_hda_power_down_pm(codec);
3512 * @codec: the HDA codec
3518 int snd_hda_input_mux_put(struct hda_codec *codec,
3533 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3573 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3580 spdif = snd_hda_spdif_out_of_nid(codec, nid);
3587 curr_fmt = snd_hda_codec_read(codec, nid, 0,
3589 reset = codec->spdif_status_reset &&
3596 set_dig_out_convert(codec, nid,
3599 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3600 if (codec->follower_dig_outs) {
3602 for (d = codec->follower_dig_outs; *d; d++)
3603 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3608 set_dig_out_convert(codec, nid,
3612 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3614 snd_hda_codec_cleanup_stream(codec, nid);
3615 if (codec->follower_dig_outs) {
3617 for (d = codec->follower_dig_outs; *d; d++)
3618 snd_hda_codec_cleanup_stream(codec, *d);
3624 * @codec: the HDA codec
3627 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3630 guard(mutex)(&codec->spdif_mutex);
3633 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3641 * @codec: the HDA codec
3647 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3653 guard(mutex)(&codec->spdif_mutex);
3654 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3661 * @codec: the HDA codec
3664 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3667 guard(mutex)(&codec->spdif_mutex);
3668 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3675 * @codec: the HDA codec
3678 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3681 guard(mutex)(&codec->spdif_mutex);
3689 * @codec: the HDA codec
3698 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3716 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
3722 guard(mutex)(&codec->spdif_mutex);
3743 * @codec: the HDA codec
3752 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3763 scoped_guard(mutex, &codec->spdif_mutex) {
3764 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
3768 snd_hda_is_supported_format(codec, mout->dig_out_nid,
3772 setup_dig_out_stream(codec, mout->dig_out_nid,
3776 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3782 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
3787 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
3792 snd_hda_codec_setup_stream(codec,
3799 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3802 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3815 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i],
3825 * @codec: the HDA codec
3828 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3835 snd_hda_codec_cleanup_stream(codec, nids[i]);
3837 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
3840 snd_hda_codec_cleanup_stream(codec,
3844 snd_hda_codec_cleanup_stream(codec,
3846 guard(mutex)(&codec->spdif_mutex);
3848 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3857 * @codec: the HDA codec
3863 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
3867 oldval = snd_hda_codec_read(codec, pin, 0,
3869 pincap = snd_hda_query_pin_caps(codec, pin);
3886 * @codec: the HDA codec
3890 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
3903 cap = snd_hda_query_pin_caps(codec, pin);
3942 * @codec: the HDA codec
3945 * @cached: access over codec pinctl cache or direct write
3953 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
3956 val = snd_hda_correct_pin_ctl(codec, pin, val);
3957 snd_hda_codec_set_pin_target(codec, pin, val);
3959 return snd_hda_codec_write_cache(codec, pin, 0,
3962 return snd_hda_codec_write(codec, pin, 0,
3969 * @codec: the HDA codec
3979 int snd_hda_add_imux_item(struct hda_codec *codec,
3985 codec_err(codec, "hda_codec: Too many imux items!\n");
4013 struct hda_codec *codec;
4015 list_for_each_codec(codec, bus) {
4017 if (current_work() != &codec->jackpoll_work.work)
4018 cancel_delayed_work_sync(&codec->jackpoll_work);
4019 if (hda_codec_is_power_on(codec)) {
4020 hda_call_codec_suspend(codec);
4021 hda_call_codec_resume(codec);
4047 MODULE_DESCRIPTION("HDA codec core");