Skip to content
Closed
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
14 changes: 7 additions & 7 deletions src/audio/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void dai_dma_cb(void *arg, enum notify_id type, void *data)
/* stop dma copy for pause/stop/xrun */
if (dev->state != COMP_STATE_ACTIVE || dd->xrun) {
/* stop the DAI */
dai_trigger(dd->dai, COMP_TRIGGER_STOP, dev->direction);
dai_trigger_sof(dd->dai, COMP_TRIGGER_STOP, dev->direction);

/* tell DMA not to reload */
next->status = DMA_CB_STATUS_END;
Expand Down Expand Up @@ -730,7 +730,7 @@ static int dai_comp_trigger_internal(struct comp_dev *dev, int cmd)
if (ret < 0)
return ret;
/* start the DAI */
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
} else {
dd->xrun = 0;
}
Expand All @@ -753,7 +753,7 @@ static int dai_comp_trigger_internal(struct comp_dev *dev, int cmd)
return ret;

/* start the DAI */
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
ret = dma_start(dd->chan);
if (ret < 0)
return ret;
Expand All @@ -780,24 +780,24 @@ static int dai_comp_trigger_internal(struct comp_dev *dev, int cmd)
*/
#if CONFIG_DMA_SUSPEND_DRAIN
ret = dma_stop(dd->chan);
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
#else
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
ret = dma_stop(dd->chan);
#endif
break;
case COMP_TRIGGER_PAUSE:
comp_dbg(dev, "dai_comp_trigger_internal(), PAUSE");
ret = dma_pause(dd->chan);
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
break;
case COMP_TRIGGER_PRE_START:
case COMP_TRIGGER_PRE_RELEASE:
/* only start the DAI if we are not XRUN handling */
if (dd->xrun)
dd->xrun = 0;
else
dai_trigger(dd->dai, cmd, dev->direction);
dai_trigger_sof(dd->dai, cmd, dev->direction);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/intel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(CONFIG_INTEL_SSP)
endif()

if(CONFIG_INTEL_ALH)
add_local_sources(sof alh.c)
add_subdirectory(alh)
endif()

if(CONFIG_INTEL_DMIC)
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/intel/alh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: BSD-3-Clause

add_local_sources(sof alh.c)
156 changes: 156 additions & 0 deletions src/drivers/intel/alh/alh-zephyr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2022 Intel Corporation. All rights reserved.
//
// Author: Adrian Bonislawski <adrian.bonislawski@intel.com>

#include <sof/audio/component.h>
#include <sof/lib/dai.h>
#include <sof/lib/dma.h>
#include <sof/lib/memory.h>
#include <sof/lib/uuid.h>
#include <sof/trace/trace.h>
#include <sof/common.h>
#include <ipc/dai.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <user/trace.h>
#include <stdint.h>
#include <ipc4/alh.h>

/* zephyr dai driver */
#include <drivers/dai.h>

/* a8e4218c-e863-4c93-84e7-5c27d2504501 */
DECLARE_SOF_UUID("alh-dai", alh_uuid, 0xa8e4218c, 0xe863, 0x4c93,
0x84, 0xe7, 0x5c, 0x27, 0xd2, 0x50, 0x45, 0x01);

DECLARE_TR_CTX(alh_tr, SOF_UUID(alh_uuid), LOG_LEVEL_INFO);

static int alh_trigger_zephyr(struct dai *dai, int cmd, int direction)
{
enum dai_trigger_cmd cmd_z;

switch(cmd) {
case COMP_TRIGGER_STOP:
cmd_z = DAI_TRIGGER_STOP;
break;
case COMP_TRIGGER_START:
case COMP_TRIGGER_RELEASE:
cmd_z = DAI_TRIGGER_START;
break;
case COMP_TRIGGER_PAUSE:
cmd_z = DAI_TRIGGER_PAUSE;
break;
case COMP_TRIGGER_PRE_START:
case COMP_TRIGGER_PRE_RELEASE:
cmd_z = DAI_TRIGGER_PRE_START;
break;
default:
return -EINVAL;
}

return dai_trigger(dai->z_drv, direction, cmd_z);
}

static int alh_set_config_zephyr(struct dai *dai, struct ipc_config_dai *common_config,
void *spec_config)
{
struct sof_ipc_dai_config *sof_cfg;
struct dai_config cfg;

sof_cfg = (struct sof_ipc_dai_config *)spec_config;
cfg.dai_index = common_config->dai_index;
cfg.format = sof_cfg->format;
cfg.options = sof_cfg->flags;

if(common_config->is_config_blob) {
cfg.type = DAI_INTEL_ALH_NHLT;
return dai_config_set(dai->z_drv, &cfg, spec_config);
} else {
cfg.type = DAI_INTEL_ALH;
return dai_config_set(dai->z_drv, &cfg, &sof_cfg->alh);
}
}

static int alh_get_hw_params_zephyr(struct dai *dai, struct sof_ipc_stream_params *params, int dir)
{
const struct dai_config *cfg;

cfg = dai_config_get(dai->z_drv, dir);

params->rate = cfg->rate;
params->buffer_fmt = 0;
params->channels = cfg->channels;

switch (cfg->word_size) {
case 16:
params->frame_fmt = SOF_IPC_FRAME_S16_LE;
break;
case 24:
params->frame_fmt = SOF_IPC_FRAME_S24_4LE;
break;
case 32:
params->frame_fmt = SOF_IPC_FRAME_S32_LE;
break;
default:
dai_warn(dai,"%d not supported format", cfg->word_size);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation - like in SSP


return 0;
}

static int alh_get_handshake_zephyr(struct dai *dai, int direction, int stream_id)
{
const struct dai_properties *props;

props = dai_get_properties(dai->z_drv, direction, stream_id);

return props->dma_hs_id;
}

static int alh_get_fifo_zephyr(struct dai *dai, int direction, int stream_id)
{
const struct dai_properties *props;

props = dai_get_properties(dai->z_drv, direction, stream_id);

return props->fifo_address;
}

static int alh_get_stream_id_zephyr(struct dai *dai, int direction)
{
const struct dai_properties *props;

props = dai_get_properties(dai->z_drv, direction, 0);

return props->stream_id;
}

static int alh_probe_zephyr(struct dai *dai)
{
return dai_probe(dai->z_drv);
}

static int alh_remove_zephyr(struct dai *dai)
{
return dai_remove(dai->z_drv);
}

const struct dai_driver alh_driver = {
.type = SOF_DAI_INTEL_ALH,
.uid = SOF_UUID(alh_uuid),
.tctx = &alh_tr,
.dma_caps = DMA_CAP_GP_LP | DMA_CAP_GP_HP,
.dma_dev = DMA_DEV_ALH,
.ops = {
.trigger = alh_trigger_zephyr,
.set_config = alh_set_config_zephyr,
.get_hw_params = alh_get_hw_params_zephyr,
.get_handshake = alh_get_handshake_zephyr,
.get_fifo = alh_get_fifo_zephyr,
.get_stream_id = alh_get_stream_id_zephyr,
.probe = alh_probe_zephyr,
.remove = alh_remove_zephyr,
},
};
8 changes: 8 additions & 0 deletions src/drivers/intel/alh.c → src/drivers/intel/alh/alh.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ static int alh_get_fifo(struct dai *dai, int direction, int stream_id)
return ALH_BASE + offset + ALH_STREAM_OFFSET * stream_id;
}

static int alh_get_stream_id(struct dai *dai, int direction)
{
struct alh_pdata *alh = dai_get_drvdata(dai);

return alh->params.stream_id;
}

const struct dai_driver alh_driver = {
.type = SOF_DAI_INTEL_ALH,
.uid = SOF_UUID(alh_uuid),
Expand All @@ -156,6 +163,7 @@ const struct dai_driver alh_driver = {
.get_hw_params = alh_get_hw_params,
.get_handshake = alh_get_handshake,
.get_fifo = alh_get_fifo,
.get_stream_id = alh_get_stream_id,
.probe = alh_probe,
.remove = alh_remove,
},
Expand Down
21 changes: 18 additions & 3 deletions src/include/sof/lib/dai.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __ZEPHYR__
#include <device.h>
#endif

struct dai;
struct sof_ipc_stream_params;
Expand Down Expand Up @@ -82,6 +85,7 @@ struct dai_ops {
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 (*get_stream_id)(struct dai *dai, int direction);
int (*probe)(struct dai *dai);
int (*remove)(struct dai *dai);
uint32_t (*get_init_delay_ms)(struct dai *dai);
Expand Down Expand Up @@ -194,6 +198,9 @@ struct dai {
int sref; /**< simple ref counter, guarded by lock */
struct dai_plat_data plat_data;
const struct dai_driver *drv;
#ifdef __ZEPHYR__
const struct device *z_drv;
#endif
void *priv_data;
};

Expand Down Expand Up @@ -376,7 +383,7 @@ static inline int dai_set_config(struct dai *dai, struct ipc_config_dai *config,
/**
* \brief Digital Audio interface trigger
*/
static inline int dai_trigger(struct dai *dai, int cmd, int direction)
static inline int dai_trigger_sof(struct dai *dai, int cmd, int direction)
{
return dai->drv->ops.trigger(dai, cmd, direction);
}
Expand Down Expand Up @@ -421,18 +428,26 @@ static inline int dai_get_fifo(struct dai *dai, int direction,
return dai->drv->ops.get_fifo(dai, direction, stream_id);
}

static inline int dai_get_stream_id(struct dai *dai, int direction)
{
if (dai->drv->ops.get_stream_id)
return dai->drv->ops.get_stream_id(dai, direction);

return -1;
}

/**
* \brief Digital Audio interface Probe
*/
static inline int dai_probe(struct dai *dai)
static inline int dai_probe_sof(struct dai *dai)
{
return dai->drv->ops.probe(dai);
}

/**
* \brief Digital Audio interface Remove
*/
static inline int dai_remove(struct dai *dai)
static inline int dai_remove_sof(struct dai *dai)
{
return dai->drv->ops.remove(dai);
}
Expand Down
7 changes: 2 additions & 5 deletions src/ipc/ipc4/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ int ipc_dai_data_config(struct comp_dev *dev)
struct ipc_config_dai *dai = &dd->ipc_config;
struct ipc4_copier_module_cfg *copier_cfg;
struct dai *dai_p = dd->dai;
struct alh_pdata *alh;

if (!dai) {
comp_err(dev, "dai_data_config(): no dai!\n");
Expand Down Expand Up @@ -100,20 +99,18 @@ int ipc_dai_data_config(struct comp_dev *dev)
case SOF_DAI_INTEL_HDA:
break;
case SOF_DAI_INTEL_ALH:
alh = dai_get_drvdata(dai_p);
/* SDW HW FIFO always requires 32bit MSB aligned sample data for
* all formats, such as 8/16/24/32 bits.
*/
dev->ipc_config.frame_fmt = SOF_IPC_FRAME_S32_LE;
dd->dma_buffer->stream.frame_fmt = dev->ipc_config.frame_fmt;

dd->config.burst_elems =
dd->dai->plat_data.fifo[dai->direction].depth;
dd->config.burst_elems = ALH_GPDMA_BURST_LENGTH;

/* As with HDA, the DMA channel is assigned in runtime,
* not during topology parsing.
*/
dd->stream_id = alh->params.stream_id;
dd->stream_id = dai_get_stream_id(dai_p, 0);//alh->params.stream_id;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily added dai_get_stream_id, not sure if this is the correct approach (feel free to comment) but we need to address this as alh private data was used here


comp_dbg(dev, "dai_data_config() SOF_DAI_INTEL_ALH dd->dma_buffer->stream.frame_fmt %#x stream_id %d",
dd->dma_buffer->stream.frame_fmt, dd->stream_id);
Expand Down
Loading