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

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

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

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  The driver for the EMU10K1 (SB Live!) based soundcards
     
    56 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
    67 *      Added support for Audigy 2 Value.
    7  *
    8  *
    9  *   This program 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 program 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
    22  *
    23  *
    248 */
    259
     
    2711#include <linux/pci.h>
    2812#include <linux/time.h>
    29 #include <linux/moduleparam.h>
     13#include <linux/module.h>
    3014#include <sound/core.h>
    3115#include <sound/emu10k1.h>
    3216#include <sound/initval.h>
     17
     18#ifdef TARGET_OS2
     19#define KBUILD_MODNAME "emu10k1"
     20#endif
    3321
    3422MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
     
    3826               "{Creative Labs,SB Audigy}}");
    3927
    40 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
     28#if IS_ENABLED(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER)
    4129#define ENABLE_SYNTH
    4230#include <sound/emu10k1_synth.h>
     
    4533static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    4634static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    47 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     35static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    4836static int extin[SNDRV_CARDS];
    4937static int extout[SNDRV_CARDS];
     
    5745static int max_buffer_size[SNDRV_CARDS] = {128,128,128,128,128,128,128,128};
    5846#endif
    59 static int enable_ir[SNDRV_CARDS];
     47static bool enable_ir[SNDRV_CARDS];
    6048static uint subsystem[SNDRV_CARDS]; /* Force card subsystem model */
    6149#ifndef TARGET_OS2
     
    9078 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value  Model:SB0400
    9179 */
    92 static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1_ids) = {
     80static const struct pci_device_id snd_emu10k1_ids[] = {
    9381        { PCI_VDEVICE(CREATIVE, 0x0002), 0 },   /* EMU10K1 */
    9482        { PCI_VDEVICE(CREATIVE, 0x0004), 1 },   /* Audigy */
     
    11098MODULE_DEVICE_TABLE(pci, snd_emu10k1_ids);
    11199
    112 static int __devinit snd_card_emu10k1_probe(struct pci_dev *pci,
    113                                             const struct pci_device_id *pci_id)
     100static int snd_card_emu10k1_probe(struct pci_dev *pci,
     101                                  const struct pci_device_id *pci_id)
    114102{
    115103        static int dev;
     
    128116        }
    129117
    130         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     118        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     119                           0, &card);
    131120        if (err < 0)
    132121                return err;
     
    142131        card->private_data = emu;
    143132        emu->delay_pcm_irq = delay_pcm_irq[dev] & 0x1f;
    144         if ((err = snd_emu10k1_pcm(emu, 0, NULL)) < 0)
    145                 goto error;
    146         if ((err = snd_emu10k1_pcm_mic(emu, 1, NULL)) < 0)
    147                 goto error;
    148         if ((err = snd_emu10k1_pcm_efx(emu, 2, NULL)) < 0)
     133        if ((err = snd_emu10k1_pcm(emu, 0)) < 0)
     134                goto error;
     135        if ((err = snd_emu10k1_pcm_mic(emu, 1)) < 0)
     136                goto error;
     137        if ((err = snd_emu10k1_pcm_efx(emu, 2)) < 0)
    149138                goto error;
    150139        /* This stores the periods table. */
    151140        if (emu->card_capabilities->ca0151_chip) { /* P16V */   
    152                 if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    153                                                1024, &emu->p16v_buffer)) < 0)
     141                err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
     142                                          1024, &emu->p16v_buffer);
     143                if (err < 0)
    154144                        goto error;
    155145        }
     
    161151                goto error;
    162152
    163         if ((err = snd_emu10k1_pcm_multi(emu, 3, NULL)) < 0)
     153        if ((err = snd_emu10k1_pcm_multi(emu, 3)) < 0)
    164154                goto error;
    165155        if (emu->card_capabilities->ca0151_chip) { /* P16V */
    166                 if ((err = snd_p16v_pcm(emu, 4, NULL)) < 0)
     156                if ((err = snd_p16v_pcm(emu, 4)) < 0)
    167157                        goto error;
    168158        }
     
    174164                        goto error;
    175165        }
    176         if ((err = snd_emu10k1_fx8010_new(emu, 0, NULL)) < 0)
     166        if ((err = snd_emu10k1_fx8010_new(emu, 0)) < 0)
    177167                goto error;
    178168#ifdef ENABLE_SYNTH
     
    180170                               sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 ||
    181171            wave == NULL) {
    182                 snd_printk(KERN_WARNING "can't initialize Emu10k1 wavetable synth\n");
     172                dev_warn(emu->card->dev,
     173                         "can't initialize Emu10k1 wavetable synth\n");
    183174        } else {
    184175                struct snd_emu10k1_synth_arg *arg;
     
    192183#endif
    193184 
    194         strcpy(card->driver, emu->card_capabilities->driver);
    195         strcpy(card->shortname, emu->card_capabilities->name);
     185        strlcpy(card->driver, emu->card_capabilities->driver,
     186                sizeof(card->driver));
     187        strlcpy(card->shortname, emu->card_capabilities->name,
     188                sizeof(card->shortname));
    196189        snprintf(card->longname, sizeof(card->longname),
    197190                 "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i",
     
    201194                goto error;
    202195
     196        if (emu->card_capabilities->emu_model)
     197                schedule_delayed_work(&emu->emu1010.firmware_work, 0);
     198
    203199        pci_set_drvdata(pci, card);
    204200        dev++;
     
    210206}
    211207
    212 static void __devexit snd_card_emu10k1_remove(struct pci_dev *pci)
     208static void snd_card_emu10k1_remove(struct pci_dev *pci)
    213209{
    214210        snd_card_free(pci_get_drvdata(pci));
    215         pci_set_drvdata(pci, NULL);
    216 }
    217 
    218 
    219 #ifdef CONFIG_PM
    220 static int snd_emu10k1_suspend(struct pci_dev *pci, pm_message_t state)
    221 {
    222         struct snd_card *card = pci_get_drvdata(pci);
     211}
     212
     213
     214#ifdef CONFIG_PM_SLEEP
     215static int snd_emu10k1_suspend(struct device *dev)
     216{
     217        struct snd_card *card = dev_get_drvdata(dev);
    223218        struct snd_emu10k1 *emu = card->private_data;
    224219
    225220        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    226221
    227         snd_pcm_suspend_all(emu->pcm);
    228         snd_pcm_suspend_all(emu->pcm_mic);
    229         snd_pcm_suspend_all(emu->pcm_efx);
    230         snd_pcm_suspend_all(emu->pcm_multi);
    231         snd_pcm_suspend_all(emu->pcm_p16v);
     222        emu->suspend = 1;
     223
     224        cancel_delayed_work_sync(&emu->emu1010.firmware_work);
    232225
    233226        snd_ac97_suspend(emu->ac97);
     
    239232
    240233        snd_emu10k1_done(emu);
    241 
    242         pci_disable_device(pci);
    243         pci_save_state(pci);
    244         pci_set_power_state(pci, pci_choose_state(pci, state));
    245234        return 0;
    246235}
    247236
    248 static int snd_emu10k1_resume(struct pci_dev *pci)
    249 {
    250         struct snd_card *card = pci_get_drvdata(pci);
     237static int snd_emu10k1_resume(struct device *dev)
     238{
     239        struct snd_card *card = dev_get_drvdata(dev);
    251240        struct snd_emu10k1 *emu = card->private_data;
    252 
    253         pci_set_power_state(pci, PCI_D0);
    254         pci_restore_state(pci);
    255         if (pci_enable_device(pci) < 0) {
    256                 printk(KERN_ERR "emu10k1: pci_enable_device failed, "
    257                        "disabling device\n");
    258                 snd_card_disconnect(card);
    259                 return -EIO;
    260         }
    261         pci_set_master(pci);
    262241
    263242        snd_emu10k1_resume_init(emu);
     
    269248                snd_p16v_resume(emu);
    270249
     250        emu->suspend = 0;
     251
    271252        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     253
     254        if (emu->card_capabilities->emu_model)
     255                schedule_delayed_work(&emu->emu1010.firmware_work, 0);
     256
    272257        return 0;
    273258}
    274 #endif
    275 
    276 static struct pci_driver driver = {
    277         .name = "EMU10K1_Audigy",
     259
     260static SIMPLE_DEV_PM_OPS(snd_emu10k1_pm, snd_emu10k1_suspend, snd_emu10k1_resume);
     261#define SND_EMU10K1_PM_OPS      &snd_emu10k1_pm
     262#else
     263#define SND_EMU10K1_PM_OPS      NULL
     264#endif /* CONFIG_PM_SLEEP */
     265
     266static struct pci_driver emu10k1_driver = {
     267        .name = KBUILD_MODNAME,
    278268        .id_table = snd_emu10k1_ids,
    279269        .probe = snd_card_emu10k1_probe,
    280         .remove = __devexit_p(snd_card_emu10k1_remove),
    281 #ifdef CONFIG_PM
    282         .suspend = snd_emu10k1_suspend,
    283         .resume = snd_emu10k1_resume,
    284 #endif
     270        .remove = snd_card_emu10k1_remove,
     271        .driver = {
     272                .pm = SND_EMU10K1_PM_OPS,
     273        },
    285274};
    286275
    287 static int __init alsa_card_emu10k1_init(void)
    288 {
    289         return pci_register_driver(&driver);
    290 }
    291 
    292 static void __exit alsa_card_emu10k1_exit(void)
    293 {
    294         pci_unregister_driver(&driver);
    295 }
    296 
    297 module_init(alsa_card_emu10k1_init)
    298 module_exit(alsa_card_emu10k1_exit)
     276module_pci_driver(emu10k1_driver);
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_callback.c

    r426 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  synth callback routines for Emu10k1
    34 *
    45 *  Copyright (C) 2000 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 */
     7
     8#include <linux/export.h>
    219#include "emu10k1_synth_local.h"
    2210#include <sound/asoundef.h>
     
    6149 * set up operators
    6250 */
    63 static struct snd_emux_operators emu10k1_ops = {
     51static const struct snd_emux_operators emu10k1_ops = {
    6452        .owner =        THIS_MODULE,
    6553        .get_voice =    get_voice,
     
    8573 *
    8674 * terminate most inactive voice and give it as a pcm voice.
     75 *
     76 * voice_lock is already held.
    8777 */
    8878int
     
    9282        struct snd_emux_voice *vp;
    9383        struct best_voice best[V_END];
    94         unsigned long flags;
    9584        int i;
    9685
    9786        emu = hw->synth;
    9887
    99         spin_lock_irqsave(&emu->voice_lock, flags);
    10088        lookup_voices(emu, hw, best, 1); /* no OFF voices */
    10189        for (i = 0; i < V_END; i++) {
     
    10593                        if ((ch = vp->ch) < 0) {
    10694                                /*
    107                                 printk(KERN_WARNING
     95                                dev_warn(emu->card->dev,
    10896                                       "synth_get_voice: ch < 0 (%d) ??", i);
    10997                                */
     
    113101                        vp->ch = -1;
    114102                        vp->state = SNDRV_EMUX_ST_OFF;
    115                         spin_unlock_irqrestore(&emu->voice_lock, flags);
    116103                        return ch;
    117104                }
    118105        }
    119         spin_unlock_irqrestore(&emu->voice_lock, flags);
    120106
    121107        /* not found */
     
    228214
    229215        for (i = 0; i < V_END; i++) {
    230                 best[i].time = (unsigned int)-1; /* XXX MAX_?INT really */;
     216                best[i].time = (unsigned int)-1; /* XXX MAX_?INT really */
    231217                best[i].voice = -1;
    232218        }
     
    339325        emem->map_locked++;
    340326        if (snd_emu10k1_memblk_map(hw, emem) < 0) {
    341                 /* printk(KERN_ERR "emu: cannot map!\n"); */
     327                /* dev_err(hw->card->devK, "emu: cannot map!\n"); */
    342328                return -ENOMEM;
    343329        }
     
    417403
    418404        /* invalidate maps */
    419         temp = (hw->silent_page.addr << 1) | MAP_PTI_MASK;
     405        temp = (hw->silent_page.addr << hw->address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
    420406        snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
    421407        snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
     
    438424
    439425                /* invalidate maps */
    440                 temp = ((unsigned int)hw->silent_page.addr << 1) | MAP_PTI_MASK;
     426                temp = ((unsigned int)hw->silent_page.addr << hw_address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
    441427                snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
    442428                snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_main.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    910 *      General bug fixes and enhancements.
    1011 *
    11  *
    1212 *  BUGS:
    1313 *    --
     
    1515 *  TODO:
    1616 *    --
    17  *
    18  *   This program is free software; you can redistribute it and/or modify
    19  *   it under the terms of the GNU General Public License as published by
    20  *   the Free Software Foundation; either version 2 of the License, or
    21  *   (at your option) any later version.
    22  *
    23  *   This program is distributed in the hope that it will be useful,
    24  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    25  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    26  *   GNU General Public License for more details.
    27  *
    28  *   You should have received a copy of the GNU General Public License
    29  *   along with this program; if not, write to the Free Software
    30  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    31  *
    3217 */
    3318
     19#ifdef TARGET_OS2
     20#define KBUILD_MODNAME "emu10k1"
     21#include <linux/dma-mapping.h>
     22#endif
     23
    3424#include <linux/sched.h>
    35 #include <linux/kthread.h>
    3625#include <linux/delay.h>
    3726#include <linux/init.h>
     27#include <linux/module.h>
    3828#include <linux/interrupt.h>
     29#include <linux/iommu.h>
    3930#include <linux/pci.h>
    4031#include <linux/slab.h>
     
    118109}
    119110
    120 static unsigned int spi_dac_init[] = {
     111static const unsigned int spi_dac_init[] = {
    121112                0x00ff,
    122113                0x02ff,
     
    142133};
    143134
    144 static unsigned int i2c_adc_init[][2] = {
     135static const unsigned int i2c_adc_init[][2] = {
    145136        { 0x17, 0x00 }, /* Reset */
    146137        { 0x07, 0x00 }, /* Timeout */
     
    220211        if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
    221212                /* Hacks for Alice3 to work independent of haP16V driver */
    222                 snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
     213                dev_info(emu->card->dev, "Audigy2 value: Special config.\n");
    223214                /* Setup SRCMulti_I2S SamplingRate */
    224215                tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
     
    285276        snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
    286277
    287         silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
     278        silent_page = (emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
    288279        for (ch = 0; ch < NUM_G; ch++) {
    289280                snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
     
    351342        }
    352343
     344        if (emu->address_mode == 0) {
     345                /* use 16M in 4G */
     346                outl(inl(emu->port + HCFG) | HCFG_EXPANDED_MEM, emu->port + HCFG);
     347        }
     348
    353349        return 0;
    354350}
     
    636632{
    637633        unsigned long special_port;
    638         unsigned int value;
     634        __always_unused unsigned int value;
    639635
    640636        /* Special initialisation routine
     
    660656}
    661657
    662 static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, const char *filename)
     658static int snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,
     659                                     const struct firmware *fw_entry)
    663660{
    664         int err;
    665661        int n, i;
    666662        int reg;
    667663        int value;
    668         unsigned int write_post;
     664        __always_unused unsigned int write_post;
    669665        unsigned long flags;
    670         const struct firmware *fw_entry;
    671 
    672         err = request_firmware(&fw_entry, filename, &emu->pci->dev);
    673         if (err != 0) {
    674                 snd_printk(KERN_ERR "firmware: %s not found. Err = %d\n", filename, err);
    675                 return err;
    676         }
    677         snd_printk(KERN_INFO "firmware size = 0x%zx\n", fw_entry->size);
     666
     667        if (!fw_entry)
     668                return -EIO;
    678669
    679670        /* The FPGA is a Xilinx Spartan IIE XC2S50E */
     
    708699        spin_unlock_irqrestore(&emu->emu_lock, flags);
    709700
    710         release_firmware(fw_entry);
    711701        return 0;
    712702}
    713703
    714 #if kthread_create != 0 /* DAZ to stop compiler warning */
    715 static int emu1010_firmware_thread(void *data)
     704/* firmware file names, per model, init-fw and dock-fw (optional) */
     705static const char * const firmware_names[5][2] = {
     706        [EMU_MODEL_EMU1010] = {
     707                HANA_FILENAME, DOCK_FILENAME
     708        },
     709        [EMU_MODEL_EMU1010B] = {
     710                EMU1010B_FILENAME, MICRO_DOCK_FILENAME
     711        },
     712        [EMU_MODEL_EMU1616] = {
     713                EMU1010_NOTEBOOK_FILENAME, MICRO_DOCK_FILENAME
     714        },
     715        [EMU_MODEL_EMU0404] = {
     716                EMU0404_FILENAME, NULL
     717        },
     718};
     719
     720static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, int dock,
     721                                     const struct firmware **fw)
    716722{
    717         struct snd_emu10k1 *emu = data;
     723        const char *filename;
     724        int err;
     725
     726        if (!*fw) {
     727                filename = firmware_names[emu->card_capabilities->emu_model][dock];
     728                if (!filename)
     729                        return 0;
     730                err = request_firmware(fw, filename, &emu->pci->dev);
     731                if (err)
     732                        return err;
     733        }
     734
     735        return snd_emu1010_load_firmware_entry(emu, *fw);
     736}
     737
     738static void emu1010_firmware_work(struct work_struct *work)
     739{
     740        struct snd_emu10k1 *emu;
    718741        u32 tmp, tmp2, reg;
    719742        int err;
    720743
    721         for (;;) {
    722                 /* Delay to allow Audio Dock to settle */
    723                 msleep_interruptible(1000);
    724                 if (kthread_should_stop())
    725                         break;
    726                 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp); /* IRQ Status */
    727                 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); /* OPTIONS: Which cards are attached to the EMU */
    728                 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
    729                         /* Audio Dock attached */
    730                         /* Return to Audio Dock programming mode */
    731                         snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
    732                         snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK);
    733                         if (emu->card_capabilities->emu_model ==
    734                             EMU_MODEL_EMU1010) {
    735                                 err = snd_emu1010_load_firmware(emu, DOCK_FILENAME);
    736                                 if (err != 0)
    737                                         continue;
    738                         } else if (emu->card_capabilities->emu_model ==
    739                                    EMU_MODEL_EMU1010B) {
    740                                 err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
    741                                 if (err != 0)
    742                                         continue;
    743                         } else if (emu->card_capabilities->emu_model ==
    744                                    EMU_MODEL_EMU1616) {
    745                                 err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
    746                                 if (err != 0)
    747                                         continue;
    748                         }
    749 
    750                         snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0);
    751                         snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg);
    752                         snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n", reg);
    753                         /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
    754                         snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
    755                         snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", reg);
    756                         if ((reg & 0x1f) != 0x15) {
    757                                 /* FPGA failed to be programmed */
    758                                 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n", reg);
    759                                 continue;
    760                         }
    761                         snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
    762                         snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
    763                         snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
    764                         snd_printk(KERN_INFO "Audio Dock ver: %u.%u\n",
    765                                    tmp, tmp2);
    766                         /* Sync clocking between 1010 and Dock */
    767                         /* Allow DLL to settle */
    768                         msleep(10);
    769                         /* Unmute all. Default is muted after a firmware load */
    770                         snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
     744        emu = container_of(work, struct snd_emu10k1,
     745                           emu1010.firmware_work.work);
     746        if (emu->card->shutdown)
     747                return;
     748#ifdef CONFIG_PM_SLEEP
     749        if (emu->suspend)
     750                return;
     751#endif
     752        snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp); /* IRQ Status */
     753        snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); /* OPTIONS: Which cards are attached to the EMU */
     754        if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
     755                /* Audio Dock attached */
     756                /* Return to Audio Dock programming mode */
     757                dev_info(emu->card->dev,
     758                         "emu1010: Loading Audio Dock Firmware\n");
     759                snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG,
     760                                       EMU_HANA_FPGA_CONFIG_AUDIODOCK);
     761                err = snd_emu1010_load_firmware(emu, 1, &emu->dock_fw);
     762                if (err < 0)
     763                        goto next;
     764
     765                snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0);
     766                snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp);
     767                dev_info(emu->card->dev,
     768                         "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n", tmp);
     769                /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
     770                snd_emu1010_fpga_read(emu, EMU_HANA_ID, &tmp);
     771                dev_info(emu->card->dev,
     772                         "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", tmp);
     773                if ((tmp & 0x1f) != 0x15) {
     774                        /* FPGA failed to be programmed */
     775                        dev_info(emu->card->dev,
     776                                 "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n",
     777                                 tmp);
     778                        goto next;
    771779                }
    772         }
    773         snd_printk(KERN_INFO "emu1010: firmware thread stopping\n");
    774         return 0;
     780                dev_info(emu->card->dev,
     781                         "emu1010: Audio Dock Firmware loaded\n");
     782                snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
     783                snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
     784                dev_info(emu->card->dev, "Audio Dock ver: %u.%u\n", tmp, tmp2);
     785                /* Sync clocking between 1010 and Dock */
     786                /* Allow DLL to settle */
     787                msleep(10);
     788                /* Unmute all. Default is muted after a firmware load */
     789                snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
     790        } else if (!reg && emu->emu1010.last_reg) {
     791                /* Audio Dock removed */
     792                dev_info(emu->card->dev, "emu1010: Audio Dock detached\n");
     793                /* Unmute all */
     794                snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
     795        }
     796
     797 next:
     798        emu->emu1010.last_reg = reg;
     799        if (!emu->card->shutdown)
     800                schedule_delayed_work(&emu->emu1010.firmware_work,
     801                                      msecs_to_jiffies(1000));
    775802}
    776 #endif
     803//#endif
    777804
    778805/*
     
    812839        u32 tmp, tmp2, reg;
    813840        int err;
    814         const char *filename = NULL;
    815 
    816         snd_printk(KERN_INFO "emu1010: Special config.\n");
     841
     842        dev_info(emu->card->dev, "emu1010: Special config.\n");
    817843        /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
    818844         * Lock Sound Memory Cache, Lock Tank Memory Cache,
     
    839865        /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
    840866        snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
    841         snd_printdd("reg1 = 0x%x\n", reg);
     867        dev_dbg(emu->card->dev, "reg1 = 0x%x\n", reg);
    842868        if ((reg & 0x3f) == 0x15) {
    843869                /* FPGA netlist already present so clear it */
     
    847873        }
    848874        snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
    849         snd_printdd("reg2 = 0x%x\n", reg);
     875        dev_dbg(emu->card->dev, "reg2 = 0x%x\n", reg);
    850876        if ((reg & 0x3f) == 0x15) {
    851877                /* FPGA failed to return to programming mode */
    852                 snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n");
     878                dev_info(emu->card->dev,
     879                         "emu1010: FPGA failed to return to programming mode\n");
    853880                return -ENODEV;
    854881        }
    855         snd_printk(KERN_INFO "emu1010: EMU_HANA_ID = 0x%x\n", reg);
    856         switch (emu->card_capabilities->emu_model) {
    857         case EMU_MODEL_EMU1010:
    858                 filename = HANA_FILENAME;
    859                 break;
    860         case EMU_MODEL_EMU1010B:
    861                 filename = EMU1010B_FILENAME;
    862                 break;
    863         case EMU_MODEL_EMU1616:
    864                 filename = EMU1010_NOTEBOOK_FILENAME;
    865                 break;
    866         case EMU_MODEL_EMU0404:
    867                 filename = EMU0404_FILENAME;
    868                 break;
    869         default:
    870                 filename = NULL;
    871                 return -ENODEV;
    872                 break;
    873         }
    874         snd_printk(KERN_INFO "emu1010: filename %s testing\n", filename);
    875         err = snd_emu1010_load_firmware(emu, filename);
    876         if (err != 0) {
    877                 snd_printk(
    878                         KERN_INFO "emu1010: Loading Firmware file %s failed\n",
    879                         filename);
     882        dev_info(emu->card->dev, "emu1010: EMU_HANA_ID = 0x%x\n", reg);
     883
     884        err = snd_emu1010_load_firmware(emu, 0, &emu->firmware);
     885        if (err < 0) {
     886                dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n");
    880887                return err;
    881888        }
     
    885892        if ((reg & 0x3f) != 0x15) {
    886893                /* FPGA failed to be programmed */
    887                 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n", reg);
     894                dev_info(emu->card->dev,
     895                         "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n",
     896                         reg);
    888897                return -ENODEV;
    889898        }
    890899
    891         snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
     900        dev_info(emu->card->dev, "emu1010: Hana Firmware loaded\n");
    892901        snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp);
    893902        snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2);
    894         snd_printk(KERN_INFO "emu1010: Hana version: %u.%u\n", tmp, tmp2);
     903        dev_info(emu->card->dev, "emu1010: Hana version: %u.%u\n", tmp, tmp2);
    895904        /* Enable 48Volt power to Audio Dock */
    896905        snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON);
    897906
    898907        snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
    899         snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
     908        dev_info(emu->card->dev, "emu1010: Card options = 0x%x\n", reg);
    900909        snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
    901         snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
     910        dev_info(emu->card->dev, "emu1010: Card options = 0x%x\n", reg);
    902911        snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp);
    903912        /* Optical -> ADAT I/O  */
     
    932941        /* Unknown. */
    933942        snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c);
    934         /* IRQ Enable: Alll on */
     943        /* IRQ Enable: All on */
    935944        /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); */
    936945        /* IRQ Enable: All off */
     
    938947
    939948        snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
    940         snd_printk(KERN_INFO "emu1010: Card options3 = 0x%x\n", reg);
     949        dev_info(emu->card->dev, "emu1010: Card options3 = 0x%x\n", reg);
    941950        /* Default WCLK set to 48kHz. */
    942951        snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00);
     
    10961105        snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp);
    10971106        snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10); /* SPDIF Format spdif  (or 0x11 for aes/ebu) */
    1098 
    1099         /* Start Micro/Audio Dock firmware loader thread */
    1100         if (!emu->emu1010.firmware_thread) {
    1101                 emu->emu1010.firmware_thread =
    1102                         kthread_create(emu1010_firmware_thread, emu,
    1103                                        "emu1010_firmware");
    1104                 wake_up_process(emu->emu1010.firmware_thread);
    1105         }
    11061107
    11071108#if 0
     
    12461247 */
    12471248
    1248 #ifdef CONFIG_PM
     1249#ifdef CONFIG_PM_SLEEP
    12491250static int alloc_pm_buffer(struct snd_emu10k1 *emu);
    12501251static void free_pm_buffer(struct snd_emu10k1 *emu);
     
    12621263                snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
    12631264        }
    1264         if (emu->emu1010.firmware_thread)
    1265                 kthread_stop(emu->emu1010.firmware_thread);
     1265        cancel_delayed_work_sync(&emu->emu1010.firmware_work);
     1266        release_firmware(emu->firmware);
     1267        release_firmware(emu->dock_fw);
    12661268        if (emu->irq >= 0)
    12671269                free_irq(emu->irq, emu);
    1268         /* remove reserved page */
    1269         if (emu->reserved_page) {
    1270                 snd_emu10k1_synth_free(emu,
    1271                         (struct snd_util_memblk *)emu->reserved_page);
    1272                 emu->reserved_page = NULL;
    1273         }
    1274         if (emu->memhdr)
    1275                 snd_util_memhdr_free(emu->memhdr);
     1270        snd_util_memhdr_free(emu->memhdr);
    12761271        if (emu->silent_page.area)
    12771272                snd_dma_free_pages(&emu->silent_page);
     
    12801275        vfree(emu->page_ptr_table);
    12811276        vfree(emu->page_addr_table);
    1282 #ifdef CONFIG_PM
     1277#ifdef CONFIG_PM_SLEEP
    12831278        free_pm_buffer(emu);
    12841279#endif
     
    12981293}
    12991294
    1300 static struct snd_emu_chip_details emu_chip_details[] = {
     1295static const struct snd_emu_chip_details emu_chip_details[] = {
     1296        /* Audigy 5/Rx SB1550 */
     1297        /* Tested by michael@gernoth.net 28 Mar 2015 */
     1298        /* DSP: CA10300-IAT LF
     1299         * DAC: Cirrus Logic CS4382-KQZ
     1300         * ADC: Philips 1361T
     1301         * AC97: Sigmatel STAC9750
     1302         * CA0151: None
     1303         */
     1304        {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10241102,
     1305         .driver = "Audigy2", .name = "SB Audigy 5/Rx [SB1550]",
     1306         .id = "Audigy2",
     1307         .emu10k2_chip = 1,
     1308         .ca0108_chip = 1,
     1309         .spk71 = 1,
     1310         .adc_1361t = 1,  /* 24 bit capture instead of 16bit */
     1311         .ac97_chip = 1},
    13011312        /* Audigy4 (Not PRO) SB0610 */
    13021313        /* Tested by James@superbug.co.uk 4th April 2006 */
     
    13951406         */
    13961407        {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
    1397          .driver = "Audigy2", .name = "SB Audigy 2 ZS Notebook [SB0530]",
     1408         .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
    13981409         .id = "Audigy2",
    13991410         .emu10k2_chip = 1,
     
    14211432         .spk71 = 1,
    14221433         .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 new revision */
     1434        /* Tested by Maxim Kachur <mcdebugger@duganet.ru> 17th Oct 2012. */
     1435        /* This is MAEM8986, 0202 is MAEM8980 */
     1436        {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40071102,
     1437         .driver = "Audigy2", .name = "E-mu 1010 PCIe [MAEM8986]",
     1438         .id = "EMU1010",
     1439         .emu10k2_chip = 1,
     1440         .ca0108_chip = 1,
     1441         .spk71 = 1,
     1442         .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 PCIe */
    14231443        /* Tested by James@superbug.co.uk 8th July 2005. */
    14241444        /* This is MAEM8810, 0202 is MAEM8820 */
     
    14461466         .spk71 = 1,
    14471467         .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 */
     1468        /* EMU0404 PCIe */
     1469        {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40051102,
     1470         .driver = "Audigy2", .name = "E-mu 0404 PCIe [MAEM8984]",
     1471         .id = "EMU0404",
     1472         .emu10k2_chip = 1,
     1473         .ca0108_chip = 1,
     1474         .spk71 = 1,
     1475         .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 PCIe ver_03 */
    14481476        /* Note that all E-mu cards require kernel 2.6 or newer. */
    14491477        {.vendor = 0x1102, .device = 0x0008,
     
    14691497        {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
    14701498         .driver = "Audigy2", .name = "SB Audigy 2 [SB0350b]",
     1499         .id = "Audigy2",
     1500         .emu10k2_chip = 1,
     1501         .ca0102_chip = 1,
     1502         .ca0151_chip = 1,
     1503         .spk71 = 1,
     1504         .spdif_bug = 1,
     1505         .invert_shared_spdif = 1,      /* digital/analog switch swapped */
     1506         .ac97_chip = 1} ,
     1507        /* 0x20051102 also has SB0350 written on it, treated as Audigy 2 ZS by
     1508           Creative's Windows driver */
     1509        {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20051102,
     1510         .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0350a]",
    14711511         .id = "Audigy2",
    14721512         .emu10k2_chip = 1,
     
    15161556         .ac97_chip = 1} ,
    15171557        {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
    1518          .driver = "Audigy2", .name = "SB Audigy 2 Platinum EX [SB0280]",
     1558         .driver = "Audigy2", .name = "Audigy 2 Platinum EX [SB0280]",
    15191559         .id = "Audigy2",
    15201560         .emu10k2_chip = 1,
     
    17141754};
    17151755
    1716 int __devinit snd_emu10k1_create(struct snd_card *card,
     1756/*
     1757 * The chip (at least the Audigy 2 CA0102 chip, but most likely others, too)
     1758 * has a problem that from time to time it likes to do few DMA reads a bit
     1759 * beyond its normal allocation and gets very confused if these reads get
     1760 * blocked by a IOMMU.
     1761 *
     1762 * This behaviour has been observed for the first (reserved) page
     1763 * (for which it happens multiple times at every playback), often for various
     1764 * synth pages and sometimes for PCM playback buffers and the page table
     1765 * memory itself.
     1766 *
     1767 * As a workaround let's widen these DMA allocations by an extra page if we
     1768 * detect that the device is behind a non-passthrough IOMMU.
     1769 */
     1770static void snd_emu10k1_detect_iommu(struct snd_emu10k1 *emu)
     1771{
     1772        struct iommu_domain *domain;
     1773
     1774        emu->iommu_workaround = false;
     1775
     1776        if (!iommu_present(emu->card->dev->bus))
     1777                return;
     1778
     1779        domain = iommu_get_domain_for_dev(emu->card->dev);
     1780        if (domain && domain->type == IOMMU_DOMAIN_IDENTITY)
     1781                return;
     1782
     1783        dev_notice(emu->card->dev,
     1784                   "non-passthrough IOMMU detected, widening DMA allocations");
     1785        emu->iommu_workaround = true;
     1786}
     1787
     1788int snd_emu10k1_create(struct snd_card *card,
    17171789                       struct pci_dev *pci,
    17181790                       unsigned short extin_mask,
     
    17261798        int idx, err;
    17271799        int is_audigy;
     1800        size_t page_table_size;
     1801        __le32 *pgtbl;
    17281802        unsigned int silent_page;
    17291803        const struct snd_emu_chip_details *c;
    1730         static struct snd_device_ops ops = {
     1804        static const struct snd_device_ops ops = {
    17311805                .dev_free =     snd_emu10k1_dev_free,
    17321806        };
     
    17591833        emu->synth = NULL;
    17601834        emu->get_synth_voice = NULL;
     1835        INIT_DELAYED_WORK(&emu->emu1010.firmware_work, emu1010_firmware_work);
    17611836        /* read revision & serial */
    17621837#ifndef TARGET_OS2
     
    17671842        pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
    17681843        pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
    1769         snd_printdd("vendor = 0x%x, device = 0x%x, subsystem_vendor_id = 0x%x, subsystem_id = 0x%x\n", pci->vendor, pci->device, emu->serial, emu->model);
     1844        dev_dbg(card->dev,
     1845                "vendor = 0x%x, device = 0x%x, subsystem_vendor_id = 0x%x, subsystem_id = 0x%x\n",
     1846                pci->vendor, pci->device, emu->serial, emu->model);
    17701847
    17711848        for (c = emu_chip_details; c->vendor; c++) {
     
    17861863        }
    17871864        if (c->vendor == 0) {
    1788                 snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
     1865                dev_err(card->dev, "emu10k1: Card not recognised\n");
    17891866                kfree(emu);
    17901867                pci_disable_device(pci);
     
    17931870        emu->card_capabilities = c;
    17941871        if (c->subsystem && !subsystem)
    1795                 snd_printdd("Sound card name = %s\n", c->name);
     1872                dev_dbg(card->dev, "Sound card name = %s\n", c->name);
    17961873        else if (subsystem)
    1797                 snd_printdd("Sound card name = %s, "
     1874                dev_dbg(card->dev, "Sound card name = %s, "
    17981875                        "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. "
    17991876                        "Forced to subsystem = 0x%x\n", c->name,
    18001877                        pci->vendor, pci->device, emu->serial, c->subsystem);
    18011878        else
    1802                 snd_printdd("Sound card name = %s, "
     1879                dev_dbg(card->dev, "Sound card name = %s, "
    18031880                        "vendor = 0x%x, device = 0x%x, subsystem = 0x%x.\n",
    18041881                        c->name, pci->vendor, pci->device,
    18051882                        emu->serial);
    18061883
    1807         if (!*card->id && c->id) {
    1808                 int i, n = 0;
     1884        if (!*card->id && c->id)
    18091885                strlcpy(card->id, c->id, sizeof(card->id));
    1810                 for (;;) {
    1811                         for (i = 0; i < snd_ecards_limit; i++) {
    1812                                 if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
    1813                                         break;
    1814                         }
    1815                         if (i >= snd_ecards_limit)
    1816                                 break;
    1817                         n++;
    1818                         if (n >= SNDRV_CARDS)
    1819                                 break;
    1820                         snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
    1821                 }
    1822         }
    18231886
    18241887        is_audigy = emu->audigy = c->emu10k2_chip;
    18251888
     1889        snd_emu10k1_detect_iommu(emu);
     1890
     1891        /* set addressing mode */
     1892        emu->address_mode = is_audigy ? 0 : 1;
    18261893        /* set the DMA transfer mask */
    1827         emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
    1828         if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
    1829             pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
    1830                 snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
     1894        emu->dma_mask = emu->address_mode ? EMU10K1_DMA_MASK : AUDIGY_DMA_MASK;
     1895        if (dma_set_mask_and_coherent(&pci->dev, emu->dma_mask) < 0) {
     1896                dev_err(card->dev,
     1897                        "architecture does not support PCI busmaster DMA with mask 0x%lx\n",
     1898                        emu->dma_mask);
    18311899                kfree(emu);
    18321900                pci_disable_device(pci);
     
    18471915
    18481916        emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
    1849         if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    1850                                 32 * 1024, &emu->ptb_pages) < 0) {
     1917
     1918        page_table_size = sizeof(u32) * (emu->address_mode ? MAXPAGES1 :
     1919                                         MAXPAGES0);
     1920        if (snd_emu10k1_alloc_pages_maybe_wider(emu, page_table_size,
     1921                                                &emu->ptb_pages) < 0) {
    18511922                err = -ENOMEM;
    18521923                goto error;
    18531924        }
    1854 
     1925        dev_dbg(card->dev, "page table address range is %.8lx:%.8lx\n",
     1926                (unsigned long)emu->ptb_pages.addr,
     1927                (unsigned long)(emu->ptb_pages.addr + emu->ptb_pages.bytes));
     1928
     1929#ifdef TARGET_OS2
     1930        emu->page_ptr_table = vmalloc(array_size(sizeof(void *),
     1931                                                 emu->max_cache_pages));
     1932        emu->page_addr_table = vmalloc(array_size(sizeof(unsigned long),
     1933                                                  emu->max_cache_pages));
     1934#else
    18551935        emu->page_ptr_table = vmalloc(emu->max_cache_pages * sizeof(void *));
    18561936        emu->page_addr_table = vmalloc(emu->max_cache_pages *
    18571937                                       sizeof(unsigned long));
     1938#endif
    18581939        if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
    18591940                err = -ENOMEM;
     
    18611942        }
    18621943
    1863         if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    1864                                 EMUPAGESIZE, &emu->silent_page) < 0) {
     1944        if (snd_emu10k1_alloc_pages_maybe_wider(emu, EMUPAGESIZE,
     1945                                                &emu->silent_page) < 0) {
    18651946                err = -ENOMEM;
    18661947                goto error;
    18671948        }
     1949        dev_dbg(card->dev, "silent page range is %.8lx:%.8lx\n",
     1950                (unsigned long)emu->silent_page.addr,
     1951                (unsigned long)(emu->silent_page.addr +
     1952                                emu->silent_page.bytes));
     1953
    18681954        emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
    18691955        if (emu->memhdr == NULL) {
     
    19142000        /* irq handler must be registered after I/O ports are activated */
    19152001        if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_SHARED,
    1916                         "EMU10K1", emu)) {
     2002                        KBUILD_MODNAME, emu)) {
    19172003                err = -EBUSY;
    19182004                goto error;
    19192005        }
    19202006        emu->irq = pci->irq;
     2007        card->sync_irq = emu->irq;
    19212008
    19222009        /*
     
    19402027                0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
    19412028
    1942         emu->reserved_page = (struct snd_emu10k1_memblk *)
    1943                 snd_emu10k1_synth_alloc(emu, 4096);
    1944         if (emu->reserved_page)
    1945                 emu->reserved_page->map_locked = 1;
    1946 
    19472029        /* Clear silent pages and set up pointers */
    1948         memset(emu->silent_page.area, 0, PAGE_SIZE);
    1949         silent_page = emu->silent_page.addr << 1;
    1950         for (idx = 0; idx < MAXPAGES; idx++)
    1951                 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
     2030        memset(emu->silent_page.area, 0, emu->silent_page.bytes);
     2031        silent_page = emu->silent_page.addr << emu->address_mode;
     2032        pgtbl = (__le32 *)emu->ptb_pages.area;
     2033        for (idx = 0; idx < (emu->address_mode ? MAXPAGES1 : MAXPAGES0); idx++)
     2034                pgtbl[idx] = cpu_to_le32(silent_page | idx);
    19522035
    19532036        /* set up voice indices */
     
    19602043        if (err < 0)
    19612044                goto error;
    1962 #ifdef CONFIG_PM
     2045#ifdef CONFIG_PM_SLEEP
    19632046        err = alloc_pm_buffer(emu);
    19642047        if (err < 0)
     
    19762059                goto error;
    19772060
    1978 #ifdef CONFIG_PROC_FS
     2061#ifdef CONFIG_SND_PROC_FS
    19792062        snd_emu10k1_proc_init(emu);
    19802063#endif
    19812064
    1982         snd_card_set_dev(card, &pci->dev);
    19832065        *remu = emu;
    19842066        return 0;
     
    19892071}
    19902072
    1991 #ifdef CONFIG_PM
    1992 static unsigned char saved_regs[] = {
     2073#ifdef CONFIG_PM_SLEEP
     2074static const unsigned char saved_regs[] = {
    19932075        CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
    19942076        FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
     
    19992081        0xff /* end */
    20002082};
    2001 static unsigned char saved_regs_audigy[] = {
     2083static const unsigned char saved_regs_audigy[] = {
    20022084        A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
    20032085        A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
     
    20052087};
    20062088
    2007 static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
     2089static int alloc_pm_buffer(struct snd_emu10k1 *emu)
    20082090{
    20092091        int size;
     
    20122094        if (emu->audigy)
    20132095                size += ARRAY_SIZE(saved_regs_audigy);
     2096#ifdef TARGET_OS2
     2097        emu->saved_ptr = vmalloc(array3_size(4, NUM_G, size));
     2098#else
    20142099        emu->saved_ptr = vmalloc(4 * NUM_G * size);
     2100#endif
    20152101        if (!emu->saved_ptr)
    20162102                return -ENOMEM;
     
    20342120{
    20352121        int i;
    2036         unsigned char *reg;
     2122        const unsigned char *reg;
    20372123        unsigned int *val;
    20382124
     
    20672153{
    20682154        int i;
    2069         unsigned char *reg;
     2155        const unsigned char *reg;
    20702156        unsigned int *val;
    20712157
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_patch.c

    r399 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Patch transfer callback for Emu10k1
    34 *
    45 *  Copyright (C) 2000 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
    196 */
    207/*
     
    3219#define BLANK_HEAD_SIZE         32
    3320
     21#ifdef TARGET_OS2
     22#define swap(a, b) \
     23        do { int __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
     24#endif
    3425/*
    3526 * allocate a sample block and copy data from userspace
     
    4132{
    4233        int offset;
    43         int truesize, size, loopsize, blocksize;
     34        int truesize, size, blocksize;
     35        __maybe_unused int loopsize;
    4436        int loopend, sampleend;
    4537        unsigned int start_addr;
     
    5143
    5244        if (sp->v.size == 0) {
    53                 snd_printd("emu: rom font for sample %d\n", sp->v.sample);
     45                dev_dbg(emu->card->dev,
     46                        "emu: rom font for sample %d\n", sp->v.sample);
    5447                return 0;
    5548        }
     
    7063
    7164        /* be sure loop points start < end */
    72         if (sp->v.loopstart >= sp->v.loopend) {
    73                 int tmp = sp->v.loopstart;
    74                 sp->v.loopstart = sp->v.loopend;
    75                 sp->v.loopend = tmp;
    76         }
     65        if (sp->v.loopstart >= sp->v.loopend)
     66                swap(sp->v.loopstart, sp->v.loopend);
    7767
    7868        /* compute true data size to be loaded */
     
    9383        sp->block = snd_emu10k1_synth_alloc(emu, blocksize);
    9484        if (sp->block == NULL) {
    95                 snd_printd("emu10k1: synth malloc failed (size=%d)\n", blocksize);
     85                dev_dbg(emu->card->dev,
     86                        "synth malloc failed (size=%d)\n", blocksize);
    9687                /* not ENOMEM (for compatibility with OSS) */
    9788                return -ENOSPC;
     
    124115        data += size;
    125116
    126 #if 0 /* not suppported yet */
     117#if 0 /* not supported yet */
    127118        /* handle reverse (or bidirectional) loop */
    128119        if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP|SNDRV_SFNT_SAMPLE_REVERSE_LOOP)) {
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_synth.c

    r305 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
    34 *
    45 *  Routines for control of EMU10K1 WaveTable synth
    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
    196 */
    207
    218#include "emu10k1_synth_local.h"
    229#include <linux/init.h>
     10#include <linux/module.h>
    2311
    2412MODULE_AUTHOR("Takashi Iwai");
     
    2614MODULE_LICENSE("GPL");
    2715
     16#ifdef TARGET_OS2
     17#define KBUILD_MODNAME "emu10k1_synth"
     18#endif
     19
    2820/*
    2921 * create a new hardware dependent device for Emu10k1
    3022 */
    31 static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
     23static int snd_emu10k1_synth_probe(struct device *_dev)
    3224{
     25        struct snd_seq_device *dev = to_seq_dev(_dev);
    3326        struct snd_emux *emux;
    3427        struct snd_emu10k1 *hw;
     
    7972}
    8073
    81 static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
     74static int snd_emu10k1_synth_remove(struct device *_dev)
    8275{
     76        struct snd_seq_device *dev = to_seq_dev(_dev);
    8377        struct snd_emux *emux;
    8478        struct snd_emu10k1 *hw;
     
    10498 */
    10599
    106 static int __init alsa_emu10k1_synth_init(void)
    107 {
    108        
    109         static struct snd_seq_dev_ops ops = {
    110                 snd_emu10k1_synth_new_device,
    111                 snd_emu10k1_synth_delete_device,
    112         };
    113         return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
    114                                               sizeof(struct snd_emu10k1_synth_arg));
    115 }
     100static struct snd_seq_driver emu10k1_synth_driver = {
     101        .driver = {
     102                .name = KBUILD_MODNAME,
     103                .probe = snd_emu10k1_synth_probe,
     104                .remove = snd_emu10k1_synth_remove,
     105        },
     106        .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
     107        .argsize = sizeof(struct snd_emu10k1_synth_arg),
     108};
    116109
    117 static void __exit alsa_emu10k1_synth_exit(void)
    118 {
    119         snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH);
    120 }
    121 
    122 module_init(alsa_emu10k1_synth_init)
    123 module_exit(alsa_emu10k1_synth_exit)
     110module_snd_seq_driver(emu10k1_synth_driver);
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_synth_local.h

    r305 r679  
     1/* SPDX-License-Identifier: GPL-2.0-or-later */
    12#ifndef __EMU10K1_SYNTH_LOCAL_H
    23#define __EMU10K1_SYNTH_LOCAL_H
     
    56 *
    67 *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
    7  *
    8  *   This program is free software; you can redistribute it and/or modify
    9  *   it under the terms of the GNU General Public License as published by
    10  *   the Free Software Foundation; either version 2 of the License, or
    11  *   (at your option) any later version.
    12  *
    13  *   This program is distributed in the hope that it will be useful,
    14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
    17  *
    18  *   You should have received a copy of the GNU General Public License
    19  *   along with this program; if not, write to the Free Software
    20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    218 */
    229
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1x.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
     
    1415 *    - EMU10K1X-DBQ
    1516 *    - STAC 9708T
    16  *
    17  *   This program is free software; you can redistribute it and/or modify
    18  *   it under the terms of the GNU General Public License as published by
    19  *   the Free Software Foundation; either version 2 of the License, or
    20  *   (at your option) any later version.
    21  *
    22  *   This program is distributed in the hope that it will be useful,
    23  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    24  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    25  *   GNU General Public License for more details.
    26  *
    27  *   You should have received a copy of the GNU General Public License
    28  *   along with this program; if not, write to the Free Software
    29  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    30  *
    3117 */
     18#ifdef TARGET_OS2
     19#define KBUILD_MODNAME "emu10k1"
     20#endif
    3221#include <linux/init.h>
    3322#include <linux/interrupt.h>
     
    3524#include <linux/dma-mapping.h>
    3625#include <linux/slab.h>
    37 #include <linux/moduleparam.h>
     26#include <linux/module.h>
    3827#include <sound/core.h>
    3928#include <sound/initval.h>
     
    5140static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
    5241static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
    53 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
     42static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
    5443
    5544module_param_array(index, int, NULL, 0444);
     
    10897/********************************************************************************************************/
    10998#define PLAYBACK_LIST_ADDR      0x00            /* Base DMA address of a list of pointers to each period/size */
    110                                                 /* One list entry: 4 bytes for DMA address,
     99                                                /* One list entry: 4 bytes for DMA address, 
    111100                                                 * 4 bytes for period_size << 16.
    112101                                                 * One list entry is 8 bytes long.
     
    181170/* From 0x50 - 0x5f, last samples captured */
    182171
    183 /**
     172/*
    184173 * The hardware has 3 channels for playback and 1 for capture.
    185174 *  - channel 0 is the front channel
     
    187176 *  - channel 2 is the center/lfe channel
    188177 * Volume is controlled by the AC97 for the front and rear channels by
    189  * the PCM Playback Volume, Sigmatel Surround Playback Volume and
     178 * the PCM Playback Volume, Sigmatel Surround Playback Volume and 
    190179 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
    191180 * the front/rear channel mixing in the REAR OUT jack. When using the
     
    200189        int number;
    201190        int use;
    202 
     191 
    203192        struct emu10k1x_pcm *epcm;
    204193};
     
    255244
    256245/* hardware definition */
    257 static struct snd_pcm_hardware snd_emu10k1x_playback_hw = {
    258         .info =                 (SNDRV_PCM_INFO_MMAP |
     246static const struct snd_pcm_hardware snd_emu10k1x_playback_hw = {
     247        .info =                 (SNDRV_PCM_INFO_MMAP | 
    259248                                 SNDRV_PCM_INFO_INTERLEAVED |
    260249                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     
    274263};
    275264
    276 static struct snd_pcm_hardware snd_emu10k1x_capture_hw = {
    277         .info =                 (SNDRV_PCM_INFO_MMAP |
     265static const struct snd_pcm_hardware snd_emu10k1x_capture_hw = {
     266        .info =                 (SNDRV_PCM_INFO_MMAP | 
    278267                                 SNDRV_PCM_INFO_INTERLEAVED |
    279268                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     
    293282};
    294283
    295 static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu,
    296                                           unsigned int reg,
     284static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu, 
     285                                          unsigned int reg, 
    297286                                          unsigned int chn)
    298287{
    299288        unsigned long flags;
    300289        unsigned int regptr, val;
    301 
     290 
    302291        regptr = (reg << 16) | chn;
    303292
     
    370359                return;
    371360#if 0
    372         snd_printk(KERN_INFO "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
     361        dev_info(emu->card->dev,
     362                 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
    373363                   epcm->substream->ops->pointer(epcm->substream),
    374364                   snd_pcm_lib_period_bytes(epcm->substream),
     
    397387        epcm->emu = chip;
    398388        epcm->substream = substream;
    399 
     389 
    400390        runtime->private_data = epcm;
    401391        runtime->private_free = snd_emu10k1x_pcm_free_substream;
    402 
     392 
    403393        runtime->hw = snd_emu10k1x_playback_hw;
    404394
     
    425415        }
    426416
    427         return snd_pcm_lib_malloc_pages(substream,
    428                                         params_buffer_bytes(hw_params));
     417        return 0;
    429418}
    430419
     
    446435        }
    447436
    448         return snd_pcm_lib_free_pages(substream);
     437        return 0;
    449438}
    450439
     
    488477        int result = 0;
    489478
    490 //      snd_printk(KERN_INFO "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream));
     479        /*
     480        dev_dbg(emu->card->dev,
     481                "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n",
     482                (int)emu, cmd, (int)substream->ops->pointer(substream));
     483        */
    491484
    492485        switch (cmd) {
     
    531524                return 0;
    532525       
    533         if (ptr3 != ptr4)
     526        if (ptr3 != ptr4) 
    534527                ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
    535528        ptr2 = bytes_to_frames(runtime, ptr1);
     
    544537
    545538/* operators */
    546 static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
     539static const struct snd_pcm_ops snd_emu10k1x_playback_ops = {
    547540        .open =        snd_emu10k1x_playback_open,
    548541        .close =       snd_emu10k1x_playback_close,
    549         .ioctl =       snd_pcm_lib_ioctl,
    550542        .hw_params =   snd_emu10k1x_pcm_hw_params,
    551543        .hw_free =     snd_emu10k1x_pcm_hw_free,
     
    604596        }
    605597
    606         return snd_pcm_lib_malloc_pages(substream,
    607                                         params_buffer_bytes(hw_params));
     598        return 0;
    608599}
    609600
     
    625616        }
    626617
    627         return snd_pcm_lib_free_pages(substream);
     618        return 0;
    628619}
    629620
     
    653644        switch (cmd) {
    654645        case SNDRV_PCM_TRIGGER_START:
    655                 snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP |
     646                snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP | 
    656647                                         INTE_CAP_0_HALF_LOOP);
    657648                snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|TRIGGER_CAPTURE);
     
    660651        case SNDRV_PCM_TRIGGER_STOP:
    661652                epcm->running = 0;
    662                 snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP |
     653                snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP | 
    663654                                          INTE_CAP_0_HALF_LOOP);
    664655                snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CAPTURE));
     
    690681}
    691682
    692 static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
     683static const struct snd_pcm_ops snd_emu10k1x_capture_ops = {
    693684        .open =        snd_emu10k1x_pcm_open_capture,
    694685        .close =       snd_emu10k1x_pcm_close_capture,
    695         .ioctl =       snd_pcm_lib_ioctl,
    696686        .hw_params =   snd_emu10k1x_pcm_hw_params_capture,
    697687        .hw_free =     snd_emu10k1x_pcm_hw_free_capture,
     
    707697        unsigned long flags;
    708698        unsigned short val;
    709 
     699 
    710700        spin_lock_irqsave(&emu->emu_lock, flags);
    711701        outb(reg, emu->port + AC97ADDRESS);
     
    720710        struct emu10k1x *emu = ac97->private_data;
    721711        unsigned long flags;
    722 
     712 
    723713        spin_lock_irqsave(&emu->emu_lock, flags);
    724714        outb(reg, emu->port + AC97ADDRESS);
     
    732722        struct snd_ac97_template ac97;
    733723        int err;
    734         static struct snd_ac97_bus_ops ops = {
     724        static const struct snd_ac97_bus_ops ops = {
    735725                .write = snd_emu10k1x_ac97_write,
    736726                .read = snd_emu10k1x_ac97_read,
    737727        };
    738 
     728 
    739729        if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
    740730                return err;
     
    799789                if (cap_voice->use)
    800790                        snd_emu10k1x_pcm_interrupt(chip, cap_voice);
    801                 else
    802                         snd_emu10k1x_intr_disable(chip,
     791                else 
     792                        snd_emu10k1x_intr_disable(chip, 
    803793                                                  INTE_CAP_0_LOOP |
    804794                                                  INTE_CAP_0_HALF_LOOP);
     
    827817        outl(status, chip->port + IPR);
    828818
    829         // snd_printk(KERN_INFO "interrupt %08x\n", status);
     819        /* dev_dbg(chip->card->dev, "interrupt %08x\n", status); */
    830820        return IRQ_HANDLED;
    831821}
    832822
    833 static int __devinit snd_emu10k1x_pcm(struct emu10k1x *emu, int device, struct snd_pcm **rpcm)
     823static const struct snd_pcm_chmap_elem surround_map[] = {
     824        { .channels = 2,
     825          .map = { SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } },
     826        {0}
     827};
     828
     829static const struct snd_pcm_chmap_elem clfe_map[] = {
     830        { .channels = 2,
     831          .map = { SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE } },
     832        {0}
     833};
     834
     835static int snd_emu10k1x_pcm(struct emu10k1x *emu, int device)
    834836{
    835837        struct snd_pcm *pcm;
     838        const struct snd_pcm_chmap_elem *map = NULL;
    836839        int err;
    837840        int capture = 0;
    838 
    839         if (rpcm)
    840                 *rpcm = NULL;
     841 
    841842        if (device == 0)
    842843                capture = 1;
     
    844845        if ((err = snd_pcm_new(emu->card, "emu10k1x", device, 1, capture, &pcm)) < 0)
    845846                return err;
    846 
     847 
    847848        pcm->private_data = emu;
    848849       
     
    862863        case 0:
    863864                strcpy(pcm->name, "EMU10K1X Front");
     865                map = snd_pcm_std_chmaps;
    864866                break;
    865867        case 1:
    866868                strcpy(pcm->name, "EMU10K1X Rear");
     869                map = surround_map;
    867870                break;
    868871        case 2:
    869872                strcpy(pcm->name, "EMU10K1X Center/LFE");
     873                map = clfe_map;
    870874                break;
    871875        }
    872876        emu->pcm = pcm;
    873877
    874         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    875                                               snd_dma_pci_data(emu->pci),
    876                                               32*1024, 32*1024);
    877 
    878         if (rpcm)
    879                 *rpcm = pcm;
    880 
    881         return 0;
    882 }
    883 
    884 static int __devinit snd_emu10k1x_create(struct snd_card *card,
    885                                          struct pci_dev *pci,
    886                                          struct emu10k1x **rchip)
     878        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
     879                                       &emu->pci->dev, 32*1024, 32*1024);
     880 
     881        return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, map, 2,
     882                                     1 << 2, NULL);
     883}
     884
     885static int snd_emu10k1x_create(struct snd_card *card,
     886                               struct pci_dev *pci,
     887                               struct emu10k1x **rchip)
    887888{
    888889        struct emu10k1x *chip;
    889890        int err;
    890891        int ch;
    891         static struct snd_device_ops ops = {
     892        static const struct snd_device_ops ops = {
    892893                .dev_free = snd_emu10k1x_dev_free,
    893894        };
     
    899900        if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
    900901            pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
    901                 snd_printk(KERN_ERR "error to set 28bit mask DMA\n");
     902                dev_err(card->dev, "error to set 28bit mask DMA\n");
    902903                pci_disable_device(pci);
    903904                return -ENXIO;
     
    916917        spin_lock_init(&chip->emu_lock);
    917918        spin_lock_init(&chip->voice_lock);
    918 
     919 
    919920        chip->port = pci_resource_start(pci, 0);
    920921        if ((chip->res_port = request_region(chip->port, 8,
    921                                              "EMU10K1X")) == NULL) {
    922                 snd_printk(KERN_ERR "emu10k1x: cannot allocate the port 0x%lx\n", chip->port);
     922                                             "EMU10K1X")) == NULL) {
     923                dev_err(card->dev, "cannot allocate the port 0x%lx\n",
     924                        chip->port);
    923925                snd_emu10k1x_free(chip);
    924926                return -EBUSY;
     
    926928
    927929        if (request_irq(pci->irq, snd_emu10k1x_interrupt,
    928                         IRQF_SHARED, "EMU10K1X", chip)) {
    929                 snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq);
     930                        IRQF_SHARED, KBUILD_MODNAME, chip)) {
     931                dev_err(card->dev, "cannot grab irq %d\n", pci->irq);
    930932                snd_emu10k1x_free(chip);
    931933                return -EBUSY;
    932934        }
    933935        chip->irq = pci->irq;
    934 
    935         if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    936                                4 * 1024, &chip->dma_buffer) < 0) {
     936        card->sync_irq = chip->irq;
     937 
     938        if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
     939                                4 * 1024, &chip->dma_buffer) < 0) {
    937940                snd_emu10k1x_free(chip);
    938941                return -ENOMEM;
     
    948951        pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
    949952        pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
    950         snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
     953        dev_info(card->dev, "Model %04x Rev %08x Serial %08x\n", chip->model,
    951954                   chip->revision, chip->serial);
    952955
     
    973976         */
    974977        snd_emu10k1x_ptr_write(chip, SPCS0, 0,
    975                                chip->spdif_bits[0] =
     978                               chip->spdif_bits[0] = 
    976979                               SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    977980                               SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     
    979982                               0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    980983        snd_emu10k1x_ptr_write(chip, SPCS1, 0,
    981                                chip->spdif_bits[1] =
     984                               chip->spdif_bits[1] = 
    982985                               SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    983986                               SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     
    985988                               0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    986989        snd_emu10k1x_ptr_write(chip, SPCS2, 0,
    987                                chip->spdif_bits[2] =
     990                               chip->spdif_bits[2] = 
    988991                               SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    989992                               SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     
    10061009}
    10071010
    1008 static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry,
     1011static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry, 
    10091012                                       struct snd_info_buffer *buffer)
    10101013{
     
    10341037}
    10351038
    1036 static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
     1039static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry, 
    10371040                                        struct snd_info_buffer *buffer)
    10381041{
     
    10451048                        continue;
    10461049
    1047                 if (reg < 0x49 && /* val <= 0xffffffff && DAZ */ channel_id <= 2)
     1050                if (reg < 0x49 && channel_id <= 2)
    10481051                        snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
    10491052        }
    10501053}
    10511054
    1052 static int __devinit snd_emu10k1x_proc_init(struct emu10k1x * emu)
    1053 {
    1054         struct snd_info_entry *entry;
    1055        
    1056         if(! snd_card_proc_new(emu->card, "emu10k1x_regs", &entry)) {
    1057                 snd_info_set_text_ops(entry, emu, snd_emu10k1x_proc_reg_read);
    1058                 entry->c.text.write = snd_emu10k1x_proc_reg_write;
    1059                 entry->mode |= S_IWUSR;
    1060                 entry->private_data = emu;
    1061         }
    1062        
     1055static int snd_emu10k1x_proc_init(struct emu10k1x *emu)
     1056{
     1057        snd_card_rw_proc_new(emu->card, "emu10k1x_regs", emu,
     1058                             snd_emu10k1x_proc_reg_read,
     1059                             snd_emu10k1x_proc_reg_write);
    10631060        return 0;
    10641061}
     
    10811078        struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
    10821079        unsigned int val;
    1083         int change = 0;
    10841080
    10851081        val = ucontrol->value.integer.value[0] ;
     
    10961092                snd_emu10k1x_gpio_write(emu, 0x1080);
    10971093        }
    1098         return change;
    1099 }
    1100 
    1101 static struct snd_kcontrol_new snd_emu10k1x_shared_spdif __devinitdata =
     1094        return 0;
     1095}
     1096
     1097static const struct snd_kcontrol_new snd_emu10k1x_shared_spdif =
    11021098{
    11031099        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    11581154}
    11591155
    1160 static struct snd_kcontrol_new snd_emu10k1x_spdif_mask_control =
     1156static const struct snd_kcontrol_new snd_emu10k1x_spdif_mask_control =
    11611157{
    11621158        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     
    11681164};
    11691165
    1170 static struct snd_kcontrol_new snd_emu10k1x_spdif_control =
     1166static const struct snd_kcontrol_new snd_emu10k1x_spdif_control =
    11711167{
    11721168        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     
    11781174};
    11791175
    1180 static int __devinit snd_emu10k1x_mixer(struct emu10k1x *emu)
     1176static int snd_emu10k1x_mixer(struct emu10k1x *emu)
    11811177{
    11821178        int err;
     
    12321228#ifdef CONFIG_SND_DEBUG
    12331229        if (timeout <= 0)
    1234                 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
     1230                dev_err(emu->card->dev,
     1231                        "cmd: clear rx timeout (status = 0x%x)\n",
     1232                        mpu401_read_stat(emu, mpu));
    12351233#endif
    12361234}
     
    13061304        spin_unlock_irqrestore(&midi->input_lock, flags);
    13071305        if (!ok) {
    1308                 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
     1306                dev_err(emu->card->dev,
     1307                        "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
    13091308                           cmd, emu->port,
    13101309                           mpu401_read_stat(emu, midi),
     
    14701469 */
    14711470
    1472 static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
     1471static const struct snd_rawmidi_ops snd_emu10k1x_midi_output =
    14731472{
    14741473        .open =         snd_emu10k1x_midi_output_open,
     
    14771476};
    14781477
    1479 static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
     1478static const struct snd_rawmidi_ops snd_emu10k1x_midi_input =
    14801479{
    14811480        .open =         snd_emu10k1x_midi_input_open,
     
    14911490}
    14921491
    1493 static int __devinit emu10k1x_midi_init(struct emu10k1x *emu,
    1494                                         struct emu10k1x_midi *midi, int device, char *name)
     1492static int emu10k1x_midi_init(struct emu10k1x *emu,
     1493                              struct emu10k1x_midi *midi, int device,
     1494                              char *name)
    14951495{
    14961496        struct snd_rawmidi *rmidi;
     
    15151515}
    15161516
    1517 static int __devinit snd_emu10k1x_midi(struct emu10k1x *emu)
     1517static int snd_emu10k1x_midi(struct emu10k1x *emu)
    15181518{
    15191519        struct emu10k1x_midi *midi = &emu->midi;
     
    15321532}
    15331533
    1534 static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
    1535                                         const struct pci_device_id *pci_id)
     1534static int snd_emu10k1x_probe(struct pci_dev *pci,
     1535                              const struct pci_device_id *pci_id)
    15361536{
    15371537        static int dev;
     
    15471547        }
    15481548
    1549         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     1549        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     1550                           0, &card);
    15501551        if (err < 0)
    15511552                return err;
     
    15561557        }
    15571558
    1558         if ((err = snd_emu10k1x_pcm(chip, 0, NULL)) < 0) {
     1559        if ((err = snd_emu10k1x_pcm(chip, 0)) < 0) {
    15591560                snd_card_free(card);
    15601561                return err;
    15611562        }
    1562         if ((err = snd_emu10k1x_pcm(chip, 1, NULL)) < 0) {
     1563        if ((err = snd_emu10k1x_pcm(chip, 1)) < 0) {
    15631564                snd_card_free(card);
    15641565                return err;
    15651566        }
    1566         if ((err = snd_emu10k1x_pcm(chip, 2, NULL)) < 0) {
     1567        if ((err = snd_emu10k1x_pcm(chip, 2)) < 0) {
    15671568                snd_card_free(card);
    15681569                return err;
     
    15911592                card->shortname, chip->port, chip->irq);
    15921593
    1593         snd_card_set_dev(card, &pci->dev);
    1594 
    15951594        if ((err = snd_card_register(card)) < 0) {
    15961595                snd_card_free(card);
     
    16031602}
    16041603
    1605 static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
     1604static void snd_emu10k1x_remove(struct pci_dev *pci)
    16061605{
    16071606        snd_card_free(pci_get_drvdata(pci));
    1608         pci_set_drvdata(pci, NULL);
    16091607}
    16101608
    16111609// PCI IDs
    1612 static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1x_ids) = {
     1610static const struct pci_device_id snd_emu10k1x_ids[] = {
    16131611        { PCI_VDEVICE(CREATIVE, 0x0006), 0 },   /* Dell OEM version (EMU10K1) */
    16141612        { 0, }
     
    16171615
    16181616// pci_driver definition
    1619 static struct pci_driver driver = {
    1620         .name = "EMU10K1X",
     1617static struct pci_driver emu10k1x_driver = {
     1618        .name = KBUILD_MODNAME,
    16211619        .id_table = snd_emu10k1x_ids,
    16221620        .probe = snd_emu10k1x_probe,
    1623         .remove = __devexit_p(snd_emu10k1x_remove),
     1621        .remove = snd_emu10k1x_remove,
    16241622};
    16251623
    1626 // initialization of the module
    1627 static int __init alsa_card_emu10k1x_init(void)
    1628 {
    1629         return pci_register_driver(&driver);
    1630 }
    1631 
    1632 // clean up the module
    1633 static void __exit alsa_card_emu10k1x_exit(void)
    1634 {
    1635         pci_unregister_driver(&driver);
    1636 }
    1637 
    1638 module_init(alsa_card_emu10k1x_init)
    1639 module_exit(alsa_card_emu10k1x_exit)
     1624module_pci_driver(emu10k1x_driver);
  • GPL/trunk/alsa-kernel/pci/emu10k1/emufx.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    1213 *  TODO:
    1314 *    --
    14  *
    15  *   This program is free software; you can redistribute it and/or modify
    16  *   it under the terms of the GNU General Public License as published by
    17  *   the Free Software Foundation; either version 2 of the License, or
    18  *   (at your option) any later version.
    19  *
    20  *   This program is distributed in the hope that it will be useful,
    21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23  *   GNU General Public License for more details.
    24  *
    25  *   You should have received a copy of the GNU General Public License
    26  *   along with this program; if not, write to the Free Software
    27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    28  *
    2915 */
    3016
     
    3723#include <linux/mutex.h>
    3824#include <linux/moduleparam.h>
     25#include <linux/nospec.h>
    3926
    4027#include <sound/core.h>
     
    5946/*
    6047 *  Tables
    61  */
    62 
    63 static char *fxbuses[16] = {
     48 */ 
     49
     50static const char * const fxbuses[16] = {
    6451        /* 0x00 */ "PCM Left",
    6552        /* 0x01 */ "PCM Right",
     
    8067};
    8168
    82 static char *creative_ins[16] = {
     69static const char * const creative_ins[16] = {
    8370        /* 0x00 */ "AC97 Left",
    8471        /* 0x01 */ "AC97 Right",
     
    9986};
    10087
    101 static char *audigy_ins[16] = {
     88static const char * const audigy_ins[16] = {
    10289        /* 0x00 */ "AC97 Left",
    10390        /* 0x01 */ "AC97 Right",
     
    118105};
    119106
    120 static char *creative_outs[32] = {
     107static const char * const creative_outs[32] = {
    121108        /* 0x00 */ "AC97 Left",
    122109        /* 0x01 */ "AC97 Right",
     
    153140};
    154141
    155 static char *audigy_outs[32] = {
     142static const char * const audigy_outs[32] = {
    156143        /* 0x00 */ "Digital Front Left",
    157144        /* 0x01 */ "Digital Front Right",
     
    172159        /* 0x10 */ "AC97 Front Left",
    173160        /* 0x11 */ "AC97 Front Right",
    174         /* 0x12 */ "ADC Caputre Left",
     161        /* 0x12 */ "ADC Capture Left",
    175162        /* 0x13 */ "ADC Capture Right",
    176163        /* 0x14 */ NULL,
     
    305292static const DECLARE_TLV_DB_LINEAR(snd_emu10k1_db_linear, TLV_DB_GAIN_MUTE, 0);
    306293
     294/* EMU10K1 bass/treble db gain */
     295static const DECLARE_TLV_DB_SCALE(snd_emu10k1_bass_treble_db_scale, -1200, 60, 0);
     296
    307297static const u32 onoff_table[2] = {
    308298        0x00000000, 0x00000001
    309299};
    310 
    311 /*
    312  */
    313 
    314 static inline mm_segment_t snd_enter_user(void)
    315 {
    316         mm_segment_t fs = get_fs();
    317         set_fs(get_ds());
    318         return fs;
    319 }
    320 
    321 static inline void snd_leave_user(mm_segment_t fs)
    322 {
    323         set_fs(fs);
    324 }
    325300
    326301/*
     
    435410                                            unsigned char gpr_running,
    436411                                            void *private_data,
    437                                             struct snd_emu10k1_fx8010_irq **r_irq)
    438 {
    439         struct snd_emu10k1_fx8010_irq *irq;
     412                                            struct snd_emu10k1_fx8010_irq *irq)
     413{
    440414        unsigned long flags;
    441415       
    442         irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
    443         if (irq == NULL)
    444                 return -ENOMEM;
    445416        irq->handler = handler;
    446417        irq->gpr_running = gpr_running;
     
    457428        }
    458429        spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags);
    459         if (r_irq)
    460                 *r_irq = irq;
    461430        return 0;
    462431}
     
    482451        }
    483452        spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags);
    484         kfree(irq);
    485453        return 0;
    486454}
     
    497465        if (snd_BUG_ON(*ptr >= 512))
    498466                return;
    499         code = (u_int32_t __force *)icode->code + (*ptr) * 2;
     467        code = icode->code + (*ptr) * 2;
    500468        set_bit(*ptr, icode->code_valid);
    501469        code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff);
     
    514482        if (snd_BUG_ON(*ptr >= 1024))
    515483                return;
    516         code = (u_int32_t __force *)icode->code + (*ptr) * 2;
     484        code = icode->code + (*ptr) * 2;
    517485        set_bit(*ptr, icode->code_valid);
    518486        code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff);
     
    537505
    538506static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu,
    539                                 struct snd_emu10k1_fx8010_code *icode)
     507                                struct snd_emu10k1_fx8010_code *icode,
     508                                bool in_kernel)
    540509{
    541510        int gpr;
     
    545514                if (!test_bit(gpr, icode->gpr_valid))
    546515                        continue;
    547                 if (get_user(val, &icode->gpr_map[gpr]))
     516                if (in_kernel)
     517                        val = icode->gpr_map[gpr];
     518                else if (get_user(val, (__user u32 *)&icode->gpr_map[gpr]))
    548519                        return -EFAULT;
    549520                snd_emu10k1_ptr_write(emu, emu->gpr_base + gpr, 0, val);
     
    561532                set_bit(gpr, icode->gpr_valid);
    562533                val = snd_emu10k1_ptr_read(emu, emu->gpr_base + gpr, 0);
    563                 if (put_user(val, &icode->gpr_map[gpr]))
     534                if (put_user(val, (__user u32 *)&icode->gpr_map[gpr]))
    564535                        return -EFAULT;
    565536        }
     
    568539
    569540static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu,
    570                                  struct snd_emu10k1_fx8010_code *icode)
     541                                 struct snd_emu10k1_fx8010_code *icode,
     542                                 bool in_kernel)
    571543{
    572544        int tram;
     
    576548                if (!test_bit(tram, icode->tram_valid))
    577549                        continue;
    578                 if (get_user(val, &icode->tram_data_map[tram]) ||
    579                     get_user(addr, &icode->tram_addr_map[tram]))
    580                         return -EFAULT;
     550                if (in_kernel) {
     551                        val = icode->tram_data_map[tram];
     552                        addr = icode->tram_addr_map[tram];
     553                } else {
     554                        if (get_user(val, (__user __u32 *)&icode->tram_data_map[tram]) ||
     555                            get_user(addr, (__user __u32 *)&icode->tram_addr_map[tram]))
     556                                return -EFAULT;
     557                }
    581558                snd_emu10k1_ptr_write(emu, TANKMEMDATAREGBASE + tram, 0, val);
    582559                if (!emu->audigy) {
     
    606583                        addr |= snd_emu10k1_ptr_read(emu, A_TANKMEMCTLREGBASE + tram, 0) << 20;
    607584                }
    608                 if (put_user(val, &icode->tram_data_map[tram]) ||
    609                     put_user(addr, &icode->tram_addr_map[tram]))
     585                if (put_user(val, (__user u32 *)&icode->tram_data_map[tram]) ||
     586                    put_user(addr, (__user u32 *)&icode->tram_addr_map[tram]))
    610587                        return -EFAULT;
    611588        }
     
    614591
    615592static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu,
    616                                  struct snd_emu10k1_fx8010_code *icode)
     593                                 struct snd_emu10k1_fx8010_code *icode,
     594                                 bool in_kernel)
    617595{
    618596        u32 pc, lo, hi;
     
    621599                if (!test_bit(pc / 2, icode->code_valid))
    622600                        continue;
    623                 if (get_user(lo, &icode->code[pc + 0]) ||
    624                     get_user(hi, &icode->code[pc + 1]))
    625                         return -EFAULT;
     601                if (in_kernel) {
     602                        lo = icode->code[pc + 0];
     603                        hi = icode->code[pc + 1];
     604                } else {
     605                        if (get_user(lo, (__user u32 *)&icode->code[pc + 0]) ||
     606                            get_user(hi, (__user u32 *)&icode->code[pc + 1]))
     607                                return -EFAULT;
     608                }
    626609                snd_emu10k1_efx_write(emu, pc + 0, lo);
    627610                snd_emu10k1_efx_write(emu, pc + 1, hi);
     
    638621        for (pc = 0; pc < (emu->audigy ? 2*1024 : 2*512); pc += 2) {
    639622                set_bit(pc / 2, icode->code_valid);
    640                 if (put_user(snd_emu10k1_efx_read(emu, pc + 0), &icode->code[pc + 0]))
     623                if (put_user(snd_emu10k1_efx_read(emu, pc + 0),
     624                             (__user u32 *)&icode->code[pc + 0]))
    641625                        return -EFAULT;
    642                 if (put_user(snd_emu10k1_efx_read(emu, pc + 1), &icode->code[pc + 1]))
     626                if (put_user(snd_emu10k1_efx_read(emu, pc + 1),
     627                             (__user u32 *)&icode->code[pc + 1]))
    643628                        return -EFAULT;
    644629        }
     
    647632
    648633static struct snd_emu10k1_fx8010_ctl *
    649 snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct snd_ctl_elem_id *id)
    650 {
     634snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu,
     635                         struct emu10k1_ctl_elem_id *_id)
     636{
     637        struct snd_ctl_elem_id *id = (struct snd_ctl_elem_id *)_id;
    651638        struct snd_emu10k1_fx8010_ctl *ctl;
    652639        struct snd_kcontrol *kcontrol;
     
    664651#define MAX_TLV_SIZE    256
    665652
    666 static unsigned int *copy_tlv(const unsigned int __user *_tlv)
     653static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel)
    667654{
    668655        unsigned int data[2];
     
    671658        if (!_tlv)
    672659                return NULL;
    673         if (copy_from_user(data, _tlv, sizeof(data)))
     660        if (in_kernel)
     661                memcpy(data, (__force void *)_tlv, sizeof(data));
     662        else if (copy_from_user(data, _tlv, sizeof(data)))
    674663                return NULL;
    675664        if (data[1] >= MAX_TLV_SIZE)
     
    679668                return NULL;
    680669        memcpy(tlv, data, sizeof(data));
    681         if (copy_from_user(tlv + 2, _tlv + 2, data[1])) {
     670        if (in_kernel) {
     671                memcpy(tlv + 2, (__force void *)(_tlv + 2),  data[1]);
     672        } else if (copy_from_user(tlv + 2, _tlv + 2, data[1])) {
    682673                kfree(tlv);
    683674                return NULL;
     
    687678
    688679static int copy_gctl(struct snd_emu10k1 *emu,
    689                      struct snd_emu10k1_fx8010_control_gpr *gctl,
    690                      struct snd_emu10k1_fx8010_control_gpr __user *_gctl,
     680                     struct snd_emu10k1_fx8010_control_gpr *dst,
     681                     struct snd_emu10k1_fx8010_control_gpr *src,
     682                     int idx, bool in_kernel)
     683{
     684        struct snd_emu10k1_fx8010_control_gpr __user *_src;
     685        struct snd_emu10k1_fx8010_control_old_gpr *octl;
     686        struct snd_emu10k1_fx8010_control_old_gpr __user *_octl;
     687
     688        _src = (struct snd_emu10k1_fx8010_control_gpr __user *)src;
     689        if (emu->support_tlv) {
     690                if (in_kernel)
     691                        *dst = src[idx];
     692                else if (copy_from_user(dst, &_src[idx], sizeof(*src)))
     693                        return -EFAULT;
     694                return 0;
     695        }
     696
     697        octl = (struct snd_emu10k1_fx8010_control_old_gpr *)src;
     698        _octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)octl;
     699        if (in_kernel)
     700                memcpy(dst, &octl[idx], sizeof(*octl));
     701        else if (copy_from_user(dst, &_octl[idx], sizeof(*octl)))
     702                return -EFAULT;
     703        dst->tlv = NULL;
     704        return 0;
     705}
     706
     707static int copy_gctl_to_user(struct snd_emu10k1 *emu,
     708                     struct snd_emu10k1_fx8010_control_gpr *dst,
     709                     struct snd_emu10k1_fx8010_control_gpr *src,
    691710                     int idx)
    692711{
     712        struct snd_emu10k1_fx8010_control_gpr __user *_dst;
    693713        struct snd_emu10k1_fx8010_control_old_gpr __user *octl;
    694714
     715        _dst = (struct snd_emu10k1_fx8010_control_gpr __user *)dst;
    695716        if (emu->support_tlv)
    696                 return copy_from_user(gctl, &_gctl[idx], sizeof(*gctl));
    697         octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;
    698         if (copy_from_user(gctl, &octl[idx], sizeof(*octl)))
     717                return copy_to_user(&_dst[idx], src, sizeof(*src));
     718       
     719        octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)dst;
     720        return copy_to_user(&octl[idx], src, sizeof(*octl));
     721}
     722
     723static int copy_ctl_elem_id(const struct emu10k1_ctl_elem_id *list, int i,
     724                            struct emu10k1_ctl_elem_id *ret, bool in_kernel)
     725{
     726        struct emu10k1_ctl_elem_id __user *_id =
     727                (struct emu10k1_ctl_elem_id __user *)&list[i];
     728
     729        if (in_kernel)
     730                *ret = list[i];
     731        else if (copy_from_user(ret, _id, sizeof(*ret)))
    699732                return -EFAULT;
    700         gctl->tlv = NULL;
    701733        return 0;
    702734}
    703735
    704 static int copy_gctl_to_user(struct snd_emu10k1 *emu,
    705                      struct snd_emu10k1_fx8010_control_gpr __user *_gctl,
    706                      struct snd_emu10k1_fx8010_control_gpr *gctl,
    707                      int idx)
    708 {
    709         struct snd_emu10k1_fx8010_control_old_gpr __user *octl;
    710 
    711         if (emu->support_tlv)
    712                 return copy_to_user(&_gctl[idx], gctl, sizeof(*gctl));
    713        
    714         octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;
    715         return copy_to_user(&octl[idx], gctl, sizeof(*octl));
    716 }
    717 
    718736static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu,
    719                                        struct snd_emu10k1_fx8010_code *icode)
     737                                       struct snd_emu10k1_fx8010_code *icode,
     738                                       bool in_kernel)
    720739{
    721740        unsigned int i;
    722         struct snd_ctl_elem_id __user *_id;
    723         struct snd_ctl_elem_id id;
     741        struct emu10k1_ctl_elem_id id;
    724742        struct snd_emu10k1_fx8010_control_gpr *gctl;
     743        struct snd_ctl_elem_id *gctl_id;
    725744        int err;
    726745       
    727         for (i = 0, _id = icode->gpr_del_controls;
    728              i < icode->gpr_del_control_count; i++, _id++) {
    729                 if (copy_from_user(&id, _id, sizeof(id)))
    730                         return -EFAULT;
     746        for (i = 0; i < icode->gpr_del_control_count; i++) {
     747                err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id,
     748                                       in_kernel);
     749                if (err < 0)
     750                        return err;
    731751                if (snd_emu10k1_look_for_ctl(emu, &id) == NULL)
    732752                        return -ENOENT;
     
    737757        err = 0;
    738758        for (i = 0; i < icode->gpr_add_control_count; i++) {
    739                 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) {
     759                if (copy_gctl(emu, gctl, icode->gpr_add_controls, i,
     760                              in_kernel)) {
    740761                        err = -EFAULT;
    741762                        goto __error;
     
    743764                if (snd_emu10k1_look_for_ctl(emu, &gctl->id))
    744765                        continue;
     766                gctl_id = (struct snd_ctl_elem_id *)&gctl->id;
    745767                down_read(&emu->card->controls_rwsem);
    746                 if (snd_ctl_find_id(emu->card, &gctl->id) != NULL) {
     768                if (snd_ctl_find_id(emu->card, gctl_id)) {
    747769                        up_read(&emu->card->controls_rwsem);
    748770                        err = -EEXIST;
     
    750772                }
    751773                up_read(&emu->card->controls_rwsem);
    752                 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
    753                     gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
     774                if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
     775                    gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) {
    754776                        err = -EINVAL;
    755777                        goto __error;
     
    758780        for (i = 0; i < icode->gpr_list_control_count; i++) {
    759781                /* FIXME: we need to check the WRITE access */
    760                 if (copy_gctl(emu, gctl, icode->gpr_list_controls, i)) {
     782                if (copy_gctl(emu, gctl, icode->gpr_list_controls, i,
     783                              in_kernel)) {
    761784                        err = -EFAULT;
    762785                        goto __error;
     
    776799        list_del(&ctl->list);
    777800        kfree(ctl);
    778         if (kctl->tlv.p)
    779                 kfree(kctl->tlv.p);
     801        kfree(kctl->tlv.p);
    780802}
    781803
    782804static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
    783                                     struct snd_emu10k1_fx8010_code *icode)
     805                                    struct snd_emu10k1_fx8010_code *icode,
     806                                    bool in_kernel)
    784807{
    785808        unsigned int i, j;
    786809        struct snd_emu10k1_fx8010_control_gpr *gctl;
     810        struct snd_ctl_elem_id *gctl_id;
    787811        struct snd_emu10k1_fx8010_ctl *ctl, *nctl;
    788812        struct snd_kcontrol_new knew;
     
    800824
    801825        for (i = 0; i < icode->gpr_add_control_count; i++) {
    802                 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) {
     826                if (copy_gctl(emu, gctl, icode->gpr_add_controls, i,
     827                              in_kernel)) {
    803828                        err = -EFAULT;
    804829                        goto __error;
    805830                }
    806                 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
    807                     gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
     831                gctl_id = (struct snd_ctl_elem_id *)&gctl->id;
     832                if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
     833                    gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) {
    808834                        err = -EINVAL;
    809835                        goto __error;
    810836                }
    811                 if (! gctl->id.name[0]) {
     837                if (!*gctl_id->name) {
    812838                        err = -EINVAL;
    813839                        goto __error;
     
    815841                ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
    816842                memset(&knew, 0, sizeof(knew));
    817                 knew.iface = gctl->id.iface;
    818                 knew.name = gctl->id.name;
    819                 knew.index = gctl->id.index;
    820                 knew.device = gctl->id.device;
    821                 knew.subdevice = gctl->id.subdevice;
     843                knew.iface = gctl_id->iface;
     844                knew.name = gctl_id->name;
     845                knew.index = gctl_id->index;
     846                knew.device = gctl_id->device;
     847                knew.subdevice = gctl_id->subdevice;
    822848                knew.info = snd_emu10k1_gpr_ctl_info;
    823                 knew.tlv.p = copy_tlv(gctl->tlv);
     849                knew.tlv.p = copy_tlv((const unsigned int __user *)gctl->tlv, in_kernel);
    824850                if (knew.tlv.p)
    825851                        knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
     
    873899
    874900static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu,
    875                                     struct snd_emu10k1_fx8010_code *icode)
     901                                    struct snd_emu10k1_fx8010_code *icode,
     902                                    bool in_kernel)
    876903{
    877904        unsigned int i;
    878         struct snd_ctl_elem_id id;
    879         struct snd_ctl_elem_id __user *_id;
     905        struct emu10k1_ctl_elem_id id;
    880906        struct snd_emu10k1_fx8010_ctl *ctl;
    881907        struct snd_card *card = emu->card;
    882        
    883         for (i = 0, _id = icode->gpr_del_controls;
    884              i < icode->gpr_del_control_count; i++, _id++) {
    885                 if (copy_from_user(&id, _id, sizeof(id)))
    886                         return -EFAULT;
     908        int err;
     909       
     910        for (i = 0; i < icode->gpr_del_control_count; i++) {
     911                err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id,
     912                                       in_kernel);
     913                if (err < 0)
     914                        return err;
    887915                down_write(&card->controls_rwsem);
    888916                ctl = snd_emu10k1_look_for_ctl(emu, &id);
     
    913941                        memset(gctl, 0, sizeof(*gctl));
    914942                        id = &ctl->kcontrol->id;
    915                         gctl->id.iface = id->iface;
     943                        gctl->id.iface = (__force int)id->iface;
    916944                        strlcpy(gctl->id.name, id->name, sizeof(gctl->id.name));
    917945                        gctl->id.index = id->index;
     
    941969
    942970static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,
    943                                   struct snd_emu10k1_fx8010_code *icode)
     971                                  struct snd_emu10k1_fx8010_code *icode,
     972                                  bool in_kernel)
    944973{
    945974        int err = 0;
    946975
    947976        mutex_lock(&emu->fx8010.lock);
    948         if ((err = snd_emu10k1_verify_controls(emu, icode)) < 0)
     977        err = snd_emu10k1_verify_controls(emu, icode, in_kernel);
     978        if (err < 0)
    949979                goto __error;
    950980        strlcpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name));
     
    956986                snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg | EMU10K1_DBG_SINGLE_STEP);
    957987        /* ok, do the main job */
    958         if ((err = snd_emu10k1_del_controls(emu, icode)) < 0 ||
    959             (err = snd_emu10k1_gpr_poke(emu, icode)) < 0 ||
    960             (err = snd_emu10k1_tram_poke(emu, icode)) < 0 ||
    961             (err = snd_emu10k1_code_poke(emu, icode)) < 0 ||
    962             (err = snd_emu10k1_add_controls(emu, icode)) < 0)
     988        err = snd_emu10k1_del_controls(emu, icode, in_kernel);
     989        if (err < 0)
     990                goto __error;
     991        err = snd_emu10k1_gpr_poke(emu, icode, in_kernel);
     992        if (err < 0)
     993                goto __error;
     994        err = snd_emu10k1_tram_poke(emu, icode, in_kernel);
     995        if (err < 0)
     996                goto __error;
     997        err = snd_emu10k1_code_poke(emu, icode, in_kernel);
     998        if (err < 0)
     999                goto __error;
     1000        err = snd_emu10k1_add_controls(emu, icode, in_kernel);
     1001        if (err < 0)
    9631002                goto __error;
    9641003        /* start FX processor when the DSP code is updated */
     
    10001039        if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT)
    10011040                return -EINVAL;
     1041        ipcm->substream = array_index_nospec(ipcm->substream,
     1042                                             EMU10K1_FX8010_PCM_COUNT);
    10021043        if (ipcm->channels > 32)
    10031044                return -EINVAL;
     
    10461087        if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT)
    10471088                return -EINVAL;
     1089        ipcm->substream = array_index_nospec(ipcm->substream,
     1090                                             EMU10K1_FX8010_PCM_COUNT);
    10481091        pcm = &emu->fx8010.pcm[ipcm->substream];
    10491092        mutex_lock(&emu->fx8010.lock);
     
    10721115#define SND_EMU10K1_CAPTURE_CHANNELS    4
    10731116
    1074 static void __devinit
     1117static void
    10751118snd_emu10k1_init_mono_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    10761119                              const char *name, int gpr, int defval)
    10771120{
    1078         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1121        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    10791122        strcpy(ctl->id.name, name);
    10801123        ctl->vcount = ctl->count = 1;
     
    10931136}
    10941137
    1095 static void __devinit
     1138static void
    10961139snd_emu10k1_init_stereo_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    10971140                                const char *name, int gpr, int defval)
    10981141{
    1099         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1142        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11001143        strcpy(ctl->id.name, name);
    11011144        ctl->vcount = ctl->count = 2;
     
    11151158}
    11161159
    1117 static void __devinit
     1160static void
    11181161snd_emu10k1_init_mono_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    11191162                                    const char *name, int gpr, int defval)
    11201163{
    1121         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1164        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11221165        strcpy(ctl->id.name, name);
    11231166        ctl->vcount = ctl->count = 1;
     
    11281171}
    11291172
    1130 static void __devinit
     1173static void
    11311174snd_emu10k1_init_stereo_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    11321175                                      const char *name, int gpr, int defval)
    11331176{
    1134         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1177        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11351178        strcpy(ctl->id.name, name);
    11361179        ctl->vcount = ctl->count = 2;
     
    11671210 */
    11681211
    1169 static int __devinit _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
     1212static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
    11701213{
    11711214        int err, i, z, gpr, nctl;
     
    11791222        struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    11801223        u32 *gpr_map;
    1181         mm_segment_t seg;
    1182 
    1183         if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL ||
    1184             (icode->gpr_map = (u_int32_t __user *)
    1185              kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
    1186                      GFP_KERNEL)) == NULL ||
    1187             (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
    1188                                 sizeof(*controls), GFP_KERNEL)) == NULL) {
    1189                 err = -ENOMEM;
    1190                 goto __err;
    1191         }
    1192         gpr_map = (u32 __force *)icode->gpr_map;
     1224
     1225        err = -ENOMEM;
     1226        icode = kzalloc(sizeof(*icode), GFP_KERNEL);
     1227        if (!icode)
     1228                return err;
     1229
     1230        icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
     1231                                 sizeof(u_int32_t), GFP_KERNEL);
     1232        if (!icode->gpr_map)
     1233                goto __err_gpr;
     1234        controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1235                           sizeof(*controls), GFP_KERNEL);
     1236        if (!controls)
     1237                goto __err_ctrls;
     1238
     1239        gpr_map = icode->gpr_map;
    11931240
    11941241        icode->tram_data_map = icode->gpr_map + 512;
     
    12771324        snd_emu10k1_init_stereo_control(&controls[nctl++], "Synth Capture Volume", gpr, 0);
    12781325        gpr += 2;
    1279 
     1326     
    12801327        /*
    12811328         * inputs
     
    13531400                                        gpr, 0);
    13541401        gpr += 2;
    1355 
     1402       
    13561403        /* Philips ADC Playback Volume */
    13571404        A_ADD_VOLUME_IN(stereo_mix, gpr, A_EXTIN_ADC_L);
     
    14451492
    14461493        ctl = &controls[nctl + 0];
    1447         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1494        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    14481495        strcpy(ctl->id.name, "Tone Control - Bass");
    14491496        ctl->vcount = 2;
     
    14541501        ctl->translation = EMU10K1_GPR_TRANSLATION_BASS;
    14551502        ctl = &controls[nctl + 1];
    1456         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1503        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    14571504        strcpy(ctl->id.name, "Tone Control - Treble");
    14581505        ctl->vcount = 2;
     
    15411588        if (emu->card_capabilities->emu_model) {
    15421589                /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */
    1543                 snd_printk(KERN_INFO "EMU outputs on\n");
     1590                dev_info(emu->card->dev, "EMU outputs on\n");
    15441591                for (z = 0; z < 8; z++) {
    15451592                        if (emu->card_capabilities->ca0108_chip) {
     
    15511598        }
    15521599
    1553         /* IEC958 Optical Raw Playback Switch */
     1600        /* IEC958 Optical Raw Playback Switch */ 
    15541601        gpr_map[gpr++] = 0;
    15551602        gpr_map[gpr++] = 0x1008;
     
    15651612                if ((z==1) && (emu->card_capabilities->spdif_bug)) {
    15661613                        /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */
    1567                         snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name);
     1614                        dev_info(emu->card->dev,
     1615                                 "Installing spdif_bug patch: %s\n",
     1616                                 emu->card_capabilities->name);
    15681617                        A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000);
    15691618                        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000);
     
    15891638        if (emu->card_capabilities->emu_model) {
    15901639                if (emu->card_capabilities->ca0108_chip) {
    1591                         snd_printk(KERN_INFO "EMU2 inputs on\n");
     1640                        dev_info(emu->card->dev, "EMU2 inputs on\n");
    15921641                        for (z = 0; z < 0x10; z++) {
    1593                                 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp,
     1642                                snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 
    15941643                                                                        bit_shifter16,
    15951644                                                                        A3_EMU32IN(z),
     
    15971646                        }
    15981647                } else {
    1599                         snd_printk(KERN_INFO "EMU inputs on\n");
     1648                        dev_info(emu->card->dev, "EMU inputs on\n");
    16001649                        /* Capture 16 (originally 8) channels of S32_LE sound */
    16011650
    16021651                        /*
    1603                         printk(KERN_DEBUG "emufx.c: gpr=0x%x, tmp=0x%x\n",
     1652                        dev_dbg(emu->card->dev, "emufx.c: gpr=0x%x, tmp=0x%x\n",
    16041653                               gpr, tmp);
    16051654                        */
     
    17321781                A_OP(icode, &ptr, 0x0f, 0xc0, 0xc0, 0xcf, 0xc0);
    17331782
    1734         seg = snd_enter_user();
    17351783        icode->gpr_add_control_count = nctl;
    1736         icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
     1784        icode->gpr_add_controls = controls;
    17371785        emu->support_tlv = 1; /* support TLV */
    1738         err = snd_emu10k1_icode_poke(emu, icode);
     1786        err = snd_emu10k1_icode_poke(emu, icode, true);
    17391787        emu->support_tlv = 0; /* clear again */
    1740         snd_leave_user(seg);
    1741 
    1742  __err:
     1788
     1789__err:
    17431790        kfree(controls);
    1744         if (icode != NULL) {
    1745                 kfree((void __force *)icode->gpr_map);
    1746                 kfree(icode);
    1747         }
     1791__err_ctrls:
     1792        kfree(icode->gpr_map);
     1793__err_gpr:
     1794        kfree(icode);
    17481795        return err;
    17491796}
     
    17561803/* when volume = max, then copy only to avoid volume modification */
    17571804/* with iMAC0 (negative values) */
    1758 static void __devinit _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1805static void _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17591806{
    17601807        OP(icode, ptr, iMAC0, dst, C_00000000, src, vol);
     
    17631810        OP(icode, ptr, iACC3, dst, src, C_00000000, C_00000000);
    17641811}
    1765 static void __devinit _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1812static void _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17661813{
    17671814        OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    17711818        OP(icode, ptr, iMAC0, dst, dst, src, vol);
    17721819}
    1773 static void __devinit _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1820static void _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17741821{
    17751822        OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    18021849
    18031850
    1804 static int __devinit _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
     1851static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
    18051852{
    18061853        int err, i, z, gpr, tmp, playback, capture;
     
    18101857        struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    18111858        u32 *gpr_map;
    1812         mm_segment_t seg;
    1813 
    1814         if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL)
    1815                 return -ENOMEM;
    1816         if ((icode->gpr_map = (u_int32_t __user *)
    1817              kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t),
    1818                      GFP_KERNEL)) == NULL ||
    1819             (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
    1820                                 sizeof(struct snd_emu10k1_fx8010_control_gpr),
    1821                                 GFP_KERNEL)) == NULL ||
    1822             (ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) {
    1823                 err = -ENOMEM;
    1824                 goto __err;
    1825         }
    1826         gpr_map = (u32 __force *)icode->gpr_map;
     1859
     1860        err = -ENOMEM;
     1861        icode = kzalloc(sizeof(*icode), GFP_KERNEL);
     1862        if (!icode)
     1863                return err;
     1864
     1865        icode->gpr_map = kcalloc(256 + 160 + 160 + 2 * 512,
     1866                                 sizeof(u_int32_t), GFP_KERNEL);
     1867        if (!icode->gpr_map)
     1868                goto __err_gpr;
     1869
     1870        controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1871                           sizeof(struct snd_emu10k1_fx8010_control_gpr),
     1872                           GFP_KERNEL);
     1873        if (!controls)
     1874                goto __err_ctrls;
     1875
     1876        ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL);
     1877        if (!ipcm)
     1878                goto __err_ipcm;
     1879
     1880        gpr_map = icode->gpr_map;
    18271881
    18281882        icode->tram_data_map = icode->gpr_map + 256;
     
    21582212
    21592213        ctl = &controls[i + 0];
    2160         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     2214        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    21612215        strcpy(ctl->id.name, "Tone Control - Bass");
    21622216        ctl->vcount = 2;
     
    21652219        ctl->max = 40;
    21662220        ctl->value[0] = ctl->value[1] = 20;
     2221        ctl->tlv = snd_emu10k1_bass_treble_db_scale;
    21672222        ctl->translation = EMU10K1_GPR_TRANSLATION_BASS;
    21682223        ctl = &controls[i + 1];
    2169         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     2224        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    21702225        strcpy(ctl->id.name, "Tone Control - Treble");
    21712226        ctl->vcount = 2;
     
    21742229        ctl->max = 40;
    21752230        ctl->value[0] = ctl->value[1] = 20;
     2231        ctl->tlv = snd_emu10k1_bass_treble_db_scale;
    21762232        ctl->translation = EMU10K1_GPR_TRANSLATION_TREBLE;
    21772233
     
    23162372                 * and EXTOUT_ALFE, so we can't connect inputs to them for multitrack recording.
    23172373                 *
    2318                  * Since only 14 of the 16 EXTINs are used, this is not a big problem.
    2319                  * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture
    2320                  * 0 and 3, then the rest of the EXTINs to the corresponding FX capture
    2321                  * channel.  Multitrack recorders will still see the center/lfe output signal
     2374                 * Since only 14 of the 16 EXTINs are used, this is not a big problem. 
     2375                 * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture 
     2376                 * 0 and 3, then the rest of the EXTINs to the corresponding FX capture 
     2377                 * channel.  Multitrack recorders will still see the center/lfe output signal 
    23222378                 * on the second and third channels.
    23232379                 */
     
    23322388                        OP(icode, &ptr, iACC3, FXBUS2(z), C_00000000, C_00000000, EXTIN(z));
    23332389        }
    2334        
     2390           
    23352391
    23362392        if (gpr > tmp) {
     
    23512407        if ((err = snd_emu10k1_fx8010_tram_setup(emu, ipcm->buffer_size)) < 0)
    23522408                goto __err;
    2353         seg = snd_enter_user();
    23542409        icode->gpr_add_control_count = i;
    2355         icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
     2410        icode->gpr_add_controls = controls;
    23562411        emu->support_tlv = 1; /* support TLV */
    2357         err = snd_emu10k1_icode_poke(emu, icode);
     2412        err = snd_emu10k1_icode_poke(emu, icode, true);
    23582413        emu->support_tlv = 0; /* clear again */
    2359         snd_leave_user(seg);
    23602414        if (err >= 0)
    23612415                err = snd_emu10k1_ipcm_poke(emu, ipcm);
    2362       __err:
     2416__err:
    23632417        kfree(ipcm);
     2418__err_ipcm:
    23642419        kfree(controls);
    2365         if (icode != NULL) {
    2366                 kfree((void __force *)icode->gpr_map);
    2367                 kfree(icode);
    2368         }
     2420__err_ctrls:
     2421        kfree(icode->gpr_map);
     2422__err_gpr:
     2423        kfree(icode);
    23692424        return err;
    23702425}
    23712426
    2372 int __devinit snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
     2427int snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
    23732428{
    23742429        spin_lock_init(&emu->fx8010.irq_lock);
     
    24352490
    24362491        if (size > 0) {
    2437                 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci),
     2492                if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
    24382493                                        size * 2, &emu->fx8010.etram_pages) < 0)
    24392494                        return -ENOMEM;
     
    24542509}
    24552510
    2456 static void copy_string(char *dst, char *src, char *null, int idx)
     2511static void copy_string(char *dst, const char *src, const char *null, int idx)
    24572512{
    24582513        if (src == NULL)
     
    24652520                                   struct snd_emu10k1_fx8010_info *info)
    24662521{
    2467         char **fxbus, **extin, **extout;
     2522        const char * const *fxbus, * const *extin, * const *extout;
    24682523        unsigned short fxbus_mask, extin_mask, extout_mask;
    24692524        int res;
     
    25022557                return put_user(SNDRV_EMU10K1_VERSION, (int __user *)argp);
    25032558        case SNDRV_EMU10K1_IOCTL_INFO:
    2504                 info = kmalloc(sizeof(*info), GFP_KERNEL);
     2559                info = kzalloc(sizeof(*info), GFP_KERNEL);
    25052560                if (!info)
    25062561                        return -ENOMEM;
     
    25192574                if (IS_ERR(icode))
    25202575                        return PTR_ERR(icode);
    2521                 res = snd_emu10k1_icode_poke(emu, icode);
     2576                res = snd_emu10k1_icode_poke(emu, icode, false);
    25222577                kfree(icode);
    25232578                return res;
     
    26232678}
    26242679
    2625 int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct snd_hwdep ** rhwdep)
     2680int snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device)
    26262681{
    26272682        struct snd_hwdep *hw;
    26282683        int err;
    26292684       
    2630         if (rhwdep)
    2631                 *rhwdep = NULL;
    26322685        if ((err = snd_hwdep_new(emu->card, "FX8010", device, &hw)) < 0)
    26332686                return err;
     
    26382691        hw->ops.release = snd_emu10k1_fx8010_release;
    26392692        hw->private_data = emu;
    2640         if (rhwdep)
    2641                 *rhwdep = hw;
    26422693        return 0;
    26432694}
    26442695
    2645 #ifdef CONFIG_PM
    2646 int __devinit snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
     2696#ifdef CONFIG_PM_SLEEP
     2697int snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
    26472698{
    26482699        int len;
    26492700
    26502701        len = emu->audigy ? 0x200 : 0x100;
    2651         emu->saved_gpr = kmalloc(len * 4, GFP_KERNEL);
     2702        emu->saved_gpr = kmalloc_array(len, 4, GFP_KERNEL);
    26522703        if (! emu->saved_gpr)
    26532704                return -ENOMEM;
    26542705        len = emu->audigy ? 0x100 : 0xa0;
    2655         emu->tram_val_saved = kmalloc(len * 4, GFP_KERNEL);
    2656         emu->tram_addr_saved = kmalloc(len * 4, GFP_KERNEL);
     2706        emu->tram_val_saved = kmalloc_array(len, 4, GFP_KERNEL);
     2707        emu->tram_addr_saved = kmalloc_array(len, 4, GFP_KERNEL);
    26572708        if (! emu->tram_val_saved || ! emu->tram_addr_saved)
    26582709                return -ENOMEM;
    26592710        len = emu->audigy ? 2 * 1024 : 2 * 512;
     2711#ifdef TARGET_OS2
     2712        emu->saved_icode = vmalloc(array_size(len, 4));
     2713#else
    26602714        emu->saved_icode = vmalloc(len * 4);
     2715#endif
    26612716        if (! emu->saved_icode)
    26622717                return -ENOMEM;
  • GPL/trunk/alsa-kernel/pci/emu10k1/emumixer.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
     
    1415 *  TODO:
    1516 *    --
    16  *
    17  *   This program is free software; you can redistribute it and/or modify
    18  *   it under the terms of the GNU General Public License as published by
    19  *   the Free Software Foundation; either version 2 of the License, or
    20  *   (at your option) any later version.
    21  *
    22  *   This program is distributed in the hope that it will be useful,
    23  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    24  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    25  *   GNU General Public License for more details.
    26  *
    27  *   You should have received a copy of the GNU General Public License
    28  *   along with this program; if not, write to the Free Software
    29  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    30  *
    3117 */
    3218
     
    8470 * each destination
    8571 */
    86 static char *emu1010_src_texts[] = {
     72static const char * const emu1010_src_texts[] = {
    8773        "Silence",
    8874        "Dock Mic A",
     
    142128/* 1616(m) cardbus */
    143129
    144 static char *emu1616_src_texts[] = {
     130static const char * const emu1616_src_texts[] = {
    145131        "Silence",
    146132        "Dock Mic A",
     
    198184 * List of data sources available for each destination
    199185 */
    200 static unsigned int emu1010_src_regs[] = {
     186static const unsigned int emu1010_src_regs[] = {
    201187        EMU_SRC_SILENCE,/* 0 */
    202188        EMU_SRC_DOCK_MIC_A1, /* 1 */
     
    255241
    256242/* 1616(m) cardbus */
    257 static unsigned int emu1616_src_regs[] = {
     243static const unsigned int emu1616_src_regs[] = {
    258244        EMU_SRC_SILENCE,
    259245        EMU_SRC_DOCK_MIC_A1,
     
    311297 * Each destination has an enum mixer control to choose a data source
    312298 */
    313 static unsigned int emu1010_output_dst[] = {
     299static const unsigned int emu1010_output_dst[] = {
    314300        EMU_DST_DOCK_DAC1_LEFT1, /* 0 */
    315301        EMU_DST_DOCK_DAC1_RIGHT1, /* 1 */
     
    339325
    340326/* 1616(m) cardbus */
    341 static unsigned int emu1616_output_dst[] = {
     327static const unsigned int emu1616_output_dst[] = {
    342328        EMU_DST_DOCK_DAC1_LEFT1,
    343329        EMU_DST_DOCK_DAC1_RIGHT1,
     
    365351 * Each destination has an enum mixer control to choose a data source
    366352 */
    367 static unsigned int emu1010_input_dst[] = {
     353static const unsigned int emu1010_input_dst[] = {
    368354        EMU_DST_ALICE2_EMU32_0,
    369355        EMU_DST_ALICE2_EMU32_1,
     
    394380{
    395381        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    396         char **items;
    397 
    398         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    399         uinfo->count = 1;
    400         if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) {
    401                 uinfo->value.enumerated.items = 49;
    402                 items = emu1616_src_texts;
    403         } else {
    404                 uinfo->value.enumerated.items = 53;
    405                 items = emu1010_src_texts;
    406         }
    407         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    408                 uinfo->value.enumerated.item =
    409                         uinfo->value.enumerated.items - 1;
    410         strcpy(uinfo->value.enumerated.name,
    411                items[uinfo->value.enumerated.item]);
    412         return 0;
     382
     383        if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616)
     384                return snd_ctl_enum_info(uinfo, 1, 49, emu1616_src_texts);
     385        else
     386                return snd_ctl_enum_info(uinfo, 1, 53, emu1010_src_texts);
    413387}
    414388
     
    511485}
    512486
    513 static struct snd_kcontrol_new snd_emu1010_output_enum_ctls[] __devinitdata = {
     487static const struct snd_kcontrol_new snd_emu1010_output_enum_ctls[] = {
    514488        EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Enum", 0),
    515489        EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Enum", 1),
     
    540514
    541515/* 1616(m) cardbus */
    542 static struct snd_kcontrol_new snd_emu1616_output_enum_ctls[] __devinitdata = {
     516static const struct snd_kcontrol_new snd_emu1616_output_enum_ctls[] = {
    543517        EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Enum", 0),
    544518        EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Enum", 1),
     
    572546}
    573547
    574 static struct snd_kcontrol_new snd_emu1010_input_enum_ctls[] __devinitdata = {
     548static const struct snd_kcontrol_new snd_emu1010_input_enum_ctls[] = {
    575549        EMU1010_SOURCE_INPUT("DSP 0 Capture Enum", 0),
    576550        EMU1010_SOURCE_INPUT("DSP 1 Capture Enum", 1),
     
    640614}
    641615
    642 static struct snd_kcontrol_new snd_emu1010_adc_pads[] __devinitdata = {
     616static const struct snd_kcontrol_new snd_emu1010_adc_pads[] = {
    643617        EMU1010_ADC_PADS("ADC1 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD1),
    644618        EMU1010_ADC_PADS("ADC2 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD2),
     
    688662}
    689663
    690 static struct snd_kcontrol_new snd_emu1010_dac_pads[] __devinitdata = {
     664static const struct snd_kcontrol_new snd_emu1010_dac_pads[] = {
    691665        EMU1010_DAC_PADS("DAC1 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD1),
    692666        EMU1010_DAC_PADS("DAC2 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD2),
     
    700674                                          struct snd_ctl_elem_info *uinfo)
    701675{
    702         static char *texts[4] = {
     676        static const char * const texts[4] = {
    703677                "44100", "48000", "SPDIF", "ADAT"
    704678        };
    705679               
    706         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    707         uinfo->count = 1;
    708         uinfo->value.enumerated.items = 4;
    709         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    710                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    711         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    712         return 0;
    713        
    714        
     680        return snd_ctl_enum_info(uinfo, 1, 4, texts);
    715681}
    716682
     
    816782}
    817783
    818 static struct snd_kcontrol_new snd_emu1010_internal_clock =
     784static const struct snd_kcontrol_new snd_emu1010_internal_clock =
    819785{
    820786        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE,
     
    827793};
    828794
     795static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
     796                                          struct snd_ctl_elem_info *uinfo)
     797{
     798        static const char * const texts[2] = {
     799                "SPDIF", "ADAT"
     800        };
     801
     802        return snd_ctl_enum_info(uinfo, 1, 2, texts);
     803}
     804
     805static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
     806                                        struct snd_ctl_elem_value *ucontrol)
     807{
     808        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     809
     810        ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
     811        return 0;
     812}
     813
     814static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
     815                                        struct snd_ctl_elem_value *ucontrol)
     816{
     817        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     818        unsigned int val;
     819        u32 tmp;
     820        int change = 0;
     821
     822        val = ucontrol->value.enumerated.item[0];
     823        /* Limit: uinfo->value.enumerated.items = 2; */
     824        if (val >= 2)
     825                return -EINVAL;
     826        change = (emu->emu1010.optical_out != val);
     827        if (change) {
     828                emu->emu1010.optical_out = val;
     829                tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
     830                        (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
     831                snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
     832        }
     833        return change;
     834}
     835
     836static const struct snd_kcontrol_new snd_emu1010_optical_out = {
     837        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE,
     838        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     839        .name =         "Optical Output Mode",
     840        .count =        1,
     841        .info =         snd_emu1010_optical_out_info,
     842        .get =          snd_emu1010_optical_out_get,
     843        .put =          snd_emu1010_optical_out_put
     844};
     845
     846static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
     847                                          struct snd_ctl_elem_info *uinfo)
     848{
     849        static const char * const texts[2] = {
     850                "SPDIF", "ADAT"
     851        };
     852
     853        return snd_ctl_enum_info(uinfo, 1, 2, texts);
     854}
     855
     856static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
     857                                        struct snd_ctl_elem_value *ucontrol)
     858{
     859        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     860
     861        ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
     862        return 0;
     863}
     864
     865static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
     866                                        struct snd_ctl_elem_value *ucontrol)
     867{
     868        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     869        unsigned int val;
     870        u32 tmp;
     871        int change = 0;
     872
     873        val = ucontrol->value.enumerated.item[0];
     874        /* Limit: uinfo->value.enumerated.items = 2; */
     875        if (val >= 2)
     876                return -EINVAL;
     877        change = (emu->emu1010.optical_in != val);
     878        if (change) {
     879                emu->emu1010.optical_in = val;
     880                tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
     881                        (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
     882                snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
     883        }
     884        return change;
     885}
     886
     887static const struct snd_kcontrol_new snd_emu1010_optical_in = {
     888        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE,
     889        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     890        .name =         "Optical Input Mode",
     891        .count =        1,
     892        .info =         snd_emu1010_optical_in_info,
     893        .get =          snd_emu1010_optical_in_get,
     894        .put =          snd_emu1010_optical_in_put
     895};
     896
    829897static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
    830898                                          struct snd_ctl_elem_info *uinfo)
    831899{
    832900#if 0
    833         static char *texts[4] = {
     901        static const char * const texts[4] = {
    834902                "Unknown1", "Unknown2", "Mic", "Line"
    835903        };
    836904#endif
    837         static char *texts[2] = {
     905        static const char * const texts[2] = {
    838906                "Mic", "Line"
    839907        };
    840908
    841         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    842         uinfo->count = 1;
    843         uinfo->value.enumerated.items = 2;
    844         if (uinfo->value.enumerated.item > 1)
    845                 uinfo->value.enumerated.item = 1;
    846         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    847         return 0;
     909        return snd_ctl_enum_info(uinfo, 1, 2, texts);
    848910}
    849911
     
    903965}
    904966
    905 static struct snd_kcontrol_new snd_audigy_i2c_capture_source =
     967static const struct snd_kcontrol_new snd_audigy_i2c_capture_source =
    906968{
    907969                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    9901052
    9911053
    992 static struct snd_kcontrol_new snd_audigy_i2c_volume_ctls[] __devinitdata = {
     1054static const struct snd_kcontrol_new snd_audigy_i2c_volume_ctls[] = {
    9931055        I2C_VOLUME("Mic Capture Volume", 0),
    9941056        I2C_VOLUME("Line Capture Volume", 0)
     
    9981060static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    9991061{
    1000         static char *texts[] = {"44100", "48000", "96000"};
    1001 
    1002         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    1003         uinfo->count = 1;
    1004         uinfo->value.enumerated.items = 3;
    1005         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    1006                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    1007         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    1008         return 0;
     1062        static const char * const texts[] = {"44100", "48000", "96000"};
     1063
     1064        return snd_ctl_enum_info(uinfo, 1, 3, texts);
    10091065}
    10101066
     
    10701126}
    10711127
    1072 static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
     1128static const struct snd_kcontrol_new snd_audigy_spdif_output_rate =
    10731129{
    10741130        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE,
     
    11081164}
    11091165
    1110 static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
     1166static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
    11111167{
    11121168        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     
    11181174};
    11191175
    1120 static struct snd_kcontrol_new snd_emu10k1_spdif_control =
     1176static const struct snd_kcontrol_new snd_emu10k1_spdif_control =
    11211177{
    11221178        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     
    12241280}
    12251281
    1226 static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
     1282static const struct snd_kcontrol_new snd_emu10k1_send_routing_control =
    12271283{
    12281284        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    12951351}
    12961352
    1297 static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
     1353static const struct snd_kcontrol_new snd_emu10k1_send_volume_control =
    12981354{
    12991355        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    13601416}
    13611417
    1362 static struct snd_kcontrol_new snd_emu10k1_attn_control =
     1418static const struct snd_kcontrol_new snd_emu10k1_attn_control =
    13631419{
    13641420        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    14321488}
    14331489
    1434 static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
     1490static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
    14351491{
    14361492        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    14991555
    15001556
    1501 static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
     1557static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
    15021558{
    15031559        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    15571613}
    15581614
    1559 static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
     1615static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
    15601616{
    15611617        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     
    16221678}
    16231679
    1624 static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
     1680static const struct snd_kcontrol_new snd_emu10k1_shared_spdif =
    16251681{
    16261682        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    16311687};
    16321688
    1633 static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
     1689static const struct snd_kcontrol_new snd_audigy_shared_spdif =
    16341690{
    16351691        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     
    16691725}
    16701726
    1671 static struct snd_kcontrol_new snd_audigy_capture_boost __devinitdata =
     1727static const struct snd_kcontrol_new snd_audigy_capture_boost =
    16721728{
    16731729        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
    1674         .name =         "Analog Capture Boost",
     1730        .name =         "Mic Extra Boost",
    16751731        .info =         snd_audigy_capture_boost_info,
    16761732        .get =          snd_audigy_capture_boost_get,
     
    17171773}
    17181774
    1719 int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
    1720                                 int pcm_device, int multi_device)
     1775int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
     1776                      int pcm_device, int multi_device)
    17211777{
    17221778        int err, pcm;
    17231779        struct snd_kcontrol *kctl;
    17241780        struct snd_card *card = emu->card;
    1725         char **c;
    1726         static char *emu10k1_remove_ctls[] = {
     1781        const char * const *c;
     1782        static const char * const emu10k1_remove_ctls[] = {
    17271783                /* no AC97 mono, surround, center/lfe */
    17281784                "Master Mono Playback Switch",
     
    17301786                "PCM Out Path & Mute",
    17311787                "Mono Output Select",
    1732                 "Front Playback Switch",
    1733                 "Front Playback Volume",
    17341788                "Surround Playback Switch",
    17351789                "Surround Playback Volume",
     
    17401794                NULL
    17411795        };
    1742         static char *emu10k1_rename_ctls[] = {
     1796        static const char * const emu10k1_rename_ctls[] = {
    17431797                "Surround Digital Playback Volume", "Surround Playback Volume",
    17441798                "Center Digital Playback Volume", "Center Playback Volume",
     
    17461800                NULL
    17471801        };
    1748         static char *audigy_remove_ctls[] = {
     1802        static const char * const audigy_remove_ctls[] = {
    17491803                /* Master/PCM controls on ac97 of Audigy has no effect */
    17501804                /* On the Audigy2 the AC97 playback is piped into
     
    17521806                "PCM Playback Switch",
    17531807                "PCM Playback Volume",
    1754                 "Master Mono Playback Switch",
    1755                 "Master Mono Playback Volume",
    17561808                "Master Playback Switch",
    17571809                "Master Playback Volume",
     
    17631815                "Capture Volume",
    17641816                "Mic Select",
     1817                "Headphone Playback Switch",
     1818                "Headphone Playback Volume",
     1819                "3D Control - Center",
     1820                "3D Control - Depth",
     1821                "3D Control - Switch",
    17651822                "Video Playback Switch",
    17661823                "Video Playback Volume",
    17671824                "Mic Playback Switch",
    17681825                "Mic Playback Volume",
     1826                "External Amplifier",
    17691827                NULL
    17701828        };
    1771         static char *audigy_rename_ctls[] = {
     1829        static const char * const audigy_rename_ctls[] = {
    17721830                /* use conventional names */
    17731831                "Wave Playback Volume", "PCM Playback Volume",
     
    17751833                "Wave Master Playback Volume", "Master Playback Volume",
    17761834                "AMic Playback Volume", "Mic Playback Volume",
     1835                "Master Mono Playback Switch", "Phone Output Playback Switch",
     1836                "Master Mono Playback Volume", "Phone Output Playback Volume",
    17771837                NULL
    17781838        };
    1779         static char *audigy_rename_ctls_i2c_adc[] = {
     1839        static const char * const audigy_rename_ctls_i2c_adc[] = {
    17801840                //"Analog Mix Capture Volume","OLD Analog Mix Capture Volume",
    17811841                "Line Capture Volume", "Analog Mix Capture Volume",
     
    17861846                NULL
    17871847        };
    1788         static char *audigy_remove_ctls_i2c_adc[] = {
     1848        static const char * const audigy_remove_ctls_i2c_adc[] = {
    17891849                /* On the Audigy2 ZS Notebook
    17901850                 * Capture via WM8775  */
     
    17951855                NULL
    17961856        };
    1797         static char *audigy_remove_ctls_1361t_adc[] = {
     1857        static const char * const audigy_remove_ctls_1361t_adc[] = {
    17981858                /* On the Audigy2 the AC97 playback is piped into
    17991859                 * the Philips ADC for 24bit capture */
    18001860                "PCM Playback Switch",
    18011861                "PCM Playback Volume",
    1802                 "Master Mono Playback Switch",
    1803                 "Master Mono Playback Volume",
    18041862                "Capture Source",
    18051863                "Capture Switch",
     
    18151873                NULL
    18161874        };
    1817         static char *audigy_rename_ctls_1361t_adc[] = {
     1875        static const char * const audigy_rename_ctls_1361t_adc[] = {
    18181876                "Master Playback Switch", "Master Capture Switch",
    18191877                "Master Playback Volume", "Master Capture Volume",
     
    18331891                "Video Playback Switch", "Video Capture Switch",
    18341892                "Video Playback Volume", "Video Capture Volume",
    1835 
     1893                "Master Mono Playback Switch", "Phone Output Playback Switch",
     1894                "Master Mono Playback Volume", "Phone Output Playback Volume",
    18361895                NULL
    18371896        };
     
    18401899                struct snd_ac97_bus *pbus;
    18411900                struct snd_ac97_template ac97;
    1842                 static struct snd_ac97_bus_ops ops = {
     1901                static const struct snd_ac97_bus_ops ops = {
    18431902                        .write = snd_emu10k1_ac97_write,
    18441903                        .read = snd_emu10k1_ac97_read,
     
    18561915                        if (emu->card_capabilities->ac97_chip == 1)
    18571916                                return err;
    1858                         snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
    1859                         snd_printd(KERN_INFO"          Proceeding without ac97 mixers...\n");
     1917                        dev_info(emu->card->dev,
     1918                                 "AC97 is optional on this board\n");
     1919                        dev_info(emu->card->dev,
     1920                                 "Proceeding without ac97 mixers...\n");
    18601921                        snd_device_free(emu->card, pbus);
    18611922                        goto no_ac97; /* FIXME: get rid of ugly gotos.. */
     
    18661927                        /* set capture source to mic */
    18671928                        snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
     1929                        /* set mono output (TAD) to mic */
     1930                        snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE,
     1931                                0x0200, 0x0200);
    18681932                        if (emu->card_capabilities->adc_1361t)
    18691933                                c = audigy_remove_ctls_1361t_adc;
     
    18801944                                snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
    18811945                                snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
     1946                                remove_ctl(card,"Front Playback Volume");
     1947                                remove_ctl(card,"Front Playback Switch");
    18821948                        }
    18831949                        /* remove unused AC97 controls */
     
    19141980                rename_ctl(card, c[0], c[1]);
    19151981
     1982        if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
     1983                remove_ctl(card, "Center Playback Volume");
     1984                remove_ctl(card, "LFE Playback Volume");
     1985                remove_ctl(card, "Wave Center Playback Volume");
     1986                remove_ctl(card, "Wave LFE Playback Volume");
     1987        }
    19161988        if (emu->card_capabilities->subsystem == 0x20071102) {  /* Audigy 4 Pro */
    19171989                rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
     
    19191991                rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
    19201992                rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
    1921                 remove_ctl(card, "Headphone Playback Switch");
    1922                 remove_ctl(card, "Headphone Playback Volume");
    1923                 remove_ctl(card, "3D Control - Center");
    1924                 remove_ctl(card, "3D Control - Depth");
    1925                 remove_ctl(card, "3D Control - Switch");
    19261993        }
    19271994        if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
     
    20762143                if (err < 0)
    20772144                        return err;
     2145                err = snd_ctl_add(card,
     2146                        snd_ctl_new1(&snd_emu1010_optical_out, emu));
     2147                if (err < 0)
     2148                        return err;
     2149                err = snd_ctl_add(card,
     2150                        snd_ctl_new1(&snd_emu1010_optical_in, emu));
     2151                if (err < 0)
     2152                        return err;
    20782153
    20792154        } else if (emu->card_capabilities->emu_model) {
     
    21112186                if (err < 0)
    21122187                        return err;
     2188                err = snd_ctl_add(card,
     2189                        snd_ctl_new1(&snd_emu1010_optical_out, emu));
     2190                if (err < 0)
     2191                        return err;
     2192                err = snd_ctl_add(card,
     2193                        snd_ctl_new1(&snd_emu1010_optical_in, emu));
     2194                if (err < 0)
     2195                        return err;
    21132196        }
    21142197
  • GPL/trunk/alsa-kernel/pci/emu10k1/emumpu401.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
    34 *  Routines for control of EMU10K1 MPU-401 in UART mode
    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
     
    6550#ifdef CONFIG_SND_DEBUG
    6651        if (timeout <= 0)
    67                 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
     52                dev_err(emu->card->dev,
     53                        "cmd: clear rx timeout (status = 0x%x)\n",
     54                        mpu401_read_stat(emu, mpu));
    6855#endif
    6956}
     
    142129        spin_unlock_irqrestore(&midi->input_lock, flags);
    143130        if (!ok) {
    144                 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
     131                dev_err(emu->card->dev,
     132                        "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
    145133                           cmd, emu->port,
    146134                           mpu401_read_stat(emu, midi),
     
    306294 */
    307295
    308 static struct snd_rawmidi_ops snd_emu10k1_midi_output =
     296static const struct snd_rawmidi_ops snd_emu10k1_midi_output =
    309297{
    310298        .open =         snd_emu10k1_midi_output_open,
     
    313301};
    314302
    315 static struct snd_rawmidi_ops snd_emu10k1_midi_input =
     303static const struct snd_rawmidi_ops snd_emu10k1_midi_input =
    316304{
    317305        .open =         snd_emu10k1_midi_input_open,
     
    327315}
    328316
    329 static int __devinit emu10k1_midi_init(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, int device, char *name)
     317static int emu10k1_midi_init(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, int device, char *name)
    330318{
    331319        struct snd_rawmidi *rmidi;
     
    350338}
    351339
    352 int __devinit snd_emu10k1_midi(struct snd_emu10k1 *emu)
     340int snd_emu10k1_midi(struct snd_emu10k1 *emu)
    353341{
    354342        struct snd_emu10k1_midi *midi = &emu->midi;
     
    367355}
    368356
    369 int __devinit snd_emu10k1_audigy_midi(struct snd_emu10k1 *emu)
     357int snd_emu10k1_audigy_midi(struct snd_emu10k1 *emu)
    370358{
    371359        struct snd_emu10k1_midi *midi;
  • GPL/trunk/alsa-kernel/pci/emu10k1/emupcm.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    1011 *  TODO:
    1112 *    --
    12  *
    13  *   This program is free software; you can redistribute it and/or modify
    14  *   it under the terms of the GNU General Public License as published by
    15  *   the Free Software Foundation; either version 2 of the License, or
    16  *   (at your option) any later version.
    17  *
    18  *   This program is distributed in the hope that it will be useful,
    19  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  *   GNU General Public License for more details.
    22  *
    23  *   You should have received a copy of the GNU General Public License
    24  *   along with this program; if not, write to the Free Software
    25  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    26  *
    2713 */
    2814
     
    4531                return;
    4632#if 0
    47         printk(KERN_DEBUG "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
     33        dev_dbg(emu->card->dev,
     34                "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
    4835                        epcm->substream->runtime->hw->pointer(emu, epcm->substream),
    4936                        snd_pcm_lib_period_bytes(epcm->substream),
     
    148135                if (err < 0) {
    149136                        /*
    150                         printk(KERN_DEBUG "pcm_channel_alloc: "
     137                        dev_dbg(emu->card->dev, "pcm_channel_alloc: "
    151138                               "failed extra: voices=%d, frame=%d\n",
    152139                               voices, frame);
     
    164151}
    165152
    166 static unsigned int capture_period_sizes[31] = {
     153static const unsigned int capture_period_sizes[31] = {
    167154        384,    448,    512,    640,
    168155        384*2,  448*2,  512*2,  640*2,
     
    175162};
    176163
    177 static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = {
     164static const struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = {
    178165        .count = 31,
    179166        .list = capture_period_sizes,
     
    181168};
    182169
    183 static unsigned int capture_rates[8] = {
     170static const unsigned int capture_rates[8] = {
    184171        8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
    185172};
    186173
    187 static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = {
     174static const struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = {
    188175        .count = 8,
    189176        .list = capture_rates,
     
    290277        unsigned int silent_page, tmp;
    291278        int voice, stereo, w_16;
    292         unsigned char attn, send_amount[8];
     279        unsigned char send_amount[8];
    293280        unsigned char send_routing[8];
    294281        unsigned long flags;
     
    313300        /* volume parameters */
    314301        if (extra) {
    315                 attn = 0;
    316302                memset(send_routing, 0, sizeof(send_routing));
    317303                send_routing[0] = 0;
     
    380366        snd_emu10k1_ptr_write(emu, Z2, voice, 0);
    381367        /* invalidate maps */
    382         silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK;
     368        silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
    383369        snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
    384370        snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
     
    411397        struct snd_pcm_runtime *runtime = substream->runtime;
    412398        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     399        size_t alloc_size;
    413400        int err;
    414401
    415402        if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0)
    416403                return err;
    417         if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
     404
     405        alloc_size = params_buffer_bytes(hw_params);
     406        if (emu->iommu_workaround)
     407                alloc_size += EMUPAGESIZE;
     408        err = snd_pcm_lib_malloc_pages(substream, alloc_size);
     409        if (err < 0)
    418410                return err;
     411        if (emu->iommu_workaround && runtime->dma_bytes >= EMUPAGESIZE)
     412                runtime->dma_bytes -= EMUPAGESIZE;
    419413        if (err > 0) {  /* change */
    420414                int mapped;
     
    556550}
    557551
    558 static struct snd_pcm_hardware snd_emu10k1_efx_playback =
     552static const struct snd_pcm_hardware snd_emu10k1_efx_playback =
    559553{
    560554        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED |
     
    575569        .fifo_size =            0,
    576570};
    577 
    578 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream *substream,
    579                                          struct snd_pcm_hw_params *hw_params)
    580 {
    581         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    582 }
    583 
    584 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream *substream)
    585 {
    586         return snd_pcm_lib_free_pages(substream);
    587 }
    588571
    589572static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
     
    762745
    763746        /*
    764         printk(KERN_DEBUG "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
     747        dev_dbg(emu->card->dev,
     748                "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
    765749               (int)emu, cmd, substream->ops->pointer(substream))
    766750        */
     
    770754                snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);     /* do we need this? */
    771755                snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
    772                 /* follow thru */
     756                fallthrough;
    773757        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    774758        case SNDRV_PCM_TRIGGER_RESUME:
     
    816800                snd_emu10k1_intr_enable(emu, epcm->capture_inte);
    817801                /*
    818                 printk(KERN_DEBUG "adccr = 0x%x, adcbs = 0x%x\n",
     802                dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
    819803                       epcm->adccr, epcm->adcbs);
    820804                */
     
    827811                                snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
    828812                                snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
    829                                 snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm->capture_cr_val, epcm->capture_cr_val2);
     813                                dev_dbg(emu->card->dev,
     814                                        "cr_val=0x%x, cr_val2=0x%x\n",
     815                                        epcm->capture_cr_val,
     816                                        epcm->capture_cr_val2);
    830817                        } else
    831818                                snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
     
    890877#endif
    891878        /*
    892         printk(KERN_DEBUG
     879        dev_dbg(emu->card->dev,
    893880               "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
    894881               (long)ptr, (long)runtime->buffer_size,
     
    916903                }
    917904                snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
    918 
    919                 /* follow thru */
     905                fallthrough;
    920906        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    921907        case SNDRV_PCM_TRIGGER_RESUME:
     
    971957 */
    972958
    973 static struct snd_pcm_hardware snd_emu10k1_playback =
     959static const struct snd_pcm_hardware snd_emu10k1_playback =
    974960{
    975961        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    995981 */
    996982
    997 static struct snd_pcm_hardware snd_emu10k1_capture =
     983static const struct snd_pcm_hardware snd_emu10k1_capture =
    998984{
    999985        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    10151001};
    10161002
    1017 static struct snd_pcm_hardware snd_emu10k1_capture_efx =
     1003static const struct snd_pcm_hardware snd_emu10k1_capture_efx =
    10181004{
    10191005        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    11281114        struct snd_emu10k1_pcm_mixer *mix;
    11291115        struct snd_pcm_runtime *runtime = substream->runtime;
    1130         int i, err;
     1116        int i, err, sample_rate;
    11311117
    11321118        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     
    11441130        }
    11451131        if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) {
     1132                kfree(epcm);
     1133                return err;
     1134        }
     1135        if (emu->card_capabilities->emu_model && emu->emu1010.internal_clock == 0)
     1136                sample_rate = 44100;
     1137        else
     1138                sample_rate = 48000;
     1139        err = snd_pcm_hw_rule_noresample(runtime, sample_rate);
     1140        if (err < 0) {
    11461141                kfree(epcm);
    11471142                return err;
     
    13061301                                runtime->hw.channels_max = 16;
    13071302                        break;
    1308                 };
     1303                }
    13091304#endif
    13101305#if 0
     
    13511346}
    13521347
    1353 static struct snd_pcm_ops snd_emu10k1_playback_ops = {
     1348static const struct snd_pcm_ops snd_emu10k1_playback_ops = {
    13541349        .open =                 snd_emu10k1_playback_open,
    13551350        .close =                snd_emu10k1_playback_close,
    1356         .ioctl =                snd_pcm_lib_ioctl,
    13571351        .hw_params =            snd_emu10k1_playback_hw_params,
    13581352        .hw_free =              snd_emu10k1_playback_hw_free,
     
    13601354        .trigger =              snd_emu10k1_playback_trigger,
    13611355        .pointer =              snd_emu10k1_playback_pointer,
    1362         .page =                 snd_pcm_sgbuf_ops_page,
    13631356};
    13641357
    1365 static struct snd_pcm_ops snd_emu10k1_capture_ops = {
     1358static const struct snd_pcm_ops snd_emu10k1_capture_ops = {
    13661359        .open =                 snd_emu10k1_capture_open,
    13671360        .close =                snd_emu10k1_capture_close,
    1368         .ioctl =                snd_pcm_lib_ioctl,
    1369         .hw_params =            snd_emu10k1_capture_hw_params,
    1370         .hw_free =              snd_emu10k1_capture_hw_free,
    13711361        .prepare =              snd_emu10k1_capture_prepare,
    13721362        .trigger =              snd_emu10k1_capture_trigger,
     
    13751365
    13761366/* EFX playback */
    1377 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
     1367static const struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
    13781368        .open =                 snd_emu10k1_efx_playback_open,
    13791369        .close =                snd_emu10k1_efx_playback_close,
    1380         .ioctl =                snd_pcm_lib_ioctl,
    13811370        .hw_params =            snd_emu10k1_playback_hw_params,
    13821371        .hw_free =              snd_emu10k1_efx_playback_hw_free,
     
    13841373        .trigger =              snd_emu10k1_efx_playback_trigger,
    13851374        .pointer =              snd_emu10k1_efx_playback_pointer,
    1386         .page =                 snd_pcm_sgbuf_ops_page,
    13871375};
    13881376
    1389 int __devinit snd_emu10k1_pcm(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1377int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device)
    13901378{
    13911379        struct snd_pcm *pcm;
    13921380        struct snd_pcm_substream *substream;
    13931381        int err;
    1394 
    1395         if (rpcm)
    1396                 *rpcm = NULL;
    13971382
    13981383        if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0)
     
    14091394        emu->pcm = pcm;
    14101395
     1396        /* playback substream can't use managed buffers due to alignment */
    14111397        for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
    1412                 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
    1413                         return err;
     1398                snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
     1399                                              &emu->pci->dev,
     1400                                              64*1024, 64*1024);
    14141401
    14151402        for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next)
    1416                 snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1417 
    1418         if (rpcm)
    1419                 *rpcm = pcm;
    1420 
    1421         return 0;
    1422 }
    1423 
    1424 int __devinit snd_emu10k1_pcm_multi(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1403                snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
     1404                                           &emu->pci->dev, 64*1024, 64*1024);
     1405
     1406        return 0;
     1407}
     1408
     1409int snd_emu10k1_pcm_multi(struct snd_emu10k1 *emu, int device)
    14251410{
    14261411        struct snd_pcm *pcm;
    14271412        struct snd_pcm_substream *substream;
    14281413        int err;
    1429 
    1430         if (rpcm)
    1431                 *rpcm = NULL;
    14321414
    14331415        if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0)
     
    14441426
    14451427        for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
    1446                 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
    1447                         return err;
    1448 
    1449         if (rpcm)
    1450                 *rpcm = pcm;
    1451 
    1452         return 0;
    1453 }
    1454 
    1455 
    1456 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
     1428                snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
     1429                                              &emu->pci->dev,
     1430                                              64*1024, 64*1024);
     1431
     1432        return 0;
     1433}
     1434
     1435
     1436static const struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
    14571437        .open =                 snd_emu10k1_capture_mic_open,
    14581438        .close =                snd_emu10k1_capture_mic_close,
    1459         .ioctl =                snd_pcm_lib_ioctl,
    1460         .hw_params =            snd_emu10k1_capture_hw_params,
    1461         .hw_free =              snd_emu10k1_capture_hw_free,
    14621439        .prepare =              snd_emu10k1_capture_prepare,
    14631440        .trigger =              snd_emu10k1_capture_trigger,
     
    14651442};
    14661443
    1467 int __devinit snd_emu10k1_pcm_mic(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1444int snd_emu10k1_pcm_mic(struct snd_emu10k1 *emu, int device)
    14681445{
    14691446        struct snd_pcm *pcm;
    14701447        int err;
    1471 
    1472         if (rpcm)
    1473                 *rpcm = NULL;
    14741448
    14751449        if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0)
     
    14841458        emu->pcm_mic = pcm;
    14851459
    1486         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1487 
    1488         if (rpcm)
    1489                 *rpcm = pcm;
     1460        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
     1461                                       64*1024, 64*1024);
     1462
    14901463        return 0;
    14911464}
     
    15461519}
    15471520
    1548 static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = {
     1521static const struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = {
    15491522        .iface = SNDRV_CTL_ELEM_IFACE_PCM,
    15501523        .name = "Captured FX8010 Outputs",
     
    15541527};
    15551528
    1556 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
     1529static const struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
    15571530        .open =                 snd_emu10k1_capture_efx_open,
    15581531        .close =                snd_emu10k1_capture_efx_close,
    1559         .ioctl =                snd_pcm_lib_ioctl,
    1560         .hw_params =            snd_emu10k1_capture_hw_params,
    1561         .hw_free =              snd_emu10k1_capture_hw_free,
    15621532        .prepare =              snd_emu10k1_capture_prepare,
    15631533        .trigger =              snd_emu10k1_capture_trigger,
     
    15841554{
    15851555        /*
    1586         printk(KERN_DEBUG "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
     1556        dev_dbg(emu->card->dev,
     1557                "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
    15871558               "src = 0x%p, count = 0x%x\n",
    15881559               dst_left, dst_right, src, count);
     
    16351606        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    16361607
    1637         snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy);
    1638         return 0;
    1639 }
    1640 
    1641 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream *substream,
    1642                                                  struct snd_pcm_hw_params *hw_params)
    1643 {
    1644         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
     1608        return snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec,
     1609                                                  fx8010_pb_trans_copy);
    16451610}
    16461611
     
    16531618        for (i = 0; i < pcm->channels; i++)
    16541619                snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);
    1655         snd_pcm_lib_free_pages(substream);
    16561620        return 0;
    16571621}
     
    16651629       
    16661630        /*
    1667         printk(KERN_DEBUG "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
     1631        dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
    16681632               "buffer_size = 0x%x (0x%x)\n",
    16691633               emu->fx8010.etram_pages, runtime->dma_area,
     
    17191683        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    17201684        case SNDRV_PCM_TRIGGER_SUSPEND:
    1721                 snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL;
     1685                snd_emu10k1_fx8010_unregister_irq_handler(emu, &pcm->irq);
    17221686                snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);
    17231687                pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
     
    17451709}
    17461710
    1747 static struct snd_pcm_hardware snd_emu10k1_fx8010_playback =
     1711static const struct snd_pcm_hardware snd_emu10k1_fx8010_playback =
    17481712{
    17491713        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    17501714                                 SNDRV_PCM_INFO_RESUME |
    1751                                  /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE),
     1715                                 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE |
     1716                                 SNDRV_PCM_INFO_SYNC_APPLPTR),
    17521717        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    17531718        .rates =                SNDRV_PCM_RATE_48000,
     
    17941759}
    17951760
    1796 static struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops = {
     1761static const struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops = {
    17971762        .open =                 snd_emu10k1_fx8010_playback_open,
    17981763        .close =                snd_emu10k1_fx8010_playback_close,
    1799         .ioctl =                snd_pcm_lib_ioctl,
    1800         .hw_params =            snd_emu10k1_fx8010_playback_hw_params,
    18011764        .hw_free =              snd_emu10k1_fx8010_playback_hw_free,
    18021765        .prepare =              snd_emu10k1_fx8010_playback_prepare,
     
    18061769};
    18071770
    1808 int __devinit snd_emu10k1_pcm_efx(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1771int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device)
    18091772{
    18101773        struct snd_pcm *pcm;
     
    18121775        int err;
    18131776
    1814         if (rpcm)
    1815                 *rpcm = NULL;
    1816 
    18171777        if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0)
    18181778                return err;
     
    18261786        strcpy(pcm->name, "Multichannel Capture/PT Playback");
    18271787        emu->pcm_efx = pcm;
    1828         if (rpcm)
    1829                 *rpcm = pcm;
    18301788
    18311789        /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
     
    18581816                return -ENOMEM;
    18591817        kctl->id.device = device;
    1860         snd_ctl_add(emu->card, kctl);
    1861 
    1862         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1863 
    1864         return 0;
    1865 }
     1818        err = snd_ctl_add(emu->card, kctl);
     1819        if (err < 0)
     1820                return err;
     1821
     1822        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
     1823                                       64*1024, 64*1024);
     1824
     1825        return 0;
     1826}
  • GPL/trunk/alsa-kernel/pci/emu10k1/emuproc.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    1213 *  TODO:
    1314 *    --
    14  *
    15  *   This program is free software; you can redistribute it and/or modify
    16  *   it under the terms of the GNU General Public License as published by
    17  *   the Free Software Foundation; either version 2 of the License, or
    18  *   (at your option) any later version.
    19  *
    20  *   This program is distributed in the hope that it will be useful,
    21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23  *   GNU General Public License for more details.
    24  *
    25  *   You should have received a copy of the GNU General Public License
    26  *   along with this program; if not, write to the Free Software
    27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    28  *
    2915 */
    3016
     
    3521#include "p16v.h"
    3622
    37 #ifdef CONFIG_PROC_FS
    3823static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,
    3924                                          struct snd_info_buffer *buffer,
     
    4227                                          int rate_reg)
    4328{
    44         static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
    45         static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    46         static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
    47         static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
     29        static const char * const clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
     30        static const int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
     31        static const char * const channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
     32        static const char * const emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
    4833        unsigned int status, rate = 0;
    4934       
     
    8368{
    8469        /* FIXME - output names are in emufx.c too */
    85         static char *creative_outs[32] = {
     70        static const char * const creative_outs[32] = {
    8671                /* 00 */ "AC97 Left",
    8772                /* 01 */ "AC97 Right",
     
    118103        };
    119104
    120         static char *audigy_outs[64] = {
     105        static const char * const audigy_outs[64] = {
    121106                /* 00 */ "Digital Front Left",
    122107                /* 01 */ "Digital Front Right",
     
    137122                /* 16 */ "AC97 Front Left",
    138123                /* 17 */ "AC97 Front Right",
    139                 /* 18 */ "ADC Caputre Left",
     124                /* 18 */ "ADC Capture Left",
    140125                /* 19 */ "ADC Capture Right",
    141126                /* 20 */ "???",
     
    188173        unsigned int val, val1;
    189174        int nefx = emu->audigy ? 64 : 32;
    190         char **outputs = emu->audigy ? audigy_outs : creative_outs;
     175        const char * const *outputs = emu->audigy ? audigy_outs : creative_outs;
    191176        int idx;
    192177       
     
    242227        u32 value;
    243228        u32 value2;
    244         unsigned long flags;
    245229        u32 rate;
    246230
    247231        if (emu->card_capabilities->emu_model) {
    248                 spin_lock_irqsave(&emu->emu_lock, flags);
    249232                snd_emu1010_fpga_read(emu, 0x38, &value);
    250                 spin_unlock_irqrestore(&emu->emu_lock, flags);
    251233                if ((value & 0x1) == 0) {
    252                         spin_lock_irqsave(&emu->emu_lock, flags);
    253234                        snd_emu1010_fpga_read(emu, 0x2a, &value);
    254235                        snd_emu1010_fpga_read(emu, 0x2b, &value2);
    255                         spin_unlock_irqrestore(&emu->emu_lock, flags);
    256236                        rate = 0x1770000 / (((value << 5) | value2)+1);
    257237                        snd_iprintf(buffer, "ADAT Locked : %u\n", rate);
     
    259239                        snd_iprintf(buffer, "ADAT Unlocked\n");
    260240                }
    261                 spin_lock_irqsave(&emu->emu_lock, flags);
    262241                snd_emu1010_fpga_read(emu, 0x20, &value);
    263                 spin_unlock_irqrestore(&emu->emu_lock, flags);
    264242                if ((value & 0x4) == 0) {
    265                         spin_lock_irqsave(&emu->emu_lock, flags);
    266243                        snd_emu1010_fpga_read(emu, 0x28, &value);
    267244                        snd_emu1010_fpga_read(emu, 0x29, &value2);
    268                         spin_unlock_irqrestore(&emu->emu_lock, flags);
    269245                        rate = 0x1770000 / (((value << 5) | value2)+1);
    270246                        snd_iprintf(buffer, "SPDIF Locked : %d\n", rate);
     
    287263                                  struct snd_info_buffer *buffer)
    288264{
    289         static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
     265        static const int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
    290266        struct snd_emu10k1 *emu = entry->private_data;
    291267        unsigned int val, tmp, n;
    292268        val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
    293         tmp = (val >> 16) & 0x8;
    294269        for (n = 0; n < 4; n++) {
    295270                tmp = val >> (16 + (n*4));
     
    411386        struct snd_emu10k1 *emu = entry->private_data;
    412387        u32 value;
    413         unsigned long flags;
    414388        int i;
    415389        snd_iprintf(buffer, "EMU1010 Registers:\n\n");
    416390
    417391        for(i = 0; i < 0x40; i+=1) {
    418                 spin_lock_irqsave(&emu->emu_lock, flags);
    419392                snd_emu1010_fpga_read(emu, i, &value);
    420                 spin_unlock_irqrestore(&emu->emu_lock, flags);
    421393                snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f);
    422394        }
     
    574546#endif
    575547
    576 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
     548static const struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
    577549        .read = snd_emu10k1_fx8010_read,
    578550};
    579551
    580 int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
     552int snd_emu10k1_proc_init(struct snd_emu10k1 *emu)
    581553{
    582554        struct snd_info_entry *entry;
    583555#ifdef CONFIG_SND_DEBUG
    584556        if (emu->card_capabilities->emu_model) {
    585                 if (! snd_card_proc_new(emu->card, "emu1010_regs", &entry))
    586                         snd_info_set_text_ops(entry, emu, snd_emu_proc_emu1010_reg_read);
    587         }
    588         if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
    589                 snd_info_set_text_ops(entry, emu, snd_emu_proc_io_reg_read);
    590                 entry->c.text.write = snd_emu_proc_io_reg_write;
    591                 entry->mode |= S_IWUSR;
    592         }
    593         if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
    594                 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00a);
    595                 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
    596                 entry->mode |= S_IWUSR;
    597         }
    598         if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
    599                 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00b);
    600                 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
    601                 entry->mode |= S_IWUSR;
    602         }
    603         if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
    604                 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20a);
    605                 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
    606                 entry->mode |= S_IWUSR;
    607         }
    608         if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
    609                 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20b);
    610                 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
    611                 entry->mode |= S_IWUSR;
    612         }
    613         if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) {
    614                 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20c);
    615                 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
    616                 entry->mode |= S_IWUSR;
    617         }
     557                snd_card_ro_proc_new(emu->card, "emu1010_regs",
     558                                     emu, snd_emu_proc_emu1010_reg_read);
     559        }
     560        snd_card_rw_proc_new(emu->card, "io_regs", emu,
     561                             snd_emu_proc_io_reg_read,
     562                             snd_emu_proc_io_reg_write);
     563        snd_card_rw_proc_new(emu->card, "ptr_regs00a", emu,
     564                             snd_emu_proc_ptr_reg_read00a,
     565                             snd_emu_proc_ptr_reg_write00);
     566        snd_card_rw_proc_new(emu->card, "ptr_regs00b", emu,
     567                             snd_emu_proc_ptr_reg_read00b,
     568                             snd_emu_proc_ptr_reg_write00);
     569        snd_card_rw_proc_new(emu->card, "ptr_regs20a", emu,
     570                             snd_emu_proc_ptr_reg_read20a,
     571                             snd_emu_proc_ptr_reg_write20);
     572        snd_card_rw_proc_new(emu->card, "ptr_regs20b", emu,
     573                             snd_emu_proc_ptr_reg_read20b,
     574                             snd_emu_proc_ptr_reg_write20);
     575        snd_card_rw_proc_new(emu->card, "ptr_regs20c", emu,
     576                             snd_emu_proc_ptr_reg_read20c,
     577                             snd_emu_proc_ptr_reg_write20);
    618578#endif
    619579       
    620         if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
    621                 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_read);
    622 
    623         if (emu->card_capabilities->emu10k2_chip) {
    624                 if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
    625                         snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_spdif_read);
    626         }
    627         if (emu->card_capabilities->ca0151_chip) {
    628                 if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
    629                         snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_rates_read);
    630         }
    631 
    632         if (! snd_card_proc_new(emu->card, "voices", &entry))
    633                 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_voices_read);
     580        snd_card_ro_proc_new(emu->card, "emu10k1", emu, snd_emu10k1_proc_read);
     581
     582        if (emu->card_capabilities->emu10k2_chip)
     583                snd_card_ro_proc_new(emu->card, "spdif-in", emu,
     584                                     snd_emu10k1_proc_spdif_read);
     585        if (emu->card_capabilities->ca0151_chip)
     586                snd_card_ro_proc_new(emu->card, "capture-rates", emu,
     587                                     snd_emu10k1_proc_rates_read);
     588
     589        snd_card_ro_proc_new(emu->card, "voices", emu,
     590                             snd_emu10k1_proc_voices_read);
    634591
    635592        if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
    636593                entry->content = SNDRV_INFO_CONTENT_DATA;
    637594                entry->private_data = emu;
    638                 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
     595                entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
    639596                entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
    640597                entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
     
    643600                entry->content = SNDRV_INFO_CONTENT_DATA;
    644601                entry->private_data = emu;
    645                 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
     602                entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
    646603                entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
    647604                entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
     
    650607                entry->content = SNDRV_INFO_CONTENT_DATA;
    651608                entry->private_data = emu;
    652                 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
     609                entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
    653610                entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
    654611                entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
     
    657614                entry->content = SNDRV_INFO_CONTENT_DATA;
    658615                entry->private_data = emu;
    659                 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
     616                entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
    660617                entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
    661618                entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
    662619        }
    663         if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
    664                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    665                 entry->private_data = emu;
    666                 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
    667                 entry->c.text.read = snd_emu10k1_proc_acode_read;
    668         }
     620        snd_card_ro_proc_new(emu->card, "fx8010_acode", emu,
     621                             snd_emu10k1_proc_acode_read);
    669622        return 0;
    670623}
    671 #endif /* CONFIG_PROC_FS */
  • GPL/trunk/alsa-kernel/pci/emu10k1/io.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    910 *  TODO:
    1011 *    --
    11  *
    12  *   This program is free software; you can redistribute it and/or modify
    13  *   it under the terms of the GNU General Public License as published by
    14  *   the Free Software Foundation; either version 2 of the License, or
    15  *   (at your option) any later version.
    16  *
    17  *   This program is distributed in the hope that it will be useful,
    18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  *   GNU General Public License for more details.
    21  *
    22  *   You should have received a copy of the GNU General Public License
    23  *   along with this program; if not, write to the Free Software
    24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    25  *
    2612 */
    2713
     
    3016#include <sound/emu10k1.h>
    3117#include <linux/delay.h>
     18#include <linux/export.h>
    3219#include "p17v.h"
    3320
     
    7158        unsigned int mask;
    7259
    73         if (!emu) {
    74                 snd_printk(KERN_ERR "ptr_write: emu is null!\n");
    75                 dump_stack();
     60        if (snd_BUG_ON(!emu))
    7661                return;
    77         }
    7862        mask = emu->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK;
    7963        regptr = ((reg << 16) & mask) | (chn & PTR_CHANNELNUM_MASK);
     
    10286EXPORT_SYMBOL(snd_emu10k1_ptr_write);
    10387
    104 unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu,
    105                                           unsigned int reg,
     88unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, 
     89                                          unsigned int reg, 
    10690                                          unsigned int chn)
    10791{
    10892        unsigned long flags;
    10993        unsigned int regptr, val;
    110 
     94 
    11195        regptr = (reg << 16) | chn;
    11296
     
    118102}
    119103
    120 void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu,
    121                                    unsigned int reg,
    122                                    unsigned int chn,
     104void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu, 
     105                                   unsigned int reg, 
     106                                   unsigned int chn, 
    123107                                   unsigned int data)
    124108{
     
    199183
    200184        if ((reg > 0x7f) || (value > 0x1ff)) {
    201                 snd_printk(KERN_ERR "i2c_write: invalid values.\n");
     185                dev_err(emu->card->dev, "i2c_write: invalid values.\n");
    202186                return -EINVAL;
    203187        }
     
    227211
    228212                        if (timeout > 1000) {
    229                                 snd_printk(KERN_WARNING
     213                                dev_warn(emu->card->dev,
    230214                                           "emu10k1:I2C:timeout status=0x%x\n",
    231215                                           status);
     
    239223
    240224        if (retry == 10) {
    241                 snd_printk(KERN_ERR "Writing to ADC failed!\n");
    242                 snd_printk(KERN_ERR "status=0x%x, reg=%d, value=%d\n",
     225                dev_err(emu->card->dev, "Writing to ADC failed!\n");
     226                dev_err(emu->card->dev, "status=0x%x, reg=%d, value=%d\n",
    243227                        status, reg, value);
    244228                /* dump_stack(); */
    245229                err = -EINVAL;
    246230        }
    247 
     231   
    248232        spin_unlock(&emu->i2c_lock);
    249233        return err;
     
    527511unsigned int snd_emu10k1_rate_to_pitch(unsigned int rate)
    528512{
    529         static u32 logMagTable[128] = {
     513        static const u32 logMagTable[128] = {
    530514                0x00000, 0x02dfc, 0x05b9e, 0x088e6, 0x0b5d6, 0x0e26f, 0x10eb3, 0x13aa2,
    531515                0x1663f, 0x1918a, 0x1bc84, 0x1e72e, 0x2118b, 0x23b9a, 0x2655d, 0x28ed5,
     
    545529                0xf4463, 0xf5c2a, 0xf73da, 0xf8b71, 0xfa2f0, 0xfba57, 0xfd1a7, 0xfe8df
    546530        };
    547         static char logSlopeTable[128] = {
     531        static const char logSlopeTable[128] = {
    548532                0x5c, 0x5c, 0x5b, 0x5a, 0x5a, 0x59, 0x58, 0x58,
    549533                0x57, 0x56, 0x56, 0x55, 0x55, 0x54, 0x53, 0x53,
  • GPL/trunk/alsa-kernel/pci/emu10k1/irq.c

    r305 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    910 *  TODO:
    1011 *    --
    11  *
    12  *   This program is free software; you can redistribute it and/or modify
    13  *   it under the terms of the GNU General Public License as published by
    14  *   the Free Software Foundation; either version 2 of the License, or
    15  *   (at your option) any later version.
    16  *
    17  *   This program is distributed in the hope that it will be useful,
    18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  *   GNU General Public License for more details.
    21  *
    22  *   You should have received a copy of the GNU General Public License
    23  *   along with this program; if not, write to the Free Software
    24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    25  *
    2612 */
    2713
     
    4228                handled = 1;
    4329                if ((status & 0xffffffff) == 0xffffffff) {
    44                         snd_printk(KERN_INFO "snd-emu10k1: Suspected sound card removal\n");
     30                        dev_info(emu->card->dev,
     31                                 "Suspected sound card removal\n");
    4532                        break;
    4633                }
    4734                if (status & IPR_PCIERROR) {
    48                         snd_printk(KERN_ERR "interrupt: PCI error\n");
     35                        dev_err(emu->card->dev, "interrupt: PCI error\n");
    4936                        snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
    5037                        status &= ~IPR_PCIERROR;
     
    158145                                struct snd_emu10k1_voice *cvoice = &(emu->p16v_capture_voice);
    159146
    160                                 //printk(KERN_INFO "status2=0x%x\n", status2);
     147                                /* dev_dbg(emu->card->dev, "status2=0x%x\n", status2); */
    161148                                orig_status2 = status2;
    162149                                if(status2 & mask) {
     
    164151                                                snd_pcm_period_elapsed(pvoice->epcm->substream);
    165152                                        } else {
    166                                                 snd_printk(KERN_ERR "p16v: status: 0x%08x, mask=0x%08x, pvoice=%p, use=%d\n", status2, mask, pvoice, pvoice->use);
     153                                                dev_err(emu->card->dev,
     154                                                        "p16v: status: 0x%08x, mask=0x%08x, pvoice=%p, use=%d\n",
     155                                                        status2, mask, pvoice,
     156                                                        pvoice->use);
    167157                                        }
    168158                                }
    169159                                if(status2 & 0x110000) {
    170                                         //printk(KERN_INFO "capture int found\n");
     160                                        /* dev_info(emu->card->dev, "capture int found\n"); */
    171161                                        if(cvoice->use) {
    172                                                 //printk(KERN_INFO "capture period_elapsed\n");
     162                                                /* dev_info(emu->card->dev, "capture period_elapsed\n"); */
    173163                                                snd_pcm_period_elapsed(cvoice->epcm->substream);
    174164                                        }
     
    181171                if (status) {
    182172                        unsigned int bits;
    183                         snd_printk(KERN_ERR "emu10k1: unhandled interrupt: 0x%08x\n", status);
     173                        dev_err(emu->card->dev,
     174                                "unhandled interrupt: 0x%08x\n", status);
    184175                        //make sure any interrupts we don't handle are disabled:
    185176                        bits = INTE_FXDSPENABLE |
     
    203194        }
    204195        if (timeout == 1000)
    205                 snd_printk(KERN_INFO "emu10k1 irq routine failure\n");
     196                dev_info(emu->card->dev, "emu10k1 irq routine failure\n");
    206197
    207198        return IRQ_RETVAL(handled);
  • GPL/trunk/alsa-kernel/pci/emu10k1/memory.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    45 *
    56 *  EMU10K1 memory page allocation (PTB area)
    6  *
    7  *
    8  *   This program is free software; you can redistribute it and/or modify
    9  *   it under the terms of the GNU General Public License as published by
    10  *   the Free Software Foundation; either version 2 of the License, or
    11  *   (at your option) any later version.
    12  *
    13  *   This program is distributed in the hope that it will be useful,
    14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
    17  *
    18  *   You should have received a copy of the GNU General Public License
    19  *   along with this program; if not, write to the Free Software
    20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    21  *
    227 */
    238
     
    2611#include <linux/time.h>
    2712#include <linux/mutex.h>
     13#include <linux/export.h>
    2814
    2915#include <sound/core.h>
     
    3420 */
    3521#define __set_ptb_entry(emu,page,addr) \
    36         (((u32 *)(emu)->ptb_pages.area)[page] = cpu_to_le32(((addr) << 1) | (page)))
     22        (((__le32 *)(emu)->ptb_pages.area)[page] = \
     23         cpu_to_le32(((addr) << (emu->address_mode)) | (page)))
     24#define __get_ptb_entry(emu, page) \
     25        (le32_to_cpu(((__le32 *)(emu)->ptb_pages.area)[page]))
    3726
    3827#define UNIT_PAGES              (PAGE_SIZE / EMUPAGESIZE)
    39 #define MAX_ALIGN_PAGES         (MAXPAGES / UNIT_PAGES)
     28#define MAX_ALIGN_PAGES0                (MAXPAGES0 / UNIT_PAGES)
     29#define MAX_ALIGN_PAGES1                (MAXPAGES1 / UNIT_PAGES)
    4030/* get aligned page from offset address */
    4131#define get_aligned_page(offset)        ((offset) >> PAGE_SHIFT)
     
    4333#define aligned_page_offset(page)       ((page) << PAGE_SHIFT)
    4434
    45 #if PAGE_SIZE == 4096
    46 /* page size == EMUPAGESIZE */
     35#if PAGE_SIZE == EMUPAGESIZE && !IS_ENABLED(CONFIG_DYNAMIC_DEBUG)
    4736/* fill PTB entrie(s) corresponding to page with addr */
    4837#define set_ptb_entry(emu,page,addr)    __set_ptb_entry(emu,page,addr)
     
    5746        for (i = 0; i < UNIT_PAGES; i++, page++) {
    5847                __set_ptb_entry(emu, page, addr);
     48                dev_dbg(emu->card->dev, "mapped page %d to entry %.8x\n", page,
     49                        (unsigned int)__get_ptb_entry(emu, page));
    5950                addr += EMUPAGESIZE;
    6051        }
     
    6455        int i;
    6556        page *= UNIT_PAGES;
    66         for (i = 0; i < UNIT_PAGES; i++, page++)
     57        for (i = 0; i < UNIT_PAGES; i++, page++) {
    6758                /* do not increment ptr */
    6859                __set_ptb_entry(emu, page, emu->silent_page.addr);
     60                dev_dbg(emu->card->dev, "mapped silent page %d to entry %.8x\n",
     61                        page, (unsigned int)__get_ptb_entry(emu, page));
     62        }
    6963}
    7064#endif /* PAGE_SIZE */
     
    10195static int search_empty_map_area(struct snd_emu10k1 *emu, int npages, struct list_head **nextp)
    10296{
    103         int page = 0, found_page = -ENOMEM;
     97        int page = 1, found_page = -ENOMEM;
    10498        int max_size = npages;
    10599        int size;
     
    124118                page = blk->mapped_page + blk->pages;
    125119        }
    126         size = MAX_ALIGN_PAGES - page;
     120        size = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0) - page;
    127121        if (size >= max_size) {
    128122                *nextp = pos;
     
    146140        if (page < 0) /* not found */
    147141                return page;
     142        if (page == 0) {
     143                dev_err(emu->card->dev, "trying to map zero (reserved) page\n");
     144                return -EINVAL;
     145        }
    148146        /* insert this block in the proper position of mapped list */
    149147        list_add_tail(&blk->mapped_link, next);
     
    176174                start_page = q->mapped_page + q->pages;
    177175        } else
    178                 start_page = 0;
     176                start_page = 1;
    179177        if ((p = blk->mapped_link.next) != &emu->mapped_link_head) {
    180178                q = get_emu10k1_memblk(p, mapped_link);
    181179                end_page = q->mapped_page;
    182180        } else
    183                 end_page = MAX_ALIGN_PAGES;
     181                end_page = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0);
    184182
    185183        /* remove links */
     
    236234{
    237235        if (addr & ~emu->dma_mask) {
    238                 snd_printk(KERN_ERR "max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr);
     236                dev_err_ratelimited(emu->card->dev,
     237                        "max memory size is 0x%lx (addr = 0x%lx)!!\n",
     238                        emu->dma_mask, (unsigned long)addr);
    239239                return 0;
    240240        }
    241241        if (addr & (EMUPAGESIZE-1)) {
    242                 snd_printk(KERN_ERR "page is not aligned\n");
     242                dev_err_ratelimited(emu->card->dev, "page is not aligned\n");
    243243                return 0;
    244244        }
     
    249249 * map the given memory block on PTB.
    250250 * if the block is already mapped, update the link order.
    251  * if no empty pages are found, tries to release unsed memory blocks
     251 * if no empty pages are found, tries to release unused memory blocks
    252252 * and retry the mapping.
    253253 */
     
    263263        if (blk->mapped_page >= 0) {
    264264                /* update order link */
    265                 list_del(&blk->mapped_order_link);
    266                 list_add_tail(&blk->mapped_order_link, &emu->mapped_order_link_head);
     265                list_move_tail(&blk->mapped_order_link,
     266                              &emu->mapped_order_link_head);
    267267                spin_unlock_irqrestore(&emu->memblk_lock, flags);
    268268                return 0;
     
    305305                return NULL;
    306306        if (snd_BUG_ON(runtime->dma_bytes == 0 || /* DAZ was unsigned <= 0 */
    307                        runtime->dma_bytes >= MAXPAGES * EMUPAGESIZE))
     307                       runtime->dma_bytes >= (emu->address_mode ? MAXPAGES1 : MAXPAGES0) * EMUPAGESIZE))
    308308                return NULL;
    309309        hdr = emu->memhdr;
     
    326326                unsigned long ofs = idx << PAGE_SHIFT;
    327327                dma_addr_t addr;
    328                 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
     328                if (ofs >= runtime->dma_bytes)
     329                        addr = emu->silent_page.addr;
     330                else
     331                        addr = snd_pcm_sgbuf_get_addr(substream, ofs);
    329332                if (! is_valid_page(emu, addr)) {
    330                         printk(KERN_ERR "emu: failure page = %d\n", idx);
     333                        dev_err_ratelimited(emu->card->dev,
     334                                "emu: failure page = %d\n", idx);
    331335                        mutex_unlock(&hdr->block_mutex);
    332336                        return NULL;
     
    359363}
    360364
     365/*
     366 * allocate DMA pages, widening the allocation if necessary
     367 *
     368 * See the comment above snd_emu10k1_detect_iommu() in emu10k1_main.c why
     369 * this might be needed.
     370 *
     371 * If you modify this function check whether __synth_free_pages() also needs
     372 * changes.
     373 */
     374int snd_emu10k1_alloc_pages_maybe_wider(struct snd_emu10k1 *emu, size_t size,
     375                                        struct snd_dma_buffer *dmab)
     376{
     377        if (emu->iommu_workaround) {
     378                size_t npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
     379                size_t size_real = npages * PAGE_SIZE;
     380
     381                /*
     382                 * The device has been observed to accesses up to 256 extra
     383                 * bytes, but use 1k to be safe.
     384                 */
     385                if (size_real < size + 1024)
     386                        size += PAGE_SIZE;
     387        }
     388
     389        return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
     390                                   &emu->pci->dev, size, dmab);
     391}
    361392
    362393/*
     
    443474                               int last_page)
    444475{
     476        struct snd_dma_buffer dmab;
    445477        int page;
    446478
     479        dmab.dev.type = SNDRV_DMA_TYPE_DEV;
     480        dmab.dev.dev = &emu->pci->dev;
     481
    447482        for (page = first_page; page <= last_page; page++) {
    448                 free_page((unsigned long)emu->page_ptr_table[page]);
     483                if (emu->page_ptr_table[page] == NULL)
     484                        continue;
     485                dmab.area = emu->page_ptr_table[page];
     486                dmab.addr = emu->page_addr_table[page];
     487
     488                /*
     489                 * please keep me in sync with logic in
     490                 * snd_emu10k1_alloc_pages_maybe_wider()
     491                 */
     492                dmab.bytes = PAGE_SIZE;
     493                if (emu->iommu_workaround)
     494                        dmab.bytes *= 2;
     495
     496                snd_dma_free_pages(&dmab);
    449497                emu->page_addr_table[page] = 0;
    450498                emu->page_ptr_table[page] = NULL;
     
    459507#ifndef TARGET_OS2
    460508        int page, first_page, last_page;
     509        struct snd_dma_buffer dmab;
    461510
    462511        emu10k1_memblk_init(blk);
     
    464513        /* allocate kernel pages */
    465514        for (page = first_page; page <= last_page; page++) {
    466                 /* first try to allocate from <4GB zone */
    467                 struct page *p = alloc_page(GFP_KERNEL | GFP_DMA32 |
    468                                             __GFP_NOWARN);
    469                 if (!p || (page_to_pfn(p) & ~(emu->dma_mask >> PAGE_SHIFT))) {
    470                         if (p)
    471                                 __free_page(p);
    472                         /* try to allocate from <16MB zone */
    473                         p = alloc_page(GFP_ATOMIC | GFP_DMA |
    474                                        __GFP_NORETRY | /* no OOM-killer */
    475                                        __GFP_NOWARN);
     515                if (snd_emu10k1_alloc_pages_maybe_wider(emu, PAGE_SIZE,
     516                                                        &dmab) < 0)
     517                        goto __fail;
     518                if (!is_valid_page(emu, dmab.addr)) {
     519                        snd_dma_free_pages(&dmab);
     520                        goto __fail;
    476521                }
    477                 if (!p) {
    478                         __synth_free_pages(emu, first_page, page - 1);
    479                         return -ENOMEM;
    480                 }
    481                 emu->page_addr_table[page] = page_to_phys(p);
    482                 emu->page_ptr_table[page] = page_address(p);
     522                emu->page_addr_table[page] = dmab.addr;
     523                emu->page_ptr_table[page] = dmab.area;
    483524        }
    484525        return 0;
     526
     527__fail:
     528        /* release allocated pages */
     529        last_page = page - 1;
     530        __synth_free_pages(emu, first_page, last_page);
     531
     532        return -ENOMEM;
    485533#else
     534#define snd_dma_pci_data(pci)   (&(pci)->dev)
    486535    int page, first_page, last_page;
    487536    struct snd_dma_buffer dmab;
     
    539588        ptr = emu->page_ptr_table[page];
    540589        if (! ptr) {
    541                 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page);
     590                dev_err(emu->card->dev,
     591                        "access to NULL ptr: page = %d\n", page);
    542592                return NULL;
    543593        }
  • GPL/trunk/alsa-kernel/pci/emu10k1/p16v.c

    r464 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
     
    7071 *    DAC: CS4382-K (8-channel, 24bit, 192Khz)
    7172 *
    72  *  This code was initally based on code from ALSA's emu10k1x.c which is:
     73 *  This code was initially based on code from ALSA's emu10k1x.c which is:
    7374 *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
    74  *
    75  *   This program is free software; you can redistribute it and/or modify
    76  *   it under the terms of the GNU General Public License as published by
    77  *   the Free Software Foundation; either version 2 of the License, or
    78  *   (at your option) any later version.
    79  *
    80  *   This program is distributed in the hope that it will be useful,
    81  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    82  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    83  *   GNU General Public License for more details.
    84  *
    85  *   You should have received a copy of the GNU General Public License
    86  *   along with this program; if not, write to the Free Software
    87  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    88  *
    8975 */
    9076#include <linux/delay.h>
     
    123109
    124110 /* hardware definition */
    125 static struct snd_pcm_hardware snd_p16v_playback_hw = {
     111static const struct snd_pcm_hardware snd_p16v_playback_hw = {
    126112        .info =                 SNDRV_PCM_INFO_MMAP |
    127113                                SNDRV_PCM_INFO_INTERLEAVED |
     
    144130};
    145131
    146 static struct snd_pcm_hardware snd_p16v_capture_hw = {
     132static const struct snd_pcm_hardware snd_p16v_capture_hw = {
    147133        .info =                 (SNDRV_PCM_INFO_MMAP |
    148134                                 SNDRV_PCM_INFO_INTERLEAVED |
     
    167153{
    168154        struct snd_emu10k1_pcm *epcm = runtime->private_data;
    169  
    170         if (epcm) {
    171                 /* snd_printk(KERN_DEBUG "epcm free: %p\n", epcm); */
    172                 kfree(epcm);
    173         }
     155
     156        kfree(epcm);
    174157}
    175158
     
    184167
    185168        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    186         /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
     169        /* dev_dbg(emu->card->dev, "epcm kcalloc: %p\n", epcm); */
    187170
    188171        if (epcm == NULL)
     
    191174        epcm->substream = substream;
    192175        /*
    193         snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
     176        dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
    194177                   substream->pcm->device, channel_id);
    195178        */
     
    204187        channel->use=1;
    205188#if 0 /* debug */
    206         snd_printk(KERN_DEBUG
     189        dev_dbg(emu->card->dev,
    207190                   "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
    208191                   channel_id, channel, channel->use);
    209         printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
     192        dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
    210193               channel_id, chip, channel);
    211194#endif /* debug */
     
    232215
    233216        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    234         /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
     217        /* dev_dbg(emu->card->dev, "epcm kcalloc: %p\n", epcm); */
    235218
    236219        if (epcm == NULL)
     
    239222        epcm->substream = substream;
    240223        /*
    241         snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
     224        dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
    242225                   substream->pcm->device, channel_id);
    243226        */
     
    252235        channel->use=1;
    253236#if 0 /* debug */
    254         snd_printk(KERN_DEBUG
     237        dev_dbg(emu->card->dev,
    255238                   "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
    256239                   channel_id, channel, channel->use);
    257         printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
     240        dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
    258241               channel_id, chip, channel);
    259242#endif /* debug */
     
    299282        return snd_p16v_pcm_open_capture_channel(substream, 0);
    300283}
    301 
    302 /* hw_params callback */
    303 static int snd_p16v_pcm_hw_params_playback(struct snd_pcm_substream *substream,
    304                                       struct snd_pcm_hw_params *hw_params)
    305 {
    306         int result;
    307         result = snd_pcm_lib_malloc_pages(substream,
    308                                         params_buffer_bytes(hw_params));
    309         return result;
    310 }
    311 
    312 /* hw_params callback */
    313 static int snd_p16v_pcm_hw_params_capture(struct snd_pcm_substream *substream,
    314                                       struct snd_pcm_hw_params *hw_params)
    315 {
    316         int result;
    317         result = snd_pcm_lib_malloc_pages(substream,
    318                                         params_buffer_bytes(hw_params));
    319         return result;
    320 }
    321 
    322 
    323 /* hw_free callback */
    324 static int snd_p16v_pcm_hw_free_playback(struct snd_pcm_substream *substream)
    325 {
    326         int result;
    327         result = snd_pcm_lib_free_pages(substream);
    328         return result;
    329 }
    330 
    331 /* hw_free callback */
    332 static int snd_p16v_pcm_hw_free_capture(struct snd_pcm_substream *substream)
    333 {
    334         int result;
    335         result = snd_pcm_lib_free_pages(substream);
    336         return result;
    337 }
    338 
    339284
    340285/* prepare playback callback */
     
    350295       
    351296#if 0 /* debug */
    352         snd_printk(KERN_DEBUG "prepare:channel_number=%d, rate=%d, "
     297        dev_dbg(emu->card->dev,
     298                "prepare:channel_number=%d, rate=%d, "
    353299                   "format=0x%x, channels=%d, buffer_size=%ld, "
    354300                   "period_size=%ld, periods=%u, frames_to_bytes=%d\n",
     
    356302                   runtime->buffer_size, runtime->period_size,
    357303                   runtime->periods, frames_to_bytes(runtime, 1));
    358         snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n",
     304        dev_dbg(emu->card->dev,
     305                "dma_addr=%x, dma_area=%p, table_base=%p\n",
    359306                   runtime->dma_addr, runtime->dma_area, table_base);
    360         snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
     307        dev_dbg(emu->card->dev,
     308                "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
    361309                   emu->p16v_buffer.addr, emu->p16v_buffer.area,
    362310                   emu->p16v_buffer.bytes);
     
    406354
    407355        /*
    408         printk(KERN_DEBUG "prepare capture:channel_number=%d, rate=%d, "
     356        dev_dbg(emu->card->dev, "prepare capture:channel_number=%d, rate=%d, "
    409357               "format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, "
    410358               "frames_to_bytes=%d\n",
     
    492440                epcm = runtime->private_data;
    493441                channel = substream->pcm->device-emu->p16v_device_offset;
    494                 /* snd_printk(KERN_DEBUG "p16v channel=%d\n", channel); */
     442                /* dev_dbg(emu->card->dev, "p16v channel=%d\n", channel); */
    495443                epcm->running = running;
    496444                basic |= (0x1<<channel);
     
    498446                snd_pcm_trigger_done(s, substream);
    499447        }
    500         /* snd_printk(KERN_DEBUG "basic=0x%x, inte=0x%x\n", basic, inte); */
     448        /* dev_dbg(emu->card->dev, "basic=0x%x, inte=0x%x\n", basic, inte); */
    501449
    502450        switch (cmd) {
     
    589537        if (ptr >= runtime->buffer_size) {
    590538                ptr -= runtime->buffer_size;
    591                 printk(KERN_WARNING "buffer capture limited!\n");
     539                dev_warn(emu->card->dev, "buffer capture limited!\n");
    592540        }
    593541        /*
    594         printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
     542        dev_dbg(emu->card->dev, "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
    595543               "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
    596544               ptr1, ptr2, ptr, (int)runtime->buffer_size,
     
    602550
    603551/* operators */
    604 static struct snd_pcm_ops snd_p16v_playback_front_ops = {
     552static const struct snd_pcm_ops snd_p16v_playback_front_ops = {
    605553        .open =        snd_p16v_pcm_open_playback_front,
    606554        .close =       snd_p16v_pcm_close_playback,
    607         .ioctl =       snd_pcm_lib_ioctl,
    608         .hw_params =   snd_p16v_pcm_hw_params_playback,
    609         .hw_free =     snd_p16v_pcm_hw_free_playback,
    610555        .prepare =     snd_p16v_pcm_prepare_playback,
    611556        .trigger =     snd_p16v_pcm_trigger_playback,
     
    613558};
    614559
    615 static struct snd_pcm_ops snd_p16v_capture_ops = {
     560static const struct snd_pcm_ops snd_p16v_capture_ops = {
    616561        .open =        snd_p16v_pcm_open_capture,
    617562        .close =       snd_p16v_pcm_close_capture,
    618         .ioctl =       snd_pcm_lib_ioctl,
    619         .hw_params =   snd_p16v_pcm_hw_params_capture,
    620         .hw_free =     snd_p16v_pcm_hw_free_capture,
    621563        .prepare =     snd_p16v_pcm_prepare_capture,
    622564        .trigger =     snd_p16v_pcm_trigger_capture,
     
    631573                snd_dma_free_pages(&chip->p16v_buffer);
    632574                /*
    633                 snd_printk(KERN_DEBUG "period lables free: %p\n",
     575                dev_dbg(chip->card->dev, "period lables free: %p\n",
    634576                           &chip->p16v_buffer);
    635577                */
     
    638580}
    639581
    640 int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
     582int snd_p16v_pcm(struct snd_emu10k1 *emu, int device)
    641583{
    642584        struct snd_pcm *pcm;
     
    645587        int capture=1;
    646588 
    647         /* snd_printk(KERN_DEBUG "snd_p16v_pcm called. device=%d\n", device); */
     589        /* dev_dbg(emu->card->dev, "snd_p16v_pcm called. device=%d\n", device); */
    648590        emu->p16v_device_offset = device;
    649         if (rpcm)
    650                 *rpcm = NULL;
    651591
    652592        if ((err = snd_pcm_new(emu->card, "p16v", device, 1, capture, &pcm)) < 0)
     
    667607            substream;
    668608            substream = substream->next) {
    669                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    670                                                          SNDRV_DMA_TYPE_DEV,
    671                                                          snd_dma_pci_data(emu->pci),
    672                                                          ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
    673                         return err;
     609                snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
     610                                           &emu->pci->dev,
     611                                           (65536 - 64) * 8,
     612                                           (65536 - 64) * 8);
    674613                /*
    675                 snd_printk(KERN_DEBUG
     614                dev_dbg(emu->card->dev,
    676615                           "preallocate playback substream: err=%d\n", err);
    677616                */
     
    681620              substream;
    682621              substream = substream->next) {
    683                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    684                                                    SNDRV_DMA_TYPE_DEV,
    685                                                    snd_dma_pci_data(emu->pci),
    686                                                    65536 - 64, 65536 - 64)) < 0)
    687                         return err;
     622                snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
     623                                           &emu->pci->dev,
     624                                           65536 - 64, 65536 - 64);
    688625                /*
    689                 snd_printk(KERN_DEBUG
     626                dev_dbg(emu->card->dev,
    690627                           "preallocate capture substream: err=%d\n", err);
    691628                */
    692629        }
    693  
    694         if (rpcm)
    695                 *rpcm = pcm;
    696630 
    697631        return 0;
     
    755689                                        struct snd_ctl_elem_info *uinfo)
    756690{
    757         static char *texts[8] = {
     691        static const char * const texts[8] = {
    758692                "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S",
    759693                "CDIF", "FX", "AC97"
    760694        };
    761695
    762         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    763         uinfo->count = 1;
    764         uinfo->value.enumerated.items = 8;
    765         if (uinfo->value.enumerated.item > 7)
    766                 uinfo->value.enumerated.item = 7;
    767         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    768         return 0;
     696        return snd_ctl_enum_info(uinfo, 1, 8, texts);
    769697}
    770698
     
    803731                                         struct snd_ctl_elem_info *uinfo)
    804732{
    805         static char *texts[4] = { "0", "1", "2", "3",  };
    806 
    807         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    808         uinfo->count = 1;
    809         uinfo->value.enumerated.items = 4;
    810         if (uinfo->value.enumerated.item > 3)
    811                 uinfo->value.enumerated.item = 3;
    812         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    813         return 0;
     733        static const char * const texts[4] = { "0", "1", "2", "3", };
     734
     735        return snd_ctl_enum_info(uinfo, 1, 4, texts);
    814736}
    815737
     
    855777}
    856778
    857 static struct snd_kcontrol_new p16v_mixer_controls[] __devinitdata = {
     779static const struct snd_kcontrol_new p16v_mixer_controls[] = {
    858780        P16V_VOL("HD Analog Front Playback Volume", PLAYBACK_VOLUME_MIXER9, 0),
    859781        P16V_VOL("HD Analog Rear Playback Volume", PLAYBACK_VOLUME_MIXER10, 1),
     
    881803
    882804
    883 int __devinit snd_p16v_mixer(struct snd_emu10k1 *emu)
     805int snd_p16v_mixer(struct snd_emu10k1 *emu)
    884806{
    885807        int i, err;
     
    894816}
    895817
    896 #ifdef CONFIG_PM
     818#ifdef CONFIG_PM_SLEEP
    897819
    898820#define NUM_CHS 1       /* up to 4, but only first channel is used */
    899821
    900 int __devinit snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
    901 {
     822int snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
     823{
     824#ifdef TARGET_OS2
     825        emu->p16v_saved = vmalloc(array_size(NUM_CHS * 4, 0x80));
     826#else
    902827        emu->p16v_saved = vmalloc(NUM_CHS * 4 * 0x80);
     828#endif
    903829        if (! emu->p16v_saved)
    904830                return -ENOMEM;
  • GPL/trunk/alsa-kernel/pci/emu10k1/p16v.h

    r598 r679  
     1/* SPDX-License-Identifier: GPL-2.0-or-later */
    12/*
    23 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
     
    4142 *    Split from p16v.c
    4243 *
    43  *
    4444 *  BUGS:
    4545 *    Some stability problems when unloading the snd-p16v kernel module.
     
    6060 *    DAC: CS4382-K (8-channel, 24bit, 192Khz)
    6161 *
    62  *  This code was initally based on code from ALSA's emu10k1x.c which is:
     62 *  This code was initially based on code from ALSA's emu10k1x.c which is:
    6363 *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
    64  *
    65  *   This program is free software; you can redistribute it and/or modify
    66  *   it under the terms of the GNU General Public License as published by
    67  *   the Free Software Foundation; either version 2 of the License, or
    68  *   (at your option) any later version.
    69  *
    70  *   This program is distributed in the hope that it will be useful,
    71  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    72  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    73  *   GNU General Public License for more details.
    74  *
    75  *   You should have received a copy of the GNU General Public License
    76  *   along with this program; if not, write to the Free Software
    77  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    78  *
    7964 */
    8065
     
    8772 */
    8873
    89 /* Initally all registers from 0x00 to 0x3f have zero contents. */
     74/* Initially all registers from 0x00 to 0x3f have zero contents. */
    9075#define PLAYBACK_LIST_ADDR      0x00            /* Base DMA address of a list of pointers to each period/size */
    9176                                                /* One list entry: 4 bytes for DMA address,
  • GPL/trunk/alsa-kernel/pci/emu10k1/p17v.h

    r305 r679  
     1/* SPDX-License-Identifier: GPL-2.0-or-later */
    12/*
    23 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
    34 *  Driver p17v chips
    45 *  Version: 0.01
    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  *
    206 */
    217
  • GPL/trunk/alsa-kernel/pci/emu10k1/timer.c

    r305 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Lee Revell <rlrevell@joe-job.com>
     
    910 *  TODO:
    1011 *    --
    11  *
    12  *   This program is free software; you can redistribute it and/or modify
    13  *   it under the terms of the GNU General Public License as published by
    14  *   the Free Software Foundation; either version 2 of the License, or
    15  *   (at your option) any later version.
    16  *
    17  *   This program is distributed in the hope that it will be useful,
    18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  *   GNU General Public License for more details.
    21  *
    22  *   You should have received a copy of the GNU General Public License
    23  *   along with this program; if not, write to the Free Software
    24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    25  *
    2612 */
    2713
     
    6753}
    6854
    69 static struct snd_timer_hardware snd_emu10k1_timer_hw = {
     55static const struct snd_timer_hardware snd_emu10k1_timer_hw = {
    7056        .flags = SNDRV_TIMER_HW_AUTO,
    7157        .resolution = 20833, /* 1 sample @ 48KHZ = 20.833...us */
     
    7662};
    7763
    78 int __devinit snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
     64int snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
    7965{
    8066        struct snd_timer *timer = NULL;
  • GPL/trunk/alsa-kernel/pci/emu10k1/tina2.h

    r111 r679  
     1/* SPDX-License-Identifier: GPL-2.0-or-later */
    12/*
    23 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
    34 *  Driver tina2 chips
    45 *  Version: 0.1
    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  *
    206 */
    217
  • GPL/trunk/alsa-kernel/pci/emu10k1/voice.c

    r426 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    1213 *  TODO:
    1314 *    --
    14  *
    15  *   This program is free software; you can redistribute it and/or modify
    16  *   it under the terms of the GNU General Public License as published by
    17  *   the Free Software Foundation; either version 2 of the License, or
    18  *   (at your option) any later version.
    19  *
    20  *   This program is distributed in the hope that it will be useful,
    21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23  *   GNU General Public License for more details.
    24  *
    25  *   You should have received a copy of the GNU General Public License
    26  *   along with this program; if not, write to the Free Software
    27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    28  *
    2915 */
    3016
    3117#include <linux/time.h>
     18#include <linux/export.h>
    3219#include <sound/core.h>
    3320#include <sound/emu10k1.h>
     
    5542        for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) {
    5643                /*
    57                 printk(KERN_DEBUG "i %d j %d next free %d!\n",
     44                dev_dbg(emu->card->dev, "i %d j %d next free %d!\n",
    5845                       i, j, emu->next_free_voice);
    5946                */
     
    7562                }
    7663                if (!skip) {
    77                         /* printk(KERN_DEBUG "allocated voice %d\n", i); */
     64                        /* dev_dbg(emu->card->dev, "allocated voice %d\n", i); */
    7865                        first_voice = i;
    7966                        last_voice = (i + number) % NUM_G;
     
    8976                voice = &emu->voices[(first_voice + i) % NUM_G];
    9077                /*
    91                 printk(kERN_DEBUG "voice alloc - %i, %i of %i\n",
     78                dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
    9279                       voice->number, idx-first_voice+1, number);
    9380                */
Note: See TracChangeset for help on using the changeset viewer.