xref: /openbmc/linux/sound/soc/intel/catpt/core.h (revision 413d6ed3)
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 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 	u32 host_dram_offset;
66 	u32 host_iram_offset;
67 	u32 host_shim_offset;
68 	u32 host_dma_offset[CATPT_DMA_COUNT];
69 	u32 host_ssp_offset[CATPT_SSP_COUNT];
70 	u32 dram_mask;
71 	u32 iram_mask;
72 	u32 d3srampgd_bit;
73 	u32 d3pgd_bit;
74 	void (*pll_shutdown)(struct catpt_dev *cdev, bool enable);
75 };
76 
77 struct catpt_dev {
78 	struct device *dev;
79 	struct dw_dma_chip *dmac;
80 	struct catpt_ipc ipc;
81 
82 	void __iomem *pci_ba;
83 	void __iomem *lpe_ba;
84 	u32 lpe_base;
85 	int irq;
86 
87 	const struct catpt_spec *spec;
88 	struct completion fw_ready;
89 
90 	struct resource dram;
91 	struct resource iram;
92 	struct resource *scratch;
93 
94 	struct catpt_mixer_stream_info mixer;
95 	struct catpt_module_type modules[CATPT_MODULE_COUNT];
96 	struct catpt_ssp_device_format devfmt[CATPT_SSP_COUNT];
97 	struct list_head stream_list;
98 	spinlock_t list_lock;
99 	struct mutex clk_mutex;
100 
101 	struct catpt_dx_context dx_ctx;
102 	void *dxbuf_vaddr;
103 	dma_addr_t dxbuf_paddr;
104 };
105 
106 int catpt_dmac_probe(struct catpt_dev *cdev);
107 void catpt_dmac_remove(struct catpt_dev *cdev);
108 struct dma_chan *catpt_dma_request_config_chan(struct catpt_dev *cdev);
109 int catpt_dma_memcpy_todsp(struct catpt_dev *cdev, struct dma_chan *chan,
110 			   dma_addr_t dst_addr, dma_addr_t src_addr,
111 			   size_t size);
112 int catpt_dma_memcpy_fromdsp(struct catpt_dev *cdev, struct dma_chan *chan,
113 			     dma_addr_t dst_addr, dma_addr_t src_addr,
114 			     size_t size);
115 
116 void lpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable);
117 void wpt_dsp_pll_shutdown(struct catpt_dev *cdev, bool enable);
118 int catpt_dsp_power_up(struct catpt_dev *cdev);
119 int catpt_dsp_power_down(struct catpt_dev *cdev);
120 int catpt_dsp_stall(struct catpt_dev *cdev, bool stall);
121 void catpt_dsp_update_srampge(struct catpt_dev *cdev, struct resource *sram,
122 			      unsigned long mask);
123 int catpt_dsp_update_lpclock(struct catpt_dev *cdev);
124 irqreturn_t catpt_dsp_irq_handler(int irq, void *dev_id);
125 irqreturn_t catpt_dsp_irq_thread(int irq, void *dev_id);
126 
127 /*
128  * IPC handlers may return positive values which denote successful
129  * HOST <-> DSP communication yet failure to process specific request.
130  * Use below macro to convert returned non-zero values appropriately
131  */
132 #define CATPT_IPC_ERROR(err) (((err) < 0) ? (err) : -EREMOTEIO)
133 
134 int catpt_dsp_send_msg_timeout(struct catpt_dev *cdev,
135 			       struct catpt_ipc_msg request,
136 			       struct catpt_ipc_msg *reply, int timeout);
137 int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request,
138 		       struct catpt_ipc_msg *reply);
139 
140 int catpt_first_boot_firmware(struct catpt_dev *cdev);
141 int catpt_boot_firmware(struct catpt_dev *cdev, bool restore);
142 int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan);
143 int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan);
144 int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan);
145 int catpt_coredump(struct catpt_dev *cdev);
146 
147 #include <sound/memalloc.h>
148 #include <uapi/sound/asound.h>
149 
150 struct snd_pcm_substream;
151 struct catpt_stream_template;
152 
153 struct catpt_stream_runtime {
154 	struct snd_pcm_substream *substream;
155 
156 	struct catpt_stream_template *template;
157 	struct catpt_stream_info info;
158 	struct resource *persistent;
159 	struct snd_dma_buffer pgtbl;
160 
161 	bool allocated;
162 	bool prepared;
163 
164 	struct list_head node;
165 };
166 
167 int catpt_register_plat_component(struct catpt_dev *cdev);
168 void catpt_stream_update_position(struct catpt_dev *cdev,
169 				  struct catpt_stream_runtime *stream,
170 				  struct catpt_notify_position *pos);
171 struct catpt_stream_runtime *
172 catpt_stream_find(struct catpt_dev *cdev, u8 stream_hw_id);
173 int catpt_arm_stream_templates(struct catpt_dev *cdev);
174 
175 #endif
176