Merge tag 'iio-fixes-for-5.2b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23...
[platform/kernel/linux-rpi.git] / sound / soc / pxa / imote2.c
1 // SPDX-License-Identifier: GPL-2.0-only
2
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"
10
11 static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
12                                  struct snd_pcm_hw_params *params)
13 {
14         struct snd_soc_pcm_runtime *rtd = substream->private_data;
15         struct snd_soc_dai *codec_dai = rtd->codec_dai;
16         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
17         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
34         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
46 static const struct snd_soc_ops imote2_asoc_ops = {
47         .hw_params = imote2_asoc_hw_params,
48 };
49
50 static struct snd_soc_dai_link imote2_dai = {
51         .name = "WM8940",
52         .stream_name = "WM8940",
53         .cpu_dai_name = "pxa2xx-i2s",
54         .codec_dai_name = "wm8940-hifi",
55         .platform_name = "pxa-pcm-audio",
56         .codec_name = "wm8940-codec.0-0034",
57         .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
58                    SND_SOC_DAIFMT_CBS_CFS,
59         .ops = &imote2_asoc_ops,
60 };
61
62 static struct snd_soc_card imote2 = {
63         .name = "Imote2",
64         .owner = THIS_MODULE,
65         .dai_link = &imote2_dai,
66         .num_links = 1,
67 };
68
69 static int imote2_probe(struct platform_device *pdev)
70 {
71         struct snd_soc_card *card = &imote2;
72         int ret;
73
74         card->dev = &pdev->dev;
75
76         ret = devm_snd_soc_register_card(&pdev->dev, card);
77         if (ret)
78                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
79                         ret);
80         return ret;
81 }
82
83 static struct platform_driver imote2_driver = {
84         .driver         = {
85                 .name   = "imote2-audio",
86                 .pm     = &snd_soc_pm_ops,
87         },
88         .probe          = imote2_probe,
89 };
90
91 module_platform_driver(imote2_driver);
92
93 MODULE_AUTHOR("Jonathan Cameron");
94 MODULE_DESCRIPTION("ALSA SoC Imote 2");
95 MODULE_LICENSE("GPL");
96 MODULE_ALIAS("platform:imote2-audio");