hda_intel.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  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 <asm/io.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/kernel.h>
  40. #include <linux/module.h>
  41. #include <linux/dma-mapping.h>
  42. #include <linux/moduleparam.h>
  43. #include <linux/init.h>
  44. #include <linux/slab.h>
  45. #include <linux/pci.h>
  46. #include <linux/mutex.h>
  47. #include <sound/core.h>
  48. #include <sound/initval.h>
  49. #include "hda_codec.h"
  50. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  51. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  52. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  53. static char *model[SNDRV_CARDS];
  54. static int position_fix[SNDRV_CARDS];
  55. static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  56. static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  57. static int single_cmd;
  58. static int enable_msi;
  59. module_param_array(index, int, NULL, 0444);
  60. MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
  61. module_param_array(id, charp, NULL, 0444);
  62. MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
  63. module_param_array(enable, bool, NULL, 0444);
  64. MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
  65. module_param_array(model, charp, NULL, 0444);
  66. MODULE_PARM_DESC(model, "Use the given board model.");
  67. module_param_array(position_fix, int, NULL, 0444);
  68. MODULE_PARM_DESC(position_fix, "Fix DMA pointer "
  69. "(0 = auto, 1 = none, 2 = POSBUF).");
  70. module_param_array(bdl_pos_adj, int, NULL, 0644);
  71. MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
  72. module_param_array(probe_mask, int, NULL, 0444);
  73. MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
  74. module_param(single_cmd, bool, 0444);
  75. MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
  76. "(for debugging only).");
  77. module_param(enable_msi, int, 0444);
  78. MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
  79. #ifdef CONFIG_SND_HDA_POWER_SAVE
  80. /* power_save option is defined in hda_codec.c */
  81. /* reset the HD-audio controller in power save mode.
  82. * this may give more power-saving, but will take longer time to
  83. * wake up.
  84. */
  85. static int power_save_controller = 1;
  86. module_param(power_save_controller, bool, 0644);
  87. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  88. #endif
  89. MODULE_LICENSE("GPL");
  90. MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
  91. "{Intel, ICH6M},"
  92. "{Intel, ICH7},"
  93. "{Intel, ESB2},"
  94. "{Intel, ICH8},"
  95. "{Intel, ICH9},"
  96. "{Intel, ICH10},"
  97. "{Intel, SCH},"
  98. "{ATI, SB450},"
  99. "{ATI, SB600},"
  100. "{ATI, RS600},"
  101. "{ATI, RS690},"
  102. "{ATI, RS780},"
  103. "{ATI, R600},"
  104. "{ATI, RV630},"
  105. "{ATI, RV610},"
  106. "{ATI, RV670},"
  107. "{ATI, RV635},"
  108. "{ATI, RV620},"
  109. "{ATI, RV770},"
  110. "{VIA, VT8251},"
  111. "{VIA, VT8237A},"
  112. "{SiS, SIS966},"
  113. "{ULI, M5461}}");
  114. MODULE_DESCRIPTION("Intel HDA driver");
  115. #define SFX "hda-intel: "
  116. /*
  117. * registers
  118. */
  119. #define ICH6_REG_GCAP 0x00
  120. #define ICH6_REG_VMIN 0x02
  121. #define ICH6_REG_VMAJ 0x03
  122. #define ICH6_REG_OUTPAY 0x04
  123. #define ICH6_REG_INPAY 0x06
  124. #define ICH6_REG_GCTL 0x08
  125. #define ICH6_REG_WAKEEN 0x0c
  126. #define ICH6_REG_STATESTS 0x0e
  127. #define ICH6_REG_GSTS 0x10
  128. #define ICH6_REG_INTCTL 0x20
  129. #define ICH6_REG_INTSTS 0x24
  130. #define ICH6_REG_WALCLK 0x30
  131. #define ICH6_REG_SYNC 0x34
  132. #define ICH6_REG_CORBLBASE 0x40
  133. #define ICH6_REG_CORBUBASE 0x44
  134. #define ICH6_REG_CORBWP 0x48
  135. #define ICH6_REG_CORBRP 0x4A
  136. #define ICH6_REG_CORBCTL 0x4c
  137. #define ICH6_REG_CORBSTS 0x4d
  138. #define ICH6_REG_CORBSIZE 0x4e
  139. #define ICH6_REG_RIRBLBASE 0x50
  140. #define ICH6_REG_RIRBUBASE 0x54
  141. #define ICH6_REG_RIRBWP 0x58
  142. #define ICH6_REG_RINTCNT 0x5a
  143. #define ICH6_REG_RIRBCTL 0x5c
  144. #define ICH6_REG_RIRBSTS 0x5d
  145. #define ICH6_REG_RIRBSIZE 0x5e
  146. #define ICH6_REG_IC 0x60
  147. #define ICH6_REG_IR 0x64
  148. #define ICH6_REG_IRS 0x68
  149. #define ICH6_IRS_VALID (1<<1)
  150. #define ICH6_IRS_BUSY (1<<0)
  151. #define ICH6_REG_DPLBASE 0x70
  152. #define ICH6_REG_DPUBASE 0x74
  153. #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  154. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  155. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  156. /* stream register offsets from stream base */
  157. #define ICH6_REG_SD_CTL 0x00
  158. #define ICH6_REG_SD_STS 0x03
  159. #define ICH6_REG_SD_LPIB 0x04
  160. #define ICH6_REG_SD_CBL 0x08
  161. #define ICH6_REG_SD_LVI 0x0c
  162. #define ICH6_REG_SD_FIFOW 0x0e
  163. #define ICH6_REG_SD_FIFOSIZE 0x10
  164. #define ICH6_REG_SD_FORMAT 0x12
  165. #define ICH6_REG_SD_BDLPL 0x18
  166. #define ICH6_REG_SD_BDLPU 0x1c
  167. /* PCI space */
  168. #define ICH6_PCIREG_TCSEL 0x44
  169. /*
  170. * other constants
  171. */
  172. /* max number of SDs */
  173. /* ICH, ATI and VIA have 4 playback and 4 capture */
  174. #define ICH6_NUM_CAPTURE 4
  175. #define ICH6_NUM_PLAYBACK 4
  176. /* ULI has 6 playback and 5 capture */
  177. #define ULI_NUM_CAPTURE 5
  178. #define ULI_NUM_PLAYBACK 6
  179. /* ATI HDMI has 1 playback and 0 capture */
  180. #define ATIHDMI_NUM_CAPTURE 0
  181. #define ATIHDMI_NUM_PLAYBACK 1
  182. /* TERA has 4 playback and 3 capture */
  183. #define TERA_NUM_CAPTURE 3
  184. #define TERA_NUM_PLAYBACK 4
  185. /* this number is statically defined for simplicity */
  186. #define MAX_AZX_DEV 16
  187. /* max number of fragments - we may use more if allocating more pages for BDL */
  188. #define BDL_SIZE 4096
  189. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  190. #define AZX_MAX_FRAG 32
  191. /* max buffer size - no h/w limit, you can increase as you like */
  192. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  193. /* max number of PCM devics per card */
  194. #define AZX_MAX_PCMS 8
  195. /* RIRB int mask: overrun[2], response[0] */
  196. #define RIRB_INT_RESPONSE 0x01
  197. #define RIRB_INT_OVERRUN 0x04
  198. #define RIRB_INT_MASK 0x05
  199. /* STATESTS int mask: SD2,SD1,SD0 */
  200. #define AZX_MAX_CODECS 3
  201. #define STATESTS_INT_MASK 0x07
  202. /* SD_CTL bits */
  203. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  204. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  205. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  206. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  207. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  208. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  209. #define SD_CTL_STREAM_TAG_SHIFT 20
  210. /* SD_CTL and SD_STS */
  211. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  212. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  213. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  214. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  215. SD_INT_COMPLETE)
  216. /* SD_STS */
  217. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  218. /* INTCTL and INTSTS */
  219. #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
  220. #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  221. #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  222. /* GCTL unsolicited response enable bit */
  223. #define ICH6_GCTL_UREN (1<<8)
  224. /* GCTL reset bit */
  225. #define ICH6_GCTL_RESET (1<<0)
  226. /* CORB/RIRB control, read/write pointer */
  227. #define ICH6_RBCTL_DMA_EN 0x02 /* enable DMA */
  228. #define ICH6_RBCTL_IRQ_EN 0x01 /* enable IRQ */
  229. #define ICH6_RBRWP_CLR 0x8000 /* read/write pointer clear */
  230. /* below are so far hardcoded - should read registers in future */
  231. #define ICH6_MAX_CORB_ENTRIES 256
  232. #define ICH6_MAX_RIRB_ENTRIES 256
  233. /* position fix mode */
  234. enum {
  235. POS_FIX_AUTO,
  236. POS_FIX_LPIB,
  237. POS_FIX_POSBUF,
  238. };
  239. /* Defines for ATI HD Audio support in SB450 south bridge */
  240. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  241. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  242. /* Defines for Nvidia HDA support */
  243. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  244. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  245. /* Defines for Intel SCH HDA snoop control */
  246. #define INTEL_SCH_HDA_DEVC 0x78
  247. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  248. /*
  249. */
  250. struct azx_dev {
  251. struct snd_dma_buffer bdl; /* BDL buffer */
  252. u32 *posbuf; /* position buffer pointer */
  253. unsigned int bufsize; /* size of the play buffer in bytes */
  254. unsigned int period_bytes; /* size of the period in bytes */
  255. unsigned int frags; /* number for period in the play buffer */
  256. unsigned int fifo_size; /* FIFO size */
  257. void __iomem *sd_addr; /* stream descriptor pointer */
  258. u32 sd_int_sta_mask; /* stream int status mask */
  259. /* pcm support */
  260. struct snd_pcm_substream *substream; /* assigned substream,
  261. * set in PCM open
  262. */
  263. unsigned int format_val; /* format value to be set in the
  264. * controller and the codec
  265. */
  266. unsigned char stream_tag; /* assigned stream */
  267. unsigned char index; /* stream index */
  268. unsigned int opened :1;
  269. unsigned int running :1;
  270. unsigned int irq_pending :1;
  271. unsigned int irq_ignore :1;
  272. };
  273. /* CORB/RIRB */
  274. struct azx_rb {
  275. u32 *buf; /* CORB/RIRB buffer
  276. * Each CORB entry is 4byte, RIRB is 8byte
  277. */
  278. dma_addr_t addr; /* physical address of CORB/RIRB buffer */
  279. /* for RIRB */
  280. unsigned short rp, wp; /* read/write pointers */
  281. int cmds; /* number of pending requests */
  282. u32 res; /* last read value */
  283. };
  284. struct azx {
  285. struct snd_card *card;
  286. struct pci_dev *pci;
  287. int dev_index;
  288. /* chip type specific */
  289. int driver_type;
  290. int playback_streams;
  291. int playback_index_offset;
  292. int capture_streams;
  293. int capture_index_offset;
  294. int num_streams;
  295. /* pci resources */
  296. unsigned long addr;
  297. void __iomem *remap_addr;
  298. int irq;
  299. /* locks */
  300. spinlock_t reg_lock;
  301. struct mutex open_mutex;
  302. /* streams (x num_streams) */
  303. struct azx_dev *azx_dev;
  304. /* PCM */
  305. struct snd_pcm *pcm[AZX_MAX_PCMS];
  306. /* HD codec */
  307. unsigned short codec_mask;
  308. struct hda_bus *bus;
  309. /* CORB/RIRB */
  310. struct azx_rb corb;
  311. struct azx_rb rirb;
  312. /* CORB/RIRB and position buffers */
  313. struct snd_dma_buffer rb;
  314. struct snd_dma_buffer posbuf;
  315. /* flags */
  316. int position_fix;
  317. unsigned int running :1;
  318. unsigned int initialized :1;
  319. unsigned int single_cmd :1;
  320. unsigned int polling_mode :1;
  321. unsigned int msi :1;
  322. unsigned int irq_pending_warned :1;
  323. /* for debugging */
  324. unsigned int last_cmd; /* last issued command (to sync) */
  325. /* for pending irqs */
  326. struct work_struct irq_pending_work;
  327. };
  328. /* driver types */
  329. enum {
  330. AZX_DRIVER_ICH,
  331. AZX_DRIVER_SCH,
  332. AZX_DRIVER_ATI,
  333. AZX_DRIVER_ATIHDMI,
  334. AZX_DRIVER_VIA,
  335. AZX_DRIVER_SIS,
  336. AZX_DRIVER_ULI,
  337. AZX_DRIVER_NVIDIA,
  338. AZX_DRIVER_TERA,
  339. };
  340. static char *driver_short_names[] __devinitdata = {
  341. [AZX_DRIVER_ICH] = "HDA Intel",
  342. [AZX_DRIVER_SCH] = "HDA Intel MID",
  343. [AZX_DRIVER_ATI] = "HDA ATI SB",
  344. [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
  345. [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
  346. [AZX_DRIVER_SIS] = "HDA SIS966",
  347. [AZX_DRIVER_ULI] = "HDA ULI M5461",
  348. [AZX_DRIVER_NVIDIA] = "HDA NVidia",
  349. [AZX_DRIVER_TERA] = "HDA Teradici",
  350. };
  351. /*
  352. * macros for easy use
  353. */
  354. #define azx_writel(chip,reg,value) \
  355. writel(value, (chip)->remap_addr + ICH6_REG_##reg)
  356. #define azx_readl(chip,reg) \
  357. readl((chip)->remap_addr + ICH6_REG_##reg)
  358. #define azx_writew(chip,reg,value) \
  359. writew(value, (chip)->remap_addr + ICH6_REG_##reg)
  360. #define azx_readw(chip,reg) \
  361. readw((chip)->remap_addr + ICH6_REG_##reg)
  362. #define azx_writeb(chip,reg,value) \
  363. writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
  364. #define azx_readb(chip,reg) \
  365. readb((chip)->remap_addr + ICH6_REG_##reg)
  366. #define azx_sd_writel(dev,reg,value) \
  367. writel(value, (dev)->sd_addr + ICH6_REG_##reg)
  368. #define azx_sd_readl(dev,reg) \
  369. readl((dev)->sd_addr + ICH6_REG_##reg)
  370. #define azx_sd_writew(dev,reg,value) \
  371. writew(value, (dev)->sd_addr + ICH6_REG_##reg)
  372. #define azx_sd_readw(dev,reg) \
  373. readw((dev)->sd_addr + ICH6_REG_##reg)
  374. #define azx_sd_writeb(dev,reg,value) \
  375. writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
  376. #define azx_sd_readb(dev,reg) \
  377. readb((dev)->sd_addr + ICH6_REG_##reg)
  378. /* for pcm support */
  379. #define get_azx_dev(substream) (substream->runtime->private_data)
  380. static int azx_acquire_irq(struct azx *chip, int do_disconnect);
  381. /*
  382. * Interface for HD codec
  383. */
  384. /*
  385. * CORB / RIRB interface
  386. */
  387. static int azx_alloc_cmd_io(struct azx *chip)
  388. {
  389. int err;
  390. /* single page (at least 4096 bytes) must suffice for both ringbuffes */
  391. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  392. snd_dma_pci_data(chip->pci),
  393. PAGE_SIZE, &chip->rb);
  394. if (err < 0) {
  395. snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
  396. return err;
  397. }
  398. return 0;
  399. }
  400. static void azx_init_cmd_io(struct azx *chip)
  401. {
  402. /* CORB set up */
  403. chip->corb.addr = chip->rb.addr;
  404. chip->corb.buf = (u32 *)chip->rb.area;
  405. azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
  406. azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
  407. /* set the corb size to 256 entries (ULI requires explicitly) */
  408. azx_writeb(chip, CORBSIZE, 0x02);
  409. /* set the corb write pointer to 0 */
  410. azx_writew(chip, CORBWP, 0);
  411. /* reset the corb hw read pointer */
  412. azx_writew(chip, CORBRP, ICH6_RBRWP_CLR);
  413. /* enable corb dma */
  414. azx_writeb(chip, CORBCTL, ICH6_RBCTL_DMA_EN);
  415. /* RIRB set up */
  416. chip->rirb.addr = chip->rb.addr + 2048;
  417. chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
  418. azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
  419. azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
  420. /* set the rirb size to 256 entries (ULI requires explicitly) */
  421. azx_writeb(chip, RIRBSIZE, 0x02);
  422. /* reset the rirb hw write pointer */
  423. azx_writew(chip, RIRBWP, ICH6_RBRWP_CLR);
  424. /* set N=1, get RIRB response interrupt for new entry */
  425. azx_writew(chip, RINTCNT, 1);
  426. /* enable rirb dma and response irq */
  427. azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
  428. chip->rirb.rp = chip->rirb.cmds = 0;
  429. }
  430. static void azx_free_cmd_io(struct azx *chip)
  431. {
  432. /* disable ringbuffer DMAs */
  433. azx_writeb(chip, RIRBCTL, 0);
  434. azx_writeb(chip, CORBCTL, 0);
  435. }
  436. /* send a command */
  437. static int azx_corb_send_cmd(struct hda_codec *codec, u32 val)
  438. {
  439. struct azx *chip = codec->bus->private_data;
  440. unsigned int wp;
  441. /* add command to corb */
  442. wp = azx_readb(chip, CORBWP);
  443. wp++;
  444. wp %= ICH6_MAX_CORB_ENTRIES;
  445. spin_lock_irq(&chip->reg_lock);
  446. chip->rirb.cmds++;
  447. chip->corb.buf[wp] = cpu_to_le32(val);
  448. azx_writel(chip, CORBWP, wp);
  449. spin_unlock_irq(&chip->reg_lock);
  450. return 0;
  451. }
  452. #define ICH6_RIRB_EX_UNSOL_EV (1<<4)
  453. /* retrieve RIRB entry - called from interrupt handler */
  454. static void azx_update_rirb(struct azx *chip)
  455. {
  456. unsigned int rp, wp;
  457. u32 res, res_ex;
  458. wp = azx_readb(chip, RIRBWP);
  459. if (wp == chip->rirb.wp)
  460. return;
  461. chip->rirb.wp = wp;
  462. while (chip->rirb.rp != wp) {
  463. chip->rirb.rp++;
  464. chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
  465. rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
  466. res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
  467. res = le32_to_cpu(chip->rirb.buf[rp]);
  468. if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
  469. snd_hda_queue_unsol_event(chip->bus, res, res_ex);
  470. else if (chip->rirb.cmds) {
  471. chip->rirb.res = res;
  472. smp_wmb();
  473. chip->rirb.cmds--;
  474. }
  475. }
  476. }
  477. /* receive a response */
  478. static unsigned int azx_rirb_get_response(struct hda_codec *codec)
  479. {
  480. struct azx *chip = codec->bus->private_data;
  481. unsigned long timeout;
  482. again:
  483. timeout = jiffies + msecs_to_jiffies(1000);
  484. for (;;) {
  485. if (chip->polling_mode) {
  486. spin_lock_irq(&chip->reg_lock);
  487. azx_update_rirb(chip);
  488. spin_unlock_irq(&chip->reg_lock);
  489. }
  490. if (!chip->rirb.cmds) {
  491. smp_rmb();
  492. return chip->rirb.res; /* the last value */
  493. }
  494. if (time_after(jiffies, timeout))
  495. break;
  496. if (codec->bus->needs_damn_long_delay)
  497. msleep(2); /* temporary workaround */
  498. else {
  499. udelay(10);
  500. cond_resched();
  501. }
  502. }
  503. if (chip->msi) {
  504. snd_printk(KERN_WARNING "hda_intel: No response from codec, "
  505. "disabling MSI: last cmd=0x%08x\n", chip->last_cmd);
  506. free_irq(chip->irq, chip);
  507. chip->irq = -1;
  508. pci_disable_msi(chip->pci);
  509. chip->msi = 0;
  510. if (azx_acquire_irq(chip, 1) < 0)
  511. return -1;
  512. goto again;
  513. }
  514. if (!chip->polling_mode) {
  515. snd_printk(KERN_WARNING "hda_intel: azx_get_response timeout, "
  516. "switching to polling mode: last cmd=0x%08x\n",
  517. chip->last_cmd);
  518. chip->polling_mode = 1;
  519. goto again;
  520. }
  521. snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
  522. "switching to single_cmd mode: last cmd=0x%08x\n",
  523. chip->last_cmd);
  524. chip->rirb.rp = azx_readb(chip, RIRBWP);
  525. chip->rirb.cmds = 0;
  526. /* switch to single_cmd mode */
  527. chip->single_cmd = 1;
  528. azx_free_cmd_io(chip);
  529. return -1;
  530. }
  531. /*
  532. * Use the single immediate command instead of CORB/RIRB for simplicity
  533. *
  534. * Note: according to Intel, this is not preferred use. The command was
  535. * intended for the BIOS only, and may get confused with unsolicited
  536. * responses. So, we shouldn't use it for normal operation from the
  537. * driver.
  538. * I left the codes, however, for debugging/testing purposes.
  539. */
  540. /* send a command */
  541. static int azx_single_send_cmd(struct hda_codec *codec, u32 val)
  542. {
  543. struct azx *chip = codec->bus->private_data;
  544. int timeout = 50;
  545. while (timeout--) {
  546. /* check ICB busy bit */
  547. if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
  548. /* Clear IRV valid bit */
  549. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  550. ICH6_IRS_VALID);
  551. azx_writel(chip, IC, val);
  552. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  553. ICH6_IRS_BUSY);
  554. return 0;
  555. }
  556. udelay(1);
  557. }
  558. if (printk_ratelimit())
  559. snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",
  560. azx_readw(chip, IRS), val);
  561. return -EIO;
  562. }
  563. /* receive a response */
  564. static unsigned int azx_single_get_response(struct hda_codec *codec)
  565. {
  566. struct azx *chip = codec->bus->private_data;
  567. int timeout = 50;
  568. while (timeout--) {
  569. /* check IRV busy bit */
  570. if (azx_readw(chip, IRS) & ICH6_IRS_VALID)
  571. return azx_readl(chip, IR);
  572. udelay(1);
  573. }
  574. if (printk_ratelimit())
  575. snd_printd(SFX "get_response timeout: IRS=0x%x\n",
  576. azx_readw(chip, IRS));
  577. return (unsigned int)-1;
  578. }
  579. /*
  580. * The below are the main callbacks from hda_codec.
  581. *
  582. * They are just the skeleton to call sub-callbacks according to the
  583. * current setting of chip->single_cmd.
  584. */
  585. /* send a command */
  586. static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid,
  587. int direct, unsigned int verb,
  588. unsigned int para)
  589. {
  590. struct azx *chip = codec->bus->private_data;
  591. u32 val;
  592. val = (u32)(codec->addr & 0x0f) << 28;
  593. val |= (u32)direct << 27;
  594. val |= (u32)nid << 20;
  595. val |= verb << 8;
  596. val |= para;
  597. chip->last_cmd = val;
  598. if (chip->single_cmd)
  599. return azx_single_send_cmd(codec, val);
  600. else
  601. return azx_corb_send_cmd(codec, val);
  602. }
  603. /* get a response */
  604. static unsigned int azx_get_response(struct hda_codec *codec)
  605. {
  606. struct azx *chip = codec->bus->private_data;
  607. if (chip->single_cmd)
  608. return azx_single_get_response(codec);
  609. else
  610. return azx_rirb_get_response(codec);
  611. }
  612. #ifdef CONFIG_SND_HDA_POWER_SAVE
  613. static void azx_power_notify(struct hda_codec *codec);
  614. #endif
  615. /* reset codec link */
  616. static int azx_reset(struct azx *chip)
  617. {
  618. int count;
  619. /* clear STATESTS */
  620. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  621. /* reset controller */
  622. azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
  623. count = 50;
  624. while (azx_readb(chip, GCTL) && --count)
  625. msleep(1);
  626. /* delay for >= 100us for codec PLL to settle per spec
  627. * Rev 0.9 section 5.5.1
  628. */
  629. msleep(1);
  630. /* Bring controller out of reset */
  631. azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
  632. count = 50;
  633. while (!azx_readb(chip, GCTL) && --count)
  634. msleep(1);
  635. /* Brent Chartrand said to wait >= 540us for codecs to initialize */
  636. msleep(1);
  637. /* check to see if controller is ready */
  638. if (!azx_readb(chip, GCTL)) {
  639. snd_printd("azx_reset: controller not ready!\n");
  640. return -EBUSY;
  641. }
  642. /* Accept unsolicited responses */
  643. azx_writel(chip, GCTL, azx_readl(chip, GCTL) | ICH6_GCTL_UREN);
  644. /* detect codecs */
  645. if (!chip->codec_mask) {
  646. chip->codec_mask = azx_readw(chip, STATESTS);
  647. snd_printdd("codec_mask = 0x%x\n", chip->codec_mask);
  648. }
  649. return 0;
  650. }
  651. /*
  652. * Lowlevel interface
  653. */
  654. /* enable interrupts */
  655. static void azx_int_enable(struct azx *chip)
  656. {
  657. /* enable controller CIE and GIE */
  658. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
  659. ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
  660. }
  661. /* disable interrupts */
  662. static void azx_int_disable(struct azx *chip)
  663. {
  664. int i;
  665. /* disable interrupts in stream descriptor */
  666. for (i = 0; i < chip->num_streams; i++) {
  667. struct azx_dev *azx_dev = &chip->azx_dev[i];
  668. azx_sd_writeb(azx_dev, SD_CTL,
  669. azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
  670. }
  671. /* disable SIE for all streams */
  672. azx_writeb(chip, INTCTL, 0);
  673. /* disable controller CIE and GIE */
  674. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
  675. ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
  676. }
  677. /* clear interrupts */
  678. static void azx_int_clear(struct azx *chip)
  679. {
  680. int i;
  681. /* clear stream status */
  682. for (i = 0; i < chip->num_streams; i++) {
  683. struct azx_dev *azx_dev = &chip->azx_dev[i];
  684. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  685. }
  686. /* clear STATESTS */
  687. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  688. /* clear rirb status */
  689. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  690. /* clear int status */
  691. azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
  692. }
  693. /* start a stream */
  694. static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
  695. {
  696. /* enable SIE */
  697. azx_writeb(chip, INTCTL,
  698. azx_readb(chip, INTCTL) | (1 << azx_dev->index));
  699. /* set DMA start and interrupt mask */
  700. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  701. SD_CTL_DMA_START | SD_INT_MASK);
  702. }
  703. /* stop a stream */
  704. static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
  705. {
  706. /* stop DMA */
  707. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
  708. ~(SD_CTL_DMA_START | SD_INT_MASK));
  709. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
  710. /* disable SIE */
  711. azx_writeb(chip, INTCTL,
  712. azx_readb(chip, INTCTL) & ~(1 << azx_dev->index));
  713. }
  714. /*
  715. * reset and start the controller registers
  716. */
  717. static void azx_init_chip(struct azx *chip)
  718. {
  719. if (chip->initialized)
  720. return;
  721. /* reset controller */
  722. azx_reset(chip);
  723. /* initialize interrupts */
  724. azx_int_clear(chip);
  725. azx_int_enable(chip);
  726. /* initialize the codec command I/O */
  727. if (!chip->single_cmd)
  728. azx_init_cmd_io(chip);
  729. /* program the position buffer */
  730. azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
  731. azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
  732. chip->initialized = 1;
  733. }
  734. /*
  735. * initialize the PCI registers
  736. */
  737. /* update bits in a PCI register byte */
  738. static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
  739. unsigned char mask, unsigned char val)
  740. {
  741. unsigned char data;
  742. pci_read_config_byte(pci, reg, &data);
  743. data &= ~mask;
  744. data |= (val & mask);
  745. pci_write_config_byte(pci, reg, data);
  746. }
  747. static void azx_init_pci(struct azx *chip)
  748. {
  749. unsigned short snoop;
  750. /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  751. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  752. * Ensuring these bits are 0 clears playback static on some HD Audio
  753. * codecs
  754. */
  755. update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
  756. switch (chip->driver_type) {
  757. case AZX_DRIVER_ATI:
  758. /* For ATI SB450 azalia HD audio, we need to enable snoop */
  759. update_pci_byte(chip->pci,
  760. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
  761. 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
  762. break;
  763. case AZX_DRIVER_NVIDIA:
  764. /* For NVIDIA HDA, enable snoop */
  765. update_pci_byte(chip->pci,
  766. NVIDIA_HDA_TRANSREG_ADDR,
  767. 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
  768. break;
  769. case AZX_DRIVER_SCH:
  770. pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
  771. if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
  772. pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, \
  773. snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
  774. pci_read_config_word(chip->pci,
  775. INTEL_SCH_HDA_DEVC, &snoop);
  776. snd_printdd("HDA snoop disabled, enabling ... %s\n",\
  777. (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) \
  778. ? "Failed" : "OK");
  779. }
  780. break;
  781. }
  782. }
  783. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
  784. /*
  785. * interrupt handler
  786. */
  787. static irqreturn_t azx_interrupt(int irq, void *dev_id)
  788. {
  789. struct azx *chip = dev_id;
  790. struct azx_dev *azx_dev;
  791. u32 status;
  792. int i;
  793. spin_lock(&chip->reg_lock);
  794. status = azx_readl(chip, INTSTS);
  795. if (status == 0) {
  796. spin_unlock(&chip->reg_lock);
  797. return IRQ_NONE;
  798. }
  799. for (i = 0; i < chip->num_streams; i++) {
  800. azx_dev = &chip->azx_dev[i];
  801. if (status & azx_dev->sd_int_sta_mask) {
  802. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  803. if (!azx_dev->substream || !azx_dev->running)
  804. continue;
  805. /* ignore the first dummy IRQ (due to pos_adj) */
  806. if (azx_dev->irq_ignore) {
  807. azx_dev->irq_ignore = 0;
  808. continue;
  809. }
  810. /* check whether this IRQ is really acceptable */
  811. if (azx_position_ok(chip, azx_dev)) {
  812. azx_dev->irq_pending = 0;
  813. spin_unlock(&chip->reg_lock);
  814. snd_pcm_period_elapsed(azx_dev->substream);
  815. spin_lock(&chip->reg_lock);
  816. } else {
  817. /* bogus IRQ, process it later */
  818. azx_dev->irq_pending = 1;
  819. schedule_work(&chip->irq_pending_work);
  820. }
  821. }
  822. }
  823. /* clear rirb int */
  824. status = azx_readb(chip, RIRBSTS);
  825. if (status & RIRB_INT_MASK) {
  826. if (!chip->single_cmd && (status & RIRB_INT_RESPONSE))
  827. azx_update_rirb(chip);
  828. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  829. }
  830. #if 0
  831. /* clear state status int */
  832. if (azx_readb(chip, STATESTS) & 0x04)
  833. azx_writeb(chip, STATESTS, 0x04);
  834. #endif
  835. spin_unlock(&chip->reg_lock);
  836. return IRQ_HANDLED;
  837. }
  838. /*
  839. * set up a BDL entry
  840. */
  841. static int setup_bdle(struct snd_pcm_substream *substream,
  842. struct azx_dev *azx_dev, u32 **bdlp,
  843. int ofs, int size, int with_ioc)
  844. {
  845. struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
  846. u32 *bdl = *bdlp;
  847. while (size > 0) {
  848. dma_addr_t addr;
  849. int chunk;
  850. if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
  851. return -EINVAL;
  852. addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
  853. /* program the address field of the BDL entry */
  854. bdl[0] = cpu_to_le32((u32)addr);
  855. bdl[1] = cpu_to_le32(upper_32_bits(addr));
  856. /* program the size field of the BDL entry */
  857. chunk = PAGE_SIZE - (ofs % PAGE_SIZE);
  858. if (size < chunk)
  859. chunk = size;
  860. bdl[2] = cpu_to_le32(chunk);
  861. /* program the IOC to enable interrupt
  862. * only when the whole fragment is processed
  863. */
  864. size -= chunk;
  865. bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
  866. bdl += 4;
  867. azx_dev->frags++;
  868. ofs += chunk;
  869. }
  870. *bdlp = bdl;
  871. return ofs;
  872. }
  873. /*
  874. * set up BDL entries
  875. */
  876. static int azx_setup_periods(struct azx *chip,
  877. struct snd_pcm_substream *substream,
  878. struct azx_dev *azx_dev)
  879. {
  880. u32 *bdl;
  881. int i, ofs, periods, period_bytes;
  882. int pos_adj;
  883. /* reset BDL address */
  884. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  885. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  886. period_bytes = snd_pcm_lib_period_bytes(substream);
  887. azx_dev->period_bytes = period_bytes;
  888. periods = azx_dev->bufsize / period_bytes;
  889. /* program the initial BDL entries */
  890. bdl = (u32 *)azx_dev->bdl.area;
  891. ofs = 0;
  892. azx_dev->frags = 0;
  893. azx_dev->irq_ignore = 0;
  894. pos_adj = bdl_pos_adj[chip->dev_index];
  895. if (pos_adj > 0) {
  896. struct snd_pcm_runtime *runtime = substream->runtime;
  897. pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
  898. if (!pos_adj)
  899. pos_adj = 1;
  900. pos_adj = frames_to_bytes(runtime, pos_adj);
  901. if (pos_adj >= period_bytes) {
  902. snd_printk(KERN_WARNING "Too big adjustment %d\n",
  903. bdl_pos_adj[chip->dev_index]);
  904. pos_adj = 0;
  905. } else {
  906. ofs = setup_bdle(substream, azx_dev,
  907. &bdl, ofs, pos_adj, 1);
  908. if (ofs < 0)
  909. goto error;
  910. azx_dev->irq_ignore = 1;
  911. }
  912. } else
  913. pos_adj = 0;
  914. for (i = 0; i < periods; i++) {
  915. if (i == periods - 1 && pos_adj)
  916. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  917. period_bytes - pos_adj, 0);
  918. else
  919. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  920. period_bytes, 1);
  921. if (ofs < 0)
  922. goto error;
  923. }
  924. return 0;
  925. error:
  926. snd_printk(KERN_ERR "Too many BDL entries: buffer=%d, period=%d\n",
  927. azx_dev->bufsize, period_bytes);
  928. /* reset */
  929. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  930. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  931. return -EINVAL;
  932. }
  933. /*
  934. * set up the SD for streaming
  935. */
  936. static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
  937. {
  938. unsigned char val;
  939. int timeout;
  940. /* make sure the run bit is zero for SD */
  941. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
  942. ~SD_CTL_DMA_START);
  943. /* reset stream */
  944. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  945. SD_CTL_STREAM_RESET);
  946. udelay(3);
  947. timeout = 300;
  948. while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  949. --timeout)
  950. ;
  951. val &= ~SD_CTL_STREAM_RESET;
  952. azx_sd_writeb(azx_dev, SD_CTL, val);
  953. udelay(3);
  954. timeout = 300;
  955. /* waiting for hardware to report that the stream is out of reset */
  956. while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  957. --timeout)
  958. ;
  959. /* program the stream_tag */
  960. azx_sd_writel(azx_dev, SD_CTL,
  961. (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
  962. (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
  963. /* program the length of samples in cyclic buffer */
  964. azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
  965. /* program the stream format */
  966. /* this value needs to be the same as the one programmed */
  967. azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
  968. /* program the stream LVI (last valid index) of the BDL */
  969. azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
  970. /* program the BDL address */
  971. /* lower BDL address */
  972. azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
  973. /* upper BDL address */
  974. azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
  975. /* enable the position buffer */
  976. if (chip->position_fix == POS_FIX_POSBUF ||
  977. chip->position_fix == POS_FIX_AUTO) {
  978. if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
  979. azx_writel(chip, DPLBASE,
  980. (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
  981. }
  982. /* set the interrupt enable bits in the descriptor control register */
  983. azx_sd_writel(azx_dev, SD_CTL,
  984. azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
  985. return 0;
  986. }
  987. /*
  988. * Codec initialization
  989. */
  990. static unsigned int azx_max_codecs[] __devinitdata = {
  991. [AZX_DRIVER_ICH] = 4, /* Some ICH9 boards use SD3 */
  992. [AZX_DRIVER_SCH] = 3,
  993. [AZX_DRIVER_ATI] = 4,
  994. [AZX_DRIVER_ATIHDMI] = 4,
  995. [AZX_DRIVER_VIA] = 3, /* FIXME: correct? */
  996. [AZX_DRIVER_SIS] = 3, /* FIXME: correct? */
  997. [AZX_DRIVER_ULI] = 3, /* FIXME: correct? */
  998. [AZX_DRIVER_NVIDIA] = 3, /* FIXME: correct? */
  999. [AZX_DRIVER_TERA] = 1,
  1000. };
  1001. static int __devinit azx_codec_create(struct azx *chip, const char *model,
  1002. unsigned int codec_probe_mask)
  1003. {
  1004. struct hda_bus_template bus_temp;
  1005. int c, codecs, audio_codecs, err;
  1006. memset(&bus_temp, 0, sizeof(bus_temp));
  1007. bus_temp.private_data = chip;
  1008. bus_temp.modelname = model;
  1009. bus_temp.pci = chip->pci;
  1010. bus_temp.ops.command = azx_send_cmd;
  1011. bus_temp.ops.get_response = azx_get_response;
  1012. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1013. bus_temp.ops.pm_notify = azx_power_notify;
  1014. #endif
  1015. err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
  1016. if (err < 0)
  1017. return err;
  1018. codecs = audio_codecs = 0;
  1019. for (c = 0; c < AZX_MAX_CODECS; c++) {
  1020. if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
  1021. struct hda_codec *codec;
  1022. err = snd_hda_codec_new(chip->bus, c, &codec);
  1023. if (err < 0)
  1024. continue;
  1025. codecs++;
  1026. if (codec->afg)
  1027. audio_codecs++;
  1028. }
  1029. }
  1030. if (!audio_codecs) {
  1031. /* probe additional slots if no codec is found */
  1032. for (; c < azx_max_codecs[chip->driver_type]; c++) {
  1033. if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
  1034. err = snd_hda_codec_new(chip->bus, c, NULL);
  1035. if (err < 0)
  1036. continue;
  1037. codecs++;
  1038. }
  1039. }
  1040. }
  1041. if (!codecs) {
  1042. snd_printk(KERN_ERR SFX "no codecs initialized\n");
  1043. return -ENXIO;
  1044. }
  1045. return 0;
  1046. }
  1047. /*
  1048. * PCM support
  1049. */
  1050. /* assign a stream for the PCM */
  1051. static inline struct azx_dev *azx_assign_device(struct azx *chip, int stream)
  1052. {
  1053. int dev, i, nums;
  1054. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1055. dev = chip->playback_index_offset;
  1056. nums = chip->playback_streams;
  1057. } else {
  1058. dev = chip->capture_index_offset;
  1059. nums = chip->capture_streams;
  1060. }
  1061. for (i = 0; i < nums; i++, dev++)
  1062. if (!chip->azx_dev[dev].opened) {
  1063. chip->azx_dev[dev].opened = 1;
  1064. return &chip->azx_dev[dev];
  1065. }
  1066. return NULL;
  1067. }
  1068. /* release the assigned stream */
  1069. static inline void azx_release_device(struct azx_dev *azx_dev)
  1070. {
  1071. azx_dev->opened = 0;
  1072. }
  1073. static struct snd_pcm_hardware azx_pcm_hw = {
  1074. .info = (SNDRV_PCM_INFO_MMAP |
  1075. SNDRV_PCM_INFO_INTERLEAVED |
  1076. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1077. SNDRV_PCM_INFO_MMAP_VALID |
  1078. /* No full-resume yet implemented */
  1079. /* SNDRV_PCM_INFO_RESUME |*/
  1080. SNDRV_PCM_INFO_PAUSE |
  1081. SNDRV_PCM_INFO_SYNC_START),
  1082. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1083. .rates = SNDRV_PCM_RATE_48000,
  1084. .rate_min = 48000,
  1085. .rate_max = 48000,
  1086. .channels_min = 2,
  1087. .channels_max = 2,
  1088. .buffer_bytes_max = AZX_MAX_BUF_SIZE,
  1089. .period_bytes_min = 128,
  1090. .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
  1091. .periods_min = 2,
  1092. .periods_max = AZX_MAX_FRAG,
  1093. .fifo_size = 0,
  1094. };
  1095. struct azx_pcm {
  1096. struct azx *chip;
  1097. struct hda_codec *codec;
  1098. struct hda_pcm_stream *hinfo[2];
  1099. };
  1100. static int azx_pcm_open(struct snd_pcm_substream *substream)
  1101. {
  1102. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1103. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1104. struct azx *chip = apcm->chip;
  1105. struct azx_dev *azx_dev;
  1106. struct snd_pcm_runtime *runtime = substream->runtime;
  1107. unsigned long flags;
  1108. int err;
  1109. mutex_lock(&chip->open_mutex);
  1110. azx_dev = azx_assign_device(chip, substream->stream);
  1111. if (azx_dev == NULL) {
  1112. mutex_unlock(&chip->open_mutex);
  1113. return -EBUSY;
  1114. }
  1115. runtime->hw = azx_pcm_hw;
  1116. runtime->hw.channels_min = hinfo->channels_min;
  1117. runtime->hw.channels_max = hinfo->channels_max;
  1118. runtime->hw.formats = hinfo->formats;
  1119. runtime->hw.rates = hinfo->rates;
  1120. snd_pcm_limit_hw_rates(runtime);
  1121. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  1122. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1123. 128);
  1124. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1125. 128);
  1126. snd_hda_power_up(apcm->codec);
  1127. err = hinfo->ops.open(hinfo, apcm->codec, substream);
  1128. if (err < 0) {
  1129. azx_release_device(azx_dev);
  1130. snd_hda_power_down(apcm->codec);
  1131. mutex_unlock(&chip->open_mutex);
  1132. return err;
  1133. }
  1134. spin_lock_irqsave(&chip->reg_lock, flags);
  1135. azx_dev->substream = substream;
  1136. azx_dev->running = 0;
  1137. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1138. runtime->private_data = azx_dev;
  1139. snd_pcm_set_sync(substream);
  1140. mutex_unlock(&chip->open_mutex);
  1141. return 0;
  1142. }
  1143. static int azx_pcm_close(struct snd_pcm_substream *substream)
  1144. {
  1145. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1146. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1147. struct azx *chip = apcm->chip;
  1148. struct azx_dev *azx_dev = get_azx_dev(substream);
  1149. unsigned long flags;
  1150. mutex_lock(&chip->open_mutex);
  1151. spin_lock_irqsave(&chip->reg_lock, flags);
  1152. azx_dev->substream = NULL;
  1153. azx_dev->running = 0;
  1154. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1155. azx_release_device(azx_dev);
  1156. hinfo->ops.close(hinfo, apcm->codec, substream);
  1157. snd_hda_power_down(apcm->codec);
  1158. mutex_unlock(&chip->open_mutex);
  1159. return 0;
  1160. }
  1161. static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
  1162. struct snd_pcm_hw_params *hw_params)
  1163. {
  1164. return snd_pcm_lib_malloc_pages(substream,
  1165. params_buffer_bytes(hw_params));
  1166. }
  1167. static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
  1168. {
  1169. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1170. struct azx_dev *azx_dev = get_azx_dev(substream);
  1171. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1172. /* reset BDL address */
  1173. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1174. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1175. azx_sd_writel(azx_dev, SD_CTL, 0);
  1176. hinfo->ops.cleanup(hinfo, apcm->codec, substream);
  1177. return snd_pcm_lib_free_pages(substream);
  1178. }
  1179. static int azx_pcm_prepare(struct snd_pcm_substream *substream)
  1180. {
  1181. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1182. struct azx *chip = apcm->chip;
  1183. struct azx_dev *azx_dev = get_azx_dev(substream);
  1184. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1185. struct snd_pcm_runtime *runtime = substream->runtime;
  1186. azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream);
  1187. azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate,
  1188. runtime->channels,
  1189. runtime->format,
  1190. hinfo->maxbps);
  1191. if (!azx_dev->format_val) {
  1192. snd_printk(KERN_ERR SFX
  1193. "invalid format_val, rate=%d, ch=%d, format=%d\n",
  1194. runtime->rate, runtime->channels, runtime->format);
  1195. return -EINVAL;
  1196. }
  1197. snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
  1198. azx_dev->bufsize, azx_dev->format_val);
  1199. if (azx_setup_periods(chip, substream, azx_dev) < 0)
  1200. return -EINVAL;
  1201. azx_setup_controller(chip, azx_dev);
  1202. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1203. azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
  1204. else
  1205. azx_dev->fifo_size = 0;
  1206. return hinfo->ops.prepare(hinfo, apcm->codec, azx_dev->stream_tag,
  1207. azx_dev->format_val, substream);
  1208. }
  1209. static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  1210. {
  1211. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1212. struct azx *chip = apcm->chip;
  1213. struct azx_dev *azx_dev;
  1214. struct snd_pcm_substream *s;
  1215. int start, nsync = 0, sbits = 0;
  1216. int nwait, timeout;
  1217. switch (cmd) {
  1218. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1219. case SNDRV_PCM_TRIGGER_RESUME:
  1220. case SNDRV_PCM_TRIGGER_START:
  1221. start = 1;
  1222. break;
  1223. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1224. case SNDRV_PCM_TRIGGER_SUSPEND:
  1225. case SNDRV_PCM_TRIGGER_STOP:
  1226. start = 0;
  1227. break;
  1228. default:
  1229. return -EINVAL;
  1230. }
  1231. snd_pcm_group_for_each_entry(s, substream) {
  1232. if (s->pcm->card != substream->pcm->card)
  1233. continue;
  1234. azx_dev = get_azx_dev(s);
  1235. sbits |= 1 << azx_dev->index;
  1236. nsync++;
  1237. snd_pcm_trigger_done(s, substream);
  1238. }
  1239. spin_lock(&chip->reg_lock);
  1240. if (nsync > 1) {
  1241. /* first, set SYNC bits of corresponding streams */
  1242. azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
  1243. }
  1244. snd_pcm_group_for_each_entry(s, substream) {
  1245. if (s->pcm->card != substream->pcm->card)
  1246. continue;
  1247. azx_dev = get_azx_dev(s);
  1248. if (start)
  1249. azx_stream_start(chip, azx_dev);
  1250. else
  1251. azx_stream_stop(chip, azx_dev);
  1252. azx_dev->running = start;
  1253. }
  1254. spin_unlock(&chip->reg_lock);
  1255. if (start) {
  1256. if (nsync == 1)
  1257. return 0;
  1258. /* wait until all FIFOs get ready */
  1259. for (timeout = 5000; timeout; timeout--) {
  1260. nwait = 0;
  1261. snd_pcm_group_for_each_entry(s, substream) {
  1262. if (s->pcm->card != substream->pcm->card)
  1263. continue;
  1264. azx_dev = get_azx_dev(s);
  1265. if (!(azx_sd_readb(azx_dev, SD_STS) &
  1266. SD_STS_FIFO_READY))
  1267. nwait++;
  1268. }
  1269. if (!nwait)
  1270. break;
  1271. cpu_relax();
  1272. }
  1273. } else {
  1274. /* wait until all RUN bits are cleared */
  1275. for (timeout = 5000; timeout; timeout--) {
  1276. nwait = 0;
  1277. snd_pcm_group_for_each_entry(s, substream) {
  1278. if (s->pcm->card != substream->pcm->card)
  1279. continue;
  1280. azx_dev = get_azx_dev(s);
  1281. if (azx_sd_readb(azx_dev, SD_CTL) &
  1282. SD_CTL_DMA_START)
  1283. nwait++;
  1284. }
  1285. if (!nwait)
  1286. break;
  1287. cpu_relax();
  1288. }
  1289. }
  1290. if (nsync > 1) {
  1291. spin_lock(&chip->reg_lock);
  1292. /* reset SYNC bits */
  1293. azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
  1294. spin_unlock(&chip->reg_lock);
  1295. }
  1296. return 0;
  1297. }
  1298. static unsigned int azx_get_position(struct azx *chip,
  1299. struct azx_dev *azx_dev)
  1300. {
  1301. unsigned int pos;
  1302. if (chip->position_fix == POS_FIX_POSBUF ||
  1303. chip->position_fix == POS_FIX_AUTO) {
  1304. /* use the position buffer */
  1305. pos = le32_to_cpu(*azx_dev->posbuf);
  1306. } else {
  1307. /* read LPIB */
  1308. pos = azx_sd_readl(azx_dev, SD_LPIB);
  1309. }
  1310. if (pos >= azx_dev->bufsize)
  1311. pos = 0;
  1312. return pos;
  1313. }
  1314. static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
  1315. {
  1316. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1317. struct azx *chip = apcm->chip;
  1318. struct azx_dev *azx_dev = get_azx_dev(substream);
  1319. return bytes_to_frames(substream->runtime,
  1320. azx_get_position(chip, azx_dev));
  1321. }
  1322. /*
  1323. * Check whether the current DMA position is acceptable for updating
  1324. * periods. Returns non-zero if it's OK.
  1325. *
  1326. * Many HD-audio controllers appear pretty inaccurate about
  1327. * the update-IRQ timing. The IRQ is issued before actually the
  1328. * data is processed. So, we need to process it afterwords in a
  1329. * workqueue.
  1330. */
  1331. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  1332. {
  1333. unsigned int pos;
  1334. pos = azx_get_position(chip, azx_dev);
  1335. if (chip->position_fix == POS_FIX_AUTO) {
  1336. if (!pos) {
  1337. printk(KERN_WARNING
  1338. "hda-intel: Invalid position buffer, "
  1339. "using LPIB read method instead.\n");
  1340. chip->position_fix = POS_FIX_LPIB;
  1341. pos = azx_get_position(chip, azx_dev);
  1342. } else
  1343. chip->position_fix = POS_FIX_POSBUF;
  1344. }
  1345. if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
  1346. return 0; /* NG - it's below the period boundary */
  1347. return 1; /* OK, it's fine */
  1348. }
  1349. /*
  1350. * The work for pending PCM period updates.
  1351. */
  1352. static void azx_irq_pending_work(struct work_struct *work)
  1353. {
  1354. struct azx *chip = container_of(work, struct azx, irq_pending_work);
  1355. int i, pending;
  1356. if (!chip->irq_pending_warned) {
  1357. printk(KERN_WARNING
  1358. "hda-intel: IRQ timing workaround is activated "
  1359. "for card #%d. Suggest a bigger bdl_pos_adj.\n",
  1360. chip->card->number);
  1361. chip->irq_pending_warned = 1;
  1362. }
  1363. for (;;) {
  1364. pending = 0;
  1365. spin_lock_irq(&chip->reg_lock);
  1366. for (i = 0; i < chip->num_streams; i++) {
  1367. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1368. if (!azx_dev->irq_pending ||
  1369. !azx_dev->substream ||
  1370. !azx_dev->running)
  1371. continue;
  1372. if (azx_position_ok(chip, azx_dev)) {
  1373. azx_dev->irq_pending = 0;
  1374. spin_unlock(&chip->reg_lock);
  1375. snd_pcm_period_elapsed(azx_dev->substream);
  1376. spin_lock(&chip->reg_lock);
  1377. } else
  1378. pending++;
  1379. }
  1380. spin_unlock_irq(&chip->reg_lock);
  1381. if (!pending)
  1382. return;
  1383. cond_resched();
  1384. }
  1385. }
  1386. /* clear irq_pending flags and assure no on-going workq */
  1387. static void azx_clear_irq_pending(struct azx *chip)
  1388. {
  1389. int i;
  1390. spin_lock_irq(&chip->reg_lock);
  1391. for (i = 0; i < chip->num_streams; i++)
  1392. chip->azx_dev[i].irq_pending = 0;
  1393. spin_unlock_irq(&chip->reg_lock);
  1394. flush_scheduled_work();
  1395. }
  1396. static struct snd_pcm_ops azx_pcm_ops = {
  1397. .open = azx_pcm_open,
  1398. .close = azx_pcm_close,
  1399. .ioctl = snd_pcm_lib_ioctl,
  1400. .hw_params = azx_pcm_hw_params,
  1401. .hw_free = azx_pcm_hw_free,
  1402. .prepare = azx_pcm_prepare,
  1403. .trigger = azx_pcm_trigger,
  1404. .pointer = azx_pcm_pointer,
  1405. .page = snd_pcm_sgbuf_ops_page,
  1406. };
  1407. static void azx_pcm_free(struct snd_pcm *pcm)
  1408. {
  1409. kfree(pcm->private_data);
  1410. }
  1411. static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
  1412. struct hda_pcm *cpcm)
  1413. {
  1414. int err;
  1415. struct snd_pcm *pcm;
  1416. struct azx_pcm *apcm;
  1417. /* if no substreams are defined for both playback and capture,
  1418. * it's just a placeholder. ignore it.
  1419. */
  1420. if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
  1421. return 0;
  1422. snd_assert(cpcm->name, return -EINVAL);
  1423. err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
  1424. cpcm->stream[0].substreams,
  1425. cpcm->stream[1].substreams,
  1426. &pcm);
  1427. if (err < 0)
  1428. return err;
  1429. strcpy(pcm->name, cpcm->name);
  1430. apcm = kmalloc(sizeof(*apcm), GFP_KERNEL);
  1431. if (apcm == NULL)
  1432. return -ENOMEM;
  1433. apcm->chip = chip;
  1434. apcm->codec = codec;
  1435. apcm->hinfo[0] = &cpcm->stream[0];
  1436. apcm->hinfo[1] = &cpcm->stream[1];
  1437. pcm->private_data = apcm;
  1438. pcm->private_free = azx_pcm_free;
  1439. if (cpcm->stream[0].substreams)
  1440. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops);
  1441. if (cpcm->stream[1].substreams)
  1442. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops);
  1443. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  1444. snd_dma_pci_data(chip->pci),
  1445. 1024 * 64, 1024 * 1024);
  1446. chip->pcm[cpcm->device] = pcm;
  1447. return 0;
  1448. }
  1449. static int __devinit azx_pcm_create(struct azx *chip)
  1450. {
  1451. static const char *dev_name[HDA_PCM_NTYPES] = {
  1452. "Audio", "SPDIF", "HDMI", "Modem"
  1453. };
  1454. /* starting device index for each PCM type */
  1455. static int dev_idx[HDA_PCM_NTYPES] = {
  1456. [HDA_PCM_TYPE_AUDIO] = 0,
  1457. [HDA_PCM_TYPE_SPDIF] = 1,
  1458. [HDA_PCM_TYPE_HDMI] = 3,
  1459. [HDA_PCM_TYPE_MODEM] = 6
  1460. };
  1461. /* normal audio device indices; not linear to keep compatibility */
  1462. static int audio_idx[4] = { 0, 2, 4, 5 };
  1463. struct hda_codec *codec;
  1464. int c, err;
  1465. int num_devs[HDA_PCM_NTYPES];
  1466. err = snd_hda_build_pcms(chip->bus);
  1467. if (err < 0)
  1468. return err;
  1469. /* create audio PCMs */
  1470. memset(num_devs, 0, sizeof(num_devs));
  1471. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  1472. for (c = 0; c < codec->num_pcms; c++) {
  1473. struct hda_pcm *cpcm = &codec->pcm_info[c];
  1474. int type = cpcm->pcm_type;
  1475. switch (type) {
  1476. case HDA_PCM_TYPE_AUDIO:
  1477. if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
  1478. snd_printk(KERN_WARNING
  1479. "Too many audio devices\n");
  1480. continue;
  1481. }
  1482. cpcm->device = audio_idx[num_devs[type]];
  1483. break;
  1484. case HDA_PCM_TYPE_SPDIF:
  1485. case HDA_PCM_TYPE_HDMI:
  1486. case HDA_PCM_TYPE_MODEM:
  1487. if (num_devs[type]) {
  1488. snd_printk(KERN_WARNING
  1489. "%s already defined\n",
  1490. dev_name[type]);
  1491. continue;
  1492. }
  1493. cpcm->device = dev_idx[type];
  1494. break;
  1495. default:
  1496. snd_printk(KERN_WARNING
  1497. "Invalid PCM type %d\n", type);
  1498. continue;
  1499. }
  1500. num_devs[type]++;
  1501. err = create_codec_pcm(chip, codec, cpcm);
  1502. if (err < 0)
  1503. return err;
  1504. }
  1505. }
  1506. return 0;
  1507. }
  1508. /*
  1509. * mixer creation - all stuff is implemented in hda module
  1510. */
  1511. static int __devinit azx_mixer_create(struct azx *chip)
  1512. {
  1513. return snd_hda_build_controls(chip->bus);
  1514. }
  1515. /*
  1516. * initialize SD streams
  1517. */
  1518. static int __devinit azx_init_stream(struct azx *chip)
  1519. {
  1520. int i;
  1521. /* initialize each stream (aka device)
  1522. * assign the starting bdl address to each stream (device)
  1523. * and initialize
  1524. */
  1525. for (i = 0; i < chip->num_streams; i++) {
  1526. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1527. azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
  1528. /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  1529. azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
  1530. /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
  1531. azx_dev->sd_int_sta_mask = 1 << i;
  1532. /* stream tag: must be non-zero and unique */
  1533. azx_dev->index = i;
  1534. azx_dev->stream_tag = i + 1;
  1535. }
  1536. return 0;
  1537. }
  1538. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  1539. {
  1540. if (request_irq(chip->pci->irq, azx_interrupt,
  1541. chip->msi ? 0 : IRQF_SHARED,
  1542. "HDA Intel", chip)) {
  1543. printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
  1544. "disabling device\n", chip->pci->irq);
  1545. if (do_disconnect)
  1546. snd_card_disconnect(chip->card);
  1547. return -1;
  1548. }
  1549. chip->irq = chip->pci->irq;
  1550. pci_intx(chip->pci, !chip->msi);
  1551. return 0;
  1552. }
  1553. static void azx_stop_chip(struct azx *chip)
  1554. {
  1555. if (!chip->initialized)
  1556. return;
  1557. /* disable interrupts */
  1558. azx_int_disable(chip);
  1559. azx_int_clear(chip);
  1560. /* disable CORB/RIRB */
  1561. azx_free_cmd_io(chip);
  1562. /* disable position buffer */
  1563. azx_writel(chip, DPLBASE, 0);
  1564. azx_writel(chip, DPUBASE, 0);
  1565. chip->initialized = 0;
  1566. }
  1567. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1568. /* power-up/down the controller */
  1569. static void azx_power_notify(struct hda_codec *codec)
  1570. {
  1571. struct azx *chip = codec->bus->private_data;
  1572. struct hda_codec *c;
  1573. int power_on = 0;
  1574. list_for_each_entry(c, &codec->bus->codec_list, list) {
  1575. if (c->power_on) {
  1576. power_on = 1;
  1577. break;
  1578. }
  1579. }
  1580. if (power_on)
  1581. azx_init_chip(chip);
  1582. else if (chip->running && power_save_controller)
  1583. azx_stop_chip(chip);
  1584. }
  1585. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  1586. #ifdef CONFIG_PM
  1587. /*
  1588. * power management
  1589. */
  1590. static int azx_suspend(struct pci_dev *pci, pm_message_t state)
  1591. {
  1592. struct snd_card *card = pci_get_drvdata(pci);
  1593. struct azx *chip = card->private_data;
  1594. int i;
  1595. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1596. azx_clear_irq_pending(chip);
  1597. for (i = 0; i < AZX_MAX_PCMS; i++)
  1598. snd_pcm_suspend_all(chip->pcm[i]);
  1599. if (chip->initialized)
  1600. snd_hda_suspend(chip->bus, state);
  1601. azx_stop_chip(chip);
  1602. if (chip->irq >= 0) {
  1603. free_irq(chip->irq, chip);
  1604. chip->irq = -1;
  1605. }
  1606. if (chip->msi)
  1607. pci_disable_msi(chip->pci);
  1608. pci_disable_device(pci);
  1609. pci_save_state(pci);
  1610. pci_set_power_state(pci, pci_choose_state(pci, state));
  1611. return 0;
  1612. }
  1613. static int azx_resume(struct pci_dev *pci)
  1614. {
  1615. struct snd_card *card = pci_get_drvdata(pci);
  1616. struct azx *chip = card->private_data;
  1617. pci_set_power_state(pci, PCI_D0);
  1618. pci_restore_state(pci);
  1619. if (pci_enable_device(pci) < 0) {
  1620. printk(KERN_ERR "hda-intel: pci_enable_device failed, "
  1621. "disabling device\n");
  1622. snd_card_disconnect(card);
  1623. return -EIO;
  1624. }
  1625. pci_set_master(pci);
  1626. if (chip->msi)
  1627. if (pci_enable_msi(pci) < 0)
  1628. chip->msi = 0;
  1629. if (azx_acquire_irq(chip, 1) < 0)
  1630. return -EIO;
  1631. azx_init_pci(chip);
  1632. if (snd_hda_codecs_inuse(chip->bus))
  1633. azx_init_chip(chip);
  1634. snd_hda_resume(chip->bus);
  1635. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1636. return 0;
  1637. }
  1638. #endif /* CONFIG_PM */
  1639. /*
  1640. * destructor
  1641. */
  1642. static int azx_free(struct azx *chip)
  1643. {
  1644. int i;
  1645. if (chip->initialized) {
  1646. azx_clear_irq_pending(chip);
  1647. for (i = 0; i < chip->num_streams; i++)
  1648. azx_stream_stop(chip, &chip->azx_dev[i]);
  1649. azx_stop_chip(chip);
  1650. }
  1651. if (chip->irq >= 0)
  1652. free_irq(chip->irq, (void*)chip);
  1653. if (chip->msi)
  1654. pci_disable_msi(chip->pci);
  1655. if (chip->remap_addr)
  1656. iounmap(chip->remap_addr);
  1657. if (chip->azx_dev) {
  1658. for (i = 0; i < chip->num_streams; i++)
  1659. if (chip->azx_dev[i].bdl.area)
  1660. snd_dma_free_pages(&chip->azx_dev[i].bdl);
  1661. }
  1662. if (chip->rb.area)
  1663. snd_dma_free_pages(&chip->rb);
  1664. if (chip->posbuf.area)
  1665. snd_dma_free_pages(&chip->posbuf);
  1666. pci_release_regions(chip->pci);
  1667. pci_disable_device(chip->pci);
  1668. kfree(chip->azx_dev);
  1669. kfree(chip);
  1670. return 0;
  1671. }
  1672. static int azx_dev_free(struct snd_device *device)
  1673. {
  1674. return azx_free(device->device_data);
  1675. }
  1676. /*
  1677. * white/black-listing for position_fix
  1678. */
  1679. static struct snd_pci_quirk position_fix_list[] __devinitdata = {
  1680. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  1681. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  1682. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  1683. {}
  1684. };
  1685. static int __devinit check_position_fix(struct azx *chip, int fix)
  1686. {
  1687. const struct snd_pci_quirk *q;
  1688. if (fix == POS_FIX_AUTO) {
  1689. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  1690. if (q) {
  1691. printk(KERN_INFO
  1692. "hda_intel: position_fix set to %d "
  1693. "for device %04x:%04x\n",
  1694. q->value, q->subvendor, q->subdevice);
  1695. return q->value;
  1696. }
  1697. }
  1698. return fix;
  1699. }
  1700. /*
  1701. * black-lists for probe_mask
  1702. */
  1703. static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
  1704. /* Thinkpad often breaks the controller communication when accessing
  1705. * to the non-working (or non-existing) modem codec slot.
  1706. */
  1707. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  1708. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  1709. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  1710. {}
  1711. };
  1712. static void __devinit check_probe_mask(struct azx *chip, int dev)
  1713. {
  1714. const struct snd_pci_quirk *q;
  1715. if (probe_mask[dev] == -1) {
  1716. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  1717. if (q) {
  1718. printk(KERN_INFO
  1719. "hda_intel: probe_mask set to 0x%x "
  1720. "for device %04x:%04x\n",
  1721. q->value, q->subvendor, q->subdevice);
  1722. probe_mask[dev] = q->value;
  1723. }
  1724. }
  1725. }
  1726. /*
  1727. * constructor
  1728. */
  1729. static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
  1730. int dev, int driver_type,
  1731. struct azx **rchip)
  1732. {
  1733. struct azx *chip;
  1734. int i, err;
  1735. unsigned short gcap;
  1736. static struct snd_device_ops ops = {
  1737. .dev_free = azx_dev_free,
  1738. };
  1739. *rchip = NULL;
  1740. err = pci_enable_device(pci);
  1741. if (err < 0)
  1742. return err;
  1743. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1744. if (!chip) {
  1745. snd_printk(KERN_ERR SFX "cannot allocate chip\n");
  1746. pci_disable_device(pci);
  1747. return -ENOMEM;
  1748. }
  1749. spin_lock_init(&chip->reg_lock);
  1750. mutex_init(&chip->open_mutex);
  1751. chip->card = card;
  1752. chip->pci = pci;
  1753. chip->irq = -1;
  1754. chip->driver_type = driver_type;
  1755. chip->msi = enable_msi;
  1756. chip->dev_index = dev;
  1757. INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
  1758. chip->position_fix = check_position_fix(chip, position_fix[dev]);
  1759. check_probe_mask(chip, dev);
  1760. chip->single_cmd = single_cmd;
  1761. if (bdl_pos_adj[dev] < 0) {
  1762. switch (chip->driver_type) {
  1763. case AZX_DRIVER_ICH:
  1764. bdl_pos_adj[dev] = 1;
  1765. break;
  1766. default:
  1767. bdl_pos_adj[dev] = 32;
  1768. break;
  1769. }
  1770. }
  1771. #if BITS_PER_LONG != 64
  1772. /* Fix up base address on ULI M5461 */
  1773. if (chip->driver_type == AZX_DRIVER_ULI) {
  1774. u16 tmp3;
  1775. pci_read_config_word(pci, 0x40, &tmp3);
  1776. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  1777. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  1778. }
  1779. #endif
  1780. err = pci_request_regions(pci, "ICH HD audio");
  1781. if (err < 0) {
  1782. kfree(chip);
  1783. pci_disable_device(pci);
  1784. return err;
  1785. }
  1786. chip->addr = pci_resource_start(pci, 0);
  1787. chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci,0));
  1788. if (chip->remap_addr == NULL) {
  1789. snd_printk(KERN_ERR SFX "ioremap error\n");
  1790. err = -ENXIO;
  1791. goto errout;
  1792. }
  1793. if (chip->msi)
  1794. if (pci_enable_msi(pci) < 0)
  1795. chip->msi = 0;
  1796. if (azx_acquire_irq(chip, 0) < 0) {
  1797. err = -EBUSY;
  1798. goto errout;
  1799. }
  1800. pci_set_master(pci);
  1801. synchronize_irq(chip->irq);
  1802. gcap = azx_readw(chip, GCAP);
  1803. snd_printdd("chipset global capabilities = 0x%x\n", gcap);
  1804. /* allow 64bit DMA address if supported by H/W */
  1805. if ((gcap & 0x01) && !pci_set_dma_mask(pci, DMA_64BIT_MASK))
  1806. pci_set_consistent_dma_mask(pci, DMA_64BIT_MASK);
  1807. /* read number of streams from GCAP register instead of using
  1808. * hardcoded value
  1809. */
  1810. chip->capture_streams = (gcap >> 8) & 0x0f;
  1811. chip->playback_streams = (gcap >> 12) & 0x0f;
  1812. if (!chip->playback_streams && !chip->capture_streams) {
  1813. /* gcap didn't give any info, switching to old method */
  1814. switch (chip->driver_type) {
  1815. case AZX_DRIVER_ULI:
  1816. chip->playback_streams = ULI_NUM_PLAYBACK;
  1817. chip->capture_streams = ULI_NUM_CAPTURE;
  1818. break;
  1819. case AZX_DRIVER_ATIHDMI:
  1820. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  1821. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  1822. break;
  1823. default:
  1824. chip->playback_streams = ICH6_NUM_PLAYBACK;
  1825. chip->capture_streams = ICH6_NUM_CAPTURE;
  1826. break;
  1827. }
  1828. }
  1829. chip->capture_index_offset = 0;
  1830. chip->playback_index_offset = chip->capture_streams;
  1831. chip->num_streams = chip->playback_streams + chip->capture_streams;
  1832. chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
  1833. GFP_KERNEL);
  1834. if (!chip->azx_dev) {
  1835. snd_printk(KERN_ERR "cannot malloc azx_dev\n");
  1836. goto errout;
  1837. }
  1838. for (i = 0; i < chip->num_streams; i++) {
  1839. /* allocate memory for the BDL for each stream */
  1840. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  1841. snd_dma_pci_data(chip->pci),
  1842. BDL_SIZE, &chip->azx_dev[i].bdl);
  1843. if (err < 0) {
  1844. snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
  1845. goto errout;
  1846. }
  1847. }
  1848. /* allocate memory for the position buffer */
  1849. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  1850. snd_dma_pci_data(chip->pci),
  1851. chip->num_streams * 8, &chip->posbuf);
  1852. if (err < 0) {
  1853. snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
  1854. goto errout;
  1855. }
  1856. /* allocate CORB/RIRB */
  1857. if (!chip->single_cmd) {
  1858. err = azx_alloc_cmd_io(chip);
  1859. if (err < 0)
  1860. goto errout;
  1861. }
  1862. /* initialize streams */
  1863. azx_init_stream(chip);
  1864. /* initialize chip */
  1865. azx_init_pci(chip);
  1866. azx_init_chip(chip);
  1867. /* codec detection */
  1868. if (!chip->codec_mask) {
  1869. snd_printk(KERN_ERR SFX "no codecs found!\n");
  1870. err = -ENODEV;
  1871. goto errout;
  1872. }
  1873. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  1874. if (err <0) {
  1875. snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
  1876. goto errout;
  1877. }
  1878. strcpy(card->driver, "HDA-Intel");
  1879. strcpy(card->shortname, driver_short_names[chip->driver_type]);
  1880. sprintf(card->longname, "%s at 0x%lx irq %i",
  1881. card->shortname, chip->addr, chip->irq);
  1882. *rchip = chip;
  1883. return 0;
  1884. errout:
  1885. azx_free(chip);
  1886. return err;
  1887. }
  1888. static void power_down_all_codecs(struct azx *chip)
  1889. {
  1890. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1891. /* The codecs were powered up in snd_hda_codec_new().
  1892. * Now all initialization done, so turn them down if possible
  1893. */
  1894. struct hda_codec *codec;
  1895. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  1896. snd_hda_power_down(codec);
  1897. }
  1898. #endif
  1899. }
  1900. static int __devinit azx_probe(struct pci_dev *pci,
  1901. const struct pci_device_id *pci_id)
  1902. {
  1903. static int dev;
  1904. struct snd_card *card;
  1905. struct azx *chip;
  1906. int err;
  1907. if (dev >= SNDRV_CARDS)
  1908. return -ENODEV;
  1909. if (!enable[dev]) {
  1910. dev++;
  1911. return -ENOENT;
  1912. }
  1913. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1914. if (!card) {
  1915. snd_printk(KERN_ERR SFX "Error creating card!\n");
  1916. return -ENOMEM;
  1917. }
  1918. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  1919. if (err < 0) {
  1920. snd_card_free(card);
  1921. return err;
  1922. }
  1923. card->private_data = chip;
  1924. /* create codec instances */
  1925. err = azx_codec_create(chip, model[dev], probe_mask[dev]);
  1926. if (err < 0) {
  1927. snd_card_free(card);
  1928. return err;
  1929. }
  1930. /* create PCM streams */
  1931. err = azx_pcm_create(chip);
  1932. if (err < 0) {
  1933. snd_card_free(card);
  1934. return err;
  1935. }
  1936. /* create mixer controls */
  1937. err = azx_mixer_create(chip);
  1938. if (err < 0) {
  1939. snd_card_free(card);
  1940. return err;
  1941. }
  1942. snd_card_set_dev(card, &pci->dev);
  1943. err = snd_card_register(card);
  1944. if (err < 0) {
  1945. snd_card_free(card);
  1946. return err;
  1947. }
  1948. pci_set_drvdata(pci, card);
  1949. chip->running = 1;
  1950. power_down_all_codecs(chip);
  1951. dev++;
  1952. return err;
  1953. }
  1954. static void __devexit azx_remove(struct pci_dev *pci)
  1955. {
  1956. snd_card_free(pci_get_drvdata(pci));
  1957. pci_set_drvdata(pci, NULL);
  1958. }
  1959. /* PCI IDs */
  1960. static struct pci_device_id azx_ids[] = {
  1961. /* ICH 6..10 */
  1962. { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
  1963. { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
  1964. { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
  1965. { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
  1966. { PCI_DEVICE(0x8086, 0x2911), .driver_data = AZX_DRIVER_ICH },
  1967. { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
  1968. { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
  1969. { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
  1970. { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
  1971. /* SCH */
  1972. { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
  1973. /* ATI SB 450/600 */
  1974. { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
  1975. { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
  1976. /* ATI HDMI */
  1977. { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
  1978. { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
  1979. { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
  1980. { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
  1981. { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
  1982. { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
  1983. { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
  1984. { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
  1985. { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
  1986. { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
  1987. { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
  1988. { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
  1989. { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
  1990. /* VIA VT8251/VT8237A */
  1991. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  1992. /* SIS966 */
  1993. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  1994. /* ULI M5461 */
  1995. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  1996. /* NVIDIA MCP */
  1997. { PCI_DEVICE(0x10de, 0x026c), .driver_data = AZX_DRIVER_NVIDIA },
  1998. { PCI_DEVICE(0x10de, 0x0371), .driver_data = AZX_DRIVER_NVIDIA },
  1999. { PCI_DEVICE(0x10de, 0x03e4), .driver_data = AZX_DRIVER_NVIDIA },
  2000. { PCI_DEVICE(0x10de, 0x03f0), .driver_data = AZX_DRIVER_NVIDIA },
  2001. { PCI_DEVICE(0x10de, 0x044a), .driver_data = AZX_DRIVER_NVIDIA },
  2002. { PCI_DEVICE(0x10de, 0x044b), .driver_data = AZX_DRIVER_NVIDIA },
  2003. { PCI_DEVICE(0x10de, 0x055c), .driver_data = AZX_DRIVER_NVIDIA },
  2004. { PCI_DEVICE(0x10de, 0x055d), .driver_data = AZX_DRIVER_NVIDIA },
  2005. { PCI_DEVICE(0x10de, 0x0774), .driver_data = AZX_DRIVER_NVIDIA },
  2006. { PCI_DEVICE(0x10de, 0x0775), .driver_data = AZX_DRIVER_NVIDIA },
  2007. { PCI_DEVICE(0x10de, 0x0776), .driver_data = AZX_DRIVER_NVIDIA },
  2008. { PCI_DEVICE(0x10de, 0x0777), .driver_data = AZX_DRIVER_NVIDIA },
  2009. { PCI_DEVICE(0x10de, 0x07fc), .driver_data = AZX_DRIVER_NVIDIA },
  2010. { PCI_DEVICE(0x10de, 0x07fd), .driver_data = AZX_DRIVER_NVIDIA },
  2011. { PCI_DEVICE(0x10de, 0x0ac0), .driver_data = AZX_DRIVER_NVIDIA },
  2012. { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
  2013. { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
  2014. { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
  2015. { PCI_DEVICE(0x10de, 0x0bd4), .driver_data = AZX_DRIVER_NVIDIA },
  2016. { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
  2017. { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
  2018. { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
  2019. /* Teradici */
  2020. { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
  2021. { 0, }
  2022. };
  2023. MODULE_DEVICE_TABLE(pci, azx_ids);
  2024. /* pci_driver definition */
  2025. static struct pci_driver driver = {
  2026. .name = "HDA Intel",
  2027. .id_table = azx_ids,
  2028. .probe = azx_probe,
  2029. .remove = __devexit_p(azx_remove),
  2030. #ifdef CONFIG_PM
  2031. .suspend = azx_suspend,
  2032. .resume = azx_resume,
  2033. #endif
  2034. };
  2035. static int __init alsa_card_azx_init(void)
  2036. {
  2037. return pci_register_driver(&driver);
  2038. }
  2039. static void __exit alsa_card_azx_exit(void)
  2040. {
  2041. pci_unregister_driver(&driver);
  2042. }
  2043. module_init(alsa_card_azx_init)
  2044. module_exit(alsa_card_azx_exit)