hda_intel.c 59 KB

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