cadence_master.h 5.5 KB

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