korg1212.c 90 KB

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