Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 2 | /* |
Stephen Warren | aef9a37 | 2012-05-22 16:09:51 -0600 | [diff] [blame] | 3 | * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver |
Stephen Warren | 1ae93b9 | 2012-03-20 14:55:48 -0600 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 6 | * Copyright (C) 2012 - NVIDIA, Inc. |
Stephen Warren | 1ae93b9 | 2012-03-20 14:55:48 -0600 | [diff] [blame] | 7 | * |
| 8 | * Authors: Leon Romanovsky <leon@leon.nu> |
| 9 | * Andrey Danin <danindrey@mail.ru> |
| 10 | * Marc Dietrich <marvin24@gmx.de> |
Stephen Warren | 1ae93b9 | 2012-03-20 14:55:48 -0600 | [diff] [blame] | 11 | */ |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 12 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/gpio.h> |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 17 | #include <linux/of_gpio.h> |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 18 | |
| 19 | #include <sound/core.h> |
| 20 | #include <sound/jack.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | #include <sound/soc.h> |
| 24 | |
| 25 | #include "../codecs/alc5632.h" |
| 26 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 27 | #include "tegra_asoc_utils.h" |
| 28 | |
| 29 | #define DRV_NAME "tegra-alc5632" |
| 30 | |
| 31 | struct tegra_alc5632 { |
| 32 | struct tegra_asoc_utils_data util_data; |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 33 | int gpio_hp_det; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream, |
| 37 | struct snd_pcm_hw_params *params) |
| 38 | { |
| 39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Lars-Peter Clausen | 093c4e5 | 2014-07-17 22:01:06 +0200 | [diff] [blame] | 41 | struct snd_soc_card *card = rtd->card; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 42 | struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card); |
| 43 | int srate, mclk; |
| 44 | int err; |
| 45 | |
| 46 | srate = params_rate(params); |
| 47 | mclk = 512 * srate; |
| 48 | |
| 49 | err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk); |
| 50 | if (err < 0) { |
| 51 | dev_err(card->dev, "Can't configure clocks\n"); |
| 52 | return err; |
| 53 | } |
| 54 | |
| 55 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
| 56 | SND_SOC_CLOCK_IN); |
| 57 | if (err < 0) { |
| 58 | dev_err(card->dev, "codec_dai clock not set\n"); |
| 59 | return err; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Julia Lawall | 8a7a282 | 2016-10-15 16:55:51 +0200 | [diff] [blame] | 65 | static const struct snd_soc_ops tegra_alc5632_asoc_ops = { |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 66 | .hw_params = tegra_alc5632_asoc_hw_params, |
| 67 | }; |
| 68 | |
| 69 | static struct snd_soc_jack tegra_alc5632_hs_jack; |
| 70 | |
| 71 | static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = { |
| 72 | { |
| 73 | .pin = "Headset Mic", |
| 74 | .mask = SND_JACK_MICROPHONE, |
| 75 | }, |
| 76 | { |
| 77 | .pin = "Headset Stereophone", |
| 78 | .mask = SND_JACK_HEADPHONE, |
| 79 | }, |
| 80 | }; |
| 81 | |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 82 | static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = { |
| 83 | .name = "Headset detection", |
| 84 | .report = SND_JACK_HEADSET, |
| 85 | .debounce_time = 150, |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 86 | }; |
| 87 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 88 | static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { |
| 89 | SND_SOC_DAPM_SPK("Int Spk", NULL), |
| 90 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
| 91 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Leon Romanovsky | dd7d3a2 | 2012-02-13 21:27:36 +0200 | [diff] [blame] | 92 | SND_SOC_DAPM_MIC("Digital Mic", NULL), |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 95 | static const struct snd_kcontrol_new tegra_alc5632_controls[] = { |
| 96 | SOC_DAPM_PIN_SWITCH("Int Spk"), |
| 97 | }; |
| 98 | |
| 99 | static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) |
| 100 | { |
Sudip Mukherjee | 319c325 | 2015-12-01 16:09:51 +0530 | [diff] [blame] | 101 | int ret; |
Lars-Peter Clausen | 093c4e5 | 2014-07-17 22:01:06 +0200 | [diff] [blame] | 102 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card); |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 103 | |
Sudip Mukherjee | 319c325 | 2015-12-01 16:09:51 +0530 | [diff] [blame] | 104 | ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", |
| 105 | SND_JACK_HEADSET, |
| 106 | &tegra_alc5632_hs_jack, |
| 107 | tegra_alc5632_hs_jack_pins, |
| 108 | ARRAY_SIZE(tegra_alc5632_hs_jack_pins)); |
| 109 | if (ret) |
| 110 | return ret; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 111 | |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 112 | if (gpio_is_valid(machine->gpio_hp_det)) { |
| 113 | tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; |
| 114 | snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack, |
| 115 | 1, |
| 116 | &tegra_alc5632_hp_jack_gpio); |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Lars-Peter Clausen | 884c0f5 | 2015-04-03 13:04:05 +0200 | [diff] [blame] | 119 | snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "MICBIAS1"); |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 124 | SND_SOC_DAILINK_DEFS(pcm, |
| 125 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
Kuninori Morimoto | bae05f2 | 2019-06-28 10:48:40 +0900 | [diff] [blame] | 126 | DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "alc5632-hifi")), |
| 127 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 128 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 129 | static struct snd_soc_dai_link tegra_alc5632_dai = { |
| 130 | .name = "ALC5632", |
| 131 | .stream_name = "ALC5632 PCM", |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 132 | .init = tegra_alc5632_asoc_init, |
| 133 | .ops = &tegra_alc5632_asoc_ops, |
| 134 | .dai_fmt = SND_SOC_DAIFMT_I2S |
| 135 | | SND_SOC_DAIFMT_NB_NF |
| 136 | | SND_SOC_DAIFMT_CBS_CFS, |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 137 | SND_SOC_DAILINK_REG(pcm), |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static struct snd_soc_card snd_soc_tegra_alc5632 = { |
| 141 | .name = "tegra-alc5632", |
Axel Lin | b16eaf9 | 2011-12-22 21:23:01 +0800 | [diff] [blame] | 142 | .owner = THIS_MODULE, |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 143 | .dai_link = &tegra_alc5632_dai, |
| 144 | .num_links = 1, |
| 145 | .controls = tegra_alc5632_controls, |
| 146 | .num_controls = ARRAY_SIZE(tegra_alc5632_controls), |
| 147 | .dapm_widgets = tegra_alc5632_dapm_widgets, |
| 148 | .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets), |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 149 | .fully_routed = true, |
| 150 | }; |
| 151 | |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 152 | static int tegra_alc5632_probe(struct platform_device *pdev) |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 153 | { |
Stephen Warren | aef9a37 | 2012-05-22 16:09:51 -0600 | [diff] [blame] | 154 | struct device_node *np = pdev->dev.of_node; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 155 | struct snd_soc_card *card = &snd_soc_tegra_alc5632; |
| 156 | struct tegra_alc5632 *alc5632; |
| 157 | int ret; |
| 158 | |
| 159 | alc5632 = devm_kzalloc(&pdev->dev, |
| 160 | sizeof(struct tegra_alc5632), GFP_KERNEL); |
Codrut Grosu | e2c187a | 2017-02-25 13:18:08 +0200 | [diff] [blame] | 161 | if (!alc5632) |
Stephen Warren | f726536 | 2013-02-15 17:07:33 -0700 | [diff] [blame] | 162 | return -ENOMEM; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 163 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 164 | card->dev = &pdev->dev; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 165 | snd_soc_card_set_drvdata(card, alc5632); |
| 166 | |
Stephen Warren | aef9a37 | 2012-05-22 16:09:51 -0600 | [diff] [blame] | 167 | alc5632->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0); |
Roland Stigge | bbfc328 | 2012-06-18 18:42:22 +0200 | [diff] [blame] | 168 | if (alc5632->gpio_hp_det == -EPROBE_DEFER) |
Stephen Warren | aef9a37 | 2012-05-22 16:09:51 -0600 | [diff] [blame] | 169 | return -EPROBE_DEFER; |
| 170 | |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 171 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); |
| 172 | if (ret) |
| 173 | goto err; |
| 174 | |
| 175 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); |
| 176 | if (ret) |
| 177 | goto err; |
| 178 | |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 179 | tegra_alc5632_dai.codecs->of_node = of_parse_phandle( |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 180 | pdev->dev.of_node, "nvidia,audio-codec", 0); |
| 181 | |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 182 | if (!tegra_alc5632_dai.codecs->of_node) { |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 183 | dev_err(&pdev->dev, |
| 184 | "Property 'nvidia,audio-codec' missing or invalid\n"); |
| 185 | ret = -EINVAL; |
| 186 | goto err; |
| 187 | } |
| 188 | |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 189 | tegra_alc5632_dai.cpus->of_node = of_parse_phandle(np, |
Stephen Warren | f726536 | 2013-02-15 17:07:33 -0700 | [diff] [blame] | 190 | "nvidia,i2s-controller", 0); |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 191 | if (!tegra_alc5632_dai.cpus->of_node) { |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 192 | dev_err(&pdev->dev, |
Stephen Warren | f726536 | 2013-02-15 17:07:33 -0700 | [diff] [blame] | 193 | "Property 'nvidia,i2s-controller' missing or invalid\n"); |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 194 | ret = -EINVAL; |
Alexey Khoroshilov | 4321723 | 2018-07-28 00:06:59 +0300 | [diff] [blame] | 195 | goto err_put_codec_of_node; |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Kuninori Morimoto | bae05f2 | 2019-06-28 10:48:40 +0900 | [diff] [blame] | 198 | tegra_alc5632_dai.platforms->of_node = tegra_alc5632_dai.cpus->of_node; |
| 199 | |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 200 | ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); |
| 201 | if (ret) |
Alexey Khoroshilov | 4321723 | 2018-07-28 00:06:59 +0300 | [diff] [blame] | 202 | goto err_put_cpu_of_node; |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 203 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 204 | ret = snd_soc_register_card(card); |
| 205 | if (ret) { |
| 206 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", |
| 207 | ret); |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 208 | goto err_fini_utils; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | return 0; |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 212 | |
| 213 | err_fini_utils: |
| 214 | tegra_asoc_utils_fini(&alc5632->util_data); |
Alexey Khoroshilov | 4321723 | 2018-07-28 00:06:59 +0300 | [diff] [blame] | 215 | err_put_cpu_of_node: |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 216 | of_node_put(tegra_alc5632_dai.cpus->of_node); |
| 217 | tegra_alc5632_dai.cpus->of_node = NULL; |
Kuninori Morimoto | bae05f2 | 2019-06-28 10:48:40 +0900 | [diff] [blame] | 218 | tegra_alc5632_dai.platforms->of_node = NULL; |
Alexey Khoroshilov | 4321723 | 2018-07-28 00:06:59 +0300 | [diff] [blame] | 219 | err_put_codec_of_node: |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 220 | of_node_put(tegra_alc5632_dai.codecs->of_node); |
| 221 | tegra_alc5632_dai.codecs->of_node = NULL; |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 222 | err: |
| 223 | return ret; |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 226 | static int tegra_alc5632_remove(struct platform_device *pdev) |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 227 | { |
| 228 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 229 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card); |
| 230 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 231 | snd_soc_unregister_card(card); |
| 232 | |
Leon Romanovsky | d559f1e | 2012-02-02 22:13:37 +0200 | [diff] [blame] | 233 | tegra_asoc_utils_fini(&machine->util_data); |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 234 | |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 235 | of_node_put(tegra_alc5632_dai.cpus->of_node); |
| 236 | tegra_alc5632_dai.cpus->of_node = NULL; |
Kuninori Morimoto | bae05f2 | 2019-06-28 10:48:40 +0900 | [diff] [blame] | 237 | tegra_alc5632_dai.platforms->of_node = NULL; |
Kuninori Morimoto | af297e6 | 2019-06-06 13:18:46 +0900 | [diff] [blame] | 238 | of_node_put(tegra_alc5632_dai.codecs->of_node); |
| 239 | tegra_alc5632_dai.codecs->of_node = NULL; |
Alexey Khoroshilov | 4321723 | 2018-07-28 00:06:59 +0300 | [diff] [blame] | 240 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Bill Pemberton | f6e6574 | 2012-11-19 13:25:33 -0500 | [diff] [blame] | 244 | static const struct of_device_id tegra_alc5632_of_match[] = { |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 245 | { .compatible = "nvidia,tegra-audio-alc5632", }, |
| 246 | {}, |
| 247 | }; |
| 248 | |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 249 | static struct platform_driver tegra_alc5632_driver = { |
| 250 | .driver = { |
| 251 | .name = DRV_NAME, |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 252 | .pm = &snd_soc_pm_ops, |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 253 | .of_match_table = tegra_alc5632_of_match, |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 254 | }, |
| 255 | .probe = tegra_alc5632_probe, |
Bill Pemberton | 4652a0d | 2012-12-07 09:26:33 -0500 | [diff] [blame] | 256 | .remove = tegra_alc5632_remove, |
Leon Romanovsky | 58783fa | 2011-12-19 21:51:52 +0200 | [diff] [blame] | 257 | }; |
| 258 | module_platform_driver(tegra_alc5632_driver); |
| 259 | |
| 260 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); |
| 261 | MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver"); |
| 262 | MODULE_LICENSE("GPL"); |
| 263 | MODULE_ALIAS("platform:" DRV_NAME); |
Leon Romanovsky | b4dc0a7 | 2012-01-31 09:26:59 +0200 | [diff] [blame] | 264 | MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match); |