2 * trimslice.c - TrimSlice machine ASoC driver
4 * Copyright (C) 2011 - CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
7 * Based on code copyright/by:
8 * Author: Stephen Warren <swarren@nvidia.com>
9 * Copyright (C) 2010-2011 - NVIDIA, Inc.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2 as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <linux/module.h>
29 #include <linux/platform_device.h>
30 #include <linux/slab.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 "../codecs/tlv320aic23.h"
40 #include "tegra_asoc_utils.h"
42 #define DRV_NAME "tegra-snd-trimslice"
44 struct tegra_trimslice {
45 struct tegra_asoc_utils_data util_data;
48 static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
49 struct snd_pcm_hw_params *params)
51 struct snd_soc_pcm_runtime *rtd = substream->private_data;
52 struct snd_soc_dai *codec_dai = rtd->codec_dai;
53 struct snd_soc_card *card = rtd->card;
54 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
58 srate = params_rate(params);
61 err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
63 dev_err(card->dev, "Can't configure clocks\n");
67 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
70 dev_err(card->dev, "codec_dai clock not set\n");
77 static struct snd_soc_ops trimslice_asoc_ops = {
78 .hw_params = trimslice_asoc_hw_params,
81 static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
82 SND_SOC_DAPM_HP("Line Out", NULL),
83 SND_SOC_DAPM_LINE("Line In", NULL),
86 static const struct snd_soc_dapm_route trimslice_audio_map[] = {
87 {"Line Out", NULL, "LOUT"},
88 {"Line Out", NULL, "ROUT"},
90 {"LLINEIN", NULL, "Line In"},
91 {"RLINEIN", NULL, "Line In"},
94 static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
95 .name = "TLV320AIC23",
96 .stream_name = "AIC23",
97 .codec_dai_name = "tlv320aic23-hifi",
98 .ops = &trimslice_asoc_ops,
99 .dai_fmt = SND_SOC_DAIFMT_I2S |
100 SND_SOC_DAIFMT_NB_NF |
101 SND_SOC_DAIFMT_CBS_CFS,
104 static struct snd_soc_card snd_soc_trimslice = {
105 .name = "tegra-trimslice",
106 .driver_name = "tegra",
107 .owner = THIS_MODULE,
108 .dai_link = &trimslice_tlv320aic23_dai,
111 .dapm_widgets = trimslice_dapm_widgets,
112 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
113 .dapm_routes = trimslice_audio_map,
114 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
115 .fully_routed = true,
118 static int tegra_snd_trimslice_probe(struct platform_device *pdev)
120 struct device_node *np = pdev->dev.of_node;
121 struct snd_soc_card *card = &snd_soc_trimslice;
122 struct tegra_trimslice *trimslice;
125 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
128 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
132 card->dev = &pdev->dev;
133 platform_set_drvdata(pdev, card);
134 snd_soc_card_set_drvdata(card, trimslice);
136 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(np,
137 "nvidia,audio-codec", 0);
138 if (!trimslice_tlv320aic23_dai.codec_of_node) {
140 "Property 'nvidia,audio-codec' missing or invalid\n");
145 trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(np,
146 "nvidia,i2s-controller", 0);
147 if (!trimslice_tlv320aic23_dai.cpu_of_node) {
149 "Property 'nvidia,i2s-controller' missing or invalid\n");
154 trimslice_tlv320aic23_dai.platform_of_node =
155 trimslice_tlv320aic23_dai.cpu_of_node;
157 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
161 ret = snd_soc_register_card(card);
163 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
171 tegra_asoc_utils_fini(&trimslice->util_data);
176 static int tegra_snd_trimslice_remove(struct platform_device *pdev)
178 struct snd_soc_card *card = platform_get_drvdata(pdev);
179 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
181 snd_soc_unregister_card(card);
183 tegra_asoc_utils_fini(&trimslice->util_data);
188 static const struct of_device_id trimslice_of_match[] = {
189 { .compatible = "nvidia,tegra-audio-trimslice", },
192 MODULE_DEVICE_TABLE(of, trimslice_of_match);
194 static struct platform_driver tegra_snd_trimslice_driver = {
197 .of_match_table = trimslice_of_match,
199 .probe = tegra_snd_trimslice_probe,
200 .remove = tegra_snd_trimslice_remove,
202 module_platform_driver(tegra_snd_trimslice_driver);
204 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
205 MODULE_DESCRIPTION("Trimslice machine ASoC driver");
206 MODULE_LICENSE("GPL");
207 MODULE_ALIAS("platform:" DRV_NAME);