| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ALSA driver for ATI IXP 150/200/250/300 AC97 controllers |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | | - * |
|---|
| 20 | 6 | */ |
|---|
| 21 | 7 | |
|---|
| 22 | 8 | #include <linux/io.h> |
|---|
| .. | .. |
|---|
| 296 | 282 | |
|---|
| 297 | 283 | MODULE_DEVICE_TABLE(pci, snd_atiixp_ids); |
|---|
| 298 | 284 | |
|---|
| 299 | | -static struct snd_pci_quirk atiixp_quirks[] = { |
|---|
| 285 | +static const struct snd_pci_quirk atiixp_quirks[] = { |
|---|
| 300 | 286 | SND_PCI_QUIRK(0x105b, 0x0c81, "Foxconn RC4107MA-RS2", 0), |
|---|
| 301 | 287 | SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0), |
|---|
| 302 | 288 | { } /* terminator */ |
|---|
| .. | .. |
|---|
| 367 | 353 | |
|---|
| 368 | 354 | if (dma->desc_buf.area == NULL) { |
|---|
| 369 | 355 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
|---|
| 370 | | - snd_dma_pci_data(chip->pci), |
|---|
| 356 | + &chip->pci->dev, |
|---|
| 371 | 357 | ATI_DESC_LIST_SIZE, |
|---|
| 372 | 358 | &dma->desc_buf) < 0) |
|---|
| 373 | 359 | return -ENOMEM; |
|---|
| .. | .. |
|---|
| 733 | 719 | case SNDRV_PCM_TRIGGER_START: |
|---|
| 734 | 720 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
|---|
| 735 | 721 | case SNDRV_PCM_TRIGGER_RESUME: |
|---|
| 722 | + if (dma->running && dma->suspended && |
|---|
| 723 | + cmd == SNDRV_PCM_TRIGGER_RESUME) |
|---|
| 724 | + writel(dma->saved_curptr, chip->remap_addr + |
|---|
| 725 | + dma->ops->dt_cur); |
|---|
| 736 | 726 | dma->ops->enable_transfer(chip, 1); |
|---|
| 737 | 727 | dma->running = 1; |
|---|
| 738 | 728 | dma->suspended = 0; |
|---|
| .. | .. |
|---|
| 740 | 730 | case SNDRV_PCM_TRIGGER_STOP: |
|---|
| 741 | 731 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
|---|
| 742 | 732 | case SNDRV_PCM_TRIGGER_SUSPEND: |
|---|
| 733 | + dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND; |
|---|
| 734 | + if (dma->running && dma->suspended) |
|---|
| 735 | + dma->saved_curptr = readl(chip->remap_addr + |
|---|
| 736 | + dma->ops->dt_cur); |
|---|
| 743 | 737 | dma->ops->enable_transfer(chip, 0); |
|---|
| 744 | 738 | dma->running = 0; |
|---|
| 745 | | - dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND; |
|---|
| 746 | 739 | break; |
|---|
| 747 | 740 | default: |
|---|
| 748 | 741 | err = -EINVAL; |
|---|
| .. | .. |
|---|
| 903 | 896 | case 8: |
|---|
| 904 | 897 | data |= ATI_REG_OUT_DMA_SLOT_BIT(10) | |
|---|
| 905 | 898 | ATI_REG_OUT_DMA_SLOT_BIT(11); |
|---|
| 906 | | - /* fallthru */ |
|---|
| 899 | + fallthrough; |
|---|
| 907 | 900 | case 6: |
|---|
| 908 | 901 | data |= ATI_REG_OUT_DMA_SLOT_BIT(7) | |
|---|
| 909 | 902 | ATI_REG_OUT_DMA_SLOT_BIT(8); |
|---|
| 910 | | - /* fallthru */ |
|---|
| 903 | + fallthrough; |
|---|
| 911 | 904 | case 4: |
|---|
| 912 | 905 | data |= ATI_REG_OUT_DMA_SLOT_BIT(6) | |
|---|
| 913 | 906 | ATI_REG_OUT_DMA_SLOT_BIT(9); |
|---|
| 914 | | - /* fallthru */ |
|---|
| 907 | + fallthrough; |
|---|
| 915 | 908 | default: |
|---|
| 916 | 909 | data |= ATI_REG_OUT_DMA_SLOT_BIT(3) | |
|---|
| 917 | 910 | ATI_REG_OUT_DMA_SLOT_BIT(4); |
|---|
| .. | .. |
|---|
| 959 | 952 | struct atiixp_dma *dma = substream->runtime->private_data; |
|---|
| 960 | 953 | int err; |
|---|
| 961 | 954 | |
|---|
| 962 | | - err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
|---|
| 963 | | - if (err < 0) |
|---|
| 964 | | - return err; |
|---|
| 965 | 955 | dma->buf_addr = substream->runtime->dma_addr; |
|---|
| 966 | 956 | dma->buf_bytes = params_buffer_bytes(hw_params); |
|---|
| 967 | 957 | |
|---|
| .. | .. |
|---|
| 1001 | 991 | dma->pcm_open_flag = 0; |
|---|
| 1002 | 992 | } |
|---|
| 1003 | 993 | atiixp_clear_dma_packets(chip, dma, substream); |
|---|
| 1004 | | - snd_pcm_lib_free_pages(substream); |
|---|
| 1005 | 994 | return 0; |
|---|
| 1006 | 995 | } |
|---|
| 1007 | 996 | |
|---|
| .. | .. |
|---|
| 1151 | 1140 | static const struct snd_pcm_ops snd_atiixp_playback_ops = { |
|---|
| 1152 | 1141 | .open = snd_atiixp_playback_open, |
|---|
| 1153 | 1142 | .close = snd_atiixp_playback_close, |
|---|
| 1154 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1155 | 1143 | .hw_params = snd_atiixp_pcm_hw_params, |
|---|
| 1156 | 1144 | .hw_free = snd_atiixp_pcm_hw_free, |
|---|
| 1157 | 1145 | .prepare = snd_atiixp_playback_prepare, |
|---|
| .. | .. |
|---|
| 1163 | 1151 | static const struct snd_pcm_ops snd_atiixp_capture_ops = { |
|---|
| 1164 | 1152 | .open = snd_atiixp_capture_open, |
|---|
| 1165 | 1153 | .close = snd_atiixp_capture_close, |
|---|
| 1166 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1167 | 1154 | .hw_params = snd_atiixp_pcm_hw_params, |
|---|
| 1168 | 1155 | .hw_free = snd_atiixp_pcm_hw_free, |
|---|
| 1169 | 1156 | .prepare = snd_atiixp_capture_prepare, |
|---|
| .. | .. |
|---|
| 1175 | 1162 | static const struct snd_pcm_ops snd_atiixp_spdif_ops = { |
|---|
| 1176 | 1163 | .open = snd_atiixp_spdif_open, |
|---|
| 1177 | 1164 | .close = snd_atiixp_spdif_close, |
|---|
| 1178 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 1179 | 1165 | .hw_params = snd_atiixp_pcm_hw_params, |
|---|
| 1180 | 1166 | .hw_free = snd_atiixp_pcm_hw_free, |
|---|
| 1181 | 1167 | .prepare = snd_atiixp_spdif_prepare, |
|---|
| .. | .. |
|---|
| 1290 | 1276 | strcpy(pcm->name, "ATI IXP AC97"); |
|---|
| 1291 | 1277 | chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm; |
|---|
| 1292 | 1278 | |
|---|
| 1293 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1294 | | - snd_dma_pci_data(chip->pci), |
|---|
| 1295 | | - 64*1024, 128*1024); |
|---|
| 1279 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1280 | + &chip->pci->dev, 64*1024, 128*1024); |
|---|
| 1296 | 1281 | |
|---|
| 1297 | 1282 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
|---|
| 1298 | 1283 | snd_pcm_alt_chmaps, chip->max_channels, 0, |
|---|
| .. | .. |
|---|
| 1323 | 1308 | strcpy(pcm->name, "ATI IXP IEC958 (Direct)"); |
|---|
| 1324 | 1309 | chip->pcmdevs[ATI_PCMDEV_DIGITAL] = pcm; |
|---|
| 1325 | 1310 | |
|---|
| 1326 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1327 | | - snd_dma_pci_data(chip->pci), |
|---|
| 1328 | | - 64*1024, 128*1024); |
|---|
| 1311 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 1312 | + &chip->pci->dev, 64*1024, 128*1024); |
|---|
| 1329 | 1313 | |
|---|
| 1330 | 1314 | /* pre-select AC97 SPDIF slots 10/11 */ |
|---|
| 1331 | 1315 | for (i = 0; i < NUM_ATI_CODECS; i++) { |
|---|
| .. | .. |
|---|
| 1419 | 1403 | struct snd_ac97_template ac97; |
|---|
| 1420 | 1404 | int i, err; |
|---|
| 1421 | 1405 | int codec_count; |
|---|
| 1422 | | - static struct snd_ac97_bus_ops ops = { |
|---|
| 1406 | + static const struct snd_ac97_bus_ops ops = { |
|---|
| 1423 | 1407 | .write = snd_atiixp_ac97_write, |
|---|
| 1424 | 1408 | .read = snd_atiixp_ac97_read, |
|---|
| 1425 | 1409 | }; |
|---|
| 1426 | | - static unsigned int codec_skip[NUM_ATI_CODECS] = { |
|---|
| 1410 | + static const unsigned int codec_skip[NUM_ATI_CODECS] = { |
|---|
| 1427 | 1411 | ATI_REG_ISR_CODEC0_NOT_READY, |
|---|
| 1428 | 1412 | ATI_REG_ISR_CODEC1_NOT_READY, |
|---|
| 1429 | 1413 | ATI_REG_ISR_CODEC2_NOT_READY, |
|---|
| .. | .. |
|---|
| 1479 | 1463 | int i; |
|---|
| 1480 | 1464 | |
|---|
| 1481 | 1465 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
|---|
| 1482 | | - for (i = 0; i < NUM_ATI_PCMDEVS; i++) |
|---|
| 1483 | | - if (chip->pcmdevs[i]) { |
|---|
| 1484 | | - struct atiixp_dma *dma = &chip->dmas[i]; |
|---|
| 1485 | | - if (dma->substream && dma->running) |
|---|
| 1486 | | - dma->saved_curptr = readl(chip->remap_addr + |
|---|
| 1487 | | - dma->ops->dt_cur); |
|---|
| 1488 | | - snd_pcm_suspend_all(chip->pcmdevs[i]); |
|---|
| 1489 | | - } |
|---|
| 1490 | 1466 | for (i = 0; i < NUM_ATI_CODECS; i++) |
|---|
| 1491 | 1467 | snd_ac97_suspend(chip->ac97[i]); |
|---|
| 1492 | 1468 | snd_atiixp_aclink_down(chip); |
|---|
| .. | .. |
|---|
| 1514 | 1490 | dma->substream->ops->prepare(dma->substream); |
|---|
| 1515 | 1491 | writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN, |
|---|
| 1516 | 1492 | chip->remap_addr + dma->ops->llp_offset); |
|---|
| 1517 | | - writel(dma->saved_curptr, chip->remap_addr + |
|---|
| 1518 | | - dma->ops->dt_cur); |
|---|
| 1519 | 1493 | } |
|---|
| 1520 | 1494 | } |
|---|
| 1521 | 1495 | |
|---|
| .. | .. |
|---|
| 1546 | 1520 | |
|---|
| 1547 | 1521 | static void snd_atiixp_proc_init(struct atiixp *chip) |
|---|
| 1548 | 1522 | { |
|---|
| 1549 | | - struct snd_info_entry *entry; |
|---|
| 1550 | | - |
|---|
| 1551 | | - if (! snd_card_proc_new(chip->card, "atiixp", &entry)) |
|---|
| 1552 | | - snd_info_set_text_ops(entry, chip, snd_atiixp_proc_read); |
|---|
| 1523 | + snd_card_ro_proc_new(chip->card, "atiixp", chip, snd_atiixp_proc_read); |
|---|
| 1553 | 1524 | } |
|---|
| 1554 | 1525 | |
|---|
| 1555 | 1526 | |
|---|
| .. | .. |
|---|
| 1586 | 1557 | struct pci_dev *pci, |
|---|
| 1587 | 1558 | struct atiixp **r_chip) |
|---|
| 1588 | 1559 | { |
|---|
| 1589 | | - static struct snd_device_ops ops = { |
|---|
| 1560 | + static const struct snd_device_ops ops = { |
|---|
| 1590 | 1561 | .dev_free = snd_atiixp_dev_free, |
|---|
| 1591 | 1562 | }; |
|---|
| 1592 | 1563 | struct atiixp *chip; |
|---|
| .. | .. |
|---|
| 1626 | 1597 | return -EBUSY; |
|---|
| 1627 | 1598 | } |
|---|
| 1628 | 1599 | chip->irq = pci->irq; |
|---|
| 1600 | + card->sync_irq = chip->irq; |
|---|
| 1629 | 1601 | pci_set_master(pci); |
|---|
| 1630 | | - synchronize_irq(chip->irq); |
|---|
| 1631 | 1602 | |
|---|
| 1632 | 1603 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
|---|
| 1633 | 1604 | snd_atiixp_free(chip); |
|---|