forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdai-legacy.h
More file actions
589 lines (494 loc) · 14.2 KB
/
dai-legacy.h
File metadata and controls
589 lines (494 loc) · 14.2 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2016 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
* Keyon Jie <yang.jie@linux.intel.com>
*
* Renamed from dai.h to dai-legacy.h because of Zephyr refactoring and
* the file content has not changed.
*/
/**
* \cond XTOS_DUP_FIXME
*
* \file include/sof/lib/dai.h
* \brief DAI Drivers definition
* \author Liam Girdwood <liam.r.girdwood@linux.intel.com>
* \author Keyon Jie <yang.jie@linux.intel.com>
*/
#ifndef __SOF_LIB_DAI_LEGACY_H__
#define __SOF_LIB_DAI_LEGACY_H__
#include <platform/lib/dai.h>
#include <rtos/bit.h>
#include <sof/list.h>
#include <sof/lib/io.h>
#include <sof/lib/memory.h>
#include <sof/lib/dma.h>
#include <sof/list.h>
#include <rtos/sof.h>
#include <rtos/spinlock.h>
#include <sof/trace/trace.h>
#include <sof/ipc/topology.h>
#include <sof/audio/pcm_converter.h>
#include <sof/audio/ipc-config.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
struct dai;
struct sof_ipc_stream_params;
/** \addtogroup sof_dai_drivers DAI Drivers
* DAI Drivers API specification.
* @{
*/
#define DAI_CLOCK_IN 0
#define DAI_CLOCK_OUT 1
#define DAI_DIR_PLAYBACK 0
#define DAI_DIR_CAPTURE 1
#define DAI_NUM_SLOT_MAPS 8
#define DAI_INFO_TYPE 0
#define DAI_INFO_DMA_CAPS 1
#define DAI_INFO_DMA_DEV 2
/* DAI flags */
/** \brief IRQ used for copy() timer */
#define DAI_FLAGS_IRQ_CB BIT(0)
/* DAI get() flags */
/** \brief If the device does not exist it will be created */
#define DAI_CREAT BIT(0)
/**
* \brief DAI operations - all optional
*
* DAI drivers may allocate private data,
* which can be set with 'dai_set_drvdata' and retrieved with 'dai_get_drvdata'.
* If a single DAI instance can have multiple DMA links and/or there is
* some other possibility of the same instance being used in multiple
* contexts at the same time, the private data should be allocated in the
* SOF_MEM_ZONE_SHARED.
*/
struct dai_ops {
int (*set_config)(struct dai *dai, struct ipc_config_dai *config,
const void *spec_config);
int (*trigger)(struct dai *dai, int cmd, int direction);
int (*get_hw_params)(struct dai *dai,
struct sof_ipc_stream_params *params, int dir);
int (*hw_params)(struct dai *dai, struct sof_ipc_stream_params *params);
int (*get_handshake)(struct dai *dai, int direction, int stream_id);
int (*get_fifo)(struct dai *dai, int direction, int stream_id);
int (*probe)(struct dai *dai);
int (*remove)(struct dai *dai);
uint32_t (*get_init_delay_ms)(struct dai *dai);
int (*get_fifo_depth)(struct dai *dai, int direction);
void (*copy)(struct dai *dai); /* Can be used by DAIs to prepare for data copying */
};
struct timestamp_cfg {
uint32_t walclk_rate; /* Rate in Hz, e.g. 19200000 */
int type; /* SSP, DMIC, HDA, etc. */
int direction; /* Playback, capture */
int index; /* For SSPx to select correct timestamp register */
int dma_id; /* GPDMA id*/
int dma_chan_index; /* Used GPDMA channel */
int dma_chan_count; /* Channels in single GPDMA */
};
struct timestamp_data {
uint64_t walclk; /* Wall clock */
uint64_t sample; /* Sample count */
uint32_t walclk_rate; /* Rate in Hz, e.g. 19200000 */
};
struct timestamp_ops {
int (*ts_config)(struct dai *dai, struct timestamp_cfg *cfg);
int (*ts_start)(struct dai *dai, struct timestamp_cfg *cfg);
int (*ts_stop)(struct dai *dai, struct timestamp_cfg *cfg);
int (*ts_get)(struct dai *dai, struct timestamp_cfg *cfg,
struct timestamp_data *tsd);
};
struct dai_driver {
uint32_t type; /**< type, one of SOF_DAI_... */
const struct sof_uuid_entry *uid;
struct tr_ctx *tctx;
uint32_t dma_caps;
uint32_t dma_dev;
struct dai_ops ops;
struct timestamp_ops ts_ops;
};
/**
* \brief DAI slot map to audio channel
*/
struct dai_slot_map {
uint32_t channel; /**< channel ID - CHAN_ID_ */
uint32_t slot; /**< physical slot index */
};
struct dai_plat_fifo_data {
uint32_t offset;
uint32_t width;
uint32_t depth;
uint32_t watermark;
uint32_t handshake;
};
/**
* \brief DAI platform data
*/
struct dai_plat_data {
uint32_t base;
int irq;
const char *irq_name;
uint32_t flags;
struct dai_plat_fifo_data fifo[2];
};
/**
* \brief llp slot info for memory window
*/
struct llp_slot_info {
uint32_t node_id;
uint32_t reg_offset;
};
/**
* \brief DAI runtime data
*/
struct dai_data {
/* local DMA config */
struct dma_chan_data *chan;
uint32_t stream_id;
struct dma_sg_config config;
struct comp_dev *dai_dev;
struct comp_buffer *dma_buffer;
struct comp_buffer *local_buffer;
struct timestamp_cfg ts_config;
struct dai *dai;
struct dma *dma;
struct dai_group *group; /* NULL if no group assigned */
int xrun; /* true if we are doing xrun recovery */
pcm_converter_func process; /* processing function */
uint32_t period_bytes; /* number of bytes per one period */
uint64_t total_data_processed;
struct ipc_config_dai ipc_config; /* generic common config */
void *dai_spec_config; /* dai specific config from the host */
uint64_t wallclock; /* wall clock at stream start */
/*
* flag indicating two-step stop/pause for DAI comp and DAI DMA.
* DAI stop occurs during STREAM_TRIG_STOP IPC and DMA stop during DAI_CONFIG IPC with
* the SOF_DAI_CONFIG_FLAGS_HW_FREE flag.
* DAI pause occurs during STREAM_TRIG_PAUSE IPC and DMA pause during DAI_CONFIG IPC with
* the SOF_DAI_CONFIG_FLAGS_PAUSE flag.
*/
bool delayed_dma_stop;
/* llp slot info in memory windows */
struct llp_slot_info slot_info;
};
struct dai {
uint32_t index; /**< index */
struct k_spinlock lock; /**< locking mechanism */
int sref; /**< simple ref counter, guarded by lock */
struct dai_plat_data plat_data;
const struct dai_driver *drv;
const struct dai_data *dd;
void *priv_data;
};
/**
* \brief Array of DAIs grouped by type.
*/
struct dai_type_info {
uint32_t type; /**< Type */
struct dai *dai_array; /**< Array of DAIs */
size_t num_dais; /**< Number of elements in dai_array */
};
/* dai tracing */
#define trace_dai_drv_get_tr_ctx(drv_p) ((drv_p)->tctx)
#define trace_dai_drv_get_id(drv_p) (-1)
#define trace_dai_drv_get_subid(drv_p) (-1)
#define trace_dai_get_tr_ctx(dai_p) ((dai_p)->drv->tctx)
#define trace_dai_get_id(dai_p) ((dai_p)->drv->type)
#define trace_dai_get_subid(dai_p) ((dai_p)->index)
#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG)
/* driver level tracing */
#define dai_cl_err(drv_p, __e, ...) LOG_ERR(__e, ##__VA_ARGS__)
#define dai_cl_warn(drv_p, __e, ...) LOG_WRN(__e, ##__VA_ARGS__)
#define dai_cl_info(drv_p, __e, ...) LOG_INF(__e, ##__VA_ARGS__)
#define dai_cl_dbg(drv_p, __e, ...) LOG_DBG(__e, ##__VA_ARGS__)
/* device level tracing */
#define dai_err(dai_p, __e, ...) LOG_ERR(__e, ##__VA_ARGS__)
#define dai_warn(dai_p, __e, ...) LOG_WRN(__e, ##__VA_ARGS__)
#define dai_info(dai_p, __e, ...) LOG_INF(__e, ##__VA_ARGS__)
#define dai_dbg(dai_p, __e, ...) LOG_DBG(__e, ##__VA_ARGS__)
#else
/* class (driver) level (no device object) tracing */
#define dai_cl_err(drv_p, __e, ...) \
trace_dev_err(trace_dai_dvr_get_tr_ctx, \
trace_dai_drv_get_id, \
trace_dai_drv_get_subid, \
drv_p, __e, ##__VA_ARGS__)
#define dai_cl_warn(drv_p, __e, ...) \
trace_dev_warn(trace_dai_drv_get_tr_ctx,\
trace_dai_drv_get_id, \
trace_dai_drv_get_subid, \
drv_p, __e, ##__VA_ARGS__)
#define dai_cl_info(drv_p, __e, ...) \
trace_dev_info(trace_dai_drv_get_tr_ctx,\
trace_dai_drv_get_id, \
trace_dai_drv_get_subid, \
drv_p, __e, ##__VA_ARGS__)
#define dai_cl_dbg(drv_p, __e, ...) \
trace_dev_dbg(trace_dai_drv_get_tr_ctx, \
trace_dai_drv_get_id, \
trace_dai_drv_get_subid, \
drv_p, __e, ##__VA_ARGS__)
/* device tracing */
#define dai_err(dai_p, __e, ...) \
trace_dev_err(trace_dai_get_tr_ctx, \
trace_dai_get_id, \
trace_dai_get_subid, dai_p, __e, ##__VA_ARGS__)
#define dai_warn(dai_p, __e, ...) \
trace_dev_warn(trace_dai_get_tr_ctx, \
trace_dai_get_id, \
trace_dai_get_subid, dai_p, __e, ##__VA_ARGS__)
#define dai_info(dai_p, __e, ...) \
trace_dev_info(trace_dai_get_tr_ctx, \
trace_dai_get_id, \
trace_dai_get_subid, dai_p, __e, ##__VA_ARGS__)
#define dai_dbg(dai_p, __e, ...) \
trace_dev_dbg(trace_dai_get_tr_ctx, \
trace_dai_get_id, \
trace_dai_get_subid, dai_p, __e, ##__VA_ARGS__)
#endif /* #if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) */
/**
* \brief API to request DAI group
*
* Returns a DAI group for the given ID and
* increments the counter of DAIs in the group.
*
* If a group for the given ID doesn't exist,
* it will either return NULL or allocate a new group structure
* if the CREATE flag is supplied.
*
* \param[in] group_id Group ID
* \param[in] flags Flags (CREATE)
*/
struct dai_group *dai_group_get(uint32_t group_id, uint32_t flags);
/**
* \brief API to release DAI group
*
* Decrements the DAI counter inside the group.
*
* \param[in] group Group
*/
void dai_group_put(struct dai_group *group);
/**
* \brief DAI group information
*/
struct dai_group {
/**
* Group ID
*/
uint32_t group_id;
/**
* Number of DAIs in this group
*/
uint32_t num_dais;
/**
* Number of DAIs to receive a trigger before processing begins
*/
uint32_t trigger_counter;
/**
* Trigger command to propagate
*/
int trigger_cmd;
/**
* Last trigger error
*/
int trigger_ret;
/**
* Group list
*/
struct list_item list;
};
/**
* \brief Holds information about array of DAIs grouped by type.
*/
struct dai_info {
const struct dai_type_info *dai_type_array;
size_t num_dai_types;
};
/**
* \brief API to initialize a platform DAI.
*
* \param[in] sof Pointer to firmware main context.
*/
int dai_init(struct sof *sof);
/**
* \brief API to request a platform DAI.
*
* \param[in] type Type of requested DAI.
* \param[in] index Index of requested DAI.
* \param[in] flags Flags (CREATE)
*/
struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags);
/**
* \brief API to release a platform DAI.
*
* @param[in] dai DAI to relese.
*/
void dai_put(struct dai *dai);
#define dai_set_drvdata(dai, data) \
(dai->priv_data = data)
#define dai_get_drvdata(dai) \
dai->priv_data
#define dai_base(dai) \
dai->plat_data.base
#define dai_irq(dai) \
dai->plat_data.irq
#define dai_fifo(dai, direction) \
dai->plat_data.fifo[direction].offset
/**
* \brief Digital Audio interface formatting
*/
static inline int dai_set_config(struct dai *dai, struct ipc_config_dai *config,
const void *spec_config)
{
return dai->drv->ops.set_config(dai, config, spec_config);
}
/**
* \brief Digital Audio interface trigger
*/
static inline int dai_trigger(struct dai *dai, int cmd, int direction)
{
return dai->drv->ops.trigger(dai, cmd, direction);
}
/**
* \brief Get Digital Audio interface stream parameters
*/
static inline int dai_get_hw_params(struct dai *dai,
struct sof_ipc_stream_params *params,
int dir)
{
return dai->drv->ops.get_hw_params(dai, params, dir);
}
/**
* \brief Configure Digital Audio interface stream parameters
*/
static inline int dai_hw_params(struct dai *dai,
struct sof_ipc_stream_params *params)
{
if (dai->drv->ops.hw_params)
return dai->drv->ops.hw_params(dai, params);
return 0;
}
/**
* \brief Get Digital Audio interface DMA Handshake
*/
static inline int dai_get_handshake(struct dai *dai, int direction,
int stream_id)
{
return dai->drv->ops.get_handshake(dai, direction, stream_id);
}
/**
* \brief Get Digital Audio interface FIFO address
*/
static inline int dai_get_fifo(struct dai *dai, int direction,
int stream_id)
{
return dai->drv->ops.get_fifo(dai, direction, stream_id);
}
/**
* \brief Digital Audio interface Probe
*/
static inline int dai_probe(struct dai *dai)
{
return dai->drv->ops.probe(dai);
}
/**
* \brief Digital Audio interface Remove
*/
static inline int dai_remove(struct dai *dai)
{
return dai->drv->ops.remove(dai);
}
/**
* \brief Get DAI initial delay in milliseconds
*/
static inline uint32_t dai_get_init_delay_ms(struct dai *dai)
{
if (dai && dai->drv->ops.get_init_delay_ms)
return dai->drv->ops.get_init_delay_ms(dai);
return 0;
}
static inline int dai_get_fifo_depth(struct dai *dai, int direction)
{
if (dai && dai->drv->ops.get_fifo_depth)
return dai->drv->ops.get_fifo_depth(dai, direction);
return 0;
}
/**
* \brief Get driver specific DAI information
*/
static inline int dai_get_info(struct dai *dai, int info)
{
int ret;
switch (info) {
case DAI_INFO_TYPE:
ret = dai->drv->type;
break;
case DAI_INFO_DMA_CAPS:
ret = dai->drv->dma_caps;
break;
case DAI_INFO_DMA_DEV:
ret = dai->drv->dma_dev;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static inline void dai_write(struct dai *dai, uint32_t reg, uint32_t value)
{
io_reg_write(dai_base(dai) + reg, value);
}
static inline uint32_t dai_read(struct dai *dai, uint32_t reg)
{
return io_reg_read(dai_base(dai) + reg);
}
static inline void dai_update_bits(struct dai *dai, uint32_t reg,
uint32_t mask, uint32_t value)
{
io_reg_update_bits(dai_base(dai) + reg, mask, value);
}
static inline const struct dai_info *dai_info_get(void)
{
return sof_get()->dai_info;
}
/**
* \brief Configure DMA channel for DAI
*/
int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void *config);
/**
* \brief Configure HD Audio DMA params for DAI
*/
void dai_set_link_hda_config(uint16_t *link_config,
struct ipc_config_dai *common_config,
const void *spec_config);
/**
* \brief Reset DAI DMA config
*/
void dai_dma_release(struct dai_data *dd, struct comp_dev *dev);
/**
* \brief Configure DAI physical interface.
*/
int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai *common_config,
const void *spec_config);
/**
* \brief Assign DAI to a group for simultaneous triggering.
*/
int dai_assign_group(struct dai_data *dd, struct comp_dev *dev, uint32_t group_id);
/**
* \brief dai position for host driver.
*/
int dai_position(struct comp_dev *dev, struct sof_ipc_stream_posn *posn);
/**
* \brief update dai dma position for host driver.
*/
void dai_dma_position_update(struct dai_data *dd, struct comp_dev *dev);
/**
* \brief release llp slot
*/
void dai_release_llp_slot(struct dai_data *dd);
/** @}*/
#endif /* __SOF_LIB_DAI_LEGACY_H__ */
/** \endcond */