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/platform_device.h>
36 #include <sound/core.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/soc.h>
40 #include <sound/soc-dapm.h>
41 #include <sound/initval.h>
45 #define SSM2602_VERSION "0.1"
47 struct snd_soc_codec_device soc_codec_dev_ssm2602
;
49 /* codec private data */
52 struct snd_pcm_substream
*master_substream
;
53 struct snd_pcm_substream
*slave_substream
;
57 * ssm2602 register cache
58 * We can't read the ssm2602 register space when we are
59 * using 2 wire for device control, so we cache them instead.
60 * There is no point in caching the reset register
62 static const u16 ssm2602_reg
[SSM2602_CACHEREGNUM
] = {
63 0x0017, 0x0017, 0x0079, 0x0079,
64 0x0000, 0x0000, 0x0000, 0x000a,
69 * read ssm2602 register cache
71 static inline unsigned int ssm2602_read_reg_cache(struct snd_soc_codec
*codec
,
74 u16
*cache
= codec
->reg_cache
;
75 if (reg
== SSM2602_RESET
)
77 if (reg
>= SSM2602_CACHEREGNUM
)
83 * write ssm2602 register cache
85 static inline void ssm2602_write_reg_cache(struct snd_soc_codec
*codec
,
86 u16 reg
, unsigned int value
)
88 u16
*cache
= codec
->reg_cache
;
89 if (reg
>= SSM2602_CACHEREGNUM
)
95 * write to the ssm2602 register space
97 static int ssm2602_write(struct snd_soc_codec
*codec
, unsigned int reg
,
103 * D15..D9 ssm2602 register offset
104 * D8...D0 register data
106 data
[0] = (reg
<< 1) | ((value
>> 8) & 0x0001);
107 data
[1] = value
& 0x00ff;
109 ssm2602_write_reg_cache(codec
, reg
, value
);
110 if (codec
->hw_write(codec
->control_data
, data
, 2) == 2)
116 #define ssm2602_reset(c) ssm2602_write(c, SSM2602_RESET, 0)
118 /*Appending several "None"s just for OSS mixer use*/
119 static const char *ssm2602_input_select
[] = {
120 "Line", "Mic", "None", "None", "None",
121 "None", "None", "None",
124 static const char *ssm2602_deemph
[] = {"None", "32Khz", "44.1Khz", "48Khz"};
126 static const struct soc_enum ssm2602_enum
[] = {
127 SOC_ENUM_SINGLE(SSM2602_APANA
, 2, 2, ssm2602_input_select
),
128 SOC_ENUM_SINGLE(SSM2602_APDIGI
, 1, 4, ssm2602_deemph
),
131 static const struct snd_kcontrol_new ssm2602_snd_controls
[] = {
133 SOC_DOUBLE_R("Master Playback Volume", SSM2602_LOUT1V
, SSM2602_ROUT1V
,
135 SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V
, SSM2602_ROUT1V
,
138 SOC_DOUBLE_R("Capture Volume", SSM2602_LINVOL
, SSM2602_RINVOL
, 0, 31, 0),
139 SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL
, SSM2602_RINVOL
, 7, 1, 1),
141 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA
, 0, 1, 0),
142 SOC_SINGLE("Mic Switch", SSM2602_APANA
, 1, 1, 1),
144 SOC_SINGLE("Sidetone Playback Volume", SSM2602_APANA
, 6, 3, 1),
146 SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI
, 0, 1, 1),
147 SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI
, 4, 1, 0),
149 SOC_ENUM("Capture Source", ssm2602_enum
[0]),
151 SOC_ENUM("Playback De-emphasis", ssm2602_enum
[1]),
154 /* add non dapm controls */
155 static int ssm2602_add_controls(struct snd_soc_codec
*codec
)
159 for (i
= 0; i
< ARRAY_SIZE(ssm2602_snd_controls
); i
++) {
160 err
= snd_ctl_add(codec
->card
,
161 snd_soc_cnew(&ssm2602_snd_controls
[i
], codec
, NULL
));
170 static const struct snd_kcontrol_new ssm2602_output_mixer_controls
[] = {
171 SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA
, 3, 1, 0),
172 SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA
, 5, 1, 0),
173 SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA
, 4, 1, 0),
177 static const struct snd_kcontrol_new ssm2602_input_mux_controls
=
178 SOC_DAPM_ENUM("Input Select", ssm2602_enum
[0]);
180 static const struct snd_soc_dapm_widget ssm2602_dapm_widgets
[] = {
181 SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR
, 4, 1,
182 &ssm2602_output_mixer_controls
[0],
183 ARRAY_SIZE(ssm2602_output_mixer_controls
)),
184 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR
, 3, 1),
185 SND_SOC_DAPM_OUTPUT("LOUT"),
186 SND_SOC_DAPM_OUTPUT("LHPOUT"),
187 SND_SOC_DAPM_OUTPUT("ROUT"),
188 SND_SOC_DAPM_OUTPUT("RHPOUT"),
189 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR
, 2, 1),
190 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM
, 0, 0, &ssm2602_input_mux_controls
),
191 SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR
, 0, 1, NULL
, 0),
192 SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR
, 1, 1),
193 SND_SOC_DAPM_INPUT("MICIN"),
194 SND_SOC_DAPM_INPUT("RLINEIN"),
195 SND_SOC_DAPM_INPUT("LLINEIN"),
198 static const struct snd_soc_dapm_route audio_conn
[] = {
200 {"Output Mixer", "Line Bypass Switch", "Line Input"},
201 {"Output Mixer", "HiFi Playback Switch", "DAC"},
202 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
205 {"RHPOUT", NULL
, "Output Mixer"},
206 {"ROUT", NULL
, "Output Mixer"},
207 {"LHPOUT", NULL
, "Output Mixer"},
208 {"LOUT", NULL
, "Output Mixer"},
211 {"Input Mux", "Line", "Line Input"},
212 {"Input Mux", "Mic", "Mic Bias"},
213 {"ADC", NULL
, "Input Mux"},
216 {"Line Input", NULL
, "LLINEIN"},
217 {"Line Input", NULL
, "RLINEIN"},
218 {"Mic Bias", NULL
, "MICIN"},
221 static int ssm2602_add_widgets(struct snd_soc_codec
*codec
)
223 snd_soc_dapm_new_controls(codec
, ssm2602_dapm_widgets
,
224 ARRAY_SIZE(ssm2602_dapm_widgets
));
226 snd_soc_dapm_add_routes(codec
, audio_conn
, ARRAY_SIZE(audio_conn
));
228 snd_soc_dapm_new_widgets(codec
);
241 /* codec mclk clock divider coefficients */
242 static const struct _coeff_div coeff_div
[] = {
244 {12288000, 48000, 256, 0x0, 0x0, 0x0},
245 {18432000, 48000, 384, 0x0, 0x1, 0x0},
246 {12000000, 48000, 250, 0x0, 0x0, 0x1},
249 {12288000, 32000, 384, 0x6, 0x0, 0x0},
250 {18432000, 32000, 576, 0x6, 0x1, 0x0},
251 {12000000, 32000, 375, 0x6, 0x0, 0x1},
254 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
255 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
256 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
257 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
258 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
261 {12288000, 96000, 128, 0x7, 0x0, 0x0},
262 {18432000, 96000, 192, 0x7, 0x1, 0x0},
263 {12000000, 96000, 125, 0x7, 0x0, 0x1},
266 {11289600, 44100, 256, 0x8, 0x0, 0x0},
267 {16934400, 44100, 384, 0x8, 0x1, 0x0},
268 {12000000, 44100, 272, 0x8, 0x1, 0x1},
271 {11289600, 88200, 128, 0xf, 0x0, 0x0},
272 {16934400, 88200, 192, 0xf, 0x1, 0x0},
273 {12000000, 88200, 136, 0xf, 0x1, 0x1},
276 static inline int get_coeff(int mclk
, int rate
)
280 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
281 if (coeff_div
[i
].rate
== rate
&& coeff_div
[i
].mclk
== mclk
)
287 static int ssm2602_hw_params(struct snd_pcm_substream
*substream
,
288 struct snd_pcm_hw_params
*params
,
289 struct snd_soc_dai
*dai
)
292 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
293 struct snd_soc_device
*socdev
= rtd
->socdev
;
294 struct snd_soc_codec
*codec
= socdev
->codec
;
295 struct ssm2602_priv
*ssm2602
= codec
->private_data
;
296 struct i2c_client
*i2c
= codec
->control_data
;
297 u16 iface
= ssm2602_read_reg_cache(codec
, SSM2602_IFACE
) & 0xfff3;
298 int i
= get_coeff(ssm2602
->sysclk
, params_rate(params
));
300 if (substream
== ssm2602
->slave_substream
) {
301 dev_dbg(&i2c
->dev
, "Ignoring hw_params for slave substream\n");
305 /*no match is found*/
306 if (i
== ARRAY_SIZE(coeff_div
))
309 srate
= (coeff_div
[i
].sr
<< 2) |
310 (coeff_div
[i
].bosr
<< 1) | coeff_div
[i
].usb
;
312 ssm2602_write(codec
, SSM2602_ACTIVE
, 0);
313 ssm2602_write(codec
, SSM2602_SRATE
, srate
);
316 switch (params_format(params
)) {
317 case SNDRV_PCM_FORMAT_S16_LE
:
319 case SNDRV_PCM_FORMAT_S20_3LE
:
322 case SNDRV_PCM_FORMAT_S24_LE
:
325 case SNDRV_PCM_FORMAT_S32_LE
:
329 ssm2602_write(codec
, SSM2602_IFACE
, iface
);
330 ssm2602_write(codec
, SSM2602_ACTIVE
, ACTIVE_ACTIVATE_CODEC
);
334 static int ssm2602_startup(struct snd_pcm_substream
*substream
,
335 struct snd_soc_dai
*dai
)
337 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
338 struct snd_soc_device
*socdev
= rtd
->socdev
;
339 struct snd_soc_codec
*codec
= socdev
->codec
;
340 struct ssm2602_priv
*ssm2602
= codec
->private_data
;
341 struct i2c_client
*i2c
= codec
->control_data
;
342 struct snd_pcm_runtime
*master_runtime
;
344 /* The DAI has shared clocks so if we already have a playback or
345 * capture going then constrain this substream to match it.
346 * TODO: the ssm2602 allows pairs of non-matching PB/REC rates
348 if (ssm2602
->master_substream
) {
349 master_runtime
= ssm2602
->master_substream
->runtime
;
350 dev_dbg(&i2c
->dev
, "Constraining to %d bits at %dHz\n",
351 master_runtime
->sample_bits
,
352 master_runtime
->rate
);
354 snd_pcm_hw_constraint_minmax(substream
->runtime
,
355 SNDRV_PCM_HW_PARAM_RATE
,
356 master_runtime
->rate
,
357 master_runtime
->rate
);
359 snd_pcm_hw_constraint_minmax(substream
->runtime
,
360 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
361 master_runtime
->sample_bits
,
362 master_runtime
->sample_bits
);
364 ssm2602
->slave_substream
= substream
;
366 ssm2602
->master_substream
= substream
;
371 static int ssm2602_pcm_prepare(struct snd_pcm_substream
*substream
,
372 struct snd_soc_dai
*dai
)
374 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
375 struct snd_soc_device
*socdev
= rtd
->socdev
;
376 struct snd_soc_codec
*codec
= socdev
->codec
;
378 ssm2602_write(codec
, SSM2602_ACTIVE
, ACTIVE_ACTIVATE_CODEC
);
383 static void ssm2602_shutdown(struct snd_pcm_substream
*substream
,
384 struct snd_soc_dai
*dai
)
386 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
387 struct snd_soc_device
*socdev
= rtd
->socdev
;
388 struct snd_soc_codec
*codec
= socdev
->codec
;
389 struct ssm2602_priv
*ssm2602
= codec
->private_data
;
392 ssm2602_write(codec
, SSM2602_ACTIVE
, 0);
394 if (ssm2602
->master_substream
== substream
)
395 ssm2602
->master_substream
= ssm2602
->slave_substream
;
397 ssm2602
->slave_substream
= NULL
;
400 static int ssm2602_mute(struct snd_soc_dai
*dai
, int mute
)
402 struct snd_soc_codec
*codec
= dai
->codec
;
403 u16 mute_reg
= ssm2602_read_reg_cache(codec
, SSM2602_APDIGI
) & ~APDIGI_ENABLE_DAC_MUTE
;
405 ssm2602_write(codec
, SSM2602_APDIGI
,
406 mute_reg
| APDIGI_ENABLE_DAC_MUTE
);
408 ssm2602_write(codec
, SSM2602_APDIGI
, mute_reg
);
412 static int ssm2602_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
413 int clk_id
, unsigned int freq
, int dir
)
415 struct snd_soc_codec
*codec
= codec_dai
->codec
;
416 struct ssm2602_priv
*ssm2602
= codec
->private_data
;
423 ssm2602
->sysclk
= freq
;
429 static int ssm2602_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
432 struct snd_soc_codec
*codec
= codec_dai
->codec
;
435 /* set master/slave audio interface */
436 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
437 case SND_SOC_DAIFMT_CBM_CFM
:
440 case SND_SOC_DAIFMT_CBS_CFS
:
446 /* interface format */
447 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
448 case SND_SOC_DAIFMT_I2S
:
451 case SND_SOC_DAIFMT_RIGHT_J
:
453 case SND_SOC_DAIFMT_LEFT_J
:
456 case SND_SOC_DAIFMT_DSP_A
:
459 case SND_SOC_DAIFMT_DSP_B
:
466 /* clock inversion */
467 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
468 case SND_SOC_DAIFMT_NB_NF
:
470 case SND_SOC_DAIFMT_IB_IF
:
473 case SND_SOC_DAIFMT_IB_NF
:
476 case SND_SOC_DAIFMT_NB_IF
:
484 ssm2602_write(codec
, SSM2602_IFACE
, iface
);
488 static int ssm2602_set_bias_level(struct snd_soc_codec
*codec
,
489 enum snd_soc_bias_level level
)
491 u16 reg
= ssm2602_read_reg_cache(codec
, SSM2602_PWR
) & 0xff7f;
494 case SND_SOC_BIAS_ON
:
495 /* vref/mid, osc on, dac unmute */
496 ssm2602_write(codec
, SSM2602_PWR
, reg
);
498 case SND_SOC_BIAS_PREPARE
:
500 case SND_SOC_BIAS_STANDBY
:
501 /* everything off except vref/vmid, */
502 ssm2602_write(codec
, SSM2602_PWR
, reg
| PWR_CLK_OUT_PDN
);
504 case SND_SOC_BIAS_OFF
:
505 /* everything off, dac mute, inactive */
506 ssm2602_write(codec
, SSM2602_ACTIVE
, 0);
507 ssm2602_write(codec
, SSM2602_PWR
, 0xffff);
511 codec
->bias_level
= level
;
515 #define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
516 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
517 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
518 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
519 SNDRV_PCM_RATE_96000)
521 #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
522 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
524 struct snd_soc_dai ssm2602_dai
= {
527 .stream_name
= "Playback",
530 .rates
= SSM2602_RATES
,
531 .formats
= SSM2602_FORMATS
,},
533 .stream_name
= "Capture",
536 .rates
= SSM2602_RATES
,
537 .formats
= SSM2602_FORMATS
,},
539 .startup
= ssm2602_startup
,
540 .prepare
= ssm2602_pcm_prepare
,
541 .hw_params
= ssm2602_hw_params
,
542 .shutdown
= ssm2602_shutdown
,
543 .digital_mute
= ssm2602_mute
,
544 .set_sysclk
= ssm2602_set_dai_sysclk
,
545 .set_fmt
= ssm2602_set_dai_fmt
,
548 EXPORT_SYMBOL_GPL(ssm2602_dai
);
550 static int ssm2602_suspend(struct platform_device
*pdev
, pm_message_t state
)
552 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
553 struct snd_soc_codec
*codec
= socdev
->codec
;
555 ssm2602_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
559 static int ssm2602_resume(struct platform_device
*pdev
)
561 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
562 struct snd_soc_codec
*codec
= socdev
->codec
;
565 u16
*cache
= codec
->reg_cache
;
567 /* Sync reg_cache with the hardware */
568 for (i
= 0; i
< ARRAY_SIZE(ssm2602_reg
); i
++) {
569 data
[0] = (i
<< 1) | ((cache
[i
] >> 8) & 0x0001);
570 data
[1] = cache
[i
] & 0x00ff;
571 codec
->hw_write(codec
->control_data
, data
, 2);
573 ssm2602_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
574 ssm2602_set_bias_level(codec
, codec
->suspend_bias_level
);
579 * initialise the ssm2602 driver
580 * register the mixer and dsp interfaces with the kernel
582 static int ssm2602_init(struct snd_soc_device
*socdev
)
584 struct snd_soc_codec
*codec
= socdev
->codec
;
587 codec
->name
= "SSM2602";
588 codec
->owner
= THIS_MODULE
;
589 codec
->read
= ssm2602_read_reg_cache
;
590 codec
->write
= ssm2602_write
;
591 codec
->set_bias_level
= ssm2602_set_bias_level
;
592 codec
->dai
= &ssm2602_dai
;
594 codec
->reg_cache_size
= sizeof(ssm2602_reg
);
595 codec
->reg_cache
= kmemdup(ssm2602_reg
, sizeof(ssm2602_reg
),
597 if (codec
->reg_cache
== NULL
)
600 ssm2602_reset(codec
);
603 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
605 pr_err("ssm2602: failed to create pcms\n");
609 ssm2602_write(codec
, SSM2602_ACTIVE
, 0);
610 /* set the update bits */
611 reg
= ssm2602_read_reg_cache(codec
, SSM2602_LINVOL
);
612 ssm2602_write(codec
, SSM2602_LINVOL
, reg
| LINVOL_LRIN_BOTH
);
613 reg
= ssm2602_read_reg_cache(codec
, SSM2602_RINVOL
);
614 ssm2602_write(codec
, SSM2602_RINVOL
, reg
| RINVOL_RLIN_BOTH
);
615 reg
= ssm2602_read_reg_cache(codec
, SSM2602_LOUT1V
);
616 ssm2602_write(codec
, SSM2602_LOUT1V
, reg
| LOUT1V_LRHP_BOTH
);
617 reg
= ssm2602_read_reg_cache(codec
, SSM2602_ROUT1V
);
618 ssm2602_write(codec
, SSM2602_ROUT1V
, reg
| ROUT1V_RLHP_BOTH
);
619 /*select Line in as default input*/
620 ssm2602_write(codec
, SSM2602_APANA
,
621 APANA_ENABLE_MIC_BOOST2
| APANA_SELECT_DAC
|
622 APANA_ENABLE_MIC_BOOST
);
623 ssm2602_write(codec
, SSM2602_PWR
, 0);
625 ssm2602_add_controls(codec
);
626 ssm2602_add_widgets(codec
);
627 ret
= snd_soc_init_card(socdev
);
629 pr_err("ssm2602: failed to register card\n");
636 snd_soc_free_pcms(socdev
);
637 snd_soc_dapm_free(socdev
);
639 kfree(codec
->reg_cache
);
643 static struct snd_soc_device
*ssm2602_socdev
;
645 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
647 * ssm2602 2 wire address is determined by GPIO5
648 * state during powerup.
652 static int ssm2602_i2c_probe(struct i2c_client
*i2c
,
653 const struct i2c_device_id
*id
)
655 struct snd_soc_device
*socdev
= ssm2602_socdev
;
656 struct snd_soc_codec
*codec
= socdev
->codec
;
659 i2c_set_clientdata(i2c
, codec
);
660 codec
->control_data
= i2c
;
662 ret
= ssm2602_init(socdev
);
664 pr_err("failed to initialise SSM2602\n");
669 static int ssm2602_i2c_remove(struct i2c_client
*client
)
671 struct snd_soc_codec
*codec
= i2c_get_clientdata(client
);
672 kfree(codec
->reg_cache
);
676 static const struct i2c_device_id ssm2602_i2c_id
[] = {
680 MODULE_DEVICE_TABLE(i2c
, ssm2602_i2c_id
);
681 /* corgi i2c codec control layer */
682 static struct i2c_driver ssm2602_i2c_driver
= {
684 .name
= "SSM2602 I2C Codec",
685 .owner
= THIS_MODULE
,
687 .probe
= ssm2602_i2c_probe
,
688 .remove
= ssm2602_i2c_remove
,
689 .id_table
= ssm2602_i2c_id
,
692 static int ssm2602_add_i2c_device(struct platform_device
*pdev
,
693 const struct ssm2602_setup_data
*setup
)
695 struct i2c_board_info info
;
696 struct i2c_adapter
*adapter
;
697 struct i2c_client
*client
;
700 ret
= i2c_add_driver(&ssm2602_i2c_driver
);
702 dev_err(&pdev
->dev
, "can't add i2c driver\n");
705 memset(&info
, 0, sizeof(struct i2c_board_info
));
706 info
.addr
= setup
->i2c_address
;
707 strlcpy(info
.type
, "ssm2602", I2C_NAME_SIZE
);
708 adapter
= i2c_get_adapter(setup
->i2c_bus
);
710 dev_err(&pdev
->dev
, "can't get i2c adapter %d\n",
714 client
= i2c_new_device(adapter
, &info
);
715 i2c_put_adapter(adapter
);
717 dev_err(&pdev
->dev
, "can't add i2c device at 0x%x\n",
718 (unsigned int)info
.addr
);
723 i2c_del_driver(&ssm2602_i2c_driver
);
728 static int ssm2602_probe(struct platform_device
*pdev
)
730 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
731 struct ssm2602_setup_data
*setup
;
732 struct snd_soc_codec
*codec
;
733 struct ssm2602_priv
*ssm2602
;
736 pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION
);
738 setup
= socdev
->codec_data
;
739 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
743 ssm2602
= kzalloc(sizeof(struct ssm2602_priv
), GFP_KERNEL
);
744 if (ssm2602
== NULL
) {
749 codec
->private_data
= ssm2602
;
750 socdev
->codec
= codec
;
751 mutex_init(&codec
->mutex
);
752 INIT_LIST_HEAD(&codec
->dapm_widgets
);
753 INIT_LIST_HEAD(&codec
->dapm_paths
);
755 ssm2602_socdev
= socdev
;
756 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
757 if (setup
->i2c_address
) {
758 codec
->hw_write
= (hw_write_t
)i2c_master_send
;
759 ret
= ssm2602_add_i2c_device(pdev
, setup
);
762 /* other interfaces */
767 /* remove everything here */
768 static int ssm2602_remove(struct platform_device
*pdev
)
770 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
771 struct snd_soc_codec
*codec
= socdev
->codec
;
773 if (codec
->control_data
)
774 ssm2602_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
776 snd_soc_free_pcms(socdev
);
777 snd_soc_dapm_free(socdev
);
778 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
779 i2c_unregister_device(codec
->control_data
);
780 i2c_del_driver(&ssm2602_i2c_driver
);
782 kfree(codec
->private_data
);
788 struct snd_soc_codec_device soc_codec_dev_ssm2602
= {
789 .probe
= ssm2602_probe
,
790 .remove
= ssm2602_remove
,
791 .suspend
= ssm2602_suspend
,
792 .resume
= ssm2602_resume
,
794 EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602
);
796 static int __init
ssm2602_modinit(void)
798 return snd_soc_register_dai(&ssm2602_dai
);
800 module_init(ssm2602_modinit
);
802 static void __exit
ssm2602_exit(void)
804 snd_soc_unregister_dai(&ssm2602_dai
);
806 module_exit(ssm2602_exit
);
808 MODULE_DESCRIPTION("ASoC ssm2602 driver");
809 MODULE_AUTHOR("Cliff Cai");
810 MODULE_LICENSE("GPL");