maestro3.c 82 KB

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