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/module.h>
16 #include <linux/gpio.h>
17 #include <sound/soc.h>
19 #define DRV_NAME "max98357a"
21 static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
22 int cmd, struct snd_soc_dai *dai)
24 struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai);
27 case SNDRV_PCM_TRIGGER_START:
28 case SNDRV_PCM_TRIGGER_RESUME:
29 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
30 gpiod_set_value(sdmode, 1);
32 case SNDRV_PCM_TRIGGER_STOP:
33 case SNDRV_PCM_TRIGGER_SUSPEND:
34 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
35 gpiod_set_value(sdmode, 0);
42 static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
43 SND_SOC_DAPM_DAC("SDMode", NULL, SND_SOC_NOPM, 0, 0),
44 SND_SOC_DAPM_OUTPUT("Speaker"),
47 static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
48 {"Speaker", NULL, "SDMode"},
51 static int max98357a_codec_probe(struct snd_soc_codec *codec)
53 struct gpio_desc *sdmode;
55 sdmode = devm_gpiod_get(codec->dev, "sdmode");
57 dev_err(codec->dev, "%s() unable to get sdmode GPIO: %ld\n",
58 __func__, PTR_ERR(sdmode));
59 return PTR_ERR(sdmode);
61 gpiod_direction_output(sdmode, 0);
62 snd_soc_codec_set_drvdata(codec, sdmode);
67 static struct snd_soc_codec_driver max98357a_codec_driver = {
68 .probe = max98357a_codec_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),
75 static struct snd_soc_dai_ops max98357a_dai_ops = {
76 .trigger = max98357a_daiops_trigger,
79 static struct snd_soc_dai_driver max98357a_dai_driver = {
82 .stream_name = DRV_NAME "-playback",
83 .formats = SNDRV_PCM_FMTBIT_S16 |
84 SNDRV_PCM_FMTBIT_S24 |
86 .rates = SNDRV_PCM_RATE_8000 |
87 SNDRV_PCM_RATE_16000 |
88 SNDRV_PCM_RATE_48000 |
95 .ops = &max98357a_dai_ops,
98 static int max98357a_platform_probe(struct platform_device *pdev)
102 ret = snd_soc_register_codec(&pdev->dev, &max98357a_codec_driver,
103 &max98357a_dai_driver, 1);
105 dev_err(&pdev->dev, "%s() error registering codec driver: %d\n",
111 static int max98357a_platform_remove(struct platform_device *pdev)
113 snd_soc_unregister_codec(&pdev->dev);
119 static const struct of_device_id max98357a_device_id[] = {
120 { .compatible = "maxim," DRV_NAME, },
123 MODULE_DEVICE_TABLE(of, max98357a_device_id);
126 static struct platform_driver max98357a_platform_driver = {
129 .of_match_table = of_match_ptr(max98357a_device_id),
131 .probe = max98357a_platform_probe,
132 .remove = max98357a_platform_remove,
134 module_platform_driver(max98357a_platform_driver);
136 MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver");
137 MODULE_LICENSE("GPL v2");
138 MODULE_ALIAS("platform:" DRV_NAME);