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

Commit 0c3aebb8 authored by Bhalchandra Gajare's avatar Bhalchandra Gajare
Browse files

ASoC: apq8084: Create sysfs property to enable CPE



Do not enable CPE for wcd9330 codec unless specifically requested to
enable CPE through sysfs.

Change-Id: Ib017217c3acbfcda8fb0d3ffc19d414c368e39c1
Signed-off-by: default avatarBhalchandra Gajare <gajare@codeaurora.org>
parent 172bca28
Loading
Loading
Loading
Loading
+76 −6
Original line number Diff line number Diff line
@@ -87,6 +87,33 @@ static void *adsp_state_notifier;

#define ADSP_STATE_READY_TIMEOUT_MS 3000

struct cpe_load_priv {
	void *cdc_handle;
	struct kobject *cpe_load_kobj;
	struct attribute_group *attr_group;
};

static int cpe_load;

static ssize_t cpe_load_store(struct kobject *kobj,
	struct kobj_attribute *attr,
	const char *buf,
	size_t count);

static struct kobj_attribute cpe_load_attr =
	__ATTR(cpe_load, 0600, NULL, cpe_load_store);

static struct attribute *attrs[] = {
	&cpe_load_attr.attr,
	NULL,
};

static struct attribute_group attr_grp = {
	.attrs = attrs,
};

static struct cpe_load_priv cpe_priv;

static inline int param_is_mask(int p)
{
	return ((p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
@@ -2026,6 +2053,44 @@ static int msm_snd_get_ext_clk_cnt(void)
	return clk_users;
}

static int apq8084_tomtom_cpe_enable(struct snd_soc_codec *codec)
{
	int ret = 0;

	ret = tomtom_enable_cpe(codec);
	if (IS_ERR_VALUE(ret))
		pr_err("%s: CPE enable failed, err (0x%x)\n",
			__func__, ret);
	return ret;
}

static ssize_t cpe_load_store(struct kobject *kobj,
	struct kobj_attribute *attr,
	const char *buf,
	size_t count)
{
	int ret = 0;

	if (cpe_load) {
		pr_err("%s: CPE already loaded\n",
			__func__);
		return count;
	}

	sscanf(buf, "%du", &cpe_load);

	if (cpe_load) {
		ret = apq8084_tomtom_cpe_enable(cpe_priv.cdc_handle);
		if (IS_ERR_VALUE(ret))
			cpe_load = 0;
		else
			pr_info("%s: CPE enabled for tomtom_codec\n",
				__func__);
	}

	return count;
}

static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
{
	int err;
@@ -2203,12 +2268,17 @@ static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
		tomtom_register_ext_clk_cb(msm_snd_enable_codec_ext_clk,
					   msm_snd_get_ext_clk_cnt,
					   rtd->codec);
		err = tomtom_enable_cpe(rtd->codec);
		if (IS_ERR_VALUE(err)) {
			pr_err("%s: Failed to enable cpe, err = 0x%x\n",
				__func__, err);
			/* Don't fail card registraion if CPE failed */
			err = 0;
		cpe_priv.cdc_handle = codec;
		cpe_priv.attr_group = &attr_grp;
		cpe_priv.cpe_load_kobj = kobject_create_and_add("snd_apq8084",
						       kernel_kobj);
		if (!cpe_priv.cpe_load_kobj) {
			pr_err("%s: cpe_load: sysfs create_add failed\n",
				__func__);
		} else if (sysfs_create_group(cpe_priv.cpe_load_kobj,
					      cpe_priv.attr_group)) {
			pr_err("%s: sysfs_create_group failed\n", __func__);
			kobject_del(cpe_priv.cpe_load_kobj);
		}
	} else
		taiko_event_register(apq8084_codec_event_cb, rtd->codec);