hda_intel.c 59 KB

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