core.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2020 Intel Corporation
  4. *
  5. * Author: Cezary Rojewski <cezary.rojewski@intel.com>
  6. */
  7. #ifndef __SND_SOC_INTEL_CATPT_CORE_H
  8. #define __SND_SOC_INTEL_CATPT_CORE_H
  9. #include <linux/dma/dw.h>
  10. #include <linux/irqreturn.h>
  11. #include "messages.h"
  12. #include "registers.h"
  13. struct catpt_dev;
  14. extern const struct attribute_group *catpt_attr_groups[];
  15. void catpt_sram_init(struct resource *sram, u32 start, u32 size);
  16. void catpt_sram_free(struct resource *sram);
  17. struct resource *
  18. catpt_request_region(struct resource *root, resource_size_t size);
  19. struct catpt_ipc_msg {
  20. union {
  21. u32 header;
  22. union catpt_global_msg rsp;
  23. };
  24. void *data;
  25. size_t size;
  26. };
  27. struct catpt_ipc {
  28. struct device *dev;
  29. struct catpt_ipc_msg rx;
  30. struct catpt_fw_ready config;
  31. u32 default_timeout;
  32. bool ready;
  33. spinlock_t lock;
  34. struct mutex mutex;
  35. struct completion done_completion;
  36. struct completion busy_completion;
  37. };
  38. void catpt_ipc_init(struct catpt_ipc *ipc, struct device *dev);
  39. struct catpt_module_type {
  40. bool loaded;
  41. u32 entry_point;
  42. u32 persistent_size;
  43. u32 scratch_size;
  44. /* DRAM, initial module state */
  45. u32 state_offset;
  46. u32 state_size;
  47. struct list_head node;
  48. };
  49. struct catpt_spec {
  50. struct snd_soc_acpi_mach *machines;
  51. u8 core_id;
  52. u32 host_dram_offset;
  53. u32 host_iram_offset;
  54. u32 host_shim_offset;
  55. u32 host_dma_offset[CATPT_DMA_COUNT];
  56. u32 host_ssp_offset[CATPT_SSP_COUNT];
  57. u32 dram_mask;
  58. u32 iram_mask;
  59. u32 d3srampgd_bit;
  60. u32 d3pgd_bit;
  61. void (*pll_shutdown)(struct catpt_dev *cdev, bool enable);
  62. };
  63. struct catpt_dev {
  64. struct device *dev;
  65. struct dw_dma_chip *dmac;
  66. struct catpt_ipc ipc;
  67. void __iomem *pci_ba;
  68. void __iomem *lpe_ba;
  69. u32 lpe_base;
  70. int irq;
  71. const struct catpt_spec *spec;
  72. struct completion fw_ready;
  73. struct resource dram;
  74. struct resource iram;
  75. struct resource *scratch;
  76. struct catpt_mixer_stream_info mixer;
  77. struct catpt_module_type modules[CATPT_MODULE_COUNT];
  78. struct catpt_ssp_device_format devfmt[CATPT_SSP_COUNT];
  79. struct list_head stream_list;
  80. spinlock_t list_lock;
  81. struct mutex clk_mutex;
  82. struct catpt_dx_context dx_ctx;
  83. void *dxbuf_vaddr;
  84. dma_addr_t dxbuf_paddr;
  85. };
  86. int catpt_dmac_probe(struct catpt_dev *cdev);
  87. void catpt_dmac_remove(struct catpt_dev *cdev);
  88. struct dma_chan *catpt_dma_request_config_chan(struct catpt_dev *cdev);
  89. int catpt_dma_memcpy_todsp(struct catpt_dev *cdev, struct dma_chan *chan,
  90. dma_addr_t dst_addr, dma_addr_t src_addr,
  91. size_t size);
  92. int catpt_dma_memcpy_fromdsp(struct catpt_dev *cdev, struct dma_chan *chan,
  93. dma_addr_t dst_addr, dma_addr_t src_addr,
  94. size_t size);
  95. void lpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable);
  96. void wpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable);
  97. int catpt_dsp_power_up(struct catpt_dev *cdev);
  98. int catpt_dsp_power_down(struct catpt_dev *cdev);
  99. int catpt_dsp_stall(struct catpt_dev *cdev, bool stall);
  100. void catpt_dsp_update_srampge(struct catpt_dev *cdev, struct resource *sram,
  101. unsigned long mask);
  102. int catpt_dsp_update_lpclock(struct catpt_dev *cdev);
  103. irqreturn_t catpt_dsp_irq_handler(int irq, void *dev_id);
  104. irqreturn_t catpt_dsp_irq_thread(int irq, void *dev_id);
  105. /*
  106. * IPC handlers may return positive values which denote successful
  107. * HOST <-> DSP communication yet failure to process specific request.
  108. * Use below macro to convert returned non-zero values appropriately
  109. */
  110. #define CATPT_IPC_ERROR(err) (((err) < 0) ? (err) : -EREMOTEIO)
  111. int catpt_dsp_send_msg_timeout(struct catpt_dev *cdev,
  112. struct catpt_ipc_msg request,
  113. struct catpt_ipc_msg *reply, int timeout);
  114. int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request,
  115. struct catpt_ipc_msg *reply);
  116. int catpt_first_boot_firmware(struct catpt_dev *cdev);
  117. int catpt_boot_firmware(struct catpt_dev *cdev, bool restore);
  118. int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan);
  119. int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan);
  120. int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan);
  121. int catpt_coredump(struct catpt_dev *cdev);
  122. #include <sound/memalloc.h>
  123. #include <uapi/sound/asound.h>
  124. struct snd_pcm_substream;
  125. struct catpt_stream_template;
  126. struct catpt_stream_runtime {
  127. struct snd_pcm_substream *substream;
  128. struct catpt_stream_template *template;
  129. struct catpt_stream_info info;
  130. struct resource *persistent;
  131. struct snd_dma_buffer pgtbl;
  132. bool allocated;
  133. bool prepared;
  134. struct list_head node;
  135. };
  136. int catpt_register_plat_component(struct catpt_dev *cdev);
  137. void catpt_stream_update_position(struct catpt_dev *cdev,
  138. struct catpt_stream_runtime *stream,
  139. struct catpt_notify_position *pos);
  140. struct catpt_stream_runtime *
  141. catpt_stream_find(struct catpt_dev *cdev, u8 stream_hw_id);
  142. int catpt_arm_stream_templates(struct catpt_dev *cdev);
  143. #endif