hda_intel.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  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 <linux/reboot.h>
  48. #include <sound/core.h>
  49. #include <sound/initval.h>
  50. #include "hda_codec.h"
  51. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  52. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  53. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  54. static char *model[SNDRV_CARDS];
  55. static int position_fix[SNDRV_CARDS];
  56. static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  57. static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
  58. static int probe_only[SNDRV_CARDS];
  59. static int single_cmd;
  60. static int enable_msi = -1;
  61. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  62. static char *patch[SNDRV_CARDS];
  63. #endif
  64. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  65. static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
  66. CONFIG_SND_HDA_INPUT_BEEP_MODE};
  67. #endif
  68. module_param_array(index, int, NULL, 0444);
  69. MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
  70. module_param_array(id, charp, NULL, 0444);
  71. MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
  72. module_param_array(enable, bool, NULL, 0444);
  73. MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
  74. module_param_array(model, charp, NULL, 0444);
  75. MODULE_PARM_DESC(model, "Use the given board model.");
  76. module_param_array(position_fix, int, NULL, 0444);
  77. MODULE_PARM_DESC(position_fix, "DMA pointer read method."
  78. "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO).");
  79. module_param_array(bdl_pos_adj, int, NULL, 0644);
  80. MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
  81. module_param_array(probe_mask, int, NULL, 0444);
  82. MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
  83. module_param_array(probe_only, int, NULL, 0444);
  84. MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
  85. module_param(single_cmd, bool, 0444);
  86. MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
  87. "(for debugging only).");
  88. module_param(enable_msi, int, 0444);
  89. MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
  90. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  91. module_param_array(patch, charp, NULL, 0444);
  92. MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
  93. #endif
  94. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  95. module_param_array(beep_mode, int, NULL, 0444);
  96. MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
  97. "(0=off, 1=on, 2=mute switch on/off) (default=1).");
  98. #endif
  99. #ifdef CONFIG_SND_HDA_POWER_SAVE
  100. static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
  101. module_param(power_save, int, 0644);
  102. MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
  103. "(in second, 0 = disable).");
  104. /* reset the HD-audio controller in power save mode.
  105. * this may give more power-saving, but will take longer time to
  106. * wake up.
  107. */
  108. static int power_save_controller = 1;
  109. module_param(power_save_controller, bool, 0644);
  110. MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
  111. #endif
  112. MODULE_LICENSE("GPL");
  113. MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
  114. "{Intel, ICH6M},"
  115. "{Intel, ICH7},"
  116. "{Intel, ESB2},"
  117. "{Intel, ICH8},"
  118. "{Intel, ICH9},"
  119. "{Intel, ICH10},"
  120. "{Intel, PCH},"
  121. "{Intel, CPT},"
  122. "{Intel, PBG},"
  123. "{Intel, SCH},"
  124. "{ATI, SB450},"
  125. "{ATI, SB600},"
  126. "{ATI, RS600},"
  127. "{ATI, RS690},"
  128. "{ATI, RS780},"
  129. "{ATI, R600},"
  130. "{ATI, RV630},"
  131. "{ATI, RV610},"
  132. "{ATI, RV670},"
  133. "{ATI, RV635},"
  134. "{ATI, RV620},"
  135. "{ATI, RV770},"
  136. "{VIA, VT8251},"
  137. "{VIA, VT8237A},"
  138. "{SiS, SIS966},"
  139. "{ULI, M5461}}");
  140. MODULE_DESCRIPTION("Intel HDA driver");
  141. #ifdef CONFIG_SND_VERBOSE_PRINTK
  142. #define SFX /* nop */
  143. #else
  144. #define SFX "hda-intel: "
  145. #endif
  146. /*
  147. * registers
  148. */
  149. #define ICH6_REG_GCAP 0x00
  150. #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
  151. #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  152. #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  153. #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
  154. #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
  155. #define ICH6_REG_VMIN 0x02
  156. #define ICH6_REG_VMAJ 0x03
  157. #define ICH6_REG_OUTPAY 0x04
  158. #define ICH6_REG_INPAY 0x06
  159. #define ICH6_REG_GCTL 0x08
  160. #define ICH6_GCTL_RESET (1 << 0) /* controller reset */
  161. #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
  162. #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  163. #define ICH6_REG_WAKEEN 0x0c
  164. #define ICH6_REG_STATESTS 0x0e
  165. #define ICH6_REG_GSTS 0x10
  166. #define ICH6_GSTS_FSTS (1 << 1) /* flush status */
  167. #define ICH6_REG_INTCTL 0x20
  168. #define ICH6_REG_INTSTS 0x24
  169. #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
  170. #define ICH6_REG_SYNC 0x34
  171. #define ICH6_REG_CORBLBASE 0x40
  172. #define ICH6_REG_CORBUBASE 0x44
  173. #define ICH6_REG_CORBWP 0x48
  174. #define ICH6_REG_CORBRP 0x4a
  175. #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
  176. #define ICH6_REG_CORBCTL 0x4c
  177. #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
  178. #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  179. #define ICH6_REG_CORBSTS 0x4d
  180. #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
  181. #define ICH6_REG_CORBSIZE 0x4e
  182. #define ICH6_REG_RIRBLBASE 0x50
  183. #define ICH6_REG_RIRBUBASE 0x54
  184. #define ICH6_REG_RIRBWP 0x58
  185. #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
  186. #define ICH6_REG_RINTCNT 0x5a
  187. #define ICH6_REG_RIRBCTL 0x5c
  188. #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  189. #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  190. #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  191. #define ICH6_REG_RIRBSTS 0x5d
  192. #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
  193. #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  194. #define ICH6_REG_RIRBSIZE 0x5e
  195. #define ICH6_REG_IC 0x60
  196. #define ICH6_REG_IR 0x64
  197. #define ICH6_REG_IRS 0x68
  198. #define ICH6_IRS_VALID (1<<1)
  199. #define ICH6_IRS_BUSY (1<<0)
  200. #define ICH6_REG_DPLBASE 0x70
  201. #define ICH6_REG_DPUBASE 0x74
  202. #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  203. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  204. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  205. /* stream register offsets from stream base */
  206. #define ICH6_REG_SD_CTL 0x00
  207. #define ICH6_REG_SD_STS 0x03
  208. #define ICH6_REG_SD_LPIB 0x04
  209. #define ICH6_REG_SD_CBL 0x08
  210. #define ICH6_REG_SD_LVI 0x0c
  211. #define ICH6_REG_SD_FIFOW 0x0e
  212. #define ICH6_REG_SD_FIFOSIZE 0x10
  213. #define ICH6_REG_SD_FORMAT 0x12
  214. #define ICH6_REG_SD_BDLPL 0x18
  215. #define ICH6_REG_SD_BDLPU 0x1c
  216. /* PCI space */
  217. #define ICH6_PCIREG_TCSEL 0x44
  218. /*
  219. * other constants
  220. */
  221. /* max number of SDs */
  222. /* ICH, ATI and VIA have 4 playback and 4 capture */
  223. #define ICH6_NUM_CAPTURE 4
  224. #define ICH6_NUM_PLAYBACK 4
  225. /* ULI has 6 playback and 5 capture */
  226. #define ULI_NUM_CAPTURE 5
  227. #define ULI_NUM_PLAYBACK 6
  228. /* ATI HDMI has 1 playback and 0 capture */
  229. #define ATIHDMI_NUM_CAPTURE 0
  230. #define ATIHDMI_NUM_PLAYBACK 1
  231. /* TERA has 4 playback and 3 capture */
  232. #define TERA_NUM_CAPTURE 3
  233. #define TERA_NUM_PLAYBACK 4
  234. /* this number is statically defined for simplicity */
  235. #define MAX_AZX_DEV 16
  236. /* max number of fragments - we may use more if allocating more pages for BDL */
  237. #define BDL_SIZE 4096
  238. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  239. #define AZX_MAX_FRAG 32
  240. /* max buffer size - no h/w limit, you can increase as you like */
  241. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  242. /* RIRB int mask: overrun[2], response[0] */
  243. #define RIRB_INT_RESPONSE 0x01
  244. #define RIRB_INT_OVERRUN 0x04
  245. #define RIRB_INT_MASK 0x05
  246. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  247. #define AZX_MAX_CODECS 8
  248. #define AZX_DEFAULT_CODECS 4
  249. #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
  250. /* SD_CTL bits */
  251. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  252. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  253. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  254. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  255. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  256. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  257. #define SD_CTL_STREAM_TAG_SHIFT 20
  258. /* SD_CTL and SD_STS */
  259. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  260. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  261. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  262. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  263. SD_INT_COMPLETE)
  264. /* SD_STS */
  265. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  266. /* INTCTL and INTSTS */
  267. #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
  268. #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  269. #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  270. /* below are so far hardcoded - should read registers in future */
  271. #define ICH6_MAX_CORB_ENTRIES 256
  272. #define ICH6_MAX_RIRB_ENTRIES 256
  273. /* position fix mode */
  274. enum {
  275. POS_FIX_AUTO,
  276. POS_FIX_LPIB,
  277. POS_FIX_POSBUF,
  278. POS_FIX_VIACOMBO,
  279. };
  280. /* Defines for ATI HD Audio support in SB450 south bridge */
  281. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  282. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  283. /* Defines for Nvidia HDA support */
  284. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  285. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  286. #define NVIDIA_HDA_ISTRM_COH 0x4d
  287. #define NVIDIA_HDA_OSTRM_COH 0x4c
  288. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  289. /* Defines for Intel SCH HDA snoop control */
  290. #define INTEL_SCH_HDA_DEVC 0x78
  291. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  292. /* Define IN stream 0 FIFO size offset in VIA controller */
  293. #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
  294. /* Define VIA HD Audio Device ID*/
  295. #define VIA_HDAC_DEVICE_ID 0x3288
  296. /* HD Audio class code */
  297. #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
  298. /*
  299. */
  300. struct azx_dev {
  301. struct snd_dma_buffer bdl; /* BDL buffer */
  302. u32 *posbuf; /* position buffer pointer */
  303. unsigned int bufsize; /* size of the play buffer in bytes */
  304. unsigned int period_bytes; /* size of the period in bytes */
  305. unsigned int frags; /* number for period in the play buffer */
  306. unsigned int fifo_size; /* FIFO size */
  307. unsigned long start_wallclk; /* start + minimum wallclk */
  308. unsigned long period_wallclk; /* wallclk for period */
  309. void __iomem *sd_addr; /* stream descriptor pointer */
  310. u32 sd_int_sta_mask; /* stream int status mask */
  311. /* pcm support */
  312. struct snd_pcm_substream *substream; /* assigned substream,
  313. * set in PCM open
  314. */
  315. unsigned int format_val; /* format value to be set in the
  316. * controller and the codec
  317. */
  318. unsigned char stream_tag; /* assigned stream */
  319. unsigned char index; /* stream index */
  320. int device; /* last device number assigned to */
  321. unsigned int opened :1;
  322. unsigned int running :1;
  323. unsigned int irq_pending :1;
  324. /*
  325. * For VIA:
  326. * A flag to ensure DMA position is 0
  327. * when link position is not greater than FIFO size
  328. */
  329. unsigned int insufficient :1;
  330. };
  331. /* CORB/RIRB */
  332. struct azx_rb {
  333. u32 *buf; /* CORB/RIRB buffer
  334. * Each CORB entry is 4byte, RIRB is 8byte
  335. */
  336. dma_addr_t addr; /* physical address of CORB/RIRB buffer */
  337. /* for RIRB */
  338. unsigned short rp, wp; /* read/write pointers */
  339. int cmds[AZX_MAX_CODECS]; /* number of pending requests */
  340. u32 res[AZX_MAX_CODECS]; /* last read value */
  341. };
  342. struct azx {
  343. struct snd_card *card;
  344. struct pci_dev *pci;
  345. int dev_index;
  346. /* chip type specific */
  347. int driver_type;
  348. int playback_streams;
  349. int playback_index_offset;
  350. int capture_streams;
  351. int capture_index_offset;
  352. int num_streams;
  353. /* pci resources */
  354. unsigned long addr;
  355. void __iomem *remap_addr;
  356. int irq;
  357. /* locks */
  358. spinlock_t reg_lock;
  359. struct mutex open_mutex;
  360. /* streams (x num_streams) */
  361. struct azx_dev *azx_dev;
  362. /* PCM */
  363. struct snd_pcm *pcm[HDA_MAX_PCMS];
  364. /* HD codec */
  365. unsigned short codec_mask;
  366. int codec_probe_mask; /* copied from probe_mask option */
  367. struct hda_bus *bus;
  368. unsigned int beep_mode;
  369. /* CORB/RIRB */
  370. struct azx_rb corb;
  371. struct azx_rb rirb;
  372. /* CORB/RIRB and position buffers */
  373. struct snd_dma_buffer rb;
  374. struct snd_dma_buffer posbuf;
  375. /* flags */
  376. int position_fix[2]; /* for both playback/capture streams */
  377. int poll_count;
  378. unsigned int running :1;
  379. unsigned int initialized :1;
  380. unsigned int single_cmd :1;
  381. unsigned int polling_mode :1;
  382. unsigned int msi :1;
  383. unsigned int irq_pending_warned :1;
  384. unsigned int probing :1; /* codec probing phase */
  385. /* for debugging */
  386. unsigned int last_cmd[AZX_MAX_CODECS];
  387. /* for pending irqs */
  388. struct work_struct irq_pending_work;
  389. /* reboot notifier (for mysterious hangup problem at power-down) */
  390. struct notifier_block reboot_notifier;
  391. };
  392. /* driver types */
  393. enum {
  394. AZX_DRIVER_ICH,
  395. AZX_DRIVER_PCH,
  396. AZX_DRIVER_SCH,
  397. AZX_DRIVER_ATI,
  398. AZX_DRIVER_ATIHDMI,
  399. AZX_DRIVER_VIA,
  400. AZX_DRIVER_SIS,
  401. AZX_DRIVER_ULI,
  402. AZX_DRIVER_NVIDIA,
  403. AZX_DRIVER_TERA,
  404. AZX_DRIVER_CTX,
  405. AZX_DRIVER_GENERIC,
  406. AZX_NUM_DRIVERS, /* keep this as last entry */
  407. };
  408. static char *driver_short_names[] __devinitdata = {
  409. [AZX_DRIVER_ICH] = "HDA Intel",
  410. [AZX_DRIVER_PCH] = "HDA Intel PCH",
  411. [AZX_DRIVER_SCH] = "HDA Intel MID",
  412. [AZX_DRIVER_ATI] = "HDA ATI SB",
  413. [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
  414. [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
  415. [AZX_DRIVER_SIS] = "HDA SIS966",
  416. [AZX_DRIVER_ULI] = "HDA ULI M5461",
  417. [AZX_DRIVER_NVIDIA] = "HDA NVidia",
  418. [AZX_DRIVER_TERA] = "HDA Teradici",
  419. [AZX_DRIVER_CTX] = "HDA Creative",
  420. [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
  421. };
  422. /*
  423. * macros for easy use
  424. */
  425. #define azx_writel(chip,reg,value) \
  426. writel(value, (chip)->remap_addr + ICH6_REG_##reg)
  427. #define azx_readl(chip,reg) \
  428. readl((chip)->remap_addr + ICH6_REG_##reg)
  429. #define azx_writew(chip,reg,value) \
  430. writew(value, (chip)->remap_addr + ICH6_REG_##reg)
  431. #define azx_readw(chip,reg) \
  432. readw((chip)->remap_addr + ICH6_REG_##reg)
  433. #define azx_writeb(chip,reg,value) \
  434. writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
  435. #define azx_readb(chip,reg) \
  436. readb((chip)->remap_addr + ICH6_REG_##reg)
  437. #define azx_sd_writel(dev,reg,value) \
  438. writel(value, (dev)->sd_addr + ICH6_REG_##reg)
  439. #define azx_sd_readl(dev,reg) \
  440. readl((dev)->sd_addr + ICH6_REG_##reg)
  441. #define azx_sd_writew(dev,reg,value) \
  442. writew(value, (dev)->sd_addr + ICH6_REG_##reg)
  443. #define azx_sd_readw(dev,reg) \
  444. readw((dev)->sd_addr + ICH6_REG_##reg)
  445. #define azx_sd_writeb(dev,reg,value) \
  446. writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
  447. #define azx_sd_readb(dev,reg) \
  448. readb((dev)->sd_addr + ICH6_REG_##reg)
  449. /* for pcm support */
  450. #define get_azx_dev(substream) (substream->runtime->private_data)
  451. static int azx_acquire_irq(struct azx *chip, int do_disconnect);
  452. static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
  453. /*
  454. * Interface for HD codec
  455. */
  456. /*
  457. * CORB / RIRB interface
  458. */
  459. static int azx_alloc_cmd_io(struct azx *chip)
  460. {
  461. int err;
  462. /* single page (at least 4096 bytes) must suffice for both ringbuffes */
  463. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  464. snd_dma_pci_data(chip->pci),
  465. PAGE_SIZE, &chip->rb);
  466. if (err < 0) {
  467. snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
  468. return err;
  469. }
  470. return 0;
  471. }
  472. static void azx_init_cmd_io(struct azx *chip)
  473. {
  474. spin_lock_irq(&chip->reg_lock);
  475. /* CORB set up */
  476. chip->corb.addr = chip->rb.addr;
  477. chip->corb.buf = (u32 *)chip->rb.area;
  478. azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
  479. azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
  480. /* set the corb size to 256 entries (ULI requires explicitly) */
  481. azx_writeb(chip, CORBSIZE, 0x02);
  482. /* set the corb write pointer to 0 */
  483. azx_writew(chip, CORBWP, 0);
  484. /* reset the corb hw read pointer */
  485. azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
  486. /* enable corb dma */
  487. azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
  488. /* RIRB set up */
  489. chip->rirb.addr = chip->rb.addr + 2048;
  490. chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
  491. chip->rirb.wp = chip->rirb.rp = 0;
  492. memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
  493. azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
  494. azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
  495. /* set the rirb size to 256 entries (ULI requires explicitly) */
  496. azx_writeb(chip, RIRBSIZE, 0x02);
  497. /* reset the rirb hw write pointer */
  498. azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
  499. /* set N=1, get RIRB response interrupt for new entry */
  500. if (chip->driver_type == AZX_DRIVER_CTX)
  501. azx_writew(chip, RINTCNT, 0xc0);
  502. else
  503. azx_writew(chip, RINTCNT, 1);
  504. /* enable rirb dma and response irq */
  505. azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
  506. spin_unlock_irq(&chip->reg_lock);
  507. }
  508. static void azx_free_cmd_io(struct azx *chip)
  509. {
  510. spin_lock_irq(&chip->reg_lock);
  511. /* disable ringbuffer DMAs */
  512. azx_writeb(chip, RIRBCTL, 0);
  513. azx_writeb(chip, CORBCTL, 0);
  514. spin_unlock_irq(&chip->reg_lock);
  515. }
  516. static unsigned int azx_command_addr(u32 cmd)
  517. {
  518. unsigned int addr = cmd >> 28;
  519. if (addr >= AZX_MAX_CODECS) {
  520. snd_BUG();
  521. addr = 0;
  522. }
  523. return addr;
  524. }
  525. static unsigned int azx_response_addr(u32 res)
  526. {
  527. unsigned int addr = res & 0xf;
  528. if (addr >= AZX_MAX_CODECS) {
  529. snd_BUG();
  530. addr = 0;
  531. }
  532. return addr;
  533. }
  534. /* send a command */
  535. static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
  536. {
  537. struct azx *chip = bus->private_data;
  538. unsigned int addr = azx_command_addr(val);
  539. unsigned int wp;
  540. spin_lock_irq(&chip->reg_lock);
  541. /* add command to corb */
  542. wp = azx_readb(chip, CORBWP);
  543. wp++;
  544. wp %= ICH6_MAX_CORB_ENTRIES;
  545. chip->rirb.cmds[addr]++;
  546. chip->corb.buf[wp] = cpu_to_le32(val);
  547. azx_writel(chip, CORBWP, wp);
  548. spin_unlock_irq(&chip->reg_lock);
  549. return 0;
  550. }
  551. #define ICH6_RIRB_EX_UNSOL_EV (1<<4)
  552. /* retrieve RIRB entry - called from interrupt handler */
  553. static void azx_update_rirb(struct azx *chip)
  554. {
  555. unsigned int rp, wp;
  556. unsigned int addr;
  557. u32 res, res_ex;
  558. wp = azx_readb(chip, RIRBWP);
  559. if (wp == chip->rirb.wp)
  560. return;
  561. chip->rirb.wp = wp;
  562. while (chip->rirb.rp != wp) {
  563. chip->rirb.rp++;
  564. chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
  565. rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
  566. res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
  567. res = le32_to_cpu(chip->rirb.buf[rp]);
  568. addr = azx_response_addr(res_ex);
  569. if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
  570. snd_hda_queue_unsol_event(chip->bus, res, res_ex);
  571. else if (chip->rirb.cmds[addr]) {
  572. chip->rirb.res[addr] = res;
  573. smp_wmb();
  574. chip->rirb.cmds[addr]--;
  575. } else
  576. snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "
  577. "last cmd=%#08x\n",
  578. res, res_ex,
  579. chip->last_cmd[addr]);
  580. }
  581. }
  582. /* receive a response */
  583. static unsigned int azx_rirb_get_response(struct hda_bus *bus,
  584. unsigned int addr)
  585. {
  586. struct azx *chip = bus->private_data;
  587. unsigned long timeout;
  588. int do_poll = 0;
  589. again:
  590. timeout = jiffies + msecs_to_jiffies(1000);
  591. for (;;) {
  592. if (chip->polling_mode || do_poll) {
  593. spin_lock_irq(&chip->reg_lock);
  594. azx_update_rirb(chip);
  595. spin_unlock_irq(&chip->reg_lock);
  596. }
  597. if (!chip->rirb.cmds[addr]) {
  598. smp_rmb();
  599. bus->rirb_error = 0;
  600. if (!do_poll)
  601. chip->poll_count = 0;
  602. return chip->rirb.res[addr]; /* the last value */
  603. }
  604. if (time_after(jiffies, timeout))
  605. break;
  606. if (bus->needs_damn_long_delay)
  607. msleep(2); /* temporary workaround */
  608. else {
  609. udelay(10);
  610. cond_resched();
  611. }
  612. }
  613. if (!chip->polling_mode && chip->poll_count < 2) {
  614. snd_printdd(SFX "azx_get_response timeout, "
  615. "polling the codec once: last cmd=0x%08x\n",
  616. chip->last_cmd[addr]);
  617. do_poll = 1;
  618. chip->poll_count++;
  619. goto again;
  620. }
  621. if (!chip->polling_mode) {
  622. snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
  623. "switching to polling mode: last cmd=0x%08x\n",
  624. chip->last_cmd[addr]);
  625. chip->polling_mode = 1;
  626. goto again;
  627. }
  628. if (chip->msi) {
  629. snd_printk(KERN_WARNING SFX "No response from codec, "
  630. "disabling MSI: last cmd=0x%08x\n",
  631. chip->last_cmd[addr]);
  632. free_irq(chip->irq, chip);
  633. chip->irq = -1;
  634. pci_disable_msi(chip->pci);
  635. chip->msi = 0;
  636. if (azx_acquire_irq(chip, 1) < 0) {
  637. bus->rirb_error = 1;
  638. return -1;
  639. }
  640. goto again;
  641. }
  642. if (chip->probing) {
  643. /* If this critical timeout happens during the codec probing
  644. * phase, this is likely an access to a non-existing codec
  645. * slot. Better to return an error and reset the system.
  646. */
  647. return -1;
  648. }
  649. /* a fatal communication error; need either to reset or to fallback
  650. * to the single_cmd mode
  651. */
  652. bus->rirb_error = 1;
  653. if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
  654. bus->response_reset = 1;
  655. return -1; /* give a chance to retry */
  656. }
  657. snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
  658. "switching to single_cmd mode: last cmd=0x%08x\n",
  659. chip->last_cmd[addr]);
  660. chip->single_cmd = 1;
  661. bus->response_reset = 0;
  662. /* release CORB/RIRB */
  663. azx_free_cmd_io(chip);
  664. /* disable unsolicited responses */
  665. azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
  666. return -1;
  667. }
  668. /*
  669. * Use the single immediate command instead of CORB/RIRB for simplicity
  670. *
  671. * Note: according to Intel, this is not preferred use. The command was
  672. * intended for the BIOS only, and may get confused with unsolicited
  673. * responses. So, we shouldn't use it for normal operation from the
  674. * driver.
  675. * I left the codes, however, for debugging/testing purposes.
  676. */
  677. /* receive a response */
  678. static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
  679. {
  680. int timeout = 50;
  681. while (timeout--) {
  682. /* check IRV busy bit */
  683. if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
  684. /* reuse rirb.res as the response return value */
  685. chip->rirb.res[addr] = azx_readl(chip, IR);
  686. return 0;
  687. }
  688. udelay(1);
  689. }
  690. if (printk_ratelimit())
  691. snd_printd(SFX "get_response timeout: IRS=0x%x\n",
  692. azx_readw(chip, IRS));
  693. chip->rirb.res[addr] = -1;
  694. return -EIO;
  695. }
  696. /* send a command */
  697. static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
  698. {
  699. struct azx *chip = bus->private_data;
  700. unsigned int addr = azx_command_addr(val);
  701. int timeout = 50;
  702. bus->rirb_error = 0;
  703. while (timeout--) {
  704. /* check ICB busy bit */
  705. if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
  706. /* Clear IRV valid bit */
  707. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  708. ICH6_IRS_VALID);
  709. azx_writel(chip, IC, val);
  710. azx_writew(chip, IRS, azx_readw(chip, IRS) |
  711. ICH6_IRS_BUSY);
  712. return azx_single_wait_for_response(chip, addr);
  713. }
  714. udelay(1);
  715. }
  716. if (printk_ratelimit())
  717. snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",
  718. azx_readw(chip, IRS), val);
  719. return -EIO;
  720. }
  721. /* receive a response */
  722. static unsigned int azx_single_get_response(struct hda_bus *bus,
  723. unsigned int addr)
  724. {
  725. struct azx *chip = bus->private_data;
  726. return chip->rirb.res[addr];
  727. }
  728. /*
  729. * The below are the main callbacks from hda_codec.
  730. *
  731. * They are just the skeleton to call sub-callbacks according to the
  732. * current setting of chip->single_cmd.
  733. */
  734. /* send a command */
  735. static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
  736. {
  737. struct azx *chip = bus->private_data;
  738. chip->last_cmd[azx_command_addr(val)] = val;
  739. if (chip->single_cmd)
  740. return azx_single_send_cmd(bus, val);
  741. else
  742. return azx_corb_send_cmd(bus, val);
  743. }
  744. /* get a response */
  745. static unsigned int azx_get_response(struct hda_bus *bus,
  746. unsigned int addr)
  747. {
  748. struct azx *chip = bus->private_data;
  749. if (chip->single_cmd)
  750. return azx_single_get_response(bus, addr);
  751. else
  752. return azx_rirb_get_response(bus, addr);
  753. }
  754. #ifdef CONFIG_SND_HDA_POWER_SAVE
  755. static void azx_power_notify(struct hda_bus *bus);
  756. #endif
  757. /* reset codec link */
  758. static int azx_reset(struct azx *chip, int full_reset)
  759. {
  760. int count;
  761. if (!full_reset)
  762. goto __skip;
  763. /* clear STATESTS */
  764. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  765. /* reset controller */
  766. azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
  767. count = 50;
  768. while (azx_readb(chip, GCTL) && --count)
  769. msleep(1);
  770. /* delay for >= 100us for codec PLL to settle per spec
  771. * Rev 0.9 section 5.5.1
  772. */
  773. msleep(1);
  774. /* Bring controller out of reset */
  775. azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
  776. count = 50;
  777. while (!azx_readb(chip, GCTL) && --count)
  778. msleep(1);
  779. /* Brent Chartrand said to wait >= 540us for codecs to initialize */
  780. msleep(1);
  781. __skip:
  782. /* check to see if controller is ready */
  783. if (!azx_readb(chip, GCTL)) {
  784. snd_printd(SFX "azx_reset: controller not ready!\n");
  785. return -EBUSY;
  786. }
  787. /* Accept unsolicited responses */
  788. if (!chip->single_cmd)
  789. azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
  790. ICH6_GCTL_UNSOL);
  791. /* detect codecs */
  792. if (!chip->codec_mask) {
  793. chip->codec_mask = azx_readw(chip, STATESTS);
  794. snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask);
  795. }
  796. return 0;
  797. }
  798. /*
  799. * Lowlevel interface
  800. */
  801. /* enable interrupts */
  802. static void azx_int_enable(struct azx *chip)
  803. {
  804. /* enable controller CIE and GIE */
  805. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
  806. ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
  807. }
  808. /* disable interrupts */
  809. static void azx_int_disable(struct azx *chip)
  810. {
  811. int i;
  812. /* disable interrupts in stream descriptor */
  813. for (i = 0; i < chip->num_streams; i++) {
  814. struct azx_dev *azx_dev = &chip->azx_dev[i];
  815. azx_sd_writeb(azx_dev, SD_CTL,
  816. azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
  817. }
  818. /* disable SIE for all streams */
  819. azx_writeb(chip, INTCTL, 0);
  820. /* disable controller CIE and GIE */
  821. azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
  822. ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
  823. }
  824. /* clear interrupts */
  825. static void azx_int_clear(struct azx *chip)
  826. {
  827. int i;
  828. /* clear stream status */
  829. for (i = 0; i < chip->num_streams; i++) {
  830. struct azx_dev *azx_dev = &chip->azx_dev[i];
  831. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  832. }
  833. /* clear STATESTS */
  834. azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
  835. /* clear rirb status */
  836. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  837. /* clear int status */
  838. azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
  839. }
  840. /* start a stream */
  841. static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
  842. {
  843. /*
  844. * Before stream start, initialize parameter
  845. */
  846. azx_dev->insufficient = 1;
  847. /* enable SIE */
  848. azx_writel(chip, INTCTL,
  849. azx_readl(chip, INTCTL) | (1 << azx_dev->index));
  850. /* set DMA start and interrupt mask */
  851. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  852. SD_CTL_DMA_START | SD_INT_MASK);
  853. }
  854. /* stop DMA */
  855. static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
  856. {
  857. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
  858. ~(SD_CTL_DMA_START | SD_INT_MASK));
  859. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
  860. }
  861. /* stop a stream */
  862. static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
  863. {
  864. azx_stream_clear(chip, azx_dev);
  865. /* disable SIE */
  866. azx_writel(chip, INTCTL,
  867. azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
  868. }
  869. /*
  870. * reset and start the controller registers
  871. */
  872. static void azx_init_chip(struct azx *chip, int full_reset)
  873. {
  874. if (chip->initialized)
  875. return;
  876. /* reset controller */
  877. azx_reset(chip, full_reset);
  878. /* initialize interrupts */
  879. azx_int_clear(chip);
  880. azx_int_enable(chip);
  881. /* initialize the codec command I/O */
  882. if (!chip->single_cmd)
  883. azx_init_cmd_io(chip);
  884. /* program the position buffer */
  885. azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
  886. azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
  887. chip->initialized = 1;
  888. }
  889. /*
  890. * initialize the PCI registers
  891. */
  892. /* update bits in a PCI register byte */
  893. static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
  894. unsigned char mask, unsigned char val)
  895. {
  896. unsigned char data;
  897. pci_read_config_byte(pci, reg, &data);
  898. data &= ~mask;
  899. data |= (val & mask);
  900. pci_write_config_byte(pci, reg, data);
  901. }
  902. static void azx_init_pci(struct azx *chip)
  903. {
  904. unsigned short snoop;
  905. /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  906. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  907. * Ensuring these bits are 0 clears playback static on some HD Audio
  908. * codecs
  909. */
  910. update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
  911. switch (chip->driver_type) {
  912. case AZX_DRIVER_ATI:
  913. /* For ATI SB450 azalia HD audio, we need to enable snoop */
  914. update_pci_byte(chip->pci,
  915. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
  916. 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
  917. break;
  918. case AZX_DRIVER_NVIDIA:
  919. /* For NVIDIA HDA, enable snoop */
  920. update_pci_byte(chip->pci,
  921. NVIDIA_HDA_TRANSREG_ADDR,
  922. 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
  923. update_pci_byte(chip->pci,
  924. NVIDIA_HDA_ISTRM_COH,
  925. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  926. update_pci_byte(chip->pci,
  927. NVIDIA_HDA_OSTRM_COH,
  928. 0x01, NVIDIA_HDA_ENABLE_COHBIT);
  929. break;
  930. case AZX_DRIVER_SCH:
  931. case AZX_DRIVER_PCH:
  932. pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
  933. if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
  934. pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
  935. snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
  936. pci_read_config_word(chip->pci,
  937. INTEL_SCH_HDA_DEVC, &snoop);
  938. snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
  939. (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
  940. ? "Failed" : "OK");
  941. }
  942. break;
  943. }
  944. }
  945. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
  946. /*
  947. * interrupt handler
  948. */
  949. static irqreturn_t azx_interrupt(int irq, void *dev_id)
  950. {
  951. struct azx *chip = dev_id;
  952. struct azx_dev *azx_dev;
  953. u32 status;
  954. u8 sd_status;
  955. int i, ok;
  956. spin_lock(&chip->reg_lock);
  957. status = azx_readl(chip, INTSTS);
  958. if (status == 0) {
  959. spin_unlock(&chip->reg_lock);
  960. return IRQ_NONE;
  961. }
  962. for (i = 0; i < chip->num_streams; i++) {
  963. azx_dev = &chip->azx_dev[i];
  964. if (status & azx_dev->sd_int_sta_mask) {
  965. sd_status = azx_sd_readb(azx_dev, SD_STS);
  966. azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
  967. if (!azx_dev->substream || !azx_dev->running ||
  968. !(sd_status & SD_INT_COMPLETE))
  969. continue;
  970. /* check whether this IRQ is really acceptable */
  971. ok = azx_position_ok(chip, azx_dev);
  972. if (ok == 1) {
  973. azx_dev->irq_pending = 0;
  974. spin_unlock(&chip->reg_lock);
  975. snd_pcm_period_elapsed(azx_dev->substream);
  976. spin_lock(&chip->reg_lock);
  977. } else if (ok == 0 && chip->bus && chip->bus->workq) {
  978. /* bogus IRQ, process it later */
  979. azx_dev->irq_pending = 1;
  980. queue_work(chip->bus->workq,
  981. &chip->irq_pending_work);
  982. }
  983. }
  984. }
  985. /* clear rirb int */
  986. status = azx_readb(chip, RIRBSTS);
  987. if (status & RIRB_INT_MASK) {
  988. if (status & RIRB_INT_RESPONSE) {
  989. if (chip->driver_type == AZX_DRIVER_CTX)
  990. udelay(80);
  991. azx_update_rirb(chip);
  992. }
  993. azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
  994. }
  995. #if 0
  996. /* clear state status int */
  997. if (azx_readb(chip, STATESTS) & 0x04)
  998. azx_writeb(chip, STATESTS, 0x04);
  999. #endif
  1000. spin_unlock(&chip->reg_lock);
  1001. return IRQ_HANDLED;
  1002. }
  1003. /*
  1004. * set up a BDL entry
  1005. */
  1006. static int setup_bdle(struct snd_pcm_substream *substream,
  1007. struct azx_dev *azx_dev, u32 **bdlp,
  1008. int ofs, int size, int with_ioc)
  1009. {
  1010. u32 *bdl = *bdlp;
  1011. while (size > 0) {
  1012. dma_addr_t addr;
  1013. int chunk;
  1014. if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
  1015. return -EINVAL;
  1016. addr = snd_pcm_sgbuf_get_addr(substream, ofs);
  1017. /* program the address field of the BDL entry */
  1018. bdl[0] = cpu_to_le32((u32)addr);
  1019. bdl[1] = cpu_to_le32(upper_32_bits(addr));
  1020. /* program the size field of the BDL entry */
  1021. chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
  1022. bdl[2] = cpu_to_le32(chunk);
  1023. /* program the IOC to enable interrupt
  1024. * only when the whole fragment is processed
  1025. */
  1026. size -= chunk;
  1027. bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
  1028. bdl += 4;
  1029. azx_dev->frags++;
  1030. ofs += chunk;
  1031. }
  1032. *bdlp = bdl;
  1033. return ofs;
  1034. }
  1035. /*
  1036. * set up BDL entries
  1037. */
  1038. static int azx_setup_periods(struct azx *chip,
  1039. struct snd_pcm_substream *substream,
  1040. struct azx_dev *azx_dev)
  1041. {
  1042. u32 *bdl;
  1043. int i, ofs, periods, period_bytes;
  1044. int pos_adj;
  1045. /* reset BDL address */
  1046. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1047. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1048. period_bytes = azx_dev->period_bytes;
  1049. periods = azx_dev->bufsize / period_bytes;
  1050. /* program the initial BDL entries */
  1051. bdl = (u32 *)azx_dev->bdl.area;
  1052. ofs = 0;
  1053. azx_dev->frags = 0;
  1054. pos_adj = bdl_pos_adj[chip->dev_index];
  1055. if (pos_adj > 0) {
  1056. struct snd_pcm_runtime *runtime = substream->runtime;
  1057. int pos_align = pos_adj;
  1058. pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
  1059. if (!pos_adj)
  1060. pos_adj = pos_align;
  1061. else
  1062. pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
  1063. pos_align;
  1064. pos_adj = frames_to_bytes(runtime, pos_adj);
  1065. if (pos_adj >= period_bytes) {
  1066. snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",
  1067. bdl_pos_adj[chip->dev_index]);
  1068. pos_adj = 0;
  1069. } else {
  1070. ofs = setup_bdle(substream, azx_dev,
  1071. &bdl, ofs, pos_adj, 1);
  1072. if (ofs < 0)
  1073. goto error;
  1074. }
  1075. } else
  1076. pos_adj = 0;
  1077. for (i = 0; i < periods; i++) {
  1078. if (i == periods - 1 && pos_adj)
  1079. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1080. period_bytes - pos_adj, 0);
  1081. else
  1082. ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
  1083. period_bytes, 1);
  1084. if (ofs < 0)
  1085. goto error;
  1086. }
  1087. return 0;
  1088. error:
  1089. snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
  1090. azx_dev->bufsize, period_bytes);
  1091. return -EINVAL;
  1092. }
  1093. /* reset stream */
  1094. static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
  1095. {
  1096. unsigned char val;
  1097. int timeout;
  1098. azx_stream_clear(chip, azx_dev);
  1099. azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
  1100. SD_CTL_STREAM_RESET);
  1101. udelay(3);
  1102. timeout = 300;
  1103. while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1104. --timeout)
  1105. ;
  1106. val &= ~SD_CTL_STREAM_RESET;
  1107. azx_sd_writeb(azx_dev, SD_CTL, val);
  1108. udelay(3);
  1109. timeout = 300;
  1110. /* waiting for hardware to report that the stream is out of reset */
  1111. while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
  1112. --timeout)
  1113. ;
  1114. /* reset first position - may not be synced with hw at this time */
  1115. *azx_dev->posbuf = 0;
  1116. }
  1117. /*
  1118. * set up the SD for streaming
  1119. */
  1120. static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
  1121. {
  1122. /* make sure the run bit is zero for SD */
  1123. azx_stream_clear(chip, azx_dev);
  1124. /* program the stream_tag */
  1125. azx_sd_writel(azx_dev, SD_CTL,
  1126. (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
  1127. (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
  1128. /* program the length of samples in cyclic buffer */
  1129. azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
  1130. /* program the stream format */
  1131. /* this value needs to be the same as the one programmed */
  1132. azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
  1133. /* program the stream LVI (last valid index) of the BDL */
  1134. azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
  1135. /* program the BDL address */
  1136. /* lower BDL address */
  1137. azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
  1138. /* upper BDL address */
  1139. azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
  1140. /* enable the position buffer */
  1141. if (chip->position_fix[0] != POS_FIX_LPIB ||
  1142. chip->position_fix[1] != POS_FIX_LPIB) {
  1143. if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
  1144. azx_writel(chip, DPLBASE,
  1145. (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
  1146. }
  1147. /* set the interrupt enable bits in the descriptor control register */
  1148. azx_sd_writel(azx_dev, SD_CTL,
  1149. azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
  1150. return 0;
  1151. }
  1152. /*
  1153. * Probe the given codec address
  1154. */
  1155. static int probe_codec(struct azx *chip, int addr)
  1156. {
  1157. unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
  1158. (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
  1159. unsigned int res;
  1160. mutex_lock(&chip->bus->cmd_mutex);
  1161. chip->probing = 1;
  1162. azx_send_cmd(chip->bus, cmd);
  1163. res = azx_get_response(chip->bus, addr);
  1164. chip->probing = 0;
  1165. mutex_unlock(&chip->bus->cmd_mutex);
  1166. if (res == -1)
  1167. return -EIO;
  1168. snd_printdd(SFX "codec #%d probed OK\n", addr);
  1169. return 0;
  1170. }
  1171. static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1172. struct hda_pcm *cpcm);
  1173. static void azx_stop_chip(struct azx *chip);
  1174. static void azx_bus_reset(struct hda_bus *bus)
  1175. {
  1176. struct azx *chip = bus->private_data;
  1177. bus->in_reset = 1;
  1178. azx_stop_chip(chip);
  1179. azx_init_chip(chip, 1);
  1180. #ifdef CONFIG_PM
  1181. if (chip->initialized) {
  1182. int i;
  1183. for (i = 0; i < HDA_MAX_PCMS; i++)
  1184. snd_pcm_suspend_all(chip->pcm[i]);
  1185. snd_hda_suspend(chip->bus);
  1186. snd_hda_resume(chip->bus);
  1187. }
  1188. #endif
  1189. bus->in_reset = 0;
  1190. }
  1191. /*
  1192. * Codec initialization
  1193. */
  1194. /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
  1195. static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
  1196. [AZX_DRIVER_NVIDIA] = 8,
  1197. [AZX_DRIVER_TERA] = 1,
  1198. };
  1199. static int __devinit azx_codec_create(struct azx *chip, const char *model)
  1200. {
  1201. struct hda_bus_template bus_temp;
  1202. int c, codecs, err;
  1203. int max_slots;
  1204. memset(&bus_temp, 0, sizeof(bus_temp));
  1205. bus_temp.private_data = chip;
  1206. bus_temp.modelname = model;
  1207. bus_temp.pci = chip->pci;
  1208. bus_temp.ops.command = azx_send_cmd;
  1209. bus_temp.ops.get_response = azx_get_response;
  1210. bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
  1211. bus_temp.ops.bus_reset = azx_bus_reset;
  1212. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1213. bus_temp.power_save = &power_save;
  1214. bus_temp.ops.pm_notify = azx_power_notify;
  1215. #endif
  1216. err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
  1217. if (err < 0)
  1218. return err;
  1219. if (chip->driver_type == AZX_DRIVER_NVIDIA)
  1220. chip->bus->needs_damn_long_delay = 1;
  1221. codecs = 0;
  1222. max_slots = azx_max_codecs[chip->driver_type];
  1223. if (!max_slots)
  1224. max_slots = AZX_DEFAULT_CODECS;
  1225. /* First try to probe all given codec slots */
  1226. for (c = 0; c < max_slots; c++) {
  1227. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1228. if (probe_codec(chip, c) < 0) {
  1229. /* Some BIOSen give you wrong codec addresses
  1230. * that don't exist
  1231. */
  1232. snd_printk(KERN_WARNING SFX
  1233. "Codec #%d probe error; "
  1234. "disabling it...\n", c);
  1235. chip->codec_mask &= ~(1 << c);
  1236. /* More badly, accessing to a non-existing
  1237. * codec often screws up the controller chip,
  1238. * and disturbs the further communications.
  1239. * Thus if an error occurs during probing,
  1240. * better to reset the controller chip to
  1241. * get back to the sanity state.
  1242. */
  1243. azx_stop_chip(chip);
  1244. azx_init_chip(chip, 1);
  1245. }
  1246. }
  1247. }
  1248. /* Then create codec instances */
  1249. for (c = 0; c < max_slots; c++) {
  1250. if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
  1251. struct hda_codec *codec;
  1252. err = snd_hda_codec_new(chip->bus, c, &codec);
  1253. if (err < 0)
  1254. continue;
  1255. codec->beep_mode = chip->beep_mode;
  1256. codecs++;
  1257. }
  1258. }
  1259. if (!codecs) {
  1260. snd_printk(KERN_ERR SFX "no codecs initialized\n");
  1261. return -ENXIO;
  1262. }
  1263. return 0;
  1264. }
  1265. /* configure each codec instance */
  1266. static int __devinit azx_codec_configure(struct azx *chip)
  1267. {
  1268. struct hda_codec *codec;
  1269. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  1270. snd_hda_codec_configure(codec);
  1271. }
  1272. return 0;
  1273. }
  1274. /*
  1275. * PCM support
  1276. */
  1277. /* assign a stream for the PCM */
  1278. static inline struct azx_dev *
  1279. azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
  1280. {
  1281. int dev, i, nums;
  1282. struct azx_dev *res = NULL;
  1283. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1284. dev = chip->playback_index_offset;
  1285. nums = chip->playback_streams;
  1286. } else {
  1287. dev = chip->capture_index_offset;
  1288. nums = chip->capture_streams;
  1289. }
  1290. for (i = 0; i < nums; i++, dev++)
  1291. if (!chip->azx_dev[dev].opened) {
  1292. res = &chip->azx_dev[dev];
  1293. if (res->device == substream->pcm->device)
  1294. break;
  1295. }
  1296. if (res) {
  1297. res->opened = 1;
  1298. res->device = substream->pcm->device;
  1299. }
  1300. return res;
  1301. }
  1302. /* release the assigned stream */
  1303. static inline void azx_release_device(struct azx_dev *azx_dev)
  1304. {
  1305. azx_dev->opened = 0;
  1306. }
  1307. static struct snd_pcm_hardware azx_pcm_hw = {
  1308. .info = (SNDRV_PCM_INFO_MMAP |
  1309. SNDRV_PCM_INFO_INTERLEAVED |
  1310. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1311. SNDRV_PCM_INFO_MMAP_VALID |
  1312. /* No full-resume yet implemented */
  1313. /* SNDRV_PCM_INFO_RESUME |*/
  1314. SNDRV_PCM_INFO_PAUSE |
  1315. SNDRV_PCM_INFO_SYNC_START),
  1316. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1317. .rates = SNDRV_PCM_RATE_48000,
  1318. .rate_min = 48000,
  1319. .rate_max = 48000,
  1320. .channels_min = 2,
  1321. .channels_max = 2,
  1322. .buffer_bytes_max = AZX_MAX_BUF_SIZE,
  1323. .period_bytes_min = 128,
  1324. .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
  1325. .periods_min = 2,
  1326. .periods_max = AZX_MAX_FRAG,
  1327. .fifo_size = 0,
  1328. };
  1329. struct azx_pcm {
  1330. struct azx *chip;
  1331. struct hda_codec *codec;
  1332. struct hda_pcm_stream *hinfo[2];
  1333. };
  1334. static int azx_pcm_open(struct snd_pcm_substream *substream)
  1335. {
  1336. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1337. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1338. struct azx *chip = apcm->chip;
  1339. struct azx_dev *azx_dev;
  1340. struct snd_pcm_runtime *runtime = substream->runtime;
  1341. unsigned long flags;
  1342. int err;
  1343. mutex_lock(&chip->open_mutex);
  1344. azx_dev = azx_assign_device(chip, substream);
  1345. if (azx_dev == NULL) {
  1346. mutex_unlock(&chip->open_mutex);
  1347. return -EBUSY;
  1348. }
  1349. runtime->hw = azx_pcm_hw;
  1350. runtime->hw.channels_min = hinfo->channels_min;
  1351. runtime->hw.channels_max = hinfo->channels_max;
  1352. runtime->hw.formats = hinfo->formats;
  1353. runtime->hw.rates = hinfo->rates;
  1354. snd_pcm_limit_hw_rates(runtime);
  1355. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  1356. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  1357. 128);
  1358. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  1359. 128);
  1360. snd_hda_power_up(apcm->codec);
  1361. err = hinfo->ops.open(hinfo, apcm->codec, substream);
  1362. if (err < 0) {
  1363. azx_release_device(azx_dev);
  1364. snd_hda_power_down(apcm->codec);
  1365. mutex_unlock(&chip->open_mutex);
  1366. return err;
  1367. }
  1368. snd_pcm_limit_hw_rates(runtime);
  1369. /* sanity check */
  1370. if (snd_BUG_ON(!runtime->hw.channels_min) ||
  1371. snd_BUG_ON(!runtime->hw.channels_max) ||
  1372. snd_BUG_ON(!runtime->hw.formats) ||
  1373. snd_BUG_ON(!runtime->hw.rates)) {
  1374. azx_release_device(azx_dev);
  1375. hinfo->ops.close(hinfo, apcm->codec, substream);
  1376. snd_hda_power_down(apcm->codec);
  1377. mutex_unlock(&chip->open_mutex);
  1378. return -EINVAL;
  1379. }
  1380. spin_lock_irqsave(&chip->reg_lock, flags);
  1381. azx_dev->substream = substream;
  1382. azx_dev->running = 0;
  1383. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1384. runtime->private_data = azx_dev;
  1385. snd_pcm_set_sync(substream);
  1386. mutex_unlock(&chip->open_mutex);
  1387. return 0;
  1388. }
  1389. static int azx_pcm_close(struct snd_pcm_substream *substream)
  1390. {
  1391. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1392. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1393. struct azx *chip = apcm->chip;
  1394. struct azx_dev *azx_dev = get_azx_dev(substream);
  1395. unsigned long flags;
  1396. mutex_lock(&chip->open_mutex);
  1397. spin_lock_irqsave(&chip->reg_lock, flags);
  1398. azx_dev->substream = NULL;
  1399. azx_dev->running = 0;
  1400. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1401. azx_release_device(azx_dev);
  1402. hinfo->ops.close(hinfo, apcm->codec, substream);
  1403. snd_hda_power_down(apcm->codec);
  1404. mutex_unlock(&chip->open_mutex);
  1405. return 0;
  1406. }
  1407. static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
  1408. struct snd_pcm_hw_params *hw_params)
  1409. {
  1410. struct azx_dev *azx_dev = get_azx_dev(substream);
  1411. azx_dev->bufsize = 0;
  1412. azx_dev->period_bytes = 0;
  1413. azx_dev->format_val = 0;
  1414. return snd_pcm_lib_malloc_pages(substream,
  1415. params_buffer_bytes(hw_params));
  1416. }
  1417. static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
  1418. {
  1419. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1420. struct azx_dev *azx_dev = get_azx_dev(substream);
  1421. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1422. /* reset BDL address */
  1423. azx_sd_writel(azx_dev, SD_BDLPL, 0);
  1424. azx_sd_writel(azx_dev, SD_BDLPU, 0);
  1425. azx_sd_writel(azx_dev, SD_CTL, 0);
  1426. azx_dev->bufsize = 0;
  1427. azx_dev->period_bytes = 0;
  1428. azx_dev->format_val = 0;
  1429. snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
  1430. return snd_pcm_lib_free_pages(substream);
  1431. }
  1432. static int azx_pcm_prepare(struct snd_pcm_substream *substream)
  1433. {
  1434. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1435. struct azx *chip = apcm->chip;
  1436. struct azx_dev *azx_dev = get_azx_dev(substream);
  1437. struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
  1438. struct snd_pcm_runtime *runtime = substream->runtime;
  1439. unsigned int bufsize, period_bytes, format_val, stream_tag;
  1440. int err;
  1441. azx_stream_reset(chip, azx_dev);
  1442. format_val = snd_hda_calc_stream_format(runtime->rate,
  1443. runtime->channels,
  1444. runtime->format,
  1445. hinfo->maxbps,
  1446. apcm->codec->spdif_ctls);
  1447. if (!format_val) {
  1448. snd_printk(KERN_ERR SFX
  1449. "invalid format_val, rate=%d, ch=%d, format=%d\n",
  1450. runtime->rate, runtime->channels, runtime->format);
  1451. return -EINVAL;
  1452. }
  1453. bufsize = snd_pcm_lib_buffer_bytes(substream);
  1454. period_bytes = snd_pcm_lib_period_bytes(substream);
  1455. snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
  1456. bufsize, format_val);
  1457. if (bufsize != azx_dev->bufsize ||
  1458. period_bytes != azx_dev->period_bytes ||
  1459. format_val != azx_dev->format_val) {
  1460. azx_dev->bufsize = bufsize;
  1461. azx_dev->period_bytes = period_bytes;
  1462. azx_dev->format_val = format_val;
  1463. err = azx_setup_periods(chip, substream, azx_dev);
  1464. if (err < 0)
  1465. return err;
  1466. }
  1467. /* wallclk has 24Mhz clock source */
  1468. azx_dev->period_wallclk = (((runtime->period_size * 24000) /
  1469. runtime->rate) * 1000);
  1470. azx_setup_controller(chip, azx_dev);
  1471. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1472. azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
  1473. else
  1474. azx_dev->fifo_size = 0;
  1475. stream_tag = azx_dev->stream_tag;
  1476. /* CA-IBG chips need the playback stream starting from 1 */
  1477. if (chip->driver_type == AZX_DRIVER_CTX &&
  1478. stream_tag > chip->capture_streams)
  1479. stream_tag -= chip->capture_streams;
  1480. return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
  1481. azx_dev->format_val, substream);
  1482. }
  1483. static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  1484. {
  1485. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1486. struct azx *chip = apcm->chip;
  1487. struct azx_dev *azx_dev;
  1488. struct snd_pcm_substream *s;
  1489. int rstart = 0, start, nsync = 0, sbits = 0;
  1490. int nwait, timeout;
  1491. switch (cmd) {
  1492. case SNDRV_PCM_TRIGGER_START:
  1493. rstart = 1;
  1494. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1495. case SNDRV_PCM_TRIGGER_RESUME:
  1496. start = 1;
  1497. break;
  1498. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1499. case SNDRV_PCM_TRIGGER_SUSPEND:
  1500. case SNDRV_PCM_TRIGGER_STOP:
  1501. start = 0;
  1502. break;
  1503. default:
  1504. return -EINVAL;
  1505. }
  1506. snd_pcm_group_for_each_entry(s, substream) {
  1507. if (s->pcm->card != substream->pcm->card)
  1508. continue;
  1509. azx_dev = get_azx_dev(s);
  1510. sbits |= 1 << azx_dev->index;
  1511. nsync++;
  1512. snd_pcm_trigger_done(s, substream);
  1513. }
  1514. spin_lock(&chip->reg_lock);
  1515. if (nsync > 1) {
  1516. /* first, set SYNC bits of corresponding streams */
  1517. azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
  1518. }
  1519. snd_pcm_group_for_each_entry(s, substream) {
  1520. if (s->pcm->card != substream->pcm->card)
  1521. continue;
  1522. azx_dev = get_azx_dev(s);
  1523. if (start) {
  1524. azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
  1525. if (!rstart)
  1526. azx_dev->start_wallclk -=
  1527. azx_dev->period_wallclk;
  1528. azx_stream_start(chip, azx_dev);
  1529. } else {
  1530. azx_stream_stop(chip, azx_dev);
  1531. }
  1532. azx_dev->running = start;
  1533. }
  1534. spin_unlock(&chip->reg_lock);
  1535. if (start) {
  1536. if (nsync == 1)
  1537. return 0;
  1538. /* wait until all FIFOs get ready */
  1539. for (timeout = 5000; timeout; timeout--) {
  1540. nwait = 0;
  1541. snd_pcm_group_for_each_entry(s, substream) {
  1542. if (s->pcm->card != substream->pcm->card)
  1543. continue;
  1544. azx_dev = get_azx_dev(s);
  1545. if (!(azx_sd_readb(azx_dev, SD_STS) &
  1546. SD_STS_FIFO_READY))
  1547. nwait++;
  1548. }
  1549. if (!nwait)
  1550. break;
  1551. cpu_relax();
  1552. }
  1553. } else {
  1554. /* wait until all RUN bits are cleared */
  1555. for (timeout = 5000; timeout; timeout--) {
  1556. nwait = 0;
  1557. snd_pcm_group_for_each_entry(s, substream) {
  1558. if (s->pcm->card != substream->pcm->card)
  1559. continue;
  1560. azx_dev = get_azx_dev(s);
  1561. if (azx_sd_readb(azx_dev, SD_CTL) &
  1562. SD_CTL_DMA_START)
  1563. nwait++;
  1564. }
  1565. if (!nwait)
  1566. break;
  1567. cpu_relax();
  1568. }
  1569. }
  1570. if (nsync > 1) {
  1571. spin_lock(&chip->reg_lock);
  1572. /* reset SYNC bits */
  1573. azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
  1574. spin_unlock(&chip->reg_lock);
  1575. }
  1576. return 0;
  1577. }
  1578. /* get the current DMA position with correction on VIA chips */
  1579. static unsigned int azx_via_get_position(struct azx *chip,
  1580. struct azx_dev *azx_dev)
  1581. {
  1582. unsigned int link_pos, mini_pos, bound_pos;
  1583. unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
  1584. unsigned int fifo_size;
  1585. link_pos = azx_sd_readl(azx_dev, SD_LPIB);
  1586. if (azx_dev->index >= 4) {
  1587. /* Playback, no problem using link position */
  1588. return link_pos;
  1589. }
  1590. /* Capture */
  1591. /* For new chipset,
  1592. * use mod to get the DMA position just like old chipset
  1593. */
  1594. mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
  1595. mod_dma_pos %= azx_dev->period_bytes;
  1596. /* azx_dev->fifo_size can't get FIFO size of in stream.
  1597. * Get from base address + offset.
  1598. */
  1599. fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
  1600. if (azx_dev->insufficient) {
  1601. /* Link position never gather than FIFO size */
  1602. if (link_pos <= fifo_size)
  1603. return 0;
  1604. azx_dev->insufficient = 0;
  1605. }
  1606. if (link_pos <= fifo_size)
  1607. mini_pos = azx_dev->bufsize + link_pos - fifo_size;
  1608. else
  1609. mini_pos = link_pos - fifo_size;
  1610. /* Find nearest previous boudary */
  1611. mod_mini_pos = mini_pos % azx_dev->period_bytes;
  1612. mod_link_pos = link_pos % azx_dev->period_bytes;
  1613. if (mod_link_pos >= fifo_size)
  1614. bound_pos = link_pos - mod_link_pos;
  1615. else if (mod_dma_pos >= mod_mini_pos)
  1616. bound_pos = mini_pos - mod_mini_pos;
  1617. else {
  1618. bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
  1619. if (bound_pos >= azx_dev->bufsize)
  1620. bound_pos = 0;
  1621. }
  1622. /* Calculate real DMA position we want */
  1623. return bound_pos + mod_dma_pos;
  1624. }
  1625. static unsigned int azx_get_position(struct azx *chip,
  1626. struct azx_dev *azx_dev)
  1627. {
  1628. unsigned int pos;
  1629. int stream = azx_dev->substream->stream;
  1630. switch (chip->position_fix[stream]) {
  1631. case POS_FIX_LPIB:
  1632. /* read LPIB */
  1633. pos = azx_sd_readl(azx_dev, SD_LPIB);
  1634. break;
  1635. case POS_FIX_VIACOMBO:
  1636. pos = azx_via_get_position(chip, azx_dev);
  1637. break;
  1638. default:
  1639. /* use the position buffer */
  1640. pos = le32_to_cpu(*azx_dev->posbuf);
  1641. }
  1642. if (pos >= azx_dev->bufsize)
  1643. pos = 0;
  1644. return pos;
  1645. }
  1646. static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
  1647. {
  1648. struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
  1649. struct azx *chip = apcm->chip;
  1650. struct azx_dev *azx_dev = get_azx_dev(substream);
  1651. return bytes_to_frames(substream->runtime,
  1652. azx_get_position(chip, azx_dev));
  1653. }
  1654. /*
  1655. * Check whether the current DMA position is acceptable for updating
  1656. * periods. Returns non-zero if it's OK.
  1657. *
  1658. * Many HD-audio controllers appear pretty inaccurate about
  1659. * the update-IRQ timing. The IRQ is issued before actually the
  1660. * data is processed. So, we need to process it afterwords in a
  1661. * workqueue.
  1662. */
  1663. static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
  1664. {
  1665. u32 wallclk;
  1666. unsigned int pos;
  1667. int stream;
  1668. wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
  1669. if (wallclk < (azx_dev->period_wallclk * 2) / 3)
  1670. return -1; /* bogus (too early) interrupt */
  1671. stream = azx_dev->substream->stream;
  1672. pos = azx_get_position(chip, azx_dev);
  1673. if (chip->position_fix[stream] == POS_FIX_AUTO) {
  1674. if (!pos) {
  1675. printk(KERN_WARNING
  1676. "hda-intel: Invalid position buffer, "
  1677. "using LPIB read method instead.\n");
  1678. chip->position_fix[stream] = POS_FIX_LPIB;
  1679. pos = azx_get_position(chip, azx_dev);
  1680. } else
  1681. chip->position_fix[stream] = POS_FIX_POSBUF;
  1682. }
  1683. if (WARN_ONCE(!azx_dev->period_bytes,
  1684. "hda-intel: zero azx_dev->period_bytes"))
  1685. return -1; /* this shouldn't happen! */
  1686. if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
  1687. pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
  1688. /* NG - it's below the first next period boundary */
  1689. return bdl_pos_adj[chip->dev_index] ? 0 : -1;
  1690. azx_dev->start_wallclk += wallclk;
  1691. return 1; /* OK, it's fine */
  1692. }
  1693. /*
  1694. * The work for pending PCM period updates.
  1695. */
  1696. static void azx_irq_pending_work(struct work_struct *work)
  1697. {
  1698. struct azx *chip = container_of(work, struct azx, irq_pending_work);
  1699. int i, pending, ok;
  1700. if (!chip->irq_pending_warned) {
  1701. printk(KERN_WARNING
  1702. "hda-intel: IRQ timing workaround is activated "
  1703. "for card #%d. Suggest a bigger bdl_pos_adj.\n",
  1704. chip->card->number);
  1705. chip->irq_pending_warned = 1;
  1706. }
  1707. for (;;) {
  1708. pending = 0;
  1709. spin_lock_irq(&chip->reg_lock);
  1710. for (i = 0; i < chip->num_streams; i++) {
  1711. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1712. if (!azx_dev->irq_pending ||
  1713. !azx_dev->substream ||
  1714. !azx_dev->running)
  1715. continue;
  1716. ok = azx_position_ok(chip, azx_dev);
  1717. if (ok > 0) {
  1718. azx_dev->irq_pending = 0;
  1719. spin_unlock(&chip->reg_lock);
  1720. snd_pcm_period_elapsed(azx_dev->substream);
  1721. spin_lock(&chip->reg_lock);
  1722. } else if (ok < 0) {
  1723. pending = 0; /* too early */
  1724. } else
  1725. pending++;
  1726. }
  1727. spin_unlock_irq(&chip->reg_lock);
  1728. if (!pending)
  1729. return;
  1730. msleep(1);
  1731. }
  1732. }
  1733. /* clear irq_pending flags and assure no on-going workq */
  1734. static void azx_clear_irq_pending(struct azx *chip)
  1735. {
  1736. int i;
  1737. spin_lock_irq(&chip->reg_lock);
  1738. for (i = 0; i < chip->num_streams; i++)
  1739. chip->azx_dev[i].irq_pending = 0;
  1740. spin_unlock_irq(&chip->reg_lock);
  1741. }
  1742. static struct snd_pcm_ops azx_pcm_ops = {
  1743. .open = azx_pcm_open,
  1744. .close = azx_pcm_close,
  1745. .ioctl = snd_pcm_lib_ioctl,
  1746. .hw_params = azx_pcm_hw_params,
  1747. .hw_free = azx_pcm_hw_free,
  1748. .prepare = azx_pcm_prepare,
  1749. .trigger = azx_pcm_trigger,
  1750. .pointer = azx_pcm_pointer,
  1751. .page = snd_pcm_sgbuf_ops_page,
  1752. };
  1753. static void azx_pcm_free(struct snd_pcm *pcm)
  1754. {
  1755. struct azx_pcm *apcm = pcm->private_data;
  1756. if (apcm) {
  1757. apcm->chip->pcm[pcm->device] = NULL;
  1758. kfree(apcm);
  1759. }
  1760. }
  1761. static int
  1762. azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
  1763. struct hda_pcm *cpcm)
  1764. {
  1765. struct azx *chip = bus->private_data;
  1766. struct snd_pcm *pcm;
  1767. struct azx_pcm *apcm;
  1768. int pcm_dev = cpcm->device;
  1769. int s, err;
  1770. if (pcm_dev >= HDA_MAX_PCMS) {
  1771. snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
  1772. pcm_dev);
  1773. return -EINVAL;
  1774. }
  1775. if (chip->pcm[pcm_dev]) {
  1776. snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
  1777. return -EBUSY;
  1778. }
  1779. err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
  1780. cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
  1781. cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
  1782. &pcm);
  1783. if (err < 0)
  1784. return err;
  1785. strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
  1786. apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
  1787. if (apcm == NULL)
  1788. return -ENOMEM;
  1789. apcm->chip = chip;
  1790. apcm->codec = codec;
  1791. pcm->private_data = apcm;
  1792. pcm->private_free = azx_pcm_free;
  1793. if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
  1794. pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
  1795. chip->pcm[pcm_dev] = pcm;
  1796. cpcm->pcm = pcm;
  1797. for (s = 0; s < 2; s++) {
  1798. apcm->hinfo[s] = &cpcm->stream[s];
  1799. if (cpcm->stream[s].substreams)
  1800. snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
  1801. }
  1802. /* buffer pre-allocation */
  1803. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  1804. snd_dma_pci_data(chip->pci),
  1805. 1024 * 64, 32 * 1024 * 1024);
  1806. return 0;
  1807. }
  1808. /*
  1809. * mixer creation - all stuff is implemented in hda module
  1810. */
  1811. static int __devinit azx_mixer_create(struct azx *chip)
  1812. {
  1813. return snd_hda_build_controls(chip->bus);
  1814. }
  1815. /*
  1816. * initialize SD streams
  1817. */
  1818. static int __devinit azx_init_stream(struct azx *chip)
  1819. {
  1820. int i;
  1821. /* initialize each stream (aka device)
  1822. * assign the starting bdl address to each stream (device)
  1823. * and initialize
  1824. */
  1825. for (i = 0; i < chip->num_streams; i++) {
  1826. struct azx_dev *azx_dev = &chip->azx_dev[i];
  1827. azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
  1828. /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  1829. azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
  1830. /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
  1831. azx_dev->sd_int_sta_mask = 1 << i;
  1832. /* stream tag: must be non-zero and unique */
  1833. azx_dev->index = i;
  1834. azx_dev->stream_tag = i + 1;
  1835. }
  1836. return 0;
  1837. }
  1838. static int azx_acquire_irq(struct azx *chip, int do_disconnect)
  1839. {
  1840. if (request_irq(chip->pci->irq, azx_interrupt,
  1841. chip->msi ? 0 : IRQF_SHARED,
  1842. "hda_intel", chip)) {
  1843. printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
  1844. "disabling device\n", chip->pci->irq);
  1845. if (do_disconnect)
  1846. snd_card_disconnect(chip->card);
  1847. return -1;
  1848. }
  1849. chip->irq = chip->pci->irq;
  1850. pci_intx(chip->pci, !chip->msi);
  1851. return 0;
  1852. }
  1853. static void azx_stop_chip(struct azx *chip)
  1854. {
  1855. if (!chip->initialized)
  1856. return;
  1857. /* disable interrupts */
  1858. azx_int_disable(chip);
  1859. azx_int_clear(chip);
  1860. /* disable CORB/RIRB */
  1861. azx_free_cmd_io(chip);
  1862. /* disable position buffer */
  1863. azx_writel(chip, DPLBASE, 0);
  1864. azx_writel(chip, DPUBASE, 0);
  1865. chip->initialized = 0;
  1866. }
  1867. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1868. /* power-up/down the controller */
  1869. static void azx_power_notify(struct hda_bus *bus)
  1870. {
  1871. struct azx *chip = bus->private_data;
  1872. struct hda_codec *c;
  1873. int power_on = 0;
  1874. list_for_each_entry(c, &bus->codec_list, list) {
  1875. if (c->power_on) {
  1876. power_on = 1;
  1877. break;
  1878. }
  1879. }
  1880. if (power_on)
  1881. azx_init_chip(chip, 1);
  1882. else if (chip->running && power_save_controller &&
  1883. !bus->power_keep_link_on)
  1884. azx_stop_chip(chip);
  1885. }
  1886. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  1887. #ifdef CONFIG_PM
  1888. /*
  1889. * power management
  1890. */
  1891. static int snd_hda_codecs_inuse(struct hda_bus *bus)
  1892. {
  1893. struct hda_codec *codec;
  1894. list_for_each_entry(codec, &bus->codec_list, list) {
  1895. if (snd_hda_codec_needs_resume(codec))
  1896. return 1;
  1897. }
  1898. return 0;
  1899. }
  1900. static int azx_suspend(struct pci_dev *pci, pm_message_t state)
  1901. {
  1902. struct snd_card *card = pci_get_drvdata(pci);
  1903. struct azx *chip = card->private_data;
  1904. int i;
  1905. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1906. azx_clear_irq_pending(chip);
  1907. for (i = 0; i < HDA_MAX_PCMS; i++)
  1908. snd_pcm_suspend_all(chip->pcm[i]);
  1909. if (chip->initialized)
  1910. snd_hda_suspend(chip->bus);
  1911. azx_stop_chip(chip);
  1912. if (chip->irq >= 0) {
  1913. free_irq(chip->irq, chip);
  1914. chip->irq = -1;
  1915. }
  1916. if (chip->msi)
  1917. pci_disable_msi(chip->pci);
  1918. pci_disable_device(pci);
  1919. pci_save_state(pci);
  1920. pci_set_power_state(pci, pci_choose_state(pci, state));
  1921. return 0;
  1922. }
  1923. static int azx_resume(struct pci_dev *pci)
  1924. {
  1925. struct snd_card *card = pci_get_drvdata(pci);
  1926. struct azx *chip = card->private_data;
  1927. pci_set_power_state(pci, PCI_D0);
  1928. pci_restore_state(pci);
  1929. if (pci_enable_device(pci) < 0) {
  1930. printk(KERN_ERR "hda-intel: pci_enable_device failed, "
  1931. "disabling device\n");
  1932. snd_card_disconnect(card);
  1933. return -EIO;
  1934. }
  1935. pci_set_master(pci);
  1936. if (chip->msi)
  1937. if (pci_enable_msi(pci) < 0)
  1938. chip->msi = 0;
  1939. if (azx_acquire_irq(chip, 1) < 0)
  1940. return -EIO;
  1941. azx_init_pci(chip);
  1942. if (snd_hda_codecs_inuse(chip->bus))
  1943. azx_init_chip(chip, 1);
  1944. snd_hda_resume(chip->bus);
  1945. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1946. return 0;
  1947. }
  1948. #endif /* CONFIG_PM */
  1949. /*
  1950. * reboot notifier for hang-up problem at power-down
  1951. */
  1952. static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
  1953. {
  1954. struct azx *chip = container_of(nb, struct azx, reboot_notifier);
  1955. snd_hda_bus_reboot_notify(chip->bus);
  1956. azx_stop_chip(chip);
  1957. return NOTIFY_OK;
  1958. }
  1959. static void azx_notifier_register(struct azx *chip)
  1960. {
  1961. chip->reboot_notifier.notifier_call = azx_halt;
  1962. register_reboot_notifier(&chip->reboot_notifier);
  1963. }
  1964. static void azx_notifier_unregister(struct azx *chip)
  1965. {
  1966. if (chip->reboot_notifier.notifier_call)
  1967. unregister_reboot_notifier(&chip->reboot_notifier);
  1968. }
  1969. /*
  1970. * destructor
  1971. */
  1972. static int azx_free(struct azx *chip)
  1973. {
  1974. int i;
  1975. azx_notifier_unregister(chip);
  1976. if (chip->initialized) {
  1977. azx_clear_irq_pending(chip);
  1978. for (i = 0; i < chip->num_streams; i++)
  1979. azx_stream_stop(chip, &chip->azx_dev[i]);
  1980. azx_stop_chip(chip);
  1981. }
  1982. if (chip->irq >= 0)
  1983. free_irq(chip->irq, (void*)chip);
  1984. if (chip->msi)
  1985. pci_disable_msi(chip->pci);
  1986. if (chip->remap_addr)
  1987. iounmap(chip->remap_addr);
  1988. if (chip->azx_dev) {
  1989. for (i = 0; i < chip->num_streams; i++)
  1990. if (chip->azx_dev[i].bdl.area)
  1991. snd_dma_free_pages(&chip->azx_dev[i].bdl);
  1992. }
  1993. if (chip->rb.area)
  1994. snd_dma_free_pages(&chip->rb);
  1995. if (chip->posbuf.area)
  1996. snd_dma_free_pages(&chip->posbuf);
  1997. pci_release_regions(chip->pci);
  1998. pci_disable_device(chip->pci);
  1999. kfree(chip->azx_dev);
  2000. kfree(chip);
  2001. return 0;
  2002. }
  2003. static int azx_dev_free(struct snd_device *device)
  2004. {
  2005. return azx_free(device->device_data);
  2006. }
  2007. /*
  2008. * white/black-listing for position_fix
  2009. */
  2010. static struct snd_pci_quirk position_fix_list[] __devinitdata = {
  2011. SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
  2012. SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
  2013. SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
  2014. SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
  2015. SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
  2016. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
  2017. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
  2018. SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
  2019. SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
  2020. SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
  2021. SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),
  2022. SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
  2023. SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
  2024. SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
  2025. SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
  2026. SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
  2027. SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
  2028. SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
  2029. SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
  2030. {}
  2031. };
  2032. static int __devinit check_position_fix(struct azx *chip, int fix)
  2033. {
  2034. const struct snd_pci_quirk *q;
  2035. switch (fix) {
  2036. case POS_FIX_LPIB:
  2037. case POS_FIX_POSBUF:
  2038. case POS_FIX_VIACOMBO:
  2039. return fix;
  2040. }
  2041. q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
  2042. if (q) {
  2043. printk(KERN_INFO
  2044. "hda_intel: position_fix set to %d "
  2045. "for device %04x:%04x\n",
  2046. q->value, q->subvendor, q->subdevice);
  2047. return q->value;
  2048. }
  2049. /* Check VIA/ATI HD Audio Controller exist */
  2050. switch (chip->driver_type) {
  2051. case AZX_DRIVER_VIA:
  2052. case AZX_DRIVER_ATI:
  2053. /* Use link position directly, avoid any transfer problem. */
  2054. return POS_FIX_VIACOMBO;
  2055. }
  2056. return POS_FIX_AUTO;
  2057. }
  2058. /*
  2059. * black-lists for probe_mask
  2060. */
  2061. static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
  2062. /* Thinkpad often breaks the controller communication when accessing
  2063. * to the non-working (or non-existing) modem codec slot.
  2064. */
  2065. SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
  2066. SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
  2067. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
  2068. /* broken BIOS */
  2069. SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
  2070. /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
  2071. SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
  2072. /* forced codec slots */
  2073. SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
  2074. SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
  2075. {}
  2076. };
  2077. #define AZX_FORCE_CODEC_MASK 0x100
  2078. static void __devinit check_probe_mask(struct azx *chip, int dev)
  2079. {
  2080. const struct snd_pci_quirk *q;
  2081. chip->codec_probe_mask = probe_mask[dev];
  2082. if (chip->codec_probe_mask == -1) {
  2083. q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
  2084. if (q) {
  2085. printk(KERN_INFO
  2086. "hda_intel: probe_mask set to 0x%x "
  2087. "for device %04x:%04x\n",
  2088. q->value, q->subvendor, q->subdevice);
  2089. chip->codec_probe_mask = q->value;
  2090. }
  2091. }
  2092. /* check forced option */
  2093. if (chip->codec_probe_mask != -1 &&
  2094. (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
  2095. chip->codec_mask = chip->codec_probe_mask & 0xff;
  2096. printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
  2097. chip->codec_mask);
  2098. }
  2099. }
  2100. /*
  2101. * white/black-list for enable_msi
  2102. */
  2103. static struct snd_pci_quirk msi_black_list[] __devinitdata = {
  2104. SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
  2105. SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
  2106. SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
  2107. SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
  2108. SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
  2109. {}
  2110. };
  2111. static void __devinit check_msi(struct azx *chip)
  2112. {
  2113. const struct snd_pci_quirk *q;
  2114. if (enable_msi >= 0) {
  2115. chip->msi = !!enable_msi;
  2116. return;
  2117. }
  2118. chip->msi = 1; /* enable MSI as default */
  2119. q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
  2120. if (q) {
  2121. printk(KERN_INFO
  2122. "hda_intel: msi for device %04x:%04x set to %d\n",
  2123. q->subvendor, q->subdevice, q->value);
  2124. chip->msi = q->value;
  2125. return;
  2126. }
  2127. /* NVidia chipsets seem to cause troubles with MSI */
  2128. if (chip->driver_type == AZX_DRIVER_NVIDIA) {
  2129. printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
  2130. chip->msi = 0;
  2131. }
  2132. }
  2133. /*
  2134. * constructor
  2135. */
  2136. static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
  2137. int dev, int driver_type,
  2138. struct azx **rchip)
  2139. {
  2140. struct azx *chip;
  2141. int i, err;
  2142. unsigned short gcap;
  2143. static struct snd_device_ops ops = {
  2144. .dev_free = azx_dev_free,
  2145. };
  2146. *rchip = NULL;
  2147. err = pci_enable_device(pci);
  2148. if (err < 0)
  2149. return err;
  2150. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2151. if (!chip) {
  2152. snd_printk(KERN_ERR SFX "cannot allocate chip\n");
  2153. pci_disable_device(pci);
  2154. return -ENOMEM;
  2155. }
  2156. spin_lock_init(&chip->reg_lock);
  2157. mutex_init(&chip->open_mutex);
  2158. chip->card = card;
  2159. chip->pci = pci;
  2160. chip->irq = -1;
  2161. chip->driver_type = driver_type;
  2162. check_msi(chip);
  2163. chip->dev_index = dev;
  2164. INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
  2165. chip->position_fix[0] = chip->position_fix[1] =
  2166. check_position_fix(chip, position_fix[dev]);
  2167. check_probe_mask(chip, dev);
  2168. chip->single_cmd = single_cmd;
  2169. if (bdl_pos_adj[dev] < 0) {
  2170. switch (chip->driver_type) {
  2171. case AZX_DRIVER_ICH:
  2172. case AZX_DRIVER_PCH:
  2173. bdl_pos_adj[dev] = 1;
  2174. break;
  2175. default:
  2176. bdl_pos_adj[dev] = 32;
  2177. break;
  2178. }
  2179. }
  2180. #if BITS_PER_LONG != 64
  2181. /* Fix up base address on ULI M5461 */
  2182. if (chip->driver_type == AZX_DRIVER_ULI) {
  2183. u16 tmp3;
  2184. pci_read_config_word(pci, 0x40, &tmp3);
  2185. pci_write_config_word(pci, 0x40, tmp3 | 0x10);
  2186. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
  2187. }
  2188. #endif
  2189. err = pci_request_regions(pci, "ICH HD audio");
  2190. if (err < 0) {
  2191. kfree(chip);
  2192. pci_disable_device(pci);
  2193. return err;
  2194. }
  2195. chip->addr = pci_resource_start(pci, 0);
  2196. chip->remap_addr = pci_ioremap_bar(pci, 0);
  2197. if (chip->remap_addr == NULL) {
  2198. snd_printk(KERN_ERR SFX "ioremap error\n");
  2199. err = -ENXIO;
  2200. goto errout;
  2201. }
  2202. if (chip->msi)
  2203. if (pci_enable_msi(pci) < 0)
  2204. chip->msi = 0;
  2205. if (azx_acquire_irq(chip, 0) < 0) {
  2206. err = -EBUSY;
  2207. goto errout;
  2208. }
  2209. pci_set_master(pci);
  2210. synchronize_irq(chip->irq);
  2211. gcap = azx_readw(chip, GCAP);
  2212. snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
  2213. /* disable SB600 64bit support for safety */
  2214. if ((chip->driver_type == AZX_DRIVER_ATI) ||
  2215. (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
  2216. struct pci_dev *p_smbus;
  2217. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  2218. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  2219. NULL);
  2220. if (p_smbus) {
  2221. if (p_smbus->revision < 0x30)
  2222. gcap &= ~ICH6_GCAP_64OK;
  2223. pci_dev_put(p_smbus);
  2224. }
  2225. }
  2226. /* disable 64bit DMA address for Teradici */
  2227. /* it does not work with device 6549:1200 subsys e4a2:040b */
  2228. if (chip->driver_type == AZX_DRIVER_TERA)
  2229. gcap &= ~ICH6_GCAP_64OK;
  2230. /* allow 64bit DMA address if supported by H/W */
  2231. if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
  2232. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
  2233. else {
  2234. pci_set_dma_mask(pci, DMA_BIT_MASK(32));
  2235. pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
  2236. }
  2237. /* read number of streams from GCAP register instead of using
  2238. * hardcoded value
  2239. */
  2240. chip->capture_streams = (gcap >> 8) & 0x0f;
  2241. chip->playback_streams = (gcap >> 12) & 0x0f;
  2242. if (!chip->playback_streams && !chip->capture_streams) {
  2243. /* gcap didn't give any info, switching to old method */
  2244. switch (chip->driver_type) {
  2245. case AZX_DRIVER_ULI:
  2246. chip->playback_streams = ULI_NUM_PLAYBACK;
  2247. chip->capture_streams = ULI_NUM_CAPTURE;
  2248. break;
  2249. case AZX_DRIVER_ATIHDMI:
  2250. chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
  2251. chip->capture_streams = ATIHDMI_NUM_CAPTURE;
  2252. break;
  2253. case AZX_DRIVER_GENERIC:
  2254. default:
  2255. chip->playback_streams = ICH6_NUM_PLAYBACK;
  2256. chip->capture_streams = ICH6_NUM_CAPTURE;
  2257. break;
  2258. }
  2259. }
  2260. chip->capture_index_offset = 0;
  2261. chip->playback_index_offset = chip->capture_streams;
  2262. chip->num_streams = chip->playback_streams + chip->capture_streams;
  2263. chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
  2264. GFP_KERNEL);
  2265. if (!chip->azx_dev) {
  2266. snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");
  2267. goto errout;
  2268. }
  2269. for (i = 0; i < chip->num_streams; i++) {
  2270. /* allocate memory for the BDL for each stream */
  2271. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2272. snd_dma_pci_data(chip->pci),
  2273. BDL_SIZE, &chip->azx_dev[i].bdl);
  2274. if (err < 0) {
  2275. snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
  2276. goto errout;
  2277. }
  2278. }
  2279. /* allocate memory for the position buffer */
  2280. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  2281. snd_dma_pci_data(chip->pci),
  2282. chip->num_streams * 8, &chip->posbuf);
  2283. if (err < 0) {
  2284. snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
  2285. goto errout;
  2286. }
  2287. /* allocate CORB/RIRB */
  2288. err = azx_alloc_cmd_io(chip);
  2289. if (err < 0)
  2290. goto errout;
  2291. /* initialize streams */
  2292. azx_init_stream(chip);
  2293. /* initialize chip */
  2294. azx_init_pci(chip);
  2295. azx_init_chip(chip, (probe_only[dev] & 2) == 0);
  2296. /* codec detection */
  2297. if (!chip->codec_mask) {
  2298. snd_printk(KERN_ERR SFX "no codecs found!\n");
  2299. err = -ENODEV;
  2300. goto errout;
  2301. }
  2302. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  2303. if (err <0) {
  2304. snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
  2305. goto errout;
  2306. }
  2307. strcpy(card->driver, "HDA-Intel");
  2308. strlcpy(card->shortname, driver_short_names[chip->driver_type],
  2309. sizeof(card->shortname));
  2310. snprintf(card->longname, sizeof(card->longname),
  2311. "%s at 0x%lx irq %i",
  2312. card->shortname, chip->addr, chip->irq);
  2313. *rchip = chip;
  2314. return 0;
  2315. errout:
  2316. azx_free(chip);
  2317. return err;
  2318. }
  2319. static void power_down_all_codecs(struct azx *chip)
  2320. {
  2321. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2322. /* The codecs were powered up in snd_hda_codec_new().
  2323. * Now all initialization done, so turn them down if possible
  2324. */
  2325. struct hda_codec *codec;
  2326. list_for_each_entry(codec, &chip->bus->codec_list, list) {
  2327. snd_hda_power_down(codec);
  2328. }
  2329. #endif
  2330. }
  2331. static int __devinit azx_probe(struct pci_dev *pci,
  2332. const struct pci_device_id *pci_id)
  2333. {
  2334. static int dev;
  2335. struct snd_card *card;
  2336. struct azx *chip;
  2337. int err;
  2338. if (dev >= SNDRV_CARDS)
  2339. return -ENODEV;
  2340. if (!enable[dev]) {
  2341. dev++;
  2342. return -ENOENT;
  2343. }
  2344. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  2345. if (err < 0) {
  2346. snd_printk(KERN_ERR SFX "Error creating card!\n");
  2347. return err;
  2348. }
  2349. /* set this here since it's referred in snd_hda_load_patch() */
  2350. snd_card_set_dev(card, &pci->dev);
  2351. err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
  2352. if (err < 0)
  2353. goto out_free;
  2354. card->private_data = chip;
  2355. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2356. chip->beep_mode = beep_mode[dev];
  2357. #endif
  2358. /* create codec instances */
  2359. err = azx_codec_create(chip, model[dev]);
  2360. if (err < 0)
  2361. goto out_free;
  2362. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  2363. if (patch[dev]) {
  2364. snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
  2365. patch[dev]);
  2366. err = snd_hda_load_patch(chip->bus, patch[dev]);
  2367. if (err < 0)
  2368. goto out_free;
  2369. }
  2370. #endif
  2371. if ((probe_only[dev] & 1) == 0) {
  2372. err = azx_codec_configure(chip);
  2373. if (err < 0)
  2374. goto out_free;
  2375. }
  2376. /* create PCM streams */
  2377. err = snd_hda_build_pcms(chip->bus);
  2378. if (err < 0)
  2379. goto out_free;
  2380. /* create mixer controls */
  2381. err = azx_mixer_create(chip);
  2382. if (err < 0)
  2383. goto out_free;
  2384. err = snd_card_register(card);
  2385. if (err < 0)
  2386. goto out_free;
  2387. pci_set_drvdata(pci, card);
  2388. chip->running = 1;
  2389. power_down_all_codecs(chip);
  2390. azx_notifier_register(chip);
  2391. dev++;
  2392. return err;
  2393. out_free:
  2394. snd_card_free(card);
  2395. return err;
  2396. }
  2397. static void __devexit azx_remove(struct pci_dev *pci)
  2398. {
  2399. snd_card_free(pci_get_drvdata(pci));
  2400. pci_set_drvdata(pci, NULL);
  2401. }
  2402. /* PCI IDs */
  2403. static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
  2404. /* CPT */
  2405. { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
  2406. /* PBG */
  2407. { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH },
  2408. /* SCH */
  2409. { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
  2410. /* Generic Intel */
  2411. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
  2412. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2413. .class_mask = 0xffffff,
  2414. .driver_data = AZX_DRIVER_ICH },
  2415. /* ATI SB 450/600 */
  2416. { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
  2417. { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
  2418. /* ATI HDMI */
  2419. { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
  2420. { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
  2421. { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
  2422. { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI },
  2423. { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
  2424. { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
  2425. { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
  2426. { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
  2427. { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
  2428. { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
  2429. { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
  2430. { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
  2431. { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
  2432. { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
  2433. /* VIA VT8251/VT8237A */
  2434. { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
  2435. /* SIS966 */
  2436. { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
  2437. /* ULI M5461 */
  2438. { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
  2439. /* NVIDIA MCP */
  2440. { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  2441. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2442. .class_mask = 0xffffff,
  2443. .driver_data = AZX_DRIVER_NVIDIA },
  2444. /* Teradici */
  2445. { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
  2446. /* Creative X-Fi (CA0110-IBG) */
  2447. #if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE)
  2448. /* the following entry conflicts with snd-ctxfi driver,
  2449. * as ctxfi driver mutates from HD-audio to native mode with
  2450. * a special command sequence.
  2451. */
  2452. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
  2453. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2454. .class_mask = 0xffffff,
  2455. .driver_data = AZX_DRIVER_CTX },
  2456. #else
  2457. /* this entry seems still valid -- i.e. without emu20kx chip */
  2458. { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX },
  2459. #endif
  2460. /* Vortex86MX */
  2461. { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
  2462. /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
  2463. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
  2464. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2465. .class_mask = 0xffffff,
  2466. .driver_data = AZX_DRIVER_GENERIC },
  2467. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
  2468. .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
  2469. .class_mask = 0xffffff,
  2470. .driver_data = AZX_DRIVER_GENERIC },
  2471. { 0, }
  2472. };
  2473. MODULE_DEVICE_TABLE(pci, azx_ids);
  2474. /* pci_driver definition */
  2475. static struct pci_driver driver = {
  2476. .name = "HDA Intel",
  2477. .id_table = azx_ids,
  2478. .probe = azx_probe,
  2479. .remove = __devexit_p(azx_remove),
  2480. #ifdef CONFIG_PM
  2481. .suspend = azx_suspend,
  2482. .resume = azx_resume,
  2483. #endif
  2484. };
  2485. static int __init alsa_card_azx_init(void)
  2486. {
  2487. return pci_register_driver(&driver);
  2488. }
  2489. static void __exit alsa_card_azx_exit(void)
  2490. {
  2491. pci_unregister_driver(&driver);
  2492. }
  2493. module_init(alsa_card_azx_init)
  2494. module_exit(alsa_card_azx_exit)