blob: af76bbd1b24fbde13e686618c9ab2409a8e18624 [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;
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070056
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +020057 struct regmap *regmap;
58
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070059 enum ssm2602_type type;
Lars-Peter Clausen02890532011-09-27 11:08:48 +020060 unsigned int clk_out_pwr;
Cliff Caib7138212008-09-05 18:09:57 +080061};
62
63/*
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
68 */
69static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
Lars-Peter Clausen7164bdb2011-05-08 09:24:41 -070070 0x0097, 0x0097, 0x0079, 0x0079,
71 0x000a, 0x0008, 0x009f, 0x000a,
Cliff Caib7138212008-09-05 18:09:57 +080072 0x0000, 0x0000
73};
74
Cliff Caib7138212008-09-05 18:09:57 +080075
76/*Appending several "None"s just for OSS mixer use*/
77static const char *ssm2602_input_select[] = {
78 "Line", "Mic", "None", "None", "None",
79 "None", "None", "None",
80};
81
82static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
83
84static 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),
87};
88
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -070089static const unsigned int ssm260x_outmix_tlv[] = {
90 TLV_DB_RANGE_HEAD(2),
91 0, 47, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
92 48, 127, TLV_DB_SCALE_ITEM(-7400, 100, 0),
93};
94
95static const DECLARE_TLV_DB_SCALE(ssm260x_inpga_tlv, -3450, 150, 0);
96static const DECLARE_TLV_DB_SCALE(ssm260x_sidetone_tlv, -1500, 300, 0);
97
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -070098static const struct snd_kcontrol_new ssm260x_snd_controls[] = {
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -070099SOC_DOUBLE_R_TLV("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 45, 0,
100 ssm260x_inpga_tlv),
Cliff Caib7138212008-09-05 18:09:57 +0800101SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1),
102
Cliff Caib7138212008-09-05 18:09:57 +0800103SOC_SINGLE("ADC High Pass Filter Switch", SSM2602_APDIGI, 0, 1, 1),
104SOC_SINGLE("Store DC Offset Switch", SSM2602_APDIGI, 4, 1, 0),
105
Cliff Caib7138212008-09-05 18:09:57 +0800106SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]),
107};
108
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700109static const struct snd_kcontrol_new ssm2602_snd_controls[] = {
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -0700110SOC_DOUBLE_R_TLV("Master Playback Volume", SSM2602_LOUT1V, SSM2602_ROUT1V,
111 0, 127, 0, ssm260x_outmix_tlv),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700112SOC_DOUBLE_R("Master Playback ZC Switch", SSM2602_LOUT1V, SSM2602_ROUT1V,
113 7, 1, 0),
Lars-Peter Clausenf3eee002011-05-08 09:24:46 -0700114SOC_SINGLE_TLV("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1,
115 ssm260x_sidetone_tlv),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700116
117SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
118SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0),
119SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
120};
121
Cliff Caib7138212008-09-05 18:09:57 +0800122/* Output Mixer */
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700123static const struct snd_kcontrol_new ssm260x_output_mixer_controls[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800124SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0),
Cliff Caib7138212008-09-05 18:09:57 +0800125SOC_DAPM_SINGLE("HiFi Playback Switch", SSM2602_APANA, 4, 1, 0),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700126SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0),
Cliff Caib7138212008-09-05 18:09:57 +0800127};
128
129/* Input mux */
130static const struct snd_kcontrol_new ssm2602_input_mux_controls =
131SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]);
132
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700133static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800134SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1),
Cliff Caib7138212008-09-05 18:09:57 +0800135SND_SOC_DAPM_ADC("ADC", "HiFi Capture", SSM2602_PWR, 2, 1),
Cliff Caib7138212008-09-05 18:09:57 +0800136SND_SOC_DAPM_PGA("Line Input", SSM2602_PWR, 0, 1, NULL, 0),
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700137
Mark Brown3afb1b3e2011-05-11 00:01:58 +0200138SND_SOC_DAPM_SUPPLY("Digital Core Power", SSM2602_ACTIVE, 0, 0, NULL, 0),
Lars-Peter Clausen2a438012011-05-08 09:24:45 -0700139
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700140SND_SOC_DAPM_OUTPUT("LOUT"),
141SND_SOC_DAPM_OUTPUT("ROUT"),
Cliff Caib7138212008-09-05 18:09:57 +0800142SND_SOC_DAPM_INPUT("RLINEIN"),
143SND_SOC_DAPM_INPUT("LLINEIN"),
144};
145
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700146static const struct snd_soc_dapm_widget ssm2602_dapm_widgets[] = {
147SND_SOC_DAPM_MIXER("Output Mixer", SSM2602_PWR, 4, 1,
148 ssm260x_output_mixer_controls,
149 ARRAY_SIZE(ssm260x_output_mixer_controls)),
150
151SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls),
152SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1),
153
154SND_SOC_DAPM_OUTPUT("LHPOUT"),
155SND_SOC_DAPM_OUTPUT("RHPOUT"),
156SND_SOC_DAPM_INPUT("MICIN"),
157};
158
159static const struct snd_soc_dapm_widget ssm2604_dapm_widgets[] = {
160SND_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 */
163};
164
165static const struct snd_soc_dapm_route ssm260x_routes[] = {
Lars-Peter Clausen2a438012011-05-08 09:24:45 -0700166 {"DAC", NULL, "Digital Core Power"},
167 {"ADC", NULL, "Digital Core Power"},
168
Cliff Caib7138212008-09-05 18:09:57 +0800169 {"Output Mixer", "Line Bypass Switch", "Line Input"},
170 {"Output Mixer", "HiFi Playback Switch", "DAC"},
Cliff Caib7138212008-09-05 18:09:57 +0800171
Cliff Caib7138212008-09-05 18:09:57 +0800172 {"ROUT", NULL, "Output Mixer"},
Cliff Caib7138212008-09-05 18:09:57 +0800173 {"LOUT", NULL, "Output Mixer"},
174
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700175 {"Line Input", NULL, "LLINEIN"},
176 {"Line Input", NULL, "RLINEIN"},
177};
178
179static const struct snd_soc_dapm_route ssm2602_routes[] = {
180 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
181
182 {"RHPOUT", NULL, "Output Mixer"},
183 {"LHPOUT", NULL, "Output Mixer"},
184
Cliff Caib7138212008-09-05 18:09:57 +0800185 {"Input Mux", "Line", "Line Input"},
186 {"Input Mux", "Mic", "Mic Bias"},
187 {"ADC", NULL, "Input Mux"},
188
Cliff Caib7138212008-09-05 18:09:57 +0800189 {"Mic Bias", NULL, "MICIN"},
190};
191
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700192static const struct snd_soc_dapm_route ssm2604_routes[] = {
193 {"ADC", NULL, "Line Input"},
194};
Cliff Caib7138212008-09-05 18:09:57 +0800195
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200196static const unsigned int ssm2602_rates_12288000[] = {
Andreas Pretzsch7ae2b552014-01-07 22:34:41 +0100197 8000, 16000, 32000, 48000, 96000,
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200198};
199
200static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
201 .list = ssm2602_rates_12288000,
202 .count = ARRAY_SIZE(ssm2602_rates_12288000),
203};
204
205static const unsigned int ssm2602_rates_11289600[] = {
206 8000, 44100, 88200,
207};
208
209static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
210 .list = ssm2602_rates_11289600,
211 .count = ARRAY_SIZE(ssm2602_rates_11289600),
212};
213
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200214struct ssm2602_coeff {
Cliff Caib7138212008-09-05 18:09:57 +0800215 u32 mclk;
216 u32 rate;
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200217 u8 srate;
Cliff Caib7138212008-09-05 18:09:57 +0800218};
219
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200220#define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb))
221
222/* codec mclk clock coefficients */
223static const struct ssm2602_coeff ssm2602_coeff_table[] = {
Cliff Caib7138212008-09-05 18:09:57 +0800224 /* 48k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200225 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800228
229 /* 32k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200230 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800233
Andreas Pretzsch7ae2b552014-01-07 22:34:41 +0100234 /* 16k */
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)},
238
Cliff Caib7138212008-09-05 18:09:57 +0800239 /* 8k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200240 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800245
246 /* 96k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200247 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800250
251 /* 44.1k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200252 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800255
256 /* 88.2k */
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200257 {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)},
Cliff Caib7138212008-09-05 18:09:57 +0800260};
261
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200262static inline int ssm2602_get_coeff(int mclk, int rate)
Cliff Caib7138212008-09-05 18:09:57 +0800263{
264 int i;
265
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200266 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;
Cliff Caib7138212008-09-05 18:09:57 +0800270 }
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200271 return -EINVAL;
Cliff Caib7138212008-09-05 18:09:57 +0800272}
273
274static int ssm2602_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000275 struct snd_pcm_hw_params *params,
276 struct snd_soc_dai *dai)
Cliff Caib7138212008-09-05 18:09:57 +0800277{
Mark Browne6968a12012-04-04 15:58:16 +0100278 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900279 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200280 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200281 unsigned int iface;
Cliff Caib7138212008-09-05 18:09:57 +0800282
Lars-Peter Clausen0b4cd2e2011-05-05 16:59:10 +0200283 if (srate < 0)
284 return srate;
Cliff Caib7138212008-09-05 18:09:57 +0800285
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200286 regmap_write(ssm2602->regmap, SSM2602_SRATE, srate);
Cliff Caib7138212008-09-05 18:09:57 +0800287
288 /* bit size */
289 switch (params_format(params)) {
290 case SNDRV_PCM_FORMAT_S16_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200291 iface = 0x0;
Cliff Caib7138212008-09-05 18:09:57 +0800292 break;
293 case SNDRV_PCM_FORMAT_S20_3LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200294 iface = 0x4;
Cliff Caib7138212008-09-05 18:09:57 +0800295 break;
296 case SNDRV_PCM_FORMAT_S24_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200297 iface = 0x8;
Cliff Caib7138212008-09-05 18:09:57 +0800298 break;
299 case SNDRV_PCM_FORMAT_S32_LE:
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200300 iface = 0xc;
Cliff Caib7138212008-09-05 18:09:57 +0800301 break;
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200302 default:
303 return -EINVAL;
Cliff Caib7138212008-09-05 18:09:57 +0800304 }
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200305 regmap_update_bits(ssm2602->regmap, SSM2602_IFACE,
306 IFACE_AUDIO_DATA_LEN, iface);
Cliff Caib7138212008-09-05 18:09:57 +0800307 return 0;
308}
309
Mark Browndee89c42008-11-18 22:11:38 +0000310static int ssm2602_startup(struct snd_pcm_substream *substream,
311 struct snd_soc_dai *dai)
Cliff Caib7138212008-09-05 18:09:57 +0800312{
Mark Browne6968a12012-04-04 15:58:16 +0100313 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900314 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800315
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200316 if (ssm2602->sysclk_constraints) {
317 snd_pcm_hw_constraint_list(substream->runtime, 0,
318 SNDRV_PCM_HW_PARAM_RATE,
319 ssm2602->sysclk_constraints);
320 }
321
Cliff Caib7138212008-09-05 18:09:57 +0800322 return 0;
323}
324
Cliff Caib7138212008-09-05 18:09:57 +0800325static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
326{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200327 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec);
Axel Lin2ee9c182011-10-19 14:07:31 +0800328
Cliff Caib7138212008-09-05 18:09:57 +0800329 if (mute)
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200330 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
Axel Lin2ee9c182011-10-19 14:07:31 +0800331 APDIGI_ENABLE_DAC_MUTE,
332 APDIGI_ENABLE_DAC_MUTE);
Cliff Caib7138212008-09-05 18:09:57 +0800333 else
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200334 regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI,
Axel Lin2ee9c182011-10-19 14:07:31 +0800335 APDIGI_ENABLE_DAC_MUTE, 0);
Cliff Caib7138212008-09-05 18:09:57 +0800336 return 0;
337}
338
339static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
340 int clk_id, unsigned int freq, int dir)
341{
342 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900343 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200344
345 if (dir == SND_SOC_CLOCK_IN) {
346 if (clk_id != SSM2602_SYSCLK)
347 return -EINVAL;
348
349 switch (freq) {
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200350 case 12288000:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200351 case 18432000:
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200352 ssm2602->sysclk_constraints = &ssm2602_constraints_12288000;
353 break;
354 case 11289600:
355 case 16934400:
356 ssm2602->sysclk_constraints = &ssm2602_constraints_11289600;
357 break;
358 case 12000000:
359 ssm2602->sysclk_constraints = NULL;
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200360 break;
361 default:
362 return -EINVAL;
363 }
Lars-Peter Clausen8b3f39d2012-04-25 11:42:46 +0200364 ssm2602->sysclk = freq;
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200365 } else {
366 unsigned int mask;
367
368 switch (clk_id) {
369 case SSM2602_CLK_CLKOUT:
370 mask = PWR_CLK_OUT_PDN;
371 break;
372 case SSM2602_CLK_XTO:
373 mask = PWR_OSC_PDN;
374 break;
375 default:
376 return -EINVAL;
377 }
378
379 if (freq == 0)
380 ssm2602->clk_out_pwr |= mask;
381 else
382 ssm2602->clk_out_pwr &= ~mask;
383
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200384 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200385 PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
Cliff Caib7138212008-09-05 18:09:57 +0800386 }
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200387
388 return 0;
Cliff Caib7138212008-09-05 18:09:57 +0800389}
390
391static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
392 unsigned int fmt)
393{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200394 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec);
395 unsigned int iface = 0;
Cliff Caib7138212008-09-05 18:09:57 +0800396
397 /* set master/slave audio interface */
398 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
399 case SND_SOC_DAIFMT_CBM_CFM:
400 iface |= 0x0040;
401 break;
402 case SND_SOC_DAIFMT_CBS_CFS:
403 break;
404 default:
405 return -EINVAL;
406 }
407
408 /* interface format */
409 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
410 case SND_SOC_DAIFMT_I2S:
411 iface |= 0x0002;
412 break;
413 case SND_SOC_DAIFMT_RIGHT_J:
414 break;
415 case SND_SOC_DAIFMT_LEFT_J:
416 iface |= 0x0001;
417 break;
418 case SND_SOC_DAIFMT_DSP_A:
Jarkko Nikulac6913482008-12-22 10:57:33 +0200419 iface |= 0x0013;
Cliff Caib7138212008-09-05 18:09:57 +0800420 break;
421 case SND_SOC_DAIFMT_DSP_B:
Jarkko Nikulac6913482008-12-22 10:57:33 +0200422 iface |= 0x0003;
Cliff Caib7138212008-09-05 18:09:57 +0800423 break;
424 default:
425 return -EINVAL;
426 }
427
428 /* clock inversion */
429 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
430 case SND_SOC_DAIFMT_NB_NF:
431 break;
432 case SND_SOC_DAIFMT_IB_IF:
433 iface |= 0x0090;
434 break;
435 case SND_SOC_DAIFMT_IB_NF:
436 iface |= 0x0080;
437 break;
438 case SND_SOC_DAIFMT_NB_IF:
439 iface |= 0x0010;
440 break;
441 default:
442 return -EINVAL;
443 }
444
445 /* set iface */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200446 regmap_write(ssm2602->regmap, SSM2602_IFACE, iface);
Cliff Caib7138212008-09-05 18:09:57 +0800447 return 0;
448}
449
450static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
451 enum snd_soc_bias_level level)
452{
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200453 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800454
455 switch (level) {
456 case SND_SOC_BIAS_ON:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200457 /* vref/mid on, osc and clkout on if enabled */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200458 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200459 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
460 ssm2602->clk_out_pwr);
Cliff Caib7138212008-09-05 18:09:57 +0800461 break;
462 case SND_SOC_BIAS_PREPARE:
463 break;
464 case SND_SOC_BIAS_STANDBY:
465 /* everything off except vref/vmid, */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200466 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200467 PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
468 PWR_CLK_OUT_PDN | PWR_OSC_PDN);
Cliff Caib7138212008-09-05 18:09:57 +0800469 break;
470 case SND_SOC_BIAS_OFF:
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200471 /* everything off */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200472 regmap_update_bits(ssm2602->regmap, SSM2602_PWR,
Lars-Peter Clausen02890532011-09-27 11:08:48 +0200473 PWR_POWER_OFF, PWR_POWER_OFF);
Cliff Caib7138212008-09-05 18:09:57 +0800474 break;
475
476 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200477 codec->dapm.bias_level = level;
Cliff Caib7138212008-09-05 18:09:57 +0800478 return 0;
479}
480
Andreas Pretzsch7ae2b552014-01-07 22:34:41 +0100481#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)
Cliff Caib7138212008-09-05 18:09:57 +0800485
Karl Beldan5de27b62008-11-20 15:39:31 +0100486#define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
487 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
488
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100489static const struct snd_soc_dai_ops ssm2602_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800490 .startup = ssm2602_startup,
Eric Miao6335d052009-03-03 09:41:00 +0800491 .hw_params = ssm2602_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +0800492 .digital_mute = ssm2602_mute,
493 .set_sysclk = ssm2602_set_dai_sysclk,
494 .set_fmt = ssm2602_set_dai_fmt,
495};
496
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000497static struct snd_soc_dai_driver ssm2602_dai = {
498 .name = "ssm2602-hifi",
Cliff Caib7138212008-09-05 18:09:57 +0800499 .playback = {
500 .stream_name = "Playback",
501 .channels_min = 2,
502 .channels_max = 2,
503 .rates = SSM2602_RATES,
Karl Beldan5de27b62008-11-20 15:39:31 +0100504 .formats = SSM2602_FORMATS,},
Cliff Caib7138212008-09-05 18:09:57 +0800505 .capture = {
506 .stream_name = "Capture",
507 .channels_min = 2,
508 .channels_max = 2,
509 .rates = SSM2602_RATES,
Karl Beldan5de27b62008-11-20 15:39:31 +0100510 .formats = SSM2602_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +0800511 .ops = &ssm2602_dai_ops,
Lars-Peter Clausena010ff62013-12-02 21:26:22 +0100512 .symmetric_rates = 1,
513 .symmetric_samplebits = 1,
Cliff Caib7138212008-09-05 18:09:57 +0800514};
Cliff Caib7138212008-09-05 18:09:57 +0800515
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100516static int ssm2602_suspend(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800517{
Cliff Caib7138212008-09-05 18:09:57 +0800518 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
519 return 0;
520}
521
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000522static int ssm2602_resume(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800523{
Lars-Peter Clausen9d863b882013-08-31 18:15:23 +0200524 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Cliff Caib7138212008-09-05 18:09:57 +0800525
Lars-Peter Clausen9d863b882013-08-31 18:15:23 +0200526 regcache_sync(ssm2602->regmap);
Cliff Caib7138212008-09-05 18:09:57 +0800527 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Cliff Cai93547e82011-03-27 17:22:57 -0400528
Cliff Caib7138212008-09-05 18:09:57 +0800529 return 0;
530}
531
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000532static int ssm2602_probe(struct snd_soc_codec *codec)
Cliff Caib7138212008-09-05 18:09:57 +0800533{
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200534 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700535 struct snd_soc_dapm_context *dapm = &codec->dapm;
Axel Lin2ee9c182011-10-19 14:07:31 +0800536 int ret;
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700537
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200538 regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V,
Axel Lin2ee9c182011-10-19 14:07:31 +0800539 LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH);
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200540 regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V,
Axel Lin2ee9c182011-10-19 14:07:31 +0800541 ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700542
Liam Girdwood022658b2012-02-03 17:43:09 +0000543 ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls,
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700544 ARRAY_SIZE(ssm2602_snd_controls));
545 if (ret)
546 return ret;
547
548 ret = snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets,
549 ARRAY_SIZE(ssm2602_dapm_widgets));
550 if (ret)
551 return ret;
552
553 return snd_soc_dapm_add_routes(dapm, ssm2602_routes,
554 ARRAY_SIZE(ssm2602_routes));
555}
556
557static int ssm2604_probe(struct snd_soc_codec *codec)
558{
559 struct snd_soc_dapm_context *dapm = &codec->dapm;
560 int ret;
561
562 ret = snd_soc_dapm_new_controls(dapm, ssm2604_dapm_widgets,
563 ARRAY_SIZE(ssm2604_dapm_widgets));
564 if (ret)
565 return ret;
566
567 return snd_soc_dapm_add_routes(dapm, ssm2604_routes,
568 ARRAY_SIZE(ssm2604_routes));
569}
570
571static int ssm260x_probe(struct snd_soc_codec *codec)
572{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000573 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
Axel Lin2ee9c182011-10-19 14:07:31 +0800574 int ret;
Cliff Caib7138212008-09-05 18:09:57 +0800575
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200576 codec->control_data = ssm2602->regmap;
577 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
Cliff Cai93547e82011-03-27 17:22:57 -0400578 if (ret < 0) {
579 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
580 return ret;
581 }
Cliff Caib7138212008-09-05 18:09:57 +0800582
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200583 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
Cliff Cai93547e82011-03-27 17:22:57 -0400584 if (ret < 0) {
585 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
586 return ret;
587 }
Cliff Caib7138212008-09-05 18:09:57 +0800588
Cliff Caib7138212008-09-05 18:09:57 +0800589 /* set the update bits */
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200590 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
Axel Lin2ee9c182011-10-19 14:07:31 +0800591 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200592 regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL,
Axel Lin2ee9c182011-10-19 14:07:31 +0800593 RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH);
Cliff Caib7138212008-09-05 18:09:57 +0800594 /*select Line in as default input*/
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200595 regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC |
Cliff Caib7138212008-09-05 18:09:57 +0800596 APANA_ENABLE_MIC_BOOST);
Cliff Caib7138212008-09-05 18:09:57 +0800597
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700598 switch (ssm2602->type) {
599 case SSM2602:
600 ret = ssm2602_probe(codec);
601 break;
602 case SSM2604:
603 ret = ssm2604_probe(codec);
604 break;
605 }
Cliff Caib7138212008-09-05 18:09:57 +0800606
Lars-Peter Clausena9d19742011-09-27 11:08:47 +0200607 if (ret)
608 return ret;
609
610 ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
611
612 return 0;
Cliff Caib7138212008-09-05 18:09:57 +0800613}
614
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000615/* remove everything here */
616static int ssm2602_remove(struct snd_soc_codec *codec)
617{
618 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
619 return 0;
620}
621
622static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700623 .probe = ssm260x_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000624 .remove = ssm2602_remove,
625 .suspend = ssm2602_suspend,
626 .resume = ssm2602_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000627 .set_bias_level = ssm2602_set_bias_level,
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700628
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),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000635};
Cliff Caib7138212008-09-05 18:09:57 +0800636
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200637static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
638{
639 return reg == SSM2602_RESET;
640}
641
642static const struct regmap_config ssm2602_regmap_config = {
643 .val_bits = 9,
644 .reg_bits = 7,
645
646 .max_register = SSM2602_RESET,
647 .volatile_reg = ssm2602_register_volatile,
648
649 .cache_type = REGCACHE_RBTREE,
650 .reg_defaults_raw = ssm2602_reg,
651 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
652};
653
Mike Frysingerb39e2852011-04-07 02:05:11 -0400654#if defined(CONFIG_SPI_MASTER)
Bill Pemberton7a79e942012-12-07 09:26:37 -0500655static int ssm2602_spi_probe(struct spi_device *spi)
Mike Frysingerb39e2852011-04-07 02:05:11 -0400656{
657 struct ssm2602_priv *ssm2602;
658 int ret;
659
Axel Lin8eeffe92011-12-29 12:05:20 +0800660 ssm2602 = devm_kzalloc(&spi->dev, sizeof(struct ssm2602_priv),
661 GFP_KERNEL);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400662 if (ssm2602 == NULL)
663 return -ENOMEM;
664
665 spi_set_drvdata(spi, ssm2602);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700666 ssm2602->type = SSM2602;
Mike Frysingerb39e2852011-04-07 02:05:11 -0400667
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200668 ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config);
669 if (IS_ERR(ssm2602->regmap))
670 return PTR_ERR(ssm2602->regmap);
671
Mike Frysingerb39e2852011-04-07 02:05:11 -0400672 ret = snd_soc_register_codec(&spi->dev,
673 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400674 return ret;
675}
676
Bill Pemberton7a79e942012-12-07 09:26:37 -0500677static int ssm2602_spi_remove(struct spi_device *spi)
Mike Frysingerb39e2852011-04-07 02:05:11 -0400678{
679 snd_soc_unregister_codec(&spi->dev);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400680 return 0;
681}
682
683static struct spi_driver ssm2602_spi_driver = {
684 .driver = {
685 .name = "ssm2602",
686 .owner = THIS_MODULE,
687 },
688 .probe = ssm2602_spi_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500689 .remove = ssm2602_spi_remove,
Mike Frysingerb39e2852011-04-07 02:05:11 -0400690};
691#endif
692
Fabio Estevame42644c2013-11-21 12:38:42 -0200693#if IS_ENABLED(CONFIG_I2C)
Cliff Caib7138212008-09-05 18:09:57 +0800694/*
695 * ssm2602 2 wire address is determined by GPIO5
696 * state during powerup.
697 * low = 0x1a
698 * high = 0x1b
699 */
Bill Pemberton7a79e942012-12-07 09:26:37 -0500700static int ssm2602_i2c_probe(struct i2c_client *i2c,
Cliff Caib7138212008-09-05 18:09:57 +0800701 const struct i2c_device_id *id)
702{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000703 struct ssm2602_priv *ssm2602;
Cliff Caib7138212008-09-05 18:09:57 +0800704 int ret;
705
Axel Lin8eeffe92011-12-29 12:05:20 +0800706 ssm2602 = devm_kzalloc(&i2c->dev, sizeof(struct ssm2602_priv),
707 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000708 if (ssm2602 == NULL)
709 return -ENOMEM;
Cliff Caib7138212008-09-05 18:09:57 +0800710
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000711 i2c_set_clientdata(i2c, ssm2602);
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700712 ssm2602->type = id->driver_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000713
Lars-Peter Clausenbec3d9a2012-04-25 11:42:48 +0200714 ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config);
715 if (IS_ERR(ssm2602->regmap))
716 return PTR_ERR(ssm2602->regmap);
717
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000718 ret = snd_soc_register_codec(&i2c->dev,
719 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
Cliff Caib7138212008-09-05 18:09:57 +0800720 return ret;
721}
722
Bill Pemberton7a79e942012-12-07 09:26:37 -0500723static int ssm2602_i2c_remove(struct i2c_client *client)
Cliff Caib7138212008-09-05 18:09:57 +0800724{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000725 snd_soc_unregister_codec(&client->dev);
Cliff Caib7138212008-09-05 18:09:57 +0800726 return 0;
727}
728
729static const struct i2c_device_id ssm2602_i2c_id[] = {
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700730 { "ssm2602", SSM2602 },
Lars-Peter Clausen7dcf2762011-05-08 09:24:44 -0700731 { "ssm2603", SSM2602 },
Lars-Peter Clausenb1f7b2b2011-05-08 09:24:43 -0700732 { "ssm2604", SSM2604 },
Cliff Caib7138212008-09-05 18:09:57 +0800733 { }
734};
735MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000736
Cliff Caib7138212008-09-05 18:09:57 +0800737/* corgi i2c codec control layer */
738static struct i2c_driver ssm2602_i2c_driver = {
739 .driver = {
Mike Frysinger2a161012011-03-27 00:44:10 -0400740 .name = "ssm2602",
Cliff Caib7138212008-09-05 18:09:57 +0800741 .owner = THIS_MODULE,
742 },
743 .probe = ssm2602_i2c_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500744 .remove = ssm2602_i2c_remove,
Cliff Caib7138212008-09-05 18:09:57 +0800745 .id_table = ssm2602_i2c_id,
746};
Cliff Caib7138212008-09-05 18:09:57 +0800747#endif
748
Cliff Caib7138212008-09-05 18:09:57 +0800749
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100750static int __init ssm2602_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +0000751{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000752 int ret = 0;
Mike Frysingerb39e2852011-04-07 02:05:11 -0400753
754#if defined(CONFIG_SPI_MASTER)
755 ret = spi_register_driver(&ssm2602_spi_driver);
756 if (ret)
757 return ret;
758#endif
759
Fabio Estevame42644c2013-11-21 12:38:42 -0200760#if IS_ENABLED(CONFIG_I2C)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000761 ret = i2c_add_driver(&ssm2602_i2c_driver);
Mike Frysingerb39e2852011-04-07 02:05:11 -0400762 if (ret)
763 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000764#endif
Mike Frysingerb39e2852011-04-07 02:05:11 -0400765
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000766 return ret;
Mark Brown64089b82008-12-08 19:17:58 +0000767}
768module_init(ssm2602_modinit);
769
770static void __exit ssm2602_exit(void)
771{
Mike Frysingerb39e2852011-04-07 02:05:11 -0400772#if defined(CONFIG_SPI_MASTER)
773 spi_unregister_driver(&ssm2602_spi_driver);
774#endif
775
Fabio Estevame42644c2013-11-21 12:38:42 -0200776#if IS_ENABLED(CONFIG_I2C)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000777 i2c_del_driver(&ssm2602_i2c_driver);
778#endif
Mark Brown64089b82008-12-08 19:17:58 +0000779}
780module_exit(ssm2602_exit);
781
Lars-Peter Clausen7dcf2762011-05-08 09:24:44 -0700782MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver");
Cliff Caib7138212008-09-05 18:09:57 +0800783MODULE_AUTHOR("Cliff Cai");
784MODULE_LICENSE("GPL");