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

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 * Driver for ESS Maestro3/Allegro (ES1988) soundcards.
     
    78 * OSS/Free by Zach Brown.  Many thanks to Zach!
    89 *
    9  *   This program is free software; you can redistribute it and/or modify
    10  *   it under the terms of the GNU General Public License as published by
    11  *   the Free Software Foundation; either version 2 of the License, or
    12  *   (at your option) any later version.
    13  *
    14  *   This program is distributed in the hope that it will be useful,
    15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  *   GNU General Public License for more details.
    18  *
    19  *   You should have received a copy of the GNU General Public License
    20  *   along with this program; if not, write to the Free Software
    21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    22  *
    23  *
    2410 * ChangeLog:
    2511 * Aug. 27, 2001
    2612 *     - Fixed deadlock on capture
    2713 *     - Added Canyon3D-2 support by Rob Riggs <rob@pangalactic.org>
    28  *
    2914 */
    3015 
    3116#define CARD_NAME "ESS Maestro3/Allegro/Canyon3D-2"
    3217#define DRIVER_NAME "Maestro3"
    33 
    34 #include <asm/io.h>
     18#ifdef TARGET_OS2
     19#define KBUILD_MODNAME "Maestro3"
     20#endif
     21
     22#include <linux/io.h>
    3523#include <linux/delay.h>
    3624#include <linux/interrupt.h>
     
    4028#include <linux/slab.h>
    4129#include <linux/vmalloc.h>
    42 #include <linux/moduleparam.h>
     30#include <linux/module.h>
    4331#include <linux/firmware.h>
    4432#include <linux/input.h>
     
    6553static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    6654static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    67 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* all enabled */
     55static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* all enabled */
    6856#ifndef TARGET_OS2
    69 static int external_amp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
     57static bool external_amp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
    7058static int amp_gpio[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
    7159#else
     
    366354#define DSP2HOST_REQ_TIMER      0x04
    367355
    368 /* AC97 registers */
    369 /* XXX fix this crap up */
    370 /*#define AC97_RESET              0x00*/
    371 
    372 #define AC97_VOL_MUTE_B         0x8000
    373 #define AC97_VOL_M              0x1F
    374 #define AC97_LEFT_VOL_S         8
    375 
    376 #define AC97_MASTER_VOL         0x02
    377 #define AC97_LINE_LEVEL_VOL     0x04
    378 #define AC97_MASTER_MONO_VOL    0x06
    379 #define AC97_PC_BEEP_VOL        0x0A
    380 #define AC97_PC_BEEP_VOL_M      0x0F
    381 #define AC97_SROUND_MASTER_VOL  0x38
    382 #define AC97_PC_BEEP_VOL_S      1
    383 
    384 /*#define AC97_PHONE_VOL          0x0C
    385 #define AC97_MIC_VOL            0x0E*/
    386 #define AC97_MIC_20DB_ENABLE    0x40
    387 
    388 /*#define AC97_LINEIN_VOL         0x10
    389 #define AC97_CD_VOL             0x12
    390 #define AC97_VIDEO_VOL          0x14
    391 #define AC97_AUX_VOL            0x16*/
    392 #define AC97_PCM_OUT_VOL        0x18
    393 /*#define AC97_RECORD_SELECT      0x1A*/
    394 #define AC97_RECORD_MIC         0x00
    395 #define AC97_RECORD_CD          0x01
    396 #define AC97_RECORD_VIDEO       0x02
    397 #define AC97_RECORD_AUX         0x03
    398 #define AC97_RECORD_MONO_MUX    0x02
    399 #define AC97_RECORD_DIGITAL     0x03
    400 #define AC97_RECORD_LINE        0x04
    401 #define AC97_RECORD_STEREO      0x05
    402 #define AC97_RECORD_MONO        0x06
    403 #define AC97_RECORD_PHONE       0x07
    404 
    405 /*#define AC97_RECORD_GAIN        0x1C*/
    406 #define AC97_RECORD_VOL_M       0x0F
    407 
    408 /*#define AC97_GENERAL_PURPOSE    0x20*/
    409 #define AC97_POWER_DOWN_CTRL    0x26
    410 #define AC97_ADC_READY          0x0001
    411 #define AC97_DAC_READY          0x0002
    412 #define AC97_ANALOG_READY       0x0004
    413 #define AC97_VREF_ON            0x0008
    414 #define AC97_PR0                0x0100
    415 #define AC97_PR1                0x0200
    416 #define AC97_PR2                0x0400
    417 #define AC97_PR3                0x0800
    418 #define AC97_PR4                0x1000
    419 
    420 #define AC97_RESERVED1          0x28
    421 
    422 #define AC97_VENDOR_TEST        0x5A
    423 
    424 #define AC97_CLOCK_DELAY        0x5C
    425 #define AC97_LINEOUT_MUX_SEL    0x0001
    426 #define AC97_MONO_MUX_SEL       0x0002
    427 #define AC97_CLOCK_DELAY_SEL    0x1F
    428 #define AC97_DAC_CDS_SHIFT      6
    429 #define AC97_ADC_CDS_SHIFT      11
    430 
    431 #define AC97_MULTI_CHANNEL_SEL  0x74
    432 
    433 /*#define AC97_VENDOR_ID1         0x7C
    434 #define AC97_VENDOR_ID2         0x7E*/
    435 
    436356/*
    437357 * ASSP control regs
     
    855775        char phys[64];                  /* physical device path */
    856776#else
    857         spinlock_t ac97_lock;
    858777        struct snd_kcontrol *master_switch;
    859778        struct snd_kcontrol *master_volume;
    860         struct tasklet_struct hwvol_tq;
    861779#endif
     780        struct work_struct hwvol_work;
    862781
    863782        unsigned int in_suspend;
    864783
    865 #ifdef CONFIG_PM
     784#ifdef CONFIG_PM_SLEEP
    866785        u16 *suspend_mem;
    867786#endif
     
    874793 * pci ids
    875794 */
    876 static DEFINE_PCI_DEVICE_TABLE(snd_m3_ids) = {
     795static const struct pci_device_id snd_m3_ids[] = {
    877796        {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID,
    878797         PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
     
    896815MODULE_DEVICE_TABLE(pci, snd_m3_ids);
    897816
    898 static struct snd_pci_quirk m3_amp_quirk_list[] __devinitdata = {
     817static const struct snd_pci_quirk m3_amp_quirk_list[] = {
    899818        SND_PCI_QUIRK(0x0E11, 0x0094, "Compaq Evo N600c", 0x0c),
    900819        SND_PCI_QUIRK(0x10f7, 0x833e, "Panasonic CF-28", 0x0d),
     
    905824};
    906825
    907 static struct snd_pci_quirk m3_irda_quirk_list[] __devinitdata = {
     826static const struct snd_pci_quirk m3_irda_quirk_list[] = {
    908827        SND_PCI_QUIRK(0x1028, 0x00b0, "Dell Inspiron 4000", 1),
    909828        SND_PCI_QUIRK(0x1028, 0x00a4, "Dell Inspiron 8000", 1),
     
    913832
    914833/* hardware volume quirks */
    915 static struct snd_pci_quirk m3_hv_quirk_list[] __devinitdata = {
     834static const struct snd_pci_quirk m3_hv_quirk_list[] = {
    916835        /* Allegro chips */
    917836        SND_PCI_QUIRK(0x0E11, 0x002E, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
     
    991910
    992911/* HP Omnibook quirks */
    993 static struct snd_pci_quirk m3_omnibook_quirk_list[] __devinitdata = {
     912static const struct snd_pci_quirk m3_omnibook_quirk_list[] = {
    994913        SND_PCI_QUIRK_ID(0x103c, 0x0010), /* HP OmniBook 6000 */
    995914        SND_PCI_QUIRK_ID(0x103c, 0x0011), /* HP OmniBook 500 */
     
    14701389{
    14711390        struct m3_dma *s = substream->runtime->private_data;
    1472         int err;
    1473 
    1474         if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
    1475                 return err;
     1391
    14761392        /* set buffer address */
    14771393        s->buffer_addr = substream->runtime->dma_addr;
    14781394        if (s->buffer_addr & 0x3) {
    1479                 snd_printk(KERN_ERR "oh my, not aligned\n");
     1395                dev_err(substream->pcm->card->dev, "oh my, not aligned\n");
    14801396                s->buffer_addr = s->buffer_addr & ~0x3;
    14811397        }
     
    14901406                return 0;
    14911407        s = substream->runtime->private_data;
    1492         snd_pcm_lib_free_pages(substream);
    14931408        s->buffer_addr = 0;
    14941409        return 0;
     
    16141529   generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
    16151530   of a byte wide register. The meaning of bits 0 and 4 is unknown. */
    1616 static void snd_m3_update_hw_volume(unsigned long private_data)
    1617 {
    1618         struct snd_m3 *chip = (struct snd_m3 *) private_data;
     1531static void snd_m3_update_hw_volume(struct work_struct *work)
     1532{
     1533        struct snd_m3 *chip = container_of(work, struct snd_m3, hwvol_work);
    16191534        int x, val;
    1620 #ifndef CONFIG_SND_MAESTRO3_INPUT
    1621         unsigned long flags;
    1622 #endif
    16231535
    16241536        /* Figure out which volume control button was pushed,
     
    16501562                return;
    16511563
    1652         /* FIXME: we can't call snd_ac97_* functions since here is in tasklet. */
    1653         spin_lock_irqsave(&chip->ac97_lock, flags);
    1654 
    1655         val = chip->ac97->regs[AC97_MASTER_VOL];
     1564        val = snd_ac97_read(chip->ac97, AC97_MASTER);
    16561565        switch (x) {
    16571566        case 0x88:
     
    16601569                   happens when pressing the mute button. */
    16611570                val ^= 0x8000;
    1662                 chip->ac97->regs[AC97_MASTER_VOL] = val;
    1663                 outw(val, chip->iobase + CODEC_DATA);
    1664                 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
    1665                 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
    1666                                &chip->master_switch->id);
    16671571                break;
    16681572        case 0xaa:
     
    16721576                if ((val & 0x7f00) > 0)
    16731577                        val -= 0x0100;
    1674                 chip->ac97->regs[AC97_MASTER_VOL] = val;
    1675                 outw(val, chip->iobase + CODEC_DATA);
    1676                 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
    1677                 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
    1678                                &chip->master_volume->id);
    16791578                break;
    16801579        case 0x66:
     
    16841583                if ((val & 0x7f00) < 0x1f00)
    16851584                        val += 0x0100;
    1686                 chip->ac97->regs[AC97_MASTER_VOL] = val;
    1687                 outw(val, chip->iobase + CODEC_DATA);
    1688                 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
     1585                break;
     1586        }
     1587        if (snd_ac97_update(chip->ac97, AC97_MASTER, val))
    16891588                snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
    1690                                &chip->master_volume->id);
    1691                 break;
    1692         }
    1693         spin_unlock_irqrestore(&chip->ac97_lock, flags);
     1589                               &chip->master_switch->id);
    16941590#else
    16951591        if (!chip->input_dev)
     
    17351631
    17361632        if (status & HV_INT_PENDING)
    1737 #ifdef CONFIG_SND_MAESTRO3_INPUT
    1738                 snd_m3_update_hw_volume((unsigned long)chip);
    1739 #else
    1740                 tasklet_schedule(&chip->hwvol_tq);
    1741 #endif
     1633                schedule_work(&chip->hwvol_work);
    17421634
    17431635        /*
     
    17781670 */
    17791671
    1780 static struct snd_pcm_hardware snd_m3_playback =
     1672static const struct snd_pcm_hardware snd_m3_playback =
    17811673{
    17821674        .info =                 (SNDRV_PCM_INFO_MMAP |
     
    17991691};
    18001692
    1801 static struct snd_pcm_hardware snd_m3_capture =
     1693static const struct snd_pcm_hardware snd_m3_capture =
    18021694{
    18031695        .info =                 (SNDRV_PCM_INFO_MMAP |
     
    19311823 */
    19321824
    1933 static struct snd_pcm_ops snd_m3_playback_ops = {
     1825static const struct snd_pcm_ops snd_m3_playback_ops = {
    19341826        .open =         snd_m3_playback_open,
    19351827        .close =        snd_m3_playback_close,
    1936         .ioctl =        snd_pcm_lib_ioctl,
    19371828        .hw_params =    snd_m3_pcm_hw_params,
    19381829        .hw_free =      snd_m3_pcm_hw_free,
     
    19421833};
    19431834
    1944 static struct snd_pcm_ops snd_m3_capture_ops = {
     1835static const struct snd_pcm_ops snd_m3_capture_ops = {
    19451836        .open =         snd_m3_capture_open,
    19461837        .close =        snd_m3_capture_close,
    1947         .ioctl =        snd_pcm_lib_ioctl,
    19481838        .hw_params =    snd_m3_pcm_hw_params,
    19491839        .hw_free =      snd_m3_pcm_hw_free,
     
    19531843};
    19541844
    1955 static int __devinit
     1845static int
    19561846snd_m3_pcm(struct snd_m3 * chip, int device)
    19571847{
     
    19721862        chip->pcm = pcm;
    19731863       
    1974         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    1975                                               snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
     1864        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
     1865                                       &chip->pci->dev, 64*1024, 64*1024);
    19761866
    19771867        return 0;
     
    19971887        } while (i-- > 0);
    19981888
    1999         snd_printk(KERN_ERR "ac97 serial bus busy\n");
     1889        dev_err(chip->card->dev, "ac97 serial bus busy\n");
    20001890        return 1;
    20011891}
     
    20051895{
    20061896        struct snd_m3 *chip = ac97->private_data;
    2007 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2008         unsigned long flags;
    2009 #endif
    20101897        unsigned short data = 0xffff;
    20111898
    20121899        if (snd_m3_ac97_wait(chip))
    20131900                goto fail;
    2014 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2015         spin_lock_irqsave(&chip->ac97_lock, flags);
    2016 #endif
    20171901        snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
    20181902        if (snd_m3_ac97_wait(chip))
    2019                 goto fail_unlock;
     1903                goto fail;
    20201904        data = snd_m3_inw(chip, CODEC_DATA);
    2021 fail_unlock:
    2022 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2023         spin_unlock_irqrestore(&chip->ac97_lock, flags);
    2024 #endif
    20251905fail:
    20261906        return data;
     
    20311911{
    20321912        struct snd_m3 *chip = ac97->private_data;
    2033 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2034         unsigned long flags;
    2035 #endif
    20361913
    20371914        if (snd_m3_ac97_wait(chip))
    20381915                return;
    2039 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2040         spin_lock_irqsave(&chip->ac97_lock, flags);
    2041 #endif
    20421916        snd_m3_outw(chip, val, CODEC_DATA);
    20431917        snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
    2044 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2045         spin_unlock_irqrestore(&chip->ac97_lock, flags);
    2046 #endif
    2047 }
    2048 
    2049 
    2050 static void snd_m3_remote_codec_config(int io, int isremote)
    2051 {
     1918        /*
     1919         * Workaround for buggy ES1988 integrated AC'97 codec. It remains silent
     1920         * until the MASTER volume or mute is touched (alsactl restore does not
     1921         * work).
     1922         */
     1923        if (ac97->id == 0x45838308 && reg == AC97_MASTER) {
     1924                snd_m3_ac97_wait(chip);
     1925                snd_m3_outw(chip, val, CODEC_DATA);
     1926                snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
     1927        }
     1928}
     1929
     1930
     1931static void snd_m3_remote_codec_config(struct snd_m3 *chip, int isremote)
     1932{
     1933        int io = chip->iobase;
     1934        u16 tmp;
     1935
    20521936        isremote = isremote ? 1 : 0;
    20531937
    2054         outw((inw(io + RING_BUS_CTRL_B) & ~SECOND_CODEC_ID_MASK) | isremote,
    2055              io + RING_BUS_CTRL_B);
     1938        tmp = inw(io + RING_BUS_CTRL_B) & ~SECOND_CODEC_ID_MASK;
     1939        /* enable dock on Dell Latitude C810 */
     1940        if (chip->pci->subsystem_vendor == 0x1028 &&
     1941            chip->pci->subsystem_device == 0x00e5)
     1942                tmp |= M3I_DOCK_ENABLE;
     1943        outw(tmp | isremote, io + RING_BUS_CTRL_B);
    20561944        outw((inw(io + SDO_OUT_DEST_CTRL) & ~COMMAND_ADDR_OUT) | isremote,
    20571945             io + SDO_OUT_DEST_CTRL);
     
    21051993                        dir |= 0x10; /* assuming pci bus master? */
    21061994
    2107                 snd_m3_remote_codec_config(io, 0);
     1995                snd_m3_remote_codec_config(chip, 0);
    21081996
    21091997                outw(IO_SRAM_ENABLE, io + RING_BUS_CTRL_A);
     
    21312019                delay2 += 100;
    21322020
    2133                 snd_printd("maestro3: retrying codec reset with delays of %d and %d ms\n",
     2021                dev_dbg(chip->card->dev,
     2022                        "retrying codec reset with delays of %d and %d ms\n",
    21342023                           delay1, delay2);
    21352024        }
     
    21472036}
    21482037
    2149 static int __devinit snd_m3_mixer(struct snd_m3 *chip)
     2038static int snd_m3_mixer(struct snd_m3 *chip)
    21502039{
    21512040        struct snd_ac97_bus *pbus;
     
    21552044#endif
    21562045        int err;
    2157         static struct snd_ac97_bus_ops ops = {
     2046        static const struct snd_ac97_bus_ops ops = {
    21582047                .write = snd_m3_ac97_write,
    21592048                .read = snd_m3_ac97_read,
     
    22012090{
    22022091        unsigned int i;
    2203         const u16 *data;
     2092        const __le16 *data;
    22042093
    22052094        /* zero kernel data */
     
    22192108
    22202109        /* write kernel into code memory.. */
    2221         data = (const u16 *)chip->assp_kernel_image->data;
     2110        data = (const __le16 *)chip->assp_kernel_image->data;
    22222111        for (i = 0 ; i * 2 < chip->assp_kernel_image->size; i++) {
    22232112                snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
     
    22322121         * need vectors, so we won't bother with them..
    22332122         */
    2234         data = (const u16 *)chip->assp_minisrc_image->data;
     2123        data = (const __le16 *)chip->assp_minisrc_image->data;
    22352124        for (i = 0; i * 2 < chip->assp_minisrc_image->size; i++) {
    22362125                snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
     
    22892178
    22902179
    2291 static int __devinit snd_m3_assp_client_init(struct snd_m3 *chip, struct m3_dma *s, int index)
     2180static int snd_m3_assp_client_init(struct snd_m3 *chip, struct m3_dma *s, int index)
    22922181{
    22932182        int data_bytes = 2 * ( MINISRC_TMP_BUFFER_SIZE / 2 +
     
    23102199
    23112200        if ((address + (data_bytes/2)) >= 0x1c00) {
    2312                 snd_printk(KERN_ERR "no memory for %d bytes at ind %d (addr 0x%x)\n",
     2201                dev_err(chip->card->dev,
     2202                        "no memory for %d bytes at ind %d (addr 0x%x)\n",
    23132203                           data_bytes, index, address);
    23142204                return -ENOMEM;
     
    24632353        int i;
    24642354
     2355        cancel_work_sync(&chip->hwvol_work);
    24652356#ifdef CONFIG_SND_MAESTRO3_INPUT
    24662357        if (chip->input_dev)
     
    24832374        }
    24842375
    2485 #ifdef CONFIG_PM
     2376#ifdef CONFIG_PM_SLEEP
    24862377        vfree(chip->suspend_mem);
    24872378#endif
     
    25052396 * APM support
    25062397 */
    2507 #ifdef CONFIG_PM
    2508 static int m3_suspend(struct pci_dev *pci, pm_message_t state)
    2509 {
    2510         struct snd_card *card = pci_get_drvdata(pci);
     2398#ifdef CONFIG_PM_SLEEP
     2399static int m3_suspend(struct device *dev)
     2400{
     2401        struct snd_card *card = dev_get_drvdata(dev);
    25112402        struct snd_m3 *chip = card->private_data;
    25122403        int i, dsp_index;
     
    25162407
    25172408        chip->in_suspend = 1;
     2409        cancel_work_sync(&chip->hwvol_work);
    25182410        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    2519         snd_pcm_suspend_all(chip->pcm);
    25202411        snd_ac97_suspend(chip->ac97);
    25212412
     
    25322423                chip->suspend_mem[dsp_index++] =
    25332424                        snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
    2534 
    2535         pci_disable_device(pci);
    2536         pci_save_state(pci);
    2537         pci_set_power_state(pci, pci_choose_state(pci, state));
    25382425        return 0;
    25392426}
    25402427
    2541 static int m3_resume(struct pci_dev *pci)
    2542 {
    2543         struct snd_card *card = pci_get_drvdata(pci);
     2428static int m3_resume(struct device *dev)
     2429{
     2430        struct snd_card *card = dev_get_drvdata(dev);
    25442431        struct snd_m3 *chip = card->private_data;
    25452432        int i, dsp_index;
     
    25472434        if (chip->suspend_mem == NULL)
    25482435                return 0;
    2549 
    2550         pci_set_power_state(pci, PCI_D0);
    2551         pci_restore_state(pci);
    2552         if (pci_enable_device(pci) < 0) {
    2553                 printk(KERN_ERR "maestor3: pci_enable_device failed, "
    2554                        "disabling device\n");
    2555                 snd_card_disconnect(card);
    2556                 return -EIO;
    2557         }
    2558         pci_set_master(pci);
    25592436
    25602437        /* first lets just bring everything back. .*/
     
    25922469        return 0;
    25932470}
    2594 #endif /* CONFIG_PM */
     2471
     2472static SIMPLE_DEV_PM_OPS(m3_pm, m3_suspend, m3_resume);
     2473#define M3_PM_OPS       &m3_pm
     2474#else
     2475#define M3_PM_OPS       NULL
     2476#endif /* CONFIG_PM_SLEEP */
    25952477
    25962478#ifdef CONFIG_SND_MAESTRO3_INPUT
    2597 static int __devinit snd_m3_input_register(struct snd_m3 *chip)
     2479static int snd_m3_input_register(struct snd_m3 *chip)
    25982480{
    25992481        struct input_dev *input_dev;
     
    26392521}
    26402522
    2641 static int __devinit
     2523static int
    26422524snd_m3_create(struct snd_card *card, struct pci_dev *pci,
    26432525              int enable_amp,
     
    26482530        int i, err;
    26492531        const struct snd_pci_quirk *quirk;
    2650         static struct snd_device_ops ops = {
     2532        static const struct snd_device_ops ops = {
    26512533                .dev_free =     snd_m3_dev_free,
    26522534        };
     
    26582540
    26592541        /* check, if we can restrict PCI DMA transfers to 28 bits */
    2660         if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
    2661             pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
    2662                 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
     2542        if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 ||
     2543            dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) {
     2544                dev_err(card->dev,
     2545                        "architecture does not support 28bit PCI busmaster DMA\n");
    26632546                pci_disable_device(pci);
    26642547                return -ENXIO;
     
    26722555
    26732556        spin_lock_init(&chip->reg_lock);
    2674 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2675         spin_lock_init(&chip->ac97_lock);
    2676 #endif
    26772557
    26782558        switch (pci->device) {
     
    26882568        chip->pci = pci;
    26892569        chip->irq = -1;
     2570        INIT_WORK(&chip->hwvol_work, snd_m3_update_hw_volume);
    26902571
    26912572        chip->external_amp = enable_amp;
     
    26952576                quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list);
    26962577                if (quirk) {
    2697 #ifndef TARGET_OS2
    2698                         snd_printdd(KERN_INFO "maestro3: set amp-gpio "
    2699                                     "for '%s'\n", quirk->name);
    2700 #endif
     2578                        dev_info(card->dev, "set amp-gpio for '%s'\n",
     2579                                 snd_pci_quirk_name(quirk));
    27012580                        chip->amp_gpio = quirk->value;
    27022581                } else if (chip->allegro_flag)
     
    27082587        quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list);
    27092588        if (quirk) {
    2710 #ifndef TARGET_OS2
    2711                 snd_printdd(KERN_INFO "maestro3: enabled irda workaround "
    2712                             "for '%s'\n", quirk->name);
    2713 #endif
     2589                dev_info(card->dev, "enabled irda workaround for '%s'\n",
     2590                         snd_pci_quirk_name(quirk));
    27142591                chip->irda_workaround = 1;
    27152592        }
     
    27312608        err = request_firmware(&chip->assp_kernel_image,
    27322609                               "ess/maestro3_assp_kernel.fw", &pci->dev);
    2733         if (err < 0) {
    2734                 snd_m3_free(chip);
    2735                 return err;
    2736         }
     2610        if (err < 0)
     2611                goto free_chip;
    27372612
    27382613        err = request_firmware(&chip->assp_minisrc_image,
    27392614                               "ess/maestro3_assp_minisrc.fw", &pci->dev);
    2740         if (err < 0) {
    2741                 snd_m3_free(chip);
    2742                 return err;
    2743         }
    2744 
    2745         if ((err = pci_request_regions(pci, card->driver)) < 0) {
    2746                 snd_m3_free(chip);
    2747                 return err;
    2748         }
     2615        if (err < 0)
     2616                goto free_chip;
     2617
     2618        err = pci_request_regions(pci, card->driver);
     2619        if (err < 0)
     2620                goto free_chip;
     2621
    27492622        chip->iobase = pci_resource_start(pci, 0);
    27502623       
     
    27612634        snd_m3_hv_init(chip);
    27622635
    2763 #ifndef CONFIG_SND_MAESTRO3_INPUT
    2764         tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
     2636        if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
     2637                        KBUILD_MODNAME, chip)) {
     2638                dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
     2639                err = -ENOMEM;
     2640                goto free_chip;
     2641        }
     2642        chip->irq = pci->irq;
     2643        card->sync_irq = chip->irq;
     2644
     2645#ifdef CONFIG_PM_SLEEP
     2646        chip->suspend_mem =
     2647                vmalloc(array_size(sizeof(u16),
     2648                                   REV_B_CODE_MEMORY_LENGTH +
     2649                                        REV_B_DATA_MEMORY_LENGTH));
     2650        if (chip->suspend_mem == NULL)
     2651                dev_warn(card->dev, "can't allocate apm buffer\n");
    27652652#endif
    27662653
    2767         if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
    2768                         card->driver, chip)) {
    2769                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
    2770                 snd_m3_free(chip);
    2771                 return -ENOMEM;
    2772         }
    2773         chip->irq = pci->irq;
    2774 
    2775 #ifdef CONFIG_PM
    2776         chip->suspend_mem = vmalloc(sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH));
    2777         if (chip->suspend_mem == NULL)
    2778                 snd_printk(KERN_WARNING "can't allocate apm buffer\n");
    2779 #endif
    2780 
    2781         if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
    2782                 snd_m3_free(chip);
    2783                 return err;
    2784         }
     2654        err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
     2655        if (err < 0)
     2656                goto free_chip;
    27852657
    27862658        if ((err = snd_m3_mixer(chip)) < 0)
     
    28002672                err = snd_m3_input_register(chip);
    28012673                if (err)
    2802                         snd_printk(KERN_WARNING "Input device registration "
    2803                                 "failed with error %i", err);
     2674                        dev_warn(card->dev,
     2675                                 "Input device registration failed with error %i",
     2676                                 err);
    28042677        }
    28052678#endif
     
    28082681        snd_m3_assp_continue(chip);
    28092682
    2810         snd_card_set_dev(card, &pci->dev);
    2811 
    28122683        *chip_ret = chip;
    28132684
    28142685        return 0;
     2686
     2687free_chip:
     2688        snd_m3_free(chip);
     2689        return err;
    28152690}
    28162691
    28172692/*
    28182693 */
    2819 static int __devinit
     2694static int
    28202695snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
    28212696{
     
    28252700        int err;
    28262701
    2827 #ifndef TARGET_OS2
    28282702        /* don't pick up modems */
    28292703        if (((pci->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
    28302704                return -ENODEV;
    2831 #endif
     2705
    28322706        if (dev >= SNDRV_CARDS)
    28332707                return -ENODEV;
     
    28372711        }
    28382712
    2839         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     2713        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     2714                           0, &card);
    28402715        if (err < 0)
    28412716                return err;
     
    28552730        }
    28562731
    2857         if ((err = snd_m3_create(card, pci,
    2858                                  external_amp[dev],
    2859                                  amp_gpio[dev],
    2860                                  &chip)) < 0) {
    2861                 snd_card_free(card);
    2862                 return err;
    2863         }
     2732        err = snd_m3_create(card, pci, external_amp[dev], amp_gpio[dev], &chip);
     2733        if (err < 0)
     2734                goto free_card;
     2735
    28642736        card->private_data = chip;
    28652737
     
    28682740                card->shortname, chip->iobase, chip->irq);
    28692741
    2870         if ((err = snd_card_register(card)) < 0) {
    2871                 snd_card_free(card);
    2872                 return err;
    2873         }
     2742        err = snd_card_register(card);
     2743        if (err < 0)
     2744                goto free_card;
    28742745
    28752746#if 0 /* TODO: not supported yet */
     
    28772748        err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
    28782749                                  chip->iobase + MPU401_DATA_PORT,
    2879                                   MPU401_INFO_INTEGRATED,
    2880                                   chip->irq, 0, &chip->rmidi);
     2750                                  MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
     2751                                  -1, &chip->rmidi);
    28812752        if (err < 0)
    2882                 printk(KERN_WARNING "maestro3: no MIDI support.\n");
     2753                dev_warn(card->dev, "no MIDI support.\n");
    28832754#endif
    28842755
     
    28862757        dev++;
    28872758        return 0;
    2888 }
    2889 
    2890 static void __devexit snd_m3_remove(struct pci_dev *pci)
     2759
     2760free_card:
     2761        snd_card_free(card);
     2762        return err;
     2763}
     2764
     2765static void snd_m3_remove(struct pci_dev *pci)
    28912766{
    28922767        snd_card_free(pci_get_drvdata(pci));
    2893         pci_set_drvdata(pci, NULL);
    2894 }
    2895 
    2896 static struct pci_driver driver = {
    2897         .name = "Maestro3",
     2768}
     2769
     2770static struct pci_driver m3_driver = {
     2771        .name = KBUILD_MODNAME,
    28982772        .id_table = snd_m3_ids,
    28992773        .probe = snd_m3_probe,
    2900         .remove = __devexit_p(snd_m3_remove),
    2901 #ifdef CONFIG_PM
    2902         .suspend = m3_suspend,
    2903         .resume = m3_resume,
    2904 #endif
     2774        .remove = snd_m3_remove,
     2775        .driver = {
     2776                .pm = M3_PM_OPS,
     2777        },
    29052778};
    29062779       
    2907 static int __init alsa_card_m3_init(void)
    2908 {
    2909         return pci_register_driver(&driver);
    2910 }
    2911 
    2912 static void __exit alsa_card_m3_exit(void)
    2913 {
    2914         pci_unregister_driver(&driver);
    2915 }
    2916 
    2917 module_init(alsa_card_m3_init)
    2918 module_exit(alsa_card_m3_exit)
     2780module_pci_driver(m3_driver);
Note: See TracChangeset for help on using the changeset viewer.