Commit | Line | Data |
---|---|---|
b7138212 CC |
1 | /* |
2 | * File: sound/soc/codecs/ssm2602.c | |
3 | * Author: Cliff Cai <Cliff.Cai@analog.com> | |
4 | * | |
5 | * Created: Tue June 06 2008 | |
6 | * Description: Driver for ssm2602 sound chip | |
7 | * | |
8 | * Modified: | |
9 | * Copyright 2008 Analog Devices Inc. | |
10 | * | |
11 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version 2 of the License, or | |
16 | * (at your option) any later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | * GNU General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with this program; if not, see the file COPYING, or write | |
25 | * to the Free Software Foundation, Inc., | |
26 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
27 | */ | |
28 | ||
29 | #include <linux/module.h> | |
30 | #include <linux/moduleparam.h> | |
31 | #include <linux/init.h> | |
32 | #include <linux/delay.h> | |
33 | #include <linux/pm.h> | |
34 | #include <linux/i2c.h> | |
35 | #include <linux/platform_device.h> | |
5a0e3ad6 | 36 | #include <linux/slab.h> |
b7138212 CC |
37 | #include <sound/core.h> |
38 | #include <sound/pcm.h> | |
39 | #include <sound/pcm_params.h> | |
40 | #include <sound/soc.h> | |
b7138212 CC |
41 | #include <sound/initval.h> |
42 | ||
43 | #include "ssm2602.h" | |
44 | ||
b7138212 CC |
45 | #define SSM2602_VERSION "0.1" |
46 | ||
b7138212 CC |
47 | /* codec private data */ |
48 | struct ssm2602_priv { | |
49 | unsigned int sysclk; | |
f0fba2ad | 50 | enum snd_soc_control_type control_type; |
b7138212 CC |
51 | struct snd_pcm_substream *master_substream; |
52 | struct snd_pcm_substream *slave_substream; | |
53 | }; | |
54 | ||
55 | /* | |
56 | * ssm2602 register cache | |
57 | * We can't read the ssm2602 register space when we are | |
58 | * using 2 wire for device control, so we cache them instead. | |
59 | * There is no point in caching the reset register | |
60 | */ | |
61 | static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = { | |
62 | 0x0017, 0x0017, 0x0079, 0x0079, | |
63 | 0x0000, 0x0000, 0x0000, 0x000a, | |
64 | 0x0000, 0x0000 | |
65 | }; | |
66 | ||
93547e89 | 67 | #define ssm2602_reset(c) snd_soc_write(c, SSM2602_RESET, 0) |
b7138212 CC |
68 | |
69 | /*Appending several "None"s just for OSS mixer use*/ | |
70 | static const char *ssm2602_input_select[] = { | |
71 | "Line", "Mic", "None", "None", "None", | |
72 | "None", "None", "None", | |
73 | }; | |
74 | ||
75 | static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; | |
76 | ||
77 | static const struct soc_enum ssm2602_enum[] = { | |
78 | SOC_ENUM_SINGLE(SSM2602_APANA, 2, 2, ssm2602_input_select), | |
79 | SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, 4, ssm2602_deemph), | |
80 | }; | |
81 | ||
82 | static const struct snd_kcontrol_new ssm2602_snd_controls[] = { | |
83 | ||
84 | SOC_DOUBLE_R("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V, | |
85 | 0, 127, 0), | |
86 | SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V, | |
87 | 7, 1, 0), | |
88 | ||
89 | SOC_DOUBLE_R("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 31, 0), | |
90 | SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1), | |
91 | ||
92 | SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0), | |
4b527e29 | 93 | SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 7, 1, 0), |
b7138212 CC |
94 | SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1), |
95 | ||
96 | SOC_SINGLE("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1), | |
97 | ||
98 | SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1), | |
99 | SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0), | |
100 | ||
101 | SOC_ENUM("Capture Source", ssm2602_enum[0]), | |
102 | ||
103 | SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), | |
104 | }; | |
105 | ||
b7138212 CC |
106 | /* Output Mixer */ |
107 | static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = { | |
108 | SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), | |
109 | SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0), | |
110 | SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0), | |
111 | }; | |
112 | ||
113 | /* Input mux */ | |
114 | static const struct snd_kcontrol_new ssm2602_input_mux_controls = | |
115 | SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]); | |
116 | ||
117 | static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = { | |
118 | SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1, | |
119 | &ssm2602_output_mixer_controls[0], | |
120 | ARRAY_SIZE(ssm2602_output_mixer_controls)), | |
121 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1), | |
122 | SND_SOC_DAPM_OUTPUT("LOUT"), | |
123 | SND_SOC_DAPM_OUTPUT("LHPOUT"), | |
124 | SND_SOC_DAPM_OUTPUT("ROUT"), | |
125 | SND_SOC_DAPM_OUTPUT("RHPOUT"), | |
126 | SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1), | |
127 | SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls), | |
128 | SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0), | |
129 | SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1), | |
130 | SND_SOC_DAPM_INPUT("MICIN"), | |
131 | SND_SOC_DAPM_INPUT("RLINEIN"), | |
132 | SND_SOC_DAPM_INPUT("LLINEIN"), | |
133 | }; | |
134 | ||
135 | static const struct snd_soc_dapm_route audio_conn[] = { | |
136 | /* output mixer */ | |
137 | {"Output Mixer", "Line Bypass Switch", "Line Input"}, | |
138 | {"Output Mixer", "HiFi Playback Switch", "DAC"}, | |
139 | {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"}, | |
140 | ||
141 | /* outputs */ | |
142 | {"RHPOUT", NULL, "Output Mixer"}, | |
143 | {"ROUT", NULL, "Output Mixer"}, | |
144 | {"LHPOUT", NULL, "Output Mixer"}, | |
145 | {"LOUT", NULL, "Output Mixer"}, | |
146 | ||
147 | /* input mux */ | |
148 | {"Input Mux", "Line", "Line Input"}, | |
149 | {"Input Mux", "Mic", "Mic Bias"}, | |
150 | {"ADC", NULL, "Input Mux"}, | |
151 | ||
152 | /* inputs */ | |
153 | {"Line Input", NULL, "LLINEIN"}, | |
154 | {"Line Input", NULL, "RLINEIN"}, | |
155 | {"Mic Bias", NULL, "MICIN"}, | |
156 | }; | |
157 | ||
158 | static int ssm2602_add_widgets(struct snd_soc_codec *codec) | |
159 | { | |
ce6120cc | 160 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
b7138212 | 161 | |
ce6120cc LG |
162 | snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets, |
163 | ARRAY_SIZE(ssm2602_dapm_widgets)); | |
164 | snd_soc_dapm_add_routes(dapm, audio_conn, ARRAY_SIZE(audio_conn)); | |
b7138212 | 165 | |
b7138212 CC |
166 | return 0; |
167 | } | |
168 | ||
169 | struct _coeff_div { | |
170 | u32 mclk; | |
171 | u32 rate; | |
172 | u16 fs; | |
173 | u8 sr:4; | |
174 | u8 bosr:1; | |
175 | u8 usb:1; | |
176 | }; | |
177 | ||
178 | /* codec mclk clock divider coefficients */ | |
179 | static const struct _coeff_div coeff_div[] = { | |
180 | /* 48k */ | |
181 | {12288000, 48000, 256, 0x0, 0x0, 0x0}, | |
182 | {18432000, 48000, 384, 0x0, 0x1, 0x0}, | |
183 | {12000000, 48000, 250, 0x0, 0x0, 0x1}, | |
184 | ||
185 | /* 32k */ | |
186 | {12288000, 32000, 384, 0x6, 0x0, 0x0}, | |
187 | {18432000, 32000, 576, 0x6, 0x1, 0x0}, | |
188 | {12000000, 32000, 375, 0x6, 0x0, 0x1}, | |
189 | ||
190 | /* 8k */ | |
191 | {12288000, 8000, 1536, 0x3, 0x0, 0x0}, | |
192 | {18432000, 8000, 2304, 0x3, 0x1, 0x0}, | |
193 | {11289600, 8000, 1408, 0xb, 0x0, 0x0}, | |
194 | {16934400, 8000, 2112, 0xb, 0x1, 0x0}, | |
195 | {12000000, 8000, 1500, 0x3, 0x0, 0x1}, | |
196 | ||
197 | /* 96k */ | |
198 | {12288000, 96000, 128, 0x7, 0x0, 0x0}, | |
199 | {18432000, 96000, 192, 0x7, 0x1, 0x0}, | |
200 | {12000000, 96000, 125, 0x7, 0x0, 0x1}, | |
201 | ||
202 | /* 44.1k */ | |
203 | {11289600, 44100, 256, 0x8, 0x0, 0x0}, | |
204 | {16934400, 44100, 384, 0x8, 0x1, 0x0}, | |
205 | {12000000, 44100, 272, 0x8, 0x1, 0x1}, | |
206 | ||
207 | /* 88.2k */ | |
208 | {11289600, 88200, 128, 0xf, 0x0, 0x0}, | |
209 | {16934400, 88200, 192, 0xf, 0x1, 0x0}, | |
210 | {12000000, 88200, 136, 0xf, 0x1, 0x1}, | |
211 | }; | |
212 | ||
213 | static inline int get_coeff(int mclk, int rate) | |
214 | { | |
215 | int i; | |
216 | ||
217 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { | |
218 | if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) | |
219 | return i; | |
220 | } | |
221 | return i; | |
222 | } | |
223 | ||
224 | static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |
dee89c4d MB |
225 | struct snd_pcm_hw_params *params, |
226 | struct snd_soc_dai *dai) | |
b7138212 CC |
227 | { |
228 | u16 srate; | |
229 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 230 | struct snd_soc_codec *codec = rtd->codec; |
b2c812e2 | 231 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
93547e89 | 232 | u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3; |
b7138212 CC |
233 | int i = get_coeff(ssm2602->sysclk, params_rate(params)); |
234 | ||
faab5a32 | 235 | if (substream == ssm2602->slave_substream) { |
93547e89 | 236 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); |
faab5a32 KB |
237 | return 0; |
238 | } | |
239 | ||
b7138212 CC |
240 | /*no match is found*/ |
241 | if (i == ARRAY_SIZE(coeff_div)) | |
242 | return -EINVAL; | |
243 | ||
244 | srate = (coeff_div[i].sr << 2) | | |
245 | (coeff_div[i].bosr << 1) | coeff_div[i].usb; | |
246 | ||
93547e89 CC |
247 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
248 | snd_soc_write(codec, SSM2602_SRATE, srate); | |
b7138212 CC |
249 | |
250 | /* bit size */ | |
251 | switch (params_format(params)) { | |
252 | case SNDRV_PCM_FORMAT_S16_LE: | |
253 | break; | |
254 | case SNDRV_PCM_FORMAT_S20_3LE: | |
255 | iface |= 0x0004; | |
256 | break; | |
257 | case SNDRV_PCM_FORMAT_S24_LE: | |
258 | iface |= 0x0008; | |
259 | break; | |
260 | case SNDRV_PCM_FORMAT_S32_LE: | |
261 | iface |= 0x000c; | |
262 | break; | |
263 | } | |
93547e89 CC |
264 | snd_soc_write(codec, SSM2602_IFACE, iface); |
265 | snd_soc_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); | |
b7138212 CC |
266 | return 0; |
267 | } | |
268 | ||
dee89c4d MB |
269 | static int ssm2602_startup(struct snd_pcm_substream *substream, |
270 | struct snd_soc_dai *dai) | |
b7138212 CC |
271 | { |
272 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 273 | struct snd_soc_codec *codec = rtd->codec; |
b2c812e2 | 274 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
faab5a32 | 275 | struct i2c_client *i2c = codec->control_data; |
b7138212 CC |
276 | struct snd_pcm_runtime *master_runtime; |
277 | ||
278 | /* The DAI has shared clocks so if we already have a playback or | |
279 | * capture going then constrain this substream to match it. | |
faab5a32 | 280 | * TODO: the ssm2602 allows pairs of non-matching PB/REC rates |
b7138212 CC |
281 | */ |
282 | if (ssm2602->master_substream) { | |
283 | master_runtime = ssm2602->master_substream->runtime; | |
faab5a32 KB |
284 | dev_dbg(&i2c->dev, "Constraining to %d bits at %dHz\n", |
285 | master_runtime->sample_bits, | |
286 | master_runtime->rate); | |
287 | ||
f692fce0 CC |
288 | if (master_runtime->rate != 0) |
289 | snd_pcm_hw_constraint_minmax(substream->runtime, | |
290 | SNDRV_PCM_HW_PARAM_RATE, | |
291 | master_runtime->rate, | |
292 | master_runtime->rate); | |
293 | ||
294 | if (master_runtime->sample_bits != 0) | |
295 | snd_pcm_hw_constraint_minmax(substream->runtime, | |
296 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, | |
297 | master_runtime->sample_bits, | |
298 | master_runtime->sample_bits); | |
b7138212 CC |
299 | |
300 | ssm2602->slave_substream = substream; | |
301 | } else | |
302 | ssm2602->master_substream = substream; | |
303 | ||
304 | return 0; | |
305 | } | |
306 | ||
dee89c4d MB |
307 | static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream, |
308 | struct snd_soc_dai *dai) | |
b7138212 CC |
309 | { |
310 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 311 | struct snd_soc_codec *codec = rtd->codec; |
b7138212 | 312 | /* set active */ |
93547e89 | 313 | snd_soc_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); |
b7138212 CC |
314 | |
315 | return 0; | |
316 | } | |
317 | ||
dee89c4d MB |
318 | static void ssm2602_shutdown(struct snd_pcm_substream *substream, |
319 | struct snd_soc_dai *dai) | |
b7138212 CC |
320 | { |
321 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 322 | struct snd_soc_codec *codec = rtd->codec; |
b2c812e2 | 323 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
f692fce0 | 324 | |
b7138212 CC |
325 | /* deactivate */ |
326 | if (!codec->active) | |
93547e89 | 327 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
faab5a32 KB |
328 | |
329 | if (ssm2602->master_substream == substream) | |
330 | ssm2602->master_substream = ssm2602->slave_substream; | |
331 | ||
332 | ssm2602->slave_substream = NULL; | |
b7138212 CC |
333 | } |
334 | ||
335 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) | |
336 | { | |
337 | struct snd_soc_codec *codec = dai->codec; | |
93547e89 | 338 | u16 mute_reg = snd_soc_read(codec, SSM2602_APDIGI) & ~APDIGI_ENABLE_DAC_MUTE; |
b7138212 | 339 | if (mute) |
93547e89 | 340 | snd_soc_write(codec, SSM2602_APDIGI, |
b7138212 CC |
341 | mute_reg | APDIGI_ENABLE_DAC_MUTE); |
342 | else | |
93547e89 | 343 | snd_soc_write(codec, SSM2602_APDIGI, mute_reg); |
b7138212 CC |
344 | return 0; |
345 | } | |
346 | ||
347 | static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |
348 | int clk_id, unsigned int freq, int dir) | |
349 | { | |
350 | struct snd_soc_codec *codec = codec_dai->codec; | |
b2c812e2 | 351 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
b7138212 CC |
352 | switch (freq) { |
353 | case 11289600: | |
354 | case 12000000: | |
355 | case 12288000: | |
356 | case 16934400: | |
357 | case 18432000: | |
358 | ssm2602->sysclk = freq; | |
359 | return 0; | |
360 | } | |
361 | return -EINVAL; | |
362 | } | |
363 | ||
364 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | |
365 | unsigned int fmt) | |
366 | { | |
367 | struct snd_soc_codec *codec = codec_dai->codec; | |
368 | u16 iface = 0; | |
369 | ||
370 | /* set master/slave audio interface */ | |
371 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | |
372 | case SND_SOC_DAIFMT_CBM_CFM: | |
373 | iface |= 0x0040; | |
374 | break; | |
375 | case SND_SOC_DAIFMT_CBS_CFS: | |
376 | break; | |
377 | default: | |
378 | return -EINVAL; | |
379 | } | |
380 | ||
381 | /* interface format */ | |
382 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
383 | case SND_SOC_DAIFMT_I2S: | |
384 | iface |= 0x0002; | |
385 | break; | |
386 | case SND_SOC_DAIFMT_RIGHT_J: | |
387 | break; | |
388 | case SND_SOC_DAIFMT_LEFT_J: | |
389 | iface |= 0x0001; | |
390 | break; | |
391 | case SND_SOC_DAIFMT_DSP_A: | |
c6913485 | 392 | iface |= 0x0013; |
b7138212 CC |
393 | break; |
394 | case SND_SOC_DAIFMT_DSP_B: | |
c6913485 | 395 | iface |= 0x0003; |
b7138212 CC |
396 | break; |
397 | default: | |
398 | return -EINVAL; | |
399 | } | |
400 | ||
401 | /* clock inversion */ | |
402 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | |
403 | case SND_SOC_DAIFMT_NB_NF: | |
404 | break; | |
405 | case SND_SOC_DAIFMT_IB_IF: | |
406 | iface |= 0x0090; | |
407 | break; | |
408 | case SND_SOC_DAIFMT_IB_NF: | |
409 | iface |= 0x0080; | |
410 | break; | |
411 | case SND_SOC_DAIFMT_NB_IF: | |
412 | iface |= 0x0010; | |
413 | break; | |
414 | default: | |
415 | return -EINVAL; | |
416 | } | |
417 | ||
418 | /* set iface */ | |
93547e89 | 419 | snd_soc_write(codec, SSM2602_IFACE, iface); |
b7138212 CC |
420 | return 0; |
421 | } | |
422 | ||
423 | static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |
424 | enum snd_soc_bias_level level) | |
425 | { | |
93547e89 | 426 | u16 reg = snd_soc_read(codec, SSM2602_PWR) & 0xff7f; |
b7138212 CC |
427 | |
428 | switch (level) { | |
429 | case SND_SOC_BIAS_ON: | |
430 | /* vref/mid, osc on, dac unmute */ | |
93547e89 | 431 | snd_soc_write(codec, SSM2602_PWR, reg); |
b7138212 CC |
432 | break; |
433 | case SND_SOC_BIAS_PREPARE: | |
434 | break; | |
435 | case SND_SOC_BIAS_STANDBY: | |
436 | /* everything off except vref/vmid, */ | |
93547e89 | 437 | snd_soc_write(codec, SSM2602_PWR, reg | PWR_CLK_OUT_PDN); |
b7138212 CC |
438 | break; |
439 | case SND_SOC_BIAS_OFF: | |
440 | /* everything off, dac mute, inactive */ | |
93547e89 CC |
441 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
442 | snd_soc_write(codec, SSM2602_PWR, 0xffff); | |
b7138212 CC |
443 | break; |
444 | ||
445 | } | |
ce6120cc | 446 | codec->dapm.bias_level = level; |
b7138212 CC |
447 | return 0; |
448 | } | |
449 | ||
2552a710 CC |
450 | #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_32000 |\ |
451 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ | |
452 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) | |
b7138212 | 453 | |
5de27b6c KB |
454 | #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
455 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | |
456 | ||
6335d055 EM |
457 | static struct snd_soc_dai_ops ssm2602_dai_ops = { |
458 | .startup = ssm2602_startup, | |
459 | .prepare = ssm2602_pcm_prepare, | |
460 | .hw_params = ssm2602_hw_params, | |
461 | .shutdown = ssm2602_shutdown, | |
462 | .digital_mute = ssm2602_mute, | |
463 | .set_sysclk = ssm2602_set_dai_sysclk, | |
464 | .set_fmt = ssm2602_set_dai_fmt, | |
465 | }; | |
466 | ||
f0fba2ad LG |
467 | static struct snd_soc_dai_driver ssm2602_dai = { |
468 | .name = "ssm2602-hifi", | |
b7138212 CC |
469 | .playback = { |
470 | .stream_name = "Playback", | |
471 | .channels_min = 2, | |
472 | .channels_max = 2, | |
473 | .rates = SSM2602_RATES, | |
5de27b6c | 474 | .formats = SSM2602_FORMATS,}, |
b7138212 CC |
475 | .capture = { |
476 | .stream_name = "Capture", | |
477 | .channels_min = 2, | |
478 | .channels_max = 2, | |
479 | .rates = SSM2602_RATES, | |
5de27b6c | 480 | .formats = SSM2602_FORMATS,}, |
6335d055 | 481 | .ops = &ssm2602_dai_ops, |
b7138212 | 482 | }; |
b7138212 | 483 | |
f0fba2ad | 484 | static int ssm2602_suspend(struct snd_soc_codec *codec, pm_message_t state) |
b7138212 | 485 | { |
b7138212 CC |
486 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); |
487 | return 0; | |
488 | } | |
489 | ||
f0fba2ad | 490 | static int ssm2602_resume(struct snd_soc_codec *codec) |
b7138212 | 491 | { |
93547e89 CC |
492 | snd_soc_cache_sync(codec); |
493 | ||
b7138212 | 494 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
93547e89 | 495 | |
b7138212 CC |
496 | return 0; |
497 | } | |
498 | ||
f0fba2ad | 499 | static int ssm2602_probe(struct snd_soc_codec *codec) |
b7138212 | 500 | { |
f0fba2ad LG |
501 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
502 | int ret = 0, reg; | |
503 | ||
504 | pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); | |
505 | ||
93547e89 CC |
506 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, ssm2602->control_type); |
507 | if (ret < 0) { | |
508 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | |
509 | return ret; | |
510 | } | |
b7138212 | 511 | |
93547e89 CC |
512 | ret = ssm2602_reset(codec); |
513 | if (ret < 0) { | |
514 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); | |
515 | return ret; | |
516 | } | |
b7138212 | 517 | |
b7138212 | 518 | /*power on device*/ |
93547e89 | 519 | snd_soc_write(codec, SSM2602_ACTIVE, 0); |
b7138212 | 520 | /* set the update bits */ |
93547e89 CC |
521 | reg = snd_soc_read(codec, SSM2602_LINVOL); |
522 | snd_soc_write(codec, SSM2602_LINVOL, reg | LINVOL_LRIN_BOTH); | |
523 | reg = snd_soc_read(codec, SSM2602_RINVOL); | |
524 | snd_soc_write(codec, SSM2602_RINVOL, reg | RINVOL_RLIN_BOTH); | |
525 | reg = snd_soc_read(codec, SSM2602_LOUT1V); | |
526 | snd_soc_write(codec, SSM2602_LOUT1V, reg | LOUT1V_LRHP_BOTH); | |
527 | reg = snd_soc_read(codec, SSM2602_ROUT1V); | |
528 | snd_soc_write(codec, SSM2602_ROUT1V, reg | ROUT1V_RLHP_BOTH); | |
b7138212 | 529 | /*select Line in as default input*/ |
93547e89 | 530 | snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC | |
b7138212 | 531 | APANA_ENABLE_MIC_BOOST); |
93547e89 | 532 | snd_soc_write(codec, SSM2602_PWR, 0); |
b7138212 | 533 | |
3e8e1952 IM |
534 | snd_soc_add_controls(codec, ssm2602_snd_controls, |
535 | ARRAY_SIZE(ssm2602_snd_controls)); | |
b7138212 | 536 | ssm2602_add_widgets(codec); |
b7138212 | 537 | |
93547e89 | 538 | return 0; |
f0fba2ad | 539 | } |
b7138212 | 540 | |
f0fba2ad LG |
541 | /* remove everything here */ |
542 | static int ssm2602_remove(struct snd_soc_codec *codec) | |
543 | { | |
544 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); | |
545 | return 0; | |
b7138212 CC |
546 | } |
547 | ||
f0fba2ad LG |
548 | static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { |
549 | .probe = ssm2602_probe, | |
550 | .remove = ssm2602_remove, | |
551 | .suspend = ssm2602_suspend, | |
552 | .resume = ssm2602_resume, | |
f0fba2ad LG |
553 | .set_bias_level = ssm2602_set_bias_level, |
554 | .reg_cache_size = sizeof(ssm2602_reg), | |
555 | .reg_word_size = sizeof(u16), | |
556 | .reg_cache_default = ssm2602_reg, | |
557 | }; | |
b7138212 CC |
558 | |
559 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | |
560 | /* | |
561 | * ssm2602 2 wire address is determined by GPIO5 | |
562 | * state during powerup. | |
563 | * low = 0x1a | |
564 | * high = 0x1b | |
565 | */ | |
566 | static int ssm2602_i2c_probe(struct i2c_client *i2c, | |
567 | const struct i2c_device_id *id) | |
568 | { | |
f0fba2ad | 569 | struct ssm2602_priv *ssm2602; |
b7138212 CC |
570 | int ret; |
571 | ||
f0fba2ad LG |
572 | ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL); |
573 | if (ssm2602 == NULL) | |
574 | return -ENOMEM; | |
b7138212 | 575 | |
f0fba2ad | 576 | i2c_set_clientdata(i2c, ssm2602); |
f0fba2ad | 577 | ssm2602->control_type = SND_SOC_I2C; |
b7138212 | 578 | |
f0fba2ad LG |
579 | ret = snd_soc_register_codec(&i2c->dev, |
580 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); | |
581 | if (ret < 0) | |
582 | kfree(ssm2602); | |
b7138212 CC |
583 | return ret; |
584 | } | |
585 | ||
586 | static int ssm2602_i2c_remove(struct i2c_client *client) | |
587 | { | |
f0fba2ad LG |
588 | snd_soc_unregister_codec(&client->dev); |
589 | kfree(i2c_get_clientdata(client)); | |
b7138212 CC |
590 | return 0; |
591 | } | |
592 | ||
593 | static const struct i2c_device_id ssm2602_i2c_id[] = { | |
594 | { "ssm2602", 0 }, | |
595 | { } | |
596 | }; | |
597 | MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id); | |
f0fba2ad | 598 | |
b7138212 CC |
599 | /* corgi i2c codec control layer */ |
600 | static struct i2c_driver ssm2602_i2c_driver = { | |
601 | .driver = { | |
2a161018 | 602 | .name = "ssm2602", |
b7138212 CC |
603 | .owner = THIS_MODULE, |
604 | }, | |
605 | .probe = ssm2602_i2c_probe, | |
606 | .remove = ssm2602_i2c_remove, | |
607 | .id_table = ssm2602_i2c_id, | |
608 | }; | |
b7138212 CC |
609 | #endif |
610 | ||
f0fba2ad LG |
611 | |
612 | static int __init ssm2602_modinit(void) | |
b7138212 | 613 | { |
b7138212 | 614 | int ret = 0; |
b7138212 | 615 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
f0fba2ad LG |
616 | ret = i2c_add_driver(&ssm2602_i2c_driver); |
617 | if (ret != 0) { | |
618 | printk(KERN_ERR "Failed to register SSM2602 I2C driver: %d\n", | |
619 | ret); | |
b7138212 | 620 | } |
b7138212 CC |
621 | #endif |
622 | return ret; | |
623 | } | |
f0fba2ad | 624 | module_init(ssm2602_modinit); |
b7138212 | 625 | |
f0fba2ad | 626 | static void __exit ssm2602_exit(void) |
b7138212 | 627 | { |
b7138212 | 628 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
b7138212 CC |
629 | i2c_del_driver(&ssm2602_i2c_driver); |
630 | #endif | |
64089b84 MB |
631 | } |
632 | module_exit(ssm2602_exit); | |
633 | ||
b7138212 CC |
634 | MODULE_DESCRIPTION("ASoC ssm2602 driver"); |
635 | MODULE_AUTHOR("Cliff Cai"); | |
636 | MODULE_LICENSE("GPL"); |