Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 1 | /* |
| 2 | * rx51.c -- SoC audio for Nokia RX-51 |
| 3 | * |
| 4 | * Copyright (C) 2008 - 2009 Nokia Corporation |
| 5 | * |
Peter Ujfalusi | 0ac3a01 | 2011-05-03 18:15:10 +0300 | [diff] [blame] | 6 | * Contact: Peter Ujfalusi <peter.ujfalusi@ti.com> |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 7 | * Eduardo Valentin <eduardo.valentin@nokia.com> |
Jarkko Nikula | 7ec41ee | 2011-08-11 15:44:57 +0300 | [diff] [blame] | 8 | * Jarkko Nikula <jarkko.nikula@bitmer.com> |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 9 | * |
| 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 Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 29 | #include <linux/gpio/consumer.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 31 | #include <sound/core.h> |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 32 | #include <sound/jack.h> |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 33 | #include <sound/pcm.h> |
| 34 | #include <sound/soc.h> |
Arnd Bergmann | 2203747 | 2012-08-24 15:21:06 +0200 | [diff] [blame] | 35 | #include <linux/platform_data/asoc-ti-mcbsp.h> |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 36 | #include "../codecs/tpa6130a2.h" |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 37 | |
| 38 | #include <asm/mach-types.h> |
| 39 | |
| 40 | #include "omap-mcbsp.h" |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 41 | |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 42 | enum { |
| 43 | RX51_JACK_DISABLED, |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 44 | RX51_JACK_TVOUT, /* tv-out with stereo output */ |
| 45 | RX51_JACK_HP, /* headphone: stereo output, no mic */ |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 46 | RX51_JACK_HS, /* headset: stereo output with mic */ |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 47 | }; |
| 48 | |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 49 | struct 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 Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 56 | static int rx51_spk_func; |
| 57 | static int rx51_dmic_func; |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 58 | static int rx51_jack_func; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 59 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 60 | static void rx51_ext_control(struct snd_soc_dapm_context *dapm) |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 61 | { |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 62 | struct snd_soc_card *card = dapm->card; |
| 63 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 64 | int hp = 0, hs = 0, tvout = 0; |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 65 | |
| 66 | switch (rx51_jack_func) { |
| 67 | case RX51_JACK_TVOUT: |
| 68 | tvout = 1; |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 69 | hp = 1; |
| 70 | break; |
| 71 | case RX51_JACK_HS: |
| 72 | hs = 1; |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 73 | case RX51_JACK_HP: |
| 74 | hp = 1; |
| 75 | break; |
| 76 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 77 | |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 78 | snd_soc_dapm_mutex_lock(dapm); |
| 79 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 80 | if (rx51_spk_func) |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 81 | snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk"); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 82 | else |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 83 | snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk"); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 84 | if (rx51_dmic_func) |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 85 | snd_soc_dapm_enable_pin_unlocked(dapm, "DMic"); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 86 | else |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 87 | snd_soc_dapm_disable_pin_unlocked(dapm, "DMic"); |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 88 | if (hp) |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 89 | snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack"); |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 90 | else |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 91 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack"); |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 92 | if (hs) |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 93 | snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 94 | else |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 95 | snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic"); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 96 | |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 97 | gpiod_set_value(pdata->tvout_selection_gpio, tvout); |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 98 | |
Charles Keepax | 9dd2bb3 | 2014-02-18 15:22:24 +0000 | [diff] [blame] | 99 | snd_soc_dapm_sync_unlocked(dapm); |
| 100 | |
| 101 | snd_soc_dapm_mutex_unlock(dapm); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static 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 Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 108 | struct snd_soc_card *card = rtd->card; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 109 | |
| 110 | snd_pcm_hw_constraint_minmax(runtime, |
| 111 | SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 112 | rx51_ext_control(&card->dapm); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int rx51_hw_params(struct snd_pcm_substream *substream, |
| 118 | struct snd_pcm_hw_params *params) |
| 119 | { |
| 120 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 121 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 122 | |
| 123 | /* Set the codec system clock for DAC and ADC */ |
| 124 | return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000, |
| 125 | SND_SOC_CLOCK_IN); |
| 126 | } |
| 127 | |
| 128 | static struct snd_soc_ops rx51_ops = { |
| 129 | .startup = rx51_startup, |
| 130 | .hw_params = rx51_hw_params, |
| 131 | }; |
| 132 | |
| 133 | static int rx51_get_spk(struct snd_kcontrol *kcontrol, |
| 134 | struct snd_ctl_elem_value *ucontrol) |
| 135 | { |
| 136 | ucontrol->value.integer.value[0] = rx51_spk_func; |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int rx51_set_spk(struct snd_kcontrol *kcontrol, |
| 142 | struct snd_ctl_elem_value *ucontrol) |
| 143 | { |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 144 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 145 | |
| 146 | if (rx51_spk_func == ucontrol->value.integer.value[0]) |
| 147 | return 0; |
| 148 | |
| 149 | rx51_spk_func = ucontrol->value.integer.value[0]; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 150 | rx51_ext_control(&card->dapm); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 151 | |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | static int rx51_spk_event(struct snd_soc_dapm_widget *w, |
| 156 | struct snd_kcontrol *k, int event) |
| 157 | { |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 158 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 159 | struct snd_soc_card *card = dapm->card; |
| 160 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); |
| 161 | |
| 162 | gpiod_set_raw_value_cansleep(pdata->speaker_amp_gpio, |
| 163 | !!SND_SOC_DAPM_EVENT_ON(event)); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 168 | static int rx51_hp_event(struct snd_soc_dapm_widget *w, |
| 169 | struct snd_kcontrol *k, int event) |
| 170 | { |
Lars-Peter Clausen | a761f87 | 2014-09-29 11:40:41 +0200 | [diff] [blame] | 171 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 172 | |
| 173 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 174 | tpa6130a2_stereo_enable(codec, 1); |
| 175 | else |
| 176 | tpa6130a2_stereo_enable(codec, 0); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 181 | static int rx51_get_input(struct snd_kcontrol *kcontrol, |
| 182 | struct snd_ctl_elem_value *ucontrol) |
| 183 | { |
| 184 | ucontrol->value.integer.value[0] = rx51_dmic_func; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static int rx51_set_input(struct snd_kcontrol *kcontrol, |
| 190 | struct snd_ctl_elem_value *ucontrol) |
| 191 | { |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 192 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 193 | |
| 194 | if (rx51_dmic_func == ucontrol->value.integer.value[0]) |
| 195 | return 0; |
| 196 | |
| 197 | rx51_dmic_func = ucontrol->value.integer.value[0]; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 198 | rx51_ext_control(&card->dapm); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 199 | |
| 200 | return 1; |
| 201 | } |
| 202 | |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 203 | static int rx51_get_jack(struct snd_kcontrol *kcontrol, |
| 204 | struct snd_ctl_elem_value *ucontrol) |
| 205 | { |
| 206 | ucontrol->value.integer.value[0] = rx51_jack_func; |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int rx51_set_jack(struct snd_kcontrol *kcontrol, |
| 212 | struct snd_ctl_elem_value *ucontrol) |
| 213 | { |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 214 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 215 | |
| 216 | if (rx51_jack_func == ucontrol->value.integer.value[0]) |
| 217 | return 0; |
| 218 | |
| 219 | rx51_jack_func = ucontrol->value.integer.value[0]; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 220 | rx51_ext_control(&card->dapm); |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 221 | |
| 222 | return 1; |
| 223 | } |
| 224 | |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 225 | static struct snd_soc_jack rx51_av_jack; |
| 226 | |
| 227 | static struct snd_soc_jack_gpio rx51_av_jack_gpios[] = { |
| 228 | { |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 229 | .name = "avdet-gpio", |
Jarkko Nikula | 1784061 | 2011-02-14 17:20:22 +0200 | [diff] [blame] | 230 | .report = SND_JACK_HEADSET, |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 231 | .invert = 1, |
| 232 | .debounce_time = 200, |
| 233 | }, |
| 234 | }; |
| 235 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 236 | static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = { |
| 237 | SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event), |
| 238 | SND_SOC_DAPM_MIC("DMic", NULL), |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 239 | SND_SOC_DAPM_HP("Headphone Jack", rx51_hp_event), |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 240 | SND_SOC_DAPM_MIC("HS Mic", NULL), |
Jarkko Nikula | 9d7e584 | 2011-02-21 14:57:22 +0200 | [diff] [blame] | 241 | SND_SOC_DAPM_LINE("FM Transmitter", NULL), |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 242 | SND_SOC_DAPM_SPK("Earphone", NULL), |
| 243 | }; |
| 244 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 245 | static const struct snd_soc_dapm_route audio_map[] = { |
| 246 | {"Ext Spk", NULL, "HPLOUT"}, |
| 247 | {"Ext Spk", NULL, "HPROUT"}, |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 248 | {"Headphone Jack", NULL, "LLOUT"}, |
| 249 | {"Headphone Jack", NULL, "RLOUT"}, |
Jarkko Nikula | 9d7e584 | 2011-02-21 14:57:22 +0200 | [diff] [blame] | 250 | {"FM Transmitter", NULL, "LLOUT"}, |
| 251 | {"FM Transmitter", NULL, "RLOUT"}, |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 252 | |
Peter Ujfalusi | 2ca087b | 2015-01-30 09:32:43 +0200 | [diff] [blame] | 253 | {"DMic Rate 64", NULL, "DMic"}, |
| 254 | {"DMic", NULL, "Mic Bias"}, |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 255 | |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 256 | {"b LINE2R", NULL, "MONO_LOUT"}, |
| 257 | {"Earphone", NULL, "b HPLOUT"}, |
Jarkko Nikula | 31164c7 | 2011-02-14 17:20:21 +0200 | [diff] [blame] | 258 | |
Peter Ujfalusi | 2ca087b | 2015-01-30 09:32:43 +0200 | [diff] [blame] | 259 | {"LINE1L", NULL, "HS Mic"}, |
| 260 | {"HS Mic", NULL, "b Mic Bias"}, |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 261 | }; |
| 262 | |
Sebastian Reichel | 441dc45 | 2014-04-28 16:07:19 +0200 | [diff] [blame] | 263 | static const char * const spk_function[] = {"Off", "On"}; |
| 264 | static const char * const input_function[] = {"ADC", "Digital Mic"}; |
| 265 | static const char * const jack_function[] = { |
| 266 | "Off", "TV-OUT", "Headphone", "Headset" |
| 267 | }; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 268 | |
| 269 | static const struct soc_enum rx51_enum[] = { |
| 270 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function), |
| 271 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function), |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 272 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function), |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | static const struct snd_kcontrol_new aic34_rx51_controls[] = { |
| 276 | SOC_ENUM_EXT("Speaker Function", rx51_enum[0], |
| 277 | rx51_get_spk, rx51_set_spk), |
| 278 | SOC_ENUM_EXT("Input Select", rx51_enum[1], |
| 279 | rx51_get_input, rx51_set_input), |
Jarkko Nikula | 4eb5470 | 2010-06-21 14:14:59 +0300 | [diff] [blame] | 280 | SOC_ENUM_EXT("Jack Function", rx51_enum[2], |
| 281 | rx51_get_jack, rx51_set_jack), |
Jarkko Nikula | 9d7e584 | 2011-02-21 14:57:22 +0200 | [diff] [blame] | 282 | SOC_DAPM_PIN_SWITCH("FM Transmitter"), |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 283 | SOC_DAPM_PIN_SWITCH("Earphone"), |
| 284 | }; |
| 285 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 286 | static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 287 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 288 | struct snd_soc_codec *codec = rtd->codec; |
Lars-Peter Clausen | 0596f70 | 2014-05-19 11:41:46 +0200 | [diff] [blame] | 289 | struct snd_soc_card *card = rtd->card; |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 290 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); |
| 291 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 292 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 293 | int err; |
| 294 | |
| 295 | /* Set up NC codec pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 296 | snd_soc_dapm_nc_pin(dapm, "MIC3L"); |
| 297 | snd_soc_dapm_nc_pin(dapm, "MIC3R"); |
| 298 | snd_soc_dapm_nc_pin(dapm, "LINE1R"); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 299 | |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 300 | err = tpa6130a2_add_controls(codec); |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 301 | if (err < 0) { |
| 302 | dev_err(card->dev, "Failed to add TPA6130A2 controls\n"); |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 303 | return err; |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 304 | } |
Jarkko Nikula | 48529b3 | 2011-01-27 16:47:11 +0200 | [diff] [blame] | 305 | snd_soc_limit_volume(codec, "TPA6130A2 Headphone Playback Volume", 42); |
| 306 | |
Sebastian Reichel | 0a17a37 | 2014-04-28 16:07:23 +0200 | [diff] [blame] | 307 | err = omap_mcbsp_st_add_controls(rtd, 2); |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 308 | if (err < 0) { |
| 309 | dev_err(card->dev, "Failed to add MCBSP controls\n"); |
Jarkko Nikula | fa4d1f5 | 2011-03-09 11:25:00 +0200 | [diff] [blame] | 310 | return err; |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 311 | } |
Jarkko Nikula | fa4d1f5 | 2011-03-09 11:25:00 +0200 | [diff] [blame] | 312 | |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 313 | /* AV jack detection */ |
Lars-Peter Clausen | 753d45e | 2015-03-04 10:33:28 +0100 | [diff] [blame^] | 314 | err = snd_soc_card_jack_new(rtd->card, "AV Jack", |
| 315 | SND_JACK_HEADSET | SND_JACK_VIDEOOUT, |
| 316 | &rx51_av_jack, NULL, 0); |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 317 | if (err) { |
| 318 | dev_err(card->dev, "Failed to add AV Jack\n"); |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 319 | return err; |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 320 | } |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 321 | |
| 322 | /* prepare gpio for snd_soc_jack_add_gpios */ |
| 323 | rx51_av_jack_gpios[0].gpio = desc_to_gpio(pdata->jack_detection_gpio); |
| 324 | devm_gpiod_put(card->dev, pdata->jack_detection_gpio); |
| 325 | |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 326 | err = snd_soc_jack_add_gpios(&rx51_av_jack, |
| 327 | ARRAY_SIZE(rx51_av_jack_gpios), |
| 328 | rx51_av_jack_gpios); |
Sebastian Reichel | 0265e1a | 2014-04-28 16:07:25 +0200 | [diff] [blame] | 329 | if (err) { |
| 330 | dev_err(card->dev, "Failed to add GPIOs\n"); |
| 331 | return err; |
| 332 | } |
Jarkko Nikula | 8c52311 | 2010-06-21 14:15:00 +0300 | [diff] [blame] | 333 | |
| 334 | return err; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 335 | } |
| 336 | |
Takashi Iwai | 16088cb | 2014-06-03 12:31:46 +0200 | [diff] [blame] | 337 | static int rx51_card_remove(struct snd_soc_card *card) |
Stephen Warren | e1d4d3c | 2014-05-30 12:42:57 -0600 | [diff] [blame] | 338 | { |
| 339 | snd_soc_jack_free_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios), |
| 340 | rx51_av_jack_gpios); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 345 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 346 | static struct snd_soc_dai_link rx51_dai[] = { |
| 347 | { |
| 348 | .name = "TLV320AIC34", |
| 349 | .stream_name = "AIC34", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 350 | .cpu_dai_name = "omap-mcbsp.2", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 351 | .codec_dai_name = "tlv320aic3x-hifi", |
Peter Ujfalusi | aac2514 | 2014-04-16 15:46:28 +0300 | [diff] [blame] | 352 | .platform_name = "omap-mcbsp.2", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 353 | .codec_name = "tlv320aic3x-codec.2-0018", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 354 | .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | |
| 355 | SND_SOC_DAIFMT_CBM_CFM, |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 356 | .init = rx51_aic34_init, |
| 357 | .ops = &rx51_ops, |
| 358 | }, |
| 359 | }; |
| 360 | |
Axel Lin | a0e17b4 | 2011-12-13 10:13:13 +0800 | [diff] [blame] | 361 | static struct snd_soc_aux_dev rx51_aux_dev[] = { |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 362 | { |
| 363 | .name = "TLV320AIC34b", |
| 364 | .codec_name = "tlv320aic3x-codec.2-0019", |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 365 | }, |
| 366 | }; |
| 367 | |
| 368 | static struct snd_soc_codec_conf rx51_codec_conf[] = { |
| 369 | { |
| 370 | .dev_name = "tlv320aic3x-codec.2-0019", |
| 371 | .name_prefix = "b", |
| 372 | }, |
| 373 | }; |
| 374 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 375 | /* Audio card */ |
| 376 | static struct snd_soc_card rx51_sound_card = { |
| 377 | .name = "RX-51", |
Axel Lin | b425b88 | 2011-12-22 11:08:59 +0800 | [diff] [blame] | 378 | .owner = THIS_MODULE, |
Stephen Warren | e1d4d3c | 2014-05-30 12:42:57 -0600 | [diff] [blame] | 379 | .remove = rx51_card_remove, |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 380 | .dai_link = rx51_dai, |
| 381 | .num_links = ARRAY_SIZE(rx51_dai), |
Jarkko Nikula | 8cda975 | 2011-01-31 14:43:48 +0200 | [diff] [blame] | 382 | .aux_dev = rx51_aux_dev, |
| 383 | .num_aux_devs = ARRAY_SIZE(rx51_aux_dev), |
| 384 | .codec_conf = rx51_codec_conf, |
| 385 | .num_configs = ARRAY_SIZE(rx51_codec_conf), |
Lars-Peter Clausen | 81fc5dd | 2014-03-12 15:27:33 +0100 | [diff] [blame] | 386 | |
| 387 | .controls = aic34_rx51_controls, |
| 388 | .num_controls = ARRAY_SIZE(aic34_rx51_controls), |
| 389 | .dapm_widgets = aic34_dapm_widgets, |
| 390 | .num_dapm_widgets = ARRAY_SIZE(aic34_dapm_widgets), |
| 391 | .dapm_routes = audio_map, |
| 392 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 393 | }; |
| 394 | |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 395 | static int rx51_soc_probe(struct platform_device *pdev) |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 396 | { |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 397 | struct rx51_audio_pdata *pdata; |
Sebastian Reichel | d052a3d | 2014-04-28 16:07:26 +0200 | [diff] [blame] | 398 | struct device_node *np = pdev->dev.of_node; |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 399 | struct snd_soc_card *card = &rx51_sound_card; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 400 | int err; |
| 401 | |
Pavel Machek | ea2409b | 2013-07-01 23:15:04 +0200 | [diff] [blame] | 402 | if (!machine_is_nokia_rx51() && !of_machine_is_compatible("nokia,omap3-n900")) |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 403 | return -ENODEV; |
| 404 | |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 405 | card->dev = &pdev->dev; |
| 406 | |
Sebastian Reichel | d052a3d | 2014-04-28 16:07:26 +0200 | [diff] [blame] | 407 | if (np) { |
| 408 | struct device_node *dai_node; |
| 409 | |
| 410 | dai_node = of_parse_phandle(np, "nokia,cpu-dai", 0); |
| 411 | if (!dai_node) { |
| 412 | dev_err(&pdev->dev, "McBSP node is not provided\n"); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | rx51_dai[0].cpu_dai_name = NULL; |
| 416 | rx51_dai[0].platform_name = NULL; |
| 417 | rx51_dai[0].cpu_of_node = dai_node; |
| 418 | rx51_dai[0].platform_of_node = dai_node; |
| 419 | |
| 420 | dai_node = of_parse_phandle(np, "nokia,audio-codec", 0); |
| 421 | if (!dai_node) { |
| 422 | dev_err(&pdev->dev, "Codec node is not provided\n"); |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | rx51_dai[0].codec_name = NULL; |
| 426 | rx51_dai[0].codec_of_node = dai_node; |
| 427 | |
| 428 | dai_node = of_parse_phandle(np, "nokia,audio-codec", 1); |
| 429 | if (!dai_node) { |
| 430 | dev_err(&pdev->dev, "Auxiliary Codec node is not provided\n"); |
| 431 | return -EINVAL; |
| 432 | } |
| 433 | rx51_aux_dev[0].codec_name = NULL; |
| 434 | rx51_aux_dev[0].codec_of_node = dai_node; |
| 435 | rx51_codec_conf[0].dev_name = NULL; |
| 436 | rx51_codec_conf[0].of_node = dai_node; |
| 437 | |
| 438 | dai_node = of_parse_phandle(np, "nokia,headphone-amplifier", 0); |
| 439 | if (!dai_node) { |
| 440 | dev_err(&pdev->dev, "Headphone amplifier node is not provided\n"); |
| 441 | return -EINVAL; |
| 442 | } |
| 443 | |
| 444 | /* TODO: tpa6130a2a driver supports only a single instance, so |
| 445 | * this driver ignores the headphone-amplifier node for now. |
| 446 | * It's already mandatory in the DT binding to be future proof. |
| 447 | */ |
| 448 | } |
| 449 | |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 450 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 451 | if (pdata == NULL) { |
| 452 | dev_err(card->dev, "failed to create private data\n"); |
| 453 | return -ENOMEM; |
| 454 | } |
| 455 | snd_soc_card_set_drvdata(card, pdata); |
| 456 | |
| 457 | pdata->tvout_selection_gpio = devm_gpiod_get(card->dev, |
| 458 | "tvout-selection"); |
| 459 | if (IS_ERR(pdata->tvout_selection_gpio)) { |
| 460 | dev_err(card->dev, "could not get tvout selection gpio\n"); |
| 461 | return PTR_ERR(pdata->tvout_selection_gpio); |
| 462 | } |
| 463 | |
| 464 | err = gpiod_direction_output(pdata->tvout_selection_gpio, 0); |
| 465 | if (err) { |
| 466 | dev_err(card->dev, "could not setup tvout selection gpio\n"); |
| 467 | return err; |
| 468 | } |
| 469 | |
| 470 | pdata->jack_detection_gpio = devm_gpiod_get(card->dev, |
| 471 | "jack-detection"); |
| 472 | if (IS_ERR(pdata->jack_detection_gpio)) { |
| 473 | dev_err(card->dev, "could not get jack detection gpio\n"); |
| 474 | return PTR_ERR(pdata->jack_detection_gpio); |
| 475 | } |
| 476 | |
| 477 | pdata->eci_sw_gpio = devm_gpiod_get(card->dev, "eci-switch"); |
| 478 | if (IS_ERR(pdata->eci_sw_gpio)) { |
| 479 | dev_err(card->dev, "could not get eci switch gpio\n"); |
| 480 | return PTR_ERR(pdata->eci_sw_gpio); |
| 481 | } |
| 482 | |
| 483 | err = gpiod_direction_output(pdata->eci_sw_gpio, 1); |
| 484 | if (err) { |
| 485 | dev_err(card->dev, "could not setup eci switch gpio\n"); |
| 486 | return err; |
| 487 | } |
| 488 | |
| 489 | pdata->speaker_amp_gpio = devm_gpiod_get(card->dev, |
| 490 | "speaker-amplifier"); |
| 491 | if (IS_ERR(pdata->speaker_amp_gpio)) { |
| 492 | dev_err(card->dev, "could not get speaker enable gpio\n"); |
| 493 | return PTR_ERR(pdata->speaker_amp_gpio); |
| 494 | } |
| 495 | |
| 496 | err = gpiod_direction_output(pdata->speaker_amp_gpio, 0); |
| 497 | if (err) { |
| 498 | dev_err(card->dev, "could not setup speaker enable gpio\n"); |
| 499 | return err; |
| 500 | } |
| 501 | |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 502 | err = devm_snd_soc_register_card(card->dev, card); |
| 503 | if (err) { |
| 504 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", err); |
Sebastian Reichel | 386e81a | 2014-04-28 16:07:24 +0200 | [diff] [blame] | 505 | return err; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 506 | } |
| 507 | |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 508 | return 0; |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 509 | } |
| 510 | |
Sebastian Reichel | d052a3d | 2014-04-28 16:07:26 +0200 | [diff] [blame] | 511 | #if defined(CONFIG_OF) |
| 512 | static const struct of_device_id rx51_audio_of_match[] = { |
| 513 | { .compatible = "nokia,n900-audio", }, |
| 514 | {}, |
| 515 | }; |
| 516 | MODULE_DEVICE_TABLE(of, rx51_audio_of_match); |
| 517 | #endif |
| 518 | |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 519 | static struct platform_driver rx51_soc_driver = { |
| 520 | .driver = { |
| 521 | .name = "rx51-audio", |
Sebastian Reichel | d052a3d | 2014-04-28 16:07:26 +0200 | [diff] [blame] | 522 | .of_match_table = of_match_ptr(rx51_audio_of_match), |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 523 | }, |
| 524 | .probe = rx51_soc_probe, |
Sebastian Reichel | a7d5202 | 2014-04-28 16:07:21 +0200 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | module_platform_driver(rx51_soc_driver); |
Jarkko Nikula | 49100c9 | 2010-05-05 11:14:22 +0300 | [diff] [blame] | 528 | |
| 529 | MODULE_AUTHOR("Nokia Corporation"); |
| 530 | MODULE_DESCRIPTION("ALSA SoC Nokia RX-51"); |
| 531 | MODULE_LICENSE("GPL"); |
Sebastian Reichel | beab3da | 2014-04-28 16:07:20 +0200 | [diff] [blame] | 532 | MODULE_ALIAS("platform:rx51-audio"); |