On 11/04/2020 09:02, Ajit Pandey wrote:
lpass_dai will store clocks related to respective dai's and it will
be initialized during probe based on variant clock names.
Signed-off-by: Ajit Pandey <ajitp@xxxxxxxxxxxxxx>
I dont understand why do we need this change? What is the advantage of doing this way vs the existing one?
--srini
Actually I've kept this in chain to add dai modes properties later in chain in this struct but with adoption of Stephen patch now , i guess we don't have any significant advantage now. I'll probably drop this patch during v2 submission.ÂÂÂÂÂ --Ajit---
 sound/soc/qcom/lpass-cpu.c | 89 ++++++++++++++++++++++++++--------------------
 sound/soc/qcom/lpass.h | 18 +++++-----
 2 files changed, 61 insertions(+), 46 deletions(-)
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index dbce7e9..492f27b 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -23,13 +23,15 @@ static int lpass_cpu_daiops_set_sysclk(struct snd_soc_dai *dai, int clk_id,
ÂÂÂÂÂÂÂÂÂ unsigned int freq, int dir)
 {
ÂÂÂÂÂ struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
-ÂÂÂ int ret;
-
-ÂÂÂ ret = clk_set_rate(drvdata->mi2s_osr_clk[dai->driver->id], freq);
-ÂÂÂ if (ret)
-ÂÂÂÂÂÂÂ dev_err(dai->dev, "error setting mi2s osrclk to %u: %d\n",
-ÂÂÂÂÂÂÂÂÂÂÂ freq, ret);
+ÂÂÂ struct lpass_dai *dai_data = drvdata->dai_priv[dai->driver->id];
+ÂÂÂ int ret = 0;
 + if (dai_data->osr_clk != NULL) {
+ÂÂÂÂÂÂÂ ret = clk_set_rate(dai_data->osr_clk, freq);
+ÂÂÂÂÂÂÂ if (ret)
+ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dai->dev, "error setting mi2s osrclk to %u:%d\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ freq, ret);
+ÂÂÂ }
ÂÂÂÂÂ return ret;
 }
 @@ -37,18 +39,22 @@ static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream,
ÂÂÂÂÂÂÂÂÂ struct snd_soc_dai *dai)
 {
ÂÂÂÂÂ struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
+ÂÂÂ struct lpass_dai *dai_data = drvdata->dai_priv[dai->driver->id];
ÂÂÂÂÂ int ret;
 - ret = clk_prepare_enable(drvdata->mi2s_osr_clk[dai->driver->id]);
-ÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂ dev_err(dai->dev, "error in enabling mi2s osr clk: %d\n", ret);
-ÂÂÂÂÂÂÂ return ret;
+ÂÂÂ if (dai_data->osr_clk != NULL) {
+ÂÂÂÂÂÂÂ ret = clk_prepare_enable(dai_data->osr_clk);
+ÂÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dai->dev,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "error in enabling mi2s osr clk: %d\n", ret);
+ÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂÂ }
ÂÂÂÂÂ }
 - ret = clk_prepare_enable(drvdata->mi2s_bit_clk[dai->driver->id]);
+ÂÂÂ ret = clk_prepare_enable(dai_data->bit_clk);
ÂÂÂÂÂ if (ret) {
ÂÂÂÂÂÂÂÂÂ dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret);
- clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
+ÂÂÂÂÂÂÂ clk_disable_unprepare(dai_data->osr_clk);
ÂÂÂÂÂÂÂÂÂ return ret;
ÂÂÂÂÂ }
 @@ -59,16 +65,18 @@ static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream,
ÂÂÂÂÂÂÂÂÂ struct snd_soc_dai *dai)
 {
ÂÂÂÂÂ struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
+ÂÂÂ struct lpass_dai *dai_data = drvdata->dai_priv[dai->driver->id];
 - clk_disable_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]);
+ÂÂÂ clk_disable_unprepare(dai_data->bit_clk);
 - clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
+ÂÂÂ clk_disable_unprepare(dai_data->osr_clk);
 }
  static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
ÂÂÂÂÂÂÂÂÂ struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
ÂÂÂÂÂ struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
+ÂÂÂ struct lpass_dai *dai_data = drvdata->dai_priv[dai->driver->id];
ÂÂÂÂÂ snd_pcm_format_t format = params_format(params);
ÂÂÂÂÂ unsigned int channels = params_channels(params);
ÂÂÂÂÂ unsigned int rate = params_rate(params);
@@ -163,8 +171,7 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
ÂÂÂÂÂÂÂÂÂ return ret;
ÂÂÂÂÂ }
 - ret = clk_set_rate(drvdata->mi2s_bit_clk[dai->driver->id],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rate * bitwidth * 2);
+ÂÂÂ ret = clk_set_rate(dai_data->bit_clk, rate * bitwidth * 2);
ÂÂÂÂÂ if (ret) {
ÂÂÂÂÂÂÂÂÂ dev_err(dai->dev, "error setting mi2s bitclk to %u: %d\n",
ÂÂÂÂÂÂÂÂÂÂÂÂÂ rate * bitwidth * 2, ret);
@@ -413,6 +420,25 @@ static bool lpass_cpu_regmap_volatile(struct device *dev, unsigned int reg)
ÂÂÂÂÂ .cache_type = REGCACHE_FLAT,
 };
 +static int lpass_init_dai_clocks(struct device *dev,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct lpass_data *drvdata)
+{
+ÂÂÂ struct lpass_dai *dai;
+ÂÂÂ struct lpass_variant *v = drvdata->variant;
+ÂÂÂ int i;
+
+ÂÂÂ for (i = 0; i < v->num_dai; i++) {
+
+ÂÂÂÂÂÂÂ dai = drvdata->dai_priv[i];
+
+ÂÂÂÂÂÂÂ dai->osr_clk = devm_clk_get_optional(dev,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ v->dai_osr_clk_names[i]);
+ÂÂÂÂÂÂÂ dai->bit_clk = devm_clk_get(dev, v->dai_bit_clk_names[i]);
+ÂÂÂ }
+
+ÂÂÂ return 0;
+}
+
 int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
 {
ÂÂÂÂÂ struct lpass_data *drvdata;
@@ -421,7 +447,7 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
ÂÂÂÂÂ struct lpass_variant *variant;
ÂÂÂÂÂ struct device *dev = &pdev->dev;
ÂÂÂÂÂ const struct of_device_id *match;
-ÂÂÂ int ret, i, dai_id;
+ÂÂÂ int ret, i;
 Â dsp_of_node = of_parse_phandle(pdev->dev.of_node, "qcom,adsp", 0);
ÂÂÂÂÂ if (dsp_of_node) {
@@ -467,28 +493,15 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
ÂÂÂÂÂÂÂÂÂ variant->init(pdev);
 Â for (i = 0; i < variant->num_dai; i++) {
-ÂÂÂÂÂÂÂ dai_id = variant->dai_driver[i].id;
-ÂÂÂÂÂÂÂ drvdata->mi2s_osr_clk[dai_id] = devm_clk_get(&pdev->dev,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ variant->dai_osr_clk_names[i]);
-ÂÂÂÂÂÂÂ if (IS_ERR(drvdata->mi2s_osr_clk[dai_id])) {
-ÂÂÂÂÂÂÂÂÂÂÂ dev_warn(&pdev->dev,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "%s() error getting optional %s: %ld\n",
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __func__,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ variant->dai_osr_clk_names[i],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ PTR_ERR(drvdata->mi2s_osr_clk[dai_id]));
-
-ÂÂÂÂÂÂÂÂÂÂÂ drvdata->mi2s_osr_clk[dai_id] = NULL;
-ÂÂÂÂÂÂÂ }
+ÂÂÂÂÂÂÂ drvdata->dai_priv[i] = devm_kzalloc(dev,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(struct lpass_dai),
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
+ÂÂÂ }
 - drvdata->mi2s_bit_clk[dai_id] = devm_clk_get(&pdev->dev,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ variant->dai_bit_clk_names[i]);
-ÂÂÂÂÂÂÂ if (IS_ERR(drvdata->mi2s_bit_clk[dai_id])) {
-ÂÂÂÂÂÂÂÂÂÂÂ dev_err(&pdev->dev,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "error getting %s: %ld\n",
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ variant->dai_bit_clk_names[i],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ PTR_ERR(drvdata->mi2s_bit_clk[dai_id]));
-ÂÂÂÂÂÂÂÂÂÂÂ return PTR_ERR(drvdata->mi2s_bit_clk[dai_id]);
-ÂÂÂÂÂÂÂ }
+ÂÂÂ ret = lpass_init_dai_clocks(dev, drvdata);
+ÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂ dev_err(&pdev->dev, "error intializing dai clock: %d\n", ret);
+ÂÂÂÂÂÂÂ return ret;
ÂÂÂÂÂ }
 Â drvdata->ahbix_clk = devm_clk_get(&pdev->dev, "ahbix-clk");
diff --git a/sound/soc/qcom/lpass.h b/sound/soc/qcom/lpass.h
index 17113d3..b729686 100644
--- a/sound/soc/qcom/lpass.h
+++ b/sound/soc/qcom/lpass.h
@@ -13,9 +13,14 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 -#define LPASS_AHBIX_CLOCK_FREQUENCY 131072000
-#define LPASS_MAX_MI2S_PORTSÂÂÂÂÂÂÂÂÂÂÂ (8)
-#define LPASS_MAX_DMA_CHANNELSÂÂÂÂÂÂÂÂÂÂÂ (8)
+#define LPASS_AHBIX_CLOCK_FREQUENCYÂÂÂÂÂÂÂÂÂÂÂ 131072000
+#define LPASS_MAX_MI2S_PORTSÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (8)
+#define LPASS_MAX_DMA_CHANNELSÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (8)
+
+struct lpass_dai {
+ÂÂÂ struct clk *osr_clk;
+ÂÂÂ struct clk *bit_clk;
+};
  /* Both the CPU DAI and platform drivers will access this data */
 struct lpass_data {
@@ -23,11 +28,8 @@ struct lpass_data {
ÂÂÂÂÂ /* AHB-I/X bus clocks inside the low-power audio subsystem (LPASS) */
ÂÂÂÂÂ struct clk *ahbix_clk;
 - /* MI2S system clock */
-ÂÂÂ struct clk *mi2s_osr_clk[LPASS_MAX_MI2S_PORTS];
-
-ÂÂÂ /* MI2S bit clock (derived from system clock by a divider */
-ÂÂÂ struct clk *mi2s_bit_clk[LPASS_MAX_MI2S_PORTS];
+ÂÂÂ /* MI2S dai specific configuration */
+ÂÂÂ struct lpass_dai *dai_priv[LPASS_MAX_MI2S_PORTS];
 Â /* low-power audio interface (LPAIF) registers */
ÂÂÂÂÂ void __iomem *lpaif;