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
[] __devinitdata
= {
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
, struct pt_regs
*regs
)
1125 struct snd_korg1212
*korg1212
= dev_id
;
1127 if(irq
!= korg1212
->irq
)
1130 doorbellValue
= readl(korg1212
->inDoorbellPtr
);
1135 spin_lock(&korg1212
->lock
);
1137 writel(doorbellValue
, korg1212
->inDoorbellPtr
);
1139 korg1212
->irqcount
++;
1144 switch (doorbellValue
) {
1145 case K1212_DB_DSPDownloadDone
:
1146 K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n",
1147 korg1212
->irqcount
, doorbellValue
,
1148 stateName
[korg1212
->cardState
]);
1149 if (korg1212
->cardState
== K1212_STATE_DSP_IN_PROCESS
) {
1150 korg1212
->dsp_is_loaded
= 1;
1151 wake_up(&korg1212
->wait
);
1155 // ------------------------------------------------------------------------
1156 // an error occurred - stop the card
1157 // ------------------------------------------------------------------------
1158 case K1212_DB_DMAERROR
:
1159 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n",
1160 korg1212
->irqcount
, doorbellValue
,
1161 stateName
[korg1212
->cardState
]);
1162 snd_printk(KERN_ERR
"korg1212: DMA Error\n");
1163 korg1212
->errorcnt
++;
1164 korg1212
->totalerrorcnt
++;
1165 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1166 snd_korg1212_setCardState(korg1212
, K1212_STATE_ERRORSTOP
);
1169 // ------------------------------------------------------------------------
1170 // the card has stopped by our request. Clear the command word and signal
1171 // the semaphore in case someone is waiting for this.
1172 // ------------------------------------------------------------------------
1173 case K1212_DB_CARDSTOPPED
:
1174 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n",
1175 korg1212
->irqcount
, doorbellValue
,
1176 stateName
[korg1212
->cardState
]);
1177 korg1212
->sharedBufferPtr
->cardCommand
= 0;
1181 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n",
1182 korg1212
->irqcount
, doorbellValue
,
1183 korg1212
->currentBuffer
, stateName
[korg1212
->cardState
]);
1184 if ((korg1212
->cardState
> K1212_STATE_SETUP
) || korg1212
->idleMonitorOn
) {
1185 korg1212
->currentBuffer
++;
1187 if (korg1212
->currentBuffer
>= kNumBuffers
)
1188 korg1212
->currentBuffer
= 0;
1190 if (!korg1212
->running
)
1193 if (korg1212
->capture_substream
) {
1194 spin_unlock(&korg1212
->lock
);
1195 snd_pcm_period_elapsed(korg1212
->capture_substream
);
1196 spin_lock(&korg1212
->lock
);
1199 if (korg1212
->playback_substream
) {
1200 spin_unlock(&korg1212
->lock
);
1201 snd_pcm_period_elapsed(korg1212
->playback_substream
);
1202 spin_lock(&korg1212
->lock
);
1210 spin_unlock(&korg1212
->lock
);
1215 static int snd_korg1212_downloadDSPCode(struct snd_korg1212
*korg1212
)
1219 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n",
1220 stateName
[korg1212
->cardState
]);
1222 // ---------------------------------------------------------------
1223 // verify the state of the card before proceeding.
1224 // ---------------------------------------------------------------
1225 if (korg1212
->cardState
>= K1212_STATE_DSP_IN_PROCESS
)
1228 snd_korg1212_setCardState(korg1212
, K1212_STATE_DSP_IN_PROCESS
);
1230 memcpy(korg1212
->dma_dsp
.area
, dspCode
, korg1212
->dspCodeSize
);
1232 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_StartDSPDownload
,
1233 UpperWordSwap(korg1212
->dma_dsp
.addr
),
1236 K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n",
1237 rc
, stateName
[korg1212
->cardState
]);
1239 korg1212
->dsp_is_loaded
= 0;
1240 wait_event_timeout(korg1212
->wait
, korg1212
->dsp_is_loaded
, HZ
* CARD_BOOT_TIMEOUT
);
1241 if (! korg1212
->dsp_is_loaded
)
1242 return -EBUSY
; /* timeout */
1244 snd_korg1212_OnDSPDownloadComplete(korg1212
);
1249 static struct snd_pcm_hardware snd_korg1212_playback_info
=
1251 .info
= (SNDRV_PCM_INFO_MMAP
|
1252 SNDRV_PCM_INFO_MMAP_VALID
|
1253 SNDRV_PCM_INFO_INTERLEAVED
),
1254 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1255 .rates
= (SNDRV_PCM_RATE_44100
|
1256 SNDRV_PCM_RATE_48000
),
1259 .channels_min
= K1212_MIN_CHANNELS
,
1260 .channels_max
= K1212_MAX_CHANNELS
,
1261 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1262 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1263 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1264 .periods_min
= K1212_PERIODS
,
1265 .periods_max
= K1212_PERIODS
,
1269 static struct snd_pcm_hardware snd_korg1212_capture_info
=
1271 .info
= (SNDRV_PCM_INFO_MMAP
|
1272 SNDRV_PCM_INFO_MMAP_VALID
|
1273 SNDRV_PCM_INFO_INTERLEAVED
),
1274 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1275 .rates
= (SNDRV_PCM_RATE_44100
|
1276 SNDRV_PCM_RATE_48000
),
1279 .channels_min
= K1212_MIN_CHANNELS
,
1280 .channels_max
= K1212_MAX_CHANNELS
,
1281 .buffer_bytes_max
= K1212_MAX_BUF_SIZE
,
1282 .period_bytes_min
= K1212_MIN_CHANNELS
* 2 * kPlayBufferFrames
,
1283 .period_bytes_max
= K1212_MAX_CHANNELS
* 2 * kPlayBufferFrames
,
1284 .periods_min
= K1212_PERIODS
,
1285 .periods_max
= K1212_PERIODS
,
1289 static int snd_korg1212_silence(struct snd_korg1212
*korg1212
, int pos
, int count
, int offset
, int size
)
1291 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1294 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n",
1295 pos
, offset
, size
, count
);
1296 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1298 for (i
=0; i
< count
; i
++) {
1299 #if K1212_DEBUG_LEVEL > 0
1300 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1301 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1302 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n",
1307 memset((void*) dst
+ offset
, 0, size
);
1314 static int snd_korg1212_copy_to(struct snd_korg1212
*korg1212
, void __user
*dst
, int pos
, int count
, int offset
, int size
)
1316 struct KorgAudioFrame
* src
= korg1212
->recordDataBufsPtr
[0].bufferData
+ pos
;
1319 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n",
1321 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1323 for (i
=0; i
< count
; i
++) {
1324 #if K1212_DEBUG_LEVEL > 0
1325 if ( (void *) src
< (void *) korg1212
->recordDataBufsPtr
||
1326 (void *) src
> (void *) korg1212
->recordDataBufsPtr
[8].bufferData
) {
1327 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1331 rc
= copy_to_user(dst
+ offset
, src
, size
);
1333 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1343 static int snd_korg1212_copy_from(struct snd_korg1212
*korg1212
, void __user
*src
, int pos
, int count
, int offset
, int size
)
1345 struct KorgAudioFrame
* dst
= korg1212
->playDataBufsPtr
[0].bufferData
+ pos
;
1348 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n",
1349 pos
, offset
, size
, count
);
1351 snd_assert(pos
+ count
<= K1212_MAX_SAMPLES
, return -EINVAL
);
1353 for (i
=0; i
< count
; i
++) {
1354 #if K1212_DEBUG_LEVEL > 0
1355 if ( (void *) dst
< (void *) korg1212
->playDataBufsPtr
||
1356 (void *) dst
> (void *) korg1212
->playDataBufsPtr
[8].bufferData
) {
1357 printk(KERN_DEBUG
"K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src
, dst
, i
);
1361 rc
= copy_from_user((void*) dst
+ offset
, src
, size
);
1363 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src
, dst
, i
);
1373 static void snd_korg1212_free_pcm(struct snd_pcm
*pcm
)
1375 struct snd_korg1212
*korg1212
= pcm
->private_data
;
1377 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n",
1378 stateName
[korg1212
->cardState
]);
1380 korg1212
->pcm
= NULL
;
1383 static int snd_korg1212_playback_open(struct snd_pcm_substream
*substream
)
1385 unsigned long flags
;
1386 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1387 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1389 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n",
1390 stateName
[korg1212
->cardState
]);
1392 snd_pcm_set_sync(substream
); // ???
1394 snd_korg1212_OpenCard(korg1212
);
1396 runtime
->hw
= snd_korg1212_playback_info
;
1397 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_play
);
1399 spin_lock_irqsave(&korg1212
->lock
, flags
);
1401 korg1212
->playback_substream
= substream
;
1402 korg1212
->playback_pid
= current
->pid
;
1403 korg1212
->periodsize
= K1212_PERIODS
;
1404 korg1212
->channels
= K1212_CHANNELS
;
1405 korg1212
->errorcnt
= 0;
1407 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1409 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, kPlayBufferFrames
, kPlayBufferFrames
);
1414 static int snd_korg1212_capture_open(struct snd_pcm_substream
*substream
)
1416 unsigned long flags
;
1417 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1418 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1420 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n",
1421 stateName
[korg1212
->cardState
]);
1423 snd_pcm_set_sync(substream
);
1425 snd_korg1212_OpenCard(korg1212
);
1427 runtime
->hw
= snd_korg1212_capture_info
;
1428 snd_pcm_set_runtime_buffer(substream
, &korg1212
->dma_rec
);
1430 spin_lock_irqsave(&korg1212
->lock
, flags
);
1432 korg1212
->capture_substream
= substream
;
1433 korg1212
->capture_pid
= current
->pid
;
1434 korg1212
->periodsize
= K1212_PERIODS
;
1435 korg1212
->channels
= K1212_CHANNELS
;
1437 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1439 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1440 kPlayBufferFrames
, kPlayBufferFrames
);
1444 static int snd_korg1212_playback_close(struct snd_pcm_substream
*substream
)
1446 unsigned long flags
;
1447 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1449 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n",
1450 stateName
[korg1212
->cardState
]);
1452 snd_korg1212_silence(korg1212
, 0, K1212_MAX_SAMPLES
, 0, korg1212
->channels
* 2);
1454 spin_lock_irqsave(&korg1212
->lock
, flags
);
1456 korg1212
->playback_pid
= -1;
1457 korg1212
->playback_substream
= NULL
;
1458 korg1212
->periodsize
= 0;
1460 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1462 snd_korg1212_CloseCard(korg1212
);
1466 static int snd_korg1212_capture_close(struct snd_pcm_substream
*substream
)
1468 unsigned long flags
;
1469 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1471 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n",
1472 stateName
[korg1212
->cardState
]);
1474 spin_lock_irqsave(&korg1212
->lock
, flags
);
1476 korg1212
->capture_pid
= -1;
1477 korg1212
->capture_substream
= NULL
;
1478 korg1212
->periodsize
= 0;
1480 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1482 snd_korg1212_CloseCard(korg1212
);
1486 static int snd_korg1212_ioctl(struct snd_pcm_substream
*substream
,
1487 unsigned int cmd
, void *arg
)
1489 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd
);
1491 if (cmd
== SNDRV_PCM_IOCTL1_CHANNEL_INFO
) {
1492 struct snd_pcm_channel_info
*info
= arg
;
1494 info
->first
= info
->channel
* 16;
1496 K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info
->channel
, info
->offset
, info
->first
, info
->step
);
1500 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1503 static int snd_korg1212_hw_params(struct snd_pcm_substream
*substream
,
1504 struct snd_pcm_hw_params
*params
)
1506 unsigned long flags
;
1507 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1512 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n",
1513 stateName
[korg1212
->cardState
]);
1515 spin_lock_irqsave(&korg1212
->lock
, flags
);
1517 if (substream
->pstr
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1518 this_pid
= korg1212
->playback_pid
;
1519 other_pid
= korg1212
->capture_pid
;
1521 this_pid
= korg1212
->capture_pid
;
1522 other_pid
= korg1212
->playback_pid
;
1525 if ((other_pid
> 0) && (this_pid
!= other_pid
)) {
1527 /* The other stream is open, and not by the same
1528 task as this one. Make sure that the parameters
1529 that matter are the same.
1532 if ((int)params_rate(params
) != korg1212
->clkRate
) {
1533 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1534 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
1538 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1542 if ((err
= snd_korg1212_SetRate(korg1212
, params_rate(params
))) < 0) {
1543 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1547 korg1212
->channels
= params_channels(params
);
1548 korg1212
->periodsize
= K1212_PERIOD_BYTES
;
1550 spin_unlock_irqrestore(&korg1212
->lock
, flags
);
1555 static int snd_korg1212_prepare(struct snd_pcm_substream
*substream
)
1557 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1560 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n",
1561 stateName
[korg1212
->cardState
]);
1563 spin_lock_irq(&korg1212
->lock
);
1565 /* FIXME: we should wait for ack! */
1566 if (korg1212
->stop_pending_cnt
> 0) {
1567 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n",
1568 stateName
[korg1212
->cardState
]);
1569 spin_unlock_irq(&korg1212
->lock
);
1572 korg1212->sharedBufferPtr->cardCommand = 0;
1573 del_timer(&korg1212->timer);
1574 korg1212->stop_pending_cnt = 0;
1578 rc
= snd_korg1212_SetupForPlay(korg1212
);
1580 korg1212
->currentBuffer
= 0;
1582 spin_unlock_irq(&korg1212
->lock
);
1584 return rc
? -EINVAL
: 0;
1587 static int snd_korg1212_trigger(struct snd_pcm_substream
*substream
,
1590 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1593 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n",
1594 stateName
[korg1212
->cardState
], cmd
);
1596 spin_lock(&korg1212
->lock
);
1598 case SNDRV_PCM_TRIGGER_START
:
1600 if (korg1212->running) {
1601 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n");
1605 korg1212
->running
++;
1606 rc
= snd_korg1212_TriggerPlay(korg1212
);
1609 case SNDRV_PCM_TRIGGER_STOP
:
1611 if (!korg1212->running) {
1612 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n");
1616 korg1212
->running
--;
1617 rc
= snd_korg1212_StopPlay(korg1212
);
1624 spin_unlock(&korg1212
->lock
);
1625 return rc
? -EINVAL
: 0;
1628 static snd_pcm_uframes_t
snd_korg1212_playback_pointer(struct snd_pcm_substream
*substream
)
1630 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1631 snd_pcm_uframes_t pos
;
1633 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1635 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n",
1636 stateName
[korg1212
->cardState
], pos
);
1641 static snd_pcm_uframes_t
snd_korg1212_capture_pointer(struct snd_pcm_substream
*substream
)
1643 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1644 snd_pcm_uframes_t pos
;
1646 pos
= korg1212
->currentBuffer
* kPlayBufferFrames
;
1648 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n",
1649 stateName
[korg1212
->cardState
], pos
);
1654 static int snd_korg1212_playback_copy(struct snd_pcm_substream
*substream
,
1655 int channel
, /* not used (interleaved data) */
1656 snd_pcm_uframes_t pos
,
1658 snd_pcm_uframes_t count
)
1660 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1662 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n",
1663 stateName
[korg1212
->cardState
], pos
, count
);
1665 return snd_korg1212_copy_from(korg1212
, src
, pos
, count
, 0, korg1212
->channels
* 2);
1669 static int snd_korg1212_playback_silence(struct snd_pcm_substream
*substream
,
1670 int channel
, /* not used (interleaved data) */
1671 snd_pcm_uframes_t pos
,
1672 snd_pcm_uframes_t count
)
1674 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1676 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n",
1677 stateName
[korg1212
->cardState
]);
1679 return snd_korg1212_silence(korg1212
, pos
, count
, 0, korg1212
->channels
* 2);
1682 static int snd_korg1212_capture_copy(struct snd_pcm_substream
*substream
,
1683 int channel
, /* not used (interleaved data) */
1684 snd_pcm_uframes_t pos
,
1686 snd_pcm_uframes_t count
)
1688 struct snd_korg1212
*korg1212
= snd_pcm_substream_chip(substream
);
1690 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n",
1691 stateName
[korg1212
->cardState
], pos
, count
);
1693 return snd_korg1212_copy_to(korg1212
, dst
, pos
, count
, 0, korg1212
->channels
* 2);
1696 static struct snd_pcm_ops snd_korg1212_playback_ops
= {
1697 .open
= snd_korg1212_playback_open
,
1698 .close
= snd_korg1212_playback_close
,
1699 .ioctl
= snd_korg1212_ioctl
,
1700 .hw_params
= snd_korg1212_hw_params
,
1701 .prepare
= snd_korg1212_prepare
,
1702 .trigger
= snd_korg1212_trigger
,
1703 .pointer
= snd_korg1212_playback_pointer
,
1704 .copy
= snd_korg1212_playback_copy
,
1705 .silence
= snd_korg1212_playback_silence
,
1708 static struct snd_pcm_ops snd_korg1212_capture_ops
= {
1709 .open
= snd_korg1212_capture_open
,
1710 .close
= snd_korg1212_capture_close
,
1711 .ioctl
= snd_korg1212_ioctl
,
1712 .hw_params
= snd_korg1212_hw_params
,
1713 .prepare
= snd_korg1212_prepare
,
1714 .trigger
= snd_korg1212_trigger
,
1715 .pointer
= snd_korg1212_capture_pointer
,
1716 .copy
= snd_korg1212_capture_copy
,
1723 static int snd_korg1212_control_phase_info(struct snd_kcontrol
*kcontrol
,
1724 struct snd_ctl_elem_info
*uinfo
)
1726 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1727 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1731 static int snd_korg1212_control_phase_get(struct snd_kcontrol
*kcontrol
,
1732 struct snd_ctl_elem_value
*u
)
1734 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1735 int i
= kcontrol
->private_value
;
1737 spin_lock_irq(&korg1212
->lock
);
1739 u
->value
.integer
.value
[0] = korg1212
->volumePhase
[i
];
1742 u
->value
.integer
.value
[1] = korg1212
->volumePhase
[i
+1];
1744 spin_unlock_irq(&korg1212
->lock
);
1749 static int snd_korg1212_control_phase_put(struct snd_kcontrol
*kcontrol
,
1750 struct snd_ctl_elem_value
*u
)
1752 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1756 spin_lock_irq(&korg1212
->lock
);
1758 i
= kcontrol
->private_value
;
1760 korg1212
->volumePhase
[i
] = u
->value
.integer
.value
[0];
1762 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
];
1764 if ((u
->value
.integer
.value
[0] > 0) != (val
< 0)) {
1765 val
= abs(val
) * (korg1212
->volumePhase
[i
] > 0 ? -1 : 1);
1766 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1771 korg1212
->volumePhase
[i
+1] = u
->value
.integer
.value
[1];
1773 val
= korg1212
->sharedBufferPtr
->volumeData
[kcontrol
->private_value
+1];
1775 if ((u
->value
.integer
.value
[1] > 0) != (val
< 0)) {
1776 val
= abs(val
) * (korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1);
1777 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1782 spin_unlock_irq(&korg1212
->lock
);
1787 static int snd_korg1212_control_volume_info(struct snd_kcontrol
*kcontrol
,
1788 struct snd_ctl_elem_info
*uinfo
)
1790 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1791 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1792 uinfo
->value
.integer
.min
= k1212MinVolume
;
1793 uinfo
->value
.integer
.max
= k1212MaxVolume
;
1797 static int snd_korg1212_control_volume_get(struct snd_kcontrol
*kcontrol
,
1798 struct snd_ctl_elem_value
*u
)
1800 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1803 spin_lock_irq(&korg1212
->lock
);
1805 i
= kcontrol
->private_value
;
1806 u
->value
.integer
.value
[0] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
]);
1809 u
->value
.integer
.value
[1] = abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1]);
1811 spin_unlock_irq(&korg1212
->lock
);
1816 static int snd_korg1212_control_volume_put(struct snd_kcontrol
*kcontrol
,
1817 struct snd_ctl_elem_value
*u
)
1819 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1824 spin_lock_irq(&korg1212
->lock
);
1826 i
= kcontrol
->private_value
;
1828 if (u
->value
.integer
.value
[0] != abs(korg1212
->sharedBufferPtr
->volumeData
[i
])) {
1829 val
= korg1212
->volumePhase
[i
] > 0 ? -1 : 1;
1830 val
*= u
->value
.integer
.value
[0];
1831 korg1212
->sharedBufferPtr
->volumeData
[i
] = val
;
1836 if (u
->value
.integer
.value
[1] != abs(korg1212
->sharedBufferPtr
->volumeData
[i
+1])) {
1837 val
= korg1212
->volumePhase
[i
+1] > 0 ? -1 : 1;
1838 val
*= u
->value
.integer
.value
[1];
1839 korg1212
->sharedBufferPtr
->volumeData
[i
+1] = val
;
1844 spin_unlock_irq(&korg1212
->lock
);
1849 static int snd_korg1212_control_route_info(struct snd_kcontrol
*kcontrol
,
1850 struct snd_ctl_elem_info
*uinfo
)
1852 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1853 uinfo
->count
= (kcontrol
->private_value
>= 8) ? 2 : 1;
1854 uinfo
->value
.enumerated
.items
= kAudioChannels
;
1855 if (uinfo
->value
.enumerated
.item
> kAudioChannels
-1) {
1856 uinfo
->value
.enumerated
.item
= kAudioChannels
-1;
1858 strcpy(uinfo
->value
.enumerated
.name
, channelName
[uinfo
->value
.enumerated
.item
]);
1862 static int snd_korg1212_control_route_get(struct snd_kcontrol
*kcontrol
,
1863 struct snd_ctl_elem_value
*u
)
1865 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1868 spin_lock_irq(&korg1212
->lock
);
1870 i
= kcontrol
->private_value
;
1871 u
->value
.enumerated
.item
[0] = korg1212
->sharedBufferPtr
->routeData
[i
];
1874 u
->value
.enumerated
.item
[1] = korg1212
->sharedBufferPtr
->routeData
[i
+1];
1876 spin_unlock_irq(&korg1212
->lock
);
1881 static int snd_korg1212_control_route_put(struct snd_kcontrol
*kcontrol
,
1882 struct snd_ctl_elem_value
*u
)
1884 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1887 spin_lock_irq(&korg1212
->lock
);
1889 i
= kcontrol
->private_value
;
1891 if (u
->value
.enumerated
.item
[0] != (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
]) {
1892 korg1212
->sharedBufferPtr
->routeData
[i
] = u
->value
.enumerated
.item
[0];
1897 if (u
->value
.enumerated
.item
[1] != (unsigned) korg1212
->sharedBufferPtr
->volumeData
[i
+1]) {
1898 korg1212
->sharedBufferPtr
->routeData
[i
+1] = u
->value
.enumerated
.item
[1];
1903 spin_unlock_irq(&korg1212
->lock
);
1908 static int snd_korg1212_control_info(struct snd_kcontrol
*kcontrol
,
1909 struct snd_ctl_elem_info
*uinfo
)
1911 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1913 uinfo
->value
.integer
.min
= k1212MaxADCSens
;
1914 uinfo
->value
.integer
.max
= k1212MinADCSens
;
1918 static int snd_korg1212_control_get(struct snd_kcontrol
*kcontrol
,
1919 struct snd_ctl_elem_value
*u
)
1921 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1923 spin_lock_irq(&korg1212
->lock
);
1925 u
->value
.integer
.value
[0] = korg1212
->leftADCInSens
;
1926 u
->value
.integer
.value
[1] = korg1212
->rightADCInSens
;
1928 spin_unlock_irq(&korg1212
->lock
);
1933 static int snd_korg1212_control_put(struct snd_kcontrol
*kcontrol
,
1934 struct snd_ctl_elem_value
*u
)
1936 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1939 spin_lock_irq(&korg1212
->lock
);
1941 if (u
->value
.integer
.value
[0] != korg1212
->leftADCInSens
) {
1942 korg1212
->leftADCInSens
= u
->value
.integer
.value
[0];
1945 if (u
->value
.integer
.value
[1] != korg1212
->rightADCInSens
) {
1946 korg1212
->rightADCInSens
= u
->value
.integer
.value
[1];
1950 spin_unlock_irq(&korg1212
->lock
);
1953 snd_korg1212_WriteADCSensitivity(korg1212
);
1958 static int snd_korg1212_control_sync_info(struct snd_kcontrol
*kcontrol
,
1959 struct snd_ctl_elem_info
*uinfo
)
1961 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1963 uinfo
->value
.enumerated
.items
= 3;
1964 if (uinfo
->value
.enumerated
.item
> 2) {
1965 uinfo
->value
.enumerated
.item
= 2;
1967 strcpy(uinfo
->value
.enumerated
.name
, clockSourceTypeName
[uinfo
->value
.enumerated
.item
]);
1971 static int snd_korg1212_control_sync_get(struct snd_kcontrol
*kcontrol
,
1972 struct snd_ctl_elem_value
*ucontrol
)
1974 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1976 spin_lock_irq(&korg1212
->lock
);
1978 ucontrol
->value
.enumerated
.item
[0] = korg1212
->clkSource
;
1980 spin_unlock_irq(&korg1212
->lock
);
1984 static int snd_korg1212_control_sync_put(struct snd_kcontrol
*kcontrol
,
1985 struct snd_ctl_elem_value
*ucontrol
)
1987 struct snd_korg1212
*korg1212
= snd_kcontrol_chip(kcontrol
);
1991 val
= ucontrol
->value
.enumerated
.item
[0] % 3;
1992 spin_lock_irq(&korg1212
->lock
);
1993 change
= val
!= korg1212
->clkSource
;
1994 snd_korg1212_SetClockSource(korg1212
, val
);
1995 spin_unlock_irq(&korg1212
->lock
);
1999 #define MON_MIXER(ord,c_name) \
2001 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
2002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2003 .name = c_name " Monitor Volume", \
2004 .info = snd_korg1212_control_volume_info, \
2005 .get = snd_korg1212_control_volume_get, \
2006 .put = snd_korg1212_control_volume_put, \
2007 .private_value = ord, \
2010 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
2011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2012 .name = c_name " Monitor Route", \
2013 .info = snd_korg1212_control_route_info, \
2014 .get = snd_korg1212_control_route_get, \
2015 .put = snd_korg1212_control_route_put, \
2016 .private_value = ord, \
2019 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \
2020 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2021 .name = c_name " Monitor Phase Invert", \
2022 .info = snd_korg1212_control_phase_info, \
2023 .get = snd_korg1212_control_phase_get, \
2024 .put = snd_korg1212_control_phase_put, \
2025 .private_value = ord, \
2028 static struct snd_kcontrol_new snd_korg1212_controls
[] = {
2029 MON_MIXER(8, "Analog"),
2030 MON_MIXER(10, "SPDIF"),
2031 MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"),
2032 MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"),
2034 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
2035 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2036 .name
= "Sync Source",
2037 .info
= snd_korg1212_control_sync_info
,
2038 .get
= snd_korg1212_control_sync_get
,
2039 .put
= snd_korg1212_control_sync_put
,
2042 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_WRITE
,
2043 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2044 .name
= "ADC Attenuation",
2045 .info
= snd_korg1212_control_info
,
2046 .get
= snd_korg1212_control_get
,
2047 .put
= snd_korg1212_control_put
,
2055 static void snd_korg1212_proc_read(struct snd_info_entry
*entry
,
2056 struct snd_info_buffer
*buffer
)
2059 struct snd_korg1212
*korg1212
= entry
->private_data
;
2061 snd_iprintf(buffer
, korg1212
->card
->longname
);
2062 snd_iprintf(buffer
, " (index #%d)\n", korg1212
->card
->number
+ 1);
2063 snd_iprintf(buffer
, "\nGeneral settings\n");
2064 snd_iprintf(buffer
, " period size: %Zd bytes\n", K1212_PERIOD_BYTES
);
2065 snd_iprintf(buffer
, " clock mode: %s\n", clockSourceName
[korg1212
->clkSrcRate
] );
2066 snd_iprintf(buffer
, " left ADC Sens: %d\n", korg1212
->leftADCInSens
);
2067 snd_iprintf(buffer
, " right ADC Sens: %d\n", korg1212
->rightADCInSens
);
2068 snd_iprintf(buffer
, " Volume Info:\n");
2069 for (n
=0; n
<kAudioChannels
; n
++)
2070 snd_iprintf(buffer
, " Channel %d: %s -> %s [%d]\n", n
,
2072 channelName
[korg1212
->sharedBufferPtr
->routeData
[n
]],
2073 korg1212
->sharedBufferPtr
->volumeData
[n
]);
2074 snd_iprintf(buffer
, "\nGeneral status\n");
2075 snd_iprintf(buffer
, " ADAT Time Code: %d\n", korg1212
->sharedBufferPtr
->AdatTimeCode
);
2076 snd_iprintf(buffer
, " Card State: %s\n", stateName
[korg1212
->cardState
]);
2077 snd_iprintf(buffer
, "Idle mon. State: %d\n", korg1212
->idleMonitorOn
);
2078 snd_iprintf(buffer
, "Cmd retry count: %d\n", korg1212
->cmdRetryCount
);
2079 snd_iprintf(buffer
, " Irq count: %ld\n", korg1212
->irqcount
);
2080 snd_iprintf(buffer
, " Error count: %ld\n", korg1212
->totalerrorcnt
);
2083 static void __devinit
snd_korg1212_proc_init(struct snd_korg1212
*korg1212
)
2085 struct snd_info_entry
*entry
;
2087 if (! snd_card_proc_new(korg1212
->card
, "korg1212", &entry
))
2088 snd_info_set_text_ops(entry
, korg1212
, 1024, snd_korg1212_proc_read
);
2092 snd_korg1212_free(struct snd_korg1212
*korg1212
)
2094 snd_korg1212_TurnOffIdleMonitor(korg1212
);
2096 if (korg1212
->irq
>= 0) {
2097 synchronize_irq(korg1212
->irq
);
2098 snd_korg1212_DisableCardInterrupts(korg1212
);
2099 free_irq(korg1212
->irq
, korg1212
);
2103 if (korg1212
->iobase
!= NULL
) {
2104 iounmap(korg1212
->iobase
);
2105 korg1212
->iobase
= NULL
;
2108 pci_release_regions(korg1212
->pci
);
2110 // ----------------------------------------------------
2111 // free up memory resources used for the DSP download.
2112 // ----------------------------------------------------
2113 if (korg1212
->dma_dsp
.area
) {
2114 snd_dma_free_pages(&korg1212
->dma_dsp
);
2115 korg1212
->dma_dsp
.area
= NULL
;
2118 #ifndef K1212_LARGEALLOC
2120 // ------------------------------------------------------
2121 // free up memory resources used for the Play/Rec Buffers
2122 // ------------------------------------------------------
2123 if (korg1212
->dma_play
.area
) {
2124 snd_dma_free_pages(&korg1212
->dma_play
);
2125 korg1212
->dma_play
.area
= NULL
;
2128 if (korg1212
->dma_rec
.area
) {
2129 snd_dma_free_pages(&korg1212
->dma_rec
);
2130 korg1212
->dma_rec
.area
= NULL
;
2135 // ----------------------------------------------------
2136 // free up memory resources used for the Shared Buffers
2137 // ----------------------------------------------------
2138 if (korg1212
->dma_shared
.area
) {
2139 snd_dma_free_pages(&korg1212
->dma_shared
);
2140 korg1212
->dma_shared
.area
= NULL
;
2143 pci_disable_device(korg1212
->pci
);
2148 static int snd_korg1212_dev_free(struct snd_device
*device
)
2150 struct snd_korg1212
*korg1212
= device
->device_data
;
2151 K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n");
2152 return snd_korg1212_free(korg1212
);
2155 static int __devinit
snd_korg1212_create(struct snd_card
*card
, struct pci_dev
*pci
,
2156 struct snd_korg1212
** rchip
)
2161 unsigned ioport_size
, iomem_size
, iomem2_size
;
2162 struct snd_korg1212
* korg1212
;
2164 static struct snd_device_ops ops
= {
2165 .dev_free
= snd_korg1212_dev_free
,
2169 if ((err
= pci_enable_device(pci
)) < 0)
2172 korg1212
= kzalloc(sizeof(*korg1212
), GFP_KERNEL
);
2173 if (korg1212
== NULL
) {
2174 pci_disable_device(pci
);
2178 korg1212
->card
= card
;
2179 korg1212
->pci
= pci
;
2181 init_waitqueue_head(&korg1212
->wait
);
2182 spin_lock_init(&korg1212
->lock
);
2183 mutex_init(&korg1212
->open_mutex
);
2184 init_timer(&korg1212
->timer
);
2185 korg1212
->timer
.function
= snd_korg1212_timer_func
;
2186 korg1212
->timer
.data
= (unsigned long)korg1212
;
2189 korg1212
->clkSource
= K1212_CLKIDX_Local
;
2190 korg1212
->clkRate
= 44100;
2191 korg1212
->inIRQ
= 0;
2192 korg1212
->running
= 0;
2193 korg1212
->opencnt
= 0;
2194 korg1212
->playcnt
= 0;
2195 korg1212
->setcnt
= 0;
2196 korg1212
->totalerrorcnt
= 0;
2197 korg1212
->playback_pid
= -1;
2198 korg1212
->capture_pid
= -1;
2199 snd_korg1212_setCardState(korg1212
, K1212_STATE_UNINITIALIZED
);
2200 korg1212
->idleMonitorOn
= 0;
2201 korg1212
->clkSrcRate
= K1212_CLKIDX_LocalAt44_1K
;
2202 korg1212
->leftADCInSens
= k1212MaxADCSens
;
2203 korg1212
->rightADCInSens
= k1212MaxADCSens
;
2205 for (i
=0; i
<kAudioChannels
; i
++)
2206 korg1212
->volumePhase
[i
] = 0;
2208 if ((err
= pci_request_regions(pci
, "korg1212")) < 0) {
2210 pci_disable_device(pci
);
2214 korg1212
->iomem
= pci_resource_start(korg1212
->pci
, 0);
2215 korg1212
->ioport
= pci_resource_start(korg1212
->pci
, 1);
2216 korg1212
->iomem2
= pci_resource_start(korg1212
->pci
, 2);
2218 iomem_size
= pci_resource_len(korg1212
->pci
, 0);
2219 ioport_size
= pci_resource_len(korg1212
->pci
, 1);
2220 iomem2_size
= pci_resource_len(korg1212
->pci
, 2);
2222 K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n"
2223 " iomem = 0x%lx (%d)\n"
2224 " ioport = 0x%lx (%d)\n"
2225 " iomem = 0x%lx (%d)\n"
2227 korg1212
->iomem
, iomem_size
,
2228 korg1212
->ioport
, ioport_size
,
2229 korg1212
->iomem2
, iomem2_size
,
2230 stateName
[korg1212
->cardState
]);
2232 if ((korg1212
->iobase
= ioremap(korg1212
->iomem
, iomem_size
)) == NULL
) {
2233 snd_printk(KERN_ERR
"korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212
->iomem
,
2234 korg1212
->iomem
+ iomem_size
- 1);
2235 snd_korg1212_free(korg1212
);
2239 err
= request_irq(pci
->irq
, snd_korg1212_interrupt
,
2240 SA_INTERRUPT
|SA_SHIRQ
,
2241 "korg1212", korg1212
);
2244 snd_printk(KERN_ERR
"korg1212: unable to grab IRQ %d\n", pci
->irq
);
2245 snd_korg1212_free(korg1212
);
2249 korg1212
->irq
= pci
->irq
;
2251 pci_set_master(korg1212
->pci
);
2253 korg1212
->statusRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ STATUS_REG_OFFSET
);
2254 korg1212
->outDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ OUT_DOORBELL_OFFSET
);
2255 korg1212
->inDoorbellPtr
= (u32 __iomem
*) (korg1212
->iobase
+ IN_DOORBELL_OFFSET
);
2256 korg1212
->mailbox0Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX0_OFFSET
);
2257 korg1212
->mailbox1Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX1_OFFSET
);
2258 korg1212
->mailbox2Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX2_OFFSET
);
2259 korg1212
->mailbox3Ptr
= (u32 __iomem
*) (korg1212
->iobase
+ MAILBOX3_OFFSET
);
2260 korg1212
->controlRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ PCI_CONTROL_OFFSET
);
2261 korg1212
->sensRegPtr
= (u16 __iomem
*) (korg1212
->iobase
+ SENS_CONTROL_OFFSET
);
2262 korg1212
->idRegPtr
= (u32 __iomem
*) (korg1212
->iobase
+ DEV_VEND_ID_OFFSET
);
2264 K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n"
2265 " Status register = 0x%p\n"
2266 " OutDoorbell = 0x%p\n"
2267 " InDoorbell = 0x%p\n"
2268 " Mailbox0 = 0x%p\n"
2269 " Mailbox1 = 0x%p\n"
2270 " Mailbox2 = 0x%p\n"
2271 " Mailbox3 = 0x%p\n"
2272 " ControlReg = 0x%p\n"
2276 korg1212
->statusRegPtr
,
2277 korg1212
->outDoorbellPtr
,
2278 korg1212
->inDoorbellPtr
,
2279 korg1212
->mailbox0Ptr
,
2280 korg1212
->mailbox1Ptr
,
2281 korg1212
->mailbox2Ptr
,
2282 korg1212
->mailbox3Ptr
,
2283 korg1212
->controlRegPtr
,
2284 korg1212
->sensRegPtr
,
2286 stateName
[korg1212
->cardState
]);
2288 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2289 sizeof(struct KorgSharedBuffer
), &korg1212
->dma_shared
) < 0) {
2290 snd_printk(KERN_ERR
"korg1212: can not allocate shared buffer memory (%Zd bytes)\n", sizeof(struct KorgSharedBuffer
));
2291 snd_korg1212_free(korg1212
);
2294 korg1212
->sharedBufferPtr
= (struct KorgSharedBuffer
*)korg1212
->dma_shared
.area
;
2295 korg1212
->sharedBufferPhy
= korg1212
->dma_shared
.addr
;
2297 K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212
->sharedBufferPtr
, korg1212
->sharedBufferPhy
, sizeof(struct KorgSharedBuffer
));
2299 #ifndef K1212_LARGEALLOC
2301 korg1212
->DataBufsSize
= sizeof(struct KorgAudioBuffer
) * kNumBuffers
;
2303 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2304 korg1212
->DataBufsSize
, &korg1212
->dma_play
) < 0) {
2305 snd_printk(KERN_ERR
"korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2306 snd_korg1212_free(korg1212
);
2309 korg1212
->playDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_play
.area
;
2310 korg1212
->PlayDataPhy
= korg1212
->dma_play
.addr
;
2312 K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n",
2313 korg1212
->playDataBufsPtr
, korg1212
->PlayDataPhy
, korg1212
->DataBufsSize
);
2315 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2316 korg1212
->DataBufsSize
, &korg1212
->dma_rec
) < 0) {
2317 snd_printk(KERN_ERR
"korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212
->DataBufsSize
);
2318 snd_korg1212_free(korg1212
);
2321 korg1212
->recordDataBufsPtr
= (struct KorgAudioBuffer
*)korg1212
->dma_rec
.area
;
2322 korg1212
->RecDataPhy
= korg1212
->dma_rec
.addr
;
2324 K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n",
2325 korg1212
->recordDataBufsPtr
, korg1212
->RecDataPhy
, korg1212
->DataBufsSize
);
2327 #else // K1212_LARGEALLOC
2329 korg1212
->recordDataBufsPtr
= korg1212
->sharedBufferPtr
->recordDataBufs
;
2330 korg1212
->playDataBufsPtr
= korg1212
->sharedBufferPtr
->playDataBufs
;
2331 korg1212
->PlayDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->playDataBufs
;
2332 korg1212
->RecDataPhy
= (u32
) &((struct KorgSharedBuffer
*) korg1212
->sharedBufferPhy
)->recordDataBufs
;
2334 #endif // K1212_LARGEALLOC
2336 korg1212
->dspCodeSize
= sizeof (dspCode
);
2338 korg1212
->VolumeTablePhy
= korg1212
->sharedBufferPhy
+
2339 offsetof(struct KorgSharedBuffer
, volumeData
);
2340 korg1212
->RoutingTablePhy
= korg1212
->sharedBufferPhy
+
2341 offsetof(struct KorgSharedBuffer
, routeData
);
2342 korg1212
->AdatTimeCodePhy
= korg1212
->sharedBufferPhy
+
2343 offsetof(struct KorgSharedBuffer
, AdatTimeCode
);
2345 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2346 korg1212
->dspCodeSize
, &korg1212
->dma_dsp
) < 0) {
2347 snd_printk(KERN_ERR
"korg1212: can not allocate dsp code memory (%d bytes)\n", korg1212
->dspCodeSize
);
2348 snd_korg1212_free(korg1212
);
2352 K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n",
2353 korg1212
->dma_dsp
.area
, korg1212
->dma_dsp
.addr
, korg1212
->dspCodeSize
,
2354 stateName
[korg1212
->cardState
]);
2356 rc
= snd_korg1212_Send1212Command(korg1212
, K1212_DB_RebootCard
, 0, 0, 0, 0);
2359 K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc
, stateName
[korg1212
->cardState
]);
2361 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, korg1212
, &ops
)) < 0) {
2362 snd_korg1212_free(korg1212
);
2366 snd_korg1212_EnableCardInterrupts(korg1212
);
2368 mdelay(CARD_BOOT_DELAY_IN_MS
);
2370 if (snd_korg1212_downloadDSPCode(korg1212
))
2373 K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], "
2374 "PlayDataPhy = %08x L[%08x]\n"
2375 "korg1212: RecDataPhy = %08x L[%08x], "
2376 "VolumeTablePhy = %08x L[%08x]\n"
2377 "korg1212: RoutingTablePhy = %08x L[%08x], "
2378 "AdatTimeCodePhy = %08x L[%08x]\n",
2379 (int)korg1212
->dma_dsp
.addr
, UpperWordSwap(korg1212
->dma_dsp
.addr
),
2380 korg1212
->PlayDataPhy
, LowerWordSwap(korg1212
->PlayDataPhy
),
2381 korg1212
->RecDataPhy
, LowerWordSwap(korg1212
->RecDataPhy
),
2382 korg1212
->VolumeTablePhy
, LowerWordSwap(korg1212
->VolumeTablePhy
),
2383 korg1212
->RoutingTablePhy
, LowerWordSwap(korg1212
->RoutingTablePhy
),
2384 korg1212
->AdatTimeCodePhy
, LowerWordSwap(korg1212
->AdatTimeCodePhy
));
2386 if ((err
= snd_pcm_new(korg1212
->card
, "korg1212", 0, 1, 1, &korg1212
->pcm
)) < 0)
2389 korg1212
->pcm
->private_data
= korg1212
;
2390 korg1212
->pcm
->private_free
= snd_korg1212_free_pcm
;
2391 strcpy(korg1212
->pcm
->name
, "korg1212");
2393 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_korg1212_playback_ops
);
2395 snd_pcm_set_ops(korg1212
->pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_korg1212_capture_ops
);
2397 korg1212
->pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
2399 for (i
= 0; i
< ARRAY_SIZE(snd_korg1212_controls
); i
++) {
2400 err
= snd_ctl_add(korg1212
->card
, snd_ctl_new1(&snd_korg1212_controls
[i
], korg1212
));
2405 snd_korg1212_proc_init(korg1212
);
2407 snd_card_set_dev(card
, &pci
->dev
);
2415 * Card initialisation
2418 static int __devinit
2419 snd_korg1212_probe(struct pci_dev
*pci
,
2420 const struct pci_device_id
*pci_id
)
2423 struct snd_korg1212
*korg1212
;
2424 struct snd_card
*card
;
2427 if (dev
>= SNDRV_CARDS
) {
2434 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2438 if ((err
= snd_korg1212_create(card
, pci
, &korg1212
)) < 0) {
2439 snd_card_free(card
);
2443 strcpy(card
->driver
, "korg1212");
2444 strcpy(card
->shortname
, "korg1212");
2445 sprintf(card
->longname
, "%s at 0x%lx, irq %d", card
->shortname
,
2446 korg1212
->iomem
, korg1212
->irq
);
2448 K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card
->longname
);
2450 if ((err
= snd_card_register(card
)) < 0) {
2451 snd_card_free(card
);
2454 pci_set_drvdata(pci
, card
);
2459 static void __devexit
snd_korg1212_remove(struct pci_dev
*pci
)
2461 snd_card_free(pci_get_drvdata(pci
));
2462 pci_set_drvdata(pci
, NULL
);
2465 static struct pci_driver driver
= {
2467 .id_table
= snd_korg1212_ids
,
2468 .probe
= snd_korg1212_probe
,
2469 .remove
= __devexit_p(snd_korg1212_remove
),
2472 static int __init
alsa_card_korg1212_init(void)
2474 return pci_register_driver(&driver
);
2477 static void __exit
alsa_card_korg1212_exit(void)
2479 pci_unregister_driver(&driver
);
2482 module_init(alsa_card_korg1212_init
)
2483 module_exit(alsa_card_korg1212_exit
)