2 * sound/soc/lpc3xxx/lpc3xxx-uda1380.c
4 * Author: Kevin Wells <kevin.wells@nxp.com>
6 * Copyright (C) 2008 NXP Semiconductors
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/version.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/clk.h>
29 #include <linux/timer.h>
30 #include <linux/interrupt.h>
31 #include <linux/platform_device.h>
32 #include <linux/i2c.h>
34 #include <sound/core.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/soc.h>
38 #include <sound/soc-dapm.h>
39 #include <sound/uda1380.h>
41 #include <mach/gpio.h>
43 #include "../codecs/uda1380.h"
44 #include "lpc3xxx-pcm.h"
45 #include "lpc3xxx-i2s.h"
47 #define SND_MODNAME "lpc3xxx_uda1380"
49 static int phy3250_uda1380_hw_params(struct snd_pcm_substream *substream,
50 struct snd_pcm_hw_params *params)
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *codec_dai = rtd->codec_dai;
54 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
55 unsigned int fmt = SND_SOC_DAIFMT_I2S;
58 /* The perspective is from the CODEC side, so slave mode means that
59 the i2s interface is the master. For the UDA1380 and playback,
60 the CODEC is always a slave and i2s is always a master. */
61 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
62 fmt |= SND_SOC_DAIFMT_CBS_CFS;
66 #if defined(CONFIG_SND_LPC32XX_USEI2S_SLAVE_MODERX)
67 fmt |= SND_SOC_DAIFMT_CBM_CFM;
69 fmt |= SND_SOC_DAIFMT_CBS_CFS;
73 /* Set the CPU I2S rate clock (first) */
74 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params),
78 "Failed to set I2S clock (%d)\n",
83 /* Set CPU and CODEC DAI format */
84 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
87 "Failed to set CPU DAI format (%d)\n",
91 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
94 "Failed to set CODEC DAI format (%d)\n",
102 static struct snd_soc_ops phy3250_uda1380_ops = {
103 .hw_params = phy3250_uda1380_hw_params,
106 static const struct snd_soc_dapm_widget phy3250_dapm_widgets[] = {
107 SND_SOC_DAPM_HP("Headphone Jack", NULL),
108 SND_SOC_DAPM_LINE("Line Out", NULL),
109 SND_SOC_DAPM_MIC("Mic Jack", NULL),
110 SND_SOC_DAPM_LINE("Line In", NULL),
113 static const struct snd_soc_dapm_route intercon[] = {
114 /* Headphone connected to VOUTRHP, VOUTLHP */
115 {"Headphone Jack", NULL, "VOUTRHP"},
116 {"Headphone Jack", NULL, "VOUTLHP"},
118 /* Line Out connected to VOUTR, VOUTL */
119 {"Line Out", NULL, "VOUTR"},
120 {"Line Out", NULL, "VOUTL"},
122 /* Mic connected to VINM */
123 {"VINM", NULL, "Mic Jack"},
125 /* Line In connected to VINR, VINL */
126 {"VINL", NULL, "Line In"},
127 {"VINR", NULL, "Line In"},
130 static int phy3250_uda1380_init(struct snd_soc_pcm_runtime *rtd)
133 struct snd_soc_codec *codec = rtd->codec;
134 struct snd_soc_dapm_context *dapm = &codec->dapm;
137 err = snd_soc_dapm_new_controls(dapm, phy3250_dapm_widgets,
138 ARRAY_SIZE(phy3250_dapm_widgets));
142 /* Set up audio_map */
143 err = snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
147 /* Always connected pins */
148 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
149 snd_soc_dapm_enable_pin(dapm, "Line Out");
150 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
151 snd_soc_dapm_enable_pin(dapm, "Line In");
153 snd_soc_dapm_sync(dapm);
158 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
159 static struct snd_soc_dai_link phy3250_uda1380_dai[] = {
162 .stream_name = "UDA1380 Duplex",
163 #if defined(CONFIG_SND_LPC32XX_USEI2S1)
164 .cpu_dai_name = "lpc3xxx-i2s1",
166 .cpu_dai_name = "lpc3xxx-i2s0",
168 .codec_dai_name = "uda1380-hifi",
169 .init = phy3250_uda1380_init,
170 .platform_name = "lpc3xxx-audio.0",
171 .codec_name = "uda1380-codec.0-0018",
172 .ops = &phy3250_uda1380_ops,
176 static struct snd_soc_card phy3250_snd_asoc = {
178 .dai_link = &phy3250_uda1380_dai[0],
179 .num_links = ARRAY_SIZE(phy3250_uda1380_dai),
182 static struct platform_device *phy3250_snd_device;
184 static int __init phy3250_asoc_init(void)
189 * Create and register platform device
191 phy3250_snd_device = platform_device_alloc("soc-audio", 0);
192 if (phy3250_snd_device == NULL) {
196 platform_set_drvdata(phy3250_snd_device, &phy3250_snd_asoc);
198 ret = platform_device_add(phy3250_snd_device);
200 pr_warning("%s: platform_device_add failed (%d)\n",
208 if (phy3250_snd_device != NULL) {
209 platform_device_put(phy3250_snd_device);
210 phy3250_snd_device = NULL;
216 static void __exit phy3250_asoc_exit(void)
218 platform_device_unregister(phy3250_snd_device);
219 phy3250_snd_device = NULL;
222 module_init(phy3250_asoc_init);
223 module_exit(phy3250_asoc_exit);
225 MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
226 MODULE_DESCRIPTION("ASoC machine driver for LPC3XXX/UDA1380");
227 MODULE_LICENSE("GPL");