ASoC: use snd_soc_component_init_regmap() on cs47l24
[sfrench/cifs-2.6.git] / sound / soc / codecs / es7134.c
1 /*
2  * Copyright (c) 2017 BayLibre, SAS.
3  * Author: Jerome Brunet <jbrunet@baylibre.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see <http://www.gnu.org/licenses/>.
16  * The full GNU General Public License is included in this distribution
17  * in the file called COPYING.
18  */
19
20 #include <linux/module.h>
21 #include <sound/soc.h>
22
23 /*
24  * The everest 7134 is a very simple DA converter with no register
25  */
26
27 static int es7134_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
28 {
29         fmt &= (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK |
30                 SND_SOC_DAIFMT_MASTER_MASK);
31
32         if (fmt != (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
33                     SND_SOC_DAIFMT_CBS_CFS)) {
34                 dev_err(codec_dai->dev, "Invalid DAI format\n");
35                 return -EINVAL;
36         }
37
38         return 0;
39 }
40
41 static const struct snd_soc_dai_ops es7134_dai_ops = {
42         .set_fmt        = es7134_set_fmt,
43 };
44
45 static struct snd_soc_dai_driver es7134_dai = {
46         .name = "es7134-hifi",
47         .playback = {
48                 .stream_name = "Playback",
49                 .channels_min = 2,
50                 .channels_max = 2,
51                 .rates = SNDRV_PCM_RATE_8000_192000,
52                 .formats = (SNDRV_PCM_FMTBIT_S16_LE  |
53                             SNDRV_PCM_FMTBIT_S18_3LE |
54                             SNDRV_PCM_FMTBIT_S20_3LE |
55                             SNDRV_PCM_FMTBIT_S24_3LE |
56                             SNDRV_PCM_FMTBIT_S24_LE),
57         },
58         .ops = &es7134_dai_ops,
59 };
60
61 static const struct snd_soc_dapm_widget es7134_dapm_widgets[] = {
62         SND_SOC_DAPM_OUTPUT("AOUTL"),
63         SND_SOC_DAPM_OUTPUT("AOUTR"),
64         SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
65 };
66
67 static const struct snd_soc_dapm_route es7134_dapm_routes[] = {
68         { "AOUTL", NULL, "DAC" },
69         { "AOUTR", NULL, "DAC" },
70 };
71
72 static const struct snd_soc_codec_driver es7134_codec_driver = {
73         .component_driver = {
74                 .dapm_widgets           = es7134_dapm_widgets,
75                 .num_dapm_widgets       = ARRAY_SIZE(es7134_dapm_widgets),
76                 .dapm_routes            = es7134_dapm_routes,
77                 .num_dapm_routes        = ARRAY_SIZE(es7134_dapm_routes),
78         },
79 };
80
81 static int es7134_probe(struct platform_device *pdev)
82 {
83         return snd_soc_register_codec(&pdev->dev,
84                                       &es7134_codec_driver,
85                                       &es7134_dai, 1);
86 }
87
88 static int es7134_remove(struct platform_device *pdev)
89 {
90         snd_soc_unregister_codec(&pdev->dev);
91         return 0;
92 }
93
94 #ifdef CONFIG_OF
95 static const struct of_device_id es7134_ids[] = {
96         { .compatible = "everest,es7134", },
97         { .compatible = "everest,es7144", },
98         { }
99 };
100 MODULE_DEVICE_TABLE(of, es7134_ids);
101 #endif
102
103 static struct platform_driver es7134_driver = {
104         .driver = {
105                 .name = "es7134",
106                 .of_match_table = of_match_ptr(es7134_ids),
107         },
108         .probe = es7134_probe,
109         .remove = es7134_remove,
110 };
111
112 module_platform_driver(es7134_driver);
113
114 MODULE_DESCRIPTION("ASoC ES7134 audio codec driver");
115 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
116 MODULE_LICENSE("GPL");