hda_intel.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838
  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, PBG},"
  123. "{Intel, SCH},"
  124. "{ATI, SB450},"
  125. "{ATI, SB600},"
  126. "{ATI, RS600},"
  127. "{ATI, RS690},"
  128. "{ATI, RS780},"
  129. "{ATI, R600},"
  130. "{ATI, RV630},"
  131. "{ATI, RV610},"
  132. "{ATI, RV670},"
  133. "{ATI, RV635},"
  134. "{ATI, RV620},"
  135. "{ATI, RV770},"
  136. "{VIA, VT8251},"
  137. "{VIA, VT8237A},"
  138. "{SiS, SIS966},"
  139. "{ULI, M5461}}");
  140. MODULE_DESCRIPTION("Intel HDA driver");
  141. #ifdef CONFIG_SND_VERBOSE_PRINTK
  142. #define SFX /* nop */
  143. #else
  144. #define SFX "hda-intel: "
  145. #endif
  146. /*
  147. * registers
  148. */
  149. #define ICH6_REG_GCAP 0x00
  150. #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
  151. #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  152. #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  153. #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
  154. #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
  155. #define ICH6_REG_VMIN 0x02
  156. #define ICH6_REG_VMAJ 0x03
  157. #define ICH6_REG_OUTPAY 0x04
  158. #define ICH6_REG_INPAY 0x06
  159. #define ICH6_REG_GCTL 0x08
  160. #define ICH6_GCTL_RESET (1 << 0) /* controller reset */
  161. #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
  162. #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  163. #define ICH6_REG_WAKEEN 0x0c
  164. #define ICH6_REG_STATESTS 0x0e
  165. #define ICH6_REG_GSTS 0x10
  166. #define ICH6_GSTS_FSTS (1 << 1) /* flush status */
  167. #define ICH6_REG_INTCTL 0x20
  168. #define ICH6_REG_INTSTS 0x24
  169. #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
  170. #define ICH6_REG_SYNC 0x34
  171. #define ICH6_REG_CORBLBASE 0x40
  172. #define ICH6_REG_CORBUBASE 0x44
  173. #define ICH6_REG_CORBWP 0x48
  174. #define ICH6_REG_CORBRP 0x4a
  175. #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
  176. #define ICH6_REG_CORBCTL 0x4c
  177. #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
  178. #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  179. #define ICH6_REG_CORBSTS 0x4d
  180. #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
  181. #define ICH6_REG_CORBSIZE 0x4e
  182. #define ICH6_REG_RIRBLBASE 0x50
  183. #define ICH6_REG_RIRBUBASE 0x54
  184. #define ICH6_REG_RIRBWP 0x58
  185. #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
  186. #define ICH6_REG_RINTCNT 0x5a
  187. #define ICH6_REG_RIRBCTL 0x5c
  188. #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  189. #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  190. #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  191. #define ICH6_REG_RIRBSTS 0x5d
  192. #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
  193. #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  194. #define ICH6_REG_RIRBSIZE 0x5e
  195. #define ICH6_REG_IC 0x60
  196. #define ICH6_REG_IR 0x64
  197. #define ICH6_REG_IRS 0x68
  198. #define ICH6_IRS_VALID (1<<1)
  199. #define ICH6_IRS_BUSY (1<<0)
  200. #define ICH6_REG_DPLBASE 0x70
  201. #define ICH6_REG_DPUBASE 0x74
  202. #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  203. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  204. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  205. /* stream register offsets from stream base */
  206. #define ICH6_REG_SD_CTL 0x00
  207. #define ICH6_REG_SD_STS 0x03
  208. #define ICH6_REG_SD_LPIB 0x04
  209. #define ICH6_REG_SD_CBL 0x08
  210. #define ICH6_REG_SD_LVI 0x0c
  211. #define ICH6_REG_SD_FIFOW 0x0e
  212. #define ICH6_REG_SD_FIFOSIZE 0x10
  213. #define ICH6_REG_SD_FORMAT 0x12
  214. #define ICH6_REG_SD_BDLPL 0x18
  215. #define ICH6_REG_SD_BDLPU 0x1c
  216. /* PCI space */
  217. #define ICH6_PCIREG_TCSEL 0x44
  218. /*
  219. * other constants
  220. */
  221. /* max number of SDs */
  222. /* ICH, ATI and VIA have 4 playback and 4 capture */
  223. #define ICH6_NUM_CAPTURE 4
  224. #define ICH6_NUM_PLAYBACK 4
  225. /* ULI has 6 playback and 5 capture */
  226. #define ULI_NUM_CAPTURE 5
  227. #define ULI_NUM_PLAYBACK 6
  228. /* ATI HDMI has 1 playback and 0 capture */
  229. #define ATIHDMI_NUM_CAPTURE 0
  230. #define ATIHDMI_NUM_PLAYBACK 1
  231. /* TERA has 4 playback and 3 capture */
  232. #define TERA_NUM_CAPTURE 3
  233. #define TERA_NUM_PLAYBACK 4
  234. /* this number is statically defined for simplicity */
  235. #define MAX_AZX_DEV 16
  236. /* max number of fragments - we may use more if allocating more pages for BDL */
  237. #define BDL_SIZE 4096
  238. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  239. #define AZX_MAX_FRAG 32
  240. /* max buffer size - no h/w limit, you can increase as you like */
  241. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  242. /* RIRB int mask: overrun[2], response[0] */
  243. #define RIRB_INT_RESPONSE 0x01
  244. #define RIRB_INT_OVERRUN 0x04
  245. #define RIRB_INT_MASK 0x05
  246. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  247. #define AZX_MAX_CODECS 8
  248. #define AZX_DEFAULT_CODECS 4
  249. #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
  250. /* SD_CTL bits */
  251. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  252. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  253. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  254. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  255. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  256. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  257. #define SD_CTL_STREAM_TAG_SHIFT 20
  258. /* SD_CTL and SD_STS */
  259. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  260. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  261. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  262. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  263. SD_INT_COMPLETE)
  264. /* SD_STS */
  265. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  266. /* INTCTL and INTSTS */
  267. #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
  268. #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  269. #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  270. /* below are so far hardcoded - should read registers in future */
  271. #define ICH6_MAX_CORB_ENTRIES 256
  272. #define ICH6_MAX_RIRB_ENTRIES 256
  273. /* position fix mode */
  274. enum {
  275. POS_FIX_AUTO,
  276. POS_FIX_LPIB,
  277. POS_FIX_POSBUF,
  278. };
  279. /* Defines for ATI HD Audio support in SB450 south bridge */
  280. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  281. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  282. /* Defines for Nvidia HDA support */
  283. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  284. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  285. #define NVIDIA_HDA_ISTRM_COH 0x4d
  286. #define NVIDIA_HDA_OSTRM_COH 0x4c
  287. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  288. /* Defines for Intel SCH HDA snoop control */
  289. #define INTEL_SCH_HDA_DEVC 0x78
  290. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  291. /* Define IN stream 0 FIFO size offset in VIA controller */
  292. #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
  293. /* Define VIA HD Audio Device ID*/
  294. #define VIA_HDAC_DEVICE_ID 0x3288
  295. /* HD Audio class code */
  296. #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
  297. /*
  298. */
  299. struct azx_dev {
  300. struct snd_dma_buffer bdl; /* BDL buffer */
  301. u32 *posbuf; /* position buffer pointer */
  302. unsigned int bufsize; /* size of the play buffer in bytes */
  303. unsigned int period_bytes; /* size of the period in bytes */
  304. unsigned int frags; /* number for period in the play buffer */
  305. unsigned int fifo_size; /* FIFO size */
  306. unsigned long start_wallclk; /* start + minimum wallclk */
  307. unsigned long period_wallclk; /* wallclk for period */
  308. void __iomem *sd_addr; /* stream descriptor pointer */
  309. u32 sd_int_sta_mask; /* stream int status mask */
  310. /* pcm support */
  311. struct snd_pcm_substream *substream; /* assigned substream,
  312. * set in PCM open
  313. */
  314. unsigned int format_val; /* format value to be set in the
  315. * controller and the codec
  316. */
  317. unsigned char stream_tag; /* assigned stream */
  318. unsigned char index; /* stream index */
  319. int device; /* last device number assigned to */
  320. unsigned int opened :1;
  321. unsigned int running :1;
  322. unsigned int irq_pending :1;
  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[2]; /* for both playback/capture streams */
  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. u8 sd_status;
  950. int i, ok;
  951. spin_lock(&chip->reg_lock);
  952. status = azx_readl(chip, INTSTS);
  953. if (status == 0) {
  954. spin_unlock(&chip->reg_lock);
  955. return IRQ_NONE;
  956. }
  957. for (i = 0; i < chip->num_streams; i++) {
  958. azx_dev = &chip->azx_dev[i];
  959. if (status & azx_dev->sd_int_sta_mask) {
  960. sd_status = azx_sd_readb(azx_dev, SD_STS);
  961. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  962. if (!azx_dev->substream || !azx_dev->running ||
  963. !(sd_status & SD_INT_COMPLETE))
  964. continue;
  965. /* check whether this IRQ is really acceptable */
  966. ok = azx_position_ok(chip, azx_dev);
  967. if (ok == 1) {
  968. azx_dev->irq_pending = 0;
  969. spin_unlock(&chip->reg_lock);
  970. snd_pcm_period_elapsed(azx_dev->substream);
  971. spin_lock(&chip->reg_lock);
  972. } else if (ok == 0 && chip->bus && chip->bus->workq) {
  973. /* bogus IRQ, process it later */
  974. azx_dev->irq_pending = 1;
  975. queue_work(chip->bus->workq,
  976. &chip->irq_pending_work);
  977. }
  978. }
  979. }
  980. /* clear rirb int */
  981. status = azx_readb(chip, RIRBSTS);
  982. if (status & RIRB_INT_MASK) {
  983. if (status & RIRB_INT_RESPONSE)
  984. azx_update_rirb(chip);
  985. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  986. }
  987. #if 0
  988. /* clear state status int */
  989. if (azx_readb(chip, STATESTS) & 0x04)
  990. azx_writeb(chip, STATESTS, 0x04);
  991. #endif
  992. spin_unlock(&chip->reg_lock);
  993. return IRQ_HANDLED;
  994. }
  995. /*
  996. * set up a BDL entry
  997. */
  998. static int setup_bdle(struct snd_pcm_substream *substream,
  999. struct azx_dev *azx_dev, u32 **bdlp,
  1000. int ofs, int size, int with_ioc)
  1001. {
  1002. u32 *bdl = *bdlp;
  1003. while (size > 0) {
  1004. dma_addr_t addr;
  1005. int chunk;
  1006. if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
  1007. return -EINVAL;
  1008. addr = snd_pcm_sgbuf_get_addr(substream, ofs);
  1009. /* program the address field of the BDL entry */
  1010. bdl[0] = cpu_to_le32((u32)addr);
  1011. bdl[1] = cpu_to_le32(upper_32_bits(addr));
  1012. /* program the size field of the BDL entry */
  1013. chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
  1014. bdl[2] = cpu_to_le32(chunk);
  1015. /* program the IOC to enable interrupt
  1016. * only when the whole fragment is processed
  1017. */
  1018. size -= chunk;
  1019. bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
  1020. bdl += 4;
  1021. azx_dev->frags++;
  1022. ofs += chunk;
  1023. }
  1024. *bdlp = bdl;
  1025. return ofs;
  1026. }
  1027. /*
  1028. * set up BDL entries
  1029. */
  1030. static int azx_setup_periods(struct azx *chip,
  1031. struct snd_pcm_substream *substream,
  1032. struct azx_dev *azx_dev)
  1033. {
  1034. u32 *bdl;
  1035. int i, ofs, periods, period_bytes;
  1036. int pos_adj;
  1037. /* reset BDL address */
  1038. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1039. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1040. period_bytes = azx_dev->period_bytes;
  1041. periods = azx_dev->bufsize / period_bytes;
  1042. /* program the initial BDL entries */
  1043. bdl = (u32 *)azx_dev->bdl.area;
  1044. ofs = 0;
  1045. azx_dev->frags = 0;
  1046. pos_adj = bdl_pos_adj[chip->dev_index];
  1047. if (pos_adj > 0) {
  1048. struct snd_pcm_runtime *runtime = substream->runtime;
  1049. int pos_align = pos_adj;
  1050. pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
  1051. if (!pos_adj)
  1052. pos_adj = pos_align;
  1053. else
  1054. pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
  1055. pos_align;
  1056. pos_adj = frames_to_bytes(runtime, pos_adj);
  1057. if (pos_adj >= period_bytes) {
  1058. snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",
  1059. bdl_pos_adj[chip->dev_index]);
  1060. pos_adj = 0;
  1061. } else {
  1062. ofs = setup_bdle(substream, azx_dev,
  1063. &bdl, ofs, pos_adj, 1);
  1064. if (ofs < 0)
  1065. goto error;
  1066. }
  1067. } else
  1068. pos_adj = 0;
  1069. for (i = 0; i < periods; i++) {
  1070. if (i == periods - 1 && pos_adj)
  1071. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1072. period_bytes - pos_adj, 0);
  1073. else
  1074. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1075. period_bytes, 1);
  1076. if (ofs < 0)
  1077. goto error;
  1078. }
  1079. return 0;
  1080. error:
  1081. snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
  1082. azx_dev->bufsize, period_bytes);
  1083. return -EINVAL;
  1084. }
  1085. /* reset stream */
  1086. static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
  1087. {
  1088. unsigned char val;
  1089. int timeout;
  1090. azx_stream_clear(chip, azx_dev);
  1091. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  1092. SD_CTL_STREAM_RESET);
  1093. udelay(3);
  1094. timeout = 300;
  1095. while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1096. --timeout)
  1097. ;
  1098. val &= ~SD_CTL_STREAM_RESET;
  1099. azx_sd_writeb(azx_dev, SD_CTL, val);
  1100. udelay(3);
  1101. timeout = 300;
  1102. /* waiting for hardware to report that the stream is out of reset */
  1103. while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1104. --timeout)
  1105. ;
  1106. /* reset first position - may not be synced with hw at this time */
  1107. *azx_dev->posbuf = 0;
  1108. }
  1109. /*
  1110. * set up the SD for streaming
  1111. */
  1112. static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
  1113. {
  1114. /* make sure the run bit is zero for SD */
  1115. azx_stream_clear(chip, azx_dev);
  1116. /* program the stream_tag */
  1117. azx_sd_writel(azx_dev, SD_CTL,
  1118. (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
  1119. (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
  1120. /* program the length of samples in cyclic buffer */
  1121. azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
  1122. /* program the stream format */
  1123. /* this value needs to be the same as the one programmed */
  1124. azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
  1125. /* program the stream LVI (last valid index) of the BDL */
  1126. azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
  1127. /* program the BDL address */
  1128. /* lower BDL address */
  1129. azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
  1130. /* upper BDL address */
  1131. azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
  1132. /* enable the position buffer */
  1133. if (chip->position_fix[0] == POS_FIX_POSBUF ||
  1134. chip->position_fix[0] == POS_FIX_AUTO ||
  1135. chip->position_fix[1] == POS_FIX_POSBUF ||
  1136. chip->position_fix[1] == POS_FIX_AUTO ||
  1137. chip->via_dmapos_patch) {
  1138. if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
  1139. azx_writel(chip, DPLBASE,
  1140. (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
  1141. }
  1142. /* set the interrupt enable bits in the descriptor control register */
  1143. azx_sd_writel(azx_dev, SD_CTL,
  1144. azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
  1145. return 0;
  1146. }
  1147. /*
  1148. * Probe the given codec address
  1149. */
  1150. static int probe_codec(struct azx *chip, int addr)
  1151. {
  1152. unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
  1153. (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
  1154. unsigned int res;
  1155. mutex_lock(&chip->bus->cmd_mutex);
  1156. chip->probing = 1;
  1157. azx_send_cmd(chip->bus, cmd);
  1158. res = azx_get_response(chip->bus, addr);
  1159. chip->probing = 0;
  1160. mutex_unlock(&chip->bus->cmd_mutex);
  1161. if (res == -1)
  1162. return -EIO;
  1163. snd_printdd(SFX "codec #%d probed OK\n", addr);
  1164. return 0;
  1165. }
  1166. static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1167. struct hda_pcm *cpcm);
  1168. static void azx_stop_chip(struct azx *chip);
  1169. static void azx_bus_reset(struct hda_bus *bus)
  1170. {
  1171. struct azx *chip = bus->private_data;
  1172. bus->in_reset = 1;
  1173. azx_stop_chip(chip);
  1174. azx_init_chip(chip, 1);
  1175. #ifdef CONFIG_PM
  1176. if (chip->initialized) {
  1177. int i;
  1178. for (i = 0; i < HDA_MAX_PCMS; i++)
  1179. snd_pcm_suspend_all(chip->pcm[i]);
  1180. snd_hda_suspend(chip->bus);
  1181. snd_hda_resume(chip->bus);
  1182. }
  1183. #endif
  1184. bus->in_reset = 0;
  1185. }
  1186. /*
  1187. * Codec initialization
  1188. */
  1189. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1190. static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
  1191. [AZX_DRIVER_NVIDIA] = 8,
  1192. [AZX_DRIVER_TERA] = 1,
  1193. };
  1194. static int __devinit azx_codec_create(struct azx *chip, const char *model)
  1195. {
  1196. struct hda_bus_template bus_temp;
  1197. int c, codecs, err;
  1198. int max_slots;
  1199. memset(&bus_temp, 0, sizeof(bus_temp));
  1200. bus_temp.private_data = chip;
  1201. bus_temp.modelname = model;
  1202. bus_temp.pci = chip->pci;
  1203. bus_temp.ops.command = azx_send_cmd;
  1204. bus_temp.ops.get_response = azx_get_response;
  1205. bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
  1206. bus_temp.ops.bus_reset = azx_bus_reset;
  1207. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1208. bus_temp.power_save = &power_save;
  1209. bus_temp.ops.pm_notify = azx_power_notify;
  1210. #endif
  1211. err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
  1212. if (err < 0)
  1213. return err;
  1214. if (chip->driver_type == AZX_DRIVER_NVIDIA)
  1215. chip->bus->needs_damn_long_delay = 1;
  1216. codecs = 0;
  1217. max_slots = azx_max_codecs[chip->driver_type];
  1218. if (!max_slots)
  1219. max_slots = AZX_DEFAULT_CODECS;
  1220. /* First try to probe all given codec slots */
  1221. for (c = 0; c < max_slots; c++) {
  1222. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1223. if (probe_codec(chip, c) < 0) {
  1224. /* Some BIOSen give you wrong codec addresses
  1225. * that don't exist
  1226. */
  1227. snd_printk(KERN_WARNING SFX
  1228. "Codec #%d probe error; "
  1229. "disabling it...\n", c);
  1230. chip->codec_mask &= ~(1 << c);
  1231. /* More badly, accessing to a non-existing
  1232. * codec often screws up the controller chip,
  1233. * and disturbs the further communications.
  1234. * Thus if an error occurs during probing,
  1235. * better to reset the controller chip to
  1236. * get back to the sanity state.
  1237. */
  1238. azx_stop_chip(chip);
  1239. azx_init_chip(chip, 1);
  1240. }
  1241. }
  1242. }
  1243. /* Then create codec instances */
  1244. for (c = 0; c < max_slots; c++) {
  1245. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1246. struct hda_codec *codec;
  1247. err = snd_hda_codec_new(chip->bus, c, &codec);
  1248. if (err < 0)
  1249. continue;
  1250. codec->beep_mode = chip->beep_mode;
  1251. codecs++;
  1252. }
  1253. }
  1254. if (!codecs) {
  1255. snd_printk(KERN_ERR SFX "no codecs initialized\n");
  1256. return -ENXIO;
  1257. }
  1258. return 0;
  1259. }
  1260. /* configure each codec instance */
  1261. static int __devinit azx_codec_configure(struct azx *chip)
  1262. {
  1263. struct hda_codec *codec;
  1264. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  1265. snd_hda_codec_configure(codec);
  1266. }
  1267. return 0;
  1268. }
  1269. /*
  1270. * PCM support
  1271. */
  1272. /* assign a stream for the PCM */
  1273. static inline struct azx_dev *
  1274. azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
  1275. {
  1276. int dev, i, nums;
  1277. struct azx_dev *res = NULL;
  1278. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1279. dev = chip->playback_index_offset;
  1280. nums = chip->playback_streams;
  1281. } else {
  1282. dev = chip->capture_index_offset;
  1283. nums = chip->capture_streams;
  1284. }
  1285. for (i = 0; i < nums; i++, dev++)
  1286. if (!chip->azx_dev[dev].opened) {
  1287. res = &chip->azx_dev[dev];
  1288. if (res->device == substream->pcm->device)
  1289. break;
  1290. }
  1291. if (res) {
  1292. res->opened = 1;
  1293. res->device = substream->pcm->device;
  1294. }
  1295. return res;
  1296. }
  1297. /* release the assigned stream */
  1298. static inline void azx_release_device(struct azx_dev *azx_dev)
  1299. {
  1300. azx_dev->opened = 0;
  1301. }
  1302. static struct snd_pcm_hardware azx_pcm_hw = {
  1303. .info = (SNDRV_PCM_INFO_MMAP |
  1304. SNDRV_PCM_INFO_INTERLEAVED |
  1305. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1306. SNDRV_PCM_INFO_MMAP_VALID |
  1307. /* No full-resume yet implemented */
  1308. /* SNDRV_PCM_INFO_RESUME |*/
  1309. SNDRV_PCM_INFO_PAUSE |
  1310. SNDRV_PCM_INFO_SYNC_START),
  1311. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1312. .rates = SNDRV_PCM_RATE_48000,
  1313. .rate_min = 48000,
  1314. .rate_max = 48000,
  1315. .channels_min = 2,
  1316. .channels_max = 2,
  1317. .buffer_bytes_max = AZX_MAX_BUF_SIZE,
  1318. .period_bytes_min = 128,
  1319. .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
  1320. .periods_min = 2,
  1321. .periods_max = AZX_MAX_FRAG,
  1322. .fifo_size = 0,
  1323. };
  1324. struct azx_pcm {
  1325. struct azx *chip;
  1326. struct hda_codec *codec;
  1327. struct hda_pcm_stream *hinfo[2];
  1328. };
  1329. static int azx_pcm_open(struct snd_pcm_substream *substream)
  1330. {
  1331. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1332. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1333. struct azx *chip = apcm->chip;
  1334. struct azx_dev *azx_dev;
  1335. struct snd_pcm_runtime *runtime = substream->runtime;
  1336. unsigned long flags;
  1337. int err;
  1338. mutex_lock(&chip->open_mutex);
  1339. azx_dev = azx_assign_device(chip, substream);
  1340. if (azx_dev == NULL) {
  1341. mutex_unlock(&chip->open_mutex);
  1342. return -EBUSY;
  1343. }
  1344. runtime->hw = azx_pcm_hw;
  1345. runtime->hw.channels_min = hinfo->channels_min;
  1346. runtime->hw.channels_max = hinfo->channels_max;
  1347. runtime->hw.formats = hinfo->formats;
  1348. runtime->hw.rates = hinfo->rates;
  1349. snd_pcm_limit_hw_rates(runtime);
  1350. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  1351. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1352. 128);
  1353. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1354. 128);
  1355. snd_hda_power_up(apcm->codec);
  1356. err = hinfo->ops.open(hinfo, apcm->codec, substream);
  1357. if (err < 0) {
  1358. azx_release_device(azx_dev);
  1359. snd_hda_power_down(apcm->codec);
  1360. mutex_unlock(&chip->open_mutex);
  1361. return err;
  1362. }
  1363. snd_pcm_limit_hw_rates(runtime);
  1364. /* sanity check */
  1365. if (snd_BUG_ON(!runtime->hw.channels_min) ||
  1366. snd_BUG_ON(!runtime->hw.channels_max) ||
  1367. snd_BUG_ON(!runtime->hw.formats) ||
  1368. snd_BUG_ON(!runtime->hw.rates)) {
  1369. azx_release_device(azx_dev);
  1370. hinfo->ops.close(hinfo, apcm->codec, substream);
  1371. snd_hda_power_down(apcm->codec);
  1372. mutex_unlock(&chip->open_mutex);
  1373. return -EINVAL;
  1374. }
  1375. spin_lock_irqsave(&chip->reg_lock, flags);
  1376. azx_dev->substream = substream;
  1377. azx_dev->running = 0;
  1378. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1379. runtime->private_data = azx_dev;
  1380. snd_pcm_set_sync(substream);
  1381. mutex_unlock(&chip->open_mutex);
  1382. return 0;
  1383. }
  1384. static int azx_pcm_close(struct snd_pcm_substream *substream)
  1385. {
  1386. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1387. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1388. struct azx *chip = apcm->chip;
  1389. struct azx_dev *azx_dev = get_azx_dev(substream);
  1390. unsigned long flags;
  1391. mutex_lock(&chip->open_mutex);
  1392. spin_lock_irqsave(&chip->reg_lock, flags);
  1393. azx_dev->substream = NULL;
  1394. azx_dev->running = 0;
  1395. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1396. azx_release_device(azx_dev);
  1397. hinfo->ops.close(hinfo, apcm->codec, substream);
  1398. snd_hda_power_down(apcm->codec);
  1399. mutex_unlock(&chip->open_mutex);
  1400. return 0;
  1401. }
  1402. static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
  1403. struct snd_pcm_hw_params *hw_params)
  1404. {
  1405. struct azx_dev *azx_dev = get_azx_dev(substream);
  1406. azx_dev->bufsize = 0;
  1407. azx_dev->period_bytes = 0;
  1408. azx_dev->format_val = 0;
  1409. return snd_pcm_lib_malloc_pages(substream,
  1410. params_buffer_bytes(hw_params));
  1411. }
  1412. static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
  1413. {
  1414. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1415. struct azx_dev *azx_dev = get_azx_dev(substream);
  1416. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1417. /* reset BDL address */
  1418. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1419. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1420. azx_sd_writel(azx_dev, SD_CTL, 0);
  1421. azx_dev->bufsize = 0;
  1422. azx_dev->period_bytes = 0;
  1423. azx_dev->format_val = 0;
  1424. snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
  1425. return snd_pcm_lib_free_pages(substream);
  1426. }
  1427. static int azx_pcm_prepare(struct snd_pcm_substream *substream)
  1428. {
  1429. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1430. struct azx *chip = apcm->chip;
  1431. struct azx_dev *azx_dev = get_azx_dev(substream);
  1432. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1433. struct snd_pcm_runtime *runtime = substream->runtime;
  1434. unsigned int bufsize, period_bytes, format_val;
  1435. int err;
  1436. azx_stream_reset(chip, azx_dev);
  1437. format_val = snd_hda_calc_stream_format(runtime->rate,
  1438. runtime->channels,
  1439. runtime->format,
  1440. hinfo->maxbps,
  1441. apcm->codec->spdif_ctls);
  1442. if (!format_val) {
  1443. snd_printk(KERN_ERR SFX
  1444. "invalid format_val, rate=%d, ch=%d, format=%d\n",
  1445. runtime->rate, runtime->channels, runtime->format);
  1446. return -EINVAL;
  1447. }
  1448. bufsize = snd_pcm_lib_buffer_bytes(substream);
  1449. period_bytes = snd_pcm_lib_period_bytes(substream);
  1450. snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
  1451. bufsize, format_val);
  1452. if (bufsize != azx_dev->bufsize ||
  1453. period_bytes != azx_dev->period_bytes ||
  1454. format_val != azx_dev->format_val) {
  1455. azx_dev->bufsize = bufsize;
  1456. azx_dev->period_bytes = period_bytes;
  1457. azx_dev->format_val = format_val;
  1458. err = azx_setup_periods(chip, substream, azx_dev);
  1459. if (err < 0)
  1460. return err;
  1461. }
  1462. /* wallclk has 24Mhz clock source */
  1463. azx_dev->period_wallclk = (((runtime->period_size * 24000) /
  1464. runtime->rate) * 1000);
  1465. azx_setup_controller(chip, azx_dev);
  1466. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1467. azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
  1468. else
  1469. azx_dev->fifo_size = 0;
  1470. return snd_hda_codec_prepare(apcm->codec, hinfo, azx_dev->stream_tag,
  1471. azx_dev->format_val, substream);
  1472. }
  1473. static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  1474. {
  1475. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1476. struct azx *chip = apcm->chip;
  1477. struct azx_dev *azx_dev;
  1478. struct snd_pcm_substream *s;
  1479. int rstart = 0, start, nsync = 0, sbits = 0;
  1480. int nwait, timeout;
  1481. switch (cmd) {
  1482. case SNDRV_PCM_TRIGGER_START:
  1483. rstart = 1;
  1484. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1485. case SNDRV_PCM_TRIGGER_RESUME:
  1486. start = 1;
  1487. break;
  1488. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1489. case SNDRV_PCM_TRIGGER_SUSPEND:
  1490. case SNDRV_PCM_TRIGGER_STOP:
  1491. start = 0;
  1492. break;
  1493. default:
  1494. return -EINVAL;
  1495. }
  1496. snd_pcm_group_for_each_entry(s, substream) {
  1497. if (s->pcm->card != substream->pcm->card)
  1498. continue;
  1499. azx_dev = get_azx_dev(s);
  1500. sbits |= 1 << azx_dev->index;
  1501. nsync++;
  1502. snd_pcm_trigger_done(s, substream);
  1503. }
  1504. spin_lock(&chip->reg_lock);
  1505. if (nsync > 1) {
  1506. /* first, set SYNC bits of corresponding streams */
  1507. azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
  1508. }
  1509. snd_pcm_group_for_each_entry(s, substream) {
  1510. if (s->pcm->card != substream->pcm->card)
  1511. continue;
  1512. azx_dev = get_azx_dev(s);
  1513. if (start) {
  1514. azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
  1515. if (!rstart)
  1516. azx_dev->start_wallclk -=
  1517. azx_dev->period_wallclk;
  1518. azx_stream_start(chip, azx_dev);
  1519. } else {
  1520. azx_stream_stop(chip, azx_dev);
  1521. }
  1522. azx_dev->running = start;
  1523. }
  1524. spin_unlock(&chip->reg_lock);
  1525. if (start) {
  1526. if (nsync == 1)
  1527. return 0;
  1528. /* wait until all FIFOs get ready */
  1529. for (timeout = 5000; timeout; timeout--) {
  1530. nwait = 0;
  1531. snd_pcm_group_for_each_entry(s, substream) {
  1532. if (s->pcm->card != substream->pcm->card)
  1533. continue;
  1534. azx_dev = get_azx_dev(s);
  1535. if (!(azx_sd_readb(azx_dev, SD_STS) &
  1536. SD_STS_FIFO_READY))
  1537. nwait++;
  1538. }
  1539. if (!nwait)
  1540. break;
  1541. cpu_relax();
  1542. }
  1543. } else {
  1544. /* wait until all RUN bits are cleared */
  1545. for (timeout = 5000; timeout; timeout--) {
  1546. nwait = 0;
  1547. snd_pcm_group_for_each_entry(s, substream) {
  1548. if (s->pcm->card != substream->pcm->card)
  1549. continue;
  1550. azx_dev = get_azx_dev(s);
  1551. if (azx_sd_readb(azx_dev, SD_CTL) &
  1552. SD_CTL_DMA_START)
  1553. nwait++;
  1554. }
  1555. if (!nwait)
  1556. break;
  1557. cpu_relax();
  1558. }
  1559. }
  1560. if (nsync > 1) {
  1561. spin_lock(&chip->reg_lock);
  1562. /* reset SYNC bits */
  1563. azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
  1564. spin_unlock(&chip->reg_lock);
  1565. }
  1566. return 0;
  1567. }
  1568. /* get the current DMA position with correction on VIA chips */
  1569. static unsigned int azx_via_get_position(struct azx *chip,
  1570. struct azx_dev *azx_dev)
  1571. {
  1572. unsigned int link_pos, mini_pos, bound_pos;
  1573. unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
  1574. unsigned int fifo_size;
  1575. link_pos = azx_sd_readl(azx_dev, SD_LPIB);
  1576. if (azx_dev->index >= 4) {
  1577. /* Playback, no problem using link position */
  1578. return link_pos;
  1579. }
  1580. /* Capture */
  1581. /* For new chipset,
  1582. * use mod to get the DMA position just like old chipset
  1583. */
  1584. mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
  1585. mod_dma_pos %= azx_dev->period_bytes;
  1586. /* azx_dev->fifo_size can't get FIFO size of in stream.
  1587. * Get from base address + offset.
  1588. */
  1589. fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
  1590. if (azx_dev->insufficient) {
  1591. /* Link position never gather than FIFO size */
  1592. if (link_pos <= fifo_size)
  1593. return 0;
  1594. azx_dev->insufficient = 0;
  1595. }
  1596. if (link_pos <= fifo_size)
  1597. mini_pos = azx_dev->bufsize + link_pos - fifo_size;
  1598. else
  1599. mini_pos = link_pos - fifo_size;
  1600. /* Find nearest previous boudary */
  1601. mod_mini_pos = mini_pos % azx_dev->period_bytes;
  1602. mod_link_pos = link_pos % azx_dev->period_bytes;
  1603. if (mod_link_pos >= fifo_size)
  1604. bound_pos = link_pos - mod_link_pos;
  1605. else if (mod_dma_pos >= mod_mini_pos)
  1606. bound_pos = mini_pos - mod_mini_pos;
  1607. else {
  1608. bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
  1609. if (bound_pos >= azx_dev->bufsize)
  1610. bound_pos = 0;
  1611. }
  1612. /* Calculate real DMA position we want */
  1613. return bound_pos + mod_dma_pos;
  1614. }
  1615. static unsigned int azx_get_position(struct azx *chip,
  1616. struct azx_dev *azx_dev)
  1617. {
  1618. unsigned int pos;
  1619. if (chip->via_dmapos_patch)
  1620. pos = azx_via_get_position(chip, azx_dev);
  1621. else {
  1622. int stream = azx_dev->substream->stream;
  1623. if (chip->position_fix[stream] == POS_FIX_POSBUF ||
  1624. chip->position_fix[stream] == POS_FIX_AUTO) {
  1625. /* use the position buffer */
  1626. pos = le32_to_cpu(*azx_dev->posbuf);
  1627. } else {
  1628. /* read LPIB */
  1629. pos = azx_sd_readl(azx_dev, SD_LPIB);
  1630. }
  1631. }
  1632. if (pos >= azx_dev->bufsize)
  1633. pos = 0;
  1634. return pos;
  1635. }
  1636. static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
  1637. {
  1638. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1639. struct azx *chip = apcm->chip;
  1640. struct azx_dev *azx_dev = get_azx_dev(substream);
  1641. return bytes_to_frames(substream->runtime,
  1642. azx_get_position(chip, azx_dev));
  1643. }
  1644. /*
  1645. * Check whether the current DMA position is acceptable for updating
  1646. * periods. Returns non-zero if it's OK.
  1647. *
  1648. * Many HD-audio controllers appear pretty inaccurate about
  1649. * the update-IRQ timing. The IRQ is issued before actually the
  1650. * data is processed. So, we need to process it afterwords in a
  1651. * workqueue.
  1652. */
  1653. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  1654. {
  1655. u32 wallclk;
  1656. unsigned int pos;
  1657. int stream;
  1658. wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
  1659. if (wallclk < (azx_dev->period_wallclk * 2) / 3)
  1660. return -1; /* bogus (too early) interrupt */
  1661. stream = azx_dev->substream->stream;
  1662. pos = azx_get_position(chip, azx_dev);
  1663. if (chip->position_fix[stream] == POS_FIX_AUTO) {
  1664. if (!pos) {
  1665. printk(KERN_WARNING
  1666. "hda-intel: Invalid position buffer, "
  1667. "using LPIB read method instead.\n");
  1668. chip->position_fix[stream] = POS_FIX_LPIB;
  1669. pos = azx_get_position(chip, azx_dev);
  1670. } else
  1671. chip->position_fix[stream] = POS_FIX_POSBUF;
  1672. }
  1673. if (WARN_ONCE(!azx_dev->period_bytes,
  1674. "hda-intel: zero azx_dev->period_bytes"))
  1675. return -1; /* this shouldn't happen! */
  1676. if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
  1677. pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
  1678. /* NG - it's below the first next period boundary */
  1679. return bdl_pos_adj[chip->dev_index] ? 0 : -1;
  1680. azx_dev->start_wallclk += wallclk;
  1681. return 1; /* OK, it's fine */
  1682. }
  1683. /*
  1684. * The work for pending PCM period updates.
  1685. */
  1686. static void azx_irq_pending_work(struct work_struct *work)
  1687. {
  1688. struct azx *chip = container_of(work, struct azx, irq_pending_work);
  1689. int i, pending, ok;
  1690. if (!chip->irq_pending_warned) {
  1691. printk(KERN_WARNING
  1692. "hda-intel: IRQ timing workaround is activated "
  1693. "for card #%d. Suggest a bigger bdl_pos_adj.\n",
  1694. chip->card->number);
  1695. chip->irq_pending_warned = 1;
  1696. }
  1697. for (;;) {
  1698. pending = 0;
  1699. spin_lock_irq(&chip->reg_lock);
  1700. for (i = 0; i < chip->num_streams; i++) {
  1701. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1702. if (!azx_dev->irq_pending ||
  1703. !azx_dev->substream ||
  1704. !azx_dev->running)
  1705. continue;
  1706. ok = azx_position_ok(chip, azx_dev);
  1707. if (ok > 0) {
  1708. azx_dev->irq_pending = 0;
  1709. spin_unlock(&chip->reg_lock);
  1710. snd_pcm_period_elapsed(azx_dev->substream);
  1711. spin_lock(&chip->reg_lock);
  1712. } else if (ok < 0) {
  1713. pending = 0; /* too early */
  1714. } else
  1715. pending++;
  1716. }
  1717. spin_unlock_irq(&chip->reg_lock);
  1718. if (!pending)
  1719. return;
  1720. msleep(1);
  1721. }
  1722. }
  1723. /* clear irq_pending flags and assure no on-going workq */
  1724. static void azx_clear_irq_pending(struct azx *chip)
  1725. {
  1726. int i;
  1727. spin_lock_irq(&chip->reg_lock);
  1728. for (i = 0; i < chip->num_streams; i++)
  1729. chip->azx_dev[i].irq_pending = 0;
  1730. spin_unlock_irq(&chip->reg_lock);
  1731. }
  1732. static struct snd_pcm_ops azx_pcm_ops = {
  1733. .open = azx_pcm_open,
  1734. .close = azx_pcm_close,
  1735. .ioctl = snd_pcm_lib_ioctl,
  1736. .hw_params = azx_pcm_hw_params,
  1737. .hw_free = azx_pcm_hw_free,
  1738. .prepare = azx_pcm_prepare,
  1739. .trigger = azx_pcm_trigger,
  1740. .pointer = azx_pcm_pointer,
  1741. .page = snd_pcm_sgbuf_ops_page,
  1742. };
  1743. static void azx_pcm_free(struct snd_pcm *pcm)
  1744. {
  1745. struct azx_pcm *apcm = pcm->private_data;
  1746. if (apcm) {
  1747. apcm->chip->pcm[pcm->device] = NULL;
  1748. kfree(apcm);
  1749. }
  1750. }
  1751. static int
  1752. azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1753. struct hda_pcm *cpcm)
  1754. {
  1755. struct azx *chip = bus->private_data;
  1756. struct snd_pcm *pcm;
  1757. struct azx_pcm *apcm;
  1758. int pcm_dev = cpcm->device;
  1759. int s, err;
  1760. if (pcm_dev >= HDA_MAX_PCMS) {
  1761. snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
  1762. pcm_dev);
  1763. return -EINVAL;
  1764. }
  1765. if (chip->pcm[pcm_dev]) {
  1766. snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
  1767. return -EBUSY;
  1768. }
  1769. err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
  1770. cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
  1771. cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
  1772. &pcm);
  1773. if (err < 0)
  1774. return err;
  1775. strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
  1776. apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
  1777. if (apcm == NULL)
  1778. return -ENOMEM;
  1779. apcm->chip = chip;
  1780. apcm->codec = codec;
  1781. pcm->private_data = apcm;
  1782. pcm->private_free = azx_pcm_free;
  1783. if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
  1784. pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
  1785. chip->pcm[pcm_dev] = pcm;
  1786. cpcm->pcm = pcm;
  1787. for (s = 0; s < 2; s++) {
  1788. apcm->hinfo[s] = &cpcm->stream[s];
  1789. if (cpcm->stream[s].substreams)
  1790. snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
  1791. }
  1792. /* buffer pre-allocation */
  1793. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  1794. snd_dma_pci_data(chip->pci),
  1795. 1024 * 64, 32 * 1024 * 1024);
  1796. return 0;
  1797. }
  1798. /*
  1799. * mixer creation - all stuff is implemented in hda module
  1800. */
  1801. static int __devinit azx_mixer_create(struct azx *chip)
  1802. {
  1803. return snd_hda_build_controls(chip->bus);
  1804. }
  1805. /*
  1806. * initialize SD streams
  1807. */
  1808. static int __devinit azx_init_stream(struct azx *chip)
  1809. {
  1810. int i;
  1811. /* initialize each stream (aka device)
  1812. * assign the starting bdl address to each stream (device)
  1813. * and initialize
  1814. */
  1815. for (i = 0; i < chip->num_streams; i++) {
  1816. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1817. azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
  1818. /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  1819. azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
  1820. /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
  1821. azx_dev->sd_int_sta_mask = 1 << i;
  1822. /* stream tag: must be non-zero and unique */
  1823. azx_dev->index = i;
  1824. azx_dev->stream_tag = i + 1;
  1825. }
  1826. return 0;
  1827. }
  1828. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  1829. {
  1830. if (request_irq(chip->pci->irq, azx_interrupt,
  1831. chip->msi ? 0 : IRQF_SHARED,
  1832. "hda_intel", chip)) {
  1833. printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
  1834. "disabling device\n", chip->pci->irq);
  1835. if (do_disconnect)
  1836. snd_card_disconnect(chip->card);
  1837. return -1;
  1838. }
  1839. chip->irq = chip->pci->irq;
  1840. pci_intx(chip->pci, !chip->msi);
  1841. return 0;
  1842. }
  1843. static void azx_stop_chip(struct azx *chip)
  1844. {
  1845. if (!chip->initialized)
  1846. return;
  1847. /* disable interrupts */
  1848. azx_int_disable(chip);
  1849. azx_int_clear(chip);
  1850. /* disable CORB/RIRB */
  1851. azx_free_cmd_io(chip);
  1852. /* disable position buffer */
  1853. azx_writel(chip, DPLBASE, 0);
  1854. azx_writel(chip, DPUBASE, 0);
  1855. chip->initialized = 0;
  1856. }
  1857. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1858. /* power-up/down the controller */
  1859. static void azx_power_notify(struct hda_bus *bus)
  1860. {
  1861. struct azx *chip = bus->private_data;
  1862. struct hda_codec *c;
  1863. int power_on = 0;
  1864. list_for_each_entry(c, &bus->codec_list, list) {
  1865. if (c->power_on) {
  1866. power_on = 1;
  1867. break;
  1868. }
  1869. }
  1870. if (power_on)
  1871. azx_init_chip(chip, 1);
  1872. else if (chip->running && power_save_controller &&
  1873. !bus->power_keep_link_on)
  1874. azx_stop_chip(chip);
  1875. }
  1876. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  1877. #ifdef CONFIG_PM
  1878. /*
  1879. * power management
  1880. */
  1881. static int snd_hda_codecs_inuse(struct hda_bus *bus)
  1882. {
  1883. struct hda_codec *codec;
  1884. list_for_each_entry(codec, &bus->codec_list, list) {
  1885. if (snd_hda_codec_needs_resume(codec))
  1886. return 1;
  1887. }
  1888. return 0;
  1889. }
  1890. static int azx_suspend(struct pci_dev *pci, pm_message_t state)
  1891. {
  1892. struct snd_card *card = pci_get_drvdata(pci);
  1893. struct azx *chip = card->private_data;
  1894. int i;
  1895. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1896. azx_clear_irq_pending(chip);
  1897. for (i = 0; i < HDA_MAX_PCMS; i++)
  1898. snd_pcm_suspend_all(chip->pcm[i]);
  1899. if (chip->initialized)
  1900. snd_hda_suspend(chip->bus);
  1901. azx_stop_chip(chip);
  1902. if (chip->irq >= 0) {
  1903. free_irq(chip->irq, chip);
  1904. chip->irq = -1;
  1905. }
  1906. if (chip->msi)
  1907. pci_disable_msi(chip->pci);
  1908. pci_disable_device(pci);
  1909. pci_save_state(pci);
  1910. pci_set_power_state(pci, pci_choose_state(pci, state));
  1911. return 0;
  1912. }
  1913. static int azx_resume(struct pci_dev *pci)
  1914. {
  1915. struct snd_card *card = pci_get_drvdata(pci);
  1916. struct azx *chip = card->private_data;
  1917. pci_set_power_state(pci, PCI_D0);
  1918. pci_restore_state(pci);
  1919. if (pci_enable_device(pci) < 0) {
  1920. printk(KERN_ERR "hda-intel: pci_enable_device failed, "
  1921. "disabling device\n");
  1922. snd_card_disconnect(card);
  1923. return -EIO;
  1924. }
  1925. pci_set_master(pci);
  1926. if (chip->msi)
  1927. if (pci_enable_msi(pci) < 0)
  1928. chip->msi = 0;
  1929. if (azx_acquire_irq(chip, 1) < 0)
  1930. return -EIO;
  1931. azx_init_pci(chip);
  1932. if (snd_hda_codecs_inuse(chip->bus))
  1933. azx_init_chip(chip, 1);
  1934. snd_hda_resume(chip->bus);
  1935. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1936. return 0;
  1937. }
  1938. #endif /* CONFIG_PM */
  1939. /*
  1940. * reboot notifier for hang-up problem at power-down
  1941. */
  1942. static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
  1943. {
  1944. struct azx *chip = container_of(nb, struct azx, reboot_notifier);
  1945. snd_hda_bus_reboot_notify(chip->bus);
  1946. azx_stop_chip(chip);
  1947. return NOTIFY_OK;
  1948. }
  1949. static void azx_notifier_register(struct azx *chip)
  1950. {
  1951. chip->reboot_notifier.notifier_call = azx_halt;
  1952. register_reboot_notifier(&chip->reboot_notifier);
  1953. }
  1954. static void azx_notifier_unregister(struct azx *chip)
  1955. {
  1956. if (chip->reboot_notifier.notifier_call)
  1957. unregister_reboot_notifier(&chip->reboot_notifier);
  1958. }
  1959. /*
  1960. * destructor
  1961. */
  1962. static int azx_free(struct azx *chip)
  1963. {
  1964. int i;
  1965. azx_notifier_unregister(chip);
  1966. if (chip->initialized) {
  1967. azx_clear_irq_pending(chip);
  1968. for (i = 0; i < chip->num_streams; i++)
  1969. azx_stream_stop(chip, &chip->azx_dev[i]);
  1970. azx_stop_chip(chip);
  1971. }
  1972. if (chip->irq >= 0)
  1973. free_irq(chip->irq, (void*)chip);
  1974. if (chip->msi)
  1975. pci_disable_msi(chip->pci);
  1976. if (chip->remap_addr)
  1977. iounmap(chip->remap_addr);
  1978. if (chip->azx_dev) {
  1979. for (i = 0; i < chip->num_streams; i++)
  1980. if (chip->azx_dev[i].bdl.area)
  1981. snd_dma_free_pages(&chip->azx_dev[i].bdl);
  1982. }
  1983. if (chip->rb.area)
  1984. snd_dma_free_pages(&chip->rb);
  1985. if (chip->posbuf.area)
  1986. snd_dma_free_pages(&chip->posbuf);
  1987. pci_release_regions(chip->pci);
  1988. pci_disable_device(chip->pci);
  1989. kfree(chip->azx_dev);
  1990. kfree(chip);
  1991. return 0;
  1992. }
  1993. static int azx_dev_free(struct snd_device *device)
  1994. {
  1995. return azx_free(device->device_data);
  1996. }
  1997. /*
  1998. * white/black-listing for position_fix
  1999. */
  2000. static struct snd_pci_quirk position_fix_list[] __devinitdata = {
  2001. SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
  2002. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  2003. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  2004. SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
  2005. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  2006. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  2007. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  2008. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  2009. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  2010. SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
  2011. SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),
  2012. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  2013. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  2014. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  2015. SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
  2016. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  2017. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  2018. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  2019. SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
  2020. {}
  2021. };
  2022. static int __devinit check_position_fix(struct azx *chip, int fix)
  2023. {
  2024. const struct snd_pci_quirk *q;
  2025. switch (fix) {
  2026. case POS_FIX_LPIB:
  2027. case POS_FIX_POSBUF:
  2028. return fix;
  2029. }
  2030. /* Check VIA/ATI HD Audio Controller exist */
  2031. switch (chip->driver_type) {
  2032. case AZX_DRIVER_VIA:
  2033. case AZX_DRIVER_ATI:
  2034. chip->via_dmapos_patch = 1;
  2035. /* Use link position directly, avoid any transfer problem. */
  2036. return POS_FIX_LPIB;
  2037. }
  2038. chip->via_dmapos_patch = 0;
  2039. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  2040. if (q) {
  2041. printk(KERN_INFO
  2042. "hda_intel: position_fix set to %d "
  2043. "for device %04x:%04x\n",
  2044. q->value, q->subvendor, q->subdevice);
  2045. return q->value;
  2046. }
  2047. return POS_FIX_AUTO;
  2048. }
  2049. /*
  2050. * black-lists for probe_mask
  2051. */
  2052. static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
  2053. /* Thinkpad often breaks the controller communication when accessing
  2054. * to the non-working (or non-existing) modem codec slot.
  2055. */
  2056. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  2057. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  2058. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  2059. /* broken BIOS */
  2060. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  2061. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  2062. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  2063. /* forced codec slots */
  2064. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  2065. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  2066. {}
  2067. };
  2068. #define AZX_FORCE_CODEC_MASK 0x100
  2069. static void __devinit check_probe_mask(struct azx *chip, int dev)
  2070. {
  2071. const struct snd_pci_quirk *q;
  2072. chip->codec_probe_mask = probe_mask[dev];
  2073. if (chip->codec_probe_mask == -1) {
  2074. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  2075. if (q) {
  2076. printk(KERN_INFO
  2077. "hda_intel: probe_mask set to 0x%x "
  2078. "for device %04x:%04x\n",
  2079. q->value, q->subvendor, q->subdevice);
  2080. chip->codec_probe_mask = q->value;
  2081. }
  2082. }
  2083. /* check forced option */
  2084. if (chip->codec_probe_mask != -1 &&
  2085. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  2086. chip->codec_mask = chip->codec_probe_mask & 0xff;
  2087. printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
  2088. chip->codec_mask);
  2089. }
  2090. }
  2091. /*
  2092. * white/black-list for enable_msi
  2093. */
  2094. static struct snd_pci_quirk msi_black_list[] __devinitdata = {
  2095. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  2096. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  2097. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  2098. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  2099. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  2100. {}
  2101. };
  2102. static void __devinit check_msi(struct azx *chip)
  2103. {
  2104. const struct snd_pci_quirk *q;
  2105. if (enable_msi >= 0) {
  2106. chip->msi = !!enable_msi;
  2107. return;
  2108. }
  2109. chip->msi = 1; /* enable MSI as default */
  2110. q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
  2111. if (q) {
  2112. printk(KERN_INFO
  2113. "hda_intel: msi for device %04x:%04x set to %d\n",
  2114. q->subvendor, q->subdevice, q->value);
  2115. chip->msi = q->value;
  2116. return;
  2117. }
  2118. /* NVidia chipsets seem to cause troubles with MSI */
  2119. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  2120. printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
  2121. chip->msi = 0;
  2122. }
  2123. }
  2124. /*
  2125. * constructor
  2126. */
  2127. static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
  2128. int dev, int driver_type,
  2129. struct azx **rchip)
  2130. {
  2131. struct azx *chip;
  2132. int i, err;
  2133. unsigned short gcap;
  2134. static struct snd_device_ops ops = {
  2135. .dev_free = azx_dev_free,
  2136. };
  2137. *rchip = NULL;
  2138. err = pci_enable_device(pci);
  2139. if (err < 0)
  2140. return err;
  2141. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2142. if (!chip) {
  2143. snd_printk(KERN_ERR SFX "cannot allocate chip\n");
  2144. pci_disable_device(pci);
  2145. return -ENOMEM;
  2146. }
  2147. spin_lock_init(&chip->reg_lock);
  2148. mutex_init(&chip->open_mutex);
  2149. chip->card = card;
  2150. chip->pci = pci;
  2151. chip->irq = -1;
  2152. chip->driver_type = driver_type;
  2153. check_msi(chip);
  2154. chip->dev_index = dev;
  2155. INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
  2156. chip->position_fix[0] = chip->position_fix[1] =
  2157. check_position_fix(chip, position_fix[dev]);
  2158. check_probe_mask(chip, dev);
  2159. chip->single_cmd = single_cmd;
  2160. if (bdl_pos_adj[dev] < 0) {
  2161. switch (chip->driver_type) {
  2162. case AZX_DRIVER_ICH:
  2163. case AZX_DRIVER_PCH:
  2164. bdl_pos_adj[dev] = 1;
  2165. break;
  2166. default:
  2167. bdl_pos_adj[dev] = 32;
  2168. break;
  2169. }
  2170. }
  2171. #if BITS_PER_LONG != 64
  2172. /* Fix up base address on ULI M5461 */
  2173. if (chip->driver_type == AZX_DRIVER_ULI) {
  2174. u16 tmp3;
  2175. pci_read_config_word(pci, 0x40, &tmp3);
  2176. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  2177. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  2178. }
  2179. #endif
  2180. err = pci_request_regions(pci, "ICH HD audio");
  2181. if (err < 0) {
  2182. kfree(chip);
  2183. pci_disable_device(pci);
  2184. return err;
  2185. }
  2186. chip->addr = pci_resource_start(pci, 0);
  2187. chip->remap_addr = pci_ioremap_bar(pci, 0);
  2188. if (chip->remap_addr == NULL) {
  2189. snd_printk(KERN_ERR SFX "ioremap error\n");
  2190. err = -ENXIO;
  2191. goto errout;
  2192. }
  2193. if (chip->msi)
  2194. if (pci_enable_msi(pci) < 0)
  2195. chip->msi = 0;
  2196. if (azx_acquire_irq(chip, 0) < 0) {
  2197. err = -EBUSY;
  2198. goto errout;
  2199. }
  2200. pci_set_master(pci);
  2201. synchronize_irq(chip->irq);
  2202. gcap = azx_readw(chip, GCAP);
  2203. snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
  2204. /* disable SB600 64bit support for safety */
  2205. if ((chip->driver_type == AZX_DRIVER_ATI) ||
  2206. (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
  2207. struct pci_dev *p_smbus;
  2208. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  2209. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  2210. NULL);
  2211. if (p_smbus) {
  2212. if (p_smbus->revision < 0x30)
  2213. gcap &= ~ICH6_GCAP_64OK;
  2214. pci_dev_put(p_smbus);
  2215. }
  2216. }
  2217. /* disable 64bit DMA address for Teradici */
  2218. /* it does not work with device 6549:1200 subsys e4a2:040b */
  2219. if (chip->driver_type == AZX_DRIVER_TERA)
  2220. gcap &= ~ICH6_GCAP_64OK;
  2221. /* allow 64bit DMA address if supported by H/W */
  2222. if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
  2223. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
  2224. else {
  2225. pci_set_dma_mask(pci, DMA_BIT_MASK(32));
  2226. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
  2227. }
  2228. /* read number of streams from GCAP register instead of using
  2229. * hardcoded value
  2230. */
  2231. chip->capture_streams = (gcap >> 8) & 0x0f;
  2232. chip->playback_streams = (gcap >> 12) & 0x0f;
  2233. if (!chip->playback_streams && !chip->capture_streams) {
  2234. /* gcap didn't give any info, switching to old method */
  2235. switch (chip->driver_type) {
  2236. case AZX_DRIVER_ULI:
  2237. chip->playback_streams = ULI_NUM_PLAYBACK;
  2238. chip->capture_streams = ULI_NUM_CAPTURE;
  2239. break;
  2240. case AZX_DRIVER_ATIHDMI:
  2241. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  2242. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  2243. break;
  2244. case AZX_DRIVER_GENERIC:
  2245. default:
  2246. chip->playback_streams = ICH6_NUM_PLAYBACK;
  2247. chip->capture_streams = ICH6_NUM_CAPTURE;
  2248. break;
  2249. }
  2250. }
  2251. chip->capture_index_offset = 0;
  2252. chip->playback_index_offset = chip->capture_streams;
  2253. chip->num_streams = chip->playback_streams + chip->capture_streams;
  2254. chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
  2255. GFP_KERNEL);
  2256. if (!chip->azx_dev) {
  2257. snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");
  2258. goto errout;
  2259. }
  2260. for (i = 0; i < chip->num_streams; i++) {
  2261. /* allocate memory for the BDL for each stream */
  2262. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2263. snd_dma_pci_data(chip->pci),
  2264. BDL_SIZE, &chip->azx_dev[i].bdl);
  2265. if (err < 0) {
  2266. snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
  2267. goto errout;
  2268. }
  2269. }
  2270. /* allocate memory for the position buffer */
  2271. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2272. snd_dma_pci_data(chip->pci),
  2273. chip->num_streams * 8, &chip->posbuf);
  2274. if (err < 0) {
  2275. snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
  2276. goto errout;
  2277. }
  2278. /* allocate CORB/RIRB */
  2279. err = azx_alloc_cmd_io(chip);
  2280. if (err < 0)
  2281. goto errout;
  2282. /* initialize streams */
  2283. azx_init_stream(chip);
  2284. /* initialize chip */
  2285. azx_init_pci(chip);
  2286. azx_init_chip(chip, (probe_only[dev] & 2) == 0);
  2287. /* codec detection */
  2288. if (!chip->codec_mask) {
  2289. snd_printk(KERN_ERR SFX "no codecs found!\n");
  2290. err = -ENODEV;
  2291. goto errout;
  2292. }
  2293. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  2294. if (err <0) {
  2295. snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
  2296. goto errout;
  2297. }
  2298. strcpy(card->driver, "HDA-Intel");
  2299. strlcpy(card->shortname, driver_short_names[chip->driver_type],
  2300. sizeof(card->shortname));
  2301. snprintf(card->longname, sizeof(card->longname),
  2302. "%s at 0x%lx irq %i",
  2303. card->shortname, chip->addr, chip->irq);
  2304. *rchip = chip;
  2305. return 0;
  2306. errout:
  2307. azx_free(chip);
  2308. return err;
  2309. }
  2310. static void power_down_all_codecs(struct azx *chip)
  2311. {
  2312. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2313. /* The codecs were powered up in snd_hda_codec_new().
  2314. * Now all initialization done, so turn them down if possible
  2315. */
  2316. struct hda_codec *codec;
  2317. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  2318. snd_hda_power_down(codec);
  2319. }
  2320. #endif
  2321. }
  2322. static int __devinit azx_probe(struct pci_dev *pci,
  2323. const struct pci_device_id *pci_id)
  2324. {
  2325. static int dev;
  2326. struct snd_card *card;
  2327. struct azx *chip;
  2328. int err;
  2329. if (dev >= SNDRV_CARDS)
  2330. return -ENODEV;
  2331. if (!enable[dev]) {
  2332. dev++;
  2333. return -ENOENT;
  2334. }
  2335. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  2336. if (err < 0) {
  2337. snd_printk(KERN_ERR SFX "Error creating card!\n");
  2338. return err;
  2339. }
  2340. /* set this here since it's referred in snd_hda_load_patch() */
  2341. snd_card_set_dev(card, &pci->dev);
  2342. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  2343. if (err < 0)
  2344. goto out_free;
  2345. card->private_data = chip;
  2346. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2347. chip->beep_mode = beep_mode[dev];
  2348. #endif
  2349. /* create codec instances */
  2350. err = azx_codec_create(chip, model[dev]);
  2351. if (err < 0)
  2352. goto out_free;
  2353. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  2354. if (patch[dev]) {
  2355. snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
  2356. patch[dev]);
  2357. err = snd_hda_load_patch(chip->bus, patch[dev]);
  2358. if (err < 0)
  2359. goto out_free;
  2360. }
  2361. #endif
  2362. if ((probe_only[dev] & 1) == 0) {
  2363. err = azx_codec_configure(chip);
  2364. if (err < 0)
  2365. goto out_free;
  2366. }
  2367. /* create PCM streams */
  2368. err = snd_hda_build_pcms(chip->bus);
  2369. if (err < 0)
  2370. goto out_free;
  2371. /* create mixer controls */
  2372. err = azx_mixer_create(chip);
  2373. if (err < 0)
  2374. goto out_free;
  2375. err = snd_card_register(card);
  2376. if (err < 0)
  2377. goto out_free;
  2378. pci_set_drvdata(pci, card);
  2379. chip->running = 1;
  2380. power_down_all_codecs(chip);
  2381. azx_notifier_register(chip);
  2382. dev++;
  2383. return err;
  2384. out_free:
  2385. snd_card_free(card);
  2386. return err;
  2387. }
  2388. static void __devexit azx_remove(struct pci_dev *pci)
  2389. {
  2390. snd_card_free(pci_get_drvdata(pci));
  2391. pci_set_drvdata(pci, NULL);
  2392. }
  2393. /* PCI IDs */
  2394. static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
  2395. /* ICH 6..10 */
  2396. { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
  2397. { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
  2398. { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
  2399. { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
  2400. { PCI_DEVICE(0x8086, 0x2911), .driver_data = AZX_DRIVER_ICH },
  2401. { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
  2402. { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
  2403. { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
  2404. { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
  2405. /* PCH */
  2406. { PCI_DEVICE(0x8086, 0x3b56), .driver_data = AZX_DRIVER_ICH },
  2407. { PCI_DEVICE(0x8086, 0x3b57), .driver_data = AZX_DRIVER_ICH },
  2408. /* CPT */
  2409. { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
  2410. /* PBG */
  2411. { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH },
  2412. /* SCH */
  2413. { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
  2414. /* ATI SB 450/600 */
  2415. { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
  2416. { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
  2417. /* ATI HDMI */
  2418. { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
  2419. { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
  2420. { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
  2421. { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI },
  2422. { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
  2423. { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
  2424. { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
  2425. { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
  2426. { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
  2427. { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
  2428. { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
  2429. { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
  2430. { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
  2431. { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
  2432. /* VIA VT8251/VT8237A */
  2433. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2434. /* SIS966 */
  2435. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2436. /* ULI M5461 */
  2437. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2438. /* NVIDIA MCP */
  2439. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2440. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2441. .class_mask = 0xffffff,
  2442. .driver_data = AZX_DRIVER_NVIDIA },
  2443. /* Teradici */
  2444. { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
  2445. /* Creative X-Fi (CA0110-IBG) */
  2446. #if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE)
  2447. /* the following entry conflicts with snd-ctxfi driver,
  2448. * as ctxfi driver mutates from HD-audio to native mode with
  2449. * a special command sequence.
  2450. */
  2451. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2452. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2453. .class_mask = 0xffffff,
  2454. .driver_data = AZX_DRIVER_GENERIC },
  2455. #else
  2456. /* this entry seems still valid -- i.e. without emu20kx chip */
  2457. { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_GENERIC },
  2458. #endif
  2459. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2460. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2461. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2462. .class_mask = 0xffffff,
  2463. .driver_data = AZX_DRIVER_GENERIC },
  2464. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2465. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2466. .class_mask = 0xffffff,
  2467. .driver_data = AZX_DRIVER_GENERIC },
  2468. { 0, }
  2469. };
  2470. MODULE_DEVICE_TABLE(pci, azx_ids);
  2471. /* pci_driver definition */
  2472. static struct pci_driver driver = {
  2473. .name = "HDA Intel",
  2474. .id_table = azx_ids,
  2475. .probe = azx_probe,
  2476. .remove = __devexit_p(azx_remove),
  2477. #ifdef CONFIG_PM
  2478. .suspend = azx_suspend,
  2479. .resume = azx_resume,
  2480. #endif
  2481. };
  2482. static int __init alsa_card_azx_init(void)
  2483. {
  2484. return pci_register_driver(&driver);
  2485. }
  2486. static void __exit alsa_card_azx_exit(void)
  2487. {
  2488. pci_unregister_driver(&driver);
  2489. }
  2490. module_init(alsa_card_azx_init)
  2491. module_exit(alsa_card_azx_exit)