hda_intel.c 53 KB

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