Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[linux/fpc-iii.git] / sound / soc / codecs / ssm2602.c
blob69a773aeb13dbbb05906e54498b4b2300f7cba77
1 /*
2 * File: sound/soc/codecs/ssm2602.c
3 * Author: Cliff Cai <Cliff.Cai@analog.com>
5 * Created: Tue June 06 2008
6 * Description: Driver for ssm2602 sound chip
8 * Modified:
9 * Copyright 2008 Analog Devices Inc.
11 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
29 #include <linux/module.h>
30 #include <linux/regmap.h>
31 #include <linux/slab.h>
33 #include <sound/pcm.h>
34 #include <sound/pcm_params.h>
35 #include <sound/soc.h>
36 #include <sound/tlv.h>
38 #include "ssm2602.h"
40 /* codec private data */
41 struct ssm2602_priv {
42 unsigned int sysclk;
43 const struct snd_pcm_hw_constraint_list *sysclk_constraints;
45 struct regmap *regmap;
47 enum ssm2602_type type;
48 unsigned int clk_out_pwr;
52 * ssm2602 register cache
53 * We can't read the ssm2602 register space when we are
54 * using 2 wire for device control, so we cache them instead.
55 * There is no point in caching the reset register
57 static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
58 0x0097, 0x0097, 0x0079, 0x0079,
59 0x000a, 0x0008, 0x009f, 0x000a,
60 0x0000, 0x0000
64 /*Appending several "None"s just for OSS mixer use*/
65 static const char *ssm2602_input_select[] = {
66 "Line", "Mic",
69 static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
71 static const struct soc_enum ssm2602_enum[] = {
72 SOC_ENUM_SINGLE(SSM2602_APANA, 2, ARRAY_SIZE(ssm2602_input_select),
73 ssm2602_input_select),
74 SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, ARRAY_SIZE(ssm2602_deemph),
75 ssm2602_deemph),
78 static const unsigned int ssm260x_outmix_tlv[] = {
79 TLV_DB_RANGE_HEAD(2),
80 0, 47, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
81 48, 127, TLV_DB_SCALE_ITEM(-7400, 100, 0),
84 static const DECLARE_TLV_DB_SCALE(ssm260x_inpga_tlv, -3450, 150, 0);
85 static const DECLARE_TLV_DB_SCALE(ssm260x_sidetone_tlv, -1500, 300, 0);
87 static const struct snd_kcontrol_new ssm260x_snd_controls[] = {
88 SOC_DOUBLE_R_TLV("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 45, 0,
89 ssm260x_inpga_tlv),
90 SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1),
92 SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1),
93 SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0),
95 SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]),
98 static const struct snd_kcontrol_new ssm2602_snd_controls[] = {
99 SOC_DOUBLE_R_TLV("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V,
100 0, 127, 0, ssm260x_outmix_tlv),
101 SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V,
102 7, 1, 0),
103 SOC_SINGLE_TLV("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1,
104 ssm260x_sidetone_tlv),
106 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
107 SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0),
108 SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
111 /* Output Mixer */
112 static const struct snd_kcontrol_new ssm260x_output_mixer_controls[] = {
113 SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0),
114 SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0),
115 SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0),
118 /* Input mux */
119 static const struct snd_kcontrol_new ssm2602_input_mux_controls =
120 SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]);
122 static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = {
123 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1),
124 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1),
125 SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0),
127 SND_SOC_DAPM_SUPPLY("Digital Core Power", SSM2602_ACTIVE, 0, 0, NULL, 0),
129 SND_SOC_DAPM_OUTPUT("LOUT"),
130 SND_SOC_DAPM_OUTPUT("ROUT"),
131 SND_SOC_DAPM_INPUT("RLINEIN"),
132 SND_SOC_DAPM_INPUT("LLINEIN"),
135 static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = {
136 SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1,
137 ssm260x_output_mixer_controls,
138 ARRAY_SIZE(ssm260x_output_mixer_controls)),
140 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls),
141 SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1),
143 SND_SOC_DAPM_OUTPUT("LHPOUT"),
144 SND_SOC_DAPM_OUTPUT("RHPOUT"),
145 SND_SOC_DAPM_INPUT("MICIN"),
148 static const struct snd_soc_dapm_widget ssm2604_dapm_widgets[] = {
149 SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0,
150 ssm260x_output_mixer_controls,
151 ARRAY_SIZE(ssm260x_output_mixer_controls) - 1), /* Last element is the mic */
154 static const struct snd_soc_dapm_route ssm260x_routes[] = {
155 {"DAC", NULL, "Digital Core Power"},
156 {"ADC", NULL, "Digital Core Power"},
158 {"Output Mixer", "Line Bypass Switch", "Line Input"},
159 {"Output Mixer", "HiFi Playback Switch", "DAC"},
161 {"ROUT", NULL, "Output Mixer"},
162 {"LOUT", NULL, "Output Mixer"},
164 {"Line Input", NULL, "LLINEIN"},
165 {"Line Input", NULL, "RLINEIN"},
168 static const struct snd_soc_dapm_route ssm2602_routes[] = {
169 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
171 {"RHPOUT", NULL, "Output Mixer"},
172 {"LHPOUT", NULL, "Output Mixer"},
174 {"Input Mux", "Line", "Line Input"},
175 {"Input Mux", "Mic", "Mic Bias"},
176 {"ADC", NULL, "Input Mux"},
178 {"Mic Bias", NULL, "MICIN"},
181 static const struct snd_soc_dapm_route ssm2604_routes[] = {
182 {"ADC", NULL, "Line Input"},
185 static const unsigned int ssm2602_rates_12288000[] = {
186 8000, 16000, 32000, 48000, 96000,
189 static const struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
190 .list = ssm2602_rates_12288000,
191 .count = ARRAY_SIZE(ssm2602_rates_12288000),
194 static const unsigned int ssm2602_rates_11289600[] = {
195 8000, 11025, 22050, 44100, 88200,
198 static const struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
199 .list = ssm2602_rates_11289600,
200 .count = ARRAY_SIZE(ssm2602_rates_11289600),
203 struct ssm2602_coeff {
204 u32 mclk;
205 u32 rate;
206 u8 srate;
209 #define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb))
211 /* codec mclk clock coefficients */
212 static const struct ssm2602_coeff ssm2602_coeff_table[] = {
213 /* 48k */
214 {12288000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x0)},
215 {18432000, 48000, SSM2602_COEFF_SRATE(0x0, 0x1, 0x0)},
216 {12000000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x1)},
218 /* 32k */
219 {12288000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x0)},
220 {18432000, 32000, SSM2602_COEFF_SRATE(0x6, 0x1, 0x0)},
221 {12000000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x1)},
223 /* 16k */
224 {12288000, 16000, SSM2602_COEFF_SRATE(0x5, 0x0, 0x0)},
225 {18432000, 16000, SSM2602_COEFF_SRATE(0x5, 0x1, 0x0)},
226 {12000000, 16000, SSM2602_COEFF_SRATE(0xa, 0x0, 0x1)},
228 /* 8k */
229 {12288000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x0)},
230 {18432000, 8000, SSM2602_COEFF_SRATE(0x3, 0x1, 0x0)},
231 {11289600, 8000, SSM2602_COEFF_SRATE(0xb, 0x0, 0x0)},
232 {16934400, 8000, SSM2602_COEFF_SRATE(0xb, 0x1, 0x0)},
233 {12000000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x1)},
235 /* 96k */
236 {12288000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x0)},
237 {18432000, 96000, SSM2602_COEFF_SRATE(0x7, 0x1, 0x0)},
238 {12000000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x1)},
240 /* 11.025k */
241 {11289600, 11025, SSM2602_COEFF_SRATE(0xc, 0x0, 0x0)},
242 {16934400, 11025, SSM2602_COEFF_SRATE(0xc, 0x1, 0x0)},
243 {12000000, 11025, SSM2602_COEFF_SRATE(0xc, 0x1, 0x1)},
245 /* 22.05k */
246 {11289600, 22050, SSM2602_COEFF_SRATE(0xd, 0x0, 0x0)},
247 {16934400, 22050, SSM2602_COEFF_SRATE(0xd, 0x1, 0x0)},
248 {12000000, 22050, SSM2602_COEFF_SRATE(0xd, 0x1, 0x1)},
250 /* 44.1k */
251 {11289600, 44100, SSM2602_COEFF_SRATE(0x8, 0x0, 0x0)},
252 {16934400, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x0)},
253 {12000000, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x1)},
255 /* 88.2k */
256 {11289600, 88200, SSM2602_COEFF_SRATE(0xf, 0x0, 0x0)},
257 {16934400, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x0)},
258 {12000000, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x1)},
261 static inline int ssm2602_get_coeff(int mclk, int rate)
263 int i;
265 for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) {
266 if (ssm2602_coeff_table[i].rate == rate &&
267 ssm2602_coeff_table[i].mclk == mclk)
268 return ssm2602_coeff_table[i].srate;
270 return -EINVAL;
273 static int ssm2602_hw_params(struct snd_pcm_substream *substream,
274 struct snd_pcm_hw_params *params,
275 struct snd_soc_dai *dai)
277 struct snd_soc_codec *codec = dai->codec;
278 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
279 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
280 unsigned int iface;
282 if (srate < 0)
283 return srate;
285 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate);
287 /* bit size */
288 switch (params_width(params)) {
289 case 16:
290 iface = 0x0;
291 break;
292 case 20:
293 iface = 0x4;
294 break;
295 case 24:
296 iface = 0x8;
297 break;
298 case 32:
299 iface = 0xc;
300 break;
301 default:
302 return -EINVAL;
304 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE,
305 IFACE_AUDIO_DATA_LEN, iface);
306 return 0;
309 static int ssm2602_startup(struct snd_pcm_substream *substream,
310 struct snd_soc_dai *dai)
312 struct snd_soc_codec *codec = dai->codec;
313 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
315 if (ssm2602->sysclk_constraints) {
316 snd_pcm_hw_constraint_list(substream->runtime, 0,
317 SNDRV_PCM_HW_PARAM_RATE,
318 ssm2602->sysclk_constraints);
321 return 0;
324 static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
326 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec);
328 if (mute)
329 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
330 APDIGI_ENABLE_DAC_MUTE,
331 APDIGI_ENABLE_DAC_MUTE);
332 else
333 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
334 APDIGI_ENABLE_DAC_MUTE, 0);
335 return 0;
338 static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
339 int clk_id, unsigned int freq, int dir)
341 struct snd_soc_codec *codec = codec_dai->codec;
342 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
344 if (dir == SND_SOC_CLOCK_IN) {
345 if (clk_id != SSM2602_SYSCLK)
346 return -EINVAL;
348 switch (freq) {
349 case 12288000:
350 case 18432000:
351 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000;
352 break;
353 case 11289600:
354 case 16934400:
355 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600;
356 break;
357 case 12000000:
358 ssm2602->sysclk_constraints = NULL;
359 break;
360 default:
361 return -EINVAL;
363 ssm2602->sysclk = freq;
364 } else {
365 unsigned int mask;
367 switch (clk_id) {
368 case SSM2602_CLK_CLKOUT:
369 mask = PWR_CLK_OUT_PDN;
370 break;
371 case SSM2602_CLK_XTO:
372 mask = PWR_OSC_PDN;
373 break;
374 default:
375 return -EINVAL;
378 if (freq == 0)
379 ssm2602->clk_out_pwr |= mask;
380 else
381 ssm2602->clk_out_pwr &= ~mask;
383 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
384 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
387 return 0;
390 static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
391 unsigned int fmt)
393 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec);
394 unsigned int iface = 0;
396 /* set master/slave audio interface */
397 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
398 case SND_SOC_DAIFMT_CBM_CFM:
399 iface |= 0x0040;
400 break;
401 case SND_SOC_DAIFMT_CBS_CFS:
402 break;
403 default:
404 return -EINVAL;
407 /* interface format */
408 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
409 case SND_SOC_DAIFMT_I2S:
410 iface |= 0x0002;
411 break;
412 case SND_SOC_DAIFMT_RIGHT_J:
413 break;
414 case SND_SOC_DAIFMT_LEFT_J:
415 iface |= 0x0001;
416 break;
417 case SND_SOC_DAIFMT_DSP_A:
418 iface |= 0x0013;
419 break;
420 case SND_SOC_DAIFMT_DSP_B:
421 iface |= 0x0003;
422 break;
423 default:
424 return -EINVAL;
427 /* clock inversion */
428 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
429 case SND_SOC_DAIFMT_NB_NF:
430 break;
431 case SND_SOC_DAIFMT_IB_IF:
432 iface |= 0x0090;
433 break;
434 case SND_SOC_DAIFMT_IB_NF:
435 iface |= 0x0080;
436 break;
437 case SND_SOC_DAIFMT_NB_IF:
438 iface |= 0x0010;
439 break;
440 default:
441 return -EINVAL;
444 /* set iface */
445 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface);
446 return 0;
449 static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
450 enum snd_soc_bias_level level)
452 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
454 switch (level) {
455 case SND_SOC_BIAS_ON:
456 /* vref/mid on, osc and clkout on if enabled */
457 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
458 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
459 ssm2602->clk_out_pwr);
460 break;
461 case SND_SOC_BIAS_PREPARE:
462 break;
463 case SND_SOC_BIAS_STANDBY:
464 /* everything off except vref/vmid, */
465 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
466 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
467 PWR_CLK_OUT_PDN | PWR_OSC_PDN);
468 break;
469 case SND_SOC_BIAS_OFF:
470 /* everything off */
471 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
472 PWR_POWER_OFF, PWR_POWER_OFF);
473 break;
476 return 0;
479 #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
480 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
481 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
482 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
483 SNDRV_PCM_RATE_96000)
485 #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
486 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
488 static const struct snd_soc_dai_ops ssm2602_dai_ops = {
489 .startup = ssm2602_startup,
490 .hw_params = ssm2602_hw_params,
491 .digital_mute = ssm2602_mute,
492 .set_sysclk = ssm2602_set_dai_sysclk,
493 .set_fmt = ssm2602_set_dai_fmt,
496 static struct snd_soc_dai_driver ssm2602_dai = {
497 .name = "ssm2602-hifi",
498 .playback = {
499 .stream_name = "Playback",
500 .channels_min = 2,
501 .channels_max = 2,
502 .rates = SSM2602_RATES,
503 .formats = SSM2602_FORMATS,},
504 .capture = {
505 .stream_name = "Capture",
506 .channels_min = 2,
507 .channels_max = 2,
508 .rates = SSM2602_RATES,
509 .formats = SSM2602_FORMATS,},
510 .ops = &ssm2602_dai_ops,
511 .symmetric_rates = 1,
512 .symmetric_samplebits = 1,
515 static int ssm2602_resume(struct snd_soc_codec *codec)
517 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
519 regcache_sync(ssm2602->regmap);
521 return 0;
524 static int ssm2602_codec_probe(struct snd_soc_codec *codec)
526 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
527 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
528 int ret;
530 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V,
531 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
532 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V,
533 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
535 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls,
536 ARRAY_SIZE(ssm2602_snd_controls));
537 if (ret)
538 return ret;
540 ret = snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets,
541 ARRAY_SIZE(ssm2602_dapm_widgets));
542 if (ret)
543 return ret;
545 return snd_soc_dapm_add_routes(dapm, ssm2602_routes,
546 ARRAY_SIZE(ssm2602_routes));
549 static int ssm2604_codec_probe(struct snd_soc_codec *codec)
551 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
552 int ret;
554 ret = snd_soc_dapm_new_controls(dapm, ssm2604_dapm_widgets,
555 ARRAY_SIZE(ssm2604_dapm_widgets));
556 if (ret)
557 return ret;
559 return snd_soc_dapm_add_routes(dapm, ssm2604_routes,
560 ARRAY_SIZE(ssm2604_routes));
563 static int ssm260x_codec_probe(struct snd_soc_codec *codec)
565 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
566 int ret;
568 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
569 if (ret < 0) {
570 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
571 return ret;
574 /* set the update bits */
575 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
576 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
577 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL,
578 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
579 /*select Line in as default input*/
580 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC |
581 APANA_ENABLE_MIC_BOOST);
583 switch (ssm2602->type) {
584 case SSM2602:
585 ret = ssm2602_codec_probe(codec);
586 break;
587 case SSM2604:
588 ret = ssm2604_codec_probe(codec);
589 break;
592 return ret;
595 static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
596 .probe = ssm260x_codec_probe,
597 .resume = ssm2602_resume,
598 .set_bias_level = ssm2602_set_bias_level,
599 .suspend_bias_off = true,
601 .controls = ssm260x_snd_controls,
602 .num_controls = ARRAY_SIZE(ssm260x_snd_controls),
603 .dapm_widgets = ssm260x_dapm_widgets,
604 .num_dapm_widgets = ARRAY_SIZE(ssm260x_dapm_widgets),
605 .dapm_routes = ssm260x_routes,
606 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes),
609 static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
611 return reg == SSM2602_RESET;
614 const struct regmap_config ssm2602_regmap_config = {
615 .val_bits = 9,
616 .reg_bits = 7,
618 .max_register = SSM2602_RESET,
619 .volatile_reg = ssm2602_register_volatile,
621 .cache_type = REGCACHE_RBTREE,
622 .reg_defaults_raw = ssm2602_reg,
623 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
625 EXPORT_SYMBOL_GPL(ssm2602_regmap_config);
627 int ssm2602_probe(struct device *dev, enum ssm2602_type type,
628 struct regmap *regmap)
630 struct ssm2602_priv *ssm2602;
632 if (IS_ERR(regmap))
633 return PTR_ERR(regmap);
635 ssm2602 = devm_kzalloc(dev, sizeof(*ssm2602), GFP_KERNEL);
636 if (ssm2602 == NULL)
637 return -ENOMEM;
639 dev_set_drvdata(dev, ssm2602);
640 ssm2602->type = type;
641 ssm2602->regmap = regmap;
643 return snd_soc_register_codec(dev, &soc_codec_dev_ssm2602,
644 &ssm2602_dai, 1);
646 EXPORT_SYMBOL_GPL(ssm2602_probe);
648 MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver");
649 MODULE_AUTHOR("Cliff Cai");
650 MODULE_LICENSE("GPL");