aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/intel/catpt/messages.c
blob: a793d114afa4f17b70def1b446aab6c80d2a8b09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//

#include <linux/slab.h>
#include "core.h"
#include "messages.h"
#include "registers.h"

int catpt_ipc_get_fw_version(struct catpt_dev *cdev,
			     struct catpt_fw_version *version)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(GET_FW_VERSION);
	struct catpt_ipc_msg request = {{0}}, reply;
	int ret;

	request.header = msg.val;
	reply.size = sizeof(*version);
	reply.data = version;

	ret = catpt_dsp_send_msg(cdev, request, &reply);
	if (ret)
		dev_err(cdev->dev, "get fw version failed: %d\n", ret);

	return ret;
}

struct catpt_alloc_stream_input {
	enum catpt_path_id path_id:8;
	enum catpt_stream_type stream_type:8;
	enum catpt_format_id format_id:8;
	u8 reserved;
	struct catpt_audio_format input_format;
	struct catpt_ring_info ring_info;
	u8 num_entries;
	/* flex array with entries here */
	struct catpt_memory_info persistent_mem;
	struct catpt_memory_info scratch_mem;
	u32 num_notifications; /* obsolete */
} __packed;

int catpt_ipc_alloc_stream(struct catpt_dev *cdev,
			   enum catpt_path_id path_id,
			   enum catpt_stream_type type,
			   struct catpt_audio_format *afmt,
			   struct catpt_ring_info *rinfo,
			   u8 num_modules,
			   struct catpt_module_entry *modules,
			   struct resource *persistent,
			   struct resource *scratch,
			   struct catpt_stream_info *sinfo)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(ALLOCATE_STREAM);
	struct catpt_alloc_stream_input input;
	struct catpt_ipc_msg request, reply;
	size_t size, arrsz;
	u8 *payload;
	off_t off;
	int ret;

	off = offsetof(struct catpt_alloc_stream_input, persistent_mem);
	arrsz = sizeof(*modules) * num_modules;
	size = sizeof(input) + arrsz;

	payload = kzalloc(size, GFP_KERNEL);
	if (!payload)
		return -ENOMEM;

	memset(&input, 0, sizeof(input));
	input.path_id = path_id;
	input.stream_type = type;
	input.format_id = CATPT_FORMAT_PCM;
	input.input_format = *afmt;
	input.ring_info = *rinfo;
	input.num_entries = num_modules;
	input.persistent_mem.offset = catpt_to_dsp_offset(persistent->start);
	input.persistent_mem.size = resource_size(persistent);
	if (scratch) {
		input.scratch_mem.offset = catpt_to_dsp_offset(scratch->start);
		input.scratch_mem.size = resource_size(scratch);
	}

	/* re-arrange the input: account for flex array 'entries' */
	memcpy(payload, &input, sizeof(input));
	memmove(payload + off + arrsz, payload + off, sizeof(input) - off);
	memcpy(payload + off, modules, arrsz);

	request.header = msg.val;
	request.size = size;
	request.data = payload;
	reply.size = sizeof(*sinfo);
	reply.data = sinfo;

	ret = catpt_dsp_send_msg(cdev, request, &reply);
	if (ret)
		dev_err(cdev->dev, "alloc stream type %d failed: %d\n",
			type, ret);

	kfree(payload);
	return ret;
}

int catpt_ipc_free_stream(struct catpt_dev *cdev, u8 stream_hw_id)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(FREE_STREAM);
	struct catpt_ipc_msg request;
	int ret;

	request.header = msg.val;
	request.size = sizeof(stream_hw_id);
	request.data = &stream_hw_id;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "free stream %d failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

int catpt_ipc_set_device_format(struct catpt_dev *cdev,
				struct catpt_ssp_device_format *devfmt)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(SET_DEVICE_FORMATS);
	struct catpt_ipc_msg request;
	int ret;

	request.header = msg.val;
	request.size = sizeof(*devfmt);
	request.data = devfmt;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "set device format failed: %d\n", ret);

	return ret;
}

int catpt_ipc_enter_dxstate(struct catpt_dev *cdev, enum catpt_dx_state state,
			    struct catpt_dx_context *context)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(ENTER_DX_STATE);
	struct catpt_ipc_msg request, reply;
	int ret;

	request.header = msg.val;
	request.size = sizeof(state);
	request.data = &state;
	reply.size = sizeof(*context);
	reply.data = context;

	ret = catpt_dsp_send_msg(cdev, request, &reply);
	if (ret)
		dev_err(cdev->dev, "enter dx state failed: %d\n", ret);

	return ret;
}

int catpt_ipc_get_mixer_stream_info(struct catpt_dev *cdev,
				    struct catpt_mixer_stream_info *info)
{
	union catpt_global_msg msg = CATPT_GLOBAL_MSG(GET_MIXER_STREAM_INFO);
	struct catpt_ipc_msg request = {{0}}, reply;
	int ret;

	request.header = msg.val;
	reply.size = sizeof(*info);
	reply.data = info;

	ret = catpt_dsp_send_msg(cdev, request, &reply);
	if (ret)
		dev_err(cdev->dev, "get mixer info failed: %d\n", ret);

	return ret;
}

int catpt_ipc_reset_stream(struct catpt_dev *cdev, u8 stream_hw_id)
{
	union catpt_stream_msg msg = CATPT_STREAM_MSG(RESET_STREAM);
	struct catpt_ipc_msg request = {{0}};
	int ret;

	msg.stream_hw_id = stream_hw_id;
	request.header = msg.val;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "reset stream %d failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

int catpt_ipc_pause_stream(struct catpt_dev *cdev, u8 stream_hw_id)
{
	union catpt_stream_msg msg = CATPT_STREAM_MSG(PAUSE_STREAM);
	struct catpt_ipc_msg request = {{0}};
	int ret;

	msg.stream_hw_id = stream_hw_id;
	request.header = msg.val;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "pause stream %d failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

int catpt_ipc_resume_stream(struct catpt_dev *cdev, u8 stream_hw_id)
{
	union catpt_stream_msg msg = CATPT_STREAM_MSG(RESUME_STREAM);
	struct catpt_ipc_msg request = {{0}};
	int ret;

	msg.stream_hw_id = stream_hw_id;
	request.header = msg.val;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "resume stream %d failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

struct catpt_set_volume_input {
	u32 channel;
	u32 target_volume;
	u64 curve_duration;
	u32 curve_type;
} __packed;

int catpt_ipc_set_volume(struct catpt_dev *cdev, u8 stream_hw_id,
			 u32 channel, u32 volume,
			 u32 curve_duration,
			 enum catpt_audio_curve_type curve_type)
{
	union catpt_stream_msg msg = CATPT_STAGE_MSG(SET_VOLUME);
	struct catpt_ipc_msg request;
	struct catpt_set_volume_input input;
	int ret;

	msg.stream_hw_id = stream_hw_id;
	input.channel = channel;
	input.target_volume = volume;
	input.curve_duration = curve_duration;
	input.curve_type = curve_type;

	request.header = msg.val;
	request.size = sizeof(input);
	request.data = &input;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "set stream %d volume failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

struct catpt_set_write_pos_input {
	u32 new_write_pos;
	bool end_of_buffer;
	bool low_latency;
} __packed;

int catpt_ipc_set_write_pos(struct catpt_dev *cdev, u8 stream_hw_id,
			    u32 pos, bool eob, bool ll)
{
	union catpt_stream_msg msg = CATPT_STAGE_MSG(SET_WRITE_POSITION);
	struct catpt_ipc_msg request;
	struct catpt_set_write_pos_input input;
	int ret;

	msg.stream_hw_id = stream_hw_id;
	input.new_write_pos = pos;
	input.end_of_buffer = eob;
	input.low_latency = ll;

	request.header = msg.val;
	request.size = sizeof(input);
	request.data = &input;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "set stream %d write pos failed: %d\n",
			stream_hw_id, ret);

	return ret;
}

int catpt_ipc_mute_loopback(struct catpt_dev *cdev, u8 stream_hw_id, bool mute)
{
	union catpt_stream_msg msg = CATPT_STAGE_MSG(MUTE_LOOPBACK);
	struct catpt_ipc_msg request;
	int ret;

	msg.stream_hw_id = stream_hw_id;
	request.header = msg.val;
	request.size = sizeof(mute);
	request.data = &mute;

	ret = catpt_dsp_send_msg(cdev, request, NULL);
	if (ret)
		dev_err(cdev->dev, "mute loopback failed: %d\n", ret);

	return ret;
}