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

Commit 3e62c61c authored by Anish Kumar's avatar Anish Kumar Committed by Banajit Goswami
Browse files

ASoC: msm: qdsp6v2: Add mutex to ensure atomicity



Make sure that afe command sent to DSP is atomic in nature
and doesn't get overwritten in concurrent scenarios.

Change-Id: I86558c293f0ce5d78533b79ed13a23e52e367c1d
Signed-off-by: default avatarAnish Kumar <kanish@codeaurora.org>
parent 5593593b
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ struct afe_ctl {
	int vi_tx_port;
	uint32_t afe_sample_rates[AFE_MAX_PORTS];
	struct aanc_data aanc_info;
	struct mutex mem_map_lock;
	struct mutex afe_cmd_lock;
};

static atomic_t afe_ports_mad_type[SLIMBUS_PORT_LAST - SLIMBUS_0_RX];
@@ -1591,6 +1591,7 @@ int afe_port_start(u16 port_id, union afe_port_config *afe_config,
		return ret;
	}

	mutex_lock(&this_afe.afe_cmd_lock);
	afe_send_cal(port_id);
	afe_send_hw_delay(port_id, rate);

@@ -1603,13 +1604,14 @@ int afe_port_start(u16 port_id, union afe_port_config *afe_config,
			!afe_has_config(AFE_SLIMBUS_SLAVE_CONFIG)) {
				pr_err("%s: AFE isn't configured yet for\n"
					   "HW MAD try Again\n", __func__);
				return -EAGAIN;
				ret = -EAGAIN;
				goto fail_cmd;
		}
		ret = afe_turn_onoff_hw_mad(mad_type, true);
		if (ret) {
			pr_err("%s: afe_turn_onoff_hw_mad failed %d\n",
			       __func__, ret);
			return ret;
			goto fail_cmd;
		}
	}

@@ -1733,9 +1735,10 @@ int afe_port_start(u16 port_id, union afe_port_config *afe_config,
		ret = -EINVAL;
		goto fail_cmd;
	}
	return afe_send_cmd_port_start(port_id);
	ret = afe_send_cmd_port_start(port_id);

fail_cmd:
	mutex_unlock(&this_afe.afe_cmd_lock);
	return ret;
}

@@ -1853,9 +1856,9 @@ int afe_open(u16 port_id,
	if (ret < 0) {
		pr_err("%s: Failed : Invalid Port id = 0x%x ret %d\n",
			__func__, port_id, ret);
		ret = -EINVAL;
		goto fail_cmd;
		return -EINVAL;
	}
	mutex_lock(&this_afe.afe_cmd_lock);

	config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
				APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
@@ -1953,6 +1956,7 @@ int afe_open(u16 port_id,
	}

fail_cmd:
	mutex_unlock(&this_afe.afe_cmd_lock);
	return ret;
}

@@ -2442,18 +2446,18 @@ int afe_memory_map(phys_addr_t dma_addr_p, u32 dma_buf_sz,
{
	int ret = 0;

	mutex_lock(&this_afe.mem_map_lock);
	mutex_lock(&this_afe.afe_cmd_lock);
	ac->mem_map_handle = 0;
	ret = afe_cmd_memory_map(dma_addr_p, dma_buf_sz);
	if (ret < 0) {
		pr_err("%s: afe_cmd_memory_map failed %d\n",
			__func__, ret);

		mutex_unlock(&this_afe.mem_map_lock);
		mutex_unlock(&this_afe.afe_cmd_lock);
		return ret;
	}
	ac->mem_map_handle = this_afe.mmap_handle;
	mutex_unlock(&this_afe.mem_map_lock);
	mutex_unlock(&this_afe.afe_cmd_lock);

	return ret;
}
@@ -3557,6 +3561,7 @@ int afe_set_lpass_clock(u16 port_id, struct afe_clk_cfg *cfg)
		return ret;
	}

	mutex_lock(&this_afe.afe_cmd_lock);
	clk_cfg.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
				APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
	clk_cfg.hdr.pkt_size = sizeof(clk_cfg);
@@ -3610,6 +3615,7 @@ int afe_set_lpass_clock(u16 port_id, struct afe_clk_cfg *cfg)
	}

fail_cmd:
	mutex_unlock(&this_afe.afe_cmd_lock);
	return ret;
}

@@ -4312,7 +4318,7 @@ static int __init afe_init(void)
	this_afe.mmap_handle = 0;
	this_afe.vi_tx_port = -1;
	this_afe.prot_cfg.mode = MSM_SPKR_PROT_DISABLED;
	mutex_init(&this_afe.mem_map_lock);
	mutex_init(&this_afe.afe_cmd_lock);
	for (i = 0; i < AFE_MAX_PORTS; i++)
		init_waitqueue_head(&this_afe.wait[i]);

@@ -4329,6 +4335,7 @@ static void __exit afe_exit(void)
	afe_delete_cal_data();

	config_debug_fs_exit();
	mutex_destroy(&this_afe.afe_cmd_lock);
}

device_initcall(afe_init);