Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Korg 1212 IO PCI card |
| 3 | * |
| 4 | * Copyright (c) 2001 Haroldo Gamal <gamal@alternex.com.br> |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 28 | #include <linux/module.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 29 | #include <linux/mutex.h> |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 30 | #include <linux/firmware.h> |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 31 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <sound/core.h> |
| 34 | #include <sound/info.h> |
| 35 | #include <sound/control.h> |
| 36 | #include <sound/pcm.h> |
| 37 | #include <sound/pcm_params.h> |
| 38 | #include <sound/initval.h> |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | // ---------------------------------------------------------------------------- |
| 41 | // Debug Stuff |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | #define K1212_DEBUG_LEVEL 0 |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 44 | #if K1212_DEBUG_LEVEL > 0 |
| 45 | #define K1212_DEBUG_PRINTK(fmt,args...) printk(KERN_DEBUG fmt,##args) |
| 46 | #else |
| 47 | #define K1212_DEBUG_PRINTK(fmt,...) |
| 48 | #endif |
| 49 | #if K1212_DEBUG_LEVEL > 1 |
| 50 | #define K1212_DEBUG_PRINTK_VERBOSE(fmt,args...) printk(KERN_DEBUG fmt,##args) |
| 51 | #else |
| 52 | #define K1212_DEBUG_PRINTK_VERBOSE(fmt,...) |
| 53 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | // ---------------------------------------------------------------------------- |
| 56 | // Record/Play Buffer Allocation Method. If K1212_LARGEALLOC is defined all |
| 57 | // buffers are alocated as a large piece inside KorgSharedBuffer. |
| 58 | // ---------------------------------------------------------------------------- |
| 59 | //#define K1212_LARGEALLOC 1 |
| 60 | |
| 61 | // ---------------------------------------------------------------------------- |
| 62 | // Valid states of the Korg 1212 I/O card. |
| 63 | // ---------------------------------------------------------------------------- |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 64 | enum CardState { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | K1212_STATE_NONEXISTENT, // there is no card here |
| 66 | K1212_STATE_UNINITIALIZED, // the card is awaiting DSP download |
| 67 | K1212_STATE_DSP_IN_PROCESS, // the card is currently downloading its DSP code |
| 68 | K1212_STATE_DSP_COMPLETE, // the card has finished the DSP download |
| 69 | K1212_STATE_READY, // the card can be opened by an application. Any application |
| 70 | // requests prior to this state should fail. Only an open |
| 71 | // request can be made at this state. |
| 72 | K1212_STATE_OPEN, // an application has opened the card |
| 73 | K1212_STATE_SETUP, // the card has been setup for play |
| 74 | K1212_STATE_PLAYING, // the card is playing |
| 75 | K1212_STATE_MONITOR, // the card is in the monitor mode |
| 76 | K1212_STATE_CALIBRATING, // the card is currently calibrating |
| 77 | K1212_STATE_ERRORSTOP, // the card has stopped itself because of an error and we |
| 78 | // are in the process of cleaning things up. |
| 79 | K1212_STATE_MAX_STATE // state values of this and beyond are invalid |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 80 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | // ---------------------------------------------------------------------------- |
| 83 | // The following enumeration defines the constants written to the card's |
| 84 | // host-to-card doorbell to initiate a command. |
| 85 | // ---------------------------------------------------------------------------- |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 86 | enum korg1212_dbcnst { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | K1212_DB_RequestForData = 0, // sent by the card to request a buffer fill. |
| 88 | K1212_DB_TriggerPlay = 1, // starts playback/record on the card. |
| 89 | K1212_DB_SelectPlayMode = 2, // select monitor, playback setup, or stop. |
| 90 | K1212_DB_ConfigureBufferMemory = 3, // tells card where the host audio buffers are. |
| 91 | K1212_DB_RequestAdatTimecode = 4, // asks the card for the latest ADAT timecode value. |
| 92 | K1212_DB_SetClockSourceRate = 5, // sets the clock source and rate for the card. |
| 93 | K1212_DB_ConfigureMiscMemory = 6, // tells card where other buffers are. |
| 94 | K1212_DB_TriggerFromAdat = 7, // tells card to trigger from Adat at a specific |
| 95 | // timecode value. |
| 96 | K1212_DB_DMAERROR = 0x80, // DMA Error - the PCI bus is congestioned. |
| 97 | K1212_DB_CARDSTOPPED = 0x81, // Card has stopped by user request. |
| 98 | K1212_DB_RebootCard = 0xA0, // instructs the card to reboot. |
| 99 | K1212_DB_BootFromDSPPage4 = 0xA4, // instructs the card to boot from the DSP microcode |
| 100 | // on page 4 (local page to card). |
| 101 | K1212_DB_DSPDownloadDone = 0xAE, // sent by the card to indicate the download has |
| 102 | // completed. |
| 103 | K1212_DB_StartDSPDownload = 0xAF // tells the card to download its DSP firmware. |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 104 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | |
| 107 | // ---------------------------------------------------------------------------- |
| 108 | // The following enumeration defines return codes |
| 109 | // to the Korg 1212 I/O driver. |
| 110 | // ---------------------------------------------------------------------------- |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 111 | enum snd_korg1212rc { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | K1212_CMDRET_Success = 0, // command was successfully placed |
| 113 | K1212_CMDRET_DIOCFailure, // the DeviceIoControl call failed |
| 114 | K1212_CMDRET_PMFailure, // the protected mode call failed |
| 115 | K1212_CMDRET_FailUnspecified, // unspecified failure |
| 116 | K1212_CMDRET_FailBadState, // the specified command can not be given in |
| 117 | // the card's current state. (or the wave device's |
| 118 | // state) |
| 119 | K1212_CMDRET_CardUninitialized, // the card is uninitialized and cannot be used |
| 120 | K1212_CMDRET_BadIndex, // an out of range card index was specified |
| 121 | K1212_CMDRET_BadHandle, // an invalid card handle was specified |
| 122 | K1212_CMDRET_NoFillRoutine, // a play request has been made before a fill routine set |
| 123 | K1212_CMDRET_FillRoutineInUse, // can't set a new fill routine while one is in use |
| 124 | K1212_CMDRET_NoAckFromCard, // the card never acknowledged a command |
| 125 | K1212_CMDRET_BadParams, // bad parameters were provided by the caller |
| 126 | |
| 127 | K1212_CMDRET_BadDevice, // the specified wave device was out of range |
| 128 | K1212_CMDRET_BadFormat // the specified wave format is unsupported |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | // ---------------------------------------------------------------------------- |
| 132 | // The following enumeration defines the constants used to select the play |
| 133 | // mode for the card in the SelectPlayMode command. |
| 134 | // ---------------------------------------------------------------------------- |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 135 | enum PlayModeSelector { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | K1212_MODE_SetupPlay = 0x00000001, // provides card with pre-play information |
| 137 | K1212_MODE_MonitorOn = 0x00000002, // tells card to turn on monitor mode |
| 138 | K1212_MODE_MonitorOff = 0x00000004, // tells card to turn off monitor mode |
| 139 | K1212_MODE_StopPlay = 0x00000008 // stops playback on the card |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 140 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | // ---------------------------------------------------------------------------- |
| 143 | // The following enumeration defines the constants used to select the monitor |
| 144 | // mode for the card in the SetMonitorMode command. |
| 145 | // ---------------------------------------------------------------------------- |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 146 | enum MonitorModeSelector { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | K1212_MONMODE_Off = 0, // tells card to turn off monitor mode |
| 148 | K1212_MONMODE_On // tells card to turn on monitor mode |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 149 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | #define MAILBOX0_OFFSET 0x40 // location of mailbox 0 relative to base address |
| 152 | #define MAILBOX1_OFFSET 0x44 // location of mailbox 1 relative to base address |
| 153 | #define MAILBOX2_OFFSET 0x48 // location of mailbox 2 relative to base address |
| 154 | #define MAILBOX3_OFFSET 0x4c // location of mailbox 3 relative to base address |
| 155 | #define OUT_DOORBELL_OFFSET 0x60 // location of PCI to local doorbell |
| 156 | #define IN_DOORBELL_OFFSET 0x64 // location of local to PCI doorbell |
| 157 | #define STATUS_REG_OFFSET 0x68 // location of interrupt control/status register |
| 158 | #define PCI_CONTROL_OFFSET 0x6c // location of the EEPROM, PCI, User I/O, init control |
| 159 | // register |
| 160 | #define SENS_CONTROL_OFFSET 0x6e // location of the input sensitivity setting register. |
| 161 | // this is the upper word of the PCI control reg. |
| 162 | #define DEV_VEND_ID_OFFSET 0x70 // location of the device and vendor ID register |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #define MAX_COMMAND_RETRIES 5 // maximum number of times the driver will attempt |
| 165 | // to send a command before giving up. |
| 166 | #define COMMAND_ACK_MASK 0x8000 // the MSB is set in the command acknowledgment from |
| 167 | // the card. |
| 168 | #define DOORBELL_VAL_MASK 0x00FF // the doorbell value is one byte |
| 169 | |
| 170 | #define CARD_BOOT_DELAY_IN_MS 10 |
| 171 | #define CARD_BOOT_TIMEOUT 10 |
| 172 | #define DSP_BOOT_DELAY_IN_MS 200 |
| 173 | |
| 174 | #define kNumBuffers 8 |
| 175 | #define k1212MaxCards 4 |
| 176 | #define k1212NumWaveDevices 6 |
| 177 | #define k16BitChannels 10 |
| 178 | #define k32BitChannels 2 |
| 179 | #define kAudioChannels (k16BitChannels + k32BitChannels) |
| 180 | #define kPlayBufferFrames 1024 |
| 181 | |
| 182 | #define K1212_ANALOG_CHANNELS 2 |
| 183 | #define K1212_SPDIF_CHANNELS 2 |
| 184 | #define K1212_ADAT_CHANNELS 8 |
| 185 | #define K1212_CHANNELS (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS) |
| 186 | #define K1212_MIN_CHANNELS 1 |
| 187 | #define K1212_MAX_CHANNELS K1212_CHANNELS |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 188 | #define K1212_FRAME_SIZE (sizeof(struct KorgAudioFrame)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #define K1212_MAX_SAMPLES (kPlayBufferFrames*kNumBuffers) |
| 190 | #define K1212_PERIODS (kNumBuffers) |
| 191 | #define K1212_PERIOD_BYTES (K1212_FRAME_SIZE*kPlayBufferFrames) |
| 192 | #define K1212_BUF_SIZE (K1212_PERIOD_BYTES*kNumBuffers) |
| 193 | #define K1212_ANALOG_BUF_SIZE (K1212_ANALOG_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers) |
| 194 | #define K1212_SPDIF_BUF_SIZE (K1212_SPDIF_CHANNELS * 3 * kPlayBufferFrames * kNumBuffers) |
| 195 | #define K1212_ADAT_BUF_SIZE (K1212_ADAT_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers) |
| 196 | #define K1212_MAX_BUF_SIZE (K1212_ANALOG_BUF_SIZE + K1212_ADAT_BUF_SIZE) |
| 197 | |
Takashi Iwai | fbaf6a5 | 2012-08-30 07:57:38 -0700 | [diff] [blame] | 198 | #define k1212MinADCSens 0x00 |
| 199 | #define k1212MaxADCSens 0x7f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #define k1212MaxVolume 0x7fff |
| 201 | #define k1212MaxWaveVolume 0xffff |
| 202 | #define k1212MinVolume 0x0000 |
| 203 | #define k1212MaxVolInverted 0x8000 |
| 204 | |
| 205 | // ----------------------------------------------------------------- |
| 206 | // the following bits are used for controlling interrupts in the |
| 207 | // interrupt control/status reg |
| 208 | // ----------------------------------------------------------------- |
| 209 | #define PCI_INT_ENABLE_BIT 0x00000100 |
| 210 | #define PCI_DOORBELL_INT_ENABLE_BIT 0x00000200 |
| 211 | #define LOCAL_INT_ENABLE_BIT 0x00010000 |
| 212 | #define LOCAL_DOORBELL_INT_ENABLE_BIT 0x00020000 |
| 213 | #define LOCAL_DMA1_INT_ENABLE_BIT 0x00080000 |
| 214 | |
| 215 | // ----------------------------------------------------------------- |
| 216 | // the following bits are defined for the PCI command register |
| 217 | // ----------------------------------------------------------------- |
| 218 | #define PCI_CMD_MEM_SPACE_ENABLE_BIT 0x0002 |
| 219 | #define PCI_CMD_IO_SPACE_ENABLE_BIT 0x0001 |
| 220 | #define PCI_CMD_BUS_MASTER_ENABLE_BIT 0x0004 |
| 221 | |
| 222 | // ----------------------------------------------------------------- |
| 223 | // the following bits are defined for the PCI status register |
| 224 | // ----------------------------------------------------------------- |
| 225 | #define PCI_STAT_PARITY_ERROR_BIT 0x8000 |
| 226 | #define PCI_STAT_SYSTEM_ERROR_BIT 0x4000 |
| 227 | #define PCI_STAT_MASTER_ABORT_RCVD_BIT 0x2000 |
| 228 | #define PCI_STAT_TARGET_ABORT_RCVD_BIT 0x1000 |
| 229 | #define PCI_STAT_TARGET_ABORT_SENT_BIT 0x0800 |
| 230 | |
| 231 | // ------------------------------------------------------------------------ |
| 232 | // the following constants are used in setting the 1212 I/O card's input |
| 233 | // sensitivity. |
| 234 | // ------------------------------------------------------------------------ |
| 235 | #define SET_SENS_LOCALINIT_BITPOS 15 |
| 236 | #define SET_SENS_DATA_BITPOS 10 |
| 237 | #define SET_SENS_CLOCK_BITPOS 8 |
| 238 | #define SET_SENS_LOADSHIFT_BITPOS 0 |
| 239 | |
| 240 | #define SET_SENS_LEFTCHANID 0x00 |
| 241 | #define SET_SENS_RIGHTCHANID 0x01 |
| 242 | |
| 243 | #define K1212SENSUPDATE_DELAY_IN_MS 50 |
| 244 | |
| 245 | // -------------------------------------------------------------------------- |
| 246 | // WaitRTCTicks |
| 247 | // |
| 248 | // This function waits the specified number of real time clock ticks. |
| 249 | // According to the DDK, each tick is ~0.8 microseconds. |
| 250 | // The defines following the function declaration can be used for the |
| 251 | // numTicksToWait parameter. |
| 252 | // -------------------------------------------------------------------------- |
| 253 | #define ONE_RTC_TICK 1 |
| 254 | #define SENSCLKPULSE_WIDTH 4 |
| 255 | #define LOADSHIFT_DELAY 4 |
| 256 | #define INTERCOMMAND_DELAY 40 |
| 257 | #define STOPCARD_DELAY 300 // max # RTC ticks for the card to stop once we write |
| 258 | // the command register. (could be up to 180 us) |
| 259 | #define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement |
| 260 | // from the card after sending a command. |
| 261 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 262 | enum ClockSourceIndex { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | K1212_CLKIDX_AdatAt44_1K = 0, // selects source as ADAT at 44.1 kHz |
| 264 | K1212_CLKIDX_AdatAt48K, // selects source as ADAT at 48 kHz |
| 265 | K1212_CLKIDX_WordAt44_1K, // selects source as S/PDIF at 44.1 kHz |
| 266 | K1212_CLKIDX_WordAt48K, // selects source as S/PDIF at 48 kHz |
| 267 | K1212_CLKIDX_LocalAt44_1K, // selects source as local clock at 44.1 kHz |
| 268 | K1212_CLKIDX_LocalAt48K, // selects source as local clock at 48 kHz |
| 269 | K1212_CLKIDX_Invalid // used to check validity of the index |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 270 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 272 | enum ClockSourceType { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | K1212_CLKIDX_Adat = 0, // selects source as ADAT |
| 274 | K1212_CLKIDX_Word, // selects source as S/PDIF |
| 275 | K1212_CLKIDX_Local // selects source as local clock |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 276 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 278 | struct KorgAudioFrame { |
| 279 | u16 frameData16[k16BitChannels]; /* channels 0-9 use 16 bit samples */ |
| 280 | u32 frameData32[k32BitChannels]; /* channels 10-11 use 32 bits - only 20 are sent across S/PDIF */ |
| 281 | u32 timeCodeVal; /* holds the ADAT timecode value */ |
| 282 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 284 | struct KorgAudioBuffer { |
| 285 | struct KorgAudioFrame bufferData[kPlayBufferFrames]; /* buffer definition */ |
| 286 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 288 | struct KorgSharedBuffer { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | #ifdef K1212_LARGEALLOC |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 290 | struct KorgAudioBuffer playDataBufs[kNumBuffers]; |
| 291 | struct KorgAudioBuffer recordDataBufs[kNumBuffers]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | #endif |
| 293 | short volumeData[kAudioChannels]; |
| 294 | u32 cardCommand; |
| 295 | u16 routeData [kAudioChannels]; |
| 296 | u32 AdatTimeCode; // ADAT timecode value |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 297 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 299 | struct SensBits { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | union { |
| 301 | struct { |
| 302 | unsigned int leftChanVal:8; |
| 303 | unsigned int leftChanId:8; |
| 304 | } v; |
| 305 | u16 leftSensBits; |
| 306 | } l; |
| 307 | union { |
| 308 | struct { |
| 309 | unsigned int rightChanVal:8; |
| 310 | unsigned int rightChanId:8; |
| 311 | } v; |
| 312 | u16 rightSensBits; |
| 313 | } r; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 314 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 316 | struct snd_korg1212 { |
| 317 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | struct pci_dev *pci; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 319 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | int irq; |
| 321 | |
| 322 | spinlock_t lock; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 323 | struct mutex open_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | struct timer_list timer; /* timer callback for checking ack of stop request */ |
| 326 | int stop_pending_cnt; /* counter for stop pending check */ |
| 327 | |
| 328 | wait_queue_head_t wait; |
| 329 | |
| 330 | unsigned long iomem; |
| 331 | unsigned long ioport; |
| 332 | unsigned long iomem2; |
| 333 | unsigned long irqcount; |
| 334 | unsigned long inIRQ; |
| 335 | void __iomem *iobase; |
| 336 | |
| 337 | struct snd_dma_buffer dma_dsp; |
| 338 | struct snd_dma_buffer dma_play; |
| 339 | struct snd_dma_buffer dma_rec; |
| 340 | struct snd_dma_buffer dma_shared; |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | u32 DataBufsSize; |
| 343 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 344 | struct KorgAudioBuffer * playDataBufsPtr; |
| 345 | struct KorgAudioBuffer * recordDataBufsPtr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 347 | struct KorgSharedBuffer * sharedBufferPtr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | u32 RecDataPhy; |
| 350 | u32 PlayDataPhy; |
| 351 | unsigned long sharedBufferPhy; |
| 352 | u32 VolumeTablePhy; |
| 353 | u32 RoutingTablePhy; |
| 354 | u32 AdatTimeCodePhy; |
| 355 | |
| 356 | u32 __iomem * statusRegPtr; // address of the interrupt status/control register |
| 357 | u32 __iomem * outDoorbellPtr; // address of the host->card doorbell register |
| 358 | u32 __iomem * inDoorbellPtr; // address of the card->host doorbell register |
| 359 | u32 __iomem * mailbox0Ptr; // address of mailbox 0 on the card |
| 360 | u32 __iomem * mailbox1Ptr; // address of mailbox 1 on the card |
| 361 | u32 __iomem * mailbox2Ptr; // address of mailbox 2 on the card |
| 362 | u32 __iomem * mailbox3Ptr; // address of mailbox 3 on the card |
| 363 | u32 __iomem * controlRegPtr; // address of the EEPROM, PCI, I/O, Init ctrl reg |
| 364 | u16 __iomem * sensRegPtr; // address of the sensitivity setting register |
| 365 | u32 __iomem * idRegPtr; // address of the device and vendor ID registers |
| 366 | |
| 367 | size_t periodsize; |
| 368 | int channels; |
| 369 | int currentBuffer; |
| 370 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 371 | struct snd_pcm_substream *playback_substream; |
| 372 | struct snd_pcm_substream *capture_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | pid_t capture_pid; |
| 375 | pid_t playback_pid; |
| 376 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 377 | enum CardState cardState; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | int running; |
| 379 | int idleMonitorOn; // indicates whether the card is in idle monitor mode. |
| 380 | u32 cmdRetryCount; // tracks how many times we have retried sending to the card. |
| 381 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 382 | enum ClockSourceIndex clkSrcRate; // sample rate and clock source |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 384 | enum ClockSourceType clkSource; // clock source |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | int clkRate; // clock rate |
| 386 | |
| 387 | int volumePhase[kAudioChannels]; |
| 388 | |
| 389 | u16 leftADCInSens; // ADC left channel input sensitivity |
| 390 | u16 rightADCInSens; // ADC right channel input sensitivity |
| 391 | |
| 392 | int opencnt; // Open/Close count |
| 393 | int setcnt; // SetupForPlay count |
| 394 | int playcnt; // TriggerPlay count |
| 395 | int errorcnt; // Error Count |
| 396 | unsigned long totalerrorcnt; // Total Error Count |
| 397 | |
| 398 | int dsp_is_loaded; |
| 399 | int dsp_stop_is_processed; |
| 400 | |
| 401 | }; |
| 402 | |
| 403 | MODULE_DESCRIPTION("korg1212"); |
| 404 | MODULE_LICENSE("GPL"); |
| 405 | MODULE_SUPPORTED_DEVICE("{{KORG,korg1212}}"); |
Clemens Ladisch | 7e0af29 | 2007-05-03 17:59:54 +0200 | [diff] [blame] | 406 | MODULE_FIRMWARE("korg/k1212.dsp"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 409 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 410 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | module_param_array(index, int, NULL, 0444); |
| 413 | MODULE_PARM_DESC(index, "Index value for Korg 1212 soundcard."); |
| 414 | module_param_array(id, charp, NULL, 0444); |
| 415 | MODULE_PARM_DESC(id, "ID string for Korg 1212 soundcard."); |
| 416 | module_param_array(enable, bool, NULL, 0444); |
| 417 | MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard."); |
| 418 | MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>"); |
| 419 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 420 | static const struct pci_device_id snd_korg1212_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | .vendor = 0x10b5, |
| 423 | .device = 0x906d, |
| 424 | .subvendor = PCI_ANY_ID, |
| 425 | .subdevice = PCI_ANY_ID, |
| 426 | }, |
| 427 | { 0, }, |
| 428 | }; |
| 429 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 430 | MODULE_DEVICE_TABLE(pci, snd_korg1212_ids); |
| 431 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 432 | static char *stateName[] = { |
| 433 | "Non-existent", |
| 434 | "Uninitialized", |
| 435 | "DSP download in process", |
| 436 | "DSP download complete", |
| 437 | "Ready", |
| 438 | "Open", |
| 439 | "Setup for play", |
| 440 | "Playing", |
| 441 | "Monitor mode on", |
| 442 | "Calibrating", |
| 443 | "Invalid" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | }; |
| 445 | |
Takashi Iwai | f861237 | 2014-10-20 18:21:58 +0200 | [diff] [blame] | 446 | static const char * const clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Takashi Iwai | f861237 | 2014-10-20 18:21:58 +0200 | [diff] [blame] | 448 | static const char * const clockSourceName[] = { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 449 | "ADAT at 44.1 kHz", |
| 450 | "ADAT at 48 kHz", |
| 451 | "S/PDIF at 44.1 kHz", |
| 452 | "S/PDIF at 48 kHz", |
| 453 | "local clock at 44.1 kHz", |
| 454 | "local clock at 48 kHz" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Takashi Iwai | f861237 | 2014-10-20 18:21:58 +0200 | [diff] [blame] | 457 | static const char * const channelName[] = { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 458 | "ADAT-1", |
| 459 | "ADAT-2", |
| 460 | "ADAT-3", |
| 461 | "ADAT-4", |
| 462 | "ADAT-5", |
| 463 | "ADAT-6", |
| 464 | "ADAT-7", |
| 465 | "ADAT-8", |
| 466 | "Analog-L", |
| 467 | "Analog-R", |
| 468 | "SPDIF-L", |
| 469 | "SPDIF-R", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | }; |
| 471 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 472 | static u16 ClockSourceSelector[] = { |
| 473 | 0x8000, // selects source as ADAT at 44.1 kHz |
| 474 | 0x0000, // selects source as ADAT at 48 kHz |
| 475 | 0x8001, // selects source as S/PDIF at 44.1 kHz |
| 476 | 0x0001, // selects source as S/PDIF at 48 kHz |
| 477 | 0x8002, // selects source as local clock at 44.1 kHz |
| 478 | 0x0002 // selects source as local clock at 48 kHz |
| 479 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 481 | union swap_u32 { unsigned char c[4]; u32 i; }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | #ifdef SNDRV_BIG_ENDIAN |
| 484 | static u32 LowerWordSwap(u32 swappee) |
| 485 | #else |
| 486 | static u32 UpperWordSwap(u32 swappee) |
| 487 | #endif |
| 488 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 489 | union swap_u32 retVal, swapper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | swapper.i = swappee; |
| 492 | retVal.c[2] = swapper.c[3]; |
| 493 | retVal.c[3] = swapper.c[2]; |
| 494 | retVal.c[1] = swapper.c[1]; |
| 495 | retVal.c[0] = swapper.c[0]; |
| 496 | |
| 497 | return retVal.i; |
| 498 | } |
| 499 | |
| 500 | #ifdef SNDRV_BIG_ENDIAN |
| 501 | static u32 UpperWordSwap(u32 swappee) |
| 502 | #else |
| 503 | static u32 LowerWordSwap(u32 swappee) |
| 504 | #endif |
| 505 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 506 | union swap_u32 retVal, swapper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | swapper.i = swappee; |
| 509 | retVal.c[2] = swapper.c[2]; |
| 510 | retVal.c[3] = swapper.c[3]; |
| 511 | retVal.c[1] = swapper.c[0]; |
| 512 | retVal.c[0] = swapper.c[1]; |
| 513 | |
| 514 | return retVal.i; |
| 515 | } |
| 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | #define SetBitInWord(theWord,bitPosition) (*theWord) |= (0x0001 << bitPosition) |
| 518 | #define SetBitInDWord(theWord,bitPosition) (*theWord) |= (0x00000001 << bitPosition) |
| 519 | #define ClearBitInWord(theWord,bitPosition) (*theWord) &= ~(0x0001 << bitPosition) |
| 520 | #define ClearBitInDWord(theWord,bitPosition) (*theWord) &= ~(0x00000001 << bitPosition) |
| 521 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 522 | static int snd_korg1212_Send1212Command(struct snd_korg1212 *korg1212, |
| 523 | enum korg1212_dbcnst doorbellVal, |
| 524 | u32 mailBox0Val, u32 mailBox1Val, |
| 525 | u32 mailBox2Val, u32 mailBox3Val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
| 527 | u32 retryCount; |
| 528 | u16 mailBox3Lo; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 529 | int rc = K1212_CMDRET_Success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | if (!korg1212->outDoorbellPtr) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 532 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: CardUninitialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return K1212_CMDRET_CardUninitialized; |
| 534 | } |
| 535 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 536 | K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n", |
| 537 | doorbellVal, mailBox0Val, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | for (retryCount = 0; retryCount < MAX_COMMAND_RETRIES; retryCount++) { |
| 539 | writel(mailBox3Val, korg1212->mailbox3Ptr); |
| 540 | writel(mailBox2Val, korg1212->mailbox2Ptr); |
| 541 | writel(mailBox1Val, korg1212->mailbox1Ptr); |
| 542 | writel(mailBox0Val, korg1212->mailbox0Ptr); |
| 543 | writel(doorbellVal, korg1212->outDoorbellPtr); // interrupt the card |
| 544 | |
| 545 | // -------------------------------------------------------------- |
| 546 | // the reboot command will not give an acknowledgement. |
| 547 | // -------------------------------------------------------------- |
| 548 | if ( doorbellVal == K1212_DB_RebootCard || |
| 549 | doorbellVal == K1212_DB_BootFromDSPPage4 || |
| 550 | doorbellVal == K1212_DB_StartDSPDownload ) { |
| 551 | rc = K1212_CMDRET_Success; |
| 552 | break; |
| 553 | } |
| 554 | |
| 555 | // -------------------------------------------------------------- |
| 556 | // See if the card acknowledged the command. Wait a bit, then |
| 557 | // read in the low word of mailbox3. If the MSB is set and the |
| 558 | // low byte is equal to the doorbell value, then it ack'd. |
| 559 | // -------------------------------------------------------------- |
| 560 | udelay(COMMAND_ACK_DELAY); |
| 561 | mailBox3Lo = readl(korg1212->mailbox3Ptr); |
| 562 | if (mailBox3Lo & COMMAND_ACK_MASK) { |
| 563 | if ((mailBox3Lo & DOORBELL_VAL_MASK) == (doorbellVal & DOORBELL_VAL_MASK)) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 564 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- Success\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | rc = K1212_CMDRET_Success; |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | korg1212->cmdRetryCount += retryCount; |
| 571 | |
| 572 | if (retryCount >= MAX_COMMAND_RETRIES) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 573 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- NoAckFromCard\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | rc = K1212_CMDRET_NoAckFromCard; |
| 575 | } |
| 576 | |
| 577 | return rc; |
| 578 | } |
| 579 | |
| 580 | /* spinlock already held */ |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 581 | static void snd_korg1212_SendStop(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | { |
| 583 | if (! korg1212->stop_pending_cnt) { |
| 584 | korg1212->sharedBufferPtr->cardCommand = 0xffffffff; |
| 585 | /* program the timer */ |
| 586 | korg1212->stop_pending_cnt = HZ; |
Takashi Iwai | 3d6f0e0 | 2015-01-19 11:34:18 +0100 | [diff] [blame] | 587 | mod_timer(&korg1212->timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 591 | static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
| 593 | unsigned long flags; |
| 594 | spin_lock_irqsave(&korg1212->lock, flags); |
| 595 | korg1212->dsp_stop_is_processed = 0; |
| 596 | snd_korg1212_SendStop(korg1212); |
| 597 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 598 | wait_event_timeout(korg1212->wait, korg1212->dsp_stop_is_processed, (HZ * 3) / 2); |
| 599 | } |
| 600 | |
| 601 | /* timer callback for checking the ack of stop request */ |
| 602 | static void snd_korg1212_timer_func(unsigned long data) |
| 603 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 604 | struct snd_korg1212 *korg1212 = (struct snd_korg1212 *) data; |
Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 605 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 607 | spin_lock_irqsave(&korg1212->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | if (korg1212->sharedBufferPtr->cardCommand == 0) { |
| 609 | /* ack'ed */ |
| 610 | korg1212->stop_pending_cnt = 0; |
| 611 | korg1212->dsp_stop_is_processed = 1; |
| 612 | wake_up(&korg1212->wait); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 613 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Stop ack'ed [%s]\n", |
| 614 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } else { |
| 616 | if (--korg1212->stop_pending_cnt > 0) { |
| 617 | /* reprogram timer */ |
Takashi Iwai | 3d6f0e0 | 2015-01-19 11:34:18 +0100 | [diff] [blame] | 618 | mod_timer(&korg1212->timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } else { |
| 620 | snd_printd("korg1212_timer_func timeout\n"); |
| 621 | korg1212->sharedBufferPtr->cardCommand = 0; |
| 622 | korg1212->dsp_stop_is_processed = 1; |
| 623 | wake_up(&korg1212->wait); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 624 | K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", |
| 625 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | } |
Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 628 | spin_unlock_irqrestore(&korg1212->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 631 | static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | unsigned long flags; |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 634 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | udelay(INTERCOMMAND_DELAY); |
| 637 | spin_lock_irqsave(&korg1212->lock, flags); |
| 638 | korg1212->idleMonitorOn = 1; |
| 639 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, |
| 640 | K1212_MODE_MonitorOn, 0, 0, 0); |
| 641 | spin_unlock_irqrestore(&korg1212->lock, flags); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 642 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 645 | static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
| 647 | if (korg1212->idleMonitorOn) { |
| 648 | snd_korg1212_SendStopAndWait(korg1212); |
| 649 | korg1212->idleMonitorOn = 0; |
| 650 | } |
| 651 | } |
| 652 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 653 | static inline void snd_korg1212_setCardState(struct snd_korg1212 * korg1212, enum CardState csState) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
| 655 | korg1212->cardState = csState; |
| 656 | } |
| 657 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 658 | static int snd_korg1212_OpenCard(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 660 | K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", |
| 661 | stateName[korg1212->cardState], korg1212->opencnt); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 662 | mutex_lock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | if (korg1212->opencnt++ == 0) { |
| 664 | snd_korg1212_TurnOffIdleMonitor(korg1212); |
| 665 | snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); |
| 666 | } |
| 667 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 668 | mutex_unlock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return 1; |
| 670 | } |
| 671 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 672 | static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 674 | K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n", |
| 675 | stateName[korg1212->cardState], korg1212->opencnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 677 | mutex_lock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if (--(korg1212->opencnt)) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 679 | mutex_unlock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | if (korg1212->cardState == K1212_STATE_SETUP) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 684 | int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | K1212_MODE_StopPlay, 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 686 | if (rc) |
| 687 | K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n", |
| 688 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | if (rc != K1212_CMDRET_Success) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 690 | mutex_unlock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | } else if (korg1212->cardState > K1212_STATE_SETUP) { |
| 694 | snd_korg1212_SendStopAndWait(korg1212); |
| 695 | } |
| 696 | |
| 697 | if (korg1212->cardState > K1212_STATE_READY) { |
| 698 | snd_korg1212_TurnOnIdleMonitor(korg1212); |
| 699 | snd_korg1212_setCardState(korg1212, K1212_STATE_READY); |
| 700 | } |
| 701 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 702 | mutex_unlock(&korg1212->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | /* spinlock already held */ |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 707 | static int snd_korg1212_SetupForPlay(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 709 | int rc; |
| 710 | |
| 711 | K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n", |
| 712 | stateName[korg1212->cardState], korg1212->setcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
| 714 | if (korg1212->setcnt++) |
| 715 | return 0; |
| 716 | |
| 717 | snd_korg1212_setCardState(korg1212, K1212_STATE_SETUP); |
| 718 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, |
| 719 | K1212_MODE_SetupPlay, 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 720 | if (rc) |
| 721 | K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n", |
| 722 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | if (rc != K1212_CMDRET_Success) { |
| 724 | return 1; |
| 725 | } |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | /* spinlock already held */ |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 730 | static int snd_korg1212_TriggerPlay(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 732 | int rc; |
| 733 | |
| 734 | K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n", |
| 735 | stateName[korg1212->cardState], korg1212->playcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | if (korg1212->playcnt++) |
| 738 | return 0; |
| 739 | |
| 740 | snd_korg1212_setCardState(korg1212, K1212_STATE_PLAYING); |
| 741 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_TriggerPlay, 0, 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 742 | if (rc) |
| 743 | K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n", |
| 744 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | if (rc != K1212_CMDRET_Success) { |
| 746 | return 1; |
| 747 | } |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | /* spinlock already held */ |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 752 | static int snd_korg1212_StopPlay(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 754 | K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n", |
| 755 | stateName[korg1212->cardState], korg1212->playcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | if (--(korg1212->playcnt)) |
| 758 | return 0; |
| 759 | |
| 760 | korg1212->setcnt = 0; |
| 761 | |
| 762 | if (korg1212->cardState != K1212_STATE_ERRORSTOP) |
| 763 | snd_korg1212_SendStop(korg1212); |
| 764 | |
| 765 | snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); |
| 766 | return 0; |
| 767 | } |
| 768 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 769 | static void snd_korg1212_EnableCardInterrupts(struct snd_korg1212 * korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
| 771 | writel(PCI_INT_ENABLE_BIT | |
| 772 | PCI_DOORBELL_INT_ENABLE_BIT | |
| 773 | LOCAL_INT_ENABLE_BIT | |
| 774 | LOCAL_DOORBELL_INT_ENABLE_BIT | |
| 775 | LOCAL_DMA1_INT_ENABLE_BIT, |
| 776 | korg1212->statusRegPtr); |
| 777 | } |
| 778 | |
| 779 | #if 0 /* not used */ |
| 780 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 781 | static int snd_korg1212_SetMonitorMode(struct snd_korg1212 *korg1212, |
| 782 | enum MonitorModeSelector mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 784 | K1212_DEBUG_PRINTK("K1212_DEBUG: SetMonitorMode [%s]\n", |
| 785 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | switch (mode) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 788 | case K1212_MONMODE_Off: |
| 789 | if (korg1212->cardState != K1212_STATE_MONITOR) |
| 790 | return 0; |
| 791 | else { |
| 792 | snd_korg1212_SendStopAndWait(korg1212); |
| 793 | snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); |
| 794 | } |
| 795 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 797 | case K1212_MONMODE_On: |
| 798 | if (korg1212->cardState != K1212_STATE_OPEN) |
| 799 | return 0; |
| 800 | else { |
| 801 | int rc; |
| 802 | snd_korg1212_setCardState(korg1212, K1212_STATE_MONITOR); |
| 803 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, |
| 804 | K1212_MODE_MonitorOn, 0, 0, 0); |
| 805 | if (rc != K1212_CMDRET_Success) |
| 806 | return 0; |
| 807 | } |
| 808 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 810 | default: |
| 811 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | return 1; |
| 815 | } |
| 816 | |
| 817 | #endif /* not used */ |
| 818 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 819 | static inline int snd_korg1212_use_is_exclusive(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 821 | if (korg1212->playback_pid != korg1212->capture_pid && |
| 822 | korg1212->playback_pid >= 0 && korg1212->capture_pid >= 0) |
| 823 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 825 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 828 | static int snd_korg1212_SetRate(struct snd_korg1212 *korg1212, int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 830 | static enum ClockSourceIndex s44[] = { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 831 | K1212_CLKIDX_AdatAt44_1K, |
| 832 | K1212_CLKIDX_WordAt44_1K, |
| 833 | K1212_CLKIDX_LocalAt44_1K |
| 834 | }; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 835 | static enum ClockSourceIndex s48[] = { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 836 | K1212_CLKIDX_AdatAt48K, |
| 837 | K1212_CLKIDX_WordAt48K, |
| 838 | K1212_CLKIDX_LocalAt48K |
| 839 | }; |
| 840 | int parm, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 842 | if (!snd_korg1212_use_is_exclusive (korg1212)) |
| 843 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 845 | switch (rate) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 846 | case 44100: |
| 847 | parm = s44[korg1212->clkSource]; |
| 848 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 850 | case 48000: |
| 851 | parm = s48[korg1212->clkSource]; |
| 852 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 854 | default: |
| 855 | return -EINVAL; |
| 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
| 858 | korg1212->clkSrcRate = parm; |
| 859 | korg1212->clkRate = rate; |
| 860 | |
| 861 | udelay(INTERCOMMAND_DELAY); |
| 862 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, |
| 863 | ClockSourceSelector[korg1212->clkSrcRate], |
| 864 | 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 865 | if (rc) |
| 866 | K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", |
| 867 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 872 | static int snd_korg1212_SetClockSource(struct snd_korg1212 *korg1212, int source) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
| 874 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 875 | if (source < 0 || source > 2) |
| 876 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | korg1212->clkSource = source; |
| 879 | |
| 880 | snd_korg1212_SetRate(korg1212, korg1212->clkRate); |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 885 | static void snd_korg1212_DisableCardInterrupts(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
| 887 | writel(0, korg1212->statusRegPtr); |
| 888 | } |
| 889 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 890 | static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 892 | struct SensBits sensVals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | int bitPosition; |
| 894 | int channel; |
| 895 | int clkIs48K; |
| 896 | int monModeSet; |
| 897 | u16 controlValue; // this keeps the current value to be written to |
| 898 | // the card's eeprom control register. |
| 899 | u16 count; |
| 900 | unsigned long flags; |
| 901 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 902 | K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n", |
| 903 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | // ---------------------------------------------------------------------------- |
| 906 | // initialize things. The local init bit is always set when writing to the |
| 907 | // card's control register. |
| 908 | // ---------------------------------------------------------------------------- |
| 909 | controlValue = 0; |
| 910 | SetBitInWord(&controlValue, SET_SENS_LOCALINIT_BITPOS); // init the control value |
| 911 | |
| 912 | // ---------------------------------------------------------------------------- |
| 913 | // make sure the card is not in monitor mode when we do this update. |
| 914 | // ---------------------------------------------------------------------------- |
| 915 | if (korg1212->cardState == K1212_STATE_MONITOR || korg1212->idleMonitorOn) { |
| 916 | monModeSet = 1; |
| 917 | snd_korg1212_SendStopAndWait(korg1212); |
| 918 | } else |
| 919 | monModeSet = 0; |
| 920 | |
| 921 | spin_lock_irqsave(&korg1212->lock, flags); |
| 922 | |
| 923 | // ---------------------------------------------------------------------------- |
| 924 | // we are about to send new values to the card, so clear the new values queued |
| 925 | // flag. Also, clear out mailbox 3, so we don't lockup. |
| 926 | // ---------------------------------------------------------------------------- |
| 927 | writel(0, korg1212->mailbox3Ptr); |
| 928 | udelay(LOADSHIFT_DELAY); |
| 929 | |
| 930 | // ---------------------------------------------------------------------------- |
| 931 | // determine whether we are running a 48K or 44.1K clock. This info is used |
| 932 | // later when setting the SPDIF FF after the volume has been shifted in. |
| 933 | // ---------------------------------------------------------------------------- |
| 934 | switch (korg1212->clkSrcRate) { |
| 935 | case K1212_CLKIDX_AdatAt44_1K: |
| 936 | case K1212_CLKIDX_WordAt44_1K: |
| 937 | case K1212_CLKIDX_LocalAt44_1K: |
| 938 | clkIs48K = 0; |
| 939 | break; |
| 940 | |
| 941 | case K1212_CLKIDX_WordAt48K: |
| 942 | case K1212_CLKIDX_AdatAt48K: |
| 943 | case K1212_CLKIDX_LocalAt48K: |
| 944 | default: |
| 945 | clkIs48K = 1; |
| 946 | break; |
| 947 | } |
| 948 | |
| 949 | // ---------------------------------------------------------------------------- |
| 950 | // start the update. Setup the bit structure and then shift the bits. |
| 951 | // ---------------------------------------------------------------------------- |
| 952 | sensVals.l.v.leftChanId = SET_SENS_LEFTCHANID; |
| 953 | sensVals.r.v.rightChanId = SET_SENS_RIGHTCHANID; |
| 954 | sensVals.l.v.leftChanVal = korg1212->leftADCInSens; |
| 955 | sensVals.r.v.rightChanVal = korg1212->rightADCInSens; |
| 956 | |
| 957 | // ---------------------------------------------------------------------------- |
| 958 | // now start shifting the bits in. Start with the left channel then the right. |
| 959 | // ---------------------------------------------------------------------------- |
| 960 | for (channel = 0; channel < 2; channel++) { |
| 961 | |
| 962 | // ---------------------------------------------------------------------------- |
| 963 | // Bring the load/shift line low, then wait - the spec says >150ns from load/ |
| 964 | // shift low to the first rising edge of the clock. |
| 965 | // ---------------------------------------------------------------------------- |
| 966 | ClearBitInWord(&controlValue, SET_SENS_LOADSHIFT_BITPOS); |
| 967 | ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); |
| 968 | writew(controlValue, korg1212->sensRegPtr); // load/shift goes low |
| 969 | udelay(LOADSHIFT_DELAY); |
| 970 | |
| 971 | for (bitPosition = 15; bitPosition >= 0; bitPosition--) { // for all the bits |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 972 | if (channel == 0) { |
| 973 | if (sensVals.l.leftSensBits & (0x0001 << bitPosition)) |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 974 | SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 975 | else |
| 976 | ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low |
| 977 | } else { |
| 978 | if (sensVals.r.rightSensBits & (0x0001 << bitPosition)) |
| 979 | SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high |
| 980 | else |
| 981 | ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low |
| 982 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); |
| 985 | writew(controlValue, korg1212->sensRegPtr); // clock goes low |
| 986 | udelay(SENSCLKPULSE_WIDTH); |
| 987 | SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); |
| 988 | writew(controlValue, korg1212->sensRegPtr); // clock goes high |
| 989 | udelay(SENSCLKPULSE_WIDTH); |
| 990 | } |
| 991 | |
| 992 | // ---------------------------------------------------------------------------- |
| 993 | // finish up SPDIF for left. Bring the load/shift line high, then write a one |
| 994 | // bit if the clock rate is 48K otherwise write 0. |
| 995 | // ---------------------------------------------------------------------------- |
| 996 | ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); |
| 997 | ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); |
| 998 | SetBitInWord(&controlValue, SET_SENS_LOADSHIFT_BITPOS); |
| 999 | writew(controlValue, korg1212->sensRegPtr); // load shift goes high - clk low |
| 1000 | udelay(SENSCLKPULSE_WIDTH); |
| 1001 | |
| 1002 | if (clkIs48K) |
| 1003 | SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); |
| 1004 | |
| 1005 | writew(controlValue, korg1212->sensRegPtr); // set/clear data bit |
| 1006 | udelay(ONE_RTC_TICK); |
| 1007 | SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); |
| 1008 | writew(controlValue, korg1212->sensRegPtr); // clock goes high |
| 1009 | udelay(SENSCLKPULSE_WIDTH); |
| 1010 | ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); |
| 1011 | writew(controlValue, korg1212->sensRegPtr); // clock goes low |
| 1012 | udelay(SENSCLKPULSE_WIDTH); |
| 1013 | } |
| 1014 | |
| 1015 | // ---------------------------------------------------------------------------- |
| 1016 | // The update is complete. Set a timeout. This is the inter-update delay. |
| 1017 | // Also, if the card was in monitor mode, restore it. |
| 1018 | // ---------------------------------------------------------------------------- |
| 1019 | for (count = 0; count < 10; count++) |
| 1020 | udelay(SENSCLKPULSE_WIDTH); |
| 1021 | |
| 1022 | if (monModeSet) { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1023 | int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | K1212_MODE_MonitorOn, 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1025 | if (rc) |
| 1026 | K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n", |
| 1027 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1031 | |
| 1032 | return 1; |
| 1033 | } |
| 1034 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1035 | static void snd_korg1212_OnDSPDownloadComplete(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1037 | int channel, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1039 | K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n", |
| 1040 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | // ---------------------------------------------------- |
| 1043 | // tell the card to boot |
| 1044 | // ---------------------------------------------------- |
| 1045 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_BootFromDSPPage4, 0, 0, 0, 0); |
| 1046 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1047 | if (rc) |
| 1048 | K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n", |
| 1049 | rc, stateName[korg1212->cardState]); |
| 1050 | msleep(DSP_BOOT_DELAY_IN_MS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
| 1052 | // -------------------------------------------------------------------------------- |
| 1053 | // Let the card know where all the buffers are. |
| 1054 | // -------------------------------------------------------------------------------- |
| 1055 | rc = snd_korg1212_Send1212Command(korg1212, |
| 1056 | K1212_DB_ConfigureBufferMemory, |
| 1057 | LowerWordSwap(korg1212->PlayDataPhy), |
| 1058 | LowerWordSwap(korg1212->RecDataPhy), |
| 1059 | ((kNumBuffers * kPlayBufferFrames) / 2), // size given to the card |
| 1060 | // is based on 2 buffers |
| 1061 | 0 |
| 1062 | ); |
| 1063 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1064 | if (rc) |
| 1065 | K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n", |
| 1066 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
| 1068 | udelay(INTERCOMMAND_DELAY); |
| 1069 | |
| 1070 | rc = snd_korg1212_Send1212Command(korg1212, |
| 1071 | K1212_DB_ConfigureMiscMemory, |
| 1072 | LowerWordSwap(korg1212->VolumeTablePhy), |
| 1073 | LowerWordSwap(korg1212->RoutingTablePhy), |
| 1074 | LowerWordSwap(korg1212->AdatTimeCodePhy), |
| 1075 | 0 |
| 1076 | ); |
| 1077 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1078 | if (rc) |
| 1079 | K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n", |
| 1080 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | // -------------------------------------------------------------------------------- |
| 1083 | // Initialize the routing and volume tables, then update the card's state. |
| 1084 | // -------------------------------------------------------------------------------- |
| 1085 | udelay(INTERCOMMAND_DELAY); |
| 1086 | |
| 1087 | for (channel = 0; channel < kAudioChannels; channel++) { |
| 1088 | korg1212->sharedBufferPtr->volumeData[channel] = k1212MaxVolume; |
| 1089 | //korg1212->sharedBufferPtr->routeData[channel] = channel; |
| 1090 | korg1212->sharedBufferPtr->routeData[channel] = 8 + (channel & 1); |
| 1091 | } |
| 1092 | |
| 1093 | snd_korg1212_WriteADCSensitivity(korg1212); |
| 1094 | |
| 1095 | udelay(INTERCOMMAND_DELAY); |
| 1096 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, |
| 1097 | ClockSourceSelector[korg1212->clkSrcRate], |
| 1098 | 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1099 | if (rc) |
| 1100 | K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", |
| 1101 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1103 | rc = snd_korg1212_TurnOnIdleMonitor(korg1212); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | snd_korg1212_setCardState(korg1212, K1212_STATE_READY); |
| 1105 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1106 | if (rc) |
| 1107 | K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n", |
| 1108 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE); |
| 1111 | } |
| 1112 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1113 | static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | { |
| 1115 | u32 doorbellValue; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1116 | struct snd_korg1212 *korg1212 = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | doorbellValue = readl(korg1212->inDoorbellPtr); |
| 1119 | |
| 1120 | if (!doorbellValue) |
| 1121 | return IRQ_NONE; |
| 1122 | |
| 1123 | spin_lock(&korg1212->lock); |
| 1124 | |
| 1125 | writel(doorbellValue, korg1212->inDoorbellPtr); |
| 1126 | |
| 1127 | korg1212->irqcount++; |
| 1128 | |
| 1129 | korg1212->inIRQ++; |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | switch (doorbellValue) { |
| 1132 | case K1212_DB_DSPDownloadDone: |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1133 | K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", |
| 1134 | korg1212->irqcount, doorbellValue, |
| 1135 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) { |
| 1137 | korg1212->dsp_is_loaded = 1; |
| 1138 | wake_up(&korg1212->wait); |
| 1139 | } |
| 1140 | break; |
| 1141 | |
| 1142 | // ------------------------------------------------------------------------ |
| 1143 | // an error occurred - stop the card |
| 1144 | // ------------------------------------------------------------------------ |
| 1145 | case K1212_DB_DMAERROR: |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1146 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", |
| 1147 | korg1212->irqcount, doorbellValue, |
| 1148 | stateName[korg1212->cardState]); |
| 1149 | snd_printk(KERN_ERR "korg1212: DMA Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | korg1212->errorcnt++; |
| 1151 | korg1212->totalerrorcnt++; |
| 1152 | korg1212->sharedBufferPtr->cardCommand = 0; |
| 1153 | snd_korg1212_setCardState(korg1212, K1212_STATE_ERRORSTOP); |
| 1154 | break; |
| 1155 | |
| 1156 | // ------------------------------------------------------------------------ |
| 1157 | // the card has stopped by our request. Clear the command word and signal |
| 1158 | // the semaphore in case someone is waiting for this. |
| 1159 | // ------------------------------------------------------------------------ |
| 1160 | case K1212_DB_CARDSTOPPED: |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1161 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1162 | korg1212->irqcount, doorbellValue, |
| 1163 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | korg1212->sharedBufferPtr->cardCommand = 0; |
| 1165 | break; |
| 1166 | |
| 1167 | default: |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1168 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1169 | korg1212->irqcount, doorbellValue, |
| 1170 | korg1212->currentBuffer, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | if ((korg1212->cardState > K1212_STATE_SETUP) || korg1212->idleMonitorOn) { |
| 1172 | korg1212->currentBuffer++; |
| 1173 | |
| 1174 | if (korg1212->currentBuffer >= kNumBuffers) |
| 1175 | korg1212->currentBuffer = 0; |
| 1176 | |
| 1177 | if (!korg1212->running) |
| 1178 | break; |
| 1179 | |
| 1180 | if (korg1212->capture_substream) { |
| 1181 | spin_unlock(&korg1212->lock); |
| 1182 | snd_pcm_period_elapsed(korg1212->capture_substream); |
| 1183 | spin_lock(&korg1212->lock); |
| 1184 | } |
| 1185 | |
| 1186 | if (korg1212->playback_substream) { |
| 1187 | spin_unlock(&korg1212->lock); |
| 1188 | snd_pcm_period_elapsed(korg1212->playback_substream); |
| 1189 | spin_lock(&korg1212->lock); |
| 1190 | } |
| 1191 | } |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | korg1212->inIRQ--; |
| 1196 | |
| 1197 | spin_unlock(&korg1212->lock); |
| 1198 | |
| 1199 | return IRQ_HANDLED; |
| 1200 | } |
| 1201 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1202 | static int snd_korg1212_downloadDSPCode(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1204 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1206 | K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n", |
| 1207 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
| 1209 | // --------------------------------------------------------------- |
| 1210 | // verify the state of the card before proceeding. |
| 1211 | // --------------------------------------------------------------- |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1212 | if (korg1212->cardState >= K1212_STATE_DSP_IN_PROCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
| 1215 | snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_IN_PROCESS); |
| 1216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_StartDSPDownload, |
| 1218 | UpperWordSwap(korg1212->dma_dsp.addr), |
| 1219 | 0, 0, 0); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1220 | if (rc) |
| 1221 | K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", |
| 1222 | rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | korg1212->dsp_is_loaded = 0; |
| 1225 | wait_event_timeout(korg1212->wait, korg1212->dsp_is_loaded, HZ * CARD_BOOT_TIMEOUT); |
| 1226 | if (! korg1212->dsp_is_loaded ) |
| 1227 | return -EBUSY; /* timeout */ |
| 1228 | |
| 1229 | snd_korg1212_OnDSPDownloadComplete(korg1212); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1234 | static struct snd_pcm_hardware snd_korg1212_playback_info = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
| 1236 | .info = (SNDRV_PCM_INFO_MMAP | |
| 1237 | SNDRV_PCM_INFO_MMAP_VALID | |
Takashi Iwai | 2008f13 | 2009-04-28 12:25:59 +0200 | [diff] [blame] | 1238 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1239 | SNDRV_PCM_INFO_BATCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1241 | .rates = (SNDRV_PCM_RATE_44100 | |
| 1242 | SNDRV_PCM_RATE_48000), |
| 1243 | .rate_min = 44100, |
| 1244 | .rate_max = 48000, |
| 1245 | .channels_min = K1212_MIN_CHANNELS, |
| 1246 | .channels_max = K1212_MAX_CHANNELS, |
| 1247 | .buffer_bytes_max = K1212_MAX_BUF_SIZE, |
| 1248 | .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, |
| 1249 | .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, |
| 1250 | .periods_min = K1212_PERIODS, |
| 1251 | .periods_max = K1212_PERIODS, |
| 1252 | .fifo_size = 0, |
| 1253 | }; |
| 1254 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1255 | static struct snd_pcm_hardware snd_korg1212_capture_info = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | { |
| 1257 | .info = (SNDRV_PCM_INFO_MMAP | |
| 1258 | SNDRV_PCM_INFO_MMAP_VALID | |
Takashi Iwai | 2008f13 | 2009-04-28 12:25:59 +0200 | [diff] [blame] | 1259 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1260 | SNDRV_PCM_INFO_BATCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1262 | .rates = (SNDRV_PCM_RATE_44100 | |
| 1263 | SNDRV_PCM_RATE_48000), |
| 1264 | .rate_min = 44100, |
| 1265 | .rate_max = 48000, |
| 1266 | .channels_min = K1212_MIN_CHANNELS, |
| 1267 | .channels_max = K1212_MAX_CHANNELS, |
| 1268 | .buffer_bytes_max = K1212_MAX_BUF_SIZE, |
| 1269 | .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, |
| 1270 | .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, |
| 1271 | .periods_min = K1212_PERIODS, |
| 1272 | .periods_max = K1212_PERIODS, |
| 1273 | .fifo_size = 0, |
| 1274 | }; |
| 1275 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1276 | static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int count, int offset, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1278 | struct KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | int i; |
| 1280 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1281 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", |
| 1282 | pos, offset, size, count); |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1283 | if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) |
| 1284 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | for (i=0; i < count; i++) { |
| 1287 | #if K1212_DEBUG_LEVEL > 0 |
| 1288 | if ( (void *) dst < (void *) korg1212->playDataBufsPtr || |
| 1289 | (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1290 | printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", |
| 1291 | dst, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | return -EFAULT; |
| 1293 | } |
| 1294 | #endif |
| 1295 | memset((void*) dst + offset, 0, size); |
| 1296 | dst++; |
| 1297 | } |
| 1298 | |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1302 | static int snd_korg1212_copy_to(struct snd_korg1212 *korg1212, void __user *dst, int pos, int count, int offset, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1304 | struct KorgAudioFrame * src = korg1212->recordDataBufsPtr[0].bufferData + pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | int i, rc; |
| 1306 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1307 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", |
| 1308 | pos, offset, size); |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1309 | if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) |
| 1310 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | for (i=0; i < count; i++) { |
| 1313 | #if K1212_DEBUG_LEVEL > 0 |
| 1314 | if ( (void *) src < (void *) korg1212->recordDataBufsPtr || |
| 1315 | (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1316 | printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | return -EFAULT; |
| 1318 | } |
| 1319 | #endif |
| 1320 | rc = copy_to_user(dst + offset, src, size); |
| 1321 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return -EFAULT; |
| 1324 | } |
| 1325 | src++; |
| 1326 | dst += size; |
| 1327 | } |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1332 | static int snd_korg1212_copy_from(struct snd_korg1212 *korg1212, void __user *src, int pos, int count, int offset, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1334 | struct KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | int i, rc; |
| 1336 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1337 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", |
| 1338 | pos, offset, size, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1340 | if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) |
| 1341 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | for (i=0; i < count; i++) { |
| 1344 | #if K1212_DEBUG_LEVEL > 0 |
| 1345 | if ( (void *) dst < (void *) korg1212->playDataBufsPtr || |
| 1346 | (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1347 | printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | return -EFAULT; |
| 1349 | } |
| 1350 | #endif |
| 1351 | rc = copy_from_user((void*) dst + offset, src, size); |
| 1352 | if (rc) { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1353 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return -EFAULT; |
| 1355 | } |
| 1356 | dst++; |
| 1357 | src += size; |
| 1358 | } |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1363 | static void snd_korg1212_free_pcm(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1365 | struct snd_korg1212 *korg1212 = pcm->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1367 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n", |
| 1368 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | korg1212->pcm = NULL; |
| 1371 | } |
| 1372 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1373 | static int snd_korg1212_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | { |
| 1375 | unsigned long flags; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1376 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
| 1377 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1379 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n", |
| 1380 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | snd_korg1212_OpenCard(korg1212); |
| 1383 | |
| 1384 | runtime->hw = snd_korg1212_playback_info; |
| 1385 | snd_pcm_set_runtime_buffer(substream, &korg1212->dma_play); |
| 1386 | |
| 1387 | spin_lock_irqsave(&korg1212->lock, flags); |
| 1388 | |
| 1389 | korg1212->playback_substream = substream; |
| 1390 | korg1212->playback_pid = current->pid; |
| 1391 | korg1212->periodsize = K1212_PERIODS; |
| 1392 | korg1212->channels = K1212_CHANNELS; |
| 1393 | korg1212->errorcnt = 0; |
| 1394 | |
| 1395 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1396 | |
Lars-Peter Clausen | 9c9cb68 | 2015-10-18 15:39:17 +0200 | [diff] [blame] | 1397 | snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1398 | kPlayBufferFrames); |
| 1399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1404 | static int snd_korg1212_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | { |
| 1406 | unsigned long flags; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1407 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
| 1408 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1410 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n", |
| 1411 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | snd_korg1212_OpenCard(korg1212); |
| 1414 | |
| 1415 | runtime->hw = snd_korg1212_capture_info; |
| 1416 | snd_pcm_set_runtime_buffer(substream, &korg1212->dma_rec); |
| 1417 | |
| 1418 | spin_lock_irqsave(&korg1212->lock, flags); |
| 1419 | |
| 1420 | korg1212->capture_substream = substream; |
| 1421 | korg1212->capture_pid = current->pid; |
| 1422 | korg1212->periodsize = K1212_PERIODS; |
| 1423 | korg1212->channels = K1212_CHANNELS; |
| 1424 | |
| 1425 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1426 | |
Lars-Peter Clausen | 9c9cb68 | 2015-10-18 15:39:17 +0200 | [diff] [blame] | 1427 | snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1428 | kPlayBufferFrames); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |
| 1431 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1432 | static int snd_korg1212_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | { |
| 1434 | unsigned long flags; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1435 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1437 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", |
| 1438 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
| 1440 | snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2); |
| 1441 | |
| 1442 | spin_lock_irqsave(&korg1212->lock, flags); |
| 1443 | |
| 1444 | korg1212->playback_pid = -1; |
| 1445 | korg1212->playback_substream = NULL; |
| 1446 | korg1212->periodsize = 0; |
| 1447 | |
| 1448 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1449 | |
| 1450 | snd_korg1212_CloseCard(korg1212); |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1454 | static int snd_korg1212_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | { |
| 1456 | unsigned long flags; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1457 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1459 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", |
| 1460 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
| 1462 | spin_lock_irqsave(&korg1212->lock, flags); |
| 1463 | |
| 1464 | korg1212->capture_pid = -1; |
| 1465 | korg1212->capture_substream = NULL; |
| 1466 | korg1212->periodsize = 0; |
| 1467 | |
| 1468 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1469 | |
| 1470 | snd_korg1212_CloseCard(korg1212); |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1474 | static int snd_korg1212_ioctl(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | unsigned int cmd, void *arg) |
| 1476 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1477 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
| 1479 | if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1480 | struct snd_pcm_channel_info *info = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | info->offset = 0; |
| 1482 | info->first = info->channel * 16; |
| 1483 | info->step = 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 1489 | } |
| 1490 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1491 | static int snd_korg1212_hw_params(struct snd_pcm_substream *substream, |
| 1492 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 1494 | unsigned long flags; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1495 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | int err; |
| 1497 | pid_t this_pid; |
| 1498 | pid_t other_pid; |
| 1499 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1500 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", |
| 1501 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
| 1503 | spin_lock_irqsave(&korg1212->lock, flags); |
| 1504 | |
| 1505 | if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 1506 | this_pid = korg1212->playback_pid; |
| 1507 | other_pid = korg1212->capture_pid; |
| 1508 | } else { |
| 1509 | this_pid = korg1212->capture_pid; |
| 1510 | other_pid = korg1212->playback_pid; |
| 1511 | } |
| 1512 | |
| 1513 | if ((other_pid > 0) && (this_pid != other_pid)) { |
| 1514 | |
| 1515 | /* The other stream is open, and not by the same |
| 1516 | task as this one. Make sure that the parameters |
| 1517 | that matter are the same. |
| 1518 | */ |
| 1519 | |
| 1520 | if ((int)params_rate(params) != korg1212->clkRate) { |
| 1521 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1522 | _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); |
| 1523 | return -EBUSY; |
| 1524 | } |
| 1525 | |
| 1526 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | if ((err = snd_korg1212_SetRate(korg1212, params_rate(params))) < 0) { |
| 1531 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1532 | return err; |
| 1533 | } |
| 1534 | |
| 1535 | korg1212->channels = params_channels(params); |
| 1536 | korg1212->periodsize = K1212_PERIOD_BYTES; |
| 1537 | |
| 1538 | spin_unlock_irqrestore(&korg1212->lock, flags); |
| 1539 | |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1543 | static int snd_korg1212_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1545 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | int rc; |
| 1547 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1548 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", |
| 1549 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
| 1551 | spin_lock_irq(&korg1212->lock); |
| 1552 | |
| 1553 | /* FIXME: we should wait for ack! */ |
| 1554 | if (korg1212->stop_pending_cnt > 0) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1555 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", |
| 1556 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | spin_unlock_irq(&korg1212->lock); |
| 1558 | return -EAGAIN; |
| 1559 | /* |
| 1560 | korg1212->sharedBufferPtr->cardCommand = 0; |
| 1561 | del_timer(&korg1212->timer); |
| 1562 | korg1212->stop_pending_cnt = 0; |
| 1563 | */ |
| 1564 | } |
| 1565 | |
| 1566 | rc = snd_korg1212_SetupForPlay(korg1212); |
| 1567 | |
| 1568 | korg1212->currentBuffer = 0; |
| 1569 | |
| 1570 | spin_unlock_irq(&korg1212->lock); |
| 1571 | |
| 1572 | return rc ? -EINVAL : 0; |
| 1573 | } |
| 1574 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1575 | static int snd_korg1212_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | int cmd) |
| 1577 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1578 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | int rc; |
| 1580 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1581 | K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", |
| 1582 | stateName[korg1212->cardState], cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
| 1584 | spin_lock(&korg1212->lock); |
| 1585 | switch (cmd) { |
| 1586 | case SNDRV_PCM_TRIGGER_START: |
| 1587 | /* |
| 1588 | if (korg1212->running) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1589 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | */ |
| 1593 | korg1212->running++; |
| 1594 | rc = snd_korg1212_TriggerPlay(korg1212); |
| 1595 | break; |
| 1596 | |
| 1597 | case SNDRV_PCM_TRIGGER_STOP: |
| 1598 | /* |
| 1599 | if (!korg1212->running) { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1600 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | break; |
| 1602 | } |
| 1603 | */ |
| 1604 | korg1212->running--; |
| 1605 | rc = snd_korg1212_StopPlay(korg1212); |
| 1606 | break; |
| 1607 | |
| 1608 | default: |
| 1609 | rc = 1; |
| 1610 | break; |
| 1611 | } |
| 1612 | spin_unlock(&korg1212->lock); |
| 1613 | return rc ? -EINVAL : 0; |
| 1614 | } |
| 1615 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1616 | static snd_pcm_uframes_t snd_korg1212_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1618 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | snd_pcm_uframes_t pos; |
| 1620 | |
| 1621 | pos = korg1212->currentBuffer * kPlayBufferFrames; |
| 1622 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1623 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", |
| 1624 | stateName[korg1212->cardState], pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
| 1626 | return pos; |
| 1627 | } |
| 1628 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1629 | static snd_pcm_uframes_t snd_korg1212_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1631 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | snd_pcm_uframes_t pos; |
| 1633 | |
| 1634 | pos = korg1212->currentBuffer * kPlayBufferFrames; |
| 1635 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1636 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n", |
| 1637 | stateName[korg1212->cardState], pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
| 1639 | return pos; |
| 1640 | } |
| 1641 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1642 | static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | int channel, /* not used (interleaved data) */ |
| 1644 | snd_pcm_uframes_t pos, |
| 1645 | void __user *src, |
| 1646 | snd_pcm_uframes_t count) |
| 1647 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1648 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1650 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", |
| 1651 | stateName[korg1212->cardState], pos, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
| 1653 | return snd_korg1212_copy_from(korg1212, src, pos, count, 0, korg1212->channels * 2); |
| 1654 | |
| 1655 | } |
| 1656 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1657 | static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | int channel, /* not used (interleaved data) */ |
| 1659 | snd_pcm_uframes_t pos, |
| 1660 | snd_pcm_uframes_t count) |
| 1661 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1662 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1664 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", |
| 1665 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | |
| 1667 | return snd_korg1212_silence(korg1212, pos, count, 0, korg1212->channels * 2); |
| 1668 | } |
| 1669 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1670 | static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | int channel, /* not used (interleaved data) */ |
| 1672 | snd_pcm_uframes_t pos, |
| 1673 | void __user *dst, |
| 1674 | snd_pcm_uframes_t count) |
| 1675 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1676 | struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 1678 | K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", |
| 1679 | stateName[korg1212->cardState], pos, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
| 1681 | return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2); |
| 1682 | } |
| 1683 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1684 | static const struct snd_pcm_ops snd_korg1212_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | .open = snd_korg1212_playback_open, |
| 1686 | .close = snd_korg1212_playback_close, |
| 1687 | .ioctl = snd_korg1212_ioctl, |
| 1688 | .hw_params = snd_korg1212_hw_params, |
| 1689 | .prepare = snd_korg1212_prepare, |
| 1690 | .trigger = snd_korg1212_trigger, |
| 1691 | .pointer = snd_korg1212_playback_pointer, |
| 1692 | .copy = snd_korg1212_playback_copy, |
| 1693 | .silence = snd_korg1212_playback_silence, |
| 1694 | }; |
| 1695 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1696 | static const struct snd_pcm_ops snd_korg1212_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | .open = snd_korg1212_capture_open, |
| 1698 | .close = snd_korg1212_capture_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_capture_pointer, |
| 1704 | .copy = snd_korg1212_capture_copy, |
| 1705 | }; |
| 1706 | |
| 1707 | /* |
| 1708 | * Control Interface |
| 1709 | */ |
| 1710 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1711 | static int snd_korg1212_control_phase_info(struct snd_kcontrol *kcontrol, |
| 1712 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | { |
| 1714 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1715 | uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1719 | static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol, |
| 1720 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1722 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | int i = kcontrol->private_value; |
| 1724 | |
| 1725 | spin_lock_irq(&korg1212->lock); |
| 1726 | |
| 1727 | u->value.integer.value[0] = korg1212->volumePhase[i]; |
| 1728 | |
| 1729 | if (i >= 8) |
| 1730 | u->value.integer.value[1] = korg1212->volumePhase[i+1]; |
| 1731 | |
| 1732 | spin_unlock_irq(&korg1212->lock); |
| 1733 | |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1737 | static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, |
| 1738 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1740 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | int change = 0; |
| 1742 | int i, val; |
| 1743 | |
| 1744 | spin_lock_irq(&korg1212->lock); |
| 1745 | |
| 1746 | i = kcontrol->private_value; |
| 1747 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1748 | korg1212->volumePhase[i] = !!u->value.integer.value[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
| 1750 | val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value]; |
| 1751 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1752 | if ((u->value.integer.value[0] != 0) != (val < 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | val = abs(val) * (korg1212->volumePhase[i] > 0 ? -1 : 1); |
| 1754 | korg1212->sharedBufferPtr->volumeData[i] = val; |
| 1755 | change = 1; |
| 1756 | } |
| 1757 | |
| 1758 | if (i >= 8) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1759 | korg1212->volumePhase[i+1] = !!u->value.integer.value[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
| 1761 | val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value+1]; |
| 1762 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1763 | if ((u->value.integer.value[1] != 0) != (val < 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | val = abs(val) * (korg1212->volumePhase[i+1] > 0 ? -1 : 1); |
| 1765 | korg1212->sharedBufferPtr->volumeData[i+1] = val; |
| 1766 | change = 1; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | spin_unlock_irq(&korg1212->lock); |
| 1771 | |
| 1772 | return change; |
| 1773 | } |
| 1774 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1775 | static int snd_korg1212_control_volume_info(struct snd_kcontrol *kcontrol, |
| 1776 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | { |
| 1778 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1779 | uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; |
| 1780 | uinfo->value.integer.min = k1212MinVolume; |
| 1781 | uinfo->value.integer.max = k1212MaxVolume; |
| 1782 | return 0; |
| 1783 | } |
| 1784 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1785 | static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol, |
| 1786 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1788 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | int i; |
| 1790 | |
| 1791 | spin_lock_irq(&korg1212->lock); |
| 1792 | |
| 1793 | i = kcontrol->private_value; |
| 1794 | u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]); |
| 1795 | |
| 1796 | if (i >= 8) |
| 1797 | u->value.integer.value[1] = abs(korg1212->sharedBufferPtr->volumeData[i+1]); |
| 1798 | |
| 1799 | spin_unlock_irq(&korg1212->lock); |
| 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1804 | static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, |
| 1805 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1807 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | int change = 0; |
| 1809 | int i; |
| 1810 | int val; |
| 1811 | |
| 1812 | spin_lock_irq(&korg1212->lock); |
| 1813 | |
| 1814 | i = kcontrol->private_value; |
| 1815 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1816 | if (u->value.integer.value[0] >= k1212MinVolume && |
| 1817 | u->value.integer.value[0] >= k1212MaxVolume && |
| 1818 | u->value.integer.value[0] != |
| 1819 | abs(korg1212->sharedBufferPtr->volumeData[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | val = korg1212->volumePhase[i] > 0 ? -1 : 1; |
| 1821 | val *= u->value.integer.value[0]; |
| 1822 | korg1212->sharedBufferPtr->volumeData[i] = val; |
| 1823 | change = 1; |
| 1824 | } |
| 1825 | |
| 1826 | if (i >= 8) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1827 | if (u->value.integer.value[1] >= k1212MinVolume && |
| 1828 | u->value.integer.value[1] >= k1212MaxVolume && |
| 1829 | u->value.integer.value[1] != |
| 1830 | abs(korg1212->sharedBufferPtr->volumeData[i+1])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | val = korg1212->volumePhase[i+1] > 0 ? -1 : 1; |
| 1832 | val *= u->value.integer.value[1]; |
| 1833 | korg1212->sharedBufferPtr->volumeData[i+1] = val; |
| 1834 | change = 1; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | spin_unlock_irq(&korg1212->lock); |
| 1839 | |
| 1840 | return change; |
| 1841 | } |
| 1842 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1843 | static int snd_korg1212_control_route_info(struct snd_kcontrol *kcontrol, |
| 1844 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | { |
Takashi Iwai | f861237 | 2014-10-20 18:21:58 +0200 | [diff] [blame] | 1846 | return snd_ctl_enum_info(uinfo, |
| 1847 | (kcontrol->private_value >= 8) ? 2 : 1, |
| 1848 | kAudioChannels, channelName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1851 | static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol, |
| 1852 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1854 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | int i; |
| 1856 | |
| 1857 | spin_lock_irq(&korg1212->lock); |
| 1858 | |
| 1859 | i = kcontrol->private_value; |
| 1860 | u->value.enumerated.item[0] = korg1212->sharedBufferPtr->routeData[i]; |
| 1861 | |
| 1862 | if (i >= 8) |
| 1863 | u->value.enumerated.item[1] = korg1212->sharedBufferPtr->routeData[i+1]; |
| 1864 | |
| 1865 | spin_unlock_irq(&korg1212->lock); |
| 1866 | |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1870 | static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol, |
| 1871 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1873 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | int change = 0, i; |
| 1875 | |
| 1876 | spin_lock_irq(&korg1212->lock); |
| 1877 | |
| 1878 | i = kcontrol->private_value; |
| 1879 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1880 | if (u->value.enumerated.item[0] < kAudioChannels && |
| 1881 | u->value.enumerated.item[0] != |
| 1882 | (unsigned) korg1212->sharedBufferPtr->volumeData[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | korg1212->sharedBufferPtr->routeData[i] = u->value.enumerated.item[0]; |
| 1884 | change = 1; |
| 1885 | } |
| 1886 | |
| 1887 | if (i >= 8) { |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1888 | if (u->value.enumerated.item[1] < kAudioChannels && |
| 1889 | u->value.enumerated.item[1] != |
| 1890 | (unsigned) korg1212->sharedBufferPtr->volumeData[i+1]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | korg1212->sharedBufferPtr->routeData[i+1] = u->value.enumerated.item[1]; |
| 1892 | change = 1; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | spin_unlock_irq(&korg1212->lock); |
| 1897 | |
| 1898 | return change; |
| 1899 | } |
| 1900 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1901 | static int snd_korg1212_control_info(struct snd_kcontrol *kcontrol, |
| 1902 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | { |
| 1904 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1905 | uinfo->count = 2; |
| 1906 | uinfo->value.integer.min = k1212MaxADCSens; |
| 1907 | uinfo->value.integer.max = k1212MinADCSens; |
| 1908 | return 0; |
| 1909 | } |
| 1910 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1911 | static int snd_korg1212_control_get(struct snd_kcontrol *kcontrol, |
| 1912 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1914 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | |
| 1916 | spin_lock_irq(&korg1212->lock); |
| 1917 | |
| 1918 | u->value.integer.value[0] = korg1212->leftADCInSens; |
| 1919 | u->value.integer.value[1] = korg1212->rightADCInSens; |
| 1920 | |
| 1921 | spin_unlock_irq(&korg1212->lock); |
| 1922 | |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1926 | static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol, |
| 1927 | struct snd_ctl_elem_value *u) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1929 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | int change = 0; |
| 1931 | |
| 1932 | spin_lock_irq(&korg1212->lock); |
| 1933 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1934 | if (u->value.integer.value[0] >= k1212MinADCSens && |
| 1935 | u->value.integer.value[0] <= k1212MaxADCSens && |
| 1936 | u->value.integer.value[0] != korg1212->leftADCInSens) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | korg1212->leftADCInSens = u->value.integer.value[0]; |
| 1938 | change = 1; |
| 1939 | } |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1940 | if (u->value.integer.value[1] >= k1212MinADCSens && |
| 1941 | u->value.integer.value[1] <= k1212MaxADCSens && |
| 1942 | u->value.integer.value[1] != korg1212->rightADCInSens) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | korg1212->rightADCInSens = u->value.integer.value[1]; |
| 1944 | change = 1; |
| 1945 | } |
| 1946 | |
| 1947 | spin_unlock_irq(&korg1212->lock); |
| 1948 | |
| 1949 | if (change) |
| 1950 | snd_korg1212_WriteADCSensitivity(korg1212); |
| 1951 | |
| 1952 | return change; |
| 1953 | } |
| 1954 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1955 | static int snd_korg1212_control_sync_info(struct snd_kcontrol *kcontrol, |
| 1956 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
Takashi Iwai | f861237 | 2014-10-20 18:21:58 +0200 | [diff] [blame] | 1958 | return snd_ctl_enum_info(uinfo, 1, 3, clockSourceTypeName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1961 | static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol, |
| 1962 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1964 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | |
| 1966 | spin_lock_irq(&korg1212->lock); |
| 1967 | |
| 1968 | ucontrol->value.enumerated.item[0] = korg1212->clkSource; |
| 1969 | |
| 1970 | spin_unlock_irq(&korg1212->lock); |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1974 | static int snd_korg1212_control_sync_put(struct snd_kcontrol *kcontrol, |
| 1975 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 1977 | struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | unsigned int val; |
| 1979 | int change; |
| 1980 | |
| 1981 | val = ucontrol->value.enumerated.item[0] % 3; |
| 1982 | spin_lock_irq(&korg1212->lock); |
| 1983 | change = val != korg1212->clkSource; |
| 1984 | snd_korg1212_SetClockSource(korg1212, val); |
| 1985 | spin_unlock_irq(&korg1212->lock); |
| 1986 | return change; |
| 1987 | } |
| 1988 | |
| 1989 | #define MON_MIXER(ord,c_name) \ |
| 1990 | { \ |
| 1991 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ |
| 1992 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 1993 | .name = c_name " Monitor Volume", \ |
| 1994 | .info = snd_korg1212_control_volume_info, \ |
| 1995 | .get = snd_korg1212_control_volume_get, \ |
| 1996 | .put = snd_korg1212_control_volume_put, \ |
| 1997 | .private_value = ord, \ |
| 1998 | }, \ |
| 1999 | { \ |
| 2000 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ |
| 2001 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2002 | .name = c_name " Monitor Route", \ |
| 2003 | .info = snd_korg1212_control_route_info, \ |
| 2004 | .get = snd_korg1212_control_route_get, \ |
| 2005 | .put = snd_korg1212_control_route_put, \ |
| 2006 | .private_value = ord, \ |
| 2007 | }, \ |
| 2008 | { \ |
| 2009 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2010 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | .name = c_name " Monitor Phase Invert", \ |
| 2012 | .info = snd_korg1212_control_phase_info, \ |
| 2013 | .get = snd_korg1212_control_phase_get, \ |
| 2014 | .put = snd_korg1212_control_phase_put, \ |
| 2015 | .private_value = ord, \ |
| 2016 | } |
| 2017 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2018 | static struct snd_kcontrol_new snd_korg1212_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | MON_MIXER(8, "Analog"), |
| 2020 | MON_MIXER(10, "SPDIF"), |
| 2021 | MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"), |
| 2022 | MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"), |
| 2023 | { |
| 2024 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2025 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | .name = "Sync Source", |
| 2027 | .info = snd_korg1212_control_sync_info, |
| 2028 | .get = snd_korg1212_control_sync_get, |
| 2029 | .put = snd_korg1212_control_sync_put, |
| 2030 | }, |
| 2031 | { |
| 2032 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, |
| 2033 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2034 | .name = "ADC Attenuation", |
| 2035 | .info = snd_korg1212_control_info, |
| 2036 | .get = snd_korg1212_control_get, |
| 2037 | .put = snd_korg1212_control_put, |
| 2038 | } |
| 2039 | }; |
| 2040 | |
| 2041 | /* |
| 2042 | * proc interface |
| 2043 | */ |
| 2044 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2045 | static void snd_korg1212_proc_read(struct snd_info_entry *entry, |
| 2046 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | { |
| 2048 | int n; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2049 | struct snd_korg1212 *korg1212 = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
| 2051 | snd_iprintf(buffer, korg1212->card->longname); |
| 2052 | snd_iprintf(buffer, " (index #%d)\n", korg1212->card->number + 1); |
| 2053 | snd_iprintf(buffer, "\nGeneral settings\n"); |
| 2054 | snd_iprintf(buffer, " period size: %Zd bytes\n", K1212_PERIOD_BYTES); |
| 2055 | snd_iprintf(buffer, " clock mode: %s\n", clockSourceName[korg1212->clkSrcRate] ); |
| 2056 | snd_iprintf(buffer, " left ADC Sens: %d\n", korg1212->leftADCInSens ); |
| 2057 | snd_iprintf(buffer, " right ADC Sens: %d\n", korg1212->rightADCInSens ); |
| 2058 | snd_iprintf(buffer, " Volume Info:\n"); |
| 2059 | for (n=0; n<kAudioChannels; n++) |
| 2060 | snd_iprintf(buffer, " Channel %d: %s -> %s [%d]\n", n, |
| 2061 | channelName[n], |
| 2062 | channelName[korg1212->sharedBufferPtr->routeData[n]], |
| 2063 | korg1212->sharedBufferPtr->volumeData[n]); |
| 2064 | snd_iprintf(buffer, "\nGeneral status\n"); |
| 2065 | snd_iprintf(buffer, " ADAT Time Code: %d\n", korg1212->sharedBufferPtr->AdatTimeCode); |
| 2066 | snd_iprintf(buffer, " Card State: %s\n", stateName[korg1212->cardState]); |
| 2067 | snd_iprintf(buffer, "Idle mon. State: %d\n", korg1212->idleMonitorOn); |
| 2068 | snd_iprintf(buffer, "Cmd retry count: %d\n", korg1212->cmdRetryCount); |
| 2069 | snd_iprintf(buffer, " Irq count: %ld\n", korg1212->irqcount); |
| 2070 | snd_iprintf(buffer, " Error count: %ld\n", korg1212->totalerrorcnt); |
| 2071 | } |
| 2072 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2073 | static void snd_korg1212_proc_init(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2075 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
| 2077 | if (! snd_card_proc_new(korg1212->card, "korg1212", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2078 | snd_info_set_text_ops(entry, korg1212, snd_korg1212_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | static int |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2082 | snd_korg1212_free(struct snd_korg1212 *korg1212) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
| 2084 | snd_korg1212_TurnOffIdleMonitor(korg1212); |
| 2085 | |
| 2086 | if (korg1212->irq >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | snd_korg1212_DisableCardInterrupts(korg1212); |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 2088 | free_irq(korg1212->irq, korg1212); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | korg1212->irq = -1; |
| 2090 | } |
| 2091 | |
| 2092 | if (korg1212->iobase != NULL) { |
| 2093 | iounmap(korg1212->iobase); |
| 2094 | korg1212->iobase = NULL; |
| 2095 | } |
| 2096 | |
| 2097 | pci_release_regions(korg1212->pci); |
| 2098 | |
| 2099 | // ---------------------------------------------------- |
| 2100 | // free up memory resources used for the DSP download. |
| 2101 | // ---------------------------------------------------- |
| 2102 | if (korg1212->dma_dsp.area) { |
| 2103 | snd_dma_free_pages(&korg1212->dma_dsp); |
| 2104 | korg1212->dma_dsp.area = NULL; |
| 2105 | } |
| 2106 | |
| 2107 | #ifndef K1212_LARGEALLOC |
| 2108 | |
| 2109 | // ------------------------------------------------------ |
| 2110 | // free up memory resources used for the Play/Rec Buffers |
| 2111 | // ------------------------------------------------------ |
| 2112 | if (korg1212->dma_play.area) { |
| 2113 | snd_dma_free_pages(&korg1212->dma_play); |
| 2114 | korg1212->dma_play.area = NULL; |
| 2115 | } |
| 2116 | |
| 2117 | if (korg1212->dma_rec.area) { |
| 2118 | snd_dma_free_pages(&korg1212->dma_rec); |
| 2119 | korg1212->dma_rec.area = NULL; |
| 2120 | } |
| 2121 | |
| 2122 | #endif |
| 2123 | |
| 2124 | // ---------------------------------------------------- |
| 2125 | // free up memory resources used for the Shared Buffers |
| 2126 | // ---------------------------------------------------- |
| 2127 | if (korg1212->dma_shared.area) { |
| 2128 | snd_dma_free_pages(&korg1212->dma_shared); |
| 2129 | korg1212->dma_shared.area = NULL; |
| 2130 | } |
| 2131 | |
| 2132 | pci_disable_device(korg1212->pci); |
| 2133 | kfree(korg1212); |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2137 | static int snd_korg1212_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | { |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2139 | struct snd_korg1212 *korg1212 = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | return snd_korg1212_free(korg1212); |
| 2142 | } |
| 2143 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2144 | static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, |
| 2145 | struct snd_korg1212 **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
| 2147 | { |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 2148 | int err, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | unsigned int i; |
| 2150 | unsigned ioport_size, iomem_size, iomem2_size; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2151 | struct snd_korg1212 * korg1212; |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2152 | const struct firmware *dsp_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2154 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | .dev_free = snd_korg1212_dev_free, |
| 2156 | }; |
| 2157 | |
| 2158 | * rchip = NULL; |
| 2159 | if ((err = pci_enable_device(pci)) < 0) |
| 2160 | return err; |
| 2161 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 2162 | korg1212 = kzalloc(sizeof(*korg1212), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | if (korg1212 == NULL) { |
| 2164 | pci_disable_device(pci); |
| 2165 | return -ENOMEM; |
| 2166 | } |
| 2167 | |
| 2168 | korg1212->card = card; |
| 2169 | korg1212->pci = pci; |
| 2170 | |
| 2171 | init_waitqueue_head(&korg1212->wait); |
| 2172 | spin_lock_init(&korg1212->lock); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2173 | mutex_init(&korg1212->open_mutex); |
Takashi Iwai | 3d6f0e0 | 2015-01-19 11:34:18 +0100 | [diff] [blame] | 2174 | setup_timer(&korg1212->timer, snd_korg1212_timer_func, |
| 2175 | (unsigned long)korg1212); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | |
| 2177 | korg1212->irq = -1; |
| 2178 | korg1212->clkSource = K1212_CLKIDX_Local; |
| 2179 | korg1212->clkRate = 44100; |
| 2180 | korg1212->inIRQ = 0; |
| 2181 | korg1212->running = 0; |
| 2182 | korg1212->opencnt = 0; |
| 2183 | korg1212->playcnt = 0; |
| 2184 | korg1212->setcnt = 0; |
| 2185 | korg1212->totalerrorcnt = 0; |
| 2186 | korg1212->playback_pid = -1; |
| 2187 | korg1212->capture_pid = -1; |
| 2188 | snd_korg1212_setCardState(korg1212, K1212_STATE_UNINITIALIZED); |
| 2189 | korg1212->idleMonitorOn = 0; |
| 2190 | korg1212->clkSrcRate = K1212_CLKIDX_LocalAt44_1K; |
| 2191 | korg1212->leftADCInSens = k1212MaxADCSens; |
| 2192 | korg1212->rightADCInSens = k1212MaxADCSens; |
| 2193 | |
| 2194 | for (i=0; i<kAudioChannels; i++) |
| 2195 | korg1212->volumePhase[i] = 0; |
| 2196 | |
| 2197 | if ((err = pci_request_regions(pci, "korg1212")) < 0) { |
| 2198 | kfree(korg1212); |
| 2199 | pci_disable_device(pci); |
| 2200 | return err; |
| 2201 | } |
| 2202 | |
| 2203 | korg1212->iomem = pci_resource_start(korg1212->pci, 0); |
| 2204 | korg1212->ioport = pci_resource_start(korg1212->pci, 1); |
| 2205 | korg1212->iomem2 = pci_resource_start(korg1212->pci, 2); |
| 2206 | |
| 2207 | iomem_size = pci_resource_len(korg1212->pci, 0); |
| 2208 | ioport_size = pci_resource_len(korg1212->pci, 1); |
| 2209 | iomem2_size = pci_resource_len(korg1212->pci, 2); |
| 2210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n" |
| 2212 | " iomem = 0x%lx (%d)\n" |
| 2213 | " ioport = 0x%lx (%d)\n" |
| 2214 | " iomem = 0x%lx (%d)\n" |
| 2215 | " [%s]\n", |
| 2216 | korg1212->iomem, iomem_size, |
| 2217 | korg1212->ioport, ioport_size, |
| 2218 | korg1212->iomem2, iomem2_size, |
| 2219 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | |
| 2221 | if ((korg1212->iobase = ioremap(korg1212->iomem, iomem_size)) == NULL) { |
| 2222 | snd_printk(KERN_ERR "korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212->iomem, |
| 2223 | korg1212->iomem + iomem_size - 1); |
| 2224 | snd_korg1212_free(korg1212); |
| 2225 | return -EBUSY; |
| 2226 | } |
| 2227 | |
| 2228 | err = request_irq(pci->irq, snd_korg1212_interrupt, |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2229 | IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 2230 | KBUILD_MODNAME, korg1212); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
| 2232 | if (err) { |
| 2233 | snd_printk(KERN_ERR "korg1212: unable to grab IRQ %d\n", pci->irq); |
| 2234 | snd_korg1212_free(korg1212); |
| 2235 | return -EBUSY; |
| 2236 | } |
| 2237 | |
| 2238 | korg1212->irq = pci->irq; |
| 2239 | |
| 2240 | pci_set_master(korg1212->pci); |
| 2241 | |
| 2242 | korg1212->statusRegPtr = (u32 __iomem *) (korg1212->iobase + STATUS_REG_OFFSET); |
| 2243 | korg1212->outDoorbellPtr = (u32 __iomem *) (korg1212->iobase + OUT_DOORBELL_OFFSET); |
| 2244 | korg1212->inDoorbellPtr = (u32 __iomem *) (korg1212->iobase + IN_DOORBELL_OFFSET); |
| 2245 | korg1212->mailbox0Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX0_OFFSET); |
| 2246 | korg1212->mailbox1Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX1_OFFSET); |
| 2247 | korg1212->mailbox2Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX2_OFFSET); |
| 2248 | korg1212->mailbox3Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX3_OFFSET); |
| 2249 | korg1212->controlRegPtr = (u32 __iomem *) (korg1212->iobase + PCI_CONTROL_OFFSET); |
| 2250 | korg1212->sensRegPtr = (u16 __iomem *) (korg1212->iobase + SENS_CONTROL_OFFSET); |
| 2251 | korg1212->idRegPtr = (u32 __iomem *) (korg1212->iobase + DEV_VEND_ID_OFFSET); |
| 2252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n" |
| 2254 | " Status register = 0x%p\n" |
| 2255 | " OutDoorbell = 0x%p\n" |
| 2256 | " InDoorbell = 0x%p\n" |
| 2257 | " Mailbox0 = 0x%p\n" |
| 2258 | " Mailbox1 = 0x%p\n" |
| 2259 | " Mailbox2 = 0x%p\n" |
| 2260 | " Mailbox3 = 0x%p\n" |
| 2261 | " ControlReg = 0x%p\n" |
| 2262 | " SensReg = 0x%p\n" |
| 2263 | " IDReg = 0x%p\n" |
| 2264 | " [%s]\n", |
| 2265 | korg1212->statusRegPtr, |
| 2266 | korg1212->outDoorbellPtr, |
| 2267 | korg1212->inDoorbellPtr, |
| 2268 | korg1212->mailbox0Ptr, |
| 2269 | korg1212->mailbox1Ptr, |
| 2270 | korg1212->mailbox2Ptr, |
| 2271 | korg1212->mailbox3Ptr, |
| 2272 | korg1212->controlRegPtr, |
| 2273 | korg1212->sensRegPtr, |
| 2274 | korg1212->idRegPtr, |
| 2275 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | |
| 2277 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2278 | sizeof(struct KorgSharedBuffer), &korg1212->dma_shared) < 0) { |
| 2279 | snd_printk(KERN_ERR "korg1212: can not allocate shared buffer memory (%Zd bytes)\n", sizeof(struct KorgSharedBuffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | snd_korg1212_free(korg1212); |
| 2281 | return -ENOMEM; |
| 2282 | } |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2283 | korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared.area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | korg1212->sharedBufferPhy = korg1212->dma_shared.addr; |
| 2285 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2286 | K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212->sharedBufferPtr, korg1212->sharedBufferPhy, sizeof(struct KorgSharedBuffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | |
| 2288 | #ifndef K1212_LARGEALLOC |
| 2289 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2290 | korg1212->DataBufsSize = sizeof(struct KorgAudioBuffer) * kNumBuffers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | |
| 2292 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), |
| 2293 | korg1212->DataBufsSize, &korg1212->dma_play) < 0) { |
| 2294 | snd_printk(KERN_ERR "korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize); |
| 2295 | snd_korg1212_free(korg1212); |
| 2296 | return -ENOMEM; |
| 2297 | } |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2298 | korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play.area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | korg1212->PlayDataPhy = korg1212->dma_play.addr; |
| 2300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n", |
| 2302 | korg1212->playDataBufsPtr, korg1212->PlayDataPhy, korg1212->DataBufsSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | |
| 2304 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), |
| 2305 | korg1212->DataBufsSize, &korg1212->dma_rec) < 0) { |
| 2306 | snd_printk(KERN_ERR "korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize); |
| 2307 | snd_korg1212_free(korg1212); |
| 2308 | return -ENOMEM; |
| 2309 | } |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2310 | korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec.area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | korg1212->RecDataPhy = korg1212->dma_rec.addr; |
| 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n", |
| 2314 | korg1212->recordDataBufsPtr, korg1212->RecDataPhy, korg1212->DataBufsSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
| 2316 | #else // K1212_LARGEALLOC |
| 2317 | |
| 2318 | korg1212->recordDataBufsPtr = korg1212->sharedBufferPtr->recordDataBufs; |
| 2319 | korg1212->playDataBufsPtr = korg1212->sharedBufferPtr->playDataBufs; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2320 | korg1212->PlayDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->playDataBufs; |
| 2321 | korg1212->RecDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->recordDataBufs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
| 2323 | #endif // K1212_LARGEALLOC |
| 2324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | korg1212->VolumeTablePhy = korg1212->sharedBufferPhy + |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2326 | offsetof(struct KorgSharedBuffer, volumeData); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | korg1212->RoutingTablePhy = korg1212->sharedBufferPhy + |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2328 | offsetof(struct KorgSharedBuffer, routeData); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy + |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2330 | offsetof(struct KorgSharedBuffer, AdatTimeCode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2332 | err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev); |
| 2333 | if (err < 0) { |
| 2334 | release_firmware(dsp_code); |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2335 | snd_printk(KERN_ERR "firmware not available\n"); |
| 2336 | snd_korg1212_free(korg1212); |
| 2337 | return err; |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2338 | } |
| 2339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2341 | dsp_code->size, &korg1212->dma_dsp) < 0) { |
Randy Dunlap | 9fb62c9 | 2006-11-21 19:01:51 +0100 | [diff] [blame] | 2342 | snd_printk(KERN_ERR "korg1212: cannot allocate dsp code memory (%zd bytes)\n", dsp_code->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | snd_korg1212_free(korg1212); |
Takashi Iwai | b7dd2b3 | 2007-04-26 14:13:44 +0200 | [diff] [blame] | 2344 | release_firmware(dsp_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | return -ENOMEM; |
| 2346 | } |
| 2347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n", |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2349 | korg1212->dma_dsp.area, korg1212->dma_dsp.addr, dsp_code->size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2352 | memcpy(korg1212->dma_dsp.area, dsp_code->data, dsp_code->size); |
| 2353 | |
Takashi Iwai | b7dd2b3 | 2007-04-26 14:13:44 +0200 | [diff] [blame] | 2354 | release_firmware(dsp_code); |
Clemens Ladisch | 2493a6d | 2006-11-06 09:24:29 +0100 | [diff] [blame] | 2355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_RebootCard, 0, 0, 0, 0); |
| 2357 | |
Takashi Iwai | 9fd9156 | 2005-11-17 10:45:48 +0100 | [diff] [blame] | 2358 | if (rc) |
| 2359 | K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | |
| 2361 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops)) < 0) { |
| 2362 | snd_korg1212_free(korg1212); |
| 2363 | return err; |
| 2364 | } |
| 2365 | |
| 2366 | snd_korg1212_EnableCardInterrupts(korg1212); |
| 2367 | |
| 2368 | mdelay(CARD_BOOT_DELAY_IN_MS); |
| 2369 | |
| 2370 | if (snd_korg1212_downloadDSPCode(korg1212)) |
| 2371 | return -EBUSY; |
| 2372 | |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2373 | K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)); |
| 2385 | |
| 2386 | if ((err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm)) < 0) |
| 2387 | return err; |
| 2388 | |
| 2389 | korg1212->pcm->private_data = korg1212; |
| 2390 | korg1212->pcm->private_free = snd_korg1212_free_pcm; |
| 2391 | strcpy(korg1212->pcm->name, "korg1212"); |
| 2392 | |
| 2393 | snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_korg1212_playback_ops); |
| 2394 | |
| 2395 | snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_korg1212_capture_ops); |
| 2396 | |
| 2397 | korg1212->pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 2398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)); |
| 2401 | if (err < 0) |
| 2402 | return err; |
| 2403 | } |
| 2404 | |
| 2405 | snd_korg1212_proc_init(korg1212); |
| 2406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | * rchip = korg1212; |
| 2408 | return 0; |
| 2409 | |
| 2410 | } |
| 2411 | |
| 2412 | /* |
| 2413 | * Card initialisation |
| 2414 | */ |
| 2415 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2416 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | snd_korg1212_probe(struct pci_dev *pci, |
| 2418 | const struct pci_device_id *pci_id) |
| 2419 | { |
| 2420 | static int dev; |
Takashi Iwai | fcfd333 | 2005-11-17 15:00:46 +0100 | [diff] [blame] | 2421 | struct snd_korg1212 *korg1212; |
| 2422 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | int err; |
| 2424 | |
| 2425 | if (dev >= SNDRV_CARDS) { |
| 2426 | return -ENODEV; |
| 2427 | } |
| 2428 | if (!enable[dev]) { |
| 2429 | dev++; |
| 2430 | return -ENOENT; |
| 2431 | } |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 2432 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 2433 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 2434 | if (err < 0) |
| 2435 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | |
| 2437 | if ((err = snd_korg1212_create(card, pci, &korg1212)) < 0) { |
| 2438 | snd_card_free(card); |
| 2439 | return err; |
| 2440 | } |
| 2441 | |
| 2442 | strcpy(card->driver, "korg1212"); |
| 2443 | strcpy(card->shortname, "korg1212"); |
| 2444 | sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, |
| 2445 | korg1212->iomem, korg1212->irq); |
| 2446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | |
| 2449 | if ((err = snd_card_register(card)) < 0) { |
| 2450 | snd_card_free(card); |
| 2451 | return err; |
| 2452 | } |
| 2453 | pci_set_drvdata(pci, card); |
| 2454 | dev++; |
| 2455 | return 0; |
| 2456 | } |
| 2457 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2458 | static void snd_korg1212_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
| 2460 | snd_card_free(pci_get_drvdata(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2463 | static struct pci_driver korg1212_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 2464 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | .id_table = snd_korg1212_ids, |
| 2466 | .probe = snd_korg1212_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2467 | .remove = snd_korg1212_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | }; |
| 2469 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2470 | module_pci_driver(korg1212_driver); |