Ignore:
Timestamp:
Jan 1, 2021, 5:31:48 AM (5 years ago)
Author:
Paul Smedley
Message:

Add source for uniaud32 based on code from linux kernel 5.4.86

Location:
GPL/branches/uniaud32-next
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/alsa-kernel/pci/atiixp.c

    r612 r615  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *   ALSA driver for ATI IXP 150/200/250/300 AC97 controllers
    34 *
    45 *      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  */
    21 
    22 #include <asm/io.h>
     6 */
     7
     8#include <linux/io.h>
    239#include <linux/delay.h>
    2410#include <linux/interrupt.h>
     
    4834static int ac97_clock = 48000;
    4935static char *ac97_quirk;
    50 static int spdif_aclink = 1;
     36static bool spdif_aclink = 1;
    5137static int ac97_codec = -1;
    5238
     
    6551
    6652/* just for backward compatibility */
    67 //static int enable;
     53//static bool enable;
    6854module_param(enable, bool, 0444);
    6955
     
    212198
    213199struct atiixp_dma_desc {
    214         u32 addr;       /* DMA buffer address */
     200        __le32 addr;    /* DMA buffer address */
    215201        u16 status;     /* status bits */
    216202        u16 size;       /* size of the packet in dwords */
    217         u32 next;       /* address of the next packet descriptor */
     203        __le32 next;    /* address of the next packet descriptor */
    218204};
    219205
     
    291277/*
    292278 */
    293 static DEFINE_PCI_DEVICE_TABLE(snd_atiixp_ids) = {
     279static const struct pci_device_id snd_atiixp_ids[] = {
    294280        { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
    295281        { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
     
    301287MODULE_DEVICE_TABLE(pci, snd_atiixp_ids);
    302288
    303 static struct snd_pci_quirk atiixp_quirks[] __devinitdata = {
     289static struct snd_pci_quirk atiixp_quirks[] = {
    304290        SND_PCI_QUIRK(0x105b, 0x0c81, "Foxconn RC4107MA-RS2", 0),
    305291        SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0),
     
    440426        while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) {
    441427                if (! timeout--) {
    442                         snd_printk(KERN_WARNING "atiixp: codec acquire timeout\n");
     428                        dev_warn(chip->card->dev, "codec acquire timeout\n");
    443429                        return -EBUSY;
    444430                }
     
    471457        /* time out may happen during reset */
    472458        if (reg < 0x7c)
    473                 snd_printk(KERN_WARNING "atiixp: codec read timeout (reg %x)\n", reg);
     459                dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg);
    474460        return 0xffff;
    475461}
     
    495481        struct atiixp *chip = ac97->private_data;
    496482        return snd_atiixp_codec_read(chip, ac97->num, reg);
    497     
     483 
    498484}
    499485
     
    532518                atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
    533519                if (!--timeout) {
    534                         snd_printk(KERN_ERR "atiixp: codec reset timeout\n");
     520                        dev_err(chip->card->dev, "codec reset timeout\n");
    535521                        break;
    536522                }
     
    545531}
    546532
    547 #ifdef CONFIG_PM
     533#ifdef CONFIG_PM_SLEEP
    548534static int snd_atiixp_aclink_down(struct atiixp *chip)
    549535{
     
    571557#define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME)
    572558
    573 static int __devinit ac97_probing_bugs(struct pci_dev *pci)
     559static int ac97_probing_bugs(struct pci_dev *pci)
    574560{
    575561        const struct snd_pci_quirk *q;
     
    577563        q = snd_pci_quirk_lookup(pci, atiixp_quirks);
    578564        if (q) {
    579 #ifndef TARGET_OS2
    580                 snd_printdd(KERN_INFO "Atiixp quirk for %s.  "
    581                             "Forcing codec %d\n", q->name, q->value);
    582 #endif
     565                dev_dbg(&pci->dev, "atiixp quirk for %s.  Forcing codec %d\n",
     566                        snd_pci_quirk_name(q), q->value);
     567
    583568                return q->value;
    584569        }
     
    587572}
    588573
    589 static int __devinit snd_atiixp_codec_detect(struct atiixp *chip)
     574static int snd_atiixp_codec_detect(struct atiixp *chip)
    590575{
    591576        int timeout;
     
    611596
    612597        if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
    613                 snd_printk(KERN_ERR "atiixp: no codec detected!\n");
     598                dev_err(chip->card->dev, "no codec detected!\n");
    614599                return -ENXIO;
    615600        }
     
    687672                return bytes_to_frames(runtime, curptr);
    688673        }
    689         snd_printd("atiixp: invalid DMA pointer read 0x%x (buf=%x)\n",
     674        dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n",
    690675                   readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);
    691676        return 0;
     
    699684        if (! dma->substream || ! dma->running)
    700685                return;
    701         snd_printdd("atiixp: XRUN detected (DMA %d)\n", dma->ops->type);
    702         snd_pcm_stream_lock(dma->substream);
    703         snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
    704         snd_pcm_stream_unlock(dma->substream);
     686        dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
     687        snd_pcm_stop_xrun(dma->substream);
    705688}
    706689
     
    747730        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    748731        case SNDRV_PCM_TRIGGER_RESUME:
     732                if (dma->running && dma->suspended &&
     733                    cmd == SNDRV_PCM_TRIGGER_RESUME)
     734                        writel(dma->saved_curptr, chip->remap_addr +
     735                               dma->ops->dt_cur);
    749736                dma->ops->enable_transfer(chip, 1);
    750737                dma->running = 1;
     
    754741        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    755742        case SNDRV_PCM_TRIGGER_SUSPEND:
     743                dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND;
     744                if (dma->running && dma->suspended)
     745                        dma->saved_curptr = readl(chip->remap_addr +
     746                                                  dma->ops->dt_cur);
    756747                dma->ops->enable_transfer(chip, 0);
    757748                dma->running = 0;
    758                 dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND;
    759749                break;
    760750        default:
     
    917907                data |= ATI_REG_OUT_DMA_SLOT_BIT(10) |
    918908                        ATI_REG_OUT_DMA_SLOT_BIT(11);
    919                 /* fallthru */
     909                /* fall through */
    920910        case 6:
    921911                data |= ATI_REG_OUT_DMA_SLOT_BIT(7) |
    922912                        ATI_REG_OUT_DMA_SLOT_BIT(8);
    923                 /* fallthru */
     913                /* fall through */
    924914        case 4:
    925915                data |= ATI_REG_OUT_DMA_SLOT_BIT(6) |
    926916                        ATI_REG_OUT_DMA_SLOT_BIT(9);
    927                 /* fallthru */
     917                /* fall through */
    928918        default:
    929919                data |= ATI_REG_OUT_DMA_SLOT_BIT(3) |
     
    10231013 * pcm hardware definition, identical for all DMA types
    10241014 */
    1025 static struct snd_pcm_hardware snd_atiixp_pcm_hw =
     1015static const struct snd_pcm_hardware snd_atiixp_pcm_hw =
    10261016{
    10271017        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    11621152
    11631153/* AC97 playback */
    1164 static struct snd_pcm_ops snd_atiixp_playback_ops = {
     1154static const struct snd_pcm_ops snd_atiixp_playback_ops = {
    11651155        .open =         snd_atiixp_playback_open,
    11661156        .close =        snd_atiixp_playback_close,
     
    11741164
    11751165/* AC97 capture */
    1176 static struct snd_pcm_ops snd_atiixp_capture_ops = {
     1166static const struct snd_pcm_ops snd_atiixp_capture_ops = {
    11771167        .open =         snd_atiixp_capture_open,
    11781168        .close =        snd_atiixp_capture_close,
     
    11861176
    11871177/* SPDIF playback */
    1188 static struct snd_pcm_ops snd_atiixp_spdif_ops = {
     1178static const struct snd_pcm_ops snd_atiixp_spdif_ops = {
    11891179        .open =         snd_atiixp_spdif_open,
    11901180        .close =        snd_atiixp_spdif_close,
     
    11971187};
    11981188
    1199 static struct ac97_pcm atiixp_pcm_defs[] __devinitdata = {
     1189static const struct ac97_pcm atiixp_pcm_defs[] = {
    12001190        /* front PCM */
    12011191        {
     
    12331223};
    12341224
    1235 static struct atiixp_dma_ops snd_atiixp_playback_dma_ops = {
     1225static const struct atiixp_dma_ops snd_atiixp_playback_dma_ops = {
    12361226        .type = ATI_DMA_PLAYBACK,
    12371227        .llp_offset = ATI_REG_OUT_DMA_LINKPTR,
     
    12421232};
    12431233       
    1244 static struct atiixp_dma_ops snd_atiixp_capture_dma_ops = {
     1234static const struct atiixp_dma_ops snd_atiixp_capture_dma_ops = {
    12451235        .type = ATI_DMA_CAPTURE,
    12461236        .llp_offset = ATI_REG_IN_DMA_LINKPTR,
     
    12511241};
    12521242       
    1253 static struct atiixp_dma_ops snd_atiixp_spdif_dma_ops = {
     1243static const struct atiixp_dma_ops snd_atiixp_spdif_dma_ops = {
    12541244        .type = ATI_DMA_SPDIF,
    12551245        .llp_offset = ATI_REG_SPDF_DMA_LINKPTR,
     
    12611251       
    12621252
    1263 static int __devinit snd_atiixp_pcm_new(struct atiixp *chip)
     1253static int snd_atiixp_pcm_new(struct atiixp *chip)
    12641254{
    12651255        struct snd_pcm *pcm;
     1256        struct snd_pcm_chmap *chmap;
    12661257        struct snd_ac97_bus *pbus = chip->ac97_bus;
    12671258        int err, i, num_pcms;
     
    13061297                                              snd_dma_pci_data(chip->pci),
    13071298                                              64*1024, 128*1024);
     1299
     1300        err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     1301                                     snd_pcm_alt_chmaps, chip->max_channels, 0,
     1302                                     &chmap);
     1303        if (err < 0)
     1304                return err;
     1305        chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
     1306        chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
    13081307
    13091308        /* no SPDIF support on codec? */
     
    13951394 */
    13961395
    1397 static struct ac97_quirk ac97_quirks[] __devinitdata = {
     1396static const struct ac97_quirk ac97_quirks[] = {
    13981397        {
    13991398                .subvendor = 0x103c,
     
    14171416};
    14181417
    1419 static int __devinit snd_atiixp_mixer_new(struct atiixp *chip, int clock,
    1420                                           const char *quirk_override)
     1418static int snd_atiixp_mixer_new(struct atiixp *chip, int clock,
     1419                                const char *quirk_override)
    14211420{
    14221421        struct snd_ac97_bus *pbus;
     
    14551454                if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
    14561455                        chip->ac97[i] = NULL; /* to be sure */
    1457                         snd_printdd("atiixp: codec %d not available for audio\n", i);
     1456                        dev_dbg(chip->card->dev,
     1457                                "codec %d not available for audio\n", i);
    14581458                        continue;
    14591459                }
     
    14621462
    14631463        if (! codec_count) {
    1464                 snd_printk(KERN_ERR "atiixp: no codec available\n");
     1464                dev_err(chip->card->dev, "no codec available\n");
    14651465                return -ENODEV;
    14661466        }
     
    14721472
    14731473
    1474 #ifdef CONFIG_PM
     1474#ifdef CONFIG_PM_SLEEP
    14751475/*
    14761476 * power management
    14771477 */
    1478 static int snd_atiixp_suspend(struct pci_dev *pci, pm_message_t state)
    1479 {
    1480         struct snd_card *card = pci_get_drvdata(pci);
     1478static int snd_atiixp_suspend(struct device *dev)
     1479{
     1480        struct snd_card *card = dev_get_drvdata(dev);
    14811481        struct atiixp *chip = card->private_data;
    14821482        int i;
    14831483
    14841484        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    1485         for (i = 0; i < NUM_ATI_PCMDEVS; i++)
    1486                 if (chip->pcmdevs[i]) {
    1487                         struct atiixp_dma *dma = &chip->dmas[i];
    1488                         if (dma->substream && dma->running)
    1489                                 dma->saved_curptr = readl(chip->remap_addr +
    1490                                                           dma->ops->dt_cur);
    1491                         snd_pcm_suspend_all(chip->pcmdevs[i]);
    1492                 }
    14931485        for (i = 0; i < NUM_ATI_CODECS; i++)
    14941486                snd_ac97_suspend(chip->ac97[i]);
    14951487        snd_atiixp_aclink_down(chip);
    14961488        snd_atiixp_chip_stop(chip);
    1497 
    1498         pci_disable_device(pci);
    1499         pci_save_state(pci);
    1500         pci_set_power_state(pci, pci_choose_state(pci, state));
    1501         return 0;
    1502 }
    1503 
    1504 static int snd_atiixp_resume(struct pci_dev *pci)
    1505 {
    1506         struct snd_card *card = pci_get_drvdata(pci);
     1489        return 0;
     1490}
     1491
     1492static int snd_atiixp_resume(struct device *dev)
     1493{
     1494        struct snd_card *card = dev_get_drvdata(dev);
    15071495        struct atiixp *chip = card->private_data;
    15081496        int i;
    1509 
    1510         pci_set_power_state(pci, PCI_D0);
    1511         pci_restore_state(pci);
    1512         if (pci_enable_device(pci) < 0) {
    1513                 printk(KERN_ERR "atiixp: pci_enable_device failed, "
    1514                        "disabling device\n");
    1515                 snd_card_disconnect(card);
    1516                 return -EIO;
    1517         }
    1518         pci_set_master(pci);
    15191497
    15201498        snd_atiixp_aclink_reset(chip);
     
    15321510                                writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN,
    15331511                                       chip->remap_addr + dma->ops->llp_offset);
    1534                                 writel(dma->saved_curptr, chip->remap_addr +
    1535                                        dma->ops->dt_cur);
    15361512                        }
    15371513                }
     
    15401516        return 0;
    15411517}
    1542 #endif /* CONFIG_PM */
    1543 
    1544 
    1545 #ifdef CONFIG_PROC_FS
     1518
     1519static SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume);
     1520#define SND_ATIIXP_PM_OPS       &snd_atiixp_pm
     1521#else
     1522#define SND_ATIIXP_PM_OPS       NULL
     1523#endif /* CONFIG_PM_SLEEP */
     1524
     1525
    15461526/*
    15471527 * proc interface for register dump
     
    15581538}
    15591539
    1560 static void __devinit snd_atiixp_proc_init(struct atiixp *chip)
    1561 {
    1562         struct snd_info_entry *entry;
    1563 
    1564         if (! snd_card_proc_new(chip->card, "atiixp", &entry))
    1565                 snd_info_set_text_ops(entry, chip, snd_atiixp_proc_read);
    1566 }
    1567 #else /* !CONFIG_PROC_FS */
    1568 #define snd_atiixp_proc_init(chip)
    1569 #endif
     1540static void snd_atiixp_proc_init(struct atiixp *chip)
     1541{
     1542        snd_card_ro_proc_new(chip->card, "atiixp", chip, snd_atiixp_proc_read);
     1543}
    15701544
    15711545
     
    15831557        if (chip->irq >= 0)
    15841558                free_irq(chip->irq, chip);
    1585         if (chip->remap_addr)
    1586                 iounmap(chip->remap_addr);
     1559        iounmap(chip->remap_addr);
    15871560        pci_release_regions(chip->pci);
    15881561        pci_disable_device(chip->pci);
     
    16001573 * constructor for chip instance
    16011574 */
    1602 static int __devinit snd_atiixp_create(struct snd_card *card,
    1603                                       struct pci_dev *pci,
    1604                                       struct atiixp **r_chip)
     1575static int snd_atiixp_create(struct snd_card *card,
     1576                             struct pci_dev *pci,
     1577                             struct atiixp **r_chip)
    16051578{
    16061579        static struct snd_device_ops ops = {
     
    16321605        chip->remap_addr = pci_ioremap_bar(pci, 0);
    16331606        if (chip->remap_addr == NULL) {
    1634                 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
     1607                dev_err(card->dev, "AC'97 space ioremap problem\n");
    16351608                snd_atiixp_free(chip);
    16361609                return -EIO;
     
    16391612        if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED,
    16401613                        KBUILD_MODNAME, chip)) {
    1641                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
     1614                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
    16421615                snd_atiixp_free(chip);
    16431616                return -EBUSY;
     
    16521625        }
    16531626
    1654         snd_card_set_dev(card, &pci->dev);
    1655 
    16561627        *r_chip = chip;
    16571628        return 0;
     
    16591630
    16601631
    1661 static int __devinit snd_atiixp_probe(struct pci_dev *pci,
    1662                                      const struct pci_device_id *pci_id)
     1632static int snd_atiixp_probe(struct pci_dev *pci,
     1633                            const struct pci_device_id *pci_id)
    16631634{
    16641635        struct snd_card *card;
     
    16661637        int err;
    16671638
    1668         err = snd_card_create(index, id, THIS_MODULE, 0, &card);
     1639        err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
    16691640        if (err < 0)
    16701641                return err;
     
    17121683}
    17131684
    1714 static void __devexit snd_atiixp_remove(struct pci_dev *pci)
     1685static void snd_atiixp_remove(struct pci_dev *pci)
    17151686{
    17161687        snd_card_free(pci_get_drvdata(pci));
    1717         pci_set_drvdata(pci, NULL);
    1718 }
    1719 
    1720 static struct pci_driver driver = {
     1688}
     1689
     1690static struct pci_driver atiixp_driver = {
    17211691        .name = KBUILD_MODNAME,
    17221692        .id_table = snd_atiixp_ids,
    17231693        .probe = snd_atiixp_probe,
    1724         .remove = __devexit_p(snd_atiixp_remove),
    1725 #ifdef CONFIG_PM
    1726         .suspend = snd_atiixp_suspend,
    1727         .resume = snd_atiixp_resume,
    1728 #endif
     1694        .remove = snd_atiixp_remove,
     1695        .driver = {
     1696                .pm = SND_ATIIXP_PM_OPS,
     1697        },
    17291698};
    17301699
    1731 
    1732 static int __init alsa_card_atiixp_init(void)
    1733 {
    1734         return pci_register_driver(&driver);
    1735 }
    1736 
    1737 static void __exit alsa_card_atiixp_exit(void)
    1738 {
    1739         pci_unregister_driver(&driver);
    1740 }
    1741 
    1742 module_init(alsa_card_atiixp_init)
    1743 module_exit(alsa_card_atiixp_exit)
     1700module_pci_driver(atiixp_driver);
Note: See TracChangeset for help on using the changeset viewer.