hda_intel.c 74 KB

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