2 * Tegra machine ASoC driver for boards using a MAX90809 CODEC.
4 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Based on code copyright/by:
20 * Copyright (C) 2010-2012 - NVIDIA, Inc.
21 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
22 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
23 * Copyright 2007 Wolfson Microelectronics PLC.
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/slab.h>
29 #include <linux/gpio.h>
30 #include <linux/of_gpio.h>
32 #include <sound/core.h>
33 #include <sound/jack.h>
34 #include <sound/pcm.h>
35 #include <sound/pcm_params.h>
36 #include <sound/soc.h>
38 #include "tegra_asoc_utils.h"
40 #define DRV_NAME "tegra-snd-max98090"
42 struct tegra_max98090
{
43 struct tegra_asoc_utils_data util_data
;
47 static int tegra_max98090_asoc_hw_params(struct snd_pcm_substream
*substream
,
48 struct snd_pcm_hw_params
*params
)
50 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
51 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
52 struct snd_soc_codec
*codec
= codec_dai
->codec
;
53 struct snd_soc_card
*card
= codec
->card
;
54 struct tegra_max98090
*machine
= snd_soc_card_get_drvdata(card
);
58 srate
= params_rate(params
);
80 err
= tegra_asoc_utils_set_rate(&machine
->util_data
, srate
, mclk
);
82 dev_err(card
->dev
, "Can't configure clocks\n");
86 err
= snd_soc_dai_set_sysclk(codec_dai
, 0, mclk
,
89 dev_err(card
->dev
, "codec_dai clock not set\n");
96 static struct snd_soc_ops tegra_max98090_ops
= {
97 .hw_params
= tegra_max98090_asoc_hw_params
,
100 static struct snd_soc_jack tegra_max98090_hp_jack
;
102 static struct snd_soc_jack_pin tegra_max98090_hp_jack_pins
[] = {
105 .mask
= SND_JACK_HEADPHONE
,
109 static struct snd_soc_jack_gpio tegra_max98090_hp_jack_gpio
= {
110 .name
= "Headphone detection",
111 .report
= SND_JACK_HEADPHONE
,
112 .debounce_time
= 150,
116 static const struct snd_soc_dapm_widget tegra_max98090_dapm_widgets
[] = {
117 SND_SOC_DAPM_HP("Headphones", NULL
),
118 SND_SOC_DAPM_SPK("Speakers", NULL
),
119 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
122 static const struct snd_kcontrol_new tegra_max98090_controls
[] = {
123 SOC_DAPM_PIN_SWITCH("Speakers"),
126 static int tegra_max98090_asoc_init(struct snd_soc_pcm_runtime
*rtd
)
128 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
129 struct snd_soc_codec
*codec
= codec_dai
->codec
;
130 struct tegra_max98090
*machine
= snd_soc_card_get_drvdata(codec
->card
);
132 if (gpio_is_valid(machine
->gpio_hp_det
)) {
133 snd_soc_jack_new(codec
, "Headphones", SND_JACK_HEADPHONE
,
134 &tegra_max98090_hp_jack
);
135 snd_soc_jack_add_pins(&tegra_max98090_hp_jack
,
136 ARRAY_SIZE(tegra_max98090_hp_jack_pins
),
137 tegra_max98090_hp_jack_pins
);
139 tegra_max98090_hp_jack_gpio
.gpio
= machine
->gpio_hp_det
;
140 snd_soc_jack_add_gpios(&tegra_max98090_hp_jack
,
142 &tegra_max98090_hp_jack_gpio
);
148 static int tegra_max98090_card_remove(struct snd_soc_card
*card
)
150 struct tegra_max98090
*machine
= snd_soc_card_get_drvdata(card
);
152 if (gpio_is_valid(machine
->gpio_hp_det
)) {
153 snd_soc_jack_free_gpios(&tegra_max98090_hp_jack
, 1,
154 &tegra_max98090_hp_jack_gpio
);
160 static struct snd_soc_dai_link tegra_max98090_dai
= {
162 .stream_name
= "max98090 PCM",
163 .codec_dai_name
= "HiFi",
164 .init
= tegra_max98090_asoc_init
,
165 .ops
= &tegra_max98090_ops
,
166 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
167 SND_SOC_DAIFMT_CBS_CFS
,
170 static struct snd_soc_card snd_soc_tegra_max98090
= {
171 .name
= "tegra-max98090",
172 .owner
= THIS_MODULE
,
173 .remove
= tegra_max98090_card_remove
,
174 .dai_link
= &tegra_max98090_dai
,
176 .controls
= tegra_max98090_controls
,
177 .num_controls
= ARRAY_SIZE(tegra_max98090_controls
),
178 .dapm_widgets
= tegra_max98090_dapm_widgets
,
179 .num_dapm_widgets
= ARRAY_SIZE(tegra_max98090_dapm_widgets
),
180 .fully_routed
= true,
183 static int tegra_max98090_probe(struct platform_device
*pdev
)
185 struct device_node
*np
= pdev
->dev
.of_node
;
186 struct snd_soc_card
*card
= &snd_soc_tegra_max98090
;
187 struct tegra_max98090
*machine
;
190 machine
= devm_kzalloc(&pdev
->dev
,
191 sizeof(struct tegra_max98090
), GFP_KERNEL
);
193 dev_err(&pdev
->dev
, "Can't allocate tegra_max98090\n");
197 card
->dev
= &pdev
->dev
;
198 platform_set_drvdata(pdev
, card
);
199 snd_soc_card_set_drvdata(card
, machine
);
201 machine
->gpio_hp_det
= of_get_named_gpio(np
, "nvidia,hp-det-gpios", 0);
202 if (machine
->gpio_hp_det
== -EPROBE_DEFER
)
203 return -EPROBE_DEFER
;
205 ret
= snd_soc_of_parse_card_name(card
, "nvidia,model");
209 ret
= snd_soc_of_parse_audio_routing(card
, "nvidia,audio-routing");
213 tegra_max98090_dai
.codec_of_node
= of_parse_phandle(np
,
214 "nvidia,audio-codec", 0);
215 if (!tegra_max98090_dai
.codec_of_node
) {
217 "Property 'nvidia,audio-codec' missing or invalid\n");
222 tegra_max98090_dai
.cpu_of_node
= of_parse_phandle(np
,
223 "nvidia,i2s-controller", 0);
224 if (!tegra_max98090_dai
.cpu_of_node
) {
226 "Property 'nvidia,i2s-controller' missing or invalid\n");
231 tegra_max98090_dai
.platform_of_node
= tegra_max98090_dai
.cpu_of_node
;
233 ret
= tegra_asoc_utils_init(&machine
->util_data
, &pdev
->dev
);
237 ret
= snd_soc_register_card(card
);
239 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n",
247 tegra_asoc_utils_fini(&machine
->util_data
);
252 static int tegra_max98090_remove(struct platform_device
*pdev
)
254 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
255 struct tegra_max98090
*machine
= snd_soc_card_get_drvdata(card
);
257 snd_soc_unregister_card(card
);
259 tegra_asoc_utils_fini(&machine
->util_data
);
264 static const struct of_device_id tegra_max98090_of_match
[] = {
265 { .compatible
= "nvidia,tegra-audio-max98090", },
269 static struct platform_driver tegra_max98090_driver
= {
272 .owner
= THIS_MODULE
,
273 .pm
= &snd_soc_pm_ops
,
274 .of_match_table
= tegra_max98090_of_match
,
276 .probe
= tegra_max98090_probe
,
277 .remove
= tegra_max98090_remove
,
279 module_platform_driver(tegra_max98090_driver
);
281 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
282 MODULE_DESCRIPTION("Tegra max98090 machine ASoC driver");
283 MODULE_LICENSE("GPL v2");
284 MODULE_ALIAS("platform:" DRV_NAME
);
285 MODULE_DEVICE_TABLE(of
, tegra_max98090_of_match
);