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);
711 snd_device_free(pcm->codec->card, pcm->pcm);
712 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
723 struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
733 pcm->codec = codec;
743 list_add_tail(&pcm->list, &codec->pcm_list_head);
749 * codec destructor
751 static void codec_release_pcms(struct hda_codec *codec)
755 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
758 snd_device_disconnect(codec->card, pcm->pcm);
763 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
765 if (codec->registered) {
767 pm_runtime_get_noresume(hda_codec_dev(codec));
768 pm_runtime_disable(hda_codec_dev(codec));
769 codec->registered = 0;
772 cancel_delayed_work_sync(&codec->jackpoll_work);
773 if (!codec->in_freeing)
774 snd_hda_ctls_clear(codec);
775 codec_release_pcms(codec);
776 snd_hda_detach_beep_device(codec);
777 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
778 snd_hda_jack_tbl_clear(codec);
779 codec->proc_widget_hook = NULL;
780 codec->spec = NULL;
783 snd_array_free(&codec->driver_pins);
784 snd_array_free(&codec->cvt_setups);
785 snd_array_free(&codec->spdif_out);
786 snd_array_free(&codec->verbs);
787 codec->follower_dig_outs = NULL;
788 codec->spdif_status_reset = 0;
789 snd_array_free(&codec->mixers);
790 snd_array_free(&codec->nids);
791 remove_conn_list(codec);
792 snd_hdac_regmap_exit(&codec->core);
793 codec->configured = 0;
797 static unsigned int hda_set_power_state(struct hda_codec *codec,
800 /* enable/disable display power per codec */
801 static void codec_display_power(struct hda_codec *codec, bool enable)
803 if (codec->display_power_control)
804 snd_hdac_display_power(&codec->bus->core, codec->addr, enable);
808 void snd_hda_codec_register(struct hda_codec *codec)
810 if (codec->registered)
812 if (device_is_registered(hda_codec_dev(codec))) {
813 codec_display_power(codec, true);
814 pm_runtime_enable(hda_codec_dev(codec));
816 snd_hda_power_down(codec);
817 codec->registered = 1;
829 struct hda_codec *codec = device->device_data;
831 codec->in_freeing = 1;
837 if (codec->core.type == HDA_DEV_LEGACY)
838 snd_hdac_device_unregister(&codec->core);
839 codec_display_power(codec, false);
845 if (codec->core.type == HDA_DEV_LEGACY)
846 put_device(hda_codec_dev(codec));
853 struct hda_codec *codec = dev_to_hda_codec(dev);
855 free_init_pincfgs(codec);
856 snd_hdac_device_exit(&codec->core);
857 snd_hda_sysfs_clear(codec);
858 kfree(codec->modelname);
859 kfree(codec->wcaps);
865 if (codec->core.type == HDA_DEV_LEGACY)
866 kfree(codec);
875 struct hda_codec *codec;
885 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
886 if (!codec)
890 err = snd_hdac_device_init(&codec->core, &bus->core, name, codec_addr);
892 kfree(codec);
896 codec->core.type = HDA_DEV_LEGACY;
897 *codecp = codec;
903 * snd_hda_codec_new - create a HDA codec
905 * @card: card for this codec
906 * @codec_addr: the codec address
907 * @codecp: the pointer to store the generated codec
925 unsigned int codec_addr, struct hda_codec *codec)
942 codec->core.dev.release = snd_hda_codec_dev_release;
943 codec->core.exec_verb = codec_exec_verb;
945 codec->bus = bus;
946 codec->card = card;
947 codec->addr = codec_addr;
948 mutex_init(&codec->spdif_mutex);
949 mutex_init(&codec->control_mutex);
950 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
951 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
952 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
953 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
954 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
955 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
956 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
957 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
958 INIT_LIST_HEAD(&codec->conn_list);
959 INIT_LIST_HEAD(&codec->pcm_list_head);
961 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
962 codec->depop_delay = -1;
963 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
966 codec->power_jiffies = jiffies;
969 snd_hda_sysfs_init(codec);
971 if (codec->bus->modelname) {
972 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
973 if (!codec->modelname) {
979 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
980 err = read_widget_caps(codec, fg);
983 err = read_pin_defaults(codec);
988 hda_set_power_state(codec, AC_PWRST_D0);
989 codec->core.dev.power.power_state = PMSG_ON;
991 snd_hda_codec_proc_new(codec);
993 snd_hda_create_hwdep(codec);
995 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id,
996 codec->core.subsystem_id, codec->core.revision_id);
999 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
1003 /* PM runtime needs to be enabled later after binding codec */
1004 pm_runtime_forbid(&codec->core.dev);
1009 put_device(hda_codec_dev(codec));
1016 * @codec: the HDA codec
1019 * the given codec.
1021 int snd_hda_codec_update_widgets(struct hda_codec *codec)
1026 err = snd_hdac_refresh_widgets(&codec->core);
1033 kfree(codec->wcaps);
1034 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1035 err = read_widget_caps(codec, fg);
1039 snd_array_free(&codec->init_pins);
1040 err = read_pin_defaults(codec);
1047 static void update_pcm_stream_id(struct hda_codec *codec,
1054 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
1057 snd_hda_codec_write(codec, nid, 0,
1066 static void update_pcm_format(struct hda_codec *codec, struct hda_cvt_setup *p,
1072 oldval = snd_hda_codec_read(codec, nid, 0,
1076 snd_hda_codec_write(codec, nid, 0,
1085 * snd_hda_codec_setup_stream - set up the codec for streaming
1086 * @codec: the CODEC to set up
1092 void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1104 codec_dbg(codec,
1107 p = get_hda_cvt_setup(codec, nid);
1111 if (codec->patch_ops.stream_pm)
1112 codec->patch_ops.stream_pm(codec, nid, true);
1113 if (codec->pcm_format_first)
1114 update_pcm_format(codec, p, nid, format);
1115 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
1116 if (!codec->pcm_format_first)
1117 update_pcm_format(codec, p, nid, format);
1123 type = get_wcaps_type(get_wcaps(codec, nid));
1124 list_for_each_codec(c, codec->bus) {
1134 static void really_cleanup_stream(struct hda_codec *codec,
1138 * __snd_hda_codec_cleanup_stream - clean up the codec for closing
1139 * @codec: the CODEC to clean up
1143 void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1151 if (codec->no_sticky_stream)
1154 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid);
1155 p = get_hda_cvt_setup(codec, nid);
1162 really_cleanup_stream(codec, p);
1169 static void really_cleanup_stream(struct hda_codec *codec,
1174 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1176 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
1180 if (codec->patch_ops.stream_pm)
1181 codec->patch_ops.stream_pm(codec, nid, false);
1185 static void purify_inactive_streams(struct hda_codec *codec)
1191 list_for_each_codec(c, codec->bus) {
1201 static void hda_cleanup_all_streams(struct hda_codec *codec)
1206 snd_array_for_each(&codec->cvt_setups, i, p) {
1208 really_cleanup_stream(codec, p);
1219 * @codec: the HD-auio codec
1229 u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1231 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1232 nid = codec->core.afg;
1233 return snd_hda_param_read(codec, nid,
1241 * @codec: the HD-audio codec
1248 bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
1253 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
1254 if (query_amp_caps(codec, nid, dir) & bits)
1262 * @codec: the CODEC to clean up
1273 int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1278 snd_hda_override_wcaps(codec, nid,
1279 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD);
1281 return snd_hdac_override_parm(&codec->core, nid, parm, caps);
1285 static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid,
1291 if ((query_amp_caps(codec, nid, dir) &
1299 * @codec: HD-audio codec
1309 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
1312 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1314 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
1320 * @codec: HD-audio codec
1330 int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1338 ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
1346 * @codec: the HDA codec
1358 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
1361 unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
1363 if (!codec->core.regmap)
1365 return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val);
1371 * @codec: the HDA codec
1380 int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
1388 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir,
1394 static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1397 u32 caps = query_amp_caps(codec, nid, dir);
1416 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1425 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
1427 codec_warn(codec,
1438 read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1442 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1452 update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1461 maxval = get_amp_max_value(codec, nid, dir, 0);
1464 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1479 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1488 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1490 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1516 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1520 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1535 caps = query_amp_caps(codec, nid, dir);
1575 * @codec: HD-audio codec
1584 void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1590 caps = query_amp_caps(codec, nid, dir);
1603 find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
1613 return snd_ctl_find_id(codec->card, &id);
1618 * @codec: HD-audio codec
1623 struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1626 return find_mixer_ctl(codec, name, 0, 0);
1630 static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name,
1636 if (!find_mixer_ctl(codec, name, 0, idx))
1643 * snd_hda_ctl_add - Add a control element and assign to the codec
1644 * @codec: HD-audio codec
1648 * Add the given control element to an array inside the codec instance.
1649 * All control elements belonging to a codec are supposed to be added
1654 * The assignment is shown in the codec proc file.
1661 int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1677 err = snd_ctl_add(codec->card, kctl);
1680 item = snd_array_new(&codec->mixers);
1692 * @codec: HD-audio codec
1697 * Add the given control element to an array inside the codec instance.
1701 int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1707 item = snd_array_new(&codec->nids);
1715 codec_err(codec, "no NID for mapping control %s:%d:%d\n",
1722 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1723 * @codec: HD-audio codec
1725 void snd_hda_ctls_clear(struct hda_codec *codec)
1728 struct hda_nid_item *items = codec->mixers.list;
1730 down_write(&codec->card->controls_rwsem);
1731 for (i = 0; i < codec->mixers.used; i++)
1732 snd_ctl_remove(codec->card, items[i].kctl);
1733 up_write(&codec->card->controls_rwsem);
1734 snd_array_free(&codec->mixers);
1735 snd_array_free(&codec->nids);
1747 struct hda_codec *codec;
1756 list_for_each_codec(codec, bus) {
1758 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
1792 * snd_hda_codec_reset - Clear all objects assigned to the codec
1793 * @codec: HD-audio codec
1795 * This frees the all PCM and control elements assigned to the codec, and
1801 int snd_hda_codec_reset(struct hda_codec *codec)
1803 struct hda_bus *bus = codec->bus;
1809 device_release_driver(hda_codec_dev(codec));
1819 static int map_followers(struct hda_codec *codec, const char * const *followers,
1826 items = codec->mixers.list;
1827 for (i = 0; i < codec->mixers.used; i++) {
1840 err = func(codec, data, sctl);
1850 static int check_follower_present(struct hda_codec *codec,
1871 struct hda_codec *codec;
1888 codec_err(arg->codec,
1906 codec_err(arg->codec,
1930 static int add_follower(struct hda_codec *codec,
1938 * @codec: HD-audio codec
1955 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1966 err = map_followers(codec, followers, suffix, check_follower_present, NULL);
1968 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,
2051 hook->hook(hook->codec, enabled);
2056 * @codec: the HDA codec
2064 int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2072 hook->codec = codec;
2080 return snd_hda_ctl_add(codec, 0, kctl);
2093 if (!hook->hook || !hook->codec)
2098 if (hook->codec->bus->shutdown)
2137 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2145 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
2148 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
2165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2174 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
2180 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
2183 hda_call_check_power_status(codec, nid);
2224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2228 if (WARN_ON(codec->spdif_out.used <= idx))
2230 mutex_lock(&codec->spdif_mutex);
2231 spdif = snd_array_elem(&codec->spdif_out, idx);
2236 mutex_unlock(&codec->spdif_mutex);
2295 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2300 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
2302 d = codec->follower_dig_outs;
2306 snd_hdac_regmap_update(&codec->core, *d,
2310 static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
2324 set_dig_out(codec, nid, mask, val);
2330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2337 if (WARN_ON(codec->spdif_out.used <= idx))
2339 mutex_lock(&codec->spdif_mutex);
2340 spdif = snd_array_elem(&codec->spdif_out, idx);
2351 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2352 mutex_unlock(&codec->spdif_mutex);
2361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2365 if (WARN_ON(codec->spdif_out.used <= idx))
2367 mutex_lock(&codec->spdif_mutex);
2368 spdif = snd_array_elem(&codec->spdif_out, idx);
2370 mutex_unlock(&codec->spdif_mutex);
2374 static inline void set_spdif_ctls(struct hda_codec *codec, hda_nid_t nid,
2377 set_dig_out_convert(codec, nid, dig1, dig2);
2379 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
2381 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 if (WARN_ON(codec->spdif_out.used <= idx))
2397 mutex_lock(&codec->spdif_mutex);
2398 spdif = snd_array_elem(&codec->spdif_out, idx);
2406 set_spdif_ctls(codec, nid, val & 0xff, -1);
2407 mutex_unlock(&codec->spdif_mutex);
2445 * @codec: the HDA codec
2454 int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
2466 struct hda_bus *bus = codec->bus;
2475 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
2485 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
2487 codec_err(codec, "too many IEC958 outputs\n");
2490 spdif = snd_array_new(&codec->spdif_out);
2494 kctl = snd_ctl_new1(dig_mix, codec);
2498 kctl->private_value = codec->spdif_out.used - 1;
2499 err = snd_hda_ctl_add(codec, associated_nid, kctl);
2504 snd_hdac_regmap_read(&codec->core, cvt_nid,
2514 * @codec: the HDA codec
2519 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
2525 snd_array_for_each(&codec->spdif_out, i, spdif) {
2535 * @codec: the HDA codec
2540 void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
2544 if (WARN_ON(codec->spdif_out.used <= idx))
2546 mutex_lock(&codec->spdif_mutex);
2547 spdif = snd_array_elem(&codec->spdif_out, idx);
2549 mutex_unlock(&codec->spdif_mutex);
2555 * @codec: the HDA codec
2561 void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
2566 if (WARN_ON(codec->spdif_out.used <= idx))
2568 mutex_lock(&codec->spdif_mutex);
2569 spdif = snd_array_elem(&codec->spdif_out, idx);
2573 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff);
2575 mutex_unlock(&codec->spdif_mutex);
2608 * @codec: the HDA codec
2611 int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2622 /* ATTENTION: here mout is passed as private_data, instead of codec */
2623 return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl);
2636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2638 ucontrol->value.integer.value[0] = codec->spdif_in_enable;
2645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2650 mutex_lock(&codec->spdif_mutex);
2651 change = codec->spdif_in_enable != val;
2653 codec->spdif_in_enable = val;
2654 snd_hdac_regmap_write(&codec->core, nid,
2657 mutex_unlock(&codec->spdif_mutex);
2664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2669 snd_hdac_regmap_read(&codec->core, nid,
2699 * @codec: the HDA codec
2707 int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2714 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
2716 codec_err(codec, "too many IEC958 inputs\n");
2720 kctl = snd_ctl_new1(dig_mix, codec);
2724 err = snd_hda_ctl_add(codec, nid, kctl);
2728 codec->spdif_in_enable =
2729 snd_hda_codec_read(codec, nid, 0,
2738 * @codec: the HDA codec
2743 * If the codec has power_filter set, it evaluates the power state and
2746 void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
2751 for_each_hda_codec_node(nid, codec) {
2752 unsigned int wcaps = get_wcaps(codec, nid);
2756 if (codec->power_filter) {
2757 state = codec->power_filter(codec, nid, power_state);
2761 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
2769 * @codec: the HDA codec
2774 * This can be used a codec power_filter callback.
2776 unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
2780 if (nid == codec->core.afg || nid == codec->core.mfg)
2783 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
2784 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
2785 int eapd = snd_hda_codec_read(codec, nid, 0,
2795 * set power state of the codec, and return the power state
2797 static unsigned int hda_set_power_state(struct hda_codec *codec,
2800 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
2807 if (codec->depop_delay < 0)
2808 msleep(codec_has_epss(codec) ? 10 : 100);
2809 else if (codec->depop_delay > 0)
2810 msleep(codec->depop_delay);
2816 if (codec->patch_ops.set_power_state)
2817 codec->patch_ops.set_power_state(codec, fg,
2821 if (codec->power_filter)
2822 state = codec->power_filter(codec, fg, state);
2824 snd_hda_codec_read(codec, fg, flags,
2827 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2829 state = snd_hda_sync_power_state(codec, fg, power_state);
2838 * this is called at the end of codec parsing
2840 static void sync_power_up_states(struct hda_codec *codec)
2845 if (!codec->power_filter)
2848 for_each_hda_codec_node(nid, codec) {
2849 unsigned int wcaps = get_wcaps(codec, nid);
2853 target = codec->power_filter(codec, nid, AC_PWRST_D0);
2856 if (!snd_hda_check_power_state(codec, nid, target))
2857 snd_hda_codec_write(codec, nid, 0,
2864 static void hda_exec_init_verbs(struct hda_codec *codec)
2866 if (codec->init_verbs.list)
2867 snd_hda_sequence_write(codec, codec->init_verbs.list);
2870 static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2875 static void update_power_acct(struct hda_codec *codec, bool on)
2877 unsigned long delta = jiffies - codec->power_jiffies;
2880 codec->power_on_acct += delta;
2882 codec->power_off_acct += delta;
2883 codec->power_jiffies += delta;
2886 void snd_hda_update_power_acct(struct hda_codec *codec)
2888 update_power_acct(codec, hda_codec_is_power_on(codec));
2895 static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
2899 snd_hdac_enter_pm(&codec->core);
2900 if (codec->patch_ops.suspend)
2901 codec->patch_ops.suspend(codec);
2902 hda_cleanup_all_streams(codec);
2903 state = hda_set_power_state(codec, AC_PWRST_D3);
2904 update_power_acct(codec, true);
2905 snd_hdac_leave_pm(&codec->core);
2910 * kick up codec; used both from PM and power-save
2912 static void hda_call_codec_resume(struct hda_codec *codec)
2914 snd_hdac_enter_pm(&codec->core);
2915 if (codec->core.regmap)
2916 regcache_mark_dirty(codec->core.regmap);
2918 codec->power_jiffies = jiffies;
2920 hda_set_power_state(codec, AC_PWRST_D0);
2921 restore_shutup_pins(codec);
2922 hda_exec_init_verbs(codec);
2923 snd_hda_jack_set_dirty_all(codec);
2924 if (codec->patch_ops.resume)
2925 codec->patch_ops.resume(codec);
2927 if (codec->patch_ops.init)
2928 codec->patch_ops.init(codec);
2929 snd_hda_regmap_sync(codec);
2932 if (codec->jackpoll_interval)
2933 hda_jackpoll_work(&codec->jackpoll_work.work);
2935 snd_hda_jack_report_sync(codec);
2936 codec->core.dev.power.power_state = PMSG_ON;
2937 snd_hdac_leave_pm(&codec->core);
2942 struct hda_codec *codec = dev_to_hda_codec(dev);
2946 if (!codec->card)
2949 cancel_delayed_work_sync(&codec->jackpoll_work);
2950 state = hda_call_codec_suspend(codec);
2951 if (codec->link_down_at_suspend ||
2952 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
2954 snd_hdac_codec_link_down(&codec->core);
2955 codec_display_power(codec, false);
2961 struct hda_codec *codec = dev_to_hda_codec(dev);
2964 if (!codec->card)
2967 codec_display_power(codec, true);
2968 snd_hdac_codec_link_up(&codec->core);
2969 hda_call_codec_resume(codec);
2985 struct hda_codec *codec = dev_to_hda_codec(dev);
2991 if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
2992 hda_codec_need_resume(codec) || codec->forced_resume))
3046 static int add_std_chmaps(struct hda_codec *codec)
3051 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
3084 int snd_hda_codec_build_controls(struct hda_codec *codec)
3087 hda_exec_init_verbs(codec);
3089 if (codec->patch_ops.init)
3090 err = codec->patch_ops.init(codec);
3091 if (!err && codec->patch_ops.build_controls)
3092 err = codec->patch_ops.build_controls(codec);
3097 err = add_std_chmaps(codec);
3101 if (codec->jackpoll_interval)
3102 hda_jackpoll_work(&codec->jackpoll_work.work);
3104 snd_hda_jack_report_sync(codec); /* call at the last init point */
3105 sync_power_up_states(codec);
3114 struct hda_codec *codec,
3121 struct hda_codec *codec,
3126 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
3131 struct hda_codec *codec,
3134 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
3138 static int set_pcm_default_values(struct hda_codec *codec,
3145 err = snd_hda_query_supported_pcm(codec, info->nid,
3170 * codec prepare/cleanup entries
3174 * @codec: the HDA codec
3180 * Calls the prepare callback set by the codec with the given arguments.
3183 int snd_hda_codec_prepare(struct hda_codec *codec,
3190 mutex_lock(&codec->bus->prepare_mutex);
3192 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
3197 purify_inactive_streams(codec);
3198 mutex_unlock(&codec->bus->prepare_mutex);
3205 * @codec: the HDA codec
3209 * Calls the cleanup callback set by the codec with the given arguments.
3211 void snd_hda_codec_cleanup(struct hda_codec *codec,
3215 mutex_lock(&codec->bus->prepare_mutex);
3217 hinfo->ops.cleanup(hinfo, codec, substream);
3218 mutex_unlock(&codec->bus->prepare_mutex);
3275 /* call build_pcms ops of the given codec and set up the default parameters */
3276 int snd_hda_codec_parse_pcms(struct hda_codec *codec)
3281 if (!list_empty(&codec->pcm_list_head))
3284 if (!codec->patch_ops.build_pcms)
3287 err = codec->patch_ops.build_pcms(codec);
3289 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
3290 codec->core.addr, err);
3294 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3302 err = set_pcm_default_values(codec, info);
3304 codec_warn(codec,
3316 /* assign all PCMs of the given codec */
3317 int snd_hda_codec_build_pcms(struct hda_codec *codec)
3319 struct hda_bus *bus = codec->bus;
3323 err = snd_hda_codec_parse_pcms(codec);
3328 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3340 err = snd_hda_attach_pcm_stream(bus, codec, cpcm);
3342 codec_err(codec,
3343 "cannot attach PCM stream %d for codec #%d\n",
3344 dev, codec->core.addr);
3354 * @codec: the HDA codec
3362 int snd_hda_add_new_ctls(struct hda_codec *codec,
3371 continue; /* skip this codec private value */
3373 kctl = snd_ctl_new1(knew, codec);
3380 err = snd_hda_ctl_add(codec, 0, kctl);
3384 * the codec addr; if it still fails (or it's the
3385 * primary codec), then try another control index
3387 if (!addr && codec->core.addr)
3388 addr = codec->core.addr;
3390 idx = find_empty_mixer_ctl_idx(codec,
3403 static void codec_set_power_save(struct hda_codec *codec, int delay)
3405 struct device *dev = hda_codec_dev(codec);
3407 if (delay == 0 && codec->auto_runtime_pm)
3440 * @codec: HD-audio codec
3451 int snd_hda_check_amp_list_power(struct hda_codec *codec,
3469 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
3474 snd_hda_power_up_pm(codec);
3482 snd_hda_power_down_pm(codec);
3518 * @codec: the HDA codec
3524 int snd_hda_input_mux_put(struct hda_codec *codec,
3539 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
3579 static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3586 spdif = snd_hda_spdif_out_of_nid(codec, nid);
3593 curr_fmt = snd_hda_codec_read(codec, nid, 0,
3595 reset = codec->spdif_status_reset &&
3602 set_dig_out_convert(codec, nid,
3605 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3606 if (codec->follower_dig_outs) {
3608 for (d = codec->follower_dig_outs; *d; d++)
3609 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
3614 set_dig_out_convert(codec, nid,
3618 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3620 snd_hda_codec_cleanup_stream(codec, nid);
3621 if (codec->follower_dig_outs) {
3623 for (d = codec->follower_dig_outs; *d; d++)
3624 snd_hda_codec_cleanup_stream(codec, *d);
3630 * @codec: the HDA codec
3633 int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3636 mutex_lock(&codec->spdif_mutex);
3639 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3641 mutex_unlock(&codec->spdif_mutex);
3648 * @codec: the HDA codec
3654 int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3660 mutex_lock(&codec->spdif_mutex);
3661 setup_dig_out_stream(codec, mout->dig_out_nid, stream_tag, format);
3662 mutex_unlock(&codec->spdif_mutex);
3669 * @codec: the HDA codec
3672 int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3675 mutex_lock(&codec->spdif_mutex);
3676 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3677 mutex_unlock(&codec->spdif_mutex);
3684 * @codec: the HDA codec
3687 int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3690 mutex_lock(&codec->spdif_mutex);
3692 mutex_unlock(&codec->spdif_mutex);
3699 * @codec: the HDA codec
3708 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3726 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
3731 mutex_lock(&codec->spdif_mutex);
3744 mutex_unlock(&codec->spdif_mutex);
3753 * @codec: the HDA codec
3762 int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3773 mutex_lock(&codec->spdif_mutex);
3774 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
3778 snd_hda_is_supported_format(codec, mout->dig_out_nid,
3782 setup_dig_out_stream(codec, mout->dig_out_nid,
3786 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3789 mutex_unlock(&codec->spdif_mutex);
3792 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
3797 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
3802 snd_hda_codec_setup_stream(codec,
3809 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3812 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
3825 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i],
3835 * @codec: the HDA codec
3838 int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3845 snd_hda_codec_cleanup_stream(codec, nids[i]);
3847 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
3850 snd_hda_codec_cleanup_stream(codec,
3854 snd_hda_codec_cleanup_stream(codec,
3856 mutex_lock(&codec->spdif_mutex);
3858 cleanup_dig_out_stream(codec, mout->dig_out_nid);
3861 mutex_unlock(&codec->spdif_mutex);
3868 * @codec: the HDA codec
3874 unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
3878 oldval = snd_hda_codec_read(codec, pin, 0,
3880 pincap = snd_hda_query_pin_caps(codec, pin);
3897 * @codec: the HDA codec
3901 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
3914 cap = snd_hda_query_pin_caps(codec, pin);
3953 * @codec: the HDA codec
3956 * @cached: access over codec pinctl cache or direct write
3964 int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
3967 val = snd_hda_correct_pin_ctl(codec, pin, val);
3968 snd_hda_codec_set_pin_target(codec, pin, val);
3970 return snd_hda_codec_write_cache(codec, pin, 0,
3973 return snd_hda_codec_write(codec, pin, 0,
3980 * @codec: the HDA codec
3990 int snd_hda_add_imux_item(struct hda_codec *codec,
3996 codec_err(codec, "hda_codec: Too many imux items!\n");
4024 struct hda_codec *codec;
4026 list_for_each_codec(codec, bus) {
4028 if (current_work() != &codec->jackpoll_work.work)
4029 cancel_delayed_work_sync(&codec->jackpoll_work);
4031 if (hda_codec_is_power_on(codec)) {
4032 hda_call_codec_suspend(codec);
4033 hda_call_codec_resume(codec);
4060 MODULE_DESCRIPTION("HDA codec core");