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

Commit 2b55a309 authored by Deven Patel's avatar Deven Patel Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: codecs: Add audio MCLK support for APQ8096



For APQ8096 target, codec MCLK control needs to be sent to DSP
when audio use cases are enabled.

CRs-fixed: 992134
Change-Id: I6c04f27119afde7203c38fc9c471a17ec2b37d0a
Signed-off-by: default avatarDeven Patel <cdevenp@codeaurora.org>
parent dc9078ea
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -542,4 +542,5 @@
#define clk_audio_ap_clk 0x312ac429
#define clk_audio_pmi_clk 0xb7ba2274
#define clk_audio_ap_clk2 0xf0fbaf5b
#define clk_audio_lpass_mclk2 0x0122abee
#endif
+86 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
enum clk_mux {
	AP_CLK2,
	LPASS_MCLK,
	LPASS_MCLK2,
};

struct pinctrl_info {
@@ -77,6 +78,15 @@ static const struct afe_clk_cfg lpass_default = {
	0,
};

static struct afe_clk_set lpass_default2 = {
	Q6AFE_LPASS_CLK_CONFIG_API_VERSION,
	Q6AFE_LPASS_CLK_ID_SPEAKER_I2S_OSR,
	Q6AFE_LPASS_IBIT_CLK_12_P288_MHZ,
	Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
	Q6AFE_LPASS_CLK_ROOT_DEFAULT,
	0,
};

static inline struct audio_ext_ap_clk *to_audio_ap_clk(struct clk *clk)
{
	return container_of(clk, struct audio_ext_ap_clk, c);
@@ -224,6 +234,54 @@ err:
	kfree(lpass_clk);
}

static int audio_ext_lpass_mclk2_prepare(struct clk *clk)
{
	struct audio_ext_lpass_mclk *audio_lpass_mclk2;
	struct pinctrl_info *pnctrl_info;
	int ret;

	audio_lpass_mclk2 = container_of(clk, struct audio_ext_lpass_mclk, c);
	pnctrl_info = &audio_lpass_mclk2->pnctrl_info;

	ret = pinctrl_select_state(pnctrl_info->pinctrl,
				   pnctrl_info->active);
	if (ret) {
		pr_err("%s: active state select failed with %d\n",
			__func__, ret);
		return -EIO;
	}

	lpass_default2.enable = 1;
	ret = afe_set_lpass_clk_cfg(IDX_RSVD_3, &lpass_default2);
	if (ret < 0) {
		pr_err("%s: failed to set clock, ret = %d\n", __func__, ret);
		return -EINVAL;
	}

	return 0;
}

static void audio_ext_lpass_mclk2_unprepare(struct clk *clk)
{
	struct audio_ext_lpass_mclk *audio_lpass_mclk2;
	struct pinctrl_info *pnctrl_info;
	int ret;

	audio_lpass_mclk2 = container_of(clk, struct audio_ext_lpass_mclk, c);
	pnctrl_info = &audio_lpass_mclk2->pnctrl_info;

	ret = pinctrl_select_state(pnctrl_info->pinctrl,
				   pnctrl_info->sleep);
	if (ret)
		pr_err("%s: sleep state select failed with %d\n",
			__func__, ret);

	lpass_default2.enable = 0;
	ret = afe_set_lpass_clk_cfg(IDX_RSVD_3, &lpass_default2);
	if (ret < 0)
		pr_err("%s: failed to reset clock, ret = %d\n", __func__, ret);
}

static struct clk_ops audio_ext_ap_clk_ops = {
	.prepare = audio_ext_clk_prepare,
	.unprepare = audio_ext_clk_unprepare,
@@ -239,6 +297,11 @@ static struct clk_ops audio_ext_lpass_mclk_ops = {
	.unprepare = audio_ext_lpass_mclk_unprepare,
};

static struct clk_ops audio_ext_lpass_mclk2_ops = {
	.prepare = audio_ext_lpass_mclk2_prepare,
	.unprepare = audio_ext_lpass_mclk2_unprepare,
};

static struct audio_ext_pmi_clk audio_pmi_clk = {
	.gpio = -EINVAL,
	.c = {
@@ -273,11 +336,20 @@ static struct audio_ext_lpass_mclk audio_lpass_mclk = {
	},
};

static struct audio_ext_lpass_mclk audio_lpass_mclk2 = {
	.c = {
		.dbg_name = "audio_ext_lpass_mclk2",
		.ops = &audio_ext_lpass_mclk2_ops,
		CLK_INIT(audio_lpass_mclk2.c),
	},
};

static struct clk_lookup audio_ref_clock[] = {
	CLK_LIST(audio_ap_clk),
	CLK_LIST(audio_pmi_clk),
	CLK_LIST(audio_ap_clk2),
	CLK_LIST(audio_lpass_mclk),
	CLK_LIST(audio_lpass_mclk2),
};

static int audio_get_pinctrl(struct platform_device *pdev, enum clk_mux mux)
@@ -293,6 +365,9 @@ static int audio_get_pinctrl(struct platform_device *pdev, enum clk_mux mux)
	case LPASS_MCLK:
		pnctrl_info = &audio_lpass_mclk.pnctrl_info;
		break;
	case LPASS_MCLK2:
		pnctrl_info = &audio_lpass_mclk2.pnctrl_info;
		break;
	default:
		dev_err(&pdev->dev, "%s Not a valid MUX ID: %d\n",
			__func__, mux);
@@ -368,6 +443,11 @@ static int audio_ref_clk_probe(struct platform_device *pdev)
			dev_err(&pdev->dev, "%s: Parsing pinctrl %s failed\n",
				__func__, "LPASS_MCLK");

		ret = audio_get_pinctrl(pdev, LPASS_MCLK2);
		if (ret)
			dev_dbg(&pdev->dev, "%s: Parsing pinctrl %s failed\n",
				__func__, "LPASS_MCLK2");

		ret = of_msm_clock_register(pdev->dev.of_node, audio_ref_clock,
			      ARRAY_SIZE(audio_ref_clock));
		if (ret)
@@ -458,6 +538,12 @@ static int audio_ref_clk_remove(struct platform_device *pdev)
		pnctrl_info->pinctrl = NULL;
	}

	pnctrl_info = &audio_lpass_mclk2.pnctrl_info;
	if (pnctrl_info->pinctrl) {
		devm_pinctrl_put(pnctrl_info->pinctrl);
		pnctrl_info->pinctrl = NULL;
	}

	return 0;
}