ASoC: SAMSUNG: Change Kconfig to support all SAMSUNG ASoC
[linux-block.git] / sound / soc / ep93xx / edb93xx.c
CommitLineData
86c33041
AS
1/*
2 * SoC audio for EDB93xx
3 *
4 * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * This driver support CS4271 codec being master or slave, working
17 * in control port mode, connected either via SPI or I2C.
18 * The data format accepted is I2S or left-justified.
19 * DAPM support not implemented.
20 */
21
22#include <linux/platform_device.h>
23#include <linux/gpio.h>
da155d5b 24#include <linux/module.h>
86c33041
AS
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
28#include <asm/mach-types.h>
29#include <mach/hardware.h>
30#include "ep93xx-pcm.h"
31
86c33041
AS
32static int edb93xx_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_dai *codec_dai = rtd->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
38 int err;
6d33cd77 39 unsigned int mclk_rate;
86c33041 40 unsigned int rate = params_rate(params);
6d33cd77 41
86c33041 42 /*
6d33cd77
AS
43 * According to CS4271 datasheet we use MCLK/LRCK=256 for
44 * rates below 50kHz and 128 for higher sample rates
86c33041 45 */
6d33cd77
AS
46 if (rate < 50000)
47 mclk_rate = rate * 64 * 4;
48 else
49 mclk_rate = rate * 64 * 2;
86c33041 50
86c33041
AS
51 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
52 SND_SOC_CLOCK_IN);
53 if (err)
54 return err;
55
56 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
57 SND_SOC_CLOCK_OUT);
58}
59
60static struct snd_soc_ops edb93xx_ops = {
61 .hw_params = edb93xx_hw_params,
62};
63
64static struct snd_soc_dai_link edb93xx_dai = {
65 .name = "CS4271",
66 .stream_name = "CS4271 HiFi",
67 .platform_name = "ep93xx-pcm-audio",
68 .cpu_dai_name = "ep93xx-i2s",
69 .codec_name = "spi0.0",
70 .codec_dai_name = "cs4271-hifi",
f521812b
AL
71 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
72 SND_SOC_DAIFMT_CBS_CFS,
86c33041
AS
73 .ops = &edb93xx_ops,
74};
75
76static struct snd_soc_card snd_soc_edb93xx = {
77 .name = "EDB93XX",
a76a7023 78 .owner = THIS_MODULE,
86c33041
AS
79 .dai_link = &edb93xx_dai,
80 .num_links = 1,
81};
82
8a386ca2 83static int __devinit edb93xx_probe(struct platform_device *pdev)
86c33041 84{
8a386ca2 85 struct snd_soc_card *card = &snd_soc_edb93xx;
86c33041
AS
86 int ret;
87
44fb864b 88 ret = ep93xx_i2s_acquire();
86c33041
AS
89 if (ret)
90 return ret;
91
8a386ca2
MW
92 card->dev = &pdev->dev;
93
94 ret = snd_soc_register_card(card);
95 if (ret) {
96 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
97 ret);
98 ep93xx_i2s_release();
86c33041
AS
99 }
100
8a386ca2
MW
101 return ret;
102}
86c33041 103
8a386ca2
MW
104static int __devexit edb93xx_remove(struct platform_device *pdev)
105{
106 struct snd_soc_card *card = platform_get_drvdata(pdev);
86c33041 107
8a386ca2 108 snd_soc_unregister_card(card);
86c33041 109 ep93xx_i2s_release();
8a386ca2
MW
110
111 return 0;
112}
113
114static struct platform_driver edb93xx_driver = {
115 .driver = {
116 .name = "edb93xx-audio",
117 .owner = THIS_MODULE,
118 },
119 .probe = edb93xx_probe,
120 .remove = __devexit_p(edb93xx_remove),
121};
122
ee18f631 123module_platform_driver(edb93xx_driver);
86c33041
AS
124
125MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
126MODULE_DESCRIPTION("ALSA SoC EDB93xx");
127MODULE_LICENSE("GPL");
8a386ca2 128MODULE_ALIAS("platform:edb93xx-audio");