rme96.c 67 KB

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