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/cs4281.c

    r612 r615  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Driver for Cirrus Logic CS4281 based PCI soundcard
    34 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
    4  *
    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  *
    205 */
    216
    22 #ifdef TARGET_OS2
    23 #define KBUILD_MODNAME "cs4281"
    24 #endif
    25 
    26 #include <asm/io.h>
     7#include <linux/io.h>
    278#include <linux/delay.h>
    289#include <linux/interrupt.h>
     
    4223
    4324
     25#ifdef TARGET_OS2
     26#define KBUILD_MODNAME "cs4281"
     27#endif
    4428MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
    4529MODULE_DESCRIPTION("Cirrus Logic CS4281");
     
    4933static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    5034static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    51 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable switches */
    52 static int dual_codec[SNDRV_CARDS];     /* dual codec */
     35static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable switches */
     36static bool dual_codec[SNDRV_CARDS];    /* dual codec */
    5337
    5438module_param_array(index, int, NULL, 0444);
     
    491475        struct gameport *gameport;
    492476
    493 #ifdef CONFIG_PM
     477#ifdef CONFIG_PM_SLEEP
    494478        u32 suspend_regs[SUSPEND_REGISTERS];
    495479#endif
     
    499483static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id);
    500484
    501 static DEFINE_PCI_DEVICE_TABLE(snd_cs4281_ids) = {
     485static const struct pci_device_id snd_cs4281_ids[] = {
    502486        { PCI_VDEVICE(CIRRUS, 0x6005), 0, },    /* CS4281 */
    503487        { 0, }
     
    569553                }
    570554        }
    571         snd_printk(KERN_ERR "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val);
     555        dev_err(chip->card->dev,
     556                "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val);
    572557}
    573558
     
    629614        }
    630615
    631         snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
     616        dev_err(chip->card->dev,
     617                "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
    632618        result = 0xffff;
    633619        goto __end;
     
    648634        }
    649635       
    650         snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg);
     636        dev_err(chip->card->dev,
     637                "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg);
    651638        result = 0xffff;
    652639        goto __end;
     
    711698static unsigned int snd_cs4281_rate(unsigned int rate, unsigned int *real_rate)
    712699{
    713         unsigned int val = ~0;
     700        unsigned int val;
    714701       
    715702        if (real_rate)
     
    724711        case 48000:     return 0;
    725712        default:
    726                 goto __variable;
    727         }
    728       __variable:
     713                break;
     714        }
    729715        val = 1536000 / rate;
    730716        if (real_rate)
     
    840826
    841827        /*
    842         printk(KERN_DEBUG "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n",
    843                snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size,
     828        dev_dbg(chip->card->dev,
     829                "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n",
     830                snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size,
    844831               jiffies);
    845832        */
     
    848835}
    849836
    850 static struct snd_pcm_hardware snd_cs4281_playback =
     837static const struct snd_pcm_hardware snd_cs4281_playback =
    851838{
    852839        .info =                 SNDRV_PCM_INFO_MMAP |
     
    873860};
    874861
    875 static struct snd_pcm_hardware snd_cs4281_capture =
     862static const struct snd_pcm_hardware snd_cs4281_capture =
    876863{
    877864        .info =                 SNDRV_PCM_INFO_MMAP |
     
    952939}
    953940
    954 static struct snd_pcm_ops snd_cs4281_playback_ops = {
     941static const struct snd_pcm_ops snd_cs4281_playback_ops = {
    955942        .open =         snd_cs4281_playback_open,
    956943        .close =        snd_cs4281_playback_close,
     
    963950};
    964951
    965 static struct snd_pcm_ops snd_cs4281_capture_ops = {
     952static const struct snd_pcm_ops snd_cs4281_capture_ops = {
    966953        .open =         snd_cs4281_capture_open,
    967954        .close =        snd_cs4281_capture_close,
     
    974961};
    975962
    976 static int __devinit snd_cs4281_pcm(struct cs4281 * chip, int device,
    977                                     struct snd_pcm ** rpcm)
     963static int snd_cs4281_pcm(struct cs4281 *chip, int device)
    978964{
    979965        struct snd_pcm *pcm;
    980966        int err;
    981967
    982         if (rpcm)
    983                 *rpcm = NULL;
    984968        err = snd_pcm_new(chip->card, "CS4281", device, 1, 1, &pcm);
    985969        if (err < 0)
     
    997981                                              snd_dma_pci_data(chip->pci), 64*1024, 512*1024);
    998982
    999         if (rpcm)
    1000                 *rpcm = pcm;
    1001983        return 0;
    1002984}
     
    10611043static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -4650, 150, 0);
    10621044
    1063 static struct snd_kcontrol_new snd_cs4281_fm_vol =
     1045static const struct snd_kcontrol_new snd_cs4281_fm_vol =
    10641046{
    10651047        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     
    10721054};
    10731055
    1074 static struct snd_kcontrol_new snd_cs4281_pcm_vol =
     1056static const struct snd_kcontrol_new snd_cs4281_pcm_vol =
    10751057{
    10761058        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     
    10981080}
    10991081
    1100 static int __devinit snd_cs4281_mixer(struct cs4281 * chip)
     1082static int snd_cs4281_mixer(struct cs4281 *chip)
    11011083{
    11021084        struct snd_card *card = chip->card;
     
    11761158};
    11771159
    1178 static void __devinit snd_cs4281_proc_init(struct cs4281 * chip)
     1160static void snd_cs4281_proc_init(struct cs4281 *chip)
    11791161{
    11801162        struct snd_info_entry *entry;
    11811163
    1182         if (! snd_card_proc_new(chip->card, "cs4281", &entry))
    1183                 snd_info_set_text_ops(entry, chip, snd_cs4281_proc_read);
     1164        snd_card_ro_proc_new(chip->card, "cs4281", chip, snd_cs4281_proc_read);
    11841165        if (! snd_card_proc_new(chip->card, "cs4281_BA0", &entry)) {
    11851166                entry->content = SNDRV_INFO_CONTENT_DATA;
     
    12001181 */
    12011182
    1202 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     1183#if IS_REACHABLE(CONFIG_GAMEPORT)
    12031184
    12041185static void snd_cs4281_gameport_trigger(struct gameport *gameport)
     
    12641245}
    12651246
    1266 static int __devinit snd_cs4281_create_gameport(struct cs4281 *chip)
     1247static int snd_cs4281_create_gameport(struct cs4281 *chip)
    12671248{
    12681249        struct gameport *gp;
     
    12701251        chip->gameport = gp = gameport_allocate_port();
    12711252        if (!gp) {
    1272                 printk(KERN_ERR "cs4281: cannot allocate memory for gameport\n");
     1253                dev_err(chip->card->dev,
     1254                        "cannot allocate memory for gameport\n");
    12731255                return -ENOMEM;
    12741256        }
     
    13011283static inline int snd_cs4281_create_gameport(struct cs4281 *chip) { return -ENOSYS; }
    13021284static inline void snd_cs4281_free_gameport(struct cs4281 *chip) { }
    1303 #endif /* CONFIG_GAMEPORT || (MODULE && CONFIG_GAMEPORT_MODULE) */
     1285#endif /* IS_REACHABLE(CONFIG_GAMEPORT) */
    13041286
    13051287static int snd_cs4281_free(struct cs4281 *chip)
     
    13171299        snd_cs4281_pokeBA0(chip, BA0_SSPM, 0);
    13181300        /* PCI interface - D3 state */
    1319         pci_set_power_state(chip->pci, 3);
     1301        pci_set_power_state(chip->pci, PCI_D3hot);
    13201302
    13211303        if (chip->irq >= 0)
    13221304                free_irq(chip->irq, chip);
    1323         if (chip->ba0)
    1324                 iounmap(chip->ba0);
    1325         if (chip->ba1)
    1326                 iounmap(chip->ba1);
     1305        iounmap(chip->ba0);
     1306        iounmap(chip->ba1);
    13271307        pci_release_regions(chip->pci);
    13281308        pci_disable_device(chip->pci);
     
    13401320static int snd_cs4281_chip_init(struct cs4281 *chip); /* defined below */
    13411321
    1342 static int __devinit snd_cs4281_create(struct snd_card *card,
    1343                                        struct pci_dev *pci,
    1344                                        struct cs4281 ** rchip,
    1345                                        int dual_codec)
     1322static int snd_cs4281_create(struct snd_card *card,
     1323                             struct pci_dev *pci,
     1324                             struct cs4281 **rchip,
     1325                             int dual_codec)
    13461326{
    13471327        struct cs4281 *chip;
     
    13661346        pci_set_master(pci);
    13671347        if (dual_codec < 0 || dual_codec > 3) {
    1368                 snd_printk(KERN_ERR "invalid dual_codec option %d\n", dual_codec);
     1348                dev_err(card->dev, "invalid dual_codec option %d\n", dual_codec);
    13691349                dual_codec = 0;
    13701350        }
     
    13881368        if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED,
    13891369                        KBUILD_MODNAME, chip)) {
    1390                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
     1370                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
    13911371                snd_cs4281_free(chip);
    13921372                return -ENOMEM;
     
    14061386
    14071387        snd_cs4281_proc_init(chip);
    1408 
    1409         snd_card_set_dev(card, &pci->dev);
    14101388
    14111389        *rchip = chip;
     
    14301408                tmp = snd_cs4281_peekBA0(chip, BA0_CFLR);
    14311409                if (tmp != BA0_CFLR_DEFAULT) {
    1432                         snd_printk(KERN_ERR "CFLR setup failed (0x%x)\n", tmp);
     1410                        dev_err(chip->card->dev,
     1411                                "CFLR setup failed (0x%x)\n", tmp);
    14331412                        return -EIO;
    14341413                }
     
    14411420       
    14421421        if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) {
    1443                 snd_printk(KERN_ERR "SERC1 AC'97 check failed (0x%x)\n", tmp);
     1422                dev_err(chip->card->dev,
     1423                        "SERC1 AC'97 check failed (0x%x)\n", tmp);
    14441424                return -EIO;
    14451425        }
    14461426        if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) {
    1447                 snd_printk(KERN_ERR "SERC2 AC'97 check failed (0x%x)\n", tmp);
     1427                dev_err(chip->card->dev,
     1428                        "SERC2 AC'97 check failed (0x%x)\n", tmp);
    14481429                return -EIO;
    14491430        }
     
    15071488        } while (time_after_eq(end_time, jiffies));
    15081489
    1509         snd_printk(KERN_ERR "DLLRDY not seen\n");
     1490        dev_err(chip->card->dev, "DLLRDY not seen\n");
    15101491        return -EIO;
    15111492
     
    15331514        } while (time_after_eq(end_time, jiffies));
    15341515
    1535         snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS));
     1516        dev_err(chip->card->dev,
     1517                "never read codec ready from AC'97 (0x%x)\n",
     1518                snd_cs4281_peekBA0(chip, BA0_ACSTS));
    15361519        return -EIO;
    15371520
     
    15441527                        schedule_timeout_uninterruptible(1);
    15451528                } while (time_after_eq(end_time, jiffies));
    1546                 snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n");
     1529                dev_info(chip->card->dev,
     1530                         "secondary codec doesn't respond. disable it...\n");
    15471531                chip->dual_codec = 0;
    15481532        __codec2_ok: ;
     
    15741558        if (--retry_count > 0)
    15751559                goto __retry;
    1576         snd_printk(KERN_ERR "never read ISV3 and ISV4 from AC'97\n");
     1560        dev_err(chip->card->dev, "never read ISV3 and ISV4 from AC'97\n");
    15771561        return -EIO;
    15781562
     
    17701754}
    17711755
    1772 static struct snd_rawmidi_ops snd_cs4281_midi_output =
     1756static const struct snd_rawmidi_ops snd_cs4281_midi_output =
    17731757{
    17741758        .open =         snd_cs4281_midi_output_open,
     
    17771761};
    17781762
    1779 static struct snd_rawmidi_ops snd_cs4281_midi_input =
     1763static const struct snd_rawmidi_ops snd_cs4281_midi_input =
    17801764{
    17811765        .open =         snd_cs4281_midi_input_open,
     
    17841768};
    17851769
    1786 static int __devinit snd_cs4281_midi(struct cs4281 * chip, int device,
    1787                                      struct snd_rawmidi **rrawmidi)
     1770static int snd_cs4281_midi(struct cs4281 *chip, int device)
    17881771{
    17891772        struct snd_rawmidi *rmidi;
    17901773        int err;
    17911774
    1792         if (rrawmidi)
    1793                 *rrawmidi = NULL;
    17941775        if ((err = snd_rawmidi_new(chip->card, "CS4281", device, 1, 1, &rmidi)) < 0)
    17951776                return err;
     
    18001781        rmidi->private_data = chip;
    18011782        chip->rmidi = rmidi;
    1802         if (rrawmidi)
    1803                 *rrawmidi = rmidi;
    18041783        return 0;
    18051784}
     
    19061885}
    19071886
    1908 static int __devinit snd_cs4281_probe(struct pci_dev *pci,
    1909                                       const struct pci_device_id *pci_id)
     1887static int snd_cs4281_probe(struct pci_dev *pci,
     1888                            const struct pci_device_id *pci_id)
    19101889{
    19111890        static int dev;
     
    19221901        }
    19231902
    1924         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     1903        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     1904                           0, &card);
    19251905        if (err < 0)
    19261906                return err;
     
    19361916                return err;
    19371917        }
    1938         if ((err = snd_cs4281_pcm(chip, 0, NULL)) < 0) {
     1918        if ((err = snd_cs4281_pcm(chip, 0)) < 0) {
    19391919                snd_card_free(card);
    19401920                return err;
    19411921        }
    1942         if ((err = snd_cs4281_midi(chip, 0, NULL)) < 0) {
     1922        if ((err = snd_cs4281_midi(chip, 0)) < 0) {
    19431923                snd_card_free(card);
    19441924                return err;
     
    19731953}
    19741954
    1975 static void __devexit snd_cs4281_remove(struct pci_dev *pci)
     1955static void snd_cs4281_remove(struct pci_dev *pci)
    19761956{
    19771957        snd_card_free(pci_get_drvdata(pci));
    1978         pci_set_drvdata(pci, NULL);
    19791958}
    19801959
     
    19821961 * Power Management
    19831962 */
    1984 #ifdef CONFIG_PM
     1963#ifdef CONFIG_PM_SLEEP
    19851964
    19861965static int saved_regs[SUSPEND_REGISTERS] = {
     
    20021981#define CLKCR1_CKRA                             0x00010000L
    20031982
    2004 static int cs4281_suspend(struct pci_dev *pci, pm_message_t state)
    2005 {
    2006         struct snd_card *card = pci_get_drvdata(pci);
     1983static int cs4281_suspend(struct device *dev)
     1984{
     1985        struct snd_card *card = dev_get_drvdata(dev);
    20071986        struct cs4281 *chip = card->private_data;
    20081987        u32 ulCLK;
     
    20101989
    20111990        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    2012         snd_pcm_suspend_all(chip->pcm);
    2013 
    20141991        snd_ac97_suspend(chip->ac97);
    20151992        snd_ac97_suspend(chip->ac97_secondary);
     
    20422019        ulCLK &= ~CLKCR1_CKRA;
    20432020        snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
    2044 
    2045         pci_disable_device(pci);
    2046         pci_save_state(pci);
    2047         pci_set_power_state(pci, pci_choose_state(pci, state));
    2048         return 0;
    2049 }
    2050 
    2051 static int cs4281_resume(struct pci_dev *pci)
    2052 {
    2053         struct snd_card *card = pci_get_drvdata(pci);
     2021        return 0;
     2022}
     2023
     2024static int cs4281_resume(struct device *dev)
     2025{
     2026        struct snd_card *card = dev_get_drvdata(dev);
    20542027        struct cs4281 *chip = card->private_data;
    20552028        unsigned int i;
    20562029        u32 ulCLK;
    2057 
    2058         pci_set_power_state(pci, PCI_D0);
    2059         pci_restore_state(pci);
    2060         if (pci_enable_device(pci) < 0) {
    2061                 printk(KERN_ERR "cs4281: pci_enable_device failed, "
    2062                        "disabling device\n");
    2063                 snd_card_disconnect(card);
    2064                 return -EIO;
    2065         }
    2066         pci_set_master(pci);
    20672030
    20682031        ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1);
     
    20872050        return 0;
    20882051}
    2089 #endif /* CONFIG_PM */
    2090 
    2091 static struct pci_driver driver = {
     2052
     2053static SIMPLE_DEV_PM_OPS(cs4281_pm, cs4281_suspend, cs4281_resume);
     2054#define CS4281_PM_OPS   &cs4281_pm
     2055#else
     2056#define CS4281_PM_OPS   NULL
     2057#endif /* CONFIG_PM_SLEEP */
     2058
     2059static struct pci_driver cs4281_driver = {
    20922060        .name = KBUILD_MODNAME,
    20932061        .id_table = snd_cs4281_ids,
    20942062        .probe = snd_cs4281_probe,
    2095         .remove = __devexit_p(snd_cs4281_remove),
    2096 #ifdef CONFIG_PM
    2097         .suspend = cs4281_suspend,
    2098         .resume = cs4281_resume,
    2099 #endif
     2063        .remove = snd_cs4281_remove,
     2064        .driver = {
     2065                .pm = CS4281_PM_OPS,
     2066        },
    21002067};
    21012068       
    2102 static int __init alsa_card_cs4281_init(void)
    2103 {
    2104         return pci_register_driver(&driver);
    2105 }
    2106 
    2107 static void __exit alsa_card_cs4281_exit(void)
    2108 {
    2109         pci_unregister_driver(&driver);
    2110 }
    2111 
    2112 module_init(alsa_card_cs4281_init)
    2113 module_exit(alsa_card_cs4281_exit)
     2069module_pci_driver(cs4281_driver);
Note: See TracChangeset for help on using the changeset viewer.