Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- */
- #include <linux/module.h>
- #include <linux/i2c.h>
- #include <linux/delay.h>
- #include <sound/pcm.h>
- #include <sound/soc.h>
- #include <linux/io.h>
- #include <asm/mach-types.h>
- static int snd_rpi_bathat_init(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_codec *codec = rtd->codec;
- dev_info(codec->dev, "Bathat init");
- return 0;
- }
- /* CS4270 */
- static int snd_rpi_bathat_startup(struct snd_pcm_substream *substream)
- {
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
- struct snd_soc_codec *codec = rtd->codec;
- int sysclk = 24576000;
- int ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, 0);
- dev_info(codec->dev, "Bathat startup");
- if (ret < 0) {
- dev_err(codec->dev, "Unable to set CS4270 system clock.");
- }
- return ret;
- }
- static void snd_rpi_bathat_shutdown(struct snd_pcm_substream *substream) {
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_soc_codec *codec = rtd->codec;
- dev_info(codec->dev, "Bathat shutdown");
- }
- static int snd_rpi_bathat_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 *codec_dai = rtd->codec_dai;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- struct snd_soc_codec *codec = rtd->codec;
- int sysclk = 24576000;
- int ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, 0);
- dev_info(codec->dev, "Bathat HW params");
- if (ret < 0) {
- dev_err(codec->dev, "Unable to set CS4270 system clock.");
- }
- return ret;
- }
- static struct snd_soc_ops snd_rpi_bathat_ops = {
- .startup = snd_rpi_bathat_startup,
- .shutdown = snd_rpi_bathat_shutdown,
- .hw_params = snd_rpi_bathat_hw_params,
- };
- static struct snd_soc_dai_link snd_soc_rpi_bathat_dai[] = {
- {
- .name = "BatHat",
- .stream_name = "BatHat",
- .cpu_dai_name = "bcm2708-i2s.0",
- .codec_dai_name = "cs4270-hifi",
- .platform_name = "bcm2708-pcm-audio.0",
- .codec_name = "cs4270.1-0048",
- .dai_fmt = SND_SOC_DAIFMT_I2S
- | SND_SOC_DAIFMT_NB_NF
- | SND_SOC_DAIFMT_CBS_CFS,
- .ops = &snd_rpi_bathat_ops,
- .init = snd_rpi_bathat_init,
- }
- };
- static struct snd_soc_card snd_rpi_bathat = {
- .name = "snd_rpi_bathat",
- .owner = THIS_MODULE,
- .dai_link = snd_soc_rpi_bathat_dai,
- .num_links = ARRAY_SIZE(snd_soc_rpi_bathat_dai),
- };
- static int snd_rpi_bathat_probe(struct platform_device *pdev)
- {
- int ret = 0;
- snd_rpi_bathat.dev = &pdev->dev;
- dev_info(&pdev->dev, "Bathat probe");
- if (pdev->dev.of_node) {
- struct device_node *i2s_node;
- struct snd_soc_dai_link *dai = &snd_soc_rpi_bathat_dai[0];
- i2s_node = of_parse_phandle(pdev->dev.of_node,
- "i2s-controller", 0);
- dev_info(&pdev->dev, "Bathat has of_node");
- if (i2s_node) {
- dev_info(&pdev->dev, "Bathat has i2s_node");
- dai->cpu_dai_name = NULL;
- dai->cpu_of_node = i2s_node;
- dai->platform_name = NULL;
- dai->platform_of_node = i2s_node;
- }
- }
- ret = snd_soc_register_card(&snd_rpi_bathat);
- if (ret)
- dev_err(&pdev->dev,
- "snd_soc_register_card() failed: %d\n", ret);
- return ret;
- }
- static int snd_rpi_bathat_remove(struct platform_device *pdev)
- {
- dev_info(&pdev->dev, "Bathat remove");
- return snd_soc_unregister_card(&snd_rpi_bathat);
- }
- static const struct of_device_id snd_rpi_bathat_of_match[] = {
- { .compatible = "bathat", },
- {},
- };
- MODULE_DEVICE_TABLE(of, snd_rpi_bathat_of_match);
- static struct platform_driver snd_rpi_bathat_driver = {
- .driver = {
- .name = "snd-rpi-bathat",
- .owner = THIS_MODULE,
- .of_match_table = snd_rpi_bathat_of_match,
- },
- .probe = snd_rpi_bathat_probe,
- .remove = snd_rpi_bathat_remove,
- };
- module_platform_driver(snd_rpi_bathat_driver);
- /* Module information */
- MODULE_AUTHOR("REDACTED");
- MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to BatHat board (CS4270)");
- MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement