Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Texas Instruments TLV320AIC26 low power audio CODEC |
| 3 | * ALSA SoC CODEC driver |
| 4 | * |
| 5 | * Copyright (C) 2008 Secret Lab Technologies Ltd. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/moduleparam.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/pm.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/sysfs.h> |
| 15 | #include <linux/spi/spi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/pcm_params.h> |
| 20 | #include <sound/soc.h> |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 21 | #include <sound/initval.h> |
| 22 | |
| 23 | #include "tlv320aic26.h" |
| 24 | |
| 25 | MODULE_DESCRIPTION("ASoC TLV320AIC26 codec driver"); |
| 26 | MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | |
| 29 | /* AIC26 driver private data */ |
| 30 | struct aic26 { |
| 31 | struct spi_device *spi; |
Mark Brown | 7fbdeb8 | 2013-09-25 13:29:44 +0100 | [diff] [blame^] | 32 | struct regmap *regmap; |
Lars-Peter Clausen | f8f1179 | 2013-08-06 13:39:29 +0200 | [diff] [blame] | 33 | struct snd_soc_codec *codec; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 34 | int master; |
| 35 | int datfm; |
| 36 | int mclk; |
| 37 | |
| 38 | /* Keyclick parameters */ |
| 39 | int keyclick_amplitude; |
| 40 | int keyclick_freq; |
| 41 | int keyclick_len; |
| 42 | }; |
| 43 | |
Mark Brown | 4a11bc2 | 2013-08-16 12:24:47 +0100 | [diff] [blame] | 44 | static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = { |
| 45 | SND_SOC_DAPM_INPUT("MICIN"), |
| 46 | SND_SOC_DAPM_INPUT("AUX"), |
| 47 | |
| 48 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 49 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 50 | }; |
| 51 | |
| 52 | static const struct snd_soc_dapm_route tlv320aic26_dapm_routes[] = { |
| 53 | { "Capture", NULL, "MICIN" }, |
| 54 | { "Capture", NULL, "AUX" }, |
| 55 | |
| 56 | { "HPL", NULL, "Playback" }, |
| 57 | { "HPR", NULL, "Playback" }, |
| 58 | }; |
| 59 | |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 60 | /* --------------------------------------------------------------------- |
| 61 | * Digital Audio Interface Operations |
| 62 | */ |
| 63 | static int aic26_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 64 | struct snd_pcm_hw_params *params, |
| 65 | struct snd_soc_dai *dai) |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 66 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 67 | struct snd_soc_codec *codec = dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 68 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 69 | int fsref, divisor, wlen, pval, jval, dval, qval; |
| 70 | u16 reg; |
| 71 | |
| 72 | dev_dbg(&aic26->spi->dev, "aic26_hw_params(substream=%p, params=%p)\n", |
| 73 | substream, params); |
| 74 | dev_dbg(&aic26->spi->dev, "rate=%i format=%i\n", params_rate(params), |
| 75 | params_format(params)); |
| 76 | |
| 77 | switch (params_rate(params)) { |
| 78 | case 8000: fsref = 48000; divisor = AIC26_DIV_6; break; |
| 79 | case 11025: fsref = 44100; divisor = AIC26_DIV_4; break; |
| 80 | case 12000: fsref = 48000; divisor = AIC26_DIV_4; break; |
| 81 | case 16000: fsref = 48000; divisor = AIC26_DIV_3; break; |
| 82 | case 22050: fsref = 44100; divisor = AIC26_DIV_2; break; |
| 83 | case 24000: fsref = 48000; divisor = AIC26_DIV_2; break; |
| 84 | case 32000: fsref = 48000; divisor = AIC26_DIV_1_5; break; |
| 85 | case 44100: fsref = 44100; divisor = AIC26_DIV_1; break; |
| 86 | case 48000: fsref = 48000; divisor = AIC26_DIV_1; break; |
| 87 | default: |
| 88 | dev_dbg(&aic26->spi->dev, "bad rate\n"); return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | /* select data word length */ |
| 92 | switch (params_format(params)) { |
| 93 | case SNDRV_PCM_FORMAT_S8: wlen = AIC26_WLEN_16; break; |
| 94 | case SNDRV_PCM_FORMAT_S16_BE: wlen = AIC26_WLEN_16; break; |
| 95 | case SNDRV_PCM_FORMAT_S24_BE: wlen = AIC26_WLEN_24; break; |
| 96 | case SNDRV_PCM_FORMAT_S32_BE: wlen = AIC26_WLEN_32; break; |
| 97 | default: |
| 98 | dev_dbg(&aic26->spi->dev, "bad format\n"); return -EINVAL; |
| 99 | } |
| 100 | |
Michael Williamson | 2aba76f | 2011-05-20 10:26:06 -0400 | [diff] [blame] | 101 | /** |
| 102 | * Configure PLL |
| 103 | * fsref = (mclk * PLLM) / 2048 |
| 104 | * where PLLM = J.DDDD (DDDD register ranges from 0 to 9999, decimal) |
| 105 | */ |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 106 | pval = 1; |
Michael Williamson | 2aba76f | 2011-05-20 10:26:06 -0400 | [diff] [blame] | 107 | /* compute J portion of multiplier */ |
| 108 | jval = fsref / (aic26->mclk / 2048); |
| 109 | /* compute fractional DDDD component of multiplier */ |
| 110 | dval = fsref - (jval * (aic26->mclk / 2048)); |
| 111 | dval = (10000 * dval) / (aic26->mclk / 2048); |
| 112 | dev_dbg(&aic26->spi->dev, "Setting PLLM to %d.%04d\n", jval, dval); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 113 | qval = 0; |
| 114 | reg = 0x8000 | qval << 11 | pval << 8 | jval << 2; |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 115 | snd_soc_write(codec, AIC26_REG_PLL_PROG1, reg); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 116 | reg = dval << 2; |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 117 | snd_soc_write(codec, AIC26_REG_PLL_PROG2, reg); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 118 | |
| 119 | /* Audio Control 3 (master mode, fsref rate) */ |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 120 | if (aic26->master) |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 121 | reg = 0x0800; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 122 | if (fsref == 48000) |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 123 | reg = 0x2000; |
| 124 | snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL3, 0xf800, reg); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 125 | |
| 126 | /* Audio Control 1 (FSref divisor) */ |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 127 | reg = wlen | aic26->datfm | (divisor << 3) | divisor; |
| 128 | snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL1, 0xfff, reg); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * aic26_mute - Mute control to reduce noise when changing audio format |
| 135 | */ |
| 136 | static int aic26_mute(struct snd_soc_dai *dai, int mute) |
| 137 | { |
| 138 | struct snd_soc_codec *codec = dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 139 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 140 | u16 reg; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 141 | |
| 142 | dev_dbg(&aic26->spi->dev, "aic26_mute(dai=%p, mute=%i)\n", |
| 143 | dai, mute); |
| 144 | |
| 145 | if (mute) |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 146 | reg = 0x8080; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 147 | else |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 148 | reg = 0; |
| 149 | snd_soc_update_bits(codec, AIC26_REG_DAC_GAIN, 0x8000, reg); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int aic26_set_sysclk(struct snd_soc_dai *codec_dai, |
| 155 | int clk_id, unsigned int freq, int dir) |
| 156 | { |
| 157 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 158 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 159 | |
| 160 | dev_dbg(&aic26->spi->dev, "aic26_set_sysclk(dai=%p, clk_id==%i," |
| 161 | " freq=%i, dir=%i)\n", |
| 162 | codec_dai, clk_id, freq, dir); |
| 163 | |
| 164 | /* MCLK needs to fall between 2MHz and 50 MHz */ |
| 165 | if ((freq < 2000000) || (freq > 50000000)) |
| 166 | return -EINVAL; |
| 167 | |
| 168 | aic26->mclk = freq; |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int aic26_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) |
| 173 | { |
| 174 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 175 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 176 | |
| 177 | dev_dbg(&aic26->spi->dev, "aic26_set_fmt(dai=%p, fmt==%i)\n", |
| 178 | codec_dai, fmt); |
| 179 | |
| 180 | /* set master/slave audio interface */ |
| 181 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 182 | case SND_SOC_DAIFMT_CBM_CFM: aic26->master = 1; break; |
| 183 | case SND_SOC_DAIFMT_CBS_CFS: aic26->master = 0; break; |
| 184 | default: |
| 185 | dev_dbg(&aic26->spi->dev, "bad master\n"); return -EINVAL; |
| 186 | } |
| 187 | |
| 188 | /* interface format */ |
| 189 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 190 | case SND_SOC_DAIFMT_I2S: aic26->datfm = AIC26_DATFM_I2S; break; |
| 191 | case SND_SOC_DAIFMT_DSP_A: aic26->datfm = AIC26_DATFM_DSP; break; |
| 192 | case SND_SOC_DAIFMT_RIGHT_J: aic26->datfm = AIC26_DATFM_RIGHTJ; break; |
| 193 | case SND_SOC_DAIFMT_LEFT_J: aic26->datfm = AIC26_DATFM_LEFTJ; break; |
| 194 | default: |
| 195 | dev_dbg(&aic26->spi->dev, "bad format\n"); return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | /* --------------------------------------------------------------------- |
| 202 | * Digital Audio Interface Definition |
| 203 | */ |
| 204 | #define AIC26_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 205 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
| 206 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ |
| 207 | SNDRV_PCM_RATE_48000) |
| 208 | #define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 209 | SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE) |
| 210 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 211 | static const struct snd_soc_dai_ops aic26_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 212 | .hw_params = aic26_hw_params, |
| 213 | .digital_mute = aic26_mute, |
| 214 | .set_sysclk = aic26_set_sysclk, |
| 215 | .set_fmt = aic26_set_fmt, |
| 216 | }; |
| 217 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 218 | static struct snd_soc_dai_driver aic26_dai = { |
| 219 | .name = "tlv320aic26-hifi", |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 220 | .playback = { |
| 221 | .stream_name = "Playback", |
| 222 | .channels_min = 2, |
| 223 | .channels_max = 2, |
| 224 | .rates = AIC26_RATES, |
| 225 | .formats = AIC26_FORMATS, |
| 226 | }, |
| 227 | .capture = { |
| 228 | .stream_name = "Capture", |
| 229 | .channels_min = 2, |
| 230 | .channels_max = 2, |
| 231 | .rates = AIC26_RATES, |
| 232 | .formats = AIC26_FORMATS, |
| 233 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 234 | .ops = &aic26_dai_ops, |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 235 | }; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 236 | |
| 237 | /* --------------------------------------------------------------------- |
| 238 | * ALSA controls |
| 239 | */ |
| 240 | static const char *aic26_capture_src_text[] = {"Mic", "Aux"}; |
| 241 | static const struct soc_enum aic26_capture_src_enum = |
| 242 | SOC_ENUM_SINGLE(AIC26_REG_AUDIO_CTRL1, 12, 2, aic26_capture_src_text); |
| 243 | |
| 244 | static const struct snd_kcontrol_new aic26_snd_controls[] = { |
| 245 | /* Output */ |
| 246 | SOC_DOUBLE("PCM Playback Volume", AIC26_REG_DAC_GAIN, 8, 0, 0x7f, 1), |
| 247 | SOC_DOUBLE("PCM Playback Switch", AIC26_REG_DAC_GAIN, 15, 7, 1, 1), |
| 248 | SOC_SINGLE("PCM Capture Volume", AIC26_REG_ADC_GAIN, 8, 0x7f, 0), |
| 249 | SOC_SINGLE("PCM Capture Mute", AIC26_REG_ADC_GAIN, 15, 1, 1), |
| 250 | SOC_SINGLE("Keyclick activate", AIC26_REG_AUDIO_CTRL2, 15, 0x1, 0), |
| 251 | SOC_SINGLE("Keyclick amplitude", AIC26_REG_AUDIO_CTRL2, 12, 0x7, 0), |
| 252 | SOC_SINGLE("Keyclick frequency", AIC26_REG_AUDIO_CTRL2, 8, 0x7, 0), |
| 253 | SOC_SINGLE("Keyclick period", AIC26_REG_AUDIO_CTRL2, 4, 0xf, 0), |
| 254 | SOC_ENUM("Capture Source", aic26_capture_src_enum), |
| 255 | }; |
| 256 | |
| 257 | /* --------------------------------------------------------------------- |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 258 | * SPI device portion of driver: sysfs files for debugging |
| 259 | */ |
| 260 | |
| 261 | static ssize_t aic26_keyclick_show(struct device *dev, |
| 262 | struct device_attribute *attr, char *buf) |
| 263 | { |
| 264 | struct aic26 *aic26 = dev_get_drvdata(dev); |
| 265 | int val, amp, freq, len; |
| 266 | |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 267 | val = snd_soc_read(aic26->codec, AIC26_REG_AUDIO_CTRL2); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 268 | amp = (val >> 12) & 0x7; |
| 269 | freq = (125 << ((val >> 8) & 0x7)) >> 1; |
| 270 | len = 2 * (1 + ((val >> 4) & 0xf)); |
| 271 | |
| 272 | return sprintf(buf, "amp=%x freq=%iHz len=%iclks\n", amp, freq, len); |
| 273 | } |
| 274 | |
| 275 | /* Any write to the keyclick attribute will trigger the keyclick event */ |
| 276 | static ssize_t aic26_keyclick_set(struct device *dev, |
| 277 | struct device_attribute *attr, |
| 278 | const char *buf, size_t count) |
| 279 | { |
| 280 | struct aic26 *aic26 = dev_get_drvdata(dev); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 281 | |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 282 | snd_soc_update_bits(aic26->codec, AIC26_REG_AUDIO_CTRL2, |
| 283 | 0x8000, 0x800); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 284 | |
| 285 | return count; |
| 286 | } |
| 287 | |
Mark Brown | 9cce39a | 2008-07-29 11:42:33 +0100 | [diff] [blame] | 288 | static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 289 | |
| 290 | /* --------------------------------------------------------------------- |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 291 | * SoC CODEC portion of driver: probe and release routines |
| 292 | */ |
| 293 | static int aic26_probe(struct snd_soc_codec *codec) |
| 294 | { |
Lars-Peter Clausen | f8f1179 | 2013-08-06 13:39:29 +0200 | [diff] [blame] | 295 | struct aic26 *aic26 = dev_get_drvdata(codec->dev); |
Mark Brown | 5b0959d | 2013-09-25 13:14:41 +0100 | [diff] [blame] | 296 | int ret, reg; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 297 | |
Mark Brown | 7fbdeb8 | 2013-09-25 13:29:44 +0100 | [diff] [blame^] | 298 | snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP); |
| 299 | |
Lars-Peter Clausen | f8f1179 | 2013-08-06 13:39:29 +0200 | [diff] [blame] | 300 | aic26->codec = codec; |
| 301 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 302 | /* Reset the codec to power on defaults */ |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 303 | snd_soc_write(codec, AIC26_REG_RESET, 0xBB00); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 304 | |
| 305 | /* Power up CODEC */ |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 306 | snd_soc_write(codec, AIC26_REG_POWER_CTRL, 0); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 307 | |
| 308 | /* Audio Control 3 (master mode, fsref rate) */ |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 309 | reg = snd_soc_read(codec, AIC26_REG_AUDIO_CTRL3); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 310 | reg &= ~0xf800; |
| 311 | reg |= 0x0800; /* set master mode */ |
Mark Brown | 1220139 | 2013-08-16 12:13:50 +0100 | [diff] [blame] | 312 | snd_soc_write(codec, AIC26_REG_AUDIO_CTRL3, reg); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 313 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 314 | /* Register the sysfs files for debugging */ |
| 315 | /* Create SysFS files */ |
| 316 | ret = device_create_file(codec->dev, &dev_attr_keyclick); |
| 317 | if (ret) |
| 318 | dev_info(codec->dev, "error creating sysfs files\n"); |
| 319 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static struct snd_soc_codec_driver aic26_soc_codec_dev = { |
| 324 | .probe = aic26_probe, |
Mark Brown | 806955d | 2013-09-25 13:10:33 +0100 | [diff] [blame] | 325 | .controls = aic26_snd_controls, |
| 326 | .num_controls = ARRAY_SIZE(aic26_snd_controls), |
Mark Brown | 4a11bc2 | 2013-08-16 12:24:47 +0100 | [diff] [blame] | 327 | .dapm_widgets = tlv320aic26_dapm_widgets, |
| 328 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic26_dapm_widgets), |
| 329 | .dapm_routes = tlv320aic26_dapm_routes, |
| 330 | .num_dapm_routes = ARRAY_SIZE(tlv320aic26_dapm_routes), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
Mark Brown | 7fbdeb8 | 2013-09-25 13:29:44 +0100 | [diff] [blame^] | 333 | static const struct regmap_config aic26_regmap = { |
| 334 | .reg_bits = 16, |
| 335 | .val_bits = 16, |
| 336 | }; |
| 337 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 338 | /* --------------------------------------------------------------------- |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 339 | * SPI device portion of driver: probe and release routines and SPI |
| 340 | * driver registration. |
| 341 | */ |
| 342 | static int aic26_spi_probe(struct spi_device *spi) |
| 343 | { |
| 344 | struct aic26 *aic26; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 345 | int ret; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 346 | |
| 347 | dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); |
| 348 | |
| 349 | /* Allocate driver data */ |
Axel Lin | a816302 | 2011-12-29 12:08:36 +0800 | [diff] [blame] | 350 | aic26 = devm_kzalloc(&spi->dev, sizeof *aic26, GFP_KERNEL); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 351 | if (!aic26) |
| 352 | return -ENOMEM; |
| 353 | |
Mark Brown | 7fbdeb8 | 2013-09-25 13:29:44 +0100 | [diff] [blame^] | 354 | aic26->regmap = devm_regmap_init_spi(spi, &aic26_regmap); |
| 355 | if (IS_ERR(aic26->regmap)) |
| 356 | return PTR_ERR(aic26->regmap); |
| 357 | |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 358 | /* Initialize the driver data */ |
| 359 | aic26->spi = spi; |
| 360 | dev_set_drvdata(&spi->dev, aic26); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 361 | aic26->master = 1; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 362 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 363 | ret = snd_soc_register_codec(&spi->dev, |
| 364 | &aic26_soc_codec_dev, &aic26_dai, 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 365 | return ret; |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static int aic26_spi_remove(struct spi_device *spi) |
| 369 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 370 | snd_soc_unregister_codec(&spi->dev); |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static struct spi_driver aic26_spi = { |
| 375 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 376 | .name = "tlv320aic26-codec", |
Grant Likely | d8e3bb7 | 2008-07-29 11:42:31 +0100 | [diff] [blame] | 377 | .owner = THIS_MODULE, |
| 378 | }, |
| 379 | .probe = aic26_spi_probe, |
| 380 | .remove = aic26_spi_remove, |
| 381 | }; |
| 382 | |
Sachin Kamat | 9bb280a | 2012-08-27 17:00:26 +0530 | [diff] [blame] | 383 | module_spi_driver(aic26_spi); |