From cf4ce59b3b70238352c7f1729f0f7223214828ad Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Fri, 20 Sep 2024 01:46:19 +0000
Subject: [PATCH] rtl88x2CE_WiFi_linux add concurrent mode

---
 kernel/sound/soc/rockchip/rockchip_multicodecs.c |   79 +++++++++++++++++++++++++++------------
 1 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/kernel/sound/soc/rockchip/rockchip_multicodecs.c b/kernel/sound/soc/rockchip/rockchip_multicodecs.c
index 8b1cb5f..e4b0a15 100644
--- a/kernel/sound/soc/rockchip/rockchip_multicodecs.c
+++ b/kernel/sound/soc/rockchip/rockchip_multicodecs.c
@@ -336,8 +336,8 @@
 static int rk_multicodecs_hw_params(struct snd_pcm_substream *substream,
 				    struct snd_pcm_hw_params *params)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct snd_soc_dai *codec_dai;
 	struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(rtd->card);
 	unsigned int mclk;
@@ -345,8 +345,7 @@
 
 	mclk = params_rate(params) * mc_data->mclk_fs;
 
-	for (i = 0; i < rtd->num_codecs; i++) {
-		codec_dai = rtd->codec_dais[i];
+	for_each_rtd_codec_dais(rtd, i, codec_dai) {
 		ret = snd_soc_dai_set_sysclk(codec_dai, substream->stream, mclk,
 					     SND_SOC_CLOCK_IN);
 		if (ret && ret != -ENOTSUPP) {
@@ -437,8 +436,7 @@
 		int i;
 
 		/* set jack for the first successful one */
-		for (i = 0; i < rtd->num_codecs; i++) {
-			codec_dai = rtd->codec_dais[i];
+		for_each_rtd_codec_dais(rtd, i, codec_dai) {
 			ret = snd_soc_component_set_jack(codec_dai->component,
 							 jack_headset, NULL);
 			if (ret >= 0)
@@ -458,9 +456,6 @@
 				dev_err(card->dev, "Failed to request headset detect irq");
 				return ret;
 			}
-
-			queue_delayed_work(system_power_efficient_wq,
-					   &mc_data->handler, msecs_to_jiffies(50));
 		}
 	}
 
@@ -584,13 +579,15 @@
 	struct snd_soc_card *card;
 	struct device_node *np = pdev->dev.of_node;
 	struct snd_soc_dai_link *link;
+	struct snd_soc_dai_link_component *cpus;
+	struct snd_soc_dai_link_component *platforms;
 	struct snd_soc_dai_link_component *codecs;
 	struct multicodecs_data *mc_data;
 	struct of_phandle_args args;
 	struct device_node *node;
 	struct input_dev *input;
 	u32 val;
-	int count, value;
+	int count, value, irq;
 	int ret = 0, i = 0, idx = 0;
 	const char *prefix = "rockchip,";
 
@@ -602,6 +599,14 @@
 
 	mc_data = devm_kzalloc(&pdev->dev, sizeof(*mc_data), GFP_KERNEL);
 	if (!mc_data)
+		return -ENOMEM;
+
+	cpus = devm_kzalloc(&pdev->dev, sizeof(*cpus), GFP_KERNEL);
+	if (!cpus)
+		return -ENOMEM;
+
+	platforms = devm_kzalloc(&pdev->dev, sizeof(*platforms), GFP_KERNEL);
+	if (!platforms)
 		return -ENOMEM;
 
 	card = &mc_data->snd_card;
@@ -617,6 +622,10 @@
 	link->stream_name = link->name;
 	link->init = rk_dailink_init;
 	link->ops = &rk_ops;
+	link->cpus = cpus;
+	link->platforms	= platforms;
+	link->num_cpus	= 1;
+	link->num_platforms = 1;
 	link->ignore_pmdown_time = 1;
 
 	card->dai_link = link;
@@ -673,11 +682,11 @@
 	/* Only reference the codecs[0].of_node which maybe as master. */
 	rk_multicodecs_parse_daifmt(np, codecs[0].of_node, mc_data, prefix);
 
-	link->cpu_of_node = of_parse_phandle(np, "rockchip,cpu", 0);
-	if (!link->cpu_of_node)
+	link->cpus->of_node = of_parse_phandle(np, "rockchip,cpu", 0);
+	if (!link->cpus->of_node)
 		return -ENODEV;
 
-	link->platform_of_node = link->cpu_of_node;
+	link->platforms->of_node = link->cpus->of_node;
 
 	mc_data->mclk_fs = DEFAULT_MCLK_FS;
 	if (!of_property_read_u32(np, "rockchip,mclk-fs", &val))
@@ -710,7 +719,7 @@
 
 		input = devm_input_allocate_device(&pdev->dev);
 		if (IS_ERR(input)) {
-			dev_err(&pdev->dev, "failed to allocate input device\n");
+			dev_err(&pdev->dev, "Failed to allocate input device\n");
 			return PTR_ERR(input);
 		}
 
@@ -733,7 +742,7 @@
 		mc_data->input = input;
 		ret = mc_keys_setup_polling(mc_data, mc_keys_poll);
 		if (ret) {
-			dev_err(&pdev->dev, "Unable to set up polling: %d\n", ret);
+			dev_err(&pdev->dev, "Failed to set up polling: %d\n", ret);
 			return ret;
 		}
 
@@ -742,7 +751,7 @@
 
 		ret = input_register_device(mc_data->input);
 		if (ret) {
-			dev_err(&pdev->dev, "Unable to register input device: %d\n", ret);
+			dev_err(&pdev->dev, "Failed to register input device: %d\n", ret);
 			return ret;
 		}
 	}
@@ -767,33 +776,51 @@
 
 	mc_data->extcon = devm_extcon_dev_allocate(&pdev->dev, headset_extcon_cable);
 	if (IS_ERR(mc_data->extcon)) {
-		dev_err(&pdev->dev, "allocate extcon failed\n");
+		dev_err(&pdev->dev, "Failed to allocate extcon\n");
 		return PTR_ERR(mc_data->extcon);
 	}
 
 	ret = devm_extcon_dev_register(&pdev->dev, mc_data->extcon);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register extcon: %d\n", ret);
+		dev_err(&pdev->dev, "Failed to register extcon: %d\n", ret);
 		return ret;
 	}
 
-	ret = snd_soc_of_parse_audio_routing(card, "rockchip,audio-routing");
-	if (ret < 0)
-		dev_warn(&pdev->dev, "Audio routing invalid/unspecified\n");
+	snd_soc_of_parse_audio_routing(card, "rockchip,audio-routing");
 
 	snd_soc_card_set_drvdata(card, mc_data);
+	platform_set_drvdata(pdev, card);
 
 	ret = devm_snd_soc_register_card(&pdev->dev, card);
-	if (ret == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
 	if (ret) {
-		dev_err(&pdev->dev, "card register failed %d\n", ret);
+		dev_err(&pdev->dev, "Failed to register card: %d\n", ret);
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, card);
+	irq = gpiod_to_irq(mc_data->hp_det_gpio);
+	if (irq >= 0)
+		queue_delayed_work(system_power_efficient_wq,
+				   &mc_data->handler, msecs_to_jiffies(50));
 
 	return ret;
+}
+
+static int rk_multicodec_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(card);
+
+	cancel_delayed_work_sync(&mc_data->handler);
+
+	return 0;
+}
+
+static void rk_multicodec_shutdown(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+	struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(card);
+
+	cancel_delayed_work_sync(&mc_data->handler);
 }
 
 static const struct of_device_id rockchip_multicodecs_of_match[] = {
@@ -805,6 +832,8 @@
 
 static struct platform_driver rockchip_multicodecs_driver = {
 	.probe = rk_multicodecs_probe,
+	.remove = rk_multicodec_remove,
+	.shutdown = rk_multicodec_shutdown,
 	.driver = {
 		.name = DRV_NAME,
 		.pm = &snd_soc_pm_ops,

--
Gitblit v1.6.2