.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Universal Interface for Intel High Definition Audio Codec |
---|
3 | 4 | * |
---|
4 | 5 | * 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 |
---|
20 | 6 | */ |
---|
21 | 7 | |
---|
22 | 8 | #include <linux/init.h> |
---|
.. | .. |
---|
27 | 13 | #include <linux/pm.h> |
---|
28 | 14 | #include <linux/pm_runtime.h> |
---|
29 | 15 | #include <sound/core.h> |
---|
30 | | -#include "hda_codec.h" |
---|
| 16 | +#include <sound/hda_codec.h> |
---|
31 | 17 | #include <sound/asoundef.h> |
---|
32 | 18 | #include <sound/tlv.h> |
---|
33 | 19 | #include <sound/initval.h> |
---|
.. | .. |
---|
36 | 22 | #include "hda_beep.h" |
---|
37 | 23 | #include "hda_jack.h" |
---|
38 | 24 | #include <sound/hda_hwdep.h> |
---|
| 25 | +#include <sound/hda_component.h> |
---|
39 | 26 | |
---|
40 | 27 | #define codec_in_pm(codec) snd_hdac_is_in_pm(&codec->core) |
---|
41 | 28 | #define hda_codec_is_power_on(codec) snd_hdac_is_power_on(&codec->core) |
---|
.. | .. |
---|
101 | 88 | struct list_head list; |
---|
102 | 89 | int len; |
---|
103 | 90 | hda_nid_t nid; |
---|
104 | | - hda_nid_t conns[0]; |
---|
| 91 | + hda_nid_t conns[]; |
---|
105 | 92 | }; |
---|
106 | 93 | |
---|
107 | 94 | /* look up the cached results */ |
---|
.. | .. |
---|
121 | 108 | { |
---|
122 | 109 | struct hda_conn_list *p; |
---|
123 | 110 | |
---|
124 | | - p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL); |
---|
| 111 | + p = kmalloc(struct_size(p, conns, len), GFP_KERNEL); |
---|
125 | 112 | if (!p) |
---|
126 | 113 | return -ENOMEM; |
---|
127 | 114 | p->len = len; |
---|
.. | .. |
---|
654 | 641 | struct hda_codec *codec = |
---|
655 | 642 | container_of(work, struct hda_codec, jackpoll_work.work); |
---|
656 | 643 | |
---|
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); |
---|
659 | 656 | |
---|
660 | 657 | if (!codec->jackpoll_interval) |
---|
661 | 658 | return; |
---|
.. | .. |
---|
787 | 784 | snd_array_free(&codec->cvt_setups); |
---|
788 | 785 | snd_array_free(&codec->spdif_out); |
---|
789 | 786 | snd_array_free(&codec->verbs); |
---|
790 | | - codec->preset = NULL; |
---|
791 | | - codec->slave_dig_outs = NULL; |
---|
| 787 | + codec->follower_dig_outs = NULL; |
---|
792 | 788 | codec->spdif_status_reset = 0; |
---|
793 | 789 | snd_array_free(&codec->mixers); |
---|
794 | 790 | snd_array_free(&codec->nids); |
---|
795 | 791 | remove_conn_list(codec); |
---|
796 | 792 | snd_hdac_regmap_exit(&codec->core); |
---|
| 793 | + codec->configured = 0; |
---|
797 | 794 | } |
---|
| 795 | +EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind); |
---|
798 | 796 | |
---|
799 | 797 | static unsigned int hda_set_power_state(struct hda_codec *codec, |
---|
800 | 798 | 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 | +} |
---|
801 | 806 | |
---|
802 | 807 | /* also called from hda_bind.c */ |
---|
803 | 808 | void snd_hda_codec_register(struct hda_codec *codec) |
---|
.. | .. |
---|
805 | 810 | if (codec->registered) |
---|
806 | 811 | return; |
---|
807 | 812 | 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); |
---|
810 | 814 | pm_runtime_enable(hda_codec_dev(codec)); |
---|
811 | 815 | /* it was powered up in snd_hda_codec_new(), now all done */ |
---|
812 | 816 | snd_hda_power_down(codec); |
---|
.. | .. |
---|
820 | 824 | return 0; |
---|
821 | 825 | } |
---|
822 | 826 | |
---|
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 | | - |
---|
831 | 827 | static int snd_hda_codec_dev_free(struct snd_device *device) |
---|
832 | 828 | { |
---|
833 | 829 | struct hda_codec *codec = device->device_data; |
---|
834 | 830 | |
---|
835 | 831 | 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 | + |
---|
839 | 848 | return 0; |
---|
840 | 849 | } |
---|
841 | 850 | |
---|
.. | .. |
---|
848 | 857 | snd_hda_sysfs_clear(codec); |
---|
849 | 858 | kfree(codec->modelname); |
---|
850 | 859 | 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); |
---|
852 | 867 | } |
---|
853 | 868 | |
---|
854 | 869 | #define DEV_NAME_LEN 31 |
---|
.. | .. |
---|
887 | 902 | /** |
---|
888 | 903 | * snd_hda_codec_new - create a HDA codec |
---|
889 | 904 | * @bus: the bus to assign |
---|
| 905 | + * @card: card for this codec |
---|
890 | 906 | * @codec_addr: the codec address |
---|
891 | 907 | * @codecp: the pointer to store the generated codec |
---|
892 | 908 | * |
---|
.. | .. |
---|
911 | 927 | char component[31]; |
---|
912 | 928 | hda_nid_t fg; |
---|
913 | 929 | int err; |
---|
914 | | - static struct snd_device_ops dev_ops = { |
---|
| 930 | + static const struct snd_device_ops dev_ops = { |
---|
915 | 931 | .dev_register = snd_hda_codec_dev_register, |
---|
916 | | - .dev_disconnect = snd_hda_codec_dev_disconnect, |
---|
917 | 932 | .dev_free = snd_hda_codec_dev_free, |
---|
918 | 933 | }; |
---|
919 | 934 | |
---|
.. | .. |
---|
985 | 1000 | if (err < 0) |
---|
986 | 1001 | goto error; |
---|
987 | 1002 | |
---|
| 1003 | + /* PM runtime needs to be enabled later after binding codec */ |
---|
| 1004 | + pm_runtime_forbid(&codec->core.dev); |
---|
| 1005 | + |
---|
988 | 1006 | return 0; |
---|
989 | 1007 | |
---|
990 | 1008 | error: |
---|
.. | .. |
---|
1005 | 1023 | hda_nid_t fg; |
---|
1006 | 1024 | int err; |
---|
1007 | 1025 | |
---|
1008 | | - err = snd_hdac_refresh_widgets(&codec->core, true); |
---|
| 1026 | + err = snd_hdac_refresh_widgets(&codec->core); |
---|
1009 | 1027 | if (err < 0) |
---|
1010 | 1028 | return err; |
---|
1011 | 1029 | |
---|
.. | .. |
---|
1264 | 1282 | } |
---|
1265 | 1283 | EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); |
---|
1266 | 1284 | |
---|
| 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 | + |
---|
1267 | 1297 | /** |
---|
1268 | 1298 | * snd_hda_codec_amp_update - update the AMP mono value |
---|
1269 | 1299 | * @codec: HD-audio codec |
---|
.. | .. |
---|
1279 | 1309 | int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, |
---|
1280 | 1310 | int ch, int dir, int idx, int mask, int val) |
---|
1281 | 1311 | { |
---|
1282 | | - unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx); |
---|
| 1312 | + unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); |
---|
1283 | 1313 | |
---|
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; |
---|
1288 | 1314 | return snd_hdac_regmap_update_raw(&codec->core, cmd, mask, val); |
---|
1289 | 1315 | } |
---|
1290 | 1316 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); |
---|
.. | .. |
---|
1332 | 1358 | int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, |
---|
1333 | 1359 | int dir, int idx, int mask, int val) |
---|
1334 | 1360 | { |
---|
1335 | | - int orig; |
---|
| 1361 | + unsigned int cmd = encode_amp(codec, nid, ch, dir, idx); |
---|
1336 | 1362 | |
---|
1337 | 1363 | if (!codec->core.regmap) |
---|
1338 | 1364 | 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); |
---|
1345 | 1366 | } |
---|
1346 | 1367 | EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); |
---|
1347 | 1368 | |
---|
.. | .. |
---|
1792 | 1813 | return 0; |
---|
1793 | 1814 | } |
---|
1794 | 1815 | |
---|
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 *); |
---|
1796 | 1817 | |
---|
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) |
---|
1800 | 1821 | { |
---|
1801 | 1822 | struct hda_nid_item *items; |
---|
1802 | 1823 | const char * const *s; |
---|
.. | .. |
---|
1807 | 1828 | struct snd_kcontrol *sctl = items[i].kctl; |
---|
1808 | 1829 | if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER) |
---|
1809 | 1830 | continue; |
---|
1810 | | - for (s = slaves; *s; s++) { |
---|
| 1831 | + for (s = followers; *s; s++) { |
---|
1811 | 1832 | char tmpname[sizeof(sctl->id.name)]; |
---|
1812 | 1833 | const char *name = *s; |
---|
1813 | 1834 | if (suffix) { |
---|
.. | .. |
---|
1826 | 1847 | return 0; |
---|
1827 | 1848 | } |
---|
1828 | 1849 | |
---|
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) |
---|
1831 | 1852 | { |
---|
1832 | 1853 | return 1; |
---|
1833 | 1854 | } |
---|
.. | .. |
---|
1846 | 1867 | return 0; |
---|
1847 | 1868 | } |
---|
1848 | 1869 | |
---|
1849 | | -struct slave_init_arg { |
---|
| 1870 | +struct follower_init_arg { |
---|
1850 | 1871 | struct hda_codec *codec; |
---|
1851 | 1872 | int step; |
---|
1852 | 1873 | }; |
---|
1853 | 1874 | |
---|
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) |
---|
1858 | 1879 | { |
---|
1859 | | - struct slave_init_arg *arg = _arg; |
---|
| 1880 | + struct follower_init_arg *arg = _arg; |
---|
1860 | 1881 | int _tlv[4]; |
---|
1861 | 1882 | const int *tlv = NULL; |
---|
1862 | 1883 | int step; |
---|
.. | .. |
---|
1865 | 1886 | if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { |
---|
1866 | 1887 | if (kctl->tlv.c != snd_hda_mixer_amp_tlv) { |
---|
1867 | 1888 | codec_err(arg->codec, |
---|
1868 | | - "Unexpected TLV callback for slave %s:%d\n", |
---|
| 1889 | + "Unexpected TLV callback for follower %s:%d\n", |
---|
1869 | 1890 | kctl->id.name, kctl->id.index); |
---|
1870 | 1891 | return 0; /* ignore */ |
---|
1871 | 1892 | } |
---|
.. | .. |
---|
1883 | 1904 | return 0; |
---|
1884 | 1905 | if (arg->step && arg->step != step) { |
---|
1885 | 1906 | codec_err(arg->codec, |
---|
1886 | | - "Mismatching dB step for vmaster slave (%d!=%d)\n", |
---|
| 1907 | + "Mismatching dB step for vmaster follower (%d!=%d)\n", |
---|
1887 | 1908 | arg->step, step); |
---|
1888 | 1909 | return 0; |
---|
1889 | 1910 | } |
---|
.. | .. |
---|
1891 | 1912 | arg->step = step; |
---|
1892 | 1913 | val = -tlv[SNDRV_CTL_TLVO_DB_SCALE_MIN] / step; |
---|
1893 | 1914 | if (val > 0) { |
---|
1894 | | - put_kctl_with_value(slave, val); |
---|
| 1915 | + put_kctl_with_value(follower, val); |
---|
1895 | 1916 | return val; |
---|
1896 | 1917 | } |
---|
1897 | 1918 | |
---|
1898 | 1919 | return 0; |
---|
1899 | 1920 | } |
---|
1900 | 1921 | |
---|
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) |
---|
1905 | 1926 | { |
---|
1906 | | - return put_kctl_with_value(slave, 1); |
---|
| 1927 | + return put_kctl_with_value(follower, 1); |
---|
1907 | 1928 | } |
---|
1908 | 1929 | |
---|
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) |
---|
1911 | 1932 | { |
---|
1912 | | - return snd_ctl_add_slave(data, slave); |
---|
| 1933 | + return snd_ctl_add_follower(data, follower); |
---|
1913 | 1934 | } |
---|
1914 | 1935 | |
---|
1915 | 1936 | /** |
---|
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 |
---|
1917 | 1938 | * @codec: HD-audio codec |
---|
1918 | 1939 | * @name: vmaster control name |
---|
1919 | 1940 | * @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 |
---|
1923 | 1944 | * @ctl_ret: store the vmaster kcontrol in return |
---|
1924 | 1945 | * |
---|
1925 | 1946 | * Create a virtual master control with the given name. The TLV data |
---|
1926 | 1947 | * must be either NULL or a valid data. |
---|
1927 | 1948 | * |
---|
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 |
---|
1930 | 1951 | * the new virtual master control. |
---|
1931 | 1952 | * |
---|
1932 | 1953 | * This function returns zero if successful or a negative error code. |
---|
1933 | 1954 | */ |
---|
1934 | 1955 | 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, |
---|
1937 | 1958 | struct snd_kcontrol **ctl_ret) |
---|
1938 | 1959 | { |
---|
1939 | 1960 | struct snd_kcontrol *kctl; |
---|
.. | .. |
---|
1942 | 1963 | if (ctl_ret) |
---|
1943 | 1964 | *ctl_ret = NULL; |
---|
1944 | 1965 | |
---|
1945 | | - err = map_slaves(codec, slaves, suffix, check_slave_present, NULL); |
---|
| 1966 | + err = map_followers(codec, followers, suffix, check_follower_present, NULL); |
---|
1946 | 1967 | 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); |
---|
1948 | 1969 | return 0; |
---|
1949 | 1970 | } |
---|
1950 | 1971 | kctl = snd_ctl_make_virtual_master(name, tlv); |
---|
.. | .. |
---|
1954 | 1975 | if (err < 0) |
---|
1955 | 1976 | return err; |
---|
1956 | 1977 | |
---|
1957 | | - err = map_slaves(codec, slaves, suffix, add_slave, kctl); |
---|
| 1978 | + err = map_followers(codec, followers, suffix, add_follower, kctl); |
---|
1958 | 1979 | if (err < 0) |
---|
1959 | 1980 | return err; |
---|
1960 | 1981 | |
---|
1961 | 1982 | /* init with master mute & zero volume */ |
---|
1962 | 1983 | 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 = { |
---|
1965 | 1986 | .codec = codec, |
---|
1966 | 1987 | .step = 0, |
---|
1967 | 1988 | }; |
---|
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); |
---|
1971 | 1992 | } |
---|
1972 | 1993 | |
---|
1973 | 1994 | if (ctl_ret) |
---|
.. | .. |
---|
2270 | 2291 | return sbits; |
---|
2271 | 2292 | } |
---|
2272 | 2293 | |
---|
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 */ |
---|
2274 | 2295 | static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, |
---|
2275 | 2296 | int mask, int val) |
---|
2276 | 2297 | { |
---|
.. | .. |
---|
2278 | 2299 | |
---|
2279 | 2300 | snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, |
---|
2280 | 2301 | mask, val); |
---|
2281 | | - d = codec->slave_dig_outs; |
---|
| 2302 | + d = codec->follower_dig_outs; |
---|
2282 | 2303 | if (!d) |
---|
2283 | 2304 | return; |
---|
2284 | 2305 | for (; *d; d++) |
---|
.. | .. |
---|
2387 | 2408 | return change; |
---|
2388 | 2409 | } |
---|
2389 | 2410 | |
---|
2390 | | -static struct snd_kcontrol_new dig_mixes[] = { |
---|
| 2411 | +static const struct snd_kcontrol_new dig_mixes[] = { |
---|
2391 | 2412 | { |
---|
2392 | 2413 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
---|
2393 | 2414 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
---|
.. | .. |
---|
2437 | 2458 | { |
---|
2438 | 2459 | int err; |
---|
2439 | 2460 | struct snd_kcontrol *kctl; |
---|
2440 | | - struct snd_kcontrol_new *dig_mix; |
---|
| 2461 | + const struct snd_kcontrol_new *dig_mix; |
---|
2441 | 2462 | int idx = 0; |
---|
2442 | 2463 | int val = 0; |
---|
2443 | 2464 | const int spdif_index = 16; |
---|
.. | .. |
---|
2655 | 2676 | return 0; |
---|
2656 | 2677 | } |
---|
2657 | 2678 | |
---|
2658 | | -static struct snd_kcontrol_new dig_in_ctls[] = { |
---|
| 2679 | +static const struct snd_kcontrol_new dig_in_ctls[] = { |
---|
2659 | 2680 | { |
---|
2660 | 2681 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
---|
2661 | 2682 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH), |
---|
.. | .. |
---|
2687 | 2708 | { |
---|
2688 | 2709 | int err; |
---|
2689 | 2710 | struct snd_kcontrol *kctl; |
---|
2690 | | - struct snd_kcontrol_new *dig_mix; |
---|
| 2711 | + const struct snd_kcontrol_new *dig_mix; |
---|
2691 | 2712 | int idx; |
---|
2692 | 2713 | |
---|
2693 | 2714 | idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); |
---|
.. | .. |
---|
2905 | 2926 | else { |
---|
2906 | 2927 | if (codec->patch_ops.init) |
---|
2907 | 2928 | codec->patch_ops.init(codec); |
---|
2908 | | - if (codec->core.regmap) |
---|
2909 | | - regcache_sync(codec->core.regmap); |
---|
| 2929 | + snd_hda_regmap_sync(codec); |
---|
2910 | 2930 | } |
---|
2911 | 2931 | |
---|
2912 | 2932 | if (codec->jackpoll_interval) |
---|
.. | .. |
---|
2920 | 2940 | static int hda_codec_runtime_suspend(struct device *dev) |
---|
2921 | 2941 | { |
---|
2922 | 2942 | struct hda_codec *codec = dev_to_hda_codec(dev); |
---|
2923 | | - struct hda_pcm *pcm; |
---|
2924 | 2943 | unsigned int state; |
---|
2925 | 2944 | |
---|
| 2945 | + /* Nothing to do if card registration fails and the component driver never probes */ |
---|
| 2946 | + if (!codec->card) |
---|
| 2947 | + return 0; |
---|
| 2948 | + |
---|
2926 | 2949 | 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); |
---|
2929 | 2950 | state = hda_call_codec_suspend(codec); |
---|
2930 | 2951 | if (codec->link_down_at_suspend || |
---|
2931 | 2952 | (codec_has_clkstop(codec) && codec_has_epss(codec) && |
---|
2932 | 2953 | (state & AC_PWRST_CLK_STOP_OK))) |
---|
2933 | 2954 | snd_hdac_codec_link_down(&codec->core); |
---|
2934 | | - snd_hdac_link_power(&codec->core, false); |
---|
| 2955 | + codec_display_power(codec, false); |
---|
2935 | 2956 | return 0; |
---|
2936 | 2957 | } |
---|
2937 | 2958 | |
---|
.. | .. |
---|
2939 | 2960 | { |
---|
2940 | 2961 | struct hda_codec *codec = dev_to_hda_codec(dev); |
---|
2941 | 2962 | |
---|
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); |
---|
2943 | 2968 | snd_hdac_codec_link_up(&codec->core); |
---|
2944 | 2969 | hda_call_codec_resume(codec); |
---|
2945 | 2970 | pm_runtime_mark_last_busy(dev); |
---|
2946 | 2971 | return 0; |
---|
2947 | 2972 | } |
---|
| 2973 | + |
---|
2948 | 2974 | #endif /* CONFIG_PM */ |
---|
2949 | 2975 | |
---|
2950 | 2976 | #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) |
---|
2952 | 2984 | { |
---|
2953 | 2985 | struct hda_codec *codec = dev_to_hda_codec(dev); |
---|
2954 | | - bool forced_resume = !codec->relaxed_resume; |
---|
2955 | | - int ret; |
---|
2956 | 2986 | |
---|
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); |
---|
2967 | 2994 | } |
---|
2968 | 2995 | |
---|
2969 | 2996 | static int hda_codec_pm_suspend(struct device *dev) |
---|
.. | .. |
---|
2975 | 3002 | static int hda_codec_pm_resume(struct device *dev) |
---|
2976 | 3003 | { |
---|
2977 | 3004 | dev->power.power_state = PMSG_RESUME; |
---|
2978 | | - return hda_codec_force_resume(dev); |
---|
| 3005 | + return pm_runtime_force_resume(dev); |
---|
2979 | 3006 | } |
---|
2980 | 3007 | |
---|
2981 | 3008 | static int hda_codec_pm_freeze(struct device *dev) |
---|
.. | .. |
---|
2987 | 3014 | static int hda_codec_pm_thaw(struct device *dev) |
---|
2988 | 3015 | { |
---|
2989 | 3016 | dev->power.power_state = PMSG_THAW; |
---|
2990 | | - return hda_codec_force_resume(dev); |
---|
| 3017 | + return pm_runtime_force_resume(dev); |
---|
2991 | 3018 | } |
---|
2992 | 3019 | |
---|
2993 | 3020 | static int hda_codec_pm_restore(struct device *dev) |
---|
2994 | 3021 | { |
---|
2995 | 3022 | dev->power.power_state = PMSG_RESTORE; |
---|
2996 | | - return hda_codec_force_resume(dev); |
---|
| 3023 | + return pm_runtime_force_resume(dev); |
---|
2997 | 3024 | } |
---|
2998 | 3025 | #endif /* CONFIG_PM_SLEEP */ |
---|
2999 | 3026 | |
---|
3000 | 3027 | /* referred in hda_bind.c */ |
---|
3001 | 3028 | const struct dev_pm_ops hda_codec_driver_pm = { |
---|
3002 | 3029 | #ifdef CONFIG_PM_SLEEP |
---|
| 3030 | + .prepare = hda_codec_pm_prepare, |
---|
| 3031 | + .complete = hda_codec_pm_complete, |
---|
3003 | 3032 | .suspend = hda_codec_pm_suspend, |
---|
3004 | 3033 | .resume = hda_codec_pm_resume, |
---|
3005 | 3034 | .freeze = hda_codec_pm_freeze, |
---|
.. | .. |
---|
3172 | 3201 | EXPORT_SYMBOL_GPL(snd_hda_codec_prepare); |
---|
3173 | 3202 | |
---|
3174 | 3203 | /** |
---|
3175 | | - * snd_hda_codec_cleanup - Prepare a stream |
---|
| 3204 | + * snd_hda_codec_cleanup - Clean up stream resources |
---|
3176 | 3205 | * @codec: the HDA codec |
---|
3177 | 3206 | * @hinfo: PCM information |
---|
3178 | 3207 | * @substream: PCM substream |
---|
.. | .. |
---|
3204 | 3233 | /* assigned to static slots up to dev#10; if more needed, assign |
---|
3205 | 3234 | * the later slot dynamically (when CONFIG_SND_DYNAMIC_MINORS=y) |
---|
3206 | 3235 | */ |
---|
3207 | | - static int audio_idx[HDA_PCM_NTYPES][5] = { |
---|
| 3236 | + static const int audio_idx[HDA_PCM_NTYPES][5] = { |
---|
3208 | 3237 | [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 }, |
---|
3209 | 3238 | [HDA_PCM_TYPE_SPDIF] = { 1, -1 }, |
---|
3210 | 3239 | [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 }, |
---|
.. | .. |
---|
3574 | 3603 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff, |
---|
3575 | 3604 | -1); |
---|
3576 | 3605 | snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); |
---|
3577 | | - if (codec->slave_dig_outs) { |
---|
| 3606 | + if (codec->follower_dig_outs) { |
---|
3578 | 3607 | const hda_nid_t *d; |
---|
3579 | | - for (d = codec->slave_dig_outs; *d; d++) |
---|
| 3608 | + for (d = codec->follower_dig_outs; *d; d++) |
---|
3580 | 3609 | snd_hda_codec_setup_stream(codec, *d, stream_tag, 0, |
---|
3581 | 3610 | format); |
---|
3582 | 3611 | } |
---|
.. | .. |
---|
3589 | 3618 | static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) |
---|
3590 | 3619 | { |
---|
3591 | 3620 | snd_hda_codec_cleanup_stream(codec, nid); |
---|
3592 | | - if (codec->slave_dig_outs) { |
---|
| 3621 | + if (codec->follower_dig_outs) { |
---|
3593 | 3622 | const hda_nid_t *d; |
---|
3594 | | - for (d = codec->slave_dig_outs; *d; d++) |
---|
| 3623 | + for (d = codec->follower_dig_outs; *d; d++) |
---|
3595 | 3624 | snd_hda_codec_cleanup_stream(codec, *d); |
---|
3596 | 3625 | } |
---|
3597 | 3626 | } |
---|
.. | .. |
---|
3673 | 3702 | * @hinfo: PCM information to assign |
---|
3674 | 3703 | * |
---|
3675 | 3704 | * 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 |
---|
3677 | 3706 | * outputs, too. |
---|
3678 | 3707 | */ |
---|
3679 | 3708 | int snd_hda_multi_out_analog_open(struct hda_codec *codec, |
---|
.. | .. |
---|
3872 | 3901 | unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec, |
---|
3873 | 3902 | hda_nid_t pin, unsigned int val) |
---|
3874 | 3903 | { |
---|
3875 | | - static unsigned int cap_lists[][2] = { |
---|
| 3904 | + static const unsigned int cap_lists[][2] = { |
---|
3876 | 3905 | { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 }, |
---|
3877 | 3906 | { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 }, |
---|
3878 | 3907 | { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 }, |
---|
.. | .. |
---|
4017 | 4046 | */ |
---|
4018 | 4047 | void snd_print_pcm_bits(int pcm, char *buf, int buflen) |
---|
4019 | 4048 | { |
---|
4020 | | - static unsigned int bits[] = { 8, 16, 20, 24, 32 }; |
---|
| 4049 | + static const unsigned int bits[] = { 8, 16, 20, 24, 32 }; |
---|
4021 | 4050 | int i, j; |
---|
4022 | 4051 | |
---|
4023 | 4052 | for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++) |
---|