blob: 54949242bc7075587e6a73a7235049db2e108734 [file] [log] [blame]
Jarkko Nikula49100c92010-05-05 11:14:22 +03001/*
2 * rx51.c -- SoC audio for Nokia RX-51
3 *
4 * Copyright (C) 2008 - 2009 Nokia Corporation
5 *
Peter Ujfalusi0ac3a012011-05-03 18:15:10 +03006 * Contact: Peter Ujfalusi <peter.ujfalusi@ti.com>
Jarkko Nikula49100c92010-05-05 11:14:22 +03007 * Eduardo Valentin <eduardo.valentin@nokia.com>
Jarkko Nikula7ec41ee2011-08-11 15:44:57 +03008 * Jarkko Nikula <jarkko.nikula@bitmer.com>
Jarkko Nikula49100c92010-05-05 11:14:22 +03009 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/delay.h>
27#include <linux/gpio.h>
28#include <linux/platform_device.h>
Sebastian Reichel386e81a2014-04-28 16:07:24 +020029#include <linux/gpio/consumer.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Jarkko Nikula49100c92010-05-05 11:14:22 +030031#include <sound/core.h>
Jarkko Nikula8c523112010-06-21 14:15:00 +030032#include <sound/jack.h>
Jarkko Nikula49100c92010-05-05 11:14:22 +030033#include <sound/pcm.h>
34#include <sound/soc.h>
Arnd Bergmann22037472012-08-24 15:21:06 +020035#include <linux/platform_data/asoc-ti-mcbsp.h>
Jarkko Nikula48529b32011-01-27 16:47:11 +020036#include "../codecs/tpa6130a2.h"
Jarkko Nikula49100c92010-05-05 11:14:22 +030037
38#include <asm/mach-types.h>
39
40#include "omap-mcbsp.h"
Jarkko Nikula49100c92010-05-05 11:14:22 +030041
Jarkko Nikula4eb54702010-06-21 14:14:59 +030042enum {
43 RX51_JACK_DISABLED,
Jarkko Nikula48529b32011-01-27 16:47:11 +020044 RX51_JACK_TVOUT, /* tv-out with stereo output */
45 RX51_JACK_HP, /* headphone: stereo output, no mic */
Jarkko Nikula31164c72011-02-14 17:20:21 +020046 RX51_JACK_HS, /* headset: stereo output with mic */
Jarkko Nikula4eb54702010-06-21 14:14:59 +030047};
48
Sebastian Reichel386e81a2014-04-28 16:07:24 +020049struct rx51_audio_pdata {
50 struct gpio_desc *tvout_selection_gpio;
51 struct gpio_desc *jack_detection_gpio;
52 struct gpio_desc *eci_sw_gpio;
53 struct gpio_desc *speaker_amp_gpio;
54};
55
Jarkko Nikula49100c92010-05-05 11:14:22 +030056static int rx51_spk_func;
57static int rx51_dmic_func;
Jarkko Nikula4eb54702010-06-21 14:14:59 +030058static int rx51_jack_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +030059
Liam Girdwood022658b2012-02-03 17:43:09 +000060static void rx51_ext_control(struct snd_soc_dapm_context *dapm)
Jarkko Nikula49100c92010-05-05 11:14:22 +030061{
Sebastian Reichel386e81a2014-04-28 16:07:24 +020062 struct snd_soc_card *card = dapm->card;
63 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
Jarkko Nikula31164c72011-02-14 17:20:21 +020064 int hp = 0, hs = 0, tvout = 0;
Jarkko Nikula48529b32011-01-27 16:47:11 +020065
66 switch (rx51_jack_func) {
67 case RX51_JACK_TVOUT:
68 tvout = 1;
Jarkko Nikula31164c72011-02-14 17:20:21 +020069 hp = 1;
70 break;
71 case RX51_JACK_HS:
72 hs = 1;
Jarkko Nikula48529b32011-01-27 16:47:11 +020073 case RX51_JACK_HP:
74 hp = 1;
75 break;
76 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +020077
Charles Keepax9dd2bb32014-02-18 15:22:24 +000078 snd_soc_dapm_mutex_lock(dapm);
79
Jarkko Nikula49100c92010-05-05 11:14:22 +030080 if (rx51_spk_func)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000081 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
Jarkko Nikula49100c92010-05-05 11:14:22 +030082 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000083 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
Jarkko Nikula49100c92010-05-05 11:14:22 +030084 if (rx51_dmic_func)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000085 snd_soc_dapm_enable_pin_unlocked(dapm, "DMic");
Jarkko Nikula49100c92010-05-05 11:14:22 +030086 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000087 snd_soc_dapm_disable_pin_unlocked(dapm, "DMic");
Jarkko Nikula48529b32011-01-27 16:47:11 +020088 if (hp)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000089 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
Jarkko Nikula48529b32011-01-27 16:47:11 +020090 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000091 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
Jarkko Nikula31164c72011-02-14 17:20:21 +020092 if (hs)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000093 snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic");
Jarkko Nikula31164c72011-02-14 17:20:21 +020094 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000095 snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic");
Jarkko Nikula49100c92010-05-05 11:14:22 +030096
Sebastian Reichel386e81a2014-04-28 16:07:24 +020097 gpiod_set_value(pdata->tvout_selection_gpio, tvout);
Jarkko Nikula4eb54702010-06-21 14:14:59 +030098
Charles Keepax9dd2bb32014-02-18 15:22:24 +000099 snd_soc_dapm_sync_unlocked(dapm);
100
101 snd_soc_dapm_mutex_unlock(dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300102}
103
104static int rx51_startup(struct snd_pcm_substream *substream)
105{
106 struct snd_pcm_runtime *runtime = substream->runtime;
107 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood022658b2012-02-03 17:43:09 +0000108 struct snd_soc_card *card = rtd->card;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300109
Lars-Peter Clausenbe448b42015-10-18 15:39:27 +0200110 snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Liam Girdwood022658b2012-02-03 17:43:09 +0000111 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300112
113 return 0;
114}
115
116static int rx51_hw_params(struct snd_pcm_substream *substream,
117 struct snd_pcm_hw_params *params)
118{
119 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000120 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300121
122 /* Set the codec system clock for DAC and ADC */
123 return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
124 SND_SOC_CLOCK_IN);
125}
126
127static struct snd_soc_ops rx51_ops = {
128 .startup = rx51_startup,
129 .hw_params = rx51_hw_params,
130};
131
132static int rx51_get_spk(struct snd_kcontrol *kcontrol,
133 struct snd_ctl_elem_value *ucontrol)
134{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100135 ucontrol->value.enumerated.item[0] = rx51_spk_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300136
137 return 0;
138}
139
140static int rx51_set_spk(struct snd_kcontrol *kcontrol,
141 struct snd_ctl_elem_value *ucontrol)
142{
Liam Girdwood022658b2012-02-03 17:43:09 +0000143 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300144
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100145 if (rx51_spk_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula49100c92010-05-05 11:14:22 +0300146 return 0;
147
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100148 rx51_spk_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000149 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300150
151 return 1;
152}
153
154static int rx51_spk_event(struct snd_soc_dapm_widget *w,
155 struct snd_kcontrol *k, int event)
156{
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200157 struct snd_soc_dapm_context *dapm = w->dapm;
158 struct snd_soc_card *card = dapm->card;
159 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
160
161 gpiod_set_raw_value_cansleep(pdata->speaker_amp_gpio,
162 !!SND_SOC_DAPM_EVENT_ON(event));
Jarkko Nikula49100c92010-05-05 11:14:22 +0300163
164 return 0;
165}
166
Jarkko Nikula48529b32011-01-27 16:47:11 +0200167static int rx51_hp_event(struct snd_soc_dapm_widget *w,
168 struct snd_kcontrol *k, int event)
169{
Lars-Peter Clausena761f872014-09-29 11:40:41 +0200170 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Jarkko Nikula48529b32011-01-27 16:47:11 +0200171
172 if (SND_SOC_DAPM_EVENT_ON(event))
173 tpa6130a2_stereo_enable(codec, 1);
174 else
175 tpa6130a2_stereo_enable(codec, 0);
176
177 return 0;
178}
179
Jarkko Nikula49100c92010-05-05 11:14:22 +0300180static int rx51_get_input(struct snd_kcontrol *kcontrol,
181 struct snd_ctl_elem_value *ucontrol)
182{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100183 ucontrol->value.enumerated.item[0] = rx51_dmic_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300184
185 return 0;
186}
187
188static int rx51_set_input(struct snd_kcontrol *kcontrol,
189 struct snd_ctl_elem_value *ucontrol)
190{
Liam Girdwood022658b2012-02-03 17:43:09 +0000191 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300192
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100193 if (rx51_dmic_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula49100c92010-05-05 11:14:22 +0300194 return 0;
195
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100196 rx51_dmic_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000197 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300198
199 return 1;
200}
201
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300202static int rx51_get_jack(struct snd_kcontrol *kcontrol,
203 struct snd_ctl_elem_value *ucontrol)
204{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100205 ucontrol->value.enumerated.item[0] = rx51_jack_func;
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300206
207 return 0;
208}
209
210static int rx51_set_jack(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_value *ucontrol)
212{
Liam Girdwood022658b2012-02-03 17:43:09 +0000213 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300214
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100215 if (rx51_jack_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300216 return 0;
217
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100218 rx51_jack_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000219 rx51_ext_control(&card->dapm);
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300220
221 return 1;
222}
223
Jarkko Nikula8c523112010-06-21 14:15:00 +0300224static struct snd_soc_jack rx51_av_jack;
225
226static struct snd_soc_jack_gpio rx51_av_jack_gpios[] = {
227 {
Jarkko Nikula8c523112010-06-21 14:15:00 +0300228 .name = "avdet-gpio",
Jarkko Nikula17840612011-02-14 17:20:22 +0200229 .report = SND_JACK_HEADSET,
Jarkko Nikula8c523112010-06-21 14:15:00 +0300230 .invert = 1,
231 .debounce_time = 200,
232 },
233};
234
Jarkko Nikula49100c92010-05-05 11:14:22 +0300235static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
236 SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
237 SND_SOC_DAPM_MIC("DMic", NULL),
Jarkko Nikula48529b32011-01-27 16:47:11 +0200238 SND_SOC_DAPM_HP("Headphone Jack", rx51_hp_event),
Jarkko Nikula31164c72011-02-14 17:20:21 +0200239 SND_SOC_DAPM_MIC("HS Mic", NULL),
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200240 SND_SOC_DAPM_LINE("FM Transmitter", NULL),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200241 SND_SOC_DAPM_SPK("Earphone", NULL),
242};
243
Jarkko Nikula49100c92010-05-05 11:14:22 +0300244static const struct snd_soc_dapm_route audio_map[] = {
245 {"Ext Spk", NULL, "HPLOUT"},
246 {"Ext Spk", NULL, "HPROUT"},
Lars-Peter Clausen6876c7c2015-06-04 16:13:51 +0200247 {"Ext Spk", NULL, "HPLCOM"},
248 {"Ext Spk", NULL, "HPRCOM"},
Jarkko Nikula48529b32011-01-27 16:47:11 +0200249 {"Headphone Jack", NULL, "LLOUT"},
250 {"Headphone Jack", NULL, "RLOUT"},
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200251 {"FM Transmitter", NULL, "LLOUT"},
252 {"FM Transmitter", NULL, "RLOUT"},
Jarkko Nikula49100c92010-05-05 11:14:22 +0300253
Peter Ujfalusi2ca087b2015-01-30 09:32:43 +0200254 {"DMic Rate 64", NULL, "DMic"},
255 {"DMic", NULL, "Mic Bias"},
Jarkko Nikula49100c92010-05-05 11:14:22 +0300256
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200257 {"b LINE2R", NULL, "MONO_LOUT"},
258 {"Earphone", NULL, "b HPLOUT"},
Jarkko Nikula31164c72011-02-14 17:20:21 +0200259
Peter Ujfalusi2ca087b2015-01-30 09:32:43 +0200260 {"LINE1L", NULL, "HS Mic"},
261 {"HS Mic", NULL, "b Mic Bias"},
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200262};
263
Sebastian Reichel441dc452014-04-28 16:07:19 +0200264static const char * const spk_function[] = {"Off", "On"};
265static const char * const input_function[] = {"ADC", "Digital Mic"};
266static const char * const jack_function[] = {
267 "Off", "TV-OUT", "Headphone", "Headset"
268};
Jarkko Nikula49100c92010-05-05 11:14:22 +0300269
270static const struct soc_enum rx51_enum[] = {
271 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
272 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300273 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
Jarkko Nikula49100c92010-05-05 11:14:22 +0300274};
275
276static const struct snd_kcontrol_new aic34_rx51_controls[] = {
277 SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
278 rx51_get_spk, rx51_set_spk),
279 SOC_ENUM_EXT("Input Select", rx51_enum[1],
280 rx51_get_input, rx51_set_input),
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300281 SOC_ENUM_EXT("Jack Function", rx51_enum[2],
282 rx51_get_jack, rx51_set_jack),
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200283 SOC_DAPM_PIN_SWITCH("FM Transmitter"),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200284 SOC_DAPM_PIN_SWITCH("Earphone"),
285};
286
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000287static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
Jarkko Nikula49100c92010-05-05 11:14:22 +0300288{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000289 struct snd_soc_codec *codec = rtd->codec;
Lars-Peter Clausen0596f702014-05-19 11:41:46 +0200290 struct snd_soc_card *card = rtd->card;
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200291 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300292 int err;
293
Jarkko Nikula48529b32011-01-27 16:47:11 +0200294 err = tpa6130a2_add_controls(codec);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200295 if (err < 0) {
296 dev_err(card->dev, "Failed to add TPA6130A2 controls\n");
Jarkko Nikula48529b32011-01-27 16:47:11 +0200297 return err;
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200298 }
Lars-Peter Clausen26d9ca32015-10-18 17:04:33 +0200299 snd_soc_limit_volume(card, "TPA6130A2 Headphone Playback Volume", 42);
Jarkko Nikula48529b32011-01-27 16:47:11 +0200300
Sebastian Reichel0a17a372014-04-28 16:07:23 +0200301 err = omap_mcbsp_st_add_controls(rtd, 2);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200302 if (err < 0) {
303 dev_err(card->dev, "Failed to add MCBSP controls\n");
Jarkko Nikulafa4d1f52011-03-09 11:25:00 +0200304 return err;
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200305 }
Jarkko Nikulafa4d1f52011-03-09 11:25:00 +0200306
Jarkko Nikula8c523112010-06-21 14:15:00 +0300307 /* AV jack detection */
Lars-Peter Clausen753d45e2015-03-04 10:33:28 +0100308 err = snd_soc_card_jack_new(rtd->card, "AV Jack",
309 SND_JACK_HEADSET | SND_JACK_VIDEOOUT,
310 &rx51_av_jack, NULL, 0);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200311 if (err) {
312 dev_err(card->dev, "Failed to add AV Jack\n");
Jarkko Nikula8c523112010-06-21 14:15:00 +0300313 return err;
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200314 }
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200315
316 /* prepare gpio for snd_soc_jack_add_gpios */
317 rx51_av_jack_gpios[0].gpio = desc_to_gpio(pdata->jack_detection_gpio);
318 devm_gpiod_put(card->dev, pdata->jack_detection_gpio);
319
Jarkko Nikula8c523112010-06-21 14:15:00 +0300320 err = snd_soc_jack_add_gpios(&rx51_av_jack,
321 ARRAY_SIZE(rx51_av_jack_gpios),
322 rx51_av_jack_gpios);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200323 if (err) {
324 dev_err(card->dev, "Failed to add GPIOs\n");
325 return err;
326 }
Jarkko Nikula8c523112010-06-21 14:15:00 +0300327
328 return err;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300329}
330
Takashi Iwai16088cb2014-06-03 12:31:46 +0200331static int rx51_card_remove(struct snd_soc_card *card)
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600332{
333 snd_soc_jack_free_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios),
334 rx51_av_jack_gpios);
335
336 return 0;
337}
338
Jarkko Nikula49100c92010-05-05 11:14:22 +0300339/* Digital audio interface glue - connects codec <--> CPU */
340static struct snd_soc_dai_link rx51_dai[] = {
341 {
342 .name = "TLV320AIC34",
343 .stream_name = "AIC34",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200344 .cpu_dai_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000345 .codec_dai_name = "tlv320aic3x-hifi",
Peter Ujfalusiaac25142014-04-16 15:46:28 +0300346 .platform_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000347 .codec_name = "tlv320aic3x-codec.2-0018",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300348 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
349 SND_SOC_DAIFMT_CBM_CFM,
Jarkko Nikula49100c92010-05-05 11:14:22 +0300350 .init = rx51_aic34_init,
351 .ops = &rx51_ops,
352 },
353};
354
Axel Lina0e17b42011-12-13 10:13:13 +0800355static struct snd_soc_aux_dev rx51_aux_dev[] = {
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200356 {
357 .name = "TLV320AIC34b",
358 .codec_name = "tlv320aic3x-codec.2-0019",
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200359 },
360};
361
362static struct snd_soc_codec_conf rx51_codec_conf[] = {
363 {
364 .dev_name = "tlv320aic3x-codec.2-0019",
365 .name_prefix = "b",
366 },
367};
368
Jarkko Nikula49100c92010-05-05 11:14:22 +0300369/* Audio card */
370static struct snd_soc_card rx51_sound_card = {
371 .name = "RX-51",
Axel Linb425b882011-12-22 11:08:59 +0800372 .owner = THIS_MODULE,
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600373 .remove = rx51_card_remove,
Jarkko Nikula49100c92010-05-05 11:14:22 +0300374 .dai_link = rx51_dai,
375 .num_links = ARRAY_SIZE(rx51_dai),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200376 .aux_dev = rx51_aux_dev,
377 .num_aux_devs = ARRAY_SIZE(rx51_aux_dev),
378 .codec_conf = rx51_codec_conf,
379 .num_configs = ARRAY_SIZE(rx51_codec_conf),
Lars-Peter Clausen6876c7c2015-06-04 16:13:51 +0200380 .fully_routed = true,
Lars-Peter Clausen81fc5dd2014-03-12 15:27:33 +0100381
382 .controls = aic34_rx51_controls,
383 .num_controls = ARRAY_SIZE(aic34_rx51_controls),
384 .dapm_widgets = aic34_dapm_widgets,
385 .num_dapm_widgets = ARRAY_SIZE(aic34_dapm_widgets),
386 .dapm_routes = audio_map,
387 .num_dapm_routes = ARRAY_SIZE(audio_map),
Jarkko Nikula49100c92010-05-05 11:14:22 +0300388};
389
Sebastian Reichela7d52022014-04-28 16:07:21 +0200390static int rx51_soc_probe(struct platform_device *pdev)
Jarkko Nikula49100c92010-05-05 11:14:22 +0300391{
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200392 struct rx51_audio_pdata *pdata;
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200393 struct device_node *np = pdev->dev.of_node;
Sebastian Reichela7d52022014-04-28 16:07:21 +0200394 struct snd_soc_card *card = &rx51_sound_card;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300395 int err;
396
Pavel Machekea2409b2013-07-01 23:15:04 +0200397 if (!machine_is_nokia_rx51() && !of_machine_is_compatible("nokia,omap3-n900"))
Jarkko Nikula49100c92010-05-05 11:14:22 +0300398 return -ENODEV;
399
Sebastian Reichela7d52022014-04-28 16:07:21 +0200400 card->dev = &pdev->dev;
401
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200402 if (np) {
403 struct device_node *dai_node;
404
405 dai_node = of_parse_phandle(np, "nokia,cpu-dai", 0);
406 if (!dai_node) {
407 dev_err(&pdev->dev, "McBSP node is not provided\n");
408 return -EINVAL;
409 }
410 rx51_dai[0].cpu_dai_name = NULL;
411 rx51_dai[0].platform_name = NULL;
412 rx51_dai[0].cpu_of_node = dai_node;
413 rx51_dai[0].platform_of_node = dai_node;
414
415 dai_node = of_parse_phandle(np, "nokia,audio-codec", 0);
416 if (!dai_node) {
417 dev_err(&pdev->dev, "Codec node is not provided\n");
418 return -EINVAL;
419 }
420 rx51_dai[0].codec_name = NULL;
421 rx51_dai[0].codec_of_node = dai_node;
422
423 dai_node = of_parse_phandle(np, "nokia,audio-codec", 1);
424 if (!dai_node) {
425 dev_err(&pdev->dev, "Auxiliary Codec node is not provided\n");
426 return -EINVAL;
427 }
428 rx51_aux_dev[0].codec_name = NULL;
429 rx51_aux_dev[0].codec_of_node = dai_node;
430 rx51_codec_conf[0].dev_name = NULL;
431 rx51_codec_conf[0].of_node = dai_node;
432
433 dai_node = of_parse_phandle(np, "nokia,headphone-amplifier", 0);
434 if (!dai_node) {
435 dev_err(&pdev->dev, "Headphone amplifier node is not provided\n");
436 return -EINVAL;
437 }
438
439 /* TODO: tpa6130a2a driver supports only a single instance, so
440 * this driver ignores the headphone-amplifier node for now.
441 * It's already mandatory in the DT binding to be future proof.
442 */
443 }
444
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200445 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
446 if (pdata == NULL) {
447 dev_err(card->dev, "failed to create private data\n");
448 return -ENOMEM;
449 }
450 snd_soc_card_set_drvdata(card, pdata);
451
452 pdata->tvout_selection_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200453 "tvout-selection",
454 GPIOD_OUT_LOW);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200455 if (IS_ERR(pdata->tvout_selection_gpio)) {
456 dev_err(card->dev, "could not get tvout selection gpio\n");
457 return PTR_ERR(pdata->tvout_selection_gpio);
458 }
459
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200460 pdata->jack_detection_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200461 "jack-detection",
462 GPIOD_ASIS);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200463 if (IS_ERR(pdata->jack_detection_gpio)) {
464 dev_err(card->dev, "could not get jack detection gpio\n");
465 return PTR_ERR(pdata->jack_detection_gpio);
466 }
467
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200468 pdata->eci_sw_gpio = devm_gpiod_get(card->dev, "eci-switch",
469 GPIOD_OUT_HIGH);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200470 if (IS_ERR(pdata->eci_sw_gpio)) {
471 dev_err(card->dev, "could not get eci switch gpio\n");
472 return PTR_ERR(pdata->eci_sw_gpio);
473 }
474
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200475 pdata->speaker_amp_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200476 "speaker-amplifier",
477 GPIOD_OUT_LOW);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200478 if (IS_ERR(pdata->speaker_amp_gpio)) {
479 dev_err(card->dev, "could not get speaker enable gpio\n");
480 return PTR_ERR(pdata->speaker_amp_gpio);
481 }
482
Sebastian Reichela7d52022014-04-28 16:07:21 +0200483 err = devm_snd_soc_register_card(card->dev, card);
484 if (err) {
485 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", err);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200486 return err;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300487 }
488
Jarkko Nikula49100c92010-05-05 11:14:22 +0300489 return 0;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300490}
491
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200492#if defined(CONFIG_OF)
493static const struct of_device_id rx51_audio_of_match[] = {
494 { .compatible = "nokia,n900-audio", },
495 {},
496};
497MODULE_DEVICE_TABLE(of, rx51_audio_of_match);
498#endif
499
Sebastian Reichela7d52022014-04-28 16:07:21 +0200500static struct platform_driver rx51_soc_driver = {
501 .driver = {
502 .name = "rx51-audio",
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200503 .of_match_table = of_match_ptr(rx51_audio_of_match),
Sebastian Reichela7d52022014-04-28 16:07:21 +0200504 },
505 .probe = rx51_soc_probe,
Sebastian Reichela7d52022014-04-28 16:07:21 +0200506};
507
508module_platform_driver(rx51_soc_driver);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300509
510MODULE_AUTHOR("Nokia Corporation");
511MODULE_DESCRIPTION("ALSA SoC Nokia RX-51");
512MODULE_LICENSE("GPL");
Sebastian Reichelbeab3da2014-04-28 16:07:20 +0200513MODULE_ALIAS("platform:rx51-audio");