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

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  card-als4000.c - driver for Avance Logic ALS4000 based soundcards.
     
    67 *
    78 *  Framework borrowed from Massimo Piccioni's card-als100.c.
    8  *
    9  *
    10  *  This program is free software; you can redistribute it and/or modify
    11  *  it under the terms of the GNU General Public License as published by
    12  *  the Free Software Foundation; either version 2 of the License, or
    13  *  (at your option) any later version.
    14  *
    15  *  This program is distributed in the hope that it will be useful,
    16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  *  GNU General Public License for more details.
    19 
    20  *  You should have received a copy of the GNU General Public License
    21  *  along with this program; if not, write to the Free Software
    22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    239 *
    2410 * NOTES
     
    6652 */
    6753
    68 #include <asm/io.h>
     54#include <linux/io.h>
    6955#include <linux/init.h>
    7056#include <linux/pci.h>
    7157#include <linux/gameport.h>
    72 #include <linux/moduleparam.h>
     58#include <linux/module.h>
    7359#include <linux/dma-mapping.h>
    7460#include <sound/core.h>
     
    8066#include <sound/initval.h>
    8167
     68#ifdef TARGET_OS2
     69#define KBUILD_MODNAME "als4000"
     70#endif
    8271MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>, Andreas Mohr");
    8372MODULE_DESCRIPTION("Avance Logic ALS4000");
     
    8574MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}");
    8675
    87 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     76#if IS_REACHABLE(CONFIG_GAMEPORT)
    8877#define SUPPORT_JOYSTICK 1
    8978#endif
     
    9180static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    9281static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    93 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     82static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    9483#ifdef SUPPORT_JOYSTICK
    9584static int joystick_port[SNDRV_CARDS];
     
    10392MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard.");
    10493#ifdef SUPPORT_JOYSTICK
    105 module_param_array(joystick_port, int, NULL, 0444);
     94module_param_hw_array(joystick_port, int, ioport, NULL, 0444);
    10695MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)");
    10796#endif
     
    117106};
    118107
    119 static DEFINE_PCI_DEVICE_TABLE(snd_als4000_ids) = {
     108static const struct pci_device_id snd_als4000_ids[] = {
    120109        { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* ALS4000 */
    121110        { 0, }
     
    369358#define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
    370359
    371 static int snd_als4000_hw_params(struct snd_pcm_substream *substream,
    372                                  struct snd_pcm_hw_params *hw_params)
    373 {
    374         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    375 }
    376 
    377 static int snd_als4000_hw_free(struct snd_pcm_substream *substream)
    378 {
    379         snd_pcm_lib_free_pages(substream);
    380         return 0;
    381 }
    382 
    383360static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream)
    384361{
     
    579556                                        ALS4K_IOB_16_ACK_FOR_CR1E);
    580557
    581         /* printk(KERN_INFO "als4000: irq 0x%04x 0x%04x\n",
     558        /* dev_dbg(chip->card->dev, "als4000: irq 0x%04x 0x%04x\n",
    582559                                         pci_irqstatus, sb_irqstatus); */
    583560
     
    593570/*****************************************************************/
    594571
    595 static struct snd_pcm_hardware snd_als4000_playback =
     572static const struct snd_pcm_hardware snd_als4000_playback =
    596573{
    597574        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    612589};
    613590
    614 static struct snd_pcm_hardware snd_als4000_capture =
     591static const struct snd_pcm_hardware snd_als4000_capture =
    615592{
    616593        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    648625
    649626        chip->playback_substream = NULL;
    650         snd_pcm_lib_free_pages(substream);
    651627        return 0;
    652628}
     
    667643
    668644        chip->capture_substream = NULL;
    669         snd_pcm_lib_free_pages(substream);
    670645        return 0;
    671646}
     
    673648/******************************************************************/
    674649
    675 static struct snd_pcm_ops snd_als4000_playback_ops = {
     650static const struct snd_pcm_ops snd_als4000_playback_ops = {
    676651        .open =         snd_als4000_playback_open,
    677652        .close =        snd_als4000_playback_close,
    678         .ioctl =        snd_pcm_lib_ioctl,
    679         .hw_params =    snd_als4000_hw_params,
    680         .hw_free =      snd_als4000_hw_free,
    681653        .prepare =      snd_als4000_playback_prepare,
    682654        .trigger =      snd_als4000_playback_trigger,
     
    684656};
    685657
    686 static struct snd_pcm_ops snd_als4000_capture_ops = {
     658static const struct snd_pcm_ops snd_als4000_capture_ops = {
    687659        .open =         snd_als4000_capture_open,
    688660        .close =        snd_als4000_capture_close,
    689         .ioctl =        snd_pcm_lib_ioctl,
    690         .hw_params =    snd_als4000_hw_params,
    691         .hw_free =      snd_als4000_hw_free,
    692661        .prepare =      snd_als4000_capture_prepare,
    693662        .trigger =      snd_als4000_capture_trigger,
     
    695664};
    696665
    697 static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device)
     666static int snd_als4000_pcm(struct snd_sb *chip, int device)
    698667{
    699668        struct snd_pcm *pcm;
     
    708677        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops);
    709678
    710         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
    711                                               64*1024, 64*1024);
     679        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
     680                                       &chip->pci->dev, 64*1024, 64*1024);
    712681
    713682        chip->pcm = pcm;
     
    771740
    772741#ifdef SUPPORT_JOYSTICK
    773 static int __devinit snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
     742static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
    774743{
    775744        struct gameport *gp;
     
    792761
    793762        if (!r) {
    794                 printk(KERN_WARNING "als4000: cannot reserve joystick ports\n");
     763                dev_warn(&acard->pci->dev, "cannot reserve joystick ports\n");
    795764                return -EBUSY;
    796765        }
     
    798767        acard->gameport = gp = gameport_allocate_port();
    799768        if (!gp) {
    800                 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n");
     769                dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n");
    801770                release_and_free_resource(r);
    802771                return -ENOMEM;
     
    848817}
    849818
    850 static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
    851                                           const struct pci_device_id *pci_id)
     819static int snd_card_als4000_probe(struct pci_dev *pci,
     820                                  const struct pci_device_id *pci_id)
    852821{
    853822        static int dev;
     
    872841        }
    873842        /* check, if we can restrict PCI DMA transfers to 24 bits */
    874         if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
    875             pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
    876                 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
     843        if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
     844            dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) {
     845                dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n");
    877846                pci_disable_device(pci);
    878847                return -ENXIO;
     
    889858        pci_set_master(pci);
    890859       
    891         err = snd_card_create(index[dev], id[dev], THIS_MODULE,
    892                               sizeof(*acard) /* private_data: acard */,
    893                               &card);
     860        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     861                           sizeof(*acard) /* private_data: acard */,
     862                           &card);
    894863        if (err < 0) {
    895864                pci_release_regions(pci);
     
    921890        chip->pci = pci;
    922891        chip->alt_port = iobase;
    923         snd_card_set_dev(card, &pci->dev);
    924892
    925893        snd_als4000_configure(chip);
     
    932900        if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
    933901                                        iobase + ALS4K_IOB_30_MIDI_DATA,
    934                                         MPU401_INFO_INTEGRATED,
    935                                         pci->irq, 0, &chip->rmidi)) < 0) {
    936                 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n",
     902                                        MPU401_INFO_INTEGRATED |
     903                                        MPU401_INFO_IRQ_HOOK,
     904                                        -1, &chip->rmidi)) < 0) {
     905                dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n",
    937906                                iobase + ALS4K_IOB_30_MIDI_DATA);
    938907                goto out_err;
     
    955924                                iobase + ALS4K_IOB_12_ADLIB_ADDR2,
    956925                            OPL3_HW_AUTO, 1, &opl3) < 0) {
    957                 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n",
     926                dev_err(&pci->dev, "no OPL device at 0x%lx-0x%lx?\n",
    958927                           iobase + ALS4K_IOB_10_ADLIB_ADDR0,
    959928                           iobase + ALS4K_IOB_12_ADLIB_ADDR2);
     
    981950}
    982951
    983 static void __devexit snd_card_als4000_remove(struct pci_dev *pci)
     952static void snd_card_als4000_remove(struct pci_dev *pci)
    984953{
    985954        snd_card_free(pci_get_drvdata(pci));
    986         pci_set_drvdata(pci, NULL);
    987 }
    988 
    989 #ifdef CONFIG_PM
    990 static int snd_als4000_suspend(struct pci_dev *pci, pm_message_t state)
    991 {
    992         struct snd_card *card = pci_get_drvdata(pci);
     955}
     956
     957#ifdef CONFIG_PM_SLEEP
     958static int snd_als4000_suspend(struct device *dev)
     959{
     960        struct snd_card *card = dev_get_drvdata(dev);
    993961        struct snd_card_als4000 *acard = card->private_data;
    994962        struct snd_sb *chip = acard->chip;
     
    996964        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    997965       
    998         snd_pcm_suspend_all(chip->pcm);
    999966        snd_sbmixer_suspend(chip);
    1000 
    1001         pci_disable_device(pci);
    1002         pci_save_state(pci);
    1003         pci_set_power_state(pci, pci_choose_state(pci, state));
    1004967        return 0;
    1005968}
    1006969
    1007 static int snd_als4000_resume(struct pci_dev *pci)
    1008 {
    1009         struct snd_card *card = pci_get_drvdata(pci);
     970static int snd_als4000_resume(struct device *dev)
     971{
     972        struct snd_card *card = dev_get_drvdata(dev);
    1010973        struct snd_card_als4000 *acard = card->private_data;
    1011974        struct snd_sb *chip = acard->chip;
    1012 
    1013         pci_set_power_state(pci, PCI_D0);
    1014         pci_restore_state(pci);
    1015         if (pci_enable_device(pci) < 0) {
    1016                 printk(KERN_ERR "als4000: pci_enable_device failed, "
    1017                        "disabling device\n");
    1018                 snd_card_disconnect(card);
    1019                 return -EIO;
    1020         }
    1021         pci_set_master(pci);
    1022975
    1023976        snd_als4000_configure(chip);
     
    1033986        return 0;
    1034987}
    1035 #endif /* CONFIG_PM */
    1036 
    1037 
    1038 static struct pci_driver driver = {
    1039         .name = "ALS4000",
     988
     989static SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume);
     990#define SND_ALS4000_PM_OPS      &snd_als4000_pm
     991#else
     992#define SND_ALS4000_PM_OPS      NULL
     993#endif /* CONFIG_PM_SLEEP */
     994
     995static struct pci_driver als4000_driver = {
     996        .name = KBUILD_MODNAME,
    1040997        .id_table = snd_als4000_ids,
    1041998        .probe = snd_card_als4000_probe,
    1042         .remove = __devexit_p(snd_card_als4000_remove),
    1043 #ifdef CONFIG_PM
    1044         .suspend = snd_als4000_suspend,
    1045         .resume = snd_als4000_resume,
    1046 #endif
    1047 };
    1048 
    1049 static int __init alsa_card_als4000_init(void)
    1050 {
    1051         return pci_register_driver(&driver);
    1052 }
    1053 
    1054 static void __exit alsa_card_als4000_exit(void)
    1055 {
    1056         pci_unregister_driver(&driver);
    1057 }
    1058 
    1059 module_init(alsa_card_als4000_init)
    1060 module_exit(alsa_card_als4000_exit)
     999        .remove = snd_card_als4000_remove,
     1000        .driver = {
     1001                .pm = SND_ALS4000_PM_OPS,
     1002        },
     1003};
     1004
     1005module_pci_driver(als4000_driver);
Note: See TracChangeset for help on using the changeset viewer.