mtd: add ECC info for nand_flash_dev{}
[linux/fpc-iii.git] / sound / soc / codecs / ak5386.c
blob1f303983ae02ddaf0a433ff32c188046d3da68a7
1 /*
2 * ALSA SoC driver for
3 * Asahi Kasei AK5386 Single-ended 24-Bit 192kHz delta-sigma ADC
5 * (c) 2013 Daniel Mack <zonque@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/of.h>
15 #include <linux/of_gpio.h>
16 #include <linux/of_device.h>
17 #include <sound/soc.h>
18 #include <sound/pcm.h>
19 #include <sound/initval.h>
21 struct ak5386_priv {
22 int reset_gpio;
25 static struct snd_soc_codec_driver soc_codec_ak5386;
27 static int ak5386_set_dai_fmt(struct snd_soc_dai *codec_dai,
28 unsigned int format)
30 struct snd_soc_codec *codec = codec_dai->codec;
32 format &= SND_SOC_DAIFMT_FORMAT_MASK;
33 if (format != SND_SOC_DAIFMT_LEFT_J &&
34 format != SND_SOC_DAIFMT_I2S) {
35 dev_err(codec->dev, "Invalid DAI format\n");
36 return -EINVAL;
39 return 0;
42 static int ak5386_hw_params(struct snd_pcm_substream *substream,
43 struct snd_pcm_hw_params *params,
44 struct snd_soc_dai *dai)
46 struct snd_soc_codec *codec = dai->codec;
47 struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec);
50 * From the datasheet:
52 * All external clocks (MCLK, SCLK and LRCK) must be present unless
53 * PDN pin = ā€œLā€. If these clocks are not provided, the AK5386 may
54 * draw excess current due to its use of internal dynamically
55 * refreshed logic. If the external clocks are not present, place
56 * the AK5386 in power-down mode (PDN pin = ā€œLā€).
59 if (gpio_is_valid(priv->reset_gpio))
60 gpio_set_value(priv->reset_gpio, 1);
62 return 0;
65 static int ak5386_hw_free(struct snd_pcm_substream *substream,
66 struct snd_soc_dai *dai)
68 struct snd_soc_codec *codec = dai->codec;
69 struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec);
71 if (gpio_is_valid(priv->reset_gpio))
72 gpio_set_value(priv->reset_gpio, 0);
74 return 0;
77 static const struct snd_soc_dai_ops ak5386_dai_ops = {
78 .set_fmt = ak5386_set_dai_fmt,
79 .hw_params = ak5386_hw_params,
80 .hw_free = ak5386_hw_free,
83 static struct snd_soc_dai_driver ak5386_dai = {
84 .name = "ak5386-hifi",
85 .capture = {
86 .stream_name = "Capture",
87 .channels_min = 1,
88 .channels_max = 2,
89 .rates = SNDRV_PCM_RATE_8000_192000,
90 .formats = SNDRV_PCM_FMTBIT_S8 |
91 SNDRV_PCM_FMTBIT_S16_LE |
92 SNDRV_PCM_FMTBIT_S24_LE |
93 SNDRV_PCM_FMTBIT_S24_3LE,
95 .ops = &ak5386_dai_ops,
98 #ifdef CONFIG_OF
99 static const struct of_device_id ak5386_dt_ids[] = {
100 { .compatible = "asahi-kasei,ak5386", },
103 MODULE_DEVICE_TABLE(of, ak5386_dt_ids);
104 #endif
106 static int ak5386_probe(struct platform_device *pdev)
108 struct device *dev = &pdev->dev;
109 struct ak5386_priv *priv;
111 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
112 if (!priv)
113 return -ENOMEM;
115 priv->reset_gpio = -EINVAL;
116 dev_set_drvdata(dev, priv);
118 if (of_match_device(of_match_ptr(ak5386_dt_ids), dev))
119 priv->reset_gpio = of_get_named_gpio(dev->of_node,
120 "reset-gpio", 0);
122 if (gpio_is_valid(priv->reset_gpio))
123 if (devm_gpio_request_one(dev, priv->reset_gpio,
124 GPIOF_OUT_INIT_LOW,
125 "AK5386 Reset"))
126 priv->reset_gpio = -EINVAL;
128 return snd_soc_register_codec(dev, &soc_codec_ak5386,
129 &ak5386_dai, 1);
132 static int ak5386_remove(struct platform_device *pdev)
134 snd_soc_unregister_codec(&pdev->dev);
135 return 0;
138 static struct platform_driver ak5386_driver = {
139 .probe = ak5386_probe,
140 .remove = ak5386_remove,
141 .driver = {
142 .name = "ak5386",
143 .owner = THIS_MODULE,
144 .of_match_table = of_match_ptr(ak5386_dt_ids),
148 module_platform_driver(ak5386_driver);
150 MODULE_DESCRIPTION("ASoC driver for AK5386 ADC");
151 MODULE_AUTHOR("Daniel Mack <zonque@gmail.com>");
152 MODULE_LICENSE("GPL");