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 <asm/mach-types.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/slab.h>
33 #include <sound/core.h>
34 #include <sound/jack.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/soc.h>
39 #include "../codecs/tlv320aic23.h"
41 #include "tegra_das.h"
42 #include "tegra_i2s.h"
43 #include "tegra_pcm.h"
44 #include "tegra_asoc_utils.h"
46 #define DRV_NAME "tegra-snd-trimslice"
48 struct tegra_trimslice
{
49 struct tegra_asoc_utils_data util_data
;
52 static int trimslice_asoc_hw_params(struct snd_pcm_substream
*substream
,
53 struct snd_pcm_hw_params
*params
)
55 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
56 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
57 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
58 struct snd_soc_codec
*codec
= rtd
->codec
;
59 struct snd_soc_card
*card
= codec
->card
;
60 struct tegra_trimslice
*trimslice
= snd_soc_card_get_drvdata(card
);
64 srate
= params_rate(params
);
67 err
= tegra_asoc_utils_set_rate(&trimslice
->util_data
, srate
, mclk
);
69 dev_err(card
->dev
, "Can't configure clocks\n");
73 err
= snd_soc_dai_set_fmt(codec_dai
,
75 SND_SOC_DAIFMT_NB_NF
|
76 SND_SOC_DAIFMT_CBS_CFS
);
78 dev_err(card
->dev
, "codec_dai fmt not set\n");
82 err
= snd_soc_dai_set_fmt(cpu_dai
,
84 SND_SOC_DAIFMT_NB_NF
|
85 SND_SOC_DAIFMT_CBS_CFS
);
87 dev_err(card
->dev
, "cpu_dai fmt not set\n");
91 err
= snd_soc_dai_set_sysclk(codec_dai
, 0, mclk
,
94 dev_err(card
->dev
, "codec_dai clock not set\n");
101 static struct snd_soc_ops trimslice_asoc_ops
= {
102 .hw_params
= trimslice_asoc_hw_params
,
105 static const struct snd_soc_dapm_widget trimslice_dapm_widgets
[] = {
106 SND_SOC_DAPM_HP("Line Out", NULL
),
107 SND_SOC_DAPM_LINE("Line In", NULL
),
110 static const struct snd_soc_dapm_route trimslice_audio_map
[] = {
111 {"Line Out", NULL
, "LOUT"},
112 {"Line Out", NULL
, "ROUT"},
114 {"LLINEIN", NULL
, "Line In"},
115 {"RLINEIN", NULL
, "Line In"},
118 static int trimslice_asoc_init(struct snd_soc_pcm_runtime
*rtd
)
120 struct snd_soc_codec
*codec
= rtd
->codec
;
121 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
123 snd_soc_dapm_nc_pin(dapm
, "LHPOUT");
124 snd_soc_dapm_nc_pin(dapm
, "RHPOUT");
125 snd_soc_dapm_nc_pin(dapm
, "MICIN");
130 static struct snd_soc_dai_link trimslice_tlv320aic23_dai
= {
131 .name
= "TLV320AIC23",
132 .stream_name
= "AIC23",
133 .codec_name
= "tlv320aic23-codec.2-001a",
134 .platform_name
= "tegra-pcm-audio",
135 .cpu_dai_name
= "tegra-i2s.0",
136 .codec_dai_name
= "tlv320aic23-hifi",
137 .init
= trimslice_asoc_init
,
138 .ops
= &trimslice_asoc_ops
,
141 static struct snd_soc_card snd_soc_trimslice
= {
142 .name
= "tegra-trimslice",
143 .dai_link
= &trimslice_tlv320aic23_dai
,
146 .dapm_widgets
= trimslice_dapm_widgets
,
147 .num_dapm_widgets
= ARRAY_SIZE(trimslice_dapm_widgets
),
148 .dapm_routes
= trimslice_audio_map
,
149 .num_dapm_routes
= ARRAY_SIZE(trimslice_audio_map
),
152 static __devinit
int tegra_snd_trimslice_probe(struct platform_device
*pdev
)
154 struct snd_soc_card
*card
= &snd_soc_trimslice
;
155 struct tegra_trimslice
*trimslice
;
158 trimslice
= kzalloc(sizeof(struct tegra_trimslice
), GFP_KERNEL
);
160 dev_err(&pdev
->dev
, "Can't allocate tegra_trimslice\n");
164 ret
= tegra_asoc_utils_init(&trimslice
->util_data
, &pdev
->dev
);
166 goto err_free_trimslice
;
168 card
->dev
= &pdev
->dev
;
169 platform_set_drvdata(pdev
, card
);
170 snd_soc_card_set_drvdata(card
, trimslice
);
172 ret
= snd_soc_register_card(card
);
174 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n",
182 tegra_asoc_utils_fini(&trimslice
->util_data
);
188 static int __devexit
tegra_snd_trimslice_remove(struct platform_device
*pdev
)
190 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
191 struct tegra_trimslice
*trimslice
= snd_soc_card_get_drvdata(card
);
193 snd_soc_unregister_card(card
);
195 tegra_asoc_utils_fini(&trimslice
->util_data
);
202 static struct platform_driver tegra_snd_trimslice_driver
= {
205 .owner
= THIS_MODULE
,
207 .probe
= tegra_snd_trimslice_probe
,
208 .remove
= __devexit_p(tegra_snd_trimslice_remove
),
211 static int __init
snd_tegra_trimslice_init(void)
213 return platform_driver_register(&tegra_snd_trimslice_driver
);
215 module_init(snd_tegra_trimslice_init
);
217 static void __exit
snd_tegra_trimslice_exit(void)
219 platform_driver_unregister(&tegra_snd_trimslice_driver
);
221 module_exit(snd_tegra_trimslice_exit
);
223 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
224 MODULE_DESCRIPTION("Trimslice machine ASoC driver");
225 MODULE_LICENSE("GPL");
226 MODULE_ALIAS("platform:" DRV_NAME
);