Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 1 | /* |
| 2 | * File: sound/soc/codecs/ad1836.c |
| 3 | * Author: Barry Song <Barry.Song@analog.com> |
| 4 | * |
| 5 | * Created: Aug 04 2009 |
| 6 | * Description: Driver for AD1836 sound chip |
| 7 | * |
| 8 | * Modified: |
| 9 | * Copyright 2009 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 | |
| 19 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 21 | #include <linux/module.h> |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/device.h> |
| 24 | #include <sound/core.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/initval.h> |
| 28 | #include <sound/soc.h> |
| 29 | #include <sound/tlv.h> |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 30 | #include <linux/spi/spi.h> |
| 31 | #include "ad1836.h" |
| 32 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 33 | enum ad1836_type { |
| 34 | AD1835, |
| 35 | AD1836, |
| 36 | AD1838, |
| 37 | }; |
| 38 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 39 | /* codec private data */ |
| 40 | struct ad1836_priv { |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 41 | enum ad1836_type type; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 42 | }; |
| 43 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 44 | /* |
| 45 | * AD1836 volume/mute/de-emphasis etc. controls |
| 46 | */ |
| 47 | static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"}; |
| 48 | |
| 49 | static const struct soc_enum ad1836_deemp_enum = |
| 50 | SOC_ENUM_SINGLE(AD1836_DAC_CTRL1, 8, 4, ad1836_deemp); |
| 51 | |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 52 | #define AD1836_DAC_VOLUME(x) \ |
| 53 | SOC_DOUBLE_R("DAC" #x " Playback Volume", AD1836_DAC_L_VOL(x), \ |
| 54 | AD1836_DAC_R_VOL(x), 0, 0x3FF, 0) |
| 55 | |
| 56 | #define AD1836_DAC_SWITCH(x) \ |
| 57 | SOC_DOUBLE("DAC" #x " Playback Switch", AD1836_DAC_CTRL2, \ |
| 58 | AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1) |
| 59 | |
| 60 | #define AD1836_ADC_SWITCH(x) \ |
| 61 | SOC_DOUBLE("ADC" #x " Capture Switch", AD1836_ADC_CTRL2, \ |
| 62 | AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1) |
| 63 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 64 | static const struct snd_kcontrol_new ad183x_dac_controls[] = { |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 65 | AD1836_DAC_VOLUME(1), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 66 | AD1836_DAC_SWITCH(1), |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 67 | AD1836_DAC_VOLUME(2), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 68 | AD1836_DAC_SWITCH(2), |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 69 | AD1836_DAC_VOLUME(3), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 70 | AD1836_DAC_SWITCH(3), |
| 71 | AD1836_DAC_VOLUME(4), |
| 72 | AD1836_DAC_SWITCH(4), |
| 73 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 74 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 75 | static const struct snd_soc_dapm_widget ad183x_dac_dapm_widgets[] = { |
| 76 | SND_SOC_DAPM_OUTPUT("DAC1OUT"), |
| 77 | SND_SOC_DAPM_OUTPUT("DAC2OUT"), |
| 78 | SND_SOC_DAPM_OUTPUT("DAC3OUT"), |
| 79 | SND_SOC_DAPM_OUTPUT("DAC4OUT"), |
| 80 | }; |
| 81 | |
| 82 | static const struct snd_soc_dapm_route ad183x_dac_routes[] = { |
| 83 | { "DAC1OUT", NULL, "DAC" }, |
| 84 | { "DAC2OUT", NULL, "DAC" }, |
| 85 | { "DAC3OUT", NULL, "DAC" }, |
| 86 | { "DAC4OUT", NULL, "DAC" }, |
| 87 | }; |
| 88 | |
| 89 | static const struct snd_kcontrol_new ad183x_adc_controls[] = { |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 90 | AD1836_ADC_SWITCH(1), |
| 91 | AD1836_ADC_SWITCH(2), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 92 | AD1836_ADC_SWITCH(3), |
| 93 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 94 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 95 | static const struct snd_soc_dapm_widget ad183x_adc_dapm_widgets[] = { |
| 96 | SND_SOC_DAPM_INPUT("ADC1IN"), |
| 97 | SND_SOC_DAPM_INPUT("ADC2IN"), |
| 98 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 99 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 100 | static const struct snd_soc_dapm_route ad183x_adc_routes[] = { |
| 101 | { "ADC", NULL, "ADC1IN" }, |
| 102 | { "ADC", NULL, "ADC2IN" }, |
| 103 | }; |
| 104 | |
| 105 | static const struct snd_kcontrol_new ad183x_controls[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 106 | /* ADC high-pass filter */ |
| 107 | SOC_SINGLE("ADC High Pass Filter Switch", AD1836_ADC_CTRL1, |
| 108 | AD1836_ADC_HIGHPASS_FILTER, 1, 0), |
| 109 | |
| 110 | /* DAC de-emphasis */ |
| 111 | SOC_ENUM("Playback Deemphasis", ad1836_deemp_enum), |
| 112 | }; |
| 113 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 114 | static const struct snd_soc_dapm_widget ad183x_dapm_widgets[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 115 | SND_SOC_DAPM_DAC("DAC", "Playback", AD1836_DAC_CTRL1, |
| 116 | AD1836_DAC_POWERDOWN, 1), |
| 117 | SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0), |
| 118 | SND_SOC_DAPM_SUPPLY("ADC_PWR", AD1836_ADC_CTRL1, |
| 119 | AD1836_ADC_POWERDOWN, 1, NULL, 0), |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 120 | }; |
| 121 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 122 | static const struct snd_soc_dapm_route ad183x_dapm_routes[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 123 | { "DAC", NULL, "ADC_PWR" }, |
| 124 | { "ADC", NULL, "ADC_PWR" }, |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 125 | }; |
| 126 | |
Lars-Peter Clausen | f97d0c6 | 2011-06-06 13:38:40 +0200 | [diff] [blame^] | 127 | static const DECLARE_TLV_DB_SCALE(ad1836_in_tlv, 0, 300, 0); |
| 128 | |
| 129 | static const struct snd_kcontrol_new ad1836_controls[] = { |
| 130 | SOC_DOUBLE_TLV("ADC2 Capture Volume", AD183X_ADC_CTRL1, 3, 0, 4, 0, |
| 131 | ad1836_in_tlv), |
| 132 | }; |
| 133 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 134 | /* |
| 135 | * DAI ops entries |
| 136 | */ |
| 137 | |
| 138 | static int ad1836_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 139 | unsigned int fmt) |
| 140 | { |
| 141 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 142 | /* at present, we support adc aux mode to interface with |
| 143 | * blackfin sport tdm mode |
| 144 | */ |
| 145 | case SND_SOC_DAIFMT_DSP_A: |
| 146 | break; |
| 147 | default: |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | |
| 151 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 152 | case SND_SOC_DAIFMT_IB_IF: |
| 153 | break; |
| 154 | default: |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | |
| 158 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 159 | /* ALCLK,ABCLK are both output, AD1836 can only be master */ |
| 160 | case SND_SOC_DAIFMT_CBM_CFM: |
| 161 | break; |
| 162 | default: |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int ad1836_hw_params(struct snd_pcm_substream *substream, |
| 170 | struct snd_pcm_hw_params *params, |
| 171 | struct snd_soc_dai *dai) |
| 172 | { |
| 173 | int word_len = 0; |
| 174 | |
| 175 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 176 | struct snd_soc_codec *codec = rtd->codec; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 177 | |
| 178 | /* bit size */ |
| 179 | switch (params_format(params)) { |
| 180 | case SNDRV_PCM_FORMAT_S16_LE: |
| 181 | word_len = 3; |
| 182 | break; |
| 183 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 184 | word_len = 1; |
| 185 | break; |
| 186 | case SNDRV_PCM_FORMAT_S24_LE: |
| 187 | case SNDRV_PCM_FORMAT_S32_LE: |
| 188 | word_len = 0; |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | snd_soc_update_bits(codec, AD1836_DAC_CTRL1, |
| 193 | AD1836_DAC_WORD_LEN_MASK, word_len); |
| 194 | |
| 195 | snd_soc_update_bits(codec, AD1836_ADC_CTRL2, |
| 196 | AD1836_ADC_WORD_LEN_MASK, word_len); |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 201 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 202 | static int ad1836_soc_suspend(struct snd_soc_codec *codec, |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 203 | pm_message_t state) |
| 204 | { |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 205 | /* reset clock control mode */ |
Lars-Peter Clausen | 2cf0342 | 2011-06-06 13:38:37 +0200 | [diff] [blame] | 206 | return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, |
| 207 | AD1836_ADC_SERFMT_MASK, 0); |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 208 | } |
| 209 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 210 | static int ad1836_soc_resume(struct snd_soc_codec *codec) |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 211 | { |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 212 | /* restore clock control mode */ |
Lars-Peter Clausen | 2cf0342 | 2011-06-06 13:38:37 +0200 | [diff] [blame] | 213 | return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, |
| 214 | AD1836_ADC_SERFMT_MASK, AD1836_ADC_AUX); |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 215 | } |
| 216 | #else |
| 217 | #define ad1836_soc_suspend NULL |
| 218 | #define ad1836_soc_resume NULL |
| 219 | #endif |
| 220 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 221 | static struct snd_soc_dai_ops ad1836_dai_ops = { |
| 222 | .hw_params = ad1836_hw_params, |
| 223 | .set_fmt = ad1836_set_dai_fmt, |
| 224 | }; |
| 225 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 226 | #define AD183X_DAI(_name, num_dacs, num_adcs) \ |
| 227 | { \ |
| 228 | .name = _name "-hifi", \ |
| 229 | .playback = { \ |
| 230 | .stream_name = "Playback", \ |
| 231 | .channels_min = 2, \ |
| 232 | .channels_max = (num_dacs) * 2, \ |
| 233 | .rates = SNDRV_PCM_RATE_48000, \ |
| 234 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 235 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \ |
| 236 | }, \ |
| 237 | .capture = { \ |
| 238 | .stream_name = "Capture", \ |
| 239 | .channels_min = 2, \ |
| 240 | .channels_max = (num_adcs) * 2, \ |
| 241 | .rates = SNDRV_PCM_RATE_48000, \ |
| 242 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 243 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \ |
| 244 | }, \ |
| 245 | .ops = &ad1836_dai_ops, \ |
| 246 | } |
| 247 | |
| 248 | static struct snd_soc_dai_driver ad183x_dais[] = { |
| 249 | [AD1835] = AD183X_DAI("ad1835", 4, 1), |
| 250 | [AD1836] = AD183X_DAI("ad1836", 3, 2), |
| 251 | [AD1838] = AD183X_DAI("ad1838", 3, 1), |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 252 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 253 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 254 | static int ad1836_probe(struct snd_soc_codec *codec) |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 255 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 256 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 257 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 258 | int num_dacs, num_adcs; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 259 | int ret = 0; |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 260 | int i; |
| 261 | |
| 262 | num_dacs = ad183x_dais[ad1836->type].playback.channels_max / 2; |
| 263 | num_adcs = ad183x_dais[ad1836->type].capture.channels_max / 2; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 264 | |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 265 | ret = snd_soc_codec_set_cache_io(codec, 4, 12, SND_SOC_SPI); |
| 266 | if (ret < 0) { |
| 267 | dev_err(codec->dev, "failed to set cache I/O: %d\n", |
| 268 | ret); |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 269 | return ret; |
| 270 | } |
| 271 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 272 | /* default setting for ad1836 */ |
| 273 | /* de-emphasis: 48kHz, power-on dac */ |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 274 | snd_soc_write(codec, AD1836_DAC_CTRL1, 0x300); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 275 | /* unmute dac channels */ |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 276 | snd_soc_write(codec, AD1836_DAC_CTRL2, 0x0); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 277 | /* high-pass filter enable, power-on adc */ |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 278 | snd_soc_write(codec, AD1836_ADC_CTRL1, 0x100); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 279 | /* unmute adc channles, adc aux mode */ |
Barry Song | 63b62ab | 2010-01-27 11:46:17 +0800 | [diff] [blame] | 280 | snd_soc_write(codec, AD1836_ADC_CTRL2, 0x180); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 281 | /* volume */ |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 282 | for (i = 1; i <= num_dacs; ++i) { |
| 283 | snd_soc_write(codec, AD1836_DAC_L_VOL(i), 0x3FF); |
| 284 | snd_soc_write(codec, AD1836_DAC_R_VOL(i), 0x3FF); |
| 285 | } |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 286 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 287 | if (ad1836->type == AD1836) { |
| 288 | /* left/right diff:PGA/MUX */ |
| 289 | snd_soc_write(codec, AD1836_ADC_CTRL3, 0x3A); |
Lars-Peter Clausen | f97d0c6 | 2011-06-06 13:38:40 +0200 | [diff] [blame^] | 290 | ret = snd_soc_add_controls(codec, ad1836_controls, |
| 291 | ARRAY_SIZE(ad1836_controls)); |
| 292 | if (ret) |
| 293 | return ret; |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 294 | } else { |
| 295 | snd_soc_write(codec, AD1836_ADC_CTRL3, 0x00); |
| 296 | } |
| 297 | |
| 298 | ret = snd_soc_add_controls(codec, ad183x_dac_controls, num_dacs * 2); |
| 299 | if (ret) |
| 300 | return ret; |
| 301 | |
| 302 | ret = snd_soc_add_controls(codec, ad183x_adc_controls, num_adcs); |
| 303 | if (ret) |
| 304 | return ret; |
| 305 | |
| 306 | ret = snd_soc_dapm_new_controls(dapm, ad183x_dac_dapm_widgets, num_dacs); |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | |
| 310 | ret = snd_soc_dapm_new_controls(dapm, ad183x_adc_dapm_widgets, num_adcs); |
| 311 | if (ret) |
| 312 | return ret; |
| 313 | |
| 314 | ret = snd_soc_dapm_add_routes(dapm, ad183x_dac_routes, num_dacs); |
| 315 | if (ret) |
| 316 | return ret; |
| 317 | |
| 318 | ret = snd_soc_dapm_add_routes(dapm, ad183x_adc_routes, num_adcs); |
| 319 | if (ret) |
| 320 | return ret; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 321 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 322 | return ret; |
| 323 | } |
| 324 | |
| 325 | /* power down chip */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 326 | static int ad1836_remove(struct snd_soc_codec *codec) |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 327 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 328 | /* reset clock control mode */ |
Lars-Peter Clausen | 2cf0342 | 2011-06-06 13:38:37 +0200 | [diff] [blame] | 329 | return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, |
| 330 | AD1836_ADC_SERFMT_MASK, 0); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 331 | } |
| 332 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 333 | static struct snd_soc_codec_driver soc_codec_dev_ad1836 = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 334 | .probe = ad1836_probe, |
| 335 | .remove = ad1836_remove, |
Barry Song | 84549d2 | 2010-01-25 16:42:25 +0800 | [diff] [blame] | 336 | .suspend = ad1836_soc_suspend, |
| 337 | .resume = ad1836_soc_resume, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 338 | .reg_cache_size = AD1836_NUM_REGS, |
| 339 | .reg_word_size = sizeof(u16), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 340 | |
| 341 | .controls = ad183x_controls, |
| 342 | .num_controls = ARRAY_SIZE(ad183x_controls), |
| 343 | .dapm_widgets = ad183x_dapm_widgets, |
| 344 | .num_dapm_widgets = ARRAY_SIZE(ad183x_dapm_widgets), |
| 345 | .dapm_routes = ad183x_dapm_routes, |
| 346 | .num_dapm_routes = ARRAY_SIZE(ad183x_dapm_routes), |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 347 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 348 | |
| 349 | static int __devinit ad1836_spi_probe(struct spi_device *spi) |
| 350 | { |
| 351 | struct ad1836_priv *ad1836; |
| 352 | int ret; |
| 353 | |
| 354 | ad1836 = kzalloc(sizeof(struct ad1836_priv), GFP_KERNEL); |
| 355 | if (ad1836 == NULL) |
| 356 | return -ENOMEM; |
| 357 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 358 | ad1836->type = spi_get_device_id(spi)->driver_data; |
| 359 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 360 | spi_set_drvdata(spi, ad1836); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 361 | |
| 362 | ret = snd_soc_register_codec(&spi->dev, |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 363 | &soc_codec_dev_ad1836, &ad183x_dais[ad1836->type], 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 364 | if (ret < 0) |
| 365 | kfree(ad1836); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | static int __devexit ad1836_spi_remove(struct spi_device *spi) |
| 370 | { |
| 371 | snd_soc_unregister_codec(&spi->dev); |
| 372 | kfree(spi_get_drvdata(spi)); |
| 373 | return 0; |
| 374 | } |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 375 | static const struct spi_device_id ad1836_ids[] = { |
| 376 | { "ad1835", AD1835 }, |
| 377 | { "ad1836", AD1836 }, |
| 378 | { "ad1837", AD1835 }, |
| 379 | { "ad1838", AD1838 }, |
| 380 | { "ad1839", AD1838 }, |
| 381 | { }, |
| 382 | }; |
| 383 | MODULE_DEVICE_TABLE(spi, ad1836_ids); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 384 | |
| 385 | static struct spi_driver ad1836_spi_driver = { |
| 386 | .driver = { |
| 387 | .name = "ad1836-codec", |
| 388 | .owner = THIS_MODULE, |
| 389 | }, |
| 390 | .probe = ad1836_spi_probe, |
| 391 | .remove = __devexit_p(ad1836_spi_remove), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 392 | .id_table = ad1836_ids, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 393 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 394 | |
| 395 | static int __init ad1836_init(void) |
| 396 | { |
| 397 | int ret; |
| 398 | |
| 399 | ret = spi_register_driver(&ad1836_spi_driver); |
| 400 | if (ret != 0) { |
| 401 | printk(KERN_ERR "Failed to register ad1836 SPI driver: %d\n", |
| 402 | ret); |
| 403 | } |
| 404 | |
| 405 | return ret; |
| 406 | } |
| 407 | module_init(ad1836_init); |
| 408 | |
| 409 | static void __exit ad1836_exit(void) |
| 410 | { |
| 411 | spi_unregister_driver(&ad1836_spi_driver); |
| 412 | } |
| 413 | module_exit(ad1836_exit); |
| 414 | |
| 415 | MODULE_DESCRIPTION("ASoC ad1836 driver"); |
| 416 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
| 417 | MODULE_LICENSE("GPL"); |