2 * Copyright 2012, 2014 Freescale Semiconductor, Inc.
3 * Copyright 2012 Linaro Ltd.
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/clk.h>
14 #include <linux/module.h>
16 #include <linux/of_platform.h>
17 #include <sound/soc.h>
19 #define SUPPORT_RATE_NUM 10
22 unsigned int mclk_freq;
23 struct platform_device *pdev;
26 static struct imx_priv card_priv;
28 static int imx_mqs_startup(struct snd_pcm_substream *substream)
30 struct snd_pcm_runtime *runtime = substream->runtime;
31 static struct snd_pcm_hw_constraint_list constraint_rates;
32 struct imx_priv *priv = &card_priv;
33 struct device *dev = &priv->pdev->dev;
34 static u32 support_rates[SUPPORT_RATE_NUM];
37 if (priv->mclk_freq == 24576000) {
38 support_rates[0] = 48000;
39 support_rates[1] = 96000;
40 support_rates[2] = 192000;
41 constraint_rates.list = support_rates;
42 constraint_rates.count = 3;
44 ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
49 dev_warn(dev, "mclk may be not supported %d\n", priv->mclk_freq);
54 static struct snd_soc_ops imx_mqs_ops = {
55 .startup = imx_mqs_startup,
60 static struct snd_soc_dai_link imx_mqs_dai = {
62 .stream_name = "HiFi",
63 .dai_fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF |
64 SND_SOC_DAIFMT_CBS_CFS,
68 static struct snd_soc_card snd_soc_card_imx_mqs = {
70 .dai_link = &imx_mqs_dai,
75 static int imx_mqs_probe(struct platform_device *pdev)
77 struct device_node *cpu_np, *codec_np;
78 struct imx_priv *priv = &card_priv;
79 struct clk *codec_clk = NULL;
80 struct platform_device *codec_dev;
85 cpu_np = of_parse_phandle(pdev->dev.of_node, "cpu-dai", 0);
91 codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
93 dev_err(&pdev->dev, "phandle missing or invalid\n");
98 codec_dev = of_find_device_by_node(codec_np);
100 dev_err(&codec_dev->dev, "failed to find codec device\n");
105 codec_clk = devm_clk_get(&codec_dev->dev, NULL);
106 if (IS_ERR(codec_clk)) {
107 ret = PTR_ERR(codec_clk);
108 dev_err(&codec_dev->dev, "failed to get codec clk: %d\n", ret);
111 priv->mclk_freq = clk_get_rate(codec_clk);
114 imx_mqs_dai.cpu_of_node = cpu_np;
115 imx_mqs_dai.platform_of_node = cpu_np;
116 imx_mqs_dai.codec_dai_name = "fsl-mqs-dai";
117 imx_mqs_dai.codec_of_node = codec_np;
118 snd_soc_card_imx_mqs.dev = &pdev->dev;
120 ret = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_imx_mqs);
122 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
133 static const struct of_device_id imx_mqs_dt_ids[] = {
134 { .compatible = "fsl,imx-audio-mqs", },
137 MODULE_DEVICE_TABLE(of, imx_mqs_dt_ids);
139 static struct platform_driver imx_mqs_driver = {
142 .owner = THIS_MODULE,
143 .of_match_table = imx_mqs_dt_ids,
145 .probe = imx_mqs_probe,
147 module_platform_driver(imx_mqs_driver);
149 MODULE_AUTHOR("Nicolin Chen <Guangyu.Chen@freescale.com>");
150 MODULE_DESCRIPTION("Freescale i.MX MQS ASoC machine driver");
151 MODULE_ALIAS("platform:imx-mqs");
152 MODULE_LICENSE("GPL v2");