1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright(c) 2020 Intel Corporation. All rights reserved. 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 static inline bool catpt_resource_overlapping(struct resource *r1, 26 struct resource *r2, 27 struct resource *ret) 28 { 29 if (!resource_overlaps(r1, r2)) 30 return false; 31 ret->start = max(r1->start, r2->start); 32 ret->end = min(r1->end, r2->end); 33 return true; 34 } 35 36 struct catpt_ipc_msg { 37 union { 38 u32 header; 39 union catpt_global_msg rsp; 40 }; 41 void *data; 42 size_t size; 43 }; 44 45 struct catpt_ipc { 46 struct device *dev; 47 48 struct catpt_ipc_msg rx; 49 struct catpt_fw_ready config; 50 u32 default_timeout; 51 bool ready; 52 53 spinlock_t lock; 54 struct mutex mutex; 55 struct completion done_completion; 56 struct completion busy_completion; 57 }; 58 59 void catpt_ipc_init(struct catpt_ipc *ipc, struct device *dev); 60 61 struct catpt_module_type { 62 bool loaded; 63 u32 entry_point; 64 u32 persistent_size; 65 u32 scratch_size; 66 /* DRAM, initial module state */ 67 u32 state_offset; 68 u32 state_size; 69 70 struct list_head node; 71 }; 72 73 struct catpt_spec { 74 struct snd_soc_acpi_mach *machines; 75 u8 core_id; 76 u32 host_dram_offset; 77 u32 host_iram_offset; 78 u32 host_shim_offset; 79 u32 host_dma_offset[CATPT_DMA_COUNT]; 80 u32 host_ssp_offset[CATPT_SSP_COUNT]; 81 u32 dram_mask; 82 u32 iram_mask; 83 void (*pll_shutdown)(struct catpt_dev *cdev, bool enable); 84 int (*power_up)(struct catpt_dev *cdev); 85 int (*power_down)(struct catpt_dev *cdev); 86 }; 87 88 struct catpt_dev { 89 struct device *dev; 90 struct dw_dma_chip *dmac; 91 struct catpt_ipc ipc; 92 93 void __iomem *pci_ba; 94 void __iomem *lpe_ba; 95 u32 lpe_base; 96 int irq; 97 98 const struct catpt_spec *spec; 99 struct completion fw_ready; 100 101 struct resource dram; 102 struct resource iram; 103 struct resource *scratch; 104 105 struct catpt_mixer_stream_info mixer; 106 struct catpt_module_type modules[CATPT_MODULE_COUNT]; 107 struct catpt_ssp_device_format devfmt[CATPT_SSP_COUNT]; 108 struct list_head stream_list; 109 spinlock_t list_lock; 110 struct mutex clk_mutex; 111 112 struct catpt_dx_context dx_ctx; 113 void *dxbuf_vaddr; 114 dma_addr_t dxbuf_paddr; 115 }; 116 117 int catpt_dmac_probe(struct catpt_dev *cdev); 118 void catpt_dmac_remove(struct catpt_dev *cdev); 119 struct dma_chan *catpt_dma_request_config_chan(struct catpt_dev *cdev); 120 int catpt_dma_memcpy_todsp(struct catpt_dev *cdev, struct dma_chan *chan, 121 dma_addr_t dst_addr, dma_addr_t src_addr, 122 size_t size); 123 int catpt_dma_memcpy_fromdsp(struct catpt_dev *cdev, struct dma_chan *chan, 124 dma_addr_t dst_addr, dma_addr_t src_addr, 125 size_t size); 126 127 void lpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable); 128 void wpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable); 129 int lpt_dsp_power_up(struct catpt_dev *cdev); 130 int lpt_dsp_power_down(struct catpt_dev *cdev); 131 int wpt_dsp_power_up(struct catpt_dev *cdev); 132 int wpt_dsp_power_down(struct catpt_dev *cdev); 133 int catpt_dsp_stall(struct catpt_dev *cdev, bool stall); 134 void catpt_dsp_update_srampge(struct catpt_dev *cdev, struct resource *sram, 135 unsigned long mask); 136 int catpt_dsp_update_lpclock(struct catpt_dev *cdev); 137 irqreturn_t catpt_dsp_irq_handler(int irq, void *dev_id); 138 irqreturn_t catpt_dsp_irq_thread(int irq, void *dev_id); 139 140 /* 141 * IPC handlers may return positive values which denote successful 142 * HOST <-> DSP communication yet failure to process specific request. 143 * Use below macro to convert returned non-zero values appropriately 144 */ 145 #define CATPT_IPC_ERROR(err) (((err) < 0) ? (err) : -EREMOTEIO) 146 147 int catpt_dsp_send_msg_timeout(struct catpt_dev *cdev, 148 struct catpt_ipc_msg request, 149 struct catpt_ipc_msg *reply, int timeout); 150 int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request, 151 struct catpt_ipc_msg *reply); 152 153 int catpt_first_boot_firmware(struct catpt_dev *cdev); 154 int catpt_boot_firmware(struct catpt_dev *cdev, bool restore); 155 int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan); 156 int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan); 157 int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan); 158 int catpt_coredump(struct catpt_dev *cdev); 159 160 #include <sound/memalloc.h> 161 #include <uapi/sound/asound.h> 162 163 struct snd_pcm_substream; 164 struct catpt_stream_template; 165 166 struct catpt_stream_runtime { 167 struct snd_pcm_substream *substream; 168 169 struct catpt_stream_template *template; 170 struct catpt_stream_info info; 171 struct resource *persistent; 172 struct snd_dma_buffer pgtbl; 173 174 bool allocated; 175 bool prepared; 176 177 struct list_head node; 178 }; 179 180 int catpt_register_plat_component(struct catpt_dev *cdev); 181 void catpt_stream_update_position(struct catpt_dev *cdev, 182 struct catpt_stream_runtime *stream, 183 struct catpt_notify_position *pos); 184 struct catpt_stream_runtime * 185 catpt_stream_find(struct catpt_dev *cdev, u8 stream_hw_id); 186 int catpt_arm_stream_templates(struct catpt_dev *cdev); 187 188 #endif 189