xref: /openbmc/linux/sound/soc/samsung/snow.c (revision deeaa686b9381ff9a66e599af57976ba7e54ec54)
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 {
3831c26a6aSTushar Behera 	struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
3931c26a6aSTushar Behera 	struct snd_soc_dai *cpu_dai = card->rtd[0].cpu_dai;
4031c26a6aSTushar Behera 	int ret;
4131c26a6aSTushar Behera 
4231c26a6aSTushar Behera 	/* Set the MCLK rate for the codec */
4331c26a6aSTushar Behera 	ret = snd_soc_dai_set_sysclk(codec_dai, 0,
4431c26a6aSTushar Behera 					FIN_PLL_RATE, SND_SOC_CLOCK_IN);
4531c26a6aSTushar Behera 	if (ret < 0)
4631c26a6aSTushar Behera 		return ret;
4731c26a6aSTushar Behera 
4831c26a6aSTushar Behera 	/* Select I2S Bus clock to set RCLK and BCLK */
4931c26a6aSTushar Behera 	ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
5031c26a6aSTushar Behera 					0, SND_SOC_CLOCK_IN);
5131c26a6aSTushar Behera 	if (ret < 0)
5231c26a6aSTushar Behera 		return ret;
5331c26a6aSTushar Behera 
5431c26a6aSTushar Behera 	return 0;
5531c26a6aSTushar Behera }
5631c26a6aSTushar Behera 
5731c26a6aSTushar Behera static struct snd_soc_card snow_snd = {
5831c26a6aSTushar Behera 	.name = "Snow-I2S",
5931c26a6aSTushar Behera 	.dai_link = snow_dai,
6031c26a6aSTushar Behera 	.num_links = ARRAY_SIZE(snow_dai),
6131c26a6aSTushar Behera 
6231c26a6aSTushar Behera 	.late_probe = snow_late_probe,
6331c26a6aSTushar Behera };
6431c26a6aSTushar Behera 
6531c26a6aSTushar Behera static int snow_probe(struct platform_device *pdev)
6631c26a6aSTushar Behera {
6731c26a6aSTushar Behera 	struct snd_soc_card *card = &snow_snd;
6831c26a6aSTushar Behera 	struct device_node *i2s_node, *codec_node;
6931c26a6aSTushar Behera 	int i, ret;
7031c26a6aSTushar Behera 
7131c26a6aSTushar Behera 	i2s_node = of_parse_phandle(pdev->dev.of_node,
7231c26a6aSTushar Behera 				    "samsung,i2s-controller", 0);
7331c26a6aSTushar Behera 	if (!i2s_node) {
7431c26a6aSTushar Behera 		dev_err(&pdev->dev,
7531c26a6aSTushar Behera 			"Property 'i2s-controller' missing or invalid\n");
7631c26a6aSTushar Behera 		return -EINVAL;
7731c26a6aSTushar Behera 	}
7831c26a6aSTushar Behera 
7931c26a6aSTushar Behera 	codec_node = of_parse_phandle(pdev->dev.of_node,
8031c26a6aSTushar Behera 				      "samsung,audio-codec", 0);
8131c26a6aSTushar Behera 	if (!codec_node) {
8231c26a6aSTushar Behera 		dev_err(&pdev->dev,
8331c26a6aSTushar Behera 			"Property 'audio-codec' missing or invalid\n");
8431c26a6aSTushar Behera 		return -EINVAL;
8531c26a6aSTushar Behera 	}
8631c26a6aSTushar Behera 
8731c26a6aSTushar Behera 	for (i = 0; i < ARRAY_SIZE(snow_dai); i++) {
8831c26a6aSTushar Behera 		snow_dai[i].codec_of_node = codec_node;
8931c26a6aSTushar Behera 		snow_dai[i].cpu_of_node = i2s_node;
9031c26a6aSTushar Behera 		snow_dai[i].platform_of_node = i2s_node;
9131c26a6aSTushar Behera 	}
9231c26a6aSTushar Behera 
9331c26a6aSTushar Behera 	card->dev = &pdev->dev;
9431c26a6aSTushar Behera 
9531c26a6aSTushar Behera 	ret = devm_snd_soc_register_card(&pdev->dev, card);
9631c26a6aSTushar Behera 	if (ret) {
9731c26a6aSTushar Behera 		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
9831c26a6aSTushar Behera 		return ret;
9931c26a6aSTushar Behera 	}
10031c26a6aSTushar Behera 
10131c26a6aSTushar Behera 	return ret;
10231c26a6aSTushar Behera }
10331c26a6aSTushar Behera 
10431c26a6aSTushar Behera static const struct of_device_id snow_of_match[] = {
10531c26a6aSTushar Behera 	{ .compatible = "google,snow-audio-max98090", },
10631c26a6aSTushar Behera 	{ .compatible = "google,snow-audio-max98095", },
10731c26a6aSTushar Behera 	{},
10831c26a6aSTushar Behera };
10931c26a6aSTushar Behera 
11031c26a6aSTushar Behera static struct platform_driver snow_driver = {
11131c26a6aSTushar Behera 	.driver = {
11231c26a6aSTushar Behera 		.name = "snow-audio",
11331c26a6aSTushar Behera 		.owner = THIS_MODULE,
114*deeaa686STushar Behera 		.pm = &snd_soc_pm_ops,
11531c26a6aSTushar Behera 		.of_match_table = snow_of_match,
11631c26a6aSTushar Behera 	},
11731c26a6aSTushar Behera 	.probe = snow_probe,
11831c26a6aSTushar Behera };
11931c26a6aSTushar Behera 
12031c26a6aSTushar Behera module_platform_driver(snow_driver);
12131c26a6aSTushar Behera 
12231c26a6aSTushar Behera MODULE_DESCRIPTION("ALSA SoC Audio machine driver for Snow");
12331c26a6aSTushar Behera MODULE_LICENSE("GPL");
124