hda_priv.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 AZX_REG_GCAP 0x00
  23. #define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
  24. #define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
  25. #define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
  26. #define AZX_GCAP_ISS (15 << 8) /* # of input streams */
  27. #define AZX_GCAP_OSS (15 << 12) /* # of output streams */
  28. #define AZX_REG_VMIN 0x02
  29. #define AZX_REG_VMAJ 0x03
  30. #define AZX_REG_OUTPAY 0x04
  31. #define AZX_REG_INPAY 0x06
  32. #define AZX_REG_GCTL 0x08
  33. #define AZX_GCTL_RESET (1 << 0) /* controller reset */
  34. #define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
  35. #define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
  36. #define AZX_REG_WAKEEN 0x0c
  37. #define AZX_REG_STATESTS 0x0e
  38. #define AZX_REG_GSTS 0x10
  39. #define AZX_GSTS_FSTS (1 << 1) /* flush status */
  40. #define AZX_REG_INTCTL 0x20
  41. #define AZX_REG_INTSTS 0x24
  42. #define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
  43. #define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
  44. #define AZX_REG_SSYNC 0x38
  45. #define AZX_REG_CORBLBASE 0x40
  46. #define AZX_REG_CORBUBASE 0x44
  47. #define AZX_REG_CORBWP 0x48
  48. #define AZX_REG_CORBRP 0x4a
  49. #define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
  50. #define AZX_REG_CORBCTL 0x4c
  51. #define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
  52. #define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
  53. #define AZX_REG_CORBSTS 0x4d
  54. #define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
  55. #define AZX_REG_CORBSIZE 0x4e
  56. #define AZX_REG_RIRBLBASE 0x50
  57. #define AZX_REG_RIRBUBASE 0x54
  58. #define AZX_REG_RIRBWP 0x58
  59. #define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
  60. #define AZX_REG_RINTCNT 0x5a
  61. #define AZX_REG_RIRBCTL 0x5c
  62. #define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
  63. #define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
  64. #define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
  65. #define AZX_REG_RIRBSTS 0x5d
  66. #define AZX_RBSTS_IRQ (1 << 0) /* response irq */
  67. #define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
  68. #define AZX_REG_RIRBSIZE 0x5e
  69. #define AZX_REG_IC 0x60
  70. #define AZX_REG_IR 0x64
  71. #define AZX_REG_IRS 0x68
  72. #define AZX_IRS_VALID (1<<1)
  73. #define AZX_IRS_BUSY (1<<0)
  74. #define AZX_REG_DPLBASE 0x70
  75. #define AZX_REG_DPUBASE 0x74
  76. #define AZX_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 AZX_REG_SD_CTL 0x00
  81. #define AZX_REG_SD_STS 0x03
  82. #define AZX_REG_SD_LPIB 0x04
  83. #define AZX_REG_SD_CBL 0x08
  84. #define AZX_REG_SD_LVI 0x0c
  85. #define AZX_REG_SD_FIFOW 0x0e
  86. #define AZX_REG_SD_FIFOSIZE 0x10
  87. #define AZX_REG_SD_FORMAT 0x12
  88. #define AZX_REG_SD_BDLPL 0x18
  89. #define AZX_REG_SD_BDLPU 0x1c
  90. /* PCI space */
  91. #define AZX_PCIREG_TCSEL 0x44
  92. /*
  93. * other constants
  94. */
  95. /* max number of fragments - we may use more if allocating more pages for BDL */
  96. #define BDL_SIZE 4096
  97. #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  98. #define AZX_MAX_FRAG 32
  99. /* max buffer size - no h/w limit, you can increase as you like */
  100. #define AZX_MAX_BUF_SIZE (1024*1024*1024)
  101. /* RIRB int mask: overrun[2], response[0] */
  102. #define RIRB_INT_RESPONSE 0x01
  103. #define RIRB_INT_OVERRUN 0x04
  104. #define RIRB_INT_MASK 0x05
  105. /* STATESTS int mask: S3,SD2,SD1,SD0 */
  106. #define AZX_MAX_CODECS 8
  107. #define AZX_DEFAULT_CODECS 4
  108. #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
  109. /* SD_CTL bits */
  110. #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
  111. #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
  112. #define SD_CTL_STRIPE (3 << 16) /* stripe control */
  113. #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
  114. #define SD_CTL_DIR (1 << 19) /* bi-directional stream */
  115. #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
  116. #define SD_CTL_STREAM_TAG_SHIFT 20
  117. /* SD_CTL and SD_STS */
  118. #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
  119. #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  120. #define SD_INT_COMPLETE 0x04 /* completion interrupt */
  121. #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
  122. SD_INT_COMPLETE)
  123. /* SD_STS */
  124. #define SD_STS_FIFO_READY 0x20 /* FIFO ready */
  125. /* INTCTL and INTSTS */
  126. #define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
  127. #define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
  128. #define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
  129. /* below are so far hardcoded - should read registers in future */
  130. #define AZX_MAX_CORB_ENTRIES 256
  131. #define AZX_MAX_RIRB_ENTRIES 256
  132. /* driver quirks (capabilities) */
  133. /* bits 0-7 are used for indicating driver type */
  134. #define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
  135. #define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
  136. #define AZX_DCAPS_ATI_SNOOP (1 << 10) /* ATI snoop enable */
  137. #define AZX_DCAPS_NVIDIA_SNOOP (1 << 11) /* Nvidia snoop enable */
  138. #define AZX_DCAPS_SCH_SNOOP (1 << 12) /* SCH/PCH snoop enable */
  139. #define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
  140. #define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
  141. #define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
  142. #define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
  143. #define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
  144. #define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
  145. #define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
  146. #define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
  147. #define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
  148. #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */
  149. #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
  150. #define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
  151. #define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
  152. #define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
  153. #define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
  154. #define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
  155. /* HD Audio class code */
  156. #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
  157. struct azx_dev {
  158. struct snd_dma_buffer bdl; /* BDL buffer */
  159. u32 *posbuf; /* position buffer pointer */
  160. unsigned int bufsize; /* size of the play buffer in bytes */
  161. unsigned int period_bytes; /* size of the period in bytes */
  162. unsigned int frags; /* number for period in the play buffer */
  163. unsigned int fifo_size; /* FIFO size */
  164. unsigned long start_wallclk; /* start + minimum wallclk */
  165. unsigned long period_wallclk; /* wallclk for period */
  166. void __iomem *sd_addr; /* stream descriptor pointer */
  167. u32 sd_int_sta_mask; /* stream int status mask */
  168. /* pcm support */
  169. struct snd_pcm_substream *substream; /* assigned substream,
  170. * set in PCM open
  171. */
  172. unsigned int format_val; /* format value to be set in the
  173. * controller and the codec
  174. */
  175. unsigned char stream_tag; /* assigned stream */
  176. unsigned char index; /* stream index */
  177. int assigned_key; /* last device# key assigned to */
  178. unsigned int opened:1;
  179. unsigned int running:1;
  180. unsigned int irq_pending:1;
  181. unsigned int prepared:1;
  182. unsigned int locked:1;
  183. /*
  184. * For VIA:
  185. * A flag to ensure DMA position is 0
  186. * when link position is not greater than FIFO size
  187. */
  188. unsigned int insufficient:1;
  189. unsigned int wc_marked:1;
  190. unsigned int no_period_wakeup:1;
  191. struct timecounter azx_tc;
  192. struct cyclecounter azx_cc;
  193. int delay_negative_threshold;
  194. #ifdef CONFIG_SND_HDA_DSP_LOADER
  195. /* Allows dsp load to have sole access to the playback stream. */
  196. struct mutex dsp_mutex;
  197. #endif
  198. };
  199. /* CORB/RIRB */
  200. struct azx_rb {
  201. u32 *buf; /* CORB/RIRB buffer
  202. * Each CORB entry is 4byte, RIRB is 8byte
  203. */
  204. dma_addr_t addr; /* physical address of CORB/RIRB buffer */
  205. /* for RIRB */
  206. unsigned short rp, wp; /* read/write pointers */
  207. int cmds[AZX_MAX_CODECS]; /* number of pending requests */
  208. u32 res[AZX_MAX_CODECS]; /* last read value */
  209. };
  210. struct azx;
  211. /* Functions to read/write to hda registers. */
  212. struct hda_controller_ops {
  213. /* Register Access */
  214. void (*reg_writel)(u32 value, u32 __iomem *addr);
  215. u32 (*reg_readl)(u32 __iomem *addr);
  216. void (*reg_writew)(u16 value, u16 __iomem *addr);
  217. u16 (*reg_readw)(u16 __iomem *addr);
  218. void (*reg_writeb)(u8 value, u8 __iomem *addr);
  219. u8 (*reg_readb)(u8 __iomem *addr);
  220. /* Disable msi if supported, PCI only */
  221. int (*disable_msi_reset_irq)(struct azx *);
  222. /* Allocation ops */
  223. int (*dma_alloc_pages)(struct azx *chip,
  224. int type,
  225. size_t size,
  226. struct snd_dma_buffer *buf);
  227. void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
  228. int (*substream_alloc_pages)(struct azx *chip,
  229. struct snd_pcm_substream *substream,
  230. size_t size);
  231. int (*substream_free_pages)(struct azx *chip,
  232. struct snd_pcm_substream *substream);
  233. void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
  234. struct vm_area_struct *area);
  235. /* Check if current position is acceptable */
  236. int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
  237. };
  238. struct azx_pcm {
  239. struct azx *chip;
  240. struct snd_pcm *pcm;
  241. struct hda_codec *codec;
  242. struct hda_pcm_stream *hinfo[2];
  243. struct list_head list;
  244. };
  245. typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
  246. typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
  247. struct azx {
  248. struct snd_card *card;
  249. struct pci_dev *pci;
  250. int dev_index;
  251. /* chip type specific */
  252. int driver_type;
  253. unsigned int driver_caps;
  254. int playback_streams;
  255. int playback_index_offset;
  256. int capture_streams;
  257. int capture_index_offset;
  258. int num_streams;
  259. const int *jackpoll_ms; /* per-card jack poll interval */
  260. /* Register interaction. */
  261. const struct hda_controller_ops *ops;
  262. /* position adjustment callbacks */
  263. azx_get_pos_callback_t get_position[2];
  264. azx_get_delay_callback_t get_delay[2];
  265. /* pci resources */
  266. unsigned long addr;
  267. void __iomem *remap_addr;
  268. int irq;
  269. /* locks */
  270. spinlock_t reg_lock;
  271. struct mutex open_mutex; /* Prevents concurrent open/close operations */
  272. /* streams (x num_streams) */
  273. struct azx_dev *azx_dev;
  274. /* PCM */
  275. struct list_head pcm_list; /* azx_pcm list */
  276. /* HD codec */
  277. unsigned short codec_mask;
  278. int codec_probe_mask; /* copied from probe_mask option */
  279. struct hda_bus *bus;
  280. unsigned int beep_mode;
  281. /* CORB/RIRB */
  282. struct azx_rb corb;
  283. struct azx_rb rirb;
  284. /* CORB/RIRB and position buffers */
  285. struct snd_dma_buffer rb;
  286. struct snd_dma_buffer posbuf;
  287. #ifdef CONFIG_SND_HDA_PATCH_LOADER
  288. const struct firmware *fw;
  289. #endif
  290. /* flags */
  291. const int *bdl_pos_adj;
  292. int poll_count;
  293. unsigned int running:1;
  294. unsigned int initialized:1;
  295. unsigned int single_cmd:1;
  296. unsigned int polling_mode:1;
  297. unsigned int msi:1;
  298. unsigned int probing:1; /* codec probing phase */
  299. unsigned int snoop:1;
  300. unsigned int align_buffer_size:1;
  301. unsigned int region_requested:1;
  302. unsigned int disabled:1; /* disabled by VGA-switcher */
  303. /* for debugging */
  304. unsigned int last_cmd[AZX_MAX_CODECS];
  305. /* reboot notifier (for mysterious hangup problem at power-down) */
  306. struct notifier_block reboot_notifier;
  307. #ifdef CONFIG_SND_HDA_DSP_LOADER
  308. struct azx_dev saved_azx_dev;
  309. #endif
  310. };
  311. #ifdef CONFIG_X86
  312. #define azx_snoop(chip) ((chip)->snoop)
  313. #else
  314. #define azx_snoop(chip) true
  315. #endif
  316. /*
  317. * macros for easy use
  318. */
  319. #define azx_writel(chip, reg, value) \
  320. ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
  321. #define azx_readl(chip, reg) \
  322. ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
  323. #define azx_writew(chip, reg, value) \
  324. ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
  325. #define azx_readw(chip, reg) \
  326. ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
  327. #define azx_writeb(chip, reg, value) \
  328. ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
  329. #define azx_readb(chip, reg) \
  330. ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
  331. #define azx_sd_writel(chip, dev, reg, value) \
  332. ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
  333. #define azx_sd_readl(chip, dev, reg) \
  334. ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
  335. #define azx_sd_writew(chip, dev, reg, value) \
  336. ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
  337. #define azx_sd_readw(chip, dev, reg) \
  338. ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
  339. #define azx_sd_writeb(chip, dev, reg, value) \
  340. ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
  341. #define azx_sd_readb(chip, dev, reg) \
  342. ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
  343. #endif /* __SOUND_HDA_PRIV_H */