cadence_master.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. // Copyright(c) 2015-17 Intel Corporation.
  3. #include <sound/soc.h>
  4. #ifndef __SDW_CADENCE_H
  5. #define __SDW_CADENCE_H
  6. /**
  7. * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
  8. *
  9. * @assigned: pdi assigned
  10. * @num: pdi number
  11. * @intel_alh_id: link identifier
  12. * @l_ch_num: low channel for PDI
  13. * @h_ch_num: high channel for PDI
  14. * @ch_count: total channel count for PDI
  15. * @dir: data direction
  16. * @type: stream type, PDM or PCM
  17. */
  18. struct sdw_cdns_pdi {
  19. bool assigned;
  20. int num;
  21. int intel_alh_id;
  22. int l_ch_num;
  23. int h_ch_num;
  24. int ch_count;
  25. enum sdw_data_direction dir;
  26. enum sdw_stream_type type;
  27. };
  28. /**
  29. * struct sdw_cdns_port: Cadence port structure
  30. *
  31. * @num: port number
  32. * @assigned: port assigned
  33. * @ch: channel count
  34. * @direction: data port direction
  35. * @pdi: pdi for this port
  36. */
  37. struct sdw_cdns_port {
  38. unsigned int num;
  39. bool assigned;
  40. unsigned int ch;
  41. enum sdw_data_direction direction;
  42. struct sdw_cdns_pdi *pdi;
  43. };
  44. /**
  45. * struct sdw_cdns_streams: Cadence stream data structure
  46. *
  47. * @num_bd: number of bidirectional streams
  48. * @num_in: number of input streams
  49. * @num_out: number of output streams
  50. * @num_ch_bd: number of bidirectional stream channels
  51. * @num_ch_bd: number of input stream channels
  52. * @num_ch_bd: number of output stream channels
  53. * @num_pdi: total number of PDIs
  54. * @bd: bidirectional streams
  55. * @in: input streams
  56. * @out: output streams
  57. */
  58. struct sdw_cdns_streams {
  59. unsigned int num_bd;
  60. unsigned int num_in;
  61. unsigned int num_out;
  62. unsigned int num_ch_bd;
  63. unsigned int num_ch_in;
  64. unsigned int num_ch_out;
  65. unsigned int num_pdi;
  66. struct sdw_cdns_pdi *bd;
  67. struct sdw_cdns_pdi *in;
  68. struct sdw_cdns_pdi *out;
  69. };
  70. /**
  71. * struct sdw_cdns_stream_config: stream configuration
  72. *
  73. * @pcm_bd: number of bidirectional PCM streams supported
  74. * @pcm_in: number of input PCM streams supported
  75. * @pcm_out: number of output PCM streams supported
  76. * @pdm_bd: number of bidirectional PDM streams supported
  77. * @pdm_in: number of input PDM streams supported
  78. * @pdm_out: number of output PDM streams supported
  79. */
  80. struct sdw_cdns_stream_config {
  81. unsigned int pcm_bd;
  82. unsigned int pcm_in;
  83. unsigned int pcm_out;
  84. unsigned int pdm_bd;
  85. unsigned int pdm_in;
  86. unsigned int pdm_out;
  87. };
  88. /**
  89. * struct sdw_cdns_dma_data: Cadence DMA data
  90. *
  91. * @name: SoundWire stream name
  92. * @nr_ports: Number of ports
  93. * @port: Ports
  94. * @bus: Bus handle
  95. * @stream_type: Stream type
  96. * @link_id: Master link id
  97. */
  98. struct sdw_cdns_dma_data {
  99. char *name;
  100. struct sdw_stream_runtime *stream;
  101. int nr_ports;
  102. struct sdw_cdns_port **port;
  103. struct sdw_bus *bus;
  104. enum sdw_stream_type stream_type;
  105. int link_id;
  106. };
  107. /**
  108. * struct sdw_cdns - Cadence driver context
  109. * @dev: Linux device
  110. * @bus: Bus handle
  111. * @instance: instance number
  112. * @response_buf: SoundWire response buffer
  113. * @tx_complete: Tx completion
  114. * @defer: Defer pointer
  115. * @ports: Data ports
  116. * @num_ports: Total number of data ports
  117. * @pcm: PCM streams
  118. * @pdm: PDM streams
  119. * @registers: Cadence registers
  120. * @link_up: Link status
  121. * @msg_count: Messages sent on bus
  122. */
  123. struct sdw_cdns {
  124. struct device *dev;
  125. struct sdw_bus bus;
  126. unsigned int instance;
  127. u32 response_buf[0x80];
  128. struct completion tx_complete;
  129. struct sdw_defer *defer;
  130. struct sdw_cdns_port *ports;
  131. int num_ports;
  132. struct sdw_cdns_streams pcm;
  133. struct sdw_cdns_streams pdm;
  134. void __iomem *registers;
  135. bool link_up;
  136. unsigned int msg_count;
  137. };
  138. #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
  139. /* Exported symbols */
  140. int sdw_cdns_probe(struct sdw_cdns *cdns);
  141. extern struct sdw_master_ops sdw_cdns_master_ops;
  142. irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
  143. irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
  144. int sdw_cdns_init(struct sdw_cdns *cdns);
  145. int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
  146. struct sdw_cdns_stream_config config);
  147. int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
  148. int sdw_cdns_get_stream(struct sdw_cdns *cdns,
  149. struct sdw_cdns_streams *stream,
  150. u32 ch, u32 dir);
  151. int sdw_cdns_alloc_stream(struct sdw_cdns *cdns,
  152. struct sdw_cdns_streams *stream,
  153. struct sdw_cdns_port *port, u32 ch, u32 dir);
  154. void sdw_cdns_config_stream(struct sdw_cdns *cdns, struct sdw_cdns_port *port,
  155. u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
  156. void sdw_cdns_shutdown(struct snd_pcm_substream *substream,
  157. struct snd_soc_dai *dai);
  158. int sdw_cdns_pcm_set_stream(struct snd_soc_dai *dai,
  159. void *stream, int direction);
  160. int sdw_cdns_pdm_set_stream(struct snd_soc_dai *dai,
  161. void *stream, int direction);
  162. enum sdw_command_response
  163. cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
  164. enum sdw_command_response
  165. cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
  166. enum sdw_command_response
  167. cdns_xfer_msg_defer(struct sdw_bus *bus,
  168. struct sdw_msg *msg, struct sdw_defer *defer);
  169. enum sdw_command_response
  170. cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
  171. int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
  172. int cdns_set_sdw_stream(struct snd_soc_dai *dai,
  173. void *stream, bool pcm, int direction);
  174. #endif /* __SDW_CADENCE_H */