maestro3.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  1. /*
  2. * Driver for ESS Maestro3/Allegro (ES1988) soundcards.
  3. * Copyright (c) 2000 by Zach Brown <zab@zabbo.net>
  4. * Takashi Iwai <tiwai@suse.de>
  5. *
  6. * Most of the hardware init stuffs are based on maestro3 driver for
  7. * OSS/Free by Zach Brown. Many thanks to Zach!
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. *
  24. * ChangeLog:
  25. * Aug. 27, 2001
  26. * - Fixed deadlock on capture
  27. * - Added Canyon3D-2 support by Rob Riggs <rob@pangalactic.org>
  28. *
  29. */
  30. #define CARD_NAME "ESS Maestro3/Allegro/Canyon3D-2"
  31. #define DRIVER_NAME "Maestro3"
  32. #include <asm/io.h>
  33. #include <linux/delay.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/init.h>
  36. #include <linux/pci.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/slab.h>
  39. #include <linux/vmalloc.h>
  40. #include <linux/moduleparam.h>
  41. #include <linux/firmware.h>
  42. #include <linux/input.h>
  43. #include <sound/core.h>
  44. #include <sound/info.h>
  45. #include <sound/control.h>
  46. #include <sound/pcm.h>
  47. #include <sound/mpu401.h>
  48. #include <sound/ac97_codec.h>
  49. #include <sound/initval.h>
  50. #include <asm/byteorder.h>
  51. MODULE_AUTHOR("Zach Brown <zab@zabbo.net>, Takashi Iwai <tiwai@suse.de>");
  52. MODULE_DESCRIPTION("ESS Maestro3 PCI");
  53. MODULE_LICENSE("GPL");
  54. MODULE_SUPPORTED_DEVICE("{{ESS,Maestro3 PCI},"
  55. "{ESS,ES1988},"
  56. "{ESS,Allegro PCI},"
  57. "{ESS,Allegro-1 PCI},"
  58. "{ESS,Canyon3D-2/LE PCI}}");
  59. MODULE_FIRMWARE("ess/maestro3_assp_kernel.fw");
  60. MODULE_FIRMWARE("ess/maestro3_assp_minisrc.fw");
  61. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  62. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  63. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* all enabled */
  64. static int external_amp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  65. static int amp_gpio[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
  66. module_param_array(index, int, NULL, 0444);
  67. MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
  68. module_param_array(id, charp, NULL, 0444);
  69. MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
  70. module_param_array(enable, bool, NULL, 0444);
  71. MODULE_PARM_DESC(enable, "Enable this soundcard.");
  72. module_param_array(external_amp, bool, NULL, 0444);
  73. MODULE_PARM_DESC(external_amp, "Enable external amp for " CARD_NAME " soundcard.");
  74. module_param_array(amp_gpio, int, NULL, 0444);
  75. MODULE_PARM_DESC(amp_gpio, "GPIO pin number for external amp. (default = -1)");
  76. #define MAX_PLAYBACKS 2
  77. #define MAX_CAPTURES 1
  78. #define NR_DSPS (MAX_PLAYBACKS + MAX_CAPTURES)
  79. /*
  80. * maestro3 registers
  81. */
  82. /* Allegro PCI configuration registers */
  83. #define PCI_LEGACY_AUDIO_CTRL 0x40
  84. #define SOUND_BLASTER_ENABLE 0x00000001
  85. #define FM_SYNTHESIS_ENABLE 0x00000002
  86. #define GAME_PORT_ENABLE 0x00000004
  87. #define MPU401_IO_ENABLE 0x00000008
  88. #define MPU401_IRQ_ENABLE 0x00000010
  89. #define ALIAS_10BIT_IO 0x00000020
  90. #define SB_DMA_MASK 0x000000C0
  91. #define SB_DMA_0 0x00000040
  92. #define SB_DMA_1 0x00000040
  93. #define SB_DMA_R 0x00000080
  94. #define SB_DMA_3 0x000000C0
  95. #define SB_IRQ_MASK 0x00000700
  96. #define SB_IRQ_5 0x00000000
  97. #define SB_IRQ_7 0x00000100
  98. #define SB_IRQ_9 0x00000200
  99. #define SB_IRQ_10 0x00000300
  100. #define MIDI_IRQ_MASK 0x00003800
  101. #define SERIAL_IRQ_ENABLE 0x00004000
  102. #define DISABLE_LEGACY 0x00008000
  103. #define PCI_ALLEGRO_CONFIG 0x50
  104. #define SB_ADDR_240 0x00000004
  105. #define MPU_ADDR_MASK 0x00000018
  106. #define MPU_ADDR_330 0x00000000
  107. #define MPU_ADDR_300 0x00000008
  108. #define MPU_ADDR_320 0x00000010
  109. #define MPU_ADDR_340 0x00000018
  110. #define USE_PCI_TIMING 0x00000040
  111. #define POSTED_WRITE_ENABLE 0x00000080
  112. #define DMA_POLICY_MASK 0x00000700
  113. #define DMA_DDMA 0x00000000
  114. #define DMA_TDMA 0x00000100
  115. #define DMA_PCPCI 0x00000200
  116. #define DMA_WBDMA16 0x00000400
  117. #define DMA_WBDMA4 0x00000500
  118. #define DMA_WBDMA2 0x00000600
  119. #define DMA_WBDMA1 0x00000700
  120. #define DMA_SAFE_GUARD 0x00000800
  121. #define HI_PERF_GP_ENABLE 0x00001000
  122. #define PIC_SNOOP_MODE_0 0x00002000
  123. #define PIC_SNOOP_MODE_1 0x00004000
  124. #define SOUNDBLASTER_IRQ_MASK 0x00008000
  125. #define RING_IN_ENABLE 0x00010000
  126. #define SPDIF_TEST_MODE 0x00020000
  127. #define CLK_MULT_MODE_SELECT_2 0x00040000
  128. #define EEPROM_WRITE_ENABLE 0x00080000
  129. #define CODEC_DIR_IN 0x00100000
  130. #define HV_BUTTON_FROM_GD 0x00200000
  131. #define REDUCED_DEBOUNCE 0x00400000
  132. #define HV_CTRL_ENABLE 0x00800000
  133. #define SPDIF_ENABLE 0x01000000
  134. #define CLK_DIV_SELECT 0x06000000
  135. #define CLK_DIV_BY_48 0x00000000
  136. #define CLK_DIV_BY_49 0x02000000
  137. #define CLK_DIV_BY_50 0x04000000
  138. #define CLK_DIV_RESERVED 0x06000000
  139. #define PM_CTRL_ENABLE 0x08000000
  140. #define CLK_MULT_MODE_SELECT 0x30000000
  141. #define CLK_MULT_MODE_SHIFT 28
  142. #define CLK_MULT_MODE_0 0x00000000
  143. #define CLK_MULT_MODE_1 0x10000000
  144. #define CLK_MULT_MODE_2 0x20000000
  145. #define CLK_MULT_MODE_3 0x30000000
  146. #define INT_CLK_SELECT 0x40000000
  147. #define INT_CLK_MULT_RESET 0x80000000
  148. /* M3 */
  149. #define INT_CLK_SRC_NOT_PCI 0x00100000
  150. #define INT_CLK_MULT_ENABLE 0x80000000
  151. #define PCI_ACPI_CONTROL 0x54
  152. #define PCI_ACPI_D0 0x00000000
  153. #define PCI_ACPI_D1 0xB4F70000
  154. #define PCI_ACPI_D2 0xB4F7B4F7
  155. #define PCI_USER_CONFIG 0x58
  156. #define EXT_PCI_MASTER_ENABLE 0x00000001
  157. #define SPDIF_OUT_SELECT 0x00000002
  158. #define TEST_PIN_DIR_CTRL 0x00000004
  159. #define AC97_CODEC_TEST 0x00000020
  160. #define TRI_STATE_BUFFER 0x00000080
  161. #define IN_CLK_12MHZ_SELECT 0x00000100
  162. #define MULTI_FUNC_DISABLE 0x00000200
  163. #define EXT_MASTER_PAIR_SEL 0x00000400
  164. #define PCI_MASTER_SUPPORT 0x00000800
  165. #define STOP_CLOCK_ENABLE 0x00001000
  166. #define EAPD_DRIVE_ENABLE 0x00002000
  167. #define REQ_TRI_STATE_ENABLE 0x00004000
  168. #define REQ_LOW_ENABLE 0x00008000
  169. #define MIDI_1_ENABLE 0x00010000
  170. #define MIDI_2_ENABLE 0x00020000
  171. #define SB_AUDIO_SYNC 0x00040000
  172. #define HV_CTRL_TEST 0x00100000
  173. #define SOUNDBLASTER_TEST 0x00400000
  174. #define PCI_USER_CONFIG_C 0x5C
  175. #define PCI_DDMA_CTRL 0x60
  176. #define DDMA_ENABLE 0x00000001
  177. /* Allegro registers */
  178. #define HOST_INT_CTRL 0x18
  179. #define SB_INT_ENABLE 0x0001
  180. #define MPU401_INT_ENABLE 0x0002
  181. #define ASSP_INT_ENABLE 0x0010
  182. #define RING_INT_ENABLE 0x0020
  183. #define HV_INT_ENABLE 0x0040
  184. #define CLKRUN_GEN_ENABLE 0x0100
  185. #define HV_CTRL_TO_PME 0x0400
  186. #define SOFTWARE_RESET_ENABLE 0x8000
  187. /*
  188. * should be using the above defines, probably.
  189. */
  190. #define REGB_ENABLE_RESET 0x01
  191. #define REGB_STOP_CLOCK 0x10
  192. #define HOST_INT_STATUS 0x1A
  193. #define SB_INT_PENDING 0x01
  194. #define MPU401_INT_PENDING 0x02
  195. #define ASSP_INT_PENDING 0x10
  196. #define RING_INT_PENDING 0x20
  197. #define HV_INT_PENDING 0x40
  198. #define HARDWARE_VOL_CTRL 0x1B
  199. #define SHADOW_MIX_REG_VOICE 0x1C
  200. #define HW_VOL_COUNTER_VOICE 0x1D
  201. #define SHADOW_MIX_REG_MASTER 0x1E
  202. #define HW_VOL_COUNTER_MASTER 0x1F
  203. #define CODEC_COMMAND 0x30
  204. #define CODEC_READ_B 0x80
  205. #define CODEC_STATUS 0x30
  206. #define CODEC_BUSY_B 0x01
  207. #define CODEC_DATA 0x32
  208. #define RING_BUS_CTRL_A 0x36
  209. #define RAC_PME_ENABLE 0x0100
  210. #define RAC_SDFS_ENABLE 0x0200
  211. #define LAC_PME_ENABLE 0x0400
  212. #define LAC_SDFS_ENABLE 0x0800
  213. #define SERIAL_AC_LINK_ENABLE 0x1000
  214. #define IO_SRAM_ENABLE 0x2000
  215. #define IIS_INPUT_ENABLE 0x8000
  216. #define RING_BUS_CTRL_B 0x38
  217. #define SECOND_CODEC_ID_MASK 0x0003
  218. #define SPDIF_FUNC_ENABLE 0x0010
  219. #define SECOND_AC_ENABLE 0x0020
  220. #define SB_MODULE_INTF_ENABLE 0x0040
  221. #define SSPE_ENABLE 0x0040
  222. #define M3I_DOCK_ENABLE 0x0080
  223. #define SDO_OUT_DEST_CTRL 0x3A
  224. #define COMMAND_ADDR_OUT 0x0003
  225. #define PCM_LR_OUT_LOCAL 0x0000
  226. #define PCM_LR_OUT_REMOTE 0x0004
  227. #define PCM_LR_OUT_MUTE 0x0008
  228. #define PCM_LR_OUT_BOTH 0x000C
  229. #define LINE1_DAC_OUT_LOCAL 0x0000
  230. #define LINE1_DAC_OUT_REMOTE 0x0010
  231. #define LINE1_DAC_OUT_MUTE 0x0020
  232. #define LINE1_DAC_OUT_BOTH 0x0030
  233. #define PCM_CLS_OUT_LOCAL 0x0000
  234. #define PCM_CLS_OUT_REMOTE 0x0040
  235. #define PCM_CLS_OUT_MUTE 0x0080
  236. #define PCM_CLS_OUT_BOTH 0x00C0
  237. #define PCM_RLF_OUT_LOCAL 0x0000
  238. #define PCM_RLF_OUT_REMOTE 0x0100
  239. #define PCM_RLF_OUT_MUTE 0x0200
  240. #define PCM_RLF_OUT_BOTH 0x0300
  241. #define LINE2_DAC_OUT_LOCAL 0x0000
  242. #define LINE2_DAC_OUT_REMOTE 0x0400
  243. #define LINE2_DAC_OUT_MUTE 0x0800
  244. #define LINE2_DAC_OUT_BOTH 0x0C00
  245. #define HANDSET_OUT_LOCAL 0x0000
  246. #define HANDSET_OUT_REMOTE 0x1000
  247. #define HANDSET_OUT_MUTE 0x2000
  248. #define HANDSET_OUT_BOTH 0x3000
  249. #define IO_CTRL_OUT_LOCAL 0x0000
  250. #define IO_CTRL_OUT_REMOTE 0x4000
  251. #define IO_CTRL_OUT_MUTE 0x8000
  252. #define IO_CTRL_OUT_BOTH 0xC000
  253. #define SDO_IN_DEST_CTRL 0x3C
  254. #define STATUS_ADDR_IN 0x0003
  255. #define PCM_LR_IN_LOCAL 0x0000
  256. #define PCM_LR_IN_REMOTE 0x0004
  257. #define PCM_LR_RESERVED 0x0008
  258. #define PCM_LR_IN_BOTH 0x000C
  259. #define LINE1_ADC_IN_LOCAL 0x0000
  260. #define LINE1_ADC_IN_REMOTE 0x0010
  261. #define LINE1_ADC_IN_MUTE 0x0020
  262. #define MIC_ADC_IN_LOCAL 0x0000
  263. #define MIC_ADC_IN_REMOTE 0x0040
  264. #define MIC_ADC_IN_MUTE 0x0080
  265. #define LINE2_DAC_IN_LOCAL 0x0000
  266. #define LINE2_DAC_IN_REMOTE 0x0400
  267. #define LINE2_DAC_IN_MUTE 0x0800
  268. #define HANDSET_IN_LOCAL 0x0000
  269. #define HANDSET_IN_REMOTE 0x1000
  270. #define HANDSET_IN_MUTE 0x2000
  271. #define IO_STATUS_IN_LOCAL 0x0000
  272. #define IO_STATUS_IN_REMOTE 0x4000
  273. #define SPDIF_IN_CTRL 0x3E
  274. #define SPDIF_IN_ENABLE 0x0001
  275. #define GPIO_DATA 0x60
  276. #define GPIO_DATA_MASK 0x0FFF
  277. #define GPIO_HV_STATUS 0x3000
  278. #define GPIO_PME_STATUS 0x4000
  279. #define GPIO_MASK 0x64
  280. #define GPIO_DIRECTION 0x68
  281. #define GPO_PRIMARY_AC97 0x0001
  282. #define GPI_LINEOUT_SENSE 0x0004
  283. #define GPO_SECONDARY_AC97 0x0008
  284. #define GPI_VOL_DOWN 0x0010
  285. #define GPI_VOL_UP 0x0020
  286. #define GPI_IIS_CLK 0x0040
  287. #define GPI_IIS_LRCLK 0x0080
  288. #define GPI_IIS_DATA 0x0100
  289. #define GPI_DOCKING_STATUS 0x0100
  290. #define GPI_HEADPHONE_SENSE 0x0200
  291. #define GPO_EXT_AMP_SHUTDOWN 0x1000
  292. #define GPO_EXT_AMP_M3 1 /* default m3 amp */
  293. #define GPO_EXT_AMP_ALLEGRO 8 /* default allegro amp */
  294. /* M3 */
  295. #define GPO_M3_EXT_AMP_SHUTDN 0x0002
  296. #define ASSP_INDEX_PORT 0x80
  297. #define ASSP_MEMORY_PORT 0x82
  298. #define ASSP_DATA_PORT 0x84
  299. #define MPU401_DATA_PORT 0x98
  300. #define MPU401_STATUS_PORT 0x99
  301. #define CLK_MULT_DATA_PORT 0x9C
  302. #define ASSP_CONTROL_A 0xA2
  303. #define ASSP_0_WS_ENABLE 0x01
  304. #define ASSP_CTRL_A_RESERVED1 0x02
  305. #define ASSP_CTRL_A_RESERVED2 0x04
  306. #define ASSP_CLK_49MHZ_SELECT 0x08
  307. #define FAST_PLU_ENABLE 0x10
  308. #define ASSP_CTRL_A_RESERVED3 0x20
  309. #define DSP_CLK_36MHZ_SELECT 0x40
  310. #define ASSP_CONTROL_B 0xA4
  311. #define RESET_ASSP 0x00
  312. #define RUN_ASSP 0x01
  313. #define ENABLE_ASSP_CLOCK 0x00
  314. #define STOP_ASSP_CLOCK 0x10
  315. #define RESET_TOGGLE 0x40
  316. #define ASSP_CONTROL_C 0xA6
  317. #define ASSP_HOST_INT_ENABLE 0x01
  318. #define FM_ADDR_REMAP_DISABLE 0x02
  319. #define HOST_WRITE_PORT_ENABLE 0x08
  320. #define ASSP_HOST_INT_STATUS 0xAC
  321. #define DSP2HOST_REQ_PIORECORD 0x01
  322. #define DSP2HOST_REQ_I2SRATE 0x02
  323. #define DSP2HOST_REQ_TIMER 0x04
  324. /* AC97 registers */
  325. /* XXX fix this crap up */
  326. /*#define AC97_RESET 0x00*/
  327. #define AC97_VOL_MUTE_B 0x8000
  328. #define AC97_VOL_M 0x1F
  329. #define AC97_LEFT_VOL_S 8
  330. #define AC97_MASTER_VOL 0x02
  331. #define AC97_LINE_LEVEL_VOL 0x04
  332. #define AC97_MASTER_MONO_VOL 0x06
  333. #define AC97_PC_BEEP_VOL 0x0A
  334. #define AC97_PC_BEEP_VOL_M 0x0F
  335. #define AC97_SROUND_MASTER_VOL 0x38
  336. #define AC97_PC_BEEP_VOL_S 1
  337. /*#define AC97_PHONE_VOL 0x0C
  338. #define AC97_MIC_VOL 0x0E*/
  339. #define AC97_MIC_20DB_ENABLE 0x40
  340. /*#define AC97_LINEIN_VOL 0x10
  341. #define AC97_CD_VOL 0x12
  342. #define AC97_VIDEO_VOL 0x14
  343. #define AC97_AUX_VOL 0x16*/
  344. #define AC97_PCM_OUT_VOL 0x18
  345. /*#define AC97_RECORD_SELECT 0x1A*/
  346. #define AC97_RECORD_MIC 0x00
  347. #define AC97_RECORD_CD 0x01
  348. #define AC97_RECORD_VIDEO 0x02
  349. #define AC97_RECORD_AUX 0x03
  350. #define AC97_RECORD_MONO_MUX 0x02
  351. #define AC97_RECORD_DIGITAL 0x03
  352. #define AC97_RECORD_LINE 0x04
  353. #define AC97_RECORD_STEREO 0x05
  354. #define AC97_RECORD_MONO 0x06
  355. #define AC97_RECORD_PHONE 0x07
  356. /*#define AC97_RECORD_GAIN 0x1C*/
  357. #define AC97_RECORD_VOL_M 0x0F
  358. /*#define AC97_GENERAL_PURPOSE 0x20*/
  359. #define AC97_POWER_DOWN_CTRL 0x26
  360. #define AC97_ADC_READY 0x0001
  361. #define AC97_DAC_READY 0x0002
  362. #define AC97_ANALOG_READY 0x0004
  363. #define AC97_VREF_ON 0x0008
  364. #define AC97_PR0 0x0100
  365. #define AC97_PR1 0x0200
  366. #define AC97_PR2 0x0400
  367. #define AC97_PR3 0x0800
  368. #define AC97_PR4 0x1000
  369. #define AC97_RESERVED1 0x28
  370. #define AC97_VENDOR_TEST 0x5A
  371. #define AC97_CLOCK_DELAY 0x5C
  372. #define AC97_LINEOUT_MUX_SEL 0x0001
  373. #define AC97_MONO_MUX_SEL 0x0002
  374. #define AC97_CLOCK_DELAY_SEL 0x1F
  375. #define AC97_DAC_CDS_SHIFT 6
  376. #define AC97_ADC_CDS_SHIFT 11
  377. #define AC97_MULTI_CHANNEL_SEL 0x74
  378. /*#define AC97_VENDOR_ID1 0x7C
  379. #define AC97_VENDOR_ID2 0x7E*/
  380. /*
  381. * ASSP control regs
  382. */
  383. #define DSP_PORT_TIMER_COUNT 0x06
  384. #define DSP_PORT_MEMORY_INDEX 0x80
  385. #define DSP_PORT_MEMORY_TYPE 0x82
  386. #define MEMTYPE_INTERNAL_CODE 0x0002
  387. #define MEMTYPE_INTERNAL_DATA 0x0003
  388. #define MEMTYPE_MASK 0x0003
  389. #define DSP_PORT_MEMORY_DATA 0x84
  390. #define DSP_PORT_CONTROL_REG_A 0xA2
  391. #define DSP_PORT_CONTROL_REG_B 0xA4
  392. #define DSP_PORT_CONTROL_REG_C 0xA6
  393. #define REV_A_CODE_MEMORY_BEGIN 0x0000
  394. #define REV_A_CODE_MEMORY_END 0x0FFF
  395. #define REV_A_CODE_MEMORY_UNIT_LENGTH 0x0040
  396. #define REV_A_CODE_MEMORY_LENGTH (REV_A_CODE_MEMORY_END - REV_A_CODE_MEMORY_BEGIN + 1)
  397. #define REV_B_CODE_MEMORY_BEGIN 0x0000
  398. #define REV_B_CODE_MEMORY_END 0x0BFF
  399. #define REV_B_CODE_MEMORY_UNIT_LENGTH 0x0040
  400. #define REV_B_CODE_MEMORY_LENGTH (REV_B_CODE_MEMORY_END - REV_B_CODE_MEMORY_BEGIN + 1)
  401. #define REV_A_DATA_MEMORY_BEGIN 0x1000
  402. #define REV_A_DATA_MEMORY_END 0x2FFF
  403. #define REV_A_DATA_MEMORY_UNIT_LENGTH 0x0080
  404. #define REV_A_DATA_MEMORY_LENGTH (REV_A_DATA_MEMORY_END - REV_A_DATA_MEMORY_BEGIN + 1)
  405. #define REV_B_DATA_MEMORY_BEGIN 0x1000
  406. #define REV_B_DATA_MEMORY_END 0x2BFF
  407. #define REV_B_DATA_MEMORY_UNIT_LENGTH 0x0080
  408. #define REV_B_DATA_MEMORY_LENGTH (REV_B_DATA_MEMORY_END - REV_B_DATA_MEMORY_BEGIN + 1)
  409. #define NUM_UNITS_KERNEL_CODE 16
  410. #define NUM_UNITS_KERNEL_DATA 2
  411. #define NUM_UNITS_KERNEL_CODE_WITH_HSP 16
  412. #define NUM_UNITS_KERNEL_DATA_WITH_HSP 5
  413. /*
  414. * Kernel data layout
  415. */
  416. #define DP_SHIFT_COUNT 7
  417. #define KDATA_BASE_ADDR 0x1000
  418. #define KDATA_BASE_ADDR2 0x1080
  419. #define KDATA_TASK0 (KDATA_BASE_ADDR + 0x0000)
  420. #define KDATA_TASK1 (KDATA_BASE_ADDR + 0x0001)
  421. #define KDATA_TASK2 (KDATA_BASE_ADDR + 0x0002)
  422. #define KDATA_TASK3 (KDATA_BASE_ADDR + 0x0003)
  423. #define KDATA_TASK4 (KDATA_BASE_ADDR + 0x0004)
  424. #define KDATA_TASK5 (KDATA_BASE_ADDR + 0x0005)
  425. #define KDATA_TASK6 (KDATA_BASE_ADDR + 0x0006)
  426. #define KDATA_TASK7 (KDATA_BASE_ADDR + 0x0007)
  427. #define KDATA_TASK_ENDMARK (KDATA_BASE_ADDR + 0x0008)
  428. #define KDATA_CURRENT_TASK (KDATA_BASE_ADDR + 0x0009)
  429. #define KDATA_TASK_SWITCH (KDATA_BASE_ADDR + 0x000A)
  430. #define KDATA_INSTANCE0_POS3D (KDATA_BASE_ADDR + 0x000B)
  431. #define KDATA_INSTANCE1_POS3D (KDATA_BASE_ADDR + 0x000C)
  432. #define KDATA_INSTANCE2_POS3D (KDATA_BASE_ADDR + 0x000D)
  433. #define KDATA_INSTANCE3_POS3D (KDATA_BASE_ADDR + 0x000E)
  434. #define KDATA_INSTANCE4_POS3D (KDATA_BASE_ADDR + 0x000F)
  435. #define KDATA_INSTANCE5_POS3D (KDATA_BASE_ADDR + 0x0010)
  436. #define KDATA_INSTANCE6_POS3D (KDATA_BASE_ADDR + 0x0011)
  437. #define KDATA_INSTANCE7_POS3D (KDATA_BASE_ADDR + 0x0012)
  438. #define KDATA_INSTANCE8_POS3D (KDATA_BASE_ADDR + 0x0013)
  439. #define KDATA_INSTANCE_POS3D_ENDMARK (KDATA_BASE_ADDR + 0x0014)
  440. #define KDATA_INSTANCE0_SPKVIRT (KDATA_BASE_ADDR + 0x0015)
  441. #define KDATA_INSTANCE_SPKVIRT_ENDMARK (KDATA_BASE_ADDR + 0x0016)
  442. #define KDATA_INSTANCE0_SPDIF (KDATA_BASE_ADDR + 0x0017)
  443. #define KDATA_INSTANCE_SPDIF_ENDMARK (KDATA_BASE_ADDR + 0x0018)
  444. #define KDATA_INSTANCE0_MODEM (KDATA_BASE_ADDR + 0x0019)
  445. #define KDATA_INSTANCE_MODEM_ENDMARK (KDATA_BASE_ADDR + 0x001A)
  446. #define KDATA_INSTANCE0_SRC (KDATA_BASE_ADDR + 0x001B)
  447. #define KDATA_INSTANCE1_SRC (KDATA_BASE_ADDR + 0x001C)
  448. #define KDATA_INSTANCE_SRC_ENDMARK (KDATA_BASE_ADDR + 0x001D)
  449. #define KDATA_INSTANCE0_MINISRC (KDATA_BASE_ADDR + 0x001E)
  450. #define KDATA_INSTANCE1_MINISRC (KDATA_BASE_ADDR + 0x001F)
  451. #define KDATA_INSTANCE2_MINISRC (KDATA_BASE_ADDR + 0x0020)
  452. #define KDATA_INSTANCE3_MINISRC (KDATA_BASE_ADDR + 0x0021)
  453. #define KDATA_INSTANCE_MINISRC_ENDMARK (KDATA_BASE_ADDR + 0x0022)
  454. #define KDATA_INSTANCE0_CPYTHRU (KDATA_BASE_ADDR + 0x0023)
  455. #define KDATA_INSTANCE1_CPYTHRU (KDATA_BASE_ADDR + 0x0024)
  456. #define KDATA_INSTANCE_CPYTHRU_ENDMARK (KDATA_BASE_ADDR + 0x0025)
  457. #define KDATA_CURRENT_DMA (KDATA_BASE_ADDR + 0x0026)
  458. #define KDATA_DMA_SWITCH (KDATA_BASE_ADDR + 0x0027)
  459. #define KDATA_DMA_ACTIVE (KDATA_BASE_ADDR + 0x0028)
  460. #define KDATA_DMA_XFER0 (KDATA_BASE_ADDR + 0x0029)
  461. #define KDATA_DMA_XFER1 (KDATA_BASE_ADDR + 0x002A)
  462. #define KDATA_DMA_XFER2 (KDATA_BASE_ADDR + 0x002B)
  463. #define KDATA_DMA_XFER3 (KDATA_BASE_ADDR + 0x002C)
  464. #define KDATA_DMA_XFER4 (KDATA_BASE_ADDR + 0x002D)
  465. #define KDATA_DMA_XFER5 (KDATA_BASE_ADDR + 0x002E)
  466. #define KDATA_DMA_XFER6 (KDATA_BASE_ADDR + 0x002F)
  467. #define KDATA_DMA_XFER7 (KDATA_BASE_ADDR + 0x0030)
  468. #define KDATA_DMA_XFER8 (KDATA_BASE_ADDR + 0x0031)
  469. #define KDATA_DMA_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0032)
  470. #define KDATA_I2S_SAMPLE_COUNT (KDATA_BASE_ADDR + 0x0033)
  471. #define KDATA_I2S_INT_METER (KDATA_BASE_ADDR + 0x0034)
  472. #define KDATA_I2S_ACTIVE (KDATA_BASE_ADDR + 0x0035)
  473. #define KDATA_TIMER_COUNT_RELOAD (KDATA_BASE_ADDR + 0x0036)
  474. #define KDATA_TIMER_COUNT_CURRENT (KDATA_BASE_ADDR + 0x0037)
  475. #define KDATA_HALT_SYNCH_CLIENT (KDATA_BASE_ADDR + 0x0038)
  476. #define KDATA_HALT_SYNCH_DMA (KDATA_BASE_ADDR + 0x0039)
  477. #define KDATA_HALT_ACKNOWLEDGE (KDATA_BASE_ADDR + 0x003A)
  478. #define KDATA_ADC1_XFER0 (KDATA_BASE_ADDR + 0x003B)
  479. #define KDATA_ADC1_XFER_ENDMARK (KDATA_BASE_ADDR + 0x003C)
  480. #define KDATA_ADC1_LEFT_VOLUME (KDATA_BASE_ADDR + 0x003D)
  481. #define KDATA_ADC1_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x003E)
  482. #define KDATA_ADC1_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x003F)
  483. #define KDATA_ADC1_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0040)
  484. #define KDATA_ADC2_XFER0 (KDATA_BASE_ADDR + 0x0041)
  485. #define KDATA_ADC2_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0042)
  486. #define KDATA_ADC2_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0043)
  487. #define KDATA_ADC2_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x0044)
  488. #define KDATA_ADC2_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x0045)
  489. #define KDATA_ADC2_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0046)
  490. #define KDATA_CD_XFER0 (KDATA_BASE_ADDR + 0x0047)
  491. #define KDATA_CD_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0048)
  492. #define KDATA_CD_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0049)
  493. #define KDATA_CD_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x004A)
  494. #define KDATA_CD_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x004B)
  495. #define KDATA_CD_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x004C)
  496. #define KDATA_MIC_XFER0 (KDATA_BASE_ADDR + 0x004D)
  497. #define KDATA_MIC_XFER_ENDMARK (KDATA_BASE_ADDR + 0x004E)
  498. #define KDATA_MIC_VOLUME (KDATA_BASE_ADDR + 0x004F)
  499. #define KDATA_MIC_SUR_VOL (KDATA_BASE_ADDR + 0x0050)
  500. #define KDATA_I2S_XFER0 (KDATA_BASE_ADDR + 0x0051)
  501. #define KDATA_I2S_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0052)
  502. #define KDATA_CHI_XFER0 (KDATA_BASE_ADDR + 0x0053)
  503. #define KDATA_CHI_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0054)
  504. #define KDATA_SPDIF_XFER (KDATA_BASE_ADDR + 0x0055)
  505. #define KDATA_SPDIF_CURRENT_FRAME (KDATA_BASE_ADDR + 0x0056)
  506. #define KDATA_SPDIF_FRAME0 (KDATA_BASE_ADDR + 0x0057)
  507. #define KDATA_SPDIF_FRAME1 (KDATA_BASE_ADDR + 0x0058)
  508. #define KDATA_SPDIF_FRAME2 (KDATA_BASE_ADDR + 0x0059)
  509. #define KDATA_SPDIF_REQUEST (KDATA_BASE_ADDR + 0x005A)
  510. #define KDATA_SPDIF_TEMP (KDATA_BASE_ADDR + 0x005B)
  511. #define KDATA_SPDIFIN_XFER0 (KDATA_BASE_ADDR + 0x005C)
  512. #define KDATA_SPDIFIN_XFER_ENDMARK (KDATA_BASE_ADDR + 0x005D)
  513. #define KDATA_SPDIFIN_INT_METER (KDATA_BASE_ADDR + 0x005E)
  514. #define KDATA_DSP_RESET_COUNT (KDATA_BASE_ADDR + 0x005F)
  515. #define KDATA_DEBUG_OUTPUT (KDATA_BASE_ADDR + 0x0060)
  516. #define KDATA_KERNEL_ISR_LIST (KDATA_BASE_ADDR + 0x0061)
  517. #define KDATA_KERNEL_ISR_CBSR1 (KDATA_BASE_ADDR + 0x0062)
  518. #define KDATA_KERNEL_ISR_CBER1 (KDATA_BASE_ADDR + 0x0063)
  519. #define KDATA_KERNEL_ISR_CBCR (KDATA_BASE_ADDR + 0x0064)
  520. #define KDATA_KERNEL_ISR_AR0 (KDATA_BASE_ADDR + 0x0065)
  521. #define KDATA_KERNEL_ISR_AR1 (KDATA_BASE_ADDR + 0x0066)
  522. #define KDATA_KERNEL_ISR_AR2 (KDATA_BASE_ADDR + 0x0067)
  523. #define KDATA_KERNEL_ISR_AR3 (KDATA_BASE_ADDR + 0x0068)
  524. #define KDATA_KERNEL_ISR_AR4 (KDATA_BASE_ADDR + 0x0069)
  525. #define KDATA_KERNEL_ISR_AR5 (KDATA_BASE_ADDR + 0x006A)
  526. #define KDATA_KERNEL_ISR_BRCR (KDATA_BASE_ADDR + 0x006B)
  527. #define KDATA_KERNEL_ISR_PASR (KDATA_BASE_ADDR + 0x006C)
  528. #define KDATA_KERNEL_ISR_PAER (KDATA_BASE_ADDR + 0x006D)
  529. #define KDATA_CLIENT_SCRATCH0 (KDATA_BASE_ADDR + 0x006E)
  530. #define KDATA_CLIENT_SCRATCH1 (KDATA_BASE_ADDR + 0x006F)
  531. #define KDATA_KERNEL_SCRATCH (KDATA_BASE_ADDR + 0x0070)
  532. #define KDATA_KERNEL_ISR_SCRATCH (KDATA_BASE_ADDR + 0x0071)
  533. #define KDATA_OUEUE_LEFT (KDATA_BASE_ADDR + 0x0072)
  534. #define KDATA_QUEUE_RIGHT (KDATA_BASE_ADDR + 0x0073)
  535. #define KDATA_ADC1_REQUEST (KDATA_BASE_ADDR + 0x0074)
  536. #define KDATA_ADC2_REQUEST (KDATA_BASE_ADDR + 0x0075)
  537. #define KDATA_CD_REQUEST (KDATA_BASE_ADDR + 0x0076)
  538. #define KDATA_MIC_REQUEST (KDATA_BASE_ADDR + 0x0077)
  539. #define KDATA_ADC1_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0078)
  540. #define KDATA_ADC2_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0079)
  541. #define KDATA_CD_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007A)
  542. #define KDATA_MIC_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007B)
  543. #define KDATA_MIC_SYNC_COUNTER (KDATA_BASE_ADDR + 0x007C)
  544. /*
  545. * second 'segment' (?) reserved for mixer
  546. * buffers..
  547. */
  548. #define KDATA_MIXER_WORD0 (KDATA_BASE_ADDR2 + 0x0000)
  549. #define KDATA_MIXER_WORD1 (KDATA_BASE_ADDR2 + 0x0001)
  550. #define KDATA_MIXER_WORD2 (KDATA_BASE_ADDR2 + 0x0002)
  551. #define KDATA_MIXER_WORD3 (KDATA_BASE_ADDR2 + 0x0003)
  552. #define KDATA_MIXER_WORD4 (KDATA_BASE_ADDR2 + 0x0004)
  553. #define KDATA_MIXER_WORD5 (KDATA_BASE_ADDR2 + 0x0005)
  554. #define KDATA_MIXER_WORD6 (KDATA_BASE_ADDR2 + 0x0006)
  555. #define KDATA_MIXER_WORD7 (KDATA_BASE_ADDR2 + 0x0007)
  556. #define KDATA_MIXER_WORD8 (KDATA_BASE_ADDR2 + 0x0008)
  557. #define KDATA_MIXER_WORD9 (KDATA_BASE_ADDR2 + 0x0009)
  558. #define KDATA_MIXER_WORDA (KDATA_BASE_ADDR2 + 0x000A)
  559. #define KDATA_MIXER_WORDB (KDATA_BASE_ADDR2 + 0x000B)
  560. #define KDATA_MIXER_WORDC (KDATA_BASE_ADDR2 + 0x000C)
  561. #define KDATA_MIXER_WORDD (KDATA_BASE_ADDR2 + 0x000D)
  562. #define KDATA_MIXER_WORDE (KDATA_BASE_ADDR2 + 0x000E)
  563. #define KDATA_MIXER_WORDF (KDATA_BASE_ADDR2 + 0x000F)
  564. #define KDATA_MIXER_XFER0 (KDATA_BASE_ADDR2 + 0x0010)
  565. #define KDATA_MIXER_XFER1 (KDATA_BASE_ADDR2 + 0x0011)
  566. #define KDATA_MIXER_XFER2 (KDATA_BASE_ADDR2 + 0x0012)
  567. #define KDATA_MIXER_XFER3 (KDATA_BASE_ADDR2 + 0x0013)
  568. #define KDATA_MIXER_XFER4 (KDATA_BASE_ADDR2 + 0x0014)
  569. #define KDATA_MIXER_XFER5 (KDATA_BASE_ADDR2 + 0x0015)
  570. #define KDATA_MIXER_XFER6 (KDATA_BASE_ADDR2 + 0x0016)
  571. #define KDATA_MIXER_XFER7 (KDATA_BASE_ADDR2 + 0x0017)
  572. #define KDATA_MIXER_XFER8 (KDATA_BASE_ADDR2 + 0x0018)
  573. #define KDATA_MIXER_XFER9 (KDATA_BASE_ADDR2 + 0x0019)
  574. #define KDATA_MIXER_XFER_ENDMARK (KDATA_BASE_ADDR2 + 0x001A)
  575. #define KDATA_MIXER_TASK_NUMBER (KDATA_BASE_ADDR2 + 0x001B)
  576. #define KDATA_CURRENT_MIXER (KDATA_BASE_ADDR2 + 0x001C)
  577. #define KDATA_MIXER_ACTIVE (KDATA_BASE_ADDR2 + 0x001D)
  578. #define KDATA_MIXER_BANK_STATUS (KDATA_BASE_ADDR2 + 0x001E)
  579. #define KDATA_DAC_LEFT_VOLUME (KDATA_BASE_ADDR2 + 0x001F)
  580. #define KDATA_DAC_RIGHT_VOLUME (KDATA_BASE_ADDR2 + 0x0020)
  581. #define MAX_INSTANCE_MINISRC (KDATA_INSTANCE_MINISRC_ENDMARK - KDATA_INSTANCE0_MINISRC)
  582. #define MAX_VIRTUAL_DMA_CHANNELS (KDATA_DMA_XFER_ENDMARK - KDATA_DMA_XFER0)
  583. #define MAX_VIRTUAL_MIXER_CHANNELS (KDATA_MIXER_XFER_ENDMARK - KDATA_MIXER_XFER0)
  584. #define MAX_VIRTUAL_ADC1_CHANNELS (KDATA_ADC1_XFER_ENDMARK - KDATA_ADC1_XFER0)
  585. /*
  586. * client data area offsets
  587. */
  588. #define CDATA_INSTANCE_READY 0x00
  589. #define CDATA_HOST_SRC_ADDRL 0x01
  590. #define CDATA_HOST_SRC_ADDRH 0x02
  591. #define CDATA_HOST_SRC_END_PLUS_1L 0x03
  592. #define CDATA_HOST_SRC_END_PLUS_1H 0x04
  593. #define CDATA_HOST_SRC_CURRENTL 0x05
  594. #define CDATA_HOST_SRC_CURRENTH 0x06
  595. #define CDATA_IN_BUF_CONNECT 0x07
  596. #define CDATA_OUT_BUF_CONNECT 0x08
  597. #define CDATA_IN_BUF_BEGIN 0x09
  598. #define CDATA_IN_BUF_END_PLUS_1 0x0A
  599. #define CDATA_IN_BUF_HEAD 0x0B
  600. #define CDATA_IN_BUF_TAIL 0x0C
  601. #define CDATA_OUT_BUF_BEGIN 0x0D
  602. #define CDATA_OUT_BUF_END_PLUS_1 0x0E
  603. #define CDATA_OUT_BUF_HEAD 0x0F
  604. #define CDATA_OUT_BUF_TAIL 0x10
  605. #define CDATA_DMA_CONTROL 0x11
  606. #define CDATA_RESERVED 0x12
  607. #define CDATA_FREQUENCY 0x13
  608. #define CDATA_LEFT_VOLUME 0x14
  609. #define CDATA_RIGHT_VOLUME 0x15
  610. #define CDATA_LEFT_SUR_VOL 0x16
  611. #define CDATA_RIGHT_SUR_VOL 0x17
  612. #define CDATA_HEADER_LEN 0x18
  613. #define SRC3_DIRECTION_OFFSET CDATA_HEADER_LEN
  614. #define SRC3_MODE_OFFSET (CDATA_HEADER_LEN + 1)
  615. #define SRC3_WORD_LENGTH_OFFSET (CDATA_HEADER_LEN + 2)
  616. #define SRC3_PARAMETER_OFFSET (CDATA_HEADER_LEN + 3)
  617. #define SRC3_COEFF_ADDR_OFFSET (CDATA_HEADER_LEN + 8)
  618. #define SRC3_FILTAP_ADDR_OFFSET (CDATA_HEADER_LEN + 10)
  619. #define SRC3_TEMP_INBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 16)
  620. #define SRC3_TEMP_OUTBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 17)
  621. #define MINISRC_IN_BUFFER_SIZE ( 0x50 * 2 )
  622. #define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2)
  623. #define MINISRC_TMP_BUFFER_SIZE ( 112 + ( MINISRC_BIQUAD_STAGE * 3 + 4 ) * 2 * 2 )
  624. #define MINISRC_BIQUAD_STAGE 2
  625. #define MINISRC_COEF_LOC 0x175
  626. #define DMACONTROL_BLOCK_MASK 0x000F
  627. #define DMAC_BLOCK0_SELECTOR 0x0000
  628. #define DMAC_BLOCK1_SELECTOR 0x0001
  629. #define DMAC_BLOCK2_SELECTOR 0x0002
  630. #define DMAC_BLOCK3_SELECTOR 0x0003
  631. #define DMAC_BLOCK4_SELECTOR 0x0004
  632. #define DMAC_BLOCK5_SELECTOR 0x0005
  633. #define DMAC_BLOCK6_SELECTOR 0x0006
  634. #define DMAC_BLOCK7_SELECTOR 0x0007
  635. #define DMAC_BLOCK8_SELECTOR 0x0008
  636. #define DMAC_BLOCK9_SELECTOR 0x0009
  637. #define DMAC_BLOCKA_SELECTOR 0x000A
  638. #define DMAC_BLOCKB_SELECTOR 0x000B
  639. #define DMAC_BLOCKC_SELECTOR 0x000C
  640. #define DMAC_BLOCKD_SELECTOR 0x000D
  641. #define DMAC_BLOCKE_SELECTOR 0x000E
  642. #define DMAC_BLOCKF_SELECTOR 0x000F
  643. #define DMACONTROL_PAGE_MASK 0x00F0
  644. #define DMAC_PAGE0_SELECTOR 0x0030
  645. #define DMAC_PAGE1_SELECTOR 0x0020
  646. #define DMAC_PAGE2_SELECTOR 0x0010
  647. #define DMAC_PAGE3_SELECTOR 0x0000
  648. #define DMACONTROL_AUTOREPEAT 0x1000
  649. #define DMACONTROL_STOPPED 0x2000
  650. #define DMACONTROL_DIRECTION 0x0100
  651. /*
  652. * an arbitrary volume we set the internal
  653. * volume settings to so that the ac97 volume
  654. * range is a little less insane. 0x7fff is
  655. * max.
  656. */
  657. #define ARB_VOLUME ( 0x6800 )
  658. /*
  659. */
  660. struct m3_list {
  661. int curlen;
  662. int mem_addr;
  663. int max;
  664. };
  665. struct m3_dma {
  666. int number;
  667. struct snd_pcm_substream *substream;
  668. struct assp_instance {
  669. unsigned short code, data;
  670. } inst;
  671. int running;
  672. int opened;
  673. unsigned long buffer_addr;
  674. int dma_size;
  675. int period_size;
  676. unsigned int hwptr;
  677. int count;
  678. int index[3];
  679. struct m3_list *index_list[3];
  680. int in_lists;
  681. struct list_head list;
  682. };
  683. struct snd_m3 {
  684. struct snd_card *card;
  685. unsigned long iobase;
  686. int irq;
  687. unsigned int allegro_flag : 1;
  688. struct snd_ac97 *ac97;
  689. struct snd_pcm *pcm;
  690. struct pci_dev *pci;
  691. int dacs_active;
  692. int timer_users;
  693. struct m3_list msrc_list;
  694. struct m3_list mixer_list;
  695. struct m3_list adc1_list;
  696. struct m3_list dma_list;
  697. /* for storing reset state..*/
  698. u8 reset_state;
  699. int external_amp;
  700. int amp_gpio; /* gpio pin # for external amp, -1 = default */
  701. unsigned int hv_config; /* hardware-volume config bits */
  702. unsigned irda_workaround :1; /* avoid to touch 0x10 on GPIO_DIRECTION
  703. (e.g. for IrDA on Dell Inspirons) */
  704. unsigned is_omnibook :1; /* Do HP OmniBook GPIO magic? */
  705. /* midi */
  706. struct snd_rawmidi *rmidi;
  707. /* pcm streams */
  708. int num_substreams;
  709. struct m3_dma *substreams;
  710. spinlock_t reg_lock;
  711. #ifdef CONFIG_SND_MAESTRO3_INPUT
  712. struct input_dev *input_dev;
  713. char phys[64]; /* physical device path */
  714. #else
  715. spinlock_t ac97_lock;
  716. struct snd_kcontrol *master_switch;
  717. struct snd_kcontrol *master_volume;
  718. struct tasklet_struct hwvol_tq;
  719. #endif
  720. unsigned int in_suspend;
  721. #ifdef CONFIG_PM
  722. u16 *suspend_mem;
  723. #endif
  724. const struct firmware *assp_kernel_image;
  725. const struct firmware *assp_minisrc_image;
  726. };
  727. /*
  728. * pci ids
  729. */
  730. static DEFINE_PCI_DEVICE_TABLE(snd_m3_ids) = {
  731. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID,
  732. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  733. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO, PCI_ANY_ID, PCI_ANY_ID,
  734. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  735. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_CANYON3D_2LE, PCI_ANY_ID, PCI_ANY_ID,
  736. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  737. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_CANYON3D_2, PCI_ANY_ID, PCI_ANY_ID,
  738. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  739. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3, PCI_ANY_ID, PCI_ANY_ID,
  740. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  741. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_1, PCI_ANY_ID, PCI_ANY_ID,
  742. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  743. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_HW, PCI_ANY_ID, PCI_ANY_ID,
  744. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  745. {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_2, PCI_ANY_ID, PCI_ANY_ID,
  746. PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
  747. {0,},
  748. };
  749. MODULE_DEVICE_TABLE(pci, snd_m3_ids);
  750. static struct snd_pci_quirk m3_amp_quirk_list[] __devinitdata = {
  751. SND_PCI_QUIRK(0x0E11, 0x0094, "Compaq Evo N600c", 0x0c),
  752. SND_PCI_QUIRK(0x10f7, 0x833e, "Panasonic CF-28", 0x0d),
  753. SND_PCI_QUIRK(0x10f7, 0x833d, "Panasonic CF-72", 0x0d),
  754. SND_PCI_QUIRK(0x1033, 0x80f1, "NEC LM800J/7", 0x03),
  755. SND_PCI_QUIRK(0x1509, 0x1740, "LEGEND ZhaoYang 3100CF", 0x03),
  756. { } /* END */
  757. };
  758. static struct snd_pci_quirk m3_irda_quirk_list[] __devinitdata = {
  759. SND_PCI_QUIRK(0x1028, 0x00b0, "Dell Inspiron 4000", 1),
  760. SND_PCI_QUIRK(0x1028, 0x00a4, "Dell Inspiron 8000", 1),
  761. SND_PCI_QUIRK(0x1028, 0x00e6, "Dell Inspiron 8100", 1),
  762. { } /* END */
  763. };
  764. /* hardware volume quirks */
  765. static struct snd_pci_quirk m3_hv_quirk_list[] __devinitdata = {
  766. /* Allegro chips */
  767. SND_PCI_QUIRK(0x0E11, 0x002E, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  768. SND_PCI_QUIRK(0x0E11, 0x0094, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  769. SND_PCI_QUIRK(0x0E11, 0xB112, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  770. SND_PCI_QUIRK(0x0E11, 0xB114, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  771. SND_PCI_QUIRK(0x103C, 0x0012, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  772. SND_PCI_QUIRK(0x103C, 0x0018, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  773. SND_PCI_QUIRK(0x103C, 0x001C, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  774. SND_PCI_QUIRK(0x103C, 0x001D, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  775. SND_PCI_QUIRK(0x103C, 0x001E, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  776. SND_PCI_QUIRK(0x107B, 0x3350, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  777. SND_PCI_QUIRK(0x10F7, 0x8338, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  778. SND_PCI_QUIRK(0x10F7, 0x833C, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  779. SND_PCI_QUIRK(0x10F7, 0x833D, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  780. SND_PCI_QUIRK(0x10F7, 0x833E, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  781. SND_PCI_QUIRK(0x10F7, 0x833F, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  782. SND_PCI_QUIRK(0x13BD, 0x1018, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  783. SND_PCI_QUIRK(0x13BD, 0x1019, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  784. SND_PCI_QUIRK(0x13BD, 0x101A, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  785. SND_PCI_QUIRK(0x14FF, 0x0F03, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  786. SND_PCI_QUIRK(0x14FF, 0x0F04, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  787. SND_PCI_QUIRK(0x14FF, 0x0F05, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  788. SND_PCI_QUIRK(0x156D, 0xB400, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  789. SND_PCI_QUIRK(0x156D, 0xB795, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  790. SND_PCI_QUIRK(0x156D, 0xB797, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  791. SND_PCI_QUIRK(0x156D, 0xC700, NULL, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD),
  792. SND_PCI_QUIRK(0x1033, 0x80F1, NULL,
  793. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  794. SND_PCI_QUIRK(0x103C, 0x001A, NULL, /* HP OmniBook 6100 */
  795. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  796. SND_PCI_QUIRK(0x107B, 0x340A, NULL,
  797. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  798. SND_PCI_QUIRK(0x107B, 0x3450, NULL,
  799. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  800. SND_PCI_QUIRK(0x109F, 0x3134, NULL,
  801. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  802. SND_PCI_QUIRK(0x109F, 0x3161, NULL,
  803. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  804. SND_PCI_QUIRK(0x144D, 0x3280, NULL,
  805. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  806. SND_PCI_QUIRK(0x144D, 0x3281, NULL,
  807. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  808. SND_PCI_QUIRK(0x144D, 0xC002, NULL,
  809. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  810. SND_PCI_QUIRK(0x144D, 0xC003, NULL,
  811. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  812. SND_PCI_QUIRK(0x1509, 0x1740, NULL,
  813. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  814. SND_PCI_QUIRK(0x1610, 0x0010, NULL,
  815. HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE),
  816. SND_PCI_QUIRK(0x1042, 0x1042, NULL, HV_CTRL_ENABLE),
  817. SND_PCI_QUIRK(0x107B, 0x9500, NULL, HV_CTRL_ENABLE),
  818. SND_PCI_QUIRK(0x14FF, 0x0F06, NULL, HV_CTRL_ENABLE),
  819. SND_PCI_QUIRK(0x1558, 0x8586, NULL, HV_CTRL_ENABLE),
  820. SND_PCI_QUIRK(0x161F, 0x2011, NULL, HV_CTRL_ENABLE),
  821. /* Maestro3 chips */
  822. SND_PCI_QUIRK(0x103C, 0x000E, NULL, HV_CTRL_ENABLE),
  823. SND_PCI_QUIRK(0x103C, 0x0010, NULL, HV_CTRL_ENABLE),
  824. SND_PCI_QUIRK(0x103C, 0x0011, NULL, HV_CTRL_ENABLE),
  825. SND_PCI_QUIRK(0x103C, 0x001B, NULL, HV_CTRL_ENABLE),
  826. SND_PCI_QUIRK(0x104D, 0x80A6, NULL, HV_CTRL_ENABLE),
  827. SND_PCI_QUIRK(0x104D, 0x80AA, NULL, HV_CTRL_ENABLE),
  828. SND_PCI_QUIRK(0x107B, 0x5300, NULL, HV_CTRL_ENABLE),
  829. SND_PCI_QUIRK(0x110A, 0x1998, NULL, HV_CTRL_ENABLE),
  830. SND_PCI_QUIRK(0x13BD, 0x1015, NULL, HV_CTRL_ENABLE),
  831. SND_PCI_QUIRK(0x13BD, 0x101C, NULL, HV_CTRL_ENABLE),
  832. SND_PCI_QUIRK(0x13BD, 0x1802, NULL, HV_CTRL_ENABLE),
  833. SND_PCI_QUIRK(0x1599, 0x0715, NULL, HV_CTRL_ENABLE),
  834. SND_PCI_QUIRK(0x5643, 0x5643, NULL, HV_CTRL_ENABLE),
  835. SND_PCI_QUIRK(0x144D, 0x3260, NULL, HV_CTRL_ENABLE | REDUCED_DEBOUNCE),
  836. SND_PCI_QUIRK(0x144D, 0x3261, NULL, HV_CTRL_ENABLE | REDUCED_DEBOUNCE),
  837. SND_PCI_QUIRK(0x144D, 0xC000, NULL, HV_CTRL_ENABLE | REDUCED_DEBOUNCE),
  838. SND_PCI_QUIRK(0x144D, 0xC001, NULL, HV_CTRL_ENABLE | REDUCED_DEBOUNCE),
  839. { } /* END */
  840. };
  841. /* HP Omnibook quirks */
  842. static struct snd_pci_quirk m3_omnibook_quirk_list[] __devinitdata = {
  843. SND_PCI_QUIRK_ID(0x103c, 0x0010), /* HP OmniBook 6000 */
  844. SND_PCI_QUIRK_ID(0x103c, 0x0011), /* HP OmniBook 500 */
  845. { } /* END */
  846. };
  847. /*
  848. * lowlevel functions
  849. */
  850. static inline void snd_m3_outw(struct snd_m3 *chip, u16 value, unsigned long reg)
  851. {
  852. outw(value, chip->iobase + reg);
  853. }
  854. static inline u16 snd_m3_inw(struct snd_m3 *chip, unsigned long reg)
  855. {
  856. return inw(chip->iobase + reg);
  857. }
  858. static inline void snd_m3_outb(struct snd_m3 *chip, u8 value, unsigned long reg)
  859. {
  860. outb(value, chip->iobase + reg);
  861. }
  862. static inline u8 snd_m3_inb(struct snd_m3 *chip, unsigned long reg)
  863. {
  864. return inb(chip->iobase + reg);
  865. }
  866. /*
  867. * access 16bit words to the code or data regions of the dsp's memory.
  868. * index addresses 16bit words.
  869. */
  870. static u16 snd_m3_assp_read(struct snd_m3 *chip, u16 region, u16 index)
  871. {
  872. snd_m3_outw(chip, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
  873. snd_m3_outw(chip, index, DSP_PORT_MEMORY_INDEX);
  874. return snd_m3_inw(chip, DSP_PORT_MEMORY_DATA);
  875. }
  876. static void snd_m3_assp_write(struct snd_m3 *chip, u16 region, u16 index, u16 data)
  877. {
  878. snd_m3_outw(chip, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
  879. snd_m3_outw(chip, index, DSP_PORT_MEMORY_INDEX);
  880. snd_m3_outw(chip, data, DSP_PORT_MEMORY_DATA);
  881. }
  882. static void snd_m3_assp_halt(struct snd_m3 *chip)
  883. {
  884. chip->reset_state = snd_m3_inb(chip, DSP_PORT_CONTROL_REG_B) & ~REGB_STOP_CLOCK;
  885. msleep(10);
  886. snd_m3_outb(chip, chip->reset_state & ~REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
  887. }
  888. static void snd_m3_assp_continue(struct snd_m3 *chip)
  889. {
  890. snd_m3_outb(chip, chip->reset_state | REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
  891. }
  892. /*
  893. * This makes me sad. the maestro3 has lists
  894. * internally that must be packed.. 0 terminates,
  895. * apparently, or maybe all unused entries have
  896. * to be 0, the lists have static lengths set
  897. * by the binary code images.
  898. */
  899. static int snd_m3_add_list(struct snd_m3 *chip, struct m3_list *list, u16 val)
  900. {
  901. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  902. list->mem_addr + list->curlen,
  903. val);
  904. return list->curlen++;
  905. }
  906. static void snd_m3_remove_list(struct snd_m3 *chip, struct m3_list *list, int index)
  907. {
  908. u16 val;
  909. int lastindex = list->curlen - 1;
  910. if (index != lastindex) {
  911. val = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
  912. list->mem_addr + lastindex);
  913. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  914. list->mem_addr + index,
  915. val);
  916. }
  917. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  918. list->mem_addr + lastindex,
  919. 0);
  920. list->curlen--;
  921. }
  922. static void snd_m3_inc_timer_users(struct snd_m3 *chip)
  923. {
  924. chip->timer_users++;
  925. if (chip->timer_users != 1)
  926. return;
  927. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  928. KDATA_TIMER_COUNT_RELOAD,
  929. 240);
  930. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  931. KDATA_TIMER_COUNT_CURRENT,
  932. 240);
  933. snd_m3_outw(chip,
  934. snd_m3_inw(chip, HOST_INT_CTRL) | CLKRUN_GEN_ENABLE,
  935. HOST_INT_CTRL);
  936. }
  937. static void snd_m3_dec_timer_users(struct snd_m3 *chip)
  938. {
  939. chip->timer_users--;
  940. if (chip->timer_users > 0)
  941. return;
  942. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  943. KDATA_TIMER_COUNT_RELOAD,
  944. 0);
  945. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  946. KDATA_TIMER_COUNT_CURRENT,
  947. 0);
  948. snd_m3_outw(chip,
  949. snd_m3_inw(chip, HOST_INT_CTRL) & ~CLKRUN_GEN_ENABLE,
  950. HOST_INT_CTRL);
  951. }
  952. /*
  953. * start/stop
  954. */
  955. /* spinlock held! */
  956. static int snd_m3_pcm_start(struct snd_m3 *chip, struct m3_dma *s,
  957. struct snd_pcm_substream *subs)
  958. {
  959. if (! s || ! subs)
  960. return -EINVAL;
  961. snd_m3_inc_timer_users(chip);
  962. switch (subs->stream) {
  963. case SNDRV_PCM_STREAM_PLAYBACK:
  964. chip->dacs_active++;
  965. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  966. s->inst.data + CDATA_INSTANCE_READY, 1);
  967. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  968. KDATA_MIXER_TASK_NUMBER,
  969. chip->dacs_active);
  970. break;
  971. case SNDRV_PCM_STREAM_CAPTURE:
  972. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  973. KDATA_ADC1_REQUEST, 1);
  974. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  975. s->inst.data + CDATA_INSTANCE_READY, 1);
  976. break;
  977. }
  978. return 0;
  979. }
  980. /* spinlock held! */
  981. static int snd_m3_pcm_stop(struct snd_m3 *chip, struct m3_dma *s,
  982. struct snd_pcm_substream *subs)
  983. {
  984. if (! s || ! subs)
  985. return -EINVAL;
  986. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  987. s->inst.data + CDATA_INSTANCE_READY, 0);
  988. snd_m3_dec_timer_users(chip);
  989. switch (subs->stream) {
  990. case SNDRV_PCM_STREAM_PLAYBACK:
  991. chip->dacs_active--;
  992. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  993. KDATA_MIXER_TASK_NUMBER,
  994. chip->dacs_active);
  995. break;
  996. case SNDRV_PCM_STREAM_CAPTURE:
  997. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  998. KDATA_ADC1_REQUEST, 0);
  999. break;
  1000. }
  1001. return 0;
  1002. }
  1003. static int
  1004. snd_m3_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
  1005. {
  1006. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1007. struct m3_dma *s = subs->runtime->private_data;
  1008. int err = -EINVAL;
  1009. if (snd_BUG_ON(!s))
  1010. return -ENXIO;
  1011. spin_lock(&chip->reg_lock);
  1012. switch (cmd) {
  1013. case SNDRV_PCM_TRIGGER_START:
  1014. case SNDRV_PCM_TRIGGER_RESUME:
  1015. if (s->running)
  1016. err = -EBUSY;
  1017. else {
  1018. s->running = 1;
  1019. err = snd_m3_pcm_start(chip, s, subs);
  1020. }
  1021. break;
  1022. case SNDRV_PCM_TRIGGER_STOP:
  1023. case SNDRV_PCM_TRIGGER_SUSPEND:
  1024. if (! s->running)
  1025. err = 0; /* should return error? */
  1026. else {
  1027. s->running = 0;
  1028. err = snd_m3_pcm_stop(chip, s, subs);
  1029. }
  1030. break;
  1031. }
  1032. spin_unlock(&chip->reg_lock);
  1033. return err;
  1034. }
  1035. /*
  1036. * setup
  1037. */
  1038. static void
  1039. snd_m3_pcm_setup1(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs)
  1040. {
  1041. int dsp_in_size, dsp_out_size, dsp_in_buffer, dsp_out_buffer;
  1042. struct snd_pcm_runtime *runtime = subs->runtime;
  1043. if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1044. dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x20 * 2);
  1045. dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x20 * 2);
  1046. } else {
  1047. dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x10 * 2);
  1048. dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x10 * 2);
  1049. }
  1050. dsp_in_buffer = s->inst.data + (MINISRC_TMP_BUFFER_SIZE / 2);
  1051. dsp_out_buffer = dsp_in_buffer + (dsp_in_size / 2) + 1;
  1052. s->dma_size = frames_to_bytes(runtime, runtime->buffer_size);
  1053. s->period_size = frames_to_bytes(runtime, runtime->period_size);
  1054. s->hwptr = 0;
  1055. s->count = 0;
  1056. #define LO(x) ((x) & 0xffff)
  1057. #define HI(x) LO((x) >> 16)
  1058. /* host dma buffer pointers */
  1059. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1060. s->inst.data + CDATA_HOST_SRC_ADDRL,
  1061. LO(s->buffer_addr));
  1062. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1063. s->inst.data + CDATA_HOST_SRC_ADDRH,
  1064. HI(s->buffer_addr));
  1065. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1066. s->inst.data + CDATA_HOST_SRC_END_PLUS_1L,
  1067. LO(s->buffer_addr + s->dma_size));
  1068. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1069. s->inst.data + CDATA_HOST_SRC_END_PLUS_1H,
  1070. HI(s->buffer_addr + s->dma_size));
  1071. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1072. s->inst.data + CDATA_HOST_SRC_CURRENTL,
  1073. LO(s->buffer_addr));
  1074. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1075. s->inst.data + CDATA_HOST_SRC_CURRENTH,
  1076. HI(s->buffer_addr));
  1077. #undef LO
  1078. #undef HI
  1079. /* dsp buffers */
  1080. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1081. s->inst.data + CDATA_IN_BUF_BEGIN,
  1082. dsp_in_buffer);
  1083. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1084. s->inst.data + CDATA_IN_BUF_END_PLUS_1,
  1085. dsp_in_buffer + (dsp_in_size / 2));
  1086. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1087. s->inst.data + CDATA_IN_BUF_HEAD,
  1088. dsp_in_buffer);
  1089. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1090. s->inst.data + CDATA_IN_BUF_TAIL,
  1091. dsp_in_buffer);
  1092. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1093. s->inst.data + CDATA_OUT_BUF_BEGIN,
  1094. dsp_out_buffer);
  1095. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1096. s->inst.data + CDATA_OUT_BUF_END_PLUS_1,
  1097. dsp_out_buffer + (dsp_out_size / 2));
  1098. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1099. s->inst.data + CDATA_OUT_BUF_HEAD,
  1100. dsp_out_buffer);
  1101. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1102. s->inst.data + CDATA_OUT_BUF_TAIL,
  1103. dsp_out_buffer);
  1104. }
  1105. static void snd_m3_pcm_setup2(struct snd_m3 *chip, struct m3_dma *s,
  1106. struct snd_pcm_runtime *runtime)
  1107. {
  1108. u32 freq;
  1109. /*
  1110. * put us in the lists if we're not already there
  1111. */
  1112. if (! s->in_lists) {
  1113. s->index[0] = snd_m3_add_list(chip, s->index_list[0],
  1114. s->inst.data >> DP_SHIFT_COUNT);
  1115. s->index[1] = snd_m3_add_list(chip, s->index_list[1],
  1116. s->inst.data >> DP_SHIFT_COUNT);
  1117. s->index[2] = snd_m3_add_list(chip, s->index_list[2],
  1118. s->inst.data >> DP_SHIFT_COUNT);
  1119. s->in_lists = 1;
  1120. }
  1121. /* write to 'mono' word */
  1122. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1123. s->inst.data + SRC3_DIRECTION_OFFSET + 1,
  1124. runtime->channels == 2 ? 0 : 1);
  1125. /* write to '8bit' word */
  1126. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1127. s->inst.data + SRC3_DIRECTION_OFFSET + 2,
  1128. snd_pcm_format_width(runtime->format) == 16 ? 0 : 1);
  1129. /* set up dac/adc rate */
  1130. freq = ((runtime->rate << 15) + 24000 ) / 48000;
  1131. if (freq)
  1132. freq--;
  1133. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1134. s->inst.data + CDATA_FREQUENCY,
  1135. freq);
  1136. }
  1137. static const struct play_vals {
  1138. u16 addr, val;
  1139. } pv[] = {
  1140. {CDATA_LEFT_VOLUME, ARB_VOLUME},
  1141. {CDATA_RIGHT_VOLUME, ARB_VOLUME},
  1142. {SRC3_DIRECTION_OFFSET, 0} ,
  1143. /* +1, +2 are stereo/16 bit */
  1144. {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
  1145. {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
  1146. {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
  1147. {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
  1148. {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
  1149. {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
  1150. {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
  1151. {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
  1152. {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
  1153. {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
  1154. {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
  1155. {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
  1156. {SRC3_DIRECTION_OFFSET + 16, 8}, /* numin */
  1157. {SRC3_DIRECTION_OFFSET + 17, 50*2}, /* numout */
  1158. {SRC3_DIRECTION_OFFSET + 18, MINISRC_BIQUAD_STAGE - 1}, /* numstage */
  1159. {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
  1160. {SRC3_DIRECTION_OFFSET + 21, 0} /* booster */
  1161. };
  1162. /* the mode passed should be already shifted and masked */
  1163. static void
  1164. snd_m3_playback_setup(struct snd_m3 *chip, struct m3_dma *s,
  1165. struct snd_pcm_substream *subs)
  1166. {
  1167. unsigned int i;
  1168. /*
  1169. * some per client initializers
  1170. */
  1171. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1172. s->inst.data + SRC3_DIRECTION_OFFSET + 12,
  1173. s->inst.data + 40 + 8);
  1174. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1175. s->inst.data + SRC3_DIRECTION_OFFSET + 19,
  1176. s->inst.code + MINISRC_COEF_LOC);
  1177. /* enable or disable low pass filter? */
  1178. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1179. s->inst.data + SRC3_DIRECTION_OFFSET + 22,
  1180. subs->runtime->rate > 45000 ? 0xff : 0);
  1181. /* tell it which way dma is going? */
  1182. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1183. s->inst.data + CDATA_DMA_CONTROL,
  1184. DMACONTROL_AUTOREPEAT + DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
  1185. /*
  1186. * set an armload of static initializers
  1187. */
  1188. for (i = 0; i < ARRAY_SIZE(pv); i++)
  1189. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1190. s->inst.data + pv[i].addr, pv[i].val);
  1191. }
  1192. /*
  1193. * Native record driver
  1194. */
  1195. static const struct rec_vals {
  1196. u16 addr, val;
  1197. } rv[] = {
  1198. {CDATA_LEFT_VOLUME, ARB_VOLUME},
  1199. {CDATA_RIGHT_VOLUME, ARB_VOLUME},
  1200. {SRC3_DIRECTION_OFFSET, 1} ,
  1201. /* +1, +2 are stereo/16 bit */
  1202. {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
  1203. {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
  1204. {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
  1205. {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
  1206. {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
  1207. {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
  1208. {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
  1209. {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
  1210. {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
  1211. {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
  1212. {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
  1213. {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
  1214. {SRC3_DIRECTION_OFFSET + 16, 50},/* numin */
  1215. {SRC3_DIRECTION_OFFSET + 17, 8}, /* numout */
  1216. {SRC3_DIRECTION_OFFSET + 18, 0}, /* numstage */
  1217. {SRC3_DIRECTION_OFFSET + 19, 0}, /* coef */
  1218. {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
  1219. {SRC3_DIRECTION_OFFSET + 21, 0}, /* booster */
  1220. {SRC3_DIRECTION_OFFSET + 22, 0xff} /* skip lpf */
  1221. };
  1222. static void
  1223. snd_m3_capture_setup(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs)
  1224. {
  1225. unsigned int i;
  1226. /*
  1227. * some per client initializers
  1228. */
  1229. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1230. s->inst.data + SRC3_DIRECTION_OFFSET + 12,
  1231. s->inst.data + 40 + 8);
  1232. /* tell it which way dma is going? */
  1233. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1234. s->inst.data + CDATA_DMA_CONTROL,
  1235. DMACONTROL_DIRECTION + DMACONTROL_AUTOREPEAT +
  1236. DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
  1237. /*
  1238. * set an armload of static initializers
  1239. */
  1240. for (i = 0; i < ARRAY_SIZE(rv); i++)
  1241. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1242. s->inst.data + rv[i].addr, rv[i].val);
  1243. }
  1244. static int snd_m3_pcm_hw_params(struct snd_pcm_substream *substream,
  1245. struct snd_pcm_hw_params *hw_params)
  1246. {
  1247. struct m3_dma *s = substream->runtime->private_data;
  1248. int err;
  1249. if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
  1250. return err;
  1251. /* set buffer address */
  1252. s->buffer_addr = substream->runtime->dma_addr;
  1253. if (s->buffer_addr & 0x3) {
  1254. snd_printk(KERN_ERR "oh my, not aligned\n");
  1255. s->buffer_addr = s->buffer_addr & ~0x3;
  1256. }
  1257. return 0;
  1258. }
  1259. static int snd_m3_pcm_hw_free(struct snd_pcm_substream *substream)
  1260. {
  1261. struct m3_dma *s;
  1262. if (substream->runtime->private_data == NULL)
  1263. return 0;
  1264. s = substream->runtime->private_data;
  1265. snd_pcm_lib_free_pages(substream);
  1266. s->buffer_addr = 0;
  1267. return 0;
  1268. }
  1269. static int
  1270. snd_m3_pcm_prepare(struct snd_pcm_substream *subs)
  1271. {
  1272. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1273. struct snd_pcm_runtime *runtime = subs->runtime;
  1274. struct m3_dma *s = runtime->private_data;
  1275. if (snd_BUG_ON(!s))
  1276. return -ENXIO;
  1277. if (runtime->format != SNDRV_PCM_FORMAT_U8 &&
  1278. runtime->format != SNDRV_PCM_FORMAT_S16_LE)
  1279. return -EINVAL;
  1280. if (runtime->rate > 48000 ||
  1281. runtime->rate < 8000)
  1282. return -EINVAL;
  1283. spin_lock_irq(&chip->reg_lock);
  1284. snd_m3_pcm_setup1(chip, s, subs);
  1285. if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1286. snd_m3_playback_setup(chip, s, subs);
  1287. else
  1288. snd_m3_capture_setup(chip, s, subs);
  1289. snd_m3_pcm_setup2(chip, s, runtime);
  1290. spin_unlock_irq(&chip->reg_lock);
  1291. return 0;
  1292. }
  1293. /*
  1294. * get current pointer
  1295. */
  1296. static unsigned int
  1297. snd_m3_get_pointer(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs)
  1298. {
  1299. u16 hi = 0, lo = 0;
  1300. int retry = 10;
  1301. u32 addr;
  1302. /*
  1303. * try and get a valid answer
  1304. */
  1305. while (retry--) {
  1306. hi = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
  1307. s->inst.data + CDATA_HOST_SRC_CURRENTH);
  1308. lo = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
  1309. s->inst.data + CDATA_HOST_SRC_CURRENTL);
  1310. if (hi == snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
  1311. s->inst.data + CDATA_HOST_SRC_CURRENTH))
  1312. break;
  1313. }
  1314. addr = lo | ((u32)hi<<16);
  1315. return (unsigned int)(addr - s->buffer_addr);
  1316. }
  1317. static snd_pcm_uframes_t
  1318. snd_m3_pcm_pointer(struct snd_pcm_substream *subs)
  1319. {
  1320. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1321. unsigned int ptr;
  1322. struct m3_dma *s = subs->runtime->private_data;
  1323. if (snd_BUG_ON(!s))
  1324. return 0;
  1325. spin_lock(&chip->reg_lock);
  1326. ptr = snd_m3_get_pointer(chip, s, subs);
  1327. spin_unlock(&chip->reg_lock);
  1328. return bytes_to_frames(subs->runtime, ptr);
  1329. }
  1330. /* update pointer */
  1331. /* spinlock held! */
  1332. static void snd_m3_update_ptr(struct snd_m3 *chip, struct m3_dma *s)
  1333. {
  1334. struct snd_pcm_substream *subs = s->substream;
  1335. unsigned int hwptr;
  1336. int diff;
  1337. if (! s->running)
  1338. return;
  1339. hwptr = snd_m3_get_pointer(chip, s, subs);
  1340. /* try to avoid expensive modulo divisions */
  1341. if (hwptr >= s->dma_size)
  1342. hwptr %= s->dma_size;
  1343. diff = s->dma_size + hwptr - s->hwptr;
  1344. if (diff >= s->dma_size)
  1345. diff %= s->dma_size;
  1346. s->hwptr = hwptr;
  1347. s->count += diff;
  1348. if (s->count >= (signed)s->period_size) {
  1349. if (s->count < 2 * (signed)s->period_size)
  1350. s->count -= (signed)s->period_size;
  1351. else
  1352. s->count %= s->period_size;
  1353. spin_unlock(&chip->reg_lock);
  1354. snd_pcm_period_elapsed(subs);
  1355. spin_lock(&chip->reg_lock);
  1356. }
  1357. }
  1358. /* The m3's hardware volume works by incrementing / decrementing 2 counters
  1359. (without wrap around) in response to volume button presses and then
  1360. generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
  1361. of a byte wide register. The meaning of bits 0 and 4 is unknown. */
  1362. static void snd_m3_update_hw_volume(unsigned long private_data)
  1363. {
  1364. struct snd_m3 *chip = (struct snd_m3 *) private_data;
  1365. int x, val;
  1366. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1367. unsigned long flags;
  1368. #endif
  1369. /* Figure out which volume control button was pushed,
  1370. based on differences from the default register
  1371. values. */
  1372. x = inb(chip->iobase + SHADOW_MIX_REG_VOICE) & 0xee;
  1373. /* Reset the volume counters to 4. Tests on the allegro integrated
  1374. into a Compaq N600C laptop, have revealed that:
  1375. 1) Writing any value will result in the 2 counters being reset to
  1376. 4 so writing 0x88 is not strictly necessary
  1377. 2) Writing to any of the 4 involved registers will reset all 4
  1378. of them (and reading them always returns the same value for all
  1379. of them)
  1380. It could be that a maestro deviates from this, so leave the code
  1381. as is. */
  1382. outb(0x88, chip->iobase + SHADOW_MIX_REG_VOICE);
  1383. outb(0x88, chip->iobase + HW_VOL_COUNTER_VOICE);
  1384. outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER);
  1385. outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER);
  1386. /* Ignore spurious HV interrupts during suspend / resume, this avoids
  1387. mistaking them for a mute button press. */
  1388. if (chip->in_suspend)
  1389. return;
  1390. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1391. if (!chip->master_switch || !chip->master_volume)
  1392. return;
  1393. /* FIXME: we can't call snd_ac97_* functions since here is in tasklet. */
  1394. spin_lock_irqsave(&chip->ac97_lock, flags);
  1395. val = chip->ac97->regs[AC97_MASTER_VOL];
  1396. switch (x) {
  1397. case 0x88:
  1398. /* The counters have not changed, yet we've received a HV
  1399. interrupt. According to tests run by various people this
  1400. happens when pressing the mute button. */
  1401. val ^= 0x8000;
  1402. chip->ac97->regs[AC97_MASTER_VOL] = val;
  1403. outw(val, chip->iobase + CODEC_DATA);
  1404. outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
  1405. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1406. &chip->master_switch->id);
  1407. break;
  1408. case 0xaa:
  1409. /* counters increased by 1 -> volume up */
  1410. if ((val & 0x7f) > 0)
  1411. val--;
  1412. if ((val & 0x7f00) > 0)
  1413. val -= 0x0100;
  1414. chip->ac97->regs[AC97_MASTER_VOL] = val;
  1415. outw(val, chip->iobase + CODEC_DATA);
  1416. outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
  1417. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1418. &chip->master_volume->id);
  1419. break;
  1420. case 0x66:
  1421. /* counters decreased by 1 -> volume down */
  1422. if ((val & 0x7f) < 0x1f)
  1423. val++;
  1424. if ((val & 0x7f00) < 0x1f00)
  1425. val += 0x0100;
  1426. chip->ac97->regs[AC97_MASTER_VOL] = val;
  1427. outw(val, chip->iobase + CODEC_DATA);
  1428. outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
  1429. snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1430. &chip->master_volume->id);
  1431. break;
  1432. }
  1433. spin_unlock_irqrestore(&chip->ac97_lock, flags);
  1434. #else
  1435. if (!chip->input_dev)
  1436. return;
  1437. val = 0;
  1438. switch (x) {
  1439. case 0x88:
  1440. /* The counters have not changed, yet we've received a HV
  1441. interrupt. According to tests run by various people this
  1442. happens when pressing the mute button. */
  1443. val = KEY_MUTE;
  1444. break;
  1445. case 0xaa:
  1446. /* counters increased by 1 -> volume up */
  1447. val = KEY_VOLUMEUP;
  1448. break;
  1449. case 0x66:
  1450. /* counters decreased by 1 -> volume down */
  1451. val = KEY_VOLUMEDOWN;
  1452. break;
  1453. }
  1454. if (val) {
  1455. input_report_key(chip->input_dev, val, 1);
  1456. input_sync(chip->input_dev);
  1457. input_report_key(chip->input_dev, val, 0);
  1458. input_sync(chip->input_dev);
  1459. }
  1460. #endif
  1461. }
  1462. static irqreturn_t snd_m3_interrupt(int irq, void *dev_id)
  1463. {
  1464. struct snd_m3 *chip = dev_id;
  1465. u8 status;
  1466. int i;
  1467. status = inb(chip->iobase + HOST_INT_STATUS);
  1468. if (status == 0xff)
  1469. return IRQ_NONE;
  1470. if (status & HV_INT_PENDING)
  1471. #ifdef CONFIG_SND_MAESTRO3_INPUT
  1472. snd_m3_update_hw_volume((unsigned long)chip);
  1473. #else
  1474. tasklet_schedule(&chip->hwvol_tq);
  1475. #endif
  1476. /*
  1477. * ack an assp int if its running
  1478. * and has an int pending
  1479. */
  1480. if (status & ASSP_INT_PENDING) {
  1481. u8 ctl = inb(chip->iobase + ASSP_CONTROL_B);
  1482. if (!(ctl & STOP_ASSP_CLOCK)) {
  1483. ctl = inb(chip->iobase + ASSP_HOST_INT_STATUS);
  1484. if (ctl & DSP2HOST_REQ_TIMER) {
  1485. outb(DSP2HOST_REQ_TIMER, chip->iobase + ASSP_HOST_INT_STATUS);
  1486. /* update adc/dac info if it was a timer int */
  1487. spin_lock(&chip->reg_lock);
  1488. for (i = 0; i < chip->num_substreams; i++) {
  1489. struct m3_dma *s = &chip->substreams[i];
  1490. if (s->running)
  1491. snd_m3_update_ptr(chip, s);
  1492. }
  1493. spin_unlock(&chip->reg_lock);
  1494. }
  1495. }
  1496. }
  1497. #if 0 /* TODO: not supported yet */
  1498. if ((status & MPU401_INT_PENDING) && chip->rmidi)
  1499. snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
  1500. #endif
  1501. /* ack ints */
  1502. outb(status, chip->iobase + HOST_INT_STATUS);
  1503. return IRQ_HANDLED;
  1504. }
  1505. /*
  1506. */
  1507. static struct snd_pcm_hardware snd_m3_playback =
  1508. {
  1509. .info = (SNDRV_PCM_INFO_MMAP |
  1510. SNDRV_PCM_INFO_INTERLEAVED |
  1511. SNDRV_PCM_INFO_MMAP_VALID |
  1512. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1513. /*SNDRV_PCM_INFO_PAUSE |*/
  1514. SNDRV_PCM_INFO_RESUME),
  1515. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  1516. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  1517. .rate_min = 8000,
  1518. .rate_max = 48000,
  1519. .channels_min = 1,
  1520. .channels_max = 2,
  1521. .buffer_bytes_max = (512*1024),
  1522. .period_bytes_min = 64,
  1523. .period_bytes_max = (512*1024),
  1524. .periods_min = 1,
  1525. .periods_max = 1024,
  1526. };
  1527. static struct snd_pcm_hardware snd_m3_capture =
  1528. {
  1529. .info = (SNDRV_PCM_INFO_MMAP |
  1530. SNDRV_PCM_INFO_INTERLEAVED |
  1531. SNDRV_PCM_INFO_MMAP_VALID |
  1532. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1533. /*SNDRV_PCM_INFO_PAUSE |*/
  1534. SNDRV_PCM_INFO_RESUME),
  1535. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  1536. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  1537. .rate_min = 8000,
  1538. .rate_max = 48000,
  1539. .channels_min = 1,
  1540. .channels_max = 2,
  1541. .buffer_bytes_max = (512*1024),
  1542. .period_bytes_min = 64,
  1543. .period_bytes_max = (512*1024),
  1544. .periods_min = 1,
  1545. .periods_max = 1024,
  1546. };
  1547. /*
  1548. */
  1549. static int
  1550. snd_m3_substream_open(struct snd_m3 *chip, struct snd_pcm_substream *subs)
  1551. {
  1552. int i;
  1553. struct m3_dma *s;
  1554. spin_lock_irq(&chip->reg_lock);
  1555. for (i = 0; i < chip->num_substreams; i++) {
  1556. s = &chip->substreams[i];
  1557. if (! s->opened)
  1558. goto __found;
  1559. }
  1560. spin_unlock_irq(&chip->reg_lock);
  1561. return -ENOMEM;
  1562. __found:
  1563. s->opened = 1;
  1564. s->running = 0;
  1565. spin_unlock_irq(&chip->reg_lock);
  1566. subs->runtime->private_data = s;
  1567. s->substream = subs;
  1568. /* set list owners */
  1569. if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1570. s->index_list[0] = &chip->mixer_list;
  1571. } else
  1572. s->index_list[0] = &chip->adc1_list;
  1573. s->index_list[1] = &chip->msrc_list;
  1574. s->index_list[2] = &chip->dma_list;
  1575. return 0;
  1576. }
  1577. static void
  1578. snd_m3_substream_close(struct snd_m3 *chip, struct snd_pcm_substream *subs)
  1579. {
  1580. struct m3_dma *s = subs->runtime->private_data;
  1581. if (s == NULL)
  1582. return; /* not opened properly */
  1583. spin_lock_irq(&chip->reg_lock);
  1584. if (s->substream && s->running)
  1585. snd_m3_pcm_stop(chip, s, s->substream); /* does this happen? */
  1586. if (s->in_lists) {
  1587. snd_m3_remove_list(chip, s->index_list[0], s->index[0]);
  1588. snd_m3_remove_list(chip, s->index_list[1], s->index[1]);
  1589. snd_m3_remove_list(chip, s->index_list[2], s->index[2]);
  1590. s->in_lists = 0;
  1591. }
  1592. s->running = 0;
  1593. s->opened = 0;
  1594. spin_unlock_irq(&chip->reg_lock);
  1595. }
  1596. static int
  1597. snd_m3_playback_open(struct snd_pcm_substream *subs)
  1598. {
  1599. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1600. struct snd_pcm_runtime *runtime = subs->runtime;
  1601. int err;
  1602. if ((err = snd_m3_substream_open(chip, subs)) < 0)
  1603. return err;
  1604. runtime->hw = snd_m3_playback;
  1605. return 0;
  1606. }
  1607. static int
  1608. snd_m3_playback_close(struct snd_pcm_substream *subs)
  1609. {
  1610. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1611. snd_m3_substream_close(chip, subs);
  1612. return 0;
  1613. }
  1614. static int
  1615. snd_m3_capture_open(struct snd_pcm_substream *subs)
  1616. {
  1617. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1618. struct snd_pcm_runtime *runtime = subs->runtime;
  1619. int err;
  1620. if ((err = snd_m3_substream_open(chip, subs)) < 0)
  1621. return err;
  1622. runtime->hw = snd_m3_capture;
  1623. return 0;
  1624. }
  1625. static int
  1626. snd_m3_capture_close(struct snd_pcm_substream *subs)
  1627. {
  1628. struct snd_m3 *chip = snd_pcm_substream_chip(subs);
  1629. snd_m3_substream_close(chip, subs);
  1630. return 0;
  1631. }
  1632. /*
  1633. * create pcm instance
  1634. */
  1635. static struct snd_pcm_ops snd_m3_playback_ops = {
  1636. .open = snd_m3_playback_open,
  1637. .close = snd_m3_playback_close,
  1638. .ioctl = snd_pcm_lib_ioctl,
  1639. .hw_params = snd_m3_pcm_hw_params,
  1640. .hw_free = snd_m3_pcm_hw_free,
  1641. .prepare = snd_m3_pcm_prepare,
  1642. .trigger = snd_m3_pcm_trigger,
  1643. .pointer = snd_m3_pcm_pointer,
  1644. };
  1645. static struct snd_pcm_ops snd_m3_capture_ops = {
  1646. .open = snd_m3_capture_open,
  1647. .close = snd_m3_capture_close,
  1648. .ioctl = snd_pcm_lib_ioctl,
  1649. .hw_params = snd_m3_pcm_hw_params,
  1650. .hw_free = snd_m3_pcm_hw_free,
  1651. .prepare = snd_m3_pcm_prepare,
  1652. .trigger = snd_m3_pcm_trigger,
  1653. .pointer = snd_m3_pcm_pointer,
  1654. };
  1655. static int __devinit
  1656. snd_m3_pcm(struct snd_m3 * chip, int device)
  1657. {
  1658. struct snd_pcm *pcm;
  1659. int err;
  1660. err = snd_pcm_new(chip->card, chip->card->driver, device,
  1661. MAX_PLAYBACKS, MAX_CAPTURES, &pcm);
  1662. if (err < 0)
  1663. return err;
  1664. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_m3_playback_ops);
  1665. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_m3_capture_ops);
  1666. pcm->private_data = chip;
  1667. pcm->info_flags = 0;
  1668. strcpy(pcm->name, chip->card->driver);
  1669. chip->pcm = pcm;
  1670. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1671. snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
  1672. return 0;
  1673. }
  1674. /*
  1675. * ac97 interface
  1676. */
  1677. /*
  1678. * Wait for the ac97 serial bus to be free.
  1679. * return nonzero if the bus is still busy.
  1680. */
  1681. static int snd_m3_ac97_wait(struct snd_m3 *chip)
  1682. {
  1683. int i = 10000;
  1684. do {
  1685. if (! (snd_m3_inb(chip, 0x30) & 1))
  1686. return 0;
  1687. cpu_relax();
  1688. } while (i-- > 0);
  1689. snd_printk(KERN_ERR "ac97 serial bus busy\n");
  1690. return 1;
  1691. }
  1692. static unsigned short
  1693. snd_m3_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
  1694. {
  1695. struct snd_m3 *chip = ac97->private_data;
  1696. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1697. unsigned long flags;
  1698. #endif
  1699. unsigned short data = 0xffff;
  1700. if (snd_m3_ac97_wait(chip))
  1701. goto fail;
  1702. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1703. spin_lock_irqsave(&chip->ac97_lock, flags);
  1704. #endif
  1705. snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
  1706. if (snd_m3_ac97_wait(chip))
  1707. goto fail_unlock;
  1708. data = snd_m3_inw(chip, CODEC_DATA);
  1709. fail_unlock:
  1710. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1711. spin_unlock_irqrestore(&chip->ac97_lock, flags);
  1712. #endif
  1713. fail:
  1714. return data;
  1715. }
  1716. static void
  1717. snd_m3_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
  1718. {
  1719. struct snd_m3 *chip = ac97->private_data;
  1720. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1721. unsigned long flags;
  1722. #endif
  1723. if (snd_m3_ac97_wait(chip))
  1724. return;
  1725. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1726. spin_lock_irqsave(&chip->ac97_lock, flags);
  1727. #endif
  1728. snd_m3_outw(chip, val, CODEC_DATA);
  1729. snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
  1730. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1731. spin_unlock_irqrestore(&chip->ac97_lock, flags);
  1732. #endif
  1733. }
  1734. static void snd_m3_remote_codec_config(int io, int isremote)
  1735. {
  1736. isremote = isremote ? 1 : 0;
  1737. outw((inw(io + RING_BUS_CTRL_B) & ~SECOND_CODEC_ID_MASK) | isremote,
  1738. io + RING_BUS_CTRL_B);
  1739. outw((inw(io + SDO_OUT_DEST_CTRL) & ~COMMAND_ADDR_OUT) | isremote,
  1740. io + SDO_OUT_DEST_CTRL);
  1741. outw((inw(io + SDO_IN_DEST_CTRL) & ~STATUS_ADDR_IN) | isremote,
  1742. io + SDO_IN_DEST_CTRL);
  1743. }
  1744. /*
  1745. * hack, returns non zero on err
  1746. */
  1747. static int snd_m3_try_read_vendor(struct snd_m3 *chip)
  1748. {
  1749. u16 ret;
  1750. if (snd_m3_ac97_wait(chip))
  1751. return 1;
  1752. snd_m3_outb(chip, 0x80 | (AC97_VENDOR_ID1 & 0x7f), 0x30);
  1753. if (snd_m3_ac97_wait(chip))
  1754. return 1;
  1755. ret = snd_m3_inw(chip, 0x32);
  1756. return (ret == 0) || (ret == 0xffff);
  1757. }
  1758. static void snd_m3_ac97_reset(struct snd_m3 *chip)
  1759. {
  1760. u16 dir;
  1761. int delay1 = 0, delay2 = 0, i;
  1762. int io = chip->iobase;
  1763. if (chip->allegro_flag) {
  1764. /*
  1765. * the onboard codec on the allegro seems
  1766. * to want to wait a very long time before
  1767. * coming back to life
  1768. */
  1769. delay1 = 50;
  1770. delay2 = 800;
  1771. } else {
  1772. /* maestro3 */
  1773. delay1 = 20;
  1774. delay2 = 500;
  1775. }
  1776. for (i = 0; i < 5; i++) {
  1777. dir = inw(io + GPIO_DIRECTION);
  1778. if (!chip->irda_workaround)
  1779. dir |= 0x10; /* assuming pci bus master? */
  1780. snd_m3_remote_codec_config(io, 0);
  1781. outw(IO_SRAM_ENABLE, io + RING_BUS_CTRL_A);
  1782. udelay(20);
  1783. outw(dir & ~GPO_PRIMARY_AC97 , io + GPIO_DIRECTION);
  1784. outw(~GPO_PRIMARY_AC97 , io + GPIO_MASK);
  1785. outw(0, io + GPIO_DATA);
  1786. outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION);
  1787. schedule_timeout_uninterruptible(msecs_to_jiffies(delay1));
  1788. outw(GPO_PRIMARY_AC97, io + GPIO_DATA);
  1789. udelay(5);
  1790. /* ok, bring back the ac-link */
  1791. outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A);
  1792. outw(~0, io + GPIO_MASK);
  1793. schedule_timeout_uninterruptible(msecs_to_jiffies(delay2));
  1794. if (! snd_m3_try_read_vendor(chip))
  1795. break;
  1796. delay1 += 10;
  1797. delay2 += 100;
  1798. snd_printd("maestro3: retrying codec reset with delays of %d and %d ms\n",
  1799. delay1, delay2);
  1800. }
  1801. #if 0
  1802. /* more gung-ho reset that doesn't
  1803. * seem to work anywhere :)
  1804. */
  1805. tmp = inw(io + RING_BUS_CTRL_A);
  1806. outw(RAC_SDFS_ENABLE|LAC_SDFS_ENABLE, io + RING_BUS_CTRL_A);
  1807. msleep(20);
  1808. outw(tmp, io + RING_BUS_CTRL_A);
  1809. msleep(50);
  1810. #endif
  1811. }
  1812. static int __devinit snd_m3_mixer(struct snd_m3 *chip)
  1813. {
  1814. struct snd_ac97_bus *pbus;
  1815. struct snd_ac97_template ac97;
  1816. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1817. struct snd_ctl_elem_id elem_id;
  1818. #endif
  1819. int err;
  1820. static struct snd_ac97_bus_ops ops = {
  1821. .write = snd_m3_ac97_write,
  1822. .read = snd_m3_ac97_read,
  1823. };
  1824. if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
  1825. return err;
  1826. memset(&ac97, 0, sizeof(ac97));
  1827. ac97.private_data = chip;
  1828. if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0)
  1829. return err;
  1830. /* seems ac97 PCM needs initialization.. hack hack.. */
  1831. snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15);
  1832. schedule_timeout_uninterruptible(msecs_to_jiffies(100));
  1833. snd_ac97_write(chip->ac97, AC97_PCM, 0);
  1834. #ifndef CONFIG_SND_MAESTRO3_INPUT
  1835. memset(&elem_id, 0, sizeof(elem_id));
  1836. elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1837. strcpy(elem_id.name, "Master Playback Switch");
  1838. chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
  1839. memset(&elem_id, 0, sizeof(elem_id));
  1840. elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1841. strcpy(elem_id.name, "Master Playback Volume");
  1842. chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
  1843. #endif
  1844. return 0;
  1845. }
  1846. /*
  1847. * initialize ASSP
  1848. */
  1849. #define MINISRC_LPF_LEN 10
  1850. static const u16 minisrc_lpf[MINISRC_LPF_LEN] = {
  1851. 0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C,
  1852. 0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F
  1853. };
  1854. static void snd_m3_assp_init(struct snd_m3 *chip)
  1855. {
  1856. unsigned int i;
  1857. const u16 *data;
  1858. /* zero kernel data */
  1859. for (i = 0; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
  1860. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1861. KDATA_BASE_ADDR + i, 0);
  1862. /* zero mixer data? */
  1863. for (i = 0; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
  1864. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1865. KDATA_BASE_ADDR2 + i, 0);
  1866. /* init dma pointer */
  1867. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1868. KDATA_CURRENT_DMA,
  1869. KDATA_DMA_XFER0);
  1870. /* write kernel into code memory.. */
  1871. data = (const u16 *)chip->assp_kernel_image->data;
  1872. for (i = 0 ; i * 2 < chip->assp_kernel_image->size; i++) {
  1873. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
  1874. REV_B_CODE_MEMORY_BEGIN + i,
  1875. le16_to_cpu(data[i]));
  1876. }
  1877. /*
  1878. * We only have this one client and we know that 0x400
  1879. * is free in our kernel's mem map, so lets just
  1880. * drop it there. It seems that the minisrc doesn't
  1881. * need vectors, so we won't bother with them..
  1882. */
  1883. data = (const u16 *)chip->assp_minisrc_image->data;
  1884. for (i = 0; i * 2 < chip->assp_minisrc_image->size; i++) {
  1885. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
  1886. 0x400 + i, le16_to_cpu(data[i]));
  1887. }
  1888. /*
  1889. * write the coefficients for the low pass filter?
  1890. */
  1891. for (i = 0; i < MINISRC_LPF_LEN ; i++) {
  1892. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
  1893. 0x400 + MINISRC_COEF_LOC + i,
  1894. minisrc_lpf[i]);
  1895. }
  1896. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
  1897. 0x400 + MINISRC_COEF_LOC + MINISRC_LPF_LEN,
  1898. 0x8000);
  1899. /*
  1900. * the minisrc is the only thing on
  1901. * our task list..
  1902. */
  1903. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1904. KDATA_TASK0,
  1905. 0x400);
  1906. /*
  1907. * init the mixer number..
  1908. */
  1909. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1910. KDATA_MIXER_TASK_NUMBER,0);
  1911. /*
  1912. * EXTREME KERNEL MASTER VOLUME
  1913. */
  1914. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1915. KDATA_DAC_LEFT_VOLUME, ARB_VOLUME);
  1916. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1917. KDATA_DAC_RIGHT_VOLUME, ARB_VOLUME);
  1918. chip->mixer_list.curlen = 0;
  1919. chip->mixer_list.mem_addr = KDATA_MIXER_XFER0;
  1920. chip->mixer_list.max = MAX_VIRTUAL_MIXER_CHANNELS;
  1921. chip->adc1_list.curlen = 0;
  1922. chip->adc1_list.mem_addr = KDATA_ADC1_XFER0;
  1923. chip->adc1_list.max = MAX_VIRTUAL_ADC1_CHANNELS;
  1924. chip->dma_list.curlen = 0;
  1925. chip->dma_list.mem_addr = KDATA_DMA_XFER0;
  1926. chip->dma_list.max = MAX_VIRTUAL_DMA_CHANNELS;
  1927. chip->msrc_list.curlen = 0;
  1928. chip->msrc_list.mem_addr = KDATA_INSTANCE0_MINISRC;
  1929. chip->msrc_list.max = MAX_INSTANCE_MINISRC;
  1930. }
  1931. static int __devinit snd_m3_assp_client_init(struct snd_m3 *chip, struct m3_dma *s, int index)
  1932. {
  1933. int data_bytes = 2 * ( MINISRC_TMP_BUFFER_SIZE / 2 +
  1934. MINISRC_IN_BUFFER_SIZE / 2 +
  1935. 1 + MINISRC_OUT_BUFFER_SIZE / 2 + 1 );
  1936. int address, i;
  1937. /*
  1938. * the revb memory map has 0x1100 through 0x1c00
  1939. * free.
  1940. */
  1941. /*
  1942. * align instance address to 256 bytes so that its
  1943. * shifted list address is aligned.
  1944. * list address = (mem address >> 1) >> 7;
  1945. */
  1946. data_bytes = ALIGN(data_bytes, 256);
  1947. address = 0x1100 + ((data_bytes/2) * index);
  1948. if ((address + (data_bytes/2)) >= 0x1c00) {
  1949. snd_printk(KERN_ERR "no memory for %d bytes at ind %d (addr 0x%x)\n",
  1950. data_bytes, index, address);
  1951. return -ENOMEM;
  1952. }
  1953. s->number = index;
  1954. s->inst.code = 0x400;
  1955. s->inst.data = address;
  1956. for (i = data_bytes / 2; i > 0; address++, i--) {
  1957. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  1958. address, 0);
  1959. }
  1960. return 0;
  1961. }
  1962. /*
  1963. * this works for the reference board, have to find
  1964. * out about others
  1965. *
  1966. * this needs more magic for 4 speaker, but..
  1967. */
  1968. static void
  1969. snd_m3_amp_enable(struct snd_m3 *chip, int enable)
  1970. {
  1971. int io = chip->iobase;
  1972. u16 gpo, polarity;
  1973. if (! chip->external_amp)
  1974. return;
  1975. polarity = enable ? 0 : 1;
  1976. polarity = polarity << chip->amp_gpio;
  1977. gpo = 1 << chip->amp_gpio;
  1978. outw(~gpo, io + GPIO_MASK);
  1979. outw(inw(io + GPIO_DIRECTION) | gpo,
  1980. io + GPIO_DIRECTION);
  1981. outw((GPO_SECONDARY_AC97 | GPO_PRIMARY_AC97 | polarity),
  1982. io + GPIO_DATA);
  1983. outw(0xffff, io + GPIO_MASK);
  1984. }
  1985. static void
  1986. snd_m3_hv_init(struct snd_m3 *chip)
  1987. {
  1988. unsigned long io = chip->iobase;
  1989. u16 val = GPI_VOL_DOWN | GPI_VOL_UP;
  1990. if (!chip->is_omnibook)
  1991. return;
  1992. /*
  1993. * Volume buttons on some HP OmniBook laptops
  1994. * require some GPIO magic to work correctly.
  1995. */
  1996. outw(0xffff, io + GPIO_MASK);
  1997. outw(0x0000, io + GPIO_DATA);
  1998. outw(~val, io + GPIO_MASK);
  1999. outw(inw(io + GPIO_DIRECTION) & ~val, io + GPIO_DIRECTION);
  2000. outw(val, io + GPIO_MASK);
  2001. outw(0xffff, io + GPIO_MASK);
  2002. }
  2003. static int
  2004. snd_m3_chip_init(struct snd_m3 *chip)
  2005. {
  2006. struct pci_dev *pcidev = chip->pci;
  2007. unsigned long io = chip->iobase;
  2008. u32 n;
  2009. u16 w;
  2010. u8 t; /* makes as much sense as 'n', no? */
  2011. pci_read_config_word(pcidev, PCI_LEGACY_AUDIO_CTRL, &w);
  2012. w &= ~(SOUND_BLASTER_ENABLE|FM_SYNTHESIS_ENABLE|
  2013. MPU401_IO_ENABLE|MPU401_IRQ_ENABLE|ALIAS_10BIT_IO|
  2014. DISABLE_LEGACY);
  2015. pci_write_config_word(pcidev, PCI_LEGACY_AUDIO_CTRL, w);
  2016. pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
  2017. n &= ~(HV_CTRL_ENABLE | REDUCED_DEBOUNCE | HV_BUTTON_FROM_GD);
  2018. n |= chip->hv_config;
  2019. /* For some reason we must always use reduced debounce. */
  2020. n |= REDUCED_DEBOUNCE;
  2021. n |= PM_CTRL_ENABLE | CLK_DIV_BY_49 | USE_PCI_TIMING;
  2022. pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
  2023. outb(RESET_ASSP, chip->iobase + ASSP_CONTROL_B);
  2024. pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
  2025. n &= ~INT_CLK_SELECT;
  2026. if (!chip->allegro_flag) {
  2027. n &= ~INT_CLK_MULT_ENABLE;
  2028. n |= INT_CLK_SRC_NOT_PCI;
  2029. }
  2030. n &= ~( CLK_MULT_MODE_SELECT | CLK_MULT_MODE_SELECT_2 );
  2031. pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
  2032. if (chip->allegro_flag) {
  2033. pci_read_config_dword(pcidev, PCI_USER_CONFIG, &n);
  2034. n |= IN_CLK_12MHZ_SELECT;
  2035. pci_write_config_dword(pcidev, PCI_USER_CONFIG, n);
  2036. }
  2037. t = inb(chip->iobase + ASSP_CONTROL_A);
  2038. t &= ~( DSP_CLK_36MHZ_SELECT | ASSP_CLK_49MHZ_SELECT);
  2039. t |= ASSP_CLK_49MHZ_SELECT;
  2040. t |= ASSP_0_WS_ENABLE;
  2041. outb(t, chip->iobase + ASSP_CONTROL_A);
  2042. snd_m3_assp_init(chip); /* download DSP code before starting ASSP below */
  2043. outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B);
  2044. outb(0x00, io + HARDWARE_VOL_CTRL);
  2045. outb(0x88, io + SHADOW_MIX_REG_VOICE);
  2046. outb(0x88, io + HW_VOL_COUNTER_VOICE);
  2047. outb(0x88, io + SHADOW_MIX_REG_MASTER);
  2048. outb(0x88, io + HW_VOL_COUNTER_MASTER);
  2049. return 0;
  2050. }
  2051. static void
  2052. snd_m3_enable_ints(struct snd_m3 *chip)
  2053. {
  2054. unsigned long io = chip->iobase;
  2055. unsigned short val;
  2056. /* TODO: MPU401 not supported yet */
  2057. val = ASSP_INT_ENABLE /*| MPU401_INT_ENABLE*/;
  2058. if (chip->hv_config & HV_CTRL_ENABLE)
  2059. val |= HV_INT_ENABLE;
  2060. outb(val, chip->iobase + HOST_INT_STATUS);
  2061. outw(val, io + HOST_INT_CTRL);
  2062. outb(inb(io + ASSP_CONTROL_C) | ASSP_HOST_INT_ENABLE,
  2063. io + ASSP_CONTROL_C);
  2064. }
  2065. /*
  2066. */
  2067. static int snd_m3_free(struct snd_m3 *chip)
  2068. {
  2069. struct m3_dma *s;
  2070. int i;
  2071. #ifdef CONFIG_SND_MAESTRO3_INPUT
  2072. if (chip->input_dev)
  2073. input_unregister_device(chip->input_dev);
  2074. #endif
  2075. if (chip->substreams) {
  2076. spin_lock_irq(&chip->reg_lock);
  2077. for (i = 0; i < chip->num_substreams; i++) {
  2078. s = &chip->substreams[i];
  2079. /* check surviving pcms; this should not happen though.. */
  2080. if (s->substream && s->running)
  2081. snd_m3_pcm_stop(chip, s, s->substream);
  2082. }
  2083. spin_unlock_irq(&chip->reg_lock);
  2084. kfree(chip->substreams);
  2085. }
  2086. if (chip->iobase) {
  2087. outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */
  2088. }
  2089. #ifdef CONFIG_PM
  2090. vfree(chip->suspend_mem);
  2091. #endif
  2092. if (chip->irq >= 0)
  2093. free_irq(chip->irq, chip);
  2094. if (chip->iobase)
  2095. pci_release_regions(chip->pci);
  2096. release_firmware(chip->assp_kernel_image);
  2097. release_firmware(chip->assp_minisrc_image);
  2098. pci_disable_device(chip->pci);
  2099. kfree(chip);
  2100. return 0;
  2101. }
  2102. /*
  2103. * APM support
  2104. */
  2105. #ifdef CONFIG_PM
  2106. static int m3_suspend(struct pci_dev *pci, pm_message_t state)
  2107. {
  2108. struct snd_card *card = pci_get_drvdata(pci);
  2109. struct snd_m3 *chip = card->private_data;
  2110. int i, dsp_index;
  2111. if (chip->suspend_mem == NULL)
  2112. return 0;
  2113. chip->in_suspend = 1;
  2114. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  2115. snd_pcm_suspend_all(chip->pcm);
  2116. snd_ac97_suspend(chip->ac97);
  2117. msleep(10); /* give the assp a chance to idle.. */
  2118. snd_m3_assp_halt(chip);
  2119. /* save dsp image */
  2120. dsp_index = 0;
  2121. for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
  2122. chip->suspend_mem[dsp_index++] =
  2123. snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i);
  2124. for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
  2125. chip->suspend_mem[dsp_index++] =
  2126. snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
  2127. pci_disable_device(pci);
  2128. pci_save_state(pci);
  2129. pci_set_power_state(pci, pci_choose_state(pci, state));
  2130. return 0;
  2131. }
  2132. static int m3_resume(struct pci_dev *pci)
  2133. {
  2134. struct snd_card *card = pci_get_drvdata(pci);
  2135. struct snd_m3 *chip = card->private_data;
  2136. int i, dsp_index;
  2137. if (chip->suspend_mem == NULL)
  2138. return 0;
  2139. pci_set_power_state(pci, PCI_D0);
  2140. pci_restore_state(pci);
  2141. if (pci_enable_device(pci) < 0) {
  2142. printk(KERN_ERR "maestor3: pci_enable_device failed, "
  2143. "disabling device\n");
  2144. snd_card_disconnect(card);
  2145. return -EIO;
  2146. }
  2147. pci_set_master(pci);
  2148. /* first lets just bring everything back. .*/
  2149. snd_m3_outw(chip, 0, 0x54);
  2150. snd_m3_outw(chip, 0, 0x56);
  2151. snd_m3_chip_init(chip);
  2152. snd_m3_assp_halt(chip);
  2153. snd_m3_ac97_reset(chip);
  2154. /* restore dsp image */
  2155. dsp_index = 0;
  2156. for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
  2157. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i,
  2158. chip->suspend_mem[dsp_index++]);
  2159. for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
  2160. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i,
  2161. chip->suspend_mem[dsp_index++]);
  2162. /* tell the dma engine to restart itself */
  2163. snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
  2164. KDATA_DMA_ACTIVE, 0);
  2165. /* restore ac97 registers */
  2166. snd_ac97_resume(chip->ac97);
  2167. snd_m3_assp_continue(chip);
  2168. snd_m3_enable_ints(chip);
  2169. snd_m3_amp_enable(chip, 1);
  2170. snd_m3_hv_init(chip);
  2171. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  2172. chip->in_suspend = 0;
  2173. return 0;
  2174. }
  2175. #endif /* CONFIG_PM */
  2176. #ifdef CONFIG_SND_MAESTRO3_INPUT
  2177. static int __devinit snd_m3_input_register(struct snd_m3 *chip)
  2178. {
  2179. struct input_dev *input_dev;
  2180. int err;
  2181. input_dev = input_allocate_device();
  2182. if (!input_dev)
  2183. return -ENOMEM;
  2184. snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0",
  2185. pci_name(chip->pci));
  2186. input_dev->name = chip->card->driver;
  2187. input_dev->phys = chip->phys;
  2188. input_dev->id.bustype = BUS_PCI;
  2189. input_dev->id.vendor = chip->pci->vendor;
  2190. input_dev->id.product = chip->pci->device;
  2191. input_dev->dev.parent = &chip->pci->dev;
  2192. __set_bit(EV_KEY, input_dev->evbit);
  2193. __set_bit(KEY_MUTE, input_dev->keybit);
  2194. __set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
  2195. __set_bit(KEY_VOLUMEUP, input_dev->keybit);
  2196. err = input_register_device(input_dev);
  2197. if (err) {
  2198. input_free_device(input_dev);
  2199. return err;
  2200. }
  2201. chip->input_dev = input_dev;
  2202. return 0;
  2203. }
  2204. #endif /* CONFIG_INPUT */
  2205. /*
  2206. */
  2207. static int snd_m3_dev_free(struct snd_device *device)
  2208. {
  2209. struct snd_m3 *chip = device->device_data;
  2210. return snd_m3_free(chip);
  2211. }
  2212. static int __devinit
  2213. snd_m3_create(struct snd_card *card, struct pci_dev *pci,
  2214. int enable_amp,
  2215. int amp_gpio,
  2216. struct snd_m3 **chip_ret)
  2217. {
  2218. struct snd_m3 *chip;
  2219. int i, err;
  2220. const struct snd_pci_quirk *quirk;
  2221. static struct snd_device_ops ops = {
  2222. .dev_free = snd_m3_dev_free,
  2223. };
  2224. *chip_ret = NULL;
  2225. if (pci_enable_device(pci))
  2226. return -EIO;
  2227. /* check, if we can restrict PCI DMA transfers to 28 bits */
  2228. if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
  2229. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
  2230. snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
  2231. pci_disable_device(pci);
  2232. return -ENXIO;
  2233. }
  2234. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2235. if (chip == NULL) {
  2236. pci_disable_device(pci);
  2237. return -ENOMEM;
  2238. }
  2239. spin_lock_init(&chip->reg_lock);
  2240. #ifndef CONFIG_SND_MAESTRO3_INPUT
  2241. spin_lock_init(&chip->ac97_lock);
  2242. #endif
  2243. switch (pci->device) {
  2244. case PCI_DEVICE_ID_ESS_ALLEGRO:
  2245. case PCI_DEVICE_ID_ESS_ALLEGRO_1:
  2246. case PCI_DEVICE_ID_ESS_CANYON3D_2LE:
  2247. case PCI_DEVICE_ID_ESS_CANYON3D_2:
  2248. chip->allegro_flag = 1;
  2249. break;
  2250. }
  2251. chip->card = card;
  2252. chip->pci = pci;
  2253. chip->irq = -1;
  2254. chip->external_amp = enable_amp;
  2255. if (amp_gpio >= 0 && amp_gpio <= 0x0f)
  2256. chip->amp_gpio = amp_gpio;
  2257. else {
  2258. quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list);
  2259. if (quirk) {
  2260. snd_printdd(KERN_INFO "maestro3: set amp-gpio "
  2261. "for '%s'\n", quirk->name);
  2262. chip->amp_gpio = quirk->value;
  2263. } else if (chip->allegro_flag)
  2264. chip->amp_gpio = GPO_EXT_AMP_ALLEGRO;
  2265. else /* presumably this is for all 'maestro3's.. */
  2266. chip->amp_gpio = GPO_EXT_AMP_M3;
  2267. }
  2268. quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list);
  2269. if (quirk) {
  2270. snd_printdd(KERN_INFO "maestro3: enabled irda workaround "
  2271. "for '%s'\n", quirk->name);
  2272. chip->irda_workaround = 1;
  2273. }
  2274. quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list);
  2275. if (quirk)
  2276. chip->hv_config = quirk->value;
  2277. if (snd_pci_quirk_lookup(pci, m3_omnibook_quirk_list))
  2278. chip->is_omnibook = 1;
  2279. chip->num_substreams = NR_DSPS;
  2280. chip->substreams = kcalloc(chip->num_substreams, sizeof(struct m3_dma),
  2281. GFP_KERNEL);
  2282. if (chip->substreams == NULL) {
  2283. kfree(chip);
  2284. pci_disable_device(pci);
  2285. return -ENOMEM;
  2286. }
  2287. err = request_firmware(&chip->assp_kernel_image,
  2288. "ess/maestro3_assp_kernel.fw", &pci->dev);
  2289. if (err < 0) {
  2290. snd_m3_free(chip);
  2291. return err;
  2292. }
  2293. err = request_firmware(&chip->assp_minisrc_image,
  2294. "ess/maestro3_assp_minisrc.fw", &pci->dev);
  2295. if (err < 0) {
  2296. snd_m3_free(chip);
  2297. return err;
  2298. }
  2299. if ((err = pci_request_regions(pci, card->driver)) < 0) {
  2300. snd_m3_free(chip);
  2301. return err;
  2302. }
  2303. chip->iobase = pci_resource_start(pci, 0);
  2304. /* just to be sure */
  2305. pci_set_master(pci);
  2306. snd_m3_chip_init(chip);
  2307. snd_m3_assp_halt(chip);
  2308. snd_m3_ac97_reset(chip);
  2309. snd_m3_amp_enable(chip, 1);
  2310. snd_m3_hv_init(chip);
  2311. #ifndef CONFIG_SND_MAESTRO3_INPUT
  2312. tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
  2313. #endif
  2314. if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
  2315. card->driver, chip)) {
  2316. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  2317. snd_m3_free(chip);
  2318. return -ENOMEM;
  2319. }
  2320. chip->irq = pci->irq;
  2321. #ifdef CONFIG_PM
  2322. chip->suspend_mem = vmalloc(sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH));
  2323. if (chip->suspend_mem == NULL)
  2324. snd_printk(KERN_WARNING "can't allocate apm buffer\n");
  2325. #endif
  2326. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  2327. snd_m3_free(chip);
  2328. return err;
  2329. }
  2330. if ((err = snd_m3_mixer(chip)) < 0)
  2331. return err;
  2332. for (i = 0; i < chip->num_substreams; i++) {
  2333. struct m3_dma *s = &chip->substreams[i];
  2334. if ((err = snd_m3_assp_client_init(chip, s, i)) < 0)
  2335. return err;
  2336. }
  2337. if ((err = snd_m3_pcm(chip, 0)) < 0)
  2338. return err;
  2339. #ifdef CONFIG_SND_MAESTRO3_INPUT
  2340. if (chip->hv_config & HV_CTRL_ENABLE) {
  2341. err = snd_m3_input_register(chip);
  2342. if (err)
  2343. snd_printk(KERN_WARNING "Input device registration "
  2344. "failed with error %i", err);
  2345. }
  2346. #endif
  2347. snd_m3_enable_ints(chip);
  2348. snd_m3_assp_continue(chip);
  2349. snd_card_set_dev(card, &pci->dev);
  2350. *chip_ret = chip;
  2351. return 0;
  2352. }
  2353. /*
  2354. */
  2355. static int __devinit
  2356. snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  2357. {
  2358. static int dev;
  2359. struct snd_card *card;
  2360. struct snd_m3 *chip;
  2361. int err;
  2362. /* don't pick up modems */
  2363. if (((pci->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
  2364. return -ENODEV;
  2365. if (dev >= SNDRV_CARDS)
  2366. return -ENODEV;
  2367. if (!enable[dev]) {
  2368. dev++;
  2369. return -ENOENT;
  2370. }
  2371. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  2372. if (err < 0)
  2373. return err;
  2374. switch (pci->device) {
  2375. case PCI_DEVICE_ID_ESS_ALLEGRO:
  2376. case PCI_DEVICE_ID_ESS_ALLEGRO_1:
  2377. strcpy(card->driver, "Allegro");
  2378. break;
  2379. case PCI_DEVICE_ID_ESS_CANYON3D_2LE:
  2380. case PCI_DEVICE_ID_ESS_CANYON3D_2:
  2381. strcpy(card->driver, "Canyon3D-2");
  2382. break;
  2383. default:
  2384. strcpy(card->driver, "Maestro3");
  2385. break;
  2386. }
  2387. if ((err = snd_m3_create(card, pci,
  2388. external_amp[dev],
  2389. amp_gpio[dev],
  2390. &chip)) < 0) {
  2391. snd_card_free(card);
  2392. return err;
  2393. }
  2394. card->private_data = chip;
  2395. sprintf(card->shortname, "ESS %s PCI", card->driver);
  2396. sprintf(card->longname, "%s at 0x%lx, irq %d",
  2397. card->shortname, chip->iobase, chip->irq);
  2398. if ((err = snd_card_register(card)) < 0) {
  2399. snd_card_free(card);
  2400. return err;
  2401. }
  2402. #if 0 /* TODO: not supported yet */
  2403. /* TODO enable MIDI IRQ and I/O */
  2404. err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
  2405. chip->iobase + MPU401_DATA_PORT,
  2406. MPU401_INFO_INTEGRATED,
  2407. chip->irq, 0, &chip->rmidi);
  2408. if (err < 0)
  2409. printk(KERN_WARNING "maestro3: no MIDI support.\n");
  2410. #endif
  2411. pci_set_drvdata(pci, card);
  2412. dev++;
  2413. return 0;
  2414. }
  2415. static void __devexit snd_m3_remove(struct pci_dev *pci)
  2416. {
  2417. snd_card_free(pci_get_drvdata(pci));
  2418. pci_set_drvdata(pci, NULL);
  2419. }
  2420. static struct pci_driver driver = {
  2421. .name = "Maestro3",
  2422. .id_table = snd_m3_ids,
  2423. .probe = snd_m3_probe,
  2424. .remove = __devexit_p(snd_m3_remove),
  2425. #ifdef CONFIG_PM
  2426. .suspend = m3_suspend,
  2427. .resume = m3_resume,
  2428. #endif
  2429. };
  2430. static int __init alsa_card_m3_init(void)
  2431. {
  2432. return pci_register_driver(&driver);
  2433. }
  2434. static void __exit alsa_card_m3_exit(void)
  2435. {
  2436. pci_unregister_driver(&driver);
  2437. }
  2438. module_init(alsa_card_m3_init)
  2439. module_exit(alsa_card_m3_exit)