0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/platform_device.h>
0014 #include <linux/gpio.h>
0015 #include <linux/module.h>
0016 #include <linux/soc/cirrus/ep93xx.h>
0017 #include <sound/core.h>
0018 #include <sound/pcm.h>
0019 #include <sound/soc.h>
0020 #include <asm/mach-types.h>
0021
0022 static int edb93xx_hw_params(struct snd_pcm_substream *substream,
0023 struct snd_pcm_hw_params *params)
0024 {
0025 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0026 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0027 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0028 int err;
0029 unsigned int mclk_rate;
0030 unsigned int rate = params_rate(params);
0031
0032
0033
0034
0035
0036 if (rate < 50000)
0037 mclk_rate = rate * 64 * 4;
0038 else
0039 mclk_rate = rate * 64 * 2;
0040
0041 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
0042 SND_SOC_CLOCK_IN);
0043 if (err)
0044 return err;
0045
0046 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
0047 SND_SOC_CLOCK_OUT);
0048 }
0049
0050 static const struct snd_soc_ops edb93xx_ops = {
0051 .hw_params = edb93xx_hw_params,
0052 };
0053
0054 SND_SOC_DAILINK_DEFS(hifi,
0055 DAILINK_COMP_ARRAY(COMP_CPU("ep93xx-i2s")),
0056 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "cs4271-hifi")),
0057 DAILINK_COMP_ARRAY(COMP_PLATFORM("ep93xx-i2s")));
0058
0059 static struct snd_soc_dai_link edb93xx_dai = {
0060 .name = "CS4271",
0061 .stream_name = "CS4271 HiFi",
0062 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0063 SND_SOC_DAIFMT_CBC_CFC,
0064 .ops = &edb93xx_ops,
0065 SND_SOC_DAILINK_REG(hifi),
0066 };
0067
0068 static struct snd_soc_card snd_soc_edb93xx = {
0069 .name = "EDB93XX",
0070 .owner = THIS_MODULE,
0071 .dai_link = &edb93xx_dai,
0072 .num_links = 1,
0073 };
0074
0075 static int edb93xx_probe(struct platform_device *pdev)
0076 {
0077 struct snd_soc_card *card = &snd_soc_edb93xx;
0078 int ret;
0079
0080 ret = ep93xx_i2s_acquire();
0081 if (ret)
0082 return ret;
0083
0084 card->dev = &pdev->dev;
0085
0086 ret = snd_soc_register_card(card);
0087 if (ret) {
0088 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
0089 ret);
0090 ep93xx_i2s_release();
0091 }
0092
0093 return ret;
0094 }
0095
0096 static int edb93xx_remove(struct platform_device *pdev)
0097 {
0098 struct snd_soc_card *card = platform_get_drvdata(pdev);
0099
0100 snd_soc_unregister_card(card);
0101 ep93xx_i2s_release();
0102
0103 return 0;
0104 }
0105
0106 static struct platform_driver edb93xx_driver = {
0107 .driver = {
0108 .name = "edb93xx-audio",
0109 },
0110 .probe = edb93xx_probe,
0111 .remove = edb93xx_remove,
0112 };
0113
0114 module_platform_driver(edb93xx_driver);
0115
0116 MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
0117 MODULE_DESCRIPTION("ALSA SoC EDB93xx");
0118 MODULE_LICENSE("GPL");
0119 MODULE_ALIAS("platform:edb93xx-audio");