hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/max98357a.c
....@@ -1,18 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
2
- *
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.
6
- *
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.
113 *
124 * max98357a.c -- MAX98357A ALSA SoC Codec driver
135 */
146
157 #include <linux/acpi.h>
8
+#include <linux/delay.h>
169 #include <linux/device.h>
1710 #include <linux/err.h>
1811 #include <linux/gpio.h>
....@@ -27,53 +20,72 @@
2720 #include <sound/soc-dai.h>
2821 #include <sound/soc-dapm.h>
2922
23
+struct max98357a_priv {
24
+ struct gpio_desc *sdmode;
25
+ unsigned int sdmode_delay;
26
+ int sdmode_switch;
27
+};
28
+
3029 static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
3130 int cmd, struct snd_soc_dai *dai)
3231 {
33
- struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai);
32
+ struct snd_soc_component *component = dai->component;
33
+ struct max98357a_priv *max98357a =
34
+ snd_soc_component_get_drvdata(component);
3435
35
- if (!sdmode)
36
+ if (!max98357a->sdmode)
3637 return 0;
3738
3839 switch (cmd) {
3940 case SNDRV_PCM_TRIGGER_START:
4041 case SNDRV_PCM_TRIGGER_RESUME:
4142 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
42
- gpiod_set_value(sdmode, 1);
43
+ mdelay(max98357a->sdmode_delay);
44
+ if (max98357a->sdmode_switch) {
45
+ gpiod_set_value(max98357a->sdmode, 1);
46
+ dev_dbg(component->dev, "set sdmode to 1");
47
+ }
4348 break;
4449 case SNDRV_PCM_TRIGGER_STOP:
4550 case SNDRV_PCM_TRIGGER_SUSPEND:
4651 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
47
- gpiod_set_value(sdmode, 0);
52
+ gpiod_set_value(max98357a->sdmode, 0);
53
+ dev_dbg(component->dev, "set sdmode to 0");
4854 break;
4955 }
5056
5157 return 0;
5258 }
5359
54
-static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
55
- SND_SOC_DAPM_OUTPUT("Speaker"),
56
-};
57
-
58
-static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
59
- {"Speaker", NULL, "HiFi Playback"},
60
-};
61
-
62
-static int max98357a_component_probe(struct snd_soc_component *component)
60
+static int max98357a_sdmode_event(struct snd_soc_dapm_widget *w,
61
+ struct snd_kcontrol *kcontrol, int event)
6362 {
64
- struct gpio_desc *sdmode;
63
+ struct snd_soc_component *component =
64
+ snd_soc_dapm_to_component(w->dapm);
65
+ struct max98357a_priv *max98357a =
66
+ snd_soc_component_get_drvdata(component);
6567
66
- sdmode = devm_gpiod_get_optional(component->dev, "sdmode", GPIOD_OUT_LOW);
67
- if (IS_ERR(sdmode))
68
- return PTR_ERR(sdmode);
69
-
70
- snd_soc_component_set_drvdata(component, sdmode);
68
+ if (event & SND_SOC_DAPM_POST_PMU)
69
+ max98357a->sdmode_switch = 1;
70
+ else if (event & SND_SOC_DAPM_POST_PMD)
71
+ max98357a->sdmode_switch = 0;
7172
7273 return 0;
7374 }
7475
76
+static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
77
+ SND_SOC_DAPM_OUTPUT("Speaker"),
78
+ SND_SOC_DAPM_OUT_DRV_E("SD_MODE", SND_SOC_NOPM, 0, 0, NULL, 0,
79
+ max98357a_sdmode_event,
80
+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
81
+};
82
+
83
+static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
84
+ {"SD_MODE", NULL, "HiFi Playback"},
85
+ {"Speaker", NULL, "SD_MODE"},
86
+};
87
+
7588 static const struct snd_soc_component_driver max98357a_component_driver = {
76
- .probe = max98357a_component_probe,
7789 .dapm_widgets = max98357a_dapm_widgets,
7890 .num_dapm_widgets = ARRAY_SIZE(max98357a_dapm_widgets),
7991 .dapm_routes = max98357a_dapm_routes,
....@@ -85,7 +97,7 @@
8597 };
8698
8799 static const struct snd_soc_dai_ops max98357a_dai_ops = {
88
- .trigger = max98357a_daiops_trigger,
100
+ .trigger = max98357a_daiops_trigger,
89101 };
90102
91103 static struct snd_soc_dai_driver max98357a_dai_driver = {
....@@ -97,7 +109,10 @@
97109 SNDRV_PCM_FMTBIT_S32,
98110 .rates = SNDRV_PCM_RATE_8000 |
99111 SNDRV_PCM_RATE_16000 |
112
+ SNDRV_PCM_RATE_32000 |
113
+ SNDRV_PCM_RATE_44100 |
100114 SNDRV_PCM_RATE_48000 |
115
+ SNDRV_PCM_RATE_88200 |
101116 SNDRV_PCM_RATE_96000,
102117 .rate_min = 8000,
103118 .rate_max = 96000,
....@@ -109,19 +124,38 @@
109124
110125 static int max98357a_platform_probe(struct platform_device *pdev)
111126 {
127
+ struct max98357a_priv *max98357a;
128
+ int ret;
129
+
130
+ max98357a = devm_kzalloc(&pdev->dev, sizeof(*max98357a), GFP_KERNEL);
131
+ if (!max98357a)
132
+ return -ENOMEM;
133
+
134
+ max98357a->sdmode = devm_gpiod_get_optional(&pdev->dev,
135
+ "sdmode", GPIOD_OUT_LOW);
136
+ if (IS_ERR(max98357a->sdmode))
137
+ return PTR_ERR(max98357a->sdmode);
138
+
139
+ ret = device_property_read_u32(&pdev->dev, "sdmode-delay",
140
+ &max98357a->sdmode_delay);
141
+ if (ret) {
142
+ max98357a->sdmode_delay = 0;
143
+ dev_dbg(&pdev->dev,
144
+ "no optional property 'sdmode-delay' found, "
145
+ "default: no delay\n");
146
+ }
147
+
148
+ dev_set_drvdata(&pdev->dev, max98357a);
149
+
112150 return devm_snd_soc_register_component(&pdev->dev,
113151 &max98357a_component_driver,
114152 &max98357a_dai_driver, 1);
115153 }
116154
117
-static int max98357a_platform_remove(struct platform_device *pdev)
118
-{
119
- return 0;
120
-}
121
-
122155 #ifdef CONFIG_OF
123156 static const struct of_device_id max98357a_device_id[] = {
124157 { .compatible = "maxim,max98357a" },
158
+ { .compatible = "maxim,max98360a" },
125159 {}
126160 };
127161 MODULE_DEVICE_TABLE(of, max98357a_device_id);
....@@ -130,6 +164,7 @@
130164 #ifdef CONFIG_ACPI
131165 static const struct acpi_device_id max98357a_acpi_match[] = {
132166 { "MX98357A", 0 },
167
+ { "MX98360A", 0 },
133168 {},
134169 };
135170 MODULE_DEVICE_TABLE(acpi, max98357a_acpi_match);
....@@ -142,7 +177,6 @@
142177 .acpi_match_table = ACPI_PTR(max98357a_acpi_match),
143178 },
144179 .probe = max98357a_platform_probe,
145
- .remove = max98357a_platform_remove,
146180 };
147181 module_platform_driver(max98357a_platform_driver);
148182