xref: /openbmc/linux/sound/soc/samsung/snow.c (revision 5015920a1732cabd1178cfe342f09ee3488a1791)
131c26a6aSTushar Behera /*
231c26a6aSTushar Behera  * ASoC machine driver for Snow boards
331c26a6aSTushar Behera  *
431c26a6aSTushar Behera  * This program is free software; you can redistribute it and/or
531c26a6aSTushar Behera  * modify it under the terms of the GNU General Public License
631c26a6aSTushar Behera  * version 2 as published by the Free Software Foundation.
731c26a6aSTushar Behera  *
831c26a6aSTushar Behera  * This program is distributed in the hope that it will be useful, but
931c26a6aSTushar Behera  * WITHOUT ANY WARRANTY; without even the implied warranty of
1031c26a6aSTushar Behera  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1131c26a6aSTushar Behera  * General Public License for more details.
1231c26a6aSTushar Behera  */
1331c26a6aSTushar Behera 
1431c26a6aSTushar Behera #include <linux/module.h>
1531c26a6aSTushar Behera #include <linux/platform_device.h>
1631c26a6aSTushar Behera #include <linux/of.h>
1731c26a6aSTushar Behera #include <linux/of_device.h>
1831c26a6aSTushar Behera 
1931c26a6aSTushar Behera #include <sound/soc.h>
2031c26a6aSTushar Behera 
2131c26a6aSTushar Behera #include "i2s.h"
2231c26a6aSTushar Behera 
2331c26a6aSTushar Behera #define FIN_PLL_RATE		24000000
2431c26a6aSTushar Behera 
2531c26a6aSTushar Behera static struct snd_soc_dai_link snow_dai[] = {
2631c26a6aSTushar Behera 	{
2731c26a6aSTushar Behera 		.name = "Primary",
2831c26a6aSTushar Behera 		.stream_name = "Primary",
2931c26a6aSTushar Behera 		.codec_dai_name = "HiFi",
3031c26a6aSTushar Behera 		.dai_fmt = SND_SOC_DAIFMT_I2S |
3131c26a6aSTushar Behera 				SND_SOC_DAIFMT_NB_NF |
3231c26a6aSTushar Behera 				SND_SOC_DAIFMT_CBS_CFS,
3331c26a6aSTushar Behera 	},
3431c26a6aSTushar Behera };
3531c26a6aSTushar Behera 
3631c26a6aSTushar Behera static int snow_late_probe(struct snd_soc_card *card)
3731c26a6aSTushar Behera {
38*5015920aSMengdong Lin 	struct snd_soc_pcm_runtime *rtd;
39*5015920aSMengdong Lin 	struct snd_soc_dai *codec_dai;
40*5015920aSMengdong Lin 	struct snd_soc_dai *cpu_dai;
4131c26a6aSTushar Behera 	int ret;
4231c26a6aSTushar Behera 
43*5015920aSMengdong Lin 	rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
44*5015920aSMengdong Lin 	codec_dai = rtd->codec_dai;
45*5015920aSMengdong Lin 	cpu_dai = rtd->cpu_dai;
46*5015920aSMengdong Lin 
4731c26a6aSTushar Behera 	/* Set the MCLK rate for the codec */
4831c26a6aSTushar Behera 	ret = snd_soc_dai_set_sysclk(codec_dai, 0,
4931c26a6aSTushar Behera 					FIN_PLL_RATE, SND_SOC_CLOCK_IN);
5031c26a6aSTushar Behera 	if (ret < 0)
5131c26a6aSTushar Behera 		return ret;
5231c26a6aSTushar Behera 
5331c26a6aSTushar Behera 	/* Select I2S Bus clock to set RCLK and BCLK */
5431c26a6aSTushar Behera 	ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
5531c26a6aSTushar Behera 					0, SND_SOC_CLOCK_IN);
5631c26a6aSTushar Behera 	if (ret < 0)
5731c26a6aSTushar Behera 		return ret;
5831c26a6aSTushar Behera 
5931c26a6aSTushar Behera 	return 0;
6031c26a6aSTushar Behera }
6131c26a6aSTushar Behera 
6231c26a6aSTushar Behera static struct snd_soc_card snow_snd = {
6331c26a6aSTushar Behera 	.name = "Snow-I2S",
6454d8697fSAxel Lin 	.owner = THIS_MODULE,
6531c26a6aSTushar Behera 	.dai_link = snow_dai,
6631c26a6aSTushar Behera 	.num_links = ARRAY_SIZE(snow_dai),
6731c26a6aSTushar Behera 
6831c26a6aSTushar Behera 	.late_probe = snow_late_probe,
6931c26a6aSTushar Behera };
7031c26a6aSTushar Behera 
7131c26a6aSTushar Behera static int snow_probe(struct platform_device *pdev)
7231c26a6aSTushar Behera {
7331c26a6aSTushar Behera 	struct snd_soc_card *card = &snow_snd;
7431c26a6aSTushar Behera 	struct device_node *i2s_node, *codec_node;
7531c26a6aSTushar Behera 	int i, ret;
7631c26a6aSTushar Behera 
7731c26a6aSTushar Behera 	i2s_node = of_parse_phandle(pdev->dev.of_node,
7831c26a6aSTushar Behera 				    "samsung,i2s-controller", 0);
7931c26a6aSTushar Behera 	if (!i2s_node) {
8031c26a6aSTushar Behera 		dev_err(&pdev->dev,
8131c26a6aSTushar Behera 			"Property 'i2s-controller' missing or invalid\n");
8231c26a6aSTushar Behera 		return -EINVAL;
8331c26a6aSTushar Behera 	}
8431c26a6aSTushar Behera 
8531c26a6aSTushar Behera 	codec_node = of_parse_phandle(pdev->dev.of_node,
8631c26a6aSTushar Behera 				      "samsung,audio-codec", 0);
8731c26a6aSTushar Behera 	if (!codec_node) {
8831c26a6aSTushar Behera 		dev_err(&pdev->dev,
8931c26a6aSTushar Behera 			"Property 'audio-codec' missing or invalid\n");
9031c26a6aSTushar Behera 		return -EINVAL;
9131c26a6aSTushar Behera 	}
9231c26a6aSTushar Behera 
9331c26a6aSTushar Behera 	for (i = 0; i < ARRAY_SIZE(snow_dai); i++) {
9431c26a6aSTushar Behera 		snow_dai[i].codec_of_node = codec_node;
9531c26a6aSTushar Behera 		snow_dai[i].cpu_of_node = i2s_node;
9631c26a6aSTushar Behera 		snow_dai[i].platform_of_node = i2s_node;
9731c26a6aSTushar Behera 	}
9831c26a6aSTushar Behera 
9931c26a6aSTushar Behera 	card->dev = &pdev->dev;
10031c26a6aSTushar Behera 
10100ad93e2STushar Behera 	/* Update card-name if provided through DT, else use default name */
10200ad93e2STushar Behera 	snd_soc_of_parse_card_name(card, "samsung,model");
10300ad93e2STushar Behera 
10431c26a6aSTushar Behera 	ret = devm_snd_soc_register_card(&pdev->dev, card);
10531c26a6aSTushar Behera 	if (ret) {
10631c26a6aSTushar Behera 		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
10731c26a6aSTushar Behera 		return ret;
10831c26a6aSTushar Behera 	}
10931c26a6aSTushar Behera 
11031c26a6aSTushar Behera 	return ret;
11131c26a6aSTushar Behera }
11231c26a6aSTushar Behera 
11331c26a6aSTushar Behera static const struct of_device_id snow_of_match[] = {
11431c26a6aSTushar Behera 	{ .compatible = "google,snow-audio-max98090", },
11546aed597STushar Behera 	{ .compatible = "google,snow-audio-max98091", },
11631c26a6aSTushar Behera 	{ .compatible = "google,snow-audio-max98095", },
11731c26a6aSTushar Behera 	{},
11831c26a6aSTushar Behera };
11962e6a3b6SAndreas Färber MODULE_DEVICE_TABLE(of, snow_of_match);
12031c26a6aSTushar Behera 
12131c26a6aSTushar Behera static struct platform_driver snow_driver = {
12231c26a6aSTushar Behera 	.driver = {
12331c26a6aSTushar Behera 		.name = "snow-audio",
124deeaa686STushar Behera 		.pm = &snd_soc_pm_ops,
12531c26a6aSTushar Behera 		.of_match_table = snow_of_match,
12631c26a6aSTushar Behera 	},
12731c26a6aSTushar Behera 	.probe = snow_probe,
12831c26a6aSTushar Behera };
12931c26a6aSTushar Behera 
13031c26a6aSTushar Behera module_platform_driver(snow_driver);
13131c26a6aSTushar Behera 
13231c26a6aSTushar Behera MODULE_DESCRIPTION("ALSA SoC Audio machine driver for Snow");
13331c26a6aSTushar Behera MODULE_LICENSE("GPL");
134