intel.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * hda_intel.c - Implementation of primary alsa driver code base
  5. * for Intel HD Audio.
  6. *
  7. * Copyright(c) 2004 Intel Corporation
  8. *
  9. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  10. * PeiSen Hou <pshou@realtek.com.tw>
  11. *
  12. * CONTACTS:
  13. *
  14. * Matt Jared matt.jared@intel.com
  15. * Andy Kopp andy.kopp@intel.com
  16. * Dan Kogan dan.d.kogan@intel.com
  17. *
  18. * CHANGES:
  19. *
  20. * 2004.12.01 Major rewrite by tiwai, merged the work of pshou
  21. */
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <linux/mutex.h>
  32. #include <linux/io.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/clocksource.h>
  35. #include <linux/time.h>
  36. #include <linux/completion.h>
  37. #include <linux/acpi.h>
  38. #include <linux/pgtable.h>
  39. #include <linux/dmi.h>
  40. #ifdef CONFIG_X86
  41. /* for snoop control */
  42. #include <asm/set_memory.h>
  43. #include <asm/cpufeature.h>
  44. #endif
  45. #include <sound/core.h>
  46. #include <sound/initval.h>
  47. #include <sound/hdaudio.h>
  48. #include <sound/hda_i915.h>
  49. #include <sound/intel-dsp-config.h>
  50. #include <linux/vgaarb.h>
  51. #include <linux/vga_switcheroo.h>
  52. #include <linux/apple-gmux.h>
  53. #include <linux/firmware.h>
  54. #include <sound/hda_codec.h>
  55. #include "intel.h"
  56. #define CREATE_TRACE_POINTS
  57. #include "intel_trace.h"
  58. /* position fix mode */
  59. enum {
  60. POS_FIX_AUTO,
  61. POS_FIX_LPIB,
  62. POS_FIX_POSBUF,
  63. POS_FIX_VIACOMBO,
  64. POS_FIX_COMBO,
  65. POS_FIX_SKL,
  66. POS_FIX_FIFO,
  67. };
  68. /* Defines for ATI HD Audio support in SB450 south bridge */
  69. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  70. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  71. /* Defines for Nvidia HDA support */
  72. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  73. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  74. #define NVIDIA_HDA_ISTRM_COH 0x4d
  75. #define NVIDIA_HDA_OSTRM_COH 0x4c
  76. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  77. /* Defines for Intel SCH HDA snoop control */
  78. #define INTEL_HDA_CGCTL 0x48
  79. #define INTEL_HDA_CGCTL_MISCBDCGE (0x1 << 6)
  80. #define INTEL_SCH_HDA_DEVC 0x78
  81. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  82. /* max number of SDs */
  83. /* ICH, ATI and VIA have 4 playback and 4 capture */
  84. #define ICH6_NUM_CAPTURE 4
  85. #define ICH6_NUM_PLAYBACK 4
  86. /* ULI has 6 playback and 5 capture */
  87. #define ULI_NUM_CAPTURE 5
  88. #define ULI_NUM_PLAYBACK 6
  89. /* ATI HDMI may have up to 8 playbacks and 0 capture */
  90. #define ATIHDMI_NUM_CAPTURE 0
  91. #define ATIHDMI_NUM_PLAYBACK 8
  92. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  93. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  94. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  95. static char *model[SNDRV_CARDS];
  96. static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  97. static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  98. static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  99. static int probe_only[SNDRV_CARDS];
  100. static int jackpoll_ms[SNDRV_CARDS];
  101. static int single_cmd = -1;
  102. static int enable_msi = -1;
  103. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  104. static char *patch[SNDRV_CARDS];
  105. #endif
  106. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  107. static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
  108. CONFIG_SND_HDA_INPUT_BEEP_MODE};
  109. #endif
  110. static bool dmic_detect = 1;
  111. static bool ctl_dev_id = IS_ENABLED(CONFIG_SND_HDA_CTL_DEV_ID) ? 1 : 0;
  112. module_param_array(index, int, NULL, 0444);
  113. MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
  114. module_param_array(id, charp, NULL, 0444);
  115. MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
  116. module_param_array(enable, bool, NULL, 0444);
  117. MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
  118. module_param_array(model, charp, NULL, 0444);
  119. MODULE_PARM_DESC(model, "Use the given board model.");
  120. module_param_array(position_fix, int, NULL, 0444);
  121. MODULE_PARM_DESC(position_fix, "DMA pointer read method."
  122. "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO, 5 = SKL+, 6 = FIFO).");
  123. module_param_array(bdl_pos_adj, int, NULL, 0644);
  124. MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
  125. module_param_array(probe_mask, int, NULL, 0444);
  126. MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
  127. module_param_array(probe_only, int, NULL, 0444);
  128. MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
  129. module_param_array(jackpoll_ms, int, NULL, 0444);
  130. MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)");
  131. module_param(single_cmd, bint, 0444);
  132. MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
  133. "(for debugging only).");
  134. module_param(enable_msi, bint, 0444);
  135. MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
  136. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  137. module_param_array(patch, charp, NULL, 0444);
  138. MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
  139. #endif
  140. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  141. module_param_array(beep_mode, bool, NULL, 0444);
  142. MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
  143. "(0=off, 1=on) (default=1).");
  144. #endif
  145. module_param(dmic_detect, bool, 0444);
  146. MODULE_PARM_DESC(dmic_detect, "Allow DSP driver selection (bypass this driver) "
  147. "(0=off, 1=on) (default=1); "
  148. "deprecated, use snd-intel-dspcfg.dsp_driver option instead");
  149. module_param(ctl_dev_id, bool, 0444);
  150. MODULE_PARM_DESC(ctl_dev_id, "Use control device identifier (based on codec address).");
  151. #ifdef CONFIG_PM
  152. static int param_set_xint(const char *val, const struct kernel_param *kp);
  153. static const struct kernel_param_ops param_ops_xint = {
  154. .set = param_set_xint,
  155. .get = param_get_int,
  156. };
  157. #define param_check_xint param_check_int
  158. static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
  159. module_param(power_save, xint, 0644);
  160. MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
  161. "(in second, 0 = disable).");
  162. static int pm_blacklist = -1;
  163. module_param(pm_blacklist, bint, 0644);
  164. MODULE_PARM_DESC(pm_blacklist, "Enable power-management denylist");
  165. /* reset the HD-audio controller in power save mode.
  166. * this may give more power-saving, but will take longer time to
  167. * wake up.
  168. */
  169. static bool power_save_controller = 1;
  170. module_param(power_save_controller, bool, 0644);
  171. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  172. #else /* CONFIG_PM */
  173. #define power_save 0
  174. #define pm_blacklist 0
  175. #define power_save_controller false
  176. #endif /* CONFIG_PM */
  177. static int align_buffer_size = -1;
  178. module_param(align_buffer_size, bint, 0644);
  179. MODULE_PARM_DESC(align_buffer_size,
  180. "Force buffer and period sizes to be multiple of 128 bytes.");
  181. #ifdef CONFIG_X86
  182. static int hda_snoop = -1;
  183. module_param_named(snoop, hda_snoop, bint, 0444);
  184. MODULE_PARM_DESC(snoop, "Enable/disable snooping");
  185. #else
  186. #define hda_snoop true
  187. #endif
  188. MODULE_LICENSE("GPL");
  189. MODULE_DESCRIPTION("Intel HDA driver");
  190. #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
  191. #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
  192. #define SUPPORT_VGA_SWITCHEROO
  193. #endif
  194. #endif
  195. /*
  196. */
  197. /* driver types */
  198. enum {
  199. AZX_DRIVER_ICH,
  200. AZX_DRIVER_PCH,
  201. AZX_DRIVER_SCH,
  202. AZX_DRIVER_SKL,
  203. AZX_DRIVER_HDMI,
  204. AZX_DRIVER_ATI,
  205. AZX_DRIVER_ATIHDMI,
  206. AZX_DRIVER_ATIHDMI_NS,
  207. AZX_DRIVER_GFHDMI,
  208. AZX_DRIVER_VIA,
  209. AZX_DRIVER_SIS,
  210. AZX_DRIVER_ULI,
  211. AZX_DRIVER_NVIDIA,
  212. AZX_DRIVER_TERA,
  213. AZX_DRIVER_CTX,
  214. AZX_DRIVER_CTHDA,
  215. AZX_DRIVER_CMEDIA,
  216. AZX_DRIVER_ZHAOXIN,
  217. AZX_DRIVER_ZHAOXINHDMI,
  218. AZX_DRIVER_LOONGSON,
  219. AZX_DRIVER_GENERIC,
  220. AZX_NUM_DRIVERS, /* keep this as last entry */
  221. };
  222. #define azx_get_snoop_type(chip) \
  223. (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
  224. #define AZX_DCAPS_SNOOP_TYPE(type) ((AZX_SNOOP_TYPE_ ## type) << 10)
  225. /* quirks for old Intel chipsets */
  226. #define AZX_DCAPS_INTEL_ICH \
  227. (AZX_DCAPS_OLD_SSYNC | AZX_DCAPS_NO_ALIGN_BUFSIZE)
  228. /* quirks for Intel PCH */
  229. #define AZX_DCAPS_INTEL_PCH_BASE \
  230. (AZX_DCAPS_NO_ALIGN_BUFSIZE | AZX_DCAPS_COUNT_LPIB_DELAY |\
  231. AZX_DCAPS_SNOOP_TYPE(SCH))
  232. /* PCH up to IVB; no runtime PM; bind with i915 gfx */
  233. #define AZX_DCAPS_INTEL_PCH_NOPM \
  234. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT)
  235. /* PCH for HSW/BDW; with runtime PM */
  236. /* no i915 binding for this as HSW/BDW has another controller for HDMI */
  237. #define AZX_DCAPS_INTEL_PCH \
  238. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME)
  239. /* HSW HDMI */
  240. #define AZX_DCAPS_INTEL_HASWELL \
  241. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
  242. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
  243. AZX_DCAPS_SNOOP_TYPE(SCH))
  244. /* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
  245. #define AZX_DCAPS_INTEL_BROADWELL \
  246. (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
  247. AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_COMPONENT |\
  248. AZX_DCAPS_SNOOP_TYPE(SCH))
  249. #define AZX_DCAPS_INTEL_BAYTRAIL \
  250. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_I915_COMPONENT)
  251. #define AZX_DCAPS_INTEL_BRASWELL \
  252. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
  253. AZX_DCAPS_I915_COMPONENT)
  254. #define AZX_DCAPS_INTEL_SKYLAKE \
  255. (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
  256. AZX_DCAPS_SEPARATE_STREAM_TAG | AZX_DCAPS_I915_COMPONENT)
  257. #define AZX_DCAPS_INTEL_BROXTON AZX_DCAPS_INTEL_SKYLAKE
  258. #define AZX_DCAPS_INTEL_LNL \
  259. (AZX_DCAPS_INTEL_SKYLAKE | AZX_DCAPS_PIO_COMMANDS)
  260. #define AZX_DCAPS_INTEL_NVL \
  261. (AZX_DCAPS_INTEL_LNL & ~AZX_DCAPS_NO_ALIGN_BUFSIZE)
  262. /* quirks for ATI SB / AMD Hudson */
  263. #define AZX_DCAPS_PRESET_ATI_SB \
  264. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_POSFIX_LPIB |\
  265. AZX_DCAPS_SNOOP_TYPE(ATI))
  266. /* quirks for ATI/AMD HDMI */
  267. #define AZX_DCAPS_PRESET_ATI_HDMI \
  268. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_POSFIX_LPIB|\
  269. AZX_DCAPS_NO_MSI64)
  270. /* quirks for ATI HDMI with snoop off */
  271. #define AZX_DCAPS_PRESET_ATI_HDMI_NS \
  272. (AZX_DCAPS_PRESET_ATI_HDMI | AZX_DCAPS_SNOOP_OFF)
  273. /* quirks for AMD SB */
  274. #define AZX_DCAPS_PRESET_AMD_SB \
  275. (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_AMD_WORKAROUND |\
  276. AZX_DCAPS_SNOOP_TYPE(ATI) | AZX_DCAPS_PM_RUNTIME |\
  277. AZX_DCAPS_RETRY_PROBE)
  278. /* quirks for Nvidia */
  279. #define AZX_DCAPS_PRESET_NVIDIA \
  280. (AZX_DCAPS_NO_MSI | AZX_DCAPS_CORBRP_SELF_CLEAR |\
  281. AZX_DCAPS_SNOOP_TYPE(NVIDIA))
  282. #define AZX_DCAPS_PRESET_CTHDA \
  283. (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB |\
  284. AZX_DCAPS_NO_64BIT |\
  285. AZX_DCAPS_4K_BDLE_BOUNDARY | AZX_DCAPS_SNOOP_OFF)
  286. /*
  287. * vga_switcheroo support
  288. */
  289. #ifdef SUPPORT_VGA_SWITCHEROO
  290. #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
  291. #define needs_eld_notify_link(chip) ((chip)->bus.keep_power)
  292. #else
  293. #define use_vga_switcheroo(chip) 0
  294. #define needs_eld_notify_link(chip) false
  295. #endif
  296. static const char * const driver_short_names[] = {
  297. [AZX_DRIVER_ICH] = "HDA Intel",
  298. [AZX_DRIVER_PCH] = "HDA Intel PCH",
  299. [AZX_DRIVER_SCH] = "HDA Intel MID",
  300. [AZX_DRIVER_SKL] = "HDA Intel PCH", /* kept old name for compatibility */
  301. [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
  302. [AZX_DRIVER_ATI] = "HDA ATI SB",
  303. [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
  304. [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI",
  305. [AZX_DRIVER_GFHDMI] = "HDA GF HDMI",
  306. [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
  307. [AZX_DRIVER_SIS] = "HDA SIS966",
  308. [AZX_DRIVER_ULI] = "HDA ULI M5461",
  309. [AZX_DRIVER_NVIDIA] = "HDA NVidia",
  310. [AZX_DRIVER_TERA] = "HDA Teradici",
  311. [AZX_DRIVER_CTX] = "HDA Creative",
  312. [AZX_DRIVER_CTHDA] = "HDA Creative",
  313. [AZX_DRIVER_CMEDIA] = "HDA C-Media",
  314. [AZX_DRIVER_ZHAOXIN] = "HDA Zhaoxin",
  315. [AZX_DRIVER_ZHAOXINHDMI] = "HDA Zhaoxin HDMI",
  316. [AZX_DRIVER_LOONGSON] = "HDA Loongson",
  317. [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
  318. };
  319. static int azx_acquire_irq(struct azx *chip, int do_disconnect);
  320. static void set_default_power_save(struct azx *chip);
  321. /*
  322. * initialize the PCI registers
  323. */
  324. /* update bits in a PCI register byte */
  325. static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
  326. unsigned char mask, unsigned char val)
  327. {
  328. unsigned char data;
  329. pci_read_config_byte(pci, reg, &data);
  330. data &= ~mask;
  331. data |= (val & mask);
  332. pci_write_config_byte(pci, reg, data);
  333. }
  334. static void azx_init_pci(struct azx *chip)
  335. {
  336. int snoop_type = azx_get_snoop_type(chip);
  337. /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  338. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  339. * Ensuring these bits are 0 clears playback static on some HD Audio
  340. * codecs.
  341. * The PCI register TCSEL is defined in the Intel manuals.
  342. */
  343. if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) {
  344. dev_dbg(chip->card->dev, "Clearing TCSEL\n");
  345. update_pci_byte(chip->pci, AZX_PCIREG_TCSEL, 0x07, 0);
  346. }
  347. /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio,
  348. * we need to enable snoop.
  349. */
  350. if (snoop_type == AZX_SNOOP_TYPE_ATI) {
  351. dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
  352. azx_snoop(chip));
  353. update_pci_byte(chip->pci,
  354. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
  355. azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
  356. }
  357. /* For NVIDIA HDA, enable snoop */
  358. if (snoop_type == AZX_SNOOP_TYPE_NVIDIA) {
  359. dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
  360. azx_snoop(chip));
  361. update_pci_byte(chip->pci,
  362. NVIDIA_HDA_TRANSREG_ADDR,
  363. 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
  364. update_pci_byte(chip->pci,
  365. NVIDIA_HDA_ISTRM_COH,
  366. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  367. update_pci_byte(chip->pci,
  368. NVIDIA_HDA_OSTRM_COH,
  369. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  370. }
  371. /* Enable SCH/PCH snoop if needed */
  372. if (snoop_type == AZX_SNOOP_TYPE_SCH) {
  373. unsigned short snoop;
  374. pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
  375. if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
  376. (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
  377. snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
  378. if (!azx_snoop(chip))
  379. snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
  380. pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
  381. pci_read_config_word(chip->pci,
  382. INTEL_SCH_HDA_DEVC, &snoop);
  383. }
  384. dev_dbg(chip->card->dev, "SCH snoop: %s\n",
  385. (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ?
  386. "Disabled" : "Enabled");
  387. }
  388. }
  389. /*
  390. * In BXT-P A0, HD-Audio DMA requests is later than expected,
  391. * and makes an audio stream sensitive to system latencies when
  392. * 24/32 bits are playing.
  393. * Adjusting threshold of DMA fifo to force the DMA request
  394. * sooner to improve latency tolerance at the expense of power.
  395. */
  396. static void bxt_reduce_dma_latency(struct azx *chip)
  397. {
  398. u32 val;
  399. val = azx_readl(chip, VS_EM4L);
  400. val &= (0x3 << 20);
  401. azx_writel(chip, VS_EM4L, val);
  402. }
  403. /*
  404. * ML_LCAP bits:
  405. * bit 0: 6 MHz Supported
  406. * bit 1: 12 MHz Supported
  407. * bit 2: 24 MHz Supported
  408. * bit 3: 48 MHz Supported
  409. * bit 4: 96 MHz Supported
  410. * bit 5: 192 MHz Supported
  411. */
  412. static int intel_get_lctl_scf(struct azx *chip)
  413. {
  414. struct hdac_bus *bus = azx_bus(chip);
  415. static const int preferred_bits[] = { 2, 3, 1, 4, 5 };
  416. u32 val, t;
  417. int i;
  418. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCAP);
  419. for (i = 0; i < ARRAY_SIZE(preferred_bits); i++) {
  420. t = preferred_bits[i];
  421. if (val & (1 << t))
  422. return t;
  423. }
  424. dev_warn(chip->card->dev, "set audio clock frequency to 6MHz");
  425. return 0;
  426. }
  427. static int intel_ml_lctl_set_power(struct azx *chip, int state)
  428. {
  429. struct hdac_bus *bus = azx_bus(chip);
  430. u32 val;
  431. int timeout;
  432. /*
  433. * Changes to LCTL.SCF are only needed for the first multi-link dealing
  434. * with external codecs
  435. */
  436. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  437. val &= ~AZX_ML_LCTL_SPA;
  438. val |= state << AZX_ML_LCTL_SPA_SHIFT;
  439. writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  440. /* wait for CPA */
  441. timeout = 50;
  442. while (timeout) {
  443. if (((readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL)) &
  444. AZX_ML_LCTL_CPA) == (state << AZX_ML_LCTL_CPA_SHIFT))
  445. return 0;
  446. timeout--;
  447. udelay(10);
  448. }
  449. return -1;
  450. }
  451. static void intel_init_lctl(struct azx *chip)
  452. {
  453. struct hdac_bus *bus = azx_bus(chip);
  454. u32 val;
  455. int ret;
  456. /* 0. check lctl register value is correct or not */
  457. val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  458. /* only perform additional configurations if the SCF is initially based on 6MHz */
  459. if ((val & AZX_ML_LCTL_SCF) != 0)
  460. return;
  461. /*
  462. * Before operating on SPA, CPA must match SPA.
  463. * Any deviation may result in undefined behavior.
  464. */
  465. if (((val & AZX_ML_LCTL_SPA) >> AZX_ML_LCTL_SPA_SHIFT) !=
  466. ((val & AZX_ML_LCTL_CPA) >> AZX_ML_LCTL_CPA_SHIFT))
  467. return;
  468. /* 1. turn link down: set SPA to 0 and wait CPA to 0 */
  469. ret = intel_ml_lctl_set_power(chip, 0);
  470. udelay(100);
  471. if (ret)
  472. goto set_spa;
  473. /* 2. update SCF to select an audio clock different from 6MHz */
  474. val &= ~AZX_ML_LCTL_SCF;
  475. val |= intel_get_lctl_scf(chip);
  476. writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL);
  477. set_spa:
  478. /* 4. turn link up: set SPA to 1 and wait CPA to 1 */
  479. intel_ml_lctl_set_power(chip, 1);
  480. udelay(100);
  481. }
  482. static void hda_intel_init_chip(struct azx *chip, bool full_reset)
  483. {
  484. struct hdac_bus *bus = azx_bus(chip);
  485. struct pci_dev *pci = chip->pci;
  486. u32 val;
  487. snd_hdac_set_codec_wakeup(bus, true);
  488. if (chip->driver_type == AZX_DRIVER_SKL) {
  489. pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
  490. val = val & ~INTEL_HDA_CGCTL_MISCBDCGE;
  491. pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
  492. }
  493. azx_init_chip(chip, full_reset);
  494. if (chip->driver_type == AZX_DRIVER_SKL) {
  495. pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
  496. val = val | INTEL_HDA_CGCTL_MISCBDCGE;
  497. pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
  498. }
  499. snd_hdac_set_codec_wakeup(bus, false);
  500. /* reduce dma latency to avoid noise */
  501. if (HDA_CONTROLLER_IS_APL(pci))
  502. bxt_reduce_dma_latency(chip);
  503. if (bus->mlcap != NULL)
  504. intel_init_lctl(chip);
  505. }
  506. /* calculate runtime delay from LPIB */
  507. static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev,
  508. unsigned int pos)
  509. {
  510. struct snd_pcm_substream *substream = azx_dev->core.substream;
  511. int stream = substream->stream;
  512. unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev);
  513. int delay;
  514. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  515. delay = pos - lpib_pos;
  516. else
  517. delay = lpib_pos - pos;
  518. if (delay < 0) {
  519. if (delay >= azx_dev->core.delay_negative_threshold)
  520. delay = 0;
  521. else
  522. delay += azx_dev->core.bufsize;
  523. }
  524. if (delay >= azx_dev->core.period_bytes) {
  525. dev_info(chip->card->dev,
  526. "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
  527. delay, azx_dev->core.period_bytes);
  528. delay = 0;
  529. chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
  530. chip->get_delay[stream] = NULL;
  531. }
  532. return bytes_to_frames(substream->runtime, delay);
  533. }
  534. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
  535. /* called from IRQ */
  536. static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
  537. {
  538. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  539. int ok;
  540. ok = azx_position_ok(chip, azx_dev);
  541. if (ok == 1) {
  542. azx_dev->irq_pending = 0;
  543. return ok;
  544. } else if (ok == 0) {
  545. /* bogus IRQ, process it later */
  546. azx_dev->irq_pending = 1;
  547. schedule_work(&hda->irq_pending_work);
  548. }
  549. return 0;
  550. }
  551. #define display_power(chip, enable) \
  552. snd_hdac_display_power(azx_bus(chip), HDA_CODEC_IDX_CONTROLLER, enable)
  553. /*
  554. * Check whether the current DMA position is acceptable for updating
  555. * periods. Returns non-zero if it's OK.
  556. *
  557. * Many HD-audio controllers appear pretty inaccurate about
  558. * the update-IRQ timing. The IRQ is issued before actually the
  559. * data is processed. So, we need to process it afterwords in a
  560. * workqueue.
  561. *
  562. * Returns 1 if OK to proceed, 0 for delay handling, -1 for skipping update
  563. */
  564. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  565. {
  566. struct snd_pcm_substream *substream = azx_dev->core.substream;
  567. struct snd_pcm_runtime *runtime = substream->runtime;
  568. int stream = substream->stream;
  569. u32 wallclk;
  570. unsigned int pos;
  571. snd_pcm_uframes_t hwptr, target;
  572. /*
  573. * The value of the WALLCLK register is always 0
  574. * on the Loongson controller, so we return directly.
  575. */
  576. if (chip->driver_type == AZX_DRIVER_LOONGSON)
  577. return 1;
  578. wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk;
  579. if (wallclk < (azx_dev->core.period_wallclk * 2) / 3)
  580. return -1; /* bogus (too early) interrupt */
  581. if (chip->get_position[stream])
  582. pos = chip->get_position[stream](chip, azx_dev);
  583. else { /* use the position buffer as default */
  584. pos = azx_get_pos_posbuf(chip, azx_dev);
  585. if (!pos || pos == (u32)-1) {
  586. dev_info(chip->card->dev,
  587. "Invalid position buffer, using LPIB read method instead.\n");
  588. chip->get_position[stream] = azx_get_pos_lpib;
  589. if (chip->get_position[0] == azx_get_pos_lpib &&
  590. chip->get_position[1] == azx_get_pos_lpib)
  591. azx_bus(chip)->use_posbuf = false;
  592. pos = azx_get_pos_lpib(chip, azx_dev);
  593. chip->get_delay[stream] = NULL;
  594. } else {
  595. chip->get_position[stream] = azx_get_pos_posbuf;
  596. if (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)
  597. chip->get_delay[stream] = azx_get_delay_from_lpib;
  598. }
  599. }
  600. if (pos >= azx_dev->core.bufsize)
  601. pos = 0;
  602. if (WARN_ONCE(!azx_dev->core.period_bytes,
  603. "hda-intel: zero azx_dev->period_bytes"))
  604. return -1; /* this shouldn't happen! */
  605. if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 &&
  606. pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2)
  607. /* NG - it's below the first next period boundary */
  608. return chip->bdl_pos_adj ? 0 : -1;
  609. azx_dev->core.start_wallclk += wallclk;
  610. if (azx_dev->core.no_period_wakeup)
  611. return 1; /* OK, no need to check period boundary */
  612. if (runtime->hw_ptr_base != runtime->hw_ptr_interrupt)
  613. return 1; /* OK, already in hwptr updating process */
  614. /* check whether the period gets really elapsed */
  615. pos = bytes_to_frames(runtime, pos);
  616. hwptr = runtime->hw_ptr_base + pos;
  617. if (hwptr < runtime->status->hw_ptr)
  618. hwptr += runtime->buffer_size;
  619. target = runtime->hw_ptr_interrupt + runtime->period_size;
  620. if (hwptr < target) {
  621. /* too early wakeup, process it later */
  622. return chip->bdl_pos_adj ? 0 : -1;
  623. }
  624. return 1; /* OK, it's fine */
  625. }
  626. /*
  627. * The work for pending PCM period updates.
  628. */
  629. static void azx_irq_pending_work(struct work_struct *work)
  630. {
  631. struct hda_intel *hda = container_of(work, struct hda_intel, irq_pending_work);
  632. struct azx *chip = &hda->chip;
  633. struct hdac_bus *bus = azx_bus(chip);
  634. struct hdac_stream *s;
  635. int pending, ok;
  636. if (!hda->irq_pending_warned) {
  637. dev_info(chip->card->dev,
  638. "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n",
  639. chip->card->number);
  640. hda->irq_pending_warned = 1;
  641. }
  642. for (;;) {
  643. pending = 0;
  644. spin_lock_irq(&bus->reg_lock);
  645. list_for_each_entry(s, &bus->stream_list, list) {
  646. struct azx_dev *azx_dev = stream_to_azx_dev(s);
  647. if (!azx_dev->irq_pending ||
  648. !s->substream ||
  649. !s->running)
  650. continue;
  651. ok = azx_position_ok(chip, azx_dev);
  652. if (ok > 0) {
  653. azx_dev->irq_pending = 0;
  654. spin_unlock(&bus->reg_lock);
  655. snd_pcm_period_elapsed(s->substream);
  656. spin_lock(&bus->reg_lock);
  657. } else if (ok < 0) {
  658. pending = 0; /* too early */
  659. } else
  660. pending++;
  661. }
  662. spin_unlock_irq(&bus->reg_lock);
  663. if (!pending)
  664. return;
  665. msleep(1);
  666. }
  667. }
  668. /* clear irq_pending flags and assure no on-going workq */
  669. static void azx_clear_irq_pending(struct azx *chip)
  670. {
  671. struct hdac_bus *bus = azx_bus(chip);
  672. struct hdac_stream *s;
  673. guard(spinlock_irq)(&bus->reg_lock);
  674. list_for_each_entry(s, &bus->stream_list, list) {
  675. struct azx_dev *azx_dev = stream_to_azx_dev(s);
  676. azx_dev->irq_pending = 0;
  677. }
  678. }
  679. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  680. {
  681. struct hdac_bus *bus = azx_bus(chip);
  682. int ret;
  683. if (!chip->msi || pci_alloc_irq_vectors(chip->pci, 1, 1, PCI_IRQ_MSI) < 0) {
  684. ret = pci_alloc_irq_vectors(chip->pci, 1, 1, PCI_IRQ_INTX);
  685. if (ret < 0)
  686. return ret;
  687. chip->msi = 0;
  688. }
  689. if (request_irq(chip->pci->irq, azx_interrupt,
  690. chip->msi ? 0 : IRQF_SHARED,
  691. chip->card->irq_descr, chip)) {
  692. dev_err(chip->card->dev,
  693. "unable to grab IRQ %d, disabling device\n",
  694. chip->pci->irq);
  695. if (do_disconnect)
  696. snd_card_disconnect(chip->card);
  697. return -1;
  698. }
  699. bus->irq = chip->pci->irq;
  700. chip->card->sync_irq = bus->irq;
  701. return 0;
  702. }
  703. /* get the current DMA position with correction on VIA chips */
  704. static unsigned int azx_via_get_position(struct azx *chip,
  705. struct azx_dev *azx_dev)
  706. {
  707. unsigned int link_pos, mini_pos, bound_pos;
  708. unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
  709. unsigned int fifo_size;
  710. link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
  711. if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  712. /* Playback, no problem using link position */
  713. return link_pos;
  714. }
  715. /* Capture */
  716. /* For new chipset,
  717. * use mod to get the DMA position just like old chipset
  718. */
  719. mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf);
  720. mod_dma_pos %= azx_dev->core.period_bytes;
  721. fifo_size = azx_stream(azx_dev)->fifo_size;
  722. if (azx_dev->insufficient) {
  723. /* Link position never gather than FIFO size */
  724. if (link_pos <= fifo_size)
  725. return 0;
  726. azx_dev->insufficient = 0;
  727. }
  728. if (link_pos <= fifo_size)
  729. mini_pos = azx_dev->core.bufsize + link_pos - fifo_size;
  730. else
  731. mini_pos = link_pos - fifo_size;
  732. /* Find nearest previous boudary */
  733. mod_mini_pos = mini_pos % azx_dev->core.period_bytes;
  734. mod_link_pos = link_pos % azx_dev->core.period_bytes;
  735. if (mod_link_pos >= fifo_size)
  736. bound_pos = link_pos - mod_link_pos;
  737. else if (mod_dma_pos >= mod_mini_pos)
  738. bound_pos = mini_pos - mod_mini_pos;
  739. else {
  740. bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes;
  741. if (bound_pos >= azx_dev->core.bufsize)
  742. bound_pos = 0;
  743. }
  744. /* Calculate real DMA position we want */
  745. return bound_pos + mod_dma_pos;
  746. }
  747. #define AMD_FIFO_SIZE 32
  748. /* get the current DMA position with FIFO size correction */
  749. static unsigned int azx_get_pos_fifo(struct azx *chip, struct azx_dev *azx_dev)
  750. {
  751. struct snd_pcm_substream *substream = azx_dev->core.substream;
  752. struct snd_pcm_runtime *runtime = substream->runtime;
  753. unsigned int pos, delay;
  754. pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
  755. if (!runtime)
  756. return pos;
  757. runtime->delay = AMD_FIFO_SIZE;
  758. delay = frames_to_bytes(runtime, AMD_FIFO_SIZE);
  759. if (azx_dev->insufficient) {
  760. if (pos < delay) {
  761. delay = pos;
  762. runtime->delay = bytes_to_frames(runtime, pos);
  763. } else {
  764. azx_dev->insufficient = 0;
  765. }
  766. }
  767. /* correct the DMA position for capture stream */
  768. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  769. if (pos < delay)
  770. pos += azx_dev->core.bufsize;
  771. pos -= delay;
  772. }
  773. return pos;
  774. }
  775. static int azx_get_delay_from_fifo(struct azx *chip, struct azx_dev *azx_dev,
  776. unsigned int pos)
  777. {
  778. struct snd_pcm_substream *substream = azx_dev->core.substream;
  779. /* just read back the calculated value in the above */
  780. return substream->runtime->delay;
  781. }
  782. static void __azx_shutdown_chip(struct azx *chip, bool skip_link_reset)
  783. {
  784. azx_stop_chip(chip);
  785. if (!skip_link_reset)
  786. azx_enter_link_reset(chip);
  787. azx_clear_irq_pending(chip);
  788. display_power(chip, false);
  789. }
  790. static DEFINE_MUTEX(card_list_lock);
  791. static LIST_HEAD(card_list);
  792. static void azx_shutdown_chip(struct azx *chip)
  793. {
  794. __azx_shutdown_chip(chip, false);
  795. }
  796. static void azx_add_card_list(struct azx *chip)
  797. {
  798. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  799. guard(mutex)(&card_list_lock);
  800. list_add(&hda->list, &card_list);
  801. }
  802. static void azx_del_card_list(struct azx *chip)
  803. {
  804. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  805. guard(mutex)(&card_list_lock);
  806. list_del_init(&hda->list);
  807. }
  808. /* trigger power-save check at writing parameter */
  809. static int __maybe_unused param_set_xint(const char *val, const struct kernel_param *kp)
  810. {
  811. struct hda_intel *hda;
  812. struct azx *chip;
  813. int prev = power_save;
  814. int ret = param_set_int(val, kp);
  815. if (ret || prev == power_save)
  816. return ret;
  817. if (pm_blacklist > 0)
  818. return 0;
  819. guard(mutex)(&card_list_lock);
  820. list_for_each_entry(hda, &card_list, list) {
  821. chip = &hda->chip;
  822. if (!hda->probe_continued || chip->disabled ||
  823. hda->runtime_pm_disabled)
  824. continue;
  825. snd_hda_set_power_save(&chip->bus, power_save * 1000);
  826. }
  827. return 0;
  828. }
  829. /*
  830. * power management
  831. */
  832. static bool azx_is_pm_ready(struct snd_card *card)
  833. {
  834. struct azx *chip;
  835. struct hda_intel *hda;
  836. if (!card)
  837. return false;
  838. chip = card->private_data;
  839. hda = container_of(chip, struct hda_intel, chip);
  840. if (chip->disabled || hda->init_failed || !chip->running)
  841. return false;
  842. return true;
  843. }
  844. static void __azx_runtime_resume(struct azx *chip)
  845. {
  846. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  847. struct hdac_bus *bus = azx_bus(chip);
  848. struct hda_codec *codec;
  849. int status;
  850. display_power(chip, true);
  851. if (hda->need_i915_power)
  852. snd_hdac_i915_set_bclk(bus);
  853. /* Read STATESTS before controller reset */
  854. status = azx_readw(chip, STATESTS);
  855. azx_init_pci(chip);
  856. hda_intel_init_chip(chip, true);
  857. /* Avoid codec resume if runtime resume is for system suspend */
  858. if (!chip->pm_prepared) {
  859. list_for_each_codec(codec, &chip->bus) {
  860. if (codec->relaxed_resume)
  861. continue;
  862. if (codec->forced_resume || (status & (1 << codec->addr)))
  863. pm_request_resume(hda_codec_dev(codec));
  864. }
  865. }
  866. /* power down again for link-controlled chips */
  867. if (!hda->need_i915_power)
  868. display_power(chip, false);
  869. }
  870. static int azx_prepare(struct device *dev)
  871. {
  872. struct snd_card *card = dev_get_drvdata(dev);
  873. struct azx *chip;
  874. if (!azx_is_pm_ready(card))
  875. return 0;
  876. chip = card->private_data;
  877. chip->pm_prepared = 1;
  878. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  879. flush_work(&azx_bus(chip)->unsol_work);
  880. /* HDA controller always requires different WAKEEN for runtime suspend
  881. * and system suspend, so don't use direct-complete here.
  882. */
  883. return 0;
  884. }
  885. static void azx_complete(struct device *dev)
  886. {
  887. struct snd_card *card = dev_get_drvdata(dev);
  888. struct azx *chip;
  889. if (!azx_is_pm_ready(card))
  890. return;
  891. chip = card->private_data;
  892. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  893. chip->pm_prepared = 0;
  894. }
  895. static int azx_suspend(struct device *dev)
  896. {
  897. struct snd_card *card = dev_get_drvdata(dev);
  898. struct azx *chip;
  899. if (!azx_is_pm_ready(card))
  900. return 0;
  901. chip = card->private_data;
  902. azx_shutdown_chip(chip);
  903. trace_azx_suspend(chip);
  904. return 0;
  905. }
  906. static int azx_resume(struct device *dev)
  907. {
  908. struct snd_card *card = dev_get_drvdata(dev);
  909. struct azx *chip;
  910. if (!azx_is_pm_ready(card))
  911. return 0;
  912. chip = card->private_data;
  913. __azx_runtime_resume(chip);
  914. trace_azx_resume(chip);
  915. return 0;
  916. }
  917. /* put codec down to D3 at hibernation for Intel SKL+;
  918. * otherwise BIOS may still access the codec and screw up the driver
  919. */
  920. static int azx_freeze_noirq(struct device *dev)
  921. {
  922. struct snd_card *card = dev_get_drvdata(dev);
  923. struct azx *chip = card->private_data;
  924. struct pci_dev *pci = to_pci_dev(dev);
  925. if (!azx_is_pm_ready(card))
  926. return 0;
  927. if (chip->driver_type == AZX_DRIVER_SKL)
  928. pci_set_power_state(pci, PCI_D3hot);
  929. return 0;
  930. }
  931. static int azx_thaw_noirq(struct device *dev)
  932. {
  933. struct snd_card *card = dev_get_drvdata(dev);
  934. struct azx *chip = card->private_data;
  935. struct pci_dev *pci = to_pci_dev(dev);
  936. if (!azx_is_pm_ready(card))
  937. return 0;
  938. if (chip->driver_type == AZX_DRIVER_SKL)
  939. pci_set_power_state(pci, PCI_D0);
  940. return 0;
  941. }
  942. static int azx_runtime_suspend(struct device *dev)
  943. {
  944. struct snd_card *card = dev_get_drvdata(dev);
  945. struct azx *chip;
  946. if (!azx_is_pm_ready(card))
  947. return 0;
  948. chip = card->private_data;
  949. /* enable controller wake up event */
  950. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) | STATESTS_INT_MASK);
  951. azx_shutdown_chip(chip);
  952. trace_azx_runtime_suspend(chip);
  953. return 0;
  954. }
  955. static int azx_runtime_resume(struct device *dev)
  956. {
  957. struct snd_card *card = dev_get_drvdata(dev);
  958. struct azx *chip;
  959. if (!azx_is_pm_ready(card))
  960. return 0;
  961. chip = card->private_data;
  962. __azx_runtime_resume(chip);
  963. /* disable controller Wake Up event*/
  964. azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & ~STATESTS_INT_MASK);
  965. trace_azx_runtime_resume(chip);
  966. return 0;
  967. }
  968. static int azx_runtime_idle(struct device *dev)
  969. {
  970. struct snd_card *card = dev_get_drvdata(dev);
  971. struct azx *chip;
  972. struct hda_intel *hda;
  973. if (!card)
  974. return 0;
  975. chip = card->private_data;
  976. hda = container_of(chip, struct hda_intel, chip);
  977. if (chip->disabled || hda->init_failed)
  978. return 0;
  979. if (!power_save_controller || !azx_has_pm_runtime(chip) ||
  980. azx_bus(chip)->codec_powered || !chip->running)
  981. return -EBUSY;
  982. /* ELD notification gets broken when HD-audio bus is off */
  983. if (needs_eld_notify_link(chip))
  984. return -EBUSY;
  985. return 0;
  986. }
  987. static const struct dev_pm_ops azx_pm = {
  988. SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
  989. .prepare = pm_sleep_ptr(azx_prepare),
  990. .complete = pm_sleep_ptr(azx_complete),
  991. .freeze_noirq = pm_sleep_ptr(azx_freeze_noirq),
  992. .thaw_noirq = pm_sleep_ptr(azx_thaw_noirq),
  993. RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
  994. };
  995. static int azx_probe_continue(struct azx *chip);
  996. #ifdef SUPPORT_VGA_SWITCHEROO
  997. static struct pci_dev *get_bound_vga(struct pci_dev *pci);
  998. static void azx_vs_set_state(struct pci_dev *pci,
  999. enum vga_switcheroo_state state)
  1000. {
  1001. struct snd_card *card = pci_get_drvdata(pci);
  1002. struct azx *chip = card->private_data;
  1003. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1004. struct hda_codec *codec;
  1005. bool disabled;
  1006. wait_for_completion(&hda->probe_wait);
  1007. if (hda->init_failed)
  1008. return;
  1009. disabled = (state == VGA_SWITCHEROO_OFF);
  1010. if (chip->disabled == disabled)
  1011. return;
  1012. if (!hda->probe_continued) {
  1013. chip->disabled = disabled;
  1014. if (!disabled) {
  1015. dev_info(chip->card->dev,
  1016. "Start delayed initialization\n");
  1017. if (azx_probe_continue(chip) < 0)
  1018. dev_err(chip->card->dev, "initialization error\n");
  1019. }
  1020. } else {
  1021. dev_info(chip->card->dev, "%s via vga_switcheroo\n",
  1022. disabled ? "Disabling" : "Enabling");
  1023. if (disabled) {
  1024. list_for_each_codec(codec, &chip->bus) {
  1025. pm_runtime_suspend(hda_codec_dev(codec));
  1026. pm_runtime_disable(hda_codec_dev(codec));
  1027. }
  1028. pm_runtime_suspend(card->dev);
  1029. pm_runtime_disable(card->dev);
  1030. /* when we get suspended by vga_switcheroo we end up in D3cold,
  1031. * however we have no ACPI handle, so pci/acpi can't put us there,
  1032. * put ourselves there */
  1033. pci->current_state = PCI_D3cold;
  1034. chip->disabled = true;
  1035. if (snd_hda_lock_devices(&chip->bus))
  1036. dev_warn(chip->card->dev,
  1037. "Cannot lock devices!\n");
  1038. } else {
  1039. snd_hda_unlock_devices(&chip->bus);
  1040. chip->disabled = false;
  1041. pm_runtime_enable(card->dev);
  1042. list_for_each_codec(codec, &chip->bus) {
  1043. pm_runtime_enable(hda_codec_dev(codec));
  1044. pm_runtime_resume(hda_codec_dev(codec));
  1045. }
  1046. }
  1047. }
  1048. }
  1049. static bool azx_vs_can_switch(struct pci_dev *pci)
  1050. {
  1051. struct snd_card *card = pci_get_drvdata(pci);
  1052. struct azx *chip = card->private_data;
  1053. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1054. wait_for_completion(&hda->probe_wait);
  1055. if (hda->init_failed)
  1056. return false;
  1057. if (chip->disabled || !hda->probe_continued)
  1058. return true;
  1059. if (snd_hda_lock_devices(&chip->bus))
  1060. return false;
  1061. snd_hda_unlock_devices(&chip->bus);
  1062. return true;
  1063. }
  1064. /*
  1065. * The discrete GPU cannot power down unless the HDA controller runtime
  1066. * suspends, so activate runtime PM on codecs even if power_save == 0.
  1067. */
  1068. static void setup_vga_switcheroo_runtime_pm(struct azx *chip)
  1069. {
  1070. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1071. struct hda_codec *codec;
  1072. if (hda->use_vga_switcheroo && !needs_eld_notify_link(chip)) {
  1073. list_for_each_codec(codec, &chip->bus)
  1074. codec->auto_runtime_pm = 1;
  1075. /* reset the power save setup */
  1076. if (chip->running)
  1077. set_default_power_save(chip);
  1078. }
  1079. }
  1080. static void azx_vs_gpu_bound(struct pci_dev *pci,
  1081. enum vga_switcheroo_client_id client_id)
  1082. {
  1083. struct snd_card *card = pci_get_drvdata(pci);
  1084. struct azx *chip = card->private_data;
  1085. if (client_id == VGA_SWITCHEROO_DIS)
  1086. chip->bus.keep_power = 0;
  1087. setup_vga_switcheroo_runtime_pm(chip);
  1088. }
  1089. static void init_vga_switcheroo(struct azx *chip)
  1090. {
  1091. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1092. struct pci_dev *p = get_bound_vga(chip->pci);
  1093. struct pci_dev *parent;
  1094. if (p) {
  1095. dev_info(chip->card->dev,
  1096. "Handle vga_switcheroo audio client\n");
  1097. hda->use_vga_switcheroo = 1;
  1098. /* cleared in either gpu_bound op or codec probe, or when its
  1099. * upstream port has _PR3 (i.e. dGPU).
  1100. */
  1101. parent = pci_upstream_bridge(p);
  1102. chip->bus.keep_power = parent ? !pci_pr3_present(parent) : 1;
  1103. chip->driver_caps |= AZX_DCAPS_PM_RUNTIME;
  1104. pci_dev_put(p);
  1105. }
  1106. }
  1107. static const struct vga_switcheroo_client_ops azx_vs_ops = {
  1108. .set_gpu_state = azx_vs_set_state,
  1109. .can_switch = azx_vs_can_switch,
  1110. .gpu_bound = azx_vs_gpu_bound,
  1111. };
  1112. static int register_vga_switcheroo(struct azx *chip)
  1113. {
  1114. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1115. struct pci_dev *p;
  1116. int err;
  1117. if (!hda->use_vga_switcheroo)
  1118. return 0;
  1119. p = get_bound_vga(chip->pci);
  1120. err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, p);
  1121. pci_dev_put(p);
  1122. if (err < 0)
  1123. return err;
  1124. hda->vga_switcheroo_registered = 1;
  1125. return 0;
  1126. }
  1127. #else
  1128. #define init_vga_switcheroo(chip) /* NOP */
  1129. #define register_vga_switcheroo(chip) 0
  1130. #define check_hdmi_disabled(pci) false
  1131. #define setup_vga_switcheroo_runtime_pm(chip) /* NOP */
  1132. #endif /* SUPPORT_VGA_SWITCHER */
  1133. /*
  1134. * destructor
  1135. */
  1136. static void azx_free(struct azx *chip)
  1137. {
  1138. struct pci_dev *pci = chip->pci;
  1139. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1140. struct hdac_bus *bus = azx_bus(chip);
  1141. if (hda->freed)
  1142. return;
  1143. if (azx_has_pm_runtime(chip) && chip->running) {
  1144. pm_runtime_get_noresume(&pci->dev);
  1145. pm_runtime_forbid(&pci->dev);
  1146. pm_runtime_dont_use_autosuspend(&pci->dev);
  1147. }
  1148. chip->running = 0;
  1149. azx_del_card_list(chip);
  1150. hda->init_failed = 1; /* to be sure */
  1151. complete_all(&hda->probe_wait);
  1152. if (use_vga_switcheroo(hda)) {
  1153. if (chip->disabled && hda->probe_continued)
  1154. snd_hda_unlock_devices(&chip->bus);
  1155. if (hda->vga_switcheroo_registered) {
  1156. vga_switcheroo_unregister_client(chip->pci);
  1157. /* Some GPUs don't have sound, and azx_first_init fails,
  1158. * leaving the device probed but non-functional. As long
  1159. * as it's probed, the PCI subsystem keeps its runtime
  1160. * PM status as active. Force it to suspended (as we
  1161. * actually stop the chip) to allow GPU to suspend via
  1162. * vga_switcheroo, and print a warning.
  1163. */
  1164. dev_warn(&pci->dev, "GPU sound probed, but not operational: please add a quirk to driver_denylist\n");
  1165. pm_runtime_disable(&pci->dev);
  1166. pm_runtime_set_suspended(&pci->dev);
  1167. pm_runtime_enable(&pci->dev);
  1168. }
  1169. }
  1170. if (bus->chip_init) {
  1171. azx_clear_irq_pending(chip);
  1172. azx_stop_all_streams(chip);
  1173. azx_stop_chip(chip);
  1174. }
  1175. if (bus->irq >= 0)
  1176. free_irq(bus->irq, (void*)chip);
  1177. azx_free_stream_pages(chip);
  1178. azx_free_streams(chip);
  1179. snd_hdac_bus_exit(bus);
  1180. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1181. release_firmware(chip->fw);
  1182. #endif
  1183. display_power(chip, false);
  1184. if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
  1185. snd_hdac_i915_exit(bus);
  1186. hda->freed = 1;
  1187. }
  1188. static int azx_dev_disconnect(struct snd_device *device)
  1189. {
  1190. struct azx *chip = device->device_data;
  1191. struct hdac_bus *bus = azx_bus(chip);
  1192. chip->bus.shutdown = 1;
  1193. cancel_work_sync(&bus->unsol_work);
  1194. return 0;
  1195. }
  1196. static int azx_dev_free(struct snd_device *device)
  1197. {
  1198. azx_free(device->device_data);
  1199. return 0;
  1200. }
  1201. #ifdef SUPPORT_VGA_SWITCHEROO
  1202. #ifdef CONFIG_ACPI
  1203. /* ATPX is in the integrated GPU's namespace */
  1204. static bool atpx_present(void)
  1205. {
  1206. struct pci_dev *pdev = NULL;
  1207. acpi_handle dhandle, atpx_handle;
  1208. acpi_status status;
  1209. while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {
  1210. if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) &&
  1211. (pdev->class != PCI_CLASS_DISPLAY_OTHER << 8))
  1212. continue;
  1213. dhandle = ACPI_HANDLE(&pdev->dev);
  1214. if (dhandle) {
  1215. status = acpi_get_handle(dhandle, "ATPX", &atpx_handle);
  1216. if (ACPI_SUCCESS(status)) {
  1217. pci_dev_put(pdev);
  1218. return true;
  1219. }
  1220. }
  1221. }
  1222. return false;
  1223. }
  1224. #else
  1225. static bool atpx_present(void)
  1226. {
  1227. return false;
  1228. }
  1229. #endif
  1230. /*
  1231. * Check of disabled HDMI controller by vga_switcheroo
  1232. */
  1233. static struct pci_dev *get_bound_vga(struct pci_dev *pci)
  1234. {
  1235. struct pci_dev *p;
  1236. /* check only discrete GPU */
  1237. switch (pci->vendor) {
  1238. case PCI_VENDOR_ID_ATI:
  1239. case PCI_VENDOR_ID_AMD:
  1240. if (pci->devfn == 1) {
  1241. p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
  1242. pci->bus->number, 0);
  1243. if (p) {
  1244. /* ATPX is in the integrated GPU's ACPI namespace
  1245. * rather than the dGPU's namespace. However,
  1246. * the dGPU is the one who is involved in
  1247. * vgaswitcheroo.
  1248. */
  1249. if (pci_is_display(p) &&
  1250. (atpx_present() || apple_gmux_detect(NULL, NULL)))
  1251. return p;
  1252. pci_dev_put(p);
  1253. }
  1254. }
  1255. break;
  1256. case PCI_VENDOR_ID_NVIDIA:
  1257. if (pci->devfn == 1) {
  1258. p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
  1259. pci->bus->number, 0);
  1260. if (p) {
  1261. if (pci_is_display(p))
  1262. return p;
  1263. pci_dev_put(p);
  1264. }
  1265. }
  1266. break;
  1267. }
  1268. return NULL;
  1269. }
  1270. static bool check_hdmi_disabled(struct pci_dev *pci)
  1271. {
  1272. bool vga_inactive = false;
  1273. struct pci_dev *p = get_bound_vga(pci);
  1274. if (p) {
  1275. if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
  1276. vga_inactive = true;
  1277. pci_dev_put(p);
  1278. }
  1279. return vga_inactive;
  1280. }
  1281. #endif /* SUPPORT_VGA_SWITCHEROO */
  1282. /*
  1283. * allow/deny-listing for position_fix
  1284. */
  1285. static const struct snd_pci_quirk position_fix_list[] = {
  1286. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  1287. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  1288. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  1289. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  1290. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  1291. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  1292. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  1293. SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
  1294. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  1295. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  1296. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  1297. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  1298. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  1299. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  1300. {}
  1301. };
  1302. static int check_position_fix(struct azx *chip, int fix)
  1303. {
  1304. const struct snd_pci_quirk *q;
  1305. switch (fix) {
  1306. case POS_FIX_AUTO:
  1307. case POS_FIX_LPIB:
  1308. case POS_FIX_POSBUF:
  1309. case POS_FIX_VIACOMBO:
  1310. case POS_FIX_COMBO:
  1311. case POS_FIX_SKL:
  1312. case POS_FIX_FIFO:
  1313. return fix;
  1314. }
  1315. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  1316. if (q) {
  1317. dev_info(chip->card->dev,
  1318. "position_fix set to %d for device %04x:%04x\n",
  1319. q->value, q->subvendor, q->subdevice);
  1320. return q->value;
  1321. }
  1322. /* Check VIA/ATI HD Audio Controller exist */
  1323. if (chip->driver_type == AZX_DRIVER_VIA) {
  1324. dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
  1325. return POS_FIX_VIACOMBO;
  1326. }
  1327. if (chip->driver_caps & AZX_DCAPS_AMD_WORKAROUND) {
  1328. dev_dbg(chip->card->dev, "Using FIFO position fix\n");
  1329. return POS_FIX_FIFO;
  1330. }
  1331. if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
  1332. dev_dbg(chip->card->dev, "Using LPIB position fix\n");
  1333. return POS_FIX_LPIB;
  1334. }
  1335. if (chip->driver_type == AZX_DRIVER_SKL) {
  1336. dev_dbg(chip->card->dev, "Using SKL position fix\n");
  1337. return POS_FIX_SKL;
  1338. }
  1339. return POS_FIX_AUTO;
  1340. }
  1341. static void assign_position_fix(struct azx *chip, int fix)
  1342. {
  1343. static const azx_get_pos_callback_t callbacks[] = {
  1344. [POS_FIX_AUTO] = NULL,
  1345. [POS_FIX_LPIB] = azx_get_pos_lpib,
  1346. [POS_FIX_POSBUF] = azx_get_pos_posbuf,
  1347. [POS_FIX_VIACOMBO] = azx_via_get_position,
  1348. [POS_FIX_COMBO] = azx_get_pos_lpib,
  1349. [POS_FIX_SKL] = azx_get_pos_posbuf,
  1350. [POS_FIX_FIFO] = azx_get_pos_fifo,
  1351. };
  1352. chip->get_position[0] = chip->get_position[1] = callbacks[fix];
  1353. /* combo mode uses LPIB only for playback */
  1354. if (fix == POS_FIX_COMBO)
  1355. chip->get_position[1] = NULL;
  1356. if ((fix == POS_FIX_POSBUF || fix == POS_FIX_SKL) &&
  1357. (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
  1358. chip->get_delay[0] = chip->get_delay[1] =
  1359. azx_get_delay_from_lpib;
  1360. }
  1361. if (fix == POS_FIX_FIFO)
  1362. chip->get_delay[0] = chip->get_delay[1] =
  1363. azx_get_delay_from_fifo;
  1364. }
  1365. /*
  1366. * deny-lists for probe_mask
  1367. */
  1368. static const struct snd_pci_quirk probe_mask_list[] = {
  1369. /* Thinkpad often breaks the controller communication when accessing
  1370. * to the non-working (or non-existing) modem codec slot.
  1371. */
  1372. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  1373. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  1374. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  1375. /* broken BIOS */
  1376. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  1377. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  1378. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  1379. /* forced codec slots */
  1380. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  1381. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  1382. SND_PCI_QUIRK(0x1558, 0x0351, "Schenker Dock 15", 0x105),
  1383. /* WinFast VP200 H (Teradici) user reported broken communication */
  1384. SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
  1385. {}
  1386. };
  1387. #define AZX_FORCE_CODEC_MASK 0x100
  1388. static void check_probe_mask(struct azx *chip, int dev)
  1389. {
  1390. const struct snd_pci_quirk *q;
  1391. chip->codec_probe_mask = probe_mask[dev];
  1392. if (chip->codec_probe_mask == -1) {
  1393. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  1394. if (q) {
  1395. dev_info(chip->card->dev,
  1396. "probe_mask set to 0x%x for device %04x:%04x\n",
  1397. q->value, q->subvendor, q->subdevice);
  1398. chip->codec_probe_mask = q->value;
  1399. }
  1400. }
  1401. /* check forced option */
  1402. if (chip->codec_probe_mask != -1 &&
  1403. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  1404. azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff;
  1405. dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
  1406. (int)azx_bus(chip)->codec_mask);
  1407. }
  1408. }
  1409. /*
  1410. * allow/deny-list for enable_msi
  1411. */
  1412. static const struct snd_pci_quirk msi_deny_list[] = {
  1413. SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
  1414. SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
  1415. SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
  1416. SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
  1417. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  1418. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  1419. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  1420. SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
  1421. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  1422. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  1423. {}
  1424. };
  1425. static void check_msi(struct azx *chip)
  1426. {
  1427. const struct snd_pci_quirk *q;
  1428. if (enable_msi >= 0) {
  1429. chip->msi = !!enable_msi;
  1430. return;
  1431. }
  1432. chip->msi = 1; /* enable MSI as default */
  1433. q = snd_pci_quirk_lookup(chip->pci, msi_deny_list);
  1434. if (q) {
  1435. dev_info(chip->card->dev,
  1436. "msi for device %04x:%04x set to %d\n",
  1437. q->subvendor, q->subdevice, q->value);
  1438. chip->msi = q->value;
  1439. return;
  1440. }
  1441. /* NVidia chipsets seem to cause troubles with MSI */
  1442. if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
  1443. dev_info(chip->card->dev, "Disabling MSI\n");
  1444. chip->msi = 0;
  1445. }
  1446. }
  1447. /* check the snoop mode availability */
  1448. static void azx_check_snoop_available(struct azx *chip)
  1449. {
  1450. int snoop = hda_snoop;
  1451. if (snoop >= 0) {
  1452. dev_info(chip->card->dev, "Force to %s mode by module option\n",
  1453. snoop ? "snoop" : "non-snoop");
  1454. chip->snoop = snoop;
  1455. chip->uc_buffer = !snoop;
  1456. return;
  1457. }
  1458. snoop = true;
  1459. if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
  1460. chip->driver_type == AZX_DRIVER_VIA) {
  1461. /* force to non-snoop mode for a new VIA controller
  1462. * when BIOS is set
  1463. */
  1464. u8 val;
  1465. pci_read_config_byte(chip->pci, 0x42, &val);
  1466. if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
  1467. chip->pci->revision == 0x20))
  1468. snoop = false;
  1469. }
  1470. if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
  1471. snoop = false;
  1472. chip->snoop = snoop;
  1473. if (!snoop) {
  1474. dev_info(chip->card->dev, "Force to non-snoop mode\n");
  1475. /* C-Media requires non-cached pages only for CORB/RIRB */
  1476. if (chip->driver_type != AZX_DRIVER_CMEDIA)
  1477. chip->uc_buffer = true;
  1478. }
  1479. }
  1480. static void azx_probe_work(struct work_struct *work)
  1481. {
  1482. struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
  1483. azx_probe_continue(&hda->chip);
  1484. }
  1485. static int default_bdl_pos_adj(struct azx *chip)
  1486. {
  1487. /* some exceptions: Atoms seem problematic with value 1 */
  1488. if (chip->pci->vendor == PCI_VENDOR_ID_INTEL) {
  1489. switch (chip->pci->device) {
  1490. case PCI_DEVICE_ID_INTEL_HDA_BYT:
  1491. case PCI_DEVICE_ID_INTEL_HDA_BSW:
  1492. return 32;
  1493. case PCI_DEVICE_ID_INTEL_HDA_APL:
  1494. return 64;
  1495. }
  1496. }
  1497. switch (chip->driver_type) {
  1498. /*
  1499. * increase the bdl size for Glenfly Gpus for hardware
  1500. * limitation on hdac interrupt interval
  1501. */
  1502. case AZX_DRIVER_GFHDMI:
  1503. return 128;
  1504. case AZX_DRIVER_ICH:
  1505. case AZX_DRIVER_PCH:
  1506. return 1;
  1507. case AZX_DRIVER_ZHAOXINHDMI:
  1508. return 128;
  1509. case AZX_DRIVER_NVIDIA:
  1510. return 64;
  1511. default:
  1512. return 32;
  1513. }
  1514. }
  1515. /*
  1516. * constructor
  1517. */
  1518. static const struct hda_controller_ops pci_hda_ops;
  1519. static int azx_create(struct snd_card *card, struct pci_dev *pci,
  1520. int dev, unsigned int driver_caps,
  1521. struct azx **rchip)
  1522. {
  1523. static const struct snd_device_ops ops = {
  1524. .dev_disconnect = azx_dev_disconnect,
  1525. .dev_free = azx_dev_free,
  1526. };
  1527. struct hda_intel *hda;
  1528. struct azx *chip;
  1529. int err;
  1530. *rchip = NULL;
  1531. err = pcim_enable_device(pci);
  1532. if (err < 0)
  1533. return err;
  1534. hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL);
  1535. if (!hda)
  1536. return -ENOMEM;
  1537. chip = &hda->chip;
  1538. mutex_init(&chip->open_mutex);
  1539. chip->card = card;
  1540. chip->pci = pci;
  1541. chip->ops = &pci_hda_ops;
  1542. chip->driver_caps = driver_caps;
  1543. chip->driver_type = driver_caps & 0xff;
  1544. check_msi(chip);
  1545. chip->dev_index = dev;
  1546. if (jackpoll_ms[dev] >= 50 && jackpoll_ms[dev] <= 60000)
  1547. chip->jackpoll_interval = msecs_to_jiffies(jackpoll_ms[dev]);
  1548. INIT_LIST_HEAD(&chip->pcm_list);
  1549. INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);
  1550. INIT_LIST_HEAD(&hda->list);
  1551. init_vga_switcheroo(chip);
  1552. init_completion(&hda->probe_wait);
  1553. assign_position_fix(chip, check_position_fix(chip, position_fix[dev]));
  1554. if (single_cmd < 0) /* allow fallback to single_cmd at errors */
  1555. chip->fallback_to_single_cmd = 1;
  1556. else /* explicitly set to single_cmd or not */
  1557. chip->single_cmd = single_cmd;
  1558. azx_check_snoop_available(chip);
  1559. if (bdl_pos_adj[dev] < 0)
  1560. chip->bdl_pos_adj = default_bdl_pos_adj(chip);
  1561. else
  1562. chip->bdl_pos_adj = bdl_pos_adj[dev];
  1563. err = azx_bus_init(chip, model[dev]);
  1564. if (err < 0)
  1565. return err;
  1566. /* use the non-cached pages in non-snoop mode */
  1567. if (!azx_snoop(chip))
  1568. azx_bus(chip)->dma_type = SNDRV_DMA_TYPE_DEV_WC;
  1569. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  1570. dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
  1571. chip->bus.core.needs_damn_long_delay = 1;
  1572. }
  1573. check_probe_mask(chip, dev);
  1574. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  1575. if (err < 0) {
  1576. dev_err(card->dev, "Error creating device [card]!\n");
  1577. azx_free(chip);
  1578. return err;
  1579. }
  1580. /* continue probing in work context as may trigger request module */
  1581. INIT_DELAYED_WORK(&hda->probe_work, azx_probe_work);
  1582. *rchip = chip;
  1583. return 0;
  1584. }
  1585. static int azx_first_init(struct azx *chip)
  1586. {
  1587. int dev = chip->dev_index;
  1588. struct pci_dev *pci = chip->pci;
  1589. struct snd_card *card = chip->card;
  1590. struct hdac_bus *bus = azx_bus(chip);
  1591. int err;
  1592. unsigned short gcap;
  1593. unsigned int dma_bits = 64;
  1594. #if BITS_PER_LONG != 64
  1595. /* Fix up base address on ULI M5461 */
  1596. if (chip->driver_type == AZX_DRIVER_ULI) {
  1597. u16 tmp3;
  1598. pci_read_config_word(pci, 0x40, &tmp3);
  1599. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  1600. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  1601. }
  1602. #endif
  1603. /*
  1604. * Fix response write request not synced to memory when handle
  1605. * hdac interrupt on Glenfly Gpus
  1606. */
  1607. if (chip->driver_type == AZX_DRIVER_GFHDMI)
  1608. bus->polling_mode = 1;
  1609. if (chip->driver_type == AZX_DRIVER_LOONGSON) {
  1610. bus->polling_mode = 1;
  1611. bus->not_use_interrupts = 1;
  1612. bus->access_sdnctl_in_dword = 1;
  1613. if (!chip->jackpoll_interval)
  1614. chip->jackpoll_interval = msecs_to_jiffies(1500);
  1615. }
  1616. if (chip->driver_type == AZX_DRIVER_ZHAOXINHDMI)
  1617. bus->polling_mode = 1;
  1618. bus->remap_addr = pcim_iomap_region(pci, 0, "ICH HD audio");
  1619. if (IS_ERR(bus->remap_addr))
  1620. return PTR_ERR(bus->remap_addr);
  1621. bus->addr = pci_resource_start(pci, 0);
  1622. if (chip->driver_type == AZX_DRIVER_SKL)
  1623. snd_hdac_bus_parse_capabilities(bus);
  1624. /*
  1625. * Some Intel CPUs has always running timer (ART) feature and
  1626. * controller may have Global time sync reporting capability, so
  1627. * check both of these before declaring synchronized time reporting
  1628. * capability SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME
  1629. */
  1630. chip->gts_present = false;
  1631. #ifdef CONFIG_X86
  1632. if (bus->ppcap && boot_cpu_has(X86_FEATURE_ART))
  1633. chip->gts_present = true;
  1634. #endif
  1635. pci_set_master(pci);
  1636. gcap = azx_readw(chip, GCAP);
  1637. dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
  1638. /* AMD devices support 40 or 48bit DMA, take the safe one */
  1639. if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
  1640. dma_bits = 40;
  1641. /* disable SB600 64bit support for safety */
  1642. if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
  1643. struct pci_dev *p_smbus;
  1644. dma_bits = 40;
  1645. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  1646. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  1647. NULL);
  1648. if (p_smbus) {
  1649. if (p_smbus->revision < 0x30)
  1650. gcap &= ~AZX_GCAP_64OK;
  1651. pci_dev_put(p_smbus);
  1652. }
  1653. }
  1654. /* NVidia hardware normally only supports up to 40 bits of DMA */
  1655. if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
  1656. dma_bits = 40;
  1657. /* disable 64bit DMA address on some devices */
  1658. if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
  1659. dev_dbg(card->dev, "Disabling 64bit DMA\n");
  1660. gcap &= ~AZX_GCAP_64OK;
  1661. }
  1662. /* disable buffer size rounding to 128-byte multiples if supported */
  1663. if (align_buffer_size >= 0)
  1664. chip->align_buffer_size = !!align_buffer_size;
  1665. else {
  1666. if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
  1667. chip->align_buffer_size = 0;
  1668. else
  1669. chip->align_buffer_size = 1;
  1670. }
  1671. /* allow 64bit DMA address if supported by H/W */
  1672. if (!(gcap & AZX_GCAP_64OK))
  1673. dma_bits = 32;
  1674. if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(dma_bits)))
  1675. dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
  1676. dma_set_max_seg_size(&pci->dev, UINT_MAX);
  1677. if (chip->msi && chip->driver_caps & AZX_DCAPS_NO_MSI64) {
  1678. dev_dbg(card->dev, "Restricting MSI to %u-bit\n", dma_bits);
  1679. pci->msi_addr_mask = DMA_BIT_MASK(dma_bits);
  1680. }
  1681. /* read number of streams from GCAP register instead of using
  1682. * hardcoded value
  1683. */
  1684. chip->capture_streams = (gcap >> 8) & 0x0f;
  1685. chip->playback_streams = (gcap >> 12) & 0x0f;
  1686. if (!chip->playback_streams && !chip->capture_streams) {
  1687. /* gcap didn't give any info, switching to old method */
  1688. switch (chip->driver_type) {
  1689. case AZX_DRIVER_ULI:
  1690. chip->playback_streams = ULI_NUM_PLAYBACK;
  1691. chip->capture_streams = ULI_NUM_CAPTURE;
  1692. break;
  1693. case AZX_DRIVER_ATIHDMI:
  1694. case AZX_DRIVER_ATIHDMI_NS:
  1695. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  1696. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  1697. break;
  1698. case AZX_DRIVER_GFHDMI:
  1699. case AZX_DRIVER_ZHAOXINHDMI:
  1700. case AZX_DRIVER_GENERIC:
  1701. default:
  1702. chip->playback_streams = ICH6_NUM_PLAYBACK;
  1703. chip->capture_streams = ICH6_NUM_CAPTURE;
  1704. break;
  1705. }
  1706. }
  1707. chip->capture_index_offset = 0;
  1708. chip->playback_index_offset = chip->capture_streams;
  1709. chip->num_streams = chip->playback_streams + chip->capture_streams;
  1710. /* sanity check for the SDxCTL.STRM field overflow */
  1711. if (chip->num_streams > 15 &&
  1712. (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) == 0) {
  1713. dev_warn(chip->card->dev, "number of I/O streams is %d, "
  1714. "forcing separate stream tags", chip->num_streams);
  1715. chip->driver_caps |= AZX_DCAPS_SEPARATE_STREAM_TAG;
  1716. }
  1717. /* initialize streams */
  1718. err = azx_init_streams(chip);
  1719. if (err < 0)
  1720. return err;
  1721. err = azx_alloc_stream_pages(chip);
  1722. if (err < 0)
  1723. return err;
  1724. /* initialize chip */
  1725. azx_init_pci(chip);
  1726. snd_hdac_i915_set_bclk(bus);
  1727. hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
  1728. /* codec detection */
  1729. if (!azx_bus(chip)->codec_mask) {
  1730. dev_err(card->dev, "no codecs found!\n");
  1731. /* keep running the rest for the runtime PM */
  1732. }
  1733. if (azx_acquire_irq(chip, 0) < 0)
  1734. return -EBUSY;
  1735. strscpy(card->driver, "HDA-Intel");
  1736. strscpy(card->shortname, driver_short_names[chip->driver_type],
  1737. sizeof(card->shortname));
  1738. snprintf(card->longname, sizeof(card->longname),
  1739. "%s at 0x%lx irq %i",
  1740. card->shortname, bus->addr, bus->irq);
  1741. return 0;
  1742. }
  1743. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1744. /* callback from request_firmware_nowait() */
  1745. static void azx_firmware_cb(const struct firmware *fw, void *context)
  1746. {
  1747. struct snd_card *card = context;
  1748. struct azx *chip = card->private_data;
  1749. if (fw)
  1750. chip->fw = fw;
  1751. else
  1752. dev_err(card->dev, "Cannot load firmware, continue without patching\n");
  1753. if (!chip->disabled) {
  1754. /* continue probing */
  1755. azx_probe_continue(chip);
  1756. }
  1757. }
  1758. #endif
  1759. static int disable_msi_reset_irq(struct azx *chip)
  1760. {
  1761. struct hdac_bus *bus = azx_bus(chip);
  1762. int err;
  1763. free_irq(bus->irq, chip);
  1764. bus->irq = -1;
  1765. chip->card->sync_irq = -1;
  1766. pci_free_irq_vectors(chip->pci);
  1767. chip->msi = 0;
  1768. err = azx_acquire_irq(chip, 1);
  1769. if (err < 0)
  1770. return err;
  1771. return 0;
  1772. }
  1773. /* Denylist for skipping the whole probe:
  1774. * some HD-audio PCI entries are exposed without any codecs, and such devices
  1775. * should be ignored from the beginning.
  1776. */
  1777. static const struct pci_device_id driver_denylist[] = {
  1778. { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1043, 0x874f) }, /* ASUS ROG Zenith II / Strix */
  1779. { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb59) }, /* MSI TRX40 Creator */
  1780. { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb60) }, /* MSI TRX40 */
  1781. {}
  1782. };
  1783. static struct pci_device_id driver_denylist_ideapad_z570[] = {
  1784. { PCI_DEVICE_SUB(0x10de, 0x0bea, 0x0000, 0x0000) }, /* NVIDIA GF108 HDA */
  1785. {}
  1786. };
  1787. static struct pci_device_id driver_denylist_msi_x870e[] = {
  1788. { PCI_DEVICE_SUB(0x1022, 0x15e3, 0x1462, 0xee59) }, /* MSI X870E Tomahawk WiFi */
  1789. {}
  1790. };
  1791. /* DMI-based denylist, to be used when:
  1792. * - PCI subsystem IDs are zero, impossible to distinguish from valid sound cards.
  1793. * - Different modifications of the same laptop use different GPU models.
  1794. */
  1795. static const struct dmi_system_id driver_denylist_dmi[] = {
  1796. {
  1797. /* No HDA in NVIDIA DGPU. BIOS disables it, but quirk_nvidia_hda() reenables. */
  1798. .matches = {
  1799. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1800. DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
  1801. },
  1802. .driver_data = &driver_denylist_ideapad_z570,
  1803. },
  1804. {
  1805. /* PCI device matching alone incorrectly matches some laptops */
  1806. .matches = {
  1807. DMI_MATCH(DMI_BOARD_VENDOR, "Micro-Star International Co., Ltd."),
  1808. DMI_MATCH(DMI_BOARD_NAME, "MAG X870E TOMAHAWK WIFI (MS-7E59)"),
  1809. },
  1810. .driver_data = &driver_denylist_msi_x870e,
  1811. },
  1812. {}
  1813. };
  1814. static const struct hda_controller_ops pci_hda_ops = {
  1815. .disable_msi_reset_irq = disable_msi_reset_irq,
  1816. .position_check = azx_position_check,
  1817. };
  1818. static DECLARE_BITMAP(probed_devs, SNDRV_CARDS);
  1819. static int azx_probe(struct pci_dev *pci,
  1820. const struct pci_device_id *pci_id)
  1821. {
  1822. const struct dmi_system_id *dmi;
  1823. struct snd_card *card;
  1824. struct hda_intel *hda;
  1825. struct azx *chip;
  1826. bool schedule_probe;
  1827. int dev;
  1828. int err;
  1829. if (pci_match_id(driver_denylist, pci)) {
  1830. dev_info(&pci->dev, "Skipping the device on the denylist\n");
  1831. return -ENODEV;
  1832. }
  1833. dmi = dmi_first_match(driver_denylist_dmi);
  1834. if (dmi && pci_match_id(dmi->driver_data, pci)) {
  1835. dev_info(&pci->dev, "Skipping the device on the DMI denylist\n");
  1836. return -ENODEV;
  1837. }
  1838. dev = find_first_zero_bit(probed_devs, SNDRV_CARDS);
  1839. if (dev >= SNDRV_CARDS)
  1840. return -ENODEV;
  1841. if (!enable[dev]) {
  1842. set_bit(dev, probed_devs);
  1843. return -ENOENT;
  1844. }
  1845. /*
  1846. * stop probe if another Intel's DSP driver should be activated
  1847. */
  1848. if (dmic_detect) {
  1849. err = snd_intel_dsp_driver_probe(pci);
  1850. if (err != SND_INTEL_DSP_DRIVER_ANY && err != SND_INTEL_DSP_DRIVER_LEGACY) {
  1851. dev_dbg(&pci->dev, "HDAudio driver not selected, aborting probe\n");
  1852. return -ENODEV;
  1853. }
  1854. } else {
  1855. dev_warn(&pci->dev, "dmic_detect option is deprecated, pass snd-intel-dspcfg.dsp_driver=1 option instead\n");
  1856. }
  1857. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  1858. 0, &card);
  1859. if (err < 0) {
  1860. dev_err(&pci->dev, "Error creating card!\n");
  1861. return err;
  1862. }
  1863. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  1864. if (err < 0)
  1865. goto out_free;
  1866. card->private_data = chip;
  1867. hda = container_of(chip, struct hda_intel, chip);
  1868. pci_set_drvdata(pci, card);
  1869. #ifdef CONFIG_SND_HDA_I915
  1870. /* bind with i915 if needed */
  1871. if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) {
  1872. err = snd_hdac_i915_init(azx_bus(chip));
  1873. if (err < 0) {
  1874. if (err == -EPROBE_DEFER)
  1875. goto out_free;
  1876. /* if the controller is bound only with HDMI/DP
  1877. * (for HSW and BDW), we need to abort the probe;
  1878. * for other chips, still continue probing as other
  1879. * codecs can be on the same link.
  1880. */
  1881. if (HDA_CONTROLLER_IN_GPU(pci)) {
  1882. dev_err_probe(card->dev, err,
  1883. "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
  1884. goto out_free;
  1885. } else {
  1886. /* don't bother any longer */
  1887. chip->driver_caps &= ~AZX_DCAPS_I915_COMPONENT;
  1888. }
  1889. }
  1890. /* HSW/BDW controllers need this power */
  1891. if (HDA_CONTROLLER_IN_GPU(pci))
  1892. hda->need_i915_power = true;
  1893. }
  1894. #else
  1895. if (HDA_CONTROLLER_IN_GPU(pci))
  1896. dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n");
  1897. #endif
  1898. err = register_vga_switcheroo(chip);
  1899. if (err < 0) {
  1900. dev_err(card->dev, "Error registering vga_switcheroo client\n");
  1901. goto out_free;
  1902. }
  1903. if (check_hdmi_disabled(pci)) {
  1904. dev_info(card->dev, "VGA controller is disabled\n");
  1905. dev_info(card->dev, "Delaying initialization\n");
  1906. chip->disabled = true;
  1907. }
  1908. schedule_probe = !chip->disabled;
  1909. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  1910. if (patch[dev] && *patch[dev]) {
  1911. dev_info(card->dev, "Applying patch firmware '%s'\n",
  1912. patch[dev]);
  1913. err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
  1914. &pci->dev, GFP_KERNEL, card,
  1915. azx_firmware_cb);
  1916. if (err < 0)
  1917. goto out_free;
  1918. schedule_probe = false; /* continued in azx_firmware_cb() */
  1919. }
  1920. #endif /* CONFIG_SND_HDA_PATCH_LOADER */
  1921. if (schedule_probe)
  1922. schedule_delayed_work(&hda->probe_work, 0);
  1923. set_bit(dev, probed_devs);
  1924. if (chip->disabled)
  1925. complete_all(&hda->probe_wait);
  1926. return 0;
  1927. out_free:
  1928. pci_set_drvdata(pci, NULL);
  1929. snd_card_free(card);
  1930. return err;
  1931. }
  1932. /* On some boards setting power_save to a non 0 value leads to clicking /
  1933. * popping sounds when ever we enter/leave powersaving mode. Ideally we would
  1934. * figure out how to avoid these sounds, but that is not always feasible.
  1935. * So we keep a list of devices where we disable powersaving as its known
  1936. * to causes problems on these devices.
  1937. */
  1938. static const struct snd_pci_quirk power_save_denylist[] = {
  1939. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1940. SND_PCI_QUIRK(0x1849, 0xc892, "Asrock B85M-ITX", 0),
  1941. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1942. SND_PCI_QUIRK(0x1849, 0x0397, "Asrock N68C-S UCC", 0),
  1943. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1944. SND_PCI_QUIRK(0x1849, 0x7662, "Asrock H81M-HDS", 0),
  1945. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1946. SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
  1947. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1948. SND_PCI_QUIRK(0x1028, 0x0497, "Dell Precision T3600", 0),
  1949. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1950. /* Note the P55A-UD3 and Z87-D3HP share the subsys id for the HDA dev */
  1951. SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P55A-UD3 / Z87-D3HP", 0),
  1952. /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
  1953. SND_PCI_QUIRK(0x8086, 0x2040, "Intel DZ77BH-55K", 0),
  1954. /* https://bugzilla.kernel.org/show_bug.cgi?id=199607 */
  1955. SND_PCI_QUIRK(0x8086, 0x2057, "Intel NUC5i7RYB", 0),
  1956. /* https://bugs.launchpad.net/bugs/1821663 */
  1957. SND_PCI_QUIRK(0x8086, 0x2064, "Intel SDP 8086:2064", 0),
  1958. /* https://bugzilla.redhat.com/show_bug.cgi?id=1520902 */
  1959. SND_PCI_QUIRK(0x8086, 0x2068, "Intel NUC7i3BNB", 0),
  1960. /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
  1961. SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
  1962. SND_PCI_QUIRK(0x17aa, 0x316e, "Lenovo ThinkCentre M70q", 0),
  1963. /* https://bugzilla.redhat.com/show_bug.cgi?id=1689623 */
  1964. SND_PCI_QUIRK(0x17aa, 0x367b, "Lenovo IdeaCentre B550", 0),
  1965. /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
  1966. SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
  1967. /* https://bugs.launchpad.net/bugs/1821663 */
  1968. SND_PCI_QUIRK(0x1631, 0xe017, "Packard Bell NEC IMEDIA 5204", 0),
  1969. /* KONTRON SinglePC may cause a stall at runtime resume */
  1970. SND_PCI_QUIRK(0x1734, 0x1232, "KONTRON SinglePC", 0),
  1971. /* Dell ALC3271 */
  1972. SND_PCI_QUIRK(0x1028, 0x0962, "Dell ALC3271", 0),
  1973. /* https://bugzilla.kernel.org/show_bug.cgi?id=220210 */
  1974. SND_PCI_QUIRK(0x17aa, 0x5079, "Lenovo Thinkpad E15", 0),
  1975. {}
  1976. };
  1977. static void set_default_power_save(struct azx *chip)
  1978. {
  1979. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  1980. int val = power_save;
  1981. if (pm_blacklist < 0) {
  1982. const struct snd_pci_quirk *q;
  1983. q = snd_pci_quirk_lookup(chip->pci, power_save_denylist);
  1984. if (q && val) {
  1985. dev_info(chip->card->dev, "device %04x:%04x is on the power_save denylist, forcing power_save to 0\n",
  1986. q->subvendor, q->subdevice);
  1987. val = 0;
  1988. hda->runtime_pm_disabled = 1;
  1989. }
  1990. } else if (pm_blacklist > 0) {
  1991. dev_info(chip->card->dev, "Forcing power_save to 0 via option\n");
  1992. val = 0;
  1993. }
  1994. snd_hda_set_power_save(&chip->bus, val * 1000);
  1995. }
  1996. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1997. static const unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
  1998. [AZX_DRIVER_NVIDIA] = 8,
  1999. [AZX_DRIVER_TERA] = 1,
  2000. };
  2001. static int azx_probe_continue(struct azx *chip)
  2002. {
  2003. struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
  2004. struct hdac_bus *bus = azx_bus(chip);
  2005. struct pci_dev *pci = chip->pci;
  2006. int dev = chip->dev_index;
  2007. int err;
  2008. if (chip->disabled || hda->init_failed)
  2009. return -EIO;
  2010. if (hda->probe_retry)
  2011. goto probe_retry;
  2012. to_hda_bus(bus)->bus_probing = 1;
  2013. hda->probe_continued = 1;
  2014. /* Request display power well for the HDA controller or codec. For
  2015. * Haswell/Broadwell, both the display HDA controller and codec need
  2016. * this power. For other platforms, like Baytrail/Braswell, only the
  2017. * display codec needs the power and it can be released after probe.
  2018. */
  2019. display_power(chip, true);
  2020. err = azx_first_init(chip);
  2021. if (err < 0)
  2022. goto out_free;
  2023. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2024. chip->beep_mode = beep_mode[dev];
  2025. #endif
  2026. chip->ctl_dev_id = ctl_dev_id;
  2027. /* create codec instances */
  2028. if (bus->codec_mask) {
  2029. err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
  2030. if (err < 0)
  2031. goto out_free;
  2032. }
  2033. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  2034. if (chip->fw) {
  2035. err = snd_hda_load_patch(&chip->bus, chip->fw->size,
  2036. chip->fw->data);
  2037. if (err < 0)
  2038. goto out_free;
  2039. }
  2040. #endif
  2041. probe_retry:
  2042. if (bus->codec_mask && !(probe_only[dev] & 1)) {
  2043. err = azx_codec_configure(chip);
  2044. if (err) {
  2045. if ((chip->driver_caps & AZX_DCAPS_RETRY_PROBE) &&
  2046. ++hda->probe_retry < 60) {
  2047. schedule_delayed_work(&hda->probe_work,
  2048. msecs_to_jiffies(1000));
  2049. return 0; /* keep things up */
  2050. }
  2051. dev_err(chip->card->dev, "Cannot probe codecs, giving up\n");
  2052. goto out_free;
  2053. }
  2054. }
  2055. err = snd_card_register(chip->card);
  2056. if (err < 0)
  2057. goto out_free;
  2058. setup_vga_switcheroo_runtime_pm(chip);
  2059. chip->running = 1;
  2060. azx_add_card_list(chip);
  2061. set_default_power_save(chip);
  2062. if (azx_has_pm_runtime(chip)) {
  2063. pm_runtime_use_autosuspend(&pci->dev);
  2064. pm_runtime_allow(&pci->dev);
  2065. pm_runtime_put_autosuspend(&pci->dev);
  2066. }
  2067. out_free:
  2068. if (err < 0) {
  2069. pci_set_drvdata(pci, NULL);
  2070. snd_card_free(chip->card);
  2071. return err;
  2072. }
  2073. if (!hda->need_i915_power)
  2074. display_power(chip, false);
  2075. complete_all(&hda->probe_wait);
  2076. to_hda_bus(bus)->bus_probing = 0;
  2077. hda->probe_retry = 0;
  2078. return 0;
  2079. }
  2080. static void azx_remove(struct pci_dev *pci)
  2081. {
  2082. struct snd_card *card = pci_get_drvdata(pci);
  2083. struct azx *chip;
  2084. struct hda_intel *hda;
  2085. if (card) {
  2086. /* cancel the pending probing work */
  2087. chip = card->private_data;
  2088. hda = container_of(chip, struct hda_intel, chip);
  2089. /* FIXME: below is an ugly workaround.
  2090. * Both device_release_driver() and driver_probe_device()
  2091. * take *both* the device's and its parent's lock before
  2092. * calling the remove() and probe() callbacks. The codec
  2093. * probe takes the locks of both the codec itself and its
  2094. * parent, i.e. the PCI controller dev. Meanwhile, when
  2095. * the PCI controller is unbound, it takes its lock, too
  2096. * ==> ouch, a deadlock!
  2097. * As a workaround, we unlock temporarily here the controller
  2098. * device during cancel_work_sync() call.
  2099. */
  2100. device_unlock(&pci->dev);
  2101. cancel_delayed_work_sync(&hda->probe_work);
  2102. device_lock(&pci->dev);
  2103. clear_bit(chip->dev_index, probed_devs);
  2104. pci_set_drvdata(pci, NULL);
  2105. snd_card_free(card);
  2106. }
  2107. }
  2108. static void azx_shutdown(struct pci_dev *pci)
  2109. {
  2110. struct snd_card *card = pci_get_drvdata(pci);
  2111. struct azx *chip;
  2112. if (!card)
  2113. return;
  2114. chip = card->private_data;
  2115. if (chip && chip->running)
  2116. __azx_shutdown_chip(chip, true);
  2117. }
  2118. /* PCI IDs */
  2119. static const struct pci_device_id azx_ids[] = {
  2120. /* CPT */
  2121. { PCI_DEVICE_DATA(INTEL, HDA_CPT, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM) },
  2122. /* PBG */
  2123. { PCI_DEVICE_DATA(INTEL, HDA_PBG, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM) },
  2124. /* Panther Point */
  2125. { PCI_DEVICE_DATA(INTEL, HDA_PPT, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM) },
  2126. /* Lynx Point */
  2127. { PCI_DEVICE_DATA(INTEL, HDA_LPT, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2128. /* 9 Series */
  2129. { PCI_DEVICE_DATA(INTEL, HDA_9_SERIES, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2130. /* Wellsburg */
  2131. { PCI_DEVICE_DATA(INTEL, HDA_WBG_0, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2132. { PCI_DEVICE_DATA(INTEL, HDA_WBG_1, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2133. /* Lewisburg */
  2134. { PCI_DEVICE_DATA(INTEL, HDA_LBG_0, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE) },
  2135. { PCI_DEVICE_DATA(INTEL, HDA_LBG_1, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE) },
  2136. /* Lynx Point-LP */
  2137. { PCI_DEVICE_DATA(INTEL, HDA_LPT_LP_0, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2138. /* Lynx Point-LP */
  2139. { PCI_DEVICE_DATA(INTEL, HDA_LPT_LP_1, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2140. /* Wildcat Point-LP */
  2141. { PCI_DEVICE_DATA(INTEL, HDA_WPT_LP, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH) },
  2142. /* Skylake (Sunrise Point) */
  2143. { PCI_DEVICE_DATA(INTEL, HDA_SKL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2144. /* Skylake-LP (Sunrise Point-LP) */
  2145. { PCI_DEVICE_DATA(INTEL, HDA_SKL_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2146. /* Kabylake */
  2147. { PCI_DEVICE_DATA(INTEL, HDA_KBL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2148. /* Kabylake-LP */
  2149. { PCI_DEVICE_DATA(INTEL, HDA_KBL_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2150. /* Kabylake-H */
  2151. { PCI_DEVICE_DATA(INTEL, HDA_KBL_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2152. /* Coffelake */
  2153. { PCI_DEVICE_DATA(INTEL, HDA_CNL_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2154. /* Cannonlake */
  2155. { PCI_DEVICE_DATA(INTEL, HDA_CNL_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2156. /* CometLake-LP */
  2157. { PCI_DEVICE_DATA(INTEL, HDA_CML_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2158. /* CometLake-H */
  2159. { PCI_DEVICE_DATA(INTEL, HDA_CML_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2160. { PCI_DEVICE_DATA(INTEL, HDA_RKL_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2161. /* CometLake-S */
  2162. { PCI_DEVICE_DATA(INTEL, HDA_CML_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2163. /* CometLake-R */
  2164. { PCI_DEVICE_DATA(INTEL, HDA_CML_R, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2165. /* Icelake */
  2166. { PCI_DEVICE_DATA(INTEL, HDA_ICL_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2167. /* Icelake-H */
  2168. { PCI_DEVICE_DATA(INTEL, HDA_ICL_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2169. /* Jasperlake */
  2170. { PCI_DEVICE_DATA(INTEL, HDA_ICL_N, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2171. { PCI_DEVICE_DATA(INTEL, HDA_JSL_N, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2172. /* Tigerlake */
  2173. { PCI_DEVICE_DATA(INTEL, HDA_TGL_LP, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2174. /* Tigerlake-H */
  2175. { PCI_DEVICE_DATA(INTEL, HDA_TGL_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2176. /* DG1 */
  2177. { PCI_DEVICE_DATA(INTEL, HDA_DG1, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2178. /* DG2 */
  2179. { PCI_DEVICE_DATA(INTEL, HDA_DG2_0, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2180. { PCI_DEVICE_DATA(INTEL, HDA_DG2_1, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2181. { PCI_DEVICE_DATA(INTEL, HDA_DG2_2, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2182. /* Alderlake-S */
  2183. { PCI_DEVICE_DATA(INTEL, HDA_ADL_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2184. /* Alderlake-P */
  2185. { PCI_DEVICE_DATA(INTEL, HDA_ADL_P, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2186. { PCI_DEVICE_DATA(INTEL, HDA_ADL_PS, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2187. { PCI_DEVICE_DATA(INTEL, HDA_ADL_PX, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2188. /* Alderlake-M */
  2189. { PCI_DEVICE_DATA(INTEL, HDA_ADL_M, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2190. /* Alderlake-N */
  2191. { PCI_DEVICE_DATA(INTEL, HDA_ADL_N, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2192. /* Elkhart Lake */
  2193. { PCI_DEVICE_DATA(INTEL, HDA_EHL_0, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2194. { PCI_DEVICE_DATA(INTEL, HDA_EHL_3, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2195. /* Raptor Lake */
  2196. { PCI_DEVICE_DATA(INTEL, HDA_RPL_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2197. { PCI_DEVICE_DATA(INTEL, HDA_RPL_P_0, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2198. { PCI_DEVICE_DATA(INTEL, HDA_RPL_P_1, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2199. { PCI_DEVICE_DATA(INTEL, HDA_RPL_M, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2200. { PCI_DEVICE_DATA(INTEL, HDA_RPL_PX, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2201. { PCI_DEVICE_DATA(INTEL, HDA_MTL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2202. /* Battlemage */
  2203. { PCI_DEVICE_DATA(INTEL, HDA_BMG, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2204. /* Lunarlake-P */
  2205. { PCI_DEVICE_DATA(INTEL, HDA_LNL_P, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_LNL) },
  2206. /* Arrow Lake-S */
  2207. { PCI_DEVICE_DATA(INTEL, HDA_ARL_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2208. /* Arrow Lake */
  2209. { PCI_DEVICE_DATA(INTEL, HDA_ARL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE) },
  2210. /* Panther Lake */
  2211. { PCI_DEVICE_DATA(INTEL, HDA_PTL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_LNL) },
  2212. /* Panther Lake-H */
  2213. { PCI_DEVICE_DATA(INTEL, HDA_PTL_H, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_LNL) },
  2214. /* Wildcat Lake */
  2215. { PCI_DEVICE_DATA(INTEL, HDA_WCL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_LNL) },
  2216. /* Nova Lake */
  2217. { PCI_DEVICE_DATA(INTEL, HDA_NVL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_NVL) },
  2218. { PCI_DEVICE_DATA(INTEL, HDA_NVL_S, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_NVL) },
  2219. /* Apollolake (Broxton-P) */
  2220. { PCI_DEVICE_DATA(INTEL, HDA_APL, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_BROXTON) },
  2221. /* Gemini-Lake */
  2222. { PCI_DEVICE_DATA(INTEL, HDA_GLK, AZX_DRIVER_SKL | AZX_DCAPS_INTEL_BROXTON) },
  2223. /* Haswell */
  2224. { PCI_DEVICE_DATA(INTEL, HDA_HSW_0, AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL) },
  2225. { PCI_DEVICE_DATA(INTEL, HDA_HSW_2, AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL) },
  2226. { PCI_DEVICE_DATA(INTEL, HDA_HSW_3, AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL) },
  2227. /* Broadwell */
  2228. { PCI_DEVICE_DATA(INTEL, HDA_BDW, AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_BROADWELL) },
  2229. /* 5 Series/3400 */
  2230. { PCI_DEVICE_DATA(INTEL, HDA_5_3400_SERIES_0, AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM) },
  2231. { PCI_DEVICE_DATA(INTEL, HDA_5_3400_SERIES_1, AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM) },
  2232. /* Poulsbo */
  2233. { PCI_DEVICE_DATA(INTEL, HDA_POULSBO, AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE |
  2234. AZX_DCAPS_POSFIX_LPIB) },
  2235. /* Oaktrail */
  2236. { PCI_DEVICE_DATA(INTEL, HDA_OAKTRAIL, AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE) },
  2237. /* BayTrail */
  2238. { PCI_DEVICE_DATA(INTEL, HDA_BYT, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL) },
  2239. /* Braswell */
  2240. { PCI_DEVICE_DATA(INTEL, HDA_BSW, AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL) },
  2241. /* ICH6 */
  2242. { PCI_DEVICE_DATA(INTEL, HDA_ICH6, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2243. /* ICH7 */
  2244. { PCI_DEVICE_DATA(INTEL, HDA_ICH7, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2245. /* ESB2 */
  2246. { PCI_DEVICE_DATA(INTEL, HDA_ESB2, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2247. /* ICH8 */
  2248. { PCI_DEVICE_DATA(INTEL, HDA_ICH8, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2249. /* ICH9 */
  2250. { PCI_DEVICE_DATA(INTEL, HDA_ICH9_0, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2251. /* ICH9 */
  2252. { PCI_DEVICE_DATA(INTEL, HDA_ICH9_1, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2253. /* ICH10 */
  2254. { PCI_DEVICE_DATA(INTEL, HDA_ICH10_0, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2255. /* ICH10 */
  2256. { PCI_DEVICE_DATA(INTEL, HDA_ICH10_1, AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH) },
  2257. /* Generic Intel */
  2258. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
  2259. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2260. .class_mask = 0xffffff,
  2261. .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
  2262. /* ATI SB 450/600/700/800/900 */
  2263. { PCI_VDEVICE(ATI, 0x437b),
  2264. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2265. { PCI_VDEVICE(ATI, 0x4383),
  2266. .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
  2267. /* AMD Hudson */
  2268. { PCI_VDEVICE(AMD, 0x780d),
  2269. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
  2270. /* AMD, X370 & co */
  2271. { PCI_VDEVICE(AMD, 0x1457),
  2272. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_AMD_SB },
  2273. /* AMD, X570 & co */
  2274. { PCI_VDEVICE(AMD, 0x1487),
  2275. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_AMD_SB },
  2276. /* AMD Stoney */
  2277. { PCI_VDEVICE(AMD, 0x157a),
  2278. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
  2279. AZX_DCAPS_PM_RUNTIME },
  2280. /* AMD Raven */
  2281. { PCI_VDEVICE(AMD, 0x15e3),
  2282. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_AMD_SB },
  2283. /* ATI HDMI */
  2284. { PCI_VDEVICE(ATI, 0x0002),
  2285. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2286. AZX_DCAPS_PM_RUNTIME },
  2287. { PCI_VDEVICE(ATI, 0x1308),
  2288. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2289. { PCI_VDEVICE(ATI, 0x157a),
  2290. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2291. { PCI_VDEVICE(ATI, 0x15b3),
  2292. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2293. { PCI_VDEVICE(ATI, 0x793b),
  2294. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2295. { PCI_VDEVICE(ATI, 0x7919),
  2296. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2297. { PCI_VDEVICE(ATI, 0x960f),
  2298. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2299. { PCI_VDEVICE(ATI, 0x970f),
  2300. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2301. { PCI_VDEVICE(ATI, 0x9840),
  2302. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2303. { PCI_VDEVICE(ATI, 0xaa00),
  2304. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2305. { PCI_VDEVICE(ATI, 0xaa08),
  2306. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2307. { PCI_VDEVICE(ATI, 0xaa10),
  2308. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2309. { PCI_VDEVICE(ATI, 0xaa18),
  2310. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2311. { PCI_VDEVICE(ATI, 0xaa20),
  2312. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2313. { PCI_VDEVICE(ATI, 0xaa28),
  2314. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2315. { PCI_VDEVICE(ATI, 0xaa30),
  2316. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2317. { PCI_VDEVICE(ATI, 0xaa38),
  2318. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2319. { PCI_VDEVICE(ATI, 0xaa40),
  2320. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2321. { PCI_VDEVICE(ATI, 0xaa48),
  2322. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2323. { PCI_VDEVICE(ATI, 0xaa50),
  2324. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2325. { PCI_VDEVICE(ATI, 0xaa58),
  2326. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2327. { PCI_VDEVICE(ATI, 0xaa60),
  2328. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2329. { PCI_VDEVICE(ATI, 0xaa68),
  2330. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2331. { PCI_VDEVICE(ATI, 0xaa80),
  2332. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2333. { PCI_VDEVICE(ATI, 0xaa88),
  2334. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2335. { PCI_VDEVICE(ATI, 0xaa90),
  2336. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2337. { PCI_VDEVICE(ATI, 0xaa98),
  2338. .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
  2339. { PCI_VDEVICE(ATI, 0x9902),
  2340. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2341. { PCI_VDEVICE(ATI, 0xaaa0),
  2342. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2343. { PCI_VDEVICE(ATI, 0xaaa8),
  2344. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2345. { PCI_VDEVICE(ATI, 0xaab0),
  2346. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
  2347. { PCI_VDEVICE(ATI, 0xaac0),
  2348. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2349. AZX_DCAPS_PM_RUNTIME },
  2350. { PCI_VDEVICE(ATI, 0xaac8),
  2351. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2352. AZX_DCAPS_PM_RUNTIME },
  2353. { PCI_VDEVICE(ATI, 0xaad8),
  2354. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2355. AZX_DCAPS_PM_RUNTIME },
  2356. { PCI_VDEVICE(ATI, 0xaae0),
  2357. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2358. AZX_DCAPS_PM_RUNTIME },
  2359. { PCI_VDEVICE(ATI, 0xaae8),
  2360. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2361. AZX_DCAPS_PM_RUNTIME },
  2362. { PCI_VDEVICE(ATI, 0xaaf0),
  2363. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2364. AZX_DCAPS_PM_RUNTIME },
  2365. { PCI_VDEVICE(ATI, 0xaaf8),
  2366. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2367. AZX_DCAPS_PM_RUNTIME },
  2368. { PCI_VDEVICE(ATI, 0xab00),
  2369. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2370. AZX_DCAPS_PM_RUNTIME },
  2371. { PCI_VDEVICE(ATI, 0xab08),
  2372. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2373. AZX_DCAPS_PM_RUNTIME },
  2374. { PCI_VDEVICE(ATI, 0xab10),
  2375. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2376. AZX_DCAPS_PM_RUNTIME },
  2377. { PCI_VDEVICE(ATI, 0xab18),
  2378. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2379. AZX_DCAPS_PM_RUNTIME },
  2380. { PCI_VDEVICE(ATI, 0xab20),
  2381. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2382. AZX_DCAPS_PM_RUNTIME },
  2383. { PCI_VDEVICE(ATI, 0xab28),
  2384. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2385. AZX_DCAPS_PM_RUNTIME },
  2386. { PCI_VDEVICE(ATI, 0xab30),
  2387. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2388. AZX_DCAPS_PM_RUNTIME },
  2389. { PCI_VDEVICE(ATI, 0xab38),
  2390. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2391. AZX_DCAPS_PM_RUNTIME },
  2392. { PCI_VDEVICE(ATI, 0xab40),
  2393. .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS |
  2394. AZX_DCAPS_PM_RUNTIME },
  2395. /* GLENFLY */
  2396. { PCI_DEVICE(PCI_VENDOR_ID_GLENFLY, PCI_ANY_ID),
  2397. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2398. .class_mask = 0xffffff,
  2399. .driver_data = AZX_DRIVER_GFHDMI | AZX_DCAPS_POSFIX_LPIB |
  2400. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2401. /* VIA VT8251/VT8237A */
  2402. { PCI_VDEVICE(VIA, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2403. /* VIA GFX VT7122/VX900 */
  2404. { PCI_VDEVICE(VIA, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
  2405. /* VIA GFX VT6122/VX11 */
  2406. { PCI_VDEVICE(VIA, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
  2407. /* SIS966 */
  2408. { PCI_VDEVICE(SI, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2409. /* ULI M5461 */
  2410. { PCI_VDEVICE(AL, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2411. /* NVIDIA MCP */
  2412. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2413. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2414. .class_mask = 0xffffff,
  2415. .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
  2416. /* Teradici */
  2417. { PCI_DEVICE(0x6549, 0x1200),
  2418. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2419. { PCI_DEVICE(0x6549, 0x2200),
  2420. .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
  2421. /* Creative X-Fi (CA0110-IBG) */
  2422. /* CTHDA chips */
  2423. { PCI_VDEVICE(CREATIVE, 0x0010),
  2424. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2425. { PCI_VDEVICE(CREATIVE, 0x0012),
  2426. .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
  2427. #if !IS_ENABLED(CONFIG_SND_CTXFI)
  2428. /* the following entry conflicts with snd-ctxfi driver,
  2429. * as ctxfi driver mutates from HD-audio to native mode with
  2430. * a special command sequence.
  2431. */
  2432. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2433. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2434. .class_mask = 0xffffff,
  2435. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2436. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2437. #else
  2438. /* this entry seems still valid -- i.e. without emu20kx chip */
  2439. { PCI_VDEVICE(CREATIVE, 0x0009),
  2440. .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
  2441. AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
  2442. #endif
  2443. /* CM8888 */
  2444. { PCI_VDEVICE(CMEDIA, 0x5011),
  2445. .driver_data = AZX_DRIVER_CMEDIA |
  2446. AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
  2447. /* Vortex86MX */
  2448. { PCI_VDEVICE(RDC, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
  2449. /* VMware HDAudio */
  2450. { PCI_VDEVICE(VMWARE, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
  2451. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2452. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2453. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2454. .class_mask = 0xffffff,
  2455. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2456. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2457. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2458. .class_mask = 0xffffff,
  2459. .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
  2460. /* Zhaoxin */
  2461. { PCI_VDEVICE(ZHAOXIN, 0x3288), .driver_data = AZX_DRIVER_ZHAOXIN },
  2462. { PCI_VDEVICE(ZHAOXIN, 0x9141),
  2463. .driver_data = AZX_DRIVER_ZHAOXINHDMI | AZX_DCAPS_POSFIX_LPIB |
  2464. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2465. { PCI_VDEVICE(ZHAOXIN, 0x9142),
  2466. .driver_data = AZX_DRIVER_ZHAOXINHDMI | AZX_DCAPS_POSFIX_LPIB |
  2467. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2468. { PCI_VDEVICE(ZHAOXIN, 0x9144),
  2469. .driver_data = AZX_DRIVER_ZHAOXINHDMI | AZX_DCAPS_POSFIX_LPIB |
  2470. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2471. { PCI_VDEVICE(ZHAOXIN, 0x9145),
  2472. .driver_data = AZX_DRIVER_ZHAOXINHDMI | AZX_DCAPS_POSFIX_LPIB |
  2473. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2474. { PCI_VDEVICE(ZHAOXIN, 0x9146),
  2475. .driver_data = AZX_DRIVER_ZHAOXINHDMI | AZX_DCAPS_POSFIX_LPIB |
  2476. AZX_DCAPS_NO_MSI | AZX_DCAPS_NO_64BIT },
  2477. /* Loongson HDAudio*/
  2478. { PCI_VDEVICE(LOONGSON, PCI_DEVICE_ID_LOONGSON_HDA),
  2479. .driver_data = AZX_DRIVER_LOONGSON | AZX_DCAPS_NO_TCSEL },
  2480. { PCI_VDEVICE(LOONGSON, PCI_DEVICE_ID_LOONGSON_HDMI),
  2481. .driver_data = AZX_DRIVER_LOONGSON | AZX_DCAPS_NO_TCSEL },
  2482. { 0, }
  2483. };
  2484. MODULE_DEVICE_TABLE(pci, azx_ids);
  2485. /* pci_driver definition */
  2486. static struct pci_driver azx_driver = {
  2487. .name = KBUILD_MODNAME,
  2488. .id_table = azx_ids,
  2489. .probe = azx_probe,
  2490. .remove = azx_remove,
  2491. .shutdown = azx_shutdown,
  2492. .driver = {
  2493. .pm = pm_ptr(&azx_pm),
  2494. },
  2495. };
  2496. module_pci_driver(azx_driver);