j721e-evm.c (8ee18e769dd621104fecad584c84ec3c4c9ef3fa) j721e-evm.c (cfc9d37ab79ff19d44a17195e57b2828084d5896)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com
4 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
5 */
6
7#include <linux/clk.h>
8#include <linux/module.h>

--- 9 unchanged lines hidden (view full) ---

18
19/*
20 * Maximum number of configuration entries for prefixes:
21 * CPB: 2 (mcasp10 + codec)
22 * IVI: 3 (mcasp0 + 2x codec)
23 */
24#define J721E_CODEC_CONF_COUNT 5
25
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com
4 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
5 */
6
7#include <linux/clk.h>
8#include <linux/module.h>

--- 9 unchanged lines hidden (view full) ---

18
19/*
20 * Maximum number of configuration entries for prefixes:
21 * CPB: 2 (mcasp10 + codec)
22 * IVI: 3 (mcasp0 + 2x codec)
23 */
24#define J721E_CODEC_CONF_COUNT 5
25
26#define J721E_AUDIO_DOMAIN_CPB 0
27#define J721E_AUDIO_DOMAIN_IVI 1
26enum j721e_audio_domain_id {
27 J721E_AUDIO_DOMAIN_CPB = 0,
28 J721E_AUDIO_DOMAIN_IVI,
29 J721E_AUDIO_DOMAIN_LAST,
30};
28
29#define J721E_CLK_PARENT_48000 0
30#define J721E_CLK_PARENT_44100 1
31
32#define J721E_MAX_CLK_HSDIV 128
33#define PCM1368A_MAX_SYSCLK 36864000
34
35#define J721E_DAI_FMT (SND_SOC_DAIFMT_RIGHT_J | \

--- 37 unchanged lines hidden (view full) ---

73 struct snd_soc_card card;
74 struct snd_soc_dai_link *dai_links;
75 struct snd_soc_codec_conf codec_conf[J721E_CODEC_CONF_COUNT];
76 struct snd_interval rate_range;
77 const struct j721e_audio_match_data *match_data;
78 u32 pll_rates[2];
79 unsigned int hsdiv_rates[2];
80
31
32#define J721E_CLK_PARENT_48000 0
33#define J721E_CLK_PARENT_44100 1
34
35#define J721E_MAX_CLK_HSDIV 128
36#define PCM1368A_MAX_SYSCLK 36864000
37
38#define J721E_DAI_FMT (SND_SOC_DAIFMT_RIGHT_J | \

--- 37 unchanged lines hidden (view full) ---

76 struct snd_soc_card card;
77 struct snd_soc_dai_link *dai_links;
78 struct snd_soc_codec_conf codec_conf[J721E_CODEC_CONF_COUNT];
79 struct snd_interval rate_range;
80 const struct j721e_audio_match_data *match_data;
81 u32 pll_rates[2];
82 unsigned int hsdiv_rates[2];
83
81 struct j721e_audio_domain audio_domains[2];
84 struct j721e_audio_domain audio_domains[J721E_AUDIO_DOMAIN_LAST];
82
83 struct mutex mutex;
84};
85
86static const struct snd_soc_dapm_widget j721e_cpb_dapm_widgets[] = {
87 SND_SOC_DAPM_HP("CPB Stereo HP 1", NULL),
88 SND_SOC_DAPM_HP("CPB Stereo HP 2", NULL),
89 SND_SOC_DAPM_HP("CPB Stereo HP 3", NULL),

--- 102 unchanged lines hidden (view full) ---

192 }
193
194 if (ret) {
195 dev_err(priv->dev, "No valid clock configuration for %u Hz\n",
196 rate);
197 return ret;
198 }
199
85
86 struct mutex mutex;
87};
88
89static const struct snd_soc_dapm_widget j721e_cpb_dapm_widgets[] = {
90 SND_SOC_DAPM_HP("CPB Stereo HP 1", NULL),
91 SND_SOC_DAPM_HP("CPB Stereo HP 2", NULL),
92 SND_SOC_DAPM_HP("CPB Stereo HP 3", NULL),

--- 102 unchanged lines hidden (view full) ---

195 }
196
197 if (ret) {
198 dev_err(priv->dev, "No valid clock configuration for %u Hz\n",
199 rate);
200 return ret;
201 }
202
200 if (domain->parent_clk_id == -1 || priv->hsdiv_rates[domain->parent_clk_id] != scki) {
203 if (priv->hsdiv_rates[domain->parent_clk_id] != scki) {
201 dev_dbg(priv->dev,
204 dev_dbg(priv->dev,
202 "%s configuration for %u Hz: %s, %dxFS (SCKI: %u Hz)\n",
203 audio_domain == J721E_AUDIO_DOMAIN_CPB ? "CPB" : "IVI",
204 rate,
205 "domain%u configuration for %u Hz: %s, %dxFS (SCKI: %u Hz)\n",
206 audio_domain, rate,
205 clk_id == J721E_CLK_PARENT_48000 ? "PLL4" : "PLL15",
206 ratios_for_pcm3168a[i], scki);
207
208 if (domain->parent_clk_id != clk_id) {
209 ret = clk_set_parent(domain->codec.target,
210 domain->codec.parent[clk_id]);
211 if (ret)
212 return ret;

--- 45 unchanged lines hidden (view full) ---

258 unsigned int active_rate;
259 int ret = 0;
260 int i;
261
262 mutex_lock(&priv->mutex);
263
264 domain->active++;
265
207 clk_id == J721E_CLK_PARENT_48000 ? "PLL4" : "PLL15",
208 ratios_for_pcm3168a[i], scki);
209
210 if (domain->parent_clk_id != clk_id) {
211 ret = clk_set_parent(domain->codec.target,
212 domain->codec.parent[clk_id]);
213 if (ret)
214 return ret;

--- 45 unchanged lines hidden (view full) ---

260 unsigned int active_rate;
261 int ret = 0;
262 int i;
263
264 mutex_lock(&priv->mutex);
265
266 domain->active++;
267
266 if (priv->audio_domains[J721E_AUDIO_DOMAIN_CPB].rate)
267 active_rate = priv->audio_domains[J721E_AUDIO_DOMAIN_CPB].rate;
268 else
269 active_rate = priv->audio_domains[J721E_AUDIO_DOMAIN_IVI].rate;
268 for (i = 0; i < J721E_AUDIO_DOMAIN_LAST; i++) {
269 active_rate = priv->audio_domains[i].rate;
270 if (active_rate)
271 break;
272 }
270
271 if (active_rate)
272 ret = snd_pcm_hw_constraint_single(substream->runtime,
273 SNDRV_PCM_HW_PARAM_RATE,
274 active_rate);
275 else
276 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
277 SNDRV_PCM_HW_PARAM_RATE,
278 j721e_rule_rate, &priv->rate_range,
279 SNDRV_PCM_HW_PARAM_RATE, -1);
280
273
274 if (active_rate)
275 ret = snd_pcm_hw_constraint_single(substream->runtime,
276 SNDRV_PCM_HW_PARAM_RATE,
277 active_rate);
278 else
279 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
280 SNDRV_PCM_HW_PARAM_RATE,
281 j721e_rule_rate, &priv->rate_range,
282 SNDRV_PCM_HW_PARAM_RATE, -1);
283
284 mutex_unlock(&priv->mutex);
281
282 if (ret)
285
286 if (ret)
283 goto out;
287 return ret;
284
285 /* Reset TDM slots to 32 */
286 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 32);
287 if (ret && ret != -ENOTSUPP)
288
289 /* Reset TDM slots to 32 */
290 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 32);
291 if (ret && ret != -ENOTSUPP)
288 goto out;
292 return ret;
289
290 for_each_rtd_codec_dais(rtd, i, codec_dai) {
291 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 2, 32);
292 if (ret && ret != -ENOTSUPP)
293
294 for_each_rtd_codec_dais(rtd, i, codec_dai) {
295 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 2, 32);
296 if (ret && ret != -ENOTSUPP)
293 goto out;
297 return ret;
294 }
295
298 }
299
296 if (ret == -ENOTSUPP)
297 ret = 0;
298out:
299 if (ret)
300 domain->active--;
301 mutex_unlock(&priv->mutex);
302
303 return ret;
300 return 0;
304}
305
306static int j721e_audio_hw_params(struct snd_pcm_substream *substream,
307 struct snd_pcm_hw_params *params)
308{
309 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
310 struct snd_soc_card *card = rtd->card;
311 struct j721e_priv *priv = snd_soc_card_get_drvdata(card);

--- 508 unchanged lines hidden (view full) ---

820}
821
822static int j721e_soc_probe(struct platform_device *pdev)
823{
824 struct device_node *node = pdev->dev.of_node;
825 struct snd_soc_card *card;
826 const struct of_device_id *match;
827 struct j721e_priv *priv;
301}
302
303static int j721e_audio_hw_params(struct snd_pcm_substream *substream,
304 struct snd_pcm_hw_params *params)
305{
306 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
307 struct snd_soc_card *card = rtd->card;
308 struct j721e_priv *priv = snd_soc_card_get_drvdata(card);

--- 508 unchanged lines hidden (view full) ---

817}
818
819static int j721e_soc_probe(struct platform_device *pdev)
820{
821 struct device_node *node = pdev->dev.of_node;
822 struct snd_soc_card *card;
823 const struct of_device_id *match;
824 struct j721e_priv *priv;
828 int link_cnt, conf_cnt, ret;
825 int link_cnt, conf_cnt, ret, i;
829
830 if (!node) {
831 dev_err(&pdev->dev, "of node is missing.\n");
832 return -ENODEV;
833 }
834
835 match = of_match_node(j721e_audio_of_match, node);
836 if (!match) {

--- 7 unchanged lines hidden (view full) ---

844
845 priv->match_data = match->data;
846
847 priv->dai_links = devm_kcalloc(&pdev->dev, priv->match_data->num_links,
848 sizeof(*priv->dai_links), GFP_KERNEL);
849 if (!priv->dai_links)
850 return -ENOMEM;
851
826
827 if (!node) {
828 dev_err(&pdev->dev, "of node is missing.\n");
829 return -ENODEV;
830 }
831
832 match = of_match_node(j721e_audio_of_match, node);
833 if (!match) {

--- 7 unchanged lines hidden (view full) ---

841
842 priv->match_data = match->data;
843
844 priv->dai_links = devm_kcalloc(&pdev->dev, priv->match_data->num_links,
845 sizeof(*priv->dai_links), GFP_KERNEL);
846 if (!priv->dai_links)
847 return -ENOMEM;
848
852 priv->audio_domains[J721E_AUDIO_DOMAIN_CPB].parent_clk_id = -1;
853 priv->audio_domains[J721E_AUDIO_DOMAIN_IVI].parent_clk_id = -1;
849 for (i = 0; i < J721E_AUDIO_DOMAIN_LAST; i++)
850 priv->audio_domains[i].parent_clk_id = -1;
851
854 priv->dev = &pdev->dev;
855 card = &priv->card;
856 card->dev = &pdev->dev;
857 card->owner = THIS_MODULE;
858 card->dapm_widgets = j721e_cpb_dapm_widgets;
859 card->num_dapm_widgets = ARRAY_SIZE(j721e_cpb_dapm_widgets);
860 card->dapm_routes = j721e_cpb_dapm_routes;
861 card->num_dapm_routes = ARRAY_SIZE(j721e_cpb_dapm_routes);

--- 52 unchanged lines hidden ---
852 priv->dev = &pdev->dev;
853 card = &priv->card;
854 card->dev = &pdev->dev;
855 card->owner = THIS_MODULE;
856 card->dapm_widgets = j721e_cpb_dapm_widgets;
857 card->num_dapm_widgets = ARRAY_SIZE(j721e_cpb_dapm_widgets);
858 card->dapm_routes = j721e_cpb_dapm_routes;
859 card->num_dapm_routes = ARRAY_SIZE(j721e_cpb_dapm_routes);

--- 52 unchanged lines hidden ---