Changeset 246


Ignore:
Timestamp:
Aug 22, 2007, 5:33:25 AM (18 years ago)
Author:
Brendan Oakley
Message:

Merged to ALSA 0.9.3

Location:
GPL/branches/alsa-resync1/alsa-kernel
Files:
2 added
60 edited
1 moved

Legend:

Unmodified
Added
Removed
  • GPL/branches/alsa-resync1/alsa-kernel/core/info.c

    r222 r246  
    2121
    2222#include <sound/driver.h>
     23#include <linux/version.h>
    2324#include <linux/init.h>
    2425#include <linux/vmalloc.h>
  • GPL/branches/alsa-resync1/alsa-kernel/core/makefile.os2

    r224 r246  
    3232#
    3333#===================================================================
    34 FILE1    = sound.obj init.obj memory.obj memory_wrapper.obj memalloc.obj sgbuf.obj
     34FILE1    = sound.obj init.obj memory.obj memalloc.obj sgbuf.obj
    3535FILE2    = control.obj device.obj misc.obj wrappers.obj
    3636#FILE3    = sound_oss.obj info_oss.obj isadma.obj
  • GPL/branches/alsa-resync1/alsa-kernel/core/pcm_native.c

    r232 r246  
    2121
    2222#include <sound/driver.h>
     23#include <linux/version.h>
    2324#include <linux/mm.h>
    2425#include <linux/file.h>
  • GPL/branches/alsa-resync1/alsa-kernel/core/sound.c

    r224 r246  
    2121
    2222#include <sound/driver.h>
     23#include <linux/version.h>
    2324#include <linux/init.h>
    2425#include <linux/slab.h>
  • GPL/branches/alsa-resync1/alsa-kernel/core/wrappers.c

    r224 r246  
    2020 */
    2121
    22 #include <linux/version.h>
    2322#include <linux/config.h>
    2423#include <linux/module.h>
  • GPL/branches/alsa-resync1/alsa-kernel/drivers/dummy.c

    r212 r246  
    2020
    2121#include <sound/driver.h>
     22#include <linux/version.h>
    2223#include <linux/init.h>
    2324#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
     
    5960#define MAX_BUFFER_SIZE         (256 * 1024)
    6061#define USE_FORMATS             SNDRV_PCM_FMTBIT_S32_LE
    61 #define USE_CHANNELS_MIN        10
    62 #define USE_CHANNELS_MAX        10
     62#define USE_CHANNELS_MIN        12
     63#define USE_CHANNELS_MAX        12
    6364#define USE_PERIODS_MIN         1
    6465#define USE_PERIODS_MAX         1024
  • GPL/branches/alsa-resync1/alsa-kernel/drivers/mtpav.c

    r224 r246  
    103103 *      defines
    104104 */
    105 //#define USE_FAKE_MTP //       dont actually read/write to MTP device (for debugging without an actual unit) (does not work yet)
     105//#define USE_FAKE_MTP //       don't actually read/write to MTP device (for debugging without an actual unit) (does not work yet)
    106106
    107107// parallel port usage masks
     
    587587}
    588588
    589 static void snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs)
    590 {
    591         mtpav_t *mcard = snd_magic_cast(mtpav_t, dev_id, return);
     589static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs)
     590{
     591        mtpav_t *mcard = snd_magic_cast(mtpav_t, dev_id, return IRQ_NONE);
    592592
    593593        //printk("irqh()\n");
     
    595595        snd_mtpav_read_bytes(mcard);
    596596        spin_unlock(&mcard->spinlock);
     597        return IRQ_HANDLED;
    597598}
    598599
     
    765766                goto __error;
    766767
    767         err = snd_card_register(mtp_card->card);        // dont snd_card_register until AFTER all cards reources done!
     768        err = snd_card_register(mtp_card->card);        // don't snd_card_register until AFTER all cards reources done!
    768769
    769770        //printk("snd_card_register returned %d\n", err);
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/ad1848.h

    r222 r246  
    2424
    2525#include "pcm.h"
     26#include <linux/interrupt.h>
    2627
    2728/* IO ports */
     
    165166const snd_pcm_ops_t *snd_ad1848_get_pcm_ops(int direction);
    166167int snd_ad1848_mixer(ad1848_t * chip);
    167 void snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs);
     168irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs);
    168169
    169170/* exported mixer stuffs */
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/adriver.h

    r234 r246  
    2222 *
    2323 */
     24
     25#include <linux/version.h>
    2426
    2527#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 3)
     
    213215#endif
    214216
     217/* pm_message_t type */
     218#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
     219#include <linux/pm.h>
     220#ifndef PMSG_FREEZE
     221typedef u32 /* __bitwise */ pm_message_t;
     222#define PMSG_FREEZE     3
     223#define PMSG_SUSPEND    3
     224#define PMSG_ON         0
     225#endif
     226#endif
    215227#ifndef PCI_D0
    216228#define PCI_D0     0
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/config.h

    r92 r246  
    4444#define EXPORT_SYMBOL(a)
    4545#define CONFIG_SOUND
    46 #define CONFIG_SND_VERSION      "0.0.1"
     46#define CONFIG_SND_VERSION      "0.9.3"
    4747#define ATTRIBUTE_UNUSED
    4848
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/core.h

    r224 r246  
    198198#define snd_power_lock(card)            do { (void)(card); } while (0)
    199199#define snd_power_unlock(card)          do { (void)(card); } while (0)
    200 #define snd_power_wait(card)            do { (void)(card); } while (0)
    201 #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
     200static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; }
     201#define snd_power_get_state(card)       SNDRV_CTL_POWER_D0
    202202#define snd_power_change_state(card, state)     do { (void)(card); } while (0)
    203203#define snd_card_set_pm_callback(card,suspend,resume,data) -EINVAL
     
    501501#define unlikely(x)     __builtin_expect((x),0)
    502502
    503 typedef u32 /*__bitwise*/ pm_message_t;
    504 
    505 #ifndef __devexit_p
    506 #define __devexit_p(x) x
    507 #endif
    508 
    509503#define printk_ratelimit()      1
    510504
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/cs4231.h

    r215 r246  
    316316void snd_cs4231_mce_down(cs4231_t *chip);
    317317
    318 void snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs);
     318irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs);
    319319
    320320const char *snd_cs4231_chip_id(cs4231_t *chip);
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/driver.h

    r224 r246  
    2828
    2929#include <linux/config.h>
    30 #include <linux/version.h>
    3130
    3231#define SNDRV_CARDS             8       /* number of supported soundcards - don't change - minor numbers */
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/es1688.h

    r96 r246  
    2525#include "control.h"
    2626#include "pcm.h"
     27#include <linux/interrupt.h>
    2728
    2829#define ES1688_HW_AUTO          0x0000
     
    110111unsigned char snd_es1688_mixer_read(es1688_t *chip, unsigned char reg);
    111112
    112 void snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs);
     113irqreturn_t snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs);
    113114
    114115int snd_es1688_create(snd_card_t * card,
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/gus.h

    r222 r246  
    562562
    563563#if 0
    564 extern void snd_gf1_lfo_effect_interrupt(snd_gus_card_t * gus, snd_gf1_voice_t * voice);
     564extern irqreturn_t snd_gf1_lfo_effect_interrupt(snd_gus_card_t * gus, snd_gf1_voice_t * voice);
    565565#endif
    566566extern void snd_gf1_lfo_init(snd_gus_card_t * gus);
     
    667667/* gus_irq.c */
    668668
    669 void snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs);
     669irqreturn_t snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs);
    670670#ifdef CONFIG_SND_DEBUG
    671671void snd_gus_irq_profile_init(snd_gus_card_t *gus);
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/initval.h

    r224 r246  
    135135#include <linux/interrupt.h>
    136136
    137 static void snd_legacy_empty_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
    138 {
     137static irqreturn_t snd_legacy_empty_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
     138{
     139        return IRQ_HANDLED;
    139140}
    140141
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/isapnp.h

    r234 r246  
    2222#ifndef LINUX_ISAPNP_H
    2323#define LINUX_ISAPNP_H
     24
     25#define ISAPNP_ALSA_LOCAL 1
    2426
    2527/*
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/snd_wavefront.h

    r212 r246  
    9999struct _snd_wavefront_card {
    100100        snd_wavefront_t wavefront;
    101 #ifdef __ISAPNP__
    102         struct isapnp_dev *wss;
    103         struct isapnp_dev *ctrl;
    104         struct isapnp_dev *mpu;
    105         struct isapnp_dev *synth;
    106 #endif /* CONFIG_ISAPNP */
     101#ifdef CONFIG_PNP
     102        struct pnp_dev *wss;
     103        struct pnp_dev *ctrl;
     104        struct pnp_dev *mpu;
     105        struct pnp_dev *synth;
     106#endif /* CONFIG_PNP */
    107107};
    108108
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/uda1341.h

    r224 r246  
    1616 */
    1717
    18 /* uda1341.h,v 1.4 2003/02/25 12:48:16 perex Exp */
     18/* uda1341.h,v 1.5 2003/04/19 13:34:32 perex Exp */
    1919
    2020#define UDA1341_ALSA_NAME "snd-uda1341"
     
    211211        CMD_AGC_TIME,
    212212        CMD_AGC_LEVEL,
     213#ifdef CONFIG_PM
     214        CMD_SUSPEND,
     215        CMD_RESUME,
     216#endif
    213217        CMD_LAST,
    214218};
     
    222226
    223227int __init snd_chip_uda1341_mixer_new(snd_card_t *card, struct l3_client **clnt);
    224 void __init snd_chip_uda1341_mixer_del(snd_card_t *card);
    225 
    226 #ifdef DEBUG_MODE
    227 #define DEBUG(format, args...)      do{printk(format, ##args);}while(0)
    228 #else
    229 #define DEBUG(format, args...)      /* nothing */
    230 #endif
    231 
    232 #ifdef DEBUG_FUNCTION_NAMES
    233 #define DEBUG_NAME(format, args...)     do{printk(format, ##args);}while(0)
    234 #else
    235 #define DEBUG_NAME(format, args...)     /* nothing */
    236 #endif
    237228
    238229/*
  • GPL/branches/alsa-resync1/alsa-kernel/include/sound/wavefront.h

    r96 r246  
    688688/* Allow direct user-space control over FX memory/coefficient data.
    689689   In theory this could be used to download the FX microprogram,
    690    but it would be a little slower, and involve some wierd code.
     690   but it would be a little slower, and involve some weird code.
    691691 */
    692692
  • GPL/branches/alsa-resync1/alsa-kernel/isa/ad1816a/ad1816a.c

    r224 r246  
    2323#include <linux/time.h>
    2424#include <linux/wait.h>
    25 #ifndef LINUX_ISAPNP_H
    26 #include <linux/isapnp.h>
    27 #define isapnp_card pci_bus
    28 #define isapnp_dev pci_dev
    29 #endif
     25#include <linux/pnp.h>
    3026#include <sound/core.h>
    3127#define SNDRV_GET_ID
     
    9490
    9591struct snd_card_ad1816a {
    96 #ifdef __ISAPNP__
    97         struct isapnp_dev *dev;
    98         struct isapnp_dev *devmpu;
    99 #endif  /* __ISAPNP__ */
     92        struct pnp_dev *dev;
     93        struct pnp_dev *devmpu;
    10094};
    10195
    102 static snd_card_t *snd_ad1816a_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    103 
    104 #ifdef __ISAPNP__
    105 
    106 static struct isapnp_card *snd_ad1816a_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    107 static const struct isapnp_card_id *snd_ad1816a_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    108 
    109 #define ISAPNP_AD1816A(_va, _vb, _vc, _device, _fa, _fb, _fc, _audio, _mpu401) \
    110         { \
    111                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    112                 .devs = { ISAPNP_DEVICE_ID(_fa, _fb, _fc, _audio), \
    113                          ISAPNP_DEVICE_ID(_fa, _fb, _fc, _mpu401), } \
    114         }
    115 
    116 static struct isapnp_card_id snd_ad1816a_pnpids[] __devinitdata = {
     96static struct pnp_card_device_id snd_ad1816a_pnpids[] __devinitdata = {
     97        /* Analog Devices AD1815 */
     98        { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
     99        /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
     100        { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
     101        /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
     102        { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
     103        /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
     104        { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
    117105        /* Highscreen Sound-Boostar 16 3D */
    118         ISAPNP_AD1816A('M','D','K',0x1605,'A','D','S',0x7180,0x7181),
    119         /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
    120         ISAPNP_AD1816A('L','W','C',0x1061,'A','D','S',0x7180,0x7181),
    121         /* Analog Devices AD1815 */
    122         ISAPNP_AD1816A('A','D','S',0x7150,'A','D','S',0x7150,0x7151),
    123         /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
    124         ISAPNP_AD1816A('A','D','S',0x7181,'A','D','S',0x7180,0x7181),
     106        { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
     107        /* Shark Predator ISA - added by Ken Arromdee */
     108        { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
     109        /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */
     110        { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
    125111        /* Analog Devices AD1816A - Terratec Base 64 */
    126         ISAPNP_AD1816A('T','E','R',0x1411,'A','D','S',0x7180,0x7181),
    127         /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */
    128         ISAPNP_AD1816A('T','E','R',0x1112,'A','D','S',0x7180,0x7181),
    129         /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
    130         ISAPNP_AD1816A('A','Z','T',0x1022,'A','Z','T',0x1018,0x2002),
    131         /* Shark Predator ISA - added by Ken Arromdee */
    132         ISAPNP_AD1816A('S','M','M',0x7180,'A','D','S',0x7180,0x7181),
    133         { ISAPNP_CARD_END, }
     112        { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
     113        /* end */
     114        { .id = "" }
    134115};
    135116
    136 ISAPNP_CARD_TABLE(snd_ad1816a_pnpids);
    137 
    138 #endif  /* __ISAPNP__ */
     117MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
     118
    139119
    140120#define DRIVER_NAME     "snd-card-ad1816a"
    141121
    142122
    143 #ifdef __ISAPNP__
    144 static int __init snd_card_ad1816a_isapnp(int dev,
    145                                           struct snd_card_ad1816a *acard)
    146 {
    147         const struct isapnp_card_id *id = snd_ad1816a_isapnp_id[dev];
    148         struct isapnp_card *card = snd_ad1816a_isapnp_cards[dev];
    149         struct isapnp_dev *pdev;
    150 
    151         acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    152         if (acard->dev->active) {
    153                 acard->dev = NULL;
     123static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
     124                                          struct pnp_card_link *card,
     125                                          const struct pnp_card_device_id *id)
     126{
     127        struct pnp_dev *pdev;
     128        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
     129        int err;
     130
     131        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     132        if (acard->dev == NULL) {
     133                kfree(cfg);
    154134                return -EBUSY;
    155135        }
    156         acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    157         if (acard->devmpu->active) {
    158                 acard->dev = acard->devmpu = NULL;
     136        acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
     137        if (acard->devmpu == NULL) {
     138                kfree(cfg);
    159139                return -EBUSY;
    160140        }
    161141
    162142        pdev = acard->dev;
    163         if (pdev->prepare(pdev) < 0)
    164                 return -EAGAIN;
     143        pnp_init_resource_table(cfg);
    165144
    166145        if (port[dev] != SNDRV_AUTO_PORT)
    167                 isapnp_resource_change(&pdev->resource[2], port[dev], 16);
     146                pnp_resource_change(&cfg->port_resource[2], port[dev], 16);
    168147        if (fm_port[dev] != SNDRV_AUTO_PORT)
    169                 isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4);
     148                pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
    170149        if (dma1[dev] != SNDRV_AUTO_DMA)
    171                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev],
    172                         1);
     150                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    173151        if (dma2[dev] != SNDRV_AUTO_DMA)
    174                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev],
    175                         1);
     152                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    176153        if (irq[dev] != SNDRV_AUTO_IRQ)
    177                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    178 
    179         if (pdev->activate(pdev) < 0) {
    180                 printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
     154                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     155
     156        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     157                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     158        err = pnp_activate_dev(pdev);
     159        if (err < 0) {
     160                printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
     161                kfree(cfg);
    181162                return -EBUSY;
    182163        }
    183164
    184         port[dev] = pdev->resource[2].start;
    185         fm_port[dev] = pdev->resource[1].start;
    186         dma1[dev] = pdev->dma_resource[0].start;
    187         dma2[dev] = pdev->dma_resource[1].start;
    188         irq[dev] = pdev->irq_resource[0].start;
     165        port[dev] = pnp_port_start(pdev, 2);
     166        fm_port[dev] = pnp_port_start(pdev, 1);
     167        dma1[dev] = pnp_dma(pdev, 0);
     168        dma2[dev] = pnp_dma(pdev, 1);
     169        irq[dev] = pnp_irq(pdev, 0);
    189170
    190171        pdev = acard->devmpu;
    191         if (pdev == NULL || pdev->prepare(pdev) < 0) {
    192                 mpu_port[dev] = -1;
    193                 acard->devmpu = NULL;
    194                 return 0;
    195         }
     172        pnp_init_resource_table(cfg);
    196173
    197174        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    198                 isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
    199                         2);
     175                pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
    200176        if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
    201                 isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
    202                         1);
    203 
    204         if (pdev->activate(pdev) < 0) {
    205                 /* not fatal error */
    206                 printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n");
     177                pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
     178
     179        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     180                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     181        err = pnp_activate_dev(pdev);
     182        if (err < 0) {
     183                printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
    207184                mpu_port[dev] = -1;
    208185                acard->devmpu = NULL;
    209186        } else {
    210                 mpu_port[dev] = pdev->resource[0].start;
    211                 mpu_irq[dev] = pdev->irq_resource[0].start;
    212         }
    213 
     187                mpu_port[dev] = pnp_port_start(pdev, 0);
     188                mpu_irq[dev] = pnp_irq(pdev, 0);
     189        }
     190
     191        kfree(cfg);
    214192        return 0;
    215193}
    216194
    217 static void snd_card_ad1816a_deactivate(struct snd_card_ad1816a *acard)
    218 {
    219         if (acard->dev) {
    220                 acard->dev->deactivate(acard->dev);
    221                 acard->dev = NULL;
    222         }
    223         if (acard->devmpu) {
    224                 acard->devmpu->deactivate(acard->devmpu);
    225                 acard->devmpu = NULL;
    226         }
    227 }
    228 #endif  /* __ISAPNP__ */
    229 
    230 static void snd_card_ad1816a_free(snd_card_t *card)
    231 {
    232         struct snd_card_ad1816a *acard = (struct snd_card_ad1816a *)card->private_data;
    233 
    234         if (acard) {
    235 #ifdef __ISAPNP__
    236                 snd_card_ad1816a_deactivate(acard);
    237 #endif  /* __ISAPNP__ */
    238         }
    239 }
    240 
    241 static int __init snd_card_ad1816a_probe(int dev)
     195static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
     196                                            const struct pnp_card_device_id *pid)
    242197{
    243198        int error;
     
    251206                return -ENOMEM;
    252207        acard = (struct snd_card_ad1816a *)card->private_data;
    253         card->private_free = snd_card_ad1816a_free;
    254 
    255 #ifdef __ISAPNP__
    256         if ((error = snd_card_ad1816a_isapnp(dev, acard))) {
    257                 snd_card_free(card);
    258                 return error;
    259         }
    260 #else
    261         printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
    262         return -ENOSYS;
    263 #endif  /* __ISAPNP__ */
     208
     209        if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
     210                snd_card_free(card);
     211                return error;
     212        }
    264213
    265214        if ((error = snd_ad1816a_create(card, port[dev],
     
    315264                return error;
    316265        }
    317         snd_ad1816a_cards[dev] = card;
     266        pnp_set_card_drvdata(pcard, card);
    318267        return 0;
    319268}
    320269
    321 #ifdef __ISAPNP__
    322 static int __init snd_ad1816a_isapnp_detect(struct isapnp_card *card,
    323                                             const struct isapnp_card_id *id)
     270static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
     271                                            const struct pnp_card_device_id *id)
    324272{
    325273        static int dev;
     
    329277                if (!enable[dev])
    330278                        continue;
    331                 snd_ad1816a_isapnp_cards[dev] = card;
    332                 snd_ad1816a_isapnp_id[dev] = id;
    333                 res = snd_card_ad1816a_probe(dev);
     279                res = snd_card_ad1816a_probe(dev, card, id);
    334280                if (res < 0)
    335281                        return res;
     
    339285        return -ENODEV;
    340286}
    341 #endif
     287
     288static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
     289{
     290        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     291
     292        snd_card_disconnect(card);
     293        snd_card_free_in_thread(card);
     294}
     295
     296static struct pnp_card_driver ad1816a_pnpc_driver = {
     297        .flags          = PNP_DRIVER_RES_DISABLE,
     298        .name           = "ad1816a",
     299        .id_table       = snd_ad1816a_pnpids,
     300        .probe          = snd_ad1816a_pnp_detect,
     301        .remove         = __devexit_p(snd_ad1816a_pnp_remove),
     302};
    342303
    343304static int __init alsa_card_ad1816a_init(void)
     
    345306        int cards = 0;
    346307
    347 #ifdef __ISAPNP__
    348         cards += isapnp_probe_cards(snd_ad1816a_pnpids, snd_ad1816a_isapnp_detect);
    349 #else
    350         printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
    351 #endif
     308        cards += pnp_register_card_driver(&ad1816a_pnpc_driver);
    352309#ifdef MODULE
    353         if (!cards)
     310        if (!cards) {
     311                pnp_unregister_card_driver(&ad1816a_pnpc_driver);
    354312                printk(KERN_ERR "no AD1816A based soundcards found.\n");
     313        }
    355314#endif  /* MODULE */
    356315        return cards ? 0 : -ENODEV;
     
    359318static void __exit alsa_card_ad1816a_exit(void)
    360319{
    361         int dev;
    362 
    363         for (dev = 0; dev < SNDRV_CARDS; dev++)
    364                 snd_card_free(snd_ad1816a_cards[dev]);
     320        pnp_unregister_card_driver(&ad1816a_pnpc_driver);
    365321}
    366322
  • GPL/branches/alsa-resync1/alsa-kernel/isa/ad1816a/ad1816a_lib.c

    r210 r246  
    310310
    311311
    312 static void snd_ad1816a_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    313 {
    314         ad1816a_t *chip = snd_magic_cast(ad1816a_t, dev_id, return);
     312static irqreturn_t snd_ad1816a_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     313{
     314        ad1816a_t *chip = snd_magic_cast(ad1816a_t, dev_id, return IRQ_NONE);
    315315        unsigned char status;
    316316
     
    331331        snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
    332332        spin_unlock(&chip->lock);
     333        return IRQ_HANDLED;
    333334}
    334335
  • GPL/branches/alsa-resync1/alsa-kernel/isa/ad1848/ad1848_lib.c

    r224 r246  
    586586}
    587587
    588 void snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    589 {
    590         ad1848_t *chip = snd_magic_cast(ad1848_t, dev_id, return);
     588irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     589{
     590        ad1848_t *chip = snd_magic_cast(ad1848_t, dev_id, return IRQ_NONE);
    591591
    592592        if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
     
    597597                snd_pcm_period_elapsed(chip->capture_substream);
    598598        outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
     599        return IRQ_HANDLED;
    599600}
    600601
  • GPL/branches/alsa-resync1/alsa-kernel/isa/als100.c

    r224 r246  
    2525#include <linux/wait.h>
    2626#include <linux/time.h>
    27 #ifndef LINUX_ISAPNP_H
    28 #include <linux/isapnp.h>
    29 #define isapnp_card pci_bus
    30 #define isapnp_dev pci_dev
    31 #endif
     27#include <linux/pnp.h>
    3228#include <sound/core.h>
    3329#define SNDRV_GET_ID
     
    9793
    9894struct snd_card_als100 {
    99 #ifdef __ISAPNP__
    100         struct isapnp_dev *dev;
    101         struct isapnp_dev *devmpu;
    102         struct isapnp_dev *devopl;
    103 #endif  /* __ISAPNP__ */
     95        int dev_no;
     96        struct pnp_dev *dev;
     97        struct pnp_dev *devmpu;
     98        struct pnp_dev *devopl;
    10499};
    105100
    106 static snd_card_t *snd_als100_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    107 
    108 #ifdef __ISAPNP__
    109 static struct isapnp_card *snd_als100_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    110 static const struct isapnp_card_id *snd_als100_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    111 
    112 #define ISAPNP_ALS100(_va, _vb, _vc, _device, _audio, _mpu401, _opl) \
    113         { \
    114                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    115                 .devs = { ISAPNP_DEVICE_ID('@', '@', '@', _audio), \
    116                          ISAPNP_DEVICE_ID('@', 'X', '@', _mpu401), \
    117                          ISAPNP_DEVICE_ID('@', 'H', '@', _opl) } \
    118         }
    119 
    120 static struct isapnp_card_id snd_als100_pnpids[] __devinitdata = {
     101static struct pnp_card_device_id snd_als100_pnpids[] __devinitdata = {
    121102        /* ALS100 - PRO16PNP */
    122         ISAPNP_ALS100('A','L','S',0x0001,0x0001,0x0001,0x0001),
     103        { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
    123104        /* ALS110 - MF1000 - Digimate 3D Sound */
    124         ISAPNP_ALS100('A','L','S',0x0110,0x1001,0x1001,0x1001),
     105        { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
    125106        /* ALS120 */
    126         ISAPNP_ALS100('A','L','S',0x0120,0x2001,0x2001,0x2001),
     107        { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
    127108        /* ALS200 */
    128         ISAPNP_ALS100('A','L','S',0x0200,0x0020,0x0020,0x0001),
     109        { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
    129110        /* RTL3000 */
    130         ISAPNP_ALS100('R','T','L',0x3000,0x2001,0x2001,0x2001),
    131         { ISAPNP_CARD_END, }
     111        { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
     112        { .id = "", } /* end */
    132113};
    133114
    134 ISAPNP_CARD_TABLE(snd_als100_pnpids);
    135 
    136 #endif  /* __ISAPNP__ */
     115MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
    137116
    138117#define DRIVER_NAME     "snd-card-als100"
    139118
    140 
    141 #ifdef __ISAPNP__
    142 static int __init snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard)
    143 {
    144         const struct isapnp_card_id *id = snd_als100_isapnp_id[dev];
    145         struct isapnp_card *card = snd_als100_isapnp_cards[dev];
    146         struct isapnp_dev *pdev;
    147 
    148         acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    149         if (acard->dev->active) {
    150                 acard->dev = NULL;
    151                 return -EBUSY;
    152         }
    153         acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    154         if (acard->devmpu->active) {
    155                 acard->dev = acard->devmpu = NULL;
    156                 return -EBUSY;
    157         }
    158         acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
    159         if (acard->devopl->active) {
    160                 acard->dev = acard->devmpu = acard->devopl = NULL;
    161                 return -EBUSY;
    162         }
     119static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
     120                                         struct pnp_card_link *card,
     121                                         const struct pnp_card_device_id *id)
     122{
     123        struct pnp_dev *pdev;
     124        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
     125        int err;
     126
     127        if (!cfg)
     128                return -ENOMEM;
     129        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     130        if (acard->dev == NULL) {
     131                kfree(cfg);
     132                return -ENODEV;
     133        }
     134        acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
     135        acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->devmpu);
    163136
    164137        pdev = acard->dev;
    165         if (pdev->prepare(pdev)<0)
    166                 return -EAGAIN;
    167 
     138
     139        pnp_init_resource_table(cfg);
     140
     141        /* override resources */
    168142        if (port[dev] != SNDRV_AUTO_PORT)
    169                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     143                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    170144        if (dma8[dev] != SNDRV_AUTO_DMA)
    171                 isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
    172                         1);
     145                pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
    173146        if (dma16[dev] != SNDRV_AUTO_DMA)
    174                 isapnp_resource_change(&pdev->dma_resource[1], dma16[dev],
    175                         1);
     147                pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
    176148        if (irq[dev] != SNDRV_AUTO_IRQ)
    177                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    178 
    179         if (pdev->activate(pdev)<0) {
    180                 printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
    181                 return -EBUSY;
    182         }
    183 
    184         port[dev] = pdev->resource[0].start;
    185         dma8[dev] = pdev->dma_resource[1].start;
    186         dma16[dev] = pdev->dma_resource[0].start;
    187         irq[dev] = pdev->irq_resource[0].start;
     149                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     150        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     151                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     152        err = pnp_activate_dev(pdev);
     153        if (err < 0) {
     154                snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
     155                kfree(cfg);
     156                return err;
     157        }
     158        port[dev] = pnp_port_start(pdev, 0);
     159        dma8[dev] = pnp_dma(pdev, 1);
     160        dma16[dev] = pnp_dma(pdev, 0);
     161        irq[dev] = pnp_irq(pdev, 0);
    188162
    189163        pdev = acard->devmpu;
    190         if (pdev == NULL || pdev->prepare(pdev)<0) {
    191                 mpu_port[dev] = -1;
    192                 return 0;
    193         }
    194 
     164        if (pdev != NULL) {
     165                pnp_init_resource_table(cfg);
    195166        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    196                 isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
    197                         2);
     167                        pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
    198168        if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
    199                 isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
    200                         1);
    201 
    202         if (pdev->activate(pdev)<0) {
    203                 printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n");
    204                 mpu_port[dev] = -1;
    205                 acard->devmpu = NULL;
     169                        pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
     170                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     171                        snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
     172                err = pnp_activate_dev(pdev);
     173                if (err < 0)
     174                        goto __mpu_error;
     175                mpu_port[dev] = pnp_port_start(pdev, 0);
     176                mpu_irq[dev] = pnp_irq(pdev, 0);
    206177        } else {
    207                 mpu_port[dev] = pdev->resource[0].start;
    208                 mpu_irq[dev] = pdev->irq_resource[0].start;
     178             __mpu_error:
     179                if (pdev) {
     180                        pnp_release_card_device(pdev);
     181                        snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
     182                }
     183                acard->devmpu = NULL;
     184                mpu_port[dev] = -1;
    209185        }
    210186
    211187        pdev = acard->devopl;
    212         if (pdev == NULL || pdev->prepare(pdev)<0) {
    213                 fm_port[dev] = -1;
    214                 return 0;
    215         }
    216 
    217         if (fm_port[dev] != SNDRV_AUTO_PORT)
    218                 isapnp_resource_change(&pdev->resource[0], fm_port[dev], 4);
    219 
    220         if (pdev->activate(pdev)<0) {
    221                 printk(KERN_ERR PFX "OPL isapnp configure failure\n");
    222                 fm_port[dev] = -1;
     188        if (pdev != NULL) {
     189                pnp_init_resource_table(cfg);
     190                if (fm_port[dev] != SNDRV_AUTO_PORT)
     191                        pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
     192                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     193                        snd_printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
     194                err = pnp_activate_dev(pdev);
     195                if (err < 0)
     196                        goto __fm_error;
     197                fm_port[dev] = pnp_port_start(pdev, 0);
     198        } else {
     199              __fm_error:
     200                if (pdev) {
     201                        pnp_release_card_device(pdev);
     202                        snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
     203                }
    223204                acard->devopl = NULL;
    224         } else {
    225                 fm_port[dev] = pdev->resource[0].start;
    226         }
    227 
     205                fm_port[dev] = -1;
     206        }
     207
     208        kfree(cfg);
    228209        return 0;
    229210}
    230211
    231 static void snd_card_als100_deactivate(struct snd_card_als100 *acard)
    232 {
    233         if (acard->dev) {
    234                 acard->dev->deactivate(acard->dev);
    235                 acard->dev = NULL;
    236         }
    237         if (acard->devmpu) {
    238                 acard->devmpu->deactivate(acard->devmpu);
    239                 acard->devmpu = NULL;
    240         }
    241         if (acard->devopl) {
    242                 acard->devopl->deactivate(acard->devopl);
    243                 acard->devopl = NULL;
    244         }
    245 }
    246 #endif  /* __ISAPNP__ */
    247 
    248 static void snd_card_als100_free(snd_card_t *card)
    249 {
    250         struct snd_card_als100 *acard = (struct snd_card_als100 *)card->private_data;
    251 
    252         if (acard) {
    253 #ifdef __ISAPNP__
    254                 snd_card_als100_deactivate(acard);
    255 #endif  /* __ISAPNP__ */
    256         }
    257 }
    258 
    259 static int __init snd_card_als100_probe(int dev)
     212static int __init snd_card_als100_probe(int dev,
     213                                        struct pnp_card_link *pcard,
     214                                        const struct pnp_card_device_id *pid)
    260215{
    261216        int error;
     
    269224                return -ENOMEM;
    270225        acard = (struct snd_card_als100 *)card->private_data;
    271         card->private_free = snd_card_als100_free;
    272 
    273 #ifdef __ISAPNP__
    274         if ((error = snd_card_als100_isapnp(dev, acard))) {
    275                 snd_card_free(card);
    276                 return error;
    277         }
    278 #else
    279         printk(KERN_ERR PFX "you have to enable PnP support ...\n");
    280         snd_card_free(card);
    281         return -ENOSYS;
    282 #endif  /* __ISAPNP__ */
     226
     227        if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
     228                snd_card_free(card);
     229                return error;
     230        }
    283231
    284232        if ((error = snd_sbdsp_create(card, port[dev],
     
    307255                                        mpu_irq[dev], SA_INTERRUPT,
    308256                                        NULL) < 0)
    309                         printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
     257                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
    310258        }
    311259
     
    314262                                    fm_port[dev], fm_port[dev] + 2,
    315263                                    OPL3_HW_AUTO, 0, &opl3) < 0) {
    316                         printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
     264                        snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
    317265                                fm_port[dev], fm_port[dev] + 2);
    318266                } else {
     
    337285                return error;
    338286        }
    339         snd_als100_cards[dev] = card;
     287        pnp_set_card_drvdata(pcard, card);
    340288        return 0;
    341289}
    342290
    343 #ifdef __ISAPNP__
    344 static int __init snd_als100_isapnp_detect(struct isapnp_card *card,
    345                                            const struct isapnp_card_id *id)
     291static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
     292                                           const struct pnp_card_device_id *id)
    346293{
    347294        static int dev;
     
    351298                if (!enable[dev])
    352299                        continue;
    353                 snd_als100_isapnp_cards[dev] = card;
    354                 snd_als100_isapnp_id[dev] = id;
    355                 res = snd_card_als100_probe(dev);
     300                res = snd_card_als100_probe(dev, card, id);
    356301                if (res < 0)
    357302                        return res;
     
    361306        return -ENODEV;
    362307}
    363 #endif
     308
     309static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
     310{
     311        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     312
     313        snd_card_disconnect(card);
     314        snd_card_free_in_thread(card);
     315}
     316
     317static struct pnp_card_driver als100_pnpc_driver = {
     318        .flags          = PNP_DRIVER_RES_DISABLE,
     319        .name           = "als100",
     320        .id_table       = snd_als100_pnpids,
     321        .probe          = snd_als100_pnp_detect,
     322        .remove         = __devexit_p(snd_als100_pnp_remove),
     323};
    364324
    365325static int __init alsa_card_als100_init(void)
     
    367327        int cards = 0;
    368328
    369 #ifdef __ISAPNP__
    370         cards += isapnp_probe_cards(snd_als100_pnpids, snd_als100_isapnp_detect);
    371 #else
    372         printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
    373 #endif
     329        cards += pnp_register_card_driver(&als100_pnpc_driver);
    374330#ifdef MODULE
    375         if (!cards)
    376                 printk(KERN_ERR "no ALS100 based soundcards found\n");
     331        if (!cards) {
     332                pnp_unregister_card_driver(&als100_pnpc_driver);
     333                snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
     334        }
    377335#endif
    378336        return cards ? 0 : -ENODEV;
     
    381339static void __exit alsa_card_als100_exit(void)
    382340{
    383         int dev;
    384 
    385         for (dev = 0; dev < SNDRV_CARDS; dev++)
    386                 snd_card_free(snd_als100_cards[dev]);
     341        pnp_unregister_card_driver(&als100_pnpc_driver);
    387342}
    388343
  • GPL/branches/alsa-resync1/alsa-kernel/isa/azt2320.c

    r224 r246  
    3737#include <linux/time.h>
    3838#include <linux/wait.h>
     39#include <linux/pnp.h>
    3940#include <sound/core.h>
    4041#define SNDRV_GET_ID
     
    105106
    106107struct snd_card_azt2320 {
    107 #ifdef __ISAPNP__
    108         struct isapnp_dev *dev;
    109         struct isapnp_dev *devmpu;
    110 #endif  /* __ISAPNP__ */
     108#ifdef CONFIG_PNP
     109        int dev_no;
     110        struct pnp_dev *dev;
     111        struct pnp_dev *devmpu;
     112#endif  /* CONFIG_PNP */
    111113};
    112114
    113 static snd_card_t *snd_azt2320_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    114 
    115 #ifdef __ISAPNP__
    116 
    117 static struct isapnp_card *snd_azt2320_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    118 static const struct isapnp_card_id *snd_azt2320_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    119 
    120 #define ISAPNP_AZT2320(_va, _vb, _vc, _device, _audio, _mpu401) \
    121         { \
    122                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    123                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
    124                          ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401), } \
    125         }
    126 
    127 static struct isapnp_card_id snd_azt2320_pnpids[] __devinitdata = {
     115static struct pnp_card_device_id snd_azt2320_pnpids[] __devinitdata = {
    128116        /* PRO16V */
    129         ISAPNP_AZT2320('A','Z','T',0x1008,0x1008,0x2001),
     117        { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
    130118        /* Aztech Sound Galaxy 16 */
    131         ISAPNP_AZT2320('A','Z','T',0x2320,0x0001,0x0002),
     119        { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
    132120        /* Packard Bell Sound III 336 AM/SP */
    133         ISAPNP_AZT2320('A','Z','T',0x3000,0x1003,0x2001),
     121        { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
    134122        /* AT3300 */
    135         ISAPNP_AZT2320('A','Z','T',0x3002,0x1004,0x2001),
     123        { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
    136124        /* --- */
    137         ISAPNP_AZT2320('A','Z','T',0x3005,0x1003,0x2001),
     125        { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
    138126        /* --- */
    139         ISAPNP_AZT2320('A','Z','T',0x3011,0x1003,0x2001),
    140         { ISAPNP_CARD_END, }    /* end */
     127        { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
     128        { .id = "" }    /* end */
    141129};
    142130
    143 ISAPNP_CARD_TABLE(snd_azt2320_pnpids);
    144 
    145 #endif  /* __ISAPNP__ */
     131MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
    146132
    147133#define DRIVER_NAME     "snd-card-azt2320"
    148134
    149 
    150 #ifdef __ISAPNP__
    151 static int __init snd_card_azt2320_isapnp(int dev, struct snd_card_azt2320 *acard)
    152 {
    153         const struct isapnp_card_id *id = snd_azt2320_isapnp_id[dev];
    154         struct isapnp_card *card = snd_azt2320_isapnp_cards[dev];
    155         struct isapnp_dev *pdev;
    156 
    157         acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    158         if (acard->dev->active) {
    159                 acard->dev = NULL;
    160                 return -EBUSY;
    161         }
    162         acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    163         if (acard->devmpu->active) {
    164                 acard->dev = acard->devmpu = NULL;
    165                 return -EBUSY;
    166         }
     135static int __devinit snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
     136                                          struct pnp_card_link *card,
     137                                          const struct pnp_card_device_id *id)
     138{
     139        struct pnp_dev *pdev;
     140        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     141        int err;
     142
     143        if (!cfg)
     144                return -ENOMEM;
     145
     146        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     147        if (acard->dev == NULL) {
     148                kfree(cfg);
     149                return -ENODEV;
     150        }
     151
     152        acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
    167153
    168154        pdev = acard->dev;
    169         if (pdev->prepare(pdev) < 0)
    170                 return -EAGAIN;
    171 
     155        pnp_init_resource_table(cfg);
     156
     157        /* override resources */
    172158        if (port[dev] != SNDRV_AUTO_PORT)
    173                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     159                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    174160        if (fm_port[dev] != SNDRV_AUTO_PORT)
    175                 isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4);
     161                pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
    176162        if (wss_port[dev] != SNDRV_AUTO_PORT)
    177                 isapnp_resource_change(&pdev->resource[2], wss_port[dev],
    178                         4);
     163                pnp_resource_change(&cfg->port_resource[2], wss_port[dev], 4);
    179164        if (dma1[dev] != SNDRV_AUTO_DMA)
    180                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev],
    181                         1);
     165                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    182166        if (dma2[dev] != SNDRV_AUTO_DMA)
    183                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev],
    184                         1);
     167                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    185168        if (irq[dev] != SNDRV_AUTO_IRQ)
    186                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    187 
    188         if (pdev->activate(pdev) < 0) {
    189                 printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
    190                 return -EBUSY;
    191         }
    192 
    193         port[dev] = pdev->resource[0].start;
    194         fm_port[dev] = pdev->resource[1].start;
    195         wss_port[dev] = pdev->resource[2].start;
    196         dma1[dev] = pdev->dma_resource[0].start;
    197         dma2[dev] = pdev->dma_resource[1].start;
    198         irq[dev] = pdev->irq_resource[0].start;
     169                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     170        if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     171                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     172
     173        err = pnp_activate_dev(pdev);
     174        if (err < 0) {
     175                snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
     176                kfree(cfg);
     177                return err;
     178        }
     179        port[dev] = pnp_port_start(pdev, 0);
     180        fm_port[dev] = pnp_port_start(pdev, 1);
     181        wss_port[dev] = pnp_port_start(pdev, 2);
     182        dma1[dev] = pnp_dma(pdev, 0);
     183        dma2[dev] = pnp_dma(pdev, 1);
     184        irq[dev] = pnp_irq(pdev, 0);
    199185
    200186        pdev = acard->devmpu;
    201         if (pdev == NULL || pdev->prepare(pdev) < 0) {
    202                 mpu_port[dev] = -1;
    203                 return 0;
    204         }
    205 
     187        if (pdev != NULL) {
     188                pnp_init_resource_table(cfg);
    206189        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    207                 isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
    208                         2);
     190                        pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
    209191        if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
    210                 isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
    211                         1);
    212 
    213         if (pdev->activate(pdev) < 0) {
    214                 /* not fatal error */
    215                 printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n");
    216                 mpu_port[dev] = -1;
    217                 acard->devmpu = NULL;
     192                        pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
     193                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     194                        snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
     195                err = pnp_activate_dev(pdev);
     196                if (err < 0)
     197                        goto __mpu_error;
     198                mpu_port[dev] = pnp_port_start(pdev, 0);
     199                mpu_irq[dev] = pnp_irq(pdev, 0);
    218200        } else {
    219                 mpu_port[dev] = pdev->resource[0].start;
    220                 mpu_irq[dev] = pdev->irq_resource[0].start;
    221         }
    222 
     201             __mpu_error:
     202                if (pdev) {
     203                        pnp_release_card_device(pdev);
     204                        snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
     205                }
     206                acard->devmpu = NULL;
     207                mpu_port[dev] = -1;
     208        }
     209
     210        kfree (cfg);
    223211        return 0;
    224212}
    225213
    226 static void snd_card_azt2320_deactivate(struct snd_card_azt2320 *acard)
    227 {
    228         if (acard->dev)
    229                 acard->dev->deactivate(acard->dev);
    230         if (acard->devmpu)
    231                 acard->devmpu->deactivate(acard->devmpu);
    232 }
    233 #endif  /* __ISAPNP__ */
    234 
    235214/* same of snd_sbdsp_command by Jaroslav Kysela */
    236 static int __init snd_card_azt2320_command(unsigned long port, unsigned char val)
     215static int __devinit snd_card_azt2320_command(unsigned long port, unsigned char val)
    237216{
    238217        int i;
     
    240219
    241220        limit = jiffies + HZ / 10;
    242         for (i = 50000; i && (limit - jiffies) > 0; i--)
     221        for (i = 50000; i && time_after(limit, jiffies); i--)
    243222                if (!(inb(port + 0x0c) & 0x80)) {
    244223                        outb(val, port + 0x0c);
     
    248227}
    249228
    250 static int __init snd_card_azt2320_enable_wss(unsigned long port)
     229static int __devinit snd_card_azt2320_enable_wss(unsigned long port)
    251230{
    252231        int error;
     
    261240}
    262241
    263 static void snd_card_azt2320_free(snd_card_t *card)
    264 {
    265         struct snd_card_azt2320 *acard = (struct snd_card_azt2320 *)card->private_data;
    266 
    267         if (acard) {
    268 #ifdef __ISAPNP__
    269                 snd_card_azt2320_deactivate(acard);
    270 #endif  /* __ISAPNP__ */
    271         }
    272 }
    273 
    274 static int __init snd_card_azt2320_probe(int dev)
     242static int __devinit snd_card_azt2320_probe(int dev,
     243                                            struct pnp_card_link *pcard,
     244                                            const struct pnp_card_device_id *pid)
    275245{
    276246        int error;
     
    284254                return -ENOMEM;
    285255        acard = (struct snd_card_azt2320 *)card->private_data;
    286         card->private_free = snd_card_azt2320_free;
    287 
    288 #ifdef __ISAPNP__
    289         if ((error = snd_card_azt2320_isapnp(dev, acard))) {
    290                 snd_card_free(card);
    291                 return error;
    292         }
    293 #endif  /* __ISAPNP__ */
     256
     257        if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
     258                snd_card_free(card);
     259                return error;
     260        }
    294261
    295262        if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
     
    325292                                mpu_irq[dev], SA_INTERRUPT,
    326293                                NULL) < 0)
    327                         printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n",
    328                                 mpu_port[dev]);
     294                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
    329295        }
    330296
     
    333299                                    fm_port[dev], fm_port[dev] + 2,
    334300                                    OPL3_HW_AUTO, 0, &opl3) < 0) {
    335                         printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
     301                        snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
    336302                                fm_port[dev], fm_port[dev] + 2);
    337303                } else {
     
    356322                return error;
    357323        }
    358         snd_azt2320_cards[dev] = card;
     324        pnp_set_card_drvdata(pcard, card);
    359325        return 0;
    360326}
    361327
    362 #ifdef __ISAPNP__
    363 static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card,
    364                                             const struct isapnp_card_id *id)
     328static int __devinit snd_azt2320_pnp_detect(struct pnp_card_link *card,
     329                                            const struct pnp_card_device_id *id)
    365330{
    366331        static int dev;
     
    370335                if (!enable[dev])
    371336                        continue;
    372                 snd_azt2320_isapnp_cards[dev] = card;
    373                 snd_azt2320_isapnp_id[dev] = id;
    374                 res = snd_card_azt2320_probe(dev);
     337                res = snd_card_azt2320_probe(dev, card, id);
    375338                if (res < 0)
    376339                        return res;
     
    380343        return -ENODEV;
    381344}
    382 #endif
     345
     346static void __devexit snd_azt2320_pnp_remove(struct pnp_card_link * pcard)
     347{
     348        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     349
     350        snd_card_disconnect(card);
     351        snd_card_free_in_thread(card);
     352}
     353
     354static struct pnp_card_driver azt2320_pnpc_driver = {
     355        .flags          = PNP_DRIVER_RES_DISABLE,
     356        .name           = "azt2320",
     357        .id_table       = snd_azt2320_pnpids,
     358        .probe          = snd_azt2320_pnp_detect,
     359        .remove         = __devexit_p(snd_azt2320_pnp_remove),
     360};
    383361
    384362static int __init alsa_card_azt2320_init(void)
     
    386364        int cards = 0;
    387365
    388 #ifdef __ISAPNP__
    389         cards += isapnp_probe_cards(snd_azt2320_pnpids, snd_azt2320_isapnp_detect);
    390 #else
    391         printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
    392 #endif
     366        cards += pnp_register_card_driver(&azt2320_pnpc_driver);
    393367#ifdef MODULE
    394         if (!cards)
    395                 printk(KERN_ERR "no AZT2320 based soundcards found\n");
     368        if (!cards) {
     369                pnp_unregister_card_driver(&azt2320_pnpc_driver);
     370                snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
     371        }
    396372#endif
    397373        return cards ? 0 : -ENODEV;
     
    400376static void __exit alsa_card_azt2320_exit(void)
    401377{
    402         int dev;
    403 
    404         for (dev = 0; dev < SNDRV_CARDS; dev++)
    405                 snd_card_free(snd_azt2320_cards[dev]);
     378        pnp_unregister_card_driver(&azt2320_pnpc_driver);
    406379}
    407380
  • GPL/branches/alsa-resync1/alsa-kernel/isa/cmi8330.c

    r224 r246  
    4747#include <linux/init.h>
    4848#include <linux/slab.h>
    49 #ifndef LINUX_ISAPNP_H
    50 #include <linux/isapnp.h>
    51 #define isapnp_card pci_bus
    52 #define isapnp_dev pci_dev
    53 #endif
     49#include <linux/pnp.h>
    5450#include <sound/core.h>
    5551#include <sound/ad1848.h>
     
    7470static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
    7571static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
    76 #ifdef __ISAPNP__
     72#ifdef CONFIG_PNP
    7773#ifdef TARGET_OS2
    7874static int isapnp[SNDRV_CARDS] = {REPEAT_SNDRV(1)};
     
    9894MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard.");
    9995MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    100 #ifdef __ISAPNP__
     96#ifdef CONFIG_PNP
    10197MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    102 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     98MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
    10399MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
    104100#endif
     
    161157
    162158struct snd_cmi8330 {
    163 #ifdef __ISAPNP__
    164         struct isapnp_dev *cap;
    165         struct isapnp_dev *play;
     159#ifdef CONFIG_PNP
     160        struct pnp_dev *cap;
     161        struct pnp_dev *play;
    166162#endif
    167163        snd_card_t *card;
     
    177173};
    178174
    179 static snd_card_t *snd_cmi8330_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    180 
    181 #ifdef __ISAPNP__
    182 
    183 static struct isapnp_card *snd_cmi8330_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    184 static const struct isapnp_card_id *snd_cmi8330_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    185 
    186 #define ISAPNP_CMI8330(_va, _vb, _vc, _device, _audio1, _audio2) \
    187         { \
    188                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    189                 .devs = { ISAPNP_DEVICE_ID('@', '@', '@', _audio1), \
    190                          ISAPNP_DEVICE_ID('@', 'X', '@', _audio2), } \
    191         }
    192 
    193 static struct isapnp_card_id snd_cmi8330_pnpids[] __devinitdata =
    194 {
    195         ISAPNP_CMI8330('C','M','I',0x0001,0x0001,0x0001),
    196         { ISAPNP_CARD_END, }
     175static snd_card_t *snd_cmi8330_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     176
     177#ifdef CONFIG_PNP
     178
     179static struct pnp_card_device_id snd_cmi8330_pnpids[] __devinitdata = {
     180        { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } },
     181        { .id = "" }
    197182};
    198183
    199 ISAPNP_CARD_TABLE(snd_cmi8330_pnpids);
     184MODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
    200185
    201186#endif
     
    263248
    264249
    265 static int __init cmi8330_add_sb_mixers(sb_t *chip)
     250static int __devinit cmi8330_add_sb_mixers(sb_t *chip)
    266251{
    267252        int idx, err;
     
    288273#endif
    289274
    290 static int __init snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
     275static int __devinit snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
    291276{
    292277        unsigned int idx;
     
    307292}
    308293
    309 #ifdef __ISAPNP__
    310 static int __init snd_cmi8330_isapnp(int dev, struct snd_cmi8330 *acard)
    311 {
    312         const struct isapnp_card_id *id = snd_cmi8330_isapnp_id[dev];
    313         struct isapnp_card *card = snd_cmi8330_isapnp_cards[dev];
    314         struct isapnp_dev *pdev;
    315 
    316         acard->cap = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    317         if (acard->cap->active) {
    318                 acard->cap = NULL;
     294#ifdef CONFIG_PNP
     295static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
     296                                     struct pnp_card_link *card,
     297                                     const struct pnp_card_device_id *id)
     298{
     299        struct pnp_dev *pdev;
     300        struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
     301        int err;
     302
     303        acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
     304        if (acard->cap == NULL) {
     305                kfree(cfg);
    319306                return -EBUSY;
    320307        }
    321         acard->play = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    322         if (acard->play->active) {
    323                 acard->cap = acard->play = NULL;
     308        acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
     309        if (acard->play == NULL) {
     310                kfree(cfg);
    324311                return -EBUSY;
    325312        }
    326313
    327314        pdev = acard->cap;
    328         if (pdev->prepare(pdev)<0)
    329                 return -EAGAIN;
     315        pnp_init_resource_table(cfg);
    330316        /* allocate AD1848 resources */
    331317        if (wssport[dev] != SNDRV_AUTO_PORT)
    332                 isapnp_resource_change(&pdev->resource[0], wssport[dev], 8);
     318                pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8);
    333319        if (wssdma[dev] != SNDRV_AUTO_DMA)
    334                 isapnp_resource_change(&pdev->dma_resource[0], wssdma[dev], 1);
     320                pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1);
    335321        if (wssirq[dev] != SNDRV_AUTO_IRQ)
    336                 isapnp_resource_change(&pdev->irq_resource[0], wssirq[dev], 1);
    337 
    338         if (pdev->activate(pdev)<0) {
    339                 snd_printk("(AD1848) PnP configure failure\n");
     322                pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1);
     323
     324        err = pnp_manual_config_dev(pdev, cfg, 0);
     325        if (err < 0)
     326                snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n");
     327        err = pnp_activate_dev(pdev);
     328        if (err < 0) {
     329                snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n");
     330                kfree(cfg);
    340331                return -EBUSY;
    341332        }
    342         wssport[dev] = pdev->resource[0].start;
    343         wssdma[dev] = pdev->dma_resource[0].start;
    344         wssirq[dev] = pdev->irq_resource[0].start;
     333        wssport[dev] = pnp_port_start(pdev, 0);
     334        wssdma[dev] = pnp_dma(pdev, 0);
     335        wssirq[dev] = pnp_irq(pdev, 0);
    345336
    346337        /* allocate SB16 resources */
    347338        pdev = acard->play;
    348         if (pdev->prepare(pdev)<0) {
    349                 acard->cap->deactivate(acard->cap);
    350                 return -EAGAIN;
    351         }
     339        pnp_init_resource_table(cfg);
    352340        if (sbport[dev] != SNDRV_AUTO_PORT)
    353                 isapnp_resource_change(&pdev->resource[0], sbport[dev], 16);
     341                pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16);
    354342        if (sbdma8[dev] != SNDRV_AUTO_DMA)
    355                 isapnp_resource_change(&pdev->dma_resource[0], sbdma8[dev], 1);
     343                pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1);
    356344        if (sbdma16[dev] != SNDRV_AUTO_DMA)
    357                 isapnp_resource_change(&pdev->dma_resource[1], sbdma16[dev], 1);
     345                pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1);
    358346        if (sbirq[dev] != SNDRV_AUTO_IRQ)
    359                 isapnp_resource_change(&pdev->irq_resource[0], sbirq[dev], 1);
    360 
    361         if (pdev->activate(pdev)<0) {
    362                 snd_printk("CMI8330/C3D (SB16) PnP configure failure\n");
    363                 acard->cap->deactivate(acard->cap);
     347                pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1);
     348
     349        err = pnp_manual_config_dev(pdev, cfg, 0);
     350        if (err < 0)
     351                snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n");
     352        err = pnp_activate_dev(pdev);
     353        if (err < 0) {
     354                snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n");
     355                kfree(cfg);
    364356                return -EBUSY;
    365357        }
    366         sbport[dev] = pdev->resource[0].start;
    367         sbdma8[dev] = pdev->dma_resource[0].start;
    368         sbdma16[dev] = pdev->dma_resource[1].start;
    369         sbirq[dev] = pdev->irq_resource[0].start;
    370 
     358        sbport[dev] = pnp_port_start(pdev, 0);
     359        sbdma8[dev] = pnp_dma(pdev, 0);
     360        sbdma16[dev] = pnp_dma(pdev, 1);
     361        sbirq[dev] = pnp_irq(pdev, 0);
     362
     363        kfree(cfg);
    371364        return 0;
    372 }
    373 
    374 static void snd_cmi8330_deactivate(struct snd_cmi8330 *acard)
    375 {
    376         if (acard->cap) {
    377                 acard->cap->deactivate(acard->cap);
    378                 acard->cap = NULL;
    379         }
    380         if (acard->play) {
    381                 acard->play->deactivate(acard->play);
    382                 acard->play = NULL;
    383         }
    384365}
    385366#endif
     
    429410}
    430411
    431 static int __init snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
     412static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
    432413{
    433414        snd_pcm_t *pcm;
     
    472453 */
    473454
    474 static void snd_cmi8330_free(snd_card_t *card)
    475 {
    476         struct snd_cmi8330 *acard = (struct snd_cmi8330 *)card->private_data;
    477 
    478         if (acard) {
    479 #ifdef __ISAPNP__
    480                 snd_cmi8330_deactivate(acard);
    481 #endif
    482         }
    483 }
    484 
    485 static int __init snd_cmi8330_probe(int dev)
     455static int __devinit snd_cmi8330_probe(int dev,
     456                                       struct pnp_card_link *pcard,
     457                                       const struct pnp_card_device_id *pid)
    486458{
    487459        snd_card_t *card;
     
    490462        int i, err;
    491463
    492 #ifdef __ISAPNP__
     464#ifdef CONFIG_PNP
    493465        if (!isapnp[dev]) {
    494466#endif
     
    501473                        return -EINVAL;
    502474                }
    503 #ifdef __ISAPNP__
     475#ifdef CONFIG_PNP
    504476        }
    505477#endif
     
    512484        acard = (struct snd_cmi8330 *)card->private_data;
    513485        acard->card = card;
    514         card->private_free = snd_cmi8330_free;
    515 
    516 #ifdef __ISAPNP__
    517         if (isapnp[dev] && (err = snd_cmi8330_isapnp(dev, acard)) < 0) {
     486
     487#ifdef CONFIG_PNP
     488        if (isapnp[dev] && (err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) {
    518489                snd_printk("PnP detection failed\n");
    519490                snd_card_free(card);
     
    585556        }
    586557
    587         snd_cmi8330_cards[dev] = card;
     558        if (pcard)
     559                pnp_set_card_drvdata(pcard, card);
     560        else
     561                snd_cmi8330_legacy[dev] = card;
    588562        return 0;
    589563}
    590564
    591 static void __exit alsa_card_cmi8330_exit(void)
    592 {
    593         int i;
    594 
    595         for (i = 0; i < SNDRV_CARDS; i++)
    596                 snd_card_free(snd_cmi8330_cards[i]);
    597 }
    598 
    599 #ifdef __ISAPNP__
    600 static int __init snd_cmi8330_isapnp_detect(struct isapnp_card *card,
    601                                             const struct isapnp_card_id *id)
     565#ifdef CONFIG_PNP
     566static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card,
     567                                            const struct pnp_card_device_id *id)
    602568{
    603569        static int dev;
     
    607573                if (!enable[dev] || !isapnp[dev])
    608574                        continue;
    609                 snd_cmi8330_isapnp_cards[dev] = card;
    610                 snd_cmi8330_isapnp_id[dev] = id;
    611                 res = snd_cmi8330_probe(dev);
     575                res = snd_cmi8330_probe(dev, card, id);
    612576                if (res < 0)
    613577                        return res;
     
    617581        return -ENODEV;
    618582}
    619 #endif /* __ISAPNP__ */
     583
     584static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard)
     585{
     586        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     587
     588        snd_card_disconnect(card);
     589        snd_card_free_in_thread(card);
     590}
     591
     592static struct pnp_card_driver cmi8330_pnpc_driver = {
     593        .flags = PNP_DRIVER_RES_DISABLE,
     594        .name = "cmi8330",
     595        .id_table = snd_cmi8330_pnpids,
     596        .probe = snd_cmi8330_pnp_detect,
     597        .remove = __devexit_p(snd_cmi8330_pnp_remove),
     598};
     599#endif /* CONFIG_PNP */
    620600
    621601static int __init alsa_card_cmi8330_init(void)
     
    626606                if (!enable[dev])
    627607                        continue;
    628 #ifdef __ISAPNP__
     608#ifdef CONFIG_PNP
    629609                if (isapnp[dev])
    630610                        continue;
    631611#endif
    632                 if (snd_cmi8330_probe(dev) >= 0)
     612                if (snd_cmi8330_probe(dev, NULL, NULL) >= 0)
    633613                        cards++;
    634614        }
    635 #ifdef __ISAPNP__
    636         cards += isapnp_probe_cards(snd_cmi8330_pnpids, snd_cmi8330_isapnp_detect);
     615#ifdef CONFIG_PNP
     616        cards += pnp_register_card_driver(&cmi8330_pnpc_driver);
    637617#endif
    638618
    639619        if (!cards) {
     620#ifdef CONFIG_PNP
     621                pnp_unregister_card_driver(&cmi8330_pnpc_driver);
     622#endif
    640623#ifdef MODULE
    641                 printk(KERN_ERR "CMI8330 not found or device busy\n");
     624                snd_printk(KERN_ERR "CMI8330 not found or device busy\n");
    642625#endif
    643626                return -ENODEV;
    644627        }
    645628        return 0;
     629}
     630
     631static void __exit alsa_card_cmi8330_exit(void)
     632{
     633        int i;
     634
     635#ifdef CONFIG_PNP
     636        /* PnP cards first */
     637        pnp_unregister_card_driver(&cmi8330_pnpc_driver);
     638#endif
     639        for (i = 0; i < SNDRV_CARDS; i++)
     640                snd_card_free(snd_cmi8330_legacy[i]);
    646641}
    647642
     
    675670               get_option(&str,&wssirq[nr_dev]) == 2 &&
    676671               get_option(&str,&wssdma[nr_dev]) == 2);
    677 #ifdef __ISAPNP__
     672#ifdef CONFIG_PNP
    678673        if (pnp != INT_MAX)
    679674                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/cs423x/cs4231_lib.c

    r224 r246  
    449449        int result = 0;
    450450        unsigned int what;
     451        struct list_head *pos;
    451452        snd_pcm_substream_t *s;
    452453        int do_start;
     
    468469
    469470        what = 0;
    470         s = substream;
    471                 do {
     471        snd_pcm_group_for_each(pos, substream) {
     472                s = snd_pcm_group_substream_entry(pos);
    472473                        if (s == chip->playback_substream) {
    473474                                what |= CS4231_PLAYBACK_ENABLE;
     
    477478                                snd_pcm_trigger_done(s, substream);
    478479                        }
    479                         s = s->link_next;
    480                 } while (s != substream);
     480        }
    481481                spin_lock(&chip->reg_lock);
    482482        if (do_start) {
     
    968968}
    969969
    970 void snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    971 {
    972         cs4231_t *chip = snd_magic_cast(cs4231_t, dev_id, return);
     970irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     971{
     972        cs4231_t *chip = snd_magic_cast(cs4231_t, dev_id, return IRQ_NONE);
    973973        unsigned char status;
    974974
     
    999999        snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
    10001000        spin_unlock(&chip->reg_lock);
     1001        return IRQ_HANDLED;
    10011002}
    10021003
  • GPL/branches/alsa-resync1/alsa-kernel/isa/cs423x/cs4236.c

    r224 r246  
    2323#include <linux/init.h>
    2424#include <linux/slab.h>
    25 #ifndef LINUX_ISAPNP_H
    26 #include <linux/isapnp.h>
    27 #define isapnp_card pci_bus
    28 #define isapnp_dev pci_dev
    29 #endif
     25#include <linux/pnp.h>
    3026#include <sound/core.h>
    3127#include <sound/cs4231.h>
     
    8884static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    8985static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
    90 #ifdef __ISAPNP__
     86#ifdef CONFIG_PNP
    9187#ifdef TARGET_OS2
    9288static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    114110MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
    115111MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    116 #ifdef __ISAPNP__
     112#ifdef CONFIG_PNP
    117113MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    118114MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     
    149145struct snd_card_cs4236 {
    150146        struct resource *res_sb_port;
    151 #ifdef __ISAPNP__
    152         struct isapnp_dev *wss;
    153         struct isapnp_dev *ctrl;
    154         struct isapnp_dev *mpu;
     147#ifdef CONFIG_PNP
     148        struct pnp_dev *wss;
     149        struct pnp_dev *ctrl;
     150        struct pnp_dev *mpu;
    155151#endif
    156152};
    157153
    158 static snd_card_t *snd_cs4236_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    159 
    160 #ifdef __ISAPNP__
    161 
    162 static struct isapnp_card *snd_cs4236_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    163 static const struct isapnp_card_id *snd_cs4236_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
     154static snd_card_t *snd_cs4236_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     155
     156#ifdef CONFIG_PNP
    164157
    165158#ifdef TARGET_OS2
     
    209202
    210203#ifdef CS4232
    211 static struct isapnp_card_id snd_card_pnpids[] __devinitdata = {
     204static struct pnp_card_device_id snd_cs423x_pnpids[] __devinitdata = {
    212205        /* Philips PCA70PS */
    213         ISAPNP_CS4232_1('C','S','C',0x0d32,0x0000,0x0010,0xb006),
     206        { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
    214207        /* TerraTec Maestro 32/96 (CS4232) */
    215         ISAPNP_CS4232('C','S','C',0x1a32,0x0000,0x0010,0x0003),
     208        { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    216209        /* HP Omnibook 5500 onboard */
    217         ISAPNP_CS4232('C','S','C',0x4232,0x0000,0x0002,0x0003),
     210        { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
    218211        /* Unnamed CS4236 card (Made in Taiwan) */
    219         ISAPNP_CS4232('C','S','C',0x4236,0x0000,0x0010,0x0003),
     212        { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    220213        /* Turtle Beach TBS-2000 (CS4232) */
    221         ISAPNP_CS4232('C','S','C',0x7532,0x0000,0x0010,0xb006),
     214        { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
    222215        /* Turtle Beach Tropez Plus (CS4232) */
    223         ISAPNP_CS4232_1('C','S','C',0x7632,0x0000,0x0010,0xb006),
     216        { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
    224217        /* SIC CrystalWave 32 (CS4232) */
    225         ISAPNP_CS4232('C','S','C',0xf032,0x0000,0x0010,0x0003),
     218        { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    226219        /* --- */
    227         { ISAPNP_CARD_END, }    /* end */
     220        { .id = "" }    /* end */
    228221};
    229222#else /* CS4236 */
    230 static struct isapnp_card_id snd_card_pnpids[] __devinitdata = {
     223static struct pnp_card_device_id snd_cs423x_pnpids[] __devinitdata = {
    231224        /* Intel Marlin Spike Motherboard - CS4235 */
    232         ISAPNP_CS4232('C','S','C',0x0225,0x0000,0x0010,0x0003),
     225        { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    233226        /* Intel Marlin Spike Motherboard (#2) - CS4235 */
    234         ISAPNP_CS4232('C','S','C',0x0225,0x0100,0x0110,0x0103),
     227        { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
    235228        /* Genius Sound Maker 3DJ - CS4237B */
    236         ISAPNP_CS4232('C','S','C',0x0437,0x0000,0x0010,0x0003),
     229        { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    237230        /* Digital PC 5000 Onboard - CS4236B */
    238         ISAPNP_CS4232_WOMPU('C','S','C',0x0735,0x0000,0x0010),
     231        { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
    239232        /* some uknown CS4236B */
    240         ISAPNP_CS4232('C','S','C',0x0b35,0x0000,0x0010,0x0003),
     233        { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    241234        /* Intel PR440FX Onboard sound */
    242         ISAPNP_CS4232('C','S','C',0x0b36,0x0000,0x0010,0x0003),
     235        { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    243236        /* CS4235 on mainboard without MPU */
    244         ISAPNP_CS4232_WOMPU('C','S','C',0x1425,0x0100,0x0110),
     237        { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
    245238        /* Gateway E1000 Onboard CS4236B */
    246         ISAPNP_CS4232('C','S','C',0x1335,0x0000,0x0010,0x0003),
     239        { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    247240        /* HP 6330 Onboard sound */
    248         ISAPNP_CS4232('C','S','C',0x1525,0x0100,0x0110,0x0103),
     241        { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
    249242        /* Crystal Computer TidalWave128 */
    250         ISAPNP_CS4232('C','S','C',0x1e37,0x0000,0x0010,0x0003),
     243        { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    251244        /* ACER AW37 - CS4235 */
    252         ISAPNP_CS4232('C','S','C',0x4236,0x0000,0x0010,0x0003),
     245        { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    253246        /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
    254         ISAPNP_CS4232('C','S','C',0x4237,0x0000,0x0010,0x0003),
     247        { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    255248        /* Crystal 3D - CS4237B */
    256         ISAPNP_CS4232('C','S','C',0x4336,0x0000,0x0010,0x0003),
     249        { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    257250        /* Typhoon Soundsystem PnP - CS4236B */
    258         ISAPNP_CS4232('C','S','C',0x4536,0x0000,0x0010,0x0003),
     251        { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    259252        /* Crystal CX4235-XQ3 EP - CS4235 */
    260         ISAPNP_CS4232('C','S','C',0x4625,0x0100,0x0110,0x0103),
     253        { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
     254        /* Crystal Semiconductors CS4237B */
     255        { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     256        /* NewClear 3D - CX4237B-XQ3 */
     257        { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     258        /* Dell Optiplex GX1 - CS4236B */
     259        { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     260        /* Dell P410 motherboard - CS4236B */
     261        { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
     262        /* Dell Workstation 400 Onboard - CS4236B */
     263        { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     264        /* Turtle Beach Malibu - CS4237B */
     265        { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     266        /* CS4235 - onboard */
     267        { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
     268        /* IBM Aptiva 2137 E24 Onboard - CS4237B */
     269        { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     270        /* IBM IntelliStation M Pro motherboard */
     271        { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
     272        /* Guillemot MaxiSound 16 PnP - CS4236B */
     273        { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     274        /* Gallant SC-70P */
     275        { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    261276        /* TerraTec AudioSystem EWS64XL - CS4236B */
    262         ISAPNP_CS4232('C','S','C',0xa836,0xa800,0xa810,0xa803),
     277        { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
    263278        /* TerraTec AudioSystem EWS64XL - CS4236B */
    264         ISAPNP_CS4232_WOMPU('C','S','C',0xa836,0xa800,0xa810),
    265         /* Crystal Semiconductors CS4237B */
    266         ISAPNP_CS4232('C','S','C',0x4637,0x0000,0x0010,0x0003),
    267         /* NewClear 3D - CX4237B-XQ3 */
    268         ISAPNP_CS4232('C','S','C',0x4837,0x0000,0x0010,0x0003),
    269         /* Dell Optiplex GX1 - CS4236B */
    270         ISAPNP_CS4232('C','S','C',0x6835,0x0000,0x0010,0x0003),
    271         /* Dell P410 motherboard - CS4236B */
    272         ISAPNP_CS4232_WOMPU('C','S','C',0x6835,0x0000,0x0010),
    273         /* Dell Workstation 400 Onboard - CS4236B */
    274         ISAPNP_CS4232('C','S','C',0x6836,0x0000,0x0010,0x0003),
    275         /* Turtle Beach Malibu - CS4237B */
    276         ISAPNP_CS4232('C','S','C',0x7537,0x0000,0x0010,0x0003),
    277         /* CS4235 - onboard */
    278         ISAPNP_CS4232('C','S','C',0x8025,0x0100,0x0110,0x0103),
     279        { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
     280        /* ACER AW37/Pro - CS4235 */
     281        { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     282        /* ACER AW35/Pro - CS4237B */
     283        { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
     284        /* CS4235 without MPU401 */
     285        { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
     286        /* IBM IntelliStation M Pro 6898 11U - CS4236B */
     287        { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
    279288        /* IBM PC 300PL Onboard - CS4236B */
    280         ISAPNP_CS4232_WOMPU('C','S','C',0xe836,0x0000,0x0010),
    281         /* IBM Aptiva 2137 E24 Onboard - CS4237B */
    282         ISAPNP_CS4232('C','S','C',0x8037,0x0000,0x0010,0x0003),
    283         /* IBM IntelliStation M Pro motherboard */
    284         ISAPNP_CS4232_WOMPU('C','S','C',0xc835,0x0000,0x0010),
    285         /* Guillemot MaxiSound 16 PnP - CS4236B */
    286         ISAPNP_CS4232('C','S','C',0x9836,0x0000,0x0010,0x0003),
    287         /* Gallant SC-70P */
    288         ISAPNP_CS4232('C','S','C',0x9837,0x0000,0x0010,0x0003),
    289         /* ACER AW37/Pro - CS4235 */
    290         ISAPNP_CS4232('C','S','C',0xd925,0x0000,0x0010,0x0003),
    291         /* ACER AW35/Pro - CS4237B */
    292         ISAPNP_CS4232('C','S','C',0xd937,0x0000,0x0010,0x0003),
    293         /* CS4235 without MPU401 */
    294         ISAPNP_CS4232_WOMPU('C','S','C',0xe825,0x0100,0x0110),
    295         /* IBM IntelliStation M Pro 6898 11U - CS4236B */
    296         ISAPNP_CS4232_WOMPU('C','S','C',0xe835,0x0000,0x0010),
     289        { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
    297290        /* Some noname CS4236 based card */
    298         ISAPNP_CS4232('C','S','C',0xe936,0x0000,0x0010,0x0003),
     291        { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    299292        /* CS4236B */
    300         ISAPNP_CS4232('C','S','C',0xf235,0x0000,0x0010,0x0003),
     293        { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    301294        /* CS4236B */
    302         ISAPNP_CS4232('C','S','C',0xf238,0x0000,0x0010,0x0003),
     295        { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
    303296        /* --- */
    304         { ISAPNP_CARD_END, }    /* end */
     297        { .id = "" }    /* end */
    305298};
    306299#endif
    307300
    308 ISAPNP_CARD_TABLE(snd_card_pnpids);
    309 
    310 static int __init snd_card_cs4236_isapnp(int dev, struct snd_card_cs4236 *acard)
    311 {
    312         const struct isapnp_card_id *id = snd_cs4236_isapnp_id[dev];
    313         struct isapnp_card *card = snd_cs4236_isapnp_cards[dev];
    314         struct isapnp_dev *pdev;
    315        
    316         acard->wss = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    317         if (acard->wss->active) {
    318                 acard->wss = NULL;
     301MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
     302
     303static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard,
     304                                         struct pnp_card_link *card,
     305                                         const struct pnp_card_device_id *id)
     306{
     307        struct pnp_dev *pdev;
     308        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     309        int err;
     310
     311        acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
     312        if (acard->wss == NULL) {
     313                kfree(cfg);
    319314                return -EBUSY;
    320315        }
    321         acard->ctrl = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    322         if (acard->ctrl->active) {
    323                 acard->wss = acard->ctrl = NULL;
     316        acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
     317        if (acard->ctrl == NULL) {
     318                kfree(cfg);
    324319                return -EBUSY;
    325320        }
    326         if (id->devs[2].vendor && id->devs[2].function) {
    327                 acard->mpu = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
    328                 if (acard->mpu->active) {
    329                         acard->wss = acard->ctrl = acard->mpu = NULL;
     321        if (id->devs[2].id[0]) {
     322                acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
     323                if (acard->mpu == NULL) {
     324                        kfree(cfg);
    330325                        return -EBUSY;
    331326                }
     
    334329        /* WSS initialization */
    335330        pdev = acard->wss;
    336         if (pdev->prepare(pdev) < 0)
    337                 return -EAGAIN;
     331        pnp_init_resource_table(cfg);
    338332        if (port[dev] != SNDRV_AUTO_PORT)
    339                 isapnp_resource_change(&pdev->resource[0], port[dev], 4);
     333                pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
    340334        if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] >= 0)
    341                 isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4);
     335                pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
    342336        if (sb_port[dev] != SNDRV_AUTO_PORT)
    343                 isapnp_resource_change(&pdev->resource[2], sb_port[dev], 16);
     337                pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
    344338        if (irq[dev] != SNDRV_AUTO_IRQ)
    345                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
     339                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
    346340        if (dma1[dev] != SNDRV_AUTO_DMA)
    347                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], 1);
     341                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    348342        if (dma2[dev] != SNDRV_AUTO_DMA)
    349                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
    350         if (pdev->activate(pdev)<0) {
    351                 printk(KERN_ERR IDENT " isapnp configure failed for WSS (out of resources?)\n");
     343                pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
     344        err = pnp_manual_config_dev(pdev, cfg, 0);
     345        if (err < 0)
     346                snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
     347        err = pnp_activate_dev(pdev);
     348        if (err < 0) {
     349                kfree(cfg);
     350                printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
    352351                return -EBUSY;
    353352        }
    354         port[dev] = pdev->resource[0].start;
     353        port[dev] = pnp_port_start(pdev, 0);
    355354        if (fm_port[dev] >= 0)
    356                 fm_port[dev] = pdev->resource[1].start;
    357         sb_port[dev] = pdev->resource[2].start;
    358         irq[dev] = pdev->irq_resource[0].start;
    359         dma1[dev] = pdev->dma_resource[0].start;
    360         dma2[dev] = pdev->dma_resource[1].start == 4 ? -1 : (int)pdev->dma_resource[1].start;
     355                fm_port[dev] = pnp_port_start(pdev, 1);
     356        sb_port[dev] = pnp_port_start(pdev, 2);
     357        irq[dev] = pnp_irq(pdev, 0);
     358        dma1[dev] = pnp_dma(pdev, 0);
     359        dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
    361360        snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
    362361                        port[dev], fm_port[dev], sb_port[dev]);
     
    366365        if (acard->ctrl && cport[dev] >= 0) {
    367366        pdev = acard->ctrl;
    368         if (pdev->prepare(pdev) < 0) {
    369                 acard->wss->deactivate(acard->wss);
    370                 return -EAGAIN;
    371         }
     367                pnp_init_resource_table(cfg);
    372368                if (cport[dev] != SNDRV_AUTO_PORT)
    373                         isapnp_resource_change(&pdev->resource[0], cport[dev], 8);
    374         if (pdev->activate(pdev)<0) {
    375                 printk(KERN_ERR IDENT " isapnp configure failed for control (out of resources?)\n");
    376                 acard->wss->deactivate(acard->wss);
     369                        pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
     370                err = pnp_manual_config_dev(pdev, cfg, 0);
     371                if (err < 0)
     372                        snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
     373                err = pnp_activate_dev(pdev);
     374                if (err < 0) {
     375                        kfree(cfg);
     376                        printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
    377377                return -EBUSY;
    378378        }
    379                 cport[dev] = pdev->resource[0].start;
     379                cport[dev] = pnp_port_start(pdev, 0);
    380380                snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
    381381        }
     
    383383        if (acard->mpu && mpu_port[dev] >= 0) {
    384384                pdev = acard->mpu;
    385                 if (pdev->prepare(pdev) < 0) {
    386                         acard->wss->deactivate(acard->wss);
    387                         acard->ctrl->deactivate(acard->ctrl);
    388                         return -EAGAIN;
    389                 }
     385                pnp_init_resource_table(cfg);
    390386                if (mpu_port[dev] != SNDRV_AUTO_PORT)
    391                         isapnp_resource_change(&pdev->resource[0], mpu_port[dev], 2);
     387                        pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
    392388                if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
    393                         isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev], 1);
    394                 if (pdev->activate(pdev)<0) {
     389                        pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
     390                err = pnp_manual_config_dev(pdev, cfg, 0);
     391                if (err < 0)
     392                        snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
     393                err = pnp_activate_dev(pdev);
     394                if (err < 0) {
     395                        kfree(cfg);
     396                        printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
    395397                        mpu_port[dev] = SNDRV_AUTO_PORT;
    396398                        mpu_irq[dev] = SNDRV_AUTO_IRQ;
    397                         printk(KERN_ERR IDENT " isapnp configure failed for MPU (out of resources?)\n");
    398399                } else {
    399                         mpu_port[dev] = pdev->resource[0].start;
    400                         if ((pdev->irq_resource[0].flags & IORESOURCE_IRQ) &&
    401                             mpu_irq[dev] >= 0) {
    402                                 mpu_irq[dev] = pdev->irq_resource[0].start;
     400                        mpu_port[dev] = pnp_port_start(pdev, 0);
     401                        if (pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
     402                                mpu_irq[dev] = pnp_irq(pdev, 0);
    403403                        } else {
    404404                                mpu_irq[dev] = -1;      /* disable interrupt */
     
    407407                snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
    408408        }
     409        kfree(cfg);
    409410        return 0;
    410411}
    411 
    412 static void snd_card_cs4236_deactivate(struct snd_card_cs4236 *acard)
    413 {
    414         if (acard->wss) {
    415                 acard->wss->deactivate(acard->wss);
    416                 acard->wss = NULL;
    417         }
    418         if (acard->ctrl) {
    419                 acard->ctrl->deactivate(acard->ctrl);
    420                 acard->ctrl = NULL;
    421         }
    422         if (acard->mpu) {
    423                 acard->mpu->deactivate(acard->mpu);
    424                 acard->mpu = NULL;
    425         }
    426 }
    427412#endif
    428413
     
    432417
    433418        if (acard) {
    434 #ifdef __ISAPNP__
    435                 snd_card_cs4236_deactivate(acard);
    436 #endif
    437419                if (acard->res_sb_port) {
    438420                        release_resource(acard->res_sb_port);
     
    442424}
    443425
    444 static int __init snd_card_cs4236_probe(int dev)
     426static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard,
     427                                           const struct pnp_card_device_id *pid)
    445428{
    446429        snd_card_t *card;
     
    451434        int err;
    452435
    453 #ifdef __ISAPNP__
     436#ifdef CONFIG_PNP
    454437        if (!isapnp[dev]) {
    455438#endif
     
    462445                        return -EINVAL;
    463446                }
    464 #ifdef __ISAPNP__
     447#ifdef CONFIG_PNP
    465448        }
    466449#endif
     
    471454        acard = (struct snd_card_cs4236 *)card->private_data;
    472455        card->private_free = snd_card_cs4236_free;
    473 #ifdef __ISAPNP__
    474         if (isapnp[dev] && (err = snd_card_cs4236_isapnp(dev, acard))<0) {
     456#ifdef CONFIG_PNP
     457        if (isapnp[dev] && (err = snd_card_cs4236_pnp(dev, acard, pcard, pid))<0) {
    475458                printk(KERN_ERR "isapnp detection failed and probing for " IDENT " is not supported\n");
    476459                snd_card_free(card);
     
    574557                return err;
    575558        }
    576         snd_cs4236_cards[dev] = card;
     559        if (pcard)
     560                pnp_set_card_drvdata(pcard, card);
     561        else
     562                snd_cs4236_legacy[dev] = card;
    577563        return 0;
    578564}
    579565
    580 #ifdef __ISAPNP__
    581 static int __init snd_cs4236_isapnp_detect(struct isapnp_card *card,
    582                                            const struct isapnp_card_id *id)
     566#ifdef CONFIG_PNP
     567static int __devinit snd_cs423x_pnp_detect(struct pnp_card_link *card,
     568                                           const struct pnp_card_device_id *id)
    583569{
    584570        static int dev;
     
    588574                if (!enable[dev])
    589575                        continue;
    590                 snd_cs4236_isapnp_cards[dev] = card;
    591                 snd_cs4236_isapnp_id[dev] = id;
    592                 res = snd_card_cs4236_probe(dev);
     576                res = snd_card_cs423x_probe(dev, card, id);
    593577                if (res < 0)
    594578                        return res;
     
    598582        return -ENODEV;
    599583}
    600 #endif /* __ISAPNP__ */
     584
     585static void __devexit snd_cs423x_pnp_remove(struct pnp_card_link * pcard)
     586{
     587        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     588       
     589        snd_card_disconnect(card);
     590        snd_card_free_in_thread(card);
     591}
     592                       
     593static struct pnp_card_driver cs423x_pnpc_driver = {
     594        .flags = PNP_DRIVER_RES_DISABLE,
     595        .name = "cs423x",
     596        .id_table = snd_cs423x_pnpids,
     597        .probe = snd_cs423x_pnp_detect,
     598        .remove = __devexit_p(snd_cs423x_pnp_remove),
     599};
     600#endif /* CONFIG_PNP */
    601601
    602602static int __init alsa_card_cs423x_init(void)
     
    607607                if (!enable[dev])
    608608                        continue;
    609 #ifdef __ISAPNP__
     609#ifdef CONFIG_PNP
    610610                if (isapnp[dev])
    611611                        continue;
    612612#endif
    613                 if (snd_card_cs4236_probe(dev) >= 0)
     613                if (snd_card_cs423x_probe(dev, NULL, NULL) >= 0)
    614614                        cards++;
    615615        }
    616 #ifdef __ISAPNP__
    617         cards += isapnp_probe_cards(snd_card_pnpids, snd_cs4236_isapnp_detect);
     616#ifdef CONFIG_PNP
     617        cards += pnp_register_card_driver(&cs423x_pnpc_driver);
    618618#endif
    619619        if (!cards) {
     620#ifdef CONFIG_PNP
     621                pnp_unregister_card_driver(&cs423x_pnpc_driver);
     622#endif
    620623#ifdef MODULE
    621624                printk(KERN_ERR IDENT " soundcard not found or device busy\n");
     
    630633        int idx;
    631634
     635#ifdef CONFIG_PNP
     636        /* PnP cards first */
     637        pnp_unregister_card_driver(&cs423x_pnpc_driver);
     638#endif
    632639        for (idx = 0; idx < SNDRV_CARDS; idx++)
    633                 snd_card_free(snd_cs4236_cards[idx]);
     640                snd_card_free(snd_cs4236_legacy[idx]);
    634641}
    635642
     
    666673               get_option(&str,&dma1[nr_dev]) == 2 &&
    667674               get_option(&str,&dma2[nr_dev]) == 2);
    668 #ifdef __ISAPNP__
     675#ifdef CONFIG_PNP
    669676        if (pnp != INT_MAX)
    670677                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/dt019x.c

    r224 r246  
    2626#include <linux/sched.h>
    2727#include <linux/wait.h>
    28 #ifndef LINUX_ISAPNP_H
    29 #include <linux/isapnp.h>
    30 #define isapnp_card pci_bus
    31 #define isapnp_dev pci_dev
    32 #endif
     28#include <linux/pnp.h>
    3329#include <sound/core.h>
    3430#define SNDRV_GET_ID
     
    8884
    8985struct snd_card_dt019x {
    90 #ifdef __ISAPNP__
    91         struct isapnp_dev *dev;
    92         struct isapnp_dev *devmpu;
    93         struct isapnp_dev *devopl;
    94 #endif  /* __ISAPNP__ */
     86        struct pnp_dev *dev;
     87        struct pnp_dev *devmpu;
     88        struct pnp_dev *devopl;
    9589};
    9690
    97 static snd_card_t *snd_dt019x_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    98 
    99 #ifdef __ISAPNP__
    100 static struct isapnp_card *snd_dt019x_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    101 static const struct isapnp_card_id *snd_dt019x_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    102 
    103 static struct isapnp_card_id snd_dt019x_pnpids[] __devinitdata = {
     91static struct pnp_card_device_id snd_dt019x_pnpids[] __devinitdata = {
    10492        /* DT197A30 */
    105         {
    106                 ISAPNP_CARD_ID('R','W','B',0x1688),
    107                 .devs = { ISAPNP_DEVICE_ID('@','@','@',0x0001),
    108                         ISAPNP_DEVICE_ID('@','X','@',0x0001),
    109                         ISAPNP_DEVICE_ID('@','H','@',0x0001) }
    110         },
     93        { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
    11194        /* DT0196 / ALS-007 */
    112         {
    113                 ISAPNP_CARD_ID('A','L','S',0x0007),
    114                 .devs = { ISAPNP_DEVICE_ID('@','@','@',0x0001),
    115                         ISAPNP_DEVICE_ID('@','X','@',0x0001),
    116                         ISAPNP_DEVICE_ID('@','H','@',0x0001) }
    117         },
    118         { ISAPNP_CARD_END, }
     95        { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
     96        { .id = "",  }
    11997};
    12098
    121 ISAPNP_CARD_TABLE(snd_dt019x_pnpids);
    122 
    123 #endif  /* __ISAPNP__ */
     99MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
     100
    124101
    125102#define DRIVER_NAME     "snd-card-dt019x"
    126103
    127104
    128 #ifdef __ISAPNP__
    129 static int __init snd_card_dt019x_isapnp(int dev, struct snd_card_dt019x *acard)
    130 {
    131         const struct isapnp_card_id *id = snd_dt019x_isapnp_id[dev];
    132         struct isapnp_card *card = snd_dt019x_isapnp_cards[dev];
    133         struct isapnp_dev *pdev;
    134 
    135         acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    136         if (acard->dev->active) {
    137                 acard->dev = NULL;
    138                 return -EBUSY;
    139         }
    140         acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    141         if (acard->devmpu->active) {
    142                 acard->dev = acard->devmpu = NULL;
    143                 return -EBUSY;
    144         }
    145         acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
    146         if (acard->devopl->active) {
    147                 acard->dev = acard->devmpu = acard->devopl = NULL;
    148                 return -EBUSY;
    149         }
     105static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
     106                                         struct pnp_card_link *card,
     107                                         const struct pnp_card_device_id *pid)
     108{
     109        struct pnp_dev *pdev;
     110        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     111        int err;
     112
     113        if (!cfg)
     114                return -ENOMEM;
     115
     116        acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
     117        if (acard->dev == NULL) {
     118                kfree (cfg);
     119                return -ENODEV;
     120        }
     121        acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
     122        acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
    150123
    151124        pdev = acard->dev;
    152         if (!pdev || pdev->prepare(pdev)<0)
    153                 return -EAGAIN;
     125        pnp_init_resource_table(cfg);
    154126
    155127        if (port[dev] != SNDRV_AUTO_PORT)
    156                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     128                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    157129        if (dma8[dev] != SNDRV_AUTO_DMA)
    158                 isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
     130                pnp_resource_change(&cfg->dma_resource[0], dma8[dev],
    159131                        1);
    160132        if (irq[dev] != SNDRV_AUTO_IRQ)
    161                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    162 
    163         if (pdev->activate(pdev)<0) {
    164                 printk(KERN_ERR PFX "DT-019X AUDIO isapnp configure failure\n");
    165                 return -EBUSY;
    166         }
    167         port[dev] = pdev->resource[0].start;
    168         dma8[dev] = pdev->dma_resource[0].start;
    169         irq[dev] = pdev->irq_resource[0].start;
     133                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     134
     135        if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     136                snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
     137        err = pnp_activate_dev(pdev);
     138        if (err < 0) {
     139                snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
     140                kfree(cfg);
     141                return err;
     142        }
     143
     144        port[dev] = pnp_port_start(pdev, 0);
     145        dma8[dev] = pnp_dma(pdev, 0);
     146        irq[dev] = pnp_irq(pdev, 0);
    170147        snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%lx, dma=0x%lx\n",
    171148                        port[dev],irq[dev],dma8[dev]);
    172149
    173150        pdev = acard->devmpu;
    174         if (!pdev || pdev->prepare(pdev)<0)
    175                 return 0;
    176 
    177         if (mpu_port[dev] != SNDRV_AUTO_PORT)
    178                 isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
    179                         2);
    180         if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
    181                 isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
    182                         1);
    183 
    184         if (pdev->activate(pdev)<0) {
    185                 printk(KERN_ERR PFX "DT-019X MPU-401 isapnp configure failure\n");
    186                 mpu_port[dev] = -1;
    187                 acard->devmpu = NULL;
    188         } else {
    189                 mpu_port[dev] = pdev->resource[0].start;
    190                 mpu_irq[dev] = pdev->irq_resource[0].start;
     151
     152        if (pdev != NULL) {
     153                pnp_init_resource_table(cfg);
     154                if (mpu_port[dev] != SNDRV_AUTO_PORT)
     155                        pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
     156                if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
     157                        pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
     158                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     159                        snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
     160                err = pnp_activate_dev(pdev);
     161                if (err < 0)
     162                        goto __mpu_error;
     163                mpu_port[dev] = pnp_port_start(pdev, 0);
     164                mpu_irq[dev] = pnp_irq(pdev, 0);
    191165                snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%lx\n",
    192166                                mpu_port[dev],mpu_irq[dev]);
     167        } else {
     168                __mpu_error:
     169                if (pdev) {
     170                        pnp_release_card_device(pdev);
     171                        snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
     172                }
     173                acard->devmpu = NULL;
     174                mpu_port[dev] = -1;
    193175        }
    194176
    195177        pdev = acard->devopl;
    196         if (!pdev || pdev->prepare(pdev)<0)
    197                 return 0;
    198 
    199         if (fm_port[dev] != SNDRV_AUTO_PORT)
    200                 isapnp_resource_change(&pdev->resource[0], fm_port[dev], 4);
    201 
    202         if (pdev->activate(pdev)<0) {
    203                 printk(KERN_ERR PFX "DT-019X OPL3 isapnp configure failure\n");
     178        if (pdev != NULL) {
     179                pnp_init_resource_table(cfg);
     180                if (fm_port[dev] != SNDRV_AUTO_PORT)
     181                        pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
     182                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     183                        snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
     184                err = pnp_activate_dev(pdev);
     185                if (err < 0)
     186                        goto __fm_error;
     187                fm_port[dev] = pnp_port_start(pdev, 0);
     188                snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
     189        } else {
     190                __fm_error:
     191                if (pdev) {
     192                        pnp_release_card_device(pdev);
     193                        snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
     194                }
     195                acard->devopl = NULL;
    204196                fm_port[dev] = -1;
    205                 acard->devopl = NULL;
    206         } else {
    207                 fm_port[dev] = pdev->resource[0].start;
    208                 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
    209         }
    210 
     197        }
     198
     199        kfree(cfg);
    211200        return 0;
    212201}
    213202
    214 static void snd_card_dt019x_deactivate(struct snd_card_dt019x *acard)
    215 {
    216         if (acard->dev) {
    217                 acard->dev->deactivate(acard->dev);
    218                 acard->dev = NULL;
    219         }
    220         if (acard->devmpu) {
    221                 acard->devmpu->deactivate(acard->devmpu);
    222                 acard->devmpu = NULL;
    223         }
    224         if (acard->devopl) {
    225                 acard->devopl->deactivate(acard->devopl);
    226                 acard->devopl = NULL;
    227         }
    228 }
    229 #endif  /* __ISAPNP__ */
    230 
    231 static void snd_card_dt019x_free(snd_card_t *card)
    232 {
    233         struct snd_card_dt019x *acard = (struct snd_card_dt019x *)card->private_data;
    234 
    235         if (acard != NULL) {
    236 #ifdef __ISAPNP__
    237                 snd_card_dt019x_deactivate(acard);
    238 #endif  /* __ISAPNP__ */
    239         }
    240 }
    241 
    242 static int __init snd_card_dt019x_probe(int dev)
     203static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
    243204{
    244205        int error;
     
    252213                return -ENOMEM;
    253214        acard = (struct snd_card_dt019x *)card->private_data;
    254         card->private_free = snd_card_dt019x_free;
    255 
    256 #ifdef __ISAPNP__
    257         if ((error = snd_card_dt019x_isapnp(dev, acard))) {
    258                 snd_card_free(card);
    259                 return error;
    260         }
    261 #else
    262         printk(KERN_ERR PFX "you have to enable PnP support ...\n");
    263         snd_card_free(card);
    264         return -ENOSYS;
    265 #endif  /* __ISAPNP__ */
     215
     216        if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
     217                snd_card_free(card);
     218                return error;
     219        }
    266220
    267221        if ((error = snd_sbdsp_create(card, port[dev],
     
    293247                                        SA_INTERRUPT,
    294248                                        NULL) < 0)
    295                         printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n",
    296                                 mpu_port[dev]);
     249                        snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
    297250        }
    298251
     
    302255                                    fm_port[dev] + 2,
    303256                                    OPL3_HW_AUTO, 0, &opl3) < 0) {
    304                         printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
    305                                 fm_port[dev], fm_port[dev] + 2);
     257                        snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
     258                                   fm_port[dev], fm_port[dev] + 2);
    306259                } else {
    307260                        if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
     
    325278                return error;
    326279        }
    327         snd_dt019x_cards[dev] = card;
     280        pnp_set_card_drvdata(pcard, card);
    328281        return 0;
    329282}
    330283
    331 #ifdef __ISAPNP__
    332 static int __init snd_dt019x_isapnp_detect(struct isapnp_card *card,
    333                                             const struct isapnp_card_id *id)
     284static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
     285                                          const struct pnp_card_device_id *pid)
    334286{
    335287        static int dev;
     
    339291                if (!enable[dev])
    340292                        continue;
    341                 snd_dt019x_isapnp_cards[dev] = card;
    342                 snd_dt019x_isapnp_id[dev] = id;
    343                 res = snd_card_dt019x_probe(dev);
     293                res = snd_card_dt019x_probe(dev, card, pid);
    344294                if (res < 0)
    345295                        return res;
     
    349299        return -ENODEV;
    350300}
    351 #endif /* __ISAPNP__ */
     301
     302static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
     303{
     304        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     305        snd_card_disconnect(card);
     306        snd_card_free_in_thread(card);
     307}
     308
     309static struct pnp_card_driver dt019x_pnpc_driver = {
     310        .flags          = PNP_DRIVER_RES_DISABLE,
     311        .name           = "dt019x",
     312        .id_table       = snd_dt019x_pnpids,
     313        .probe          = snd_dt019x_pnp_probe,
     314        .remove         = __devexit_p(snd_dt019x_pnp_remove),
     315};
    352316
    353317static int __init alsa_card_dt019x_init(void)
     
    355319        int cards = 0;
    356320
    357 #ifdef __ISAPNP__
    358         cards += isapnp_probe_cards(snd_dt019x_pnpids, snd_dt019x_isapnp_detect);
    359 #else
    360         printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
    361 #endif
     321        cards += pnp_register_card_driver(&dt019x_pnpc_driver);
     322
    362323#ifdef MODULE
    363324        if (!cards)
    364                 printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
     325                snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
    365326#endif
    366327        return cards ? 0 : -ENODEV;
     
    369330static void __exit alsa_card_dt019x_exit(void)
    370331{
    371         int dev;
    372 
    373         for (dev = 0; dev < SNDRV_CARDS; dev++)
    374                 snd_card_free(snd_dt019x_cards[dev]);
     332        pnp_unregister_card_driver(&dt019x_pnpc_driver);
    375333}
    376334
  • GPL/branches/alsa-resync1/alsa-kernel/isa/es1688/es1688_lib.c

    r224 r246  
    483483}
    484484
    485 void snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    486 {
    487         es1688_t *chip = snd_magic_cast(es1688_t, dev_id, return);
     485irqreturn_t snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     486{
     487        es1688_t *chip = snd_magic_cast(es1688_t, dev_id, return IRQ_NONE);
    488488
    489489        if (chip->trigger_value == 0x05)        /* ok.. playback is active */
     
    493493
    494494        inb(ES1688P(chip, DATA_AVAIL)); /* ack interrupt */
     495        return IRQ_HANDLED;
    495496}
    496497
  • GPL/branches/alsa-resync1/alsa-kernel/isa/es18xx.c

    r224 r246  
    7171#include <linux/pm.h>
    7272#include <linux/slab.h>
    73 #ifndef LINUX_ISAPNP_H
     73#include <linux/pnp.h>
    7474#include <linux/isapnp.h>
    75 #define isapnp_card pci_bus
    76 #define isapnp_dev pci_dev
    77 #endif
    7875#include <sound/core.h>
    7976#include <sound/control.h>
     
    731728}
    732729
    733 static void snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    734 {
    735         es18xx_t *chip = snd_magic_cast(es18xx_t, dev_id, return);
     730static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     731{
     732        es18xx_t *chip = snd_magic_cast(es18xx_t, dev_id, return IRQ_NONE);
    736733        unsigned char status;
    737 
    738734
    739735        if (chip->caps & ES18XX_CONTROL) {
     
    791787                snd_es18xx_mixer_write(chip, 0x66, 0x00);
    792788        }
    793 
     789        return IRQ_HANDLED;
    794790}
    795791
     
    12641260
    12651261#if 0
    1266 static int __init snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
     1262static int __devinit snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
    12671263{
    12681264        int data;
     
    12761272#endif
    12771273
    1278 static void __init snd_es18xx_config_write(es18xx_t *chip,
     1274static void __devinit snd_es18xx_config_write(es18xx_t *chip,
    12791275                                           unsigned char reg, unsigned char data)
    12801276{
     
    12881284}
    12891285
    1290 static int __init snd_es18xx_initialize(es18xx_t *chip)
     1286static int __devinit snd_es18xx_initialize(es18xx_t *chip)
    12911287{
    12921288        int mask = 0;
     
    14371433}
    14381434
    1439 static int __init snd_es18xx_identify(es18xx_t *chip)
     1435static int __devinit snd_es18xx_identify(es18xx_t *chip)
    14401436{
    14411437        int hi,lo;
     
    15011497}
    15021498
    1503 static int __init snd_es18xx_probe(es18xx_t *chip)
     1499static int __devinit snd_es18xx_probe(es18xx_t *chip)
    15041500{
    15051501        if (snd_es18xx_identify(chip) < 0) {
    1506                 printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
     1502                snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
    15071503                return -ENODEV;
    15081504        }
     
    15701566}
    15711567
    1572 int __init snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpcm)
     1568int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpcm)
    15731569{
    15741570        snd_pcm_t *pcm;
     
    17151711}
    17161712
    1717 static int __init snd_es18xx_new_device(snd_card_t * card,
     1713static int __devinit snd_es18xx_new_device(snd_card_t * card,
    17181714                                        unsigned long port,
    17191715                                        unsigned long mpu_port,
     
    17471743        if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) {
    17481744                snd_es18xx_free(chip);
    1749                 printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
     1745                snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
    17501746                return -EBUSY;
    17511747        }
     
    17531749        if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) {
    17541750                snd_es18xx_free(chip);
    1755                 printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
     1751                snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
    17561752                return -EBUSY;
    17571753        }
     
    17601756        if (request_dma(dma1, "ES18xx DMA 1")) {
    17611757                snd_es18xx_free(chip);
    1762                 printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
     1758                snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
    17631759                return -EBUSY;
    17641760        }
     
    17671763        if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
    17681764                snd_es18xx_free(chip);
    1769                 printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
     1765                snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
    17701766                return -EBUSY;
    17711767        }
     
    17841780}
    17851781
    1786 static int __init snd_es18xx_mixer(es18xx_t *chip)
     1782static int __devinit snd_es18xx_mixer(es18xx_t *chip)
    17871783{
    17881784        snd_card_t *card;
     
    18871883static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    18881884static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
    1889 #ifdef __ISAPNP__
     1885#ifdef CONFIG_PNP
    18901886#ifdef TARGET_OS2
    18911887static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    18951891#endif
    18961892static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* 0x220,0x240,0x260,0x280 */
    1897 #ifndef __ISAPNP__
     1893#ifndef CONFIG_PNP
    18981894#ifdef TARGET_OS2
    18991895static long mpu_port[SNDRV_CARDS] = {-1,-1,-1,-1,-1,-1,-1,-1};
     
    19171913MODULE_PARM_DESC(enable, "Enable ES18xx soundcard.");
    19181914MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    1919 #ifdef __ISAPNP__
     1915#ifdef CONFIG_PNP
    19201916MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    1921 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     1917MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
    19221918MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
    19231919#endif
     
    19421938
    19431939struct snd_audiodrive {
    1944 #ifdef __ISAPNP__
    1945         struct isapnp_dev *dev;
    1946         struct isapnp_dev *devc;
     1940#ifdef CONFIG_PNP
     1941        struct pnp_dev *dev;
     1942        struct pnp_dev *devc;
    19471943#endif
    19481944};
    19491945
    1950 static snd_card_t *snd_audiodrive_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    1951 
    1952 #ifdef __ISAPNP__
    1953 
    1954 static struct isapnp_card *snd_audiodrive_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    1955 static const struct isapnp_card_id *snd_audiodrive_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    1956 
    1957 #define ISAPNP_ES18XX(_va, _vb, _vc, _device, _audio, _control) \
    1958         { \
    1959                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    1960                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
    1961                          ISAPNP_DEVICE_ID(_va, _vb, _vc, _control) } \
    1962         }
    1963 
    1964 static struct isapnp_card_id snd_audiodrive_pnpids[] __devinitdata = {
     1946static snd_card_t *snd_audiodrive_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     1947
     1948#ifdef CONFIG_PNP
     1949
     1950static struct pnp_card_device_id snd_audiodrive_pnpids[] __devinitdata = {
    19651951        /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
    1966         ISAPNP_ES18XX('E','S','S',0x1868,0x1868,0x0000),
     1952        { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } },
    19671953        /* ESS 1868 (integrated on Maxisound Cards) */
    1968         ISAPNP_ES18XX('E','S','S',0x1868,0x8601,0x8600),
     1954        { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } },
    19691955        /* ESS 1868 (integrated on Maxisound Cards) */
    1970         ISAPNP_ES18XX('E','S','S',0x1868,0x8611,0x8610),
     1956        { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } },
    19711957        /* ESS ES1869 Plug and Play AudioDrive */
    1972         ISAPNP_ES18XX('E','S','S',0x0003,0x1869,0x0006),
     1958        { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } },
    19731959        /* ESS 1869 */
    1974         ISAPNP_ES18XX('E','S','S',0x1869,0x1869,0x0006),
     1960        { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } },
    19751961        /* ESS 1878 */
    1976         ISAPNP_ES18XX('E','S','S',0x1878,0x1878,0x0004),
     1962        { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } },
    19771963        /* ESS 1879 */
    1978         ISAPNP_ES18XX('E','S','S',0x1879,0x1879,0x0009),
     1964        { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } },
    19791965        /* --- */
    1980         { ISAPNP_CARD_END, } /* end */
     1966        { .id = "" } /* end */
    19811967};
    19821968
    1983 ISAPNP_CARD_TABLE(snd_audiodrive_pnpids);
    1984 
    1985 static int __init snd_audiodrive_isapnp(int dev, struct snd_audiodrive *acard)
    1986 {
    1987         const struct isapnp_card_id *id = snd_audiodrive_isapnp_id[dev];
    1988         struct isapnp_card *card = snd_audiodrive_isapnp_cards[dev];
    1989         struct isapnp_dev *pdev;
    1990 
    1991         acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    1992         if (acard->dev->active) {
    1993                 acard->dev = NULL;
     1969MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
     1970
     1971static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
     1972                                        struct pnp_card_link *card,
     1973                                        const struct pnp_card_device_id *id)
     1974{
     1975        struct pnp_dev *pdev;
     1976        struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
     1977        int err;
     1978
     1979        if (!cfg)
     1980                return -ENOMEM;
     1981        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     1982        if (acard->dev == NULL) {
     1983                kfree(cfg);
    19941984                return -EBUSY;
    19951985        }
    1996         acard->devc = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    1997         if (acard->devc->active) {
    1998                 acard->dev = acard->devc = NULL;
     1986        acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
     1987        if (acard->devc == NULL) {
     1988                kfree(cfg);
    19991989                return -EBUSY;
    20001990        }
    20011991        /* Control port initialization */
    2002         if (acard->devc->prepare(acard->devc)<0)
     1992        err = pnp_activate_dev(acard->devc);
     1993        if (err < 0) {
     1994                snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
    20031995                return -EAGAIN;
    2004         if (acard->devc->activate(acard->devc)<0) {
    2005                 printk(KERN_ERR PFX "isapnp control configure failure (out of resources?)\n");
    2006                 return -EAGAIN;
    2007         }
    2008         snd_printdd("isapnp: port=0x%lx\n", acard->devc->resource[0].start);
     1996        }
     1997        snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0));
    20091998        /* PnP initialization */
    20101999        pdev = acard->dev;
    2011         if (pdev->prepare(pdev)<0) {
    2012                 acard->devc->deactivate(acard->devc);
    2013                 return -EAGAIN;
    2014         }
     2000        pnp_init_resource_table(cfg);
    20152001        if (port[dev] != SNDRV_AUTO_PORT)
    2016                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     2002                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    20172003        if (fm_port[dev] != SNDRV_AUTO_PORT)
    2018                 isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4);
     2004                pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
    20192005        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    2020                 isapnp_resource_change(&pdev->resource[2], mpu_port[dev], 2);
     2006                pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2);
    20212007        if (dma1[dev] != SNDRV_AUTO_DMA)
    2022                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], 1);
     2008                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    20232009        if (dma2[dev] != SNDRV_AUTO_DMA)
    2024                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev], 1);
     2010                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    20252011        if (irq[dev] != SNDRV_AUTO_IRQ)
    2026                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    2027         if (pdev->activate(pdev)<0) {
    2028                 printk(KERN_ERR PFX "isapnp configure failure (out of resources?)\n");
    2029                 acard->devc->deactivate(acard->devc);
     2012                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     2013        err = pnp_manual_config_dev(pdev, cfg, 0);
     2014        if (err < 0)
     2015                snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n");
     2016        err = pnp_activate_dev(pdev);
     2017        if (err < 0) {
     2018                snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
     2019                kfree(cfg);
    20302020                return -EBUSY;
    20312021        }
    20322022        /* ok. hack using Vendor-Defined Card-Level registers */
    20332023        /* skip csn and logdev initialization - already done in isapnp_configure */
    2034         isapnp_cfg_begin(pdev->bus->number, pdev->devfn);
    2035         isapnp_write_byte(0x27, pdev->irq_resource[0].start);   /* Hardware Volume IRQ Number */
     2024        if (pnp_device_is_isapnp(pdev)) {
     2025                isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
     2026                isapnp_write_byte(0x27, pnp_irq(pdev, 0));      /* Hardware Volume IRQ Number */
    20362027        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    2037                 isapnp_write_byte(0x28, pdev->irq);             /* MPU-401 IRQ Number */
    2038         isapnp_write_byte(0x72, pdev->irq_resource[0].start);   /* second IRQ */
     2028                        isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
     2029                isapnp_write_byte(0x72, pnp_irq(pdev, 0));      /* second IRQ */
    20392030        isapnp_cfg_end();
    2040         port[dev] = pdev->resource[0].start;
    2041         fm_port[dev] = pdev->resource[1].start;
    2042         mpu_port[dev] = pdev->resource[2].start;
    2043         dma1[dev] = pdev->dma_resource[0].start;
    2044         dma2[dev] = pdev->dma_resource[1].start;
    2045         irq[dev] = pdev->irq_resource[0].start;
    2046         snd_printdd("isapnp ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
    2047         snd_printdd("isapnp ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
    2048         return 0;
    2049 }
    2050 
    2051 static void snd_audiodrive_deactivate(struct snd_audiodrive *acard)
    2052 {
    2053         if (acard->devc) {
    2054                 acard->devc->deactivate(acard->devc);
    2055                 acard->devc = NULL;
    2056         }
    2057         if (acard->dev) {
    2058                 acard->dev->deactivate(acard->dev);
    2059                 acard->dev = NULL;
    2060         }
    2061 }
    2062 #endif /* __ISAPNP__ */
    2063 
    2064 static void snd_audiodrive_free(snd_card_t *card)
    2065 {
    2066         struct snd_audiodrive *acard = (struct snd_audiodrive *)card->private_data;
    2067 
    2068         if (acard) {
    2069 #ifdef __ISAPNP__
    2070                 snd_audiodrive_deactivate(acard);
    2071 #endif
    2072         }
    2073 }
    2074 
    2075 static int __init snd_audiodrive_probe(int dev)
     2031        } else {
     2032                snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n");
     2033        }
     2034        port[dev] = pnp_port_start(pdev, 0);
     2035        fm_port[dev] = pnp_port_start(pdev, 1);
     2036        mpu_port[dev] = pnp_port_start(pdev, 2);
     2037        dma1[dev] = pnp_dma(pdev, 0);
     2038        dma2[dev] = pnp_dma(pdev, 1);
     2039        irq[dev] = pnp_irq(pdev, 0);
     2040        snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
     2041        snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
     2042        kfree(cfg);
     2043        return 0;
     2044}
     2045#endif /* CONFIG_PNP_ */
     2046
     2047static int __devinit snd_audiodrive_probe(int dev, struct pnp_card_link *pcard,
     2048                                          const struct pnp_card_device_id *pid)
    20762049{
    20772050        static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
     
    20902063                return -ENOMEM;
    20912064        acard = (struct snd_audiodrive *)card->private_data;
    2092         card->private_free = snd_audiodrive_free;
    2093 #ifdef __ISAPNP__
    2094         if (isapnp[dev] && (err = snd_audiodrive_isapnp(dev, acard)) < 0) {
     2065#ifdef CONFIG_PNP
     2066        if (isapnp[dev] && (err = snd_audiodrive_pnp(dev, acard, pcard, pid)) < 0) {
    20952067                snd_card_free(card);
    20962068                return err;
     
    21432115        if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
    21442116        if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
    2145                         printk(KERN_ERR PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
     2117                        snd_printk(KERN_ERR PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
    21462118        } else {
    21472119                if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
     
    21892161                return err;
    21902162        }
    2191         snd_audiodrive_cards[dev] = card;
    2192         return 0;
    2193 }
    2194 
    2195 static int __init snd_audiodrive_probe_legacy_port(unsigned long xport)
     2163        if (pcard)
     2164                pnp_set_card_drvdata(pcard, card);
     2165        else
     2166                snd_audiodrive_legacy[dev] = card;
     2167        return 0;
     2168}
     2169
     2170static int __devinit snd_audiodrive_probe_legacy_port(unsigned long xport)
    21962171{
    21972172        static int dev;
     
    22012176                if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
    22022177                        continue;
    2203 #ifdef __ISAPNP__
     2178#ifdef CONFIG_PNP
    22042179                if (isapnp[dev])
    22052180                        continue;
    22062181#endif
    22072182                port[dev] = xport;
    2208                 res = snd_audiodrive_probe(dev);
     2183                res = snd_audiodrive_probe(dev, NULL, NULL);
    22092184                if (res < 0)
    22102185                        port[dev] = SNDRV_AUTO_PORT;
     
    22152190
    22162191
    2217 #ifdef __ISAPNP__
    2218 static int __init snd_audiodrive_isapnp_detect(struct isapnp_card *card,
    2219                                                const struct isapnp_card_id *id)
     2192#ifdef CONFIG_PNP
     2193static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *card,
     2194                                               const struct pnp_card_device_id *id)
    22202195{
    22212196        static int dev;
     
    22252200                if (!enable[dev] || !isapnp[dev])
    22262201                        continue;
    2227                 snd_audiodrive_isapnp_cards[dev] = card;
    2228                 snd_audiodrive_isapnp_id[dev] = id;
    2229                 res = snd_audiodrive_probe(dev);
     2202                res = snd_audiodrive_probe(dev, card, id);
    22302203                if (res < 0)
    22312204                        return res;
     
    22362209        return -ENODEV;
    22372210}
    2238 #endif /* __ISAPNP__ */
     2211
     2212static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard)
     2213{
     2214        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     2215
     2216        snd_card_disconnect(card);
     2217        snd_card_free_in_thread(card);
     2218}
     2219
     2220static struct pnp_card_driver es18xx_pnpc_driver = {
     2221        .flags = PNP_DRIVER_RES_DISABLE,
     2222        .name = "es18xx",
     2223        .id_table = snd_audiodrive_pnpids,
     2224        .probe = snd_audiodrive_pnp_detect,
     2225        .remove = __devexit_p(snd_audiodrive_pnp_remove),
     2226};
     2227#endif /* CONFIG_PNP */
    22392228
    22402229static int __init alsa_card_es18xx_init(void)
     
    22472236                if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
    22482237                        continue;
    2249 #ifdef __ISAPNP__
     2238#ifdef CONFIG_PNP
    22502239                if (isapnp[dev])
    22512240                        continue;
    22522241#endif
    2253                 if (snd_audiodrive_probe(dev) >= 0)
     2242                if (snd_audiodrive_probe(dev, NULL, NULL) >= 0)
    22542243                        cards++;
    22552244        }
    22562245        /* legacy auto configured cards */
    22572246        cards += snd_legacy_auto_probe(possible_ports, snd_audiodrive_probe_legacy_port);
    2258 #ifdef __ISAPNP__
     2247#ifdef CONFIG_PNP
    22592248        /* ISA PnP cards at last */
    2260         cards += isapnp_probe_cards(snd_audiodrive_pnpids, snd_audiodrive_isapnp_detect);
     2249        cards += pnp_register_card_driver(&es18xx_pnpc_driver);
    22612250#endif
    22622251        if(!cards) {
     2252#ifdef CONFIG_PNP
     2253                pnp_unregister_card_driver(&es18xx_pnpc_driver);
     2254#endif
    22632255#ifdef MODULE
    2264                 printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
     2256                snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
    22652257#endif
    22662258                return -ENODEV;
     
    22732265        int idx;
    22742266
     2267#ifdef CONFIG_PNP
     2268        /* PnP cards first */
     2269        pnp_unregister_card_driver(&es18xx_pnpc_driver);
     2270#endif
    22752271        for(idx = 0; idx < SNDRV_CARDS; idx++)
    2276                 snd_card_free(snd_audiodrive_cards[idx]);
     2272                snd_card_free(snd_audiodrive_legacy[idx]);
    22772273}
    22782274
    22792275module_init(alsa_card_es18xx_init)
    22802276module_exit(alsa_card_es18xx_exit)
     2277
    22812278
    22822279#ifndef MODULE
     
    23032300               get_option(&str,&dma1[nr_dev]) == 2 &&
    23042301               get_option(&str,&dma2[nr_dev]) == 2);
    2305 #ifdef __ISAPNP__
     2302#ifdef CONFIG_PNP
    23062303        if (pnp != INT_MAX)
    23072304                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/gus/gus_irq.c

    r210 r246  
    3131#endif
    3232
    33 void snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     33irqreturn_t snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    3434{
    35         snd_gus_card_t * gus = snd_magic_cast(snd_gus_card_t, dev_id, return);
     35        snd_gus_card_t * gus = snd_magic_cast(snd_gus_card_t, dev_id, return IRQ_NONE);
    3636        unsigned char status;
    3737        int loop = 100;
    38        
    39       __again:
     38        int handled = 0;
     39
     40__again:
    4041        status = inb(gus->gf1.reg_irqstat);
    4142        if (status == 0)
    42                 return;
     43                return IRQ_RETVAL(handled);
     44        handled = 1;
    4345        // snd_printk("IRQ: status = 0x%x\n", status);
    4446        if (status & 0x02) {
     
    102104        if (--loop > 0)
    103105                goto __again;
     106        return IRQ_NONE;
    104107}
    105108
  • GPL/branches/alsa-resync1/alsa-kernel/isa/gus/gusmax.c

    r212 r246  
    137137}
    138138
    139 static void snd_gusmax_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     139static irqreturn_t snd_gusmax_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    140140{
    141141        struct snd_gusmax *maxcard = (struct snd_gusmax *) dev_id;
    142142        int loop, max = 5;
     143        int handled = 0;
    143144
    144145        do {
    145146                loop = 0;
    146147                if (inb(maxcard->gus_status_reg)) {
     148                        handled = 1;
    147149                        snd_gus_interrupt(irq, maxcard->gus, regs);
    148150                        loop++;
    149151                }
    150152                if (inb(maxcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
     153                        handled = 1;
    151154                        snd_cs4231_interrupt(irq, maxcard->cs4231, regs);
    152155                        loop++;
    153156                }
    154157        } while (loop && --max > 0);
     158        return IRQ_RETVAL(handled);
    155159}
    156160
  • GPL/branches/alsa-resync1/alsa-kernel/isa/gus/interwave.c

    r224 r246  
    2828#include <linux/init.h>
    2929#include <linux/slab.h>
    30 #ifndef LINUX_ISAPNP_H
    31 #include <linux/isapnp.h>
    32 #define isapnp_card pci_bus
    33 #define isapnp_dev pci_dev
    34 #endif
     30#include <linux/pnp.h>
    3531#include <sound/core.h>
    3632#include <sound/gus.h>
     
    6359static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    6460static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
    65 #ifdef __ISAPNP__
     61#ifdef CONFIG_PNP
    6662#ifdef TARGET_OS2
    6763static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    143139        unsigned short gus_status_reg;
    144140        unsigned short pcm_status_reg;
    145 #ifdef __ISAPNP__
    146         struct isapnp_dev *dev;
    147 #ifdef SNDRV_STB
    148         struct isapnp_dev *devtc;
     141#ifdef CONFIG_PNP
     142        struct pnp_dev *dev;
     143#ifdef SNDRV_STB
     144        struct pnp_dev *devtc;
    149145#endif
    150146#endif
    151147};
    152148
    153 static snd_card_t *snd_interwave_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    154 
    155 #ifdef __ISAPNP__
    156 
    157 static struct isapnp_card *snd_interwave_isapnp_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    158 static const struct isapnp_card_id *snd_interwave_isapnp_id[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    159 
    160 #define ISAPNP_INTERWAVE(_va, _vb, _vc, _device, _audio) \
    161         { \
    162                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    163                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), } \
    164         }
    165 #define ISAPNP_INTERWAVE_STB(_va, _vb, _vc, _device, _audio, _tone) \
    166         { \
    167                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    168                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
    169                          ISAPNP_DEVICE_ID(_va, _vb, _vc, _tone), } \
    170         }
    171 
    172 static struct isapnp_card_id snd_interwave_pnpids[] __devinitdata = {
     149static snd_card_t *snd_interwave_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     150
     151#ifdef CONFIG_PNP
     152
     153static struct pnp_card_device_id snd_interwave_pnpids[] __devinitdata = {
    173154#ifndef SNDRV_STB
    174155        /* Gravis UltraSound Plug & Play */
    175         ISAPNP_INTERWAVE('G','R','V',0x0001,0x0000),
     156        { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
    176157        /* STB SoundRage32 */
    177         ISAPNP_INTERWAVE('S','T','B',0x011a,0x0010),
     158        { .id = "STB011a", .devs = { { .id = "STB0010" } } },
    178159        /* MED3210 */
    179         ISAPNP_INTERWAVE('D','X','P',0x3201,0x0010),
     160        { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
    180161        /* Dynasonic Pro */
    181162        /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
    182         ISAPNP_INTERWAVE('C','D','C',0x1111,0x1112),
     163        { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
    183164        /* Panasonic PCA761AW Audio Card */
    184         ISAPNP_INTERWAVE('A','D','V',0x55ff,0x0010),
     165        { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
    185166#else
    186167        /* InterWave STB with TEA6330T */
    187         ISAPNP_INTERWAVE_STB('A','D','V',0x550a,0x0010,0x0015),
    188 #endif
    189         { ISAPNP_CARD_END, }
     168        { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
     169#endif
     170        { .id = "" }
    190171};
    191172
    192 ISAPNP_CARD_TABLE(snd_interwave_pnpids);
    193 
    194 #endif /* __ISAPNP__ */
     173MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
     174
     175#endif /* CONFIG_PNP */
    195176
    196177
     
    239220};
    240221
    241 static int __init snd_interwave_detect_stb(struct snd_interwave *iwcard,
    242                                            snd_gus_card_t * gus, int dev,
    243                                            snd_i2c_bus_t **rbus)
     222static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard,
     223                                              snd_gus_card_t * gus, int dev,
     224                                              snd_i2c_bus_t **rbus)
    244225{
    245226        unsigned long port;
     
    279260#endif
    280261
    281 static int __init snd_interwave_detect(struct snd_interwave *iwcard,
    282                                        snd_gus_card_t * gus,
    283                                        int dev
    284 #ifdef SNDRV_STB
    285                                        , snd_i2c_bus_t **rbus
    286 #endif
    287                                        )
     262static int __devinit snd_interwave_detect(struct snd_interwave *iwcard,
     263                                          snd_gus_card_t * gus,
     264                                          int dev
     265#ifdef SNDRV_STB
     266                                          , snd_i2c_bus_t **rbus
     267#endif
     268                                          )
    288269{
    289270        unsigned long flags;
     
    344325}
    345326
    346 static void snd_interwave_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     327static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    347328{
    348329        struct snd_interwave *iwcard = (struct snd_interwave *) dev_id;
    349330        int loop, max = 5;
     331        int handled = 0;
    350332
    351333        do {
    352334                loop = 0;
    353335                if (inb(iwcard->gus_status_reg)) {
     336                        handled = 1;
    354337                        snd_gus_interrupt(irq, iwcard->gus, regs);
    355338                        loop++;
    356339                }
    357340                if (inb(iwcard->pcm_status_reg) & 0x01) {       /* IRQ bit is set? */
     341                        handled = 1;
    358342                        snd_cs4231_interrupt(irq, iwcard->cs4231, regs);
    359343                        loop++;
    360344                }
    361345        } while (loop && --max > 0);
    362 }
    363 
    364 static void __init snd_interwave_reset(snd_gus_card_t * gus)
     346        return IRQ_RETVAL(handled);
     347}
     348
     349static void __devinit snd_interwave_reset(snd_gus_card_t * gus)
    365350{
    366351        snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
     
    370355}
    371356
    372 static void __init snd_interwave_bank_sizes(snd_gus_card_t * gus, int *sizes)
     357static void __devinit snd_interwave_bank_sizes(snd_gus_card_t * gus, int *sizes)
    373358{
    374359        unsigned int idx;
     
    419404};
    420405
    421 static void __init snd_interwave_detect_memory(snd_gus_card_t * gus)
     406static void __devinit snd_interwave_detect_memory(snd_gus_card_t * gus)
    422407{
    423408        static unsigned int lmc[13] =
     
    522507}
    523508
    524 static void __init snd_interwave_init(int dev, snd_gus_card_t * gus)
     509static void __devinit snd_interwave_init(int dev, snd_gus_card_t * gus)
    525510{
    526511        unsigned long flags;
     
    553538};
    554539
    555 static int __init snd_interwave_mixer(cs4231_t *chip)
     540static int __devinit snd_interwave_mixer(cs4231_t *chip)
    556541{
    557542        snd_card_t *card = chip->card;
     
    601586}
    602587
    603 #ifdef __ISAPNP__
    604 
    605 static int __init snd_interwave_isapnp(int dev, struct snd_interwave *iwcard)
    606 {
    607         const struct isapnp_card_id *id = snd_interwave_isapnp_id[dev];
    608         struct isapnp_card *card = snd_interwave_isapnp_cards[dev];
    609         struct isapnp_dev *pdev;
    610 
    611         iwcard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    612         if (iwcard->dev->active) {
    613                 iwcard->dev = NULL;
     588#ifdef CONFIG_PNP
     589
     590static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
     591                                       struct pnp_card_link *card,
     592                                       const struct pnp_card_device_id *id)
     593{
     594        struct pnp_dev *pdev;
     595        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     596        int err;
     597
     598        iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     599        if (iwcard->dev == NULL) {
     600                kfree(cfg);
    614601                return -EBUSY;
    615602        }
    616603#ifdef SNDRV_STB
    617         iwcard->devtc = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    618         if (iwcard->devtc->active) {
    619                 iwcard->dev = iwcard->devtc = NULL;
     604        iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
     605        if (iwcard->devtc == NULL) {
     606                kfree(cfg);
    620607                return -EBUSY;
    621608        }
     
    623610        /* Synth & Codec initialization */
    624611        pdev = iwcard->dev;
    625         if (pdev->prepare(pdev)<0)
    626                 return -EAGAIN;
     612        pnp_init_resource_table(cfg);
    627613        if (port[dev] != SNDRV_AUTO_PORT) {
    628                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
    629                 isapnp_resource_change(&pdev->resource[1], port[dev] + 0x100, 12);
    630                 isapnp_resource_change(&pdev->resource[2], port[dev] + 0x10c, 4);
     614                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
     615                pnp_resource_change(&cfg->port_resource[1], port[dev] + 0x100, 12);
     616                pnp_resource_change(&cfg->port_resource[2], port[dev] + 0x10c, 4);
    631617        }
    632618        if (dma1[dev] != SNDRV_AUTO_DMA)
    633                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], 1);
     619                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    634620        if (dma2[dev] != SNDRV_AUTO_DMA)
    635                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev], 1);
     621                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    636622        if (dma2[dev] < 0)
    637                 isapnp_resource_change(&pdev->dma_resource[1], 4, 1);
     623                pnp_resource_change(&cfg->dma_resource[1], 4, 1);
    638624        if (irq[dev] != SNDRV_AUTO_IRQ)
    639                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    640         if (pdev->activate(pdev)<0) {
    641                 snd_printk("isapnp configure failure (out of resources?)\n");
    642                 return -EBUSY;
    643         }
    644         if (pdev->resource[0].start + 0x100 != pdev->resource[1].start ||
    645             pdev->resource[0].start + 0x10c != pdev->resource[2].start) {
    646                 snd_printk("isapnp configure failure (wrong ports)\n");
    647                 pdev->deactivate(pdev);
     625                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     626        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     627                snd_printk(KERN_ERR "InterWave - Synth - the requested resources are invalid, using auto config\n");
     628        err = pnp_activate_dev(pdev);
     629        if (err < 0) {
     630                kfree(cfg);
     631                snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
     632                return err;
     633        }
     634        if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
     635            pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
     636                kfree(cfg);
     637                snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
    648638                return -ENOENT;
    649639        }
    650         port[dev] = pdev->resource[0].start;
    651         dma1[dev] = pdev->dma_resource[0].start;
     640        port[dev] = pnp_port_start(pdev, 0);
     641        dma1[dev] = pnp_dma(pdev, 1);
    652642        if (dma2[dev] >= 0)
    653                 dma2[dev] = pdev->dma_resource[1].start;
    654         irq[dev] = pdev->irq_resource[0].start;
     643                dma2[dev] = pnp_dma(pdev, 1);
     644        irq[dev] = pnp_irq(pdev, 0);
    655645        snd_printdd("isapnp IW: sb port=0x%lx, gf1 port=0x%lx, codec port=0x%lx\n",
    656                                 pdev->resource[0].start,
    657                                 pdev->resource[1].start,
    658                                 pdev->resource[2].start);
     646                                pnp_port_start(pdev, 0),
     647                                pnp_port_start(pdev, 1),
     648                                pnp_port_start(pdev, 2));
    659649        snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
    660650#ifdef SNDRV_STB
    661651        /* Tone Control initialization */
    662652        pdev = iwcard->devtc;
    663         if (pdev->prepare(pdev)<0) {
    664                 iwcard->dev->deactivate(iwcard->dev);
    665                 return -EAGAIN;
    666         }
     653        pnp_init_resource_table(cfg);
    667654        if (port_tc[dev] != SNDRV_AUTO_PORT)
    668                 isapnp_resource_change(&pdev->resource[0], port_tc[dev], 1);
    669         if (pdev->activate(pdev)<0) {
    670                 snd_printk("Tone Control isapnp configure failure (out of resources?)\n");
    671                 iwcard->dev->deactivate(iwcard->dev);
    672                 return -EBUSY;
    673         }
    674         port_tc[dev] = pdev->resource[0].start;
     655                pnp_resource_change(&cfg->port_resource[0], port_tc[dev], 1);
     656        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     657                snd_printk(KERN_ERR "InterWave - ToneControl - the requested resources are invalid, using auto config\n");
     658        err = pnp_activate_dev(pdev);
     659        if (err < 0) {
     660                kfree(cfg);
     661                snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
     662                return err;
     663        }
     664        port_tc[dev] = pnp_port_start(pdev, 0);
    675665        snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
    676666#endif
     667        kfree(cfg);
    677668        return 0;
    678669}
    679 
    680 static void snd_interwave_deactivate(struct snd_interwave *iwcard)
    681 {
    682         if (iwcard->dev) {
    683                 iwcard->dev->deactivate(iwcard->dev);
    684                 iwcard->dev = NULL;
    685         }
    686 #ifdef SNDRV_STB
    687         if (iwcard->devtc) {
    688                 iwcard->devtc->deactivate(iwcard->devtc);
    689                 iwcard->devtc = NULL;
    690         }
    691 #endif
    692 }
    693 
    694 #endif /* __ISAPNP__ */
     670#endif /* CONFIG_PNP */
    695671
    696672static void snd_interwave_free(snd_card_t *card)
     
    700676        if (iwcard == NULL)
    701677                return;
    702 #ifdef __ISAPNP__
    703         snd_interwave_deactivate(iwcard);
    704 #endif
    705678#ifdef SNDRV_STB
    706679        if (iwcard->i2c_res) {
     
    713686}
    714687
    715 static int __init snd_interwave_probe(int dev)
     688static int __devinit snd_interwave_probe(int dev, struct pnp_card_link *pcard,
     689                                         const struct pnp_card_device_id *pid)
    716690{
    717691        static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
     
    737711        iwcard->irq = -1;
    738712        card->private_free = snd_interwave_free;
    739 #ifdef __ISAPNP__
    740         if (isapnp[dev] && snd_interwave_isapnp(dev, iwcard)) {
     713#ifdef CONFIG_PNP
     714        if (isapnp[dev] && snd_interwave_pnp(dev, iwcard, pcard, pid)) {
    741715                snd_card_free(card);
    742716                return -ENODEV;
     
    892866        iwcard->cs4231 = cs4231;
    893867        iwcard->gus = gus;
    894         snd_interwave_cards[dev++] = card;
     868        if (pcard)
     869                pnp_set_card_drvdata(pcard, card);
     870        else
     871                snd_interwave_legacy[dev++] = card;
    895872        return 0;
    896873}
    897874
    898 static int __init snd_interwave_probe_legacy_port(unsigned long xport)
     875static int __devinit snd_interwave_probe_legacy_port(unsigned long xport)
    899876{
    900877        static int dev;
     
    904881                if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
    905882                        continue;
    906 #ifdef __ISAPNP__
     883#ifdef CONFIG_PNP
    907884                if (isapnp[dev])
    908885                        continue;
    909886#endif
    910887                port[dev] = xport;
    911                 res = snd_interwave_probe(dev);
     888                res = snd_interwave_probe(dev, NULL, NULL);
    912889                if (res < 0)
    913890                        port[dev] = SNDRV_AUTO_PORT;
     
    917894}
    918895
    919 #ifdef __ISAPNP__
    920 
    921 static int __init snd_interwave_isapnp_detect(struct isapnp_card *card,
    922                                               const struct isapnp_card_id *id)
     896#ifdef CONFIG_PNP
     897
     898static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *card,
     899                                           const struct pnp_card_device_id *id)
    923900{
    924901        static int dev;
     
    928905                if (!enable[dev] || !isapnp[dev])
    929906                        continue;
    930                 snd_interwave_isapnp_cards[dev] = card;
    931                 snd_interwave_isapnp_id[dev] = id;
    932                 res = snd_interwave_probe(dev);
     907                res = snd_interwave_probe(dev, card, id);
    933908                if (res < 0)
    934909                        return res;
     
    940915}
    941916
    942 #endif /* __ISAPNP__ */
     917static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard)
     918{
     919        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     920
     921        snd_card_disconnect(card);
     922        snd_card_free_in_thread(card);
     923}
     924
     925static struct pnp_card_driver interwave_pnpc_driver = {
     926        .flags = PNP_DRIVER_RES_DISABLE,
     927        .name = "interwave",
     928        .id_table = snd_interwave_pnpids,
     929        .probe = snd_interwave_pnp_detect,
     930        .remove = __devexit_p(snd_interwave_pnp_remove),
     931};
     932
     933#endif /* CONFIG_PNP */
    943934
    944935static int __init alsa_card_interwave_init(void)
     
    951942                if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
    952943                        continue;
    953 #ifdef __ISAPNP__
     944#ifdef CONFIG_PNP
    954945                if (isapnp[dev])
    955946                        continue;
    956947#endif
    957                 if (!snd_interwave_probe(dev)) {
     948                if (!snd_interwave_probe(dev, NULL, NULL)) {
    958949                        cards++;
    959950                        continue;
     
    965956        /* legacy auto configured cards */
    966957        cards += snd_legacy_auto_probe(possible_ports, snd_interwave_probe_legacy_port);
    967 #ifdef __ISAPNP__
     958#ifdef CONFIG_PNP
    968959        /* ISA PnP cards */
    969         cards += isapnp_probe_cards(snd_interwave_pnpids, snd_interwave_isapnp_detect);
     960        cards += pnp_register_card_driver(&interwave_pnpc_driver);
    970961#endif
    971962
    972963        if (!cards) {
     964#ifdef CONFIG_PNP
     965                pnp_unregister_card_driver(&interwave_pnpc_driver);
     966#endif
    973967#ifdef MODULE
    974968                printk(KERN_ERR "InterWave soundcard not found or device busy\n");
     
    983977        int dev;
    984978
     979#ifdef CONFIG_PNP
     980        /* PnP cards first */
     981        pnp_unregister_card_driver(&interwave_pnpc_driver);
     982#endif
    985983        for (dev = 0; dev < SNDRV_CARDS; dev++)
    986                 snd_card_free(snd_interwave_cards[dev]);
     984                snd_card_free(snd_interwave_legacy[dev]);
    987985}
    988986
     
    10201018               get_option(&str,&pcm_channels[nr_dev]) == 2 &&
    10211019               get_option(&str,&effect[nr_dev]) == 2);
    1022 #ifdef __ISAPNP__
     1020#ifdef CONFIG_PNP
    10231021        if (pnp != INT_MAX)
    10241022                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/opl3sa2.c

    r224 r246  
    2525#include <linux/pm.h>
    2626#include <linux/slab.h>
    27 #ifndef LINUX_ISAPNP_H
    28 #include <linux/isapnp.h>
    29 #define isapnp_card pci_bus
    30 #define isapnp_dev pci_dev
    31 #endif
     27#include <linux/pnp.h>
    3228#include <sound/core.h>
    3329#include <sound/cs4231.h>
     
    5248static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    5349static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
    54 #ifdef __ISAPNP__
     50#ifdef CONFIG_PNP
    5551#ifdef TARGET_OS2
    5652static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    8278MODULE_PARM_DESC(enable, "Enable OPL3-SA soundcard.");
    8379MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    84 #ifdef __ISAPNP__
     80#ifdef CONFIG_PNP
    8581MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    86 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     82MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
    8783MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
    8884#endif
     
    156152        snd_rawmidi_t *rmidi;
    157153        cs4231_t *cs4231;
    158 #ifdef __ISAPNP__
    159         struct isapnp_dev *dev;
     154#ifdef CONFIG_PNP
     155        struct pnp_dev *dev;
    160156#endif
    161157        unsigned char ctlregs[0x20];
     
    170166};
    171167
    172 static snd_card_t *snd_opl3sa2_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    173 
    174 #ifdef __ISAPNP__
    175 
    176 static struct isapnp_card *snd_opl3sa2_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    177 static const struct isapnp_card_id *snd_opl3sa2_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    178 
    179 #ifdef TARGET_OS2
    180 #define ISAPNP_OPL3SA2(_va, _vb, _vc, _device, _function) \
    181         { \
    182                 0, ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    183                 { ISAPNP_DEVICE_ID(_va, _vb, _vc, _function), } \
    184         }
    185 #else
    186 #define ISAPNP_OPL3SA2(_va, _vb, _vc, _device, _function) \
    187         { \
    188                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    189                 devs : { ISAPNP_DEVICE_ID(_va, _vb, _vc, _function), } \
    190         }
    191 #endif
    192 
    193 static struct isapnp_card_id snd_opl3sa2_pnpids[] __devinitdata = {
     168static snd_card_t *snd_opl3sa2_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     169
     170#ifdef CONFIG_PNP
     171
     172static struct pnp_card_device_id snd_opl3sa2_pnpids[] __devinitdata = {
    194173        /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */
    195         ISAPNP_OPL3SA2('Y','M','H',0x0020,0x0021),
     174        { .id = "YMH0020", .devs = { { "YMH0021" } } },
    196175        /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */
    197         ISAPNP_OPL3SA2('Y','M','H',0x0030,0x0021),
     176        { .id = "YMH0030", .devs = { { "YMH0021" } } },
    198177        /* Yamaha OPL3-SA2 */
    199         ISAPNP_OPL3SA2('Y','M','H',0x0800,0x0021),
     178        { .id = "YMH0800", .devs = { { "YMH0021" } } },
    200179        /* NeoMagic MagicWave 3DX */
    201         ISAPNP_OPL3SA2('N','M','X',0x2200,0x2210),
     180        { .id = "NMX2200", .devs = { { "YMH2210" } } },
    202181        /* --- */
    203         { ISAPNP_CARD_END, }    /* end */
     182        { .id = "" }    /* end */
    204183};
    205184
    206 ISAPNP_CARD_TABLE(snd_opl3sa2_pnpids);
    207 
    208 #endif /* __ISAPNP__ */
     185MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpids);
     186
     187#endif /* CONFIG_PNP */
    209188
    210189
     
    327306}
    328307
    329 static int snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     308static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    330309{
    331310        unsigned short status;
    332311        opl3sa2_t *chip = dev_id;
     312        int handled = 0;
    333313
    334314        if (chip == NULL || chip->card == NULL)
    335                 return 0;
     315                return IRQ_NONE;
    336316
    337317        status = snd_opl3sa2_read(chip, OPL3SA2_IRQ_STATUS);
    338318
    339         if (status & 0x20)
     319        if (status & 0x20) {
     320                handled = 1;
    340321                snd_opl3_interrupt(chip->synth);
    341 
    342         if ((status & 0x10) && chip->rmidi != NULL)
     322        }
     323
     324        if ((status & 0x10) && chip->rmidi != NULL) {
     325                handled = 1;
    343326                snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
    344 
    345         if (status & 0x07)      /* TI,CI,PI */
     327        }
     328
     329        if (status & 0x07) {    /* TI,CI,PI */
     330                handled = 1;
    346331                snd_cs4231_interrupt(irq, chip->cs4231, regs);
     332        }
    347333
    348334        if (status & 0x40) { /* hardware volume change */
     335                handled = 1;
    349336                /* reading from Master Lch register at 0x07 clears this bit */
    350337                snd_opl3sa2_read(chip, OPL3SA2_MASTER_RIGHT);
     
    355342                }
    356343        }
    357         return 0;
     344        return IRQ_RETVAL(handled);
    358345}
    359346
     
    605592#endif /* CONFIG_PM */
    606593
    607 #ifdef __ISAPNP__
    608 static int __init snd_opl3sa2_isapnp(int dev, opl3sa2_t *chip)
    609 {
    610         const struct isapnp_card_id *id = snd_opl3sa2_isapnp_id[dev];
    611         struct isapnp_card *card = snd_opl3sa2_isapnp_cards[dev];
    612         struct isapnp_dev *pdev;
    613 
    614         chip->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    615         if (chip->dev->active) {
    616                 chip->dev = NULL;
     594#ifdef CONFIG_PNP
     595static int __init snd_opl3sa2_pnp(int dev, opl3sa2_t *chip,
     596                                  struct pnp_card_link *card,
     597                                  const struct pnp_card_device_id *id)
     598{
     599        struct pnp_dev *pdev;
     600        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     601        int err;
     602
     603        if (!cfg)
     604                return -ENOMEM;
     605        pdev = chip->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     606        if (chip->dev == NULL) {
     607                kfree(cfg);
    617608                return -EBUSY;
    618609        }
    619610        /* PnP initialization */
    620         pdev = chip->dev;
    621         if (pdev->prepare(pdev)<0)
    622                 return -EAGAIN;
     611        pnp_init_resource_table(cfg);
    623612        if (sb_port[dev] != SNDRV_AUTO_PORT)
    624                 isapnp_resource_change(&pdev->resource[0], sb_port[dev], 16);
    625         if (wss_port[dev] != SNDRV_AUTO_PORT)
    626                 isapnp_resource_change(&pdev->resource[1], wss_port[dev], 8);
     613                pnp_resource_change(&cfg->port_resource[0], sb_port[dev], 16);
     614                pnp_resource_change(&cfg->port_resource[1], wss_port[dev], 8);
    627615        if (fm_port[dev] != SNDRV_AUTO_PORT)
    628                 isapnp_resource_change(&pdev->resource[2], fm_port[dev], 4);
     616                pnp_resource_change(&cfg->port_resource[2], fm_port[dev], 4);
    629617        if (midi_port[dev] != SNDRV_AUTO_PORT)
    630                 isapnp_resource_change(&pdev->resource[3], midi_port[dev], 2);
     618                pnp_resource_change(&cfg->port_resource[3], midi_port[dev], 2);
    631619        if (port[dev] != SNDRV_AUTO_PORT)
    632                 isapnp_resource_change(&pdev->resource[4], port[dev], 2);
     620                pnp_resource_change(&cfg->port_resource[4], port[dev], 2);
    633621        if (dma1[dev] != SNDRV_AUTO_DMA)
    634                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], 1);
     622                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    635623        if (dma2[dev] != SNDRV_AUTO_DMA)
    636                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev], 1);
     624                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    637625        if (irq[dev] != SNDRV_AUTO_IRQ)
    638                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    639         if (pdev->activate(pdev)<0) {
    640                 snd_printk("isapnp configure failure (out of resources?)\n");
     626                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     627        err = pnp_manual_config_dev(pdev, cfg, 0);
     628        if (err < 0)
     629                snd_printk(KERN_ERR "PnP manual resources are invalid, using auto config\n");
     630        err = pnp_activate_dev(pdev);
     631        if (err < 0) {
     632                kfree(cfg);
     633                snd_printk(KERN_ERR "PnP configure failure (out of resources?)\n");
    641634                return -EBUSY;
    642635        }
    643         sb_port[dev] = pdev->resource[0].start;
    644         wss_port[dev] = pdev->resource[1].start;
    645         fm_port[dev] = pdev->resource[2].start;
    646         midi_port[dev] = pdev->resource[3].start;
    647         port[dev] = pdev->resource[4].start;
    648         dma1[dev] = pdev->dma_resource[0].start;
    649         dma2[dev] = pdev->dma_resource[1].start;
    650         irq[dev] = pdev->irq_resource[0].start;
    651         snd_printdd("isapnp OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n",
     636        sb_port[dev] = pnp_port_start(pdev, 0);
     637        wss_port[dev] = pnp_port_start(pdev, 1);
     638        fm_port[dev] = pnp_port_start(pdev, 2);
     639        midi_port[dev] = pnp_port_start(pdev, 3);
     640        port[dev] = pnp_port_start(pdev, 4);
     641        dma1[dev] = pnp_dma(pdev, 0);
     642        dma2[dev] = pnp_dma(pdev, 1);
     643        irq[dev] = pnp_irq(pdev, 0);
     644        snd_printdd("PnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n",
    652645                sb_port[dev], wss_port[dev], fm_port[dev], midi_port[dev]);
    653         snd_printdd("isapnp OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n",
     646        snd_printdd("PnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n",
    654647                port[dev], dma1[dev], dma2[dev], irq[dev]);
    655         return 0;
    656 }
    657 
    658 static void snd_opl3sa2_deactivate(opl3sa2_t *chip)
    659 {
    660         if (chip->dev) {
    661                 chip->dev->deactivate(chip->dev);
    662                 chip->dev = NULL;
    663         }
    664 }
    665 #endif /* __ISAPNP__ */
     648        kfree(cfg);
     649        return 0;
     650}
     651#endif /* CONFIG_PNP */
    666652
    667653static int snd_opl3sa2_free(opl3sa2_t *chip)
    668654{
    669 #ifdef __ISAPNP__
    670         snd_opl3sa2_deactivate(chip);
    671 #endif
    672655#ifdef CONFIG_PM
    673656        if (chip->pm_dev)
     
    690673}
    691674
    692 static int __init snd_opl3sa2_probe(int dev)
     675static int __devinit snd_opl3sa2_probe(int dev,
     676                                       struct pnp_card_link *pcard,
     677                                       const struct pnp_card_device_id *pid)
    693678{
    694679        int xirq, xdma1, xdma2;
     
    702687        int err;
    703688
    704 #ifdef __ISAPNP__
     689#ifdef CONFIG_PNP
    705690        if (!isapnp[dev]) {
    706691#endif
     
    721706                        return -EINVAL;
    722707                }
    723 #ifdef __ISAPNP__
     708#ifdef CONFIG_PNP
    724709        }
    725710#endif
     
    737722        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
    738723                goto __error;
    739 #ifdef __ISAPNP__
    740         if (isapnp[dev] && (err = snd_opl3sa2_isapnp(dev, chip)) < 0)
     724#ifdef CONFIG_PNP
     725        if (isapnp[dev] && (err = snd_opl3sa2_pnp(dev, chip, pcard, pid)) < 0)
    741726                goto __error;
    742727#endif
     
    807792                goto __error;
    808793
    809         snd_opl3sa2_cards[dev] = card;
     794        if (pcard)
     795                pnp_set_card_drvdata(pcard, card);
     796        else
     797                snd_opl3sa2_legacy[dev] = card;
    810798        return 0;
    811799
     
    815803}
    816804
    817 #ifdef __ISAPNP__
    818 static int __init snd_opl3sa2_isapnp_detect(struct isapnp_card *card,
    819                                             const struct isapnp_card_id *id)
     805#ifdef CONFIG_PNP
     806static int __devinit snd_opl3sa2_pnp_detect(struct pnp_card_link *card,
     807                                            const struct pnp_card_device_id *id)
    820808{
    821809        static int dev;
     
    823811
    824812        for ( ; dev < SNDRV_CARDS; dev++) {
    825                 if (!enable[dev])
     813                if (!enable[dev] && !isapnp[dev])
    826814                        continue;
    827                 snd_opl3sa2_isapnp_cards[dev] = card;
    828                 snd_opl3sa2_isapnp_id[dev] = id;
    829                 res = snd_opl3sa2_probe(dev);
     815                res = snd_opl3sa2_probe(dev, card, id);
    830816                if (res < 0)
    831817                        return res;
     
    835821        return -ENODEV;
    836822}
    837 #endif /* __ISAPNP__ */
     823
     824static void __devexit snd_opl3sa2_pnp_remove(struct pnp_card_link * pcard)
     825{
     826        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     827       
     828        snd_card_disconnect(card);
     829        snd_card_free_in_thread(card);
     830}
     831
     832static struct pnp_card_driver opl3sa2_pnpc_driver = {
     833        .flags = PNP_DRIVER_RES_DISABLE,
     834        .name = "opl3sa2",
     835        .id_table = snd_opl3sa2_pnpids,
     836        .probe = snd_opl3sa2_pnp_detect,
     837        .remove = __devexit_p(snd_opl3sa2_pnp_remove),
     838};
     839#endif /* CONFIG_PNP */
    838840
    839841static int __init alsa_card_opl3sa2_init(void)
     
    844846                if (!enable[dev])
    845847                        continue;
    846 #ifdef __ISAPNP__
     848#ifdef CONFIG_PNP
    847849                if (isapnp[dev])
    848850                        continue;
    849851#endif
    850                 if (snd_opl3sa2_probe(dev) >= 0)
     852                if (snd_opl3sa2_probe(dev, NULL, NULL) >= 0)
    851853                        cards++;
    852854        }
    853 #ifdef __ISAPNP__
    854         cards += isapnp_probe_cards(snd_opl3sa2_pnpids, snd_opl3sa2_isapnp_detect);
     855#ifdef CONFIG_PNP
     856        cards += pnp_register_card_driver(&opl3sa2_pnpc_driver);
    855857#endif
    856858        if (!cards) {
    857859#ifdef MODULE
    858                 printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n");
     860                snd_printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n");
     861#endif
     862#ifdef CONFIG_PNP
     863                pnp_unregister_card_driver(&opl3sa2_pnpc_driver);
    859864#endif
    860865                return -ENODEV;
     
    867872        int idx;
    868873
     874#ifdef CONFIG_PNP
     875        /* PnP cards first */
     876        pnp_unregister_card_driver(&opl3sa2_pnpc_driver);
     877#endif
    869878        for (idx = 0; idx < SNDRV_CARDS; idx++)
    870                 snd_card_free(snd_opl3sa2_cards[idx]);
     879                snd_card_free(snd_opl3sa2_legacy[idx]);
    871880}
    872881
     
    901910               get_option(&str,&dma2[nr_dev]) == 2 &&
    902911               get_option(&str,&opl3sa3_ymode[nr_dev]) == 2);
    903 #ifdef __ISAPNP__
     912#ifdef CONFIG_PNP
    904913        if (pnp != INT_MAX)
    905914                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/opti9xx/opti92x-ad1848.c

    r231 r246  
    3030#include <linux/init.h>
    3131#include <linux/slab.h>
    32 #ifndef LINUX_ISAPNP_H
    33 #include <linux/isapnp.h>
    34 #define isapnp_card pci_bus
    35 #define isapnp_dev pci_dev
    36 #endif
     32#include <linux/pnp.h>
    3733#include <sound/core.h>
    3834#ifdef CS4231
     
    4844#include <sound/mpu401.h>
    4945#include <sound/opl3.h>
     46#ifdef USE_OPL4
     47#ifndef OPTi93X
     48#include "opl4.h" /* <sound/opl4.h> */
     49#endif
     50#endif
    5051#define SNDRV_LEGACY_FIND_FREE_IRQ
    5152#define SNDRV_LEGACY_FIND_FREE_DMA
     
    268269        int mpu_irq;
    269270
    270 #if defined(OPTi93X)
    271         opti93x_t *opti93x;
    272 #elif defined(CS4231)
    273         cs4231_t *cs4231;
    274 #else
    275         ad1848_t *ad1848;
    276 #endif  /* AD1848 */
    277         snd_rawmidi_t *rmidi;
    278 #ifdef __ISAPNP__
    279         struct isapnp_dev *dev;
    280         struct isapnp_dev *devmpu;
    281 #endif  /* __ISAPNP__ */
     271#ifdef CONFIG_PNP
     272        struct pnp_dev *dev;
     273        struct pnp_dev *devmpu;
     274#endif  /* CONFIG_PNP */
    282275};
    283276
    284 static snd_card_t *snd_opti9xx_card = SNDRV_DEFAULT_PTR1;
    285 
    286 #ifdef __ISAPNP__
     277static int snd_opti9xx_first_hit = 1;
     278static snd_card_t *snd_opti9xx_legacy = SNDRV_DEFAULT_PTR1;
     279
     280#ifdef CONFIG_PNP
    287281
    288282#define ISAPNP_OPTI9XX(_va, _vb, _vc, _device, _fa, _fb, _fc, _audio, _mpu401) \
     
    293287        }
    294288
    295 static struct isapnp_card_id snd_card_opti9xx_pnpids[] = {
     289static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
    296290#ifndef OPTi93X
    297291        /* OPTi 82C924 */
    298         ISAPNP_OPTI9XX('O','P','T',0x0924,'O','P','T',0x0000,0x0002),
     292        { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
    299293        /* OPTi 82C925 */
    300         ISAPNP_OPTI9XX('O','P','T',0x0925,'O','P','T',0x9250,0x0002),
     294        { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
    301295#else
    302296        /* OPTi 82C931/3 */
    303         ISAPNP_OPTI9XX('O','P','T',0x0931,'O','P','T',0x9310,0x0002),
     297        { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
    304298#endif  /* OPTi93X */
    305         { ISAPNP_CARD_END, }
     299        { .id = "" }
    306300};
    307301
    308 ISAPNP_CARD_TABLE(snd_card_opti9xx_pnpids);
    309 
    310 #endif  /* __ISAPNP__ */
     302MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
     303
     304#endif  /* CONFIG_PNP */
    311305
    312306#ifdef OPTi93X
     
    334328}
    335329
    336 static int __init snd_opti9xx_init(opti9xx_t *chip, unsigned short hardware)
     330static int __devinit snd_opti9xx_init(opti9xx_t *chip, unsigned short hardware)
    337331{
    338332        static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
     
    479473
    480474
    481 static int __init snd_opti9xx_configure(opti9xx_t *chip)
     475static int __devinit snd_opti9xx_configure(opti9xx_t *chip)
    482476{
    483477        unsigned char wss_base_bits;
     
    976970        {
    977971                unsigned int what = 0;
    978                 snd_pcm_substream_t *s = substream;
    979                 do {
     972                struct list_head *pos;
     973                snd_pcm_substream_t *s;
     974                snd_pcm_group_for_each(pos, substream) {
     975                        s = snd_pcm_group_substream_entry(pos);
    980976                        if (s == chip->playback_substream) {
    981977                                what |= OPTi93X_PLAYBACK_ENABLE;
     
    985981                                snd_pcm_trigger_done(s, substream);
    986982                        }
    987                         s = s->link_next;
    988                 } while (s != substream);
     983                }
    989984                spin_lock(&chip->lock);
    990985                if (cmd == SNDRV_PCM_TRIGGER_START) {
     
    11321127}
    11331128
    1134 void snd_opti93x_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    1135 {
    1136         opti93x_t *codec = snd_magic_cast(opti93x_t, dev_id, return);
     1129irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     1130{
     1131        opti93x_t *codec = snd_magic_cast(opti93x_t, dev_id, return IRQ_NONE);
    11371132        unsigned char status;
    11381133
     
    11451140        }
    11461141        outb(0x00, OPTi93X_PORT(codec, STATUS));
     1142        return IRQ_HANDLED;
    11471143}
    11481144
     
    16701666#endif /* OPTi93X */
    16711667
    1672 static int __init snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
     1668static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
    16731669{
    16741670        int i, err;
     
    17161712}
    17171713
    1718 #ifdef __ISAPNP__
    1719 static int __init snd_card_opti9xx_isapnp(opti9xx_t *chip)
    1720 {
    1721         struct isapnp_dev *pdev = NULL;
    1722         const struct isapnp_card_id *pid = snd_card_opti9xx_pnpids-1;
    1723         static struct isapnp_card *card = NULL;
    1724 
    1725       __again:
    1726         while (1) {
    1727                 pid++;
    1728                 if (pid->card_vendor == 0)
    1729                         return -ENODEV;
    1730                 if ((card = isapnp_find_card(pid->card_vendor, pid->card_device, card)))
    1731                         break;
    1732         }
    1733         if (card == NULL)
    1734                 return -ENODEV;
    1735 
    1736         chip->dev = isapnp_find_dev(card, pid->devs[0].vendor, pid->devs[0].function, NULL);
    1737         if (chip->dev == NULL)
    1738                 goto __again;
    1739 
    1740         chip->devmpu = isapnp_find_dev(card, pid->devs[1].vendor, pid->devs[1].function, NULL);
     1714#ifdef CONFIG_PNP
     1715static int __devinit snd_card_opti9xx_pnp(opti9xx_t *chip, struct pnp_card_link *card,
     1716                                          const struct pnp_card_device_id *pid)
     1717{
     1718        struct pnp_dev *pdev;
     1719        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
     1720        int err;
     1721
     1722        chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
     1723        if (chip->dev == NULL) {
     1724                kfree(cfg);
     1725                return -EBUSY;
     1726        }
     1727        chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
    17411728
    17421729        pdev = chip->dev;
    1743         if (pdev->prepare(pdev) < 0)
    1744                 return -EAGAIN;
     1730        pnp_init_resource_table(cfg);
    17451731
    17461732#ifdef OPTi93X
    17471733        if (port != SNDRV_AUTO_PORT)
    1748                 isapnp_resource_change(&pdev->resource[0], port + 4, 4);
     1734                pnp_resource_change(&cfg->port_resource[0], port + 4, 4);
    17491735#else
    1750         if ((pid->card_device != ISAPNP_DEVICE(0x0924)) && (port != SNDRV_AUTO_PORT))
    1751                 isapnp_resource_change(&pdev->resource[1], port, 4);
     1736        if (pid->driver_data != 0x0924 && port != SNDRV_AUTO_PORT)
     1737                pnp_resource_change(&cfg->port_resource[1], port, 4);
    17521738#endif  /* OPTi93X */
    17531739        if (irq != SNDRV_AUTO_IRQ)
    1754                 isapnp_resource_change(&pdev->irq_resource[0], irq, 1);
     1740                pnp_resource_change(&cfg->irq_resource[0], irq, 1);
    17551741        if (dma1 != SNDRV_AUTO_DMA)
    1756                 isapnp_resource_change(&pdev->dma_resource[0], dma1, 1);
     1742                pnp_resource_change(&cfg->dma_resource[0], dma1, 1);
    17571743#if defined(CS4231) || defined(OPTi93X)
    17581744        if (dma2 != SNDRV_AUTO_DMA)
    1759                 isapnp_resource_change(&pdev->dma_resource[1], dma2, 1);
     1745                pnp_resource_change(&cfg->dma_resource[1], dma2, 1);
    17601746#endif  /* CS4231 || OPTi93X */
    17611747        if (fm_port != SNDRV_AUTO_PORT)
    1762                 isapnp_resource_change(&pdev->resource[1], fm_port, 4);
    1763 
    1764         if (pdev->activate(pdev) < 0) {
    1765                 snd_printk("AUDIO isapnp configure failure\n");
    1766                 return -EBUSY;
     1748                pnp_resource_change(&cfg->port_resource[1], fm_port, 4);
     1749
     1750        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     1751                snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
     1752        err = pnp_activate_dev(pdev);
     1753        if (err < 0) {
     1754                snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
     1755                kfree(cfg);
     1756                return err;
    17671757        }
    17681758
    17691759#ifdef OPTi93X
    1770         port = pdev->resource[0].start - 4;
    1771         fm_port = pdev->resource[1].start;
     1760        port = pnp_port_start(pdev, 0) - 4;
     1761        fm_port = pnp_port_start(pdev, 1);
    17721762#else
    1773         if (pid->card_device != ISAPNP_DEVICE(0x0924))
    1774                 port = pdev->resource[1].start;
    1775         fm_port = pdev->resource[2].start;
     1763        if (pid->driver_data != 0x0924)
     1764                port = pnp_port_start(pdev, 1);
     1765        fm_port = pnp_port_start(pdev, 2);
    17761766#endif  /* OPTi93X */
    1777         irq = pdev->irq_resource[0].start;
    1778         dma1 = pdev->dma_resource[0].start;
     1767        irq = pnp_irq(pdev, 0);
     1768        dma1 = pnp_dma(pdev, 0);
    17791769#if defined(CS4231) || defined(OPTi93X)
    1780         dma2 = pdev->dma_resource[1].start;
     1770        dma2 = pnp_dma(pdev, 1);
    17811771#endif  /* CS4231 || OPTi93X */
    17821772
    17831773        pdev = chip->devmpu;
    1784         if (pdev == NULL || pdev->prepare(pdev) < 0) {
    1785                 mpu_port = -1;
    1786                 chip->devmpu = NULL;
    1787                 return pid->card_device;
    1788         }
    1789 
    1790         if (mpu_port != SNDRV_AUTO_PORT)
    1791                 isapnp_resource_change(&pdev->resource[0], mpu_port, 2);
    1792         if (mpu_irq != SNDRV_AUTO_IRQ)
    1793                 isapnp_resource_change(&pdev->irq_resource[0], mpu_irq, 1);
    1794 
    1795         if (pdev->activate(pdev) < 0) {
    1796                 snd_printk("MPU-401 isapnp configure failure\n");
    1797                 mpu_port = -1;
    1798                 chip->devmpu = NULL;
    1799         } else {
    1800                 mpu_port = pdev->resource[0].start;
    1801                 mpu_irq = pdev->irq_resource[0].start;
    1802         }
    1803         return pid->card_device;
    1804 }
    1805 
    1806 static void snd_card_opti9xx_deactivate(opti9xx_t *chip)
    1807 {
    1808         if (chip->dev)
    1809                 chip->dev->deactivate(chip->dev);
    1810         if (chip->devmpu)
    1811                 chip->devmpu->deactivate(chip->devmpu);
    1812 }
    1813 #endif  /* __ISAPNP__ */
     1774        if (pdev) {
     1775                pnp_init_resource_table(cfg);
     1776
     1777                if (mpu_port != SNDRV_AUTO_PORT)
     1778                        pnp_resource_change(&cfg->port_resource[0], mpu_port, 2);
     1779                if (mpu_irq != SNDRV_AUTO_IRQ)
     1780                        pnp_resource_change(&cfg->irq_resource[0], mpu_irq, 1);
     1781
     1782                if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     1783                        snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
     1784                err = pnp_activate_dev(pdev);
     1785                if (err < 0) {
     1786                        snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
     1787                        mpu_port = -1;
     1788                        chip->devmpu = NULL;
     1789                } else {
     1790                        mpu_port = pnp_port_start(pdev, 0);
     1791                        mpu_irq = pnp_irq(pdev, 0);
     1792                }
     1793        }
     1794        kfree(cfg);
     1795        return pid->driver_data;
     1796}
     1797#endif  /* CONFIG_PNP */
    18141798
    18151799#if 0
    1816 static int __init snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
    1817                                              snd_card_t *card)
     1800static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
     1801                                                snd_card_t *card)
    18181802{
    18191803        int error, i, pnp = 0;
    18201804
    1821 #ifdef __ISAPNP__
     1805#ifdef CONFIG_PNP
    18221806        pnp = chip->dev != NULL;
    1823 #endif  /* __ISAPNP__ */
     1807#endif  /* CONFIG_PNP */
    18241808
    18251809#ifndef OPTi93X
     
    19151899       
    19161900        if (chip) {
    1917 #ifdef __ISAPNP__
    1918                 snd_card_opti9xx_deactivate(chip);
    1919 #endif  /* __ISAPNP__ */
    19201901                if (chip->res_mc_base) {
    19211902                        release_resource(chip->res_mc_base);
     
    19251906}
    19261907
    1927 static int __init snd_card_opti9xx_probe(void)
     1908static int __devinit snd_card_opti9xx_probe(struct pnp_card_link *pcard,
     1909                                            const struct pnp_card_device_id *pid)
    19281910{
    19291911        static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
     
    19531935        snd_rawmidi_t *rmidi;
    19541936        snd_hwdep_t *synth;
    1955 #ifdef __ISAPNP__
     1937#ifdef CONFIG_PNP
    19561938        int hw;
    1957 #endif  /* __ISAPNP__ */
    1958 
     1939#endif  /* CONFIG_PNP */
     1940
     1941        if (pcard && !snd_opti9xx_first_hit)
     1942                return -EBUSY;
    19591943        if (!(card = snd_card_new(index, id, THIS_MODULE,
    19601944                                  sizeof(opti9xx_t))))
     
    19631947        chip = (opti9xx_t *)card->private_data;
    19641948
    1965 #ifdef __ISAPNP__
    1966         if (isapnp && (hw = snd_card_opti9xx_isapnp(chip)) > 0) {
     1949#ifdef CONFIG_PNP
     1950        if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {
    19671951                switch (hw) {
    1968                 case ISAPNP_DEVICE(0x0924):
     1952                case 0x0924:
    19691953                        hw = OPTi9XX_HW_82C924;
    19701954                        break;
    1971                 case ISAPNP_DEVICE(0x0925):
     1955                case 0x0925:
    19721956                        hw = OPTi9XX_HW_82C925;
    19731957                        break;
    1974                 case ISAPNP_DEVICE(0x0931):
     1958                case 0x0931:
    19751959                        hw = OPTi9XX_HW_82C931;
    19761960                        break;
     
    19871971                        chip->mc_base -= 0x80;
    19881972        } else {
    1989 #endif  /* __ISAPNP__ */
     1973#endif  /* CONFIG_PNP */
    19901974                if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {
    19911975                        snd_card_free(card);
    19921976                        return error;
    19931977                }
    1994 #ifdef __ISAPNP__
    1995         }
    1996 #endif  /* __ISAPNP__ */
     1978#ifdef CONFIG_PNP
     1979        }
     1980#endif  /* CONFIG_PNP */
    19971981
    19981982        if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) {
     
    20111995#endif
    20121996
    2013 #ifdef __ISAPNP__
     1997#ifdef CONFIG_PNP
    20141998        if (!isapnp) {
    20151999#endif
     
    20592043#endif
    20602044
    2061 #ifdef __ISAPNP__
     2045#ifdef CONFIG_PNP
    20622046        }
    20632047#endif
     
    21282112
    21292113        if (chip->fm_port > 0) {
    2130                 opl3_t *opl3;
    2131                 if (snd_opl3_create(card,
    2132                                     chip->fm_port,
    2133                                     chip->fm_port + 2,
    2134                                     OPL3_HW_AUTO, 0, &opl3) < 0) {
     2114                opl3_t *opl3 = NULL;
     2115#ifdef USE_OPL4
     2116#ifndef OPTi93X
     2117                if (chip->hardware == OPTi9XX_HW_82C928 ||
     2118                    chip->hardware == OPTi9XX_HW_82C929 ||
     2119                    chip->hardware == OPTi9XX_HW_82C924) {
     2120                        opl4_t *opl4;
     2121                        /* assume we have an OPL4 */
     2122                        snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
     2123                                               0x20, 0x20);
     2124                        if (snd_opl4_create(card,
     2125                                            chip->fm_port,
     2126                                            chip->fm_port - 8,
     2127                                            2, &opl3, &opl4) < 0) {
     2128                                /* no luck, use OPL3 instead */
     2129                                snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
     2130                                                       0x00, 0x20);
     2131                        }
     2132                }
     2133#endif  /* !OPTi93X */
     2134#endif
     2135                if (!opl3 && snd_opl3_create(card,
     2136                                             chip->fm_port,
     2137                                             chip->fm_port + 2,
     2138                                             OPL3_HW_AUTO, 0, &opl3) < 0) {
    21352139                        snd_printk("no OPL device at 0x%lx-0x%lx\n",
    2136                                 chip->fm_port, chip->fm_port + 4 - 1);
    2137                 } else {
     2140                                   chip->fm_port, chip->fm_port + 4 - 1);
     2141                }
     2142                if (opl3) {
    21382143                        if ((error = snd_opl3_timer_new(opl3,
    21392144#ifdef CS4231
     
    21672172                return error;
    21682173        }
    2169         snd_opti9xx_card = card;
     2174        snd_opti9xx_first_hit = 0;
     2175        if (pcard)
     2176                pnp_set_card_drvdata(pcard, card);
     2177        else
     2178                snd_opti9xx_legacy = card;
    21702179        return 0;
    21712180}
    21722181
     2182#ifdef CONFIG_PNP
     2183static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
     2184{
     2185        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     2186
     2187        snd_card_disconnect(card);
     2188        snd_card_free_in_thread(card);
     2189        snd_opti9xx_first_hit = 0;
     2190}
     2191
     2192static struct pnp_card_driver opti9xx_pnpc_driver = {
     2193        .flags          = PNP_DRIVER_RES_DISABLE,
     2194        .name           = "opti9xx",
     2195        .id_table       = snd_opti9xx_pnpids,
     2196        .probe          = snd_card_opti9xx_probe,
     2197        .remove         = __devexit_p(snd_opti9xx_pnp_remove),
     2198};
     2199#endif
     2200
    21732201static int __init alsa_card_opti9xx_init(void)
    21742202{
    2175         int error;
    2176 
    2177         if ((error = snd_card_opti9xx_probe())) {
     2203        int cards, error;
     2204
     2205        cards = pnp_register_card_driver(&opti9xx_pnpc_driver);
     2206        if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {
     2207#ifdef CONFIG_PNP
     2208                pnp_unregister_card_driver(&opti9xx_pnpc_driver);
     2209#endif
    21782210#ifdef MODULE
    21792211#ifdef OPTi93X
     
    21902222static void __exit alsa_card_opti9xx_exit(void)
    21912223{
    2192         if (snd_opti9xx_card)
    2193                 snd_card_free(snd_opti9xx_card);
     2224#ifdef CONFIG_PNP
     2225        pnp_unregister_card_driver(&opti9xx_pnpc_driver);
     2226#endif
     2227        if (snd_opti9xx_legacy)
     2228                snd_card_free(snd_opti9xx_legacy);
    21942229}
    21952230
     
    22242259#endif
    22252260               );
    2226 #ifdef __ISAPNP__
     2261#ifdef CONFIG_PNP
    22272262        if (pnp != INT_MAX)
    22282263                isapnp = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/es968.c

    r224 r246  
    2424#include <linux/init.h>
    2525#include <linux/time.h>
    26 #ifndef LINUX_ISAPNP_H
    27 #include <linux/isapnp.h>
    28 #define isapnp_card pci_bus
    29 #define isapnp_dev pci_dev
    30 #endif
     26#include <linux/pnp.h>
    3127#include <sound/core.h>
    3228#define SNDRV_GET_ID
     
    3531
    3632#define chip_t sb_t
     33
     34#define PFX "es968: "
    3735
    3836MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
     
    6967
    7068struct snd_card_es968 {
    71 #ifdef __ISAPNP__
    72     struct isapnp_dev *dev;
    73 #endif  /* __ISAPNP__ */
     69        struct pnp_dev *dev;
    7470};
    7571
    76 static snd_card_t *snd_es968_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    77 
    78 #ifdef __ISAPNP__
    79 static struct isapnp_card *snd_es968_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    80 static const struct isapnp_card_id *snd_es968_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
    81 
    82 static struct isapnp_card_id snd_es968_pnpids[] __devinitdata = {
    83     {
    84         ISAPNP_CARD_ID('E','S','S',0x0968),
    85                 .devs = { ISAPNP_DEVICE_ID('E','S','S',0x0968), }
    86     },
    87     { ISAPNP_CARD_END, }
     72static struct pnp_card_device_id snd_es968_pnpids[] __devinitdata = {
     73        { .id = "ESS0968", .devs = { { "@@@0968" }, } },
     74        { .id = "", } /* end */
    8875};
    8976
    90 ISAPNP_CARD_TABLE(snd_es968_pnpids);
    91 
    92 #endif  /* __ISAPNP__ */
     77MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
    9378
    9479#define DRIVER_NAME     "snd-card-es968"
    9580
    96 
    97 static void snd_card_es968_interrupt(int irq, void *dev_id,
     81static irqreturn_t snd_card_es968_interrupt(int irq, void *dev_id,
    9882                                     struct pt_regs *regs)
    9983{
    100         sb_t *chip = snd_magic_cast(sb_t, dev_id, return);
     84        sb_t *chip = snd_magic_cast(sb_t, dev_id, return IRQ_NONE);
    10185
    10286    if (chip->open & SB_OPEN_PCM) {
    103         snd_sb8dsp_interrupt(chip);
     87                return snd_sb8dsp_interrupt(chip);
    10488    } else {
    105         snd_sb8dsp_midi_interrupt(chip);
    106     }
    107 }
    108 
    109 #ifdef __ISAPNP__
    110 static int __init snd_card_es968_isapnp(int dev, struct snd_card_es968 *acard)
    111 {
    112     const struct isapnp_card_id *id = snd_es968_isapnp_id[dev];
    113     struct isapnp_card *card = snd_es968_isapnp_cards[dev];
    114     struct isapnp_dev *pdev;
    115 
    116     acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    117     if (acard->dev->active) {
    118         acard->dev = NULL;
    119         return -EBUSY;
     89                return snd_sb8dsp_midi_interrupt(chip);
     90        }
     91}
     92
     93static int __devinit snd_card_es968_pnp(int dev, struct snd_card_es968 *acard,
     94                                        struct pnp_card_link *card,
     95                                        const struct pnp_card_device_id *id)
     96{
     97        struct pnp_dev *pdev;
     98        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
     99        int err;
     100        if (!cfg)
     101                return -ENOMEM;
     102        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     103        if (acard->dev == NULL) {
     104                kfree(cfg);
     105                return -ENODEV;
    120106    }
    121107
    122108    pdev = acard->dev;
    123     if (pdev->prepare(pdev)<0)
    124         return -EAGAIN;
    125 
     109
     110        pnp_init_resource_table(cfg);
     111
     112        /* override resources */
    126113        if (port[dev] != SNDRV_AUTO_PORT)
    127                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     114                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    128115        if (dma8[dev] != SNDRV_AUTO_DMA)
    129                 isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
    130                                1);
     116                pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
    131117        if (irq[dev] != SNDRV_AUTO_IRQ)
    132                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    133 
    134     if (pdev->activate(pdev)<0) {
    135         snd_printk("AUDIO isapnp configure failure\n");
    136         return -EBUSY;
    137     }
    138 
    139         port[dev] = pdev->resource[0].start;
    140         dma8[dev] = pdev->dma_resource[0].start;
    141         irq[dev] = pdev->irq_resource[0].start;
    142 
     118                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     119        if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     120                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     121        err = pnp_activate_dev(pdev);
     122        if (err < 0) {
     123                snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
     124                return err;
     125        }
     126        port[dev] = pnp_port_start(pdev, 0);
     127        dma8[dev] = pnp_dma(pdev, 1);
     128        irq[dev] = pnp_irq(pdev, 0);
     129
     130        kfree(cfg);
    143131    return 0;
    144132}
    145133
    146 static void snd_card_es968_deactivate(struct snd_card_es968 *acard)
    147 {
    148     if (acard->dev) {
    149         acard->dev->deactivate(acard->dev);
    150         acard->dev = NULL;
    151     }
    152 }
    153 #endif  /* __ISAPNP__ */
    154 
    155 static void snd_card_es968_free(snd_card_t *card)
    156 {
    157     struct snd_card_es968 *acard = (struct snd_card_es968 *)card->private_data;
    158 
    159     if (acard) {
    160 #ifdef __ISAPNP__
    161         snd_card_es968_deactivate(acard);
    162 #endif  /* __ISAPNP__ */
    163     }
    164 }
    165 
    166 static int __init snd_card_es968_probe(int dev)
     134static int __init snd_card_es968_probe(int dev,
     135                                        struct pnp_card_link *pcard,
     136                                        const struct pnp_card_device_id *pid)
    167137{
    168138    int error;
     
    175145        return -ENOMEM;
    176146    acard = (struct snd_card_es968 *)card->private_data;
    177     card->private_free = snd_card_es968_free;
    178 
    179 #ifdef __ISAPNP__
    180     if ((error = snd_card_es968_isapnp(dev, acard))) {
    181         snd_card_free(card);
    182         return error;
    183     }
    184 #else
    185     snd_printk("you have to enable PnP support ...\n");
    186     snd_card_free(card);
    187     return -ENOSYS;
    188 #endif  /* __ISAPNP__ */
     147        if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
     148                snd_card_free(card);
     149                return error;
     150        }
    189151
    190152        if ((error = snd_sbdsp_create(card, port[dev],
     
    222184        return error;
    223185    }
    224     snd_es968_cards[dev] = card;
     186        pnp_set_card_drvdata(pcard, card);
    225187    return 0;
    226188}
    227189
    228 #ifdef __ISAPNP__
    229 static int __init snd_es968_isapnp_detect(struct isapnp_card *card,
    230                                           const struct isapnp_card_id *id)
     190static int __devinit snd_es968_pnp_detect(struct pnp_card_link *card,
     191                                          const struct pnp_card_device_id *id)
    231192{
    232193        static int dev;
     
    236197                if (!enable[dev])
    237198            continue;
    238         snd_es968_isapnp_cards[dev] = card;
    239         snd_es968_isapnp_id[dev] = id;
    240         res = snd_card_es968_probe(dev);
     199                res = snd_card_es968_probe(dev, card, id);
    241200        if (res < 0)
    242201            return res;
     
    246205    return -ENODEV;
    247206}
    248 #endif /* __ISAPNP__ */
     207
     208static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
     209{
     210        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     211
     212        snd_card_disconnect(card);
     213        snd_card_free_in_thread(card);
     214}
     215
     216static struct pnp_card_driver es968_pnpc_driver = {
     217        .flags          = PNP_DRIVER_RES_DISABLE,
     218        .name           = "es968",
     219        .id_table       = snd_es968_pnpids,
     220        .probe          = snd_es968_pnp_detect,
     221        .remove         = __devexit_p(snd_es968_pnp_remove),
     222};
    249223
    250224static int __init alsa_card_es968_init(void)
    251225{
    252     int cards = 0;
    253 
    254 #ifdef __ISAPNP__
    255     cards += isapnp_probe_cards(snd_es968_pnpids, snd_es968_isapnp_detect);
    256 #else
    257     snd_printk("you have to enable ISA PnP support.\n");
     226        int res = pnp_register_card_driver(&es968_pnpc_driver);
     227        if (res == 0)
     228        {
     229                pnp_unregister_card_driver(&es968_pnpc_driver);
     230#ifdef MODULE
     231                snd_printk(KERN_ERR "no ES968 based soundcards found\n");
    258232#endif
    259 #ifdef MODULE
    260     if (!cards)
    261         snd_printk("no ES968 based soundcards found\n");
    262 #endif
    263     return cards ? 0 : -ENODEV;
     233        }
     234        return res < 0 ? res : 0;
    264235}
    265236
    266237static void __exit alsa_card_es968_exit(void)
    267238{
    268     int dev;
    269 
    270     for (dev = 0; dev < SNDRV_CARDS; dev++)
    271         snd_card_free(snd_es968_cards[dev]);
     239        pnp_unregister_card_driver(&es968_pnpc_driver);
    272240}
    273241
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/sb16.c

    r224 r246  
    2424#include <linux/init.h>
    2525#include <linux/slab.h>
    26 #ifndef LINUX_ISAPNP_H
    27 #include <linux/isapnp.h>
    28 #define isapnp_card pci_bus
    29 #define isapnp_dev pci_dev
    30 #endif
     26#include <linux/pnp.h>
    3127#include <sound/core.h>
    3228#include <sound/sb.h>
     
    7874static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    7975static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
    80 #ifdef __ISAPNP__
     76#ifdef CONFIG_PNP
    8177#ifdef TARGET_OS2
    8278static int isapnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    125121MODULE_PARM_DESC(enable, "Enable SoundBlaster 16 soundcard.");
    126122MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    127 #ifdef __ISAPNP__
     123#ifdef CONFIG_PNP
    128124MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    129 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
     125MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
    130126MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
    131127#endif
     
    167163#endif
    168164
    169 struct snd_sb16 {
     165struct snd_card_sb16 {
    170166    struct resource *fm_res;    /* used to block FM i/o region for legacy cards */
    171 #ifdef __ISAPNP__
    172     struct isapnp_dev *dev;
    173 #ifdef SNDRV_SBAWE_EMU8000
    174     struct isapnp_dev *devwt;
     167#ifdef CONFIG_PNP
     168        int dev_no;
     169        struct pnp_dev *dev;
     170#ifdef SNDRV_SBAWE_EMU8000
     171        struct pnp_dev *devwt;
    175172#endif
    176173#endif
    177174};
    178175
    179 static snd_card_t *snd_sb16_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    180 
    181 #ifdef __ISAPNP__
    182 
    183 static struct isapnp_card *snd_sb16_isapnp_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    184 static const struct isapnp_card_id *snd_sb16_isapnp_id[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    185 
    186 #ifdef TARGET_OS2
    187 #define ISAPNP_SB16(_va, _vb, _vc, _device, _audio) \
    188     { \
    189     0, ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    190     { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), } \
    191     }
    192 #define ISAPNP_SBAWE(_va, _vb, _vc, _device, _audio, _awe) \
    193     { \
    194     0, ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    195     { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
    196     ISAPNP_DEVICE_ID(_va, _vb, _vc, _awe), } \
    197     }
    198 #else
    199 #define ISAPNP_SB16(_va, _vb, _vc, _device, _audio) \
    200     { \
    201     ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    202                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), } \
    203     }
    204 #define ISAPNP_SBAWE(_va, _vb, _vc, _device, _audio, _awe) \
    205     { \
    206     ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
    207                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
    208     ISAPNP_DEVICE_ID(_va, _vb, _vc, _awe), } \
    209     }
    210 #endif
    211 
    212 static struct isapnp_card_id snd_sb16_pnpids[] __devinitdata = {
     176static snd_card_t *snd_sb16_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     177
     178static struct pnp_card_device_id snd_sb16_pnpids[] __devinitdata = {
    213179#ifndef SNDRV_SBAWE
    214180    /* Sound Blaster 16 PnP */
    215     ISAPNP_SB16('C','T','L',0x0024,0x0031),
     181        { .id = "CTL0024", .devs = { { "CTL0031" } } },
    216182        /* Sound Blaster 16 PnP */
    217         ISAPNP_SB16('C','T','L',0x0025,0x0031),
    218     /* Sound Blaster 16 PnP */
    219     ISAPNP_SB16('C','T','L',0x0026,0x0031),
    220     /* Sound Blaster 16 PnP */
    221     ISAPNP_SB16('C','T','L',0x0027,0x0031),
    222     /* Sound Blaster 16 PnP */
    223     ISAPNP_SB16('C','T','L',0x0028,0x0031),
    224     /* Sound Blaster 16 PnP */
    225     ISAPNP_SB16('C','T','L',0x0029,0x0031),
    226     /* Sound Blaster 16 PnP */
    227     ISAPNP_SB16('C','T','L',0x002a,0x0031),
     183        { .id = "CTL0025", .devs = { { "CTL0031" } } },
     184        /* Sound Blaster 16 PnP */
     185        { .id = "CTL0026", .devs = { { "CTL0031" } } },
     186        /* Sound Blaster 16 PnP */
     187        { .id = "CTL0027", .devs = { { "CTL0031" } } },
     188        /* Sound Blaster 16 PnP */
     189        { .id = "CTL0028", .devs = { { "CTL0031" } } },
     190        /* Sound Blaster 16 PnP */
     191        { .id = "CTL0029", .devs = { { "CTL0031" } } },
     192        /* Sound Blaster 16 PnP */
     193        { .id = "CTL002a", .devs = { { "CTL0031" } } },
    228194    /* Sound Blaster 16 PnP */
    229195    /* Note: This card has also a CTL0051:StereoEnhance device!!! */
    230     ISAPNP_SB16('C','T','L',0x002b,0x0031),
    231     /* Sound Blaster 16 PnP */
    232         ISAPNP_SB16('C','T','L',0x002c,0x0031),
     196        { .id = "CTL002b", .devs = { { "CTL0031" } } },
     197        /* Sound Blaster 16 PnP */
     198        { .id = "CTL002c", .devs = { { "CTL0031" } } },
    233199    /* Sound Blaster Vibra16S */
    234     ISAPNP_SB16('C','T','L',0x0051,0x0001),
     200        { .id = "CTL0051", .devs = { { "CTL0001" } } },
    235201    /* Sound Blaster Vibra16C */
    236     ISAPNP_SB16('C','T','L',0x0070,0x0001),
     202        { .id = "CTL0070", .devs = { { "CTL0001" } } },
    237203    /* Sound Blaster Vibra16CL - added by ctm@ardi.com */
    238     ISAPNP_SB16('C','T','L',0x0080,0x0041),
     204        { .id = "CTL0080", .devs = { { "CTL0041" } } },
    239205        /* Sound Blaster 16 'value' PnP. It says model ct4130 on the pcb, */
    240206        /* but ct4131 on a sticker on the board.. */
    241         ISAPNP_SB16('C','T','L',0x0086,0x0041),
     207        { .id = "CTL0086", .devs = { { "CTL0041" } } },
    242208    /* Sound Blaster Vibra16X */
    243     ISAPNP_SB16('C','T','L',0x00f0,0x0043),
     209        { .id = "CTL00f0", .devs = { { "CTL0043" } } },
    244210#else  /* SNDRV_SBAWE defined */
    245211    /* Sound Blaster AWE 32 PnP */
    246     ISAPNP_SBAWE('C','T','L',0x0035,0x0031,0x0021),
    247     /* Sound Blaster AWE 32 PnP */
    248     ISAPNP_SBAWE('C','T','L',0x0039,0x0031,0x0021),
    249     /* Sound Blaster AWE 32 PnP */
    250     ISAPNP_SBAWE('C','T','L',0x0042,0x0031,0x0021),
    251     /* Sound Blaster AWE 32 PnP */
    252     ISAPNP_SBAWE('C','T','L',0x0043,0x0031,0x0021),
     212        { .id = "CTL0035", .devs = { { "CTL0031" }, { "CTL0021" } } },
     213        /* Sound Blaster AWE 32 PnP */
     214        { .id = "CTL0039", .devs = { { "CTL0031" }, { "CTL0021" } } },
     215        /* Sound Blaster AWE 32 PnP */
     216        { .id = "CTL0042", .devs = { { "CTL0031" }, { "CTL0021" } } },
     217        /* Sound Blaster AWE 32 PnP */
     218        { .id = "CTL0043", .devs = { { "CTL0031" }, { "CTL0021" } } },
    253219    /* Sound Blaster AWE 32 PnP */
    254220    /* Note: This card has also a CTL0051:StereoEnhance device!!! */
    255     ISAPNP_SBAWE('C','T','L',0x0044,0x0031,0x0021),
     221        { .id = "CTL0044", .devs = { { "CTL0031" }, { "CTL0021" } } },
    256222    /* Sound Blaster AWE 32 PnP */
    257223    /* Note: This card has also a CTL0051:StereoEnhance device!!! */
    258     ISAPNP_SBAWE('C','T','L',0x0045,0x0031,0x0021),
    259         /* Sound Blaster AWE 32 PnP */
    260         ISAPNP_SBAWE('C','T','L',0x0046,0x0031,0x0021),
    261     /* Sound Blaster AWE 32 PnP */
    262     ISAPNP_SBAWE('C','T','L',0x0047,0x0031,0x0021),
    263     /* Sound Blaster AWE 32 PnP */
    264     ISAPNP_SBAWE('C','T','L',0x0048,0x0031,0x0021),
    265     /* Sound Blaster AWE 32 PnP */
    266     ISAPNP_SBAWE('C','T','L',0x0054,0x0031,0x0021),
    267     /* Sound Blaster AWE 32 PnP */
    268     ISAPNP_SBAWE('C','T','L',0x009a,0x0041,0x0021),
    269     /* Sound Blaster AWE 32 PnP */
    270     ISAPNP_SBAWE('C','T','L',0x009c,0x0041,0x0021),
     224        { .id = "CTL0045", .devs = { { "CTL0031" }, { "CTL0021" } } },
     225        /* Sound Blaster AWE 32 PnP */
     226        { .id = "CTL0046", .devs = { { "CTL0031" }, { "CTL0021" } } },
     227        /* Sound Blaster AWE 32 PnP */
     228        { .id = "CTL0047", .devs = { { "CTL0031" }, { "CTL0021" } } },
     229        /* Sound Blaster AWE 32 PnP */
     230        { .id = "CTL0048", .devs = { { "CTL0031" }, { "CTL0021" } } },
     231        /* Sound Blaster AWE 32 PnP */
     232        { .id = "CTL0054", .devs = { { "CTL0031" }, { "CTL0021" } } },
     233        /* Sound Blaster AWE 32 PnP */
     234        { .id = "CTL009a", .devs = { { "CTL0041" }, { "CTL0021" } } },
     235        /* Sound Blaster AWE 32 PnP */
     236        { .id = "CTL009c", .devs = { { "CTL0041" }, { "CTL0021" } } },
    271237    /* Sound Blaster 32 PnP */
    272     ISAPNP_SBAWE('C','T','L',0x009f,0x0041,0x0021),
     238        { .id = "CTL009f", .devs = { { "CTL0041" }, { "CTL0021" } } },
    273239    /* Sound Blaster AWE 64 PnP */
    274     ISAPNP_SBAWE('C','T','L',0x009d,0x0042,0x0022),
     240        { .id = "CTL009d", .devs = { { "CTL0042" }, { "CTL0022" } } },
    275241    /* Sound Blaster AWE 64 PnP Gold */
    276     ISAPNP_SBAWE('C','T','L',0x009e,0x0044,0x0023),
     242        { .id = "CTL009e", .devs = { { "CTL0044" }, { "CTL0023" } } },
    277243    /* Sound Blaster AWE 64 PnP Gold */
    278     ISAPNP_SBAWE('C','T','L',0x00b2,0x0044,0x0023),
     244        { .id = "CTL00b2", .devs = { { "CTL0044" }, { "CTL0023" } } },
    279245    /* Sound Blaster AWE 64 PnP */
    280     ISAPNP_SBAWE('C','T','L',0x00c1,0x0042,0x0022),
     246        { .id = "CTL00c1", .devs = { { "CTL0042" }, { "CTL0022" } } },
    281247    /* Sound Blaster AWE 64 PnP */
    282     ISAPNP_SBAWE('C','T','L',0x00c3,0x0045,0x0022),
     248        { .id = "CTL00c3", .devs = { { "CTL0045" }, { "CTL0022" } } },
    283249    /* Sound Blaster AWE 64 PnP */
    284     ISAPNP_SBAWE('C','T','L',0x00c5,0x0045,0x0022),
     250        { .id = "CTL00c5", .devs = { { "CTL0045" }, { "CTL0022" } } },
    285251    /* Sound Blaster AWE 64 PnP */
    286     ISAPNP_SBAWE('C','T','L',0x00c7,0x0045,0x0022),
     252        { .id = "CTL00c7", .devs = { { "CTL0045" }, { "CTL0022" } } },
    287253    /* Sound Blaster AWE 64 PnP */
    288     ISAPNP_SBAWE('C','T','L',0x00e4,0x0045,0x0022),
     254        { .id = "CTL00e4", .devs = { { "CTL0045" }, { "CTL0022" } } },
    289255        /* Sound Blaster AWE 64 PnP */
    290         ISAPNP_SBAWE('C','T','L',0x00e9,0x0045,0x0022),
     256        { .id = "CTL00e9", .devs = { { "CTL0045" }, { "CTL0022" } } },
    291257    /* Sound Blaster 16 PnP (AWE) */
    292     ISAPNP_SBAWE('C','T','L',0x00ed,0x0041,0x0070),
     258        { .id = "CTL00ed", .devs = { { "CTL0041" }, { "CTL0070" } } },
    293259    /* Generic entries */
    294     ISAPNP_SBAWE('C','T','L',ISAPNP_ANY_ID,0x0031,0x0021),
    295     ISAPNP_SBAWE('C','T','L',ISAPNP_ANY_ID,0x0041,0x0021),
    296     ISAPNP_SBAWE('C','T','L',ISAPNP_ANY_ID,0x0042,0x0022),
    297     ISAPNP_SBAWE('C','T','L',ISAPNP_ANY_ID,0x0044,0x0023),
    298     ISAPNP_SBAWE('C','T','L',ISAPNP_ANY_ID,0x0045,0x0022),
     260        { .id = "CTLXXXX" , .devs = { { "CTL0031" }, { "CTL0021" } } },
     261        { .id = "CTLXXXX" , .devs = { { "CTL0041" }, { "CTL0021" } } },
     262        { .id = "CTLXXXX" , .devs = { { "CTL0042" }, { "CTL0022" } } },
     263        { .id = "CTLXXXX" , .devs = { { "CTL0044" }, { "CTL0023" } } },
     264        { .id = "CTLXXXX" , .devs = { { "CTL0045" }, { "CTL0022" } } },
    299265#endif /* SNDRV_SBAWE */
    300     { ISAPNP_CARD_END, }
     266        { .id = "", }
    301267};
    302268
    303 ISAPNP_CARD_TABLE(snd_sb16_pnpids);
    304 
    305 static int __init snd_sb16_isapnp(int dev, struct snd_sb16 *acard)
     269MODULE_DEVICE_TABLE(pnp_card, snd_sb16_pnpids);
     270
     271#ifdef SNDRV_SBAWE_EMU8000
     272#define DRIVER_NAME     "snd-card-sbawe"
     273#else
     274#define DRIVER_NAME     "snd-card-sb16"
     275#endif
     276
     277static int __devinit snd_card_sb16_pnp(int dev, struct snd_card_sb16 *acard,
     278                                       struct pnp_card_link *card,
     279                                       const struct pnp_card_device_id *id)
    306280{
    307     const struct isapnp_card_id *id = snd_sb16_isapnp_id[dev];
    308     struct isapnp_card *card = snd_sb16_isapnp_cards[dev];
    309     struct isapnp_dev *pdev;
    310 
    311     acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    312     if (acard->dev->active) {
    313         acard->dev = NULL;
    314         return -EBUSY;
    315     }
    316 #ifdef SNDRV_SBAWE_EMU8000
    317     acard->devwt = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
    318     if (acard->devwt->active) {
    319         acard->dev = acard->devwt = NULL;
    320         return -EBUSY;
    321     }
    322 #endif 
     281        struct pnp_dev *pdev;
     282        struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
     283        int err;
     284
     285        if (!cfg)
     286                return -ENOMEM;
     287        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
     288        if (acard->dev == NULL) {
     289                kfree(cfg);
     290                return -ENODEV;
     291        }
     292#ifdef SNDRV_SBAWE_EMU8000
     293        acard->devwt = pnp_request_card_device(card, id->devs[1].id, acard->dev);
     294#endif
    323295    /* Audio initialization */
    324296    pdev = acard->dev;
    325     if (pdev->prepare(pdev) < 0)
    326         return -EAGAIN;
     297
     298        pnp_init_resource_table(cfg);
     299         
     300        /* override resources */
     301
    327302        if (port[dev] != SNDRV_AUTO_PORT)
    328                 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
     303                pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
    329304        if (mpu_port[dev] != SNDRV_AUTO_PORT)
    330                 isapnp_resource_change(&pdev->resource[1], mpu_port[dev], 2);
     305                pnp_resource_change(&cfg->port_resource[1], mpu_port[dev], 2);
    331306        if (fm_port[dev] != SNDRV_AUTO_PORT)
    332                 isapnp_resource_change(&pdev->resource[2], fm_port[dev], 4);
     307                pnp_resource_change(&cfg->port_resource[2], fm_port[dev], 4);
    333308        if (dma8[dev] != SNDRV_AUTO_DMA)
    334                 isapnp_resource_change(&pdev->dma_resource[0], dma8[dev], 1);
     309                pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
    335310        if (dma16[dev] != SNDRV_AUTO_DMA)
    336                 isapnp_resource_change(&pdev->dma_resource[1], dma16[dev], 1);
     311                pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
    337312        if (irq[dev] != SNDRV_AUTO_IRQ)
    338                 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
    339     if (pdev->activate(pdev) < 0) {
    340                 printk(KERN_ERR PFX "isapnp configure failure (out of resources?)\n");
    341         return -EBUSY;
    342     }
    343         port[dev] = pdev->resource[0].start;
    344         mpu_port[dev] = pdev->resource[1].start;
    345         fm_port[dev] = pdev->resource[2].start;
    346         dma8[dev] = pdev->dma_resource[0].start;
    347         dma16[dev] = pdev->dma_resource[1].start;
    348         irq[dev] = pdev->irq_resource[0].start;
    349     snd_printdd("isapnp SB16: port=0x%lx, mpu port=0x%lx, fm port=0x%lx\n",
     313                pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
     314        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     315                snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
     316        err = pnp_activate_dev(pdev);
     317        if (err < 0) {
     318                snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
     319                kfree(cfg);
     320                return err;
     321        }
     322        port[dev] = pnp_port_start(pdev, 0);
     323        mpu_port[dev] = pnp_port_start(pdev, 1);
     324        fm_port[dev] = pnp_port_start(pdev, 2);
     325        dma8[dev] = pnp_dma(pdev, 0);
     326        dma16[dev] = pnp_dma(pdev, 1);
     327        irq[dev] = pnp_irq(pdev, 0);
     328        snd_printdd("pnp SB16: port=0x%lx, mpu port=0x%lx, fm port=0x%lx\n",
    350329                        port[dev], mpu_port[dev], fm_port[dev]);
    351     snd_printdd("isapnp SB16: dma1=%i, dma2=%i, irq=%i\n",
     330        snd_printdd("pnp SB16: dma1=%i, dma2=%i, irq=%i\n",
    352331                        dma8[dev], dma16[dev], irq[dev]);
    353332#ifdef SNDRV_SBAWE_EMU8000
    354333    /* WaveTable initialization */
    355334    pdev = acard->devwt;
    356     if (pdev->prepare(pdev)<0) {
    357         acard->dev->deactivate(acard->dev);
    358         return -EAGAIN;
    359     }
     335        if (pdev != NULL) {
     336                pnp_init_resource_table(cfg);
     337         
     338                /* override resources */
     339
    360340        if (awe_port[dev] != SNDRV_AUTO_PORT) {
    361                 isapnp_resource_change(&pdev->resource[0], awe_port[dev], 4);
    362                 isapnp_resource_change(&pdev->resource[1], awe_port[dev] + 0x400, 4);
    363                 isapnp_resource_change(&pdev->resource[2], awe_port[dev] + 0x800, 4);
     341                        pnp_resource_change(&cfg->port_resource[0], awe_port[dev], 4);
     342                        pnp_resource_change(&cfg->port_resource[1], awe_port[dev] + 0x400, 4);
     343                        pnp_resource_change(&cfg->port_resource[2], awe_port[dev] + 0x800, 4);
     344                }
     345                if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
     346                        snd_printk(KERN_ERR PFX "WaveTable the requested resources are invalid, using auto config\n");
     347                err = pnp_activate_dev(pdev);
     348                if (err < 0) {
     349                        goto __wt_error;
     350                }
     351                awe_port[dev] = pnp_port_start(pdev, 0);
     352                snd_printdd("pnp SB16: wavetable port=0x%lx\n", pnp_port_start(pdev, 0));
     353        } else {
     354__wt_error:
     355                if (pdev) {
     356                        pnp_release_card_device(pdev);
     357                        snd_printk(KERN_ERR PFX "WaveTable pnp configure failure\n");
     358                }
     359        acard->devwt = NULL;
     360                awe_port[dev] = -1;
    364361        }
    365     if (pdev->activate(pdev)<0) {
    366                 printk(KERN_ERR PFX "WaveTable isapnp configure failure (out of resources?)\n");
    367                 acard->dev->deactivate(acard->dev);             
    368         return -EBUSY;
    369     }
    370         awe_port[dev] = pdev->resource[0].start;
    371     snd_printdd("isapnp SB16: wavetable port=0x%lx\n", pdev->resource[0].start);
    372 #endif
    373     return 0;
     362#endif
     363        kfree(cfg);
     364        return 0;
    374365}
    375366
    376 static void snd_sb16_deactivate(struct snd_sb16 *acard)
    377 {
    378     if (acard->dev) {
    379         acard->dev->deactivate(acard->dev);
    380         acard->dev = NULL;
    381     }
    382 #ifdef SNDRV_SBAWE_EMU8000
    383     if (acard->devwt) {
    384         acard->devwt->deactivate(acard->devwt);
    385         acard->devwt = NULL;
    386     }
    387 #endif
    388 }
    389 
    390 #endif /* __ISAPNP__ */
    391 
    392 static void snd_sb16_free(snd_card_t *card)
    393 {
    394     struct snd_sb16 *acard = (struct snd_sb16 *)card->private_data;
    395 
    396     if (acard == NULL)
    397         return;
    398         if (acard->fm_res) {
    399         release_resource(acard->fm_res);
    400                 kfree_nocheck(acard->fm_res);
    401         }
    402 #ifdef __ISAPNP__
    403     snd_sb16_deactivate(acard);
    404 #endif
    405 }
    406 
    407 static int __init snd_sb16_probe(int dev)
     367static int __init snd_sb16_probe(int dev,
     368                                 struct pnp_card_link *pcard,
     369                                 const struct pnp_card_device_id *pid)
    408370{
    409371    static int possible_irqs[] = {5, 9, 10, 7, -1};
     
    413375    sb_t *chip;
    414376    snd_card_t *card;
    415     struct snd_sb16 *acard;
     377        struct snd_card_sb16 *acard;
    416378    opl3_t *opl3;
    417379    snd_hwdep_t *synth = NULL;
     
    423385
    424386        card = snd_card_new(index[dev], id[dev], THIS_MODULE,
    425                         sizeof(struct snd_sb16));
     387                            sizeof(struct snd_card_sb16));
    426388    if (card == NULL)
    427389        return -ENOMEM;
    428     acard = (struct snd_sb16 *) card->private_data;
    429     card->private_free = snd_sb16_free;
    430 #ifdef __ISAPNP__
    431         if (isapnp[dev] && snd_sb16_isapnp(dev, acard) < 0) {
    432         snd_card_free(card);
    433         return -EBUSY;
    434     }
    435 #endif
     390        acard = (struct snd_card_sb16 *) card->private_data;
     391        if (isapnp[dev]) {
     392                if ((err = snd_card_sb16_pnp(dev, acard, pcard, pid))) {
     393                        snd_card_free(card);
     394                        return err;
     395                }
     396        }
    436397
    437398        xirq = irq[dev];
    438399        xdma8 = dma8[dev];
    439400        xdma16 = dma16[dev];
    440 #ifdef __ISAPNP__
     401#ifdef CONFIG_PNP
    441402        if (!isapnp[dev]) {
    442403#endif
     
    444405                if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
    445406                snd_card_free(card);
    446                         printk(KERN_ERR PFX "unable to find a free IRQ\n");
     407                        snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
    447408                return -EBUSY;
    448409            }
     
    451412                if ((xdma8 = snd_legacy_find_free_dma(possible_dmas8)) < 0) {
    452413                snd_card_free(card);
    453                         printk(KERN_ERR PFX "unable to find a free 8-bit DMA\n");
     414                        snd_printk(KERN_ERR PFX "unable to find a free 8-bit DMA\n");
    454415                return -EBUSY;
    455416            }
     
    458419                if ((xdma16 = snd_legacy_find_free_dma(possible_dmas16)) < 0) {
    459420                snd_card_free(card);
    460                         printk(KERN_ERR PFX "unable to find a free 16-bit DMA\n");
     421                        snd_printk(KERN_ERR PFX "unable to find a free 16-bit DMA\n");
    461422                return -EBUSY;
    462423            }
     
    470431        awe_port[dev] = port[dev] + 0x400;
    471432#endif
    472 #ifdef __ISAPNP__
     433#ifdef CONFIG_PNP
    473434    }
    474435#endif
     
    491452    }
    492453        chip->mpu_port = mpu_port[dev];
    493 #ifdef __ISAPNP__
     454#ifdef CONFIG_PNP
    494455        if (!isapnp[dev] && (err = snd_sb16dsp_configure(chip)) < 0) {
    495456#else
     
    518479                                    OPL3_HW_OPL3, fm_port[dev] == port[dev],
    519480                                &opl3) < 0) {
    520                         printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
     481                        snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
    521482                                   fm_port[dev], fm_port[dev] + 2);
    522483            } else {
     
    546507                chip->hardware = SB_HW_16CSP;
    547508            } else {
    548                         printk(KERN_INFO PFX "warning - CSP chip not detected on soundcard #%i\n", dev + 1);
     509                        snd_printk(KERN_INFO PFX "warning - CSP chip not detected on soundcard #%i\n", dev + 1);
    549510            }
    550511        }
     
    554515                if (snd_emu8000_new(card, 1, awe_port[dev],
    555516                                    seq_ports[dev], NULL) < 0) {
    556                         printk(KERN_ERR PFX "fatal error - EMU-8000 synthesizer not detected at 0x%lx\n", awe_port[dev]);
     517                        snd_printk(KERN_ERR PFX "fatal error - EMU-8000 synthesizer not detected at 0x%lx\n", awe_port[dev]);
    557518                snd_card_free(card);
    558519                return -ENXIO;
     
    587548            return err;
    588549        }
    589         snd_sb16_cards[dev] = card;
     550        if (pcard)
     551                pnp_set_card_drvdata(pcard, card);
     552        else
     553                snd_sb16_legacy[dev] = card;
    590554        return 0;
    591555    }
     
    599563                if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
    600564                continue;
    601 #ifdef __ISAPNP__
     565#ifdef CONFIG_PNP
    602566                if (isapnp[dev])
    603567                continue;
    604568#endif
    605569                port[dev] = xport;
    606             res = snd_sb16_probe(dev);
     570                res = snd_sb16_probe(dev, NULL, NULL);
    607571            if (res < 0)
    608572                        port[dev] = SNDRV_AUTO_PORT;
     
    612576    }
    613577
    614 #ifdef __ISAPNP__
    615 
    616     static int __init snd_sb16_isapnp_detect(struct isapnp_card *card,
    617                                              const struct isapnp_card_id *id)
     578#ifdef CONFIG_PNP
     579
     580static int __devinit snd_sb16_pnp_detect(struct pnp_card_link *card,
     581                                         const struct pnp_card_device_id *id)
    618582    {
    619583        static int dev;
     
    623587                if (!enable[dev] || !isapnp[dev])
    624588                continue;
    625             snd_sb16_isapnp_cards[dev] = card;
    626             snd_sb16_isapnp_id[dev] = id;
    627             res = snd_sb16_probe(dev);
     589                res = snd_sb16_probe(dev, card, id);
    628590            if (res < 0)
    629591                return res;
     
    635597    }
    636598
    637 #endif /* __ISAPNP__ */
     599static void __devexit snd_sb16_pnp_remove(struct pnp_card_link * pcard)
     600{
     601        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     602
     603        snd_card_disconnect(card);
     604        snd_card_free_in_thread(card);
     605}
     606
     607static struct pnp_card_driver sb16_pnpc_driver = {
     608        .flags = PNP_DRIVER_RES_DISABLE,
     609        .name = "sb16",
     610        .id_table = snd_sb16_pnpids,
     611        .probe = snd_sb16_pnp_detect,
     612        .remove = __devexit_p(snd_sb16_pnp_remove),
     613};
     614
     615#endif /* CONFIG_PNP */
    638616
    639617    static int __init alsa_card_sb16_init(void)
     
    646624                if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
    647625                continue;
    648 #ifdef __ISAPNP__
     626#ifdef CONFIG_PNP
    649627                if (isapnp[dev])
    650628                continue;
    651629#endif
    652             if (!snd_sb16_probe(dev)) {
     630                if (!snd_sb16_probe(dev, NULL, NULL)) {
    653631                cards++;
    654632                continue;
    655633            }
    656634#ifdef MODULE
    657                 printk(KERN_ERR "Sound Blaster 16+ soundcard #%i not found at 0x%lx or device busy\n", dev, port[dev]);
    658 #endif                 
     635                snd_printk(KERN_ERR "Sound Blaster 16+ soundcard #%i not found at 0x%lx or device busy\n", dev, port[dev]);
     636#endif
    659637        }
    660638        /* legacy auto configured cards */
    661639        cards += snd_legacy_auto_probe(possible_ports, snd_sb16_probe_legacy_port);
    662 #ifdef __ISAPNP__
    663         /* ISA PnP cards at last */
    664         cards += isapnp_probe_cards(snd_sb16_pnpids, snd_sb16_isapnp_detect);
     640#ifdef CONFIG_PNP
     641        /* PnP cards at last */
     642        cards += pnp_register_card_driver(&sb16_pnpc_driver);
    665643#endif
    666644
    667645        if (!cards) {
     646#ifdef CONFIG_PNP
     647                pnp_unregister_card_driver(&sb16_pnpc_driver);
     648#endif
    668649#ifdef MODULE
    669                 printk(KERN_ERR "Sound Blaster 16 soundcard not found or device busy\n");
    670 #ifdef SNDRV_SBAWE_EMU8000
    671                 printk(KERN_ERR "In case, if you have non-AWE card, try snd-sb16 module\n");
    672 #else
    673                 printk(KERN_ERR "In case, if you have AWE card, try snd-sbawe module\n");
     650                snd_printk(KERN_ERR "Sound Blaster 16 soundcard not found or device busy\n");
     651#ifdef SNDRV_SBAWE_EMU8000
     652                snd_printk(KERN_ERR "In case, if you have non-AWE card, try snd-sb16 module\n");
     653#else
     654                snd_printk(KERN_ERR "In case, if you have AWE card, try snd-sbawe module\n");
    674655#endif
    675656#endif
     
    683664        int dev;
    684665
     666#ifdef CONFIG_PNP
     667        /* PnP cards first */
     668        pnp_unregister_card_driver(&sb16_pnpc_driver);
     669#endif
    685670        for (dev = 0; dev < SNDRV_CARDS; dev++)
    686             snd_card_free(snd_sb16_cards[dev]);
     671                snd_card_free(snd_sb16_legacy[dev]);
    687672    }
    688673
     
    727712#endif
    728713              );
    729 #ifdef __ISAPNP__
     714#ifdef CONFIG_PNP
    730715        if (pnp != INT_MAX)
    731716                isapnp[nr_dev] = pnp;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/sb16_main.c

    r224 r246  
    394394}
    395395
    396 void snd_sb16dsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     396irqreturn_t snd_sb16dsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    397397{
    398398    sb_t *chip = dev_id;
     
    439439        spin_unlock(&chip->reg_lock);
    440440    }
     441        return IRQ_HANDLED;
    441442}
    442443
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/sb8.c

    r224 r246  
    7171static snd_card_t *snd_sb8_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    7272
    73 static void snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    74 {
    75         sb_t *chip = snd_magic_cast(sb_t, dev_id, return);
     73static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     74{
     75        sb_t *chip = snd_magic_cast(sb_t, dev_id, return IRQ_NONE);
    7676
    7777    if (chip->open & SB_OPEN_PCM) {
    78         snd_sb8dsp_interrupt(chip);
     78                return snd_sb8dsp_interrupt(chip);
    7979    } else {
    80         snd_sb8dsp_midi_interrupt(chip);
     80                return snd_sb8dsp_midi_interrupt(chip);
    8181    }
    8282}
     
    144144                                   OPL3_HW_AUTO, 1,
    145145                                   &opl3)) < 0) {
    146                         printk(KERN_ERR "sb8: no OPL device at 0x%lx\n", chip->port + 8);
     146                        snd_printk(KERN_ERR "sb8: no OPL device at 0x%lx\n", chip->port + 8);
    147147        }
    148148    } else {
     
    150150                                   OPL3_HW_AUTO, 1,
    151151                                   &opl3)) < 0) {
    152                         printk(KERN_ERR "sb8: no OPL device at 0x%lx-0x%lx\n",
     152                        snd_printk(KERN_ERR "sb8: no OPL device at 0x%lx-0x%lx\n",
    153153                       chip->port, chip->port + 2);
    154154        }
     
    211211    if (!cards) {
    212212#ifdef MODULE
    213                 printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n");
     213                snd_printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n");
    214214#endif
    215215        return -ENODEV;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/sb8_main.c

    r224 r246  
    332332}
    333333
    334 void snd_sb8dsp_interrupt(sb_t *chip)
     334irqreturn_t snd_sb8dsp_interrupt(sb_t *chip)
    335335{
    336336    snd_pcm_substream_t *substream;
     
    357357        break;
    358358    }
     359        return IRQ_HANDLED;
    359360}
    360361
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sb/sb8_midi.c

    r210 r246  
    3434*/
    3535
    36 void snd_sb8dsp_midi_interrupt(sb_t * chip)
     36irqreturn_t snd_sb8dsp_midi_interrupt(sb_t * chip)
    3737{
    3838    snd_rawmidi_t *rmidi;
     
    4242    if (chip == NULL || (rmidi = chip->rmidi) == NULL) {
    4343        inb(SBP(chip, READ));   /* ack interrupt */
    44         return;
     44                return IRQ_NONE;
    4545    }
    4646    while (max-- > 0) {
     
    5454        }
    5555    }
     56        return IRQ_HANDLED;
    5657}
    5758
     
    206207    if (up) {
    207208        if (!(chip->open & SB_OPEN_MIDI_TRIGGER)) {
     209                        init_timer(&chip->midi_timer);
    208210            chip->midi_timer.function = snd_sb8dsp_midi_output_timer;
    209211            chip->midi_timer.data = (unsigned long) substream;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/sgalaxy.c

    r224 r246  
    113113}
    114114
    115 static void snd_sgalaxy_dummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    116 {
     115static irqreturn_t snd_sgalaxy_dummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     116{
     117        return IRQ_NONE;
    117118}
    118119
     
    307308        if (!cards) {
    308309#ifdef MODULE
    309                 printk(KERN_ERR "Sound Galaxy soundcard not found or device busy\n");
     310                snd_printk(KERN_ERR "Sound Galaxy soundcard not found or device busy\n");
    310311#endif
    311312                return -ENODEV;
  • GPL/branches/alsa-resync1/alsa-kernel/isa/wavefront/wavefront.c

    r212 r246  
    2222#include <sound/driver.h>
    2323#include <linux/init.h>
     24#include <linux/interrupt.h>
    2425#include <linux/slab.h>
    25 #ifndef LINUX_ISAPNP_H
    26 #include <linux/isapnp.h>
    27 #define isapnp_card pci_bus
    28 #define isapnp_dev pci_dev
    29 #endif
     26#include <linux/pnp.h>
    3027#include <sound/core.h>
    3128#define SNDRV_GET_ID
     
    6663MODULE_PARM_DESC(enable, "Enable WaveFront soundcard.");
    6764MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    68 #ifdef __ISAPNP__
     65#ifdef CONFIG_PNP
    6966MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    7067MODULE_PARM_DESC(isapnp, "ISA PnP detection for WaveFront soundcards.");
     
    10299MODULE_PARM_SYNTAX(use_cs4232_midi, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    103100
    104 static snd_card_t *snd_wavefront_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    105 
    106 #ifdef __ISAPNP__
    107 
    108 static struct isapnp_card *snd_wavefront_isapnp_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    109 static const struct isapnp_card_id *snd_wavefront_isapnp_id[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
    110 
    111 static struct isapnp_card_id snd_wavefront_pnpids[] __devinitdata = {
    112         {
    113                 ISAPNP_CARD_ID('C','S','C',0x7532),     /* Tropez */
    114                 .devs = { ISAPNP_DEVICE_ID('C','S','C',0x0000), /* WSS */
    115                         ISAPNP_DEVICE_ID('C','S','C',0x0010),   /* CTRL */
    116                         ISAPNP_DEVICE_ID('P','n','P',0xb006),   /* MPU */
    117                         ISAPNP_DEVICE_ID('C','S','C',000004), }, /* SYNTH */
    118         },
    119         {
    120                 ISAPNP_CARD_ID('C','S','C',0x7632),     /* Tropez+ */
    121                 .devs = { ISAPNP_DEVICE_ID('C','S','C',0x0000), /* WSS */
    122                         ISAPNP_DEVICE_ID('C','S','C',0x0010),   /* CTRL */
    123                         ISAPNP_DEVICE_ID('P','n','P',0xb006),   /* MPU */
    124                         ISAPNP_DEVICE_ID('C','S','C',000004), }, /* SYNTH */
    125         },
    126         { ISAPNP_CARD_END, }
     101static snd_card_t *snd_wavefront_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
     102
     103#ifdef CONFIG_PNP
     104
     105static struct pnp_card_device_id snd_wavefront_pnpids[] __devinitdata = {
     106        /* Tropez */
     107        { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
     108        /* Tropez+ */
     109        { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
     110        { .id = "" }
    127111};
    128112
    129 ISAPNP_CARD_TABLE(snd_wavefront_pnpids);
    130 
    131 static int __init
    132 snd_wavefront_isapnp (int dev, snd_wavefront_card_t *acard)
    133 {
    134         const struct isapnp_card_id *id = snd_wavefront_isapnp_id[dev];
    135         struct isapnp_card *card = snd_wavefront_isapnp_cards[dev];
    136         struct isapnp_dev *pdev;
    137         int tmp;
     113MODULE_DEVICE_TABLE(pnp_card, snd_wavefront_pnpids);
     114
     115static int __devinit
     116snd_wavefront_pnp (int dev, snd_wavefront_card_t *acard, struct pnp_card_link *card,
     117                   const struct pnp_card_device_id *id)
     118{
     119        struct pnp_dev *pdev;
     120        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
     121        int err;
     122
     123        if (!cfg)
     124                return -ENOMEM;
    138125       
    139126        /* Check for each logical device. */
     
    141128        /* CS4232 chip (aka "windows sound system") is logical device 0 */
    142129
    143         acard->wss = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
    144         if (acard->wss->active) {
    145                 acard->wss = NULL;
     130        acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
     131        if (acard->wss == NULL) {
     132                kfree(cfg);
    146133                return -EBUSY;
    147134        }
     
    159146
    160147        if (use_cs4232_midi[dev]) {
    161                 acard->mpu = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
    162                 if (acard->mpu->active) {
    163                         acard->wss = acard->synth = acard->mpu = NULL;
     148                acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
     149                if (acard->mpu == NULL) {
     150                        kfree(cfg);
    164151                        return -EBUSY;
    165152                }
     
    168155        /* The ICS2115 synth is logical device 4 */
    169156
    170         acard->synth = isapnp_find_dev(card, id->devs[3].vendor, id->devs[3].function, NULL);
    171         if (acard->synth->active) {
    172                 acard->wss = acard->synth = NULL;
     157        acard->synth = pnp_request_card_device(card, id->devs[3].id, NULL);
     158        if (acard->synth == NULL) {
     159                kfree(cfg);
    173160                return -EBUSY;
    174161        }
     
    178165        pdev = acard->wss;
    179166
    180         if ((tmp = pdev->prepare (pdev)) < 0) {
    181                 if (tmp == -EBUSY) {
    182                         snd_printk ("ISA PnP configuration appears to have "
    183                                     "been done. Restart the isapnp module.\n");
    184                         return 0;
    185                 }
    186                 snd_printk ("isapnp WSS preparation failed\n");
    187                 return -EAGAIN;
    188         }
     167        pnp_init_resource_table(cfg);
    189168
    190169        /* An interesting note from the Tropez+ FAQ:
     
    201180
    202181        if (cs4232_pcm_port[dev] != SNDRV_AUTO_PORT)
    203                 isapnp_resource_change(&pdev->resource[0], cs4232_pcm_port[dev], 4);
    204182        if (fm_port[dev] != SNDRV_AUTO_PORT)
    205                 isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4);
     183                pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
    206184        if (dma1[dev] != SNDRV_AUTO_DMA)
    207                 isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], 1);
     185                pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
    208186        if (dma2[dev] != SNDRV_AUTO_DMA)
    209                 isapnp_resource_change(&pdev->dma_resource[1], dma2[dev], 1);
     187                pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
    210188        if (cs4232_pcm_irq[dev] != SNDRV_AUTO_IRQ)
    211                 isapnp_resource_change(&pdev->irq_resource[0], cs4232_pcm_irq[dev], 1);
    212 
    213         if (pdev->activate(pdev)<0) {
    214                 snd_printk ("isapnp WSS activation failed\n");
    215                 return -EBUSY;
    216         }
    217 
    218         cs4232_pcm_port[dev] = pdev->resource[0].start;
    219         fm_port[dev] = pdev->resource[1].start;
    220         dma1[dev] = pdev->dma_resource[0].start;
    221         dma2[dev] = pdev->dma_resource[1].start;
    222         cs4232_pcm_irq[dev] = pdev->irq_resource[0].start;
     189                pnp_resource_change(&cfg->irq_resource[0], cs4232_pcm_irq[dev], 1);
     190
     191        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     192                snd_printk(KERN_ERR "PnP WSS the requested resources are invalid, using auto config\n");
     193        err = pnp_activate_dev(pdev);
     194        if (err < 0) {
     195                snd_printk(KERN_ERR "PnP WSS pnp configure failure\n");
     196                kfree(cfg);
     197                return err;
     198        }
     199
     200        cs4232_pcm_port[dev] = pnp_port_start(pdev, 0);
     201        fm_port[dev] = pnp_port_start(pdev, 1);
     202        dma1[dev] = pnp_dma(pdev, 0);
     203        dma2[dev] = pnp_dma(pdev, 1);
     204        cs4232_pcm_irq[dev] = pnp_irq(pdev, 0);
    223205
    224206        /* Synth initialization */
     
    226208                pdev = acard->synth;
    227209
    228         if ((tmp = pdev->prepare(pdev))<0) {
    229                 if (tmp == -EBUSY) {
    230                         snd_printk ("ISA PnP configuration appears to have "
    231                                     "been done. Restart the isapnp module.\n");
    232                 }
    233                         acard->wss->deactivate(acard->wss);
    234                         snd_printk ("ICS2115 synth preparation failed\n");
    235                         return -EAGAIN;
    236                 }
     210        pnp_init_resource_table(cfg);
     211
    237212        if (ics2115_port[dev] != SNDRV_AUTO_PORT) {
    238                 isapnp_resource_change(&pdev->resource[0], ics2115_port[dev], 16);
     213                pnp_resource_change(&cfg->port_resource[0], ics2115_port[dev], 16);
    239214        }
    240215               
    241216        if (ics2115_port[dev] != SNDRV_AUTO_IRQ) {
    242                 isapnp_resource_change(&pdev->irq_resource[0], ics2115_irq[dev], 1);
    243         }
    244 
    245                 if (pdev->activate(pdev)<0) {
    246                 snd_printk("isapnp activation for ICS2115 failed\n");
    247                         acard->wss->deactivate(acard->wss);
    248                         return -EBUSY;
    249                 }
    250                
    251         ics2115_port[dev] = pdev->resource[0].start;
    252         ics2115_irq[dev] = pdev->irq_resource[0].start;
     217                pnp_resource_change(&cfg->irq_resource[0], ics2115_irq[dev], 1);
     218        }
     219
     220        if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     221                snd_printk(KERN_ERR "PnP ICS2115 the requested resources are invalid, using auto config\n");
     222        err = pnp_activate_dev(pdev);
     223        if (err < 0) {
     224                snd_printk(KERN_ERR "PnP ICS2115 pnp configure failure\n");
     225                kfree(cfg);
     226                return err;
     227        }
     228
     229        ics2115_port[dev] = pnp_port_start(pdev, 0);
     230        ics2115_irq[dev] = pnp_irq(pdev, 0);
    253231
    254232        /* CS4232 MPU initialization. Configure this only if
     
    261239                pdev = acard->mpu;
    262240
    263                 if (pdev->prepare(pdev)<0) {
    264                         acard->wss->deactivate(acard->wss);
    265                         if (acard->synth)
    266                                 acard->synth->deactivate(acard->synth);
    267                         snd_printk ("CS4232 MPU preparation failed\n");
    268                         return -EAGAIN;
    269                 }
     241                pnp_init_resource_table(cfg);
    270242
    271243                if (cs4232_mpu_port[dev] != SNDRV_AUTO_PORT)
    272                         isapnp_resource_change(&pdev->resource[0], cs4232_mpu_port[dev], 2);
     244                        pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_port[dev], 2);
    273245                if (cs4232_mpu_irq[dev] != SNDRV_AUTO_IRQ)
    274                         isapnp_resource_change(&pdev->resource[0], cs4232_mpu_irq[dev], 1);
    275 
    276                 if (pdev->activate(pdev)<0) {
    277                         snd_printk("isapnp CS4232 MPU activation failed\n");
     246                        pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_irq[dev], 1);
     247
     248                if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
     249                        snd_printk(KERN_ERR "PnP MPU401 the requested resources are invalid, using auto config\n");
     250                err = pnp_activate_dev(pdev);
     251                if (err < 0) {
     252                        snd_printk(KERN_ERR "PnP MPU401 pnp configure failure\n");
    278253                        cs4232_mpu_port[dev] = SNDRV_AUTO_PORT;
    279254                } else {
    280                         cs4232_mpu_port[dev] = pdev->resource[0].start;
    281                         cs4232_mpu_irq[dev] = pdev->irq_resource[0].start;
     255                        cs4232_mpu_port[dev] = pnp_port_start(pdev, 0);
     256                        cs4232_mpu_irq[dev] = pnp_irq(pdev, 0);
    282257                }
    283258
     
    296271                    ics2115_irq[dev]);
    297272
     273        kfree(cfg);
    298274        return 0;
    299275}
    300276
    301 static void
    302 snd_wavefront_deactivate (snd_wavefront_card_t *acard)
    303 {
    304         snd_printk ("deactivating PnP devices\n");
    305         if (acard->wss) {
    306                 acard->wss->deactivate(acard->wss);
    307                 acard->wss = NULL;
    308         }
    309         if (acard->ctrl) {
    310                 acard->ctrl->deactivate(acard->ctrl);
    311                 acard->ctrl = NULL;
    312         }
    313         if (acard->mpu) {
    314                 acard->mpu->deactivate(acard->mpu);
    315                 acard->mpu = NULL;
    316         }
    317         if (acard->synth) {
    318                 acard->synth->deactivate(acard->synth);
    319                 acard->synth = NULL;
    320         }
    321 }
    322 
    323 #endif /* __ISAPNP__ */
    324 
    325 static void snd_wavefront_ics2115_interrupt(int irq,
     277#endif /* CONFIG_PNP */
     278
     279static irqreturn_t snd_wavefront_ics2115_interrupt(int irq,
    326280                                            void *dev_id,
    327281                                            struct pt_regs *regs)
     
    332286
    333287        if (acard == NULL)
    334                 return;
     288                return IRQ_NONE;
    335289
    336290        if (acard->wavefront.interrupts_are_midi) {
     
    339293                snd_wavefront_internal_interrupt (acard);
    340294        }
    341 }
    342 
    343 snd_hwdep_t * __init
     295        return IRQ_HANDLED;
     296}
     297
     298snd_hwdep_t * __devinit
    344299snd_wavefront_new_synth (snd_card_t *card,
    345300                         int hw_dev,
     
    367322}
    368323
    369 snd_hwdep_t * __init
     324snd_hwdep_t * __devinit
    370325snd_wavefront_new_fx (snd_card_t *card,
    371326                      int hw_dev,
     
    394349static snd_wavefront_mpu_id external_id = external_mpu;
    395350
    396 snd_rawmidi_t * __init
     351snd_rawmidi_t * __devinit
    397352snd_wavefront_new_midi (snd_card_t *card,
    398353                        int midi_dev,
     
    441396       
    442397        if (acard) {
    443 #ifdef __ISAPNP__
    444                 snd_wavefront_deactivate(acard);
    445 #endif
    446398                if (acard->wavefront.res_base != NULL) {
    447399                        release_resource(acard->wavefront.res_base);
     
    453405}
    454406
    455 static int __init
    456 snd_wavefront_probe (int dev)
     407static int __devinit
     408snd_wavefront_probe (int dev, struct pnp_card_link *pcard,
     409                     const struct pnp_card_device_id *pid)
    457410{
    458411        snd_card_t *card;
     
    472425                ics2115_port[dev] = SNDRV_AUTO_PORT;
    473426
    474 #ifdef __ISAPNP__
     427#ifdef CONFIG_PNP
    475428        if (!isapnp[dev]) {
    476429#endif
     
    483436                        return -ENODEV;
    484437                }
    485 #ifdef __ISAPNP__
     438#ifdef CONFIG_PNP
    486439        }
    487440#endif
     
    502455        card->private_free = snd_wavefront_free;
    503456
    504 #ifdef __ISAPNP__
    505         if (isapnp[dev] && snd_wavefront_isapnp (dev, acard) < 0) {
     457#ifdef CONFIG_PNP
     458        if (isapnp[dev] && snd_wavefront_pnp (dev, acard, pcard, pid) < 0) {
    506459                if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
    507460                        snd_printk ("isapnp detection failed\n");
     
    510463                }
    511464        }
    512 #endif /* __ISAPNP__ */
     465#endif /* CONFIG_PNP */
    513466
    514467        /* --------- PCM --------------- */
     
    694647                return err;
    695648        }
    696         snd_wavefront_cards[dev] = card;
     649        if (pcard)
     650                pnp_set_card_drvdata(pcard, card);
     651        else
     652                snd_wavefront_legacy[dev] = card;
    697653        return 0;
    698654}       
    699655
    700 #ifdef __ISAPNP__
    701 
    702 static int __init snd_wavefront_isapnp_detect(struct isapnp_card *card,
    703                                               const struct isapnp_card_id *id)
     656#ifdef CONFIG_PNP
     657
     658static int __devinit snd_wavefront_pnp_detect(struct pnp_card_link *card,
     659                                              const struct pnp_card_device_id *id)
    704660{
    705661        static int dev;
     
    709665                if (!enable[dev] || !isapnp[dev])
    710666                        continue;
    711                 snd_wavefront_isapnp_cards[dev] = card;
    712                 snd_wavefront_isapnp_id[dev] = id;
    713                 res = snd_wavefront_probe(dev);
     667                res = snd_wavefront_probe(dev, card, id);
    714668                if (res < 0)
    715669                        return res;
     
    721675}
    722676
    723 #endif /* __ISAPNP__ */
     677static void __devexit snd_wavefront_pnp_remove(struct pnp_card_link * pcard)
     678{
     679        snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
     680
     681        snd_card_disconnect(card);
     682        snd_card_free_in_thread(card);
     683}
     684
     685static struct pnp_card_driver wavefront_pnpc_driver = {
     686        .flags          = PNP_DRIVER_RES_DISABLE,
     687        .name           = "wavefront",
     688        .id_table       = snd_wavefront_pnpids,
     689        .probe          = snd_wavefront_pnp_detect,
     690        .remove         = __devexit_p(snd_wavefront_pnp_remove),
     691};
     692
     693#endif /* CONFIG_PNP */
    724694
    725695static int __init alsa_card_wavefront_init(void)
     
    730700                if (!enable[dev])
    731701                        continue;
    732 #ifdef __ISAPNP__
     702#ifdef CONFIG_PNP
    733703                if (isapnp[dev])
    734704                        continue;
    735705#endif
    736                 if (snd_wavefront_probe(dev) >= 0)
     706                if (snd_wavefront_probe(dev, NULL, NULL) >= 0)
    737707                        cards++;
    738708        }
    739 #ifdef __ISAPNP__
    740         cards += isapnp_probe_cards(snd_wavefront_pnpids, snd_wavefront_isapnp_detect);
     709#ifdef CONFIG_PNP
     710        cards += pnp_register_card_driver(&wavefront_pnpc_driver);
    741711#endif
    742712        if (!cards) {
     713#ifdef CONFIG_PNP
     714                pnp_unregister_card_driver(&wavefront_pnpc_driver);
     715#endif
    743716#ifdef MODULE
    744717                printk (KERN_ERR "No WaveFront cards found or devices busy\n");
     
    753726        int idx;
    754727
     728#ifdef CONFIG_PNP
     729        pnp_unregister_card_driver(&wavefront_pnpc_driver);
     730#endif
    755731        for (idx = 0; idx < SNDRV_CARDS; idx++)
    756                 snd_card_free(snd_wavefront_cards[idx]);
     732                snd_card_free(snd_wavefront_legacy[idx]);
    757733}
    758734
  • GPL/branches/alsa-resync1/alsa-kernel/isa/wavefront/wavefront_fx.c

    r224 r246  
    228228   utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
    229229   of the port I/O done, using the Yamaha faxback document as a guide
    230    to add more logic to the code. Its really pretty wierd.
     230   to add more logic to the code. Its really pretty weird.
    231231
    232232   There was an alternative approach of just dumping the whole I/O
     
    693693}
    694694
    695 /* wierd stuff, derived from port I/O tracing with dosemu */
     695/* weird stuff, derived from port I/O tracing with dosemu */
    696696
    697697static unsigned char page_zero[] __initdata = {
  • GPL/branches/alsa-resync1/alsa-kernel/isa/wavefront/wavefront_synth.c

    r224 r246  
    520520WaveFront data munging   
    521521
    522 Things here are wierd. All data written to the board cannot
     522Things here are weird. All data written to the board cannot
    523523have its most significant bit set. Any data item with values
    524524potentially > 0x7F (127) must be split across multiple bytes.
     
    529529efficient approach to handling both cases seems to be to use 2
    530530different functions for munging and 2 for de-munging. This avoids
    531 wierd casting and worrying about bit-level offsets.
     531weird casting and worrying about bit-level offsets.
    532532
    533533**********************************************************************/
     
    909909        if (header->size) {
    910910
    911                 /* XXX its a debatable point whether or not RDONLY semantics
     911                /* XXX it's a debatable point whether or not RDONLY semantics
    912912                   on the ROM samples should cover just the sample data or
    913913                   the sample header. For now, it only covers the sample data,
     
    10371037                             shptr, 4);
    10381038       
    1039         /* This one is truly wierd. What kind of wierdo decided that in
     1039        /* This one is truly weird. What kind of weirdo decided that in
    10401040           a system dominated by 16 and 32 bit integers, they would use
    10411041           a just 12 bits ?
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ak4xxx.c

    r244 r246  
    3030#include "ice1712.h"
    3131
     32static void snd_ice1712_akm4xxx_lock(akm4xxx_t *ak, int chip)
     33{
     34        ice1712_t *ice = ak->private_data[0];
     35
     36        snd_ice1712_save_gpio_status(ice);
     37}
     38
     39static void snd_ice1712_akm4xxx_unlock(akm4xxx_t *ak, int chip)
     40{
     41        ice1712_t *ice = ak->private_data[0];
     42
     43        snd_ice1712_restore_gpio_status(ice);
     44}
    3245
    3346/*
    3447 * write AK4xxx register
    3548 */
    36 void snd_ice1712_akm4xxx_write(akm4xxx_t *ak, int chip,
    37                               unsigned char addr, unsigned char data)
     49static void snd_ice1712_akm4xxx_write(akm4xxx_t *ak, int chip,
     50                                      unsigned char addr, unsigned char data)
    3851{
    3952        unsigned int tmp;
    4053        int idx;
    4154        unsigned int addrdata;
    42         ice1712_t *ice = ak->chip;
     55        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     56        ice1712_t *ice = ak->private_data[0];
    4357
    4458        snd_assert(chip >= 0 && chip < 4, return);
    4559
    46         if (ak->ops.start) {
    47                 if (ak->ops.start(ak, chip) < 0)
    48                         return;
    49         } else
    50                 snd_ice1712_save_gpio_status(ice);
    51 
    5260        tmp = snd_ice1712_gpio_read(ice);
    53         tmp |= ak->add_flags;
    54         tmp &= ~ak->mask_flags;
    55         if (ak->cs_mask == ak->cs_addr) {
    56                 if (ak->cif) {
    57                         tmp |= ak->cs_mask; /* start without chip select */
     61        tmp |= priv->add_flags;
     62        tmp &= ~priv->mask_flags;
     63        if (priv->cs_mask == priv->cs_addr) {
     64                if (priv->cif) {
     65                        tmp |= priv->cs_mask; /* start without chip select */
    5866                }  else {
    59                         tmp &= ~ak->cs_mask; /* chip select low */
     67                        tmp &= ~priv->cs_mask; /* chip select low */
    6068                        snd_ice1712_gpio_write(ice, tmp);
    6169                        udelay(1);
     
    6371        } else {
    6472                /* doesn't handle cf=1 yet */
    65                 tmp &= ~ak->cs_mask;
    66                 tmp |= ak->cs_addr;
     73                tmp &= ~priv->cs_mask;
     74                tmp |= priv->cs_addr;
    6775                snd_ice1712_gpio_write(ice, tmp);
    6876                udelay(1);
     
    7078
    7179        /* build I2C address + data byte */
    72         addrdata = (ak->caddr << 6) | 0x20 | (addr & 0x1f);
     80        addrdata = (priv->caddr << 6) | 0x20 | (addr & 0x1f);
    7381        addrdata = (addrdata << 8) | data;
    7482        for (idx = 15; idx >= 0; idx--) {
    7583                /* drop clock */
    76                 tmp &= ~ak->clk_mask;
     84                tmp &= ~priv->clk_mask;
    7785                snd_ice1712_gpio_write(ice, tmp);
    7886                udelay(1);
    7987                /* set data */
    8088                if (addrdata & (1 << idx))
    81                         tmp |= ak->data_mask;
     89                        tmp |= priv->data_mask;
    8290                else
    83                         tmp &= ~ak->data_mask;
     91                        tmp &= ~priv->data_mask;
    8492                snd_ice1712_gpio_write(ice, tmp);
    8593                udelay(1);
    8694                /* raise clock */
    87                 tmp |= ak->clk_mask;
     95                tmp |= priv->clk_mask;
    8896                snd_ice1712_gpio_write(ice, tmp);
    8997                udelay(1);
     
    101109        }
    102110       
    103         if (ak->cs_mask == ak->cs_addr) {
    104                 if (ak->cif) {
     111        if (priv->cs_mask == priv->cs_addr) {
     112                if (priv->cif) {
    105113                        /* assert a cs pulse to trigger */
    106                         tmp &= ~ak->cs_mask;
     114                        tmp &= ~priv->cs_mask;
    107115                        snd_ice1712_gpio_write(ice, tmp);
    108116                        udelay(1);
    109117                }
    110                 tmp |= ak->cs_mask; /* chip select high to trigger */
     118                tmp |= priv->cs_mask; /* chip select high to trigger */
    111119        } else {
    112                 tmp &= ~ak->cs_mask;
    113                 tmp |= ak->cs_none; /* deselect address */
     120                tmp &= ~priv->cs_mask;
     121                tmp |= priv->cs_none; /* deselect address */
    114122        }
    115123        snd_ice1712_gpio_write(ice, tmp);
    116124        udelay(1);
    117 
    118         if (ak->ops.stop)
    119                 ak->ops.stop(ak);
    120         else
    121                 snd_ice1712_restore_gpio_status(ice);
    122125}
    123 
    124 /*
    125  * reset the AKM codecs
    126  * @state: 1 = reset codec, 0 = restore the registers
    127  *
    128  * assert the reset operation and restores the register values to the chips.
    129  */
    130 void snd_ice1712_akm4xxx_reset(akm4xxx_t *ak, int state)
    131 {
    132         unsigned int chip;
    133         unsigned char reg;
    134        
    135         switch (ak->type) {
    136         case SND_AK4524:
    137         case SND_AK4528:
    138                 for (chip = 0; chip < ak->num_dacs/2; chip++) {
    139                         snd_ice1712_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
    140                         if (state)
    141                                 continue;
    142                         /* DAC volumes */
    143                         for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
    144                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->images[chip][reg]);
    145                         if (ak->type == SND_AK4528)
    146                                 continue;
    147                         /* IPGA */
    148                         for (reg = 0x04; reg < 0x06; reg++)
    149                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->ipga_gain[chip][reg-4]);
    150                 }
    151                 break;
    152         case SND_AK4529:
    153                 /* FIXME: needed for ak4529? */
    154                 break;
    155         case SND_AK4355:
    156                 snd_ice1712_akm4xxx_write(ak, 0, 0x01, state ? 0x02 : 0x01);
    157                 if (state)
    158                         return;
    159                 for (reg = 0x00; reg < 0x0a; reg++)
    160                         if (reg != 0x01)
    161                                 snd_ice1712_akm4xxx_write(ak, 0, reg, ak->images[0][reg]);
    162                 break;
    163         case SND_AK4381:
    164                 for (chip = 0; chip < ak->num_dacs/2; chip++) {
    165                         snd_ice1712_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
    166                         if (state)
    167                                 continue;
    168                         for (reg = 0x01; reg < 0x05; reg++)
    169                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->images[chip][reg]);
    170                 }
    171                 break;
    172         }
    173 }
    174 
    175 /*
    176  * initialize all the ak4xxx chips
    177  */
    178 static void __devinit snd_ice1712_akm4xxx_init_chip(akm4xxx_t *ak)
    179 {
    180         static unsigned char inits_ak4524[] = {
    181                 0x00, 0x07, /* 0: all power up */
    182                 0x01, 0x00, /* 1: ADC/DAC reset */
    183                 0x02, 0x60, /* 2: 24bit I2S */
    184                 0x03, 0x19, /* 3: deemphasis off */
    185                 0x01, 0x03, /* 1: ADC/DAC enable */
    186                 0x04, 0x00, /* 4: ADC left muted */
    187                 0x05, 0x00, /* 5: ADC right muted */
    188                 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
    189                 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
    190                 0x06, 0x00, /* 6: DAC left muted */
    191                 0x07, 0x00, /* 7: DAC right muted */
    192                 0xff, 0xff
    193         };
    194         static unsigned char inits_ak4528[] = {
    195                 0x00, 0x07, /* 0: all power up */
    196                 0x01, 0x00, /* 1: ADC/DAC reset */
    197                 0x02, 0x60, /* 2: 24bit I2S */
    198                 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
    199                 0x01, 0x03, /* 1: ADC/DAC enable */
    200                 0x04, 0x00, /* 4: ADC left muted */
    201                 0x05, 0x00, /* 5: ADC right muted */
    202                 0xff, 0xff
    203         };
    204         static unsigned char inits_ak4529[] = {
    205                 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
    206                 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
    207                 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
    208                 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
    209                 0x02, 0xff, /* 2: LOUT1 muted */
    210                 0x03, 0xff, /* 3: ROUT1 muted */
    211                 0x04, 0xff, /* 4: LOUT2 muted */
    212                 0x05, 0xff, /* 5: ROUT2 muted */
    213                 0x06, 0xff, /* 6: LOUT3 muted */
    214                 0x07, 0xff, /* 7: ROUT3 muted */
    215                 0x0b, 0xff, /* B: LOUT4 muted */
    216                 0x0c, 0xff, /* C: ROUT4 muted */
    217                 0x08, 0x55, /* 8: deemphasis all off */
    218                 0xff, 0xff
    219         };
    220         static unsigned char inits_ak4355[] = {
    221                 0x01, 0x02, /* 1: reset and soft-mute */
    222                 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
    223                 // 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
    224                 0x02, 0x2e,
    225                 0x03, 0x01, /* 3: de-emphasis off */
    226                 0x04, 0x00, /* 4: LOUT1 volume muted */
    227                 0x05, 0x00, /* 5: ROUT1 volume muted */
    228                 0x06, 0x00, /* 6: LOUT2 volume muted */
    229                 0x07, 0x00, /* 7: ROUT2 volume muted */
    230                 0x08, 0x00, /* 8: LOUT3 volume muted */
    231                 0x09, 0x00, /* 9: ROUT3 volume muted */
    232                 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
    233                 0x01, 0x01, /* 1: un-reset, unmute */
    234                 0xff, 0xff
    235         };
    236         static unsigned char inits_ak4381[] = {
    237                 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
    238                 // 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
    239                 0x01, 0x12,
    240                 0x02, 0x00, /* 2: DZF disabled */
    241                 0x03, 0x00, /* 3: LATT 0 */
    242                 0x04, 0x00, /* 4: RATT 0 */
    243                 0x00, 0x0f, /* 0: power-up, un-reset */
    244                 0xff, 0xff
    245         };
    246 
    247         int chip, num_chips;
    248         unsigned char *ptr, reg, data, *inits;
    249 
    250         switch (ak->type) {
    251         case SND_AK4524:
    252                 inits = inits_ak4524;
    253                 num_chips = ak->num_dacs / 2;
    254                 break;
    255         case SND_AK4528:
    256                 inits = inits_ak4528;
    257                 num_chips = ak->num_dacs / 2;
    258                 break;
    259         case SND_AK4529:
    260                 inits = inits_ak4529;
    261                 num_chips = 1;
    262                 break;
    263         case SND_AK4355:
    264                 inits = inits_ak4355;
    265                 num_chips = 1;
    266                 break;
    267         case SND_AK4381:
    268                 inits = inits_ak4381;
    269                 num_chips = ak->num_dacs / 2;
    270                 break;
    271         default:
    272                 snd_BUG();
    273                 return;
    274         }
    275 
    276         for (chip = 0; chip < num_chips; chip++) {
    277                 ptr = inits;
    278                 while (*ptr != 0xff) {
    279                         reg = *ptr++;
    280                         data = *ptr++;
    281                         snd_ice1712_akm4xxx_write(ak, chip, reg, data);
    282                 }
    283         }
    284 }
    285 
    286126
    287127/*
    288128 * initialize the akm4xxx_t record with the template
    289129 */
    290 void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp, ice1712_t *ice)
     130int __devinit snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp,
     131                                       const struct snd_ak4xxx_private *_priv, ice1712_t *ice)
    291132{
     133        struct snd_ak4xxx_private *priv;
     134
     135        priv = kmalloc(sizeof(*priv), GFP_KERNEL);
     136        if (priv == NULL)
     137                return -ENOMEM;
    292138        *ak = *temp;
    293         ak->chip = ice;
    294         snd_ice1712_akm4xxx_init_chip(ak);
    295 }
    296 
    297 
    298 #define AK_GET_CHIP(val)                (((val) >> 8) & 0xff)
    299 #define AK_GET_ADDR(val)                ((val) & 0xff)
    300 #define AK_GET_SHIFT(val)               (((val) >> 16) & 0x7f)
    301 #define AK_GET_INVERT(val)              (((val) >> 23) & 1)
    302 #define AK_GET_MASK(val)                (((val) >> 24) & 0xff)
    303 #define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
    304 #define AK_INVERT                       (1<<23)
    305 
    306 static int snd_ice1712_akm4xxx_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    307 {
    308         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    309 
    310         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    311         uinfo->count = 1;
    312         uinfo->value.integer.min = 0;
    313         uinfo->value.integer.max = mask;
     139        ak->card = ice->card;
     140        *priv = *_priv;
     141        ak->private_value[0] = (unsigned long)priv;
     142        ak->private_data[0] = ice;
     143        if (ak->ops.lock == NULL)
     144                ak->ops.lock = snd_ice1712_akm4xxx_lock;
     145        if (ak->ops.unlock == NULL)
     146                ak->ops.unlock = snd_ice1712_akm4xxx_unlock;
     147        if (ak->ops.write == NULL)
     148                ak->ops.write = snd_ice1712_akm4xxx_write;
     149        snd_akm4xxx_init(ak);
    314150        return 0;
    315151}
    316152
    317 static int snd_ice1712_akm4xxx_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     153void __devexit snd_ice1712_akm4xxx_free(ice1712_t *ice)
    318154{
    319         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    320         int chip = AK_GET_CHIP(kcontrol->private_value);
    321         int addr = AK_GET_ADDR(kcontrol->private_value);
    322         int invert = AK_GET_INVERT(kcontrol->private_value);
    323         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    324         unsigned char val = ak->images[chip][addr];
    325        
    326         ucontrol->value.integer.value[0] = invert ? mask - val : val;
    327         return 0;
    328 }
    329 
    330 static int snd_ice1712_akm4xxx_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    331 {
    332         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    333         int chip = AK_GET_CHIP(kcontrol->private_value);
    334         int addr = AK_GET_ADDR(kcontrol->private_value);
    335         int invert = AK_GET_INVERT(kcontrol->private_value);
    336         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    337         unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
    338         int change;
    339 
    340         if (invert)
    341                 nval = mask - nval;
    342         change = ak->images[chip][addr] != nval;
    343         if (change)
    344                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    345         return change;
    346 }
    347 
    348 static int snd_ice1712_akm4xxx_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    349 {
    350         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    351         uinfo->count = 1;
    352         uinfo->value.integer.min = 0;
    353         uinfo->value.integer.max = 36;
    354         return 0;
    355 }
    356 
    357 static int snd_ice1712_akm4xxx_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    358 {
    359         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    360         int chip = AK_GET_CHIP(kcontrol->private_value);
    361         int addr = AK_GET_ADDR(kcontrol->private_value);
    362         ucontrol->value.integer.value[0] = ak->ipga_gain[chip][addr-4] & 0x7f;
    363         return 0;
    364 }
    365 
    366 static int snd_ice1712_akm4xxx_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    367 {
    368         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    369         int chip = AK_GET_CHIP(kcontrol->private_value);
    370         int addr = AK_GET_ADDR(kcontrol->private_value);
    371         unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
    372         int change = ak->ipga_gain[chip][addr] != nval;
    373         if (change)
    374                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    375         return change;
    376 }
    377 
    378 static int snd_ice1712_akm4xxx_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
    379 {
    380         static char *texts[4] = {
    381                 "44.1kHz", "Off", "48kHz", "32kHz",
    382         };
    383         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    384         uinfo->count = 1;
    385         uinfo->value.enumerated.items = 4;
    386         if (uinfo->value.enumerated.item >= 4)
    387                 uinfo->value.enumerated.item = 3;
    388         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    389         return 0;
    390 }
    391 
    392 static int snd_ice1712_akm4xxx_deemphasis_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
    393 {
    394         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    395         int chip = AK_GET_CHIP(kcontrol->private_value);
    396         int addr = AK_GET_ADDR(kcontrol->private_value);
    397         int shift = AK_GET_SHIFT(kcontrol->private_value);
    398         ucontrol->value.enumerated.item[0] = (ak->images[chip][addr] >> shift) & 3;
    399         return 0;
    400 }
    401 
    402 static int snd_ice1712_akm4xxx_deemphasis_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    403 {
    404         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    405         int chip = AK_GET_CHIP(kcontrol->private_value);
    406         int addr = AK_GET_ADDR(kcontrol->private_value);
    407         int shift = AK_GET_SHIFT(kcontrol->private_value);
    408         unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
    409         int change;
    410        
    411         nval = (nval << shift) | (ak->images[chip][addr] & ~(3 << shift));
    412         change = ak->images[chip][addr] != nval;
    413         if (change)
    414                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    415         return change;
     155        unsigned int akidx;
     156        if (ice->akm == NULL)
     157                return;
     158        for (akidx = 0; akidx < ice->akm_codecs; akidx++) {
     159                akm4xxx_t *ak = &ice->akm[akidx];
     160                if (ak->private_value[0])
     161                        kfree((void *)ak->private_value[0]);
     162        }
     163        kfree(ice->akm);
    416164}
    417165
    418166/*
    419  * build AK4524 controls
     167 * build AK4xxx controls
    420168 */
    421 
    422169int __devinit snd_ice1712_akm4xxx_build_controls(ice1712_t *ice)
    423170{
    424         unsigned int idx;
     171        unsigned int akidx;
    425172        int err;
    426         unsigned int akidx;
    427173
    428174        for (akidx = 0; akidx < ice->akm_codecs; akidx++) {
    429175                akm4xxx_t *ak = &ice->akm[akidx];
    430                 for (idx = 0; idx < ak->num_dacs; ++idx) {
    431                         snd_kcontrol_t ctl;
    432                         memset(&ctl, 0, sizeof(ctl));
    433                         strcpy(ctl.id.name, "DAC Volume");
    434                         ctl.id.index = idx + ak->idx_offset * 2;
    435                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    436                         ctl.info = snd_ice1712_akm4xxx_volume_info;
    437                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    438                         ctl.get = snd_ice1712_akm4xxx_volume_get;
    439                         ctl.put = snd_ice1712_akm4xxx_volume_put;
    440                         switch (ak->type) {
    441                         case SND_AK4524:
    442                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
    443                                 break;
    444                         case SND_AK4528:
    445                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
    446                                 break;
    447                         case SND_AK4529: {
    448                                 int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
    449                                 ctl.private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
    450                                 break;
    451                         }
    452                         case SND_AK4355:
    453                                 ctl.private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
    454                                 break;
    455                         case SND_AK4381:
    456                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
    457                                 break;
    458                         default:
    459                                 return -EINVAL;
    460                         }
    461                         ctl.private_data = ak;
    462                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    463                                 return err;
    464                 }
    465                 for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
    466                         snd_kcontrol_t ctl;
    467                         memset(&ctl, 0, sizeof(ctl));
    468                         strcpy(ctl.id.name, "ADC Volume");
    469                         ctl.id.index = idx;
    470                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    471                         ctl.info = snd_ice1712_akm4xxx_volume_info;
    472                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    473                         ctl.get = snd_ice1712_akm4xxx_volume_get;
    474                         ctl.put = snd_ice1712_akm4xxx_volume_put;
    475                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
    476                         ctl.private_data = ak;
    477                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    478                                 return err;
    479                         memset(&ctl, 0, sizeof(ctl));
    480                         strcpy(ctl.id.name, "IPGA Analog Capture Volume");
    481                         ctl.id.index = idx;
    482                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    483                         ctl.info = snd_ice1712_akm4xxx_ipga_gain_info;
    484                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    485                         ctl.get = snd_ice1712_akm4xxx_ipga_gain_get;
    486                         ctl.put = snd_ice1712_akm4xxx_ipga_gain_put;
    487                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
    488                         ctl.private_data = ak;
    489                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    490                                 return err;
    491                 }
    492                 for (idx = 0; idx < ak->num_dacs/2; idx++) {
    493                         snd_kcontrol_t ctl;
    494                         memset(&ctl, 0, sizeof(ctl));
    495                         strcpy(ctl.id.name, "Deemphasis");
    496                         ctl.id.index = idx + ak->idx_offset;
    497                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    498                         ctl.info = snd_ice1712_akm4xxx_deemphasis_info;
    499                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    500                         ctl.get = snd_ice1712_akm4xxx_deemphasis_get;
    501                         ctl.put = snd_ice1712_akm4xxx_deemphasis_put;
    502                         switch (ak->type) {
    503                         case SND_AK4524:
    504                         case SND_AK4528:
    505                                 ctl.private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
    506                                 break;
    507                         case SND_AK4529: {
    508                                 int shift = idx == 3 ? 6 : (2 - idx) * 2;
    509                                 ctl.private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
    510                                 break;
    511                         }
    512                         case SND_AK4355:
    513                                 ctl.private_value = AK_COMPOSE(idx, 3, 0, 0);
    514                                 break;
    515                         case SND_AK4381:
    516                                 ctl.private_value = AK_COMPOSE(idx, 1, 1, 0);
    517                                 break;
    518                         }
    519                         ctl.private_data = ak;
    520                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    521                                 return err;
    522                 }
     176                err = snd_akm4xxx_build_controls(ak);
     177                if (err < 0)
     178                        return err;
    523179        }
    524180        return 0;
    525181}
    526 
    527 
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/delta.c

    r224 r246  
    233233 * AK4524 on Delta 44 and 66 to choose the chip mask
    234234 */
    235 static int delta_ak4524_start(akm4xxx_t *ak, int chip)
    236 {
    237         snd_ice1712_save_gpio_status(ak->chip);
    238         ak->cs_mask =
    239         ak->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
    240                                   ICE1712_DELTA_CODEC_CHIP_B;
    241         return 0;
     235static void delta_ak4524_lock(akm4xxx_t *ak, int chip)
     236{
     237        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     238        ice1712_t *ice = ak->private_data[0];
     239
     240        snd_ice1712_save_gpio_status(ice);
     241        priv->cs_mask =
     242        priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
     243                                    ICE1712_DELTA_CODEC_CHIP_B;
    242244}
    243245
     
    245247 * AK4524 on Delta1010LT to choose the chip address
    246248 */
    247 static int delta1010lt_ak4524_start(akm4xxx_t *ak, int chip)
    248 {
    249         snd_ice1712_save_gpio_status(ak->chip);
    250         ak->cs_mask = ICE1712_DELTA_1010LT_CS;
    251         ak->cs_addr = chip << 4;
    252         return 0;
     249static void delta1010lt_ak4524_lock(akm4xxx_t *ak, int chip)
     250{
     251        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     252        ice1712_t *ice = ak->private_data[0];
     253
     254        snd_ice1712_save_gpio_status(ice);
     255        priv->cs_mask = ICE1712_DELTA_1010LT_CS;
     256        priv->cs_addr = chip << 4;
    253257}
    254258
     
    259263{
    260264        unsigned char tmp, tmp2;
    261         ice1712_t *ice = ak->chip;
     265        ice1712_t *ice = ak->private_data[0];
    262266
    263267        if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
     
    276280
    277281        /* do it again */
    278         snd_ice1712_akm4xxx_reset(ak, 1);
     282        snd_akm4xxx_reset(ak, 1);
    279283        down(&ice->gpio_mutex);
    280284        tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
     
    283287        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    284288        up(&ice->gpio_mutex);
    285         snd_ice1712_akm4xxx_reset(ak, 0);
     289        snd_akm4xxx_reset(ak, 0);
    286290}
    287291
     
    331335        .num_adcs = 2,
    332336        .num_dacs = 2,
     337        .ops = {
     338                .set_rate_val = delta_ak4524_set_rate_val
     339        }
     340};
     341
     342static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = {
    333343        .caddr = 2,
    334344        .cif = 0,
     
    340350        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
    341351        .mask_flags = 0,
    342         .ops = {
    343                 .set_rate_val = delta_ak4524_set_rate_val
    344         }
    345352};
    346353
     
    349356        .num_adcs = 2,
    350357        .num_dacs = 8,
     358        .ops = {
     359                .set_rate_val = delta_ak4524_set_rate_val
     360        }
     361};
     362
     363static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = {
    351364        .caddr = 0,
    352365        .cif = 0,
     
    358371        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
    359372        .mask_flags = 0,
    360         .ops = {
    361                 .set_rate_val = delta_ak4524_set_rate_val
    362         }
    363373};
    364374
     
    367377        .num_adcs = 8,
    368378        .num_dacs = 8,
     379        .ops = {
     380                .lock = delta1010lt_ak4524_lock,
     381                .set_rate_val = delta_ak4524_set_rate_val
     382        }
     383};
     384
     385static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
    369386        .caddr = 2,
    370387        .cif = 0, /* the default level of the CIF pin from AK4524 */
     
    376393        .add_flags = 0,
    377394        .mask_flags = 0,
    378         .ops = {
    379                 .start = delta1010lt_ak4524_start,
    380                 .set_rate_val = delta_ak4524_set_rate_val
    381         }
    382395};
    383396
     
    386399        .num_adcs = 4,
    387400        .num_dacs = 4,
     401        .ops = {
     402                .lock = delta_ak4524_lock,
     403                .set_rate_val = delta_ak4524_set_rate_val
     404        }
     405};
     406
     407static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = {
    388408        .caddr = 2,
    389409        .cif = 0, /* the default level of the CIF pin from AK4524 */
     
    395415        .add_flags = 0,
    396416        .mask_flags = 0,
    397         .ops = {
    398                 .start = delta_ak4524_start,
    399                 .set_rate_val = delta_ak4524_set_rate_val
    400         }
    401417};
    402418
     
    467483        switch (ice->eeprom.subvendor) {
    468484        case ICE1712_SUBDEVICE_AUDIOPHILE:
    469                 snd_ice1712_akm4xxx_init(ak, &akm_audiophile, ice);
     485                err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
    470486                break;
    471487        case ICE1712_SUBDEVICE_DELTA410:
    472                 snd_ice1712_akm4xxx_init(ak, &akm_delta410, ice);
     488                err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
    473489                break;
    474490        case ICE1712_SUBDEVICE_DELTA1010LT:
    475                 snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, ice);
     491                err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
    476492                break;
    477493        case ICE1712_SUBDEVICE_DELTA66:
    478494        case ICE1712_SUBDEVICE_DELTA44:
    479                 snd_ice1712_akm4xxx_init(ak, &akm_delta44, ice);
     495                err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
    480496                break;
    481497        default:
     
    484500        }
    485501
    486         return 0;
     502        return err;
    487503}
    488504
     
    535551        case ICE1712_SUBDEVICE_DELTADIO2496:
    536552        case ICE1712_SUBDEVICE_DELTA66:
    537         case ICE1712_SUBDEVICE_AUDIOPHILE:
    538         case ICE1712_SUBDEVICE_DELTA410:
    539         case ICE1712_SUBDEVICE_DELTA1010LT:
    540553                err = snd_ice1712_spdif_build_controls(ice);
    541554                if (err < 0)
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ews.c

    r224 r246  
    156156
    157157/* start callback for EWS88MT, needs to select a certain chip mask */
    158 static int ews88mt_ak4524_start(akm4xxx_t *ak, int chip)
    159 {
    160         ice1712_t *ice = ak->chip;
     158static void ews88mt_ak4524_lock(akm4xxx_t *ak, int chip)
     159{
     160        ice1712_t *ice = ak->private_data[0];
    161161        unsigned char tmp;
    162162        /* assert AK4524 CS */
    163163        if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
    164                 return -EINVAL;
     164                snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
    165165        snd_ice1712_save_gpio_status(ice);
    166166        tmp = ICE1712_EWS88_SERIAL_DATA |
     
    170170                          ice->gpio.direction | tmp);
    171171        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    172         return 0;
    173172}
    174173
    175174/* stop callback for EWS88MT, needs to deselect chip mask */
    176 static void ews88mt_ak4524_stop(akm4xxx_t *ak)
    177 {
    178         ice1712_t *ice = ak->chip;
     175static void ews88mt_ak4524_unlock(akm4xxx_t *ak, int chip)
     176{
     177        ice1712_t *ice = ak->private_data[0];
    179178        snd_ice1712_restore_gpio_status(ice);
    180179        udelay(1);
     
    183182
    184183/* start callback for EWX24/96 */
    185 static int ewx2496_ak4524_start(akm4xxx_t *ak, int chip)
    186 {
    187         ice1712_t *ice = ak->chip;
     184static void ewx2496_ak4524_lock(akm4xxx_t *ak, int chip)
     185{
     186        ice1712_t *ice = ak->private_data[0];
    188187        unsigned char tmp;
    189188        snd_ice1712_save_gpio_status(ice);
     
    195194                          ice->gpio.direction | tmp);
    196195        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    197         return 0;
    198196}
    199197
    200198/* start callback for DMX 6fire */
    201 static int dmx6fire_ak4524_start(akm4xxx_t *ak, int chip)
    202 {
    203         ice1712_t *ice = ak->chip;
     199static void dmx6fire_ak4524_lock(akm4xxx_t *ak, int chip)
     200{
     201        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     202        ice1712_t *ice = ak->private_data[0];
    204203        unsigned char tmp;
    205204        snd_ice1712_save_gpio_status(ice);
    206         tmp = ak->cs_mask = ak->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
     205        tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
    207206        tmp |= ICE1712_6FIRE_SERIAL_DATA |
    208207                ICE1712_6FIRE_SERIAL_CLOCK |
     
    211210                          ice->gpio.direction | tmp);
    212211        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    213         return 0;
    214 }
    215 
     212}
    216213
    217214/*
     
    329326        .num_dacs = 8,
    330327        .type = SND_AK4524,
     328        .ops = {
     329                .lock = ews88mt_ak4524_lock,
     330                .unlock = ews88mt_ak4524_unlock
     331        }
     332};
     333
     334static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
    331335        .caddr = 2,
    332336        .cif = 1, /* CIF high */
     
    338342        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
    339343        .mask_flags = 0,
    340         .ops = {
    341                 .start = ews88mt_ak4524_start,
    342                 .stop = ews88mt_ak4524_stop
    343         }
    344344};
    345345
     
    348348        .num_dacs = 2,
    349349        .type = SND_AK4524,
     350        .ops = {
     351                .lock = ewx2496_ak4524_lock
     352        }
     353};
     354
     355static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
    350356        .caddr = 2,
    351357        .cif = 1, /* CIF high */
     
    357363        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
    358364        .mask_flags = 0,
    359         .ops = {
    360                 .start = ewx2496_ak4524_start
    361         }
    362365};
    363366
     
    366369        .num_dacs = 6,
    367370        .type = SND_AK4524,
     371        .ops = {
     372                .lock = dmx6fire_ak4524_lock
     373        }
     374};
     375
     376static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
    368377        .caddr = 2,
    369378        .cif = 1, /* CIF high */
     
    375384        .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
    376385        .mask_flags = 0,
    377         .ops = {
    378                 .start = dmx6fire_ak4524_start
    379         }
    380 };
    381 
     386};
    382387
    383388/*
     
    480485        case ICE1712_SUBDEVICE_EWS88MT:
    481486        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    482                 snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, ice);
     487                err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
    483488                break;
    484489        case ICE1712_SUBDEVICE_EWX2496:
    485                 snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, ice);
     490                err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
    486491                break;
    487492        case ICE1712_SUBDEVICE_DMX6FIRE:
    488                 snd_ice1712_akm4xxx_init(ak, &akm_6fire, ice);
    489                 break;
    490         }
    491 
    492         return 0;
     493                err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
     494                break;
     495        default:
     496                err = 0;
     497        }
     498
     499        return err;
    493500}
    494501
     
    603610{
    604611        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    605         int channel = kcontrol->id.index;
     612        int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    606613        unsigned char data;
    607614
     
    622629{
    623630        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    624         int channel = kcontrol->id.index;
     631        int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    625632        unsigned char data, ndata;
    626633
     
    646653        .get = snd_ice1712_ews88mt_input_sense_get,
    647654        .put = snd_ice1712_ews88mt_input_sense_put,
     655        .count = 8,
    648656};
    649657
     
    895903        unsigned int idx;
    896904        int err;
    897         snd_kcontrol_t *kctl;
    898905       
    899         /* all terratec cards have spdif */
    900         err = snd_ice1712_spdif_build_controls(ice);
    901         if (err < 0)
    902                 return err;
     906        /* all terratec cards have spdif, but cs8427 module builds it's own controls */
     907        if (ice->cs8427 == NULL) {
     908                err = snd_ice1712_spdif_build_controls(ice);
     909                if (err < 0)
     910                        return err;
     911        }
    903912
    904913        /* ak4524 controls */
     
    925934        case ICE1712_SUBDEVICE_EWS88MT:
    926935        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    927                 for (idx = 0; idx < 8; idx++) {
    928                         kctl = snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice);
    929                         kctl->id.index = idx;
    930                         err = snd_ctl_add(ice->card, kctl);
    931                         if (err < 0)
    932                                 return err;
    933                 }
     936                err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
     937                if (err < 0)
     938                        return err;
    934939                err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
    935940                if (err < 0)
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.c

    r231 r246  
    119119
    120120/*
     121 *  AK4xxx stuff
     122 */
     123
     124#include "ak4xxx.c"
     125
     126/*
    121127 *  Basic I/O
    122128 */
     
    399405 */
    400406
    401 static void snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    402 {
    403         ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return);
     407static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     408{
     409        ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
    404410        unsigned char status;
     411        int handled = 0;
    405412
    406413        while (1) {
     
    408415                if (status == 0)
    409416                        break;
     417                handled = 1;
    410418                if (status & ICE1712_IRQ_MPU1) {
    411419                        if (ice->rmidi[0])
     
    463471                }
    464472        }
     473        return IRQ_RETVAL(handled);
    465474}
    466475
     
    963972                unsigned int what = 0;
    964973                unsigned int old;
    965                 snd_pcm_substream_t *s = substream;
    966 
    967                 do {
     974                struct list_head *pos;
     975                snd_pcm_substream_t *s;
     976
     977                snd_pcm_group_for_each(pos, substream) {
     978                        s = snd_pcm_group_substream_entry(pos);
    968979                        if (s == ice->playback_pro_substream) {
    969980                                what |= ICE1712_PLAYBACK_START;
     
    973984                                snd_pcm_trigger_done(s, substream);
    974985                        }
    975                         s = s->link_next;
    976                 } while (s != substream);
     986                }
    977987                spin_lock(&ice->reg_lock);
    978988                old = inl(ICEMT(ice, PLAYBACK_CONTROL));
     
    12971307{
    12981308        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1299         int index = kcontrol->private_value;
     1309        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13001310       
    13011311        spin_lock_irq(&ice->reg_lock);
     
    13091319{
    13101320        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1311         int index = kcontrol->private_value;
     1321        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13121322        unsigned int nval, change;
    13131323
     
    13351345{
    13361346        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1337         int index = kcontrol->private_value;
     1347        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13381348       
    13391349        spin_lock_irq(&ice->reg_lock);
     
    13471357{
    13481358        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1349         int index = kcontrol->private_value;
     1359        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13501360        unsigned int nval, change;
    13511361
     
    13621372
    13631373
     1374static snd_kcontrol_new_t snd_ice1712_multi_ctrls[] __devinitdata = {
     1375        {
     1376                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1377                .name = "Multi Playback Switch",
     1378                .info = snd_ice1712_pro_mixer_switch_info,
     1379                .get = snd_ice1712_pro_mixer_switch_get,
     1380                .put = snd_ice1712_pro_mixer_switch_put,
     1381                .private_value = 0,
     1382                .count = 10,
     1383        },
     1384        {
     1385                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1386                .name = "Multi Playback Volume",
     1387                .info = snd_ice1712_pro_mixer_volume_info,
     1388                .get = snd_ice1712_pro_mixer_volume_get,
     1389                .put = snd_ice1712_pro_mixer_volume_put,
     1390                .private_value = 0,
     1391                .count = 10,
     1392        },
     1393        {
     1394                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1395                .name = "Multi Capture Switch",
     1396                .info = snd_ice1712_pro_mixer_switch_info,
     1397                .get = snd_ice1712_pro_mixer_switch_get,
     1398                .put = snd_ice1712_pro_mixer_switch_put,
     1399                .private_value = 10,
     1400                .count = 10,
     1401        },
     1402        {
     1403                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1404                .name = "Multi Capture Volume",
     1405                .info = snd_ice1712_pro_mixer_volume_info,
     1406                .get = snd_ice1712_pro_mixer_volume_get,
     1407                .put = snd_ice1712_pro_mixer_volume_put,
     1408                .private_value = 10,
     1409                .count = 10,
     1410        },
     1411};
     1412
    13641413static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
    13651414{
    13661415        snd_card_t * card = ice->card;
    1367         snd_kcontrol_t ctl;
    1368         int idx, err;
    1369 
    1370         /* PCM playback */
    1371         for (idx = 0; idx < 10; idx++) {
    1372                 memset(&ctl, 0, sizeof(ctl));
    1373                 strcpy(ctl.id.name, "Multi Playback Switch");
    1374                 ctl.id.index = idx;
    1375                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1376                 ctl.info = snd_ice1712_pro_mixer_switch_info;
    1377                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1378                 ctl.get = snd_ice1712_pro_mixer_switch_get;
    1379                 ctl.put = snd_ice1712_pro_mixer_switch_put;
    1380                 ctl.private_value = idx;
    1381                 ctl.private_data = ice;
    1382                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1383                         return err;
    1384                 memset(&ctl, 0, sizeof(ctl));
    1385                 strcpy(ctl.id.name, "Multi Playback Volume");
    1386                 ctl.id.index = idx;
    1387                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1388                 ctl.info = snd_ice1712_pro_mixer_volume_info;
    1389                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1390                 ctl.get = snd_ice1712_pro_mixer_volume_get;
    1391                 ctl.put = snd_ice1712_pro_mixer_volume_put;
    1392                 ctl.private_value = idx;
    1393                 ctl.private_data = ice;
    1394                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1395                         return err;
    1396         }
    1397 
    1398         /* PCM capture */
    1399         for (idx = 0; idx < 10; idx++) {
    1400                 memset(&ctl, 0, sizeof(ctl));
    1401                 strcpy(ctl.id.name, "Multi Capture Switch");
    1402                 ctl.id.index = idx;
    1403                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1404                 ctl.info = snd_ice1712_pro_mixer_switch_info;
    1405                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1406                 ctl.get = snd_ice1712_pro_mixer_switch_get;
    1407                 ctl.put = snd_ice1712_pro_mixer_switch_put;
    1408                 ctl.private_value = idx + 10;
    1409                 ctl.private_data = ice;
    1410                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1411                         return err;
    1412                 memset(&ctl, 0, sizeof(ctl));
    1413                 strcpy(ctl.id.name, "Multi Capture Volume");
    1414                 ctl.id.index = idx;
    1415                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1416                 ctl.info = snd_ice1712_pro_mixer_volume_info;
    1417                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1418                 ctl.get = snd_ice1712_pro_mixer_volume_get;
    1419                 ctl.put = snd_ice1712_pro_mixer_volume_put;
    1420                 ctl.private_value = idx + 10;
    1421                 ctl.private_data = ice;
    1422                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
     1416        unsigned int idx;
     1417        int err;
     1418
     1419        /* multi-channel mixer */
     1420        for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_ctrls); idx++) {
     1421                err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_ctrls[idx], ice));
     1422                if (err < 0)
    14231423                        return err;
    14241424        }
     
    19091909        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    19101910        uinfo->count = 1;
    1911         uinfo->value.enumerated.items = kcontrol->id.index < 2 ? 12 : 11;
     1911        uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
    19121912        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    19131913                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     
    19191919{
    19201920        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1921         int idx = kcontrol->id.index;
     1921        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19221922        unsigned int val, cval;
    19231923
     
    19451945        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    19461946        int change, shift;
    1947         int idx = kcontrol->id.index;
     1947        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19481948        unsigned int val, old_val, nval;
    19491949       
     
    19931993{
    19941994        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1995         int idx = kcontrol->id.index;
     1995        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19961996        unsigned int val, cval;
    19971997        val = inw(ICEMT(ice, ROUTE_SPDOUT));
     
    20132013        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    20142014        int change, shift;
    2015         int idx = kcontrol->id.index;
     2015        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    20162016        unsigned int val, old_val, nval;
    20172017       
     
    20612061        .get = snd_ice1712_pro_route_spdif_get,
    20622062        .put = snd_ice1712_pro_route_spdif_put,
     2063        .count = 2,
    20632064};
    20642065
     
    22472248static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
    22482249{
    2249         unsigned int idx;
    2250         snd_kcontrol_t *kctl;
    22512250        int err;
    22522251
     
    22652264                return err;
    22662265
    2267         for (idx = 0; idx < ice->num_total_dacs; idx++) {
    2268                 kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
    2269                 if (kctl == NULL)
    2270                         return -ENOMEM;
    2271                 kctl->id.index = idx;
    2272                 err = snd_ctl_add(ice->card, kctl);
     2266        if (ice->num_total_dacs > 0) {
     2267                snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
     2268                tmp.count = ice->num_total_dacs;
     2269                err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
    22732270                if (err < 0)
    22742271                        return err;
    22752272        }
    22762273
    2277         for (idx = 0; idx < 2; idx++) {
    2278                 kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice);
    2279                 if (kctl == NULL)
    2280                         return -ENOMEM;
    2281                 kctl->id.index = idx;
    2282                 err = snd_ctl_add(ice->card, kctl);
    2283                 if (err < 0)
    2284                         return err;
    2285         }
     2274        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
     2275        if (err < 0)
     2276                return err;
    22862277
    22872278        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
     
    23242315                kfree_nocheck(ice->res_profi_port);
    23252316        }
    2326         if (ice->akm)
    2327                 kfree(ice->akm);
     2317        snd_ice1712_akm4xxx_free(ice);
    23282318        snd_magic_kfree(ice);
    23292319        return 0;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.h

    r224 r246  
    2727#include <sound/rawmidi.h>
    2828#include <sound/i2c.h>
     29#include <sound/ak4xxx-adda.h>
    2930#include <sound/pcm.h>
    3031
     
    215216
    216217typedef struct _snd_ice1712 ice1712_t;
    217 typedef struct snd_ak4xxx akm4xxx_t;
    218218
    219219typedef struct {
     
    255255
    256256
    257 struct snd_ak4xxx {
    258         unsigned int num_adcs;          /* AK4524 or AK4528 ADCs */
    259         unsigned int num_dacs;          /* AK4524 or AK4528 DACs */
    260         unsigned char images[4][16];    /* saved register image */
    261         unsigned char ipga_gain[4][2];  /* saved register image for IPGA (AK4528) */
    262         ice1712_t *chip;
    263         /* template should fill the following fields */
    264         unsigned int idx_offset;        /* control index offset */
    265         enum {
    266                 SND_AK4524, SND_AK4528, SND_AK4529, SND_AK4355, SND_AK4381
    267         } type;
     257struct snd_ak4xxx_private {
    268258        unsigned int cif: 1;            /* CIF mode */
    269259        unsigned char caddr;            /* C0 and C1 bits */
     
    276266        unsigned int mask_flags;        /* total mask bits */
    277267        struct snd_akm4xxx_ops {
    278                 int (*start)(akm4xxx_t *ak, int chip);
    279                 void (*stop)(akm4xxx_t *ak);
    280268                void (*set_rate_val)(akm4xxx_t *ak, unsigned int rate);
    281269        } ops;
     
    440428int snd_ice1712_spdif_build_controls(ice1712_t *ice);
    441429
    442 void snd_ice1712_akm4xxx_write(akm4xxx_t *ice, int chip, unsigned char addr, unsigned char data);
    443 void snd_ice1712_akm4xxx_reset(akm4xxx_t *ice, int state);
    444 void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *template, ice1712_t *ice);
     430int snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *template, const struct snd_ak4xxx_private *priv, ice1712_t *ice);
     431void snd_ice1712_akm4xxx_free(ice1712_t *ice);
    445432int snd_ice1712_akm4xxx_build_controls(ice1712_t *ice);
    446433
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1724.c

    r231 r246  
    8989
    9090/*
     91 *  AK4xxx stuff
     92 */
     93
     94#include "ak4xxx.c"
     95
     96/*
    9197 *  Basic I/O
    9298 */
     
    195201 */
    196202
    197 static void snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    198 {
    199         ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return);
     203static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     204{
     205        ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
    200206        unsigned char status;
     207        int handled = 0;
    201208
    202209        while (1) {
     
    204211                if (status == 0)
    205212                        break;
    206                
     213
     214                handled = 1;           
    207215                /*  these should probably be separated at some point,
    208216                        but as we don't currently have MPU support on the board I will leave it */
     
    243251                }
    244252        }
     253        return IRQ_RETVAL(handled);
    245254}
    246255
     
    282291        unsigned int what;
    283292        unsigned int old;
     293        struct list_head *pos;
    284294        snd_pcm_substream_t *s;
    285295
     
    288298        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    289299                what = 0;
    290                 s = substream;
    291                 do {
     300                snd_pcm_group_for_each(pos, substream) {
     301                        s = snd_pcm_group_substream_entry(pos);
    292302                        if (s == ice->playback_pro_substream)
    293303                                what |= VT1724_PDMA0_PAUSE;
     
    298308                        else if (s == ice->capture_con_substream)
    299309                                what |= VT1724_RDMA1_PAUSE;
    300                         s = s->link_next;
    301                 } while (s != substream);
     310                }
    302311                spin_lock(&ice->reg_lock);
    303312                old = inl(ICEMT1724(ice, DMA_PAUSE));
     
    314323                what = 0;
    315324                s = substream;
    316                 do {
     325                snd_pcm_group_for_each(pos, substream) {
     326                        s = snd_pcm_group_substream_entry(pos);
    317327                        if (s == ice->playback_pro_substream) {
    318328                                what |= VT1724_PDMA0_START;
     
    328338                                snd_pcm_trigger_done(s, substream);
    329339                        }
    330                         s = s->link_next;
    331                 } while (s != substream);
     340                }
    332341                spin_lock(&ice->reg_lock);
    333342                old = inl(ICEMT1724(ice, DMA_CONTROL));
     
    12951304}
    12961305
    1297 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock = __devinitdata {
     1306static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
    12981307        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    12991308        .name = "Multi Track Internal Clock",
     
    14501459{
    14511460        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1452         int idx = kcontrol->id.index;
     1461        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14531462        ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
    14541463        return 0;
     
    14581467{
    14591468        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1460         int idx = kcontrol->id.index;
     1469        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14611470        return put_route_val(ice, ucontrol->value.enumerated.item[0],
    14621471                             analog_route_shift(idx));
     
    14661475{
    14671476        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1468         int idx = kcontrol->id.index;
     1477        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14691478        ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
    14701479        return 0;
     
    14741483{
    14751484        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1476         int idx = kcontrol->id.index;
     1485        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14771486        return put_route_val(ice, ucontrol->value.enumerated.item[0],
    14781487                             digital_route_shift(idx));
     
    14931502        .get = snd_vt1724_pro_route_spdif_get,
    14941503        .put = snd_vt1724_pro_route_spdif_put,
     1504        .count = 2,
    14951505};
    14961506
     
    16031613{
    16041614        int err;
    1605         unsigned int idx;
    16061615        snd_kcontrol_t *kctl;
    16071616
    16081617        snd_assert(ice->pcm != NULL, return -EIO);
    16091618
    1610         for (idx = 0; idx < 2; idx++) {
    1611                 kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice);
    1612                 if (kctl == NULL)
    1613                         return -ENOMEM;
    1614                 kctl->id.index = idx;
    1615                 err = snd_ctl_add(ice->card, kctl);
    1616                 if (err < 0)
    1617                         return err;
    1618         }
     1619        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
     1620        if (err < 0)
     1621                return err;
    16191622
    16201623        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
     
    16471650static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
    16481651{
    1649         unsigned int idx;
    1650         snd_kcontrol_t *kctl;
    16511652        int err;
    16521653
     
    16651666                return err;
    16661667
    1667         for (idx = 0; idx < ice->num_total_dacs; idx++) {
    1668                 kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_analog_route, ice);
    1669                 if (kctl == NULL)
    1670                         return -ENOMEM;
    1671                 kctl->id.index = idx;
    1672                 err = snd_ctl_add(ice->card, kctl);
     1668        if (ice->num_total_dacs > 0) {
     1669                snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
     1670                tmp.count = ice->num_total_dacs;
     1671                err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
    16731672                if (err < 0)
    16741673                        return err;
     
    17031702                kfree_nocheck(ice->res_profi_port);
    17041703        }
    1705         if (ice->akm)
    1706                 kfree(ice->akm);
     1704        snd_ice1712_akm4xxx_free(ice);
    17071705        snd_magic_kfree(ice);
    17081706        return 0;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/makefile.os2

    r224 r246  
    1313#
    1414#===================================================================
    15 FILE1    = ak4524.obj delta.obj ews.obj hoontech.obj ice1712.obj
     15FILE1    = ak4xxx.obj delta.obj ews.obj hoontech.obj ice1712.obj
    1616FILE2    = ice1724.obj revo.obj
    1717FILE3    =
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/revo.c

    r224 r246  
    6666
    6767        /* reset DFS */
    68         snd_ice1712_akm4xxx_reset(ak, 1);
     68        snd_akm4xxx_reset(ak, 1);
    6969        tmp = ak->images[0][reg];
    7070        tmp &= ~(0x03 << shift);
    7171        tmp |= dfs << shift;
    72         snd_ice1712_akm4xxx_write(ak, 0, reg, tmp);
    73         snd_ice1712_akm4xxx_reset(ak, 0);
     72        snd_akm4xxx_write(ak, 0, reg, tmp);
     73        snd_akm4xxx_reset(ak, 0);
    7474}
    7575
     
    8181        .type = SND_AK4381,
    8282        .num_dacs = 2,
     83        .ops = {
     84                .set_rate_val = revo_set_rate_val
     85        }
     86};
     87
     88static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
    8389        .caddr = 1,
    8490        .cif = 0,
     
    9096        .add_flags = VT1724_REVO_CCLK, /* high at init */
    9197        .mask_flags = 0,
    92         .ops = {
    93                 .set_rate_val = revo_set_rate_val
    94         }
    9598};
    9699
     
    99102        .idx_offset = 1,
    100103        .num_dacs = 6,
     104        .ops = {
     105                .set_rate_val = revo_set_rate_val
     106        }
     107};
     108
     109static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
    101110        .caddr = 3,
    102111        .cif = 0,
     
    108117        .add_flags = VT1724_REVO_CCLK, /* high at init */
    109118        .mask_flags = 0,
    110         .ops = {
    111                 .set_rate_val = revo_set_rate_val
    112         }
    113119};
    114120
     
    134140        switch (ice->eeprom.subvendor) {
    135141        case VT1724_SUBDEVICE_REVOLUTION71:
    136                 snd_ice1712_akm4xxx_init(ak, &akm_revo_front, ice);
    137                 snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, ice);
     142                snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice);
     143                snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice);
    138144                /* unmute all codecs */
    139145                snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/korg1212/korg1212.c

    r224 r246  
    150150#define MAILBOX2_OFFSET      0x48       // location of mailbox 2 relative to base address
    151151#define MAILBOX3_OFFSET      0x4c       // location of mailbox 3 relative to base address
    152 #define OUT_DOORBELL_OFFSET  0x60       // location of PCI to local doorbell "
    153 #define IN_DOORBELL_OFFSET   0x64       // location of local to PCI doorbell "
    154 #define STATUS_REG_OFFSET    0x68       // location of interrupt control/status register "
     152#define OUT_DOORBELL_OFFSET  0x60       // location of PCI to local doorbell
     153#define IN_DOORBELL_OFFSET   0x64       // location of local to PCI doorbell
     154#define STATUS_REG_OFFSET    0x68       // location of interrupt control/status register
    155155#define PCI_CONTROL_OFFSET   0x6c       // location of the EEPROM, PCI, User I/O, init control
    156156                                        //    register
     
    330330
    331331        spinlock_t    lock;
     332        struct semaphore open_mutex;
     333
     334        struct timer_list timer;        /* timer callback for checking ack of stop request */
     335        int stop_pending_cnt;           /* counter for stop pending check */
    332336
    333337        wait_queue_head_t wait;
     
    603607}
    604608
    605 static void snd_korg1212_WaitForCardStopAck(korg1212_t *korg1212)
    606 {
    607         u32 endtime = jiffies + 2 * HZ;
    608 
    609 #if K1212_DEBUG_LEVEL > 0
    610         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.in [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    611 #endif
    612 
    613         if (korg1212->inIRQ)
    614                 return;
    615 
    616         do {
     609/* spinlock already held */
     610static void snd_korg1212_SendStop(korg1212_t *korg1212)
     611{
     612        if (! korg1212->stop_pending_cnt) {
     613                writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
     614                /* program the timer */
     615                korg1212->stop_pending_cnt = HZ;
     616                korg1212->timer.expires = jiffies + 1;
     617                add_timer(&korg1212->timer);
     618        }
     619}
     620
     621static void snd_korg1212_SendStopAndWait(korg1212_t *korg1212)
     622{
     623        unsigned long flags;
     624        spin_lock_irqsave(&korg1212->lock, flags);
     625        snd_korg1212_SendStop(korg1212);
     626        spin_unlock_irqrestore(&korg1212->lock, flags);
     627        sleep_on_timeout(&korg1212->wait, (HZ * 3) / 2);
     628}
     629
     630/* timer callback for checking the ack of stop request */
     631static void snd_korg1212_timer_func(unsigned long data)
     632{
     633        korg1212_t *korg1212 = snd_magic_cast(korg1212_t, (void*)data, return);
     634       
     635        spin_lock(&korg1212->lock);
    617636                if (readl(&korg1212->sharedBufferPtr->cardCommand) == 0) {
    618 #if K1212_DEBUG_LEVEL > 0
    619                         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.out [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    620 #endif
    621                         return;
     637                /* ack'ed */
     638                korg1212->stop_pending_cnt = 0;
     639                wake_up(&korg1212->wait);
     640#if K1212_DEBUG_LEVEL > 1
     641                K1212_DEBUG_PRINTK("K1212_DEBUG: Stop ack'ed [%s]\n", stateName[korg1212->cardState]);
     642#endif
     643        } else {
     644                if (--korg1212->stop_pending_cnt > 0) {
     645                        /* reprogram timer */
     646                        korg1212->timer.expires = jiffies + 1;
     647                        add_timer(&korg1212->timer);
     648                } else {
     649                        snd_printd("korg1212_timer_func timeout\n");
     650        writel(0, &korg1212->sharedBufferPtr->cardCommand);
     651                        wake_up(&korg1212->wait);
     652#if K1212_DEBUG_LEVEL > 0
     653                        K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", stateName[korg1212->cardState]);
     654#endif
    622655                }
    623                 if (!korg1212->inIRQ)
    624                         schedule();
    625         } while (time_before(jiffies, endtime));
    626 
    627 #if K1212_DEBUG_LEVEL > 0
    628         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.out TO [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    629 #endif
    630         writel(0, &korg1212->sharedBufferPtr->cardCommand);
     656        }
     657        spin_unlock(&korg1212->lock);
    631658}
    632659
    633660static void snd_korg1212_TurnOnIdleMonitor(korg1212_t *korg1212)
    634661{
     662        unsigned long flags;
     663
    635664        udelay(INTERCOMMAND_DELAY);
     665        spin_lock_irqsave(&korg1212->lock, flags);
    636666        korg1212->idleMonitorOn = 1;
    637667        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
    638668                        K1212_MODE_MonitorOn, 0, 0, 0);
     669        spin_unlock_irqrestore(&korg1212->lock, flags);
    639670}
    640671
     
    642673{
    643674        if (korg1212->idleMonitorOn) {
    644                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    645                 snd_korg1212_WaitForCardStopAck(korg1212);
     675                snd_korg1212_SendStopAndWait(korg1212);
    646676                korg1212->idleMonitorOn = 0;
    647677        }
    648678}
    649679
    650 static void snd_korg1212_setCardState(korg1212_t * korg1212, CardState csState)
    651 {
    652         switch (csState) {
    653                 case K1212_STATE_READY:
    654                         snd_korg1212_TurnOnIdleMonitor(korg1212);
    655                         break;
    656 
    657                 case K1212_STATE_OPEN:
    658                         snd_korg1212_TurnOffIdleMonitor(korg1212);
    659                         break;
    660 
    661                 default:
    662                         break;
    663         }
    664 
     680static inline void snd_korg1212_setCardState(korg1212_t * korg1212, CardState csState)
     681{
    665682        korg1212->cardState = csState;
    666683}
     
    671688        K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt);
    672689#endif
    673         if (korg1212->opencnt++ == 0)
     690        down(&korg1212->open_mutex);
     691        if (korg1212->opencnt++ == 0) {
     692                snd_korg1212_TurnOffIdleMonitor(korg1212);
    674693        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
     694        }
     695
     696        up(&korg1212->open_mutex);
    675697        return 1;
    676698}
     
    682704#endif
    683705
    684         if (--(korg1212->opencnt))
     706        down(&korg1212->open_mutex);
     707        if (--(korg1212->opencnt)) {
     708                up(&korg1212->open_mutex);
    685709                return 0;
     710        }
    686711
    687712        if (korg1212->cardState == K1212_STATE_SETUP) {
     
    692717#endif
    693718
    694                 if (rc != K1212_CMDRET_Success)
     719                if (rc != K1212_CMDRET_Success) {
     720                        up(&korg1212->open_mutex);
    695721                        return 0;
     722                }
    696723        } else if (korg1212->cardState > K1212_STATE_SETUP) {
    697                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    698                 snd_korg1212_WaitForCardStopAck(korg1212);
    699         }
    700 
    701         if (korg1212->cardState > K1212_STATE_READY)
     724                snd_korg1212_SendStopAndWait(korg1212);
     725        }
     726
     727        if (korg1212->cardState > K1212_STATE_READY) {
     728                snd_korg1212_TurnOnIdleMonitor(korg1212);
    702729                snd_korg1212_setCardState(korg1212, K1212_STATE_READY);
    703 
     730        }
     731
     732        up(&korg1212->open_mutex);
    704733        return 0;
    705734}
    706735
     736/* spinlock already held */
    707737static int snd_korg1212_SetupForPlay(korg1212_t * korg1212)
    708738{
     
    727757}
    728758
     759/* spinlock already held */
    729760static int snd_korg1212_TriggerPlay(korg1212_t * korg1212)
    730761{
     
    749780}
    750781
     782/* spinlock already held */
    751783static int snd_korg1212_StopPlay(korg1212_t * korg1212)
    752784{
     
    760792        korg1212->setcnt = 0;
    761793
    762         if (korg1212->cardState != K1212_STATE_ERRORSTOP) {
    763                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    764                 snd_korg1212_WaitForCardStopAck(korg1212);
    765         }
     794        if (korg1212->cardState != K1212_STATE_ERRORSTOP)
     795                snd_korg1212_SendStop(korg1212);
     796
    766797        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    767798        return 0;
     
    790821                                return 0;
    791822                        } else {
    792                                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    793                                 snd_korg1212_WaitForCardStopAck(korg1212);
     823                                snd_korg1212_SendStopAndWait(korg1212);
    794824                                snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    795825                        }
     
    885915                                   //  the card's eeprom control register.
    886916        u16       count;
     917        unsigned long flags;
    887918
    888919#if K1212_DEBUG_LEVEL > 0
     
    901932        // ----------------------------------------------------------------------------
    902933        if (korg1212->cardState == K1212_STATE_MONITOR || korg1212->idleMonitorOn) {
    903                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    904934                monModeSet = 1;
    905                 snd_korg1212_WaitForCardStopAck(korg1212);
     935                snd_korg1212_SendStopAndWait(korg1212);
    906936        } else
    907937                monModeSet = 0;
     938
     939        spin_lock_irqsave(&korg1212->lock, flags);
    908940
    909941        // ----------------------------------------------------------------------------
     
    10171049        }
    10181050
     1051        spin_unlock_irqrestore(&korg1212->lock, flags);
     1052
    10191053        return 1;
    10201054}
     
    10901124#endif
    10911125
     1126        snd_korg1212_TurnOnIdleMonitor(korg1212);
    10921127        snd_korg1212_setCardState(korg1212, K1212_STATE_READY);
    10931128
     
    10961131#endif
    10971132
    1098         wake_up_interruptible(&korg1212->wait);
    1099 }
    1100 
    1101 static void snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     1133        snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE);
     1134}
     1135
     1136static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    11021137{
    11031138        u32 doorbellValue;
    1104         korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return);
     1139        korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return IRQ_NONE);
    11051140
    11061141        if(irq != korg1212->irq)
    1107                 return;
     1142                return IRQ_NONE;
    11081143
    11091144        doorbellValue = readl(korg1212->inDoorbellPtr);
    11101145
    11111146        if (!doorbellValue)
    1112                 return;
     1147                return IRQ_HANDLED;
     1148
     1149        spin_lock(&korg1212->lock);
    11131150
    11141151        writel(doorbellValue, korg1212->inDoorbellPtr);
     
    11241161                        K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);
    11251162#endif
    1126                         if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) {
    1127                                         snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE);
    1128                                         snd_korg1212_OnDSPDownloadComplete(korg1212);
    1129                         }
     1163                        if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS)
     1164                                wake_up(&korg1212->wait);
    11301165                        break;
    11311166
     
    11671202
    11681203                                if (korg1212->capture_substream) {
     1204                                        spin_unlock(&korg1212->lock);
    11691205                                        snd_pcm_period_elapsed(korg1212->capture_substream);
     1206                                        spin_lock(&korg1212->lock);
    11701207                                }
    11711208
    11721209                                if (korg1212->playback_substream) {
     1210                                        spin_unlock(&korg1212->lock);
    11731211                                        snd_pcm_period_elapsed(korg1212->playback_substream);
     1212                                        spin_lock(&korg1212->lock);
    11741213                                }
    11751214                        }
     
    11781217
    11791218        korg1212->inIRQ--;
     1219
     1220        spin_unlock(&korg1212->lock);
     1221        return IRQ_HANDLED;
    11801222}
    11811223
     
    12061248#endif
    12071249
    1208         interruptible_sleep_on_timeout(&korg1212->wait, HZ * 4);
     1250        if (! sleep_on_timeout(&korg1212->wait, HZ * 4))
     1251                return -EBUSY; /* timeout */
     1252
     1253        snd_korg1212_OnDSPDownloadComplete(korg1212);
    12091254
    12101255        return 0;
     
    13641409        snd_pcm_set_sync(substream);    // ???
    13651410
    1366         spin_lock_irqsave(&korg1212->lock, flags);
    1367 
    13681411        snd_korg1212_OpenCard(korg1212);
    13691412
     1413        runtime->hw = snd_korg1212_playback_info;
    13701414        runtime->dma_area = (char *) korg1212->playDataBufsPtr;
    13711415        runtime->dma_bytes = K1212_BUF_SIZE;
     1416
     1417        spin_lock_irqsave(&korg1212->lock, flags);
    13721418
    13731419        korg1212->playback_substream = substream;
     
    13941440        snd_pcm_set_sync(substream);    // ???
    13951441
    1396         spin_lock_irqsave(&korg1212->lock, flags);
    1397 
    13981442        snd_korg1212_OpenCard(korg1212);
    13991443
     
    14021446        runtime->dma_bytes = K1212_BUF_SIZE;
    14031447
     1448        spin_lock_irqsave(&korg1212->lock, flags);
     1449
    14041450        korg1212->capture_substream = substream;
    14051451        korg1212->periodsize = K1212_PERIODS;
     
    14281474        korg1212->periodsize = 0;
    14291475
    1430         snd_korg1212_CloseCard(korg1212);
    1431 
    14321476        spin_unlock_irqrestore(&korg1212->lock, flags);
     1477
     1478        snd_korg1212_CloseCard(korg1212);
    14331479        return 0;
    14341480}
     
    14481494        korg1212->periodsize = 0;
    14491495
    1450         snd_korg1212_CloseCard(korg1212);
    1451 
    14521496        spin_unlock_irqrestore(&korg1212->lock, flags);
     1497
     1498        snd_korg1212_CloseCard(korg1212);
    14531499        return 0;
    14541500}
     
    15081554{
    15091555        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    1510         unsigned long flags;
    15111556        int rc;
    15121557
     
    15151560#endif
    15161561
    1517         spin_lock_irqsave(&korg1212->lock, flags);
     1562        spin_lock(&korg1212->lock);
     1563
     1564        /* FIXME: we should wait for ack! */
     1565        if (korg1212->stop_pending_cnt > 0) {
     1566#if K1212_DEBUG_LEVEL > 0
     1567                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]);
     1568#endif
     1569                spin_unlock(&korg1212->lock);
     1570                return -EAGAIN;
     1571                /*
     1572                writel(0, &korg1212->sharedBufferPtr->cardCommand);
     1573                del_timer(&korg1212->timer);
     1574                korg1212->stop_pending_cnt = 0;
     1575                */
     1576        }
    15181577
    15191578        rc = snd_korg1212_SetupForPlay(korg1212);
     1579
    15201580        korg1212->currentBuffer = 0;
    15211581
    1522         spin_unlock_irqrestore(&korg1212->lock, flags);
     1582        spin_unlock(&korg1212->lock);
    15231583
    15241584        return rc ? -EINVAL : 0;
     
    15351595#endif
    15361596
     1597        spin_lock(&korg1212->lock);
    15371598        switch (cmd) {
    15381599                case SNDRV_PCM_TRIGGER_START:
     
    15661627                        break;
    15671628        }
     1629        spin_unlock(&korg1212->lock);
    15681630        return rc ? -EINVAL : 0;
    15691631}
     
    18941956        }
    18951957
     1958        spin_unlock_irqrestore(&korg1212->lock, flags);
     1959
    18961960        if (change)
    18971961                snd_korg1212_WriteADCSensitivity(korg1212);
    1898 
    1899         spin_unlock_irqrestore(&korg1212->lock, flags);
    19001962
    19011963        return change;
     
    21512213        init_waitqueue_head(&korg1212->wait);
    21522214        spin_lock_init(&korg1212->lock);
     2215        init_MUTEX(&korg1212->open_mutex);
     2216        init_timer(&korg1212->timer);
     2217        korg1212->timer.function = snd_korg1212_timer_func;
     2218        korg1212->timer.data = (unsigned long)korg1212;
    21532219
    21542220        korg1212->irq = -1;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme96.c

    r224 r246  
    11541154}
    11551155
    1156 static void
     1156static irqreturn_t
    11571157snd_rme96_interrupt(int irq,
    11581158                    void *dev_id,
     
    11661166              (rme96->rcreg & RME96_RCR_IRQ_2)))
    11671167        {
    1168                 return;
     1168                return IRQ_NONE;
    11691169        }
    11701170       
     
    11791179                writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
    11801180        }
     1181        return IRQ_HANDLED;
    11811182}
    11821183
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/hdsp.c

    r224 r246  
    33 *
    44 *      Copyright (c) 2002  Paul Davis
     5 *                          Marcus Andersson
     6 *                          Thomas Charbonnel
    57 *
    68 *   This program is free software; you can redistribute it and/or modify
     
    2123
    2224#include <sound/driver.h>
    23 #include <asm/io.h>
    24 #include <asm/byteorder.h>
    2525#include <linux/delay.h>
    26 #include <linux/init.h>
     26#include <linux/interrupt.h>
    2727#include <linux/slab.h>
    2828#include <linux/pci.h>
     29
    2930#include <sound/core.h>
    3031#include <sound/control.h>
     
    3334#include <sound/asoundef.h>
    3435#include <sound/rawmidi.h>
     36#include <sound/hwdep.h>
    3537#define SNDRV_GET_ID
    3638#include <sound/initval.h>
    37 
    38 #include "multiface_firmware.dat"
    39 #include "digiface_firmware.dat"
     39#include <sound/hdsp.h>
     40
     41#include <asm/byteorder.h>
     42#include <asm/current.h>
     43#include <asm/io.h>
    4044
    4145static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
     
    4448static int precise_ptr[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* Enable precise pointer */
    4549static int line_outs_monitor[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Send all inputs/playback to line outs */
    46 static int force_firmware[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Force firmware reload */
    4750
    4851MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     
    6164MODULE_PARM_DESC(line_outs_monitor, "Send all input and playback streams to line outs by default.");
    6265MODULE_PARM_SYNTAX(line_outs_monitor, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    63 MODULE_PARM(force_firmware,"1-" __MODULE_STRING(SNDRV_CARDS) "i");
    64 MODULE_PARM_DESC(force_firmware, "Force a reload of the I/O box firmware");
    65 MODULE_PARM_SYNTAX(force_firmware, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    66 MODULE_AUTHOR("Paul Davis <pbd@op.net>");
     66MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
    6767MODULE_DESCRIPTION("RME Hammerfall DSP");
    6868MODULE_LICENSE("GPL");
    6969MODULE_CLASSES("{sound}");
    70 MODULE_DEVICES("{{RME,Hammerfall-DSP}}");
    71 
    72 typedef enum {
    73         Digiface,
    74         Multiface
    75 } HDSP_Type;
     70MODULE_DEVICES("{{RME Hammerfall-DSP},"
     71                "{RME HDSP-9652}}");
    7672
    7773#define HDSP_MAX_CHANNELS        26
     
    7975#define DIGIFACE_DS_CHANNELS     14
    8076#define MULTIFACE_SS_CHANNELS    18
    81 #define MULTIFACE_DS_CHANNELS    10
     77#define MULTIFACE_DS_CHANNELS    14
    8278
    8379/* Write registers. These are defined as byte-offsets from the iobase value.
     
    119115#define HDSP_playbackPeakLevel  4096  /* 26 * 32 bit values */
    120116#define HDSP_inputPeakLevel     4224  /* 26 * 32 bit values */
    121 #define HDSP_outputPeakLevel    4100  /* 26 * 32 bit values */
     117#define HDSP_outputPeakLevel    4352  /* (26+2) * 32 bit values */
    122118#define HDSP_playbackRmsLevel   4612  /* 26 * 64 bit values */
    123 #define HDSP_inputRmsLevel      4884  /* 26 * 64 bit values */
     119#define HDSP_inputRmsLevel      4868  /* 26 * 64 bit values */
    124120
    125121#define HDSP_IO_EXTENT     5192
     
    144140/* Control Register bits */
    145141
    146 #define HDSP_Start                (1<<0)  // start engine
    147 #define HDSP_Latency0             (1<<1)  // buffer size = 2^n where n is defined by Latency{2,1,0}
    148 #define HDSP_Latency1             (1<<2)  // [ see above ]
    149 #define HDSP_Latency2             (1<<3)  // ] see above ]
    150 #define HDSP_ClockModeMaster      (1<<4)  // 1=Master, 0=Slave/Autosync
    151 #define HDSP_AudioInterruptEnable (1<<5)  // what do you think ?
    152 #define HDSP_Frequency0           (1<<6)  // 0=44.1kHz/88.2kHz 1=48kHz/96kHz
    153 #define HDSP_Frequency1           (1<<7)  // 0=32kHz/64kHz
    154 #define HDSP_DoubleSpeed          (1<<8)  // 0=normal speed, 1=double speed
    155 #define HDSP_SPDIFProfessional    (1<<9)  // 0=consumer, 1=professional
    156 #define HDSP_SPDIFEmphasis        (1<<10) // 0=none, 1=on
    157 #define HDSP_SPDIFNonAudio        (1<<11) // 0=off, 1=on
    158 #define HDSP_SPDIFOpticalOut      (1<<12) // 1=use 1st ADAT connector for SPDIF, 0=do not
     142#define HDSP_Start                (1<<0)  /* start engine */
     143#define HDSP_Latency0             (1<<1)  /* buffer size = 2^n where n is defined by Latency{2,1,0} */
     144#define HDSP_Latency1             (1<<2)  /* [ see above ] */
     145#define HDSP_Latency2             (1<<3)  /* ] see above ] */
     146#define HDSP_ClockModeMaster      (1<<4)  /* 1=Master, 0=Slave/Autosync */
     147#define HDSP_AudioInterruptEnable (1<<5)  /* what do you think ? */
     148#define HDSP_Frequency0           (1<<6)  /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
     149#define HDSP_Frequency1           (1<<7)  /* 0=32kHz/64kHz */
     150#define HDSP_DoubleSpeed          (1<<8)  /* 0=normal speed, 1=double speed */
     151#define HDSP_SPDIFProfessional    (1<<9)  /* 0=consumer, 1=professional */
     152#define HDSP_SPDIFEmphasis        (1<<10) /* 0=none, 1=on */
     153#define HDSP_SPDIFNonAudio        (1<<11) /* 0=off, 1=on */
     154#define HDSP_SPDIFOpticalOut      (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
    159155#define HDSP_SyncRef2             (1<<13)
    160156#define HDSP_SPDIFInputSelect0    (1<<14)
     
    182178#define HDSP_SyncRef_ADAT_SYNC  (HDSP_SyncRef0|HDSP_SyncRef2)
    183179
    184 /* Preferred sync source choices - used by "sync_pref" control switch */
    185 
    186 #define HDSP_SYNC_FROM_SELF      0
    187 #define HDSP_SYNC_FROM_WORD      1
    188 #define HDSP_SYNC_FROM_ADAT_SYNC 2
    189 #define HDSP_SYNC_FROM_SPDIF     3
    190 #define HDSP_SYNC_FROM_ADAT1     4
    191 #define HDSP_SYNC_FROM_ADAT2     5
    192 #define HDSP_SYNC_FROM_ADAT3     6
     180/* Sample Clock Sources */
     181
     182#define HDSP_CLOCK_SOURCE_AUTOSYNC         0
     183#define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ   1
     184#define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
     185#define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ   3
     186#define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ   4
     187#define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
     188#define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ   6
     189
     190/* Preferred sync reference choices - used by "pref_sync_ref" control switch */
     191
     192#define HDSP_SYNC_FROM_WORD      0
     193#define HDSP_SYNC_FROM_ADAT_SYNC 1
     194#define HDSP_SYNC_FROM_SPDIF     2
     195#define HDSP_SYNC_FROM_ADAT1     3
     196#define HDSP_SYNC_FROM_ADAT2     4
     197#define HDSP_SYNC_FROM_ADAT3     5
     198
     199/* SyncCheck status */
     200
     201#define HDSP_SYNC_CHECK_NO_LOCK 0
     202#define HDSP_SYNC_CHECK_LOCK    1
     203#define HDSP_SYNC_CHECK_SYNC    2
     204
     205/* AutoSync references - used by "autosync_ref" control switch */
     206
     207#define HDSP_AUTOSYNC_FROM_WORD      0
     208#define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
     209#define HDSP_AUTOSYNC_FROM_SPDIF     2
     210#define HDSP_AUTOSYNC_FROM_NONE      3
     211#define HDSP_AUTOSYNC_FROM_ADAT1     4
     212#define HDSP_AUTOSYNC_FROM_ADAT2     5
     213#define HDSP_AUTOSYNC_FROM_ADAT3     6
    193214
    194215/* Possible sources of S/PDIF input */
     
    238259#define HDSP_spdifFrequencyMask    (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
    239260
    240 #define HDSP_spdifFrequency32KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
    241 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
    242 #define HDSP_spdifFrequency48KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
    243 
    244 #define HDSP_spdifFrequency64KHz    0
    245 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency2)
    246 #define HDSP_spdifFrequency96KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
     261#define HDSP_spdifFrequency32KHz   (HDSP_spdifFrequency0)
     262#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
     263#define HDSP_spdifFrequency48KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
     264
     265#define HDSP_spdifFrequency64KHz   (HDSP_spdifFrequency2)
     266#define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
     267#define HDSP_spdifFrequency96KHz   (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
    247268
    248269/* Status2 Register bits */
     
    278299#define HDSP_SelSyncRef_ADAT_SYNC  (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
    279300
    280 /* FIFO wait times, defined in terms of loops on readl() */
    281 
    282 #define HDSP_LONG_WAIT   40000
    283 #define HDSP_SHORT_WAIT  100
    284 
    285 /* Computing addresses for adjusting gains */
    286 
    287 #define INPUT_TO_OUTPUT_KEY(in,out)     ((64 * (out)) + (in))
    288 #define PLAYBACK_TO_OUTPUT_KEY(chn,out) ((64 * (out)) + 32 + (chn))
     301/* Card state flags */
     302
     303#define HDSP_InitializationComplete  (1<<0)
     304#define HDSP_FirmwareLoaded          (1<<1)
     305#define HDSP_FirmwareCached          (1<<2)
     306
     307/* FIFO wait times, defined in terms of 1/10ths of msecs */
     308
     309#define HDSP_LONG_WAIT   5000
     310#define HDSP_SHORT_WAIT  30
     311
    289312#define UNITY_GAIN                       32768
    290313#define MINUS_INFINITY_GAIN              0
     
    314337#define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
    315338
    316 #define HDSP_MATRIX_MIXER_SIZE 2048
    317 
    318 typedef struct _hdsp      hdsp_t;
    319 typedef struct _hdsp_midi hdsp_midi_t;
     339typedef struct _hdsp          hdsp_t;
     340typedef struct _hdsp_midi     hdsp_midi_t;
    320341
    321342struct _hdsp_midi {
     
    328349    struct timer_list        timer;
    329350    spinlock_t               lock;
     351    int                      pending;
    330352};
    331353
    332354struct _hdsp {
    333         spinlock_t lock;
    334         snd_pcm_substream_t *capture_substream;
    335         snd_pcm_substream_t *playback_substream;
    336         hdsp_midi_t midi[2];
    337         int precise_ptr;
    338         u32 control_register;            /* cached value */
    339         u32 creg_spdif;
    340         u32 creg_spdif_stream;
    341         char *card_name;                 /* digiface/multiface */
    342         HDSP_Type type;                  /* ditto, but for code use */
    343         size_t period_bytes;             /* guess what this is */
    344         unsigned char ds_channels;
    345         unsigned char ss_channels;       /* different for multiface/digiface */
    346         void *capture_buffer_unaligned;  /* original buffer addresses */
    347         void *playback_buffer_unaligned; /* original buffer addresses */
    348         unsigned char *capture_buffer;   /* suitably aligned address */
    349         unsigned char *playback_buffer;  /* suitably aligned address */
    350         dma_addr_t capture_buffer_addr;
    351         dma_addr_t playback_buffer_addr;
    352         pid_t capture_pid;
    353         pid_t playback_pid;
    354         int running;
    355         int passthru;                   /* non-zero if doing pass-thru */
    356         int last_spdif_sample_rate;     /* so that we can catch externally ... */
    357         int last_adat_sample_rate;      /* ... induced rate changes            */
    358         char *channel_map;
    359         int dev;
    360         int irq;
    361         unsigned long port;
    362         struct resource *res_port;
    363         unsigned long iobase;
    364         snd_card_t *card;
    365         snd_pcm_t *pcm;
    366         struct pci_dev *pci;
    367         snd_info_entry_t *proc_entry;
    368         snd_kcontrol_t *spdif_ctl;
    369         unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
     355        spinlock_t            lock;
     356        snd_pcm_substream_t  *capture_substream;
     357        snd_pcm_substream_t  *playback_substream;
     358        hdsp_midi_t           midi[2];
     359        struct tasklet_struct midi_tasklet;
     360        int                   precise_ptr;
     361        u32                   control_register;          /* cached value */
     362        u32                   creg_spdif;
     363        u32                   creg_spdif_stream;
     364        char                 *card_name;                    /* digiface/multiface */
     365        HDSP_IO_Type          io_type;               /* ditto, but for code use */
     366        unsigned short        firmware_rev;
     367        unsigned short        state;                 /* stores state bits */
     368        u32                   firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
     369        size_t                period_bytes;         /* guess what this is */
     370        unsigned char         ds_channels;
     371        unsigned char         ss_channels;          /* different for multiface/digiface */
     372        void                 *capture_buffer_unaligned;  /* original buffer addresses */
     373        void                 *playback_buffer_unaligned; /* original buffer addresses */
     374        unsigned char        *capture_buffer;       /* suitably aligned address */
     375        unsigned char        *playback_buffer;      /* suitably aligned address */
     376        dma_addr_t            capture_buffer_addr;
     377        dma_addr_t            playback_buffer_addr;
     378        pid_t                 capture_pid;
     379        pid_t                 playback_pid;
     380        int                   running;
     381        int                   passthru;              /* non-zero if doing pass-thru */
     382        int                   last_spdif_sample_rate;/* for information reporting */
     383        int                   last_external_sample_rate;
     384        int                   last_internal_sample_rate;
     385        int                   system_sample_rate;
     386        char                 *channel_map;
     387        int                   dev;
     388        int                   irq;
     389        unsigned long         port;
     390        struct resource      *res_port;
     391        unsigned long         iobase;
     392        snd_card_t           *card;
     393        snd_pcm_t            *pcm;
     394        snd_hwdep_t          *hwdep;
     395        struct pci_dev       *pci;
     396        snd_kcontrol_t       *spdif_ctl;
     397        snd_kcontrol_t       *playback_mixer_ctls[HDSP_MAX_CHANNELS];
     398        unsigned short        mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
    370399};
    371400
     
    384413
    385414static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
    386         /* ADAT 0 */
     415        /* Analog */
    387416        0, 1, 2, 3, 4, 5, 6, 7,
    388417        /* ADAT 2 */
     
    410439
    411440static struct pci_device_id snd_hdsp_ids[] __devinitdata = {
    412         {PCI_VENDOR_ID_XILINX,
    413          PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
    414          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,}, /* RME Hammerfall-DSP */
    415         {0,}
     441        {
     442                .vendor = PCI_VENDOR_ID_XILINX,
     443                .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
     444                .subvendor = PCI_ANY_ID,
     445                .subdevice = PCI_ANY_ID,
     446        }, /* RME Hammerfall-DSP */
     447        { 0, },
    416448};
    417449
    418450MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
    419451
     452/* prototypes */
     453static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
     454static int __devinit snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
     455static inline int snd_hdsp_initialize_input_enable (hdsp_t *hdsp);
     456static inline void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
     457static inline void snd_hdsp_initialize_channels (hdsp_t *hdsp);
     458static inline int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
     459static int hdsp_update_simple_mixer_controls(hdsp_t *hdsp);
     460static int hdsp_autosync_ref(hdsp_t *hdsp);
     461static int snd_hdsp_set_defaults(hdsp_t *hdsp);
     462
     463static inline int hdsp_is_9652 (hdsp_t *hdsp)
     464{
     465        switch (hdsp->firmware_rev) {
     466        case 0x64:
     467        case 0x65:
     468        case 0x68:
     469                return 1;
     470        default:
     471                return 0;
     472        }
     473}
     474
     475static inline int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
     476{
     477        switch (hdsp->firmware_rev) {
     478        case 0xa:
     479                return (64 * out) + (32 + (in));
     480        default:
     481                return (52 * out) + (26 + (in));
     482        }
     483}
     484
     485static inline int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
     486{
     487        switch (hdsp->firmware_rev) {
     488        case 0xa:
     489                return (64 * out) + in;
     490        default:
     491                return (52 * out) + in;
     492        }
     493}
     494
    420495static inline void hdsp_write(hdsp_t *hdsp, int reg, int val)
    421496{
     
    426501{
    427502        return readl (hdsp->iobase + reg);
    428 }
    429 
    430 static inline unsigned long long hdsp_read64 (hdsp_t *hdsp, int reg)
    431 {
    432         unsigned long long val;
    433         val = hdsp_read(hdsp, reg);
    434         val = (val<<32)|hdsp_read(hdsp, reg + 4);
    435 
    436         return val;
    437503}
    438504
     
    441507        if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
    442508                snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
     509                hdsp->state &= ~HDSP_FirmwareLoaded;
    443510                return -EIO;
    444511        }
    445512        return 0;
    446513}
     514
     515static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
     516
     517        int i;
     518        unsigned long flags;
     519
     520        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     521               
     522                snd_printk ("loading firmware\n");
     523
     524                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_PROGRAM);
     525                hdsp_write (hdsp, HDSP_fifoData, 0);
     526               
     527                if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
     528                        snd_printk ("timeout waiting for download preparation\n");
     529                        return -EIO;
     530                }
     531               
     532                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     533               
     534                for (i = 0; i < 24413; ++i) {
     535                        hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
     536                        if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
     537                                snd_printk ("timeout during firmware loading\n");
     538                                return -EIO;
     539                        }
     540                }
     541               
     542                if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
     543                        snd_printk ("timeout at end of firmware loading\n");
     544                        return -EIO;
     545                }
     546
     547                hdsp_write (hdsp, HDSP_jtagReg, 0);
     548                snd_printk ("finished firmware loading\n");
     549               
     550                if ((1000 / HZ) < 3000) {
     551                        set_current_state(TASK_UNINTERRUPTIBLE);
     552                        schedule_timeout((3000 * HZ + 999) / 1000);
     553                } else {
     554                        mdelay(3000);
     555                }
     556        }
     557        if (hdsp->state & HDSP_InitializationComplete) {
     558                snd_printk("firmware loaded from cache, restoring defaults\n");
     559                spin_lock_irqsave(&hdsp->lock, flags);
     560                snd_hdsp_set_defaults(hdsp);
     561                spin_unlock_irqrestore(&hdsp->lock, flags);
     562        }
     563       
     564        hdsp->state |= HDSP_FirmwareLoaded;
     565
     566        return 0;
     567}
     568
     569static inline int hdsp_get_iobox_version (hdsp_t *hdsp)
     570{
     571        int err;
     572       
     573        if (hdsp_check_for_iobox (hdsp)) {
     574                return -EIO;
     575        }
     576
     577        if ((err = snd_hdsp_initialize_input_enable(hdsp)) < 0) {
     578                return err;
     579        }
     580               
     581        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     582       
     583                hdsp_write (hdsp, HDSP_jtagReg, HDSP_PROGRAM);
     584                hdsp_write (hdsp, HDSP_fifoData, 0);
     585                if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
     586                        return -EIO;
     587                }
     588
     589                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     590                hdsp_write (hdsp, HDSP_fifoData, 0);
     591
     592                if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
     593                        hdsp->io_type = Multiface;
     594                        hdsp_write (hdsp, HDSP_jtagReg, HDSP_VERSION_BIT);
     595                        hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     596                        hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
     597                } else {
     598                        hdsp->io_type = Digiface;
     599                }
     600        } else {
     601                /* firmware was already loaded, get iobox type */
     602                if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
     603                        hdsp->io_type = Multiface;
     604                } else {
     605                        hdsp->io_type = Digiface;
     606                }
     607        }
     608        return 0;
     609}
     610
     611
     612static inline int hdsp_check_for_firmware (hdsp_t *hdsp)
     613{
     614        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     615                snd_printk("firmware not present.\n");
     616                hdsp->state &= ~HDSP_FirmwareLoaded;
     617                return -EIO;
     618        }
     619        return 0;
     620}
     621
    447622
    448623static inline int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
     
    454629        */
    455630       
    456         for (i = 0; i < timeout; i++)
     631        for (i = 0; i < timeout; i++) {
     632
    457633                if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
    458634                        return 0;
     635
     636                /* not very friendly, but we only do this during a firmware
     637                   load and changing the mixer, so we just put up with it.
     638                */
     639
     640                udelay (100);
     641        }
    459642
    460643        snd_printk ("wait for FIFO status <= %d failed after %d iterations\n",
     
    475658        unsigned int ad;
    476659
    477         if (addr >= HDSP_MATRIX_MIXER_SIZE)
    478                 return -1;
    479 
    480         ad = data + addr * 65536;
    481 
    482         if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
    483                 return -1;
    484         }
    485         hdsp_write (hdsp, HDSP_fifoData, ad);
    486         hdsp->mixer_matrix[addr] = data;
     660        if (hdsp_is_9652 (hdsp)) {
     661
     662                if ((ad = addr/2) < 676) {
     663
     664                        /* from martin björnsen:
     665
     666                           "You can only write dwords to the
     667                           mixer memory which contain two
     668                           mixer values in the low and high
     669                           word. So if you want to change
     670                           value 0 you have to read value 1
     671                           from the cache and write both to
     672                           the first dword in the mixer
     673                           memory."
     674                        */
     675
     676                        hdsp->mixer_matrix[addr] = data;
     677                        hdsp_write (hdsp, 1024 + ad,
     678                                    (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
     679                                    hdsp->mixer_matrix[addr&0x7fe]);
     680                        return 0;
     681                } else {
     682                        return -1;
     683                }
     684               
     685
     686        } else {
     687                if (addr >= HDSP_MATRIX_MIXER_SIZE)
     688                        return -1;
     689               
     690                ad = (addr << 16) + data;
     691               
     692                if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
     693                        return -1;
     694                }
     695
     696                hdsp_write (hdsp, HDSP_fifoData, ad);
     697                hdsp->mixer_matrix[addr] = data;
     698
     699        }
    487700
    488701        return 0;
     
    503716}
    504717
    505 static inline int hdsp_system_sample_rate (hdsp_t *hdsp)
     718static inline int hdsp_external_sample_rate (hdsp_t *hdsp)
    506719{
    507720        unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
     
    515728        case HDSP_systemFrequency88_2: return 88200;
    516729        case HDSP_systemFrequency96:   return 96000;
    517         default:                       return 0;
     730        default:
     731                return 0;
    518732        }
    519733}
     
    527741                return 0;
    528742        }
    529 
     743       
    530744        switch (rate_bits) {
    531745        case HDSP_spdifFrequency32KHz: return 32000;
     
    536750        case HDSP_spdifFrequency96KHz: return 96000;
    537751        default:
    538                 snd_printk ("unknown frequency status; bits = 0x%x, status = 0x%x", rate_bits, status);
     752                snd_printk ("unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
    539753                return 0;
    540754        }
     
    565779static inline void hdsp_reset_hw_pointer(hdsp_t *hdsp)
    566780{
    567 #if 0
    568         /* reset the hw pointer to zero. We do this by writing to 8
    569            registers, each of which is a 32bit wide register, and set
    570            them all to zero.
    571         */
    572 
    573         for (i = 0; i < 8; ++i) {
    574                 hdsp_write(hdsp, i, 0);
    575                 udelay(10);
    576         }
    577 #endif
     781        hdsp_write (hdsp, HDSP_resetPointer, 0);
    578782}
    579783
     
    620824}
    621825
    622 static int hdsp_set_rate(hdsp_t *hdsp, int rate)
     826static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
    623827{
    624828        int reject_if_open = 0;
    625829        int current_rate;
    626 
    627         if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
    628                 snd_printk ("device is not running as a clock master: cannot set sample rate.\n");
    629                 return -1;
    630         }
     830        int rate_bits;
     831
     832        if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
     833                if (called_internally) {
     834                        /* request from ctl or card initialization */
     835                        snd_printk("device is not running as a clock master: cannot set sample rate.\n");
     836                        return -1;
     837                } else {               
     838                        /* hw_param request while in AutoSync mode */
     839                        int external_freq = hdsp_external_sample_rate(hdsp);
     840                        int spdif_freq = hdsp_spdif_sample_rate(hdsp);
     841               
     842                        if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
     843                                snd_printk("Detected ADAT in double speed mode\n");
     844                        } else if (rate != external_freq) {
     845                                snd_printk("No AutoSync source for requested rate\n");
     846                                return -1;
     847                        }               
     848                }       
     849        }
     850
     851        current_rate = hdsp->system_sample_rate;
    631852
    632853        /* Changing from a "single speed" to a "double speed" rate is
     
    638859           Note that a similar but essentially insoluble problem
    639860           exists for externally-driven rate changes. All we can do
    640            is to flag rate changes in the read/write routines.
    641          */
     861           is to flag rate changes in the read/write routines.  */
    642862
    643863        spin_lock_irq(&hdsp->lock);
    644         current_rate = hdsp_system_sample_rate(hdsp);
    645864
    646865        switch (rate) {
     
    649868                        reject_if_open = 1;
    650869                }
    651                 rate = HDSP_Frequency32KHz;
     870                rate_bits = HDSP_Frequency32KHz;
    652871                break;
    653872        case 44100:
     
    655874                        reject_if_open = 1;
    656875                }
    657                 rate = HDSP_Frequency44_1KHz;
     876                rate_bits = HDSP_Frequency44_1KHz;
    658877                break;
    659878        case 48000:
     
    661880                        reject_if_open = 1;
    662881                }
    663                 rate = HDSP_Frequency48KHz;
     882                rate_bits = HDSP_Frequency48KHz;
    664883                break;
    665884        case 64000:
    666                 if (current_rate < 48000) {
     885                if (current_rate <= 48000) {
    667886                        reject_if_open = 1;
    668887                }
    669                 rate = HDSP_Frequency64KHz;
     888                rate_bits = HDSP_Frequency64KHz;
    670889                break;
    671890        case 88200:
    672                 if (current_rate < 48000) {
     891                if (current_rate <= 48000) {
    673892                        reject_if_open = 1;
    674893                }
    675                 rate = HDSP_Frequency88_2KHz;
     894                rate_bits = HDSP_Frequency88_2KHz;
    676895                break;
    677896        case 96000:
    678                 if (current_rate < 48000) {
     897                if (current_rate <= 48000) {
    679898                        reject_if_open = 1;
    680899                }
    681                 rate = HDSP_Frequency96KHz;
     900                rate_bits = HDSP_Frequency96KHz;
    682901                break;
    683902        default:
     903                spin_unlock_irq(&hdsp->lock);
    684904                return -EINVAL;
    685905        }
     
    694914
    695915        hdsp->control_register &= ~HDSP_FrequencyMask;
    696         hdsp->control_register |= rate;
     916        hdsp->control_register |= rate_bits;
    697917        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    698918
     
    700920                hdsp->channel_map = channel_map_ds;
    701921        } else {
    702                 switch (hdsp->type) {
     922                switch (hdsp->io_type) {
    703923                case Multiface:
    704924                        hdsp->channel_map = channel_map_mf_ss;
     
    707927                        hdsp->channel_map = channel_map_df_ss;
    708928                        break;
    709                 }
     929                default:
     930                        /* should never happen */
     931                        break;
     932                }
     933        }
     934       
     935        hdsp->system_sample_rate = rate;
     936       
     937        if (reject_if_open) {
     938                hdsp_update_simple_mixer_controls (hdsp);
    710939        }
    711940
     
    727956                if (enable) {
    728957                        for (i = 0; i < 26; i++) {
    729                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(i,i), UNITY_GAIN);
     958                                hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), UNITY_GAIN);
    730959                        }
    731960                } else {
    732961                        for (i = 0; i < 26; i++) {
    733                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(i,i), MINUS_INFINITY_GAIN);
     962                                hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), MINUS_INFINITY_GAIN);
    734963                        }
    735964                }
     
    742971                mapped_channel = hdsp->channel_map[channel];
    743972
     973                snd_assert(mapped_channel > -1, return);
     974
    744975                if (enable) {
    745                         hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), UNITY_GAIN);
     976                        hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), UNITY_GAIN);
    746977                } else {
    747                         hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), MINUS_INFINITY_GAIN);
     978                        hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
    748979                }
    749980        }
     
    8091040static inline int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
    8101041{
     1042        int fifo_bytes_used;
     1043
    8111044        if (id) {
    812                 return (hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff) < 128;
     1045                fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
    8131046        } else {
    814                 return (hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff)< 128;
     1047                fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
     1048        }
     1049
     1050        if (fifo_bytes_used < 128) {
     1051                return  128 - fifo_bytes_used;
     1052        } else {
     1053                return 0;
    8151054        }
    8161055}
     
    8271066        unsigned long flags;
    8281067        int n_pending;
    829         int clear_timer = 0;
    8301068        int to_write;
    8311069        int i;
     
    8351073               
    8361074        spin_lock_irqsave (&hmidi->lock, flags);
    837 
    8381075        if (hmidi->output) {
    8391076                if (!snd_rawmidi_transmit_empty (hmidi->output)) {
     
    8451082                                        for (i = 0; i < to_write; ++i)
    8461083                                                snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
    847                                 } else {
    848                                         clear_timer = 1;
    8491084                                }
    8501085                        }
    851                 } else {
    852                         clear_timer = 1;
    853                 }
    854 
    855                 if (clear_timer && hmidi->istimer && --hmidi->istimer <= 0) {
    856                         del_timer(&hmidi->timer);
    857                 }
    858         }
    859 
     1086                }
     1087        }
    8601088        spin_unlock_irqrestore (&hmidi->lock, flags);
    8611089        return 0;
     
    8701098
    8711099        spin_lock_irqsave (&hmidi->lock, flags);
    872 
    8731100        if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
    8741101                if (hmidi->input) {
     
    8881115                        }
    8891116                }
    890         }
     1117        }
     1118        hmidi->pending = 0;
     1119        if (hmidi->id) {
     1120                hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
     1121        } else {
     1122                hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
     1123        }
     1124        hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
    8911125        spin_unlock_irqrestore (&hmidi->lock, flags);
    8921126        return snd_hdsp_midi_output_write (hmidi);
     
    9631197        }
    9641198        spin_unlock_irqrestore (&hmidi->lock, flags);
     1199        if (up)
     1200                snd_hdsp_midi_output_write(hmidi);
    9651201}
    9661202
     
    10461282        hdsp->midi[id].hdsp = hdsp;
    10471283        hdsp->midi[id].istimer = 0;
     1284        hdsp->midi[id].pending = 0;
    10481285        spin_lock_init (&hdsp->midi[id].lock);
    10491286
     
    11681405
    11691406#define HDSP_SPDIF_IN(xname, xindex) \
    1170 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     1407{ .iface = SNDRV_CTL_ELEM_IFACE_PCM,  \
     1408  .name = xname, \
     1409  .index = xindex, \
    11711410  .info = snd_hdsp_info_spdif_in, \
    1172   .get = snd_hdsp_get_spdif_in, .put = snd_hdsp_put_spdif_in }
     1411  .get = snd_hdsp_get_spdif_in, \
     1412  .put = snd_hdsp_put_spdif_in }
    11731413
    11741414static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
     
    12011441{
    12021442        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1203         unsigned long flags;
    1204        
    1205         spin_lock_irqsave(&hdsp->lock, flags);
     1443       
    12061444        ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
    1207         spin_unlock_irqrestore(&hdsp->lock, flags);
    12081445        return 0;
    12091446}
     
    12281465
    12291466#define HDSP_SPDIF_OUT(xname, xindex) \
    1230 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
    1231   .info = snd_hdsp_info_spdif_out, \
     1467{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1468  .info = snd_hdsp_info_spdif_bits, \
    12321469  .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
    12331470
     
    12481485}
    12491486
    1250 static int snd_hdsp_info_spdif_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1487static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    12511488{
    12521489        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     
    12601497{
    12611498        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1262         unsigned long flags;
    1263        
    1264         spin_lock_irqsave(&hdsp->lock, flags);
     1499       
    12651500        ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
    1266         spin_unlock_irqrestore(&hdsp->lock, flags);
    12671501        return 0;
    12681502}
     
    12851519}
    12861520
    1287 #define HDSP_SYNC_PREF(xname, xindex) \
    1288 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
    1289   .info = snd_hdsp_info_sync_pref, \
    1290   .get = snd_hdsp_get_sync_pref, .put = snd_hdsp_put_sync_pref }
    1291 
    1292 static int hdsp_sync_pref(hdsp_t *hdsp)
     1521#define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
     1522{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1523  .info = snd_hdsp_info_spdif_bits, \
     1524  .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
     1525
     1526static int hdsp_spdif_professional(hdsp_t *hdsp)
     1527{
     1528        return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
     1529}
     1530
     1531static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
     1532{
     1533        if (val) {
     1534                hdsp->control_register |= HDSP_SPDIFProfessional;
     1535        } else {
     1536                hdsp->control_register &= ~HDSP_SPDIFProfessional;
     1537        }
     1538        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1539        return 0;
     1540}
     1541
     1542static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1543{
     1544        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1545       
     1546        ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
     1547        return 0;
     1548}
     1549
     1550static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1551{
     1552        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1553        unsigned long flags;
     1554        int change;
     1555        unsigned int val;
     1556       
     1557        if (!snd_hdsp_use_is_exclusive(hdsp))
     1558                return -EBUSY;
     1559        val = ucontrol->value.integer.value[0] & 1;
     1560        spin_lock_irqsave(&hdsp->lock, flags);
     1561        change = (int)val != hdsp_spdif_professional(hdsp);
     1562        hdsp_set_spdif_professional(hdsp, val);
     1563        spin_unlock_irqrestore(&hdsp->lock, flags);
     1564        return change;
     1565}
     1566
     1567#define HDSP_SPDIF_EMPHASIS(xname, xindex) \
     1568{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1569  .info = snd_hdsp_info_spdif_bits, \
     1570  .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
     1571
     1572static int hdsp_spdif_emphasis(hdsp_t *hdsp)
     1573{
     1574        return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
     1575}
     1576
     1577static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
     1578{
     1579        if (val) {
     1580                hdsp->control_register |= HDSP_SPDIFEmphasis;
     1581        } else {
     1582                hdsp->control_register &= ~HDSP_SPDIFEmphasis;
     1583        }
     1584        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1585        return 0;
     1586}
     1587
     1588static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1589{
     1590        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1591       
     1592        ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
     1593        return 0;
     1594}
     1595
     1596static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1597{
     1598        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1599        unsigned long flags;
     1600        int change;
     1601        unsigned int val;
     1602       
     1603        if (!snd_hdsp_use_is_exclusive(hdsp))
     1604                return -EBUSY;
     1605        val = ucontrol->value.integer.value[0] & 1;
     1606        spin_lock_irqsave(&hdsp->lock, flags);
     1607        change = (int)val != hdsp_spdif_emphasis(hdsp);
     1608        hdsp_set_spdif_emphasis(hdsp, val);
     1609        spin_unlock_irqrestore(&hdsp->lock, flags);
     1610        return change;
     1611}
     1612
     1613#define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
     1614{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1615  .info = snd_hdsp_info_spdif_bits, \
     1616  .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
     1617
     1618static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
     1619{
     1620        return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
     1621}
     1622
     1623static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
     1624{
     1625        if (val) {
     1626                hdsp->control_register |= HDSP_SPDIFNonAudio;
     1627        } else {
     1628                hdsp->control_register &= ~HDSP_SPDIFNonAudio;
     1629        }
     1630        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1631        return 0;
     1632}
     1633
     1634static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1635{
     1636        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1637       
     1638        ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
     1639        return 0;
     1640}
     1641
     1642static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1643{
     1644        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1645        unsigned long flags;
     1646        int change;
     1647        unsigned int val;
     1648       
     1649        if (!snd_hdsp_use_is_exclusive(hdsp))
     1650                return -EBUSY;
     1651        val = ucontrol->value.integer.value[0] & 1;
     1652        spin_lock_irqsave(&hdsp->lock, flags);
     1653        change = (int)val != hdsp_spdif_nonaudio(hdsp);
     1654        hdsp_set_spdif_nonaudio(hdsp, val);
     1655        spin_unlock_irqrestore(&hdsp->lock, flags);
     1656        return change;
     1657}
     1658
     1659#define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
     1660{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1661  .name = xname, \
     1662  .index = xindex, \
     1663  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1664  .info = snd_hdsp_info_spdif_sample_rate, \
     1665  .get = snd_hdsp_get_spdif_sample_rate \
     1666}
     1667
     1668static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1669{
     1670        static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None"};
     1671        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1672        uinfo->count = 1;
     1673        uinfo->value.enumerated.items = 7 ;
     1674        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1675                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1676        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1677        return 0;
     1678}
     1679
     1680static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1681{
     1682        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1683       
     1684        switch (hdsp_spdif_sample_rate(hdsp)) {
     1685        case 32000:
     1686                ucontrol->value.enumerated.item[0] = 0;
     1687                break;
     1688        case 44100:
     1689                ucontrol->value.enumerated.item[0] = 1;
     1690                break;
     1691        case 48000:
     1692                ucontrol->value.enumerated.item[0] = 2;
     1693                break;
     1694        case 64000:
     1695                ucontrol->value.enumerated.item[0] = 3;
     1696                break;
     1697        case 88200:
     1698                ucontrol->value.enumerated.item[0] = 4;
     1699                break;
     1700        case 96000:
     1701                ucontrol->value.enumerated.item[0] = 5;
     1702                break;
     1703        default:
     1704                ucontrol->value.enumerated.item[0] = 6;         
     1705        }
     1706        return 0;
     1707}
     1708
     1709#define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
     1710{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1711  .name = xname, \
     1712  .index = xindex, \
     1713  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1714  .info = snd_hdsp_info_system_sample_rate, \
     1715  .get = snd_hdsp_get_system_sample_rate \
     1716}
     1717
     1718static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1719{
     1720        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     1721        uinfo->count = 1;
     1722        return 0;
     1723}
     1724
     1725static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1726{
     1727        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1728       
     1729        ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
     1730        return 0;
     1731}
     1732
     1733#define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
     1734{ .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     1735  .name = xname, \
     1736  .index = xindex, \
     1737  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1738  .info = snd_hdsp_info_autosync_sample_rate, \
     1739  .get = snd_hdsp_get_autosync_sample_rate \
     1740}
     1741
     1742static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1743{
     1744        static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None"}; 
     1745        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1746        uinfo->count = 1;
     1747        uinfo->value.enumerated.items = 7 ;
     1748        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1749                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1750        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1751        return 0;
     1752}
     1753
     1754static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1755{
     1756        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1757       
     1758        switch (hdsp_external_sample_rate(hdsp)) {
     1759        case 32000:
     1760                ucontrol->value.enumerated.item[0] = 0;
     1761                break;
     1762        case 44100:
     1763                ucontrol->value.enumerated.item[0] = 1;
     1764                break;
     1765        case 48000:
     1766                ucontrol->value.enumerated.item[0] = 2;
     1767                break;
     1768        case 64000:
     1769                ucontrol->value.enumerated.item[0] = 3;
     1770                break;
     1771        case 88200:
     1772                ucontrol->value.enumerated.item[0] = 4;
     1773                break;
     1774        case 96000:
     1775                ucontrol->value.enumerated.item[0] = 5;
     1776                break;
     1777        default:
     1778                ucontrol->value.enumerated.item[0] = 6;         
     1779        }
     1780        return 0;
     1781}
     1782
     1783#define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
     1784{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1785  .name = xname, \
     1786  .index = xindex, \
     1787  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1788  .info = snd_hdsp_info_system_clock_mode, \
     1789  .get = snd_hdsp_get_system_clock_mode \
     1790}
     1791
     1792static int hdsp_system_clock_mode(hdsp_t *hdsp)
     1793{
     1794        if (hdsp->control_register & HDSP_ClockModeMaster) {
     1795                return 0;
     1796        } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
     1797                        return 0;
     1798        }
     1799        return 1;
     1800}
     1801
     1802static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1803{
     1804        static char *texts[] = {"Master", "Slave" };
     1805       
     1806        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1807        uinfo->count = 1;
     1808        uinfo->value.enumerated.items = 2;
     1809        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1810                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1811        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1812        return 0;
     1813}
     1814
     1815static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1816{
     1817        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1818       
     1819        ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
     1820        return 0;
     1821}
     1822
     1823#define HDSP_CLOCK_SOURCE(xname, xindex) \
     1824{ .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     1825  .name = xname, \
     1826  .index = xindex, \
     1827  .info = snd_hdsp_info_clock_source, \
     1828  .get = snd_hdsp_get_clock_source, \
     1829  .put = snd_hdsp_put_clock_source \
     1830}
     1831
     1832static int hdsp_clock_source(hdsp_t *hdsp)
     1833{
     1834        if (hdsp->control_register & HDSP_ClockModeMaster) {
     1835                switch (hdsp->system_sample_rate) {
     1836                case 32000:
     1837                        return 1;
     1838                case 44100:
     1839                        return 2;
     1840                case 48000:
     1841                        return 3;
     1842                case 64000:
     1843                        return 4;
     1844                case 88200:
     1845                        return 5;
     1846                case 96000:
     1847                        return 6;
     1848                default:
     1849                        return 3;       
     1850                }
     1851        } else {
     1852                return 0;
     1853        }
     1854}
     1855
     1856static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
     1857{
     1858        int rate;
     1859        switch (mode) {
     1860        case HDSP_CLOCK_SOURCE_AUTOSYNC:
     1861                if (hdsp_external_sample_rate(hdsp) != 0) {
     1862                    hdsp->control_register &= ~HDSP_ClockModeMaster;           
     1863                    hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1864                    return 0;
     1865                }
     1866                return -1;
     1867        case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
     1868                rate = 32000;
     1869                break;
     1870        case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
     1871                rate = 44100;
     1872                break;     
     1873        case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
     1874                rate = 48000;
     1875                break;
     1876        case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
     1877                rate = 64000;
     1878                break;
     1879        case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
     1880                rate = 88200;
     1881                break;
     1882        case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
     1883                rate = 96000;
     1884                break;
     1885        default:
     1886                rate = 48000;
     1887        }
     1888        hdsp->control_register |= HDSP_ClockModeMaster;
     1889        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1890        hdsp_set_rate(hdsp, rate, 1);
     1891        return 0;
     1892}
     1893
     1894static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1895{
     1896        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" };
     1897       
     1898        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1899        uinfo->count = 1;
     1900        uinfo->value.enumerated.items = 7;
     1901        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1902                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1903        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1904        return 0;
     1905}
     1906
     1907static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1908{
     1909        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1910       
     1911        ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
     1912        return 0;
     1913}
     1914
     1915static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1916{
     1917        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1918        unsigned long flags;
     1919        int change;
     1920        int val;
     1921       
     1922        if (!snd_hdsp_use_is_exclusive(hdsp))
     1923                return -EBUSY;
     1924        val = ucontrol->value.enumerated.item[0];
     1925        if (val < 0) val = 0;
     1926        if (val > 6) val = 6;
     1927        spin_lock_irqsave(&hdsp->lock, flags);
     1928        if (val != hdsp_clock_source(hdsp)) {
     1929                change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
     1930        } else {
     1931                change = 0;
     1932        }
     1933        spin_unlock_irqrestore(&hdsp->lock, flags);
     1934        return change;
     1935}
     1936
     1937#define HDSP_PREF_SYNC_REF(xname, xindex) \
     1938{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1939  .name = xname, \
     1940  .index = xindex, \
     1941  .info = snd_hdsp_info_pref_sync_ref, \
     1942  .get = snd_hdsp_get_pref_sync_ref, \
     1943  .put = snd_hdsp_put_pref_sync_ref \
     1944}
     1945
     1946static int hdsp_pref_sync_ref(hdsp_t *hdsp)
    12931947{
    12941948        /* Notice that this looks at the requested sync source,
    12951949           not the one actually in use.
    12961950        */
    1297        
    1298         if (hdsp->control_register & HDSP_ClockModeMaster) {
    1299                 return HDSP_SYNC_FROM_SELF;
    1300         }
    13011951
    13021952        switch (hdsp->control_register & HDSP_SyncRefMask) {
     
    13141964                return HDSP_SYNC_FROM_ADAT_SYNC;
    13151965        default:
    1316                 return HDSP_SYNC_FROM_SELF;
    1317         }
    1318         return 0;
    1319 }
    1320 
    1321 static int hdsp_set_sync_pref(hdsp_t *hdsp, int pref)
     1966                return HDSP_SYNC_FROM_WORD;
     1967        }
     1968        return 0;
     1969}
     1970
     1971static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
    13221972{
    13231973        hdsp->control_register &= ~HDSP_SyncRefMask;
    13241974        switch (pref) {
    13251975        case HDSP_SYNC_FROM_ADAT1:
    1326                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13271976                hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
    13281977                break;
    13291978        case HDSP_SYNC_FROM_ADAT2:
    1330                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13311979                hdsp->control_register |= HDSP_SyncRef_ADAT2;
    13321980                break;
    13331981        case HDSP_SYNC_FROM_ADAT3:
    1334                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13351982                hdsp->control_register |= HDSP_SyncRef_ADAT3;
    13361983                break;
    13371984        case HDSP_SYNC_FROM_SPDIF:
    1338                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13391985                hdsp->control_register |= HDSP_SyncRef_SPDIF;
    13401986                break;
    13411987        case HDSP_SYNC_FROM_WORD:
    1342                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13431988                hdsp->control_register |= HDSP_SyncRef_WORD;
    13441989                break;
    13451990        case HDSP_SYNC_FROM_ADAT_SYNC:
    1346                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13471991                hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
    1348                 break;
    1349         case HDSP_SYNC_FROM_SELF:
    1350                 hdsp->control_register |= HDSP_ClockModeMaster;
    13511992                break;
    13521993        default:
     
    13571998}
    13581999
    1359 static int snd_hdsp_info_sync_pref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1360 {
    1361         static char *texts[] = {"Internal", "Word", "ADAT Sync", "IEC958", "ADAT1", "ADAT2", "ADAT3" };
     2000static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2001{
     2002        static char *texts[] = {"Word", "ADAT Sync", "IEC958", "ADAT1", "ADAT2", "ADAT3" };
    13622003        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    13632004       
    13642005        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    13652006        uinfo->count = 1;
    1366         uinfo->value.enumerated.items = (hdsp->type == Digiface) ? 7 : 6;
     2007        uinfo->value.enumerated.items = (hdsp->io_type == Digiface) ? 6 : 4;
    13672008        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    13682009                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     
    13712012}
    13722013
    1373 static int snd_hdsp_get_sync_pref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2014static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13742015{
    13752016        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1376         unsigned long flags;
    1377        
    1378         spin_lock_irqsave(&hdsp->lock, flags);
    1379         ucontrol->value.enumerated.item[0] = hdsp_sync_pref(hdsp);
    1380         spin_unlock_irqrestore(&hdsp->lock, flags);
    1381         return 0;
    1382 }
    1383 
    1384 static int snd_hdsp_put_sync_pref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2017       
     2018        ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
     2019        return 0;
     2020}
     2021
     2022static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13852023{
    13862024        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     
    13912029        if (!snd_hdsp_use_is_exclusive(hdsp))
    13922030                return -EBUSY;
    1393         max = hdsp->ss_channels == (hdsp->type == Digiface) ? 7 : 6;
     2031        max = (hdsp->io_type == Digiface) ? 6 : 4;
    13942032        val = ucontrol->value.enumerated.item[0] % max;
    13952033        spin_lock_irqsave(&hdsp->lock, flags);
    1396         change = (int)val != hdsp_sync_pref(hdsp);
    1397         hdsp_set_sync_pref(hdsp, val);
     2034        change = (int)val != hdsp_pref_sync_ref(hdsp);
     2035        hdsp_set_pref_sync_ref(hdsp, val);
    13982036        spin_unlock_irqrestore(&hdsp->lock, flags);
    13992037        return change;
    14002038}
    14012039
     2040#define HDSP_AUTOSYNC_REF(xname, xindex) \
     2041{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2042  .name = xname, \
     2043  .index = xindex, \
     2044  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     2045  .info = snd_hdsp_info_autosync_ref, \
     2046  .get = snd_hdsp_get_autosync_ref, \
     2047}
     2048
     2049static int hdsp_autosync_ref(hdsp_t *hdsp)
     2050{
     2051        /* This looks at the autosync selected sync reference */
     2052        unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
     2053
     2054        switch (status2 & HDSP_SelSyncRefMask) {
     2055        case HDSP_SelSyncRef_WORD:
     2056                return HDSP_AUTOSYNC_FROM_WORD;
     2057        case HDSP_SelSyncRef_ADAT_SYNC:
     2058                return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
     2059        case HDSP_SelSyncRef_SPDIF:
     2060                return HDSP_AUTOSYNC_FROM_SPDIF;
     2061        case HDSP_SelSyncRefMask:
     2062                return HDSP_AUTOSYNC_FROM_NONE;
     2063        case HDSP_SelSyncRef_ADAT1:
     2064                return HDSP_AUTOSYNC_FROM_ADAT1;
     2065        case HDSP_SelSyncRef_ADAT2:
     2066                return HDSP_AUTOSYNC_FROM_ADAT2;
     2067        case HDSP_SelSyncRef_ADAT3:
     2068                return HDSP_AUTOSYNC_FROM_ADAT3;
     2069        default:
     2070                return HDSP_AUTOSYNC_FROM_WORD;
     2071        }
     2072        return 0;
     2073}
     2074
     2075static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2076{
     2077        static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
     2078       
     2079        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2080        uinfo->count = 1;
     2081        uinfo->value.enumerated.items = 7;
     2082        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     2083                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     2084        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2085        return 0;
     2086}
     2087
     2088static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2089{
     2090        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     2091       
     2092        ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
     2093        return 0;
     2094}
     2095
    14022096#define HDSP_PASSTHRU(xname, xindex) \
    1403 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2097{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2098  .name = xname, \
     2099  .index = xindex, \
    14042100  .info = snd_hdsp_info_passthru, \
    14052101  .put = snd_hdsp_put_passthru, \
    1406   .get = snd_hdsp_get_passthru }
     2102  .get = snd_hdsp_get_passthru \
     2103}
    14072104
    14082105static int snd_hdsp_info_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
     
    14472144
    14482145#define HDSP_LINE_OUT(xname, xindex) \
    1449 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2146{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2147  .name = xname, \
     2148  .index = xindex, \
    14502149  .info = snd_hdsp_info_line_out, \
    1451   .get = snd_hdsp_get_line_out, .put = snd_hdsp_put_line_out }
     2150  .get = snd_hdsp_get_line_out, \
     2151  .put = snd_hdsp_put_line_out \
     2152}
    14522153
    14532154static int hdsp_line_out(hdsp_t *hdsp)
     
    15052206
    15062207#define HDSP_MIXER(xname, xindex) \
    1507 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2208{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2209  .name = xname, \
     2210  .index = xindex, \
     2211  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
     2212                 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    15082213  .info = snd_hdsp_info_mixer, \
    1509   .get = snd_hdsp_get_mixer, .put = snd_hdsp_put_mixer }
     2214  .get = snd_hdsp_get_mixer, \
     2215  .put = snd_hdsp_put_mixer \
     2216}
    15102217
    15112218static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     
    15312238
    15322239        if (source > 25) {
    1533                 addr = PLAYBACK_TO_OUTPUT_KEY(source-26,destination);
     2240                addr = hdsp_playback_to_output_key(hdsp,source-26,destination);
    15342241        } else {
    1535                 addr = INPUT_TO_OUTPUT_KEY(source, destination);
     2242                addr = hdsp_input_to_output_key(hdsp,source, destination);
    15362243        }
    15372244       
    15382245        spin_lock_irqsave(&hdsp->lock, flags);
    1539         ucontrol->value.integer.value[0] = hdsp_read_gain (hdsp, addr);
     2246        ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
    15402247        spin_unlock_irqrestore(&hdsp->lock, flags);
    15412248        return 0;
     
    15592266
    15602267        if (source > 25) {
    1561                 addr = PLAYBACK_TO_OUTPUT_KEY(source-26, destination);
     2268                addr = hdsp_playback_to_output_key(hdsp,source-26, destination);
    15622269        } else {
    1563                 addr = INPUT_TO_OUTPUT_KEY(source, destination);
     2270                addr = hdsp_input_to_output_key(hdsp,source, destination);
    15642271        }
    15652272
     
    15842291                 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    15852292  .info = snd_hdsp_info_playback_mixer, \
    1586   .get = snd_hdsp_get_playback_mixer, .put = snd_hdsp_put_playback_mixer }
     2293  .get = snd_hdsp_get_playback_mixer, \
     2294  .put = snd_hdsp_put_playback_mixer \
     2295}
    15872296
    15882297static int snd_hdsp_info_playback_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     
    16012310        unsigned long flags;
    16022311        int addr;
    1603         int chn;
    1604 
    1605         chn = ucontrol->id.index - 1;
    1606         addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
     2312        int channel;
     2313        int mapped_channel;
     2314
     2315        channel = ucontrol->id.index - 1;
     2316
     2317        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
     2318       
     2319        if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
     2320                return -EINVAL;
     2321        }
     2322
     2323        addr = hdsp_playback_to_output_key(hdsp,mapped_channel, mapped_channel);
    16072324
    16082325        spin_lock_irqsave(&hdsp->lock, flags);
     
    16182335        int change;
    16192336        int addr;
    1620         int chn;
     2337        int channel;
     2338        int mapped_channel;
    16212339        int gain;
    16222340
     
    16242342                return -EBUSY;
    16252343       
    1626         chn = ucontrol->id.index - 1;
    1627         addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
     2344        channel = ucontrol->id.index - 1;
     2345
     2346        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
     2347       
     2348        if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
     2349                return -EINVAL;
     2350        }
     2351
     2352        addr = hdsp_playback_to_output_key(hdsp,mapped_channel, mapped_channel);
    16282353        gain = ucontrol->value.integer.value[0];
    16292354
     
    16372362}
    16382363
    1639 #define HDSP_PEAK_PLAYBACK \
    1640 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2364#define HDSP_WC_SYNC_CHECK(xname, xindex) \
     2365{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2366  .name = xname, \
     2367  .index = xindex, \
    16412368  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1642   .info = snd_hdsp_info_peak_playback, \
    1643   .get = snd_hdsp_get_peak_playback \
    1644 }
    1645 
    1646 static int snd_hdsp_info_peak_playback(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1647 {
    1648         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1649         uinfo->count = 2;
    1650         return 0;
    1651 }
    1652 
    1653 static int snd_hdsp_get_peak_playback(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2369  .info = snd_hdsp_info_sync_check, \
     2370  .get = snd_hdsp_get_wc_sync_check \
     2371}
     2372
     2373static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2374{
     2375        static char *texts[] = {"No Lock", "Lock", "Sync" };   
     2376        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2377        uinfo->count = 1;
     2378        uinfo->value.enumerated.items = 3;
     2379        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     2380                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     2381        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2382        return 0;
     2383}
     2384
     2385static int hdsp_wc_sync_check(hdsp_t *hdsp)
     2386{
     2387        int status2 = hdsp_read(hdsp, HDSP_status2Register);
     2388        if (status2 & HDSP_wc_lock) {
     2389                if (status2 & HDSP_wc_sync) {
     2390                        return 2;
     2391                } else {
     2392                         return 1;
     2393                }
     2394        } else {               
     2395                return 0;
     2396        }
     2397        return 0;
     2398}
     2399
     2400static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    16542401{
    16552402        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1656         unsigned int peakval = hdsp_read (hdsp, HDSP_playbackPeakLevel + (4 * (ucontrol->id.index-1)));
    1657         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1658         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1659         return 0;
    1660 }
    1661 
    1662 #define HDSP_PEAK_INPUT \
    1663 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2403
     2404        ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
     2405        return 0;
     2406}
     2407
     2408#define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
     2409{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2410  .name = xname, \
     2411  .index = xindex, \
    16642412  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1665   .info = snd_hdsp_info_peak_input, \
    1666   .get = snd_hdsp_get_peak_input \
    1667 }
    1668 
    1669 static int snd_hdsp_info_peak_input(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1670 {
    1671         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1672         uinfo->count = 2;
    1673         return 0;
    1674 }
    1675 
    1676 static int snd_hdsp_get_peak_input(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2413  .info = snd_hdsp_info_sync_check, \
     2414  .get = snd_hdsp_get_spdif_sync_check \
     2415}
     2416
     2417static int hdsp_spdif_sync_check(hdsp_t *hdsp)
     2418{
     2419        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2420        if (status & HDSP_SPDIFErrorFlag) {
     2421                return 0;
     2422        } else {       
     2423                if (status & HDSP_SPDIFSync) {
     2424                        return 2;
     2425                } else {
     2426                        return 1;
     2427                }
     2428        }
     2429        return 0;
     2430}
     2431
     2432static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    16772433{
    16782434        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1679         unsigned int peakval = hdsp_read (hdsp, HDSP_inputPeakLevel + (4 * (ucontrol->id.index-1)));
    1680         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1681         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1682         return 0;
    1683 }
    1684 
    1685 #define HDSP_PEAK_OUTPUT \
    1686 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2435
     2436        ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
     2437        return 0;
     2438}
     2439
     2440#define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
     2441{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2442  .name = xname, \
     2443  .index = xindex, \
    16872444  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1688   .info = snd_hdsp_info_peak_output, \
    1689   .get = snd_hdsp_get_peak_output \
    1690 }
    1691 
    1692 static int snd_hdsp_info_peak_output(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1693 {
    1694         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1695         uinfo->count = 2;
    1696         return 0;
    1697 }
    1698 
    1699 static int snd_hdsp_get_peak_output(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2445  .info = snd_hdsp_info_sync_check, \
     2446  .get = snd_hdsp_get_adatsync_sync_check \
     2447}
     2448
     2449static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
     2450{
     2451        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2452        if (status & HDSP_TimecodeLock) {
     2453                if (status & HDSP_TimecodeSync) {
     2454                        return 2;
     2455                } else {
     2456                        return 1;
     2457                }
     2458        } else {
     2459                return 0;
     2460        }
     2461}       
     2462
     2463static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    17002464{
    17012465        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1702         unsigned int peakval = hdsp_read (hdsp, HDSP_outputPeakLevel + (4 * (ucontrol->id.index-1)));
    1703         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1704         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1705         return 0;
    1706 }
    1707 
    1708 #define HDSP_RMS_INPUT \
    1709 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2466
     2467        ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
     2468        return 0;
     2469}
     2470
     2471#define HDSP_ADAT_SYNC_CHECK \
     2472{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
    17102473  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1711   .info = snd_hdsp_info_rms_input, \
    1712   .get = snd_hdsp_get_rms_input \
    1713 }
    1714 
    1715 static int snd_hdsp_info_rms_input(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1716 {
    1717         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER64;
    1718         uinfo->count = 1;
    1719         return 0;
    1720 }
    1721 
    1722 static int snd_hdsp_get_rms_input(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1723 {
     2474  .info = snd_hdsp_info_sync_check, \
     2475  .get = snd_hdsp_get_adat_sync_check \
     2476}
     2477
     2478static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
     2479{       
     2480        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2481       
     2482        if (status & (HDSP_Lock0>>idx)) {
     2483                if (status & (HDSP_Sync0>>idx)) {
     2484                        return 2;
     2485                } else {
     2486                        return 1;               
     2487                }
     2488        } else {
     2489                return 0;
     2490        }               
     2491}
     2492
     2493static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2494{
     2495        int offset;
    17242496        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1725         ucontrol->value.integer64.value[0] = hdsp_read64 (hdsp, HDSP_inputRmsLevel + (8 * (ucontrol->id.index-1)));
    1726         return 0;
    1727 }
    1728 
    1729 #define HDSP_RMS_PLAYBACK \
    1730 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
    1731   .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1732   .info = snd_hdsp_info_rms_playback, \
    1733   .get = snd_hdsp_get_rms_playback \
    1734 }
    1735 
    1736 static int snd_hdsp_info_rms_playback(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1737 {
    1738         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER64;
    1739         uinfo->count = 1;
    1740         return 0;
    1741 }
    1742 
    1743 static int snd_hdsp_get_rms_playback(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1744 {
    1745         hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1746         ucontrol->value.integer64.value[0] = hdsp_read64 (hdsp, HDSP_playbackRmsLevel + (8 * (ucontrol->id.index-1)));
     2497
     2498        offset = ucontrol->id.index - 1;
     2499        snd_assert(offset >= 0 || offset < ((hdsp->io_type == Digiface) ? 3 : 1), return -EINVAL);
     2500        ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
    17472501        return 0;
    17482502}
     
    17712525        .get =          snd_hdsp_control_spdif_mask_get,
    17722526        .private_value = IEC958_AES0_NONAUDIO |
    1773                         IEC958_AES0_PROFESSIONAL |
    1774                         IEC958_AES0_CON_EMPHASIS,                                                                                             
     2527                         IEC958_AES0_PROFESSIONAL |
     2528                         IEC958_AES0_CON_EMPHASIS,                                                                                           
    17752529},
    17762530{
     
    17812535        .get =          snd_hdsp_control_spdif_mask_get,
    17822536        .private_value = IEC958_AES0_NONAUDIO |
    1783                         IEC958_AES0_PROFESSIONAL |
    1784                         IEC958_AES0_PRO_EMPHASIS,
     2537                         IEC958_AES0_PROFESSIONAL |
     2538                         IEC958_AES0_PRO_EMPHASIS,
    17852539},
    17862540HDSP_MIXER("Mixer", 0),
    17872541HDSP_SPDIF_IN("IEC958 Input Connector", 0),
    17882542HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
    1789 HDSP_SYNC_PREF("Preferred Sync Source", 0),
     2543HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
     2544HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
     2545HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
     2546/* 'Sample Clock Source' complies with the alsa control naming scheme */
     2547HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
     2548HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
     2549HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
     2550HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
     2551HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
     2552HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
     2553/* 'External Rate' complies with the alsa control naming scheme */
     2554HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
     2555HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
     2556HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
     2557HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
    17902558HDSP_PASSTHRU("Passthru", 0),
    17912559HDSP_LINE_OUT("Line Out", 0),
     
    17952563
    17962564static snd_kcontrol_new_t snd_hdsp_playback_mixer = HDSP_PLAYBACK_MIXER;
    1797 static snd_kcontrol_new_t snd_hdsp_input_peak = HDSP_PEAK_INPUT;
    1798 static snd_kcontrol_new_t snd_hdsp_output_peak = HDSP_PEAK_OUTPUT;
    1799 static snd_kcontrol_new_t snd_hdsp_playback_peak = HDSP_PEAK_PLAYBACK;
    1800 static snd_kcontrol_new_t snd_hdsp_input_rms = HDSP_RMS_INPUT;
    1801 static snd_kcontrol_new_t snd_hdsp_playback_rms = HDSP_RMS_PLAYBACK;
     2565static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
     2566
     2567
     2568static int hdsp_update_simple_mixer_controls(hdsp_t *hdsp)
     2569{
     2570    int i;
     2571
     2572    for (i = hdsp->ds_channels; i < hdsp->ss_channels; ++i) {
     2573            if (hdsp->system_sample_rate > 48000) {
     2574                    hdsp->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_INACTIVE |
     2575                                                            SNDRV_CTL_ELEM_ACCESS_READ |
     2576                                                             SNDRV_CTL_ELEM_ACCESS_VOLATILE;
     2577            } else {
     2578                    hdsp->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
     2579                                                             SNDRV_CTL_ELEM_ACCESS_VOLATILE;
     2580            }
     2581            snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
     2582                            SNDRV_CTL_EVENT_MASK_INFO, &hdsp->playback_mixer_ctls[i]->id);
     2583    }
     2584
     2585    return 0;
     2586}
     2587
    18022588
    18032589int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
     
    18142600        }
    18152601
    1816         if (hdsp->type == Digiface) {
     2602        snd_hdsp_playback_mixer.name = "Chn";
     2603        snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
     2604
     2605        if (hdsp->io_type == Digiface) {
    18172606                limit = DIGIFACE_SS_CHANNELS;
    18182607        } else {
    18192608                limit = MULTIFACE_SS_CHANNELS;
    18202609        }
    1821 
     2610       
    18222611        /* The index values are one greater than the channel ID so that alsamixer
    18232612           will display them correctly. We want to use the index for fast lookup
     
    18262615        */
    18272616
    1828         snd_hdsp_playback_mixer.name = "Chn";
    1829         snd_hdsp_input_peak.name = "Input Peak";
    1830         snd_hdsp_output_peak.name = "Output Peak";
    1831         snd_hdsp_playback_peak.name = "Playback Peak";
    1832         snd_hdsp_playback_rms.name = "Playback RMS";
    1833         snd_hdsp_input_rms.name = "Input RMS";
    1834 
    18352617        for (idx = 0; idx < limit; ++idx) {
    18362618                snd_hdsp_playback_mixer.index = idx+1;
     
    18382620                        return err;
    18392621                }
    1840                 snd_hdsp_input_peak.index = idx+1;
    1841                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_input_peak, hdsp)))) {
    1842                         return err;
    1843                 }
    1844                 snd_hdsp_output_peak.index = idx+1;
    1845                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_output_peak, hdsp)))) {
    1846                         return err;
    1847                 }
    1848                 snd_hdsp_playback_peak.index = idx+1;
    1849                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_playback_peak, hdsp)))) {
    1850                         return err;
    1851                 }
    1852                 snd_hdsp_playback_rms.index = idx+1;
    1853                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_playback_rms, hdsp)))) {
    1854                         return err;
    1855                 }
    1856                 snd_hdsp_input_rms.index = idx+1;
    1857                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_input_rms, hdsp)))) {
    1858                         return err;
     2622                hdsp->playback_mixer_ctls[idx] = kctl;
     2623        }
     2624       
     2625        /* ADAT SyncCheck status */
     2626        snd_hdsp_adat_sync_check.index = 1;
     2627        if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
     2628                return err;
     2629        }       
     2630        if (hdsp->io_type == Digiface) {
     2631                for (idx = 1; idx < 3; ++idx) {
     2632                        snd_hdsp_adat_sync_check.index = idx+1;
     2633                        if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
     2634                                return err;
     2635                        }
    18592636                }
    18602637        }
     
    18732650        unsigned int status;
    18742651        unsigned int status2;
    1875         char *requested_sync_ref;
     2652        char *pref_sync_ref;
     2653        char *autosync_ref;
     2654        char *system_clock_mode;
     2655        char *clock_source;
    18762656        int x;
    18772657
    18782658        if (hdsp_check_for_iobox (hdsp)) {
     2659                snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
    18792660                return;
    18802661        }
    18812662
     2663        if (hdsp_check_for_firmware(hdsp)) {
     2664                if (hdsp->state & HDSP_FirmwareCached) {
     2665                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     2666                                snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
     2667                                return;
     2668                        }
     2669                } else {
     2670                        snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
     2671                        return;
     2672                }
     2673        }
     2674       
    18822675        status = hdsp_read(hdsp, HDSP_statusRegister);
    18832676        status2 = hdsp_read(hdsp, HDSP_status2Register);
     
    19022695        x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
    19032696
    1904         snd_iprintf(buffer, "Latency: %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
     2697        snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
    19052698        snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
    19062699        snd_iprintf(buffer, "Passthru: %s\n", hdsp->passthru ? "yes" : "no");
     
    19092702        snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
    19102703
    1911         switch (hdsp_sync_pref (hdsp)) {
     2704        snd_iprintf(buffer, "\n");
     2705
     2706
     2707        switch (hdsp_clock_source(hdsp)) {
     2708        case HDSP_CLOCK_SOURCE_AUTOSYNC:
     2709                clock_source = "AutoSync";
     2710                break;
     2711        case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
     2712                clock_source = "Internal 32 kHz";
     2713                break;
     2714        case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
     2715                clock_source = "Internal 44.1 kHz";
     2716                break;
     2717        case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
     2718                clock_source = "Internal 48 kHz";
     2719                break;
     2720        case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
     2721                clock_source = "Internal 64 kHz";
     2722                break;
     2723        case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
     2724                clock_source = "Internal 88.2 kHz";
     2725                break;
     2726        case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
     2727                clock_source = "Internal 96 kHz";
     2728                break;
     2729        default:
     2730                clock_source = "Error";         
     2731        }
     2732        snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
     2733                       
     2734        if (hdsp_system_clock_mode(hdsp)) {
     2735                system_clock_mode = "Slave";
     2736        } else {
     2737                system_clock_mode = "Master";
     2738        }
     2739       
     2740        switch (hdsp_pref_sync_ref (hdsp)) {
    19122741        case HDSP_SYNC_FROM_WORD:
    1913                 requested_sync_ref = "Word";
     2742                pref_sync_ref = "Word Clock";
    19142743                break;
    19152744        case HDSP_SYNC_FROM_ADAT_SYNC:
    1916                 requested_sync_ref = "ADAT Sync";
     2745                pref_sync_ref = "ADAT Sync";
    19172746                break;
    19182747        case HDSP_SYNC_FROM_SPDIF:
    1919                 requested_sync_ref = "SPDIF";
     2748                pref_sync_ref = "SPDIF";
    19202749                break;
    19212750        case HDSP_SYNC_FROM_ADAT1:
    1922                 requested_sync_ref = "ADAT1";
     2751                pref_sync_ref = "ADAT1";
    19232752                break;
    19242753        case HDSP_SYNC_FROM_ADAT2:
    1925                 requested_sync_ref = "ADAT2";
     2754                pref_sync_ref = "ADAT2";
    19262755                break;
    19272756        case HDSP_SYNC_FROM_ADAT3:
    1928                 requested_sync_ref = "ADAT3";
    1929                 break;
    1930         case HDSP_SYNC_FROM_SELF:
     2757                pref_sync_ref = "ADAT3";
     2758                break;
    19312759        default:
    1932                 requested_sync_ref = "Master";
    1933                 break;
    1934         }
    1935 
    1936         if ((hdsp->control_register & HDSP_ClockModeMaster)) {
    1937                 snd_iprintf (buffer, "Sync reference: %s/Master (chosen)\n", requested_sync_ref);
    1938         } else if (hdsp_system_sample_rate(hdsp) == 0) {
    1939                 snd_iprintf (buffer, "Sync reference: %s/Master (forced)\n", requested_sync_ref);
    1940         } else {
    1941                 switch (status2 & HDSP_SelSyncRefMask) {
    1942                 case HDSP_SelSyncRef_ADAT1:
    1943                         snd_iprintf (buffer, "Sync reference: %s/ADAT1\n", requested_sync_ref);
    1944                         break;
    1945                 case HDSP_SelSyncRef_ADAT2:
    1946                         snd_iprintf (buffer, "Sync reference: %s/ADAT2\n", requested_sync_ref);
    1947                         break;
    1948                 case HDSP_SelSyncRef_ADAT3:
    1949                         snd_iprintf (buffer, "Sync reference: %s/ADAT3\n", requested_sync_ref);
    1950                         break;
    1951                 case HDSP_SelSyncRef_SPDIF:
    1952                         snd_iprintf (buffer, "Sync reference: %s/SPDIF\n", requested_sync_ref);
    1953                         break;
    1954                 case HDSP_SelSyncRef_WORD:
    1955                         snd_iprintf (buffer, "Sync reference: %s/WORD\n", requested_sync_ref);
    1956                         break;
    1957                 case HDSP_SelSyncRef_ADAT_SYNC:
    1958                         snd_iprintf (buffer, "Sync reference: %s/ADAT Sync\n", requested_sync_ref);
    1959                         break;
    1960                 default:
    1961                         snd_iprintf (buffer, "Sync reference: %s/Master (fallback)\n", requested_sync_ref);
    1962                         break;
    1963                 }
    1964         }
    1965         snd_iprintf (buffer, "Sample rate: %d\n", hdsp_system_sample_rate(hdsp));
    1966 
     2760                pref_sync_ref = "Word Clock";
     2761                break;
     2762        }
     2763        snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
     2764       
     2765        switch (hdsp_autosync_ref (hdsp)) {
     2766        case HDSP_AUTOSYNC_FROM_WORD:
     2767                autosync_ref = "Word Clock";
     2768                break;
     2769        case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
     2770                autosync_ref = "ADAT Sync";
     2771                break;
     2772        case HDSP_AUTOSYNC_FROM_SPDIF:
     2773                autosync_ref = "SPDIF";
     2774                break;
     2775        case HDSP_AUTOSYNC_FROM_NONE:
     2776                autosync_ref = "None";
     2777                break; 
     2778        case HDSP_AUTOSYNC_FROM_ADAT1:
     2779                autosync_ref = "ADAT1";
     2780                break;
     2781        case HDSP_AUTOSYNC_FROM_ADAT2:
     2782                autosync_ref = "ADAT2";
     2783                break;
     2784        case HDSP_AUTOSYNC_FROM_ADAT3:
     2785                autosync_ref = "ADAT3";
     2786                break;
     2787        default:
     2788                autosync_ref = "---";
     2789                break;
     2790        }
     2791        snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
     2792       
     2793        snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
     2794       
     2795        snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
     2796
     2797        snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
     2798               
    19672799        snd_iprintf(buffer, "\n");
    19682800
     
    20052837                snd_iprintf(buffer, "IEC958 NonAudio: off\n");
    20062838        }
    2007 
    2008         snd_iprintf(buffer, "\n");
    2009 
    20102839        if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
    20112840                snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
     
    20242853        }
    20252854
    2026         x = status & HDSP_Sync1;
    2027         if (status & HDSP_Lock1) {
    2028                 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
    2029         } else {
    2030                 snd_iprintf(buffer, "ADAT2: No Lock\n");
    2031         }
    2032 
    2033         if (hdsp->type == Digiface) {
     2855        switch (hdsp->io_type) {
     2856        case Digiface:
     2857                x = status & HDSP_Sync1;
     2858                if (status & HDSP_Lock1) {
     2859                        snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
     2860                } else {
     2861                        snd_iprintf(buffer, "ADAT2: No Lock\n");
     2862                }
    20342863                x = status & HDSP_Sync2;
    20352864                if (status & HDSP_Lock2) {
     
    20382867                        snd_iprintf(buffer, "ADAT3: No Lock\n");
    20392868                }
     2869        default:
     2870                /* relax */
     2871                break;
     2872        }
     2873
     2874        x = status & HDSP_SPDIFSync;
     2875        if (status & HDSP_SPDIFErrorFlag) {
     2876                snd_iprintf (buffer, "SPDIF: No Lock\n");
     2877        } else {
     2878                snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
     2879        }
     2880       
     2881        x = status2 & HDSP_wc_sync;
     2882        if (status2 & HDSP_wc_lock) {
     2883                snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
     2884        } else {
     2885                snd_iprintf (buffer, "Word Clock: No Lock\n");
     2886        }
     2887       
     2888        x = status & HDSP_TimecodeSync;
     2889        if (status & HDSP_TimecodeLock) {
     2890                snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
     2891        } else {
     2892                snd_iprintf(buffer, "ADAT Sync: No Lock\n");
    20402893        }
    20412894
     
    20542907        snd_info_entry_t *entry;
    20552908
    2056         if ((entry = snd_info_create_card_entry(hdsp->card, "hdsp", hdsp->card->proc_root)) !=
    2057             NULL) {
    2058                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    2059                 entry->private_data = hdsp;
    2060                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    2061                 entry->c.text.read_size = 256;
    2062                 entry->c.text.read = snd_hdsp_proc_read;
    2063                 if (snd_info_register(entry) < 0) {
    2064                         snd_info_free_entry(entry);
    2065                         entry = NULL;
    2066                 }
    2067         }
    2068         hdsp->proc_entry = entry;
    2069 }
    2070 
    2071 static void snd_hdsp_proc_done(hdsp_t *hdsp)
    2072 {
    2073         if (hdsp->proc_entry) {
    2074                 snd_info_unregister(hdsp->proc_entry);
    2075                 hdsp->proc_entry = NULL;
    2076         }
     2909        if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
     2910                snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
    20772911}
    20782912
     
    21592993}
    21602994
    2161 static void snd_hdsp_set_defaults(hdsp_t *hdsp)
     2995static int snd_hdsp_set_defaults(hdsp_t *hdsp)
    21622996{
    21632997        unsigned int i;
     
    21923026        }
    21933027
    2194         for (i = 0; i < 2048; i++)
    2195                 hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN);
    2196 
    2197         if (line_outs_monitor[hdsp->dev]) {
     3028        for (i = 0; i < (hdsp_is_9652(hdsp) ? 1352 : HDSP_MATRIX_MIXER_SIZE); i++) {
     3029                if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
     3030                        return -EIO;
     3031                }
     3032        }
     3033       
     3034        if (!hdsp_is_9652(hdsp) && line_outs_monitor[hdsp->dev]) {
    21983035               
    21993036                snd_printk ("sending all inputs and playback streams to line outs.\n");
     
    22053042                for (i = 0; i < HDSP_MAX_CHANNELS; i++) {
    22063043                        if (i & 1) {
    2207                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY (i, 26), UNITY_GAIN);
    2208                                 hdsp_write_gain (hdsp, PLAYBACK_TO_OUTPUT_KEY (i, 26), UNITY_GAIN);
     3044                                if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, 26), UNITY_GAIN) ||
     3045                                    hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, 26), UNITY_GAIN)) {
     3046                                    return -EIO;
     3047                                }   
    22093048                        } else {
    2210                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY (i, 27), UNITY_GAIN);
    2211                                 hdsp_write_gain (hdsp, PLAYBACK_TO_OUTPUT_KEY (i, 27), UNITY_GAIN);
     3049                                if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, 27), UNITY_GAIN) ||
     3050                                    hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, 27), UNITY_GAIN)) {
     3051                                    return -EIO;
     3052                                }
    22123053                        }
    22133054                }
     
    22193060         */
    22203061
    2221         hdsp_set_rate(hdsp, 48000);
    2222 }
    2223 
    2224 void snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     3062        hdsp_set_rate(hdsp, 48000, 1);
     3063
     3064        return 0;
     3065}
     3066
     3067void hdsp_midi_tasklet(unsigned long arg)
     3068{
     3069        hdsp_t *hdsp = (hdsp_t *)arg;
     3070       
     3071        if (hdsp->midi[0].pending) {
     3072                snd_hdsp_midi_input_read (&hdsp->midi[0]);
     3073        }
     3074        if (hdsp->midi[1].pending) {
     3075                snd_hdsp_midi_input_read (&hdsp->midi[1]);
     3076        }
     3077}
     3078
     3079static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    22253080{
    22263081        hdsp_t *hdsp = (hdsp_t *) dev_id;
     
    22313086        unsigned int midi0status;
    22323087        unsigned int midi1status;
    2233 
     3088        int schedule = 0;
     3089       
    22343090        status = hdsp_read(hdsp, HDSP_statusRegister);
    22353091
     
    22393095
    22403096        if (!audio && !midi0 && !midi1) {
    2241                 return;
     3097                return IRQ_NONE;
    22423098        }
    22433099
     
    22463102        midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
    22473103        midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
    2248 
     3104       
    22493105        if (audio) {
    22503106                if (hdsp->capture_substream) {
     
    22563112                }
    22573113        }
    2258 
    2259         /* note: snd_hdsp_midi_input_read() calls output_write() because
    2260            output is not interrupt-driven ...
    2261         */
    2262 
    2263         if (midi0status)
    2264                 snd_hdsp_midi_input_read (&hdsp->midi[0]);
    2265         if (midi1status)
    2266                 snd_hdsp_midi_input_read (&hdsp->midi[1]);
     3114       
     3115        if (midi0 && midi0status) {
     3116                /* we disable interrupts for this input until processing is done */
     3117                hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
     3118                hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     3119                hdsp->midi[0].pending = 1;
     3120                schedule = 1;
     3121        }
     3122        if (midi1 && midi1status) {
     3123                /* we disable interrupts for this input until processing is done */
     3124                hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
     3125                hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     3126                hdsp->midi[1].pending = 1;
     3127                schedule = 1;
     3128        }
     3129        if (schedule)
     3130            tasklet_hi_schedule(&hdsp->midi_tasklet);
     3131        return IRQ_HANDLED;
    22673132}
    22683133
     
    23033168        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23043169        snd_assert(channel_buf != NULL, return -EIO);
    2305         if (copy_from_user(channel_buf + pos * 4, src, count * 4))
    2306                 return -EFAULT;
     3170        copy_from_user(channel_buf + pos * 4, src, count * 4);
    23073171        return count;
    23083172}
     
    23183182        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23193183        snd_assert(channel_buf != NULL, return -EIO);
    2320         if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
    2321                 return -EFAULT;
     3184        copy_to_user(dst, channel_buf + pos * 4, count * 4);
    23223185        return count;
    23233186}
     
    23493212                runtime->status->hw_ptr = 0;
    23503213        if (other) {
    2351                 snd_pcm_substream_t *s = substream;
     3214                struct list_head *pos;
     3215                snd_pcm_substream_t *s;
    23523216                snd_pcm_runtime_t *oruntime = other->runtime;
    2353                 do {
    2354                         s = s->link_next;
     3217                snd_pcm_group_for_each(pos, substream) {
     3218                        s = snd_pcm_group_substream_entry(pos);
    23553219                        if (s == other) {
    23563220                                oruntime->status->hw_ptr = runtime->status->hw_ptr;
    23573221                                break;
    23583222                        }
    2359                 } while (s != substream);
     3223                }
    23603224        }
    23613225        return 0;
     
    23713235
    23723236        if (hdsp_check_for_iobox (hdsp)) {
     3237                return -EIO;
     3238        }
     3239
     3240        if (hdsp_check_for_firmware(hdsp)) {
     3241                if (hdsp->state & HDSP_FirmwareCached) {
     3242                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3243                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3244                        }
     3245                } else {
     3246                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3247                }
    23733248                return -EIO;
    23743249        }
     
    23933268                 */
    23943269
    2395                 if ((int)params_rate(params) != hdsp_system_sample_rate(hdsp)) {
     3270                if (params_rate(params) != hdsp->system_sample_rate) {
    23963271                        spin_unlock_irq(&hdsp->lock);
    23973272                        _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
     
    24173292         */
    24183293
    2419         if ((err = hdsp_set_rate(hdsp, params_rate(params))) < 0) {
     3294        if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
    24203295                _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
    24213296                return err;
     
    24343309{
    24353310        hdsp_t *hdsp = _snd_pcm_substream_chip(substream);
    2436         int chn;
     3311        int mapped_channel;
    24373312
    24383313        snd_assert(info->channel < HDSP_MAX_CHANNELS, return -EINVAL);
    24393314
    2440         if ((chn = hdsp->channel_map[info->channel]) < 0) {
     3315        if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
    24413316                return -EINVAL;
    24423317        }
    24433318
    2444         info->offset = chn * HDSP_CHANNEL_BUFFER_BYTES;
     3319        info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
    24453320        info->first = 0;
    24463321        info->step = 32;
     
    24753350       
    24763351        if (hdsp_check_for_iobox (hdsp)) {
     3352                return -EIO;
     3353        }
     3354
     3355        if (hdsp_check_for_firmware(hdsp)) {
     3356                if (hdsp->state & HDSP_FirmwareCached) {
     3357                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3358                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3359                        }
     3360                } else {
     3361                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3362                }
    24773363                return -EIO;
    24783364        }
     
    24983384
    24993385        if (other) {
    2500                 snd_pcm_substream_t *s = substream;
    2501                 do {
    2502                         s = s->link_next;
     3386                struct list_head *pos;
     3387                snd_pcm_substream_t *s;
     3388                snd_pcm_group_for_each(pos, substream) {
     3389                        s = snd_pcm_group_substream_entry(pos);
    25033390                        if (s == other) {
    25043391                                snd_pcm_trigger_done(s, substream);
     
    25093396                                goto _ok;
    25103397                        }
    2511                 } while (s != substream);
     3398                }
    25123399                if (cmd == SNDRV_PCM_TRIGGER_START) {
    25133400                        if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
     
    25413428
    25423429        if (hdsp_check_for_iobox (hdsp)) {
     3430                return -EIO;
     3431        }
     3432
     3433        if (hdsp_check_for_firmware(hdsp)) {
     3434                if (hdsp->state & HDSP_FirmwareCached) {
     3435                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3436                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3437                        }
     3438                } else {
     3439                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3440                }
    25433441                return -EIO;
    25443442        }
     
    25673465        .rate_min =             32000,
    25683466        .rate_max =             96000,
    2569         .channels_min =         10,
     3467        .channels_min =         14,
    25703468        .channels_max =         HDSP_MAX_CHANNELS,
    25713469        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
    2572         .period_bytes_min =     (64 * 4) *10,
     3470        .period_bytes_min =     (64 * 4) * 10,
    25733471        .period_bytes_max =     (8192 * 4) * HDSP_MAX_CHANNELS,
    25743472        .periods_min =          2,
    25753473        .periods_max =          2,
    2576         .fifo_size =            0,
     3474        .fifo_size =            0
    25773475};
    25783476
     
    25923490        .rate_min =             32000,
    25933491        .rate_max =             96000,
    2594         .channels_min =         10,
     3492        .channels_min =         14,
    25953493        .channels_max =         HDSP_MAX_CHANNELS,
    25963494        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
     
    25993497        .periods_min =          2,
    26003498        .periods_max =          2,
    2601         .fifo_size =            0,
     3499        .fifo_size =            0
    26023500};
    26033501
     
    26793577        }
    26803578
     3579        if (hdsp_check_for_firmware(hdsp)) {
     3580                if (hdsp->state & HDSP_FirmwareCached) {
     3581                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3582                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3583                        }
     3584                } else {
     3585                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3586                }
     3587                return -EIO;
     3588        }
     3589
    26813590        spin_lock_irqsave(&hdsp->lock, flags);
    26823591
     
    27103619
    27113620        hdsp->creg_spdif_stream = hdsp->creg_spdif;
    2712         hdsp->spdif_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     3621        hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    27133622        snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
    27143623                       SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
     
    27283637        spin_unlock_irqrestore(&hdsp->lock, flags);
    27293638
    2730         hdsp->spdif_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     3639        hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    27313640        snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
    27323641                       SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
     
    27423651
    27433652        if (hdsp_check_for_iobox (hdsp)) {
     3653                return -EIO;
     3654        }
     3655
     3656        if (hdsp_check_for_firmware(hdsp)) {
     3657                if (hdsp->state & HDSP_FirmwareCached) {
     3658                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3659                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3660                        }
     3661                } else {
     3662                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3663                }
    27443664                return -EIO;
    27453665        }
     
    27913711}
    27923712
     3713static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
     3714{
     3715    /* we have nothing to initialize but the call is required */
     3716    return 0;
     3717}
     3718
     3719
     3720static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
     3721{
     3722        hdsp_t *hdsp = (hdsp_t *)hw->private_data;     
     3723        hdsp_peak_rms_t *peak_rms;
     3724        hdsp_firmware_t *firmware;
     3725        hdsp_mixer_t    *mixer;
     3726        hdsp_config_info_t info;
     3727        hdsp_version_t hdsp_version;
     3728        int i;
     3729        int err;
     3730        unsigned long flags;
     3731       
     3732        switch (cmd) {
     3733        case SNDRV_HDSP_IOCTL_GET_PEAK_RMS:
     3734                if (!(hdsp->state & HDSP_FirmwareLoaded)) {
     3735                        snd_printk("firmware needs to be uploaded to the card.\n");     
     3736                        return -EINVAL;
     3737                }
     3738                peak_rms = (hdsp_peak_rms_t *)arg;
     3739                if (copy_to_user_fromio((void *)peak_rms->playback_peaks, hdsp->iobase+HDSP_playbackPeakLevel, 26*4) != 0) {
     3740                        return -EFAULT;
     3741                }
     3742                if (copy_to_user_fromio((void *)peak_rms->input_peaks, hdsp->iobase+HDSP_inputPeakLevel, 26*4) != 0) {
     3743                        return -EFAULT;
     3744                }
     3745                if (copy_to_user_fromio((void *)peak_rms->output_peaks, hdsp->iobase+HDSP_outputPeakLevel, 28*4) != 0) {
     3746                        return -EFAULT;
     3747                }
     3748                if (copy_to_user_fromio((void *)peak_rms->playback_rms, hdsp->iobase+HDSP_playbackRmsLevel, 26*8) != 0) {
     3749                        return -EFAULT;
     3750                }
     3751                if (copy_to_user_fromio((void *)peak_rms->input_rms, hdsp->iobase+HDSP_inputRmsLevel, 26*8) != 0) {
     3752                        return -EFAULT;
     3753                }
     3754                break;
     3755        case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO:
     3756                if (!(hdsp->state & HDSP_FirmwareLoaded)) {
     3757                        snd_printk("Firmware needs to be uploaded to the card.\n");     
     3758                        return -EINVAL;
     3759                }
     3760                spin_lock_irqsave(&hdsp->lock, flags);
     3761                info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
     3762                info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
     3763                info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
     3764                info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
     3765                for (i = 0; i < ((hdsp->io_type != Multiface) ? 3 : 1); ++i) {
     3766                        info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
     3767                }
     3768                info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
     3769                info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
     3770                info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
     3771                info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
     3772                info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
     3773                info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
     3774                info.system_sample_rate = hdsp->system_sample_rate;
     3775                info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
     3776                info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
     3777                info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
     3778                info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
     3779                info.line_out = (unsigned char)hdsp_line_out(hdsp);
     3780                info.passthru = (unsigned char)hdsp->passthru;
     3781                spin_unlock_irqrestore(&hdsp->lock, flags);
     3782                if (copy_to_user((void *)arg, &info, sizeof(info)))
     3783                        return -EFAULT;
     3784                break;
     3785        case SNDRV_HDSP_IOCTL_GET_VERSION:
     3786                if (hdsp_is_9652(hdsp)) return -EINVAL;
     3787                if (hdsp->io_type == Undefined) {
     3788                        if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
     3789                                return err;
     3790                        }
     3791                }
     3792                hdsp_version.io_type = hdsp->io_type;
     3793                hdsp_version.firmware_rev = hdsp->firmware_rev;
     3794                if ((err = copy_to_user((void *)arg, &hdsp_version, sizeof(hdsp_version)))) {
     3795                        return -EFAULT;
     3796                }
     3797                break;
     3798        case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE:
     3799                if (hdsp_is_9652(hdsp)) return -EINVAL;
     3800                /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
     3801                if (hdsp->io_type == Undefined) return -EINVAL;
     3802
     3803                snd_printk("initializing firmware upload\n");
     3804                firmware = (hdsp_firmware_t *)arg;
     3805
     3806                if (hdsp_check_for_iobox (hdsp)) {
     3807                        return -EIO;
     3808                }
     3809
     3810                if (copy_from_user(hdsp->firmware_cache, firmware->firmware_data, sizeof(unsigned long)*24413) != 0) {
     3811                        return -EFAULT;
     3812                }
     3813               
     3814                hdsp->state |= HDSP_FirmwareCached;
     3815
     3816                if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
     3817                        return err;
     3818                }
     3819               
     3820               
     3821                if (!(hdsp->state & HDSP_InitializationComplete)) {
     3822                        snd_hdsp_initialize_channels(hdsp);
     3823               
     3824                        snd_hdsp_initialize_midi_flush(hdsp);
     3825           
     3826                        if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
     3827                                snd_printk("error creating alsa devices\n");
     3828                            return err;
     3829                        }
     3830                }
     3831                break;
     3832        case SNDRV_HDSP_IOCTL_GET_MIXER:
     3833                mixer = (hdsp_mixer_t *)arg;
     3834                if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
     3835                        return -EFAULT;
     3836                break;
     3837        default:
     3838                return -EINVAL;
     3839        }
     3840        return 0;
     3841}
     3842
    27933843static snd_pcm_ops_t snd_hdsp_playback_ops = {
    27943844        .open =         snd_hdsp_playback_open,
     
    28143864};
    28153865
     3866static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
     3867                                           hdsp_t *hdsp)
     3868{
     3869        snd_hwdep_t *hw;
     3870        int err;
     3871       
     3872        if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
     3873                return err;
     3874               
     3875        hdsp->hwdep = hw;
     3876        hw->private_data = hdsp;
     3877        strcpy(hw->name, "HDSP hwdep interface");
     3878
     3879        hw->ops.open = snd_hdsp_hwdep_dummy_op;
     3880        hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
     3881        hw->ops.release = snd_hdsp_hwdep_dummy_op;
     3882               
     3883        return 0;
     3884}
     3885
    28163886static int __devinit snd_hdsp_create_pcm(snd_card_t *card,
    28173887                                         hdsp_t *hdsp)
     
    28353905}
    28363906
    2837 static int __devinit snd_hdsp_initialize_firmware (hdsp_t *hdsp)
     3907static inline int snd_hdsp_initialize_input_enable (hdsp_t *hdsp)
    28383908{
    28393909        int i;
    2840         u32 *firmware_ptr;
    2841 
    2842         if (hdsp_check_for_iobox (hdsp)) {
    2843                 return -EIO;
    2844         }
    2845 
     3910       
    28463911        if (hdsp_fifo_wait (hdsp, 0, 100)) {
    28473912                return -EIO;
    28483913        }
    28493914       
    2850         /* enable all channels */
    2851 
    28523915        for (i = 0; i < HDSP_MAX_CHANNELS; ++i) {
    28533916                hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
    28543917                hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
    28553918        }
    2856 
    2857         if (force_firmware[hdsp->dev] || (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
    2858 
    2859                 snd_printk ("loading firmware\n");
    2860 
    2861                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_PROGRAM);
    2862                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2863                 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
    2864                         snd_printk ("timeout waiting for firmware setup\n");
    2865                         return -EIO;
    2866                 }
    2867 
    2868                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2869                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2870 
    2871                 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
    2872                         hdsp->type = Multiface;
    2873                         hdsp_write (hdsp, HDSP_jtagReg, HDSP_VERSION_BIT);
    2874                         hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2875                         hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
    2876                 } else {
    2877                         hdsp->type = Digiface;
    2878                 }
    2879 
    2880                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_PROGRAM);
    2881                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2882                
    2883                 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
    2884                         snd_printk ("timeout waiting for download preparation\n");
    2885                         return -EIO;
    2886                 }
    2887                
    2888                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2889                
    2890                 if (hdsp->type == Digiface) {
    2891                         firmware_ptr = (u32 *) digiface_firmware;
    2892                 } else {
    2893                         firmware_ptr = (u32 *) multiface_firmware;
    2894                 }
    2895                
    2896                 for (i = 0; i < 24413; ++i) {
    2897                         hdsp_write(hdsp, HDSP_fifoData, firmware_ptr[i]);
    2898                         if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
    2899                                 snd_printk ("timeout during firmware loading\n");
    2900                                 return -EIO;
    2901                         }
    2902                 }
    2903                
    2904                 if (hdsp_fifo_wait (hdsp, 3, HDSP_LONG_WAIT)) {
    2905                         snd_printk ("timeout at end of firmware loading\n");
    2906                         return -EIO;
    2907                 }
    2908 
    2909         } else {
    2910 
    2911                 /* firmware already loaded, but we need to know what type
    2912                    of I/O box is connected.
    2913                 */
    2914 
    2915                 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
    2916                         hdsp->type = Multiface;
    2917                 } else {
    2918                         hdsp->type = Digiface;
    2919                 }
    2920         }
    2921 
    2922         if (hdsp->type == Digiface) {
    2923                 snd_printk ("I/O Box is a Digiface\n");
    2924                 hdsp->card_name = "RME Hammerfall DSP (Digiface)";
     3919       
     3920        return 0;
     3921}
     3922
     3923static inline void snd_hdsp_initialize_channels(hdsp_t *hdsp)
     3924{
     3925        if (hdsp->io_type == Digiface) {
     3926                hdsp->card_name = "RME Hammerfall DSP + Digiface";
    29253927                hdsp->ss_channels = DIGIFACE_SS_CHANNELS;
    29263928                hdsp->ds_channels = DIGIFACE_DS_CHANNELS;
    29273929        } else {
    2928                 snd_printk ("I/O Box is a Multiface\n");
    2929                 hdsp->card_name = "RME Hammerfall DSP (Multiface)";
     3930                hdsp->card_name = "RME Hammerfall DSP + Multiface";
    29303931                hdsp->ss_channels = MULTIFACE_SS_CHANNELS;
    29313932                hdsp->ds_channels = MULTIFACE_DS_CHANNELS;
    29323933        }
    2933        
     3934}
     3935
     3936static inline void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
     3937{
    29343938        snd_hdsp_flush_midi_input (hdsp, 0);
    29353939        snd_hdsp_flush_midi_input (hdsp, 1);
     
    29383942        hdsp_write(hdsp, HDSP_jtagReg, HDSP_BIGENDIAN_MODE);
    29393943#endif
    2940 
     3944}
     3945
     3946static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
     3947{
     3948        int err;
     3949       
     3950        if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
     3951                return err;
     3952        }
     3953       
     3954        if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
     3955                return err;
     3956        }
     3957
     3958        if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
     3959                return err;
     3960        }
     3961
     3962        if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
     3963                return err;
     3964        }
     3965
     3966        snd_hdsp_proc_init(hdsp);
     3967
     3968        hdsp->last_spdif_sample_rate = -1;
     3969        hdsp->system_sample_rate = -1;
     3970        hdsp->last_external_sample_rate = -1;
     3971        hdsp->last_internal_sample_rate = -1;
     3972        hdsp->playback_pid = -1;
     3973        hdsp->capture_pid = -1;
     3974        hdsp->capture_substream = NULL;
     3975        hdsp->playback_substream = NULL;
     3976
     3977        if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
     3978                return err;
     3979        }
     3980       
     3981        hdsp_update_simple_mixer_controls(hdsp);
     3982       
     3983        if (!(hdsp->state & HDSP_InitializationComplete)) {
     3984                sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
     3985                        hdsp->port, hdsp->irq);
     3986           
     3987                if ((err = snd_card_register(card)) < 0) {
     3988                        snd_printk("error registering card\n");
     3989                        return err;
     3990                }
     3991                hdsp->state |= HDSP_InitializationComplete;
     3992        }
     3993       
    29413994        return 0;
    29423995}
     
    29484001        struct pci_dev *pci = hdsp->pci;
    29494002        int err;
    2950         unsigned short rev;
     4003        int i;
    29514004
    29524005        hdsp->irq = -1;
     4006        hdsp->state = 0;
    29534007        hdsp->midi[0].rmidi = 0;
    29544008        hdsp->midi[1].rmidi = 0;
     
    29614015        hdsp->iobase = 0;
    29624016        hdsp->res_port = 0;
     4017        hdsp->io_type = Undefined;
     4018        for (i = 0; i < HDSP_MAX_CHANNELS; ++i)
     4019                hdsp->playback_mixer_ctls[i] = 0;
    29634020
    29644021        hdsp->card = card;
     
    29664023        spin_lock_init(&hdsp->lock);
    29674024
    2968         pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &rev);
     4025        tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
     4026       
     4027        pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
    29694028        strcpy(card->driver, "H-DSP");
    29704029        strcpy(card->mixername, "Xilinx FPGA");
    29714030       
    2972         switch (rev & 0xff) {
     4031        switch (hdsp->firmware_rev & 0xff) {
    29734032        case 0xa:
    29744033        case 0xb:
     4034                hdsp->card_name = "RME Hammerfall DSP";
     4035                break;
    29754036        case 0x64:
    2976                 /* hdsp_initialize_firmware() will reset this */
    2977                 hdsp->card_name = "RME Hammerfall DSP";
    2978                 break;
    2979 
     4037        case 0x65:
     4038        case 0x68:
     4039                hdsp->card_name = "RME HDSP 9652";
     4040                break;
    29804041        default:
    29814042                return -ENODEV;
     
    30104071                return err;
    30114072        }
    3012 
    3013         if ((err = snd_hdsp_initialize_firmware(hdsp)) < 0) {
     4073       
     4074        if (hdsp_is_9652(hdsp)) {
     4075               
     4076                if ((err = snd_hdsp_initialize_input_enable(hdsp)) != 0) {
     4077                        return err;
     4078                }
     4079
     4080                hdsp->io_type = Digiface;               
     4081       
     4082                hdsp->ss_channels = DIGIFACE_SS_CHANNELS;
     4083                hdsp->ds_channels = DIGIFACE_DS_CHANNELS;
     4084       
     4085                snd_hdsp_initialize_midi_flush(hdsp);
     4086       
     4087                if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4088                        return err;
     4089                }
     4090
     4091        } else {
     4092       
     4093                if (hdsp_check_for_iobox (hdsp)) {
     4094                        /* no iobox connected, we defer initialization */
     4095                        snd_printk("card initialization pending : waiting for firmware\n");
     4096                        if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4097                                return err;
     4098                        }
     4099                        return 0;
     4100                }
     4101
     4102                if ((err = snd_hdsp_initialize_input_enable(hdsp)) != 0) {
     4103                        return err;
     4104                }
     4105               
     4106                if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     4107                        snd_printk("card initialization pending : waiting for firmware\n");
     4108                        if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4109                                return err;
     4110                        }
     4111                return 0;
     4112                }
     4113               
     4114                snd_printk("Firmware already loaded, initializing card.\n");
     4115
     4116                if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
     4117                        hdsp->io_type = Multiface;
     4118                } else {
     4119                        hdsp->io_type = Digiface;
     4120                }
     4121               
     4122                if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4123                        return err;
     4124                }
     4125               
     4126                snd_hdsp_initialize_channels(hdsp);
     4127               
     4128                snd_hdsp_initialize_midi_flush(hdsp);
     4129               
     4130        }
     4131       
     4132        hdsp->state |= HDSP_FirmwareLoaded;     
     4133       
     4134        if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
    30144135                return err;
    30154136        }
    3016 
    3017         if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
    3018                 return err;
    3019         }
    3020 
    3021         if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
    3022                 return err;
    3023         }
    3024 
    3025         if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
    3026                 return err;
    3027         }
    3028 
    3029         if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
    3030                 return err;
    3031         }
    3032 
    3033         snd_hdsp_proc_init(hdsp);
    3034 
    3035         hdsp->last_spdif_sample_rate = -1;
    3036         hdsp->last_adat_sample_rate = -1;
    3037         hdsp->playback_pid = -1;
    3038         hdsp->capture_pid = -1;
    3039         hdsp->capture_substream = NULL;
    3040         hdsp->playback_substream = NULL;
    3041 
    3042         snd_hdsp_set_defaults(hdsp);
    3043 
    3044         return 0;
     4137       
     4138        return 0;       
    30454139}
    30464140
    30474141static int snd_hdsp_free(hdsp_t *hdsp)
    30484142{
    3049         /* stop the audio, and cancel all interrupts */
    3050         hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
    3051         hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
     4143        if (hdsp->res_port) {
     4144                /* stop the audio, and cancel all interrupts */
     4145                hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
     4146                hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
     4147        }
    30524148
    30534149        if (hdsp->irq >= 0)
    30544150                free_irq(hdsp->irq, (void *)hdsp);
    30554151
    3056         snd_hdsp_proc_done(hdsp);
    30574152        snd_hdsp_free_buffers(hdsp);
    30584153       
     
    31244219
    31254220static struct pci_driver driver = {
    3126         .name = "RME Hammerfall DSP",
     4221        .name =     "RME Hammerfall DSP",
    31274222        .id_table = snd_hdsp_ids,
    3128         .probe = snd_hdsp_probe,
     4223        .probe =    snd_hdsp_probe,
    31294224        .remove = __devexit_p(snd_hdsp_remove),
    31304225};
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/rme9652.c

    r224 r246  
    19471947}
    19481948
    1949 void snd_rme9652_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     1949static irqreturn_t snd_rme9652_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    19501950{
    19511951        rme9652_t *rme9652 = (rme9652_t *) dev_id;
    19521952
    19531953        if (!(rme9652_read(rme9652, RME9652_status_register) & RME9652_IRQ)) {
    1954                 return;
     1954                return IRQ_NONE;
    19551955        }
    19561956
     
    19641964                snd_pcm_period_elapsed(rme9652->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
    19651965        }
     1966        return IRQ_HANDLED;
    19661967}
    19671968
     
    20542055                runtime->status->hw_ptr = 0;
    20552056        if (other) {
    2056                 snd_pcm_substream_t *s = substream;
     2057                struct list_head *pos;
     2058                snd_pcm_substream_t *s;
    20572059                snd_pcm_runtime_t *oruntime = other->runtime;
    2058                 do {
    2059                         s = s->link_next;
     2060                snd_pcm_group_for_each(pos, substream) {
     2061                        s = snd_pcm_group_substream_entry(pos);
    20602062                        if (s == other) {
    20612063                                oruntime->status->hw_ptr = runtime->status->hw_ptr;
    20622064                                break;
    20632065                        }
    2064                 } while (s != substream);
     2066                }
    20652067        }
    20662068        return 0;
     
    22002202
    22012203        if (other) {
    2202                 snd_pcm_substream_t *s = substream;
    2203                 do {
    2204                         s = s->link_next;
     2204                struct list_head *pos;
     2205                snd_pcm_substream_t *s;
     2206                snd_pcm_group_for_each(pos, substream) {
     2207                        s = snd_pcm_group_substream_entry(pos);
    22052208                        if (s == other) {
    22062209                                snd_pcm_trigger_done(s, substream);
     
    22112214                                goto _ok;
    22122215                        }
    2213                 } while (s != substream);
     2216                }
    22142217                if (cmd == SNDRV_PCM_TRIGGER_START) {
    22152218                        if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
     
    24052408
    24062409        rme9652->creg_spdif_stream = rme9652->creg_spdif;
    2407         rme9652->spdif_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     2410        rme9652->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    24082411        snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
    24092412                       SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id);
     
    24232426        spin_unlock_irqrestore(&rme9652->lock, flags);
    24242427
    2425         rme9652->spdif_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     2428        rme9652->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    24262429        snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
    24272430                       SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/sonicvibes.c

    r224 r246  
    602602}
    603603
    604 static void snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    605 {
    606         sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, dev_id, return);
     604static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     605{
     606        sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, dev_id, return IRQ_NONE);
    607607        unsigned char status;
    608608
    609609        status = inb(SV_REG(sonic, STATUS));
    610610        if (!(status & (SV_DMAA_IRQ | SV_DMAC_IRQ | SV_MIDI_IRQ)))
    611                 return;
     611                return IRQ_NONE;
    612612        if (status == 0xff) {   /* failure */
    613613                outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
    614614                snd_printk("IRQ failure - interrupts disabled!!\n");
    615                 return;
     615                return IRQ_HANDLED;
    616616        }
    617617        if (sonic->pcm) {
     
    660660                snd_ctl_notify(sonic->card, SNDRV_CTL_EVENT_MASK_VALUE, &sonic->master_volume->id);
    661661        }
     662        return IRQ_HANDLED;
    662663}
    663664
  • GPL/branches/alsa-resync1/alsa-kernel/pci/trident/trident_main.c

    r224 r246  
    27152715        .name =         "PCM Front Playback Volume",
    27162716        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2717        .count =        32,
    27172718        .info =         snd_trident_pcm_vol_control_info,
    27182719        .get =          snd_trident_pcm_vol_control_get,
     
    27762777        .name =         "PCM Pan Playback Control",
    27772778        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2779        .count =        32,
    27782780        .info =         snd_trident_pcm_pan_control_info,
    27792781        .get =          snd_trident_pcm_pan_control_get,
     
    28292831        .name =         "PCM Reverb Playback Volume",
    28302832        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2833        .count =        32,
    28312834        .info =         snd_trident_pcm_rvol_control_info,
    28322835        .get =          snd_trident_pcm_rvol_control_get,
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ymfpci/ymfpci_main.c

    r224 r246  
    13681368{
    13691369        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    1370         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    1371         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
     1370        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1371        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
    13721372        .info =         snd_ymfpci_spdif_stream_info,
    13731373        .get =          snd_ymfpci_spdif_stream_get,
Note: See TracChangeset for help on using the changeset viewer.