hda_intel.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  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 <linux/delay.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/kernel.h>
  39. #include <linux/module.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/moduleparam.h>
  42. #include <linux/init.h>
  43. #include <linux/slab.h>
  44. #include <linux/pci.h>
  45. #include <linux/mutex.h>
  46. #include <linux/io.h>
  47. #include <linux/pm_runtime.h>
  48. #include <linux/clocksource.h>
  49. #include <linux/time.h>
  50. #include <linux/completion.h>
  51. #ifdef CONFIG_X86
  52. /* for snoop control */
  53. #include <asm/pgtable.h>
  54. #include <asm/set_memory.h>
  55. #include <asm/cpufeature.h>
  56. #endif
  57. #include <sound/core.h>
  58. #include <sound/initval.h>
  59. #include <sound/hdaudio.h>
  60. #include <sound/hda_i915.h>
  61. #include <linux/vgaarb.h>
  62. #include <linux/vga_switcheroo.h>
  63. #include <linux/firmware.h>
  64. #include "hda_codec.h"
  65. #include "hda_controller.h"
  66. #include "hda_intel.h"
  67. #define CREATE_TRACE_POINTS
  68. #include "hda_intel_trace.h"
  69. /* position fix mode */
  70. enum {
  71. POS_FIX_AUTO,
  72. POS_FIX_LPIB,
  73. POS_FIX_POSBUF,
  74. POS_FIX_VIACOMBO,
  75. POS_FIX_COMBO,
  76. POS_FIX_SKL,
  77. };
  78. /* Defines for ATI HD Audio support in SB450 south bridge */
  79. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  80. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  81. /* Defines for Nvidia HDA support */
  82. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  83. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  84. #define NVIDIA_HDA_ISTRM_COH 0x4d
  85. #define NVIDIA_HDA_OSTRM_COH 0x4c
  86. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  87. /* Defines for Intel SCH HDA snoop control */
  88. #define INTEL_HDA_CGCTL 0x48
  89. #define INTEL_HDA_CGCTL_MISCBDCGE (0x1 << 6)
  90. #define INTEL_SCH_HDA_DEVC 0x78
  91. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  92. /* Define IN stream 0 FIFO size offset in VIA controller */
  93. #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
  94. /* Define VIA HD Audio Device ID*/
  95. #define VIA_HDAC_DEVICE_ID 0x3288
  96. /* max number of SDs */
  97. /* ICH, ATI and VIA have 4 playback and 4 capture */
  98. #define ICH6_NUM_CAPTURE 4
  99. #define ICH6_NUM_PLAYBACK 4
  100. /* ULI has 6 playback and 5 capture */
  101. #define ULI_NUM_CAPTURE 5
  102. #define ULI_NUM_PLAYBACK 6
  103. /* ATI HDMI may have up to 8 playbacks and 0 capture */
  104. #define ATIHDMI_NUM_CAPTURE 0
  105. #define ATIHDMI_NUM_PLAYBACK 8
  106. /* TERA has 4 playback and 3 capture */
  107. #define TERA_NUM_CAPTURE 3
  108. #define TERA_NUM_PLAYBACK 4
  109. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  110. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  111. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  112. static char *model[SNDRV_CARDS];
  113. static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  114. static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  115. static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  116. static int probe_only[SNDRV_CARDS];
  117. static int jackpoll_ms[SNDRV_CARDS];
  118. static int single_cmd = -1;
  119. static int enable_msi = -1;
  120. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  121. static char *patch[SNDRV_CARDS];
  122. #endif
  123. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  124. static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
  125. CONFIG_SND_HDA_INPUT_BEEP_MODE};
  126. #endif
  127. module_param_array(index, int, NULL, 0444);
  128. MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
  129. module_param_array(id, charp, NULL, 0444);
  130. MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
  131. module_param_array(enable, bool, NULL, 0444);
  132. MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
  133. module_param_array(model, charp, NULL, 0444);
  134. MODULE_PARM_DESC(model, "Use the given board model.");
  135. module_param_array(position_fix, int, NULL, 0444);
  136. MODULE_PARM_DESC(position_fix, "DMA pointer read method."
  137. "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO, 5 = SKL+).");
  138. module_param_array(bdl_pos_adj, int, NULL, 0644);
  139. MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
  140. module_param_array(probe_mask, int, NULL, 0444);
  141. MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
  142. module_param_array(probe_only, int, NULL, 0444);
  143. MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
  144. module_param_array(jackpoll_ms, int, NULL, 0444);
  145. MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)");
  146. module_param(single_cmd, bint, 0444);
  147. MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
  148. "(for debugging only).");
  149. module_param(enable_msi, bint, 0444);
  150. MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
  151. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  152. module_param_array(patch, charp, NULL, 0444);
  153. MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
  154. #endif
  155. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  156. module_param_array(beep_mode, bool, NULL, 0444);
  157. MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
  158. "(0=off, 1=on) (default=1).");
  159. #endif
  160. #ifdef CONFIG_PM
  161. static int param_set_xint(const char *val, const struct kernel_param *kp);
  162. static const struct kernel_param_ops param_ops_xint = {
  163. .set = param_set_xint,
  164. .get = param_get_int,
  165. };
  166. #define param_check_xint param_check_int
  167. static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
  168. module_param(power_save, xint, 0644);
  169. MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
  170. "(in second, 0 = disable).");
  171. /* reset the HD-audio controller in power save mode.
  172. * this may give more power-saving, but will take longer time to
  173. * wake up.
  174. */
  175. static bool power_save_controller = 1;
  176. module_param(power_save_controller, bool, 0644);
  177. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  178. #else
  179. #define power_save 0
  180. #endif /* CONFIG_PM */
  181. static int align_buffer_size = -1;
  182. module_param(align_buffer_size, bint, 0644);
  183. MODULE_PARM_DESC(align_buffer_size,
  184. "Force buffer and period sizes to be multiple of 128 bytes.");
  185. #ifdef CONFIG_X86
  186. static int hda_snoop = -1;
  187. module_param_named(snoop, hda_snoop, bint, 0444);
  188. MODULE_PARM_DESC(snoop, "Enable/disable snooping");
  189. #else
  190. #define hda_snoop true
  191. #endif
  192. MODULE_LICENSE("GPL");
  193. MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
  194. "{Intel, ICH6M},"
  195. "{Intel, ICH7},"
  196. "{Intel, ESB2},"
  197. "{Intel, ICH8},"
  198. "{Intel, ICH9},"
  199. "{Intel, ICH10},"
  200. "{Intel, PCH},"
  201. "{Intel, CPT},"
  202. "{Intel, PPT},"
  203. "{Intel, LPT},"
  204. "{Intel, LPT_LP},"
  205. "{Intel, WPT_LP},"
  206. "{Intel, SPT},"
  207. "{Intel, SPT_LP},"
  208. "{Intel, HPT},"
  209. "{Intel, PBG},"
  210. "{Intel, SCH},"
  211. "{ATI, SB450},"
  212. "{ATI, SB600},"
  213. "{ATI, RS600},"
  214. "{ATI, RS690},"
  215. "{ATI, RS780},"
  216. "{ATI, R600},"
  217. "{ATI, RV630},"
  218. "{ATI, RV610},"
  219. "{ATI, RV670},"
  220. "{ATI, RV635},"
  221. "{ATI, RV620},"
  222. "{ATI, RV770},"
  223. "{VIA, VT8251},"
  224. "{VIA, VT8237A},"
  225. "{SiS, SIS966},"
  226. "{ULI, M5461}}");
  227. MODULE_DESCRIPTION("Intel HDA driver");
  228. #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
  229. #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
  230. #define SUPPORT_VGA_SWITCHEROO
  231. #endif
  232. #endif
  233. /*
  234. */
  235. /* driver types */
  236. enum {
  237. AZX_DRIVER_ICH,
  238. AZX_DRIVER_PCH,
  239. AZX_DRIVER_SCH,
  240. AZX_DRIVER_HDMI,
  241. AZX_DRIVER_ATI,
  242. AZX_DRIVER_ATIHDMI,
  243. AZX_DRIVER_ATIHDMI_NS,
  244. AZX_DRIVER_VIA,
  245. AZX_DRIVER_SIS,
  246. AZX_DRIVER_ULI,
  247. AZX_DRIVER_NVIDIA,
  248. AZX_DRIVER_TERA,
  249. AZX_DRIVER_CTX,
  250. AZX_DRIVER_CTHDA,
  251. AZX_DRIVER_CMEDIA,
  252. AZX_DRIVER_GENERIC,
  253. AZX_NUM_DRIVERS, /* keep this as last entry */
  254. };
  255. #define azx_get_snoop_type(chip) \
  256. (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
  257. #define AZX_DCAPS_SNOOP_TYPE(type) ((AZX_SNOOP_TYPE_ ## type) << 10)
  258. /* quirks for old Intel chipsets */
  259. #define AZX_DCAPS_INTEL_ICH \
  260. (AZX_DCAPS_OLD_SSYNC | AZX_DCAPS_NO_ALIGN_BUFSIZE)
  261. /* quirks for Intel PCH */
  262. #define AZX_DCAPS_INTEL_PCH_BASE \
  263. (AZX_DCAPS_NO_ALIGN_BUFSIZE | AZX_DCAPS_COUNT_LPIB_DELAY |\
  264. AZX_DCAPS_SNOOP_TYPE(SCH))
  265. /* PCH up to IVB; no runtime PM */
  266. #define AZX_DCAPS_INTEL_PCH_NOPM \
  267. (AZX_DCAPS_INTEL_PCH_BASE)
  268. /* PCH for HSW/BDW; with runtime PM */
  269. #define AZX_DCAPS_INTEL_PCH \
  270. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME)
  271. /* HSW HDMI */
  272. #define AZX_DCAPS_INTEL_HASWELL \
  273. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
  274. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
  275. AZX_DCAPS_SNOOP_TYPE(SCH))
  276. /* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
  277. #define AZX_DCAPS_INTEL_BROADWELL \
  278. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
  279. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
  280. AZX_DCAPS_SNOOP_TYPE(SCH))
  281. #define AZX_DCAPS_INTEL_BAYTRAIL \
  282. (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_I915_POWERWELL)
  283. #define AZX_DCAPS_INTEL_BRASWELL \
  284. (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_I915_POWERWELL)
  285. #define AZX_DCAPS_INTEL_SKYLAKE \
  286. (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\
  287. AZX_DCAPS_I915_POWERWELL)
  288. #define AZX_DCAPS_INTEL_BROXTON \
  289. (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\
  290. AZX_DCAPS_I915_POWERWELL)
  291. /* quirks for ATI SB / AMD Hudson */
  292. #define AZX_DCAPS_PRESET_ATI_SB \
  293. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB |\
  294. AZX_DCAPS_SNOOP_TYPE(ATI))
  295. /* quirks for ATI/AMD HDMI */
  296. #define AZX_DCAPS_PRESET_ATI_HDMI \
  297. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\
  298. AZX_DCAPS_NO_MSI64)
  299. /* quirks for ATI HDMI with snoop off */
  300. #define AZX_DCAPS_PRESET_ATI_HDMI_NS \
  301. (AZX_DCAPS_PRESET_ATI_HDMI | AZX_DCAPS_SNOOP_OFF)
  302. /* quirks for Nvidia */
  303. #define AZX_DCAPS_PRESET_NVIDIA \
  304. (AZX_DCAPS_NO_MSI | AZX_DCAPS_CORBRP_SELF_CLEAR |\
  305. AZX_DCAPS_SNOOP_TYPE(NVIDIA))
  306. #define AZX_DCAPS_PRESET_CTHDA \
  307. (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB |\
  308. AZX_DCAPS_NO_64BIT |\
  309. AZX_DCAPS_4K_BDLE_BOUNDARY | AZX_DCAPS_SNOOP_OFF)
  310. /*
  311. * vga_switcheroo support
  312. */
  313. #ifdef SUPPORT_VGA_SWITCHEROO
  314. #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
  315. #else
  316. #define use_vga_switcheroo(chip) 0
  317. #endif
  318. #define CONTROLLER_IN_GPU(pci) (((pci)->device == 0x0a0c) || \
  319. ((pci)->device == 0x0c0c) || \
  320. ((pci)->device == 0x0d0c) || \
  321. ((pci)->device == 0x160c))
  322. #define IS_SKL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa170)
  323. #define IS_SKL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d70)
  324. #define IS_KBL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa171)
  325. #define IS_KBL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d71)
  326. #define IS_KBL_H(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa2f0)
  327. #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
  328. #define IS_BXT_T(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x1a98)
  329. #define IS_GLK(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x3198)
  330. #define IS_CFL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa348)
  331. #define IS_SKL_PLUS(pci) (IS_SKL(pci) || IS_SKL_LP(pci) || IS_BXT(pci) || \
  332. IS_BXT_T(pci) || IS_KBL(pci) || IS_KBL_LP(pci) || \
  333. IS_KBL_H(pci) || IS_GLK(pci) || IS_CFL(pci))
  334. static char *driver_short_names[] = {
  335. [AZX_DRIVER_ICH] = "HDA Intel",
  336. [AZX_DRIVER_PCH] = "HDA Intel PCH",
  337. [AZX_DRIVER_SCH] = "HDA Intel MID",
  338. [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
  339. [AZX_DRIVER_ATI] = "HDA ATI SB",
  340. [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
  341. [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI",
  342. [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
  343. [AZX_DRIVER_SIS] = "HDA SIS966",
  344. [AZX_DRIVER_ULI] = "HDA ULI M5461",
  345. [AZX_DRIVER_NVIDIA] = "HDA NVidia",
  346. [AZX_DRIVER_TERA] = "HDA Teradici",
  347. [AZX_DRIVER_CTX] = "HDA Creative",
  348. [AZX_DRIVER_CTHDA] = "HDA Creative",
  349. [AZX_DRIVER_CMEDIA] = "HDA C-Media",
  350. [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
  351. };
  352. #ifdef CONFIG_X86
  353. static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
  354. {
  355. int pages;
  356. if (azx_snoop(chip))
  357. return;
  358. if (!dmab || !dmab->area || !dmab->bytes)
  359. return;
  360. #ifdef CONFIG_SND_DMA_SGBUF
  361. if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
  362. struct snd_sg_buf *sgbuf = dmab->private_data;
  363. if (chip->driver_type == AZX_DRIVER_CMEDIA)
  364. return; /* deal with only CORB/RIRB buffers */
  365. if (on)
  366. set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
  367. else
  368. set_pages_array_wb(sgbuf->page_table, sgbuf->pages);
  369. return;
  370. }
  371. #endif
  372. pages = (dmab->bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
  373. if (on)
  374. set_memory_wc((unsigned long)dmab->area, pages);
  375. else
  376. set_memory_wb((unsigned long)dmab->area, pages);
  377. }
  378. static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
  379. bool on)
  380. {
  381. __mark_pages_wc(chip, buf, on);
  382. }
  383. static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
  384. struct snd_pcm_substream *substream, bool on)
  385. {
  386. if (azx_dev->wc_marked != on) {
  387. __mark_pages_wc(chip, snd_pcm_get_dma_buf(substream), on);
  388. azx_dev->wc_marked = on;
  389. }
  390. }
  391. #else
  392. /* NOP for other archs */
  393. static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
  394. bool on)
  395. {
  396. }
  397. static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
  398. struct snd_pcm_substream *substream, bool on)
  399. {
  400. }
  401. #endif
  402. static int azx_acquire_irq(struct azx *chip, int do_disconnect);
  403. /*
  404. * initialize the PCI registers
  405. */
  406. /* update bits in a PCI register byte */
  407. static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
  408. unsigned char mask, unsigned char val)
  409. {
  410. unsigned char data;
  411. pci_read_config_byte(pci, reg, &data);
  412. data &= ~mask;
  413. data |= (val & mask);
  414. pci_write_config_byte(pci, reg, data);
  415. }
  416. static void azx_init_pci(struct azx *chip)
  417. {
  418. int snoop_type = azx_get_snoop_type(chip);
  419. /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  420. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  421. * Ensuring these bits are 0 clears playback static on some HD Audio
  422. * codecs.
  423. * The PCI register TCSEL is defined in the Intel manuals.
  424. */
  425. if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) {
  426. dev_dbg(chip->card->dev, "Clearing TCSEL\n");
  427. update_pci_byte(chip->pci, AZX_PCIREG_TCSEL, 0x07, 0);
  428. }
  429. /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio,
  430. * we need to enable snoop.
  431. */
  432. if (snoop_type == AZX_SNOOP_TYPE_ATI) {
  433. dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
  434. azx_snoop(chip));
  435. update_pci_byte(chip->pci,
  436. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
  437. azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
  438. }
  439. /* For NVIDIA HDA, enable snoop */
  440. if (snoop_type == AZX_SNOOP_TYPE_NVIDIA) {
  441. dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
  442. azx_snoop(chip));
  443. update_pci_byte(chip->pci,
  444. NVIDIA_HDA_TRANSREG_ADDR,
  445. 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
  446. update_pci_byte(chip->pci,
  447. NVIDIA_HDA_ISTRM_COH,
  448. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  449. update_pci_byte(chip->pci,
  450. NVIDIA_HDA_OSTRM_COH,
  451. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  452. }
  453. /* Enable SCH/PCH snoop if needed */
  454. if (snoop_type == AZX_SNOOP_TYPE_SCH) {
  455. unsigned short snoop;
  456. pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
  457. if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
  458. (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
  459. snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
  460. if (!azx_snoop(chip))
  461. snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
  462. pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
  463. pci_read_config_word(chip->pci,
  464. INTEL_SCH_HDA_DEVC, &snoop);
  465. }
  466. dev_dbg(chip->card->dev, "SCH snoop: %s\n",
  467. (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ?
  468. "Disabled" : "Enabled");
  469. }
  470. }
  471. /*
  472. * In BXT-P A0, HD-Audio DMA requests is later than expected,
  473. * and makes an audio stream sensitive to system latencies when
  474. * 24/32 bits are playing.
  475. * Adjusting threshold of DMA fifo to force the DMA request
  476. * sooner to improve latency tolerance at the expense of power.
  477. */
  478. static void bxt_reduce_dma_latency(struct azx *chip)
  479. {
  480. u32 val;
  481. val = azx_readl(chip, VS_EM4L);
  482. val &= (0x3 << 20);
  483. azx_writel(chip, VS_EM4L, val);
  484. }
  485. /*
  486. * ML_LCAP bits:
  487. * bit 0: 6 MHz Supported
  488. * bit 1: 12 MHz Supported
  489. * bit 2: 24 MHz Supported
  490. * bit 3: 48 MHz Supported
  491. * bit 4: 96 MHz Supported
  492. * bit 5: 192 MHz Supported
  493. */
  494. static int intel_get_lctl_scf(struct azx *chip)
  495. {
  496. struct hdac_bus *bus = azx_bus(chip);
  497. static int preferred_bits[] = { 2, 3, 1, 4, 5 };
  498. u32 val, t;
  499. int i;
  500. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCAP);
  501. for (i = 0; i < ARRAY_SIZE(preferred_bits); i++) {
  502. t = preferred_bits[i];
  503. if (val & (1 << t))
  504. return t;
  505. }
  506. dev_warn(chip->card->dev, "set audio clock frequency to 6MHz");
  507. return 0;
  508. }
  509. static int intel_ml_lctl_set_power(struct azx *chip, int state)
  510. {
  511. struct hdac_bus *bus = azx_bus(chip);
  512. u32 val;
  513. int timeout;
  514. /*
  515. * the codecs are sharing the first link setting by default
  516. * If other links are enabled for stream, they need similar fix
  517. */
  518. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  519. val &= ~AZX_MLCTL_SPA;
  520. val |= state << AZX_MLCTL_SPA_SHIFT;
  521. writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  522. /* wait for CPA */
  523. timeout = 50;
  524. while (timeout) {
  525. if (((readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL)) &
  526. AZX_MLCTL_CPA) == (state << AZX_MLCTL_CPA_SHIFT))
  527. return 0;
  528. timeout--;
  529. udelay(10);
  530. }
  531. return -1;
  532. }
  533. static void intel_init_lctl(struct azx *chip)
  534. {
  535. struct hdac_bus *bus = azx_bus(chip);
  536. u32 val;
  537. int ret;
  538. /* 0. check lctl register value is correct or not */
  539. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  540. /* if SCF is already set, let's use it */
  541. if ((val & ML_LCTL_SCF_MASK) != 0)
  542. return;
  543. /*
  544. * Before operating on SPA, CPA must match SPA.
  545. * Any deviation may result in undefined behavior.
  546. */
  547. if (((val & AZX_MLCTL_SPA) >> AZX_MLCTL_SPA_SHIFT) !=
  548. ((val & AZX_MLCTL_CPA) >> AZX_MLCTL_CPA_SHIFT))
  549. return;
  550. /* 1. turn link down: set SPA to 0 and wait CPA to 0 */
  551. ret = intel_ml_lctl_set_power(chip, 0);
  552. udelay(100);
  553. if (ret)
  554. goto set_spa;
  555. /* 2. update SCF to select a properly audio clock*/
  556. val &= ~ML_LCTL_SCF_MASK;
  557. val |= intel_get_lctl_scf(chip);
  558. writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  559. set_spa:
  560. /* 4. turn link up: set SPA to 1 and wait CPA to 1 */
  561. intel_ml_lctl_set_power(chip, 1);
  562. udelay(100);
  563. }
  564. static void hda_intel_init_chip(struct azx *chip, bool full_reset)
  565. {
  566. struct hdac_bus *bus = azx_bus(chip);
  567. struct pci_dev *pci = chip->pci;
  568. u32 val;
  569. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  570. snd_hdac_set_codec_wakeup(bus, true);
  571. if (IS_SKL_PLUS(pci)) {
  572. pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
  573. val = val & ~INTEL_HDA_CGCTL_MISCBDCGE;
  574. pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
  575. }
  576. azx_init_chip(chip, full_reset);
  577. if (IS_SKL_PLUS(pci)) {
  578. pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
  579. val = val | INTEL_HDA_CGCTL_MISCBDCGE;
  580. pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
  581. }
  582. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  583. snd_hdac_set_codec_wakeup(bus, false);
  584. /* reduce dma latency to avoid noise */
  585. if (IS_BXT(pci))
  586. bxt_reduce_dma_latency(chip);
  587. if (bus->mlcap != NULL)
  588. intel_init_lctl(chip);
  589. }
  590. /* calculate runtime delay from LPIB */
  591. static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev,
  592. unsigned int pos)
  593. {
  594. struct snd_pcm_substream *substream = azx_dev->core.substream;
  595. int stream = substream->stream;
  596. unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev);
  597. int delay;
  598. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  599. delay = pos - lpib_pos;
  600. else
  601. delay = lpib_pos - pos;
  602. if (delay < 0) {
  603. if (delay >= azx_dev->core.delay_negative_threshold)
  604. delay = 0;
  605. else
  606. delay += azx_dev->core.bufsize;
  607. }
  608. if (delay >= azx_dev->core.period_bytes) {
  609. dev_info(chip->card->dev,
  610. "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
  611. delay, azx_dev->core.period_bytes);
  612. delay = 0;
  613. chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
  614. chip->get_delay[stream] = NULL;
  615. }
  616. return bytes_to_frames(substream->runtime, delay);
  617. }
  618. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
  619. /* called from IRQ */
  620. static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
  621. {
  622. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  623. int ok;
  624. ok = azx_position_ok(chip, azx_dev);
  625. if (ok == 1) {
  626. azx_dev->irq_pending = 0;
  627. return ok;
  628. } else if (ok == 0) {
  629. /* bogus IRQ, process it later */
  630. azx_dev->irq_pending = 1;
  631. schedule_work(&hda->irq_pending_work);
  632. }
  633. return 0;
  634. }
  635. /* Enable/disable i915 display power for the link */
  636. static int azx_intel_link_power(struct azx *chip, bool enable)
  637. {
  638. struct hdac_bus *bus = azx_bus(chip);
  639. return snd_hdac_display_power(bus, enable);
  640. }
  641. /*
  642. * Check whether the current DMA position is acceptable for updating
  643. * periods. Returns non-zero if it's OK.
  644. *
  645. * Many HD-audio controllers appear pretty inaccurate about
  646. * the update-IRQ timing. The IRQ is issued before actually the
  647. * data is processed. So, we need to process it afterwords in a
  648. * workqueue.
  649. */
  650. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  651. {
  652. struct snd_pcm_substream *substream = azx_dev->core.substream;
  653. int stream = substream->stream;
  654. u32 wallclk;
  655. unsigned int pos;
  656. wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk;
  657. if (wallclk < (azx_dev->core.period_wallclk * 2) / 3)
  658. return -1; /* bogus (too early) interrupt */
  659. if (chip->get_position[stream])
  660. pos = chip->get_position[stream](chip, azx_dev);
  661. else { /* use the position buffer as default */
  662. pos = azx_get_pos_posbuf(chip, azx_dev);
  663. if (!pos || pos == (u32)-1) {
  664. dev_info(chip->card->dev,
  665. "Invalid position buffer, using LPIB read method instead.\n");
  666. chip->get_position[stream] = azx_get_pos_lpib;
  667. if (chip->get_position[0] == azx_get_pos_lpib &&
  668. chip->get_position[1] == azx_get_pos_lpib)
  669. azx_bus(chip)->use_posbuf = false;
  670. pos = azx_get_pos_lpib(chip, azx_dev);
  671. chip->get_delay[stream] = NULL;
  672. } else {
  673. chip->get_position[stream] = azx_get_pos_posbuf;
  674. if (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)
  675. chip->get_delay[stream] = azx_get_delay_from_lpib;
  676. }
  677. }
  678. if (pos >= azx_dev->core.bufsize)
  679. pos = 0;
  680. if (WARN_ONCE(!azx_dev->core.period_bytes,
  681. "hda-intel: zero azx_dev->period_bytes"))
  682. return -1; /* this shouldn't happen! */
  683. if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 &&
  684. pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2)
  685. /* NG - it's below the first next period boundary */
  686. return chip->bdl_pos_adj ? 0 : -1;
  687. azx_dev->core.start_wallclk += wallclk;
  688. return 1; /* OK, it's fine */
  689. }
  690. /*
  691. * The work for pending PCM period updates.
  692. */
  693. static void azx_irq_pending_work(struct work_struct *work)
  694. {
  695. struct hda_intel *hda = container_of(work, struct hda_intel, irq_pending_work);
  696. struct azx *chip = &hda->chip;
  697. struct hdac_bus *bus = azx_bus(chip);
  698. struct hdac_stream *s;
  699. int pending, ok;
  700. if (!hda->irq_pending_warned) {
  701. dev_info(chip->card->dev,
  702. "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n",
  703. chip->card->number);
  704. hda->irq_pending_warned = 1;
  705. }
  706. for (;;) {
  707. pending = 0;
  708. spin_lock_irq(&bus->reg_lock);
  709. list_for_each_entry(s, &bus->stream_list, list) {
  710. struct azx_dev *azx_dev = stream_to_azx_dev(s);
  711. if (!azx_dev->irq_pending ||
  712. !s->substream ||
  713. !s->running)
  714. continue;
  715. ok = azx_position_ok(chip, azx_dev);
  716. if (ok > 0) {
  717. azx_dev->irq_pending = 0;
  718. spin_unlock(&bus->reg_lock);
  719. snd_pcm_period_elapsed(s->substream);
  720. spin_lock(&bus->reg_lock);
  721. } else if (ok < 0) {
  722. pending = 0; /* too early */
  723. } else
  724. pending++;
  725. }
  726. spin_unlock_irq(&bus->reg_lock);
  727. if (!pending)
  728. return;
  729. msleep(1);
  730. }
  731. }
  732. /* clear irq_pending flags and assure no on-going workq */
  733. static void azx_clear_irq_pending(struct azx *chip)
  734. {
  735. struct hdac_bus *bus = azx_bus(chip);
  736. struct hdac_stream *s;
  737. spin_lock_irq(&bus->reg_lock);
  738. list_for_each_entry(s, &bus->stream_list, list) {
  739. struct azx_dev *azx_dev = stream_to_azx_dev(s);
  740. azx_dev->irq_pending = 0;
  741. }
  742. spin_unlock_irq(&bus->reg_lock);
  743. }
  744. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  745. {
  746. struct hdac_bus *bus = azx_bus(chip);
  747. if (request_irq(chip->pci->irq, azx_interrupt,
  748. chip->msi ? 0 : IRQF_SHARED,
  749. chip->card->irq_descr, chip)) {
  750. dev_err(chip->card->dev,
  751. "unable to grab IRQ %d, disabling device\n",
  752. chip->pci->irq);
  753. if (do_disconnect)
  754. snd_card_disconnect(chip->card);
  755. return -1;
  756. }
  757. bus->irq = chip->pci->irq;
  758. pci_intx(chip->pci, !chip->msi);
  759. return 0;
  760. }
  761. /* get the current DMA position with correction on VIA chips */
  762. static unsigned int azx_via_get_position(struct azx *chip,
  763. struct azx_dev *azx_dev)
  764. {
  765. unsigned int link_pos, mini_pos, bound_pos;
  766. unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
  767. unsigned int fifo_size;
  768. link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
  769. if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  770. /* Playback, no problem using link position */
  771. return link_pos;
  772. }
  773. /* Capture */
  774. /* For new chipset,
  775. * use mod to get the DMA position just like old chipset
  776. */
  777. mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf);
  778. mod_dma_pos %= azx_dev->core.period_bytes;
  779. /* azx_dev->fifo_size can't get FIFO size of in stream.
  780. * Get from base address + offset.
  781. */
  782. fifo_size = readw(azx_bus(chip)->remap_addr +
  783. VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
  784. if (azx_dev->insufficient) {
  785. /* Link position never gather than FIFO size */
  786. if (link_pos <= fifo_size)
  787. return 0;
  788. azx_dev->insufficient = 0;
  789. }
  790. if (link_pos <= fifo_size)
  791. mini_pos = azx_dev->core.bufsize + link_pos - fifo_size;
  792. else
  793. mini_pos = link_pos - fifo_size;
  794. /* Find nearest previous boudary */
  795. mod_mini_pos = mini_pos % azx_dev->core.period_bytes;
  796. mod_link_pos = link_pos % azx_dev->core.period_bytes;
  797. if (mod_link_pos >= fifo_size)
  798. bound_pos = link_pos - mod_link_pos;
  799. else if (mod_dma_pos >= mod_mini_pos)
  800. bound_pos = mini_pos - mod_mini_pos;
  801. else {
  802. bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes;
  803. if (bound_pos >= azx_dev->core.bufsize)
  804. bound_pos = 0;
  805. }
  806. /* Calculate real DMA position we want */
  807. return bound_pos + mod_dma_pos;
  808. }
  809. static unsigned int azx_skl_get_dpib_pos(struct azx *chip,
  810. struct azx_dev *azx_dev)
  811. {
  812. return _snd_hdac_chip_readl(azx_bus(chip),
  813. AZX_REG_VS_SDXDPIB_XBASE +
  814. (AZX_REG_VS_SDXDPIB_XINTERVAL *
  815. azx_dev->core.index));
  816. }
  817. /* get the current DMA position with correction on SKL+ chips */
  818. static unsigned int azx_get_pos_skl(struct azx *chip, struct azx_dev *azx_dev)
  819. {
  820. /* DPIB register gives a more accurate position for playback */
  821. if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  822. return azx_skl_get_dpib_pos(chip, azx_dev);
  823. /* For capture, we need to read posbuf, but it requires a delay
  824. * for the possible boundary overlap; the read of DPIB fetches the
  825. * actual posbuf
  826. */
  827. udelay(20);
  828. azx_skl_get_dpib_pos(chip, azx_dev);
  829. return azx_get_pos_posbuf(chip, azx_dev);
  830. }
  831. #ifdef CONFIG_PM
  832. static DEFINE_MUTEX(card_list_lock);
  833. static LIST_HEAD(card_list);
  834. static void azx_add_card_list(struct azx *chip)
  835. {
  836. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  837. mutex_lock(&card_list_lock);
  838. list_add(&hda->list, &card_list);
  839. mutex_unlock(&card_list_lock);
  840. }
  841. static void azx_del_card_list(struct azx *chip)
  842. {
  843. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  844. mutex_lock(&card_list_lock);
  845. list_del_init(&hda->list);
  846. mutex_unlock(&card_list_lock);
  847. }
  848. /* trigger power-save check at writing parameter */
  849. static int param_set_xint(const char *val, const struct kernel_param *kp)
  850. {
  851. struct hda_intel *hda;
  852. struct azx *chip;
  853. int prev = power_save;
  854. int ret = param_set_int(val, kp);
  855. if (ret || prev == power_save)
  856. return ret;
  857. mutex_lock(&card_list_lock);
  858. list_for_each_entry(hda, &card_list, list) {
  859. chip = &hda->chip;
  860. if (!hda->probe_continued || chip->disabled)
  861. continue;
  862. snd_hda_set_power_save(&chip->bus, power_save * 1000);
  863. }
  864. mutex_unlock(&card_list_lock);
  865. return 0;
  866. }
  867. #else
  868. #define azx_add_card_list(chip) /* NOP */
  869. #define azx_del_card_list(chip) /* NOP */
  870. #endif /* CONFIG_PM */
  871. #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO)
  872. /*
  873. * power management
  874. */
  875. static int azx_suspend(struct device *dev)
  876. {
  877. struct snd_card *card = dev_get_drvdata(dev);
  878. struct azx *chip;
  879. struct hda_intel *hda;
  880. struct hdac_bus *bus;
  881. if (!card)
  882. return 0;
  883. chip = card->private_data;
  884. hda = container_of(chip, struct hda_intel, chip);
  885. if (chip->disabled || hda->init_failed || !chip->running)
  886. return 0;
  887. bus = azx_bus(chip);
  888. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  889. azx_clear_irq_pending(chip);
  890. azx_stop_chip(chip);
  891. azx_enter_link_reset(chip);
  892. if (bus->irq >= 0) {
  893. free_irq(bus->irq, chip);
  894. bus->irq = -1;
  895. }
  896. if (chip->msi)
  897. pci_disable_msi(chip->pci);
  898. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
  899. && hda->need_i915_power)
  900. snd_hdac_display_power(bus, false);
  901. trace_azx_suspend(chip);
  902. return 0;
  903. }
  904. static int azx_resume(struct device *dev)
  905. {
  906. struct pci_dev *pci = to_pci_dev(dev);
  907. struct snd_card *card = dev_get_drvdata(dev);
  908. struct azx *chip;
  909. struct hda_intel *hda;
  910. struct hdac_bus *bus;
  911. if (!card)
  912. return 0;
  913. chip = card->private_data;
  914. hda = container_of(chip, struct hda_intel, chip);
  915. bus = azx_bus(chip);
  916. if (chip->disabled || hda->init_failed || !chip->running)
  917. return 0;
  918. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  919. snd_hdac_display_power(bus, true);
  920. if (hda->need_i915_power)
  921. snd_hdac_i915_set_bclk(bus);
  922. }
  923. if (chip->msi)
  924. if (pci_enable_msi(pci) < 0)
  925. chip->msi = 0;
  926. if (azx_acquire_irq(chip, 1) < 0)
  927. return -EIO;
  928. azx_init_pci(chip);
  929. hda_intel_init_chip(chip, true);
  930. /* power down again for link-controlled chips */
  931. if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
  932. !hda->need_i915_power)
  933. snd_hdac_display_power(bus, false);
  934. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  935. trace_azx_resume(chip);
  936. return 0;
  937. }
  938. #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */
  939. #ifdef CONFIG_PM_SLEEP
  940. /* put codec down to D3 at hibernation for Intel SKL+;
  941. * otherwise BIOS may still access the codec and screw up the driver
  942. */
  943. static int azx_freeze_noirq(struct device *dev)
  944. {
  945. struct pci_dev *pci = to_pci_dev(dev);
  946. if (IS_SKL_PLUS(pci))
  947. pci_set_power_state(pci, PCI_D3hot);
  948. return 0;
  949. }
  950. static int azx_thaw_noirq(struct device *dev)
  951. {
  952. struct pci_dev *pci = to_pci_dev(dev);
  953. if (IS_SKL_PLUS(pci))
  954. pci_set_power_state(pci, PCI_D0);
  955. return 0;
  956. }
  957. #endif /* CONFIG_PM_SLEEP */
  958. #ifdef CONFIG_PM
  959. static int azx_runtime_suspend(struct device *dev)
  960. {
  961. struct snd_card *card = dev_get_drvdata(dev);
  962. struct azx *chip;
  963. struct hda_intel *hda;
  964. if (!card)
  965. return 0;
  966. chip = card->private_data;
  967. hda = container_of(chip, struct hda_intel, chip);
  968. if (chip->disabled || hda->init_failed)
  969. return 0;
  970. if (!azx_has_pm_runtime(chip))
  971. return 0;
  972. /* enable controller wake up event */
  973. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
  974. STATESTS_INT_MASK);
  975. azx_stop_chip(chip);
  976. azx_enter_link_reset(chip);
  977. azx_clear_irq_pending(chip);
  978. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
  979. && hda->need_i915_power)
  980. snd_hdac_display_power(azx_bus(chip), false);
  981. trace_azx_runtime_suspend(chip);
  982. return 0;
  983. }
  984. static int azx_runtime_resume(struct device *dev)
  985. {
  986. struct snd_card *card = dev_get_drvdata(dev);
  987. struct azx *chip;
  988. struct hda_intel *hda;
  989. struct hdac_bus *bus;
  990. struct hda_codec *codec;
  991. int status;
  992. if (!card)
  993. return 0;
  994. chip = card->private_data;
  995. hda = container_of(chip, struct hda_intel, chip);
  996. bus = azx_bus(chip);
  997. if (chip->disabled || hda->init_failed)
  998. return 0;
  999. if (!azx_has_pm_runtime(chip))
  1000. return 0;
  1001. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1002. snd_hdac_display_power(bus, true);
  1003. if (hda->need_i915_power)
  1004. snd_hdac_i915_set_bclk(bus);
  1005. }
  1006. /* Read STATESTS before controller reset */
  1007. status = azx_readw(chip, STATESTS);
  1008. azx_init_pci(chip);
  1009. hda_intel_init_chip(chip, true);
  1010. if (status) {
  1011. list_for_each_codec(codec, &chip->bus)
  1012. if (status & (1 << codec->addr))
  1013. schedule_delayed_work(&codec->jackpoll_work,
  1014. codec->jackpoll_interval);
  1015. }
  1016. /* disable controller Wake Up event*/
  1017. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
  1018. ~STATESTS_INT_MASK);
  1019. /* power down again for link-controlled chips */
  1020. if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
  1021. !hda->need_i915_power)
  1022. snd_hdac_display_power(bus, false);
  1023. trace_azx_runtime_resume(chip);
  1024. return 0;
  1025. }
  1026. static int azx_runtime_idle(struct device *dev)
  1027. {
  1028. struct snd_card *card = dev_get_drvdata(dev);
  1029. struct azx *chip;
  1030. struct hda_intel *hda;
  1031. if (!card)
  1032. return 0;
  1033. chip = card->private_data;
  1034. hda = container_of(chip, struct hda_intel, chip);
  1035. if (chip->disabled || hda->init_failed)
  1036. return 0;
  1037. if (!power_save_controller || !azx_has_pm_runtime(chip) ||
  1038. azx_bus(chip)->codec_powered || !chip->running)
  1039. return -EBUSY;
  1040. return 0;
  1041. }
  1042. static const struct dev_pm_ops azx_pm = {
  1043. SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
  1044. #ifdef CONFIG_PM_SLEEP
  1045. .freeze_noirq = azx_freeze_noirq,
  1046. .thaw_noirq = azx_thaw_noirq,
  1047. #endif
  1048. SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
  1049. };
  1050. #define AZX_PM_OPS &azx_pm
  1051. #else
  1052. #define AZX_PM_OPS NULL
  1053. #endif /* CONFIG_PM */
  1054. static int azx_probe_continue(struct azx *chip);
  1055. #ifdef SUPPORT_VGA_SWITCHEROO
  1056. static struct pci_dev *get_bound_vga(struct pci_dev *pci);
  1057. static void azx_vs_set_state(struct pci_dev *pci,
  1058. enum vga_switcheroo_state state)
  1059. {
  1060. struct snd_card *card = pci_get_drvdata(pci);
  1061. struct azx *chip = card->private_data;
  1062. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1063. bool disabled;
  1064. wait_for_completion(&hda->probe_wait);
  1065. if (hda->init_failed)
  1066. return;
  1067. disabled = (state == VGA_SWITCHEROO_OFF);
  1068. if (chip->disabled == disabled)
  1069. return;
  1070. if (!hda->probe_continued) {
  1071. chip->disabled = disabled;
  1072. if (!disabled) {
  1073. dev_info(chip->card->dev,
  1074. "Start delayed initialization\n");
  1075. if (azx_probe_continue(chip) < 0) {
  1076. dev_err(chip->card->dev, "initialization error\n");
  1077. hda->init_failed = true;
  1078. }
  1079. }
  1080. } else {
  1081. dev_info(chip->card->dev, "%s via vga_switcheroo\n",
  1082. disabled ? "Disabling" : "Enabling");
  1083. if (disabled) {
  1084. pm_runtime_put_sync_suspend(card->dev);
  1085. azx_suspend(card->dev);
  1086. /* when we get suspended by vga_switcheroo we end up in D3cold,
  1087. * however we have no ACPI handle, so pci/acpi can't put us there,
  1088. * put ourselves there */
  1089. pci->current_state = PCI_D3cold;
  1090. chip->disabled = true;
  1091. if (snd_hda_lock_devices(&chip->bus))
  1092. dev_warn(chip->card->dev,
  1093. "Cannot lock devices!\n");
  1094. } else {
  1095. snd_hda_unlock_devices(&chip->bus);
  1096. pm_runtime_get_noresume(card->dev);
  1097. chip->disabled = false;
  1098. azx_resume(card->dev);
  1099. }
  1100. }
  1101. }
  1102. static bool azx_vs_can_switch(struct pci_dev *pci)
  1103. {
  1104. struct snd_card *card = pci_get_drvdata(pci);
  1105. struct azx *chip = card->private_data;
  1106. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1107. wait_for_completion(&hda->probe_wait);
  1108. if (hda->init_failed)
  1109. return false;
  1110. if (chip->disabled || !hda->probe_continued)
  1111. return true;
  1112. if (snd_hda_lock_devices(&chip->bus))
  1113. return false;
  1114. snd_hda_unlock_devices(&chip->bus);
  1115. return true;
  1116. }
  1117. static void init_vga_switcheroo(struct azx *chip)
  1118. {
  1119. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1120. struct pci_dev *p = get_bound_vga(chip->pci);
  1121. if (p) {
  1122. dev_info(chip->card->dev,
  1123. "Handle vga_switcheroo audio client\n");
  1124. hda->use_vga_switcheroo = 1;
  1125. pci_dev_put(p);
  1126. }
  1127. }
  1128. static const struct vga_switcheroo_client_ops azx_vs_ops = {
  1129. .set_gpu_state = azx_vs_set_state,
  1130. .can_switch = azx_vs_can_switch,
  1131. };
  1132. static int register_vga_switcheroo(struct azx *chip)
  1133. {
  1134. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1135. int err;
  1136. if (!hda->use_vga_switcheroo)
  1137. return 0;
  1138. /* FIXME: currently only handling DIS controller
  1139. * is there any machine with two switchable HDMI audio controllers?
  1140. */
  1141. err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops,
  1142. VGA_SWITCHEROO_DIS);
  1143. if (err < 0)
  1144. return err;
  1145. hda->vga_switcheroo_registered = 1;
  1146. /* register as an optimus hdmi audio power domain */
  1147. vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev,
  1148. &hda->hdmi_pm_domain);
  1149. return 0;
  1150. }
  1151. #else
  1152. #define init_vga_switcheroo(chip) /* NOP */
  1153. #define register_vga_switcheroo(chip) 0
  1154. #define check_hdmi_disabled(pci) false
  1155. #endif /* SUPPORT_VGA_SWITCHER */
  1156. /*
  1157. * destructor
  1158. */
  1159. static int azx_free(struct azx *chip)
  1160. {
  1161. struct pci_dev *pci = chip->pci;
  1162. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1163. struct hdac_bus *bus = azx_bus(chip);
  1164. if (azx_has_pm_runtime(chip) && chip->running)
  1165. pm_runtime_get_noresume(&pci->dev);
  1166. azx_del_card_list(chip);
  1167. hda->init_failed = 1; /* to be sure */
  1168. complete_all(&hda->probe_wait);
  1169. if (use_vga_switcheroo(hda)) {
  1170. if (chip->disabled && hda->probe_continued)
  1171. snd_hda_unlock_devices(&chip->bus);
  1172. if (hda->vga_switcheroo_registered) {
  1173. vga_switcheroo_unregister_client(chip->pci);
  1174. vga_switcheroo_fini_domain_pm_ops(chip->card->dev);
  1175. }
  1176. }
  1177. if (bus->chip_init) {
  1178. azx_clear_irq_pending(chip);
  1179. azx_stop_all_streams(chip);
  1180. azx_stop_chip(chip);
  1181. }
  1182. if (bus->irq >= 0)
  1183. free_irq(bus->irq, (void*)chip);
  1184. if (chip->msi)
  1185. pci_disable_msi(chip->pci);
  1186. iounmap(bus->remap_addr);
  1187. azx_free_stream_pages(chip);
  1188. azx_free_streams(chip);
  1189. snd_hdac_bus_exit(bus);
  1190. if (chip->region_requested)
  1191. pci_release_regions(chip->pci);
  1192. pci_disable_device(chip->pci);
  1193. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1194. release_firmware(chip->fw);
  1195. #endif
  1196. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1197. if (hda->need_i915_power)
  1198. snd_hdac_display_power(bus, false);
  1199. snd_hdac_i915_exit(bus);
  1200. }
  1201. kfree(hda);
  1202. return 0;
  1203. }
  1204. static int azx_dev_disconnect(struct snd_device *device)
  1205. {
  1206. struct azx *chip = device->device_data;
  1207. chip->bus.shutdown = 1;
  1208. return 0;
  1209. }
  1210. static int azx_dev_free(struct snd_device *device)
  1211. {
  1212. return azx_free(device->device_data);
  1213. }
  1214. #ifdef SUPPORT_VGA_SWITCHEROO
  1215. /*
  1216. * Check of disabled HDMI controller by vga_switcheroo
  1217. */
  1218. static struct pci_dev *get_bound_vga(struct pci_dev *pci)
  1219. {
  1220. struct pci_dev *p;
  1221. /* check only discrete GPU */
  1222. switch (pci->vendor) {
  1223. case PCI_VENDOR_ID_ATI:
  1224. case PCI_VENDOR_ID_AMD:
  1225. case PCI_VENDOR_ID_NVIDIA:
  1226. if (pci->devfn == 1) {
  1227. p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
  1228. pci->bus->number, 0);
  1229. if (p) {
  1230. if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA)
  1231. return p;
  1232. pci_dev_put(p);
  1233. }
  1234. }
  1235. break;
  1236. }
  1237. return NULL;
  1238. }
  1239. static bool check_hdmi_disabled(struct pci_dev *pci)
  1240. {
  1241. bool vga_inactive = false;
  1242. struct pci_dev *p = get_bound_vga(pci);
  1243. if (p) {
  1244. if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
  1245. vga_inactive = true;
  1246. pci_dev_put(p);
  1247. }
  1248. return vga_inactive;
  1249. }
  1250. #endif /* SUPPORT_VGA_SWITCHEROO */
  1251. /*
  1252. * white/black-listing for position_fix
  1253. */
  1254. static struct snd_pci_quirk position_fix_list[] = {
  1255. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  1256. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  1257. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  1258. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  1259. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  1260. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  1261. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  1262. SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
  1263. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  1264. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  1265. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  1266. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  1267. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  1268. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  1269. {}
  1270. };
  1271. static int check_position_fix(struct azx *chip, int fix)
  1272. {
  1273. const struct snd_pci_quirk *q;
  1274. switch (fix) {
  1275. case POS_FIX_AUTO:
  1276. case POS_FIX_LPIB:
  1277. case POS_FIX_POSBUF:
  1278. case POS_FIX_VIACOMBO:
  1279. case POS_FIX_COMBO:
  1280. case POS_FIX_SKL:
  1281. return fix;
  1282. }
  1283. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  1284. if (q) {
  1285. dev_info(chip->card->dev,
  1286. "position_fix set to %d for device %04x:%04x\n",
  1287. q->value, q->subvendor, q->subdevice);
  1288. return q->value;
  1289. }
  1290. /* Check VIA/ATI HD Audio Controller exist */
  1291. if (chip->driver_type == AZX_DRIVER_VIA) {
  1292. dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
  1293. return POS_FIX_VIACOMBO;
  1294. }
  1295. if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
  1296. dev_dbg(chip->card->dev, "Using LPIB position fix\n");
  1297. return POS_FIX_LPIB;
  1298. }
  1299. if (IS_SKL_PLUS(chip->pci)) {
  1300. dev_dbg(chip->card->dev, "Using SKL position fix\n");
  1301. return POS_FIX_SKL;
  1302. }
  1303. return POS_FIX_AUTO;
  1304. }
  1305. static void assign_position_fix(struct azx *chip, int fix)
  1306. {
  1307. static azx_get_pos_callback_t callbacks[] = {
  1308. [POS_FIX_AUTO] = NULL,
  1309. [POS_FIX_LPIB] = azx_get_pos_lpib,
  1310. [POS_FIX_POSBUF] = azx_get_pos_posbuf,
  1311. [POS_FIX_VIACOMBO] = azx_via_get_position,
  1312. [POS_FIX_COMBO] = azx_get_pos_lpib,
  1313. [POS_FIX_SKL] = azx_get_pos_skl,
  1314. };
  1315. chip->get_position[0] = chip->get_position[1] = callbacks[fix];
  1316. /* combo mode uses LPIB only for playback */
  1317. if (fix == POS_FIX_COMBO)
  1318. chip->get_position[1] = NULL;
  1319. if ((fix == POS_FIX_POSBUF || fix == POS_FIX_SKL) &&
  1320. (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
  1321. chip->get_delay[0] = chip->get_delay[1] =
  1322. azx_get_delay_from_lpib;
  1323. }
  1324. }
  1325. /*
  1326. * black-lists for probe_mask
  1327. */
  1328. static struct snd_pci_quirk probe_mask_list[] = {
  1329. /* Thinkpad often breaks the controller communication when accessing
  1330. * to the non-working (or non-existing) modem codec slot.
  1331. */
  1332. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  1333. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  1334. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  1335. /* broken BIOS */
  1336. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  1337. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  1338. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  1339. /* forced codec slots */
  1340. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  1341. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  1342. /* WinFast VP200 H (Teradici) user reported broken communication */
  1343. SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
  1344. {}
  1345. };
  1346. #define AZX_FORCE_CODEC_MASK 0x100
  1347. static void check_probe_mask(struct azx *chip, int dev)
  1348. {
  1349. const struct snd_pci_quirk *q;
  1350. chip->codec_probe_mask = probe_mask[dev];
  1351. if (chip->codec_probe_mask == -1) {
  1352. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  1353. if (q) {
  1354. dev_info(chip->card->dev,
  1355. "probe_mask set to 0x%x for device %04x:%04x\n",
  1356. q->value, q->subvendor, q->subdevice);
  1357. chip->codec_probe_mask = q->value;
  1358. }
  1359. }
  1360. /* check forced option */
  1361. if (chip->codec_probe_mask != -1 &&
  1362. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  1363. azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff;
  1364. dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
  1365. (int)azx_bus(chip)->codec_mask);
  1366. }
  1367. }
  1368. /*
  1369. * white/black-list for enable_msi
  1370. */
  1371. static struct snd_pci_quirk msi_black_list[] = {
  1372. SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
  1373. SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
  1374. SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
  1375. SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
  1376. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  1377. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  1378. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  1379. SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
  1380. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  1381. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  1382. {}
  1383. };
  1384. static void check_msi(struct azx *chip)
  1385. {
  1386. const struct snd_pci_quirk *q;
  1387. if (enable_msi >= 0) {
  1388. chip->msi = !!enable_msi;
  1389. return;
  1390. }
  1391. chip->msi = 1; /* enable MSI as default */
  1392. q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
  1393. if (q) {
  1394. dev_info(chip->card->dev,
  1395. "msi for device %04x:%04x set to %d\n",
  1396. q->subvendor, q->subdevice, q->value);
  1397. chip->msi = q->value;
  1398. return;
  1399. }
  1400. /* NVidia chipsets seem to cause troubles with MSI */
  1401. if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
  1402. dev_info(chip->card->dev, "Disabling MSI\n");
  1403. chip->msi = 0;
  1404. }
  1405. }
  1406. /* check the snoop mode availability */
  1407. static void azx_check_snoop_available(struct azx *chip)
  1408. {
  1409. int snoop = hda_snoop;
  1410. if (snoop >= 0) {
  1411. dev_info(chip->card->dev, "Force to %s mode by module option\n",
  1412. snoop ? "snoop" : "non-snoop");
  1413. chip->snoop = snoop;
  1414. return;
  1415. }
  1416. snoop = true;
  1417. if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
  1418. chip->driver_type == AZX_DRIVER_VIA) {
  1419. /* force to non-snoop mode for a new VIA controller
  1420. * when BIOS is set
  1421. */
  1422. u8 val;
  1423. pci_read_config_byte(chip->pci, 0x42, &val);
  1424. if (!(val & 0x80) && chip->pci->revision == 0x30)
  1425. snoop = false;
  1426. }
  1427. if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
  1428. snoop = false;
  1429. chip->snoop = snoop;
  1430. if (!snoop)
  1431. dev_info(chip->card->dev, "Force to non-snoop mode\n");
  1432. }
  1433. static void azx_probe_work(struct work_struct *work)
  1434. {
  1435. struct hda_intel *hda = container_of(work, struct hda_intel, probe_work);
  1436. azx_probe_continue(&hda->chip);
  1437. }
  1438. static int default_bdl_pos_adj(struct azx *chip)
  1439. {
  1440. /* some exceptions: Atoms seem problematic with value 1 */
  1441. if (chip->pci->vendor == PCI_VENDOR_ID_INTEL) {
  1442. switch (chip->pci->device) {
  1443. case 0x0f04: /* Baytrail */
  1444. case 0x2284: /* Braswell */
  1445. return 32;
  1446. }
  1447. }
  1448. switch (chip->driver_type) {
  1449. case AZX_DRIVER_ICH:
  1450. case AZX_DRIVER_PCH:
  1451. return 1;
  1452. default:
  1453. return 32;
  1454. }
  1455. }
  1456. /*
  1457. * constructor
  1458. */
  1459. static const struct hdac_io_ops pci_hda_io_ops;
  1460. static const struct hda_controller_ops pci_hda_ops;
  1461. static int azx_create(struct snd_card *card, struct pci_dev *pci,
  1462. int dev, unsigned int driver_caps,
  1463. struct azx **rchip)
  1464. {
  1465. static struct snd_device_ops ops = {
  1466. .dev_disconnect = azx_dev_disconnect,
  1467. .dev_free = azx_dev_free,
  1468. };
  1469. struct hda_intel *hda;
  1470. struct azx *chip;
  1471. int err;
  1472. *rchip = NULL;
  1473. err = pci_enable_device(pci);
  1474. if (err < 0)
  1475. return err;
  1476. hda = kzalloc(sizeof(*hda), GFP_KERNEL);
  1477. if (!hda) {
  1478. pci_disable_device(pci);
  1479. return -ENOMEM;
  1480. }
  1481. chip = &hda->chip;
  1482. mutex_init(&chip->open_mutex);
  1483. chip->card = card;
  1484. chip->pci = pci;
  1485. chip->ops = &pci_hda_ops;
  1486. chip->driver_caps = driver_caps;
  1487. chip->driver_type = driver_caps & 0xff;
  1488. check_msi(chip);
  1489. chip->dev_index = dev;
  1490. chip->jackpoll_ms = jackpoll_ms;
  1491. INIT_LIST_HEAD(&chip->pcm_list);
  1492. INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);
  1493. INIT_LIST_HEAD(&hda->list);
  1494. init_vga_switcheroo(chip);
  1495. init_completion(&hda->probe_wait);
  1496. assign_position_fix(chip, check_position_fix(chip, position_fix[dev]));
  1497. check_probe_mask(chip, dev);
  1498. if (single_cmd < 0) /* allow fallback to single_cmd at errors */
  1499. chip->fallback_to_single_cmd = 1;
  1500. else /* explicitly set to single_cmd or not */
  1501. chip->single_cmd = single_cmd;
  1502. azx_check_snoop_available(chip);
  1503. if (bdl_pos_adj[dev] < 0)
  1504. chip->bdl_pos_adj = default_bdl_pos_adj(chip);
  1505. else
  1506. chip->bdl_pos_adj = bdl_pos_adj[dev];
  1507. err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
  1508. if (err < 0) {
  1509. kfree(hda);
  1510. pci_disable_device(pci);
  1511. return err;
  1512. }
  1513. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  1514. dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
  1515. chip->bus.needs_damn_long_delay = 1;
  1516. }
  1517. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  1518. if (err < 0) {
  1519. dev_err(card->dev, "Error creating device [card]!\n");
  1520. azx_free(chip);
  1521. return err;
  1522. }
  1523. /* continue probing in work context as may trigger request module */
  1524. INIT_WORK(&hda->probe_work, azx_probe_work);
  1525. *rchip = chip;
  1526. return 0;
  1527. }
  1528. static int azx_first_init(struct azx *chip)
  1529. {
  1530. int dev = chip->dev_index;
  1531. struct pci_dev *pci = chip->pci;
  1532. struct snd_card *card = chip->card;
  1533. struct hdac_bus *bus = azx_bus(chip);
  1534. int err;
  1535. unsigned short gcap;
  1536. unsigned int dma_bits = 64;
  1537. #if BITS_PER_LONG != 64
  1538. /* Fix up base address on ULI M5461 */
  1539. if (chip->driver_type == AZX_DRIVER_ULI) {
  1540. u16 tmp3;
  1541. pci_read_config_word(pci, 0x40, &tmp3);
  1542. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  1543. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  1544. }
  1545. #endif
  1546. err = pci_request_regions(pci, "ICH HD audio");
  1547. if (err < 0)
  1548. return err;
  1549. chip->region_requested = 1;
  1550. bus->addr = pci_resource_start(pci, 0);
  1551. bus->remap_addr = pci_ioremap_bar(pci, 0);
  1552. if (bus->remap_addr == NULL) {
  1553. dev_err(card->dev, "ioremap error\n");
  1554. return -ENXIO;
  1555. }
  1556. if (IS_SKL_PLUS(pci))
  1557. snd_hdac_bus_parse_capabilities(bus);
  1558. /*
  1559. * Some Intel CPUs has always running timer (ART) feature and
  1560. * controller may have Global time sync reporting capability, so
  1561. * check both of these before declaring synchronized time reporting
  1562. * capability SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME
  1563. */
  1564. chip->gts_present = false;
  1565. #ifdef CONFIG_X86
  1566. if (bus->ppcap && boot_cpu_has(X86_FEATURE_ART))
  1567. chip->gts_present = true;
  1568. #endif
  1569. if (chip->msi) {
  1570. if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
  1571. dev_dbg(card->dev, "Disabling 64bit MSI\n");
  1572. pci->no_64bit_msi = true;
  1573. }
  1574. if (pci_enable_msi(pci) < 0)
  1575. chip->msi = 0;
  1576. }
  1577. if (azx_acquire_irq(chip, 0) < 0)
  1578. return -EBUSY;
  1579. pci_set_master(pci);
  1580. synchronize_irq(bus->irq);
  1581. gcap = azx_readw(chip, GCAP);
  1582. dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
  1583. /* AMD devices support 40 or 48bit DMA, take the safe one */
  1584. if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
  1585. dma_bits = 40;
  1586. /* disable SB600 64bit support for safety */
  1587. if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
  1588. struct pci_dev *p_smbus;
  1589. dma_bits = 40;
  1590. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  1591. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  1592. NULL);
  1593. if (p_smbus) {
  1594. if (p_smbus->revision < 0x30)
  1595. gcap &= ~AZX_GCAP_64OK;
  1596. pci_dev_put(p_smbus);
  1597. }
  1598. }
  1599. /* NVidia hardware normally only supports up to 40 bits of DMA */
  1600. if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
  1601. dma_bits = 40;
  1602. /* disable 64bit DMA address on some devices */
  1603. if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
  1604. dev_dbg(card->dev, "Disabling 64bit DMA\n");
  1605. gcap &= ~AZX_GCAP_64OK;
  1606. }
  1607. /* disable buffer size rounding to 128-byte multiples if supported */
  1608. if (align_buffer_size >= 0)
  1609. chip->align_buffer_size = !!align_buffer_size;
  1610. else {
  1611. if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
  1612. chip->align_buffer_size = 0;
  1613. else
  1614. chip->align_buffer_size = 1;
  1615. }
  1616. /* allow 64bit DMA address if supported by H/W */
  1617. if (!(gcap & AZX_GCAP_64OK))
  1618. dma_bits = 32;
  1619. if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) {
  1620. dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits));
  1621. } else {
  1622. dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
  1623. dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32));
  1624. }
  1625. /* read number of streams from GCAP register instead of using
  1626. * hardcoded value
  1627. */
  1628. chip->capture_streams = (gcap >> 8) & 0x0f;
  1629. chip->playback_streams = (gcap >> 12) & 0x0f;
  1630. if (!chip->playback_streams && !chip->capture_streams) {
  1631. /* gcap didn't give any info, switching to old method */
  1632. switch (chip->driver_type) {
  1633. case AZX_DRIVER_ULI:
  1634. chip->playback_streams = ULI_NUM_PLAYBACK;
  1635. chip->capture_streams = ULI_NUM_CAPTURE;
  1636. break;
  1637. case AZX_DRIVER_ATIHDMI:
  1638. case AZX_DRIVER_ATIHDMI_NS:
  1639. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  1640. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  1641. break;
  1642. case AZX_DRIVER_GENERIC:
  1643. default:
  1644. chip->playback_streams = ICH6_NUM_PLAYBACK;
  1645. chip->capture_streams = ICH6_NUM_CAPTURE;
  1646. break;
  1647. }
  1648. }
  1649. chip->capture_index_offset = 0;
  1650. chip->playback_index_offset = chip->capture_streams;
  1651. chip->num_streams = chip->playback_streams + chip->capture_streams;
  1652. /* sanity check for the SDxCTL.STRM field overflow */
  1653. if (chip->num_streams > 15 &&
  1654. (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) == 0) {
  1655. dev_warn(chip->card->dev, "number of I/O streams is %d, "
  1656. "forcing separate stream tags", chip->num_streams);
  1657. chip->driver_caps |= AZX_DCAPS_SEPARATE_STREAM_TAG;
  1658. }
  1659. /* initialize streams */
  1660. err = azx_init_streams(chip);
  1661. if (err < 0)
  1662. return err;
  1663. err = azx_alloc_stream_pages(chip);
  1664. if (err < 0)
  1665. return err;
  1666. /* initialize chip */
  1667. azx_init_pci(chip);
  1668. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  1669. snd_hdac_i915_set_bclk(bus);
  1670. hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
  1671. /* codec detection */
  1672. if (!azx_bus(chip)->codec_mask) {
  1673. dev_err(card->dev, "no codecs found!\n");
  1674. return -ENODEV;
  1675. }
  1676. strcpy(card->driver, "HDA-Intel");
  1677. strlcpy(card->shortname, driver_short_names[chip->driver_type],
  1678. sizeof(card->shortname));
  1679. snprintf(card->longname, sizeof(card->longname),
  1680. "%s at 0x%lx irq %i",
  1681. card->shortname, bus->addr, bus->irq);
  1682. return 0;
  1683. }
  1684. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1685. /* callback from request_firmware_nowait() */
  1686. static void azx_firmware_cb(const struct firmware *fw, void *context)
  1687. {
  1688. struct snd_card *card = context;
  1689. struct azx *chip = card->private_data;
  1690. struct pci_dev *pci = chip->pci;
  1691. if (!fw) {
  1692. dev_err(card->dev, "Cannot load firmware, aborting\n");
  1693. goto error;
  1694. }
  1695. chip->fw = fw;
  1696. if (!chip->disabled) {
  1697. /* continue probing */
  1698. if (azx_probe_continue(chip))
  1699. goto error;
  1700. }
  1701. return; /* OK */
  1702. error:
  1703. snd_card_free(card);
  1704. pci_set_drvdata(pci, NULL);
  1705. }
  1706. #endif
  1707. /*
  1708. * HDA controller ops.
  1709. */
  1710. /* PCI register access. */
  1711. static void pci_azx_writel(u32 value, u32 __iomem *addr)
  1712. {
  1713. writel(value, addr);
  1714. }
  1715. static u32 pci_azx_readl(u32 __iomem *addr)
  1716. {
  1717. return readl(addr);
  1718. }
  1719. static void pci_azx_writew(u16 value, u16 __iomem *addr)
  1720. {
  1721. writew(value, addr);
  1722. }
  1723. static u16 pci_azx_readw(u16 __iomem *addr)
  1724. {
  1725. return readw(addr);
  1726. }
  1727. static void pci_azx_writeb(u8 value, u8 __iomem *addr)
  1728. {
  1729. writeb(value, addr);
  1730. }
  1731. static u8 pci_azx_readb(u8 __iomem *addr)
  1732. {
  1733. return readb(addr);
  1734. }
  1735. static int disable_msi_reset_irq(struct azx *chip)
  1736. {
  1737. struct hdac_bus *bus = azx_bus(chip);
  1738. int err;
  1739. free_irq(bus->irq, chip);
  1740. bus->irq = -1;
  1741. pci_disable_msi(chip->pci);
  1742. chip->msi = 0;
  1743. err = azx_acquire_irq(chip, 1);
  1744. if (err < 0)
  1745. return err;
  1746. return 0;
  1747. }
  1748. /* DMA page allocation helpers. */
  1749. static int dma_alloc_pages(struct hdac_bus *bus,
  1750. int type,
  1751. size_t size,
  1752. struct snd_dma_buffer *buf)
  1753. {
  1754. struct azx *chip = bus_to_azx(bus);
  1755. int err;
  1756. err = snd_dma_alloc_pages(type,
  1757. bus->dev,
  1758. size, buf);
  1759. if (err < 0)
  1760. return err;
  1761. mark_pages_wc(chip, buf, true);
  1762. return 0;
  1763. }
  1764. static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
  1765. {
  1766. struct azx *chip = bus_to_azx(bus);
  1767. mark_pages_wc(chip, buf, false);
  1768. snd_dma_free_pages(buf);
  1769. }
  1770. static int substream_alloc_pages(struct azx *chip,
  1771. struct snd_pcm_substream *substream,
  1772. size_t size)
  1773. {
  1774. struct azx_dev *azx_dev = get_azx_dev(substream);
  1775. int ret;
  1776. mark_runtime_wc(chip, azx_dev, substream, false);
  1777. ret = snd_pcm_lib_malloc_pages(substream, size);
  1778. if (ret < 0)
  1779. return ret;
  1780. mark_runtime_wc(chip, azx_dev, substream, true);
  1781. return 0;
  1782. }
  1783. static int substream_free_pages(struct azx *chip,
  1784. struct snd_pcm_substream *substream)
  1785. {
  1786. struct azx_dev *azx_dev = get_azx_dev(substream);
  1787. mark_runtime_wc(chip, azx_dev, substream, false);
  1788. return snd_pcm_lib_free_pages(substream);
  1789. }
  1790. static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
  1791. struct vm_area_struct *area)
  1792. {
  1793. #ifdef CONFIG_X86
  1794. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1795. struct azx *chip = apcm->chip;
  1796. if (!azx_snoop(chip) && chip->driver_type != AZX_DRIVER_CMEDIA)
  1797. area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
  1798. #endif
  1799. }
  1800. static const struct hdac_io_ops pci_hda_io_ops = {
  1801. .reg_writel = pci_azx_writel,
  1802. .reg_readl = pci_azx_readl,
  1803. .reg_writew = pci_azx_writew,
  1804. .reg_readw = pci_azx_readw,
  1805. .reg_writeb = pci_azx_writeb,
  1806. .reg_readb = pci_azx_readb,
  1807. .dma_alloc_pages = dma_alloc_pages,
  1808. .dma_free_pages = dma_free_pages,
  1809. };
  1810. static const struct hda_controller_ops pci_hda_ops = {
  1811. .disable_msi_reset_irq = disable_msi_reset_irq,
  1812. .substream_alloc_pages = substream_alloc_pages,
  1813. .substream_free_pages = substream_free_pages,
  1814. .pcm_mmap_prepare = pcm_mmap_prepare,
  1815. .position_check = azx_position_check,
  1816. .link_power = azx_intel_link_power,
  1817. };
  1818. static int azx_probe(struct pci_dev *pci,
  1819. const struct pci_device_id *pci_id)
  1820. {
  1821. static int dev;
  1822. struct snd_card *card;
  1823. struct hda_intel *hda;
  1824. struct azx *chip;
  1825. bool schedule_probe;
  1826. int err;
  1827. if (dev >= SNDRV_CARDS)
  1828. return -ENODEV;
  1829. if (!enable[dev]) {
  1830. dev++;
  1831. return -ENOENT;
  1832. }
  1833. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  1834. 0, &card);
  1835. if (err < 0) {
  1836. dev_err(&pci->dev, "Error creating card!\n");
  1837. return err;
  1838. }
  1839. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  1840. if (err < 0)
  1841. goto out_free;
  1842. card->private_data = chip;
  1843. hda = container_of(chip, struct hda_intel, chip);
  1844. pci_set_drvdata(pci, card);
  1845. err = register_vga_switcheroo(chip);
  1846. if (err < 0) {
  1847. dev_err(card->dev, "Error registering vga_switcheroo client\n");
  1848. goto out_free;
  1849. }
  1850. if (check_hdmi_disabled(pci)) {
  1851. dev_info(card->dev, "VGA controller is disabled\n");
  1852. dev_info(card->dev, "Delaying initialization\n");
  1853. chip->disabled = true;
  1854. }
  1855. schedule_probe = !chip->disabled;
  1856. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1857. if (patch[dev] && *patch[dev]) {
  1858. dev_info(card->dev, "Applying patch firmware '%s'\n",
  1859. patch[dev]);
  1860. err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
  1861. &pci->dev, GFP_KERNEL, card,
  1862. azx_firmware_cb);
  1863. if (err < 0)
  1864. goto out_free;
  1865. schedule_probe = false; /* continued in azx_firmware_cb() */
  1866. }
  1867. #endif /* CONFIG_SND_HDA_PATCH_LOADER */
  1868. #ifndef CONFIG_SND_HDA_I915
  1869. if (CONTROLLER_IN_GPU(pci))
  1870. dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n");
  1871. #endif
  1872. if (schedule_probe)
  1873. schedule_work(&hda->probe_work);
  1874. dev++;
  1875. if (chip->disabled)
  1876. complete_all(&hda->probe_wait);
  1877. return 0;
  1878. out_free:
  1879. snd_card_free(card);
  1880. return err;
  1881. }
  1882. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1883. static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
  1884. [AZX_DRIVER_NVIDIA] = 8,
  1885. [AZX_DRIVER_TERA] = 1,
  1886. };
  1887. static int azx_probe_continue(struct azx *chip)
  1888. {
  1889. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1890. struct hdac_bus *bus = azx_bus(chip);
  1891. struct pci_dev *pci = chip->pci;
  1892. int dev = chip->dev_index;
  1893. int err;
  1894. hda->probe_continued = 1;
  1895. /* Request display power well for the HDA controller or codec. For
  1896. * Haswell/Broadwell, both the display HDA controller and codec need
  1897. * this power. For other platforms, like Baytrail/Braswell, only the
  1898. * display codec needs the power and it can be released after probe.
  1899. */
  1900. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1901. /* HSW/BDW controllers need this power */
  1902. if (CONTROLLER_IN_GPU(pci))
  1903. hda->need_i915_power = 1;
  1904. err = snd_hdac_i915_init(bus);
  1905. if (err < 0) {
  1906. /* if the controller is bound only with HDMI/DP
  1907. * (for HSW and BDW), we need to abort the probe;
  1908. * for other chips, still continue probing as other
  1909. * codecs can be on the same link.
  1910. */
  1911. if (CONTROLLER_IN_GPU(pci)) {
  1912. dev_err(chip->card->dev,
  1913. "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
  1914. goto out_free;
  1915. } else
  1916. goto skip_i915;
  1917. }
  1918. err = snd_hdac_display_power(bus, true);
  1919. if (err < 0) {
  1920. dev_err(chip->card->dev,
  1921. "Cannot turn on display power on i915\n");
  1922. goto i915_power_fail;
  1923. }
  1924. }
  1925. skip_i915:
  1926. err = azx_first_init(chip);
  1927. if (err < 0)
  1928. goto out_free;
  1929. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1930. chip->beep_mode = beep_mode[dev];
  1931. #endif
  1932. /* create codec instances */
  1933. err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
  1934. if (err < 0)
  1935. goto out_free;
  1936. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1937. if (chip->fw) {
  1938. err = snd_hda_load_patch(&chip->bus, chip->fw->size,
  1939. chip->fw->data);
  1940. if (err < 0)
  1941. goto out_free;
  1942. #ifndef CONFIG_PM
  1943. release_firmware(chip->fw); /* no longer needed */
  1944. chip->fw = NULL;
  1945. #endif
  1946. }
  1947. #endif
  1948. if ((probe_only[dev] & 1) == 0) {
  1949. err = azx_codec_configure(chip);
  1950. if (err < 0)
  1951. goto out_free;
  1952. }
  1953. err = snd_card_register(chip->card);
  1954. if (err < 0)
  1955. goto out_free;
  1956. chip->running = 1;
  1957. azx_add_card_list(chip);
  1958. snd_hda_set_power_save(&chip->bus, power_save * 1000);
  1959. if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo)
  1960. pm_runtime_put_autosuspend(&pci->dev);
  1961. out_free:
  1962. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
  1963. && !hda->need_i915_power)
  1964. snd_hdac_display_power(bus, false);
  1965. i915_power_fail:
  1966. if (err < 0)
  1967. hda->init_failed = 1;
  1968. complete_all(&hda->probe_wait);
  1969. return err;
  1970. }
  1971. static void azx_remove(struct pci_dev *pci)
  1972. {
  1973. struct snd_card *card = pci_get_drvdata(pci);
  1974. struct azx *chip;
  1975. struct hda_intel *hda;
  1976. if (card) {
  1977. /* cancel the pending probing work */
  1978. chip = card->private_data;
  1979. hda = container_of(chip, struct hda_intel, chip);
  1980. /* FIXME: below is an ugly workaround.
  1981. * Both device_release_driver() and driver_probe_device()
  1982. * take *both* the device's and its parent's lock before
  1983. * calling the remove() and probe() callbacks. The codec
  1984. * probe takes the locks of both the codec itself and its
  1985. * parent, i.e. the PCI controller dev. Meanwhile, when
  1986. * the PCI controller is unbound, it takes its lock, too
  1987. * ==> ouch, a deadlock!
  1988. * As a workaround, we unlock temporarily here the controller
  1989. * device during cancel_work_sync() call.
  1990. */
  1991. device_unlock(&pci->dev);
  1992. cancel_work_sync(&hda->probe_work);
  1993. device_lock(&pci->dev);
  1994. snd_card_free(card);
  1995. }
  1996. }
  1997. static void azx_shutdown(struct pci_dev *pci)
  1998. {
  1999. struct snd_card *card = pci_get_drvdata(pci);
  2000. struct azx *chip;
  2001. if (!card)
  2002. return;
  2003. chip = card->private_data;
  2004. if (chip && chip->running)
  2005. azx_stop_chip(chip);
  2006. }
  2007. /* PCI IDs */
  2008. static const struct pci_device_id azx_ids[] = {
  2009. /* CPT */
  2010. { PCI_DEVICE(0x8086, 0x1c20),
  2011. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2012. /* PBG */
  2013. { PCI_DEVICE(0x8086, 0x1d20),
  2014. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2015. /* Panther Point */
  2016. { PCI_DEVICE(0x8086, 0x1e20),
  2017. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2018. /* Lynx Point */
  2019. { PCI_DEVICE(0x8086, 0x8c20),
  2020. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2021. /* 9 Series */
  2022. { PCI_DEVICE(0x8086, 0x8ca0),
  2023. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2024. /* Wellsburg */
  2025. { PCI_DEVICE(0x8086, 0x8d20),
  2026. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2027. { PCI_DEVICE(0x8086, 0x8d21),
  2028. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2029. /* Lewisburg */
  2030. { PCI_DEVICE(0x8086, 0xa1f0),
  2031. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2032. { PCI_DEVICE(0x8086, 0xa270),
  2033. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2034. /* Lynx Point-LP */
  2035. { PCI_DEVICE(0x8086, 0x9c20),
  2036. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2037. /* Lynx Point-LP */
  2038. { PCI_DEVICE(0x8086, 0x9c21),
  2039. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2040. /* Wildcat Point-LP */
  2041. { PCI_DEVICE(0x8086, 0x9ca0),
  2042. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2043. /* Sunrise Point */
  2044. { PCI_DEVICE(0x8086, 0xa170),
  2045. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2046. /* Sunrise Point-LP */
  2047. { PCI_DEVICE(0x8086, 0x9d70),
  2048. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2049. /* Kabylake */
  2050. { PCI_DEVICE(0x8086, 0xa171),
  2051. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2052. /* Kabylake-LP */
  2053. { PCI_DEVICE(0x8086, 0x9d71),
  2054. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2055. /* Kabylake-H */
  2056. { PCI_DEVICE(0x8086, 0xa2f0),
  2057. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2058. /* Coffelake */
  2059. { PCI_DEVICE(0x8086, 0xa348),
  2060. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE},
  2061. /* Broxton-P(Apollolake) */
  2062. { PCI_DEVICE(0x8086, 0x5a98),
  2063. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
  2064. /* Broxton-T */
  2065. { PCI_DEVICE(0x8086, 0x1a98),
  2066. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
  2067. /* Gemini-Lake */
  2068. { PCI_DEVICE(0x8086, 0x3198),
  2069. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
  2070. /* Haswell */
  2071. { PCI_DEVICE(0x8086, 0x0a0c),
  2072. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2073. { PCI_DEVICE(0x8086, 0x0c0c),
  2074. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2075. { PCI_DEVICE(0x8086, 0x0d0c),
  2076. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2077. /* Broadwell */
  2078. { PCI_DEVICE(0x8086, 0x160c),
  2079. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_BROADWELL },
  2080. /* 5 Series/3400 */
  2081. { PCI_DEVICE(0x8086, 0x3b56),
  2082. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2083. /* Poulsbo */
  2084. { PCI_DEVICE(0x8086, 0x811b),
  2085. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE },
  2086. /* Oaktrail */
  2087. { PCI_DEVICE(0x8086, 0x080a),
  2088. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE },
  2089. /* BayTrail */
  2090. { PCI_DEVICE(0x8086, 0x0f04),
  2091. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL },
  2092. /* Braswell */
  2093. { PCI_DEVICE(0x8086, 0x2284),
  2094. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL },
  2095. /* ICH6 */
  2096. { PCI_DEVICE(0x8086, 0x2668),
  2097. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2098. /* ICH7 */
  2099. { PCI_DEVICE(0x8086, 0x27d8),
  2100. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2101. /* ESB2 */
  2102. { PCI_DEVICE(0x8086, 0x269a),
  2103. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2104. /* ICH8 */
  2105. { PCI_DEVICE(0x8086, 0x284b),
  2106. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2107. /* ICH9 */
  2108. { PCI_DEVICE(0x8086, 0x293e),
  2109. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2110. /* ICH9 */
  2111. { PCI_DEVICE(0x8086, 0x293f),
  2112. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2113. /* ICH10 */
  2114. { PCI_DEVICE(0x8086, 0x3a3e),
  2115. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2116. /* ICH10 */
  2117. { PCI_DEVICE(0x8086, 0x3a6e),
  2118. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2119. /* Generic Intel */
  2120. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
  2121. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2122. .class_mask = 0xffffff,
  2123. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
  2124. /* ATI SB 450/600/700/800/900 */
  2125. { PCI_DEVICE(0x1002, 0x437b),
  2126. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2127. { PCI_DEVICE(0x1002, 0x4383),
  2128. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2129. /* AMD Hudson */
  2130. { PCI_DEVICE(0x1022, 0x780d),
  2131. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
  2132. /* ATI HDMI */
  2133. { PCI_DEVICE(0x1002, 0x0002),
  2134. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2135. { PCI_DEVICE(0x1002, 0x1308),
  2136. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2137. { PCI_DEVICE(0x1002, 0x157a),
  2138. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2139. { PCI_DEVICE(0x1002, 0x15b3),
  2140. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2141. { PCI_DEVICE(0x1002, 0x793b),
  2142. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2143. { PCI_DEVICE(0x1002, 0x7919),
  2144. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2145. { PCI_DEVICE(0x1002, 0x960f),
  2146. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2147. { PCI_DEVICE(0x1002, 0x970f),
  2148. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2149. { PCI_DEVICE(0x1002, 0x9840),
  2150. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2151. { PCI_DEVICE(0x1002, 0xaa00),
  2152. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2153. { PCI_DEVICE(0x1002, 0xaa08),
  2154. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2155. { PCI_DEVICE(0x1002, 0xaa10),
  2156. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2157. { PCI_DEVICE(0x1002, 0xaa18),
  2158. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2159. { PCI_DEVICE(0x1002, 0xaa20),
  2160. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2161. { PCI_DEVICE(0x1002, 0xaa28),
  2162. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2163. { PCI_DEVICE(0x1002, 0xaa30),
  2164. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2165. { PCI_DEVICE(0x1002, 0xaa38),
  2166. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2167. { PCI_DEVICE(0x1002, 0xaa40),
  2168. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2169. { PCI_DEVICE(0x1002, 0xaa48),
  2170. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2171. { PCI_DEVICE(0x1002, 0xaa50),
  2172. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2173. { PCI_DEVICE(0x1002, 0xaa58),
  2174. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2175. { PCI_DEVICE(0x1002, 0xaa60),
  2176. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2177. { PCI_DEVICE(0x1002, 0xaa68),
  2178. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2179. { PCI_DEVICE(0x1002, 0xaa80),
  2180. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2181. { PCI_DEVICE(0x1002, 0xaa88),
  2182. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2183. { PCI_DEVICE(0x1002, 0xaa90),
  2184. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2185. { PCI_DEVICE(0x1002, 0xaa98),
  2186. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2187. { PCI_DEVICE(0x1002, 0x9902),
  2188. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2189. { PCI_DEVICE(0x1002, 0xaaa0),
  2190. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2191. { PCI_DEVICE(0x1002, 0xaaa8),
  2192. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2193. { PCI_DEVICE(0x1002, 0xaab0),
  2194. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2195. { PCI_DEVICE(0x1002, 0xaac0),
  2196. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2197. { PCI_DEVICE(0x1002, 0xaac8),
  2198. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2199. { PCI_DEVICE(0x1002, 0xaad8),
  2200. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2201. { PCI_DEVICE(0x1002, 0xaae8),
  2202. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2203. { PCI_DEVICE(0x1002, 0xaae0),
  2204. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2205. { PCI_DEVICE(0x1002, 0xaaf0),
  2206. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2207. /* VIA VT8251/VT8237A */
  2208. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2209. /* VIA GFX VT7122/VX900 */
  2210. { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
  2211. /* VIA GFX VT6122/VX11 */
  2212. { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
  2213. /* SIS966 */
  2214. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2215. /* ULI M5461 */
  2216. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2217. /* NVIDIA MCP */
  2218. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2219. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2220. .class_mask = 0xffffff,
  2221. .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
  2222. /* Teradici */
  2223. { PCI_DEVICE(0x6549, 0x1200),
  2224. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2225. { PCI_DEVICE(0x6549, 0x2200),
  2226. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2227. /* Creative X-Fi (CA0110-IBG) */
  2228. /* CTHDA chips */
  2229. { PCI_DEVICE(0x1102, 0x0010),
  2230. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2231. { PCI_DEVICE(0x1102, 0x0012),
  2232. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2233. #if !IS_ENABLED(CONFIG_SND_CTXFI)
  2234. /* the following entry conflicts with snd-ctxfi driver,
  2235. * as ctxfi driver mutates from HD-audio to native mode with
  2236. * a special command sequence.
  2237. */
  2238. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2239. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2240. .class_mask = 0xffffff,
  2241. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2242. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2243. #else
  2244. /* this entry seems still valid -- i.e. without emu20kx chip */
  2245. { PCI_DEVICE(0x1102, 0x0009),
  2246. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2247. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2248. #endif
  2249. /* CM8888 */
  2250. { PCI_DEVICE(0x13f6, 0x5011),
  2251. .driver_data = AZX_DRIVER_CMEDIA |
  2252. AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
  2253. /* Vortex86MX */
  2254. { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
  2255. /* VMware HDAudio */
  2256. { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
  2257. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2258. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2259. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2260. .class_mask = 0xffffff,
  2261. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2262. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2263. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2264. .class_mask = 0xffffff,
  2265. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2266. { 0, }
  2267. };
  2268. MODULE_DEVICE_TABLE(pci, azx_ids);
  2269. /* pci_driver definition */
  2270. static struct pci_driver azx_driver = {
  2271. .name = KBUILD_MODNAME,
  2272. .id_table = azx_ids,
  2273. .probe = azx_probe,
  2274. .remove = azx_remove,
  2275. .shutdown = azx_shutdown,
  2276. .driver = {
  2277. .pm = AZX_PM_OPS,
  2278. },
  2279. };
  2280. module_pci_driver(azx_driver);