hda_intel.c 68 KB

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