blob: 945e8abdc10fbf9579a1f89bd9a6a0610980256f [file] [log] [blame]
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +01001/*
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>
Ben Dooksaa6b9042009-08-20 22:50:42 +010017#include <linux/i2c.h>
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +010018#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +010021
22#include <variant/dmac.h>
23
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +010024#include "s6000-pcm.h"
25#include "s6000-i2s.h"
26
27#define S6105_CAM_CODEC_CLOCK 12288000
28
29static int s6105_hw_params(struct snd_pcm_substream *substream,
30 struct snd_pcm_hw_params *params)
31{
32 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000033 struct snd_soc_dai *codec_dai = rtd->codec_dai;
34 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +010035 int ret = 0;
36
37 /* set codec DAI configuration */
38 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
39 SND_SOC_DAIFMT_CBM_CFM);
40 if (ret < 0)
41 return ret;
42
43 /* set cpu DAI configuration */
44 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
Daniel Glöckner80fbe6a2009-04-06 11:50:22 +020045 SND_SOC_DAIFMT_NB_NF);
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +010046 if (ret < 0)
47 return ret;
48
49 /* set the codec system clock */
50 ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK,
51 SND_SOC_CLOCK_OUT);
52 if (ret < 0)
53 return ret;
54
55 return 0;
56}
57
58static struct snd_soc_ops s6105_ops = {
59 .hw_params = s6105_hw_params,
60};
61
62/* s6105 machine dapm widgets */
63static 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),
67};
68
69/* s6105 machine audio_mapnections to the codec pins */
70static 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"},
76
77 /* Audio In connected to LINE1L, LINE1R */
78 {"LINE1L", NULL, "Audio In"},
79 {"LINE1R", NULL, "Audio In"},
80};
81
82static int output_type_info(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_info *uinfo)
84{
85 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
86 uinfo->count = 1;
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");
91 } else {
92 strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM");
93 }
94 return 0;
95}
96
97static int output_type_get(struct snd_kcontrol *kcontrol,
98 struct snd_ctl_elem_value *ucontrol)
99{
100 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
101 return 0;
102}
103
104static int output_type_put(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_value *ucontrol)
106{
107 struct snd_soc_codec *codec = kcontrol->private_data;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200108 struct snd_soc_dapm_context *dapm = &codec->dapm;
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100109 unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
110 char *differential = "Audio Out Differential";
111 char *stereo = "Audio Out Stereo";
112
113 if (kcontrol->private_value == val)
114 return 0;
115 kcontrol->private_value = val;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200116 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);
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100120
121 return 1;
122}
123
124static const struct snd_kcontrol_new audio_out_mux = {
125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
126 .name = "Master Output Mux",
127 .index = 0,
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 */
133};
134
135/* Logic for a aic3x as connected on the s6105 ip camera ref design */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000136static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100137{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000138 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200139 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000140
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100141 /* Add s6105 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200142 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100143 ARRAY_SIZE(aic3x_dapm_widgets));
144
145 /* Set up s6105 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200146 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100147
148 /* not present */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200149 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
150 snd_soc_dapm_nc_pin(dapm, "LINE2L");
151 snd_soc_dapm_nc_pin(dapm, "LINE2R");
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100152
153 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200154 snd_soc_dapm_nc_pin(dapm, "MIC3L"); /* LINE2L on this chip */
155 snd_soc_dapm_nc_pin(dapm, "MIC3R"); /* LINE2R on this chip */
156 snd_soc_dapm_nc_pin(dapm, "LLOUT");
157 snd_soc_dapm_nc_pin(dapm, "RLOUT");
158 snd_soc_dapm_nc_pin(dapm, "HPRCOM");
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100159
160 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200161 snd_soc_dapm_enable_pin(dapm, "Audio In");
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100162
163 /* must correspond to audio_out_mux.private_value initializer */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200164 snd_soc_dapm_disable_pin(dapm, "Audio Out Differential");
165 snd_soc_dapm_sync(dapm);
166 snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100167
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200168 snd_soc_dapm_sync(dapm);
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100169
Daniel Glöcknerb76fb392010-11-30 01:00:18 +0100170 snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec));
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100171
172 return 0;
173}
174
175/* s6105 digital audio interface glue - connects codec <--> CPU */
176static struct snd_soc_dai_link s6105_dai = {
177 .name = "TLV320AIC31",
178 .stream_name = "AIC31",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000179 .cpu_dai_name = "s6000-i2s",
180 .codec_dai_name = "tlv320aic3x-hifi",
181 .platform_name = "s6000-pcm-audio",
182 .codec_name = "tlv320aic3x-codec.0-001a",
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100183 .init = s6105_aic3x_init,
184 .ops = &s6105_ops,
185};
186
187/* s6105 audio machine driver */
188static struct snd_soc_card snd_soc_card_s6105 = {
189 .name = "Stretch IP Camera",
Axel Lin23bd1ce2011-12-23 14:52:22 +0800190 .owner = THIS_MODULE,
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100191 .dai_link = &s6105_dai,
192 .num_links = 1,
193};
194
Sachin Kamat74b45232013-08-08 16:52:18 +0530195static struct s6000_snd_platform_data s6105_snd_data __initdata = {
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100196 .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
Ben Dooksaa6b9042009-08-20 22:50:42 +0100206/* 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
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100213static int __init s6105_init(void)
214{
215 int ret;
216
Ben Dooksaa6b9042009-08-20 22:50:42 +0100217 i2c_register_board_info(0, i2c_device, ARRAY_SIZE(i2c_device));
218
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100219 s6105_snd_device = platform_device_alloc("soc-audio", -1);
220 if (!s6105_snd_device)
221 return -ENOMEM;
222
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000223 platform_set_drvdata(s6105_snd_device, &snd_soc_card_s6105);
Daniel Glöckner2b7dbbe2009-03-28 19:47:02 +0100224 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");