hda_intel.c 76 KB

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