hda_priv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Common defines for the alsa driver code base for HD Audio.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef __SOUND_HDA_PRIV_H
  15. #define __SOUND_HDA_PRIV_H
  16. #include <linux/clocksource.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. /*
  20. * registers
  21. */
  22. #define ICH6_REG_GCAP 0x00
  23. #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
  24. #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  25. #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  26. #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
  27. #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
  28. #define ICH6_REG_VMIN 0x02
  29. #define ICH6_REG_VMAJ 0x03
  30. #define ICH6_REG_OUTPAY 0x04
  31. #define ICH6_REG_INPAY 0x06
  32. #define ICH6_REG_GCTL 0x08
  33. #define ICH6_GCTL_RESET (1 << 0) /* controller reset */
  34. #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
  35. #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  36. #define ICH6_REG_WAKEEN 0x0c
  37. #define ICH6_REG_STATESTS 0x0e
  38. #define ICH6_REG_GSTS 0x10
  39. #define ICH6_GSTS_FSTS (1 << 1) /* flush status */
  40. #define ICH6_REG_INTCTL 0x20
  41. #define ICH6_REG_INTSTS 0x24
  42. #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
  43. #define ICH6_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
  44. #define ICH6_REG_SSYNC 0x38
  45. #define ICH6_REG_CORBLBASE 0x40
  46. #define ICH6_REG_CORBUBASE 0x44
  47. #define ICH6_REG_CORBWP 0x48
  48. #define ICH6_REG_CORBRP 0x4a
  49. #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
  50. #define ICH6_REG_CORBCTL 0x4c
  51. #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
  52. #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  53. #define ICH6_REG_CORBSTS 0x4d
  54. #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
  55. #define ICH6_REG_CORBSIZE 0x4e
  56. #define ICH6_REG_RIRBLBASE 0x50
  57. #define ICH6_REG_RIRBUBASE 0x54
  58. #define ICH6_REG_RIRBWP 0x58
  59. #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
  60. #define ICH6_REG_RINTCNT 0x5a
  61. #define ICH6_REG_RIRBCTL 0x5c
  62. #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  63. #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  64. #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  65. #define ICH6_REG_RIRBSTS 0x5d
  66. #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
  67. #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  68. #define ICH6_REG_RIRBSIZE 0x5e
  69. #define ICH6_REG_IC 0x60
  70. #define ICH6_REG_IR 0x64
  71. #define ICH6_REG_IRS 0x68
  72. #define ICH6_IRS_VALID (1<<1)
  73. #define ICH6_IRS_BUSY (1<<0)
  74. #define ICH6_REG_DPLBASE 0x70
  75. #define ICH6_REG_DPUBASE 0x74
  76. #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
  77. /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  78. enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
  79. /* stream register offsets from stream base */
  80. #define ICH6_REG_SD_CTL 0x00
  81. #define ICH6_REG_SD_STS 0x03
  82. #define ICH6_REG_SD_LPIB 0x04
  83. #define ICH6_REG_SD_CBL 0x08
  84. #define ICH6_REG_SD_LVI 0x0c
  85. #define ICH6_REG_SD_FIFOW 0x0e
  86. #define ICH6_REG_SD_FIFOSIZE 0x10
  87. #define ICH6_REG_SD_FORMAT 0x12
  88. #define ICH6_REG_SD_BDLPL 0x18
  89. #define ICH6_REG_SD_BDLPU 0x1c
  90. /* PCI space */
  91. #define ICH6_PCIREG_TCSEL 0x44
  92. /*
  93. * other constants
  94. */
  95. /* max number of SDs */
  96. /* ICH, ATI and VIA have 4 playback and 4 capture */
  97. #define ICH6_NUM_CAPTURE 4
  98. #define ICH6_NUM_PLAYBACK 4
  99. /* ULI has 6 playback and 5 capture */
  100. #define ULI_NUM_CAPTURE 5
  101. #define ULI_NUM_PLAYBACK 6
  102. /* ATI HDMI may have up to 8 playbacks and 0 capture */
  103. #define ATIHDMI_NUM_CAPTURE 0
  104. #define ATIHDMI_NUM_PLAYBACK 8
  105. /* TERA has 4 playback and 3 capture */
  106. #define TERA_NUM_CAPTURE 3
  107. #define TERA_NUM_PLAYBACK 4
  108. /* this number is statically defined for simplicity */
  109. #define MAX_AZX_DEV 16
  110. /* max number of fragments - we may use more if allocating more pages for BDL */
  111. #define BDL_SIZE 4096
  112. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  113. #define AZX_MAX_FRAG 32
  114. /* max buffer size - no h/w limit, you can increase as you like */
  115. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  116. /* RIRB int mask: overrun[2], response[0] */
  117. #define RIRB_INT_RESPONSE 0x01
  118. #define RIRB_INT_OVERRUN 0x04
  119. #define RIRB_INT_MASK 0x05
  120. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  121. #define AZX_MAX_CODECS 8
  122. #define AZX_DEFAULT_CODECS 4
  123. #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
  124. /* SD_CTL bits */
  125. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  126. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  127. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  128. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  129. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  130. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  131. #define SD_CTL_STREAM_TAG_SHIFT 20
  132. /* SD_CTL and SD_STS */
  133. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  134. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  135. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  136. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  137. SD_INT_COMPLETE)
  138. /* SD_STS */
  139. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  140. /* INTCTL and INTSTS */
  141. #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
  142. #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  143. #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  144. /* below are so far hardcoded - should read registers in future */
  145. #define ICH6_MAX_CORB_ENTRIES 256
  146. #define ICH6_MAX_RIRB_ENTRIES 256
  147. /* driver quirks (capabilities) */
  148. /* bits 0-7 are used for indicating driver type */
  149. #define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
  150. #define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
  151. #define AZX_DCAPS_ATI_SNOOP (1 << 10) /* ATI snoop enable */
  152. #define AZX_DCAPS_NVIDIA_SNOOP (1 << 11) /* Nvidia snoop enable */
  153. #define AZX_DCAPS_SCH_SNOOP (1 << 12) /* SCH/PCH snoop enable */
  154. #define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
  155. #define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
  156. #define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
  157. #define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
  158. #define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
  159. #define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
  160. #define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
  161. #define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
  162. #define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
  163. #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */
  164. #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
  165. #define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
  166. #define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
  167. #define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
  168. #define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
  169. /* position fix mode */
  170. enum {
  171. POS_FIX_AUTO,
  172. POS_FIX_LPIB,
  173. POS_FIX_POSBUF,
  174. POS_FIX_VIACOMBO,
  175. POS_FIX_COMBO,
  176. };
  177. /* Defines for ATI HD Audio support in SB450 south bridge */
  178. #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
  179. #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
  180. /* Defines for Nvidia HDA support */
  181. #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
  182. #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
  183. #define NVIDIA_HDA_ISTRM_COH 0x4d
  184. #define NVIDIA_HDA_OSTRM_COH 0x4c
  185. #define NVIDIA_HDA_ENABLE_COHBIT 0x01
  186. /* Defines for Intel SCH HDA snoop control */
  187. #define INTEL_SCH_HDA_DEVC 0x78
  188. #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
  189. /* Define IN stream 0 FIFO size offset in VIA controller */
  190. #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
  191. /* Define VIA HD Audio Device ID*/
  192. #define VIA_HDAC_DEVICE_ID 0x3288
  193. /* HD Audio class code */
  194. #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
  195. struct azx_dev {
  196. struct snd_dma_buffer bdl; /* BDL buffer */
  197. u32 *posbuf; /* position buffer pointer */
  198. unsigned int bufsize; /* size of the play buffer in bytes */
  199. unsigned int period_bytes; /* size of the period in bytes */
  200. unsigned int frags; /* number for period in the play buffer */
  201. unsigned int fifo_size; /* FIFO size */
  202. unsigned long start_wallclk; /* start + minimum wallclk */
  203. unsigned long period_wallclk; /* wallclk for period */
  204. void __iomem *sd_addr; /* stream descriptor pointer */
  205. u32 sd_int_sta_mask; /* stream int status mask */
  206. /* pcm support */
  207. struct snd_pcm_substream *substream; /* assigned substream,
  208. * set in PCM open
  209. */
  210. unsigned int format_val; /* format value to be set in the
  211. * controller and the codec
  212. */
  213. unsigned char stream_tag; /* assigned stream */
  214. unsigned char index; /* stream index */
  215. int assigned_key; /* last device# key assigned to */
  216. unsigned int opened:1;
  217. unsigned int running:1;
  218. unsigned int irq_pending:1;
  219. unsigned int prepared:1;
  220. unsigned int locked:1;
  221. /*
  222. * For VIA:
  223. * A flag to ensure DMA position is 0
  224. * when link position is not greater than FIFO size
  225. */
  226. unsigned int insufficient:1;
  227. unsigned int wc_marked:1;
  228. unsigned int no_period_wakeup:1;
  229. struct timecounter azx_tc;
  230. struct cyclecounter azx_cc;
  231. int delay_negative_threshold;
  232. #ifdef CONFIG_SND_HDA_DSP_LOADER
  233. /* Allows dsp load to have sole access to the playback stream. */
  234. struct mutex dsp_mutex;
  235. #endif
  236. };
  237. /* CORB/RIRB */
  238. struct azx_rb {
  239. u32 *buf; /* CORB/RIRB buffer
  240. * Each CORB entry is 4byte, RIRB is 8byte
  241. */
  242. dma_addr_t addr; /* physical address of CORB/RIRB buffer */
  243. /* for RIRB */
  244. unsigned short rp, wp; /* read/write pointers */
  245. int cmds[AZX_MAX_CODECS]; /* number of pending requests */
  246. u32 res[AZX_MAX_CODECS]; /* last read value */
  247. };
  248. struct azx;
  249. /* Functions to read/write to hda registers. */
  250. struct hda_controller_ops {
  251. /* Register Access */
  252. void (*reg_writel)(u32 value, u32 __iomem *addr);
  253. u32 (*reg_readl)(u32 __iomem *addr);
  254. void (*reg_writew)(u16 value, u16 __iomem *addr);
  255. u16 (*reg_readw)(u16 __iomem *addr);
  256. void (*reg_writeb)(u8 value, u8 __iomem *addr);
  257. u8 (*reg_readb)(u8 __iomem *addr);
  258. /* Disable msi if supported, PCI only */
  259. int (*disable_msi_reset_irq)(struct azx *);
  260. /* Allocation ops */
  261. int (*dma_alloc_pages)(struct azx *chip,
  262. int type,
  263. size_t size,
  264. struct snd_dma_buffer *buf);
  265. void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
  266. int (*substream_alloc_pages)(struct azx *chip,
  267. struct snd_pcm_substream *substream,
  268. size_t size);
  269. int (*substream_free_pages)(struct azx *chip,
  270. struct snd_pcm_substream *substream);
  271. void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
  272. struct vm_area_struct *area);
  273. /* Check if current position is acceptable */
  274. int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
  275. };
  276. struct azx_pcm {
  277. struct azx *chip;
  278. struct snd_pcm *pcm;
  279. struct hda_codec *codec;
  280. struct hda_pcm_stream *hinfo[2];
  281. struct list_head list;
  282. };
  283. struct azx {
  284. struct snd_card *card;
  285. struct pci_dev *pci;
  286. int dev_index;
  287. /* chip type specific */
  288. int driver_type;
  289. unsigned int driver_caps;
  290. int playback_streams;
  291. int playback_index_offset;
  292. int capture_streams;
  293. int capture_index_offset;
  294. int num_streams;
  295. const int *jackpoll_ms; /* per-card jack poll interval */
  296. /* Register interaction. */
  297. const struct hda_controller_ops *ops;
  298. /* pci resources */
  299. unsigned long addr;
  300. void __iomem *remap_addr;
  301. int irq;
  302. /* locks */
  303. spinlock_t reg_lock;
  304. struct mutex open_mutex; /* Prevents concurrent open/close operations */
  305. struct completion probe_wait;
  306. /* streams (x num_streams) */
  307. struct azx_dev *azx_dev;
  308. /* PCM */
  309. struct list_head pcm_list; /* azx_pcm list */
  310. /* HD codec */
  311. unsigned short codec_mask;
  312. int codec_probe_mask; /* copied from probe_mask option */
  313. struct hda_bus *bus;
  314. unsigned int beep_mode;
  315. /* CORB/RIRB */
  316. struct azx_rb corb;
  317. struct azx_rb rirb;
  318. /* CORB/RIRB and position buffers */
  319. struct snd_dma_buffer rb;
  320. struct snd_dma_buffer posbuf;
  321. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  322. const struct firmware *fw;
  323. #endif
  324. /* flags */
  325. int position_fix[2]; /* for both playback/capture streams */
  326. const int *bdl_pos_adj;
  327. int poll_count;
  328. unsigned int running:1;
  329. unsigned int initialized:1;
  330. unsigned int single_cmd:1;
  331. unsigned int polling_mode:1;
  332. unsigned int msi:1;
  333. unsigned int irq_pending_warned:1;
  334. unsigned int probing:1; /* codec probing phase */
  335. unsigned int snoop:1;
  336. unsigned int align_buffer_size:1;
  337. unsigned int region_requested:1;
  338. /* VGA-switcheroo setup */
  339. unsigned int use_vga_switcheroo:1;
  340. unsigned int vga_switcheroo_registered:1;
  341. unsigned int init_failed:1; /* delayed init failed */
  342. unsigned int disabled:1; /* disabled by VGA-switcher */
  343. /* for debugging */
  344. unsigned int last_cmd[AZX_MAX_CODECS];
  345. /* for pending irqs */
  346. struct work_struct irq_pending_work;
  347. struct work_struct probe_work;
  348. /* reboot notifier (for mysterious hangup problem at power-down) */
  349. struct notifier_block reboot_notifier;
  350. /* card list (for power_save trigger) */
  351. struct list_head list;
  352. #ifdef CONFIG_SND_HDA_DSP_LOADER
  353. struct azx_dev saved_azx_dev;
  354. #endif
  355. /* secondary power domain for hdmi audio under vga device */
  356. struct dev_pm_domain hdmi_pm_domain;
  357. };
  358. #ifdef CONFIG_SND_VERBOSE_PRINTK
  359. #define SFX /* nop */
  360. #else
  361. #define SFX "hda-intel "
  362. #endif
  363. #ifdef CONFIG_X86
  364. #define azx_snoop(chip) ((chip)->snoop)
  365. #else
  366. #define azx_snoop(chip) true
  367. #endif
  368. /*
  369. * macros for easy use
  370. */
  371. #define azx_writel(chip, reg, value) \
  372. ((chip)->ops->reg_writel(value, (chip)->remap_addr + ICH6_REG_##reg))
  373. #define azx_readl(chip, reg) \
  374. ((chip)->ops->reg_readl((chip)->remap_addr + ICH6_REG_##reg))
  375. #define azx_writew(chip, reg, value) \
  376. ((chip)->ops->reg_writew(value, (chip)->remap_addr + ICH6_REG_##reg))
  377. #define azx_readw(chip, reg) \
  378. ((chip)->ops->reg_readw((chip)->remap_addr + ICH6_REG_##reg))
  379. #define azx_writeb(chip, reg, value) \
  380. ((chip)->ops->reg_writeb(value, (chip)->remap_addr + ICH6_REG_##reg))
  381. #define azx_readb(chip, reg) \
  382. ((chip)->ops->reg_readb((chip)->remap_addr + ICH6_REG_##reg))
  383. #define azx_sd_writel(chip, dev, reg, value) \
  384. ((chip)->ops->reg_writel(value, (dev)->sd_addr + ICH6_REG_##reg))
  385. #define azx_sd_readl(chip, dev, reg) \
  386. ((chip)->ops->reg_readl((dev)->sd_addr + ICH6_REG_##reg))
  387. #define azx_sd_writew(chip, dev, reg, value) \
  388. ((chip)->ops->reg_writew(value, (dev)->sd_addr + ICH6_REG_##reg))
  389. #define azx_sd_readw(chip, dev, reg) \
  390. ((chip)->ops->reg_readw((dev)->sd_addr + ICH6_REG_##reg))
  391. #define azx_sd_writeb(chip, dev, reg, value) \
  392. ((chip)->ops->reg_writeb(value, (dev)->sd_addr + ICH6_REG_##reg))
  393. #define azx_sd_readb(chip, dev, reg) \
  394. ((chip)->ops->reg_readb((dev)->sd_addr + ICH6_REG_##reg))
  395. #endif /* __SOUND_HDA_PRIV_H */