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> |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 22 | #include <linux/regmap.h> |
| 23 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 24 | #include "ad1836.h" |
| 25 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 26 | enum ad1836_type { |
| 27 | AD1835, |
| 28 | AD1836, |
| 29 | AD1838, |
| 30 | }; |
| 31 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 32 | /* codec private data */ |
| 33 | struct ad1836_priv { |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 34 | enum ad1836_type type; |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 35 | struct regmap *regmap; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 36 | }; |
| 37 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 38 | /* |
| 39 | * AD1836 volume/mute/de-emphasis etc. controls |
| 40 | */ |
| 41 | static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"}; |
| 42 | |
Takashi Iwai | 2e86434 | 2014-02-18 10:54:31 +0100 | [diff] [blame] | 43 | static SOC_ENUM_SINGLE_DECL(ad1836_deemp_enum, |
| 44 | AD1836_DAC_CTRL1, 8, ad1836_deemp); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 45 | |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 46 | #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 Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 58 | static const struct snd_kcontrol_new ad183x_dac_controls[] = { |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 59 | AD1836_DAC_VOLUME(1), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 60 | AD1836_DAC_SWITCH(1), |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 61 | AD1836_DAC_VOLUME(2), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 62 | AD1836_DAC_SWITCH(2), |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 63 | AD1836_DAC_VOLUME(3), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 64 | AD1836_DAC_SWITCH(3), |
| 65 | AD1836_DAC_VOLUME(4), |
| 66 | AD1836_DAC_SWITCH(4), |
| 67 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 68 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 69 | static 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 | |
| 76 | static 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 | |
| 83 | static const struct snd_kcontrol_new ad183x_adc_controls[] = { |
Lars-Peter Clausen | 90bc11d | 2011-06-06 13:38:36 +0200 | [diff] [blame] | 84 | AD1836_ADC_SWITCH(1), |
| 85 | AD1836_ADC_SWITCH(2), |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 86 | AD1836_ADC_SWITCH(3), |
| 87 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 88 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 89 | static const struct snd_soc_dapm_widget ad183x_adc_dapm_widgets[] = { |
| 90 | SND_SOC_DAPM_INPUT("ADC1IN"), |
| 91 | SND_SOC_DAPM_INPUT("ADC2IN"), |
| 92 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 93 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 94 | static const struct snd_soc_dapm_route ad183x_adc_routes[] = { |
| 95 | { "ADC", NULL, "ADC1IN" }, |
| 96 | { "ADC", NULL, "ADC2IN" }, |
| 97 | }; |
| 98 | |
| 99 | static const struct snd_kcontrol_new ad183x_controls[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 100 | /* 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 Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 108 | static const struct snd_soc_dapm_widget ad183x_dapm_widgets[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 109 | 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 Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 114 | }; |
| 115 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 116 | static const struct snd_soc_dapm_route ad183x_dapm_routes[] = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 117 | { "DAC", NULL, "ADC_PWR" }, |
| 118 | { "ADC", NULL, "ADC_PWR" }, |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 119 | }; |
| 120 | |
Lars-Peter Clausen | f97d0c6 | 2011-06-06 13:38:40 +0200 | [diff] [blame] | 121 | static const DECLARE_TLV_DB_SCALE(ad1836_in_tlv, 0, 300, 0); |
| 122 | |
| 123 | static const struct snd_kcontrol_new ad1836_controls[] = { |
Lars-Peter Clausen | 0c8e291 | 2011-06-07 07:02:59 +0200 | [diff] [blame] | 124 | 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] | 125 | ad1836_in_tlv), |
| 126 | }; |
| 127 | |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 128 | /* |
| 129 | * DAI ops entries |
| 130 | */ |
| 131 | |
| 132 | static 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 | |
| 163 | static 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 Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 167 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(dai->codec); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 168 | int word_len = 0; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 169 | |
| 170 | /* bit size */ |
Mark Brown | fa69b0f | 2014-01-08 18:37:22 +0000 | [diff] [blame] | 171 | switch (params_width(params)) { |
| 172 | case 16: |
Lars-Peter Clausen | 8ca695f | 2011-06-06 13:38:35 +0200 | [diff] [blame] | 173 | word_len = AD1836_WORD_LEN_16; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 174 | break; |
Mark Brown | fa69b0f | 2014-01-08 18:37:22 +0000 | [diff] [blame] | 175 | case 20: |
Lars-Peter Clausen | 8ca695f | 2011-06-06 13:38:35 +0200 | [diff] [blame] | 176 | word_len = AD1836_WORD_LEN_20; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 177 | break; |
Mark Brown | fa69b0f | 2014-01-08 18:37:22 +0000 | [diff] [blame] | 178 | case 24: |
| 179 | case 32: |
Lars-Peter Clausen | 8ca695f | 2011-06-06 13:38:35 +0200 | [diff] [blame] | 180 | word_len = AD1836_WORD_LEN_24; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 181 | break; |
Mark Brown | c097d5f | 2013-12-23 12:41:39 +0000 | [diff] [blame] | 182 | default: |
| 183 | return -EINVAL; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 186 | regmap_update_bits(ad1836->regmap, AD1836_DAC_CTRL1, |
| 187 | AD1836_DAC_WORD_LEN_MASK, |
Lars-Peter Clausen | 8ca695f | 2011-06-06 13:38:35 +0200 | [diff] [blame] | 188 | word_len << AD1836_DAC_WORD_LEN_OFFSET); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 189 | |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 190 | regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, |
| 191 | AD1836_ADC_WORD_LEN_MASK, |
Lars-Peter Clausen | 8ca695f | 2011-06-06 13:38:35 +0200 | [diff] [blame] | 192 | word_len << AD1836_ADC_WORD_OFFSET); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 197 | static const struct snd_soc_dai_ops ad1836_dai_ops = { |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 198 | .hw_params = ad1836_hw_params, |
| 199 | .set_fmt = ad1836_set_dai_fmt, |
| 200 | }; |
| 201 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 202 | #define AD183X_DAI(_name, num_dacs, num_adcs) \ |
| 203 | { \ |
| 204 | .name = _name "-hifi", \ |
| 205 | .playback = { \ |
| 206 | .stream_name = "Playback", \ |
| 207 | .channels_min = 2, \ |
| 208 | .channels_max = (num_dacs) * 2, \ |
| 209 | .rates = SNDRV_PCM_RATE_48000, \ |
| 210 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 211 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \ |
| 212 | }, \ |
| 213 | .capture = { \ |
| 214 | .stream_name = "Capture", \ |
| 215 | .channels_min = 2, \ |
| 216 | .channels_max = (num_adcs) * 2, \ |
| 217 | .rates = SNDRV_PCM_RATE_48000, \ |
| 218 | .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 219 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \ |
| 220 | }, \ |
| 221 | .ops = &ad1836_dai_ops, \ |
| 222 | } |
| 223 | |
| 224 | static struct snd_soc_dai_driver ad183x_dais[] = { |
| 225 | [AD1835] = AD183X_DAI("ad1835", 4, 1), |
| 226 | [AD1836] = AD183X_DAI("ad1836", 3, 2), |
| 227 | [AD1838] = AD183X_DAI("ad1838", 3, 1), |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 228 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 229 | |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 230 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 231 | static int ad1836_suspend(struct snd_soc_codec *codec) |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 232 | { |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 233 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 234 | /* reset clock control mode */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 235 | return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 236 | AD1836_ADC_SERFMT_MASK, 0); |
| 237 | } |
| 238 | |
| 239 | static int ad1836_resume(struct snd_soc_codec *codec) |
| 240 | { |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 241 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 242 | /* restore clock control mode */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 243 | return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 244 | AD1836_ADC_SERFMT_MASK, AD1836_ADC_AUX); |
| 245 | } |
| 246 | #else |
| 247 | #define ad1836_suspend NULL |
| 248 | #define ad1836_resume NULL |
| 249 | #endif |
| 250 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 251 | static int ad1836_probe(struct snd_soc_codec *codec) |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 252 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 253 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 254 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 255 | int num_dacs, num_adcs; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 256 | int ret = 0; |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 257 | int i; |
| 258 | |
| 259 | num_dacs = ad183x_dais[ad1836->type].playback.channels_max / 2; |
| 260 | num_adcs = ad183x_dais[ad1836->type].capture.channels_max / 2; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 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 */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 264 | regmap_write(ad1836->regmap, AD1836_DAC_CTRL1, 0x300); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 265 | /* unmute dac channels */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 266 | regmap_write(ad1836->regmap, AD1836_DAC_CTRL2, 0x0); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 267 | /* high-pass filter enable, power-on adc */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 268 | regmap_write(ad1836->regmap, AD1836_ADC_CTRL1, 0x100); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 269 | /* unmute adc channles, adc aux mode */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 270 | regmap_write(ad1836->regmap, 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) { |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 273 | regmap_write(ad1836->regmap, AD1836_DAC_L_VOL(i), 0x3FF); |
| 274 | regmap_write(ad1836->regmap, AD1836_DAC_R_VOL(i), 0x3FF); |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 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 */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 279 | regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x3A); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 280 | ret = snd_soc_add_codec_controls(codec, ad1836_controls, |
Lars-Peter Clausen | f97d0c6 | 2011-06-06 13:38:40 +0200 | [diff] [blame] | 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 { |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 285 | regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x00); |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 288 | ret = snd_soc_add_codec_controls(codec, ad183x_dac_controls, num_dacs * 2); |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 289 | if (ret) |
| 290 | return ret; |
| 291 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 292 | ret = snd_soc_add_codec_controls(codec, ad183x_adc_controls, num_adcs); |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 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 | { |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 318 | struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 319 | /* reset clock control mode */ |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 320 | return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, |
Lars-Peter Clausen | 2cf0342 | 2011-06-06 13:38:37 +0200 | [diff] [blame] | 321 | AD1836_ADC_SERFMT_MASK, 0); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 324 | static struct snd_soc_codec_driver soc_codec_dev_ad1836 = { |
Mike Frysinger | d4d80f5 | 2011-06-15 15:29:20 -0400 | [diff] [blame] | 325 | .probe = ad1836_probe, |
| 326 | .remove = ad1836_remove, |
Barry Song | 5d0e7f6 | 2011-06-15 15:29:22 -0400 | [diff] [blame] | 327 | .suspend = ad1836_suspend, |
| 328 | .resume = ad1836_resume, |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 329 | |
| 330 | .controls = ad183x_controls, |
| 331 | .num_controls = ARRAY_SIZE(ad183x_controls), |
| 332 | .dapm_widgets = ad183x_dapm_widgets, |
| 333 | .num_dapm_widgets = ARRAY_SIZE(ad183x_dapm_widgets), |
| 334 | .dapm_routes = ad183x_dapm_routes, |
| 335 | .num_dapm_routes = ARRAY_SIZE(ad183x_dapm_routes), |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 336 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 337 | |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 338 | static const struct reg_default ad1836_reg_defaults[] = { |
| 339 | { AD1836_DAC_CTRL1, 0x0000 }, |
| 340 | { AD1836_DAC_CTRL2, 0x0000 }, |
| 341 | { AD1836_DAC_L_VOL(0), 0x0000 }, |
| 342 | { AD1836_DAC_R_VOL(0), 0x0000 }, |
| 343 | { AD1836_DAC_L_VOL(1), 0x0000 }, |
| 344 | { AD1836_DAC_R_VOL(1), 0x0000 }, |
| 345 | { AD1836_DAC_L_VOL(2), 0x0000 }, |
| 346 | { AD1836_DAC_R_VOL(2), 0x0000 }, |
| 347 | { AD1836_DAC_L_VOL(3), 0x0000 }, |
| 348 | { AD1836_DAC_R_VOL(3), 0x0000 }, |
| 349 | { AD1836_ADC_CTRL1, 0x0000 }, |
| 350 | { AD1836_ADC_CTRL2, 0x0000 }, |
| 351 | { AD1836_ADC_CTRL3, 0x0000 }, |
| 352 | }; |
| 353 | |
| 354 | static const struct regmap_config ad1836_regmap_config = { |
| 355 | .val_bits = 12, |
| 356 | .reg_bits = 4, |
| 357 | .read_flag_mask = 0x08, |
| 358 | |
| 359 | .max_register = AD1836_ADC_CTRL3, |
| 360 | .reg_defaults = ad1836_reg_defaults, |
| 361 | .num_reg_defaults = ARRAY_SIZE(ad1836_reg_defaults), |
| 362 | .cache_type = REGCACHE_RBTREE, |
| 363 | }; |
| 364 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 365 | static int ad1836_spi_probe(struct spi_device *spi) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 366 | { |
| 367 | struct ad1836_priv *ad1836; |
| 368 | int ret; |
| 369 | |
Axel Lin | 6e4f17c | 2011-12-26 20:50:02 +0800 | [diff] [blame] | 370 | ad1836 = devm_kzalloc(&spi->dev, sizeof(struct ad1836_priv), |
| 371 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | if (ad1836 == NULL) |
| 373 | return -ENOMEM; |
| 374 | |
Lars-Peter Clausen | 7f22fd9 | 2012-09-13 12:04:51 +0200 | [diff] [blame] | 375 | ad1836->regmap = devm_regmap_init_spi(spi, &ad1836_regmap_config); |
| 376 | if (IS_ERR(ad1836->regmap)) |
| 377 | return PTR_ERR(ad1836->regmap); |
| 378 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 379 | ad1836->type = spi_get_device_id(spi)->driver_data; |
| 380 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 381 | spi_set_drvdata(spi, ad1836); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 382 | |
| 383 | ret = snd_soc_register_codec(&spi->dev, |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 384 | &soc_codec_dev_ad1836, &ad183x_dais[ad1836->type], 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 385 | return ret; |
| 386 | } |
| 387 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 388 | static int ad1836_spi_remove(struct spi_device *spi) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 389 | { |
| 390 | snd_soc_unregister_codec(&spi->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 391 | return 0; |
| 392 | } |
Axel Lin | 6e4f17c | 2011-12-26 20:50:02 +0800 | [diff] [blame] | 393 | |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 394 | static const struct spi_device_id ad1836_ids[] = { |
| 395 | { "ad1835", AD1835 }, |
| 396 | { "ad1836", AD1836 }, |
| 397 | { "ad1837", AD1835 }, |
| 398 | { "ad1838", AD1838 }, |
| 399 | { "ad1839", AD1838 }, |
| 400 | { }, |
| 401 | }; |
| 402 | MODULE_DEVICE_TABLE(spi, ad1836_ids); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 403 | |
| 404 | static struct spi_driver ad1836_spi_driver = { |
| 405 | .driver = { |
Mike Frysinger | 0679059 | 2011-06-15 15:29:21 -0400 | [diff] [blame] | 406 | .name = "ad1836", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 407 | .owner = THIS_MODULE, |
| 408 | }, |
| 409 | .probe = ad1836_spi_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 410 | .remove = ad1836_spi_remove, |
Lars-Peter Clausen | 874ce77 | 2011-06-06 13:38:38 +0200 | [diff] [blame] | 411 | .id_table = ad1836_ids, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 412 | }; |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 413 | |
Sachin Kamat | 2a9a9c8 | 2012-08-27 17:00:28 +0530 | [diff] [blame] | 414 | module_spi_driver(ad1836_spi_driver); |
Barry Song | 7eaae41 | 2009-08-13 11:59:32 +0800 | [diff] [blame] | 415 | |
| 416 | MODULE_DESCRIPTION("ASoC ad1836 driver"); |
| 417 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
| 418 | MODULE_LICENSE("GPL"); |