maestro3.c 92 KB

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