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
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/moduleparam.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
34 #include <linux/i2c.h>
35 #include <linux/spi/spi.h>
36 #include <linux/regmap.h>
37 #include <linux/slab.h>
38 #include <sound/core.h>
39 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/soc.h>
42 #include <sound/initval.h>
43 #include <sound/tlv.h>
52 /* codec private data */
55 struct snd_pcm_hw_constraint_list *sysclk_constraints;
57 struct regmap *regmap;
59 enum ssm2602_type type;
60 unsigned int clk_out_pwr;
64 * ssm2602 register cache
65 * We can't read the ssm2602 register space when we are
66 * using 2 wire for device control, so we cache them instead.
67 * There is no point in caching the reset register
69 static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
70 0x0097, 0x0097, 0x0079, 0x0079,
71 0x000a, 0x0008, 0x009f, 0x000a,
76 /*Appending several "None"s just for OSS mixer use*/
77 static const char *ssm2602_input_select[] = {
78 "Line", "Mic", "None", "None", "None",
79 "None", "None", "None",
82 static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
84 static const struct soc_enum ssm2602_enum[] = {
85 SOC_ENUM_SINGLE(SSM2602_APANA, 2, 2, ssm2602_input_select),
86 SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, 4, ssm2602_deemph),
89 static const unsigned int ssm260x_outmix_tlv[] = {
91 0, 47, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
92 48, 127, TLV_DB_SCALE_ITEM(-7400, 100, 0),
95 static const DECLARE_TLV_DB_SCALE(ssm260x_inpga_tlv, -3450, 150, 0);
96 static const DECLARE_TLV_DB_SCALE(ssm260x_sidetone_tlv, -1500, 300, 0);
98 static const struct snd_kcontrol_new ssm260x_snd_controls[] = {
99 SOC_DOUBLE_R_TLV("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 45, 0,
101 SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1),
103 SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1),
104 SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0),
106 SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]),
109 static const struct snd_kcontrol_new ssm2602_snd_controls[] = {
110 SOC_DOUBLE_R_TLV("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V,
111 0, 127, 0, ssm260x_outmix_tlv),
112 SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V,
114 SOC_SINGLE_TLV("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1,
115 ssm260x_sidetone_tlv),
117 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
118 SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0),
119 SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
123 static const struct snd_kcontrol_new ssm260x_output_mixer_controls[] = {
124 SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0),
125 SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0),
126 SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0),
130 static const struct snd_kcontrol_new ssm2602_input_mux_controls =
131 SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]);
133 static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = {
134 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1),
135 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1),
136 SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0),
138 SND_SOC_DAPM_SUPPLY("Digital Core Power", SSM2602_ACTIVE, 0, 0, NULL, 0),
140 SND_SOC_DAPM_OUTPUT("LOUT"),
141 SND_SOC_DAPM_OUTPUT("ROUT"),
142 SND_SOC_DAPM_INPUT("RLINEIN"),
143 SND_SOC_DAPM_INPUT("LLINEIN"),
146 static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = {
147 SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1,
148 ssm260x_output_mixer_controls,
149 ARRAY_SIZE(ssm260x_output_mixer_controls)),
151 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls),
152 SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1),
154 SND_SOC_DAPM_OUTPUT("LHPOUT"),
155 SND_SOC_DAPM_OUTPUT("RHPOUT"),
156 SND_SOC_DAPM_INPUT("MICIN"),
159 static const struct snd_soc_dapm_widget ssm2604_dapm_widgets[] = {
160 SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0,
161 ssm260x_output_mixer_controls,
162 ARRAY_SIZE(ssm260x_output_mixer_controls) - 1), /* Last element is the mic */
165 static const struct snd_soc_dapm_route ssm260x_routes[] = {
166 {"DAC", NULL, "Digital Core Power"},
167 {"ADC", NULL, "Digital Core Power"},
169 {"Output Mixer", "Line Bypass Switch", "Line Input"},
170 {"Output Mixer", "HiFi Playback Switch", "DAC"},
172 {"ROUT", NULL, "Output Mixer"},
173 {"LOUT", NULL, "Output Mixer"},
175 {"Line Input", NULL, "LLINEIN"},
176 {"Line Input", NULL, "RLINEIN"},
179 static const struct snd_soc_dapm_route ssm2602_routes[] = {
180 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
182 {"RHPOUT", NULL, "Output Mixer"},
183 {"LHPOUT", NULL, "Output Mixer"},
185 {"Input Mux", "Line", "Line Input"},
186 {"Input Mux", "Mic", "Mic Bias"},
187 {"ADC", NULL, "Input Mux"},
189 {"Mic Bias", NULL, "MICIN"},
192 static const struct snd_soc_dapm_route ssm2604_routes[] = {
193 {"ADC", NULL, "Line Input"},
196 static const unsigned int ssm2602_rates_12288000[] = {
197 8000, 16000, 32000, 48000, 96000,
200 static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
201 .list = ssm2602_rates_12288000,
202 .count = ARRAY_SIZE(ssm2602_rates_12288000),
205 static const unsigned int ssm2602_rates_11289600[] = {
209 static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
210 .list = ssm2602_rates_11289600,
211 .count = ARRAY_SIZE(ssm2602_rates_11289600),
214 struct ssm2602_coeff {
220 #define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb))
222 /* codec mclk clock coefficients */
223 static const struct ssm2602_coeff ssm2602_coeff_table[] = {
225 {12288000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x0)},
226 {18432000, 48000, SSM2602_COEFF_SRATE(0x0, 0x1, 0x0)},
227 {12000000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x1)},
230 {12288000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x0)},
231 {18432000, 32000, SSM2602_COEFF_SRATE(0x6, 0x1, 0x0)},
232 {12000000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x1)},
235 {12288000, 16000, SSM2602_COEFF_SRATE(0x5, 0x0, 0x0)},
236 {18432000, 16000, SSM2602_COEFF_SRATE(0x5, 0x1, 0x0)},
237 {12000000, 16000, SSM2602_COEFF_SRATE(0xa, 0x0, 0x1)},
240 {12288000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x0)},
241 {18432000, 8000, SSM2602_COEFF_SRATE(0x3, 0x1, 0x0)},
242 {11289600, 8000, SSM2602_COEFF_SRATE(0xb, 0x0, 0x0)},
243 {16934400, 8000, SSM2602_COEFF_SRATE(0xb, 0x1, 0x0)},
244 {12000000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x1)},
247 {12288000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x0)},
248 {18432000, 96000, SSM2602_COEFF_SRATE(0x7, 0x1, 0x0)},
249 {12000000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x1)},
252 {11289600, 44100, SSM2602_COEFF_SRATE(0x8, 0x0, 0x0)},
253 {16934400, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x0)},
254 {12000000, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x1)},
257 {11289600, 88200, SSM2602_COEFF_SRATE(0xf, 0x0, 0x0)},
258 {16934400, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x0)},
259 {12000000, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x1)},
262 static inline int ssm2602_get_coeff(int mclk, int rate)
266 for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) {
267 if (ssm2602_coeff_table[i].rate == rate &&
268 ssm2602_coeff_table[i].mclk == mclk)
269 return ssm2602_coeff_table[i].srate;
274 static int ssm2602_hw_params(struct snd_pcm_substream *substream,
275 struct snd_pcm_hw_params *params,
276 struct snd_soc_dai *dai)
278 struct snd_soc_codec *codec = dai->codec;
279 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
280 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
286 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate);
289 switch (params_format(params)) {
290 case SNDRV_PCM_FORMAT_S16_LE:
293 case SNDRV_PCM_FORMAT_S20_3LE:
296 case SNDRV_PCM_FORMAT_S24_LE:
299 case SNDRV_PCM_FORMAT_S32_LE:
305 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE,
306 IFACE_AUDIO_DATA_LEN, iface);
310 static int ssm2602_startup(struct snd_pcm_substream *substream,
311 struct snd_soc_dai *dai)
313 struct snd_soc_codec *codec = dai->codec;
314 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
316 if (ssm2602->sysclk_constraints) {
317 snd_pcm_hw_constraint_list(substream->runtime, 0,
318 SNDRV_PCM_HW_PARAM_RATE,
319 ssm2602->sysclk_constraints);
325 static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
327 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec);
330 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
331 APDIGI_ENABLE_DAC_MUTE,
332 APDIGI_ENABLE_DAC_MUTE);
334 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
335 APDIGI_ENABLE_DAC_MUTE, 0);
339 static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
340 int clk_id, unsigned int freq, int dir)
342 struct snd_soc_codec *codec = codec_dai->codec;
343 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
345 if (dir == SND_SOC_CLOCK_IN) {
346 if (clk_id != SSM2602_SYSCLK)
352 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000;
356 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600;
359 ssm2602->sysclk_constraints = NULL;
364 ssm2602->sysclk = freq;
369 case SSM2602_CLK_CLKOUT:
370 mask = PWR_CLK_OUT_PDN;
372 case SSM2602_CLK_XTO:
380 ssm2602->clk_out_pwr |= mask;
382 ssm2602->clk_out_pwr &= ~mask;
384 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
385 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
391 static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
394 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec);
395 unsigned int iface = 0;
397 /* set master/slave audio interface */
398 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
399 case SND_SOC_DAIFMT_CBM_CFM:
402 case SND_SOC_DAIFMT_CBS_CFS:
408 /* interface format */
409 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
410 case SND_SOC_DAIFMT_I2S:
413 case SND_SOC_DAIFMT_RIGHT_J:
415 case SND_SOC_DAIFMT_LEFT_J:
418 case SND_SOC_DAIFMT_DSP_A:
421 case SND_SOC_DAIFMT_DSP_B:
428 /* clock inversion */
429 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
430 case SND_SOC_DAIFMT_NB_NF:
432 case SND_SOC_DAIFMT_IB_IF:
435 case SND_SOC_DAIFMT_IB_NF:
438 case SND_SOC_DAIFMT_NB_IF:
446 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface);
450 static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
451 enum snd_soc_bias_level level)
453 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
456 case SND_SOC_BIAS_ON:
457 /* vref/mid on, osc and clkout on if enabled */
458 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
459 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
460 ssm2602->clk_out_pwr);
462 case SND_SOC_BIAS_PREPARE:
464 case SND_SOC_BIAS_STANDBY:
465 /* everything off except vref/vmid, */
466 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
467 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
468 PWR_CLK_OUT_PDN | PWR_OSC_PDN);
470 case SND_SOC_BIAS_OFF:
472 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
473 PWR_POWER_OFF, PWR_POWER_OFF);
477 codec->dapm.bias_level = level;
481 #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
482 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
483 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
484 SNDRV_PCM_RATE_96000)
486 #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
487 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
489 static const struct snd_soc_dai_ops ssm2602_dai_ops = {
490 .startup = ssm2602_startup,
491 .hw_params = ssm2602_hw_params,
492 .digital_mute = ssm2602_mute,
493 .set_sysclk = ssm2602_set_dai_sysclk,
494 .set_fmt = ssm2602_set_dai_fmt,
497 static struct snd_soc_dai_driver ssm2602_dai = {
498 .name = "ssm2602-hifi",
500 .stream_name = "Playback",
503 .rates = SSM2602_RATES,
504 .formats = SSM2602_FORMATS,},
506 .stream_name = "Capture",
509 .rates = SSM2602_RATES,
510 .formats = SSM2602_FORMATS,},
511 .ops = &ssm2602_dai_ops,
512 .symmetric_rates = 1,
513 .symmetric_samplebits = 1,
516 static int ssm2602_suspend(struct snd_soc_codec *codec)
518 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
522 static int ssm2602_resume(struct snd_soc_codec *codec)
524 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
526 regcache_sync(ssm2602->regmap);
527 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
532 static int ssm2602_probe(struct snd_soc_codec *codec)
534 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
535 struct snd_soc_dapm_context *dapm = &codec->dapm;
538 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V,
539 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
540 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V,
541 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
543 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls,
544 ARRAY_SIZE(ssm2602_snd_controls));
548 ret = snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets,
549 ARRAY_SIZE(ssm2602_dapm_widgets));
553 return snd_soc_dapm_add_routes(dapm, ssm2602_routes,
554 ARRAY_SIZE(ssm2602_routes));
557 static int ssm2604_probe(struct snd_soc_codec *codec)
559 struct snd_soc_dapm_context *dapm = &codec->dapm;
562 ret = snd_soc_dapm_new_controls(dapm, ssm2604_dapm_widgets,
563 ARRAY_SIZE(ssm2604_dapm_widgets));
567 return snd_soc_dapm_add_routes(dapm, ssm2604_routes,
568 ARRAY_SIZE(ssm2604_routes));
571 static int ssm260x_probe(struct snd_soc_codec *codec)
573 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
576 codec->control_data = ssm2602->regmap;
577 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
579 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
583 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
585 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
589 /* set the update bits */
590 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
591 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
592 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL,
593 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
594 /*select Line in as default input*/
595 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC |
596 APANA_ENABLE_MIC_BOOST);
598 switch (ssm2602->type) {
600 ret = ssm2602_probe(codec);
603 ret = ssm2604_probe(codec);
610 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
615 /* remove everything here */
616 static int ssm2602_remove(struct snd_soc_codec *codec)
618 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
622 static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
623 .probe = ssm260x_probe,
624 .remove = ssm2602_remove,
625 .suspend = ssm2602_suspend,
626 .resume = ssm2602_resume,
627 .set_bias_level = ssm2602_set_bias_level,
629 .controls = ssm260x_snd_controls,
630 .num_controls = ARRAY_SIZE(ssm260x_snd_controls),
631 .dapm_widgets = ssm260x_dapm_widgets,
632 .num_dapm_widgets = ARRAY_SIZE(ssm260x_dapm_widgets),
633 .dapm_routes = ssm260x_routes,
634 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes),
637 static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
639 return reg == SSM2602_RESET;
642 static const struct regmap_config ssm2602_regmap_config = {
646 .max_register = SSM2602_RESET,
647 .volatile_reg = ssm2602_register_volatile,
649 .cache_type = REGCACHE_RBTREE,
650 .reg_defaults_raw = ssm2602_reg,
651 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
654 #if defined(CONFIG_SPI_MASTER)
655 static int ssm2602_spi_probe(struct spi_device *spi)
657 struct ssm2602_priv *ssm2602;
660 ssm2602 = devm_kzalloc(&spi->dev, sizeof(struct ssm2602_priv),
665 spi_set_drvdata(spi, ssm2602);
666 ssm2602->type = SSM2602;
668 ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config);
669 if (IS_ERR(ssm2602->regmap))
670 return PTR_ERR(ssm2602->regmap);
672 ret = snd_soc_register_codec(&spi->dev,
673 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
677 static int ssm2602_spi_remove(struct spi_device *spi)
679 snd_soc_unregister_codec(&spi->dev);
683 static struct spi_driver ssm2602_spi_driver = {
686 .owner = THIS_MODULE,
688 .probe = ssm2602_spi_probe,
689 .remove = ssm2602_spi_remove,
693 #if IS_ENABLED(CONFIG_I2C)
695 * ssm2602 2 wire address is determined by GPIO5
696 * state during powerup.
700 static int ssm2602_i2c_probe(struct i2c_client *i2c,
701 const struct i2c_device_id *id)
703 struct ssm2602_priv *ssm2602;
706 ssm2602 = devm_kzalloc(&i2c->dev, sizeof(struct ssm2602_priv),
711 i2c_set_clientdata(i2c, ssm2602);
712 ssm2602->type = id->driver_data;
714 ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config);
715 if (IS_ERR(ssm2602->regmap))
716 return PTR_ERR(ssm2602->regmap);
718 ret = snd_soc_register_codec(&i2c->dev,
719 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
723 static int ssm2602_i2c_remove(struct i2c_client *client)
725 snd_soc_unregister_codec(&client->dev);
729 static const struct i2c_device_id ssm2602_i2c_id[] = {
730 { "ssm2602", SSM2602 },
731 { "ssm2603", SSM2602 },
732 { "ssm2604", SSM2604 },
735 MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
737 /* corgi i2c codec control layer */
738 static struct i2c_driver ssm2602_i2c_driver = {
741 .owner = THIS_MODULE,
743 .probe = ssm2602_i2c_probe,
744 .remove = ssm2602_i2c_remove,
745 .id_table = ssm2602_i2c_id,
750 static int __init ssm2602_modinit(void)
754 #if defined(CONFIG_SPI_MASTER)
755 ret = spi_register_driver(&ssm2602_spi_driver);
760 #if IS_ENABLED(CONFIG_I2C)
761 ret = i2c_add_driver(&ssm2602_i2c_driver);
768 module_init(ssm2602_modinit);
770 static void __exit ssm2602_exit(void)
772 #if defined(CONFIG_SPI_MASTER)
773 spi_unregister_driver(&ssm2602_spi_driver);
776 #if IS_ENABLED(CONFIG_I2C)
777 i2c_del_driver(&ssm2602_i2c_driver);
780 module_exit(ssm2602_exit);
782 MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver");
783 MODULE_AUTHOR("Cliff Cai");
784 MODULE_LICENSE("GPL");