Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio: Fix the errors of dai timestamp ops #8192

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,11 @@ static int asrc_dai_stop_timestamp(struct comp_data *cd)
return -EINVAL;
}

static int asrc_dai_get_timestamp(struct comp_data *cd,
struct timestamp_data *tsd)
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
static int asrc_dai_get_timestamp(struct comp_data *cd, struct dai_ts_data *tsd)
#else
static int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd)
#endif
{
if (!cd->dai_dev)
return -EINVAL;
Expand Down Expand Up @@ -909,7 +912,11 @@ static int asrc_prepare(struct comp_dev *dev)

static int asrc_control_loop(struct comp_dev *dev, struct comp_data *cd)
{
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
struct dai_ts_data tsd;
#else
struct timestamp_data tsd;
#endif
int64_t tmp;
int32_t delta_sample;
int32_t delta_ts;
Expand Down
4 changes: 4 additions & 0 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,11 @@ static int copier_dai_ts_start_op(struct comp_dev *dev)
return dai_common_ts_start(dd, dev);
}

#if CONFIG_ZEPHYR_NATIVE_DRIVERS
static int copier_dai_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd)
#else
static int copier_dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd)
#endif
{
struct processing_module *mod = comp_get_drvdata(dev);
struct copier_data *cd = module_get_private_data(mod);
Expand Down
38 changes: 16 additions & 22 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ static int dai_copy(struct comp_dev *dev)
int dai_common_ts_config_op(struct dai_data *dd, struct comp_dev *dev)
{
struct ipc_config_dai *dai = &dd->ipc_config;
struct dai_ts_cfg cfg;
struct dai_ts_cfg *cfg = &dd->ts_config;

comp_dbg(dev, "dai_ts_config()");
if (!dd->chan) {
Expand All @@ -1679,26 +1679,26 @@ int dai_common_ts_config_op(struct dai_data *dd, struct comp_dev *dev)

switch (dai->type) {
case SOF_DAI_INTEL_SSP:
cfg.type = DAI_INTEL_SSP;
cfg->type = DAI_INTEL_SSP;
break;
case SOF_DAI_INTEL_ALH:
cfg.type = DAI_INTEL_ALH;
cfg->type = DAI_INTEL_ALH;
break;
case SOF_DAI_INTEL_DMIC:
cfg.type = DAI_INTEL_DMIC;
cfg->type = DAI_INTEL_DMIC;
break;
default:
comp_err(dev, "dai_ts_config(), not supported dai type");
return -EINVAL;
}

cfg.direction = dai->direction;
cfg.index = dd->dai->index;
cfg.dma_id = dd->dma->plat_data.id;
cfg.dma_chan_index = dd->chan->index;
cfg.dma_chan_count = dd->dma->plat_data.channels;
cfg->direction = dai->direction;
cfg->index = dd->dai->index;
cfg->dma_id = dd->dma->plat_data.id;
cfg->dma_chan_index = dd->chan->index;
cfg->dma_chan_count = dd->dma->plat_data.channels;

return dai_ts_config(dd->dai->dev, &cfg);
return dai_ts_config(dd->dai->dev, cfg);
}

static int dai_ts_config_op(struct comp_dev *dev)
Expand All @@ -1710,9 +1710,7 @@ static int dai_ts_config_op(struct comp_dev *dev)

int dai_common_ts_start(struct dai_data *dd, struct comp_dev *dev)
{
struct dai_ts_cfg cfg;

return dai_ts_start(dd->dai->dev, &cfg);
return dai_ts_start(dd->dai->dev, (struct dai_ts_cfg *)&dd->ts_config);
}

static int dai_ts_start_op(struct comp_dev *dev)
Expand All @@ -1723,16 +1721,14 @@ static int dai_ts_start_op(struct comp_dev *dev)
return dai_common_ts_start(dd, dev);
}

int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct timestamp_data *tsd)
int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct dai_ts_data *tsd)
{
struct dai_ts_data tsdata;
struct dai_ts_cfg cfg;
struct dai_ts_cfg *cfg = (struct dai_ts_cfg *)&dd->ts_config;

/* TODO: convert to timestamp_data */
return dai_ts_get(dd->dai->dev, &cfg, &tsdata);
return dai_ts_get(dd->dai->dev, cfg, tsd);
}

static int dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd)
static int dai_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd)
{
struct dai_data *dd = comp_get_drvdata(dev);

Expand All @@ -1743,9 +1739,7 @@ static int dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd)

int dai_common_ts_stop(struct dai_data *dd, struct comp_dev *dev)
{
struct dai_ts_cfg cfg;

return dai_ts_stop(dd->dai->dev, &cfg);
return dai_ts_stop(dd->dai->dev, (struct dai_ts_cfg *)&dd->ts_config);
}

static int dai_ts_stop_op(struct comp_dev *dev)
Expand Down
4 changes: 4 additions & 0 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,11 @@ int module_adapter_ts_stop_op(struct comp_dev *dev)
* 0 - success
* value < 0 - failure.
*/
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
int module_adapter_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd)
#else
int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd)
#endif
{
struct processing_module *mod = comp_get_drvdata(dev);
struct module_data *md = &mod->priv;
Expand Down
5 changes: 5 additions & 0 deletions src/include/sof/audio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct comp_dev;
struct sof_ipc_stream_posn;
struct dai_hw_params;
struct timestamp_data;
struct dai_ts_data;

/** \addtogroup component_api Component API
* @{
Expand Down Expand Up @@ -455,8 +456,12 @@ struct comp_ops {
*
* Mandatory for components that allocate DAI.
*/
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
int (*dai_ts_get)(struct comp_dev *dev, struct dai_ts_data *tsd);
#else
int (*dai_ts_get)(struct comp_dev *dev,
struct timestamp_data *tsd);
#endif

/**
* Bind, atomic - used to notify component of bind event.
Expand Down
4 changes: 4 additions & 0 deletions src/include/sof/audio/dai_copier.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ int dai_common_ts_start(struct dai_data *dd, struct comp_dev *dev);

int dai_common_ts_stop(struct dai_data *dd, struct comp_dev *dev);

#if CONFIG_ZEPHYR_NATIVE_DRIVERS
int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct dai_ts_data *tsd);
#else
int dai_common_ts_get(struct dai_data *dd, struct comp_dev *dev, struct timestamp_data *tsd);
#endif

int dai_common_get_hw_params(struct dai_data *dd, struct comp_dev *dev,
struct sof_ipc_stream_params *params, int dir);
Expand Down
4 changes: 4 additions & 0 deletions src/include/sof/audio/module_adapter/module/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ int module_adapter_position(struct comp_dev *dev, struct sof_ipc_stream_posn *po
int module_adapter_ts_config_op(struct comp_dev *dev);
int module_adapter_ts_start_op(struct comp_dev *dev);
int module_adapter_ts_stop_op(struct comp_dev *dev);
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
int module_adapter_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd);
#else
int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd);
#endif

static inline void module_update_buffer_position(struct input_stream_buffer *input_buffers,
struct output_stream_buffer *output_buffers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct output_stream_buffer {

struct comp_dev;
struct timestamp_data;
struct dai_ts_data;
/**
* \struct module_endpoint_ops
* \brief Ops relevant only for the endpoint devices such as the host copier or DAI copier.
Expand Down Expand Up @@ -120,7 +121,11 @@ struct module_endpoint_ops {
*
* Mandatory for components that allocate DAI.
*/
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
int (*dai_ts_get)(struct comp_dev *dev, struct dai_ts_data *tsd);
#else
int (*dai_ts_get)(struct comp_dev *dev, struct timestamp_data *tsd);
#endif

/**
* Fetches hardware stream parameters.
Expand Down
36 changes: 0 additions & 36 deletions src/include/sof/drivers/timestamp.h

This file was deleted.

27 changes: 2 additions & 25 deletions src/include/sof/lib/dai-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stddef.h>
#include <stdint.h>
#include <zephyr/device.h>
#include <zephyr/drivers/dai.h>

/** \addtogroup sof_dai_drivers DAI Drivers
* DAI Drivers API specification.
Expand All @@ -52,30 +53,6 @@ struct dai {
struct k_spinlock lock; /* protect properties */
};

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);
};

union hdalink_cfg {
uint16_t full;
struct {
Expand Down Expand Up @@ -141,7 +118,7 @@ struct dai_data {
struct comp_dev *dai_dev;
struct comp_buffer *dma_buffer;
struct comp_buffer *local_buffer;
struct timestamp_cfg ts_config;
struct dai_ts_cfg ts_config;
struct dai *dai;
struct dma *dma;
struct dai_group *group; /* NULL if no group assigned */
Expand Down