blob: 079066fef4255217adce5319e58be0d15acdcb91 [file] [log] [blame]
Cliff Caib7138212008-09-05 18:09:57 +08001/*
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>
Mike Frysingerb39e2852011-04-07 02:05:11 -040035#include <linux/spi/spi.h>
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +020036#include <linux/regmap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Cliff Caib7138212008-09-05 18:09:57 +080038#include <sound/core.h>
39#include <sound/pcm.h>
40#include <sound/pcm_params.h>
41#include <sound/soc.h>
Cliff Caib7138212008-09-05 18:09:57 +080042#include <sound/initval.h>
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -070043#include <sound/tlv.h>
Cliff Caib7138212008-09-05 18:09:57 +080044
45#include "ssm2602.h"
46
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070047enum ssm2602_type {
48 SSM2602,
49 SSM2604,
50};
51
Cliff Caib7138212008-09-05 18:09:57 +080052/* codec private data */
53struct ssm2602_priv {
54 unsigned int sysclk;
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +020055 struct snd_pcm_hw_constraint_list *sysclk_constraints;
Cliff Caib7138212008-09-05 18:09:57 +080056 struct snd_pcm_substream *master_substream;
57 struct snd_pcm_substream *slave_substream;
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070058
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +020059 struct regmap *regmap;
60
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070061 enum ssm2602_type type;
Lars-Peter Clausen02890532011-09-27 11:08:48 +020062 unsigned int clk_out_pwr;
Cliff Caib7138212008-09-05 18:09:57 +080063};
64
65/*
66 * ssm2602 register cache
67 * We can't read the ssm2602 register space when we are
68 * using 2 wire for device control, so we cache them instead.
69 * There is no point in caching the reset register
70 */
71static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
Lars-Peter Clausen7164bdb2011-05-08 09:24:41 -070072 0x0097, 0x0097, 0x0079, 0x0079,
73 0x000a, 0x0008, 0x009f, 0x000a,
Cliff Caib7138212008-09-05 18:09:57 +080074 0x0000, 0x0000
75};
76
Cliff Caib7138212008-09-05 18:09:57 +080077
78/*Appending several "None"s just for OSS mixer use*/
79static const char *ssm2602_input_select[] = {
80 "Line", "Mic", "None", "None", "None",
81 "None", "None", "None",
82};
83
84static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
85
86static const struct soc_enum ssm2602_enum[] = {
87 SOC_ENUM_SINGLE(SSM2602_APANA, 2, 2, ssm2602_input_select),
88 SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, 4, ssm2602_deemph),
89};
90
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -070091static const unsigned int ssm260x_outmix_tlv[] = {
92 TLV_DB_RANGE_HEAD(2),
93 0, 47, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
94 48, 127, TLV_DB_SCALE_ITEM(-7400, 100, 0),
95};
96
97static const DECLARE_TLV_DB_SCALE(ssm260x_inpga_tlv, -3450, 150, 0);
98static const DECLARE_TLV_DB_SCALE(ssm260x_sidetone_tlv, -1500, 300, 0);
99
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700100static const struct snd_kcontrol_new ssm260x_snd_controls[] = {
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -0700101SOC_DOUBLE_R_TLV("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 45, 0,
102 ssm260x_inpga_tlv),
Cliff Caib7138212008-09-05 18:09:57 +0800103SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1),
104
Cliff Caib7138212008-09-05 18:09:57 +0800105SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1),
106SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0),
107
Cliff Caib7138212008-09-05 18:09:57 +0800108SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]),
109};
110
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700111static const struct snd_kcontrol_new ssm2602_snd_controls[] = {
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -0700112SOC_DOUBLE_R_TLV("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V,
113 0, 127, 0, ssm260x_outmix_tlv),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700114SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V,
115 7, 1, 0),
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -0700116SOC_SINGLE_TLV("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1,
117 ssm260x_sidetone_tlv),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700118
119SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
120SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0),
121SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
122};
123
Cliff Caib7138212008-09-05 18:09:57 +0800124/* Output Mixer */
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700125static const struct snd_kcontrol_new ssm260x_output_mixer_controls[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800126SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0),
Cliff Caib7138212008-09-05 18:09:57 +0800127SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700128SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0),
Cliff Caib7138212008-09-05 18:09:57 +0800129};
130
131/* Input mux */
132static const struct snd_kcontrol_new ssm2602_input_mux_controls =
133SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]);
134
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700135static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800136SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1),
Cliff Caib7138212008-09-05 18:09:57 +0800137SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1),
Cliff Caib7138212008-09-05 18:09:57 +0800138SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700139
Mark Brown3afb1b3e2011-05-11 00:01:58 +0200140SND_SOC_DAPM_SUPPLY("Digital Core Power", SSM2602_ACTIVE, 0, 0, NULL, 0),
Lars-Peter Clausen2a438012011-05-08 09:24:45 -0700141
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700142SND_SOC_DAPM_OUTPUT("LOUT"),
143SND_SOC_DAPM_OUTPUT("ROUT"),
Cliff Caib7138212008-09-05 18:09:57 +0800144SND_SOC_DAPM_INPUT("RLINEIN"),
145SND_SOC_DAPM_INPUT("LLINEIN"),
146};
147
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700148static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = {
149SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1,
150 ssm260x_output_mixer_controls,
151 ARRAY_SIZE(ssm260x_output_mixer_controls)),
152
153SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls),
154SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1),
155
156SND_SOC_DAPM_OUTPUT("LHPOUT"),
157SND_SOC_DAPM_OUTPUT("RHPOUT"),
158SND_SOC_DAPM_INPUT("MICIN"),
159};
160
161static const struct snd_soc_dapm_widget ssm2604_dapm_widgets[] = {
162SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0,
163 ssm260x_output_mixer_controls,
164 ARRAY_SIZE(ssm260x_output_mixer_controls) - 1), /* Last element is the mic */
165};
166
167static const struct snd_soc_dapm_route ssm260x_routes[] = {
Lars-Peter Clausen2a438012011-05-08 09:24:45 -0700168 {"DAC", NULL, "Digital Core Power"},
169 {"ADC", NULL, "Digital Core Power"},
170
Cliff Caib7138212008-09-05 18:09:57 +0800171 {"Output Mixer", "Line Bypass Switch", "Line Input"},
172 {"Output Mixer", "HiFi Playback Switch", "DAC"},
Cliff Caib7138212008-09-05 18:09:57 +0800173
Cliff Caib7138212008-09-05 18:09:57 +0800174 {"ROUT", NULL, "Output Mixer"},
Cliff Caib7138212008-09-05 18:09:57 +0800175 {"LOUT", NULL, "Output Mixer"},
176
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700177 {"Line Input", NULL, "LLINEIN"},
178 {"Line Input", NULL, "RLINEIN"},
179};
180
181static const struct snd_soc_dapm_route ssm2602_routes[] = {
182 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
183
184 {"RHPOUT", NULL, "Output Mixer"},
185 {"LHPOUT", NULL, "Output Mixer"},
186
Cliff Caib7138212008-09-05 18:09:57 +0800187 {"Input Mux", "Line", "Line Input"},
188 {"Input Mux", "Mic", "Mic Bias"},
189 {"ADC", NULL, "Input Mux"},
190
Cliff Caib7138212008-09-05 18:09:57 +0800191 {"Mic Bias", NULL, "MICIN"},
192};
193
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700194static const struct snd_soc_dapm_route ssm2604_routes[] = {
195 {"ADC", NULL, "Line Input"},
196};
Cliff Caib7138212008-09-05 18:09:57 +0800197
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200198static const unsigned int ssm2602_rates_12288000[] = {
199 8000, 32000, 48000, 96000,
200};
201
202static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
203 .list = ssm2602_rates_12288000,
204 .count = ARRAY_SIZE(ssm2602_rates_12288000),
205};
206
207static const unsigned int ssm2602_rates_11289600[] = {
208 8000, 44100, 88200,
209};
210
211static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
212 .list = ssm2602_rates_11289600,
213 .count = ARRAY_SIZE(ssm2602_rates_11289600),
214};
215
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200216struct ssm2602_coeff {
Cliff Caib7138212008-09-05 18:09:57 +0800217 u32 mclk;
218 u32 rate;
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200219 u8 srate;
Cliff Caib7138212008-09-05 18:09:57 +0800220};
221
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200222#define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb))
223
224/* codec mclk clock coefficients */
225static const struct ssm2602_coeff ssm2602_coeff_table[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800226 /* 48k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200227 {12288000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x0)},
228 {18432000, 48000, SSM2602_COEFF_SRATE(0x0, 0x1, 0x0)},
229 {12000000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800230
231 /* 32k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200232 {12288000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x0)},
233 {18432000, 32000, SSM2602_COEFF_SRATE(0x6, 0x1, 0x0)},
234 {12000000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800235
236 /* 8k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200237 {12288000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x0)},
238 {18432000, 8000, SSM2602_COEFF_SRATE(0x3, 0x1, 0x0)},
239 {11289600, 8000, SSM2602_COEFF_SRATE(0xb, 0x0, 0x0)},
240 {16934400, 8000, SSM2602_COEFF_SRATE(0xb, 0x1, 0x0)},
241 {12000000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800242
243 /* 96k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200244 {12288000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x0)},
245 {18432000, 96000, SSM2602_COEFF_SRATE(0x7, 0x1, 0x0)},
246 {12000000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800247
248 /* 44.1k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200249 {11289600, 44100, SSM2602_COEFF_SRATE(0x8, 0x0, 0x0)},
250 {16934400, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x0)},
251 {12000000, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800252
253 /* 88.2k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200254 {11289600, 88200, SSM2602_COEFF_SRATE(0xf, 0x0, 0x0)},
255 {16934400, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x0)},
256 {12000000, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x1)},
Cliff Caib7138212008-09-05 18:09:57 +0800257};
258
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200259static inline int ssm2602_get_coeff(int mclk, int rate)
Cliff Caib7138212008-09-05 18:09:57 +0800260{
261 int i;
262
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200263 for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) {
264 if (ssm2602_coeff_table[i].rate == rate &&
265 ssm2602_coeff_table[i].mclk == mclk)
266 return ssm2602_coeff_table[i].srate;
Cliff Caib7138212008-09-05 18:09:57 +0800267 }
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200268 return -EINVAL;
Cliff Caib7138212008-09-05 18:09:57 +0800269}
270
271static int ssm2602_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000272 struct snd_pcm_hw_params *params,
273 struct snd_soc_dai *dai)
Cliff Caib7138212008-09-05 18:09:57 +0800274{
Mark Browne6968a12012-04-04 15:58:16 +0100275 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900276 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200277 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200278 unsigned int iface;
Cliff Caib7138212008-09-05 18:09:57 +0800279
Karl Beldanfaab5a32008-11-20 15:39:27 +0100280 if (substream == ssm2602->slave_substream) {
Cliff Cai93547e82011-03-27 17:22:57 -0400281 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n");
Karl Beldanfaab5a32008-11-20 15:39:27 +0100282 return 0;
283 }
284
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200285 if (srate < 0)
286 return srate;
Cliff Caib7138212008-09-05 18:09:57 +0800287
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200288 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate);
Cliff Caib7138212008-09-05 18:09:57 +0800289
290 /* bit size */
291 switch (params_format(params)) {
292 case SNDRV_PCM_FORMAT_S16_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200293 iface = 0x0;
Cliff Caib7138212008-09-05 18:09:57 +0800294 break;
295 case SNDRV_PCM_FORMAT_S20_3LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200296 iface = 0x4;
Cliff Caib7138212008-09-05 18:09:57 +0800297 break;
298 case SNDRV_PCM_FORMAT_S24_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200299 iface = 0x8;
Cliff Caib7138212008-09-05 18:09:57 +0800300 break;
301 case SNDRV_PCM_FORMAT_S32_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200302 iface = 0xc;
Cliff Caib7138212008-09-05 18:09:57 +0800303 break;
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200304 default:
305 return -EINVAL;
Cliff Caib7138212008-09-05 18:09:57 +0800306 }
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200307 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE,
308 IFACE_AUDIO_DATA_LEN, iface);
Cliff Caib7138212008-09-05 18:09:57 +0800309 return 0;
310}
311
Mark Browndee89c42008-11-18 22:11:38 +0000312static int ssm2602_startup(struct snd_pcm_substream *substream,
313 struct snd_soc_dai *dai)
Cliff Caib7138212008-09-05 18:09:57 +0800314{
Mark Browne6968a12012-04-04 15:58:16 +0100315 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900316 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800317 struct snd_pcm_runtime *master_runtime;
318
319 /* The DAI has shared clocks so if we already have a playback or
320 * capture going then constrain this substream to match it.
Karl Beldanfaab5a32008-11-20 15:39:27 +0100321 * TODO: the ssm2602 allows pairs of non-matching PB/REC rates
Cliff Caib7138212008-09-05 18:09:57 +0800322 */
323 if (ssm2602->master_substream) {
324 master_runtime = ssm2602->master_substream->runtime;
Lars-Peter Clausen26806a42011-09-20 08:19:58 +0200325 dev_dbg(codec->dev, "Constraining to %d bits at %dHz\n",
Karl Beldanfaab5a32008-11-20 15:39:27 +0100326 master_runtime->sample_bits,
327 master_runtime->rate);
328
Cliff Caif692fce2009-06-02 00:18:54 -0400329 if (master_runtime->rate != 0)
330 snd_pcm_hw_constraint_minmax(substream->runtime,
331 SNDRV_PCM_HW_PARAM_RATE,
332 master_runtime->rate,
333 master_runtime->rate);
Cliff Caib7138212008-09-05 18:09:57 +0800334
Cliff Caif692fce2009-06-02 00:18:54 -0400335 if (master_runtime->sample_bits != 0)
336 snd_pcm_hw_constraint_minmax(substream->runtime,
337 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
338 master_runtime->sample_bits,
339 master_runtime->sample_bits);
Cliff Caib7138212008-09-05 18:09:57 +0800340
341 ssm2602->slave_substream = substream;
342 } else
343 ssm2602->master_substream = substream;
344
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200345 if (ssm2602->sysclk_constraints) {
346 snd_pcm_hw_constraint_list(substream->runtime, 0,
347 SNDRV_PCM_HW_PARAM_RATE,
348 ssm2602->sysclk_constraints);
349 }
350
Cliff Caib7138212008-09-05 18:09:57 +0800351 return 0;
352}
353
Mark Browndee89c42008-11-18 22:11:38 +0000354static void ssm2602_shutdown(struct snd_pcm_substream *substream,
355 struct snd_soc_dai *dai)
Cliff Caib7138212008-09-05 18:09:57 +0800356{
Mark Browne6968a12012-04-04 15:58:16 +0100357 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900358 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caif692fce2009-06-02 00:18:54 -0400359
Karl Beldanfaab5a32008-11-20 15:39:27 +0100360 if (ssm2602->master_substream == substream)
361 ssm2602->master_substream = ssm2602->slave_substream;
362
363 ssm2602->slave_substream = NULL;
Cliff Caib7138212008-09-05 18:09:57 +0800364}
365
Lars-Peter Clausen2a438012011-05-08 09:24:45 -0700366
Cliff Caib7138212008-09-05 18:09:57 +0800367static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
368{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200369 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec);
Axel Lin2ee9c182011-10-19 14:07:31 +0800370
Cliff Caib7138212008-09-05 18:09:57 +0800371 if (mute)
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200372 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
Axel Lin2ee9c182011-10-19 14:07:31 +0800373 APDIGI_ENABLE_DAC_MUTE,
374 APDIGI_ENABLE_DAC_MUTE);
Cliff Caib7138212008-09-05 18:09:57 +0800375 else
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200376 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
Axel Lin2ee9c182011-10-19 14:07:31 +0800377 APDIGI_ENABLE_DAC_MUTE, 0);
Cliff Caib7138212008-09-05 18:09:57 +0800378 return 0;
379}
380
381static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
382 int clk_id, unsigned int freq, int dir)
383{
384 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900385 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200386
387 if (dir == SND_SOC_CLOCK_IN) {
388 if (clk_id != SSM2602_SYSCLK)
389 return -EINVAL;
390
391 switch (freq) {
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200392 case 12288000:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200393 case 18432000:
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200394 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000;
395 break;
396 case 11289600:
397 case 16934400:
398 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600;
399 break;
400 case 12000000:
401 ssm2602->sysclk_constraints = NULL;
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200402 break;
403 default:
404 return -EINVAL;
405 }
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200406 ssm2602->sysclk = freq;
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200407 } else {
408 unsigned int mask;
409
410 switch (clk_id) {
411 case SSM2602_CLK_CLKOUT:
412 mask = PWR_CLK_OUT_PDN;
413 break;
414 case SSM2602_CLK_XTO:
415 mask = PWR_OSC_PDN;
416 break;
417 default:
418 return -EINVAL;
419 }
420
421 if (freq == 0)
422 ssm2602->clk_out_pwr |= mask;
423 else
424 ssm2602->clk_out_pwr &= ~mask;
425
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200426 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200427 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
Cliff Caib7138212008-09-05 18:09:57 +0800428 }
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200429
430 return 0;
Cliff Caib7138212008-09-05 18:09:57 +0800431}
432
433static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
434 unsigned int fmt)
435{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200436 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec);
437 unsigned int iface = 0;
Cliff Caib7138212008-09-05 18:09:57 +0800438
439 /* set master/slave audio interface */
440 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
441 case SND_SOC_DAIFMT_CBM_CFM:
442 iface |= 0x0040;
443 break;
444 case SND_SOC_DAIFMT_CBS_CFS:
445 break;
446 default:
447 return -EINVAL;
448 }
449
450 /* interface format */
451 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
452 case SND_SOC_DAIFMT_I2S:
453 iface |= 0x0002;
454 break;
455 case SND_SOC_DAIFMT_RIGHT_J:
456 break;
457 case SND_SOC_DAIFMT_LEFT_J:
458 iface |= 0x0001;
459 break;
460 case SND_SOC_DAIFMT_DSP_A:
Jarkko Nikulac6913482008-12-22 10:57:33 +0200461 iface |= 0x0013;
Cliff Caib7138212008-09-05 18:09:57 +0800462 break;
463 case SND_SOC_DAIFMT_DSP_B:
Jarkko Nikulac6913482008-12-22 10:57:33 +0200464 iface |= 0x0003;
Cliff Caib7138212008-09-05 18:09:57 +0800465 break;
466 default:
467 return -EINVAL;
468 }
469
470 /* clock inversion */
471 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
472 case SND_SOC_DAIFMT_NB_NF:
473 break;
474 case SND_SOC_DAIFMT_IB_IF:
475 iface |= 0x0090;
476 break;
477 case SND_SOC_DAIFMT_IB_NF:
478 iface |= 0x0080;
479 break;
480 case SND_SOC_DAIFMT_NB_IF:
481 iface |= 0x0010;
482 break;
483 default:
484 return -EINVAL;
485 }
486
487 /* set iface */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200488 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface);
Cliff Caib7138212008-09-05 18:09:57 +0800489 return 0;
490}
491
492static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
493 enum snd_soc_bias_level level)
494{
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200495 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800496
497 switch (level) {
498 case SND_SOC_BIAS_ON:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200499 /* vref/mid on, osc and clkout on if enabled */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200500 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200501 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
502 ssm2602->clk_out_pwr);
Cliff Caib7138212008-09-05 18:09:57 +0800503 break;
504 case SND_SOC_BIAS_PREPARE:
505 break;
506 case SND_SOC_BIAS_STANDBY:
507 /* everything off except vref/vmid, */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200508 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200509 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
510 PWR_CLK_OUT_PDN | PWR_OSC_PDN);
Cliff Caib7138212008-09-05 18:09:57 +0800511 break;
512 case SND_SOC_BIAS_OFF:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200513 /* everything off */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200514 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200515 PWR_POWER_OFF, PWR_POWER_OFF);
Cliff Caib7138212008-09-05 18:09:57 +0800516 break;
517
518 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200519 codec->dapm.bias_level = level;
Cliff Caib7138212008-09-05 18:09:57 +0800520 return 0;
521}
522
Cliff Cai2552a712009-06-02 00:18:53 -0400523#define SSM2602_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_32000 |\
524 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
525 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
Cliff Caib7138212008-09-05 18:09:57 +0800526
Karl Beldan5de27b62008-11-20 15:39:31 +0100527#define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
528 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
529
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100530static const struct snd_soc_dai_ops ssm2602_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800531 .startup = ssm2602_startup,
Eric Miao6335d052009-03-03 09:41:00 +0800532 .hw_params = ssm2602_hw_params,
533 .shutdown = ssm2602_shutdown,
534 .digital_mute = ssm2602_mute,
535 .set_sysclk = ssm2602_set_dai_sysclk,
536 .set_fmt = ssm2602_set_dai_fmt,
537};
538
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000539static struct snd_soc_dai_driver ssm2602_dai = {
540 .name = "ssm2602-hifi",
Cliff Caib7138212008-09-05 18:09:57 +0800541 .playback = {
542 .stream_name = "Playback",
543 .channels_min = 2,
544 .channels_max = 2,
545 .rates = SSM2602_RATES,
Karl Beldan5de27b62008-11-20 15:39:31 +0100546 .formats = SSM2602_FORMATS,},
Cliff Caib7138212008-09-05 18:09:57 +0800547 .capture = {
548 .stream_name = "Capture",
549 .channels_min = 2,
550 .channels_max = 2,
551 .rates = SSM2602_RATES,
Karl Beldan5de27b62008-11-20 15:39:31 +0100552 .formats = SSM2602_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +0800553 .ops = &ssm2602_dai_ops,
Cliff Caib7138212008-09-05 18:09:57 +0800554};
Cliff Caib7138212008-09-05 18:09:57 +0800555
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100556static int ssm2602_suspend(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800557{
Cliff Caib7138212008-09-05 18:09:57 +0800558 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
559 return 0;
560}
561
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000562static int ssm2602_resume(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800563{
Cliff Cai93547e82011-03-27 17:22:57 -0400564 snd_soc_cache_sync(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800565
Cliff Caib7138212008-09-05 18:09:57 +0800566 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Cliff Cai93547e82011-03-27 17:22:57 -0400567
Cliff Caib7138212008-09-05 18:09:57 +0800568 return 0;
569}
570
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000571static int ssm2602_probe(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800572{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200573 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700574 struct snd_soc_dapm_context *dapm = &codec->dapm;
Axel Lin2ee9c182011-10-19 14:07:31 +0800575 int ret;
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700576
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200577 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V,
Axel Lin2ee9c182011-10-19 14:07:31 +0800578 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200579 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V,
Axel Lin2ee9c182011-10-19 14:07:31 +0800580 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700581
Liam Girdwood022658b2012-02-03 17:43:09 +0000582 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls,
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700583 ARRAY_SIZE(ssm2602_snd_controls));
584 if (ret)
585 return ret;
586
587 ret = snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets,
588 ARRAY_SIZE(ssm2602_dapm_widgets));
589 if (ret)
590 return ret;
591
592 return snd_soc_dapm_add_routes(dapm, ssm2602_routes,
593 ARRAY_SIZE(ssm2602_routes));
594}
595
596static int ssm2604_probe(struct snd_soc_codec *codec)
597{
598 struct snd_soc_dapm_context *dapm = &codec->dapm;
599 int ret;
600
601 ret = snd_soc_dapm_new_controls(dapm, ssm2604_dapm_widgets,
602 ARRAY_SIZE(ssm2604_dapm_widgets));
603 if (ret)
604 return ret;
605
606 return snd_soc_dapm_add_routes(dapm, ssm2604_routes,
607 ARRAY_SIZE(ssm2604_routes));
608}
609
610static int ssm260x_probe(struct snd_soc_codec *codec)
611{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000612 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Axel Lin2ee9c182011-10-19 14:07:31 +0800613 int ret;
Cliff Caib7138212008-09-05 18:09:57 +0800614
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200615 codec->control_data = ssm2602->regmap;
616 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
Cliff Cai93547e82011-03-27 17:22:57 -0400617 if (ret < 0) {
618 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
619 return ret;
620 }
Cliff Caib7138212008-09-05 18:09:57 +0800621
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200622 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
Cliff Cai93547e82011-03-27 17:22:57 -0400623 if (ret < 0) {
624 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
625 return ret;
626 }
Cliff Caib7138212008-09-05 18:09:57 +0800627
Cliff Caib7138212008-09-05 18:09:57 +0800628 /* set the update bits */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200629 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
Axel Lin2ee9c182011-10-19 14:07:31 +0800630 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200631 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL,
Axel Lin2ee9c182011-10-19 14:07:31 +0800632 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
Cliff Caib7138212008-09-05 18:09:57 +0800633 /*select Line in as default input*/
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200634 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC |
Cliff Caib7138212008-09-05 18:09:57 +0800635 APANA_ENABLE_MIC_BOOST);
Cliff Caib7138212008-09-05 18:09:57 +0800636
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700637 switch (ssm2602->type) {
638 case SSM2602:
639 ret = ssm2602_probe(codec);
640 break;
641 case SSM2604:
642 ret = ssm2604_probe(codec);
643 break;
644 }
Cliff Caib7138212008-09-05 18:09:57 +0800645
Lars-Peter Clausena9d19742011-09-27 11:08:47 +0200646 if (ret)
647 return ret;
648
649 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
650
651 return 0;
Cliff Caib7138212008-09-05 18:09:57 +0800652}
653
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000654/* remove everything here */
655static int ssm2602_remove(struct snd_soc_codec *codec)
656{
657 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
658 return 0;
659}
660
661static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700662 .probe = ssm260x_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000663 .remove = ssm2602_remove,
664 .suspend = ssm2602_suspend,
665 .resume = ssm2602_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000666 .set_bias_level = ssm2602_set_bias_level,
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700667
668 .controls = ssm260x_snd_controls,
669 .num_controls = ARRAY_SIZE(ssm260x_snd_controls),
670 .dapm_widgets = ssm260x_dapm_widgets,
671 .num_dapm_widgets = ARRAY_SIZE(ssm260x_dapm_widgets),
672 .dapm_routes = ssm260x_routes,
673 .num_dapm_routes = ARRAY_SIZE(ssm260x_routes),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000674};
Cliff Caib7138212008-09-05 18:09:57 +0800675
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200676static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
677{
678 return reg == SSM2602_RESET;
679}
680
681static const struct regmap_config ssm2602_regmap_config = {
682 .val_bits = 9,
683 .reg_bits = 7,
684
685 .max_register = SSM2602_RESET,
686 .volatile_reg = ssm2602_register_volatile,
687
688 .cache_type = REGCACHE_RBTREE,
689 .reg_defaults_raw = ssm2602_reg,
690 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
691};
692
Mike Frysingerb39e2852011-04-07 02:05:11 -0400693#if defined(CONFIG_SPI_MASTER)
694static int __devinit ssm2602_spi_probe(struct spi_device *spi)
695{
696 struct ssm2602_priv *ssm2602;
697 int ret;
698
Axel Lin8eeffe92011-12-29 12:05:20 +0800699 ssm2602 = devm_kzalloc(&spi->dev, sizeof(struct ssm2602_priv),
700 GFP_KERNEL);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400701 if (ssm2602 == NULL)
702 return -ENOMEM;
703
704 spi_set_drvdata(spi, ssm2602);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700705 ssm2602->type = SSM2602;
Mike Frysingerb39e2852011-04-07 02:05:11 -0400706
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200707 ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config);
708 if (IS_ERR(ssm2602->regmap))
709 return PTR_ERR(ssm2602->regmap);
710
Mike Frysingerb39e2852011-04-07 02:05:11 -0400711 ret = snd_soc_register_codec(&spi->dev,
712 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400713 return ret;
714}
715
716static int __devexit ssm2602_spi_remove(struct spi_device *spi)
717{
718 snd_soc_unregister_codec(&spi->dev);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400719 return 0;
720}
721
722static struct spi_driver ssm2602_spi_driver = {
723 .driver = {
724 .name = "ssm2602",
725 .owner = THIS_MODULE,
726 },
727 .probe = ssm2602_spi_probe,
728 .remove = __devexit_p(ssm2602_spi_remove),
729};
730#endif
731
Cliff Caib7138212008-09-05 18:09:57 +0800732#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
733/*
734 * ssm2602 2 wire address is determined by GPIO5
735 * state during powerup.
736 * low = 0x1a
737 * high = 0x1b
738 */
Lars-Peter Clausen04b89452011-05-05 16:59:12 +0200739static int __devinit ssm2602_i2c_probe(struct i2c_client *i2c,
Cliff Caib7138212008-09-05 18:09:57 +0800740 const struct i2c_device_id *id)
741{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000742 struct ssm2602_priv *ssm2602;
Cliff Caib7138212008-09-05 18:09:57 +0800743 int ret;
744
Axel Lin8eeffe92011-12-29 12:05:20 +0800745 ssm2602 = devm_kzalloc(&i2c->dev, sizeof(struct ssm2602_priv),
746 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000747 if (ssm2602 == NULL)
748 return -ENOMEM;
Cliff Caib7138212008-09-05 18:09:57 +0800749
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000750 i2c_set_clientdata(i2c, ssm2602);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700751 ssm2602->type = id->driver_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000752
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200753 ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config);
754 if (IS_ERR(ssm2602->regmap))
755 return PTR_ERR(ssm2602->regmap);
756
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000757 ret = snd_soc_register_codec(&i2c->dev,
758 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
Cliff Caib7138212008-09-05 18:09:57 +0800759 return ret;
760}
761
Lars-Peter Clausen04b89452011-05-05 16:59:12 +0200762static int __devexit ssm2602_i2c_remove(struct i2c_client *client)
Cliff Caib7138212008-09-05 18:09:57 +0800763{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000764 snd_soc_unregister_codec(&client->dev);
Cliff Caib7138212008-09-05 18:09:57 +0800765 return 0;
766}
767
768static const struct i2c_device_id ssm2602_i2c_id[] = {
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700769 { "ssm2602", SSM2602 },
Lars-Peter Clausen7dcf2762011-05-08 09:24:44 -0700770 { "ssm2603", SSM2602 },
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700771 { "ssm2604", SSM2604 },
Cliff Caib7138212008-09-05 18:09:57 +0800772 { }
773};
774MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000775
Cliff Caib7138212008-09-05 18:09:57 +0800776/* corgi i2c codec control layer */
777static struct i2c_driver ssm2602_i2c_driver = {
778 .driver = {
Mike Frysinger2a161012011-03-27 00:44:10 -0400779 .name = "ssm2602",
Cliff Caib7138212008-09-05 18:09:57 +0800780 .owner = THIS_MODULE,
781 },
782 .probe = ssm2602_i2c_probe,
Lars-Peter Clausen04b89452011-05-05 16:59:12 +0200783 .remove = __devexit_p(ssm2602_i2c_remove),
Cliff Caib7138212008-09-05 18:09:57 +0800784 .id_table = ssm2602_i2c_id,
785};
Cliff Caib7138212008-09-05 18:09:57 +0800786#endif
787
Cliff Caib7138212008-09-05 18:09:57 +0800788
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100789static int __init ssm2602_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +0000790{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000791 int ret = 0;
Mike Frysingerb39e2852011-04-07 02:05:11 -0400792
793#if defined(CONFIG_SPI_MASTER)
794 ret = spi_register_driver(&ssm2602_spi_driver);
795 if (ret)
796 return ret;
797#endif
798
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000799#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
800 ret = i2c_add_driver(&ssm2602_i2c_driver);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400801 if (ret)
802 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000803#endif
Mike Frysingerb39e2852011-04-07 02:05:11 -0400804
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000805 return ret;
Mark Brown64089b82008-12-08 19:17:58 +0000806}
807module_init(ssm2602_modinit);
808
809static void __exit ssm2602_exit(void)
810{
Mike Frysingerb39e2852011-04-07 02:05:11 -0400811#if defined(CONFIG_SPI_MASTER)
812 spi_unregister_driver(&ssm2602_spi_driver);
813#endif
814
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000815#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
816 i2c_del_driver(&ssm2602_i2c_driver);
817#endif
Mark Brown64089b82008-12-08 19:17:58 +0000818}
819module_exit(ssm2602_exit);
820
Lars-Peter Clausen7dcf2762011-05-08 09:24:44 -0700821MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver");
Cliff Caib7138212008-09-05 18:09:57 +0800822MODULE_AUTHOR("Cliff Cai");
823MODULE_LICENSE("GPL");