hda_intel.c 73 KB

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