aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-01 23:35:13 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-01 23:35:13 -0500
commitcc43b45684018fc94ea9e007961bcf20ed8aaed8 (patch)
tree306a7a96b108ce355c2f6eccee2166536d228595
parent05cf9dd84b91fab91ddf2398ae974516445295f0 (diff)
parent330345ebdbe68e90a9592f3e1ac3bb63aed50cf8 (diff)
Merge remote-tracking branch 'asoc/topic/si476x' into asoc-next
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/si476x.c255
3 files changed, 261 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 7f15a82d1b21..3a847828932a 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -55,6 +55,7 @@ config SND_SOC_ALL_CODECS
55 select SND_SOC_PCM3008 55 select SND_SOC_PCM3008
56 select SND_SOC_RT5631 if I2C 56 select SND_SOC_RT5631 if I2C
57 select SND_SOC_SGTL5000 if I2C 57 select SND_SOC_SGTL5000 if I2C
58 select SND_SOC_SI476X if MFD_SI476X_CORE
58 select SND_SOC_SN95031 if INTEL_SCU_IPC 59 select SND_SOC_SN95031 if INTEL_SCU_IPC
59 select SND_SOC_SPDIF 60 select SND_SOC_SPDIF
60 select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI 61 select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI
@@ -289,6 +290,9 @@ config SND_SOC_RT5631
289config SND_SOC_SGTL5000 290config SND_SOC_SGTL5000
290 tristate 291 tristate
291 292
293config SND_SOC_SI476X
294 tristate
295
292config SND_SOC_SIGMADSP 296config SND_SOC_SIGMADSP
293 tristate 297 tristate
294 select CRC32 298 select CRC32
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 998f5c528af1..f6e8e36cceb7 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -46,6 +46,7 @@ snd-soc-sgtl5000-objs := sgtl5000.o
46snd-soc-alc5623-objs := alc5623.o 46snd-soc-alc5623-objs := alc5623.o
47snd-soc-alc5632-objs := alc5632.o 47snd-soc-alc5632-objs := alc5632.o
48snd-soc-sigmadsp-objs := sigmadsp.o 48snd-soc-sigmadsp-objs := sigmadsp.o
49snd-soc-si476x-objs := si476x.o
49snd-soc-sn95031-objs := sn95031.o 50snd-soc-sn95031-objs := sn95031.o
50snd-soc-spdif-tx-objs := spdif_transciever.o 51snd-soc-spdif-tx-objs := spdif_transciever.o
51snd-soc-spdif-rx-objs := spdif_receiver.o 52snd-soc-spdif-rx-objs := spdif_receiver.o
@@ -167,6 +168,7 @@ obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
167obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 168obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
168obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o 169obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
169obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o 170obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o
171obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o
170obj-$(CONFIG_SND_SOC_SN95031) +=snd-soc-sn95031.o 172obj-$(CONFIG_SND_SOC_SN95031) +=snd-soc-sn95031.o
171obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o 173obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o
172obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o 174obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c
new file mode 100644
index 000000000000..38145ba74db8
--- /dev/null
+++ b/sound/soc/codecs/si476x.c
@@ -0,0 +1,255 @@
1#include <linux/module.h>
2#include <linux/slab.h>
3#include <sound/pcm.h>
4#include <sound/pcm_params.h>
5#include <sound/soc.h>
6#include <sound/initval.h>
7
8#include <linux/i2c.h>
9
10#include <linux/mfd/si476x-core.h>
11
12enum si476x_audio_registers {
13 SI476X_DIGITAL_IO_OUTPUT_FORMAT = 0x0203,
14 SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE = 0x0202,
15};
16
17enum si476x_digital_io_output_format {
18 SI476X_DIGITAL_IO_SLOT_SIZE_SHIFT = 11,
19 SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT = 8,
20};
21
22#define SI476X_DIGITAL_IO_OUTPUT_WIDTH_MASK ((0b111 << SI476X_DIGITAL_IO_SLOT_SIZE_SHIFT) | \
23 (0b111 << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT))
24#define SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK (0b1111110)
25
26enum si476x_daudio_formats {
27 SI476X_DAUDIO_MODE_I2S = (0x0 << 1),
28 SI476X_DAUDIO_MODE_DSP_A = (0x6 << 1),
29 SI476X_DAUDIO_MODE_DSP_B = (0x7 << 1),
30 SI476X_DAUDIO_MODE_LEFT_J = (0x8 << 1),
31 SI476X_DAUDIO_MODE_RIGHT_J = (0x9 << 1),
32
33 SI476X_DAUDIO_MODE_IB = (1 << 5),
34 SI476X_DAUDIO_MODE_IF = (1 << 6),
35};
36
37enum si476x_pcm_format {
38 SI476X_PCM_FORMAT_S8 = 2,
39 SI476X_PCM_FORMAT_S16_LE = 4,
40 SI476X_PCM_FORMAT_S20_3LE = 5,
41 SI476X_PCM_FORMAT_S24_LE = 6,
42};
43
44static unsigned int si476x_codec_read(struct snd_soc_codec *codec,
45 unsigned int reg)
46{
47 int err;
48 struct si476x_core *core = codec->control_data;
49
50 si476x_core_lock(core);
51 err = si476x_core_cmd_get_property(core, reg);
52 si476x_core_unlock(core);
53
54 return err;
55}
56
57static int si476x_codec_write(struct snd_soc_codec *codec,
58 unsigned int reg, unsigned int val)
59{
60 int err;
61 struct si476x_core *core = codec->control_data;
62
63 si476x_core_lock(core);
64 err = si476x_core_cmd_set_property(core, reg, val);
65 si476x_core_unlock(core);
66
67 return err;
68}
69
70static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
71 unsigned int fmt)
72{
73 int err;
74 u16 format = 0;
75
76 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
77 return -EINVAL;
78
79 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
80 case SND_SOC_DAIFMT_DSP_A:
81 format |= SI476X_DAUDIO_MODE_DSP_A;
82 break;
83 case SND_SOC_DAIFMT_DSP_B:
84 format |= SI476X_DAUDIO_MODE_DSP_B;
85 break;
86 case SND_SOC_DAIFMT_I2S:
87 format |= SI476X_DAUDIO_MODE_I2S;
88 break;
89 case SND_SOC_DAIFMT_RIGHT_J:
90 format |= SI476X_DAUDIO_MODE_RIGHT_J;
91 break;
92 case SND_SOC_DAIFMT_LEFT_J:
93 format |= SI476X_DAUDIO_MODE_LEFT_J;
94 break;
95 default:
96 return -EINVAL;
97 }
98
99 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
100 case SND_SOC_DAIFMT_DSP_A:
101 case SND_SOC_DAIFMT_DSP_B:
102 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
103 case SND_SOC_DAIFMT_NB_NF:
104 break;
105 case SND_SOC_DAIFMT_IB_NF:
106 format |= SI476X_DAUDIO_MODE_IB;
107 break;
108 default:
109 return -EINVAL;
110 }
111 break;
112 case SND_SOC_DAIFMT_I2S:
113 case SND_SOC_DAIFMT_RIGHT_J:
114 case SND_SOC_DAIFMT_LEFT_J:
115 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
116 case SND_SOC_DAIFMT_NB_NF:
117 break;
118 case SND_SOC_DAIFMT_IB_IF:
119 format |= SI476X_DAUDIO_MODE_IB |
120 SI476X_DAUDIO_MODE_IF;
121 break;
122 case SND_SOC_DAIFMT_IB_NF:
123 format |= SI476X_DAUDIO_MODE_IB;
124 break;
125 case SND_SOC_DAIFMT_NB_IF:
126 format |= SI476X_DAUDIO_MODE_IF;
127 break;
128 default:
129 return -EINVAL;
130 }
131 break;
132 default:
133 return -EINVAL;
134 }
135
136 err = snd_soc_update_bits(codec_dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT,
137 SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK,
138 format);
139 if (err < 0) {
140 dev_err(codec_dai->codec->dev, "Failed to set output format\n");
141 return err;
142 }
143
144 return 0;
145}
146
147static int si476x_codec_hw_params(struct snd_pcm_substream *substream,
148 struct snd_pcm_hw_params *params,
149 struct snd_soc_dai *dai)
150{
151 int rate, width, err;
152
153 rate = params_rate(params);
154 if (rate < 32000 || rate > 48000) {
155 dev_err(dai->codec->dev, "Rate: %d is not supported\n", rate);
156 return -EINVAL;
157 }
158
159 switch (params_format(params)) {
160 case SNDRV_PCM_FORMAT_S8:
161 width = SI476X_PCM_FORMAT_S8;
162 case SNDRV_PCM_FORMAT_S16_LE:
163 width = SI476X_PCM_FORMAT_S16_LE;
164 break;
165 case SNDRV_PCM_FORMAT_S20_3LE:
166 width = SI476X_PCM_FORMAT_S20_3LE;
167 break;
168 case SNDRV_PCM_FORMAT_S24_LE:
169 width = SI476X_PCM_FORMAT_S24_LE;
170 break;
171 default:
172 return -EINVAL;
173 }
174
175 err = snd_soc_write(dai->codec, SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE,
176 rate);
177 if (err < 0) {
178 dev_err(dai->codec->dev, "Failed to set sample rate\n");
179 return err;
180 }
181
182 err = snd_soc_update_bits(dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT,
183 SI476X_DIGITAL_IO_OUTPUT_WIDTH_MASK,
184 (width << SI476X_DIGITAL_IO_SLOT_SIZE_SHIFT) |
185 (width << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT));
186 if (err < 0) {
187 dev_err(dai->codec->dev, "Failed to set output width\n");
188 return err;
189 }
190
191 return 0;
192}
193
194static int si476x_codec_probe(struct snd_soc_codec *codec)
195{
196 codec->control_data = i2c_mfd_cell_to_core(codec->dev);
197 return 0;
198}
199
200static struct snd_soc_dai_ops si476x_dai_ops = {
201 .hw_params = si476x_codec_hw_params,
202 .set_fmt = si476x_codec_set_dai_fmt,
203};
204
205static struct snd_soc_dai_driver si476x_dai = {
206 .name = "si476x-codec",
207 .capture = {
208 .stream_name = "Capture",
209 .channels_min = 2,
210 .channels_max = 2,
211
212 .rates = SNDRV_PCM_RATE_32000 |
213 SNDRV_PCM_RATE_44100 |
214 SNDRV_PCM_RATE_48000,
215 .formats = SNDRV_PCM_FMTBIT_S8 |
216 SNDRV_PCM_FMTBIT_S16_LE |
217 SNDRV_PCM_FMTBIT_S20_3LE |
218 SNDRV_PCM_FMTBIT_S24_LE
219 },
220 .ops = &si476x_dai_ops,
221};
222
223static struct snd_soc_codec_driver soc_codec_dev_si476x = {
224 .probe = si476x_codec_probe,
225 .read = si476x_codec_read,
226 .write = si476x_codec_write,
227};
228
229static int __devinit si476x_platform_probe(struct platform_device *pdev)
230{
231 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_si476x,
232 &si476x_dai, 1);
233}
234
235static int __devexit si476x_platform_remove(struct platform_device *pdev)
236{
237 snd_soc_unregister_codec(&pdev->dev);
238 return 0;
239}
240
241MODULE_ALIAS("platform:si476x-codec");
242
243static struct platform_driver si476x_platform_driver = {
244 .driver = {
245 .name = "si476x-codec",
246 .owner = THIS_MODULE,
247 },
248 .probe = si476x_platform_probe,
249 .remove = __devexit_p(si476x_platform_remove),
250};
251module_platform_driver(si476x_platform_driver);
252
253MODULE_AUTHOR("Andrey Smirnov <andrey.smirnov@convergeddevices.net>");
254MODULE_DESCRIPTION("ASoC Si4761/64 codec driver");
255MODULE_LICENSE("GPL");