[alsa-devel] [PATCH v2 1/7] ASoC: max98090: Add #sound-dai-cells property documentation
MAX98090 CODEC supports 1 input DAI, adding the #sound-dai-cells property helps to reference the DAI in DT in a standard way.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com --- Changes since v1: - new patch.
Documentation/devicetree/bindings/sound/max98090.txt | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/max98090.txt b/Documentation/devicetree/bindings/sound/max98090.txt index 4e3be6682c98..7e1bbd5c27fd 100644 --- a/Documentation/devicetree/bindings/sound/max98090.txt +++ b/Documentation/devicetree/bindings/sound/max98090.txt @@ -16,6 +16,8 @@ Optional properties:
- clock-names: Should be "mclk"
+- #sound-dai-cells : should be 0. + - maxim,dmic-freq: Frequency at which to clock DMIC
- maxim,micbias: Micbias voltage applies to the analog mic, valid voltages value are: -- 2.14.2
MAX98095 CODEC supports 3 input DAIs, adding the #sound-dai-cells property allows to reference selected DAI in DT.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com Reviewed-by: Rob Herring robh@kernel.org --- Changes since v1: - none. --- Documentation/devicetree/bindings/sound/max98095.txt | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/max98095.txt b/Documentation/devicetree/bindings/sound/max98095.txt index 318a4c82f17f..944efa06487b 100644 --- a/Documentation/devicetree/bindings/sound/max98095.txt +++ b/Documentation/devicetree/bindings/sound/max98095.txt @@ -14,6 +14,9 @@ Optional properties:
- clock-names: Should be "mclk"
+- #sound-dai-cells : should be 1. + + Example:
max98095: codec@11 {
The code for dereferencing device nodes in the 'codecs' array is moved to a separate function so we can avoid open coding that in drivers.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com --- Changes since v1: - none. --- include/sound/soc.h | 1 + sound/soc/soc-core.c | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 747fd583b9dc..4a387f0b3d56 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1807,6 +1807,7 @@ int snd_soc_of_get_dai_name(struct device_node *of_node, int snd_soc_of_get_dai_link_codecs(struct device *dev, struct device_node *of_node, struct snd_soc_dai_link *dai_link); +void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
int snd_soc_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 96c44f6576c9..a1f86e85bff9 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -4397,6 +4397,26 @@ int snd_soc_of_get_dai_name(struct device_node *of_node, } EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
+/* + * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array + * @dai_link: DAI link + * + * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs(). + */ +void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) +{ + struct snd_soc_dai_link_component *component = dai_link->codecs; + int index; + + for (index = 0; index < dai_link->num_codecs; index++, component++) { + if (!component->of_node) + break; + of_node_put(component->of_node); + component->of_node = NULL; + } +} +EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs); + /* * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree * @dev: Card device @@ -4406,7 +4426,8 @@ EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); * Builds an array of CODEC DAI components from the DAI link property * 'sound-dai'. * The array is set in the DAI link and the number of DAIs is set accordingly. - * The device nodes in the array (of_node) must be dereferenced by the caller. + * The device nodes in the array (of_node) must be dereferenced by calling + * snd_soc_of_put_dai_link_codecs() on @dai_link. * * Returns 0 for success */ @@ -4454,14 +4475,7 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev, } return 0; err: - for (index = 0, component = dai_link->codecs; - index < dai_link->num_codecs; - index++, component++) { - if (!component->of_node) - break; - of_node_put(component->of_node); - component->of_node = NULL; - } + snd_soc_of_put_dai_link_codecs(dai_link); dai_link->codecs = NULL; dai_link->num_codecs = 0; return ret; -- 2.14.2
As the RCLK clock may be updated through the common clk API before each snd_soc_dai_ops::trigger call, it is not enough to update i2s->rclk_srcrate only once after it has been initially set to 0. To avoid wrong PSR values we always get RCLK frequency from the CLK_I2S_RCLK_SRC clock, when that clock is available.
Fixes: e1417fdf3011 "ASoC: samsung: i2s: Ensure the RCLK rate is properly determined" Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com --- Changes since v1: - none. --- sound/soc/samsung/i2s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c index c65227e2561c..97fe3f9352c5 100644 --- a/sound/soc/samsung/i2s.c +++ b/sound/soc/samsung/i2s.c @@ -897,7 +897,7 @@ static int config_setup(struct i2s_dai *i2s) if (!(i2s->quirks & QUIRK_NO_MUXPSR)) { struct clk *rclksrc = i2s->clock[CLK_I2S_RCLK_SRC];
- if (i2s->rclk_srcrate == 0 && rclksrc && !IS_ERR(rclksrc)) + if (rclksrc && !IS_ERR(rclksrc)) i2s->rclk_srcrate = clk_get_rate(rclksrc);
psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
The new DT bindings are introduced so sound on the HDMI interface can also be supported. The exisiting CPU and CODEC DAI phandle properties are marked as deprecated.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com Reviewed-by: Rob Herring robh@kernel.org --- Changes since v1: - none. --- Documentation/devicetree/bindings/sound/snow.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/snow.txt b/Documentation/devicetree/bindings/sound/snow.txt index 6df74f15687f..80fd9a87bb3f 100644 --- a/Documentation/devicetree/bindings/sound/snow.txt +++ b/Documentation/devicetree/bindings/sound/snow.txt @@ -5,5 +5,14 @@ Required properties: "google,snow-audio-max98090" or "google,snow-audio-max98091" or "google,snow-audio-max98095" -- samsung,i2s-controller: The phandle of the Samsung I2S controller -- samsung,audio-codec: The phandle of the audio codec +- samsung,i2s-controller (deprecated): The phandle of the Samsung I2S controller +- samsung,audio-codec (deprecated): The phandle of the audio codec + +Required sub-nodes: + + - 'cpu' subnode with a 'sound-dai' property containing the phandle of the I2S + controller + - 'codec' subnode with a 'sound-dai' property containing list of phandles + to the CODEC nodes, first entry must be the phandle of the MAX98090, + MAX98091 or MAX98095 CODEC (exact device type is indicated by the compatible + string) and the second entry must be the phandle of the HDMI IP block node
Optional: - samsung,model: The name of the sound-card -- 2.14.2
On Fri, Mar 09, 2018 at 06:48:56PM +0100, Sylwester Nawrocki wrote:
The new DT bindings are introduced so sound on the HDMI interface can also be supported. The exisiting CPU and CODEC DAI phandle properties are marked as deprecated.
This doesn't seem to apply against current code, please check and resend.
The RCLKSRC mux input 0 is a default configuration after reset, so there is no need for this explicit snd_soc_dai_set_sysclk() call. Also, this static mux clock configuration can be specified in DT.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com --- Changes since v1: - none. --- sound/soc/samsung/snow.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c index d8ac907bbb0d..fc62110f500f 100644 --- a/sound/soc/samsung/snow.c +++ b/sound/soc/samsung/snow.c @@ -50,11 +50,6 @@ static int snow_late_probe(struct snd_soc_card *card) if (ret < 0) return ret;
- /* Select I2S Bus clock to set RCLK and BCLK */ - ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0, - 0, SND_SOC_CLOCK_IN); - if (ret < 0) - return ret;
return 0; }
On Fri, Mar 9, 2018 at 6:48 PM, Sylwester Nawrocki s.nawrocki@samsung.com wrote:
The RCLKSRC mux input 0 is a default configuration after reset, so there is no need for this explicit snd_soc_dai_set_sysclk() call. Also, this static mux clock configuration can be specified in DT.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com
Changes since v1:
- none.
sound/soc/samsung/snow.c | 5 ----- 1 file changed, 5 deletions(-)
Acked-by: Krzysztof Kozlowski krzk@kernel.org
Best regards, Krzysztof
This patch updates the driver so, in addition to current DT bindings, the new DT bindings with cpu, codec subnodes can be used, in order to support sound on the HDMI interface.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com --- Changes since v1: - adjustments to changed order of codecs in codec/cpu-dai property, - fixed errors in snow_remove(). --- sound/soc/samsung/snow.c | 226 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 178 insertions(+), 48 deletions(-)
diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c index fc62110f500f..f00ca1ca0171 100644 --- a/sound/soc/samsung/snow.c +++ b/sound/soc/samsung/snow.c @@ -11,92 +11,207 @@ * General Public License for more details. */
+#include <linux/clk.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/of.h> #include <linux/of_device.h> - +#include <sound/pcm_params.h> #include <sound/soc.h>
#include "i2s.h"
-#define FIN_PLL_RATE 24000000 +#define FIN_PLL_RATE 24000000UL
-static struct snd_soc_dai_link snow_dai[] = { - { - .name = "Primary", - .stream_name = "Primary", - .codec_dai_name = "HiFi", - .dai_fmt = SND_SOC_DAIFMT_I2S | - SND_SOC_DAIFMT_NB_NF | - SND_SOC_DAIFMT_CBS_CFS, - }, +struct snow_priv { + struct snd_soc_dai_link dai_link; + struct clk *clk_i2s_bus; +}; + +static int snow_card_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + static const unsigned int pll_rate[] = { + 73728000U, 67737602U, 49152000U, 45158401U, 32768001U + }; + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snow_priv *priv = snd_soc_card_get_drvdata(rtd->card); + int bfs, psr, rfs, bitwidth; + unsigned long int rclk; + long int freq = -EINVAL; + int ret, i; + + bitwidth = snd_pcm_format_width(params_format(params)); + if (bitwidth < 0) { + dev_err(rtd->card->dev, "Invalid bit-width: %d\n", bitwidth); + return bitwidth; + } + + if (bitwidth != 16 && bitwidth != 24) { + dev_err(rtd->card->dev, "Unsupported bit-width: %d\n", bitwidth); + return -EINVAL; + } + + bfs = 2 * bitwidth; + + switch (params_rate(params)) { + case 16000: + case 22050: + case 24000: + case 32000: + case 44100: + case 48000: + case 88200: + case 96000: + rfs = 8 * bfs; + break; + case 64000: + rfs = 384; + break; + case 8000: + case 11025: + case 12000: + rfs = 16 * bfs; + break; + default: + return -EINVAL; + } + + rclk = params_rate(params) * rfs; + + for (psr = 8; psr > 0; psr /= 2) { + for (i = 0; i < ARRAY_SIZE(pll_rate); i++) { + if ((pll_rate[i] - rclk * psr) <= 2) { + freq = pll_rate[i]; + break; + } + } + } + if (freq < 0) { + dev_err(rtd->card->dev, "Unsupported RCLK rate: %lu\n", rclk); + return -EINVAL; + } + + ret = clk_set_rate(priv->clk_i2s_bus, freq); + if (ret < 0) { + dev_err(rtd->card->dev, "I2S bus clock rate set failed\n"); + return ret; + } + + return 0; +} + +static const struct snd_soc_ops snow_card_ops = { + .hw_params = snow_card_hw_params, };
static int snow_late_probe(struct snd_soc_card *card) { struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai *codec_dai; - struct snd_soc_dai *cpu_dai; - int ret;
rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name); - codec_dai = rtd->codec_dai; - cpu_dai = rtd->cpu_dai; - - /* Set the MCLK rate for the codec */ - ret = snd_soc_dai_set_sysclk(codec_dai, 0, - FIN_PLL_RATE, SND_SOC_CLOCK_IN); - if (ret < 0) - return ret;
+ /* In the multi-codec case codec_dais 0 is MAX98095 and 1 is HDMI. */ + if (rtd->num_codecs > 1) + codec_dai = rtd->codec_dais[0]; + else + codec_dai = rtd->codec_dai;
- return 0; + /* Set the MCLK rate for the codec */ + return snd_soc_dai_set_sysclk(codec_dai, 0, + FIN_PLL_RATE, SND_SOC_CLOCK_IN); }
static struct snd_soc_card snow_snd = { .name = "Snow-I2S", .owner = THIS_MODULE, - .dai_link = snow_dai, - .num_links = ARRAY_SIZE(snow_dai), - .late_probe = snow_late_probe, };
static int snow_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct snd_soc_card *card = &snow_snd; - struct device_node *i2s_node, *codec_node; - int i, ret; - - i2s_node = of_parse_phandle(pdev->dev.of_node, - "samsung,i2s-controller", 0); - if (!i2s_node) { - dev_err(&pdev->dev, - "Property 'i2s-controller' missing or invalid\n"); - return -EINVAL; - } + struct device_node *cpu, *codec; + struct snd_soc_dai_link *link; + struct snow_priv *priv; + int ret;
- codec_node = of_parse_phandle(pdev->dev.of_node, - "samsung,audio-codec", 0); - if (!codec_node) { - dev_err(&pdev->dev, - "Property 'audio-codec' missing or invalid\n"); - return -EINVAL; - } + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + link = &priv->dai_link; + + link->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS; + + link->name = "Primary"; + link->stream_name = link->name; + + card->dai_link = link; + card->num_links = 1; + card->dev = dev; + + /* Try new DT bindings with HDMI support first. */ + cpu = of_get_child_by_name(dev->of_node, "cpu"); + + if (cpu) { + link->ops = &snow_card_ops;
- for (i = 0; i < ARRAY_SIZE(snow_dai); i++) { - snow_dai[i].codec_of_node = codec_node; - snow_dai[i].cpu_of_node = i2s_node; - snow_dai[i].platform_of_node = i2s_node; + link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0); + of_node_put(cpu); + + if (!link->cpu_of_node) { + dev_err(dev, "Failed parsing cpu/sound-dai property\n"); + return -EINVAL; + } + + codec = of_get_child_by_name(dev->of_node, "codec"); + ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); + of_node_put(codec); + + if (ret < 0) { + of_node_put(link->cpu_of_node); + dev_err(dev, "Failed parsing codec node\n"); + return ret; + } + + priv->clk_i2s_bus = of_clk_get_by_name(link->cpu_of_node, + "i2s_opclk0"); + if (IS_ERR(priv->clk_i2s_bus)) { + snd_soc_of_put_dai_link_codecs(link); + of_node_put(link->cpu_of_node); + return PTR_ERR(priv->clk_i2s_bus); + } + } else { + link->codec_dai_name = "HiFi", + + link->cpu_of_node = of_parse_phandle(dev->of_node, + "samsung,i2s-controller", 0); + if (!link->cpu_of_node) { + dev_err(dev, "i2s-controller property parse error\n"); + return -EINVAL; + } + + link->codec_of_node = of_parse_phandle(dev->of_node, + "samsung,audio-codec", 0); + if (!link->codec_of_node) { + of_node_put(link->cpu_of_node); + dev_err(dev, "audio-codec property parse error\n"); + return -EINVAL; + } }
- card->dev = &pdev->dev; + link->platform_of_node = link->cpu_of_node;
/* Update card-name if provided through DT, else use default name */ snd_soc_of_parse_card_name(card, "samsung,model");
- ret = devm_snd_soc_register_card(&pdev->dev, card); + snd_soc_card_set_drvdata(card, priv); + + ret = devm_snd_soc_register_card(dev, card); if (ret) { dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); return ret; @@ -105,6 +220,20 @@ static int snow_probe(struct platform_device *pdev) return ret; }
+static int snow_remove(struct platform_device *pdev) +{ + struct snow_priv *priv = platform_get_drvdata(pdev); + struct snd_soc_dai_link *link = &priv->dai_link; + + of_node_put(link->cpu_of_node); + of_node_put(link->codec_of_node); + snd_soc_of_put_dai_link_codecs(link); + + clk_put(priv->clk_i2s_bus); + + return 0; +} + static const struct of_device_id snow_of_match[] = { { .compatible = "google,snow-audio-max98090", }, { .compatible = "google,snow-audio-max98091", }, @@ -120,6 +249,7 @@ static struct platform_driver snow_driver = { .of_match_table = snow_of_match, }, .probe = snow_probe, + .remove = snow_remove, };
module_platform_driver(snow_driver); -- 2.14.2
On Fri, Mar 9, 2018 at 6:48 PM, Sylwester Nawrocki s.nawrocki@samsung.com wrote:
This patch updates the driver so, in addition to current DT bindings, the new DT bindings with cpu, codec subnodes can be used, in order to support sound on the HDMI interface.
Signed-off-by: Sylwester Nawrocki s.nawrocki@samsung.com
Changes since v1:
- adjustments to changed order of codecs in codec/cpu-dai property,
- fixed errors in snow_remove().
sound/soc/samsung/snow.c | 226 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 178 insertions(+), 48 deletions(-)
diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c index fc62110f500f..f00ca1ca0171 100644 --- a/sound/soc/samsung/snow.c +++ b/sound/soc/samsung/snow.c @@ -11,92 +11,207 @@
- General Public License for more details.
*/
+#include <linux/clk.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/of.h> #include <linux/of_device.h>
+#include <sound/pcm_params.h> #include <sound/soc.h>
#include "i2s.h"
-#define FIN_PLL_RATE 24000000 +#define FIN_PLL_RATE 24000000UL
This change looks unrelated so how about making it separate patch?
For the rest: Acked-by: Krzysztof Kozlowski krzk@kernel.org
Best regards, Krzysztof
On 03/12/2018 08:39 AM, Krzysztof Kozlowski wrote:
-#define FIN_PLL_RATE 24000000 +#define FIN_PLL_RATE 24000000UL
This change looks unrelated so how about making it separate patch?
I knew you will find this! ;P I don't want to be making this kind of funny patches :), I can repost v3 in a few days with this bit removed.
On Mon, Mar 12, 2018 at 05:21:03PM +0100, Sylwester Nawrocki wrote:
On 03/12/2018 08:39 AM, Krzysztof Kozlowski wrote:
-#define FIN_PLL_RATE 24000000 +#define FIN_PLL_RATE 24000000UL
This change looks unrelated so how about making it separate patch?
I knew you will find this! ;P I don't want to be making this kind of funny patches :), I can repost v3 in a few days with this bit removed.
Ah, you know, after working with crappy code and crappy history, I find very useful to have strict approach around changes. This one might be harmless... or you might be fixing some warning caught by your compiler thus it looks like nice candidate for seaprate patch.
Best regards, Krzysztof
participants (3)
-
Krzysztof Kozlowski
-
Mark Brown
-
Sylwester Nawrocki