Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/sound/soc/tegra/tegra_alc5632.c

  1 /*
  2 * tegra_alc5632.c  --  Toshiba AC100(PAZ00) machine ASoC driver
  3  *
  4  * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
  5  * Copyright (C) 2012 - NVIDIA, Inc.
  6  *
  7  * Authors:  Leon Romanovsky <leon@leon.nu>
  8  *           Andrey Danin <danindrey@mail.ru>
  9  *           Marc Dietrich <marvin24@gmx.de>
 10  *
 11  * This program is free software; you can redistribute it and/or modify
 12  * it under the terms of the GNU General Public License version 2 as
 13  * published by the Free Software Foundation.
 14  */
 15 
 16 #include <linux/module.h>
 17 #include <linux/platform_device.h>
 18 #include <linux/slab.h>
 19 #include <linux/gpio.h>
 20 #include <linux/of_gpio.h>
 21 
 22 #include <sound/core.h>
 23 #include <sound/jack.h>
 24 #include <sound/pcm.h>
 25 #include <sound/pcm_params.h>
 26 #include <sound/soc.h>
 27 
 28 #include "../codecs/alc5632.h"
 29 
 30 #include "tegra_asoc_utils.h"
 31 
 32 #define DRV_NAME "tegra-alc5632"
 33 
 34 struct tegra_alc5632 {
 35         struct tegra_asoc_utils_data util_data;
 36         int gpio_hp_det;
 37 };
 38 
 39 static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream,
 40                                         struct snd_pcm_hw_params *params)
 41 {
 42         struct snd_soc_pcm_runtime *rtd = substream->private_data;
 43         struct snd_soc_dai *codec_dai = rtd->codec_dai;
 44         struct snd_soc_codec *codec = codec_dai->codec;
 45         struct snd_soc_card *card = codec->card;
 46         struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
 47         int srate, mclk;
 48         int err;
 49 
 50         srate = params_rate(params);
 51         mclk = 512 * srate;
 52 
 53         err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk);
 54         if (err < 0) {
 55                 dev_err(card->dev, "Can't configure clocks\n");
 56                 return err;
 57         }
 58 
 59         err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
 60                                         SND_SOC_CLOCK_IN);
 61         if (err < 0) {
 62                 dev_err(card->dev, "codec_dai clock not set\n");
 63                 return err;
 64         }
 65 
 66         return 0;
 67 }
 68 
 69 static struct snd_soc_ops tegra_alc5632_asoc_ops = {
 70         .hw_params = tegra_alc5632_asoc_hw_params,
 71 };
 72 
 73 static struct snd_soc_jack tegra_alc5632_hs_jack;
 74 
 75 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = {
 76         {
 77                 .pin = "Headset Mic",
 78                 .mask = SND_JACK_MICROPHONE,
 79         },
 80         {
 81                 .pin = "Headset Stereophone",
 82                 .mask = SND_JACK_HEADPHONE,
 83         },
 84 };
 85 
 86 static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = {
 87         .name = "Headset detection",
 88         .report = SND_JACK_HEADSET,
 89         .debounce_time = 150,
 90 };
 91 
 92 static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
 93         SND_SOC_DAPM_SPK("Int Spk", NULL),
 94         SND_SOC_DAPM_HP("Headset Stereophone", NULL),
 95         SND_SOC_DAPM_MIC("Headset Mic", NULL),
 96         SND_SOC_DAPM_MIC("Digital Mic", NULL),
 97 };
 98 
 99 static const struct snd_kcontrol_new tegra_alc5632_controls[] = {
100         SOC_DAPM_PIN_SWITCH("Int Spk"),
101 };
102 
103 static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
104 {
105         struct snd_soc_dai *codec_dai = rtd->codec_dai;
106         struct snd_soc_codec *codec = codec_dai->codec;
107         struct snd_soc_dapm_context *dapm = &codec->dapm;
108         struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(codec->card);
109 
110         snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
111                          &tegra_alc5632_hs_jack);
112         snd_soc_jack_add_pins(&tegra_alc5632_hs_jack,
113                         ARRAY_SIZE(tegra_alc5632_hs_jack_pins),
114                         tegra_alc5632_hs_jack_pins);
115 
116         if (gpio_is_valid(machine->gpio_hp_det)) {
117                 tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det;
118                 snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack,
119                                                 1,
120                                                 &tegra_alc5632_hp_jack_gpio);
121         }
122 
123         snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
124 
125         return 0;
126 }
127 
128 static int tegra_alc5632_card_remove(struct snd_soc_card *card)
129 {
130         struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
131 
132         if (gpio_is_valid(machine->gpio_hp_det)) {
133                 snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack, 1,
134                                         &tegra_alc5632_hp_jack_gpio);
135         }
136 
137         return 0;
138 }
139 
140 static struct snd_soc_dai_link tegra_alc5632_dai = {
141         .name = "ALC5632",
142         .stream_name = "ALC5632 PCM",
143         .codec_dai_name = "alc5632-hifi",
144         .init = tegra_alc5632_asoc_init,
145         .ops = &tegra_alc5632_asoc_ops,
146         .dai_fmt = SND_SOC_DAIFMT_I2S
147                            | SND_SOC_DAIFMT_NB_NF
148                            | SND_SOC_DAIFMT_CBS_CFS,
149 };
150 
151 static struct snd_soc_card snd_soc_tegra_alc5632 = {
152         .name = "tegra-alc5632",
153         .owner = THIS_MODULE,
154         .remove = tegra_alc5632_card_remove,
155         .dai_link = &tegra_alc5632_dai,
156         .num_links = 1,
157         .controls = tegra_alc5632_controls,
158         .num_controls = ARRAY_SIZE(tegra_alc5632_controls),
159         .dapm_widgets = tegra_alc5632_dapm_widgets,
160         .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets),
161         .fully_routed = true,
162 };
163 
164 static int tegra_alc5632_probe(struct platform_device *pdev)
165 {
166         struct device_node *np = pdev->dev.of_node;
167         struct snd_soc_card *card = &snd_soc_tegra_alc5632;
168         struct tegra_alc5632 *alc5632;
169         int ret;
170 
171         alc5632 = devm_kzalloc(&pdev->dev,
172                         sizeof(struct tegra_alc5632), GFP_KERNEL);
173         if (!alc5632) {
174                 dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n");
175                 return -ENOMEM;
176         }
177 
178         card->dev = &pdev->dev;
179         platform_set_drvdata(pdev, card);
180         snd_soc_card_set_drvdata(card, alc5632);
181 
182         alc5632->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
183         if (alc5632->gpio_hp_det == -EPROBE_DEFER)
184                 return -EPROBE_DEFER;
185 
186         ret = snd_soc_of_parse_card_name(card, "nvidia,model");
187         if (ret)
188                 goto err;
189 
190         ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
191         if (ret)
192                 goto err;
193 
194         tegra_alc5632_dai.codec_of_node = of_parse_phandle(
195                         pdev->dev.of_node, "nvidia,audio-codec", 0);
196 
197         if (!tegra_alc5632_dai.codec_of_node) {
198                 dev_err(&pdev->dev,
199                         "Property 'nvidia,audio-codec' missing or invalid\n");
200                 ret = -EINVAL;
201                 goto err;
202         }
203 
204         tegra_alc5632_dai.cpu_of_node = of_parse_phandle(np,
205                         "nvidia,i2s-controller", 0);
206         if (!tegra_alc5632_dai.cpu_of_node) {
207                 dev_err(&pdev->dev,
208                         "Property 'nvidia,i2s-controller' missing or invalid\n");
209                 ret = -EINVAL;
210                 goto err;
211         }
212 
213         tegra_alc5632_dai.platform_of_node = tegra_alc5632_dai.cpu_of_node;
214 
215         ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
216         if (ret)
217                 goto err;
218 
219         ret = snd_soc_register_card(card);
220         if (ret) {
221                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
222                         ret);
223                 goto err_fini_utils;
224         }
225 
226         return 0;
227 
228 err_fini_utils:
229         tegra_asoc_utils_fini(&alc5632->util_data);
230 err:
231         return ret;
232 }
233 
234 static int tegra_alc5632_remove(struct platform_device *pdev)
235 {
236         struct snd_soc_card *card = platform_get_drvdata(pdev);
237         struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
238 
239         snd_soc_unregister_card(card);
240 
241         tegra_asoc_utils_fini(&machine->util_data);
242 
243         return 0;
244 }
245 
246 static const struct of_device_id tegra_alc5632_of_match[] = {
247         { .compatible = "nvidia,tegra-audio-alc5632", },
248         {},
249 };
250 
251 static struct platform_driver tegra_alc5632_driver = {
252         .driver = {
253                 .name = DRV_NAME,
254                 .owner = THIS_MODULE,
255                 .pm = &snd_soc_pm_ops,
256                 .of_match_table = tegra_alc5632_of_match,
257         },
258         .probe = tegra_alc5632_probe,
259         .remove = tegra_alc5632_remove,
260 };
261 module_platform_driver(tegra_alc5632_driver);
262 
263 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
264 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
265 MODULE_LICENSE("GPL");
266 MODULE_ALIAS("platform:" DRV_NAME);
267 MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match);
268 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us