Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/pci/bt87x.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 * bt87x.c - Brooktree Bt878/Bt879 driver for ALSA
     
    56 *
    67 * based on btaudio.c by Gerd Knorr <kraxel@bytesex.org>
    7  *
    8  *
    9  *  This driver is free software; you can redistribute it and/or modify
    10  *  it under the terms of the GNU General Public License as published by
    11  *  the Free Software Foundation; either version 2 of the License, or
    12  *  (at your option) any later version.
    13  *
    14  *  This driver is distributed in the hope that it will be useful,
    15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  *  GNU General Public License for more details.
    18  *
    19  *  You should have received a copy of the GNU General Public License
    20  *  along with this program; if not, write to the Free Software
    21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    228 */
     9
     10#ifdef TARGET_OS2
     11#define KBUILD_MODNAME "bt87x"
     12#endif
    2313
    2414#include <linux/init.h>
     
    2616#include <linux/pci.h>
    2717#include <linux/slab.h>
    28 #include <linux/moduleparam.h>
     18#include <linux/module.h>
    2919#include <linux/bitops.h>
    30 #include <asm/io.h>
     20#include <linux/io.h>
    3121#include <sound/core.h>
    3222#include <sound/pcm.h>
     
    4838static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    4939#endif
    50 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     40static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    5141static int digital_rate[SNDRV_CARDS];   /* digital input rate */
    52 static int load_all;    /* allow to load the non-whitelisted cards */
     42static bool load_all;   /* allow to load cards not the allowlist */
    5343
    5444module_param_array(index, int, NULL, 0444);
     
    6151MODULE_PARM_DESC(digital_rate, "Digital input rate for Bt87x soundcard");
    6252module_param(load_all, bool, 0444);
    63 MODULE_PARM_DESC(load_all, "Allow to load the non-whitelisted cards");
     53MODULE_PARM_DESC(load_all, "Allow to load cards not on the allowlist");
    6454
    6555
     
    170160};
    171161
    172 static __devinitdata struct snd_bt87x_board snd_bt87x_boards[] = {
     162static const struct snd_bt87x_board snd_bt87x_boards[] = {
    173163        [SND_BT87X_BOARD_UNKNOWN] = {
    174164                .dig_rate = 32000, /* just a guess */
     
    234224{
    235225        unsigned int i, offset;
    236         u32 *risc;
     226        __le32 *risc;
    237227
    238228        if (chip->dma_risc.area == NULL) {
    239                 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
     229                if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
    240230                                        PAGE_ALIGN(MAX_RISC_SIZE), &chip->dma_risc) < 0)
    241231                        return -ENOMEM;
    242232        }
    243         risc = (u32 *)chip->dma_risc.area;
     233        risc = (__le32 *)chip->dma_risc.area;
    244234        offset = 0;
    245235        *risc++ = cpu_to_le32(RISC_SYNC | RISC_SYNC_FM1);
     
    291281static void snd_bt87x_pci_error(struct snd_bt87x *chip, unsigned int status)
    292282{
    293         u16 pci_status;
    294 
    295         pci_read_config_word(chip->pci, PCI_STATUS, &pci_status);
    296         pci_status &= PCI_STATUS_PARITY | PCI_STATUS_SIG_TARGET_ABORT |
    297                 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT |
    298                 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY;
    299         pci_write_config_word(chip->pci, PCI_STATUS, pci_status);
     283        int pci_status = pci_status_get_and_clear_errors(chip->pci);
     284
    300285        if (pci_status != PCI_STATUS_DETECTED_PARITY)
    301                 snd_printk(KERN_ERR "Aieee - PCI error! status %#08x, PCI status %#04x\n",
     286                dev_err(chip->card->dev,
     287                        "Aieee - PCI error! status %#08x, PCI status %#04x\n",
    302288                           status & ERROR_INTERRUPTS, pci_status);
    303289        else {
    304                 snd_printk(KERN_ERR "Aieee - PCI parity error detected!\n");
     290                dev_err(chip->card->dev,
     291                        "Aieee - PCI parity error detected!\n");
    305292                /* error 'handling' similar to aic7xxx_pci.c: */
    306293                chip->pci_parity_errors++;
    307294                if (chip->pci_parity_errors > 20) {
    308                         snd_printk(KERN_ERR "Too many PCI parity errors observed.\n");
    309                         snd_printk(KERN_ERR "Some device on this bus is generating bad parity.\n");
    310                         snd_printk(KERN_ERR "This is an error *observed by*, not *generated by*, this card.\n");
    311                         snd_printk(KERN_ERR "PCI parity error checking has been disabled.\n");
     295                        dev_err(chip->card->dev,
     296                                "Too many PCI parity errors observed.\n");
     297                        dev_err(chip->card->dev,
     298                                "Some device on this bus is generating bad parity.\n");
     299                        dev_err(chip->card->dev,
     300                                "This is an error *observed by*, not *generated by*, this card.\n");
     301                        dev_err(chip->card->dev,
     302                                "PCI parity error checking has been disabled.\n");
    312303                        chip->interrupt_mask &= ~(INT_PPERR | INT_RIPERR);
    313304                        snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask);
     
    329320        if (irq_status & ERROR_INTERRUPTS) {
    330321                if (irq_status & (INT_FBUS | INT_FTRGT))
    331                         snd_printk(KERN_WARNING "FIFO overrun, status %#08x\n", status);
     322                        dev_warn(chip->card->dev,
     323                                 "FIFO overrun, status %#08x\n", status);
    332324                if (irq_status & INT_OCERR)
    333                         snd_printk(KERN_ERR "internal RISC error, status %#08x\n", status);
     325                        dev_err(chip->card->dev,
     326                                "internal RISC error, status %#08x\n", status);
    334327                if (irq_status & (INT_PPERR | INT_RIPERR | INT_PABORT))
    335328                        snd_bt87x_pci_error(chip, irq_status);
     
    351344}
    352345
    353 static struct snd_pcm_hardware snd_bt87x_digital_hw = {
     346static const struct snd_pcm_hardware snd_bt87x_digital_hw = {
    354347        .info = SNDRV_PCM_INFO_MMAP |
    355348                SNDRV_PCM_INFO_INTERLEAVED |
     
    368361};
    369362
    370 static struct snd_pcm_hardware snd_bt87x_analog_hw = {
     363static const struct snd_pcm_hardware snd_bt87x_analog_hw = {
    371364        .info = SNDRV_PCM_INFO_MMAP |
    372365                SNDRV_PCM_INFO_INTERLEAVED |
     
    399392static int snd_bt87x_set_analog_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime)
    400393{
    401         static struct snd_ratnum analog_clock = {
     394        static const struct snd_ratnum analog_clock = {
    402395                .num = ANALOG_CLOCK,
    403396                .den_min = CLOCK_DIV_MIN,
     
    405398                .den_step = 1
    406399        };
    407         static struct snd_pcm_hw_constraint_ratnums constraint_rates = {
     400        static const struct snd_pcm_hw_constraint_ratnums constraint_rates = {
    408401                .nrats = 1,
    409402                .rats = &analog_clock
     
    441434_error:
    442435        clear_bit(0, &chip->opened);
    443         smp_mb__after_clear_bit();
     436        smp_mb__after_atomic();
    444437        return err;
    445438}
     
    456449        chip->substream = NULL;
    457450        clear_bit(0, &chip->opened);
    458         smp_mb__after_clear_bit();
     451        smp_mb__after_atomic();
    459452        return 0;
    460453}
     
    464457{
    465458        struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
    466         int err;
    467 
    468         err = snd_pcm_lib_malloc_pages(substream,
    469                                        params_buffer_bytes(hw_params));
    470         if (err < 0)
    471                 return err;
     459
    472460        return snd_bt87x_create_risc(chip, substream,
    473461                                     params_periods(hw_params),
     
    480468
    481469        snd_bt87x_free_risc(chip);
    482         snd_pcm_lib_free_pages(substream);
    483470        return 0;
    484471}
     
    548535}
    549536
    550 static struct snd_pcm_ops snd_bt87x_pcm_ops = {
     537static const struct snd_pcm_ops snd_bt87x_pcm_ops = {
    551538        .open = snd_bt87x_pcm_open,
    552539        .close = snd_bt87x_close,
    553         .ioctl = snd_pcm_lib_ioctl,
    554540        .hw_params = snd_bt87x_hw_params,
    555541        .hw_free = snd_bt87x_hw_free,
     
    557543        .trigger = snd_bt87x_trigger,
    558544        .pointer = snd_bt87x_pointer,
    559         .page = snd_pcm_sgbuf_ops_page,
    560545};
    561546
     
    596581}
    597582
    598 static struct snd_kcontrol_new snd_bt87x_capture_volume = {
     583static const struct snd_kcontrol_new snd_bt87x_capture_volume = {
    599584        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    600585        .name = "Capture Volume",
     
    632617}
    633618
    634 static struct snd_kcontrol_new snd_bt87x_capture_boost = {
     619static const struct snd_kcontrol_new snd_bt87x_capture_boost = {
    635620        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    636621        .name = "Capture Boost",
     
    674659}
    675660
    676 static struct snd_kcontrol_new snd_bt87x_capture_source = {
     661static const struct snd_kcontrol_new snd_bt87x_capture_source = {
    677662        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    678663        .name = "Capture Source",
     
    688673        if (chip->irq >= 0)
    689674                free_irq(chip->irq, chip);
    690         if (chip->mmio)
    691                 iounmap(chip->mmio);
     675        iounmap(chip->mmio);
    692676        pci_release_regions(chip->pci);
    693677        pci_disable_device(chip->pci);
     
    702686}
    703687
    704 static int __devinit snd_bt87x_pcm(struct snd_bt87x *chip, int device, char *name)
     688static int snd_bt87x_pcm(struct snd_bt87x *chip, int device, char *name)
    705689{
    706690        int err;
     
    713697        strcpy(pcm->name, name);
    714698        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_bt87x_pcm_ops);
    715         return snd_pcm_lib_preallocate_pages_for_all(pcm,
    716                                                      SNDRV_DMA_TYPE_DEV_SG,
    717                                                      snd_dma_pci_data(chip->pci),
    718                                                         128 * 1024,
    719                                                         ALIGN(255 * 4092, 1024));
    720 }
    721 
    722 static int __devinit snd_bt87x_create(struct snd_card *card,
    723                                       struct pci_dev *pci,
    724                                       struct snd_bt87x **rchip)
     699        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
     700                                       &chip->pci->dev,
     701                                       128 * 1024,
     702                                       ALIGN(255 * 4092, 1024));
     703        return 0;
     704}
     705
     706static int snd_bt87x_create(struct snd_card *card,
     707                            struct pci_dev *pci,
     708                            struct snd_bt87x **rchip)
    725709{
    726710        struct snd_bt87x *chip;
    727711        int err;
    728         static struct snd_device_ops ops = {
     712        static const struct snd_device_ops ops = {
    729713                .dev_free = snd_bt87x_dev_free
    730714        };
     
    753737        chip->mmio = pci_ioremap_bar(pci, 0);
    754738        if (!chip->mmio) {
    755                 snd_printk(KERN_ERR "cannot remap io memory\n");
     739                dev_err(card->dev, "cannot remap io memory\n");
    756740                err = -ENOMEM;
    757741                goto fail;
     
    766750
    767751        err = request_irq(pci->irq, snd_bt87x_interrupt, IRQF_SHARED,
    768                           "Bt87x audio", chip);
     752                          KBUILD_MODNAME, chip);
    769753        if (err < 0) {
    770                 snd_printk(KERN_ERR "cannot grab irq %d\n", pci->irq);
     754                dev_err(card->dev, "cannot grab irq %d\n", pci->irq);
    771755                goto fail;
    772756        }
    773757        chip->irq = pci->irq;
     758        card->sync_irq = chip->irq;
    774759        pci_set_master(pci);
    775         synchronize_irq(chip->irq);
    776760
    777761        err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
     
    779763                goto fail;
    780764
    781         snd_card_set_dev(card, &pci->dev);
    782765        *rchip = chip;
    783766        return 0;
     
    795778/* driver_data is the card id for that device */
    796779
    797 static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_ids) = {
     780static const struct pci_device_id snd_bt87x_ids[] = {
    798781        /* Hauppauge WinTV series */
    799782        BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0x13eb, GENERIC),
     
    828811static struct {
    829812        unsigned short subvendor, subdevice;
    830 } blacklist[] __devinitdata = {
     813} denylist[] = {
    831814        {0x0071, 0x0101}, /* Nebula Electronics DigiTV */
    832815        {0x11bd, 0x001c}, /* Pinnacle PCTV Sat */
     
    844827static struct pci_driver driver;
    845828
    846 /* return the id of the card, or a negative value if it's blacklisted */
    847 static int __devinit snd_bt87x_detect_card(struct pci_dev *pci)
     829/* return the id of the card, or a negative value if it's on the denylist */
     830static int snd_bt87x_detect_card(struct pci_dev *pci)
    848831{
    849832        int i;
    850833        const struct pci_device_id *supported;
    851 #ifdef TARGET_OS2
    852         u16 subsystem_vendor, subsystem_device;
    853 #endif
    854 
    855 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
     834
    856835        supported = pci_match_id(snd_bt87x_ids, pci);
    857 #else
    858         supported = pci_match_device(snd_bt87x_ids, pci);
    859 #endif
    860836        if (supported && supported->driver_data > 0)
    861837                return supported->driver_data;
    862838
    863 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 0)
    864         subsystem_vendor = pci->subsystem_vendor;
    865         subsystem_device = pci->subsystem_device;
    866 #else
    867         pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
    868         pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
    869 #endif
    870         for (i = 0; i < ARRAY_SIZE(blacklist); ++i)
    871 #ifndef TARGET_OS2
    872                 if (blacklist[i].subvendor == pci->subsystem_vendor &&
    873                     blacklist[i].subdevice == pci->subsystem_device) {
    874 #else
    875                 if (blacklist[i].subvendor == subsystem_vendor &&
    876                     blacklist[i].subdevice == subsystem_device) {
    877 #endif
    878                         snd_printdd(KERN_INFO "card %#04x-%#04x:%#04x has no audio\n",
    879 #ifndef TARGET_OS2
     839        for (i = 0; i < ARRAY_SIZE(denylist); ++i)
     840                if (denylist[i].subvendor == pci->subsystem_vendor &&
     841                    denylist[i].subdevice == pci->subsystem_device) {
     842                        dev_dbg(&pci->dev,
     843                                "card %#04x-%#04x:%#04x has no audio\n",
    880844                                    pci->device, pci->subsystem_vendor, pci->subsystem_device);
    881 #else
    882                                     pci->device, subsystem_vendor, subsystem_device);
    883 #endif
    884845                        return -EBUSY;
    885846                }
    886847
    887         snd_printk(KERN_INFO "unknown card %#04x-%#04x:%#04x\n",
    888 #ifndef TARGET_OS2
     848        dev_info(&pci->dev, "unknown card %#04x-%#04x:%#04x\n",
    889849                   pci->device, pci->subsystem_vendor, pci->subsystem_device);
    890 #else
    891                    pci->device, subsystem_vendor, subsystem_device);
    892 #endif
    893         snd_printk(KERN_DEBUG "please mail id, board name, and, "
     850        dev_info(&pci->dev, "please mail id, board name, and, "
    894851                   "if it works, the correct digital_rate option to "
    895852                   "<alsa-devel@alsa-project.org>\n");
     
    897854}
    898855
    899 static int __devinit snd_bt87x_probe(struct pci_dev *pci,
    900                                      const struct pci_device_id *pci_id)
     856static int snd_bt87x_probe(struct pci_dev *pci,
     857                           const struct pci_device_id *pci_id)
    901858{
    902859        static int dev;
     
    921878        }
    922879
    923         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     880        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     881                           0, &card);
    924882        if (err < 0)
    925883                return err;
     
    958916                        goto _error;
    959917        }
    960         snd_printk(KERN_INFO "bt87x%d: Using board %d, %sanalog, %sdigital "
     918        dev_info(card->dev, "bt87x%d: Using board %d, %sanalog, %sdigital "
    961919                   "(rate %d Hz)\n", dev, boardid,
    962920                   chip->board.no_analog ? "no " : "",
     
    983941}
    984942
    985 static void __devexit snd_bt87x_remove(struct pci_dev *pci)
     943static void snd_bt87x_remove(struct pci_dev *pci)
    986944{
    987945        snd_card_free(pci_get_drvdata(pci));
    988         pci_set_drvdata(pci, NULL);
    989946}
    990947
    991948/* default entries for all Bt87x cards - it's not exported */
    992949/* driver_data is set to 0 to call detection */
    993 static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_default_ids) = {
     950static const struct pci_device_id snd_bt87x_default_ids[] = {
    994951        BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
    995952        BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
     
    998955
    999956static struct pci_driver driver = {
    1000         .name = "Bt87x",
     957        .name = KBUILD_MODNAME,
    1001958        .id_table = snd_bt87x_ids,
    1002959        .probe = snd_bt87x_probe,
    1003         .remove = __devexit_p(snd_bt87x_remove),
     960        .remove = snd_bt87x_remove,
    1004961};
    1005962
Note: See TracChangeset for help on using the changeset viewer.