xref: /openbmc/linux/sound/soc/codecs/es7134.c (revision 5ef12cb4)
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_component_driver es7134_component_driver = {
73 	.dapm_widgets		= es7134_dapm_widgets,
74 	.num_dapm_widgets	= ARRAY_SIZE(es7134_dapm_widgets),
75 	.dapm_routes		= es7134_dapm_routes,
76 	.num_dapm_routes	= ARRAY_SIZE(es7134_dapm_routes),
77 	.idle_bias_on		= 1,
78 	.use_pmdown_time	= 1,
79 	.endianness		= 1,
80 	.non_legacy_dai_naming	= 1,
81 };
82 
83 static int es7134_probe(struct platform_device *pdev)
84 {
85 	return devm_snd_soc_register_component(&pdev->dev,
86 				      &es7134_component_driver,
87 				      &es7134_dai, 1);
88 }
89 
90 #ifdef CONFIG_OF
91 static const struct of_device_id es7134_ids[] = {
92 	{ .compatible = "everest,es7134", },
93 	{ .compatible = "everest,es7144", },
94 	{ }
95 };
96 MODULE_DEVICE_TABLE(of, es7134_ids);
97 #endif
98 
99 static struct platform_driver es7134_driver = {
100 	.driver = {
101 		.name = "es7134",
102 		.of_match_table = of_match_ptr(es7134_ids),
103 	},
104 	.probe = es7134_probe,
105 };
106 
107 module_platform_driver(es7134_driver);
108 
109 MODULE_DESCRIPTION("ASoC ES7134 audio codec driver");
110 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
111 MODULE_LICENSE("GPL");
112