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

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/pci/rme9652/hdsp.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *   ALSA driver for RME Hammerfall DSP audio interface(s)
     
    56 *                          Marcus Andersson
    67 *                          Thomas Charbonnel
    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  *
    228 */
    239
     
    2713#include <linux/pci.h>
    2814#include <linux/firmware.h>
    29 #include <linux/moduleparam.h>
     15#include <linux/module.h>
    3016#include <linux/math64.h>
     17#include <linux/vmalloc.h>
     18#include <linux/io.h>
     19#include <linux/nospec.h>
    3120
    3221#include <sound/core.h>
     
    4231#include <asm/byteorder.h>
    4332#include <asm/current.h>
    44 #include <asm/io.h>
    4533
    4634static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    4735static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    48 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     36static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    4937
    5038module_param_array(index, int, NULL, 0444);
     
    6048                "{RME HDSP-9652},"
    6149                "{RME HDSP-9632}}");
    62 #ifdef HDSP_FW_LOADER
    6350MODULE_FIRMWARE("rpm_firmware.bin");
    6451MODULE_FIRMWARE("multiface_firmware.bin");
     
    6653MODULE_FIRMWARE("digiface_firmware.bin");
    6754MODULE_FIRMWARE("digiface_firmware_rev11.bin");
    68 #endif
    6955
    7056#define HDSP_MAX_CHANNELS        26
     
    152138#define HDSP_CONFIG_MODE_0      0x040
    153139#define HDSP_CONFIG_MODE_1      0x080
    154 #define HDSP_VERSION_BIT        0x100
     140#define HDSP_VERSION_BIT        (0x100 | HDSP_S_LOAD)
    155141#define HDSP_BIGENDIAN_MODE     0x200
    156142#define HDSP_RD_MULTIPLE        0x400
    157143#define HDSP_9652_ENABLE_MIXER  0x800
     144#define HDSP_S200               0x800
     145#define HDSP_S300               (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */
     146#define HDSP_CYCLIC_MODE        0x1000
    158147#define HDSP_TDO                0x10000000
    159148
    160 #define HDSP_S_PROGRAM          (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
    161 #define HDSP_S_LOAD             (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
     149#define HDSP_S_PROGRAM      (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
     150#define HDSP_S_LOAD         (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
    162151
    163152/* Control Register bits */
     
    424413#define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
    425414
    426 /* use hotplug firmware loader? */
    427 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
    428 #if !defined(HDSP_USE_HWDEP_LOADER)
    429 #define HDSP_FW_LOADER
    430 #endif
    431 #endif
     415#define HDSP_FIRMWARE_SIZE      (24413 * 4)
    432416
    433417struct hdsp_9632_meters {
     
    464448        struct snd_pcm_substream *playback_substream;
    465449        struct hdsp_midi      midi[2];
    466         struct tasklet_struct midi_tasklet;
    467         int                   use_midi_tasklet;
     450        struct work_struct    midi_work;
     451        int                   use_midi_work;
    468452        int                   precise_ptr;
    469453        u32                   control_register;      /* cached value */
     
    476460        unsigned short        firmware_rev;
    477461        unsigned short        state;                 /* stores state bits */
    478         u32                   firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
     462        const struct firmware *firmware;
     463        u32                  *fw_uploaded;
    479464        size_t                period_bytes;          /* guess what this is */
    480465        unsigned char         max_channels;
     
    495480        int                   running;
    496481        int                   system_sample_rate;
    497         char                 *channel_map;
     482        const char           *channel_map;
    498483        int                   dev;
    499484        int                   irq;
     
    517502*/
    518503
    519 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
     504static const char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
    520505        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
    521506        18, 19, 20, 21, 22, 23, 24, 25
    522507};
    523508
    524 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
     509static const char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
    525510        /* Analog */
    526511        0, 1, 2, 3, 4, 5, 6, 7,
     
    532517};
    533518
    534 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
     519static const char channel_map_ds[HDSP_MAX_CHANNELS] = {
    535520        /* ADAT channels are remapped */
    536521        1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
     
    541526};
    542527
    543 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
     528static const char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
    544529        /* ADAT channels */
    545530        0, 1, 2, 3, 4, 5, 6, 7,
     
    555540};
    556541
    557 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
     542static const char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
    558543        /* ADAT */
    559544        1, 3, 5, 7,
     
    569554};
    570555
    571 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
     556static const char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
    572557        /* ADAT is disabled in this mode */
    573558        /* SPDIF */
     
    585570static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
    586571{
    587         dmab->dev.type = SNDRV_DMA_TYPE_DEV;
    588         dmab->dev.dev = snd_dma_pci_data(pci);
    589         if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
    590                 if (dmab->bytes >= size)
    591                         return 0;
    592         }
    593         if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    594                                 size, dmab) < 0)
    595                 return -ENOMEM;
    596         return 0;
     572        return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, dmab);
    597573}
    598574
    599575static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
    600576{
    601         if (dmab->area) {
    602                 dmab->dev.dev = NULL; /* make it anonymous */
    603                 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
    604         }
    605 }
    606 
    607 
    608 static DEFINE_PCI_DEVICE_TABLE(snd_hdsp_ids) = {
     577        if (dmab->area)
     578                snd_dma_free_pages(dmab);
     579}
     580
     581
     582static const struct pci_device_id snd_hdsp_ids[] = {
    609583        {
    610584                .vendor = PCI_VENDOR_ID_XILINX,
     
    677651static int hdsp_check_for_iobox (struct hdsp *hdsp)
    678652{
     653        int i;
     654
    679655        if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
    680         if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
    681                 snd_printk("Hammerfall-DSP: no IO box connected!\n");
    682                 hdsp->state &= ~HDSP_FirmwareLoaded;
    683                 return -EIO;
    684         }
    685         return 0;
     656        for (i = 0; i < 500; i++) {
     657                if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
     658                                        HDSP_ConfigError)) {
     659                        if (i) {
     660                                dev_dbg(hdsp->card->dev,
     661                                        "IO box found after %d ms\n",
     662                                                (20 * i));
     663                        }
     664                        return 0;
     665                }
     666                msleep(20);
     667        }
     668        dev_err(hdsp->card->dev, "no IO box connected!\n");
     669        hdsp->state &= ~HDSP_FirmwareLoaded;
     670        return -EIO;
    686671}
    687672
     
    698683                        msleep(delay);
    699684                else {
    700                         snd_printd("Hammerfall-DSP: iobox found after %ums!\n",
     685                        dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
    701686                                   i * delay);
    702687                        return 0;
     
    704689        }
    705690
    706         snd_printk("Hammerfall-DSP: no IO box connected!\n");
     691        dev_info(hdsp->card->dev, "no IO box connected!\n");
    707692        hdsp->state &= ~HDSP_FirmwareLoaded;
    708693        return -EIO;
     
    713698        int i;
    714699        unsigned long flags;
     700        const u32 *cache;
     701
     702        if (hdsp->fw_uploaded)
     703                cache = hdsp->fw_uploaded;
     704        else {
     705                if (!hdsp->firmware)
     706                        return -ENODEV;
     707                cache = (u32 *)hdsp->firmware->data;
     708                if (!cache)
     709                        return -ENODEV;
     710        }
    715711
    716712        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
    717713
    718                 snd_printk ("Hammerfall-DSP: loading firmware\n");
     714                dev_info(hdsp->card->dev, "loading firmware\n");
    719715
    720716                hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
     
    722718
    723719                if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
    724                         snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
     720                        dev_info(hdsp->card->dev,
     721                                 "timeout waiting for download preparation\n");
     722                        hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
    725723                        return -EIO;
    726724                }
     
    728726                hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
    729727
    730                 for (i = 0; i < 24413; ++i) {
    731                         hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
     728                for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) {
     729                        hdsp_write(hdsp, HDSP_fifoData, cache[i]);
    732730                        if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
    733                                 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
     731                                dev_info(hdsp->card->dev,
     732                                         "timeout during firmware loading\n");
     733                                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
    734734                                return -EIO;
    735735                        }
    736736                }
    737737
     738                hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
     739                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
     740
    738741                ssleep(3);
    739 
    740                 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
    741                         snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
    742                         return -EIO;
    743                 }
    744 
    745742#ifdef SNDRV_BIG_ENDIAN
    746743                hdsp->control2_register = HDSP_BIGENDIAN_MODE;
     
    749746#endif
    750747                hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
    751                 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
     748                dev_info(hdsp->card->dev, "finished firmware loading\n");
    752749
    753750        }
    754751        if (hdsp->state & HDSP_InitializationComplete) {
    755                 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
     752                dev_info(hdsp->card->dev,
     753                         "firmware loaded from cache, restoring defaults\n");
    756754                spin_lock_irqsave(&hdsp->lock, flags);
    757755                snd_hdsp_set_defaults(hdsp);
     
    768766        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
    769767
    770                 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
     768                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
     769                hdsp_write(hdsp, HDSP_fifoData, 0);
     770
     771                if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
     772                        hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
     773                        hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
     774                }
     775
     776                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
    771777                hdsp_write (hdsp, HDSP_fifoData, 0);
    772                 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
    773                         return -EIO;
    774 
    775                 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
    776                 hdsp_write (hdsp, HDSP_fifoData, 0);
    777 
    778                 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT)) {
    779                         hdsp_write(hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
    780                         hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
    781                         if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT))
    782                                 hdsp->io_type = RPM;
    783                         else
    784                                 hdsp->io_type = Multiface;
    785                 } else {
     778                if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
     779                        goto set_multi;
     780
     781                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
     782                hdsp_write(hdsp, HDSP_fifoData, 0);
     783                if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
    786784                        hdsp->io_type = Digiface;
     785                        dev_info(hdsp->card->dev, "Digiface found\n");
     786                        return 0;
    787787                }
     788
     789                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
     790                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
     791                hdsp_write(hdsp, HDSP_fifoData, 0);
     792                if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0)
     793                        goto set_multi;
     794
     795                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
     796                hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
     797                hdsp_write(hdsp, HDSP_fifoData, 0);
     798                if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
     799                        goto set_multi;
     800
     801                hdsp->io_type = RPM;
     802                dev_info(hdsp->card->dev, "RPM found\n");
     803                return 0;
    788804        } else {
    789805                /* firmware was already loaded, get iobox type */
     
    796812        }
    797813        return 0;
    798 }
    799 
    800 
    801 #ifdef HDSP_FW_LOADER
     814
     815set_multi:
     816        hdsp->io_type = Multiface;
     817        dev_info(hdsp->card->dev, "Multiface found\n");
     818        return 0;
     819}
     820
     821
    802822static int hdsp_request_fw_loader(struct hdsp *hdsp);
    803 #endif
    804823
    805824static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
     
    811830                if (! load_on_demand)
    812831                        return -EIO;
    813                 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
     832                dev_err(hdsp->card->dev, "firmware not present.\n");
    814833                /* try to load firmware */
    815834                if (! (hdsp->state & HDSP_FirmwareCached)) {
    816 #ifdef HDSP_FW_LOADER
    817835                        if (! hdsp_request_fw_loader(hdsp))
    818836                                return 0;
    819 #endif
    820                         snd_printk(KERN_ERR
    821                                    "Hammerfall-DSP: No firmware loaded nor "
    822                                    "cached, please upload firmware.\n");
     837                        dev_err(hdsp->card->dev,
     838                                   "No firmware loaded nor cached, please upload firmware.\n");
    823839                        return -EIO;
    824840                }
    825841                if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
    826                         snd_printk(KERN_ERR
    827                                    "Hammerfall-DSP: Firmware loading from "
    828                                    "cache failed, please upload manually.\n");
     842                        dev_err(hdsp->card->dev,
     843                                   "Firmware loading from cache failed, please upload manually.\n");
    829844                        return -EIO;
    830845                }
     
    854869        }
    855870
    856         snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
     871        dev_warn(hdsp->card->dev,
     872                 "wait for FIFO status <= %d failed after %d iterations\n",
    857873                    count, timeout);
    858874        return -1;
     
    971987                break;
    972988        }
    973         snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
     989        dev_warn(hdsp->card->dev,
     990                 "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n",
     991                 rate_bits, status);
    974992        return 0;
    975993}
     
    11051123                if (called_internally) {
    11061124                        /* request from ctl or card initialization */
    1107                         snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
     1125                        dev_err(hdsp->card->dev,
     1126                                "device is not running as a clock master: cannot set sample rate.\n");
    11081127                        return -1;
    11091128                } else {
     
    11131132
    11141133                        if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
    1115                                 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
     1134                                dev_info(hdsp->card->dev,
     1135                                         "Detected ADAT in double speed mode\n");
    11161136                        else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
    1117                                 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
     1137                                dev_info(hdsp->card->dev,
     1138                                         "Detected ADAT in quad speed mode\n");
    11181139                        else if (rate != external_freq) {
    1119                                 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
     1140                                dev_info(hdsp->card->dev,
     1141                                         "No AutoSync source for requested rate\n");
    11201142                                return -1;
    11211143                        }
     
    11891211
    11901212        if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
    1191                 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
     1213                dev_warn(hdsp->card->dev,
     1214                         "cannot change speed mode (capture PID = %d, playback PID = %d)\n",
    11921215                            hdsp->capture_pid,
    11931216                            hdsp->playback_pid);
     
    13631386        } else {
    13641387                hdsp->control_register &= ~ie;
    1365                 tasklet_kill(&hdsp->midi_tasklet);
    13661388        }
    13671389
     
    13701392}
    13711393
    1372 static void snd_hdsp_midi_output_timer(unsigned long data)
    1373 {
    1374         struct hdsp_midi *hmidi = (struct hdsp_midi *) data;
     1394static void snd_hdsp_midi_output_timer(struct timer_list *t)
     1395{
     1396        struct hdsp_midi *hmidi = from_timer(hmidi, t, timer);
    13751397        unsigned long flags;
    13761398
     
    13841406        */
    13851407
    1386         if (hmidi->istimer) {
    1387                 hmidi->timer.expires = 1 + jiffies;
    1388                 add_timer(&hmidi->timer);
    1389         }
     1408        if (hmidi->istimer)
     1409                mod_timer(&hmidi->timer, 1 + jiffies);
    13901410
    13911411        spin_unlock_irqrestore (&hmidi->lock, flags);
     
    14011421        if (up) {
    14021422                if (!hmidi->istimer) {
    1403                         init_timer(&hmidi->timer);
    1404                         hmidi->timer.function = snd_hdsp_midi_output_timer;
    1405                         hmidi->timer.data = (unsigned long) hmidi;
    1406                         hmidi->timer.expires = 1 + jiffies;
    1407                         add_timer(&hmidi->timer);
     1423                        timer_setup(&hmidi->timer, snd_hdsp_midi_output_timer,
     1424                                    0);
     1425                        mod_timer(&hmidi->timer, 1 + jiffies);
    14081426                        hmidi->istimer++;
    14091427                }
     
    14701488}
    14711489
    1472 static struct snd_rawmidi_ops snd_hdsp_midi_output =
     1490static const struct snd_rawmidi_ops snd_hdsp_midi_output =
    14731491{
    14741492        .open =         snd_hdsp_midi_output_open,
     
    14771495};
    14781496
    1479 static struct snd_rawmidi_ops snd_hdsp_midi_input =
     1497static const struct snd_rawmidi_ops snd_hdsp_midi_input =
    14801498{
    14811499        .open =         snd_hdsp_midi_input_open,
     
    14861504static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
    14871505{
    1488         char buf[32];
     1506        char buf[40];
    14891507
    14901508        hdsp->midi[id].id = id;
     
    14971515        spin_lock_init (&hdsp->midi[id].lock);
    14981516
    1499         sprintf (buf, "%s MIDI %d", card->shortname, id+1);
     1517        snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id + 1);
    15001518        if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
    15011519                return -1;
     
    16361654static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    16371655{
    1638         static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
     1656        static const char * const texts[4] = {
     1657                "Optical", "Coaxial", "Internal", "AES"
     1658        };
    16391659        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    16401660
    1641         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    1642         uinfo->count = 1;
    1643         uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
    1644         if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
    1645                 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
    1646         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    1647         return 0;
     1661        return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
     1662                                 texts);
    16481663}
    16491664
     
    16731688}
    16741689
    1675 #define HDSP_SPDIF_OUT(xname, xindex) \
    1676 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    1677   .info = snd_hdsp_info_spdif_bits, \
    1678   .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
    1679 
    1680 static int hdsp_spdif_out(struct hdsp *hdsp)
    1681 {
    1682         return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
    1683 }
    1684 
    1685 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
     1690#define HDSP_TOGGLE_SETTING(xname, xindex) \
     1691{   .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
     1692        .name = xname, \
     1693        .private_value = xindex, \
     1694        .info = snd_hdsp_info_toggle_setting, \
     1695        .get = snd_hdsp_get_toggle_setting, \
     1696        .put = snd_hdsp_put_toggle_setting \
     1697}
     1698
     1699static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
     1700{
     1701        return (hdsp->control_register & regmask) ? 1 : 0;
     1702}
     1703
     1704static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
    16861705{
    16871706        if (out)
    1688                 hdsp->control_register |= HDSP_SPDIFOpticalOut;
     1707                hdsp->control_register |= regmask;
    16891708        else
    1690                 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
     1709                hdsp->control_register &= ~regmask;
    16911710        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    1692         return 0;
    1693 }
    1694 
    1695 #define snd_hdsp_info_spdif_bits        snd_ctl_boolean_mono_info
    1696 
    1697 static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     1711
     1712        return 0;
     1713}
     1714
     1715#define snd_hdsp_info_toggle_setting               snd_ctl_boolean_mono_info
     1716
     1717static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol,
     1718                struct snd_ctl_elem_value *ucontrol)
    16981719{
    16991720        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1700 
    1701         ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
    1702         return 0;
    1703 }
    1704 
    1705 static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     1721        u32 regmask = kcontrol->private_value;
     1722
     1723        spin_lock_irq(&hdsp->lock);
     1724        ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
     1725        spin_unlock_irq(&hdsp->lock);
     1726        return 0;
     1727}
     1728
     1729static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,
     1730                struct snd_ctl_elem_value *ucontrol)
    17061731{
    17071732        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
     1733        u32 regmask = kcontrol->private_value;
    17081734        int change;
    17091735        unsigned int val;
     
    17131739        val = ucontrol->value.integer.value[0] & 1;
    17141740        spin_lock_irq(&hdsp->lock);
    1715         change = (int)val != hdsp_spdif_out(hdsp);
    1716         hdsp_set_spdif_output(hdsp, val);
    1717         spin_unlock_irq(&hdsp->lock);
    1718         return change;
    1719 }
    1720 
    1721 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
    1722 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    1723   .info = snd_hdsp_info_spdif_bits, \
    1724   .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
    1725 
    1726 static int hdsp_spdif_professional(struct hdsp *hdsp)
    1727 {
    1728         return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
    1729 }
    1730 
    1731 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
    1732 {
    1733         if (val)
    1734                 hdsp->control_register |= HDSP_SPDIFProfessional;
    1735         else
    1736                 hdsp->control_register &= ~HDSP_SPDIFProfessional;
    1737         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    1738         return 0;
    1739 }
    1740 
    1741 static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1742 {
    1743         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1744 
    1745         ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
    1746         return 0;
    1747 }
    1748 
    1749 static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1750 {
    1751         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1752         int change;
    1753         unsigned int val;
    1754 
    1755         if (!snd_hdsp_use_is_exclusive(hdsp))
    1756                 return -EBUSY;
    1757         val = ucontrol->value.integer.value[0] & 1;
    1758         spin_lock_irq(&hdsp->lock);
    1759         change = (int)val != hdsp_spdif_professional(hdsp);
    1760         hdsp_set_spdif_professional(hdsp, val);
    1761         spin_unlock_irq(&hdsp->lock);
    1762         return change;
    1763 }
    1764 
    1765 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
    1766 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    1767   .info = snd_hdsp_info_spdif_bits, \
    1768   .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
    1769 
    1770 static int hdsp_spdif_emphasis(struct hdsp *hdsp)
    1771 {
    1772         return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
    1773 }
    1774 
    1775 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
    1776 {
    1777         if (val)
    1778                 hdsp->control_register |= HDSP_SPDIFEmphasis;
    1779         else
    1780                 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
    1781         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    1782         return 0;
    1783 }
    1784 
    1785 static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1786 {
    1787         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1788 
    1789         ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
    1790         return 0;
    1791 }
    1792 
    1793 static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1794 {
    1795         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1796         int change;
    1797         unsigned int val;
    1798 
    1799         if (!snd_hdsp_use_is_exclusive(hdsp))
    1800                 return -EBUSY;
    1801         val = ucontrol->value.integer.value[0] & 1;
    1802         spin_lock_irq(&hdsp->lock);
    1803         change = (int)val != hdsp_spdif_emphasis(hdsp);
    1804         hdsp_set_spdif_emphasis(hdsp, val);
    1805         spin_unlock_irq(&hdsp->lock);
    1806         return change;
    1807 }
    1808 
    1809 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
    1810 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    1811   .info = snd_hdsp_info_spdif_bits, \
    1812   .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
    1813 
    1814 static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
    1815 {
    1816         return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
    1817 }
    1818 
    1819 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
    1820 {
    1821         if (val)
    1822                 hdsp->control_register |= HDSP_SPDIFNonAudio;
    1823         else
    1824                 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
    1825         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    1826         return 0;
    1827 }
    1828 
    1829 static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1830 {
    1831         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1832 
    1833         ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
    1834         return 0;
    1835 }
    1836 
    1837 static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    1838 {
    1839         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1840         int change;
    1841         unsigned int val;
    1842 
    1843         if (!snd_hdsp_use_is_exclusive(hdsp))
    1844                 return -EBUSY;
    1845         val = ucontrol->value.integer.value[0] & 1;
    1846         spin_lock_irq(&hdsp->lock);
    1847         change = (int)val != hdsp_spdif_nonaudio(hdsp);
    1848         hdsp_set_spdif_nonaudio(hdsp, val);
     1741        change = (int) val != hdsp_toggle_setting(hdsp, regmask);
     1742        if (change)
     1743                hdsp_set_toggle_setting(hdsp, regmask, val);
    18491744        spin_unlock_irq(&hdsp->lock);
    18501745        return change;
     
    18621757static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    18631758{
    1864         static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
     1759        static const char * const texts[] = {
     1760                "32000", "44100", "48000", "64000", "88200", "96000",
     1761                "None", "128000", "176400", "192000"
     1762        };
    18651763        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    18661764
    1867         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    1868         uinfo->count = 1;
    1869         uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
    1870         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    1871                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    1872         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    1873         return 0;
     1765        return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
     1766                                 texts);
    18741767}
    18751768
     
    19481841{
    19491842        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    1950         static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
    1951         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    1952         uinfo->count = 1;
    1953         uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
    1954         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    1955                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    1956         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    1957         return 0;
     1843        static const char * const texts[] = {
     1844                "32000", "44100", "48000", "64000", "88200", "96000",
     1845                "None", "128000", "176400", "192000"
     1846        };
     1847
     1848        return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
     1849                                 texts);
    19581850}
    19591851
     
    20161908static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    20171909{
    2018         static char *texts[] = {"Master", "Slave" };
    2019 
    2020         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2021         uinfo->count = 1;
    2022         uinfo->value.enumerated.items = 2;
    2023         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2024                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2025         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2026         return 0;
     1910        static const char * const texts[] = {"Master", "Slave" };
     1911
     1912        return snd_ctl_enum_info(uinfo, 1, 2, texts);
    20271913}
    20281914
     
    21252011static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    21262012{
    2127         static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
     2013        static const char * const texts[] = {
     2014                "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz",
     2015                "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz",
     2016                "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz",
     2017                "Internal 192.0 KHz"
     2018        };
    21282019        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    21292020
    2130         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2131         uinfo->count = 1;
    2132         if (hdsp->io_type == H9632)
    2133             uinfo->value.enumerated.items = 10;
    2134         else
    2135             uinfo->value.enumerated.items = 7;
    2136         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2137                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2138         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2139         return 0;
     2021        return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
     2022                                 texts);
    21402023}
    21412024
     
    22412124static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    22422125{
    2243         static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
    2244 
    2245         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2246         uinfo->count = 1;
    2247         uinfo->value.enumerated.items = 3;
    2248         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2249                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2250         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2251         return 0;
     2126        static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
     2127
     2128        return snd_ctl_enum_info(uinfo, 1, 3, texts);
    22522129}
    22532130
     
    23262203static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    23272204{
    2328         static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
    2329 
    2330         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2331         uinfo->count = 1;
    2332         uinfo->value.enumerated.items = 3;
    2333         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2334                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2335         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2336         return 0;
     2205        static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
     2206
     2207        return snd_ctl_enum_info(uinfo, 1, 3, texts);
    23372208}
    23382209
     
    24112282static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    24122283{
    2413         static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
    2414 
    2415         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2416         uinfo->count = 1;
    2417         uinfo->value.enumerated.items = 3;
    2418         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2419                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2420         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2421         return 0;
     2284        static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"};
     2285
     2286        return snd_ctl_enum_info(uinfo, 1, 3, texts);
    24222287}
    24232288
     
    24462311        else
    24472312                change = 0;
    2448         spin_unlock_irq(&hdsp->lock);
    2449         return change;
    2450 }
    2451 
    2452 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
    2453 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    2454   .name = xname, \
    2455   .index = xindex, \
    2456   .info = snd_hdsp_info_xlr_breakout_cable, \
    2457   .get = snd_hdsp_get_xlr_breakout_cable, \
    2458   .put = snd_hdsp_put_xlr_breakout_cable \
    2459 }
    2460 
    2461 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
    2462 {
    2463         if (hdsp->control_register & HDSP_XLRBreakoutCable)
    2464                 return 1;
    2465         return 0;
    2466 }
    2467 
    2468 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
    2469 {
    2470         if (mode)
    2471                 hdsp->control_register |= HDSP_XLRBreakoutCable;
    2472         else
    2473                 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
    2474         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    2475         return 0;
    2476 }
    2477 
    2478 #define snd_hdsp_info_xlr_breakout_cable        snd_ctl_boolean_mono_info
    2479 
    2480 static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2481 {
    2482         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2483 
    2484         ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
    2485         return 0;
    2486 }
    2487 
    2488 static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2489 {
    2490         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2491         int change;
    2492         int val;
    2493 
    2494         if (!snd_hdsp_use_is_exclusive(hdsp))
    2495                 return -EBUSY;
    2496         val = ucontrol->value.integer.value[0] & 1;
    2497         spin_lock_irq(&hdsp->lock);
    2498         change = (int)val != hdsp_xlr_breakout_cable(hdsp);
    2499         hdsp_set_xlr_breakout_cable(hdsp, val);
    2500         spin_unlock_irq(&hdsp->lock);
    2501         return change;
    2502 }
    2503 
    2504 /* (De)activates old RME Analog Extension Board
    2505    These are connected to the internal ADAT connector
    2506    Switching this on desactivates external ADAT
    2507 */
    2508 #define HDSP_AEB(xname, xindex) \
    2509 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    2510   .name = xname, \
    2511   .index = xindex, \
    2512   .info = snd_hdsp_info_aeb, \
    2513   .get = snd_hdsp_get_aeb, \
    2514   .put = snd_hdsp_put_aeb \
    2515 }
    2516 
    2517 static int hdsp_aeb(struct hdsp *hdsp)
    2518 {
    2519         if (hdsp->control_register & HDSP_AnalogExtensionBoard)
    2520                 return 1;
    2521         return 0;
    2522 }
    2523 
    2524 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
    2525 {
    2526         if (mode)
    2527                 hdsp->control_register |= HDSP_AnalogExtensionBoard;
    2528         else
    2529                 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
    2530         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    2531         return 0;
    2532 }
    2533 
    2534 #define snd_hdsp_info_aeb               snd_ctl_boolean_mono_info
    2535 
    2536 static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2537 {
    2538         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2539 
    2540         ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
    2541         return 0;
    2542 }
    2543 
    2544 static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2545 {
    2546         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2547         int change;
    2548         int val;
    2549 
    2550         if (!snd_hdsp_use_is_exclusive(hdsp))
    2551                 return -EBUSY;
    2552         val = ucontrol->value.integer.value[0] & 1;
    2553         spin_lock_irq(&hdsp->lock);
    2554         change = (int)val != hdsp_aeb(hdsp);
    2555         hdsp_set_aeb(hdsp, val);
    25562313        spin_unlock_irq(&hdsp->lock);
    25572314        return change;
     
    26232380static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    26242381{
    2625         static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
     2382        static const char * const texts[] = {
     2383                "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3"
     2384        };
    26262385        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2627 
    2628         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2629         uinfo->count = 1;
     2386        int num_items;
    26302387
    26312388        switch (hdsp->io_type) {
    26322389        case Digiface:
    26332390        case H9652:
    2634                 uinfo->value.enumerated.items = 6;
     2391                num_items = 6;
    26352392                break;
    26362393        case Multiface:
    2637                 uinfo->value.enumerated.items = 4;
     2394                num_items = 4;
    26382395                break;
    26392396        case H9632:
    2640                 uinfo->value.enumerated.items = 3;
     2397                num_items = 3;
    26412398                break;
    26422399        default:
    2643                 uinfo->value.enumerated.items = 0;
    2644                 break;
    2645         }
    2646 
    2647         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2648                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2649         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2650         return 0;
     2400                return -EINVAL;
     2401        }
     2402
     2403        return snd_ctl_enum_info(uinfo, 1, num_items, texts);
    26512404}
    26522405
     
    27282481static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    27292482{
    2730         static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
    2731 
    2732         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2733         uinfo->count = 1;
    2734         uinfo->value.enumerated.items = 7;
    2735         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2736                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2737         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2738         return 0;
     2483        static const char * const texts[] = {
     2484                "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3"
     2485        };
     2486
     2487        return snd_ctl_enum_info(uinfo, 1, 7, texts);
    27392488}
    27402489
     
    27452494        ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
    27462495        return 0;
    2747 }
    2748 
    2749 #define HDSP_LINE_OUT(xname, xindex) \
    2750 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    2751   .name = xname, \
    2752   .index = xindex, \
    2753   .info = snd_hdsp_info_line_out, \
    2754   .get = snd_hdsp_get_line_out, \
    2755   .put = snd_hdsp_put_line_out \
    2756 }
    2757 
    2758 static int hdsp_line_out(struct hdsp *hdsp)
    2759 {
    2760         return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
    2761 }
    2762 
    2763 static int hdsp_set_line_output(struct hdsp *hdsp, int out)
    2764 {
    2765         if (out)
    2766                 hdsp->control_register |= HDSP_LineOut;
    2767         else
    2768                 hdsp->control_register &= ~HDSP_LineOut;
    2769         hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    2770         return 0;
    2771 }
    2772 
    2773 #define snd_hdsp_info_line_out          snd_ctl_boolean_mono_info
    2774 
    2775 static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2776 {
    2777         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2778 
    2779         spin_lock_irq(&hdsp->lock);
    2780         ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
    2781         spin_unlock_irq(&hdsp->lock);
    2782         return 0;
    2783 }
    2784 
    2785 static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    2786 {
    2787         struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    2788         int change;
    2789         unsigned int val;
    2790 
    2791         if (!snd_hdsp_use_is_exclusive(hdsp))
    2792                 return -EBUSY;
    2793         val = ucontrol->value.integer.value[0] & 1;
    2794         spin_lock_irq(&hdsp->lock);
    2795         change = (int)val != hdsp_line_out(hdsp);
    2796         hdsp_set_line_output(hdsp, val);
    2797         spin_unlock_irq(&hdsp->lock);
    2798         return change;
    27992496}
    28002497
     
    28452542}
    28462543
    2847 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
     2544#define HDSP_USE_MIDI_WORK(xname, xindex) \
    28482545{ .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
    28492546  .name = xname, \
    28502547  .index = xindex, \
    2851   .info = snd_hdsp_info_use_midi_tasklet, \
    2852   .get = snd_hdsp_get_use_midi_tasklet, \
    2853   .put = snd_hdsp_put_use_midi_tasklet \
    2854 }
    2855 
    2856 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
    2857 {
    2858         if (use_tasklet)
    2859                 hdsp->use_midi_tasklet = 1;
     2548  .info = snd_hdsp_info_use_midi_work, \
     2549  .get = snd_hdsp_get_use_midi_work, \
     2550  .put = snd_hdsp_put_use_midi_work \
     2551}
     2552
     2553static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work)
     2554{
     2555        if (use_work)
     2556                hdsp->use_midi_work = 1;
    28602557        else
    2861                 hdsp->use_midi_tasklet = 0;
    2862         return 0;
    2863 }
    2864 
    2865 #define snd_hdsp_info_use_midi_tasklet          snd_ctl_boolean_mono_info
    2866 
    2867 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     2558                hdsp->use_midi_work = 0;
     2559        return 0;
     2560}
     2561
     2562#define snd_hdsp_info_use_midi_work             snd_ctl_boolean_mono_info
     2563
     2564static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    28682565{
    28692566        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    28702567
    28712568        spin_lock_irq(&hdsp->lock);
    2872         ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
     2569        ucontrol->value.integer.value[0] = hdsp->use_midi_work;
    28732570        spin_unlock_irq(&hdsp->lock);
    28742571        return 0;
    28752572}
    28762573
    2877 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     2574static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    28782575{
    28792576        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
     
    28852582        val = ucontrol->value.integer.value[0] & 1;
    28862583        spin_lock_irq(&hdsp->lock);
    2887         change = (int)val != hdsp->use_midi_tasklet;
    2888         hdsp_set_use_midi_tasklet(hdsp, val);
     2584        change = (int)val != hdsp->use_midi_work;
     2585        hdsp_set_use_midi_work(hdsp, val);
    28892586        spin_unlock_irq(&hdsp->lock);
    28902587        return change;
     
    29752672static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    29762673{
    2977         static char *texts[] = {"No Lock", "Lock", "Sync" };
    2978         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    2979         uinfo->count = 1;
    2980         uinfo->value.enumerated.items = 3;
    2981         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    2982                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    2983         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    2984         return 0;
     2674        static const char * const texts[] = {"No Lock", "Lock", "Sync" };
     2675
     2676        return snd_ctl_enum_info(uinfo, 1, 3, texts);
    29852677}
    29862678
     
    30922784
    30932785        offset = ucontrol->id.index - 1;
    3094         snd_BUG_ON(offset < 0);
     2786        if (snd_BUG_ON(offset < 0))
     2787                return -EINVAL;
    30952788
    30962789        switch (hdsp->io_type) {
     
    31642857        struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
    31652858
    3166         ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
     2859        ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp);
    31672860        return 0;
    31682861}
     
    31762869        if (!snd_hdsp_use_is_exclusive(hdsp))
    31772870                return -EBUSY;
    3178         val = ucontrol->value.enumerated.item[0];
     2871        val = ucontrol->value.integer.value[0];
    31792872        spin_lock_irq(&hdsp->lock);
    31802873        if (val != hdsp_dds_offset(hdsp))
     
    31862879}
    31872880
    3188 static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
     2881static const struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
    31892882HDSP_DA_GAIN("DA Gain", 0),
    31902883HDSP_AD_GAIN("AD Gain", 0),
    31912884HDSP_PHONE_GAIN("Phones Gain", 0),
    3192 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0),
     2885HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable),
    31932886HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
    31942887};
    31952888
    3196 static struct snd_kcontrol_new snd_hdsp_controls[] = {
     2889static const struct snd_kcontrol_new snd_hdsp_controls[] = {
    31972890{
    31982891        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     
    32322925HDSP_MIXER("Mixer", 0),
    32332926HDSP_SPDIF_IN("IEC958 Input Connector", 0),
    3234 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
    3235 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
    3236 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
    3237 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
     2927HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut),
     2928HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional),
     2929HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis),
     2930HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio),
    32382931/* 'Sample Clock Source' complies with the alsa control naming scheme */
    32392932HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
     
    32552948HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
    32562949HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
    3257 HDSP_LINE_OUT("Line Out", 0),
     2950HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut),
    32582951HDSP_PRECISE_POINTER("Precise Pointer", 0),
    3259 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
     2952HDSP_USE_MIDI_WORK("Use Midi Tasklet", 0),
    32602953};
    32612954
     
    33383031static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    33393032{
    3340         static char *texts[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"};
    3341 
    3342         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    3343         uinfo->count = 1;
    3344         uinfo->value.enumerated.items = 5;
    3345         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    3346                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    3347         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    3348         return 0;
     3033        static const char * const texts[] = {
     3034                "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"
     3035        };
     3036
     3037        return snd_ctl_enum_info(uinfo, 1, 5, texts);
    33493038}
    33503039
     
    34713160static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    34723161{
    3473         static char *texts[] = {"On", "Off"};
    3474 
    3475         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    3476         uinfo->count = 1;
    3477         uinfo->value.enumerated.items = 2;
    3478         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    3479                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    3480         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    3481         return 0;
     3162        static const char * const texts[] = {"On", "Off"};
     3163
     3164        return snd_ctl_enum_info(uinfo, 1, 2, texts);
    34823165}
    34833166
     
    35283211static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    35293212{
    3530         static char *texts[] = {"On", "Off"};
    3531 
    3532         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    3533         uinfo->count = 1;
    3534         uinfo->value.enumerated.items = 2;
    3535         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    3536                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
    3537         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    3538         return 0;
    3539 }
    3540 
    3541 static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
     3213        static const char * const texts[] = {"On", "Off"};
     3214
     3215        return snd_ctl_enum_info(uinfo, 1, 2, texts);
     3216}
     3217
     3218static const struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
    35423219        {
    35433220                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     
    35723249};
    35733250
    3574 static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
     3251static const struct snd_kcontrol_new snd_hdsp_96xx_aeb =
     3252        HDSP_TOGGLE_SETTING("Analog Extension Board",
     3253                        HDSP_AnalogExtensionBoard);
    35753254static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
    35763255
     
    36743353                        }
    36753354                } else {
    3676                         int err = -EINVAL;
    3677 #ifdef HDSP_FW_LOADER
     3355                        int err;
     3356
    36783357                        err = hdsp_request_fw_loader(hdsp);
    3679 #endif
    36803358                        if (err < 0) {
    36813359                                snd_iprintf(buffer,
     
    36923370        snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
    36933371        snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
    3694         snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
     3372        snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off");
    36953373
    36963374        snd_iprintf(buffer, "\n");
     
    39973675                snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
    39983676
    3999                 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
     3677                snd_iprintf(buffer, "XLR Breakout Cable : %s\n",
     3678                        hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
     3679                        "yes" : "no");
    40003680
    40013681                if (hdsp->control_register & HDSP_AnalogExtensionBoard)
     
    40103690static void snd_hdsp_proc_init(struct hdsp *hdsp)
    40113691{
    4012         struct snd_info_entry *entry;
    4013 
    4014         if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
    4015                 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
     3692        snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read);
    40163693}
    40173694
     
    40223699}
    40233700
    4024 static int __devinit snd_hdsp_initialize_memory(struct hdsp *hdsp)
     3701static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
    40253702{
    40263703        unsigned long pb_bus, cb_bus;
     
    40303707                if (hdsp->capture_dma_buf.area)
    40313708                        snd_dma_free_pages(&hdsp->capture_dma_buf);
    4032                 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
     3709                dev_err(hdsp->card->dev,
     3710                        "%s: no buffers available\n", hdsp->card_name);
    40333711                return -ENOMEM;
    40343712        }
     
    41133791}
    41143792
    4115 static void hdsp_midi_tasklet(unsigned long arg)
    4116 {
    4117         struct hdsp *hdsp = (struct hdsp *)arg;
     3793static void hdsp_midi_work(struct work_struct *work)
     3794{
     3795        struct hdsp *hdsp = container_of(work, struct hdsp, midi_work);
    41183796
    41193797        if (hdsp->midi[0].pending)
     
    41603838
    41613839        if (midi0 && midi0status) {
    4162                 if (hdsp->use_midi_tasklet) {
     3840                if (hdsp->use_midi_work) {
    41633841                        /* we disable interrupts for this input until processing is done */
    41643842                        hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
     
    41713849        }
    41723850        if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
    4173                 if (hdsp->use_midi_tasklet) {
     3851                if (hdsp->use_midi_work) {
    41743852                        /* we disable interrupts for this input until processing is done */
    41753853                        hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
     
    41813859                }
    41823860        }
    4183         if (hdsp->use_midi_tasklet && schedule)
    4184                 tasklet_schedule(&hdsp->midi_tasklet);
     3861        if (hdsp->use_midi_work && schedule)
     3862                queue_work(system_highpri_wq, &hdsp->midi_work);
    41853863        return IRQ_HANDLED;
    41863864}
     
    42113889}
    42123890
    4213 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel,
    4214                                   snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
     3891static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream,
     3892                                  int channel, unsigned long pos,
     3893                                  void __user *src, unsigned long count)
    42153894{
    42163895        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
    42173896        char *channel_buf;
    42183897
    4219         if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
     3898        if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
    42203899                return -EINVAL;
    42213900
     
    42233902        if (snd_BUG_ON(!channel_buf))
    42243903                return -EIO;
    4225         if (copy_from_user(channel_buf + pos * 4, src, count * 4))
     3904        if (copy_from_user(channel_buf + pos, src, count))
    42263905                return -EFAULT;
    4227         return count;
    4228 }
    4229 
    4230 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel,
    4231                                  snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
     3906        return 0;
     3907}
     3908
     3909static int snd_hdsp_playback_copy_kernel(struct snd_pcm_substream *substream,
     3910                                         int channel, unsigned long pos,
     3911                                         void *src, unsigned long count)
    42323912{
    42333913        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
    42343914        char *channel_buf;
    42353915
    4236         if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
     3916        channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
     3917        if (snd_BUG_ON(!channel_buf))
     3918                return -EIO;
     3919        memcpy(channel_buf + pos, src, count);
     3920        return 0;
     3921}
     3922
     3923static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream,
     3924                                 int channel, unsigned long pos,
     3925                                 void __user *dst, unsigned long count)
     3926{
     3927        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
     3928        char *channel_buf;
     3929
     3930        if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
    42373931                return -EINVAL;
    42383932
     
    42403934        if (snd_BUG_ON(!channel_buf))
    42413935                return -EIO;
    4242         if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
     3936        if (copy_to_user(dst, channel_buf + pos, count))
    42433937                return -EFAULT;
    4244         return count;
    4245 }
    4246 
    4247 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel,
    4248                                   snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
     3938        return 0;
     3939}
     3940
     3941static int snd_hdsp_capture_copy_kernel(struct snd_pcm_substream *substream,
     3942                                        int channel, unsigned long pos,
     3943                                        void *dst, unsigned long count)
     3944{
     3945        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
     3946        char *channel_buf;
     3947
     3948        channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
     3949        if (snd_BUG_ON(!channel_buf))
     3950                return -EIO;
     3951        memcpy(dst, channel_buf + pos, count);
     3952        return 0;
     3953}
     3954
     3955static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream,
     3956                               int channel, unsigned long pos,
     3957                               unsigned long count)
    42493958{
    42503959        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
     
    42543963        if (snd_BUG_ON(!channel_buf))
    42553964                return -EIO;
    4256         memset(channel_buf + pos * 4, 0, count * 4);
    4257         return count;
     3965        memset(channel_buf + pos, 0, count);
     3966        return 0;
    42583967}
    42593968
     
    43634072{
    43644073        struct hdsp *hdsp = snd_pcm_substream_chip(substream);
    4365         int mapped_channel;
    4366 
    4367         if (snd_BUG_ON(info->channel >= hdsp->max_channels))
     4074        unsigned int channel = info->channel;
     4075
     4076        if (snd_BUG_ON(channel >= hdsp->max_channels))
    43684077                return -EINVAL;
    4369 
    4370         if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
     4078        channel = array_index_nospec(channel, hdsp->max_channels);
     4079
     4080        if (hdsp->channel_map[channel] < 0)
    43714081                return -EINVAL;
    43724082
    4373         info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
     4083        info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES;
    43744084        info->first = 0;
    43754085        info->step = 32;
     
    44784188}
    44794189
    4480 static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
     4190static const struct snd_pcm_hardware snd_hdsp_playback_subinfo =
    44814191{
    44824192        .info =                 (SNDRV_PCM_INFO_MMAP |
     
    45084218};
    45094219
    4510 static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
     4220static const struct snd_pcm_hardware snd_hdsp_capture_subinfo =
    45114221{
    45124222        .info =                 (SNDRV_PCM_INFO_MMAP |
     
    45374247};
    45384248
    4539 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
    4540 
    4541 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
     4249static const unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
     4250
     4251static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
    45424252        .count = ARRAY_SIZE(hdsp_period_sizes),
    45434253        .list = hdsp_period_sizes,
     
    45454255};
    45464256
    4547 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
    4548 
    4549 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
     4257static const unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
     4258
     4259static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
    45504260        .count = ARRAY_SIZE(hdsp_9632_sample_rates),
    45514261        .list = hdsp_9632_sample_rates,
     
    49924702
    49934703                if (!(hdsp->state & HDSP_FirmwareLoaded)) {
    4994                         snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
     4704                        dev_err(hdsp->card->dev,
     4705                                "firmware needs to be uploaded to the card.\n");
    49954706                        return -EINVAL;
    49964707                }
     
    50284739                        info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
    50294740                info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
    5030                 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
    5031                 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
    5032                 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
    5033                 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
     4741                info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
     4742                                HDSP_SPDIFOpticalOut);
     4743                info.spdif_professional = (unsigned char)
     4744                        hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
     4745                info.spdif_emphasis = (unsigned char)
     4746                        hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
     4747                info.spdif_nonaudio = (unsigned char)
     4748                        hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
    50344749                info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
    50354750                info.system_sample_rate = hdsp->system_sample_rate;
     
    50384753                info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
    50394754                info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
    5040                 info.line_out = (unsigned char)hdsp_line_out(hdsp);
     4755                info.line_out = (unsigned char)
     4756                        hdsp_toggle_setting(hdsp, HDSP_LineOut);
    50414757                if (hdsp->io_type == H9632) {
    50424758                        info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
    50434759                        info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
    50444760                        info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
    5045                         info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
     4761                        info.xlr_breakout_cable =
     4762                                (unsigned char)hdsp_toggle_setting(hdsp,
     4763                                        HDSP_XLRBreakoutCable);
    50464764
    50474765                } else if (hdsp->io_type == RPM) {
     
    50504768                }
    50514769                if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
    5052                         info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
     4770                        info.analog_extension_board =
     4771                                (unsigned char)hdsp_toggle_setting(hdsp,
     4772                                            HDSP_AnalogExtensionBoard);
    50534773                spin_unlock_irqrestore(&hdsp->lock, flags);
    50544774                if (copy_to_user(argp, &info, sizeof(info)))
     
    50754795                                return err;
    50764796                }
     4797                memset(&hdsp_version, 0, sizeof(hdsp_version));
    50774798                hdsp_version.io_type = hdsp->io_type;
    50784799                hdsp_version.firmware_rev = hdsp->firmware_rev;
     
    50824803        }
    50834804        case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
    5084                 struct hdsp_firmware __user *firmware;
     4805                struct hdsp_firmware firmware;
    50854806                u32 __user *firmware_data;
    50864807                int err;
     
    50934814                        return -EBUSY;
    50944815
    5095                 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
    5096                 firmware = (struct hdsp_firmware __user *)argp;
    5097 
    5098                 if (get_user(firmware_data, &firmware->firmware_data))
     4816                dev_info(hdsp->card->dev,
     4817                         "initializing firmware upload\n");
     4818                if (copy_from_user(&firmware, argp, sizeof(firmware)))
    50994819                        return -EFAULT;
     4820                firmware_data = (u32 __user *)firmware.firmware_data;
    51004821
    51014822                if (hdsp_check_for_iobox (hdsp))
    51024823                        return -EIO;
    51034824
    5104                 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
     4825                if (!hdsp->fw_uploaded) {
     4826                        hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE);
     4827                        if (!hdsp->fw_uploaded)
     4828                                return -ENOMEM;
     4829                }
     4830
     4831                if (copy_from_user(hdsp->fw_uploaded, firmware_data,
     4832                                   HDSP_FIRMWARE_SIZE)) {
     4833                        vfree(hdsp->fw_uploaded);
     4834                        hdsp->fw_uploaded = NULL;
    51054835                        return -EFAULT;
     4836                }
    51064837
    51074838                hdsp->state |= HDSP_FirmwareCached;
     
    51184849
    51194850                        if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
    5120                                 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
     4851                                dev_err(hdsp->card->dev,
     4852                                        "error creating alsa devices\n");
    51214853                                return err;
    51224854                        }
     
    51364868}
    51374869
    5138 static struct snd_pcm_ops snd_hdsp_playback_ops = {
     4870static const struct snd_pcm_ops snd_hdsp_playback_ops = {
    51394871        .open =         snd_hdsp_playback_open,
    51404872        .close =        snd_hdsp_playback_release,
     
    51444876        .trigger =      snd_hdsp_trigger,
    51454877        .pointer =      snd_hdsp_hw_pointer,
    5146         .copy =         snd_hdsp_playback_copy,
    5147         .silence =      snd_hdsp_hw_silence,
     4878        .copy_user =    snd_hdsp_playback_copy,
     4879        .copy_kernel =  snd_hdsp_playback_copy_kernel,
     4880        .fill_silence = snd_hdsp_hw_silence,
    51484881};
    51494882
    5150 static struct snd_pcm_ops snd_hdsp_capture_ops = {
     4883static const struct snd_pcm_ops snd_hdsp_capture_ops = {
    51514884        .open =         snd_hdsp_capture_open,
    51524885        .close =        snd_hdsp_capture_release,
     
    51564889        .trigger =      snd_hdsp_trigger,
    51574890        .pointer =      snd_hdsp_hw_pointer,
    5158         .copy =         snd_hdsp_capture_copy,
     4891        .copy_user =    snd_hdsp_capture_copy,
     4892        .copy_kernel =  snd_hdsp_capture_copy_kernel,
    51594893};
    51604894
     
    51724906
    51734907        hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
     4908        hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
    51744909
    51754910        return 0;
     
    52074942
    52084943        if (hdsp_fifo_wait (hdsp, 0, 100)) {
    5209                 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
     4944                dev_err(hdsp->card->dev,
     4945                        "enable_io fifo_wait failed\n");
    52104946                return -EIO;
    52114947        }
     
    52815017
    52825018        if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
    5283                 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
     5019                dev_err(card->dev,
     5020                        "Error creating pcm interface\n");
    52845021                return err;
    52855022        }
     
    52875024
    52885025        if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
    5289                 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
     5026                dev_err(card->dev,
     5027                        "Error creating first midi interface\n");
    52905028                return err;
    52915029        }
     
    52935031        if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
    52945032                if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
    5295                         snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
     5033                        dev_err(card->dev,
     5034                                "Error creating second midi interface\n");
    52965035                        return err;
    52975036                }
     
    52995038
    53005039        if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
    5301                 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
     5040                dev_err(card->dev,
     5041                        "Error creating ctl interface\n");
    53025042                return err;
    53035043        }
     
    53125052
    53135053        if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
    5314                 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
     5054                dev_err(card->dev,
     5055                        "Error setting default values\n");
    53155056                return err;
    53165057        }
     
    53225063
    53235064                if ((err = snd_card_register(card)) < 0) {
    5324                         snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
     5065                        dev_err(card->dev,
     5066                                "error registering card\n");
    53255067                        return err;
    53265068                }
     
    53315073}
    53325074
    5333 #ifdef HDSP_FW_LOADER
    53345075/* load firmware via hotplug fw loader */
    53355076static int hdsp_request_fw_loader(struct hdsp *hdsp)
     
    53665107                break;
    53675108        default:
    5368                 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
     5109                dev_err(hdsp->card->dev,
     5110                        "invalid io_type %d\n", hdsp->io_type);
    53695111                return -EINVAL;
    53705112        }
    53715113
    53725114        if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
    5373                 snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile);
     5115                dev_err(hdsp->card->dev,
     5116                        "cannot load firmware %s\n", fwfile);
    53745117                return -ENOENT;
    53755118        }
    5376         if (fw->size < sizeof(hdsp->firmware_cache)) {
    5377                 snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n",
    5378                            (int)fw->size, (int)sizeof(hdsp->firmware_cache));
     5119        if (fw->size < HDSP_FIRMWARE_SIZE) {
     5120                dev_err(hdsp->card->dev,
     5121                        "too short firmware size %d (expected %d)\n",
     5122                           (int)fw->size, HDSP_FIRMWARE_SIZE);
    53795123                release_firmware(fw);
    53805124                return -EINVAL;
    53815125        }
    53825126
    5383         memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
    5384 
    5385         release_firmware(fw);
     5127        hdsp->firmware = fw;
    53865128
    53875129        hdsp->state |= HDSP_FirmwareCached;
     
    53955137
    53965138                if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
    5397                         snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
     5139                        dev_err(hdsp->card->dev,
     5140                                "error creating hwdep device\n");
    53985141                        return err;
    53995142                }
     
    54015144                snd_hdsp_initialize_midi_flush(hdsp);
    54025145                if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
    5403                         snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
     5146                        dev_err(hdsp->card->dev,
     5147                                "error creating alsa devices\n");
    54045148                        return err;
    54055149                }
     
    54075151        return 0;
    54085152}
    5409 #endif
    5410 
    5411 static int __devinit snd_hdsp_create(struct snd_card *card,
    5412                                      struct hdsp *hdsp)
     5153
     5154static int snd_hdsp_create(struct snd_card *card,
     5155                           struct hdsp *hdsp)
    54135156{
    54145157        struct pci_dev *pci = hdsp->pci;
     
    54395182        spin_lock_init(&hdsp->lock);
    54405183
    5441         tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
     5184        INIT_WORK(&hdsp->midi_work, hdsp_midi_work);
    54425185
    54435186        pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
     
    54775220                return err;
    54785221        hdsp->port = pci_resource_start(pci, 0);
    5479         if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
    5480                 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
     5222        if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
     5223                dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
     5224                        hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
    54815225                return -EBUSY;
    54825226        }
    54835227
    54845228        if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
    5485                         "hdsp", hdsp)) {
    5486                 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
     5229                        KBUILD_MODNAME, hdsp)) {
     5230                dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
    54875231                return -EBUSY;
    54885232        }
    54895233
    54905234        hdsp->irq = pci->irq;
     5235        card->sync_irq = hdsp->irq;
    54915236        hdsp->precise_ptr = 0;
    5492         hdsp->use_midi_tasklet = 1;
     5237        hdsp->use_midi_work = 1;
    54935238        hdsp->dds_value = 0;
    54945239
     
    55055250
    55065251                if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
    5507 #ifdef HDSP_FW_LOADER
    55085252                        if ((err = hdsp_request_fw_loader(hdsp)) < 0)
    55095253                                /* we don't fail as this can happen
     
    55115255                                   firmware upload
    55125256                                */
    5513                                 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
     5257                                dev_err(hdsp->card->dev,
     5258                                        "couldn't get firmware from userspace. try using hdsploader\n");
    55145259                        else
    55155260                                /* init is complete, we return */
    55165261                                return 0;
    5517 #endif
    55185262                        /* we defer initialization */
    5519                         snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
     5263                        dev_info(hdsp->card->dev,
     5264                                 "card initialization pending : waiting for firmware\n");
    55205265                        if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
    55215266                                return err;
    55225267                        return 0;
    55235268                } else {
    5524                         snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
     5269                        dev_info(hdsp->card->dev,
     5270                                 "Firmware already present, initializing card.\n");
    55255271                        if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
    55265272                                hdsp->io_type = RPM;
     
    55595305        if (hdsp->port) {
    55605306                /* stop the audio, and cancel all interrupts */
    5561                 tasklet_kill(&hdsp->midi_tasklet);
     5307                cancel_work_sync(&hdsp->midi_work);
    55625308                hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
    55635309                hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
     
    55695315        snd_hdsp_free_buffers(hdsp);
    55705316
    5571         if (hdsp->iobase)
    5572                 iounmap(hdsp->iobase);
     5317        release_firmware(hdsp->firmware);
     5318        vfree(hdsp->fw_uploaded);
     5319        iounmap(hdsp->iobase);
    55735320
    55745321        if (hdsp->port)
     
    55875334}
    55885335
    5589 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
    5590                                     const struct pci_device_id *pci_id)
     5336static int snd_hdsp_probe(struct pci_dev *pci,
     5337                          const struct pci_device_id *pci_id)
    55915338{
    55925339        static int dev;
     
    56025349        }
    56035350
    5604         err = snd_card_create(index[dev], id[dev], THIS_MODULE,
    5605                               sizeof(struct hdsp), &card);
     5351        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     5352                           sizeof(struct hdsp), &card);
    56065353        if (err < 0)
    56075354                return err;
     
    56115358        hdsp->dev = dev;
    56125359        hdsp->pci = pci;
    5613         snd_card_set_dev(card, &pci->dev);
    5614 
    5615         if ((err = snd_hdsp_create(card, hdsp)) < 0) {
    5616                 snd_card_free(card);
    5617                 return err;
    5618         }
     5360        err = snd_hdsp_create(card, hdsp);
     5361        if (err)
     5362                goto free_card;
    56195363
    56205364        strcpy(card->shortname, "Hammerfall DSP");
    56215365        sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
    56225366                hdsp->port, hdsp->irq);
    5623 
    5624         if ((err = snd_card_register(card)) < 0) {
     5367        err = snd_card_register(card);
     5368        if (err) {
     5369free_card:
    56255370                snd_card_free(card);
    56265371                return err;
     
    56315376}
    56325377
    5633 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
     5378static void snd_hdsp_remove(struct pci_dev *pci)
    56345379{
    56355380        snd_card_free(pci_get_drvdata(pci));
    5636         pci_set_drvdata(pci, NULL);
    5637 }
    5638 
    5639 static struct pci_driver driver = {
    5640         .name =     "RME Hammerfall DSP",
     5381}
     5382
     5383static struct pci_driver hdsp_driver = {
     5384        .name =     KBUILD_MODNAME,
    56415385        .id_table = snd_hdsp_ids,
    56425386        .probe =    snd_hdsp_probe,
    5643         .remove = __devexit_p(snd_hdsp_remove),
     5387        .remove = snd_hdsp_remove,
    56445388};
    56455389
    5646 static int __init alsa_card_hdsp_init(void)
    5647 {
    5648         return pci_register_driver(&driver);
    5649 }
    5650 
    5651 static void __exit alsa_card_hdsp_exit(void)
    5652 {
    5653         pci_unregister_driver(&driver);
    5654 }
    5655 
    5656 module_init(alsa_card_hdsp_init)
    5657 module_exit(alsa_card_hdsp_exit)
     5390module_pci_driver(hdsp_driver);
Note: See TracChangeset for help on using the changeset viewer.