hda_intel.c 60 KB

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