1 /*
2  * e750-wm9705.c  --  SoC audio for e750
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>
19 
20 #include <mach/audio.h>
21 #include <mach/eseries-gpio.h>
22 
23 #include <asm/mach-types.h>
24 
e750_spk_amp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)25 static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
26 				struct snd_kcontrol *kcontrol, int event)
27 {
28 	if (event & SND_SOC_DAPM_PRE_PMU)
29 		gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
30 	else if (event & SND_SOC_DAPM_POST_PMD)
31 		gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
32 
33 	return 0;
34 }
35 
e750_hp_amp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)36 static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
37 				struct snd_kcontrol *kcontrol, int event)
38 {
39 	if (event & SND_SOC_DAPM_PRE_PMU)
40 		gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
41 	else if (event & SND_SOC_DAPM_POST_PMD)
42 		gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
43 
44 	return 0;
45 }
46 
47 static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
48 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
49 	SND_SOC_DAPM_SPK("Speaker", NULL),
50 	SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
51 	SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
52 			e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
53 			SND_SOC_DAPM_POST_PMD),
54 	SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
55 			e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
56 			SND_SOC_DAPM_POST_PMD),
57 };
58 
59 static const struct snd_soc_dapm_route audio_map[] = {
60 	{"Headphone Amp", NULL, "HPOUTL"},
61 	{"Headphone Amp", NULL, "HPOUTR"},
62 	{"Headphone Jack", NULL, "Headphone Amp"},
63 
64 	{"Speaker Amp", NULL, "MONOOUT"},
65 	{"Speaker", NULL, "Speaker Amp"},
66 
67 	{"MIC1", NULL, "Mic (Internal)"},
68 };
69 
70 static struct snd_soc_dai_link e750_dai[] = {
71 	{
72 		.name = "AC97",
73 		.stream_name = "AC97 HiFi",
74 		.cpu_dai_name = "pxa2xx-ac97",
75 		.codec_dai_name = "wm9705-hifi",
76 		.platform_name = "pxa-pcm-audio",
77 		.codec_name = "wm9705-codec",
78 		/* use ops to check startup state */
79 	},
80 	{
81 		.name = "AC97 Aux",
82 		.stream_name = "AC97 Aux",
83 		.cpu_dai_name = "pxa2xx-ac97-aux",
84 		.codec_dai_name = "wm9705-aux",
85 		.platform_name = "pxa-pcm-audio",
86 		.codec_name = "wm9705-codec",
87 	},
88 };
89 
90 static struct snd_soc_card e750 = {
91 	.name = "Toshiba e750",
92 	.owner = THIS_MODULE,
93 	.dai_link = e750_dai,
94 	.num_links = ARRAY_SIZE(e750_dai),
95 
96 	.dapm_widgets = e750_dapm_widgets,
97 	.num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
98 	.dapm_routes = audio_map,
99 	.num_dapm_routes = ARRAY_SIZE(audio_map),
100 	.fully_routed = true,
101 };
102 
103 static struct gpio e750_audio_gpios[] = {
104 	{ GPIO_E750_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
105 	{ GPIO_E750_SPK_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
106 };
107 
e750_probe(struct platform_device * pdev)108 static int e750_probe(struct platform_device *pdev)
109 {
110 	struct snd_soc_card *card = &e750;
111 	int ret;
112 
113 	ret = gpio_request_array(e750_audio_gpios,
114 				 ARRAY_SIZE(e750_audio_gpios));
115 	if (ret)
116 		return ret;
117 
118 	card->dev = &pdev->dev;
119 
120 	ret = devm_snd_soc_register_card(&pdev->dev, card);
121 	if (ret) {
122 		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
123 			ret);
124 		gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
125 	}
126 	return ret;
127 }
128 
e750_remove(struct platform_device * pdev)129 static int e750_remove(struct platform_device *pdev)
130 {
131 	gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
132 	return 0;
133 }
134 
135 static struct platform_driver e750_driver = {
136 	.driver		= {
137 		.name	= "e750-audio",
138 		.pm     = &snd_soc_pm_ops,
139 	},
140 	.probe		= e750_probe,
141 	.remove		= e750_remove,
142 };
143 
144 module_platform_driver(e750_driver);
145 
146 /* Module information */
147 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
148 MODULE_DESCRIPTION("ALSA SoC driver for e750");
149 MODULE_LICENSE("GPL v2");
150 MODULE_ALIAS("platform:e750-audio");
151