hda_intel.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850
  1. /*
  2. *
  3. * hda_intel.c - Implementation of primary alsa driver code base
  4. * for Intel HD Audio.
  5. *
  6. * Copyright(c) 2004 Intel Corporation. All rights reserved.
  7. *
  8. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  9. * PeiSen Hou <pshou@realtek.com.tw>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  19. * more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along with
  22. * this program; if not, write to the Free Software Foundation, Inc., 59
  23. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. *
  25. * CONTACTS:
  26. *
  27. * Matt Jared matt.jared@intel.com
  28. * Andy Kopp andy.kopp@intel.com
  29. * Dan Kogan dan.d.kogan@intel.com
  30. *
  31. * CHANGES:
  32. *
  33. * 2004.12.01 Major rewrite by tiwai, merged the work of pshou
  34. *
  35. */
  36. #include <asm/io.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/kernel.h>
  40. #include <linux/module.h>
  41. #include <linux/dma-mapping.h>
  42. #include <linux/moduleparam.h>
  43. #include <linux/init.h>
  44. #include <linux/slab.h>
  45. #include <linux/pci.h>
  46. #include <linux/mutex.h>
  47. #include <linux/reboot.h>
  48. #include <sound/core.h>
  49. #include <sound/initval.h>
  50. #include "hda_codec.h"
  51. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  52. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  53. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  54. static char *model[SNDRV_CARDS];
  55. static int position_fix[SNDRV_CARDS];
  56. static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  57. static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  58. static int probe_only[SNDRV_CARDS];
  59. static int single_cmd;
  60. static int enable_msi = -1;
  61. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  62. static char *patch[SNDRV_CARDS];
  63. #endif
  64. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  65. static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
  66. CONFIG_SND_HDA_INPUT_BEEP_MODE};
  67. #endif
  68. module_param_array(index, int, NULL, 0444);
  69. MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
  70. module_param_array(id, charp, NULL, 0444);
  71. MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
  72. module_param_array(enable, bool, NULL, 0444);
  73. MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
  74. module_param_array(model, charp, NULL, 0444);
  75. MODULE_PARM_DESC(model, "Use the given board model.");
  76. module_param_array(position_fix, int, NULL, 0444);
  77. MODULE_PARM_DESC(position_fix, "DMA pointer read method."
  78. "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO).");
  79. module_param_array(bdl_pos_adj, int, NULL, 0644);
  80. MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
  81. module_param_array(probe_mask, int, NULL, 0444);
  82. MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
  83. module_param_array(probe_only, int, NULL, 0444);
  84. MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
  85. module_param(single_cmd, bool, 0444);
  86. MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
  87. "(for debugging only).");
  88. module_param(enable_msi, int, 0444);
  89. MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
  90. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  91. module_param_array(patch, charp, NULL, 0444);
  92. MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
  93. #endif
  94. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  95. module_param_array(beep_mode, int, NULL, 0444);
  96. MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
  97. "(0=off, 1=on, 2=mute switch on/off) (default=1).");
  98. #endif
  99. #ifdef CONFIG_SND_HDA_POWER_SAVE
  100. static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
  101. module_param(power_save, int, 0644);
  102. MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
  103. "(in second, 0 = disable).");
  104. /* reset the HD-audio controller in power save mode.
  105. * this may give more power-saving, but will take longer time to
  106. * wake up.
  107. */
  108. static int power_save_controller = 1;
  109. module_param(power_save_controller, bool, 0644);
  110. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  111. #endif
  112. MODULE_LICENSE("GPL");
  113. MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
  114. "{Intel, ICH6M},"
  115. "{Intel, ICH7},"
  116. "{Intel, ESB2},"
  117. "{Intel, ICH8},"
  118. "{Intel, ICH9},"
  119. "{Intel, ICH10},"
  120. "{Intel, PCH},"
  121. "{Intel, CPT},"
  122. "{Intel, PBG},"
  123. "{Intel, SCH},"
  124. "{ATI, SB450},"
  125. "{ATI, SB600},"
  126. "{ATI, RS600},"
  127. "{ATI, RS690},"
  128. "{ATI, RS780},"
  129. "{ATI, R600},"
  130. "{ATI, RV630},"
  131. "{ATI, RV610},"
  132. "{ATI, RV670},"
  133. "{ATI, RV635},"
  134. "{ATI, RV620},"
  135. "{ATI, RV770},"
  136. "{VIA, VT8251},"
  137. "{VIA, VT8237A},"
  138. "{SiS, SIS966},"
  139. "{ULI, M5461}}");
  140. MODULE_DESCRIPTION("Intel HDA driver");
  141. #ifdef CONFIG_SND_VERBOSE_PRINTK
  142. #define SFX /* nop */
  143. #else
  144. #define SFX "hda-intel: "
  145. #endif
  146. /*
  147. * registers
  148. */
  149. #define ICH6_REG_GCAP 0x00
  150. #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
  151. #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  152. #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  153. #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
  154. #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
  155. #define ICH6_REG_VMIN 0x02
  156. #define ICH6_REG_VMAJ 0x03
  157. #define ICH6_REG_OUTPAY 0x04
  158. #define ICH6_REG_INPAY 0x06
  159. #define ICH6_REG_GCTL 0x08
  160. #define ICH6_GCTL_RESET (1 << 0) /* controller reset */
  161. #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
  162. #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  163. #define ICH6_REG_WAKEEN 0x0c
  164. #define ICH6_REG_STATESTS 0x0e
  165. #define ICH6_REG_GSTS 0x10
  166. #define ICH6_GSTS_FSTS (1 << 1) /* flush status */
  167. #define ICH6_REG_INTCTL 0x20
  168. #define ICH6_REG_INTSTS 0x24
  169. #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
  170. #define ICH6_REG_SYNC 0x34
  171. #define ICH6_REG_CORBLBASE 0x40
  172. #define ICH6_REG_CORBUBASE 0x44
  173. #define ICH6_REG_CORBWP 0x48
  174. #define ICH6_REG_CORBRP 0x4a
  175. #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
  176. #define ICH6_REG_CORBCTL 0x4c
  177. #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
  178. #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  179. #define ICH6_REG_CORBSTS 0x4d
  180. #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
  181. #define ICH6_REG_CORBSIZE 0x4e
  182. #define ICH6_REG_RIRBLBASE 0x50
  183. #define ICH6_REG_RIRBUBASE 0x54
  184. #define ICH6_REG_RIRBWP 0x58
  185. #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
  186. #define ICH6_REG_RINTCNT 0x5a
  187. #define ICH6_REG_RIRBCTL 0x5c
  188. #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  189. #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  190. #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  191. #define ICH6_REG_RIRBSTS 0x5d
  192. #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
  193. #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  194. #define ICH6_REG_RIRBSIZE 0x5e
  195. #define ICH6_REG_IC 0x60
  196. #define ICH6_REG_IR 0x64
  197. #define ICH6_REG_IRS 0x68
  198. #define ICH6_IRS_VALID (1<<1)
  199. #define ICH6_IRS_BUSY (1<<0)
  200. #define ICH6_REG_DPLBASE 0x70
  201. #define ICH6_REG_DPUBASE 0x74
  202. #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  203. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  204. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  205. /* stream register offsets from stream base */
  206. #define ICH6_REG_SD_CTL 0x00
  207. #define ICH6_REG_SD_STS 0x03
  208. #define ICH6_REG_SD_LPIB 0x04
  209. #define ICH6_REG_SD_CBL 0x08
  210. #define ICH6_REG_SD_LVI 0x0c
  211. #define ICH6_REG_SD_FIFOW 0x0e
  212. #define ICH6_REG_SD_FIFOSIZE 0x10
  213. #define ICH6_REG_SD_FORMAT 0x12
  214. #define ICH6_REG_SD_BDLPL 0x18
  215. #define ICH6_REG_SD_BDLPU 0x1c
  216. /* PCI space */
  217. #define ICH6_PCIREG_TCSEL 0x44
  218. /*
  219. * other constants
  220. */
  221. /* max number of SDs */
  222. /* ICH, ATI and VIA have 4 playback and 4 capture */
  223. #define ICH6_NUM_CAPTURE 4
  224. #define ICH6_NUM_PLAYBACK 4
  225. /* ULI has 6 playback and 5 capture */
  226. #define ULI_NUM_CAPTURE 5
  227. #define ULI_NUM_PLAYBACK 6
  228. /* ATI HDMI has 1 playback and 0 capture */
  229. #define ATIHDMI_NUM_CAPTURE 0
  230. #define ATIHDMI_NUM_PLAYBACK 1
  231. /* TERA has 4 playback and 3 capture */
  232. #define TERA_NUM_CAPTURE 3
  233. #define TERA_NUM_PLAYBACK 4
  234. /* this number is statically defined for simplicity */
  235. #define MAX_AZX_DEV 16
  236. /* max number of fragments - we may use more if allocating more pages for BDL */
  237. #define BDL_SIZE 4096
  238. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  239. #define AZX_MAX_FRAG 32
  240. /* max buffer size - no h/w limit, you can increase as you like */
  241. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  242. /* RIRB int mask: overrun[2], response[0] */
  243. #define RIRB_INT_RESPONSE 0x01
  244. #define RIRB_INT_OVERRUN 0x04
  245. #define RIRB_INT_MASK 0x05
  246. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  247. #define AZX_MAX_CODECS 8
  248. #define AZX_DEFAULT_CODECS 4
  249. #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
  250. /* SD_CTL bits */
  251. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  252. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  253. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  254. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  255. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  256. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  257. #define SD_CTL_STREAM_TAG_SHIFT 20
  258. /* SD_CTL and SD_STS */
  259. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  260. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  261. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  262. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  263. SD_INT_COMPLETE)
  264. /* SD_STS */
  265. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  266. /* INTCTL and INTSTS */
  267. #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
  268. #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  269. #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  270. /* below are so far hardcoded - should read registers in future */
  271. #define ICH6_MAX_CORB_ENTRIES 256
  272. #define ICH6_MAX_RIRB_ENTRIES 256
  273. /* position fix mode */
  274. enum {
  275. POS_FIX_AUTO,
  276. POS_FIX_LPIB,
  277. POS_FIX_POSBUF,
  278. POS_FIX_VIACOMBO,
  279. };
  280. /* Defines for ATI HD Audio support in SB450 south bridge */
  281. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  282. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  283. /* Defines for Nvidia HDA support */
  284. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  285. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  286. #define NVIDIA_HDA_ISTRM_COH 0x4d
  287. #define NVIDIA_HDA_OSTRM_COH 0x4c
  288. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  289. /* Defines for Intel SCH HDA snoop control */
  290. #define INTEL_SCH_HDA_DEVC 0x78
  291. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  292. /* Define IN stream 0 FIFO size offset in VIA controller */
  293. #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
  294. /* Define VIA HD Audio Device ID*/
  295. #define VIA_HDAC_DEVICE_ID 0x3288
  296. /* HD Audio class code */
  297. #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
  298. /*
  299. */
  300. struct azx_dev {
  301. struct snd_dma_buffer bdl; /* BDL buffer */
  302. u32 *posbuf; /* position buffer pointer */
  303. unsigned int bufsize; /* size of the play buffer in bytes */
  304. unsigned int period_bytes; /* size of the period in bytes */
  305. unsigned int frags; /* number for period in the play buffer */
  306. unsigned int fifo_size; /* FIFO size */
  307. unsigned long start_wallclk; /* start + minimum wallclk */
  308. unsigned long period_wallclk; /* wallclk for period */
  309. void __iomem *sd_addr; /* stream descriptor pointer */
  310. u32 sd_int_sta_mask; /* stream int status mask */
  311. /* pcm support */
  312. struct snd_pcm_substream *substream; /* assigned substream,
  313. * set in PCM open
  314. */
  315. unsigned int format_val; /* format value to be set in the
  316. * controller and the codec
  317. */
  318. unsigned char stream_tag; /* assigned stream */
  319. unsigned char index; /* stream index */
  320. int device; /* last device number assigned to */
  321. unsigned int opened :1;
  322. unsigned int running :1;
  323. unsigned int irq_pending :1;
  324. /*
  325. * For VIA:
  326. * A flag to ensure DMA position is 0
  327. * when link position is not greater than FIFO size
  328. */
  329. unsigned int insufficient :1;
  330. };
  331. /* CORB/RIRB */
  332. struct azx_rb {
  333. u32 *buf; /* CORB/RIRB buffer
  334. * Each CORB entry is 4byte, RIRB is 8byte
  335. */
  336. dma_addr_t addr; /* physical address of CORB/RIRB buffer */
  337. /* for RIRB */
  338. unsigned short rp, wp; /* read/write pointers */
  339. int cmds[AZX_MAX_CODECS]; /* number of pending requests */
  340. u32 res[AZX_MAX_CODECS]; /* last read value */
  341. };
  342. struct azx {
  343. struct snd_card *card;
  344. struct pci_dev *pci;
  345. int dev_index;
  346. /* chip type specific */
  347. int driver_type;
  348. int playback_streams;
  349. int playback_index_offset;
  350. int capture_streams;
  351. int capture_index_offset;
  352. int num_streams;
  353. /* pci resources */
  354. unsigned long addr;
  355. void __iomem *remap_addr;
  356. int irq;
  357. /* locks */
  358. spinlock_t reg_lock;
  359. struct mutex open_mutex;
  360. /* streams (x num_streams) */
  361. struct azx_dev *azx_dev;
  362. /* PCM */
  363. struct snd_pcm *pcm[HDA_MAX_PCMS];
  364. /* HD codec */
  365. unsigned short codec_mask;
  366. int codec_probe_mask; /* copied from probe_mask option */
  367. struct hda_bus *bus;
  368. unsigned int beep_mode;
  369. /* CORB/RIRB */
  370. struct azx_rb corb;
  371. struct azx_rb rirb;
  372. /* CORB/RIRB and position buffers */
  373. struct snd_dma_buffer rb;
  374. struct snd_dma_buffer posbuf;
  375. /* flags */
  376. int position_fix[2]; /* for both playback/capture streams */
  377. int poll_count;
  378. unsigned int running :1;
  379. unsigned int initialized :1;
  380. unsigned int single_cmd :1;
  381. unsigned int polling_mode :1;
  382. unsigned int msi :1;
  383. unsigned int irq_pending_warned :1;
  384. unsigned int probing :1; /* codec probing phase */
  385. /* for debugging */
  386. unsigned int last_cmd[AZX_MAX_CODECS];
  387. /* for pending irqs */
  388. struct work_struct irq_pending_work;
  389. /* reboot notifier (for mysterious hangup problem at power-down) */
  390. struct notifier_block reboot_notifier;
  391. };
  392. /* driver types */
  393. enum {
  394. AZX_DRIVER_ICH,
  395. AZX_DRIVER_PCH,
  396. AZX_DRIVER_SCH,
  397. AZX_DRIVER_ATI,
  398. AZX_DRIVER_ATIHDMI,
  399. AZX_DRIVER_VIA,
  400. AZX_DRIVER_SIS,
  401. AZX_DRIVER_ULI,
  402. AZX_DRIVER_NVIDIA,
  403. AZX_DRIVER_TERA,
  404. AZX_DRIVER_CTX,
  405. AZX_DRIVER_GENERIC,
  406. AZX_NUM_DRIVERS, /* keep this as last entry */
  407. };
  408. static char *driver_short_names[] __devinitdata = {
  409. [AZX_DRIVER_ICH] = "HDA Intel",
  410. [AZX_DRIVER_PCH] = "HDA Intel PCH",
  411. [AZX_DRIVER_SCH] = "HDA Intel MID",
  412. [AZX_DRIVER_ATI] = "HDA ATI SB",
  413. [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
  414. [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
  415. [AZX_DRIVER_SIS] = "HDA SIS966",
  416. [AZX_DRIVER_ULI] = "HDA ULI M5461",
  417. [AZX_DRIVER_NVIDIA] = "HDA NVidia",
  418. [AZX_DRIVER_TERA] = "HDA Teradici",
  419. [AZX_DRIVER_CTX] = "HDA Creative",
  420. [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
  421. };
  422. /*
  423. * macros for easy use
  424. */
  425. #define azx_writel(chip,reg,value) \
  426. writel(value, (chip)->remap_addr + ICH6_REG_##reg)
  427. #define azx_readl(chip,reg) \
  428. readl((chip)->remap_addr + ICH6_REG_##reg)
  429. #define azx_writew(chip,reg,value) \
  430. writew(value, (chip)->remap_addr + ICH6_REG_##reg)
  431. #define azx_readw(chip,reg) \
  432. readw((chip)->remap_addr + ICH6_REG_##reg)
  433. #define azx_writeb(chip,reg,value) \
  434. writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
  435. #define azx_readb(chip,reg) \
  436. readb((chip)->remap_addr + ICH6_REG_##reg)
  437. #define azx_sd_writel(dev,reg,value) \
  438. writel(value, (dev)->sd_addr + ICH6_REG_##reg)
  439. #define azx_sd_readl(dev,reg) \
  440. readl((dev)->sd_addr + ICH6_REG_##reg)
  441. #define azx_sd_writew(dev,reg,value) \
  442. writew(value, (dev)->sd_addr + ICH6_REG_##reg)
  443. #define azx_sd_readw(dev,reg) \
  444. readw((dev)->sd_addr + ICH6_REG_##reg)
  445. #define azx_sd_writeb(dev,reg,value) \
  446. writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
  447. #define azx_sd_readb(dev,reg) \
  448. readb((dev)->sd_addr + ICH6_REG_##reg)
  449. /* for pcm support */
  450. #define get_azx_dev(substream) (substream->runtime->private_data)
  451. static int azx_acquire_irq(struct azx *chip, int do_disconnect);
  452. static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
  453. /*
  454. * Interface for HD codec
  455. */
  456. /*
  457. * CORB / RIRB interface
  458. */
  459. static int azx_alloc_cmd_io(struct azx *chip)
  460. {
  461. int err;
  462. /* single page (at least 4096 bytes) must suffice for both ringbuffes */
  463. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  464. snd_dma_pci_data(chip->pci),
  465. PAGE_SIZE, &chip->rb);
  466. if (err < 0) {
  467. snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
  468. return err;
  469. }
  470. return 0;
  471. }
  472. static void azx_init_cmd_io(struct azx *chip)
  473. {
  474. spin_lock_irq(&chip->reg_lock);
  475. /* CORB set up */
  476. chip->corb.addr = chip->rb.addr;
  477. chip->corb.buf = (u32 *)chip->rb.area;
  478. azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
  479. azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
  480. /* set the corb size to 256 entries (ULI requires explicitly) */
  481. azx_writeb(chip, CORBSIZE, 0x02);
  482. /* set the corb write pointer to 0 */
  483. azx_writew(chip, CORBWP, 0);
  484. /* reset the corb hw read pointer */
  485. azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
  486. /* enable corb dma */
  487. azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
  488. /* RIRB set up */
  489. chip->rirb.addr = chip->rb.addr + 2048;
  490. chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
  491. chip->rirb.wp = chip->rirb.rp = 0;
  492. memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
  493. azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
  494. azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
  495. /* set the rirb size to 256 entries (ULI requires explicitly) */
  496. azx_writeb(chip, RIRBSIZE, 0x02);
  497. /* reset the rirb hw write pointer */
  498. azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
  499. /* set N=1, get RIRB response interrupt for new entry */
  500. if (chip->driver_type == AZX_DRIVER_CTX)
  501. azx_writew(chip, RINTCNT, 0xc0);
  502. else
  503. azx_writew(chip, RINTCNT, 1);
  504. /* enable rirb dma and response irq */
  505. azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
  506. spin_unlock_irq(&chip->reg_lock);
  507. }
  508. static void azx_free_cmd_io(struct azx *chip)
  509. {
  510. spin_lock_irq(&chip->reg_lock);
  511. /* disable ringbuffer DMAs */
  512. azx_writeb(chip, RIRBCTL, 0);
  513. azx_writeb(chip, CORBCTL, 0);
  514. spin_unlock_irq(&chip->reg_lock);
  515. }
  516. static unsigned int azx_command_addr(u32 cmd)
  517. {
  518. unsigned int addr = cmd >> 28;
  519. if (addr >= AZX_MAX_CODECS) {
  520. snd_BUG();
  521. addr = 0;
  522. }
  523. return addr;
  524. }
  525. static unsigned int azx_response_addr(u32 res)
  526. {
  527. unsigned int addr = res & 0xf;
  528. if (addr >= AZX_MAX_CODECS) {
  529. snd_BUG();
  530. addr = 0;
  531. }
  532. return addr;
  533. }
  534. /* send a command */
  535. static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
  536. {
  537. struct azx *chip = bus->private_data;
  538. unsigned int addr = azx_command_addr(val);
  539. unsigned int wp;
  540. spin_lock_irq(&chip->reg_lock);
  541. /* add command to corb */
  542. wp = azx_readb(chip, CORBWP);
  543. wp++;
  544. wp %= ICH6_MAX_CORB_ENTRIES;
  545. chip->rirb.cmds[addr]++;
  546. chip->corb.buf[wp] = cpu_to_le32(val);
  547. azx_writel(chip, CORBWP, wp);
  548. spin_unlock_irq(&chip->reg_lock);
  549. return 0;
  550. }
  551. #define ICH6_RIRB_EX_UNSOL_EV (1<<4)
  552. /* retrieve RIRB entry - called from interrupt handler */
  553. static void azx_update_rirb(struct azx *chip)
  554. {
  555. unsigned int rp, wp;
  556. unsigned int addr;
  557. u32 res, res_ex;
  558. wp = azx_readb(chip, RIRBWP);
  559. if (wp == chip->rirb.wp)
  560. return;
  561. chip->rirb.wp = wp;
  562. while (chip->rirb.rp != wp) {
  563. chip->rirb.rp++;
  564. chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
  565. rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
  566. res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
  567. res = le32_to_cpu(chip->rirb.buf[rp]);
  568. addr = azx_response_addr(res_ex);
  569. if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
  570. snd_hda_queue_unsol_event(chip->bus, res, res_ex);
  571. else if (chip->rirb.cmds[addr]) {
  572. chip->rirb.res[addr] = res;
  573. smp_wmb();
  574. chip->rirb.cmds[addr]--;
  575. } else
  576. snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "
  577. "last cmd=%#08x\n",
  578. res, res_ex,
  579. chip->last_cmd[addr]);
  580. }
  581. }
  582. /* receive a response */
  583. static unsigned int azx_rirb_get_response(struct hda_bus *bus,
  584. unsigned int addr)
  585. {
  586. struct azx *chip = bus->private_data;
  587. unsigned long timeout;
  588. int do_poll = 0;
  589. again:
  590. timeout = jiffies + msecs_to_jiffies(1000);
  591. for (;;) {
  592. if (chip->polling_mode || do_poll) {
  593. spin_lock_irq(&chip->reg_lock);
  594. azx_update_rirb(chip);
  595. spin_unlock_irq(&chip->reg_lock);
  596. }
  597. if (!chip->rirb.cmds[addr]) {
  598. smp_rmb();
  599. bus->rirb_error = 0;
  600. if (!do_poll)
  601. chip->poll_count = 0;
  602. return chip->rirb.res[addr]; /* the last value */
  603. }
  604. if (time_after(jiffies, timeout))
  605. break;
  606. if (bus->needs_damn_long_delay)
  607. msleep(2); /* temporary workaround */
  608. else {
  609. udelay(10);
  610. cond_resched();
  611. }
  612. }
  613. if (!chip->polling_mode && chip->poll_count < 2) {
  614. snd_printdd(SFX "azx_get_response timeout, "
  615. "polling the codec once: last cmd=0x%08x\n",
  616. chip->last_cmd[addr]);
  617. do_poll = 1;
  618. chip->poll_count++;
  619. goto again;
  620. }
  621. if (!chip->polling_mode) {
  622. snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
  623. "switching to polling mode: last cmd=0x%08x\n",
  624. chip->last_cmd[addr]);
  625. chip->polling_mode = 1;
  626. goto again;
  627. }
  628. if (chip->msi) {
  629. snd_printk(KERN_WARNING SFX "No response from codec, "
  630. "disabling MSI: last cmd=0x%08x\n",
  631. chip->last_cmd[addr]);
  632. free_irq(chip->irq, chip);
  633. chip->irq = -1;
  634. pci_disable_msi(chip->pci);
  635. chip->msi = 0;
  636. if (azx_acquire_irq(chip, 1) < 0) {
  637. bus->rirb_error = 1;
  638. return -1;
  639. }
  640. goto again;
  641. }
  642. if (chip->probing) {
  643. /* If this critical timeout happens during the codec probing
  644. * phase, this is likely an access to a non-existing codec
  645. * slot. Better to return an error and reset the system.
  646. */
  647. return -1;
  648. }
  649. /* a fatal communication error; need either to reset or to fallback
  650. * to the single_cmd mode
  651. */
  652. bus->rirb_error = 1;
  653. if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
  654. bus->response_reset = 1;
  655. return -1; /* give a chance to retry */
  656. }
  657. snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
  658. "switching to single_cmd mode: last cmd=0x%08x\n",
  659. chip->last_cmd[addr]);
  660. chip->single_cmd = 1;
  661. bus->response_reset = 0;
  662. /* release CORB/RIRB */
  663. azx_free_cmd_io(chip);
  664. /* disable unsolicited responses */
  665. azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
  666. return -1;
  667. }
  668. /*
  669. * Use the single immediate command instead of CORB/RIRB for simplicity
  670. *
  671. * Note: according to Intel, this is not preferred use. The command was
  672. * intended for the BIOS only, and may get confused with unsolicited
  673. * responses. So, we shouldn't use it for normal operation from the
  674. * driver.
  675. * I left the codes, however, for debugging/testing purposes.
  676. */
  677. /* receive a response */
  678. static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
  679. {
  680. int timeout = 50;
  681. while (timeout--) {
  682. /* check IRV busy bit */
  683. if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
  684. /* reuse rirb.res as the response return value */
  685. chip->rirb.res[addr] = azx_readl(chip, IR);
  686. return 0;
  687. }
  688. udelay(1);
  689. }
  690. if (printk_ratelimit())
  691. snd_printd(SFX "get_response timeout: IRS=0x%x\n",
  692. azx_readw(chip, IRS));
  693. chip->rirb.res[addr] = -1;
  694. return -EIO;
  695. }
  696. /* send a command */
  697. static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
  698. {
  699. struct azx *chip = bus->private_data;
  700. unsigned int addr = azx_command_addr(val);
  701. int timeout = 50;
  702. bus->rirb_error = 0;
  703. while (timeout--) {
  704. /* check ICB busy bit */
  705. if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
  706. /* Clear IRV valid bit */
  707. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  708. ICH6_IRS_VALID);
  709. azx_writel(chip, IC, val);
  710. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  711. ICH6_IRS_BUSY);
  712. return azx_single_wait_for_response(chip, addr);
  713. }
  714. udelay(1);
  715. }
  716. if (printk_ratelimit())
  717. snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",
  718. azx_readw(chip, IRS), val);
  719. return -EIO;
  720. }
  721. /* receive a response */
  722. static unsigned int azx_single_get_response(struct hda_bus *bus,
  723. unsigned int addr)
  724. {
  725. struct azx *chip = bus->private_data;
  726. return chip->rirb.res[addr];
  727. }
  728. /*
  729. * The below are the main callbacks from hda_codec.
  730. *
  731. * They are just the skeleton to call sub-callbacks according to the
  732. * current setting of chip->single_cmd.
  733. */
  734. /* send a command */
  735. static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
  736. {
  737. struct azx *chip = bus->private_data;
  738. chip->last_cmd[azx_command_addr(val)] = val;
  739. if (chip->single_cmd)
  740. return azx_single_send_cmd(bus, val);
  741. else
  742. return azx_corb_send_cmd(bus, val);
  743. }
  744. /* get a response */
  745. static unsigned int azx_get_response(struct hda_bus *bus,
  746. unsigned int addr)
  747. {
  748. struct azx *chip = bus->private_data;
  749. if (chip->single_cmd)
  750. return azx_single_get_response(bus, addr);
  751. else
  752. return azx_rirb_get_response(bus, addr);
  753. }
  754. #ifdef CONFIG_SND_HDA_POWER_SAVE
  755. static void azx_power_notify(struct hda_bus *bus);
  756. #endif
  757. /* reset codec link */
  758. static int azx_reset(struct azx *chip, int full_reset)
  759. {
  760. int count;
  761. if (!full_reset)
  762. goto __skip;
  763. /* clear STATESTS */
  764. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  765. /* reset controller */
  766. azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
  767. count = 50;
  768. while (azx_readb(chip, GCTL) && --count)
  769. msleep(1);
  770. /* delay for >= 100us for codec PLL to settle per spec
  771. * Rev 0.9 section 5.5.1
  772. */
  773. msleep(1);
  774. /* Bring controller out of reset */
  775. azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
  776. count = 50;
  777. while (!azx_readb(chip, GCTL) && --count)
  778. msleep(1);
  779. /* Brent Chartrand said to wait >= 540us for codecs to initialize */
  780. msleep(1);
  781. __skip:
  782. /* check to see if controller is ready */
  783. if (!azx_readb(chip, GCTL)) {
  784. snd_printd(SFX "azx_reset: controller not ready!\n");
  785. return -EBUSY;
  786. }
  787. /* Accept unsolicited responses */
  788. if (!chip->single_cmd)
  789. azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
  790. ICH6_GCTL_UNSOL);
  791. /* detect codecs */
  792. if (!chip->codec_mask) {
  793. chip->codec_mask = azx_readw(chip, STATESTS);
  794. snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask);
  795. }
  796. return 0;
  797. }
  798. /*
  799. * Lowlevel interface
  800. */
  801. /* enable interrupts */
  802. static void azx_int_enable(struct azx *chip)
  803. {
  804. /* enable controller CIE and GIE */
  805. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
  806. ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
  807. }
  808. /* disable interrupts */
  809. static void azx_int_disable(struct azx *chip)
  810. {
  811. int i;
  812. /* disable interrupts in stream descriptor */
  813. for (i = 0; i < chip->num_streams; i++) {
  814. struct azx_dev *azx_dev = &chip->azx_dev[i];
  815. azx_sd_writeb(azx_dev, SD_CTL,
  816. azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
  817. }
  818. /* disable SIE for all streams */
  819. azx_writeb(chip, INTCTL, 0);
  820. /* disable controller CIE and GIE */
  821. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
  822. ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
  823. }
  824. /* clear interrupts */
  825. static void azx_int_clear(struct azx *chip)
  826. {
  827. int i;
  828. /* clear stream status */
  829. for (i = 0; i < chip->num_streams; i++) {
  830. struct azx_dev *azx_dev = &chip->azx_dev[i];
  831. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  832. }
  833. /* clear STATESTS */
  834. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  835. /* clear rirb status */
  836. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  837. /* clear int status */
  838. azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
  839. }
  840. /* start a stream */
  841. static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
  842. {
  843. /*
  844. * Before stream start, initialize parameter
  845. */
  846. azx_dev->insufficient = 1;
  847. /* enable SIE */
  848. azx_writel(chip, INTCTL,
  849. azx_readl(chip, INTCTL) | (1 << azx_dev->index));
  850. /* set DMA start and interrupt mask */
  851. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  852. SD_CTL_DMA_START | SD_INT_MASK);
  853. }
  854. /* stop DMA */
  855. static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
  856. {
  857. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
  858. ~(SD_CTL_DMA_START | SD_INT_MASK));
  859. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
  860. }
  861. /* stop a stream */
  862. static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
  863. {
  864. azx_stream_clear(chip, azx_dev);
  865. /* disable SIE */
  866. azx_writel(chip, INTCTL,
  867. azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
  868. }
  869. /*
  870. * reset and start the controller registers
  871. */
  872. static void azx_init_chip(struct azx *chip, int full_reset)
  873. {
  874. if (chip->initialized)
  875. return;
  876. /* reset controller */
  877. azx_reset(chip, full_reset);
  878. /* initialize interrupts */
  879. azx_int_clear(chip);
  880. azx_int_enable(chip);
  881. /* initialize the codec command I/O */
  882. if (!chip->single_cmd)
  883. azx_init_cmd_io(chip);
  884. /* program the position buffer */
  885. azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
  886. azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
  887. chip->initialized = 1;
  888. }
  889. /*
  890. * initialize the PCI registers
  891. */
  892. /* update bits in a PCI register byte */
  893. static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
  894. unsigned char mask, unsigned char val)
  895. {
  896. unsigned char data;
  897. pci_read_config_byte(pci, reg, &data);
  898. data &= ~mask;
  899. data |= (val & mask);
  900. pci_write_config_byte(pci, reg, data);
  901. }
  902. static void azx_init_pci(struct azx *chip)
  903. {
  904. unsigned short snoop;
  905. /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  906. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  907. * Ensuring these bits are 0 clears playback static on some HD Audio
  908. * codecs
  909. */
  910. update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
  911. switch (chip->driver_type) {
  912. case AZX_DRIVER_ATI:
  913. /* For ATI SB450 azalia HD audio, we need to enable snoop */
  914. update_pci_byte(chip->pci,
  915. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
  916. 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
  917. break;
  918. case AZX_DRIVER_NVIDIA:
  919. /* For NVIDIA HDA, enable snoop */
  920. update_pci_byte(chip->pci,
  921. NVIDIA_HDA_TRANSREG_ADDR,
  922. 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
  923. update_pci_byte(chip->pci,
  924. NVIDIA_HDA_ISTRM_COH,
  925. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  926. update_pci_byte(chip->pci,
  927. NVIDIA_HDA_OSTRM_COH,
  928. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  929. break;
  930. case AZX_DRIVER_SCH:
  931. case AZX_DRIVER_PCH:
  932. pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
  933. if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
  934. pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
  935. snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
  936. pci_read_config_word(chip->pci,
  937. INTEL_SCH_HDA_DEVC, &snoop);
  938. snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
  939. (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
  940. ? "Failed" : "OK");
  941. }
  942. break;
  943. }
  944. }
  945. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
  946. /*
  947. * interrupt handler
  948. */
  949. static irqreturn_t azx_interrupt(int irq, void *dev_id)
  950. {
  951. struct azx *chip = dev_id;
  952. struct azx_dev *azx_dev;
  953. u32 status;
  954. u8 sd_status;
  955. int i, ok;
  956. spin_lock(&chip->reg_lock);
  957. status = azx_readl(chip, INTSTS);
  958. if (status == 0) {
  959. spin_unlock(&chip->reg_lock);
  960. return IRQ_NONE;
  961. }
  962. for (i = 0; i < chip->num_streams; i++) {
  963. azx_dev = &chip->azx_dev[i];
  964. if (status & azx_dev->sd_int_sta_mask) {
  965. sd_status = azx_sd_readb(azx_dev, SD_STS);
  966. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  967. if (!azx_dev->substream || !azx_dev->running ||
  968. !(sd_status & SD_INT_COMPLETE))
  969. continue;
  970. /* check whether this IRQ is really acceptable */
  971. ok = azx_position_ok(chip, azx_dev);
  972. if (ok == 1) {
  973. azx_dev->irq_pending = 0;
  974. spin_unlock(&chip->reg_lock);
  975. snd_pcm_period_elapsed(azx_dev->substream);
  976. spin_lock(&chip->reg_lock);
  977. } else if (ok == 0 && chip->bus && chip->bus->workq) {
  978. /* bogus IRQ, process it later */
  979. azx_dev->irq_pending = 1;
  980. queue_work(chip->bus->workq,
  981. &chip->irq_pending_work);
  982. }
  983. }
  984. }
  985. /* clear rirb int */
  986. status = azx_readb(chip, RIRBSTS);
  987. if (status & RIRB_INT_MASK) {
  988. if (status & RIRB_INT_RESPONSE) {
  989. if (chip->driver_type == AZX_DRIVER_CTX)
  990. udelay(80);
  991. azx_update_rirb(chip);
  992. }
  993. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  994. }
  995. #if 0
  996. /* clear state status int */
  997. if (azx_readb(chip, STATESTS) & 0x04)
  998. azx_writeb(chip, STATESTS, 0x04);
  999. #endif
  1000. spin_unlock(&chip->reg_lock);
  1001. return IRQ_HANDLED;
  1002. }
  1003. /*
  1004. * set up a BDL entry
  1005. */
  1006. static int setup_bdle(struct snd_pcm_substream *substream,
  1007. struct azx_dev *azx_dev, u32 **bdlp,
  1008. int ofs, int size, int with_ioc)
  1009. {
  1010. u32 *bdl = *bdlp;
  1011. while (size > 0) {
  1012. dma_addr_t addr;
  1013. int chunk;
  1014. if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
  1015. return -EINVAL;
  1016. addr = snd_pcm_sgbuf_get_addr(substream, ofs);
  1017. /* program the address field of the BDL entry */
  1018. bdl[0] = cpu_to_le32((u32)addr);
  1019. bdl[1] = cpu_to_le32(upper_32_bits(addr));
  1020. /* program the size field of the BDL entry */
  1021. chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
  1022. bdl[2] = cpu_to_le32(chunk);
  1023. /* program the IOC to enable interrupt
  1024. * only when the whole fragment is processed
  1025. */
  1026. size -= chunk;
  1027. bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
  1028. bdl += 4;
  1029. azx_dev->frags++;
  1030. ofs += chunk;
  1031. }
  1032. *bdlp = bdl;
  1033. return ofs;
  1034. }
  1035. /*
  1036. * set up BDL entries
  1037. */
  1038. static int azx_setup_periods(struct azx *chip,
  1039. struct snd_pcm_substream *substream,
  1040. struct azx_dev *azx_dev)
  1041. {
  1042. u32 *bdl;
  1043. int i, ofs, periods, period_bytes;
  1044. int pos_adj;
  1045. /* reset BDL address */
  1046. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1047. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1048. period_bytes = azx_dev->period_bytes;
  1049. periods = azx_dev->bufsize / period_bytes;
  1050. /* program the initial BDL entries */
  1051. bdl = (u32 *)azx_dev->bdl.area;
  1052. ofs = 0;
  1053. azx_dev->frags = 0;
  1054. pos_adj = bdl_pos_adj[chip->dev_index];
  1055. if (pos_adj > 0) {
  1056. struct snd_pcm_runtime *runtime = substream->runtime;
  1057. int pos_align = pos_adj;
  1058. pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
  1059. if (!pos_adj)
  1060. pos_adj = pos_align;
  1061. else
  1062. pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
  1063. pos_align;
  1064. pos_adj = frames_to_bytes(runtime, pos_adj);
  1065. if (pos_adj >= period_bytes) {
  1066. snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",
  1067. bdl_pos_adj[chip->dev_index]);
  1068. pos_adj = 0;
  1069. } else {
  1070. ofs = setup_bdle(substream, azx_dev,
  1071. &bdl, ofs, pos_adj,
  1072. !substream->runtime->no_period_wakeup);
  1073. if (ofs < 0)
  1074. goto error;
  1075. }
  1076. } else
  1077. pos_adj = 0;
  1078. for (i = 0; i < periods; i++) {
  1079. if (i == periods - 1 && pos_adj)
  1080. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1081. period_bytes - pos_adj, 0);
  1082. else
  1083. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1084. period_bytes,
  1085. !substream->runtime->no_period_wakeup);
  1086. if (ofs < 0)
  1087. goto error;
  1088. }
  1089. return 0;
  1090. error:
  1091. snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
  1092. azx_dev->bufsize, period_bytes);
  1093. return -EINVAL;
  1094. }
  1095. /* reset stream */
  1096. static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
  1097. {
  1098. unsigned char val;
  1099. int timeout;
  1100. azx_stream_clear(chip, azx_dev);
  1101. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  1102. SD_CTL_STREAM_RESET);
  1103. udelay(3);
  1104. timeout = 300;
  1105. while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1106. --timeout)
  1107. ;
  1108. val &= ~SD_CTL_STREAM_RESET;
  1109. azx_sd_writeb(azx_dev, SD_CTL, val);
  1110. udelay(3);
  1111. timeout = 300;
  1112. /* waiting for hardware to report that the stream is out of reset */
  1113. while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1114. --timeout)
  1115. ;
  1116. /* reset first position - may not be synced with hw at this time */
  1117. *azx_dev->posbuf = 0;
  1118. }
  1119. /*
  1120. * set up the SD for streaming
  1121. */
  1122. static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
  1123. {
  1124. /* make sure the run bit is zero for SD */
  1125. azx_stream_clear(chip, azx_dev);
  1126. /* program the stream_tag */
  1127. azx_sd_writel(azx_dev, SD_CTL,
  1128. (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
  1129. (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
  1130. /* program the length of samples in cyclic buffer */
  1131. azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
  1132. /* program the stream format */
  1133. /* this value needs to be the same as the one programmed */
  1134. azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
  1135. /* program the stream LVI (last valid index) of the BDL */
  1136. azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
  1137. /* program the BDL address */
  1138. /* lower BDL address */
  1139. azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
  1140. /* upper BDL address */
  1141. azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
  1142. /* enable the position buffer */
  1143. if (chip->position_fix[0] != POS_FIX_LPIB ||
  1144. chip->position_fix[1] != POS_FIX_LPIB) {
  1145. if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
  1146. azx_writel(chip, DPLBASE,
  1147. (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
  1148. }
  1149. /* set the interrupt enable bits in the descriptor control register */
  1150. azx_sd_writel(azx_dev, SD_CTL,
  1151. azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
  1152. return 0;
  1153. }
  1154. /*
  1155. * Probe the given codec address
  1156. */
  1157. static int probe_codec(struct azx *chip, int addr)
  1158. {
  1159. unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
  1160. (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
  1161. unsigned int res;
  1162. mutex_lock(&chip->bus->cmd_mutex);
  1163. chip->probing = 1;
  1164. azx_send_cmd(chip->bus, cmd);
  1165. res = azx_get_response(chip->bus, addr);
  1166. chip->probing = 0;
  1167. mutex_unlock(&chip->bus->cmd_mutex);
  1168. if (res == -1)
  1169. return -EIO;
  1170. snd_printdd(SFX "codec #%d probed OK\n", addr);
  1171. return 0;
  1172. }
  1173. static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1174. struct hda_pcm *cpcm);
  1175. static void azx_stop_chip(struct azx *chip);
  1176. static void azx_bus_reset(struct hda_bus *bus)
  1177. {
  1178. struct azx *chip = bus->private_data;
  1179. bus->in_reset = 1;
  1180. azx_stop_chip(chip);
  1181. azx_init_chip(chip, 1);
  1182. #ifdef CONFIG_PM
  1183. if (chip->initialized) {
  1184. int i;
  1185. for (i = 0; i < HDA_MAX_PCMS; i++)
  1186. snd_pcm_suspend_all(chip->pcm[i]);
  1187. snd_hda_suspend(chip->bus);
  1188. snd_hda_resume(chip->bus);
  1189. }
  1190. #endif
  1191. bus->in_reset = 0;
  1192. }
  1193. /*
  1194. * Codec initialization
  1195. */
  1196. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1197. static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
  1198. [AZX_DRIVER_NVIDIA] = 8,
  1199. [AZX_DRIVER_TERA] = 1,
  1200. };
  1201. static int __devinit azx_codec_create(struct azx *chip, const char *model)
  1202. {
  1203. struct hda_bus_template bus_temp;
  1204. int c, codecs, err;
  1205. int max_slots;
  1206. memset(&bus_temp, 0, sizeof(bus_temp));
  1207. bus_temp.private_data = chip;
  1208. bus_temp.modelname = model;
  1209. bus_temp.pci = chip->pci;
  1210. bus_temp.ops.command = azx_send_cmd;
  1211. bus_temp.ops.get_response = azx_get_response;
  1212. bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
  1213. bus_temp.ops.bus_reset = azx_bus_reset;
  1214. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1215. bus_temp.power_save = &power_save;
  1216. bus_temp.ops.pm_notify = azx_power_notify;
  1217. #endif
  1218. err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
  1219. if (err < 0)
  1220. return err;
  1221. if (chip->driver_type == AZX_DRIVER_NVIDIA)
  1222. chip->bus->needs_damn_long_delay = 1;
  1223. codecs = 0;
  1224. max_slots = azx_max_codecs[chip->driver_type];
  1225. if (!max_slots)
  1226. max_slots = AZX_DEFAULT_CODECS;
  1227. /* First try to probe all given codec slots */
  1228. for (c = 0; c < max_slots; c++) {
  1229. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1230. if (probe_codec(chip, c) < 0) {
  1231. /* Some BIOSen give you wrong codec addresses
  1232. * that don't exist
  1233. */
  1234. snd_printk(KERN_WARNING SFX
  1235. "Codec #%d probe error; "
  1236. "disabling it...\n", c);
  1237. chip->codec_mask &= ~(1 << c);
  1238. /* More badly, accessing to a non-existing
  1239. * codec often screws up the controller chip,
  1240. * and disturbs the further communications.
  1241. * Thus if an error occurs during probing,
  1242. * better to reset the controller chip to
  1243. * get back to the sanity state.
  1244. */
  1245. azx_stop_chip(chip);
  1246. azx_init_chip(chip, 1);
  1247. }
  1248. }
  1249. }
  1250. /* Then create codec instances */
  1251. for (c = 0; c < max_slots; c++) {
  1252. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1253. struct hda_codec *codec;
  1254. err = snd_hda_codec_new(chip->bus, c, &codec);
  1255. if (err < 0)
  1256. continue;
  1257. codec->beep_mode = chip->beep_mode;
  1258. codecs++;
  1259. }
  1260. }
  1261. if (!codecs) {
  1262. snd_printk(KERN_ERR SFX "no codecs initialized\n");
  1263. return -ENXIO;
  1264. }
  1265. return 0;
  1266. }
  1267. /* configure each codec instance */
  1268. static int __devinit azx_codec_configure(struct azx *chip)
  1269. {
  1270. struct hda_codec *codec;
  1271. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  1272. snd_hda_codec_configure(codec);
  1273. }
  1274. return 0;
  1275. }
  1276. /*
  1277. * PCM support
  1278. */
  1279. /* assign a stream for the PCM */
  1280. static inline struct azx_dev *
  1281. azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
  1282. {
  1283. int dev, i, nums;
  1284. struct azx_dev *res = NULL;
  1285. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1286. dev = chip->playback_index_offset;
  1287. nums = chip->playback_streams;
  1288. } else {
  1289. dev = chip->capture_index_offset;
  1290. nums = chip->capture_streams;
  1291. }
  1292. for (i = 0; i < nums; i++, dev++)
  1293. if (!chip->azx_dev[dev].opened) {
  1294. res = &chip->azx_dev[dev];
  1295. if (res->device == substream->pcm->device)
  1296. break;
  1297. }
  1298. if (res) {
  1299. res->opened = 1;
  1300. res->device = substream->pcm->device;
  1301. }
  1302. return res;
  1303. }
  1304. /* release the assigned stream */
  1305. static inline void azx_release_device(struct azx_dev *azx_dev)
  1306. {
  1307. azx_dev->opened = 0;
  1308. }
  1309. static struct snd_pcm_hardware azx_pcm_hw = {
  1310. .info = (SNDRV_PCM_INFO_MMAP |
  1311. SNDRV_PCM_INFO_INTERLEAVED |
  1312. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1313. SNDRV_PCM_INFO_MMAP_VALID |
  1314. /* No full-resume yet implemented */
  1315. /* SNDRV_PCM_INFO_RESUME |*/
  1316. SNDRV_PCM_INFO_PAUSE |
  1317. SNDRV_PCM_INFO_SYNC_START |
  1318. SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
  1319. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1320. .rates = SNDRV_PCM_RATE_48000,
  1321. .rate_min = 48000,
  1322. .rate_max = 48000,
  1323. .channels_min = 2,
  1324. .channels_max = 2,
  1325. .buffer_bytes_max = AZX_MAX_BUF_SIZE,
  1326. .period_bytes_min = 128,
  1327. .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
  1328. .periods_min = 2,
  1329. .periods_max = AZX_MAX_FRAG,
  1330. .fifo_size = 0,
  1331. };
  1332. struct azx_pcm {
  1333. struct azx *chip;
  1334. struct hda_codec *codec;
  1335. struct hda_pcm_stream *hinfo[2];
  1336. };
  1337. static int azx_pcm_open(struct snd_pcm_substream *substream)
  1338. {
  1339. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1340. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1341. struct azx *chip = apcm->chip;
  1342. struct azx_dev *azx_dev;
  1343. struct snd_pcm_runtime *runtime = substream->runtime;
  1344. unsigned long flags;
  1345. int err;
  1346. mutex_lock(&chip->open_mutex);
  1347. azx_dev = azx_assign_device(chip, substream);
  1348. if (azx_dev == NULL) {
  1349. mutex_unlock(&chip->open_mutex);
  1350. return -EBUSY;
  1351. }
  1352. runtime->hw = azx_pcm_hw;
  1353. runtime->hw.channels_min = hinfo->channels_min;
  1354. runtime->hw.channels_max = hinfo->channels_max;
  1355. runtime->hw.formats = hinfo->formats;
  1356. runtime->hw.rates = hinfo->rates;
  1357. snd_pcm_limit_hw_rates(runtime);
  1358. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  1359. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1360. 128);
  1361. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1362. 128);
  1363. snd_hda_power_up(apcm->codec);
  1364. err = hinfo->ops.open(hinfo, apcm->codec, substream);
  1365. if (err < 0) {
  1366. azx_release_device(azx_dev);
  1367. snd_hda_power_down(apcm->codec);
  1368. mutex_unlock(&chip->open_mutex);
  1369. return err;
  1370. }
  1371. snd_pcm_limit_hw_rates(runtime);
  1372. /* sanity check */
  1373. if (snd_BUG_ON(!runtime->hw.channels_min) ||
  1374. snd_BUG_ON(!runtime->hw.channels_max) ||
  1375. snd_BUG_ON(!runtime->hw.formats) ||
  1376. snd_BUG_ON(!runtime->hw.rates)) {
  1377. azx_release_device(azx_dev);
  1378. hinfo->ops.close(hinfo, apcm->codec, substream);
  1379. snd_hda_power_down(apcm->codec);
  1380. mutex_unlock(&chip->open_mutex);
  1381. return -EINVAL;
  1382. }
  1383. spin_lock_irqsave(&chip->reg_lock, flags);
  1384. azx_dev->substream = substream;
  1385. azx_dev->running = 0;
  1386. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1387. runtime->private_data = azx_dev;
  1388. snd_pcm_set_sync(substream);
  1389. mutex_unlock(&chip->open_mutex);
  1390. return 0;
  1391. }
  1392. static int azx_pcm_close(struct snd_pcm_substream *substream)
  1393. {
  1394. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1395. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1396. struct azx *chip = apcm->chip;
  1397. struct azx_dev *azx_dev = get_azx_dev(substream);
  1398. unsigned long flags;
  1399. mutex_lock(&chip->open_mutex);
  1400. spin_lock_irqsave(&chip->reg_lock, flags);
  1401. azx_dev->substream = NULL;
  1402. azx_dev->running = 0;
  1403. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1404. azx_release_device(azx_dev);
  1405. hinfo->ops.close(hinfo, apcm->codec, substream);
  1406. snd_hda_power_down(apcm->codec);
  1407. mutex_unlock(&chip->open_mutex);
  1408. return 0;
  1409. }
  1410. static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
  1411. struct snd_pcm_hw_params *hw_params)
  1412. {
  1413. struct azx_dev *azx_dev = get_azx_dev(substream);
  1414. azx_dev->bufsize = 0;
  1415. azx_dev->period_bytes = 0;
  1416. azx_dev->format_val = 0;
  1417. return snd_pcm_lib_malloc_pages(substream,
  1418. params_buffer_bytes(hw_params));
  1419. }
  1420. static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
  1421. {
  1422. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1423. struct azx_dev *azx_dev = get_azx_dev(substream);
  1424. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1425. /* reset BDL address */
  1426. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1427. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1428. azx_sd_writel(azx_dev, SD_CTL, 0);
  1429. azx_dev->bufsize = 0;
  1430. azx_dev->period_bytes = 0;
  1431. azx_dev->format_val = 0;
  1432. snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
  1433. return snd_pcm_lib_free_pages(substream);
  1434. }
  1435. static int azx_pcm_prepare(struct snd_pcm_substream *substream)
  1436. {
  1437. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1438. struct azx *chip = apcm->chip;
  1439. struct azx_dev *azx_dev = get_azx_dev(substream);
  1440. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1441. struct snd_pcm_runtime *runtime = substream->runtime;
  1442. unsigned int bufsize, period_bytes, format_val, stream_tag;
  1443. int err;
  1444. azx_stream_reset(chip, azx_dev);
  1445. format_val = snd_hda_calc_stream_format(runtime->rate,
  1446. runtime->channels,
  1447. runtime->format,
  1448. hinfo->maxbps,
  1449. apcm->codec->spdif_ctls);
  1450. if (!format_val) {
  1451. snd_printk(KERN_ERR SFX
  1452. "invalid format_val, rate=%d, ch=%d, format=%d\n",
  1453. runtime->rate, runtime->channels, runtime->format);
  1454. return -EINVAL;
  1455. }
  1456. bufsize = snd_pcm_lib_buffer_bytes(substream);
  1457. period_bytes = snd_pcm_lib_period_bytes(substream);
  1458. snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
  1459. bufsize, format_val);
  1460. if (bufsize != azx_dev->bufsize ||
  1461. period_bytes != azx_dev->period_bytes ||
  1462. format_val != azx_dev->format_val) {
  1463. azx_dev->bufsize = bufsize;
  1464. azx_dev->period_bytes = period_bytes;
  1465. azx_dev->format_val = format_val;
  1466. err = azx_setup_periods(chip, substream, azx_dev);
  1467. if (err < 0)
  1468. return err;
  1469. }
  1470. /* wallclk has 24Mhz clock source */
  1471. azx_dev->period_wallclk = (((runtime->period_size * 24000) /
  1472. runtime->rate) * 1000);
  1473. azx_setup_controller(chip, azx_dev);
  1474. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1475. azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
  1476. else
  1477. azx_dev->fifo_size = 0;
  1478. stream_tag = azx_dev->stream_tag;
  1479. /* CA-IBG chips need the playback stream starting from 1 */
  1480. if (chip->driver_type == AZX_DRIVER_CTX &&
  1481. stream_tag > chip->capture_streams)
  1482. stream_tag -= chip->capture_streams;
  1483. return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
  1484. azx_dev->format_val, substream);
  1485. }
  1486. static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  1487. {
  1488. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1489. struct azx *chip = apcm->chip;
  1490. struct azx_dev *azx_dev;
  1491. struct snd_pcm_substream *s;
  1492. int rstart = 0, start, nsync = 0, sbits = 0;
  1493. int nwait, timeout;
  1494. switch (cmd) {
  1495. case SNDRV_PCM_TRIGGER_START:
  1496. rstart = 1;
  1497. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1498. case SNDRV_PCM_TRIGGER_RESUME:
  1499. start = 1;
  1500. break;
  1501. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1502. case SNDRV_PCM_TRIGGER_SUSPEND:
  1503. case SNDRV_PCM_TRIGGER_STOP:
  1504. start = 0;
  1505. break;
  1506. default:
  1507. return -EINVAL;
  1508. }
  1509. snd_pcm_group_for_each_entry(s, substream) {
  1510. if (s->pcm->card != substream->pcm->card)
  1511. continue;
  1512. azx_dev = get_azx_dev(s);
  1513. sbits |= 1 << azx_dev->index;
  1514. nsync++;
  1515. snd_pcm_trigger_done(s, substream);
  1516. }
  1517. spin_lock(&chip->reg_lock);
  1518. if (nsync > 1) {
  1519. /* first, set SYNC bits of corresponding streams */
  1520. azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
  1521. }
  1522. snd_pcm_group_for_each_entry(s, substream) {
  1523. if (s->pcm->card != substream->pcm->card)
  1524. continue;
  1525. azx_dev = get_azx_dev(s);
  1526. if (start) {
  1527. azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
  1528. if (!rstart)
  1529. azx_dev->start_wallclk -=
  1530. azx_dev->period_wallclk;
  1531. azx_stream_start(chip, azx_dev);
  1532. } else {
  1533. azx_stream_stop(chip, azx_dev);
  1534. }
  1535. azx_dev->running = start;
  1536. }
  1537. spin_unlock(&chip->reg_lock);
  1538. if (start) {
  1539. if (nsync == 1)
  1540. return 0;
  1541. /* wait until all FIFOs get ready */
  1542. for (timeout = 5000; timeout; timeout--) {
  1543. nwait = 0;
  1544. snd_pcm_group_for_each_entry(s, substream) {
  1545. if (s->pcm->card != substream->pcm->card)
  1546. continue;
  1547. azx_dev = get_azx_dev(s);
  1548. if (!(azx_sd_readb(azx_dev, SD_STS) &
  1549. SD_STS_FIFO_READY))
  1550. nwait++;
  1551. }
  1552. if (!nwait)
  1553. break;
  1554. cpu_relax();
  1555. }
  1556. } else {
  1557. /* wait until all RUN bits are cleared */
  1558. for (timeout = 5000; timeout; timeout--) {
  1559. nwait = 0;
  1560. snd_pcm_group_for_each_entry(s, substream) {
  1561. if (s->pcm->card != substream->pcm->card)
  1562. continue;
  1563. azx_dev = get_azx_dev(s);
  1564. if (azx_sd_readb(azx_dev, SD_CTL) &
  1565. SD_CTL_DMA_START)
  1566. nwait++;
  1567. }
  1568. if (!nwait)
  1569. break;
  1570. cpu_relax();
  1571. }
  1572. }
  1573. if (nsync > 1) {
  1574. spin_lock(&chip->reg_lock);
  1575. /* reset SYNC bits */
  1576. azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
  1577. spin_unlock(&chip->reg_lock);
  1578. }
  1579. return 0;
  1580. }
  1581. /* get the current DMA position with correction on VIA chips */
  1582. static unsigned int azx_via_get_position(struct azx *chip,
  1583. struct azx_dev *azx_dev)
  1584. {
  1585. unsigned int link_pos, mini_pos, bound_pos;
  1586. unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
  1587. unsigned int fifo_size;
  1588. link_pos = azx_sd_readl(azx_dev, SD_LPIB);
  1589. if (azx_dev->index >= 4) {
  1590. /* Playback, no problem using link position */
  1591. return link_pos;
  1592. }
  1593. /* Capture */
  1594. /* For new chipset,
  1595. * use mod to get the DMA position just like old chipset
  1596. */
  1597. mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
  1598. mod_dma_pos %= azx_dev->period_bytes;
  1599. /* azx_dev->fifo_size can't get FIFO size of in stream.
  1600. * Get from base address + offset.
  1601. */
  1602. fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
  1603. if (azx_dev->insufficient) {
  1604. /* Link position never gather than FIFO size */
  1605. if (link_pos <= fifo_size)
  1606. return 0;
  1607. azx_dev->insufficient = 0;
  1608. }
  1609. if (link_pos <= fifo_size)
  1610. mini_pos = azx_dev->bufsize + link_pos - fifo_size;
  1611. else
  1612. mini_pos = link_pos - fifo_size;
  1613. /* Find nearest previous boudary */
  1614. mod_mini_pos = mini_pos % azx_dev->period_bytes;
  1615. mod_link_pos = link_pos % azx_dev->period_bytes;
  1616. if (mod_link_pos >= fifo_size)
  1617. bound_pos = link_pos - mod_link_pos;
  1618. else if (mod_dma_pos >= mod_mini_pos)
  1619. bound_pos = mini_pos - mod_mini_pos;
  1620. else {
  1621. bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
  1622. if (bound_pos >= azx_dev->bufsize)
  1623. bound_pos = 0;
  1624. }
  1625. /* Calculate real DMA position we want */
  1626. return bound_pos + mod_dma_pos;
  1627. }
  1628. static unsigned int azx_get_position(struct azx *chip,
  1629. struct azx_dev *azx_dev)
  1630. {
  1631. unsigned int pos;
  1632. int stream = azx_dev->substream->stream;
  1633. switch (chip->position_fix[stream]) {
  1634. case POS_FIX_LPIB:
  1635. /* read LPIB */
  1636. pos = azx_sd_readl(azx_dev, SD_LPIB);
  1637. break;
  1638. case POS_FIX_VIACOMBO:
  1639. pos = azx_via_get_position(chip, azx_dev);
  1640. break;
  1641. default:
  1642. /* use the position buffer */
  1643. pos = le32_to_cpu(*azx_dev->posbuf);
  1644. }
  1645. if (pos >= azx_dev->bufsize)
  1646. pos = 0;
  1647. return pos;
  1648. }
  1649. static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
  1650. {
  1651. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1652. struct azx *chip = apcm->chip;
  1653. struct azx_dev *azx_dev = get_azx_dev(substream);
  1654. return bytes_to_frames(substream->runtime,
  1655. azx_get_position(chip, azx_dev));
  1656. }
  1657. /*
  1658. * Check whether the current DMA position is acceptable for updating
  1659. * periods. Returns non-zero if it's OK.
  1660. *
  1661. * Many HD-audio controllers appear pretty inaccurate about
  1662. * the update-IRQ timing. The IRQ is issued before actually the
  1663. * data is processed. So, we need to process it afterwords in a
  1664. * workqueue.
  1665. */
  1666. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  1667. {
  1668. u32 wallclk;
  1669. unsigned int pos;
  1670. int stream;
  1671. wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
  1672. if (wallclk < (azx_dev->period_wallclk * 2) / 3)
  1673. return -1; /* bogus (too early) interrupt */
  1674. stream = azx_dev->substream->stream;
  1675. pos = azx_get_position(chip, azx_dev);
  1676. if (chip->position_fix[stream] == POS_FIX_AUTO) {
  1677. if (!pos) {
  1678. printk(KERN_WARNING
  1679. "hda-intel: Invalid position buffer, "
  1680. "using LPIB read method instead.\n");
  1681. chip->position_fix[stream] = POS_FIX_LPIB;
  1682. pos = azx_get_position(chip, azx_dev);
  1683. } else
  1684. chip->position_fix[stream] = POS_FIX_POSBUF;
  1685. }
  1686. if (WARN_ONCE(!azx_dev->period_bytes,
  1687. "hda-intel: zero azx_dev->period_bytes"))
  1688. return -1; /* this shouldn't happen! */
  1689. if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
  1690. pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
  1691. /* NG - it's below the first next period boundary */
  1692. return bdl_pos_adj[chip->dev_index] ? 0 : -1;
  1693. azx_dev->start_wallclk += wallclk;
  1694. return 1; /* OK, it's fine */
  1695. }
  1696. /*
  1697. * The work for pending PCM period updates.
  1698. */
  1699. static void azx_irq_pending_work(struct work_struct *work)
  1700. {
  1701. struct azx *chip = container_of(work, struct azx, irq_pending_work);
  1702. int i, pending, ok;
  1703. if (!chip->irq_pending_warned) {
  1704. printk(KERN_WARNING
  1705. "hda-intel: IRQ timing workaround is activated "
  1706. "for card #%d. Suggest a bigger bdl_pos_adj.\n",
  1707. chip->card->number);
  1708. chip->irq_pending_warned = 1;
  1709. }
  1710. for (;;) {
  1711. pending = 0;
  1712. spin_lock_irq(&chip->reg_lock);
  1713. for (i = 0; i < chip->num_streams; i++) {
  1714. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1715. if (!azx_dev->irq_pending ||
  1716. !azx_dev->substream ||
  1717. !azx_dev->running)
  1718. continue;
  1719. ok = azx_position_ok(chip, azx_dev);
  1720. if (ok > 0) {
  1721. azx_dev->irq_pending = 0;
  1722. spin_unlock(&chip->reg_lock);
  1723. snd_pcm_period_elapsed(azx_dev->substream);
  1724. spin_lock(&chip->reg_lock);
  1725. } else if (ok < 0) {
  1726. pending = 0; /* too early */
  1727. } else
  1728. pending++;
  1729. }
  1730. spin_unlock_irq(&chip->reg_lock);
  1731. if (!pending)
  1732. return;
  1733. msleep(1);
  1734. }
  1735. }
  1736. /* clear irq_pending flags and assure no on-going workq */
  1737. static void azx_clear_irq_pending(struct azx *chip)
  1738. {
  1739. int i;
  1740. spin_lock_irq(&chip->reg_lock);
  1741. for (i = 0; i < chip->num_streams; i++)
  1742. chip->azx_dev[i].irq_pending = 0;
  1743. spin_unlock_irq(&chip->reg_lock);
  1744. }
  1745. static struct snd_pcm_ops azx_pcm_ops = {
  1746. .open = azx_pcm_open,
  1747. .close = azx_pcm_close,
  1748. .ioctl = snd_pcm_lib_ioctl,
  1749. .hw_params = azx_pcm_hw_params,
  1750. .hw_free = azx_pcm_hw_free,
  1751. .prepare = azx_pcm_prepare,
  1752. .trigger = azx_pcm_trigger,
  1753. .pointer = azx_pcm_pointer,
  1754. .page = snd_pcm_sgbuf_ops_page,
  1755. };
  1756. static void azx_pcm_free(struct snd_pcm *pcm)
  1757. {
  1758. struct azx_pcm *apcm = pcm->private_data;
  1759. if (apcm) {
  1760. apcm->chip->pcm[pcm->device] = NULL;
  1761. kfree(apcm);
  1762. }
  1763. }
  1764. static int
  1765. azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1766. struct hda_pcm *cpcm)
  1767. {
  1768. struct azx *chip = bus->private_data;
  1769. struct snd_pcm *pcm;
  1770. struct azx_pcm *apcm;
  1771. int pcm_dev = cpcm->device;
  1772. int s, err;
  1773. if (pcm_dev >= HDA_MAX_PCMS) {
  1774. snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
  1775. pcm_dev);
  1776. return -EINVAL;
  1777. }
  1778. if (chip->pcm[pcm_dev]) {
  1779. snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
  1780. return -EBUSY;
  1781. }
  1782. err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
  1783. cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
  1784. cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
  1785. &pcm);
  1786. if (err < 0)
  1787. return err;
  1788. strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
  1789. apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
  1790. if (apcm == NULL)
  1791. return -ENOMEM;
  1792. apcm->chip = chip;
  1793. apcm->codec = codec;
  1794. pcm->private_data = apcm;
  1795. pcm->private_free = azx_pcm_free;
  1796. if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
  1797. pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
  1798. chip->pcm[pcm_dev] = pcm;
  1799. cpcm->pcm = pcm;
  1800. for (s = 0; s < 2; s++) {
  1801. apcm->hinfo[s] = &cpcm->stream[s];
  1802. if (cpcm->stream[s].substreams)
  1803. snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
  1804. }
  1805. /* buffer pre-allocation */
  1806. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  1807. snd_dma_pci_data(chip->pci),
  1808. 1024 * 64, 32 * 1024 * 1024);
  1809. return 0;
  1810. }
  1811. /*
  1812. * mixer creation - all stuff is implemented in hda module
  1813. */
  1814. static int __devinit azx_mixer_create(struct azx *chip)
  1815. {
  1816. return snd_hda_build_controls(chip->bus);
  1817. }
  1818. /*
  1819. * initialize SD streams
  1820. */
  1821. static int __devinit azx_init_stream(struct azx *chip)
  1822. {
  1823. int i;
  1824. /* initialize each stream (aka device)
  1825. * assign the starting bdl address to each stream (device)
  1826. * and initialize
  1827. */
  1828. for (i = 0; i < chip->num_streams; i++) {
  1829. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1830. azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
  1831. /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  1832. azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
  1833. /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
  1834. azx_dev->sd_int_sta_mask = 1 << i;
  1835. /* stream tag: must be non-zero and unique */
  1836. azx_dev->index = i;
  1837. azx_dev->stream_tag = i + 1;
  1838. }
  1839. return 0;
  1840. }
  1841. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  1842. {
  1843. if (request_irq(chip->pci->irq, azx_interrupt,
  1844. chip->msi ? 0 : IRQF_SHARED,
  1845. "hda_intel", chip)) {
  1846. printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
  1847. "disabling device\n", chip->pci->irq);
  1848. if (do_disconnect)
  1849. snd_card_disconnect(chip->card);
  1850. return -1;
  1851. }
  1852. chip->irq = chip->pci->irq;
  1853. pci_intx(chip->pci, !chip->msi);
  1854. return 0;
  1855. }
  1856. static void azx_stop_chip(struct azx *chip)
  1857. {
  1858. if (!chip->initialized)
  1859. return;
  1860. /* disable interrupts */
  1861. azx_int_disable(chip);
  1862. azx_int_clear(chip);
  1863. /* disable CORB/RIRB */
  1864. azx_free_cmd_io(chip);
  1865. /* disable position buffer */
  1866. azx_writel(chip, DPLBASE, 0);
  1867. azx_writel(chip, DPUBASE, 0);
  1868. chip->initialized = 0;
  1869. }
  1870. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1871. /* power-up/down the controller */
  1872. static void azx_power_notify(struct hda_bus *bus)
  1873. {
  1874. struct azx *chip = bus->private_data;
  1875. struct hda_codec *c;
  1876. int power_on = 0;
  1877. list_for_each_entry(c, &bus->codec_list, list) {
  1878. if (c->power_on) {
  1879. power_on = 1;
  1880. break;
  1881. }
  1882. }
  1883. if (power_on)
  1884. azx_init_chip(chip, 1);
  1885. else if (chip->running && power_save_controller &&
  1886. !bus->power_keep_link_on)
  1887. azx_stop_chip(chip);
  1888. }
  1889. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  1890. #ifdef CONFIG_PM
  1891. /*
  1892. * power management
  1893. */
  1894. static int snd_hda_codecs_inuse(struct hda_bus *bus)
  1895. {
  1896. struct hda_codec *codec;
  1897. list_for_each_entry(codec, &bus->codec_list, list) {
  1898. if (snd_hda_codec_needs_resume(codec))
  1899. return 1;
  1900. }
  1901. return 0;
  1902. }
  1903. static int azx_suspend(struct pci_dev *pci, pm_message_t state)
  1904. {
  1905. struct snd_card *card = pci_get_drvdata(pci);
  1906. struct azx *chip = card->private_data;
  1907. int i;
  1908. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1909. azx_clear_irq_pending(chip);
  1910. for (i = 0; i < HDA_MAX_PCMS; i++)
  1911. snd_pcm_suspend_all(chip->pcm[i]);
  1912. if (chip->initialized)
  1913. snd_hda_suspend(chip->bus);
  1914. azx_stop_chip(chip);
  1915. if (chip->irq >= 0) {
  1916. free_irq(chip->irq, chip);
  1917. chip->irq = -1;
  1918. }
  1919. if (chip->msi)
  1920. pci_disable_msi(chip->pci);
  1921. pci_disable_device(pci);
  1922. pci_save_state(pci);
  1923. pci_set_power_state(pci, pci_choose_state(pci, state));
  1924. return 0;
  1925. }
  1926. static int azx_resume(struct pci_dev *pci)
  1927. {
  1928. struct snd_card *card = pci_get_drvdata(pci);
  1929. struct azx *chip = card->private_data;
  1930. pci_set_power_state(pci, PCI_D0);
  1931. pci_restore_state(pci);
  1932. if (pci_enable_device(pci) < 0) {
  1933. printk(KERN_ERR "hda-intel: pci_enable_device failed, "
  1934. "disabling device\n");
  1935. snd_card_disconnect(card);
  1936. return -EIO;
  1937. }
  1938. pci_set_master(pci);
  1939. if (chip->msi)
  1940. if (pci_enable_msi(pci) < 0)
  1941. chip->msi = 0;
  1942. if (azx_acquire_irq(chip, 1) < 0)
  1943. return -EIO;
  1944. azx_init_pci(chip);
  1945. if (snd_hda_codecs_inuse(chip->bus))
  1946. azx_init_chip(chip, 1);
  1947. snd_hda_resume(chip->bus);
  1948. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1949. return 0;
  1950. }
  1951. #endif /* CONFIG_PM */
  1952. /*
  1953. * reboot notifier for hang-up problem at power-down
  1954. */
  1955. static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
  1956. {
  1957. struct azx *chip = container_of(nb, struct azx, reboot_notifier);
  1958. snd_hda_bus_reboot_notify(chip->bus);
  1959. azx_stop_chip(chip);
  1960. return NOTIFY_OK;
  1961. }
  1962. static void azx_notifier_register(struct azx *chip)
  1963. {
  1964. chip->reboot_notifier.notifier_call = azx_halt;
  1965. register_reboot_notifier(&chip->reboot_notifier);
  1966. }
  1967. static void azx_notifier_unregister(struct azx *chip)
  1968. {
  1969. if (chip->reboot_notifier.notifier_call)
  1970. unregister_reboot_notifier(&chip->reboot_notifier);
  1971. }
  1972. /*
  1973. * destructor
  1974. */
  1975. static int azx_free(struct azx *chip)
  1976. {
  1977. int i;
  1978. azx_notifier_unregister(chip);
  1979. if (chip->initialized) {
  1980. azx_clear_irq_pending(chip);
  1981. for (i = 0; i < chip->num_streams; i++)
  1982. azx_stream_stop(chip, &chip->azx_dev[i]);
  1983. azx_stop_chip(chip);
  1984. }
  1985. if (chip->irq >= 0)
  1986. free_irq(chip->irq, (void*)chip);
  1987. if (chip->msi)
  1988. pci_disable_msi(chip->pci);
  1989. if (chip->remap_addr)
  1990. iounmap(chip->remap_addr);
  1991. if (chip->azx_dev) {
  1992. for (i = 0; i < chip->num_streams; i++)
  1993. if (chip->azx_dev[i].bdl.area)
  1994. snd_dma_free_pages(&chip->azx_dev[i].bdl);
  1995. }
  1996. if (chip->rb.area)
  1997. snd_dma_free_pages(&chip->rb);
  1998. if (chip->posbuf.area)
  1999. snd_dma_free_pages(&chip->posbuf);
  2000. pci_release_regions(chip->pci);
  2001. pci_disable_device(chip->pci);
  2002. kfree(chip->azx_dev);
  2003. kfree(chip);
  2004. return 0;
  2005. }
  2006. static int azx_dev_free(struct snd_device *device)
  2007. {
  2008. return azx_free(device->device_data);
  2009. }
  2010. /*
  2011. * white/black-listing for position_fix
  2012. */
  2013. static struct snd_pci_quirk position_fix_list[] __devinitdata = {
  2014. SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
  2015. SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB),
  2016. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  2017. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  2018. SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
  2019. SND_PCI_QUIRK(0x1028, 0x0470, "Dell Inspiron 1120", POS_FIX_LPIB),
  2020. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  2021. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  2022. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  2023. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  2024. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  2025. SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
  2026. SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),
  2027. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  2028. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  2029. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  2030. SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
  2031. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  2032. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  2033. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  2034. SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
  2035. {}
  2036. };
  2037. static int __devinit check_position_fix(struct azx *chip, int fix)
  2038. {
  2039. const struct snd_pci_quirk *q;
  2040. switch (fix) {
  2041. case POS_FIX_LPIB:
  2042. case POS_FIX_POSBUF:
  2043. case POS_FIX_VIACOMBO:
  2044. return fix;
  2045. }
  2046. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  2047. if (q) {
  2048. printk(KERN_INFO
  2049. "hda_intel: position_fix set to %d "
  2050. "for device %04x:%04x\n",
  2051. q->value, q->subvendor, q->subdevice);
  2052. return q->value;
  2053. }
  2054. /* Check VIA/ATI HD Audio Controller exist */
  2055. switch (chip->driver_type) {
  2056. case AZX_DRIVER_VIA:
  2057. case AZX_DRIVER_ATI:
  2058. /* Use link position directly, avoid any transfer problem. */
  2059. return POS_FIX_VIACOMBO;
  2060. }
  2061. return POS_FIX_AUTO;
  2062. }
  2063. /*
  2064. * black-lists for probe_mask
  2065. */
  2066. static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
  2067. /* Thinkpad often breaks the controller communication when accessing
  2068. * to the non-working (or non-existing) modem codec slot.
  2069. */
  2070. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  2071. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  2072. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  2073. /* broken BIOS */
  2074. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  2075. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  2076. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  2077. /* forced codec slots */
  2078. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  2079. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  2080. {}
  2081. };
  2082. #define AZX_FORCE_CODEC_MASK 0x100
  2083. static void __devinit check_probe_mask(struct azx *chip, int dev)
  2084. {
  2085. const struct snd_pci_quirk *q;
  2086. chip->codec_probe_mask = probe_mask[dev];
  2087. if (chip->codec_probe_mask == -1) {
  2088. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  2089. if (q) {
  2090. printk(KERN_INFO
  2091. "hda_intel: probe_mask set to 0x%x "
  2092. "for device %04x:%04x\n",
  2093. q->value, q->subvendor, q->subdevice);
  2094. chip->codec_probe_mask = q->value;
  2095. }
  2096. }
  2097. /* check forced option */
  2098. if (chip->codec_probe_mask != -1 &&
  2099. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  2100. chip->codec_mask = chip->codec_probe_mask & 0xff;
  2101. printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
  2102. chip->codec_mask);
  2103. }
  2104. }
  2105. /*
  2106. * white/black-list for enable_msi
  2107. */
  2108. static struct snd_pci_quirk msi_black_list[] __devinitdata = {
  2109. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  2110. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  2111. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  2112. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  2113. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  2114. {}
  2115. };
  2116. static void __devinit check_msi(struct azx *chip)
  2117. {
  2118. const struct snd_pci_quirk *q;
  2119. if (enable_msi >= 0) {
  2120. chip->msi = !!enable_msi;
  2121. return;
  2122. }
  2123. chip->msi = 1; /* enable MSI as default */
  2124. q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
  2125. if (q) {
  2126. printk(KERN_INFO
  2127. "hda_intel: msi for device %04x:%04x set to %d\n",
  2128. q->subvendor, q->subdevice, q->value);
  2129. chip->msi = q->value;
  2130. return;
  2131. }
  2132. /* NVidia chipsets seem to cause troubles with MSI */
  2133. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  2134. printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
  2135. chip->msi = 0;
  2136. }
  2137. }
  2138. /*
  2139. * constructor
  2140. */
  2141. static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
  2142. int dev, int driver_type,
  2143. struct azx **rchip)
  2144. {
  2145. struct azx *chip;
  2146. int i, err;
  2147. unsigned short gcap;
  2148. static struct snd_device_ops ops = {
  2149. .dev_free = azx_dev_free,
  2150. };
  2151. *rchip = NULL;
  2152. err = pci_enable_device(pci);
  2153. if (err < 0)
  2154. return err;
  2155. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2156. if (!chip) {
  2157. snd_printk(KERN_ERR SFX "cannot allocate chip\n");
  2158. pci_disable_device(pci);
  2159. return -ENOMEM;
  2160. }
  2161. spin_lock_init(&chip->reg_lock);
  2162. mutex_init(&chip->open_mutex);
  2163. chip->card = card;
  2164. chip->pci = pci;
  2165. chip->irq = -1;
  2166. chip->driver_type = driver_type;
  2167. check_msi(chip);
  2168. chip->dev_index = dev;
  2169. INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
  2170. chip->position_fix[0] = chip->position_fix[1] =
  2171. check_position_fix(chip, position_fix[dev]);
  2172. check_probe_mask(chip, dev);
  2173. chip->single_cmd = single_cmd;
  2174. if (bdl_pos_adj[dev] < 0) {
  2175. switch (chip->driver_type) {
  2176. case AZX_DRIVER_ICH:
  2177. case AZX_DRIVER_PCH:
  2178. bdl_pos_adj[dev] = 1;
  2179. break;
  2180. default:
  2181. bdl_pos_adj[dev] = 32;
  2182. break;
  2183. }
  2184. }
  2185. #if BITS_PER_LONG != 64
  2186. /* Fix up base address on ULI M5461 */
  2187. if (chip->driver_type == AZX_DRIVER_ULI) {
  2188. u16 tmp3;
  2189. pci_read_config_word(pci, 0x40, &tmp3);
  2190. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  2191. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  2192. }
  2193. #endif
  2194. err = pci_request_regions(pci, "ICH HD audio");
  2195. if (err < 0) {
  2196. kfree(chip);
  2197. pci_disable_device(pci);
  2198. return err;
  2199. }
  2200. chip->addr = pci_resource_start(pci, 0);
  2201. chip->remap_addr = pci_ioremap_bar(pci, 0);
  2202. if (chip->remap_addr == NULL) {
  2203. snd_printk(KERN_ERR SFX "ioremap error\n");
  2204. err = -ENXIO;
  2205. goto errout;
  2206. }
  2207. if (chip->msi)
  2208. if (pci_enable_msi(pci) < 0)
  2209. chip->msi = 0;
  2210. if (azx_acquire_irq(chip, 0) < 0) {
  2211. err = -EBUSY;
  2212. goto errout;
  2213. }
  2214. pci_set_master(pci);
  2215. synchronize_irq(chip->irq);
  2216. gcap = azx_readw(chip, GCAP);
  2217. snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
  2218. /* disable SB600 64bit support for safety */
  2219. if ((chip->driver_type == AZX_DRIVER_ATI) ||
  2220. (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
  2221. struct pci_dev *p_smbus;
  2222. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  2223. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  2224. NULL);
  2225. if (p_smbus) {
  2226. if (p_smbus->revision < 0x30)
  2227. gcap &= ~ICH6_GCAP_64OK;
  2228. pci_dev_put(p_smbus);
  2229. }
  2230. }
  2231. /* disable 64bit DMA address for Teradici */
  2232. /* it does not work with device 6549:1200 subsys e4a2:040b */
  2233. if (chip->driver_type == AZX_DRIVER_TERA)
  2234. gcap &= ~ICH6_GCAP_64OK;
  2235. /* allow 64bit DMA address if supported by H/W */
  2236. if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
  2237. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
  2238. else {
  2239. pci_set_dma_mask(pci, DMA_BIT_MASK(32));
  2240. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
  2241. }
  2242. /* read number of streams from GCAP register instead of using
  2243. * hardcoded value
  2244. */
  2245. chip->capture_streams = (gcap >> 8) & 0x0f;
  2246. chip->playback_streams = (gcap >> 12) & 0x0f;
  2247. if (!chip->playback_streams && !chip->capture_streams) {
  2248. /* gcap didn't give any info, switching to old method */
  2249. switch (chip->driver_type) {
  2250. case AZX_DRIVER_ULI:
  2251. chip->playback_streams = ULI_NUM_PLAYBACK;
  2252. chip->capture_streams = ULI_NUM_CAPTURE;
  2253. break;
  2254. case AZX_DRIVER_ATIHDMI:
  2255. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  2256. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  2257. break;
  2258. case AZX_DRIVER_GENERIC:
  2259. default:
  2260. chip->playback_streams = ICH6_NUM_PLAYBACK;
  2261. chip->capture_streams = ICH6_NUM_CAPTURE;
  2262. break;
  2263. }
  2264. }
  2265. chip->capture_index_offset = 0;
  2266. chip->playback_index_offset = chip->capture_streams;
  2267. chip->num_streams = chip->playback_streams + chip->capture_streams;
  2268. chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
  2269. GFP_KERNEL);
  2270. if (!chip->azx_dev) {
  2271. snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");
  2272. goto errout;
  2273. }
  2274. for (i = 0; i < chip->num_streams; i++) {
  2275. /* allocate memory for the BDL for each stream */
  2276. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2277. snd_dma_pci_data(chip->pci),
  2278. BDL_SIZE, &chip->azx_dev[i].bdl);
  2279. if (err < 0) {
  2280. snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
  2281. goto errout;
  2282. }
  2283. }
  2284. /* allocate memory for the position buffer */
  2285. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2286. snd_dma_pci_data(chip->pci),
  2287. chip->num_streams * 8, &chip->posbuf);
  2288. if (err < 0) {
  2289. snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
  2290. goto errout;
  2291. }
  2292. /* allocate CORB/RIRB */
  2293. err = azx_alloc_cmd_io(chip);
  2294. if (err < 0)
  2295. goto errout;
  2296. /* initialize streams */
  2297. azx_init_stream(chip);
  2298. /* initialize chip */
  2299. azx_init_pci(chip);
  2300. azx_init_chip(chip, (probe_only[dev] & 2) == 0);
  2301. /* codec detection */
  2302. if (!chip->codec_mask) {
  2303. snd_printk(KERN_ERR SFX "no codecs found!\n");
  2304. err = -ENODEV;
  2305. goto errout;
  2306. }
  2307. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  2308. if (err <0) {
  2309. snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
  2310. goto errout;
  2311. }
  2312. strcpy(card->driver, "HDA-Intel");
  2313. strlcpy(card->shortname, driver_short_names[chip->driver_type],
  2314. sizeof(card->shortname));
  2315. snprintf(card->longname, sizeof(card->longname),
  2316. "%s at 0x%lx irq %i",
  2317. card->shortname, chip->addr, chip->irq);
  2318. *rchip = chip;
  2319. return 0;
  2320. errout:
  2321. azx_free(chip);
  2322. return err;
  2323. }
  2324. static void power_down_all_codecs(struct azx *chip)
  2325. {
  2326. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2327. /* The codecs were powered up in snd_hda_codec_new().
  2328. * Now all initialization done, so turn them down if possible
  2329. */
  2330. struct hda_codec *codec;
  2331. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  2332. snd_hda_power_down(codec);
  2333. }
  2334. #endif
  2335. }
  2336. static int __devinit azx_probe(struct pci_dev *pci,
  2337. const struct pci_device_id *pci_id)
  2338. {
  2339. static int dev;
  2340. struct snd_card *card;
  2341. struct azx *chip;
  2342. int err;
  2343. if (dev >= SNDRV_CARDS)
  2344. return -ENODEV;
  2345. if (!enable[dev]) {
  2346. dev++;
  2347. return -ENOENT;
  2348. }
  2349. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  2350. if (err < 0) {
  2351. snd_printk(KERN_ERR SFX "Error creating card!\n");
  2352. return err;
  2353. }
  2354. /* set this here since it's referred in snd_hda_load_patch() */
  2355. snd_card_set_dev(card, &pci->dev);
  2356. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  2357. if (err < 0)
  2358. goto out_free;
  2359. card->private_data = chip;
  2360. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2361. chip->beep_mode = beep_mode[dev];
  2362. #endif
  2363. /* create codec instances */
  2364. err = azx_codec_create(chip, model[dev]);
  2365. if (err < 0)
  2366. goto out_free;
  2367. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  2368. if (patch[dev] && *patch[dev]) {
  2369. snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
  2370. patch[dev]);
  2371. err = snd_hda_load_patch(chip->bus, patch[dev]);
  2372. if (err < 0)
  2373. goto out_free;
  2374. }
  2375. #endif
  2376. if ((probe_only[dev] & 1) == 0) {
  2377. err = azx_codec_configure(chip);
  2378. if (err < 0)
  2379. goto out_free;
  2380. }
  2381. /* create PCM streams */
  2382. err = snd_hda_build_pcms(chip->bus);
  2383. if (err < 0)
  2384. goto out_free;
  2385. /* create mixer controls */
  2386. err = azx_mixer_create(chip);
  2387. if (err < 0)
  2388. goto out_free;
  2389. err = snd_card_register(card);
  2390. if (err < 0)
  2391. goto out_free;
  2392. pci_set_drvdata(pci, card);
  2393. chip->running = 1;
  2394. power_down_all_codecs(chip);
  2395. azx_notifier_register(chip);
  2396. dev++;
  2397. return err;
  2398. out_free:
  2399. snd_card_free(card);
  2400. return err;
  2401. }
  2402. static void __devexit azx_remove(struct pci_dev *pci)
  2403. {
  2404. snd_card_free(pci_get_drvdata(pci));
  2405. pci_set_drvdata(pci, NULL);
  2406. }
  2407. /* PCI IDs */
  2408. static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
  2409. /* CPT */
  2410. { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
  2411. /* PBG */
  2412. { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH },
  2413. /* SCH */
  2414. { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
  2415. /* Generic Intel */
  2416. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
  2417. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2418. .class_mask = 0xffffff,
  2419. .driver_data = AZX_DRIVER_ICH },
  2420. /* ATI SB 450/600 */
  2421. { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
  2422. { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
  2423. /* ATI HDMI */
  2424. { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
  2425. { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
  2426. { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
  2427. { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI },
  2428. { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
  2429. { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
  2430. { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
  2431. { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
  2432. { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
  2433. { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
  2434. { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
  2435. { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
  2436. { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
  2437. { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
  2438. /* VIA VT8251/VT8237A */
  2439. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2440. /* SIS966 */
  2441. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2442. /* ULI M5461 */
  2443. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2444. /* NVIDIA MCP */
  2445. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2446. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2447. .class_mask = 0xffffff,
  2448. .driver_data = AZX_DRIVER_NVIDIA },
  2449. /* Teradici */
  2450. { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
  2451. /* Creative X-Fi (CA0110-IBG) */
  2452. #if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE)
  2453. /* the following entry conflicts with snd-ctxfi driver,
  2454. * as ctxfi driver mutates from HD-audio to native mode with
  2455. * a special command sequence.
  2456. */
  2457. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2458. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2459. .class_mask = 0xffffff,
  2460. .driver_data = AZX_DRIVER_CTX },
  2461. #else
  2462. /* this entry seems still valid -- i.e. without emu20kx chip */
  2463. { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX },
  2464. #endif
  2465. /* Vortex86MX */
  2466. { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
  2467. /* VMware HDAudio */
  2468. { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
  2469. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2470. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2471. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2472. .class_mask = 0xffffff,
  2473. .driver_data = AZX_DRIVER_GENERIC },
  2474. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2475. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2476. .class_mask = 0xffffff,
  2477. .driver_data = AZX_DRIVER_GENERIC },
  2478. { 0, }
  2479. };
  2480. MODULE_DEVICE_TABLE(pci, azx_ids);
  2481. /* pci_driver definition */
  2482. static struct pci_driver driver = {
  2483. .name = "HDA Intel",
  2484. .id_table = azx_ids,
  2485. .probe = azx_probe,
  2486. .remove = __devexit_p(azx_remove),
  2487. #ifdef CONFIG_PM
  2488. .suspend = azx_suspend,
  2489. .resume = azx_resume,
  2490. #endif
  2491. };
  2492. static int __init alsa_card_azx_init(void)
  2493. {
  2494. return pci_register_driver(&driver);
  2495. }
  2496. static void __exit alsa_card_azx_exit(void)
  2497. {
  2498. pci_unregister_driver(&driver);
  2499. }
  2500. module_init(alsa_card_azx_init)
  2501. module_exit(alsa_card_azx_exit)