Skip to content

Commit

Permalink
base_fw: ipc: add support for dmic dma control
Browse files Browse the repository at this point in the history
Add support for Dmic gain config update to DMA Control IPC.
Fix DMA Control IPC implementation

Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
  • Loading branch information
iganakov committed Jul 26, 2024
1 parent 916600f commit ead3cba
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 37 deletions.
25 changes: 10 additions & 15 deletions src/audio/base_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,35 +498,30 @@ static int basefw_dma_control(bool first_block,
const char *data)
{
struct ipc4_dma_control *dma_control;
size_t data_size;
const uint32_t *config_data;
size_t config_size;
int ret;

/* Ensure that the message is atomic and contains all necessary information */
if (!first_block || !last_block) {
tr_err(&ipc_tr, "Non-atomic DMA Control message received");
return -EINVAL;
return IPC4_ERROR_INVALID_PARAM;
}

dma_control = (struct ipc4_dma_control *)data;
if (dma_control->config_length > 0) {
/* DMA Control is passed using a structure with the same construction as in DAI
* configuration. There is an additional section whose size is not accounted for in
* the config_length field. As a result, the configuration size will always be 0.
*/
tr_err(&ipc_tr, "The expected size of the data is 0.");
return -EINVAL;
}
config_data = dma_control->config_data;

data_size = data_offset - (sizeof(struct ipc4_dma_control) - sizeof(uint32_t));
ret = basefw_vendor_dma_control(dma_control->node_id,
(const char *)dma_control->config_data,
data_size);
/* config_length is set as number of dwords */
config_size = dma_control->config_length * sizeof(uint32_t);

ret = basefw_vendor_dma_control(dma_control->node_id, config_data,
config_size);
if (ret < 0) {
tr_err(&ipc_tr, "DMA gateway configuration failed, error: %d", ret);
return ret;
}

return 0;
return IPC4_SUCCESS;
}

static int basefw_set_large_config(struct comp_dev *dev,
Expand Down
45 changes: 33 additions & 12 deletions src/audio/base_fw_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <rtos/string.h>
#include <sof/tlv.h>
#include <sof/lib/dai.h>
#include <ipc/dai.h>
#include <ipc4/error_status.h>

#if defined(CONFIG_SOC_SERIES_INTEL_ADSP_ACE)
#include <intel_adsp_hda.h>
Expand All @@ -22,6 +24,8 @@

#include <ipc4/base_fw.h>
#include <rimage/sof/user/manifest.h>
#include "copier/copier.h"
#include "copier/copier_gain.h"

struct ipc4_modules_info {
uint32_t modules_count;
Expand Down Expand Up @@ -327,36 +331,53 @@ static inline bool is_ssp_node_id(uint32_t dma_type)
dma_type == ipc4_i2s_link_input_class;
}

int basefw_vendor_dma_control(uint32_t node_id, const char *config_data, size_t data_size)
int basefw_vendor_dma_control(uint32_t node_id, const uint32_t *config_data,
size_t config_size)
{
union ipc4_connector_node_id node = (union ipc4_connector_node_id)node_id;
const struct device *dev;
int ret, result;

tr_info(&basefw_comp_tr, "node_id 0x%x, config_data 0x%x, data_size %u",
node_id, (uint32_t)config_data, data_size);
if (!is_ssp_node_id(node.f.dma_type)) {
tr_err(&basefw_comp_tr, "Unsupported or invalid node_id: 0x%x for DMA Control",
node_id);
return -EOPNOTSUPP;
node_id, (uint32_t)config_data, config_size);

switch (node.f.dma_type) {
case ipc4_dmic_link_input_class:
/* In DMIC case we don't need to update zephyr dai params */
dev = NULL;
ret = copier_gain_dma_control(node_id, config_data, config_size,
SOF_DAI_INTEL_DMIC);
if (ret) {
tr_err(&basefw_comp_tr,
"Failed to update copier gain coefs, error: %d", ret);
return IPC4_INVALID_REQUEST;
}
return IPC4_SUCCESS;
case ipc4_i2s_link_output_class:
case ipc4_i2s_link_input_class:
dev = dai_get_device(DAI_INTEL_SSP, node.f.v_index);
break;
default:
tr_err(&basefw_comp_tr, "DAI device=%d with node_id: 0x%x not supported",
node.f.dma_type, node_id);
return IPC4_INVALID_REQUEST;
}

const struct device *dev = dai_get_device(DAI_INTEL_SSP, node.f.v_index);

if (!dev) {
tr_err(&basefw_comp_tr,
"Failed to find the SSP DAI device for node_id: 0x%x",
node_id);
return -EINVAL;
return IPC4_ERROR_INVALID_PARAM;
}

ret = pm_device_runtime_get(dev);
if (ret < 0) {
tr_err(&basefw_comp_tr, "Failed to get resume device, error: %d",
ret);
return ret;
return IPC4_ERROR_INVALID_PARAM;
}

result = dai_config_update(dev, config_data, data_size);
result = dai_config_update(dev, config_data, config_size);
if (result < 0)
tr_err(&basefw_comp_tr,
"Failed to set DMA control for SSP DAI, error: %d",
Expand All @@ -365,7 +386,7 @@ int basefw_vendor_dma_control(uint32_t node_id, const char *config_data, size_t
ret = pm_device_runtime_put(dev);
if (ret < 0)
tr_err(&basefw_comp_tr, "Failed to suspend device, error: %d",
ret);
IPC4_ERROR_INVALID_PARAM);

return result;
}
2 changes: 1 addition & 1 deletion src/include/ipc4/base_fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ struct ipc4_astate_table {
struct ipc4_dma_control {
uint32_t node_id;
uint32_t config_length;
uint32_t config_data[1];
uint32_t config_data[0];
} __attribute__((packed, aligned(4)));

enum ipc4_perf_measurements_state_set {
Expand Down
16 changes: 7 additions & 9 deletions src/include/ipc4/base_fw_vendor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ int basefw_vendor_set_large_config(struct comp_dev *dev,
/**
* @brief Vendor specific routine to configure DMA gateway.
*
* @param node_id The node ID of the DMA gateway to configure.
* @param config_data pointer to the configuration data.
* @param data_size Size of the configuration data.
* @param node_id Node ID of the DMA gateway.
* @param config_data pointer to the configuration data containing tlv.
* @param config_size Size of the configuration data.
* @return 0 if successful, error code otherwise.
*/
int basefw_vendor_dma_control(uint32_t node_id,
const char *config_data,
size_t data_size);
int basefw_vendor_dma_control(uint32_t node_id, const uint32_t *config_data,
size_t config_size);

#else /* !CONFIG_IPC4_BASE_FW_INTEL */

Expand Down Expand Up @@ -145,9 +144,8 @@ static inline int basefw_vendor_set_large_config(struct comp_dev *dev,
return IPC4_UNKNOWN_MESSAGE_TYPE;
}

static inline int basefw_vendor_dma_control(uint32_t node_id,
const char *config_data,
size_t data_size)
static inline int basefw_vendor_dma_control(uint32_t node_id, const uint32_t *config_data,
size_t config_size)
{
return IPC4_UNKNOWN_MESSAGE_TYPE;
}
Expand Down

0 comments on commit ead3cba

Please sign in to comment.