drm: powerpc can use a simpler drm_io_prot()
[linux/fpc-iii.git] / sound / soc / tegra / tegra_alc5632.c
bloba83aff09dce2aa4dbb3755012a07f22ce1de830f
1 /*
2 * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
5 * Copyright (C) 2012 - NVIDIA, Inc.
7 * Authors: Leon Romanovsky <leon@leon.nu>
8 * Andrey Danin <danindrey@mail.ru>
9 * Marc Dietrich <marvin24@gmx.de>
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.
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>
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>
28 #include "../codecs/alc5632.h"
30 #include "tegra_asoc_utils.h"
32 #define DRV_NAME "tegra-alc5632"
34 struct tegra_alc5632 {
35 struct tegra_asoc_utils_data util_data;
36 int gpio_hp_det;
39 static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
43 struct snd_soc_dai *codec_dai = rtd->codec_dai;
44 struct snd_soc_card *card = rtd->card;
45 struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card);
46 int srate, mclk;
47 int err;
49 srate = params_rate(params);
50 mclk = 512 * srate;
52 err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk);
53 if (err < 0) {
54 dev_err(card->dev, "Can't configure clocks\n");
55 return err;
58 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
59 SND_SOC_CLOCK_IN);
60 if (err < 0) {
61 dev_err(card->dev, "codec_dai clock not set\n");
62 return err;
65 return 0;
68 static struct snd_soc_ops tegra_alc5632_asoc_ops = {
69 .hw_params = tegra_alc5632_asoc_hw_params,
72 static struct snd_soc_jack tegra_alc5632_hs_jack;
74 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = {
76 .pin = "Headset Mic",
77 .mask = SND_JACK_MICROPHONE,
80 .pin = "Headset Stereophone",
81 .mask = SND_JACK_HEADPHONE,
85 static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = {
86 .name = "Headset detection",
87 .report = SND_JACK_HEADSET,
88 .debounce_time = 150,
91 static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
92 SND_SOC_DAPM_SPK("Int Spk", NULL),
93 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
94 SND_SOC_DAPM_MIC("Headset Mic", NULL),
95 SND_SOC_DAPM_MIC("Digital Mic", NULL),
98 static const struct snd_kcontrol_new tegra_alc5632_controls[] = {
99 SOC_DAPM_PIN_SWITCH("Int Spk"),
102 static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd)
104 struct snd_soc_dai *codec_dai = rtd->codec_dai;
105 struct snd_soc_codec *codec = codec_dai->codec;
106 struct snd_soc_dapm_context *dapm = &codec->dapm;
107 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(rtd->card);
109 snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
110 &tegra_alc5632_hs_jack);
111 snd_soc_jack_add_pins(&tegra_alc5632_hs_jack,
112 ARRAY_SIZE(tegra_alc5632_hs_jack_pins),
113 tegra_alc5632_hs_jack_pins);
115 if (gpio_is_valid(machine->gpio_hp_det)) {
116 tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det;
117 snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack,
119 &tegra_alc5632_hp_jack_gpio);
122 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
124 return 0;
127 static int tegra_alc5632_card_remove(struct snd_soc_card *card)
129 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
131 if (gpio_is_valid(machine->gpio_hp_det)) {
132 snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack, 1,
133 &tegra_alc5632_hp_jack_gpio);
136 return 0;
139 static struct snd_soc_dai_link tegra_alc5632_dai = {
140 .name = "ALC5632",
141 .stream_name = "ALC5632 PCM",
142 .codec_dai_name = "alc5632-hifi",
143 .init = tegra_alc5632_asoc_init,
144 .ops = &tegra_alc5632_asoc_ops,
145 .dai_fmt = SND_SOC_DAIFMT_I2S
146 | SND_SOC_DAIFMT_NB_NF
147 | SND_SOC_DAIFMT_CBS_CFS,
150 static struct snd_soc_card snd_soc_tegra_alc5632 = {
151 .name = "tegra-alc5632",
152 .owner = THIS_MODULE,
153 .remove = tegra_alc5632_card_remove,
154 .dai_link = &tegra_alc5632_dai,
155 .num_links = 1,
156 .controls = tegra_alc5632_controls,
157 .num_controls = ARRAY_SIZE(tegra_alc5632_controls),
158 .dapm_widgets = tegra_alc5632_dapm_widgets,
159 .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets),
160 .fully_routed = true,
163 static int tegra_alc5632_probe(struct platform_device *pdev)
165 struct device_node *np = pdev->dev.of_node;
166 struct snd_soc_card *card = &snd_soc_tegra_alc5632;
167 struct tegra_alc5632 *alc5632;
168 int ret;
170 alc5632 = devm_kzalloc(&pdev->dev,
171 sizeof(struct tegra_alc5632), GFP_KERNEL);
172 if (!alc5632) {
173 dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n");
174 return -ENOMEM;
177 card->dev = &pdev->dev;
178 platform_set_drvdata(pdev, card);
179 snd_soc_card_set_drvdata(card, alc5632);
181 alc5632->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
182 if (alc5632->gpio_hp_det == -EPROBE_DEFER)
183 return -EPROBE_DEFER;
185 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
186 if (ret)
187 goto err;
189 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
190 if (ret)
191 goto err;
193 tegra_alc5632_dai.codec_of_node = of_parse_phandle(
194 pdev->dev.of_node, "nvidia,audio-codec", 0);
196 if (!tegra_alc5632_dai.codec_of_node) {
197 dev_err(&pdev->dev,
198 "Property 'nvidia,audio-codec' missing or invalid\n");
199 ret = -EINVAL;
200 goto err;
203 tegra_alc5632_dai.cpu_of_node = of_parse_phandle(np,
204 "nvidia,i2s-controller", 0);
205 if (!tegra_alc5632_dai.cpu_of_node) {
206 dev_err(&pdev->dev,
207 "Property 'nvidia,i2s-controller' missing or invalid\n");
208 ret = -EINVAL;
209 goto err;
212 tegra_alc5632_dai.platform_of_node = tegra_alc5632_dai.cpu_of_node;
214 ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev);
215 if (ret)
216 goto err;
218 ret = snd_soc_register_card(card);
219 if (ret) {
220 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
221 ret);
222 goto err_fini_utils;
225 return 0;
227 err_fini_utils:
228 tegra_asoc_utils_fini(&alc5632->util_data);
229 err:
230 return ret;
233 static int tegra_alc5632_remove(struct platform_device *pdev)
235 struct snd_soc_card *card = platform_get_drvdata(pdev);
236 struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card);
238 snd_soc_unregister_card(card);
240 tegra_asoc_utils_fini(&machine->util_data);
242 return 0;
245 static const struct of_device_id tegra_alc5632_of_match[] = {
246 { .compatible = "nvidia,tegra-audio-alc5632", },
250 static struct platform_driver tegra_alc5632_driver = {
251 .driver = {
252 .name = DRV_NAME,
253 .owner = THIS_MODULE,
254 .pm = &snd_soc_pm_ops,
255 .of_match_table = tegra_alc5632_of_match,
257 .probe = tegra_alc5632_probe,
258 .remove = tegra_alc5632_remove,
260 module_platform_driver(tegra_alc5632_driver);
262 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
263 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
264 MODULE_LICENSE("GPL");
265 MODULE_ALIAS("platform:" DRV_NAME);
266 MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match);