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