]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
Driver support for Google voiceHAT soundcard.
authorPeter Malkin <petermalkin@google.com>
Mon, 27 Mar 2017 23:38:21 +0000 (16:38 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 19 Sep 2017 10:07:57 +0000 (12:07 +0200)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
arch/arm/boot/dts/overlays/Makefile
arch/arm/boot/dts/overlays/README
arch/arm/boot/dts/overlays/googlevoicehat-soundcard-overlay.dts [new file with mode: 0644]
arch/arm/configs/bcm2709_defconfig
arch/arm/configs/bcmrpi_defconfig
sound/soc/bcm/Kconfig
sound/soc/bcm/Makefile
sound/soc/bcm/googlevoicehat-codec.c [new file with mode: 0644]
sound/soc/bcm/googlevoicehat-soundcard.c [new file with mode: 0644]

index 0f7340799fb465ba1fb5aaa1e970cbf6295d75c4..2f1cd17697606687fe47cb4e6a25a572611bf241 100644 (file)
@@ -23,6 +23,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
        enc28j60.dtbo \
        enc28j60-spi2.dtbo \
        fe-pi-audio.dtbo \
+       googlevoicehat-soundcard.dtbo \
        gpio-ir.dtbo \
        gpio-poweroff.dtbo \
        hifiberry-amp.dtbo \
index a8853b7820cd7a333cdaa2421f770a834dc724d5..6870e83a2e6acf842259a769d483b0b98c172279 100644 (file)
@@ -414,6 +414,12 @@ Load:   dtoverlay=fe-pi-audio
 Params: <None>
 
 
+Name:   googlevoicehat-soundcard
+Info:   Configures the Google voiceHAT soundcard
+Load:   dtoverlay=googlevoicehat-soundcard
+Params: <None>
+
+
 Name:   gpio-ir
 Info:   Use GPIO pin as rc-core style infrared receiver input. The rc-core-
         based gpio_ir_recv driver maps received keys directly to a
diff --git a/arch/arm/boot/dts/overlays/googlevoicehat-soundcard-overlay.dts b/arch/arm/boot/dts/overlays/googlevoicehat-soundcard-overlay.dts
new file mode 100644 (file)
index 0000000..9a9e9a0
--- /dev/null
@@ -0,0 +1,49 @@
+// Definitions for Google voiceHAT v1 soundcard overlay
+/dts-v1/;
+/plugin/;
+
+/ {
+       compatible = "brcm,bcm2708";
+
+       fragment@0 {
+               target = <&i2s>;
+               __overlay__ {
+                       status = "okay";
+               };
+       };
+
+       fragment@1 {
+               target = <&gpio>;
+               __overlay__ {
+                       googlevoicehat_pins: googlevoicehat_pins {
+                               brcm,pins = <16>;
+                               brcm,function = <1>; /* out */
+                               brcm,pull = <0>; /* up */
+                       };
+               };
+       };
+
+
+       fragment@2 {
+               target-path = "/";
+               __overlay__ {
+                       voicehat-codec {
+                               #sound-dai-cells = <0>;
+                               compatible = "google,voicehat";
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&googlevoicehat_pins>;
+                               sdmode-gpios= <&gpio 16 0>;
+                               status = "okay";
+                       };
+               };
+       };
+
+       fragment@3 {
+               target = <&sound>;
+               __overlay__ {
+                       compatible = "googlevoicehat,googlevoicehat-soundcard";
+                       i2s-controller = <&i2s>;
+                       status = "okay";
+               };
+       };
+};
index 8ce1707b537e9e21589887b93c0dbf9302cb5974..a58ef95ea4ef28946d51f717d96f9be63115de3f 100644 (file)
@@ -884,6 +884,7 @@ CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
 CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
+CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
 CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD=m
 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
index e65b2106d97ea9351c1d85166d2bff39d458ded3..cdf52529d8b5176303a60217eb28dc0b6f2f7184 100644 (file)
@@ -877,6 +877,7 @@ CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
 CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
+CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
 CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD=m
 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
index 706c500b5303ac3a0fd8687d23dc9f06c7d08388..cb9edcc96247e47855907da06b14a13695d408df 100644 (file)
@@ -18,6 +18,13 @@ config SND_SOC_CYGNUS
 
          If you don't know what to do here, say N.
 
+config SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD
+       tristate "Support for Google voiceHAT soundcard"
+       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
+       select SND_SOC_VOICEHAT
+       help
+          Say Y or M if you want to add support for voiceHAT soundcard.
+
 config SND_BCM2708_SOC_HIFIBERRY_DAC
         tristate "Support for HifiBerry DAC"
         depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
index d448aa517bf994fc0a41580c91b5d87deec9e1b0..e37457f01b263ba47ad884c7e945d33b001d9c66 100644 (file)
@@ -8,8 +8,12 @@ snd-soc-cygnus-objs := cygnus-pcm.o cygnus-ssp.o
 
 obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-cygnus.o
 
+# Google voiceHAT custom codec support
+snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
+
 # BCM2708 Machine Support
 snd-soc-adau1977-adc-objs := adau1977-adc.o
+snd-soc-googlevoicehat-soundcard-objs := googlevoicehat-soundcard.o
 snd-soc-hifiberry-amp-objs := hifiberry_amp.o
 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
@@ -32,6 +36,8 @@ snd-soc-pisound-objs := pisound.o
 snd-soc-fe-pi-audio-objs := fe-pi-audio.o
 
 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
+obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-soundcard.o
+obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD)  += snd-soc-googlevoicehat-codec.o
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
diff --git a/sound/soc/bcm/googlevoicehat-codec.c b/sound/soc/bcm/googlevoicehat-codec.c
new file mode 100644 (file)
index 0000000..7e31c9c
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Driver for the Google voiceHAT audio codec for Raspberry Pi.
+ *
+ * Author:     Peter Malkin <petermalkin@google.com>
+ *             Copyright 2016
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/version.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dai.h>
+#include <sound/soc-dapm.h>
+
+#define ICS43432_RATE_MIN_HZ 7190  /* from data sheet */
+#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
+#define SDMODE_DELAY_MS \
+  5 /* Delay in enabling SDMODE after clock settles to remove pop */
+
+struct voicehat_priv {
+  struct delayed_work enable_sdmode_work;
+  struct gpio_desc *sdmode_gpio;
+  unsigned int sdmode_delay;
+};
+
+static void voicehat_enable_sdmode_work(struct work_struct *work) {
+  struct voicehat_priv *voicehat =
+      container_of(work, struct voicehat_priv, enable_sdmode_work.work);
+  gpiod_set_value(voicehat->sdmode_gpio, 1);
+}
+
+static int voicehat_codec_probe(struct snd_soc_codec *codec) {
+  struct voicehat_priv *voicehat = snd_soc_codec_get_drvdata(codec);
+
+  voicehat->sdmode_gpio = devm_gpiod_get(codec->dev, "sdmode", GPIOD_OUT_LOW);
+  if (IS_ERR(voicehat->sdmode_gpio)) {
+    dev_err(codec->dev, "Unable to allocate GPIO pin\n");
+    return PTR_ERR(voicehat->sdmode_gpio);
+  }
+
+  INIT_DELAYED_WORK(&voicehat->enable_sdmode_work, voicehat_enable_sdmode_work);
+  return 0;
+}
+
+static int voicehat_codec_remove(struct snd_soc_codec *codec) {
+  struct voicehat_priv *voicehat = snd_soc_codec_get_drvdata(codec);
+
+  cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
+
+  return 0;
+}
+
+static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
+    SND_SOC_DAPM_OUTPUT("Speaker"),
+};
+
+static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
+    {"Speaker", NULL, "HiFi Playback"},
+};
+
+static struct snd_soc_codec_driver voicehat_codec_driver = {
+    .probe = voicehat_codec_probe,
+    .remove = voicehat_codec_remove,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+    .component_driver = {
+#endif
+    .dapm_widgets = voicehat_dapm_widgets,
+    .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
+    .dapm_routes = voicehat_dapm_routes,
+    .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+    },
+#endif
+};
+
+static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
+                                struct snd_soc_dai *dai) {
+  struct snd_soc_codec *codec = dai->codec;
+  struct voicehat_priv *voicehat = snd_soc_codec_get_drvdata(codec);
+
+  if (voicehat->sdmode_delay == 0) return 0;
+
+  dev_dbg(dai->dev, "CMD             %d", cmd);
+  dev_dbg(dai->dev, "Playback Active %d", dai->playback_active);
+  dev_dbg(dai->dev, "Capture Active  %d", dai->capture_active);
+
+  switch (cmd) {
+    case SNDRV_PCM_TRIGGER_START:
+    case SNDRV_PCM_TRIGGER_RESUME:
+    case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+      if (dai->playback_active) {
+        dev_info(dai->dev, "Enabling audio amp...\n");
+        queue_delayed_work(system_power_efficient_wq,
+                           &voicehat->enable_sdmode_work,
+                           msecs_to_jiffies(voicehat->sdmode_delay));
+      }
+      break;
+    case SNDRV_PCM_TRIGGER_STOP:
+    case SNDRV_PCM_TRIGGER_SUSPEND:
+    case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+      if (dai->playback_active) {
+        cancel_delayed_work(&voicehat->enable_sdmode_work);
+        dev_info(dai->dev, "Disabling audio amp...\n");
+        gpiod_set_value(voicehat->sdmode_gpio, 0);
+      }
+      break;
+  }
+  return 0;
+}
+
+static const struct snd_soc_dai_ops voicehat_dai_ops = {
+    .trigger = voicehat_daiops_trigger,
+};
+
+static struct snd_soc_dai_driver voicehat_dai = {
+    .name = "voicehat-hifi",
+    .capture = {.stream_name = "HiFi Capture",
+                .channels_min = 2,
+                .channels_max = 2,
+                .rates = SNDRV_PCM_RATE_48000,
+                .formats = SNDRV_PCM_FMTBIT_S32_LE},
+    .playback = {.stream_name = "HiFi Playback",
+                 .channels_min = 2,
+                 .channels_max = 2,
+                 .rates = SNDRV_PCM_RATE_48000,
+                 .formats = SNDRV_PCM_FMTBIT_S32_LE},
+    .ops = &voicehat_dai_ops,
+    .symmetric_rates = 1};
+
+#ifdef CONFIG_OF
+static const struct of_device_id voicehat_ids[] = {
+    {
+        .compatible = "google,voicehat",
+    },
+    {}};
+MODULE_DEVICE_TABLE(of, voicehat_ids);
+#endif
+
+static int voicehat_platform_probe(struct platform_device *pdev) {
+  struct voicehat_priv *voicehat;
+  int ret;
+
+  voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
+  if (!voicehat) return -ENOMEM;
+
+  ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
+                                 &voicehat->sdmode_delay);
+
+  if (ret) {
+    voicehat->sdmode_delay = SDMODE_DELAY_MS;
+    dev_info(&pdev->dev,
+             "property 'voicehat_sdmode_delay' not found default 5 mS");
+  } else {
+    dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
+             voicehat->sdmode_delay);
+  }
+
+  dev_set_drvdata(&pdev->dev, voicehat);
+
+  return snd_soc_register_codec(&pdev->dev, &voicehat_codec_driver, &voicehat_dai, 1);
+}
+
+static int voicehat_platform_remove(struct platform_device *pdev) {
+  snd_soc_unregister_codec(&pdev->dev);
+  return 0;
+}
+
+static struct platform_driver voicehat_driver = {
+    .driver =
+        {
+            .name = "voicehat-codec", .of_match_table = of_match_ptr(voicehat_ids),
+        },
+    .probe = voicehat_platform_probe,
+    .remove = voicehat_platform_remove,
+};
+
+module_platform_driver(voicehat_driver);
+
+MODULE_DESCRIPTION("Google voiceHAT Codec driver");
+MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/bcm/googlevoicehat-soundcard.c b/sound/soc/bcm/googlevoicehat-soundcard.c
new file mode 100644 (file)
index 0000000..225854b
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * ASoC Driver for Google voiceHAT SoundCard
+ *
+ * Author: Peter Malkin <petermalkin@google.com>
+ *         Copyright 2016
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/jack.h>
+
+static int snd_rpi_googlevoicehat_soundcard_init(struct snd_soc_pcm_runtime *rtd)
+{
+       return 0;
+}
+
+static int snd_rpi_googlevoicehat_soundcard_hw_params(
+       struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+
+       unsigned int sample_bits =
+               snd_pcm_format_physical_width(params_format(params));
+
+       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
+}
+
+/* machine stream operations */
+static struct snd_soc_ops snd_rpi_googlevoicehat_soundcard_ops = {
+       .hw_params = snd_rpi_googlevoicehat_soundcard_hw_params,
+};
+
+static struct snd_soc_dai_link snd_rpi_googlevoicehat_soundcard_dai[] = {
+{
+       .name           = "Google voiceHAT SoundCard",
+       .stream_name    = "Google voiceHAT SoundCard HiFi",
+       .cpu_dai_name   = "bcm2708-i2s.0",
+       .codec_dai_name = "voicehat-hifi",
+       .platform_name  = "bcm2708-i2s.0",
+       .codec_name     = "voicehat-codec",
+       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                               SND_SOC_DAIFMT_CBS_CFS,
+       .ops            = &snd_rpi_googlevoicehat_soundcard_ops,
+       .init           = snd_rpi_googlevoicehat_soundcard_init,
+},
+};
+
+/* audio machine driver */
+static struct snd_soc_card snd_rpi_googlevoicehat_soundcard = {
+       .name         = "snd_rpi_googlevoicehat_soundcard",
+       .owner        = THIS_MODULE,
+       .dai_link     = snd_rpi_googlevoicehat_soundcard_dai,
+       .num_links    = ARRAY_SIZE(snd_rpi_googlevoicehat_soundcard_dai),
+};
+
+static int snd_rpi_googlevoicehat_soundcard_probe(struct platform_device *pdev)
+{
+       int ret = 0;
+
+       snd_rpi_googlevoicehat_soundcard.dev = &pdev->dev;
+
+       if (pdev->dev.of_node) {
+               struct device_node *i2s_node;
+               struct snd_soc_dai_link *dai = &snd_rpi_googlevoicehat_soundcard_dai[0];
+               i2s_node = of_parse_phandle(pdev->dev.of_node,
+                                       "i2s-controller", 0);
+
+               if (i2s_node) {
+                       dai->cpu_dai_name = NULL;
+                       dai->cpu_of_node = i2s_node;
+                       dai->platform_name = NULL;
+                       dai->platform_of_node = i2s_node;
+               }
+       }
+
+       ret = snd_soc_register_card(&snd_rpi_googlevoicehat_soundcard);
+       if (ret)
+               dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
+
+       return ret;
+}
+
+static int snd_rpi_googlevoicehat_soundcard_remove(struct platform_device *pdev)
+{
+       return snd_soc_unregister_card(&snd_rpi_googlevoicehat_soundcard);
+}
+
+static const struct of_device_id snd_rpi_googlevoicehat_soundcard_of_match[] = {
+       { .compatible = "googlevoicehat,googlevoicehat-soundcard", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, snd_rpi_googlevoicehat_soundcard_of_match);
+
+static struct platform_driver snd_rpi_googlevoicehat_soundcard_driver = {
+       .driver = {
+               .name   = "snd-googlevoicehat-soundcard",
+               .owner  = THIS_MODULE,
+               .of_match_table = snd_rpi_googlevoicehat_soundcard_of_match,
+       },
+       .probe          = snd_rpi_googlevoicehat_soundcard_probe,
+       .remove         = snd_rpi_googlevoicehat_soundcard_remove,
+};
+
+module_platform_driver(snd_rpi_googlevoicehat_soundcard_driver);
+
+MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
+MODULE_DESCRIPTION("ASoC Driver for Google voiceHAT SoundCard");
+MODULE_LICENSE("GPL v2");