1 From ae0077658c007643020b88e233150cf1eca6cea8 Mon Sep 17 00:00:00 2001
2 From: Peter Malkin <petermalkin@google.com>
3 Date: Mon, 27 Mar 2017 16:38:21 -0700
4 Subject: [PATCH 083/806] Driver support for Google voiceHAT soundcard.
6 ASoC: googlevoicehat-codec: Use correct device when grabbing GPIO
8 The fixup for the VoiceHAT in 4.18 incorrectly tried to find the
9 sdmode GPIO pin under the card device, not the codec device.
10 This failed, and therefore caused the device probe to fail.
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
14 ASoC: googlevoicehat-codec: Reformat for kernel coding standards
16 Fix all whitespace, indentation, and bracing errors.
18 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
20 ASoC: googlevoicehat-codec: Make driver function structure const
22 Make voicehat_component_driver a const structure.
24 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
26 ASoC: googlevoicehat-codec: Only convert from ms to jiffies once
28 Minor optimisation and allows to become checkpatch clean.
29 A msec value is read out of DT or from a define, and convert once to
30 jiffies, rather than every time that it is used.
32 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
34 sound/soc/bcm/googlevoicehat-codec.c | 214 +++++++++++++++++++++++++++
35 1 file changed, 214 insertions(+)
36 create mode 100644 sound/soc/bcm/googlevoicehat-codec.c
39 +++ b/sound/soc/bcm/googlevoicehat-codec.c
42 + * Driver for the Google voiceHAT audio codec for Raspberry Pi.
44 + * Author: Peter Malkin <petermalkin@google.com>
47 + * This program is free software; you can redistribute it and/or
48 + * modify it under the terms of the GNU General Public License
49 + * version 2 as published by the Free Software Foundation.
51 + * This program is distributed in the hope that it will be useful, but
52 + * WITHOUT ANY WARRANTY; without even the implied warranty of
53 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54 + * General Public License for more details.
57 +#include <linux/device.h>
58 +#include <linux/err.h>
59 +#include <linux/gpio.h>
60 +#include <linux/gpio/consumer.h>
61 +#include <linux/init.h>
62 +#include <linux/kernel.h>
63 +#include <linux/mod_devicetable.h>
64 +#include <linux/module.h>
65 +#include <linux/of.h>
66 +#include <linux/platform_device.h>
67 +#include <linux/version.h>
68 +#include <sound/pcm.h>
69 +#include <sound/soc.h>
70 +#include <sound/soc-dai.h>
71 +#include <sound/soc-dapm.h>
73 +#define ICS43432_RATE_MIN_HZ 7190 /* from data sheet */
74 +#define ICS43432_RATE_MAX_HZ 52800 /* from data sheet */
75 +/* Delay in enabling SDMODE after clock settles to remove pop */
76 +#define SDMODE_DELAY_MS 5
78 +struct voicehat_priv {
79 + struct delayed_work enable_sdmode_work;
80 + struct gpio_desc *sdmode_gpio;
81 + unsigned long sdmode_delay_jiffies;
84 +static void voicehat_enable_sdmode_work(struct work_struct *work)
86 + struct voicehat_priv *voicehat = container_of(work,
87 + struct voicehat_priv,
88 + enable_sdmode_work.work);
89 + gpiod_set_value(voicehat->sdmode_gpio, 1);
92 +static int voicehat_component_probe(struct snd_soc_component *component)
94 + struct voicehat_priv *voicehat =
95 + snd_soc_component_get_drvdata(component);
97 + voicehat->sdmode_gpio = devm_gpiod_get(component->dev, "sdmode",
99 + if (IS_ERR(voicehat->sdmode_gpio)) {
100 + dev_err(component->dev, "Unable to allocate GPIO pin\n");
101 + return PTR_ERR(voicehat->sdmode_gpio);
104 + INIT_DELAYED_WORK(&voicehat->enable_sdmode_work,
105 + voicehat_enable_sdmode_work);
109 +static void voicehat_component_remove(struct snd_soc_component *component)
111 + struct voicehat_priv *voicehat =
112 + snd_soc_component_get_drvdata(component);
114 + cancel_delayed_work_sync(&voicehat->enable_sdmode_work);
117 +static const struct snd_soc_dapm_widget voicehat_dapm_widgets[] = {
118 + SND_SOC_DAPM_OUTPUT("Speaker"),
121 +static const struct snd_soc_dapm_route voicehat_dapm_routes[] = {
122 + {"Speaker", NULL, "HiFi Playback"},
125 +static const struct snd_soc_component_driver voicehat_component_driver = {
126 + .probe = voicehat_component_probe,
127 + .remove = voicehat_component_remove,
128 + .dapm_widgets = voicehat_dapm_widgets,
129 + .num_dapm_widgets = ARRAY_SIZE(voicehat_dapm_widgets),
130 + .dapm_routes = voicehat_dapm_routes,
131 + .num_dapm_routes = ARRAY_SIZE(voicehat_dapm_routes),
134 +static int voicehat_daiops_trigger(struct snd_pcm_substream *substream, int cmd,
135 + struct snd_soc_dai *dai)
137 + struct snd_soc_component *component = dai->component;
138 + struct voicehat_priv *voicehat =
139 + snd_soc_component_get_drvdata(component);
141 + if (voicehat->sdmode_delay_jiffies == 0)
144 + dev_dbg(dai->dev, "CMD %d", cmd);
145 + dev_dbg(dai->dev, "Playback Active %d", dai->playback_active);
146 + dev_dbg(dai->dev, "Capture Active %d", dai->capture_active);
149 + case SNDRV_PCM_TRIGGER_START:
150 + case SNDRV_PCM_TRIGGER_RESUME:
151 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
152 + if (dai->playback_active) {
153 + dev_info(dai->dev, "Enabling audio amp...\n");
154 + queue_delayed_work(
155 + system_power_efficient_wq,
156 + &voicehat->enable_sdmode_work,
157 + voicehat->sdmode_delay_jiffies);
160 + case SNDRV_PCM_TRIGGER_STOP:
161 + case SNDRV_PCM_TRIGGER_SUSPEND:
162 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
163 + if (dai->playback_active) {
164 + cancel_delayed_work(&voicehat->enable_sdmode_work);
165 + dev_info(dai->dev, "Disabling audio amp...\n");
166 + gpiod_set_value(voicehat->sdmode_gpio, 0);
173 +static const struct snd_soc_dai_ops voicehat_dai_ops = {
174 + .trigger = voicehat_daiops_trigger,
177 +static struct snd_soc_dai_driver voicehat_dai = {
178 + .name = "voicehat-hifi",
180 + .stream_name = "HiFi Capture",
183 + .rates = SNDRV_PCM_RATE_48000,
184 + .formats = SNDRV_PCM_FMTBIT_S32_LE
187 + .stream_name = "HiFi Playback",
190 + .rates = SNDRV_PCM_RATE_48000,
191 + .formats = SNDRV_PCM_FMTBIT_S32_LE
193 + .ops = &voicehat_dai_ops,
194 + .symmetric_rates = 1
198 +static const struct of_device_id voicehat_ids[] = {
199 + { .compatible = "google,voicehat", }, {}
201 + MODULE_DEVICE_TABLE(of, voicehat_ids);
204 +static int voicehat_platform_probe(struct platform_device *pdev)
206 + struct voicehat_priv *voicehat;
207 + unsigned int sdmode_delay;
210 + voicehat = devm_kzalloc(&pdev->dev, sizeof(*voicehat), GFP_KERNEL);
214 + ret = device_property_read_u32(&pdev->dev, "voicehat_sdmode_delay",
218 + sdmode_delay = SDMODE_DELAY_MS;
219 + dev_info(&pdev->dev,
220 + "property 'voicehat_sdmode_delay' not found default 5 mS");
222 + dev_info(&pdev->dev, "property 'voicehat_sdmode_delay' found delay= %d mS",
225 + voicehat->sdmode_delay_jiffies = msecs_to_jiffies(sdmode_delay);
227 + dev_set_drvdata(&pdev->dev, voicehat);
229 + return snd_soc_register_component(&pdev->dev,
230 + &voicehat_component_driver,
235 +static int voicehat_platform_remove(struct platform_device *pdev)
237 + snd_soc_unregister_component(&pdev->dev);
241 +static struct platform_driver voicehat_driver = {
243 + .name = "voicehat-codec",
244 + .of_match_table = of_match_ptr(voicehat_ids),
246 + .probe = voicehat_platform_probe,
247 + .remove = voicehat_platform_remove,
250 +module_platform_driver(voicehat_driver);
252 +MODULE_DESCRIPTION("Google voiceHAT Codec driver");
253 +MODULE_AUTHOR("Peter Malkin <petermalkin@google.com>");
254 +MODULE_LICENSE("GPL v2");