hda_intel.c 75 KB

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