hdaudio_ext.h 7.0 KB

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