hda_intel.c 77 KB

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