| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
|---|
| 3 | 4 | * Routines for control of YMF724/740/744/754 chips |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 7 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | | - * (at your option) any later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, write to the Free Software |
|---|
| 17 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | | - * |
|---|
| 19 | 5 | */ |
|---|
| 20 | 6 | |
|---|
| 21 | 7 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 136 | 122 | } |
|---|
| 137 | 123 | } |
|---|
| 138 | 124 | |
|---|
| 139 | | -static u32 def_rate[8] = { |
|---|
| 125 | +static const u32 def_rate[8] = { |
|---|
| 140 | 126 | 100, 2000, 8000, 11025, 16000, 22050, 32000, 48000 |
|---|
| 141 | 127 | }; |
|---|
| 142 | 128 | |
|---|
| 143 | 129 | static u32 snd_ymfpci_calc_lpfK(u32 rate) |
|---|
| 144 | 130 | { |
|---|
| 145 | 131 | u32 i; |
|---|
| 146 | | - static u32 val[8] = { |
|---|
| 132 | + static const u32 val[8] = { |
|---|
| 147 | 133 | 0x00570000, 0x06AA0000, 0x18B20000, 0x20930000, |
|---|
| 148 | 134 | 0x2B9A0000, 0x35A10000, 0x3EAA0000, 0x40000000 |
|---|
| 149 | 135 | }; |
|---|
| .. | .. |
|---|
| 159 | 145 | static u32 snd_ymfpci_calc_lpfQ(u32 rate) |
|---|
| 160 | 146 | { |
|---|
| 161 | 147 | u32 i; |
|---|
| 162 | | - static u32 val[8] = { |
|---|
| 148 | + static const u32 val[8] = { |
|---|
| 163 | 149 | 0x35280000, 0x34A70000, 0x32020000, 0x31770000, |
|---|
| 164 | 150 | 0x31390000, 0x31C90000, 0x33D00000, 0x40000000 |
|---|
| 165 | 151 | }; |
|---|
| .. | .. |
|---|
| 414 | 400 | kctl = chip->pcm_mixer[substream->number].ctl; |
|---|
| 415 | 401 | kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
|---|
| 416 | 402 | } |
|---|
| 417 | | - /* fall through */ |
|---|
| 403 | + fallthrough; |
|---|
| 418 | 404 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
|---|
| 419 | 405 | case SNDRV_PCM_TRIGGER_SUSPEND: |
|---|
| 420 | 406 | chip->ctrl_playback[ypcm->voices[0]->number + 1] = 0; |
|---|
| .. | .. |
|---|
| 601 | 587 | |
|---|
| 602 | 588 | static int snd_ymfpci_ac3_init(struct snd_ymfpci *chip) |
|---|
| 603 | 589 | { |
|---|
| 604 | | - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), |
|---|
| 590 | + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, |
|---|
| 605 | 591 | 4096, &chip->ac3_tmp_base) < 0) |
|---|
| 606 | 592 | return -ENOMEM; |
|---|
| 607 | 593 | |
|---|
| .. | .. |
|---|
| 642 | 628 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
|---|
| 643 | 629 | int err; |
|---|
| 644 | 630 | |
|---|
| 645 | | - if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
|---|
| 646 | | - return err; |
|---|
| 647 | 631 | if ((err = snd_ymfpci_pcm_voice_alloc(ypcm, params_channels(hw_params))) < 0) |
|---|
| 648 | 632 | return err; |
|---|
| 649 | 633 | return 0; |
|---|
| .. | .. |
|---|
| 661 | 645 | |
|---|
| 662 | 646 | /* wait, until the PCI operations are not finished */ |
|---|
| 663 | 647 | snd_ymfpci_irq_wait(chip); |
|---|
| 664 | | - snd_pcm_lib_free_pages(substream); |
|---|
| 665 | 648 | if (ypcm->voices[1]) { |
|---|
| 666 | 649 | snd_ymfpci_voice_free(chip, ypcm->voices[1]); |
|---|
| 667 | 650 | ypcm->voices[1] = NULL; |
|---|
| .. | .. |
|---|
| 697 | 680 | return 0; |
|---|
| 698 | 681 | } |
|---|
| 699 | 682 | |
|---|
| 700 | | -static int snd_ymfpci_capture_hw_params(struct snd_pcm_substream *substream, |
|---|
| 701 | | - struct snd_pcm_hw_params *hw_params) |
|---|
| 702 | | -{ |
|---|
| 703 | | - return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
|---|
| 704 | | -} |
|---|
| 705 | | - |
|---|
| 706 | 683 | static int snd_ymfpci_capture_hw_free(struct snd_pcm_substream *substream) |
|---|
| 707 | 684 | { |
|---|
| 708 | 685 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
|---|
| 709 | 686 | |
|---|
| 710 | 687 | /* wait, until the PCI operations are not finished */ |
|---|
| 711 | 688 | snd_ymfpci_irq_wait(chip); |
|---|
| 712 | | - return snd_pcm_lib_free_pages(substream); |
|---|
| 689 | + return 0; |
|---|
| 713 | 690 | } |
|---|
| 714 | 691 | |
|---|
| 715 | 692 | static int snd_ymfpci_capture_prepare(struct snd_pcm_substream *substream) |
|---|
| .. | .. |
|---|
| 1126 | 1103 | static const struct snd_pcm_ops snd_ymfpci_playback_ops = { |
|---|
| 1127 | 1104 | .open = snd_ymfpci_playback_open, |
|---|
| 1128 | 1105 | .close = snd_ymfpci_playback_close, |
|---|
| 1129 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1130 | 1106 | .hw_params = snd_ymfpci_playback_hw_params, |
|---|
| 1131 | 1107 | .hw_free = snd_ymfpci_playback_hw_free, |
|---|
| 1132 | 1108 | .prepare = snd_ymfpci_playback_prepare, |
|---|
| .. | .. |
|---|
| 1137 | 1113 | static const struct snd_pcm_ops snd_ymfpci_capture_rec_ops = { |
|---|
| 1138 | 1114 | .open = snd_ymfpci_capture_rec_open, |
|---|
| 1139 | 1115 | .close = snd_ymfpci_capture_close, |
|---|
| 1140 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1141 | | - .hw_params = snd_ymfpci_capture_hw_params, |
|---|
| 1142 | 1116 | .hw_free = snd_ymfpci_capture_hw_free, |
|---|
| 1143 | 1117 | .prepare = snd_ymfpci_capture_prepare, |
|---|
| 1144 | 1118 | .trigger = snd_ymfpci_capture_trigger, |
|---|
| .. | .. |
|---|
| 1162 | 1136 | strcpy(pcm->name, "YMFPCI"); |
|---|
| 1163 | 1137 | chip->pcm = pcm; |
|---|
| 1164 | 1138 | |
|---|
| 1165 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1166 | | - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
|---|
| 1139 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1140 | + &chip->pci->dev, 64*1024, 256*1024); |
|---|
| 1167 | 1141 | |
|---|
| 1168 | 1142 | return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
|---|
| 1169 | 1143 | snd_pcm_std_chmaps, 2, 0, NULL); |
|---|
| .. | .. |
|---|
| 1172 | 1146 | static const struct snd_pcm_ops snd_ymfpci_capture_ac97_ops = { |
|---|
| 1173 | 1147 | .open = snd_ymfpci_capture_ac97_open, |
|---|
| 1174 | 1148 | .close = snd_ymfpci_capture_close, |
|---|
| 1175 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1176 | | - .hw_params = snd_ymfpci_capture_hw_params, |
|---|
| 1177 | 1149 | .hw_free = snd_ymfpci_capture_hw_free, |
|---|
| 1178 | 1150 | .prepare = snd_ymfpci_capture_prepare, |
|---|
| 1179 | 1151 | .trigger = snd_ymfpci_capture_trigger, |
|---|
| .. | .. |
|---|
| 1197 | 1169 | chip->device_id == PCI_DEVICE_ID_YAMAHA_754 ? "Direct Recording" : "AC'97"); |
|---|
| 1198 | 1170 | chip->pcm2 = pcm; |
|---|
| 1199 | 1171 | |
|---|
| 1200 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1201 | | - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
|---|
| 1172 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1173 | + &chip->pci->dev, 64*1024, 256*1024); |
|---|
| 1202 | 1174 | |
|---|
| 1203 | 1175 | return 0; |
|---|
| 1204 | 1176 | } |
|---|
| .. | .. |
|---|
| 1206 | 1178 | static const struct snd_pcm_ops snd_ymfpci_playback_spdif_ops = { |
|---|
| 1207 | 1179 | .open = snd_ymfpci_playback_spdif_open, |
|---|
| 1208 | 1180 | .close = snd_ymfpci_playback_spdif_close, |
|---|
| 1209 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1210 | 1181 | .hw_params = snd_ymfpci_playback_hw_params, |
|---|
| 1211 | 1182 | .hw_free = snd_ymfpci_playback_hw_free, |
|---|
| 1212 | 1183 | .prepare = snd_ymfpci_playback_prepare, |
|---|
| .. | .. |
|---|
| 1230 | 1201 | strcpy(pcm->name, "YMFPCI - IEC958"); |
|---|
| 1231 | 1202 | chip->pcm_spdif = pcm; |
|---|
| 1232 | 1203 | |
|---|
| 1233 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1234 | | - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
|---|
| 1204 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1205 | + &chip->pci->dev, 64*1024, 256*1024); |
|---|
| 1235 | 1206 | |
|---|
| 1236 | 1207 | return 0; |
|---|
| 1237 | 1208 | } |
|---|
| .. | .. |
|---|
| 1239 | 1210 | static const struct snd_pcm_ops snd_ymfpci_playback_4ch_ops = { |
|---|
| 1240 | 1211 | .open = snd_ymfpci_playback_4ch_open, |
|---|
| 1241 | 1212 | .close = snd_ymfpci_playback_4ch_close, |
|---|
| 1242 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1243 | 1213 | .hw_params = snd_ymfpci_playback_hw_params, |
|---|
| 1244 | 1214 | .hw_free = snd_ymfpci_playback_hw_free, |
|---|
| 1245 | 1215 | .prepare = snd_ymfpci_playback_prepare, |
|---|
| .. | .. |
|---|
| 1271 | 1241 | strcpy(pcm->name, "YMFPCI - Rear PCM"); |
|---|
| 1272 | 1242 | chip->pcm_4ch = pcm; |
|---|
| 1273 | 1243 | |
|---|
| 1274 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1275 | | - snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
|---|
| 1244 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1245 | + &chip->pci->dev, 64*1024, 256*1024); |
|---|
| 1276 | 1246 | |
|---|
| 1277 | 1247 | return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
|---|
| 1278 | 1248 | surround_map, 2, 0, NULL); |
|---|
| .. | .. |
|---|
| 1618 | 1588 | .put = snd_ymfpci_put_dup4ch, |
|---|
| 1619 | 1589 | }; |
|---|
| 1620 | 1590 | |
|---|
| 1621 | | -static struct snd_kcontrol_new snd_ymfpci_controls[] = { |
|---|
| 1591 | +static const struct snd_kcontrol_new snd_ymfpci_controls[] = { |
|---|
| 1622 | 1592 | { |
|---|
| 1623 | 1593 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
|---|
| 1624 | 1594 | .name = "Wave Playback Volume", |
|---|
| .. | .. |
|---|
| 1810 | 1780 | struct snd_pcm_substream *substream; |
|---|
| 1811 | 1781 | unsigned int idx; |
|---|
| 1812 | 1782 | int err; |
|---|
| 1813 | | - static struct snd_ac97_bus_ops ops = { |
|---|
| 1783 | + static const struct snd_ac97_bus_ops ops = { |
|---|
| 1814 | 1784 | .write = snd_ymfpci_codec_write, |
|---|
| 1815 | 1785 | .read = snd_ymfpci_codec_read, |
|---|
| 1816 | 1786 | }; |
|---|
| .. | .. |
|---|
| 1938 | 1908 | return 0; |
|---|
| 1939 | 1909 | } |
|---|
| 1940 | 1910 | |
|---|
| 1941 | | -static struct snd_timer_hardware snd_ymfpci_timer_hw = { |
|---|
| 1911 | +static const struct snd_timer_hardware snd_ymfpci_timer_hw = { |
|---|
| 1942 | 1912 | .flags = SNDRV_TIMER_HW_AUTO, |
|---|
| 1943 | 1913 | .resolution = 10417, /* 1 / 96 kHz = 10.41666...us */ |
|---|
| 1944 | 1914 | .ticks = 0x10000, |
|---|
| .. | .. |
|---|
| 1985 | 1955 | |
|---|
| 1986 | 1956 | static int snd_ymfpci_proc_init(struct snd_card *card, struct snd_ymfpci *chip) |
|---|
| 1987 | 1957 | { |
|---|
| 1988 | | - struct snd_info_entry *entry; |
|---|
| 1989 | | - |
|---|
| 1990 | | - if (! snd_card_proc_new(card, "ymfpci", &entry)) |
|---|
| 1991 | | - snd_info_set_text_ops(entry, chip, snd_ymfpci_proc_read); |
|---|
| 1992 | | - return 0; |
|---|
| 1958 | + return snd_card_ro_proc_new(card, "ymfpci", chip, snd_ymfpci_proc_read); |
|---|
| 1993 | 1959 | } |
|---|
| 1994 | 1960 | |
|---|
| 1995 | 1961 | /* |
|---|
| .. | .. |
|---|
| 2126 | 2092 | chip->work_size; |
|---|
| 2127 | 2093 | /* work_ptr must be aligned to 256 bytes, but it's already |
|---|
| 2128 | 2094 | covered with the kernel page allocation mechanism */ |
|---|
| 2129 | | - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), |
|---|
| 2095 | + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, |
|---|
| 2130 | 2096 | size, &chip->work_ptr) < 0) |
|---|
| 2131 | 2097 | return -ENOMEM; |
|---|
| 2132 | 2098 | ptr = chip->work_ptr.area; |
|---|
| .. | .. |
|---|
| 2268 | 2234 | } |
|---|
| 2269 | 2235 | |
|---|
| 2270 | 2236 | #ifdef CONFIG_PM_SLEEP |
|---|
| 2271 | | -static int saved_regs_index[] = { |
|---|
| 2237 | +static const int saved_regs_index[] = { |
|---|
| 2272 | 2238 | /* spdif */ |
|---|
| 2273 | 2239 | YDSXGR_SPDIFOUTCTRL, |
|---|
| 2274 | 2240 | YDSXGR_SPDIFOUTSTATUS, |
|---|
| .. | .. |
|---|
| 2304 | 2270 | unsigned int i; |
|---|
| 2305 | 2271 | |
|---|
| 2306 | 2272 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
|---|
| 2307 | | - snd_pcm_suspend_all(chip->pcm); |
|---|
| 2308 | | - snd_pcm_suspend_all(chip->pcm2); |
|---|
| 2309 | | - snd_pcm_suspend_all(chip->pcm_spdif); |
|---|
| 2310 | | - snd_pcm_suspend_all(chip->pcm_4ch); |
|---|
| 2311 | 2273 | snd_ac97_suspend(chip->ac97); |
|---|
| 2312 | 2274 | for (i = 0; i < YDSXGR_NUM_SAVED_REGS; i++) |
|---|
| 2313 | 2275 | chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]); |
|---|
| .. | .. |
|---|
| 2365 | 2327 | { |
|---|
| 2366 | 2328 | struct snd_ymfpci *chip; |
|---|
| 2367 | 2329 | int err; |
|---|
| 2368 | | - static struct snd_device_ops ops = { |
|---|
| 2330 | + static const struct snd_device_ops ops = { |
|---|
| 2369 | 2331 | .dev_free = snd_ymfpci_dev_free, |
|---|
| 2370 | 2332 | }; |
|---|
| 2371 | 2333 | |
|---|
| .. | .. |
|---|
| 2391 | 2353 | chip->device_id = pci->device; |
|---|
| 2392 | 2354 | chip->rev = pci->revision; |
|---|
| 2393 | 2355 | chip->reg_area_phys = pci_resource_start(pci, 0); |
|---|
| 2394 | | - chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000); |
|---|
| 2356 | + chip->reg_area_virt = ioremap(chip->reg_area_phys, 0x8000); |
|---|
| 2395 | 2357 | pci_set_master(pci); |
|---|
| 2396 | 2358 | chip->src441_used = -1; |
|---|
| 2397 | 2359 | |
|---|
| .. | .. |
|---|
| 2409 | 2371 | goto free_chip; |
|---|
| 2410 | 2372 | } |
|---|
| 2411 | 2373 | chip->irq = pci->irq; |
|---|
| 2374 | + card->sync_irq = chip->irq; |
|---|
| 2412 | 2375 | |
|---|
| 2413 | 2376 | snd_ymfpci_aclink_reset(pci); |
|---|
| 2414 | 2377 | if (snd_ymfpci_codec_ready(chip, 0) < 0) { |
|---|