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