blob: 56d543da938ae95b05d7027b71c8b3d535531ff2 [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001// SPDX-License-Identifier: GPL-2.0-only
Ian Moltonab40d4f2008-01-10 14:50:34 +01002/*
3 * e800-wm9712.c -- SoC audio for e800
4 *
Ian Moltonab40d4f2008-01-10 14:50:34 +01005 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
Ian Moltonab40d4f2008-01-10 14:50:34 +01006 */
7
8#include <linux/module.h>
9#include <linux/moduleparam.h>
Ian Molton0465c7a2009-01-08 21:16:05 +000010#include <linux/gpio.h>
Ian Moltonab40d4f2008-01-10 14:50:34 +010011
12#include <sound/core.h>
13#include <sound/pcm.h>
14#include <sound/soc.h>
Ian Moltonab40d4f2008-01-10 14:50:34 +010015
Mark Brownc91cf252009-01-23 11:23:32 +000016#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010017#include <mach/audio.h>
Ian Molton0465c7a2009-01-08 21:16:05 +000018#include <mach/eseries-gpio.h>
19
Ian Molton0465c7a2009-01-08 21:16:05 +000020static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
21 struct snd_kcontrol *kcontrol, int event)
22{
23 if (event & SND_SOC_DAPM_PRE_PMU)
24 gpio_set_value(GPIO_E800_SPK_AMP_ON, 1);
25 else if (event & SND_SOC_DAPM_POST_PMD)
26 gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
27
28 return 0;
29}
30
31static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *kcontrol, int event)
33{
34 if (event & SND_SOC_DAPM_PRE_PMU)
35 gpio_set_value(GPIO_E800_HP_AMP_OFF, 0);
36 else if (event & SND_SOC_DAPM_POST_PMD)
37 gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
38
39 return 0;
40}
41
42static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphone Jack", NULL),
44 SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
45 SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
46 SND_SOC_DAPM_SPK("Speaker", NULL),
47 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
48 e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
49 SND_SOC_DAPM_POST_PMD),
50 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
51 e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
52 SND_SOC_DAPM_POST_PMD),
53};
54
55static const struct snd_soc_dapm_route audio_map[] = {
56 {"Headphone Jack", NULL, "HPOUTL"},
57 {"Headphone Jack", NULL, "HPOUTR"},
58 {"Headphone Jack", NULL, "Headphone Amp"},
59
60 {"Speaker Amp", NULL, "MONOOUT"},
61 {"Speaker", NULL, "Speaker Amp"},
62
63 {"MIC1", NULL, "Mic (Internal1)"},
64 {"MIC2", NULL, "Mic (Internal2)"},
65};
66
Kuninori Morimoto32b787a2019-06-06 13:11:12 +090067
68SND_SOC_DAILINK_DEFS(ac97,
69 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
70 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
71 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
72
73SND_SOC_DAILINK_DEFS(ac97_aux,
74 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
75 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
76 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
77
Ian Moltonab40d4f2008-01-10 14:50:34 +010078static struct snd_soc_dai_link e800_dai[] = {
Ian Molton0465c7a2009-01-08 21:16:05 +000079 {
80 .name = "AC97",
81 .stream_name = "AC97 HiFi",
Kuninori Morimoto32b787a2019-06-06 13:11:12 +090082 SND_SOC_DAILINK_REG(ac97),
Ian Molton0465c7a2009-01-08 21:16:05 +000083 },
84 {
85 .name = "AC97 Aux",
86 .stream_name = "AC97 Aux",
Kuninori Morimoto32b787a2019-06-06 13:11:12 +090087 SND_SOC_DAILINK_REG(ac97_aux),
Ian Molton0465c7a2009-01-08 21:16:05 +000088 },
Ian Moltonab40d4f2008-01-10 14:50:34 +010089};
90
Mark Brown87506542008-11-18 20:50:34 +000091static struct snd_soc_card e800 = {
Ian Moltonab40d4f2008-01-10 14:50:34 +010092 .name = "Toshiba e800",
Axel Lin561c6a12011-12-22 09:44:43 +080093 .owner = THIS_MODULE,
Ian Moltonab40d4f2008-01-10 14:50:34 +010094 .dai_link = e800_dai,
95 .num_links = ARRAY_SIZE(e800_dai),
Lars-Peter Clausen1bdd3012014-03-01 15:48:16 +010096
97 .dapm_widgets = e800_dapm_widgets,
98 .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
99 .dapm_routes = audio_map,
100 .num_dapm_routes = ARRAY_SIZE(audio_map),
Ian Moltonab40d4f2008-01-10 14:50:34 +0100101};
102
Axel Lin1eb02022011-12-15 10:54:25 +0800103static struct gpio e800_audio_gpios[] = {
104 { GPIO_E800_SPK_AMP_ON, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
105 { GPIO_E800_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
106};
Ian Moltonab40d4f2008-01-10 14:50:34 +0100107
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500108static int e800_probe(struct platform_device *pdev)
Ian Moltonab40d4f2008-01-10 14:50:34 +0100109{
Axel Lin1eb02022011-12-15 10:54:25 +0800110 struct snd_soc_card *card = &e800;
Ian Moltonab40d4f2008-01-10 14:50:34 +0100111 int ret;
112
Axel Lin1eb02022011-12-15 10:54:25 +0800113 ret = gpio_request_array(e800_audio_gpios,
114 ARRAY_SIZE(e800_audio_gpios));
Ian Molton0465c7a2009-01-08 21:16:05 +0000115 if (ret)
116 return ret;
117
Axel Lin1eb02022011-12-15 10:54:25 +0800118 card->dev = &pdev->dev;
Ian Molton0465c7a2009-01-08 21:16:05 +0000119
Axel Lin2fd70762015-09-01 10:32:59 +0800120 ret = devm_snd_soc_register_card(&pdev->dev, card);
Axel Lin1eb02022011-12-15 10:54:25 +0800121 if (ret) {
122 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
123 ret);
124 gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
Axel Lin8faab9412011-12-07 10:01:30 +0800125 }
Ian Moltonab40d4f2008-01-10 14:50:34 +0100126 return ret;
127}
128
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500129static int e800_remove(struct platform_device *pdev)
Ian Moltonab40d4f2008-01-10 14:50:34 +0100130{
Axel Lin1eb02022011-12-15 10:54:25 +0800131 gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
Axel Lin1eb02022011-12-15 10:54:25 +0800132 return 0;
Ian Moltonab40d4f2008-01-10 14:50:34 +0100133}
134
Axel Lin1eb02022011-12-15 10:54:25 +0800135static struct platform_driver e800_driver = {
136 .driver = {
137 .name = "e800-audio",
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +0400138 .pm = &snd_soc_pm_ops,
Axel Lin1eb02022011-12-15 10:54:25 +0800139 },
140 .probe = e800_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500141 .remove = e800_remove,
Axel Lin1eb02022011-12-15 10:54:25 +0800142};
143
144module_platform_driver(e800_driver);
Ian Moltonab40d4f2008-01-10 14:50:34 +0100145
146/* Module information */
147MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
148MODULE_DESCRIPTION("ALSA SoC driver for e800");
Ian Molton0465c7a2009-01-08 21:16:05 +0000149MODULE_LICENSE("GPL v2");
Axel Lin1eb02022011-12-15 10:54:25 +0800150MODULE_ALIAS("platform:e800-audio");