hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/sound/soc/rockchip/rockchip_i2s_tdm.c
....@@ -28,7 +28,8 @@
2828 #include <sound/dmaengine_pcm.h>
2929
3030 #include "rockchip_i2s_tdm.h"
31
-#include "rockchip_dlp.h"
31
+#include "rockchip_dlp_pcm.h"
32
+#include "rockchip_utils.h"
3233
3334 #define DRV_NAME "rockchip-i2s-tdm"
3435
....@@ -1678,6 +1679,25 @@
16781679 return ret;
16791680 }
16801681
1682
+static void rockchip_i2s_tdm_get_performance(struct snd_pcm_substream *substream,
1683
+ struct snd_pcm_hw_params *params,
1684
+ struct snd_soc_dai *dai,
1685
+ unsigned int csr)
1686
+{
1687
+ struct rk_i2s_tdm_dev *i2s_tdm = to_info(dai);
1688
+ unsigned int tdl;
1689
+ int fifo;
1690
+
1691
+ regmap_read(i2s_tdm->regmap, I2S_DMACR, &tdl);
1692
+
1693
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1694
+ fifo = I2S_DMACR_TDL_V(tdl) * I2S_TXCR_CSR_V(csr);
1695
+ else
1696
+ fifo = I2S_DMACR_RDL_V(tdl) * I2S_RXCR_CSR_V(csr);
1697
+
1698
+ rockchip_utils_get_performance(substream, params, dai, fifo);
1699
+}
1700
+
16811701 static int rockchip_i2s_tdm_hw_params(struct snd_pcm_substream *substream,
16821702 struct snd_pcm_hw_params *params,
16831703 struct snd_soc_dai *dai)
....@@ -1740,6 +1760,8 @@
17401760 if (ret < 0)
17411761 goto err;
17421762
1763
+ rockchip_i2s_tdm_get_performance(substream, params, dai, ret);
1764
+
17431765 val |= ret;
17441766 if (!is_params_dirty(substream, dai, div_bclk, div_lrck, val))
17451767 return 0;
....@@ -1753,6 +1775,13 @@
17531775
17541776 err:
17551777 return ret;
1778
+}
1779
+static int rockchip_i2s_tdm_hw_free(struct snd_pcm_substream *substream,
1780
+ struct snd_soc_dai *dai)
1781
+{
1782
+ rockchip_utils_put_performance(substream, dai);
1783
+
1784
+ return 0;
17561785 }
17571786
17581787 static int rockchip_i2s_tdm_trigger(struct snd_pcm_substream *substream,
....@@ -1817,8 +1846,8 @@
18171846 static int rockchip_i2s_tdm_clk_compensation_get(struct snd_kcontrol *kcontrol,
18181847 struct snd_ctl_elem_value *ucontrol)
18191848 {
1820
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
1821
- struct rk_i2s_tdm_dev *i2s_tdm = snd_soc_dai_get_drvdata(dai);
1849
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1850
+ struct rk_i2s_tdm_dev *i2s_tdm = snd_soc_component_get_drvdata(component);
18221851
18231852 ucontrol->value.integer.value[0] = i2s_tdm->clk_ppm;
18241853
....@@ -1828,8 +1857,8 @@
18281857 static int rockchip_i2s_tdm_clk_compensation_put(struct snd_kcontrol *kcontrol,
18291858 struct snd_ctl_elem_value *ucontrol)
18301859 {
1831
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
1832
- struct rk_i2s_tdm_dev *i2s_tdm = snd_soc_dai_get_drvdata(dai);
1860
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1861
+ struct rk_i2s_tdm_dev *i2s_tdm = snd_soc_component_get_drvdata(component);
18331862 int ret = 0, ppm = 0;
18341863
18351864 if ((ucontrol->value.integer.value[0] < CLK_PPM_MIN) ||
....@@ -2119,6 +2148,7 @@
21192148 .startup = rockchip_i2s_tdm_startup,
21202149 .shutdown = rockchip_i2s_tdm_shutdown,
21212150 .hw_params = rockchip_i2s_tdm_hw_params,
2151
+ .hw_free = rockchip_i2s_tdm_hw_free,
21222152 .set_sysclk = rockchip_i2s_tdm_set_sysclk,
21232153 .set_fmt = rockchip_i2s_tdm_set_fmt,
21242154 .set_tdm_slot = rockchip_dai_tdm_slot,
....@@ -2548,12 +2578,13 @@
25482578 return rockchip_i2s_tdm_path_prepare(i2s_tdm, np, 1);
25492579 }
25502580
2551
-static int rockchip_i2s_tdm_get_fifo_count(struct device *dev, int stream)
2581
+static int rockchip_i2s_tdm_get_fifo_count(struct device *dev,
2582
+ struct snd_pcm_substream *substream)
25522583 {
25532584 struct rk_i2s_tdm_dev *i2s_tdm = dev_get_drvdata(dev);
25542585 int val = 0;
25552586
2556
- if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2587
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
25572588 regmap_read(i2s_tdm->regmap, I2S_TXFIFOLR, &val);
25582589 else
25592590 regmap_read(i2s_tdm->regmap, I2S_RXFIFOLR, &val);
....@@ -2640,6 +2671,29 @@
26402671 mclk_rate, bclk_rate, DEFAULT_FS);
26412672
26422673 return 0;
2674
+}
2675
+
2676
+static int rockchip_i2s_tdm_register_platform(struct device *dev)
2677
+{
2678
+ int ret = 0;
2679
+
2680
+ if (device_property_read_bool(dev, "rockchip,no-dmaengine")) {
2681
+ dev_info(dev, "Used for Multi-DAI\n");
2682
+ return 0;
2683
+ }
2684
+
2685
+ if (device_property_read_bool(dev, "rockchip,digital-loopback")) {
2686
+ ret = devm_snd_dmaengine_dlp_register(dev, &dconfig);
2687
+ if (ret)
2688
+ dev_err(dev, "Could not register DLP\n");
2689
+ return ret;
2690
+ }
2691
+
2692
+ ret = devm_snd_dmaengine_pcm_register(dev, NULL, 0);
2693
+ if (ret)
2694
+ dev_err(dev, "Could not register PCM\n");
2695
+
2696
+ return ret;
26432697 }
26442698
26452699 static int rockchip_i2s_tdm_probe(struct platform_device *pdev)
....@@ -2919,28 +2973,16 @@
29192973 goto err_pm_disable;
29202974 }
29212975
2976
+ ret = rockchip_i2s_tdm_register_platform(&pdev->dev);
2977
+ if (ret)
2978
+ goto err_suspend;
2979
+
29222980 ret = devm_snd_soc_register_component(&pdev->dev,
29232981 &rockchip_i2s_tdm_component,
29242982 soc_dai, 1);
2925
-
29262983 if (ret) {
29272984 dev_err(&pdev->dev, "Could not register DAI\n");
29282985 goto err_suspend;
2929
- }
2930
-
2931
- if (of_property_read_bool(node, "rockchip,no-dmaengine")) {
2932
- dev_info(&pdev->dev, "Used for Multi-DAI\n");
2933
- return 0;
2934
- }
2935
-
2936
- if (of_property_read_bool(node, "rockchip,digital-loopback"))
2937
- ret = devm_snd_dmaengine_dlp_register(&pdev->dev, &dconfig);
2938
- else
2939
- ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
2940
-
2941
- if (ret) {
2942
- dev_err(&pdev->dev, "Could not register PCM\n");
2943
- return ret;
29442986 }
29452987
29462988 return 0;