hda_intel.c 73 KB

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