maestro3.c 84 KB

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