Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 1 | /* |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 2 | * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec. |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 3 | * |
| 4 | * Author: Stephen Warren <swarren@nvidia.com> |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 5 | * Copyright (C) 2010-2012 - NVIDIA, Inc. |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 6 | * |
| 7 | * Based on code copyright/by: |
| 8 | * |
| 9 | * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd. |
| 10 | * |
| 11 | * Copyright 2007 Wolfson Microelectronics PLC. |
| 12 | * Author: Graeme Gregory |
| 13 | * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * version 2 as published by the Free Software Foundation. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, but |
| 20 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | * General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 27 | * 02110-1301 USA |
| 28 | * |
| 29 | */ |
| 30 | |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/slab.h> |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 34 | #include <linux/gpio.h> |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 35 | #include <linux/of_gpio.h> |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 36 | |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 37 | #include <sound/core.h> |
Stephen Warren | f7d3e40 | 2011-02-03 13:56:13 -0700 | [diff] [blame] | 38 | #include <sound/jack.h> |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 39 | #include <sound/pcm.h> |
| 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> |
| 42 | |
Stephen Warren | 41b5f9b | 2011-02-10 15:37:16 -0700 | [diff] [blame] | 43 | #include "../codecs/wm8903.h" |
| 44 | |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 45 | #include "tegra_asoc_utils.h" |
| 46 | |
Stephen Warren | 7b33af2 | 2011-04-12 11:29:00 -0600 | [diff] [blame] | 47 | #define DRV_NAME "tegra-snd-wm8903" |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 48 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 49 | struct tegra_wm8903 { |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 50 | int gpio_spkr_en; |
| 51 | int gpio_hp_det; |
| 52 | int gpio_hp_mute; |
| 53 | int gpio_int_mic_en; |
| 54 | int gpio_ext_mic_en; |
Stephen Warren | d64e57c | 2011-01-28 14:26:40 -0700 | [diff] [blame] | 55 | struct tegra_asoc_utils_data util_data; |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 56 | }; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 57 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 58 | static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream, |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 59 | struct snd_pcm_hw_params *params) |
| 60 | { |
| 61 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 62 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Lars-Peter Clausen | 093c4e5 | 2014-07-17 22:01:06 +0200 | [diff] [blame] | 63 | struct snd_soc_card *card = rtd->card; |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 64 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
Stephen Warren | 0754139 | 2011-04-19 15:25:09 -0600 | [diff] [blame] | 65 | int srate, mclk; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 66 | int err; |
| 67 | |
| 68 | srate = params_rate(params); |
| 69 | switch (srate) { |
| 70 | case 64000: |
| 71 | case 88200: |
| 72 | case 96000: |
| 73 | mclk = 128 * srate; |
| 74 | break; |
| 75 | default: |
| 76 | mclk = 256 * srate; |
| 77 | break; |
| 78 | } |
| 79 | /* FIXME: Codec only requires >= 3MHz if OSR==0 */ |
| 80 | while (mclk < 6000000) |
| 81 | mclk *= 2; |
| 82 | |
Stephen Warren | 0754139 | 2011-04-19 15:25:09 -0600 | [diff] [blame] | 83 | err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk); |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 84 | if (err < 0) { |
Stephen Warren | c244d47 | 2011-01-28 14:26:39 -0700 | [diff] [blame] | 85 | dev_err(card->dev, "Can't configure clocks\n"); |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 86 | return err; |
| 87 | } |
| 88 | |
Stephen Warren | 0754139 | 2011-04-19 15:25:09 -0600 | [diff] [blame] | 89 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
| 90 | SND_SOC_CLOCK_IN); |
| 91 | if (err < 0) { |
| 92 | dev_err(card->dev, "codec_dai clock not set\n"); |
| 93 | return err; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 99 | static struct snd_soc_ops tegra_wm8903_ops = { |
| 100 | .hw_params = tegra_wm8903_hw_params, |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 103 | static struct snd_soc_jack tegra_wm8903_hp_jack; |
Stephen Warren | f7d3e40 | 2011-02-03 13:56:13 -0700 | [diff] [blame] | 104 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 105 | static struct snd_soc_jack_pin tegra_wm8903_hp_jack_pins[] = { |
Stephen Warren | f7d3e40 | 2011-02-03 13:56:13 -0700 | [diff] [blame] | 106 | { |
| 107 | .pin = "Headphone Jack", |
| 108 | .mask = SND_JACK_HEADPHONE, |
| 109 | }, |
| 110 | }; |
| 111 | |
Stephen Warren | 3eb25f9 | 2011-04-12 11:40:38 -0600 | [diff] [blame] | 112 | static struct snd_soc_jack_gpio tegra_wm8903_hp_jack_gpio = { |
| 113 | .name = "headphone detect", |
| 114 | .report = SND_JACK_HEADPHONE, |
| 115 | .debounce_time = 150, |
| 116 | .invert = 1, |
Stephen Warren | f7d3e40 | 2011-02-03 13:56:13 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 119 | static struct snd_soc_jack tegra_wm8903_mic_jack; |
Stephen Warren | 41b5f9b | 2011-02-10 15:37:16 -0700 | [diff] [blame] | 120 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 121 | static struct snd_soc_jack_pin tegra_wm8903_mic_jack_pins[] = { |
Stephen Warren | 41b5f9b | 2011-02-10 15:37:16 -0700 | [diff] [blame] | 122 | { |
| 123 | .pin = "Mic Jack", |
| 124 | .mask = SND_JACK_MICROPHONE, |
| 125 | }, |
| 126 | }; |
| 127 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 128 | static int tegra_wm8903_event_int_spk(struct snd_soc_dapm_widget *w, |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 129 | struct snd_kcontrol *k, int event) |
| 130 | { |
Stephen Warren | a32955d | 2011-04-19 15:25:10 -0600 | [diff] [blame] | 131 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 132 | struct snd_soc_card *card = dapm->card; |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 133 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 134 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 135 | if (!gpio_is_valid(machine->gpio_spkr_en)) |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 136 | return 0; |
| 137 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 138 | gpio_set_value_cansleep(machine->gpio_spkr_en, |
Stephen Warren | f9eabc3 | 2011-01-31 11:00:17 -0700 | [diff] [blame] | 139 | SND_SOC_DAPM_EVENT_ON(event)); |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 144 | static int tegra_wm8903_event_hp(struct snd_soc_dapm_widget *w, |
| 145 | struct snd_kcontrol *k, int event) |
| 146 | { |
Stephen Warren | a32955d | 2011-04-19 15:25:10 -0600 | [diff] [blame] | 147 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 148 | struct snd_soc_card *card = dapm->card; |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 149 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 150 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 151 | if (!gpio_is_valid(machine->gpio_hp_mute)) |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 152 | return 0; |
| 153 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 154 | gpio_set_value_cansleep(machine->gpio_hp_mute, |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 155 | !SND_SOC_DAPM_EVENT_ON(event)); |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 160 | static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = { |
| 161 | SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk), |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 162 | SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp), |
Stephen Warren | 62ffac4 | 2011-01-13 15:22:08 -0700 | [diff] [blame] | 163 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 164 | }; |
| 165 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 166 | static const struct snd_kcontrol_new tegra_wm8903_controls[] = { |
Stephen Warren | 3d8bc39 | 2011-02-03 13:56:14 -0700 | [diff] [blame] | 167 | SOC_DAPM_PIN_SWITCH("Int Spk"), |
| 168 | }; |
| 169 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 170 | static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd) |
Stephen Warren | 62ffac4 | 2011-01-13 15:22:08 -0700 | [diff] [blame] | 171 | { |
Stephen Warren | 40db77a | 2012-06-06 17:15:49 -0600 | [diff] [blame] | 172 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 173 | struct snd_soc_codec *codec = codec_dai->codec; |
Stephen Warren | 62ffac4 | 2011-01-13 15:22:08 -0700 | [diff] [blame] | 174 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lars-Peter Clausen | 093c4e5 | 2014-07-17 22:01:06 +0200 | [diff] [blame] | 175 | struct snd_soc_card *card = rtd->card; |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 176 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
Stephen Warren | bf1b132 | 2011-02-10 15:37:18 -0700 | [diff] [blame] | 177 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 178 | if (gpio_is_valid(machine->gpio_hp_det)) { |
| 179 | tegra_wm8903_hp_jack_gpio.gpio = machine->gpio_hp_det; |
Lars-Peter Clausen | 7ba8cbb | 2015-03-04 10:33:44 +0100 | [diff] [blame] | 180 | snd_soc_card_jack_new(rtd->card, "Headphone Jack", |
| 181 | SND_JACK_HEADPHONE, &tegra_wm8903_hp_jack, |
| 182 | tegra_wm8903_hp_jack_pins, |
| 183 | ARRAY_SIZE(tegra_wm8903_hp_jack_pins)); |
Stephen Warren | 773b1d3 | 2011-04-12 11:40:39 -0600 | [diff] [blame] | 184 | snd_soc_jack_add_gpios(&tegra_wm8903_hp_jack, |
| 185 | 1, |
| 186 | &tegra_wm8903_hp_jack_gpio); |
| 187 | } |
Stephen Warren | f7d3e40 | 2011-02-03 13:56:13 -0700 | [diff] [blame] | 188 | |
Lars-Peter Clausen | 7ba8cbb | 2015-03-04 10:33:44 +0100 | [diff] [blame] | 189 | snd_soc_card_jack_new(rtd->card, "Mic Jack", SND_JACK_MICROPHONE, |
| 190 | &tegra_wm8903_mic_jack, |
| 191 | tegra_wm8903_mic_jack_pins, |
| 192 | ARRAY_SIZE(tegra_wm8903_mic_jack_pins)); |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 193 | wm8903_mic_detect(codec, &tegra_wm8903_mic_jack, SND_JACK_MICROPHONE, |
| 194 | 0); |
Stephen Warren | 41b5f9b | 2011-02-10 15:37:16 -0700 | [diff] [blame] | 195 | |
Mark Brown | 5032dc3 | 2011-11-27 12:20:08 +0000 | [diff] [blame] | 196 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS"); |
Stephen Warren | 41b5f9b | 2011-02-10 15:37:16 -0700 | [diff] [blame] | 197 | |
Stephen Warren | 62ffac4 | 2011-01-13 15:22:08 -0700 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
Stephen Warren | 3419ae7 | 2012-06-11 11:27:19 -0600 | [diff] [blame] | 201 | static int tegra_wm8903_remove(struct snd_soc_card *card) |
| 202 | { |
| 203 | struct snd_soc_pcm_runtime *rtd = &(card->rtd[0]); |
| 204 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 205 | struct snd_soc_codec *codec = codec_dai->codec; |
Stephen Warren | fb6b8e7 | 2014-05-22 16:14:53 -0600 | [diff] [blame] | 206 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
| 207 | |
| 208 | if (gpio_is_valid(machine->gpio_hp_det)) { |
| 209 | snd_soc_jack_free_gpios(&tegra_wm8903_hp_jack, 1, |
| 210 | &tegra_wm8903_hp_jack_gpio); |
| 211 | } |
Stephen Warren | 3419ae7 | 2012-06-11 11:27:19 -0600 | [diff] [blame] | 212 | |
| 213 | wm8903_mic_detect(codec, NULL, 0, 0); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 218 | static struct snd_soc_dai_link tegra_wm8903_dai = { |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 219 | .name = "WM8903", |
| 220 | .stream_name = "WM8903 PCM", |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 221 | .codec_dai_name = "wm8903-hifi", |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 222 | .init = tegra_wm8903_init, |
| 223 | .ops = &tegra_wm8903_ops, |
Stephen Warren | 408dafc | 2012-06-06 17:15:48 -0600 | [diff] [blame] | 224 | .dai_fmt = SND_SOC_DAIFMT_I2S | |
| 225 | SND_SOC_DAIFMT_NB_NF | |
| 226 | SND_SOC_DAIFMT_CBS_CFS, |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 229 | static struct snd_soc_card snd_soc_tegra_wm8903 = { |
| 230 | .name = "tegra-wm8903", |
Axel Lin | b16eaf9 | 2011-12-22 21:23:01 +0800 | [diff] [blame] | 231 | .owner = THIS_MODULE, |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 232 | .dai_link = &tegra_wm8903_dai, |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 233 | .num_links = 1, |
Stephen Warren | 3419ae7 | 2012-06-11 11:27:19 -0600 | [diff] [blame] | 234 | .remove = tegra_wm8903_remove, |
Stephen Warren | dea8b6e | 2011-04-19 15:25:12 -0600 | [diff] [blame] | 235 | .controls = tegra_wm8903_controls, |
| 236 | .num_controls = ARRAY_SIZE(tegra_wm8903_controls), |
| 237 | .dapm_widgets = tegra_wm8903_dapm_widgets, |
| 238 | .num_dapm_widgets = ARRAY_SIZE(tegra_wm8903_dapm_widgets), |
Stephen Warren | 6e5fdba | 2011-11-23 12:42:05 -0700 | [diff] [blame] | 239 | .fully_routed = true, |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 242 | static int tegra_wm8903_driver_probe(struct platform_device *pdev) |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 243 | { |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 244 | struct device_node *np = pdev->dev.of_node; |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 245 | struct snd_soc_card *card = &snd_soc_tegra_wm8903; |
| 246 | struct tegra_wm8903 *machine; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 247 | int ret; |
| 248 | |
Stephen Warren | e4e4c18 | 2011-11-22 18:21:20 -0700 | [diff] [blame] | 249 | machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8903), |
| 250 | GFP_KERNEL); |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 251 | if (!machine) { |
| 252 | dev_err(&pdev->dev, "Can't allocate tegra_wm8903 struct\n"); |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 253 | return -ENOMEM; |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 254 | } |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 255 | |
| 256 | card->dev = &pdev->dev; |
| 257 | platform_set_drvdata(pdev, card); |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 258 | snd_soc_card_set_drvdata(card, machine); |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 259 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 260 | machine->gpio_spkr_en = of_get_named_gpio(np, "nvidia,spkr-en-gpios", |
| 261 | 0); |
| 262 | if (machine->gpio_spkr_en == -EPROBE_DEFER) |
| 263 | return -EPROBE_DEFER; |
| 264 | if (gpio_is_valid(machine->gpio_spkr_en)) { |
| 265 | ret = devm_gpio_request_one(&pdev->dev, machine->gpio_spkr_en, |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 266 | GPIOF_OUT_INIT_LOW, "spkr_en"); |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 267 | if (ret) { |
| 268 | dev_err(card->dev, "cannot get spkr_en gpio\n"); |
| 269 | return ret; |
| 270 | } |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 271 | } |
| 272 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 273 | machine->gpio_hp_mute = of_get_named_gpio(np, "nvidia,hp-mute-gpios", |
| 274 | 0); |
| 275 | if (machine->gpio_hp_mute == -EPROBE_DEFER) |
| 276 | return -EPROBE_DEFER; |
| 277 | if (gpio_is_valid(machine->gpio_hp_mute)) { |
| 278 | ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_mute, |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 279 | GPIOF_OUT_INIT_HIGH, "hp_mute"); |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 280 | if (ret) { |
| 281 | dev_err(card->dev, "cannot get hp_mute gpio\n"); |
| 282 | return ret; |
| 283 | } |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 284 | } |
| 285 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 286 | machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0); |
| 287 | if (machine->gpio_hp_det == -EPROBE_DEFER) |
| 288 | return -EPROBE_DEFER; |
| 289 | |
| 290 | machine->gpio_int_mic_en = of_get_named_gpio(np, |
| 291 | "nvidia,int-mic-en-gpios", 0); |
| 292 | if (machine->gpio_int_mic_en == -EPROBE_DEFER) |
| 293 | return -EPROBE_DEFER; |
| 294 | if (gpio_is_valid(machine->gpio_int_mic_en)) { |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 295 | /* Disable int mic; enable signal is active-high */ |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 296 | ret = devm_gpio_request_one(&pdev->dev, |
| 297 | machine->gpio_int_mic_en, |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 298 | GPIOF_OUT_INIT_LOW, "int_mic_en"); |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 299 | if (ret) { |
| 300 | dev_err(card->dev, "cannot get int_mic_en gpio\n"); |
| 301 | return ret; |
| 302 | } |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 303 | } |
| 304 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 305 | machine->gpio_ext_mic_en = of_get_named_gpio(np, |
| 306 | "nvidia,ext-mic-en-gpios", 0); |
| 307 | if (machine->gpio_ext_mic_en == -EPROBE_DEFER) |
| 308 | return -EPROBE_DEFER; |
| 309 | if (gpio_is_valid(machine->gpio_ext_mic_en)) { |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 310 | /* Enable ext mic; enable signal is active-low */ |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 311 | ret = devm_gpio_request_one(&pdev->dev, |
| 312 | machine->gpio_ext_mic_en, |
Stephen Warren | e2d287c | 2012-05-22 16:08:55 -0600 | [diff] [blame] | 313 | GPIOF_OUT_INIT_LOW, "ext_mic_en"); |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 314 | if (ret) { |
| 315 | dev_err(card->dev, "cannot get ext_mic_en gpio\n"); |
| 316 | return ret; |
| 317 | } |
Stephen Warren | f51022f | 2012-05-22 16:08:54 -0600 | [diff] [blame] | 318 | } |
| 319 | |
Stephen Warren | 8f5f5e0 | 2013-02-15 17:07:35 -0700 | [diff] [blame] | 320 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); |
| 321 | if (ret) |
| 322 | goto err; |
| 323 | |
| 324 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); |
| 325 | if (ret) |
| 326 | goto err; |
| 327 | |
| 328 | tegra_wm8903_dai.codec_of_node = of_parse_phandle(np, |
| 329 | "nvidia,audio-codec", 0); |
| 330 | if (!tegra_wm8903_dai.codec_of_node) { |
| 331 | dev_err(&pdev->dev, |
| 332 | "Property 'nvidia,audio-codec' missing or invalid\n"); |
| 333 | ret = -EINVAL; |
| 334 | goto err; |
| 335 | } |
| 336 | |
| 337 | tegra_wm8903_dai.cpu_of_node = of_parse_phandle(np, |
| 338 | "nvidia,i2s-controller", 0); |
| 339 | if (!tegra_wm8903_dai.cpu_of_node) { |
| 340 | dev_err(&pdev->dev, |
| 341 | "Property 'nvidia,i2s-controller' missing or invalid\n"); |
| 342 | ret = -EINVAL; |
| 343 | goto err; |
| 344 | } |
| 345 | |
| 346 | tegra_wm8903_dai.platform_of_node = tegra_wm8903_dai.cpu_of_node; |
| 347 | |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 348 | ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); |
| 349 | if (ret) |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 350 | goto err; |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 351 | |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 352 | ret = snd_soc_register_card(card); |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 353 | if (ret) { |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 354 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 355 | ret); |
Stephen Warren | acb8303 | 2011-04-19 15:25:08 -0600 | [diff] [blame] | 356 | goto err_fini_utils; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | return 0; |
| 360 | |
Stephen Warren | acb8303 | 2011-04-19 15:25:08 -0600 | [diff] [blame] | 361 | err_fini_utils: |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 362 | tegra_asoc_utils_fini(&machine->util_data); |
Stephen Warren | e4e4c18 | 2011-11-22 18:21:20 -0700 | [diff] [blame] | 363 | err: |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 364 | return ret; |
| 365 | } |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 366 | |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 367 | static int tegra_wm8903_driver_remove(struct platform_device *pdev) |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 368 | { |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 369 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 370 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 371 | |
Stephen Warren | 29591ed | 2011-08-04 16:44:43 -0600 | [diff] [blame] | 372 | snd_soc_unregister_card(card); |
| 373 | |
| 374 | tegra_asoc_utils_fini(&machine->util_data); |
Stephen Warren | 6e26764 | 2011-01-28 14:26:37 -0700 | [diff] [blame] | 375 | |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 376 | return 0; |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 377 | } |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 378 | |
Bill Pemberton | f6e6574 | 2012-11-19 13:25:33 -0500 | [diff] [blame] | 379 | static const struct of_device_id tegra_wm8903_of_match[] = { |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 380 | { .compatible = "nvidia,tegra-audio-wm8903", }, |
| 381 | {}, |
| 382 | }; |
| 383 | |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 384 | static struct platform_driver tegra_wm8903_driver = { |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 385 | .driver = { |
| 386 | .name = DRV_NAME, |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 387 | .pm = &snd_soc_pm_ops, |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 388 | .of_match_table = tegra_wm8903_of_match, |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 389 | }, |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 390 | .probe = tegra_wm8903_driver_probe, |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 391 | .remove = tegra_wm8903_driver_remove, |
Stephen Warren | 72de2b1 | 2011-01-28 14:26:36 -0700 | [diff] [blame] | 392 | }; |
Stephen Warren | e4e4c18 | 2011-11-22 18:21:20 -0700 | [diff] [blame] | 393 | module_platform_driver(tegra_wm8903_driver); |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 394 | |
| 395 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); |
Stephen Warren | dc0a50af | 2011-04-12 11:40:36 -0600 | [diff] [blame] | 396 | MODULE_DESCRIPTION("Tegra+WM8903 machine ASoC driver"); |
Stephen Warren | a8bf1ba | 2011-01-07 22:36:16 -0700 | [diff] [blame] | 397 | MODULE_LICENSE("GPL"); |
Stephen Warren | 8eb3420 | 2011-02-10 15:37:19 -0700 | [diff] [blame] | 398 | MODULE_ALIAS("platform:" DRV_NAME); |
Stephen Warren | 07cdf36 | 2011-12-12 15:55:36 -0700 | [diff] [blame] | 399 | MODULE_DEVICE_TABLE(of, tegra_wm8903_of_match); |