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
;
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_codec
*codec
= codec_dai
->codec
;
45 struct snd_soc_card
*card
= codec
->card
;
46 struct tegra_alc5632
*alc5632
= snd_soc_card_get_drvdata(card
);
50 srate
= params_rate(params
);
53 err
= tegra_asoc_utils_set_rate(&alc5632
->util_data
, srate
, mclk
);
55 dev_err(card
->dev
, "Can't configure clocks\n");
59 err
= snd_soc_dai_set_sysclk(codec_dai
, 0, mclk
,
62 dev_err(card
->dev
, "codec_dai clock not set\n");
69 static struct snd_soc_ops tegra_alc5632_asoc_ops
= {
70 .hw_params
= tegra_alc5632_asoc_hw_params
,
73 static struct snd_soc_jack tegra_alc5632_hs_jack
;
75 static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins
[] = {
78 .mask
= SND_JACK_MICROPHONE
,
81 .pin
= "Headset Stereophone",
82 .mask
= SND_JACK_HEADPHONE
,
86 static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio
= {
87 .name
= "Headset detection",
88 .report
= SND_JACK_HEADSET
,
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
),
99 static const struct snd_kcontrol_new tegra_alc5632_controls
[] = {
100 SOC_DAPM_PIN_SWITCH("Int Spk"),
103 static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime
*rtd
)
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
);
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
);
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
,
120 &tegra_alc5632_hp_jack_gpio
);
123 snd_soc_dapm_force_enable_pin(dapm
, "MICBIAS1");
128 static struct snd_soc_dai_link tegra_alc5632_dai
= {
130 .stream_name
= "ALC5632 PCM",
131 .codec_dai_name
= "alc5632-hifi",
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
,
139 static struct snd_soc_card snd_soc_tegra_alc5632
= {
140 .name
= "tegra-alc5632",
141 .owner
= THIS_MODULE
,
142 .dai_link
= &tegra_alc5632_dai
,
144 .controls
= tegra_alc5632_controls
,
145 .num_controls
= ARRAY_SIZE(tegra_alc5632_controls
),
146 .dapm_widgets
= tegra_alc5632_dapm_widgets
,
147 .num_dapm_widgets
= ARRAY_SIZE(tegra_alc5632_dapm_widgets
),
148 .fully_routed
= true,
151 static int tegra_alc5632_probe(struct platform_device
*pdev
)
153 struct device_node
*np
= pdev
->dev
.of_node
;
154 struct snd_soc_card
*card
= &snd_soc_tegra_alc5632
;
155 struct tegra_alc5632
*alc5632
;
158 alc5632
= devm_kzalloc(&pdev
->dev
,
159 sizeof(struct tegra_alc5632
), GFP_KERNEL
);
161 dev_err(&pdev
->dev
, "Can't allocate tegra_alc5632\n");
165 card
->dev
= &pdev
->dev
;
166 platform_set_drvdata(pdev
, card
);
167 snd_soc_card_set_drvdata(card
, alc5632
);
169 alc5632
->gpio_hp_det
= of_get_named_gpio(np
, "nvidia,hp-det-gpios", 0);
170 if (alc5632
->gpio_hp_det
== -EPROBE_DEFER
)
171 return -EPROBE_DEFER
;
173 ret
= snd_soc_of_parse_card_name(card
, "nvidia,model");
177 ret
= snd_soc_of_parse_audio_routing(card
, "nvidia,audio-routing");
181 tegra_alc5632_dai
.codec_of_node
= of_parse_phandle(
182 pdev
->dev
.of_node
, "nvidia,audio-codec", 0);
184 if (!tegra_alc5632_dai
.codec_of_node
) {
186 "Property 'nvidia,audio-codec' missing or invalid\n");
191 tegra_alc5632_dai
.cpu_of_node
= of_parse_phandle(np
,
192 "nvidia,i2s-controller", 0);
193 if (!tegra_alc5632_dai
.cpu_of_node
) {
195 "Property 'nvidia,i2s-controller' missing or invalid\n");
200 tegra_alc5632_dai
.platform_of_node
= tegra_alc5632_dai
.cpu_of_node
;
202 ret
= tegra_asoc_utils_init(&alc5632
->util_data
, &pdev
->dev
);
206 ret
= snd_soc_register_card(card
);
208 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n",
216 tegra_asoc_utils_fini(&alc5632
->util_data
);
221 static int tegra_alc5632_remove(struct platform_device
*pdev
)
223 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
224 struct tegra_alc5632
*machine
= snd_soc_card_get_drvdata(card
);
226 snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack
, 1,
227 &tegra_alc5632_hp_jack_gpio
);
229 snd_soc_unregister_card(card
);
231 tegra_asoc_utils_fini(&machine
->util_data
);
236 static const struct of_device_id tegra_alc5632_of_match
[] = {
237 { .compatible
= "nvidia,tegra-audio-alc5632", },
241 static struct platform_driver tegra_alc5632_driver
= {
244 .owner
= THIS_MODULE
,
245 .pm
= &snd_soc_pm_ops
,
246 .of_match_table
= tegra_alc5632_of_match
,
248 .probe
= tegra_alc5632_probe
,
249 .remove
= tegra_alc5632_remove
,
251 module_platform_driver(tegra_alc5632_driver
);
253 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
254 MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver");
255 MODULE_LICENSE("GPL");
256 MODULE_ALIAS("platform:" DRV_NAME
);
257 MODULE_DEVICE_TABLE(of
, tegra_alc5632_of_match
);