hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/pci/hda/hda_codec.c
....@@ -1,22 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Universal Interface for Intel High Definition Audio Codec
34 *
45 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
5
- *
6
- *
7
- * This driver is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This driver is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
206 */
217
228 #include <linux/init.h>
....@@ -27,7 +13,7 @@
2713 #include <linux/pm.h>
2814 #include <linux/pm_runtime.h>
2915 #include <sound/core.h>
30
-#include "hda_codec.h"
16
+#include <sound/hda_codec.h>
3117 #include <sound/asoundef.h>
3218 #include <sound/tlv.h>
3319 #include <sound/initval.h>
....@@ -36,6 +22,7 @@
3622 #include "hda_beep.h"
3723 #include "hda_jack.h"
3824 #include <sound/hda_hwdep.h>
25
+#include <sound/hda_component.h>
3926
4027 #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core)
4128 #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core)
....@@ -101,7 +88,7 @@
10188 struct list_head list;
10289 int len;
10390 hda_nid_t nid;
104
- hda_nid_t conns[0];
91
+ hda_nid_t conns[];
10592 };
10693
10794 /* look up the cached results */
....@@ -121,7 +108,7 @@
121108 {
122109 struct hda_conn_list *p;
123110
124
- p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL);
111
+ p = kmalloc(struct_size(p, conns, len), GFP_KERNEL);
125112 if (!p)
126113 return -ENOMEM;
127114 p->len = len;
....@@ -654,8 +641,18 @@
654641 struct hda_codec *codec =
655642 container_of(work, struct hda_codec, jackpoll_work.work);
656643
657
- snd_hda_jack_set_dirty_all(codec);
658
- snd_hda_jack_poll_all(codec);
644
+ /* for non-polling trigger: we need nothing if already powered on */
645
+ if (!codec->jackpoll_interval && snd_hdac_is_power_on(&codec->core))
646
+ return;
647
+
648
+ /* the power-up/down sequence triggers the runtime resume */
649
+ snd_hda_power_up_pm(codec);
650
+ /* update jacks manually if polling is required, too */
651
+ if (codec->jackpoll_interval) {
652
+ snd_hda_jack_set_dirty_all(codec);
653
+ snd_hda_jack_poll_all(codec);
654
+ }
655
+ snd_hda_power_down_pm(codec);
659656
660657 if (!codec->jackpoll_interval)
661658 return;
....@@ -787,17 +784,25 @@
787784 snd_array_free(&codec->cvt_setups);
788785 snd_array_free(&codec->spdif_out);
789786 snd_array_free(&codec->verbs);
790
- codec->preset = NULL;
791
- codec->slave_dig_outs = NULL;
787
+ codec->follower_dig_outs = NULL;
792788 codec->spdif_status_reset = 0;
793789 snd_array_free(&codec->mixers);
794790 snd_array_free(&codec->nids);
795791 remove_conn_list(codec);
796792 snd_hdac_regmap_exit(&codec->core);
793
+ codec->configured = 0;
797794 }
795
+EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind);
798796
799797 static unsigned int hda_set_power_state(struct hda_codec *codec,
800798 unsigned int power_state);
799
+
800
+/* enable/disable display power per codec */
801
+static void codec_display_power(struct hda_codec *codec, bool enable)
802
+{
803
+ if (codec->display_power_control)
804
+ snd_hdac_display_power(&codec->bus->core, codec->addr, enable);
805
+}
801806
802807 /* also called from hda_bind.c */
803808 void snd_hda_codec_register(struct hda_codec *codec)
....@@ -805,8 +810,7 @@
805810 if (codec->registered)
806811 return;
807812 if (device_is_registered(hda_codec_dev(codec))) {
808
- snd_hda_register_beep_device(codec);
809
- snd_hdac_link_power(&codec->core, true);
813
+ codec_display_power(codec, true);
810814 pm_runtime_enable(hda_codec_dev(codec));
811815 /* it was powered up in snd_hda_codec_new(), now all done */
812816 snd_hda_power_down(codec);
....@@ -820,22 +824,27 @@
820824 return 0;
821825 }
822826
823
-static int snd_hda_codec_dev_disconnect(struct snd_device *device)
824
-{
825
- struct hda_codec *codec = device->device_data;
826
-
827
- snd_hda_detach_beep_device(codec);
828
- return 0;
829
-}
830
-
831827 static int snd_hda_codec_dev_free(struct snd_device *device)
832828 {
833829 struct hda_codec *codec = device->device_data;
834830
835831 codec->in_freeing = 1;
836
- snd_hdac_device_unregister(&codec->core);
837
- snd_hdac_link_power(&codec->core, false);
838
- put_device(hda_codec_dev(codec));
832
+ /*
833
+ * snd_hda_codec_device_new() is used by legacy HDA and ASoC driver.
834
+ * We can't unregister ASoC device since it will be unregistered in
835
+ * snd_hdac_ext_bus_device_remove().
836
+ */
837
+ if (codec->core.type == HDA_DEV_LEGACY)
838
+ snd_hdac_device_unregister(&codec->core);
839
+ codec_display_power(codec, false);
840
+
841
+ /*
842
+ * In the case of ASoC HD-audio bus, the device refcount is released in
843
+ * snd_hdac_ext_bus_device_remove() explicitly.
844
+ */
845
+ if (codec->core.type == HDA_DEV_LEGACY)
846
+ put_device(hda_codec_dev(codec));
847
+
839848 return 0;
840849 }
841850
....@@ -848,7 +857,13 @@
848857 snd_hda_sysfs_clear(codec);
849858 kfree(codec->modelname);
850859 kfree(codec->wcaps);
851
- kfree(codec);
860
+
861
+ /*
862
+ * In the case of ASoC HD-audio, hda_codec is device managed.
863
+ * It will be freed when the ASoC device is removed.
864
+ */
865
+ if (codec->core.type == HDA_DEV_LEGACY)
866
+ kfree(codec);
852867 }
853868
854869 #define DEV_NAME_LEN 31
....@@ -887,6 +902,7 @@
887902 /**
888903 * snd_hda_codec_new - create a HDA codec
889904 * @bus: the bus to assign
905
+ * @card: card for this codec
890906 * @codec_addr: the codec address
891907 * @codecp: the pointer to store the generated codec
892908 *
....@@ -911,9 +927,8 @@
911927 char component[31];
912928 hda_nid_t fg;
913929 int err;
914
- static struct snd_device_ops dev_ops = {
930
+ static const struct snd_device_ops dev_ops = {
915931 .dev_register = snd_hda_codec_dev_register,
916
- .dev_disconnect = snd_hda_codec_dev_disconnect,
917932 .dev_free = snd_hda_codec_dev_free,
918933 };
919934
....@@ -985,6 +1000,9 @@
9851000 if (err < 0)
9861001 goto error;
9871002
1003
+ /* PM runtime needs to be enabled later after binding codec */
1004
+ pm_runtime_forbid(&codec->core.dev);
1005
+
9881006 return 0;
9891007
9901008 error:
....@@ -1005,7 +1023,7 @@
10051023 hda_nid_t fg;
10061024 int err;
10071025
1008
- err = snd_hdac_refresh_widgets(&codec->core, true);
1026
+ err = snd_hdac_refresh_widgets(&codec->core);
10091027 if (err < 0)
10101028 return err;
10111029
....@@ -1264,6 +1282,18 @@
12641282 }
12651283 EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps);
12661284
1285
+static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid,
1286
+ int ch, int dir, int idx)
1287
+{
1288
+ unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
1289
+
1290
+ /* enable fake mute if no h/w mute but min=mute */
1291
+ if ((query_amp_caps(codec, nid, dir) &
1292
+ (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) == AC_AMPCAP_MIN_MUTE)
1293
+ cmd |= AC_AMP_FAKE_MUTE;
1294
+ return cmd;
1295
+}
1296
+
12671297 /**
12681298 * snd_hda_codec_amp_update - update the AMP mono value
12691299 * @codec: HD-audio codec
....@@ -1279,12 +1309,8 @@
12791309 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
12801310 int ch, int dir, int idx, int mask, int val)
12811311 {
1282
- unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
1312
+ unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
12831313
1284
- /* enable fake mute if no h/w mute but min=mute */
1285
- if ((query_amp_caps(codec, nid, dir) &
1286
- (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) == AC_AMPCAP_MIN_MUTE)
1287
- cmd |= AC_AMP_FAKE_MUTE;
12881314 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
12891315 }
12901316 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
....@@ -1332,16 +1358,11 @@
13321358 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
13331359 int dir, int idx, int mask, int val)
13341360 {
1335
- int orig;
1361
+ unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
13361362
13371363 if (!codec->core.regmap)
13381364 return -EINVAL;
1339
- regcache_cache_only(codec->core.regmap, true);
1340
- orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1341
- regcache_cache_only(codec->core.regmap, false);
1342
- if (orig >= 0)
1343
- return 0;
1344
- return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val);
1365
+ return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val);
13451366 }
13461367 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
13471368
....@@ -1792,11 +1813,11 @@
17921813 return 0;
17931814 }
17941815
1795
-typedef int (*map_slave_func_t)(struct hda_codec *, void *, struct snd_kcontrol *);
1816
+typedef int (*map_follower_func_t)(struct hda_codec *, void *, struct snd_kcontrol *);
17961817
1797
-/* apply the function to all matching slave ctls in the mixer list */
1798
-static int map_slaves(struct hda_codec *codec, const char * const *slaves,
1799
- const char *suffix, map_slave_func_t func, void *data)
1818
+/* apply the function to all matching follower ctls in the mixer list */
1819
+static int map_followers(struct hda_codec *codec, const char * const *followers,
1820
+ const char *suffix, map_follower_func_t func, void *data)
18001821 {
18011822 struct hda_nid_item *items;
18021823 const char * const *s;
....@@ -1807,7 +1828,7 @@
18071828 struct snd_kcontrol *sctl = items[i].kctl;
18081829 if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
18091830 continue;
1810
- for (s = slaves; *s; s++) {
1831
+ for (s = followers; *s; s++) {
18111832 char tmpname[sizeof(sctl->id.name)];
18121833 const char *name = *s;
18131834 if (suffix) {
....@@ -1826,8 +1847,8 @@
18261847 return 0;
18271848 }
18281849
1829
-static int check_slave_present(struct hda_codec *codec,
1830
- void *data, struct snd_kcontrol *sctl)
1850
+static int check_follower_present(struct hda_codec *codec,
1851
+ void *data, struct snd_kcontrol *sctl)
18311852 {
18321853 return 1;
18331854 }
....@@ -1846,17 +1867,17 @@
18461867 return 0;
18471868 }
18481869
1849
-struct slave_init_arg {
1870
+struct follower_init_arg {
18501871 struct hda_codec *codec;
18511872 int step;
18521873 };
18531874
1854
-/* initialize the slave volume with 0dB via snd_ctl_apply_vmaster_slaves() */
1855
-static int init_slave_0dB(struct snd_kcontrol *slave,
1856
- struct snd_kcontrol *kctl,
1857
- void *_arg)
1875
+/* initialize the follower volume with 0dB via snd_ctl_apply_vmaster_followers() */
1876
+static int init_follower_0dB(struct snd_kcontrol *follower,
1877
+ struct snd_kcontrol *kctl,
1878
+ void *_arg)
18581879 {
1859
- struct slave_init_arg *arg = _arg;
1880
+ struct follower_init_arg *arg = _arg;
18601881 int _tlv[4];
18611882 const int *tlv = NULL;
18621883 int step;
....@@ -1865,7 +1886,7 @@
18651886 if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
18661887 if (kctl->tlv.c != snd_hda_mixer_amp_tlv) {
18671888 codec_err(arg->codec,
1868
- "Unexpected TLV callback for slave %s:%d\n",
1889
+ "Unexpected TLV callback for follower %s:%d\n",
18691890 kctl->id.name, kctl->id.index);
18701891 return 0; /* ignore */
18711892 }
....@@ -1883,7 +1904,7 @@
18831904 return 0;
18841905 if (arg->step && arg->step != step) {
18851906 codec_err(arg->codec,
1886
- "Mismatching dB step for vmaster slave (%d!=%d)\n",
1907
+ "Mismatching dB step for vmaster follower (%d!=%d)\n",
18871908 arg->step, step);
18881909 return 0;
18891910 }
....@@ -1891,49 +1912,49 @@
18911912 arg->step = step;
18921913 val = -tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] / step;
18931914 if (val > 0) {
1894
- put_kctl_with_value(slave, val);
1915
+ put_kctl_with_value(follower, val);
18951916 return val;
18961917 }
18971918
18981919 return 0;
18991920 }
19001921
1901
-/* unmute the slave via snd_ctl_apply_vmaster_slaves() */
1902
-static int init_slave_unmute(struct snd_kcontrol *slave,
1903
- struct snd_kcontrol *kctl,
1904
- void *_arg)
1922
+/* unmute the follower via snd_ctl_apply_vmaster_followers() */
1923
+static int init_follower_unmute(struct snd_kcontrol *follower,
1924
+ struct snd_kcontrol *kctl,
1925
+ void *_arg)
19051926 {
1906
- return put_kctl_with_value(slave, 1);
1927
+ return put_kctl_with_value(follower, 1);
19071928 }
19081929
1909
-static int add_slave(struct hda_codec *codec,
1910
- void *data, struct snd_kcontrol *slave)
1930
+static int add_follower(struct hda_codec *codec,
1931
+ void *data, struct snd_kcontrol *follower)
19111932 {
1912
- return snd_ctl_add_slave(data, slave);
1933
+ return snd_ctl_add_follower(data, follower);
19131934 }
19141935
19151936 /**
1916
- * __snd_hda_add_vmaster - create a virtual master control and add slaves
1937
+ * __snd_hda_add_vmaster - create a virtual master control and add followers
19171938 * @codec: HD-audio codec
19181939 * @name: vmaster control name
19191940 * @tlv: TLV data (optional)
1920
- * @slaves: slave control names (optional)
1921
- * @suffix: suffix string to each slave name (optional)
1922
- * @init_slave_vol: initialize slaves to unmute/0dB
1941
+ * @followers: follower control names (optional)
1942
+ * @suffix: suffix string to each follower name (optional)
1943
+ * @init_follower_vol: initialize followers to unmute/0dB
19231944 * @ctl_ret: store the vmaster kcontrol in return
19241945 *
19251946 * Create a virtual master control with the given name. The TLV data
19261947 * must be either NULL or a valid data.
19271948 *
1928
- * @slaves is a NULL-terminated array of strings, each of which is a
1929
- * slave control name. All controls with these names are assigned to
1949
+ * @followers is a NULL-terminated array of strings, each of which is a
1950
+ * follower control name. All controls with these names are assigned to
19301951 * the new virtual master control.
19311952 *
19321953 * This function returns zero if successful or a negative error code.
19331954 */
19341955 int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1935
- unsigned int *tlv, const char * const *slaves,
1936
- const char *suffix, bool init_slave_vol,
1956
+ unsigned int *tlv, const char * const *followers,
1957
+ const char *suffix, bool init_follower_vol,
19371958 struct snd_kcontrol **ctl_ret)
19381959 {
19391960 struct snd_kcontrol *kctl;
....@@ -1942,9 +1963,9 @@
19421963 if (ctl_ret)
19431964 *ctl_ret = NULL;
19441965
1945
- err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
1966
+ err = map_followers(codec, followers, suffix, check_follower_present, NULL);
19461967 if (err != 1) {
1947
- codec_dbg(codec, "No slave found for %s\n", name);
1968
+ codec_dbg(codec, "No follower found for %s\n", name);
19481969 return 0;
19491970 }
19501971 kctl = snd_ctl_make_virtual_master(name, tlv);
....@@ -1954,20 +1975,20 @@
19541975 if (err < 0)
19551976 return err;
19561977
1957
- err = map_slaves(codec, slaves, suffix, add_slave, kctl);
1978
+ err = map_followers(codec, followers, suffix, add_follower, kctl);
19581979 if (err < 0)
19591980 return err;
19601981
19611982 /* init with master mute & zero volume */
19621983 put_kctl_with_value(kctl, 0);
1963
- if (init_slave_vol) {
1964
- struct slave_init_arg arg = {
1984
+ if (init_follower_vol) {
1985
+ struct follower_init_arg arg = {
19651986 .codec = codec,
19661987 .step = 0,
19671988 };
1968
- snd_ctl_apply_vmaster_slaves(kctl,
1969
- tlv ? init_slave_0dB : init_slave_unmute,
1970
- &arg);
1989
+ snd_ctl_apply_vmaster_followers(kctl,
1990
+ tlv ? init_follower_0dB : init_follower_unmute,
1991
+ &arg);
19711992 }
19721993
19731994 if (ctl_ret)
....@@ -2270,7 +2291,7 @@
22702291 return sbits;
22712292 }
22722293
2273
-/* set digital convert verbs both for the given NID and its slaves */
2294
+/* set digital convert verbs both for the given NID and its followers */
22742295 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
22752296 int mask, int val)
22762297 {
....@@ -2278,7 +2299,7 @@
22782299
22792300 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
22802301 mask, val);
2281
- d = codec->slave_dig_outs;
2302
+ d = codec->follower_dig_outs;
22822303 if (!d)
22832304 return;
22842305 for (; *d; d++)
....@@ -2387,7 +2408,7 @@
23872408 return change;
23882409 }
23892410
2390
-static struct snd_kcontrol_new dig_mixes[] = {
2411
+static const struct snd_kcontrol_new dig_mixes[] = {
23912412 {
23922413 .access = SNDRV_CTL_ELEM_ACCESS_READ,
23932414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
....@@ -2437,7 +2458,7 @@
24372458 {
24382459 int err;
24392460 struct snd_kcontrol *kctl;
2440
- struct snd_kcontrol_new *dig_mix;
2461
+ const struct snd_kcontrol_new *dig_mix;
24412462 int idx = 0;
24422463 int val = 0;
24432464 const int spdif_index = 16;
....@@ -2655,7 +2676,7 @@
26552676 return 0;
26562677 }
26572678
2658
-static struct snd_kcontrol_new dig_in_ctls[] = {
2679
+static const struct snd_kcontrol_new dig_in_ctls[] = {
26592680 {
26602681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26612682 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
....@@ -2687,7 +2708,7 @@
26872708 {
26882709 int err;
26892710 struct snd_kcontrol *kctl;
2690
- struct snd_kcontrol_new *dig_mix;
2711
+ const struct snd_kcontrol_new *dig_mix;
26912712 int idx;
26922713
26932714 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
....@@ -2905,8 +2926,7 @@
29052926 else {
29062927 if (codec->patch_ops.init)
29072928 codec->patch_ops.init(codec);
2908
- if (codec->core.regmap)
2909
- regcache_sync(codec->core.regmap);
2929
+ snd_hda_regmap_sync(codec);
29102930 }
29112931
29122932 if (codec->jackpoll_interval)
....@@ -2920,18 +2940,19 @@
29202940 static int hda_codec_runtime_suspend(struct device *dev)
29212941 {
29222942 struct hda_codec *codec = dev_to_hda_codec(dev);
2923
- struct hda_pcm *pcm;
29242943 unsigned int state;
29252944
2945
+ /* Nothing to do if card registration fails and the component driver never probes */
2946
+ if (!codec->card)
2947
+ return 0;
2948
+
29262949 cancel_delayed_work_sync(&codec->jackpoll_work);
2927
- list_for_each_entry(pcm, &codec->pcm_list_head, list)
2928
- snd_pcm_suspend_all(pcm->pcm);
29292950 state = hda_call_codec_suspend(codec);
29302951 if (codec->link_down_at_suspend ||
29312952 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
29322953 (state & AC_PWRST_CLK_STOP_OK)))
29332954 snd_hdac_codec_link_down(&codec->core);
2934
- snd_hdac_link_power(&codec->core, false);
2955
+ codec_display_power(codec, false);
29352956 return 0;
29362957 }
29372958
....@@ -2939,31 +2960,37 @@
29392960 {
29402961 struct hda_codec *codec = dev_to_hda_codec(dev);
29412962
2942
- snd_hdac_link_power(&codec->core, true);
2963
+ /* Nothing to do if card registration fails and the component driver never probes */
2964
+ if (!codec->card)
2965
+ return 0;
2966
+
2967
+ codec_display_power(codec, true);
29432968 snd_hdac_codec_link_up(&codec->core);
29442969 hda_call_codec_resume(codec);
29452970 pm_runtime_mark_last_busy(dev);
29462971 return 0;
29472972 }
2973
+
29482974 #endif /* CONFIG_PM */
29492975
29502976 #ifdef CONFIG_PM_SLEEP
2951
-static int hda_codec_force_resume(struct device *dev)
2977
+static int hda_codec_pm_prepare(struct device *dev)
2978
+{
2979
+ dev->power.power_state = PMSG_SUSPEND;
2980
+ return pm_runtime_suspended(dev);
2981
+}
2982
+
2983
+static void hda_codec_pm_complete(struct device *dev)
29522984 {
29532985 struct hda_codec *codec = dev_to_hda_codec(dev);
2954
- bool forced_resume = !codec->relaxed_resume;
2955
- int ret;
29562986
2957
- /* The get/put pair below enforces the runtime resume even if the
2958
- * device hasn't been used at suspend time. This trick is needed to
2959
- * update the jack state change during the sleep.
2960
- */
2961
- if (forced_resume)
2962
- pm_runtime_get_noresume(dev);
2963
- ret = pm_runtime_force_resume(dev);
2964
- if (forced_resume)
2965
- pm_runtime_put(dev);
2966
- return ret;
2987
+ /* If no other pm-functions are called between prepare() and complete() */
2988
+ if (dev->power.power_state.event == PM_EVENT_SUSPEND)
2989
+ dev->power.power_state = PMSG_RESUME;
2990
+
2991
+ if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
2992
+ hda_codec_need_resume(codec) || codec->forced_resume))
2993
+ pm_request_resume(dev);
29672994 }
29682995
29692996 static int hda_codec_pm_suspend(struct device *dev)
....@@ -2975,7 +3002,7 @@
29753002 static int hda_codec_pm_resume(struct device *dev)
29763003 {
29773004 dev->power.power_state = PMSG_RESUME;
2978
- return hda_codec_force_resume(dev);
3005
+ return pm_runtime_force_resume(dev);
29793006 }
29803007
29813008 static int hda_codec_pm_freeze(struct device *dev)
....@@ -2987,19 +3014,21 @@
29873014 static int hda_codec_pm_thaw(struct device *dev)
29883015 {
29893016 dev->power.power_state = PMSG_THAW;
2990
- return hda_codec_force_resume(dev);
3017
+ return pm_runtime_force_resume(dev);
29913018 }
29923019
29933020 static int hda_codec_pm_restore(struct device *dev)
29943021 {
29953022 dev->power.power_state = PMSG_RESTORE;
2996
- return hda_codec_force_resume(dev);
3023
+ return pm_runtime_force_resume(dev);
29973024 }
29983025 #endif /* CONFIG_PM_SLEEP */
29993026
30003027 /* referred in hda_bind.c */
30013028 const struct dev_pm_ops hda_codec_driver_pm = {
30023029 #ifdef CONFIG_PM_SLEEP
3030
+ .prepare = hda_codec_pm_prepare,
3031
+ .complete = hda_codec_pm_complete,
30033032 .suspend = hda_codec_pm_suspend,
30043033 .resume = hda_codec_pm_resume,
30053034 .freeze = hda_codec_pm_freeze,
....@@ -3172,7 +3201,7 @@
31723201 EXPORT_SYMBOL_GPL(snd_hda_codec_prepare);
31733202
31743203 /**
3175
- * snd_hda_codec_cleanup - Prepare a stream
3204
+ * snd_hda_codec_cleanup - Clean up stream resources
31763205 * @codec: the HDA codec
31773206 * @hinfo: PCM information
31783207 * @substream: PCM substream
....@@ -3204,7 +3233,7 @@
32043233 /* assigned to static slots up to dev#10; if more needed, assign
32053234 * the later slot dynamically (when CONFIG_SND_DYNAMIC_MINORS=y)
32063235 */
3207
- static int audio_idx[HDA_PCM_NTYPES][5] = {
3236
+ static const int audio_idx[HDA_PCM_NTYPES][5] = {
32083237 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
32093238 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
32103239 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
....@@ -3574,9 +3603,9 @@
35743603 spdif->ctls & ~AC_DIG1_ENABLE & 0xff,
35753604 -1);
35763605 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3577
- if (codec->slave_dig_outs) {
3606
+ if (codec->follower_dig_outs) {
35783607 const hda_nid_t *d;
3579
- for (d = codec->slave_dig_outs; *d; d++)
3608
+ for (d = codec->follower_dig_outs; *d; d++)
35803609 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
35813610 format);
35823611 }
....@@ -3589,9 +3618,9 @@
35893618 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
35903619 {
35913620 snd_hda_codec_cleanup_stream(codec, nid);
3592
- if (codec->slave_dig_outs) {
3621
+ if (codec->follower_dig_outs) {
35933622 const hda_nid_t *d;
3594
- for (d = codec->slave_dig_outs; *d; d++)
3623
+ for (d = codec->follower_dig_outs; *d; d++)
35953624 snd_hda_codec_cleanup_stream(codec, *d);
35963625 }
35973626 }
....@@ -3673,7 +3702,7 @@
36733702 * @hinfo: PCM information to assign
36743703 *
36753704 * Open analog outputs and set up the hw-constraints.
3676
- * If the digital outputs can be opened as slave, open the digital
3705
+ * If the digital outputs can be opened as follower, open the digital
36773706 * outputs, too.
36783707 */
36793708 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
....@@ -3872,7 +3901,7 @@
38723901 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
38733902 hda_nid_t pin, unsigned int val)
38743903 {
3875
- static unsigned int cap_lists[][2] = {
3904
+ static const unsigned int cap_lists[][2] = {
38763905 { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 },
38773906 { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 },
38783907 { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 },
....@@ -4017,7 +4046,7 @@
40174046 */
40184047 void snd_print_pcm_bits(int pcm, char *buf, int buflen)
40194048 {
4020
- static unsigned int bits[] = { 8, 16, 20, 24, 32 };
4049
+ static const unsigned int bits[] = { 8, 16, 20, 24, 32 };
40214050 int i, j;
40224051
40234052 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)