X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fkorg1212%2Fkorg1212.c;h=e39fad1a420041cb5cb0aa3e1b3689dd473b128c;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=d196d224839d1ac15f5b9f3f6833856dd32cfee3;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index d196d2248..e39fad1a4 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -26,13 +26,14 @@ #include #include #include +#include +#include #include #include #include #include #include -#define SNDRV_GET_ID #include #include @@ -41,8 +42,16 @@ // Debug Stuff // ---------------------------------------------------------------------------- #define K1212_DEBUG_LEVEL 0 -#define K1212_DEBUG_PRINTK printk -//#define K1212_DEBUG_PRINTK(x...) printk("<0>" x) +#if K1212_DEBUG_LEVEL > 0 +#define K1212_DEBUG_PRINTK(fmt,args...) printk(KERN_DEBUG fmt,##args) +#else +#define K1212_DEBUG_PRINTK(fmt,...) +#endif +#if K1212_DEBUG_LEVEL > 1 +#define K1212_DEBUG_PRINTK_VERBOSE(fmt,args...) printk(KERN_DEBUG fmt,##args) +#else +#define K1212_DEBUG_PRINTK_VERBOSE(fmt,...) +#endif // ---------------------------------------------------------------------------- // Record/Play Buffer Allocation Method. If K1212_LARGEALLOC is defined all @@ -51,9 +60,9 @@ //#define K1212_LARGEALLOC 1 // ---------------------------------------------------------------------------- -// the following enum defines the valid states of the Korg 1212 I/O card. +// Valid states of the Korg 1212 I/O card. // ---------------------------------------------------------------------------- -typedef enum { +enum CardState { K1212_STATE_NONEXISTENT, // there is no card here K1212_STATE_UNINITIALIZED, // the card is awaiting DSP download K1212_STATE_DSP_IN_PROCESS, // the card is currently downloading its DSP code @@ -69,13 +78,13 @@ typedef enum { K1212_STATE_ERRORSTOP, // the card has stopped itself because of an error and we // are in the process of cleaning things up. K1212_STATE_MAX_STATE // state values of this and beyond are invalid -} CardState; +}; // ---------------------------------------------------------------------------- // The following enumeration defines the constants written to the card's // host-to-card doorbell to initiate a command. // ---------------------------------------------------------------------------- -typedef enum { +enum korg1212_dbcnst { K1212_DB_RequestForData = 0, // sent by the card to request a buffer fill. K1212_DB_TriggerPlay = 1, // starts playback/record on the card. K1212_DB_SelectPlayMode = 2, // select monitor, playback setup, or stop. @@ -85,22 +94,22 @@ typedef enum { K1212_DB_ConfigureMiscMemory = 6, // tells card where other buffers are. K1212_DB_TriggerFromAdat = 7, // tells card to trigger from Adat at a specific // timecode value. + K1212_DB_DMAERROR = 0x80, // DMA Error - the PCI bus is congestioned. + K1212_DB_CARDSTOPPED = 0x81, // Card has stopped by user request. K1212_DB_RebootCard = 0xA0, // instructs the card to reboot. K1212_DB_BootFromDSPPage4 = 0xA4, // instructs the card to boot from the DSP microcode // on page 4 (local page to card). K1212_DB_DSPDownloadDone = 0xAE, // sent by the card to indicate the download has // completed. K1212_DB_StartDSPDownload = 0xAF // tells the card to download its DSP firmware. -} korg1212_dbcnst_t; +}; -#define K1212_ISRCODE_DMAERROR 0x80 -#define K1212_ISRCODE_CARDSTOPPED 0x81 // ---------------------------------------------------------------------------- -// The following enumeration defines return codes for DeviceIoControl() calls +// The following enumeration defines return codes // to the Korg 1212 I/O driver. // ---------------------------------------------------------------------------- -typedef enum { +enum snd_korg1212rc { K1212_CMDRET_Success = 0, // command was successfully placed K1212_CMDRET_DIOCFailure, // the DeviceIoControl call failed K1212_CMDRET_PMFailure, // the protected mode call failed @@ -116,34 +125,29 @@ typedef enum { K1212_CMDRET_NoAckFromCard, // the card never acknowledged a command K1212_CMDRET_BadParams, // bad parameters were provided by the caller - // -------------------------------------------------------------- - // the following return errors are specific to the wave device - // driver interface. These will not be encountered by users of - // the 32 bit DIOC interface (a.k.a. custom or native API). - // -------------------------------------------------------------- K1212_CMDRET_BadDevice, // the specified wave device was out of range K1212_CMDRET_BadFormat // the specified wave format is unsupported -} snd_korg1212rc; +}; // ---------------------------------------------------------------------------- // The following enumeration defines the constants used to select the play // mode for the card in the SelectPlayMode command. // ---------------------------------------------------------------------------- -typedef enum { +enum PlayModeSelector { K1212_MODE_SetupPlay = 0x00000001, // provides card with pre-play information K1212_MODE_MonitorOn = 0x00000002, // tells card to turn on monitor mode K1212_MODE_MonitorOff = 0x00000004, // tells card to turn off monitor mode K1212_MODE_StopPlay = 0x00000008 // stops playback on the card -} PlayModeSelector; +}; // ---------------------------------------------------------------------------- // The following enumeration defines the constants used to select the monitor // mode for the card in the SetMonitorMode command. // ---------------------------------------------------------------------------- -typedef enum { +enum MonitorModeSelector { K1212_MONMODE_Off = 0, // tells card to turn off monitor mode K1212_MONMODE_On // tells card to turn on monitor mode -} MonitorModeSelector; +}; #define MAILBOX0_OFFSET 0x40 // location of mailbox 0 relative to base address #define MAILBOX1_OFFSET 0x44 // location of mailbox 1 relative to base address @@ -168,7 +172,7 @@ typedef enum { #define DOORBELL_VAL_MASK 0x00FF // the doorbell value is one byte #define CARD_BOOT_DELAY_IN_MS 10 - +#define CARD_BOOT_TIMEOUT 10 #define DSP_BOOT_DELAY_IN_MS 200 #define kNumBuffers 8 @@ -185,7 +189,7 @@ typedef enum { #define K1212_CHANNELS (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS) #define K1212_MIN_CHANNELS 1 #define K1212_MAX_CHANNELS K1212_CHANNELS -#define K1212_FRAME_SIZE (sizeof(KorgAudioFrame)) +#define K1212_FRAME_SIZE (sizeof(struct KorgAudioFrame)) #define K1212_MAX_SAMPLES (kPlayBufferFrames*kNumBuffers) #define K1212_PERIODS (kNumBuffers) #define K1212_PERIOD_BYTES (K1212_FRAME_SIZE*kPlayBufferFrames) @@ -261,14 +265,7 @@ typedef enum { #include "korg1212-firmware.h" -typedef struct _snd_korg1212 korg1212_t; - -typedef u16 K1212Sample; // channels 0-9 use 16 bit samples -typedef u32 K1212SpdifSample; // channels 10-11 use 32 bits - only 20 are sent - // across S/PDIF. -typedef u32 K1212TimeCodeSample; // holds the ADAT timecode value - -typedef enum { +enum ClockSourceIndex { K1212_CLKIDX_AdatAt44_1K = 0, // selects source as ADAT at 44.1 kHz K1212_CLKIDX_AdatAt48K, // selects source as ADAT at 48 kHz K1212_CLKIDX_WordAt44_1K, // selects source as S/PDIF at 44.1 kHz @@ -276,36 +273,36 @@ typedef enum { K1212_CLKIDX_LocalAt44_1K, // selects source as local clock at 44.1 kHz K1212_CLKIDX_LocalAt48K, // selects source as local clock at 48 kHz K1212_CLKIDX_Invalid // used to check validity of the index -} ClockSourceIndex; +}; -typedef enum { +enum ClockSourceType { K1212_CLKIDX_Adat = 0, // selects source as ADAT K1212_CLKIDX_Word, // selects source as S/PDIF K1212_CLKIDX_Local // selects source as local clock -} ClockSourceType; +}; -typedef struct KorgAudioFrame { - K1212Sample frameData16[k16BitChannels]; - K1212SpdifSample frameData32[k32BitChannels]; - K1212TimeCodeSample timeCodeVal; -} KorgAudioFrame; +struct KorgAudioFrame { + u16 frameData16[k16BitChannels]; /* channels 0-9 use 16 bit samples */ + u32 frameData32[k32BitChannels]; /* channels 10-11 use 32 bits - only 20 are sent across S/PDIF */ + u32 timeCodeVal; /* holds the ADAT timecode value */ +}; -typedef struct KorgAudioBuffer { - KorgAudioFrame bufferData[kPlayBufferFrames]; /* buffer definition */ -} KorgAudioBuffer; +struct KorgAudioBuffer { + struct KorgAudioFrame bufferData[kPlayBufferFrames]; /* buffer definition */ +}; -typedef struct KorgSharedBuffer { +struct KorgSharedBuffer { #ifdef K1212_LARGEALLOC - KorgAudioBuffer playDataBufs[kNumBuffers]; - KorgAudioBuffer recordDataBufs[kNumBuffers]; + struct KorgAudioBuffer playDataBufs[kNumBuffers]; + struct KorgAudioBuffer recordDataBufs[kNumBuffers]; #endif short volumeData[kAudioChannels]; u32 cardCommand; u16 routeData [kAudioChannels]; u32 AdatTimeCode; // ADAT timecode value -} KorgSharedBuffer; +}; -typedef struct SensBits { +struct SensBits { union { struct { unsigned int leftChanVal:8; @@ -320,16 +317,16 @@ typedef struct SensBits { } v; u16 rightSensBits; } r; -} SensBits; +}; -struct _snd_korg1212 { - snd_card_t *card; +struct snd_korg1212 { + struct snd_card *card; struct pci_dev *pci; - snd_pcm_t *pcm; + struct snd_pcm *pcm; int irq; spinlock_t lock; - struct semaphore open_mutex; + struct mutex open_mutex; struct timer_list timer; /* timer callback for checking ack of stop request */ int stop_pending_cnt; /* counter for stop pending check */ @@ -341,13 +338,7 @@ struct _snd_korg1212 { unsigned long iomem2; unsigned long irqcount; unsigned long inIRQ; - unsigned long iobase; - - struct resource *res_iomem; - struct resource *res_ioport; - struct resource *res_iomem2; - - struct snd_dma_device dma_dev; + void __iomem *iobase; struct snd_dma_buffer dma_dsp; struct snd_dma_buffer dma_play; @@ -358,10 +349,10 @@ struct _snd_korg1212 { u32 DataBufsSize; - KorgAudioBuffer * playDataBufsPtr; - KorgAudioBuffer * recordDataBufsPtr; + struct KorgAudioBuffer * playDataBufsPtr; + struct KorgAudioBuffer * recordDataBufsPtr; - KorgSharedBuffer * sharedBufferPtr; + struct KorgSharedBuffer * sharedBufferPtr; u32 RecDataPhy; u32 PlayDataPhy; @@ -370,32 +361,35 @@ struct _snd_korg1212 { u32 RoutingTablePhy; u32 AdatTimeCodePhy; - u32 * statusRegPtr; // address of the interrupt status/control register - u32 * outDoorbellPtr; // address of the host->card doorbell register - u32 * inDoorbellPtr; // address of the card->host doorbell register - u32 * mailbox0Ptr; // address of mailbox 0 on the card - u32 * mailbox1Ptr; // address of mailbox 1 on the card - u32 * mailbox2Ptr; // address of mailbox 2 on the card - u32 * mailbox3Ptr; // address of mailbox 3 on the card - u32 * controlRegPtr; // address of the EEPROM, PCI, I/O, Init ctrl reg - u16 * sensRegPtr; // address of the sensitivity setting register - u32 * idRegPtr; // address of the device and vendor ID registers + u32 __iomem * statusRegPtr; // address of the interrupt status/control register + u32 __iomem * outDoorbellPtr; // address of the host->card doorbell register + u32 __iomem * inDoorbellPtr; // address of the card->host doorbell register + u32 __iomem * mailbox0Ptr; // address of mailbox 0 on the card + u32 __iomem * mailbox1Ptr; // address of mailbox 1 on the card + u32 __iomem * mailbox2Ptr; // address of mailbox 2 on the card + u32 __iomem * mailbox3Ptr; // address of mailbox 3 on the card + u32 __iomem * controlRegPtr; // address of the EEPROM, PCI, I/O, Init ctrl reg + u16 __iomem * sensRegPtr; // address of the sensitivity setting register + u32 __iomem * idRegPtr; // address of the device and vendor ID registers size_t periodsize; int channels; int currentBuffer; - snd_pcm_substream_t *playback_substream; - snd_pcm_substream_t *capture_substream; + struct snd_pcm_substream *playback_substream; + struct snd_pcm_substream *capture_substream; + + pid_t capture_pid; + pid_t playback_pid; - CardState cardState; + enum CardState cardState; int running; int idleMonitorOn; // indicates whether the card is in idle monitor mode. u32 cmdRetryCount; // tracks how many times we have retried sending to the card. - ClockSourceIndex clkSrcRate; // sample rate and clock source + enum ClockSourceIndex clkSrcRate; // sample rate and clock source - ClockSourceType clkSource; // clock source + enum ClockSourceType clkSource; // clock source int clkRate; // clock rate int volumePhase[kAudioChannels]; @@ -403,33 +397,34 @@ struct _snd_korg1212 { u16 leftADCInSens; // ADC left channel input sensitivity u16 rightADCInSens; // ADC right channel input sensitivity - int opencnt; // Open/Close count - int setcnt; // SetupForPlay count - int playcnt; // TriggerPlay count + int opencnt; // Open/Close count + int setcnt; // SetupForPlay count + int playcnt; // TriggerPlay count + int errorcnt; // Error Count + unsigned long totalerrorcnt; // Total Error Count + + int dsp_is_loaded; + int dsp_stop_is_processed; }; MODULE_DESCRIPTION("korg1212"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{KORG,korg1212}}"); +MODULE_SUPPORTED_DEVICE("{{KORG,korg1212}}"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ -MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Korg 1212 soundcard."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); +module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Korg 1212 soundcard."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); MODULE_AUTHOR("Haroldo Gamal "); -static struct pci_device_id snd_korg1212_ids[] = { +static struct pci_device_id snd_korg1212_ids[] __devinitdata = { { .vendor = 0x10b5, .device = 0x906d, @@ -439,59 +434,58 @@ static struct pci_device_id snd_korg1212_ids[] = { { 0, }, }; -static char* stateName[] = { - "Non-existent", - "Uninitialized", - "DSP download in process", - "DSP download complete", - "Ready", - "Open", - "Setup for play", - "Playing", - "Monitor mode on", - "Calibrating" - "Invalid" +MODULE_DEVICE_TABLE(pci, snd_korg1212_ids); + +static char *stateName[] = { + "Non-existent", + "Uninitialized", + "DSP download in process", + "DSP download complete", + "Ready", + "Open", + "Setup for play", + "Playing", + "Monitor mode on", + "Calibrating", + "Invalid" }; -static char* clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" }; +static char *clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" }; -static char* clockSourceName[] = { - "ADAT at 44.1 kHz", - "ADAT at 48 kHz", - "S/PDIF at 44.1 kHz", - "S/PDIF at 48 kHz", - "local clock at 44.1 kHz", - "local clock at 48 kHz" +static char *clockSourceName[] = { + "ADAT at 44.1 kHz", + "ADAT at 48 kHz", + "S/PDIF at 44.1 kHz", + "S/PDIF at 48 kHz", + "local clock at 44.1 kHz", + "local clock at 48 kHz" }; -static char* channelName[] = { - "ADAT-1", - "ADAT-2", - "ADAT-3", - "ADAT-4", - "ADAT-5", - "ADAT-6", - "ADAT-7", - "ADAT-8", - "Analog-L", - "Analog-R", - "SPDIF-L", - "SPDIF-R", +static char *channelName[] = { + "ADAT-1", + "ADAT-2", + "ADAT-3", + "ADAT-4", + "ADAT-5", + "ADAT-6", + "ADAT-7", + "ADAT-8", + "Analog-L", + "Analog-R", + "SPDIF-L", + "SPDIF-R", }; -u16 ClockSourceSelector[] = {0x8000, // selects source as ADAT at 44.1 kHz - 0x0000, // selects source as ADAT at 48 kHz - 0x8001, // selects source as S/PDIF at 44.1 kHz - 0x0001, // selects source as S/PDIF at 48 kHz - 0x8002, // selects source as local clock at 44.1 kHz - 0x0002 // selects source as local clock at 48 kHz - }; - -static snd_korg1212rc rc; - -MODULE_DEVICE_TABLE(pci, snd_korg1212_ids); +static u16 ClockSourceSelector[] = { + 0x8000, // selects source as ADAT at 44.1 kHz + 0x0000, // selects source as ADAT at 48 kHz + 0x8001, // selects source as S/PDIF at 44.1 kHz + 0x0001, // selects source as S/PDIF at 48 kHz + 0x8002, // selects source as local clock at 44.1 kHz + 0x0002 // selects source as local clock at 48 kHz +}; -typedef union swap_u32 { unsigned char c[4]; u32 i; } swap_u32; +union swap_u32 { unsigned char c[4]; u32 i; }; #ifdef SNDRV_BIG_ENDIAN static u32 LowerWordSwap(u32 swappee) @@ -499,7 +493,7 @@ static u32 LowerWordSwap(u32 swappee) static u32 UpperWordSwap(u32 swappee) #endif { - swap_u32 retVal, swapper; + union swap_u32 retVal, swapper; swapper.i = swappee; retVal.c[2] = swapper.c[3]; @@ -516,7 +510,7 @@ static u32 UpperWordSwap(u32 swappee) static u32 LowerWordSwap(u32 swappee) #endif { - swap_u32 retVal, swapper; + union swap_u32 retVal, swapper; swapper.i = swappee; retVal.c[2] = swapper.c[2]; @@ -527,45 +521,27 @@ static u32 LowerWordSwap(u32 swappee) return retVal.i; } -#if 0 /* not used */ - -static u32 EndianSwap(u32 swappee) -{ - swap_u32 retVal, swapper; - - swapper.i = swappee; - retVal.c[0] = swapper.c[3]; - retVal.c[1] = swapper.c[2]; - retVal.c[2] = swapper.c[1]; - retVal.c[3] = swapper.c[0]; - - return retVal.i; -} - -#endif /* not used */ - #define SetBitInWord(theWord,bitPosition) (*theWord) |= (0x0001 << bitPosition) #define SetBitInDWord(theWord,bitPosition) (*theWord) |= (0x00000001 << bitPosition) #define ClearBitInWord(theWord,bitPosition) (*theWord) &= ~(0x0001 << bitPosition) #define ClearBitInDWord(theWord,bitPosition) (*theWord) &= ~(0x00000001 << bitPosition) -static snd_korg1212rc snd_korg1212_Send1212Command(korg1212_t *korg1212, korg1212_dbcnst_t doorbellVal, - u32 mailBox0Val, u32 mailBox1Val, u32 mailBox2Val, u32 mailBox3Val) +static int snd_korg1212_Send1212Command(struct snd_korg1212 *korg1212, + enum korg1212_dbcnst doorbellVal, + u32 mailBox0Val, u32 mailBox1Val, + u32 mailBox2Val, u32 mailBox3Val) { u32 retryCount; u16 mailBox3Lo; - snd_korg1212rc rc = K1212_CMDRET_Success; + int rc = K1212_CMDRET_Success; if (!korg1212->outDoorbellPtr) { -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: CardUninitialized\n"); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: CardUninitialized\n"); return K1212_CMDRET_CardUninitialized; } -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n", doorbellVal, mailBox0Val, stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n", + doorbellVal, mailBox0Val, stateName[korg1212->cardState]); for (retryCount = 0; retryCount < MAX_COMMAND_RETRIES; retryCount++) { writel(mailBox3Val, korg1212->mailbox3Ptr); writel(mailBox2Val, korg1212->mailbox2Ptr); @@ -592,9 +568,7 @@ static snd_korg1212rc snd_korg1212_Send1212Command(korg1212_t *korg1212, korg121 mailBox3Lo = readl(korg1212->mailbox3Ptr); if (mailBox3Lo & COMMAND_ACK_MASK) { if ((mailBox3Lo & DOORBELL_VAL_MASK) == (doorbellVal & DOORBELL_VAL_MASK)) { -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- Success\n"); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- Success\n"); rc = K1212_CMDRET_Success; break; } @@ -603,9 +577,7 @@ static snd_korg1212rc snd_korg1212_Send1212Command(korg1212_t *korg1212, korg121 korg1212->cmdRetryCount += retryCount; if (retryCount >= MAX_COMMAND_RETRIES) { -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- NoAckFromCard\n"); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- NoAckFromCard\n"); rc = K1212_CMDRET_NoAckFromCard; } @@ -613,10 +585,10 @@ static snd_korg1212rc snd_korg1212_Send1212Command(korg1212_t *korg1212, korg121 } /* spinlock already held */ -static void snd_korg1212_SendStop(korg1212_t *korg1212) +static void snd_korg1212_SendStop(struct snd_korg1212 *korg1212) { if (! korg1212->stop_pending_cnt) { - writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand); + korg1212->sharedBufferPtr->cardCommand = 0xffffffff; /* program the timer */ korg1212->stop_pending_cnt = HZ; korg1212->timer.expires = jiffies + 1; @@ -624,28 +596,30 @@ static void snd_korg1212_SendStop(korg1212_t *korg1212) } } -static void snd_korg1212_SendStopAndWait(korg1212_t *korg1212) +static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212) { unsigned long flags; spin_lock_irqsave(&korg1212->lock, flags); + korg1212->dsp_stop_is_processed = 0; snd_korg1212_SendStop(korg1212); spin_unlock_irqrestore(&korg1212->lock, flags); - sleep_on_timeout(&korg1212->wait, (HZ * 3) / 2); + wait_event_timeout(korg1212->wait, korg1212->dsp_stop_is_processed, (HZ * 3) / 2); } /* timer callback for checking the ack of stop request */ static void snd_korg1212_timer_func(unsigned long data) { - korg1212_t *korg1212 = snd_magic_cast(korg1212_t, (void*)data, return); + struct snd_korg1212 *korg1212 = (struct snd_korg1212 *) data; + unsigned long flags; - spin_lock(&korg1212->lock); - if (readl(&korg1212->sharedBufferPtr->cardCommand) == 0) { + spin_lock_irqsave(&korg1212->lock, flags); + if (korg1212->sharedBufferPtr->cardCommand == 0) { /* ack'ed */ korg1212->stop_pending_cnt = 0; + korg1212->dsp_stop_is_processed = 1; wake_up(&korg1212->wait); -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: Stop ack'ed [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Stop ack'ed [%s]\n", + stateName[korg1212->cardState]); } else { if (--korg1212->stop_pending_cnt > 0) { /* reprogram timer */ @@ -653,19 +627,20 @@ static void snd_korg1212_timer_func(unsigned long data) add_timer(&korg1212->timer); } else { snd_printd("korg1212_timer_func timeout\n"); - writel(0, &korg1212->sharedBufferPtr->cardCommand); + korg1212->sharedBufferPtr->cardCommand = 0; + korg1212->dsp_stop_is_processed = 1; wake_up(&korg1212->wait); -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", + stateName[korg1212->cardState]); } } - spin_unlock(&korg1212->lock); + spin_unlock_irqrestore(&korg1212->lock, flags); } -static void snd_korg1212_TurnOnIdleMonitor(korg1212_t *korg1212) +static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212 *korg1212) { unsigned long flags; + int rc; udelay(INTERCOMMAND_DELAY); spin_lock_irqsave(&korg1212->lock, flags); @@ -673,9 +648,10 @@ static void snd_korg1212_TurnOnIdleMonitor(korg1212_t *korg1212) rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0); spin_unlock_irqrestore(&korg1212->lock, flags); + return rc; } -static void snd_korg1212_TurnOffIdleMonitor(korg1212_t *korg1212) +static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212 *korg1212) { if (korg1212->idleMonitorOn) { snd_korg1212_SendStopAndWait(korg1212); @@ -683,47 +659,44 @@ static void snd_korg1212_TurnOffIdleMonitor(korg1212_t *korg1212) } } -static inline void snd_korg1212_setCardState(korg1212_t * korg1212, CardState csState) +static inline void snd_korg1212_setCardState(struct snd_korg1212 * korg1212, enum CardState csState) { korg1212->cardState = csState; } -static int snd_korg1212_OpenCard(korg1212_t * korg1212) +static int snd_korg1212_OpenCard(struct snd_korg1212 * korg1212) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt); -#endif - down(&korg1212->open_mutex); + K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", + stateName[korg1212->cardState], korg1212->opencnt); + mutex_lock(&korg1212->open_mutex); if (korg1212->opencnt++ == 0) { snd_korg1212_TurnOffIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); } - up(&korg1212->open_mutex); + mutex_unlock(&korg1212->open_mutex); return 1; } -static int snd_korg1212_CloseCard(korg1212_t * korg1212) +static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n", + stateName[korg1212->cardState], korg1212->opencnt); - down(&korg1212->open_mutex); + mutex_lock(&korg1212->open_mutex); if (--(korg1212->opencnt)) { - up(&korg1212->open_mutex); + mutex_unlock(&korg1212->open_mutex); return 0; } if (korg1212->cardState == K1212_STATE_SETUP) { - rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, + int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_StopPlay, 0, 0, 0); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { - up(&korg1212->open_mutex); + mutex_unlock(&korg1212->open_mutex); return 0; } } else if (korg1212->cardState > K1212_STATE_SETUP) { @@ -735,16 +708,17 @@ static int snd_korg1212_CloseCard(korg1212_t * korg1212) snd_korg1212_setCardState(korg1212, K1212_STATE_READY); } - up(&korg1212->open_mutex); + mutex_unlock(&korg1212->open_mutex); return 0; } /* spinlock already held */ -static int snd_korg1212_SetupForPlay(korg1212_t * korg1212) +static int snd_korg1212_SetupForPlay(struct snd_korg1212 * korg1212) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->setcnt); -#endif + int rc; + + K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n", + stateName[korg1212->cardState], korg1212->setcnt); if (korg1212->setcnt++) return 0; @@ -752,10 +726,9 @@ static int snd_korg1212_SetupForPlay(korg1212_t * korg1212) snd_korg1212_setCardState(korg1212, K1212_STATE_SETUP); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_SetupPlay, 0, 0, 0); - -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { return 1; } @@ -763,22 +736,21 @@ static int snd_korg1212_SetupForPlay(korg1212_t * korg1212) } /* spinlock already held */ -static int snd_korg1212_TriggerPlay(korg1212_t * korg1212) +static int snd_korg1212_TriggerPlay(struct snd_korg1212 * korg1212) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt); -#endif + int rc; + + K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n", + stateName[korg1212->cardState], korg1212->playcnt); if (korg1212->playcnt++) return 0; snd_korg1212_setCardState(korg1212, K1212_STATE_PLAYING); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_TriggerPlay, 0, 0, 0, 0); - -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { return 1; } @@ -786,11 +758,10 @@ static int snd_korg1212_TriggerPlay(korg1212_t * korg1212) } /* spinlock already held */ -static int snd_korg1212_StopPlay(korg1212_t * korg1212) +static int snd_korg1212_StopPlay(struct snd_korg1212 * korg1212) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n", + stateName[korg1212->cardState], korg1212->playcnt); if (--(korg1212->playcnt)) return 0; @@ -804,48 +775,49 @@ static int snd_korg1212_StopPlay(korg1212_t * korg1212) return 0; } -static void snd_korg1212_EnableCardInterrupts(korg1212_t * korg1212) +static void snd_korg1212_EnableCardInterrupts(struct snd_korg1212 * korg1212) { - * korg1212->statusRegPtr = PCI_INT_ENABLE_BIT | - PCI_DOORBELL_INT_ENABLE_BIT | - LOCAL_INT_ENABLE_BIT | - LOCAL_DOORBELL_INT_ENABLE_BIT | - LOCAL_DMA1_INT_ENABLE_BIT; + writel(PCI_INT_ENABLE_BIT | + PCI_DOORBELL_INT_ENABLE_BIT | + LOCAL_INT_ENABLE_BIT | + LOCAL_DOORBELL_INT_ENABLE_BIT | + LOCAL_DMA1_INT_ENABLE_BIT, + korg1212->statusRegPtr); } #if 0 /* not used */ -static int snd_korg1212_SetMonitorMode(korg1212_t *korg1212, MonitorModeSelector mode) +static int snd_korg1212_SetMonitorMode(struct snd_korg1212 *korg1212, + enum MonitorModeSelector mode) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: SetMonitorMode [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: SetMonitorMode [%s]\n", + stateName[korg1212->cardState]); switch (mode) { - case K1212_MONMODE_Off: - if (korg1212->cardState != K1212_STATE_MONITOR) { - return 0; - } else { - snd_korg1212_SendStopAndWait(korg1212); - snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); - } - break; - - case K1212_MONMODE_On: - if (korg1212->cardState != K1212_STATE_OPEN) { - return 0; - } else { - snd_korg1212_setCardState(korg1212, K1212_STATE_MONITOR); - rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, - K1212_MODE_MonitorOn, 0, 0, 0); - if (rc != K1212_CMDRET_Success) { - return 0; - } - } - break; + case K1212_MONMODE_Off: + if (korg1212->cardState != K1212_STATE_MONITOR) + return 0; + else { + snd_korg1212_SendStopAndWait(korg1212); + snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); + } + break; + + case K1212_MONMODE_On: + if (korg1212->cardState != K1212_STATE_OPEN) + return 0; + else { + int rc; + snd_korg1212_setCardState(korg1212, K1212_STATE_MONITOR); + rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, + K1212_MODE_MonitorOn, 0, 0, 0); + if (rc != K1212_CMDRET_Success) + return 0; + } + break; - default: - return 0; + default: + return 0; } return 1; @@ -853,29 +825,44 @@ static int snd_korg1212_SetMonitorMode(korg1212_t *korg1212, MonitorModeSelector #endif /* not used */ -static int snd_korg1212_SetRate(korg1212_t *korg1212, int rate) +static inline int snd_korg1212_use_is_exclusive(struct snd_korg1212 *korg1212) { - static ClockSourceIndex s44[] = { K1212_CLKIDX_AdatAt44_1K, - K1212_CLKIDX_WordAt44_1K, - K1212_CLKIDX_LocalAt44_1K }; - static ClockSourceIndex s48[] = { - K1212_CLKIDX_AdatAt48K, - K1212_CLKIDX_WordAt48K, - K1212_CLKIDX_LocalAt48K }; - int parm; + if (korg1212->playback_pid != korg1212->capture_pid && + korg1212->playback_pid >= 0 && korg1212->capture_pid >= 0) + return 0; - switch(rate) { - case 44100: - parm = s44[korg1212->clkSource]; - break; + return 1; +} - case 48000: - parm = s48[korg1212->clkSource]; - break; +static int snd_korg1212_SetRate(struct snd_korg1212 *korg1212, int rate) +{ + static enum ClockSourceIndex s44[] = { + K1212_CLKIDX_AdatAt44_1K, + K1212_CLKIDX_WordAt44_1K, + K1212_CLKIDX_LocalAt44_1K + }; + static enum ClockSourceIndex s48[] = { + K1212_CLKIDX_AdatAt48K, + K1212_CLKIDX_WordAt48K, + K1212_CLKIDX_LocalAt48K + }; + int parm, rc; - default: - return -EINVAL; - } + if (!snd_korg1212_use_is_exclusive (korg1212)) + return -EBUSY; + + switch (rate) { + case 44100: + parm = s44[korg1212->clkSource]; + break; + + case 48000: + parm = s48[korg1212->clkSource]; + break; + + default: + return -EINVAL; + } korg1212->clkSrcRate = parm; korg1212->clkRate = rate; @@ -884,19 +871,18 @@ static int snd_korg1212_SetRate(korg1212_t *korg1212, int rate) rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, ClockSourceSelector[korg1212->clkSrcRate], 0, 0, 0); - -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); return 0; } -static int snd_korg1212_SetClockSource(korg1212_t *korg1212, int source) +static int snd_korg1212_SetClockSource(struct snd_korg1212 *korg1212, int source) { - if (source<0 || source >2) - return -EINVAL; + if (source < 0 || source > 2) + return -EINVAL; korg1212->clkSource = source; @@ -905,14 +891,14 @@ static int snd_korg1212_SetClockSource(korg1212_t *korg1212, int source) return 0; } -static void snd_korg1212_DisableCardInterrupts(korg1212_t *korg1212) +static void snd_korg1212_DisableCardInterrupts(struct snd_korg1212 *korg1212) { - * korg1212->statusRegPtr = 0; + writel(0, korg1212->statusRegPtr); } -static int snd_korg1212_WriteADCSensitivity(korg1212_t *korg1212) +static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212) { - SensBits sensVals; + struct SensBits sensVals; int bitPosition; int channel; int clkIs48K; @@ -922,9 +908,8 @@ static int snd_korg1212_WriteADCSensitivity(korg1212_t *korg1212) u16 count; unsigned long flags; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n", + stateName[korg1212->cardState]); // ---------------------------------------------------------------------------- // initialize things. The local init bit is always set when writing to the @@ -993,19 +978,17 @@ static int snd_korg1212_WriteADCSensitivity(korg1212_t *korg1212) udelay(LOADSHIFT_DELAY); for (bitPosition = 15; bitPosition >= 0; bitPosition--) { // for all the bits - if (channel == 0) { - if (sensVals.l.leftSensBits & (0x0001 << bitPosition)) { + if (channel == 0) { + if (sensVals.l.leftSensBits & (0x0001 << bitPosition)) SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high - } else { - ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low - } - } else { - if (sensVals.r.rightSensBits & (0x0001 << bitPosition)) { - SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high - } else { - ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low - } - } + else + ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low + } else { + if (sensVals.r.rightSensBits & (0x0001 << bitPosition)) + SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high + else + ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low + } ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); writew(controlValue, korg1212->sensRegPtr); // clock goes low @@ -1046,12 +1029,11 @@ static int snd_korg1212_WriteADCSensitivity(korg1212_t *korg1212) udelay(SENSCLKPULSE_WIDTH); if (monModeSet) { - rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, + int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); } spin_unlock_irqrestore(&korg1212->lock, flags); @@ -1059,23 +1041,22 @@ static int snd_korg1212_WriteADCSensitivity(korg1212_t *korg1212) return 1; } -static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212) +static void snd_korg1212_OnDSPDownloadComplete(struct snd_korg1212 *korg1212) { - int channel; + int channel, rc; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n", + stateName[korg1212->cardState]); // ---------------------------------------------------- // tell the card to boot // ---------------------------------------------------- rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_BootFromDSPPage4, 0, 0, 0, 0); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - mdelay(DSP_BOOT_DELAY_IN_MS); + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); + msleep(DSP_BOOT_DELAY_IN_MS); // -------------------------------------------------------------------------------- // Let the card know where all the buffers are. @@ -1089,9 +1070,9 @@ static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212) 0 ); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); udelay(INTERCOMMAND_DELAY); @@ -1103,10 +1084,9 @@ static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212) 0 ); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); // -------------------------------------------------------------------------------- // Initialize the routing and volume tables, then update the card's state. @@ -1125,16 +1105,16 @@ static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212) rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, ClockSourceSelector[korg1212->clkSrcRate], 0, 0, 0); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); - snd_korg1212_TurnOnIdleMonitor(korg1212); + rc = snd_korg1212_TurnOnIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_READY); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE); } @@ -1142,7 +1122,7 @@ static void snd_korg1212_OnDSPDownloadComplete(korg1212_t *korg1212) static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs) { u32 doorbellValue; - korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return IRQ_NONE); + struct snd_korg1212 *korg1212 = dev_id; if(irq != korg1212->irq) return IRQ_NONE; @@ -1163,21 +1143,26 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs switch (doorbellValue) { case K1212_DB_DSPDownloadDone: -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); -#endif - if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) + K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", + korg1212->irqcount, doorbellValue, + stateName[korg1212->cardState]); + if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) { + korg1212->dsp_is_loaded = 1; wake_up(&korg1212->wait); + } break; // ------------------------------------------------------------------------ // an error occurred - stop the card // ------------------------------------------------------------------------ - case K1212_ISRCODE_DMAERROR: -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); -#endif - writel(0, &korg1212->sharedBufferPtr->cardCommand); + case K1212_DB_DMAERROR: + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", + korg1212->irqcount, doorbellValue, + stateName[korg1212->cardState]); + snd_printk(KERN_ERR "korg1212: DMA Error\n"); + korg1212->errorcnt++; + korg1212->totalerrorcnt++; + korg1212->sharedBufferPtr->cardCommand = 0; snd_korg1212_setCardState(korg1212, K1212_STATE_ERRORSTOP); break; @@ -1185,18 +1170,17 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs // the card has stopped by our request. Clear the command word and signal // the semaphore in case someone is waiting for this. // ------------------------------------------------------------------------ - case K1212_ISRCODE_CARDSTOPPED: -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); -#endif - writel(0, &korg1212->sharedBufferPtr->cardCommand); + case K1212_DB_CARDSTOPPED: + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", + korg1212->irqcount, doorbellValue, + stateName[korg1212->cardState]); + korg1212->sharedBufferPtr->cardCommand = 0; break; default: -#if K1212_DEBUG_LEVEL > 3 - K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", korg1212->irqcount, doorbellValue, - korg1212->currentBuffer, stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", + korg1212->irqcount, doorbellValue, + korg1212->currentBuffer, stateName[korg1212->cardState]); if ((korg1212->cardState > K1212_STATE_SETUP) || korg1212->idleMonitorOn) { korg1212->currentBuffer++; @@ -1228,19 +1212,18 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs return IRQ_HANDLED; } -static int snd_korg1212_downloadDSPCode(korg1212_t *korg1212) +static int snd_korg1212_downloadDSPCode(struct snd_korg1212 *korg1212) { + int rc; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n", + stateName[korg1212->cardState]); // --------------------------------------------------------------- // verify the state of the card before proceeding. // --------------------------------------------------------------- - if (korg1212->cardState >= K1212_STATE_DSP_IN_PROCESS) { + if (korg1212->cardState >= K1212_STATE_DSP_IN_PROCESS) return 1; - } snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_IN_PROCESS); @@ -1249,12 +1232,13 @@ static int snd_korg1212_downloadDSPCode(korg1212_t *korg1212) rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_StartDSPDownload, UpperWordSwap(korg1212->dma_dsp.addr), 0, 0, 0); + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", + rc, stateName[korg1212->cardState]); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif - - if (! sleep_on_timeout(&korg1212->wait, HZ * 4)) + korg1212->dsp_is_loaded = 0; + wait_event_timeout(korg1212->wait, korg1212->dsp_is_loaded, HZ * CARD_BOOT_TIMEOUT); + if (! korg1212->dsp_is_loaded ) return -EBUSY; /* timeout */ snd_korg1212_OnDSPDownloadComplete(korg1212); @@ -1262,7 +1246,7 @@ static int snd_korg1212_downloadDSPCode(korg1212_t *korg1212) return 0; } -static snd_pcm_hardware_t snd_korg1212_playback_info = +static struct snd_pcm_hardware snd_korg1212_playback_info = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -1282,7 +1266,7 @@ static snd_pcm_hardware_t snd_korg1212_playback_info = .fifo_size = 0, }; -static snd_pcm_hardware_t snd_korg1212_capture_info = +static struct snd_pcm_hardware snd_korg1212_capture_info = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -1302,21 +1286,21 @@ static snd_pcm_hardware_t snd_korg1212_capture_info = .fifo_size = 0, }; -static int snd_korg1212_silence(korg1212_t *korg1212, int pos, int count, int offset, int size) +static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int count, int offset, int size) { - KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; + struct KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; int i; -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", + pos, offset, size, count); snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); for (i=0; i < count; i++) { #if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", dst, i); + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", + dst, i); return -EFAULT; } #endif @@ -1327,29 +1311,26 @@ static int snd_korg1212_silence(korg1212_t *korg1212, int pos, int count, int of return 0; } -static int snd_korg1212_copy_to(korg1212_t *korg1212, void *dst, int pos, int count, int offset, int size) +static int snd_korg1212_copy_to(struct snd_korg1212 *korg1212, void __user *dst, int pos, int count, int offset, int size) { - KorgAudioFrame * src = korg1212->recordDataBufsPtr[0].bufferData + pos; + struct KorgAudioFrame * src = korg1212->recordDataBufsPtr[0].bufferData + pos; int i, rc; -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", pos, offset, size); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", + pos, offset, size); snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); for (i=0; i < count; i++) { #if K1212_DEBUG_LEVEL > 0 if ( (void *) src < (void *) korg1212->recordDataBufsPtr || (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); return -EFAULT; } #endif - rc = copy_to_user((void*) dst + offset, src, size); + rc = copy_to_user(dst + offset, src, size); if (rc) { -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i); -#endif return -EFAULT; } src++; @@ -1359,14 +1340,13 @@ static int snd_korg1212_copy_to(korg1212_t *korg1212, void *dst, int pos, int co return 0; } -static int snd_korg1212_copy_from(korg1212_t *korg1212, void *src, int pos, int count, int offset, int size) +static int snd_korg1212_copy_from(struct snd_korg1212 *korg1212, void __user *src, int pos, int count, int offset, int size) { - KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; + struct KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; int i, rc; -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", + pos, offset, size, count); snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); @@ -1374,15 +1354,13 @@ static int snd_korg1212_copy_from(korg1212_t *korg1212, void *src, int pos, int #if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); return -EFAULT; } #endif rc = copy_from_user((void*) dst + offset, src, size); if (rc) { -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i); -#endif return -EFAULT; } dst++; @@ -1392,40 +1370,39 @@ static int snd_korg1212_copy_from(korg1212_t *korg1212, void *src, int pos, int return 0; } -static void snd_korg1212_free_pcm(snd_pcm_t *pcm) +static void snd_korg1212_free_pcm(struct snd_pcm *pcm) { - korg1212_t *korg1212 = (korg1212_t *) pcm->private_data; + struct snd_korg1212 *korg1212 = pcm->private_data; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n", + stateName[korg1212->cardState]); korg1212->pcm = NULL; } -static int snd_korg1212_playback_open(snd_pcm_substream_t *substream) +static int snd_korg1212_playback_open(struct snd_pcm_substream *substream) { unsigned long flags; - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n", + stateName[korg1212->cardState]); snd_pcm_set_sync(substream); // ??? snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_playback_info; - runtime->dma_area = (char *) korg1212->playDataBufsPtr; - runtime->dma_bytes = K1212_BUF_SIZE; + snd_pcm_set_runtime_buffer(substream, &korg1212->dma_play); spin_lock_irqsave(&korg1212->lock, flags); korg1212->playback_substream = substream; + korg1212->playback_pid = current->pid; korg1212->periodsize = K1212_PERIODS; korg1212->channels = K1212_CHANNELS; + korg1212->errorcnt = 0; spin_unlock_irqrestore(&korg1212->lock, flags); @@ -1434,49 +1411,49 @@ static int snd_korg1212_playback_open(snd_pcm_substream_t *substream) } -static int snd_korg1212_capture_open(snd_pcm_substream_t *substream) +static int snd_korg1212_capture_open(struct snd_pcm_substream *substream) { unsigned long flags; - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n", + stateName[korg1212->cardState]); - snd_pcm_set_sync(substream); // ??? + snd_pcm_set_sync(substream); snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_capture_info; - runtime->dma_area = (char *) korg1212->recordDataBufsPtr; - runtime->dma_bytes = K1212_BUF_SIZE; + snd_pcm_set_runtime_buffer(substream, &korg1212->dma_rec); spin_lock_irqsave(&korg1212->lock, flags); korg1212->capture_substream = substream; + korg1212->capture_pid = current->pid; korg1212->periodsize = K1212_PERIODS; korg1212->channels = K1212_CHANNELS; spin_unlock_irqrestore(&korg1212->lock, flags); - snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames); + snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, + kPlayBufferFrames, kPlayBufferFrames); return 0; } -static int snd_korg1212_playback_close(snd_pcm_substream_t *substream) +static int snd_korg1212_playback_close(struct snd_pcm_substream *substream) { unsigned long flags; - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", + stateName[korg1212->cardState]); snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2); spin_lock_irqsave(&korg1212->lock, flags); + korg1212->playback_pid = -1; korg1212->playback_substream = NULL; korg1212->periodsize = 0; @@ -1486,17 +1463,17 @@ static int snd_korg1212_playback_close(snd_pcm_substream_t *substream) return 0; } -static int snd_korg1212_capture_close(snd_pcm_substream_t *substream) +static int snd_korg1212_capture_close(struct snd_pcm_substream *substream) { unsigned long flags; - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", + stateName[korg1212->cardState]); spin_lock_irqsave(&korg1212->lock, flags); + korg1212->capture_pid = -1; korg1212->capture_substream = NULL; korg1212->periodsize = 0; @@ -1506,49 +1483,67 @@ static int snd_korg1212_capture_close(snd_pcm_substream_t *substream) return 0; } -static int snd_korg1212_ioctl(snd_pcm_substream_t *substream, +static int snd_korg1212_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd); if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) { - snd_pcm_channel_info_t *info = arg; + struct snd_pcm_channel_info *info = arg; info->offset = 0; info->first = info->channel * 16; info->step = 256; -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step); -#endif return 0; } return snd_pcm_lib_ioctl(substream, cmd, arg); } -static int snd_korg1212_hw_params(snd_pcm_substream_t *substream, - snd_pcm_hw_params_t *params) +static int snd_korg1212_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) { unsigned long flags; - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int err; + pid_t this_pid; + pid_t other_pid; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", + stateName[korg1212->cardState]); spin_lock_irqsave(&korg1212->lock, flags); + + if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { + this_pid = korg1212->playback_pid; + other_pid = korg1212->capture_pid; + } else { + this_pid = korg1212->capture_pid; + other_pid = korg1212->playback_pid; + } + + if ((other_pid > 0) && (this_pid != other_pid)) { + + /* The other stream is open, and not by the same + task as this one. Make sure that the parameters + that matter are the same. + */ + + if ((int)params_rate(params) != korg1212->clkRate) { + spin_unlock_irqrestore(&korg1212->lock, flags); + _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); + return -EBUSY; + } + + spin_unlock_irqrestore(&korg1212->lock, flags); + return 0; + } + if ((err = snd_korg1212_SetRate(korg1212, params_rate(params))) < 0) { spin_unlock_irqrestore(&korg1212->lock, flags); return err; } -/* - if (params_format(params) != SNDRV_PCM_FORMAT_S16_LE) { - spin_unlock_irqrestore(&korg1212->lock, flags); - return -EINVAL; - } -*/ + korg1212->channels = params_channels(params); korg1212->periodsize = K1212_PERIOD_BYTES; @@ -1557,26 +1552,24 @@ static int snd_korg1212_hw_params(snd_pcm_substream_t *substream, return 0; } -static int snd_korg1212_prepare(snd_pcm_substream_t *substream) +static int snd_korg1212_prepare(struct snd_pcm_substream *substream) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", + stateName[korg1212->cardState]); - spin_lock(&korg1212->lock); + spin_lock_irq(&korg1212->lock); /* FIXME: we should wait for ack! */ if (korg1212->stop_pending_cnt > 0) { -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]); -#endif - spin_unlock(&korg1212->lock); + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", + stateName[korg1212->cardState]); + spin_unlock_irq(&korg1212->lock); return -EAGAIN; /* - writel(0, &korg1212->sharedBufferPtr->cardCommand); + korg1212->sharedBufferPtr->cardCommand = 0; del_timer(&korg1212->timer); korg1212->stop_pending_cnt = 0; */ @@ -1586,29 +1579,26 @@ static int snd_korg1212_prepare(snd_pcm_substream_t *substream) korg1212->currentBuffer = 0; - spin_unlock(&korg1212->lock); + spin_unlock_irq(&korg1212->lock); return rc ? -EINVAL : 0; } -static int snd_korg1212_trigger(snd_pcm_substream_t *substream, +static int snd_korg1212_trigger(struct snd_pcm_substream *substream, int cmd) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", stateName[korg1212->cardState], cmd); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", + stateName[korg1212->cardState], cmd); spin_lock(&korg1212->lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* if (korg1212->running) { -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already running?\n"); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n"); break; } */ @@ -1619,9 +1609,7 @@ static int snd_korg1212_trigger(snd_pcm_substream_t *substream, case SNDRV_PCM_TRIGGER_STOP: /* if (!korg1212->running) { -#if K1212_DEBUG_LEVEL > 1 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n"); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n"); break; } */ @@ -1637,82 +1625,75 @@ static int snd_korg1212_trigger(snd_pcm_substream_t *substream, return rc ? -EINVAL : 0; } -static snd_pcm_uframes_t snd_korg1212_playback_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_korg1212_playback_pointer(struct snd_pcm_substream *substream) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", - stateName[korg1212->cardState], pos); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", + stateName[korg1212->cardState], pos); return pos; } -static snd_pcm_uframes_t snd_korg1212_capture_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_korg1212_capture_pointer(struct snd_pcm_substream *substream) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n", - stateName[korg1212->cardState], pos); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n", + stateName[korg1212->cardState], pos); return pos; } -static int snd_korg1212_playback_copy(snd_pcm_substream_t *substream, +static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, - void *src, + void __user *src, snd_pcm_uframes_t count) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", + stateName[korg1212->cardState], pos, count); return snd_korg1212_copy_from(korg1212, src, pos, count, 0, korg1212->channels * 2); } -static int snd_korg1212_playback_silence(snd_pcm_substream_t *substream, +static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, snd_pcm_uframes_t count) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", + stateName[korg1212->cardState]); return snd_korg1212_silence(korg1212, pos, count, 0, korg1212->channels * 2); } -static int snd_korg1212_capture_copy(snd_pcm_substream_t *substream, +static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ snd_pcm_uframes_t pos, - void *dst, + void __user *dst, snd_pcm_uframes_t count) { - korg1212_t *korg1212 = _snd_pcm_substream_chip(substream); + struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); -#if K1212_DEBUG_LEVEL > 2 - K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count); -#endif + K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", + stateName[korg1212->cardState], pos, count); return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2); } -static snd_pcm_ops_t snd_korg1212_playback_ops = { +static struct snd_pcm_ops snd_korg1212_playback_ops = { .open = snd_korg1212_playback_open, .close = snd_korg1212_playback_close, .ioctl = snd_korg1212_ioctl, @@ -1724,7 +1705,7 @@ static snd_pcm_ops_t snd_korg1212_playback_ops = { .silence = snd_korg1212_playback_silence, }; -static snd_pcm_ops_t snd_korg1212_capture_ops = { +static struct snd_pcm_ops snd_korg1212_capture_ops = { .open = snd_korg1212_capture_open, .close = snd_korg1212_capture_close, .ioctl = snd_korg1212_ioctl, @@ -1739,39 +1720,40 @@ static snd_pcm_ops_t snd_korg1212_capture_ops = { * Control Interface */ -static int snd_korg1212_control_phase_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_korg1212_control_phase_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; return 0; } -static int snd_korg1212_control_phase_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i = kcontrol->private_value; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); u->value.integer.value[0] = korg1212->volumePhase[i]; if (i >= 8) u->value.integer.value[1] = korg1212->volumePhase[i+1]; - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return 0; } -static int snd_korg1212_control_phase_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; int i, val; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; @@ -1797,12 +1779,13 @@ static int snd_korg1212_control_phase_put(snd_kcontrol_t *kcontrol, snd_ctl_elem } } - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return change; } -static int snd_korg1212_control_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_korg1212_control_volume_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; @@ -1811,13 +1794,13 @@ static int snd_korg1212_control_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_el return 0; } -static int snd_korg1212_control_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]); @@ -1825,20 +1808,20 @@ static int snd_korg1212_control_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_ele if (i >= 8) u->value.integer.value[1] = abs(korg1212->sharedBufferPtr->volumeData[i+1]); - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return 0; } -static int snd_korg1212_control_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; int i; int val; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; @@ -1858,12 +1841,13 @@ static int snd_korg1212_control_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_ele } } - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return change; } -static int snd_korg1212_control_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_korg1212_control_route_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; @@ -1875,13 +1859,13 @@ static int snd_korg1212_control_route_info(snd_kcontrol_t *kcontrol, snd_ctl_ele return 0; } -static int snd_korg1212_control_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; u->value.enumerated.item[0] = korg1212->sharedBufferPtr->routeData[i]; @@ -1889,18 +1873,18 @@ static int snd_korg1212_control_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem if (i >= 8) u->value.enumerated.item[1] = korg1212->sharedBufferPtr->routeData[i+1]; - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return 0; } -static int snd_korg1212_control_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0, i; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; @@ -1916,12 +1900,13 @@ static int snd_korg1212_control_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem } } - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return change; } -static int snd_korg1212_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_korg1212_control_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; @@ -1930,28 +1915,28 @@ static int snd_korg1212_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info return 0; } -static int snd_korg1212_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); u->value.integer.value[0] = korg1212->leftADCInSens; u->value.integer.value[1] = korg1212->rightADCInSens; - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return 0; } -static int snd_korg1212_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u) +static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *u) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); if (u->value.integer.value[0] != korg1212->leftADCInSens) { korg1212->leftADCInSens = u->value.integer.value[0]; @@ -1962,7 +1947,7 @@ static int snd_korg1212_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value change = 1; } - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); if (change) snd_korg1212_WriteADCSensitivity(korg1212); @@ -1970,7 +1955,8 @@ static int snd_korg1212_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value return change; } -static int snd_korg1212_control_sync_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_korg1212_control_sync_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; @@ -1982,31 +1968,31 @@ static int snd_korg1212_control_sync_info(snd_kcontrol_t *kcontrol, snd_ctl_elem return 0; } -static int snd_korg1212_control_sync_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); ucontrol->value.enumerated.item[0] = korg1212->clkSource; - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return 0; } -static int snd_korg1212_control_sync_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_korg1212_control_sync_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = ucontrol->value.enumerated.item[0] % 3; - spin_lock_irqsave(&korg1212->lock, flags); + spin_lock_irq(&korg1212->lock); change = val != korg1212->clkSource; snd_korg1212_SetClockSource(korg1212, val); - spin_unlock_irqrestore(&korg1212->lock, flags); + spin_unlock_irq(&korg1212->lock); return change; } @@ -2031,7 +2017,7 @@ static int snd_korg1212_control_sync_put(snd_kcontrol_t * kcontrol, snd_ctl_elem }, \ { \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ - .iface = SNDRV_CTL_ELEM_IFACE_PCM, \ + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = c_name " Monitor Phase Invert", \ .info = snd_korg1212_control_phase_info, \ .get = snd_korg1212_control_phase_get, \ @@ -2039,14 +2025,14 @@ static int snd_korg1212_control_sync_put(snd_kcontrol_t * kcontrol, snd_ctl_elem .private_value = ord, \ } -static snd_kcontrol_new_t snd_korg1212_controls[] = { +static struct snd_kcontrol_new snd_korg1212_controls[] = { MON_MIXER(8, "Analog"), MON_MIXER(10, "SPDIF"), MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"), MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"), { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, - .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Sync Source", .info = snd_korg1212_control_sync_info, .get = snd_korg1212_control_sync_get, @@ -2062,16 +2048,15 @@ static snd_kcontrol_new_t snd_korg1212_controls[] = { } }; -#define K1212_CONTROL_ELEMENTS (sizeof(snd_korg1212_controls) / sizeof(snd_korg1212_controls[0])) - /* * proc interface */ -static void snd_korg1212_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer) +static void snd_korg1212_proc_read(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { int n; - korg1212_t *korg1212 = (korg1212_t *)entry->private_data; + struct snd_korg1212 *korg1212 = entry->private_data; snd_iprintf(buffer, korg1212->card->longname); snd_iprintf(buffer, " (index #%d)\n", korg1212->card->number + 1); @@ -2092,56 +2077,41 @@ static void snd_korg1212_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *b snd_iprintf(buffer, "Idle mon. State: %d\n", korg1212->idleMonitorOn); snd_iprintf(buffer, "Cmd retry count: %d\n", korg1212->cmdRetryCount); snd_iprintf(buffer, " Irq count: %ld\n", korg1212->irqcount); + snd_iprintf(buffer, " Error count: %ld\n", korg1212->totalerrorcnt); } -static void __devinit snd_korg1212_proc_init(korg1212_t *korg1212) +static void __devinit snd_korg1212_proc_init(struct snd_korg1212 *korg1212) { - snd_info_entry_t *entry; + struct snd_info_entry *entry; if (! snd_card_proc_new(korg1212->card, "korg1212", &entry)) snd_info_set_text_ops(entry, korg1212, 1024, snd_korg1212_proc_read); } static int -snd_korg1212_free(korg1212_t *korg1212) +snd_korg1212_free(struct snd_korg1212 *korg1212) { snd_korg1212_TurnOffIdleMonitor(korg1212); if (korg1212->irq >= 0) { synchronize_irq(korg1212->irq); snd_korg1212_DisableCardInterrupts(korg1212); - free_irq(korg1212->irq, (void *)korg1212); + free_irq(korg1212->irq, korg1212); korg1212->irq = -1; } - if (korg1212->iobase != 0) { - iounmap((void *)korg1212->iobase); - korg1212->iobase = 0; + if (korg1212->iobase != NULL) { + iounmap(korg1212->iobase); + korg1212->iobase = NULL; } - if (korg1212->res_iomem != NULL) { - release_resource(korg1212->res_iomem); - kfree_nocheck(korg1212->res_iomem); - korg1212->res_iomem = NULL; - } - - if (korg1212->res_ioport != NULL) { - release_resource(korg1212->res_ioport); - kfree_nocheck(korg1212->res_ioport); - korg1212->res_ioport = NULL; - } - - if (korg1212->res_iomem2 != NULL) { - release_resource(korg1212->res_iomem2); - kfree_nocheck(korg1212->res_iomem2); - korg1212->res_iomem2 = NULL; - } + pci_release_regions(korg1212->pci); // ---------------------------------------------------- // free up memory resources used for the DSP download. // ---------------------------------------------------- if (korg1212->dma_dsp.area) { - snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_dsp); + snd_dma_free_pages(&korg1212->dma_dsp); korg1212->dma_dsp.area = NULL; } @@ -2151,12 +2121,12 @@ snd_korg1212_free(korg1212_t *korg1212) // free up memory resources used for the Play/Rec Buffers // ------------------------------------------------------ if (korg1212->dma_play.area) { - snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_play); + snd_dma_free_pages(&korg1212->dma_play); korg1212->dma_play.area = NULL; } if (korg1212->dma_rec.area) { - snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_rec); + snd_dma_free_pages(&korg1212->dma_rec); korg1212->dma_rec.area = NULL; } @@ -2166,33 +2136,32 @@ snd_korg1212_free(korg1212_t *korg1212) // free up memory resources used for the Shared Buffers // ---------------------------------------------------- if (korg1212->dma_shared.area) { - snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_shared); + snd_dma_free_pages(&korg1212->dma_shared); korg1212->dma_shared.area = NULL; } - snd_magic_kfree(korg1212); + pci_disable_device(korg1212->pci); + kfree(korg1212); return 0; } -static int snd_korg1212_dev_free(snd_device_t *device) +static int snd_korg1212_dev_free(struct snd_device *device) { - korg1212_t *korg1212 = snd_magic_cast(korg1212_t, device->device_data, return -ENXIO); -#if K1212_DEBUG_LEVEL > 0 + struct snd_korg1212 *korg1212 = device->device_data; K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n"); -#endif return snd_korg1212_free(korg1212); } -static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, - korg1212_t ** rchip) +static int __devinit snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, + struct snd_korg1212 ** rchip) { - int err; + int err, rc; unsigned int i; unsigned ioport_size, iomem_size, iomem2_size; - korg1212_t * korg1212; + struct snd_korg1212 * korg1212; - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_korg1212_dev_free, }; @@ -2200,16 +2169,18 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, if ((err = pci_enable_device(pci)) < 0) return err; - korg1212 = snd_magic_kcalloc(korg1212_t, 0, GFP_KERNEL); - if (korg1212 == NULL) + korg1212 = kzalloc(sizeof(*korg1212), GFP_KERNEL); + if (korg1212 == NULL) { + pci_disable_device(pci); return -ENOMEM; + } korg1212->card = card; korg1212->pci = pci; init_waitqueue_head(&korg1212->wait); spin_lock_init(&korg1212->lock); - init_MUTEX(&korg1212->open_mutex); + mutex_init(&korg1212->open_mutex); init_timer(&korg1212->timer); korg1212->timer.function = snd_korg1212_timer_func; korg1212->timer.data = (unsigned long)korg1212; @@ -2222,6 +2193,9 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, korg1212->opencnt = 0; korg1212->playcnt = 0; korg1212->setcnt = 0; + korg1212->totalerrorcnt = 0; + korg1212->playback_pid = -1; + korg1212->capture_pid = -1; snd_korg1212_setCardState(korg1212, K1212_STATE_UNINITIALIZED); korg1212->idleMonitorOn = 0; korg1212->clkSrcRate = K1212_CLKIDX_LocalAt44_1K; @@ -2231,6 +2205,12 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, for (i=0; ivolumePhase[i] = 0; + if ((err = pci_request_regions(pci, "korg1212")) < 0) { + kfree(korg1212); + pci_disable_device(pci); + return err; + } + korg1212->iomem = pci_resource_start(korg1212->pci, 0); korg1212->ioport = pci_resource_start(korg1212->pci, 1); korg1212->iomem2 = pci_resource_start(korg1212->pci, 2); @@ -2239,7 +2219,6 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, ioport_size = pci_resource_len(korg1212->pci, 1); iomem2_size = pci_resource_len(korg1212->pci, 2); -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n" " iomem = 0x%lx (%d)\n" " ioport = 0x%lx (%d)\n" @@ -2249,41 +2228,21 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, korg1212->ioport, ioport_size, korg1212->iomem2, iomem2_size, stateName[korg1212->cardState]); -#endif - korg1212->res_iomem = request_mem_region(korg1212->iomem, iomem_size, "korg1212"); - if (korg1212->res_iomem == NULL) { - snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n", - korg1212->iomem, korg1212->iomem + iomem_size - 1); - return -EBUSY; - } - - korg1212->res_ioport = request_region(korg1212->ioport, ioport_size, "korg1212"); - if (korg1212->res_ioport == NULL) { - snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n", - korg1212->ioport, korg1212->ioport + ioport_size - 1); - return -EBUSY; - } - - korg1212->res_iomem2 = request_mem_region(korg1212->iomem2, iomem2_size, "korg1212"); - if (korg1212->res_iomem2 == NULL) { - snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n", - korg1212->iomem2, korg1212->iomem2 + iomem2_size - 1); - return -EBUSY; - } - - if ((korg1212->iobase = (unsigned long) ioremap(korg1212->iomem, iomem_size)) == 0) { - snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", korg1212->iobase, - korg1212->iobase + iomem_size - 1); + if ((korg1212->iobase = ioremap(korg1212->iomem, iomem_size)) == NULL) { + snd_printk(KERN_ERR "korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212->iomem, + korg1212->iomem + iomem_size - 1); + snd_korg1212_free(korg1212); return -EBUSY; } err = request_irq(pci->irq, snd_korg1212_interrupt, SA_INTERRUPT|SA_SHIRQ, - "korg1212", (void *) korg1212); + "korg1212", korg1212); if (err) { - snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); + snd_printk(KERN_ERR "korg1212: unable to grab IRQ %d\n", pci->irq); + snd_korg1212_free(korg1212); return -EBUSY; } @@ -2291,18 +2250,17 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, pci_set_master(korg1212->pci); - korg1212->statusRegPtr = (u32 *) (korg1212->iobase + STATUS_REG_OFFSET); - korg1212->outDoorbellPtr = (u32 *) (korg1212->iobase + OUT_DOORBELL_OFFSET); - korg1212->inDoorbellPtr = (u32 *) (korg1212->iobase + IN_DOORBELL_OFFSET); - korg1212->mailbox0Ptr = (u32 *) (korg1212->iobase + MAILBOX0_OFFSET); - korg1212->mailbox1Ptr = (u32 *) (korg1212->iobase + MAILBOX1_OFFSET); - korg1212->mailbox2Ptr = (u32 *) (korg1212->iobase + MAILBOX2_OFFSET); - korg1212->mailbox3Ptr = (u32 *) (korg1212->iobase + MAILBOX3_OFFSET); - korg1212->controlRegPtr = (u32 *) (korg1212->iobase + PCI_CONTROL_OFFSET); - korg1212->sensRegPtr = (u16 *) (korg1212->iobase + SENS_CONTROL_OFFSET); - korg1212->idRegPtr = (u32 *) (korg1212->iobase + DEV_VEND_ID_OFFSET); + korg1212->statusRegPtr = (u32 __iomem *) (korg1212->iobase + STATUS_REG_OFFSET); + korg1212->outDoorbellPtr = (u32 __iomem *) (korg1212->iobase + OUT_DOORBELL_OFFSET); + korg1212->inDoorbellPtr = (u32 __iomem *) (korg1212->iobase + IN_DOORBELL_OFFSET); + korg1212->mailbox0Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX0_OFFSET); + korg1212->mailbox1Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX1_OFFSET); + korg1212->mailbox2Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX2_OFFSET); + korg1212->mailbox3Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX3_OFFSET); + korg1212->controlRegPtr = (u32 __iomem *) (korg1212->iobase + PCI_CONTROL_OFFSET); + korg1212->sensRegPtr = (u16 __iomem *) (korg1212->iobase + SENS_CONTROL_OFFSET); + korg1212->idRegPtr = (u32 __iomem *) (korg1212->iobase + DEV_VEND_ID_OFFSET); -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n" " Status register = 0x%p\n" " OutDoorbell = 0x%p\n" @@ -2326,100 +2284,99 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, korg1212->sensRegPtr, korg1212->idRegPtr, stateName[korg1212->cardState]); -#endif - - memset(&korg1212->dma_dev, 0, sizeof(korg1212->dma_dev)); - korg1212->dma_dev.type = SNDRV_DMA_TYPE_DEV; - korg1212->dma_dev.dev = snd_dma_pci_data(korg1212->pci); - if (snd_dma_alloc_pages(&korg1212->dma_dev, sizeof(KorgSharedBuffer), &korg1212->dma_shared) < 0) { - snd_printk(KERN_ERR "can not allocate shared buffer memory (%Zd bytes)\n", sizeof(KorgSharedBuffer)); + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), + sizeof(struct KorgSharedBuffer), &korg1212->dma_shared) < 0) { + snd_printk(KERN_ERR "korg1212: can not allocate shared buffer memory (%Zd bytes)\n", sizeof(struct KorgSharedBuffer)); + snd_korg1212_free(korg1212); return -ENOMEM; } - korg1212->sharedBufferPtr = (KorgSharedBuffer *)korg1212->dma_shared.area; + korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared.area; korg1212->sharedBufferPhy = korg1212->dma_shared.addr; -#if K1212_DEBUG_LEVEL > 0 - K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212->sharedBufferPtr, korg1212->sharedBufferPhy, sizeof(KorgSharedBuffer)); -#endif + K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212->sharedBufferPtr, korg1212->sharedBufferPhy, sizeof(struct KorgSharedBuffer)); #ifndef K1212_LARGEALLOC - korg1212->DataBufsSize = sizeof(KorgAudioBuffer) * kNumBuffers; + korg1212->DataBufsSize = sizeof(struct KorgAudioBuffer) * kNumBuffers; - if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->DataBufsSize, &korg1212->dma_play) < 0) { - snd_printk(KERN_ERR "can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize); + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), + korg1212->DataBufsSize, &korg1212->dma_play) < 0) { + snd_printk(KERN_ERR "korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize); + snd_korg1212_free(korg1212); return -ENOMEM; } - korg1212->playDataBufsPtr = (KorgAudioBuffer *)korg1212->dma_play.area; + korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play.area; korg1212->PlayDataPhy = korg1212->dma_play.addr; -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n", korg1212->playDataBufsPtr, korg1212->PlayDataPhy, korg1212->DataBufsSize); -#endif - if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->DataBufsSize, &korg1212->dma_rec) < 0) { - snd_printk(KERN_ERR "can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize); + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), + korg1212->DataBufsSize, &korg1212->dma_rec) < 0) { + snd_printk(KERN_ERR "korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize); + snd_korg1212_free(korg1212); return -ENOMEM; } - korg1212->recordDataBufsPtr = (KorgAudioBuffer *)korg1212->dma_rec.area; + korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec.area; korg1212->RecDataPhy = korg1212->dma_rec.addr; -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n", - korg1212->recordDataBufsPtr, korg1212->RecDataBufsPhy, korg1212->DataBufsSize); -#endif + korg1212->recordDataBufsPtr, korg1212->RecDataPhy, korg1212->DataBufsSize); #else // K1212_LARGEALLOC korg1212->recordDataBufsPtr = korg1212->sharedBufferPtr->recordDataBufs; korg1212->playDataBufsPtr = korg1212->sharedBufferPtr->playDataBufs; - korg1212->PlayDataPhy = (u32) &((KorgSharedBuffer *) korg1212->sharedBufferPhy)->playDataBufs; - korg1212->RecDataPhy = (u32) &((KorgSharedBuffer *) korg1212->sharedBufferPhy)->recordDataBufs; + korg1212->PlayDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->playDataBufs; + korg1212->RecDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->recordDataBufs; #endif // K1212_LARGEALLOC korg1212->dspCodeSize = sizeof (dspCode); korg1212->VolumeTablePhy = korg1212->sharedBufferPhy + - offsetof(KorgSharedBuffer, volumeData); + offsetof(struct KorgSharedBuffer, volumeData); korg1212->RoutingTablePhy = korg1212->sharedBufferPhy + - offsetof(KorgSharedBuffer, routeData); + offsetof(struct KorgSharedBuffer, routeData); korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy + - offsetof(KorgSharedBuffer, AdatTimeCode); + offsetof(struct KorgSharedBuffer, AdatTimeCode); - if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->dspCodeSize, &korg1212->dma_dsp) < 0) { - snd_printk(KERN_ERR "can not allocate dsp code memory (%d bytes)\n", korg1212->dspCodeSize); + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), + korg1212->dspCodeSize, &korg1212->dma_dsp) < 0) { + snd_printk(KERN_ERR "korg1212: can not allocate dsp code memory (%d bytes)\n", korg1212->dspCodeSize); + snd_korg1212_free(korg1212); return -ENOMEM; } -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n", korg1212->dma_dsp.area, korg1212->dma_dsp.addr, korg1212->dspCodeSize, stateName[korg1212->cardState]); -#endif rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_RebootCard, 0, 0, 0, 0); -#if K1212_DEBUG_LEVEL > 0 - if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); -#endif + if (rc) + K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); + if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops)) < 0) { + snd_korg1212_free(korg1212); + return err; + } + snd_korg1212_EnableCardInterrupts(korg1212); mdelay(CARD_BOOT_DELAY_IN_MS); - if (snd_korg1212_downloadDSPCode(korg1212)) + if (snd_korg1212_downloadDSPCode(korg1212)) return -EBUSY; - printk(KERN_INFO "dspMemPhy = %08x U[%08x]\n" - "PlayDataPhy = %08x L[%08x]\n" - "RecDataPhy = %08x L[%08x]\n" - "VolumeTablePhy = %08x L[%08x]\n" - "RoutingTablePhy = %08x L[%08x]\n" + K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], " + "PlayDataPhy = %08x L[%08x]\n" + "korg1212: RecDataPhy = %08x L[%08x], " + "VolumeTablePhy = %08x L[%08x]\n" + "korg1212: RoutingTablePhy = %08x L[%08x], " "AdatTimeCodePhy = %08x L[%08x]\n", - korg1212->dma_dsp.addr, UpperWordSwap(korg1212->dma_dsp.addr), + (int)korg1212->dma_dsp.addr, UpperWordSwap(korg1212->dma_dsp.addr), korg1212->PlayDataPhy, LowerWordSwap(korg1212->PlayDataPhy), korg1212->RecDataPhy, LowerWordSwap(korg1212->RecDataPhy), korg1212->VolumeTablePhy, LowerWordSwap(korg1212->VolumeTablePhy), @@ -2439,10 +2396,7 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, korg1212->pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; - //snd_pcm_lib_preallocate_pages_for_all(korg1212->pcm, - // K1212_MAX_BUF_SIZE, K1212_MAX_BUF_SIZE, GFP_KERNEL); - - for (i = 0; i < K1212_CONTROL_ELEMENTS; i++) { + for (i = 0; i < ARRAY_SIZE(snd_korg1212_controls); i++) { err = snd_ctl_add(korg1212->card, snd_ctl_new1(&snd_korg1212_controls[i], korg1212)); if (err < 0) return err; @@ -2450,11 +2404,6 @@ static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci, snd_korg1212_proc_init(korg1212); - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops)) < 0) { - snd_korg1212_free(korg1212); - return err; - } - snd_card_set_dev(card, &pci->dev); * rchip = korg1212; @@ -2471,8 +2420,8 @@ snd_korg1212_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; - korg1212_t *korg1212; - snd_card_t *card; + struct snd_korg1212 *korg1212; + struct snd_card *card; int err; if (dev >= SNDRV_CARDS) { @@ -2496,23 +2445,20 @@ snd_korg1212_probe(struct pci_dev *pci, sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, korg1212->iomem, korg1212->irq); -#if K1212_DEBUG_LEVEL > 0 K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname); -#endif if ((err = snd_card_register(card)) < 0) { snd_card_free(card); return err; } - pci_set_drvdata(pci, korg1212); + pci_set_drvdata(pci, card); dev++; return 0; } static void __devexit snd_korg1212_remove(struct pci_dev *pci) { - korg1212_t *korg1212 = pci_get_drvdata(pci); - snd_card_free(korg1212->card); + snd_card_free(pci_get_drvdata(pci)); pci_set_drvdata(pci, NULL); } @@ -2525,15 +2471,7 @@ static struct pci_driver driver = { static int __init alsa_card_korg1212_init(void) { - int err; - - if ((err = pci_module_init(&driver)) < 0) { -#ifdef MODULE - printk(KERN_ERR "No Korg 1212IO cards found\n"); -#endif - return err; - } - return 0; + return pci_register_driver(&driver); } static void __exit alsa_card_korg1212_exit(void) @@ -2543,25 +2481,3 @@ static void __exit alsa_card_korg1212_exit(void) module_init(alsa_card_korg1212_init) module_exit(alsa_card_korg1212_exit) - -#ifndef MODULE - -/* format is: snd-korg1212=enable,index,id */ - -static int __init alsa_card_korg1212_setup(char *str) -{ - static unsigned __initdata nr_dev = 0; - - if (nr_dev >= SNDRV_CARDS) - return 0; - (void)(get_option(&str,&enable[nr_dev]) == 2 && - get_option(&str,&index[nr_dev]) == 2 && - get_id(&str,&id[nr_dev]) == 2); - nr_dev++; - return 1; -} - -__setup("snd-korg1212=", alsa_card_korg1212_setup); - -#endif /* ifndef MODULE */ -