blob: a76845748a103447e039ee4db94cf3f8abe10c93 [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 Nikula49100c92010-05-05 11:14:22 +030036
37#include <asm/mach-types.h>
38
39#include "omap-mcbsp.h"
Jarkko Nikula49100c92010-05-05 11:14:22 +030040
Jarkko Nikula4eb54702010-06-21 14:14:59 +030041enum {
42 RX51_JACK_DISABLED,
Jarkko Nikula48529b32011-01-27 16:47:11 +020043 RX51_JACK_TVOUT, /* tv-out with stereo output */
44 RX51_JACK_HP, /* headphone: stereo output, no mic */
Jarkko Nikula31164c72011-02-14 17:20:21 +020045 RX51_JACK_HS, /* headset: stereo output with mic */
Jarkko Nikula4eb54702010-06-21 14:14:59 +030046};
47
Sebastian Reichel386e81a2014-04-28 16:07:24 +020048struct rx51_audio_pdata {
49 struct gpio_desc *tvout_selection_gpio;
50 struct gpio_desc *jack_detection_gpio;
51 struct gpio_desc *eci_sw_gpio;
52 struct gpio_desc *speaker_amp_gpio;
53};
54
Jarkko Nikula49100c92010-05-05 11:14:22 +030055static int rx51_spk_func;
56static int rx51_dmic_func;
Jarkko Nikula4eb54702010-06-21 14:14:59 +030057static int rx51_jack_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +030058
Liam Girdwood022658b2012-02-03 17:43:09 +000059static void rx51_ext_control(struct snd_soc_dapm_context *dapm)
Jarkko Nikula49100c92010-05-05 11:14:22 +030060{
Sebastian Reichel386e81a2014-04-28 16:07:24 +020061 struct snd_soc_card *card = dapm->card;
62 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
Jarkko Nikula31164c72011-02-14 17:20:21 +020063 int hp = 0, hs = 0, tvout = 0;
Jarkko Nikula48529b32011-01-27 16:47:11 +020064
65 switch (rx51_jack_func) {
66 case RX51_JACK_TVOUT:
67 tvout = 1;
Jarkko Nikula31164c72011-02-14 17:20:21 +020068 hp = 1;
69 break;
70 case RX51_JACK_HS:
71 hs = 1;
Jarkko Nikula48529b32011-01-27 16:47:11 +020072 case RX51_JACK_HP:
73 hp = 1;
74 break;
75 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +020076
Charles Keepax9dd2bb32014-02-18 15:22:24 +000077 snd_soc_dapm_mutex_lock(dapm);
78
Jarkko Nikula49100c92010-05-05 11:14:22 +030079 if (rx51_spk_func)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000080 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
Jarkko Nikula49100c92010-05-05 11:14:22 +030081 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000082 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
Jarkko Nikula49100c92010-05-05 11:14:22 +030083 if (rx51_dmic_func)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000084 snd_soc_dapm_enable_pin_unlocked(dapm, "DMic");
Jarkko Nikula49100c92010-05-05 11:14:22 +030085 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000086 snd_soc_dapm_disable_pin_unlocked(dapm, "DMic");
Jarkko Nikula48529b32011-01-27 16:47:11 +020087 if (hp)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000088 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
Jarkko Nikula48529b32011-01-27 16:47:11 +020089 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000090 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
Jarkko Nikula31164c72011-02-14 17:20:21 +020091 if (hs)
Charles Keepax9dd2bb32014-02-18 15:22:24 +000092 snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic");
Jarkko Nikula31164c72011-02-14 17:20:21 +020093 else
Charles Keepax9dd2bb32014-02-18 15:22:24 +000094 snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic");
Jarkko Nikula49100c92010-05-05 11:14:22 +030095
Sebastian Reichel386e81a2014-04-28 16:07:24 +020096 gpiod_set_value(pdata->tvout_selection_gpio, tvout);
Jarkko Nikula4eb54702010-06-21 14:14:59 +030097
Charles Keepax9dd2bb32014-02-18 15:22:24 +000098 snd_soc_dapm_sync_unlocked(dapm);
99
100 snd_soc_dapm_mutex_unlock(dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300101}
102
103static int rx51_startup(struct snd_pcm_substream *substream)
104{
105 struct snd_pcm_runtime *runtime = substream->runtime;
106 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood022658b2012-02-03 17:43:09 +0000107 struct snd_soc_card *card = rtd->card;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300108
Lars-Peter Clausenbe448b42015-10-18 15:39:27 +0200109 snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Liam Girdwood022658b2012-02-03 17:43:09 +0000110 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300111
112 return 0;
113}
114
115static int rx51_hw_params(struct snd_pcm_substream *substream,
116 struct snd_pcm_hw_params *params)
117{
118 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000119 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300120
121 /* Set the codec system clock for DAC and ADC */
122 return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
123 SND_SOC_CLOCK_IN);
124}
125
126static struct snd_soc_ops rx51_ops = {
127 .startup = rx51_startup,
128 .hw_params = rx51_hw_params,
129};
130
131static int rx51_get_spk(struct snd_kcontrol *kcontrol,
132 struct snd_ctl_elem_value *ucontrol)
133{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100134 ucontrol->value.enumerated.item[0] = rx51_spk_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300135
136 return 0;
137}
138
139static int rx51_set_spk(struct snd_kcontrol *kcontrol,
140 struct snd_ctl_elem_value *ucontrol)
141{
Liam Girdwood022658b2012-02-03 17:43:09 +0000142 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300143
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100144 if (rx51_spk_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula49100c92010-05-05 11:14:22 +0300145 return 0;
146
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100147 rx51_spk_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000148 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300149
150 return 1;
151}
152
153static int rx51_spk_event(struct snd_soc_dapm_widget *w,
154 struct snd_kcontrol *k, int event)
155{
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200156 struct snd_soc_dapm_context *dapm = w->dapm;
157 struct snd_soc_card *card = dapm->card;
158 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
159
160 gpiod_set_raw_value_cansleep(pdata->speaker_amp_gpio,
161 !!SND_SOC_DAPM_EVENT_ON(event));
Jarkko Nikula49100c92010-05-05 11:14:22 +0300162
163 return 0;
164}
165
166static int rx51_get_input(struct snd_kcontrol *kcontrol,
167 struct snd_ctl_elem_value *ucontrol)
168{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100169 ucontrol->value.enumerated.item[0] = rx51_dmic_func;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300170
171 return 0;
172}
173
174static int rx51_set_input(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_value *ucontrol)
176{
Liam Girdwood022658b2012-02-03 17:43:09 +0000177 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300178
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100179 if (rx51_dmic_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula49100c92010-05-05 11:14:22 +0300180 return 0;
181
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100182 rx51_dmic_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000183 rx51_ext_control(&card->dapm);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300184
185 return 1;
186}
187
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300188static int rx51_get_jack(struct snd_kcontrol *kcontrol,
189 struct snd_ctl_elem_value *ucontrol)
190{
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100191 ucontrol->value.enumerated.item[0] = rx51_jack_func;
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300192
193 return 0;
194}
195
196static int rx51_set_jack(struct snd_kcontrol *kcontrol,
197 struct snd_ctl_elem_value *ucontrol)
198{
Liam Girdwood022658b2012-02-03 17:43:09 +0000199 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300200
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100201 if (rx51_jack_func == ucontrol->value.enumerated.item[0])
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300202 return 0;
203
Takashi Iwaif4d438e2016-02-29 17:26:22 +0100204 rx51_jack_func = ucontrol->value.enumerated.item[0];
Liam Girdwood022658b2012-02-03 17:43:09 +0000205 rx51_ext_control(&card->dapm);
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300206
207 return 1;
208}
209
Jarkko Nikula8c523112010-06-21 14:15:00 +0300210static struct snd_soc_jack rx51_av_jack;
211
212static struct snd_soc_jack_gpio rx51_av_jack_gpios[] = {
213 {
Jarkko Nikula8c523112010-06-21 14:15:00 +0300214 .name = "avdet-gpio",
Jarkko Nikula17840612011-02-14 17:20:22 +0200215 .report = SND_JACK_HEADSET,
Jarkko Nikula8c523112010-06-21 14:15:00 +0300216 .invert = 1,
217 .debounce_time = 200,
218 },
219};
220
Jarkko Nikula49100c92010-05-05 11:14:22 +0300221static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
222 SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
223 SND_SOC_DAPM_MIC("DMic", NULL),
Helen Koike6d2de5a2016-06-23 16:23:13 -0300224 SND_SOC_DAPM_HP("Headphone Jack", NULL),
Jarkko Nikula31164c72011-02-14 17:20:21 +0200225 SND_SOC_DAPM_MIC("HS Mic", NULL),
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200226 SND_SOC_DAPM_LINE("FM Transmitter", NULL),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200227 SND_SOC_DAPM_SPK("Earphone", NULL),
228};
229
Jarkko Nikula49100c92010-05-05 11:14:22 +0300230static const struct snd_soc_dapm_route audio_map[] = {
231 {"Ext Spk", NULL, "HPLOUT"},
232 {"Ext Spk", NULL, "HPROUT"},
Lars-Peter Clausen6876c7c2015-06-04 16:13:51 +0200233 {"Ext Spk", NULL, "HPLCOM"},
234 {"Ext Spk", NULL, "HPRCOM"},
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200235 {"FM Transmitter", NULL, "LLOUT"},
236 {"FM Transmitter", NULL, "RLOUT"},
Jarkko Nikula49100c92010-05-05 11:14:22 +0300237
Helen Koike6d2de5a2016-06-23 16:23:13 -0300238 {"Headphone Jack", NULL, "TPA6130A2 HPLEFT"},
239 {"Headphone Jack", NULL, "TPA6130A2 HPRIGHT"},
240 {"TPA6130A2 LEFTIN", NULL, "LLOUT"},
241 {"TPA6130A2 RIGHTIN", NULL, "RLOUT"},
242
Peter Ujfalusi2ca087b2015-01-30 09:32:43 +0200243 {"DMic Rate 64", NULL, "DMic"},
244 {"DMic", NULL, "Mic Bias"},
Jarkko Nikula49100c92010-05-05 11:14:22 +0300245
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200246 {"b LINE2R", NULL, "MONO_LOUT"},
247 {"Earphone", NULL, "b HPLOUT"},
Jarkko Nikula31164c72011-02-14 17:20:21 +0200248
Peter Ujfalusi2ca087b2015-01-30 09:32:43 +0200249 {"LINE1L", NULL, "HS Mic"},
250 {"HS Mic", NULL, "b Mic Bias"},
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200251};
252
Sebastian Reichel441dc452014-04-28 16:07:19 +0200253static const char * const spk_function[] = {"Off", "On"};
254static const char * const input_function[] = {"ADC", "Digital Mic"};
255static const char * const jack_function[] = {
256 "Off", "TV-OUT", "Headphone", "Headset"
257};
Jarkko Nikula49100c92010-05-05 11:14:22 +0300258
259static const struct soc_enum rx51_enum[] = {
260 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
261 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300262 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
Jarkko Nikula49100c92010-05-05 11:14:22 +0300263};
264
265static const struct snd_kcontrol_new aic34_rx51_controls[] = {
266 SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
267 rx51_get_spk, rx51_set_spk),
268 SOC_ENUM_EXT("Input Select", rx51_enum[1],
269 rx51_get_input, rx51_set_input),
Jarkko Nikula4eb54702010-06-21 14:14:59 +0300270 SOC_ENUM_EXT("Jack Function", rx51_enum[2],
271 rx51_get_jack, rx51_set_jack),
Jarkko Nikula9d7e5842011-02-21 14:57:22 +0200272 SOC_DAPM_PIN_SWITCH("FM Transmitter"),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200273 SOC_DAPM_PIN_SWITCH("Earphone"),
274};
275
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000276static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
Jarkko Nikula49100c92010-05-05 11:14:22 +0300277{
Lars-Peter Clausen0596f702014-05-19 11:41:46 +0200278 struct snd_soc_card *card = rtd->card;
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200279 struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300280 int err;
281
Lars-Peter Clausen26d9ca32015-10-18 17:04:33 +0200282 snd_soc_limit_volume(card, "TPA6130A2 Headphone Playback Volume", 42);
Jarkko Nikula48529b32011-01-27 16:47:11 +0200283
Sebastian Reichel0a17a372014-04-28 16:07:23 +0200284 err = omap_mcbsp_st_add_controls(rtd, 2);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200285 if (err < 0) {
286 dev_err(card->dev, "Failed to add MCBSP controls\n");
Jarkko Nikulafa4d1f52011-03-09 11:25:00 +0200287 return err;
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200288 }
Jarkko Nikulafa4d1f52011-03-09 11:25:00 +0200289
Jarkko Nikula8c523112010-06-21 14:15:00 +0300290 /* AV jack detection */
Lars-Peter Clausen753d45e2015-03-04 10:33:28 +0100291 err = snd_soc_card_jack_new(rtd->card, "AV Jack",
292 SND_JACK_HEADSET | SND_JACK_VIDEOOUT,
293 &rx51_av_jack, NULL, 0);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200294 if (err) {
295 dev_err(card->dev, "Failed to add AV Jack\n");
Jarkko Nikula8c523112010-06-21 14:15:00 +0300296 return err;
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200297 }
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200298
299 /* prepare gpio for snd_soc_jack_add_gpios */
300 rx51_av_jack_gpios[0].gpio = desc_to_gpio(pdata->jack_detection_gpio);
301 devm_gpiod_put(card->dev, pdata->jack_detection_gpio);
302
Jarkko Nikula8c523112010-06-21 14:15:00 +0300303 err = snd_soc_jack_add_gpios(&rx51_av_jack,
304 ARRAY_SIZE(rx51_av_jack_gpios),
305 rx51_av_jack_gpios);
Sebastian Reichel0265e1a2014-04-28 16:07:25 +0200306 if (err) {
307 dev_err(card->dev, "Failed to add GPIOs\n");
308 return err;
309 }
Jarkko Nikula8c523112010-06-21 14:15:00 +0300310
311 return err;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300312}
313
Takashi Iwai16088cb2014-06-03 12:31:46 +0200314static int rx51_card_remove(struct snd_soc_card *card)
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600315{
316 snd_soc_jack_free_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios),
317 rx51_av_jack_gpios);
318
319 return 0;
320}
321
Jarkko Nikula49100c92010-05-05 11:14:22 +0300322/* Digital audio interface glue - connects codec <--> CPU */
323static struct snd_soc_dai_link rx51_dai[] = {
324 {
325 .name = "TLV320AIC34",
326 .stream_name = "AIC34",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200327 .cpu_dai_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000328 .codec_dai_name = "tlv320aic3x-hifi",
Peter Ujfalusiaac25142014-04-16 15:46:28 +0300329 .platform_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000330 .codec_name = "tlv320aic3x-codec.2-0018",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300331 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
332 SND_SOC_DAIFMT_CBM_CFM,
Jarkko Nikula49100c92010-05-05 11:14:22 +0300333 .init = rx51_aic34_init,
334 .ops = &rx51_ops,
335 },
336};
337
Axel Lina0e17b42011-12-13 10:13:13 +0800338static struct snd_soc_aux_dev rx51_aux_dev[] = {
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200339 {
340 .name = "TLV320AIC34b",
341 .codec_name = "tlv320aic3x-codec.2-0019",
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200342 },
Helen Koikecb7e6222016-06-20 14:12:29 -0300343 {
344 .name = "TPA61320A2",
345 .codec_name = "tpa6130a2.2-0060",
346 },
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200347};
348
349static struct snd_soc_codec_conf rx51_codec_conf[] = {
350 {
351 .dev_name = "tlv320aic3x-codec.2-0019",
352 .name_prefix = "b",
353 },
Helen Koikecb7e6222016-06-20 14:12:29 -0300354 {
355 .dev_name = "tpa6130a2.2-0060",
356 .name_prefix = "TPA6130A2",
357 },
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200358};
359
Jarkko Nikula49100c92010-05-05 11:14:22 +0300360/* Audio card */
361static struct snd_soc_card rx51_sound_card = {
362 .name = "RX-51",
Axel Linb425b882011-12-22 11:08:59 +0800363 .owner = THIS_MODULE,
Stephen Warrene1d4d3c2014-05-30 12:42:57 -0600364 .remove = rx51_card_remove,
Jarkko Nikula49100c92010-05-05 11:14:22 +0300365 .dai_link = rx51_dai,
366 .num_links = ARRAY_SIZE(rx51_dai),
Jarkko Nikula8cda9752011-01-31 14:43:48 +0200367 .aux_dev = rx51_aux_dev,
368 .num_aux_devs = ARRAY_SIZE(rx51_aux_dev),
369 .codec_conf = rx51_codec_conf,
370 .num_configs = ARRAY_SIZE(rx51_codec_conf),
Lars-Peter Clausen6876c7c2015-06-04 16:13:51 +0200371 .fully_routed = true,
Lars-Peter Clausen81fc5dd2014-03-12 15:27:33 +0100372
373 .controls = aic34_rx51_controls,
374 .num_controls = ARRAY_SIZE(aic34_rx51_controls),
375 .dapm_widgets = aic34_dapm_widgets,
376 .num_dapm_widgets = ARRAY_SIZE(aic34_dapm_widgets),
377 .dapm_routes = audio_map,
378 .num_dapm_routes = ARRAY_SIZE(audio_map),
Jarkko Nikula49100c92010-05-05 11:14:22 +0300379};
380
Sebastian Reichela7d52022014-04-28 16:07:21 +0200381static int rx51_soc_probe(struct platform_device *pdev)
Jarkko Nikula49100c92010-05-05 11:14:22 +0300382{
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200383 struct rx51_audio_pdata *pdata;
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200384 struct device_node *np = pdev->dev.of_node;
Sebastian Reichela7d52022014-04-28 16:07:21 +0200385 struct snd_soc_card *card = &rx51_sound_card;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300386 int err;
387
Pavel Machekea2409b2013-07-01 23:15:04 +0200388 if (!machine_is_nokia_rx51() && !of_machine_is_compatible("nokia,omap3-n900"))
Jarkko Nikula49100c92010-05-05 11:14:22 +0300389 return -ENODEV;
390
Sebastian Reichela7d52022014-04-28 16:07:21 +0200391 card->dev = &pdev->dev;
392
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200393 if (np) {
394 struct device_node *dai_node;
395
396 dai_node = of_parse_phandle(np, "nokia,cpu-dai", 0);
397 if (!dai_node) {
398 dev_err(&pdev->dev, "McBSP node is not provided\n");
399 return -EINVAL;
400 }
401 rx51_dai[0].cpu_dai_name = NULL;
402 rx51_dai[0].platform_name = NULL;
403 rx51_dai[0].cpu_of_node = dai_node;
404 rx51_dai[0].platform_of_node = dai_node;
405
406 dai_node = of_parse_phandle(np, "nokia,audio-codec", 0);
407 if (!dai_node) {
408 dev_err(&pdev->dev, "Codec node is not provided\n");
409 return -EINVAL;
410 }
411 rx51_dai[0].codec_name = NULL;
412 rx51_dai[0].codec_of_node = dai_node;
413
414 dai_node = of_parse_phandle(np, "nokia,audio-codec", 1);
415 if (!dai_node) {
416 dev_err(&pdev->dev, "Auxiliary Codec node is not provided\n");
417 return -EINVAL;
418 }
419 rx51_aux_dev[0].codec_name = NULL;
420 rx51_aux_dev[0].codec_of_node = dai_node;
421 rx51_codec_conf[0].dev_name = NULL;
422 rx51_codec_conf[0].of_node = dai_node;
423
424 dai_node = of_parse_phandle(np, "nokia,headphone-amplifier", 0);
425 if (!dai_node) {
426 dev_err(&pdev->dev, "Headphone amplifier node is not provided\n");
427 return -EINVAL;
428 }
Helen Koikecb7e6222016-06-20 14:12:29 -0300429 rx51_aux_dev[1].codec_name = NULL;
430 rx51_aux_dev[1].codec_of_node = dai_node;
431 rx51_codec_conf[1].dev_name = NULL;
432 rx51_codec_conf[1].of_node = dai_node;
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200433 }
434
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200435 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
436 if (pdata == NULL) {
437 dev_err(card->dev, "failed to create private data\n");
438 return -ENOMEM;
439 }
440 snd_soc_card_set_drvdata(card, pdata);
441
442 pdata->tvout_selection_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200443 "tvout-selection",
444 GPIOD_OUT_LOW);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200445 if (IS_ERR(pdata->tvout_selection_gpio)) {
446 dev_err(card->dev, "could not get tvout selection gpio\n");
447 return PTR_ERR(pdata->tvout_selection_gpio);
448 }
449
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200450 pdata->jack_detection_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200451 "jack-detection",
452 GPIOD_ASIS);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200453 if (IS_ERR(pdata->jack_detection_gpio)) {
454 dev_err(card->dev, "could not get jack detection gpio\n");
455 return PTR_ERR(pdata->jack_detection_gpio);
456 }
457
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200458 pdata->eci_sw_gpio = devm_gpiod_get(card->dev, "eci-switch",
459 GPIOD_OUT_HIGH);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200460 if (IS_ERR(pdata->eci_sw_gpio)) {
461 dev_err(card->dev, "could not get eci switch gpio\n");
462 return PTR_ERR(pdata->eci_sw_gpio);
463 }
464
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200465 pdata->speaker_amp_gpio = devm_gpiod_get(card->dev,
Uwe Kleine-König0a8ba6e2015-05-19 09:48:08 +0200466 "speaker-amplifier",
467 GPIOD_OUT_LOW);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200468 if (IS_ERR(pdata->speaker_amp_gpio)) {
469 dev_err(card->dev, "could not get speaker enable gpio\n");
470 return PTR_ERR(pdata->speaker_amp_gpio);
471 }
472
Sebastian Reichela7d52022014-04-28 16:07:21 +0200473 err = devm_snd_soc_register_card(card->dev, card);
474 if (err) {
475 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", err);
Sebastian Reichel386e81a2014-04-28 16:07:24 +0200476 return err;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300477 }
478
Jarkko Nikula49100c92010-05-05 11:14:22 +0300479 return 0;
Jarkko Nikula49100c92010-05-05 11:14:22 +0300480}
481
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200482#if defined(CONFIG_OF)
483static const struct of_device_id rx51_audio_of_match[] = {
484 { .compatible = "nokia,n900-audio", },
485 {},
486};
487MODULE_DEVICE_TABLE(of, rx51_audio_of_match);
488#endif
489
Sebastian Reichela7d52022014-04-28 16:07:21 +0200490static struct platform_driver rx51_soc_driver = {
491 .driver = {
492 .name = "rx51-audio",
Sebastian Reicheld052a3d2014-04-28 16:07:26 +0200493 .of_match_table = of_match_ptr(rx51_audio_of_match),
Sebastian Reichela7d52022014-04-28 16:07:21 +0200494 },
495 .probe = rx51_soc_probe,
Sebastian Reichela7d52022014-04-28 16:07:21 +0200496};
497
498module_platform_driver(rx51_soc_driver);
Jarkko Nikula49100c92010-05-05 11:14:22 +0300499
500MODULE_AUTHOR("Nokia Corporation");
501MODULE_DESCRIPTION("ALSA SoC Nokia RX-51");
502MODULE_LICENSE("GPL");
Sebastian Reichelbeab3da2014-04-28 16:07:20 +0200503MODULE_ALIAS("platform:rx51-audio");