forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/samsung/neo1973_wm8753.c
....@@ -1,38 +1,30 @@
1
-/*
2
- * neo1973_wm8753.c -- SoC audio for Openmoko Neo1973 and Freerunner devices
3
- *
4
- * Copyright 2007 Openmoko Inc
5
- * Author: Graeme Gregory <graeme@openmoko.org>
6
- * Copyright 2007 Wolfson Microelectronics PLC.
7
- * Author: Graeme Gregory
8
- * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
9
- * Copyright 2009 Wolfson Microelectronics
10
- *
11
- * This program is free software; you can redistribute it and/or modify it
12
- * under the terms of the GNU General Public License as published by the
13
- * Free Software Foundation; either version 2 of the License, or (at your
14
- * option) any later version.
15
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// neo1973_wm8753.c - SoC audio for Openmoko Neo1973 and Freerunner devices
4
+//
5
+// Copyright 2007 Openmoko Inc
6
+// Author: Graeme Gregory <graeme@openmoko.org>
7
+// Copyright 2007 Wolfson Microelectronics PLC.
8
+// Author: Graeme Gregory
9
+// graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
10
+// Copyright 2009 Wolfson Microelectronics
1611
1712 #include <linux/module.h>
1813 #include <linux/platform_device.h>
19
-#include <linux/gpio.h>
14
+#include <linux/gpio/consumer.h>
2015
2116 #include <sound/soc.h>
2217
23
-#include <mach/gpio-samsung.h>
24
-#include <asm/mach-types.h>
2518 #include "regs-iis.h"
26
-
2719 #include "../codecs/wm8753.h"
2820 #include "s3c24xx-i2s.h"
2921
3022 static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
3123 struct snd_pcm_hw_params *params)
3224 {
33
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
34
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
35
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
25
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
26
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
27
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
3628 unsigned int pll_out = 0, bclk = 0;
3729 int ret = 0;
3830 unsigned long iis_clkrate;
....@@ -104,8 +96,8 @@
10496
10597 static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
10698 {
107
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
108
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
99
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
100
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
109101
110102 /* disable the PLL */
111103 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
....@@ -122,8 +114,8 @@
122114 static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
123115 struct snd_pcm_hw_params *params)
124116 {
125
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
126
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
117
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
118
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
127119 unsigned int pcmdiv = 0;
128120 int ret = 0;
129121 unsigned long iis_clkrate;
....@@ -159,8 +151,8 @@
159151
160152 static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
161153 {
162
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
163
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
154
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
155
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
164156
165157 /* disable the PLL */
166158 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
....@@ -171,6 +163,7 @@
171163 .hw_free = neo1973_voice_hw_free,
172164 };
173165
166
+static struct gpio_desc *gpiod_hp_in, *gpiod_amp_shut;
174167 static int gta02_speaker_enabled;
175168
176169 static int lm4853_set_spk(struct snd_kcontrol *kcontrol,
....@@ -178,7 +171,7 @@
178171 {
179172 gta02_speaker_enabled = ucontrol->value.integer.value[0];
180173
181
- gpio_set_value(S3C2410_GPJ(2), !gta02_speaker_enabled);
174
+ gpiod_set_value(gpiod_hp_in, !gta02_speaker_enabled);
182175
183176 return 0;
184177 }
....@@ -193,7 +186,7 @@
193186 static int lm4853_event(struct snd_soc_dapm_widget *w,
194187 struct snd_kcontrol *k, int event)
195188 {
196
- gpio_set_value(S3C2410_GPJ(1), SND_SOC_DAPM_EVENT_OFF(event));
189
+ gpiod_set_value(gpiod_amp_shut, SND_SOC_DAPM_EVENT_OFF(event));
197190
198191 return 0;
199192 }
....@@ -271,52 +264,50 @@
271264 return 0;
272265 }
273266
267
+SND_SOC_DAILINK_DEFS(wm8753,
268
+ DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
269
+ DAILINK_COMP_ARRAY(COMP_CODEC("wm8753.0-001a", "wm8753-hifi")),
270
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
271
+
272
+SND_SOC_DAILINK_DEFS(bluetooth,
273
+ DAILINK_COMP_ARRAY(COMP_CPU("bt-sco-pcm")),
274
+ DAILINK_COMP_ARRAY(COMP_CODEC("wm8753.0-001a", "wm8753-voice")));
275
+
274276 static struct snd_soc_dai_link neo1973_dai[] = {
275277 { /* Hifi Playback - for similatious use with voice below */
276278 .name = "WM8753",
277279 .stream_name = "WM8753 HiFi",
278
- .platform_name = "s3c24xx-iis",
279
- .cpu_dai_name = "s3c24xx-iis",
280
- .codec_dai_name = "wm8753-hifi",
281
- .codec_name = "wm8753.0-001a",
282280 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
283281 SND_SOC_DAIFMT_CBM_CFM,
284282 .init = neo1973_wm8753_init,
285283 .ops = &neo1973_hifi_ops,
284
+ SND_SOC_DAILINK_REG(wm8753),
286285 },
287286 { /* Voice via BT */
288287 .name = "Bluetooth",
289288 .stream_name = "Voice",
290
- .cpu_dai_name = "bt-sco-pcm",
291
- .codec_dai_name = "wm8753-voice",
292
- .codec_name = "wm8753.0-001a",
293289 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
294290 SND_SOC_DAIFMT_CBS_CFS,
295291 .ops = &neo1973_voice_ops,
292
+ SND_SOC_DAILINK_REG(bluetooth),
296293 },
297294 };
298295
299296 static struct snd_soc_aux_dev neo1973_aux_devs[] = {
300297 {
301
- .name = "dfbmcs320",
302
- .codec_name = "dfbmcs320.0",
298
+ .dlc = COMP_AUX("dfbmcs320.0"),
303299 },
304300 };
305301
306302 static struct snd_soc_codec_conf neo1973_codec_conf[] = {
307303 {
308
- .dev_name = "lm4857.0-007c",
304
+ .dlc = COMP_CODEC_CONF("lm4857.0-007c"),
309305 .name_prefix = "Amp",
310306 },
311307 };
312308
313
-static const struct gpio neo1973_gta02_gpios[] = {
314
- { S3C2410_GPJ(2), GPIOF_OUT_INIT_HIGH, "GTA02_HP_IN" },
315
- { S3C2410_GPJ(1), GPIOF_OUT_INIT_HIGH, "GTA02_AMP_SHUT" },
316
-};
317
-
318309 static struct snd_soc_card neo1973 = {
319
- .name = "neo1973",
310
+ .name = "neo1973gta02",
320311 .owner = THIS_MODULE,
321312 .dai_link = neo1973_dai,
322313 .num_links = ARRAY_SIZE(neo1973_dai),
....@@ -334,62 +325,36 @@
334325 .fully_routed = true,
335326 };
336327
337
-static struct platform_device *neo1973_snd_device;
338
-
339
-static int __init neo1973_init(void)
328
+static int neo1973_probe(struct platform_device *pdev)
340329 {
341
- int ret;
330
+ struct device *dev = &pdev->dev;
342331
343
- if (!machine_is_neo1973_gta02())
344
- return -ENODEV;
345
-
346
- if (machine_is_neo1973_gta02()) {
347
- neo1973.name = "neo1973gta02";
348
- neo1973.num_aux_devs = 1;
349
-
350
- ret = gpio_request_array(neo1973_gta02_gpios,
351
- ARRAY_SIZE(neo1973_gta02_gpios));
352
- if (ret)
353
- return ret;
332
+ gpiod_hp_in = devm_gpiod_get(dev, "hp", GPIOD_OUT_HIGH);
333
+ if (IS_ERR(gpiod_hp_in)) {
334
+ dev_err(dev, "missing gpio %s\n", "hp");
335
+ return PTR_ERR(gpiod_hp_in);
336
+ }
337
+ gpiod_amp_shut = devm_gpiod_get(dev, "amp-shut", GPIOD_OUT_HIGH);
338
+ if (IS_ERR(gpiod_amp_shut)) {
339
+ dev_err(dev, "missing gpio %s\n", "amp-shut");
340
+ return PTR_ERR(gpiod_amp_shut);
354341 }
355342
356
- neo1973_snd_device = platform_device_alloc("soc-audio", -1);
357
- if (!neo1973_snd_device) {
358
- ret = -ENOMEM;
359
- goto err_gpio_free;
360
- }
361
-
362
- platform_set_drvdata(neo1973_snd_device, &neo1973);
363
- ret = platform_device_add(neo1973_snd_device);
364
-
365
- if (ret)
366
- goto err_put_device;
367
-
368
- return 0;
369
-
370
-err_put_device:
371
- platform_device_put(neo1973_snd_device);
372
-err_gpio_free:
373
- if (machine_is_neo1973_gta02()) {
374
- gpio_free_array(neo1973_gta02_gpios,
375
- ARRAY_SIZE(neo1973_gta02_gpios));
376
- }
377
- return ret;
343
+ neo1973.dev = dev;
344
+ return devm_snd_soc_register_card(dev, &neo1973);
378345 }
379
-module_init(neo1973_init);
380346
381
-static void __exit neo1973_exit(void)
382
-{
383
- platform_device_unregister(neo1973_snd_device);
384
-
385
- if (machine_is_neo1973_gta02()) {
386
- gpio_free_array(neo1973_gta02_gpios,
387
- ARRAY_SIZE(neo1973_gta02_gpios));
388
- }
389
-}
390
-module_exit(neo1973_exit);
347
+struct platform_driver neo1973_audio = {
348
+ .driver = {
349
+ .name = "neo1973-audio",
350
+ .pm = &snd_soc_pm_ops,
351
+ },
352
+ .probe = neo1973_probe,
353
+};
354
+module_platform_driver(neo1973_audio);
391355
392356 /* Module information */
393357 MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
394358 MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973 and Frerunner");
395359 MODULE_LICENSE("GPL");
360
+MODULE_ALIAS("platform:neo1973-audio");