hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/pci/hda/hda_controller.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 *
34 * Implementation of primary alsa driver code base for Intel HD Audio.
....@@ -6,18 +7,6 @@
67 *
78 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
89 * PeiSen Hou <pshou@realtek.com.tw>
9
- *
10
- * This program is free software; you can redistribute it and/or modify it
11
- * under the terms of the GNU General Public License as published by the Free
12
- * Software Foundation; either version 2 of the License, or (at your option)
13
- * any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful, but WITHOUT
16
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18
- * more details.
19
- *
20
- *
2110 */
2211
2312 #include <linux/clocksource.h>
....@@ -36,6 +25,7 @@
3625 #include <sound/core.h>
3726 #include <sound/initval.h>
3827 #include "hda_controller.h"
28
+#include "hda_local.h"
3929
4030 #define CREATE_TRACE_POINTS
4131 #include "hda_controller_trace.h"
....@@ -118,7 +108,7 @@
118108 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
119109 struct azx *chip = apcm->chip;
120110 struct azx_dev *azx_dev = get_azx_dev(substream);
121
- int ret;
111
+ int ret = 0;
122112
123113 trace_azx_pcm_hw_params(chip, azx_dev);
124114 dsp_lock(azx_dev);
....@@ -130,8 +120,7 @@
130120 azx_dev->core.bufsize = 0;
131121 azx_dev->core.period_bytes = 0;
132122 azx_dev->core.format_val = 0;
133
- ret = chip->ops->substream_alloc_pages(chip, substream,
134
- params_buffer_bytes(hw_params));
123
+
135124 unlock:
136125 dsp_unlock(azx_dev);
137126 return ret;
....@@ -141,9 +130,7 @@
141130 {
142131 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
143132 struct azx_dev *azx_dev = get_azx_dev(substream);
144
- struct azx *chip = apcm->chip;
145133 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
146
- int err;
147134
148135 /* reset BDL address */
149136 dsp_lock(azx_dev);
....@@ -152,10 +139,9 @@
152139
153140 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
154141
155
- err = chip->ops->substream_free_pages(chip, substream);
156142 azx_stream(azx_dev)->prepared = 0;
157143 dsp_unlock(azx_dev);
158
- return err;
144
+ return 0;
159145 }
160146
161147 static int azx_pcm_prepare(struct snd_pcm_substream *substream)
....@@ -388,7 +374,7 @@
388374 u32 wallclk_ctr, wallclk_cycles;
389375 bool direction;
390376 u32 dma_select;
391
- u32 timeout = 200;
377
+ u32 timeout;
392378 u32 retry_count = 0;
393379
394380 runtime = substream->runtime;
....@@ -502,7 +488,7 @@
502488 }
503489
504490 static int azx_get_time_info(struct snd_pcm_substream *substream,
505
- struct timespec *system_ts, struct timespec *audio_ts,
491
+ struct timespec64 *system_ts, struct timespec64 *audio_ts,
506492 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
507493 struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
508494 {
....@@ -522,7 +508,7 @@
522508 if (audio_tstamp_config->report_delay)
523509 nsec = azx_adjust_codec_delay(substream, nsec);
524510
525
- *audio_ts = ns_to_timespec(nsec);
511
+ *audio_ts = ns_to_timespec64(nsec);
526512
527513 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
528514 audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
....@@ -539,16 +525,16 @@
539525 return -EINVAL;
540526
541527 case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
542
- *system_ts = ktime_to_timespec(xtstamp.sys_monoraw);
528
+ *system_ts = ktime_to_timespec64(xtstamp.sys_monoraw);
543529 break;
544530
545531 default:
546
- *system_ts = ktime_to_timespec(xtstamp.sys_realtime);
532
+ *system_ts = ktime_to_timespec64(xtstamp.sys_realtime);
547533 break;
548534
549535 }
550536
551
- *audio_ts = ktime_to_timespec(xtstamp.device);
537
+ *audio_ts = ktime_to_timespec64(xtstamp.device);
552538
553539 audio_tstamp_report->actual_type =
554540 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED;
....@@ -563,7 +549,7 @@
563549 return 0;
564550 }
565551
566
-static struct snd_pcm_hardware azx_pcm_hw = {
552
+static const struct snd_pcm_hardware azx_pcm_hw = {
567553 .info = (SNDRV_PCM_INFO_MMAP |
568554 SNDRV_PCM_INFO_INTERLEAVED |
569555 SNDRV_PCM_INFO_BLOCK_TRANSFER |
....@@ -697,7 +683,6 @@
697683 static const struct snd_pcm_ops azx_pcm_ops = {
698684 .open = azx_pcm_open,
699685 .close = azx_pcm_close,
700
- .ioctl = snd_pcm_lib_ioctl,
701686 .hw_params = azx_pcm_hw_params,
702687 .hw_free = azx_pcm_hw_free,
703688 .prepare = azx_pcm_prepare,
....@@ -705,7 +690,6 @@
705690 .pointer = azx_pcm_pointer,
706691 .get_time_info = azx_get_time_info,
707692 .mmap = azx_pcm_mmap,
708
- .page = snd_pcm_sgbuf_ops_page,
709693 };
710694
711695 static void azx_pcm_free(struct snd_pcm *pcm)
....@@ -730,6 +714,7 @@
730714 int pcm_dev = cpcm->device;
731715 unsigned int size;
732716 int s, err;
717
+ int type = SNDRV_DMA_TYPE_DEV_SG;
733718
734719 list_for_each_entry(apcm, &chip->pcm_list, list) {
735720 if (apcm->pcm->device == pcm_dev) {
....@@ -768,9 +753,10 @@
768753 size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
769754 if (size > MAX_PREALLOC_SIZE)
770755 size = MAX_PREALLOC_SIZE;
771
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
772
- chip->card->dev,
773
- size, MAX_PREALLOC_SIZE);
756
+ if (chip->uc_buffer)
757
+ type = SNDRV_DMA_TYPE_DEV_UC_SG;
758
+ snd_pcm_set_managed_buffer_all(pcm, type, chip->card->dev,
759
+ size, MAX_PREALLOC_SIZE);
774760 return 0;
775761 }
776762
....@@ -792,54 +778,21 @@
792778 {
793779 struct azx *chip = bus_to_azx(bus);
794780 struct hda_bus *hbus = &chip->bus;
795
- unsigned long timeout;
796
- unsigned long loopcounter;
797
- int do_poll = 0;
781
+ int err;
798782
799783 again:
800
- timeout = jiffies + msecs_to_jiffies(1000);
801
-
802
- for (loopcounter = 0;; loopcounter++) {
803
- spin_lock_irq(&bus->reg_lock);
804
- if (chip->polling_mode || do_poll)
805
- snd_hdac_bus_update_rirb(bus);
806
- if (!bus->rirb.cmds[addr]) {
807
- if (!do_poll)
808
- chip->poll_count = 0;
809
- if (res)
810
- *res = bus->rirb.res[addr]; /* the last value */
811
- spin_unlock_irq(&bus->reg_lock);
812
- return 0;
813
- }
814
- spin_unlock_irq(&bus->reg_lock);
815
- if (time_after(jiffies, timeout))
816
- break;
817
- if (hbus->needs_damn_long_delay || loopcounter > 3000)
818
- msleep(2); /* temporary workaround */
819
- else {
820
- udelay(10);
821
- cond_resched();
822
- }
823
- }
784
+ err = snd_hdac_bus_get_response(bus, addr, res);
785
+ if (!err)
786
+ return 0;
824787
825788 if (hbus->no_response_fallback)
826789 return -EIO;
827790
828
- if (!chip->polling_mode && chip->poll_count < 2) {
829
- dev_dbg(chip->card->dev,
830
- "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n",
831
- bus->last_cmd[addr]);
832
- do_poll = 1;
833
- chip->poll_count++;
834
- goto again;
835
- }
836
-
837
-
838
- if (!chip->polling_mode) {
791
+ if (!bus->polling_mode) {
839792 dev_warn(chip->card->dev,
840793 "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n",
841794 bus->last_cmd[addr]);
842
- chip->polling_mode = 1;
795
+ bus->polling_mode = 1;
843796 goto again;
844797 }
845798
....@@ -987,20 +940,9 @@
987940 return azx_rirb_get_response(bus, addr, res);
988941 }
989942
990
-static int azx_link_power(struct hdac_bus *bus, bool enable)
991
-{
992
- struct azx *chip = bus_to_azx(bus);
993
-
994
- if (chip->ops->link_power)
995
- return chip->ops->link_power(chip, enable);
996
- else
997
- return -EINVAL;
998
-}
999
-
1000943 static const struct hdac_bus_ops bus_core_ops = {
1001944 .command = azx_send_cmd,
1002945 .get_response = azx_get_response,
1003
- .link_power = azx_link_power,
1004946 };
1005947
1006948 #ifdef CONFIG_SND_HDA_DSP_LOADER
....@@ -1103,10 +1045,8 @@
11031045 void azx_stop_all_streams(struct azx *chip)
11041046 {
11051047 struct hdac_bus *bus = azx_bus(chip);
1106
- struct hdac_stream *s;
11071048
1108
- list_for_each_entry(s, &bus->stream_list, list)
1109
- snd_hdac_stream_stop(s);
1049
+ snd_hdac_stop_streams(bus);
11101050 }
11111051 EXPORT_SYMBOL_GPL(azx_stop_all_streams);
11121052
....@@ -1228,36 +1168,13 @@
12281168 bus->in_reset = 0;
12291169 }
12301170
1231
-static int get_jackpoll_interval(struct azx *chip)
1232
-{
1233
- int i;
1234
- unsigned int j;
1235
-
1236
- if (!chip->jackpoll_ms)
1237
- return 0;
1238
-
1239
- i = chip->jackpoll_ms[chip->dev_index];
1240
- if (i == 0)
1241
- return 0;
1242
- if (i < 50 || i > 60000)
1243
- j = 0;
1244
- else
1245
- j = msecs_to_jiffies(i);
1246
- if (j == 0)
1247
- dev_warn(chip->card->dev,
1248
- "jackpoll_ms value out of range: %d\n", i);
1249
- return j;
1250
-}
1251
-
12521171 /* HD-audio bus initialization */
1253
-int azx_bus_init(struct azx *chip, const char *model,
1254
- const struct hdac_io_ops *io_ops)
1172
+int azx_bus_init(struct azx *chip, const char *model)
12551173 {
12561174 struct hda_bus *bus = &chip->bus;
12571175 int err;
12581176
1259
- err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops,
1260
- io_ops);
1177
+ err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops);
12611178 if (err < 0)
12621179 return err;
12631180
....@@ -1277,15 +1194,8 @@
12771194 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY)
12781195 bus->core.align_bdle_4k = true;
12791196
1280
- /* AMD chipsets often cause the communication stalls upon certain
1281
- * sequence like the pin-detection. It seems that forcing the synced
1282
- * access works around the stall. Grrr...
1283
- */
1284
- if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1285
- dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1286
- bus->core.sync_write = 1;
1287
- bus->allow_bus_reset = 1;
1288
- }
1197
+ /* enable sync_write flag for stable communication as default */
1198
+ bus->core.sync_write = 1;
12891199
12901200 return 0;
12911201 }
....@@ -1331,7 +1241,7 @@
13311241 err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec);
13321242 if (err < 0)
13331243 continue;
1334
- codec->jackpoll_interval = get_jackpoll_interval(chip);
1244
+ codec->jackpoll_interval = chip->jackpoll_interval;
13351245 codec->beep_mode = chip->beep_mode;
13361246 codecs++;
13371247 }
....@@ -1348,17 +1258,24 @@
13481258 int azx_codec_configure(struct azx *chip)
13491259 {
13501260 struct hda_codec *codec, *next;
1261
+ int success = 0;
13511262
1352
- /* use _safe version here since snd_hda_codec_configure() deregisters
1353
- * the device upon error and deletes itself from the bus list.
1354
- */
1355
- list_for_each_codec_safe(codec, next, &chip->bus) {
1356
- snd_hda_codec_configure(codec);
1263
+ list_for_each_codec(codec, &chip->bus) {
1264
+ if (!snd_hda_codec_configure(codec))
1265
+ success++;
13571266 }
13581267
1359
- if (!azx_bus(chip)->num_codecs)
1360
- return -ENODEV;
1361
- return 0;
1268
+ if (success) {
1269
+ /* unregister failed codecs if any codec has been probed */
1270
+ list_for_each_codec_safe(codec, next, &chip->bus) {
1271
+ if (!codec->configured) {
1272
+ codec_err(codec, "Unable to configure, disabling\n");
1273
+ snd_hdac_device_unregister(&codec->core);
1274
+ }
1275
+ }
1276
+ }
1277
+
1278
+ return success ? 0 : -ENODEV;
13621279 }
13631280 EXPORT_SYMBOL_GPL(azx_codec_configure);
13641281