hda_intel.c 61 KB

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