hda_intel.c 67 KB

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