riptide.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  1. /*
  2. * Driver for the Conexant Riptide Soundchip
  3. *
  4. * Copyright (c) 2004 Peter Gruber <nokos@gmx.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. /*
  22. History:
  23. - 02/15/2004 first release
  24. This Driver is based on the OSS Driver version from Linuxant (riptide-0.6lnxtbeta03111100)
  25. credits from the original files:
  26. MODULE NAME: cnxt_rt.h
  27. AUTHOR: K. Lazarev (Transcribed by KNL)
  28. HISTORY: Major Revision Date By
  29. ----------------------------- -------- -----
  30. Created 02/1/2000 KNL
  31. MODULE NAME: int_mdl.c
  32. AUTHOR: Konstantin Lazarev (Transcribed by KNL)
  33. HISTORY: Major Revision Date By
  34. ----------------------------- -------- -----
  35. Created 10/01/99 KNL
  36. MODULE NAME: riptide.h
  37. AUTHOR: O. Druzhinin (Transcribed by OLD)
  38. HISTORY: Major Revision Date By
  39. ----------------------------- -------- -----
  40. Created 10/16/97 OLD
  41. MODULE NAME: Rp_Cmdif.cpp
  42. AUTHOR: O. Druzhinin (Transcribed by OLD)
  43. K. Lazarev (Transcribed by KNL)
  44. HISTORY: Major Revision Date By
  45. ----------------------------- -------- -----
  46. Adopted from NT4 driver 6/22/99 OLD
  47. Ported to Linux 9/01/99 KNL
  48. MODULE NAME: rt_hw.c
  49. AUTHOR: O. Druzhinin (Transcribed by OLD)
  50. C. Lazarev (Transcribed by CNL)
  51. HISTORY: Major Revision Date By
  52. ----------------------------- -------- -----
  53. Created 11/18/97 OLD
  54. Hardware functions for RipTide 11/24/97 CNL
  55. (ES1) are coded
  56. Hardware functions for RipTide 12/24/97 CNL
  57. (A0) are coded
  58. Hardware functions for RipTide 03/20/98 CNL
  59. (A1) are coded
  60. Boot loader is included 05/07/98 CNL
  61. Redesigned for WDM 07/27/98 CNL
  62. Redesigned for Linux 09/01/99 CNL
  63. MODULE NAME: rt_hw.h
  64. AUTHOR: C. Lazarev (Transcribed by CNL)
  65. HISTORY: Major Revision Date By
  66. ----------------------------- -------- -----
  67. Created 11/18/97 CNL
  68. MODULE NAME: rt_mdl.c
  69. AUTHOR: Konstantin Lazarev (Transcribed by KNL)
  70. HISTORY: Major Revision Date By
  71. ----------------------------- -------- -----
  72. Created 10/01/99 KNL
  73. MODULE NAME: mixer.h
  74. AUTHOR: K. Kenney
  75. HISTORY: Major Revision Date By
  76. ----------------------------- -------- -----
  77. Created from MS W95 Sample 11/28/95 KRS
  78. RipTide 10/15/97 KRS
  79. Adopted for Windows NT driver 01/20/98 CNL
  80. */
  81. #include <sound/driver.h>
  82. #include <linux/delay.h>
  83. #include <linux/init.h>
  84. #include <linux/interrupt.h>
  85. #include <linux/pci.h>
  86. #include <linux/slab.h>
  87. #include <linux/wait.h>
  88. #include <linux/gameport.h>
  89. #include <linux/device.h>
  90. #include <linux/firmware.h>
  91. #include <asm/io.h>
  92. #include <sound/core.h>
  93. #include <sound/info.h>
  94. #include <sound/control.h>
  95. #include <sound/pcm.h>
  96. #include <sound/pcm_params.h>
  97. #include <sound/ac97_codec.h>
  98. #include <sound/mpu401.h>
  99. #include <sound/opl3.h>
  100. #include <sound/initval.h>
  101. #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  102. #define SUPPORT_JOYSTICK 1
  103. #endif
  104. MODULE_AUTHOR("Peter Gruber <nokos@gmx.net>");
  105. MODULE_DESCRIPTION("riptide");
  106. MODULE_LICENSE("GPL");
  107. MODULE_SUPPORTED_DEVICE("{{Conexant,Riptide}}");
  108. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  109. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  110. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
  111. #ifdef SUPPORT_JOYSTICK
  112. static int joystick_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x200 };
  113. #endif
  114. static int mpu_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x330 };
  115. static int opl3_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x388 };
  116. module_param_array(index, int, NULL, 0444);
  117. MODULE_PARM_DESC(index, "Index value for Riptide soundcard.");
  118. module_param_array(id, charp, NULL, 0444);
  119. MODULE_PARM_DESC(id, "ID string for Riptide soundcard.");
  120. module_param_array(enable, bool, NULL, 0444);
  121. MODULE_PARM_DESC(enable, "Enable Riptide soundcard.");
  122. #ifdef SUPPORT_JOYSTICK
  123. module_param_array(joystick_port, int, NULL, 0444);
  124. MODULE_PARM_DESC(joystick_port, "Joystick port # for Riptide soundcard.");
  125. #endif
  126. module_param_array(mpu_port, int, NULL, 0444);
  127. MODULE_PARM_DESC(mpu_port, "MPU401 port # for Riptide driver.");
  128. module_param_array(opl3_port, int, NULL, 0444);
  129. MODULE_PARM_DESC(opl3_port, "OPL3 port # for Riptide driver.");
  130. /*
  131. */
  132. #define MPU401_HW_RIPTIDE MPU401_HW_MPU401
  133. #define OPL3_HW_RIPTIDE OPL3_HW_OPL3
  134. #define PCI_EXT_CapId 0x40
  135. #define PCI_EXT_NextCapPrt 0x41
  136. #define PCI_EXT_PWMC 0x42
  137. #define PCI_EXT_PWSCR 0x44
  138. #define PCI_EXT_Data00 0x46
  139. #define PCI_EXT_PMSCR_BSE 0x47
  140. #define PCI_EXT_SB_Base 0x48
  141. #define PCI_EXT_FM_Base 0x4a
  142. #define PCI_EXT_MPU_Base 0x4C
  143. #define PCI_EXT_Game_Base 0x4E
  144. #define PCI_EXT_Legacy_Mask 0x50
  145. #define PCI_EXT_AsicRev 0x52
  146. #define PCI_EXT_Reserved3 0x53
  147. #define LEGACY_ENABLE_ALL 0x8000 /* legacy device options */
  148. #define LEGACY_ENABLE_SB 0x4000
  149. #define LEGACY_ENABLE_FM 0x2000
  150. #define LEGACY_ENABLE_MPU_INT 0x1000
  151. #define LEGACY_ENABLE_MPU 0x0800
  152. #define LEGACY_ENABLE_GAMEPORT 0x0400
  153. #define MAX_WRITE_RETRY 10 /* cmd interface limits */
  154. #define MAX_ERROR_COUNT 10
  155. #define CMDIF_TIMEOUT 500000
  156. #define RESET_TRIES 5
  157. #define READ_PORT_ULONG(p) inl((unsigned long)&(p))
  158. #define WRITE_PORT_ULONG(p,x) outl(x,(unsigned long)&(p))
  159. #define READ_AUDIO_CONTROL(p) READ_PORT_ULONG(p->audio_control)
  160. #define WRITE_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,x)
  161. #define UMASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)|x)
  162. #define MASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)&x)
  163. #define READ_AUDIO_STATUS(p) READ_PORT_ULONG(p->audio_status)
  164. #define SET_GRESET(p) UMASK_AUDIO_CONTROL(p,0x0001) /* global reset switch */
  165. #define UNSET_GRESET(p) MASK_AUDIO_CONTROL(p,~0x0001)
  166. #define SET_AIE(p) UMASK_AUDIO_CONTROL(p,0x0004) /* interrupt enable */
  167. #define UNSET_AIE(p) MASK_AUDIO_CONTROL(p,~0x0004)
  168. #define SET_AIACK(p) UMASK_AUDIO_CONTROL(p,0x0008) /* interrupt acknowledge */
  169. #define UNSET_AIACKT(p) MASKAUDIO_CONTROL(p,~0x0008)
  170. #define SET_ECMDAE(p) UMASK_AUDIO_CONTROL(p,0x0010)
  171. #define UNSET_ECMDAE(p) MASK_AUDIO_CONTROL(p,~0x0010)
  172. #define SET_ECMDBE(p) UMASK_AUDIO_CONTROL(p,0x0020)
  173. #define UNSET_ECMDBE(p) MASK_AUDIO_CONTROL(p,~0x0020)
  174. #define SET_EDATAF(p) UMASK_AUDIO_CONTROL(p,0x0040)
  175. #define UNSET_EDATAF(p) MASK_AUDIO_CONTROL(p,~0x0040)
  176. #define SET_EDATBF(p) UMASK_AUDIO_CONTROL(p,0x0080)
  177. #define UNSET_EDATBF(p) MASK_AUDIO_CONTROL(p,~0x0080)
  178. #define SET_ESBIRQON(p) UMASK_AUDIO_CONTROL(p,0x0100)
  179. #define UNSET_ESBIRQON(p) MASK_AUDIO_CONTROL(p,~0x0100)
  180. #define SET_EMPUIRQ(p) UMASK_AUDIO_CONTROL(p,0x0200)
  181. #define UNSET_EMPUIRQ(p) MASK_AUDIO_CONTROL(p,~0x0200)
  182. #define IS_CMDE(a) (READ_PORT_ULONG(a->stat)&0x1) /* cmd empty */
  183. #define IS_DATF(a) (READ_PORT_ULONG(a->stat)&0x2) /* data filled */
  184. #define IS_READY(p) (READ_AUDIO_STATUS(p)&0x0001)
  185. #define IS_DLREADY(p) (READ_AUDIO_STATUS(p)&0x0002)
  186. #define IS_DLERR(p) (READ_AUDIO_STATUS(p)&0x0004)
  187. #define IS_GERR(p) (READ_AUDIO_STATUS(p)&0x0008) /* error ! */
  188. #define IS_CMDAEIRQ(p) (READ_AUDIO_STATUS(p)&0x0010)
  189. #define IS_CMDBEIRQ(p) (READ_AUDIO_STATUS(p)&0x0020)
  190. #define IS_DATAFIRQ(p) (READ_AUDIO_STATUS(p)&0x0040)
  191. #define IS_DATBFIRQ(p) (READ_AUDIO_STATUS(p)&0x0080)
  192. #define IS_EOBIRQ(p) (READ_AUDIO_STATUS(p)&0x0100) /* interrupt status */
  193. #define IS_EOSIRQ(p) (READ_AUDIO_STATUS(p)&0x0200)
  194. #define IS_EOCIRQ(p) (READ_AUDIO_STATUS(p)&0x0400)
  195. #define IS_UNSLIRQ(p) (READ_AUDIO_STATUS(p)&0x0800)
  196. #define IS_SBIRQ(p) (READ_AUDIO_STATUS(p)&0x1000)
  197. #define IS_MPUIRQ(p) (READ_AUDIO_STATUS(p)&0x2000)
  198. #define RESP 0x00000001 /* command flags */
  199. #define PARM 0x00000002
  200. #define CMDA 0x00000004
  201. #define CMDB 0x00000008
  202. #define NILL 0x00000000
  203. #define LONG0(a) ((u32)a) /* shifts and masks */
  204. #define BYTE0(a) (LONG0(a)&0xff)
  205. #define BYTE1(a) (BYTE0(a)<<8)
  206. #define BYTE2(a) (BYTE0(a)<<16)
  207. #define BYTE3(a) (BYTE0(a)<<24)
  208. #define WORD0(a) (LONG0(a)&0xffff)
  209. #define WORD1(a) (WORD0(a)<<8)
  210. #define WORD2(a) (WORD0(a)<<16)
  211. #define TRINIB0(a) (LONG0(a)&0xffffff)
  212. #define TRINIB1(a) (TRINIB0(a)<<8)
  213. #define RET(a) ((union cmdret *)(a))
  214. #define SEND_GETV(p,b) sendcmd(p,RESP,GETV,0,RET(b)) /* get version */
  215. #define SEND_GETC(p,b,c) sendcmd(p,PARM|RESP,GETC,c,RET(b))
  216. #define SEND_GUNS(p,b) sendcmd(p,RESP,GUNS,0,RET(b))
  217. #define SEND_SCID(p,b) sendcmd(p,RESP,SCID,0,RET(b))
  218. #define SEND_RMEM(p,b,c,d) sendcmd(p,PARM|RESP,RMEM|BYTE1(b),LONG0(c),RET(d)) /* memory access for firmware write */
  219. #define SEND_SMEM(p,b,c) sendcmd(p,PARM,SMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */
  220. #define SEND_WMEM(p,b,c) sendcmd(p,PARM,WMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */
  221. #define SEND_SDTM(p,b,c) sendcmd(p,PARM|RESP,SDTM|TRINIB1(b),0,RET(c)) /* memory access for firmware write */
  222. #define SEND_GOTO(p,b) sendcmd(p,PARM,GOTO,LONG0(b),RET(0)) /* memory access for firmware write */
  223. #define SEND_SETDPLL(p) sendcmd(p,0,ARM_SETDPLL,0,RET(0))
  224. #define SEND_SSTR(p,b,c) sendcmd(p,PARM,SSTR|BYTE3(b),LONG0(c),RET(0)) /* start stream */
  225. #define SEND_PSTR(p,b) sendcmd(p,PARM,PSTR,BYTE3(b),RET(0)) /* pause stream */
  226. #define SEND_KSTR(p,b) sendcmd(p,PARM,KSTR,BYTE3(b),RET(0)) /* stop stream */
  227. #define SEND_KDMA(p) sendcmd(p,0,KDMA,0,RET(0)) /* stop all dma */
  228. #define SEND_GPOS(p,b,c,d) sendcmd(p,PARM|RESP,GPOS,BYTE3(c)|BYTE2(b),RET(d)) /* get position in dma */
  229. #define SEND_SETF(p,b,c,d,e,f,g) sendcmd(p,PARM,SETF|WORD1(b)|BYTE3(c),d|BYTE1(e)|BYTE2(f)|BYTE3(g),RET(0)) /* set sample format at mixer */
  230. #define SEND_GSTS(p,b,c,d) sendcmd(p,PARM|RESP,GSTS,BYTE3(c)|BYTE2(b),RET(d))
  231. #define SEND_NGPOS(p,b,c,d) sendcmd(p,PARM|RESP,NGPOS,BYTE3(c)|BYTE2(b),RET(d))
  232. #define SEND_PSEL(p,b,c) sendcmd(p,PARM,PSEL,BYTE2(b)|BYTE3(c),RET(0)) /* activate lbus path */
  233. #define SEND_PCLR(p,b,c) sendcmd(p,PARM,PCLR,BYTE2(b)|BYTE3(c),RET(0)) /* deactivate lbus path */
  234. #define SEND_PLST(p,b) sendcmd(p,PARM,PLST,BYTE3(b),RET(0))
  235. #define SEND_RSSV(p,b,c,d) sendcmd(p,PARM|RESP,RSSV,BYTE2(b)|BYTE3(c),RET(d))
  236. #define SEND_LSEL(p,b,c,d,e,f,g,h) sendcmd(p,PARM,LSEL|BYTE1(b)|BYTE2(c)|BYTE3(d),BYTE0(e)|BYTE1(f)|BYTE2(g)|BYTE3(h),RET(0)) /* select paths for internal connections */
  237. #define SEND_SSRC(p,b,c,d,e) sendcmd(p,PARM,SSRC|BYTE1(b)|WORD2(c),WORD0(d)|WORD2(e),RET(0)) /* configure source */
  238. #define SEND_SLST(p,b) sendcmd(p,PARM,SLST,BYTE3(b),RET(0))
  239. #define SEND_RSRC(p,b,c) sendcmd(p,RESP,RSRC|BYTE1(b),0,RET(c)) /* read source config */
  240. #define SEND_SSRB(p,b,c) sendcmd(p,PARM,SSRB|BYTE1(b),WORD2(c),RET(0))
  241. #define SEND_SDGV(p,b,c,d,e) sendcmd(p,PARM,SDGV|BYTE2(b)|BYTE3(c),WORD0(d)|WORD2(e),RET(0)) /* set digital mixer */
  242. #define SEND_RDGV(p,b,c,d) sendcmd(p,PARM|RESP,RDGV|BYTE2(b)|BYTE3(c),0,RET(d)) /* read digital mixer */
  243. #define SEND_DLST(p,b) sendcmd(p,PARM,DLST,BYTE3(b),RET(0))
  244. #define SEND_SACR(p,b,c) sendcmd(p,PARM,SACR,WORD0(b)|WORD2(c),RET(0)) /* set AC97 register */
  245. #define SEND_RACR(p,b,c) sendcmd(p,PARM|RESP,RACR,WORD2(b),RET(c)) /* get AC97 register */
  246. #define SEND_ALST(p,b) sendcmd(p,PARM,ALST,BYTE3(b),RET(0))
  247. #define SEND_TXAC(p,b,c,d,e,f) sendcmd(p,PARM,TXAC|BYTE1(b)|WORD2(c),WORD0(d)|BYTE2(e)|BYTE3(f),RET(0))
  248. #define SEND_RXAC(p,b,c,d) sendcmd(p,PARM|RESP,RXAC,BYTE2(b)|BYTE3(c),RET(d))
  249. #define SEND_SI2S(p,b) sendcmd(p,PARM,SI2S,WORD2(b),RET(0))
  250. #define EOB_STATUS 0x80000000 /* status flags : block boundary */
  251. #define EOS_STATUS 0x40000000 /* : stoppped */
  252. #define EOC_STATUS 0x20000000 /* : stream end */
  253. #define ERR_STATUS 0x10000000
  254. #define EMPTY_STATUS 0x08000000
  255. #define IEOB_ENABLE 0x1 /* enable interrupts for status notification above */
  256. #define IEOS_ENABLE 0x2
  257. #define IEOC_ENABLE 0x4
  258. #define RDONCE 0x8
  259. #define DESC_MAX_MASK 0xff
  260. #define ST_PLAY 0x1 /* stream states */
  261. #define ST_STOP 0x2
  262. #define ST_PAUSE 0x4
  263. #define I2S_INTDEC 3 /* config for I2S link */
  264. #define I2S_MERGER 0
  265. #define I2S_SPLITTER 0
  266. #define I2S_MIXER 7
  267. #define I2S_RATE 44100
  268. #define MODEM_INTDEC 4 /* config for modem link */
  269. #define MODEM_MERGER 3
  270. #define MODEM_SPLITTER 0
  271. #define MODEM_MIXER 11
  272. #define FM_INTDEC 3 /* config for FM/OPL3 link */
  273. #define FM_MERGER 0
  274. #define FM_SPLITTER 0
  275. #define FM_MIXER 9
  276. #define SPLIT_PATH 0x80 /* path splitting flag */
  277. enum FIRMWARE {
  278. DATA_REC = 0, EXT_END_OF_FILE, EXT_SEG_ADDR_REC, EXT_GOTO_CMD_REC,
  279. EXT_LIN_ADDR_REC,
  280. };
  281. enum CMDS {
  282. GETV = 0x00, GETC, GUNS, SCID, RMEM =
  283. 0x10, SMEM, WMEM, SDTM, GOTO, SSTR =
  284. 0x20, PSTR, KSTR, KDMA, GPOS, SETF, GSTS, NGPOS, PSEL =
  285. 0x30, PCLR, PLST, RSSV, LSEL, SSRC = 0x40, SLST, RSRC, SSRB, SDGV =
  286. 0x50, RDGV, DLST, SACR = 0x60, RACR, ALST, TXAC, RXAC, SI2S =
  287. 0x70, ARM_SETDPLL = 0x72,
  288. };
  289. enum E1SOURCE {
  290. ARM2LBUS_FIFO0 = 0, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2, ARM2LBUS_FIFO3,
  291. ARM2LBUS_FIFO4, ARM2LBUS_FIFO5, ARM2LBUS_FIFO6, ARM2LBUS_FIFO7,
  292. ARM2LBUS_FIFO8, ARM2LBUS_FIFO9, ARM2LBUS_FIFO10, ARM2LBUS_FIFO11,
  293. ARM2LBUS_FIFO12, ARM2LBUS_FIFO13, ARM2LBUS_FIFO14, ARM2LBUS_FIFO15,
  294. INTER0_OUT, INTER1_OUT, INTER2_OUT, INTER3_OUT, INTER4_OUT,
  295. INTERM0_OUT, INTERM1_OUT, INTERM2_OUT, INTERM3_OUT, INTERM4_OUT,
  296. INTERM5_OUT, INTERM6_OUT, DECIMM0_OUT, DECIMM1_OUT, DECIMM2_OUT,
  297. DECIMM3_OUT, DECIM0_OUT, SR3_4_OUT, OPL3_SAMPLE, ASRC0, ASRC1,
  298. ACLNK2PADC, ACLNK2MODEM0RX, ACLNK2MIC, ACLNK2MODEM1RX, ACLNK2HNDMIC,
  299. DIGITAL_MIXER_OUT0, GAINFUNC0_OUT, GAINFUNC1_OUT, GAINFUNC2_OUT,
  300. GAINFUNC3_OUT, GAINFUNC4_OUT, SOFTMODEMTX, SPLITTER0_OUTL,
  301. SPLITTER0_OUTR, SPLITTER1_OUTL, SPLITTER1_OUTR, SPLITTER2_OUTL,
  302. SPLITTER2_OUTR, SPLITTER3_OUTL, SPLITTER3_OUTR, MERGER0_OUT,
  303. MERGER1_OUT, MERGER2_OUT, MERGER3_OUT, ARM2LBUS_FIFO_DIRECT, NO_OUT
  304. };
  305. enum E2SINK {
  306. LBUS2ARM_FIFO0 = 0, LBUS2ARM_FIFO1, LBUS2ARM_FIFO2, LBUS2ARM_FIFO3,
  307. LBUS2ARM_FIFO4, LBUS2ARM_FIFO5, LBUS2ARM_FIFO6, LBUS2ARM_FIFO7,
  308. INTER0_IN, INTER1_IN, INTER2_IN, INTER3_IN, INTER4_IN, INTERM0_IN,
  309. INTERM1_IN, INTERM2_IN, INTERM3_IN, INTERM4_IN, INTERM5_IN, INTERM6_IN,
  310. DECIMM0_IN, DECIMM1_IN, DECIMM2_IN, DECIMM3_IN, DECIM0_IN, SR3_4_IN,
  311. PDAC2ACLNK, MODEM0TX2ACLNK, MODEM1TX2ACLNK, HNDSPK2ACLNK,
  312. DIGITAL_MIXER_IN0, DIGITAL_MIXER_IN1, DIGITAL_MIXER_IN2,
  313. DIGITAL_MIXER_IN3, DIGITAL_MIXER_IN4, DIGITAL_MIXER_IN5,
  314. DIGITAL_MIXER_IN6, DIGITAL_MIXER_IN7, DIGITAL_MIXER_IN8,
  315. DIGITAL_MIXER_IN9, DIGITAL_MIXER_IN10, DIGITAL_MIXER_IN11,
  316. GAINFUNC0_IN, GAINFUNC1_IN, GAINFUNC2_IN, GAINFUNC3_IN, GAINFUNC4_IN,
  317. SOFTMODEMRX, SPLITTER0_IN, SPLITTER1_IN, SPLITTER2_IN, SPLITTER3_IN,
  318. MERGER0_INL, MERGER0_INR, MERGER1_INL, MERGER1_INR, MERGER2_INL,
  319. MERGER2_INR, MERGER3_INL, MERGER3_INR, E2SINK_MAX
  320. };
  321. enum LBUS_SINK {
  322. LS_SRC_INTERPOLATOR = 0, LS_SRC_INTERPOLATORM, LS_SRC_DECIMATOR,
  323. LS_SRC_DECIMATORM, LS_MIXER_IN, LS_MIXER_GAIN_FUNCTION,
  324. LS_SRC_SPLITTER, LS_SRC_MERGER, LS_NONE1, LS_NONE2,
  325. };
  326. enum RT_CHANNEL_IDS {
  327. M0TX = 0, M1TX, TAMTX, HSSPKR, PDAC, DSNDTX0, DSNDTX1, DSNDTX2,
  328. DSNDTX3, DSNDTX4, DSNDTX5, DSNDTX6, DSNDTX7, WVSTRTX, COP3DTX, SPARE,
  329. M0RX, HSMIC, M1RX, CLEANRX, MICADC, PADC, COPRX1, COPRX2,
  330. CHANNEL_ID_COUNTER
  331. };
  332. enum { SB_CMD = 0, MODEM_CMD, I2S_CMD0, I2S_CMD1, FM_CMD, MAX_CMD };
  333. struct lbuspath {
  334. unsigned char *noconv;
  335. unsigned char *stereo;
  336. unsigned char *mono;
  337. };
  338. struct cmdport {
  339. u32 data1; /* cmd,param */
  340. u32 data2; /* param */
  341. u32 stat; /* status */
  342. u32 pad[5];
  343. };
  344. struct riptideport {
  345. u32 audio_control; /* status registers */
  346. u32 audio_status;
  347. u32 pad[2];
  348. struct cmdport port[2]; /* command ports */
  349. };
  350. struct cmdif {
  351. struct riptideport *hwport;
  352. spinlock_t lock;
  353. unsigned int cmdcnt; /* cmd statistics */
  354. unsigned int cmdtime;
  355. unsigned int cmdtimemax;
  356. unsigned int cmdtimemin;
  357. unsigned int errcnt;
  358. int is_reset;
  359. };
  360. struct riptide_firmware {
  361. u16 ASIC;
  362. u16 CODEC;
  363. u16 AUXDSP;
  364. u16 PROG;
  365. };
  366. union cmdret {
  367. u8 retbytes[8];
  368. u16 retwords[4];
  369. u32 retlongs[2];
  370. };
  371. union firmware_version {
  372. union cmdret ret;
  373. struct riptide_firmware firmware;
  374. };
  375. #define get_pcmhwdev(substream) (struct pcmhw *)(substream->runtime->private_data)
  376. #define PLAYBACK_SUBSTREAMS 3
  377. struct snd_riptide {
  378. struct snd_card *card;
  379. struct pci_dev *pci;
  380. const struct firmware *fw_entry;
  381. struct cmdif *cif;
  382. struct snd_pcm *pcm;
  383. struct snd_pcm *pcm_i2s;
  384. struct snd_rawmidi *rmidi;
  385. struct snd_opl3 *opl3;
  386. struct snd_ac97 *ac97;
  387. struct snd_ac97_bus *ac97_bus;
  388. struct snd_pcm_substream *playback_substream[PLAYBACK_SUBSTREAMS];
  389. struct snd_pcm_substream *capture_substream;
  390. int openstreams;
  391. int irq;
  392. unsigned long port;
  393. unsigned short mpuaddr;
  394. unsigned short opladdr;
  395. #ifdef SUPPORT_JOYSTICK
  396. unsigned short gameaddr;
  397. #endif
  398. struct resource *res_port;
  399. unsigned short device_id;
  400. union firmware_version firmware;
  401. spinlock_t lock;
  402. struct tasklet_struct riptide_tq;
  403. struct snd_info_entry *proc_entry;
  404. unsigned long received_irqs;
  405. unsigned long handled_irqs;
  406. #ifdef CONFIG_PM
  407. int in_suspend;
  408. #endif
  409. };
  410. struct sgd { /* scatter gather desriptor */
  411. u32 dwNextLink;
  412. u32 dwSegPtrPhys;
  413. u32 dwSegLen;
  414. u32 dwStat_Ctl;
  415. };
  416. struct pcmhw { /* pcm descriptor */
  417. struct lbuspath paths;
  418. unsigned char *lbuspath;
  419. unsigned char source;
  420. unsigned char intdec[2];
  421. unsigned char mixer;
  422. unsigned char id;
  423. unsigned char state;
  424. unsigned int rate;
  425. unsigned int channels;
  426. snd_pcm_format_t format;
  427. struct snd_dma_buffer sgdlist;
  428. struct sgd *sgdbuf;
  429. unsigned int size;
  430. unsigned int pages;
  431. unsigned int oldpos;
  432. unsigned int pointer;
  433. };
  434. #define CMDRET_ZERO (union cmdret){{(u32)0, (u32) 0}}
  435. static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm,
  436. union cmdret *ret);
  437. static int getsourcesink(struct cmdif *cif, unsigned char source,
  438. unsigned char sink, unsigned char *a,
  439. unsigned char *b);
  440. static int snd_riptide_initialize(struct snd_riptide *chip);
  441. static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip);
  442. /*
  443. */
  444. static struct pci_device_id snd_riptide_ids[] = {
  445. {
  446. .vendor = 0x127a,.device = 0x4310,
  447. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  448. },
  449. {
  450. .vendor = 0x127a,.device = 0x4320,
  451. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  452. },
  453. {
  454. .vendor = 0x127a,.device = 0x4330,
  455. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  456. },
  457. {
  458. .vendor = 0x127a,.device = 0x4340,
  459. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  460. },
  461. {0,},
  462. };
  463. #ifdef SUPPORT_JOYSTICK
  464. static struct pci_device_id snd_riptide_joystick_ids[] __devinitdata = {
  465. {
  466. .vendor = 0x127a,.device = 0x4312,
  467. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  468. },
  469. {
  470. .vendor = 0x127a,.device = 0x4322,
  471. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  472. },
  473. {.vendor = 0x127a,.device = 0x4332,
  474. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  475. },
  476. {.vendor = 0x127a,.device = 0x4342,
  477. .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,
  478. },
  479. {0,},
  480. };
  481. #endif
  482. MODULE_DEVICE_TABLE(pci, snd_riptide_ids);
  483. /*
  484. */
  485. static unsigned char lbusin2out[E2SINK_MAX + 1][2] = {
  486. {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT,
  487. LS_NONE2},
  488. {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT,
  489. LS_NONE2},
  490. {INTER0_OUT, LS_SRC_INTERPOLATOR}, {INTER1_OUT, LS_SRC_INTERPOLATOR},
  491. {INTER2_OUT, LS_SRC_INTERPOLATOR}, {INTER3_OUT, LS_SRC_INTERPOLATOR},
  492. {INTER4_OUT, LS_SRC_INTERPOLATOR}, {INTERM0_OUT, LS_SRC_INTERPOLATORM},
  493. {INTERM1_OUT, LS_SRC_INTERPOLATORM}, {INTERM2_OUT,
  494. LS_SRC_INTERPOLATORM},
  495. {INTERM3_OUT, LS_SRC_INTERPOLATORM}, {INTERM4_OUT,
  496. LS_SRC_INTERPOLATORM},
  497. {INTERM5_OUT, LS_SRC_INTERPOLATORM}, {INTERM6_OUT,
  498. LS_SRC_INTERPOLATORM},
  499. {DECIMM0_OUT, LS_SRC_DECIMATORM}, {DECIMM1_OUT, LS_SRC_DECIMATORM},
  500. {DECIMM2_OUT, LS_SRC_DECIMATORM}, {DECIMM3_OUT, LS_SRC_DECIMATORM},
  501. {DECIM0_OUT, LS_SRC_DECIMATOR}, {SR3_4_OUT, LS_NONE1}, {NO_OUT,
  502. LS_NONE2},
  503. {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1},
  504. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  505. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  506. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  507. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  508. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  509. {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN},
  510. {GAINFUNC0_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC1_OUT,
  511. LS_MIXER_GAIN_FUNCTION},
  512. {GAINFUNC2_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC3_OUT,
  513. LS_MIXER_GAIN_FUNCTION},
  514. {GAINFUNC4_OUT, LS_MIXER_GAIN_FUNCTION}, {SOFTMODEMTX, LS_NONE1},
  515. {SPLITTER0_OUTL, LS_SRC_SPLITTER}, {SPLITTER1_OUTL, LS_SRC_SPLITTER},
  516. {SPLITTER2_OUTL, LS_SRC_SPLITTER}, {SPLITTER3_OUTL, LS_SRC_SPLITTER},
  517. {MERGER0_OUT, LS_SRC_MERGER}, {MERGER0_OUT, LS_SRC_MERGER},
  518. {MERGER1_OUT, LS_SRC_MERGER},
  519. {MERGER1_OUT, LS_SRC_MERGER}, {MERGER2_OUT, LS_SRC_MERGER},
  520. {MERGER2_OUT, LS_SRC_MERGER},
  521. {MERGER3_OUT, LS_SRC_MERGER}, {MERGER3_OUT, LS_SRC_MERGER}, {NO_OUT,
  522. LS_NONE2},
  523. };
  524. static unsigned char lbus_play_opl3[] = {
  525. DIGITAL_MIXER_IN0 + FM_MIXER, 0xff
  526. };
  527. static unsigned char lbus_play_modem[] = {
  528. DIGITAL_MIXER_IN0 + MODEM_MIXER, 0xff
  529. };
  530. static unsigned char lbus_play_i2s[] = {
  531. INTER0_IN + I2S_INTDEC, DIGITAL_MIXER_IN0 + I2S_MIXER, 0xff
  532. };
  533. static unsigned char lbus_play_out[] = {
  534. PDAC2ACLNK, 0xff
  535. };
  536. static unsigned char lbus_play_outhp[] = {
  537. HNDSPK2ACLNK, 0xff
  538. };
  539. static unsigned char lbus_play_noconv1[] = {
  540. DIGITAL_MIXER_IN0, 0xff
  541. };
  542. static unsigned char lbus_play_stereo1[] = {
  543. INTER0_IN, DIGITAL_MIXER_IN0, 0xff
  544. };
  545. static unsigned char lbus_play_mono1[] = {
  546. INTERM0_IN, DIGITAL_MIXER_IN0, 0xff
  547. };
  548. static unsigned char lbus_play_noconv2[] = {
  549. DIGITAL_MIXER_IN1, 0xff
  550. };
  551. static unsigned char lbus_play_stereo2[] = {
  552. INTER1_IN, DIGITAL_MIXER_IN1, 0xff
  553. };
  554. static unsigned char lbus_play_mono2[] = {
  555. INTERM1_IN, DIGITAL_MIXER_IN1, 0xff
  556. };
  557. static unsigned char lbus_play_noconv3[] = {
  558. DIGITAL_MIXER_IN2, 0xff
  559. };
  560. static unsigned char lbus_play_stereo3[] = {
  561. INTER2_IN, DIGITAL_MIXER_IN2, 0xff
  562. };
  563. static unsigned char lbus_play_mono3[] = {
  564. INTERM2_IN, DIGITAL_MIXER_IN2, 0xff
  565. };
  566. static unsigned char lbus_rec_noconv1[] = {
  567. LBUS2ARM_FIFO5, 0xff
  568. };
  569. static unsigned char lbus_rec_stereo1[] = {
  570. DECIM0_IN, LBUS2ARM_FIFO5, 0xff
  571. };
  572. static unsigned char lbus_rec_mono1[] = {
  573. DECIMM3_IN, LBUS2ARM_FIFO5, 0xff
  574. };
  575. static unsigned char play_ids[] = { 4, 1, 2, };
  576. static unsigned char play_sources[] = {
  577. ARM2LBUS_FIFO4, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2,
  578. };
  579. static struct lbuspath lbus_play_paths[] = {
  580. {
  581. .noconv = lbus_play_noconv1,
  582. .stereo = lbus_play_stereo1,
  583. .mono = lbus_play_mono1,
  584. },
  585. {
  586. .noconv = lbus_play_noconv2,
  587. .stereo = lbus_play_stereo2,
  588. .mono = lbus_play_mono2,
  589. },
  590. {
  591. .noconv = lbus_play_noconv3,
  592. .stereo = lbus_play_stereo3,
  593. .mono = lbus_play_mono3,
  594. },
  595. };
  596. static struct lbuspath lbus_rec_path = {
  597. .noconv = lbus_rec_noconv1,
  598. .stereo = lbus_rec_stereo1,
  599. .mono = lbus_rec_mono1,
  600. };
  601. #define FIRMWARE_VERSIONS 1
  602. static union firmware_version firmware_versions[] = {
  603. {
  604. .firmware = {
  605. .ASIC = 3,
  606. .CODEC = 2,
  607. .AUXDSP = 3,
  608. .PROG = 773,
  609. },
  610. },
  611. };
  612. static u32 atoh(unsigned char *in, unsigned int len)
  613. {
  614. u32 sum = 0;
  615. unsigned int mult = 1;
  616. unsigned char c;
  617. while (len) {
  618. c = in[len - 1];
  619. if ((c >= '0') && (c <= '9'))
  620. sum += mult * (c - '0');
  621. else if ((c >= 'A') && (c <= 'F'))
  622. sum += mult * (c - ('A' - 10));
  623. else if ((c >= 'a') && (c <= 'f'))
  624. sum += mult * (c - ('a' - 10));
  625. mult *= 16;
  626. --len;
  627. }
  628. return sum;
  629. }
  630. static int senddata(struct cmdif *cif, unsigned char *in, u32 offset)
  631. {
  632. u32 addr;
  633. u32 data;
  634. u32 i;
  635. unsigned char *p;
  636. i = atoh(&in[1], 2);
  637. addr = offset + atoh(&in[3], 4);
  638. if (SEND_SMEM(cif, 0, addr) != 0)
  639. return -EACCES;
  640. p = in + 9;
  641. while (i) {
  642. data = atoh(p, 8);
  643. if (SEND_WMEM(cif, 2,
  644. ((data & 0x0f0f0f0f) << 4) | ((data & 0xf0f0f0f0)
  645. >> 4)))
  646. return -EACCES;
  647. i -= 4;
  648. p += 8;
  649. }
  650. return 0;
  651. }
  652. static int loadfirmware(struct cmdif *cif, unsigned char *img,
  653. unsigned int size)
  654. {
  655. unsigned char *in;
  656. u32 laddr, saddr, t, val;
  657. int err = 0;
  658. laddr = saddr = 0;
  659. while (size > 0 && err == 0) {
  660. in = img;
  661. if (in[0] == ':') {
  662. t = atoh(&in[7], 2);
  663. switch (t) {
  664. case DATA_REC:
  665. err = senddata(cif, in, laddr + saddr);
  666. break;
  667. case EXT_SEG_ADDR_REC:
  668. saddr = atoh(&in[9], 4) << 4;
  669. break;
  670. case EXT_LIN_ADDR_REC:
  671. laddr = atoh(&in[9], 4) << 16;
  672. break;
  673. case EXT_GOTO_CMD_REC:
  674. val = atoh(&in[9], 8);
  675. if (SEND_GOTO(cif, val) != 0)
  676. err = -EACCES;
  677. break;
  678. case EXT_END_OF_FILE:
  679. size = 0;
  680. break;
  681. default:
  682. break;
  683. }
  684. while (size > 0) {
  685. size--;
  686. if (*img++ == '\n')
  687. break;
  688. }
  689. }
  690. }
  691. snd_printdd("load firmware return %d\n", err);
  692. return err;
  693. }
  694. static void
  695. alloclbuspath(struct cmdif *cif, unsigned char source,
  696. unsigned char *path, unsigned char *mixer, unsigned char *s)
  697. {
  698. while (*path != 0xff) {
  699. unsigned char sink, type;
  700. sink = *path & (~SPLIT_PATH);
  701. if (sink != E2SINK_MAX) {
  702. snd_printdd("alloc path 0x%x->0x%x\n", source, sink);
  703. SEND_PSEL(cif, source, sink);
  704. source = lbusin2out[sink][0];
  705. type = lbusin2out[sink][1];
  706. if (type == LS_MIXER_IN) {
  707. if (mixer)
  708. *mixer = sink - DIGITAL_MIXER_IN0;
  709. }
  710. if (type == LS_SRC_DECIMATORM ||
  711. type == LS_SRC_DECIMATOR ||
  712. type == LS_SRC_INTERPOLATORM ||
  713. type == LS_SRC_INTERPOLATOR) {
  714. if (s) {
  715. if (s[0] != 0xff)
  716. s[1] = sink;
  717. else
  718. s[0] = sink;
  719. }
  720. }
  721. }
  722. if (*path++ & SPLIT_PATH) {
  723. unsigned char *npath = path;
  724. while (*npath != 0xff)
  725. npath++;
  726. alloclbuspath(cif, source + 1, ++npath, mixer, s);
  727. }
  728. }
  729. }
  730. static void
  731. freelbuspath(struct cmdif *cif, unsigned char source, unsigned char *path)
  732. {
  733. while (*path != 0xff) {
  734. unsigned char sink;
  735. sink = *path & (~SPLIT_PATH);
  736. if (sink != E2SINK_MAX) {
  737. snd_printdd("free path 0x%x->0x%x\n", source, sink);
  738. SEND_PCLR(cif, source, sink);
  739. source = lbusin2out[sink][0];
  740. }
  741. if (*path++ & SPLIT_PATH) {
  742. unsigned char *npath = path;
  743. while (*npath != 0xff)
  744. npath++;
  745. freelbuspath(cif, source + 1, ++npath);
  746. }
  747. }
  748. }
  749. static int writearm(struct cmdif *cif, u32 addr, u32 data, u32 mask)
  750. {
  751. union cmdret rptr = CMDRET_ZERO;
  752. unsigned int i = MAX_WRITE_RETRY;
  753. int flag = 1;
  754. SEND_RMEM(cif, 0x02, addr, &rptr);
  755. rptr.retlongs[0] &= (~mask);
  756. while (--i) {
  757. SEND_SMEM(cif, 0x01, addr);
  758. SEND_WMEM(cif, 0x02, (rptr.retlongs[0] | data));
  759. SEND_RMEM(cif, 0x02, addr, &rptr);
  760. if ((rptr.retlongs[0] & data) == data) {
  761. flag = 0;
  762. break;
  763. } else
  764. rptr.retlongs[0] &= ~mask;
  765. }
  766. snd_printdd("send arm 0x%x 0x%x 0x%x return %d\n", addr, data, mask,
  767. flag);
  768. return flag;
  769. }
  770. static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm,
  771. union cmdret *ret)
  772. {
  773. int i, j;
  774. int err;
  775. unsigned int time = 0;
  776. unsigned long irqflags;
  777. struct riptideport *hwport;
  778. struct cmdport *cmdport = NULL;
  779. snd_assert(cif, return -EINVAL);
  780. hwport = cif->hwport;
  781. if (cif->errcnt > MAX_ERROR_COUNT) {
  782. if (cif->is_reset) {
  783. snd_printk(KERN_ERR
  784. "Riptide: Too many failed cmds, reinitializing\n");
  785. if (riptide_reset(cif, NULL) == 0) {
  786. cif->errcnt = 0;
  787. return -EIO;
  788. }
  789. }
  790. snd_printk(KERN_ERR "Riptide: Initialization failed.\n");
  791. return -EINVAL;
  792. }
  793. if (ret) {
  794. ret->retlongs[0] = 0;
  795. ret->retlongs[1] = 0;
  796. }
  797. i = 0;
  798. spin_lock_irqsave(&cif->lock, irqflags);
  799. while (i++ < CMDIF_TIMEOUT && !IS_READY(cif->hwport))
  800. udelay(10);
  801. if (i >= CMDIF_TIMEOUT) {
  802. err = -EBUSY;
  803. goto errout;
  804. }
  805. err = 0;
  806. for (j = 0, time = 0; time < CMDIF_TIMEOUT; j++, time += 2) {
  807. cmdport = &(hwport->port[j % 2]);
  808. if (IS_DATF(cmdport)) { /* free pending data */
  809. READ_PORT_ULONG(cmdport->data1);
  810. READ_PORT_ULONG(cmdport->data2);
  811. }
  812. if (IS_CMDE(cmdport)) {
  813. if (flags & PARM) /* put data */
  814. WRITE_PORT_ULONG(cmdport->data2, parm);
  815. WRITE_PORT_ULONG(cmdport->data1, cmd); /* write cmd */
  816. if ((flags & RESP) && ret) {
  817. while (!IS_DATF(cmdport) &&
  818. time++ < CMDIF_TIMEOUT)
  819. udelay(10);
  820. if (time < CMDIF_TIMEOUT) { /* read response */
  821. ret->retlongs[0] =
  822. READ_PORT_ULONG(cmdport->data1);
  823. ret->retlongs[1] =
  824. READ_PORT_ULONG(cmdport->data2);
  825. } else {
  826. err = -ENOSYS;
  827. goto errout;
  828. }
  829. }
  830. break;
  831. }
  832. udelay(20);
  833. }
  834. if (time == CMDIF_TIMEOUT) {
  835. err = -ENODATA;
  836. goto errout;
  837. }
  838. spin_unlock_irqrestore(&cif->lock, irqflags);
  839. cif->cmdcnt++; /* update command statistics */
  840. cif->cmdtime += time;
  841. if (time > cif->cmdtimemax)
  842. cif->cmdtimemax = time;
  843. if (time < cif->cmdtimemin)
  844. cif->cmdtimemin = time;
  845. if ((cif->cmdcnt) % 1000 == 0)
  846. snd_printdd
  847. ("send cmd %d time: %d mintime: %d maxtime %d err: %d\n",
  848. cif->cmdcnt, cif->cmdtime, cif->cmdtimemin,
  849. cif->cmdtimemax, cif->errcnt);
  850. return 0;
  851. errout:
  852. cif->errcnt++;
  853. spin_unlock_irqrestore(&cif->lock, irqflags);
  854. snd_printdd
  855. ("send cmd %d hw: 0x%x flag: 0x%x cmd: 0x%x parm: 0x%x ret: 0x%x 0x%x CMDE: %d DATF: %d failed %d\n",
  856. cif->cmdcnt, (int)((void *)&(cmdport->stat) - (void *)hwport),
  857. flags, cmd, parm, ret ? ret->retlongs[0] : 0,
  858. ret ? ret->retlongs[1] : 0, IS_CMDE(cmdport), IS_DATF(cmdport),
  859. err);
  860. return err;
  861. }
  862. static int
  863. setmixer(struct cmdif *cif, short num, unsigned short rval, unsigned short lval)
  864. {
  865. union cmdret rptr = CMDRET_ZERO;
  866. int i = 0;
  867. snd_printdd("sent mixer %d: 0x%d 0x%d\n", num, rval, lval);
  868. do {
  869. SEND_SDGV(cif, num, num, rval, lval);
  870. SEND_RDGV(cif, num, num, &rptr);
  871. if (rptr.retwords[0] == lval && rptr.retwords[1] == rval)
  872. return 0;
  873. } while (i++ < MAX_WRITE_RETRY);
  874. snd_printdd("sent mixer failed\n");
  875. return -EIO;
  876. }
  877. static int getpaths(struct cmdif *cif, unsigned char *o)
  878. {
  879. unsigned char src[E2SINK_MAX];
  880. unsigned char sink[E2SINK_MAX];
  881. int i, j = 0;
  882. for (i = 0; i < E2SINK_MAX; i++) {
  883. getsourcesink(cif, i, i, &src[i], &sink[i]);
  884. if (sink[i] < E2SINK_MAX) {
  885. o[j++] = sink[i];
  886. o[j++] = i;
  887. }
  888. }
  889. return j;
  890. }
  891. static int
  892. getsourcesink(struct cmdif *cif, unsigned char source, unsigned char sink,
  893. unsigned char *a, unsigned char *b)
  894. {
  895. union cmdret rptr = CMDRET_ZERO;
  896. if (SEND_RSSV(cif, source, sink, &rptr) &&
  897. SEND_RSSV(cif, source, sink, &rptr))
  898. return -EIO;
  899. *a = rptr.retbytes[0];
  900. *b = rptr.retbytes[1];
  901. snd_printdd("getsourcesink 0x%x 0x%x\n", *a, *b);
  902. return 0;
  903. }
  904. static int
  905. getsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int *rate)
  906. {
  907. unsigned char *s;
  908. unsigned int p[2] = { 0, 0 };
  909. int i;
  910. union cmdret rptr = CMDRET_ZERO;
  911. s = intdec;
  912. for (i = 0; i < 2; i++) {
  913. if (*s != 0xff) {
  914. if (SEND_RSRC(cif, *s, &rptr) &&
  915. SEND_RSRC(cif, *s, &rptr))
  916. return -EIO;
  917. p[i] += rptr.retwords[1];
  918. p[i] *= rptr.retwords[2];
  919. p[i] += rptr.retwords[3];
  920. p[i] /= 65536;
  921. }
  922. s++;
  923. }
  924. if (p[0]) {
  925. if (p[1] != p[0])
  926. snd_printdd("rates differ %d %d\n", p[0], p[1]);
  927. *rate = (unsigned int)p[0];
  928. } else
  929. *rate = (unsigned int)p[1];
  930. snd_printdd("getsampleformat %d %d %d\n", intdec[0], intdec[1], *rate);
  931. return 0;
  932. }
  933. static int
  934. setsampleformat(struct cmdif *cif,
  935. unsigned char mixer, unsigned char id,
  936. unsigned char channels, unsigned char format)
  937. {
  938. unsigned char w, ch, sig, order;
  939. snd_printdd
  940. ("setsampleformat mixer: %d id: %d channels: %d format: %d\n",
  941. mixer, id, channels, format);
  942. ch = channels == 1;
  943. w = snd_pcm_format_width(format) == 8;
  944. sig = snd_pcm_format_unsigned(format) != 0;
  945. order = snd_pcm_format_big_endian(format) != 0;
  946. if (SEND_SETF(cif, mixer, w, ch, order, sig, id) &&
  947. SEND_SETF(cif, mixer, w, ch, order, sig, id)) {
  948. snd_printdd("setsampleformat failed\n");
  949. return -EIO;
  950. }
  951. return 0;
  952. }
  953. static int
  954. setsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int rate)
  955. {
  956. u32 D, M, N;
  957. union cmdret rptr = CMDRET_ZERO;
  958. int i;
  959. snd_printdd("setsamplerate intdec: %d,%d rate: %d\n", intdec[0],
  960. intdec[1], rate);
  961. D = 48000;
  962. M = ((rate == 48000) ? 47999 : rate) * 65536;
  963. N = M % D;
  964. M /= D;
  965. for (i = 0; i < 2; i++) {
  966. if (*intdec != 0xff) {
  967. do {
  968. SEND_SSRC(cif, *intdec, D, M, N);
  969. SEND_RSRC(cif, *intdec, &rptr);
  970. } while (rptr.retwords[1] != D &&
  971. rptr.retwords[2] != M &&
  972. rptr.retwords[3] != N &&
  973. i++ < MAX_WRITE_RETRY);
  974. if (i == MAX_WRITE_RETRY) {
  975. snd_printdd("sent samplerate %d: %d failed\n",
  976. *intdec, rate);
  977. return -EIO;
  978. }
  979. }
  980. intdec++;
  981. }
  982. return 0;
  983. }
  984. static int
  985. getmixer(struct cmdif *cif, short num, unsigned short *rval,
  986. unsigned short *lval)
  987. {
  988. union cmdret rptr = CMDRET_ZERO;
  989. if (SEND_RDGV(cif, num, num, &rptr) && SEND_RDGV(cif, num, num, &rptr))
  990. return -EIO;
  991. *rval = rptr.retwords[0];
  992. *lval = rptr.retwords[1];
  993. snd_printdd("got mixer %d: 0x%d 0x%d\n", num, *rval, *lval);
  994. return 0;
  995. }
  996. static void riptide_handleirq(unsigned long dev_id)
  997. {
  998. struct snd_riptide *chip = (void *)dev_id;
  999. struct cmdif *cif = chip->cif;
  1000. struct snd_pcm_substream *substream[PLAYBACK_SUBSTREAMS + 1];
  1001. struct snd_pcm_runtime *runtime;
  1002. struct pcmhw *data = NULL;
  1003. unsigned int pos, period_bytes;
  1004. struct sgd *c;
  1005. int i, j;
  1006. unsigned int flag;
  1007. if (!cif)
  1008. return;
  1009. for (i = 0; i < PLAYBACK_SUBSTREAMS; i++)
  1010. substream[i] = chip->playback_substream[i];
  1011. substream[i] = chip->capture_substream;
  1012. for (i = 0; i < PLAYBACK_SUBSTREAMS + 1; i++) {
  1013. if (substream[i] &&
  1014. (runtime = substream[i]->runtime) &&
  1015. (data = runtime->private_data) && data->state != ST_STOP) {
  1016. pos = 0;
  1017. for (j = 0; j < data->pages; j++) {
  1018. c = &data->sgdbuf[j];
  1019. flag = le32_to_cpu(c->dwStat_Ctl);
  1020. if (flag & EOB_STATUS)
  1021. pos += le32_to_cpu(c->dwSegLen);
  1022. if (flag & EOC_STATUS)
  1023. pos += le32_to_cpu(c->dwSegLen);
  1024. if ((flag & EOS_STATUS)
  1025. && (data->state == ST_PLAY)) {
  1026. data->state = ST_STOP;
  1027. snd_printk(KERN_ERR
  1028. "Riptide: DMA stopped unexpectedly\n");
  1029. }
  1030. c->dwStat_Ctl =
  1031. cpu_to_le32(flag &
  1032. ~(EOS_STATUS | EOB_STATUS |
  1033. EOC_STATUS));
  1034. }
  1035. data->pointer += pos;
  1036. pos += data->oldpos;
  1037. if (data->state != ST_STOP) {
  1038. period_bytes =
  1039. frames_to_bytes(runtime,
  1040. runtime->period_size);
  1041. snd_printdd
  1042. ("interrupt 0x%x after 0x%lx of 0x%lx frames in period\n",
  1043. READ_AUDIO_STATUS(cif->hwport),
  1044. bytes_to_frames(runtime, pos),
  1045. runtime->period_size);
  1046. j = 0;
  1047. if (pos >= period_bytes) {
  1048. j++;
  1049. while (pos >= period_bytes)
  1050. pos -= period_bytes;
  1051. }
  1052. data->oldpos = pos;
  1053. if (j > 0)
  1054. snd_pcm_period_elapsed(substream[i]);
  1055. }
  1056. }
  1057. }
  1058. }
  1059. #ifdef CONFIG_PM
  1060. static int riptide_suspend(struct pci_dev *pci, pm_message_t state)
  1061. {
  1062. struct snd_card *card = pci_get_drvdata(pci);
  1063. struct snd_riptide *chip = card->private_data;
  1064. chip->in_suspend = 1;
  1065. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1066. snd_pcm_suspend_all(chip->pcm);
  1067. snd_ac97_suspend(chip->ac97);
  1068. pci_set_power_state(pci, PCI_D3hot);
  1069. pci_disable_device(pci);
  1070. pci_save_state(pci);
  1071. return 0;
  1072. }
  1073. static int riptide_resume(struct pci_dev *pci)
  1074. {
  1075. struct snd_card *card = pci_get_drvdata(pci);
  1076. struct snd_riptide *chip = card->private_data;
  1077. pci_restore_state(pci);
  1078. pci_enable_device(pci);
  1079. pci_set_power_state(pci, PCI_D0);
  1080. pci_set_master(pci);
  1081. snd_riptide_initialize(chip);
  1082. snd_ac97_resume(chip->ac97);
  1083. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1084. chip->in_suspend = 0;
  1085. return 0;
  1086. }
  1087. #endif
  1088. static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
  1089. {
  1090. int timeout, tries;
  1091. union cmdret rptr = CMDRET_ZERO;
  1092. union firmware_version firmware;
  1093. int i, j, err, has_firmware;
  1094. if (!cif)
  1095. return -EINVAL;
  1096. cif->cmdcnt = 0;
  1097. cif->cmdtime = 0;
  1098. cif->cmdtimemax = 0;
  1099. cif->cmdtimemin = 0xffffffff;
  1100. cif->errcnt = 0;
  1101. cif->is_reset = 0;
  1102. tries = RESET_TRIES;
  1103. has_firmware = 0;
  1104. while (has_firmware == 0 && tries-- > 0) {
  1105. for (i = 0; i < 2; i++) {
  1106. WRITE_PORT_ULONG(cif->hwport->port[i].data1, 0);
  1107. WRITE_PORT_ULONG(cif->hwport->port[i].data2, 0);
  1108. }
  1109. SET_GRESET(cif->hwport);
  1110. udelay(100);
  1111. UNSET_GRESET(cif->hwport);
  1112. udelay(100);
  1113. for (timeout = 100000; --timeout; udelay(10)) {
  1114. if (IS_READY(cif->hwport) && !IS_GERR(cif->hwport))
  1115. break;
  1116. }
  1117. if (timeout == 0) {
  1118. snd_printk(KERN_ERR
  1119. "Riptide: device not ready, audio status: 0x%x ready: %d gerr: %d\n",
  1120. READ_AUDIO_STATUS(cif->hwport),
  1121. IS_READY(cif->hwport), IS_GERR(cif->hwport));
  1122. return -EIO;
  1123. } else {
  1124. snd_printdd
  1125. ("Riptide: audio status: 0x%x ready: %d gerr: %d\n",
  1126. READ_AUDIO_STATUS(cif->hwport),
  1127. IS_READY(cif->hwport), IS_GERR(cif->hwport));
  1128. }
  1129. SEND_GETV(cif, &rptr);
  1130. for (i = 0; i < 4; i++)
  1131. firmware.ret.retwords[i] = rptr.retwords[i];
  1132. snd_printdd
  1133. ("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n",
  1134. firmware.firmware.ASIC, firmware.firmware.CODEC,
  1135. firmware.firmware.AUXDSP, firmware.firmware.PROG);
  1136. for (j = 0; j < FIRMWARE_VERSIONS; j++) {
  1137. has_firmware = 1;
  1138. for (i = 0; i < 4; i++) {
  1139. if (firmware_versions[j].ret.retwords[i] !=
  1140. firmware.ret.retwords[i])
  1141. has_firmware = 0;
  1142. }
  1143. if (has_firmware)
  1144. break;
  1145. }
  1146. if (chip != NULL && has_firmware == 0) {
  1147. snd_printdd("Writing Firmware\n");
  1148. if (!chip->fw_entry) {
  1149. if ((err =
  1150. request_firmware(&chip->fw_entry,
  1151. "riptide.hex",
  1152. &chip->pci->dev)) != 0) {
  1153. snd_printk(KERN_ERR
  1154. "Riptide: Firmware not available %d\n",
  1155. err);
  1156. return -EIO;
  1157. }
  1158. }
  1159. err = loadfirmware(cif, chip->fw_entry->data,
  1160. chip->fw_entry->size);
  1161. if (err)
  1162. snd_printk(KERN_ERR
  1163. "Riptide: Could not load firmware %d\n",
  1164. err);
  1165. }
  1166. }
  1167. SEND_SACR(cif, 0, AC97_RESET);
  1168. SEND_RACR(cif, AC97_RESET, &rptr);
  1169. snd_printdd("AC97: 0x%x 0x%x\n", rptr.retlongs[0], rptr.retlongs[1]);
  1170. SEND_PLST(cif, 0);
  1171. SEND_SLST(cif, 0);
  1172. SEND_DLST(cif, 0);
  1173. SEND_ALST(cif, 0);
  1174. SEND_KDMA(cif);
  1175. writearm(cif, 0x301F8, 1, 1);
  1176. writearm(cif, 0x301F4, 1, 1);
  1177. SEND_LSEL(cif, MODEM_CMD, 0, 0, MODEM_INTDEC, MODEM_MERGER,
  1178. MODEM_SPLITTER, MODEM_MIXER);
  1179. setmixer(cif, MODEM_MIXER, 0x7fff, 0x7fff);
  1180. alloclbuspath(cif, ARM2LBUS_FIFO13, lbus_play_modem, NULL, NULL);
  1181. SEND_LSEL(cif, FM_CMD, 0, 0, FM_INTDEC, FM_MERGER, FM_SPLITTER,
  1182. FM_MIXER);
  1183. setmixer(cif, FM_MIXER, 0x7fff, 0x7fff);
  1184. writearm(cif, 0x30648 + FM_MIXER * 4, 0x01, 0x00000005);
  1185. writearm(cif, 0x301A8, 0x02, 0x00000002);
  1186. writearm(cif, 0x30264, 0x08, 0xffffffff);
  1187. alloclbuspath(cif, OPL3_SAMPLE, lbus_play_opl3, NULL, NULL);
  1188. SEND_SSRC(cif, I2S_INTDEC, 48000,
  1189. ((u32) I2S_RATE * 65536) / 48000,
  1190. ((u32) I2S_RATE * 65536) % 48000);
  1191. SEND_LSEL(cif, I2S_CMD0, 0, 0, I2S_INTDEC, I2S_MERGER, I2S_SPLITTER,
  1192. I2S_MIXER);
  1193. SEND_SI2S(cif, 1);
  1194. alloclbuspath(cif, ARM2LBUS_FIFO0, lbus_play_i2s, NULL, NULL);
  1195. alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_out, NULL, NULL);
  1196. alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_outhp, NULL, NULL);
  1197. SET_AIACK(cif->hwport);
  1198. SET_AIE(cif->hwport);
  1199. SET_AIACK(cif->hwport);
  1200. cif->is_reset = 1;
  1201. if (chip) {
  1202. for (i = 0; i < 4; i++)
  1203. chip->firmware.ret.retwords[i] =
  1204. firmware.ret.retwords[i];
  1205. }
  1206. return 0;
  1207. }
  1208. static struct snd_pcm_hardware snd_riptide_playback = {
  1209. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1210. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1211. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
  1212. .formats =
  1213. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8
  1214. | SNDRV_PCM_FMTBIT_U16_LE,
  1215. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  1216. .rate_min = 5500,
  1217. .rate_max = 48000,
  1218. .channels_min = 1,
  1219. .channels_max = 2,
  1220. .buffer_bytes_max = (64 * 1024),
  1221. .period_bytes_min = PAGE_SIZE >> 1,
  1222. .period_bytes_max = PAGE_SIZE << 8,
  1223. .periods_min = 2,
  1224. .periods_max = 64,
  1225. .fifo_size = 0,
  1226. };
  1227. static struct snd_pcm_hardware snd_riptide_capture = {
  1228. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1229. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1230. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
  1231. .formats =
  1232. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8
  1233. | SNDRV_PCM_FMTBIT_U16_LE,
  1234. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  1235. .rate_min = 5500,
  1236. .rate_max = 48000,
  1237. .channels_min = 1,
  1238. .channels_max = 2,
  1239. .buffer_bytes_max = (64 * 1024),
  1240. .period_bytes_min = PAGE_SIZE >> 1,
  1241. .period_bytes_max = PAGE_SIZE << 3,
  1242. .periods_min = 2,
  1243. .periods_max = 64,
  1244. .fifo_size = 0,
  1245. };
  1246. static snd_pcm_uframes_t snd_riptide_pointer(struct snd_pcm_substream
  1247. *substream)
  1248. {
  1249. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1250. struct snd_pcm_runtime *runtime = substream->runtime;
  1251. struct pcmhw *data = get_pcmhwdev(substream);
  1252. struct cmdif *cif = chip->cif;
  1253. union cmdret rptr = CMDRET_ZERO;
  1254. snd_pcm_uframes_t ret;
  1255. SEND_GPOS(cif, 0, data->id, &rptr);
  1256. if (data->size && runtime->period_size) {
  1257. snd_printdd
  1258. ("pointer stream %d position 0x%x(0x%x in buffer) bytes 0x%lx(0x%lx in period) frames\n",
  1259. data->id, rptr.retlongs[1], rptr.retlongs[1] % data->size,
  1260. bytes_to_frames(runtime, rptr.retlongs[1]),
  1261. bytes_to_frames(runtime,
  1262. rptr.retlongs[1]) % runtime->period_size);
  1263. if (rptr.retlongs[1] > data->pointer)
  1264. ret =
  1265. bytes_to_frames(runtime,
  1266. rptr.retlongs[1] % data->size);
  1267. else
  1268. ret =
  1269. bytes_to_frames(runtime,
  1270. data->pointer % data->size);
  1271. } else {
  1272. snd_printdd("stream not started or strange parms (%d %ld)\n",
  1273. data->size, runtime->period_size);
  1274. ret = bytes_to_frames(runtime, 0);
  1275. }
  1276. return ret;
  1277. }
  1278. static int snd_riptide_trigger(struct snd_pcm_substream *substream, int cmd)
  1279. {
  1280. int i, j;
  1281. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1282. struct pcmhw *data = get_pcmhwdev(substream);
  1283. struct cmdif *cif = chip->cif;
  1284. union cmdret rptr = CMDRET_ZERO;
  1285. spin_lock(&chip->lock);
  1286. switch (cmd) {
  1287. case SNDRV_PCM_TRIGGER_START:
  1288. case SNDRV_PCM_TRIGGER_RESUME:
  1289. if (!(data->state & ST_PLAY)) {
  1290. SEND_SSTR(cif, data->id, data->sgdlist.addr);
  1291. SET_AIE(cif->hwport);
  1292. data->state = ST_PLAY;
  1293. if (data->mixer != 0xff)
  1294. setmixer(cif, data->mixer, 0x7fff, 0x7fff);
  1295. chip->openstreams++;
  1296. data->oldpos = 0;
  1297. data->pointer = 0;
  1298. }
  1299. break;
  1300. case SNDRV_PCM_TRIGGER_STOP:
  1301. case SNDRV_PCM_TRIGGER_SUSPEND:
  1302. if (data->mixer != 0xff)
  1303. setmixer(cif, data->mixer, 0, 0);
  1304. setmixer(cif, data->mixer, 0, 0);
  1305. SEND_KSTR(cif, data->id);
  1306. data->state = ST_STOP;
  1307. chip->openstreams--;
  1308. j = 0;
  1309. do {
  1310. i = rptr.retlongs[1];
  1311. SEND_GPOS(cif, 0, data->id, &rptr);
  1312. udelay(1);
  1313. } while (i != rptr.retlongs[1] && j++ < MAX_WRITE_RETRY);
  1314. if (j >= MAX_WRITE_RETRY)
  1315. snd_printk(KERN_ERR "Riptide: Could not stop stream!");
  1316. break;
  1317. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1318. if (!(data->state & ST_PAUSE)) {
  1319. SEND_PSTR(cif, data->id);
  1320. data->state |= ST_PAUSE;
  1321. chip->openstreams--;
  1322. }
  1323. break;
  1324. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1325. if (data->state & ST_PAUSE) {
  1326. SEND_SSTR(cif, data->id, data->sgdlist.addr);
  1327. data->state &= ~ST_PAUSE;
  1328. chip->openstreams++;
  1329. }
  1330. break;
  1331. default:
  1332. spin_unlock(&chip->lock);
  1333. return -EINVAL;
  1334. }
  1335. spin_unlock(&chip->lock);
  1336. return 0;
  1337. }
  1338. static int snd_riptide_prepare(struct snd_pcm_substream *substream)
  1339. {
  1340. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1341. struct snd_pcm_runtime *runtime = substream->runtime;
  1342. struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
  1343. struct pcmhw *data = get_pcmhwdev(substream);
  1344. struct cmdif *cif = chip->cif;
  1345. unsigned char *lbuspath = NULL;
  1346. unsigned int rate, channels;
  1347. int err = 0;
  1348. snd_pcm_format_t format;
  1349. snd_assert(cif && data, return -EINVAL);
  1350. snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data->id,
  1351. runtime->channels, runtime->format, runtime->rate);
  1352. spin_lock_irq(&chip->lock);
  1353. channels = runtime->channels;
  1354. format = runtime->format;
  1355. rate = runtime->rate;
  1356. switch (channels) {
  1357. case 1:
  1358. if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE)
  1359. lbuspath = data->paths.noconv;
  1360. else
  1361. lbuspath = data->paths.mono;
  1362. break;
  1363. case 2:
  1364. if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE)
  1365. lbuspath = data->paths.noconv;
  1366. else
  1367. lbuspath = data->paths.stereo;
  1368. break;
  1369. }
  1370. snd_printdd("use sgdlist at 0x%p and buffer at 0x%p\n",
  1371. data->sgdlist.area, sgbuf);
  1372. if (data->sgdlist.area && sgbuf) {
  1373. unsigned int i, j, size, pages, f, pt, period;
  1374. struct sgd *c, *p = NULL;
  1375. size = frames_to_bytes(runtime, runtime->buffer_size);
  1376. period = frames_to_bytes(runtime, runtime->period_size);
  1377. f = PAGE_SIZE;
  1378. while ((size + (f >> 1) - 1) <= (f << 7) && (f << 1) > period)
  1379. f = f >> 1;
  1380. pages = (size + f - 1) / f;
  1381. data->size = size;
  1382. data->pages = pages;
  1383. snd_printdd
  1384. ("create sgd size: 0x%x pages %d of size 0x%x for period 0x%x\n",
  1385. size, pages, f, period);
  1386. pt = 0;
  1387. j = 0;
  1388. for (i = 0; i < pages; i++) {
  1389. c = &data->sgdbuf[i];
  1390. if (p)
  1391. p->dwNextLink = cpu_to_le32(data->sgdlist.addr +
  1392. (i *
  1393. sizeof(struct
  1394. sgd)));
  1395. c->dwNextLink = cpu_to_le32(data->sgdlist.addr);
  1396. c->dwSegPtrPhys =
  1397. cpu_to_le32(sgbuf->table[j].addr + pt);
  1398. pt = (pt + f) % PAGE_SIZE;
  1399. if (pt == 0)
  1400. j++;
  1401. c->dwSegLen = cpu_to_le32(f);
  1402. c->dwStat_Ctl =
  1403. cpu_to_le32(IEOB_ENABLE | IEOS_ENABLE |
  1404. IEOC_ENABLE);
  1405. p = c;
  1406. size -= f;
  1407. }
  1408. data->sgdbuf[i].dwSegLen = cpu_to_le32(size);
  1409. }
  1410. if (lbuspath && lbuspath != data->lbuspath) {
  1411. if (data->lbuspath)
  1412. freelbuspath(cif, data->source, data->lbuspath);
  1413. alloclbuspath(cif, data->source, lbuspath,
  1414. &data->mixer, data->intdec);
  1415. data->lbuspath = lbuspath;
  1416. data->rate = 0;
  1417. }
  1418. if (data->rate != rate || data->format != format ||
  1419. data->channels != channels) {
  1420. data->rate = rate;
  1421. data->format = format;
  1422. data->channels = channels;
  1423. if (setsampleformat
  1424. (cif, data->mixer, data->id, channels, format)
  1425. || setsamplerate(cif, data->intdec, rate))
  1426. err = -EIO;
  1427. }
  1428. spin_unlock_irq(&chip->lock);
  1429. return err;
  1430. }
  1431. static int
  1432. snd_riptide_hw_params(struct snd_pcm_substream *substream,
  1433. struct snd_pcm_hw_params *hw_params)
  1434. {
  1435. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1436. struct pcmhw *data = get_pcmhwdev(substream);
  1437. struct snd_dma_buffer *sgdlist = &data->sgdlist;
  1438. int err;
  1439. snd_printdd("hw params id %d (sgdlist: 0x%p 0x%lx %d)\n", data->id,
  1440. sgdlist->area, (unsigned long)sgdlist->addr,
  1441. (int)sgdlist->bytes);
  1442. if (sgdlist->area)
  1443. snd_dma_free_pages(sgdlist);
  1444. if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  1445. snd_dma_pci_data(chip->pci),
  1446. sizeof(struct sgd) * (DESC_MAX_MASK + 1),
  1447. sgdlist)) < 0) {
  1448. snd_printk(KERN_ERR "Riptide: failed to alloc %d dma bytes\n",
  1449. (int)sizeof(struct sgd) * (DESC_MAX_MASK + 1));
  1450. return err;
  1451. }
  1452. data->sgdbuf = (struct sgd *)sgdlist->area;
  1453. return snd_pcm_lib_malloc_pages(substream,
  1454. params_buffer_bytes(hw_params));
  1455. }
  1456. static int snd_riptide_hw_free(struct snd_pcm_substream *substream)
  1457. {
  1458. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1459. struct pcmhw *data = get_pcmhwdev(substream);
  1460. struct cmdif *cif = chip->cif;
  1461. if (cif && data) {
  1462. if (data->lbuspath)
  1463. freelbuspath(cif, data->source, data->lbuspath);
  1464. data->lbuspath = NULL;
  1465. data->source = 0xff;
  1466. data->intdec[0] = 0xff;
  1467. data->intdec[1] = 0xff;
  1468. if (data->sgdlist.area) {
  1469. snd_dma_free_pages(&data->sgdlist);
  1470. data->sgdlist.area = NULL;
  1471. }
  1472. }
  1473. return snd_pcm_lib_free_pages(substream);
  1474. }
  1475. static int snd_riptide_playback_open(struct snd_pcm_substream *substream)
  1476. {
  1477. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1478. struct snd_pcm_runtime *runtime = substream->runtime;
  1479. struct pcmhw *data;
  1480. int index = substream->number;
  1481. chip->playback_substream[index] = substream;
  1482. runtime->hw = snd_riptide_playback;
  1483. data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL);
  1484. data->paths = lbus_play_paths[index];
  1485. data->id = play_ids[index];
  1486. data->source = play_sources[index];
  1487. data->intdec[0] = 0xff;
  1488. data->intdec[1] = 0xff;
  1489. data->state = ST_STOP;
  1490. runtime->private_data = data;
  1491. return snd_pcm_hw_constraint_integer(runtime,
  1492. SNDRV_PCM_HW_PARAM_PERIODS);
  1493. }
  1494. static int snd_riptide_capture_open(struct snd_pcm_substream *substream)
  1495. {
  1496. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1497. struct snd_pcm_runtime *runtime = substream->runtime;
  1498. struct pcmhw *data;
  1499. chip->capture_substream = substream;
  1500. runtime->hw = snd_riptide_capture;
  1501. data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL);
  1502. data->paths = lbus_rec_path;
  1503. data->id = PADC;
  1504. data->source = ACLNK2PADC;
  1505. data->intdec[0] = 0xff;
  1506. data->intdec[1] = 0xff;
  1507. data->state = ST_STOP;
  1508. runtime->private_data = data;
  1509. return snd_pcm_hw_constraint_integer(runtime,
  1510. SNDRV_PCM_HW_PARAM_PERIODS);
  1511. }
  1512. static int snd_riptide_playback_close(struct snd_pcm_substream *substream)
  1513. {
  1514. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1515. struct pcmhw *data = get_pcmhwdev(substream);
  1516. int index = substream->number;
  1517. substream->runtime->private_data = NULL;
  1518. chip->playback_substream[index] = NULL;
  1519. kfree(data);
  1520. return 0;
  1521. }
  1522. static int snd_riptide_capture_close(struct snd_pcm_substream *substream)
  1523. {
  1524. struct snd_riptide *chip = snd_pcm_substream_chip(substream);
  1525. struct pcmhw *data = get_pcmhwdev(substream);
  1526. substream->runtime->private_data = NULL;
  1527. chip->capture_substream = NULL;
  1528. kfree(data);
  1529. return 0;
  1530. }
  1531. static struct snd_pcm_ops snd_riptide_playback_ops = {
  1532. .open = snd_riptide_playback_open,
  1533. .close = snd_riptide_playback_close,
  1534. .ioctl = snd_pcm_lib_ioctl,
  1535. .hw_params = snd_riptide_hw_params,
  1536. .hw_free = snd_riptide_hw_free,
  1537. .prepare = snd_riptide_prepare,
  1538. .page = snd_pcm_sgbuf_ops_page,
  1539. .trigger = snd_riptide_trigger,
  1540. .pointer = snd_riptide_pointer,
  1541. };
  1542. static struct snd_pcm_ops snd_riptide_capture_ops = {
  1543. .open = snd_riptide_capture_open,
  1544. .close = snd_riptide_capture_close,
  1545. .ioctl = snd_pcm_lib_ioctl,
  1546. .hw_params = snd_riptide_hw_params,
  1547. .hw_free = snd_riptide_hw_free,
  1548. .prepare = snd_riptide_prepare,
  1549. .page = snd_pcm_sgbuf_ops_page,
  1550. .trigger = snd_riptide_trigger,
  1551. .pointer = snd_riptide_pointer,
  1552. };
  1553. static int __devinit
  1554. snd_riptide_pcm(struct snd_riptide *chip, int device, struct snd_pcm **rpcm)
  1555. {
  1556. struct snd_pcm *pcm;
  1557. int err;
  1558. if (rpcm)
  1559. *rpcm = NULL;
  1560. if ((err =
  1561. snd_pcm_new(chip->card, "RIPTIDE", device, PLAYBACK_SUBSTREAMS, 1,
  1562. &pcm)) < 0)
  1563. return err;
  1564. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1565. &snd_riptide_playback_ops);
  1566. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  1567. &snd_riptide_capture_ops);
  1568. pcm->private_data = chip;
  1569. pcm->info_flags = 0;
  1570. strcpy(pcm->name, "RIPTIDE");
  1571. chip->pcm = pcm;
  1572. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  1573. snd_dma_pci_data(chip->pci),
  1574. 64 * 1024, 128 * 1024);
  1575. if (rpcm)
  1576. *rpcm = pcm;
  1577. return 0;
  1578. }
  1579. static irqreturn_t
  1580. snd_riptide_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1581. {
  1582. struct snd_riptide *chip = dev_id;
  1583. struct cmdif *cif = chip->cif;
  1584. if (cif) {
  1585. chip->received_irqs++;
  1586. if (IS_EOBIRQ(cif->hwport) || IS_EOSIRQ(cif->hwport) ||
  1587. IS_EOCIRQ(cif->hwport)) {
  1588. chip->handled_irqs++;
  1589. tasklet_hi_schedule(&chip->riptide_tq);
  1590. }
  1591. if (chip->rmidi && IS_MPUIRQ(cif->hwport)) {
  1592. chip->handled_irqs++;
  1593. snd_mpu401_uart_interrupt(irq,
  1594. chip->rmidi->private_data,
  1595. regs);
  1596. }
  1597. SET_AIACK(cif->hwport);
  1598. }
  1599. return IRQ_HANDLED;
  1600. }
  1601. static void
  1602. snd_riptide_codec_write(struct snd_ac97 *ac97, unsigned short reg,
  1603. unsigned short val)
  1604. {
  1605. struct snd_riptide *chip = ac97->private_data;
  1606. struct cmdif *cif = chip->cif;
  1607. union cmdret rptr = CMDRET_ZERO;
  1608. int i = 0;
  1609. snd_assert(cif, return);
  1610. snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg, val);
  1611. do {
  1612. SEND_SACR(cif, val, reg);
  1613. SEND_RACR(cif, reg, &rptr);
  1614. } while (rptr.retwords[1] != val && i++ < MAX_WRITE_RETRY);
  1615. if (i == MAX_WRITE_RETRY)
  1616. snd_printdd("Write AC97 reg failed\n");
  1617. }
  1618. static unsigned short snd_riptide_codec_read(struct snd_ac97 *ac97,
  1619. unsigned short reg)
  1620. {
  1621. struct snd_riptide *chip = ac97->private_data;
  1622. struct cmdif *cif = chip->cif;
  1623. union cmdret rptr = CMDRET_ZERO;
  1624. snd_assert(cif, return 0);
  1625. if (SEND_RACR(cif, reg, &rptr) != 0)
  1626. SEND_RACR(cif, reg, &rptr);
  1627. snd_printdd("Read AC97 reg 0x%x got 0x%x\n", reg, rptr.retwords[1]);
  1628. return rptr.retwords[1];
  1629. }
  1630. static int snd_riptide_initialize(struct snd_riptide *chip)
  1631. {
  1632. struct cmdif *cif;
  1633. unsigned int device_id;
  1634. int err;
  1635. snd_assert(chip, return -EINVAL);
  1636. cif = chip->cif;
  1637. if (!cif) {
  1638. if ((cif = kzalloc(sizeof(struct cmdif), GFP_KERNEL)) == NULL)
  1639. return -ENOMEM;
  1640. cif->hwport = (struct riptideport *)chip->port;
  1641. spin_lock_init(&cif->lock);
  1642. chip->cif = cif;
  1643. }
  1644. cif->is_reset = 0;
  1645. if ((err = riptide_reset(cif, chip)) != 0)
  1646. return err;
  1647. device_id = chip->device_id;
  1648. switch (device_id) {
  1649. case 0x4310:
  1650. case 0x4320:
  1651. case 0x4330:
  1652. snd_printdd("Modem enable?\n");
  1653. SEND_SETDPLL(cif);
  1654. break;
  1655. }
  1656. snd_printdd("Enabling MPU IRQs\n");
  1657. if (chip->rmidi)
  1658. SET_EMPUIRQ(cif->hwport);
  1659. return err;
  1660. }
  1661. static int snd_riptide_free(struct snd_riptide *chip)
  1662. {
  1663. struct cmdif *cif;
  1664. snd_assert(chip, return 0);
  1665. if ((cif = chip->cif)) {
  1666. SET_GRESET(cif->hwport);
  1667. udelay(100);
  1668. UNSET_GRESET(cif->hwport);
  1669. kfree(chip->cif);
  1670. }
  1671. if (chip->irq >= 0)
  1672. free_irq(chip->irq, chip);
  1673. if (chip->fw_entry)
  1674. release_firmware(chip->fw_entry);
  1675. release_and_free_resource(chip->res_port);
  1676. kfree(chip);
  1677. return 0;
  1678. }
  1679. static int snd_riptide_dev_free(struct snd_device *device)
  1680. {
  1681. struct snd_riptide *chip = device->device_data;
  1682. return snd_riptide_free(chip);
  1683. }
  1684. static int __devinit
  1685. snd_riptide_create(struct snd_card *card, struct pci_dev *pci,
  1686. struct snd_riptide **rchip)
  1687. {
  1688. struct snd_riptide *chip;
  1689. struct riptideport *hwport;
  1690. int err;
  1691. static struct snd_device_ops ops = {
  1692. .dev_free = snd_riptide_dev_free,
  1693. };
  1694. *rchip = NULL;
  1695. if ((err = pci_enable_device(pci)) < 0)
  1696. return err;
  1697. if (!(chip = kzalloc(sizeof(struct snd_riptide), GFP_KERNEL)))
  1698. return -ENOMEM;
  1699. spin_lock_init(&chip->lock);
  1700. chip->card = card;
  1701. chip->pci = pci;
  1702. chip->irq = -1;
  1703. chip->openstreams = 0;
  1704. chip->port = pci_resource_start(pci, 0);
  1705. chip->received_irqs = 0;
  1706. chip->handled_irqs = 0;
  1707. chip->cif = NULL;
  1708. tasklet_init(&chip->riptide_tq, riptide_handleirq, (unsigned long)chip);
  1709. if ((chip->res_port =
  1710. request_region(chip->port, 64, "RIPTIDE")) == NULL) {
  1711. snd_printk(KERN_ERR
  1712. "Riptide: unable to grab region 0x%lx-0x%lx\n",
  1713. chip->port, chip->port + 64 - 1);
  1714. snd_riptide_free(chip);
  1715. return -EBUSY;
  1716. }
  1717. hwport = (struct riptideport *)chip->port;
  1718. UNSET_AIE(hwport);
  1719. if (request_irq
  1720. (pci->irq, snd_riptide_interrupt, IRQF_DISABLED | IRQF_SHARED,
  1721. "RIPTIDE", chip)) {
  1722. snd_printk(KERN_ERR "Riptide: unable to grab IRQ %d\n",
  1723. pci->irq);
  1724. snd_riptide_free(chip);
  1725. return -EBUSY;
  1726. }
  1727. chip->irq = pci->irq;
  1728. chip->device_id = pci->device;
  1729. pci_set_master(pci);
  1730. if ((err = snd_riptide_initialize(chip)) < 0) {
  1731. snd_riptide_free(chip);
  1732. return err;
  1733. }
  1734. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  1735. snd_riptide_free(chip);
  1736. return err;
  1737. }
  1738. *rchip = chip;
  1739. return 0;
  1740. }
  1741. static void
  1742. snd_riptide_proc_read(struct snd_info_entry *entry,
  1743. struct snd_info_buffer *buffer)
  1744. {
  1745. struct snd_riptide *chip = entry->private_data;
  1746. struct pcmhw *data;
  1747. int i;
  1748. struct cmdif *cif = NULL;
  1749. unsigned char p[256];
  1750. unsigned short rval = 0, lval = 0;
  1751. unsigned int rate;
  1752. if (!chip)
  1753. return;
  1754. snd_iprintf(buffer, "%s\n\n", chip->card->longname);
  1755. snd_iprintf(buffer, "Device ID: 0x%x\nReceived IRQs: (%ld)%ld\nPorts:",
  1756. chip->device_id, chip->handled_irqs, chip->received_irqs);
  1757. for (i = 0; i < 64; i += 4)
  1758. snd_iprintf(buffer, "%c%02x: %08x",
  1759. (i % 16) ? ' ' : '\n', i, inl(chip->port + i));
  1760. if ((cif = chip->cif)) {
  1761. snd_iprintf(buffer,
  1762. "\nVersion: ASIC: %d CODEC: %d AUXDSP: %d PROG: %d",
  1763. chip->firmware.firmware.ASIC,
  1764. chip->firmware.firmware.CODEC,
  1765. chip->firmware.firmware.AUXDSP,
  1766. chip->firmware.firmware.PROG);
  1767. snd_iprintf(buffer, "\nDigital mixer:");
  1768. for (i = 0; i < 12; i++) {
  1769. getmixer(cif, i, &rval, &lval);
  1770. snd_iprintf(buffer, "\n %d: %d %d", i, rval, lval);
  1771. }
  1772. snd_iprintf(buffer,
  1773. "\nARM Commands num: %d failed: %d time: %d max: %d min: %d",
  1774. cif->cmdcnt, cif->errcnt,
  1775. cif->cmdtime, cif->cmdtimemax, cif->cmdtimemin);
  1776. }
  1777. snd_iprintf(buffer, "\nOpen streams %d:\n", chip->openstreams);
  1778. for (i = 0; i < PLAYBACK_SUBSTREAMS; i++) {
  1779. if (chip->playback_substream[i]
  1780. && chip->playback_substream[i]->runtime
  1781. && (data =
  1782. chip->playback_substream[i]->runtime->private_data)) {
  1783. snd_iprintf(buffer,
  1784. "stream: %d mixer: %d source: %d (%d,%d)\n",
  1785. data->id, data->mixer, data->source,
  1786. data->intdec[0], data->intdec[1]);
  1787. if (!(getsamplerate(cif, data->intdec, &rate)))
  1788. snd_iprintf(buffer, "rate: %d\n", rate);
  1789. }
  1790. }
  1791. if (chip->capture_substream
  1792. && chip->capture_substream->runtime
  1793. && (data = chip->capture_substream->runtime->private_data)) {
  1794. snd_iprintf(buffer,
  1795. "stream: %d mixer: %d source: %d (%d,%d)\n",
  1796. data->id, data->mixer,
  1797. data->source, data->intdec[0], data->intdec[1]);
  1798. if (!(getsamplerate(cif, data->intdec, &rate)))
  1799. snd_iprintf(buffer, "rate: %d\n", rate);
  1800. }
  1801. snd_iprintf(buffer, "Paths:\n");
  1802. i = getpaths(cif, p);
  1803. while (i--) {
  1804. snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]);
  1805. i--;
  1806. }
  1807. snd_iprintf(buffer, "\n");
  1808. }
  1809. static void __devinit snd_riptide_proc_init(struct snd_riptide *chip)
  1810. {
  1811. struct snd_info_entry *entry;
  1812. if (!snd_card_proc_new(chip->card, "riptide", &entry))
  1813. snd_info_set_text_ops(entry, chip, snd_riptide_proc_read);
  1814. }
  1815. static int __devinit snd_riptide_mixer(struct snd_riptide *chip)
  1816. {
  1817. struct snd_ac97_bus *pbus;
  1818. struct snd_ac97_template ac97;
  1819. int err = 0;
  1820. static struct snd_ac97_bus_ops ops = {
  1821. .write = snd_riptide_codec_write,
  1822. .read = snd_riptide_codec_read,
  1823. };
  1824. memset(&ac97, 0, sizeof(ac97));
  1825. ac97.private_data = chip;
  1826. ac97.scaps = AC97_SCAP_SKIP_MODEM;
  1827. if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
  1828. return err;
  1829. chip->ac97_bus = pbus;
  1830. ac97.pci = chip->pci;
  1831. if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0)
  1832. return err;
  1833. return err;
  1834. }
  1835. #ifdef SUPPORT_JOYSTICK
  1836. static int have_joystick;
  1837. static struct pci_dev *riptide_gameport_pci;
  1838. static struct gameport *riptide_gameport;
  1839. static int __devinit
  1840. snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id)
  1841. {
  1842. static int dev;
  1843. if (dev >= SNDRV_CARDS)
  1844. return -ENODEV;
  1845. if (!enable[dev]) {
  1846. dev++;
  1847. return -ENOENT;
  1848. }
  1849. if (joystick_port[dev]) {
  1850. riptide_gameport = gameport_allocate_port();
  1851. if (riptide_gameport) {
  1852. if (!request_region
  1853. (joystick_port[dev], 8, "Riptide gameport")) {
  1854. snd_printk(KERN_WARNING
  1855. "Riptide: cannot grab gameport 0x%x\n",
  1856. joystick_port[dev]);
  1857. gameport_free_port(riptide_gameport);
  1858. riptide_gameport = NULL;
  1859. } else {
  1860. riptide_gameport_pci = pci;
  1861. riptide_gameport->io = joystick_port[dev];
  1862. gameport_register_port(riptide_gameport);
  1863. }
  1864. }
  1865. }
  1866. dev++;
  1867. return 0;
  1868. }
  1869. static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci)
  1870. {
  1871. if (riptide_gameport) {
  1872. if (riptide_gameport_pci == pci) {
  1873. release_region(riptide_gameport->io, 8);
  1874. riptide_gameport_pci = NULL;
  1875. gameport_unregister_port(riptide_gameport);
  1876. riptide_gameport = NULL;
  1877. }
  1878. }
  1879. }
  1880. #endif
  1881. static int __devinit
  1882. snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  1883. {
  1884. static int dev;
  1885. struct snd_card *card;
  1886. struct snd_riptide *chip;
  1887. unsigned short addr;
  1888. int err = 0;
  1889. if (dev >= SNDRV_CARDS)
  1890. return -ENODEV;
  1891. if (!enable[dev]) {
  1892. dev++;
  1893. return -ENOENT;
  1894. }
  1895. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1896. if (card == NULL)
  1897. return -ENOMEM;
  1898. if ((err = snd_riptide_create(card, pci, &chip)) < 0) {
  1899. snd_card_free(card);
  1900. return err;
  1901. }
  1902. card->private_data = chip;
  1903. if ((err = snd_riptide_pcm(chip, 0, NULL)) < 0) {
  1904. snd_card_free(card);
  1905. return err;
  1906. }
  1907. if ((err = snd_riptide_mixer(chip)) < 0) {
  1908. snd_card_free(card);
  1909. return err;
  1910. }
  1911. pci_write_config_word(chip->pci, PCI_EXT_Legacy_Mask, LEGACY_ENABLE_ALL
  1912. | (opl3_port[dev] ? LEGACY_ENABLE_FM : 0)
  1913. #ifdef SUPPORT_JOYSTICK
  1914. | (joystick_port[dev] ? LEGACY_ENABLE_GAMEPORT :
  1915. 0)
  1916. #endif
  1917. | (mpu_port[dev]
  1918. ? (LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU) :
  1919. 0)
  1920. | ((chip->irq << 4) & 0xF0));
  1921. if ((addr = mpu_port[dev]) != 0) {
  1922. pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, addr);
  1923. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE,
  1924. addr, 0, chip->irq, 0,
  1925. &chip->rmidi)) < 0)
  1926. snd_printk(KERN_WARNING
  1927. "Riptide: Can't Allocate MPU at 0x%x\n",
  1928. addr);
  1929. else
  1930. chip->mpuaddr = addr;
  1931. }
  1932. if ((addr = opl3_port[dev]) != 0) {
  1933. pci_write_config_word(chip->pci, PCI_EXT_FM_Base, addr);
  1934. if ((err = snd_opl3_create(card, addr, addr + 2,
  1935. OPL3_HW_RIPTIDE, 0,
  1936. &chip->opl3)) < 0)
  1937. snd_printk(KERN_WARNING
  1938. "Riptide: Can't Allocate OPL3 at 0x%x\n",
  1939. addr);
  1940. else {
  1941. chip->opladdr = addr;
  1942. if ((err =
  1943. snd_opl3_hwdep_new(chip->opl3, 0, 1, NULL)) < 0)
  1944. snd_printk(KERN_WARNING
  1945. "Riptide: Can't Allocate OPL3-HWDEP\n");
  1946. }
  1947. }
  1948. #ifdef SUPPORT_JOYSTICK
  1949. if ((addr = joystick_port[dev]) != 0) {
  1950. pci_write_config_word(chip->pci, PCI_EXT_Game_Base, addr);
  1951. chip->gameaddr = addr;
  1952. }
  1953. #endif
  1954. strcpy(card->driver, "RIPTIDE");
  1955. strcpy(card->shortname, "Riptide");
  1956. #ifdef SUPPORT_JOYSTICK
  1957. snprintf(card->longname, sizeof(card->longname),
  1958. "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x",
  1959. card->shortname, chip->port, chip->irq, chip->mpuaddr,
  1960. chip->opladdr, chip->gameaddr);
  1961. #else
  1962. snprintf(card->longname, sizeof(card->longname),
  1963. "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x",
  1964. card->shortname, chip->port, chip->irq, chip->mpuaddr,
  1965. chip->opladdr);
  1966. #endif
  1967. snd_riptide_proc_init(chip);
  1968. if ((err = snd_card_register(card)) < 0) {
  1969. snd_card_free(card);
  1970. return err;
  1971. }
  1972. pci_set_drvdata(pci, card);
  1973. dev++;
  1974. return 0;
  1975. }
  1976. static void __devexit snd_card_riptide_remove(struct pci_dev *pci)
  1977. {
  1978. snd_card_free(pci_get_drvdata(pci));
  1979. pci_set_drvdata(pci, NULL);
  1980. }
  1981. static struct pci_driver driver = {
  1982. .name = "RIPTIDE",
  1983. .id_table = snd_riptide_ids,
  1984. .probe = snd_card_riptide_probe,
  1985. .remove = __devexit_p(snd_card_riptide_remove),
  1986. #ifdef CONFIG_PM
  1987. .suspend = riptide_suspend,
  1988. .resume = riptide_resume,
  1989. #endif
  1990. };
  1991. #ifdef SUPPORT_JOYSTICK
  1992. static struct pci_driver joystick_driver = {
  1993. .name = "Riptide Joystick",
  1994. .id_table = snd_riptide_joystick_ids,
  1995. .probe = snd_riptide_joystick_probe,
  1996. .remove = __devexit_p(snd_riptide_joystick_remove),
  1997. };
  1998. #endif
  1999. static int __init alsa_card_riptide_init(void)
  2000. {
  2001. int err;
  2002. if ((err = pci_register_driver(&driver)) < 0)
  2003. return err;
  2004. #if defined(SUPPORT_JOYSTICK)
  2005. if (pci_register_driver(&joystick_driver) < 0) {
  2006. have_joystick = 0;
  2007. snd_printk(KERN_INFO "no joystick found\n");
  2008. } else
  2009. have_joystick = 1;
  2010. #endif
  2011. return 0;
  2012. }
  2013. static void __exit alsa_card_riptide_exit(void)
  2014. {
  2015. pci_unregister_driver(&driver);
  2016. #if defined(SUPPORT_JOYSTICK)
  2017. if (have_joystick)
  2018. pci_unregister_driver(&joystick_driver);
  2019. #endif
  2020. }
  2021. module_init(alsa_card_riptide_init);
  2022. module_exit(alsa_card_riptide_exit);