~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/tegra/tegra_alc5632.c

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3 * tegra_alc5632.c  --  Toshiba AC100(PAZ00) machine ASoC driver
  4  *
  5  * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
  6  * Copyright (C) 2012 - NVIDIA, Inc.
  7  *
  8  * Authors:  Leon Romanovsky <leon@leon.nu>
  9  *           Andrey Danin <danindrey@mail.ru>
 10  *           Marc Dietrich <marvin24@gmx.de>
 11  */
 12 
 13 #include <linux/module.h>
 14 #include <linux/platform_device.h>
 15 #include <linux/slab.h>
 16 #include <linux/gpio.h>
 17 #include <linux/of_gpio.h>
 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 
 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;
 33         int gpio_hp_det;
 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;
 41         struct snd_soc_card *card = rtd->card;
 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 
 65 static const struct snd_soc_ops tegra_alc5632_asoc_ops = {
 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 
 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,
 86 };
 87 
 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),
 92         SND_SOC_DAPM_MIC("Digital Mic", NULL),
 93 };
 94 
 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 {
101         int ret;
102         struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card);
103 
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;
111 
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);
117         }
118 
119         snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "MICBIAS1");
120 
121         return 0;
122 }
123 
124 SND_SOC_DAILINK_DEFS(pcm,
125         DAILINK_COMP_ARRAY(COMP_EMPTY()),
126         DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "alc5632-hifi")),
127         DAILINK_COMP_ARRAY(COMP_EMPTY()));
128 
129 static struct snd_soc_dai_link tegra_alc5632_dai = {
130         .name = "ALC5632",
131         .stream_name = "ALC5632 PCM",
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,
137         SND_SOC_DAILINK_REG(pcm),
138 };
139 
140 static struct snd_soc_card snd_soc_tegra_alc5632 = {
141         .name = "tegra-alc5632",
142         .owner = THIS_MODULE,
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),
149         .fully_routed = true,
150 };
151 
152 static int tegra_alc5632_probe(struct platform_device *pdev)
153 {
154         struct device_node *np = pdev->dev.of_node;
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);
161         if (!alc5632)
162                 return -ENOMEM;
163 
164         card->dev = &pdev->dev;
165         snd_soc_card_set_drvdata(card, alc5632);
166 
167         alc5632->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
168         if (alc5632->gpio_hp_det == -EPROBE_DEFER)
169                 return -EPROBE_DEFER;
170 
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 
179         tegra_alc5632_dai.codecs->of_node = of_parse_phandle(
180                         pdev->dev.of_node, "nvidia,audio-codec", 0);
181 
182         if (!tegra_alc5632_dai.codecs->of_node) {
183                 dev_err(&pdev->dev,
184                         "Property 'nvidia,audio-codec' missing or invalid\n");
185                 ret = -EINVAL;
186                 goto err;
187         }
188 
189         tegra_alc5632_dai.cpus->of_node = of_parse_phandle(np,
190                         "nvidia,i2s-controller", 0);
191         if (!tegra_alc5632_dai.cpus->of_node) {
192                 dev_err(&pdev->dev,
193                         "Property 'nvidia,i2s-controller' missing or invalid\n");
194                 ret = -EINVAL;
195                 goto err_put_codec_of_node;
196         }
197 
198         tegra_alc5632_dai.platforms->of_node = tegra_alc5632_dai.cpus->of_node;
199 
200         ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
201         if (ret)
202                 goto err_put_cpu_of_node;
203 
204         ret = snd_soc_register_card(card);
205         if (ret) {
206                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
207                         ret);
208                 goto err_fini_utils;
209         }
210 
211         return 0;
212 
213 err_fini_utils:
214         tegra_asoc_utils_fini(&alc5632->util_data);
215 err_put_cpu_of_node:
216         of_node_put(tegra_alc5632_dai.cpus->of_node);
217         tegra_alc5632_dai.cpus->of_node = NULL;
218         tegra_alc5632_dai.platforms->of_node = NULL;
219 err_put_codec_of_node:
220         of_node_put(tegra_alc5632_dai.codecs->of_node);
221         tegra_alc5632_dai.codecs->of_node = NULL;
222 err:
223         return ret;
224 }
225 
226 static int tegra_alc5632_remove(struct platform_device *pdev)
227 {
228         struct snd_soc_card *card = platform_get_drvdata(pdev);
229         struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
230 
231         snd_soc_unregister_card(card);
232 
233         tegra_asoc_utils_fini(&machine->util_data);
234 
235         of_node_put(tegra_alc5632_dai.cpus->of_node);
236         tegra_alc5632_dai.cpus->of_node = NULL;
237         tegra_alc5632_dai.platforms->of_node = NULL;
238         of_node_put(tegra_alc5632_dai.codecs->of_node);
239         tegra_alc5632_dai.codecs->of_node = NULL;
240 
241         return 0;
242 }
243 
244 static const struct of_device_id tegra_alc5632_of_match[] = {
245         { .compatible = "nvidia,tegra-audio-alc5632", },
246         {},
247 };
248 
249 static struct platform_driver tegra_alc5632_driver = {
250         .driver = {
251                 .name = DRV_NAME,
252                 .pm = &snd_soc_pm_ops,
253                 .of_match_table = tegra_alc5632_of_match,
254         },
255         .probe = tegra_alc5632_probe,
256         .remove = tegra_alc5632_remove,
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);
264 MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match);
265 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp