cadence_master.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
  10. *
  11. * @num: pdi number
  12. * @intel_alh_id: link identifier
  13. * @l_ch_num: low channel for PDI
  14. * @h_ch_num: high channel for PDI
  15. * @ch_count: total channel count for PDI
  16. * @dir: data direction
  17. * @type: stream type, PDM or PCM
  18. */
  19. struct sdw_cdns_pdi {
  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_streams: Cadence stream data structure
  30. *
  31. * @num_bd: number of bidirectional streams
  32. * @num_in: number of input streams
  33. * @num_out: number of output streams
  34. * @num_ch_bd: number of bidirectional stream channels
  35. * @num_ch_bd: number of input stream channels
  36. * @num_ch_bd: number of output stream channels
  37. * @num_pdi: total number of PDIs
  38. * @bd: bidirectional streams
  39. * @in: input streams
  40. * @out: output streams
  41. */
  42. struct sdw_cdns_streams {
  43. unsigned int num_bd;
  44. unsigned int num_in;
  45. unsigned int num_out;
  46. unsigned int num_ch_bd;
  47. unsigned int num_ch_in;
  48. unsigned int num_ch_out;
  49. unsigned int num_pdi;
  50. struct sdw_cdns_pdi *bd;
  51. struct sdw_cdns_pdi *in;
  52. struct sdw_cdns_pdi *out;
  53. };
  54. /**
  55. * struct sdw_cdns_stream_config: stream configuration
  56. *
  57. * @pcm_bd: number of bidirectional PCM streams supported
  58. * @pcm_in: number of input PCM streams supported
  59. * @pcm_out: number of output PCM streams supported
  60. * @pdm_bd: number of bidirectional PDM streams supported
  61. * @pdm_in: number of input PDM streams supported
  62. * @pdm_out: number of output PDM streams supported
  63. */
  64. struct sdw_cdns_stream_config {
  65. unsigned int pcm_bd;
  66. unsigned int pcm_in;
  67. unsigned int pcm_out;
  68. unsigned int pdm_bd;
  69. unsigned int pdm_in;
  70. unsigned int pdm_out;
  71. };
  72. /**
  73. * struct sdw_cdns_dma_data: Cadence DMA 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. * @hw_params: hw_params to be applied in .prepare step
  82. * @suspended: status set when suspended, to be used in .prepare
  83. */
  84. struct sdw_cdns_dma_data {
  85. char *name;
  86. struct sdw_stream_runtime *stream;
  87. struct sdw_cdns_pdi *pdi;
  88. struct sdw_bus *bus;
  89. enum sdw_stream_type stream_type;
  90. int link_id;
  91. struct snd_pcm_hw_params *hw_params;
  92. bool suspended;
  93. };
  94. /**
  95. * struct sdw_cdns - Cadence driver context
  96. * @dev: Linux device
  97. * @bus: Bus handle
  98. * @instance: instance number
  99. * @response_buf: SoundWire response buffer
  100. * @tx_complete: Tx completion
  101. * @defer: Defer pointer
  102. * @ports: Data ports
  103. * @num_ports: Total number of data ports
  104. * @pcm: PCM streams
  105. * @pdm: PDM streams
  106. * @registers: Cadence registers
  107. * @link_up: Link status
  108. * @msg_count: Messages sent on bus
  109. */
  110. struct sdw_cdns {
  111. struct device *dev;
  112. struct sdw_bus bus;
  113. unsigned int instance;
  114. u32 response_buf[0x80];
  115. struct completion tx_complete;
  116. struct sdw_defer *defer;
  117. struct sdw_cdns_port *ports;
  118. int num_ports;
  119. struct sdw_cdns_streams pcm;
  120. struct sdw_cdns_streams pdm;
  121. void __iomem *registers;
  122. bool link_up;
  123. unsigned int msg_count;
  124. bool interrupt_enabled;
  125. struct work_struct work;
  126. struct list_head list;
  127. };
  128. #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
  129. /* Exported symbols */
  130. int sdw_cdns_probe(struct sdw_cdns *cdns);
  131. extern struct sdw_master_ops sdw_cdns_master_ops;
  132. irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
  133. irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
  134. int sdw_cdns_init(struct sdw_cdns *cdns);
  135. int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
  136. struct sdw_cdns_stream_config config);
  137. int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
  138. int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
  139. bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
  140. int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
  141. int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
  142. #ifdef CONFIG_DEBUG_FS
  143. void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
  144. #endif
  145. struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
  146. struct sdw_cdns_streams *stream,
  147. u32 ch, u32 dir, int dai_id);
  148. void sdw_cdns_config_stream(struct sdw_cdns *cdns,
  149. u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
  150. enum sdw_command_response
  151. cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
  152. enum sdw_command_response
  153. cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
  154. enum sdw_command_response
  155. cdns_xfer_msg_defer(struct sdw_bus *bus,
  156. struct sdw_msg *msg, struct sdw_defer *defer);
  157. enum sdw_command_response
  158. cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
  159. int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
  160. int cdns_set_sdw_stream(struct snd_soc_dai *dai,
  161. void *stream, bool pcm, int direction);
  162. #endif /* __SDW_CADENCE_H */