maestro3.c 92 KB

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