blob: 30c65b28fa60725c6b77bf7dbfba1f3beab0404f [file] [log] [blame]
Mark Browna4b12992014-03-12 23:04:35 +00001/*
2 * Intel SST Haswell/Broadwell IPC Support
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __SST_HASWELL_IPC_H
18#define __SST_HASWELL_IPC_H
19
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/platform_device.h>
Libin Yang1b006992015-02-10 10:02:47 +080023#include <sound/asound.h>
Mark Browna4b12992014-03-12 23:04:35 +000024
Jie Yangf74e2c92014-11-03 21:59:37 +080025#define SST_HSW_NO_CHANNELS 4
Mark Browna4b12992014-03-12 23:04:35 +000026#define SST_HSW_MAX_DX_REGIONS 14
Liam Girdwoodaed3c7b2014-10-29 17:40:42 +000027#define SST_HSW_DX_CONTEXT_SIZE (640 * 1024)
Jie Yangf1e59822014-11-25 21:00:53 +080028#define SST_HSW_CHANNELS_ALL 0xffffffff
Mark Browna4b12992014-03-12 23:04:35 +000029
30#define SST_HSW_FW_LOG_CONFIG_DWORDS 12
31#define SST_HSW_GLOBAL_LOG 15
32
33/**
34 * Upfront defined maximum message size that is
35 * expected by the in/out communication pipes in FW.
36 */
37#define SST_HSW_IPC_MAX_PAYLOAD_SIZE 400
38#define SST_HSW_MAX_INFO_SIZE 64
39#define SST_HSW_BUILD_HASH_LENGTH 40
40
41struct sst_hsw;
42struct sst_hsw_stream;
43struct sst_hsw_log_stream;
44struct sst_pdata;
45struct sst_module;
Liam Girdwoode9600bc2014-10-28 17:37:12 +000046struct sst_module_runtime;
Mark Browna4b12992014-03-12 23:04:35 +000047extern struct sst_ops haswell_ops;
48
49/* Stream Allocate Path ID */
50enum sst_hsw_stream_path_id {
51 SST_HSW_STREAM_PATH_SSP0_OUT = 0,
52 SST_HSW_STREAM_PATH_SSP0_IN = 1,
53 SST_HSW_STREAM_PATH_MAX_PATH_ID = 2,
54};
55
56/* Stream Allocate Stream Type */
57enum sst_hsw_stream_type {
58 SST_HSW_STREAM_TYPE_RENDER = 0,
59 SST_HSW_STREAM_TYPE_SYSTEM = 1,
60 SST_HSW_STREAM_TYPE_CAPTURE = 2,
61 SST_HSW_STREAM_TYPE_LOOPBACK = 3,
62 SST_HSW_STREAM_TYPE_MAX_STREAM_TYPE = 4,
63};
64
65/* Stream Allocate Stream Format */
66enum sst_hsw_stream_format {
67 SST_HSW_STREAM_FORMAT_PCM_FORMAT = 0,
68 SST_HSW_STREAM_FORMAT_MP3_FORMAT = 1,
69 SST_HSW_STREAM_FORMAT_AAC_FORMAT = 2,
70 SST_HSW_STREAM_FORMAT_MAX_FORMAT_ID = 3,
71};
72
73/* Device ID */
74enum sst_hsw_device_id {
75 SST_HSW_DEVICE_SSP_0 = 0,
76 SST_HSW_DEVICE_SSP_1 = 1,
77};
78
79/* Device Master Clock Frequency */
80enum sst_hsw_device_mclk {
81 SST_HSW_DEVICE_MCLK_OFF = 0,
82 SST_HSW_DEVICE_MCLK_FREQ_6_MHZ = 1,
83 SST_HSW_DEVICE_MCLK_FREQ_12_MHZ = 2,
84 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ = 3,
85};
86
87/* Device Clock Master */
88enum sst_hsw_device_mode {
89 SST_HSW_DEVICE_CLOCK_SLAVE = 0,
90 SST_HSW_DEVICE_CLOCK_MASTER = 1,
Liam Girdwoodf07e51c2014-10-16 15:29:15 +010091 SST_HSW_DEVICE_TDM_CLOCK_MASTER = 2,
Mark Browna4b12992014-03-12 23:04:35 +000092};
93
94/* DX Power State */
95enum sst_hsw_dx_state {
96 SST_HSW_DX_STATE_D0 = 0,
97 SST_HSW_DX_STATE_D1 = 1,
98 SST_HSW_DX_STATE_D3 = 3,
99 SST_HSW_DX_STATE_MAX = 3,
100};
101
102/* Audio stream stage IDs */
103enum sst_hsw_fx_stage_id {
104 SST_HSW_STAGE_ID_WAVES = 0,
105 SST_HSW_STAGE_ID_DTS = 1,
106 SST_HSW_STAGE_ID_DOLBY = 2,
107 SST_HSW_STAGE_ID_BOOST = 3,
108 SST_HSW_STAGE_ID_MAX_FX_ID
109};
110
111/* DX State Type */
112enum sst_hsw_dx_type {
113 SST_HSW_DX_TYPE_FW_IMAGE = 0,
114 SST_HSW_DX_TYPE_MEMORY_DUMP = 1
115};
116
117/* Volume Curve Type*/
118enum sst_hsw_volume_curve {
119 SST_HSW_VOLUME_CURVE_NONE = 0,
120 SST_HSW_VOLUME_CURVE_FADE = 1
121};
122
123/* Sample ordering */
124enum sst_hsw_interleaving {
125 SST_HSW_INTERLEAVING_PER_CHANNEL = 0,
126 SST_HSW_INTERLEAVING_PER_SAMPLE = 1,
127};
128
129/* Channel indices */
130enum sst_hsw_channel_index {
131 SST_HSW_CHANNEL_LEFT = 0,
132 SST_HSW_CHANNEL_CENTER = 1,
133 SST_HSW_CHANNEL_RIGHT = 2,
134 SST_HSW_CHANNEL_LEFT_SURROUND = 3,
135 SST_HSW_CHANNEL_CENTER_SURROUND = 3,
136 SST_HSW_CHANNEL_RIGHT_SURROUND = 4,
137 SST_HSW_CHANNEL_LFE = 7,
138 SST_HSW_CHANNEL_INVALID = 0xF,
139};
140
141/* List of supported channel maps. */
142enum sst_hsw_channel_config {
143 SST_HSW_CHANNEL_CONFIG_MONO = 0, /* mono only. */
144 SST_HSW_CHANNEL_CONFIG_STEREO = 1, /* L & R. */
145 SST_HSW_CHANNEL_CONFIG_2_POINT_1 = 2, /* L, R & LFE; PCM only. */
146 SST_HSW_CHANNEL_CONFIG_3_POINT_0 = 3, /* L, C & R; MP3 & AAC only. */
147 SST_HSW_CHANNEL_CONFIG_3_POINT_1 = 4, /* L, C, R & LFE; PCM only. */
148 SST_HSW_CHANNEL_CONFIG_QUATRO = 5, /* L, R, Ls & Rs; PCM only. */
149 SST_HSW_CHANNEL_CONFIG_4_POINT_0 = 6, /* L, C, R & Cs; MP3 & AAC only. */
150 SST_HSW_CHANNEL_CONFIG_5_POINT_0 = 7, /* L, C, R, Ls & Rs. */
151 SST_HSW_CHANNEL_CONFIG_5_POINT_1 = 8, /* L, C, R, Ls, Rs & LFE. */
152 SST_HSW_CHANNEL_CONFIG_DUAL_MONO = 9, /* One channel replicated in two. */
153 SST_HSW_CHANNEL_CONFIG_INVALID,
154};
155
156/* List of supported bit depths. */
157enum sst_hsw_bitdepth {
158 SST_HSW_DEPTH_8BIT = 8,
159 SST_HSW_DEPTH_16BIT = 16,
160 SST_HSW_DEPTH_24BIT = 24, /* Default. */
161 SST_HSW_DEPTH_32BIT = 32,
162 SST_HSW_DEPTH_INVALID = 33,
163};
164
165enum sst_hsw_module_id {
166 SST_HSW_MODULE_BASE_FW = 0x0,
167 SST_HSW_MODULE_MP3 = 0x1,
168 SST_HSW_MODULE_AAC_5_1 = 0x2,
169 SST_HSW_MODULE_AAC_2_0 = 0x3,
170 SST_HSW_MODULE_SRC = 0x4,
171 SST_HSW_MODULE_WAVES = 0x5,
172 SST_HSW_MODULE_DOLBY = 0x6,
173 SST_HSW_MODULE_BOOST = 0x7,
174 SST_HSW_MODULE_LPAL = 0x8,
175 SST_HSW_MODULE_DTS = 0x9,
176 SST_HSW_MODULE_PCM_CAPTURE = 0xA,
177 SST_HSW_MODULE_PCM_SYSTEM = 0xB,
178 SST_HSW_MODULE_PCM_REFERENCE = 0xC,
179 SST_HSW_MODULE_PCM = 0xD,
180 SST_HSW_MODULE_BLUETOOTH_RENDER_MODULE = 0xE,
181 SST_HSW_MODULE_BLUETOOTH_CAPTURE_MODULE = 0xF,
182 SST_HSW_MAX_MODULE_ID,
183};
184
185enum sst_hsw_performance_action {
186 SST_HSW_PERF_START = 0,
187 SST_HSW_PERF_STOP = 1,
188};
189
190/* SST firmware module info */
191struct sst_hsw_module_info {
192 u8 name[SST_HSW_MAX_INFO_SIZE];
193 u8 version[SST_HSW_MAX_INFO_SIZE];
194} __attribute__((packed));
195
196/* Module entry point */
197struct sst_hsw_module_entry {
198 enum sst_hsw_module_id module_id;
199 u32 entry_point;
200} __attribute__((packed));
201
202/* Module map - alignement matches DSP */
203struct sst_hsw_module_map {
204 u8 module_entries_count;
205 struct sst_hsw_module_entry module_entries[1];
206} __attribute__((packed));
207
208struct sst_hsw_memory_info {
209 u32 offset;
210 u32 size;
211} __attribute__((packed));
212
213struct sst_hsw_fx_enable {
214 struct sst_hsw_module_map module_map;
215 struct sst_hsw_memory_info persistent_mem;
216} __attribute__((packed));
217
Lu, Hane8e79ed2015-03-10 10:41:22 +0800218struct sst_hsw_ipc_module_config {
219 struct sst_hsw_module_map map;
220 struct sst_hsw_memory_info persistent_mem;
221 struct sst_hsw_memory_info scratch_mem;
222} __attribute__((packed));
223
Mark Browna4b12992014-03-12 23:04:35 +0000224struct sst_hsw_get_fx_param {
225 u32 parameter_id;
226 u32 param_size;
227} __attribute__((packed));
228
229struct sst_hsw_perf_action {
230 u32 action;
231} __attribute__((packed));
232
233struct sst_hsw_perf_data {
234 u64 timestamp;
235 u64 cycles;
236 u64 datatime;
237} __attribute__((packed));
238
239/* FW version */
240struct sst_hsw_ipc_fw_version {
241 u8 build;
242 u8 minor;
243 u8 major;
244 u8 type;
245 u8 fw_build_hash[SST_HSW_BUILD_HASH_LENGTH];
246 u32 fw_log_providers_hash;
247} __attribute__((packed));
248
249/* Stream ring info */
250struct sst_hsw_ipc_stream_ring {
251 u32 ring_pt_address;
252 u32 num_pages;
253 u32 ring_size;
254 u32 ring_offset;
255 u32 ring_first_pfn;
256} __attribute__((packed));
257
258/* Debug Dump Log Enable Request */
259struct sst_hsw_ipc_debug_log_enable_req {
260 struct sst_hsw_ipc_stream_ring ringinfo;
261 u32 config[SST_HSW_FW_LOG_CONFIG_DWORDS];
262} __attribute__((packed));
263
264/* Debug Dump Log Reply */
265struct sst_hsw_ipc_debug_log_reply {
266 u32 log_buffer_begining;
267 u32 log_buffer_size;
268} __attribute__((packed));
269
270/* Stream glitch position */
271struct sst_hsw_ipc_stream_glitch_position {
272 u32 glitch_type;
273 u32 present_pos;
274 u32 write_pos;
275} __attribute__((packed));
276
277/* Stream get position */
278struct sst_hsw_ipc_stream_get_position {
279 u32 position;
280 u32 fw_cycle_count;
281} __attribute__((packed));
282
283/* Stream set position */
284struct sst_hsw_ipc_stream_set_position {
285 u32 position;
286 u32 end_of_buffer;
287} __attribute__((packed));
288
289/* Stream Free Request */
290struct sst_hsw_ipc_stream_free_req {
291 u8 stream_id;
292 u8 reserved[3];
293} __attribute__((packed));
294
295/* Set Volume Request */
296struct sst_hsw_ipc_volume_req {
297 u32 channel;
298 u32 target_volume;
299 u64 curve_duration;
300 u32 curve_type;
301} __attribute__((packed));
302
303/* Device Configuration Request */
304struct sst_hsw_ipc_device_config_req {
305 u32 ssp_interface;
306 u32 clock_frequency;
307 u32 mode;
308 u16 clock_divider;
Liam Girdwoodf07e51c2014-10-16 15:29:15 +0100309 u8 channels;
310 u8 reserved;
Mark Browna4b12992014-03-12 23:04:35 +0000311} __attribute__((packed));
312
313/* Audio Data formats */
314struct sst_hsw_audio_data_format_ipc {
315 u32 frequency;
316 u32 bitdepth;
317 u32 map;
318 u32 config;
319 u32 style;
320 u8 ch_num;
321 u8 valid_bit;
322 u8 reserved[2];
323} __attribute__((packed));
324
325/* Stream Allocate Request */
326struct sst_hsw_ipc_stream_alloc_req {
327 u8 path_id;
328 u8 stream_type;
329 u8 format_id;
330 u8 reserved;
331 struct sst_hsw_audio_data_format_ipc format;
332 struct sst_hsw_ipc_stream_ring ringinfo;
333 struct sst_hsw_module_map map;
334 struct sst_hsw_memory_info persistent_mem;
335 struct sst_hsw_memory_info scratch_mem;
336 u32 number_of_notifications;
337} __attribute__((packed));
338
339/* Stream Allocate Reply */
340struct sst_hsw_ipc_stream_alloc_reply {
341 u32 stream_hw_id;
342 u32 mixer_hw_id; // returns rate ????
343 u32 read_position_register_address;
344 u32 presentation_position_register_address;
345 u32 peak_meter_register_address[SST_HSW_NO_CHANNELS];
346 u32 volume_register_address[SST_HSW_NO_CHANNELS];
347} __attribute__((packed));
348
349/* Get Mixer Stream Info */
350struct sst_hsw_ipc_stream_info_reply {
351 u32 mixer_hw_id;
352 u32 peak_meter_register_address[SST_HSW_NO_CHANNELS];
353 u32 volume_register_address[SST_HSW_NO_CHANNELS];
354} __attribute__((packed));
355
356/* DX State Request */
357struct sst_hsw_ipc_dx_req {
358 u8 state;
359 u8 reserved[3];
360} __attribute__((packed));
361
362/* DX State Reply Memory Info Item */
363struct sst_hsw_ipc_dx_memory_item {
364 u32 offset;
365 u32 size;
366 u32 source;
367} __attribute__((packed));
368
369/* DX State Reply */
370struct sst_hsw_ipc_dx_reply {
371 u32 entries_no;
372 struct sst_hsw_ipc_dx_memory_item mem_info[SST_HSW_MAX_DX_REGIONS];
373} __attribute__((packed));
374
375struct sst_hsw_ipc_fw_version;
376
377/* SST Init & Free */
378struct sst_hsw *sst_hsw_new(struct device *dev, const u8 *fw, size_t fw_length,
379 u32 fw_offset);
380void sst_hsw_free(struct sst_hsw *hsw);
381int sst_hsw_fw_get_version(struct sst_hsw *hsw,
382 struct sst_hsw_ipc_fw_version *version);
383u32 create_channel_map(enum sst_hsw_channel_config config);
384
385/* Stream Mixer Controls - */
Mark Browna4b12992014-03-12 23:04:35 +0000386int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
387 struct sst_hsw_stream *stream, u32 stage_id, u32 channel, u32 volume);
388int sst_hsw_stream_get_volume(struct sst_hsw *hsw,
389 struct sst_hsw_stream *stream, u32 stage_id, u32 channel, u32 *volume);
390
Mark Browna4b12992014-03-12 23:04:35 +0000391/* Global Mixer Controls - */
Mark Browna4b12992014-03-12 23:04:35 +0000392int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
393 u32 volume);
394int sst_hsw_mixer_get_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
395 u32 *volume);
396
Mark Browna4b12992014-03-12 23:04:35 +0000397/* Stream API */
398struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id,
399 u32 (*get_write_position)(struct sst_hsw_stream *stream, void *data),
400 void *data);
401
402int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
403
404/* Stream Configuration */
405int sst_hsw_stream_format(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
406 enum sst_hsw_stream_path_id path_id,
407 enum sst_hsw_stream_type stream_type,
408 enum sst_hsw_stream_format format_id);
409
410int sst_hsw_stream_buffer(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
411 u32 ring_pt_address, u32 num_pages,
412 u32 ring_size, u32 ring_offset, u32 ring_first_pfn);
413
414int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
415
416int sst_hsw_stream_set_valid(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
417 u32 bits);
418int sst_hsw_stream_set_rate(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
419 int rate);
420int sst_hsw_stream_set_bits(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
421 enum sst_hsw_bitdepth bits);
422int sst_hsw_stream_set_channels(struct sst_hsw *hsw,
423 struct sst_hsw_stream *stream, int channels);
424int sst_hsw_stream_set_map_config(struct sst_hsw *hsw,
425 struct sst_hsw_stream *stream, u32 map,
426 enum sst_hsw_channel_config config);
427int sst_hsw_stream_set_style(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
428 enum sst_hsw_interleaving style);
429int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
Liam Girdwoode9600bc2014-10-28 17:37:12 +0000430 struct sst_hsw_stream *stream, struct sst_module_runtime *runtime);
Mark Browna4b12992014-03-12 23:04:35 +0000431int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw,
432 struct sst_hsw_stream *stream, u32 offset, u32 size);
433int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw,
434 struct sst_hsw_stream *stream, u32 offset, u32 size);
Libin Yang1b006992015-02-10 10:02:47 +0800435snd_pcm_uframes_t sst_hsw_stream_get_old_position(struct sst_hsw *hsw,
436 struct sst_hsw_stream *stream);
437void sst_hsw_stream_set_old_position(struct sst_hsw *hsw,
438 struct sst_hsw_stream *stream, snd_pcm_uframes_t val);
439bool sst_hsw_stream_get_silence_start(struct sst_hsw *hsw,
440 struct sst_hsw_stream *stream);
441void sst_hsw_stream_set_silence_start(struct sst_hsw *hsw,
442 struct sst_hsw_stream *stream, bool val);
Mark Browna4b12992014-03-12 23:04:35 +0000443int sst_hsw_mixer_get_info(struct sst_hsw *hsw);
444
445/* Stream ALSA trigger operations */
446int sst_hsw_stream_pause(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
447 int wait);
448int sst_hsw_stream_resume(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
449 int wait);
450int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
451
452/* Stream pointer positions */
453int sst_hsw_stream_get_read_pos(struct sst_hsw *hsw,
454 struct sst_hsw_stream *stream, u32 *position);
455int sst_hsw_stream_get_write_pos(struct sst_hsw *hsw,
456 struct sst_hsw_stream *stream, u32 *position);
Liam Girdwood51b4e242014-05-02 16:56:33 +0100457u32 sst_hsw_get_dsp_position(struct sst_hsw *hsw,
458 struct sst_hsw_stream *stream);
459u64 sst_hsw_get_dsp_presentation_position(struct sst_hsw *hsw,
Mark Browna4b12992014-03-12 23:04:35 +0000460 struct sst_hsw_stream *stream);
461
462/* HW port config */
463int sst_hsw_device_set_config(struct sst_hsw *hsw,
464 enum sst_hsw_device_id dev, enum sst_hsw_device_mclk mclk,
465 enum sst_hsw_device_mode mode, u32 clock_divider);
466
467/* DX Config */
468int sst_hsw_dx_set_state(struct sst_hsw *hsw,
469 enum sst_hsw_dx_state state, struct sst_hsw_ipc_dx_reply *dx);
Mark Browna4b12992014-03-12 23:04:35 +0000470
471/* init */
472int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata);
473void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata);
474struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw);
Liam Girdwoode9600bc2014-10-28 17:37:12 +0000475
Lu, Han9449d392015-03-10 10:41:20 +0800476/* fw module function */
477void sst_hsw_init_module_state(struct sst_hsw *hsw);
Lu, Han8c43fc22015-03-10 10:41:21 +0800478bool sst_hsw_is_module_loaded(struct sst_hsw *hsw, u32 module_id);
Lu, Hane8e79ed2015-03-10 10:41:22 +0800479bool sst_hsw_is_module_active(struct sst_hsw *hsw, u32 module_id);
Lu, Han9449d392015-03-10 10:41:20 +0800480
481int sst_hsw_module_load(struct sst_hsw *hsw,
482 u32 module_id, u32 instance_id, char *name);
Lu, Hane8e79ed2015-03-10 10:41:22 +0800483int sst_hsw_module_enable(struct sst_hsw *hsw,
484 u32 module_id, u32 instance_id);
485int sst_hsw_module_disable(struct sst_hsw *hsw,
486 u32 module_id, u32 instance_id);
Lu, Han9449d392015-03-10 10:41:20 +0800487
Liam Girdwoode9600bc2014-10-28 17:37:12 +0000488/* runtime module management */
489struct sst_module_runtime *sst_hsw_runtime_module_create(struct sst_hsw *hsw,
490 int mod_id, int offset);
491void sst_hsw_runtime_module_free(struct sst_module_runtime *runtime);
Mark Browna4b12992014-03-12 23:04:35 +0000492
Liam Girdwoodaed3c7b2014-10-29 17:40:42 +0000493/* PM */
494int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw);
495int sst_hsw_dsp_runtime_suspend(struct sst_hsw *hsw);
496int sst_hsw_dsp_load(struct sst_hsw *hsw);
497int sst_hsw_dsp_runtime_sleep(struct sst_hsw *hsw);
498
Mark Browna4b12992014-03-12 23:04:35 +0000499#endif