hdaudio_ext.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SOUND_HDAUDIO_EXT_H
  3. #define __SOUND_HDAUDIO_EXT_H
  4. #include <linux/io-64-nonatomic-lo-hi.h>
  5. #include <linux/iopoll.h>
  6. #include <sound/hdaudio.h>
  7. int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
  8. const struct hdac_bus_ops *ops,
  9. const struct hdac_ext_bus_ops *ext_ops);
  10. void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
  11. void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
  12. #define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
  13. { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
  14. .api_version = HDA_DEV_ASOC, \
  15. .driver_data = (unsigned long)(drv_data) }
  16. #define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
  17. HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
  18. void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
  19. void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
  20. void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *chip,
  21. bool enable, int index);
  22. int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
  23. struct hdac_ext_link *snd_hdac_ext_bus_link_at(struct hdac_bus *bus, int addr);
  24. struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_bus *bus,
  25. const char *codec_name);
  26. enum hdac_ext_stream_type {
  27. HDAC_EXT_STREAM_TYPE_COUPLED = 0,
  28. HDAC_EXT_STREAM_TYPE_HOST,
  29. HDAC_EXT_STREAM_TYPE_LINK
  30. };
  31. /**
  32. * hdac_ext_stream: HDAC extended stream for extended HDA caps
  33. *
  34. * @hstream: hdac_stream
  35. * @pphc_addr: processing pipe host stream pointer
  36. * @pplc_addr: processing pipe link stream pointer
  37. * @spib_addr: software position in buffers stream pointer
  38. * @fifo_addr: software position Max fifos stream pointer
  39. * @dpibr_addr: DMA position in buffer resume pointer
  40. * @dpib: DMA position in buffer
  41. * @lpib: Linear position in buffer
  42. * @decoupled: stream host and link is decoupled
  43. * @link_locked: link is locked
  44. * @link_prepared: link is prepared
  45. * @link_substream: link substream
  46. */
  47. struct hdac_ext_stream {
  48. struct hdac_stream hstream;
  49. void __iomem *pphc_addr;
  50. void __iomem *pplc_addr;
  51. void __iomem *spib_addr;
  52. void __iomem *fifo_addr;
  53. void __iomem *dpibr_addr;
  54. u32 dpib;
  55. u32 lpib;
  56. bool decoupled:1;
  57. bool link_locked:1;
  58. bool link_prepared;
  59. struct snd_pcm_substream *link_substream;
  60. };
  61. #define hdac_stream(s) (&(s)->hstream)
  62. #define stream_to_hdac_ext_stream(s) \
  63. container_of(s, struct hdac_ext_stream, hstream)
  64. int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
  65. int num_stream, int dir);
  66. void snd_hdac_ext_stream_free_all(struct hdac_bus *bus);
  67. void snd_hdac_link_free_all(struct hdac_bus *bus);
  68. struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
  69. struct snd_pcm_substream *substream,
  70. int type);
  71. void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type);
  72. void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
  73. struct hdac_ext_stream *hext_stream, bool decouple);
  74. void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
  75. struct hdac_ext_stream *azx_dev, bool decouple);
  76. int snd_hdac_ext_stream_set_spib(struct hdac_bus *bus,
  77. struct hdac_ext_stream *hext_stream, u32 value);
  78. int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_bus *bus,
  79. struct hdac_ext_stream *hext_stream);
  80. void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
  81. bool enable, int index);
  82. int snd_hdac_ext_stream_set_dpibr(struct hdac_bus *bus,
  83. struct hdac_ext_stream *hext_stream, u32 value);
  84. int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *hext_stream, u32 value);
  85. void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hext_stream);
  86. void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hext_stream);
  87. void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hext_stream);
  88. int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *hext_stream, int fmt);
  89. struct hdac_ext_link {
  90. struct hdac_bus *bus;
  91. int index;
  92. void __iomem *ml_addr; /* link output stream reg pointer */
  93. u32 lcaps; /* link capablities */
  94. u16 lsdiid; /* link sdi identifier */
  95. int ref_count;
  96. struct list_head list;
  97. };
  98. int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
  99. int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
  100. int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
  101. int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
  102. void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
  103. int stream);
  104. void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
  105. int stream);
  106. int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *link);
  107. int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *link);
  108. void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
  109. /* update register macro */
  110. #define snd_hdac_updatel(addr, reg, mask, val) \
  111. writel(((readl(addr + reg) & ~(mask)) | (val)), \
  112. addr + reg)
  113. #define snd_hdac_updatew(addr, reg, mask, val) \
  114. writew(((readw(addr + reg) & ~(mask)) | (val)), \
  115. addr + reg)
  116. #define snd_hdac_adsp_writeb(chip, reg, value) \
  117. snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
  118. #define snd_hdac_adsp_readb(chip, reg) \
  119. snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
  120. #define snd_hdac_adsp_writew(chip, reg, value) \
  121. snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
  122. #define snd_hdac_adsp_readw(chip, reg) \
  123. snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
  124. #define snd_hdac_adsp_writel(chip, reg, value) \
  125. snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
  126. #define snd_hdac_adsp_readl(chip, reg) \
  127. snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
  128. #define snd_hdac_adsp_writeq(chip, reg, value) \
  129. snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
  130. #define snd_hdac_adsp_readq(chip, reg) \
  131. snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
  132. #define snd_hdac_adsp_updateb(chip, reg, mask, val) \
  133. snd_hdac_adsp_writeb(chip, reg, \
  134. (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val))
  135. #define snd_hdac_adsp_updatew(chip, reg, mask, val) \
  136. snd_hdac_adsp_writew(chip, reg, \
  137. (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val))
  138. #define snd_hdac_adsp_updatel(chip, reg, mask, val) \
  139. snd_hdac_adsp_writel(chip, reg, \
  140. (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val))
  141. #define snd_hdac_adsp_updateq(chip, reg, mask, val) \
  142. snd_hdac_adsp_writeq(chip, reg, \
  143. (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val))
  144. #define snd_hdac_adsp_readb_poll(chip, reg, val, cond, delay_us, timeout_us) \
  145. readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
  146. delay_us, timeout_us)
  147. #define snd_hdac_adsp_readw_poll(chip, reg, val, cond, delay_us, timeout_us) \
  148. readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
  149. delay_us, timeout_us)
  150. #define snd_hdac_adsp_readl_poll(chip, reg, val, cond, delay_us, timeout_us) \
  151. readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
  152. delay_us, timeout_us)
  153. #define snd_hdac_adsp_readq_poll(chip, reg, val, cond, delay_us, timeout_us) \
  154. readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
  155. delay_us, timeout_us)
  156. struct hdac_ext_device;
  157. /* ops common to all codec drivers */
  158. struct hdac_ext_codec_ops {
  159. int (*build_controls)(struct hdac_ext_device *dev);
  160. int (*init)(struct hdac_ext_device *dev);
  161. void (*free)(struct hdac_ext_device *dev);
  162. };
  163. struct hda_dai_map {
  164. char *dai_name;
  165. hda_nid_t nid;
  166. u32 maxbps;
  167. };
  168. struct hdac_ext_dma_params {
  169. u32 format;
  170. u8 stream_tag;
  171. };
  172. int snd_hda_ext_driver_register(struct hdac_driver *drv);
  173. void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
  174. #endif /* __SOUND_HDAUDIO_EXT_H */