hda_intel.c 80 KB

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