hda_intel.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691
  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. static bool pm_blacklist = true;
  172. module_param(pm_blacklist, bool, 0644);
  173. MODULE_PARM_DESC(pm_blacklist, "Enable power-management blacklist");
  174. /* reset the HD-audio controller in power save mode.
  175. * this may give more power-saving, but will take longer time to
  176. * wake up.
  177. */
  178. static bool power_save_controller = 1;
  179. module_param(power_save_controller, bool, 0644);
  180. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  181. #else
  182. #define power_save 0
  183. #endif /* CONFIG_PM */
  184. static int align_buffer_size = -1;
  185. module_param(align_buffer_size, bint, 0644);
  186. MODULE_PARM_DESC(align_buffer_size,
  187. "Force buffer and period sizes to be multiple of 128 bytes.");
  188. #ifdef CONFIG_X86
  189. static int hda_snoop = -1;
  190. module_param_named(snoop, hda_snoop, bint, 0444);
  191. MODULE_PARM_DESC(snoop, "Enable/disable snooping");
  192. #else
  193. #define hda_snoop true
  194. #endif
  195. MODULE_LICENSE("GPL");
  196. MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
  197. "{Intel, ICH6M},"
  198. "{Intel, ICH7},"
  199. "{Intel, ESB2},"
  200. "{Intel, ICH8},"
  201. "{Intel, ICH9},"
  202. "{Intel, ICH10},"
  203. "{Intel, PCH},"
  204. "{Intel, CPT},"
  205. "{Intel, PPT},"
  206. "{Intel, LPT},"
  207. "{Intel, LPT_LP},"
  208. "{Intel, WPT_LP},"
  209. "{Intel, SPT},"
  210. "{Intel, SPT_LP},"
  211. "{Intel, HPT},"
  212. "{Intel, PBG},"
  213. "{Intel, SCH},"
  214. "{ATI, SB450},"
  215. "{ATI, SB600},"
  216. "{ATI, RS600},"
  217. "{ATI, RS690},"
  218. "{ATI, RS780},"
  219. "{ATI, R600},"
  220. "{ATI, RV630},"
  221. "{ATI, RV610},"
  222. "{ATI, RV670},"
  223. "{ATI, RV635},"
  224. "{ATI, RV620},"
  225. "{ATI, RV770},"
  226. "{VIA, VT8251},"
  227. "{VIA, VT8237A},"
  228. "{SiS, SIS966},"
  229. "{ULI, M5461}}");
  230. MODULE_DESCRIPTION("Intel HDA driver");
  231. #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
  232. #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
  233. #define SUPPORT_VGA_SWITCHEROO
  234. #endif
  235. #endif
  236. /*
  237. */
  238. /* driver types */
  239. enum {
  240. AZX_DRIVER_ICH,
  241. AZX_DRIVER_PCH,
  242. AZX_DRIVER_SCH,
  243. AZX_DRIVER_SKL,
  244. AZX_DRIVER_HDMI,
  245. AZX_DRIVER_ATI,
  246. AZX_DRIVER_ATIHDMI,
  247. AZX_DRIVER_ATIHDMI_NS,
  248. AZX_DRIVER_VIA,
  249. AZX_DRIVER_SIS,
  250. AZX_DRIVER_ULI,
  251. AZX_DRIVER_NVIDIA,
  252. AZX_DRIVER_TERA,
  253. AZX_DRIVER_CTX,
  254. AZX_DRIVER_CTHDA,
  255. AZX_DRIVER_CMEDIA,
  256. AZX_DRIVER_GENERIC,
  257. AZX_NUM_DRIVERS, /* keep this as last entry */
  258. };
  259. #define azx_get_snoop_type(chip) \
  260. (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
  261. #define AZX_DCAPS_SNOOP_TYPE(type) ((AZX_SNOOP_TYPE_ ## type) << 10)
  262. /* quirks for old Intel chipsets */
  263. #define AZX_DCAPS_INTEL_ICH \
  264. (AZX_DCAPS_OLD_SSYNC | AZX_DCAPS_NO_ALIGN_BUFSIZE)
  265. /* quirks for Intel PCH */
  266. #define AZX_DCAPS_INTEL_PCH_BASE \
  267. (AZX_DCAPS_NO_ALIGN_BUFSIZE | AZX_DCAPS_COUNT_LPIB_DELAY |\
  268. AZX_DCAPS_SNOOP_TYPE(SCH))
  269. /* PCH up to IVB; no runtime PM; bind with i915 gfx */
  270. #define AZX_DCAPS_INTEL_PCH_NOPM \
  271. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT)
  272. /* PCH for HSW/BDW; with runtime PM */
  273. /* no i915 binding for this as HSW/BDW has another controller for HDMI */
  274. #define AZX_DCAPS_INTEL_PCH \
  275. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME)
  276. /* HSW HDMI */
  277. #define AZX_DCAPS_INTEL_HASWELL \
  278. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
  279. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
  280. AZX_DCAPS_I915_POWERWELL | AZX_DCAPS_SNOOP_TYPE(SCH))
  281. /* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
  282. #define AZX_DCAPS_INTEL_BROADWELL \
  283. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
  284. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
  285. AZX_DCAPS_I915_POWERWELL | AZX_DCAPS_SNOOP_TYPE(SCH))
  286. #define AZX_DCAPS_INTEL_BAYTRAIL \
  287. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT |\
  288. AZX_DCAPS_I915_POWERWELL)
  289. #define AZX_DCAPS_INTEL_BRASWELL \
  290. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
  291. AZX_DCAPS_I915_COMPONENT | AZX_DCAPS_I915_POWERWELL)
  292. #define AZX_DCAPS_INTEL_SKYLAKE \
  293. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
  294. AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT |\
  295. AZX_DCAPS_I915_POWERWELL)
  296. #define AZX_DCAPS_INTEL_BROXTON \
  297. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
  298. AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT |\
  299. AZX_DCAPS_I915_POWERWELL)
  300. /* quirks for ATI SB / AMD Hudson */
  301. #define AZX_DCAPS_PRESET_ATI_SB \
  302. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB |\
  303. AZX_DCAPS_SNOOP_TYPE(ATI))
  304. /* quirks for ATI/AMD HDMI */
  305. #define AZX_DCAPS_PRESET_ATI_HDMI \
  306. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\
  307. AZX_DCAPS_NO_MSI64)
  308. /* quirks for ATI HDMI with snoop off */
  309. #define AZX_DCAPS_PRESET_ATI_HDMI_NS \
  310. (AZX_DCAPS_PRESET_ATI_HDMI | AZX_DCAPS_SNOOP_OFF)
  311. /* quirks for Nvidia */
  312. #define AZX_DCAPS_PRESET_NVIDIA \
  313. (AZX_DCAPS_NO_MSI | AZX_DCAPS_CORBRP_SELF_CLEAR |\
  314. AZX_DCAPS_SNOOP_TYPE(NVIDIA))
  315. #define AZX_DCAPS_PRESET_CTHDA \
  316. (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB |\
  317. AZX_DCAPS_NO_64BIT |\
  318. AZX_DCAPS_4K_BDLE_BOUNDARY | AZX_DCAPS_SNOOP_OFF)
  319. /*
  320. * vga_switcheroo support
  321. */
  322. #ifdef SUPPORT_VGA_SWITCHEROO
  323. #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
  324. #else
  325. #define use_vga_switcheroo(chip) 0
  326. #endif
  327. #define CONTROLLER_IN_GPU(pci) (((pci)->device == 0x0a0c) || \
  328. ((pci)->device == 0x0c0c) || \
  329. ((pci)->device == 0x0d0c) || \
  330. ((pci)->device == 0x160c))
  331. #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
  332. #define IS_CFL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa348)
  333. static char *driver_short_names[] = {
  334. [AZX_DRIVER_ICH] = "HDA Intel",
  335. [AZX_DRIVER_PCH] = "HDA Intel PCH",
  336. [AZX_DRIVER_SCH] = "HDA Intel MID",
  337. [AZX_DRIVER_SKL] = "HDA Intel PCH", /* kept old name for compatibility */
  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 (chip->driver_type == AZX_DRIVER_SKL) {
  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 (chip->driver_type == AZX_DRIVER_SKL) {
  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. #ifdef CONFIG_PM_SLEEP
  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. /* put codec down to D3 at hibernation for Intel SKL+;
  939. * otherwise BIOS may still access the codec and screw up the driver
  940. */
  941. static int azx_freeze_noirq(struct device *dev)
  942. {
  943. struct snd_card *card = dev_get_drvdata(dev);
  944. struct azx *chip = card->private_data;
  945. struct pci_dev *pci = to_pci_dev(dev);
  946. if (chip->driver_type == AZX_DRIVER_SKL)
  947. pci_set_power_state(pci, PCI_D3hot);
  948. return 0;
  949. }
  950. static int azx_thaw_noirq(struct device *dev)
  951. {
  952. struct snd_card *card = dev_get_drvdata(dev);
  953. struct azx *chip = card->private_data;
  954. struct pci_dev *pci = to_pci_dev(dev);
  955. if (chip->driver_type == AZX_DRIVER_SKL)
  956. pci_set_power_state(pci, PCI_D0);
  957. return 0;
  958. }
  959. #endif /* CONFIG_PM_SLEEP */
  960. #ifdef CONFIG_PM
  961. static int azx_runtime_suspend(struct device *dev)
  962. {
  963. struct snd_card *card = dev_get_drvdata(dev);
  964. struct azx *chip;
  965. struct hda_intel *hda;
  966. if (!card)
  967. return 0;
  968. chip = card->private_data;
  969. hda = container_of(chip, struct hda_intel, chip);
  970. if (chip->disabled || hda->init_failed)
  971. return 0;
  972. if (!azx_has_pm_runtime(chip))
  973. return 0;
  974. /* enable controller wake up event */
  975. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
  976. STATESTS_INT_MASK);
  977. azx_stop_chip(chip);
  978. azx_enter_link_reset(chip);
  979. azx_clear_irq_pending(chip);
  980. if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  981. && hda->need_i915_power)
  982. snd_hdac_display_power(azx_bus(chip), false);
  983. trace_azx_runtime_suspend(chip);
  984. return 0;
  985. }
  986. static int azx_runtime_resume(struct device *dev)
  987. {
  988. struct snd_card *card = dev_get_drvdata(dev);
  989. struct azx *chip;
  990. struct hda_intel *hda;
  991. struct hdac_bus *bus;
  992. struct hda_codec *codec;
  993. int status;
  994. if (!card)
  995. return 0;
  996. chip = card->private_data;
  997. hda = container_of(chip, struct hda_intel, chip);
  998. bus = azx_bus(chip);
  999. if (chip->disabled || hda->init_failed)
  1000. return 0;
  1001. if (!azx_has_pm_runtime(chip))
  1002. return 0;
  1003. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1004. snd_hdac_display_power(bus, true);
  1005. if (hda->need_i915_power)
  1006. snd_hdac_i915_set_bclk(bus);
  1007. }
  1008. /* Read STATESTS before controller reset */
  1009. status = azx_readw(chip, STATESTS);
  1010. azx_init_pci(chip);
  1011. hda_intel_init_chip(chip, true);
  1012. if (status) {
  1013. list_for_each_codec(codec, &chip->bus)
  1014. if (status & (1 << codec->addr))
  1015. schedule_delayed_work(&codec->jackpoll_work,
  1016. codec->jackpoll_interval);
  1017. }
  1018. /* disable controller Wake Up event*/
  1019. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
  1020. ~STATESTS_INT_MASK);
  1021. /* power down again for link-controlled chips */
  1022. if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
  1023. !hda->need_i915_power)
  1024. snd_hdac_display_power(bus, false);
  1025. trace_azx_runtime_resume(chip);
  1026. return 0;
  1027. }
  1028. static int azx_runtime_idle(struct device *dev)
  1029. {
  1030. struct snd_card *card = dev_get_drvdata(dev);
  1031. struct azx *chip;
  1032. struct hda_intel *hda;
  1033. if (!card)
  1034. return 0;
  1035. chip = card->private_data;
  1036. hda = container_of(chip, struct hda_intel, chip);
  1037. if (chip->disabled || hda->init_failed)
  1038. return 0;
  1039. if (!power_save_controller || !azx_has_pm_runtime(chip) ||
  1040. azx_bus(chip)->codec_powered || !chip->running)
  1041. return -EBUSY;
  1042. return 0;
  1043. }
  1044. static const struct dev_pm_ops azx_pm = {
  1045. SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
  1046. #ifdef CONFIG_PM_SLEEP
  1047. .freeze_noirq = azx_freeze_noirq,
  1048. .thaw_noirq = azx_thaw_noirq,
  1049. #endif
  1050. SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
  1051. };
  1052. #define AZX_PM_OPS &azx_pm
  1053. #else
  1054. #define AZX_PM_OPS NULL
  1055. #endif /* CONFIG_PM */
  1056. static int azx_probe_continue(struct azx *chip);
  1057. #ifdef SUPPORT_VGA_SWITCHEROO
  1058. static struct pci_dev *get_bound_vga(struct pci_dev *pci);
  1059. static void azx_vs_set_state(struct pci_dev *pci,
  1060. enum vga_switcheroo_state state)
  1061. {
  1062. struct snd_card *card = pci_get_drvdata(pci);
  1063. struct azx *chip = card->private_data;
  1064. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1065. struct hda_codec *codec;
  1066. bool disabled;
  1067. wait_for_completion(&hda->probe_wait);
  1068. if (hda->init_failed)
  1069. return;
  1070. disabled = (state == VGA_SWITCHEROO_OFF);
  1071. if (chip->disabled == disabled)
  1072. return;
  1073. if (!hda->probe_continued) {
  1074. chip->disabled = disabled;
  1075. if (!disabled) {
  1076. dev_info(chip->card->dev,
  1077. "Start delayed initialization\n");
  1078. if (azx_probe_continue(chip) < 0) {
  1079. dev_err(chip->card->dev, "initialization error\n");
  1080. hda->init_failed = true;
  1081. }
  1082. }
  1083. } else {
  1084. dev_info(chip->card->dev, "%s via vga_switcheroo\n",
  1085. disabled ? "Disabling" : "Enabling");
  1086. if (disabled) {
  1087. list_for_each_codec(codec, &chip->bus) {
  1088. pm_runtime_suspend(hda_codec_dev(codec));
  1089. pm_runtime_disable(hda_codec_dev(codec));
  1090. }
  1091. pm_runtime_suspend(card->dev);
  1092. pm_runtime_disable(card->dev);
  1093. /* when we get suspended by vga_switcheroo we end up in D3cold,
  1094. * however we have no ACPI handle, so pci/acpi can't put us there,
  1095. * put ourselves there */
  1096. pci->current_state = PCI_D3cold;
  1097. chip->disabled = true;
  1098. if (snd_hda_lock_devices(&chip->bus))
  1099. dev_warn(chip->card->dev,
  1100. "Cannot lock devices!\n");
  1101. } else {
  1102. snd_hda_unlock_devices(&chip->bus);
  1103. chip->disabled = false;
  1104. pm_runtime_enable(card->dev);
  1105. list_for_each_codec(codec, &chip->bus) {
  1106. pm_runtime_enable(hda_codec_dev(codec));
  1107. pm_runtime_resume(hda_codec_dev(codec));
  1108. }
  1109. }
  1110. }
  1111. }
  1112. static bool azx_vs_can_switch(struct pci_dev *pci)
  1113. {
  1114. struct snd_card *card = pci_get_drvdata(pci);
  1115. struct azx *chip = card->private_data;
  1116. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1117. wait_for_completion(&hda->probe_wait);
  1118. if (hda->init_failed)
  1119. return false;
  1120. if (chip->disabled || !hda->probe_continued)
  1121. return true;
  1122. if (snd_hda_lock_devices(&chip->bus))
  1123. return false;
  1124. snd_hda_unlock_devices(&chip->bus);
  1125. return true;
  1126. }
  1127. static void init_vga_switcheroo(struct azx *chip)
  1128. {
  1129. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1130. struct pci_dev *p = get_bound_vga(chip->pci);
  1131. if (p) {
  1132. dev_info(chip->card->dev,
  1133. "Handle vga_switcheroo audio client\n");
  1134. hda->use_vga_switcheroo = 1;
  1135. chip->driver_caps |= AZX_DCAPS_PM_RUNTIME;
  1136. pci_dev_put(p);
  1137. }
  1138. }
  1139. static const struct vga_switcheroo_client_ops azx_vs_ops = {
  1140. .set_gpu_state = azx_vs_set_state,
  1141. .can_switch = azx_vs_can_switch,
  1142. };
  1143. static int register_vga_switcheroo(struct azx *chip)
  1144. {
  1145. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1146. struct pci_dev *p;
  1147. int err;
  1148. if (!hda->use_vga_switcheroo)
  1149. return 0;
  1150. p = get_bound_vga(chip->pci);
  1151. err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, p);
  1152. pci_dev_put(p);
  1153. if (err < 0)
  1154. return err;
  1155. hda->vga_switcheroo_registered = 1;
  1156. return 0;
  1157. }
  1158. #else
  1159. #define init_vga_switcheroo(chip) /* NOP */
  1160. #define register_vga_switcheroo(chip) 0
  1161. #define check_hdmi_disabled(pci) false
  1162. #endif /* SUPPORT_VGA_SWITCHER */
  1163. /*
  1164. * destructor
  1165. */
  1166. static int azx_free(struct azx *chip)
  1167. {
  1168. struct pci_dev *pci = chip->pci;
  1169. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1170. struct hdac_bus *bus = azx_bus(chip);
  1171. if (azx_has_pm_runtime(chip) && chip->running)
  1172. pm_runtime_get_noresume(&pci->dev);
  1173. azx_del_card_list(chip);
  1174. hda->init_failed = 1; /* to be sure */
  1175. complete_all(&hda->probe_wait);
  1176. if (use_vga_switcheroo(hda)) {
  1177. if (chip->disabled && hda->probe_continued)
  1178. snd_hda_unlock_devices(&chip->bus);
  1179. if (hda->vga_switcheroo_registered)
  1180. vga_switcheroo_unregister_client(chip->pci);
  1181. }
  1182. if (bus->chip_init) {
  1183. azx_clear_irq_pending(chip);
  1184. azx_stop_all_streams(chip);
  1185. azx_stop_chip(chip);
  1186. }
  1187. if (bus->irq >= 0)
  1188. free_irq(bus->irq, (void*)chip);
  1189. if (chip->msi)
  1190. pci_disable_msi(chip->pci);
  1191. iounmap(bus->remap_addr);
  1192. azx_free_stream_pages(chip);
  1193. azx_free_streams(chip);
  1194. snd_hdac_bus_exit(bus);
  1195. if (chip->region_requested)
  1196. pci_release_regions(chip->pci);
  1197. pci_disable_device(chip->pci);
  1198. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1199. release_firmware(chip->fw);
  1200. #endif
  1201. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1202. if (hda->need_i915_power)
  1203. snd_hdac_display_power(bus, false);
  1204. }
  1205. if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
  1206. snd_hdac_i915_exit(bus);
  1207. kfree(hda);
  1208. return 0;
  1209. }
  1210. static int azx_dev_disconnect(struct snd_device *device)
  1211. {
  1212. struct azx *chip = device->device_data;
  1213. chip->bus.shutdown = 1;
  1214. return 0;
  1215. }
  1216. static int azx_dev_free(struct snd_device *device)
  1217. {
  1218. return azx_free(device->device_data);
  1219. }
  1220. #ifdef SUPPORT_VGA_SWITCHEROO
  1221. /*
  1222. * Check of disabled HDMI controller by vga_switcheroo
  1223. */
  1224. static struct pci_dev *get_bound_vga(struct pci_dev *pci)
  1225. {
  1226. struct pci_dev *p;
  1227. /* check only discrete GPU */
  1228. switch (pci->vendor) {
  1229. case PCI_VENDOR_ID_ATI:
  1230. case PCI_VENDOR_ID_AMD:
  1231. case PCI_VENDOR_ID_NVIDIA:
  1232. if (pci->devfn == 1) {
  1233. p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
  1234. pci->bus->number, 0);
  1235. if (p) {
  1236. if ((p->class >> 16) == PCI_BASE_CLASS_DISPLAY)
  1237. return p;
  1238. pci_dev_put(p);
  1239. }
  1240. }
  1241. break;
  1242. }
  1243. return NULL;
  1244. }
  1245. static bool check_hdmi_disabled(struct pci_dev *pci)
  1246. {
  1247. bool vga_inactive = false;
  1248. struct pci_dev *p = get_bound_vga(pci);
  1249. if (p) {
  1250. if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
  1251. vga_inactive = true;
  1252. pci_dev_put(p);
  1253. }
  1254. return vga_inactive;
  1255. }
  1256. #endif /* SUPPORT_VGA_SWITCHEROO */
  1257. /*
  1258. * white/black-listing for position_fix
  1259. */
  1260. static struct snd_pci_quirk position_fix_list[] = {
  1261. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  1262. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  1263. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  1264. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  1265. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  1266. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  1267. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  1268. SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
  1269. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  1270. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  1271. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  1272. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  1273. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  1274. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  1275. {}
  1276. };
  1277. static int check_position_fix(struct azx *chip, int fix)
  1278. {
  1279. const struct snd_pci_quirk *q;
  1280. switch (fix) {
  1281. case POS_FIX_AUTO:
  1282. case POS_FIX_LPIB:
  1283. case POS_FIX_POSBUF:
  1284. case POS_FIX_VIACOMBO:
  1285. case POS_FIX_COMBO:
  1286. case POS_FIX_SKL:
  1287. return fix;
  1288. }
  1289. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  1290. if (q) {
  1291. dev_info(chip->card->dev,
  1292. "position_fix set to %d for device %04x:%04x\n",
  1293. q->value, q->subvendor, q->subdevice);
  1294. return q->value;
  1295. }
  1296. /* Check VIA/ATI HD Audio Controller exist */
  1297. if (chip->driver_type == AZX_DRIVER_VIA) {
  1298. dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
  1299. return POS_FIX_VIACOMBO;
  1300. }
  1301. if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
  1302. dev_dbg(chip->card->dev, "Using LPIB position fix\n");
  1303. return POS_FIX_LPIB;
  1304. }
  1305. if (chip->driver_type == AZX_DRIVER_SKL) {
  1306. dev_dbg(chip->card->dev, "Using SKL position fix\n");
  1307. return POS_FIX_SKL;
  1308. }
  1309. return POS_FIX_AUTO;
  1310. }
  1311. static void assign_position_fix(struct azx *chip, int fix)
  1312. {
  1313. static azx_get_pos_callback_t callbacks[] = {
  1314. [POS_FIX_AUTO] = NULL,
  1315. [POS_FIX_LPIB] = azx_get_pos_lpib,
  1316. [POS_FIX_POSBUF] = azx_get_pos_posbuf,
  1317. [POS_FIX_VIACOMBO] = azx_via_get_position,
  1318. [POS_FIX_COMBO] = azx_get_pos_lpib,
  1319. [POS_FIX_SKL] = azx_get_pos_skl,
  1320. };
  1321. chip->get_position[0] = chip->get_position[1] = callbacks[fix];
  1322. /* combo mode uses LPIB only for playback */
  1323. if (fix == POS_FIX_COMBO)
  1324. chip->get_position[1] = NULL;
  1325. if ((fix == POS_FIX_POSBUF || fix == POS_FIX_SKL) &&
  1326. (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
  1327. chip->get_delay[0] = chip->get_delay[1] =
  1328. azx_get_delay_from_lpib;
  1329. }
  1330. }
  1331. /*
  1332. * black-lists for probe_mask
  1333. */
  1334. static struct snd_pci_quirk probe_mask_list[] = {
  1335. /* Thinkpad often breaks the controller communication when accessing
  1336. * to the non-working (or non-existing) modem codec slot.
  1337. */
  1338. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  1339. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  1340. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  1341. /* broken BIOS */
  1342. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  1343. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  1344. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  1345. /* forced codec slots */
  1346. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  1347. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  1348. /* WinFast VP200 H (Teradici) user reported broken communication */
  1349. SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
  1350. {}
  1351. };
  1352. #define AZX_FORCE_CODEC_MASK 0x100
  1353. static void check_probe_mask(struct azx *chip, int dev)
  1354. {
  1355. const struct snd_pci_quirk *q;
  1356. chip->codec_probe_mask = probe_mask[dev];
  1357. if (chip->codec_probe_mask == -1) {
  1358. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  1359. if (q) {
  1360. dev_info(chip->card->dev,
  1361. "probe_mask set to 0x%x for device %04x:%04x\n",
  1362. q->value, q->subvendor, q->subdevice);
  1363. chip->codec_probe_mask = q->value;
  1364. }
  1365. }
  1366. /* check forced option */
  1367. if (chip->codec_probe_mask != -1 &&
  1368. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  1369. azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff;
  1370. dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
  1371. (int)azx_bus(chip)->codec_mask);
  1372. }
  1373. }
  1374. /*
  1375. * white/black-list for enable_msi
  1376. */
  1377. static struct snd_pci_quirk msi_black_list[] = {
  1378. SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
  1379. SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
  1380. SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
  1381. SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
  1382. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  1383. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  1384. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  1385. SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
  1386. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  1387. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  1388. {}
  1389. };
  1390. static void check_msi(struct azx *chip)
  1391. {
  1392. const struct snd_pci_quirk *q;
  1393. if (enable_msi >= 0) {
  1394. chip->msi = !!enable_msi;
  1395. return;
  1396. }
  1397. chip->msi = 1; /* enable MSI as default */
  1398. q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
  1399. if (q) {
  1400. dev_info(chip->card->dev,
  1401. "msi for device %04x:%04x set to %d\n",
  1402. q->subvendor, q->subdevice, q->value);
  1403. chip->msi = q->value;
  1404. return;
  1405. }
  1406. /* NVidia chipsets seem to cause troubles with MSI */
  1407. if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
  1408. dev_info(chip->card->dev, "Disabling MSI\n");
  1409. chip->msi = 0;
  1410. }
  1411. }
  1412. /* check the snoop mode availability */
  1413. static void azx_check_snoop_available(struct azx *chip)
  1414. {
  1415. int snoop = hda_snoop;
  1416. if (snoop >= 0) {
  1417. dev_info(chip->card->dev, "Force to %s mode by module option\n",
  1418. snoop ? "snoop" : "non-snoop");
  1419. chip->snoop = snoop;
  1420. return;
  1421. }
  1422. snoop = true;
  1423. if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
  1424. chip->driver_type == AZX_DRIVER_VIA) {
  1425. /* force to non-snoop mode for a new VIA controller
  1426. * when BIOS is set
  1427. */
  1428. u8 val;
  1429. pci_read_config_byte(chip->pci, 0x42, &val);
  1430. if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
  1431. chip->pci->revision == 0x20))
  1432. snoop = false;
  1433. }
  1434. if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
  1435. snoop = false;
  1436. chip->snoop = snoop;
  1437. if (!snoop)
  1438. dev_info(chip->card->dev, "Force to non-snoop mode\n");
  1439. }
  1440. static void azx_probe_work(struct work_struct *work)
  1441. {
  1442. struct hda_intel *hda = container_of(work, struct hda_intel, probe_work);
  1443. azx_probe_continue(&hda->chip);
  1444. }
  1445. static int default_bdl_pos_adj(struct azx *chip)
  1446. {
  1447. /* some exceptions: Atoms seem problematic with value 1 */
  1448. if (chip->pci->vendor == PCI_VENDOR_ID_INTEL) {
  1449. switch (chip->pci->device) {
  1450. case 0x0f04: /* Baytrail */
  1451. case 0x2284: /* Braswell */
  1452. return 32;
  1453. }
  1454. }
  1455. switch (chip->driver_type) {
  1456. case AZX_DRIVER_ICH:
  1457. case AZX_DRIVER_PCH:
  1458. return 1;
  1459. default:
  1460. return 32;
  1461. }
  1462. }
  1463. /*
  1464. * constructor
  1465. */
  1466. static const struct hdac_io_ops pci_hda_io_ops;
  1467. static const struct hda_controller_ops pci_hda_ops;
  1468. static int azx_create(struct snd_card *card, struct pci_dev *pci,
  1469. int dev, unsigned int driver_caps,
  1470. struct azx **rchip)
  1471. {
  1472. static struct snd_device_ops ops = {
  1473. .dev_disconnect = azx_dev_disconnect,
  1474. .dev_free = azx_dev_free,
  1475. };
  1476. struct hda_intel *hda;
  1477. struct azx *chip;
  1478. int err;
  1479. *rchip = NULL;
  1480. err = pci_enable_device(pci);
  1481. if (err < 0)
  1482. return err;
  1483. hda = kzalloc(sizeof(*hda), GFP_KERNEL);
  1484. if (!hda) {
  1485. pci_disable_device(pci);
  1486. return -ENOMEM;
  1487. }
  1488. chip = &hda->chip;
  1489. mutex_init(&chip->open_mutex);
  1490. chip->card = card;
  1491. chip->pci = pci;
  1492. chip->ops = &pci_hda_ops;
  1493. chip->driver_caps = driver_caps;
  1494. chip->driver_type = driver_caps & 0xff;
  1495. check_msi(chip);
  1496. chip->dev_index = dev;
  1497. chip->jackpoll_ms = jackpoll_ms;
  1498. INIT_LIST_HEAD(&chip->pcm_list);
  1499. INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);
  1500. INIT_LIST_HEAD(&hda->list);
  1501. init_vga_switcheroo(chip);
  1502. init_completion(&hda->probe_wait);
  1503. assign_position_fix(chip, check_position_fix(chip, position_fix[dev]));
  1504. check_probe_mask(chip, dev);
  1505. if (single_cmd < 0) /* allow fallback to single_cmd at errors */
  1506. chip->fallback_to_single_cmd = 1;
  1507. else /* explicitly set to single_cmd or not */
  1508. chip->single_cmd = single_cmd;
  1509. azx_check_snoop_available(chip);
  1510. if (bdl_pos_adj[dev] < 0)
  1511. chip->bdl_pos_adj = default_bdl_pos_adj(chip);
  1512. else
  1513. chip->bdl_pos_adj = bdl_pos_adj[dev];
  1514. /* Workaround for a communication error on CFL (bko#199007) */
  1515. if (IS_CFL(pci))
  1516. chip->polling_mode = 1;
  1517. err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
  1518. if (err < 0) {
  1519. kfree(hda);
  1520. pci_disable_device(pci);
  1521. return err;
  1522. }
  1523. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  1524. dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
  1525. chip->bus.needs_damn_long_delay = 1;
  1526. }
  1527. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  1528. if (err < 0) {
  1529. dev_err(card->dev, "Error creating device [card]!\n");
  1530. azx_free(chip);
  1531. return err;
  1532. }
  1533. /* continue probing in work context as may trigger request module */
  1534. INIT_WORK(&hda->probe_work, azx_probe_work);
  1535. *rchip = chip;
  1536. return 0;
  1537. }
  1538. static int azx_first_init(struct azx *chip)
  1539. {
  1540. int dev = chip->dev_index;
  1541. struct pci_dev *pci = chip->pci;
  1542. struct snd_card *card = chip->card;
  1543. struct hdac_bus *bus = azx_bus(chip);
  1544. int err;
  1545. unsigned short gcap;
  1546. unsigned int dma_bits = 64;
  1547. #if BITS_PER_LONG != 64
  1548. /* Fix up base address on ULI M5461 */
  1549. if (chip->driver_type == AZX_DRIVER_ULI) {
  1550. u16 tmp3;
  1551. pci_read_config_word(pci, 0x40, &tmp3);
  1552. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  1553. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  1554. }
  1555. #endif
  1556. err = pci_request_regions(pci, "ICH HD audio");
  1557. if (err < 0)
  1558. return err;
  1559. chip->region_requested = 1;
  1560. bus->addr = pci_resource_start(pci, 0);
  1561. bus->remap_addr = pci_ioremap_bar(pci, 0);
  1562. if (bus->remap_addr == NULL) {
  1563. dev_err(card->dev, "ioremap error\n");
  1564. return -ENXIO;
  1565. }
  1566. if (chip->driver_type == AZX_DRIVER_SKL)
  1567. snd_hdac_bus_parse_capabilities(bus);
  1568. /*
  1569. * Some Intel CPUs has always running timer (ART) feature and
  1570. * controller may have Global time sync reporting capability, so
  1571. * check both of these before declaring synchronized time reporting
  1572. * capability SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME
  1573. */
  1574. chip->gts_present = false;
  1575. #ifdef CONFIG_X86
  1576. if (bus->ppcap && boot_cpu_has(X86_FEATURE_ART))
  1577. chip->gts_present = true;
  1578. #endif
  1579. if (chip->msi) {
  1580. if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
  1581. dev_dbg(card->dev, "Disabling 64bit MSI\n");
  1582. pci->no_64bit_msi = true;
  1583. }
  1584. if (pci_enable_msi(pci) < 0)
  1585. chip->msi = 0;
  1586. }
  1587. if (azx_acquire_irq(chip, 0) < 0)
  1588. return -EBUSY;
  1589. pci_set_master(pci);
  1590. synchronize_irq(bus->irq);
  1591. gcap = azx_readw(chip, GCAP);
  1592. dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
  1593. /* AMD devices support 40 or 48bit DMA, take the safe one */
  1594. if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
  1595. dma_bits = 40;
  1596. /* disable SB600 64bit support for safety */
  1597. if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
  1598. struct pci_dev *p_smbus;
  1599. dma_bits = 40;
  1600. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  1601. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  1602. NULL);
  1603. if (p_smbus) {
  1604. if (p_smbus->revision < 0x30)
  1605. gcap &= ~AZX_GCAP_64OK;
  1606. pci_dev_put(p_smbus);
  1607. }
  1608. }
  1609. /* NVidia hardware normally only supports up to 40 bits of DMA */
  1610. if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
  1611. dma_bits = 40;
  1612. /* disable 64bit DMA address on some devices */
  1613. if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
  1614. dev_dbg(card->dev, "Disabling 64bit DMA\n");
  1615. gcap &= ~AZX_GCAP_64OK;
  1616. }
  1617. /* disable buffer size rounding to 128-byte multiples if supported */
  1618. if (align_buffer_size >= 0)
  1619. chip->align_buffer_size = !!align_buffer_size;
  1620. else {
  1621. if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
  1622. chip->align_buffer_size = 0;
  1623. else
  1624. chip->align_buffer_size = 1;
  1625. }
  1626. /* allow 64bit DMA address if supported by H/W */
  1627. if (!(gcap & AZX_GCAP_64OK))
  1628. dma_bits = 32;
  1629. if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) {
  1630. dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits));
  1631. } else {
  1632. dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
  1633. dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32));
  1634. }
  1635. /* read number of streams from GCAP register instead of using
  1636. * hardcoded value
  1637. */
  1638. chip->capture_streams = (gcap >> 8) & 0x0f;
  1639. chip->playback_streams = (gcap >> 12) & 0x0f;
  1640. if (!chip->playback_streams && !chip->capture_streams) {
  1641. /* gcap didn't give any info, switching to old method */
  1642. switch (chip->driver_type) {
  1643. case AZX_DRIVER_ULI:
  1644. chip->playback_streams = ULI_NUM_PLAYBACK;
  1645. chip->capture_streams = ULI_NUM_CAPTURE;
  1646. break;
  1647. case AZX_DRIVER_ATIHDMI:
  1648. case AZX_DRIVER_ATIHDMI_NS:
  1649. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  1650. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  1651. break;
  1652. case AZX_DRIVER_GENERIC:
  1653. default:
  1654. chip->playback_streams = ICH6_NUM_PLAYBACK;
  1655. chip->capture_streams = ICH6_NUM_CAPTURE;
  1656. break;
  1657. }
  1658. }
  1659. chip->capture_index_offset = 0;
  1660. chip->playback_index_offset = chip->capture_streams;
  1661. chip->num_streams = chip->playback_streams + chip->capture_streams;
  1662. /* sanity check for the SDxCTL.STRM field overflow */
  1663. if (chip->num_streams > 15 &&
  1664. (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) == 0) {
  1665. dev_warn(chip->card->dev, "number of I/O streams is %d, "
  1666. "forcing separate stream tags", chip->num_streams);
  1667. chip->driver_caps |= AZX_DCAPS_SEPARATE_STREAM_TAG;
  1668. }
  1669. /* initialize streams */
  1670. err = azx_init_streams(chip);
  1671. if (err < 0)
  1672. return err;
  1673. err = azx_alloc_stream_pages(chip);
  1674. if (err < 0)
  1675. return err;
  1676. /* initialize chip */
  1677. azx_init_pci(chip);
  1678. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  1679. snd_hdac_i915_set_bclk(bus);
  1680. hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
  1681. /* codec detection */
  1682. if (!azx_bus(chip)->codec_mask) {
  1683. dev_err(card->dev, "no codecs found!\n");
  1684. return -ENODEV;
  1685. }
  1686. strcpy(card->driver, "HDA-Intel");
  1687. strlcpy(card->shortname, driver_short_names[chip->driver_type],
  1688. sizeof(card->shortname));
  1689. snprintf(card->longname, sizeof(card->longname),
  1690. "%s at 0x%lx irq %i",
  1691. card->shortname, bus->addr, bus->irq);
  1692. return 0;
  1693. }
  1694. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1695. /* callback from request_firmware_nowait() */
  1696. static void azx_firmware_cb(const struct firmware *fw, void *context)
  1697. {
  1698. struct snd_card *card = context;
  1699. struct azx *chip = card->private_data;
  1700. struct pci_dev *pci = chip->pci;
  1701. if (!fw) {
  1702. dev_err(card->dev, "Cannot load firmware, aborting\n");
  1703. goto error;
  1704. }
  1705. chip->fw = fw;
  1706. if (!chip->disabled) {
  1707. /* continue probing */
  1708. if (azx_probe_continue(chip))
  1709. goto error;
  1710. }
  1711. return; /* OK */
  1712. error:
  1713. snd_card_free(card);
  1714. pci_set_drvdata(pci, NULL);
  1715. }
  1716. #endif
  1717. /*
  1718. * HDA controller ops.
  1719. */
  1720. /* PCI register access. */
  1721. static void pci_azx_writel(u32 value, u32 __iomem *addr)
  1722. {
  1723. writel(value, addr);
  1724. }
  1725. static u32 pci_azx_readl(u32 __iomem *addr)
  1726. {
  1727. return readl(addr);
  1728. }
  1729. static void pci_azx_writew(u16 value, u16 __iomem *addr)
  1730. {
  1731. writew(value, addr);
  1732. }
  1733. static u16 pci_azx_readw(u16 __iomem *addr)
  1734. {
  1735. return readw(addr);
  1736. }
  1737. static void pci_azx_writeb(u8 value, u8 __iomem *addr)
  1738. {
  1739. writeb(value, addr);
  1740. }
  1741. static u8 pci_azx_readb(u8 __iomem *addr)
  1742. {
  1743. return readb(addr);
  1744. }
  1745. static int disable_msi_reset_irq(struct azx *chip)
  1746. {
  1747. struct hdac_bus *bus = azx_bus(chip);
  1748. int err;
  1749. free_irq(bus->irq, chip);
  1750. bus->irq = -1;
  1751. pci_disable_msi(chip->pci);
  1752. chip->msi = 0;
  1753. err = azx_acquire_irq(chip, 1);
  1754. if (err < 0)
  1755. return err;
  1756. return 0;
  1757. }
  1758. /* DMA page allocation helpers. */
  1759. static int dma_alloc_pages(struct hdac_bus *bus,
  1760. int type,
  1761. size_t size,
  1762. struct snd_dma_buffer *buf)
  1763. {
  1764. struct azx *chip = bus_to_azx(bus);
  1765. int err;
  1766. err = snd_dma_alloc_pages(type,
  1767. bus->dev,
  1768. size, buf);
  1769. if (err < 0)
  1770. return err;
  1771. mark_pages_wc(chip, buf, true);
  1772. return 0;
  1773. }
  1774. static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
  1775. {
  1776. struct azx *chip = bus_to_azx(bus);
  1777. mark_pages_wc(chip, buf, false);
  1778. snd_dma_free_pages(buf);
  1779. }
  1780. static int substream_alloc_pages(struct azx *chip,
  1781. struct snd_pcm_substream *substream,
  1782. size_t size)
  1783. {
  1784. struct azx_dev *azx_dev = get_azx_dev(substream);
  1785. int ret;
  1786. mark_runtime_wc(chip, azx_dev, substream, false);
  1787. ret = snd_pcm_lib_malloc_pages(substream, size);
  1788. if (ret < 0)
  1789. return ret;
  1790. mark_runtime_wc(chip, azx_dev, substream, true);
  1791. return 0;
  1792. }
  1793. static int substream_free_pages(struct azx *chip,
  1794. struct snd_pcm_substream *substream)
  1795. {
  1796. struct azx_dev *azx_dev = get_azx_dev(substream);
  1797. mark_runtime_wc(chip, azx_dev, substream, false);
  1798. return snd_pcm_lib_free_pages(substream);
  1799. }
  1800. static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
  1801. struct vm_area_struct *area)
  1802. {
  1803. #ifdef CONFIG_X86
  1804. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1805. struct azx *chip = apcm->chip;
  1806. if (!azx_snoop(chip) && chip->driver_type != AZX_DRIVER_CMEDIA)
  1807. area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
  1808. #endif
  1809. }
  1810. static const struct hdac_io_ops pci_hda_io_ops = {
  1811. .reg_writel = pci_azx_writel,
  1812. .reg_readl = pci_azx_readl,
  1813. .reg_writew = pci_azx_writew,
  1814. .reg_readw = pci_azx_readw,
  1815. .reg_writeb = pci_azx_writeb,
  1816. .reg_readb = pci_azx_readb,
  1817. .dma_alloc_pages = dma_alloc_pages,
  1818. .dma_free_pages = dma_free_pages,
  1819. };
  1820. static const struct hda_controller_ops pci_hda_ops = {
  1821. .disable_msi_reset_irq = disable_msi_reset_irq,
  1822. .substream_alloc_pages = substream_alloc_pages,
  1823. .substream_free_pages = substream_free_pages,
  1824. .pcm_mmap_prepare = pcm_mmap_prepare,
  1825. .position_check = azx_position_check,
  1826. .link_power = azx_intel_link_power,
  1827. };
  1828. static int azx_probe(struct pci_dev *pci,
  1829. const struct pci_device_id *pci_id)
  1830. {
  1831. static int dev;
  1832. struct snd_card *card;
  1833. struct hda_intel *hda;
  1834. struct azx *chip;
  1835. bool schedule_probe;
  1836. int err;
  1837. if (dev >= SNDRV_CARDS)
  1838. return -ENODEV;
  1839. if (!enable[dev]) {
  1840. dev++;
  1841. return -ENOENT;
  1842. }
  1843. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  1844. 0, &card);
  1845. if (err < 0) {
  1846. dev_err(&pci->dev, "Error creating card!\n");
  1847. return err;
  1848. }
  1849. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  1850. if (err < 0)
  1851. goto out_free;
  1852. card->private_data = chip;
  1853. hda = container_of(chip, struct hda_intel, chip);
  1854. pci_set_drvdata(pci, card);
  1855. err = register_vga_switcheroo(chip);
  1856. if (err < 0) {
  1857. dev_err(card->dev, "Error registering vga_switcheroo client\n");
  1858. goto out_free;
  1859. }
  1860. if (check_hdmi_disabled(pci)) {
  1861. dev_info(card->dev, "VGA controller is disabled\n");
  1862. dev_info(card->dev, "Delaying initialization\n");
  1863. chip->disabled = true;
  1864. }
  1865. schedule_probe = !chip->disabled;
  1866. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1867. if (patch[dev] && *patch[dev]) {
  1868. dev_info(card->dev, "Applying patch firmware '%s'\n",
  1869. patch[dev]);
  1870. err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
  1871. &pci->dev, GFP_KERNEL, card,
  1872. azx_firmware_cb);
  1873. if (err < 0)
  1874. goto out_free;
  1875. schedule_probe = false; /* continued in azx_firmware_cb() */
  1876. }
  1877. #endif /* CONFIG_SND_HDA_PATCH_LOADER */
  1878. #ifndef CONFIG_SND_HDA_I915
  1879. if (CONTROLLER_IN_GPU(pci))
  1880. dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n");
  1881. #endif
  1882. if (schedule_probe)
  1883. schedule_work(&hda->probe_work);
  1884. dev++;
  1885. if (chip->disabled)
  1886. complete_all(&hda->probe_wait);
  1887. return 0;
  1888. out_free:
  1889. snd_card_free(card);
  1890. return err;
  1891. }
  1892. #ifdef CONFIG_PM
  1893. /* On some boards setting power_save to a non 0 value leads to clicking /
  1894. * popping sounds when ever we enter/leave powersaving mode. Ideally we would
  1895. * figure out how to avoid these sounds, but that is not always feasible.
  1896. * So we keep a list of devices where we disable powersaving as its known
  1897. * to causes problems on these devices.
  1898. */
  1899. static struct snd_pci_quirk power_save_blacklist[] = {
  1900. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1901. SND_PCI_QUIRK(0x1849, 0xc892, "Asrock B85M-ITX", 0),
  1902. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1903. SND_PCI_QUIRK(0x1849, 0x7662, "Asrock H81M-HDS", 0),
  1904. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1905. SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
  1906. /* https://bugzilla.redhat.com/show_bug.cgi?id=1581607 */
  1907. SND_PCI_QUIRK(0x1558, 0x3501, "Clevo W35xSS_370SS", 0),
  1908. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1909. /* Note the P55A-UD3 and Z87-D3HP share the subsys id for the HDA dev */
  1910. SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P55A-UD3 / Z87-D3HP", 0),
  1911. /* https://bugzilla.kernel.org/show_bug.cgi?id=199607 */
  1912. SND_PCI_QUIRK(0x8086, 0x2057, "Intel NUC5i7RYB", 0),
  1913. /* https://bugzilla.redhat.com/show_bug.cgi?id=1520902 */
  1914. SND_PCI_QUIRK(0x8086, 0x2068, "Intel NUC7i3BNB", 0),
  1915. /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
  1916. SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
  1917. /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
  1918. SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
  1919. {}
  1920. };
  1921. #endif /* CONFIG_PM */
  1922. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1923. static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
  1924. [AZX_DRIVER_NVIDIA] = 8,
  1925. [AZX_DRIVER_TERA] = 1,
  1926. };
  1927. static int azx_probe_continue(struct azx *chip)
  1928. {
  1929. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1930. struct hdac_bus *bus = azx_bus(chip);
  1931. struct pci_dev *pci = chip->pci;
  1932. struct hda_codec *codec;
  1933. int dev = chip->dev_index;
  1934. int val;
  1935. int err;
  1936. hda->probe_continued = 1;
  1937. /* bind with i915 if needed */
  1938. if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
  1939. err = snd_hdac_i915_init(bus);
  1940. if (err < 0) {
  1941. /* if the controller is bound only with HDMI/DP
  1942. * (for HSW and BDW), we need to abort the probe;
  1943. * for other chips, still continue probing as other
  1944. * codecs can be on the same link.
  1945. */
  1946. if (CONTROLLER_IN_GPU(pci)) {
  1947. dev_err(chip->card->dev,
  1948. "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
  1949. goto out_free;
  1950. } else {
  1951. /* don't bother any longer */
  1952. chip->driver_caps &=
  1953. ~(AZX_DCAPS_I915_COMPONENT | AZX_DCAPS_I915_POWERWELL);
  1954. }
  1955. }
  1956. }
  1957. /* Request display power well for the HDA controller or codec. For
  1958. * Haswell/Broadwell, both the display HDA controller and codec need
  1959. * this power. For other platforms, like Baytrail/Braswell, only the
  1960. * display codec needs the power and it can be released after probe.
  1961. */
  1962. if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
  1963. /* HSW/BDW controllers need this power */
  1964. if (CONTROLLER_IN_GPU(pci))
  1965. hda->need_i915_power = 1;
  1966. err = snd_hdac_display_power(bus, true);
  1967. if (err < 0) {
  1968. dev_err(chip->card->dev,
  1969. "Cannot turn on display power on i915\n");
  1970. goto i915_power_fail;
  1971. }
  1972. }
  1973. err = azx_first_init(chip);
  1974. if (err < 0)
  1975. goto out_free;
  1976. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1977. chip->beep_mode = beep_mode[dev];
  1978. #endif
  1979. /* create codec instances */
  1980. err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
  1981. if (err < 0)
  1982. goto out_free;
  1983. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1984. if (chip->fw) {
  1985. err = snd_hda_load_patch(&chip->bus, chip->fw->size,
  1986. chip->fw->data);
  1987. if (err < 0)
  1988. goto out_free;
  1989. #ifndef CONFIG_PM
  1990. release_firmware(chip->fw); /* no longer needed */
  1991. chip->fw = NULL;
  1992. #endif
  1993. }
  1994. #endif
  1995. if ((probe_only[dev] & 1) == 0) {
  1996. err = azx_codec_configure(chip);
  1997. if (err < 0)
  1998. goto out_free;
  1999. }
  2000. err = snd_card_register(chip->card);
  2001. if (err < 0)
  2002. goto out_free;
  2003. chip->running = 1;
  2004. azx_add_card_list(chip);
  2005. val = power_save;
  2006. #ifdef CONFIG_PM
  2007. if (pm_blacklist) {
  2008. const struct snd_pci_quirk *q;
  2009. q = snd_pci_quirk_lookup(chip->pci, power_save_blacklist);
  2010. if (q && val) {
  2011. dev_info(chip->card->dev, "device %04x:%04x is on the power_save blacklist, forcing power_save to 0\n",
  2012. q->subvendor, q->subdevice);
  2013. val = 0;
  2014. }
  2015. }
  2016. #endif /* CONFIG_PM */
  2017. /*
  2018. * The discrete GPU cannot power down unless the HDA controller runtime
  2019. * suspends, so activate runtime PM on codecs even if power_save == 0.
  2020. */
  2021. if (use_vga_switcheroo(hda))
  2022. list_for_each_codec(codec, &chip->bus)
  2023. codec->auto_runtime_pm = 1;
  2024. snd_hda_set_power_save(&chip->bus, val * 1000);
  2025. if (azx_has_pm_runtime(chip))
  2026. pm_runtime_put_autosuspend(&pci->dev);
  2027. out_free:
  2028. if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
  2029. && !hda->need_i915_power)
  2030. snd_hdac_display_power(bus, false);
  2031. i915_power_fail:
  2032. if (err < 0)
  2033. hda->init_failed = 1;
  2034. complete_all(&hda->probe_wait);
  2035. return err;
  2036. }
  2037. static void azx_remove(struct pci_dev *pci)
  2038. {
  2039. struct snd_card *card = pci_get_drvdata(pci);
  2040. struct azx *chip;
  2041. struct hda_intel *hda;
  2042. if (card) {
  2043. /* cancel the pending probing work */
  2044. chip = card->private_data;
  2045. hda = container_of(chip, struct hda_intel, chip);
  2046. /* FIXME: below is an ugly workaround.
  2047. * Both device_release_driver() and driver_probe_device()
  2048. * take *both* the device's and its parent's lock before
  2049. * calling the remove() and probe() callbacks. The codec
  2050. * probe takes the locks of both the codec itself and its
  2051. * parent, i.e. the PCI controller dev. Meanwhile, when
  2052. * the PCI controller is unbound, it takes its lock, too
  2053. * ==> ouch, a deadlock!
  2054. * As a workaround, we unlock temporarily here the controller
  2055. * device during cancel_work_sync() call.
  2056. */
  2057. device_unlock(&pci->dev);
  2058. cancel_work_sync(&hda->probe_work);
  2059. device_lock(&pci->dev);
  2060. snd_card_free(card);
  2061. }
  2062. }
  2063. static void azx_shutdown(struct pci_dev *pci)
  2064. {
  2065. struct snd_card *card = pci_get_drvdata(pci);
  2066. struct azx *chip;
  2067. if (!card)
  2068. return;
  2069. chip = card->private_data;
  2070. if (chip && chip->running)
  2071. azx_stop_chip(chip);
  2072. }
  2073. /* PCI IDs */
  2074. static const struct pci_device_id azx_ids[] = {
  2075. /* CPT */
  2076. { PCI_DEVICE(0x8086, 0x1c20),
  2077. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2078. /* PBG */
  2079. { PCI_DEVICE(0x8086, 0x1d20),
  2080. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2081. /* Panther Point */
  2082. { PCI_DEVICE(0x8086, 0x1e20),
  2083. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2084. /* Lynx Point */
  2085. { PCI_DEVICE(0x8086, 0x8c20),
  2086. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2087. /* 9 Series */
  2088. { PCI_DEVICE(0x8086, 0x8ca0),
  2089. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2090. /* Wellsburg */
  2091. { PCI_DEVICE(0x8086, 0x8d20),
  2092. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2093. { PCI_DEVICE(0x8086, 0x8d21),
  2094. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2095. /* Lewisburg */
  2096. { PCI_DEVICE(0x8086, 0xa1f0),
  2097. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2098. { PCI_DEVICE(0x8086, 0xa270),
  2099. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
  2100. /* Lynx Point-LP */
  2101. { PCI_DEVICE(0x8086, 0x9c20),
  2102. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2103. /* Lynx Point-LP */
  2104. { PCI_DEVICE(0x8086, 0x9c21),
  2105. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2106. /* Wildcat Point-LP */
  2107. { PCI_DEVICE(0x8086, 0x9ca0),
  2108. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
  2109. /* Sunrise Point */
  2110. { PCI_DEVICE(0x8086, 0xa170),
  2111. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE },
  2112. /* Sunrise Point-LP */
  2113. { PCI_DEVICE(0x8086, 0x9d70),
  2114. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE },
  2115. /* Kabylake */
  2116. { PCI_DEVICE(0x8086, 0xa171),
  2117. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE },
  2118. /* Kabylake-LP */
  2119. { PCI_DEVICE(0x8086, 0x9d71),
  2120. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE },
  2121. /* Kabylake-H */
  2122. { PCI_DEVICE(0x8086, 0xa2f0),
  2123. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE },
  2124. /* Coffelake */
  2125. { PCI_DEVICE(0x8086, 0xa348),
  2126. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
  2127. /* Cannonlake */
  2128. { PCI_DEVICE(0x8086, 0x9dc8),
  2129. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
  2130. /* Icelake */
  2131. { PCI_DEVICE(0x8086, 0x34c8),
  2132. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
  2133. /* Broxton-P(Apollolake) */
  2134. { PCI_DEVICE(0x8086, 0x5a98),
  2135. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_BROXTON },
  2136. /* Broxton-T */
  2137. { PCI_DEVICE(0x8086, 0x1a98),
  2138. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_BROXTON },
  2139. /* Gemini-Lake */
  2140. { PCI_DEVICE(0x8086, 0x3198),
  2141. .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_BROXTON },
  2142. /* Haswell */
  2143. { PCI_DEVICE(0x8086, 0x0a0c),
  2144. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2145. { PCI_DEVICE(0x8086, 0x0c0c),
  2146. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2147. { PCI_DEVICE(0x8086, 0x0d0c),
  2148. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
  2149. /* Broadwell */
  2150. { PCI_DEVICE(0x8086, 0x160c),
  2151. .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_BROADWELL },
  2152. /* 5 Series/3400 */
  2153. { PCI_DEVICE(0x8086, 0x3b56),
  2154. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
  2155. /* Poulsbo */
  2156. { PCI_DEVICE(0x8086, 0x811b),
  2157. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE },
  2158. /* Oaktrail */
  2159. { PCI_DEVICE(0x8086, 0x080a),
  2160. .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE },
  2161. /* BayTrail */
  2162. { PCI_DEVICE(0x8086, 0x0f04),
  2163. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL },
  2164. /* Braswell */
  2165. { PCI_DEVICE(0x8086, 0x2284),
  2166. .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL },
  2167. /* ICH6 */
  2168. { PCI_DEVICE(0x8086, 0x2668),
  2169. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2170. /* ICH7 */
  2171. { PCI_DEVICE(0x8086, 0x27d8),
  2172. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2173. /* ESB2 */
  2174. { PCI_DEVICE(0x8086, 0x269a),
  2175. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2176. /* ICH8 */
  2177. { PCI_DEVICE(0x8086, 0x284b),
  2178. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2179. /* ICH9 */
  2180. { PCI_DEVICE(0x8086, 0x293e),
  2181. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2182. /* ICH9 */
  2183. { PCI_DEVICE(0x8086, 0x293f),
  2184. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2185. /* ICH10 */
  2186. { PCI_DEVICE(0x8086, 0x3a3e),
  2187. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2188. /* ICH10 */
  2189. { PCI_DEVICE(0x8086, 0x3a6e),
  2190. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
  2191. /* Generic Intel */
  2192. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
  2193. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2194. .class_mask = 0xffffff,
  2195. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
  2196. /* ATI SB 450/600/700/800/900 */
  2197. { PCI_DEVICE(0x1002, 0x437b),
  2198. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2199. { PCI_DEVICE(0x1002, 0x4383),
  2200. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2201. /* AMD Hudson */
  2202. { PCI_DEVICE(0x1022, 0x780d),
  2203. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
  2204. /* AMD Raven */
  2205. { PCI_DEVICE(0x1022, 0x15e3),
  2206. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
  2207. AZX_DCAPS_PM_RUNTIME },
  2208. /* ATI HDMI */
  2209. { PCI_DEVICE(0x1002, 0x0002),
  2210. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2211. { PCI_DEVICE(0x1002, 0x1308),
  2212. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2213. { PCI_DEVICE(0x1002, 0x157a),
  2214. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2215. { PCI_DEVICE(0x1002, 0x15b3),
  2216. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2217. { PCI_DEVICE(0x1002, 0x793b),
  2218. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2219. { PCI_DEVICE(0x1002, 0x7919),
  2220. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2221. { PCI_DEVICE(0x1002, 0x960f),
  2222. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2223. { PCI_DEVICE(0x1002, 0x970f),
  2224. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2225. { PCI_DEVICE(0x1002, 0x9840),
  2226. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2227. { PCI_DEVICE(0x1002, 0xaa00),
  2228. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2229. { PCI_DEVICE(0x1002, 0xaa08),
  2230. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2231. { PCI_DEVICE(0x1002, 0xaa10),
  2232. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2233. { PCI_DEVICE(0x1002, 0xaa18),
  2234. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2235. { PCI_DEVICE(0x1002, 0xaa20),
  2236. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2237. { PCI_DEVICE(0x1002, 0xaa28),
  2238. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2239. { PCI_DEVICE(0x1002, 0xaa30),
  2240. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2241. { PCI_DEVICE(0x1002, 0xaa38),
  2242. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2243. { PCI_DEVICE(0x1002, 0xaa40),
  2244. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2245. { PCI_DEVICE(0x1002, 0xaa48),
  2246. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2247. { PCI_DEVICE(0x1002, 0xaa50),
  2248. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2249. { PCI_DEVICE(0x1002, 0xaa58),
  2250. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2251. { PCI_DEVICE(0x1002, 0xaa60),
  2252. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2253. { PCI_DEVICE(0x1002, 0xaa68),
  2254. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2255. { PCI_DEVICE(0x1002, 0xaa80),
  2256. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2257. { PCI_DEVICE(0x1002, 0xaa88),
  2258. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2259. { PCI_DEVICE(0x1002, 0xaa90),
  2260. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2261. { PCI_DEVICE(0x1002, 0xaa98),
  2262. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2263. { PCI_DEVICE(0x1002, 0x9902),
  2264. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2265. { PCI_DEVICE(0x1002, 0xaaa0),
  2266. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2267. { PCI_DEVICE(0x1002, 0xaaa8),
  2268. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2269. { PCI_DEVICE(0x1002, 0xaab0),
  2270. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2271. { PCI_DEVICE(0x1002, 0xaac0),
  2272. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2273. { PCI_DEVICE(0x1002, 0xaac8),
  2274. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2275. { PCI_DEVICE(0x1002, 0xaad8),
  2276. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2277. { PCI_DEVICE(0x1002, 0xaae8),
  2278. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2279. { PCI_DEVICE(0x1002, 0xaae0),
  2280. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2281. { PCI_DEVICE(0x1002, 0xaaf0),
  2282. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2283. /* VIA VT8251/VT8237A */
  2284. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2285. /* VIA GFX VT7122/VX900 */
  2286. { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
  2287. /* VIA GFX VT6122/VX11 */
  2288. { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
  2289. /* SIS966 */
  2290. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2291. /* ULI M5461 */
  2292. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2293. /* NVIDIA MCP */
  2294. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2295. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2296. .class_mask = 0xffffff,
  2297. .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
  2298. /* Teradici */
  2299. { PCI_DEVICE(0x6549, 0x1200),
  2300. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2301. { PCI_DEVICE(0x6549, 0x2200),
  2302. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2303. /* Creative X-Fi (CA0110-IBG) */
  2304. /* CTHDA chips */
  2305. { PCI_DEVICE(0x1102, 0x0010),
  2306. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2307. { PCI_DEVICE(0x1102, 0x0012),
  2308. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2309. #if !IS_ENABLED(CONFIG_SND_CTXFI)
  2310. /* the following entry conflicts with snd-ctxfi driver,
  2311. * as ctxfi driver mutates from HD-audio to native mode with
  2312. * a special command sequence.
  2313. */
  2314. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2315. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2316. .class_mask = 0xffffff,
  2317. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2318. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2319. #else
  2320. /* this entry seems still valid -- i.e. without emu20kx chip */
  2321. { PCI_DEVICE(0x1102, 0x0009),
  2322. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2323. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2324. #endif
  2325. /* CM8888 */
  2326. { PCI_DEVICE(0x13f6, 0x5011),
  2327. .driver_data = AZX_DRIVER_CMEDIA |
  2328. AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
  2329. /* Vortex86MX */
  2330. { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
  2331. /* VMware HDAudio */
  2332. { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
  2333. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2334. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2335. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2336. .class_mask = 0xffffff,
  2337. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2338. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2339. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2340. .class_mask = 0xffffff,
  2341. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2342. { 0, }
  2343. };
  2344. MODULE_DEVICE_TABLE(pci, azx_ids);
  2345. /* pci_driver definition */
  2346. static struct pci_driver azx_driver = {
  2347. .name = KBUILD_MODNAME,
  2348. .id_table = azx_ids,
  2349. .probe = azx_probe,
  2350. .remove = azx_remove,
  2351. .shutdown = azx_shutdown,
  2352. .driver = {
  2353. .pm = AZX_PM_OPS,
  2354. },
  2355. };
  2356. module_pci_driver(azx_driver);