2 * ASoC driver for Stretch s6105 IP camera platform
4 * Author: Daniel Gloeckner, <dg@emlix.com>
5 * Copyright: (C) 2009 emlix GmbH <info@emlix.com>
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.
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>
17 #include <linux/i2c.h>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
22 #include <variant/dmac.h>
24 #include "s6000-pcm.h"
25 #include "s6000-i2s.h"
27 #define S6105_CAM_CODEC_CLOCK 12288000
29 static int s6105_hw_params(struct snd_pcm_substream
*substream
,
30 struct snd_pcm_hw_params
*params
)
32 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
33 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
34 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
37 /* set codec DAI configuration */
38 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
39 SND_SOC_DAIFMT_CBM_CFM
);
43 /* set cpu DAI configuration */
44 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_CBM_CFM
|
45 SND_SOC_DAIFMT_NB_NF
);
49 /* set the codec system clock */
50 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, S6105_CAM_CODEC_CLOCK
,
58 static struct snd_soc_ops s6105_ops
= {
59 .hw_params
= s6105_hw_params
,
62 /* s6105 machine dapm widgets */
63 static const struct snd_soc_dapm_widget aic3x_dapm_widgets
[] = {
64 SND_SOC_DAPM_LINE("Audio Out Differential", NULL
),
65 SND_SOC_DAPM_LINE("Audio Out Stereo", NULL
),
66 SND_SOC_DAPM_LINE("Audio In", NULL
),
69 /* s6105 machine audio_mapnections to the codec pins */
70 static const struct snd_soc_dapm_route audio_map
[] = {
71 /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */
72 {"Audio Out Differential", NULL
, "HPLOUT"},
73 {"Audio Out Differential", NULL
, "HPLCOM"},
74 {"Audio Out Stereo", NULL
, "HPLOUT"},
75 {"Audio Out Stereo", NULL
, "HPROUT"},
77 /* Audio In connected to LINE1L, LINE1R */
78 {"LINE1L", NULL
, "Audio In"},
79 {"LINE1R", NULL
, "Audio In"},
82 static int output_type_info(struct snd_kcontrol
*kcontrol
,
83 struct snd_ctl_elem_info
*uinfo
)
85 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
87 uinfo
->value
.enumerated
.items
= 2;
88 if (uinfo
->value
.enumerated
.item
) {
89 uinfo
->value
.enumerated
.item
= 1;
90 strcpy(uinfo
->value
.enumerated
.name
, "HPLOUT/HPROUT");
92 strcpy(uinfo
->value
.enumerated
.name
, "HPLOUT/HPLCOM");
97 static int output_type_get(struct snd_kcontrol
*kcontrol
,
98 struct snd_ctl_elem_value
*ucontrol
)
100 ucontrol
->value
.enumerated
.item
[0] = kcontrol
->private_value
;
104 static int output_type_put(struct snd_kcontrol
*kcontrol
,
105 struct snd_ctl_elem_value
*ucontrol
)
107 struct snd_soc_card
*card
= kcontrol
->private_data
;
108 struct snd_soc_dapm_context
*dapm
= &card
->dapm
;
109 unsigned int val
= (ucontrol
->value
.enumerated
.item
[0] != 0);
110 char *differential
= "Audio Out Differential";
111 char *stereo
= "Audio Out Stereo";
113 if (kcontrol
->private_value
== val
)
115 kcontrol
->private_value
= val
;
116 snd_soc_dapm_disable_pin(dapm
, val
? differential
: stereo
);
117 snd_soc_dapm_sync(dapm
);
118 snd_soc_dapm_enable_pin(dapm
, val
? stereo
: differential
);
119 snd_soc_dapm_sync(dapm
);
124 static const struct snd_kcontrol_new audio_out_mux
= {
125 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
126 .name
= "Master Output Mux",
128 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
129 .info
= output_type_info
,
130 .get
= output_type_get
,
131 .put
= output_type_put
,
132 .private_value
= 1 /* default to stereo */
135 /* Logic for a aic3x as connected on the s6105 ip camera ref design */
136 static int s6105_aic3x_init(struct snd_soc_pcm_runtime
*rtd
)
138 struct snd_soc_codec
*codec
= rtd
->codec
;
139 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
140 struct snd_soc_card
*card
= rtd
->card
;
143 snd_soc_dapm_nc_pin(dapm
, "MONO_LOUT");
144 snd_soc_dapm_nc_pin(dapm
, "LINE2L");
145 snd_soc_dapm_nc_pin(dapm
, "LINE2R");
148 snd_soc_dapm_nc_pin(dapm
, "MIC3L"); /* LINE2L on this chip */
149 snd_soc_dapm_nc_pin(dapm
, "MIC3R"); /* LINE2R on this chip */
150 snd_soc_dapm_nc_pin(dapm
, "LLOUT");
151 snd_soc_dapm_nc_pin(dapm
, "RLOUT");
152 snd_soc_dapm_nc_pin(dapm
, "HPRCOM");
154 /* must correspond to audio_out_mux.private_value initializer */
155 snd_soc_dapm_disable_pin(&card
->dapm
, "Audio Out Differential");
157 snd_ctl_add(card
->snd_card
, snd_ctl_new1(&audio_out_mux
, card
));
162 /* s6105 digital audio interface glue - connects codec <--> CPU */
163 static struct snd_soc_dai_link s6105_dai
= {
164 .name
= "TLV320AIC31",
165 .stream_name
= "AIC31",
166 .cpu_dai_name
= "s6000-i2s",
167 .codec_dai_name
= "tlv320aic3x-hifi",
168 .platform_name
= "s6000-pcm-audio",
169 .codec_name
= "tlv320aic3x-codec.0-001a",
170 .init
= s6105_aic3x_init
,
174 /* s6105 audio machine driver */
175 static struct snd_soc_card snd_soc_card_s6105
= {
176 .name
= "Stretch IP Camera",
177 .owner
= THIS_MODULE
,
178 .dai_link
= &s6105_dai
,
181 .dapm_widgets
= aic3x_dapm_widgets
,
182 .num_dapm_widgets
= ARRAY_SIZE(aic3x_dapm_widgets
),
183 .dapm_routes
= audio_map
,
184 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
187 static struct s6000_snd_platform_data s6105_snd_data __initdata
= {
196 static struct platform_device
*s6105_snd_device
;
198 /* temporary i2c device creation until this can be moved into the machine
201 static struct i2c_board_info i2c_device
[] = {
202 { I2C_BOARD_INFO("tlv320aic33", 0x18), }
205 static int __init
s6105_init(void)
209 i2c_register_board_info(0, i2c_device
, ARRAY_SIZE(i2c_device
));
211 s6105_snd_device
= platform_device_alloc("soc-audio", -1);
212 if (!s6105_snd_device
)
215 platform_set_drvdata(s6105_snd_device
, &snd_soc_card_s6105
);
216 platform_device_add_data(s6105_snd_device
, &s6105_snd_data
,
217 sizeof(s6105_snd_data
));
219 ret
= platform_device_add(s6105_snd_device
);
221 platform_device_put(s6105_snd_device
);
226 static void __exit
s6105_exit(void)
228 platform_device_unregister(s6105_snd_device
);
231 module_init(s6105_init
);
232 module_exit(s6105_exit
);
234 MODULE_AUTHOR("Daniel Gloeckner");
235 MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver");
236 MODULE_LICENSE("GPL");