rme96.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445
  1. /*
  2. * ALSA driver for RME Digi96, Digi96/8 and Digi96/8 PRO/PAD/PST audio
  3. * interfaces
  4. *
  5. * Copyright (c) 2000, 2001 Anders Torger <torger@ludd.luth.se>
  6. *
  7. * Thanks to Henk Hesselink <henk@anda.nl> for the analog volume control
  8. * code.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <sound/driver.h>
  26. #include <linux/delay.h>
  27. #include <linux/init.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/slab.h>
  31. #include <linux/moduleparam.h>
  32. #include <sound/core.h>
  33. #include <sound/info.h>
  34. #include <sound/control.h>
  35. #include <sound/pcm.h>
  36. #include <sound/pcm_params.h>
  37. #include <sound/asoundef.h>
  38. #include <sound/initval.h>
  39. #include <asm/io.h>
  40. /* note, two last pcis should be equal, it is not a bug */
  41. MODULE_AUTHOR("Anders Torger <torger@ludd.luth.se>");
  42. MODULE_DESCRIPTION("RME Digi96, Digi96/8, Digi96/8 PRO, Digi96/8 PST, "
  43. "Digi96/8 PAD");
  44. MODULE_LICENSE("GPL");
  45. MODULE_SUPPORTED_DEVICE("{{RME,Digi96},"
  46. "{RME,Digi96/8},"
  47. "{RME,Digi96/8 PRO},"
  48. "{RME,Digi96/8 PST},"
  49. "{RME,Digi96/8 PAD}}");
  50. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  51. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  52. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  53. module_param_array(index, int, NULL, 0444);
  54. MODULE_PARM_DESC(index, "Index value for RME Digi96 soundcard.");
  55. module_param_array(id, charp, NULL, 0444);
  56. MODULE_PARM_DESC(id, "ID string for RME Digi96 soundcard.");
  57. module_param_array(enable, bool, NULL, 0444);
  58. MODULE_PARM_DESC(enable, "Enable RME Digi96 soundcard.");
  59. /*
  60. * Defines for RME Digi96 series, from internal RME reference documents
  61. * dated 12.01.00
  62. */
  63. #define RME96_SPDIF_NCHANNELS 2
  64. /* Playback and capture buffer size */
  65. #define RME96_BUFFER_SIZE 0x10000
  66. /* IO area size */
  67. #define RME96_IO_SIZE 0x60000
  68. /* IO area offsets */
  69. #define RME96_IO_PLAY_BUFFER 0x0
  70. #define RME96_IO_REC_BUFFER 0x10000
  71. #define RME96_IO_CONTROL_REGISTER 0x20000
  72. #define RME96_IO_ADDITIONAL_REG 0x20004
  73. #define RME96_IO_CONFIRM_PLAY_IRQ 0x20008
  74. #define RME96_IO_CONFIRM_REC_IRQ 0x2000C
  75. #define RME96_IO_SET_PLAY_POS 0x40000
  76. #define RME96_IO_RESET_PLAY_POS 0x4FFFC
  77. #define RME96_IO_SET_REC_POS 0x50000
  78. #define RME96_IO_RESET_REC_POS 0x5FFFC
  79. #define RME96_IO_GET_PLAY_POS 0x20000
  80. #define RME96_IO_GET_REC_POS 0x30000
  81. /* Write control register bits */
  82. #define RME96_WCR_START (1 << 0)
  83. #define RME96_WCR_START_2 (1 << 1)
  84. #define RME96_WCR_GAIN_0 (1 << 2)
  85. #define RME96_WCR_GAIN_1 (1 << 3)
  86. #define RME96_WCR_MODE24 (1 << 4)
  87. #define RME96_WCR_MODE24_2 (1 << 5)
  88. #define RME96_WCR_BM (1 << 6)
  89. #define RME96_WCR_BM_2 (1 << 7)
  90. #define RME96_WCR_ADAT (1 << 8)
  91. #define RME96_WCR_FREQ_0 (1 << 9)
  92. #define RME96_WCR_FREQ_1 (1 << 10)
  93. #define RME96_WCR_DS (1 << 11)
  94. #define RME96_WCR_PRO (1 << 12)
  95. #define RME96_WCR_EMP (1 << 13)
  96. #define RME96_WCR_SEL (1 << 14)
  97. #define RME96_WCR_MASTER (1 << 15)
  98. #define RME96_WCR_PD (1 << 16)
  99. #define RME96_WCR_INP_0 (1 << 17)
  100. #define RME96_WCR_INP_1 (1 << 18)
  101. #define RME96_WCR_THRU_0 (1 << 19)
  102. #define RME96_WCR_THRU_1 (1 << 20)
  103. #define RME96_WCR_THRU_2 (1 << 21)
  104. #define RME96_WCR_THRU_3 (1 << 22)
  105. #define RME96_WCR_THRU_4 (1 << 23)
  106. #define RME96_WCR_THRU_5 (1 << 24)
  107. #define RME96_WCR_THRU_6 (1 << 25)
  108. #define RME96_WCR_THRU_7 (1 << 26)
  109. #define RME96_WCR_DOLBY (1 << 27)
  110. #define RME96_WCR_MONITOR_0 (1 << 28)
  111. #define RME96_WCR_MONITOR_1 (1 << 29)
  112. #define RME96_WCR_ISEL (1 << 30)
  113. #define RME96_WCR_IDIS (1 << 31)
  114. #define RME96_WCR_BITPOS_GAIN_0 2
  115. #define RME96_WCR_BITPOS_GAIN_1 3
  116. #define RME96_WCR_BITPOS_FREQ_0 9
  117. #define RME96_WCR_BITPOS_FREQ_1 10
  118. #define RME96_WCR_BITPOS_INP_0 17
  119. #define RME96_WCR_BITPOS_INP_1 18
  120. #define RME96_WCR_BITPOS_MONITOR_0 28
  121. #define RME96_WCR_BITPOS_MONITOR_1 29
  122. /* Read control register bits */
  123. #define RME96_RCR_AUDIO_ADDR_MASK 0xFFFF
  124. #define RME96_RCR_IRQ_2 (1 << 16)
  125. #define RME96_RCR_T_OUT (1 << 17)
  126. #define RME96_RCR_DEV_ID_0 (1 << 21)
  127. #define RME96_RCR_DEV_ID_1 (1 << 22)
  128. #define RME96_RCR_LOCK (1 << 23)
  129. #define RME96_RCR_VERF (1 << 26)
  130. #define RME96_RCR_F0 (1 << 27)
  131. #define RME96_RCR_F1 (1 << 28)
  132. #define RME96_RCR_F2 (1 << 29)
  133. #define RME96_RCR_AUTOSYNC (1 << 30)
  134. #define RME96_RCR_IRQ (1 << 31)
  135. #define RME96_RCR_BITPOS_F0 27
  136. #define RME96_RCR_BITPOS_F1 28
  137. #define RME96_RCR_BITPOS_F2 29
  138. /* Additonal register bits */
  139. #define RME96_AR_WSEL (1 << 0)
  140. #define RME96_AR_ANALOG (1 << 1)
  141. #define RME96_AR_FREQPAD_0 (1 << 2)
  142. #define RME96_AR_FREQPAD_1 (1 << 3)
  143. #define RME96_AR_FREQPAD_2 (1 << 4)
  144. #define RME96_AR_PD2 (1 << 5)
  145. #define RME96_AR_DAC_EN (1 << 6)
  146. #define RME96_AR_CLATCH (1 << 7)
  147. #define RME96_AR_CCLK (1 << 8)
  148. #define RME96_AR_CDATA (1 << 9)
  149. #define RME96_AR_BITPOS_F0 2
  150. #define RME96_AR_BITPOS_F1 3
  151. #define RME96_AR_BITPOS_F2 4
  152. /* Monitor tracks */
  153. #define RME96_MONITOR_TRACKS_1_2 0
  154. #define RME96_MONITOR_TRACKS_3_4 1
  155. #define RME96_MONITOR_TRACKS_5_6 2
  156. #define RME96_MONITOR_TRACKS_7_8 3
  157. /* Attenuation */
  158. #define RME96_ATTENUATION_0 0
  159. #define RME96_ATTENUATION_6 1
  160. #define RME96_ATTENUATION_12 2
  161. #define RME96_ATTENUATION_18 3
  162. /* Input types */
  163. #define RME96_INPUT_OPTICAL 0
  164. #define RME96_INPUT_COAXIAL 1
  165. #define RME96_INPUT_INTERNAL 2
  166. #define RME96_INPUT_XLR 3
  167. #define RME96_INPUT_ANALOG 4
  168. /* Clock modes */
  169. #define RME96_CLOCKMODE_SLAVE 0
  170. #define RME96_CLOCKMODE_MASTER 1
  171. #define RME96_CLOCKMODE_WORDCLOCK 2
  172. /* Block sizes in bytes */
  173. #define RME96_SMALL_BLOCK_SIZE 2048
  174. #define RME96_LARGE_BLOCK_SIZE 8192
  175. /* Volume control */
  176. #define RME96_AD1852_VOL_BITS 14
  177. #define RME96_AD1855_VOL_BITS 10
  178. struct rme96 {
  179. spinlock_t lock;
  180. int irq;
  181. unsigned long port;
  182. void __iomem *iobase;
  183. u32 wcreg; /* cached write control register value */
  184. u32 wcreg_spdif; /* S/PDIF setup */
  185. u32 wcreg_spdif_stream; /* S/PDIF setup (temporary) */
  186. u32 rcreg; /* cached read control register value */
  187. u32 areg; /* cached additional register value */
  188. u16 vol[2]; /* cached volume of analog output */
  189. u8 rev; /* card revision number */
  190. struct snd_pcm_substream *playback_substream;
  191. struct snd_pcm_substream *capture_substream;
  192. int playback_frlog; /* log2 of framesize */
  193. int capture_frlog;
  194. size_t playback_periodsize; /* in bytes, zero if not used */
  195. size_t capture_periodsize; /* in bytes, zero if not used */
  196. struct snd_card *card;
  197. struct snd_pcm *spdif_pcm;
  198. struct snd_pcm *adat_pcm;
  199. struct pci_dev *pci;
  200. struct snd_kcontrol *spdif_ctl;
  201. };
  202. static struct pci_device_id snd_rme96_ids[] = {
  203. { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96,
  204. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
  205. { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8,
  206. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
  207. { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO,
  208. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
  209. { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST,
  210. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
  211. { 0, }
  212. };
  213. MODULE_DEVICE_TABLE(pci, snd_rme96_ids);
  214. #define RME96_ISPLAYING(rme96) ((rme96)->wcreg & RME96_WCR_START)
  215. #define RME96_ISRECORDING(rme96) ((rme96)->wcreg & RME96_WCR_START_2)
  216. #define RME96_HAS_ANALOG_IN(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST)
  217. #define RME96_HAS_ANALOG_OUT(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PRO || \
  218. (rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST)
  219. #define RME96_DAC_IS_1852(rme96) (RME96_HAS_ANALOG_OUT(rme96) && (rme96)->rev >= 4)
  220. #define RME96_DAC_IS_1855(rme96) (((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST && (rme96)->rev < 4) || \
  221. ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PRO && (rme96)->rev == 2))
  222. #define RME96_185X_MAX_OUT(rme96) ((1 << (RME96_DAC_IS_1852(rme96) ? RME96_AD1852_VOL_BITS : RME96_AD1855_VOL_BITS)) - 1)
  223. static int
  224. snd_rme96_playback_prepare(struct snd_pcm_substream *substream);
  225. static int
  226. snd_rme96_capture_prepare(struct snd_pcm_substream *substream);
  227. static int
  228. snd_rme96_playback_trigger(struct snd_pcm_substream *substream,
  229. int cmd);
  230. static int
  231. snd_rme96_capture_trigger(struct snd_pcm_substream *substream,
  232. int cmd);
  233. static snd_pcm_uframes_t
  234. snd_rme96_playback_pointer(struct snd_pcm_substream *substream);
  235. static snd_pcm_uframes_t
  236. snd_rme96_capture_pointer(struct snd_pcm_substream *substream);
  237. static void __devinit
  238. snd_rme96_proc_init(struct rme96 *rme96);
  239. static int
  240. snd_rme96_create_switches(struct snd_card *card,
  241. struct rme96 *rme96);
  242. static int
  243. snd_rme96_getinputtype(struct rme96 *rme96);
  244. static inline unsigned int
  245. snd_rme96_playback_ptr(struct rme96 *rme96)
  246. {
  247. return (readl(rme96->iobase + RME96_IO_GET_PLAY_POS)
  248. & RME96_RCR_AUDIO_ADDR_MASK) >> rme96->playback_frlog;
  249. }
  250. static inline unsigned int
  251. snd_rme96_capture_ptr(struct rme96 *rme96)
  252. {
  253. return (readl(rme96->iobase + RME96_IO_GET_REC_POS)
  254. & RME96_RCR_AUDIO_ADDR_MASK) >> rme96->capture_frlog;
  255. }
  256. static int
  257. snd_rme96_ratecode(int rate)
  258. {
  259. switch (rate) {
  260. case 32000: return SNDRV_PCM_RATE_32000;
  261. case 44100: return SNDRV_PCM_RATE_44100;
  262. case 48000: return SNDRV_PCM_RATE_48000;
  263. case 64000: return SNDRV_PCM_RATE_64000;
  264. case 88200: return SNDRV_PCM_RATE_88200;
  265. case 96000: return SNDRV_PCM_RATE_96000;
  266. }
  267. return 0;
  268. }
  269. static int
  270. snd_rme96_playback_silence(struct snd_pcm_substream *substream,
  271. int channel, /* not used (interleaved data) */
  272. snd_pcm_uframes_t pos,
  273. snd_pcm_uframes_t count)
  274. {
  275. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  276. count <<= rme96->playback_frlog;
  277. pos <<= rme96->playback_frlog;
  278. memset_io(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
  279. 0, count);
  280. return 0;
  281. }
  282. static int
  283. snd_rme96_playback_copy(struct snd_pcm_substream *substream,
  284. int channel, /* not used (interleaved data) */
  285. snd_pcm_uframes_t pos,
  286. void __user *src,
  287. snd_pcm_uframes_t count)
  288. {
  289. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  290. count <<= rme96->playback_frlog;
  291. pos <<= rme96->playback_frlog;
  292. copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src,
  293. count);
  294. return 0;
  295. }
  296. static int
  297. snd_rme96_capture_copy(struct snd_pcm_substream *substream,
  298. int channel, /* not used (interleaved data) */
  299. snd_pcm_uframes_t pos,
  300. void __user *dst,
  301. snd_pcm_uframes_t count)
  302. {
  303. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  304. count <<= rme96->capture_frlog;
  305. pos <<= rme96->capture_frlog;
  306. copy_to_user_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos,
  307. count);
  308. return 0;
  309. }
  310. /*
  311. * Digital output capabilities (S/PDIF)
  312. */
  313. static struct snd_pcm_hardware snd_rme96_playback_spdif_info =
  314. {
  315. .info = (SNDRV_PCM_INFO_MMAP_IOMEM |
  316. SNDRV_PCM_INFO_MMAP_VALID |
  317. SNDRV_PCM_INFO_INTERLEAVED |
  318. SNDRV_PCM_INFO_PAUSE),
  319. .formats = (SNDRV_PCM_FMTBIT_S16_LE |
  320. SNDRV_PCM_FMTBIT_S32_LE),
  321. .rates = (SNDRV_PCM_RATE_32000 |
  322. SNDRV_PCM_RATE_44100 |
  323. SNDRV_PCM_RATE_48000 |
  324. SNDRV_PCM_RATE_64000 |
  325. SNDRV_PCM_RATE_88200 |
  326. SNDRV_PCM_RATE_96000),
  327. .rate_min = 32000,
  328. .rate_max = 96000,
  329. .channels_min = 2,
  330. .channels_max = 2,
  331. .buffer_bytes_max = RME96_BUFFER_SIZE,
  332. .period_bytes_min = RME96_SMALL_BLOCK_SIZE,
  333. .period_bytes_max = RME96_LARGE_BLOCK_SIZE,
  334. .periods_min = RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
  335. .periods_max = RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
  336. .fifo_size = 0,
  337. };
  338. /*
  339. * Digital input capabilities (S/PDIF)
  340. */
  341. static struct snd_pcm_hardware snd_rme96_capture_spdif_info =
  342. {
  343. .info = (SNDRV_PCM_INFO_MMAP_IOMEM |
  344. SNDRV_PCM_INFO_MMAP_VALID |
  345. SNDRV_PCM_INFO_INTERLEAVED |
  346. SNDRV_PCM_INFO_PAUSE),
  347. .formats = (SNDRV_PCM_FMTBIT_S16_LE |
  348. SNDRV_PCM_FMTBIT_S32_LE),
  349. .rates = (SNDRV_PCM_RATE_32000 |
  350. SNDRV_PCM_RATE_44100 |
  351. SNDRV_PCM_RATE_48000 |
  352. SNDRV_PCM_RATE_64000 |
  353. SNDRV_PCM_RATE_88200 |
  354. SNDRV_PCM_RATE_96000),
  355. .rate_min = 32000,
  356. .rate_max = 96000,
  357. .channels_min = 2,
  358. .channels_max = 2,
  359. .buffer_bytes_max = RME96_BUFFER_SIZE,
  360. .period_bytes_min = RME96_SMALL_BLOCK_SIZE,
  361. .period_bytes_max = RME96_LARGE_BLOCK_SIZE,
  362. .periods_min = RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
  363. .periods_max = RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
  364. .fifo_size = 0,
  365. };
  366. /*
  367. * Digital output capabilities (ADAT)
  368. */
  369. static struct snd_pcm_hardware snd_rme96_playback_adat_info =
  370. {
  371. .info = (SNDRV_PCM_INFO_MMAP_IOMEM |
  372. SNDRV_PCM_INFO_MMAP_VALID |
  373. SNDRV_PCM_INFO_INTERLEAVED |
  374. SNDRV_PCM_INFO_PAUSE),
  375. .formats = (SNDRV_PCM_FMTBIT_S16_LE |
  376. SNDRV_PCM_FMTBIT_S32_LE),
  377. .rates = (SNDRV_PCM_RATE_44100 |
  378. SNDRV_PCM_RATE_48000),
  379. .rate_min = 44100,
  380. .rate_max = 48000,
  381. .channels_min = 8,
  382. .channels_max = 8,
  383. .buffer_bytes_max = RME96_BUFFER_SIZE,
  384. .period_bytes_min = RME96_SMALL_BLOCK_SIZE,
  385. .period_bytes_max = RME96_LARGE_BLOCK_SIZE,
  386. .periods_min = RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
  387. .periods_max = RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
  388. .fifo_size = 0,
  389. };
  390. /*
  391. * Digital input capabilities (ADAT)
  392. */
  393. static struct snd_pcm_hardware snd_rme96_capture_adat_info =
  394. {
  395. .info = (SNDRV_PCM_INFO_MMAP_IOMEM |
  396. SNDRV_PCM_INFO_MMAP_VALID |
  397. SNDRV_PCM_INFO_INTERLEAVED |
  398. SNDRV_PCM_INFO_PAUSE),
  399. .formats = (SNDRV_PCM_FMTBIT_S16_LE |
  400. SNDRV_PCM_FMTBIT_S32_LE),
  401. .rates = (SNDRV_PCM_RATE_44100 |
  402. SNDRV_PCM_RATE_48000),
  403. .rate_min = 44100,
  404. .rate_max = 48000,
  405. .channels_min = 8,
  406. .channels_max = 8,
  407. .buffer_bytes_max = RME96_BUFFER_SIZE,
  408. .period_bytes_min = RME96_SMALL_BLOCK_SIZE,
  409. .period_bytes_max = RME96_LARGE_BLOCK_SIZE,
  410. .periods_min = RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
  411. .periods_max = RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
  412. .fifo_size = 0,
  413. };
  414. /*
  415. * The CDATA, CCLK and CLATCH bits can be used to write to the SPI interface
  416. * of the AD1852 or AD1852 D/A converter on the board. CDATA must be set up
  417. * on the falling edge of CCLK and be stable on the rising edge. The rising
  418. * edge of CLATCH after the last data bit clocks in the whole data word.
  419. * A fast processor could probably drive the SPI interface faster than the
  420. * DAC can handle (3MHz for the 1855, unknown for the 1852). The udelay(1)
  421. * limits the data rate to 500KHz and only causes a delay of 33 microsecs.
  422. *
  423. * NOTE: increased delay from 1 to 10, since there where problems setting
  424. * the volume.
  425. */
  426. static void
  427. snd_rme96_write_SPI(struct rme96 *rme96, u16 val)
  428. {
  429. int i;
  430. for (i = 0; i < 16; i++) {
  431. if (val & 0x8000) {
  432. rme96->areg |= RME96_AR_CDATA;
  433. } else {
  434. rme96->areg &= ~RME96_AR_CDATA;
  435. }
  436. rme96->areg &= ~(RME96_AR_CCLK | RME96_AR_CLATCH);
  437. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  438. udelay(10);
  439. rme96->areg |= RME96_AR_CCLK;
  440. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  441. udelay(10);
  442. val <<= 1;
  443. }
  444. rme96->areg &= ~(RME96_AR_CCLK | RME96_AR_CDATA);
  445. rme96->areg |= RME96_AR_CLATCH;
  446. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  447. udelay(10);
  448. rme96->areg &= ~RME96_AR_CLATCH;
  449. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  450. }
  451. static void
  452. snd_rme96_apply_dac_volume(struct rme96 *rme96)
  453. {
  454. if (RME96_DAC_IS_1852(rme96)) {
  455. snd_rme96_write_SPI(rme96, (rme96->vol[0] << 2) | 0x0);
  456. snd_rme96_write_SPI(rme96, (rme96->vol[1] << 2) | 0x2);
  457. } else if (RME96_DAC_IS_1855(rme96)) {
  458. snd_rme96_write_SPI(rme96, (rme96->vol[0] & 0x3FF) | 0x000);
  459. snd_rme96_write_SPI(rme96, (rme96->vol[1] & 0x3FF) | 0x400);
  460. }
  461. }
  462. static void
  463. snd_rme96_reset_dac(struct rme96 *rme96)
  464. {
  465. writel(rme96->wcreg | RME96_WCR_PD,
  466. rme96->iobase + RME96_IO_CONTROL_REGISTER);
  467. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  468. }
  469. static int
  470. snd_rme96_getmontracks(struct rme96 *rme96)
  471. {
  472. return ((rme96->wcreg >> RME96_WCR_BITPOS_MONITOR_0) & 1) +
  473. (((rme96->wcreg >> RME96_WCR_BITPOS_MONITOR_1) & 1) << 1);
  474. }
  475. static int
  476. snd_rme96_setmontracks(struct rme96 *rme96,
  477. int montracks)
  478. {
  479. if (montracks & 1) {
  480. rme96->wcreg |= RME96_WCR_MONITOR_0;
  481. } else {
  482. rme96->wcreg &= ~RME96_WCR_MONITOR_0;
  483. }
  484. if (montracks & 2) {
  485. rme96->wcreg |= RME96_WCR_MONITOR_1;
  486. } else {
  487. rme96->wcreg &= ~RME96_WCR_MONITOR_1;
  488. }
  489. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  490. return 0;
  491. }
  492. static int
  493. snd_rme96_getattenuation(struct rme96 *rme96)
  494. {
  495. return ((rme96->wcreg >> RME96_WCR_BITPOS_GAIN_0) & 1) +
  496. (((rme96->wcreg >> RME96_WCR_BITPOS_GAIN_1) & 1) << 1);
  497. }
  498. static int
  499. snd_rme96_setattenuation(struct rme96 *rme96,
  500. int attenuation)
  501. {
  502. switch (attenuation) {
  503. case 0:
  504. rme96->wcreg = (rme96->wcreg & ~RME96_WCR_GAIN_0) &
  505. ~RME96_WCR_GAIN_1;
  506. break;
  507. case 1:
  508. rme96->wcreg = (rme96->wcreg | RME96_WCR_GAIN_0) &
  509. ~RME96_WCR_GAIN_1;
  510. break;
  511. case 2:
  512. rme96->wcreg = (rme96->wcreg & ~RME96_WCR_GAIN_0) |
  513. RME96_WCR_GAIN_1;
  514. break;
  515. case 3:
  516. rme96->wcreg = (rme96->wcreg | RME96_WCR_GAIN_0) |
  517. RME96_WCR_GAIN_1;
  518. break;
  519. default:
  520. return -EINVAL;
  521. }
  522. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  523. return 0;
  524. }
  525. static int
  526. snd_rme96_capture_getrate(struct rme96 *rme96,
  527. int *is_adat)
  528. {
  529. int n, rate;
  530. *is_adat = 0;
  531. if (rme96->areg & RME96_AR_ANALOG) {
  532. /* Analog input, overrides S/PDIF setting */
  533. n = ((rme96->areg >> RME96_AR_BITPOS_F0) & 1) +
  534. (((rme96->areg >> RME96_AR_BITPOS_F1) & 1) << 1);
  535. switch (n) {
  536. case 1:
  537. rate = 32000;
  538. break;
  539. case 2:
  540. rate = 44100;
  541. break;
  542. case 3:
  543. rate = 48000;
  544. break;
  545. default:
  546. return -1;
  547. }
  548. return (rme96->areg & RME96_AR_BITPOS_F2) ? rate << 1 : rate;
  549. }
  550. rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
  551. if (rme96->rcreg & RME96_RCR_LOCK) {
  552. /* ADAT rate */
  553. *is_adat = 1;
  554. if (rme96->rcreg & RME96_RCR_T_OUT) {
  555. return 48000;
  556. }
  557. return 44100;
  558. }
  559. if (rme96->rcreg & RME96_RCR_VERF) {
  560. return -1;
  561. }
  562. /* S/PDIF rate */
  563. n = ((rme96->rcreg >> RME96_RCR_BITPOS_F0) & 1) +
  564. (((rme96->rcreg >> RME96_RCR_BITPOS_F1) & 1) << 1) +
  565. (((rme96->rcreg >> RME96_RCR_BITPOS_F2) & 1) << 2);
  566. switch (n) {
  567. case 0:
  568. if (rme96->rcreg & RME96_RCR_T_OUT) {
  569. return 64000;
  570. }
  571. return -1;
  572. case 3: return 96000;
  573. case 4: return 88200;
  574. case 5: return 48000;
  575. case 6: return 44100;
  576. case 7: return 32000;
  577. default:
  578. break;
  579. }
  580. return -1;
  581. }
  582. static int
  583. snd_rme96_playback_getrate(struct rme96 *rme96)
  584. {
  585. int rate, dummy;
  586. if (!(rme96->wcreg & RME96_WCR_MASTER) &&
  587. snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
  588. (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
  589. {
  590. /* slave clock */
  591. return rate;
  592. }
  593. rate = ((rme96->wcreg >> RME96_WCR_BITPOS_FREQ_0) & 1) +
  594. (((rme96->wcreg >> RME96_WCR_BITPOS_FREQ_1) & 1) << 1);
  595. switch (rate) {
  596. case 1:
  597. rate = 32000;
  598. break;
  599. case 2:
  600. rate = 44100;
  601. break;
  602. case 3:
  603. rate = 48000;
  604. break;
  605. default:
  606. return -1;
  607. }
  608. return (rme96->wcreg & RME96_WCR_DS) ? rate << 1 : rate;
  609. }
  610. static int
  611. snd_rme96_playback_setrate(struct rme96 *rme96,
  612. int rate)
  613. {
  614. int ds;
  615. ds = rme96->wcreg & RME96_WCR_DS;
  616. switch (rate) {
  617. case 32000:
  618. rme96->wcreg &= ~RME96_WCR_DS;
  619. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) &
  620. ~RME96_WCR_FREQ_1;
  621. break;
  622. case 44100:
  623. rme96->wcreg &= ~RME96_WCR_DS;
  624. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_1) &
  625. ~RME96_WCR_FREQ_0;
  626. break;
  627. case 48000:
  628. rme96->wcreg &= ~RME96_WCR_DS;
  629. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) |
  630. RME96_WCR_FREQ_1;
  631. break;
  632. case 64000:
  633. rme96->wcreg |= RME96_WCR_DS;
  634. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) &
  635. ~RME96_WCR_FREQ_1;
  636. break;
  637. case 88200:
  638. rme96->wcreg |= RME96_WCR_DS;
  639. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_1) &
  640. ~RME96_WCR_FREQ_0;
  641. break;
  642. case 96000:
  643. rme96->wcreg |= RME96_WCR_DS;
  644. rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) |
  645. RME96_WCR_FREQ_1;
  646. break;
  647. default:
  648. return -EINVAL;
  649. }
  650. if ((!ds && rme96->wcreg & RME96_WCR_DS) ||
  651. (ds && !(rme96->wcreg & RME96_WCR_DS)))
  652. {
  653. /* change to/from double-speed: reset the DAC (if available) */
  654. snd_rme96_reset_dac(rme96);
  655. } else {
  656. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  657. }
  658. return 0;
  659. }
  660. static int
  661. snd_rme96_capture_analog_setrate(struct rme96 *rme96,
  662. int rate)
  663. {
  664. switch (rate) {
  665. case 32000:
  666. rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) &
  667. ~RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
  668. break;
  669. case 44100:
  670. rme96->areg = ((rme96->areg & ~RME96_AR_FREQPAD_0) |
  671. RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
  672. break;
  673. case 48000:
  674. rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) |
  675. RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
  676. break;
  677. case 64000:
  678. if (rme96->rev < 4) {
  679. return -EINVAL;
  680. }
  681. rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) &
  682. ~RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
  683. break;
  684. case 88200:
  685. if (rme96->rev < 4) {
  686. return -EINVAL;
  687. }
  688. rme96->areg = ((rme96->areg & ~RME96_AR_FREQPAD_0) |
  689. RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
  690. break;
  691. case 96000:
  692. rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) |
  693. RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
  694. break;
  695. default:
  696. return -EINVAL;
  697. }
  698. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  699. return 0;
  700. }
  701. static int
  702. snd_rme96_setclockmode(struct rme96 *rme96,
  703. int mode)
  704. {
  705. switch (mode) {
  706. case RME96_CLOCKMODE_SLAVE:
  707. /* AutoSync */
  708. rme96->wcreg &= ~RME96_WCR_MASTER;
  709. rme96->areg &= ~RME96_AR_WSEL;
  710. break;
  711. case RME96_CLOCKMODE_MASTER:
  712. /* Internal */
  713. rme96->wcreg |= RME96_WCR_MASTER;
  714. rme96->areg &= ~RME96_AR_WSEL;
  715. break;
  716. case RME96_CLOCKMODE_WORDCLOCK:
  717. /* Word clock is a master mode */
  718. rme96->wcreg |= RME96_WCR_MASTER;
  719. rme96->areg |= RME96_AR_WSEL;
  720. break;
  721. default:
  722. return -EINVAL;
  723. }
  724. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  725. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  726. return 0;
  727. }
  728. static int
  729. snd_rme96_getclockmode(struct rme96 *rme96)
  730. {
  731. if (rme96->areg & RME96_AR_WSEL) {
  732. return RME96_CLOCKMODE_WORDCLOCK;
  733. }
  734. return (rme96->wcreg & RME96_WCR_MASTER) ? RME96_CLOCKMODE_MASTER :
  735. RME96_CLOCKMODE_SLAVE;
  736. }
  737. static int
  738. snd_rme96_setinputtype(struct rme96 *rme96,
  739. int type)
  740. {
  741. int n;
  742. switch (type) {
  743. case RME96_INPUT_OPTICAL:
  744. rme96->wcreg = (rme96->wcreg & ~RME96_WCR_INP_0) &
  745. ~RME96_WCR_INP_1;
  746. break;
  747. case RME96_INPUT_COAXIAL:
  748. rme96->wcreg = (rme96->wcreg | RME96_WCR_INP_0) &
  749. ~RME96_WCR_INP_1;
  750. break;
  751. case RME96_INPUT_INTERNAL:
  752. rme96->wcreg = (rme96->wcreg & ~RME96_WCR_INP_0) |
  753. RME96_WCR_INP_1;
  754. break;
  755. case RME96_INPUT_XLR:
  756. if ((rme96->pci->device != PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST &&
  757. rme96->pci->device != PCI_DEVICE_ID_RME_DIGI96_8_PRO) ||
  758. (rme96->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST &&
  759. rme96->rev > 4))
  760. {
  761. /* Only Digi96/8 PRO and Digi96/8 PAD supports XLR */
  762. return -EINVAL;
  763. }
  764. rme96->wcreg = (rme96->wcreg | RME96_WCR_INP_0) |
  765. RME96_WCR_INP_1;
  766. break;
  767. case RME96_INPUT_ANALOG:
  768. if (!RME96_HAS_ANALOG_IN(rme96)) {
  769. return -EINVAL;
  770. }
  771. rme96->areg |= RME96_AR_ANALOG;
  772. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  773. if (rme96->rev < 4) {
  774. /*
  775. * Revision less than 004 does not support 64 and
  776. * 88.2 kHz
  777. */
  778. if (snd_rme96_capture_getrate(rme96, &n) == 88200) {
  779. snd_rme96_capture_analog_setrate(rme96, 44100);
  780. }
  781. if (snd_rme96_capture_getrate(rme96, &n) == 64000) {
  782. snd_rme96_capture_analog_setrate(rme96, 32000);
  783. }
  784. }
  785. return 0;
  786. default:
  787. return -EINVAL;
  788. }
  789. if (type != RME96_INPUT_ANALOG && RME96_HAS_ANALOG_IN(rme96)) {
  790. rme96->areg &= ~RME96_AR_ANALOG;
  791. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  792. }
  793. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  794. return 0;
  795. }
  796. static int
  797. snd_rme96_getinputtype(struct rme96 *rme96)
  798. {
  799. if (rme96->areg & RME96_AR_ANALOG) {
  800. return RME96_INPUT_ANALOG;
  801. }
  802. return ((rme96->wcreg >> RME96_WCR_BITPOS_INP_0) & 1) +
  803. (((rme96->wcreg >> RME96_WCR_BITPOS_INP_1) & 1) << 1);
  804. }
  805. static void
  806. snd_rme96_setframelog(struct rme96 *rme96,
  807. int n_channels,
  808. int is_playback)
  809. {
  810. int frlog;
  811. if (n_channels == 2) {
  812. frlog = 1;
  813. } else {
  814. /* assume 8 channels */
  815. frlog = 3;
  816. }
  817. if (is_playback) {
  818. frlog += (rme96->wcreg & RME96_WCR_MODE24) ? 2 : 1;
  819. rme96->playback_frlog = frlog;
  820. } else {
  821. frlog += (rme96->wcreg & RME96_WCR_MODE24_2) ? 2 : 1;
  822. rme96->capture_frlog = frlog;
  823. }
  824. }
  825. static int
  826. snd_rme96_playback_setformat(struct rme96 *rme96,
  827. int format)
  828. {
  829. switch (format) {
  830. case SNDRV_PCM_FORMAT_S16_LE:
  831. rme96->wcreg &= ~RME96_WCR_MODE24;
  832. break;
  833. case SNDRV_PCM_FORMAT_S32_LE:
  834. rme96->wcreg |= RME96_WCR_MODE24;
  835. break;
  836. default:
  837. return -EINVAL;
  838. }
  839. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  840. return 0;
  841. }
  842. static int
  843. snd_rme96_capture_setformat(struct rme96 *rme96,
  844. int format)
  845. {
  846. switch (format) {
  847. case SNDRV_PCM_FORMAT_S16_LE:
  848. rme96->wcreg &= ~RME96_WCR_MODE24_2;
  849. break;
  850. case SNDRV_PCM_FORMAT_S32_LE:
  851. rme96->wcreg |= RME96_WCR_MODE24_2;
  852. break;
  853. default:
  854. return -EINVAL;
  855. }
  856. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  857. return 0;
  858. }
  859. static void
  860. snd_rme96_set_period_properties(struct rme96 *rme96,
  861. size_t period_bytes)
  862. {
  863. switch (period_bytes) {
  864. case RME96_LARGE_BLOCK_SIZE:
  865. rme96->wcreg &= ~RME96_WCR_ISEL;
  866. break;
  867. case RME96_SMALL_BLOCK_SIZE:
  868. rme96->wcreg |= RME96_WCR_ISEL;
  869. break;
  870. default:
  871. snd_BUG();
  872. break;
  873. }
  874. rme96->wcreg &= ~RME96_WCR_IDIS;
  875. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  876. }
  877. static int
  878. snd_rme96_playback_hw_params(struct snd_pcm_substream *substream,
  879. struct snd_pcm_hw_params *params)
  880. {
  881. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  882. struct snd_pcm_runtime *runtime = substream->runtime;
  883. int err, rate, dummy;
  884. runtime->dma_area = (void __force *)(rme96->iobase +
  885. RME96_IO_PLAY_BUFFER);
  886. runtime->dma_addr = rme96->port + RME96_IO_PLAY_BUFFER;
  887. runtime->dma_bytes = RME96_BUFFER_SIZE;
  888. spin_lock_irq(&rme96->lock);
  889. if (!(rme96->wcreg & RME96_WCR_MASTER) &&
  890. snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
  891. (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
  892. {
  893. /* slave clock */
  894. if ((int)params_rate(params) != rate) {
  895. spin_unlock_irq(&rme96->lock);
  896. return -EIO;
  897. }
  898. } else if ((err = snd_rme96_playback_setrate(rme96, params_rate(params))) < 0) {
  899. spin_unlock_irq(&rme96->lock);
  900. return err;
  901. }
  902. if ((err = snd_rme96_playback_setformat(rme96, params_format(params))) < 0) {
  903. spin_unlock_irq(&rme96->lock);
  904. return err;
  905. }
  906. snd_rme96_setframelog(rme96, params_channels(params), 1);
  907. if (rme96->capture_periodsize != 0) {
  908. if (params_period_size(params) << rme96->playback_frlog !=
  909. rme96->capture_periodsize)
  910. {
  911. spin_unlock_irq(&rme96->lock);
  912. return -EBUSY;
  913. }
  914. }
  915. rme96->playback_periodsize =
  916. params_period_size(params) << rme96->playback_frlog;
  917. snd_rme96_set_period_properties(rme96, rme96->playback_periodsize);
  918. /* S/PDIF setup */
  919. if ((rme96->wcreg & RME96_WCR_ADAT) == 0) {
  920. rme96->wcreg &= ~(RME96_WCR_PRO | RME96_WCR_DOLBY | RME96_WCR_EMP);
  921. writel(rme96->wcreg |= rme96->wcreg_spdif_stream, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  922. }
  923. spin_unlock_irq(&rme96->lock);
  924. return 0;
  925. }
  926. static int
  927. snd_rme96_capture_hw_params(struct snd_pcm_substream *substream,
  928. struct snd_pcm_hw_params *params)
  929. {
  930. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  931. struct snd_pcm_runtime *runtime = substream->runtime;
  932. int err, isadat, rate;
  933. runtime->dma_area = (void __force *)(rme96->iobase +
  934. RME96_IO_REC_BUFFER);
  935. runtime->dma_addr = rme96->port + RME96_IO_REC_BUFFER;
  936. runtime->dma_bytes = RME96_BUFFER_SIZE;
  937. spin_lock_irq(&rme96->lock);
  938. if ((err = snd_rme96_capture_setformat(rme96, params_format(params))) < 0) {
  939. spin_unlock_irq(&rme96->lock);
  940. return err;
  941. }
  942. if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
  943. if ((err = snd_rme96_capture_analog_setrate(rme96,
  944. params_rate(params))) < 0)
  945. {
  946. spin_unlock_irq(&rme96->lock);
  947. return err;
  948. }
  949. } else if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
  950. if ((int)params_rate(params) != rate) {
  951. spin_unlock_irq(&rme96->lock);
  952. return -EIO;
  953. }
  954. if ((isadat && runtime->hw.channels_min == 2) ||
  955. (!isadat && runtime->hw.channels_min == 8))
  956. {
  957. spin_unlock_irq(&rme96->lock);
  958. return -EIO;
  959. }
  960. }
  961. snd_rme96_setframelog(rme96, params_channels(params), 0);
  962. if (rme96->playback_periodsize != 0) {
  963. if (params_period_size(params) << rme96->capture_frlog !=
  964. rme96->playback_periodsize)
  965. {
  966. spin_unlock_irq(&rme96->lock);
  967. return -EBUSY;
  968. }
  969. }
  970. rme96->capture_periodsize =
  971. params_period_size(params) << rme96->capture_frlog;
  972. snd_rme96_set_period_properties(rme96, rme96->capture_periodsize);
  973. spin_unlock_irq(&rme96->lock);
  974. return 0;
  975. }
  976. static void
  977. snd_rme96_playback_start(struct rme96 *rme96,
  978. int from_pause)
  979. {
  980. if (!from_pause) {
  981. writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
  982. }
  983. rme96->wcreg |= RME96_WCR_START;
  984. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  985. }
  986. static void
  987. snd_rme96_capture_start(struct rme96 *rme96,
  988. int from_pause)
  989. {
  990. if (!from_pause) {
  991. writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
  992. }
  993. rme96->wcreg |= RME96_WCR_START_2;
  994. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  995. }
  996. static void
  997. snd_rme96_playback_stop(struct rme96 *rme96)
  998. {
  999. /*
  1000. * Check if there is an unconfirmed IRQ, if so confirm it, or else
  1001. * the hardware will not stop generating interrupts
  1002. */
  1003. rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1004. if (rme96->rcreg & RME96_RCR_IRQ) {
  1005. writel(0, rme96->iobase + RME96_IO_CONFIRM_PLAY_IRQ);
  1006. }
  1007. rme96->wcreg &= ~RME96_WCR_START;
  1008. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1009. }
  1010. static void
  1011. snd_rme96_capture_stop(struct rme96 *rme96)
  1012. {
  1013. rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1014. if (rme96->rcreg & RME96_RCR_IRQ_2) {
  1015. writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
  1016. }
  1017. rme96->wcreg &= ~RME96_WCR_START_2;
  1018. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1019. }
  1020. static irqreturn_t
  1021. snd_rme96_interrupt(int irq,
  1022. void *dev_id)
  1023. {
  1024. struct rme96 *rme96 = (struct rme96 *)dev_id;
  1025. rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1026. /* fastpath out, to ease interrupt sharing */
  1027. if (!((rme96->rcreg & RME96_RCR_IRQ) ||
  1028. (rme96->rcreg & RME96_RCR_IRQ_2)))
  1029. {
  1030. return IRQ_NONE;
  1031. }
  1032. if (rme96->rcreg & RME96_RCR_IRQ) {
  1033. /* playback */
  1034. snd_pcm_period_elapsed(rme96->playback_substream);
  1035. writel(0, rme96->iobase + RME96_IO_CONFIRM_PLAY_IRQ);
  1036. }
  1037. if (rme96->rcreg & RME96_RCR_IRQ_2) {
  1038. /* capture */
  1039. snd_pcm_period_elapsed(rme96->capture_substream);
  1040. writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
  1041. }
  1042. return IRQ_HANDLED;
  1043. }
  1044. static unsigned int period_bytes[] = { RME96_SMALL_BLOCK_SIZE, RME96_LARGE_BLOCK_SIZE };
  1045. static struct snd_pcm_hw_constraint_list hw_constraints_period_bytes = {
  1046. .count = ARRAY_SIZE(period_bytes),
  1047. .list = period_bytes,
  1048. .mask = 0
  1049. };
  1050. static void
  1051. rme96_set_buffer_size_constraint(struct rme96 *rme96,
  1052. struct snd_pcm_runtime *runtime)
  1053. {
  1054. unsigned int size;
  1055. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1056. RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
  1057. if ((size = rme96->playback_periodsize) != 0 ||
  1058. (size = rme96->capture_periodsize) != 0)
  1059. snd_pcm_hw_constraint_minmax(runtime,
  1060. SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1061. size, size);
  1062. else
  1063. snd_pcm_hw_constraint_list(runtime, 0,
  1064. SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1065. &hw_constraints_period_bytes);
  1066. }
  1067. static int
  1068. snd_rme96_playback_spdif_open(struct snd_pcm_substream *substream)
  1069. {
  1070. int rate, dummy;
  1071. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1072. struct snd_pcm_runtime *runtime = substream->runtime;
  1073. snd_pcm_set_sync(substream);
  1074. spin_lock_irq(&rme96->lock);
  1075. if (rme96->playback_substream != NULL) {
  1076. spin_unlock_irq(&rme96->lock);
  1077. return -EBUSY;
  1078. }
  1079. rme96->wcreg &= ~RME96_WCR_ADAT;
  1080. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1081. rme96->playback_substream = substream;
  1082. spin_unlock_irq(&rme96->lock);
  1083. runtime->hw = snd_rme96_playback_spdif_info;
  1084. if (!(rme96->wcreg & RME96_WCR_MASTER) &&
  1085. snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
  1086. (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
  1087. {
  1088. /* slave clock */
  1089. runtime->hw.rates = snd_rme96_ratecode(rate);
  1090. runtime->hw.rate_min = rate;
  1091. runtime->hw.rate_max = rate;
  1092. }
  1093. rme96_set_buffer_size_constraint(rme96, runtime);
  1094. rme96->wcreg_spdif_stream = rme96->wcreg_spdif;
  1095. rme96->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1096. snd_ctl_notify(rme96->card, SNDRV_CTL_EVENT_MASK_VALUE |
  1097. SNDRV_CTL_EVENT_MASK_INFO, &rme96->spdif_ctl->id);
  1098. return 0;
  1099. }
  1100. static int
  1101. snd_rme96_capture_spdif_open(struct snd_pcm_substream *substream)
  1102. {
  1103. int isadat, rate;
  1104. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1105. struct snd_pcm_runtime *runtime = substream->runtime;
  1106. snd_pcm_set_sync(substream);
  1107. runtime->hw = snd_rme96_capture_spdif_info;
  1108. if (snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
  1109. (rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0)
  1110. {
  1111. if (isadat) {
  1112. return -EIO;
  1113. }
  1114. runtime->hw.rates = snd_rme96_ratecode(rate);
  1115. runtime->hw.rate_min = rate;
  1116. runtime->hw.rate_max = rate;
  1117. }
  1118. spin_lock_irq(&rme96->lock);
  1119. if (rme96->capture_substream != NULL) {
  1120. spin_unlock_irq(&rme96->lock);
  1121. return -EBUSY;
  1122. }
  1123. rme96->capture_substream = substream;
  1124. spin_unlock_irq(&rme96->lock);
  1125. rme96_set_buffer_size_constraint(rme96, runtime);
  1126. return 0;
  1127. }
  1128. static int
  1129. snd_rme96_playback_adat_open(struct snd_pcm_substream *substream)
  1130. {
  1131. int rate, dummy;
  1132. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1133. struct snd_pcm_runtime *runtime = substream->runtime;
  1134. snd_pcm_set_sync(substream);
  1135. spin_lock_irq(&rme96->lock);
  1136. if (rme96->playback_substream != NULL) {
  1137. spin_unlock_irq(&rme96->lock);
  1138. return -EBUSY;
  1139. }
  1140. rme96->wcreg |= RME96_WCR_ADAT;
  1141. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1142. rme96->playback_substream = substream;
  1143. spin_unlock_irq(&rme96->lock);
  1144. runtime->hw = snd_rme96_playback_adat_info;
  1145. if (!(rme96->wcreg & RME96_WCR_MASTER) &&
  1146. snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
  1147. (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
  1148. {
  1149. /* slave clock */
  1150. runtime->hw.rates = snd_rme96_ratecode(rate);
  1151. runtime->hw.rate_min = rate;
  1152. runtime->hw.rate_max = rate;
  1153. }
  1154. rme96_set_buffer_size_constraint(rme96, runtime);
  1155. return 0;
  1156. }
  1157. static int
  1158. snd_rme96_capture_adat_open(struct snd_pcm_substream *substream)
  1159. {
  1160. int isadat, rate;
  1161. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1162. struct snd_pcm_runtime *runtime = substream->runtime;
  1163. snd_pcm_set_sync(substream);
  1164. runtime->hw = snd_rme96_capture_adat_info;
  1165. if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
  1166. /* makes no sense to use analog input. Note that analog
  1167. expension cards AEB4/8-I are RME96_INPUT_INTERNAL */
  1168. return -EIO;
  1169. }
  1170. if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
  1171. if (!isadat) {
  1172. return -EIO;
  1173. }
  1174. runtime->hw.rates = snd_rme96_ratecode(rate);
  1175. runtime->hw.rate_min = rate;
  1176. runtime->hw.rate_max = rate;
  1177. }
  1178. spin_lock_irq(&rme96->lock);
  1179. if (rme96->capture_substream != NULL) {
  1180. spin_unlock_irq(&rme96->lock);
  1181. return -EBUSY;
  1182. }
  1183. rme96->capture_substream = substream;
  1184. spin_unlock_irq(&rme96->lock);
  1185. rme96_set_buffer_size_constraint(rme96, runtime);
  1186. return 0;
  1187. }
  1188. static int
  1189. snd_rme96_playback_close(struct snd_pcm_substream *substream)
  1190. {
  1191. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1192. int spdif = 0;
  1193. spin_lock_irq(&rme96->lock);
  1194. if (RME96_ISPLAYING(rme96)) {
  1195. snd_rme96_playback_stop(rme96);
  1196. }
  1197. rme96->playback_substream = NULL;
  1198. rme96->playback_periodsize = 0;
  1199. spdif = (rme96->wcreg & RME96_WCR_ADAT) == 0;
  1200. spin_unlock_irq(&rme96->lock);
  1201. if (spdif) {
  1202. rme96->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1203. snd_ctl_notify(rme96->card, SNDRV_CTL_EVENT_MASK_VALUE |
  1204. SNDRV_CTL_EVENT_MASK_INFO, &rme96->spdif_ctl->id);
  1205. }
  1206. return 0;
  1207. }
  1208. static int
  1209. snd_rme96_capture_close(struct snd_pcm_substream *substream)
  1210. {
  1211. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1212. spin_lock_irq(&rme96->lock);
  1213. if (RME96_ISRECORDING(rme96)) {
  1214. snd_rme96_capture_stop(rme96);
  1215. }
  1216. rme96->capture_substream = NULL;
  1217. rme96->capture_periodsize = 0;
  1218. spin_unlock_irq(&rme96->lock);
  1219. return 0;
  1220. }
  1221. static int
  1222. snd_rme96_playback_prepare(struct snd_pcm_substream *substream)
  1223. {
  1224. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1225. spin_lock_irq(&rme96->lock);
  1226. if (RME96_ISPLAYING(rme96)) {
  1227. snd_rme96_playback_stop(rme96);
  1228. }
  1229. writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
  1230. spin_unlock_irq(&rme96->lock);
  1231. return 0;
  1232. }
  1233. static int
  1234. snd_rme96_capture_prepare(struct snd_pcm_substream *substream)
  1235. {
  1236. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1237. spin_lock_irq(&rme96->lock);
  1238. if (RME96_ISRECORDING(rme96)) {
  1239. snd_rme96_capture_stop(rme96);
  1240. }
  1241. writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
  1242. spin_unlock_irq(&rme96->lock);
  1243. return 0;
  1244. }
  1245. static int
  1246. snd_rme96_playback_trigger(struct snd_pcm_substream *substream,
  1247. int cmd)
  1248. {
  1249. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1250. switch (cmd) {
  1251. case SNDRV_PCM_TRIGGER_START:
  1252. if (!RME96_ISPLAYING(rme96)) {
  1253. if (substream != rme96->playback_substream) {
  1254. return -EBUSY;
  1255. }
  1256. snd_rme96_playback_start(rme96, 0);
  1257. }
  1258. break;
  1259. case SNDRV_PCM_TRIGGER_STOP:
  1260. if (RME96_ISPLAYING(rme96)) {
  1261. if (substream != rme96->playback_substream) {
  1262. return -EBUSY;
  1263. }
  1264. snd_rme96_playback_stop(rme96);
  1265. }
  1266. break;
  1267. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1268. if (RME96_ISPLAYING(rme96)) {
  1269. snd_rme96_playback_stop(rme96);
  1270. }
  1271. break;
  1272. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1273. if (!RME96_ISPLAYING(rme96)) {
  1274. snd_rme96_playback_start(rme96, 1);
  1275. }
  1276. break;
  1277. default:
  1278. return -EINVAL;
  1279. }
  1280. return 0;
  1281. }
  1282. static int
  1283. snd_rme96_capture_trigger(struct snd_pcm_substream *substream,
  1284. int cmd)
  1285. {
  1286. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1287. switch (cmd) {
  1288. case SNDRV_PCM_TRIGGER_START:
  1289. if (!RME96_ISRECORDING(rme96)) {
  1290. if (substream != rme96->capture_substream) {
  1291. return -EBUSY;
  1292. }
  1293. snd_rme96_capture_start(rme96, 0);
  1294. }
  1295. break;
  1296. case SNDRV_PCM_TRIGGER_STOP:
  1297. if (RME96_ISRECORDING(rme96)) {
  1298. if (substream != rme96->capture_substream) {
  1299. return -EBUSY;
  1300. }
  1301. snd_rme96_capture_stop(rme96);
  1302. }
  1303. break;
  1304. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1305. if (RME96_ISRECORDING(rme96)) {
  1306. snd_rme96_capture_stop(rme96);
  1307. }
  1308. break;
  1309. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1310. if (!RME96_ISRECORDING(rme96)) {
  1311. snd_rme96_capture_start(rme96, 1);
  1312. }
  1313. break;
  1314. default:
  1315. return -EINVAL;
  1316. }
  1317. return 0;
  1318. }
  1319. static snd_pcm_uframes_t
  1320. snd_rme96_playback_pointer(struct snd_pcm_substream *substream)
  1321. {
  1322. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1323. return snd_rme96_playback_ptr(rme96);
  1324. }
  1325. static snd_pcm_uframes_t
  1326. snd_rme96_capture_pointer(struct snd_pcm_substream *substream)
  1327. {
  1328. struct rme96 *rme96 = snd_pcm_substream_chip(substream);
  1329. return snd_rme96_capture_ptr(rme96);
  1330. }
  1331. static struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
  1332. .open = snd_rme96_playback_spdif_open,
  1333. .close = snd_rme96_playback_close,
  1334. .ioctl = snd_pcm_lib_ioctl,
  1335. .hw_params = snd_rme96_playback_hw_params,
  1336. .prepare = snd_rme96_playback_prepare,
  1337. .trigger = snd_rme96_playback_trigger,
  1338. .pointer = snd_rme96_playback_pointer,
  1339. .copy = snd_rme96_playback_copy,
  1340. .silence = snd_rme96_playback_silence,
  1341. .mmap = snd_pcm_lib_mmap_iomem,
  1342. };
  1343. static struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
  1344. .open = snd_rme96_capture_spdif_open,
  1345. .close = snd_rme96_capture_close,
  1346. .ioctl = snd_pcm_lib_ioctl,
  1347. .hw_params = snd_rme96_capture_hw_params,
  1348. .prepare = snd_rme96_capture_prepare,
  1349. .trigger = snd_rme96_capture_trigger,
  1350. .pointer = snd_rme96_capture_pointer,
  1351. .copy = snd_rme96_capture_copy,
  1352. .mmap = snd_pcm_lib_mmap_iomem,
  1353. };
  1354. static struct snd_pcm_ops snd_rme96_playback_adat_ops = {
  1355. .open = snd_rme96_playback_adat_open,
  1356. .close = snd_rme96_playback_close,
  1357. .ioctl = snd_pcm_lib_ioctl,
  1358. .hw_params = snd_rme96_playback_hw_params,
  1359. .prepare = snd_rme96_playback_prepare,
  1360. .trigger = snd_rme96_playback_trigger,
  1361. .pointer = snd_rme96_playback_pointer,
  1362. .copy = snd_rme96_playback_copy,
  1363. .silence = snd_rme96_playback_silence,
  1364. .mmap = snd_pcm_lib_mmap_iomem,
  1365. };
  1366. static struct snd_pcm_ops snd_rme96_capture_adat_ops = {
  1367. .open = snd_rme96_capture_adat_open,
  1368. .close = snd_rme96_capture_close,
  1369. .ioctl = snd_pcm_lib_ioctl,
  1370. .hw_params = snd_rme96_capture_hw_params,
  1371. .prepare = snd_rme96_capture_prepare,
  1372. .trigger = snd_rme96_capture_trigger,
  1373. .pointer = snd_rme96_capture_pointer,
  1374. .copy = snd_rme96_capture_copy,
  1375. .mmap = snd_pcm_lib_mmap_iomem,
  1376. };
  1377. static void
  1378. snd_rme96_free(void *private_data)
  1379. {
  1380. struct rme96 *rme96 = (struct rme96 *)private_data;
  1381. if (rme96 == NULL) {
  1382. return;
  1383. }
  1384. if (rme96->irq >= 0) {
  1385. snd_rme96_playback_stop(rme96);
  1386. snd_rme96_capture_stop(rme96);
  1387. rme96->areg &= ~RME96_AR_DAC_EN;
  1388. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  1389. free_irq(rme96->irq, (void *)rme96);
  1390. rme96->irq = -1;
  1391. }
  1392. if (rme96->iobase) {
  1393. iounmap(rme96->iobase);
  1394. rme96->iobase = NULL;
  1395. }
  1396. if (rme96->port) {
  1397. pci_release_regions(rme96->pci);
  1398. rme96->port = 0;
  1399. }
  1400. pci_disable_device(rme96->pci);
  1401. }
  1402. static void
  1403. snd_rme96_free_spdif_pcm(struct snd_pcm *pcm)
  1404. {
  1405. struct rme96 *rme96 = (struct rme96 *) pcm->private_data;
  1406. rme96->spdif_pcm = NULL;
  1407. }
  1408. static void
  1409. snd_rme96_free_adat_pcm(struct snd_pcm *pcm)
  1410. {
  1411. struct rme96 *rme96 = (struct rme96 *) pcm->private_data;
  1412. rme96->adat_pcm = NULL;
  1413. }
  1414. static int __devinit
  1415. snd_rme96_create(struct rme96 *rme96)
  1416. {
  1417. struct pci_dev *pci = rme96->pci;
  1418. int err;
  1419. rme96->irq = -1;
  1420. spin_lock_init(&rme96->lock);
  1421. if ((err = pci_enable_device(pci)) < 0)
  1422. return err;
  1423. if ((err = pci_request_regions(pci, "RME96")) < 0)
  1424. return err;
  1425. rme96->port = pci_resource_start(rme96->pci, 0);
  1426. if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) {
  1427. snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
  1428. return -ENOMEM;
  1429. }
  1430. if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_DISABLED|IRQF_SHARED, "RME96", (void *)rme96)) {
  1431. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  1432. return -EBUSY;
  1433. }
  1434. rme96->irq = pci->irq;
  1435. /* read the card's revision number */
  1436. pci_read_config_byte(pci, 8, &rme96->rev);
  1437. /* set up ALSA pcm device for S/PDIF */
  1438. if ((err = snd_pcm_new(rme96->card, "Digi96 IEC958", 0,
  1439. 1, 1, &rme96->spdif_pcm)) < 0)
  1440. {
  1441. return err;
  1442. }
  1443. rme96->spdif_pcm->private_data = rme96;
  1444. rme96->spdif_pcm->private_free = snd_rme96_free_spdif_pcm;
  1445. strcpy(rme96->spdif_pcm->name, "Digi96 IEC958");
  1446. snd_pcm_set_ops(rme96->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rme96_playback_spdif_ops);
  1447. snd_pcm_set_ops(rme96->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rme96_capture_spdif_ops);
  1448. rme96->spdif_pcm->info_flags = 0;
  1449. /* set up ALSA pcm device for ADAT */
  1450. if (pci->device == PCI_DEVICE_ID_RME_DIGI96) {
  1451. /* ADAT is not available on the base model */
  1452. rme96->adat_pcm = NULL;
  1453. } else {
  1454. if ((err = snd_pcm_new(rme96->card, "Digi96 ADAT", 1,
  1455. 1, 1, &rme96->adat_pcm)) < 0)
  1456. {
  1457. return err;
  1458. }
  1459. rme96->adat_pcm->private_data = rme96;
  1460. rme96->adat_pcm->private_free = snd_rme96_free_adat_pcm;
  1461. strcpy(rme96->adat_pcm->name, "Digi96 ADAT");
  1462. snd_pcm_set_ops(rme96->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rme96_playback_adat_ops);
  1463. snd_pcm_set_ops(rme96->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rme96_capture_adat_ops);
  1464. rme96->adat_pcm->info_flags = 0;
  1465. }
  1466. rme96->playback_periodsize = 0;
  1467. rme96->capture_periodsize = 0;
  1468. /* make sure playback/capture is stopped, if by some reason active */
  1469. snd_rme96_playback_stop(rme96);
  1470. snd_rme96_capture_stop(rme96);
  1471. /* set default values in registers */
  1472. rme96->wcreg =
  1473. RME96_WCR_FREQ_1 | /* set 44.1 kHz playback */
  1474. RME96_WCR_SEL | /* normal playback */
  1475. RME96_WCR_MASTER | /* set to master clock mode */
  1476. RME96_WCR_INP_0; /* set coaxial input */
  1477. rme96->areg = RME96_AR_FREQPAD_1; /* set 44.1 kHz analog capture */
  1478. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1479. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  1480. /* reset the ADC */
  1481. writel(rme96->areg | RME96_AR_PD2,
  1482. rme96->iobase + RME96_IO_ADDITIONAL_REG);
  1483. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  1484. /* reset and enable the DAC (order is important). */
  1485. snd_rme96_reset_dac(rme96);
  1486. rme96->areg |= RME96_AR_DAC_EN;
  1487. writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
  1488. /* reset playback and record buffer pointers */
  1489. writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
  1490. writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
  1491. /* reset volume */
  1492. rme96->vol[0] = rme96->vol[1] = 0;
  1493. if (RME96_HAS_ANALOG_OUT(rme96)) {
  1494. snd_rme96_apply_dac_volume(rme96);
  1495. }
  1496. /* init switch interface */
  1497. if ((err = snd_rme96_create_switches(rme96->card, rme96)) < 0) {
  1498. return err;
  1499. }
  1500. /* init proc interface */
  1501. snd_rme96_proc_init(rme96);
  1502. return 0;
  1503. }
  1504. /*
  1505. * proc interface
  1506. */
  1507. static void
  1508. snd_rme96_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
  1509. {
  1510. int n;
  1511. struct rme96 *rme96 = (struct rme96 *)entry->private_data;
  1512. rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1513. snd_iprintf(buffer, rme96->card->longname);
  1514. snd_iprintf(buffer, " (index #%d)\n", rme96->card->number + 1);
  1515. snd_iprintf(buffer, "\nGeneral settings\n");
  1516. if (rme96->wcreg & RME96_WCR_IDIS) {
  1517. snd_iprintf(buffer, " period size: N/A (interrupts "
  1518. "disabled)\n");
  1519. } else if (rme96->wcreg & RME96_WCR_ISEL) {
  1520. snd_iprintf(buffer, " period size: 2048 bytes\n");
  1521. } else {
  1522. snd_iprintf(buffer, " period size: 8192 bytes\n");
  1523. }
  1524. snd_iprintf(buffer, "\nInput settings\n");
  1525. switch (snd_rme96_getinputtype(rme96)) {
  1526. case RME96_INPUT_OPTICAL:
  1527. snd_iprintf(buffer, " input: optical");
  1528. break;
  1529. case RME96_INPUT_COAXIAL:
  1530. snd_iprintf(buffer, " input: coaxial");
  1531. break;
  1532. case RME96_INPUT_INTERNAL:
  1533. snd_iprintf(buffer, " input: internal");
  1534. break;
  1535. case RME96_INPUT_XLR:
  1536. snd_iprintf(buffer, " input: XLR");
  1537. break;
  1538. case RME96_INPUT_ANALOG:
  1539. snd_iprintf(buffer, " input: analog");
  1540. break;
  1541. }
  1542. if (snd_rme96_capture_getrate(rme96, &n) < 0) {
  1543. snd_iprintf(buffer, "\n sample rate: no valid signal\n");
  1544. } else {
  1545. if (n) {
  1546. snd_iprintf(buffer, " (8 channels)\n");
  1547. } else {
  1548. snd_iprintf(buffer, " (2 channels)\n");
  1549. }
  1550. snd_iprintf(buffer, " sample rate: %d Hz\n",
  1551. snd_rme96_capture_getrate(rme96, &n));
  1552. }
  1553. if (rme96->wcreg & RME96_WCR_MODE24_2) {
  1554. snd_iprintf(buffer, " sample format: 24 bit\n");
  1555. } else {
  1556. snd_iprintf(buffer, " sample format: 16 bit\n");
  1557. }
  1558. snd_iprintf(buffer, "\nOutput settings\n");
  1559. if (rme96->wcreg & RME96_WCR_SEL) {
  1560. snd_iprintf(buffer, " output signal: normal playback\n");
  1561. } else {
  1562. snd_iprintf(buffer, " output signal: same as input\n");
  1563. }
  1564. snd_iprintf(buffer, " sample rate: %d Hz\n",
  1565. snd_rme96_playback_getrate(rme96));
  1566. if (rme96->wcreg & RME96_WCR_MODE24) {
  1567. snd_iprintf(buffer, " sample format: 24 bit\n");
  1568. } else {
  1569. snd_iprintf(buffer, " sample format: 16 bit\n");
  1570. }
  1571. if (rme96->areg & RME96_AR_WSEL) {
  1572. snd_iprintf(buffer, " sample clock source: word clock\n");
  1573. } else if (rme96->wcreg & RME96_WCR_MASTER) {
  1574. snd_iprintf(buffer, " sample clock source: internal\n");
  1575. } else if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
  1576. snd_iprintf(buffer, " sample clock source: autosync (internal anyway due to analog input setting)\n");
  1577. } else if (snd_rme96_capture_getrate(rme96, &n) < 0) {
  1578. snd_iprintf(buffer, " sample clock source: autosync (internal anyway due to no valid signal)\n");
  1579. } else {
  1580. snd_iprintf(buffer, " sample clock source: autosync\n");
  1581. }
  1582. if (rme96->wcreg & RME96_WCR_PRO) {
  1583. snd_iprintf(buffer, " format: AES/EBU (professional)\n");
  1584. } else {
  1585. snd_iprintf(buffer, " format: IEC958 (consumer)\n");
  1586. }
  1587. if (rme96->wcreg & RME96_WCR_EMP) {
  1588. snd_iprintf(buffer, " emphasis: on\n");
  1589. } else {
  1590. snd_iprintf(buffer, " emphasis: off\n");
  1591. }
  1592. if (rme96->wcreg & RME96_WCR_DOLBY) {
  1593. snd_iprintf(buffer, " non-audio (dolby): on\n");
  1594. } else {
  1595. snd_iprintf(buffer, " non-audio (dolby): off\n");
  1596. }
  1597. if (RME96_HAS_ANALOG_IN(rme96)) {
  1598. snd_iprintf(buffer, "\nAnalog output settings\n");
  1599. switch (snd_rme96_getmontracks(rme96)) {
  1600. case RME96_MONITOR_TRACKS_1_2:
  1601. snd_iprintf(buffer, " monitored ADAT tracks: 1+2\n");
  1602. break;
  1603. case RME96_MONITOR_TRACKS_3_4:
  1604. snd_iprintf(buffer, " monitored ADAT tracks: 3+4\n");
  1605. break;
  1606. case RME96_MONITOR_TRACKS_5_6:
  1607. snd_iprintf(buffer, " monitored ADAT tracks: 5+6\n");
  1608. break;
  1609. case RME96_MONITOR_TRACKS_7_8:
  1610. snd_iprintf(buffer, " monitored ADAT tracks: 7+8\n");
  1611. break;
  1612. }
  1613. switch (snd_rme96_getattenuation(rme96)) {
  1614. case RME96_ATTENUATION_0:
  1615. snd_iprintf(buffer, " attenuation: 0 dB\n");
  1616. break;
  1617. case RME96_ATTENUATION_6:
  1618. snd_iprintf(buffer, " attenuation: -6 dB\n");
  1619. break;
  1620. case RME96_ATTENUATION_12:
  1621. snd_iprintf(buffer, " attenuation: -12 dB\n");
  1622. break;
  1623. case RME96_ATTENUATION_18:
  1624. snd_iprintf(buffer, " attenuation: -18 dB\n");
  1625. break;
  1626. }
  1627. snd_iprintf(buffer, " volume left: %u\n", rme96->vol[0]);
  1628. snd_iprintf(buffer, " volume right: %u\n", rme96->vol[1]);
  1629. }
  1630. }
  1631. static void __devinit
  1632. snd_rme96_proc_init(struct rme96 *rme96)
  1633. {
  1634. struct snd_info_entry *entry;
  1635. if (! snd_card_proc_new(rme96->card, "rme96", &entry))
  1636. snd_info_set_text_ops(entry, rme96, snd_rme96_proc_read);
  1637. }
  1638. /*
  1639. * control interface
  1640. */
  1641. static int
  1642. snd_rme96_info_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1643. {
  1644. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1645. uinfo->count = 1;
  1646. uinfo->value.integer.min = 0;
  1647. uinfo->value.integer.max = 1;
  1648. return 0;
  1649. }
  1650. static int
  1651. snd_rme96_get_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1652. {
  1653. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1654. spin_lock_irq(&rme96->lock);
  1655. ucontrol->value.integer.value[0] = rme96->wcreg & RME96_WCR_SEL ? 0 : 1;
  1656. spin_unlock_irq(&rme96->lock);
  1657. return 0;
  1658. }
  1659. static int
  1660. snd_rme96_put_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1661. {
  1662. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1663. unsigned int val;
  1664. int change;
  1665. val = ucontrol->value.integer.value[0] ? 0 : RME96_WCR_SEL;
  1666. spin_lock_irq(&rme96->lock);
  1667. val = (rme96->wcreg & ~RME96_WCR_SEL) | val;
  1668. change = val != rme96->wcreg;
  1669. rme96->wcreg = val;
  1670. writel(val, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1671. spin_unlock_irq(&rme96->lock);
  1672. return change;
  1673. }
  1674. static int
  1675. snd_rme96_info_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1676. {
  1677. static char *_texts[5] = { "Optical", "Coaxial", "Internal", "XLR", "Analog" };
  1678. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1679. char *texts[5] = { _texts[0], _texts[1], _texts[2], _texts[3], _texts[4] };
  1680. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1681. uinfo->count = 1;
  1682. switch (rme96->pci->device) {
  1683. case PCI_DEVICE_ID_RME_DIGI96:
  1684. case PCI_DEVICE_ID_RME_DIGI96_8:
  1685. uinfo->value.enumerated.items = 3;
  1686. break;
  1687. case PCI_DEVICE_ID_RME_DIGI96_8_PRO:
  1688. uinfo->value.enumerated.items = 4;
  1689. break;
  1690. case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST:
  1691. if (rme96->rev > 4) {
  1692. /* PST */
  1693. uinfo->value.enumerated.items = 4;
  1694. texts[3] = _texts[4]; /* Analog instead of XLR */
  1695. } else {
  1696. /* PAD */
  1697. uinfo->value.enumerated.items = 5;
  1698. }
  1699. break;
  1700. default:
  1701. snd_BUG();
  1702. break;
  1703. }
  1704. if (uinfo->value.enumerated.item > uinfo->value.enumerated.items - 1) {
  1705. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1706. }
  1707. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1708. return 0;
  1709. }
  1710. static int
  1711. snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1712. {
  1713. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1714. unsigned int items = 3;
  1715. spin_lock_irq(&rme96->lock);
  1716. ucontrol->value.enumerated.item[0] = snd_rme96_getinputtype(rme96);
  1717. switch (rme96->pci->device) {
  1718. case PCI_DEVICE_ID_RME_DIGI96:
  1719. case PCI_DEVICE_ID_RME_DIGI96_8:
  1720. items = 3;
  1721. break;
  1722. case PCI_DEVICE_ID_RME_DIGI96_8_PRO:
  1723. items = 4;
  1724. break;
  1725. case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST:
  1726. if (rme96->rev > 4) {
  1727. /* for handling PST case, (INPUT_ANALOG is moved to INPUT_XLR */
  1728. if (ucontrol->value.enumerated.item[0] == RME96_INPUT_ANALOG) {
  1729. ucontrol->value.enumerated.item[0] = RME96_INPUT_XLR;
  1730. }
  1731. items = 4;
  1732. } else {
  1733. items = 5;
  1734. }
  1735. break;
  1736. default:
  1737. snd_BUG();
  1738. break;
  1739. }
  1740. if (ucontrol->value.enumerated.item[0] >= items) {
  1741. ucontrol->value.enumerated.item[0] = items - 1;
  1742. }
  1743. spin_unlock_irq(&rme96->lock);
  1744. return 0;
  1745. }
  1746. static int
  1747. snd_rme96_put_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1748. {
  1749. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1750. unsigned int val;
  1751. int change, items = 3;
  1752. switch (rme96->pci->device) {
  1753. case PCI_DEVICE_ID_RME_DIGI96:
  1754. case PCI_DEVICE_ID_RME_DIGI96_8:
  1755. items = 3;
  1756. break;
  1757. case PCI_DEVICE_ID_RME_DIGI96_8_PRO:
  1758. items = 4;
  1759. break;
  1760. case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST:
  1761. if (rme96->rev > 4) {
  1762. items = 4;
  1763. } else {
  1764. items = 5;
  1765. }
  1766. break;
  1767. default:
  1768. snd_BUG();
  1769. break;
  1770. }
  1771. val = ucontrol->value.enumerated.item[0] % items;
  1772. /* special case for PST */
  1773. if (rme96->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST && rme96->rev > 4) {
  1774. if (val == RME96_INPUT_XLR) {
  1775. val = RME96_INPUT_ANALOG;
  1776. }
  1777. }
  1778. spin_lock_irq(&rme96->lock);
  1779. change = (int)val != snd_rme96_getinputtype(rme96);
  1780. snd_rme96_setinputtype(rme96, val);
  1781. spin_unlock_irq(&rme96->lock);
  1782. return change;
  1783. }
  1784. static int
  1785. snd_rme96_info_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1786. {
  1787. static char *texts[3] = { "AutoSync", "Internal", "Word" };
  1788. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1789. uinfo->count = 1;
  1790. uinfo->value.enumerated.items = 3;
  1791. if (uinfo->value.enumerated.item > 2) {
  1792. uinfo->value.enumerated.item = 2;
  1793. }
  1794. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1795. return 0;
  1796. }
  1797. static int
  1798. snd_rme96_get_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1799. {
  1800. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1801. spin_lock_irq(&rme96->lock);
  1802. ucontrol->value.enumerated.item[0] = snd_rme96_getclockmode(rme96);
  1803. spin_unlock_irq(&rme96->lock);
  1804. return 0;
  1805. }
  1806. static int
  1807. snd_rme96_put_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1808. {
  1809. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1810. unsigned int val;
  1811. int change;
  1812. val = ucontrol->value.enumerated.item[0] % 3;
  1813. spin_lock_irq(&rme96->lock);
  1814. change = (int)val != snd_rme96_getclockmode(rme96);
  1815. snd_rme96_setclockmode(rme96, val);
  1816. spin_unlock_irq(&rme96->lock);
  1817. return change;
  1818. }
  1819. static int
  1820. snd_rme96_info_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1821. {
  1822. static char *texts[4] = { "0 dB", "-6 dB", "-12 dB", "-18 dB" };
  1823. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1824. uinfo->count = 1;
  1825. uinfo->value.enumerated.items = 4;
  1826. if (uinfo->value.enumerated.item > 3) {
  1827. uinfo->value.enumerated.item = 3;
  1828. }
  1829. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1830. return 0;
  1831. }
  1832. static int
  1833. snd_rme96_get_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1834. {
  1835. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1836. spin_lock_irq(&rme96->lock);
  1837. ucontrol->value.enumerated.item[0] = snd_rme96_getattenuation(rme96);
  1838. spin_unlock_irq(&rme96->lock);
  1839. return 0;
  1840. }
  1841. static int
  1842. snd_rme96_put_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1843. {
  1844. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1845. unsigned int val;
  1846. int change;
  1847. val = ucontrol->value.enumerated.item[0] % 4;
  1848. spin_lock_irq(&rme96->lock);
  1849. change = (int)val != snd_rme96_getattenuation(rme96);
  1850. snd_rme96_setattenuation(rme96, val);
  1851. spin_unlock_irq(&rme96->lock);
  1852. return change;
  1853. }
  1854. static int
  1855. snd_rme96_info_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1856. {
  1857. static char *texts[4] = { "1+2", "3+4", "5+6", "7+8" };
  1858. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1859. uinfo->count = 1;
  1860. uinfo->value.enumerated.items = 4;
  1861. if (uinfo->value.enumerated.item > 3) {
  1862. uinfo->value.enumerated.item = 3;
  1863. }
  1864. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1865. return 0;
  1866. }
  1867. static int
  1868. snd_rme96_get_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1869. {
  1870. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1871. spin_lock_irq(&rme96->lock);
  1872. ucontrol->value.enumerated.item[0] = snd_rme96_getmontracks(rme96);
  1873. spin_unlock_irq(&rme96->lock);
  1874. return 0;
  1875. }
  1876. static int
  1877. snd_rme96_put_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1878. {
  1879. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1880. unsigned int val;
  1881. int change;
  1882. val = ucontrol->value.enumerated.item[0] % 4;
  1883. spin_lock_irq(&rme96->lock);
  1884. change = (int)val != snd_rme96_getmontracks(rme96);
  1885. snd_rme96_setmontracks(rme96, val);
  1886. spin_unlock_irq(&rme96->lock);
  1887. return change;
  1888. }
  1889. static u32 snd_rme96_convert_from_aes(struct snd_aes_iec958 *aes)
  1890. {
  1891. u32 val = 0;
  1892. val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? RME96_WCR_PRO : 0;
  1893. val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? RME96_WCR_DOLBY : 0;
  1894. if (val & RME96_WCR_PRO)
  1895. val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? RME96_WCR_EMP : 0;
  1896. else
  1897. val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? RME96_WCR_EMP : 0;
  1898. return val;
  1899. }
  1900. static void snd_rme96_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
  1901. {
  1902. aes->status[0] = ((val & RME96_WCR_PRO) ? IEC958_AES0_PROFESSIONAL : 0) |
  1903. ((val & RME96_WCR_DOLBY) ? IEC958_AES0_NONAUDIO : 0);
  1904. if (val & RME96_WCR_PRO)
  1905. aes->status[0] |= (val & RME96_WCR_EMP) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
  1906. else
  1907. aes->status[0] |= (val & RME96_WCR_EMP) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
  1908. }
  1909. static int snd_rme96_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1910. {
  1911. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1912. uinfo->count = 1;
  1913. return 0;
  1914. }
  1915. static int snd_rme96_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1916. {
  1917. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1918. snd_rme96_convert_to_aes(&ucontrol->value.iec958, rme96->wcreg_spdif);
  1919. return 0;
  1920. }
  1921. static int snd_rme96_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1922. {
  1923. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1924. int change;
  1925. u32 val;
  1926. val = snd_rme96_convert_from_aes(&ucontrol->value.iec958);
  1927. spin_lock_irq(&rme96->lock);
  1928. change = val != rme96->wcreg_spdif;
  1929. rme96->wcreg_spdif = val;
  1930. spin_unlock_irq(&rme96->lock);
  1931. return change;
  1932. }
  1933. static int snd_rme96_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1934. {
  1935. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1936. uinfo->count = 1;
  1937. return 0;
  1938. }
  1939. static int snd_rme96_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1940. {
  1941. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1942. snd_rme96_convert_to_aes(&ucontrol->value.iec958, rme96->wcreg_spdif_stream);
  1943. return 0;
  1944. }
  1945. static int snd_rme96_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1946. {
  1947. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1948. int change;
  1949. u32 val;
  1950. val = snd_rme96_convert_from_aes(&ucontrol->value.iec958);
  1951. spin_lock_irq(&rme96->lock);
  1952. change = val != rme96->wcreg_spdif_stream;
  1953. rme96->wcreg_spdif_stream = val;
  1954. rme96->wcreg &= ~(RME96_WCR_PRO | RME96_WCR_DOLBY | RME96_WCR_EMP);
  1955. rme96->wcreg |= val;
  1956. writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
  1957. spin_unlock_irq(&rme96->lock);
  1958. return change;
  1959. }
  1960. static int snd_rme96_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1961. {
  1962. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1963. uinfo->count = 1;
  1964. return 0;
  1965. }
  1966. static int snd_rme96_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1967. {
  1968. ucontrol->value.iec958.status[0] = kcontrol->private_value;
  1969. return 0;
  1970. }
  1971. static int
  1972. snd_rme96_dac_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1973. {
  1974. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1975. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1976. uinfo->count = 2;
  1977. uinfo->value.integer.min = 0;
  1978. uinfo->value.integer.max = RME96_185X_MAX_OUT(rme96);
  1979. return 0;
  1980. }
  1981. static int
  1982. snd_rme96_dac_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u)
  1983. {
  1984. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1985. spin_lock_irq(&rme96->lock);
  1986. u->value.integer.value[0] = rme96->vol[0];
  1987. u->value.integer.value[1] = rme96->vol[1];
  1988. spin_unlock_irq(&rme96->lock);
  1989. return 0;
  1990. }
  1991. static int
  1992. snd_rme96_dac_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u)
  1993. {
  1994. struct rme96 *rme96 = snd_kcontrol_chip(kcontrol);
  1995. int change = 0;
  1996. if (!RME96_HAS_ANALOG_OUT(rme96)) {
  1997. return -EINVAL;
  1998. }
  1999. spin_lock_irq(&rme96->lock);
  2000. if (u->value.integer.value[0] != rme96->vol[0]) {
  2001. rme96->vol[0] = u->value.integer.value[0];
  2002. change = 1;
  2003. }
  2004. if (u->value.integer.value[1] != rme96->vol[1]) {
  2005. rme96->vol[1] = u->value.integer.value[1];
  2006. change = 1;
  2007. }
  2008. if (change) {
  2009. snd_rme96_apply_dac_volume(rme96);
  2010. }
  2011. spin_unlock_irq(&rme96->lock);
  2012. return change;
  2013. }
  2014. static struct snd_kcontrol_new snd_rme96_controls[] = {
  2015. {
  2016. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2017. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  2018. .info = snd_rme96_control_spdif_info,
  2019. .get = snd_rme96_control_spdif_get,
  2020. .put = snd_rme96_control_spdif_put
  2021. },
  2022. {
  2023. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  2024. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2025. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  2026. .info = snd_rme96_control_spdif_stream_info,
  2027. .get = snd_rme96_control_spdif_stream_get,
  2028. .put = snd_rme96_control_spdif_stream_put
  2029. },
  2030. {
  2031. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  2032. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2033. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  2034. .info = snd_rme96_control_spdif_mask_info,
  2035. .get = snd_rme96_control_spdif_mask_get,
  2036. .private_value = IEC958_AES0_NONAUDIO |
  2037. IEC958_AES0_PROFESSIONAL |
  2038. IEC958_AES0_CON_EMPHASIS
  2039. },
  2040. {
  2041. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  2042. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  2043. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  2044. .info = snd_rme96_control_spdif_mask_info,
  2045. .get = snd_rme96_control_spdif_mask_get,
  2046. .private_value = IEC958_AES0_NONAUDIO |
  2047. IEC958_AES0_PROFESSIONAL |
  2048. IEC958_AES0_PRO_EMPHASIS
  2049. },
  2050. {
  2051. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2052. .name = "Input Connector",
  2053. .info = snd_rme96_info_inputtype_control,
  2054. .get = snd_rme96_get_inputtype_control,
  2055. .put = snd_rme96_put_inputtype_control
  2056. },
  2057. {
  2058. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2059. .name = "Loopback Input",
  2060. .info = snd_rme96_info_loopback_control,
  2061. .get = snd_rme96_get_loopback_control,
  2062. .put = snd_rme96_put_loopback_control
  2063. },
  2064. {
  2065. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2066. .name = "Sample Clock Source",
  2067. .info = snd_rme96_info_clockmode_control,
  2068. .get = snd_rme96_get_clockmode_control,
  2069. .put = snd_rme96_put_clockmode_control
  2070. },
  2071. {
  2072. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2073. .name = "Monitor Tracks",
  2074. .info = snd_rme96_info_montracks_control,
  2075. .get = snd_rme96_get_montracks_control,
  2076. .put = snd_rme96_put_montracks_control
  2077. },
  2078. {
  2079. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2080. .name = "Attenuation",
  2081. .info = snd_rme96_info_attenuation_control,
  2082. .get = snd_rme96_get_attenuation_control,
  2083. .put = snd_rme96_put_attenuation_control
  2084. },
  2085. {
  2086. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2087. .name = "DAC Playback Volume",
  2088. .info = snd_rme96_dac_volume_info,
  2089. .get = snd_rme96_dac_volume_get,
  2090. .put = snd_rme96_dac_volume_put
  2091. }
  2092. };
  2093. static int
  2094. snd_rme96_create_switches(struct snd_card *card,
  2095. struct rme96 *rme96)
  2096. {
  2097. int idx, err;
  2098. struct snd_kcontrol *kctl;
  2099. for (idx = 0; idx < 7; idx++) {
  2100. if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_rme96_controls[idx], rme96))) < 0)
  2101. return err;
  2102. if (idx == 1) /* IEC958 (S/PDIF) Stream */
  2103. rme96->spdif_ctl = kctl;
  2104. }
  2105. if (RME96_HAS_ANALOG_OUT(rme96)) {
  2106. for (idx = 7; idx < 10; idx++)
  2107. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_rme96_controls[idx], rme96))) < 0)
  2108. return err;
  2109. }
  2110. return 0;
  2111. }
  2112. /*
  2113. * Card initialisation
  2114. */
  2115. static void snd_rme96_card_free(struct snd_card *card)
  2116. {
  2117. snd_rme96_free(card->private_data);
  2118. }
  2119. static int __devinit
  2120. snd_rme96_probe(struct pci_dev *pci,
  2121. const struct pci_device_id *pci_id)
  2122. {
  2123. static int dev;
  2124. struct rme96 *rme96;
  2125. struct snd_card *card;
  2126. int err;
  2127. u8 val;
  2128. if (dev >= SNDRV_CARDS) {
  2129. return -ENODEV;
  2130. }
  2131. if (!enable[dev]) {
  2132. dev++;
  2133. return -ENOENT;
  2134. }
  2135. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  2136. sizeof(struct rme96))) == NULL)
  2137. return -ENOMEM;
  2138. card->private_free = snd_rme96_card_free;
  2139. rme96 = (struct rme96 *)card->private_data;
  2140. rme96->card = card;
  2141. rme96->pci = pci;
  2142. snd_card_set_dev(card, &pci->dev);
  2143. if ((err = snd_rme96_create(rme96)) < 0) {
  2144. snd_card_free(card);
  2145. return err;
  2146. }
  2147. strcpy(card->driver, "Digi96");
  2148. switch (rme96->pci->device) {
  2149. case PCI_DEVICE_ID_RME_DIGI96:
  2150. strcpy(card->shortname, "RME Digi96");
  2151. break;
  2152. case PCI_DEVICE_ID_RME_DIGI96_8:
  2153. strcpy(card->shortname, "RME Digi96/8");
  2154. break;
  2155. case PCI_DEVICE_ID_RME_DIGI96_8_PRO:
  2156. strcpy(card->shortname, "RME Digi96/8 PRO");
  2157. break;
  2158. case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST:
  2159. pci_read_config_byte(rme96->pci, 8, &val);
  2160. if (val < 5) {
  2161. strcpy(card->shortname, "RME Digi96/8 PAD");
  2162. } else {
  2163. strcpy(card->shortname, "RME Digi96/8 PST");
  2164. }
  2165. break;
  2166. }
  2167. sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname,
  2168. rme96->port, rme96->irq);
  2169. if ((err = snd_card_register(card)) < 0) {
  2170. snd_card_free(card);
  2171. return err;
  2172. }
  2173. pci_set_drvdata(pci, card);
  2174. dev++;
  2175. return 0;
  2176. }
  2177. static void __devexit snd_rme96_remove(struct pci_dev *pci)
  2178. {
  2179. snd_card_free(pci_get_drvdata(pci));
  2180. pci_set_drvdata(pci, NULL);
  2181. }
  2182. static struct pci_driver driver = {
  2183. .name = "RME Digi96",
  2184. .id_table = snd_rme96_ids,
  2185. .probe = snd_rme96_probe,
  2186. .remove = __devexit_p(snd_rme96_remove),
  2187. };
  2188. static int __init alsa_card_rme96_init(void)
  2189. {
  2190. return pci_register_driver(&driver);
  2191. }
  2192. static void __exit alsa_card_rme96_exit(void)
  2193. {
  2194. pci_unregister_driver(&driver);
  2195. }
  2196. module_init(alsa_card_rme96_init)
  2197. module_exit(alsa_card_rme96_exit)