1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/sound/soc/pxa/palm27x.c
4  *
5  * SoC Audio driver for Palm T|X, T5 and LifeDrive
6  *
7  * based on tosa.c
8  *
9  * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
10  */
11 
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/device.h>
15 #include <linux/gpio.h>
16 
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/soc.h>
20 #include <sound/jack.h>
21 
22 #include <asm/mach-types.h>
23 #include <linux/platform_data/asoc-pxa.h>
24 #include <linux/platform_data/asoc-palm27x.h>
25 
26 static struct snd_soc_jack hs_jack;
27 
28 /* Headphones jack detection DAPM pins */
29 static struct snd_soc_jack_pin hs_jack_pins[] = {
30 	{
31 		.pin    = "Headphone Jack",
32 		.mask   = SND_JACK_HEADPHONE,
33 	},
34 };
35 
36 /* Headphones jack detection gpios */
37 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
38 	[0] = {
39 		/* gpio is set on per-platform basis */
40 		.name           = "hp-gpio",
41 		.report         = SND_JACK_HEADPHONE,
42 		.debounce_time	= 200,
43 	},
44 };
45 
46 /* Palm27x machine dapm widgets */
47 static const struct snd_soc_dapm_widget palm27x_dapm_widgets[] = {
48 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
49 	SND_SOC_DAPM_SPK("Ext. Speaker", NULL),
50 	SND_SOC_DAPM_MIC("Ext. Microphone", NULL),
51 };
52 
53 /* PalmTX audio map */
54 static const struct snd_soc_dapm_route audio_map[] = {
55 	/* headphone connected to HPOUTL, HPOUTR */
56 	{"Headphone Jack", NULL, "HPOUTL"},
57 	{"Headphone Jack", NULL, "HPOUTR"},
58 
59 	/* ext speaker connected to ROUT2, LOUT2 */
60 	{"Ext. Speaker", NULL, "LOUT2"},
61 	{"Ext. Speaker", NULL, "ROUT2"},
62 
63 	/* mic connected to MIC1 */
64 	{"MIC1", NULL, "Ext. Microphone"},
65 };
66 
67 static struct snd_soc_card palm27x_asoc;
68 
palm27x_ac97_init(struct snd_soc_pcm_runtime * rtd)69 static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
70 {
71 	int err;
72 
73 	/* Jack detection API stuff */
74 	err = snd_soc_card_jack_new_pins(rtd->card, "Headphone Jack",
75 					 SND_JACK_HEADPHONE, &hs_jack,
76 					 hs_jack_pins,
77 					 ARRAY_SIZE(hs_jack_pins));
78 	if (err)
79 		return err;
80 
81 	err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
82 				hs_jack_gpios);
83 
84 	return err;
85 }
86 
87 SND_SOC_DAILINK_DEFS(hifi,
88 	DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
89 	DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
90 	DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
91 
92 SND_SOC_DAILINK_DEFS(aux,
93 	DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
94 	DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
95 	DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
96 
97 static struct snd_soc_dai_link palm27x_dai[] = {
98 {
99 	.name = "AC97 HiFi",
100 	.stream_name = "AC97 HiFi",
101 	.init = palm27x_ac97_init,
102 	SND_SOC_DAILINK_REG(hifi),
103 },
104 {
105 	.name = "AC97 Aux",
106 	.stream_name = "AC97 Aux",
107 	SND_SOC_DAILINK_REG(aux),
108 },
109 };
110 
111 static struct snd_soc_card palm27x_asoc = {
112 	.name = "Palm/PXA27x",
113 	.owner = THIS_MODULE,
114 	.dai_link = palm27x_dai,
115 	.num_links = ARRAY_SIZE(palm27x_dai),
116 	.dapm_widgets = palm27x_dapm_widgets,
117 	.num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
118 	.dapm_routes = audio_map,
119 	.num_dapm_routes = ARRAY_SIZE(audio_map),
120 	.fully_routed = true,
121 };
122 
palm27x_asoc_probe(struct platform_device * pdev)123 static int palm27x_asoc_probe(struct platform_device *pdev)
124 {
125 	int ret;
126 
127 	if (!(machine_is_palmtx() || machine_is_palmt5() ||
128 		machine_is_palmld() || machine_is_palmte2()))
129 		return -ENODEV;
130 
131 	if (!pdev->dev.platform_data) {
132 		dev_err(&pdev->dev, "please supply platform_data\n");
133 		return -ENODEV;
134 	}
135 
136 	hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
137 			(pdev->dev.platform_data))->jack_gpio;
138 
139 	palm27x_asoc.dev = &pdev->dev;
140 
141 	ret = devm_snd_soc_register_card(&pdev->dev, &palm27x_asoc);
142 	if (ret)
143 		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
144 			ret);
145 	return ret;
146 }
147 
148 static struct platform_driver palm27x_wm9712_driver = {
149 	.probe		= palm27x_asoc_probe,
150 	.driver		= {
151 		.name		= "palm27x-asoc",
152 		.pm     = &snd_soc_pm_ops,
153 	},
154 };
155 
156 module_platform_driver(palm27x_wm9712_driver);
157 
158 /* Module information */
159 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
160 MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
161 MODULE_LICENSE("GPL");
162 MODULE_ALIAS("platform:palm27x-asoc");
163