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