hda_intel.c 75 KB

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