blob: c29fedab2f49abb225a67c07e2e8659826aec7a1 [file] [log] [blame]
Ian Molton28796ea2009-01-17 15:11:06 +00001/*
2 * e740-wm9705.c -- SoC audio for e740
3 *
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 ONLY.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/gpio.h>
15
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
Ian Molton28796ea2009-01-17 15:11:06 +000019
Ian Molton28796ea2009-01-17 15:11:06 +000020#include <mach/audio.h>
21#include <mach/eseries-gpio.h>
22
23#include <asm/mach-types.h>
24
25#include "../codecs/wm9705.h"
Ian Molton28796ea2009-01-17 15:11:06 +000026#include "pxa2xx-ac97.h"
27
28
29#define E740_AUDIO_OUT 1
30#define E740_AUDIO_IN 2
31
32static int e740_audio_power;
33
34static void e740_sync_audio_power(int status)
35{
36 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
37 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
38 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
39}
40
41static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
42 struct snd_kcontrol *kcontrol, int event)
43{
44 if (event & SND_SOC_DAPM_PRE_PMU)
45 e740_audio_power |= E740_AUDIO_IN;
46 else if (event & SND_SOC_DAPM_POST_PMD)
47 e740_audio_power &= ~E740_AUDIO_IN;
48
49 e740_sync_audio_power(e740_audio_power);
50
51 return 0;
52}
53
54static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
55 struct snd_kcontrol *kcontrol, int event)
56{
57 if (event & SND_SOC_DAPM_PRE_PMU)
58 e740_audio_power |= E740_AUDIO_OUT;
59 else if (event & SND_SOC_DAPM_POST_PMD)
60 e740_audio_power &= ~E740_AUDIO_OUT;
61
62 e740_sync_audio_power(e740_audio_power);
63
64 return 0;
65}
66
67static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
68 SND_SOC_DAPM_HP("Headphone Jack", NULL),
69 SND_SOC_DAPM_SPK("Speaker", NULL),
70 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
71 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
72 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
73 SND_SOC_DAPM_POST_PMD),
74 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
75 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
76 SND_SOC_DAPM_POST_PMD),
77};
78
79static const struct snd_soc_dapm_route audio_map[] = {
80 {"Output Amp", NULL, "LOUT"},
81 {"Output Amp", NULL, "ROUT"},
82 {"Output Amp", NULL, "MONOOUT"},
83
84 {"Speaker", NULL, "Output Amp"},
85 {"Headphone Jack", NULL, "Output Amp"},
86
87 {"MIC1", NULL, "Mic Amp"},
88 {"Mic Amp", NULL, "Mic (Internal)"},
89};
90
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000091static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
Ian Molton28796ea2009-01-17 15:11:06 +000092{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000093 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020094 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095
Liam Girdwoodce6120c2010-11-05 15:53:46 +020096 snd_soc_dapm_nc_pin(dapm, "HPOUTL");
97 snd_soc_dapm_nc_pin(dapm, "HPOUTR");
98 snd_soc_dapm_nc_pin(dapm, "PHONE");
99 snd_soc_dapm_nc_pin(dapm, "LINEINL");
100 snd_soc_dapm_nc_pin(dapm, "LINEINR");
101 snd_soc_dapm_nc_pin(dapm, "CDINL");
102 snd_soc_dapm_nc_pin(dapm, "CDINR");
103 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
104 snd_soc_dapm_nc_pin(dapm, "MIC2");
Ian Molton28796ea2009-01-17 15:11:06 +0000105
Ian Molton28796ea2009-01-17 15:11:06 +0000106 return 0;
107}
108
109static struct snd_soc_dai_link e740_dai[] = {
110 {
111 .name = "AC97",
112 .stream_name = "AC97 HiFi",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300113 .cpu_dai_name = "pxa2xx-ac97",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000114 .codec_dai_name = "wm9705-hifi",
115 .platform_name = "pxa-pcm-audio",
116 .codec_name = "wm9705-codec",
Ian Molton28796ea2009-01-17 15:11:06 +0000117 .init = e740_ac97_init,
118 },
119 {
120 .name = "AC97 Aux",
121 .stream_name = "AC97 Aux",
Dmitry Eremin-Solenikov4bfc4e22011-02-23 02:29:11 +0300122 .cpu_dai_name = "pxa2xx-ac97-aux",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000123 .codec_dai_name = "wm9705-aux",
124 .platform_name = "pxa-pcm-audio",
125 .codec_name = "wm9705-codec",
Ian Molton28796ea2009-01-17 15:11:06 +0000126 },
127};
128
129static struct snd_soc_card e740 = {
130 .name = "Toshiba e740",
Axel Lin561c6a12011-12-22 09:44:43 +0800131 .owner = THIS_MODULE,
Ian Molton28796ea2009-01-17 15:11:06 +0000132 .dai_link = e740_dai,
133 .num_links = ARRAY_SIZE(e740_dai),
Lars-Peter Clausen23d8f222014-03-01 15:48:14 +0100134
135 .dapm_widgets = e740_dapm_widgets,
136 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
137 .dapm_routes = audio_map,
138 .num_dapm_routes = ARRAY_SIZE(audio_map),
Ian Molton28796ea2009-01-17 15:11:06 +0000139};
140
Axel Lin62133822011-12-15 10:52:42 +0800141static struct gpio e740_audio_gpios[] = {
142 { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" },
143 { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" },
144 { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" },
145};
Ian Molton28796ea2009-01-17 15:11:06 +0000146
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500147static int e740_probe(struct platform_device *pdev)
Ian Molton28796ea2009-01-17 15:11:06 +0000148{
Axel Lin62133822011-12-15 10:52:42 +0800149 struct snd_soc_card *card = &e740;
Ian Molton28796ea2009-01-17 15:11:06 +0000150 int ret;
151
Axel Lin62133822011-12-15 10:52:42 +0800152 ret = gpio_request_array(e740_audio_gpios,
153 ARRAY_SIZE(e740_audio_gpios));
Ian Molton28796ea2009-01-17 15:11:06 +0000154 if (ret)
155 return ret;
156
Axel Lin62133822011-12-15 10:52:42 +0800157 card->dev = &pdev->dev;
Ian Molton28796ea2009-01-17 15:11:06 +0000158
Axel Lin62133822011-12-15 10:52:42 +0800159 ret = snd_soc_register_card(card);
160 if (ret) {
161 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
162 ret);
163 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
Ian Molton28796ea2009-01-17 15:11:06 +0000164 }
Ian Molton28796ea2009-01-17 15:11:06 +0000165 return ret;
166}
167
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500168static int e740_remove(struct platform_device *pdev)
Ian Molton28796ea2009-01-17 15:11:06 +0000169{
Axel Lin62133822011-12-15 10:52:42 +0800170 struct snd_soc_card *card = platform_get_drvdata(pdev);
171
172 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
173 snd_soc_unregister_card(card);
174 return 0;
Ian Molton28796ea2009-01-17 15:11:06 +0000175}
176
Axel Lin62133822011-12-15 10:52:42 +0800177static struct platform_driver e740_driver = {
178 .driver = {
179 .name = "e740-audio",
180 .owner = THIS_MODULE,
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +0400181 .pm = &snd_soc_pm_ops,
Axel Lin62133822011-12-15 10:52:42 +0800182 },
183 .probe = e740_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500184 .remove = e740_remove,
Axel Lin62133822011-12-15 10:52:42 +0800185};
186
187module_platform_driver(e740_driver);
Ian Molton28796ea2009-01-17 15:11:06 +0000188
189/* Module information */
190MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
191MODULE_DESCRIPTION("ALSA SoC driver for e740");
192MODULE_LICENSE("GPL v2");
Axel Lin62133822011-12-15 10:52:42 +0800193MODULE_ALIAS("platform:e740-audio");