cadence_master.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
  2. /* Copyright(c) 2015-17 Intel Corporation. */
  3. #include <sound/soc.h>
  4. #include "bus.h"
  5. #ifndef __SDW_CADENCE_H
  6. #define __SDW_CADENCE_H
  7. #define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */
  8. #define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000)
  9. /*
  10. * The Cadence IP supports up to 32 entries in the FIFO, though implementations
  11. * can configure the IP to have a smaller FIFO.
  12. */
  13. #define CDNS_MCP_IP_MAX_CMD_LEN 32
  14. #define SDW_CADENCE_MCP_IP_OFFSET 0x4000
  15. /**
  16. * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
  17. *
  18. * @num: pdi number
  19. * @intel_alh_id: link identifier
  20. * @l_ch_num: low channel for PDI
  21. * @h_ch_num: high channel for PDI
  22. * @ch_count: total channel count for PDI
  23. * @dir: data direction
  24. * @type: stream type, (only PCM supported)
  25. */
  26. struct sdw_cdns_pdi {
  27. int num;
  28. int intel_alh_id;
  29. int l_ch_num;
  30. int h_ch_num;
  31. int ch_count;
  32. enum sdw_data_direction dir;
  33. enum sdw_stream_type type;
  34. };
  35. /**
  36. * struct sdw_cdns_streams: Cadence stream data structure
  37. *
  38. * @num_bd: number of bidirectional streams
  39. * @num_in: number of input streams
  40. * @num_out: number of output streams
  41. * @num_ch_bd: number of bidirectional stream channels
  42. * @num_ch_bd: number of input stream channels
  43. * @num_ch_bd: number of output stream channels
  44. * @num_pdi: total number of PDIs
  45. * @bd: bidirectional streams
  46. * @in: input streams
  47. * @out: output streams
  48. */
  49. struct sdw_cdns_streams {
  50. unsigned int num_bd;
  51. unsigned int num_in;
  52. unsigned int num_out;
  53. unsigned int num_ch_bd;
  54. unsigned int num_ch_in;
  55. unsigned int num_ch_out;
  56. unsigned int num_pdi;
  57. struct sdw_cdns_pdi *bd;
  58. struct sdw_cdns_pdi *in;
  59. struct sdw_cdns_pdi *out;
  60. };
  61. /**
  62. * struct sdw_cdns_stream_config: stream configuration
  63. *
  64. * @pcm_bd: number of bidirectional PCM streams supported
  65. * @pcm_in: number of input PCM streams supported
  66. * @pcm_out: number of output PCM streams supported
  67. */
  68. struct sdw_cdns_stream_config {
  69. unsigned int pcm_bd;
  70. unsigned int pcm_in;
  71. unsigned int pcm_out;
  72. };
  73. /**
  74. * struct sdw_cdns_dai_runtime: Cadence DAI runtime data
  75. *
  76. * @name: SoundWire stream name
  77. * @stream: stream runtime
  78. * @pdi: PDI used for this dai
  79. * @bus: Bus handle
  80. * @stream_type: Stream type
  81. * @link_id: Master link id
  82. * @suspended: status set when suspended, to be used in .prepare
  83. * @paused: status set in .trigger, to be used in suspend
  84. * @direction: stream direction
  85. */
  86. struct sdw_cdns_dai_runtime {
  87. char *name;
  88. struct sdw_stream_runtime *stream;
  89. struct sdw_cdns_pdi *pdi;
  90. struct sdw_bus *bus;
  91. enum sdw_stream_type stream_type;
  92. int link_id;
  93. bool suspended;
  94. bool paused;
  95. int direction;
  96. };
  97. /**
  98. * struct sdw_cdns - Cadence driver context
  99. * @dev: Linux device
  100. * @bus: Bus handle
  101. * @instance: instance number
  102. * @ip_offset: version-dependent offset to access IP_MCP registers and fields
  103. * @response_buf: SoundWire response buffer
  104. * @tx_complete: Tx completion
  105. * @ports: Data ports
  106. * @num_ports: Total number of data ports
  107. * @pcm: PCM streams
  108. * @registers: Cadence registers
  109. * @link_up: Link status
  110. * @msg_count: Messages sent on bus
  111. * @dai_runtime_array: runtime context for each allocated DAI.
  112. * @status_update_lock: protect concurrency between interrupt-based and delayed work
  113. * status update
  114. */
  115. struct sdw_cdns {
  116. struct device *dev;
  117. struct sdw_bus bus;
  118. unsigned int instance;
  119. u32 ip_offset;
  120. /*
  121. * The datasheet says the RX FIFO AVAIL can be 2 entries more
  122. * than the FIFO capacity, so allow for this.
  123. */
  124. u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2];
  125. struct completion tx_complete;
  126. struct sdw_cdns_port *ports;
  127. int num_ports;
  128. struct sdw_cdns_streams pcm;
  129. int pdi_loopback_source;
  130. int pdi_loopback_target;
  131. void __iomem *registers;
  132. bool link_up;
  133. unsigned int msg_count;
  134. bool interrupt_enabled;
  135. struct work_struct work;
  136. struct delayed_work attach_dwork;
  137. struct list_head list;
  138. struct sdw_cdns_dai_runtime **dai_runtime_array;
  139. struct mutex status_update_lock; /* add mutual exclusion to sdw_handle_slave_status() */
  140. };
  141. #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
  142. /* Exported symbols */
  143. int sdw_cdns_probe(struct sdw_cdns *cdns);
  144. irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
  145. irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
  146. int sdw_cdns_soft_reset(struct sdw_cdns *cdns);
  147. int sdw_cdns_init(struct sdw_cdns *cdns);
  148. int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
  149. struct sdw_cdns_stream_config config);
  150. int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
  151. int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
  152. bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
  153. int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
  154. int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
  155. #ifdef CONFIG_DEBUG_FS
  156. void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
  157. #endif
  158. struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
  159. struct sdw_cdns_streams *stream,
  160. u32 ch, u32 dir, int dai_id);
  161. void sdw_cdns_config_stream(struct sdw_cdns *cdns,
  162. u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
  163. enum sdw_command_response
  164. cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
  165. enum sdw_command_response
  166. cdns_xfer_msg_defer(struct sdw_bus *bus);
  167. u32 cdns_read_ping_status(struct sdw_bus *bus);
  168. int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
  169. int cdns_set_sdw_stream(struct snd_soc_dai *dai,
  170. void *stream, int direction);
  171. void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
  172. bool initial_delay, int reset_iterations);
  173. void sdw_cdns_config_update(struct sdw_cdns *cdns);
  174. int sdw_cdns_config_update_set_wait(struct sdw_cdns *cdns);
  175. /* SoundWire BPT/BRA helpers to format data */
  176. int sdw_cdns_bpt_find_bandwidth(int command, /* 0: write, 1: read */
  177. int row, int col, int frame_rate,
  178. unsigned int *tx_dma_bandwidth,
  179. unsigned int *rx_dma_bandwidth);
  180. int sdw_cdns_bpt_find_buffer_sizes(int command, /* 0: write, 1: read */
  181. int row, int col, unsigned int data_bytes,
  182. unsigned int requested_bytes_per_frame,
  183. unsigned int *data_per_frame, unsigned int *pdi0_buffer_size,
  184. unsigned int *pdi1_buffer_size, unsigned int *num_frames);
  185. int sdw_cdns_prepare_write_dma_buffer(u8 dev_num, struct sdw_bpt_section *sec, int num_sec,
  186. int data_per_frame, u8 *dma_buffer,
  187. int dma_buffer_size, int *dma_buffer_total_bytes);
  188. int sdw_cdns_prepare_read_dma_buffer(u8 dev_num, struct sdw_bpt_section *sec, int num_sec,
  189. int data_per_frame, u8 *dma_buffer, int dma_buffer_size,
  190. int *dma_buffer_total_bytes, unsigned int fake_size);
  191. int sdw_cdns_check_write_response(struct device *dev, u8 *dma_buffer,
  192. int dma_buffer_size, int num_frames);
  193. int sdw_cdns_check_read_response(struct device *dev, u8 *dma_buffer, int dma_buffer_size,
  194. struct sdw_bpt_section *sec, int num_sec, int num_frames,
  195. int data_per_frame);
  196. #endif /* __SDW_CADENCE_H */