Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * wm9705.c -- ALSA Soc WM9705 codec support |
| 3 | * |
| 4 | * Copyright 2008 Ian Molton <spyro@f2s.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; Version 2 of the License only. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/device.h> |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 17 | #include <linux/regmap.h> |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/ac97_codec.h> |
| 21 | #include <sound/initval.h> |
| 22 | #include <sound/soc.h> |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 23 | |
Lars-Peter Clausen | 6e0b73a | 2015-07-21 21:53:04 +0200 | [diff] [blame] | 24 | #define WM9705_VENDOR_ID 0x574d4c05 |
| 25 | #define WM9705_VENDOR_ID_MASK 0xffffffff |
| 26 | |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 27 | static const struct reg_default wm9705_reg_defaults[] = { |
| 28 | { 0x02, 0x8000 }, |
| 29 | { 0x04, 0x8000 }, |
| 30 | { 0x06, 0x8000 }, |
| 31 | { 0x0a, 0x8000 }, |
| 32 | { 0x0c, 0x8008 }, |
| 33 | { 0x0e, 0x8008 }, |
| 34 | { 0x10, 0x8808 }, |
| 35 | { 0x12, 0x8808 }, |
| 36 | { 0x14, 0x8808 }, |
| 37 | { 0x16, 0x8808 }, |
| 38 | { 0x18, 0x8808 }, |
| 39 | { 0x1a, 0x0000 }, |
| 40 | { 0x1c, 0x8000 }, |
| 41 | { 0x20, 0x0000 }, |
| 42 | { 0x22, 0x0000 }, |
| 43 | { 0x26, 0x000f }, |
| 44 | { 0x28, 0x0605 }, |
| 45 | { 0x2a, 0x0000 }, |
| 46 | { 0x2c, 0xbb80 }, |
| 47 | { 0x32, 0xbb80 }, |
| 48 | { 0x34, 0x2000 }, |
| 49 | { 0x5a, 0x0000 }, |
| 50 | { 0x5c, 0x0000 }, |
| 51 | { 0x72, 0x0808 }, |
| 52 | { 0x74, 0x0000 }, |
| 53 | { 0x76, 0x0006 }, |
| 54 | { 0x78, 0x0000 }, |
| 55 | { 0x7a, 0x0000 }, |
| 56 | }; |
| 57 | |
| 58 | static const struct regmap_config wm9705_regmap_config = { |
| 59 | .reg_bits = 16, |
| 60 | .reg_stride = 2, |
| 61 | .val_bits = 16, |
| 62 | .max_register = 0x7e, |
| 63 | .cache_type = REGCACHE_RBTREE, |
| 64 | |
| 65 | .volatile_reg = regmap_ac97_default_volatile, |
| 66 | |
| 67 | .reg_defaults = wm9705_reg_defaults, |
| 68 | .num_reg_defaults = ARRAY_SIZE(wm9705_reg_defaults), |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = { |
| 72 | SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1), |
| 73 | SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1), |
| 74 | SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), |
| 75 | SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1), |
| 76 | SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), |
| 77 | SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1), |
| 78 | SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), |
| 79 | SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), |
| 80 | SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1), |
| 81 | SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1), |
| 82 | SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1), |
| 83 | SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1), |
| 84 | SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1), |
| 85 | SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0), |
Ian Molton | 927b0ae | 2009-01-19 17:23:11 +0000 | [diff] [blame] | 86 | SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0), |
| 87 | SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static const char *wm9705_mic[] = {"Mic 1", "Mic 2"}; |
| 91 | static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC", |
| 92 | "Line", "Stereo Mix", "Mono Mix", "Phone"}; |
| 93 | |
Takashi Iwai | 09981dc | 2014-02-18 10:47:00 +0100 | [diff] [blame] | 94 | static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic, |
| 95 | AC97_GENERAL_PURPOSE, 8, wm9705_mic); |
| 96 | static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l, |
| 97 | AC97_REC_SEL, 8, wm9705_rec_sel); |
| 98 | static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r, |
| 99 | AC97_REC_SEL, 0, wm9705_rec_sel); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 100 | |
| 101 | /* Headphone Mixer */ |
| 102 | static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = { |
| 103 | SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1), |
| 104 | SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1), |
| 105 | SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1), |
| 106 | SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1), |
| 107 | SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1), |
| 108 | }; |
| 109 | |
| 110 | /* Mic source */ |
| 111 | static const struct snd_kcontrol_new wm9705_mic_src_controls = |
| 112 | SOC_DAPM_ENUM("Route", wm9705_enum_mic); |
| 113 | |
| 114 | /* Capture source */ |
| 115 | static const struct snd_kcontrol_new wm9705_capture_selectl_controls = |
| 116 | SOC_DAPM_ENUM("Route", wm9705_enum_rec_l); |
| 117 | static const struct snd_kcontrol_new wm9705_capture_selectr_controls = |
| 118 | SOC_DAPM_ENUM("Route", wm9705_enum_rec_r); |
| 119 | |
| 120 | /* DAPM widgets */ |
| 121 | static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = { |
| 122 | SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0, |
| 123 | &wm9705_mic_src_controls), |
| 124 | SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, |
| 125 | &wm9705_capture_selectl_controls), |
| 126 | SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, |
| 127 | &wm9705_capture_selectr_controls), |
| 128 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", |
| 129 | SND_SOC_NOPM, 0, 0), |
| 130 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", |
| 131 | SND_SOC_NOPM, 0, 0), |
| 132 | SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0, |
| 133 | &wm9705_hp_mixer_controls[0], |
| 134 | ARRAY_SIZE(wm9705_hp_mixer_controls)), |
| 135 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 136 | SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), |
| 137 | SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), |
| 138 | SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 139 | SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 140 | SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 141 | SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 142 | SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 143 | SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 144 | SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 145 | SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 146 | SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 147 | SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 148 | SND_SOC_DAPM_OUTPUT("HPOUTL"), |
| 149 | SND_SOC_DAPM_OUTPUT("HPOUTR"), |
| 150 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 151 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| 152 | SND_SOC_DAPM_OUTPUT("MONOOUT"), |
| 153 | SND_SOC_DAPM_INPUT("PHONE"), |
| 154 | SND_SOC_DAPM_INPUT("LINEINL"), |
| 155 | SND_SOC_DAPM_INPUT("LINEINR"), |
| 156 | SND_SOC_DAPM_INPUT("CDINL"), |
| 157 | SND_SOC_DAPM_INPUT("CDINR"), |
| 158 | SND_SOC_DAPM_INPUT("PCBEEP"), |
| 159 | SND_SOC_DAPM_INPUT("MIC1"), |
| 160 | SND_SOC_DAPM_INPUT("MIC2"), |
| 161 | }; |
| 162 | |
| 163 | /* Audio map |
| 164 | * WM9705 has no switches to disable the route from the inputs to the HP mixer |
| 165 | * so in order to prevent active inputs from forcing the audio outputs to be |
| 166 | * constantly enabled, we use the mutes on those inputs to simulate such |
| 167 | * controls. |
| 168 | */ |
Lu Guanqun | 97a58d6 | 2011-03-30 21:53:13 +0800 | [diff] [blame] | 169 | static const struct snd_soc_dapm_route wm9705_audio_map[] = { |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 170 | /* HP mixer */ |
| 171 | {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"}, |
| 172 | {"HP Mixer", "CD Playback Switch", "CD PGA"}, |
| 173 | {"HP Mixer", "Mic Playback Switch", "Mic PGA"}, |
| 174 | {"HP Mixer", "Phone Playback Switch", "Phone PGA"}, |
| 175 | {"HP Mixer", "Line Playback Switch", "Line PGA"}, |
| 176 | {"HP Mixer", NULL, "Left DAC"}, |
| 177 | {"HP Mixer", NULL, "Right DAC"}, |
| 178 | |
| 179 | /* mono mixer */ |
| 180 | {"Mono Mixer", NULL, "HP Mixer"}, |
| 181 | |
| 182 | /* outputs */ |
| 183 | {"Headphone PGA", NULL, "HP Mixer"}, |
| 184 | {"HPOUTL", NULL, "Headphone PGA"}, |
| 185 | {"HPOUTR", NULL, "Headphone PGA"}, |
| 186 | {"Line out PGA", NULL, "HP Mixer"}, |
| 187 | {"LOUT", NULL, "Line out PGA"}, |
| 188 | {"ROUT", NULL, "Line out PGA"}, |
| 189 | {"Mono PGA", NULL, "Mono Mixer"}, |
| 190 | {"MONOOUT", NULL, "Mono PGA"}, |
| 191 | |
| 192 | /* inputs */ |
| 193 | {"CD PGA", NULL, "CDINL"}, |
| 194 | {"CD PGA", NULL, "CDINR"}, |
| 195 | {"Line PGA", NULL, "LINEINL"}, |
| 196 | {"Line PGA", NULL, "LINEINR"}, |
| 197 | {"Phone PGA", NULL, "PHONE"}, |
| 198 | {"Mic Source", "Mic 1", "MIC1"}, |
| 199 | {"Mic Source", "Mic 2", "MIC2"}, |
| 200 | {"Mic PGA", NULL, "Mic Source"}, |
| 201 | {"PCBEEP PGA", NULL, "PCBEEP"}, |
| 202 | |
| 203 | /* Left capture selector */ |
| 204 | {"Left Capture Source", "Mic", "Mic Source"}, |
| 205 | {"Left Capture Source", "CD", "CDINL"}, |
| 206 | {"Left Capture Source", "Line", "LINEINL"}, |
| 207 | {"Left Capture Source", "Stereo Mix", "HP Mixer"}, |
| 208 | {"Left Capture Source", "Mono Mix", "HP Mixer"}, |
| 209 | {"Left Capture Source", "Phone", "PHONE"}, |
| 210 | |
| 211 | /* Right capture source */ |
| 212 | {"Right Capture Source", "Mic", "Mic Source"}, |
| 213 | {"Right Capture Source", "CD", "CDINR"}, |
| 214 | {"Right Capture Source", "Line", "LINEINR"}, |
| 215 | {"Right Capture Source", "Stereo Mix", "HP Mixer"}, |
| 216 | {"Right Capture Source", "Mono Mix", "HP Mixer"}, |
| 217 | {"Right Capture Source", "Phone", "PHONE"}, |
| 218 | |
| 219 | {"ADC PGA", NULL, "Left Capture Source"}, |
| 220 | {"ADC PGA", NULL, "Right Capture Source"}, |
| 221 | |
| 222 | /* ADC's */ |
| 223 | {"Left ADC", NULL, "ADC PGA"}, |
| 224 | {"Right ADC", NULL, "ADC PGA"}, |
| 225 | }; |
| 226 | |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 227 | static int ac97_prepare(struct snd_pcm_substream *substream, |
| 228 | struct snd_soc_dai *dai) |
| 229 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 230 | struct snd_soc_codec *codec = dai->codec; |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 231 | int reg; |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 232 | |
Lars-Peter Clausen | 1457de3 | 2016-10-21 10:27:08 +0200 | [diff] [blame] | 233 | snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x1, 0x1); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 234 | |
| 235 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 236 | reg = AC97_PCM_FRONT_DAC_RATE; |
| 237 | else |
| 238 | reg = AC97_PCM_LR_ADC_RATE; |
| 239 | |
Lars-Peter Clausen | 1457de3 | 2016-10-21 10:27:08 +0200 | [diff] [blame] | 240 | return snd_soc_write(codec, reg, substream->runtime->rate); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ |
| 244 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ |
| 245 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 246 | SNDRV_PCM_RATE_48000) |
| 247 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 248 | static const struct snd_soc_dai_ops wm9705_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 249 | .prepare = ac97_prepare, |
| 250 | }; |
| 251 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 252 | static struct snd_soc_dai_driver wm9705_dai[] = { |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 253 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 254 | .name = "wm9705-hifi", |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 255 | .playback = { |
| 256 | .stream_name = "HiFi Playback", |
| 257 | .channels_min = 1, |
| 258 | .channels_max = 2, |
| 259 | .rates = WM9705_AC97_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 260 | .formats = SND_SOC_STD_AC97_FMTS, |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 261 | }, |
| 262 | .capture = { |
| 263 | .stream_name = "HiFi Capture", |
| 264 | .channels_min = 1, |
| 265 | .channels_max = 2, |
| 266 | .rates = WM9705_AC97_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 267 | .formats = SND_SOC_STD_AC97_FMTS, |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 268 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 269 | .ops = &wm9705_dai_ops, |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 270 | }, |
| 271 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 272 | .name = "wm9705-aux", |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 273 | .playback = { |
| 274 | .stream_name = "Aux Playback", |
| 275 | .channels_min = 1, |
| 276 | .channels_max = 1, |
| 277 | .rates = WM9705_AC97_RATES, |
| 278 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 279 | }, |
| 280 | } |
| 281 | }; |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 282 | |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 283 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 284 | static int wm9705_soc_suspend(struct snd_soc_codec *codec) |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 285 | { |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 286 | regcache_cache_bypass(codec->component.regmap, true); |
Lars-Peter Clausen | 1457de3 | 2016-10-21 10:27:08 +0200 | [diff] [blame] | 287 | snd_soc_write(codec, AC97_POWERDOWN, 0xffff); |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 288 | regcache_cache_bypass(codec->component.regmap, false); |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 293 | static int wm9705_soc_resume(struct snd_soc_codec *codec) |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 294 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 295 | struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 296 | int ret; |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 297 | |
Lars-Peter Clausen | 6e0b73a | 2015-07-21 21:53:04 +0200 | [diff] [blame] | 298 | ret = snd_ac97_reset(ac97, true, WM9705_VENDOR_ID, |
| 299 | WM9705_VENDOR_ID_MASK); |
Lars-Peter Clausen | 9cf766f | 2014-10-30 21:01:03 +0100 | [diff] [blame] | 300 | if (ret < 0) |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 301 | return ret; |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 302 | |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 303 | regcache_sync(codec->component.regmap); |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | #else |
| 308 | #define wm9705_soc_suspend NULL |
| 309 | #define wm9705_soc_resume NULL |
| 310 | #endif |
| 311 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 312 | static int wm9705_soc_probe(struct snd_soc_codec *codec) |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 313 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 314 | struct snd_ac97 *ac97; |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 315 | struct regmap *regmap; |
| 316 | int ret; |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 317 | |
Lars-Peter Clausen | 6e0b73a | 2015-07-21 21:53:04 +0200 | [diff] [blame] | 318 | ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID, |
| 319 | WM9705_VENDOR_ID_MASK); |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 320 | if (IS_ERR(ac97)) { |
Lars-Peter Clausen | 9cf766f | 2014-10-30 21:01:03 +0100 | [diff] [blame] | 321 | dev_err(codec->dev, "Failed to register AC97 codec\n"); |
Lars-Peter Clausen | 6e0b73a | 2015-07-21 21:53:04 +0200 | [diff] [blame] | 322 | return PTR_ERR(ac97); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 325 | regmap = regmap_init_ac97(ac97, &wm9705_regmap_config); |
| 326 | if (IS_ERR(regmap)) { |
| 327 | ret = PTR_ERR(regmap); |
| 328 | goto err_free_ac97_codec; |
| 329 | } |
| 330 | |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 331 | snd_soc_codec_set_drvdata(codec, ac97); |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 332 | snd_soc_codec_init_regmap(codec, regmap); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 333 | |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 334 | return 0; |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 335 | err_free_ac97_codec: |
| 336 | snd_soc_free_ac97_codec(ac97); |
| 337 | return ret; |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 340 | static int wm9705_soc_remove(struct snd_soc_codec *codec) |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 341 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 342 | struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); |
| 343 | |
Lars-Peter Clausen | 206964e | 2016-10-21 10:27:07 +0200 | [diff] [blame] | 344 | snd_soc_codec_exit_regmap(codec); |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 345 | snd_soc_free_ac97_codec(ac97); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
Julia Lawall | f802d6c | 2016-08-31 23:52:27 +0200 | [diff] [blame] | 349 | static const struct snd_soc_codec_driver soc_codec_dev_wm9705 = { |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 350 | .probe = wm9705_soc_probe, |
| 351 | .remove = wm9705_soc_remove, |
Mark Brown | 0a11b16 | 2009-04-02 15:49:41 +0100 | [diff] [blame] | 352 | .suspend = wm9705_soc_suspend, |
| 353 | .resume = wm9705_soc_resume, |
Lars-Peter Clausen | d7cabb0 | 2014-10-30 21:01:04 +0100 | [diff] [blame] | 354 | |
Kuninori Morimoto | 2fa1f30 | 2016-08-08 09:35:34 +0000 | [diff] [blame] | 355 | .component_driver = { |
| 356 | .controls = wm9705_snd_ac97_controls, |
| 357 | .num_controls = ARRAY_SIZE(wm9705_snd_ac97_controls), |
| 358 | .dapm_widgets = wm9705_dapm_widgets, |
| 359 | .num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets), |
| 360 | .dapm_routes = wm9705_audio_map, |
| 361 | .num_dapm_routes = ARRAY_SIZE(wm9705_audio_map), |
| 362 | }, |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 363 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 364 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 365 | static int wm9705_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 366 | { |
| 367 | return snd_soc_register_codec(&pdev->dev, |
| 368 | &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai)); |
| 369 | } |
| 370 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 371 | static int wm9705_remove(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | { |
| 373 | snd_soc_unregister_codec(&pdev->dev); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static struct platform_driver wm9705_codec_driver = { |
| 378 | .driver = { |
| 379 | .name = "wm9705-codec", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 380 | }, |
| 381 | |
| 382 | .probe = wm9705_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 383 | .remove = wm9705_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 384 | }; |
| 385 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 386 | module_platform_driver(wm9705_codec_driver); |
Ian Molton | 2aceefe | 2009-01-16 11:04:18 +0000 | [diff] [blame] | 387 | |
| 388 | MODULE_DESCRIPTION("ASoC WM9705 driver"); |
| 389 | MODULE_AUTHOR("Ian Molton"); |
| 390 | MODULE_LICENSE("GPL v2"); |