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