Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dai.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_DAI_H_
13#define ZEPHYR_INCLUDE_DRIVERS_DAI_H_
14
29#include <errno.h>
30
31#include <zephyr/types.h>
32#include <zephyr/device.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
39#define DAI_FORMAT_CLOCK_PROVIDER_MASK 0xf000
41#define DAI_FORMAT_PROTOCOL_MASK 0x000f
43#define DAI_FORMAT_CLOCK_INVERSION_MASK 0x0f00
44
53 DAI_CBP_CFP = (0 << 12),
55 DAI_CBC_CFP = (2 << 12),
57 DAI_CBP_CFC = (3 << 12),
59 DAI_CBC_CFC = (4 << 12),
60};
61
74};
75
86 DAI_INVERSION_NB_IF = (2 << 8),
88 DAI_INVERSION_IB_NF = (3 << 8),
91};
92
118};
119
130};
131
153};
154
227};
228
246};
247
271};
272
280 int type;
284 int index;
291};
292
303};
304
310__subsystem struct dai_driver_api {
311 int (*probe)(const struct device *dev);
312 int (*remove)(const struct device *dev);
313 int (*config_set)(const struct device *dev, const struct dai_config *cfg,
314 const void *bespoke_cfg);
315 int (*config_get)(const struct device *dev, struct dai_config *cfg,
316 enum dai_dir dir);
317
318 const struct dai_properties *(*get_properties)(const struct device *dev,
319 enum dai_dir dir,
320 int stream_id);
321
322 int (*trigger)(const struct device *dev, enum dai_dir dir,
323 enum dai_trigger_cmd cmd);
324
325 /* optional methods */
326 int (*ts_config)(const struct device *dev, struct dai_ts_cfg *cfg);
327 int (*ts_start)(const struct device *dev, struct dai_ts_cfg *cfg);
328 int (*ts_stop)(const struct device *dev, struct dai_ts_cfg *cfg);
329 int (*ts_get)(const struct device *dev, struct dai_ts_cfg *cfg,
330 struct dai_ts_data *tsd);
331};
332
348static inline int dai_probe(const struct device *dev)
349{
350 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
351
352 return api->probe(dev);
353}
354
365static inline int dai_remove(const struct device *dev)
366{
367 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
368
369 return api->remove(dev);
370}
371
392static inline int dai_config_set(const struct device *dev,
393 const struct dai_config *cfg,
394 const void *bespoke_cfg)
395{
396 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
397
398 return api->config_set(dev, cfg, bespoke_cfg);
399}
400
409static inline int dai_config_get(const struct device *dev,
410 struct dai_config *cfg,
411 enum dai_dir dir)
412{
413 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
414
415 return api->config_get(dev, cfg, dir);
416}
417
428static inline const struct dai_properties *dai_get_properties(const struct device *dev,
429 enum dai_dir dir,
430 int stream_id)
431{
432 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
433
434 return api->get_properties(dev, dir, stream_id);
435}
436
454static inline int dai_trigger(const struct device *dev,
455 enum dai_dir dir,
456 enum dai_trigger_cmd cmd)
457{
458 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
459
460 return api->trigger(dev, dir, cmd);
461}
462
472static inline int dai_ts_config(const struct device *dev, struct dai_ts_cfg *cfg)
473{
474 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
475
476 if (!api->ts_config)
477 return -EINVAL;
478
479 return api->ts_config(dev, cfg);
480}
481
491static inline int dai_ts_start(const struct device *dev, struct dai_ts_cfg *cfg)
492{
493 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
494
495 if (!api->ts_start)
496 return -EINVAL;
497
498 return api->ts_start(dev, cfg);
499}
500
510static inline int dai_ts_stop(const struct device *dev, struct dai_ts_cfg *cfg)
511{
512 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
513
514 if (!api->ts_stop)
515 return -EINVAL;
516
517 return api->ts_stop(dev, cfg);
518}
519
530static inline int dai_ts_get(const struct device *dev, struct dai_ts_cfg *cfg,
531 struct dai_ts_data *tsd)
532{
533 const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;
534
535 if (!api->ts_get)
536 return -EINVAL;
537
538 return api->ts_get(dev, cfg, tsd);
539}
540
545#ifdef __cplusplus
546}
547#endif
548
549#endif /* ZEPHYR_INCLUDE_DRIVERS_DAI_H_ */
System error numbers.
static int dai_config_set(const struct device *dev, const struct dai_config *cfg, const void *bespoke_cfg)
Configure operation of a DAI driver.
Definition: dai.h:392
dai_state
Interface state.
Definition: dai.h:133
static int dai_ts_start(const struct device *dev, struct dai_ts_cfg *cfg)
Starts timestamping.
Definition: dai.h:491
dai_protocol
DAI protocol.
Definition: dai.h:67
static int dai_probe(const struct device *dev)
Probe operation of DAI driver.
Definition: dai.h:348
dai_clock_provider
DAI clock configurations.
Definition: dai.h:51
static int dai_remove(const struct device *dev)
Remove operation of DAI driver.
Definition: dai.h:365
static int dai_ts_stop(const struct device *dev, struct dai_ts_cfg *cfg)
Stops timestamping.
Definition: dai.h:510
static int dai_config_get(const struct device *dev, struct dai_config *cfg, enum dai_dir dir)
Fetch configuration information of a DAI driver.
Definition: dai.h:409
static int dai_trigger(const struct device *dev, enum dai_dir dir, enum dai_trigger_cmd cmd)
Send a trigger command.
Definition: dai.h:454
static int dai_ts_config(const struct device *dev, struct dai_ts_cfg *cfg)
Configures timestamping in attached DAI.
Definition: dai.h:472
static const struct dai_properties * dai_get_properties(const struct device *dev, enum dai_dir dir, int stream_id)
Fetch properties of a DAI driver.
Definition: dai.h:428
dai_type
Types of DAI.
Definition: dai.h:102
dai_trigger_cmd
Trigger command.
Definition: dai.h:156
dai_clock_inversion
DAI clock inversion.
Definition: dai.h:82
static int dai_ts_get(const struct device *dev, struct dai_ts_cfg *cfg, struct dai_ts_data *tsd)
Gets timestamp.
Definition: dai.h:530
dai_dir
DAI Direction.
Definition: dai.h:123
@ DAI_STATE_READY
The interface is ready to receive / transmit data.
Definition: dai.h:142
@ DAI_STATE_PRE_RUNNING
The interface is clocking but not receiving / transmitting data.
Definition: dai.h:146
@ DAI_STATE_ERROR
TX buffer underrun or RX buffer overrun has occurred.
Definition: dai.h:152
@ DAI_STATE_NOT_READY
The interface is not ready.
Definition: dai.h:140
@ DAI_STATE_RUNNING
The interface is receiving / transmitting data.
Definition: dai.h:144
@ DAI_STATE_STOPPING
The interface is draining its transmit queue.
Definition: dai.h:150
@ DAI_STATE_PAUSED
The interface paused.
Definition: dai.h:148
@ DAI_PROTO_LEFT_J
Left Justified.
Definition: dai.h:70
@ DAI_PROTO_PDM
Pulse Density Modulation.
Definition: dai.h:73
@ DAI_PROTO_DSP_A
TDM, FSYNC asserted 1 BCLK early.
Definition: dai.h:71
@ DAI_PROTO_RIGHT_J
Right Justified.
Definition: dai.h:69
@ DAI_PROTO_I2S
I2S.
Definition: dai.h:68
@ DAI_PROTO_DSP_B
TDM, FSYNC asserted at the same time as MSB.
Definition: dai.h:72
@ DAI_CBP_CFP
codec BLCK provider, codec FSYNC provider
Definition: dai.h:53
@ DAI_CBP_CFC
codec BCLK consumer, codec FSYNC consumer
Definition: dai.h:57
@ DAI_CBC_CFC
Definition: dai.h:59
@ DAI_CBC_CFP
codec BCLK provider, codec FSYNC consumer
Definition: dai.h:55
@ DAI_INTEL_ALH
Intel ALH.
Definition: dai.h:107
@ DAI_INTEL_HDA
Intel HD/A.
Definition: dai.h:106
@ DAI_LEGACY_I2S
Legacy I2S compatible with i2s.h.
Definition: dai.h:103
@ DAI_INTEL_ALH_NHLT
nhlt Intel ALH
Definition: dai.h:117
@ DAI_INTEL_DMIC
Intel DMIC.
Definition: dai.h:105
@ DAI_AMD_DMIC
Amd DMIC.
Definition: dai.h:112
@ DAI_INTEL_DMIC_NHLT
nhlt ssp
Definition: dai.h:115
@ DAI_AMD_BT
Amd BT.
Definition: dai.h:110
@ DAI_IMX_ESAI
i.MX ESAI
Definition: dai.h:109
@ DAI_INTEL_SSP_NHLT
nhlt ssp
Definition: dai.h:114
@ DAI_INTEL_SSP
Intel SSP.
Definition: dai.h:104
@ DAI_IMX_SAI
i.MX SAI
Definition: dai.h:108
@ DAI_AMD_SP
Amd SP.
Definition: dai.h:111
@ DAI_MEDIATEK_AFE
Mtk AFE.
Definition: dai.h:113
@ DAI_INTEL_HDA_NHLT
nhlt Intel HD/A
Definition: dai.h:116
@ DAI_TRIGGER_DRAIN
Empty the transmit queue.
Definition: dai.h:202
@ DAI_TRIGGER_DROP
Discard the transmit / receive queue.
Definition: dai.h:209
@ DAI_TRIGGER_STOP
Stop the transmission / reception of data.
Definition: dai.h:179
@ DAI_TRIGGER_COPY
Copy.
Definition: dai.h:226
@ DAI_TRIGGER_START
Start the transmission / reception of data.
Definition: dai.h:163
@ DAI_TRIGGER_PRE_START
Optional - Pre Start the transmission / reception of data.
Definition: dai.h:169
@ DAI_TRIGGER_POST_STOP
Optional - Post Stop the transmission / reception of data.
Definition: dai.h:193
@ DAI_TRIGGER_PREPARE
Prepare the queues after underrun/overrun error has occurred.
Definition: dai.h:215
@ DAI_TRIGGER_PAUSE
Pause the transmission / reception of data.
Definition: dai.h:187
@ DAI_TRIGGER_RESET
Reset.
Definition: dai.h:221
@ DAI_INVERSION_NB_NF
no BCLK inversion, no FSYNC inversion
Definition: dai.h:84
@ DAI_INVERSION_IB_IF
Definition: dai.h:90
@ DAI_INVERSION_NB_IF
BCLK inversion, no FSYNC inversion.
Definition: dai.h:86
@ DAI_INVERSION_IB_NF
BCLK inversion, FSYNC inversion.
Definition: dai.h:88
@ DAI_DIR_RX
Receive data.
Definition: dai.h:127
@ DAI_DIR_BOTH
Both receive and transmit data.
Definition: dai.h:129
@ DAI_DIR_TX
Transmit data.
Definition: dai.h:125
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
#define EINVAL
Invalid argument.
Definition: errno.h:61
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Main DAI config structure.
Definition: dai.h:252
uint32_t rate
Frame clock (WS) frequency, sampling rate.
Definition: dai.h:260
uint16_t format
DAI specific data stream format.
Definition: dai.h:262
uint8_t channels
Number of audio channels, words in frame.
Definition: dai.h:258
uint8_t options
DAI specific configuration options.
Definition: dai.h:264
enum dai_type type
Type of the DAI.
Definition: dai.h:254
uint32_t dai_index
Index of the DAI.
Definition: dai.h:256
size_t block_size
Size of one RX/TX memory block (buffer) in bytes.
Definition: dai.h:268
uint16_t link_config
DAI specific link configuration.
Definition: dai.h:270
uint8_t word_size
Number of bits representing one data word.
Definition: dai.h:266
DAI properties.
Definition: dai.h:235
uint32_t dma_hs_id
DMA handshake id.
Definition: dai.h:241
uint32_t reg_init_delay
Delay for initializing registers.
Definition: dai.h:243
uint32_t fifo_address
Fifo hw address for e.g.
Definition: dai.h:237
uint32_t fifo_depth
Fifo depth.
Definition: dai.h:239
int stream_id
Stream ID.
Definition: dai.h:245
DAI timestamp configuration.
Definition: dai.h:276
int type
Type of the DAI (SSP, DMIC, HDA, etc.).
Definition: dai.h:280
int dma_chan_count
Number of channels in single DMA.
Definition: dai.h:290
int dma_chan_index
Used DMA channel index.
Definition: dai.h:288
int dma_id
DMA instance id.
Definition: dai.h:286
uint32_t walclk_rate
Rate in Hz, e.g.
Definition: dai.h:278
int direction
Direction (playback/capture)
Definition: dai.h:282
int index
Index for SSPx to select correct timestamp register.
Definition: dai.h:284
DAI timestamp data.
Definition: dai.h:296
uint64_t walclk
Wall clock.
Definition: dai.h:298
uint64_t sample
Sample count.
Definition: dai.h:300
uint32_t walclk_rate
Rate in Hz, e.g.
Definition: dai.h:302
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405