forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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;
....@@ -788,16 +785,25 @@
788785 snd_array_free(&codec->spdif_out);
789786 snd_array_free(&codec->verbs);
790787 codec->preset = NULL;
791
- codec->slave_dig_outs = NULL;
788
+ codec->follower_dig_outs = NULL;
792789 codec->spdif_status_reset = 0;
793790 snd_array_free(&codec->mixers);
794791 snd_array_free(&codec->nids);
795792 remove_conn_list(codec);
796793 snd_hdac_regmap_exit(&codec->core);
794
+ codec->configured = 0;
797795 }
796
+EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind);
798797
799798 static unsigned int hda_set_power_state(struct hda_codec *codec,
800799 unsigned int power_state);
800
+
801
+/* enable/disable display power per codec */
802
+static void codec_display_power(struct hda_codec *codec, bool enable)
803
+{
804
+ if (codec->display_power_control)
805
+ snd_hdac_display_power(&codec->bus->core, codec->addr, enable);
806
+}
801807
802808 /* also called from hda_bind.c */
803809 void snd_hda_codec_register(struct hda_codec *codec)
....@@ -805,8 +811,7 @@
805811 if (codec->registered)
806812 return;
807813 if (device_is_registered(hda_codec_dev(codec))) {
808
- snd_hda_register_beep_device(codec);
809
- snd_hdac_link_power(&codec->core, true);
814
+ codec_display_power(codec, true);
810815 pm_runtime_enable(hda_codec_dev(codec));
811816 /* it was powered up in snd_hda_codec_new(), now all done */
812817 snd_hda_power_down(codec);
....@@ -820,22 +825,27 @@
820825 return 0;
821826 }
822827
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
-
831828 static int snd_hda_codec_dev_free(struct snd_device *device)
832829 {
833830 struct hda_codec *codec = device->device_data;
834831
835832 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));
833
+ /*
834
+ * snd_hda_codec_device_new() is used by legacy HDA and ASoC driver.
835
+ * We can't unregister ASoC device since it will be unregistered in
836
+ * snd_hdac_ext_bus_device_remove().
837
+ */
838
+ if (codec->core.type == HDA_DEV_LEGACY)
839
+ snd_hdac_device_unregister(&codec->core);
840
+ codec_display_power(codec, false);
841
+
842
+ /*
843
+ * In the case of ASoC HD-audio bus, the device refcount is released in
844
+ * snd_hdac_ext_bus_device_remove() explicitly.
845
+ */
846
+ if (codec->core.type == HDA_DEV_LEGACY)
847
+ put_device(hda_codec_dev(codec));
848
+
839849 return 0;
840850 }
841851
....@@ -848,7 +858,13 @@
848858 snd_hda_sysfs_clear(codec);
849859 kfree(codec->modelname);
850860 kfree(codec->wcaps);
851
- kfree(codec);
861
+
862
+ /*
863
+ * In the case of ASoC HD-audio, hda_codec is device managed.
864
+ * It will be freed when the ASoC device is removed.
865
+ */
866
+ if (codec->core.type == HDA_DEV_LEGACY)
867
+ kfree(codec);
852868 }
853869
854870 #define DEV_NAME_LEN 31
....@@ -887,6 +903,7 @@
887903 /**
888904 * snd_hda_codec_new - create a HDA codec
889905 * @bus: the bus to assign
906
+ * @card: card for this codec
890907 * @codec_addr: the codec address
891908 * @codecp: the pointer to store the generated codec
892909 *
....@@ -911,9 +928,8 @@
911928 char component[31];
912929 hda_nid_t fg;
913930 int err;
914
- static struct snd_device_ops dev_ops = {
931
+ static const struct snd_device_ops dev_ops = {
915932 .dev_register = snd_hda_codec_dev_register,
916
- .dev_disconnect = snd_hda_codec_dev_disconnect,
917933 .dev_free = snd_hda_codec_dev_free,
918934 };
919935
....@@ -985,6 +1001,9 @@
9851001 if (err < 0)
9861002 goto error;
9871003
1004
+ /* PM runtime needs to be enabled later after binding codec */
1005
+ pm_runtime_forbid(&codec->core.dev);
1006
+
9881007 return 0;
9891008
9901009 error:
....@@ -1005,7 +1024,7 @@
10051024 hda_nid_t fg;
10061025 int err;
10071026
1008
- err = snd_hdac_refresh_widgets(&codec->core, true);
1027
+ err = snd_hdac_refresh_widgets(&codec->core);
10091028 if (err < 0)
10101029 return err;
10111030
....@@ -1264,6 +1283,18 @@
12641283 }
12651284 EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps);
12661285
1286
+static unsigned int encode_amp(struct hda_codec *codec, hda_nid_t nid,
1287
+ int ch, int dir, int idx)
1288
+{
1289
+ unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
1290
+
1291
+ /* enable fake mute if no h/w mute but min=mute */
1292
+ if ((query_amp_caps(codec, nid, dir) &
1293
+ (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) == AC_AMPCAP_MIN_MUTE)
1294
+ cmd |= AC_AMP_FAKE_MUTE;
1295
+ return cmd;
1296
+}
1297
+
12671298 /**
12681299 * snd_hda_codec_amp_update - update the AMP mono value
12691300 * @codec: HD-audio codec
....@@ -1279,12 +1310,8 @@
12791310 int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
12801311 int ch, int dir, int idx, int mask, int val)
12811312 {
1282
- unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
1313
+ unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
12831314
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;
12881315 return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val);
12891316 }
12901317 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
....@@ -1332,16 +1359,11 @@
13321359 int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
13331360 int dir, int idx, int mask, int val)
13341361 {
1335
- int orig;
1362
+ unsigned int cmd = encode_amp(codec, nid, ch, dir, idx);
13361363
13371364 if (!codec->core.regmap)
13381365 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);
1366
+ return snd_hdac_regmap_update_raw_once(&codec->core, cmd, mask, val);
13451367 }
13461368 EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
13471369
....@@ -1792,11 +1814,11 @@
17921814 return 0;
17931815 }
17941816
1795
-typedef int (*map_slave_func_t)(struct hda_codec *, void *, struct snd_kcontrol *);
1817
+typedef int (*map_follower_func_t)(struct hda_codec *, void *, struct snd_kcontrol *);
17961818
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)
1819
+/* apply the function to all matching follower ctls in the mixer list */
1820
+static int map_followers(struct hda_codec *codec, const char * const *followers,
1821
+ const char *suffix, map_follower_func_t func, void *data)
18001822 {
18011823 struct hda_nid_item *items;
18021824 const char * const *s;
....@@ -1807,7 +1829,7 @@
18071829 struct snd_kcontrol *sctl = items[i].kctl;
18081830 if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
18091831 continue;
1810
- for (s = slaves; *s; s++) {
1832
+ for (s = followers; *s; s++) {
18111833 char tmpname[sizeof(sctl->id.name)];
18121834 const char *name = *s;
18131835 if (suffix) {
....@@ -1826,8 +1848,8 @@
18261848 return 0;
18271849 }
18281850
1829
-static int check_slave_present(struct hda_codec *codec,
1830
- void *data, struct snd_kcontrol *sctl)
1851
+static int check_follower_present(struct hda_codec *codec,
1852
+ void *data, struct snd_kcontrol *sctl)
18311853 {
18321854 return 1;
18331855 }
....@@ -1846,17 +1868,17 @@
18461868 return 0;
18471869 }
18481870
1849
-struct slave_init_arg {
1871
+struct follower_init_arg {
18501872 struct hda_codec *codec;
18511873 int step;
18521874 };
18531875
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)
1876
+/* initialize the follower volume with 0dB via snd_ctl_apply_vmaster_followers() */
1877
+static int init_follower_0dB(struct snd_kcontrol *follower,
1878
+ struct snd_kcontrol *kctl,
1879
+ void *_arg)
18581880 {
1859
- struct slave_init_arg *arg = _arg;
1881
+ struct follower_init_arg *arg = _arg;
18601882 int _tlv[4];
18611883 const int *tlv = NULL;
18621884 int step;
....@@ -1865,7 +1887,7 @@
18651887 if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
18661888 if (kctl->tlv.c != snd_hda_mixer_amp_tlv) {
18671889 codec_err(arg->codec,
1868
- "Unexpected TLV callback for slave %s:%d\n",
1890
+ "Unexpected TLV callback for follower %s:%d\n",
18691891 kctl->id.name, kctl->id.index);
18701892 return 0; /* ignore */
18711893 }
....@@ -1883,7 +1905,7 @@
18831905 return 0;
18841906 if (arg->step && arg->step != step) {
18851907 codec_err(arg->codec,
1886
- "Mismatching dB step for vmaster slave (%d!=%d)\n",
1908
+ "Mismatching dB step for vmaster follower (%d!=%d)\n",
18871909 arg->step, step);
18881910 return 0;
18891911 }
....@@ -1891,49 +1913,49 @@
18911913 arg->step = step;
18921914 val = -tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] / step;
18931915 if (val > 0) {
1894
- put_kctl_with_value(slave, val);
1916
+ put_kctl_with_value(follower, val);
18951917 return val;
18961918 }
18971919
18981920 return 0;
18991921 }
19001922
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)
1923
+/* unmute the follower via snd_ctl_apply_vmaster_followers() */
1924
+static int init_follower_unmute(struct snd_kcontrol *follower,
1925
+ struct snd_kcontrol *kctl,
1926
+ void *_arg)
19051927 {
1906
- return put_kctl_with_value(slave, 1);
1928
+ return put_kctl_with_value(follower, 1);
19071929 }
19081930
1909
-static int add_slave(struct hda_codec *codec,
1910
- void *data, struct snd_kcontrol *slave)
1931
+static int add_follower(struct hda_codec *codec,
1932
+ void *data, struct snd_kcontrol *follower)
19111933 {
1912
- return snd_ctl_add_slave(data, slave);
1934
+ return snd_ctl_add_follower(data, follower);
19131935 }
19141936
19151937 /**
1916
- * __snd_hda_add_vmaster - create a virtual master control and add slaves
1938
+ * __snd_hda_add_vmaster - create a virtual master control and add followers
19171939 * @codec: HD-audio codec
19181940 * @name: vmaster control name
19191941 * @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
1942
+ * @followers: follower control names (optional)
1943
+ * @suffix: suffix string to each follower name (optional)
1944
+ * @init_follower_vol: initialize followers to unmute/0dB
19231945 * @ctl_ret: store the vmaster kcontrol in return
19241946 *
19251947 * Create a virtual master control with the given name. The TLV data
19261948 * must be either NULL or a valid data.
19271949 *
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
1950
+ * @followers is a NULL-terminated array of strings, each of which is a
1951
+ * follower control name. All controls with these names are assigned to
19301952 * the new virtual master control.
19311953 *
19321954 * This function returns zero if successful or a negative error code.
19331955 */
19341956 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,
1957
+ unsigned int *tlv, const char * const *followers,
1958
+ const char *suffix, bool init_follower_vol,
19371959 struct snd_kcontrol **ctl_ret)
19381960 {
19391961 struct snd_kcontrol *kctl;
....@@ -1942,9 +1964,9 @@
19421964 if (ctl_ret)
19431965 *ctl_ret = NULL;
19441966
1945
- err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
1967
+ err = map_followers(codec, followers, suffix, check_follower_present, NULL);
19461968 if (err != 1) {
1947
- codec_dbg(codec, "No slave found for %s\n", name);
1969
+ codec_dbg(codec, "No follower found for %s\n", name);
19481970 return 0;
19491971 }
19501972 kctl = snd_ctl_make_virtual_master(name, tlv);
....@@ -1954,20 +1976,20 @@
19541976 if (err < 0)
19551977 return err;
19561978
1957
- err = map_slaves(codec, slaves, suffix, add_slave, kctl);
1979
+ err = map_followers(codec, followers, suffix, add_follower, kctl);
19581980 if (err < 0)
19591981 return err;
19601982
19611983 /* init with master mute & zero volume */
19621984 put_kctl_with_value(kctl, 0);
1963
- if (init_slave_vol) {
1964
- struct slave_init_arg arg = {
1985
+ if (init_follower_vol) {
1986
+ struct follower_init_arg arg = {
19651987 .codec = codec,
19661988 .step = 0,
19671989 };
1968
- snd_ctl_apply_vmaster_slaves(kctl,
1969
- tlv ? init_slave_0dB : init_slave_unmute,
1970
- &arg);
1990
+ snd_ctl_apply_vmaster_followers(kctl,
1991
+ tlv ? init_follower_0dB : init_follower_unmute,
1992
+ &arg);
19711993 }
19721994
19731995 if (ctl_ret)
....@@ -2270,7 +2292,7 @@
22702292 return sbits;
22712293 }
22722294
2273
-/* set digital convert verbs both for the given NID and its slaves */
2295
+/* set digital convert verbs both for the given NID and its followers */
22742296 static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
22752297 int mask, int val)
22762298 {
....@@ -2278,7 +2300,7 @@
22782300
22792301 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
22802302 mask, val);
2281
- d = codec->slave_dig_outs;
2303
+ d = codec->follower_dig_outs;
22822304 if (!d)
22832305 return;
22842306 for (; *d; d++)
....@@ -2387,7 +2409,7 @@
23872409 return change;
23882410 }
23892411
2390
-static struct snd_kcontrol_new dig_mixes[] = {
2412
+static const struct snd_kcontrol_new dig_mixes[] = {
23912413 {
23922414 .access = SNDRV_CTL_ELEM_ACCESS_READ,
23932415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
....@@ -2437,7 +2459,7 @@
24372459 {
24382460 int err;
24392461 struct snd_kcontrol *kctl;
2440
- struct snd_kcontrol_new *dig_mix;
2462
+ const struct snd_kcontrol_new *dig_mix;
24412463 int idx = 0;
24422464 int val = 0;
24432465 const int spdif_index = 16;
....@@ -2655,7 +2677,7 @@
26552677 return 0;
26562678 }
26572679
2658
-static struct snd_kcontrol_new dig_in_ctls[] = {
2680
+static const struct snd_kcontrol_new dig_in_ctls[] = {
26592681 {
26602682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26612683 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
....@@ -2687,7 +2709,7 @@
26872709 {
26882710 int err;
26892711 struct snd_kcontrol *kctl;
2690
- struct snd_kcontrol_new *dig_mix;
2712
+ const struct snd_kcontrol_new *dig_mix;
26912713 int idx;
26922714
26932715 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
....@@ -2905,8 +2927,7 @@
29052927 else {
29062928 if (codec->patch_ops.init)
29072929 codec->patch_ops.init(codec);
2908
- if (codec->core.regmap)
2909
- regcache_sync(codec->core.regmap);
2930
+ snd_hda_regmap_sync(codec);
29102931 }
29112932
29122933 if (codec->jackpoll_interval)
....@@ -2920,18 +2941,19 @@
29202941 static int hda_codec_runtime_suspend(struct device *dev)
29212942 {
29222943 struct hda_codec *codec = dev_to_hda_codec(dev);
2923
- struct hda_pcm *pcm;
29242944 unsigned int state;
29252945
2946
+ /* Nothing to do if card registration fails and the component driver never probes */
2947
+ if (!codec->card)
2948
+ return 0;
2949
+
29262950 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);
29292951 state = hda_call_codec_suspend(codec);
29302952 if (codec->link_down_at_suspend ||
29312953 (codec_has_clkstop(codec) && codec_has_epss(codec) &&
29322954 (state & AC_PWRST_CLK_STOP_OK)))
29332955 snd_hdac_codec_link_down(&codec->core);
2934
- snd_hdac_link_power(&codec->core, false);
2956
+ codec_display_power(codec, false);
29352957 return 0;
29362958 }
29372959
....@@ -2939,31 +2961,37 @@
29392961 {
29402962 struct hda_codec *codec = dev_to_hda_codec(dev);
29412963
2942
- snd_hdac_link_power(&codec->core, true);
2964
+ /* Nothing to do if card registration fails and the component driver never probes */
2965
+ if (!codec->card)
2966
+ return 0;
2967
+
2968
+ codec_display_power(codec, true);
29432969 snd_hdac_codec_link_up(&codec->core);
29442970 hda_call_codec_resume(codec);
29452971 pm_runtime_mark_last_busy(dev);
29462972 return 0;
29472973 }
2974
+
29482975 #endif /* CONFIG_PM */
29492976
29502977 #ifdef CONFIG_PM_SLEEP
2951
-static int hda_codec_force_resume(struct device *dev)
2978
+static int hda_codec_pm_prepare(struct device *dev)
2979
+{
2980
+ dev->power.power_state = PMSG_SUSPEND;
2981
+ return pm_runtime_suspended(dev);
2982
+}
2983
+
2984
+static void hda_codec_pm_complete(struct device *dev)
29522985 {
29532986 struct hda_codec *codec = dev_to_hda_codec(dev);
2954
- bool forced_resume = !codec->relaxed_resume;
2955
- int ret;
29562987
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;
2988
+ /* If no other pm-functions are called between prepare() and complete() */
2989
+ if (dev->power.power_state.event == PM_EVENT_SUSPEND)
2990
+ dev->power.power_state = PMSG_RESUME;
2991
+
2992
+ if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
2993
+ hda_codec_need_resume(codec) || codec->forced_resume))
2994
+ pm_request_resume(dev);
29672995 }
29682996
29692997 static int hda_codec_pm_suspend(struct device *dev)
....@@ -2975,7 +3003,7 @@
29753003 static int hda_codec_pm_resume(struct device *dev)
29763004 {
29773005 dev->power.power_state = PMSG_RESUME;
2978
- return hda_codec_force_resume(dev);
3006
+ return pm_runtime_force_resume(dev);
29793007 }
29803008
29813009 static int hda_codec_pm_freeze(struct device *dev)
....@@ -2987,19 +3015,21 @@
29873015 static int hda_codec_pm_thaw(struct device *dev)
29883016 {
29893017 dev->power.power_state = PMSG_THAW;
2990
- return hda_codec_force_resume(dev);
3018
+ return pm_runtime_force_resume(dev);
29913019 }
29923020
29933021 static int hda_codec_pm_restore(struct device *dev)
29943022 {
29953023 dev->power.power_state = PMSG_RESTORE;
2996
- return hda_codec_force_resume(dev);
3024
+ return pm_runtime_force_resume(dev);
29973025 }
29983026 #endif /* CONFIG_PM_SLEEP */
29993027
30003028 /* referred in hda_bind.c */
30013029 const struct dev_pm_ops hda_codec_driver_pm = {
30023030 #ifdef CONFIG_PM_SLEEP
3031
+ .prepare = hda_codec_pm_prepare,
3032
+ .complete = hda_codec_pm_complete,
30033033 .suspend = hda_codec_pm_suspend,
30043034 .resume = hda_codec_pm_resume,
30053035 .freeze = hda_codec_pm_freeze,
....@@ -3172,7 +3202,7 @@
31723202 EXPORT_SYMBOL_GPL(snd_hda_codec_prepare);
31733203
31743204 /**
3175
- * snd_hda_codec_cleanup - Prepare a stream
3205
+ * snd_hda_codec_cleanup - Clean up stream resources
31763206 * @codec: the HDA codec
31773207 * @hinfo: PCM information
31783208 * @substream: PCM substream
....@@ -3204,7 +3234,7 @@
32043234 /* assigned to static slots up to dev#10; if more needed, assign
32053235 * the later slot dynamically (when CONFIG_SND_DYNAMIC_MINORS=y)
32063236 */
3207
- static int audio_idx[HDA_PCM_NTYPES][5] = {
3237
+ static const int audio_idx[HDA_PCM_NTYPES][5] = {
32083238 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
32093239 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
32103240 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
....@@ -3574,9 +3604,9 @@
35743604 spdif->ctls & ~AC_DIG1_ENABLE & 0xff,
35753605 -1);
35763606 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
3577
- if (codec->slave_dig_outs) {
3607
+ if (codec->follower_dig_outs) {
35783608 const hda_nid_t *d;
3579
- for (d = codec->slave_dig_outs; *d; d++)
3609
+ for (d = codec->follower_dig_outs; *d; d++)
35803610 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
35813611 format);
35823612 }
....@@ -3589,9 +3619,9 @@
35893619 static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
35903620 {
35913621 snd_hda_codec_cleanup_stream(codec, nid);
3592
- if (codec->slave_dig_outs) {
3622
+ if (codec->follower_dig_outs) {
35933623 const hda_nid_t *d;
3594
- for (d = codec->slave_dig_outs; *d; d++)
3624
+ for (d = codec->follower_dig_outs; *d; d++)
35953625 snd_hda_codec_cleanup_stream(codec, *d);
35963626 }
35973627 }
....@@ -3673,7 +3703,7 @@
36733703 * @hinfo: PCM information to assign
36743704 *
36753705 * Open analog outputs and set up the hw-constraints.
3676
- * If the digital outputs can be opened as slave, open the digital
3706
+ * If the digital outputs can be opened as follower, open the digital
36773707 * outputs, too.
36783708 */
36793709 int snd_hda_multi_out_analog_open(struct hda_codec *codec,
....@@ -3872,7 +3902,7 @@
38723902 unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
38733903 hda_nid_t pin, unsigned int val)
38743904 {
3875
- static unsigned int cap_lists[][2] = {
3905
+ static const unsigned int cap_lists[][2] = {
38763906 { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 },
38773907 { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 },
38783908 { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 },
....@@ -4017,7 +4047,7 @@
40174047 */
40184048 void snd_print_pcm_bits(int pcm, char *buf, int buflen)
40194049 {
4020
- static unsigned int bits[] = { 8, 16, 20, 24, 32 };
4050
+ static const unsigned int bits[] = { 8, 16, 20, 24, 32 };
40214051 int i, j;
40224052
40234053 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)