diff mbox series

[v3,6/8] ASoC: qcom: apq8016_sbc: Add support for msm8953 SoC

Message ID 20240731-msm8953-msm8976-asoc-v3-6-163f23c3a28d@gmail.com
State New
Headers show
Series MSM8953/MSM8976 ASoC support | expand

Commit Message

Adam Skladowski July 31, 2024, 3:25 p.m. UTC
From: Vladimir Lypak <vladimir.lypak@gmail.com>

Introduce support for audio card on MSM8953 platform.
Main difference between MSM8953 and MSM8916 is Q6AFE CLK API
supported by firmware which influence way we set codec clocks.
SoCs shipping on at least msm-3.18 should use v2 clocks.

Signed-off-by: Vladimir Lypak <vladimir.lypak@gmail.com>
[Adam: rename functions, add msg]
Co-developed-by: Adam Skladowski <a39.skl@gmail.com>
Signed-off-by: Adam Skladowski <a39.skl@gmail.com>
---
 sound/soc/qcom/apq8016_sbc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

Comments

Dmitry Baryshkov Aug. 1, 2024, 8:22 a.m. UTC | #1
On Wed, Jul 31, 2024 at 05:25:30PM GMT, Adam Skladowski wrote:
> From: Vladimir Lypak <vladimir.lypak@gmail.com>
> 
> Introduce support for audio card on MSM8953 platform.
> Main difference between MSM8953 and MSM8916 is Q6AFE CLK API
> supported by firmware which influence way we set codec clocks.
> SoCs shipping on at least msm-3.18 should use v2 clocks.
> 
> Signed-off-by: Vladimir Lypak <vladimir.lypak@gmail.com>
> [Adam: rename functions, add msg]
> Co-developed-by: Adam Skladowski <a39.skl@gmail.com>
> Signed-off-by: Adam Skladowski <a39.skl@gmail.com>
> ---
>  sound/soc/qcom/apq8016_sbc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 41 insertions(+), 2 deletions(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Adam Skladowski Aug. 9, 2024, 7:31 p.m. UTC | #2
On 8/1/24 12:47, Stephan Gerhold wrote:
> On Wed, Jul 31, 2024 at 05:25:30PM +0200, Adam Skladowski wrote:
>> From: Vladimir Lypak <vladimir.lypak@gmail.com>
>>
>> Introduce support for audio card on MSM8953 platform.
>> Main difference between MSM8953 and MSM8916 is Q6AFE CLK API
>> supported by firmware which influence way we set codec clocks.
>> SoCs shipping on at least msm-3.18 should use v2 clocks.
>>
>> Signed-off-by: Vladimir Lypak <vladimir.lypak@gmail.com>
>> [Adam: rename functions, add msg]
>> Co-developed-by: Adam Skladowski <a39.skl@gmail.com>
>> Signed-off-by: Adam Skladowski <a39.skl@gmail.com>
>> ---
>>  sound/soc/qcom/apq8016_sbc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 41 insertions(+), 2 deletions(-)
>>
>> diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c
>> index 5a29adbd3f82..3ed35beb671a 100644
>> --- a/sound/soc/qcom/apq8016_sbc.c
>> +++ b/sound/soc/qcom/apq8016_sbc.c
>> @@ -22,6 +22,11 @@
>>  
> Is there a particular reason why you decided to hardcode the
> q6afe_clk_ver for the SoCs rather than finishing up the dynamic
> detection Otto proposed [1]?
>
> This works for MSM8953 but there are a few SoCs like MSM8909 where
> both clock API versions exist (depending on the firmware versions).
> If we want to support them at some point, we will need the dynamic
> detection anyway. It would be nice to finish up that patch set.
>
> Thanks,
> Stephan
>
> [1]: https://lore.kernel.org/linux-arm-msm/20231029165716.69878-1-otto.pflueger@abscue.de/
This probably sound obvious but i don't understand takes Srinivas
had on these patches.
On top i don't feel good sending code i don't understand much.
On a note i managed to slightly modify fallback commit
and provide match table translating new clks into v1.
In theory if we want we can drop snd_soc_component_set_sysclk()
from soundcard driver and use devm_clk_get/clk_set_rate/clk_prepare_enable
to manage clocks provided by q6afe_clocks.
Biggest issue for me is lack of people who i can even discuss with about,
even here i fail to see much feedback.
diff mbox series

Patch

diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c
index 5a29adbd3f82..3ed35beb671a 100644
--- a/sound/soc/qcom/apq8016_sbc.c
+++ b/sound/soc/qcom/apq8016_sbc.c
@@ -22,6 +22,11 @@ 
 
 #define MI2S_COUNT  (MI2S_QUINARY + 1)
 
+enum afe_clk_api {
+	Q6AFE_CLK_V1,
+	Q6AFE_CLK_V2
+};
+
 struct apq8016_sbc_data {
 	struct snd_soc_card card;
 	void __iomem *mic_iomux;
@@ -29,6 +34,7 @@  struct apq8016_sbc_data {
 	void __iomem *quin_iomux;
 	struct snd_soc_jack jack;
 	bool jack_setup;
+	enum afe_clk_api q6afe_clk_ver;
 	int mi2s_clk_count[MI2S_COUNT];
 };
 
@@ -192,6 +198,28 @@  static int qdsp6_dai_get_lpass_id(struct snd_soc_dai *cpu_dai)
 	}
 }
 
+static int qdsp6_get_clk_id(struct apq8016_sbc_data *data, int mi2s_id)
+{
+	if (data->q6afe_clk_ver == Q6AFE_CLK_V2) {
+		switch (mi2s_id) {
+		case MI2S_PRIMARY:
+			return Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT;
+		case MI2S_SECONDARY:
+			return Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT;
+		case MI2S_TERTIARY:
+			return Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT;
+		case MI2S_QUATERNARY:
+			return Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT;
+		case MI2S_QUINARY:
+			return Q6AFE_LPASS_CLK_ID_QUI_MI2S_IBIT;
+		default:
+			break;
+		}
+	}
+	/* If AFE CLK isn't V2 return V1 */
+	return LPAIF_BIT_CLK;
+}
+
 static int msm8916_qdsp6_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
@@ -215,7 +243,7 @@  static int msm8916_qdsp6_startup(struct snd_pcm_substream *substream)
 	if (++data->mi2s_clk_count[mi2s] > 1)
 		return 0;
 
-	ret = snd_soc_dai_set_sysclk(cpu_dai, LPAIF_BIT_CLK, MI2S_BCLK_RATE, 0);
+	ret = snd_soc_dai_set_sysclk(cpu_dai, qdsp6_get_clk_id(data, mi2s), MI2S_BCLK_RATE, 0);
 	if (ret)
 		dev_err(card->dev, "Failed to enable LPAIF bit clk: %d\n", ret);
 	return ret;
@@ -236,7 +264,7 @@  static void msm8916_qdsp6_shutdown(struct snd_pcm_substream *substream)
 	if (--data->mi2s_clk_count[mi2s] > 0)
 		return;
 
-	ret = snd_soc_dai_set_sysclk(cpu_dai, LPAIF_BIT_CLK, 0, 0);
+	ret = snd_soc_dai_set_sysclk(cpu_dai, qdsp6_get_clk_id(data, mi2s), 0, 0);
 	if (ret)
 		dev_err(card->dev, "Failed to disable LPAIF bit clk: %d\n", ret);
 }
@@ -265,10 +293,12 @@  static int msm8916_qdsp6_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
 static void msm8916_qdsp6_add_ops(struct snd_soc_card *card)
 {
 	struct snd_soc_dai_link *link;
+	struct apq8016_sbc_data *pdata = snd_soc_card_get_drvdata(card);
 	int i;
 
 	/* Make it obvious to userspace that QDSP6 is used */
 	card->components = "qdsp6";
+	pdata->q6afe_clk_ver = Q6AFE_CLK_V1;
 
 	for_each_card_prelinks(card, i, link) {
 		if (link->no_pcm) {
@@ -279,6 +309,14 @@  static void msm8916_qdsp6_add_ops(struct snd_soc_card *card)
 	}
 }
 
+static void msm8953_qdsp6_add_ops(struct snd_soc_card *card)
+{
+	struct apq8016_sbc_data *pdata = snd_soc_card_get_drvdata(card);
+
+	msm8916_qdsp6_add_ops(card);
+	pdata->q6afe_clk_ver = Q6AFE_CLK_V2;
+}
+
 static const struct snd_kcontrol_new apq8016_sbc_snd_controls[] = {
 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
 	SOC_DAPM_PIN_SWITCH("Mic Jack"),
@@ -344,6 +382,7 @@  static int apq8016_sbc_platform_probe(struct platform_device *pdev)
 static const struct of_device_id apq8016_sbc_device_id[] __maybe_unused = {
 	{ .compatible = "qcom,apq8016-sbc-sndcard", .data = apq8016_sbc_add_ops },
 	{ .compatible = "qcom,msm8916-qdsp6-sndcard", .data = msm8916_qdsp6_add_ops },
+	{ .compatible = "qcom,msm8953-qdsp6-sndcard", .data = msm8953_qdsp6_add_ops },
 	{},
 };
 MODULE_DEVICE_TABLE(of, apq8016_sbc_device_id);