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 <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/wait.h>
28 #include <linux/moduleparam.h>
29 #include <linux/mutex.h>
30 #include <linux/firmware.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 MAX_COMMAND_RETRIES 5 // maximum number of times the driver will attempt
166 // to send a command before giving up.
167 #define COMMAND_ACK_MASK 0x8000 // the MSB is set in the command acknowledgment from
169 #define DOORBELL_VAL_MASK 0x00FF // the doorbell value is one byte
171 #define CARD_BOOT_DELAY_IN_MS 10
172 #define CARD_BOOT_TIMEOUT 10
173 #define DSP_BOOT_DELAY_IN_MS 200
175 #define kNumBuffers 8
176 #define k1212MaxCards 4
177 #define k1212NumWaveDevices 6
178 #define k16BitChannels 10
179 #define k32BitChannels 2
180 #define kAudioChannels (k16BitChannels + k32BitChannels)
181 #define kPlayBufferFrames 1024
183 #define K1212_ANALOG_CHANNELS 2
184 #define K1212_SPDIF_CHANNELS 2
185 #define K1212_ADAT_CHANNELS 8
186 #define K1212_CHANNELS (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS)
187 #define K1212_MIN_CHANNELS 1
188 #define K1212_MAX_CHANNELS K1212_CHANNELS
189 #define K1212_FRAME_SIZE (sizeof(struct KorgAudioFrame))
190 #define K1212_MAX_SAMPLES (kPlayBufferFrames*kNumBuffers)
191 #define K1212_PERIODS (kNumBuffers)
192 #define K1212_PERIOD_BYTES (K1212_FRAME_SIZE*kPlayBufferFrames)
193 #define K1212_BUF_SIZE (K1212_PERIOD_BYTES*kNumBuffers)
194 #define K1212_ANALOG_BUF_SIZE (K1212_ANALOG_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
195 #define K1212_SPDIF_BUF_SIZE (K1212_SPDIF_CHANNELS * 3 * kPlayBufferFrames * kNumBuffers)
196 #define K1212_ADAT_BUF_SIZE (K1212_ADAT_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
197 #define K1212_MAX_BUF_SIZE (K1212_ANALOG_BUF_SIZE + K1212_ADAT_BUF_SIZE)
199 #define k1212MinADCSens 0x7f
200 #define k1212MaxADCSens 0x00
201 #define k1212MaxVolume 0x7fff
202 #define k1212MaxWaveVolume 0xffff
203 #define k1212MinVolume 0x0000
204 #define k1212MaxVolInverted 0x8000
206 // -----------------------------------------------------------------
207 // the following bits are used for controlling interrupts in the
208 // interrupt control/status reg
209 // -----------------------------------------------------------------
210 #define PCI_INT_ENABLE_BIT 0x00000100
211 #define PCI_DOORBELL_INT_ENABLE_BIT 0x00000200
212 #define LOCAL_INT_ENABLE_BIT 0x00010000
213 #define LOCAL_DOORBELL_INT_ENABLE_BIT 0x00020000
214 #define LOCAL_DMA1_INT_ENABLE_BIT 0x00080000
216 // -----------------------------------------------------------------
217 // the following bits are defined for the PCI command register
218 // -----------------------------------------------------------------
219 #define PCI_CMD_MEM_SPACE_ENABLE_BIT 0x0002
220 #define PCI_CMD_IO_SPACE_ENABLE_BIT 0x0001
221 #define PCI_CMD_BUS_MASTER_ENABLE_BIT 0x0004
223 // -----------------------------------------------------------------
224 // the following bits are defined for the PCI status register
225 // -----------------------------------------------------------------
226 #define PCI_STAT_PARITY_ERROR_BIT 0x8000
227 #define PCI_STAT_SYSTEM_ERROR_BIT 0x4000
228 #define PCI_STAT_MASTER_ABORT_RCVD_BIT 0x2000
229 #define PCI_STAT_TARGET_ABORT_RCVD_BIT 0x1000
230 #define PCI_STAT_TARGET_ABORT_SENT_BIT 0x0800
232 // ------------------------------------------------------------------------
233 // the following constants are used in setting the 1212 I/O card's input
235 // ------------------------------------------------------------------------
236 #define SET_SENS_LOCALINIT_BITPOS 15
237 #define SET_SENS_DATA_BITPOS 10
238 #define SET_SENS_CLOCK_BITPOS 8
239 #define SET_SENS_LOADSHIFT_BITPOS 0
241 #define SET_SENS_LEFTCHANID 0x00
242 #define SET_SENS_RIGHTCHANID 0x01
244 #define K1212SENSUPDATE_DELAY_IN_MS 50
246 // --------------------------------------------------------------------------
249 // This function waits the specified number of real time clock ticks.
250 // According to the DDK, each tick is ~0.8 microseconds.
251 // The defines following the function declaration can be used for the
252 // numTicksToWait parameter.
253 // --------------------------------------------------------------------------
254 #define ONE_RTC_TICK 1
255 #define SENSCLKPULSE_WIDTH 4
256 #define LOADSHIFT_DELAY 4
257 #define INTERCOMMAND_DELAY 40
258 #define STOPCARD_DELAY 300 // max # RTC ticks for the card to stop once we write
259 // the command register. (could be up to 180 us)
260 #define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement
261 // from the card after sending a command.
263 enum ClockSourceIndex
{
264 K1212_CLKIDX_AdatAt44_1K
= 0, // selects source as ADAT at 44.1 kHz
265 K1212_CLKIDX_AdatAt48K
, // selects source as ADAT at 48 kHz
266 K1212_CLKIDX_WordAt44_1K
, // selects source as S/PDIF at 44.1 kHz
267 K1212_CLKIDX_WordAt48K
, // selects source as S/PDIF at 48 kHz
268 K1212_CLKIDX_LocalAt44_1K
, // selects source as local clock at 44.1 kHz
269 K1212_CLKIDX_LocalAt48K
, // selects source as local clock at 48 kHz
270 K1212_CLKIDX_Invalid
// used to check validity of the index
273 enum ClockSourceType
{
274 K1212_CLKIDX_Adat
= 0, // selects source as ADAT
275 K1212_CLKIDX_Word
, // selects source as S/PDIF
276 K1212_CLKIDX_Local
// selects source as local clock
279 struct KorgAudioFrame
{
280 u16 frameData16
[k16BitChannels
]; /* channels 0-9 use 16 bit samples */
281 u32 frameData32
[k32BitChannels
]; /* channels 10-11 use 32 bits - only 20 are sent across S/PDIF */
282 u32 timeCodeVal
; /* holds the ADAT timecode value */
285 struct KorgAudioBuffer
{
286 struct KorgAudioFrame bufferData
[kPlayBufferFrames
]; /* buffer definition */
289 struct KorgSharedBuffer
{
290 #ifdef K1212_LARGEALLOC
291 struct KorgAudioBuffer playDataBufs
[kNumBuffers
];
292 struct KorgAudioBuffer recordDataBufs
[kNumBuffers
];
294 short volumeData
[kAudioChannels
];
296 u16 routeData
[kAudioChannels
];
297 u32 AdatTimeCode
; // ADAT timecode value
303 unsigned int leftChanVal
:8;
304 unsigned int leftChanId
:8;
310 unsigned int rightChanVal
:8;
311 unsigned int rightChanId
:8;
317 struct snd_korg1212
{
318 struct snd_card
*card
;
324 struct mutex open_mutex
;
326 struct timer_list timer
; /* timer callback for checking ack of stop request */
327 int stop_pending_cnt
; /* counter for stop pending check */
329 wait_queue_head_t wait
;
332 unsigned long ioport
;
333 unsigned long iomem2
;
334 unsigned long irqcount
;
336 void __iomem
*iobase
;
338 struct snd_dma_buffer dma_dsp
;
339 struct snd_dma_buffer dma_play
;
340 struct snd_dma_buffer dma_rec
;
341 struct snd_dma_buffer dma_shared
;
345 struct KorgAudioBuffer
* playDataBufsPtr
;
346 struct KorgAudioBuffer
* recordDataBufsPtr
;
348 struct KorgSharedBuffer
* sharedBufferPtr
;
352 unsigned long sharedBufferPhy
;
357 u32 __iomem
* statusRegPtr
; // address of the interrupt status/control register
358 u32 __iomem
* outDoorbellPtr
; // address of the host->card doorbell register
359 u32 __iomem
* inDoorbellPtr
; // address of the card->host doorbell register
360 u32 __iomem
* mailbox0Ptr
; // address of mailbox 0 on the card
361 u32 __iomem
* mailbox1Ptr
; // address of mailbox 1 on the card
362 u32 __iomem
* mailbox2Ptr
; // address of mailbox 2 on the card
363 u32 __iomem
* mailbox3Ptr
; // address of mailbox 3 on the card
364 u32 __iomem
* controlRegPtr
; // address of the EEPROM, PCI, I/O, Init ctrl reg
365 u16 __iomem
* sensRegPtr
; // address of the sensitivity setting register
366 u32 __iomem
* idRegPtr
; // address of the device and vendor ID registers
372 struct snd_pcm_substream
*playback_substream
;
373 struct snd_pcm_substream
*capture_substream
;
378 enum CardState cardState
;
380 int idleMonitorOn
; // indicates whether the card is in idle monitor mode.
381 u32 cmdRetryCount
; // tracks how many times we have retried sending to the card.
383 enum ClockSourceIndex clkSrcRate
; // sample rate and clock source
385 enum ClockSourceType clkSource
; // clock source
386 int clkRate
; // clock rate
388 int volumePhase
[kAudioChannels
];
390 u16 leftADCInSens
; // ADC left channel input sensitivity
391 u16 rightADCInSens
; // ADC right channel input sensitivity
393 int opencnt
; // Open/Close count
394 int setcnt
; // SetupForPlay count
395 int playcnt
; // TriggerPlay count
396 int errorcnt
; // Error Count
397 unsigned long totalerrorcnt
; // Total Error Count
400 int dsp_stop_is_processed
;
404 MODULE_DESCRIPTION("korg1212");
405 MODULE_LICENSE("GPL");
406 MODULE_SUPPORTED_DEVICE("{{KORG,korg1212}}");
407 MODULE_FIRMWARE("korg/k1212.dsp");
409 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
410 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
411 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
; /* Enable this card */
413 module_param_array(index
, int, NULL
, 0444);
414 MODULE_PARM_DESC(index
, "Index value for Korg 1212 soundcard.");
415 module_param_array(id
, charp
, NULL
, 0444);
416 MODULE_PARM_DESC(id
, "ID string for Korg 1212 soundcard.");
417 module_param_array(enable
, bool, NULL
, 0444);
418 MODULE_PARM_DESC(enable
, "Enable Korg 1212 soundcard.");
419 MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>");
421 static DEFINE_PCI_DEVICE_TABLE(snd_korg1212_ids
) = {
425 .subvendor
= PCI_ANY_ID
,
426 .subdevice
= PCI_ANY_ID
,
431 MODULE_DEVICE_TABLE(pci
, snd_korg1212_ids
);
433 static char *stateName
[] = {
436 "DSP download in process",
437 "DSP download complete",
447 static char *clockSourceTypeName
[] = { "ADAT", "S/PDIF", "local" };
449 static char *clockSourceName
[] = {
452 "S/PDIF at 44.1 kHz",
454 "local clock at 44.1 kHz",
455 "local clock at 48 kHz"
458 static char *channelName
[] = {
473 static u16 ClockSourceSelector
[] = {
474 0x8000, // selects source as ADAT at 44.1 kHz
475 0x0000, // selects source as ADAT at 48 kHz
476 0x8001, // selects source as S/PDIF at 44.1 kHz
477 0x0001, // selects source as S/PDIF at 48 kHz
478 0x8002, // selects source as local clock at 44.1 kHz
479 0x0002 // selects source as local clock at 48 kHz
482 union swap_u32
{ unsigned char c
[4]; u32 i
; };
484 #ifdef SNDRV_BIG_ENDIAN
485 static u32
LowerWordSwap(u32 swappee
)
487 static u32
UpperWordSwap(u32 swappee
)
490 union swap_u32 retVal
, swapper
;
493 retVal
.c
[2] = swapper
.c
[3];
494 retVal
.c
[3] = swapper
.c
[2];
495 retVal
.c
[1] = swapper
.c
[1];
496 retVal
.c
[0] = swapper
.c
[0];
501 #ifdef SNDRV_BIG_ENDIAN
502 static u32
UpperWordSwap(u32 swappee
)
504 static u32
LowerWordSwap(u32 swappee
)
507 union swap_u32 retVal
, swapper
;
510 retVal
.c
[2] = swapper
.c
[2];
511 retVal
.c
[3] = swapper
.c
[3];
512 retVal
.c
[1] = swapper
.c
[0];
513 retVal
.c
[0] = swapper
.c
[1];
518 #define SetBitInWord(theWord,bitPosition) (*theWord) |= (0x0001 << bitPosition)
519 #define SetBitInDWord(theWord,bitPosition) (*theWord) |= (0x00000001 << bitPosition)
520 #define ClearBitInWord(theWord,bitPosition) (*theWord) &= ~(0x0001 << bitPosition)
521 #define ClearBitInDWord(theWord,bitPosition) (*theWord) &= ~(0x00000001 << bitPosition)
523 static int snd_korg1212_Send1212Command(struct snd_korg1212
*korg1212
,
524 enum korg1212_dbcnst doorbellVal
,
525 u32 mailBox0Val
, u32 mailBox1Val
,
526 u32 mailBox2Val
, u32 mailBox3Val
)
530 int rc
= K1212_CMDRET_Success
;
532 if (!korg1212
->outDoorbellPtr
) {
533 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: CardUninitialized\n");
534 return K1212_CMDRET_CardUninitialized
;
537 K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n",
538 doorbellVal
, mailBox0Val
, stateName
[korg1212
->cardState
]);
539 for (retryCount
= 0; retryCount
< MAX_COMMAND_RETRIES
; retryCount
++) {
540 writel(mailBox3Val
, korg1212
->mailbox3Ptr
);
541 writel(mailBox2Val
, korg1212
->mailbox2Ptr
);
542 writel(mailBox1Val
, korg1212
->mailbox1Ptr
);
543 writel(mailBox0Val
, korg1212
->mailbox0Ptr
);
544 writel(doorbellVal
, korg1212
->outDoorbellPtr
); // interrupt the card
546 // --------------------------------------------------------------
547 // the reboot command will not give an acknowledgement.
548 // --------------------------------------------------------------
549 if ( doorbellVal
== K1212_DB_RebootCard
||
550 doorbellVal
== K1212_DB_BootFromDSPPage4
||
551 doorbellVal
== K1212_DB_StartDSPDownload
) {
552 rc
= K1212_CMDRET_Success
;
556 // --------------------------------------------------------------
557 // See if the card acknowledged the command. Wait a bit, then
558 // read in the low word of mailbox3. If the MSB is set and the
559 // low byte is equal to the doorbell value, then it ack'd.
560 // --------------------------------------------------------------
561 udelay(COMMAND_ACK_DELAY
);
562 mailBox3Lo
= readl(korg1212
->mailbox3Ptr
);
563 if (mailBox3Lo
& COMMAND_ACK_MASK
) {
564 if ((mailBox3Lo
& DOORBELL_VAL_MASK
) == (doorbellVal
& DOORBELL_VAL_MASK
)) {
565 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- Success\n");
566 rc
= K1212_CMDRET_Success
;
571 korg1212
->cmdRetryCount
+= retryCount
;
573 if (retryCount
>= MAX_COMMAND_RETRIES
) {
574 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- NoAckFromCard\n");
575 rc
= K1212_CMDRET_NoAckFromCard
;
581 /* spinlock already held */
582 static void snd_korg1212_SendStop(struct snd_korg1212
*korg1212
)
584 if (! korg1212
->stop_pending_cnt
) {
585 korg1212
->sharedBufferPtr
->cardCommand
= 0xffffffff;
586 /* program the timer */
587 korg1212
->stop_pending_cnt
= HZ
;
588 korg1212
->timer
.expires
= jiffies
+ 1;
589 add_timer(&korg1212
->timer
);
593 static void snd_korg1212_SendStopAndWait(struct snd_korg1212
*korg1212
)
596 spin_lock_irqsave(&korg1212
->lock
, flags
);
597 korg1212
->dsp_stop_is_processed
= 0;
598 snd_korg1212_SendStop(korg1212
);
599 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
600 wait_event_timeout(korg1212
->wait
, korg1212
->dsp_stop_is_processed
, (HZ
* 3) / 2);
603 /* timer callback for checking the ack of stop request */
604 static void snd_korg1212_timer_func(unsigned long data
)
606 struct snd_korg1212
*korg1212
= (struct snd_korg1212
*) data
;
609 spin_lock_irqsave(&korg1212
->lock
, flags
);
610 if (korg1212
->sharedBufferPtr
->cardCommand
== 0) {
612 korg1212
->stop_pending_cnt
= 0;
613 korg1212
->dsp_stop_is_processed
= 1;
614 wake_up(&korg1212
->wait
);
615 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Stop ack'ed [%s]\n",
616 stateName
[korg1212
->cardState
]);
618 if (--korg1212
->stop_pending_cnt
> 0) {
619 /* reprogram timer */
620 korg1212
->timer
.expires
= jiffies
+ 1;
621 add_timer(&korg1212
->timer
);
623 snd_printd("korg1212_timer_func timeout\n");
624 korg1212
->sharedBufferPtr
->cardCommand
= 0;
625 korg1212
->dsp_stop_is_processed
= 1;
626 wake_up(&korg1212
->wait
);
627 K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n",
628 stateName
[korg1212
->cardState
]);
631 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
634 static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212
*korg1212
)
639 udelay(INTERCOMMAND_DELAY
);
640 spin_lock_irqsave(&korg1212
->lock
, flags
);
641 korg1212
->idleMonitorOn
= 1;
642 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
643 K1212_MODE_MonitorOn
, 0, 0, 0);
644 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
648 static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212
*korg1212
)
650 if (korg1212
->idleMonitorOn
) {
651 snd_korg1212_SendStopAndWait(korg1212
);
652 korg1212
->idleMonitorOn
= 0;
656 static inline void snd_korg1212_setCardState(struct snd_korg1212
* korg1212
, enum CardState csState
)
658 korg1212
->cardState
= csState
;
661 static int snd_korg1212_OpenCard(struct snd_korg1212
* korg1212
)
663 K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n",
664 stateName
[korg1212
->cardState
], korg1212
->opencnt
);
665 mutex_lock(&korg1212
->open_mutex
);
666 if (korg1212
->opencnt
++ == 0) {
667 snd_korg1212_TurnOffIdleMonitor(korg1212
);
668 snd_korg1212_setCardState(korg1212
, K1212_STATE_OPEN
);
671 mutex_unlock(&korg1212
->open_mutex
);
675 static int snd_korg1212_CloseCard(struct snd_korg1212
* korg1212
)
677 K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n",
678 stateName
[korg1212
->cardState
], korg1212
->opencnt
);
680 mutex_lock(&korg1212
->open_mutex
);
681 if (--(korg1212
->opencnt
)) {
682 mutex_unlock(&korg1212
->open_mutex
);
686 if (korg1212
->cardState
== K1212_STATE_SETUP
) {
687 int rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
688 K1212_MODE_StopPlay
, 0, 0, 0);
690 K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n",
691 rc
, stateName
[korg1212
->cardState
]);
692 if (rc
!= K1212_CMDRET_Success
) {
693 mutex_unlock(&korg1212
->open_mutex
);
696 } else if (korg1212
->cardState
> K1212_STATE_SETUP
) {
697 snd_korg1212_SendStopAndWait(korg1212
);
700 if (korg1212
->cardState
> K1212_STATE_READY
) {
701 snd_korg1212_TurnOnIdleMonitor(korg1212
);
702 snd_korg1212_setCardState(korg1212
, K1212_STATE_READY
);
705 mutex_unlock(&korg1212
->open_mutex
);
709 /* spinlock already held */
710 static int snd_korg1212_SetupForPlay(struct snd_korg1212
* korg1212
)
714 K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n",
715 stateName
[korg1212
->cardState
], korg1212
->setcnt
);
717 if (korg1212
->setcnt
++)
720 snd_korg1212_setCardState(korg1212
, K1212_STATE_SETUP
);
721 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
722 K1212_MODE_SetupPlay
, 0, 0, 0);
724 K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n",
725 rc
, stateName
[korg1212
->cardState
]);
726 if (rc
!= K1212_CMDRET_Success
) {
732 /* spinlock already held */
733 static int snd_korg1212_TriggerPlay(struct snd_korg1212
* korg1212
)
737 K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n",
738 stateName
[korg1212
->cardState
], korg1212
->playcnt
);
740 if (korg1212
->playcnt
++)
743 snd_korg1212_setCardState(korg1212
, K1212_STATE_PLAYING
);
744 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_TriggerPlay
, 0, 0, 0, 0);
746 K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n",
747 rc
, stateName
[korg1212
->cardState
]);
748 if (rc
!= K1212_CMDRET_Success
) {
754 /* spinlock already held */
755 static int snd_korg1212_StopPlay(struct snd_korg1212
* korg1212
)
757 K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n",
758 stateName
[korg1212
->cardState
], korg1212
->playcnt
);
760 if (--(korg1212
->playcnt
))
763 korg1212
->setcnt
= 0;
765 if (korg1212
->cardState
!= K1212_STATE_ERRORSTOP
)
766 snd_korg1212_SendStop(korg1212
);
768 snd_korg1212_setCardState(korg1212
, K1212_STATE_OPEN
);
772 static void snd_korg1212_EnableCardInterrupts(struct snd_korg1212
* korg1212
)
774 writel(PCI_INT_ENABLE_BIT
|
775 PCI_DOORBELL_INT_ENABLE_BIT
|
776 LOCAL_INT_ENABLE_BIT
|
777 LOCAL_DOORBELL_INT_ENABLE_BIT
|
778 LOCAL_DMA1_INT_ENABLE_BIT
,
779 korg1212
->statusRegPtr
);
783 static inline int snd_korg1212_use_is_exclusive(struct snd_korg1212
*korg1212
)
785 if (korg1212
->playback_pid
!= korg1212
->capture_pid
&&
786 korg1212
->playback_pid
>= 0 && korg1212
->capture_pid
>= 0)
792 static int snd_korg1212_SetRate(struct snd_korg1212
*korg1212
, int rate
)
794 static enum ClockSourceIndex s44
[] = {
795 K1212_CLKIDX_AdatAt44_1K
,
796 K1212_CLKIDX_WordAt44_1K
,
797 K1212_CLKIDX_LocalAt44_1K
799 static enum ClockSourceIndex s48
[] = {
800 K1212_CLKIDX_AdatAt48K
,
801 K1212_CLKIDX_WordAt48K
,
802 K1212_CLKIDX_LocalAt48K
806 if (!snd_korg1212_use_is_exclusive (korg1212
))
811 parm
= s44
[korg1212
->clkSource
];
815 parm
= s48
[korg1212
->clkSource
];
822 korg1212
->clkSrcRate
= parm
;
823 korg1212
->clkRate
= rate
;
825 udelay(INTERCOMMAND_DELAY
);
826 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SetClockSourceRate
,
827 ClockSourceSelector
[korg1212
->clkSrcRate
],
830 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n",
831 rc
, stateName
[korg1212
->cardState
]);
836 static int snd_korg1212_SetClockSource(struct snd_korg1212
*korg1212
, int source
)
839 if (source
< 0 || source
> 2)
842 korg1212
->clkSource
= source
;
844 snd_korg1212_SetRate(korg1212
, korg1212
->clkRate
);
849 static void snd_korg1212_DisableCardInterrupts(struct snd_korg1212
*korg1212
)
851 writel(0, korg1212
->statusRegPtr
);
854 static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212
*korg1212
)
856 struct SensBits sensVals
;
861 u16 controlValue
; // this keeps the current value to be written to
862 // the card's eeprom control register.
866 K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n",
867 stateName
[korg1212
->cardState
]);
869 // ----------------------------------------------------------------------------
870 // initialize things. The local init bit is always set when writing to the
871 // card's control register.
872 // ----------------------------------------------------------------------------
874 SetBitInWord(&controlValue
, SET_SENS_LOCALINIT_BITPOS
); // init the control value
876 // ----------------------------------------------------------------------------
877 // make sure the card is not in monitor mode when we do this update.
878 // ----------------------------------------------------------------------------
879 if (korg1212
->cardState
== K1212_STATE_MONITOR
|| korg1212
->idleMonitorOn
) {
881 snd_korg1212_SendStopAndWait(korg1212
);
885 spin_lock_irqsave(&korg1212
->lock
, flags
);
887 // ----------------------------------------------------------------------------
888 // we are about to send new values to the card, so clear the new values queued
889 // flag. Also, clear out mailbox 3, so we don't lockup.
890 // ----------------------------------------------------------------------------
891 writel(0, korg1212
->mailbox3Ptr
);
892 udelay(LOADSHIFT_DELAY
);
894 // ----------------------------------------------------------------------------
895 // determine whether we are running a 48K or 44.1K clock. This info is used
896 // later when setting the SPDIF FF after the volume has been shifted in.
897 // ----------------------------------------------------------------------------
898 switch (korg1212
->clkSrcRate
) {
899 case K1212_CLKIDX_AdatAt44_1K
:
900 case K1212_CLKIDX_WordAt44_1K
:
901 case K1212_CLKIDX_LocalAt44_1K
:
905 case K1212_CLKIDX_WordAt48K
:
906 case K1212_CLKIDX_AdatAt48K
:
907 case K1212_CLKIDX_LocalAt48K
:
913 // ----------------------------------------------------------------------------
914 // start the update. Setup the bit structure and then shift the bits.
915 // ----------------------------------------------------------------------------
916 sensVals
.l
.v
.leftChanId
= SET_SENS_LEFTCHANID
;
917 sensVals
.r
.v
.rightChanId
= SET_SENS_RIGHTCHANID
;
918 sensVals
.l
.v
.leftChanVal
= korg1212
->leftADCInSens
;
919 sensVals
.r
.v
.rightChanVal
= korg1212
->rightADCInSens
;
921 // ----------------------------------------------------------------------------
922 // now start shifting the bits in. Start with the left channel then the right.
923 // ----------------------------------------------------------------------------
924 for (channel
= 0; channel
< 2; channel
++) {
926 // ----------------------------------------------------------------------------
927 // Bring the load/shift line low, then wait - the spec says >150ns from load/
928 // shift low to the first rising edge of the clock.
929 // ----------------------------------------------------------------------------
930 ClearBitInWord(&controlValue
, SET_SENS_LOADSHIFT_BITPOS
);
931 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
932 writew(controlValue
, korg1212
->sensRegPtr
); // load/shift goes low
933 udelay(LOADSHIFT_DELAY
);
935 for (bitPosition
= 15; bitPosition
>= 0; bitPosition
--) { // for all the bits
937 if (sensVals
.l
.leftSensBits
& (0x0001 << bitPosition
))
938 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set high
940 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set low
942 if (sensVals
.r
.rightSensBits
& (0x0001 << bitPosition
))
943 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set high
945 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
); // data bit set low
948 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
949 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes low
950 udelay(SENSCLKPULSE_WIDTH
);
951 SetBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
952 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes high
953 udelay(SENSCLKPULSE_WIDTH
);
956 // ----------------------------------------------------------------------------
957 // finish up SPDIF for left. Bring the load/shift line high, then write a one
958 // bit if the clock rate is 48K otherwise write 0.
959 // ----------------------------------------------------------------------------
960 ClearBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
961 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
962 SetBitInWord(&controlValue
, SET_SENS_LOADSHIFT_BITPOS
);
963 writew(controlValue
, korg1212
->sensRegPtr
); // load shift goes high - clk low
964 udelay(SENSCLKPULSE_WIDTH
);
967 SetBitInWord(&controlValue
, SET_SENS_DATA_BITPOS
);
969 writew(controlValue
, korg1212
->sensRegPtr
); // set/clear data bit
970 udelay(ONE_RTC_TICK
);
971 SetBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
972 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes high
973 udelay(SENSCLKPULSE_WIDTH
);
974 ClearBitInWord(&controlValue
, SET_SENS_CLOCK_BITPOS
);
975 writew(controlValue
, korg1212
->sensRegPtr
); // clock goes low
976 udelay(SENSCLKPULSE_WIDTH
);
979 // ----------------------------------------------------------------------------
980 // The update is complete. Set a timeout. This is the inter-update delay.
981 // Also, if the card was in monitor mode, restore it.
982 // ----------------------------------------------------------------------------
983 for (count
= 0; count
< 10; count
++)
984 udelay(SENSCLKPULSE_WIDTH
);
987 int rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SelectPlayMode
,
988 K1212_MODE_MonitorOn
, 0, 0, 0);
990 K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n",
991 rc
, stateName
[korg1212
->cardState
]);
994 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
999 static void snd_korg1212_OnDSPDownloadComplete(struct snd_korg1212
*korg1212
)
1003 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n",
1004 stateName
[korg1212
->cardState
]);
1006 // ----------------------------------------------------
1007 // tell the card to boot
1008 // ----------------------------------------------------
1009 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_BootFromDSPPage4
, 0, 0, 0, 0);
1012 K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n",
1013 rc
, stateName
[korg1212
->cardState
]);
1014 msleep(DSP_BOOT_DELAY_IN_MS
);
1016 // --------------------------------------------------------------------------------
1017 // Let the card know where all the buffers are.
1018 // --------------------------------------------------------------------------------
1019 rc
= snd_korg1212_Send1212Command(korg1212
,
1020 K1212_DB_ConfigureBufferMemory
,
1021 LowerWordSwap(korg1212
->PlayDataPhy
),
1022 LowerWordSwap(korg1212
->RecDataPhy
),
1023 ((kNumBuffers
* kPlayBufferFrames
) / 2), // size given to the card
1024 // is based on 2 buffers
1029 K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n",
1030 rc
, stateName
[korg1212
->cardState
]);
1032 udelay(INTERCOMMAND_DELAY
);
1034 rc
= snd_korg1212_Send1212Command(korg1212
,
1035 K1212_DB_ConfigureMiscMemory
,
1036 LowerWordSwap(korg1212
->VolumeTablePhy
),
1037 LowerWordSwap(korg1212
->RoutingTablePhy
),
1038 LowerWordSwap(korg1212
->AdatTimeCodePhy
),
1043 K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n",
1044 rc
, stateName
[korg1212
->cardState
]);
1046 // --------------------------------------------------------------------------------
1047 // Initialize the routing and volume tables, then update the card's state.
1048 // --------------------------------------------------------------------------------
1049 udelay(INTERCOMMAND_DELAY
);
1051 for (channel
= 0; channel
< kAudioChannels
; channel
++) {
1052 korg1212
->sharedBufferPtr
->volumeData
[channel
] = k1212MaxVolume
;
1053 //korg1212->sharedBufferPtr->routeData[channel] = channel;
1054 korg1212
->sharedBufferPtr
->routeData
[channel
] = 8 + (channel
& 1);
1057 snd_korg1212_WriteADCSensitivity(korg1212
);
1059 udelay(INTERCOMMAND_DELAY
);
1060 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_SetClockSourceRate
,
1061 ClockSourceSelector
[korg1212
->clkSrcRate
],
1064 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n",
1065 rc
, stateName
[korg1212
->cardState
]);
1067 rc
= snd_korg1212_TurnOnIdleMonitor(korg1212
);
1068 snd_korg1212_setCardState(korg1212
, K1212_STATE_READY
);
1071 K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n",
1072 rc
, stateName
[korg1212
->cardState
]);
1074 snd_korg1212_setCardState(korg1212
, K1212_STATE_DSP_COMPLETE
);
1077 static irqreturn_t
snd_korg1212_interrupt(int irq
, void *dev_id
)
1080 struct snd_korg1212
*korg1212
= dev_id
;
1082 doorbellValue
= readl(korg1212
->inDoorbellPtr
);
1087 spin_lock(&korg1212
->lock
);
1089 writel(doorbellValue
, korg1212
->inDoorbellPtr
);
1091 korg1212
->irqcount
++;
1095 switch (doorbellValue
) {
1096 case K1212_DB_DSPDownloadDone
:
1097 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n",
1098 korg1212
->irqcount
, doorbellValue
,
1099 stateName
[korg1212
->cardState
]);
1100 if (korg1212
->cardState
== K1212_STATE_DSP_IN_PROCESS
) {
1101 korg1212
->dsp_is_loaded
= 1;
1102 wake_up(&korg1212
->wait
);
1106 // ------------------------------------------------------------------------
1107 // an error occurred - stop the card
1108 // ------------------------------------------------------------------------
1109 case K1212_DB_DMAERROR
:
1110 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n",
1111 korg1212
->irqcount
, doorbellValue
,
1112 stateName
[korg1212
->cardState
]);
1113 snd_printk(KERN_ERR
"korg1212: DMA Error\n");
1114 korg1212
->errorcnt
++;
1115 korg1212
->totalerrorcnt
++;
1116 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1117 snd_korg1212_setCardState(korg1212
, K1212_STATE_ERRORSTOP
);
1120 // ------------------------------------------------------------------------
1121 // the card has stopped by our request. Clear the command word and signal
1122 // the semaphore in case someone is waiting for this.
1123 // ------------------------------------------------------------------------
1124 case K1212_DB_CARDSTOPPED
:
1125 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n",
1126 korg1212
->irqcount
, doorbellValue
,
1127 stateName
[korg1212
->cardState
]);
1128 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1132 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n",
1133 korg1212
->irqcount
, doorbellValue
,
1134 korg1212
->currentBuffer
, stateName
[korg1212
->cardState
]);
1135 if ((korg1212
->cardState
> K1212_STATE_SETUP
) || korg1212
->idleMonitorOn
) {
1136 korg1212
->currentBuffer
++;
1138 if (korg1212
->currentBuffer
>= kNumBuffers
)
1139 korg1212
->currentBuffer
= 0;
1141 if (!korg1212
->running
)
1144 if (korg1212
->capture_substream
) {
1145 spin_unlock(&korg1212
->lock
);
1146 snd_pcm_period_elapsed(korg1212
->capture_substream
);
1147 spin_lock(&korg1212
->lock
);
1150 if (korg1212
->playback_substream
) {
1151 spin_unlock(&korg1212
->lock
);
1152 snd_pcm_period_elapsed(korg1212
->playback_substream
);
1153 spin_lock(&korg1212
->lock
);
1161 spin_unlock(&korg1212
->lock
);
1166 static int snd_korg1212_downloadDSPCode(struct snd_korg1212
*korg1212
)
1170 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n",
1171 stateName
[korg1212
->cardState
]);
1173 // ---------------------------------------------------------------
1174 // verify the state of the card before proceeding.
1175 // ---------------------------------------------------------------
1176 if (korg1212
->cardState
>= K1212_STATE_DSP_IN_PROCESS
)
1179 snd_korg1212_setCardState(korg1212
, K1212_STATE_DSP_IN_PROCESS
);
1181 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_StartDSPDownload
,
1182 UpperWordSwap(korg1212
->dma_dsp
.addr
),
1185 K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n",
1186 rc
, stateName
[korg1212
->cardState
]);
1188 korg1212
->dsp_is_loaded
= 0;
1189 wait_event_timeout(korg1212
->wait
, korg1212
->dsp_is_loaded
, HZ
* CARD_BOOT_TIMEOUT
);
1190 if (! korg1212
->dsp_is_loaded
)
1191 return -EBUSY
; /* timeout */
1193 snd_korg1212_OnDSPDownloadComplete(korg1212
);
1198 static struct snd_pcm_hardware snd_korg1212_playback_info
=
1200 .info
= (SNDRV_PCM_INFO_MMAP
|
1201 SNDRV_PCM_INFO_MMAP_VALID
|
1202 SNDRV_PCM_INFO_INTERLEAVED
|
1203 SNDRV_PCM_INFO_BATCH
),
1204 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1205 .rates
= (SNDRV_PCM_RATE_44100
|
1206 SNDRV_PCM_RATE_48000
),
1209 .channels_min
= K1212_MIN_CHANNELS
,
1210 .channels_max
= K1212_MAX_CHANNELS
,
1211 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1212 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1213 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1214 .periods_min
= K1212_PERIODS
,
1215 .periods_max
= K1212_PERIODS
,
1219 static struct snd_pcm_hardware snd_korg1212_capture_info
=
1221 .info
= (SNDRV_PCM_INFO_MMAP
|
1222 SNDRV_PCM_INFO_MMAP_VALID
|
1223 SNDRV_PCM_INFO_INTERLEAVED
|
1224 SNDRV_PCM_INFO_BATCH
),
1225 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1226 .rates
= (SNDRV_PCM_RATE_44100
|
1227 SNDRV_PCM_RATE_48000
),
1230 .channels_min
= K1212_MIN_CHANNELS
,
1231 .channels_max
= K1212_MAX_CHANNELS
,
1232 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1233 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1234 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1235 .periods_min
= K1212_PERIODS
,
1236 .periods_max
= K1212_PERIODS
,
1240 static int snd_korg1212_silence(struct snd_korg1212
*korg1212
, int pos
, int count
, int offset
, int size
)
1242 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1245 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n",
1246 pos
, offset
, size
, count
);
1247 if (snd_BUG_ON(pos
+ count
> K1212_MAX_SAMPLES
))
1250 for (i
=0; i
< count
; i
++) {
1251 #if K1212_DEBUG_LEVEL > 0
1252 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1253 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1254 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n",
1259 memset((void*) dst
+ offset
, 0, size
);
1266 static int snd_korg1212_copy_to(struct snd_korg1212
*korg1212
, void __user
*dst
, int pos
, int count
, int offset
, int size
)
1268 struct KorgAudioFrame
* src
= korg1212
->recordDataBufsPtr
[0].bufferData
+ pos
;
1271 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n",
1273 if (snd_BUG_ON(pos
+ count
> K1212_MAX_SAMPLES
))
1276 for (i
=0; i
< count
; i
++) {
1277 #if K1212_DEBUG_LEVEL > 0
1278 if ( (void *) src
< (void *) korg1212
->recordDataBufsPtr
||
1279 (void *) src
> (void *) korg1212
->recordDataBufsPtr
[8].bufferData
) {
1280 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1284 rc
= copy_to_user(dst
+ offset
, src
, size
);
1286 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1296 static int snd_korg1212_copy_from(struct snd_korg1212
*korg1212
, void __user
*src
, int pos
, int count
, int offset
, int size
)
1298 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1301 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n",
1302 pos
, offset
, size
, count
);
1304 if (snd_BUG_ON(pos
+ count
> K1212_MAX_SAMPLES
))
1307 for (i
=0; i
< count
; i
++) {
1308 #if K1212_DEBUG_LEVEL > 0
1309 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1310 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1311 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1315 rc
= copy_from_user((void*) dst
+ offset
, src
, size
);
1317 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1327 static void snd_korg1212_free_pcm(struct snd_pcm
*pcm
)
1329 struct snd_korg1212
*korg1212
= pcm
->private_data
;
1331 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n",
1332 stateName
[korg1212
->cardState
]);
1334 korg1212
->pcm
= NULL
;
1337 static int snd_korg1212_playback_open(struct snd_pcm_substream
*substream
)
1339 unsigned long flags
;
1340 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1341 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1343 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n",
1344 stateName
[korg1212
->cardState
]);
1346 snd_korg1212_OpenCard(korg1212
);
1348 runtime
->hw
= snd_korg1212_playback_info
;
1349 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_play
);
1351 spin_lock_irqsave(&korg1212
->lock
, flags
);
1353 korg1212
->playback_substream
= substream
;
1354 korg1212
->playback_pid
= current
->pid
;
1355 korg1212
->periodsize
= K1212_PERIODS
;
1356 korg1212
->channels
= K1212_CHANNELS
;
1357 korg1212
->errorcnt
= 0;
1359 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1361 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, kPlayBufferFrames
, kPlayBufferFrames
);
1366 static int snd_korg1212_capture_open(struct snd_pcm_substream
*substream
)
1368 unsigned long flags
;
1369 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1370 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1372 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n",
1373 stateName
[korg1212
->cardState
]);
1375 snd_korg1212_OpenCard(korg1212
);
1377 runtime
->hw
= snd_korg1212_capture_info
;
1378 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_rec
);
1380 spin_lock_irqsave(&korg1212
->lock
, flags
);
1382 korg1212
->capture_substream
= substream
;
1383 korg1212
->capture_pid
= current
->pid
;
1384 korg1212
->periodsize
= K1212_PERIODS
;
1385 korg1212
->channels
= K1212_CHANNELS
;
1387 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1389 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1390 kPlayBufferFrames
, kPlayBufferFrames
);
1394 static int snd_korg1212_playback_close(struct snd_pcm_substream
*substream
)
1396 unsigned long flags
;
1397 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1399 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n",
1400 stateName
[korg1212
->cardState
]);
1402 snd_korg1212_silence(korg1212
, 0, K1212_MAX_SAMPLES
, 0, korg1212
->channels
* 2);
1404 spin_lock_irqsave(&korg1212
->lock
, flags
);
1406 korg1212
->playback_pid
= -1;
1407 korg1212
->playback_substream
= NULL
;
1408 korg1212
->periodsize
= 0;
1410 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1412 snd_korg1212_CloseCard(korg1212
);
1416 static int snd_korg1212_capture_close(struct snd_pcm_substream
*substream
)
1418 unsigned long flags
;
1419 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1421 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n",
1422 stateName
[korg1212
->cardState
]);
1424 spin_lock_irqsave(&korg1212
->lock
, flags
);
1426 korg1212
->capture_pid
= -1;
1427 korg1212
->capture_substream
= NULL
;
1428 korg1212
->periodsize
= 0;
1430 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1432 snd_korg1212_CloseCard(korg1212
);
1436 static int snd_korg1212_ioctl(struct snd_pcm_substream
*substream
,
1437 unsigned int cmd
, void *arg
)
1439 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd
);
1441 if (cmd
== SNDRV_PCM_IOCTL1_CHANNEL_INFO
) {
1442 struct snd_pcm_channel_info
*info
= arg
;
1444 info
->first
= info
->channel
* 16;
1446 K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info
->channel
, info
->offset
, info
->first
, info
->step
);
1450 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1453 static int snd_korg1212_hw_params(struct snd_pcm_substream
*substream
,
1454 struct snd_pcm_hw_params
*params
)
1456 unsigned long flags
;
1457 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1462 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n",
1463 stateName
[korg1212
->cardState
]);
1465 spin_lock_irqsave(&korg1212
->lock
, flags
);
1467 if (substream
->pstr
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1468 this_pid
= korg1212
->playback_pid
;
1469 other_pid
= korg1212
->capture_pid
;
1471 this_pid
= korg1212
->capture_pid
;
1472 other_pid
= korg1212
->playback_pid
;
1475 if ((other_pid
> 0) && (this_pid
!= other_pid
)) {
1477 /* The other stream is open, and not by the same
1478 task as this one. Make sure that the parameters
1479 that matter are the same.
1482 if ((int)params_rate(params
) != korg1212
->clkRate
) {
1483 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1484 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
1488 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1492 if ((err
= snd_korg1212_SetRate(korg1212
, params_rate(params
))) < 0) {
1493 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1497 korg1212
->channels
= params_channels(params
);
1498 korg1212
->periodsize
= K1212_PERIOD_BYTES
;
1500 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1505 static int snd_korg1212_prepare(struct snd_pcm_substream
*substream
)
1507 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1510 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n",
1511 stateName
[korg1212
->cardState
]);
1513 spin_lock_irq(&korg1212
->lock
);
1515 if (korg1212
->stop_pending_cnt
> 0) {
1516 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n",
1517 stateName
[korg1212
->cardState
]);
1518 spin_unlock_irq(&korg1212
->lock
);
1521 korg1212->sharedBufferPtr->cardCommand = 0;
1522 del_timer(&korg1212->timer);
1523 korg1212->stop_pending_cnt = 0;
1527 rc
= snd_korg1212_SetupForPlay(korg1212
);
1529 korg1212
->currentBuffer
= 0;
1531 spin_unlock_irq(&korg1212
->lock
);
1533 return rc
? -EINVAL
: 0;
1536 static int snd_korg1212_trigger(struct snd_pcm_substream
*substream
,
1539 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1542 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n",
1543 stateName
[korg1212
->cardState
], cmd
);
1545 spin_lock(&korg1212
->lock
);
1547 case SNDRV_PCM_TRIGGER_START
:
1549 if (korg1212->running) {
1550 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n");
1554 korg1212
->running
++;
1555 rc
= snd_korg1212_TriggerPlay(korg1212
);
1558 case SNDRV_PCM_TRIGGER_STOP
:
1560 if (!korg1212->running) {
1561 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n");
1565 korg1212
->running
--;
1566 rc
= snd_korg1212_StopPlay(korg1212
);
1573 spin_unlock(&korg1212
->lock
);
1574 return rc
? -EINVAL
: 0;
1577 static snd_pcm_uframes_t
snd_korg1212_playback_pointer(struct snd_pcm_substream
*substream
)
1579 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1580 snd_pcm_uframes_t pos
;
1582 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1584 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n",
1585 stateName
[korg1212
->cardState
], pos
);
1590 static snd_pcm_uframes_t
snd_korg1212_capture_pointer(struct snd_pcm_substream
*substream
)
1592 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1593 snd_pcm_uframes_t pos
;
1595 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1597 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n",
1598 stateName
[korg1212
->cardState
], pos
);
1603 static int snd_korg1212_playback_copy(struct snd_pcm_substream
*substream
,
1604 int channel
, /* not used (interleaved data) */
1605 snd_pcm_uframes_t pos
,
1607 snd_pcm_uframes_t count
)
1609 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1611 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n",
1612 stateName
[korg1212
->cardState
], pos
, count
);
1614 return snd_korg1212_copy_from(korg1212
, src
, pos
, count
, 0, korg1212
->channels
* 2);
1618 static int snd_korg1212_playback_silence(struct snd_pcm_substream
*substream
,
1619 int channel
, /* not used (interleaved data) */
1620 snd_pcm_uframes_t pos
,
1621 snd_pcm_uframes_t count
)
1623 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1625 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n",
1626 stateName
[korg1212
->cardState
]);
1628 return snd_korg1212_silence(korg1212
, pos
, count
, 0, korg1212
->channels
* 2);
1631 static int snd_korg1212_capture_copy(struct snd_pcm_substream
*substream
,
1632 int channel
, /* not used (interleaved data) */
1633 snd_pcm_uframes_t pos
,
1635 snd_pcm_uframes_t count
)
1637 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1639 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n",
1640 stateName
[korg1212
->cardState
], pos
, count
);
1642 return snd_korg1212_copy_to(korg1212
, dst
, pos
, count
, 0, korg1212
->channels
* 2);
1645 static struct snd_pcm_ops snd_korg1212_playback_ops
= {
1646 .open
= snd_korg1212_playback_open
,
1647 .close
= snd_korg1212_playback_close
,
1648 .ioctl
= snd_korg1212_ioctl
,
1649 .hw_params
= snd_korg1212_hw_params
,
1650 .prepare
= snd_korg1212_prepare
,
1651 .trigger
= snd_korg1212_trigger
,
1652 .pointer
= snd_korg1212_playback_pointer
,
1653 .copy
= snd_korg1212_playback_copy
,
1654 .silence
= snd_korg1212_playback_silence
,
1657 static struct snd_pcm_ops snd_korg1212_capture_ops
= {
1658 .open
= snd_korg1212_capture_open
,
1659 .close
= snd_korg1212_capture_close
,
1660 .ioctl
= snd_korg1212_ioctl
,
1661 .hw_params
= snd_korg1212_hw_params
,
1662 .prepare
= snd_korg1212_prepare
,
1663 .trigger
= snd_korg1212_trigger
,
1664 .pointer
= snd_korg1212_capture_pointer
,
1665 .copy
= snd_korg1212_capture_copy
,
1672 static int snd_korg1212_control_phase_info(struct snd_kcontrol
*kcontrol
,
1673 struct snd_ctl_elem_info
*uinfo
)
1675 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1676 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1680 static int snd_korg1212_control_phase_get(struct snd_kcontrol
*kcontrol
,
1681 struct snd_ctl_elem_value
*u
)
1683 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1684 int i
= kcontrol
->private_value
;
1686 spin_lock_irq(&korg1212
->lock
);
1688 u
->value
.integer
.value
[0] = korg1212
->volumePhase
[i
];
1691 u
->value
.integer
.value
[1] = korg1212
->volumePhase
[i
+1];
1693 spin_unlock_irq(&korg1212
->lock
);
1698 static int snd_korg1212_control_phase_put(struct snd_kcontrol
*kcontrol
,
1699 struct snd_ctl_elem_value
*u
)
1701 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1705 spin_lock_irq(&korg1212
->lock
);
1707 i
= kcontrol
->private_value
;
1709 korg1212
->volumePhase
[i
] = !!u
->value
.integer
.value
[0];
1711 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
];
1713 if ((u
->value
.integer
.value
[0] != 0) != (val
< 0)) {
1714 val
= abs(val
) * (korg1212
->volumePhase
[i
] > 0 ? -1 : 1);
1715 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1720 korg1212
->volumePhase
[i
+1] = !!u
->value
.integer
.value
[1];
1722 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
+1];
1724 if ((u
->value
.integer
.value
[1] != 0) != (val
< 0)) {
1725 val
= abs(val
) * (korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1);
1726 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1731 spin_unlock_irq(&korg1212
->lock
);
1736 static int snd_korg1212_control_volume_info(struct snd_kcontrol
*kcontrol
,
1737 struct snd_ctl_elem_info
*uinfo
)
1739 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1740 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1741 uinfo
->value
.integer
.min
= k1212MinVolume
;
1742 uinfo
->value
.integer
.max
= k1212MaxVolume
;
1746 static int snd_korg1212_control_volume_get(struct snd_kcontrol
*kcontrol
,
1747 struct snd_ctl_elem_value
*u
)
1749 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1752 spin_lock_irq(&korg1212
->lock
);
1754 i
= kcontrol
->private_value
;
1755 u
->value
.integer
.value
[0] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
]);
1758 u
->value
.integer
.value
[1] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1]);
1760 spin_unlock_irq(&korg1212
->lock
);
1765 static int snd_korg1212_control_volume_put(struct snd_kcontrol
*kcontrol
,
1766 struct snd_ctl_elem_value
*u
)
1768 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1773 spin_lock_irq(&korg1212
->lock
);
1775 i
= kcontrol
->private_value
;
1777 if (u
->value
.integer
.value
[0] >= k1212MinVolume
&&
1778 u
->value
.integer
.value
[0] >= k1212MaxVolume
&&
1779 u
->value
.integer
.value
[0] !=
1780 abs(korg1212
->sharedBufferPtr
->volumeData
[i
])) {
1781 val
= korg1212
->volumePhase
[i
] > 0 ? -1 : 1;
1782 val
*= u
->value
.integer
.value
[0];
1783 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1788 if (u
->value
.integer
.value
[1] >= k1212MinVolume
&&
1789 u
->value
.integer
.value
[1] >= k1212MaxVolume
&&
1790 u
->value
.integer
.value
[1] !=
1791 abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1])) {
1792 val
= korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1;
1793 val
*= u
->value
.integer
.value
[1];
1794 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1799 spin_unlock_irq(&korg1212
->lock
);
1804 static int snd_korg1212_control_route_info(struct snd_kcontrol
*kcontrol
,
1805 struct snd_ctl_elem_info
*uinfo
)
1807 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1808 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1809 uinfo
->value
.enumerated
.items
= kAudioChannels
;
1810 if (uinfo
->value
.enumerated
.item
> kAudioChannels
-1) {
1811 uinfo
->value
.enumerated
.item
= kAudioChannels
-1;
1813 strcpy(uinfo
->value
.enumerated
.name
, channelName
[uinfo
->value
.enumerated
.item
]);
1817 static int snd_korg1212_control_route_get(struct snd_kcontrol
*kcontrol
,
1818 struct snd_ctl_elem_value
*u
)
1820 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1823 spin_lock_irq(&korg1212
->lock
);
1825 i
= kcontrol
->private_value
;
1826 u
->value
.enumerated
.item
[0] = korg1212
->sharedBufferPtr
->routeData
[i
];
1829 u
->value
.enumerated
.item
[1] = korg1212
->sharedBufferPtr
->routeData
[i
+1];
1831 spin_unlock_irq(&korg1212
->lock
);
1836 static int snd_korg1212_control_route_put(struct snd_kcontrol
*kcontrol
,
1837 struct snd_ctl_elem_value
*u
)
1839 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1842 spin_lock_irq(&korg1212
->lock
);
1844 i
= kcontrol
->private_value
;
1846 if (u
->value
.enumerated
.item
[0] < kAudioChannels
&&
1847 u
->value
.enumerated
.item
[0] !=
1848 (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
]) {
1849 korg1212
->sharedBufferPtr
->routeData
[i
] = u
->value
.enumerated
.item
[0];
1854 if (u
->value
.enumerated
.item
[1] < kAudioChannels
&&
1855 u
->value
.enumerated
.item
[1] !=
1856 (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
+1]) {
1857 korg1212
->sharedBufferPtr
->routeData
[i
+1] = u
->value
.enumerated
.item
[1];
1862 spin_unlock_irq(&korg1212
->lock
);
1867 static int snd_korg1212_control_info(struct snd_kcontrol
*kcontrol
,
1868 struct snd_ctl_elem_info
*uinfo
)
1870 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1872 uinfo
->value
.integer
.min
= k1212MaxADCSens
;
1873 uinfo
->value
.integer
.max
= k1212MinADCSens
;
1877 static int snd_korg1212_control_get(struct snd_kcontrol
*kcontrol
,
1878 struct snd_ctl_elem_value
*u
)
1880 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1882 spin_lock_irq(&korg1212
->lock
);
1884 u
->value
.integer
.value
[0] = korg1212
->leftADCInSens
;
1885 u
->value
.integer
.value
[1] = korg1212
->rightADCInSens
;
1887 spin_unlock_irq(&korg1212
->lock
);
1892 static int snd_korg1212_control_put(struct snd_kcontrol
*kcontrol
,
1893 struct snd_ctl_elem_value
*u
)
1895 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1898 spin_lock_irq(&korg1212
->lock
);
1900 if (u
->value
.integer
.value
[0] >= k1212MinADCSens
&&
1901 u
->value
.integer
.value
[0] <= k1212MaxADCSens
&&
1902 u
->value
.integer
.value
[0] != korg1212
->leftADCInSens
) {
1903 korg1212
->leftADCInSens
= u
->value
.integer
.value
[0];
1906 if (u
->value
.integer
.value
[1] >= k1212MinADCSens
&&
1907 u
->value
.integer
.value
[1] <= k1212MaxADCSens
&&
1908 u
->value
.integer
.value
[1] != korg1212
->rightADCInSens
) {
1909 korg1212
->rightADCInSens
= u
->value
.integer
.value
[1];
1913 spin_unlock_irq(&korg1212
->lock
);
1916 snd_korg1212_WriteADCSensitivity(korg1212
);
1921 static int snd_korg1212_control_sync_info(struct snd_kcontrol
*kcontrol
,
1922 struct snd_ctl_elem_info
*uinfo
)
1924 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1926 uinfo
->value
.enumerated
.items
= 3;
1927 if (uinfo
->value
.enumerated
.item
> 2) {
1928 uinfo
->value
.enumerated
.item
= 2;
1930 strcpy(uinfo
->value
.enumerated
.name
, clockSourceTypeName
[uinfo
->value
.enumerated
.item
]);
1934 static int snd_korg1212_control_sync_get(struct snd_kcontrol
*kcontrol
,
1935 struct snd_ctl_elem_value
*ucontrol
)
1937 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1939 spin_lock_irq(&korg1212
->lock
);
1941 ucontrol
->value
.enumerated
.item
[0] = korg1212
->clkSource
;
1943 spin_unlock_irq(&korg1212
->lock
);
1947 static int snd_korg1212_control_sync_put(struct snd_kcontrol
*kcontrol
,
1948 struct snd_ctl_elem_value
*ucontrol
)
1950 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1954 val
= ucontrol
->value
.enumerated
.item
[0] % 3;
1955 spin_lock_irq(&korg1212
->lock
);
1956 change
= val
!= korg1212
->clkSource
;
1957 snd_korg1212_SetClockSource(korg1212
, val
);
1958 spin_unlock_irq(&korg1212
->lock
);
1962 #define MON_MIXER(ord,c_name) \
1964 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
1965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1966 .name = c_name " Monitor Volume", \
1967 .info = snd_korg1212_control_volume_info, \
1968 .get = snd_korg1212_control_volume_get, \
1969 .put = snd_korg1212_control_volume_put, \
1970 .private_value = ord, \
1973 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
1974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1975 .name = c_name " Monitor Route", \
1976 .info = snd_korg1212_control_route_info, \
1977 .get = snd_korg1212_control_route_get, \
1978 .put = snd_korg1212_control_route_put, \
1979 .private_value = ord, \
1982 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
1983 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1984 .name = c_name " Monitor Phase Invert", \
1985 .info = snd_korg1212_control_phase_info, \
1986 .get = snd_korg1212_control_phase_get, \
1987 .put = snd_korg1212_control_phase_put, \
1988 .private_value = ord, \
1991 static struct snd_kcontrol_new snd_korg1212_controls
[] = {
1992 MON_MIXER(8, "Analog"),
1993 MON_MIXER(10, "SPDIF"),
1994 MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"),
1995 MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"),
1997 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
1998 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1999 .name
= "Sync Source",
2000 .info
= snd_korg1212_control_sync_info
,
2001 .get
= snd_korg1212_control_sync_get
,
2002 .put
= snd_korg1212_control_sync_put
,
2005 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
2006 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2007 .name
= "ADC Attenuation",
2008 .info
= snd_korg1212_control_info
,
2009 .get
= snd_korg1212_control_get
,
2010 .put
= snd_korg1212_control_put
,
2018 static void snd_korg1212_proc_read(struct snd_info_entry
*entry
,
2019 struct snd_info_buffer
*buffer
)
2022 struct snd_korg1212
*korg1212
= entry
->private_data
;
2024 snd_iprintf(buffer
, korg1212
->card
->longname
);
2025 snd_iprintf(buffer
, " (index #%d)\n", korg1212
->card
->number
+ 1);
2026 snd_iprintf(buffer
, "\nGeneral settings\n");
2027 snd_iprintf(buffer
, " period size: %Zd bytes\n", K1212_PERIOD_BYTES
);
2028 snd_iprintf(buffer
, " clock mode: %s\n", clockSourceName
[korg1212
->clkSrcRate
] );
2029 snd_iprintf(buffer
, " left ADC Sens: %d\n", korg1212
->leftADCInSens
);
2030 snd_iprintf(buffer
, " right ADC Sens: %d\n", korg1212
->rightADCInSens
);
2031 snd_iprintf(buffer
, " Volume Info:\n");
2032 for (n
=0; n
<kAudioChannels
; n
++)
2033 snd_iprintf(buffer
, " Channel %d: %s -> %s [%d]\n", n
,
2035 channelName
[korg1212
->sharedBufferPtr
->routeData
[n
]],
2036 korg1212
->sharedBufferPtr
->volumeData
[n
]);
2037 snd_iprintf(buffer
, "\nGeneral status\n");
2038 snd_iprintf(buffer
, " ADAT Time Code: %d\n", korg1212
->sharedBufferPtr
->AdatTimeCode
);
2039 snd_iprintf(buffer
, " Card State: %s\n", stateName
[korg1212
->cardState
]);
2040 snd_iprintf(buffer
, "Idle mon. State: %d\n", korg1212
->idleMonitorOn
);
2041 snd_iprintf(buffer
, "Cmd retry count: %d\n", korg1212
->cmdRetryCount
);
2042 snd_iprintf(buffer
, " Irq count: %ld\n", korg1212
->irqcount
);
2043 snd_iprintf(buffer
, " Error count: %ld\n", korg1212
->totalerrorcnt
);
2046 static void __devinit
snd_korg1212_proc_init(struct snd_korg1212
*korg1212
)
2048 struct snd_info_entry
*entry
;
2050 if (! snd_card_proc_new(korg1212
->card
, "korg1212", &entry
))
2051 snd_info_set_text_ops(entry
, korg1212
, snd_korg1212_proc_read
);
2055 snd_korg1212_free(struct snd_korg1212
*korg1212
)
2057 snd_korg1212_TurnOffIdleMonitor(korg1212
);
2059 if (korg1212
->irq
>= 0) {
2060 snd_korg1212_DisableCardInterrupts(korg1212
);
2061 free_irq(korg1212
->irq
, korg1212
);
2065 if (korg1212
->iobase
!= NULL
) {
2066 iounmap(korg1212
->iobase
);
2067 korg1212
->iobase
= NULL
;
2070 pci_release_regions(korg1212
->pci
);
2072 // ----------------------------------------------------
2073 // free up memory resources used for the DSP download.
2074 // ----------------------------------------------------
2075 if (korg1212
->dma_dsp
.area
) {
2076 snd_dma_free_pages(&korg1212
->dma_dsp
);
2077 korg1212
->dma_dsp
.area
= NULL
;
2080 #ifndef K1212_LARGEALLOC
2082 // ------------------------------------------------------
2083 // free up memory resources used for the Play/Rec Buffers
2084 // ------------------------------------------------------
2085 if (korg1212
->dma_play
.area
) {
2086 snd_dma_free_pages(&korg1212
->dma_play
);
2087 korg1212
->dma_play
.area
= NULL
;
2090 if (korg1212
->dma_rec
.area
) {
2091 snd_dma_free_pages(&korg1212
->dma_rec
);
2092 korg1212
->dma_rec
.area
= NULL
;
2097 // ----------------------------------------------------
2098 // free up memory resources used for the Shared Buffers
2099 // ----------------------------------------------------
2100 if (korg1212
->dma_shared
.area
) {
2101 snd_dma_free_pages(&korg1212
->dma_shared
);
2102 korg1212
->dma_shared
.area
= NULL
;
2105 pci_disable_device(korg1212
->pci
);
2110 static int snd_korg1212_dev_free(struct snd_device
*device
)
2112 struct snd_korg1212
*korg1212
= device
->device_data
;
2113 K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n");
2114 return snd_korg1212_free(korg1212
);
2117 static int __devinit
snd_korg1212_create(struct snd_card
*card
, struct pci_dev
*pci
,
2118 struct snd_korg1212
** rchip
)
2123 unsigned ioport_size
, iomem_size
, iomem2_size
;
2124 struct snd_korg1212
* korg1212
;
2125 const struct firmware
*dsp_code
;
2127 static struct snd_device_ops ops
= {
2128 .dev_free
= snd_korg1212_dev_free
,
2132 if ((err
= pci_enable_device(pci
)) < 0)
2135 korg1212
= kzalloc(sizeof(*korg1212
), GFP_KERNEL
);
2136 if (korg1212
== NULL
) {
2137 pci_disable_device(pci
);
2141 korg1212
->card
= card
;
2142 korg1212
->pci
= pci
;
2144 init_waitqueue_head(&korg1212
->wait
);
2145 spin_lock_init(&korg1212
->lock
);
2146 mutex_init(&korg1212
->open_mutex
);
2147 init_timer(&korg1212
->timer
);
2148 korg1212
->timer
.function
= snd_korg1212_timer_func
;
2149 korg1212
->timer
.data
= (unsigned long)korg1212
;
2152 korg1212
->clkSource
= K1212_CLKIDX_Local
;
2153 korg1212
->clkRate
= 44100;
2154 korg1212
->inIRQ
= 0;
2155 korg1212
->running
= 0;
2156 korg1212
->opencnt
= 0;
2157 korg1212
->playcnt
= 0;
2158 korg1212
->setcnt
= 0;
2159 korg1212
->totalerrorcnt
= 0;
2160 korg1212
->playback_pid
= -1;
2161 korg1212
->capture_pid
= -1;
2162 snd_korg1212_setCardState(korg1212
, K1212_STATE_UNINITIALIZED
);
2163 korg1212
->idleMonitorOn
= 0;
2164 korg1212
->clkSrcRate
= K1212_CLKIDX_LocalAt44_1K
;
2165 korg1212
->leftADCInSens
= k1212MaxADCSens
;
2166 korg1212
->rightADCInSens
= k1212MaxADCSens
;
2168 for (i
=0; i
<kAudioChannels
; i
++)
2169 korg1212
->volumePhase
[i
] = 0;
2171 if ((err
= pci_request_regions(pci
, "korg1212")) < 0) {
2173 pci_disable_device(pci
);
2177 korg1212
->iomem
= pci_resource_start(korg1212
->pci
, 0);
2178 korg1212
->ioport
= pci_resource_start(korg1212
->pci
, 1);
2179 korg1212
->iomem2
= pci_resource_start(korg1212
->pci
, 2);
2181 iomem_size
= pci_resource_len(korg1212
->pci
, 0);
2182 ioport_size
= pci_resource_len(korg1212
->pci
, 1);
2183 iomem2_size
= pci_resource_len(korg1212
->pci
, 2);
2185 K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n"
2186 " iomem = 0x%lx (%d)\n"
2187 " ioport = 0x%lx (%d)\n"
2188 " iomem = 0x%lx (%d)\n"
2190 korg1212
->iomem
, iomem_size
,
2191 korg1212
->ioport
, ioport_size
,
2192 korg1212
->iomem2
, iomem2_size
,
2193 stateName
[korg1212
->cardState
]);
2195 if ((korg1212
->iobase
= ioremap(korg1212
->iomem
, iomem_size
)) == NULL
) {
2196 snd_printk(KERN_ERR
"korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212
->iomem
,
2197 korg1212
->iomem
+ iomem_size
- 1);
2198 snd_korg1212_free(korg1212
);
2202 err
= request_irq(pci
->irq
, snd_korg1212_interrupt
,
2204 "korg1212", korg1212
);
2207 snd_printk(KERN_ERR
"korg1212: unable to grab IRQ %d\n", pci
->irq
);
2208 snd_korg1212_free(korg1212
);
2212 korg1212
->irq
= pci
->irq
;
2214 pci_set_master(korg1212
->pci
);
2216 korg1212
->statusRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ STATUS_REG_OFFSET
);
2217 korg1212
->outDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ OUT_DOORBELL_OFFSET
);
2218 korg1212
->inDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ IN_DOORBELL_OFFSET
);
2219 korg1212
->mailbox0Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX0_OFFSET
);
2220 korg1212
->mailbox1Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX1_OFFSET
);
2221 korg1212
->mailbox2Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX2_OFFSET
);
2222 korg1212
->mailbox3Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX3_OFFSET
);
2223 korg1212
->controlRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ PCI_CONTROL_OFFSET
);
2224 korg1212
->sensRegPtr
= (u16 __iomem
*) (korg1212
->iobase
+ SENS_CONTROL_OFFSET
);
2225 korg1212
->idRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ DEV_VEND_ID_OFFSET
);
2227 K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n"
2228 " Status register = 0x%p\n"
2229 " OutDoorbell = 0x%p\n"
2230 " InDoorbell = 0x%p\n"
2231 " Mailbox0 = 0x%p\n"
2232 " Mailbox1 = 0x%p\n"
2233 " Mailbox2 = 0x%p\n"
2234 " Mailbox3 = 0x%p\n"
2235 " ControlReg = 0x%p\n"
2239 korg1212
->statusRegPtr
,
2240 korg1212
->outDoorbellPtr
,
2241 korg1212
->inDoorbellPtr
,
2242 korg1212
->mailbox0Ptr
,
2243 korg1212
->mailbox1Ptr
,
2244 korg1212
->mailbox2Ptr
,
2245 korg1212
->mailbox3Ptr
,
2246 korg1212
->controlRegPtr
,
2247 korg1212
->sensRegPtr
,
2249 stateName
[korg1212
->cardState
]);
2251 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2252 sizeof(struct KorgSharedBuffer
), &korg1212
->dma_shared
) < 0) {
2253 snd_printk(KERN_ERR
"korg1212: can not allocate shared buffer memory (%Zd bytes)\n", sizeof(struct KorgSharedBuffer
));
2254 snd_korg1212_free(korg1212
);
2257 korg1212
->sharedBufferPtr
= (struct KorgSharedBuffer
*)korg1212
->dma_shared
.area
;
2258 korg1212
->sharedBufferPhy
= korg1212
->dma_shared
.addr
;
2260 K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212
->sharedBufferPtr
, korg1212
->sharedBufferPhy
, sizeof(struct KorgSharedBuffer
));
2262 #ifndef K1212_LARGEALLOC
2264 korg1212
->DataBufsSize
= sizeof(struct KorgAudioBuffer
) * kNumBuffers
;
2266 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2267 korg1212
->DataBufsSize
, &korg1212
->dma_play
) < 0) {
2268 snd_printk(KERN_ERR
"korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2269 snd_korg1212_free(korg1212
);
2272 korg1212
->playDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_play
.area
;
2273 korg1212
->PlayDataPhy
= korg1212
->dma_play
.addr
;
2275 K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n",
2276 korg1212
->playDataBufsPtr
, korg1212
->PlayDataPhy
, korg1212
->DataBufsSize
);
2278 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2279 korg1212
->DataBufsSize
, &korg1212
->dma_rec
) < 0) {
2280 snd_printk(KERN_ERR
"korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2281 snd_korg1212_free(korg1212
);
2284 korg1212
->recordDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_rec
.area
;
2285 korg1212
->RecDataPhy
= korg1212
->dma_rec
.addr
;
2287 K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n",
2288 korg1212
->recordDataBufsPtr
, korg1212
->RecDataPhy
, korg1212
->DataBufsSize
);
2290 #else // K1212_LARGEALLOC
2292 korg1212
->recordDataBufsPtr
= korg1212
->sharedBufferPtr
->recordDataBufs
;
2293 korg1212
->playDataBufsPtr
= korg1212
->sharedBufferPtr
->playDataBufs
;
2294 korg1212
->PlayDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->playDataBufs
;
2295 korg1212
->RecDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->recordDataBufs
;
2297 #endif // K1212_LARGEALLOC
2299 korg1212
->VolumeTablePhy
= korg1212
->sharedBufferPhy
+
2300 offsetof(struct KorgSharedBuffer
, volumeData
);
2301 korg1212
->RoutingTablePhy
= korg1212
->sharedBufferPhy
+
2302 offsetof(struct KorgSharedBuffer
, routeData
);
2303 korg1212
->AdatTimeCodePhy
= korg1212
->sharedBufferPhy
+
2304 offsetof(struct KorgSharedBuffer
, AdatTimeCode
);
2306 err
= request_firmware(&dsp_code
, "korg/k1212.dsp", &pci
->dev
);
2308 release_firmware(dsp_code
);
2309 snd_printk(KERN_ERR
"firmware not available\n");
2310 snd_korg1212_free(korg1212
);
2314 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2315 dsp_code
->size
, &korg1212
->dma_dsp
) < 0) {
2316 snd_printk(KERN_ERR
"korg1212: cannot allocate dsp code memory (%zd bytes)\n", dsp_code
->size
);
2317 snd_korg1212_free(korg1212
);
2318 release_firmware(dsp_code
);
2322 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n",
2323 korg1212
->dma_dsp
.area
, korg1212
->dma_dsp
.addr
, dsp_code
->size
,
2324 stateName
[korg1212
->cardState
]);
2326 memcpy(korg1212
->dma_dsp
.area
, dsp_code
->data
, dsp_code
->size
);
2328 release_firmware(dsp_code
);
2330 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_RebootCard
, 0, 0, 0, 0);
2333 K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc
, stateName
[korg1212
->cardState
]);
2335 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, korg1212
, &ops
)) < 0) {
2336 snd_korg1212_free(korg1212
);
2340 snd_korg1212_EnableCardInterrupts(korg1212
);
2342 mdelay(CARD_BOOT_DELAY_IN_MS
);
2344 if (snd_korg1212_downloadDSPCode(korg1212
))
2347 K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], "
2348 "PlayDataPhy = %08x L[%08x]\n"
2349 "korg1212: RecDataPhy = %08x L[%08x], "
2350 "VolumeTablePhy = %08x L[%08x]\n"
2351 "korg1212: RoutingTablePhy = %08x L[%08x], "
2352 "AdatTimeCodePhy = %08x L[%08x]\n",
2353 (int)korg1212
->dma_dsp
.addr
, UpperWordSwap(korg1212
->dma_dsp
.addr
),
2354 korg1212
->PlayDataPhy
, LowerWordSwap(korg1212
->PlayDataPhy
),
2355 korg1212
->RecDataPhy
, LowerWordSwap(korg1212
->RecDataPhy
),
2356 korg1212
->VolumeTablePhy
, LowerWordSwap(korg1212
->VolumeTablePhy
),
2357 korg1212
->RoutingTablePhy
, LowerWordSwap(korg1212
->RoutingTablePhy
),
2358 korg1212
->AdatTimeCodePhy
, LowerWordSwap(korg1212
->AdatTimeCodePhy
));
2360 if ((err
= snd_pcm_new(korg1212
->card
, "korg1212", 0, 1, 1, &korg1212
->pcm
)) < 0)
2363 korg1212
->pcm
->private_data
= korg1212
;
2364 korg1212
->pcm
->private_free
= snd_korg1212_free_pcm
;
2365 strcpy(korg1212
->pcm
->name
, "korg1212");
2367 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_korg1212_playback_ops
);
2369 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_korg1212_capture_ops
);
2371 korg1212
->pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
2373 for (i
= 0; i
< ARRAY_SIZE(snd_korg1212_controls
); i
++) {
2374 err
= snd_ctl_add(korg1212
->card
, snd_ctl_new1(&snd_korg1212_controls
[i
], korg1212
));
2379 snd_korg1212_proc_init(korg1212
);
2381 snd_card_set_dev(card
, &pci
->dev
);
2389 * Card initialisation
2392 static int __devinit
2393 snd_korg1212_probe(struct pci_dev
*pci
,
2394 const struct pci_device_id
*pci_id
)
2397 struct snd_korg1212
*korg1212
;
2398 struct snd_card
*card
;
2401 if (dev
>= SNDRV_CARDS
) {
2408 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
2412 if ((err
= snd_korg1212_create(card
, pci
, &korg1212
)) < 0) {
2413 snd_card_free(card
);
2417 strcpy(card
->driver
, "korg1212");
2418 strcpy(card
->shortname
, "korg1212");
2419 sprintf(card
->longname
, "%s at 0x%lx, irq %d", card
->shortname
,
2420 korg1212
->iomem
, korg1212
->irq
);
2422 K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card
->longname
);
2424 if ((err
= snd_card_register(card
)) < 0) {
2425 snd_card_free(card
);
2428 pci_set_drvdata(pci
, card
);
2433 static void __devexit
snd_korg1212_remove(struct pci_dev
*pci
)
2435 snd_card_free(pci_get_drvdata(pci
));
2436 pci_set_drvdata(pci
, NULL
);
2439 static struct pci_driver driver
= {
2441 .id_table
= snd_korg1212_ids
,
2442 .probe
= snd_korg1212_probe
,
2443 .remove
= __devexit_p(snd_korg1212_remove
),
2446 static int __init
alsa_card_korg1212_init(void)
2448 return pci_register_driver(&driver
);
2451 static void __exit
alsa_card_korg1212_exit(void)
2453 pci_unregister_driver(&driver
);
2456 module_init(alsa_card_korg1212_init
)
2457 module_exit(alsa_card_korg1212_exit
)