1 /* Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * max98357a.c -- MAX98357A ALSA SoC Codec driver
15 #include <linux/acpi.h>
16 #include <linux/device.h>
17 #include <linux/err.h>
18 #include <linux/gpio.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/kernel.h>
21 #include <linux/mod_devicetable.h>
22 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dai.h>
28 #include <sound/soc-dapm.h>
30 static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
31 int cmd, struct snd_soc_dai *dai)
33 struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai);
39 case SNDRV_PCM_TRIGGER_START:
40 case SNDRV_PCM_TRIGGER_RESUME:
41 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
42 gpiod_set_value(sdmode, 1);
44 case SNDRV_PCM_TRIGGER_STOP:
45 case SNDRV_PCM_TRIGGER_SUSPEND:
46 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
47 gpiod_set_value(sdmode, 0);
54 static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
55 SND_SOC_DAPM_OUTPUT("Speaker"),
58 static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
59 {"Speaker", NULL, "HiFi Playback"},
62 static int max98357a_codec_probe(struct snd_soc_codec *codec)
64 struct gpio_desc *sdmode;
66 sdmode = devm_gpiod_get_optional(codec->dev, "sdmode", GPIOD_OUT_LOW);
68 return PTR_ERR(sdmode);
70 snd_soc_codec_set_drvdata(codec, sdmode);
75 static const struct snd_soc_codec_driver max98357a_codec_driver = {
76 .probe = max98357a_codec_probe,
78 .dapm_widgets = max98357a_dapm_widgets,
79 .num_dapm_widgets = ARRAY_SIZE(max98357a_dapm_widgets),
80 .dapm_routes = max98357a_dapm_routes,
81 .num_dapm_routes = ARRAY_SIZE(max98357a_dapm_routes),
85 static const struct snd_soc_dai_ops max98357a_dai_ops = {
86 .trigger = max98357a_daiops_trigger,
89 static struct snd_soc_dai_driver max98357a_dai_driver = {
92 .stream_name = "HiFi Playback",
93 .formats = SNDRV_PCM_FMTBIT_S16 |
94 SNDRV_PCM_FMTBIT_S24 |
96 .rates = SNDRV_PCM_RATE_8000 |
97 SNDRV_PCM_RATE_16000 |
98 SNDRV_PCM_RATE_48000 |
105 .ops = &max98357a_dai_ops,
108 static int max98357a_platform_probe(struct platform_device *pdev)
110 return snd_soc_register_codec(&pdev->dev, &max98357a_codec_driver,
111 &max98357a_dai_driver, 1);
114 static int max98357a_platform_remove(struct platform_device *pdev)
116 snd_soc_unregister_codec(&pdev->dev);
122 static const struct of_device_id max98357a_device_id[] = {
123 { .compatible = "maxim,max98357a" },
126 MODULE_DEVICE_TABLE(of, max98357a_device_id);
130 static const struct acpi_device_id max98357a_acpi_match[] = {
134 MODULE_DEVICE_TABLE(acpi, max98357a_acpi_match);
137 static struct platform_driver max98357a_platform_driver = {
140 .of_match_table = of_match_ptr(max98357a_device_id),
141 .acpi_match_table = ACPI_PTR(max98357a_acpi_match),
143 .probe = max98357a_platform_probe,
144 .remove = max98357a_platform_remove,
146 module_platform_driver(max98357a_platform_driver);
148 MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver");
149 MODULE_LICENSE("GPL v2");