Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cba7830 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ASoC: wcd_cpe_core: add support to select CPE AFE port"

parents 4bf664e9 b4d8293a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ struct cpe_lsm_session {
	u16 cmd_err_code;
	u8 id;
	u8 num_confidence_levels;
	u16 afe_out_port_id;
	struct task_struct *lsm_lab_thread;
	bool started;

@@ -128,6 +129,9 @@ struct wcd_cpe_lsm_ops {
	int (*lsm_deregister_snd_model) (void *core_handle,
					 struct cpe_lsm_session *);

	int (*lsm_get_afe_out_port_id)(void *core_handle,
			       struct cpe_lsm_session *session);

	int (*lsm_start) (void *core_handle,
			  struct cpe_lsm_session *);

+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ struct snd_pcm_ops {
#define SNDRV_PCM_RATE_96000		(1<<10)		/* 96000Hz */
#define SNDRV_PCM_RATE_176400		(1<<11)		/* 176400Hz */
#define SNDRV_PCM_RATE_192000		(1<<12)		/* 192000Hz */
#define SNDRV_PCM_RATE_384000		(1<<13)		/* 384000Hz */

#define SNDRV_PCM_RATE_CONTINUOUS	(1<<30)		/* continuous range */
#define SNDRV_PCM_RATE_KNOT		(1<<31)		/* supports more non-continuos rates */
+2 −1
Original line number Diff line number Diff line
@@ -1938,7 +1938,8 @@ static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params,
#endif

static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
                                 48000, 64000, 88200, 96000, 176400, 192000 };
				48000, 64000, 88200, 96000, 176400, 192000,
				384000 };

const struct snd_pcm_hw_constraint_list snd_pcm_known_rates = {
	.count = ARRAY_SIZE(rates),
+76 −11
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@

#define CMI_CMD_TIMEOUT (10 * HZ)
#define WCD_CPE_LSM_MAX_SESSIONS 1
#define WCD_CPE_AFE_MAX_PORTS 2
#define WCD_CPE_AFE_MAX_PORTS 4
#define WCD_CPE_DRAM_SIZE 0x30000
#define WCD_CPE_DRAM_OFFSET 0x50000
#define AFE_SVC_EXPLICIT_PORT_START 1
@@ -69,14 +69,12 @@
#define CPE_ERR_IRQ_CB(core) \
	(core->cpe_cdc_cb->cpe_err_irq_control)

#define AFE_OUT_BUF_SAMPLES 8

/*
 * AFE output buffer size is always
 * AFE_OUT_BUF_SAMPLES * number of bytes per sample
 * (sample_rate * number of bytes per sample/2*1000)
 */
#define AFE_OUT_BUF_SIZE(bit_width) \
	(AFE_OUT_BUF_SAMPLES * (bit_width / BITS_PER_BYTE))
#define AFE_OUT_BUF_SIZE(bit_width, sample_rate) \
	(((sample_rate) * (bit_width / BITS_PER_BYTE))/(2*1000))

enum afe_port_state {
	AFE_PORT_STATE_DEINIT = 0,
@@ -2775,7 +2773,7 @@ err_ret:

static int wcd_cpe_send_param_connectport(struct wcd_cpe_core *core,
		struct cpe_lsm_session *session,
		void *data, struct cpe_lsm_ids *ids)
		void *data, struct cpe_lsm_ids *ids, u16 port_id)
{
	struct cpe_lsm_param_connectport con_port_cmd;
	struct cmi_hdr *msg_hdr = &con_port_cmd.hdr;
@@ -2797,7 +2795,7 @@ static int wcd_cpe_send_param_connectport(struct wcd_cpe_core *core,
			       CPE_LSM_SESSION_CMD_SET_PARAMS_V2);

	con_port_cmd.minor_version = 1;
	con_port_cmd.afe_port_id = CPE_AFE_PORT_1_TX;
	con_port_cmd.afe_port_id = port_id;
	con_port_cmd.reserved = 0;

	WCD_CPE_GRAB_LOCK(&session->lsm_lock, "lsm");
@@ -3019,7 +3017,7 @@ static int wcd_cpe_set_one_param(void *core_handle,
		connectport_ids.param_id = LSM_PARAM_ID_CONNECT_TO_PORT;

		rc = wcd_cpe_send_param_connectport(core, session, NULL,
				       &connectport_ids);
				       &connectport_ids, CPE_AFE_PORT_1_TX);
		if (rc)
			dev_err(core->dev,
				"%s: send_param_connectport failed, err %d\n",
@@ -3097,7 +3095,7 @@ static int wcd_cpe_lsm_set_params(struct wcd_cpe_core *core,
	ids.module_id = CPE_LSM_MODULE_ID_VOICE_WAKEUP;
	ids.param_id = CPE_LSM_PARAM_ID_CONNECT_TO_PORT;
	ret = wcd_cpe_send_param_connectport(core, session,
					     NULL, &ids);
					     NULL, &ids, CPE_AFE_PORT_1_TX);
	if (ret)
		dev_err(core->dev,
			"%s: Failed to set connectPort, err=%d\n",
@@ -3241,6 +3239,58 @@ end_ret:
	return ret;
}

/*
 * wcd_cpe_lsm_get_afe_out_port_id: get afe output port id
 * @core_handle: handle to the CPE core
 * @session: session for which port id needs to get
 */
static int wcd_cpe_lsm_get_afe_out_port_id(void *core_handle,
					   struct cpe_lsm_session *session)
{
	struct wcd_cpe_core *core = core_handle;
	struct snd_soc_codec *codec;
	int rc = 0;

	if (!core || !core->codec) {
		pr_err("%s: Invalid handle to %s\n",
			__func__,
			(!core) ? "core" : "codec");
		rc = -EINVAL;
		goto done;
	}

	if (!session) {
		dev_err(core->dev, "%s: Invalid session\n",
			__func__);
		rc = -EINVAL;
		goto done;
	}

	if (!core->cpe_cdc_cb ||
		!core->cpe_cdc_cb->get_afe_out_port_id) {
		session->afe_out_port_id = WCD_CPE_AFE_OUT_PORT_2;
		dev_dbg(core->dev,
			"%s: callback not defined, default port_id = %d\n",
			__func__, session->afe_out_port_id);
		goto done;
	}

	codec = core->codec;
	rc = core->cpe_cdc_cb->get_afe_out_port_id(codec,
						   &session->afe_out_port_id);
	if (rc) {
		dev_err(core->dev,
			"%s: failed to get port id, err = %d\n",
			__func__, rc);
		goto done;
	}
	dev_dbg(core->dev, "%s: port_id: %d\n", __func__,
		session->afe_out_port_id);

done:
	return rc;
}

/*
 * wcd_cpe_cmd_lsm_start: send the start command to lsm
 * @core_handle: handle to the CPE core
@@ -3252,6 +3302,7 @@ static int wcd_cpe_cmd_lsm_start(void *core_handle,
{
	struct cmi_hdr cmd_lsm_start;
	struct wcd_cpe_core *core = core_handle;
	struct cpe_lsm_ids ids;
	int ret = 0;

	ret = wcd_cpe_is_valid_lsm_session(core, session,
@@ -3259,6 +3310,18 @@ static int wcd_cpe_cmd_lsm_start(void *core_handle,
	if (ret)
		return ret;

	/* Send connect to port */
	ids.module_id = CPE_LSM_MODULE_FRAMEWORK;
	ids.param_id = CPE_LSM_PARAM_ID_CONNECT_TO_PORT;
	ret = wcd_cpe_send_param_connectport(core, session,
					NULL, &ids, session->afe_out_port_id);
	if (ret) {
		dev_err(core->dev,
			"%s: Failed to set connectPort, err=%d\n",
			__func__, ret);
		return ret;
	}

	WCD_CPE_GRAB_LOCK(&session->lsm_lock, "lsm");

	memset(&cmd_lsm_start, 0, sizeof(struct cmi_hdr));
@@ -3774,6 +3837,7 @@ int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops)
	lsm_ops->lsm_shmem_dealloc = wcd_cpe_cmd_lsm_shmem_dealloc;
	lsm_ops->lsm_register_snd_model = wcd_cpe_lsm_reg_snd_model;
	lsm_ops->lsm_deregister_snd_model = wcd_cpe_lsm_dereg_snd_model;
	lsm_ops->lsm_get_afe_out_port_id = wcd_cpe_lsm_get_afe_out_port_id;
	lsm_ops->lsm_start = wcd_cpe_cmd_lsm_start;
	lsm_ops->lsm_stop = wcd_cpe_cmd_lsm_stop;
	lsm_ops->lsm_lab_control = wcd_cpe_lsm_lab_control;
@@ -4182,7 +4246,8 @@ static int wcd_cpe_afe_cmd_port_cfg(void *core_handle,
	port_cfg_cmd.bit_width = afe_cfg->bit_width;
	port_cfg_cmd.num_channels = afe_cfg->num_channels;
	port_cfg_cmd.sample_rate = afe_cfg->sample_rate;
	port_cfg_cmd.buffer_size = AFE_OUT_BUF_SIZE(afe_cfg->bit_width);
	port_cfg_cmd.buffer_size = AFE_OUT_BUF_SIZE(afe_cfg->bit_width,
						    afe_cfg->sample_rate);

	ret = wcd_cpe_cmi_send_afe_msg(core, afe_port_d, &port_cfg_cmd);
	if (ret)
+4 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@

#define WCD_CPE_IMAGE_FNAME_MAX 64

#define WCD_CPE_AFE_OUT_PORT_2 2
#define WCD_CPE_AFE_OUT_PORT_4 4

enum {
	WCD_CPE_LSM_CAL_AFE = 0,
	WCD_CPE_LSM_CAL_LSM,
@@ -58,6 +61,7 @@ struct wcd_cpe_cdc_cb {
	int (*cpe_clk_en) (struct snd_soc_codec *, bool);
	int (*cdc_ext_clk)(struct snd_soc_codec *codec, int enable, bool dapm);
	int (*lab_cdc_ch_ctl)(struct snd_soc_codec *codec, u8 event);
	int (*get_afe_out_port_id)(struct snd_soc_codec *codec, u16 *port_id);
	int (*bus_vote_bw)(struct snd_soc_codec *codec,
			   bool vote);