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