.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * |
---|
3 | 4 | * Implementation of primary alsa driver code base for Intel HD Audio. |
---|
.. | .. |
---|
6 | 7 | * |
---|
7 | 8 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
---|
8 | 9 | * 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 | | - * |
---|
21 | 10 | */ |
---|
22 | 11 | |
---|
23 | 12 | #include <linux/clocksource.h> |
---|
.. | .. |
---|
36 | 25 | #include <sound/core.h> |
---|
37 | 26 | #include <sound/initval.h> |
---|
38 | 27 | #include "hda_controller.h" |
---|
| 28 | +#include "hda_local.h" |
---|
39 | 29 | |
---|
40 | 30 | #define CREATE_TRACE_POINTS |
---|
41 | 31 | #include "hda_controller_trace.h" |
---|
.. | .. |
---|
118 | 108 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
---|
119 | 109 | struct azx *chip = apcm->chip; |
---|
120 | 110 | struct azx_dev *azx_dev = get_azx_dev(substream); |
---|
121 | | - int ret; |
---|
| 111 | + int ret = 0; |
---|
122 | 112 | |
---|
123 | 113 | trace_azx_pcm_hw_params(chip, azx_dev); |
---|
124 | 114 | dsp_lock(azx_dev); |
---|
.. | .. |
---|
130 | 120 | azx_dev->core.bufsize = 0; |
---|
131 | 121 | azx_dev->core.period_bytes = 0; |
---|
132 | 122 | azx_dev->core.format_val = 0; |
---|
133 | | - ret = chip->ops->substream_alloc_pages(chip, substream, |
---|
134 | | - params_buffer_bytes(hw_params)); |
---|
| 123 | + |
---|
135 | 124 | unlock: |
---|
136 | 125 | dsp_unlock(azx_dev); |
---|
137 | 126 | return ret; |
---|
.. | .. |
---|
141 | 130 | { |
---|
142 | 131 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
---|
143 | 132 | struct azx_dev *azx_dev = get_azx_dev(substream); |
---|
144 | | - struct azx *chip = apcm->chip; |
---|
145 | 133 | struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); |
---|
146 | | - int err; |
---|
147 | 134 | |
---|
148 | 135 | /* reset BDL address */ |
---|
149 | 136 | dsp_lock(azx_dev); |
---|
.. | .. |
---|
152 | 139 | |
---|
153 | 140 | snd_hda_codec_cleanup(apcm->codec, hinfo, substream); |
---|
154 | 141 | |
---|
155 | | - err = chip->ops->substream_free_pages(chip, substream); |
---|
156 | 142 | azx_stream(azx_dev)->prepared = 0; |
---|
157 | 143 | dsp_unlock(azx_dev); |
---|
158 | | - return err; |
---|
| 144 | + return 0; |
---|
159 | 145 | } |
---|
160 | 146 | |
---|
161 | 147 | static int azx_pcm_prepare(struct snd_pcm_substream *substream) |
---|
.. | .. |
---|
388 | 374 | u32 wallclk_ctr, wallclk_cycles; |
---|
389 | 375 | bool direction; |
---|
390 | 376 | u32 dma_select; |
---|
391 | | - u32 timeout = 200; |
---|
| 377 | + u32 timeout; |
---|
392 | 378 | u32 retry_count = 0; |
---|
393 | 379 | |
---|
394 | 380 | runtime = substream->runtime; |
---|
.. | .. |
---|
502 | 488 | } |
---|
503 | 489 | |
---|
504 | 490 | 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, |
---|
506 | 492 | struct snd_pcm_audio_tstamp_config *audio_tstamp_config, |
---|
507 | 493 | struct snd_pcm_audio_tstamp_report *audio_tstamp_report) |
---|
508 | 494 | { |
---|
.. | .. |
---|
522 | 508 | if (audio_tstamp_config->report_delay) |
---|
523 | 509 | nsec = azx_adjust_codec_delay(substream, nsec); |
---|
524 | 510 | |
---|
525 | | - *audio_ts = ns_to_timespec(nsec); |
---|
| 511 | + *audio_ts = ns_to_timespec64(nsec); |
---|
526 | 512 | |
---|
527 | 513 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; |
---|
528 | 514 | audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ |
---|
.. | .. |
---|
539 | 525 | return -EINVAL; |
---|
540 | 526 | |
---|
541 | 527 | 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); |
---|
543 | 529 | break; |
---|
544 | 530 | |
---|
545 | 531 | default: |
---|
546 | | - *system_ts = ktime_to_timespec(xtstamp.sys_realtime); |
---|
| 532 | + *system_ts = ktime_to_timespec64(xtstamp.sys_realtime); |
---|
547 | 533 | break; |
---|
548 | 534 | |
---|
549 | 535 | } |
---|
550 | 536 | |
---|
551 | | - *audio_ts = ktime_to_timespec(xtstamp.device); |
---|
| 537 | + *audio_ts = ktime_to_timespec64(xtstamp.device); |
---|
552 | 538 | |
---|
553 | 539 | audio_tstamp_report->actual_type = |
---|
554 | 540 | SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED; |
---|
.. | .. |
---|
563 | 549 | return 0; |
---|
564 | 550 | } |
---|
565 | 551 | |
---|
566 | | -static struct snd_pcm_hardware azx_pcm_hw = { |
---|
| 552 | +static const struct snd_pcm_hardware azx_pcm_hw = { |
---|
567 | 553 | .info = (SNDRV_PCM_INFO_MMAP | |
---|
568 | 554 | SNDRV_PCM_INFO_INTERLEAVED | |
---|
569 | 555 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
---|
.. | .. |
---|
697 | 683 | static const struct snd_pcm_ops azx_pcm_ops = { |
---|
698 | 684 | .open = azx_pcm_open, |
---|
699 | 685 | .close = azx_pcm_close, |
---|
700 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
701 | 686 | .hw_params = azx_pcm_hw_params, |
---|
702 | 687 | .hw_free = azx_pcm_hw_free, |
---|
703 | 688 | .prepare = azx_pcm_prepare, |
---|
.. | .. |
---|
705 | 690 | .pointer = azx_pcm_pointer, |
---|
706 | 691 | .get_time_info = azx_get_time_info, |
---|
707 | 692 | .mmap = azx_pcm_mmap, |
---|
708 | | - .page = snd_pcm_sgbuf_ops_page, |
---|
709 | 693 | }; |
---|
710 | 694 | |
---|
711 | 695 | static void azx_pcm_free(struct snd_pcm *pcm) |
---|
.. | .. |
---|
730 | 714 | int pcm_dev = cpcm->device; |
---|
731 | 715 | unsigned int size; |
---|
732 | 716 | int s, err; |
---|
| 717 | + int type = SNDRV_DMA_TYPE_DEV_SG; |
---|
733 | 718 | |
---|
734 | 719 | list_for_each_entry(apcm, &chip->pcm_list, list) { |
---|
735 | 720 | if (apcm->pcm->device == pcm_dev) { |
---|
.. | .. |
---|
768 | 753 | size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024; |
---|
769 | 754 | if (size > MAX_PREALLOC_SIZE) |
---|
770 | 755 | 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); |
---|
774 | 760 | return 0; |
---|
775 | 761 | } |
---|
776 | 762 | |
---|
.. | .. |
---|
792 | 778 | { |
---|
793 | 779 | struct azx *chip = bus_to_azx(bus); |
---|
794 | 780 | struct hda_bus *hbus = &chip->bus; |
---|
795 | | - unsigned long timeout; |
---|
796 | | - unsigned long loopcounter; |
---|
797 | | - int do_poll = 0; |
---|
| 781 | + int err; |
---|
798 | 782 | |
---|
799 | 783 | 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; |
---|
824 | 787 | |
---|
825 | 788 | if (hbus->no_response_fallback) |
---|
826 | 789 | return -EIO; |
---|
827 | 790 | |
---|
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) { |
---|
839 | 792 | dev_warn(chip->card->dev, |
---|
840 | 793 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", |
---|
841 | 794 | bus->last_cmd[addr]); |
---|
842 | | - chip->polling_mode = 1; |
---|
| 795 | + bus->polling_mode = 1; |
---|
843 | 796 | goto again; |
---|
844 | 797 | } |
---|
845 | 798 | |
---|
.. | .. |
---|
987 | 940 | return azx_rirb_get_response(bus, addr, res); |
---|
988 | 941 | } |
---|
989 | 942 | |
---|
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 | | - |
---|
1000 | 943 | static const struct hdac_bus_ops bus_core_ops = { |
---|
1001 | 944 | .command = azx_send_cmd, |
---|
1002 | 945 | .get_response = azx_get_response, |
---|
1003 | | - .link_power = azx_link_power, |
---|
1004 | 946 | }; |
---|
1005 | 947 | |
---|
1006 | 948 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
---|
.. | .. |
---|
1103 | 1045 | void azx_stop_all_streams(struct azx *chip) |
---|
1104 | 1046 | { |
---|
1105 | 1047 | struct hdac_bus *bus = azx_bus(chip); |
---|
1106 | | - struct hdac_stream *s; |
---|
1107 | 1048 | |
---|
1108 | | - list_for_each_entry(s, &bus->stream_list, list) |
---|
1109 | | - snd_hdac_stream_stop(s); |
---|
| 1049 | + snd_hdac_stop_streams(bus); |
---|
1110 | 1050 | } |
---|
1111 | 1051 | EXPORT_SYMBOL_GPL(azx_stop_all_streams); |
---|
1112 | 1052 | |
---|
.. | .. |
---|
1228 | 1168 | bus->in_reset = 0; |
---|
1229 | 1169 | } |
---|
1230 | 1170 | |
---|
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 | | - |
---|
1252 | 1171 | /* 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) |
---|
1255 | 1173 | { |
---|
1256 | 1174 | struct hda_bus *bus = &chip->bus; |
---|
1257 | 1175 | int err; |
---|
1258 | 1176 | |
---|
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); |
---|
1261 | 1178 | if (err < 0) |
---|
1262 | 1179 | return err; |
---|
1263 | 1180 | |
---|
.. | .. |
---|
1277 | 1194 | if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) |
---|
1278 | 1195 | bus->core.align_bdle_4k = true; |
---|
1279 | 1196 | |
---|
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; |
---|
1289 | 1199 | |
---|
1290 | 1200 | return 0; |
---|
1291 | 1201 | } |
---|
.. | .. |
---|
1331 | 1241 | err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); |
---|
1332 | 1242 | if (err < 0) |
---|
1333 | 1243 | continue; |
---|
1334 | | - codec->jackpoll_interval = get_jackpoll_interval(chip); |
---|
| 1244 | + codec->jackpoll_interval = chip->jackpoll_interval; |
---|
1335 | 1245 | codec->beep_mode = chip->beep_mode; |
---|
1336 | 1246 | codecs++; |
---|
1337 | 1247 | } |
---|
.. | .. |
---|
1348 | 1258 | int azx_codec_configure(struct azx *chip) |
---|
1349 | 1259 | { |
---|
1350 | 1260 | struct hda_codec *codec, *next; |
---|
| 1261 | + int success = 0; |
---|
1351 | 1262 | |
---|
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++; |
---|
1357 | 1266 | } |
---|
1358 | 1267 | |
---|
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; |
---|
1362 | 1279 | } |
---|
1363 | 1280 | EXPORT_SYMBOL_GPL(azx_codec_configure); |
---|
1364 | 1281 | |
---|