1 // SPDX-License-Identifier: GPL-2.0-only
4 * Asahi Kasei AK5386 Single-ended 24-Bit 192kHz delta-sigma ADC
6 * (c) 2013 Daniel Mack <zonque@gmail.com>
9 #include <linux/module.h>
10 #include <linux/slab.h>
12 #include <linux/of_gpio.h>
13 #include <linux/regulator/consumer.h>
14 #include <sound/soc.h>
15 #include <sound/pcm.h>
16 #include <sound/initval.h>
18 static const char * const supply_names[] = {
24 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
27 static const struct snd_soc_dapm_widget ak5386_dapm_widgets[] = {
28 SND_SOC_DAPM_INPUT("AINL"),
29 SND_SOC_DAPM_INPUT("AINR"),
32 static const struct snd_soc_dapm_route ak5386_dapm_routes[] = {
33 { "Capture", NULL, "AINL" },
34 { "Capture", NULL, "AINR" },
37 static int ak5386_soc_probe(struct snd_soc_component *component)
39 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
40 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
43 static void ak5386_soc_remove(struct snd_soc_component *component)
45 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
46 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
50 static int ak5386_soc_suspend(struct snd_soc_component *component)
52 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
53 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
57 static int ak5386_soc_resume(struct snd_soc_component *component)
59 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
60 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
63 #define ak5386_soc_suspend NULL
64 #define ak5386_soc_resume NULL
65 #endif /* CONFIG_PM */
67 static const struct snd_soc_component_driver soc_component_ak5386 = {
68 .probe = ak5386_soc_probe,
69 .remove = ak5386_soc_remove,
70 .suspend = ak5386_soc_suspend,
71 .resume = ak5386_soc_resume,
72 .dapm_widgets = ak5386_dapm_widgets,
73 .num_dapm_widgets = ARRAY_SIZE(ak5386_dapm_widgets),
74 .dapm_routes = ak5386_dapm_routes,
75 .num_dapm_routes = ARRAY_SIZE(ak5386_dapm_routes),
81 static int ak5386_set_dai_fmt(struct snd_soc_dai *codec_dai,
84 struct snd_soc_component *component = codec_dai->component;
86 format &= SND_SOC_DAIFMT_FORMAT_MASK;
87 if (format != SND_SOC_DAIFMT_LEFT_J &&
88 format != SND_SOC_DAIFMT_I2S) {
89 dev_err(component->dev, "Invalid DAI format\n");
96 static int ak5386_hw_params(struct snd_pcm_substream *substream,
97 struct snd_pcm_hw_params *params,
98 struct snd_soc_dai *dai)
100 struct snd_soc_component *component = dai->component;
101 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
104 * From the datasheet:
106 * All external clocks (MCLK, SCLK and LRCK) must be present unless
107 * PDN pin = āLā. If these clocks are not provided, the AK5386 may
108 * draw excess current due to its use of internal dynamically
109 * refreshed logic. If the external clocks are not present, place
110 * the AK5386 in power-down mode (PDN pin = āLā).
113 if (gpio_is_valid(priv->reset_gpio))
114 gpio_set_value(priv->reset_gpio, 1);
119 static int ak5386_hw_free(struct snd_pcm_substream *substream,
120 struct snd_soc_dai *dai)
122 struct snd_soc_component *component = dai->component;
123 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component);
125 if (gpio_is_valid(priv->reset_gpio))
126 gpio_set_value(priv->reset_gpio, 0);
131 static const struct snd_soc_dai_ops ak5386_dai_ops = {
132 .set_fmt = ak5386_set_dai_fmt,
133 .hw_params = ak5386_hw_params,
134 .hw_free = ak5386_hw_free,
137 static struct snd_soc_dai_driver ak5386_dai = {
138 .name = "ak5386-hifi",
140 .stream_name = "Capture",
143 .rates = SNDRV_PCM_RATE_8000_192000,
144 .formats = SNDRV_PCM_FMTBIT_S8 |
145 SNDRV_PCM_FMTBIT_S16_LE |
146 SNDRV_PCM_FMTBIT_S24_LE |
147 SNDRV_PCM_FMTBIT_S24_3LE,
149 .ops = &ak5386_dai_ops,
153 static const struct of_device_id ak5386_dt_ids[] = {
154 { .compatible = "asahi-kasei,ak5386", },
157 MODULE_DEVICE_TABLE(of, ak5386_dt_ids);
160 static int ak5386_probe(struct platform_device *pdev)
162 struct device *dev = &pdev->dev;
163 struct ak5386_priv *priv;
166 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
170 dev_set_drvdata(dev, priv);
172 for (i = 0; i < ARRAY_SIZE(supply_names); i++)
173 priv->supplies[i].supply = supply_names[i];
175 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
180 priv->reset_gpio = of_get_named_gpio(dev->of_node,
183 if (gpio_is_valid(priv->reset_gpio))
184 if (devm_gpio_request_one(dev, priv->reset_gpio,
187 priv->reset_gpio = -EINVAL;
189 return devm_snd_soc_register_component(dev, &soc_component_ak5386,
193 static struct platform_driver ak5386_driver = {
194 .probe = ak5386_probe,
197 .of_match_table = of_match_ptr(ak5386_dt_ids),
201 module_platform_driver(ak5386_driver);
203 MODULE_DESCRIPTION("ASoC driver for AK5386 ADC");
204 MODULE_AUTHOR("Daniel Mack <zonque@gmail.com>");
205 MODULE_LICENSE("GPL");