forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/samsung/h1940_uda1380.c
....@@ -1,29 +1,20 @@
1
-/*
2
- * h1940-uda1380.c -- ALSA Soc Audio Layer
3
- *
4
- * Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5
- * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
6
- *
7
- * Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the
11
- * Free Software Foundation; either version 2 of the License, or (at your
12
- * option) any later version.
13
- *
14
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// h1940_uda1380.c - ALSA SoC Audio Layer
4
+//
5
+// Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
6
+// Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
7
+//
8
+// Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
159
1610 #include <linux/types.h>
17
-#include <linux/gpio.h>
11
+#include <linux/gpio/consumer.h>
1812 #include <linux/module.h>
1913
2014 #include <sound/soc.h>
2115 #include <sound/jack.h>
2216
2317 #include "regs-iis.h"
24
-#include <asm/mach-types.h>
25
-
26
-#include <mach/gpio-samsung.h>
2718 #include "s3c24xx-i2s.h"
2819
2920 static const unsigned int rates[] = {
....@@ -36,6 +27,8 @@
3627 .count = ARRAY_SIZE(rates),
3728 .list = rates,
3829 };
30
+
31
+static struct gpio_desc *gpiod_speaker_power;
3932
4033 static struct snd_soc_jack hp_jack;
4134
....@@ -53,7 +46,6 @@
5346
5447 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
5548 {
56
- .gpio = S3C2410_GPG(4),
5749 .name = "hp-gpio",
5850 .report = SND_JACK_HEADPHONE,
5951 .invert = 1,
....@@ -73,8 +65,8 @@
7365 static int h1940_hw_params(struct snd_pcm_substream *substream,
7466 struct snd_pcm_hw_params *params)
7567 {
76
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
77
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
68
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
69
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
7870 int div;
7971 int ret;
8072 unsigned int rate = params_rate(params);
....@@ -129,9 +121,9 @@
129121 struct snd_kcontrol *kcontrol, int event)
130122 {
131123 if (SND_SOC_DAPM_EVENT_ON(event))
132
- gpio_set_value(S3C_GPIO_END + 9, 1);
124
+ gpiod_set_value(gpiod_speaker_power, 1);
133125 else
134
- gpio_set_value(S3C_GPIO_END + 9, 0);
126
+ gpiod_set_value(gpiod_speaker_power, 0);
135127
136128 return 0;
137129 }
....@@ -157,8 +149,6 @@
157149 {"VINM", NULL, "Mic Jack"},
158150 };
159151
160
-static struct platform_device *s3c24xx_snd_device;
161
-
162152 static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
163153 {
164154 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
....@@ -171,18 +161,20 @@
171161 }
172162
173163 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
164
+SND_SOC_DAILINK_DEFS(uda1380,
165
+ DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
166
+ DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a", "uda1380-hifi")),
167
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
168
+
174169 static struct snd_soc_dai_link h1940_uda1380_dai[] = {
175170 {
176171 .name = "uda1380",
177172 .stream_name = "UDA1380 Duplex",
178
- .cpu_dai_name = "s3c24xx-iis",
179
- .codec_dai_name = "uda1380-hifi",
180173 .init = h1940_uda1380_init,
181
- .platform_name = "s3c24xx-iis",
182
- .codec_name = "uda1380-codec.0-001a",
183174 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
184175 SND_SOC_DAIFMT_CBS_CFS,
185176 .ops = &h1940_ops,
177
+ SND_SOC_DAILINK_REG(uda1380),
186178 },
187179 };
188180
....@@ -198,55 +190,34 @@
198190 .num_dapm_routes = ARRAY_SIZE(audio_map),
199191 };
200192
201
-static int __init h1940_init(void)
193
+static int h1940_probe(struct platform_device *pdev)
202194 {
203
- int ret;
195
+ struct device *dev = &pdev->dev;
204196
205
- if (!machine_is_h1940())
206
- return -ENODEV;
197
+ h1940_asoc.dev = dev;
198
+ hp_jack_gpios[0].gpiod_dev = dev;
199
+ gpiod_speaker_power = devm_gpiod_get(&pdev->dev, "speaker-power",
200
+ GPIOD_OUT_LOW);
207201
208
- /* configure some gpios */
209
- ret = gpio_request(S3C_GPIO_END + 9, "speaker-power");
210
- if (ret)
211
- goto err_out;
212
-
213
- ret = gpio_direction_output(S3C_GPIO_END + 9, 0);
214
- if (ret)
215
- goto err_gpio;
216
-
217
- s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
218
- if (!s3c24xx_snd_device) {
219
- ret = -ENOMEM;
220
- goto err_gpio;
202
+ if (IS_ERR(gpiod_speaker_power)) {
203
+ dev_err(dev, "Could not get gpio\n");
204
+ return PTR_ERR(gpiod_speaker_power);
221205 }
222206
223
- platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
224
- ret = platform_device_add(s3c24xx_snd_device);
225
-
226
- if (ret)
227
- goto err_plat;
228
-
229
- return 0;
230
-
231
-err_plat:
232
- platform_device_put(s3c24xx_snd_device);
233
-err_gpio:
234
- gpio_free(S3C_GPIO_END + 9);
235
-
236
-err_out:
237
- return ret;
207
+ return devm_snd_soc_register_card(dev, &h1940_asoc);
238208 }
239209
240
-static void __exit h1940_exit(void)
241
-{
242
- platform_device_unregister(s3c24xx_snd_device);
243
- gpio_free(S3C_GPIO_END + 9);
244
-}
245
-
246
-module_init(h1940_init);
247
-module_exit(h1940_exit);
210
+static struct platform_driver h1940_audio_driver = {
211
+ .driver = {
212
+ .name = "h1940-audio",
213
+ .pm = &snd_soc_pm_ops,
214
+ },
215
+ .probe = h1940_probe,
216
+};
217
+module_platform_driver(h1940_audio_driver);
248218
249219 /* Module information */
250220 MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
251221 MODULE_DESCRIPTION("ALSA SoC H1940");
252222 MODULE_LICENSE("GPL");
223
+MODULE_ALIAS("platform:h1940-audio");