hda_intel.c 59 KB

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