maestro3.c 81 KB

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