blob: 51930b6a83af193f3f802df490df3f00b7930cd1 [file] [log] [blame]
Alexander Sverdlin86c33042011-01-23 04:01:15 +03001/*
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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040024#include <linux/module.h>
Alexander Sverdlin86c33042011-01-23 04:01:15 +030025#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
Alexander Sverdlin86c33042011-01-23 04:01:15 +030032static 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;
Alexander Sverdlin6d33cd72011-03-07 20:29:53 +030039 unsigned int mclk_rate;
Alexander Sverdlin86c33042011-01-23 04:01:15 +030040 unsigned int rate = params_rate(params);
Alexander Sverdlin6d33cd72011-03-07 20:29:53 +030041
Alexander Sverdlin86c33042011-01-23 04:01:15 +030042 /*
Alexander Sverdlin6d33cd72011-03-07 20:29:53 +030043 * According to CS4271 datasheet we use MCLK/LRCK=256 for
44 * rates below 50kHz and 128 for higher sample rates
Alexander Sverdlin86c33042011-01-23 04:01:15 +030045 */
Alexander Sverdlin6d33cd72011-03-07 20:29:53 +030046 if (rate < 50000)
47 mclk_rate = rate * 64 * 4;
48 else
49 mclk_rate = rate * 64 * 2;
Alexander Sverdlin86c33042011-01-23 04:01:15 +030050
51 err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
52 SND_SOC_DAIFMT_NB_IF |
53 SND_SOC_DAIFMT_CBS_CFS);
54 if (err)
55 return err;
56
57 err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
58 SND_SOC_DAIFMT_NB_IF |
59 SND_SOC_DAIFMT_CBS_CFS);
60 if (err)
61 return err;
62
63 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
64 SND_SOC_CLOCK_IN);
65 if (err)
66 return err;
67
68 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
69 SND_SOC_CLOCK_OUT);
70}
71
72static struct snd_soc_ops edb93xx_ops = {
73 .hw_params = edb93xx_hw_params,
74};
75
76static struct snd_soc_dai_link edb93xx_dai = {
77 .name = "CS4271",
78 .stream_name = "CS4271 HiFi",
79 .platform_name = "ep93xx-pcm-audio",
80 .cpu_dai_name = "ep93xx-i2s",
81 .codec_name = "spi0.0",
82 .codec_dai_name = "cs4271-hifi",
83 .ops = &edb93xx_ops,
84};
85
86static struct snd_soc_card snd_soc_edb93xx = {
87 .name = "EDB93XX",
88 .dai_link = &edb93xx_dai,
89 .num_links = 1,
90};
91
Mika Westerberg8a386ca2011-09-11 12:28:51 +030092static int __devinit edb93xx_probe(struct platform_device *pdev)
Alexander Sverdlin86c33042011-01-23 04:01:15 +030093{
Mika Westerberg8a386ca2011-09-11 12:28:51 +030094 struct snd_soc_card *card = &snd_soc_edb93xx;
Alexander Sverdlin86c33042011-01-23 04:01:15 +030095 int ret;
96
Alexander Sverdlin86c33042011-01-23 04:01:15 +030097 ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
98 EP93XX_SYSCON_I2SCLKDIV_ORIDE |
99 EP93XX_SYSCON_I2SCLKDIV_SPOL);
100 if (ret)
101 return ret;
102
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300103 card->dev = &pdev->dev;
104
105 ret = snd_soc_register_card(card);
106 if (ret) {
107 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
108 ret);
109 ep93xx_i2s_release();
Alexander Sverdlin86c33042011-01-23 04:01:15 +0300110 }
111
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300112 return ret;
113}
114
115static int __devexit edb93xx_remove(struct platform_device *pdev)
116{
117 struct snd_soc_card *card = platform_get_drvdata(pdev);
118
119 snd_soc_unregister_card(card);
120 ep93xx_i2s_release();
Alexander Sverdlin86c33042011-01-23 04:01:15 +0300121
122 return 0;
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300123}
Alexander Sverdlin86c33042011-01-23 04:01:15 +0300124
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300125static struct platform_driver edb93xx_driver = {
126 .driver = {
127 .name = "edb93xx-audio",
128 .owner = THIS_MODULE,
129 },
130 .probe = edb93xx_probe,
131 .remove = __devexit_p(edb93xx_remove),
132};
133
134static int __init edb93xx_init(void)
135{
136 return platform_driver_register(&edb93xx_driver);
Alexander Sverdlin86c33042011-01-23 04:01:15 +0300137}
138module_init(edb93xx_init);
139
140static void __exit edb93xx_exit(void)
141{
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300142 platform_driver_unregister(&edb93xx_driver);
Alexander Sverdlin86c33042011-01-23 04:01:15 +0300143}
144module_exit(edb93xx_exit);
145
146MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
147MODULE_DESCRIPTION("ALSA SoC EDB93xx");
148MODULE_LICENSE("GPL");
Mika Westerberg8a386ca2011-09-11 12:28:51 +0300149MODULE_ALIAS("platform:edb93xx-audio");