hda_intel.c 74 KB

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