1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
4 * max98357a.c -- MAX98357A ALSA SoC Codec driver
7 #include <linux/acpi.h>
8 #include <linux/device.h>
10 #include <linux/gpio.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/kernel.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
19 #include <sound/soc-dai.h>
20 #include <sound/soc-dapm.h>
22 static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
23 int cmd, struct snd_soc_dai *dai)
25 struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai);
31 case SNDRV_PCM_TRIGGER_START:
32 case SNDRV_PCM_TRIGGER_RESUME:
33 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
34 gpiod_set_value(sdmode, 1);
36 case SNDRV_PCM_TRIGGER_STOP:
37 case SNDRV_PCM_TRIGGER_SUSPEND:
38 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
39 gpiod_set_value(sdmode, 0);
46 static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
47 SND_SOC_DAPM_OUTPUT("Speaker"),
50 static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
51 {"Speaker", NULL, "HiFi Playback"},
54 static int max98357a_component_probe(struct snd_soc_component *component)
56 struct gpio_desc *sdmode;
58 sdmode = devm_gpiod_get_optional(component->dev, "sdmode", GPIOD_OUT_LOW);
60 return PTR_ERR(sdmode);
62 snd_soc_component_set_drvdata(component, sdmode);
67 static const struct snd_soc_component_driver max98357a_component_driver = {
68 .probe = max98357a_component_probe,
69 .dapm_widgets = max98357a_dapm_widgets,
70 .num_dapm_widgets = ARRAY_SIZE(max98357a_dapm_widgets),
71 .dapm_routes = max98357a_dapm_routes,
72 .num_dapm_routes = ARRAY_SIZE(max98357a_dapm_routes),
76 .non_legacy_dai_naming = 1,
79 static const struct snd_soc_dai_ops max98357a_dai_ops = {
80 .trigger = max98357a_daiops_trigger,
83 static struct snd_soc_dai_driver max98357a_dai_driver = {
86 .stream_name = "HiFi Playback",
87 .formats = SNDRV_PCM_FMTBIT_S16 |
88 SNDRV_PCM_FMTBIT_S24 |
90 .rates = SNDRV_PCM_RATE_8000 |
91 SNDRV_PCM_RATE_16000 |
92 SNDRV_PCM_RATE_32000 |
93 SNDRV_PCM_RATE_44100 |
94 SNDRV_PCM_RATE_48000 |
95 SNDRV_PCM_RATE_88200 |
102 .ops = &max98357a_dai_ops,
105 static int max98357a_platform_probe(struct platform_device *pdev)
107 return devm_snd_soc_register_component(&pdev->dev,
108 &max98357a_component_driver,
109 &max98357a_dai_driver, 1);
112 static int max98357a_platform_remove(struct platform_device *pdev)
118 static const struct of_device_id max98357a_device_id[] = {
119 { .compatible = "maxim,max98357a" },
122 MODULE_DEVICE_TABLE(of, max98357a_device_id);
126 static const struct acpi_device_id max98357a_acpi_match[] = {
130 MODULE_DEVICE_TABLE(acpi, max98357a_acpi_match);
133 static struct platform_driver max98357a_platform_driver = {
136 .of_match_table = of_match_ptr(max98357a_device_id),
137 .acpi_match_table = ACPI_PTR(max98357a_acpi_match),
139 .probe = max98357a_platform_probe,
140 .remove = max98357a_platform_remove,
142 module_platform_driver(max98357a_platform_driver);
144 MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver");
145 MODULE_LICENSE("GPL v2");