hda_intel.c 87 KB

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