hda_intel.c 60 KB

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