ASoC: Decouple DAPM from CODECs
[linux-2.6-block.git] / sound / soc / s6000 / s6105-ipcam.c
CommitLineData
2b7dbbe0
DG
1/*
2 * ASoC driver for Stretch s6105 IP camera platform
3 *
4 * Author: Daniel Gloeckner, <dg@emlix.com>
5 * Copyright: (C) 2009 emlix GmbH <info@emlix.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
aa6b904e 17#include <linux/i2c.h>
2b7dbbe0
DG
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22
23#include <variant/dmac.h>
24
25#include "../codecs/tlv320aic3x.h"
26#include "s6000-pcm.h"
27#include "s6000-i2s.h"
28
29#define S6105_CAM_CODEC_CLOCK 12288000
30
31static int s6105_hw_params(struct snd_pcm_substream *substream,
32 struct snd_pcm_hw_params *params)
33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
35 struct snd_soc_dai *codec_dai = rtd->codec_dai;
36 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2b7dbbe0
DG
37 int ret = 0;
38
39 /* set codec DAI configuration */
40 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
41 SND_SOC_DAIFMT_CBM_CFM);
42 if (ret < 0)
43 return ret;
44
45 /* set cpu DAI configuration */
46 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
80fbe6ac 47 SND_SOC_DAIFMT_NB_NF);
2b7dbbe0
DG
48 if (ret < 0)
49 return ret;
50
51 /* set the codec system clock */
52 ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK,
53 SND_SOC_CLOCK_OUT);
54 if (ret < 0)
55 return ret;
56
57 return 0;
58}
59
60static struct snd_soc_ops s6105_ops = {
61 .hw_params = s6105_hw_params,
62};
63
64/* s6105 machine dapm widgets */
65static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
66 SND_SOC_DAPM_LINE("Audio Out Differential", NULL),
67 SND_SOC_DAPM_LINE("Audio Out Stereo", NULL),
68 SND_SOC_DAPM_LINE("Audio In", NULL),
69};
70
71/* s6105 machine audio_mapnections to the codec pins */
72static const struct snd_soc_dapm_route audio_map[] = {
73 /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */
74 {"Audio Out Differential", NULL, "HPLOUT"},
75 {"Audio Out Differential", NULL, "HPLCOM"},
76 {"Audio Out Stereo", NULL, "HPLOUT"},
77 {"Audio Out Stereo", NULL, "HPROUT"},
78
79 /* Audio In connected to LINE1L, LINE1R */
80 {"LINE1L", NULL, "Audio In"},
81 {"LINE1R", NULL, "Audio In"},
82};
83
84static int output_type_info(struct snd_kcontrol *kcontrol,
85 struct snd_ctl_elem_info *uinfo)
86{
87 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
88 uinfo->count = 1;
89 uinfo->value.enumerated.items = 2;
90 if (uinfo->value.enumerated.item) {
91 uinfo->value.enumerated.item = 1;
92 strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT");
93 } else {
94 strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM");
95 }
96 return 0;
97}
98
99static int output_type_get(struct snd_kcontrol *kcontrol,
100 struct snd_ctl_elem_value *ucontrol)
101{
102 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
103 return 0;
104}
105
106static int output_type_put(struct snd_kcontrol *kcontrol,
107 struct snd_ctl_elem_value *ucontrol)
108{
109 struct snd_soc_codec *codec = kcontrol->private_data;
ce6120cc 110 struct snd_soc_dapm_context *dapm = &codec->dapm;
2b7dbbe0
DG
111 unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
112 char *differential = "Audio Out Differential";
113 char *stereo = "Audio Out Stereo";
114
115 if (kcontrol->private_value == val)
116 return 0;
117 kcontrol->private_value = val;
ce6120cc
LG
118 snd_soc_dapm_disable_pin(dapm, val ? differential : stereo);
119 snd_soc_dapm_sync(dapm);
120 snd_soc_dapm_enable_pin(dapm, val ? stereo : differential);
121 snd_soc_dapm_sync(dapm);
2b7dbbe0
DG
122
123 return 1;
124}
125
126static const struct snd_kcontrol_new audio_out_mux = {
127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
128 .name = "Master Output Mux",
129 .index = 0,
130 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
131 .info = output_type_info,
132 .get = output_type_get,
133 .put = output_type_put,
134 .private_value = 1 /* default to stereo */
135};
136
137/* Logic for a aic3x as connected on the s6105 ip camera ref design */
f0fba2ad 138static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
2b7dbbe0 139{
f0fba2ad 140 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 141 struct snd_soc_dapm_context *dapm = &codec->dapm;
f0fba2ad 142
2b7dbbe0 143 /* Add s6105 specific widgets */
ce6120cc 144 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
2b7dbbe0
DG
145 ARRAY_SIZE(aic3x_dapm_widgets));
146
147 /* Set up s6105 specific audio path audio_map */
ce6120cc 148 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
2b7dbbe0
DG
149
150 /* not present */
ce6120cc
LG
151 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
152 snd_soc_dapm_nc_pin(dapm, "LINE2L");
153 snd_soc_dapm_nc_pin(dapm, "LINE2R");
2b7dbbe0
DG
154
155 /* not connected */
ce6120cc
LG
156 snd_soc_dapm_nc_pin(dapm, "MIC3L"); /* LINE2L on this chip */
157 snd_soc_dapm_nc_pin(dapm, "MIC3R"); /* LINE2R on this chip */
158 snd_soc_dapm_nc_pin(dapm, "LLOUT");
159 snd_soc_dapm_nc_pin(dapm, "RLOUT");
160 snd_soc_dapm_nc_pin(dapm, "HPRCOM");
2b7dbbe0
DG
161
162 /* always connected */
ce6120cc 163 snd_soc_dapm_enable_pin(dapm, "Audio In");
2b7dbbe0
DG
164
165 /* must correspond to audio_out_mux.private_value initializer */
ce6120cc
LG
166 snd_soc_dapm_disable_pin(dapm, "Audio Out Differential");
167 snd_soc_dapm_sync(dapm);
168 snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
2b7dbbe0 169
ce6120cc 170 snd_soc_dapm_sync(dapm);
2b7dbbe0 171
f0fba2ad 172 snd_ctl_add(codec->snd_card, snd_ctl_new1(&audio_out_mux, codec));
2b7dbbe0
DG
173
174 return 0;
175}
176
177/* s6105 digital audio interface glue - connects codec <--> CPU */
178static struct snd_soc_dai_link s6105_dai = {
179 .name = "TLV320AIC31",
180 .stream_name = "AIC31",
f0fba2ad
LG
181 .cpu_dai_name = "s6000-i2s",
182 .codec_dai_name = "tlv320aic3x-hifi",
183 .platform_name = "s6000-pcm-audio",
184 .codec_name = "tlv320aic3x-codec.0-001a",
2b7dbbe0
DG
185 .init = s6105_aic3x_init,
186 .ops = &s6105_ops,
187};
188
189/* s6105 audio machine driver */
190static struct snd_soc_card snd_soc_card_s6105 = {
191 .name = "Stretch IP Camera",
2b7dbbe0
DG
192 .dai_link = &s6105_dai,
193 .num_links = 1,
194};
195
2b7dbbe0
DG
196static struct s6000_snd_platform_data __initdata s6105_snd_data = {
197 .wide = 0,
198 .channel_in = 0,
199 .channel_out = 1,
200 .lines_in = 1,
201 .lines_out = 1,
202 .same_rate = 1,
203};
204
205static struct platform_device *s6105_snd_device;
206
aa6b904e
BD
207/* temporary i2c device creation until this can be moved into the machine
208 * support file.
209*/
210static struct i2c_board_info i2c_device[] = {
211 { I2C_BOARD_INFO("tlv320aic33", 0x18), }
212};
213
2b7dbbe0
DG
214static int __init s6105_init(void)
215{
216 int ret;
217
aa6b904e
BD
218 i2c_register_board_info(0, i2c_device, ARRAY_SIZE(i2c_device));
219
2b7dbbe0
DG
220 s6105_snd_device = platform_device_alloc("soc-audio", -1);
221 if (!s6105_snd_device)
222 return -ENOMEM;
223
f0fba2ad 224 platform_set_drvdata(s6105_snd_device, &snd_soc_card_s6105);
2b7dbbe0
DG
225 platform_device_add_data(s6105_snd_device, &s6105_snd_data,
226 sizeof(s6105_snd_data));
227
228 ret = platform_device_add(s6105_snd_device);
229 if (ret)
230 platform_device_put(s6105_snd_device);
231
232 return ret;
233}
234
235static void __exit s6105_exit(void)
236{
237 platform_device_unregister(s6105_snd_device);
238}
239
240module_init(s6105_init);
241module_exit(s6105_exit);
242
243MODULE_AUTHOR("Daniel Gloeckner");
244MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver");
245MODULE_LICENSE("GPL");