blob: a575676508b35a0812f0ecd661c7ee6b9123b708 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Jonathan Camerona195b512009-05-04 14:54:11 +00002
3#include <linux/module.h>
4#include <sound/soc.h>
5
6#include <asm/mach-types.h>
7
8#include "../codecs/wm8940.h"
9#include "pxa2xx-i2s.h"
Jonathan Camerona195b512009-05-04 14:54:11 +000010
11static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
12 struct snd_pcm_hw_params *params)
13{
Kuninori Morimoto83b95c22020-07-20 10:18:20 +090014 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto8d8fef22020-03-23 14:19:49 +090015 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
16 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
Jonathan Camerona195b512009-05-04 14:54:11 +000017 unsigned int clk = 0;
18 int ret;
19
20 switch (params_rate(params)) {
21 case 8000:
22 case 16000:
23 case 48000:
24 case 96000:
25 clk = 12288000;
26 break;
27 case 11025:
28 case 22050:
29 case 44100:
30 clk = 11289600;
31 break;
32 }
33
Jonathan Camerona195b512009-05-04 14:54:11 +000034 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
35 SND_SOC_CLOCK_IN);
36 if (ret < 0)
37 return ret;
38
39 /* set the I2S system clock as input (unused) */
40 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
41 SND_SOC_CLOCK_OUT);
42
43 return ret;
44}
45
Bhumika Goyal943b7312017-03-14 01:16:40 +053046static const struct snd_soc_ops imote2_asoc_ops = {
Jonathan Camerona195b512009-05-04 14:54:11 +000047 .hw_params = imote2_asoc_hw_params,
48};
49
Kuninori Morimoto76359b12019-06-06 13:11:46 +090050SND_SOC_DAILINK_DEFS(wm8940,
51 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
52 DAILINK_COMP_ARRAY(COMP_CODEC("wm8940-codec.0-0034",
53 "wm8940-hifi")),
54 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
55
Jonathan Camerona195b512009-05-04 14:54:11 +000056static struct snd_soc_dai_link imote2_dai = {
57 .name = "WM8940",
58 .stream_name = "WM8940",
Axel Lin52ec35f2011-12-20 16:27:28 +080059 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
60 SND_SOC_DAIFMT_CBS_CFS,
Jonathan Camerona195b512009-05-04 14:54:11 +000061 .ops = &imote2_asoc_ops,
Kuninori Morimoto76359b12019-06-06 13:11:46 +090062 SND_SOC_DAILINK_REG(wm8940),
Jonathan Camerona195b512009-05-04 14:54:11 +000063};
64
Axel Linac1e8982011-12-15 10:55:24 +080065static struct snd_soc_card imote2 = {
Jonathan Camerona195b512009-05-04 14:54:11 +000066 .name = "Imote2",
Axel Lin561c6a12011-12-22 09:44:43 +080067 .owner = THIS_MODULE,
Jonathan Camerona195b512009-05-04 14:54:11 +000068 .dai_link = &imote2_dai,
69 .num_links = 1,
70};
71
Bill Pemberton570f6fe2012-12-07 09:26:17 -050072static int imote2_probe(struct platform_device *pdev)
Jonathan Camerona195b512009-05-04 14:54:11 +000073{
Axel Linac1e8982011-12-15 10:55:24 +080074 struct snd_soc_card *card = &imote2;
Jonathan Camerona195b512009-05-04 14:54:11 +000075 int ret;
76
Axel Linac1e8982011-12-15 10:55:24 +080077 card->dev = &pdev->dev;
Jonathan Camerona195b512009-05-04 14:54:11 +000078
Axel Lin2fd70762015-09-01 10:32:59 +080079 ret = devm_snd_soc_register_card(&pdev->dev, card);
Jonathan Camerona195b512009-05-04 14:54:11 +000080 if (ret)
Axel Linac1e8982011-12-15 10:55:24 +080081 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
82 ret);
Jonathan Camerona195b512009-05-04 14:54:11 +000083 return ret;
84}
Jonathan Camerona195b512009-05-04 14:54:11 +000085
Axel Linac1e8982011-12-15 10:55:24 +080086static struct platform_driver imote2_driver = {
87 .driver = {
88 .name = "imote2-audio",
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +040089 .pm = &snd_soc_pm_ops,
Axel Linac1e8982011-12-15 10:55:24 +080090 },
91 .probe = imote2_probe,
Axel Linac1e8982011-12-15 10:55:24 +080092};
93
94module_platform_driver(imote2_driver);
Jonathan Camerona195b512009-05-04 14:54:11 +000095
96MODULE_AUTHOR("Jonathan Cameron");
97MODULE_DESCRIPTION("ALSA SoC Imote 2");
98MODULE_LICENSE("GPL");
Axel Linac1e8982011-12-15 10:55:24 +080099MODULE_ALIAS("platform:imote2-audio");