]> Pileus Git - ~andy/linux/commitdiff
ASoC: Add codec driver for AK5386
authorDaniel Mack <zonque@gmail.com>
Fri, 8 Mar 2013 11:07:28 +0000 (12:07 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 8 Mar 2013 11:49:22 +0000 (19:49 +0800)
Adds a driver for Asahi Kasei's AK5386 Single-ended 24-Bit 192kHz
delta-sigma ADC. The device has no control port interface but an
optional RESET/PDN GPIO pin.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Documentation/devicetree/bindings/sound/ak5386.txt [new file with mode: 0644]
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/ak5386.c [new file with mode: 0644]

diff --git a/Documentation/devicetree/bindings/sound/ak5386.txt b/Documentation/devicetree/bindings/sound/ak5386.txt
new file mode 100644 (file)
index 0000000..dc3914f
--- /dev/null
@@ -0,0 +1,19 @@
+AK5386 Single-ended 24-Bit 192kHz delta-sigma ADC
+
+This device has no control interface.
+
+Required properties:
+
+  - compatible : "asahi-kasei,ak5386"
+
+Optional properties:
+
+  - reset-gpio : a GPIO spec for the reset/power down pin.
+                If specified, it will be deasserted at probe time.
+
+Example:
+
+spdif: ak5386@0 {
+       compatible = "asahi-kasei,ak5386";
+       reset-gpio = <&gpio0 23>;
+};
index 45b72561c61588f672b524471d9c5dd96cdeb73f..500f666c3875474e15f4d9b9fa9f153f48080419 100644 (file)
@@ -26,6 +26,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_AK4641 if I2C
        select SND_SOC_AK4642 if I2C
        select SND_SOC_AK4671 if I2C
+       select SND_SOC_AK5386
        select SND_SOC_ALC5623 if I2C
        select SND_SOC_ALC5632 if I2C
        select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
@@ -203,6 +204,9 @@ config SND_SOC_AK4642
 config SND_SOC_AK4671
        tristate
 
+config SND_SOC_AK5386
+       tristate
+
 config SND_SOC_ALC5623
        tristate
 config SND_SOC_ALC5632
index 6a3b3c3b8b4115ebaea8c673d2f4b4916a8ef2ee..3a7ec1c397419da6c4270c5c591a312e33d0f1df 100644 (file)
@@ -14,6 +14,7 @@ snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4641-objs := ak4641.o
 snd-soc-ak4642-objs := ak4642.o
 snd-soc-ak4671-objs := ak4671.o
+snd-soc-ak5386-objs := ak5386.o
 snd-soc-arizona-objs := arizona.o
 snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs42l51-objs := cs42l51.o
@@ -137,6 +138,7 @@ obj-$(CONFIG_SND_SOC_AK4535)        += snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4641)   += snd-soc-ak4641.o
 obj-$(CONFIG_SND_SOC_AK4642)   += snd-soc-ak4642.o
 obj-$(CONFIG_SND_SOC_AK4671)   += snd-soc-ak4671.o
+obj-$(CONFIG_SND_SOC_AK5386)   += snd-soc-ak5386.o
 obj-$(CONFIG_SND_SOC_ALC5623)    += snd-soc-alc5623.o
 obj-$(CONFIG_SND_SOC_ALC5632)  += snd-soc-alc5632.o
 obj-$(CONFIG_SND_SOC_ARIZONA)  += snd-soc-arizona.o
diff --git a/sound/soc/codecs/ak5386.c b/sound/soc/codecs/ak5386.c
new file mode 100644 (file)
index 0000000..1f30398
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * ALSA SoC driver for
+ *    Asahi Kasei AK5386 Single-ended 24-Bit 192kHz delta-sigma ADC
+ *
+ * (c) 2013 Daniel Mack <zonque@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/of_device.h>
+#include <sound/soc.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+
+struct ak5386_priv {
+       int reset_gpio;
+};
+
+static struct snd_soc_codec_driver soc_codec_ak5386;
+
+static int ak5386_set_dai_fmt(struct snd_soc_dai *codec_dai,
+                             unsigned int format)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+
+       format &= SND_SOC_DAIFMT_FORMAT_MASK;
+       if (format != SND_SOC_DAIFMT_LEFT_J &&
+           format != SND_SOC_DAIFMT_I2S) {
+               dev_err(codec->dev, "Invalid DAI format\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int ak5386_hw_params(struct snd_pcm_substream *substream,
+                           struct snd_pcm_hw_params *params,
+                           struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec);
+
+       /*
+        * From the datasheet:
+        *
+        * All external clocks (MCLK, SCLK and LRCK) must be present unless
+        * PDN pin = ā€œLā€. If these clocks are not provided, the AK5386 may
+        * draw excess current due to its use of internal dynamically
+        * refreshed logic. If the external clocks are not present, place
+        * the AK5386 in power-down mode (PDN pin = ā€œLā€).
+        */
+
+       if (gpio_is_valid(priv->reset_gpio))
+               gpio_set_value(priv->reset_gpio, 1);
+
+       return 0;
+}
+
+static int ak5386_hw_free(struct snd_pcm_substream *substream,
+                         struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec);
+
+       if (gpio_is_valid(priv->reset_gpio))
+               gpio_set_value(priv->reset_gpio, 0);
+
+       return 0;
+}
+
+static const struct snd_soc_dai_ops ak5386_dai_ops = {
+       .set_fmt        = ak5386_set_dai_fmt,
+       .hw_params      = ak5386_hw_params,
+       .hw_free        = ak5386_hw_free,
+};
+
+static struct snd_soc_dai_driver ak5386_dai = {
+       .name           = "ak5386-hifi",
+       .capture        = {
+               .stream_name    = "Capture",
+               .channels_min   = 1,
+               .channels_max   = 2,
+               .rates          = SNDRV_PCM_RATE_8000_192000,
+               .formats        = SNDRV_PCM_FMTBIT_S8     |
+                                 SNDRV_PCM_FMTBIT_S16_LE |
+                                 SNDRV_PCM_FMTBIT_S24_LE |
+                                 SNDRV_PCM_FMTBIT_S24_3LE,
+       },
+       .ops    = &ak5386_dai_ops,
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id ak5386_dt_ids[] = {
+       { .compatible = "asahi-kasei,ak5386", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, ak5386_dt_ids);
+#endif
+
+static int ak5386_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct ak5386_priv *priv;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       priv->reset_gpio = -EINVAL;
+       dev_set_drvdata(dev, priv);
+
+       if (of_match_device(of_match_ptr(ak5386_dt_ids), dev))
+               priv->reset_gpio = of_get_named_gpio(dev->of_node,
+                                                     "reset-gpio", 0);
+
+       if (gpio_is_valid(priv->reset_gpio))
+               if (devm_gpio_request_one(dev, priv->reset_gpio,
+                                         GPIOF_OUT_INIT_LOW,
+                                         "AK5386 Reset"))
+                       priv->reset_gpio = -EINVAL;
+
+       return snd_soc_register_codec(dev, &soc_codec_ak5386,
+                                     &ak5386_dai, 1);
+}
+
+static int ak5386_remove(struct platform_device *pdev)
+{
+       snd_soc_unregister_codec(&pdev->dev);
+       return 0;
+}
+
+static struct platform_driver ak5386_driver = {
+       .probe          = ak5386_probe,
+       .remove         = ak5386_remove,
+       .driver         = {
+               .name   = "ak5386",
+               .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(ak5386_dt_ids),
+       },
+};
+
+module_platform_driver(ak5386_driver);
+
+MODULE_DESCRIPTION("ASoC driver for AK5386 ADC");
+MODULE_AUTHOR("Daniel Mack <zonque@gmail.com>");
+MODULE_LICENSE("GPL");