hda_intel.c 59 KB

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