hda_intel.c 63 KB

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