hdaudio_ext.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SOUND_HDAUDIO_EXT_H
  3. #define __SOUND_HDAUDIO_EXT_H
  4. #include <sound/hdaudio.h>
  5. /**
  6. * hdac_ext_bus: HDAC extended bus for extended HDA caps
  7. *
  8. * @bus: hdac bus
  9. * @num_streams: streams supported
  10. * @hlink_list: link list of HDA links
  11. * @lock: lock for link mgmt
  12. * @cmd_dma_state: state of cmd DMAs: CORB and RIRB
  13. */
  14. struct hdac_ext_bus {
  15. struct hdac_bus bus;
  16. int num_streams;
  17. int idx;
  18. struct list_head hlink_list;
  19. struct mutex lock;
  20. bool cmd_dma_state;
  21. };
  22. int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
  23. const struct hdac_bus_ops *ops,
  24. const struct hdac_io_ops *io_ops);
  25. void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
  26. int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
  27. void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
  28. void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
  29. #define ebus_to_hbus(ebus) (&(ebus)->bus)
  30. #define hbus_to_ebus(_bus) \
  31. container_of(_bus, struct hdac_ext_bus, bus)
  32. #define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
  33. { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
  34. .api_version = HDA_DEV_ASOC, \
  35. .driver_data = (unsigned long)(drv_data) }
  36. #define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
  37. HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
  38. void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
  39. void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
  40. void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
  41. bool enable, int index);
  42. int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
  43. struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
  44. const char *codec_name);
  45. enum hdac_ext_stream_type {
  46. HDAC_EXT_STREAM_TYPE_COUPLED = 0,
  47. HDAC_EXT_STREAM_TYPE_HOST,
  48. HDAC_EXT_STREAM_TYPE_LINK
  49. };
  50. /**
  51. * hdac_ext_stream: HDAC extended stream for extended HDA caps
  52. *
  53. * @hstream: hdac_stream
  54. * @pphc_addr: processing pipe host stream pointer
  55. * @pplc_addr: processing pipe link stream pointer
  56. * @spib_addr: software position in buffers stream pointer
  57. * @fifo_addr: software position Max fifos stream pointer
  58. * @dpibr_addr: DMA position in buffer resume pointer
  59. * @dpib: DMA position in buffer
  60. * @lpib: Linear position in buffer
  61. * @decoupled: stream host and link is decoupled
  62. * @link_locked: link is locked
  63. * @link_prepared: link is prepared
  64. * link_substream: link substream
  65. */
  66. struct hdac_ext_stream {
  67. struct hdac_stream hstream;
  68. void __iomem *pphc_addr;
  69. void __iomem *pplc_addr;
  70. void __iomem *spib_addr;
  71. void __iomem *fifo_addr;
  72. void __iomem *dpibr_addr;
  73. u32 dpib;
  74. u32 lpib;
  75. bool decoupled:1;
  76. bool link_locked:1;
  77. bool link_prepared;
  78. struct snd_pcm_substream *link_substream;
  79. };
  80. #define hdac_stream(s) (&(s)->hstream)
  81. #define stream_to_hdac_ext_stream(s) \
  82. container_of(s, struct hdac_ext_stream, hstream)
  83. void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
  84. struct hdac_ext_stream *stream, int idx,
  85. int direction, int tag);
  86. int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
  87. int num_stream, int dir);
  88. void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
  89. void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
  90. struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
  91. struct snd_pcm_substream *substream,
  92. int type);
  93. void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
  94. void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
  95. struct hdac_ext_stream *azx_dev, bool decouple);
  96. void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
  97. int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
  98. struct hdac_ext_stream *stream, u32 value);
  99. int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
  100. struct hdac_ext_stream *stream);
  101. void snd_hdac_ext_stream_drsm_enable(struct hdac_ext_bus *ebus,
  102. bool enable, int index);
  103. int snd_hdac_ext_stream_set_dpibr(struct hdac_ext_bus *ebus,
  104. struct hdac_ext_stream *stream, u32 value);
  105. int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
  106. void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
  107. void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
  108. void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
  109. int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
  110. struct hdac_ext_link {
  111. struct hdac_bus *bus;
  112. int index;
  113. void __iomem *ml_addr; /* link output stream reg pointer */
  114. u32 lcaps; /* link capablities */
  115. u16 lsdiid; /* link sdi identifier */
  116. int ref_count;
  117. struct list_head list;
  118. };
  119. int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
  120. int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
  121. int snd_hdac_ext_bus_link_power_up_all(struct hdac_ext_bus *ebus);
  122. int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
  123. void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
  124. int stream);
  125. void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
  126. int stream);
  127. int snd_hdac_ext_bus_link_get(struct hdac_ext_bus *ebus,
  128. struct hdac_ext_link *link);
  129. int snd_hdac_ext_bus_link_put(struct hdac_ext_bus *ebus,
  130. struct hdac_ext_link *link);
  131. /* update register macro */
  132. #define snd_hdac_updatel(addr, reg, mask, val) \
  133. writel(((readl(addr + reg) & ~(mask)) | (val)), \
  134. addr + reg)
  135. #define snd_hdac_updatew(addr, reg, mask, val) \
  136. writew(((readw(addr + reg) & ~(mask)) | (val)), \
  137. addr + reg)
  138. struct hdac_ext_device;
  139. /* ops common to all codec drivers */
  140. struct hdac_ext_codec_ops {
  141. int (*build_controls)(struct hdac_ext_device *dev);
  142. int (*init)(struct hdac_ext_device *dev);
  143. void (*free)(struct hdac_ext_device *dev);
  144. };
  145. struct hda_dai_map {
  146. char *dai_name;
  147. hda_nid_t nid;
  148. u32 maxbps;
  149. };
  150. #define HDA_MAX_NIDS 16
  151. /**
  152. * struct hdac_ext_device - HDAC Ext device
  153. *
  154. * @hdac: hdac core device
  155. * @nid_list - the dai map which matches the dai-name with the nid
  156. * @map_cur_idx - the idx in use in dai_map
  157. * @ops - the hda codec ops common to all codec drivers
  158. * @pvt_data - private data, for asoc contains asoc codec object
  159. */
  160. struct hdac_ext_device {
  161. struct hdac_device hdac;
  162. struct hdac_ext_bus *ebus;
  163. /* soc-dai to nid map */
  164. struct hda_dai_map nid_list[HDA_MAX_NIDS];
  165. unsigned int map_cur_idx;
  166. /* codec ops */
  167. struct hdac_ext_codec_ops ops;
  168. struct snd_card *card;
  169. void *scodec;
  170. void *private_data;
  171. };
  172. struct hdac_ext_dma_params {
  173. u32 format;
  174. u8 stream_tag;
  175. };
  176. #define to_ehdac_device(dev) (container_of((dev), \
  177. struct hdac_ext_device, hdac))
  178. /*
  179. * HD-audio codec base driver
  180. */
  181. struct hdac_ext_driver {
  182. struct hdac_driver hdac;
  183. int (*probe)(struct hdac_ext_device *dev);
  184. int (*remove)(struct hdac_ext_device *dev);
  185. void (*shutdown)(struct hdac_ext_device *dev);
  186. };
  187. int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
  188. void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
  189. #define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
  190. #endif /* __SOUND_HDAUDIO_EXT_H */