ASoC: q6dsp: audioreach: add helper function to set u32 param
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 19 Jun 2023 10:16:45 +0000 (11:16 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 19 Jun 2023 11:58:59 +0000 (12:58 +0100)
Some of the Audioreach commands take a u32 value,
ex: PARAM_ID_MODULE_ENABLE.

It makes more sense to provide a helper function so that other new
commands can reuse this.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230619101653.9750-4-srinivas.kandagatla@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/qdsp6/audioreach.c
sound/soc/qcom/qdsp6/audioreach.h

index 8d9410d..0acd4a7 100644 (file)
@@ -732,33 +732,32 @@ static int audioreach_codec_dma_set_media_format(struct q6apm_graph *graph,
        return rc;
 }
 
-static int audioreach_sal_limiter_enable(struct q6apm_graph *graph,
-                                        struct audioreach_module *module, bool enable)
+int audioreach_send_u32_param(struct q6apm_graph *graph, struct audioreach_module *module,
+                             uint32_t param_id, uint32_t param_val)
 {
        struct apm_module_param_data *param_data;
-       struct param_id_sal_limiter_enable *limiter_enable;
-       int payload_size;
        struct gpr_pkt *pkt;
-       int rc;
+       uint32_t *param;
+       int rc, payload_size;
        void *p;
 
-       payload_size = sizeof(*limiter_enable) + APM_MODULE_PARAM_DATA_SIZE;
-
-       pkt = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0);
-       if (IS_ERR(pkt))
-               return PTR_ERR(pkt);
+       payload_size = sizeof(uint32_t) + APM_MODULE_PARAM_DATA_SIZE;
+       p = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0);
+       if (IS_ERR(p))
+               return -ENOMEM;
 
-       p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
+       pkt = p;
+       p = p + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
 
        param_data = p;
        param_data->module_instance_id = module->instance_id;
        param_data->error_code = 0;
-       param_data->param_id = PARAM_ID_SAL_LIMITER_ENABLE;
-       param_data->param_size = sizeof(*limiter_enable);
-       p = p + APM_MODULE_PARAM_DATA_SIZE;
-       limiter_enable = p;
+       param_data->param_id = param_id;
+       param_data->param_size = sizeof(uint32_t);
 
-       limiter_enable->enable_lim = enable;
+       p = p + APM_MODULE_PARAM_DATA_SIZE;
+       param = p;
+       *param = param_val;
 
        rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
 
@@ -766,77 +765,26 @@ static int audioreach_sal_limiter_enable(struct q6apm_graph *graph,
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(audioreach_send_u32_param);
+
+static int audioreach_sal_limiter_enable(struct q6apm_graph *graph,
+                                        struct audioreach_module *module, bool enable)
+{
+       return audioreach_send_u32_param(graph, module, PARAM_ID_SAL_LIMITER_ENABLE, enable);
+}
 
 static int audioreach_sal_set_media_format(struct q6apm_graph *graph,
                                           struct audioreach_module *module,
                                           struct audioreach_module_config *cfg)
 {
-       struct apm_module_param_data *param_data;
-       struct param_id_sal_output_config *media_format;
-       int payload_size;
-       struct gpr_pkt *pkt;
-       int rc;
-       void *p;
-
-       payload_size = sizeof(*media_format) + APM_MODULE_PARAM_DATA_SIZE;
-
-       pkt = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0);
-       if (IS_ERR(pkt))
-               return PTR_ERR(pkt);
-
-       p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
-
-       param_data = p;
-       param_data->module_instance_id = module->instance_id;
-       param_data->error_code = 0;
-       param_data->param_id = PARAM_ID_SAL_OUTPUT_CFG;
-       param_data->param_size = sizeof(*media_format);
-       p = p + APM_MODULE_PARAM_DATA_SIZE;
-       media_format = p;
-
-       media_format->bits_per_sample = cfg->bit_width;
-
-       rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
-
-       kfree(pkt);
-
-       return rc;
+       return audioreach_send_u32_param(graph, module, PARAM_ID_SAL_OUTPUT_CFG,  cfg->bit_width);
 }
 
 static int audioreach_module_enable(struct q6apm_graph *graph,
                                    struct audioreach_module *module,
                                    bool enable)
 {
-       struct apm_module_param_data *param_data;
-       struct param_id_module_enable *param;
-       int payload_size;
-       struct gpr_pkt *pkt;
-       int rc;
-       void *p;
-
-       payload_size = sizeof(*param) + APM_MODULE_PARAM_DATA_SIZE;
-
-       pkt = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_SET_CFG, 0);
-       if (IS_ERR(pkt))
-               return PTR_ERR(pkt);
-
-       p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
-
-       param_data = p;
-       param_data->module_instance_id = module->instance_id;
-       param_data->error_code = 0;
-       param_data->param_id = PARAM_ID_MODULE_ENABLE;
-       param_data->param_size = sizeof(*param);
-       p = p + APM_MODULE_PARAM_DATA_SIZE;
-       param = p;
-
-       param->enable = enable;
-
-       rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
-
-       kfree(pkt);
-
-       return rc;
+       return audioreach_send_u32_param(graph, module, PARAM_ID_MODULE_ENABLE, enable);
 }
 
 static int audioreach_mfc_set_media_format(struct q6apm_graph *graph,
index 3ebb81c..18d8d24 100644 (file)
@@ -752,4 +752,6 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
 int audioreach_shared_memory_send_eos(struct q6apm_graph *graph);
 int audioreach_gain_set_vol_ctrl(struct q6apm *apm,
                                 struct audioreach_module *module, int vol);
+int audioreach_send_u32_param(struct q6apm_graph *graph, struct audioreach_module *module,
+                             uint32_t param_id, uint32_t param_val);
 #endif /* __AUDIOREACH_H__ */