diff options
Diffstat (limited to 'sound/soc/samsung/tm2_wm5110.c')
-rw-r--r-- | sound/soc/samsung/tm2_wm5110.c | 206 |
1 files changed, 156 insertions, 50 deletions
diff --git a/sound/soc/samsung/tm2_wm5110.c b/sound/soc/samsung/tm2_wm5110.c index a55d18703fe7..43332c32d7e9 100644 --- a/sound/soc/samsung/tm2_wm5110.c +++ b/sound/soc/samsung/tm2_wm5110.c @@ -31,7 +31,7 @@ #define TM2_DAI_AIF2 1 struct tm2_machine_priv { - struct snd_soc_codec *codec; + struct snd_soc_component *component; unsigned int sysclk_rate; struct gpio_desc *gpio_mic_bias; }; @@ -39,33 +39,33 @@ struct tm2_machine_priv { static int tm2_start_sysclk(struct snd_soc_card *card) { struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); - struct snd_soc_codec *codec = priv->codec; + struct snd_soc_component *component = priv->component; int ret; - ret = snd_soc_codec_set_pll(codec, WM5110_FLL1_REFCLK, + ret = snd_soc_component_set_pll(component, WM5110_FLL1_REFCLK, ARIZONA_FLL_SRC_MCLK1, MCLK_RATE, priv->sysclk_rate); if (ret < 0) { - dev_err(codec->dev, "Failed to set FLL1 source: %d\n", ret); + dev_err(component->dev, "Failed to set FLL1 source: %d\n", ret); return ret; } - ret = snd_soc_codec_set_pll(codec, WM5110_FLL1, + ret = snd_soc_component_set_pll(component, WM5110_FLL1, ARIZONA_FLL_SRC_MCLK1, MCLK_RATE, priv->sysclk_rate); if (ret < 0) { - dev_err(codec->dev, "Failed to start FLL1: %d\n", ret); + dev_err(component->dev, "Failed to start FLL1: %d\n", ret); return ret; } - ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_SYSCLK, + ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1, priv->sysclk_rate, SND_SOC_CLOCK_IN); if (ret < 0) { - dev_err(codec->dev, "Failed to set SYSCLK source: %d\n", ret); + dev_err(component->dev, "Failed to set SYSCLK source: %d\n", ret); return ret; } @@ -75,19 +75,19 @@ static int tm2_start_sysclk(struct snd_soc_card *card) static int tm2_stop_sysclk(struct snd_soc_card *card) { struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card); - struct snd_soc_codec *codec = priv->codec; + struct snd_soc_component *component = priv->component; int ret; - ret = snd_soc_codec_set_pll(codec, WM5110_FLL1, 0, 0, 0); + ret = snd_soc_component_set_pll(component, WM5110_FLL1, 0, 0, 0); if (ret < 0) { - dev_err(codec->dev, "Failed to stop FLL1: %d\n", ret); + dev_err(component->dev, "Failed to stop FLL1: %d\n", ret); return ret; } - ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_SYSCLK, + ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_SYSCLK, ARIZONA_CLK_SRC_FLL1, 0, 0); if (ret < 0) { - dev_err(codec->dev, "Failed to stop SYSCLK: %d\n", ret); + dev_err(component->dev, "Failed to stop SYSCLK: %d\n", ret); return ret; } @@ -98,7 +98,7 @@ static int tm2_aif1_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_codec *codec = rtd->codec; + struct snd_soc_component *component = rtd->codec_dai->component; struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(rtd->card); switch (params_rate(params)) { @@ -123,7 +123,7 @@ static int tm2_aif1_hw_params(struct snd_pcm_substream *substream, priv->sysclk_rate = 135475200U; break; default: - dev_err(codec->dev, "Not supported sample rate: %d\n", + dev_err(component->dev, "Not supported sample rate: %d\n", params_rate(params)); return -EINVAL; } @@ -139,7 +139,7 @@ static int tm2_aif2_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_codec *codec = rtd->codec; + struct snd_soc_component *component = rtd->codec_dai->component; unsigned int asyncclk_rate; int ret; @@ -155,35 +155,35 @@ static int tm2_aif2_hw_params(struct snd_pcm_substream *substream, asyncclk_rate = 45158400U; break; default: - dev_err(codec->dev, "Not supported sample rate: %d\n", + dev_err(component->dev, "Not supported sample rate: %d\n", params_rate(params)); return -EINVAL; } - ret = snd_soc_codec_set_pll(codec, WM5110_FLL2_REFCLK, + ret = snd_soc_component_set_pll(component, WM5110_FLL2_REFCLK, ARIZONA_FLL_SRC_MCLK1, MCLK_RATE, asyncclk_rate); if (ret < 0) { - dev_err(codec->dev, "Failed to set FLL2 source: %d\n", ret); + dev_err(component->dev, "Failed to set FLL2 source: %d\n", ret); return ret; } - ret = snd_soc_codec_set_pll(codec, WM5110_FLL2, + ret = snd_soc_component_set_pll(component, WM5110_FLL2, ARIZONA_FLL_SRC_MCLK1, MCLK_RATE, asyncclk_rate); if (ret < 0) { - dev_err(codec->dev, "Failed to start FLL2: %d\n", ret); + dev_err(component->dev, "Failed to start FLL2: %d\n", ret); return ret; } - ret = snd_soc_codec_set_sysclk(codec, ARIZONA_CLK_ASYNCCLK, + ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_ASYNCCLK, ARIZONA_CLK_SRC_FLL2, asyncclk_rate, SND_SOC_CLOCK_IN); if (ret < 0) { - dev_err(codec->dev, "Failed to set ASYNCCLK source: %d\n", ret); + dev_err(component->dev, "Failed to set ASYNCCLK source: %d\n", ret); return ret; } @@ -193,14 +193,14 @@ static int tm2_aif2_hw_params(struct snd_pcm_substream *substream, static int tm2_aif2_hw_free(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_codec *codec = rtd->codec; + struct snd_soc_component *component = rtd->codec_dai->component; int ret; /* disable FLL2 */ - ret = snd_soc_codec_set_pll(codec, WM5110_FLL2, ARIZONA_FLL_SRC_MCLK1, + ret = snd_soc_component_set_pll(component, WM5110_FLL2, ARIZONA_FLL_SRC_MCLK1, 0, 0); if (ret < 0) - dev_err(codec->dev, "Failed to stop FLL2: %d\n", ret); + dev_err(component->dev, "Failed to stop FLL2: %d\n", ret); return ret; } @@ -210,6 +210,59 @@ static struct snd_soc_ops tm2_aif2_ops = { .hw_free = tm2_aif2_hw_free, }; +static int tm2_hdmi_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; + unsigned int bfs; + int bitwidth, ret; + + bitwidth = snd_pcm_format_width(params_format(params)); + if (bitwidth < 0) { + dev_err(rtd->card->dev, "Invalid bit-width: %d\n", bitwidth); + return bitwidth; + } + + switch (bitwidth) { + case 48: + bfs = 64; + break; + case 16: + bfs = 32; + break; + default: + dev_err(rtd->card->dev, "Unsupported bit-width: %d\n", bitwidth); + return -EINVAL; + } + + switch (params_rate(params)) { + case 48000: + case 96000: + case 192000: + break; + default: + dev_err(rtd->card->dev, "Unsupported sample rate: %d\n", + params_rate(params)); + return -EINVAL; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK, + 0, SAMSUNG_I2S_OPCLK_PCLK); + if (ret < 0) + return ret; + + ret = snd_soc_dai_set_clkdiv(cpu_dai, SAMSUNG_I2S_DIV_BCLK, bfs); + if (ret < 0) + return ret; + + return 0; +} + +static struct snd_soc_ops tm2_hdmi_ops = { + .hw_params = tm2_hdmi_hw_params, +}; + static int tm2_mic_bias(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { @@ -269,7 +322,7 @@ static int tm2_late_probe(struct snd_soc_card *card) rtd = snd_soc_get_pcm_runtime(card, card->dai_link[TM2_DAI_AIF1].name); aif1_dai = rtd->codec_dai; - priv->codec = rtd->codec; + priv->component = rtd->codec_dai->component; ret = snd_soc_dai_set_sysclk(aif1_dai, ARIZONA_CLK_SYSCLK, 0, 0); if (ret < 0) { @@ -405,6 +458,12 @@ static struct snd_soc_dai_link tm2_dai_links[] = { .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM, .ignore_suspend = 1, + }, { + .name = "HDMI", + .stream_name = "i2s1", + .ops = &tm2_hdmi_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, } }; @@ -412,7 +471,6 @@ static struct snd_soc_card tm2_card = { .owner = THIS_MODULE, .dai_link = tm2_dai_links, - .num_links = ARRAY_SIZE(tm2_dai_links), .controls = tm2_controls, .num_controls = ARRAY_SIZE(tm2_controls), .dapm_widgets = tm2_dapm_widgets, @@ -426,11 +484,14 @@ static struct snd_soc_card tm2_card = { static int tm2_probe(struct platform_device *pdev) { + struct device_node *cpu_dai_node[2] = {}; + struct device_node *codec_dai_node[2] = {}; + const char *cells_name = NULL; struct device *dev = &pdev->dev; struct snd_soc_card *card = &tm2_card; struct tm2_machine_priv *priv; - struct device_node *cpu_dai_node, *codec_dai_node; - int ret, i; + struct of_phandle_args args; + int num_codecs, ret, i; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -464,47 +525,92 @@ static int tm2_probe(struct platform_device *pdev) return -EINVAL; } - cpu_dai_node = of_parse_phandle(dev->of_node, "i2s-controller", 0); - if (!cpu_dai_node) { - dev_err(dev, "i2s-controllers property invalid or missing\n"); - ret = -EINVAL; - goto amp_node_put; + num_codecs = of_count_phandle_with_args(dev->of_node, "audio-codec", + NULL); + + /* Skip the HDMI link if not specified in DT */ + if (num_codecs > 1) { + card->num_links = ARRAY_SIZE(tm2_dai_links); + cells_name = "#sound-dai-cells"; + } else { + card->num_links = ARRAY_SIZE(tm2_dai_links) - 1; } - codec_dai_node = of_parse_phandle(dev->of_node, "audio-codec", 0); - if (!codec_dai_node) { - dev_err(dev, "audio-codec property invalid or missing\n"); - ret = -EINVAL; - goto cpu_dai_node_put; + for (i = 0; i < num_codecs; i++) { + struct of_phandle_args args; + + ret = of_parse_phandle_with_args(dev->of_node, "i2s-controller", + cells_name, i, &args); + if (!args.np) { + dev_err(dev, "i2s-controller property parse error: %d\n", i); + ret = -EINVAL; + goto dai_node_put; + } + cpu_dai_node[i] = args.np; + + codec_dai_node[i] = of_parse_phandle(dev->of_node, + "audio-codec", i); + if (!codec_dai_node[i]) { + dev_err(dev, "audio-codec property parse error\n"); + ret = -EINVAL; + goto dai_node_put; + } } + /* Initialize WM5110 - I2S and HDMI - I2S1 DAI links */ for (i = 0; i < card->num_links; i++) { + unsigned int dai_index = 0; /* WM5110 */ + card->dai_link[i].cpu_name = NULL; card->dai_link[i].platform_name = NULL; - card->dai_link[i].codec_of_node = codec_dai_node; - card->dai_link[i].cpu_of_node = cpu_dai_node; - card->dai_link[i].platform_of_node = cpu_dai_node; + + if (num_codecs > 1 && i == card->num_links - 1) + dai_index = 1; /* HDMI */ + + card->dai_link[i].codec_of_node = codec_dai_node[dai_index]; + card->dai_link[i].cpu_of_node = cpu_dai_node[dai_index]; + card->dai_link[i].platform_of_node = cpu_dai_node[dai_index]; + } + + if (num_codecs > 1) { + /* HDMI DAI link (I2S1) */ + i = card->num_links - 1; + + ret = of_parse_phandle_with_fixed_args(dev->of_node, + "audio-codec", 0, 1, &args); + if (ret) { + dev_err(dev, "audio-codec property parse error\n"); + goto dai_node_put; + } + + ret = snd_soc_get_dai_name(&args, &card->dai_link[i].codec_dai_name); + if (ret) { + dev_err(dev, "Unable to get codec_dai_name\n"); + goto dai_node_put; + } } ret = devm_snd_soc_register_component(dev, &tm2_component, tm2_ext_dai, ARRAY_SIZE(tm2_ext_dai)); if (ret < 0) { dev_err(dev, "Failed to register component: %d\n", ret); - goto codec_dai_node_put; + goto dai_node_put; } ret = devm_snd_soc_register_card(dev, card); if (ret < 0) { dev_err(dev, "Failed to register card: %d\n", ret); - goto codec_dai_node_put; + goto dai_node_put; + } + +dai_node_put: + for (i = 0; i < num_codecs; i++) { + of_node_put(codec_dai_node[i]); + of_node_put(cpu_dai_node[i]); } -codec_dai_node_put: - of_node_put(codec_dai_node); -cpu_dai_node_put: - of_node_put(cpu_dai_node); -amp_node_put: of_node_put(card->aux_dev[0].codec_of_node); + return ret; } |