hda_intel.c 53 KB

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