hda_intel.c 59 KB

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