2 * Driver for the Korg 1212 IO PCI card
4 * Copyright (c) 2001 Haroldo Gamal <gamal@alternex.com.br>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/delay.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/pci.h>
27 #include <linux/slab.h>
28 #include <linux/wait.h>
29 #include <linux/moduleparam.h>
30 #include <linux/mutex.h>
32 #include <sound/core.h>
33 #include <sound/info.h>
34 #include <sound/control.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/initval.h>
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
44 #define K1212_DEBUG_LEVEL 0
45 #if K1212_DEBUG_LEVEL > 0
46 #define K1212_DEBUG_PRINTK(fmt,args...) printk(KERN_DEBUG fmt,##args)
48 #define K1212_DEBUG_PRINTK(fmt,...)
50 #if K1212_DEBUG_LEVEL > 1
51 #define K1212_DEBUG_PRINTK_VERBOSE(fmt,args...) printk(KERN_DEBUG fmt,##args)
53 #define K1212_DEBUG_PRINTK_VERBOSE(fmt,...)
56 // ----------------------------------------------------------------------------
57 // Record/Play Buffer Allocation Method. If K1212_LARGEALLOC is defined all
58 // buffers are alocated as a large piece inside KorgSharedBuffer.
59 // ----------------------------------------------------------------------------
60 //#define K1212_LARGEALLOC 1
62 // ----------------------------------------------------------------------------
63 // Valid states of the Korg 1212 I/O card.
64 // ----------------------------------------------------------------------------
66 K1212_STATE_NONEXISTENT
, // there is no card here
67 K1212_STATE_UNINITIALIZED
, // the card is awaiting DSP download
68 K1212_STATE_DSP_IN_PROCESS
, // the card is currently downloading its DSP code
69 K1212_STATE_DSP_COMPLETE
, // the card has finished the DSP download
70 K1212_STATE_READY
, // the card can be opened by an application. Any application
71 // requests prior to this state should fail. Only an open
72 // request can be made at this state.
73 K1212_STATE_OPEN
, // an application has opened the card
74 K1212_STATE_SETUP
, // the card has been setup for play
75 K1212_STATE_PLAYING
, // the card is playing
76 K1212_STATE_MONITOR
, // the card is in the monitor mode
77 K1212_STATE_CALIBRATING
, // the card is currently calibrating
78 K1212_STATE_ERRORSTOP
, // the card has stopped itself because of an error and we
79 // are in the process of cleaning things up.
80 K1212_STATE_MAX_STATE
// state values of this and beyond are invalid
83 // ----------------------------------------------------------------------------
84 // The following enumeration defines the constants written to the card's
85 // host-to-card doorbell to initiate a command.
86 // ----------------------------------------------------------------------------
87 enum korg1212_dbcnst
{
88 K1212_DB_RequestForData
= 0, // sent by the card to request a buffer fill.
89 K1212_DB_TriggerPlay
= 1, // starts playback/record on the card.
90 K1212_DB_SelectPlayMode
= 2, // select monitor, playback setup, or stop.
91 K1212_DB_ConfigureBufferMemory
= 3, // tells card where the host audio buffers are.
92 K1212_DB_RequestAdatTimecode
= 4, // asks the card for the latest ADAT timecode value.
93 K1212_DB_SetClockSourceRate
= 5, // sets the clock source and rate for the card.
94 K1212_DB_ConfigureMiscMemory
= 6, // tells card where other buffers are.
95 K1212_DB_TriggerFromAdat
= 7, // tells card to trigger from Adat at a specific
97 K1212_DB_DMAERROR
= 0x80, // DMA Error - the PCI bus is congestioned.
98 K1212_DB_CARDSTOPPED
= 0x81, // Card has stopped by user request.
99 K1212_DB_RebootCard
= 0xA0, // instructs the card to reboot.
100 K1212_DB_BootFromDSPPage4
= 0xA4, // instructs the card to boot from the DSP microcode
101 // on page 4 (local page to card).
102 K1212_DB_DSPDownloadDone
= 0xAE, // sent by the card to indicate the download has
104 K1212_DB_StartDSPDownload
= 0xAF // tells the card to download its DSP firmware.
108 // ----------------------------------------------------------------------------
109 // The following enumeration defines return codes
110 // to the Korg 1212 I/O driver.
111 // ----------------------------------------------------------------------------
112 enum snd_korg1212rc
{
113 K1212_CMDRET_Success
= 0, // command was successfully placed
114 K1212_CMDRET_DIOCFailure
, // the DeviceIoControl call failed
115 K1212_CMDRET_PMFailure
, // the protected mode call failed
116 K1212_CMDRET_FailUnspecified
, // unspecified failure
117 K1212_CMDRET_FailBadState
, // the specified command can not be given in
118 // the card's current state. (or the wave device's
120 K1212_CMDRET_CardUninitialized
, // the card is uninitialized and cannot be used
121 K1212_CMDRET_BadIndex
, // an out of range card index was specified
122 K1212_CMDRET_BadHandle
, // an invalid card handle was specified
123 K1212_CMDRET_NoFillRoutine
, // a play request has been made before a fill routine set
124 K1212_CMDRET_FillRoutineInUse
, // can't set a new fill routine while one is in use
125 K1212_CMDRET_NoAckFromCard
, // the card never acknowledged a command
126 K1212_CMDRET_BadParams
, // bad parameters were provided by the caller
128 K1212_CMDRET_BadDevice
, // the specified wave device was out of range
129 K1212_CMDRET_BadFormat
// the specified wave format is unsupported
132 // ----------------------------------------------------------------------------
133 // The following enumeration defines the constants used to select the play
134 // mode for the card in the SelectPlayMode command.
135 // ----------------------------------------------------------------------------
136 enum PlayModeSelector
{
137 K1212_MODE_SetupPlay
= 0x00000001, // provides card with pre-play information
138 K1212_MODE_MonitorOn
= 0x00000002, // tells card to turn on monitor mode
139 K1212_MODE_MonitorOff
= 0x00000004, // tells card to turn off monitor mode
140 K1212_MODE_StopPlay
= 0x00000008 // stops playback on the card
143 // ----------------------------------------------------------------------------
144 // The following enumeration defines the constants used to select the monitor
145 // mode for the card in the SetMonitorMode command.
146 // ----------------------------------------------------------------------------
147 enum MonitorModeSelector
{
148 K1212_MONMODE_Off
= 0, // tells card to turn off monitor mode
149 K1212_MONMODE_On
// tells card to turn on monitor mode
152 #define MAILBOX0_OFFSET 0x40 // location of mailbox 0 relative to base address
153 #define MAILBOX1_OFFSET 0x44 // location of mailbox 1 relative to base address
154 #define MAILBOX2_OFFSET 0x48 // location of mailbox 2 relative to base address
155 #define MAILBOX3_OFFSET 0x4c // location of mailbox 3 relative to base address
156 #define OUT_DOORBELL_OFFSET 0x60 // location of PCI to local doorbell
157 #define IN_DOORBELL_OFFSET 0x64 // location of local to PCI doorbell
158 #define STATUS_REG_OFFSET 0x68 // location of interrupt control/status register
159 #define PCI_CONTROL_OFFSET 0x6c // location of the EEPROM, PCI, User I/O, init control
161 #define SENS_CONTROL_OFFSET 0x6e // location of the input sensitivity setting register.
162 // this is the upper word of the PCI control reg.
163 #define DEV_VEND_ID_OFFSET 0x70 // location of the device and vendor ID register
165 #define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement
166 // from the card after sending a command.
167 #define INTERCOMMAND_DELAY 40
168 #define MAX_COMMAND_RETRIES 5 // maximum number of times the driver will attempt
169 // to send a command before giving up.
170 #define COMMAND_ACK_MASK 0x8000 // the MSB is set in the command acknowledgment from
172 #define DOORBELL_VAL_MASK 0x00FF // the doorbell value is one byte
174 #define CARD_BOOT_DELAY_IN_MS 10
175 #define CARD_BOOT_TIMEOUT 10
176 #define DSP_BOOT_DELAY_IN_MS 200
178 #define kNumBuffers 8
179 #define k1212MaxCards 4
180 #define k1212NumWaveDevices 6
181 #define k16BitChannels 10
182 #define k32BitChannels 2
183 #define kAudioChannels (k16BitChannels + k32BitChannels)
184 #define kPlayBufferFrames 1024
186 #define K1212_ANALOG_CHANNELS 2
187 #define K1212_SPDIF_CHANNELS 2
188 #define K1212_ADAT_CHANNELS 8
189 #define K1212_CHANNELS (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS)
190 #define K1212_MIN_CHANNELS 1
191 #define K1212_MAX_CHANNELS K1212_CHANNELS
192 #define K1212_FRAME_SIZE (sizeof(struct KorgAudioFrame))
193 #define K1212_MAX_SAMPLES (kPlayBufferFrames*kNumBuffers)
194 #define K1212_PERIODS (kNumBuffers)
195 #define K1212_PERIOD_BYTES (K1212_FRAME_SIZE*kPlayBufferFrames)
196 #define K1212_BUF_SIZE (K1212_PERIOD_BYTES*kNumBuffers)
197 #define K1212_ANALOG_BUF_SIZE (K1212_ANALOG_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
198 #define K1212_SPDIF_BUF_SIZE (K1212_SPDIF_CHANNELS * 3 * kPlayBufferFrames * kNumBuffers)
199 #define K1212_ADAT_BUF_SIZE (K1212_ADAT_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
200 #define K1212_MAX_BUF_SIZE (K1212_ANALOG_BUF_SIZE + K1212_ADAT_BUF_SIZE)
202 #define k1212MinADCSens 0x7f
203 #define k1212MaxADCSens 0x00
204 #define k1212MaxVolume 0x7fff
205 #define k1212MaxWaveVolume 0xffff
206 #define k1212MinVolume 0x0000
207 #define k1212MaxVolInverted 0x8000
209 // -----------------------------------------------------------------
210 // the following bits are used for controlling interrupts in the
211 // interrupt control/status reg
212 // -----------------------------------------------------------------
213 #define PCI_INT_ENABLE_BIT 0x00000100
214 #define PCI_DOORBELL_INT_ENABLE_BIT 0x00000200
215 #define LOCAL_INT_ENABLE_BIT 0x00010000
216 #define LOCAL_DOORBELL_INT_ENABLE_BIT 0x00020000
217 #define LOCAL_DMA1_INT_ENABLE_BIT 0x00080000
219 // -----------------------------------------------------------------
220 // the following bits are defined for the PCI command register
221 // -----------------------------------------------------------------
222 #define PCI_CMD_MEM_SPACE_ENABLE_BIT 0x0002
223 #define PCI_CMD_IO_SPACE_ENABLE_BIT 0x0001
224 #define PCI_CMD_BUS_MASTER_ENABLE_BIT 0x0004
226 // -----------------------------------------------------------------
227 // the following bits are defined for the PCI status register
228 // -----------------------------------------------------------------
229 #define PCI_STAT_PARITY_ERROR_BIT 0x8000
230 #define PCI_STAT_SYSTEM_ERROR_BIT 0x4000
231 #define PCI_STAT_MASTER_ABORT_RCVD_BIT 0x2000
232 #define PCI_STAT_TARGET_ABORT_RCVD_BIT 0x1000
233 #define PCI_STAT_TARGET_ABORT_SENT_BIT 0x0800
235 // ------------------------------------------------------------------------
236 // the following constants are used in setting the 1212 I/O card's input
238 // ------------------------------------------------------------------------
239 #define SET_SENS_LOCALINIT_BITPOS 15
240 #define SET_SENS_DATA_BITPOS 10
241 #define SET_SENS_CLOCK_BITPOS 8
242 #define SET_SENS_LOADSHIFT_BITPOS 0
244 #define SET_SENS_LEFTCHANID 0x00
245 #define SET_SENS_RIGHTCHANID 0x01
247 #define K1212SENSUPDATE_DELAY_IN_MS 50
249 // --------------------------------------------------------------------------
252 // This function waits the specified number of real time clock ticks.
253 // According to the DDK, each tick is ~0.8 microseconds.
254 // The defines following the function declaration can be used for the
255 // numTicksToWait parameter.
256 // --------------------------------------------------------------------------
257 #define ONE_RTC_TICK 1
258 #define SENSCLKPULSE_WIDTH 4
259 #define LOADSHIFT_DELAY 4
260 #define INTERCOMMAND_DELAY 40
261 #define STOPCARD_DELAY 300 // max # RTC ticks for the card to stop once we write
262 // the command register. (could be up to 180 us)
263 #define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement
264 // from the card after sending a command.
266 #include "korg1212-firmware.h"
268 enum ClockSourceIndex
{
269 K1212_CLKIDX_AdatAt44_1K
= 0, // selects source as ADAT at 44.1 kHz
270 K1212_CLKIDX_AdatAt48K
, // selects source as ADAT at 48 kHz
271 K1212_CLKIDX_WordAt44_1K
, // selects source as S/PDIF at 44.1 kHz
272 K1212_CLKIDX_WordAt48K
, // selects source as S/PDIF at 48 kHz
273 K1212_CLKIDX_LocalAt44_1K
, // selects source as local clock at 44.1 kHz
274 K1212_CLKIDX_LocalAt48K
, // selects source as local clock at 48 kHz
275 K1212_CLKIDX_Invalid
// used to check validity of the index
278 enum ClockSourceType
{
279 K1212_CLKIDX_Adat
= 0, // selects source as ADAT
280 K1212_CLKIDX_Word
, // selects source as S/PDIF
281 K1212_CLKIDX_Local
// selects source as local clock
284 struct KorgAudioFrame
{
285 u16 frameData16
[k16BitChannels
]; /* channels 0-9 use 16 bit samples */
286 u32 frameData32
[k32BitChannels
]; /* channels 10-11 use 32 bits - only 20 are sent across S/PDIF */
287 u32 timeCodeVal
; /* holds the ADAT timecode value */
290 struct KorgAudioBuffer
{
291 struct KorgAudioFrame bufferData
[kPlayBufferFrames
]; /* buffer definition */
294 struct KorgSharedBuffer
{
295 #ifdef K1212_LARGEALLOC
296 struct KorgAudioBuffer playDataBufs
[kNumBuffers
];
297 struct KorgAudioBuffer recordDataBufs
[kNumBuffers
];
299 short volumeData
[kAudioChannels
];
301 u16 routeData
[kAudioChannels
];
302 u32 AdatTimeCode
; // ADAT timecode value
308 unsigned int leftChanVal
:8;
309 unsigned int leftChanId
:8;
315 unsigned int rightChanVal
:8;
316 unsigned int rightChanId
:8;
322 struct snd_korg1212
{
323 struct snd_card
*card
;
329 struct mutex open_mutex
;
331 struct timer_list timer
; /* timer callback for checking ack of stop request */
332 int stop_pending_cnt
; /* counter for stop pending check */
334 wait_queue_head_t wait
;
337 unsigned long ioport
;
338 unsigned long iomem2
;
339 unsigned long irqcount
;
341 void __iomem
*iobase
;
343 struct snd_dma_buffer dma_dsp
;
344 struct snd_dma_buffer dma_play
;
345 struct snd_dma_buffer dma_rec
;
346 struct snd_dma_buffer dma_shared
;
352 struct KorgAudioBuffer
* playDataBufsPtr
;
353 struct KorgAudioBuffer
* recordDataBufsPtr
;
355 struct KorgSharedBuffer
* sharedBufferPtr
;
359 unsigned long sharedBufferPhy
;
364 u32 __iomem
* statusRegPtr
; // address of the interrupt status/control register
365 u32 __iomem
* outDoorbellPtr
; // address of the host->card doorbell register
366 u32 __iomem
* inDoorbellPtr
; // address of the card->host doorbell register
367 u32 __iomem
* mailbox0Ptr
; // address of mailbox 0 on the card
368 u32 __iomem
* mailbox1Ptr
; // address of mailbox 1 on the card
369 u32 __iomem
* mailbox2Ptr
; // address of mailbox 2 on the card
370 u32 __iomem
* mailbox3Ptr
; // address of mailbox 3 on the card
371 u32 __iomem
* controlRegPtr
; // address of the EEPROM, PCI, I/O, Init ctrl reg
372 u16 __iomem
* sensRegPtr
; // address of the sensitivity setting register
373 u32 __iomem
* idRegPtr
; // address of the device and vendor ID registers
379 struct snd_pcm_substream
*playback_substream
;
380 struct snd_pcm_substream
*capture_substream
;
385 enum CardState cardState
;
387 int idleMonitorOn
; // indicates whether the card is in idle monitor mode.
388 u32 cmdRetryCount
; // tracks how many times we have retried sending to the card.
390 enum ClockSourceIndex clkSrcRate
; // sample rate and clock source
392 enum ClockSourceType clkSource
; // clock source
393 int clkRate
; // clock rate
395 int volumePhase
[kAudioChannels
];
397 u16 leftADCInSens
; // ADC left channel input sensitivity
398 u16 rightADCInSens
; // ADC right channel input sensitivity
400 int opencnt
; // Open/Close count
401 int setcnt
; // SetupForPlay count
402 int playcnt
; // TriggerPlay count
403 int errorcnt
; // Error Count
404 unsigned long totalerrorcnt
; // Total Error Count
407 int dsp_stop_is_processed
;
411 MODULE_DESCRIPTION("korg1212");
412 MODULE_LICENSE("GPL");
413 MODULE_SUPPORTED_DEVICE("{{KORG,korg1212}}");
415 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
416 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
417 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
; /* Enable this card */
419 module_param_array(index
, int, NULL
, 0444);
420 MODULE_PARM_DESC(index
, "Index value for Korg 1212 soundcard.");
421 module_param_array(id
, charp
, NULL
, 0444);
422 MODULE_PARM_DESC(id
, "ID string for Korg 1212 soundcard.");
423 module_param_array(enable
, bool, NULL
, 0444);
424 MODULE_PARM_DESC(enable
, "Enable Korg 1212 soundcard.");
425 MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>");
427 static struct pci_device_id snd_korg1212_ids
[] = {
431 .subvendor
= PCI_ANY_ID
,
432 .subdevice
= PCI_ANY_ID
,
437 MODULE_DEVICE_TABLE(pci
, snd_korg1212_ids
);
439 static char *stateName
[] = {
442 "DSP download in process",
443 "DSP download complete",
453 static char *clockSourceTypeName
[] = { "ADAT", "S/PDIF", "local" };
455 static char *clockSourceName
[] = {
458 "S/PDIF at 44.1 kHz",
460 "local clock at 44.1 kHz",
461 "local clock at 48 kHz"
464 static char *channelName
[] = {
479 static u16 ClockSourceSelector
[] = {
480 0x8000, // selects source as ADAT at 44.1 kHz
481 0x0000, // selects source as ADAT at 48 kHz
482 0x8001, // selects source as S/PDIF at 44.1 kHz
483 0x0001, // selects source as S/PDIF at 48 kHz
484 0x8002, // selects source as local clock at 44.1 kHz
485 0x0002 // selects source as local clock at 48 kHz
488 union swap_u32
{ unsigned char c
[4]; u32 i
; };
490 #ifdef SNDRV_BIG_ENDIAN
491 static u32
LowerWordSwap(u32 swappee
)
493 static u32
UpperWordSwap(u32 swappee
)
496 union swap_u32 retVal
, swapper
;
499 retVal
.c
[2] = swapper
.c
[3];
500 retVal
.c
[3] = swapper
.c
[2];
501 retVal
.c
[1] = swapper
.c
[1];
502 retVal
.c
[0] = swapper
.c
[0];
507 #ifdef SNDRV_BIG_ENDIAN
508 static u32
UpperWordSwap(u32 swappee
)
510 static u32
LowerWordSwap(u32 swappee
)
513 union swap_u32 retVal
, swapper
;
516 retVal
.c
[2] = swapper
.c
[2];
517 retVal
.c
[3] = swapper
.c
[3];
518 retVal
.c
[1] = swapper
.c
[0];
519 retVal
.c
[0] = swapper
.c
[1];
524 #define SetBitInWord(theWord,bitPosition) (*theWord) |= (0x0001 << bitPosition)
525 #define SetBitInDWord(theWord,bitPosition) (*theWord) |= (0x00000001 << bitPosition)
526 #define ClearBitInWord(theWord,bitPosition) (*theWord) &= ~(0x0001 << bitPosition)
527 #define ClearBitInDWord(theWord,bitPosition) (*theWord) &= ~(0x00000001 << bitPosition)
529 static int snd_korg1212_Send1212Command(struct snd_korg1212
*korg1212
,
530 enum korg1212_dbcnst doorbellVal
,
531 u32 mailBox0Val
, u32 mailBox1Val
,
532 u32 mailBox2Val
, u32 mailBox3Val
)
536 int rc
= K1212_CMDRET_Success
;
538 if (!korg1212
->outDoorbellPtr
) {
539 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: CardUninitialized\n");
540 return K1212_CMDRET_CardUninitialized
;
543 K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n",
544 doorbellVal
, mailBox0Val
, stateName
[korg1212
->cardState
]);
545 for (retryCount
= 0; retryCount
< MAX_COMMAND_RETRIES
; retryCount
++) {
546 writel(mailBox3Val
, korg1212
->mailbox3Ptr
);
547 writel(mailBox2Val
, korg1212
->mailbox2Ptr
);
548 writel(mailBox1Val
, korg1212
->mailbox1Ptr
);
549 writel(mailBox0Val
, korg1212
->mailbox0Ptr
);
550 writel(doorbellVal
, korg1212
->outDoorbellPtr
); // interrupt the card
552 // --------------------------------------------------------------
553 // the reboot command will not give an acknowledgement.
554 // --------------------------------------------------------------
555 if ( doorbellVal
== K1212_DB_RebootCard
||
556 doorbellVal
== K1212_DB_BootFromDSPPage4
||
557 doorbellVal
== K1212_DB_StartDSPDownload
) {
558 rc
= K1212_CMDRET_Success
;
562 // --------------------------------------------------------------
563 // See if the card acknowledged the command. Wait a bit, then
564 // read in the low word of mailbox3. If the MSB is set and the
565 // low byte is equal to the doorbell value, then it ack'd.
566 // --------------------------------------------------------------
567 udelay(COMMAND_ACK_DELAY
);
568 mailBox3Lo
= readl(korg1212
->mailbox3Ptr
);
569 if (mailBox3Lo
& COMMAND_ACK_MASK
) {
570 if ((mailBox3Lo
& DOORBELL_VAL_MASK
) == (doorbellVal
& DOORBELL_VAL_MASK
)) {
571 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- Success\n");
572 rc
= K1212_CMDRET_Success
;
577 korg1212
->cmdRetryCount
+= retryCount
;
579 if (retryCount
>= MAX_COMMAND_RETRIES
) {
580 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- NoAckFromCard\n");
581 rc
= K1212_CMDRET_NoAckFromCard
;
587 /* spinlock already held */
588 static void snd_korg1212_SendStop(struct snd_korg1212
*korg1212
)
590 if (! korg1212
->stop_pending_cnt
) {
591 korg1212
->sharedBufferPtr
->cardCommand
= 0xffffffff;
592 /* program the timer */
593 korg1212
->stop_pending_cnt
= HZ
;
594 korg1212
->timer
.expires
= jiffies
+ 1;
595 add_timer(&korg1212
->timer
);
599 static void snd_korg1212_SendStopAndWait(struct snd_korg1212
*korg1212
)
602 spin_lock_irqsave(&korg1212
->lock
, flags
);
603 korg1212
->dsp_stop_is_processed
= 0;
604 snd_korg1212_SendStop(korg1212
);
605 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
606 wait_event_timeout(korg1212
->wait
, korg1212
->dsp_stop_is_processed
, (HZ
* 3) / 2);
609 /* timer callback for checking the ack of stop request */
610 static void snd_korg1212_timer_func(unsigned long data
)
612 struct snd_korg1212
*korg1212
= (struct snd_korg1212
*) data
;
615 spin_lock_irqsave(&korg1212
->lock
, flags
);
616 if (korg1212
->sharedBufferPtr
->cardCommand
== 0) {
618 korg1212
->stop_pending_cnt
= 0;
619 korg1212
->dsp_stop_is_processed
= 1;
620 wake_up(&korg1212
->wait
);
621 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Stop ack'ed [%s]\n",
622 stateName
[korg1212
->cardState
]);
624 if (--korg1212
->stop_pending_cnt
> 0) {
625 /* reprogram timer */
626 korg1212
->timer
.expires
= jiffies
+ 1;
627 add_timer(&korg1212
->timer
);
629 snd_printd("korg1212_timer_func timeout\n");
630 korg1212
->sharedBufferPtr
->cardCommand
= 0;
631 korg1212
->dsp_stop_is_processed
= 1;
632 wake_up(&korg1212
->wait
);
633 K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n",
634 stateName
[korg1212
->cardState
]);
637 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
640 static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212
*korg1212
)
645 udelay(INTERCOMMAND_DELAY
);
646 spin_lock_irqsave(&korg1212
->lock
, flags
);
647 korg1212
->idleMonitorOn
= 1;
648 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
649 K1212_MODE_MonitorOn
, 0, 0, 0);
650 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
654 static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212
*korg1212
)
656 if (korg1212
->idleMonitorOn
) {
657 snd_korg1212_SendStopAndWait(korg1212
);
658 korg1212
->idleMonitorOn
= 0;
662 static inline void snd_korg1212_setCardState(struct snd_korg1212
* korg1212
, enum CardState csState
)
664 korg1212
->cardState
= csState
;
667 static int snd_korg1212_OpenCard(struct snd_korg1212
* korg1212
)
669 K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n",
670 stateName
[korg1212
->cardState
], korg1212
->opencnt
);
671 mutex_lock(&korg1212
->open_mutex
);
672 if (korg1212
->opencnt
++ == 0) {
673 snd_korg1212_TurnOffIdleMonitor(korg1212
);
674 snd_korg1212_setCardState(korg1212
, K1212_STATE_OPEN
);
677 mutex_unlock(&korg1212
->open_mutex
);
681 static int snd_korg1212_CloseCard(struct snd_korg1212
* korg1212
)
683 K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n",
684 stateName
[korg1212
->cardState
], korg1212
->opencnt
);
686 mutex_lock(&korg1212
->open_mutex
);
687 if (--(korg1212
->opencnt
)) {
688 mutex_unlock(&korg1212
->open_mutex
);
692 if (korg1212
->cardState
== K1212_STATE_SETUP
) {
693 int rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
694 K1212_MODE_StopPlay
, 0, 0, 0);
696 K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n",
697 rc
, stateName
[korg1212
->cardState
]);
698 if (rc
!= K1212_CMDRET_Success
) {
699 mutex_unlock(&korg1212
->open_mutex
);
702 } else if (korg1212
->cardState
> K1212_STATE_SETUP
) {
703 snd_korg1212_SendStopAndWait(korg1212
);
706 if (korg1212
->cardState
> K1212_STATE_READY
) {
707 snd_korg1212_TurnOnIdleMonitor(korg1212
);
708 snd_korg1212_setCardState(korg1212
, K1212_STATE_READY
);
711 mutex_unlock(&korg1212
->open_mutex
);
715 /* spinlock already held */
716 static int snd_korg1212_SetupForPlay(struct snd_korg1212
* korg1212
)
720 K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n",
721 stateName
[korg1212
->cardState
], korg1212
->setcnt
);
723 if (korg1212
->setcnt
++)
726 snd_korg1212_setCardState(korg1212
, K1212_STATE_SETUP
);
727 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
728 K1212_MODE_SetupPlay
, 0, 0, 0);
730 K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n",
731 rc
, stateName
[korg1212
->cardState
]);
732 if (rc
!= K1212_CMDRET_Success
) {
738 /* spinlock already held */
739 static int snd_korg1212_TriggerPlay(struct snd_korg1212
* korg1212
)
743 K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n",
744 stateName
[korg1212
->cardState
], korg1212
->playcnt
);
746 if (korg1212
->playcnt
++)
749 snd_korg1212_setCardState(korg1212
, K1212_STATE_PLAYING
);
750 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_TriggerPlay
, 0, 0, 0, 0);
752 K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n",
753 rc
, stateName
[korg1212
->cardState
]);
754 if (rc
!= K1212_CMDRET_Success
) {
760 /* spinlock already held */
761 static int snd_korg1212_StopPlay(struct snd_korg1212
* korg1212
)
763 K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n",
764 stateName
[korg1212
->cardState
], korg1212
->playcnt
);
766 if (--(korg1212
->playcnt
))
769 korg1212
->setcnt
= 0;
771 if (korg1212
->cardState
!= K1212_STATE_ERRORSTOP
)
772 snd_korg1212_SendStop(korg1212
);
774 snd_korg1212_setCardState(korg1212
, K1212_STATE_OPEN
);
778 static void snd_korg1212_EnableCardInterrupts(struct snd_korg1212
* korg1212
)
780 writel(PCI_INT_ENABLE_BIT
|
781 PCI_DOORBELL_INT_ENABLE_BIT
|
782 LOCAL_INT_ENABLE_BIT
|
783 LOCAL_DOORBELL_INT_ENABLE_BIT
|
784 LOCAL_DMA1_INT_ENABLE_BIT
,
785 korg1212
->statusRegPtr
);
790 static int snd_korg1212_SetMonitorMode(struct snd_korg1212
*korg1212
,
791 enum MonitorModeSelector mode
)
793 K1212_DEBUG_PRINTK("K1212_DEBUG: SetMonitorMode [%s]\n",
794 stateName
[korg1212
->cardState
]);
797 case K1212_MONMODE_Off
:
798 if (korg1212
->cardState
!= K1212_STATE_MONITOR
)
801 snd_korg1212_SendStopAndWait(korg1212
);
802 snd_korg1212_setCardState(korg1212
, K1212_STATE_OPEN
);
806 case K1212_MONMODE_On
:
807 if (korg1212
->cardState
!= K1212_STATE_OPEN
)
811 snd_korg1212_setCardState(korg1212
, K1212_STATE_MONITOR
);
812 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
813 K1212_MODE_MonitorOn
, 0, 0, 0);
814 if (rc
!= K1212_CMDRET_Success
)
826 #endif /* not used */
828 static inline int snd_korg1212_use_is_exclusive(struct snd_korg1212
*korg1212
)
830 if (korg1212
->playback_pid
!= korg1212
->capture_pid
&&
831 korg1212
->playback_pid
>= 0 && korg1212
->capture_pid
>= 0)
837 static int snd_korg1212_SetRate(struct snd_korg1212
*korg1212
, int rate
)
839 static enum ClockSourceIndex s44
[] = {
840 K1212_CLKIDX_AdatAt44_1K
,
841 K1212_CLKIDX_WordAt44_1K
,
842 K1212_CLKIDX_LocalAt44_1K
844 static enum ClockSourceIndex s48
[] = {
845 K1212_CLKIDX_AdatAt48K
,
846 K1212_CLKIDX_WordAt48K
,
847 K1212_CLKIDX_LocalAt48K
851 if (!snd_korg1212_use_is_exclusive (korg1212
))
856 parm
= s44
[korg1212
->clkSource
];
860 parm
= s48
[korg1212
->clkSource
];
867 korg1212
->clkSrcRate
= parm
;
868 korg1212
->clkRate
= rate
;
870 udelay(INTERCOMMAND_DELAY
);
871 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SetClockSourceRate
,
872 ClockSourceSelector
[korg1212
->clkSrcRate
],
875 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n",
876 rc
, stateName
[korg1212
->cardState
]);
881 static int snd_korg1212_SetClockSource(struct snd_korg1212
*korg1212
, int source
)
884 if (source
< 0 || source
> 2)
887 korg1212
->clkSource
= source
;
889 snd_korg1212_SetRate(korg1212
, korg1212
->clkRate
);
894 static void snd_korg1212_DisableCardInterrupts(struct snd_korg1212
*korg1212
)
896 writel(0, korg1212
->statusRegPtr
);
899 static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212
*korg1212
)
901 struct SensBits sensVals
;
906 u16 controlValue
; // this keeps the current value to be written to
907 // the card's eeprom control register.
911 K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n",
912 stateName
[korg1212
->cardState
]);
914 // ----------------------------------------------------------------------------
915 // initialize things. The local init bit is always set when writing to the
916 // card's control register.
917 // ----------------------------------------------------------------------------
919 SetBitInWord(&controlValue
, SET_SENS_LOCALINIT_BITPOS
); // init the control value
921 // ----------------------------------------------------------------------------
922 // make sure the card is not in monitor mode when we do this update.
923 // ----------------------------------------------------------------------------
924 if (korg1212
->cardState
== K1212_STATE_MONITOR
|| korg1212
->idleMonitorOn
) {
926 snd_korg1212_SendStopAndWait(korg1212
);
930 spin_lock_irqsave(&korg1212
->lock
, flags
);
932 // ----------------------------------------------------------------------------
933 // we are about to send new values to the card, so clear the new values queued
934 // flag. Also, clear out mailbox 3, so we don't lockup.
935 // ----------------------------------------------------------------------------
936 writel(0, korg1212
->mailbox3Ptr
);
937 udelay(LOADSHIFT_DELAY
);
939 // ----------------------------------------------------------------------------
940 // determine whether we are running a 48K or 44.1K clock. This info is used
941 // later when setting the SPDIF FF after the volume has been shifted in.
942 // ----------------------------------------------------------------------------
943 switch (korg1212
->clkSrcRate
) {
944 case K1212_CLKIDX_AdatAt44_1K
:
945 case K1212_CLKIDX_WordAt44_1K
:
946 case K1212_CLKIDX_LocalAt44_1K
:
950 case K1212_CLKIDX_WordAt48K
:
951 case K1212_CLKIDX_AdatAt48K
:
952 case K1212_CLKIDX_LocalAt48K
:
958 // ----------------------------------------------------------------------------
959 // start the update. Setup the bit structure and then shift the bits.
960 // ----------------------------------------------------------------------------
961 sensVals
.l
.v
.leftChanId
= SET_SENS_LEFTCHANID
;
962 sensVals
.r
.v
.rightChanId
= SET_SENS_RIGHTCHANID
;
963 sensVals
.l
.v
.leftChanVal
= korg1212
->leftADCInSens
;
964 sensVals
.r
.v
.rightChanVal
= korg1212
->rightADCInSens
;
966 // ----------------------------------------------------------------------------
967 // now start shifting the bits in. Start with the left channel then the right.
968 // ----------------------------------------------------------------------------
969 for (channel
= 0; channel
< 2; channel
++) {
971 // ----------------------------------------------------------------------------
972 // Bring the load/shift line low, then wait - the spec says >150ns from load/
973 // shift low to the first rising edge of the clock.
974 // ----------------------------------------------------------------------------
975 ClearBitInWord(&controlValue
, SET_SENS_LOADSHIFT_BITPOS
);
976 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
977 writew(controlValue
, korg1212
->sensRegPtr
); // load/shift goes low
978 udelay(LOADSHIFT_DELAY
);
980 for (bitPosition
= 15; bitPosition
>= 0; bitPosition
--) { // for all the bits
982 if (sensVals
.l
.leftSensBits
& (0x0001 << bitPosition
))
983 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set high
985 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set low
987 if (sensVals
.r
.rightSensBits
& (0x0001 << bitPosition
))
988 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set high
990 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set low
993 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
994 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes low
995 udelay(SENSCLKPULSE_WIDTH
);
996 SetBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
997 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes high
998 udelay(SENSCLKPULSE_WIDTH
);
1001 // ----------------------------------------------------------------------------
1002 // finish up SPDIF for left. Bring the load/shift line high, then write a one
1003 // bit if the clock rate is 48K otherwise write 0.
1004 // ----------------------------------------------------------------------------
1005 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
1006 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
1007 SetBitInWord(&controlValue
, SET_SENS_LOADSHIFT_BITPOS
);
1008 writew(controlValue
, korg1212
->sensRegPtr
); // load shift goes high - clk low
1009 udelay(SENSCLKPULSE_WIDTH
);
1012 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
1014 writew(controlValue
, korg1212
->sensRegPtr
); // set/clear data bit
1015 udelay(ONE_RTC_TICK
);
1016 SetBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
1017 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes high
1018 udelay(SENSCLKPULSE_WIDTH
);
1019 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
1020 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes low
1021 udelay(SENSCLKPULSE_WIDTH
);
1024 // ----------------------------------------------------------------------------
1025 // The update is complete. Set a timeout. This is the inter-update delay.
1026 // Also, if the card was in monitor mode, restore it.
1027 // ----------------------------------------------------------------------------
1028 for (count
= 0; count
< 10; count
++)
1029 udelay(SENSCLKPULSE_WIDTH
);
1032 int rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
1033 K1212_MODE_MonitorOn
, 0, 0, 0);
1035 K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n",
1036 rc
, stateName
[korg1212
->cardState
]);
1039 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1044 static void snd_korg1212_OnDSPDownloadComplete(struct snd_korg1212
*korg1212
)
1048 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n",
1049 stateName
[korg1212
->cardState
]);
1051 // ----------------------------------------------------
1052 // tell the card to boot
1053 // ----------------------------------------------------
1054 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_BootFromDSPPage4
, 0, 0, 0, 0);
1057 K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n",
1058 rc
, stateName
[korg1212
->cardState
]);
1059 msleep(DSP_BOOT_DELAY_IN_MS
);
1061 // --------------------------------------------------------------------------------
1062 // Let the card know where all the buffers are.
1063 // --------------------------------------------------------------------------------
1064 rc
= snd_korg1212_Send1212Command(korg1212
,
1065 K1212_DB_ConfigureBufferMemory
,
1066 LowerWordSwap(korg1212
->PlayDataPhy
),
1067 LowerWordSwap(korg1212
->RecDataPhy
),
1068 ((kNumBuffers
* kPlayBufferFrames
) / 2), // size given to the card
1069 // is based on 2 buffers
1074 K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n",
1075 rc
, stateName
[korg1212
->cardState
]);
1077 udelay(INTERCOMMAND_DELAY
);
1079 rc
= snd_korg1212_Send1212Command(korg1212
,
1080 K1212_DB_ConfigureMiscMemory
,
1081 LowerWordSwap(korg1212
->VolumeTablePhy
),
1082 LowerWordSwap(korg1212
->RoutingTablePhy
),
1083 LowerWordSwap(korg1212
->AdatTimeCodePhy
),
1088 K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n",
1089 rc
, stateName
[korg1212
->cardState
]);
1091 // --------------------------------------------------------------------------------
1092 // Initialize the routing and volume tables, then update the card's state.
1093 // --------------------------------------------------------------------------------
1094 udelay(INTERCOMMAND_DELAY
);
1096 for (channel
= 0; channel
< kAudioChannels
; channel
++) {
1097 korg1212
->sharedBufferPtr
->volumeData
[channel
] = k1212MaxVolume
;
1098 //korg1212->sharedBufferPtr->routeData[channel] = channel;
1099 korg1212
->sharedBufferPtr
->routeData
[channel
] = 8 + (channel
& 1);
1102 snd_korg1212_WriteADCSensitivity(korg1212
);
1104 udelay(INTERCOMMAND_DELAY
);
1105 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SetClockSourceRate
,
1106 ClockSourceSelector
[korg1212
->clkSrcRate
],
1109 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n",
1110 rc
, stateName
[korg1212
->cardState
]);
1112 rc
= snd_korg1212_TurnOnIdleMonitor(korg1212
);
1113 snd_korg1212_setCardState(korg1212
, K1212_STATE_READY
);
1116 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n",
1117 rc
, stateName
[korg1212
->cardState
]);
1119 snd_korg1212_setCardState(korg1212
, K1212_STATE_DSP_COMPLETE
);
1122 static irqreturn_t
snd_korg1212_interrupt(int irq
, void *dev_id
)
1125 struct snd_korg1212
*korg1212
= dev_id
;
1127 doorbellValue
= readl(korg1212
->inDoorbellPtr
);
1132 spin_lock(&korg1212
->lock
);
1134 writel(doorbellValue
, korg1212
->inDoorbellPtr
);
1136 korg1212
->irqcount
++;
1140 switch (doorbellValue
) {
1141 case K1212_DB_DSPDownloadDone
:
1142 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n",
1143 korg1212
->irqcount
, doorbellValue
,
1144 stateName
[korg1212
->cardState
]);
1145 if (korg1212
->cardState
== K1212_STATE_DSP_IN_PROCESS
) {
1146 korg1212
->dsp_is_loaded
= 1;
1147 wake_up(&korg1212
->wait
);
1151 // ------------------------------------------------------------------------
1152 // an error occurred - stop the card
1153 // ------------------------------------------------------------------------
1154 case K1212_DB_DMAERROR
:
1155 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n",
1156 korg1212
->irqcount
, doorbellValue
,
1157 stateName
[korg1212
->cardState
]);
1158 snd_printk(KERN_ERR
"korg1212: DMA Error\n");
1159 korg1212
->errorcnt
++;
1160 korg1212
->totalerrorcnt
++;
1161 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1162 snd_korg1212_setCardState(korg1212
, K1212_STATE_ERRORSTOP
);
1165 // ------------------------------------------------------------------------
1166 // the card has stopped by our request. Clear the command word and signal
1167 // the semaphore in case someone is waiting for this.
1168 // ------------------------------------------------------------------------
1169 case K1212_DB_CARDSTOPPED
:
1170 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n",
1171 korg1212
->irqcount
, doorbellValue
,
1172 stateName
[korg1212
->cardState
]);
1173 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1177 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n",
1178 korg1212
->irqcount
, doorbellValue
,
1179 korg1212
->currentBuffer
, stateName
[korg1212
->cardState
]);
1180 if ((korg1212
->cardState
> K1212_STATE_SETUP
) || korg1212
->idleMonitorOn
) {
1181 korg1212
->currentBuffer
++;
1183 if (korg1212
->currentBuffer
>= kNumBuffers
)
1184 korg1212
->currentBuffer
= 0;
1186 if (!korg1212
->running
)
1189 if (korg1212
->capture_substream
) {
1190 spin_unlock(&korg1212
->lock
);
1191 snd_pcm_period_elapsed(korg1212
->capture_substream
);
1192 spin_lock(&korg1212
->lock
);
1195 if (korg1212
->playback_substream
) {
1196 spin_unlock(&korg1212
->lock
);
1197 snd_pcm_period_elapsed(korg1212
->playback_substream
);
1198 spin_lock(&korg1212
->lock
);
1206 spin_unlock(&korg1212
->lock
);
1211 static int snd_korg1212_downloadDSPCode(struct snd_korg1212
*korg1212
)
1215 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n",
1216 stateName
[korg1212
->cardState
]);
1218 // ---------------------------------------------------------------
1219 // verify the state of the card before proceeding.
1220 // ---------------------------------------------------------------
1221 if (korg1212
->cardState
>= K1212_STATE_DSP_IN_PROCESS
)
1224 snd_korg1212_setCardState(korg1212
, K1212_STATE_DSP_IN_PROCESS
);
1226 memcpy(korg1212
->dma_dsp
.area
, dspCode
, korg1212
->dspCodeSize
);
1228 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_StartDSPDownload
,
1229 UpperWordSwap(korg1212
->dma_dsp
.addr
),
1232 K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n",
1233 rc
, stateName
[korg1212
->cardState
]);
1235 korg1212
->dsp_is_loaded
= 0;
1236 wait_event_timeout(korg1212
->wait
, korg1212
->dsp_is_loaded
, HZ
* CARD_BOOT_TIMEOUT
);
1237 if (! korg1212
->dsp_is_loaded
)
1238 return -EBUSY
; /* timeout */
1240 snd_korg1212_OnDSPDownloadComplete(korg1212
);
1245 static struct snd_pcm_hardware snd_korg1212_playback_info
=
1247 .info
= (SNDRV_PCM_INFO_MMAP
|
1248 SNDRV_PCM_INFO_MMAP_VALID
|
1249 SNDRV_PCM_INFO_INTERLEAVED
),
1250 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1251 .rates
= (SNDRV_PCM_RATE_44100
|
1252 SNDRV_PCM_RATE_48000
),
1255 .channels_min
= K1212_MIN_CHANNELS
,
1256 .channels_max
= K1212_MAX_CHANNELS
,
1257 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1258 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1259 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1260 .periods_min
= K1212_PERIODS
,
1261 .periods_max
= K1212_PERIODS
,
1265 static struct snd_pcm_hardware snd_korg1212_capture_info
=
1267 .info
= (SNDRV_PCM_INFO_MMAP
|
1268 SNDRV_PCM_INFO_MMAP_VALID
|
1269 SNDRV_PCM_INFO_INTERLEAVED
),
1270 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1271 .rates
= (SNDRV_PCM_RATE_44100
|
1272 SNDRV_PCM_RATE_48000
),
1275 .channels_min
= K1212_MIN_CHANNELS
,
1276 .channels_max
= K1212_MAX_CHANNELS
,
1277 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1278 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1279 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1280 .periods_min
= K1212_PERIODS
,
1281 .periods_max
= K1212_PERIODS
,
1285 static int snd_korg1212_silence(struct snd_korg1212
*korg1212
, int pos
, int count
, int offset
, int size
)
1287 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1290 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n",
1291 pos
, offset
, size
, count
);
1292 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1294 for (i
=0; i
< count
; i
++) {
1295 #if K1212_DEBUG_LEVEL > 0
1296 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1297 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1298 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n",
1303 memset((void*) dst
+ offset
, 0, size
);
1310 static int snd_korg1212_copy_to(struct snd_korg1212
*korg1212
, void __user
*dst
, int pos
, int count
, int offset
, int size
)
1312 struct KorgAudioFrame
* src
= korg1212
->recordDataBufsPtr
[0].bufferData
+ pos
;
1315 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n",
1317 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1319 for (i
=0; i
< count
; i
++) {
1320 #if K1212_DEBUG_LEVEL > 0
1321 if ( (void *) src
< (void *) korg1212
->recordDataBufsPtr
||
1322 (void *) src
> (void *) korg1212
->recordDataBufsPtr
[8].bufferData
) {
1323 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1327 rc
= copy_to_user(dst
+ offset
, src
, size
);
1329 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1339 static int snd_korg1212_copy_from(struct snd_korg1212
*korg1212
, void __user
*src
, int pos
, int count
, int offset
, int size
)
1341 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1344 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n",
1345 pos
, offset
, size
, count
);
1347 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1349 for (i
=0; i
< count
; i
++) {
1350 #if K1212_DEBUG_LEVEL > 0
1351 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1352 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1353 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1357 rc
= copy_from_user((void*) dst
+ offset
, src
, size
);
1359 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1369 static void snd_korg1212_free_pcm(struct snd_pcm
*pcm
)
1371 struct snd_korg1212
*korg1212
= pcm
->private_data
;
1373 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n",
1374 stateName
[korg1212
->cardState
]);
1376 korg1212
->pcm
= NULL
;
1379 static int snd_korg1212_playback_open(struct snd_pcm_substream
*substream
)
1381 unsigned long flags
;
1382 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1383 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1385 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n",
1386 stateName
[korg1212
->cardState
]);
1388 snd_pcm_set_sync(substream
); // ???
1390 snd_korg1212_OpenCard(korg1212
);
1392 runtime
->hw
= snd_korg1212_playback_info
;
1393 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_play
);
1395 spin_lock_irqsave(&korg1212
->lock
, flags
);
1397 korg1212
->playback_substream
= substream
;
1398 korg1212
->playback_pid
= current
->pid
;
1399 korg1212
->periodsize
= K1212_PERIODS
;
1400 korg1212
->channels
= K1212_CHANNELS
;
1401 korg1212
->errorcnt
= 0;
1403 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1405 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, kPlayBufferFrames
, kPlayBufferFrames
);
1410 static int snd_korg1212_capture_open(struct snd_pcm_substream
*substream
)
1412 unsigned long flags
;
1413 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1414 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1416 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n",
1417 stateName
[korg1212
->cardState
]);
1419 snd_pcm_set_sync(substream
);
1421 snd_korg1212_OpenCard(korg1212
);
1423 runtime
->hw
= snd_korg1212_capture_info
;
1424 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_rec
);
1426 spin_lock_irqsave(&korg1212
->lock
, flags
);
1428 korg1212
->capture_substream
= substream
;
1429 korg1212
->capture_pid
= current
->pid
;
1430 korg1212
->periodsize
= K1212_PERIODS
;
1431 korg1212
->channels
= K1212_CHANNELS
;
1433 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1435 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1436 kPlayBufferFrames
, kPlayBufferFrames
);
1440 static int snd_korg1212_playback_close(struct snd_pcm_substream
*substream
)
1442 unsigned long flags
;
1443 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1445 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n",
1446 stateName
[korg1212
->cardState
]);
1448 snd_korg1212_silence(korg1212
, 0, K1212_MAX_SAMPLES
, 0, korg1212
->channels
* 2);
1450 spin_lock_irqsave(&korg1212
->lock
, flags
);
1452 korg1212
->playback_pid
= -1;
1453 korg1212
->playback_substream
= NULL
;
1454 korg1212
->periodsize
= 0;
1456 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1458 snd_korg1212_CloseCard(korg1212
);
1462 static int snd_korg1212_capture_close(struct snd_pcm_substream
*substream
)
1464 unsigned long flags
;
1465 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1467 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n",
1468 stateName
[korg1212
->cardState
]);
1470 spin_lock_irqsave(&korg1212
->lock
, flags
);
1472 korg1212
->capture_pid
= -1;
1473 korg1212
->capture_substream
= NULL
;
1474 korg1212
->periodsize
= 0;
1476 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1478 snd_korg1212_CloseCard(korg1212
);
1482 static int snd_korg1212_ioctl(struct snd_pcm_substream
*substream
,
1483 unsigned int cmd
, void *arg
)
1485 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd
);
1487 if (cmd
== SNDRV_PCM_IOCTL1_CHANNEL_INFO
) {
1488 struct snd_pcm_channel_info
*info
= arg
;
1490 info
->first
= info
->channel
* 16;
1492 K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info
->channel
, info
->offset
, info
->first
, info
->step
);
1496 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1499 static int snd_korg1212_hw_params(struct snd_pcm_substream
*substream
,
1500 struct snd_pcm_hw_params
*params
)
1502 unsigned long flags
;
1503 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1508 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n",
1509 stateName
[korg1212
->cardState
]);
1511 spin_lock_irqsave(&korg1212
->lock
, flags
);
1513 if (substream
->pstr
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1514 this_pid
= korg1212
->playback_pid
;
1515 other_pid
= korg1212
->capture_pid
;
1517 this_pid
= korg1212
->capture_pid
;
1518 other_pid
= korg1212
->playback_pid
;
1521 if ((other_pid
> 0) && (this_pid
!= other_pid
)) {
1523 /* The other stream is open, and not by the same
1524 task as this one. Make sure that the parameters
1525 that matter are the same.
1528 if ((int)params_rate(params
) != korg1212
->clkRate
) {
1529 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1530 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
1534 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1538 if ((err
= snd_korg1212_SetRate(korg1212
, params_rate(params
))) < 0) {
1539 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1543 korg1212
->channels
= params_channels(params
);
1544 korg1212
->periodsize
= K1212_PERIOD_BYTES
;
1546 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1551 static int snd_korg1212_prepare(struct snd_pcm_substream
*substream
)
1553 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1556 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n",
1557 stateName
[korg1212
->cardState
]);
1559 spin_lock_irq(&korg1212
->lock
);
1561 /* FIXME: we should wait for ack! */
1562 if (korg1212
->stop_pending_cnt
> 0) {
1563 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n",
1564 stateName
[korg1212
->cardState
]);
1565 spin_unlock_irq(&korg1212
->lock
);
1568 korg1212->sharedBufferPtr->cardCommand = 0;
1569 del_timer(&korg1212->timer);
1570 korg1212->stop_pending_cnt = 0;
1574 rc
= snd_korg1212_SetupForPlay(korg1212
);
1576 korg1212
->currentBuffer
= 0;
1578 spin_unlock_irq(&korg1212
->lock
);
1580 return rc
? -EINVAL
: 0;
1583 static int snd_korg1212_trigger(struct snd_pcm_substream
*substream
,
1586 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1589 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n",
1590 stateName
[korg1212
->cardState
], cmd
);
1592 spin_lock(&korg1212
->lock
);
1594 case SNDRV_PCM_TRIGGER_START
:
1596 if (korg1212->running) {
1597 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n");
1601 korg1212
->running
++;
1602 rc
= snd_korg1212_TriggerPlay(korg1212
);
1605 case SNDRV_PCM_TRIGGER_STOP
:
1607 if (!korg1212->running) {
1608 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n");
1612 korg1212
->running
--;
1613 rc
= snd_korg1212_StopPlay(korg1212
);
1620 spin_unlock(&korg1212
->lock
);
1621 return rc
? -EINVAL
: 0;
1624 static snd_pcm_uframes_t
snd_korg1212_playback_pointer(struct snd_pcm_substream
*substream
)
1626 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1627 snd_pcm_uframes_t pos
;
1629 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1631 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n",
1632 stateName
[korg1212
->cardState
], pos
);
1637 static snd_pcm_uframes_t
snd_korg1212_capture_pointer(struct snd_pcm_substream
*substream
)
1639 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1640 snd_pcm_uframes_t pos
;
1642 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1644 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n",
1645 stateName
[korg1212
->cardState
], pos
);
1650 static int snd_korg1212_playback_copy(struct snd_pcm_substream
*substream
,
1651 int channel
, /* not used (interleaved data) */
1652 snd_pcm_uframes_t pos
,
1654 snd_pcm_uframes_t count
)
1656 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1658 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n",
1659 stateName
[korg1212
->cardState
], pos
, count
);
1661 return snd_korg1212_copy_from(korg1212
, src
, pos
, count
, 0, korg1212
->channels
* 2);
1665 static int snd_korg1212_playback_silence(struct snd_pcm_substream
*substream
,
1666 int channel
, /* not used (interleaved data) */
1667 snd_pcm_uframes_t pos
,
1668 snd_pcm_uframes_t count
)
1670 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1672 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n",
1673 stateName
[korg1212
->cardState
]);
1675 return snd_korg1212_silence(korg1212
, pos
, count
, 0, korg1212
->channels
* 2);
1678 static int snd_korg1212_capture_copy(struct snd_pcm_substream
*substream
,
1679 int channel
, /* not used (interleaved data) */
1680 snd_pcm_uframes_t pos
,
1682 snd_pcm_uframes_t count
)
1684 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1686 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n",
1687 stateName
[korg1212
->cardState
], pos
, count
);
1689 return snd_korg1212_copy_to(korg1212
, dst
, pos
, count
, 0, korg1212
->channels
* 2);
1692 static struct snd_pcm_ops snd_korg1212_playback_ops
= {
1693 .open
= snd_korg1212_playback_open
,
1694 .close
= snd_korg1212_playback_close
,
1695 .ioctl
= snd_korg1212_ioctl
,
1696 .hw_params
= snd_korg1212_hw_params
,
1697 .prepare
= snd_korg1212_prepare
,
1698 .trigger
= snd_korg1212_trigger
,
1699 .pointer
= snd_korg1212_playback_pointer
,
1700 .copy
= snd_korg1212_playback_copy
,
1701 .silence
= snd_korg1212_playback_silence
,
1704 static struct snd_pcm_ops snd_korg1212_capture_ops
= {
1705 .open
= snd_korg1212_capture_open
,
1706 .close
= snd_korg1212_capture_close
,
1707 .ioctl
= snd_korg1212_ioctl
,
1708 .hw_params
= snd_korg1212_hw_params
,
1709 .prepare
= snd_korg1212_prepare
,
1710 .trigger
= snd_korg1212_trigger
,
1711 .pointer
= snd_korg1212_capture_pointer
,
1712 .copy
= snd_korg1212_capture_copy
,
1719 static int snd_korg1212_control_phase_info(struct snd_kcontrol
*kcontrol
,
1720 struct snd_ctl_elem_info
*uinfo
)
1722 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1723 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1727 static int snd_korg1212_control_phase_get(struct snd_kcontrol
*kcontrol
,
1728 struct snd_ctl_elem_value
*u
)
1730 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1731 int i
= kcontrol
->private_value
;
1733 spin_lock_irq(&korg1212
->lock
);
1735 u
->value
.integer
.value
[0] = korg1212
->volumePhase
[i
];
1738 u
->value
.integer
.value
[1] = korg1212
->volumePhase
[i
+1];
1740 spin_unlock_irq(&korg1212
->lock
);
1745 static int snd_korg1212_control_phase_put(struct snd_kcontrol
*kcontrol
,
1746 struct snd_ctl_elem_value
*u
)
1748 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1752 spin_lock_irq(&korg1212
->lock
);
1754 i
= kcontrol
->private_value
;
1756 korg1212
->volumePhase
[i
] = u
->value
.integer
.value
[0];
1758 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
];
1760 if ((u
->value
.integer
.value
[0] > 0) != (val
< 0)) {
1761 val
= abs(val
) * (korg1212
->volumePhase
[i
] > 0 ? -1 : 1);
1762 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1767 korg1212
->volumePhase
[i
+1] = u
->value
.integer
.value
[1];
1769 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
+1];
1771 if ((u
->value
.integer
.value
[1] > 0) != (val
< 0)) {
1772 val
= abs(val
) * (korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1);
1773 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1778 spin_unlock_irq(&korg1212
->lock
);
1783 static int snd_korg1212_control_volume_info(struct snd_kcontrol
*kcontrol
,
1784 struct snd_ctl_elem_info
*uinfo
)
1786 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1787 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1788 uinfo
->value
.integer
.min
= k1212MinVolume
;
1789 uinfo
->value
.integer
.max
= k1212MaxVolume
;
1793 static int snd_korg1212_control_volume_get(struct snd_kcontrol
*kcontrol
,
1794 struct snd_ctl_elem_value
*u
)
1796 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1799 spin_lock_irq(&korg1212
->lock
);
1801 i
= kcontrol
->private_value
;
1802 u
->value
.integer
.value
[0] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
]);
1805 u
->value
.integer
.value
[1] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1]);
1807 spin_unlock_irq(&korg1212
->lock
);
1812 static int snd_korg1212_control_volume_put(struct snd_kcontrol
*kcontrol
,
1813 struct snd_ctl_elem_value
*u
)
1815 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1820 spin_lock_irq(&korg1212
->lock
);
1822 i
= kcontrol
->private_value
;
1824 if (u
->value
.integer
.value
[0] != abs(korg1212
->sharedBufferPtr
->volumeData
[i
])) {
1825 val
= korg1212
->volumePhase
[i
] > 0 ? -1 : 1;
1826 val
*= u
->value
.integer
.value
[0];
1827 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1832 if (u
->value
.integer
.value
[1] != abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1])) {
1833 val
= korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1;
1834 val
*= u
->value
.integer
.value
[1];
1835 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1840 spin_unlock_irq(&korg1212
->lock
);
1845 static int snd_korg1212_control_route_info(struct snd_kcontrol
*kcontrol
,
1846 struct snd_ctl_elem_info
*uinfo
)
1848 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1849 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1850 uinfo
->value
.enumerated
.items
= kAudioChannels
;
1851 if (uinfo
->value
.enumerated
.item
> kAudioChannels
-1) {
1852 uinfo
->value
.enumerated
.item
= kAudioChannels
-1;
1854 strcpy(uinfo
->value
.enumerated
.name
, channelName
[uinfo
->value
.enumerated
.item
]);
1858 static int snd_korg1212_control_route_get(struct snd_kcontrol
*kcontrol
,
1859 struct snd_ctl_elem_value
*u
)
1861 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1864 spin_lock_irq(&korg1212
->lock
);
1866 i
= kcontrol
->private_value
;
1867 u
->value
.enumerated
.item
[0] = korg1212
->sharedBufferPtr
->routeData
[i
];
1870 u
->value
.enumerated
.item
[1] = korg1212
->sharedBufferPtr
->routeData
[i
+1];
1872 spin_unlock_irq(&korg1212
->lock
);
1877 static int snd_korg1212_control_route_put(struct snd_kcontrol
*kcontrol
,
1878 struct snd_ctl_elem_value
*u
)
1880 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1883 spin_lock_irq(&korg1212
->lock
);
1885 i
= kcontrol
->private_value
;
1887 if (u
->value
.enumerated
.item
[0] != (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
]) {
1888 korg1212
->sharedBufferPtr
->routeData
[i
] = u
->value
.enumerated
.item
[0];
1893 if (u
->value
.enumerated
.item
[1] != (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
+1]) {
1894 korg1212
->sharedBufferPtr
->routeData
[i
+1] = u
->value
.enumerated
.item
[1];
1899 spin_unlock_irq(&korg1212
->lock
);
1904 static int snd_korg1212_control_info(struct snd_kcontrol
*kcontrol
,
1905 struct snd_ctl_elem_info
*uinfo
)
1907 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1909 uinfo
->value
.integer
.min
= k1212MaxADCSens
;
1910 uinfo
->value
.integer
.max
= k1212MinADCSens
;
1914 static int snd_korg1212_control_get(struct snd_kcontrol
*kcontrol
,
1915 struct snd_ctl_elem_value
*u
)
1917 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1919 spin_lock_irq(&korg1212
->lock
);
1921 u
->value
.integer
.value
[0] = korg1212
->leftADCInSens
;
1922 u
->value
.integer
.value
[1] = korg1212
->rightADCInSens
;
1924 spin_unlock_irq(&korg1212
->lock
);
1929 static int snd_korg1212_control_put(struct snd_kcontrol
*kcontrol
,
1930 struct snd_ctl_elem_value
*u
)
1932 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1935 spin_lock_irq(&korg1212
->lock
);
1937 if (u
->value
.integer
.value
[0] != korg1212
->leftADCInSens
) {
1938 korg1212
->leftADCInSens
= u
->value
.integer
.value
[0];
1941 if (u
->value
.integer
.value
[1] != korg1212
->rightADCInSens
) {
1942 korg1212
->rightADCInSens
= u
->value
.integer
.value
[1];
1946 spin_unlock_irq(&korg1212
->lock
);
1949 snd_korg1212_WriteADCSensitivity(korg1212
);
1954 static int snd_korg1212_control_sync_info(struct snd_kcontrol
*kcontrol
,
1955 struct snd_ctl_elem_info
*uinfo
)
1957 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1959 uinfo
->value
.enumerated
.items
= 3;
1960 if (uinfo
->value
.enumerated
.item
> 2) {
1961 uinfo
->value
.enumerated
.item
= 2;
1963 strcpy(uinfo
->value
.enumerated
.name
, clockSourceTypeName
[uinfo
->value
.enumerated
.item
]);
1967 static int snd_korg1212_control_sync_get(struct snd_kcontrol
*kcontrol
,
1968 struct snd_ctl_elem_value
*ucontrol
)
1970 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1972 spin_lock_irq(&korg1212
->lock
);
1974 ucontrol
->value
.enumerated
.item
[0] = korg1212
->clkSource
;
1976 spin_unlock_irq(&korg1212
->lock
);
1980 static int snd_korg1212_control_sync_put(struct snd_kcontrol
*kcontrol
,
1981 struct snd_ctl_elem_value
*ucontrol
)
1983 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1987 val
= ucontrol
->value
.enumerated
.item
[0] % 3;
1988 spin_lock_irq(&korg1212
->lock
);
1989 change
= val
!= korg1212
->clkSource
;
1990 snd_korg1212_SetClockSource(korg1212
, val
);
1991 spin_unlock_irq(&korg1212
->lock
);
1995 #define MON_MIXER(ord,c_name) \
1997 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
1998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1999 .name = c_name " Monitor Volume", \
2000 .info = snd_korg1212_control_volume_info, \
2001 .get = snd_korg1212_control_volume_get, \
2002 .put = snd_korg1212_control_volume_put, \
2003 .private_value = ord, \
2006 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
2007 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2008 .name = c_name " Monitor Route", \
2009 .info = snd_korg1212_control_route_info, \
2010 .get = snd_korg1212_control_route_get, \
2011 .put = snd_korg1212_control_route_put, \
2012 .private_value = ord, \
2015 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
2016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2017 .name = c_name " Monitor Phase Invert", \
2018 .info = snd_korg1212_control_phase_info, \
2019 .get = snd_korg1212_control_phase_get, \
2020 .put = snd_korg1212_control_phase_put, \
2021 .private_value = ord, \
2024 static struct snd_kcontrol_new snd_korg1212_controls
[] = {
2025 MON_MIXER(8, "Analog"),
2026 MON_MIXER(10, "SPDIF"),
2027 MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"),
2028 MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"),
2030 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
2031 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2032 .name
= "Sync Source",
2033 .info
= snd_korg1212_control_sync_info
,
2034 .get
= snd_korg1212_control_sync_get
,
2035 .put
= snd_korg1212_control_sync_put
,
2038 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
2039 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2040 .name
= "ADC Attenuation",
2041 .info
= snd_korg1212_control_info
,
2042 .get
= snd_korg1212_control_get
,
2043 .put
= snd_korg1212_control_put
,
2051 static void snd_korg1212_proc_read(struct snd_info_entry
*entry
,
2052 struct snd_info_buffer
*buffer
)
2055 struct snd_korg1212
*korg1212
= entry
->private_data
;
2057 snd_iprintf(buffer
, korg1212
->card
->longname
);
2058 snd_iprintf(buffer
, " (index #%d)\n", korg1212
->card
->number
+ 1);
2059 snd_iprintf(buffer
, "\nGeneral settings\n");
2060 snd_iprintf(buffer
, " period size: %Zd bytes\n", K1212_PERIOD_BYTES
);
2061 snd_iprintf(buffer
, " clock mode: %s\n", clockSourceName
[korg1212
->clkSrcRate
] );
2062 snd_iprintf(buffer
, " left ADC Sens: %d\n", korg1212
->leftADCInSens
);
2063 snd_iprintf(buffer
, " right ADC Sens: %d\n", korg1212
->rightADCInSens
);
2064 snd_iprintf(buffer
, " Volume Info:\n");
2065 for (n
=0; n
<kAudioChannels
; n
++)
2066 snd_iprintf(buffer
, " Channel %d: %s -> %s [%d]\n", n
,
2068 channelName
[korg1212
->sharedBufferPtr
->routeData
[n
]],
2069 korg1212
->sharedBufferPtr
->volumeData
[n
]);
2070 snd_iprintf(buffer
, "\nGeneral status\n");
2071 snd_iprintf(buffer
, " ADAT Time Code: %d\n", korg1212
->sharedBufferPtr
->AdatTimeCode
);
2072 snd_iprintf(buffer
, " Card State: %s\n", stateName
[korg1212
->cardState
]);
2073 snd_iprintf(buffer
, "Idle mon. State: %d\n", korg1212
->idleMonitorOn
);
2074 snd_iprintf(buffer
, "Cmd retry count: %d\n", korg1212
->cmdRetryCount
);
2075 snd_iprintf(buffer
, " Irq count: %ld\n", korg1212
->irqcount
);
2076 snd_iprintf(buffer
, " Error count: %ld\n", korg1212
->totalerrorcnt
);
2079 static void __devinit
snd_korg1212_proc_init(struct snd_korg1212
*korg1212
)
2081 struct snd_info_entry
*entry
;
2083 if (! snd_card_proc_new(korg1212
->card
, "korg1212", &entry
))
2084 snd_info_set_text_ops(entry
, korg1212
, snd_korg1212_proc_read
);
2088 snd_korg1212_free(struct snd_korg1212
*korg1212
)
2090 snd_korg1212_TurnOffIdleMonitor(korg1212
);
2092 if (korg1212
->irq
>= 0) {
2093 synchronize_irq(korg1212
->irq
);
2094 snd_korg1212_DisableCardInterrupts(korg1212
);
2095 free_irq(korg1212
->irq
, korg1212
);
2099 if (korg1212
->iobase
!= NULL
) {
2100 iounmap(korg1212
->iobase
);
2101 korg1212
->iobase
= NULL
;
2104 pci_release_regions(korg1212
->pci
);
2106 // ----------------------------------------------------
2107 // free up memory resources used for the DSP download.
2108 // ----------------------------------------------------
2109 if (korg1212
->dma_dsp
.area
) {
2110 snd_dma_free_pages(&korg1212
->dma_dsp
);
2111 korg1212
->dma_dsp
.area
= NULL
;
2114 #ifndef K1212_LARGEALLOC
2116 // ------------------------------------------------------
2117 // free up memory resources used for the Play/Rec Buffers
2118 // ------------------------------------------------------
2119 if (korg1212
->dma_play
.area
) {
2120 snd_dma_free_pages(&korg1212
->dma_play
);
2121 korg1212
->dma_play
.area
= NULL
;
2124 if (korg1212
->dma_rec
.area
) {
2125 snd_dma_free_pages(&korg1212
->dma_rec
);
2126 korg1212
->dma_rec
.area
= NULL
;
2131 // ----------------------------------------------------
2132 // free up memory resources used for the Shared Buffers
2133 // ----------------------------------------------------
2134 if (korg1212
->dma_shared
.area
) {
2135 snd_dma_free_pages(&korg1212
->dma_shared
);
2136 korg1212
->dma_shared
.area
= NULL
;
2139 pci_disable_device(korg1212
->pci
);
2144 static int snd_korg1212_dev_free(struct snd_device
*device
)
2146 struct snd_korg1212
*korg1212
= device
->device_data
;
2147 K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n");
2148 return snd_korg1212_free(korg1212
);
2151 static int __devinit
snd_korg1212_create(struct snd_card
*card
, struct pci_dev
*pci
,
2152 struct snd_korg1212
** rchip
)
2157 unsigned ioport_size
, iomem_size
, iomem2_size
;
2158 struct snd_korg1212
* korg1212
;
2160 static struct snd_device_ops ops
= {
2161 .dev_free
= snd_korg1212_dev_free
,
2165 if ((err
= pci_enable_device(pci
)) < 0)
2168 korg1212
= kzalloc(sizeof(*korg1212
), GFP_KERNEL
);
2169 if (korg1212
== NULL
) {
2170 pci_disable_device(pci
);
2174 korg1212
->card
= card
;
2175 korg1212
->pci
= pci
;
2177 init_waitqueue_head(&korg1212
->wait
);
2178 spin_lock_init(&korg1212
->lock
);
2179 mutex_init(&korg1212
->open_mutex
);
2180 init_timer(&korg1212
->timer
);
2181 korg1212
->timer
.function
= snd_korg1212_timer_func
;
2182 korg1212
->timer
.data
= (unsigned long)korg1212
;
2185 korg1212
->clkSource
= K1212_CLKIDX_Local
;
2186 korg1212
->clkRate
= 44100;
2187 korg1212
->inIRQ
= 0;
2188 korg1212
->running
= 0;
2189 korg1212
->opencnt
= 0;
2190 korg1212
->playcnt
= 0;
2191 korg1212
->setcnt
= 0;
2192 korg1212
->totalerrorcnt
= 0;
2193 korg1212
->playback_pid
= -1;
2194 korg1212
->capture_pid
= -1;
2195 snd_korg1212_setCardState(korg1212
, K1212_STATE_UNINITIALIZED
);
2196 korg1212
->idleMonitorOn
= 0;
2197 korg1212
->clkSrcRate
= K1212_CLKIDX_LocalAt44_1K
;
2198 korg1212
->leftADCInSens
= k1212MaxADCSens
;
2199 korg1212
->rightADCInSens
= k1212MaxADCSens
;
2201 for (i
=0; i
<kAudioChannels
; i
++)
2202 korg1212
->volumePhase
[i
] = 0;
2204 if ((err
= pci_request_regions(pci
, "korg1212")) < 0) {
2206 pci_disable_device(pci
);
2210 korg1212
->iomem
= pci_resource_start(korg1212
->pci
, 0);
2211 korg1212
->ioport
= pci_resource_start(korg1212
->pci
, 1);
2212 korg1212
->iomem2
= pci_resource_start(korg1212
->pci
, 2);
2214 iomem_size
= pci_resource_len(korg1212
->pci
, 0);
2215 ioport_size
= pci_resource_len(korg1212
->pci
, 1);
2216 iomem2_size
= pci_resource_len(korg1212
->pci
, 2);
2218 K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n"
2219 " iomem = 0x%lx (%d)\n"
2220 " ioport = 0x%lx (%d)\n"
2221 " iomem = 0x%lx (%d)\n"
2223 korg1212
->iomem
, iomem_size
,
2224 korg1212
->ioport
, ioport_size
,
2225 korg1212
->iomem2
, iomem2_size
,
2226 stateName
[korg1212
->cardState
]);
2228 if ((korg1212
->iobase
= ioremap(korg1212
->iomem
, iomem_size
)) == NULL
) {
2229 snd_printk(KERN_ERR
"korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212
->iomem
,
2230 korg1212
->iomem
+ iomem_size
- 1);
2231 snd_korg1212_free(korg1212
);
2235 err
= request_irq(pci
->irq
, snd_korg1212_interrupt
,
2237 "korg1212", korg1212
);
2240 snd_printk(KERN_ERR
"korg1212: unable to grab IRQ %d\n", pci
->irq
);
2241 snd_korg1212_free(korg1212
);
2245 korg1212
->irq
= pci
->irq
;
2247 pci_set_master(korg1212
->pci
);
2249 korg1212
->statusRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ STATUS_REG_OFFSET
);
2250 korg1212
->outDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ OUT_DOORBELL_OFFSET
);
2251 korg1212
->inDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ IN_DOORBELL_OFFSET
);
2252 korg1212
->mailbox0Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX0_OFFSET
);
2253 korg1212
->mailbox1Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX1_OFFSET
);
2254 korg1212
->mailbox2Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX2_OFFSET
);
2255 korg1212
->mailbox3Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX3_OFFSET
);
2256 korg1212
->controlRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ PCI_CONTROL_OFFSET
);
2257 korg1212
->sensRegPtr
= (u16 __iomem
*) (korg1212
->iobase
+ SENS_CONTROL_OFFSET
);
2258 korg1212
->idRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ DEV_VEND_ID_OFFSET
);
2260 K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n"
2261 " Status register = 0x%p\n"
2262 " OutDoorbell = 0x%p\n"
2263 " InDoorbell = 0x%p\n"
2264 " Mailbox0 = 0x%p\n"
2265 " Mailbox1 = 0x%p\n"
2266 " Mailbox2 = 0x%p\n"
2267 " Mailbox3 = 0x%p\n"
2268 " ControlReg = 0x%p\n"
2272 korg1212
->statusRegPtr
,
2273 korg1212
->outDoorbellPtr
,
2274 korg1212
->inDoorbellPtr
,
2275 korg1212
->mailbox0Ptr
,
2276 korg1212
->mailbox1Ptr
,
2277 korg1212
->mailbox2Ptr
,
2278 korg1212
->mailbox3Ptr
,
2279 korg1212
->controlRegPtr
,
2280 korg1212
->sensRegPtr
,
2282 stateName
[korg1212
->cardState
]);
2284 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2285 sizeof(struct KorgSharedBuffer
), &korg1212
->dma_shared
) < 0) {
2286 snd_printk(KERN_ERR
"korg1212: can not allocate shared buffer memory (%Zd bytes)\n", sizeof(struct KorgSharedBuffer
));
2287 snd_korg1212_free(korg1212
);
2290 korg1212
->sharedBufferPtr
= (struct KorgSharedBuffer
*)korg1212
->dma_shared
.area
;
2291 korg1212
->sharedBufferPhy
= korg1212
->dma_shared
.addr
;
2293 K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212
->sharedBufferPtr
, korg1212
->sharedBufferPhy
, sizeof(struct KorgSharedBuffer
));
2295 #ifndef K1212_LARGEALLOC
2297 korg1212
->DataBufsSize
= sizeof(struct KorgAudioBuffer
) * kNumBuffers
;
2299 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2300 korg1212
->DataBufsSize
, &korg1212
->dma_play
) < 0) {
2301 snd_printk(KERN_ERR
"korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2302 snd_korg1212_free(korg1212
);
2305 korg1212
->playDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_play
.area
;
2306 korg1212
->PlayDataPhy
= korg1212
->dma_play
.addr
;
2308 K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n",
2309 korg1212
->playDataBufsPtr
, korg1212
->PlayDataPhy
, korg1212
->DataBufsSize
);
2311 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2312 korg1212
->DataBufsSize
, &korg1212
->dma_rec
) < 0) {
2313 snd_printk(KERN_ERR
"korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2314 snd_korg1212_free(korg1212
);
2317 korg1212
->recordDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_rec
.area
;
2318 korg1212
->RecDataPhy
= korg1212
->dma_rec
.addr
;
2320 K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n",
2321 korg1212
->recordDataBufsPtr
, korg1212
->RecDataPhy
, korg1212
->DataBufsSize
);
2323 #else // K1212_LARGEALLOC
2325 korg1212
->recordDataBufsPtr
= korg1212
->sharedBufferPtr
->recordDataBufs
;
2326 korg1212
->playDataBufsPtr
= korg1212
->sharedBufferPtr
->playDataBufs
;
2327 korg1212
->PlayDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->playDataBufs
;
2328 korg1212
->RecDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->recordDataBufs
;
2330 #endif // K1212_LARGEALLOC
2332 korg1212
->dspCodeSize
= sizeof (dspCode
);
2334 korg1212
->VolumeTablePhy
= korg1212
->sharedBufferPhy
+
2335 offsetof(struct KorgSharedBuffer
, volumeData
);
2336 korg1212
->RoutingTablePhy
= korg1212
->sharedBufferPhy
+
2337 offsetof(struct KorgSharedBuffer
, routeData
);
2338 korg1212
->AdatTimeCodePhy
= korg1212
->sharedBufferPhy
+
2339 offsetof(struct KorgSharedBuffer
, AdatTimeCode
);
2341 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2342 korg1212
->dspCodeSize
, &korg1212
->dma_dsp
) < 0) {
2343 snd_printk(KERN_ERR
"korg1212: can not allocate dsp code memory (%d bytes)\n", korg1212
->dspCodeSize
);
2344 snd_korg1212_free(korg1212
);
2348 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n",
2349 korg1212
->dma_dsp
.area
, korg1212
->dma_dsp
.addr
, korg1212
->dspCodeSize
,
2350 stateName
[korg1212
->cardState
]);
2352 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_RebootCard
, 0, 0, 0, 0);
2355 K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc
, stateName
[korg1212
->cardState
]);
2357 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, korg1212
, &ops
)) < 0) {
2358 snd_korg1212_free(korg1212
);
2362 snd_korg1212_EnableCardInterrupts(korg1212
);
2364 mdelay(CARD_BOOT_DELAY_IN_MS
);
2366 if (snd_korg1212_downloadDSPCode(korg1212
))
2369 K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], "
2370 "PlayDataPhy = %08x L[%08x]\n"
2371 "korg1212: RecDataPhy = %08x L[%08x], "
2372 "VolumeTablePhy = %08x L[%08x]\n"
2373 "korg1212: RoutingTablePhy = %08x L[%08x], "
2374 "AdatTimeCodePhy = %08x L[%08x]\n",
2375 (int)korg1212
->dma_dsp
.addr
, UpperWordSwap(korg1212
->dma_dsp
.addr
),
2376 korg1212
->PlayDataPhy
, LowerWordSwap(korg1212
->PlayDataPhy
),
2377 korg1212
->RecDataPhy
, LowerWordSwap(korg1212
->RecDataPhy
),
2378 korg1212
->VolumeTablePhy
, LowerWordSwap(korg1212
->VolumeTablePhy
),
2379 korg1212
->RoutingTablePhy
, LowerWordSwap(korg1212
->RoutingTablePhy
),
2380 korg1212
->AdatTimeCodePhy
, LowerWordSwap(korg1212
->AdatTimeCodePhy
));
2382 if ((err
= snd_pcm_new(korg1212
->card
, "korg1212", 0, 1, 1, &korg1212
->pcm
)) < 0)
2385 korg1212
->pcm
->private_data
= korg1212
;
2386 korg1212
->pcm
->private_free
= snd_korg1212_free_pcm
;
2387 strcpy(korg1212
->pcm
->name
, "korg1212");
2389 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_korg1212_playback_ops
);
2391 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_korg1212_capture_ops
);
2393 korg1212
->pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
2395 for (i
= 0; i
< ARRAY_SIZE(snd_korg1212_controls
); i
++) {
2396 err
= snd_ctl_add(korg1212
->card
, snd_ctl_new1(&snd_korg1212_controls
[i
], korg1212
));
2401 snd_korg1212_proc_init(korg1212
);
2403 snd_card_set_dev(card
, &pci
->dev
);
2411 * Card initialisation
2414 static int __devinit
2415 snd_korg1212_probe(struct pci_dev
*pci
,
2416 const struct pci_device_id
*pci_id
)
2419 struct snd_korg1212
*korg1212
;
2420 struct snd_card
*card
;
2423 if (dev
>= SNDRV_CARDS
) {
2430 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2434 if ((err
= snd_korg1212_create(card
, pci
, &korg1212
)) < 0) {
2435 snd_card_free(card
);
2439 strcpy(card
->driver
, "korg1212");
2440 strcpy(card
->shortname
, "korg1212");
2441 sprintf(card
->longname
, "%s at 0x%lx, irq %d", card
->shortname
,
2442 korg1212
->iomem
, korg1212
->irq
);
2444 K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card
->longname
);
2446 if ((err
= snd_card_register(card
)) < 0) {
2447 snd_card_free(card
);
2450 pci_set_drvdata(pci
, card
);
2455 static void __devexit
snd_korg1212_remove(struct pci_dev
*pci
)
2457 snd_card_free(pci_get_drvdata(pci
));
2458 pci_set_drvdata(pci
, NULL
);
2461 static struct pci_driver driver
= {
2463 .id_table
= snd_korg1212_ids
,
2464 .probe
= snd_korg1212_probe
,
2465 .remove
= __devexit_p(snd_korg1212_remove
),
2468 static int __init
alsa_card_korg1212_init(void)
2470 return pci_register_driver(&driver
);
2473 static void __exit
alsa_card_korg1212_exit(void)
2475 pci_unregister_driver(&driver
);
2478 module_init(alsa_card_korg1212_init
)
2479 module_exit(alsa_card_korg1212_exit
)