blob: 9a92b7962f41b67e3ba8461d1a88c584ef4822b0 [file] [log] [blame]
Mike Frysinger42f32c52011-06-15 15:29:23 -04001 /*
2 * Audio Codec driver supporting:
3 * AD1835A, AD1836, AD1837A, AD1838A, AD1839A
Barry Song7eaae412009-08-13 11:59:32 +08004 *
Mike Frysinger42f32c52011-06-15 15:29:23 -04005 * Copyright 2009-2011 Analog Devices Inc.
Barry Song7eaae412009-08-13 11:59:32 +08006 *
Mike Frysinger42f32c52011-06-15 15:29:23 -04007 * Licensed under the GPL-2 or later.
Barry Song7eaae412009-08-13 11:59:32 +08008 */
9
10#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Barry Song7eaae412009-08-13 11:59:32 +080012#include <linux/module.h>
Barry Song7eaae412009-08-13 11:59:32 +080013#include <linux/kernel.h>
14#include <linux/device.h>
15#include <sound/core.h>
16#include <sound/pcm.h>
17#include <sound/pcm_params.h>
18#include <sound/initval.h>
19#include <sound/soc.h>
20#include <sound/tlv.h>
Barry Song7eaae412009-08-13 11:59:32 +080021#include <linux/spi/spi.h>
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +020022#include <linux/regmap.h>
23
Barry Song7eaae412009-08-13 11:59:32 +080024#include "ad1836.h"
25
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020026enum ad1836_type {
27 AD1835,
28 AD1836,
29 AD1838,
30};
31
Barry Song7eaae412009-08-13 11:59:32 +080032/* codec private data */
33struct ad1836_priv {
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020034 enum ad1836_type type;
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +020035 struct regmap *regmap;
Barry Song7eaae412009-08-13 11:59:32 +080036};
37
Barry Song7eaae412009-08-13 11:59:32 +080038/*
39 * AD1836 volume/mute/de-emphasis etc. controls
40 */
41static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"};
42
43static const struct soc_enum ad1836_deemp_enum =
44 SOC_ENUM_SINGLE(AD1836_DAC_CTRL1, 8, 4, ad1836_deemp);
45
Lars-Peter Clausen90bc11d2011-06-06 13:38:36 +020046#define AD1836_DAC_VOLUME(x) \
47 SOC_DOUBLE_R("DAC" #x " Playback Volume", AD1836_DAC_L_VOL(x), \
48 AD1836_DAC_R_VOL(x), 0, 0x3FF, 0)
49
50#define AD1836_DAC_SWITCH(x) \
51 SOC_DOUBLE("DAC" #x " Playback Switch", AD1836_DAC_CTRL2, \
52 AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1)
53
54#define AD1836_ADC_SWITCH(x) \
55 SOC_DOUBLE("ADC" #x " Capture Switch", AD1836_ADC_CTRL2, \
56 AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1)
57
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020058static const struct snd_kcontrol_new ad183x_dac_controls[] = {
Lars-Peter Clausen90bc11d2011-06-06 13:38:36 +020059 AD1836_DAC_VOLUME(1),
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020060 AD1836_DAC_SWITCH(1),
Lars-Peter Clausen90bc11d2011-06-06 13:38:36 +020061 AD1836_DAC_VOLUME(2),
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020062 AD1836_DAC_SWITCH(2),
Lars-Peter Clausen90bc11d2011-06-06 13:38:36 +020063 AD1836_DAC_VOLUME(3),
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020064 AD1836_DAC_SWITCH(3),
65 AD1836_DAC_VOLUME(4),
66 AD1836_DAC_SWITCH(4),
67};
Barry Song7eaae412009-08-13 11:59:32 +080068
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020069static const struct snd_soc_dapm_widget ad183x_dac_dapm_widgets[] = {
70 SND_SOC_DAPM_OUTPUT("DAC1OUT"),
71 SND_SOC_DAPM_OUTPUT("DAC2OUT"),
72 SND_SOC_DAPM_OUTPUT("DAC3OUT"),
73 SND_SOC_DAPM_OUTPUT("DAC4OUT"),
74};
75
76static const struct snd_soc_dapm_route ad183x_dac_routes[] = {
77 { "DAC1OUT", NULL, "DAC" },
78 { "DAC2OUT", NULL, "DAC" },
79 { "DAC3OUT", NULL, "DAC" },
80 { "DAC4OUT", NULL, "DAC" },
81};
82
83static const struct snd_kcontrol_new ad183x_adc_controls[] = {
Lars-Peter Clausen90bc11d2011-06-06 13:38:36 +020084 AD1836_ADC_SWITCH(1),
85 AD1836_ADC_SWITCH(2),
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020086 AD1836_ADC_SWITCH(3),
87};
Barry Song7eaae412009-08-13 11:59:32 +080088
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020089static const struct snd_soc_dapm_widget ad183x_adc_dapm_widgets[] = {
90 SND_SOC_DAPM_INPUT("ADC1IN"),
91 SND_SOC_DAPM_INPUT("ADC2IN"),
92};
Barry Song7eaae412009-08-13 11:59:32 +080093
Lars-Peter Clausen874ce772011-06-06 13:38:38 +020094static const struct snd_soc_dapm_route ad183x_adc_routes[] = {
95 { "ADC", NULL, "ADC1IN" },
96 { "ADC", NULL, "ADC2IN" },
97};
98
99static const struct snd_kcontrol_new ad183x_controls[] = {
Barry Song7eaae412009-08-13 11:59:32 +0800100 /* ADC high-pass filter */
101 SOC_SINGLE("ADC High Pass Filter Switch", AD1836_ADC_CTRL1,
102 AD1836_ADC_HIGHPASS_FILTER, 1, 0),
103
104 /* DAC de-emphasis */
105 SOC_ENUM("Playback Deemphasis", ad1836_deemp_enum),
106};
107
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200108static const struct snd_soc_dapm_widget ad183x_dapm_widgets[] = {
Barry Song7eaae412009-08-13 11:59:32 +0800109 SND_SOC_DAPM_DAC("DAC", "Playback", AD1836_DAC_CTRL1,
110 AD1836_DAC_POWERDOWN, 1),
111 SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
112 SND_SOC_DAPM_SUPPLY("ADC_PWR", AD1836_ADC_CTRL1,
113 AD1836_ADC_POWERDOWN, 1, NULL, 0),
Barry Song7eaae412009-08-13 11:59:32 +0800114};
115
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200116static const struct snd_soc_dapm_route ad183x_dapm_routes[] = {
Barry Song7eaae412009-08-13 11:59:32 +0800117 { "DAC", NULL, "ADC_PWR" },
118 { "ADC", NULL, "ADC_PWR" },
Barry Song7eaae412009-08-13 11:59:32 +0800119};
120
Lars-Peter Clausenf97d0c62011-06-06 13:38:40 +0200121static const DECLARE_TLV_DB_SCALE(ad1836_in_tlv, 0, 300, 0);
122
123static const struct snd_kcontrol_new ad1836_controls[] = {
Lars-Peter Clausen0c8e2912011-06-07 07:02:59 +0200124 SOC_DOUBLE_TLV("ADC2 Capture Volume", AD1836_ADC_CTRL1, 3, 0, 4, 0,
Lars-Peter Clausenf97d0c62011-06-06 13:38:40 +0200125 ad1836_in_tlv),
126};
127
Barry Song7eaae412009-08-13 11:59:32 +0800128/*
129 * DAI ops entries
130 */
131
132static int ad1836_set_dai_fmt(struct snd_soc_dai *codec_dai,
133 unsigned int fmt)
134{
135 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
136 /* at present, we support adc aux mode to interface with
137 * blackfin sport tdm mode
138 */
139 case SND_SOC_DAIFMT_DSP_A:
140 break;
141 default:
142 return -EINVAL;
143 }
144
145 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
146 case SND_SOC_DAIFMT_IB_IF:
147 break;
148 default:
149 return -EINVAL;
150 }
151
152 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
153 /* ALCLK,ABCLK are both output, AD1836 can only be master */
154 case SND_SOC_DAIFMT_CBM_CFM:
155 break;
156 default:
157 return -EINVAL;
158 }
159
160 return 0;
161}
162
163static int ad1836_hw_params(struct snd_pcm_substream *substream,
164 struct snd_pcm_hw_params *params,
165 struct snd_soc_dai *dai)
166{
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200167 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(dai->codec);
Barry Song7eaae412009-08-13 11:59:32 +0800168 int word_len = 0;
Barry Song7eaae412009-08-13 11:59:32 +0800169
170 /* bit size */
171 switch (params_format(params)) {
172 case SNDRV_PCM_FORMAT_S16_LE:
Lars-Peter Clausen8ca695f2011-06-06 13:38:35 +0200173 word_len = AD1836_WORD_LEN_16;
Barry Song7eaae412009-08-13 11:59:32 +0800174 break;
175 case SNDRV_PCM_FORMAT_S20_3LE:
Lars-Peter Clausen8ca695f2011-06-06 13:38:35 +0200176 word_len = AD1836_WORD_LEN_20;
Barry Song7eaae412009-08-13 11:59:32 +0800177 break;
178 case SNDRV_PCM_FORMAT_S24_LE:
179 case SNDRV_PCM_FORMAT_S32_LE:
Lars-Peter Clausen8ca695f2011-06-06 13:38:35 +0200180 word_len = AD1836_WORD_LEN_24;
Barry Song7eaae412009-08-13 11:59:32 +0800181 break;
182 }
183
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200184 regmap_update_bits(ad1836->regmap, AD1836_DAC_CTRL1,
185 AD1836_DAC_WORD_LEN_MASK,
Lars-Peter Clausen8ca695f2011-06-06 13:38:35 +0200186 word_len << AD1836_DAC_WORD_LEN_OFFSET);
Barry Song7eaae412009-08-13 11:59:32 +0800187
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200188 regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
189 AD1836_ADC_WORD_LEN_MASK,
Lars-Peter Clausen8ca695f2011-06-06 13:38:35 +0200190 word_len << AD1836_ADC_WORD_OFFSET);
Barry Song7eaae412009-08-13 11:59:32 +0800191
192 return 0;
193}
194
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100195static const struct snd_soc_dai_ops ad1836_dai_ops = {
Barry Song7eaae412009-08-13 11:59:32 +0800196 .hw_params = ad1836_hw_params,
197 .set_fmt = ad1836_set_dai_fmt,
198};
199
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200200#define AD183X_DAI(_name, num_dacs, num_adcs) \
201{ \
202 .name = _name "-hifi", \
203 .playback = { \
204 .stream_name = "Playback", \
205 .channels_min = 2, \
206 .channels_max = (num_dacs) * 2, \
207 .rates = SNDRV_PCM_RATE_48000, \
208 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \
209 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \
210 }, \
211 .capture = { \
212 .stream_name = "Capture", \
213 .channels_min = 2, \
214 .channels_max = (num_adcs) * 2, \
215 .rates = SNDRV_PCM_RATE_48000, \
216 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \
217 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \
218 }, \
219 .ops = &ad1836_dai_ops, \
220}
221
222static struct snd_soc_dai_driver ad183x_dais[] = {
223 [AD1835] = AD183X_DAI("ad1835", 4, 1),
224 [AD1836] = AD183X_DAI("ad1836", 3, 2),
225 [AD1838] = AD183X_DAI("ad1838", 3, 1),
Barry Song7eaae412009-08-13 11:59:32 +0800226};
Barry Song7eaae412009-08-13 11:59:32 +0800227
Barry Song5d0e7f62011-06-15 15:29:22 -0400228#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100229static int ad1836_suspend(struct snd_soc_codec *codec)
Barry Song5d0e7f62011-06-15 15:29:22 -0400230{
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200231 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
Barry Song5d0e7f62011-06-15 15:29:22 -0400232 /* reset clock control mode */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200233 return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
Barry Song5d0e7f62011-06-15 15:29:22 -0400234 AD1836_ADC_SERFMT_MASK, 0);
235}
236
237static int ad1836_resume(struct snd_soc_codec *codec)
238{
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200239 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
Barry Song5d0e7f62011-06-15 15:29:22 -0400240 /* restore clock control mode */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200241 return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
Barry Song5d0e7f62011-06-15 15:29:22 -0400242 AD1836_ADC_SERFMT_MASK, AD1836_ADC_AUX);
243}
244#else
245#define ad1836_suspend NULL
246#define ad1836_resume NULL
247#endif
248
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000249static int ad1836_probe(struct snd_soc_codec *codec)
Barry Song7eaae412009-08-13 11:59:32 +0800250{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000251 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200252 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200253 int num_dacs, num_adcs;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000254 int ret = 0;
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200255 int i;
256
257 num_dacs = ad183x_dais[ad1836->type].playback.channels_max / 2;
258 num_adcs = ad183x_dais[ad1836->type].capture.channels_max / 2;
Barry Song7eaae412009-08-13 11:59:32 +0800259
Barry Song7eaae412009-08-13 11:59:32 +0800260 /* default setting for ad1836 */
261 /* de-emphasis: 48kHz, power-on dac */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200262 regmap_write(ad1836->regmap, AD1836_DAC_CTRL1, 0x300);
Barry Song7eaae412009-08-13 11:59:32 +0800263 /* unmute dac channels */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200264 regmap_write(ad1836->regmap, AD1836_DAC_CTRL2, 0x0);
Barry Song7eaae412009-08-13 11:59:32 +0800265 /* high-pass filter enable, power-on adc */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200266 regmap_write(ad1836->regmap, AD1836_ADC_CTRL1, 0x100);
Barry Song7eaae412009-08-13 11:59:32 +0800267 /* unmute adc channles, adc aux mode */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200268 regmap_write(ad1836->regmap, AD1836_ADC_CTRL2, 0x180);
Barry Song7eaae412009-08-13 11:59:32 +0800269 /* volume */
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200270 for (i = 1; i <= num_dacs; ++i) {
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200271 regmap_write(ad1836->regmap, AD1836_DAC_L_VOL(i), 0x3FF);
272 regmap_write(ad1836->regmap, AD1836_DAC_R_VOL(i), 0x3FF);
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200273 }
Barry Song7eaae412009-08-13 11:59:32 +0800274
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200275 if (ad1836->type == AD1836) {
276 /* left/right diff:PGA/MUX */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200277 regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x3A);
Liam Girdwood022658b2012-02-03 17:43:09 +0000278 ret = snd_soc_add_codec_controls(codec, ad1836_controls,
Lars-Peter Clausenf97d0c62011-06-06 13:38:40 +0200279 ARRAY_SIZE(ad1836_controls));
280 if (ret)
281 return ret;
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200282 } else {
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200283 regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x00);
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200284 }
285
Liam Girdwood022658b2012-02-03 17:43:09 +0000286 ret = snd_soc_add_codec_controls(codec, ad183x_dac_controls, num_dacs * 2);
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200287 if (ret)
288 return ret;
289
Liam Girdwood022658b2012-02-03 17:43:09 +0000290 ret = snd_soc_add_codec_controls(codec, ad183x_adc_controls, num_adcs);
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200291 if (ret)
292 return ret;
293
294 ret = snd_soc_dapm_new_controls(dapm, ad183x_dac_dapm_widgets, num_dacs);
295 if (ret)
296 return ret;
297
298 ret = snd_soc_dapm_new_controls(dapm, ad183x_adc_dapm_widgets, num_adcs);
299 if (ret)
300 return ret;
301
302 ret = snd_soc_dapm_add_routes(dapm, ad183x_dac_routes, num_dacs);
303 if (ret)
304 return ret;
305
306 ret = snd_soc_dapm_add_routes(dapm, ad183x_adc_routes, num_adcs);
307 if (ret)
308 return ret;
Barry Song7eaae412009-08-13 11:59:32 +0800309
Barry Song7eaae412009-08-13 11:59:32 +0800310 return ret;
311}
312
313/* power down chip */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000314static int ad1836_remove(struct snd_soc_codec *codec)
Barry Song7eaae412009-08-13 11:59:32 +0800315{
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200316 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000317 /* reset clock control mode */
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200318 return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
Lars-Peter Clausen2cf03422011-06-06 13:38:37 +0200319 AD1836_ADC_SERFMT_MASK, 0);
Barry Song7eaae412009-08-13 11:59:32 +0800320}
321
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000322static struct snd_soc_codec_driver soc_codec_dev_ad1836 = {
Mike Frysingerd4d80f52011-06-15 15:29:20 -0400323 .probe = ad1836_probe,
324 .remove = ad1836_remove,
Barry Song5d0e7f62011-06-15 15:29:22 -0400325 .suspend = ad1836_suspend,
326 .resume = ad1836_resume,
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200327
328 .controls = ad183x_controls,
329 .num_controls = ARRAY_SIZE(ad183x_controls),
330 .dapm_widgets = ad183x_dapm_widgets,
331 .num_dapm_widgets = ARRAY_SIZE(ad183x_dapm_widgets),
332 .dapm_routes = ad183x_dapm_routes,
333 .num_dapm_routes = ARRAY_SIZE(ad183x_dapm_routes),
Barry Song7eaae412009-08-13 11:59:32 +0800334};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000335
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200336static const struct reg_default ad1836_reg_defaults[] = {
337 { AD1836_DAC_CTRL1, 0x0000 },
338 { AD1836_DAC_CTRL2, 0x0000 },
339 { AD1836_DAC_L_VOL(0), 0x0000 },
340 { AD1836_DAC_R_VOL(0), 0x0000 },
341 { AD1836_DAC_L_VOL(1), 0x0000 },
342 { AD1836_DAC_R_VOL(1), 0x0000 },
343 { AD1836_DAC_L_VOL(2), 0x0000 },
344 { AD1836_DAC_R_VOL(2), 0x0000 },
345 { AD1836_DAC_L_VOL(3), 0x0000 },
346 { AD1836_DAC_R_VOL(3), 0x0000 },
347 { AD1836_ADC_CTRL1, 0x0000 },
348 { AD1836_ADC_CTRL2, 0x0000 },
349 { AD1836_ADC_CTRL3, 0x0000 },
350};
351
352static const struct regmap_config ad1836_regmap_config = {
353 .val_bits = 12,
354 .reg_bits = 4,
355 .read_flag_mask = 0x08,
356
357 .max_register = AD1836_ADC_CTRL3,
358 .reg_defaults = ad1836_reg_defaults,
359 .num_reg_defaults = ARRAY_SIZE(ad1836_reg_defaults),
360 .cache_type = REGCACHE_RBTREE,
361};
362
Bill Pemberton7a79e942012-12-07 09:26:37 -0500363static int ad1836_spi_probe(struct spi_device *spi)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000364{
365 struct ad1836_priv *ad1836;
366 int ret;
367
Axel Lin6e4f17c2011-12-26 20:50:02 +0800368 ad1836 = devm_kzalloc(&spi->dev, sizeof(struct ad1836_priv),
369 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000370 if (ad1836 == NULL)
371 return -ENOMEM;
372
Lars-Peter Clausen7f22fd92012-09-13 12:04:51 +0200373 ad1836->regmap = devm_regmap_init_spi(spi, &ad1836_regmap_config);
374 if (IS_ERR(ad1836->regmap))
375 return PTR_ERR(ad1836->regmap);
376
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200377 ad1836->type = spi_get_device_id(spi)->driver_data;
378
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000379 spi_set_drvdata(spi, ad1836);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000380
381 ret = snd_soc_register_codec(&spi->dev,
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200382 &soc_codec_dev_ad1836, &ad183x_dais[ad1836->type], 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000383 return ret;
384}
385
Bill Pemberton7a79e942012-12-07 09:26:37 -0500386static int ad1836_spi_remove(struct spi_device *spi)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000387{
388 snd_soc_unregister_codec(&spi->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000389 return 0;
390}
Axel Lin6e4f17c2011-12-26 20:50:02 +0800391
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200392static const struct spi_device_id ad1836_ids[] = {
393 { "ad1835", AD1835 },
394 { "ad1836", AD1836 },
395 { "ad1837", AD1835 },
396 { "ad1838", AD1838 },
397 { "ad1839", AD1838 },
398 { },
399};
400MODULE_DEVICE_TABLE(spi, ad1836_ids);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000401
402static struct spi_driver ad1836_spi_driver = {
403 .driver = {
Mike Frysinger06790592011-06-15 15:29:21 -0400404 .name = "ad1836",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000405 .owner = THIS_MODULE,
406 },
407 .probe = ad1836_spi_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500408 .remove = ad1836_spi_remove,
Lars-Peter Clausen874ce772011-06-06 13:38:38 +0200409 .id_table = ad1836_ids,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000410};
Barry Song7eaae412009-08-13 11:59:32 +0800411
Sachin Kamat2a9a9c82012-08-27 17:00:28 +0530412module_spi_driver(ad1836_spi_driver);
Barry Song7eaae412009-08-13 11:59:32 +0800413
414MODULE_DESCRIPTION("ASoC ad1836 driver");
415MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
416MODULE_LICENSE("GPL");